Commit | Line | Data |
---|---|---|
5198e746 | 1 | /* Target-dependent code for the Fujitsu FR30. |
17139ec5 ZR |
2 | Copyright 1996, Free Software Foundation, Inc. |
3 | ||
4 | This file is part of GDB. | |
5 | ||
6 | This program is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 2 of the License, or | |
9 | (at your option) any later version. | |
10 | ||
11 | This program is distributed in the hope that it will be useful, | |
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 | |
17 | along with this program; if not, write to the Free Software | |
18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |
19 | ||
20 | #include "defs.h" | |
21 | #include "frame.h" | |
22 | #include "inferior.h" | |
23 | #include "obstack.h" | |
24 | #include "target.h" | |
25 | #include "value.h" | |
26 | #include "bfd.h" | |
27 | #include "gdb_string.h" | |
28 | #include "gdbcore.h" | |
29 | #include "symfile.h" | |
30 | ||
31 | niy(char *f, int l) | |
32 | { | |
33 | fprintf(stderr, "%s(%d): Not implemented yet\n", f, l); | |
34 | } | |
35 | #define NIY() niy(__FILE__, __LINE__) | |
36 | ||
5198e746 ZR |
37 | /* Function: pop_frame |
38 | This routine gets called when either the user uses the `return' | |
39 | command, or the call dummy breakpoint gets hit. */ | |
40 | ||
17139ec5 | 41 | void |
5198e746 | 42 | fr30_pop_frame () |
17139ec5 | 43 | { |
5198e746 ZR |
44 | struct frame_info *frame = get_current_frame(); |
45 | int regnum; | |
17139ec5 | 46 | |
5198e746 ZR |
47 | if (PC_IN_CALL_DUMMY(frame->pc, frame->frame, frame->frame)) |
48 | generic_pop_dummy_frame (); | |
49 | else | |
50 | { | |
51 | write_register (PC_REGNUM, FRAME_SAVED_PC (frame)); | |
17139ec5 | 52 | |
5198e746 ZR |
53 | for (regnum = 0; regnum < NUM_REGS; regnum++) |
54 | if (frame->fsr.regs[regnum] != 0) | |
55 | write_register (regnum, | |
56 | read_memory_unsigned_integer (frame->fsr.regs[regnum], | |
57 | REGISTER_RAW_SIZE(regnum))); | |
58 | ||
59 | write_register (SP_REGNUM, FRAME_FP (frame)); | |
60 | } | |
61 | ||
62 | flush_cached_frames (); | |
17139ec5 ZR |
63 | } |
64 | ||
5198e746 ZR |
65 | /* Function: skip_prologue |
66 | Return the address of the first code past the prologue of the function. */ | |
67 | ||
17139ec5 ZR |
68 | CORE_ADDR |
69 | fr30_skip_prologue(CORE_ADDR pc) | |
70 | { | |
5198e746 ZR |
71 | CORE_ADDR func_addr, func_end; |
72 | ||
73 | /* See what the symbol table says */ | |
74 | ||
75 | if (find_pc_partial_function (pc, NULL, &func_addr, &func_end)) | |
76 | { | |
77 | struct symtab_and_line sal; | |
78 | ||
79 | sal = find_pc_line (func_addr, 0); | |
80 | ||
81 | if (sal.line != 0 && sal.end < func_end) | |
82 | return sal.end; | |
83 | } | |
84 | ||
85 | /* Either we didn't find the start of this function (nothing we can do), | |
86 | or there's no line info, or the line after the prologue is after | |
87 | the end of the function (there probably isn't a prologue). */ | |
88 | ||
89 | return pc; | |
17139ec5 ZR |
90 | } |
91 | ||
92 | ||
93 | CORE_ADDR | |
94 | fr30_push_arguments(nargs, args, sp, struct_return, struct_addr) | |
95 | int nargs; | |
96 | value_ptr * args; | |
97 | CORE_ADDR sp; | |
98 | int struct_return; | |
99 | CORE_ADDR struct_addr; | |
100 | { | |
101 | int argreg; | |
102 | int argnum; | |
103 | int stack_offset; | |
104 | struct stack_arg { | |
105 | char *val; | |
106 | int len; | |
107 | int offset; | |
108 | }; | |
109 | struct stack_arg *stack_args = | |
110 | (struct stack_arg*)alloca (nargs * sizeof (struct stack_arg)); | |
111 | int nstack_args = 0; | |
112 | ||
17139ec5 ZR |
113 | argreg = FIRST_ARGREG; |
114 | ||
115 | /* the struct_return pointer occupies the first parameter-passing reg */ | |
116 | if (struct_return) | |
117 | write_register (argreg++, struct_addr); | |
118 | ||
119 | #if(0) | |
120 | /* The offset onto the stack at which we will start copying parameters | |
121 | (after the registers are used up) begins at 16 in the old ABI. | |
122 | This leaves room for the "home" area for register parameters. */ | |
123 | stack_offset = REGISTER_SIZE * 4; | |
124 | #else | |
125 | /* XXX which ABI are we using ? Z.R. */ | |
126 | stack_offset = 0; | |
127 | #endif | |
128 | ||
129 | /* Process args from left to right. Store as many as allowed in | |
130 | registers, save the rest to be pushed on the stack */ | |
131 | for(argnum = 0; argnum < nargs; argnum++) | |
132 | { | |
133 | char * val; | |
134 | value_ptr arg = args[argnum]; | |
135 | struct type * arg_type = check_typedef (VALUE_TYPE (arg)); | |
136 | struct type * target_type = TYPE_TARGET_TYPE (arg_type); | |
137 | int len = TYPE_LENGTH (arg_type); | |
138 | enum type_code typecode = TYPE_CODE (arg_type); | |
139 | CORE_ADDR regval; | |
140 | int newarg; | |
141 | ||
142 | val = (char *) VALUE_CONTENTS (arg); | |
143 | ||
144 | { | |
145 | /* Copy the argument to general registers or the stack in | |
146 | register-sized pieces. Large arguments are split between | |
147 | registers and stack. */ | |
148 | while (len > 0) | |
149 | { | |
150 | if (argreg <= LAST_ARGREG) | |
151 | { | |
152 | int partial_len = len < REGISTER_SIZE ? len : REGISTER_SIZE; | |
153 | regval = extract_address (val, partial_len); | |
154 | ||
155 | /* It's a simple argument being passed in a general | |
156 | register. */ | |
157 | write_register (argreg, regval); | |
158 | argreg++; | |
159 | len -= partial_len; | |
160 | val += partial_len; | |
161 | } | |
162 | else | |
163 | { | |
164 | /* keep for later pushing */ | |
165 | stack_args[nstack_args].val = val; | |
166 | stack_args[nstack_args++].len = len; | |
167 | break; | |
168 | } | |
169 | } | |
170 | } | |
171 | } | |
172 | /* now do the real stack pushing, process args right to left */ | |
173 | while(nstack_args--) | |
174 | { | |
175 | sp -= stack_args[nstack_args].len; | |
176 | write_memory(sp, stack_args[nstack_args].val, | |
177 | stack_args[nstack_args].len); | |
178 | } | |
179 | ||
180 | /* Return adjusted stack pointer. */ | |
181 | return sp; | |
182 | } | |
183 | ||
184 | _initialize_fr30_tdep() | |
185 | { | |
186 | extern int print_insn_fr30(bfd_vma, disassemble_info *); | |
187 | ||
188 | tm_print_insn = print_insn_fr30; | |
189 | } | |
190 | ||
191 | ||
17139ec5 ZR |
192 | /* Info gleaned from scanning a function's prologue. */ |
193 | ||
194 | struct pifsr /* Info about one saved reg */ | |
195 | { | |
196 | int framereg; /* Frame reg (SP or FP) */ | |
197 | int offset; /* Offset from framereg */ | |
198 | int cur_frameoffset; /* Current frameoffset */ | |
199 | int reg; /* Saved register number */ | |
200 | }; | |
201 | ||
202 | struct prologue_info | |
203 | { | |
204 | int framereg; | |
205 | int frameoffset; | |
206 | int start_function; | |
207 | struct pifsr *pifsrs; | |
208 | }; | |
209 | ||
5198e746 | 210 | static CORE_ADDR fr30_scan_prologue PARAMS ((CORE_ADDR pc, |
17139ec5 ZR |
211 | struct prologue_info *fs)); |
212 | \f | |
213 | /* Function: scan_prologue | |
214 | Scan the prologue of the function that contains PC, and record what | |
215 | we find in PI. PI->fsr must be zeroed by the called. Returns the | |
216 | pc after the prologue. Note that the addresses saved in pi->fsr | |
217 | are actually just frame relative (negative offsets from the frame | |
218 | pointer). This is because we don't know the actual value of the | |
219 | frame pointer yet. In some circumstances, the frame pointer can't | |
220 | be determined till after we have scanned the prologue. */ | |
221 | ||
222 | static CORE_ADDR | |
5198e746 | 223 | fr30_scan_prologue (pc, pi) |
17139ec5 ZR |
224 | CORE_ADDR pc; |
225 | struct prologue_info *pi; | |
226 | { | |
227 | CORE_ADDR func_addr, prologue_end, current_pc; | |
228 | struct pifsr *pifsr, *pifsr_tmp; | |
229 | int fp_used; | |
230 | int ep_used; | |
231 | int reg; | |
232 | CORE_ADDR save_pc, save_end; | |
233 | int regsave_func_p; | |
234 | int current_sp_size; | |
235 | int r12_tmp; | |
236 | ||
237 | /* First, figure out the bounds of the prologue so that we can limit the | |
238 | search to something reasonable. */ | |
239 | ||
240 | if (find_pc_partial_function (pc, NULL, &func_addr, NULL)) | |
241 | { | |
242 | struct symtab_and_line sal; | |
243 | ||
244 | sal = find_pc_line (func_addr, 0); | |
245 | ||
246 | if (func_addr == entry_point_address ()) | |
247 | pi->start_function = 1; | |
248 | else | |
249 | pi->start_function = 0; | |
250 | ||
251 | #if 0 | |
252 | if (sal.line == 0) | |
253 | prologue_end = pc; | |
254 | else | |
255 | prologue_end = sal.end; | |
256 | #else | |
257 | prologue_end = pc; | |
258 | #endif | |
259 | } | |
260 | else | |
261 | { /* We're in the boondocks */ | |
262 | func_addr = pc - 100; | |
263 | prologue_end = pc; | |
264 | } | |
265 | ||
266 | prologue_end = min (prologue_end, pc); | |
267 | ||
268 | /* Now, search the prologue looking for instructions that setup fp, save | |
269 | rp, adjust sp and such. We also record the frame offset of any saved | |
270 | registers. */ | |
271 | ||
272 | pi->frameoffset = 0; | |
273 | pi->framereg = SP_REGNUM; | |
274 | fp_used = 0; | |
275 | ep_used = 0; | |
276 | pifsr = pi->pifsrs; | |
277 | regsave_func_p = 0; | |
278 | save_pc = 0; | |
279 | save_end = 0; | |
280 | r12_tmp = 0; | |
281 | ||
282 | #ifdef DEBUG | |
283 | printf_filtered ("Current_pc = 0x%.8lx, prologue_end = 0x%.8lx\n", | |
284 | (long)func_addr, (long)prologue_end); | |
285 | #endif | |
286 | ||
287 | for (current_pc = func_addr; current_pc < prologue_end; current_pc += 2) | |
288 | { | |
289 | int insn; | |
290 | ||
291 | #ifdef DEBUG | |
292 | printf_filtered ("0x%.8lx ", (long)current_pc); | |
293 | (*tm_print_insn) (current_pc, &tm_print_insn_info); | |
294 | #endif | |
295 | ||
296 | insn = read_memory_unsigned_integer (current_pc, 2); | |
297 | ||
298 | if ((insn & 0xffc0) == ((10 << 11) | 0x0780) && !regsave_func_p) | |
299 | { /* jarl <func>,10 */ | |
300 | long low_disp = read_memory_unsigned_integer (current_pc + 2, 2) & ~ (long) 1; | |
301 | long disp = (((((insn & 0x3f) << 16) + low_disp) | |
302 | & ~ (long) 1) ^ 0x00200000) - 0x00200000; | |
303 | ||
304 | save_pc = current_pc; | |
305 | save_end = prologue_end; | |
306 | regsave_func_p = 1; | |
307 | current_pc += disp - 2; | |
308 | prologue_end = (current_pc | |
309 | + (2 * 3) /* moves to/from ep */ | |
310 | + 4 /* addi <const>,sp,sp */ | |
311 | + 2 /* jmp [r10] */ | |
312 | + (2 * 12) /* sst.w to save r2, r20-r29, r31 */ | |
313 | + 20); /* slop area */ | |
314 | ||
315 | #ifdef DEBUG | |
316 | printf_filtered ("\tfound jarl <func>,r10, disp = %ld, low_disp = %ld, new pc = 0x%.8lx\n", | |
317 | disp, low_disp, (long)current_pc + 2); | |
318 | #endif | |
319 | continue; | |
320 | } | |
321 | else if ((insn & 0xffe0) == 0x0060 && regsave_func_p) | |
322 | { /* jmp after processing register save function */ | |
323 | current_pc = save_pc + 2; | |
324 | prologue_end = save_end; | |
325 | regsave_func_p = 0; | |
326 | #ifdef DEBUG | |
327 | printf_filtered ("\tfound jmp after regsave func"); | |
328 | #endif | |
329 | } | |
330 | else if ((insn & 0x07c0) == 0x0780 /* jarl or jr */ | |
331 | || (insn & 0xffe0) == 0x0060 /* jmp */ | |
332 | || (insn & 0x0780) == 0x0580) /* branch */ | |
333 | { | |
334 | #ifdef DEBUG | |
335 | printf_filtered ("\n"); | |
336 | #endif | |
337 | break; /* Ran into end of prologue */ | |
338 | } | |
339 | ||
340 | else if ((insn & 0xffe0) == ((SP_REGNUM << 11) | 0x0240)) /* add <imm>,sp */ | |
341 | pi->frameoffset += ((insn & 0x1f) ^ 0x10) - 0x10; | |
342 | else if (insn == ((SP_REGNUM << 11) | 0x0600 | SP_REGNUM)) /* addi <imm>,sp,sp */ | |
343 | pi->frameoffset += read_memory_integer (current_pc + 2, 2); | |
5198e746 | 344 | else if (insn == ((FP_REGNUM << 11) | 0x0000 | SP_REGNUM)) /* mov sp,fp */ |
17139ec5 ZR |
345 | { |
346 | fp_used = 1; | |
5198e746 | 347 | pi->framereg = FP_REGNUM; |
17139ec5 ZR |
348 | } |
349 | ||
5198e746 | 350 | #if(0) /* Z.R. XXX */ |
17139ec5 ZR |
351 | else if (insn == ((R12_REGNUM << 11) | 0x0640 | R0_REGNUM)) /* movhi hi(const),r0,r12 */ |
352 | r12_tmp = read_memory_integer (current_pc + 2, 2) << 16; | |
353 | else if (insn == ((R12_REGNUM << 11) | 0x0620 | R12_REGNUM)) /* movea lo(const),r12,r12 */ | |
354 | r12_tmp += read_memory_integer (current_pc + 2, 2); | |
355 | else if (insn == ((SP_REGNUM << 11) | 0x01c0 | R12_REGNUM) && r12_tmp) /* add r12,sp */ | |
356 | pi->frameoffset = r12_tmp; | |
357 | else if (insn == ((EP_REGNUM << 11) | 0x0000 | SP_REGNUM)) /* mov sp,ep */ | |
358 | ep_used = 1; | |
359 | else if (insn == ((EP_REGNUM << 11) | 0x0000 | R1_REGNUM)) /* mov r1,ep */ | |
360 | ep_used = 0; | |
361 | else if (((insn & 0x07ff) == (0x0760 | SP_REGNUM) /* st.w <reg>,<offset>[sp] */ | |
362 | || (fp_used | |
363 | && (insn & 0x07ff) == (0x0760 | FP_RAW_REGNUM))) /* st.w <reg>,<offset>[fp] */ | |
364 | && pifsr | |
365 | && (((reg = (insn >> 11) & 0x1f) >= SAVE1_START_REGNUM && reg <= SAVE1_END_REGNUM) | |
366 | || (reg >= SAVE2_START_REGNUM && reg <= SAVE2_END_REGNUM) | |
367 | || (reg >= SAVE3_START_REGNUM && reg <= SAVE3_END_REGNUM))) | |
368 | { | |
369 | pifsr->reg = reg; | |
370 | pifsr->offset = read_memory_integer (current_pc + 2, 2) & ~1; | |
371 | pifsr->cur_frameoffset = pi->frameoffset; | |
372 | #ifdef DEBUG | |
373 | printf_filtered ("\tSaved register r%d, offset %d", reg, pifsr->offset); | |
374 | #endif | |
375 | pifsr++; | |
376 | } | |
377 | ||
378 | else if (ep_used /* sst.w <reg>,<offset>[ep] */ | |
379 | && ((insn & 0x0781) == 0x0501) | |
380 | && pifsr | |
381 | && (((reg = (insn >> 11) & 0x1f) >= SAVE1_START_REGNUM && reg <= SAVE1_END_REGNUM) | |
382 | || (reg >= SAVE2_START_REGNUM && reg <= SAVE2_END_REGNUM) | |
383 | || (reg >= SAVE3_START_REGNUM && reg <= SAVE3_END_REGNUM))) | |
384 | { | |
385 | pifsr->reg = reg; | |
386 | pifsr->offset = (insn & 0x007e) << 1; | |
387 | pifsr->cur_frameoffset = pi->frameoffset; | |
388 | #ifdef DEBUG | |
389 | printf_filtered ("\tSaved register r%d, offset %d", reg, pifsr->offset); | |
390 | #endif | |
391 | pifsr++; | |
392 | } | |
5198e746 | 393 | #endif /* Z.R. */ |
17139ec5 ZR |
394 | |
395 | if ((insn & 0x0780) >= 0x0600) /* Four byte instruction? */ | |
396 | current_pc += 2; | |
397 | ||
398 | #ifdef DEBUG | |
399 | printf_filtered ("\n"); | |
400 | #endif | |
401 | } | |
402 | ||
403 | if (pifsr) | |
404 | pifsr->framereg = 0; /* Tie off last entry */ | |
405 | ||
406 | /* Fix up any offsets to the final offset. If a frame pointer was created, use it | |
407 | instead of the stack pointer. */ | |
408 | for (pifsr_tmp = pi->pifsrs; pifsr_tmp && pifsr_tmp != pifsr; pifsr_tmp++) | |
409 | { | |
410 | pifsr_tmp->offset -= pi->frameoffset - pifsr_tmp->cur_frameoffset; | |
411 | pifsr_tmp->framereg = pi->framereg; | |
412 | ||
413 | #ifdef DEBUG | |
414 | printf_filtered ("Saved register r%d, offset = %d, framereg = r%d\n", | |
415 | pifsr_tmp->reg, pifsr_tmp->offset, pifsr_tmp->framereg); | |
416 | #endif | |
417 | } | |
418 | ||
419 | #ifdef DEBUG | |
420 | printf_filtered ("Framereg = r%d, frameoffset = %d\n", pi->framereg, pi->frameoffset); | |
421 | #endif | |
422 | ||
423 | return current_pc; | |
424 | } | |
425 | ||
426 | /* Function: init_extra_frame_info | |
427 | Setup the frame's frame pointer, pc, and frame addresses for saved | |
428 | registers. Most of the work is done in scan_prologue(). | |
429 | ||
430 | Note that when we are called for the last frame (currently active frame), | |
431 | that fi->pc and fi->frame will already be setup. However, fi->frame will | |
432 | be valid only if this routine uses FP. For previous frames, fi-frame will | |
5198e746 | 433 | always be correct (since that is derived from fr30_frame_chain ()). |
17139ec5 ZR |
434 | |
435 | We can be called with the PC in the call dummy under two circumstances. | |
436 | First, during normal backtracing, second, while figuring out the frame | |
437 | pointer just prior to calling the target function (see run_stack_dummy). */ | |
438 | ||
439 | void | |
5198e746 | 440 | fr30_init_extra_frame_info (fi) |
17139ec5 ZR |
441 | struct frame_info *fi; |
442 | { | |
443 | struct prologue_info pi; | |
444 | struct pifsr pifsrs[NUM_REGS + 1], *pifsr; | |
445 | int reg; | |
446 | ||
447 | if (fi->next) | |
448 | fi->pc = FRAME_SAVED_PC (fi->next); | |
449 | ||
450 | memset (fi->fsr.regs, '\000', sizeof fi->fsr.regs); | |
451 | ||
452 | /* The call dummy doesn't save any registers on the stack, so we can return | |
453 | now. */ | |
454 | if (PC_IN_CALL_DUMMY (fi->pc, fi->frame, fi->frame)) | |
455 | return; | |
456 | ||
457 | pi.pifsrs = pifsrs; | |
458 | ||
5198e746 | 459 | fr30_scan_prologue (fi->pc, &pi); |
17139ec5 ZR |
460 | |
461 | if (!fi->next && pi.framereg == SP_REGNUM) | |
462 | fi->frame = read_register (pi.framereg) - pi.frameoffset; | |
463 | ||
464 | for (pifsr = pifsrs; pifsr->framereg; pifsr++) | |
465 | { | |
466 | fi->fsr.regs[pifsr->reg] = pifsr->offset + fi->frame; | |
467 | ||
468 | if (pifsr->framereg == SP_REGNUM) | |
469 | fi->fsr.regs[pifsr->reg] += pi.frameoffset; | |
470 | } | |
471 | } | |
472 | ||
17139ec5 ZR |
473 | /* Function: find_callers_reg |
474 | Find REGNUM on the stack. Otherwise, it's in an active register. | |
475 | One thing we might want to do here is to check REGNUM against the | |
476 | clobber mask, and somehow flag it as invalid if it isn't saved on | |
477 | the stack somewhere. This would provide a graceful failure mode | |
478 | when trying to get the value of caller-saves registers for an inner | |
479 | frame. */ | |
480 | ||
481 | CORE_ADDR | |
5198e746 | 482 | fr30_find_callers_reg (fi, regnum) |
17139ec5 ZR |
483 | struct frame_info *fi; |
484 | int regnum; | |
485 | { | |
486 | for (; fi; fi = fi->next) | |
487 | if (PC_IN_CALL_DUMMY (fi->pc, fi->frame, fi->frame)) | |
488 | return generic_read_register_dummy (fi->pc, fi->frame, regnum); | |
489 | else if (fi->fsr.regs[regnum] != 0) | |
490 | return read_memory_unsigned_integer (fi->fsr.regs[regnum], | |
491 | REGISTER_RAW_SIZE(regnum)); | |
492 | ||
493 | return read_register (regnum); | |
494 | } | |
495 | ||
5198e746 ZR |
496 | |
497 | /* Function: frame_chain | |
498 | Figure out the frame prior to FI. Unfortunately, this involves | |
499 | scanning the prologue of the caller, which will also be done | |
500 | shortly by fr30_init_extra_frame_info. For the dummy frame, we | |
501 | just return the stack pointer that was in use at the time the | |
502 | function call was made. */ | |
17139ec5 ZR |
503 | |
504 | CORE_ADDR | |
5198e746 ZR |
505 | fr30_frame_chain (fi) |
506 | struct frame_info *fi; | |
17139ec5 | 507 | { |
5198e746 ZR |
508 | struct prologue_info pi; |
509 | CORE_ADDR callers_pc, fp; | |
17139ec5 | 510 | |
5198e746 ZR |
511 | /* First, find out who called us */ |
512 | callers_pc = FRAME_SAVED_PC (fi); | |
513 | /* If caller is a call-dummy, then our FP bears no relation to his FP! */ | |
514 | fp = fr30_find_callers_reg (fi, FP_REGNUM); | |
515 | if (PC_IN_CALL_DUMMY(callers_pc, fp, fp)) | |
516 | return fp; /* caller is call-dummy: return oldest value of FP */ | |
17139ec5 | 517 | |
5198e746 ZR |
518 | /* Caller is NOT a call-dummy, so everything else should just work. |
519 | Even if THIS frame is a call-dummy! */ | |
520 | pi.pifsrs = NULL; | |
17139ec5 | 521 | |
5198e746 | 522 | fr30_scan_prologue (callers_pc, &pi); |
17139ec5 | 523 | |
5198e746 ZR |
524 | if (pi.start_function) |
525 | return 0; /* Don't chain beyond the start function */ | |
17139ec5 | 526 | |
5198e746 ZR |
527 | if (pi.framereg == FP_REGNUM) |
528 | return fr30_find_callers_reg (fi, pi.framereg); | |
17139ec5 | 529 | |
5198e746 | 530 | return fi->frame - pi.frameoffset; |
17139ec5 | 531 | } |
17139ec5 ZR |
532 | /* Function: push_arguments |
533 | Setup arguments and RP for a call to the target. First four args | |
534 | go in R6->R9, subsequent args go into sp + 16 -> sp + ... Structs | |
535 | are passed by reference. 64 bit quantities (doubles and long | |
536 | longs) may be split between the regs and the stack. When calling a | |
537 | function that returns a struct, a pointer to the struct is passed | |
538 | in as a secret first argument (always in R6). | |
539 | ||
540 | Stack space for the args has NOT been allocated: that job is up to us. | |
541 | */ | |
542 | ||
5198e746 | 543 | #if(0) /* Z.R. XXX */ |
17139ec5 | 544 | CORE_ADDR |
5198e746 | 545 | fr30_push_arguments (nargs, args, sp, struct_return, struct_addr) |
17139ec5 ZR |
546 | int nargs; |
547 | value_ptr *args; | |
548 | CORE_ADDR sp; | |
549 | unsigned char struct_return; | |
550 | CORE_ADDR struct_addr; | |
551 | { | |
552 | int argreg; | |
553 | int argnum; | |
554 | int len = 0; | |
555 | int stack_offset; | |
556 | ||
557 | /* First, just for safety, make sure stack is aligned */ | |
558 | sp &= ~3; | |
559 | ||
560 | /* Now make space on the stack for the args. */ | |
561 | for (argnum = 0; argnum < nargs; argnum++) | |
562 | len += ((TYPE_LENGTH(VALUE_TYPE(args[argnum])) + 3) & ~3); | |
563 | sp -= len; /* possibly over-allocating, but it works... */ | |
564 | /* (you might think we could allocate 16 bytes */ | |
565 | /* less, but the ABI seems to use it all! ) */ | |
566 | argreg = ARG0_REGNUM; | |
567 | ||
568 | /* the struct_return pointer occupies the first parameter-passing reg */ | |
569 | if (struct_return) | |
570 | write_register (argreg++, struct_addr); | |
571 | ||
572 | stack_offset = 16; | |
573 | /* The offset onto the stack at which we will start copying parameters | |
574 | (after the registers are used up) begins at 16 rather than at zero. | |
575 | I don't really know why, that's just the way it seems to work. */ | |
576 | ||
577 | /* Now load as many as possible of the first arguments into | |
578 | registers, and push the rest onto the stack. There are 16 bytes | |
579 | in four registers available. Loop thru args from first to last. */ | |
580 | for (argnum = 0; argnum < nargs; argnum++) | |
581 | { | |
582 | int len; | |
583 | char *val; | |
584 | char valbuf[REGISTER_RAW_SIZE(ARG0_REGNUM)]; | |
585 | ||
586 | if (TYPE_CODE (VALUE_TYPE (*args)) == TYPE_CODE_STRUCT | |
587 | && TYPE_LENGTH (VALUE_TYPE (*args)) > 8) | |
588 | { | |
589 | store_address (valbuf, 4, VALUE_ADDRESS (*args)); | |
590 | len = 4; | |
591 | val = valbuf; | |
592 | } | |
593 | else | |
594 | { | |
595 | len = TYPE_LENGTH (VALUE_TYPE (*args)); | |
596 | val = (char *)VALUE_CONTENTS (*args); | |
597 | } | |
598 | ||
599 | while (len > 0) | |
600 | if (argreg <= ARGLAST_REGNUM) | |
601 | { | |
602 | CORE_ADDR regval; | |
603 | ||
604 | regval = extract_address (val, REGISTER_RAW_SIZE (argreg)); | |
605 | write_register (argreg, regval); | |
606 | ||
607 | len -= REGISTER_RAW_SIZE (argreg); | |
608 | val += REGISTER_RAW_SIZE (argreg); | |
609 | argreg++; | |
610 | } | |
611 | else | |
612 | { | |
613 | write_memory (sp + stack_offset, val, 4); | |
614 | ||
615 | len -= 4; | |
616 | val += 4; | |
617 | stack_offset += 4; | |
618 | } | |
619 | args++; | |
620 | } | |
621 | return sp; | |
622 | } | |
5198e746 | 623 | #endif /* Z.R. */ |
17139ec5 ZR |
624 | |
625 | /* Function: push_return_address (pc) | |
626 | Set up the return address for the inferior function call. | |
627 | Needed for targets where we don't actually execute a JSR/BSR instruction */ | |
628 | ||
629 | CORE_ADDR | |
5198e746 | 630 | fr30_push_return_address (pc, sp) |
17139ec5 ZR |
631 | CORE_ADDR pc; |
632 | CORE_ADDR sp; | |
633 | { | |
634 | write_register (RP_REGNUM, CALL_DUMMY_ADDRESS ()); | |
635 | return sp; | |
636 | } | |
637 | ||
638 | /* Function: frame_saved_pc | |
639 | Find the caller of this frame. We do this by seeing if RP_REGNUM | |
640 | is saved in the stack anywhere, otherwise we get it from the | |
641 | registers. If the inner frame is a dummy frame, return its PC | |
642 | instead of RP, because that's where "caller" of the dummy-frame | |
643 | will be found. */ | |
644 | ||
645 | CORE_ADDR | |
5198e746 | 646 | fr30_frame_saved_pc (fi) |
17139ec5 ZR |
647 | struct frame_info *fi; |
648 | { | |
649 | if (PC_IN_CALL_DUMMY(fi->pc, fi->frame, fi->frame)) | |
650 | return generic_read_register_dummy(fi->pc, fi->frame, PC_REGNUM); | |
651 | else | |
5198e746 | 652 | return fr30_find_callers_reg (fi, RP_REGNUM); |
17139ec5 ZR |
653 | } |
654 | ||
5198e746 | 655 | #if(0) /* Z.R. XXX */ |
17139ec5 ZR |
656 | void |
657 | get_saved_register (raw_buffer, optimized, addrp, frame, regnum, lval) | |
658 | char *raw_buffer; | |
659 | int *optimized; | |
660 | CORE_ADDR *addrp; | |
661 | struct frame_info *frame; | |
662 | int regnum; | |
663 | enum lval_type *lval; | |
664 | { | |
665 | generic_get_saved_register (raw_buffer, optimized, addrp, | |
666 | frame, regnum, lval); | |
667 | } | |
5198e746 | 668 | #endif /* Z.R. */ |
17139ec5 ZR |
669 | |
670 | ||
671 | /* Function: fix_call_dummy | |
672 | Pokes the callee function's address into the CALL_DUMMY assembly stub. | |
673 | Assumes that the CALL_DUMMY looks like this: | |
674 | jarl <offset24>, r31 | |
675 | trap | |
676 | */ | |
677 | ||
678 | int | |
5198e746 | 679 | fr30_fix_call_dummy (dummy, sp, fun, nargs, args, type, gcc_p) |
17139ec5 ZR |
680 | char *dummy; |
681 | CORE_ADDR sp; | |
682 | CORE_ADDR fun; | |
683 | int nargs; | |
684 | value_ptr *args; | |
685 | struct type *type; | |
686 | int gcc_p; | |
687 | { | |
688 | long offset24; | |
689 | ||
690 | offset24 = (long) fun - (long) entry_point_address (); | |
691 | offset24 &= 0x3fffff; | |
692 | offset24 |= 0xff800000; /* jarl <offset24>, r31 */ | |
693 | ||
694 | store_unsigned_integer ((unsigned int *)&dummy[2], 2, offset24 & 0xffff); | |
695 | store_unsigned_integer ((unsigned int *)&dummy[0], 2, offset24 >> 16); | |
696 | return 0; | |
697 | } | |
698 |