]>
Commit | Line | Data |
---|---|---|
dd3b648e RP |
1 | /* Target-machine dependent code for the Intel 960 |
2 | Copyright (C) 1991 Free Software Foundation, Inc. | |
3 | Contributed by Intel Corporation. | |
4 | examine_prologue and other parts contributed by Wind River Systems. | |
5 | ||
6 | This file is part of GDB. | |
7 | ||
8 | This program is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
99a7de40 JG |
10 | the Free Software Foundation; either version 2 of the License, or |
11 | (at your option) any later version. | |
dd3b648e RP |
12 | |
13 | This program is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
99a7de40 JG |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
dd3b648e RP |
21 | |
22 | /* Miscellaneous i80960-dependent routines. | |
23 | Most are called from macros defined in "tm-i960.h". */ | |
24 | ||
dd3b648e | 25 | #include "defs.h" |
d747e0af | 26 | #include <signal.h> |
dd3b648e RP |
27 | #include "symtab.h" |
28 | #include "value.h" | |
29 | #include "frame.h" | |
48792545 | 30 | #include "floatformat.h" |
98506620 | 31 | #include "target.h" |
dd3b648e | 32 | |
dd3b648e RP |
33 | /* gdb960 is always running on a non-960 host. Check its characteristics. |
34 | This routine must be called as part of gdb initialization. */ | |
35 | ||
36 | static void | |
37 | check_host() | |
38 | { | |
39 | int i; | |
40 | ||
41 | static struct typestruct { | |
42 | int hostsize; /* Size of type on host */ | |
43 | int i960size; /* Size of type on i960 */ | |
44 | char *typename; /* Name of type, for error msg */ | |
45 | } types[] = { | |
46 | { sizeof(short), 2, "short" }, | |
47 | { sizeof(int), 4, "int" }, | |
48 | { sizeof(long), 4, "long" }, | |
49 | { sizeof(float), 4, "float" }, | |
50 | { sizeof(double), 8, "double" }, | |
51 | { sizeof(char *), 4, "pointer" }, | |
52 | }; | |
53 | #define TYPELEN (sizeof(types) / sizeof(struct typestruct)) | |
54 | ||
55 | /* Make sure that host type sizes are same as i960 | |
56 | */ | |
57 | for ( i = 0; i < TYPELEN; i++ ){ | |
58 | if ( types[i].hostsize != types[i].i960size ){ | |
199b2450 | 59 | printf_unfiltered("sizeof(%s) != %d: PROCEED AT YOUR OWN RISK!\n", |
dd3b648e RP |
60 | types[i].typename, types[i].i960size ); |
61 | } | |
62 | ||
63 | } | |
64 | } | |
65 | \f | |
66 | /* Examine an i960 function prologue, recording the addresses at which | |
67 | registers are saved explicitly by the prologue code, and returning | |
68 | the address of the first instruction after the prologue (but not | |
69 | after the instruction at address LIMIT, as explained below). | |
70 | ||
71 | LIMIT places an upper bound on addresses of the instructions to be | |
72 | examined. If the prologue code scan reaches LIMIT, the scan is | |
73 | aborted and LIMIT is returned. This is used, when examining the | |
74 | prologue for the current frame, to keep examine_prologue () from | |
75 | claiming that a given register has been saved when in fact the | |
76 | instruction that saves it has not yet been executed. LIMIT is used | |
77 | at other times to stop the scan when we hit code after the true | |
78 | function prologue (e.g. for the first source line) which might | |
79 | otherwise be mistaken for function prologue. | |
80 | ||
81 | The format of the function prologue matched by this routine is | |
82 | derived from examination of the source to gcc960 1.21, particularly | |
83 | the routine i960_function_prologue (). A "regular expression" for | |
84 | the function prologue is given below: | |
85 | ||
86 | (lda LRn, g14 | |
87 | mov g14, g[0-7] | |
88 | (mov 0, g14) | (lda 0, g14))? | |
89 | ||
90 | (mov[qtl]? g[0-15], r[4-15])* | |
91 | ((addo [1-31], sp, sp) | (lda n(sp), sp))? | |
92 | (st[qtl]? g[0-15], n(fp))* | |
93 | ||
94 | (cmpobne 0, g14, LFn | |
95 | mov sp, g14 | |
96 | lda 0x30(sp), sp | |
97 | LFn: stq g0, (g14) | |
98 | stq g4, 0x10(g14) | |
99 | stq g8, 0x20(g14))? | |
100 | ||
101 | (st g14, n(fp))? | |
102 | (mov g13,r[4-15])? | |
103 | */ | |
104 | ||
105 | /* Macros for extracting fields from i960 instructions. */ | |
106 | ||
107 | #define BITMASK(pos, width) (((0x1 << (width)) - 1) << (pos)) | |
108 | #define EXTRACT_FIELD(val, pos, width) ((val) >> (pos) & BITMASK (0, width)) | |
109 | ||
110 | #define REG_SRC1(insn) EXTRACT_FIELD (insn, 0, 5) | |
111 | #define REG_SRC2(insn) EXTRACT_FIELD (insn, 14, 5) | |
112 | #define REG_SRCDST(insn) EXTRACT_FIELD (insn, 19, 5) | |
113 | #define MEM_SRCDST(insn) EXTRACT_FIELD (insn, 19, 5) | |
114 | #define MEMA_OFFSET(insn) EXTRACT_FIELD (insn, 0, 12) | |
115 | ||
116 | /* Fetch the instruction at ADDR, returning 0 if ADDR is beyond LIM or | |
117 | is not the address of a valid instruction, the address of the next | |
118 | instruction beyond ADDR otherwise. *PWORD1 receives the first word | |
119 | of the instruction, and (for two-word instructions), *PWORD2 receives | |
120 | the second. */ | |
121 | ||
122 | #define NEXT_PROLOGUE_INSN(addr, lim, pword1, pword2) \ | |
123 | (((addr) < (lim)) ? next_insn (addr, pword1, pword2) : 0) | |
124 | ||
125 | static CORE_ADDR | |
126 | examine_prologue (ip, limit, frame_addr, fsr) | |
127 | register CORE_ADDR ip; | |
128 | register CORE_ADDR limit; | |
129 | FRAME_ADDR frame_addr; | |
130 | struct frame_saved_regs *fsr; | |
131 | { | |
132 | register CORE_ADDR next_ip; | |
133 | register int src, dst; | |
134 | register unsigned int *pcode; | |
135 | unsigned int insn1, insn2; | |
136 | int size; | |
137 | int within_leaf_prologue; | |
138 | CORE_ADDR save_addr; | |
139 | static unsigned int varargs_prologue_code [] = | |
140 | { | |
141 | 0x3507a00c, /* cmpobne 0x0, g14, LFn */ | |
142 | 0x5cf01601, /* mov sp, g14 */ | |
143 | 0x8c086030, /* lda 0x30(sp), sp */ | |
144 | 0xb2879000, /* LFn: stq g0, (g14) */ | |
145 | 0xb2a7a010, /* stq g4, 0x10(g14) */ | |
146 | 0xb2c7a020 /* stq g8, 0x20(g14) */ | |
147 | }; | |
148 | ||
149 | /* Accept a leaf procedure prologue code fragment if present. | |
150 | Note that ip might point to either the leaf or non-leaf | |
151 | entry point; we look for the non-leaf entry point first: */ | |
152 | ||
153 | within_leaf_prologue = 0; | |
154 | if ((next_ip = NEXT_PROLOGUE_INSN (ip, limit, &insn1, &insn2)) | |
155 | && ((insn1 & 0xfffff000) == 0x8cf00000 /* lda LRx, g14 (MEMA) */ | |
156 | || (insn1 & 0xfffffc60) == 0x8cf03000)) /* lda LRx, g14 (MEMB) */ | |
157 | { | |
158 | within_leaf_prologue = 1; | |
159 | next_ip = NEXT_PROLOGUE_INSN (next_ip, limit, &insn1, &insn2); | |
160 | } | |
161 | ||
162 | /* Now look for the prologue code at a leaf entry point: */ | |
163 | ||
164 | if (next_ip | |
165 | && (insn1 & 0xff87ffff) == 0x5c80161e /* mov g14, gx */ | |
166 | && REG_SRCDST (insn1) <= G0_REGNUM + 7) | |
167 | { | |
168 | within_leaf_prologue = 1; | |
169 | if ((next_ip = NEXT_PROLOGUE_INSN (next_ip, limit, &insn1, &insn2)) | |
170 | && (insn1 == 0x8cf00000 /* lda 0, g14 */ | |
171 | || insn1 == 0x5cf01e00)) /* mov 0, g14 */ | |
172 | { | |
173 | ip = next_ip; | |
174 | next_ip = NEXT_PROLOGUE_INSN (ip, limit, &insn1, &insn2); | |
175 | within_leaf_prologue = 0; | |
176 | } | |
177 | } | |
178 | ||
179 | /* If something that looks like the beginning of a leaf prologue | |
180 | has been seen, but the remainder of the prologue is missing, bail. | |
181 | We don't know what we've got. */ | |
182 | ||
183 | if (within_leaf_prologue) | |
184 | return (ip); | |
185 | ||
186 | /* Accept zero or more instances of "mov[qtl]? gx, ry", where y >= 4. | |
187 | This may cause us to mistake the moving of a register | |
188 | parameter to a local register for the saving of a callee-saved | |
189 | register, but that can't be helped, since with the | |
190 | "-fcall-saved" flag, any register can be made callee-saved. */ | |
191 | ||
192 | while (next_ip | |
193 | && (insn1 & 0xfc802fb0) == 0x5c000610 | |
194 | && (dst = REG_SRCDST (insn1)) >= (R0_REGNUM + 4)) | |
195 | { | |
196 | src = REG_SRC1 (insn1); | |
197 | size = EXTRACT_FIELD (insn1, 24, 2) + 1; | |
198 | save_addr = frame_addr + ((dst - R0_REGNUM) * 4); | |
199 | while (size--) | |
200 | { | |
201 | fsr->regs[src++] = save_addr; | |
202 | save_addr += 4; | |
203 | } | |
204 | ip = next_ip; | |
205 | next_ip = NEXT_PROLOGUE_INSN (ip, limit, &insn1, &insn2); | |
206 | } | |
207 | ||
208 | /* Accept an optional "addo n, sp, sp" or "lda n(sp), sp". */ | |
209 | ||
210 | if (next_ip && | |
211 | ((insn1 & 0xffffffe0) == 0x59084800 /* addo n, sp, sp */ | |
212 | || (insn1 & 0xfffff000) == 0x8c086000 /* lda n(sp), sp (MEMA) */ | |
213 | || (insn1 & 0xfffffc60) == 0x8c087400)) /* lda n(sp), sp (MEMB) */ | |
214 | { | |
215 | ip = next_ip; | |
216 | next_ip = NEXT_PROLOGUE_INSN (ip, limit, &insn1, &insn2); | |
217 | } | |
218 | ||
219 | /* Accept zero or more instances of "st[qtl]? gx, n(fp)". | |
220 | This may cause us to mistake the copying of a register | |
221 | parameter to the frame for the saving of a callee-saved | |
222 | register, but that can't be helped, since with the | |
223 | "-fcall-saved" flag, any register can be made callee-saved. | |
224 | We can, however, refuse to accept a save of register g14, | |
225 | since that is matched explicitly below. */ | |
226 | ||
227 | while (next_ip && | |
228 | ((insn1 & 0xf787f000) == 0x9287e000 /* stl? gx, n(fp) (MEMA) */ | |
229 | || (insn1 & 0xf787fc60) == 0x9287f400 /* stl? gx, n(fp) (MEMB) */ | |
230 | || (insn1 & 0xef87f000) == 0xa287e000 /* st[tq] gx, n(fp) (MEMA) */ | |
231 | || (insn1 & 0xef87fc60) == 0xa287f400) /* st[tq] gx, n(fp) (MEMB) */ | |
232 | && ((src = MEM_SRCDST (insn1)) != G14_REGNUM)) | |
233 | { | |
234 | save_addr = frame_addr + ((insn1 & BITMASK (12, 1)) | |
235 | ? insn2 : MEMA_OFFSET (insn1)); | |
236 | size = (insn1 & BITMASK (29, 1)) ? ((insn1 & BITMASK (28, 1)) ? 4 : 3) | |
237 | : ((insn1 & BITMASK (27, 1)) ? 2 : 1); | |
238 | while (size--) | |
239 | { | |
240 | fsr->regs[src++] = save_addr; | |
241 | save_addr += 4; | |
242 | } | |
243 | ip = next_ip; | |
244 | next_ip = NEXT_PROLOGUE_INSN (ip, limit, &insn1, &insn2); | |
245 | } | |
246 | ||
247 | /* Accept the varargs prologue code if present. */ | |
248 | ||
249 | size = sizeof (varargs_prologue_code) / sizeof (int); | |
250 | pcode = varargs_prologue_code; | |
251 | while (size-- && next_ip && *pcode++ == insn1) | |
252 | { | |
253 | ip = next_ip; | |
254 | next_ip = NEXT_PROLOGUE_INSN (ip, limit, &insn1, &insn2); | |
255 | } | |
256 | ||
257 | /* Accept an optional "st g14, n(fp)". */ | |
258 | ||
259 | if (next_ip && | |
260 | ((insn1 & 0xfffff000) == 0x92f7e000 /* st g14, n(fp) (MEMA) */ | |
261 | || (insn1 & 0xfffffc60) == 0x92f7f400)) /* st g14, n(fp) (MEMB) */ | |
262 | { | |
263 | fsr->regs[G14_REGNUM] = frame_addr + ((insn1 & BITMASK (12, 1)) | |
264 | ? insn2 : MEMA_OFFSET (insn1)); | |
265 | ip = next_ip; | |
266 | next_ip = NEXT_PROLOGUE_INSN (ip, limit, &insn1, &insn2); | |
267 | } | |
268 | ||
269 | /* Accept zero or one instance of "mov g13, ry", where y >= 4. | |
270 | This is saving the address where a struct should be returned. */ | |
271 | ||
272 | if (next_ip | |
273 | && (insn1 & 0xff802fbf) == 0x5c00061d | |
274 | && (dst = REG_SRCDST (insn1)) >= (R0_REGNUM + 4)) | |
275 | { | |
276 | save_addr = frame_addr + ((dst - R0_REGNUM) * 4); | |
277 | fsr->regs[G0_REGNUM+13] = save_addr; | |
278 | ip = next_ip; | |
279 | #if 0 /* We'll need this once there is a subsequent instruction examined. */ | |
280 | next_ip = NEXT_PROLOGUE_INSN (ip, limit, &insn1, &insn2); | |
281 | #endif | |
282 | } | |
283 | ||
284 | return (ip); | |
285 | } | |
286 | ||
287 | /* Given an ip value corresponding to the start of a function, | |
288 | return the ip of the first instruction after the function | |
289 | prologue. */ | |
290 | ||
291 | CORE_ADDR | |
292 | skip_prologue (ip) | |
293 | CORE_ADDR (ip); | |
294 | { | |
295 | struct frame_saved_regs saved_regs_dummy; | |
296 | struct symtab_and_line sal; | |
297 | CORE_ADDR limit; | |
298 | ||
299 | sal = find_pc_line (ip, 0); | |
300 | limit = (sal.end) ? sal.end : 0xffffffff; | |
301 | ||
302 | return (examine_prologue (ip, limit, (FRAME_ADDR) 0, &saved_regs_dummy)); | |
303 | } | |
304 | ||
305 | /* Put here the code to store, into a struct frame_saved_regs, | |
306 | the addresses of the saved registers of frame described by FRAME_INFO. | |
307 | This includes special registers such as pc and fp saved in special | |
308 | ways in the stack frame. sp is even more special: | |
309 | the address we return for it IS the sp for the next frame. | |
310 | ||
311 | We cache the result of doing this in the frame_cache_obstack, since | |
312 | it is fairly expensive. */ | |
313 | ||
314 | void | |
315 | frame_find_saved_regs (fi, fsr) | |
316 | struct frame_info *fi; | |
317 | struct frame_saved_regs *fsr; | |
318 | { | |
319 | register CORE_ADDR next_addr; | |
320 | register CORE_ADDR *saved_regs; | |
321 | register int regnum; | |
322 | register struct frame_saved_regs *cache_fsr; | |
323 | extern struct obstack frame_cache_obstack; | |
324 | CORE_ADDR ip; | |
325 | struct symtab_and_line sal; | |
326 | CORE_ADDR limit; | |
327 | ||
328 | if (!fi->fsr) | |
329 | { | |
330 | cache_fsr = (struct frame_saved_regs *) | |
331 | obstack_alloc (&frame_cache_obstack, | |
332 | sizeof (struct frame_saved_regs)); | |
4ed97c9a | 333 | memset (cache_fsr, '\0', sizeof (struct frame_saved_regs)); |
dd3b648e RP |
334 | fi->fsr = cache_fsr; |
335 | ||
336 | /* Find the start and end of the function prologue. If the PC | |
337 | is in the function prologue, we only consider the part that | |
338 | has executed already. */ | |
339 | ||
340 | ip = get_pc_function_start (fi->pc); | |
341 | sal = find_pc_line (ip, 0); | |
342 | limit = (sal.end && sal.end < fi->pc) ? sal.end: fi->pc; | |
343 | ||
344 | examine_prologue (ip, limit, fi->frame, cache_fsr); | |
345 | ||
346 | /* Record the addresses at which the local registers are saved. | |
347 | Strictly speaking, we should only do this for non-leaf procedures, | |
348 | but no one will ever look at these values if it is a leaf procedure, | |
349 | since local registers are always caller-saved. */ | |
350 | ||
351 | next_addr = (CORE_ADDR) fi->frame; | |
352 | saved_regs = cache_fsr->regs; | |
353 | for (regnum = R0_REGNUM; regnum <= R15_REGNUM; regnum++) | |
354 | { | |
355 | *saved_regs++ = next_addr; | |
356 | next_addr += 4; | |
357 | } | |
358 | ||
359 | cache_fsr->regs[FP_REGNUM] = cache_fsr->regs[PFP_REGNUM]; | |
360 | } | |
361 | ||
362 | *fsr = *fi->fsr; | |
363 | ||
364 | /* Fetch the value of the sp from memory every time, since it | |
365 | is conceivable that it has changed since the cache was flushed. | |
366 | This unfortunately undoes much of the savings from caching the | |
367 | saved register values. I suggest adding an argument to | |
368 | get_frame_saved_regs () specifying the register number we're | |
369 | interested in (or -1 for all registers). This would be passed | |
370 | through to FRAME_FIND_SAVED_REGS (), permitting more efficient | |
371 | computation of saved register addresses (e.g., on the i960, | |
372 | we don't have to examine the prologue to find local registers). | |
373 | -- [email protected] | |
374 | FIXME, we don't need to refetch this, since the cache is cleared | |
375 | every time the child process is restarted. If GDB itself | |
376 | modifies SP, it has to clear the cache by hand (does it?). -gnu */ | |
377 | ||
378 | fsr->regs[SP_REGNUM] = read_memory_integer (fsr->regs[SP_REGNUM], 4); | |
379 | } | |
380 | ||
381 | /* Return the address of the argument block for the frame | |
382 | described by FI. Returns 0 if the address is unknown. */ | |
383 | ||
384 | CORE_ADDR | |
385 | frame_args_address (fi, must_be_correct) | |
386 | struct frame_info *fi; | |
387 | { | |
388 | register FRAME frame; | |
389 | struct frame_saved_regs fsr; | |
390 | CORE_ADDR ap; | |
391 | ||
392 | /* If g14 was saved in the frame by the function prologue code, return | |
393 | the saved value. If the frame is current and we are being sloppy, | |
394 | return the value of g14. Otherwise, return zero. */ | |
395 | ||
396 | frame = FRAME_INFO_ID (fi); | |
397 | get_frame_saved_regs (fi, &fsr); | |
398 | if (fsr.regs[G14_REGNUM]) | |
399 | ap = read_memory_integer (fsr.regs[G14_REGNUM],4); | |
400 | else { | |
401 | if (must_be_correct) | |
402 | return 0; /* Don't cache this result */ | |
403 | if (get_next_frame (frame)) | |
404 | ap = 0; | |
405 | else | |
406 | ap = read_register (G14_REGNUM); | |
7b8ca0a0 KR |
407 | if (ap == 0) |
408 | ap = fi->frame; | |
dd3b648e RP |
409 | } |
410 | fi->arg_pointer = ap; /* Cache it for next time */ | |
411 | return ap; | |
412 | } | |
413 | ||
414 | /* Return the address of the return struct for the frame | |
415 | described by FI. Returns 0 if the address is unknown. */ | |
416 | ||
417 | CORE_ADDR | |
418 | frame_struct_result_address (fi) | |
419 | struct frame_info *fi; | |
420 | { | |
421 | register FRAME frame; | |
422 | struct frame_saved_regs fsr; | |
423 | CORE_ADDR ap; | |
424 | ||
425 | /* If the frame is non-current, check to see if g14 was saved in the | |
426 | frame by the function prologue code; return the saved value if so, | |
427 | zero otherwise. If the frame is current, return the value of g14. | |
428 | ||
429 | FIXME, shouldn't this use the saved value as long as we are past | |
430 | the function prologue, and only use the current value if we have | |
431 | no saved value and are at TOS? -- [email protected] */ | |
432 | ||
433 | frame = FRAME_INFO_ID (fi); | |
434 | if (get_next_frame (frame)) { | |
435 | get_frame_saved_regs (fi, &fsr); | |
436 | if (fsr.regs[G13_REGNUM]) | |
437 | ap = read_memory_integer (fsr.regs[G13_REGNUM],4); | |
438 | else | |
439 | ap = 0; | |
440 | } else { | |
441 | ap = read_register (G13_REGNUM); | |
442 | } | |
443 | return ap; | |
444 | } | |
445 | ||
446 | /* Return address to which the currently executing leafproc will return, | |
447 | or 0 if ip is not in a leafproc (or if we can't tell if it is). | |
448 | ||
449 | Do this by finding the starting address of the routine in which ip lies. | |
450 | If the instruction there is "mov g14, gx" (where x is in [0,7]), this | |
451 | is a leafproc and the return address is in register gx. Well, this is | |
452 | true unless the return address points at a RET instruction in the current | |
453 | procedure, which indicates that we have a 'dual entry' routine that | |
454 | has been entered through the CALL entry point. */ | |
455 | ||
456 | CORE_ADDR | |
457 | leafproc_return (ip) | |
458 | CORE_ADDR ip; /* ip from currently executing function */ | |
459 | { | |
1ab3bf1b | 460 | register struct minimal_symbol *msymbol; |
dd3b648e RP |
461 | char *p; |
462 | int dst; | |
463 | unsigned int insn1, insn2; | |
464 | CORE_ADDR return_addr; | |
dd3b648e | 465 | |
1ab3bf1b | 466 | if ((msymbol = lookup_minimal_symbol_by_pc (ip)) != NULL) |
dd3b648e | 467 | { |
c398de0c | 468 | if ((p = strchr(SYMBOL_NAME (msymbol), '.')) && STREQ (p, ".lf")) |
dd3b648e | 469 | { |
81028ab0 | 470 | if (next_insn (SYMBOL_VALUE_ADDRESS (msymbol), &insn1, &insn2) |
dd3b648e RP |
471 | && (insn1 & 0xff87ffff) == 0x5c80161e /* mov g14, gx */ |
472 | && (dst = REG_SRCDST (insn1)) <= G0_REGNUM + 7) | |
473 | { | |
474 | /* Get the return address. If the "mov g14, gx" | |
475 | instruction hasn't been executed yet, read | |
476 | the return address from g14; otherwise, read it | |
477 | from the register into which g14 was moved. */ | |
478 | ||
81028ab0 FF |
479 | return_addr = |
480 | read_register ((ip == SYMBOL_VALUE_ADDRESS (msymbol)) | |
dd3b648e RP |
481 | ? G14_REGNUM : dst); |
482 | ||
483 | /* We know we are in a leaf procedure, but we don't know | |
484 | whether the caller actually did a "bal" to the ".lf" | |
485 | entry point, or a normal "call" to the non-leaf entry | |
486 | point one instruction before. In the latter case, the | |
487 | return address will be the address of a "ret" | |
488 | instruction within the procedure itself. We test for | |
489 | this below. */ | |
490 | ||
491 | if (!next_insn (return_addr, &insn1, &insn2) | |
492 | || (insn1 & 0xff000000) != 0xa000000 /* ret */ | |
1ab3bf1b | 493 | || lookup_minimal_symbol_by_pc (return_addr) != msymbol) |
dd3b648e RP |
494 | return (return_addr); |
495 | } | |
496 | } | |
497 | } | |
498 | ||
499 | return (0); | |
500 | } | |
501 | ||
502 | /* Immediately after a function call, return the saved pc. | |
503 | Can't go through the frames for this because on some machines | |
504 | the new frame is not set up until the new function executes | |
505 | some instructions. | |
506 | On the i960, the frame *is* set up immediately after the call, | |
507 | unless the function is a leaf procedure. */ | |
508 | ||
509 | CORE_ADDR | |
510 | saved_pc_after_call (frame) | |
511 | FRAME frame; | |
512 | { | |
513 | CORE_ADDR saved_pc; | |
514 | CORE_ADDR get_frame_pc (); | |
515 | ||
516 | saved_pc = leafproc_return (get_frame_pc (frame)); | |
517 | if (!saved_pc) | |
518 | saved_pc = FRAME_SAVED_PC (frame); | |
519 | ||
520 | return (saved_pc); | |
521 | } | |
522 | ||
523 | /* Discard from the stack the innermost frame, | |
524 | restoring all saved registers. */ | |
525 | ||
526 | pop_frame () | |
527 | { | |
528 | register struct frame_info *current_fi, *prev_fi; | |
529 | register int i; | |
530 | CORE_ADDR save_addr; | |
531 | CORE_ADDR leaf_return_addr; | |
532 | struct frame_saved_regs fsr; | |
533 | char local_regs_buf[16 * 4]; | |
534 | ||
535 | current_fi = get_frame_info (get_current_frame ()); | |
536 | ||
537 | /* First, undo what the hardware does when we return. | |
538 | If this is a non-leaf procedure, restore local registers from | |
539 | the save area in the calling frame. Otherwise, load the return | |
540 | address obtained from leafproc_return () into the rip. */ | |
541 | ||
542 | leaf_return_addr = leafproc_return (current_fi->pc); | |
543 | if (!leaf_return_addr) | |
544 | { | |
545 | /* Non-leaf procedure. Restore local registers, incl IP. */ | |
546 | prev_fi = get_frame_info (get_prev_frame (FRAME_INFO_ID (current_fi))); | |
547 | read_memory (prev_fi->frame, local_regs_buf, sizeof (local_regs_buf)); | |
548 | write_register_bytes (REGISTER_BYTE (R0_REGNUM), local_regs_buf, | |
549 | sizeof (local_regs_buf)); | |
550 | ||
551 | /* Restore frame pointer. */ | |
552 | write_register (FP_REGNUM, prev_fi->frame); | |
553 | } | |
554 | else | |
555 | { | |
556 | /* Leaf procedure. Just restore the return address into the IP. */ | |
557 | write_register (RIP_REGNUM, leaf_return_addr); | |
558 | } | |
559 | ||
560 | /* Now restore any global regs that the current function had saved. */ | |
561 | get_frame_saved_regs (current_fi, &fsr); | |
562 | for (i = G0_REGNUM; i < G14_REGNUM; i++) | |
563 | { | |
564 | if (save_addr = fsr.regs[i]) | |
565 | write_register (i, read_memory_integer (save_addr, 4)); | |
566 | } | |
567 | ||
568 | /* Flush the frame cache, create a frame for the new innermost frame, | |
569 | and make it the current frame. */ | |
570 | ||
571 | flush_cached_frames (); | |
572 | set_current_frame (create_new_frame (read_register (FP_REGNUM), read_pc ())); | |
573 | } | |
574 | ||
67ac9759 JK |
575 | /* Given a 960 stop code (fault or trace), return the signal which |
576 | corresponds. */ | |
dd3b648e | 577 | |
67ac9759 JK |
578 | enum target_signal |
579 | i960_fault_to_signal (fault) | |
580 | int fault; | |
dd3b648e | 581 | { |
67ac9759 JK |
582 | switch (fault) |
583 | { | |
584 | case 0: return TARGET_SIGNAL_BUS; /* parallel fault */ | |
585 | case 1: return TARGET_SIGNAL_UNKNOWN; | |
24a11a79 | 586 | case 2: return TARGET_SIGNAL_ILL; /* operation fault */ |
67ac9759 JK |
587 | case 3: return TARGET_SIGNAL_FPE; /* arithmetic fault */ |
588 | case 4: return TARGET_SIGNAL_FPE; /* floating point fault */ | |
24a11a79 JK |
589 | |
590 | /* constraint fault. This appears not to distinguish between | |
591 | a range constraint fault (which should be SIGFPE) and a privileged | |
592 | fault (which should be SIGILL). */ | |
593 | case 5: return TARGET_SIGNAL_ILL; | |
594 | ||
67ac9759 | 595 | case 6: return TARGET_SIGNAL_SEGV; /* virtual memory fault */ |
24a11a79 JK |
596 | |
597 | /* protection fault. This is for an out-of-range argument to | |
598 | "calls". I guess it also could be SIGILL. */ | |
599 | case 7: return TARGET_SIGNAL_SEGV; | |
600 | ||
67ac9759 JK |
601 | case 8: return TARGET_SIGNAL_BUS; /* machine fault */ |
602 | case 9: return TARGET_SIGNAL_BUS; /* structural fault */ | |
24a11a79 | 603 | case 0xa: return TARGET_SIGNAL_ILL; /* type fault */ |
67ac9759 JK |
604 | case 0xb: return TARGET_SIGNAL_UNKNOWN; /* reserved fault */ |
605 | case 0xc: return TARGET_SIGNAL_BUS; /* process fault */ | |
606 | case 0xd: return TARGET_SIGNAL_SEGV; /* descriptor fault */ | |
607 | case 0xe: return TARGET_SIGNAL_BUS; /* event fault */ | |
608 | case 0xf: return TARGET_SIGNAL_UNKNOWN; /* reserved fault */ | |
609 | case 0x10: return TARGET_SIGNAL_TRAP; /* single-step trace */ | |
610 | case 0x11: return TARGET_SIGNAL_TRAP; /* branch trace */ | |
611 | case 0x12: return TARGET_SIGNAL_TRAP; /* call trace */ | |
612 | case 0x13: return TARGET_SIGNAL_TRAP; /* return trace */ | |
613 | case 0x14: return TARGET_SIGNAL_TRAP; /* pre-return trace */ | |
614 | case 0x15: return TARGET_SIGNAL_TRAP; /* supervisor call trace */ | |
615 | case 0x16: return TARGET_SIGNAL_TRAP; /* breakpoint trace */ | |
616 | default: return TARGET_SIGNAL_UNKNOWN; | |
617 | } | |
dd3b648e RP |
618 | } |
619 | ||
620 | /* Initialization stub */ | |
621 | ||
976bb0be | 622 | void |
dd3b648e RP |
623 | _initialize_i960_tdep () |
624 | { | |
625 | check_host (); | |
626 | } |