Split breakpoint_from_pc to breakpoint_kind_from_pc and sw_breakpoint_from_kind
[deliverable/binutils-gdb.git] / gdb / sh-tdep.c
1 /* Target-dependent code for Renesas Super-H, for GDB.
2
3 Copyright (C) 1993-2016 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20 /* Contributed by Steve Chamberlain
21 sac@cygnus.com. */
22
23 #include "defs.h"
24 #include "frame.h"
25 #include "frame-base.h"
26 #include "frame-unwind.h"
27 #include "dwarf2-frame.h"
28 #include "symtab.h"
29 #include "gdbtypes.h"
30 #include "gdbcmd.h"
31 #include "gdbcore.h"
32 #include "value.h"
33 #include "dis-asm.h"
34 #include "inferior.h"
35 #include "arch-utils.h"
36 #include "floatformat.h"
37 #include "regcache.h"
38 #include "doublest.h"
39 #include "osabi.h"
40 #include "reggroups.h"
41 #include "regset.h"
42 #include "objfiles.h"
43
44 #include "sh-tdep.h"
45 #include "sh64-tdep.h"
46
47 #include "elf-bfd.h"
48 #include "solib-svr4.h"
49
50 /* sh flags */
51 #include "elf/sh.h"
52 #include "dwarf2.h"
53 /* registers numbers shared with the simulator. */
54 #include "gdb/sim-sh.h"
55 #include <algorithm>
56
57 /* List of "set sh ..." and "show sh ..." commands. */
58 static struct cmd_list_element *setshcmdlist = NULL;
59 static struct cmd_list_element *showshcmdlist = NULL;
60
61 static const char sh_cc_gcc[] = "gcc";
62 static const char sh_cc_renesas[] = "renesas";
63 static const char *const sh_cc_enum[] = {
64 sh_cc_gcc,
65 sh_cc_renesas,
66 NULL
67 };
68
69 static const char *sh_active_calling_convention = sh_cc_gcc;
70
71 #define SH_NUM_REGS 67
72
73 struct sh_frame_cache
74 {
75 /* Base address. */
76 CORE_ADDR base;
77 LONGEST sp_offset;
78 CORE_ADDR pc;
79
80 /* Flag showing that a frame has been created in the prologue code. */
81 int uses_fp;
82
83 /* Saved registers. */
84 CORE_ADDR saved_regs[SH_NUM_REGS];
85 CORE_ADDR saved_sp;
86 };
87
88 static int
89 sh_is_renesas_calling_convention (struct type *func_type)
90 {
91 int val = 0;
92
93 if (func_type)
94 {
95 func_type = check_typedef (func_type);
96
97 if (TYPE_CODE (func_type) == TYPE_CODE_PTR)
98 func_type = check_typedef (TYPE_TARGET_TYPE (func_type));
99
100 if (TYPE_CODE (func_type) == TYPE_CODE_FUNC
101 && TYPE_CALLING_CONVENTION (func_type) == DW_CC_GNU_renesas_sh)
102 val = 1;
103 }
104
105 if (sh_active_calling_convention == sh_cc_renesas)
106 val = 1;
107
108 return val;
109 }
110
111 static const char *
112 sh_sh_register_name (struct gdbarch *gdbarch, int reg_nr)
113 {
114 static char *register_names[] = {
115 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
116 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
117 "pc", "pr", "gbr", "vbr", "mach", "macl", "sr",
118 "", "",
119 "", "", "", "", "", "", "", "",
120 "", "", "", "", "", "", "", "",
121 "", "",
122 "", "", "", "", "", "", "", "",
123 "", "", "", "", "", "", "", "",
124 "", "", "", "", "", "", "", "",
125 };
126 if (reg_nr < 0)
127 return NULL;
128 if (reg_nr >= (sizeof (register_names) / sizeof (*register_names)))
129 return NULL;
130 return register_names[reg_nr];
131 }
132
133 static const char *
134 sh_sh3_register_name (struct gdbarch *gdbarch, int reg_nr)
135 {
136 static char *register_names[] = {
137 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
138 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
139 "pc", "pr", "gbr", "vbr", "mach", "macl", "sr",
140 "", "",
141 "", "", "", "", "", "", "", "",
142 "", "", "", "", "", "", "", "",
143 "ssr", "spc",
144 "r0b0", "r1b0", "r2b0", "r3b0", "r4b0", "r5b0", "r6b0", "r7b0",
145 "r0b1", "r1b1", "r2b1", "r3b1", "r4b1", "r5b1", "r6b1", "r7b1"
146 "", "", "", "", "", "", "", "",
147 };
148 if (reg_nr < 0)
149 return NULL;
150 if (reg_nr >= (sizeof (register_names) / sizeof (*register_names)))
151 return NULL;
152 return register_names[reg_nr];
153 }
154
155 static const char *
156 sh_sh3e_register_name (struct gdbarch *gdbarch, int reg_nr)
157 {
158 static char *register_names[] = {
159 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
160 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
161 "pc", "pr", "gbr", "vbr", "mach", "macl", "sr",
162 "fpul", "fpscr",
163 "fr0", "fr1", "fr2", "fr3", "fr4", "fr5", "fr6", "fr7",
164 "fr8", "fr9", "fr10", "fr11", "fr12", "fr13", "fr14", "fr15",
165 "ssr", "spc",
166 "r0b0", "r1b0", "r2b0", "r3b0", "r4b0", "r5b0", "r6b0", "r7b0",
167 "r0b1", "r1b1", "r2b1", "r3b1", "r4b1", "r5b1", "r6b1", "r7b1",
168 "", "", "", "", "", "", "", "",
169 };
170 if (reg_nr < 0)
171 return NULL;
172 if (reg_nr >= (sizeof (register_names) / sizeof (*register_names)))
173 return NULL;
174 return register_names[reg_nr];
175 }
176
177 static const char *
178 sh_sh2e_register_name (struct gdbarch *gdbarch, int reg_nr)
179 {
180 static char *register_names[] = {
181 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
182 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
183 "pc", "pr", "gbr", "vbr", "mach", "macl", "sr",
184 "fpul", "fpscr",
185 "fr0", "fr1", "fr2", "fr3", "fr4", "fr5", "fr6", "fr7",
186 "fr8", "fr9", "fr10", "fr11", "fr12", "fr13", "fr14", "fr15",
187 "", "",
188 "", "", "", "", "", "", "", "",
189 "", "", "", "", "", "", "", "",
190 "", "", "", "", "", "", "", "",
191 };
192 if (reg_nr < 0)
193 return NULL;
194 if (reg_nr >= (sizeof (register_names) / sizeof (*register_names)))
195 return NULL;
196 return register_names[reg_nr];
197 }
198
199 static const char *
200 sh_sh2a_register_name (struct gdbarch *gdbarch, int reg_nr)
201 {
202 static char *register_names[] = {
203 /* general registers 0-15 */
204 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
205 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
206 /* 16 - 22 */
207 "pc", "pr", "gbr", "vbr", "mach", "macl", "sr",
208 /* 23, 24 */
209 "fpul", "fpscr",
210 /* floating point registers 25 - 40 */
211 "fr0", "fr1", "fr2", "fr3", "fr4", "fr5", "fr6", "fr7",
212 "fr8", "fr9", "fr10", "fr11", "fr12", "fr13", "fr14", "fr15",
213 /* 41, 42 */
214 "", "",
215 /* 43 - 62. Banked registers. The bank number used is determined by
216 the bank register (63). */
217 "r0b", "r1b", "r2b", "r3b", "r4b", "r5b", "r6b", "r7b",
218 "r8b", "r9b", "r10b", "r11b", "r12b", "r13b", "r14b",
219 "machb", "ivnb", "prb", "gbrb", "maclb",
220 /* 63: register bank number, not a real register but used to
221 communicate the register bank currently get/set. This register
222 is hidden to the user, who manipulates it using the pseudo
223 register called "bank" (67). See below. */
224 "",
225 /* 64 - 66 */
226 "ibcr", "ibnr", "tbr",
227 /* 67: register bank number, the user visible pseudo register. */
228 "bank",
229 /* double precision (pseudo) 68 - 75 */
230 "dr0", "dr2", "dr4", "dr6", "dr8", "dr10", "dr12", "dr14",
231 };
232 if (reg_nr < 0)
233 return NULL;
234 if (reg_nr >= (sizeof (register_names) / sizeof (*register_names)))
235 return NULL;
236 return register_names[reg_nr];
237 }
238
239 static const char *
240 sh_sh2a_nofpu_register_name (struct gdbarch *gdbarch, int reg_nr)
241 {
242 static char *register_names[] = {
243 /* general registers 0-15 */
244 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
245 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
246 /* 16 - 22 */
247 "pc", "pr", "gbr", "vbr", "mach", "macl", "sr",
248 /* 23, 24 */
249 "", "",
250 /* floating point registers 25 - 40 */
251 "", "", "", "", "", "", "", "",
252 "", "", "", "", "", "", "", "",
253 /* 41, 42 */
254 "", "",
255 /* 43 - 62. Banked registers. The bank number used is determined by
256 the bank register (63). */
257 "r0b", "r1b", "r2b", "r3b", "r4b", "r5b", "r6b", "r7b",
258 "r8b", "r9b", "r10b", "r11b", "r12b", "r13b", "r14b",
259 "machb", "ivnb", "prb", "gbrb", "maclb",
260 /* 63: register bank number, not a real register but used to
261 communicate the register bank currently get/set. This register
262 is hidden to the user, who manipulates it using the pseudo
263 register called "bank" (67). See below. */
264 "",
265 /* 64 - 66 */
266 "ibcr", "ibnr", "tbr",
267 /* 67: register bank number, the user visible pseudo register. */
268 "bank",
269 /* double precision (pseudo) 68 - 75 */
270 "", "", "", "", "", "", "", "",
271 };
272 if (reg_nr < 0)
273 return NULL;
274 if (reg_nr >= (sizeof (register_names) / sizeof (*register_names)))
275 return NULL;
276 return register_names[reg_nr];
277 }
278
279 static const char *
280 sh_sh_dsp_register_name (struct gdbarch *gdbarch, int reg_nr)
281 {
282 static char *register_names[] = {
283 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
284 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
285 "pc", "pr", "gbr", "vbr", "mach", "macl", "sr",
286 "", "dsr",
287 "a0g", "a0", "a1g", "a1", "m0", "m1", "x0", "x1",
288 "y0", "y1", "", "", "", "", "", "mod",
289 "", "",
290 "rs", "re", "", "", "", "", "", "",
291 "", "", "", "", "", "", "", "",
292 "", "", "", "", "", "", "", "",
293 };
294 if (reg_nr < 0)
295 return NULL;
296 if (reg_nr >= (sizeof (register_names) / sizeof (*register_names)))
297 return NULL;
298 return register_names[reg_nr];
299 }
300
301 static const char *
302 sh_sh3_dsp_register_name (struct gdbarch *gdbarch, int reg_nr)
303 {
304 static char *register_names[] = {
305 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
306 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
307 "pc", "pr", "gbr", "vbr", "mach", "macl", "sr",
308 "", "dsr",
309 "a0g", "a0", "a1g", "a1", "m0", "m1", "x0", "x1",
310 "y0", "y1", "", "", "", "", "", "mod",
311 "ssr", "spc",
312 "rs", "re", "", "", "", "", "", "",
313 "r0b", "r1b", "r2b", "r3b", "r4b", "r5b", "r6b", "r7b",
314 "", "", "", "", "", "", "", "",
315 "", "", "", "", "", "", "", "",
316 };
317 if (reg_nr < 0)
318 return NULL;
319 if (reg_nr >= (sizeof (register_names) / sizeof (*register_names)))
320 return NULL;
321 return register_names[reg_nr];
322 }
323
324 static const char *
325 sh_sh4_register_name (struct gdbarch *gdbarch, int reg_nr)
326 {
327 static char *register_names[] = {
328 /* general registers 0-15 */
329 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
330 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
331 /* 16 - 22 */
332 "pc", "pr", "gbr", "vbr", "mach", "macl", "sr",
333 /* 23, 24 */
334 "fpul", "fpscr",
335 /* floating point registers 25 - 40 */
336 "fr0", "fr1", "fr2", "fr3", "fr4", "fr5", "fr6", "fr7",
337 "fr8", "fr9", "fr10", "fr11", "fr12", "fr13", "fr14", "fr15",
338 /* 41, 42 */
339 "ssr", "spc",
340 /* bank 0 43 - 50 */
341 "r0b0", "r1b0", "r2b0", "r3b0", "r4b0", "r5b0", "r6b0", "r7b0",
342 /* bank 1 51 - 58 */
343 "r0b1", "r1b1", "r2b1", "r3b1", "r4b1", "r5b1", "r6b1", "r7b1",
344 /* 59 - 66 */
345 "", "", "", "", "", "", "", "",
346 /* pseudo bank register. */
347 "",
348 /* double precision (pseudo) 68 - 75 */
349 "dr0", "dr2", "dr4", "dr6", "dr8", "dr10", "dr12", "dr14",
350 /* vectors (pseudo) 76 - 79 */
351 "fv0", "fv4", "fv8", "fv12",
352 /* FIXME: missing XF */
353 /* FIXME: missing XD */
354 };
355 if (reg_nr < 0)
356 return NULL;
357 if (reg_nr >= (sizeof (register_names) / sizeof (*register_names)))
358 return NULL;
359 return register_names[reg_nr];
360 }
361
362 static const char *
363 sh_sh4_nofpu_register_name (struct gdbarch *gdbarch, int reg_nr)
364 {
365 static char *register_names[] = {
366 /* general registers 0-15 */
367 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
368 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
369 /* 16 - 22 */
370 "pc", "pr", "gbr", "vbr", "mach", "macl", "sr",
371 /* 23, 24 */
372 "", "",
373 /* floating point registers 25 - 40 -- not for nofpu target */
374 "", "", "", "", "", "", "", "",
375 "", "", "", "", "", "", "", "",
376 /* 41, 42 */
377 "ssr", "spc",
378 /* bank 0 43 - 50 */
379 "r0b0", "r1b0", "r2b0", "r3b0", "r4b0", "r5b0", "r6b0", "r7b0",
380 /* bank 1 51 - 58 */
381 "r0b1", "r1b1", "r2b1", "r3b1", "r4b1", "r5b1", "r6b1", "r7b1",
382 /* 59 - 66 */
383 "", "", "", "", "", "", "", "",
384 /* pseudo bank register. */
385 "",
386 /* double precision (pseudo) 68 - 75 -- not for nofpu target */
387 "", "", "", "", "", "", "", "",
388 /* vectors (pseudo) 76 - 79 -- not for nofpu target */
389 "", "", "", "",
390 };
391 if (reg_nr < 0)
392 return NULL;
393 if (reg_nr >= (sizeof (register_names) / sizeof (*register_names)))
394 return NULL;
395 return register_names[reg_nr];
396 }
397
398 static const char *
399 sh_sh4al_dsp_register_name (struct gdbarch *gdbarch, int reg_nr)
400 {
401 static char *register_names[] = {
402 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
403 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
404 "pc", "pr", "gbr", "vbr", "mach", "macl", "sr",
405 "", "dsr",
406 "a0g", "a0", "a1g", "a1", "m0", "m1", "x0", "x1",
407 "y0", "y1", "", "", "", "", "", "mod",
408 "ssr", "spc",
409 "rs", "re", "", "", "", "", "", "",
410 "r0b", "r1b", "r2b", "r3b", "r4b", "r5b", "r6b", "r7b",
411 "", "", "", "", "", "", "", "",
412 "", "", "", "", "", "", "", "",
413 };
414 if (reg_nr < 0)
415 return NULL;
416 if (reg_nr >= (sizeof (register_names) / sizeof (*register_names)))
417 return NULL;
418 return register_names[reg_nr];
419 }
420
421 static int
422 sh_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
423 {
424 return 2;
425 }
426
427 static const gdb_byte *
428 sh_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
429 {
430 *size = kind;
431
432 /* For remote stub targets, trapa #20 is used. */
433 if (strcmp (target_shortname, "remote") == 0)
434 {
435 static unsigned char big_remote_breakpoint[] = { 0xc3, 0x20 };
436 static unsigned char little_remote_breakpoint[] = { 0x20, 0xc3 };
437
438 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
439 return big_remote_breakpoint;
440 else
441 return little_remote_breakpoint;
442 }
443 else
444 {
445 /* 0xc3c3 is trapa #c3, and it works in big and little endian
446 modes. */
447 static unsigned char breakpoint[] = { 0xc3, 0xc3 };
448
449 return breakpoint;
450 }
451 }
452
453 GDBARCH_BREAKPOINT_FROM_PC (sh)
454
455 /* Prologue looks like
456 mov.l r14,@-r15
457 sts.l pr,@-r15
458 mov.l <regs>,@-r15
459 sub <room_for_loca_vars>,r15
460 mov r15,r14
461
462 Actually it can be more complicated than this but that's it, basically. */
463
464 #define GET_SOURCE_REG(x) (((x) >> 4) & 0xf)
465 #define GET_TARGET_REG(x) (((x) >> 8) & 0xf)
466
467 /* JSR @Rm 0100mmmm00001011 */
468 #define IS_JSR(x) (((x) & 0xf0ff) == 0x400b)
469
470 /* STS.L PR,@-r15 0100111100100010
471 r15-4-->r15, PR-->(r15) */
472 #define IS_STS(x) ((x) == 0x4f22)
473
474 /* STS.L MACL,@-r15 0100111100010010
475 r15-4-->r15, MACL-->(r15) */
476 #define IS_MACL_STS(x) ((x) == 0x4f12)
477
478 /* MOV.L Rm,@-r15 00101111mmmm0110
479 r15-4-->r15, Rm-->(R15) */
480 #define IS_PUSH(x) (((x) & 0xff0f) == 0x2f06)
481
482 /* MOV r15,r14 0110111011110011
483 r15-->r14 */
484 #define IS_MOV_SP_FP(x) ((x) == 0x6ef3)
485
486 /* ADD #imm,r15 01111111iiiiiiii
487 r15+imm-->r15 */
488 #define IS_ADD_IMM_SP(x) (((x) & 0xff00) == 0x7f00)
489
490 #define IS_MOV_R3(x) (((x) & 0xff00) == 0x1a00)
491 #define IS_SHLL_R3(x) ((x) == 0x4300)
492
493 /* ADD r3,r15 0011111100111100
494 r15+r3-->r15 */
495 #define IS_ADD_R3SP(x) ((x) == 0x3f3c)
496
497 /* FMOV.S FRm,@-Rn Rn-4-->Rn, FRm-->(Rn) 1111nnnnmmmm1011
498 FMOV DRm,@-Rn Rn-8-->Rn, DRm-->(Rn) 1111nnnnmmm01011
499 FMOV XDm,@-Rn Rn-8-->Rn, XDm-->(Rn) 1111nnnnmmm11011 */
500 /* CV, 2003-08-28: Only suitable with Rn == SP, therefore name changed to
501 make this entirely clear. */
502 /* #define IS_FMOV(x) (((x) & 0xf00f) == 0xf00b) */
503 #define IS_FPUSH(x) (((x) & 0xff0f) == 0xff0b)
504
505 /* MOV Rm,Rn Rm-->Rn 0110nnnnmmmm0011 4 <= m <= 7 */
506 #define IS_MOV_ARG_TO_REG(x) \
507 (((x) & 0xf00f) == 0x6003 && \
508 ((x) & 0x00f0) >= 0x0040 && \
509 ((x) & 0x00f0) <= 0x0070)
510 /* MOV.L Rm,@Rn 0010nnnnmmmm0010 n = 14, 4 <= m <= 7 */
511 #define IS_MOV_ARG_TO_IND_R14(x) \
512 (((x) & 0xff0f) == 0x2e02 && \
513 ((x) & 0x00f0) >= 0x0040 && \
514 ((x) & 0x00f0) <= 0x0070)
515 /* MOV.L Rm,@(disp*4,Rn) 00011110mmmmdddd n = 14, 4 <= m <= 7 */
516 #define IS_MOV_ARG_TO_IND_R14_WITH_DISP(x) \
517 (((x) & 0xff00) == 0x1e00 && \
518 ((x) & 0x00f0) >= 0x0040 && \
519 ((x) & 0x00f0) <= 0x0070)
520
521 /* MOV.W @(disp*2,PC),Rn 1001nnnndddddddd */
522 #define IS_MOVW_PCREL_TO_REG(x) (((x) & 0xf000) == 0x9000)
523 /* MOV.L @(disp*4,PC),Rn 1101nnnndddddddd */
524 #define IS_MOVL_PCREL_TO_REG(x) (((x) & 0xf000) == 0xd000)
525 /* MOVI20 #imm20,Rn 0000nnnniiii0000 */
526 #define IS_MOVI20(x) (((x) & 0xf00f) == 0x0000)
527 /* SUB Rn,R15 00111111nnnn1000 */
528 #define IS_SUB_REG_FROM_SP(x) (((x) & 0xff0f) == 0x3f08)
529
530 #define FPSCR_SZ (1 << 20)
531
532 /* The following instructions are used for epilogue testing. */
533 #define IS_RESTORE_FP(x) ((x) == 0x6ef6)
534 #define IS_RTS(x) ((x) == 0x000b)
535 #define IS_LDS(x) ((x) == 0x4f26)
536 #define IS_MACL_LDS(x) ((x) == 0x4f16)
537 #define IS_MOV_FP_SP(x) ((x) == 0x6fe3)
538 #define IS_ADD_REG_TO_FP(x) (((x) & 0xff0f) == 0x3e0c)
539 #define IS_ADD_IMM_FP(x) (((x) & 0xff00) == 0x7e00)
540
541 static CORE_ADDR
542 sh_analyze_prologue (struct gdbarch *gdbarch,
543 CORE_ADDR pc, CORE_ADDR limit_pc,
544 struct sh_frame_cache *cache, ULONGEST fpscr)
545 {
546 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
547 ULONGEST inst;
548 int offset;
549 int sav_offset = 0;
550 int r3_val = 0;
551 int reg, sav_reg = -1;
552
553 cache->uses_fp = 0;
554 for (; pc < limit_pc; pc += 2)
555 {
556 inst = read_memory_unsigned_integer (pc, 2, byte_order);
557 /* See where the registers will be saved to. */
558 if (IS_PUSH (inst))
559 {
560 cache->saved_regs[GET_SOURCE_REG (inst)] = cache->sp_offset;
561 cache->sp_offset += 4;
562 }
563 else if (IS_STS (inst))
564 {
565 cache->saved_regs[PR_REGNUM] = cache->sp_offset;
566 cache->sp_offset += 4;
567 }
568 else if (IS_MACL_STS (inst))
569 {
570 cache->saved_regs[MACL_REGNUM] = cache->sp_offset;
571 cache->sp_offset += 4;
572 }
573 else if (IS_MOV_R3 (inst))
574 {
575 r3_val = ((inst & 0xff) ^ 0x80) - 0x80;
576 }
577 else if (IS_SHLL_R3 (inst))
578 {
579 r3_val <<= 1;
580 }
581 else if (IS_ADD_R3SP (inst))
582 {
583 cache->sp_offset += -r3_val;
584 }
585 else if (IS_ADD_IMM_SP (inst))
586 {
587 offset = ((inst & 0xff) ^ 0x80) - 0x80;
588 cache->sp_offset -= offset;
589 }
590 else if (IS_MOVW_PCREL_TO_REG (inst))
591 {
592 if (sav_reg < 0)
593 {
594 reg = GET_TARGET_REG (inst);
595 if (reg < 14)
596 {
597 sav_reg = reg;
598 offset = (inst & 0xff) << 1;
599 sav_offset =
600 read_memory_integer ((pc + 4) + offset, 2, byte_order);
601 }
602 }
603 }
604 else if (IS_MOVL_PCREL_TO_REG (inst))
605 {
606 if (sav_reg < 0)
607 {
608 reg = GET_TARGET_REG (inst);
609 if (reg < 14)
610 {
611 sav_reg = reg;
612 offset = (inst & 0xff) << 2;
613 sav_offset =
614 read_memory_integer (((pc & 0xfffffffc) + 4) + offset,
615 4, byte_order);
616 }
617 }
618 }
619 else if (IS_MOVI20 (inst)
620 && (pc + 2 < limit_pc))
621 {
622 if (sav_reg < 0)
623 {
624 reg = GET_TARGET_REG (inst);
625 if (reg < 14)
626 {
627 sav_reg = reg;
628 sav_offset = GET_SOURCE_REG (inst) << 16;
629 /* MOVI20 is a 32 bit instruction! */
630 pc += 2;
631 sav_offset
632 |= read_memory_unsigned_integer (pc, 2, byte_order);
633 /* Now sav_offset contains an unsigned 20 bit value.
634 It must still get sign extended. */
635 if (sav_offset & 0x00080000)
636 sav_offset |= 0xfff00000;
637 }
638 }
639 }
640 else if (IS_SUB_REG_FROM_SP (inst))
641 {
642 reg = GET_SOURCE_REG (inst);
643 if (sav_reg > 0 && reg == sav_reg)
644 {
645 sav_reg = -1;
646 }
647 cache->sp_offset += sav_offset;
648 }
649 else if (IS_FPUSH (inst))
650 {
651 if (fpscr & FPSCR_SZ)
652 {
653 cache->sp_offset += 8;
654 }
655 else
656 {
657 cache->sp_offset += 4;
658 }
659 }
660 else if (IS_MOV_SP_FP (inst))
661 {
662 pc += 2;
663 /* Don't go any further than six more instructions. */
664 limit_pc = std::min (limit_pc, pc + (2 * 6));
665
666 cache->uses_fp = 1;
667 /* At this point, only allow argument register moves to other
668 registers or argument register moves to @(X,fp) which are
669 moving the register arguments onto the stack area allocated
670 by a former add somenumber to SP call. Don't allow moving
671 to an fp indirect address above fp + cache->sp_offset. */
672 for (; pc < limit_pc; pc += 2)
673 {
674 inst = read_memory_integer (pc, 2, byte_order);
675 if (IS_MOV_ARG_TO_IND_R14 (inst))
676 {
677 reg = GET_SOURCE_REG (inst);
678 if (cache->sp_offset > 0)
679 cache->saved_regs[reg] = cache->sp_offset;
680 }
681 else if (IS_MOV_ARG_TO_IND_R14_WITH_DISP (inst))
682 {
683 reg = GET_SOURCE_REG (inst);
684 offset = (inst & 0xf) * 4;
685 if (cache->sp_offset > offset)
686 cache->saved_regs[reg] = cache->sp_offset - offset;
687 }
688 else if (IS_MOV_ARG_TO_REG (inst))
689 continue;
690 else
691 break;
692 }
693 break;
694 }
695 else if (IS_JSR (inst))
696 {
697 /* We have found a jsr that has been scheduled into the prologue.
698 If we continue the scan and return a pc someplace after this,
699 then setting a breakpoint on this function will cause it to
700 appear to be called after the function it is calling via the
701 jsr, which will be very confusing. Most likely the next
702 instruction is going to be IS_MOV_SP_FP in the delay slot. If
703 so, note that before returning the current pc. */
704 if (pc + 2 < limit_pc)
705 {
706 inst = read_memory_integer (pc + 2, 2, byte_order);
707 if (IS_MOV_SP_FP (inst))
708 cache->uses_fp = 1;
709 }
710 break;
711 }
712 #if 0 /* This used to just stop when it found an instruction
713 that was not considered part of the prologue. Now,
714 we just keep going looking for likely
715 instructions. */
716 else
717 break;
718 #endif
719 }
720
721 return pc;
722 }
723
724 /* Skip any prologue before the guts of a function. */
725 static CORE_ADDR
726 sh_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
727 {
728 CORE_ADDR post_prologue_pc, func_addr, func_end_addr, limit_pc;
729 struct sh_frame_cache cache;
730
731 /* See if we can determine the end of the prologue via the symbol table.
732 If so, then return either PC, or the PC after the prologue, whichever
733 is greater. */
734 if (find_pc_partial_function (pc, NULL, &func_addr, &func_end_addr))
735 {
736 post_prologue_pc = skip_prologue_using_sal (gdbarch, func_addr);
737 if (post_prologue_pc != 0)
738 return std::max (pc, post_prologue_pc);
739 }
740
741 /* Can't determine prologue from the symbol table, need to examine
742 instructions. */
743
744 /* Find an upper limit on the function prologue using the debug
745 information. If the debug information could not be used to provide
746 that bound, then use an arbitrary large number as the upper bound. */
747 limit_pc = skip_prologue_using_sal (gdbarch, pc);
748 if (limit_pc == 0)
749 /* Don't go any further than 28 instructions. */
750 limit_pc = pc + (2 * 28);
751
752 /* Do not allow limit_pc to be past the function end, if we know
753 where that end is... */
754 if (func_end_addr != 0)
755 limit_pc = std::min (limit_pc, func_end_addr);
756
757 cache.sp_offset = -4;
758 post_prologue_pc = sh_analyze_prologue (gdbarch, pc, limit_pc, &cache, 0);
759 if (cache.uses_fp)
760 pc = post_prologue_pc;
761
762 return pc;
763 }
764
765 /* The ABI says:
766
767 Aggregate types not bigger than 8 bytes that have the same size and
768 alignment as one of the integer scalar types are returned in the
769 same registers as the integer type they match.
770
771 For example, a 2-byte aligned structure with size 2 bytes has the
772 same size and alignment as a short int, and will be returned in R0.
773 A 4-byte aligned structure with size 8 bytes has the same size and
774 alignment as a long long int, and will be returned in R0 and R1.
775
776 When an aggregate type is returned in R0 and R1, R0 contains the
777 first four bytes of the aggregate, and R1 contains the
778 remainder. If the size of the aggregate type is not a multiple of 4
779 bytes, the aggregate is tail-padded up to a multiple of 4
780 bytes. The value of the padding is undefined. For little-endian
781 targets the padding will appear at the most significant end of the
782 last element, for big-endian targets the padding appears at the
783 least significant end of the last element.
784
785 All other aggregate types are returned by address. The caller
786 function passes the address of an area large enough to hold the
787 aggregate value in R2. The called function stores the result in
788 this location.
789
790 To reiterate, structs smaller than 8 bytes could also be returned
791 in memory, if they don't pass the "same size and alignment as an
792 integer type" rule.
793
794 For example, in
795
796 struct s { char c[3]; } wibble;
797 struct s foo(void) { return wibble; }
798
799 the return value from foo() will be in memory, not
800 in R0, because there is no 3-byte integer type.
801
802 Similarly, in
803
804 struct s { char c[2]; } wibble;
805 struct s foo(void) { return wibble; }
806
807 because a struct containing two chars has alignment 1, that matches
808 type char, but size 2, that matches type short. There's no integer
809 type that has alignment 1 and size 2, so the struct is returned in
810 memory. */
811
812 static int
813 sh_use_struct_convention (int renesas_abi, struct type *type)
814 {
815 int len = TYPE_LENGTH (type);
816 int nelem = TYPE_NFIELDS (type);
817
818 /* The Renesas ABI returns aggregate types always on stack. */
819 if (renesas_abi && (TYPE_CODE (type) == TYPE_CODE_STRUCT
820 || TYPE_CODE (type) == TYPE_CODE_UNION))
821 return 1;
822
823 /* Non-power of 2 length types and types bigger than 8 bytes (which don't
824 fit in two registers anyway) use struct convention. */
825 if (len != 1 && len != 2 && len != 4 && len != 8)
826 return 1;
827
828 /* Scalar types and aggregate types with exactly one field are aligned
829 by definition. They are returned in registers. */
830 if (nelem <= 1)
831 return 0;
832
833 /* If the first field in the aggregate has the same length as the entire
834 aggregate type, the type is returned in registers. */
835 if (TYPE_LENGTH (TYPE_FIELD_TYPE (type, 0)) == len)
836 return 0;
837
838 /* If the size of the aggregate is 8 bytes and the first field is
839 of size 4 bytes its alignment is equal to long long's alignment,
840 so it's returned in registers. */
841 if (len == 8 && TYPE_LENGTH (TYPE_FIELD_TYPE (type, 0)) == 4)
842 return 0;
843
844 /* Otherwise use struct convention. */
845 return 1;
846 }
847
848 static int
849 sh_use_struct_convention_nofpu (int renesas_abi, struct type *type)
850 {
851 /* The Renesas ABI returns long longs/doubles etc. always on stack. */
852 if (renesas_abi && TYPE_NFIELDS (type) == 0 && TYPE_LENGTH (type) >= 8)
853 return 1;
854 return sh_use_struct_convention (renesas_abi, type);
855 }
856
857 static CORE_ADDR
858 sh_frame_align (struct gdbarch *ignore, CORE_ADDR sp)
859 {
860 return sp & ~3;
861 }
862
863 /* Function: push_dummy_call (formerly push_arguments)
864 Setup the function arguments for calling a function in the inferior.
865
866 On the Renesas SH architecture, there are four registers (R4 to R7)
867 which are dedicated for passing function arguments. Up to the first
868 four arguments (depending on size) may go into these registers.
869 The rest go on the stack.
870
871 MVS: Except on SH variants that have floating point registers.
872 In that case, float and double arguments are passed in the same
873 manner, but using FP registers instead of GP registers.
874
875 Arguments that are smaller than 4 bytes will still take up a whole
876 register or a whole 32-bit word on the stack, and will be
877 right-justified in the register or the stack word. This includes
878 chars, shorts, and small aggregate types.
879
880 Arguments that are larger than 4 bytes may be split between two or
881 more registers. If there are not enough registers free, an argument
882 may be passed partly in a register (or registers), and partly on the
883 stack. This includes doubles, long longs, and larger aggregates.
884 As far as I know, there is no upper limit to the size of aggregates
885 that will be passed in this way; in other words, the convention of
886 passing a pointer to a large aggregate instead of a copy is not used.
887
888 MVS: The above appears to be true for the SH variants that do not
889 have an FPU, however those that have an FPU appear to copy the
890 aggregate argument onto the stack (and not place it in registers)
891 if it is larger than 16 bytes (four GP registers).
892
893 An exceptional case exists for struct arguments (and possibly other
894 aggregates such as arrays) if the size is larger than 4 bytes but
895 not a multiple of 4 bytes. In this case the argument is never split
896 between the registers and the stack, but instead is copied in its
897 entirety onto the stack, AND also copied into as many registers as
898 there is room for. In other words, space in registers permitting,
899 two copies of the same argument are passed in. As far as I can tell,
900 only the one on the stack is used, although that may be a function
901 of the level of compiler optimization. I suspect this is a compiler
902 bug. Arguments of these odd sizes are left-justified within the
903 word (as opposed to arguments smaller than 4 bytes, which are
904 right-justified).
905
906 If the function is to return an aggregate type such as a struct, it
907 is either returned in the normal return value register R0 (if its
908 size is no greater than one byte), or else the caller must allocate
909 space into which the callee will copy the return value (if the size
910 is greater than one byte). In this case, a pointer to the return
911 value location is passed into the callee in register R2, which does
912 not displace any of the other arguments passed in via registers R4
913 to R7. */
914
915 /* Helper function to justify value in register according to endianess. */
916 static const gdb_byte *
917 sh_justify_value_in_reg (struct gdbarch *gdbarch, struct value *val, int len)
918 {
919 static gdb_byte valbuf[4];
920
921 memset (valbuf, 0, sizeof (valbuf));
922 if (len < 4)
923 {
924 /* value gets right-justified in the register or stack word. */
925 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
926 memcpy (valbuf + (4 - len), value_contents (val), len);
927 else
928 memcpy (valbuf, value_contents (val), len);
929 return valbuf;
930 }
931 return value_contents (val);
932 }
933
934 /* Helper function to eval number of bytes to allocate on stack. */
935 static CORE_ADDR
936 sh_stack_allocsize (int nargs, struct value **args)
937 {
938 int stack_alloc = 0;
939 while (nargs-- > 0)
940 stack_alloc += ((TYPE_LENGTH (value_type (args[nargs])) + 3) & ~3);
941 return stack_alloc;
942 }
943
944 /* Helper functions for getting the float arguments right. Registers usage
945 depends on the ABI and the endianess. The comments should enlighten how
946 it's intended to work. */
947
948 /* This array stores which of the float arg registers are already in use. */
949 static int flt_argreg_array[FLOAT_ARGLAST_REGNUM - FLOAT_ARG0_REGNUM + 1];
950
951 /* This function just resets the above array to "no reg used so far". */
952 static void
953 sh_init_flt_argreg (void)
954 {
955 memset (flt_argreg_array, 0, sizeof flt_argreg_array);
956 }
957
958 /* This function returns the next register to use for float arg passing.
959 It returns either a valid value between FLOAT_ARG0_REGNUM and
960 FLOAT_ARGLAST_REGNUM if a register is available, otherwise it returns
961 FLOAT_ARGLAST_REGNUM + 1 to indicate that no register is available.
962
963 Note that register number 0 in flt_argreg_array corresponds with the
964 real float register fr4. In contrast to FLOAT_ARG0_REGNUM (value is
965 29) the parity of the register number is preserved, which is important
966 for the double register passing test (see the "argreg & 1" test below). */
967 static int
968 sh_next_flt_argreg (struct gdbarch *gdbarch, int len, struct type *func_type)
969 {
970 int argreg;
971
972 /* First search for the next free register. */
973 for (argreg = 0; argreg <= FLOAT_ARGLAST_REGNUM - FLOAT_ARG0_REGNUM;
974 ++argreg)
975 if (!flt_argreg_array[argreg])
976 break;
977
978 /* No register left? */
979 if (argreg > FLOAT_ARGLAST_REGNUM - FLOAT_ARG0_REGNUM)
980 return FLOAT_ARGLAST_REGNUM + 1;
981
982 if (len == 8)
983 {
984 /* Doubles are always starting in a even register number. */
985 if (argreg & 1)
986 {
987 /* In gcc ABI, the skipped register is lost for further argument
988 passing now. Not so in Renesas ABI. */
989 if (!sh_is_renesas_calling_convention (func_type))
990 flt_argreg_array[argreg] = 1;
991
992 ++argreg;
993
994 /* No register left? */
995 if (argreg > FLOAT_ARGLAST_REGNUM - FLOAT_ARG0_REGNUM)
996 return FLOAT_ARGLAST_REGNUM + 1;
997 }
998 /* Also mark the next register as used. */
999 flt_argreg_array[argreg + 1] = 1;
1000 }
1001 else if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE
1002 && !sh_is_renesas_calling_convention (func_type))
1003 {
1004 /* In little endian, gcc passes floats like this: f5, f4, f7, f6, ... */
1005 if (!flt_argreg_array[argreg + 1])
1006 ++argreg;
1007 }
1008 flt_argreg_array[argreg] = 1;
1009 return FLOAT_ARG0_REGNUM + argreg;
1010 }
1011
1012 /* Helper function which figures out, if a type is treated like a float type.
1013
1014 The FPU ABIs have a special way how to treat types as float types.
1015 Structures with exactly one member, which is of type float or double, are
1016 treated exactly as the base types float or double:
1017
1018 struct sf {
1019 float f;
1020 };
1021
1022 struct sd {
1023 double d;
1024 };
1025
1026 are handled the same way as just
1027
1028 float f;
1029
1030 double d;
1031
1032 As a result, arguments of these struct types are pushed into floating point
1033 registers exactly as floats or doubles, using the same decision algorithm.
1034
1035 The same is valid if these types are used as function return types. The
1036 above structs are returned in fr0 resp. fr0,fr1 instead of in r0, r0,r1
1037 or even using struct convention as it is for other structs. */
1038
1039 static int
1040 sh_treat_as_flt_p (struct type *type)
1041 {
1042 /* Ordinary float types are obviously treated as float. */
1043 if (TYPE_CODE (type) == TYPE_CODE_FLT)
1044 return 1;
1045 /* Otherwise non-struct types are not treated as float. */
1046 if (TYPE_CODE (type) != TYPE_CODE_STRUCT)
1047 return 0;
1048 /* Otherwise structs with more than one memeber are not treated as float. */
1049 if (TYPE_NFIELDS (type) != 1)
1050 return 0;
1051 /* Otherwise if the type of that member is float, the whole type is
1052 treated as float. */
1053 if (TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) == TYPE_CODE_FLT)
1054 return 1;
1055 /* Otherwise it's not treated as float. */
1056 return 0;
1057 }
1058
1059 static CORE_ADDR
1060 sh_push_dummy_call_fpu (struct gdbarch *gdbarch,
1061 struct value *function,
1062 struct regcache *regcache,
1063 CORE_ADDR bp_addr, int nargs,
1064 struct value **args,
1065 CORE_ADDR sp, int struct_return,
1066 CORE_ADDR struct_addr)
1067 {
1068 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1069 int stack_offset = 0;
1070 int argreg = ARG0_REGNUM;
1071 int flt_argreg = 0;
1072 int argnum;
1073 struct type *func_type = value_type (function);
1074 struct type *type;
1075 CORE_ADDR regval;
1076 const gdb_byte *val;
1077 int len, reg_size = 0;
1078 int pass_on_stack = 0;
1079 int treat_as_flt;
1080 int last_reg_arg = INT_MAX;
1081
1082 /* The Renesas ABI expects all varargs arguments, plus the last
1083 non-vararg argument to be on the stack, no matter how many
1084 registers have been used so far. */
1085 if (sh_is_renesas_calling_convention (func_type)
1086 && TYPE_VARARGS (func_type))
1087 last_reg_arg = TYPE_NFIELDS (func_type) - 2;
1088
1089 /* First force sp to a 4-byte alignment. */
1090 sp = sh_frame_align (gdbarch, sp);
1091
1092 /* Make room on stack for args. */
1093 sp -= sh_stack_allocsize (nargs, args);
1094
1095 /* Initialize float argument mechanism. */
1096 sh_init_flt_argreg ();
1097
1098 /* Now load as many as possible of the first arguments into
1099 registers, and push the rest onto the stack. There are 16 bytes
1100 in four registers available. Loop thru args from first to last. */
1101 for (argnum = 0; argnum < nargs; argnum++)
1102 {
1103 type = value_type (args[argnum]);
1104 len = TYPE_LENGTH (type);
1105 val = sh_justify_value_in_reg (gdbarch, args[argnum], len);
1106
1107 /* Some decisions have to be made how various types are handled.
1108 This also differs in different ABIs. */
1109 pass_on_stack = 0;
1110
1111 /* Find out the next register to use for a floating point value. */
1112 treat_as_flt = sh_treat_as_flt_p (type);
1113 if (treat_as_flt)
1114 flt_argreg = sh_next_flt_argreg (gdbarch, len, func_type);
1115 /* In Renesas ABI, long longs and aggregate types are always passed
1116 on stack. */
1117 else if (sh_is_renesas_calling_convention (func_type)
1118 && ((TYPE_CODE (type) == TYPE_CODE_INT && len == 8)
1119 || TYPE_CODE (type) == TYPE_CODE_STRUCT
1120 || TYPE_CODE (type) == TYPE_CODE_UNION))
1121 pass_on_stack = 1;
1122 /* In contrast to non-FPU CPUs, arguments are never split between
1123 registers and stack. If an argument doesn't fit in the remaining
1124 registers it's always pushed entirely on the stack. */
1125 else if (len > ((ARGLAST_REGNUM - argreg + 1) * 4))
1126 pass_on_stack = 1;
1127
1128 while (len > 0)
1129 {
1130 if ((treat_as_flt && flt_argreg > FLOAT_ARGLAST_REGNUM)
1131 || (!treat_as_flt && (argreg > ARGLAST_REGNUM
1132 || pass_on_stack))
1133 || argnum > last_reg_arg)
1134 {
1135 /* The data goes entirely on the stack, 4-byte aligned. */
1136 reg_size = (len + 3) & ~3;
1137 write_memory (sp + stack_offset, val, reg_size);
1138 stack_offset += reg_size;
1139 }
1140 else if (treat_as_flt && flt_argreg <= FLOAT_ARGLAST_REGNUM)
1141 {
1142 /* Argument goes in a float argument register. */
1143 reg_size = register_size (gdbarch, flt_argreg);
1144 regval = extract_unsigned_integer (val, reg_size, byte_order);
1145 /* In little endian mode, float types taking two registers
1146 (doubles on sh4, long doubles on sh2e, sh3e and sh4) must
1147 be stored swapped in the argument registers. The below
1148 code first writes the first 32 bits in the next but one
1149 register, increments the val and len values accordingly
1150 and then proceeds as normal by writing the second 32 bits
1151 into the next register. */
1152 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE
1153 && TYPE_LENGTH (type) == 2 * reg_size)
1154 {
1155 regcache_cooked_write_unsigned (regcache, flt_argreg + 1,
1156 regval);
1157 val += reg_size;
1158 len -= reg_size;
1159 regval = extract_unsigned_integer (val, reg_size,
1160 byte_order);
1161 }
1162 regcache_cooked_write_unsigned (regcache, flt_argreg++, regval);
1163 }
1164 else if (!treat_as_flt && argreg <= ARGLAST_REGNUM)
1165 {
1166 /* there's room in a register */
1167 reg_size = register_size (gdbarch, argreg);
1168 regval = extract_unsigned_integer (val, reg_size, byte_order);
1169 regcache_cooked_write_unsigned (regcache, argreg++, regval);
1170 }
1171 /* Store the value one register at a time or in one step on
1172 stack. */
1173 len -= reg_size;
1174 val += reg_size;
1175 }
1176 }
1177
1178 if (struct_return)
1179 {
1180 if (sh_is_renesas_calling_convention (func_type))
1181 /* If the function uses the Renesas ABI, subtract another 4 bytes from
1182 the stack and store the struct return address there. */
1183 write_memory_unsigned_integer (sp -= 4, 4, byte_order, struct_addr);
1184 else
1185 /* Using the gcc ABI, the "struct return pointer" pseudo-argument has
1186 its own dedicated register. */
1187 regcache_cooked_write_unsigned (regcache,
1188 STRUCT_RETURN_REGNUM, struct_addr);
1189 }
1190
1191 /* Store return address. */
1192 regcache_cooked_write_unsigned (regcache, PR_REGNUM, bp_addr);
1193
1194 /* Update stack pointer. */
1195 regcache_cooked_write_unsigned (regcache,
1196 gdbarch_sp_regnum (gdbarch), sp);
1197
1198 return sp;
1199 }
1200
1201 static CORE_ADDR
1202 sh_push_dummy_call_nofpu (struct gdbarch *gdbarch,
1203 struct value *function,
1204 struct regcache *regcache,
1205 CORE_ADDR bp_addr,
1206 int nargs, struct value **args,
1207 CORE_ADDR sp, int struct_return,
1208 CORE_ADDR struct_addr)
1209 {
1210 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1211 int stack_offset = 0;
1212 int argreg = ARG0_REGNUM;
1213 int argnum;
1214 struct type *func_type = value_type (function);
1215 struct type *type;
1216 CORE_ADDR regval;
1217 const gdb_byte *val;
1218 int len, reg_size = 0;
1219 int pass_on_stack = 0;
1220 int last_reg_arg = INT_MAX;
1221
1222 /* The Renesas ABI expects all varargs arguments, plus the last
1223 non-vararg argument to be on the stack, no matter how many
1224 registers have been used so far. */
1225 if (sh_is_renesas_calling_convention (func_type)
1226 && TYPE_VARARGS (func_type))
1227 last_reg_arg = TYPE_NFIELDS (func_type) - 2;
1228
1229 /* First force sp to a 4-byte alignment. */
1230 sp = sh_frame_align (gdbarch, sp);
1231
1232 /* Make room on stack for args. */
1233 sp -= sh_stack_allocsize (nargs, args);
1234
1235 /* Now load as many as possible of the first arguments into
1236 registers, and push the rest onto the stack. There are 16 bytes
1237 in four registers available. Loop thru args from first to last. */
1238 for (argnum = 0; argnum < nargs; argnum++)
1239 {
1240 type = value_type (args[argnum]);
1241 len = TYPE_LENGTH (type);
1242 val = sh_justify_value_in_reg (gdbarch, args[argnum], len);
1243
1244 /* Some decisions have to be made how various types are handled.
1245 This also differs in different ABIs. */
1246 pass_on_stack = 0;
1247 /* Renesas ABI pushes doubles and long longs entirely on stack.
1248 Same goes for aggregate types. */
1249 if (sh_is_renesas_calling_convention (func_type)
1250 && ((TYPE_CODE (type) == TYPE_CODE_INT && len >= 8)
1251 || (TYPE_CODE (type) == TYPE_CODE_FLT && len >= 8)
1252 || TYPE_CODE (type) == TYPE_CODE_STRUCT
1253 || TYPE_CODE (type) == TYPE_CODE_UNION))
1254 pass_on_stack = 1;
1255 while (len > 0)
1256 {
1257 if (argreg > ARGLAST_REGNUM || pass_on_stack
1258 || argnum > last_reg_arg)
1259 {
1260 /* The remainder of the data goes entirely on the stack,
1261 4-byte aligned. */
1262 reg_size = (len + 3) & ~3;
1263 write_memory (sp + stack_offset, val, reg_size);
1264 stack_offset += reg_size;
1265 }
1266 else if (argreg <= ARGLAST_REGNUM)
1267 {
1268 /* There's room in a register. */
1269 reg_size = register_size (gdbarch, argreg);
1270 regval = extract_unsigned_integer (val, reg_size, byte_order);
1271 regcache_cooked_write_unsigned (regcache, argreg++, regval);
1272 }
1273 /* Store the value reg_size bytes at a time. This means that things
1274 larger than reg_size bytes may go partly in registers and partly
1275 on the stack. */
1276 len -= reg_size;
1277 val += reg_size;
1278 }
1279 }
1280
1281 if (struct_return)
1282 {
1283 if (sh_is_renesas_calling_convention (func_type))
1284 /* If the function uses the Renesas ABI, subtract another 4 bytes from
1285 the stack and store the struct return address there. */
1286 write_memory_unsigned_integer (sp -= 4, 4, byte_order, struct_addr);
1287 else
1288 /* Using the gcc ABI, the "struct return pointer" pseudo-argument has
1289 its own dedicated register. */
1290 regcache_cooked_write_unsigned (regcache,
1291 STRUCT_RETURN_REGNUM, struct_addr);
1292 }
1293
1294 /* Store return address. */
1295 regcache_cooked_write_unsigned (regcache, PR_REGNUM, bp_addr);
1296
1297 /* Update stack pointer. */
1298 regcache_cooked_write_unsigned (regcache,
1299 gdbarch_sp_regnum (gdbarch), sp);
1300
1301 return sp;
1302 }
1303
1304 /* Find a function's return value in the appropriate registers (in
1305 regbuf), and copy it into valbuf. Extract from an array REGBUF
1306 containing the (raw) register state a function return value of type
1307 TYPE, and copy that, in virtual format, into VALBUF. */
1308 static void
1309 sh_extract_return_value_nofpu (struct type *type, struct regcache *regcache,
1310 gdb_byte *valbuf)
1311 {
1312 struct gdbarch *gdbarch = get_regcache_arch (regcache);
1313 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1314 int len = TYPE_LENGTH (type);
1315
1316 if (len <= 4)
1317 {
1318 ULONGEST c;
1319
1320 regcache_cooked_read_unsigned (regcache, R0_REGNUM, &c);
1321 store_unsigned_integer (valbuf, len, byte_order, c);
1322 }
1323 else if (len == 8)
1324 {
1325 int i, regnum = R0_REGNUM;
1326 for (i = 0; i < len; i += 4)
1327 regcache_raw_read (regcache, regnum++, valbuf + i);
1328 }
1329 else
1330 error (_("bad size for return value"));
1331 }
1332
1333 static void
1334 sh_extract_return_value_fpu (struct type *type, struct regcache *regcache,
1335 gdb_byte *valbuf)
1336 {
1337 struct gdbarch *gdbarch = get_regcache_arch (regcache);
1338 if (sh_treat_as_flt_p (type))
1339 {
1340 int len = TYPE_LENGTH (type);
1341 int i, regnum = gdbarch_fp0_regnum (gdbarch);
1342 for (i = 0; i < len; i += 4)
1343 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE)
1344 regcache_raw_read (regcache, regnum++,
1345 valbuf + len - 4 - i);
1346 else
1347 regcache_raw_read (regcache, regnum++, valbuf + i);
1348 }
1349 else
1350 sh_extract_return_value_nofpu (type, regcache, valbuf);
1351 }
1352
1353 /* Write into appropriate registers a function return value
1354 of type TYPE, given in virtual format.
1355 If the architecture is sh4 or sh3e, store a function's return value
1356 in the R0 general register or in the FP0 floating point register,
1357 depending on the type of the return value. In all the other cases
1358 the result is stored in r0, left-justified. */
1359 static void
1360 sh_store_return_value_nofpu (struct type *type, struct regcache *regcache,
1361 const gdb_byte *valbuf)
1362 {
1363 struct gdbarch *gdbarch = get_regcache_arch (regcache);
1364 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1365 ULONGEST val;
1366 int len = TYPE_LENGTH (type);
1367
1368 if (len <= 4)
1369 {
1370 val = extract_unsigned_integer (valbuf, len, byte_order);
1371 regcache_cooked_write_unsigned (regcache, R0_REGNUM, val);
1372 }
1373 else
1374 {
1375 int i, regnum = R0_REGNUM;
1376 for (i = 0; i < len; i += 4)
1377 regcache_raw_write (regcache, regnum++, valbuf + i);
1378 }
1379 }
1380
1381 static void
1382 sh_store_return_value_fpu (struct type *type, struct regcache *regcache,
1383 const gdb_byte *valbuf)
1384 {
1385 struct gdbarch *gdbarch = get_regcache_arch (regcache);
1386 if (sh_treat_as_flt_p (type))
1387 {
1388 int len = TYPE_LENGTH (type);
1389 int i, regnum = gdbarch_fp0_regnum (gdbarch);
1390 for (i = 0; i < len; i += 4)
1391 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE)
1392 regcache_raw_write (regcache, regnum++,
1393 valbuf + len - 4 - i);
1394 else
1395 regcache_raw_write (regcache, regnum++, valbuf + i);
1396 }
1397 else
1398 sh_store_return_value_nofpu (type, regcache, valbuf);
1399 }
1400
1401 static enum return_value_convention
1402 sh_return_value_nofpu (struct gdbarch *gdbarch, struct value *function,
1403 struct type *type, struct regcache *regcache,
1404 gdb_byte *readbuf, const gdb_byte *writebuf)
1405 {
1406 struct type *func_type = function ? value_type (function) : NULL;
1407
1408 if (sh_use_struct_convention_nofpu (
1409 sh_is_renesas_calling_convention (func_type), type))
1410 return RETURN_VALUE_STRUCT_CONVENTION;
1411 if (writebuf)
1412 sh_store_return_value_nofpu (type, regcache, writebuf);
1413 else if (readbuf)
1414 sh_extract_return_value_nofpu (type, regcache, readbuf);
1415 return RETURN_VALUE_REGISTER_CONVENTION;
1416 }
1417
1418 static enum return_value_convention
1419 sh_return_value_fpu (struct gdbarch *gdbarch, struct value *function,
1420 struct type *type, struct regcache *regcache,
1421 gdb_byte *readbuf, const gdb_byte *writebuf)
1422 {
1423 struct type *func_type = function ? value_type (function) : NULL;
1424
1425 if (sh_use_struct_convention (
1426 sh_is_renesas_calling_convention (func_type), type))
1427 return RETURN_VALUE_STRUCT_CONVENTION;
1428 if (writebuf)
1429 sh_store_return_value_fpu (type, regcache, writebuf);
1430 else if (readbuf)
1431 sh_extract_return_value_fpu (type, regcache, readbuf);
1432 return RETURN_VALUE_REGISTER_CONVENTION;
1433 }
1434
1435 static struct type *
1436 sh_sh2a_register_type (struct gdbarch *gdbarch, int reg_nr)
1437 {
1438 if ((reg_nr >= gdbarch_fp0_regnum (gdbarch)
1439 && (reg_nr <= FP_LAST_REGNUM)) || (reg_nr == FPUL_REGNUM))
1440 return builtin_type (gdbarch)->builtin_float;
1441 else if (reg_nr >= DR0_REGNUM && reg_nr <= DR_LAST_REGNUM)
1442 return builtin_type (gdbarch)->builtin_double;
1443 else
1444 return builtin_type (gdbarch)->builtin_int;
1445 }
1446
1447 /* Return the GDB type object for the "standard" data type
1448 of data in register N. */
1449 static struct type *
1450 sh_sh3e_register_type (struct gdbarch *gdbarch, int reg_nr)
1451 {
1452 if ((reg_nr >= gdbarch_fp0_regnum (gdbarch)
1453 && (reg_nr <= FP_LAST_REGNUM)) || (reg_nr == FPUL_REGNUM))
1454 return builtin_type (gdbarch)->builtin_float;
1455 else
1456 return builtin_type (gdbarch)->builtin_int;
1457 }
1458
1459 static struct type *
1460 sh_sh4_build_float_register_type (struct gdbarch *gdbarch, int high)
1461 {
1462 return lookup_array_range_type (builtin_type (gdbarch)->builtin_float,
1463 0, high);
1464 }
1465
1466 static struct type *
1467 sh_sh4_register_type (struct gdbarch *gdbarch, int reg_nr)
1468 {
1469 if ((reg_nr >= gdbarch_fp0_regnum (gdbarch)
1470 && (reg_nr <= FP_LAST_REGNUM)) || (reg_nr == FPUL_REGNUM))
1471 return builtin_type (gdbarch)->builtin_float;
1472 else if (reg_nr >= DR0_REGNUM && reg_nr <= DR_LAST_REGNUM)
1473 return builtin_type (gdbarch)->builtin_double;
1474 else if (reg_nr >= FV0_REGNUM && reg_nr <= FV_LAST_REGNUM)
1475 return sh_sh4_build_float_register_type (gdbarch, 3);
1476 else
1477 return builtin_type (gdbarch)->builtin_int;
1478 }
1479
1480 static struct type *
1481 sh_default_register_type (struct gdbarch *gdbarch, int reg_nr)
1482 {
1483 return builtin_type (gdbarch)->builtin_int;
1484 }
1485
1486 /* Is a register in a reggroup?
1487 The default code in reggroup.c doesn't identify system registers, some
1488 float registers or any of the vector registers.
1489 TODO: sh2a and dsp registers. */
1490 static int
1491 sh_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
1492 struct reggroup *reggroup)
1493 {
1494 if (gdbarch_register_name (gdbarch, regnum) == NULL
1495 || *gdbarch_register_name (gdbarch, regnum) == '\0')
1496 return 0;
1497
1498 if (reggroup == float_reggroup
1499 && (regnum == FPUL_REGNUM
1500 || regnum == FPSCR_REGNUM))
1501 return 1;
1502
1503 if (regnum >= FV0_REGNUM && regnum <= FV_LAST_REGNUM)
1504 {
1505 if (reggroup == vector_reggroup || reggroup == float_reggroup)
1506 return 1;
1507 if (reggroup == general_reggroup)
1508 return 0;
1509 }
1510
1511 if (regnum == VBR_REGNUM
1512 || regnum == SR_REGNUM
1513 || regnum == FPSCR_REGNUM
1514 || regnum == SSR_REGNUM
1515 || regnum == SPC_REGNUM)
1516 {
1517 if (reggroup == system_reggroup)
1518 return 1;
1519 if (reggroup == general_reggroup)
1520 return 0;
1521 }
1522
1523 /* The default code can cope with any other registers. */
1524 return default_register_reggroup_p (gdbarch, regnum, reggroup);
1525 }
1526
1527 /* On the sh4, the DRi pseudo registers are problematic if the target
1528 is little endian. When the user writes one of those registers, for
1529 instance with 'set var $dr0=1', we want the double to be stored
1530 like this:
1531 fr0 = 0x00 0x00 0xf0 0x3f
1532 fr1 = 0x00 0x00 0x00 0x00
1533
1534 This corresponds to little endian byte order & big endian word
1535 order. However if we let gdb write the register w/o conversion, it
1536 will write fr0 and fr1 this way:
1537 fr0 = 0x00 0x00 0x00 0x00
1538 fr1 = 0x00 0x00 0xf0 0x3f
1539 because it will consider fr0 and fr1 as a single LE stretch of memory.
1540
1541 To achieve what we want we must force gdb to store things in
1542 floatformat_ieee_double_littlebyte_bigword (which is defined in
1543 include/floatformat.h and libiberty/floatformat.c.
1544
1545 In case the target is big endian, there is no problem, the
1546 raw bytes will look like:
1547 fr0 = 0x3f 0xf0 0x00 0x00
1548 fr1 = 0x00 0x00 0x00 0x00
1549
1550 The other pseudo registers (the FVs) also don't pose a problem
1551 because they are stored as 4 individual FP elements. */
1552
1553 static void
1554 sh_register_convert_to_virtual (struct gdbarch *gdbarch, int regnum,
1555 struct type *type, gdb_byte *from, gdb_byte *to)
1556 {
1557 if (gdbarch_byte_order (gdbarch) != BFD_ENDIAN_LITTLE)
1558 {
1559 /* It is a no-op. */
1560 memcpy (to, from, register_size (gdbarch, regnum));
1561 return;
1562 }
1563
1564 if (regnum >= DR0_REGNUM && regnum <= DR_LAST_REGNUM)
1565 {
1566 DOUBLEST val;
1567 floatformat_to_doublest (&floatformat_ieee_double_littlebyte_bigword,
1568 from, &val);
1569 store_typed_floating (to, type, val);
1570 }
1571 else
1572 error
1573 ("sh_register_convert_to_virtual called with non DR register number");
1574 }
1575
1576 static void
1577 sh_register_convert_to_raw (struct gdbarch *gdbarch, struct type *type,
1578 int regnum, const gdb_byte *from, gdb_byte *to)
1579 {
1580 if (gdbarch_byte_order (gdbarch) != BFD_ENDIAN_LITTLE)
1581 {
1582 /* It is a no-op. */
1583 memcpy (to, from, register_size (gdbarch, regnum));
1584 return;
1585 }
1586
1587 if (regnum >= DR0_REGNUM && regnum <= DR_LAST_REGNUM)
1588 {
1589 DOUBLEST val = extract_typed_floating (from, type);
1590 floatformat_from_doublest (&floatformat_ieee_double_littlebyte_bigword,
1591 &val, to);
1592 }
1593 else
1594 error (_("sh_register_convert_to_raw called with non DR register number"));
1595 }
1596
1597 /* For vectors of 4 floating point registers. */
1598 static int
1599 fv_reg_base_num (struct gdbarch *gdbarch, int fv_regnum)
1600 {
1601 int fp_regnum;
1602
1603 fp_regnum = gdbarch_fp0_regnum (gdbarch)
1604 + (fv_regnum - FV0_REGNUM) * 4;
1605 return fp_regnum;
1606 }
1607
1608 /* For double precision floating point registers, i.e 2 fp regs. */
1609 static int
1610 dr_reg_base_num (struct gdbarch *gdbarch, int dr_regnum)
1611 {
1612 int fp_regnum;
1613
1614 fp_regnum = gdbarch_fp0_regnum (gdbarch)
1615 + (dr_regnum - DR0_REGNUM) * 2;
1616 return fp_regnum;
1617 }
1618
1619 /* Concatenate PORTIONS contiguous raw registers starting at
1620 BASE_REGNUM into BUFFER. */
1621
1622 static enum register_status
1623 pseudo_register_read_portions (struct gdbarch *gdbarch,
1624 struct regcache *regcache,
1625 int portions,
1626 int base_regnum, gdb_byte *buffer)
1627 {
1628 int portion;
1629
1630 for (portion = 0; portion < portions; portion++)
1631 {
1632 enum register_status status;
1633 gdb_byte *b;
1634
1635 b = buffer + register_size (gdbarch, base_regnum) * portion;
1636 status = regcache_raw_read (regcache, base_regnum + portion, b);
1637 if (status != REG_VALID)
1638 return status;
1639 }
1640
1641 return REG_VALID;
1642 }
1643
1644 static enum register_status
1645 sh_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache,
1646 int reg_nr, gdb_byte *buffer)
1647 {
1648 int base_regnum;
1649 gdb_byte temp_buffer[MAX_REGISTER_SIZE];
1650 enum register_status status;
1651
1652 if (reg_nr == PSEUDO_BANK_REGNUM)
1653 return regcache_raw_read (regcache, BANK_REGNUM, buffer);
1654 else if (reg_nr >= DR0_REGNUM && reg_nr <= DR_LAST_REGNUM)
1655 {
1656 base_regnum = dr_reg_base_num (gdbarch, reg_nr);
1657
1658 /* Build the value in the provided buffer. */
1659 /* Read the real regs for which this one is an alias. */
1660 status = pseudo_register_read_portions (gdbarch, regcache,
1661 2, base_regnum, temp_buffer);
1662 if (status == REG_VALID)
1663 {
1664 /* We must pay attention to the endiannes. */
1665 sh_register_convert_to_virtual (gdbarch, reg_nr,
1666 register_type (gdbarch, reg_nr),
1667 temp_buffer, buffer);
1668 }
1669 return status;
1670 }
1671 else if (reg_nr >= FV0_REGNUM && reg_nr <= FV_LAST_REGNUM)
1672 {
1673 base_regnum = fv_reg_base_num (gdbarch, reg_nr);
1674
1675 /* Read the real regs for which this one is an alias. */
1676 return pseudo_register_read_portions (gdbarch, regcache,
1677 4, base_regnum, buffer);
1678 }
1679 else
1680 gdb_assert_not_reached ("invalid pseudo register number");
1681 }
1682
1683 static void
1684 sh_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
1685 int reg_nr, const gdb_byte *buffer)
1686 {
1687 int base_regnum, portion;
1688 gdb_byte temp_buffer[MAX_REGISTER_SIZE];
1689
1690 if (reg_nr == PSEUDO_BANK_REGNUM)
1691 {
1692 /* When the bank register is written to, the whole register bank
1693 is switched and all values in the bank registers must be read
1694 from the target/sim again. We're just invalidating the regcache
1695 so that a re-read happens next time it's necessary. */
1696 int bregnum;
1697
1698 regcache_raw_write (regcache, BANK_REGNUM, buffer);
1699 for (bregnum = R0_BANK0_REGNUM; bregnum < MACLB_REGNUM; ++bregnum)
1700 regcache_invalidate (regcache, bregnum);
1701 }
1702 else if (reg_nr >= DR0_REGNUM && reg_nr <= DR_LAST_REGNUM)
1703 {
1704 base_regnum = dr_reg_base_num (gdbarch, reg_nr);
1705
1706 /* We must pay attention to the endiannes. */
1707 sh_register_convert_to_raw (gdbarch, register_type (gdbarch, reg_nr),
1708 reg_nr, buffer, temp_buffer);
1709
1710 /* Write the real regs for which this one is an alias. */
1711 for (portion = 0; portion < 2; portion++)
1712 regcache_raw_write (regcache, base_regnum + portion,
1713 (temp_buffer
1714 + register_size (gdbarch,
1715 base_regnum) * portion));
1716 }
1717 else if (reg_nr >= FV0_REGNUM && reg_nr <= FV_LAST_REGNUM)
1718 {
1719 base_regnum = fv_reg_base_num (gdbarch, reg_nr);
1720
1721 /* Write the real regs for which this one is an alias. */
1722 for (portion = 0; portion < 4; portion++)
1723 regcache_raw_write (regcache, base_regnum + portion,
1724 (buffer
1725 + register_size (gdbarch,
1726 base_regnum) * portion));
1727 }
1728 }
1729
1730 static int
1731 sh_dsp_register_sim_regno (struct gdbarch *gdbarch, int nr)
1732 {
1733 if (legacy_register_sim_regno (gdbarch, nr) < 0)
1734 return legacy_register_sim_regno (gdbarch, nr);
1735 if (nr >= DSR_REGNUM && nr <= Y1_REGNUM)
1736 return nr - DSR_REGNUM + SIM_SH_DSR_REGNUM;
1737 if (nr == MOD_REGNUM)
1738 return SIM_SH_MOD_REGNUM;
1739 if (nr == RS_REGNUM)
1740 return SIM_SH_RS_REGNUM;
1741 if (nr == RE_REGNUM)
1742 return SIM_SH_RE_REGNUM;
1743 if (nr >= DSP_R0_BANK_REGNUM && nr <= DSP_R7_BANK_REGNUM)
1744 return nr - DSP_R0_BANK_REGNUM + SIM_SH_R0_BANK_REGNUM;
1745 return nr;
1746 }
1747
1748 static int
1749 sh_sh2a_register_sim_regno (struct gdbarch *gdbarch, int nr)
1750 {
1751 switch (nr)
1752 {
1753 case TBR_REGNUM:
1754 return SIM_SH_TBR_REGNUM;
1755 case IBNR_REGNUM:
1756 return SIM_SH_IBNR_REGNUM;
1757 case IBCR_REGNUM:
1758 return SIM_SH_IBCR_REGNUM;
1759 case BANK_REGNUM:
1760 return SIM_SH_BANK_REGNUM;
1761 case MACLB_REGNUM:
1762 return SIM_SH_BANK_MACL_REGNUM;
1763 case GBRB_REGNUM:
1764 return SIM_SH_BANK_GBR_REGNUM;
1765 case PRB_REGNUM:
1766 return SIM_SH_BANK_PR_REGNUM;
1767 case IVNB_REGNUM:
1768 return SIM_SH_BANK_IVN_REGNUM;
1769 case MACHB_REGNUM:
1770 return SIM_SH_BANK_MACH_REGNUM;
1771 default:
1772 break;
1773 }
1774 return legacy_register_sim_regno (gdbarch, nr);
1775 }
1776
1777 /* Set up the register unwinding such that call-clobbered registers are
1778 not displayed in frames >0 because the true value is not certain.
1779 The 'undefined' registers will show up as 'not available' unless the
1780 CFI says otherwise.
1781
1782 This function is currently set up for SH4 and compatible only. */
1783
1784 static void
1785 sh_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum,
1786 struct dwarf2_frame_state_reg *reg,
1787 struct frame_info *this_frame)
1788 {
1789 /* Mark the PC as the destination for the return address. */
1790 if (regnum == gdbarch_pc_regnum (gdbarch))
1791 reg->how = DWARF2_FRAME_REG_RA;
1792
1793 /* Mark the stack pointer as the call frame address. */
1794 else if (regnum == gdbarch_sp_regnum (gdbarch))
1795 reg->how = DWARF2_FRAME_REG_CFA;
1796
1797 /* The above was taken from the default init_reg in dwarf2-frame.c
1798 while the below is SH specific. */
1799
1800 /* Caller save registers. */
1801 else if ((regnum >= R0_REGNUM && regnum <= R0_REGNUM+7)
1802 || (regnum >= FR0_REGNUM && regnum <= FR0_REGNUM+11)
1803 || (regnum >= DR0_REGNUM && regnum <= DR0_REGNUM+5)
1804 || (regnum >= FV0_REGNUM && regnum <= FV0_REGNUM+2)
1805 || (regnum == MACH_REGNUM)
1806 || (regnum == MACL_REGNUM)
1807 || (regnum == FPUL_REGNUM)
1808 || (regnum == SR_REGNUM))
1809 reg->how = DWARF2_FRAME_REG_UNDEFINED;
1810
1811 /* Callee save registers. */
1812 else if ((regnum >= R0_REGNUM+8 && regnum <= R0_REGNUM+15)
1813 || (regnum >= FR0_REGNUM+12 && regnum <= FR0_REGNUM+15)
1814 || (regnum >= DR0_REGNUM+6 && regnum <= DR0_REGNUM+8)
1815 || (regnum == FV0_REGNUM+3))
1816 reg->how = DWARF2_FRAME_REG_SAME_VALUE;
1817
1818 /* Other registers. These are not in the ABI and may or may not
1819 mean anything in frames >0 so don't show them. */
1820 else if ((regnum >= R0_BANK0_REGNUM && regnum <= R0_BANK0_REGNUM+15)
1821 || (regnum == GBR_REGNUM)
1822 || (regnum == VBR_REGNUM)
1823 || (regnum == FPSCR_REGNUM)
1824 || (regnum == SSR_REGNUM)
1825 || (regnum == SPC_REGNUM))
1826 reg->how = DWARF2_FRAME_REG_UNDEFINED;
1827 }
1828
1829 static struct sh_frame_cache *
1830 sh_alloc_frame_cache (void)
1831 {
1832 struct sh_frame_cache *cache;
1833 int i;
1834
1835 cache = FRAME_OBSTACK_ZALLOC (struct sh_frame_cache);
1836
1837 /* Base address. */
1838 cache->base = 0;
1839 cache->saved_sp = 0;
1840 cache->sp_offset = 0;
1841 cache->pc = 0;
1842
1843 /* Frameless until proven otherwise. */
1844 cache->uses_fp = 0;
1845
1846 /* Saved registers. We initialize these to -1 since zero is a valid
1847 offset (that's where fp is supposed to be stored). */
1848 for (i = 0; i < SH_NUM_REGS; i++)
1849 {
1850 cache->saved_regs[i] = -1;
1851 }
1852
1853 return cache;
1854 }
1855
1856 static struct sh_frame_cache *
1857 sh_frame_cache (struct frame_info *this_frame, void **this_cache)
1858 {
1859 struct gdbarch *gdbarch = get_frame_arch (this_frame);
1860 struct sh_frame_cache *cache;
1861 CORE_ADDR current_pc;
1862 int i;
1863
1864 if (*this_cache)
1865 return (struct sh_frame_cache *) *this_cache;
1866
1867 cache = sh_alloc_frame_cache ();
1868 *this_cache = cache;
1869
1870 /* In principle, for normal frames, fp holds the frame pointer,
1871 which holds the base address for the current stack frame.
1872 However, for functions that don't need it, the frame pointer is
1873 optional. For these "frameless" functions the frame pointer is
1874 actually the frame pointer of the calling frame. */
1875 cache->base = get_frame_register_unsigned (this_frame, FP_REGNUM);
1876 if (cache->base == 0)
1877 return cache;
1878
1879 cache->pc = get_frame_func (this_frame);
1880 current_pc = get_frame_pc (this_frame);
1881 if (cache->pc != 0)
1882 {
1883 ULONGEST fpscr;
1884
1885 /* Check for the existence of the FPSCR register. If it exists,
1886 fetch its value for use in prologue analysis. Passing a zero
1887 value is the best choice for architecture variants upon which
1888 there's no FPSCR register. */
1889 if (gdbarch_register_reggroup_p (gdbarch, FPSCR_REGNUM, all_reggroup))
1890 fpscr = get_frame_register_unsigned (this_frame, FPSCR_REGNUM);
1891 else
1892 fpscr = 0;
1893
1894 sh_analyze_prologue (gdbarch, cache->pc, current_pc, cache, fpscr);
1895 }
1896
1897 if (!cache->uses_fp)
1898 {
1899 /* We didn't find a valid frame, which means that CACHE->base
1900 currently holds the frame pointer for our calling frame. If
1901 we're at the start of a function, or somewhere half-way its
1902 prologue, the function's frame probably hasn't been fully
1903 setup yet. Try to reconstruct the base address for the stack
1904 frame by looking at the stack pointer. For truly "frameless"
1905 functions this might work too. */
1906 cache->base = get_frame_register_unsigned
1907 (this_frame, gdbarch_sp_regnum (gdbarch));
1908 }
1909
1910 /* Now that we have the base address for the stack frame we can
1911 calculate the value of sp in the calling frame. */
1912 cache->saved_sp = cache->base + cache->sp_offset;
1913
1914 /* Adjust all the saved registers such that they contain addresses
1915 instead of offsets. */
1916 for (i = 0; i < SH_NUM_REGS; i++)
1917 if (cache->saved_regs[i] != -1)
1918 cache->saved_regs[i] = cache->saved_sp - cache->saved_regs[i] - 4;
1919
1920 return cache;
1921 }
1922
1923 static struct value *
1924 sh_frame_prev_register (struct frame_info *this_frame,
1925 void **this_cache, int regnum)
1926 {
1927 struct gdbarch *gdbarch = get_frame_arch (this_frame);
1928 struct sh_frame_cache *cache = sh_frame_cache (this_frame, this_cache);
1929
1930 gdb_assert (regnum >= 0);
1931
1932 if (regnum == gdbarch_sp_regnum (gdbarch) && cache->saved_sp)
1933 return frame_unwind_got_constant (this_frame, regnum, cache->saved_sp);
1934
1935 /* The PC of the previous frame is stored in the PR register of
1936 the current frame. Frob regnum so that we pull the value from
1937 the correct place. */
1938 if (regnum == gdbarch_pc_regnum (gdbarch))
1939 regnum = PR_REGNUM;
1940
1941 if (regnum < SH_NUM_REGS && cache->saved_regs[regnum] != -1)
1942 return frame_unwind_got_memory (this_frame, regnum,
1943 cache->saved_regs[regnum]);
1944
1945 return frame_unwind_got_register (this_frame, regnum, regnum);
1946 }
1947
1948 static void
1949 sh_frame_this_id (struct frame_info *this_frame, void **this_cache,
1950 struct frame_id *this_id)
1951 {
1952 struct sh_frame_cache *cache = sh_frame_cache (this_frame, this_cache);
1953
1954 /* This marks the outermost frame. */
1955 if (cache->base == 0)
1956 return;
1957
1958 *this_id = frame_id_build (cache->saved_sp, cache->pc);
1959 }
1960
1961 static const struct frame_unwind sh_frame_unwind = {
1962 NORMAL_FRAME,
1963 default_frame_unwind_stop_reason,
1964 sh_frame_this_id,
1965 sh_frame_prev_register,
1966 NULL,
1967 default_frame_sniffer
1968 };
1969
1970 static CORE_ADDR
1971 sh_unwind_sp (struct gdbarch *gdbarch, struct frame_info *next_frame)
1972 {
1973 return frame_unwind_register_unsigned (next_frame,
1974 gdbarch_sp_regnum (gdbarch));
1975 }
1976
1977 static CORE_ADDR
1978 sh_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
1979 {
1980 return frame_unwind_register_unsigned (next_frame,
1981 gdbarch_pc_regnum (gdbarch));
1982 }
1983
1984 static struct frame_id
1985 sh_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame)
1986 {
1987 CORE_ADDR sp = get_frame_register_unsigned (this_frame,
1988 gdbarch_sp_regnum (gdbarch));
1989 return frame_id_build (sp, get_frame_pc (this_frame));
1990 }
1991
1992 static CORE_ADDR
1993 sh_frame_base_address (struct frame_info *this_frame, void **this_cache)
1994 {
1995 struct sh_frame_cache *cache = sh_frame_cache (this_frame, this_cache);
1996
1997 return cache->base;
1998 }
1999
2000 static const struct frame_base sh_frame_base = {
2001 &sh_frame_unwind,
2002 sh_frame_base_address,
2003 sh_frame_base_address,
2004 sh_frame_base_address
2005 };
2006
2007 static struct sh_frame_cache *
2008 sh_make_stub_cache (struct frame_info *this_frame)
2009 {
2010 struct gdbarch *gdbarch = get_frame_arch (this_frame);
2011 struct sh_frame_cache *cache;
2012
2013 cache = sh_alloc_frame_cache ();
2014
2015 cache->saved_sp
2016 = get_frame_register_unsigned (this_frame, gdbarch_sp_regnum (gdbarch));
2017
2018 return cache;
2019 }
2020
2021 static void
2022 sh_stub_this_id (struct frame_info *this_frame, void **this_cache,
2023 struct frame_id *this_id)
2024 {
2025 struct sh_frame_cache *cache;
2026
2027 if (*this_cache == NULL)
2028 *this_cache = sh_make_stub_cache (this_frame);
2029 cache = (struct sh_frame_cache *) *this_cache;
2030
2031 *this_id = frame_id_build (cache->saved_sp, get_frame_pc (this_frame));
2032 }
2033
2034 static int
2035 sh_stub_unwind_sniffer (const struct frame_unwind *self,
2036 struct frame_info *this_frame,
2037 void **this_prologue_cache)
2038 {
2039 CORE_ADDR addr_in_block;
2040
2041 addr_in_block = get_frame_address_in_block (this_frame);
2042 if (in_plt_section (addr_in_block))
2043 return 1;
2044
2045 return 0;
2046 }
2047
2048 static const struct frame_unwind sh_stub_unwind =
2049 {
2050 NORMAL_FRAME,
2051 default_frame_unwind_stop_reason,
2052 sh_stub_this_id,
2053 sh_frame_prev_register,
2054 NULL,
2055 sh_stub_unwind_sniffer
2056 };
2057
2058 /* Implement the stack_frame_destroyed_p gdbarch method.
2059
2060 The epilogue is defined here as the area at the end of a function,
2061 either on the `ret' instruction itself or after an instruction which
2062 destroys the function's stack frame. */
2063
2064 static int
2065 sh_stack_frame_destroyed_p (struct gdbarch *gdbarch, CORE_ADDR pc)
2066 {
2067 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
2068 CORE_ADDR func_addr = 0, func_end = 0;
2069
2070 if (find_pc_partial_function (pc, NULL, &func_addr, &func_end))
2071 {
2072 ULONGEST inst;
2073 /* The sh epilogue is max. 14 bytes long. Give another 14 bytes
2074 for a nop and some fixed data (e.g. big offsets) which are
2075 unfortunately also treated as part of the function (which
2076 means, they are below func_end. */
2077 CORE_ADDR addr = func_end - 28;
2078 if (addr < func_addr + 4)
2079 addr = func_addr + 4;
2080 if (pc < addr)
2081 return 0;
2082
2083 /* First search forward until hitting an rts. */
2084 while (addr < func_end
2085 && !IS_RTS (read_memory_unsigned_integer (addr, 2, byte_order)))
2086 addr += 2;
2087 if (addr >= func_end)
2088 return 0;
2089
2090 /* At this point we should find a mov.l @r15+,r14 instruction,
2091 either before or after the rts. If not, then the function has
2092 probably no "normal" epilogue and we bail out here. */
2093 inst = read_memory_unsigned_integer (addr - 2, 2, byte_order);
2094 if (IS_RESTORE_FP (read_memory_unsigned_integer (addr - 2, 2,
2095 byte_order)))
2096 addr -= 2;
2097 else if (!IS_RESTORE_FP (read_memory_unsigned_integer (addr + 2, 2,
2098 byte_order)))
2099 return 0;
2100
2101 inst = read_memory_unsigned_integer (addr - 2, 2, byte_order);
2102
2103 /* Step over possible lds.l @r15+,macl. */
2104 if (IS_MACL_LDS (inst))
2105 {
2106 addr -= 2;
2107 inst = read_memory_unsigned_integer (addr - 2, 2, byte_order);
2108 }
2109
2110 /* Step over possible lds.l @r15+,pr. */
2111 if (IS_LDS (inst))
2112 {
2113 addr -= 2;
2114 inst = read_memory_unsigned_integer (addr - 2, 2, byte_order);
2115 }
2116
2117 /* Step over possible mov r14,r15. */
2118 if (IS_MOV_FP_SP (inst))
2119 {
2120 addr -= 2;
2121 inst = read_memory_unsigned_integer (addr - 2, 2, byte_order);
2122 }
2123
2124 /* Now check for FP adjustments, using add #imm,r14 or add rX, r14
2125 instructions. */
2126 while (addr > func_addr + 4
2127 && (IS_ADD_REG_TO_FP (inst) || IS_ADD_IMM_FP (inst)))
2128 {
2129 addr -= 2;
2130 inst = read_memory_unsigned_integer (addr - 2, 2, byte_order);
2131 }
2132
2133 /* On SH2a check if the previous instruction was perhaps a MOVI20.
2134 That's allowed for the epilogue. */
2135 if ((gdbarch_bfd_arch_info (gdbarch)->mach == bfd_mach_sh2a
2136 || gdbarch_bfd_arch_info (gdbarch)->mach == bfd_mach_sh2a_nofpu)
2137 && addr > func_addr + 6
2138 && IS_MOVI20 (read_memory_unsigned_integer (addr - 4, 2,
2139 byte_order)))
2140 addr -= 4;
2141
2142 if (pc >= addr)
2143 return 1;
2144 }
2145 return 0;
2146 }
2147
2148
2149 /* Supply register REGNUM from the buffer specified by REGS and LEN
2150 in the register set REGSET to register cache REGCACHE.
2151 REGTABLE specifies where each register can be found in REGS.
2152 If REGNUM is -1, do this for all registers in REGSET. */
2153
2154 void
2155 sh_corefile_supply_regset (const struct regset *regset,
2156 struct regcache *regcache,
2157 int regnum, const void *regs, size_t len)
2158 {
2159 struct gdbarch *gdbarch = get_regcache_arch (regcache);
2160 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
2161 const struct sh_corefile_regmap *regmap = (regset == &sh_corefile_gregset
2162 ? tdep->core_gregmap
2163 : tdep->core_fpregmap);
2164 int i;
2165
2166 for (i = 0; regmap[i].regnum != -1; i++)
2167 {
2168 if ((regnum == -1 || regnum == regmap[i].regnum)
2169 && regmap[i].offset + 4 <= len)
2170 regcache_raw_supply (regcache, regmap[i].regnum,
2171 (char *)regs + regmap[i].offset);
2172 }
2173 }
2174
2175 /* Collect register REGNUM in the register set REGSET from register cache
2176 REGCACHE into the buffer specified by REGS and LEN.
2177 REGTABLE specifies where each register can be found in REGS.
2178 If REGNUM is -1, do this for all registers in REGSET. */
2179
2180 void
2181 sh_corefile_collect_regset (const struct regset *regset,
2182 const struct regcache *regcache,
2183 int regnum, void *regs, size_t len)
2184 {
2185 struct gdbarch *gdbarch = get_regcache_arch (regcache);
2186 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
2187 const struct sh_corefile_regmap *regmap = (regset == &sh_corefile_gregset
2188 ? tdep->core_gregmap
2189 : tdep->core_fpregmap);
2190 int i;
2191
2192 for (i = 0; regmap[i].regnum != -1; i++)
2193 {
2194 if ((regnum == -1 || regnum == regmap[i].regnum)
2195 && regmap[i].offset + 4 <= len)
2196 regcache_raw_collect (regcache, regmap[i].regnum,
2197 (char *)regs + regmap[i].offset);
2198 }
2199 }
2200
2201 /* The following two regsets have the same contents, so it is tempting to
2202 unify them, but they are distiguished by their address, so don't. */
2203
2204 const struct regset sh_corefile_gregset =
2205 {
2206 NULL,
2207 sh_corefile_supply_regset,
2208 sh_corefile_collect_regset
2209 };
2210
2211 static const struct regset sh_corefile_fpregset =
2212 {
2213 NULL,
2214 sh_corefile_supply_regset,
2215 sh_corefile_collect_regset
2216 };
2217
2218 static void
2219 sh_iterate_over_regset_sections (struct gdbarch *gdbarch,
2220 iterate_over_regset_sections_cb *cb,
2221 void *cb_data,
2222 const struct regcache *regcache)
2223 {
2224 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
2225
2226 if (tdep->core_gregmap != NULL)
2227 cb (".reg", tdep->sizeof_gregset, &sh_corefile_gregset, NULL, cb_data);
2228
2229 if (tdep->core_fpregmap != NULL)
2230 cb (".reg2", tdep->sizeof_fpregset, &sh_corefile_fpregset, NULL, cb_data);
2231 }
2232
2233 /* This is the implementation of gdbarch method
2234 return_in_first_hidden_param_p. */
2235
2236 static int
2237 sh_return_in_first_hidden_param_p (struct gdbarch *gdbarch,
2238 struct type *type)
2239 {
2240 return 0;
2241 }
2242
2243 \f
2244
2245 static struct gdbarch *
2246 sh_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
2247 {
2248 struct gdbarch *gdbarch;
2249 struct gdbarch_tdep *tdep;
2250
2251 /* SH5 is handled entirely in sh64-tdep.c. */
2252 if (info.bfd_arch_info->mach == bfd_mach_sh5)
2253 return sh64_gdbarch_init (info, arches);
2254
2255 /* If there is already a candidate, use it. */
2256 arches = gdbarch_list_lookup_by_info (arches, &info);
2257 if (arches != NULL)
2258 return arches->gdbarch;
2259
2260 /* None found, create a new architecture from the information
2261 provided. */
2262 tdep = XCNEW (struct gdbarch_tdep);
2263 gdbarch = gdbarch_alloc (&info, tdep);
2264
2265 set_gdbarch_short_bit (gdbarch, 2 * TARGET_CHAR_BIT);
2266 set_gdbarch_int_bit (gdbarch, 4 * TARGET_CHAR_BIT);
2267 set_gdbarch_long_bit (gdbarch, 4 * TARGET_CHAR_BIT);
2268 set_gdbarch_long_long_bit (gdbarch, 8 * TARGET_CHAR_BIT);
2269 set_gdbarch_float_bit (gdbarch, 4 * TARGET_CHAR_BIT);
2270 set_gdbarch_double_bit (gdbarch, 8 * TARGET_CHAR_BIT);
2271 set_gdbarch_long_double_bit (gdbarch, 8 * TARGET_CHAR_BIT);
2272 set_gdbarch_ptr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
2273
2274 set_gdbarch_num_regs (gdbarch, SH_NUM_REGS);
2275 set_gdbarch_sp_regnum (gdbarch, 15);
2276 set_gdbarch_pc_regnum (gdbarch, 16);
2277 set_gdbarch_fp0_regnum (gdbarch, -1);
2278 set_gdbarch_num_pseudo_regs (gdbarch, 0);
2279
2280 set_gdbarch_register_type (gdbarch, sh_default_register_type);
2281 set_gdbarch_register_reggroup_p (gdbarch, sh_register_reggroup_p);
2282
2283 SET_GDBARCH_BREAKPOINT_MANIPULATION (sh);
2284
2285 set_gdbarch_print_insn (gdbarch, print_insn_sh);
2286 set_gdbarch_register_sim_regno (gdbarch, legacy_register_sim_regno);
2287
2288 set_gdbarch_return_value (gdbarch, sh_return_value_nofpu);
2289
2290 set_gdbarch_skip_prologue (gdbarch, sh_skip_prologue);
2291 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
2292
2293 set_gdbarch_push_dummy_call (gdbarch, sh_push_dummy_call_nofpu);
2294 set_gdbarch_return_in_first_hidden_param_p (gdbarch,
2295 sh_return_in_first_hidden_param_p);
2296
2297 set_gdbarch_believe_pcc_promotion (gdbarch, 1);
2298
2299 set_gdbarch_frame_align (gdbarch, sh_frame_align);
2300 set_gdbarch_unwind_sp (gdbarch, sh_unwind_sp);
2301 set_gdbarch_unwind_pc (gdbarch, sh_unwind_pc);
2302 set_gdbarch_dummy_id (gdbarch, sh_dummy_id);
2303 frame_base_set_default (gdbarch, &sh_frame_base);
2304
2305 set_gdbarch_stack_frame_destroyed_p (gdbarch, sh_stack_frame_destroyed_p);
2306
2307 dwarf2_frame_set_init_reg (gdbarch, sh_dwarf2_frame_init_reg);
2308
2309 set_gdbarch_iterate_over_regset_sections
2310 (gdbarch, sh_iterate_over_regset_sections);
2311
2312 switch (info.bfd_arch_info->mach)
2313 {
2314 case bfd_mach_sh:
2315 set_gdbarch_register_name (gdbarch, sh_sh_register_name);
2316 break;
2317
2318 case bfd_mach_sh2:
2319 set_gdbarch_register_name (gdbarch, sh_sh_register_name);
2320 break;
2321
2322 case bfd_mach_sh2e:
2323 /* doubles on sh2e and sh3e are actually 4 byte. */
2324 set_gdbarch_double_bit (gdbarch, 4 * TARGET_CHAR_BIT);
2325 set_gdbarch_double_format (gdbarch, floatformats_ieee_single);
2326
2327 set_gdbarch_register_name (gdbarch, sh_sh2e_register_name);
2328 set_gdbarch_register_type (gdbarch, sh_sh3e_register_type);
2329 set_gdbarch_fp0_regnum (gdbarch, 25);
2330 set_gdbarch_return_value (gdbarch, sh_return_value_fpu);
2331 set_gdbarch_push_dummy_call (gdbarch, sh_push_dummy_call_fpu);
2332 break;
2333
2334 case bfd_mach_sh2a:
2335 set_gdbarch_register_name (gdbarch, sh_sh2a_register_name);
2336 set_gdbarch_register_type (gdbarch, sh_sh2a_register_type);
2337 set_gdbarch_register_sim_regno (gdbarch, sh_sh2a_register_sim_regno);
2338
2339 set_gdbarch_fp0_regnum (gdbarch, 25);
2340 set_gdbarch_num_pseudo_regs (gdbarch, 9);
2341 set_gdbarch_pseudo_register_read (gdbarch, sh_pseudo_register_read);
2342 set_gdbarch_pseudo_register_write (gdbarch, sh_pseudo_register_write);
2343 set_gdbarch_return_value (gdbarch, sh_return_value_fpu);
2344 set_gdbarch_push_dummy_call (gdbarch, sh_push_dummy_call_fpu);
2345 break;
2346
2347 case bfd_mach_sh2a_nofpu:
2348 set_gdbarch_register_name (gdbarch, sh_sh2a_nofpu_register_name);
2349 set_gdbarch_register_sim_regno (gdbarch, sh_sh2a_register_sim_regno);
2350
2351 set_gdbarch_num_pseudo_regs (gdbarch, 1);
2352 set_gdbarch_pseudo_register_read (gdbarch, sh_pseudo_register_read);
2353 set_gdbarch_pseudo_register_write (gdbarch, sh_pseudo_register_write);
2354 break;
2355
2356 case bfd_mach_sh_dsp:
2357 set_gdbarch_register_name (gdbarch, sh_sh_dsp_register_name);
2358 set_gdbarch_register_sim_regno (gdbarch, sh_dsp_register_sim_regno);
2359 break;
2360
2361 case bfd_mach_sh3:
2362 case bfd_mach_sh3_nommu:
2363 case bfd_mach_sh2a_nofpu_or_sh3_nommu:
2364 set_gdbarch_register_name (gdbarch, sh_sh3_register_name);
2365 break;
2366
2367 case bfd_mach_sh3e:
2368 case bfd_mach_sh2a_or_sh3e:
2369 /* doubles on sh2e and sh3e are actually 4 byte. */
2370 set_gdbarch_double_bit (gdbarch, 4 * TARGET_CHAR_BIT);
2371 set_gdbarch_double_format (gdbarch, floatformats_ieee_single);
2372
2373 set_gdbarch_register_name (gdbarch, sh_sh3e_register_name);
2374 set_gdbarch_register_type (gdbarch, sh_sh3e_register_type);
2375 set_gdbarch_fp0_regnum (gdbarch, 25);
2376 set_gdbarch_return_value (gdbarch, sh_return_value_fpu);
2377 set_gdbarch_push_dummy_call (gdbarch, sh_push_dummy_call_fpu);
2378 break;
2379
2380 case bfd_mach_sh3_dsp:
2381 set_gdbarch_register_name (gdbarch, sh_sh3_dsp_register_name);
2382 set_gdbarch_register_sim_regno (gdbarch, sh_dsp_register_sim_regno);
2383 break;
2384
2385 case bfd_mach_sh4:
2386 case bfd_mach_sh4a:
2387 case bfd_mach_sh2a_or_sh4:
2388 set_gdbarch_register_name (gdbarch, sh_sh4_register_name);
2389 set_gdbarch_register_type (gdbarch, sh_sh4_register_type);
2390 set_gdbarch_fp0_regnum (gdbarch, 25);
2391 set_gdbarch_num_pseudo_regs (gdbarch, 13);
2392 set_gdbarch_pseudo_register_read (gdbarch, sh_pseudo_register_read);
2393 set_gdbarch_pseudo_register_write (gdbarch, sh_pseudo_register_write);
2394 set_gdbarch_return_value (gdbarch, sh_return_value_fpu);
2395 set_gdbarch_push_dummy_call (gdbarch, sh_push_dummy_call_fpu);
2396 break;
2397
2398 case bfd_mach_sh4_nofpu:
2399 case bfd_mach_sh4a_nofpu:
2400 case bfd_mach_sh4_nommu_nofpu:
2401 case bfd_mach_sh2a_nofpu_or_sh4_nommu_nofpu:
2402 set_gdbarch_register_name (gdbarch, sh_sh4_nofpu_register_name);
2403 break;
2404
2405 case bfd_mach_sh4al_dsp:
2406 set_gdbarch_register_name (gdbarch, sh_sh4al_dsp_register_name);
2407 set_gdbarch_register_sim_regno (gdbarch, sh_dsp_register_sim_regno);
2408 break;
2409
2410 default:
2411 set_gdbarch_register_name (gdbarch, sh_sh_register_name);
2412 break;
2413 }
2414
2415 /* Hook in ABI-specific overrides, if they have been registered. */
2416 gdbarch_init_osabi (info, gdbarch);
2417
2418 dwarf2_append_unwinders (gdbarch);
2419 frame_unwind_append_unwinder (gdbarch, &sh_stub_unwind);
2420 frame_unwind_append_unwinder (gdbarch, &sh_frame_unwind);
2421
2422 return gdbarch;
2423 }
2424
2425 static void
2426 show_sh_command (char *args, int from_tty)
2427 {
2428 help_list (showshcmdlist, "show sh ", all_commands, gdb_stdout);
2429 }
2430
2431 static void
2432 set_sh_command (char *args, int from_tty)
2433 {
2434 printf_unfiltered
2435 ("\"set sh\" must be followed by an appropriate subcommand.\n");
2436 help_list (setshcmdlist, "set sh ", all_commands, gdb_stdout);
2437 }
2438
2439 extern initialize_file_ftype _initialize_sh_tdep; /* -Wmissing-prototypes */
2440
2441 void
2442 _initialize_sh_tdep (void)
2443 {
2444 gdbarch_register (bfd_arch_sh, sh_gdbarch_init, NULL);
2445
2446 add_prefix_cmd ("sh", no_class, set_sh_command, "SH specific commands.",
2447 &setshcmdlist, "set sh ", 0, &setlist);
2448 add_prefix_cmd ("sh", no_class, show_sh_command, "SH specific commands.",
2449 &showshcmdlist, "show sh ", 0, &showlist);
2450
2451 add_setshow_enum_cmd ("calling-convention", class_vars, sh_cc_enum,
2452 &sh_active_calling_convention,
2453 _("Set calling convention used when calling target "
2454 "functions from GDB."),
2455 _("Show calling convention used when calling target "
2456 "functions from GDB."),
2457 _("gcc - Use GCC calling convention (default).\n"
2458 "renesas - Enforce Renesas calling convention."),
2459 NULL, NULL,
2460 &setshcmdlist, &showshcmdlist);
2461 }
This page took 0.137079 seconds and 5 git commands to generate.