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