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