Commit | Line | Data |
---|---|---|
c906108c SS |
1 | /* Target-dependent code for Hitachi Super-H, for GDB. |
2 | Copyright 1993, 1994, 1995, 1996, 1997, 1998 Free Software Foundation, Inc. | |
3 | ||
c5aa993b | 4 | This file is part of GDB. |
c906108c | 5 | |
c5aa993b JM |
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. | |
c906108c | 10 | |
c5aa993b JM |
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. | |
c906108c | 15 | |
c5aa993b JM |
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, | |
19 | Boston, MA 02111-1307, USA. */ | |
c906108c SS |
20 | |
21 | /* | |
c5aa993b JM |
22 | Contributed by Steve Chamberlain |
23 | sac@cygnus.com | |
c906108c SS |
24 | */ |
25 | ||
26 | #include "defs.h" | |
27 | #include "frame.h" | |
28 | #include "obstack.h" | |
29 | #include "symtab.h" | |
30 | #include "symfile.h" | |
31 | #include "gdbtypes.h" | |
32 | #include "gdbcmd.h" | |
33 | #include "gdbcore.h" | |
34 | #include "value.h" | |
35 | #include "dis-asm.h" | |
36 | #include "inferior.h" /* for BEFORE_TEXT_END etc. */ | |
37 | #include "gdb_string.h" | |
38 | ||
39 | /* A set of original names, to be used when restoring back to generic | |
40 | registers from a specific set. */ | |
9846de1b | 41 | /* *INDENT-OFF* */ |
c906108c SS |
42 | static char *sh_generic_reg_names[] = { |
43 | "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", | |
44 | "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", | |
45 | "pc", "pr", "gbr", "vbr", "mach", "macl", "sr", | |
46 | "fpul", "fpscr", | |
47 | "fr0", "fr1", "fr2", "fr3", "fr4", "fr5", "fr6", "fr7", | |
48 | "fr8", "fr9", "fr10", "fr11", "fr12", "fr13", "fr14", "fr15", | |
49 | "ssr", "spc", | |
50 | "r0b0", "r1b0", "r2b0", "r3b0", "r4b0", "r5b0", "r6b0", "r7b0", | |
51 | "r0b1", "r1b1", "r2b1", "r3b1", "r4b1", "r5b1", "r6b1", "r7b1", | |
52 | }; | |
53 | ||
54 | static char *sh_reg_names[] = { | |
55 | "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", | |
56 | "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", | |
57 | "pc", "pr", "gbr", "vbr", "mach", "macl", "sr", | |
58 | "", "", | |
59 | "", "", "", "", "", "", "", "", | |
60 | "", "", "", "", "", "", "", "", | |
61 | "", "", | |
62 | "", "", "", "", "", "", "", "", | |
63 | "", "", "", "", "", "", "", "", | |
64 | }; | |
65 | ||
66 | static char *sh3_reg_names[] = { | |
67 | "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", | |
68 | "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", | |
69 | "pc", "pr", "gbr", "vbr", "mach", "macl", "sr", | |
70 | "", "", | |
71 | "", "", "", "", "", "", "", "", | |
72 | "", "", "", "", "", "", "", "", | |
73 | "ssr", "spc", | |
74 | "r0b0", "r1b0", "r2b0", "r3b0", "r4b0", "r5b0", "r6b0", "r7b0", | |
75 | "r0b1", "r1b1", "r2b1", "r3b1", "r4b1", "r5b1", "r6b1", "r7b1" | |
76 | }; | |
77 | ||
78 | static char *sh3e_reg_names[] = { | |
79 | "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", | |
80 | "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", | |
81 | "pc", "pr", "gbr", "vbr", "mach", "macl", "sr", | |
82 | "fpul", "fpscr", | |
83 | "fr0", "fr1", "fr2", "fr3", "fr4", "fr5", "fr6", "fr7", | |
84 | "fr8", "fr9", "fr10", "fr11", "fr12", "fr13", "fr14", "fr15", | |
85 | "ssr", "spc", | |
86 | "r0b0", "r1b0", "r2b0", "r3b0", "r4b0", "r5b0", "r6b0", "r7b0", | |
87 | "r0b1", "r1b1", "r2b1", "r3b1", "r4b1", "r5b1", "r6b1", "r7b1", | |
88 | }; | |
9846de1b | 89 | /* *INDENT-ON* */ |
c906108c | 90 | |
c5aa993b JM |
91 | |
92 | ||
c906108c SS |
93 | char **sh_register_names = sh_generic_reg_names; |
94 | ||
c5aa993b JM |
95 | struct |
96 | { | |
97 | char **regnames; | |
98 | int mach; | |
99 | } | |
100 | sh_processor_type_table[] = | |
101 | { | |
102 | { | |
103 | sh_reg_names, bfd_mach_sh | |
104 | } | |
105 | , | |
106 | { | |
107 | sh3_reg_names, bfd_mach_sh3 | |
108 | } | |
109 | , | |
110 | { | |
111 | sh3e_reg_names, bfd_mach_sh3e | |
112 | } | |
113 | , | |
c5aa993b JM |
114 | { |
115 | NULL, 0 | |
116 | } | |
c906108c SS |
117 | }; |
118 | ||
119 | /* Prologue looks like | |
c5aa993b JM |
120 | [mov.l <regs>,@-r15]... |
121 | [sts.l pr,@-r15] | |
122 | [mov.l r14,@-r15] | |
123 | [mov r15,r14] | |
124 | */ | |
c906108c SS |
125 | |
126 | #define IS_STS(x) ((x) == 0x4f22) | |
127 | #define IS_PUSH(x) (((x) & 0xff0f) == 0x2f06) | |
128 | #define GET_PUSHED_REG(x) (((x) >> 4) & 0xf) | |
129 | #define IS_MOV_SP_FP(x) ((x) == 0x6ef3) | |
130 | #define IS_ADD_SP(x) (((x) & 0xff00) == 0x7f00) | |
131 | #define IS_MOV_R3(x) (((x) & 0xff00) == 0x1a00) | |
132 | #define IS_SHLL_R3(x) ((x) == 0x4300) | |
133 | #define IS_ADD_R3SP(x) ((x) == 0x3f3c) | |
134 | #define IS_FMOV(x) (((x) & 0xf00f) == 0xf00b) | |
135 | #define FPSCR_SZ (1 << 20) | |
136 | ||
137 | ||
138 | /* Should call_function allocate stack space for a struct return? */ | |
139 | int | |
140 | sh_use_struct_convention (gcc_p, type) | |
141 | int gcc_p; | |
142 | struct type *type; | |
143 | { | |
144 | return (TYPE_LENGTH (type) > 1); | |
145 | } | |
146 | ||
147 | ||
148 | /* Skip any prologue before the guts of a function */ | |
149 | ||
150 | CORE_ADDR | |
151 | sh_skip_prologue (start_pc) | |
152 | CORE_ADDR start_pc; | |
153 | { | |
154 | int w; | |
155 | ||
156 | w = read_memory_integer (start_pc, 2); | |
157 | while (IS_STS (w) | |
158 | || IS_FMOV (w) | |
159 | || IS_PUSH (w) | |
160 | || IS_MOV_SP_FP (w) | |
161 | || IS_MOV_R3 (w) | |
162 | || IS_ADD_R3SP (w) | |
163 | || IS_ADD_SP (w) | |
164 | || IS_SHLL_R3 (w)) | |
165 | { | |
166 | start_pc += 2; | |
167 | w = read_memory_integer (start_pc, 2); | |
168 | } | |
169 | ||
170 | return start_pc; | |
171 | } | |
172 | ||
173 | /* Disassemble an instruction. */ | |
174 | ||
175 | int | |
176 | gdb_print_insn_sh (memaddr, info) | |
177 | bfd_vma memaddr; | |
178 | disassemble_info *info; | |
179 | { | |
180 | if (TARGET_BYTE_ORDER == BIG_ENDIAN) | |
181 | return print_insn_sh (memaddr, info); | |
182 | else | |
183 | return print_insn_shl (memaddr, info); | |
184 | } | |
185 | ||
186 | /* Given a GDB frame, determine the address of the calling function's frame. | |
187 | This will be used to create a new GDB frame struct, and then | |
188 | INIT_EXTRA_FRAME_INFO and INIT_FRAME_PC will be called for the new frame. | |
189 | ||
190 | For us, the frame address is its stack pointer value, so we look up | |
191 | the function prologue to determine the caller's sp value, and return it. */ | |
192 | ||
193 | CORE_ADDR | |
194 | sh_frame_chain (frame) | |
195 | struct frame_info *frame; | |
196 | { | |
197 | if (PC_IN_CALL_DUMMY (frame->pc, frame->frame, frame->frame)) | |
198 | return frame->frame; /* dummy frame same as caller's frame */ | |
199 | if (!inside_entry_file (frame->pc)) | |
200 | return read_memory_integer (FRAME_FP (frame) + frame->f_offset, 4); | |
201 | else | |
202 | return 0; | |
203 | } | |
204 | ||
205 | /* Find REGNUM on the stack. Otherwise, it's in an active register. One thing | |
206 | we might want to do here is to check REGNUM against the clobber mask, and | |
207 | somehow flag it as invalid if it isn't saved on the stack somewhere. This | |
208 | would provide a graceful failure mode when trying to get the value of | |
209 | caller-saves registers for an inner frame. */ | |
210 | ||
211 | CORE_ADDR | |
212 | sh_find_callers_reg (fi, regnum) | |
213 | struct frame_info *fi; | |
214 | int regnum; | |
215 | { | |
216 | struct frame_saved_regs fsr; | |
217 | ||
218 | for (; fi; fi = fi->next) | |
219 | if (PC_IN_CALL_DUMMY (fi->pc, fi->frame, fi->frame)) | |
220 | /* When the caller requests PR from the dummy frame, we return PC because | |
c5aa993b | 221 | that's where the previous routine appears to have done a call from. */ |
c906108c | 222 | return generic_read_register_dummy (fi->pc, fi->frame, regnum); |
c5aa993b | 223 | else |
c906108c | 224 | { |
c5aa993b | 225 | FRAME_FIND_SAVED_REGS (fi, fsr); |
c906108c | 226 | if (fsr.regs[regnum] != 0) |
c5aa993b JM |
227 | return read_memory_integer (fsr.regs[regnum], |
228 | REGISTER_RAW_SIZE (regnum)); | |
c906108c SS |
229 | } |
230 | return read_register (regnum); | |
231 | } | |
232 | ||
233 | /* Put here the code to store, into a struct frame_saved_regs, the | |
234 | addresses of the saved registers of frame described by FRAME_INFO. | |
235 | This includes special registers such as pc and fp saved in special | |
236 | ways in the stack frame. sp is even more special: the address we | |
237 | return for it IS the sp for the next frame. */ | |
238 | ||
239 | void | |
240 | sh_frame_find_saved_regs (fi, fsr) | |
241 | struct frame_info *fi; | |
242 | struct frame_saved_regs *fsr; | |
243 | { | |
244 | int where[NUM_REGS]; | |
245 | int rn; | |
246 | int have_fp = 0; | |
247 | int depth; | |
248 | int pc; | |
249 | int opc; | |
250 | int insn; | |
251 | int r3_val = 0; | |
c5aa993b | 252 | char *dummy_regs = generic_find_dummy_frame (fi->pc, fi->frame); |
c906108c SS |
253 | |
254 | if (dummy_regs) | |
255 | { | |
256 | /* DANGER! This is ONLY going to work if the char buffer format of | |
c5aa993b JM |
257 | the saved registers is byte-for-byte identical to the |
258 | CORE_ADDR regs[NUM_REGS] format used by struct frame_saved_regs! */ | |
259 | memcpy (&fsr->regs, dummy_regs, sizeof (fsr)); | |
c906108c SS |
260 | return; |
261 | } | |
262 | ||
263 | opc = pc = get_pc_function_start (fi->pc); | |
264 | ||
265 | insn = read_memory_integer (pc, 2); | |
266 | ||
267 | fi->leaf_function = 1; | |
268 | fi->f_offset = 0; | |
269 | ||
270 | for (rn = 0; rn < NUM_REGS; rn++) | |
271 | where[rn] = -1; | |
272 | ||
273 | depth = 0; | |
274 | ||
275 | /* Loop around examining the prologue insns until we find something | |
276 | that does not appear to be part of the prologue. But give up | |
277 | after 20 of them, since we're getting silly then. */ | |
278 | ||
279 | while (pc < opc + 20 * 2) | |
280 | { | |
281 | /* See where the registers will be saved to */ | |
282 | if (IS_PUSH (insn)) | |
283 | { | |
284 | pc += 2; | |
285 | rn = GET_PUSHED_REG (insn); | |
286 | where[rn] = depth; | |
287 | insn = read_memory_integer (pc, 2); | |
288 | depth += 4; | |
289 | } | |
290 | else if (IS_STS (insn)) | |
291 | { | |
292 | pc += 2; | |
293 | where[PR_REGNUM] = depth; | |
294 | insn = read_memory_integer (pc, 2); | |
295 | /* If we're storing the pr then this isn't a leaf */ | |
296 | fi->leaf_function = 0; | |
297 | depth += 4; | |
298 | } | |
299 | else if (IS_MOV_R3 (insn)) | |
300 | { | |
301 | r3_val = ((insn & 0xff) ^ 0x80) - 0x80; | |
302 | pc += 2; | |
303 | insn = read_memory_integer (pc, 2); | |
304 | } | |
305 | else if (IS_SHLL_R3 (insn)) | |
306 | { | |
307 | r3_val <<= 1; | |
308 | pc += 2; | |
309 | insn = read_memory_integer (pc, 2); | |
310 | } | |
311 | else if (IS_ADD_R3SP (insn)) | |
312 | { | |
313 | depth += -r3_val; | |
314 | pc += 2; | |
315 | insn = read_memory_integer (pc, 2); | |
316 | } | |
317 | else if (IS_ADD_SP (insn)) | |
318 | { | |
319 | pc += 2; | |
320 | depth -= ((insn & 0xff) ^ 0x80) - 0x80; | |
321 | insn = read_memory_integer (pc, 2); | |
322 | } | |
323 | else if (IS_FMOV (insn)) | |
324 | { | |
325 | pc += 2; | |
326 | insn = read_memory_integer (pc, 2); | |
327 | if (read_register (FPSCR_REGNUM) & FPSCR_SZ) | |
328 | { | |
329 | depth += 8; | |
330 | } | |
331 | else | |
332 | { | |
333 | depth += 4; | |
334 | } | |
335 | } | |
336 | else | |
337 | break; | |
338 | } | |
339 | ||
340 | /* Now we know how deep things are, we can work out their addresses */ | |
341 | ||
342 | for (rn = 0; rn < NUM_REGS; rn++) | |
343 | { | |
344 | if (where[rn] >= 0) | |
345 | { | |
346 | if (rn == FP_REGNUM) | |
347 | have_fp = 1; | |
348 | ||
349 | fsr->regs[rn] = fi->frame - where[rn] + depth - 4; | |
350 | } | |
351 | else | |
352 | { | |
353 | fsr->regs[rn] = 0; | |
354 | } | |
355 | } | |
356 | ||
357 | if (have_fp) | |
358 | { | |
359 | fsr->regs[SP_REGNUM] = read_memory_integer (fsr->regs[FP_REGNUM], 4); | |
360 | } | |
361 | else | |
362 | { | |
363 | fsr->regs[SP_REGNUM] = fi->frame - 4; | |
364 | } | |
365 | ||
366 | fi->f_offset = depth - where[FP_REGNUM] - 4; | |
367 | /* Work out the return pc - either from the saved pr or the pr | |
368 | value */ | |
369 | } | |
370 | ||
371 | /* initialize the extra info saved in a FRAME */ | |
372 | ||
373 | void | |
374 | sh_init_extra_frame_info (fromleaf, fi) | |
375 | int fromleaf; | |
376 | struct frame_info *fi; | |
377 | { | |
378 | struct frame_saved_regs fsr; | |
379 | ||
380 | if (fi->next) | |
381 | fi->pc = FRAME_SAVED_PC (fi->next); | |
382 | ||
383 | if (PC_IN_CALL_DUMMY (fi->pc, fi->frame, fi->frame)) | |
384 | { | |
385 | /* We need to setup fi->frame here because run_stack_dummy gets it wrong | |
c5aa993b JM |
386 | by assuming it's always FP. */ |
387 | fi->frame = generic_read_register_dummy (fi->pc, fi->frame, | |
388 | SP_REGNUM); | |
389 | fi->return_pc = generic_read_register_dummy (fi->pc, fi->frame, | |
c906108c SS |
390 | PC_REGNUM); |
391 | fi->f_offset = -(CALL_DUMMY_LENGTH + 4); | |
392 | fi->leaf_function = 0; | |
393 | return; | |
394 | } | |
395 | else | |
396 | { | |
397 | FRAME_FIND_SAVED_REGS (fi, fsr); | |
398 | fi->return_pc = sh_find_callers_reg (fi, PR_REGNUM); | |
399 | } | |
400 | } | |
401 | ||
402 | /* Discard from the stack the innermost frame, | |
403 | restoring all saved registers. */ | |
404 | ||
405 | void | |
406 | sh_pop_frame () | |
407 | { | |
408 | register struct frame_info *frame = get_current_frame (); | |
409 | register CORE_ADDR fp; | |
410 | register int regnum; | |
411 | struct frame_saved_regs fsr; | |
412 | ||
413 | if (PC_IN_CALL_DUMMY (frame->pc, frame->frame, frame->frame)) | |
414 | generic_pop_dummy_frame (); | |
415 | else | |
c5aa993b JM |
416 | { |
417 | fp = FRAME_FP (frame); | |
418 | get_frame_saved_regs (frame, &fsr); | |
c906108c | 419 | |
c5aa993b JM |
420 | /* Copy regs from where they were saved in the frame */ |
421 | for (regnum = 0; regnum < NUM_REGS; regnum++) | |
422 | if (fsr.regs[regnum]) | |
423 | write_register (regnum, read_memory_integer (fsr.regs[regnum], 4)); | |
c906108c | 424 | |
c5aa993b JM |
425 | write_register (PC_REGNUM, frame->return_pc); |
426 | write_register (SP_REGNUM, fp + 4); | |
427 | } | |
c906108c SS |
428 | flush_cached_frames (); |
429 | } | |
430 | ||
431 | /* Function: push_arguments | |
432 | Setup the function arguments for calling a function in the inferior. | |
433 | ||
434 | On the Hitachi SH architecture, there are four registers (R4 to R7) | |
435 | which are dedicated for passing function arguments. Up to the first | |
436 | four arguments (depending on size) may go into these registers. | |
437 | The rest go on the stack. | |
438 | ||
439 | Arguments that are smaller than 4 bytes will still take up a whole | |
440 | register or a whole 32-bit word on the stack, and will be | |
441 | right-justified in the register or the stack word. This includes | |
442 | chars, shorts, and small aggregate types. | |
443 | ||
444 | Arguments that are larger than 4 bytes may be split between two or | |
445 | more registers. If there are not enough registers free, an argument | |
446 | may be passed partly in a register (or registers), and partly on the | |
447 | stack. This includes doubles, long longs, and larger aggregates. | |
448 | As far as I know, there is no upper limit to the size of aggregates | |
449 | that will be passed in this way; in other words, the convention of | |
450 | passing a pointer to a large aggregate instead of a copy is not used. | |
451 | ||
452 | An exceptional case exists for struct arguments (and possibly other | |
453 | aggregates such as arrays) if the size is larger than 4 bytes but | |
454 | not a multiple of 4 bytes. In this case the argument is never split | |
455 | between the registers and the stack, but instead is copied in its | |
456 | entirety onto the stack, AND also copied into as many registers as | |
457 | there is room for. In other words, space in registers permitting, | |
458 | two copies of the same argument are passed in. As far as I can tell, | |
459 | only the one on the stack is used, although that may be a function | |
460 | of the level of compiler optimization. I suspect this is a compiler | |
461 | bug. Arguments of these odd sizes are left-justified within the | |
462 | word (as opposed to arguments smaller than 4 bytes, which are | |
463 | right-justified). | |
c5aa993b | 464 | |
c906108c SS |
465 | |
466 | If the function is to return an aggregate type such as a struct, it | |
467 | is either returned in the normal return value register R0 (if its | |
468 | size is no greater than one byte), or else the caller must allocate | |
469 | space into which the callee will copy the return value (if the size | |
470 | is greater than one byte). In this case, a pointer to the return | |
471 | value location is passed into the callee in register R2, which does | |
472 | not displace any of the other arguments passed in via registers R4 | |
473 | to R7. */ | |
474 | ||
475 | CORE_ADDR | |
476 | sh_push_arguments (nargs, args, sp, struct_return, struct_addr) | |
477 | int nargs; | |
478 | value_ptr *args; | |
479 | CORE_ADDR sp; | |
480 | unsigned char struct_return; | |
481 | CORE_ADDR struct_addr; | |
482 | { | |
483 | int stack_offset, stack_alloc; | |
484 | int argreg; | |
485 | int argnum; | |
486 | struct type *type; | |
487 | CORE_ADDR regval; | |
488 | char *val; | |
489 | char valbuf[4]; | |
490 | int len; | |
491 | int odd_sized_struct; | |
492 | ||
493 | /* first force sp to a 4-byte alignment */ | |
494 | sp = sp & ~3; | |
495 | ||
496 | /* The "struct return pointer" pseudo-argument has its own dedicated | |
497 | register */ | |
498 | if (struct_return) | |
c5aa993b | 499 | write_register (STRUCT_RETURN_REGNUM, struct_addr); |
c906108c SS |
500 | |
501 | /* Now make sure there's space on the stack */ | |
502 | for (argnum = 0, stack_alloc = 0; | |
503 | argnum < nargs; argnum++) | |
c5aa993b JM |
504 | stack_alloc += ((TYPE_LENGTH (VALUE_TYPE (args[argnum])) + 3) & ~3); |
505 | sp -= stack_alloc; /* make room on stack for args */ | |
c906108c SS |
506 | |
507 | ||
508 | /* Now load as many as possible of the first arguments into | |
509 | registers, and push the rest onto the stack. There are 16 bytes | |
510 | in four registers available. Loop thru args from first to last. */ | |
511 | ||
512 | argreg = ARG0_REGNUM; | |
513 | for (argnum = 0, stack_offset = 0; argnum < nargs; argnum++) | |
514 | { | |
515 | type = VALUE_TYPE (args[argnum]); | |
c5aa993b JM |
516 | len = TYPE_LENGTH (type); |
517 | memset (valbuf, 0, sizeof (valbuf)); | |
c906108c | 518 | if (len < 4) |
c5aa993b JM |
519 | { /* value gets right-justified in the register or stack word */ |
520 | memcpy (valbuf + (4 - len), | |
521 | (char *) VALUE_CONTENTS (args[argnum]), len); | |
522 | val = valbuf; | |
523 | } | |
c906108c | 524 | else |
c5aa993b | 525 | val = (char *) VALUE_CONTENTS (args[argnum]); |
c906108c SS |
526 | |
527 | if (len > 4 && (len & 3) != 0) | |
c5aa993b JM |
528 | odd_sized_struct = 1; /* such structs go entirely on stack */ |
529 | else | |
c906108c SS |
530 | odd_sized_struct = 0; |
531 | while (len > 0) | |
532 | { | |
533 | if (argreg > ARGLAST_REGNUM || odd_sized_struct) | |
c5aa993b | 534 | { /* must go on the stack */ |
c906108c SS |
535 | write_memory (sp + stack_offset, val, 4); |
536 | stack_offset += 4; | |
537 | } | |
538 | /* NOTE WELL!!!!! This is not an "else if" clause!!! | |
539 | That's because some *&^%$ things get passed on the stack | |
540 | AND in the registers! */ | |
541 | if (argreg <= ARGLAST_REGNUM) | |
c5aa993b JM |
542 | { /* there's room in a register */ |
543 | regval = extract_address (val, REGISTER_RAW_SIZE (argreg)); | |
c906108c SS |
544 | write_register (argreg++, regval); |
545 | } | |
546 | /* Store the value 4 bytes at a time. This means that things | |
547 | larger than 4 bytes may go partly in registers and partly | |
548 | on the stack. */ | |
c5aa993b JM |
549 | len -= REGISTER_RAW_SIZE (argreg); |
550 | val += REGISTER_RAW_SIZE (argreg); | |
c906108c SS |
551 | } |
552 | } | |
553 | return sp; | |
554 | } | |
555 | ||
556 | /* Function: push_return_address (pc) | |
557 | Set up the return address for the inferior function call. | |
558 | Needed for targets where we don't actually execute a JSR/BSR instruction */ | |
559 | ||
560 | CORE_ADDR | |
561 | sh_push_return_address (pc, sp) | |
562 | CORE_ADDR pc; | |
563 | CORE_ADDR sp; | |
564 | { | |
565 | write_register (PR_REGNUM, CALL_DUMMY_ADDRESS ()); | |
566 | return sp; | |
567 | } | |
568 | ||
569 | /* Function: fix_call_dummy | |
570 | Poke the callee function's address into the destination part of | |
571 | the CALL_DUMMY. The address is actually stored in a data word | |
572 | following the actualy CALL_DUMMY instructions, which will load | |
573 | it into a register using PC-relative addressing. This function | |
574 | expects the CALL_DUMMY to look like this: | |
575 | ||
c5aa993b JM |
576 | mov.w @(2,PC), R8 |
577 | jsr @R8 | |
578 | nop | |
579 | trap | |
580 | <destination> | |
581 | */ | |
c906108c SS |
582 | |
583 | #if 0 | |
584 | void | |
585 | sh_fix_call_dummy (dummy, pc, fun, nargs, args, type, gcc_p) | |
586 | char *dummy; | |
587 | CORE_ADDR pc; | |
588 | CORE_ADDR fun; | |
589 | int nargs; | |
590 | value_ptr *args; | |
591 | struct type *type; | |
592 | int gcc_p; | |
593 | { | |
594 | *(unsigned long *) (dummy + 8) = fun; | |
595 | } | |
596 | #endif | |
597 | ||
c906108c SS |
598 | |
599 | /* Modify the actual processor type. */ | |
600 | ||
601 | int | |
602 | sh_target_architecture_hook (ap) | |
603 | const bfd_arch_info_type *ap; | |
604 | { | |
605 | int i, j; | |
606 | ||
607 | if (ap->arch != bfd_arch_sh) | |
608 | return 0; | |
609 | ||
610 | for (i = 0; sh_processor_type_table[i].regnames != NULL; i++) | |
611 | { | |
612 | if (sh_processor_type_table[i].mach == ap->mach) | |
613 | { | |
614 | sh_register_names = sh_processor_type_table[i].regnames; | |
615 | return 1; | |
616 | } | |
617 | } | |
618 | ||
96baa820 | 619 | internal_error ("Architecture `%s' unreconized", ap->printable_name); |
c906108c SS |
620 | } |
621 | ||
622 | /* Print the registers in a form similar to the E7000 */ | |
623 | ||
624 | static void | |
625 | sh_show_regs (args, from_tty) | |
626 | char *args; | |
627 | int from_tty; | |
628 | { | |
629 | int cpu; | |
630 | if (TARGET_ARCHITECTURE->arch == bfd_arch_sh) | |
631 | cpu = TARGET_ARCHITECTURE->mach; | |
632 | else | |
633 | cpu = 0; | |
634 | ||
d4f3574e SS |
635 | printf_filtered ("PC=%s SR=%08lx PR=%08lx MACH=%08lx MACHL=%08lx\n", |
636 | paddr (read_register (PC_REGNUM)), | |
637 | (long) read_register (SR_REGNUM), | |
638 | (long) read_register (PR_REGNUM), | |
639 | (long) read_register (MACH_REGNUM), | |
640 | (long) read_register (MACL_REGNUM)); | |
641 | ||
642 | printf_filtered ("GBR=%08lx VBR=%08lx", | |
643 | (long) read_register (GBR_REGNUM), | |
644 | (long) read_register (VBR_REGNUM)); | |
c906108c SS |
645 | if (cpu == bfd_mach_sh3 || cpu == bfd_mach_sh3e) |
646 | { | |
d4f3574e SS |
647 | printf_filtered (" SSR=%08lx SPC=%08lx", |
648 | (long) read_register (SSR_REGNUM), | |
649 | (long) read_register (SPC_REGNUM)); | |
c906108c | 650 | if (cpu == bfd_mach_sh3e) |
c5aa993b | 651 | { |
d4f3574e SS |
652 | printf_filtered (" FPUL=%08lx FPSCR=%08lx", |
653 | (long) read_register (FPUL_REGNUM), | |
654 | (long) read_register (FPSCR_REGNUM)); | |
c5aa993b | 655 | } |
c906108c SS |
656 | } |
657 | ||
d4f3574e SS |
658 | printf_filtered ("\nR0-R7 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n", |
659 | (long) read_register (0), | |
660 | (long) read_register (1), | |
661 | (long) read_register (2), | |
662 | (long) read_register (3), | |
663 | (long) read_register (4), | |
664 | (long) read_register (5), | |
665 | (long) read_register (6), | |
666 | (long) read_register (7)); | |
667 | printf_filtered ("R8-R15 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n", | |
668 | (long) read_register (8), | |
669 | (long) read_register (9), | |
670 | (long) read_register (10), | |
671 | (long) read_register (11), | |
672 | (long) read_register (12), | |
673 | (long) read_register (13), | |
674 | (long) read_register (14), | |
675 | (long) read_register (15)); | |
c906108c SS |
676 | if (cpu == bfd_mach_sh3e) |
677 | { | |
d4f3574e SS |
678 | printf_filtered ("FP0-FP7 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n", |
679 | (long) read_register (FP0_REGNUM + 0), | |
680 | (long) read_register (FP0_REGNUM + 1), | |
681 | (long) read_register (FP0_REGNUM + 2), | |
682 | (long) read_register (FP0_REGNUM + 3), | |
683 | (long) read_register (FP0_REGNUM + 4), | |
684 | (long) read_register (FP0_REGNUM + 5), | |
685 | (long) read_register (FP0_REGNUM + 6), | |
686 | (long) read_register (FP0_REGNUM + 7)); | |
687 | printf_filtered ("FP8-FP15 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n", | |
688 | (long) read_register (FP0_REGNUM + 8), | |
689 | (long) read_register (FP0_REGNUM + 9), | |
690 | (long) read_register (FP0_REGNUM + 10), | |
691 | (long) read_register (FP0_REGNUM + 11), | |
692 | (long) read_register (FP0_REGNUM + 12), | |
693 | (long) read_register (FP0_REGNUM + 13), | |
694 | (long) read_register (FP0_REGNUM + 14), | |
695 | (long) read_register (FP0_REGNUM + 15)); | |
c906108c SS |
696 | } |
697 | } | |
698 | ||
699 | /* Function: extract_return_value | |
700 | Find a function's return value in the appropriate registers (in regbuf), | |
701 | and copy it into valbuf. */ | |
702 | ||
703 | void | |
704 | sh_extract_return_value (type, regbuf, valbuf) | |
705 | struct type *type; | |
706 | void *regbuf; | |
707 | void *valbuf; | |
708 | { | |
c5aa993b | 709 | int len = TYPE_LENGTH (type); |
c906108c SS |
710 | |
711 | if (len <= 4) | |
712 | memcpy (valbuf, ((char *) regbuf) + 4 - len, len); | |
713 | else if (len <= 8) | |
714 | memcpy (valbuf, ((char *) regbuf) + 8 - len, len); | |
715 | else | |
716 | error ("bad size for return value"); | |
717 | } | |
718 | ||
719 | void | |
720 | _initialize_sh_tdep () | |
721 | { | |
722 | struct cmd_list_element *c; | |
723 | ||
724 | tm_print_insn = gdb_print_insn_sh; | |
725 | ||
726 | target_architecture_hook = sh_target_architecture_hook; | |
727 | ||
728 | add_com ("regs", class_vars, sh_show_regs, "Print all registers"); | |
729 | } |