]>
Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Target-machine dependent code for Motorola 88000 series, for GDB. |
6d531722 AC |
2 | |
3 | Copyright 1988, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998, | |
4 | 2000, 2001, 2002 Free Software Foundation, Inc. | |
c906108c | 5 | |
c5aa993b | 6 | This file is part of GDB. |
c906108c | 7 | |
c5aa993b JM |
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 | |
10 | the Free Software Foundation; either version 2 of the License, or | |
11 | (at your option) any later version. | |
c906108c | 12 | |
c5aa993b JM |
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. | |
c906108c | 17 | |
c5aa993b JM |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software | |
20 | Foundation, Inc., 59 Temple Place - Suite 330, | |
21 | Boston, MA 02111-1307, USA. */ | |
c906108c SS |
22 | |
23 | #include "defs.h" | |
24 | #include "frame.h" | |
25 | #include "inferior.h" | |
26 | #include "value.h" | |
27 | #include "gdbcore.h" | |
28 | #include "symtab.h" | |
29 | #include "setjmp.h" | |
30 | #include "value.h" | |
4e052eda | 31 | #include "regcache.h" |
c906108c SS |
32 | |
33 | /* Size of an instruction */ | |
34 | #define BYTES_PER_88K_INSN 4 | |
35 | ||
36 | void frame_find_saved_regs (); | |
37 | ||
38 | /* Is this target an m88110? Otherwise assume m88100. This has | |
39 | relevance for the ways in which we screw with instruction pointers. */ | |
40 | ||
41 | int target_is_m88110 = 0; | |
42 | ||
6d531722 AC |
43 | void |
44 | m88k_target_write_pc (CORE_ADDR pc, ptid_t ptid) | |
45 | { | |
46 | /* According to the MC88100 RISC Microprocessor User's Manual, | |
47 | section 6.4.3.1.2: | |
48 | ||
49 | ... can be made to return to a particular instruction by placing | |
50 | a valid instruction address in the SNIP and the next sequential | |
51 | instruction address in the SFIP (with V bits set and E bits | |
52 | clear). The rte resumes execution at the instruction pointed to | |
53 | by the SNIP, then the SFIP. | |
54 | ||
55 | The E bit is the least significant bit (bit 0). The V (valid) | |
56 | bit is bit 1. This is why we logical or 2 into the values we are | |
57 | writing below. It turns out that SXIP plays no role when | |
58 | returning from an exception so nothing special has to be done | |
59 | with it. We could even (presumably) give it a totally bogus | |
60 | value. | |
61 | ||
62 | -- Kevin Buettner */ | |
63 | ||
64 | write_register_pid (SXIP_REGNUM, pc, ptid); | |
65 | write_register_pid (SNIP_REGNUM, (pc | 2), ptid); | |
66 | write_register_pid (SFIP_REGNUM, (pc | 2) + 4, ptid); | |
67 | } | |
68 | ||
2c10d744 AC |
69 | /* The type of a register. */ |
70 | struct type * | |
71 | m88k_register_type (int regnum) | |
72 | { | |
73 | if (regnum >= XFP_REGNUM) | |
74 | return builtin_type_m88110_ext; | |
75 | else if (regnum == PC_REGNUM || regnum == FP_REGNUM || regnum == SP_REGNUM) | |
76 | return builtin_type_void_func_ptr; | |
77 | else | |
78 | return builtin_type_int32; | |
79 | } | |
80 | ||
81 | ||
c906108c SS |
82 | /* The m88k kernel aligns all instructions on 4-byte boundaries. The |
83 | kernel also uses the least significant two bits for its own hocus | |
84 | pocus. When gdb receives an address from the kernel, it needs to | |
85 | preserve those right-most two bits, but gdb also needs to be careful | |
86 | to realize that those two bits are not really a part of the address | |
87 | of an instruction. Shrug. */ | |
88 | ||
89 | CORE_ADDR | |
fba45db2 | 90 | m88k_addr_bits_remove (CORE_ADDR addr) |
c906108c SS |
91 | { |
92 | return ((addr) & ~3); | |
93 | } | |
94 | ||
95 | ||
96 | /* Given a GDB frame, determine the address of the calling function's frame. | |
97 | This will be used to create a new GDB frame struct, and then | |
98 | INIT_EXTRA_FRAME_INFO and INIT_FRAME_PC will be called for the new frame. | |
99 | ||
100 | For us, the frame address is its stack pointer value, so we look up | |
101 | the function prologue to determine the caller's sp value, and return it. */ | |
102 | ||
103 | CORE_ADDR | |
fba45db2 | 104 | frame_chain (struct frame_info *thisframe) |
c906108c SS |
105 | { |
106 | ||
107 | frame_find_saved_regs (thisframe, (struct frame_saved_regs *) 0); | |
108 | /* NOTE: this depends on frame_find_saved_regs returning the VALUE, not | |
c5aa993b JM |
109 | the ADDRESS, of SP_REGNUM. It also depends on the cache of |
110 | frame_find_saved_regs results. */ | |
c906108c SS |
111 | if (thisframe->fsr->regs[SP_REGNUM]) |
112 | return thisframe->fsr->regs[SP_REGNUM]; | |
113 | else | |
114 | return thisframe->frame; /* Leaf fn -- next frame up has same SP. */ | |
115 | } | |
116 | ||
117 | int | |
fba45db2 | 118 | frameless_function_invocation (struct frame_info *frame) |
c906108c SS |
119 | { |
120 | ||
121 | frame_find_saved_regs (frame, (struct frame_saved_regs *) 0); | |
122 | /* NOTE: this depends on frame_find_saved_regs returning the VALUE, not | |
c5aa993b JM |
123 | the ADDRESS, of SP_REGNUM. It also depends on the cache of |
124 | frame_find_saved_regs results. */ | |
c906108c SS |
125 | if (frame->fsr->regs[SP_REGNUM]) |
126 | return 0; /* Frameful -- return addr saved somewhere */ | |
127 | else | |
128 | return 1; /* Frameless -- no saved return address */ | |
129 | } | |
130 | ||
131 | void | |
fba45db2 | 132 | init_extra_frame_info (int fromleaf, struct frame_info *frame) |
c906108c | 133 | { |
c5aa993b JM |
134 | frame->fsr = 0; /* Not yet allocated */ |
135 | frame->args_pointer = 0; /* Unknown */ | |
c906108c SS |
136 | frame->locals_pointer = 0; /* Unknown */ |
137 | } | |
138 | \f | |
139 | /* Examine an m88k function prologue, recording the addresses at which | |
140 | registers are saved explicitly by the prologue code, and returning | |
141 | the address of the first instruction after the prologue (but not | |
142 | after the instruction at address LIMIT, as explained below). | |
143 | ||
144 | LIMIT places an upper bound on addresses of the instructions to be | |
145 | examined. If the prologue code scan reaches LIMIT, the scan is | |
146 | aborted and LIMIT is returned. This is used, when examining the | |
147 | prologue for the current frame, to keep examine_prologue () from | |
148 | claiming that a given register has been saved when in fact the | |
149 | instruction that saves it has not yet been executed. LIMIT is used | |
150 | at other times to stop the scan when we hit code after the true | |
151 | function prologue (e.g. for the first source line) which might | |
152 | otherwise be mistaken for function prologue. | |
153 | ||
154 | The format of the function prologue matched by this routine is | |
155 | derived from examination of the source to gcc 1.95, particularly | |
156 | the routine output_prologue () in config/out-m88k.c. | |
157 | ||
c5aa993b | 158 | subu r31,r31,n # stack pointer update |
c906108c | 159 | |
c5aa993b | 160 | (st rn,r31,offset)? # save incoming regs |
c906108c SS |
161 | (st.d rn,r31,offset)? |
162 | ||
c5aa993b | 163 | (addu r30,r31,n)? # frame pointer update |
c906108c | 164 | |
c5aa993b | 165 | (pic sequence)? # PIC code prologue |
c906108c | 166 | |
c5aa993b JM |
167 | (or rn,rm,0)? # Move parameters to other regs |
168 | */ | |
c906108c SS |
169 | |
170 | /* Macros for extracting fields from instructions. */ | |
171 | ||
172 | #define BITMASK(pos, width) (((0x1 << (width)) - 1) << (pos)) | |
173 | #define EXTRACT_FIELD(val, pos, width) ((val) >> (pos) & BITMASK (0, width)) | |
174 | #define SUBU_OFFSET(x) ((unsigned)(x & 0xFFFF)) | |
175 | #define ST_OFFSET(x) ((unsigned)((x) & 0xFFFF)) | |
176 | #define ST_SRC(x) EXTRACT_FIELD ((x), 21, 5) | |
177 | #define ADDU_OFFSET(x) ((unsigned)(x & 0xFFFF)) | |
178 | ||
179 | /* | |
180 | * prologue_insn_tbl is a table of instructions which may comprise a | |
181 | * function prologue. Associated with each table entry (corresponding | |
182 | * to a single instruction or group of instructions), is an action. | |
183 | * This action is used by examine_prologue (below) to determine | |
184 | * the state of certain machine registers and where the stack frame lives. | |
185 | */ | |
186 | ||
c5aa993b JM |
187 | enum prologue_insn_action |
188 | { | |
c906108c SS |
189 | PIA_SKIP, /* don't care what the instruction does */ |
190 | PIA_NOTE_ST, /* note register stored and where */ | |
191 | PIA_NOTE_STD, /* note pair of registers stored and where */ | |
192 | PIA_NOTE_SP_ADJUSTMENT, /* note stack pointer adjustment */ | |
193 | PIA_NOTE_FP_ASSIGNMENT, /* note frame pointer assignment */ | |
194 | PIA_NOTE_PROLOGUE_END, /* no more prologue */ | |
195 | }; | |
196 | ||
c5aa993b JM |
197 | struct prologue_insns |
198 | { | |
c906108c SS |
199 | unsigned long insn; |
200 | unsigned long mask; | |
201 | enum prologue_insn_action action; | |
c5aa993b | 202 | }; |
c906108c | 203 | |
c5aa993b JM |
204 | struct prologue_insns prologue_insn_tbl[] = |
205 | { | |
c906108c | 206 | /* Various register move instructions */ |
c5aa993b JM |
207 | {0x58000000, 0xf800ffff, PIA_SKIP}, /* or/or.u with immed of 0 */ |
208 | {0xf4005800, 0xfc1fffe0, PIA_SKIP}, /* or rd, r0, rs */ | |
209 | {0xf4005800, 0xfc00ffff, PIA_SKIP}, /* or rd, rs, r0 */ | |
c906108c SS |
210 | |
211 | /* Stack pointer setup: "subu sp, sp, n" where n is a multiple of 8 */ | |
c5aa993b | 212 | {0x67ff0000, 0xffff0007, PIA_NOTE_SP_ADJUSTMENT}, |
c906108c SS |
213 | |
214 | /* Frame pointer assignment: "addu r30, r31, n" */ | |
c5aa993b | 215 | {0x63df0000, 0xffff0000, PIA_NOTE_FP_ASSIGNMENT}, |
c906108c SS |
216 | |
217 | /* Store to stack instructions; either "st rx, sp, n" or "st.d rx, sp, n" */ | |
c5aa993b JM |
218 | {0x241f0000, 0xfc1f0000, PIA_NOTE_ST}, /* st rx, sp, n */ |
219 | {0x201f0000, 0xfc1f0000, PIA_NOTE_STD}, /* st.d rs, sp, n */ | |
c906108c SS |
220 | |
221 | /* Instructions needed for setting up r25 for pic code. */ | |
c5aa993b JM |
222 | {0x5f200000, 0xffff0000, PIA_SKIP}, /* or.u r25, r0, offset_high */ |
223 | {0xcc000002, 0xffffffff, PIA_SKIP}, /* bsr.n Lab */ | |
224 | {0x5b390000, 0xffff0000, PIA_SKIP}, /* or r25, r25, offset_low */ | |
225 | {0xf7396001, 0xffffffff, PIA_SKIP}, /* Lab: addu r25, r25, r1 */ | |
c906108c SS |
226 | |
227 | /* Various branch or jump instructions which have a delay slot -- these | |
228 | do not form part of the prologue, but the instruction in the delay | |
229 | slot might be a store instruction which should be noted. */ | |
c5aa993b JM |
230 | {0xc4000000, 0xe4000000, PIA_NOTE_PROLOGUE_END}, |
231 | /* br.n, bsr.n, bb0.n, or bb1.n */ | |
232 | {0xec000000, 0xfc000000, PIA_NOTE_PROLOGUE_END}, /* bcnd.n */ | |
233 | {0xf400c400, 0xfffff7e0, PIA_NOTE_PROLOGUE_END} /* jmp.n or jsr.n */ | |
c906108c SS |
234 | |
235 | }; | |
236 | ||
237 | ||
238 | /* Fetch the instruction at ADDR, returning 0 if ADDR is beyond LIM or | |
239 | is not the address of a valid instruction, the address of the next | |
240 | instruction beyond ADDR otherwise. *PWORD1 receives the first word | |
241 | of the instruction. */ | |
242 | ||
243 | #define NEXT_PROLOGUE_INSN(addr, lim, pword1) \ | |
244 | (((addr) < (lim)) ? next_insn (addr, pword1) : 0) | |
245 | ||
246 | /* Read the m88k instruction at 'memaddr' and return the address of | |
247 | the next instruction after that, or 0 if 'memaddr' is not the | |
248 | address of a valid instruction. The instruction | |
249 | is stored at 'pword1'. */ | |
250 | ||
251 | CORE_ADDR | |
fba45db2 | 252 | next_insn (CORE_ADDR memaddr, unsigned long *pword1) |
c906108c SS |
253 | { |
254 | *pword1 = read_memory_integer (memaddr, BYTES_PER_88K_INSN); | |
255 | return memaddr + BYTES_PER_88K_INSN; | |
256 | } | |
257 | ||
258 | /* Read a register from frames called by us (or from the hardware regs). */ | |
259 | ||
260 | static int | |
fba45db2 | 261 | read_next_frame_reg (struct frame_info *frame, int regno) |
c906108c | 262 | { |
c5aa993b JM |
263 | for (; frame; frame = frame->next) |
264 | { | |
c906108c SS |
265 | if (regno == SP_REGNUM) |
266 | return FRAME_FP (frame); | |
267 | else if (frame->fsr->regs[regno]) | |
c5aa993b JM |
268 | return read_memory_integer (frame->fsr->regs[regno], 4); |
269 | } | |
270 | return read_register (regno); | |
c906108c SS |
271 | } |
272 | ||
273 | /* Examine the prologue of a function. `ip' points to the first instruction. | |
274 | `limit' is the limit of the prologue (e.g. the addr of the first | |
275 | linenumber, or perhaps the program counter if we're stepping through). | |
276 | `frame_sp' is the stack pointer value in use in this frame. | |
277 | `fsr' is a pointer to a frame_saved_regs structure into which we put | |
278 | info about the registers saved by this frame. | |
279 | `fi' is a struct frame_info pointer; we fill in various fields in it | |
280 | to reflect the offsets of the arg pointer and the locals pointer. */ | |
281 | ||
282 | static CORE_ADDR | |
fba45db2 KB |
283 | examine_prologue (register CORE_ADDR ip, register CORE_ADDR limit, |
284 | CORE_ADDR frame_sp, struct frame_saved_regs *fsr, | |
285 | struct frame_info *fi) | |
c906108c SS |
286 | { |
287 | register CORE_ADDR next_ip; | |
288 | register int src; | |
971ff545 | 289 | unsigned long insn; |
c906108c SS |
290 | int size, offset; |
291 | char must_adjust[32]; /* If set, must adjust offsets in fsr */ | |
292 | int sp_offset = -1; /* -1 means not set (valid must be mult of 8) */ | |
293 | int fp_offset = -1; /* -1 means not set */ | |
294 | CORE_ADDR frame_fp; | |
295 | CORE_ADDR prologue_end = 0; | |
296 | ||
297 | memset (must_adjust, '\0', sizeof (must_adjust)); | |
298 | next_ip = NEXT_PROLOGUE_INSN (ip, limit, &insn); | |
299 | ||
300 | while (next_ip) | |
301 | { | |
c5aa993b | 302 | struct prologue_insns *pip; |
c906108c | 303 | |
c5aa993b JM |
304 | for (pip = prologue_insn_tbl; (insn & pip->mask) != pip->insn;) |
305 | if (++pip >= prologue_insn_tbl + sizeof prologue_insn_tbl) | |
306 | goto end_of_prologue_found; /* not a prologue insn */ | |
c906108c SS |
307 | |
308 | switch (pip->action) | |
309 | { | |
c5aa993b JM |
310 | case PIA_NOTE_ST: |
311 | case PIA_NOTE_STD: | |
312 | if (sp_offset != -1) | |
313 | { | |
314 | src = ST_SRC (insn); | |
315 | offset = ST_OFFSET (insn); | |
316 | must_adjust[src] = 1; | |
317 | fsr->regs[src++] = offset; /* Will be adjusted later */ | |
318 | if (pip->action == PIA_NOTE_STD && src < 32) | |
319 | { | |
320 | offset += 4; | |
321 | must_adjust[src] = 1; | |
322 | fsr->regs[src++] = offset; | |
323 | } | |
c906108c | 324 | } |
c5aa993b JM |
325 | else |
326 | goto end_of_prologue_found; | |
327 | break; | |
328 | case PIA_NOTE_SP_ADJUSTMENT: | |
329 | if (sp_offset == -1) | |
330 | sp_offset = -SUBU_OFFSET (insn); | |
331 | else | |
332 | goto end_of_prologue_found; | |
333 | break; | |
334 | case PIA_NOTE_FP_ASSIGNMENT: | |
335 | if (fp_offset == -1) | |
336 | fp_offset = ADDU_OFFSET (insn); | |
337 | else | |
338 | goto end_of_prologue_found; | |
339 | break; | |
340 | case PIA_NOTE_PROLOGUE_END: | |
341 | if (!prologue_end) | |
342 | prologue_end = ip; | |
343 | break; | |
344 | case PIA_SKIP: | |
345 | default: | |
346 | /* Do nothing */ | |
347 | break; | |
c906108c SS |
348 | } |
349 | ||
350 | ip = next_ip; | |
351 | next_ip = NEXT_PROLOGUE_INSN (ip, limit, &insn); | |
352 | } | |
353 | ||
354 | end_of_prologue_found: | |
355 | ||
c5aa993b JM |
356 | if (prologue_end) |
357 | ip = prologue_end; | |
c906108c SS |
358 | |
359 | /* We're done with the prologue. If we don't care about the stack | |
360 | frame itself, just return. (Note that fsr->regs has been trashed, | |
361 | but the one caller who calls with fi==0 passes a dummy there.) */ | |
362 | ||
363 | if (fi == 0) | |
364 | return ip; | |
365 | ||
366 | /* | |
367 | OK, now we have: | |
368 | ||
c5aa993b JM |
369 | sp_offset original (before any alloca calls) displacement of SP |
370 | (will be negative). | |
c906108c | 371 | |
c5aa993b JM |
372 | fp_offset displacement from original SP to the FP for this frame |
373 | or -1. | |
c906108c | 374 | |
c5aa993b JM |
375 | fsr->regs[0..31] displacement from original SP to the stack |
376 | location where reg[0..31] is stored. | |
c906108c | 377 | |
c5aa993b | 378 | must_adjust[0..31] set if corresponding offset was set. |
c906108c SS |
379 | |
380 | If alloca has been called between the function prologue and the current | |
381 | IP, then the current SP (frame_sp) will not be the original SP as set by | |
382 | the function prologue. If the current SP is not the original SP, then the | |
383 | compiler will have allocated an FP for this frame, fp_offset will be set, | |
384 | and we can use it to calculate the original SP. | |
385 | ||
386 | Then, we figure out where the arguments and locals are, and relocate the | |
387 | offsets in fsr->regs to absolute addresses. */ | |
388 | ||
c5aa993b JM |
389 | if (fp_offset != -1) |
390 | { | |
391 | /* We have a frame pointer, so get it, and base our calc's on it. */ | |
392 | frame_fp = (CORE_ADDR) read_next_frame_reg (fi->next, ACTUAL_FP_REGNUM); | |
393 | frame_sp = frame_fp - fp_offset; | |
394 | } | |
395 | else | |
396 | { | |
397 | /* We have no frame pointer, therefore frame_sp is still the same value | |
398 | as set by prologue. But where is the frame itself? */ | |
399 | if (must_adjust[SRP_REGNUM]) | |
400 | { | |
401 | /* Function header saved SRP (r1), the return address. Frame starts | |
402 | 4 bytes down from where it was saved. */ | |
403 | frame_fp = frame_sp + fsr->regs[SRP_REGNUM] - 4; | |
404 | fi->locals_pointer = frame_fp; | |
405 | } | |
406 | else | |
407 | { | |
408 | /* Function header didn't save SRP (r1), so we are in a leaf fn or | |
409 | are otherwise confused. */ | |
410 | frame_fp = -1; | |
411 | } | |
c906108c | 412 | } |
c906108c SS |
413 | |
414 | /* The locals are relative to the FP (whether it exists as an allocated | |
415 | register, or just as an assumed offset from the SP) */ | |
416 | fi->locals_pointer = frame_fp; | |
417 | ||
418 | /* The arguments are just above the SP as it was before we adjusted it | |
419 | on entry. */ | |
420 | fi->args_pointer = frame_sp - sp_offset; | |
421 | ||
422 | /* Now that we know the SP value used by the prologue, we know where | |
423 | it saved all the registers. */ | |
424 | for (src = 0; src < 32; src++) | |
425 | if (must_adjust[src]) | |
426 | fsr->regs[src] += frame_sp; | |
c5aa993b | 427 | |
c906108c SS |
428 | /* The saved value of the SP is always known. */ |
429 | /* (we hope...) */ | |
c5aa993b JM |
430 | if (fsr->regs[SP_REGNUM] != 0 |
431 | && fsr->regs[SP_REGNUM] != frame_sp - sp_offset) | |
971ff545 | 432 | fprintf_unfiltered (gdb_stderr, "Bad saved SP value %lx != %lx, offset %x!\n", |
c5aa993b JM |
433 | fsr->regs[SP_REGNUM], |
434 | frame_sp - sp_offset, sp_offset); | |
c906108c SS |
435 | |
436 | fsr->regs[SP_REGNUM] = frame_sp - sp_offset; | |
437 | ||
438 | return (ip); | |
439 | } | |
440 | ||
441 | /* Given an ip value corresponding to the start of a function, | |
442 | return the ip of the first instruction after the function | |
443 | prologue. */ | |
444 | ||
445 | CORE_ADDR | |
afd64b4e | 446 | m88k_skip_prologue (CORE_ADDR ip) |
c906108c SS |
447 | { |
448 | struct frame_saved_regs saved_regs_dummy; | |
449 | struct symtab_and_line sal; | |
450 | CORE_ADDR limit; | |
451 | ||
452 | sal = find_pc_line (ip, 0); | |
453 | limit = (sal.end) ? sal.end : 0xffffffff; | |
454 | ||
455 | return (examine_prologue (ip, limit, (CORE_ADDR) 0, &saved_regs_dummy, | |
c5aa993b | 456 | (struct frame_info *) 0)); |
c906108c SS |
457 | } |
458 | ||
459 | /* Put here the code to store, into a struct frame_saved_regs, | |
460 | the addresses of the saved registers of frame described by FRAME_INFO. | |
461 | This includes special registers such as pc and fp saved in special | |
462 | ways in the stack frame. sp is even more special: | |
463 | the address we return for it IS the sp for the next frame. | |
464 | ||
465 | We cache the result of doing this in the frame_obstack, since it is | |
466 | fairly expensive. */ | |
467 | ||
468 | void | |
fba45db2 | 469 | frame_find_saved_regs (struct frame_info *fi, struct frame_saved_regs *fsr) |
c906108c SS |
470 | { |
471 | register struct frame_saved_regs *cache_fsr; | |
472 | CORE_ADDR ip; | |
473 | struct symtab_and_line sal; | |
474 | CORE_ADDR limit; | |
475 | ||
476 | if (!fi->fsr) | |
477 | { | |
478 | cache_fsr = (struct frame_saved_regs *) | |
479 | frame_obstack_alloc (sizeof (struct frame_saved_regs)); | |
480 | memset (cache_fsr, '\0', sizeof (struct frame_saved_regs)); | |
481 | fi->fsr = cache_fsr; | |
482 | ||
483 | /* Find the start and end of the function prologue. If the PC | |
c5aa993b JM |
484 | is in the function prologue, we only consider the part that |
485 | has executed already. In the case where the PC is not in | |
486 | the function prologue, we set limit to two instructions beyond | |
487 | where the prologue ends in case if any of the prologue instructions | |
488 | were moved into a delay slot of a branch instruction. */ | |
489 | ||
c906108c SS |
490 | ip = get_pc_function_start (fi->pc); |
491 | sal = find_pc_line (ip, 0); | |
c5aa993b JM |
492 | limit = (sal.end && sal.end < fi->pc) ? sal.end + 2 * BYTES_PER_88K_INSN |
493 | : fi->pc; | |
c906108c SS |
494 | |
495 | /* This will fill in fields in *fi as well as in cache_fsr. */ | |
496 | #ifdef SIGTRAMP_FRAME_FIXUP | |
497 | if (fi->signal_handler_caller) | |
c5aa993b | 498 | SIGTRAMP_FRAME_FIXUP (fi->frame); |
c906108c SS |
499 | #endif |
500 | examine_prologue (ip, limit, fi->frame, cache_fsr, fi); | |
501 | #ifdef SIGTRAMP_SP_FIXUP | |
502 | if (fi->signal_handler_caller && fi->fsr->regs[SP_REGNUM]) | |
c5aa993b | 503 | SIGTRAMP_SP_FIXUP (fi->fsr->regs[SP_REGNUM]); |
c906108c SS |
504 | #endif |
505 | } | |
506 | ||
507 | if (fsr) | |
508 | *fsr = *fi->fsr; | |
509 | } | |
510 | ||
511 | /* Return the address of the locals block for the frame | |
512 | described by FI. Returns 0 if the address is unknown. | |
513 | NOTE! Frame locals are referred to by negative offsets from the | |
514 | argument pointer, so this is the same as frame_args_address(). */ | |
515 | ||
516 | CORE_ADDR | |
fba45db2 | 517 | frame_locals_address (struct frame_info *fi) |
c906108c SS |
518 | { |
519 | struct frame_saved_regs fsr; | |
520 | ||
c5aa993b | 521 | if (fi->args_pointer) /* Cached value is likely there. */ |
c906108c SS |
522 | return fi->args_pointer; |
523 | ||
524 | /* Nope, generate it. */ | |
525 | ||
526 | get_frame_saved_regs (fi, &fsr); | |
527 | ||
528 | return fi->args_pointer; | |
529 | } | |
530 | ||
531 | /* Return the address of the argument block for the frame | |
532 | described by FI. Returns 0 if the address is unknown. */ | |
533 | ||
534 | CORE_ADDR | |
fba45db2 | 535 | frame_args_address (struct frame_info *fi) |
c906108c SS |
536 | { |
537 | struct frame_saved_regs fsr; | |
538 | ||
539 | if (fi->args_pointer) /* Cached value is likely there. */ | |
540 | return fi->args_pointer; | |
541 | ||
542 | /* Nope, generate it. */ | |
543 | ||
544 | get_frame_saved_regs (fi, &fsr); | |
545 | ||
546 | return fi->args_pointer; | |
547 | } | |
548 | ||
549 | /* Return the saved PC from this frame. | |
550 | ||
551 | If the frame has a memory copy of SRP_REGNUM, use that. If not, | |
552 | just use the register SRP_REGNUM itself. */ | |
553 | ||
554 | CORE_ADDR | |
fba45db2 | 555 | frame_saved_pc (struct frame_info *frame) |
c906108c | 556 | { |
c5aa993b | 557 | return read_next_frame_reg (frame, SRP_REGNUM); |
c906108c SS |
558 | } |
559 | ||
560 | ||
561 | #define DUMMY_FRAME_SIZE 192 | |
562 | ||
563 | static void | |
fba45db2 | 564 | write_word (CORE_ADDR sp, ULONGEST word) |
c906108c SS |
565 | { |
566 | register int len = REGISTER_SIZE; | |
567 | char buffer[MAX_REGISTER_RAW_SIZE]; | |
568 | ||
569 | store_unsigned_integer (buffer, len, word); | |
570 | write_memory (sp, buffer, len); | |
571 | } | |
572 | ||
573 | void | |
fba45db2 | 574 | m88k_push_dummy_frame (void) |
c906108c SS |
575 | { |
576 | register CORE_ADDR sp = read_register (SP_REGNUM); | |
577 | register int rn; | |
578 | int offset; | |
579 | ||
580 | sp -= DUMMY_FRAME_SIZE; /* allocate a bunch of space */ | |
581 | ||
c5aa993b JM |
582 | for (rn = 0, offset = 0; rn <= SP_REGNUM; rn++, offset += 4) |
583 | write_word (sp + offset, read_register (rn)); | |
584 | ||
585 | write_word (sp + offset, read_register (SXIP_REGNUM)); | |
c906108c SS |
586 | offset += 4; |
587 | ||
c5aa993b | 588 | write_word (sp + offset, read_register (SNIP_REGNUM)); |
c906108c SS |
589 | offset += 4; |
590 | ||
c5aa993b | 591 | write_word (sp + offset, read_register (SFIP_REGNUM)); |
c906108c SS |
592 | offset += 4; |
593 | ||
c5aa993b | 594 | write_word (sp + offset, read_register (PSR_REGNUM)); |
c906108c SS |
595 | offset += 4; |
596 | ||
c5aa993b | 597 | write_word (sp + offset, read_register (FPSR_REGNUM)); |
c906108c SS |
598 | offset += 4; |
599 | ||
c5aa993b | 600 | write_word (sp + offset, read_register (FPCR_REGNUM)); |
c906108c SS |
601 | offset += 4; |
602 | ||
603 | write_register (SP_REGNUM, sp); | |
604 | write_register (ACTUAL_FP_REGNUM, sp); | |
605 | } | |
606 | ||
607 | void | |
fba45db2 | 608 | pop_frame (void) |
c906108c SS |
609 | { |
610 | register struct frame_info *frame = get_current_frame (); | |
c906108c SS |
611 | register int regnum; |
612 | struct frame_saved_regs fsr; | |
613 | ||
c906108c SS |
614 | get_frame_saved_regs (frame, &fsr); |
615 | ||
971ff545 | 616 | if (PC_IN_CALL_DUMMY (read_pc (), read_register (SP_REGNUM), frame->frame)) |
c906108c SS |
617 | { |
618 | /* FIXME: I think get_frame_saved_regs should be handling this so | |
c5aa993b JM |
619 | that we can deal with the saved registers properly (e.g. frame |
620 | 1 is a call dummy, the user types "frame 2" and then "print $ps"). */ | |
c906108c SS |
621 | register CORE_ADDR sp = read_register (ACTUAL_FP_REGNUM); |
622 | int offset; | |
623 | ||
c5aa993b JM |
624 | for (regnum = 0, offset = 0; regnum <= SP_REGNUM; regnum++, offset += 4) |
625 | (void) write_register (regnum, read_memory_integer (sp + offset, 4)); | |
626 | ||
627 | write_register (SXIP_REGNUM, read_memory_integer (sp + offset, 4)); | |
c906108c SS |
628 | offset += 4; |
629 | ||
c5aa993b | 630 | write_register (SNIP_REGNUM, read_memory_integer (sp + offset, 4)); |
c906108c SS |
631 | offset += 4; |
632 | ||
c5aa993b | 633 | write_register (SFIP_REGNUM, read_memory_integer (sp + offset, 4)); |
c906108c SS |
634 | offset += 4; |
635 | ||
c5aa993b | 636 | write_register (PSR_REGNUM, read_memory_integer (sp + offset, 4)); |
c906108c SS |
637 | offset += 4; |
638 | ||
c5aa993b | 639 | write_register (FPSR_REGNUM, read_memory_integer (sp + offset, 4)); |
c906108c SS |
640 | offset += 4; |
641 | ||
c5aa993b | 642 | write_register (FPCR_REGNUM, read_memory_integer (sp + offset, 4)); |
c906108c SS |
643 | offset += 4; |
644 | ||
645 | } | |
c5aa993b | 646 | else |
c906108c | 647 | { |
c5aa993b JM |
648 | for (regnum = FP_REGNUM; regnum > 0; regnum--) |
649 | if (fsr.regs[regnum]) | |
650 | write_register (regnum, | |
651 | read_memory_integer (fsr.regs[regnum], 4)); | |
c906108c SS |
652 | write_pc (frame_saved_pc (frame)); |
653 | } | |
654 | reinit_frame_cache (); | |
655 | } | |
656 | ||
657 | void | |
fba45db2 | 658 | _initialize_m88k_tdep (void) |
c906108c SS |
659 | { |
660 | tm_print_insn = print_insn_m88k; | |
661 | } |