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