]>
Commit | Line | Data |
---|---|---|
ea3c0839 JG |
1 | /* Target-machine dependent code for Motorola 88000 series, for GDB. |
2 | Copyright (C) 1988, 1990, 1991 Free Software Foundation, Inc. | |
8aa13b87 JK |
3 | |
4 | This file is part of GDB. | |
5 | ||
99a7de40 | 6 | This program is free software; you can redistribute it and/or modify |
8aa13b87 | 7 | it under the terms of the GNU General Public License as published by |
99a7de40 JG |
8 | the Free Software Foundation; either version 2 of the License, or |
9 | (at your option) any later version. | |
8aa13b87 | 10 | |
99a7de40 | 11 | This program is distributed in the hope that it will be useful, |
8aa13b87 JK |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
99a7de40 JG |
17 | along with this program; if not, write to the Free Software |
18 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
8aa13b87 | 19 | |
8aa13b87 | 20 | #include "defs.h" |
8aa13b87 JK |
21 | #include "frame.h" |
22 | #include "inferior.h" | |
23 | #include "value.h" | |
8aa13b87 | 24 | #include "gdbcore.h" |
8aa13b87 JK |
25 | |
26 | #include "symtab.h" | |
27 | #include "setjmp.h" | |
28 | #include "value.h" | |
29 | ||
2a770cac JG |
30 | /* Size of an instruction */ |
31 | #define BYTES_PER_88K_INSN 4 | |
32 | ||
ea3c0839 | 33 | void frame_find_saved_regs (); |
8aa13b87 | 34 | |
817ac7f8 RP |
35 | /* is this target an m88110? Otherwise assume m88100. This has |
36 | relevance for the ways in which we screw with instruction pointers. */ | |
37 | int target_is_m88110 = 0; | |
38 | ||
ea3c0839 JG |
39 | /* Given a GDB frame, determine the address of the calling function's frame. |
40 | This will be used to create a new GDB frame struct, and then | |
41 | INIT_EXTRA_FRAME_INFO and INIT_FRAME_PC will be called for the new frame. | |
42 | ||
43 | For us, the frame address is its stack pointer value, so we look up | |
44 | the function prologue to determine the caller's sp value, and return it. */ | |
45 | ||
46 | FRAME_ADDR | |
47 | frame_chain (thisframe) | |
48 | FRAME thisframe; | |
8aa13b87 | 49 | { |
8aa13b87 | 50 | |
ea3c0839 JG |
51 | frame_find_saved_regs (thisframe, (struct frame_saved_regs *) 0); |
52 | /* NOTE: this depends on frame_find_saved_regs returning the VALUE, not | |
53 | the ADDRESS, of SP_REGNUM. It also depends on the cache of | |
54 | frame_find_saved_regs results. */ | |
55 | if (thisframe->fsr->regs[SP_REGNUM]) | |
56 | return thisframe->fsr->regs[SP_REGNUM]; | |
57 | else | |
58 | return thisframe->frame; /* Leaf fn -- next frame up has same SP. */ | |
59 | } | |
8aa13b87 | 60 | |
ea3c0839 JG |
61 | int |
62 | frameless_function_invocation (frame) | |
63 | FRAME frame; | |
8aa13b87 | 64 | { |
ea3c0839 JG |
65 | |
66 | frame_find_saved_regs (frame, (struct frame_saved_regs *) 0); | |
67 | /* NOTE: this depends on frame_find_saved_regs returning the VALUE, not | |
68 | the ADDRESS, of SP_REGNUM. It also depends on the cache of | |
69 | frame_find_saved_regs results. */ | |
70 | if (frame->fsr->regs[SP_REGNUM]) | |
71 | return 0; /* Frameful -- return addr saved somewhere */ | |
8aa13b87 | 72 | else |
ea3c0839 | 73 | return 1; /* Frameless -- no saved return address */ |
8aa13b87 JK |
74 | } |
75 | ||
ea3c0839 JG |
76 | void |
77 | init_extra_frame_info (fromleaf, fi) | |
78 | int fromleaf; | |
79 | struct frame_info *fi; | |
80 | { | |
81 | fi->fsr = 0; /* Not yet allocated */ | |
82 | fi->args_pointer = 0; /* Unknown */ | |
83 | fi->locals_pointer = 0; /* Unknown */ | |
84 | } | |
ea3c0839 JG |
85 | \f |
86 | /* Examine an m88k function prologue, recording the addresses at which | |
87 | registers are saved explicitly by the prologue code, and returning | |
88 | the address of the first instruction after the prologue (but not | |
89 | after the instruction at address LIMIT, as explained below). | |
90 | ||
91 | LIMIT places an upper bound on addresses of the instructions to be | |
92 | examined. If the prologue code scan reaches LIMIT, the scan is | |
93 | aborted and LIMIT is returned. This is used, when examining the | |
94 | prologue for the current frame, to keep examine_prologue () from | |
95 | claiming that a given register has been saved when in fact the | |
96 | instruction that saves it has not yet been executed. LIMIT is used | |
97 | at other times to stop the scan when we hit code after the true | |
98 | function prologue (e.g. for the first source line) which might | |
99 | otherwise be mistaken for function prologue. | |
100 | ||
101 | The format of the function prologue matched by this routine is | |
102 | derived from examination of the source to gcc 1.95, particularly | |
103 | the routine output_prologue () in config/out-m88k.c. | |
104 | ||
105 | subu r31,r31,n # stack pointer update | |
106 | ||
107 | (st rn,r31,offset)? # save incoming regs | |
108 | (st.d rn,r31,offset)? | |
109 | ||
110 | (addu r30,r31,n)? # frame pointer update | |
111 | ||
112 | (pic sequence)? # PIC code prologue | |
430923f3 JG |
113 | |
114 | (or rn,rm,0)? # Move parameters to other regs | |
ea3c0839 JG |
115 | */ |
116 | ||
117 | /* Macros for extracting fields from instructions. */ | |
118 | ||
119 | #define BITMASK(pos, width) (((0x1 << (width)) - 1) << (pos)) | |
120 | #define EXTRACT_FIELD(val, pos, width) ((val) >> (pos) & BITMASK (0, width)) | |
121 | ||
122 | /* Prologue code that handles position-independent-code setup. */ | |
123 | ||
124 | struct pic_prologue_code { | |
125 | unsigned long insn, mask; | |
126 | }; | |
127 | ||
128 | static struct pic_prologue_code pic_prologue_code [] = { | |
129 | /* FIXME -- until this is translated to hex, we won't match it... */ | |
817ac7f8 | 130 | { 0xffffffff, 0 }, |
ea3c0839 JG |
131 | /* or r10,r1,0 (if not saved) */ |
132 | /* bsr.n LabN */ | |
133 | /* or.u r25,r0,const */ | |
134 | /*LabN: or r25,r25,const2 */ | |
135 | /* addu r25,r25,1 */ | |
136 | /* or r1,r10,0 (if not saved) */ | |
137 | }; | |
138 | ||
139 | /* Fetch the instruction at ADDR, returning 0 if ADDR is beyond LIM or | |
140 | is not the address of a valid instruction, the address of the next | |
141 | instruction beyond ADDR otherwise. *PWORD1 receives the first word | |
142 | of the instruction. PWORD2 is ignored -- a remnant of the original | |
143 | i960 version. */ | |
144 | ||
637603f9 | 145 | #define NEXT_PROLOGUE_INSN(addr, lim, pword1) \ |
ea3c0839 JG |
146 | (((addr) < (lim)) ? next_insn (addr, pword1) : 0) |
147 | ||
148 | /* Read the m88k instruction at 'memaddr' and return the address of | |
149 | the next instruction after that, or 0 if 'memaddr' is not the | |
150 | address of a valid instruction. The instruction | |
151 | is stored at 'pword1'. */ | |
8aa13b87 | 152 | |
ea3c0839 JG |
153 | CORE_ADDR |
154 | next_insn (memaddr, pword1) | |
155 | unsigned long *pword1; | |
156 | CORE_ADDR memaddr; | |
8aa13b87 | 157 | { |
2a770cac JG |
158 | *pword1 = read_memory_integer (memaddr, BYTES_PER_88K_INSN); |
159 | return memaddr + BYTES_PER_88K_INSN; | |
8aa13b87 JK |
160 | } |
161 | ||
ea3c0839 | 162 | /* Read a register from frames called by us (or from the hardware regs). */ |
8aa13b87 | 163 | |
637603f9 | 164 | static int |
ea3c0839 JG |
165 | read_next_frame_reg(fi, regno) |
166 | FRAME fi; | |
167 | int regno; | |
8aa13b87 | 168 | { |
ea3c0839 JG |
169 | for (; fi; fi = fi->next) { |
170 | if (regno == SP_REGNUM) return fi->frame; | |
171 | else if (fi->fsr->regs[regno]) | |
172 | return read_memory_integer(fi->fsr->regs[regno], 4); | |
173 | } | |
174 | return read_register(regno); | |
8aa13b87 | 175 | } |
8aa13b87 | 176 | |
ea3c0839 JG |
177 | /* Examine the prologue of a function. `ip' points to the first instruction. |
178 | `limit' is the limit of the prologue (e.g. the addr of the first | |
179 | linenumber, or perhaps the program counter if we're stepping through). | |
180 | `frame_sp' is the stack pointer value in use in this frame. | |
181 | `fsr' is a pointer to a frame_saved_regs structure into which we put | |
182 | info about the registers saved by this frame. | |
183 | `fi' is a struct frame_info pointer; we fill in various fields in it | |
184 | to reflect the offsets of the arg pointer and the locals pointer. */ | |
185 | ||
186 | static CORE_ADDR | |
187 | examine_prologue (ip, limit, frame_sp, fsr, fi) | |
188 | register CORE_ADDR ip; | |
189 | register CORE_ADDR limit; | |
190 | FRAME_ADDR frame_sp; | |
191 | struct frame_saved_regs *fsr; | |
192 | struct frame_info *fi; | |
193 | { | |
194 | register CORE_ADDR next_ip; | |
195 | register int src; | |
196 | register struct pic_prologue_code *pcode; | |
637603f9 | 197 | unsigned int insn; |
ea3c0839 JG |
198 | int size, offset; |
199 | char must_adjust[32]; /* If set, must adjust offsets in fsr */ | |
200 | int sp_offset = -1; /* -1 means not set (valid must be mult of 8) */ | |
201 | int fp_offset = -1; /* -1 means not set */ | |
202 | CORE_ADDR frame_fp; | |
203 | ||
4ed97c9a | 204 | memset (must_adjust, '\0', sizeof (must_adjust)); |
637603f9 | 205 | next_ip = NEXT_PROLOGUE_INSN (ip, limit, &insn); |
ea3c0839 | 206 | |
653d6c56 JG |
207 | /* Accept move of incoming registers to other registers, using |
208 | "or rd,rs,0" or "or.u rd,rs,0" or "or rd,r0,rs" or "or rd,rs,r0". | |
209 | We don't have to worry about walking into the first lines of code, | |
210 | since the first line number will stop us (assuming we have symbols). | |
211 | What we have actually seen is "or r10,r0,r12". */ | |
212 | ||
213 | #define OR_MOVE_INSN 0x58000000 /* or/or.u with immed of 0 */ | |
214 | #define OR_MOVE_MASK 0xF800FFFF | |
215 | #define OR_REG_MOVE1_INSN 0xF4005800 /* or rd,r0,rs */ | |
216 | #define OR_REG_MOVE1_MASK 0xFC1FFFE0 | |
217 | #define OR_REG_MOVE2_INSN 0xF4005800 /* or rd,rs,r0 */ | |
218 | #define OR_REG_MOVE2_MASK 0xFC00FFFF | |
219 | while (next_ip && | |
637603f9 RP |
220 | ((insn & OR_MOVE_MASK) == OR_MOVE_INSN || |
221 | (insn & OR_REG_MOVE1_MASK) == OR_REG_MOVE1_INSN || | |
222 | (insn & OR_REG_MOVE2_MASK) == OR_REG_MOVE2_INSN | |
653d6c56 JG |
223 | ) |
224 | ) | |
225 | { | |
226 | /* We don't care what moves to where. The result of the moves | |
227 | has already been reflected in what the compiler tells us is the | |
228 | location of these parameters. */ | |
229 | ip = next_ip; | |
637603f9 | 230 | next_ip = NEXT_PROLOGUE_INSN (ip, limit, &insn); |
653d6c56 JG |
231 | } |
232 | ||
ea3c0839 JG |
233 | /* Accept an optional "subu sp,sp,n" to set up the stack pointer. */ |
234 | ||
235 | #define SUBU_SP_INSN 0x67ff0000 | |
236 | #define SUBU_SP_MASK 0xffff0007 /* Note offset must be mult. of 8 */ | |
237 | #define SUBU_OFFSET(x) ((unsigned)(x & 0xFFFF)) | |
238 | if (next_ip && | |
637603f9 | 239 | ((insn & SUBU_SP_MASK) == SUBU_SP_INSN)) /* subu r31, r31, N */ |
ea3c0839 | 240 | { |
637603f9 | 241 | sp_offset = -SUBU_OFFSET (insn); |
ea3c0839 | 242 | ip = next_ip; |
637603f9 | 243 | next_ip = NEXT_PROLOGUE_INSN (ip, limit, &insn); |
ea3c0839 JG |
244 | } |
245 | ||
246 | /* The function must start with a stack-pointer adjustment, or | |
247 | we don't know WHAT'S going on... */ | |
248 | if (sp_offset == -1) | |
249 | return ip; | |
250 | ||
251 | /* Accept zero or more instances of "st rx,sp,n" or "st.d rx,sp,n". | |
252 | This may cause us to mistake the copying of a register | |
253 | parameter to the frame for the saving of a callee-saved | |
254 | register, but that can't be helped, since with the | |
255 | "-fcall-saved" flag, any register can be made callee-saved. | |
256 | This probably doesn't matter, since the ``saved'' caller's values of | |
257 | non-callee-saved registers are not relevant anyway. */ | |
258 | ||
259 | #define STD_STACK_INSN 0x201f0000 | |
260 | #define STD_STACK_MASK 0xfc1f0000 | |
261 | #define ST_STACK_INSN 0x241f0000 | |
262 | #define ST_STACK_MASK 0xfc1f0000 | |
263 | #define ST_OFFSET(x) ((unsigned)((x) & 0xFFFF)) | |
264 | #define ST_SRC(x) EXTRACT_FIELD ((x), 21, 5) | |
265 | ||
266 | while (next_ip) | |
267 | { | |
637603f9 | 268 | if ((insn & ST_STACK_MASK) == ST_STACK_INSN) |
ea3c0839 | 269 | size = 1; |
637603f9 | 270 | else if ((insn & STD_STACK_MASK) == STD_STACK_INSN) |
ea3c0839 JG |
271 | size = 2; |
272 | else | |
273 | break; | |
274 | ||
637603f9 RP |
275 | src = ST_SRC (insn); |
276 | offset = ST_OFFSET (insn); | |
ea3c0839 JG |
277 | while (size--) |
278 | { | |
279 | must_adjust[src] = 1; | |
280 | fsr->regs[src++] = offset; /* Will be adjusted later */ | |
281 | offset += 4; | |
282 | } | |
283 | ip = next_ip; | |
637603f9 | 284 | next_ip = NEXT_PROLOGUE_INSN (ip, limit, &insn); |
ea3c0839 JG |
285 | } |
286 | ||
287 | /* Accept an optional "addu r30,r31,n" to set up the frame pointer. */ | |
288 | ||
289 | #define ADDU_FP_INSN 0x63df0000 | |
290 | #define ADDU_FP_MASK 0xffff0000 | |
291 | #define ADDU_OFFSET(x) ((unsigned)(x & 0xFFFF)) | |
292 | if (next_ip && | |
637603f9 | 293 | ((insn & ADDU_FP_MASK) == ADDU_FP_INSN)) /* addu r30, r31, N */ |
ea3c0839 | 294 | { |
637603f9 | 295 | fp_offset = ADDU_OFFSET (insn); |
ea3c0839 | 296 | ip = next_ip; |
637603f9 | 297 | next_ip = NEXT_PROLOGUE_INSN (ip, limit, &insn); |
ea3c0839 JG |
298 | } |
299 | ||
300 | /* Accept the PIC prologue code if present. */ | |
301 | ||
302 | pcode = pic_prologue_code; | |
303 | size = sizeof (pic_prologue_code) / sizeof (*pic_prologue_code); | |
304 | /* If return addr is saved, we don't use first or last insn of PICstuff. */ | |
305 | if (fsr->regs[SRP_REGNUM]) { | |
306 | pcode++; | |
307 | size-=2; | |
308 | } | |
309 | ||
637603f9 | 310 | while (size-- && next_ip && (pcode->insn == (pcode->mask & insn))) |
ea3c0839 JG |
311 | { |
312 | pcode++; | |
313 | ip = next_ip; | |
637603f9 | 314 | next_ip = NEXT_PROLOGUE_INSN (ip, limit, &insn); |
ea3c0839 JG |
315 | } |
316 | ||
430923f3 JG |
317 | /* Accept moves of parameter registers to other registers, using |
318 | "or rd,rs,0" or "or.u rd,rs,0" or "or rd,r0,rs" or "or rd,rs,r0". | |
319 | We don't have to worry about walking into the first lines of code, | |
320 | since the first line number will stop us (assuming we have symbols). | |
321 | What gcc actually seems to produce is "or rd,r0,rs". */ | |
322 | ||
323 | #define OR_MOVE_INSN 0x58000000 /* or/or.u with immed of 0 */ | |
324 | #define OR_MOVE_MASK 0xF800FFFF | |
325 | #define OR_REG_MOVE1_INSN 0xF4005800 /* or rd,r0,rs */ | |
326 | #define OR_REG_MOVE1_MASK 0xFC1FFFE0 | |
327 | #define OR_REG_MOVE2_INSN 0xF4005800 /* or rd,rs,r0 */ | |
328 | #define OR_REG_MOVE2_MASK 0xFC00FFFF | |
329 | while (next_ip && | |
637603f9 RP |
330 | ((insn & OR_MOVE_MASK) == OR_MOVE_INSN || |
331 | (insn & OR_REG_MOVE1_MASK) == OR_REG_MOVE1_INSN || | |
332 | (insn & OR_REG_MOVE2_MASK) == OR_REG_MOVE2_INSN | |
430923f3 JG |
333 | ) |
334 | ) | |
335 | { | |
336 | /* We don't care what moves to where. The result of the moves | |
337 | has already been reflected in what the compiler tells us is the | |
338 | location of these parameters. */ | |
339 | ip = next_ip; | |
637603f9 | 340 | next_ip = NEXT_PROLOGUE_INSN (ip, limit, &insn); |
430923f3 JG |
341 | } |
342 | ||
ea3c0839 JG |
343 | /* We're done with the prologue. If we don't care about the stack |
344 | frame itself, just return. (Note that fsr->regs has been trashed, | |
345 | but the one caller who calls with fi==0 passes a dummy there.) */ | |
346 | ||
347 | if (fi == 0) | |
348 | return ip; | |
349 | ||
637603f9 RP |
350 | /* |
351 | OK, now we have: | |
352 | ||
353 | sp_offset original (before any alloca calls) displacement of SP | |
354 | (will be negative). | |
355 | ||
356 | fp_offset displacement from original SP to the FP for this frame | |
357 | or -1. | |
358 | ||
359 | fsr->regs[0..31] displacement from original SP to the stack | |
360 | location where reg[0..31] is stored. | |
361 | ||
362 | must_adjust[0..31] set if corresponding offset was set. | |
ea3c0839 | 363 | |
637603f9 RP |
364 | If alloca has been called between the function prologue and the current |
365 | IP, then the current SP (frame_sp) will not be the original SP as set by | |
366 | the function prologue. If the current SP is not the original SP, then the | |
367 | compiler will have allocated an FP for this frame, fp_offset will be set, | |
368 | and we can use it to calculate the original SP. | |
ea3c0839 | 369 | |
637603f9 RP |
370 | Then, we figure out where the arguments and locals are, and relocate the |
371 | offsets in fsr->regs to absolute addresses. */ | |
ea3c0839 JG |
372 | |
373 | if (fp_offset != -1) { | |
374 | /* We have a frame pointer, so get it, and base our calc's on it. */ | |
637603f9 | 375 | frame_fp = (CORE_ADDR) read_next_frame_reg (fi->next, ACTUAL_FP_REGNUM); |
ea3c0839 JG |
376 | frame_sp = frame_fp - fp_offset; |
377 | } else { | |
378 | /* We have no frame pointer, therefore frame_sp is still the same value | |
379 | as set by prologue. But where is the frame itself? */ | |
380 | if (must_adjust[SRP_REGNUM]) { | |
381 | /* Function header saved SRP (r1), the return address. Frame starts | |
382 | 4 bytes down from where it was saved. */ | |
383 | frame_fp = frame_sp + fsr->regs[SRP_REGNUM] - 4; | |
384 | fi->locals_pointer = frame_fp; | |
385 | } else { | |
386 | /* Function header didn't save SRP (r1), so we are in a leaf fn or | |
387 | are otherwise confused. */ | |
388 | frame_fp = -1; | |
389 | } | |
390 | } | |
391 | ||
392 | /* The locals are relative to the FP (whether it exists as an allocated | |
393 | register, or just as an assumed offset from the SP) */ | |
394 | fi->locals_pointer = frame_fp; | |
395 | ||
396 | /* The arguments are just above the SP as it was before we adjusted it | |
397 | on entry. */ | |
398 | fi->args_pointer = frame_sp - sp_offset; | |
399 | ||
400 | /* Now that we know the SP value used by the prologue, we know where | |
401 | it saved all the registers. */ | |
402 | for (src = 0; src < 32; src++) | |
403 | if (must_adjust[src]) | |
404 | fsr->regs[src] += frame_sp; | |
405 | ||
406 | /* The saved value of the SP is always known. */ | |
407 | /* (we hope...) */ | |
408 | if (fsr->regs[SP_REGNUM] != 0 | |
409 | && fsr->regs[SP_REGNUM] != frame_sp - sp_offset) | |
199b2450 | 410 | fprintf_unfiltered(gdb_stderr, "Bad saved SP value %x != %x, offset %x!\n", |
ea3c0839 JG |
411 | fsr->regs[SP_REGNUM], |
412 | frame_sp - sp_offset, sp_offset); | |
413 | ||
414 | fsr->regs[SP_REGNUM] = frame_sp - sp_offset; | |
8aa13b87 | 415 | |
ea3c0839 JG |
416 | return (ip); |
417 | } | |
8aa13b87 | 418 | |
ea3c0839 JG |
419 | /* Given an ip value corresponding to the start of a function, |
420 | return the ip of the first instruction after the function | |
421 | prologue. */ | |
8aa13b87 JK |
422 | |
423 | CORE_ADDR | |
ea3c0839 JG |
424 | skip_prologue (ip) |
425 | CORE_ADDR (ip); | |
8aa13b87 | 426 | { |
ea3c0839 JG |
427 | struct frame_saved_regs saved_regs_dummy; |
428 | struct symtab_and_line sal; | |
429 | CORE_ADDR limit; | |
8aa13b87 | 430 | |
ea3c0839 JG |
431 | sal = find_pc_line (ip, 0); |
432 | limit = (sal.end) ? sal.end : 0xffffffff; | |
433 | ||
434 | return (examine_prologue (ip, limit, (FRAME_ADDR) 0, &saved_regs_dummy, | |
435 | (struct frame_info *)0 )); | |
436 | } | |
437 | ||
438 | /* Put here the code to store, into a struct frame_saved_regs, | |
439 | the addresses of the saved registers of frame described by FRAME_INFO. | |
440 | This includes special registers such as pc and fp saved in special | |
441 | ways in the stack frame. sp is even more special: | |
442 | the address we return for it IS the sp for the next frame. | |
443 | ||
444 | We cache the result of doing this in the frame_cache_obstack, since | |
445 | it is fairly expensive. */ | |
446 | ||
447 | void | |
448 | frame_find_saved_regs (fi, fsr) | |
449 | struct frame_info *fi; | |
450 | struct frame_saved_regs *fsr; | |
451 | { | |
ea3c0839 JG |
452 | register struct frame_saved_regs *cache_fsr; |
453 | extern struct obstack frame_cache_obstack; | |
454 | CORE_ADDR ip; | |
455 | struct symtab_and_line sal; | |
456 | CORE_ADDR limit; | |
457 | ||
458 | if (!fi->fsr) | |
8aa13b87 | 459 | { |
ea3c0839 JG |
460 | cache_fsr = (struct frame_saved_regs *) |
461 | obstack_alloc (&frame_cache_obstack, | |
462 | sizeof (struct frame_saved_regs)); | |
4ed97c9a | 463 | memset (cache_fsr, '\0', sizeof (struct frame_saved_regs)); |
ea3c0839 JG |
464 | fi->fsr = cache_fsr; |
465 | ||
466 | /* Find the start and end of the function prologue. If the PC | |
467 | is in the function prologue, we only consider the part that | |
468 | has executed already. */ | |
469 | ||
470 | ip = get_pc_function_start (fi->pc); | |
471 | sal = find_pc_line (ip, 0); | |
472 | limit = (sal.end && sal.end < fi->pc) ? sal.end: fi->pc; | |
473 | ||
474 | /* This will fill in fields in *fi as well as in cache_fsr. */ | |
7bec77b4 JK |
475 | #ifdef SIGTRAMP_FRAME_FIXUP |
476 | if (fi->signal_handler_caller) | |
477 | SIGTRAMP_FRAME_FIXUP(fi->frame); | |
478 | #endif | |
ea3c0839 | 479 | examine_prologue (ip, limit, fi->frame, cache_fsr, fi); |
7bec77b4 JK |
480 | #ifdef SIGTRAMP_SP_FIXUP |
481 | if (fi->signal_handler_caller && fi->fsr->regs[SP_REGNUM]) | |
482 | SIGTRAMP_SP_FIXUP(fi->fsr->regs[SP_REGNUM]); | |
483 | #endif | |
8aa13b87 JK |
484 | } |
485 | ||
ea3c0839 JG |
486 | if (fsr) |
487 | *fsr = *fi->fsr; | |
488 | } | |
489 | ||
490 | /* Return the address of the locals block for the frame | |
491 | described by FI. Returns 0 if the address is unknown. | |
492 | NOTE! Frame locals are referred to by negative offsets from the | |
493 | argument pointer, so this is the same as frame_args_address(). */ | |
494 | ||
495 | CORE_ADDR | |
496 | frame_locals_address (fi) | |
497 | struct frame_info *fi; | |
498 | { | |
ea3c0839 | 499 | struct frame_saved_regs fsr; |
ea3c0839 JG |
500 | |
501 | if (fi->args_pointer) /* Cached value is likely there. */ | |
502 | return fi->args_pointer; | |
503 | ||
504 | /* Nope, generate it. */ | |
505 | ||
506 | get_frame_saved_regs (fi, &fsr); | |
507 | ||
508 | return fi->args_pointer; | |
509 | } | |
510 | ||
511 | /* Return the address of the argument block for the frame | |
512 | described by FI. Returns 0 if the address is unknown. */ | |
513 | ||
514 | CORE_ADDR | |
515 | frame_args_address (fi) | |
516 | struct frame_info *fi; | |
517 | { | |
ea3c0839 | 518 | struct frame_saved_regs fsr; |
ea3c0839 JG |
519 | |
520 | if (fi->args_pointer) /* Cached value is likely there. */ | |
521 | return fi->args_pointer; | |
522 | ||
523 | /* Nope, generate it. */ | |
524 | ||
525 | get_frame_saved_regs (fi, &fsr); | |
526 | ||
527 | return fi->args_pointer; | |
528 | } | |
529 | ||
530 | /* Return the saved PC from this frame. | |
531 | ||
532 | If the frame has a memory copy of SRP_REGNUM, use that. If not, | |
533 | just use the register SRP_REGNUM itself. */ | |
534 | ||
535 | CORE_ADDR | |
536 | frame_saved_pc (frame) | |
537 | FRAME frame; | |
538 | { | |
539 | return read_next_frame_reg(frame, SRP_REGNUM); | |
8aa13b87 JK |
540 | } |
541 | ||
abef03ce JK |
542 | #if 0 |
543 | /* I believe this is all obsolete call dummy stuff. */ | |
ef98d5ac JG |
544 | static int |
545 | pushed_size (prev_words, v) | |
546 | int prev_words; | |
547 | struct value *v; | |
548 | { | |
549 | switch (TYPE_CODE (VALUE_TYPE (v))) | |
550 | { | |
551 | case TYPE_CODE_VOID: /* Void type (values zero length) */ | |
552 | ||
553 | return 0; /* That was easy! */ | |
554 | ||
555 | case TYPE_CODE_PTR: /* Pointer type */ | |
556 | case TYPE_CODE_ENUM: /* Enumeration type */ | |
557 | case TYPE_CODE_INT: /* Integer type */ | |
558 | case TYPE_CODE_REF: /* C++ Reference types */ | |
85f0a848 | 559 | case TYPE_CODE_ARRAY: /* Array type, lower & upper bounds */ |
ef98d5ac JG |
560 | |
561 | return 1; | |
562 | ||
563 | case TYPE_CODE_FLT: /* Floating type */ | |
564 | ||
565 | if (TYPE_LENGTH (VALUE_TYPE (v)) == 4) | |
566 | return 1; | |
567 | else | |
568 | /* Assume that it must be a double. */ | |
569 | if (prev_words & 1) /* at an odd-word boundary */ | |
570 | return 3; /* round to 8-byte boundary */ | |
571 | else | |
572 | return 2; | |
573 | ||
574 | case TYPE_CODE_STRUCT: /* C struct or Pascal record */ | |
575 | case TYPE_CODE_UNION: /* C union or Pascal variant part */ | |
576 | ||
577 | return (((TYPE_LENGTH (VALUE_TYPE (v)) + 3) / 4) * 4); | |
578 | ||
579 | case TYPE_CODE_FUNC: /* Function type */ | |
580 | case TYPE_CODE_SET: /* Pascal sets */ | |
581 | case TYPE_CODE_RANGE: /* Range (integers within bounds) */ | |
c4413e2c | 582 | case TYPE_CODE_STRING: /* String type */ |
ef98d5ac JG |
583 | case TYPE_CODE_MEMBER: /* Member type */ |
584 | case TYPE_CODE_METHOD: /* Method type */ | |
585 | /* Don't know how to pass these yet. */ | |
586 | ||
587 | case TYPE_CODE_UNDEF: /* Not used; catches errors */ | |
588 | default: | |
589 | abort (); | |
590 | } | |
591 | } | |
592 | ||
593 | static void | |
594 | store_parm_word (address, val) | |
595 | CORE_ADDR address; | |
596 | int val; | |
597 | { | |
2a770cac | 598 | write_memory (address, (char *)&val, 4); |
ef98d5ac JG |
599 | } |
600 | ||
601 | static int | |
602 | store_parm (prev_words, left_parm_addr, v) | |
603 | unsigned int prev_words; | |
604 | CORE_ADDR left_parm_addr; | |
605 | struct value *v; | |
606 | { | |
607 | CORE_ADDR start = left_parm_addr + (prev_words * 4); | |
608 | int *val_addr = (int *)VALUE_CONTENTS(v); | |
609 | ||
610 | switch (TYPE_CODE (VALUE_TYPE (v))) | |
611 | { | |
612 | case TYPE_CODE_VOID: /* Void type (values zero length) */ | |
613 | ||
614 | return 0; | |
615 | ||
616 | case TYPE_CODE_PTR: /* Pointer type */ | |
617 | case TYPE_CODE_ENUM: /* Enumeration type */ | |
618 | case TYPE_CODE_INT: /* Integer type */ | |
85f0a848 | 619 | case TYPE_CODE_ARRAY: /* Array type, lower & upper bounds */ |
ef98d5ac JG |
620 | case TYPE_CODE_REF: /* C++ Reference types */ |
621 | ||
622 | store_parm_word (start, *val_addr); | |
623 | return 1; | |
624 | ||
625 | case TYPE_CODE_FLT: /* Floating type */ | |
626 | ||
627 | if (TYPE_LENGTH (VALUE_TYPE (v)) == 4) | |
628 | { | |
629 | store_parm_word (start, *val_addr); | |
630 | return 1; | |
631 | } | |
632 | else | |
633 | { | |
634 | store_parm_word (start + ((prev_words & 1) * 4), val_addr[0]); | |
635 | store_parm_word (start + ((prev_words & 1) * 4) + 4, val_addr[1]); | |
636 | return 2 + (prev_words & 1); | |
637 | } | |
638 | ||
639 | case TYPE_CODE_STRUCT: /* C struct or Pascal record */ | |
640 | case TYPE_CODE_UNION: /* C union or Pascal variant part */ | |
641 | ||
642 | { | |
643 | unsigned int words = (((TYPE_LENGTH (VALUE_TYPE (v)) + 3) / 4) * 4); | |
644 | unsigned int word; | |
645 | ||
646 | for (word = 0; word < words; word++) | |
647 | store_parm_word (start + (word * 4), val_addr[word]); | |
648 | return words; | |
649 | } | |
650 | ||
651 | default: | |
652 | abort (); | |
653 | } | |
654 | } | |
8aa13b87 | 655 | |
8aa13b87 JK |
656 | /* This routine sets up all of the parameter values needed to make a pseudo |
657 | call. The name "push_parameters" is a misnomer on some archs, | |
658 | because (on the m88k) most parameters generally end up being passed in | |
659 | registers rather than on the stack. In this routine however, we do | |
660 | end up storing *all* parameter values onto the stack (even if we will | |
661 | realize later that some of these stores were unnecessary). */ | |
662 | ||
ea3c0839 JG |
663 | #define FIRST_PARM_REGNUM 2 |
664 | ||
8aa13b87 JK |
665 | void |
666 | push_parameters (return_type, struct_conv, nargs, args) | |
667 | struct type *return_type; | |
668 | int struct_conv; | |
669 | int nargs; | |
670 | value *args; | |
ea3c0839 | 671 | { |
8aa13b87 JK |
672 | int parm_num; |
673 | unsigned int p_words = 0; | |
674 | CORE_ADDR left_parm_addr; | |
675 | ||
676 | /* Start out by creating a space for the return value (if need be). We | |
677 | only need to do this if the return value is a struct or union. If we | |
678 | do make a space for a struct or union return value, then we must also | |
679 | arrange for the base address of that space to go into r12, which is the | |
680 | standard place to pass the address of the return value area to the | |
681 | callee. Note that only structs and unions are returned in this fashion. | |
682 | Ints, enums, pointers, and floats are returned into r2. Doubles are | |
683 | returned into the register pair {r2,r3}. Note also that the space | |
684 | reserved for a struct or union return value only has to be word aligned | |
685 | (not double-word) but it is double-word aligned here anyway (just in | |
686 | case that becomes important someday). */ | |
687 | ||
688 | switch (TYPE_CODE (return_type)) | |
689 | { | |
690 | case TYPE_CODE_STRUCT: | |
691 | case TYPE_CODE_UNION: | |
692 | { | |
693 | int return_bytes = ((TYPE_LENGTH (return_type) + 7) / 8) * 8; | |
694 | CORE_ADDR rv_addr; | |
695 | ||
696 | rv_addr = read_register (SP_REGNUM) - return_bytes; | |
697 | ||
698 | write_register (SP_REGNUM, rv_addr); /* push space onto the stack */ | |
699 | write_register (SRA_REGNUM, rv_addr);/* set return value register */ | |
817ac7f8 | 700 | break; |
8aa13b87 | 701 | } |
817ac7f8 | 702 | default: break; |
8aa13b87 JK |
703 | } |
704 | ||
705 | /* Here we make a pre-pass on the whole parameter list to figure out exactly | |
706 | how many words worth of stuff we are going to pass. */ | |
707 | ||
708 | for (p_words = 0, parm_num = 0; parm_num < nargs; parm_num++) | |
709 | p_words += pushed_size (p_words, value_arg_coerce (args[parm_num])); | |
710 | ||
711 | /* Now, check to see if we have to round up the number of parameter words | |
712 | to get up to the next 8-bytes boundary. This may be necessary because | |
713 | of the software convention to always keep the stack aligned on an 8-byte | |
714 | boundary. */ | |
715 | ||
716 | if (p_words & 1) | |
717 | p_words++; /* round to 8-byte boundary */ | |
718 | ||
719 | /* Now figure out the absolute address of the leftmost parameter, and update | |
720 | the stack pointer to point at that address. */ | |
721 | ||
722 | left_parm_addr = read_register (SP_REGNUM) - (p_words * 4); | |
723 | write_register (SP_REGNUM, left_parm_addr); | |
724 | ||
725 | /* Now we can go through all of the parameters (in left-to-right order) | |
726 | and write them to their parameter stack slots. Note that we are not | |
727 | really "pushing" the parameter values. The stack space for these values | |
728 | was already allocated above. Now we are just filling it up. */ | |
729 | ||
730 | for (p_words = 0, parm_num = 0; parm_num < nargs; parm_num++) | |
731 | p_words += | |
732 | store_parm (p_words, left_parm_addr, value_arg_coerce (args[parm_num])); | |
733 | ||
734 | /* Now that we are all done storing the parameter values into the stack, we | |
735 | must go back and load up the parameter registers with the values from the | |
736 | corresponding stack slots. Note that in the two cases of (a) gaps in the | |
737 | parameter word sequence causes by (otherwise) misaligned doubles, and (b) | |
738 | slots correcponding to structs or unions, the work we do here in loading | |
739 | some parameter registers may be unnecessary, but who cares? */ | |
740 | ||
741 | for (p_words = 0; p_words < 8; p_words++) | |
742 | { | |
743 | write_register (FIRST_PARM_REGNUM + p_words, | |
744 | read_memory_integer (left_parm_addr + (p_words * 4), 4)); | |
745 | } | |
746 | } | |
747 | ||
ea3c0839 JG |
748 | void |
749 | collect_returned_value (rval, value_type, struct_return, nargs, args) | |
750 | value *rval; | |
751 | struct type *value_type; | |
752 | int struct_return; | |
753 | int nargs; | |
754 | value *args; | |
755 | { | |
756 | char retbuf[REGISTER_BYTES]; | |
757 | ||
ade40d31 | 758 | memcpy (retbuf, registers, REGISTER_BYTES); |
ea3c0839 JG |
759 | *rval = value_being_returned (value_type, retbuf, struct_return); |
760 | return; | |
761 | } | |
abef03ce | 762 | #endif /* 0 */ |
8aa13b87 | 763 | |
abef03ce JK |
764 | /*start of lines added by kev*/ |
765 | ||
766 | #define DUMMY_FRAME_SIZE 192 | |
767 | ||
768 | static void | |
769 | write_word (sp, word) | |
770 | CORE_ADDR sp; | |
f4f0d174 | 771 | unsigned LONGEST word; |
abef03ce | 772 | { |
f4f0d174 | 773 | register int len = REGISTER_SIZE; |
abef03ce JK |
774 | char buffer[MAX_REGISTER_RAW_SIZE]; |
775 | ||
776 | store_unsigned_integer (buffer, len, word); | |
777 | write_memory (sp, buffer, len); | |
778 | } | |
779 | ||
780 | void | |
781 | m88k_push_dummy_frame() | |
782 | { | |
783 | register CORE_ADDR sp = read_register (SP_REGNUM); | |
784 | register int rn; | |
785 | int offset; | |
786 | ||
787 | sp -= DUMMY_FRAME_SIZE; /* allocate a bunch of space */ | |
788 | ||
789 | for (rn = 0, offset = 0; rn <= SP_REGNUM; rn++, offset+=4) | |
790 | write_word (sp+offset, read_register(rn)); | |
8aa13b87 | 791 | |
abef03ce JK |
792 | write_word (sp+offset, read_register (SXIP_REGNUM)); |
793 | offset += 4; | |
794 | ||
795 | write_word (sp+offset, read_register (SNIP_REGNUM)); | |
796 | offset += 4; | |
797 | ||
798 | write_word (sp+offset, read_register (SFIP_REGNUM)); | |
799 | offset += 4; | |
800 | ||
801 | write_word (sp+offset, read_register (PSR_REGNUM)); | |
802 | offset += 4; | |
803 | ||
804 | write_word (sp+offset, read_register (FPSR_REGNUM)); | |
805 | offset += 4; | |
806 | ||
807 | write_word (sp+offset, read_register (FPCR_REGNUM)); | |
808 | offset += 4; | |
809 | ||
810 | write_register (SP_REGNUM, sp); | |
811 | write_register (ACTUAL_FP_REGNUM, sp); | |
812 | } | |
813 | ||
814 | void | |
815 | pop_frame () | |
ea3c0839 | 816 | { |
abef03ce JK |
817 | register FRAME frame = get_current_frame (); |
818 | register CORE_ADDR fp; | |
819 | register int regnum; | |
820 | struct frame_saved_regs fsr; | |
821 | struct frame_info *fi; | |
822 | ||
823 | fi = get_frame_info (frame); | |
824 | fp = fi -> frame; | |
825 | get_frame_saved_regs (fi, &fsr); | |
826 | ||
827 | if (PC_IN_CALL_DUMMY (read_pc(), read_register(SP_REGNUM), FRAME_FP(fi))) | |
828 | { | |
829 | /* FIXME: I think get_frame_saved_regs should be handling this so | |
830 | that we can deal with the saved registers properly (e.g. frame | |
831 | 1 is a call dummy, the user types "frame 2" and then "print $ps"). */ | |
832 | register CORE_ADDR sp = read_register (ACTUAL_FP_REGNUM); | |
833 | int offset; | |
834 | ||
835 | for (regnum = 0, offset = 0; regnum <= SP_REGNUM; regnum++, offset+=4) | |
836 | (void) write_register (regnum, read_memory_integer (sp+offset, 4)); | |
837 | ||
838 | write_register (SXIP_REGNUM, read_memory_integer (sp+offset, 4)); | |
839 | offset += 4; | |
8aa13b87 | 840 | |
abef03ce JK |
841 | write_register (SNIP_REGNUM, read_memory_integer (sp+offset, 4)); |
842 | offset += 4; | |
8aa13b87 | 843 | |
abef03ce JK |
844 | write_register (SFIP_REGNUM, read_memory_integer (sp+offset, 4)); |
845 | offset += 4; | |
8aa13b87 | 846 | |
abef03ce JK |
847 | write_register (PSR_REGNUM, read_memory_integer (sp+offset, 4)); |
848 | offset += 4; | |
ea3c0839 | 849 | |
abef03ce JK |
850 | write_register (FPSR_REGNUM, read_memory_integer (sp+offset, 4)); |
851 | offset += 4; | |
8aa13b87 | 852 | |
abef03ce JK |
853 | write_register (FPCR_REGNUM, read_memory_integer (sp+offset, 4)); |
854 | offset += 4; | |
ea3c0839 | 855 | |
abef03ce JK |
856 | } |
857 | else | |
858 | { | |
859 | for (regnum = FP_REGNUM ; regnum > 0 ; regnum--) | |
860 | if (fsr.regs[regnum]) | |
861 | write_register (regnum, | |
862 | read_memory_integer (fsr.regs[regnum], 4)); | |
863 | write_pc(frame_saved_pc(frame)); | |
864 | } | |
865 | reinit_frame_cache (); | |
8aa13b87 | 866 | } |