* ax-gdb.c (gen_exp_binop_rest) [BINOP_SUBSCRIPT]: Error out if
[binutils-gdb.git] / gdb / sh-tdep.c
blob7e01469b058257612d5beb80159d654c134e41a0
1 /* Target-dependent code for Renesas Super-H, for GDB.
3 Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
4 2003, 2004, 2005, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 Contributed by Steve Chamberlain
23 sac@cygnus.com
26 #include "defs.h"
27 #include "frame.h"
28 #include "frame-base.h"
29 #include "frame-unwind.h"
30 #include "dwarf2-frame.h"
31 #include "symtab.h"
32 #include "gdbtypes.h"
33 #include "gdbcmd.h"
34 #include "gdbcore.h"
35 #include "value.h"
36 #include "dis-asm.h"
37 #include "inferior.h"
38 #include "gdb_string.h"
39 #include "gdb_assert.h"
40 #include "arch-utils.h"
41 #include "floatformat.h"
42 #include "regcache.h"
43 #include "doublest.h"
44 #include "osabi.h"
45 #include "reggroups.h"
46 #include "regset.h"
48 #include "sh-tdep.h"
50 #include "elf-bfd.h"
51 #include "solib-svr4.h"
53 /* sh flags */
54 #include "elf/sh.h"
55 #include "dwarf2.h"
56 /* registers numbers shared with the simulator */
57 #include "gdb/sim-sh.h"
59 /* List of "set sh ..." and "show sh ..." commands. */
60 static struct cmd_list_element *setshcmdlist = NULL;
61 static struct cmd_list_element *showshcmdlist = NULL;
63 static const char sh_cc_gcc[] = "gcc";
64 static const char sh_cc_renesas[] = "renesas";
65 static const char *sh_cc_enum[] = {
66 sh_cc_gcc,
67 sh_cc_renesas,
68 NULL
71 static const char *sh_active_calling_convention = sh_cc_gcc;
73 static void (*sh_show_regs) (struct frame_info *);
75 #define SH_NUM_REGS 67
77 struct sh_frame_cache
79 /* Base address. */
80 CORE_ADDR base;
81 LONGEST sp_offset;
82 CORE_ADDR pc;
84 /* Flag showing that a frame has been created in the prologue code. */
85 int uses_fp;
87 /* Saved registers. */
88 CORE_ADDR saved_regs[SH_NUM_REGS];
89 CORE_ADDR saved_sp;
92 static int
93 sh_is_renesas_calling_convention (struct type *func_type)
95 return ((func_type
96 && TYPE_CALLING_CONVENTION (func_type) == DW_CC_GNU_renesas_sh)
97 || sh_active_calling_convention == sh_cc_renesas);
100 static const char *
101 sh_sh_register_name (struct gdbarch *gdbarch, int reg_nr)
103 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",
107 "", "",
108 "", "", "", "", "", "", "", "",
109 "", "", "", "", "", "", "", "",
110 "", "",
111 "", "", "", "", "", "", "", "",
112 "", "", "", "", "", "", "", "",
113 "", "", "", "", "", "", "", "",
115 if (reg_nr < 0)
116 return NULL;
117 if (reg_nr >= (sizeof (register_names) / sizeof (*register_names)))
118 return NULL;
119 return register_names[reg_nr];
122 static const char *
123 sh_sh3_register_name (struct gdbarch *gdbarch, int reg_nr)
125 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",
129 "", "",
130 "", "", "", "", "", "", "", "",
131 "", "", "", "", "", "", "", "",
132 "ssr", "spc",
133 "r0b0", "r1b0", "r2b0", "r3b0", "r4b0", "r5b0", "r6b0", "r7b0",
134 "r0b1", "r1b1", "r2b1", "r3b1", "r4b1", "r5b1", "r6b1", "r7b1"
135 "", "", "", "", "", "", "", "",
137 if (reg_nr < 0)
138 return NULL;
139 if (reg_nr >= (sizeof (register_names) / sizeof (*register_names)))
140 return NULL;
141 return register_names[reg_nr];
144 static const char *
145 sh_sh3e_register_name (struct gdbarch *gdbarch, int reg_nr)
147 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",
151 "fpul", "fpscr",
152 "fr0", "fr1", "fr2", "fr3", "fr4", "fr5", "fr6", "fr7",
153 "fr8", "fr9", "fr10", "fr11", "fr12", "fr13", "fr14", "fr15",
154 "ssr", "spc",
155 "r0b0", "r1b0", "r2b0", "r3b0", "r4b0", "r5b0", "r6b0", "r7b0",
156 "r0b1", "r1b1", "r2b1", "r3b1", "r4b1", "r5b1", "r6b1", "r7b1",
157 "", "", "", "", "", "", "", "",
159 if (reg_nr < 0)
160 return NULL;
161 if (reg_nr >= (sizeof (register_names) / sizeof (*register_names)))
162 return NULL;
163 return register_names[reg_nr];
166 static const char *
167 sh_sh2e_register_name (struct gdbarch *gdbarch, int reg_nr)
169 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",
173 "fpul", "fpscr",
174 "fr0", "fr1", "fr2", "fr3", "fr4", "fr5", "fr6", "fr7",
175 "fr8", "fr9", "fr10", "fr11", "fr12", "fr13", "fr14", "fr15",
176 "", "",
177 "", "", "", "", "", "", "", "",
178 "", "", "", "", "", "", "", "",
179 "", "", "", "", "", "", "", "",
181 if (reg_nr < 0)
182 return NULL;
183 if (reg_nr >= (sizeof (register_names) / sizeof (*register_names)))
184 return NULL;
185 return register_names[reg_nr];
188 static const char *
189 sh_sh2a_register_name (struct gdbarch *gdbarch, int reg_nr)
191 static char *register_names[] = {
192 /* general registers 0-15 */
193 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
194 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
195 /* 16 - 22 */
196 "pc", "pr", "gbr", "vbr", "mach", "macl", "sr",
197 /* 23, 24 */
198 "fpul", "fpscr",
199 /* floating point registers 25 - 40 */
200 "fr0", "fr1", "fr2", "fr3", "fr4", "fr5", "fr6", "fr7",
201 "fr8", "fr9", "fr10", "fr11", "fr12", "fr13", "fr14", "fr15",
202 /* 41, 42 */
203 "", "",
204 /* 43 - 62. Banked registers. The bank number used is determined by
205 the bank register (63). */
206 "r0b", "r1b", "r2b", "r3b", "r4b", "r5b", "r6b", "r7b",
207 "r8b", "r9b", "r10b", "r11b", "r12b", "r13b", "r14b",
208 "machb", "ivnb", "prb", "gbrb", "maclb",
209 /* 63: register bank number, not a real register but used to
210 communicate the register bank currently get/set. This register
211 is hidden to the user, who manipulates it using the pseudo
212 register called "bank" (67). See below. */
214 /* 64 - 66 */
215 "ibcr", "ibnr", "tbr",
216 /* 67: register bank number, the user visible pseudo register. */
217 "bank",
218 /* double precision (pseudo) 68 - 75 */
219 "dr0", "dr2", "dr4", "dr6", "dr8", "dr10", "dr12", "dr14",
221 if (reg_nr < 0)
222 return NULL;
223 if (reg_nr >= (sizeof (register_names) / sizeof (*register_names)))
224 return NULL;
225 return register_names[reg_nr];
228 static const char *
229 sh_sh2a_nofpu_register_name (struct gdbarch *gdbarch, int reg_nr)
231 static char *register_names[] = {
232 /* general registers 0-15 */
233 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
234 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
235 /* 16 - 22 */
236 "pc", "pr", "gbr", "vbr", "mach", "macl", "sr",
237 /* 23, 24 */
238 "", "",
239 /* floating point registers 25 - 40 */
240 "", "", "", "", "", "", "", "",
241 "", "", "", "", "", "", "", "",
242 /* 41, 42 */
243 "", "",
244 /* 43 - 62. Banked registers. The bank number used is determined by
245 the bank register (63). */
246 "r0b", "r1b", "r2b", "r3b", "r4b", "r5b", "r6b", "r7b",
247 "r8b", "r9b", "r10b", "r11b", "r12b", "r13b", "r14b",
248 "machb", "ivnb", "prb", "gbrb", "maclb",
249 /* 63: register bank number, not a real register but used to
250 communicate the register bank currently get/set. This register
251 is hidden to the user, who manipulates it using the pseudo
252 register called "bank" (67). See below. */
254 /* 64 - 66 */
255 "ibcr", "ibnr", "tbr",
256 /* 67: register bank number, the user visible pseudo register. */
257 "bank",
258 /* double precision (pseudo) 68 - 75 */
259 "", "", "", "", "", "", "", "",
261 if (reg_nr < 0)
262 return NULL;
263 if (reg_nr >= (sizeof (register_names) / sizeof (*register_names)))
264 return NULL;
265 return register_names[reg_nr];
268 static const char *
269 sh_sh_dsp_register_name (struct gdbarch *gdbarch, int reg_nr)
271 static char *register_names[] = {
272 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
273 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
274 "pc", "pr", "gbr", "vbr", "mach", "macl", "sr",
275 "", "dsr",
276 "a0g", "a0", "a1g", "a1", "m0", "m1", "x0", "x1",
277 "y0", "y1", "", "", "", "", "", "mod",
278 "", "",
279 "rs", "re", "", "", "", "", "", "",
280 "", "", "", "", "", "", "", "",
281 "", "", "", "", "", "", "", "",
283 if (reg_nr < 0)
284 return NULL;
285 if (reg_nr >= (sizeof (register_names) / sizeof (*register_names)))
286 return NULL;
287 return register_names[reg_nr];
290 static const char *
291 sh_sh3_dsp_register_name (struct gdbarch *gdbarch, int reg_nr)
293 static char *register_names[] = {
294 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
295 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
296 "pc", "pr", "gbr", "vbr", "mach", "macl", "sr",
297 "", "dsr",
298 "a0g", "a0", "a1g", "a1", "m0", "m1", "x0", "x1",
299 "y0", "y1", "", "", "", "", "", "mod",
300 "ssr", "spc",
301 "rs", "re", "", "", "", "", "", "",
302 "r0b", "r1b", "r2b", "r3b", "r4b", "r5b", "r6b", "r7b",
303 "", "", "", "", "", "", "", "",
304 "", "", "", "", "", "", "", "",
306 if (reg_nr < 0)
307 return NULL;
308 if (reg_nr >= (sizeof (register_names) / sizeof (*register_names)))
309 return NULL;
310 return register_names[reg_nr];
313 static const char *
314 sh_sh4_register_name (struct gdbarch *gdbarch, int reg_nr)
316 static char *register_names[] = {
317 /* general registers 0-15 */
318 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
319 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
320 /* 16 - 22 */
321 "pc", "pr", "gbr", "vbr", "mach", "macl", "sr",
322 /* 23, 24 */
323 "fpul", "fpscr",
324 /* floating point registers 25 - 40 */
325 "fr0", "fr1", "fr2", "fr3", "fr4", "fr5", "fr6", "fr7",
326 "fr8", "fr9", "fr10", "fr11", "fr12", "fr13", "fr14", "fr15",
327 /* 41, 42 */
328 "ssr", "spc",
329 /* bank 0 43 - 50 */
330 "r0b0", "r1b0", "r2b0", "r3b0", "r4b0", "r5b0", "r6b0", "r7b0",
331 /* bank 1 51 - 58 */
332 "r0b1", "r1b1", "r2b1", "r3b1", "r4b1", "r5b1", "r6b1", "r7b1",
333 "", "", "", "", "", "", "", "",
334 /* pseudo bank register. */
336 /* double precision (pseudo) 59 - 66 */
337 "dr0", "dr2", "dr4", "dr6", "dr8", "dr10", "dr12", "dr14",
338 /* vectors (pseudo) 67 - 70 */
339 "fv0", "fv4", "fv8", "fv12",
340 /* FIXME: missing XF 71 - 86 */
341 /* FIXME: missing XD 87 - 94 */
343 if (reg_nr < 0)
344 return NULL;
345 if (reg_nr >= (sizeof (register_names) / sizeof (*register_names)))
346 return NULL;
347 return register_names[reg_nr];
350 static const char *
351 sh_sh4_nofpu_register_name (struct gdbarch *gdbarch, int reg_nr)
353 static char *register_names[] = {
354 /* general registers 0-15 */
355 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
356 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
357 /* 16 - 22 */
358 "pc", "pr", "gbr", "vbr", "mach", "macl", "sr",
359 /* 23, 24 */
360 "", "",
361 /* floating point registers 25 - 40 -- not for nofpu target */
362 "", "", "", "", "", "", "", "",
363 "", "", "", "", "", "", "", "",
364 /* 41, 42 */
365 "ssr", "spc",
366 /* bank 0 43 - 50 */
367 "r0b0", "r1b0", "r2b0", "r3b0", "r4b0", "r5b0", "r6b0", "r7b0",
368 /* bank 1 51 - 58 */
369 "r0b1", "r1b1", "r2b1", "r3b1", "r4b1", "r5b1", "r6b1", "r7b1",
370 "", "", "", "", "", "", "", "",
371 /* pseudo bank register. */
373 /* double precision (pseudo) 59 - 66 -- not for nofpu target */
374 "", "", "", "", "", "", "", "",
375 /* vectors (pseudo) 67 - 70 -- not for nofpu target */
376 "", "", "", "",
378 if (reg_nr < 0)
379 return NULL;
380 if (reg_nr >= (sizeof (register_names) / sizeof (*register_names)))
381 return NULL;
382 return register_names[reg_nr];
385 static const char *
386 sh_sh4al_dsp_register_name (struct gdbarch *gdbarch, int reg_nr)
388 static char *register_names[] = {
389 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
390 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
391 "pc", "pr", "gbr", "vbr", "mach", "macl", "sr",
392 "", "dsr",
393 "a0g", "a0", "a1g", "a1", "m0", "m1", "x0", "x1",
394 "y0", "y1", "", "", "", "", "", "mod",
395 "ssr", "spc",
396 "rs", "re", "", "", "", "", "", "",
397 "r0b", "r1b", "r2b", "r3b", "r4b", "r5b", "r6b", "r7b",
398 "", "", "", "", "", "", "", "",
399 "", "", "", "", "", "", "", "",
401 if (reg_nr < 0)
402 return NULL;
403 if (reg_nr >= (sizeof (register_names) / sizeof (*register_names)))
404 return NULL;
405 return register_names[reg_nr];
408 static const unsigned char *
409 sh_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr, int *lenptr)
411 /* 0xc3c3 is trapa #c3, and it works in big and little endian modes */
412 static unsigned char breakpoint[] = { 0xc3, 0xc3 };
414 /* For remote stub targets, trapa #20 is used. */
415 if (strcmp (target_shortname, "remote") == 0)
417 static unsigned char big_remote_breakpoint[] = { 0xc3, 0x20 };
418 static unsigned char little_remote_breakpoint[] = { 0x20, 0xc3 };
420 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
422 *lenptr = sizeof (big_remote_breakpoint);
423 return big_remote_breakpoint;
425 else
427 *lenptr = sizeof (little_remote_breakpoint);
428 return little_remote_breakpoint;
432 *lenptr = sizeof (breakpoint);
433 return breakpoint;
436 /* Prologue looks like
437 mov.l r14,@-r15
438 sts.l pr,@-r15
439 mov.l <regs>,@-r15
440 sub <room_for_loca_vars>,r15
441 mov r15,r14
443 Actually it can be more complicated than this but that's it, basically.
446 #define GET_SOURCE_REG(x) (((x) >> 4) & 0xf)
447 #define GET_TARGET_REG(x) (((x) >> 8) & 0xf)
449 /* JSR @Rm 0100mmmm00001011 */
450 #define IS_JSR(x) (((x) & 0xf0ff) == 0x400b)
452 /* STS.L PR,@-r15 0100111100100010
453 r15-4-->r15, PR-->(r15) */
454 #define IS_STS(x) ((x) == 0x4f22)
456 /* STS.L MACL,@-r15 0100111100010010
457 r15-4-->r15, MACL-->(r15) */
458 #define IS_MACL_STS(x) ((x) == 0x4f12)
460 /* MOV.L Rm,@-r15 00101111mmmm0110
461 r15-4-->r15, Rm-->(R15) */
462 #define IS_PUSH(x) (((x) & 0xff0f) == 0x2f06)
464 /* MOV r15,r14 0110111011110011
465 r15-->r14 */
466 #define IS_MOV_SP_FP(x) ((x) == 0x6ef3)
468 /* ADD #imm,r15 01111111iiiiiiii
469 r15+imm-->r15 */
470 #define IS_ADD_IMM_SP(x) (((x) & 0xff00) == 0x7f00)
472 #define IS_MOV_R3(x) (((x) & 0xff00) == 0x1a00)
473 #define IS_SHLL_R3(x) ((x) == 0x4300)
475 /* ADD r3,r15 0011111100111100
476 r15+r3-->r15 */
477 #define IS_ADD_R3SP(x) ((x) == 0x3f3c)
479 /* FMOV.S FRm,@-Rn Rn-4-->Rn, FRm-->(Rn) 1111nnnnmmmm1011
480 FMOV DRm,@-Rn Rn-8-->Rn, DRm-->(Rn) 1111nnnnmmm01011
481 FMOV XDm,@-Rn Rn-8-->Rn, XDm-->(Rn) 1111nnnnmmm11011 */
482 /* CV, 2003-08-28: Only suitable with Rn == SP, therefore name changed to
483 make this entirely clear. */
484 /* #define IS_FMOV(x) (((x) & 0xf00f) == 0xf00b) */
485 #define IS_FPUSH(x) (((x) & 0xff0f) == 0xff0b)
487 /* MOV Rm,Rn Rm-->Rn 0110nnnnmmmm0011 4 <= m <= 7 */
488 #define IS_MOV_ARG_TO_REG(x) \
489 (((x) & 0xf00f) == 0x6003 && \
490 ((x) & 0x00f0) >= 0x0040 && \
491 ((x) & 0x00f0) <= 0x0070)
492 /* MOV.L Rm,@Rn 0010nnnnmmmm0010 n = 14, 4 <= m <= 7 */
493 #define IS_MOV_ARG_TO_IND_R14(x) \
494 (((x) & 0xff0f) == 0x2e02 && \
495 ((x) & 0x00f0) >= 0x0040 && \
496 ((x) & 0x00f0) <= 0x0070)
497 /* MOV.L Rm,@(disp*4,Rn) 00011110mmmmdddd n = 14, 4 <= m <= 7 */
498 #define IS_MOV_ARG_TO_IND_R14_WITH_DISP(x) \
499 (((x) & 0xff00) == 0x1e00 && \
500 ((x) & 0x00f0) >= 0x0040 && \
501 ((x) & 0x00f0) <= 0x0070)
503 /* MOV.W @(disp*2,PC),Rn 1001nnnndddddddd */
504 #define IS_MOVW_PCREL_TO_REG(x) (((x) & 0xf000) == 0x9000)
505 /* MOV.L @(disp*4,PC),Rn 1101nnnndddddddd */
506 #define IS_MOVL_PCREL_TO_REG(x) (((x) & 0xf000) == 0xd000)
507 /* MOVI20 #imm20,Rn 0000nnnniiii0000 */
508 #define IS_MOVI20(x) (((x) & 0xf00f) == 0x0000)
509 /* SUB Rn,R15 00111111nnnn1000 */
510 #define IS_SUB_REG_FROM_SP(x) (((x) & 0xff0f) == 0x3f08)
512 #define FPSCR_SZ (1 << 20)
514 /* The following instructions are used for epilogue testing. */
515 #define IS_RESTORE_FP(x) ((x) == 0x6ef6)
516 #define IS_RTS(x) ((x) == 0x000b)
517 #define IS_LDS(x) ((x) == 0x4f26)
518 #define IS_MACL_LDS(x) ((x) == 0x4f16)
519 #define IS_MOV_FP_SP(x) ((x) == 0x6fe3)
520 #define IS_ADD_REG_TO_FP(x) (((x) & 0xff0f) == 0x3e0c)
521 #define IS_ADD_IMM_FP(x) (((x) & 0xff00) == 0x7e00)
523 static CORE_ADDR
524 sh_analyze_prologue (struct gdbarch *gdbarch,
525 CORE_ADDR pc, CORE_ADDR current_pc,
526 struct sh_frame_cache *cache, ULONGEST fpscr)
528 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
529 ULONGEST inst;
530 CORE_ADDR opc;
531 int offset;
532 int sav_offset = 0;
533 int r3_val = 0;
534 int reg, sav_reg = -1;
536 if (pc >= current_pc)
537 return current_pc;
539 cache->uses_fp = 0;
540 for (opc = pc + (2 * 28); pc < opc; pc += 2)
542 inst = read_memory_unsigned_integer (pc, 2, byte_order);
543 /* See where the registers will be saved to */
544 if (IS_PUSH (inst))
546 cache->saved_regs[GET_SOURCE_REG (inst)] = cache->sp_offset;
547 cache->sp_offset += 4;
549 else if (IS_STS (inst))
551 cache->saved_regs[PR_REGNUM] = cache->sp_offset;
552 cache->sp_offset += 4;
554 else if (IS_MACL_STS (inst))
556 cache->saved_regs[MACL_REGNUM] = cache->sp_offset;
557 cache->sp_offset += 4;
559 else if (IS_MOV_R3 (inst))
561 r3_val = ((inst & 0xff) ^ 0x80) - 0x80;
563 else if (IS_SHLL_R3 (inst))
565 r3_val <<= 1;
567 else if (IS_ADD_R3SP (inst))
569 cache->sp_offset += -r3_val;
571 else if (IS_ADD_IMM_SP (inst))
573 offset = ((inst & 0xff) ^ 0x80) - 0x80;
574 cache->sp_offset -= offset;
576 else if (IS_MOVW_PCREL_TO_REG (inst))
578 if (sav_reg < 0)
580 reg = GET_TARGET_REG (inst);
581 if (reg < 14)
583 sav_reg = reg;
584 offset = (inst & 0xff) << 1;
585 sav_offset =
586 read_memory_integer ((pc + 4) + offset, 2, byte_order);
590 else if (IS_MOVL_PCREL_TO_REG (inst))
592 if (sav_reg < 0)
594 reg = GET_TARGET_REG (inst);
595 if (reg < 14)
597 sav_reg = reg;
598 offset = (inst & 0xff) << 2;
599 sav_offset =
600 read_memory_integer (((pc & 0xfffffffc) + 4) + offset,
601 4, byte_order);
605 else if (IS_MOVI20 (inst))
607 if (sav_reg < 0)
609 reg = GET_TARGET_REG (inst);
610 if (reg < 14)
612 sav_reg = reg;
613 sav_offset = GET_SOURCE_REG (inst) << 16;
614 /* MOVI20 is a 32 bit instruction! */
615 pc += 2;
616 sav_offset
617 |= read_memory_unsigned_integer (pc, 2, byte_order);
618 /* Now sav_offset contains an unsigned 20 bit value.
619 It must still get sign extended. */
620 if (sav_offset & 0x00080000)
621 sav_offset |= 0xfff00000;
625 else if (IS_SUB_REG_FROM_SP (inst))
627 reg = GET_SOURCE_REG (inst);
628 if (sav_reg > 0 && reg == sav_reg)
630 sav_reg = -1;
632 cache->sp_offset += sav_offset;
634 else if (IS_FPUSH (inst))
636 if (fpscr & FPSCR_SZ)
638 cache->sp_offset += 8;
640 else
642 cache->sp_offset += 4;
645 else if (IS_MOV_SP_FP (inst))
647 cache->uses_fp = 1;
648 /* At this point, only allow argument register moves to other
649 registers or argument register moves to @(X,fp) which are
650 moving the register arguments onto the stack area allocated
651 by a former add somenumber to SP call. Don't allow moving
652 to an fp indirect address above fp + cache->sp_offset. */
653 pc += 2;
654 for (opc = pc + 12; pc < opc; pc += 2)
656 inst = read_memory_integer (pc, 2, byte_order);
657 if (IS_MOV_ARG_TO_IND_R14 (inst))
659 reg = GET_SOURCE_REG (inst);
660 if (cache->sp_offset > 0)
661 cache->saved_regs[reg] = cache->sp_offset;
663 else if (IS_MOV_ARG_TO_IND_R14_WITH_DISP (inst))
665 reg = GET_SOURCE_REG (inst);
666 offset = (inst & 0xf) * 4;
667 if (cache->sp_offset > offset)
668 cache->saved_regs[reg] = cache->sp_offset - offset;
670 else if (IS_MOV_ARG_TO_REG (inst))
671 continue;
672 else
673 break;
675 break;
677 else if (IS_JSR (inst))
679 /* We have found a jsr that has been scheduled into the prologue.
680 If we continue the scan and return a pc someplace after this,
681 then setting a breakpoint on this function will cause it to
682 appear to be called after the function it is calling via the
683 jsr, which will be very confusing. Most likely the next
684 instruction is going to be IS_MOV_SP_FP in the delay slot. If
685 so, note that before returning the current pc. */
686 inst = read_memory_integer (pc + 2, 2, byte_order);
687 if (IS_MOV_SP_FP (inst))
688 cache->uses_fp = 1;
689 break;
691 #if 0 /* This used to just stop when it found an instruction that
692 was not considered part of the prologue. Now, we just
693 keep going looking for likely instructions. */
694 else
695 break;
696 #endif
699 return pc;
702 /* Skip any prologue before the guts of a function */
704 /* Skip the prologue using the debug information. If this fails we'll
705 fall back on the 'guess' method below. */
706 static CORE_ADDR
707 after_prologue (CORE_ADDR pc)
709 struct symtab_and_line sal;
710 CORE_ADDR func_addr, func_end;
712 /* If we can not find the symbol in the partial symbol table, then
713 there is no hope we can determine the function's start address
714 with this code. */
715 if (!find_pc_partial_function (pc, NULL, &func_addr, &func_end))
716 return 0;
718 /* Get the line associated with FUNC_ADDR. */
719 sal = find_pc_line (func_addr, 0);
721 /* There are only two cases to consider. First, the end of the source line
722 is within the function bounds. In that case we return the end of the
723 source line. Second is the end of the source line extends beyond the
724 bounds of the current function. We need to use the slow code to
725 examine instructions in that case. */
726 if (sal.end < func_end)
727 return sal.end;
728 else
729 return 0;
732 static CORE_ADDR
733 sh_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
735 CORE_ADDR pc;
736 struct sh_frame_cache cache;
738 /* See if we can determine the end of the prologue via the symbol table.
739 If so, then return either PC, or the PC after the prologue, whichever
740 is greater. */
741 pc = after_prologue (start_pc);
743 /* If after_prologue returned a useful address, then use it. Else
744 fall back on the instruction skipping code. */
745 if (pc)
746 return max (pc, start_pc);
748 cache.sp_offset = -4;
749 pc = sh_analyze_prologue (gdbarch, start_pc, (CORE_ADDR) -1, &cache, 0);
750 if (!cache.uses_fp)
751 return start_pc;
753 return pc;
756 /* The ABI says:
758 Aggregate types not bigger than 8 bytes that have the same size and
759 alignment as one of the integer scalar types are returned in the
760 same registers as the integer type they match.
762 For example, a 2-byte aligned structure with size 2 bytes has the
763 same size and alignment as a short int, and will be returned in R0.
764 A 4-byte aligned structure with size 8 bytes has the same size and
765 alignment as a long long int, and will be returned in R0 and R1.
767 When an aggregate type is returned in R0 and R1, R0 contains the
768 first four bytes of the aggregate, and R1 contains the
769 remainder. If the size of the aggregate type is not a multiple of 4
770 bytes, the aggregate is tail-padded up to a multiple of 4
771 bytes. The value of the padding is undefined. For little-endian
772 targets the padding will appear at the most significant end of the
773 last element, for big-endian targets the padding appears at the
774 least significant end of the last element.
776 All other aggregate types are returned by address. The caller
777 function passes the address of an area large enough to hold the
778 aggregate value in R2. The called function stores the result in
779 this location.
781 To reiterate, structs smaller than 8 bytes could also be returned
782 in memory, if they don't pass the "same size and alignment as an
783 integer type" rule.
785 For example, in
787 struct s { char c[3]; } wibble;
788 struct s foo(void) { return wibble; }
790 the return value from foo() will be in memory, not
791 in R0, because there is no 3-byte integer type.
793 Similarly, in
795 struct s { char c[2]; } wibble;
796 struct s foo(void) { return wibble; }
798 because a struct containing two chars has alignment 1, that matches
799 type char, but size 2, that matches type short. There's no integer
800 type that has alignment 1 and size 2, so the struct is returned in
801 memory.
805 static int
806 sh_use_struct_convention (int renesas_abi, struct type *type)
808 int len = TYPE_LENGTH (type);
809 int nelem = TYPE_NFIELDS (type);
811 /* The Renesas ABI returns aggregate types always on stack. */
812 if (renesas_abi && (TYPE_CODE (type) == TYPE_CODE_STRUCT
813 || TYPE_CODE (type) == TYPE_CODE_UNION))
814 return 1;
816 /* Non-power of 2 length types and types bigger than 8 bytes (which don't
817 fit in two registers anyway) use struct convention. */
818 if (len != 1 && len != 2 && len != 4 && len != 8)
819 return 1;
821 /* Scalar types and aggregate types with exactly one field are aligned
822 by definition. They are returned in registers. */
823 if (nelem <= 1)
824 return 0;
826 /* If the first field in the aggregate has the same length as the entire
827 aggregate type, the type is returned in registers. */
828 if (TYPE_LENGTH (TYPE_FIELD_TYPE (type, 0)) == len)
829 return 0;
831 /* If the size of the aggregate is 8 bytes and the first field is
832 of size 4 bytes its alignment is equal to long long's alignment,
833 so it's returned in registers. */
834 if (len == 8 && TYPE_LENGTH (TYPE_FIELD_TYPE (type, 0)) == 4)
835 return 0;
837 /* Otherwise use struct convention. */
838 return 1;
841 static int
842 sh_use_struct_convention_nofpu (int renesas_abi, struct type *type)
844 /* The Renesas ABI returns long longs/doubles etc. always on stack. */
845 if (renesas_abi && TYPE_NFIELDS (type) == 0 && TYPE_LENGTH (type) >= 8)
846 return 1;
847 return sh_use_struct_convention (renesas_abi, type);
850 static CORE_ADDR
851 sh_frame_align (struct gdbarch *ignore, CORE_ADDR sp)
853 return sp & ~3;
856 /* Function: push_dummy_call (formerly push_arguments)
857 Setup the function arguments for calling a function in the inferior.
859 On the Renesas SH architecture, there are four registers (R4 to R7)
860 which are dedicated for passing function arguments. Up to the first
861 four arguments (depending on size) may go into these registers.
862 The rest go on the stack.
864 MVS: Except on SH variants that have floating point registers.
865 In that case, float and double arguments are passed in the same
866 manner, but using FP registers instead of GP registers.
868 Arguments that are smaller than 4 bytes will still take up a whole
869 register or a whole 32-bit word on the stack, and will be
870 right-justified in the register or the stack word. This includes
871 chars, shorts, and small aggregate types.
873 Arguments that are larger than 4 bytes may be split between two or
874 more registers. If there are not enough registers free, an argument
875 may be passed partly in a register (or registers), and partly on the
876 stack. This includes doubles, long longs, and larger aggregates.
877 As far as I know, there is no upper limit to the size of aggregates
878 that will be passed in this way; in other words, the convention of
879 passing a pointer to a large aggregate instead of a copy is not used.
881 MVS: The above appears to be true for the SH variants that do not
882 have an FPU, however those that have an FPU appear to copy the
883 aggregate argument onto the stack (and not place it in registers)
884 if it is larger than 16 bytes (four GP registers).
886 An exceptional case exists for struct arguments (and possibly other
887 aggregates such as arrays) if the size is larger than 4 bytes but
888 not a multiple of 4 bytes. In this case the argument is never split
889 between the registers and the stack, but instead is copied in its
890 entirety onto the stack, AND also copied into as many registers as
891 there is room for. In other words, space in registers permitting,
892 two copies of the same argument are passed in. As far as I can tell,
893 only the one on the stack is used, although that may be a function
894 of the level of compiler optimization. I suspect this is a compiler
895 bug. Arguments of these odd sizes are left-justified within the
896 word (as opposed to arguments smaller than 4 bytes, which are
897 right-justified).
899 If the function is to return an aggregate type such as a struct, it
900 is either returned in the normal return value register R0 (if its
901 size is no greater than one byte), or else the caller must allocate
902 space into which the callee will copy the return value (if the size
903 is greater than one byte). In this case, a pointer to the return
904 value location is passed into the callee in register R2, which does
905 not displace any of the other arguments passed in via registers R4
906 to R7. */
908 /* Helper function to justify value in register according to endianess. */
909 static char *
910 sh_justify_value_in_reg (struct gdbarch *gdbarch, struct value *val, int len)
912 static char valbuf[4];
914 memset (valbuf, 0, sizeof (valbuf));
915 if (len < 4)
917 /* value gets right-justified in the register or stack word */
918 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
919 memcpy (valbuf + (4 - len), (char *) value_contents (val), len);
920 else
921 memcpy (valbuf, (char *) value_contents (val), len);
922 return valbuf;
924 return (char *) value_contents (val);
927 /* Helper function to eval number of bytes to allocate on stack. */
928 static CORE_ADDR
929 sh_stack_allocsize (int nargs, struct value **args)
931 int stack_alloc = 0;
932 while (nargs-- > 0)
933 stack_alloc += ((TYPE_LENGTH (value_type (args[nargs])) + 3) & ~3);
934 return stack_alloc;
937 /* Helper functions for getting the float arguments right. Registers usage
938 depends on the ABI and the endianess. The comments should enlighten how
939 it's intended to work. */
941 /* This array stores which of the float arg registers are already in use. */
942 static int flt_argreg_array[FLOAT_ARGLAST_REGNUM - FLOAT_ARG0_REGNUM + 1];
944 /* This function just resets the above array to "no reg used so far". */
945 static void
946 sh_init_flt_argreg (void)
948 memset (flt_argreg_array, 0, sizeof flt_argreg_array);
951 /* This function returns the next register to use for float arg passing.
952 It returns either a valid value between FLOAT_ARG0_REGNUM and
953 FLOAT_ARGLAST_REGNUM if a register is available, otherwise it returns
954 FLOAT_ARGLAST_REGNUM + 1 to indicate that no register is available.
956 Note that register number 0 in flt_argreg_array corresponds with the
957 real float register fr4. In contrast to FLOAT_ARG0_REGNUM (value is
958 29) the parity of the register number is preserved, which is important
959 for the double register passing test (see the "argreg & 1" test below). */
960 static int
961 sh_next_flt_argreg (struct gdbarch *gdbarch, int len, struct type *func_type)
963 int argreg;
965 /* First search for the next free register. */
966 for (argreg = 0; argreg <= FLOAT_ARGLAST_REGNUM - FLOAT_ARG0_REGNUM;
967 ++argreg)
968 if (!flt_argreg_array[argreg])
969 break;
971 /* No register left? */
972 if (argreg > FLOAT_ARGLAST_REGNUM - FLOAT_ARG0_REGNUM)
973 return FLOAT_ARGLAST_REGNUM + 1;
975 if (len == 8)
977 /* Doubles are always starting in a even register number. */
978 if (argreg & 1)
980 /* In gcc ABI, the skipped register is lost for further argument
981 passing now. Not so in Renesas ABI. */
982 if (!sh_is_renesas_calling_convention (func_type))
983 flt_argreg_array[argreg] = 1;
985 ++argreg;
987 /* No register left? */
988 if (argreg > FLOAT_ARGLAST_REGNUM - FLOAT_ARG0_REGNUM)
989 return FLOAT_ARGLAST_REGNUM + 1;
991 /* Also mark the next register as used. */
992 flt_argreg_array[argreg + 1] = 1;
994 else if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE
995 && !sh_is_renesas_calling_convention (func_type))
997 /* In little endian, gcc passes floats like this: f5, f4, f7, f6, ... */
998 if (!flt_argreg_array[argreg + 1])
999 ++argreg;
1001 flt_argreg_array[argreg] = 1;
1002 return FLOAT_ARG0_REGNUM + argreg;
1005 /* Helper function which figures out, if a type is treated like a float type.
1007 The FPU ABIs have a special way how to treat types as float types.
1008 Structures with exactly one member, which is of type float or double, are
1009 treated exactly as the base types float or double:
1011 struct sf {
1012 float f;
1015 struct sd {
1016 double d;
1019 are handled the same way as just
1021 float f;
1023 double d;
1025 As a result, arguments of these struct types are pushed into floating point
1026 registers exactly as floats or doubles, using the same decision algorithm.
1028 The same is valid if these types are used as function return types. The
1029 above structs are returned in fr0 resp. fr0,fr1 instead of in r0, r0,r1
1030 or even using struct convention as it is for other structs. */
1032 static int
1033 sh_treat_as_flt_p (struct type *type)
1035 int len = TYPE_LENGTH (type);
1037 /* Ordinary float types are obviously treated as float. */
1038 if (TYPE_CODE (type) == TYPE_CODE_FLT)
1039 return 1;
1040 /* Otherwise non-struct types are not treated as float. */
1041 if (TYPE_CODE (type) != TYPE_CODE_STRUCT)
1042 return 0;
1043 /* Otherwise structs with more than one memeber are not treated as float. */
1044 if (TYPE_NFIELDS (type) != 1)
1045 return 0;
1046 /* Otherwise if the type of that member is float, the whole type is
1047 treated as float. */
1048 if (TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) == TYPE_CODE_FLT)
1049 return 1;
1050 /* Otherwise it's not treated as float. */
1051 return 0;
1054 static CORE_ADDR
1055 sh_push_dummy_call_fpu (struct gdbarch *gdbarch,
1056 struct value *function,
1057 struct regcache *regcache,
1058 CORE_ADDR bp_addr, int nargs,
1059 struct value **args,
1060 CORE_ADDR sp, int struct_return,
1061 CORE_ADDR struct_addr)
1063 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1064 int stack_offset = 0;
1065 int argreg = ARG0_REGNUM;
1066 int flt_argreg = 0;
1067 int argnum;
1068 struct type *func_type = value_type (function);
1069 struct type *type;
1070 CORE_ADDR regval;
1071 char *val;
1072 int len, reg_size = 0;
1073 int pass_on_stack = 0;
1074 int treat_as_flt;
1075 int last_reg_arg = INT_MAX;
1077 /* The Renesas ABI expects all varargs arguments, plus the last
1078 non-vararg argument to be on the stack, no matter how many
1079 registers have been used so far. */
1080 if (sh_is_renesas_calling_convention (func_type)
1081 && TYPE_VARARGS (func_type))
1082 last_reg_arg = TYPE_NFIELDS (func_type) - 2;
1084 /* first force sp to a 4-byte alignment */
1085 sp = sh_frame_align (gdbarch, sp);
1087 /* make room on stack for args */
1088 sp -= sh_stack_allocsize (nargs, args);
1090 /* Initialize float argument mechanism. */
1091 sh_init_flt_argreg ();
1093 /* Now load as many as possible of the first arguments into
1094 registers, and push the rest onto the stack. There are 16 bytes
1095 in four registers available. Loop thru args from first to last. */
1096 for (argnum = 0; argnum < nargs; argnum++)
1098 type = value_type (args[argnum]);
1099 len = TYPE_LENGTH (type);
1100 val = sh_justify_value_in_reg (gdbarch, args[argnum], len);
1102 /* Some decisions have to be made how various types are handled.
1103 This also differs in different ABIs. */
1104 pass_on_stack = 0;
1106 /* Find out the next register to use for a floating point value. */
1107 treat_as_flt = sh_treat_as_flt_p (type);
1108 if (treat_as_flt)
1109 flt_argreg = sh_next_flt_argreg (gdbarch, len, func_type);
1110 /* In Renesas ABI, long longs and aggregate types are always passed
1111 on stack. */
1112 else if (sh_is_renesas_calling_convention (func_type)
1113 && ((TYPE_CODE (type) == TYPE_CODE_INT && len == 8)
1114 || TYPE_CODE (type) == TYPE_CODE_STRUCT
1115 || TYPE_CODE (type) == TYPE_CODE_UNION))
1116 pass_on_stack = 1;
1117 /* In contrast to non-FPU CPUs, arguments are never split between
1118 registers and stack. If an argument doesn't fit in the remaining
1119 registers it's always pushed entirely on the stack. */
1120 else if (len > ((ARGLAST_REGNUM - argreg + 1) * 4))
1121 pass_on_stack = 1;
1123 while (len > 0)
1125 if ((treat_as_flt && flt_argreg > FLOAT_ARGLAST_REGNUM)
1126 || (!treat_as_flt && (argreg > ARGLAST_REGNUM
1127 || pass_on_stack))
1128 || argnum > last_reg_arg)
1130 /* The data goes entirely on the stack, 4-byte aligned. */
1131 reg_size = (len + 3) & ~3;
1132 write_memory (sp + stack_offset, val, reg_size);
1133 stack_offset += reg_size;
1135 else if (treat_as_flt && flt_argreg <= FLOAT_ARGLAST_REGNUM)
1137 /* Argument goes in a float argument register. */
1138 reg_size = register_size (gdbarch, flt_argreg);
1139 regval = extract_unsigned_integer (val, reg_size, byte_order);
1140 /* In little endian mode, float types taking two registers
1141 (doubles on sh4, long doubles on sh2e, sh3e and sh4) must
1142 be stored swapped in the argument registers. The below
1143 code first writes the first 32 bits in the next but one
1144 register, increments the val and len values accordingly
1145 and then proceeds as normal by writing the second 32 bits
1146 into the next register. */
1147 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE
1148 && TYPE_LENGTH (type) == 2 * reg_size)
1150 regcache_cooked_write_unsigned (regcache, flt_argreg + 1,
1151 regval);
1152 val += reg_size;
1153 len -= reg_size;
1154 regval = extract_unsigned_integer (val, reg_size, byte_order);
1156 regcache_cooked_write_unsigned (regcache, flt_argreg++, regval);
1158 else if (!treat_as_flt && argreg <= ARGLAST_REGNUM)
1160 /* there's room in a register */
1161 reg_size = register_size (gdbarch, argreg);
1162 regval = extract_unsigned_integer (val, reg_size, byte_order);
1163 regcache_cooked_write_unsigned (regcache, argreg++, regval);
1165 /* Store the value one register at a time or in one step on stack. */
1166 len -= reg_size;
1167 val += reg_size;
1171 if (struct_return)
1173 if (sh_is_renesas_calling_convention (func_type))
1174 /* If the function uses the Renesas ABI, subtract another 4 bytes from
1175 the stack and store the struct return address there. */
1176 write_memory_unsigned_integer (sp -= 4, 4, byte_order, struct_addr);
1177 else
1178 /* Using the gcc ABI, the "struct return pointer" pseudo-argument has
1179 its own dedicated register. */
1180 regcache_cooked_write_unsigned (regcache,
1181 STRUCT_RETURN_REGNUM, struct_addr);
1184 /* Store return address. */
1185 regcache_cooked_write_unsigned (regcache, PR_REGNUM, bp_addr);
1187 /* Update stack pointer. */
1188 regcache_cooked_write_unsigned (regcache,
1189 gdbarch_sp_regnum (gdbarch), sp);
1191 return sp;
1194 static CORE_ADDR
1195 sh_push_dummy_call_nofpu (struct gdbarch *gdbarch,
1196 struct value *function,
1197 struct regcache *regcache,
1198 CORE_ADDR bp_addr,
1199 int nargs, struct value **args,
1200 CORE_ADDR sp, int struct_return,
1201 CORE_ADDR struct_addr)
1203 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1204 int stack_offset = 0;
1205 int argreg = ARG0_REGNUM;
1206 int argnum;
1207 struct type *func_type = value_type (function);
1208 struct type *type;
1209 CORE_ADDR regval;
1210 char *val;
1211 int len, reg_size = 0;
1212 int pass_on_stack = 0;
1213 int last_reg_arg = INT_MAX;
1215 /* The Renesas ABI expects all varargs arguments, plus the last
1216 non-vararg argument to be on the stack, no matter how many
1217 registers have been used so far. */
1218 if (sh_is_renesas_calling_convention (func_type)
1219 && TYPE_VARARGS (func_type))
1220 last_reg_arg = TYPE_NFIELDS (func_type) - 2;
1222 /* first force sp to a 4-byte alignment */
1223 sp = sh_frame_align (gdbarch, sp);
1225 /* make room on stack for args */
1226 sp -= sh_stack_allocsize (nargs, args);
1228 /* Now load as many as possible of the first arguments into
1229 registers, and push the rest onto the stack. There are 16 bytes
1230 in four registers available. Loop thru args from first to last. */
1231 for (argnum = 0; argnum < nargs; argnum++)
1233 type = value_type (args[argnum]);
1234 len = TYPE_LENGTH (type);
1235 val = sh_justify_value_in_reg (gdbarch, args[argnum], len);
1237 /* Some decisions have to be made how various types are handled.
1238 This also differs in different ABIs. */
1239 pass_on_stack = 0;
1240 /* Renesas ABI pushes doubles and long longs entirely on stack.
1241 Same goes for aggregate types. */
1242 if (sh_is_renesas_calling_convention (func_type)
1243 && ((TYPE_CODE (type) == TYPE_CODE_INT && len >= 8)
1244 || (TYPE_CODE (type) == TYPE_CODE_FLT && len >= 8)
1245 || TYPE_CODE (type) == TYPE_CODE_STRUCT
1246 || TYPE_CODE (type) == TYPE_CODE_UNION))
1247 pass_on_stack = 1;
1248 while (len > 0)
1250 if (argreg > ARGLAST_REGNUM || pass_on_stack
1251 || argnum > last_reg_arg)
1253 /* The remainder of the data goes entirely on the stack,
1254 4-byte aligned. */
1255 reg_size = (len + 3) & ~3;
1256 write_memory (sp + stack_offset, val, reg_size);
1257 stack_offset += reg_size;
1259 else if (argreg <= ARGLAST_REGNUM)
1261 /* there's room in a register */
1262 reg_size = register_size (gdbarch, argreg);
1263 regval = extract_unsigned_integer (val, reg_size, byte_order);
1264 regcache_cooked_write_unsigned (regcache, argreg++, regval);
1266 /* Store the value reg_size bytes at a time. This means that things
1267 larger than reg_size bytes may go partly in registers and partly
1268 on the stack. */
1269 len -= reg_size;
1270 val += reg_size;
1274 if (struct_return)
1276 if (sh_is_renesas_calling_convention (func_type))
1277 /* If the function uses the Renesas ABI, subtract another 4 bytes from
1278 the stack and store the struct return address there. */
1279 write_memory_unsigned_integer (sp -= 4, 4, byte_order, struct_addr);
1280 else
1281 /* Using the gcc ABI, the "struct return pointer" pseudo-argument has
1282 its own dedicated register. */
1283 regcache_cooked_write_unsigned (regcache,
1284 STRUCT_RETURN_REGNUM, struct_addr);
1287 /* Store return address. */
1288 regcache_cooked_write_unsigned (regcache, PR_REGNUM, bp_addr);
1290 /* Update stack pointer. */
1291 regcache_cooked_write_unsigned (regcache,
1292 gdbarch_sp_regnum (gdbarch), sp);
1294 return sp;
1297 /* Find a function's return value in the appropriate registers (in
1298 regbuf), and copy it into valbuf. Extract from an array REGBUF
1299 containing the (raw) register state a function return value of type
1300 TYPE, and copy that, in virtual format, into VALBUF. */
1301 static void
1302 sh_extract_return_value_nofpu (struct type *type, struct regcache *regcache,
1303 void *valbuf)
1305 struct gdbarch *gdbarch = get_regcache_arch (regcache);
1306 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1307 int len = TYPE_LENGTH (type);
1308 int return_register = R0_REGNUM;
1309 int offset;
1311 if (len <= 4)
1313 ULONGEST c;
1315 regcache_cooked_read_unsigned (regcache, R0_REGNUM, &c);
1316 store_unsigned_integer (valbuf, len, byte_order, c);
1318 else if (len == 8)
1320 int i, regnum = R0_REGNUM;
1321 for (i = 0; i < len; i += 4)
1322 regcache_raw_read (regcache, regnum++, (char *) valbuf + i);
1324 else
1325 error (_("bad size for return value"));
1328 static void
1329 sh_extract_return_value_fpu (struct type *type, struct regcache *regcache,
1330 void *valbuf)
1332 struct gdbarch *gdbarch = get_regcache_arch (regcache);
1333 if (sh_treat_as_flt_p (type))
1335 int len = TYPE_LENGTH (type);
1336 int i, regnum = gdbarch_fp0_regnum (gdbarch);
1337 for (i = 0; i < len; i += 4)
1338 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE)
1339 regcache_raw_read (regcache, regnum++, (char *) valbuf + len - 4 - i);
1340 else
1341 regcache_raw_read (regcache, regnum++, (char *) valbuf + i);
1343 else
1344 sh_extract_return_value_nofpu (type, regcache, valbuf);
1347 /* Write into appropriate registers a function return value
1348 of type TYPE, given in virtual format.
1349 If the architecture is sh4 or sh3e, store a function's return value
1350 in the R0 general register or in the FP0 floating point register,
1351 depending on the type of the return value. In all the other cases
1352 the result is stored in r0, left-justified. */
1353 static void
1354 sh_store_return_value_nofpu (struct type *type, struct regcache *regcache,
1355 const void *valbuf)
1357 struct gdbarch *gdbarch = get_regcache_arch (regcache);
1358 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1359 ULONGEST val;
1360 int len = TYPE_LENGTH (type);
1362 if (len <= 4)
1364 val = extract_unsigned_integer (valbuf, len, byte_order);
1365 regcache_cooked_write_unsigned (regcache, R0_REGNUM, val);
1367 else
1369 int i, regnum = R0_REGNUM;
1370 for (i = 0; i < len; i += 4)
1371 regcache_raw_write (regcache, regnum++, (char *) valbuf + i);
1375 static void
1376 sh_store_return_value_fpu (struct type *type, struct regcache *regcache,
1377 const void *valbuf)
1379 struct gdbarch *gdbarch = get_regcache_arch (regcache);
1380 if (sh_treat_as_flt_p (type))
1382 int len = TYPE_LENGTH (type);
1383 int i, regnum = gdbarch_fp0_regnum (gdbarch);
1384 for (i = 0; i < len; i += 4)
1385 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE)
1386 regcache_raw_write (regcache, regnum++,
1387 (char *) valbuf + len - 4 - i);
1388 else
1389 regcache_raw_write (regcache, regnum++, (char *) valbuf + i);
1391 else
1392 sh_store_return_value_nofpu (type, regcache, valbuf);
1395 static enum return_value_convention
1396 sh_return_value_nofpu (struct gdbarch *gdbarch, struct type *func_type,
1397 struct type *type, struct regcache *regcache,
1398 gdb_byte *readbuf, const gdb_byte *writebuf)
1400 if (sh_use_struct_convention_nofpu (
1401 sh_is_renesas_calling_convention (func_type), type))
1402 return RETURN_VALUE_STRUCT_CONVENTION;
1403 if (writebuf)
1404 sh_store_return_value_nofpu (type, regcache, writebuf);
1405 else if (readbuf)
1406 sh_extract_return_value_nofpu (type, regcache, readbuf);
1407 return RETURN_VALUE_REGISTER_CONVENTION;
1410 static enum return_value_convention
1411 sh_return_value_fpu (struct gdbarch *gdbarch, struct type *func_type,
1412 struct type *type, struct regcache *regcache,
1413 gdb_byte *readbuf, const gdb_byte *writebuf)
1415 if (sh_use_struct_convention (
1416 sh_is_renesas_calling_convention (func_type), type))
1417 return RETURN_VALUE_STRUCT_CONVENTION;
1418 if (writebuf)
1419 sh_store_return_value_fpu (type, regcache, writebuf);
1420 else if (readbuf)
1421 sh_extract_return_value_fpu (type, regcache, readbuf);
1422 return RETURN_VALUE_REGISTER_CONVENTION;
1425 /* Print the registers in a form similar to the E7000 */
1427 static void
1428 sh_generic_show_regs (struct frame_info *frame)
1430 printf_filtered
1431 (" PC %s SR %08lx PR %08lx MACH %08lx\n",
1432 phex (get_frame_register_unsigned (frame,
1433 gdbarch_pc_regnum
1434 (get_frame_arch (frame))), 4),
1435 (long) get_frame_register_unsigned (frame, SR_REGNUM),
1436 (long) get_frame_register_unsigned (frame, PR_REGNUM),
1437 (long) get_frame_register_unsigned (frame, MACH_REGNUM));
1439 printf_filtered
1440 (" GBR %08lx VBR %08lx MACL %08lx\n",
1441 (long) get_frame_register_unsigned (frame, GBR_REGNUM),
1442 (long) get_frame_register_unsigned (frame, VBR_REGNUM),
1443 (long) get_frame_register_unsigned (frame, MACL_REGNUM));
1445 printf_filtered
1446 ("R0-R7 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
1447 (long) get_frame_register_unsigned (frame, 0),
1448 (long) get_frame_register_unsigned (frame, 1),
1449 (long) get_frame_register_unsigned (frame, 2),
1450 (long) get_frame_register_unsigned (frame, 3),
1451 (long) get_frame_register_unsigned (frame, 4),
1452 (long) get_frame_register_unsigned (frame, 5),
1453 (long) get_frame_register_unsigned (frame, 6),
1454 (long) get_frame_register_unsigned (frame, 7));
1455 printf_filtered
1456 ("R8-R15 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
1457 (long) get_frame_register_unsigned (frame, 8),
1458 (long) get_frame_register_unsigned (frame, 9),
1459 (long) get_frame_register_unsigned (frame, 10),
1460 (long) get_frame_register_unsigned (frame, 11),
1461 (long) get_frame_register_unsigned (frame, 12),
1462 (long) get_frame_register_unsigned (frame, 13),
1463 (long) get_frame_register_unsigned (frame, 14),
1464 (long) get_frame_register_unsigned (frame, 15));
1467 static void
1468 sh3_show_regs (struct frame_info *frame)
1470 printf_filtered
1471 (" PC %s SR %08lx PR %08lx MACH %08lx\n",
1472 phex (get_frame_register_unsigned (frame,
1473 gdbarch_pc_regnum
1474 (get_frame_arch (frame))), 4),
1475 (long) get_frame_register_unsigned (frame, SR_REGNUM),
1476 (long) get_frame_register_unsigned (frame, PR_REGNUM),
1477 (long) get_frame_register_unsigned (frame, MACH_REGNUM));
1479 printf_filtered
1480 (" GBR %08lx VBR %08lx MACL %08lx\n",
1481 (long) get_frame_register_unsigned (frame, GBR_REGNUM),
1482 (long) get_frame_register_unsigned (frame, VBR_REGNUM),
1483 (long) get_frame_register_unsigned (frame, MACL_REGNUM));
1484 printf_filtered
1485 (" SSR %08lx SPC %08lx\n",
1486 (long) get_frame_register_unsigned (frame, SSR_REGNUM),
1487 (long) get_frame_register_unsigned (frame, SPC_REGNUM));
1489 printf_filtered
1490 ("R0-R7 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
1491 (long) get_frame_register_unsigned (frame, 0),
1492 (long) get_frame_register_unsigned (frame, 1),
1493 (long) get_frame_register_unsigned (frame, 2),
1494 (long) get_frame_register_unsigned (frame, 3),
1495 (long) get_frame_register_unsigned (frame, 4),
1496 (long) get_frame_register_unsigned (frame, 5),
1497 (long) get_frame_register_unsigned (frame, 6),
1498 (long) get_frame_register_unsigned (frame, 7));
1499 printf_filtered
1500 ("R8-R15 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
1501 (long) get_frame_register_unsigned (frame, 8),
1502 (long) get_frame_register_unsigned (frame, 9),
1503 (long) get_frame_register_unsigned (frame, 10),
1504 (long) get_frame_register_unsigned (frame, 11),
1505 (long) get_frame_register_unsigned (frame, 12),
1506 (long) get_frame_register_unsigned (frame, 13),
1507 (long) get_frame_register_unsigned (frame, 14),
1508 (long) get_frame_register_unsigned (frame, 15));
1511 static void
1512 sh2e_show_regs (struct frame_info *frame)
1514 struct gdbarch *gdbarch = get_frame_arch (frame);
1515 printf_filtered
1516 (" PC %s SR %08lx PR %08lx MACH %08lx\n",
1517 phex (get_frame_register_unsigned (frame,
1518 gdbarch_pc_regnum (gdbarch)), 4),
1519 (long) get_frame_register_unsigned (frame, SR_REGNUM),
1520 (long) get_frame_register_unsigned (frame, PR_REGNUM),
1521 (long) get_frame_register_unsigned (frame, MACH_REGNUM));
1523 printf_filtered
1524 (" GBR %08lx VBR %08lx MACL %08lx\n",
1525 (long) get_frame_register_unsigned (frame, GBR_REGNUM),
1526 (long) get_frame_register_unsigned (frame, VBR_REGNUM),
1527 (long) get_frame_register_unsigned (frame, MACL_REGNUM));
1528 printf_filtered
1529 (" SSR %08lx SPC %08lx FPUL %08lx FPSCR %08lx\n",
1530 (long) get_frame_register_unsigned (frame, SSR_REGNUM),
1531 (long) get_frame_register_unsigned (frame, SPC_REGNUM),
1532 (long) get_frame_register_unsigned (frame, FPUL_REGNUM),
1533 (long) get_frame_register_unsigned (frame, FPSCR_REGNUM));
1535 printf_filtered
1536 ("R0-R7 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
1537 (long) get_frame_register_unsigned (frame, 0),
1538 (long) get_frame_register_unsigned (frame, 1),
1539 (long) get_frame_register_unsigned (frame, 2),
1540 (long) get_frame_register_unsigned (frame, 3),
1541 (long) get_frame_register_unsigned (frame, 4),
1542 (long) get_frame_register_unsigned (frame, 5),
1543 (long) get_frame_register_unsigned (frame, 6),
1544 (long) get_frame_register_unsigned (frame, 7));
1545 printf_filtered
1546 ("R8-R15 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
1547 (long) get_frame_register_unsigned (frame, 8),
1548 (long) get_frame_register_unsigned (frame, 9),
1549 (long) get_frame_register_unsigned (frame, 10),
1550 (long) get_frame_register_unsigned (frame, 11),
1551 (long) get_frame_register_unsigned (frame, 12),
1552 (long) get_frame_register_unsigned (frame, 13),
1553 (long) get_frame_register_unsigned (frame, 14),
1554 (long) get_frame_register_unsigned (frame, 15));
1556 printf_filtered
1557 ("FP0-FP7 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
1558 (long) get_frame_register_unsigned
1559 (frame, gdbarch_fp0_regnum (gdbarch) + 0),
1560 (long) get_frame_register_unsigned
1561 (frame, gdbarch_fp0_regnum (gdbarch) + 1),
1562 (long) get_frame_register_unsigned
1563 (frame, gdbarch_fp0_regnum (gdbarch) + 2),
1564 (long) get_frame_register_unsigned
1565 (frame, gdbarch_fp0_regnum (gdbarch) + 3),
1566 (long) get_frame_register_unsigned
1567 (frame, gdbarch_fp0_regnum (gdbarch) + 4),
1568 (long) get_frame_register_unsigned
1569 (frame, gdbarch_fp0_regnum (gdbarch) + 5),
1570 (long) get_frame_register_unsigned
1571 (frame, gdbarch_fp0_regnum (gdbarch) + 6),
1572 (long) get_frame_register_unsigned
1573 (frame, gdbarch_fp0_regnum (gdbarch) + 7));
1574 printf_filtered
1575 ("FP8-FP15 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
1576 (long) get_frame_register_unsigned
1577 (frame, gdbarch_fp0_regnum (gdbarch) + 8),
1578 (long) get_frame_register_unsigned
1579 (frame, gdbarch_fp0_regnum (gdbarch) + 9),
1580 (long) get_frame_register_unsigned
1581 (frame, gdbarch_fp0_regnum (gdbarch) + 10),
1582 (long) get_frame_register_unsigned
1583 (frame, gdbarch_fp0_regnum (gdbarch) + 11),
1584 (long) get_frame_register_unsigned
1585 (frame, gdbarch_fp0_regnum (gdbarch) + 12),
1586 (long) get_frame_register_unsigned
1587 (frame, gdbarch_fp0_regnum (gdbarch) + 13),
1588 (long) get_frame_register_unsigned
1589 (frame, gdbarch_fp0_regnum (gdbarch) + 14),
1590 (long) get_frame_register_unsigned
1591 (frame, gdbarch_fp0_regnum (gdbarch) + 15));
1594 static void
1595 sh2a_show_regs (struct frame_info *frame)
1597 struct gdbarch *gdbarch = get_frame_arch (frame);
1598 int pr = get_frame_register_unsigned (frame, FPSCR_REGNUM) & 0x80000;
1600 printf_filtered
1601 (" PC %s SR %08lx PR %08lx MACH %08lx\n",
1602 phex (get_frame_register_unsigned (frame,
1603 gdbarch_pc_regnum (gdbarch)), 4),
1604 (long) get_frame_register_unsigned (frame, SR_REGNUM),
1605 (long) get_frame_register_unsigned (frame, PR_REGNUM),
1606 (long) get_frame_register_unsigned (frame, MACH_REGNUM));
1608 printf_filtered
1609 (" GBR %08lx VBR %08lx TBR %08lx MACL %08lx\n",
1610 (long) get_frame_register_unsigned (frame, GBR_REGNUM),
1611 (long) get_frame_register_unsigned (frame, VBR_REGNUM),
1612 (long) get_frame_register_unsigned (frame, TBR_REGNUM),
1613 (long) get_frame_register_unsigned (frame, MACL_REGNUM));
1614 printf_filtered
1615 (" SSR %08lx SPC %08lx FPUL %08lx FPSCR %08lx\n",
1616 (long) get_frame_register_unsigned (frame, SSR_REGNUM),
1617 (long) get_frame_register_unsigned (frame, SPC_REGNUM),
1618 (long) get_frame_register_unsigned (frame, FPUL_REGNUM),
1619 (long) get_frame_register_unsigned (frame, FPSCR_REGNUM));
1621 printf_filtered
1622 ("R0-R7 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
1623 (long) get_frame_register_unsigned (frame, 0),
1624 (long) get_frame_register_unsigned (frame, 1),
1625 (long) get_frame_register_unsigned (frame, 2),
1626 (long) get_frame_register_unsigned (frame, 3),
1627 (long) get_frame_register_unsigned (frame, 4),
1628 (long) get_frame_register_unsigned (frame, 5),
1629 (long) get_frame_register_unsigned (frame, 6),
1630 (long) get_frame_register_unsigned (frame, 7));
1631 printf_filtered
1632 ("R8-R15 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
1633 (long) get_frame_register_unsigned (frame, 8),
1634 (long) get_frame_register_unsigned (frame, 9),
1635 (long) get_frame_register_unsigned (frame, 10),
1636 (long) get_frame_register_unsigned (frame, 11),
1637 (long) get_frame_register_unsigned (frame, 12),
1638 (long) get_frame_register_unsigned (frame, 13),
1639 (long) get_frame_register_unsigned (frame, 14),
1640 (long) get_frame_register_unsigned (frame, 15));
1642 printf_filtered
1643 (pr ? "DR0-DR6 %08lx%08lx %08lx%08lx %08lx%08lx %08lx%08lx\n"
1644 : "FP0-FP7 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
1645 (long) get_frame_register_unsigned
1646 (frame, gdbarch_fp0_regnum (gdbarch) + 0),
1647 (long) get_frame_register_unsigned
1648 (frame, gdbarch_fp0_regnum (gdbarch) + 1),
1649 (long) get_frame_register_unsigned
1650 (frame, gdbarch_fp0_regnum (gdbarch) + 2),
1651 (long) get_frame_register_unsigned
1652 (frame, gdbarch_fp0_regnum (gdbarch) + 3),
1653 (long) get_frame_register_unsigned
1654 (frame, gdbarch_fp0_regnum (gdbarch) + 4),
1655 (long) get_frame_register_unsigned
1656 (frame, gdbarch_fp0_regnum (gdbarch) + 5),
1657 (long) get_frame_register_unsigned
1658 (frame, gdbarch_fp0_regnum (gdbarch) + 6),
1659 (long) get_frame_register_unsigned
1660 (frame, gdbarch_fp0_regnum (gdbarch) + 7));
1661 printf_filtered
1662 (pr ? "DR8-DR14 %08lx%08lx %08lx%08lx %08lx%08lx %08lx%08lx\n"
1663 : "FP8-FP15 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
1664 (long) get_frame_register_unsigned
1665 (frame, gdbarch_fp0_regnum (gdbarch) + 8),
1666 (long) get_frame_register_unsigned
1667 (frame, gdbarch_fp0_regnum (gdbarch) + 9),
1668 (long) get_frame_register_unsigned
1669 (frame, gdbarch_fp0_regnum (gdbarch) + 10),
1670 (long) get_frame_register_unsigned
1671 (frame, gdbarch_fp0_regnum (gdbarch) + 11),
1672 (long) get_frame_register_unsigned
1673 (frame, gdbarch_fp0_regnum (gdbarch) + 12),
1674 (long) get_frame_register_unsigned
1675 (frame, gdbarch_fp0_regnum (gdbarch) + 13),
1676 (long) get_frame_register_unsigned
1677 (frame, gdbarch_fp0_regnum (gdbarch) + 14),
1678 (long) get_frame_register_unsigned
1679 (frame, gdbarch_fp0_regnum (gdbarch) + 15));
1680 printf_filtered
1681 ("BANK=%-3d\n", (int) get_frame_register_unsigned (frame, BANK_REGNUM));
1682 printf_filtered
1683 ("R0b-R7b %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
1684 (long) get_frame_register_unsigned (frame, R0_BANK0_REGNUM + 0),
1685 (long) get_frame_register_unsigned (frame, R0_BANK0_REGNUM + 1),
1686 (long) get_frame_register_unsigned (frame, R0_BANK0_REGNUM + 2),
1687 (long) get_frame_register_unsigned (frame, R0_BANK0_REGNUM + 3),
1688 (long) get_frame_register_unsigned (frame, R0_BANK0_REGNUM + 4),
1689 (long) get_frame_register_unsigned (frame, R0_BANK0_REGNUM + 5),
1690 (long) get_frame_register_unsigned (frame, R0_BANK0_REGNUM + 6),
1691 (long) get_frame_register_unsigned (frame, R0_BANK0_REGNUM + 7));
1692 printf_filtered
1693 ("R8b-R14b %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
1694 (long) get_frame_register_unsigned (frame, R0_BANK0_REGNUM + 8),
1695 (long) get_frame_register_unsigned (frame, R0_BANK0_REGNUM + 9),
1696 (long) get_frame_register_unsigned (frame, R0_BANK0_REGNUM + 10),
1697 (long) get_frame_register_unsigned (frame, R0_BANK0_REGNUM + 11),
1698 (long) get_frame_register_unsigned (frame, R0_BANK0_REGNUM + 12),
1699 (long) get_frame_register_unsigned (frame, R0_BANK0_REGNUM + 13),
1700 (long) get_frame_register_unsigned (frame, R0_BANK0_REGNUM + 14));
1701 printf_filtered
1702 ("MACHb=%08lx IVNb=%08lx PRb=%08lx GBRb=%08lx MACLb=%08lx\n",
1703 (long) get_frame_register_unsigned (frame, R0_BANK0_REGNUM + 15),
1704 (long) get_frame_register_unsigned (frame, R0_BANK0_REGNUM + 16),
1705 (long) get_frame_register_unsigned (frame, R0_BANK0_REGNUM + 17),
1706 (long) get_frame_register_unsigned (frame, R0_BANK0_REGNUM + 18),
1707 (long) get_frame_register_unsigned (frame, R0_BANK0_REGNUM + 19));
1710 static void
1711 sh2a_nofpu_show_regs (struct frame_info *frame)
1713 int pr = get_frame_register_unsigned (frame, FPSCR_REGNUM) & 0x80000;
1715 printf_filtered
1716 (" PC %s SR %08lx PR %08lx MACH %08lx\n",
1717 phex (get_frame_register_unsigned (frame,
1718 gdbarch_pc_regnum
1719 (get_frame_arch (frame))), 4),
1720 (long) get_frame_register_unsigned (frame, SR_REGNUM),
1721 (long) get_frame_register_unsigned (frame, PR_REGNUM),
1722 (long) get_frame_register_unsigned (frame, MACH_REGNUM));
1724 printf_filtered
1725 (" GBR %08lx VBR %08lx TBR %08lx MACL %08lx\n",
1726 (long) get_frame_register_unsigned (frame, GBR_REGNUM),
1727 (long) get_frame_register_unsigned (frame, VBR_REGNUM),
1728 (long) get_frame_register_unsigned (frame, TBR_REGNUM),
1729 (long) get_frame_register_unsigned (frame, MACL_REGNUM));
1730 printf_filtered
1731 (" SSR %08lx SPC %08lx FPUL %08lx FPSCR %08lx\n",
1732 (long) get_frame_register_unsigned (frame, SSR_REGNUM),
1733 (long) get_frame_register_unsigned (frame, SPC_REGNUM),
1734 (long) get_frame_register_unsigned (frame, FPUL_REGNUM),
1735 (long) get_frame_register_unsigned (frame, FPSCR_REGNUM));
1737 printf_filtered
1738 ("R0-R7 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
1739 (long) get_frame_register_unsigned (frame, 0),
1740 (long) get_frame_register_unsigned (frame, 1),
1741 (long) get_frame_register_unsigned (frame, 2),
1742 (long) get_frame_register_unsigned (frame, 3),
1743 (long) get_frame_register_unsigned (frame, 4),
1744 (long) get_frame_register_unsigned (frame, 5),
1745 (long) get_frame_register_unsigned (frame, 6),
1746 (long) get_frame_register_unsigned (frame, 7));
1747 printf_filtered
1748 ("R8-R15 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
1749 (long) get_frame_register_unsigned (frame, 8),
1750 (long) get_frame_register_unsigned (frame, 9),
1751 (long) get_frame_register_unsigned (frame, 10),
1752 (long) get_frame_register_unsigned (frame, 11),
1753 (long) get_frame_register_unsigned (frame, 12),
1754 (long) get_frame_register_unsigned (frame, 13),
1755 (long) get_frame_register_unsigned (frame, 14),
1756 (long) get_frame_register_unsigned (frame, 15));
1758 printf_filtered
1759 ("BANK=%-3d\n", (int) get_frame_register_unsigned (frame, BANK_REGNUM));
1760 printf_filtered
1761 ("R0b-R7b %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
1762 (long) get_frame_register_unsigned (frame, R0_BANK0_REGNUM + 0),
1763 (long) get_frame_register_unsigned (frame, R0_BANK0_REGNUM + 1),
1764 (long) get_frame_register_unsigned (frame, R0_BANK0_REGNUM + 2),
1765 (long) get_frame_register_unsigned (frame, R0_BANK0_REGNUM + 3),
1766 (long) get_frame_register_unsigned (frame, R0_BANK0_REGNUM + 4),
1767 (long) get_frame_register_unsigned (frame, R0_BANK0_REGNUM + 5),
1768 (long) get_frame_register_unsigned (frame, R0_BANK0_REGNUM + 6),
1769 (long) get_frame_register_unsigned (frame, R0_BANK0_REGNUM + 7));
1770 printf_filtered
1771 ("R8b-R14b %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
1772 (long) get_frame_register_unsigned (frame, R0_BANK0_REGNUM + 8),
1773 (long) get_frame_register_unsigned (frame, R0_BANK0_REGNUM + 9),
1774 (long) get_frame_register_unsigned (frame, R0_BANK0_REGNUM + 10),
1775 (long) get_frame_register_unsigned (frame, R0_BANK0_REGNUM + 11),
1776 (long) get_frame_register_unsigned (frame, R0_BANK0_REGNUM + 12),
1777 (long) get_frame_register_unsigned (frame, R0_BANK0_REGNUM + 13),
1778 (long) get_frame_register_unsigned (frame, R0_BANK0_REGNUM + 14));
1779 printf_filtered
1780 ("MACHb=%08lx IVNb=%08lx PRb=%08lx GBRb=%08lx MACLb=%08lx\n",
1781 (long) get_frame_register_unsigned (frame, R0_BANK0_REGNUM + 15),
1782 (long) get_frame_register_unsigned (frame, R0_BANK0_REGNUM + 16),
1783 (long) get_frame_register_unsigned (frame, R0_BANK0_REGNUM + 17),
1784 (long) get_frame_register_unsigned (frame, R0_BANK0_REGNUM + 18),
1785 (long) get_frame_register_unsigned (frame, R0_BANK0_REGNUM + 19));
1788 static void
1789 sh3e_show_regs (struct frame_info *frame)
1791 struct gdbarch *gdbarch = get_frame_arch (frame);
1792 printf_filtered
1793 (" PC %s SR %08lx PR %08lx MACH %08lx\n",
1794 phex (get_frame_register_unsigned (frame,
1795 gdbarch_pc_regnum (gdbarch)), 4),
1796 (long) get_frame_register_unsigned (frame, SR_REGNUM),
1797 (long) get_frame_register_unsigned (frame, PR_REGNUM),
1798 (long) get_frame_register_unsigned (frame, MACH_REGNUM));
1800 printf_filtered
1801 (" GBR %08lx VBR %08lx MACL %08lx\n",
1802 (long) get_frame_register_unsigned (frame, GBR_REGNUM),
1803 (long) get_frame_register_unsigned (frame, VBR_REGNUM),
1804 (long) get_frame_register_unsigned (frame, MACL_REGNUM));
1805 printf_filtered
1806 (" SSR %08lx SPC %08lx FPUL %08lx FPSCR %08lx\n",
1807 (long) get_frame_register_unsigned (frame, SSR_REGNUM),
1808 (long) get_frame_register_unsigned (frame, SPC_REGNUM),
1809 (long) get_frame_register_unsigned (frame, FPUL_REGNUM),
1810 (long) get_frame_register_unsigned (frame, FPSCR_REGNUM));
1812 printf_filtered
1813 ("R0-R7 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
1814 (long) get_frame_register_unsigned (frame, 0),
1815 (long) get_frame_register_unsigned (frame, 1),
1816 (long) get_frame_register_unsigned (frame, 2),
1817 (long) get_frame_register_unsigned (frame, 3),
1818 (long) get_frame_register_unsigned (frame, 4),
1819 (long) get_frame_register_unsigned (frame, 5),
1820 (long) get_frame_register_unsigned (frame, 6),
1821 (long) get_frame_register_unsigned (frame, 7));
1822 printf_filtered
1823 ("R8-R15 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
1824 (long) get_frame_register_unsigned (frame, 8),
1825 (long) get_frame_register_unsigned (frame, 9),
1826 (long) get_frame_register_unsigned (frame, 10),
1827 (long) get_frame_register_unsigned (frame, 11),
1828 (long) get_frame_register_unsigned (frame, 12),
1829 (long) get_frame_register_unsigned (frame, 13),
1830 (long) get_frame_register_unsigned (frame, 14),
1831 (long) get_frame_register_unsigned (frame, 15));
1833 printf_filtered
1834 ("FP0-FP7 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
1835 (long) get_frame_register_unsigned
1836 (frame, gdbarch_fp0_regnum (gdbarch) + 0),
1837 (long) get_frame_register_unsigned
1838 (frame, gdbarch_fp0_regnum (gdbarch) + 1),
1839 (long) get_frame_register_unsigned
1840 (frame, gdbarch_fp0_regnum (gdbarch) + 2),
1841 (long) get_frame_register_unsigned
1842 (frame, gdbarch_fp0_regnum (gdbarch) + 3),
1843 (long) get_frame_register_unsigned
1844 (frame, gdbarch_fp0_regnum (gdbarch) + 4),
1845 (long) get_frame_register_unsigned
1846 (frame, gdbarch_fp0_regnum (gdbarch) + 5),
1847 (long) get_frame_register_unsigned
1848 (frame, gdbarch_fp0_regnum (gdbarch) + 6),
1849 (long) get_frame_register_unsigned
1850 (frame, gdbarch_fp0_regnum (gdbarch) + 7));
1851 printf_filtered
1852 ("FP8-FP15 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
1853 (long) get_frame_register_unsigned
1854 (frame, gdbarch_fp0_regnum (gdbarch) + 8),
1855 (long) get_frame_register_unsigned
1856 (frame, gdbarch_fp0_regnum (gdbarch) + 9),
1857 (long) get_frame_register_unsigned
1858 (frame, gdbarch_fp0_regnum (gdbarch) + 10),
1859 (long) get_frame_register_unsigned
1860 (frame, gdbarch_fp0_regnum (gdbarch) + 11),
1861 (long) get_frame_register_unsigned
1862 (frame, gdbarch_fp0_regnum (gdbarch) + 12),
1863 (long) get_frame_register_unsigned
1864 (frame, gdbarch_fp0_regnum (gdbarch) + 13),
1865 (long) get_frame_register_unsigned
1866 (frame, gdbarch_fp0_regnum (gdbarch) + 14),
1867 (long) get_frame_register_unsigned
1868 (frame, gdbarch_fp0_regnum (gdbarch) + 15));
1871 static void
1872 sh3_dsp_show_regs (struct frame_info *frame)
1874 printf_filtered
1875 (" PC %s SR %08lx PR %08lx MACH %08lx\n",
1876 phex (get_frame_register_unsigned (frame,
1877 gdbarch_pc_regnum
1878 (get_frame_arch (frame))), 4),
1879 (long) get_frame_register_unsigned (frame, SR_REGNUM),
1880 (long) get_frame_register_unsigned (frame, PR_REGNUM),
1881 (long) get_frame_register_unsigned (frame, MACH_REGNUM));
1883 printf_filtered
1884 (" GBR %08lx VBR %08lx MACL %08lx\n",
1885 (long) get_frame_register_unsigned (frame, GBR_REGNUM),
1886 (long) get_frame_register_unsigned (frame, VBR_REGNUM),
1887 (long) get_frame_register_unsigned (frame, MACL_REGNUM));
1889 printf_filtered
1890 (" SSR %08lx SPC %08lx DSR %08lx\n",
1891 (long) get_frame_register_unsigned (frame, SSR_REGNUM),
1892 (long) get_frame_register_unsigned (frame, SPC_REGNUM),
1893 (long) get_frame_register_unsigned (frame, DSR_REGNUM));
1895 printf_filtered
1896 ("R0-R7 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
1897 (long) get_frame_register_unsigned (frame, 0),
1898 (long) get_frame_register_unsigned (frame, 1),
1899 (long) get_frame_register_unsigned (frame, 2),
1900 (long) get_frame_register_unsigned (frame, 3),
1901 (long) get_frame_register_unsigned (frame, 4),
1902 (long) get_frame_register_unsigned (frame, 5),
1903 (long) get_frame_register_unsigned (frame, 6),
1904 (long) get_frame_register_unsigned (frame, 7));
1905 printf_filtered
1906 ("R8-R15 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
1907 (long) get_frame_register_unsigned (frame, 8),
1908 (long) get_frame_register_unsigned (frame, 9),
1909 (long) get_frame_register_unsigned (frame, 10),
1910 (long) get_frame_register_unsigned (frame, 11),
1911 (long) get_frame_register_unsigned (frame, 12),
1912 (long) get_frame_register_unsigned (frame, 13),
1913 (long) get_frame_register_unsigned (frame, 14),
1914 (long) get_frame_register_unsigned (frame, 15));
1916 printf_filtered
1917 ("A0G=%02lx A0=%08lx M0=%08lx X0=%08lx Y0=%08lx RS=%08lx MOD=%08lx\n",
1918 (long) get_frame_register_unsigned (frame, A0G_REGNUM) & 0xff,
1919 (long) get_frame_register_unsigned (frame, A0_REGNUM),
1920 (long) get_frame_register_unsigned (frame, M0_REGNUM),
1921 (long) get_frame_register_unsigned (frame, X0_REGNUM),
1922 (long) get_frame_register_unsigned (frame, Y0_REGNUM),
1923 (long) get_frame_register_unsigned (frame, RS_REGNUM),
1924 (long) get_frame_register_unsigned (frame, MOD_REGNUM));
1925 printf_filtered
1926 ("A1G=%02lx A1=%08lx M1=%08lx X1=%08lx Y1=%08lx RE=%08lx\n",
1927 (long) get_frame_register_unsigned (frame, A1G_REGNUM) & 0xff,
1928 (long) get_frame_register_unsigned (frame, A1_REGNUM),
1929 (long) get_frame_register_unsigned (frame, M1_REGNUM),
1930 (long) get_frame_register_unsigned (frame, X1_REGNUM),
1931 (long) get_frame_register_unsigned (frame, Y1_REGNUM),
1932 (long) get_frame_register_unsigned (frame, RE_REGNUM));
1935 static void
1936 sh4_show_regs (struct frame_info *frame)
1938 struct gdbarch *gdbarch = get_frame_arch (frame);
1939 int pr = get_frame_register_unsigned (frame, FPSCR_REGNUM) & 0x80000;
1941 printf_filtered
1942 (" PC %s SR %08lx PR %08lx MACH %08lx\n",
1943 phex (get_frame_register_unsigned (frame,
1944 gdbarch_pc_regnum (gdbarch)), 4),
1945 (long) get_frame_register_unsigned (frame, SR_REGNUM),
1946 (long) get_frame_register_unsigned (frame, PR_REGNUM),
1947 (long) get_frame_register_unsigned (frame, MACH_REGNUM));
1949 printf_filtered
1950 (" GBR %08lx VBR %08lx MACL %08lx\n",
1951 (long) get_frame_register_unsigned (frame, GBR_REGNUM),
1952 (long) get_frame_register_unsigned (frame, VBR_REGNUM),
1953 (long) get_frame_register_unsigned (frame, MACL_REGNUM));
1954 printf_filtered
1955 (" SSR %08lx SPC %08lx FPUL %08lx FPSCR %08lx\n",
1956 (long) get_frame_register_unsigned (frame, SSR_REGNUM),
1957 (long) get_frame_register_unsigned (frame, SPC_REGNUM),
1958 (long) get_frame_register_unsigned (frame, FPUL_REGNUM),
1959 (long) get_frame_register_unsigned (frame, FPSCR_REGNUM));
1961 printf_filtered
1962 ("R0-R7 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
1963 (long) get_frame_register_unsigned (frame, 0),
1964 (long) get_frame_register_unsigned (frame, 1),
1965 (long) get_frame_register_unsigned (frame, 2),
1966 (long) get_frame_register_unsigned (frame, 3),
1967 (long) get_frame_register_unsigned (frame, 4),
1968 (long) get_frame_register_unsigned (frame, 5),
1969 (long) get_frame_register_unsigned (frame, 6),
1970 (long) get_frame_register_unsigned (frame, 7));
1971 printf_filtered
1972 ("R8-R15 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
1973 (long) get_frame_register_unsigned (frame, 8),
1974 (long) get_frame_register_unsigned (frame, 9),
1975 (long) get_frame_register_unsigned (frame, 10),
1976 (long) get_frame_register_unsigned (frame, 11),
1977 (long) get_frame_register_unsigned (frame, 12),
1978 (long) get_frame_register_unsigned (frame, 13),
1979 (long) get_frame_register_unsigned (frame, 14),
1980 (long) get_frame_register_unsigned (frame, 15));
1982 printf_filtered
1983 (pr ? "DR0-DR6 %08lx%08lx %08lx%08lx %08lx%08lx %08lx%08lx\n"
1984 : "FP0-FP7 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
1985 (long) get_frame_register_unsigned
1986 (frame, gdbarch_fp0_regnum (gdbarch) + 0),
1987 (long) get_frame_register_unsigned
1988 (frame, gdbarch_fp0_regnum (gdbarch) + 1),
1989 (long) get_frame_register_unsigned
1990 (frame, gdbarch_fp0_regnum (gdbarch) + 2),
1991 (long) get_frame_register_unsigned
1992 (frame, gdbarch_fp0_regnum (gdbarch) + 3),
1993 (long) get_frame_register_unsigned
1994 (frame, gdbarch_fp0_regnum (gdbarch) + 4),
1995 (long) get_frame_register_unsigned
1996 (frame, gdbarch_fp0_regnum (gdbarch) + 5),
1997 (long) get_frame_register_unsigned
1998 (frame, gdbarch_fp0_regnum (gdbarch) + 6),
1999 (long) get_frame_register_unsigned
2000 (frame, gdbarch_fp0_regnum (gdbarch) + 7));
2001 printf_filtered
2002 (pr ? "DR8-DR14 %08lx%08lx %08lx%08lx %08lx%08lx %08lx%08lx\n"
2003 : "FP8-FP15 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
2004 (long) get_frame_register_unsigned
2005 (frame, gdbarch_fp0_regnum (gdbarch) + 8),
2006 (long) get_frame_register_unsigned
2007 (frame, gdbarch_fp0_regnum (gdbarch) + 9),
2008 (long) get_frame_register_unsigned
2009 (frame, gdbarch_fp0_regnum (gdbarch) + 10),
2010 (long) get_frame_register_unsigned
2011 (frame, gdbarch_fp0_regnum (gdbarch) + 11),
2012 (long) get_frame_register_unsigned
2013 (frame, gdbarch_fp0_regnum (gdbarch) + 12),
2014 (long) get_frame_register_unsigned
2015 (frame, gdbarch_fp0_regnum (gdbarch) + 13),
2016 (long) get_frame_register_unsigned
2017 (frame, gdbarch_fp0_regnum (gdbarch) + 14),
2018 (long) get_frame_register_unsigned
2019 (frame, gdbarch_fp0_regnum (gdbarch) + 15));
2022 static void
2023 sh4_nofpu_show_regs (struct frame_info *frame)
2025 printf_filtered
2026 (" PC %s SR %08lx PR %08lx MACH %08lx\n",
2027 phex (get_frame_register_unsigned (frame,
2028 gdbarch_pc_regnum
2029 (get_frame_arch (frame))), 4),
2030 (long) get_frame_register_unsigned (frame, SR_REGNUM),
2031 (long) get_frame_register_unsigned (frame, PR_REGNUM),
2032 (long) get_frame_register_unsigned (frame, MACH_REGNUM));
2034 printf_filtered
2035 (" GBR %08lx VBR %08lx MACL %08lx\n",
2036 (long) get_frame_register_unsigned (frame, GBR_REGNUM),
2037 (long) get_frame_register_unsigned (frame, VBR_REGNUM),
2038 (long) get_frame_register_unsigned (frame, MACL_REGNUM));
2039 printf_filtered
2040 (" SSR %08lx SPC %08lx FPUL %08lx FPSCR %08lx\n",
2041 (long) get_frame_register_unsigned (frame, SSR_REGNUM),
2042 (long) get_frame_register_unsigned (frame, SPC_REGNUM),
2043 (long) get_frame_register_unsigned (frame, FPUL_REGNUM),
2044 (long) get_frame_register_unsigned (frame, FPSCR_REGNUM));
2046 printf_filtered
2047 ("R0-R7 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
2048 (long) get_frame_register_unsigned (frame, 0),
2049 (long) get_frame_register_unsigned (frame, 1),
2050 (long) get_frame_register_unsigned (frame, 2),
2051 (long) get_frame_register_unsigned (frame, 3),
2052 (long) get_frame_register_unsigned (frame, 4),
2053 (long) get_frame_register_unsigned (frame, 5),
2054 (long) get_frame_register_unsigned (frame, 6),
2055 (long) get_frame_register_unsigned (frame, 7));
2056 printf_filtered
2057 ("R8-R15 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
2058 (long) get_frame_register_unsigned (frame, 8),
2059 (long) get_frame_register_unsigned (frame, 9),
2060 (long) get_frame_register_unsigned (frame, 10),
2061 (long) get_frame_register_unsigned (frame, 11),
2062 (long) get_frame_register_unsigned (frame, 12),
2063 (long) get_frame_register_unsigned (frame, 13),
2064 (long) get_frame_register_unsigned (frame, 14),
2065 (long) get_frame_register_unsigned (frame, 15));
2068 static void
2069 sh_dsp_show_regs (struct frame_info *frame)
2071 printf_filtered
2072 (" PC %s SR %08lx PR %08lx MACH %08lx\n",
2073 phex (get_frame_register_unsigned (frame,
2074 gdbarch_pc_regnum
2075 (get_frame_arch (frame))), 4),
2076 (long) get_frame_register_unsigned (frame, SR_REGNUM),
2077 (long) get_frame_register_unsigned (frame, PR_REGNUM),
2078 (long) get_frame_register_unsigned (frame, MACH_REGNUM));
2080 printf_filtered
2081 (" GBR %08lx VBR %08lx DSR %08lx MACL %08lx\n",
2082 (long) get_frame_register_unsigned (frame, GBR_REGNUM),
2083 (long) get_frame_register_unsigned (frame, VBR_REGNUM),
2084 (long) get_frame_register_unsigned (frame, DSR_REGNUM),
2085 (long) get_frame_register_unsigned (frame, MACL_REGNUM));
2087 printf_filtered
2088 ("R0-R7 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
2089 (long) get_frame_register_unsigned (frame, 0),
2090 (long) get_frame_register_unsigned (frame, 1),
2091 (long) get_frame_register_unsigned (frame, 2),
2092 (long) get_frame_register_unsigned (frame, 3),
2093 (long) get_frame_register_unsigned (frame, 4),
2094 (long) get_frame_register_unsigned (frame, 5),
2095 (long) get_frame_register_unsigned (frame, 6),
2096 (long) get_frame_register_unsigned (frame, 7));
2097 printf_filtered
2098 ("R8-R15 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
2099 (long) get_frame_register_unsigned (frame, 8),
2100 (long) get_frame_register_unsigned (frame, 9),
2101 (long) get_frame_register_unsigned (frame, 10),
2102 (long) get_frame_register_unsigned (frame, 11),
2103 (long) get_frame_register_unsigned (frame, 12),
2104 (long) get_frame_register_unsigned (frame, 13),
2105 (long) get_frame_register_unsigned (frame, 14),
2106 (long) get_frame_register_unsigned (frame, 15));
2108 printf_filtered
2109 ("A0G=%02lx A0=%08lx M0=%08lx X0=%08lx Y0=%08lx RS=%08lx MOD=%08lx\n",
2110 (long) get_frame_register_unsigned (frame, A0G_REGNUM) & 0xff,
2111 (long) get_frame_register_unsigned (frame, A0_REGNUM),
2112 (long) get_frame_register_unsigned (frame, M0_REGNUM),
2113 (long) get_frame_register_unsigned (frame, X0_REGNUM),
2114 (long) get_frame_register_unsigned (frame, Y0_REGNUM),
2115 (long) get_frame_register_unsigned (frame, RS_REGNUM),
2116 (long) get_frame_register_unsigned (frame, MOD_REGNUM));
2117 printf_filtered ("A1G=%02lx A1=%08lx M1=%08lx X1=%08lx Y1=%08lx RE=%08lx\n",
2118 (long) get_frame_register_unsigned (frame, A1G_REGNUM) & 0xff,
2119 (long) get_frame_register_unsigned (frame, A1_REGNUM),
2120 (long) get_frame_register_unsigned (frame, M1_REGNUM),
2121 (long) get_frame_register_unsigned (frame, X1_REGNUM),
2122 (long) get_frame_register_unsigned (frame, Y1_REGNUM),
2123 (long) get_frame_register_unsigned (frame, RE_REGNUM));
2126 static void
2127 sh_show_regs_command (char *args, int from_tty)
2129 if (sh_show_regs)
2130 (*sh_show_regs) (get_current_frame ());
2133 static struct type *
2134 sh_sh2a_register_type (struct gdbarch *gdbarch, int reg_nr)
2136 if ((reg_nr >= gdbarch_fp0_regnum (gdbarch)
2137 && (reg_nr <= FP_LAST_REGNUM)) || (reg_nr == FPUL_REGNUM))
2138 return builtin_type (gdbarch)->builtin_float;
2139 else if (reg_nr >= DR0_REGNUM && reg_nr <= DR_LAST_REGNUM)
2140 return builtin_type (gdbarch)->builtin_double;
2141 else
2142 return builtin_type (gdbarch)->builtin_int;
2145 /* Return the GDB type object for the "standard" data type
2146 of data in register N. */
2147 static struct type *
2148 sh_sh3e_register_type (struct gdbarch *gdbarch, int reg_nr)
2150 if ((reg_nr >= gdbarch_fp0_regnum (gdbarch)
2151 && (reg_nr <= FP_LAST_REGNUM)) || (reg_nr == FPUL_REGNUM))
2152 return builtin_type (gdbarch)->builtin_float;
2153 else
2154 return builtin_type (gdbarch)->builtin_int;
2157 static struct type *
2158 sh_sh4_build_float_register_type (struct gdbarch *gdbarch, int high)
2160 return lookup_array_range_type (builtin_type (gdbarch)->builtin_float,
2161 0, high);
2164 static struct type *
2165 sh_sh4_register_type (struct gdbarch *gdbarch, int reg_nr)
2167 if ((reg_nr >= gdbarch_fp0_regnum (gdbarch)
2168 && (reg_nr <= FP_LAST_REGNUM)) || (reg_nr == FPUL_REGNUM))
2169 return builtin_type (gdbarch)->builtin_float;
2170 else if (reg_nr >= DR0_REGNUM && reg_nr <= DR_LAST_REGNUM)
2171 return builtin_type (gdbarch)->builtin_double;
2172 else if (reg_nr >= FV0_REGNUM && reg_nr <= FV_LAST_REGNUM)
2173 return sh_sh4_build_float_register_type (gdbarch, 3);
2174 else
2175 return builtin_type (gdbarch)->builtin_int;
2178 static struct type *
2179 sh_default_register_type (struct gdbarch *gdbarch, int reg_nr)
2181 return builtin_type (gdbarch)->builtin_int;
2184 /* Is a register in a reggroup?
2185 The default code in reggroup.c doesn't identify system registers, some
2186 float registers or any of the vector registers.
2187 TODO: sh2a and dsp registers. */
2188 static int
2189 sh_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
2190 struct reggroup *reggroup)
2192 if (gdbarch_register_name (gdbarch, regnum) == NULL
2193 || *gdbarch_register_name (gdbarch, regnum) == '\0')
2194 return 0;
2196 if (reggroup == float_reggroup
2197 && (regnum == FPUL_REGNUM
2198 || regnum == FPSCR_REGNUM))
2199 return 1;
2201 if (regnum >= FV0_REGNUM && regnum <= FV_LAST_REGNUM)
2203 if (reggroup == vector_reggroup || reggroup == float_reggroup)
2204 return 1;
2205 if (reggroup == general_reggroup)
2206 return 0;
2209 if (regnum == VBR_REGNUM
2210 || regnum == SR_REGNUM
2211 || regnum == FPSCR_REGNUM
2212 || regnum == SSR_REGNUM
2213 || regnum == SPC_REGNUM)
2215 if (reggroup == system_reggroup)
2216 return 1;
2217 if (reggroup == general_reggroup)
2218 return 0;
2221 /* The default code can cope with any other registers. */
2222 return default_register_reggroup_p (gdbarch, regnum, reggroup);
2225 /* On the sh4, the DRi pseudo registers are problematic if the target
2226 is little endian. When the user writes one of those registers, for
2227 instance with 'ser var $dr0=1', we want the double to be stored
2228 like this:
2229 fr0 = 0x00 0x00 0x00 0x00 0x00 0xf0 0x3f
2230 fr1 = 0x00 0x00 0x00 0x00 0x00 0x00 0x00
2232 This corresponds to little endian byte order & big endian word
2233 order. However if we let gdb write the register w/o conversion, it
2234 will write fr0 and fr1 this way:
2235 fr0 = 0x00 0x00 0x00 0x00 0x00 0x00 0x00
2236 fr1 = 0x00 0x00 0x00 0x00 0x00 0xf0 0x3f
2237 because it will consider fr0 and fr1 as a single LE stretch of memory.
2239 To achieve what we want we must force gdb to store things in
2240 floatformat_ieee_double_littlebyte_bigword (which is defined in
2241 include/floatformat.h and libiberty/floatformat.c.
2243 In case the target is big endian, there is no problem, the
2244 raw bytes will look like:
2245 fr0 = 0x3f 0xf0 0x00 0x00 0x00 0x00 0x00
2246 fr1 = 0x00 0x00 0x00 0x00 0x00 0x00 0x00
2248 The other pseudo registers (the FVs) also don't pose a problem
2249 because they are stored as 4 individual FP elements. */
2251 static void
2252 sh_register_convert_to_virtual (int regnum, struct type *type,
2253 char *from, char *to)
2255 if (regnum >= DR0_REGNUM && regnum <= DR_LAST_REGNUM)
2257 DOUBLEST val;
2258 floatformat_to_doublest (&floatformat_ieee_double_littlebyte_bigword,
2259 from, &val);
2260 store_typed_floating (to, type, val);
2262 else
2263 error
2264 ("sh_register_convert_to_virtual called with non DR register number");
2267 static void
2268 sh_register_convert_to_raw (struct type *type, int regnum,
2269 const void *from, void *to)
2271 if (regnum >= DR0_REGNUM && regnum <= DR_LAST_REGNUM)
2273 DOUBLEST val = extract_typed_floating (from, type);
2274 floatformat_from_doublest (&floatformat_ieee_double_littlebyte_bigword,
2275 &val, to);
2277 else
2278 error (_("sh_register_convert_to_raw called with non DR register number"));
2281 /* For vectors of 4 floating point registers. */
2282 static int
2283 fv_reg_base_num (struct gdbarch *gdbarch, int fv_regnum)
2285 int fp_regnum;
2287 fp_regnum = gdbarch_fp0_regnum (gdbarch)
2288 + (fv_regnum - FV0_REGNUM) * 4;
2289 return fp_regnum;
2292 /* For double precision floating point registers, i.e 2 fp regs.*/
2293 static int
2294 dr_reg_base_num (struct gdbarch *gdbarch, int dr_regnum)
2296 int fp_regnum;
2298 fp_regnum = gdbarch_fp0_regnum (gdbarch)
2299 + (dr_regnum - DR0_REGNUM) * 2;
2300 return fp_regnum;
2303 static void
2304 sh_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache,
2305 int reg_nr, gdb_byte *buffer)
2307 int base_regnum, portion;
2308 char temp_buffer[MAX_REGISTER_SIZE];
2310 if (reg_nr == PSEUDO_BANK_REGNUM)
2311 regcache_raw_read (regcache, BANK_REGNUM, buffer);
2312 else
2313 if (reg_nr >= DR0_REGNUM && reg_nr <= DR_LAST_REGNUM)
2315 base_regnum = dr_reg_base_num (gdbarch, reg_nr);
2317 /* Build the value in the provided buffer. */
2318 /* Read the real regs for which this one is an alias. */
2319 for (portion = 0; portion < 2; portion++)
2320 regcache_raw_read (regcache, base_regnum + portion,
2321 (temp_buffer
2322 + register_size (gdbarch,
2323 base_regnum) * portion));
2324 /* We must pay attention to the endiannes. */
2325 sh_register_convert_to_virtual (reg_nr,
2326 register_type (gdbarch, reg_nr),
2327 temp_buffer, buffer);
2329 else if (reg_nr >= FV0_REGNUM && reg_nr <= FV_LAST_REGNUM)
2331 base_regnum = fv_reg_base_num (gdbarch, reg_nr);
2333 /* Read the real regs for which this one is an alias. */
2334 for (portion = 0; portion < 4; portion++)
2335 regcache_raw_read (regcache, base_regnum + portion,
2336 ((char *) buffer
2337 + register_size (gdbarch,
2338 base_regnum) * portion));
2342 static void
2343 sh_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
2344 int reg_nr, const gdb_byte *buffer)
2346 int base_regnum, portion;
2347 char temp_buffer[MAX_REGISTER_SIZE];
2349 if (reg_nr == PSEUDO_BANK_REGNUM)
2351 /* When the bank register is written to, the whole register bank
2352 is switched and all values in the bank registers must be read
2353 from the target/sim again. We're just invalidating the regcache
2354 so that a re-read happens next time it's necessary. */
2355 int bregnum;
2357 regcache_raw_write (regcache, BANK_REGNUM, buffer);
2358 for (bregnum = R0_BANK0_REGNUM; bregnum < MACLB_REGNUM; ++bregnum)
2359 regcache_invalidate (regcache, bregnum);
2361 else if (reg_nr >= DR0_REGNUM && reg_nr <= DR_LAST_REGNUM)
2363 base_regnum = dr_reg_base_num (gdbarch, reg_nr);
2365 /* We must pay attention to the endiannes. */
2366 sh_register_convert_to_raw (register_type (gdbarch, reg_nr),
2367 reg_nr, buffer, temp_buffer);
2369 /* Write the real regs for which this one is an alias. */
2370 for (portion = 0; portion < 2; portion++)
2371 regcache_raw_write (regcache, base_regnum + portion,
2372 (temp_buffer
2373 + register_size (gdbarch,
2374 base_regnum) * portion));
2376 else if (reg_nr >= FV0_REGNUM && reg_nr <= FV_LAST_REGNUM)
2378 base_regnum = fv_reg_base_num (gdbarch, reg_nr);
2380 /* Write the real regs for which this one is an alias. */
2381 for (portion = 0; portion < 4; portion++)
2382 regcache_raw_write (regcache, base_regnum + portion,
2383 ((char *) buffer
2384 + register_size (gdbarch,
2385 base_regnum) * portion));
2389 static int
2390 sh_dsp_register_sim_regno (struct gdbarch *gdbarch, int nr)
2392 if (legacy_register_sim_regno (gdbarch, nr) < 0)
2393 return legacy_register_sim_regno (gdbarch, nr);
2394 if (nr >= DSR_REGNUM && nr <= Y1_REGNUM)
2395 return nr - DSR_REGNUM + SIM_SH_DSR_REGNUM;
2396 if (nr == MOD_REGNUM)
2397 return SIM_SH_MOD_REGNUM;
2398 if (nr == RS_REGNUM)
2399 return SIM_SH_RS_REGNUM;
2400 if (nr == RE_REGNUM)
2401 return SIM_SH_RE_REGNUM;
2402 if (nr >= DSP_R0_BANK_REGNUM && nr <= DSP_R7_BANK_REGNUM)
2403 return nr - DSP_R0_BANK_REGNUM + SIM_SH_R0_BANK_REGNUM;
2404 return nr;
2407 static int
2408 sh_sh2a_register_sim_regno (struct gdbarch *gdbarch, int nr)
2410 switch (nr)
2412 case TBR_REGNUM:
2413 return SIM_SH_TBR_REGNUM;
2414 case IBNR_REGNUM:
2415 return SIM_SH_IBNR_REGNUM;
2416 case IBCR_REGNUM:
2417 return SIM_SH_IBCR_REGNUM;
2418 case BANK_REGNUM:
2419 return SIM_SH_BANK_REGNUM;
2420 case MACLB_REGNUM:
2421 return SIM_SH_BANK_MACL_REGNUM;
2422 case GBRB_REGNUM:
2423 return SIM_SH_BANK_GBR_REGNUM;
2424 case PRB_REGNUM:
2425 return SIM_SH_BANK_PR_REGNUM;
2426 case IVNB_REGNUM:
2427 return SIM_SH_BANK_IVN_REGNUM;
2428 case MACHB_REGNUM:
2429 return SIM_SH_BANK_MACH_REGNUM;
2430 default:
2431 break;
2433 return legacy_register_sim_regno (gdbarch, nr);
2436 /* Set up the register unwinding such that call-clobbered registers are
2437 not displayed in frames >0 because the true value is not certain.
2438 The 'undefined' registers will show up as 'not available' unless the
2439 CFI says otherwise.
2441 This function is currently set up for SH4 and compatible only. */
2443 static void
2444 sh_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum,
2445 struct dwarf2_frame_state_reg *reg,
2446 struct frame_info *this_frame)
2448 /* Mark the PC as the destination for the return address. */
2449 if (regnum == gdbarch_pc_regnum (gdbarch))
2450 reg->how = DWARF2_FRAME_REG_RA;
2452 /* Mark the stack pointer as the call frame address. */
2453 else if (regnum == gdbarch_sp_regnum (gdbarch))
2454 reg->how = DWARF2_FRAME_REG_CFA;
2456 /* The above was taken from the default init_reg in dwarf2-frame.c
2457 while the below is SH specific. */
2459 /* Caller save registers. */
2460 else if ((regnum >= R0_REGNUM && regnum <= R0_REGNUM+7)
2461 || (regnum >= FR0_REGNUM && regnum <= FR0_REGNUM+11)
2462 || (regnum >= DR0_REGNUM && regnum <= DR0_REGNUM+5)
2463 || (regnum >= FV0_REGNUM && regnum <= FV0_REGNUM+2)
2464 || (regnum == MACH_REGNUM)
2465 || (regnum == MACL_REGNUM)
2466 || (regnum == FPUL_REGNUM)
2467 || (regnum == SR_REGNUM))
2468 reg->how = DWARF2_FRAME_REG_UNDEFINED;
2470 /* Callee save registers. */
2471 else if ((regnum >= R0_REGNUM+8 && regnum <= R0_REGNUM+15)
2472 || (regnum >= FR0_REGNUM+12 && regnum <= FR0_REGNUM+15)
2473 || (regnum >= DR0_REGNUM+6 && regnum <= DR0_REGNUM+8)
2474 || (regnum == FV0_REGNUM+3))
2475 reg->how = DWARF2_FRAME_REG_SAME_VALUE;
2477 /* Other registers. These are not in the ABI and may or may not
2478 mean anything in frames >0 so don't show them. */
2479 else if ((regnum >= R0_BANK0_REGNUM && regnum <= R0_BANK0_REGNUM+15)
2480 || (regnum == GBR_REGNUM)
2481 || (regnum == VBR_REGNUM)
2482 || (regnum == FPSCR_REGNUM)
2483 || (regnum == SSR_REGNUM)
2484 || (regnum == SPC_REGNUM))
2485 reg->how = DWARF2_FRAME_REG_UNDEFINED;
2488 static struct sh_frame_cache *
2489 sh_alloc_frame_cache (void)
2491 struct sh_frame_cache *cache;
2492 int i;
2494 cache = FRAME_OBSTACK_ZALLOC (struct sh_frame_cache);
2496 /* Base address. */
2497 cache->base = 0;
2498 cache->saved_sp = 0;
2499 cache->sp_offset = 0;
2500 cache->pc = 0;
2502 /* Frameless until proven otherwise. */
2503 cache->uses_fp = 0;
2505 /* Saved registers. We initialize these to -1 since zero is a valid
2506 offset (that's where fp is supposed to be stored). */
2507 for (i = 0; i < SH_NUM_REGS; i++)
2509 cache->saved_regs[i] = -1;
2512 return cache;
2515 static struct sh_frame_cache *
2516 sh_frame_cache (struct frame_info *this_frame, void **this_cache)
2518 struct gdbarch *gdbarch = get_frame_arch (this_frame);
2519 struct sh_frame_cache *cache;
2520 CORE_ADDR current_pc;
2521 int i;
2523 if (*this_cache)
2524 return *this_cache;
2526 cache = sh_alloc_frame_cache ();
2527 *this_cache = cache;
2529 /* In principle, for normal frames, fp holds the frame pointer,
2530 which holds the base address for the current stack frame.
2531 However, for functions that don't need it, the frame pointer is
2532 optional. For these "frameless" functions the frame pointer is
2533 actually the frame pointer of the calling frame. */
2534 cache->base = get_frame_register_unsigned (this_frame, FP_REGNUM);
2535 if (cache->base == 0)
2536 return cache;
2538 cache->pc = get_frame_func (this_frame);
2539 current_pc = get_frame_pc (this_frame);
2540 if (cache->pc != 0)
2542 ULONGEST fpscr;
2543 fpscr = get_frame_register_unsigned (this_frame, FPSCR_REGNUM);
2544 sh_analyze_prologue (gdbarch, cache->pc, current_pc, cache, fpscr);
2547 if (!cache->uses_fp)
2549 /* We didn't find a valid frame, which means that CACHE->base
2550 currently holds the frame pointer for our calling frame. If
2551 we're at the start of a function, or somewhere half-way its
2552 prologue, the function's frame probably hasn't been fully
2553 setup yet. Try to reconstruct the base address for the stack
2554 frame by looking at the stack pointer. For truly "frameless"
2555 functions this might work too. */
2556 cache->base = get_frame_register_unsigned
2557 (this_frame, gdbarch_sp_regnum (gdbarch));
2560 /* Now that we have the base address for the stack frame we can
2561 calculate the value of sp in the calling frame. */
2562 cache->saved_sp = cache->base + cache->sp_offset;
2564 /* Adjust all the saved registers such that they contain addresses
2565 instead of offsets. */
2566 for (i = 0; i < SH_NUM_REGS; i++)
2567 if (cache->saved_regs[i] != -1)
2568 cache->saved_regs[i] = cache->saved_sp - cache->saved_regs[i] - 4;
2570 return cache;
2573 static struct value *
2574 sh_frame_prev_register (struct frame_info *this_frame,
2575 void **this_cache, int regnum)
2577 struct gdbarch *gdbarch = get_frame_arch (this_frame);
2578 struct sh_frame_cache *cache = sh_frame_cache (this_frame, this_cache);
2580 gdb_assert (regnum >= 0);
2582 if (regnum == gdbarch_sp_regnum (gdbarch) && cache->saved_sp)
2583 return frame_unwind_got_constant (this_frame, regnum, cache->saved_sp);
2585 /* The PC of the previous frame is stored in the PR register of
2586 the current frame. Frob regnum so that we pull the value from
2587 the correct place. */
2588 if (regnum == gdbarch_pc_regnum (gdbarch))
2589 regnum = PR_REGNUM;
2591 if (regnum < SH_NUM_REGS && cache->saved_regs[regnum] != -1)
2592 return frame_unwind_got_memory (this_frame, regnum,
2593 cache->saved_regs[regnum]);
2595 return frame_unwind_got_register (this_frame, regnum, regnum);
2598 static void
2599 sh_frame_this_id (struct frame_info *this_frame, void **this_cache,
2600 struct frame_id *this_id)
2602 struct sh_frame_cache *cache = sh_frame_cache (this_frame, this_cache);
2604 /* This marks the outermost frame. */
2605 if (cache->base == 0)
2606 return;
2608 *this_id = frame_id_build (cache->saved_sp, cache->pc);
2611 static const struct frame_unwind sh_frame_unwind = {
2612 NORMAL_FRAME,
2613 sh_frame_this_id,
2614 sh_frame_prev_register,
2615 NULL,
2616 default_frame_sniffer
2619 static CORE_ADDR
2620 sh_unwind_sp (struct gdbarch *gdbarch, struct frame_info *next_frame)
2622 return frame_unwind_register_unsigned (next_frame,
2623 gdbarch_sp_regnum (gdbarch));
2626 static CORE_ADDR
2627 sh_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
2629 return frame_unwind_register_unsigned (next_frame,
2630 gdbarch_pc_regnum (gdbarch));
2633 static struct frame_id
2634 sh_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame)
2636 CORE_ADDR sp = get_frame_register_unsigned (this_frame,
2637 gdbarch_sp_regnum (gdbarch));
2638 return frame_id_build (sp, get_frame_pc (this_frame));
2641 static CORE_ADDR
2642 sh_frame_base_address (struct frame_info *this_frame, void **this_cache)
2644 struct sh_frame_cache *cache = sh_frame_cache (this_frame, this_cache);
2646 return cache->base;
2649 static const struct frame_base sh_frame_base = {
2650 &sh_frame_unwind,
2651 sh_frame_base_address,
2652 sh_frame_base_address,
2653 sh_frame_base_address
2656 /* The epilogue is defined here as the area at the end of a function,
2657 either on the `ret' instruction itself or after an instruction which
2658 destroys the function's stack frame. */
2659 static int
2660 sh_in_function_epilogue_p (struct gdbarch *gdbarch, CORE_ADDR pc)
2662 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
2663 CORE_ADDR func_addr = 0, func_end = 0;
2665 if (find_pc_partial_function (pc, NULL, &func_addr, &func_end))
2667 ULONGEST inst;
2668 /* The sh epilogue is max. 14 bytes long. Give another 14 bytes
2669 for a nop and some fixed data (e.g. big offsets) which are
2670 unfortunately also treated as part of the function (which
2671 means, they are below func_end. */
2672 CORE_ADDR addr = func_end - 28;
2673 if (addr < func_addr + 4)
2674 addr = func_addr + 4;
2675 if (pc < addr)
2676 return 0;
2678 /* First search forward until hitting an rts. */
2679 while (addr < func_end
2680 && !IS_RTS (read_memory_unsigned_integer (addr, 2, byte_order)))
2681 addr += 2;
2682 if (addr >= func_end)
2683 return 0;
2685 /* At this point we should find a mov.l @r15+,r14 instruction,
2686 either before or after the rts. If not, then the function has
2687 probably no "normal" epilogue and we bail out here. */
2688 inst = read_memory_unsigned_integer (addr - 2, 2, byte_order);
2689 if (IS_RESTORE_FP (read_memory_unsigned_integer (addr - 2, 2,
2690 byte_order)))
2691 addr -= 2;
2692 else if (!IS_RESTORE_FP (read_memory_unsigned_integer (addr + 2, 2,
2693 byte_order)))
2694 return 0;
2696 inst = read_memory_unsigned_integer (addr - 2, 2, byte_order);
2698 /* Step over possible lds.l @r15+,macl. */
2699 if (IS_MACL_LDS (inst))
2701 addr -= 2;
2702 inst = read_memory_unsigned_integer (addr - 2, 2, byte_order);
2705 /* Step over possible lds.l @r15+,pr. */
2706 if (IS_LDS (inst))
2708 addr -= 2;
2709 inst = read_memory_unsigned_integer (addr - 2, 2, byte_order);
2712 /* Step over possible mov r14,r15. */
2713 if (IS_MOV_FP_SP (inst))
2715 addr -= 2;
2716 inst = read_memory_unsigned_integer (addr - 2, 2, byte_order);
2719 /* Now check for FP adjustments, using add #imm,r14 or add rX, r14
2720 instructions. */
2721 while (addr > func_addr + 4
2722 && (IS_ADD_REG_TO_FP (inst) || IS_ADD_IMM_FP (inst)))
2724 addr -= 2;
2725 inst = read_memory_unsigned_integer (addr - 2, 2, byte_order);
2728 /* On SH2a check if the previous instruction was perhaps a MOVI20.
2729 That's allowed for the epilogue. */
2730 if ((gdbarch_bfd_arch_info (gdbarch)->mach == bfd_mach_sh2a
2731 || gdbarch_bfd_arch_info (gdbarch)->mach == bfd_mach_sh2a_nofpu)
2732 && addr > func_addr + 6
2733 && IS_MOVI20 (read_memory_unsigned_integer (addr - 4, 2,
2734 byte_order)))
2735 addr -= 4;
2737 if (pc >= addr)
2738 return 1;
2740 return 0;
2744 /* Supply register REGNUM from the buffer specified by REGS and LEN
2745 in the register set REGSET to register cache REGCACHE.
2746 REGTABLE specifies where each register can be found in REGS.
2747 If REGNUM is -1, do this for all registers in REGSET. */
2749 void
2750 sh_corefile_supply_regset (const struct regset *regset,
2751 struct regcache *regcache,
2752 int regnum, const void *regs, size_t len)
2754 struct gdbarch *gdbarch = get_regcache_arch (regcache);
2755 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
2756 const struct sh_corefile_regmap *regmap = (regset == &sh_corefile_gregset
2757 ? tdep->core_gregmap
2758 : tdep->core_fpregmap);
2759 int i;
2761 for (i = 0; regmap[i].regnum != -1; i++)
2763 if ((regnum == -1 || regnum == regmap[i].regnum)
2764 && regmap[i].offset + 4 <= len)
2765 regcache_raw_supply (regcache, regmap[i].regnum,
2766 (char *)regs + regmap[i].offset);
2770 /* Collect register REGNUM in the register set REGSET from register cache
2771 REGCACHE into the buffer specified by REGS and LEN.
2772 REGTABLE specifies where each register can be found in REGS.
2773 If REGNUM is -1, do this for all registers in REGSET. */
2775 void
2776 sh_corefile_collect_regset (const struct regset *regset,
2777 const struct regcache *regcache,
2778 int regnum, void *regs, size_t len)
2780 struct gdbarch *gdbarch = get_regcache_arch (regcache);
2781 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
2782 const struct sh_corefile_regmap *regmap = (regset == &sh_corefile_gregset
2783 ? tdep->core_gregmap
2784 : tdep->core_fpregmap);
2785 int i;
2787 for (i = 0; regmap[i].regnum != -1; i++)
2789 if ((regnum == -1 || regnum == regmap[i].regnum)
2790 && regmap[i].offset + 4 <= len)
2791 regcache_raw_collect (regcache, regmap[i].regnum,
2792 (char *)regs + regmap[i].offset);
2796 /* The following two regsets have the same contents, so it is tempting to
2797 unify them, but they are distiguished by their address, so don't. */
2799 struct regset sh_corefile_gregset =
2801 NULL,
2802 sh_corefile_supply_regset,
2803 sh_corefile_collect_regset
2806 static struct regset sh_corefile_fpregset =
2808 NULL,
2809 sh_corefile_supply_regset,
2810 sh_corefile_collect_regset
2813 static const struct regset *
2814 sh_regset_from_core_section (struct gdbarch *gdbarch, const char *sect_name,
2815 size_t sect_size)
2817 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
2819 if (tdep->core_gregmap && strcmp (sect_name, ".reg") == 0)
2820 return &sh_corefile_gregset;
2822 if (tdep->core_fpregmap && strcmp (sect_name, ".reg2") == 0)
2823 return &sh_corefile_fpregset;
2825 return NULL;
2829 static struct gdbarch *
2830 sh_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
2832 struct gdbarch *gdbarch;
2833 struct gdbarch_tdep *tdep;
2835 sh_show_regs = sh_generic_show_regs;
2836 switch (info.bfd_arch_info->mach)
2838 case bfd_mach_sh2e:
2839 sh_show_regs = sh2e_show_regs;
2840 break;
2841 case bfd_mach_sh2a:
2842 sh_show_regs = sh2a_show_regs;
2843 break;
2844 case bfd_mach_sh2a_nofpu:
2845 sh_show_regs = sh2a_nofpu_show_regs;
2846 break;
2847 case bfd_mach_sh_dsp:
2848 sh_show_regs = sh_dsp_show_regs;
2849 break;
2851 case bfd_mach_sh3:
2852 case bfd_mach_sh3_nommu:
2853 case bfd_mach_sh2a_nofpu_or_sh3_nommu:
2854 sh_show_regs = sh3_show_regs;
2855 break;
2857 case bfd_mach_sh3e:
2858 case bfd_mach_sh2a_or_sh3e:
2859 sh_show_regs = sh3e_show_regs;
2860 break;
2862 case bfd_mach_sh3_dsp:
2863 case bfd_mach_sh4al_dsp:
2864 sh_show_regs = sh3_dsp_show_regs;
2865 break;
2867 case bfd_mach_sh4:
2868 case bfd_mach_sh4a:
2869 case bfd_mach_sh2a_or_sh4:
2870 sh_show_regs = sh4_show_regs;
2871 break;
2873 case bfd_mach_sh4_nofpu:
2874 case bfd_mach_sh4_nommu_nofpu:
2875 case bfd_mach_sh4a_nofpu:
2876 case bfd_mach_sh2a_nofpu_or_sh4_nommu_nofpu:
2877 sh_show_regs = sh4_nofpu_show_regs;
2878 break;
2880 case bfd_mach_sh5:
2881 sh_show_regs = sh64_show_regs;
2882 /* SH5 is handled entirely in sh64-tdep.c */
2883 return sh64_gdbarch_init (info, arches);
2886 /* If there is already a candidate, use it. */
2887 arches = gdbarch_list_lookup_by_info (arches, &info);
2888 if (arches != NULL)
2889 return arches->gdbarch;
2891 /* None found, create a new architecture from the information
2892 provided. */
2893 tdep = XZALLOC (struct gdbarch_tdep);
2894 gdbarch = gdbarch_alloc (&info, tdep);
2896 set_gdbarch_short_bit (gdbarch, 2 * TARGET_CHAR_BIT);
2897 set_gdbarch_int_bit (gdbarch, 4 * TARGET_CHAR_BIT);
2898 set_gdbarch_long_bit (gdbarch, 4 * TARGET_CHAR_BIT);
2899 set_gdbarch_long_long_bit (gdbarch, 8 * TARGET_CHAR_BIT);
2900 set_gdbarch_float_bit (gdbarch, 4 * TARGET_CHAR_BIT);
2901 set_gdbarch_double_bit (gdbarch, 8 * TARGET_CHAR_BIT);
2902 set_gdbarch_long_double_bit (gdbarch, 8 * TARGET_CHAR_BIT);
2903 set_gdbarch_ptr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
2905 set_gdbarch_num_regs (gdbarch, SH_NUM_REGS);
2906 set_gdbarch_sp_regnum (gdbarch, 15);
2907 set_gdbarch_pc_regnum (gdbarch, 16);
2908 set_gdbarch_fp0_regnum (gdbarch, -1);
2909 set_gdbarch_num_pseudo_regs (gdbarch, 0);
2911 set_gdbarch_register_type (gdbarch, sh_default_register_type);
2912 set_gdbarch_register_reggroup_p (gdbarch, sh_register_reggroup_p);
2914 set_gdbarch_breakpoint_from_pc (gdbarch, sh_breakpoint_from_pc);
2916 set_gdbarch_print_insn (gdbarch, print_insn_sh);
2917 set_gdbarch_register_sim_regno (gdbarch, legacy_register_sim_regno);
2919 set_gdbarch_return_value (gdbarch, sh_return_value_nofpu);
2921 set_gdbarch_skip_prologue (gdbarch, sh_skip_prologue);
2922 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
2924 set_gdbarch_push_dummy_call (gdbarch, sh_push_dummy_call_nofpu);
2926 set_gdbarch_believe_pcc_promotion (gdbarch, 1);
2928 set_gdbarch_frame_align (gdbarch, sh_frame_align);
2929 set_gdbarch_unwind_sp (gdbarch, sh_unwind_sp);
2930 set_gdbarch_unwind_pc (gdbarch, sh_unwind_pc);
2931 set_gdbarch_dummy_id (gdbarch, sh_dummy_id);
2932 frame_base_set_default (gdbarch, &sh_frame_base);
2934 set_gdbarch_in_function_epilogue_p (gdbarch, sh_in_function_epilogue_p);
2936 dwarf2_frame_set_init_reg (gdbarch, sh_dwarf2_frame_init_reg);
2938 set_gdbarch_regset_from_core_section (gdbarch, sh_regset_from_core_section);
2940 switch (info.bfd_arch_info->mach)
2942 case bfd_mach_sh:
2943 set_gdbarch_register_name (gdbarch, sh_sh_register_name);
2944 break;
2946 case bfd_mach_sh2:
2947 set_gdbarch_register_name (gdbarch, sh_sh_register_name);
2948 break;
2950 case bfd_mach_sh2e:
2951 /* doubles on sh2e and sh3e are actually 4 byte. */
2952 set_gdbarch_double_bit (gdbarch, 4 * TARGET_CHAR_BIT);
2954 set_gdbarch_register_name (gdbarch, sh_sh2e_register_name);
2955 set_gdbarch_register_type (gdbarch, sh_sh3e_register_type);
2956 set_gdbarch_fp0_regnum (gdbarch, 25);
2957 set_gdbarch_return_value (gdbarch, sh_return_value_fpu);
2958 set_gdbarch_push_dummy_call (gdbarch, sh_push_dummy_call_fpu);
2959 break;
2961 case bfd_mach_sh2a:
2962 set_gdbarch_register_name (gdbarch, sh_sh2a_register_name);
2963 set_gdbarch_register_type (gdbarch, sh_sh2a_register_type);
2964 set_gdbarch_register_sim_regno (gdbarch, sh_sh2a_register_sim_regno);
2966 set_gdbarch_fp0_regnum (gdbarch, 25);
2967 set_gdbarch_num_pseudo_regs (gdbarch, 9);
2968 set_gdbarch_pseudo_register_read (gdbarch, sh_pseudo_register_read);
2969 set_gdbarch_pseudo_register_write (gdbarch, sh_pseudo_register_write);
2970 set_gdbarch_return_value (gdbarch, sh_return_value_fpu);
2971 set_gdbarch_push_dummy_call (gdbarch, sh_push_dummy_call_fpu);
2972 break;
2974 case bfd_mach_sh2a_nofpu:
2975 set_gdbarch_register_name (gdbarch, sh_sh2a_nofpu_register_name);
2976 set_gdbarch_register_sim_regno (gdbarch, sh_sh2a_register_sim_regno);
2978 set_gdbarch_num_pseudo_regs (gdbarch, 1);
2979 set_gdbarch_pseudo_register_read (gdbarch, sh_pseudo_register_read);
2980 set_gdbarch_pseudo_register_write (gdbarch, sh_pseudo_register_write);
2981 break;
2983 case bfd_mach_sh_dsp:
2984 set_gdbarch_register_name (gdbarch, sh_sh_dsp_register_name);
2985 set_gdbarch_register_sim_regno (gdbarch, sh_dsp_register_sim_regno);
2986 break;
2988 case bfd_mach_sh3:
2989 case bfd_mach_sh3_nommu:
2990 case bfd_mach_sh2a_nofpu_or_sh3_nommu:
2991 set_gdbarch_register_name (gdbarch, sh_sh3_register_name);
2992 break;
2994 case bfd_mach_sh3e:
2995 case bfd_mach_sh2a_or_sh3e:
2996 /* doubles on sh2e and sh3e are actually 4 byte. */
2997 set_gdbarch_double_bit (gdbarch, 4 * TARGET_CHAR_BIT);
2999 set_gdbarch_register_name (gdbarch, sh_sh3e_register_name);
3000 set_gdbarch_register_type (gdbarch, sh_sh3e_register_type);
3001 set_gdbarch_fp0_regnum (gdbarch, 25);
3002 set_gdbarch_return_value (gdbarch, sh_return_value_fpu);
3003 set_gdbarch_push_dummy_call (gdbarch, sh_push_dummy_call_fpu);
3004 break;
3006 case bfd_mach_sh3_dsp:
3007 set_gdbarch_register_name (gdbarch, sh_sh3_dsp_register_name);
3008 set_gdbarch_register_sim_regno (gdbarch, sh_dsp_register_sim_regno);
3009 break;
3011 case bfd_mach_sh4:
3012 case bfd_mach_sh4a:
3013 case bfd_mach_sh2a_or_sh4:
3014 set_gdbarch_register_name (gdbarch, sh_sh4_register_name);
3015 set_gdbarch_register_type (gdbarch, sh_sh4_register_type);
3016 set_gdbarch_fp0_regnum (gdbarch, 25);
3017 set_gdbarch_num_pseudo_regs (gdbarch, 13);
3018 set_gdbarch_pseudo_register_read (gdbarch, sh_pseudo_register_read);
3019 set_gdbarch_pseudo_register_write (gdbarch, sh_pseudo_register_write);
3020 set_gdbarch_return_value (gdbarch, sh_return_value_fpu);
3021 set_gdbarch_push_dummy_call (gdbarch, sh_push_dummy_call_fpu);
3022 break;
3024 case bfd_mach_sh4_nofpu:
3025 case bfd_mach_sh4a_nofpu:
3026 case bfd_mach_sh4_nommu_nofpu:
3027 case bfd_mach_sh2a_nofpu_or_sh4_nommu_nofpu:
3028 set_gdbarch_register_name (gdbarch, sh_sh4_nofpu_register_name);
3029 break;
3031 case bfd_mach_sh4al_dsp:
3032 set_gdbarch_register_name (gdbarch, sh_sh4al_dsp_register_name);
3033 set_gdbarch_register_sim_regno (gdbarch, sh_dsp_register_sim_regno);
3034 break;
3036 default:
3037 set_gdbarch_register_name (gdbarch, sh_sh_register_name);
3038 break;
3041 /* Hook in ABI-specific overrides, if they have been registered. */
3042 gdbarch_init_osabi (info, gdbarch);
3044 dwarf2_append_unwinders (gdbarch);
3045 frame_unwind_append_unwinder (gdbarch, &sh_frame_unwind);
3047 return gdbarch;
3050 static void
3051 show_sh_command (char *args, int from_tty)
3053 help_list (showshcmdlist, "show sh ", all_commands, gdb_stdout);
3056 static void
3057 set_sh_command (char *args, int from_tty)
3059 printf_unfiltered
3060 ("\"set sh\" must be followed by an appropriate subcommand.\n");
3061 help_list (setshcmdlist, "set sh ", all_commands, gdb_stdout);
3064 extern initialize_file_ftype _initialize_sh_tdep; /* -Wmissing-prototypes */
3066 void
3067 _initialize_sh_tdep (void)
3069 struct cmd_list_element *c;
3071 gdbarch_register (bfd_arch_sh, sh_gdbarch_init, NULL);
3073 add_com ("regs", class_vars, sh_show_regs_command, _("Print all registers"));
3075 add_prefix_cmd ("sh", no_class, set_sh_command, "SH specific commands.",
3076 &setshcmdlist, "set sh ", 0, &setlist);
3077 add_prefix_cmd ("sh", no_class, show_sh_command, "SH specific commands.",
3078 &showshcmdlist, "show sh ", 0, &showlist);
3080 add_setshow_enum_cmd ("calling-convention", class_vars, sh_cc_enum,
3081 &sh_active_calling_convention,
3082 _("Set calling convention used when calling target "
3083 "functions from GDB."),
3084 _("Show calling convention used when calling target "
3085 "functions from GDB."),
3086 _("gcc - Use GCC calling convention (default).\n"
3087 "renesas - Enforce Renesas calling convention."),
3088 NULL, NULL,
3089 &setshcmdlist, &showshcmdlist);