1 /* Target-dependent code for Hitachi Super-H, for GDB.
2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
23 Contributed by Steve Chamberlain
29 #include "frame-base.h"
30 #include "frame-unwind.h"
31 #include "dwarf2-frame.h"
40 #include "gdb_string.h"
41 #include "gdb_assert.h"
42 #include "arch-utils.h"
43 #include "floatformat.h"
51 #include "solib-svr4.h"
55 /* registers numbers shared with the simulator */
56 #include "gdb/sim-sh.h"
58 static void (*sh_show_regs) (void);
60 #define SH_NUM_REGS 59
69 /* Flag showing that a frame has been created in the prologue code. */
72 /* Saved registers. */
73 CORE_ADDR saved_regs[SH_NUM_REGS];
78 sh_generic_register_name (int reg_nr)
80 static char *register_names[] =
82 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
83 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
84 "pc", "pr", "gbr", "vbr", "mach", "macl", "sr",
86 "fr0", "fr1", "fr2", "fr3", "fr4", "fr5", "fr6", "fr7",
87 "fr8", "fr9", "fr10", "fr11", "fr12", "fr13", "fr14", "fr15",
89 "r0b0", "r1b0", "r2b0", "r3b0", "r4b0", "r5b0", "r6b0", "r7b0",
90 "r0b1", "r1b1", "r2b1", "r3b1", "r4b1", "r5b1", "r6b1", "r7b1",
94 if (reg_nr >= (sizeof (register_names) / sizeof (*register_names)))
96 return register_names[reg_nr];
100 sh_sh_register_name (int reg_nr)
102 static char *register_names[] =
104 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
105 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
106 "pc", "pr", "gbr", "vbr", "mach", "macl", "sr",
108 "", "", "", "", "", "", "", "",
109 "", "", "", "", "", "", "", "",
111 "", "", "", "", "", "", "", "",
112 "", "", "", "", "", "", "", "",
116 if (reg_nr >= (sizeof (register_names) / sizeof (*register_names)))
118 return register_names[reg_nr];
122 sh_sh3_register_name (int reg_nr)
124 static char *register_names[] =
126 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
127 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
128 "pc", "pr", "gbr", "vbr", "mach", "macl", "sr",
130 "", "", "", "", "", "", "", "",
131 "", "", "", "", "", "", "", "",
133 "r0b0", "r1b0", "r2b0", "r3b0", "r4b0", "r5b0", "r6b0", "r7b0",
134 "r0b1", "r1b1", "r2b1", "r3b1", "r4b1", "r5b1", "r6b1", "r7b1"
138 if (reg_nr >= (sizeof (register_names) / sizeof (*register_names)))
140 return register_names[reg_nr];
144 sh_sh3e_register_name (int reg_nr)
146 static char *register_names[] =
148 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
149 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
150 "pc", "pr", "gbr", "vbr", "mach", "macl", "sr",
152 "fr0", "fr1", "fr2", "fr3", "fr4", "fr5", "fr6", "fr7",
153 "fr8", "fr9", "fr10", "fr11", "fr12", "fr13", "fr14", "fr15",
155 "r0b0", "r1b0", "r2b0", "r3b0", "r4b0", "r5b0", "r6b0", "r7b0",
156 "r0b1", "r1b1", "r2b1", "r3b1", "r4b1", "r5b1", "r6b1", "r7b1",
160 if (reg_nr >= (sizeof (register_names) / sizeof (*register_names)))
162 return register_names[reg_nr];
166 sh_sh2e_register_name (int reg_nr)
168 static char *register_names[] =
170 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
171 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
172 "pc", "pr", "gbr", "vbr", "mach", "macl", "sr",
174 "fr0", "fr1", "fr2", "fr3", "fr4", "fr5", "fr6", "fr7",
175 "fr8", "fr9", "fr10", "fr11", "fr12", "fr13", "fr14", "fr15",
177 "", "", "", "", "", "", "", "",
178 "", "", "", "", "", "", "", "",
182 if (reg_nr >= (sizeof (register_names) / sizeof (*register_names)))
184 return register_names[reg_nr];
188 sh_sh_dsp_register_name (int reg_nr)
190 static char *register_names[] =
192 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
193 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
194 "pc", "pr", "gbr", "vbr", "mach", "macl", "sr",
196 "a0g", "a0", "a1g", "a1", "m0", "m1", "x0", "x1",
197 "y0", "y1", "", "", "", "", "", "mod",
199 "rs", "re", "", "", "", "", "", "",
200 "", "", "", "", "", "", "", "",
204 if (reg_nr >= (sizeof (register_names) / sizeof (*register_names)))
206 return register_names[reg_nr];
210 sh_sh3_dsp_register_name (int reg_nr)
212 static char *register_names[] =
214 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
215 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
216 "pc", "pr", "gbr", "vbr", "mach", "macl", "sr",
218 "a0g", "a0", "a1g", "a1", "m0", "m1", "x0", "x1",
219 "y0", "y1", "", "", "", "", "", "mod",
221 "rs", "re", "", "", "", "", "", "",
222 "r0b", "r1b", "r2b", "r3b", "r4b", "r5b", "r6b", "r7b"
223 "", "", "", "", "", "", "", "",
227 if (reg_nr >= (sizeof (register_names) / sizeof (*register_names)))
229 return register_names[reg_nr];
233 sh_sh4_register_name (int reg_nr)
235 static char *register_names[] =
237 /* general registers 0-15 */
238 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
239 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
241 "pc", "pr", "gbr", "vbr", "mach", "macl", "sr",
244 /* floating point registers 25 - 40 */
245 "fr0", "fr1", "fr2", "fr3", "fr4", "fr5", "fr6", "fr7",
246 "fr8", "fr9", "fr10", "fr11", "fr12", "fr13", "fr14", "fr15",
250 "r0b0", "r1b0", "r2b0", "r3b0", "r4b0", "r5b0", "r6b0", "r7b0",
252 "r0b1", "r1b1", "r2b1", "r3b1", "r4b1", "r5b1", "r6b1", "r7b1",
253 /* double precision (pseudo) 59 - 66 */
254 "dr0", "dr2", "dr4", "dr6", "dr8", "dr10", "dr12", "dr14",
255 /* vectors (pseudo) 67 - 70 */
256 "fv0", "fv4", "fv8", "fv12",
257 /* FIXME: missing XF 71 - 86 */
258 /* FIXME: missing XD 87 - 94 */
262 if (reg_nr >= (sizeof (register_names) / sizeof (*register_names)))
264 return register_names[reg_nr];
267 static const unsigned char *
268 sh_breakpoint_from_pc (CORE_ADDR *pcptr, int *lenptr)
270 /* 0xc3c3 is trapa #c3, and it works in big and little endian modes */
271 static unsigned char breakpoint[] = {0xc3, 0xc3};
273 *lenptr = sizeof (breakpoint);
278 sh_push_dummy_code (struct gdbarch *gdbarch,
279 CORE_ADDR sp, CORE_ADDR funaddr, int using_gcc,
280 struct value **args, int nargs,
281 struct type *value_type,
282 CORE_ADDR *real_pc, CORE_ADDR *bp_addr)
284 /* Allocate space sufficient for a breakpoint. */
286 /* Store the address of that breakpoint */
288 /* sh always starts the call at the callee's entry point. */
293 /* Prologue looks like
297 sub <room_for_loca_vars>,r15
300 Actually it can be more complicated than this but that's it, basically.
303 #define GET_SOURCE_REG(x) (((x) >> 4) & 0xf)
304 #define GET_TARGET_REG(x) (((x) >> 8) & 0xf)
306 /* STS.L PR,@-r15 0100111100100010
307 r15-4-->r15, PR-->(r15) */
308 #define IS_STS(x) ((x) == 0x4f22)
310 /* MOV.L Rm,@-r15 00101111mmmm0110
311 r15-4-->r15, Rm-->(R15) */
312 #define IS_PUSH(x) (((x) & 0xff0f) == 0x2f06)
314 /* MOV r15,r14 0110111011110011
316 #define IS_MOV_SP_FP(x) ((x) == 0x6ef3)
318 /* ADD #imm,r15 01111111iiiiiiii
320 #define IS_ADD_IMM_SP(x) (((x) & 0xff00) == 0x7f00)
322 #define IS_MOV_R3(x) (((x) & 0xff00) == 0x1a00)
323 #define IS_SHLL_R3(x) ((x) == 0x4300)
325 /* ADD r3,r15 0011111100111100
327 #define IS_ADD_R3SP(x) ((x) == 0x3f3c)
329 /* FMOV.S FRm,@-Rn Rn-4-->Rn, FRm-->(Rn) 1111nnnnmmmm1011
330 FMOV DRm,@-Rn Rn-8-->Rn, DRm-->(Rn) 1111nnnnmmm01011
331 FMOV XDm,@-Rn Rn-8-->Rn, XDm-->(Rn) 1111nnnnmmm11011 */
332 /* CV, 2003-08-28: Only suitable with Rn == SP, therefore name changed to
333 make this entirely clear. */
334 /* #define IS_FMOV(x) (((x) & 0xf00f) == 0xf00b) */
335 #define IS_FPUSH(x) (((x) & 0xff0f) == 0xff0b)
337 /* MOV Rm,Rn Rm-->Rn 0110nnnnmmmm0011 4 <= m <= 7 */
338 #define IS_MOV_ARG_TO_REG(x) \
339 (((x) & 0xf00f) == 0x6003 && \
340 ((x) & 0x00f0) >= 0x0040 && \
341 ((x) & 0x00f0) <= 0x0070)
342 /* MOV.L Rm,@Rn 0010nnnnmmmm0010 n = 14, 4 <= m <= 7 */
343 #define IS_MOV_ARG_TO_IND_R14(x) \
344 (((x) & 0xff0f) == 0x2e02 && \
345 ((x) & 0x00f0) >= 0x0040 && \
346 ((x) & 0x00f0) <= 0x0070)
347 /* MOV.L Rm,@(disp*4,Rn) 00011110mmmmdddd n = 14, 4 <= m <= 7 */
348 #define IS_MOV_ARG_TO_IND_R14_WITH_DISP(x) \
349 (((x) & 0xff00) == 0x1e00 && \
350 ((x) & 0x00f0) >= 0x0040 && \
351 ((x) & 0x00f0) <= 0x0070)
353 /* MOV.W @(disp*2,PC),Rn 1001nnnndddddddd */
354 #define IS_MOVW_PCREL_TO_REG(x) (((x) & 0xf000) == 0x9000)
355 /* MOV.L @(disp*4,PC),Rn 1101nnnndddddddd */
356 #define IS_MOVL_PCREL_TO_REG(x) (((x) & 0xf000) == 0xd000)
357 /* SUB Rn,R15 00111111nnnn1000 */
358 #define IS_SUB_REG_FROM_SP(x) (((x) & 0xff0f) == 0x3f08)
360 #define FPSCR_SZ (1 << 20)
362 /* The following instructions are used for epilogue testing. */
363 #define IS_RESTORE_FP(x) ((x) == 0x6ef6)
364 #define IS_RTS(x) ((x) == 0x000b)
365 #define IS_LDS(x) ((x) == 0x4f26)
366 #define IS_MOV_FP_SP(x) ((x) == 0x6fe3)
367 #define IS_ADD_REG_TO_FP(x) (((x) & 0xff0f) == 0x3e0c)
368 #define IS_ADD_IMM_FP(x) (((x) & 0xff00) == 0x7e00)
370 /* Disassemble an instruction. */
372 gdb_print_insn_sh (bfd_vma memaddr, disassemble_info *info)
374 info->endian = TARGET_BYTE_ORDER;
375 return print_insn_sh (memaddr, info);
379 sh_analyze_prologue (CORE_ADDR pc, CORE_ADDR current_pc,
380 struct sh_frame_cache *cache)
387 int reg, sav_reg = -1;
389 if (pc >= current_pc)
393 for (opc = pc + (2 * 28); pc < opc; pc += 2)
395 inst = read_memory_unsigned_integer (pc, 2);
396 /* See where the registers will be saved to */
399 cache->saved_regs[GET_SOURCE_REG (inst)] = cache->sp_offset;
400 cache->sp_offset += 4;
402 else if (IS_STS (inst))
404 cache->saved_regs[PR_REGNUM] = cache->sp_offset;
405 cache->sp_offset += 4;
407 else if (IS_MOV_R3 (inst))
409 r3_val = ((inst & 0xff) ^ 0x80) - 0x80;
411 else if (IS_SHLL_R3 (inst))
415 else if (IS_ADD_R3SP (inst))
417 cache->sp_offset += -r3_val;
419 else if (IS_ADD_IMM_SP (inst))
421 offset = ((inst & 0xff) ^ 0x80) - 0x80;
422 cache->sp_offset -= offset;
424 else if (IS_MOVW_PCREL_TO_REG (inst))
428 reg = GET_TARGET_REG (inst);
432 offset = (((inst & 0xff) ^ 0x80) - 0x80) << 1;
434 read_memory_integer (((pc + 4) & ~3) + offset, 2);
438 else if (IS_MOVL_PCREL_TO_REG (inst))
442 reg = (inst & 0x0f00) >> 8;
446 offset = (((inst & 0xff) ^ 0x80) - 0x80) << 1;
448 read_memory_integer (((pc + 4) & ~3) + offset, 4);
452 else if (IS_SUB_REG_FROM_SP (inst))
454 reg = GET_SOURCE_REG (inst);
455 if (sav_reg > 0 && reg == sav_reg)
459 cache->sp_offset += sav_offset;
461 else if (IS_FPUSH (inst))
463 if (read_register (FPSCR_REGNUM) & FPSCR_SZ)
465 cache->sp_offset += 8;
469 cache->sp_offset += 4;
472 else if (IS_MOV_SP_FP (inst))
476 /* At this point, only allow argument register moves to other
477 registers or argument register moves to @(X,fp) which are
478 moving the register arguments onto the stack area allocated
479 by a former add somenumber to SP call. Don't allow moving
480 to an fp indirect address above fp + cache->sp_offset. */
482 for (opc = pc + 12; pc < opc; pc += 2)
484 inst = read_memory_integer (pc, 2);
485 if (IS_MOV_ARG_TO_IND_R14 (inst))
487 reg = GET_SOURCE_REG (inst);
488 if (cache->sp_offset > 0)
489 cache->saved_regs[reg] = cache->sp_offset;
491 else if (IS_MOV_ARG_TO_IND_R14_WITH_DISP (inst))
493 reg = GET_SOURCE_REG (inst);
494 offset = (inst & 0xf) * 4;
495 if (cache->sp_offset > offset)
496 cache->saved_regs[reg] = cache->sp_offset - offset;
498 else if (IS_MOV_ARG_TO_REG (inst))
505 #if 0 /* This used to just stop when it found an instruction that
506 was not considered part of the prologue. Now, we just
507 keep going looking for likely instructions. */
516 /* Skip any prologue before the guts of a function */
518 /* Skip the prologue using the debug information. If this fails we'll
519 fall back on the 'guess' method below. */
521 after_prologue (CORE_ADDR pc)
523 struct symtab_and_line sal;
524 CORE_ADDR func_addr, func_end;
526 /* If we can not find the symbol in the partial symbol table, then
527 there is no hope we can determine the function's start address
529 if (!find_pc_partial_function (pc, NULL, &func_addr, &func_end))
532 /* Get the line associated with FUNC_ADDR. */
533 sal = find_pc_line (func_addr, 0);
535 /* There are only two cases to consider. First, the end of the source line
536 is within the function bounds. In that case we return the end of the
537 source line. Second is the end of the source line extends beyond the
538 bounds of the current function. We need to use the slow code to
539 examine instructions in that case. */
540 if (sal.end < func_end)
547 sh_skip_prologue (CORE_ADDR start_pc)
550 struct sh_frame_cache cache;
552 /* See if we can determine the end of the prologue via the symbol table.
553 If so, then return either PC, or the PC after the prologue, whichever
555 pc = after_prologue (start_pc);
557 /* If after_prologue returned a useful address, then use it. Else
558 fall back on the instruction skipping code. */
560 return max (pc, start_pc);
562 cache.sp_offset = -4;
563 pc = sh_analyze_prologue (start_pc, (CORE_ADDR) -1, &cache);
570 /* Should call_function allocate stack space for a struct return? */
572 sh_use_struct_convention (int gcc_p, struct type *type)
574 int len = TYPE_LENGTH (type);
575 int nelem = TYPE_NFIELDS (type);
576 return ((len != 1 && len != 2 && len != 4 && len != 8) || nelem != 1) &&
577 (len != 8 || TYPE_LENGTH (TYPE_FIELD_TYPE (type, 0)) != 4);
580 /* Extract from an array REGBUF containing the (raw) register state
581 the address in which a function should return its structure value,
582 as a CORE_ADDR (or an expression that can be used as one). */
584 sh_extract_struct_value_address (struct regcache *regcache)
588 regcache_cooked_read_unsigned (regcache, STRUCT_RETURN_REGNUM, &addr);
593 sh_frame_align (struct gdbarch *ignore, CORE_ADDR sp)
598 /* Function: push_dummy_call (formerly push_arguments)
599 Setup the function arguments for calling a function in the inferior.
601 On the Hitachi SH architecture, there are four registers (R4 to R7)
602 which are dedicated for passing function arguments. Up to the first
603 four arguments (depending on size) may go into these registers.
604 The rest go on the stack.
606 MVS: Except on SH variants that have floating point registers.
607 In that case, float and double arguments are passed in the same
608 manner, but using FP registers instead of GP registers.
610 Arguments that are smaller than 4 bytes will still take up a whole
611 register or a whole 32-bit word on the stack, and will be
612 right-justified in the register or the stack word. This includes
613 chars, shorts, and small aggregate types.
615 Arguments that are larger than 4 bytes may be split between two or
616 more registers. If there are not enough registers free, an argument
617 may be passed partly in a register (or registers), and partly on the
618 stack. This includes doubles, long longs, and larger aggregates.
619 As far as I know, there is no upper limit to the size of aggregates
620 that will be passed in this way; in other words, the convention of
621 passing a pointer to a large aggregate instead of a copy is not used.
623 MVS: The above appears to be true for the SH variants that do not
624 have an FPU, however those that have an FPU appear to copy the
625 aggregate argument onto the stack (and not place it in registers)
626 if it is larger than 16 bytes (four GP registers).
628 An exceptional case exists for struct arguments (and possibly other
629 aggregates such as arrays) if the size is larger than 4 bytes but
630 not a multiple of 4 bytes. In this case the argument is never split
631 between the registers and the stack, but instead is copied in its
632 entirety onto the stack, AND also copied into as many registers as
633 there is room for. In other words, space in registers permitting,
634 two copies of the same argument are passed in. As far as I can tell,
635 only the one on the stack is used, although that may be a function
636 of the level of compiler optimization. I suspect this is a compiler
637 bug. Arguments of these odd sizes are left-justified within the
638 word (as opposed to arguments smaller than 4 bytes, which are
641 If the function is to return an aggregate type such as a struct, it
642 is either returned in the normal return value register R0 (if its
643 size is no greater than one byte), or else the caller must allocate
644 space into which the callee will copy the return value (if the size
645 is greater than one byte). In this case, a pointer to the return
646 value location is passed into the callee in register R2, which does
647 not displace any of the other arguments passed in via registers R4
650 /* Helper function to justify value in register according to endianess. */
652 sh_justify_value_in_reg (struct value *val, int len)
654 static char valbuf[4];
656 memset (valbuf, 0, sizeof (valbuf));
659 /* value gets right-justified in the register or stack word */
660 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
661 memcpy (valbuf + (4 - len), (char *) VALUE_CONTENTS (val), len);
663 memcpy (valbuf, (char *) VALUE_CONTENTS (val), len);
666 return (char *) VALUE_CONTENTS (val);
669 /* Helper function to eval number of bytes to allocate on stack. */
671 sh_stack_allocsize (int nargs, struct value **args)
675 stack_alloc += ((TYPE_LENGTH (VALUE_TYPE (args[nargs])) + 3) & ~3);
679 /* Helper functions for getting the float arguments right. Registers usage
680 depends on the ABI and the endianess. The comments should enlighten how
681 it's intended to work. */
683 /* This array stores which of the float arg registers are already in use. */
684 static int flt_argreg_array[FLOAT_ARGLAST_REGNUM - FLOAT_ARG0_REGNUM + 1];
686 /* This function just resets the above array to "no reg used so far". */
688 sh_init_flt_argreg (void)
690 memset (flt_argreg_array, 0, sizeof flt_argreg_array);
693 /* This function returns the next register to use for float arg passing.
694 It returns either a valid value between FLOAT_ARG0_REGNUM and
695 FLOAT_ARGLAST_REGNUM if a register is available, otherwise it returns
696 FLOAT_ARGLAST_REGNUM + 1 to indicate that no register is available.
698 Note that register number 0 in flt_argreg_array corresponds with the
699 real float register fr4. In contrast to FLOAT_ARG0_REGNUM (value is
700 29) the parity of the register number is preserved, which is important
701 for the double register passing test (see the "argreg & 1" test below). */
703 sh_next_flt_argreg (int len)
707 /* First search for the next free register. */
708 for (argreg = 0; argreg <= FLOAT_ARGLAST_REGNUM - FLOAT_ARG0_REGNUM; ++argreg)
709 if (!flt_argreg_array[argreg])
712 /* No register left? */
713 if (argreg > FLOAT_ARGLAST_REGNUM - FLOAT_ARG0_REGNUM)
714 return FLOAT_ARGLAST_REGNUM + 1;
718 /* Doubles are always starting in a even register number. */
721 flt_argreg_array[argreg] = 1;
725 /* No register left? */
726 if (argreg > FLOAT_ARGLAST_REGNUM - FLOAT_ARG0_REGNUM)
727 return FLOAT_ARGLAST_REGNUM + 1;
729 /* Also mark the next register as used. */
730 flt_argreg_array[argreg + 1] = 1;
732 else if (TARGET_BYTE_ORDER == BFD_ENDIAN_LITTLE)
734 /* In little endian, gcc passes floats like this: f5, f4, f7, f6, ... */
735 if (!flt_argreg_array[argreg + 1])
738 flt_argreg_array[argreg] = 1;
739 return FLOAT_ARG0_REGNUM + argreg;
743 sh_push_dummy_call_fpu (struct gdbarch *gdbarch,
745 struct regcache *regcache,
746 CORE_ADDR bp_addr, int nargs,
748 CORE_ADDR sp, int struct_return,
749 CORE_ADDR struct_addr)
751 int stack_offset = 0;
752 int argreg = ARG0_REGNUM;
761 /* first force sp to a 4-byte alignment */
762 sp = sh_frame_align (gdbarch, sp);
765 regcache_cooked_write_unsigned (regcache,
766 STRUCT_RETURN_REGNUM,
769 /* make room on stack for args */
770 sp -= sh_stack_allocsize (nargs, args);
772 /* Initialize float argument mechanism. */
773 sh_init_flt_argreg ();
775 /* Now load as many as possible of the first arguments into
776 registers, and push the rest onto the stack. There are 16 bytes
777 in four registers available. Loop thru args from first to last. */
778 for (argnum = 0; argnum < nargs; argnum++)
780 type = VALUE_TYPE (args[argnum]);
781 len = TYPE_LENGTH (type);
782 val = sh_justify_value_in_reg (args[argnum], len);
784 /* Some decisions have to be made how various types are handled.
785 This also differs in different ABIs. */
788 pass_on_stack = 1; /* Types bigger than 16 bytes are passed on stack. */
790 /* Find out the next register to use for a floating point value. */
791 if (TYPE_CODE (type) == TYPE_CODE_FLT)
792 flt_argreg = sh_next_flt_argreg (len);
796 if ((TYPE_CODE (type) == TYPE_CODE_FLT
797 && flt_argreg > FLOAT_ARGLAST_REGNUM)
798 || argreg > ARGLAST_REGNUM
801 /* The remainder of the data goes entirely on the stack,
803 reg_size = (len + 3) & ~3;
804 write_memory (sp + stack_offset, val, reg_size);
805 stack_offset += reg_size;
807 else if (TYPE_CODE (type) == TYPE_CODE_FLT
808 && flt_argreg <= FLOAT_ARGLAST_REGNUM)
810 /* Argument goes in a float argument register. */
811 reg_size = register_size (gdbarch, flt_argreg);
812 regval = extract_unsigned_integer (val, reg_size);
813 regcache_cooked_write_unsigned (regcache, flt_argreg++, regval);
815 else if (argreg <= ARGLAST_REGNUM)
817 /* there's room in a register */
818 reg_size = register_size (gdbarch, argreg);
819 regval = extract_unsigned_integer (val, reg_size);
820 regcache_cooked_write_unsigned (regcache, argreg++, regval);
822 /* Store the value reg_size bytes at a time. This means that things
823 larger than reg_size bytes may go partly in registers and partly
830 /* Store return address. */
831 regcache_cooked_write_unsigned (regcache, PR_REGNUM, bp_addr);
833 /* Update stack pointer. */
834 regcache_cooked_write_unsigned (regcache, SP_REGNUM, sp);
840 sh_push_dummy_call_nofpu (struct gdbarch *gdbarch,
842 struct regcache *regcache,
844 int nargs, struct value **args,
845 CORE_ADDR sp, int struct_return,
846 CORE_ADDR struct_addr)
848 int stack_offset = 0;
849 int argreg = ARG0_REGNUM;
856 /* first force sp to a 4-byte alignment */
857 sp = sh_frame_align (gdbarch, sp);
860 regcache_cooked_write_unsigned (regcache,
861 STRUCT_RETURN_REGNUM,
864 /* make room on stack for args */
865 sp -= sh_stack_allocsize (nargs, args);
867 /* Now load as many as possible of the first arguments into
868 registers, and push the rest onto the stack. There are 16 bytes
869 in four registers available. Loop thru args from first to last. */
870 for (argnum = 0; argnum < nargs; argnum++)
872 type = VALUE_TYPE (args[argnum]);
873 len = TYPE_LENGTH (type);
874 val = sh_justify_value_in_reg (args[argnum], len);
878 if (argreg > ARGLAST_REGNUM)
880 /* The remainder of the data goes entirely on the stack,
882 reg_size = (len + 3) & ~3;
883 write_memory (sp + stack_offset, val, reg_size);
884 stack_offset += reg_size;
886 else if (argreg <= ARGLAST_REGNUM)
888 /* there's room in a register */
889 reg_size = register_size (gdbarch, argreg);
890 regval = extract_unsigned_integer (val, reg_size);
891 regcache_cooked_write_unsigned (regcache, argreg++, regval);
893 /* Store the value reg_size bytes at a time. This means that things
894 larger than reg_size bytes may go partly in registers and partly
901 /* Store return address. */
902 regcache_cooked_write_unsigned (regcache, PR_REGNUM, bp_addr);
904 /* Update stack pointer. */
905 regcache_cooked_write_unsigned (regcache, SP_REGNUM, sp);
910 /* Find a function's return value in the appropriate registers (in
911 regbuf), and copy it into valbuf. Extract from an array REGBUF
912 containing the (raw) register state a function return value of type
913 TYPE, and copy that, in virtual format, into VALBUF. */
915 sh_default_extract_return_value (struct type *type, struct regcache *regcache,
918 int len = TYPE_LENGTH (type);
919 int return_register = R0_REGNUM;
926 regcache_cooked_read_unsigned (regcache, R0_REGNUM, &c);
927 store_unsigned_integer (valbuf, len, c);
931 int i, regnum = R0_REGNUM;
932 for (i = 0; i < len; i += 4)
933 regcache_raw_read (regcache, regnum++, (char *)valbuf + i);
936 error ("bad size for return value");
940 sh3e_sh4_extract_return_value (struct type *type, struct regcache *regcache,
943 if (TYPE_CODE (type) == TYPE_CODE_FLT)
945 int len = TYPE_LENGTH (type);
946 int i, regnum = FP0_REGNUM;
947 for (i = 0; i < len; i += 4)
948 regcache_raw_read (regcache, regnum++, (char *)valbuf + i);
951 sh_default_extract_return_value (type, regcache, valbuf);
954 /* Write into appropriate registers a function return value
955 of type TYPE, given in virtual format.
956 If the architecture is sh4 or sh3e, store a function's return value
957 in the R0 general register or in the FP0 floating point register,
958 depending on the type of the return value. In all the other cases
959 the result is stored in r0, left-justified. */
961 sh_default_store_return_value (struct type *type, struct regcache *regcache,
965 int len = TYPE_LENGTH (type);
969 val = extract_unsigned_integer (valbuf, len);
970 regcache_cooked_write_unsigned (regcache, R0_REGNUM, val);
974 int i, regnum = R0_REGNUM;
975 for (i = 0; i < len; i += 4)
976 regcache_raw_write (regcache, regnum++, (char *)valbuf + i);
981 sh3e_sh4_store_return_value (struct type *type, struct regcache *regcache,
984 if (TYPE_CODE (type) == TYPE_CODE_FLT)
986 int len = TYPE_LENGTH (type);
987 int i, regnum = FP0_REGNUM;
988 for (i = 0; i < len; i += 4)
989 regcache_raw_write (regcache, regnum++, (char *)valbuf + i);
992 sh_default_store_return_value (type, regcache, valbuf);
995 /* Print the registers in a form similar to the E7000 */
998 sh_generic_show_regs (void)
1000 printf_filtered ("PC=%s SR=%08lx PR=%08lx MACH=%08lx MACHL=%08lx\n",
1001 paddr (read_register (PC_REGNUM)),
1002 (long) read_register (SR_REGNUM),
1003 (long) read_register (PR_REGNUM),
1004 (long) read_register (MACH_REGNUM),
1005 (long) read_register (MACL_REGNUM));
1007 printf_filtered ("GBR=%08lx VBR=%08lx",
1008 (long) read_register (GBR_REGNUM),
1009 (long) read_register (VBR_REGNUM));
1011 printf_filtered ("\nR0-R7 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
1012 (long) read_register (0),
1013 (long) read_register (1),
1014 (long) read_register (2),
1015 (long) read_register (3),
1016 (long) read_register (4),
1017 (long) read_register (5),
1018 (long) read_register (6),
1019 (long) read_register (7));
1020 printf_filtered ("R8-R15 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
1021 (long) read_register (8),
1022 (long) read_register (9),
1023 (long) read_register (10),
1024 (long) read_register (11),
1025 (long) read_register (12),
1026 (long) read_register (13),
1027 (long) read_register (14),
1028 (long) read_register (15));
1032 sh3_show_regs (void)
1034 printf_filtered ("PC=%s SR=%08lx PR=%08lx MACH=%08lx MACHL=%08lx\n",
1035 paddr (read_register (PC_REGNUM)),
1036 (long) read_register (SR_REGNUM),
1037 (long) read_register (PR_REGNUM),
1038 (long) read_register (MACH_REGNUM),
1039 (long) read_register (MACL_REGNUM));
1041 printf_filtered ("GBR=%08lx VBR=%08lx",
1042 (long) read_register (GBR_REGNUM),
1043 (long) read_register (VBR_REGNUM));
1044 printf_filtered (" SSR=%08lx SPC=%08lx",
1045 (long) read_register (SSR_REGNUM),
1046 (long) read_register (SPC_REGNUM));
1048 printf_filtered ("\nR0-R7 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
1049 (long) read_register (0),
1050 (long) read_register (1),
1051 (long) read_register (2),
1052 (long) read_register (3),
1053 (long) read_register (4),
1054 (long) read_register (5),
1055 (long) read_register (6),
1056 (long) read_register (7));
1057 printf_filtered ("R8-R15 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
1058 (long) read_register (8),
1059 (long) read_register (9),
1060 (long) read_register (10),
1061 (long) read_register (11),
1062 (long) read_register (12),
1063 (long) read_register (13),
1064 (long) read_register (14),
1065 (long) read_register (15));
1070 sh2e_show_regs (void)
1072 printf_filtered ("PC=%s SR=%08lx PR=%08lx MACH=%08lx MACHL=%08lx\n",
1073 paddr (read_register (PC_REGNUM)),
1074 (long) read_register (SR_REGNUM),
1075 (long) read_register (PR_REGNUM),
1076 (long) read_register (MACH_REGNUM),
1077 (long) read_register (MACL_REGNUM));
1079 printf_filtered ("GBR=%08lx VBR=%08lx",
1080 (long) read_register (GBR_REGNUM),
1081 (long) read_register (VBR_REGNUM));
1082 printf_filtered (" FPUL=%08lx FPSCR=%08lx",
1083 (long) read_register (FPUL_REGNUM),
1084 (long) read_register (FPSCR_REGNUM));
1086 printf_filtered ("\nR0-R7 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
1087 (long) read_register (0),
1088 (long) read_register (1),
1089 (long) read_register (2),
1090 (long) read_register (3),
1091 (long) read_register (4),
1092 (long) read_register (5),
1093 (long) read_register (6),
1094 (long) read_register (7));
1095 printf_filtered ("R8-R15 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
1096 (long) read_register (8),
1097 (long) read_register (9),
1098 (long) read_register (10),
1099 (long) read_register (11),
1100 (long) read_register (12),
1101 (long) read_register (13),
1102 (long) read_register (14),
1103 (long) read_register (15));
1105 printf_filtered (("FP0-FP7 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n"),
1106 (long) read_register (FP0_REGNUM + 0),
1107 (long) read_register (FP0_REGNUM + 1),
1108 (long) read_register (FP0_REGNUM + 2),
1109 (long) read_register (FP0_REGNUM + 3),
1110 (long) read_register (FP0_REGNUM + 4),
1111 (long) read_register (FP0_REGNUM + 5),
1112 (long) read_register (FP0_REGNUM + 6),
1113 (long) read_register (FP0_REGNUM + 7));
1114 printf_filtered (("FP8-FP15 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n"),
1115 (long) read_register (FP0_REGNUM + 8),
1116 (long) read_register (FP0_REGNUM + 9),
1117 (long) read_register (FP0_REGNUM + 10),
1118 (long) read_register (FP0_REGNUM + 11),
1119 (long) read_register (FP0_REGNUM + 12),
1120 (long) read_register (FP0_REGNUM + 13),
1121 (long) read_register (FP0_REGNUM + 14),
1122 (long) read_register (FP0_REGNUM + 15));
1126 sh3e_show_regs (void)
1128 printf_filtered ("PC=%s SR=%08lx PR=%08lx MACH=%08lx MACHL=%08lx\n",
1129 paddr (read_register (PC_REGNUM)),
1130 (long) read_register (SR_REGNUM),
1131 (long) read_register (PR_REGNUM),
1132 (long) read_register (MACH_REGNUM),
1133 (long) read_register (MACL_REGNUM));
1135 printf_filtered ("GBR=%08lx VBR=%08lx",
1136 (long) read_register (GBR_REGNUM),
1137 (long) read_register (VBR_REGNUM));
1138 printf_filtered (" SSR=%08lx SPC=%08lx",
1139 (long) read_register (SSR_REGNUM),
1140 (long) read_register (SPC_REGNUM));
1141 printf_filtered (" FPUL=%08lx FPSCR=%08lx",
1142 (long) read_register (FPUL_REGNUM),
1143 (long) read_register (FPSCR_REGNUM));
1145 printf_filtered ("\nR0-R7 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
1146 (long) read_register (0),
1147 (long) read_register (1),
1148 (long) read_register (2),
1149 (long) read_register (3),
1150 (long) read_register (4),
1151 (long) read_register (5),
1152 (long) read_register (6),
1153 (long) read_register (7));
1154 printf_filtered ("R8-R15 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
1155 (long) read_register (8),
1156 (long) read_register (9),
1157 (long) read_register (10),
1158 (long) read_register (11),
1159 (long) read_register (12),
1160 (long) read_register (13),
1161 (long) read_register (14),
1162 (long) read_register (15));
1164 printf_filtered (("FP0-FP7 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n"),
1165 (long) read_register (FP0_REGNUM + 0),
1166 (long) read_register (FP0_REGNUM + 1),
1167 (long) read_register (FP0_REGNUM + 2),
1168 (long) read_register (FP0_REGNUM + 3),
1169 (long) read_register (FP0_REGNUM + 4),
1170 (long) read_register (FP0_REGNUM + 5),
1171 (long) read_register (FP0_REGNUM + 6),
1172 (long) read_register (FP0_REGNUM + 7));
1173 printf_filtered (("FP8-FP15 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n"),
1174 (long) read_register (FP0_REGNUM + 8),
1175 (long) read_register (FP0_REGNUM + 9),
1176 (long) read_register (FP0_REGNUM + 10),
1177 (long) read_register (FP0_REGNUM + 11),
1178 (long) read_register (FP0_REGNUM + 12),
1179 (long) read_register (FP0_REGNUM + 13),
1180 (long) read_register (FP0_REGNUM + 14),
1181 (long) read_register (FP0_REGNUM + 15));
1185 sh3_dsp_show_regs (void)
1187 printf_filtered ("PC=%s SR=%08lx PR=%08lx MACH=%08lx MACHL=%08lx\n",
1188 paddr (read_register (PC_REGNUM)),
1189 (long) read_register (SR_REGNUM),
1190 (long) read_register (PR_REGNUM),
1191 (long) read_register (MACH_REGNUM),
1192 (long) read_register (MACL_REGNUM));
1194 printf_filtered ("GBR=%08lx VBR=%08lx",
1195 (long) read_register (GBR_REGNUM),
1196 (long) read_register (VBR_REGNUM));
1198 printf_filtered (" SSR=%08lx SPC=%08lx",
1199 (long) read_register (SSR_REGNUM),
1200 (long) read_register (SPC_REGNUM));
1202 printf_filtered (" DSR=%08lx",
1203 (long) read_register (DSR_REGNUM));
1205 printf_filtered ("\nR0-R7 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
1206 (long) read_register (0),
1207 (long) read_register (1),
1208 (long) read_register (2),
1209 (long) read_register (3),
1210 (long) read_register (4),
1211 (long) read_register (5),
1212 (long) read_register (6),
1213 (long) read_register (7));
1214 printf_filtered ("R8-R15 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
1215 (long) read_register (8),
1216 (long) read_register (9),
1217 (long) read_register (10),
1218 (long) read_register (11),
1219 (long) read_register (12),
1220 (long) read_register (13),
1221 (long) read_register (14),
1222 (long) read_register (15));
1224 printf_filtered ("A0G=%02lx A0=%08lx M0=%08lx X0=%08lx Y0=%08lx RS=%08lx MOD=%08lx\n",
1225 (long) read_register (A0G_REGNUM) & 0xff,
1226 (long) read_register (A0_REGNUM),
1227 (long) read_register (M0_REGNUM),
1228 (long) read_register (X0_REGNUM),
1229 (long) read_register (Y0_REGNUM),
1230 (long) read_register (RS_REGNUM),
1231 (long) read_register (MOD_REGNUM));
1232 printf_filtered ("A1G=%02lx A1=%08lx M1=%08lx X1=%08lx Y1=%08lx RE=%08lx\n",
1233 (long) read_register (A1G_REGNUM) & 0xff,
1234 (long) read_register (A1_REGNUM),
1235 (long) read_register (M1_REGNUM),
1236 (long) read_register (X1_REGNUM),
1237 (long) read_register (Y1_REGNUM),
1238 (long) read_register (RE_REGNUM));
1242 sh4_show_regs (void)
1244 int pr = read_register (FPSCR_REGNUM) & 0x80000;
1245 printf_filtered ("PC=%s SR=%08lx PR=%08lx MACH=%08lx MACHL=%08lx\n",
1246 paddr (read_register (PC_REGNUM)),
1247 (long) read_register (SR_REGNUM),
1248 (long) read_register (PR_REGNUM),
1249 (long) read_register (MACH_REGNUM),
1250 (long) read_register (MACL_REGNUM));
1252 printf_filtered ("GBR=%08lx VBR=%08lx",
1253 (long) read_register (GBR_REGNUM),
1254 (long) read_register (VBR_REGNUM));
1255 printf_filtered (" SSR=%08lx SPC=%08lx",
1256 (long) read_register (SSR_REGNUM),
1257 (long) read_register (SPC_REGNUM));
1258 printf_filtered (" FPUL=%08lx FPSCR=%08lx",
1259 (long) read_register (FPUL_REGNUM),
1260 (long) read_register (FPSCR_REGNUM));
1262 printf_filtered ("\nR0-R7 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
1263 (long) read_register (0),
1264 (long) read_register (1),
1265 (long) read_register (2),
1266 (long) read_register (3),
1267 (long) read_register (4),
1268 (long) read_register (5),
1269 (long) read_register (6),
1270 (long) read_register (7));
1271 printf_filtered ("R8-R15 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
1272 (long) read_register (8),
1273 (long) read_register (9),
1274 (long) read_register (10),
1275 (long) read_register (11),
1276 (long) read_register (12),
1277 (long) read_register (13),
1278 (long) read_register (14),
1279 (long) read_register (15));
1281 printf_filtered ((pr
1282 ? "DR0-DR6 %08lx%08lx %08lx%08lx %08lx%08lx %08lx%08lx\n"
1283 : "FP0-FP7 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n"),
1284 (long) read_register (FP0_REGNUM + 0),
1285 (long) read_register (FP0_REGNUM + 1),
1286 (long) read_register (FP0_REGNUM + 2),
1287 (long) read_register (FP0_REGNUM + 3),
1288 (long) read_register (FP0_REGNUM + 4),
1289 (long) read_register (FP0_REGNUM + 5),
1290 (long) read_register (FP0_REGNUM + 6),
1291 (long) read_register (FP0_REGNUM + 7));
1292 printf_filtered ((pr
1293 ? "DR8-DR14 %08lx%08lx %08lx%08lx %08lx%08lx %08lx%08lx\n"
1294 : "FP8-FP15 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n"),
1295 (long) read_register (FP0_REGNUM + 8),
1296 (long) read_register (FP0_REGNUM + 9),
1297 (long) read_register (FP0_REGNUM + 10),
1298 (long) read_register (FP0_REGNUM + 11),
1299 (long) read_register (FP0_REGNUM + 12),
1300 (long) read_register (FP0_REGNUM + 13),
1301 (long) read_register (FP0_REGNUM + 14),
1302 (long) read_register (FP0_REGNUM + 15));
1306 sh_dsp_show_regs (void)
1308 printf_filtered ("PC=%s SR=%08lx PR=%08lx MACH=%08lx MACHL=%08lx\n",
1309 paddr (read_register (PC_REGNUM)),
1310 (long) read_register (SR_REGNUM),
1311 (long) read_register (PR_REGNUM),
1312 (long) read_register (MACH_REGNUM),
1313 (long) read_register (MACL_REGNUM));
1315 printf_filtered ("GBR=%08lx VBR=%08lx",
1316 (long) read_register (GBR_REGNUM),
1317 (long) read_register (VBR_REGNUM));
1319 printf_filtered (" DSR=%08lx",
1320 (long) read_register (DSR_REGNUM));
1322 printf_filtered ("\nR0-R7 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
1323 (long) read_register (0),
1324 (long) read_register (1),
1325 (long) read_register (2),
1326 (long) read_register (3),
1327 (long) read_register (4),
1328 (long) read_register (5),
1329 (long) read_register (6),
1330 (long) read_register (7));
1331 printf_filtered ("R8-R15 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
1332 (long) read_register (8),
1333 (long) read_register (9),
1334 (long) read_register (10),
1335 (long) read_register (11),
1336 (long) read_register (12),
1337 (long) read_register (13),
1338 (long) read_register (14),
1339 (long) read_register (15));
1341 printf_filtered ("A0G=%02lx A0=%08lx M0=%08lx X0=%08lx Y0=%08lx RS=%08lx MOD=%08lx\n",
1342 (long) read_register (A0G_REGNUM) & 0xff,
1343 (long) read_register (A0_REGNUM),
1344 (long) read_register (M0_REGNUM),
1345 (long) read_register (X0_REGNUM),
1346 (long) read_register (Y0_REGNUM),
1347 (long) read_register (RS_REGNUM),
1348 (long) read_register (MOD_REGNUM));
1349 printf_filtered ("A1G=%02lx A1=%08lx M1=%08lx X1=%08lx Y1=%08lx RE=%08lx\n",
1350 (long) read_register (A1G_REGNUM) & 0xff,
1351 (long) read_register (A1_REGNUM),
1352 (long) read_register (M1_REGNUM),
1353 (long) read_register (X1_REGNUM),
1354 (long) read_register (Y1_REGNUM),
1355 (long) read_register (RE_REGNUM));
1359 sh_show_regs_command (char *args, int from_tty)
1365 /* Return the GDB type object for the "standard" data type
1366 of data in register N. */
1367 static struct type *
1368 sh_sh3e_register_type (struct gdbarch *gdbarch, int reg_nr)
1370 if ((reg_nr >= FP0_REGNUM
1371 && (reg_nr <= FP_LAST_REGNUM))
1372 || (reg_nr == FPUL_REGNUM))
1373 return builtin_type_float;
1375 return builtin_type_int;
1378 static struct type *
1379 sh_sh4_build_float_register_type (int high)
1383 temp = create_range_type (NULL, builtin_type_int, 0, high);
1384 return create_array_type (NULL, builtin_type_float, temp);
1387 static struct type *
1388 sh_sh4_register_type (struct gdbarch *gdbarch, int reg_nr)
1390 if ((reg_nr >= FP0_REGNUM
1391 && (reg_nr <= FP_LAST_REGNUM))
1392 || (reg_nr == FPUL_REGNUM))
1393 return builtin_type_float;
1394 else if (reg_nr >= DR0_REGNUM
1395 && reg_nr <= DR_LAST_REGNUM)
1396 return builtin_type_double;
1397 else if (reg_nr >= FV0_REGNUM
1398 && reg_nr <= FV_LAST_REGNUM)
1399 return sh_sh4_build_float_register_type (3);
1401 return builtin_type_int;
1404 static struct type *
1405 sh_default_register_type (struct gdbarch *gdbarch, int reg_nr)
1407 return builtin_type_int;
1410 /* On the sh4, the DRi pseudo registers are problematic if the target
1411 is little endian. When the user writes one of those registers, for
1412 instance with 'ser var $dr0=1', we want the double to be stored
1414 fr0 = 0x00 0x00 0x00 0x00 0x00 0xf0 0x3f
1415 fr1 = 0x00 0x00 0x00 0x00 0x00 0x00 0x00
1417 This corresponds to little endian byte order & big endian word
1418 order. However if we let gdb write the register w/o conversion, it
1419 will write fr0 and fr1 this way:
1420 fr0 = 0x00 0x00 0x00 0x00 0x00 0x00 0x00
1421 fr1 = 0x00 0x00 0x00 0x00 0x00 0xf0 0x3f
1422 because it will consider fr0 and fr1 as a single LE stretch of memory.
1424 To achieve what we want we must force gdb to store things in
1425 floatformat_ieee_double_littlebyte_bigword (which is defined in
1426 include/floatformat.h and libiberty/floatformat.c.
1428 In case the target is big endian, there is no problem, the
1429 raw bytes will look like:
1430 fr0 = 0x3f 0xf0 0x00 0x00 0x00 0x00 0x00
1431 fr1 = 0x00 0x00 0x00 0x00 0x00 0x00 0x00
1433 The other pseudo registers (the FVs) also don't pose a problem
1434 because they are stored as 4 individual FP elements. */
1437 sh_sh4_register_convert_to_virtual (int regnum, struct type *type,
1438 char *from, char *to)
1440 if (regnum >= DR0_REGNUM
1441 && regnum <= DR_LAST_REGNUM)
1444 floatformat_to_doublest (&floatformat_ieee_double_littlebyte_bigword, from, &val);
1445 store_typed_floating (to, type, val);
1448 error ("sh_register_convert_to_virtual called with non DR register number");
1452 sh_sh4_register_convert_to_raw (struct type *type, int regnum,
1453 const void *from, void *to)
1455 if (regnum >= DR0_REGNUM
1456 && regnum <= DR_LAST_REGNUM)
1458 DOUBLEST val = extract_typed_floating (from, type);
1459 floatformat_from_doublest (&floatformat_ieee_double_littlebyte_bigword, &val, to);
1462 error("sh_register_convert_to_raw called with non DR register number");
1465 /* For vectors of 4 floating point registers. */
1467 fv_reg_base_num (int fv_regnum)
1471 fp_regnum = FP0_REGNUM +
1472 (fv_regnum - FV0_REGNUM) * 4;
1476 /* For double precision floating point registers, i.e 2 fp regs.*/
1478 dr_reg_base_num (int dr_regnum)
1482 fp_regnum = FP0_REGNUM +
1483 (dr_regnum - DR0_REGNUM) * 2;
1488 sh_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache,
1489 int reg_nr, void *buffer)
1491 int base_regnum, portion;
1492 char temp_buffer[MAX_REGISTER_SIZE];
1494 if (reg_nr >= DR0_REGNUM
1495 && reg_nr <= DR_LAST_REGNUM)
1497 base_regnum = dr_reg_base_num (reg_nr);
1499 /* Build the value in the provided buffer. */
1500 /* Read the real regs for which this one is an alias. */
1501 for (portion = 0; portion < 2; portion++)
1502 regcache_raw_read (regcache, base_regnum + portion,
1504 + register_size (gdbarch, base_regnum) * portion));
1505 /* We must pay attention to the endiannes. */
1506 sh_sh4_register_convert_to_virtual (reg_nr,
1507 gdbarch_register_type (gdbarch, reg_nr),
1508 temp_buffer, buffer);
1510 else if (reg_nr >= FV0_REGNUM
1511 && reg_nr <= FV_LAST_REGNUM)
1513 base_regnum = fv_reg_base_num (reg_nr);
1515 /* Read the real regs for which this one is an alias. */
1516 for (portion = 0; portion < 4; portion++)
1517 regcache_raw_read (regcache, base_regnum + portion,
1519 + register_size (gdbarch, base_regnum) * portion));
1524 sh_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
1525 int reg_nr, const void *buffer)
1527 int base_regnum, portion;
1528 char temp_buffer[MAX_REGISTER_SIZE];
1530 if (reg_nr >= DR0_REGNUM
1531 && reg_nr <= DR_LAST_REGNUM)
1533 base_regnum = dr_reg_base_num (reg_nr);
1535 /* We must pay attention to the endiannes. */
1536 sh_sh4_register_convert_to_raw (gdbarch_register_type (gdbarch, reg_nr), reg_nr,
1537 buffer, temp_buffer);
1539 /* Write the real regs for which this one is an alias. */
1540 for (portion = 0; portion < 2; portion++)
1541 regcache_raw_write (regcache, base_regnum + portion,
1543 + register_size (gdbarch, base_regnum) * portion));
1545 else if (reg_nr >= FV0_REGNUM
1546 && reg_nr <= FV_LAST_REGNUM)
1548 base_regnum = fv_reg_base_num (reg_nr);
1550 /* Write the real regs for which this one is an alias. */
1551 for (portion = 0; portion < 4; portion++)
1552 regcache_raw_write (regcache, base_regnum + portion,
1554 + register_size (gdbarch, base_regnum) * portion));
1558 /* Floating point vector of 4 float registers. */
1560 do_fv_register_info (struct gdbarch *gdbarch, struct ui_file *file,
1563 int first_fp_reg_num = fv_reg_base_num (fv_regnum);
1564 fprintf_filtered (file, "fv%d\t0x%08x\t0x%08x\t0x%08x\t0x%08x\n",
1565 fv_regnum - FV0_REGNUM,
1566 (int) read_register (first_fp_reg_num),
1567 (int) read_register (first_fp_reg_num + 1),
1568 (int) read_register (first_fp_reg_num + 2),
1569 (int) read_register (first_fp_reg_num + 3));
1572 /* Double precision registers. */
1574 do_dr_register_info (struct gdbarch *gdbarch, struct ui_file *file,
1577 int first_fp_reg_num = dr_reg_base_num (dr_regnum);
1579 fprintf_filtered (file, "dr%d\t0x%08x%08x\n",
1580 dr_regnum - DR0_REGNUM,
1581 (int) read_register (first_fp_reg_num),
1582 (int) read_register (first_fp_reg_num + 1));
1586 sh_print_pseudo_register (struct gdbarch *gdbarch, struct ui_file *file,
1589 if (regnum < NUM_REGS || regnum >= NUM_REGS + NUM_PSEUDO_REGS)
1590 internal_error (__FILE__, __LINE__,
1591 "Invalid pseudo register number %d\n", regnum);
1592 else if (regnum >= DR0_REGNUM
1593 && regnum <= DR_LAST_REGNUM)
1594 do_dr_register_info (gdbarch, file, regnum);
1595 else if (regnum >= FV0_REGNUM
1596 && regnum <= FV_LAST_REGNUM)
1597 do_fv_register_info (gdbarch, file, regnum);
1601 sh_do_fp_register (struct gdbarch *gdbarch, struct ui_file *file, int regnum)
1602 { /* do values for FP (float) regs */
1604 double flt; /* double extracted from raw hex data */
1608 /* Allocate space for the float. */
1609 raw_buffer = (char *) alloca (register_size (gdbarch, FP0_REGNUM));
1611 /* Get the data in raw format. */
1612 if (!frame_register_read (get_selected_frame (), regnum, raw_buffer))
1613 error ("can't read register %d (%s)", regnum, REGISTER_NAME (regnum));
1615 /* Get the register as a number */
1616 flt = unpack_double (builtin_type_float, raw_buffer, &inv);
1618 /* Print the name and some spaces. */
1619 fputs_filtered (REGISTER_NAME (regnum), file);
1620 print_spaces_filtered (15 - strlen (REGISTER_NAME (regnum)), file);
1622 /* Print the value. */
1624 fprintf_filtered (file, "<invalid float>");
1626 fprintf_filtered (file, "%-10.9g", flt);
1628 /* Print the fp register as hex. */
1629 fprintf_filtered (file, "\t(raw 0x");
1630 for (j = 0; j < register_size (gdbarch, regnum); j++)
1632 register int idx = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? j
1633 : register_size (gdbarch, regnum) - 1 - j;
1634 fprintf_filtered (file, "%02x", (unsigned char) raw_buffer[idx]);
1636 fprintf_filtered (file, ")");
1637 fprintf_filtered (file, "\n");
1641 sh_do_register (struct gdbarch *gdbarch, struct ui_file *file, int regnum)
1643 char raw_buffer[MAX_REGISTER_SIZE];
1645 fputs_filtered (REGISTER_NAME (regnum), file);
1646 print_spaces_filtered (15 - strlen (REGISTER_NAME (regnum)), file);
1648 /* Get the data in raw format. */
1649 if (!frame_register_read (get_selected_frame (), regnum, raw_buffer))
1650 fprintf_filtered (file, "*value not available*\n");
1652 val_print (gdbarch_register_type (gdbarch, regnum), raw_buffer, 0, 0,
1653 file, 'x', 1, 0, Val_pretty_default);
1654 fprintf_filtered (file, "\t");
1655 val_print (gdbarch_register_type (gdbarch, regnum), raw_buffer, 0, 0,
1656 file, 0, 1, 0, Val_pretty_default);
1657 fprintf_filtered (file, "\n");
1661 sh_print_register (struct gdbarch *gdbarch, struct ui_file *file, int regnum)
1663 if (regnum < 0 || regnum >= NUM_REGS + NUM_PSEUDO_REGS)
1664 internal_error (__FILE__, __LINE__,
1665 "Invalid register number %d\n", regnum);
1667 else if (regnum >= 0 && regnum < NUM_REGS)
1669 if (TYPE_CODE (gdbarch_register_type (gdbarch, regnum)) == TYPE_CODE_FLT)
1670 sh_do_fp_register (gdbarch, file, regnum); /* FP regs */
1672 sh_do_register (gdbarch, file, regnum); /* All other regs */
1675 else if (regnum < NUM_REGS + NUM_PSEUDO_REGS)
1677 sh_print_pseudo_register (gdbarch, file, regnum);
1682 sh_print_registers_info (struct gdbarch *gdbarch, struct ui_file *file,
1683 struct frame_info *frame, int regnum, int fpregs)
1685 if (regnum != -1) /* do one specified register */
1687 if (*(REGISTER_NAME (regnum)) == '\0')
1688 error ("Not a valid register for the current processor type");
1690 sh_print_register (gdbarch, file, regnum);
1693 /* do all (or most) registers */
1696 while (regnum < NUM_REGS)
1698 /* If the register name is empty, it is undefined for this
1699 processor, so don't display anything. */
1700 if (REGISTER_NAME (regnum) == NULL
1701 || *(REGISTER_NAME (regnum)) == '\0')
1707 if (TYPE_CODE (gdbarch_register_type (gdbarch, regnum)) == TYPE_CODE_FLT)
1711 /* true for "INFO ALL-REGISTERS" command */
1712 sh_do_fp_register (gdbarch, file, regnum); /* FP regs */
1716 regnum += (FP_LAST_REGNUM - FP0_REGNUM); /* skip FP regs */
1720 sh_do_register (gdbarch, file, regnum); /* All other regs */
1726 while (regnum < NUM_REGS + NUM_PSEUDO_REGS)
1728 sh_print_pseudo_register (gdbarch, file, regnum);
1734 #ifdef SVR4_SHARED_LIBS
1736 /* Fetch (and possibly build) an appropriate link_map_offsets structure
1737 for native i386 linux targets using the struct offsets defined in
1738 link.h (but without actual reference to that file).
1740 This makes it possible to access i386-linux shared libraries from
1741 a gdb that was not built on an i386-linux host (for cross debugging).
1744 struct link_map_offsets *
1745 sh_linux_svr4_fetch_link_map_offsets (void)
1747 static struct link_map_offsets lmo;
1748 static struct link_map_offsets *lmp = 0;
1754 lmo.r_debug_size = 8; /* 20 not actual size but all we need */
1756 lmo.r_map_offset = 4;
1759 lmo.link_map_size = 20; /* 552 not actual size but all we need */
1761 lmo.l_addr_offset = 0;
1762 lmo.l_addr_size = 4;
1764 lmo.l_name_offset = 4;
1765 lmo.l_name_size = 4;
1767 lmo.l_next_offset = 12;
1768 lmo.l_next_size = 4;
1770 lmo.l_prev_offset = 16;
1771 lmo.l_prev_size = 4;
1776 #endif /* SVR4_SHARED_LIBS */
1779 sh_dsp_register_sim_regno (int nr)
1781 if (legacy_register_sim_regno (nr) < 0)
1782 return legacy_register_sim_regno (nr);
1783 if (nr >= DSR_REGNUM && nr <= Y1_REGNUM)
1784 return nr - DSR_REGNUM + SIM_SH_DSR_REGNUM;
1785 if (nr == MOD_REGNUM)
1786 return SIM_SH_MOD_REGNUM;
1787 if (nr == RS_REGNUM)
1788 return SIM_SH_RS_REGNUM;
1789 if (nr == RE_REGNUM)
1790 return SIM_SH_RE_REGNUM;
1791 if (nr >= R0_BANK_REGNUM && nr <= R7_BANK_REGNUM)
1792 return nr - R0_BANK_REGNUM + SIM_SH_R0_BANK_REGNUM;
1796 static struct sh_frame_cache *
1797 sh_alloc_frame_cache (void)
1799 struct sh_frame_cache *cache;
1802 cache = FRAME_OBSTACK_ZALLOC (struct sh_frame_cache);
1806 cache->saved_sp = 0;
1807 cache->sp_offset = 0;
1810 /* Frameless until proven otherwise. */
1813 /* Saved registers. We initialize these to -1 since zero is a valid
1814 offset (that's where fp is supposed to be stored). */
1815 for (i = 0; i < SH_NUM_REGS; i++)
1817 cache->saved_regs[i] = -1;
1823 static struct sh_frame_cache *
1824 sh_frame_cache (struct frame_info *next_frame, void **this_cache)
1826 struct sh_frame_cache *cache;
1827 CORE_ADDR current_pc;
1833 cache = sh_alloc_frame_cache ();
1834 *this_cache = cache;
1836 /* In principle, for normal frames, fp holds the frame pointer,
1837 which holds the base address for the current stack frame.
1838 However, for functions that don't need it, the frame pointer is
1839 optional. For these "frameless" functions the frame pointer is
1840 actually the frame pointer of the calling frame. */
1841 cache->base = frame_unwind_register_unsigned (next_frame, FP_REGNUM);
1842 if (cache->base == 0)
1845 cache->pc = frame_func_unwind (next_frame);
1846 current_pc = frame_pc_unwind (next_frame);
1848 sh_analyze_prologue (cache->pc, current_pc, cache);
1850 if (!cache->uses_fp)
1852 /* We didn't find a valid frame, which means that CACHE->base
1853 currently holds the frame pointer for our calling frame. If
1854 we're at the start of a function, or somewhere half-way its
1855 prologue, the function's frame probably hasn't been fully
1856 setup yet. Try to reconstruct the base address for the stack
1857 frame by looking at the stack pointer. For truly "frameless"
1858 functions this might work too. */
1859 cache->base = frame_unwind_register_unsigned (next_frame, SP_REGNUM);
1862 /* Now that we have the base address for the stack frame we can
1863 calculate the value of sp in the calling frame. */
1864 cache->saved_sp = cache->base + cache->sp_offset;
1866 /* Adjust all the saved registers such that they contain addresses
1867 instead of offsets. */
1868 for (i = 0; i < SH_NUM_REGS; i++)
1869 if (cache->saved_regs[i] != -1)
1870 cache->saved_regs[i] = cache->saved_sp - cache->saved_regs[i] - 4;
1876 sh_frame_prev_register (struct frame_info *next_frame, void **this_cache,
1877 int regnum, int *optimizedp,
1878 enum lval_type *lvalp, CORE_ADDR *addrp,
1879 int *realnump, void *valuep)
1881 struct sh_frame_cache *cache = sh_frame_cache (next_frame, this_cache);
1883 gdb_assert (regnum >= 0);
1885 if (regnum == SP_REGNUM && cache->saved_sp)
1893 /* Store the value. */
1894 store_unsigned_integer (valuep, 4, cache->saved_sp);
1899 /* The PC of the previous frame is stored in the PR register of
1900 the current frame. Frob regnum so that we pull the value from
1901 the correct place. */
1902 if (regnum == PC_REGNUM)
1905 if (regnum < SH_NUM_REGS && cache->saved_regs[regnum] != -1)
1908 *lvalp = lval_memory;
1909 *addrp = cache->saved_regs[regnum];
1913 /* Read the value in from memory. */
1914 read_memory (*addrp, valuep,
1915 register_size (current_gdbarch, regnum));
1920 frame_register_unwind (next_frame, regnum,
1921 optimizedp, lvalp, addrp, realnump, valuep);
1925 sh_frame_this_id (struct frame_info *next_frame, void **this_cache,
1926 struct frame_id *this_id)
1928 struct sh_frame_cache *cache = sh_frame_cache (next_frame, this_cache);
1930 /* This marks the outermost frame. */
1931 if (cache->base == 0)
1934 *this_id = frame_id_build (cache->saved_sp, cache->pc);
1937 static const struct frame_unwind sh_frame_unwind =
1941 sh_frame_prev_register
1944 static const struct frame_unwind *
1945 sh_frame_sniffer (struct frame_info *next_frame)
1947 return &sh_frame_unwind;
1951 sh_unwind_sp (struct gdbarch *gdbarch, struct frame_info *next_frame)
1953 return frame_unwind_register_unsigned (next_frame, SP_REGNUM);
1957 sh_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
1959 return frame_unwind_register_unsigned (next_frame, PC_REGNUM);
1962 static struct frame_id
1963 sh_unwind_dummy_id (struct gdbarch *gdbarch, struct frame_info *next_frame)
1965 return frame_id_build (sh_unwind_sp (gdbarch, next_frame),
1966 frame_pc_unwind (next_frame));
1970 sh_frame_base_address (struct frame_info *next_frame, void **this_cache)
1972 struct sh_frame_cache *cache = sh_frame_cache (next_frame, this_cache);
1977 static const struct frame_base sh_frame_base =
1980 sh_frame_base_address,
1981 sh_frame_base_address,
1982 sh_frame_base_address
1985 /* The epilogue is defined here as the area at the end of a function,
1986 either on the `ret' instruction itself or after an instruction which
1987 destroys the function's stack frame. */
1989 sh_in_function_epilogue_p (struct gdbarch *gdbarch, CORE_ADDR pc)
1991 CORE_ADDR func_addr = 0, func_end = 0;
1993 if (find_pc_partial_function (pc, NULL, &func_addr, &func_end))
1996 /* The sh epilogue is max. 14 bytes long. Give another 14 bytes
1997 for a nop and some fixed data (e.g. big offsets) which are
1998 unfortunately also treated as part of the function (which
1999 means, they are below func_end. */
2000 CORE_ADDR addr = func_end - 28;
2001 if (addr < func_addr + 4)
2002 addr = func_addr + 4;
2006 /* First search forward until hitting an rts. */
2007 while (addr < func_end
2008 && !IS_RTS (read_memory_unsigned_integer (addr, 2)))
2010 if (addr >= func_end)
2013 /* At this point we should find a mov.l @r15+,r14 instruction,
2014 either before or after the rts. If not, then the function has
2015 probably no "normal" epilogue and we bail out here. */
2016 inst = read_memory_unsigned_integer (addr - 2, 2);
2017 if (IS_RESTORE_FP (read_memory_unsigned_integer (addr - 2, 2)))
2019 else if (!IS_RESTORE_FP (read_memory_unsigned_integer (addr + 2, 2)))
2022 /* Step over possible lds.l @r15+,pr. */
2023 inst = read_memory_unsigned_integer (addr - 2, 2);
2027 inst = read_memory_unsigned_integer (addr - 2, 2);
2030 /* Step over possible mov r14,r15. */
2031 if (IS_MOV_FP_SP (inst))
2034 inst = read_memory_unsigned_integer (addr - 2, 2);
2037 /* Now check for FP adjustments, using add #imm,r14 or add rX, r14
2039 while (addr > func_addr + 4
2040 && (IS_ADD_REG_TO_FP (inst) || IS_ADD_IMM_FP (inst)))
2043 inst = read_memory_unsigned_integer (addr - 2, 2);
2052 static gdbarch_init_ftype sh_gdbarch_init;
2054 static struct gdbarch *
2055 sh_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
2057 struct gdbarch *gdbarch;
2059 sh_show_regs = sh_generic_show_regs;
2060 switch (info.bfd_arch_info->mach)
2063 sh_show_regs = sh2e_show_regs;
2065 case bfd_mach_sh_dsp:
2066 sh_show_regs = sh_dsp_show_regs;
2070 sh_show_regs = sh3_show_regs;
2074 sh_show_regs = sh3e_show_regs;
2077 case bfd_mach_sh3_dsp:
2078 sh_show_regs = sh3_dsp_show_regs;
2082 sh_show_regs = sh4_show_regs;
2086 sh_show_regs = sh64_show_regs;
2087 /* SH5 is handled entirely in sh64-tdep.c */
2088 return sh64_gdbarch_init (info, arches);
2091 /* If there is already a candidate, use it. */
2092 arches = gdbarch_list_lookup_by_info (arches, &info);
2094 return arches->gdbarch;
2096 /* None found, create a new architecture from the information
2098 gdbarch = gdbarch_alloc (&info, NULL);
2100 set_gdbarch_short_bit (gdbarch, 2 * TARGET_CHAR_BIT);
2101 set_gdbarch_int_bit (gdbarch, 4 * TARGET_CHAR_BIT);
2102 set_gdbarch_long_bit (gdbarch, 4 * TARGET_CHAR_BIT);
2103 set_gdbarch_long_long_bit (gdbarch, 8 * TARGET_CHAR_BIT);
2104 set_gdbarch_float_bit (gdbarch, 4 * TARGET_CHAR_BIT);
2105 set_gdbarch_double_bit (gdbarch, 8 * TARGET_CHAR_BIT);
2106 set_gdbarch_long_double_bit (gdbarch, 8 * TARGET_CHAR_BIT);
2107 set_gdbarch_ptr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
2109 set_gdbarch_num_regs (gdbarch, SH_NUM_REGS);
2110 set_gdbarch_sp_regnum (gdbarch, 15);
2111 set_gdbarch_pc_regnum (gdbarch, 16);
2112 set_gdbarch_fp0_regnum (gdbarch, -1);
2113 set_gdbarch_num_pseudo_regs (gdbarch, 0);
2115 set_gdbarch_register_type (gdbarch, sh_default_register_type);
2117 set_gdbarch_print_registers_info (gdbarch, sh_print_registers_info);
2119 set_gdbarch_breakpoint_from_pc (gdbarch, sh_breakpoint_from_pc);
2120 set_gdbarch_use_struct_convention (gdbarch, sh_use_struct_convention);
2122 set_gdbarch_print_insn (gdbarch, gdb_print_insn_sh);
2123 set_gdbarch_register_sim_regno (gdbarch, legacy_register_sim_regno);
2125 set_gdbarch_write_pc (gdbarch, generic_target_write_pc);
2127 set_gdbarch_store_return_value (gdbarch, sh_default_store_return_value);
2128 set_gdbarch_extract_return_value (gdbarch, sh_default_extract_return_value);
2129 set_gdbarch_extract_struct_value_address (gdbarch,
2130 sh_extract_struct_value_address);
2132 set_gdbarch_skip_prologue (gdbarch, sh_skip_prologue);
2133 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
2134 set_gdbarch_decr_pc_after_break (gdbarch, 0);
2135 set_gdbarch_function_start_offset (gdbarch, 0);
2137 set_gdbarch_push_dummy_code (gdbarch, sh_push_dummy_code);
2138 set_gdbarch_push_dummy_call (gdbarch, sh_push_dummy_call_nofpu);
2140 set_gdbarch_frame_args_skip (gdbarch, 0);
2141 set_gdbarch_frameless_function_invocation (gdbarch,
2142 frameless_look_for_prologue);
2143 set_gdbarch_believe_pcc_promotion (gdbarch, 1);
2145 set_gdbarch_frame_align (gdbarch, sh_frame_align);
2146 set_gdbarch_unwind_sp (gdbarch, sh_unwind_sp);
2147 set_gdbarch_unwind_pc (gdbarch, sh_unwind_pc);
2148 set_gdbarch_unwind_dummy_id (gdbarch, sh_unwind_dummy_id);
2149 frame_base_set_default (gdbarch, &sh_frame_base);
2151 set_gdbarch_in_function_epilogue_p (gdbarch,
2152 sh_in_function_epilogue_p);
2154 switch (info.bfd_arch_info->mach)
2157 set_gdbarch_register_name (gdbarch, sh_sh_register_name);
2161 set_gdbarch_register_name (gdbarch, sh_sh_register_name);
2165 /* doubles on sh2e and sh3e are actually 4 byte. */
2166 set_gdbarch_double_bit (gdbarch, 4 * TARGET_CHAR_BIT);
2168 set_gdbarch_register_name (gdbarch, sh_sh2e_register_name);
2169 set_gdbarch_register_type (gdbarch, sh_sh3e_register_type);
2170 set_gdbarch_fp0_regnum (gdbarch, 25);
2171 set_gdbarch_store_return_value (gdbarch, sh3e_sh4_store_return_value);
2172 set_gdbarch_extract_return_value (gdbarch, sh3e_sh4_extract_return_value);
2173 set_gdbarch_push_dummy_call (gdbarch, sh_push_dummy_call_fpu);
2176 case bfd_mach_sh_dsp:
2177 set_gdbarch_register_name (gdbarch, sh_sh_dsp_register_name);
2178 set_gdbarch_register_sim_regno (gdbarch, sh_dsp_register_sim_regno);
2182 set_gdbarch_register_name (gdbarch, sh_sh3_register_name);
2186 /* doubles on sh2e and sh3e are actually 4 byte. */
2187 set_gdbarch_double_bit (gdbarch, 4 * TARGET_CHAR_BIT);
2189 set_gdbarch_register_name (gdbarch, sh_sh3e_register_name);
2190 set_gdbarch_register_type (gdbarch, sh_sh3e_register_type);
2191 set_gdbarch_fp0_regnum (gdbarch, 25);
2192 set_gdbarch_store_return_value (gdbarch, sh3e_sh4_store_return_value);
2193 set_gdbarch_extract_return_value (gdbarch, sh3e_sh4_extract_return_value);
2194 set_gdbarch_push_dummy_call (gdbarch, sh_push_dummy_call_fpu);
2197 case bfd_mach_sh3_dsp:
2198 set_gdbarch_register_name (gdbarch, sh_sh3_dsp_register_name);
2199 set_gdbarch_register_sim_regno (gdbarch, sh_dsp_register_sim_regno);
2203 set_gdbarch_register_name (gdbarch, sh_sh4_register_name);
2204 set_gdbarch_register_type (gdbarch, sh_sh4_register_type);
2205 set_gdbarch_fp0_regnum (gdbarch, 25);
2206 set_gdbarch_num_pseudo_regs (gdbarch, 12);
2207 set_gdbarch_pseudo_register_read (gdbarch, sh_pseudo_register_read);
2208 set_gdbarch_pseudo_register_write (gdbarch, sh_pseudo_register_write);
2209 set_gdbarch_store_return_value (gdbarch, sh3e_sh4_store_return_value);
2210 set_gdbarch_extract_return_value (gdbarch, sh3e_sh4_extract_return_value);
2211 set_gdbarch_push_dummy_call (gdbarch, sh_push_dummy_call_fpu);
2215 set_gdbarch_register_name (gdbarch, sh_generic_register_name);
2219 /* Hook in ABI-specific overrides, if they have been registered. */
2220 gdbarch_init_osabi (info, gdbarch);
2222 frame_unwind_append_sniffer (gdbarch, dwarf2_frame_sniffer);
2223 frame_unwind_append_sniffer (gdbarch, sh_frame_sniffer);
2228 extern initialize_file_ftype _initialize_sh_tdep; /* -Wmissing-prototypes */
2231 _initialize_sh_tdep (void)
2233 struct cmd_list_element *c;
2235 gdbarch_register (bfd_arch_sh, sh_gdbarch_init, NULL);
2237 add_com ("regs", class_vars, sh_show_regs_command, "Print all registers");