* configure: Regenerate with proper autoconf 2.13.
[deliverable/binutils-gdb.git] / gdb / sh-tdep.c
CommitLineData
c906108c 1/* Target-dependent code for Hitachi Super-H, for GDB.
1e698235 2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
3116c80a 3 Free Software Foundation, Inc.
c906108c 4
c5aa993b 5 This file is part of GDB.
c906108c 6
c5aa993b
JM
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
c906108c 11
c5aa993b
JM
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.
c906108c 16
c5aa993b
JM
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
c906108c
SS
21
22/*
c5aa993b
JM
23 Contributed by Steve Chamberlain
24 sac@cygnus.com
c906108c
SS
25 */
26
27#include "defs.h"
28#include "frame.h"
c906108c
SS
29#include "symtab.h"
30#include "symfile.h"
31#include "gdbtypes.h"
32#include "gdbcmd.h"
33#include "gdbcore.h"
34#include "value.h"
35#include "dis-asm.h"
36#include "inferior.h" /* for BEFORE_TEXT_END etc. */
37#include "gdb_string.h"
b4a20239 38#include "arch-utils.h"
fb409745 39#include "floatformat.h"
4e052eda 40#include "regcache.h"
d16aafd8 41#include "doublest.h"
4be87837 42#include "osabi.h"
c906108c 43
ab3b8126
JT
44#include "sh-tdep.h"
45
d658f924 46#include "elf-bfd.h"
1a8629c7
MS
47#include "solib-svr4.h"
48
283150cd
EZ
49/* sh64 flags */
50#include "elf/sh.h"
51/* registers numbers shared with the simulator */
1c922164 52#include "gdb/sim-sh.h"
283150cd 53
53116e27 54void (*sh_show_regs) (void);
3bbfbb92
EZ
55CORE_ADDR (*skip_prologue_hard_way) (CORE_ADDR);
56void (*do_pseudo_register) (int);
cc17453a 57
88e04cc1
EZ
58#define SH_DEFAULT_NUM_REGS 59
59
cc17453a
EZ
60/* Define other aspects of the stack frame.
61 we keep a copy of the worked out return pc lying around, since it
62 is a useful bit of info */
63
64struct frame_extra_info
65{
66 CORE_ADDR return_pc;
67 int leaf_function;
68 int f_offset;
63978407 69};
c906108c 70
fa88f677 71static const char *
cc17453a 72sh_generic_register_name (int reg_nr)
c5aa993b 73{
cc17453a 74 static char *register_names[] =
c5aa993b 75 {
cc17453a
EZ
76 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
77 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
78 "pc", "pr", "gbr", "vbr", "mach", "macl", "sr",
79 "fpul", "fpscr",
80 "fr0", "fr1", "fr2", "fr3", "fr4", "fr5", "fr6", "fr7",
81 "fr8", "fr9", "fr10", "fr11", "fr12", "fr13", "fr14", "fr15",
82 "ssr", "spc",
83 "r0b0", "r1b0", "r2b0", "r3b0", "r4b0", "r5b0", "r6b0", "r7b0",
84 "r0b1", "r1b1", "r2b1", "r3b1", "r4b1", "r5b1", "r6b1", "r7b1",
85 };
86 if (reg_nr < 0)
87 return NULL;
88 if (reg_nr >= (sizeof (register_names) / sizeof (*register_names)))
89 return NULL;
90 return register_names[reg_nr];
91}
92
fa88f677 93static const char *
cc17453a
EZ
94sh_sh_register_name (int reg_nr)
95{
96 static char *register_names[] =
63978407 97 {
cc17453a
EZ
98 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
99 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
100 "pc", "pr", "gbr", "vbr", "mach", "macl", "sr",
101 "", "",
102 "", "", "", "", "", "", "", "",
103 "", "", "", "", "", "", "", "",
104 "", "",
105 "", "", "", "", "", "", "", "",
106 "", "", "", "", "", "", "", "",
107 };
108 if (reg_nr < 0)
109 return NULL;
110 if (reg_nr >= (sizeof (register_names) / sizeof (*register_names)))
111 return NULL;
112 return register_names[reg_nr];
113}
114
fa88f677 115static const char *
cc17453a
EZ
116sh_sh3_register_name (int reg_nr)
117{
118 static char *register_names[] =
c5aa993b 119 {
cc17453a
EZ
120 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
121 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
122 "pc", "pr", "gbr", "vbr", "mach", "macl", "sr",
123 "", "",
124 "", "", "", "", "", "", "", "",
125 "", "", "", "", "", "", "", "",
126 "ssr", "spc",
127 "r0b0", "r1b0", "r2b0", "r3b0", "r4b0", "r5b0", "r6b0", "r7b0",
128 "r0b1", "r1b1", "r2b1", "r3b1", "r4b1", "r5b1", "r6b1", "r7b1"
129 };
130 if (reg_nr < 0)
131 return NULL;
132 if (reg_nr >= (sizeof (register_names) / sizeof (*register_names)))
133 return NULL;
134 return register_names[reg_nr];
135}
136
fa88f677 137static const char *
cc17453a
EZ
138sh_sh3e_register_name (int reg_nr)
139{
140 static char *register_names[] =
63978407 141 {
cc17453a
EZ
142 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
143 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
144 "pc", "pr", "gbr", "vbr", "mach", "macl", "sr",
145 "fpul", "fpscr",
146 "fr0", "fr1", "fr2", "fr3", "fr4", "fr5", "fr6", "fr7",
147 "fr8", "fr9", "fr10", "fr11", "fr12", "fr13", "fr14", "fr15",
148 "ssr", "spc",
149 "r0b0", "r1b0", "r2b0", "r3b0", "r4b0", "r5b0", "r6b0", "r7b0",
150 "r0b1", "r1b1", "r2b1", "r3b1", "r4b1", "r5b1", "r6b1", "r7b1",
151 };
152 if (reg_nr < 0)
153 return NULL;
154 if (reg_nr >= (sizeof (register_names) / sizeof (*register_names)))
155 return NULL;
156 return register_names[reg_nr];
157}
158
fa88f677 159static const char *
cc17453a
EZ
160sh_sh_dsp_register_name (int reg_nr)
161{
162 static char *register_names[] =
c5aa993b 163 {
cc17453a
EZ
164 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
165 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
166 "pc", "pr", "gbr", "vbr", "mach", "macl", "sr",
167 "", "dsr",
168 "a0g", "a0", "a1g", "a1", "m0", "m1", "x0", "x1",
169 "y0", "y1", "", "", "", "", "", "mod",
170 "", "",
171 "rs", "re", "", "", "", "", "", "",
172 "", "", "", "", "", "", "", "",
173 };
174 if (reg_nr < 0)
175 return NULL;
176 if (reg_nr >= (sizeof (register_names) / sizeof (*register_names)))
177 return NULL;
178 return register_names[reg_nr];
179}
180
fa88f677 181static const char *
cc17453a
EZ
182sh_sh3_dsp_register_name (int reg_nr)
183{
184 static char *register_names[] =
c5aa993b 185 {
cc17453a
EZ
186 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
187 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
188 "pc", "pr", "gbr", "vbr", "mach", "macl", "sr",
189 "", "dsr",
190 "a0g", "a0", "a1g", "a1", "m0", "m1", "x0", "x1",
191 "y0", "y1", "", "", "", "", "", "mod",
192 "ssr", "spc",
193 "rs", "re", "", "", "", "", "", "",
194 "r0b", "r1b", "r2b", "r3b", "r4b", "r5b", "r6b", "r7b"
195 "", "", "", "", "", "", "", "",
196 };
197 if (reg_nr < 0)
198 return NULL;
199 if (reg_nr >= (sizeof (register_names) / sizeof (*register_names)))
200 return NULL;
201 return register_names[reg_nr];
202}
203
fa88f677 204static const char *
53116e27
EZ
205sh_sh4_register_name (int reg_nr)
206{
207 static char *register_names[] =
208 {
a38d2a54 209 /* general registers 0-15 */
53116e27
EZ
210 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
211 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
a38d2a54 212 /* 16 - 22 */
53116e27 213 "pc", "pr", "gbr", "vbr", "mach", "macl", "sr",
a38d2a54 214 /* 23, 24 */
53116e27 215 "fpul", "fpscr",
a38d2a54 216 /* floating point registers 25 - 40 */
53116e27
EZ
217 "fr0", "fr1", "fr2", "fr3", "fr4", "fr5", "fr6", "fr7",
218 "fr8", "fr9", "fr10", "fr11", "fr12", "fr13", "fr14", "fr15",
a38d2a54 219 /* 41, 42 */
53116e27 220 "ssr", "spc",
a38d2a54 221 /* bank 0 43 - 50 */
53116e27 222 "r0b0", "r1b0", "r2b0", "r3b0", "r4b0", "r5b0", "r6b0", "r7b0",
a38d2a54 223 /* bank 1 51 - 58 */
53116e27 224 "r0b1", "r1b1", "r2b1", "r3b1", "r4b1", "r5b1", "r6b1", "r7b1",
a38d2a54 225 /* double precision (pseudo) 59 - 66 */
fe9f384f 226 "dr0", "dr2", "dr4", "dr6", "dr8", "dr10", "dr12", "dr14",
a38d2a54 227 /* vectors (pseudo) 67 - 70 */
fe9f384f 228 "fv0", "fv4", "fv8", "fv12",
a38d2a54
EZ
229 /* FIXME: missing XF 71 - 86 */
230 /* FIXME: missing XD 87 - 94 */
53116e27
EZ
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
fa88f677 239static const char *
283150cd
EZ
240sh_sh64_register_name (int reg_nr)
241{
242 static char *register_names[] =
243 {
244 /* SH MEDIA MODE (ISA 32) */
245 /* general registers (64-bit) 0-63 */
246 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
247 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
248 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
249 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
250 "r32", "r33", "r34", "r35", "r36", "r37", "r38", "r39",
251 "r40", "r41", "r42", "r43", "r44", "r45", "r46", "r47",
252 "r48", "r49", "r50", "r51", "r52", "r53", "r54", "r55",
253 "r56", "r57", "r58", "r59", "r60", "r61", "r62", "r63",
254
255 /* pc (64-bit) 64 */
256 "pc",
257
258 /* status reg., saved status reg., saved pc reg. (64-bit) 65-67 */
259 "sr", "ssr", "spc",
260
261 /* target registers (64-bit) 68-75*/
262 "tr0", "tr1", "tr2", "tr3", "tr4", "tr5", "tr6", "tr7",
263
264 /* floating point state control register (32-bit) 76 */
265 "fpscr",
266
267 /* single precision floating point registers (32-bit) 77-140*/
268 "fr0", "fr1", "fr2", "fr3", "fr4", "fr5", "fr6", "fr7",
269 "fr8", "fr9", "fr10", "fr11", "fr12", "fr13", "fr14", "fr15",
270 "fr16", "fr17", "fr18", "fr19", "fr20", "fr21", "fr22", "fr23",
271 "fr24", "fr25", "fr26", "fr27", "fr28", "fr29", "fr30", "fr31",
272 "fr32", "fr33", "fr34", "fr35", "fr36", "fr37", "fr38", "fr39",
273 "fr40", "fr41", "fr42", "fr43", "fr44", "fr45", "fr46", "fr47",
274 "fr48", "fr49", "fr50", "fr51", "fr52", "fr53", "fr54", "fr55",
275 "fr56", "fr57", "fr58", "fr59", "fr60", "fr61", "fr62", "fr63",
276
277 /* double precision registers (pseudo) 141-172 */
278 "dr0", "dr2", "dr4", "dr6", "dr8", "dr10", "dr12", "dr14",
279 "dr16", "dr18", "dr20", "dr22", "dr24", "dr26", "dr28", "dr30",
280 "dr32", "dr34", "dr36", "dr38", "dr40", "dr42", "dr44", "dr46",
281 "dr48", "dr50", "dr52", "dr54", "dr56", "dr58", "dr60", "dr62",
282
283 /* floating point pairs (pseudo) 173-204*/
284 "fp0", "fp2", "fp4", "fp6", "fp8", "fp10", "fp12", "fp14",
285 "fp16", "fp18", "fp20", "fp22", "fp24", "fp26", "fp28", "fp30",
286 "fp32", "fp34", "fp36", "fp38", "fp40", "fp42", "fp44", "fp46",
287 "fp48", "fp50", "fp52", "fp54", "fp56", "fp58", "fp60", "fp62",
288
289 /* floating point vectors (4 floating point regs) (pseudo) 205-220*/
290 "fv0", "fv4", "fv8", "fv12", "fv16", "fv20", "fv24", "fv28",
291 "fv32", "fv36", "fv40", "fv44", "fv48", "fv52", "fv56", "fv60",
292
293 /* SH COMPACT MODE (ISA 16) (all pseudo) 221-272*/
294 "r0_c", "r1_c", "r2_c", "r3_c", "r4_c", "r5_c", "r6_c", "r7_c",
295 "r8_c", "r9_c", "r10_c", "r11_c", "r12_c", "r13_c", "r14_c", "r15_c",
296 "pc_c",
297 "gbr_c", "mach_c", "macl_c", "pr_c", "t_c",
298 "fpscr_c", "fpul_c",
299 "fr0_c", "fr1_c", "fr2_c", "fr3_c", "fr4_c", "fr5_c", "fr6_c", "fr7_c",
300 "fr8_c", "fr9_c", "fr10_c", "fr11_c", "fr12_c", "fr13_c", "fr14_c", "fr15_c",
301 "dr0_c", "dr2_c", "dr4_c", "dr6_c", "dr8_c", "dr10_c", "dr12_c", "dr14_c",
302 "fv0_c", "fv4_c", "fv8_c", "fv12_c",
303 /* FIXME!!!! XF0 XF15, XD0 XD14 ?????*/
304 };
305
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];
311}
312
313#define NUM_PSEUDO_REGS_SH_MEDIA 80
314#define NUM_PSEUDO_REGS_SH_COMPACT 51
315
3117ed25 316static const unsigned char *
fba45db2 317sh_breakpoint_from_pc (CORE_ADDR *pcptr, int *lenptr)
cc17453a
EZ
318{
319 /* 0xc3c3 is trapa #c3, and it works in big and little endian modes */
320 static unsigned char breakpoint[] = {0xc3, 0xc3};
321
322 *lenptr = sizeof (breakpoint);
323 return breakpoint;
324}
c906108c 325
283150cd
EZ
326/* Macros and functions for setting and testing a bit in a minimal
327 symbol that marks it as 32-bit function. The MSB of the minimal
328 symbol's "info" field is used for this purpose. This field is
329 already being used to store the symbol size, so the assumption is
330 that the symbol size cannot exceed 2^31.
331
332 ELF_MAKE_MSYMBOL_SPECIAL
333 tests whether an ELF symbol is "special", i.e. refers
334 to a 32-bit function, and sets a "special" bit in a
335 minimal symbol to mark it as a 32-bit function
336 MSYMBOL_IS_SPECIAL tests the "special" bit in a minimal symbol
337 MSYMBOL_SIZE returns the size of the minimal symbol, i.e.
338 the "info" field with the "special" bit masked out */
339
340#define MSYMBOL_IS_SPECIAL(msym) \
341 (((long) MSYMBOL_INFO (msym) & 0x80000000) != 0)
342
343void
344sh64_elf_make_msymbol_special (asymbol *sym, struct minimal_symbol *msym)
345{
346 if (msym == NULL)
347 return;
348
349 if (((elf_symbol_type *)(sym))->internal_elf_sym.st_other == STO_SH5_ISA32)
350 {
351 MSYMBOL_INFO (msym) = (char *) (((long) MSYMBOL_INFO (msym)) | 0x80000000);
352 SYMBOL_VALUE_ADDRESS (msym) |= 1;
353 }
354}
355
356/* ISA32 (shmedia) function addresses are odd (bit 0 is set). Here
357 are some macros to test, set, or clear bit 0 of addresses. */
358#define IS_ISA32_ADDR(addr) ((addr) & 1)
359#define MAKE_ISA32_ADDR(addr) ((addr) | 1)
360#define UNMAKE_ISA32_ADDR(addr) ((addr) & ~1)
361
362static int
363pc_is_isa32 (bfd_vma memaddr)
364{
365 struct minimal_symbol *sym;
366
367 /* If bit 0 of the address is set, assume this is a
368 ISA32 (shmedia) address. */
369 if (IS_ISA32_ADDR (memaddr))
370 return 1;
371
372 /* A flag indicating that this is a ISA32 function is stored by elfread.c in
373 the high bit of the info field. Use this to decide if the function is
374 ISA16 or ISA32. */
375 sym = lookup_minimal_symbol_by_pc (memaddr);
376 if (sym)
377 return MSYMBOL_IS_SPECIAL (sym);
378 else
379 return 0;
380}
381
382static const unsigned char *
383sh_sh64_breakpoint_from_pc (CORE_ADDR *pcptr, int *lenptr)
384{
385 /* The BRK instruction for shmedia is
386 01101111 11110101 11111111 11110000
387 which translates in big endian mode to 0x6f, 0xf5, 0xff, 0xf0
388 and in little endian mode to 0xf0, 0xff, 0xf5, 0x6f */
389
390 /* The BRK instruction for shcompact is
391 00000000 00111011
392 which translates in big endian mode to 0x0, 0x3b
393 and in little endian mode to 0x3b, 0x0*/
394
395 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
396 {
397 if (pc_is_isa32 (*pcptr))
398 {
399 static unsigned char big_breakpoint_media[] = {0x6f, 0xf5, 0xff, 0xf0};
400 *pcptr = UNMAKE_ISA32_ADDR (*pcptr);
401 *lenptr = sizeof (big_breakpoint_media);
402 return big_breakpoint_media;
403 }
404 else
405 {
406 static unsigned char big_breakpoint_compact[] = {0x0, 0x3b};
407 *lenptr = sizeof (big_breakpoint_compact);
408 return big_breakpoint_compact;
409 }
410 }
411 else
412 {
413 if (pc_is_isa32 (*pcptr))
414 {
415 static unsigned char little_breakpoint_media[] = {0xf0, 0xff, 0xf5, 0x6f};
416 *pcptr = UNMAKE_ISA32_ADDR (*pcptr);
417 *lenptr = sizeof (little_breakpoint_media);
418 return little_breakpoint_media;
419 }
420 else
421 {
422 static unsigned char little_breakpoint_compact[] = {0x3b, 0x0};
423 *lenptr = sizeof (little_breakpoint_compact);
424 return little_breakpoint_compact;
425 }
426 }
427}
428
c906108c 429/* Prologue looks like
c5aa993b
JM
430 [mov.l <regs>,@-r15]...
431 [sts.l pr,@-r15]
432 [mov.l r14,@-r15]
433 [mov r15,r14]
8db62801
EZ
434
435 Actually it can be more complicated than this. For instance, with
436 newer gcc's:
437
438 mov.l r14,@-r15
439 add #-12,r15
440 mov r15,r14
441 mov r4,r1
442 mov r5,r2
443 mov.l r6,@(4,r14)
444 mov.l r7,@(8,r14)
445 mov.b r1,@r14
446 mov r14,r1
447 mov r14,r1
448 add #2,r1
449 mov.w r2,@r1
450
c5aa993b 451 */
c906108c 452
283150cd
EZ
453/* PTABS/L Rn, TRa 0110101111110001nnnnnnl00aaa0000
454 with l=1 and n = 18 0110101111110001010010100aaa0000 */
455#define IS_PTABSL_R18(x) (((x) & 0xffffff8f) == 0x6bf14a00)
456
457/* STS.L PR,@-r0 0100000000100010
458 r0-4-->r0, PR-->(r0) */
459#define IS_STS_R0(x) ((x) == 0x4022)
460
461/* STS PR, Rm 0000mmmm00101010
462 PR-->Rm */
463#define IS_STS_PR(x) (((x) & 0xf0ff) == 0x2a)
464
465/* MOV.L Rm,@(disp,r15) 00011111mmmmdddd
466 Rm-->(dispx4+r15) */
467#define IS_MOV_TO_R15(x) (((x) & 0xff00) == 0x1f00)
468
469/* MOV.L R14,@(disp,r15) 000111111110dddd
470 R14-->(dispx4+r15) */
471#define IS_MOV_R14(x) (((x) & 0xfff0) == 0x1fe0)
472
473/* ST.Q R14, disp, R18 101011001110dddddddddd0100100000
474 R18-->(dispx8+R14) */
475#define IS_STQ_R18_R14(x) (((x) & 0xfff003ff) == 0xace00120)
476
477/* ST.Q R15, disp, R18 101011001111dddddddddd0100100000
478 R18-->(dispx8+R15) */
479#define IS_STQ_R18_R15(x) (((x) & 0xfff003ff) == 0xacf00120)
480
481/* ST.L R15, disp, R18 101010001111dddddddddd0100100000
482 R18-->(dispx4+R15) */
483#define IS_STL_R18_R15(x) (((x) & 0xfff003ff) == 0xa8f00120)
484
485/* ST.Q R15, disp, R14 1010 1100 1111 dddd dddd dd00 1110 0000
486 R14-->(dispx8+R15) */
487#define IS_STQ_R14_R15(x) (((x) & 0xfff003ff) == 0xacf000e0)
488
489/* ST.L R15, disp, R14 1010 1000 1111 dddd dddd dd00 1110 0000
490 R14-->(dispx4+R15) */
491#define IS_STL_R14_R15(x) (((x) & 0xfff003ff) == 0xa8f000e0)
492
493/* ADDI.L R15,imm,R15 1101 0100 1111 ssss ssss ss00 1111 0000
494 R15 + imm --> R15 */
495#define IS_ADDIL_SP_MEDIA(x) (((x) & 0xfff003ff) == 0xd4f000f0)
496
497/* ADDI R15,imm,R15 1101 0000 1111 ssss ssss ss00 1111 0000
498 R15 + imm --> R15 */
499#define IS_ADDI_SP_MEDIA(x) (((x) & 0xfff003ff) == 0xd0f000f0)
500
501/* ADD.L R15,R63,R14 0000 0000 1111 1000 1111 1100 1110 0000
502 R15 + R63 --> R14 */
503#define IS_ADDL_SP_FP_MEDIA(x) ((x) == 0x00f8fce0)
504
505/* ADD R15,R63,R14 0000 0000 1111 1001 1111 1100 1110 0000
506 R15 + R63 --> R14 */
507#define IS_ADD_SP_FP_MEDIA(x) ((x) == 0x00f9fce0)
508
509#define IS_MOV_SP_FP_MEDIA(x) (IS_ADDL_SP_FP_MEDIA(x) || IS_ADD_SP_FP_MEDIA(x))
510
511/* MOV #imm, R0 1110 0000 ssss ssss
512 #imm-->R0 */
513#define IS_MOV_R0(x) (((x) & 0xff00) == 0xe000)
514
515/* MOV.L @(disp,PC), R0 1101 0000 iiii iiii */
516#define IS_MOVL_R0(x) (((x) & 0xff00) == 0xd000)
517
518/* ADD r15,r0 0011 0000 1111 1100
519 r15+r0-->r0 */
520#define IS_ADD_SP_R0(x) ((x) == 0x30fc)
521
522/* MOV.L R14 @-R0 0010 0000 1110 0110
523 R14-->(R0-4), R0-4-->R0 */
524#define IS_MOV_R14_R0(x) ((x) == 0x20e6)
525
526/* ADD Rm,R63,Rn Rm+R63-->Rn 0000 00mm mmmm 1001 1111 11nn nnnn 0000
527 where Rm is one of r2-r9 which are the argument registers. */
528/* FIXME: Recognize the float and double register moves too! */
529#define IS_MEDIA_IND_ARG_MOV(x) \
530((((x) & 0xfc0ffc0f) == 0x0009fc00) && (((x) & 0x03f00000) >= 0x00200000 && ((x) & 0x03f00000) <= 0x00900000))
531
532/* ST.Q Rn,0,Rm Rm-->Rn+0 1010 11nn nnnn 0000 0000 00mm mmmm 0000
533 or ST.L Rn,0,Rm Rm-->Rn+0 1010 10nn nnnn 0000 0000 00mm mmmm 0000
534 where Rm is one of r2-r9 which are the argument registers. */
535#define IS_MEDIA_ARG_MOV(x) \
536(((((x) & 0xfc0ffc0f) == 0xac000000) || (((x) & 0xfc0ffc0f) == 0xa8000000)) \
537 && (((x) & 0x000003f0) >= 0x00000020 && ((x) & 0x000003f0) <= 0x00000090))
538
539/* ST.B R14,0,Rn Rn-->(R14+0) 1010 0000 1110 0000 0000 00nn nnnn 0000*/
540/* ST.W R14,0,Rn Rn-->(R14+0) 1010 0100 1110 0000 0000 00nn nnnn 0000*/
541/* ST.L R14,0,Rn Rn-->(R14+0) 1010 1000 1110 0000 0000 00nn nnnn 0000*/
542/* FST.S R14,0,FRn Rn-->(R14+0) 1011 0100 1110 0000 0000 00nn nnnn 0000*/
543/* FST.D R14,0,DRn Rn-->(R14+0) 1011 1100 1110 0000 0000 00nn nnnn 0000*/
544#define IS_MEDIA_MOV_TO_R14(x) \
545((((x) & 0xfffffc0f) == 0xa0e00000) \
546|| (((x) & 0xfffffc0f) == 0xa4e00000) \
547|| (((x) & 0xfffffc0f) == 0xa8e00000) \
548|| (((x) & 0xfffffc0f) == 0xb4e00000) \
549|| (((x) & 0xfffffc0f) == 0xbce00000))
550
551/* MOV Rm, Rn Rm-->Rn 0110 nnnn mmmm 0011
552 where Rm is r2-r9 */
553#define IS_COMPACT_IND_ARG_MOV(x) \
554((((x) & 0xf00f) == 0x6003) && (((x) & 0x00f0) >= 0x0020) && (((x) & 0x00f0) <= 0x0090))
555
556/* compact direct arg move!
557 MOV.L Rn, @r14 0010 1110 mmmm 0010 */
558#define IS_COMPACT_ARG_MOV(x) \
559(((((x) & 0xff0f) == 0x2e02) && (((x) & 0x00f0) >= 0x0020) && ((x) & 0x00f0) <= 0x0090))
560
561/* MOV.B Rm, @R14 0010 1110 mmmm 0000
562 MOV.W Rm, @R14 0010 1110 mmmm 0001 */
563#define IS_COMPACT_MOV_TO_R14(x) \
564((((x) & 0xff0f) == 0x2e00) || (((x) & 0xff0f) == 0x2e01))
565
566#define IS_JSR_R0(x) ((x) == 0x400b)
567#define IS_NOP(x) ((x) == 0x0009)
568
569
8db62801
EZ
570/* STS.L PR,@-r15 0100111100100010
571 r15-4-->r15, PR-->(r15) */
c906108c 572#define IS_STS(x) ((x) == 0x4f22)
8db62801
EZ
573
574/* MOV.L Rm,@-r15 00101111mmmm0110
575 r15-4-->r15, Rm-->(R15) */
c906108c 576#define IS_PUSH(x) (((x) & 0xff0f) == 0x2f06)
8db62801 577
c906108c 578#define GET_PUSHED_REG(x) (((x) >> 4) & 0xf)
8db62801
EZ
579
580/* MOV r15,r14 0110111011110011
581 r15-->r14 */
c906108c 582#define IS_MOV_SP_FP(x) ((x) == 0x6ef3)
8db62801
EZ
583
584/* ADD #imm,r15 01111111iiiiiiii
585 r15+imm-->r15 */
c906108c 586#define IS_ADD_SP(x) (((x) & 0xff00) == 0x7f00)
8db62801 587
c906108c
SS
588#define IS_MOV_R3(x) (((x) & 0xff00) == 0x1a00)
589#define IS_SHLL_R3(x) ((x) == 0x4300)
8db62801
EZ
590
591/* ADD r3,r15 0011111100111100
592 r15+r3-->r15 */
c906108c 593#define IS_ADD_R3SP(x) ((x) == 0x3f3c)
8db62801
EZ
594
595/* FMOV.S FRm,@-Rn Rn-4-->Rn, FRm-->(Rn) 1111nnnnmmmm1011
8db62801 596 FMOV DRm,@-Rn Rn-8-->Rn, DRm-->(Rn) 1111nnnnmmm01011
8db62801 597 FMOV XDm,@-Rn Rn-8-->Rn, XDm-->(Rn) 1111nnnnmmm11011 */
c906108c 598#define IS_FMOV(x) (((x) & 0xf00f) == 0xf00b)
c906108c 599
8db62801 600/* MOV Rm,Rn Rm-->Rn 0110nnnnmmmm0011
8db62801 601 MOV.L Rm,@(disp,Rn) Rm-->(dispx4+Rn) 0001nnnnmmmmdddd
8db62801
EZ
602 MOV.L Rm,@Rn Rm-->(Rn) 0010nnnnmmmm0010
603 where Rm is one of r4,r5,r6,r7 which are the argument registers. */
604#define IS_ARG_MOV(x) \
605(((((x) & 0xf00f) == 0x6003) && (((x) & 0x00f0) >= 0x0040 && ((x) & 0x00f0) <= 0x0070)) \
cc17453a
EZ
606 || ((((x) & 0xf000) == 0x1000) && (((x) & 0x00f0) >= 0x0040 && ((x) & 0x00f0) <= 0x0070)) \
607 || ((((x) & 0xf00f) == 0x2002) && (((x) & 0x00f0) >= 0x0040 && ((x) & 0x00f0) <= 0x0070)))
8db62801
EZ
608
609/* MOV.L Rm,@(disp,r14) 00011110mmmmdddd
610 Rm-->(dispx4+r14) where Rm is one of r4,r5,r6,r7 */
3bbfbb92 611#define IS_MOV_TO_R14(x) \
cc17453a 612 ((((x) & 0xff00) == 0x1e) && (((x) & 0x00f0) >= 0x0040 && ((x) & 0x00f0) <= 0x0070))
8db62801
EZ
613
614#define FPSCR_SZ (1 << 20)
c906108c 615
c906108c
SS
616/* Skip any prologue before the guts of a function */
617
8db62801
EZ
618/* Skip the prologue using the debug information. If this fails we'll
619 fall back on the 'guess' method below. */
620static CORE_ADDR
fba45db2 621after_prologue (CORE_ADDR pc)
8db62801
EZ
622{
623 struct symtab_and_line sal;
624 CORE_ADDR func_addr, func_end;
625
626 /* If we can not find the symbol in the partial symbol table, then
627 there is no hope we can determine the function's start address
628 with this code. */
629 if (!find_pc_partial_function (pc, NULL, &func_addr, &func_end))
630 return 0;
631
632 /* Get the line associated with FUNC_ADDR. */
633 sal = find_pc_line (func_addr, 0);
634
635 /* There are only two cases to consider. First, the end of the source line
636 is within the function bounds. In that case we return the end of the
637 source line. Second is the end of the source line extends beyond the
638 bounds of the current function. We need to use the slow code to
639 examine instructions in that case. */
640 if (sal.end < func_end)
641 return sal.end;
642 else
643 return 0;
644}
645
646/* Here we look at each instruction in the function, and try to guess
647 where the prologue ends. Unfortunately this is not always
648 accurate. */
649static CORE_ADDR
3bbfbb92 650sh_skip_prologue_hard_way (CORE_ADDR start_pc)
c906108c 651{
2bfa91ee 652 CORE_ADDR here, end;
8db62801 653 int updated_fp = 0;
2bfa91ee
EZ
654
655 if (!start_pc)
656 return 0;
657
658 for (here = start_pc, end = start_pc + (2 * 28); here < end;)
c906108c 659 {
2bfa91ee
EZ
660 int w = read_memory_integer (here, 2);
661 here += 2;
662 if (IS_FMOV (w) || IS_PUSH (w) || IS_STS (w) || IS_MOV_R3 (w)
8db62801 663 || IS_ADD_R3SP (w) || IS_ADD_SP (w) || IS_SHLL_R3 (w)
3bbfbb92 664 || IS_ARG_MOV (w) || IS_MOV_TO_R14 (w))
2bfa91ee
EZ
665 {
666 start_pc = here;
2bfa91ee 667 }
8db62801
EZ
668 else if (IS_MOV_SP_FP (w))
669 {
670 start_pc = here;
671 updated_fp = 1;
672 }
673 else
674 /* Don't bail out yet, if we are before the copy of sp. */
675 if (updated_fp)
676 break;
c906108c
SS
677 }
678
679 return start_pc;
680}
681
283150cd
EZ
682static CORE_ADDR
683look_for_args_moves (CORE_ADDR start_pc, int media_mode)
684{
685 CORE_ADDR here, end;
686 int w;
687 int insn_size = (media_mode ? 4 : 2);
688
689 for (here = start_pc, end = start_pc + (insn_size * 28); here < end;)
690 {
691 if (media_mode)
692 {
693 w = read_memory_integer (UNMAKE_ISA32_ADDR (here), insn_size);
694 here += insn_size;
695 if (IS_MEDIA_IND_ARG_MOV (w))
696 {
697 /* This must be followed by a store to r14, so the argument
698 is where the debug info says it is. This can happen after
699 the SP has been saved, unfortunately. */
700
701 int next_insn = read_memory_integer (UNMAKE_ISA32_ADDR (here),
702 insn_size);
703 here += insn_size;
704 if (IS_MEDIA_MOV_TO_R14 (next_insn))
705 start_pc = here;
706 }
707 else if (IS_MEDIA_ARG_MOV (w))
708 {
709 /* These instructions store directly the argument in r14. */
710 start_pc = here;
711 }
712 else
713 break;
714 }
715 else
716 {
717 w = read_memory_integer (here, insn_size);
718 w = w & 0xffff;
719 here += insn_size;
720 if (IS_COMPACT_IND_ARG_MOV (w))
721 {
722 /* This must be followed by a store to r14, so the argument
723 is where the debug info says it is. This can happen after
724 the SP has been saved, unfortunately. */
725
726 int next_insn = 0xffff & read_memory_integer (here, insn_size);
727 here += insn_size;
728 if (IS_COMPACT_MOV_TO_R14 (next_insn))
729 start_pc = here;
730 }
731 else if (IS_COMPACT_ARG_MOV (w))
732 {
733 /* These instructions store directly the argument in r14. */
734 start_pc = here;
735 }
736 else if (IS_MOVL_R0 (w))
737 {
738 /* There is a function that gcc calls to get the arguments
739 passed correctly to the function. Only after this
740 function call the arguments will be found at the place
741 where they are supposed to be. This happens in case the
742 argument has to be stored into a 64-bit register (for
743 instance doubles, long longs). SHcompact doesn't have
744 access to the full 64-bits, so we store the register in
745 stack slot and store the address of the stack slot in
746 the register, then do a call through a wrapper that
747 loads the memory value into the register. A SHcompact
748 callee calls an argument decoder
749 (GCC_shcompact_incoming_args) that stores the 64-bit
750 value in a stack slot and stores the address of the
751 stack slot in the register. GCC thinks the argument is
752 just passed by transparent reference, but this is only
753 true after the argument decoder is called. Such a call
754 needs to be considered part of the prologue. */
755
756 /* This must be followed by a JSR @r0 instruction and by
757 a NOP instruction. After these, the prologue is over! */
758
759 int next_insn = 0xffff & read_memory_integer (here, insn_size);
760 here += insn_size;
761 if (IS_JSR_R0 (next_insn))
762 {
763 next_insn = 0xffff & read_memory_integer (here, insn_size);
764 here += insn_size;
765
766 if (IS_NOP (next_insn))
767 start_pc = here;
768 }
769 }
770 else
771 break;
772 }
773 }
774
775 return start_pc;
776}
777
778static CORE_ADDR
779sh64_skip_prologue_hard_way (CORE_ADDR start_pc)
780{
781 CORE_ADDR here, end;
782 int updated_fp = 0;
783 int insn_size = 4;
784 int media_mode = 1;
785
786 if (!start_pc)
787 return 0;
788
789 if (pc_is_isa32 (start_pc) == 0)
790 {
791 insn_size = 2;
792 media_mode = 0;
793 }
794
795 for (here = start_pc, end = start_pc + (insn_size * 28); here < end;)
796 {
797
798 if (media_mode)
799 {
800 int w = read_memory_integer (UNMAKE_ISA32_ADDR (here), insn_size);
801 here += insn_size;
802 if (IS_STQ_R18_R14 (w) || IS_STQ_R18_R15 (w) || IS_STQ_R14_R15 (w)
803 || IS_STL_R14_R15 (w) || IS_STL_R18_R15 (w)
804 || IS_ADDIL_SP_MEDIA (w) || IS_ADDI_SP_MEDIA (w) || IS_PTABSL_R18 (w))
805 {
806 start_pc = here;
807 }
808 else if (IS_MOV_SP_FP (w) || IS_MOV_SP_FP_MEDIA(w))
809 {
810 start_pc = here;
811 updated_fp = 1;
812 }
813 else
814 if (updated_fp)
815 {
816 /* Don't bail out yet, we may have arguments stored in
817 registers here, according to the debug info, so that
818 gdb can print the frames correctly. */
819 start_pc = look_for_args_moves (here - insn_size, media_mode);
820 break;
821 }
822 }
823 else
824 {
825 int w = 0xffff & read_memory_integer (here, insn_size);
826 here += insn_size;
827
828 if (IS_STS_R0 (w) || IS_STS_PR (w)
829 || IS_MOV_TO_R15 (w) || IS_MOV_R14 (w)
830 || IS_MOV_R0 (w) || IS_ADD_SP_R0 (w) || IS_MOV_R14_R0 (w))
831 {
832 start_pc = here;
833 }
834 else if (IS_MOV_SP_FP (w))
835 {
836 start_pc = here;
837 updated_fp = 1;
838 }
839 else
840 if (updated_fp)
841 {
842 /* Don't bail out yet, we may have arguments stored in
843 registers here, according to the debug info, so that
844 gdb can print the frames correctly. */
845 start_pc = look_for_args_moves (here - insn_size, media_mode);
846 break;
847 }
848 }
849 }
850
851 return start_pc;
852}
853
cc17453a 854static CORE_ADDR
fba45db2 855sh_skip_prologue (CORE_ADDR pc)
8db62801
EZ
856{
857 CORE_ADDR post_prologue_pc;
858
859 /* See if we can determine the end of the prologue via the symbol table.
860 If so, then return either PC, or the PC after the prologue, whichever
861 is greater. */
8db62801
EZ
862 post_prologue_pc = after_prologue (pc);
863
864 /* If after_prologue returned a useful address, then use it. Else
865 fall back on the instruction skipping code. */
866 if (post_prologue_pc != 0)
867 return max (pc, post_prologue_pc);
868 else
869 return (skip_prologue_hard_way (pc));
870}
871
cc17453a
EZ
872/* Immediately after a function call, return the saved pc.
873 Can't always go through the frames for this because on some machines
874 the new frame is not set up until the new function executes
875 some instructions.
876
877 The return address is the value saved in the PR register + 4 */
878static CORE_ADDR
fba45db2 879sh_saved_pc_after_call (struct frame_info *frame)
cc17453a 880{
3bbfbb92 881 return (ADDR_BITS_REMOVE (read_register (gdbarch_tdep (current_gdbarch)->PR_REGNUM)));
cc17453a
EZ
882}
883
884/* Should call_function allocate stack space for a struct return? */
885static int
fba45db2 886sh_use_struct_convention (int gcc_p, struct type *type)
cc17453a 887{
7079c36c 888#if 0
cc17453a 889 return (TYPE_LENGTH (type) > 1);
7079c36c
CV
890#else
891 int len = TYPE_LENGTH (type);
892 int nelem = TYPE_NFIELDS (type);
893 return ((len != 1 && len != 2 && len != 4 && len != 8) || nelem != 1) &&
894 (len != 8 || TYPE_LENGTH (TYPE_FIELD_TYPE (type, 0)) != 4);
895#endif
cc17453a
EZ
896}
897
283150cd
EZ
898static int
899sh64_use_struct_convention (int gcc_p, struct type *type)
900{
901 return (TYPE_LENGTH (type) > 8);
902}
903
cc17453a
EZ
904/* Store the address of the place in which to copy the structure the
905 subroutine will return. This is called from call_function.
906
3bbfbb92 907 We store structs through a pointer passed in R2 */
cc17453a 908static void
fba45db2 909sh_store_struct_return (CORE_ADDR addr, CORE_ADDR sp)
cc17453a
EZ
910{
911 write_register (STRUCT_RETURN_REGNUM, (addr));
912}
c906108c 913
cc17453a
EZ
914/* Disassemble an instruction. */
915static int
fba45db2 916gdb_print_insn_sh (bfd_vma memaddr, disassemble_info *info)
c906108c 917{
1c509ca8
JR
918 info->endian = TARGET_BYTE_ORDER;
919 return print_insn_sh (memaddr, info);
283150cd
EZ
920}
921
a5afb99f
AC
922/* Given a GDB frame, determine the address of the calling function's
923 frame. This will be used to create a new GDB frame struct, and
924 then INIT_EXTRA_FRAME_INFO and DEPRECATED_INIT_FRAME_PC will be
925 called for the new frame.
c906108c
SS
926
927 For us, the frame address is its stack pointer value, so we look up
928 the function prologue to determine the caller's sp value, and return it. */
cc17453a 929static CORE_ADDR
fba45db2 930sh_frame_chain (struct frame_info *frame)
c906108c 931{
50abf9e5 932 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (frame), frame->frame, frame->frame))
c906108c 933 return frame->frame; /* dummy frame same as caller's frame */
50abf9e5 934 if (get_frame_pc (frame) && !inside_entry_file (get_frame_pc (frame)))
c193f6ac 935 return read_memory_integer (get_frame_base (frame) + frame->extra_info->f_offset, 4);
c906108c
SS
936 else
937 return 0;
938}
939
283150cd
EZ
940/* Given a register number RN as it appears in an assembly
941 instruction, find the corresponding register number in the GDB
942 scheme. */
943static int
944translate_insn_rn (int rn, int media_mode)
945{
946 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
947
948 /* FIXME: this assumes that the number rn is for a not pseudo
949 register only. */
950 if (media_mode)
951 return rn;
952 else
953 {
954 /* These registers don't have a corresponding compact one. */
955 /* FIXME: This is probably not enough. */
956#if 0
957 if ((rn >= 16 && rn <= 63) || (rn >= 93 && rn <= 140))
958 return rn;
959#endif
960 if (rn >= 0 && rn <= tdep->R0_C_REGNUM)
961 return tdep->R0_C_REGNUM + rn;
962 else
963 return rn;
964 }
965}
966
967static CORE_ADDR
968sh64_frame_chain (struct frame_info *frame)
969{
50abf9e5 970 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (frame), frame->frame, frame->frame))
283150cd 971 return frame->frame; /* dummy frame same as caller's frame */
50abf9e5 972 if (get_frame_pc (frame) && !inside_entry_file (get_frame_pc (frame)))
283150cd 973 {
50abf9e5 974 int media_mode = pc_is_isa32 (get_frame_pc (frame));
283150cd
EZ
975 int size;
976 if (gdbarch_tdep (current_gdbarch)->sh_abi == SH_ABI_32)
977 size = 4;
978 else
979 size = REGISTER_RAW_SIZE (translate_insn_rn (FP_REGNUM, media_mode));
c193f6ac 980 return read_memory_integer (get_frame_base (frame) + frame->extra_info->f_offset, size);
283150cd
EZ
981 }
982 else
983 return 0;
984}
985
c906108c
SS
986/* Find REGNUM on the stack. Otherwise, it's in an active register. One thing
987 we might want to do here is to check REGNUM against the clobber mask, and
988 somehow flag it as invalid if it isn't saved on the stack somewhere. This
989 would provide a graceful failure mode when trying to get the value of
990 caller-saves registers for an inner frame. */
cc17453a 991static CORE_ADDR
fba45db2 992sh_find_callers_reg (struct frame_info *fi, int regnum)
c906108c 993{
c906108c 994 for (; fi; fi = fi->next)
50abf9e5 995 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (fi), fi->frame, fi->frame))
c906108c 996 /* When the caller requests PR from the dummy frame, we return PC because
c5aa993b 997 that's where the previous routine appears to have done a call from. */
50abf9e5 998 return deprecated_read_register_dummy (get_frame_pc (fi), fi->frame, regnum);
c5aa993b 999 else
c906108c 1000 {
cc17453a 1001 FRAME_INIT_SAVED_REGS (fi);
50abf9e5 1002 if (!get_frame_pc (fi))
2bfa91ee 1003 return 0;
b2fb4676
AC
1004 if (get_frame_saved_regs (fi)[regnum] != 0)
1005 return read_memory_integer (get_frame_saved_regs (fi)[regnum],
c5aa993b 1006 REGISTER_RAW_SIZE (regnum));
c906108c
SS
1007 }
1008 return read_register (regnum);
1009}
1010
283150cd
EZ
1011static CORE_ADDR
1012sh64_get_saved_pr (struct frame_info *fi, int pr_regnum)
1013{
1014 int media_mode = 0;
1015
1016 for (; fi; fi = fi->next)
50abf9e5 1017 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (fi), fi->frame, fi->frame))
283150cd
EZ
1018 /* When the caller requests PR from the dummy frame, we return PC because
1019 that's where the previous routine appears to have done a call from. */
50abf9e5 1020 return deprecated_read_register_dummy (get_frame_pc (fi), fi->frame, pr_regnum);
283150cd
EZ
1021 else
1022 {
1023 FRAME_INIT_SAVED_REGS (fi);
50abf9e5 1024 if (!get_frame_pc (fi))
283150cd
EZ
1025 return 0;
1026
50abf9e5 1027 media_mode = pc_is_isa32 (get_frame_pc (fi));
283150cd 1028
b2fb4676 1029 if (get_frame_saved_regs (fi)[pr_regnum] != 0)
283150cd
EZ
1030 {
1031 int gdb_reg_num = translate_insn_rn (pr_regnum, media_mode);
1032 int size = ((gdbarch_tdep (current_gdbarch)->sh_abi == SH_ABI_32)
1033 ? 4
1034 : REGISTER_RAW_SIZE (gdb_reg_num));
b2fb4676 1035 return read_memory_integer (get_frame_saved_regs (fi)[pr_regnum], size);
283150cd
EZ
1036 }
1037 }
1038 return read_register (pr_regnum);
1039}
1040
c906108c
SS
1041/* Put here the code to store, into a struct frame_saved_regs, the
1042 addresses of the saved registers of frame described by FRAME_INFO.
1043 This includes special registers such as pc and fp saved in special
1044 ways in the stack frame. sp is even more special: the address we
1045 return for it IS the sp for the next frame. */
cc17453a 1046static void
fba45db2 1047sh_nofp_frame_init_saved_regs (struct frame_info *fi)
c906108c 1048{
e7d717c0 1049 int *where = (int *) alloca ((NUM_REGS + NUM_PSEUDO_REGS) * sizeof(int));
c906108c
SS
1050 int rn;
1051 int have_fp = 0;
1052 int depth;
1053 int pc;
1054 int opc;
1055 int insn;
1056 int r3_val = 0;
50abf9e5 1057 char *dummy_regs = deprecated_generic_find_dummy_frame (get_frame_pc (fi), fi->frame);
cc17453a 1058
b2fb4676 1059 if (get_frame_saved_regs (fi) == NULL)
cc17453a
EZ
1060 frame_saved_regs_zalloc (fi);
1061 else
b2fb4676 1062 memset (get_frame_saved_regs (fi), 0, SIZEOF_FRAME_SAVED_REGS);
cc17453a
EZ
1063
1064 if (dummy_regs)
1065 {
1066 /* DANGER! This is ONLY going to work if the char buffer format of
1067 the saved registers is byte-for-byte identical to the
1068 CORE_ADDR regs[NUM_REGS] format used by struct frame_saved_regs! */
1069 memcpy (fi->saved_regs, dummy_regs, sizeof (fi->saved_regs));
1070 return;
1071 }
1072
1073 fi->extra_info->leaf_function = 1;
1074 fi->extra_info->f_offset = 0;
1075
cd4bffcf 1076 for (rn = 0; rn < NUM_REGS + NUM_PSEUDO_REGS; rn++)
cc17453a
EZ
1077 where[rn] = -1;
1078
1079 depth = 0;
1080
1081 /* Loop around examining the prologue insns until we find something
1082 that does not appear to be part of the prologue. But give up
1083 after 20 of them, since we're getting silly then. */
1084
50abf9e5 1085 pc = get_pc_function_start (get_frame_pc (fi));
cc17453a
EZ
1086 if (!pc)
1087 {
50abf9e5 1088 deprecated_update_frame_pc_hack (fi, 0);
cc17453a
EZ
1089 return;
1090 }
1091
1092 for (opc = pc + (2 * 28); pc < opc; pc += 2)
1093 {
1094 insn = read_memory_integer (pc, 2);
1095 /* See where the registers will be saved to */
1096 if (IS_PUSH (insn))
1097 {
1098 rn = GET_PUSHED_REG (insn);
1099 where[rn] = depth;
1100 depth += 4;
1101 }
1102 else if (IS_STS (insn))
1103 {
3bbfbb92 1104 where[gdbarch_tdep (current_gdbarch)->PR_REGNUM] = depth;
cc17453a
EZ
1105 /* If we're storing the pr then this isn't a leaf */
1106 fi->extra_info->leaf_function = 0;
1107 depth += 4;
1108 }
1109 else if (IS_MOV_R3 (insn))
1110 {
1111 r3_val = ((insn & 0xff) ^ 0x80) - 0x80;
1112 }
1113 else if (IS_SHLL_R3 (insn))
1114 {
1115 r3_val <<= 1;
1116 }
1117 else if (IS_ADD_R3SP (insn))
1118 {
1119 depth += -r3_val;
1120 }
1121 else if (IS_ADD_SP (insn))
1122 {
1123 depth -= ((insn & 0xff) ^ 0x80) - 0x80;
1124 }
1125 else if (IS_MOV_SP_FP (insn))
1126 break;
1127#if 0 /* This used to just stop when it found an instruction that
1128 was not considered part of the prologue. Now, we just
1129 keep going looking for likely instructions. */
1130 else
1131 break;
1132#endif
1133 }
1134
1135 /* Now we know how deep things are, we can work out their addresses */
1136
cd4bffcf 1137 for (rn = 0; rn < NUM_REGS + NUM_PSEUDO_REGS; rn++)
cc17453a
EZ
1138 {
1139 if (where[rn] >= 0)
1140 {
1141 if (rn == FP_REGNUM)
1142 have_fp = 1;
c906108c 1143
b2fb4676 1144 get_frame_saved_regs (fi)[rn] = fi->frame - where[rn] + depth - 4;
cc17453a
EZ
1145 }
1146 else
1147 {
b2fb4676 1148 get_frame_saved_regs (fi)[rn] = 0;
cc17453a
EZ
1149 }
1150 }
1151
1152 if (have_fp)
1153 {
b2fb4676 1154 get_frame_saved_regs (fi)[SP_REGNUM] = read_memory_integer (get_frame_saved_regs (fi)[FP_REGNUM], 4);
cc17453a
EZ
1155 }
1156 else
1157 {
b2fb4676 1158 get_frame_saved_regs (fi)[SP_REGNUM] = fi->frame - 4;
cc17453a
EZ
1159 }
1160
1161 fi->extra_info->f_offset = depth - where[FP_REGNUM] - 4;
1162 /* Work out the return pc - either from the saved pr or the pr
1163 value */
1164}
1165
3bbfbb92
EZ
1166/* For vectors of 4 floating point registers. */
1167static int
1168fv_reg_base_num (int fv_regnum)
1169{
1170 int fp_regnum;
1171
1172 fp_regnum = FP0_REGNUM +
1173 (fv_regnum - gdbarch_tdep (current_gdbarch)->FV0_REGNUM) * 4;
1174 return fp_regnum;
1175}
1176
1177/* For double precision floating point registers, i.e 2 fp regs.*/
1178static int
1179dr_reg_base_num (int dr_regnum)
1180{
1181 int fp_regnum;
1182
1183 fp_regnum = FP0_REGNUM +
1184 (dr_regnum - gdbarch_tdep (current_gdbarch)->DR0_REGNUM) * 2;
1185 return fp_regnum;
1186}
1187
283150cd
EZ
1188/* For pairs of floating point registers */
1189static int
1190fpp_reg_base_num (int fpp_regnum)
1191{
1192 int fp_regnum;
1193
1194 fp_regnum = FP0_REGNUM +
1195 (fpp_regnum - gdbarch_tdep (current_gdbarch)->FPP0_REGNUM) * 2;
1196 return fp_regnum;
1197}
1198
1199static int
1200is_media_pseudo (int rn)
1201{
1202 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
1203
1204 return (rn >= tdep->DR0_REGNUM
1205 && rn <= tdep->FV_LAST_REGNUM);
1206}
1207
1208int
1209sh64_get_gdb_regnum (int gcc_regnum, CORE_ADDR pc)
1210{
1211 return translate_insn_rn (gcc_regnum, pc_is_isa32 (pc));
1212}
1213
1214static int
1215sh64_media_reg_base_num (int reg_nr)
1216{
1217 int base_regnum = -1;
1218 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
1219
1220 if (reg_nr >= tdep->DR0_REGNUM
1221 && reg_nr <= tdep->DR_LAST_REGNUM)
1222 base_regnum = dr_reg_base_num (reg_nr);
1223
1224 else if (reg_nr >= tdep->FPP0_REGNUM
1225 && reg_nr <= tdep->FPP_LAST_REGNUM)
1226 base_regnum = fpp_reg_base_num (reg_nr);
1227
1228 else if (reg_nr >= tdep->FV0_REGNUM
1229 && reg_nr <= tdep->FV_LAST_REGNUM)
1230 base_regnum = fv_reg_base_num (reg_nr);
1231
1232 return base_regnum;
1233}
1234
1235/* *INDENT-OFF* */
1236/*
1237 SH COMPACT MODE (ISA 16) (all pseudo) 221-272
1238 GDB_REGNUM BASE_REGNUM
1239 r0_c 221 0
1240 r1_c 222 1
1241 r2_c 223 2
1242 r3_c 224 3
1243 r4_c 225 4
1244 r5_c 226 5
1245 r6_c 227 6
1246 r7_c 228 7
1247 r8_c 229 8
1248 r9_c 230 9
1249 r10_c 231 10
1250 r11_c 232 11
1251 r12_c 233 12
1252 r13_c 234 13
1253 r14_c 235 14
1254 r15_c 236 15
1255
1256 pc_c 237 64
1257 gbr_c 238 16
1258 mach_c 239 17
1259 macl_c 240 17
1260 pr_c 241 18
1261 t_c 242 19
1262 fpscr_c 243 76
1263 fpul_c 244 109
1264
1265 fr0_c 245 77
1266 fr1_c 246 78
1267 fr2_c 247 79
1268 fr3_c 248 80
1269 fr4_c 249 81
1270 fr5_c 250 82
1271 fr6_c 251 83
1272 fr7_c 252 84
1273 fr8_c 253 85
1274 fr9_c 254 86
1275 fr10_c 255 87
1276 fr11_c 256 88
1277 fr12_c 257 89
1278 fr13_c 258 90
1279 fr14_c 259 91
1280 fr15_c 260 92
1281
1282 dr0_c 261 77
1283 dr2_c 262 79
1284 dr4_c 263 81
1285 dr6_c 264 83
1286 dr8_c 265 85
1287 dr10_c 266 87
1288 dr12_c 267 89
1289 dr14_c 268 91
1290
1291 fv0_c 269 77
1292 fv4_c 270 81
1293 fv8_c 271 85
1294 fv12_c 272 91
1295*/
1296/* *INDENT-ON* */
1297static int
1298sh64_compact_reg_base_num (int reg_nr)
1299{
1300 int base_regnum = -1;
1301 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
1302
1303 /* general register N maps to general register N */
1304 if (reg_nr >= tdep->R0_C_REGNUM
1305 && reg_nr <= tdep->R_LAST_C_REGNUM)
1306 base_regnum = reg_nr - tdep->R0_C_REGNUM;
1307
1308 /* floating point register N maps to floating point register N */
1309 else if (reg_nr >= tdep->FP0_C_REGNUM
1310 && reg_nr <= tdep->FP_LAST_C_REGNUM)
1311 base_regnum = reg_nr - tdep->FP0_C_REGNUM + FP0_REGNUM;
1312
1313 /* double prec register N maps to base regnum for double prec register N */
1314 else if (reg_nr >= tdep->DR0_C_REGNUM
1315 && reg_nr <= tdep->DR_LAST_C_REGNUM)
1316 base_regnum = dr_reg_base_num (tdep->DR0_REGNUM
1317 + reg_nr - tdep->DR0_C_REGNUM);
1318
1319 /* vector N maps to base regnum for vector register N */
1320 else if (reg_nr >= tdep->FV0_C_REGNUM
1321 && reg_nr <= tdep->FV_LAST_C_REGNUM)
1322 base_regnum = fv_reg_base_num (tdep->FV0_REGNUM
1323 + reg_nr - tdep->FV0_C_REGNUM);
1324
1325 else if (reg_nr == tdep->PC_C_REGNUM)
1326 base_regnum = PC_REGNUM;
1327
1328 else if (reg_nr == tdep->GBR_C_REGNUM)
1329 base_regnum = 16;
1330
1331 else if (reg_nr == tdep->MACH_C_REGNUM
1332 || reg_nr == tdep->MACL_C_REGNUM)
1333 base_regnum = 17;
1334
1335 else if (reg_nr == tdep->PR_C_REGNUM)
1336 base_regnum = 18;
1337
1338 else if (reg_nr == tdep->T_C_REGNUM)
1339 base_regnum = 19;
1340
1341 else if (reg_nr == tdep->FPSCR_C_REGNUM)
1342 base_regnum = tdep->FPSCR_REGNUM; /*???? this register is a mess. */
1343
1344 else if (reg_nr == tdep->FPUL_C_REGNUM)
1345 base_regnum = FP0_REGNUM + 32;
1346
1347 return base_regnum;
1348}
1349
1350/* Given a register number RN (according to the gdb scheme) , return
1351 its corresponding architectural register. In media mode, only a
1352 subset of the registers is pseudo registers. For compact mode, all
1353 the registers are pseudo. */
1354static int
1355translate_rn_to_arch_reg_num (int rn, int media_mode)
1356{
1357
1358 if (media_mode)
1359 {
1360 if (!is_media_pseudo (rn))
1361 return rn;
1362 else
1363 return sh64_media_reg_base_num (rn);
1364 }
1365 else
1366 /* All compact registers are pseudo. */
1367 return sh64_compact_reg_base_num (rn);
1368}
1369
1370static int
1371sign_extend (int value, int bits)
1372{
1373 value = value & ((1 << bits) - 1);
1374 return (value & (1 << (bits - 1))
1375 ? value | (~((1 << bits) - 1))
1376 : value);
1377}
1378
cc17453a 1379static void
283150cd 1380sh64_nofp_frame_init_saved_regs (struct frame_info *fi)
cc17453a 1381{
ddde02bd 1382 int *where = (int *) alloca ((NUM_REGS + NUM_PSEUDO_REGS) * sizeof (int));
cc17453a
EZ
1383 int rn;
1384 int have_fp = 0;
283150cd
EZ
1385 int fp_regnum;
1386 int sp_regnum;
1387 int depth;
1388 int pc;
1389 int opc;
1390 int insn;
1391 int r0_val = 0;
1392 int media_mode = 0;
1393 int insn_size;
1394 int gdb_register_number;
1395 int register_number;
50abf9e5 1396 char *dummy_regs = deprecated_generic_find_dummy_frame (get_frame_pc (fi), fi->frame);
283150cd
EZ
1397 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
1398
b2fb4676 1399 if (get_frame_saved_regs (fi) == NULL)
283150cd
EZ
1400 frame_saved_regs_zalloc (fi);
1401 else
b2fb4676 1402 memset (get_frame_saved_regs (fi), 0, SIZEOF_FRAME_SAVED_REGS);
283150cd
EZ
1403
1404 if (dummy_regs)
1405 {
1406 /* DANGER! This is ONLY going to work if the char buffer format of
1407 the saved registers is byte-for-byte identical to the
1408 CORE_ADDR regs[NUM_REGS] format used by struct frame_saved_regs! */
1409 memcpy (fi->saved_regs, dummy_regs, sizeof (fi->saved_regs));
1410 return;
1411 }
1412
1413 fi->extra_info->leaf_function = 1;
1414 fi->extra_info->f_offset = 0;
1415
1416 for (rn = 0; rn < NUM_REGS + NUM_PSEUDO_REGS; rn++)
1417 where[rn] = -1;
1418
1419 depth = 0;
1420
1421 /* Loop around examining the prologue insns until we find something
1422 that does not appear to be part of the prologue. But give up
1423 after 20 of them, since we're getting silly then. */
1424
50abf9e5 1425 pc = get_pc_function_start (get_frame_pc (fi));
283150cd
EZ
1426 if (!pc)
1427 {
50abf9e5 1428 deprecated_update_frame_pc_hack (fi, 0);
283150cd
EZ
1429 return;
1430 }
1431
1432 if (pc_is_isa32 (pc))
1433 {
1434 media_mode = 1;
1435 insn_size = 4;
1436 }
1437 else
1438 {
1439 media_mode = 0;
1440 insn_size = 2;
1441 }
1442
1443 /* The frame pointer register is general register 14 in shmedia and
1444 shcompact modes. In sh compact it is a pseudo register. Same goes
1445 for the stack pointer register, which is register 15. */
1446 fp_regnum = translate_insn_rn (FP_REGNUM, media_mode);
1447 sp_regnum = translate_insn_rn (SP_REGNUM, media_mode);
1448
1449 for (opc = pc + (insn_size * 28); pc < opc; pc += insn_size)
1450 {
1451 insn = read_memory_integer (media_mode ? UNMAKE_ISA32_ADDR (pc) : pc,
1452 insn_size);
1453
1454 if (media_mode == 0)
1455 {
1456 if (IS_STS_PR (insn))
1457 {
1458 int next_insn = read_memory_integer (pc + insn_size, insn_size);
1459 if (IS_MOV_TO_R15 (next_insn))
1460 {
1461 int reg_nr = tdep->PR_C_REGNUM;
1462
1463 where[reg_nr] = depth - ((((next_insn & 0xf) ^ 0x8) - 0x8) << 2);
1464 fi->extra_info->leaf_function = 0;
1465 pc += insn_size;
1466 }
1467 }
1468 else if (IS_MOV_R14 (insn))
1469 {
1470 where[fp_regnum] = depth - ((((insn & 0xf) ^ 0x8) - 0x8) << 2);
1471 }
1472
1473 else if (IS_MOV_R0 (insn))
1474 {
1475 /* Put in R0 the offset from SP at which to store some
1476 registers. We are interested in this value, because it
1477 will tell us where the given registers are stored within
1478 the frame. */
1479 r0_val = ((insn & 0xff) ^ 0x80) - 0x80;
1480 }
1481 else if (IS_ADD_SP_R0 (insn))
1482 {
1483 /* This instruction still prepares r0, but we don't care.
1484 We already have the offset in r0_val. */
1485 }
1486 else if (IS_STS_R0 (insn))
1487 {
1488 /* Store PR at r0_val-4 from SP. Decrement r0 by 4*/
1489 int reg_nr = tdep->PR_C_REGNUM;
1490 where[reg_nr] = depth - (r0_val - 4);
1491 r0_val -= 4;
1492 fi->extra_info->leaf_function = 0;
1493 }
1494 else if (IS_MOV_R14_R0 (insn))
1495 {
1496 /* Store R14 at r0_val-4 from SP. Decrement r0 by 4 */
1497 where[fp_regnum] = depth - (r0_val - 4);
1498 r0_val -= 4;
1499 }
1500
1501 else if (IS_ADD_SP (insn))
1502 {
1503 depth -= ((insn & 0xff) ^ 0x80) - 0x80;
1504 }
1505 else if (IS_MOV_SP_FP (insn))
1506 break;
1507 }
1508 else
1509 {
1510 if (IS_ADDIL_SP_MEDIA (insn)
1511 || IS_ADDI_SP_MEDIA (insn))
1512 {
1513 depth -= sign_extend ((((insn & 0xffc00) ^ 0x80000) - 0x80000) >> 10, 9);
1514 }
1515
1516 else if (IS_STQ_R18_R15 (insn))
1517 {
1518 where[tdep->PR_REGNUM] =
1519 depth - (sign_extend ((insn & 0xffc00) >> 10, 9) << 3);
1520 fi->extra_info->leaf_function = 0;
1521 }
1522
1523 else if (IS_STL_R18_R15 (insn))
1524 {
1525 where[tdep->PR_REGNUM] =
1526 depth - (sign_extend ((insn & 0xffc00) >> 10, 9) << 2);
1527 fi->extra_info->leaf_function = 0;
1528 }
1529
1530 else if (IS_STQ_R14_R15 (insn))
1531 {
1532 where[fp_regnum] = depth - (sign_extend ((insn & 0xffc00) >> 10, 9) << 3);
1533 }
1534
1535 else if (IS_STL_R14_R15 (insn))
1536 {
1537 where[fp_regnum] = depth - (sign_extend ((insn & 0xffc00) >> 10, 9) << 2);
1538 }
1539
1540 else if (IS_MOV_SP_FP_MEDIA (insn))
1541 break;
1542 }
1543 }
1544
1545 /* Now we know how deep things are, we can work out their addresses. */
1546 for (rn = 0; rn < NUM_REGS + NUM_PSEUDO_REGS; rn++)
1547 {
1548 register_number = translate_rn_to_arch_reg_num (rn, media_mode);
1549
1550 if (where[rn] >= 0)
1551 {
1552 if (rn == fp_regnum)
1553 have_fp = 1;
1554
1555 /* Watch out! saved_regs is only for the real registers, and
1556 doesn't include space for the pseudo registers. */
b2fb4676 1557 get_frame_saved_regs (fi)[register_number]= fi->frame - where[rn] + depth;
283150cd
EZ
1558
1559 }
1560 else
b2fb4676 1561 get_frame_saved_regs (fi)[register_number] = 0;
283150cd
EZ
1562 }
1563
1564 if (have_fp)
1565 {
1566 /* SP_REGNUM is 15. For shmedia 15 is the real register. For
1567 shcompact 15 is the arch register corresponding to the pseudo
1568 register r15 which still is the SP register. */
1569 /* The place on the stack where fp is stored contains the sp of
1570 the caller. */
1571 /* Again, saved_registers contains only space for the real registers,
1572 so we store in FP_REGNUM position. */
1573 int size;
1574 if (tdep->sh_abi == SH_ABI_32)
1575 size = 4;
1576 else
1577 size = REGISTER_RAW_SIZE (fp_regnum);
b2fb4676 1578 get_frame_saved_regs (fi)[sp_regnum] = read_memory_integer (get_frame_saved_regs (fi)[fp_regnum], size);
283150cd
EZ
1579 }
1580 else
b2fb4676 1581 get_frame_saved_regs (fi)[sp_regnum] = fi->frame;
283150cd
EZ
1582
1583 fi->extra_info->f_offset = depth - where[fp_regnum];
1584}
1585
1586static void
1587sh_fp_frame_init_saved_regs (struct frame_info *fi)
1588{
ddde02bd 1589 int *where = (int *) alloca ((NUM_REGS + NUM_PSEUDO_REGS) * sizeof (int));
283150cd
EZ
1590 int rn;
1591 int have_fp = 0;
cc17453a
EZ
1592 int depth;
1593 int pc;
1594 int opc;
1595 int insn;
1596 int r3_val = 0;
50abf9e5 1597 char *dummy_regs = deprecated_generic_find_dummy_frame (get_frame_pc (fi), fi->frame);
f81353e4 1598 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
cc17453a 1599
b2fb4676 1600 if (get_frame_saved_regs (fi) == NULL)
cc17453a
EZ
1601 frame_saved_regs_zalloc (fi);
1602 else
b2fb4676 1603 memset (get_frame_saved_regs (fi), 0, SIZEOF_FRAME_SAVED_REGS);
cc17453a 1604
c906108c
SS
1605 if (dummy_regs)
1606 {
1607 /* DANGER! This is ONLY going to work if the char buffer format of
c5aa993b
JM
1608 the saved registers is byte-for-byte identical to the
1609 CORE_ADDR regs[NUM_REGS] format used by struct frame_saved_regs! */
cc17453a 1610 memcpy (fi->saved_regs, dummy_regs, sizeof (fi->saved_regs));
c906108c
SS
1611 return;
1612 }
1613
cc17453a
EZ
1614 fi->extra_info->leaf_function = 1;
1615 fi->extra_info->f_offset = 0;
c906108c 1616
cd4bffcf 1617 for (rn = 0; rn < NUM_REGS + NUM_PSEUDO_REGS; rn++)
c906108c
SS
1618 where[rn] = -1;
1619
1620 depth = 0;
1621
1622 /* Loop around examining the prologue insns until we find something
1623 that does not appear to be part of the prologue. But give up
1624 after 20 of them, since we're getting silly then. */
1625
50abf9e5 1626 pc = get_pc_function_start (get_frame_pc (fi));
2bfa91ee 1627 if (!pc)
c906108c 1628 {
50abf9e5 1629 deprecated_update_frame_pc_hack (fi, 0);
2bfa91ee
EZ
1630 return;
1631 }
1632
1633 for (opc = pc + (2 * 28); pc < opc; pc += 2)
1634 {
1635 insn = read_memory_integer (pc, 2);
c906108c
SS
1636 /* See where the registers will be saved to */
1637 if (IS_PUSH (insn))
1638 {
c906108c
SS
1639 rn = GET_PUSHED_REG (insn);
1640 where[rn] = depth;
c906108c
SS
1641 depth += 4;
1642 }
1643 else if (IS_STS (insn))
1644 {
f81353e4 1645 where[tdep->PR_REGNUM] = depth;
c906108c 1646 /* If we're storing the pr then this isn't a leaf */
cc17453a 1647 fi->extra_info->leaf_function = 0;
c906108c
SS
1648 depth += 4;
1649 }
1650 else if (IS_MOV_R3 (insn))
1651 {
1652 r3_val = ((insn & 0xff) ^ 0x80) - 0x80;
c906108c
SS
1653 }
1654 else if (IS_SHLL_R3 (insn))
1655 {
1656 r3_val <<= 1;
c906108c
SS
1657 }
1658 else if (IS_ADD_R3SP (insn))
1659 {
1660 depth += -r3_val;
c906108c
SS
1661 }
1662 else if (IS_ADD_SP (insn))
1663 {
c906108c 1664 depth -= ((insn & 0xff) ^ 0x80) - 0x80;
c906108c
SS
1665 }
1666 else if (IS_FMOV (insn))
1667 {
f81353e4 1668 if (read_register (tdep->FPSCR_REGNUM) & FPSCR_SZ)
c906108c
SS
1669 {
1670 depth += 8;
1671 }
1672 else
1673 {
1674 depth += 4;
1675 }
1676 }
2bfa91ee
EZ
1677 else if (IS_MOV_SP_FP (insn))
1678 break;
1679#if 0 /* This used to just stop when it found an instruction that
1680 was not considered part of the prologue. Now, we just
1681 keep going looking for likely instructions. */
c906108c
SS
1682 else
1683 break;
2bfa91ee 1684#endif
c906108c
SS
1685 }
1686
1687 /* Now we know how deep things are, we can work out their addresses */
1688
cd4bffcf 1689 for (rn = 0; rn < NUM_REGS + NUM_PSEUDO_REGS; rn++)
c906108c
SS
1690 {
1691 if (where[rn] >= 0)
1692 {
1693 if (rn == FP_REGNUM)
1694 have_fp = 1;
1695
b2fb4676 1696 get_frame_saved_regs (fi)[rn] = fi->frame - where[rn] + depth - 4;
c906108c
SS
1697 }
1698 else
1699 {
b2fb4676 1700 get_frame_saved_regs (fi)[rn] = 0;
c906108c
SS
1701 }
1702 }
1703
1704 if (have_fp)
1705 {
b2fb4676
AC
1706 get_frame_saved_regs (fi)[SP_REGNUM] =
1707 read_memory_integer (get_frame_saved_regs (fi)[FP_REGNUM], 4);
c906108c
SS
1708 }
1709 else
1710 {
b2fb4676 1711 get_frame_saved_regs (fi)[SP_REGNUM] = fi->frame - 4;
c906108c
SS
1712 }
1713
cc17453a 1714 fi->extra_info->f_offset = depth - where[FP_REGNUM] - 4;
c906108c
SS
1715 /* Work out the return pc - either from the saved pr or the pr
1716 value */
1717}
1718
cc17453a
EZ
1719/* Initialize the extra info saved in a FRAME */
1720static void
fba45db2 1721sh_init_extra_frame_info (int fromleaf, struct frame_info *fi)
c906108c 1722{
cc17453a 1723
a00a19e9 1724 frame_extra_info_zalloc (fi, sizeof (struct frame_extra_info));
c906108c
SS
1725
1726 if (fi->next)
50abf9e5 1727 deprecated_update_frame_pc_hack (fi, FRAME_SAVED_PC (fi->next));
c906108c 1728
50abf9e5 1729 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (fi), fi->frame, fi->frame))
c906108c
SS
1730 {
1731 /* We need to setup fi->frame here because run_stack_dummy gets it wrong
c5aa993b 1732 by assuming it's always FP. */
8ccd593b
AC
1733 deprecated_update_frame_base_hack (fi, deprecated_read_register_dummy (get_frame_pc (fi), fi->frame,
1734 SP_REGNUM));
50abf9e5 1735 fi->extra_info->return_pc = deprecated_read_register_dummy (get_frame_pc (fi),
135c175f
AC
1736 fi->frame,
1737 PC_REGNUM);
cc17453a
EZ
1738 fi->extra_info->f_offset = -(CALL_DUMMY_LENGTH + 4);
1739 fi->extra_info->leaf_function = 0;
c906108c
SS
1740 return;
1741 }
1742 else
1743 {
cc17453a 1744 FRAME_INIT_SAVED_REGS (fi);
cd4bffcf
EZ
1745 fi->extra_info->return_pc =
1746 sh_find_callers_reg (fi, gdbarch_tdep (current_gdbarch)->PR_REGNUM);
c906108c
SS
1747 }
1748}
1749
283150cd
EZ
1750static void
1751sh64_init_extra_frame_info (int fromleaf, struct frame_info *fi)
1752{
50abf9e5 1753 int media_mode = pc_is_isa32 (get_frame_pc (fi));
283150cd 1754
a00a19e9 1755 frame_extra_info_zalloc (fi, sizeof (struct frame_extra_info));
283150cd 1756
50abf9e5
AC
1757 if (fi->next)
1758 deprecated_update_frame_pc_hack (fi, FRAME_SAVED_PC (fi->next));
283150cd 1759
50abf9e5 1760 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (fi), fi->frame, fi->frame))
283150cd
EZ
1761 {
1762 /* We need to setup fi->frame here because run_stack_dummy gets it wrong
1763 by assuming it's always FP. */
8ccd593b
AC
1764 deprecated_update_frame_base_hack (fi, deprecated_read_register_dummy (get_frame_pc (fi), fi->frame,
1765 SP_REGNUM));
283150cd 1766 fi->extra_info->return_pc =
50abf9e5 1767 deprecated_read_register_dummy (get_frame_pc (fi), fi->frame, PC_REGNUM);
283150cd
EZ
1768 fi->extra_info->f_offset = -(CALL_DUMMY_LENGTH + 4);
1769 fi->extra_info->leaf_function = 0;
1770 return;
1771 }
1772 else
1773 {
1774 FRAME_INIT_SAVED_REGS (fi);
1775 fi->extra_info->return_pc =
1776 sh64_get_saved_pr (fi, gdbarch_tdep (current_gdbarch)->PR_REGNUM);
1777 }
1778}
1779
1780void
1781sh64_get_saved_register (char *raw_buffer, int *optimized, CORE_ADDR *addrp,
1782 struct frame_info *frame, int regnum,
1783 enum lval_type *lval)
1784{
1785 int media_mode;
1786 int live_regnum = regnum;
1787 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
1788
1789 if (!target_has_registers)
1790 error ("No registers.");
1791
1792 /* Normal systems don't optimize out things with register numbers. */
1793 if (optimized != NULL)
1794 *optimized = 0;
1795
1796 if (addrp) /* default assumption: not found in memory */
1797 *addrp = 0;
1798
1799 if (raw_buffer)
1800 memset (raw_buffer, 0, sizeof (raw_buffer));
1801
1802 /* We must do this here, before the following while loop changes
1803 frame, and makes it NULL. If this is a media register number,
1804 but we are in compact mode, it will become the corresponding
1805 compact pseudo register. If there is no corresponding compact
1806 pseudo-register what do we do?*/
50abf9e5 1807 media_mode = pc_is_isa32 (get_frame_pc (frame));
283150cd
EZ
1808 live_regnum = translate_insn_rn (regnum, media_mode);
1809
1810 /* Note: since the current frame's registers could only have been
1811 saved by frames INTERIOR TO the current frame, we skip examining
1812 the current frame itself: otherwise, we would be getting the
1813 previous frame's registers which were saved by the current frame. */
1814
1815 while (frame && ((frame = frame->next) != NULL))
1816 {
50abf9e5 1817 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (frame), frame->frame, frame->frame))
283150cd
EZ
1818 {
1819 if (lval) /* found it in a CALL_DUMMY frame */
1820 *lval = not_lval;
1821 if (raw_buffer)
1822 memcpy (raw_buffer,
50abf9e5 1823 (deprecated_generic_find_dummy_frame (get_frame_pc (frame), frame->frame)
da130f98 1824 + REGISTER_BYTE (regnum)),
283150cd
EZ
1825 REGISTER_RAW_SIZE (regnum));
1826 return;
1827 }
1828
1829 FRAME_INIT_SAVED_REGS (frame);
b2fb4676
AC
1830 if (get_frame_saved_regs (frame) != NULL
1831 && get_frame_saved_regs (frame)[regnum] != 0)
283150cd
EZ
1832 {
1833 if (lval) /* found it saved on the stack */
1834 *lval = lval_memory;
1835 if (regnum == SP_REGNUM)
1836 {
1837 if (raw_buffer) /* SP register treated specially */
1838 store_address (raw_buffer, REGISTER_RAW_SIZE (regnum),
b2fb4676 1839 get_frame_saved_regs (frame)[regnum]);
283150cd
EZ
1840 }
1841 else
1842 { /* any other register */
1843
1844 if (addrp)
b2fb4676 1845 *addrp = get_frame_saved_regs (frame)[regnum];
283150cd
EZ
1846 if (raw_buffer)
1847 {
1848 int size;
1849 if (tdep->sh_abi == SH_ABI_32
1850 && (live_regnum == FP_REGNUM
1851 || live_regnum == tdep->PR_REGNUM))
1852 size = 4;
1853 else
1854 size = REGISTER_RAW_SIZE (live_regnum);
1855 if (TARGET_BYTE_ORDER == BFD_ENDIAN_LITTLE)
b2fb4676 1856 read_memory (get_frame_saved_regs (frame)[regnum], raw_buffer, size);
283150cd 1857 else
b2fb4676 1858 read_memory (get_frame_saved_regs (frame)[regnum],
283150cd
EZ
1859 raw_buffer
1860 + REGISTER_RAW_SIZE (live_regnum)
1861 - size,
1862 size);
1863 }
1864 }
1865 return;
1866 }
1867 }
1868
1869 /* If we get thru the loop to this point, it means the register was
1870 not saved in any frame. Return the actual live-register value. */
1871
1872 if (lval) /* found it in a live register */
1873 *lval = lval_register;
1874 if (addrp)
1875 *addrp = REGISTER_BYTE (live_regnum);
1876 if (raw_buffer)
4caf0990 1877 deprecated_read_register_gen (live_regnum, raw_buffer);
283150cd
EZ
1878}
1879
cc17453a
EZ
1880/* Extract from an array REGBUF containing the (raw) register state
1881 the address in which a function should return its structure value,
1882 as a CORE_ADDR (or an expression that can be used as one). */
b3df3fff 1883static CORE_ADDR
0c8053b6 1884sh_extract_struct_value_address (char *regbuf)
cc17453a
EZ
1885{
1886 return (extract_address ((regbuf), REGISTER_RAW_SIZE (0)));
1887}
1888
283150cd
EZ
1889static CORE_ADDR
1890sh64_extract_struct_value_address (char *regbuf)
1891{
1892 return (extract_address ((regbuf + REGISTER_BYTE (STRUCT_RETURN_REGNUM)),
1893 REGISTER_RAW_SIZE (STRUCT_RETURN_REGNUM)));
1894}
1895
cc17453a 1896static CORE_ADDR
fba45db2 1897sh_frame_saved_pc (struct frame_info *frame)
cc17453a
EZ
1898{
1899 return ((frame)->extra_info->return_pc);
1900}
1901
c906108c
SS
1902/* Discard from the stack the innermost frame,
1903 restoring all saved registers. */
cc17453a 1904static void
fba45db2 1905sh_pop_frame (void)
c906108c
SS
1906{
1907 register struct frame_info *frame = get_current_frame ();
1908 register CORE_ADDR fp;
1909 register int regnum;
c906108c 1910
50abf9e5 1911 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (frame), frame->frame, frame->frame))
c906108c
SS
1912 generic_pop_dummy_frame ();
1913 else
c5aa993b 1914 {
c193f6ac 1915 fp = get_frame_base (frame);
cc17453a 1916 FRAME_INIT_SAVED_REGS (frame);
c906108c 1917
c5aa993b 1918 /* Copy regs from where they were saved in the frame */
cd4bffcf 1919 for (regnum = 0; regnum < NUM_REGS + NUM_PSEUDO_REGS; regnum++)
b2fb4676 1920 if (get_frame_saved_regs (frame)[regnum])
cd4bffcf 1921 write_register (regnum,
b2fb4676 1922 read_memory_integer (get_frame_saved_regs (frame)[regnum], 4));
c906108c 1923
cc17453a 1924 write_register (PC_REGNUM, frame->extra_info->return_pc);
c5aa993b
JM
1925 write_register (SP_REGNUM, fp + 4);
1926 }
c906108c
SS
1927 flush_cached_frames ();
1928}
1929
283150cd
EZ
1930/* Used in the 'return' command. */
1931static void
1932sh64_pop_frame (void)
1933{
1934 register struct frame_info *frame = get_current_frame ();
1935 register CORE_ADDR fp;
1936 register int regnum;
1937 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
1938
50abf9e5 1939 int media_mode = pc_is_isa32 (get_frame_pc (frame));
283150cd 1940
50abf9e5 1941 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (frame), frame->frame, frame->frame))
283150cd
EZ
1942 generic_pop_dummy_frame ();
1943 else
1944 {
c193f6ac 1945 fp = get_frame_base (frame);
283150cd
EZ
1946 FRAME_INIT_SAVED_REGS (frame);
1947
1948 /* Copy regs from where they were saved in the frame */
1949 for (regnum = 0; regnum < NUM_REGS + NUM_PSEUDO_REGS; regnum++)
b2fb4676 1950 if (get_frame_saved_regs (frame)[regnum])
283150cd
EZ
1951 {
1952 int size;
1953 if (tdep->sh_abi == SH_ABI_32
1954 && (regnum == FP_REGNUM
1955 || regnum == tdep->PR_REGNUM))
1956 size = 4;
1957 else
1958 size = REGISTER_RAW_SIZE (translate_insn_rn (regnum,
1959 media_mode));
1960 write_register (regnum,
b2fb4676 1961 read_memory_integer (get_frame_saved_regs (frame)[regnum],
283150cd
EZ
1962 size));
1963 }
1964
1965 write_register (PC_REGNUM, frame->extra_info->return_pc);
1966 write_register (SP_REGNUM, fp + 8);
1967 }
1968 flush_cached_frames ();
1969}
1970
c906108c
SS
1971/* Function: push_arguments
1972 Setup the function arguments for calling a function in the inferior.
1973
1974 On the Hitachi SH architecture, there are four registers (R4 to R7)
1975 which are dedicated for passing function arguments. Up to the first
1976 four arguments (depending on size) may go into these registers.
1977 The rest go on the stack.
1978
1979 Arguments that are smaller than 4 bytes will still take up a whole
1980 register or a whole 32-bit word on the stack, and will be
1981 right-justified in the register or the stack word. This includes
1982 chars, shorts, and small aggregate types.
1983
1984 Arguments that are larger than 4 bytes may be split between two or
1985 more registers. If there are not enough registers free, an argument
1986 may be passed partly in a register (or registers), and partly on the
1987 stack. This includes doubles, long longs, and larger aggregates.
1988 As far as I know, there is no upper limit to the size of aggregates
1989 that will be passed in this way; in other words, the convention of
1990 passing a pointer to a large aggregate instead of a copy is not used.
1991
1992 An exceptional case exists for struct arguments (and possibly other
1993 aggregates such as arrays) if the size is larger than 4 bytes but
1994 not a multiple of 4 bytes. In this case the argument is never split
1995 between the registers and the stack, but instead is copied in its
1996 entirety onto the stack, AND also copied into as many registers as
1997 there is room for. In other words, space in registers permitting,
1998 two copies of the same argument are passed in. As far as I can tell,
1999 only the one on the stack is used, although that may be a function
2000 of the level of compiler optimization. I suspect this is a compiler
2001 bug. Arguments of these odd sizes are left-justified within the
2002 word (as opposed to arguments smaller than 4 bytes, which are
2003 right-justified).
c5aa993b 2004
c906108c
SS
2005 If the function is to return an aggregate type such as a struct, it
2006 is either returned in the normal return value register R0 (if its
2007 size is no greater than one byte), or else the caller must allocate
2008 space into which the callee will copy the return value (if the size
2009 is greater than one byte). In this case, a pointer to the return
2010 value location is passed into the callee in register R2, which does
2011 not displace any of the other arguments passed in via registers R4
2012 to R7. */
2013
cc17453a 2014static CORE_ADDR
34e9d9bb 2015sh_push_arguments (int nargs, struct value **args, CORE_ADDR sp,
3bbfbb92 2016 int struct_return, CORE_ADDR struct_addr)
c906108c
SS
2017{
2018 int stack_offset, stack_alloc;
2019 int argreg;
2020 int argnum;
2021 struct type *type;
2022 CORE_ADDR regval;
2023 char *val;
2024 char valbuf[4];
2025 int len;
2026 int odd_sized_struct;
f81353e4 2027 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
c906108c
SS
2028
2029 /* first force sp to a 4-byte alignment */
2030 sp = sp & ~3;
2031
2032 /* The "struct return pointer" pseudo-argument has its own dedicated
2033 register */
2034 if (struct_return)
c5aa993b 2035 write_register (STRUCT_RETURN_REGNUM, struct_addr);
c906108c
SS
2036
2037 /* Now make sure there's space on the stack */
cc17453a 2038 for (argnum = 0, stack_alloc = 0; argnum < nargs; argnum++)
c5aa993b
JM
2039 stack_alloc += ((TYPE_LENGTH (VALUE_TYPE (args[argnum])) + 3) & ~3);
2040 sp -= stack_alloc; /* make room on stack for args */
c906108c 2041
c906108c
SS
2042 /* Now load as many as possible of the first arguments into
2043 registers, and push the rest onto the stack. There are 16 bytes
2044 in four registers available. Loop thru args from first to last. */
2045
f81353e4 2046 argreg = tdep->ARG0_REGNUM;
c906108c
SS
2047 for (argnum = 0, stack_offset = 0; argnum < nargs; argnum++)
2048 {
2049 type = VALUE_TYPE (args[argnum]);
c5aa993b
JM
2050 len = TYPE_LENGTH (type);
2051 memset (valbuf, 0, sizeof (valbuf));
c906108c 2052 if (len < 4)
cc17453a
EZ
2053 {
2054 /* value gets right-justified in the register or stack word */
7079c36c
CV
2055 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
2056 memcpy (valbuf + (4 - len),
2057 (char *) VALUE_CONTENTS (args[argnum]), len);
2058 else
2059 memcpy (valbuf, (char *) VALUE_CONTENTS (args[argnum]), len);
c5aa993b
JM
2060 val = valbuf;
2061 }
c906108c 2062 else
c5aa993b 2063 val = (char *) VALUE_CONTENTS (args[argnum]);
c906108c
SS
2064
2065 if (len > 4 && (len & 3) != 0)
c5aa993b
JM
2066 odd_sized_struct = 1; /* such structs go entirely on stack */
2067 else
c906108c
SS
2068 odd_sized_struct = 0;
2069 while (len > 0)
2070 {
f81353e4 2071 if (argreg > tdep->ARGLAST_REGNUM
3bbfbb92
EZ
2072 || odd_sized_struct)
2073 {
2074 /* must go on the stack */
c906108c
SS
2075 write_memory (sp + stack_offset, val, 4);
2076 stack_offset += 4;
2077 }
2078 /* NOTE WELL!!!!! This is not an "else if" clause!!!
2079 That's because some *&^%$ things get passed on the stack
2080 AND in the registers! */
f81353e4 2081 if (argreg <= tdep->ARGLAST_REGNUM)
3bbfbb92
EZ
2082 {
2083 /* there's room in a register */
c5aa993b 2084 regval = extract_address (val, REGISTER_RAW_SIZE (argreg));
c906108c
SS
2085 write_register (argreg++, regval);
2086 }
2087 /* Store the value 4 bytes at a time. This means that things
2088 larger than 4 bytes may go partly in registers and partly
2089 on the stack. */
c5aa993b
JM
2090 len -= REGISTER_RAW_SIZE (argreg);
2091 val += REGISTER_RAW_SIZE (argreg);
c906108c
SS
2092 }
2093 }
2094 return sp;
2095}
2096
283150cd
EZ
2097/* R2-R9 for integer types and integer equivalent (char, pointers) and
2098 non-scalar (struct, union) elements (even if the elements are
2099 floats).
2100 FR0-FR11 for single precision floating point (float)
2101 DR0-DR10 for double precision floating point (double)
2102
2103 If a float is argument number 3 (for instance) and arguments number
2104 1,2, and 4 are integer, the mapping will be:
2105 arg1 -->R2, arg2 --> R3, arg3 -->FR0, arg4 --> R5. I.e. R4 is not used.
2106
2107 If a float is argument number 10 (for instance) and arguments number
2108 1 through 10 are integer, the mapping will be:
2109 arg1->R2, arg2->R3, arg3->R4, arg4->R5, arg5->R6, arg6->R7, arg7->R8,
2110 arg8->R9, arg9->(0,SP)stack(8-byte aligned), arg10->FR0, arg11->stack(16,SP).
2111 I.e. there is hole in the stack.
2112
2113 Different rules apply for variable arguments functions, and for functions
2114 for which the prototype is not known. */
2115
2116static CORE_ADDR
2117sh64_push_arguments (int nargs, struct value **args, CORE_ADDR sp,
2118 int struct_return, CORE_ADDR struct_addr)
2119{
2120 int stack_offset, stack_alloc;
2121 int int_argreg;
2122 int float_argreg;
2123 int double_argreg;
2124 int float_arg_index = 0;
2125 int double_arg_index = 0;
2126 int argnum;
2127 struct type *type;
2128 CORE_ADDR regval;
2129 char *val;
2130 char valbuf[8];
2131 char valbuf_tmp[8];
2132 int len;
2133 int argreg_size;
2134 int fp_args[12];
2135 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
2136
2137 memset (fp_args, 0, sizeof (fp_args));
2138
2139 /* first force sp to a 8-byte alignment */
2140 sp = sp & ~7;
2141
2142 /* The "struct return pointer" pseudo-argument has its own dedicated
2143 register */
2144
2145 if (struct_return)
2146 write_register (STRUCT_RETURN_REGNUM, struct_addr);
2147
2148 /* Now make sure there's space on the stack */
2149 for (argnum = 0, stack_alloc = 0; argnum < nargs; argnum++)
2150 stack_alloc += ((TYPE_LENGTH (VALUE_TYPE (args[argnum])) + 7) & ~7);
2151 sp -= stack_alloc; /* make room on stack for args */
2152
2153 /* Now load as many as possible of the first arguments into
2154 registers, and push the rest onto the stack. There are 64 bytes
2155 in eight registers available. Loop thru args from first to last. */
2156
2157 int_argreg = tdep->ARG0_REGNUM;
2158 float_argreg = FP0_REGNUM;
2159 double_argreg = tdep->DR0_REGNUM;
2160
2161 for (argnum = 0, stack_offset = 0; argnum < nargs; argnum++)
2162 {
2163 type = VALUE_TYPE (args[argnum]);
2164 len = TYPE_LENGTH (type);
2165 memset (valbuf, 0, sizeof (valbuf));
2166
2167 if (TYPE_CODE (type) != TYPE_CODE_FLT)
2168 {
2169 argreg_size = REGISTER_RAW_SIZE (int_argreg);
2170
2171 if (len < argreg_size)
2172 {
2173 /* value gets right-justified in the register or stack word */
2174 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
2175 memcpy (valbuf + argreg_size - len,
2176 (char *) VALUE_CONTENTS (args[argnum]), len);
2177 else
2178 memcpy (valbuf, (char *) VALUE_CONTENTS (args[argnum]), len);
2179
2180 val = valbuf;
2181 }
2182 else
2183 val = (char *) VALUE_CONTENTS (args[argnum]);
2184
2185 while (len > 0)
2186 {
2187 if (int_argreg > tdep->ARGLAST_REGNUM)
2188 {
2189 /* must go on the stack */
2190 write_memory (sp + stack_offset, val, argreg_size);
2191 stack_offset += 8;/*argreg_size;*/
2192 }
2193 /* NOTE WELL!!!!! This is not an "else if" clause!!!
2194 That's because some *&^%$ things get passed on the stack
2195 AND in the registers! */
2196 if (int_argreg <= tdep->ARGLAST_REGNUM)
2197 {
2198 /* there's room in a register */
2199 regval = extract_address (val, argreg_size);
2200 write_register (int_argreg, regval);
2201 }
2202 /* Store the value 8 bytes at a time. This means that
2203 things larger than 8 bytes may go partly in registers
2204 and partly on the stack. FIXME: argreg is incremented
2205 before we use its size. */
2206 len -= argreg_size;
2207 val += argreg_size;
2208 int_argreg++;
2209 }
2210 }
2211 else
2212 {
2213 val = (char *) VALUE_CONTENTS (args[argnum]);
2214 if (len == 4)
2215 {
2216 /* Where is it going to be stored? */
2217 while (fp_args[float_arg_index])
2218 float_arg_index ++;
2219
2220 /* Now float_argreg points to the register where it
2221 should be stored. Are we still within the allowed
2222 register set? */
2223 if (float_arg_index <= tdep->FLOAT_ARGLAST_REGNUM)
2224 {
2225 /* Goes in FR0...FR11 */
4caf0990
AC
2226 deprecated_write_register_gen (FP0_REGNUM + float_arg_index,
2227 val);
283150cd
EZ
2228 fp_args[float_arg_index] = 1;
2229 /* Skip the corresponding general argument register. */
2230 int_argreg ++;
2231 }
2232 else
2233 ;
2234 /* Store it as the integers, 8 bytes at the time, if
2235 necessary spilling on the stack. */
2236
2237 }
2238 else if (len == 8)
2239 {
2240 /* Where is it going to be stored? */
2241 while (fp_args[double_arg_index])
2242 double_arg_index += 2;
2243 /* Now double_argreg points to the register
2244 where it should be stored.
2245 Are we still within the allowed register set? */
2246 if (double_arg_index < tdep->FLOAT_ARGLAST_REGNUM)
2247 {
2248 /* Goes in DR0...DR10 */
2249 /* The numbering of the DRi registers is consecutive,
2250 i.e. includes odd numbers. */
2251 int double_register_offset = double_arg_index / 2;
2252 int regnum = tdep->DR0_REGNUM +
2253 double_register_offset;
2254#if 0
2255 if (TARGET_BYTE_ORDER == BFD_ENDIAN_LITTLE)
2256 {
2257 memset (valbuf_tmp, 0, sizeof (valbuf_tmp));
2258 REGISTER_CONVERT_TO_VIRTUAL (regnum,
2259 type, val, valbuf_tmp);
2260 val = valbuf_tmp;
2261 }
2262#endif
2263 /* Note: must use write_register_gen here instead
0818c12a
AC
2264 of regcache_raw_write, because
2265 regcache_raw_write works only for real
2266 registers, not pseudo. write_register_gen will
2267 call the gdbarch function to do register
2268 writes, and that will properly know how to deal
2269 with pseudoregs. */
4caf0990 2270 deprecated_write_register_gen (regnum, val);
283150cd
EZ
2271 fp_args[double_arg_index] = 1;
2272 fp_args[double_arg_index + 1] = 1;
2273 /* Skip the corresponding general argument register. */
2274 int_argreg ++;
2275 }
2276 else
2277 ;
2278 /* Store it as the integers, 8 bytes at the time, if
2279 necessary spilling on the stack. */
2280 }
2281 }
2282 }
2283 return sp;
2284}
2285
c906108c
SS
2286/* Function: push_return_address (pc)
2287 Set up the return address for the inferior function call.
2288 Needed for targets where we don't actually execute a JSR/BSR instruction */
2289
cc17453a 2290static CORE_ADDR
fba45db2 2291sh_push_return_address (CORE_ADDR pc, CORE_ADDR sp)
c906108c 2292{
283150cd
EZ
2293 write_register (gdbarch_tdep (current_gdbarch)->PR_REGNUM,
2294 CALL_DUMMY_ADDRESS ());
c906108c
SS
2295 return sp;
2296}
2297
2298/* Function: fix_call_dummy
2299 Poke the callee function's address into the destination part of
2300 the CALL_DUMMY. The address is actually stored in a data word
2301 following the actualy CALL_DUMMY instructions, which will load
2302 it into a register using PC-relative addressing. This function
2303 expects the CALL_DUMMY to look like this:
2304
c5aa993b
JM
2305 mov.w @(2,PC), R8
2306 jsr @R8
2307 nop
2308 trap
2309 <destination>
2310 */
c906108c
SS
2311
2312#if 0
2313void
fba45db2 2314sh_fix_call_dummy (char *dummy, CORE_ADDR pc, CORE_ADDR fun, int nargs,
ea7c478f 2315 struct value **args, struct type *type, int gcc_p)
c906108c
SS
2316{
2317 *(unsigned long *) (dummy + 8) = fun;
2318}
2319#endif
2320
cc17453a
EZ
2321/* Find a function's return value in the appropriate registers (in
2322 regbuf), and copy it into valbuf. Extract from an array REGBUF
2323 containing the (raw) register state a function return value of type
2324 TYPE, and copy that, in virtual format, into VALBUF. */
2325static void
fba45db2 2326sh_extract_return_value (struct type *type, char *regbuf, char *valbuf)
c906108c 2327{
cc17453a 2328 int len = TYPE_LENGTH (type);
3116c80a
EZ
2329 int return_register = R0_REGNUM;
2330 int offset;
2331
cc17453a 2332 if (len <= 4)
3116c80a 2333 {
d7449b42 2334 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3116c80a
EZ
2335 offset = REGISTER_BYTE (return_register) + 4 - len;
2336 else
2337 offset = REGISTER_BYTE (return_register);
2338 memcpy (valbuf, regbuf + offset, len);
2339 }
cc17453a 2340 else if (len <= 8)
3116c80a 2341 {
d7449b42 2342 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3116c80a
EZ
2343 offset = REGISTER_BYTE (return_register) + 8 - len;
2344 else
2345 offset = REGISTER_BYTE (return_register);
2346 memcpy (valbuf, regbuf + offset, len);
2347 }
2348 else
2349 error ("bad size for return value");
2350}
2351
2352static void
2353sh3e_sh4_extract_return_value (struct type *type, char *regbuf, char *valbuf)
2354{
2355 int return_register;
2356 int offset;
2357 int len = TYPE_LENGTH (type);
2358
2359 if (TYPE_CODE (type) == TYPE_CODE_FLT)
2360 return_register = FP0_REGNUM;
2361 else
2362 return_register = R0_REGNUM;
2363
2364 if (len == 8 && TYPE_CODE (type) == TYPE_CODE_FLT)
2365 {
2366 DOUBLEST val;
778eb05e 2367 if (TARGET_BYTE_ORDER == BFD_ENDIAN_LITTLE)
3116c80a
EZ
2368 floatformat_to_doublest (&floatformat_ieee_double_littlebyte_bigword,
2369 (char *) regbuf + REGISTER_BYTE (return_register),
2370 &val);
2371 else
2372 floatformat_to_doublest (&floatformat_ieee_double_big,
2373 (char *) regbuf + REGISTER_BYTE (return_register),
2374 &val);
2375 store_floating (valbuf, len, val);
2376 }
2377 else if (len <= 4)
2378 {
d7449b42 2379 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3116c80a
EZ
2380 offset = REGISTER_BYTE (return_register) + 4 - len;
2381 else
2382 offset = REGISTER_BYTE (return_register);
2383 memcpy (valbuf, regbuf + offset, len);
2384 }
2385 else if (len <= 8)
2386 {
d7449b42 2387 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3116c80a
EZ
2388 offset = REGISTER_BYTE (return_register) + 8 - len;
2389 else
2390 offset = REGISTER_BYTE (return_register);
2391 memcpy (valbuf, regbuf + offset, len);
2392 }
cc17453a
EZ
2393 else
2394 error ("bad size for return value");
2395}
c906108c 2396
283150cd
EZ
2397static void
2398sh64_extract_return_value (struct type *type, char *regbuf, char *valbuf)
2399{
2400 int offset;
2401 int return_register;
2402 int len = TYPE_LENGTH (type);
2403 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
2404
2405 if (TYPE_CODE (type) == TYPE_CODE_FLT)
2406 {
2407 if (len == 4)
2408 {
2409 /* Return value stored in FP0_REGNUM */
2410 return_register = FP0_REGNUM;
2411 offset = REGISTER_BYTE (return_register);
2412 memcpy (valbuf, (char *) regbuf + offset, len);
2413 }
2414 else if (len == 8)
2415 {
2416 /* return value stored in DR0_REGNUM */
2417 DOUBLEST val;
2418
2419 return_register = tdep->DR0_REGNUM;
2420 offset = REGISTER_BYTE (return_register);
2421
2422 if (TARGET_BYTE_ORDER == BFD_ENDIAN_LITTLE)
2423 floatformat_to_doublest (&floatformat_ieee_double_littlebyte_bigword,
2424 (char *) regbuf + offset, &val);
2425 else
2426 floatformat_to_doublest (&floatformat_ieee_double_big,
2427 (char *) regbuf + offset, &val);
2428 store_floating (valbuf, len, val);
2429 }
2430 }
2431 else
2432 {
2433 if (len <= 8)
2434 {
2435 /* Result is in register 2. If smaller than 8 bytes, it is padded
2436 at the most significant end. */
2437 return_register = tdep->RETURN_REGNUM;
2438 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
2439 offset = REGISTER_BYTE (return_register) +
2440 REGISTER_RAW_SIZE (return_register) - len;
2441 else
2442 offset = REGISTER_BYTE (return_register);
2443 memcpy (valbuf, (char *) regbuf + offset, len);
2444 }
2445 else
2446 error ("bad size for return value");
2447 }
2448}
2449
cc17453a
EZ
2450/* Write into appropriate registers a function return value
2451 of type TYPE, given in virtual format.
2452 If the architecture is sh4 or sh3e, store a function's return value
2453 in the R0 general register or in the FP0 floating point register,
2454 depending on the type of the return value. In all the other cases
3bbfbb92 2455 the result is stored in r0, left-justified. */
cc17453a
EZ
2456static void
2457sh_default_store_return_value (struct type *type, char *valbuf)
2458{
d19b71be
MS
2459 char buf[32]; /* more than enough... */
2460
2461 if (TYPE_LENGTH (type) < REGISTER_RAW_SIZE (R0_REGNUM))
2462 {
2463 /* Add leading zeros to the value. */
2464 memset (buf, 0, REGISTER_RAW_SIZE (R0_REGNUM));
7079c36c
CV
2465 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
2466 memcpy (buf + REGISTER_RAW_SIZE (R0_REGNUM) - TYPE_LENGTH (type),
2467 valbuf, TYPE_LENGTH (type));
2468 else
2469 memcpy (buf, valbuf, TYPE_LENGTH (type));
73937e03
AC
2470 deprecated_write_register_bytes (REGISTER_BYTE (R0_REGNUM), buf,
2471 REGISTER_RAW_SIZE (R0_REGNUM));
d19b71be
MS
2472 }
2473 else
73937e03
AC
2474 deprecated_write_register_bytes (REGISTER_BYTE (R0_REGNUM), valbuf,
2475 TYPE_LENGTH (type));
cc17453a 2476}
c906108c 2477
cc17453a
EZ
2478static void
2479sh3e_sh4_store_return_value (struct type *type, char *valbuf)
2480{
2481 if (TYPE_CODE (type) == TYPE_CODE_FLT)
73937e03
AC
2482 deprecated_write_register_bytes (REGISTER_BYTE (FP0_REGNUM),
2483 valbuf, TYPE_LENGTH (type));
cc17453a 2484 else
d19b71be 2485 sh_default_store_return_value (type, valbuf);
c906108c
SS
2486}
2487
283150cd
EZ
2488static void
2489sh64_store_return_value (struct type *type, char *valbuf)
2490{
2491 char buf[64]; /* more than enough... */
2492 int len = TYPE_LENGTH (type);
2493
2494 if (TYPE_CODE (type) == TYPE_CODE_FLT)
2495 {
2496 if (len == 4)
2497 {
2498 /* Return value stored in FP0_REGNUM */
4caf0990 2499 deprecated_write_register_gen (FP0_REGNUM, valbuf);
283150cd
EZ
2500 }
2501 if (len == 8)
2502 {
2503 /* return value stored in DR0_REGNUM */
2504 /* FIXME: Implement */
2505 }
2506 }
2507 else
2508 {
2509 int return_register = gdbarch_tdep (current_gdbarch)->RETURN_REGNUM;
2510 int offset = 0;
2511
2512 if (len <= REGISTER_RAW_SIZE (return_register))
2513 {
2514 /* Pad with zeros. */
2515 memset (buf, 0, REGISTER_RAW_SIZE (return_register));
2516 if (TARGET_BYTE_ORDER == BFD_ENDIAN_LITTLE)
2517 offset = 0; /*REGISTER_RAW_SIZE (return_register) - len;*/
2518 else
2519 offset = REGISTER_RAW_SIZE (return_register) - len;
2520
2521 memcpy (buf + offset, valbuf, len);
4caf0990 2522 deprecated_write_register_gen (return_register, buf);
283150cd
EZ
2523 }
2524 else
4caf0990 2525 deprecated_write_register_gen (return_register, valbuf);
283150cd
EZ
2526 }
2527}
2528
c906108c
SS
2529/* Print the registers in a form similar to the E7000 */
2530
2531static void
fba45db2 2532sh_generic_show_regs (void)
c906108c 2533{
f81353e4
EZ
2534 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
2535
cc17453a
EZ
2536 printf_filtered ("PC=%s SR=%08lx PR=%08lx MACH=%08lx MACHL=%08lx\n",
2537 paddr (read_register (PC_REGNUM)),
f81353e4
EZ
2538 (long) read_register (tdep->SR_REGNUM),
2539 (long) read_register (tdep->PR_REGNUM),
cc17453a
EZ
2540 (long) read_register (MACH_REGNUM),
2541 (long) read_register (MACL_REGNUM));
2542
2543 printf_filtered ("GBR=%08lx VBR=%08lx",
2544 (long) read_register (GBR_REGNUM),
2545 (long) read_register (VBR_REGNUM));
2546
2547 printf_filtered ("\nR0-R7 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
2548 (long) read_register (0),
2549 (long) read_register (1),
2550 (long) read_register (2),
2551 (long) read_register (3),
2552 (long) read_register (4),
2553 (long) read_register (5),
2554 (long) read_register (6),
2555 (long) read_register (7));
2556 printf_filtered ("R8-R15 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
2557 (long) read_register (8),
2558 (long) read_register (9),
2559 (long) read_register (10),
2560 (long) read_register (11),
2561 (long) read_register (12),
2562 (long) read_register (13),
2563 (long) read_register (14),
2564 (long) read_register (15));
2565}
c906108c 2566
cc17453a 2567static void
fba45db2 2568sh3_show_regs (void)
cc17453a 2569{
f81353e4
EZ
2570 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
2571
d4f3574e
SS
2572 printf_filtered ("PC=%s SR=%08lx PR=%08lx MACH=%08lx MACHL=%08lx\n",
2573 paddr (read_register (PC_REGNUM)),
f81353e4
EZ
2574 (long) read_register (tdep->SR_REGNUM),
2575 (long) read_register (tdep->PR_REGNUM),
d4f3574e
SS
2576 (long) read_register (MACH_REGNUM),
2577 (long) read_register (MACL_REGNUM));
2578
2579 printf_filtered ("GBR=%08lx VBR=%08lx",
2580 (long) read_register (GBR_REGNUM),
2581 (long) read_register (VBR_REGNUM));
cc17453a 2582 printf_filtered (" SSR=%08lx SPC=%08lx",
f81353e4
EZ
2583 (long) read_register (tdep->SSR_REGNUM),
2584 (long) read_register (tdep->SPC_REGNUM));
c906108c 2585
d4f3574e
SS
2586 printf_filtered ("\nR0-R7 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
2587 (long) read_register (0),
2588 (long) read_register (1),
2589 (long) read_register (2),
2590 (long) read_register (3),
2591 (long) read_register (4),
2592 (long) read_register (5),
2593 (long) read_register (6),
2594 (long) read_register (7));
2595 printf_filtered ("R8-R15 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
2596 (long) read_register (8),
2597 (long) read_register (9),
2598 (long) read_register (10),
2599 (long) read_register (11),
2600 (long) read_register (12),
2601 (long) read_register (13),
2602 (long) read_register (14),
2603 (long) read_register (15));
c906108c
SS
2604}
2605
53116e27 2606
cc17453a 2607static void
fba45db2 2608sh3e_show_regs (void)
cc17453a 2609{
f81353e4
EZ
2610 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
2611
cc17453a
EZ
2612 printf_filtered ("PC=%s SR=%08lx PR=%08lx MACH=%08lx MACHL=%08lx\n",
2613 paddr (read_register (PC_REGNUM)),
f81353e4
EZ
2614 (long) read_register (tdep->SR_REGNUM),
2615 (long) read_register (tdep->PR_REGNUM),
cc17453a
EZ
2616 (long) read_register (MACH_REGNUM),
2617 (long) read_register (MACL_REGNUM));
2618
2619 printf_filtered ("GBR=%08lx VBR=%08lx",
2620 (long) read_register (GBR_REGNUM),
2621 (long) read_register (VBR_REGNUM));
2622 printf_filtered (" SSR=%08lx SPC=%08lx",
f81353e4
EZ
2623 (long) read_register (tdep->SSR_REGNUM),
2624 (long) read_register (tdep->SPC_REGNUM));
cc17453a 2625 printf_filtered (" FPUL=%08lx FPSCR=%08lx",
f81353e4
EZ
2626 (long) read_register (tdep->FPUL_REGNUM),
2627 (long) read_register (tdep->FPSCR_REGNUM));
c906108c 2628
cc17453a
EZ
2629 printf_filtered ("\nR0-R7 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
2630 (long) read_register (0),
2631 (long) read_register (1),
2632 (long) read_register (2),
2633 (long) read_register (3),
2634 (long) read_register (4),
2635 (long) read_register (5),
2636 (long) read_register (6),
2637 (long) read_register (7));
2638 printf_filtered ("R8-R15 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
2639 (long) read_register (8),
2640 (long) read_register (9),
2641 (long) read_register (10),
2642 (long) read_register (11),
2643 (long) read_register (12),
2644 (long) read_register (13),
2645 (long) read_register (14),
2646 (long) read_register (15));
2647
2648 printf_filtered (("FP0-FP7 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n"),
2649 (long) read_register (FP0_REGNUM + 0),
2650 (long) read_register (FP0_REGNUM + 1),
2651 (long) read_register (FP0_REGNUM + 2),
2652 (long) read_register (FP0_REGNUM + 3),
2653 (long) read_register (FP0_REGNUM + 4),
2654 (long) read_register (FP0_REGNUM + 5),
2655 (long) read_register (FP0_REGNUM + 6),
2656 (long) read_register (FP0_REGNUM + 7));
2657 printf_filtered (("FP8-FP15 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n"),
2658 (long) read_register (FP0_REGNUM + 8),
2659 (long) read_register (FP0_REGNUM + 9),
2660 (long) read_register (FP0_REGNUM + 10),
2661 (long) read_register (FP0_REGNUM + 11),
2662 (long) read_register (FP0_REGNUM + 12),
2663 (long) read_register (FP0_REGNUM + 13),
2664 (long) read_register (FP0_REGNUM + 14),
2665 (long) read_register (FP0_REGNUM + 15));
2666}
2667
2668static void
fba45db2 2669sh3_dsp_show_regs (void)
c906108c 2670{
f81353e4
EZ
2671 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
2672
cc17453a
EZ
2673 printf_filtered ("PC=%s SR=%08lx PR=%08lx MACH=%08lx MACHL=%08lx\n",
2674 paddr (read_register (PC_REGNUM)),
f81353e4
EZ
2675 (long) read_register (tdep->SR_REGNUM),
2676 (long) read_register (tdep->PR_REGNUM),
cc17453a
EZ
2677 (long) read_register (MACH_REGNUM),
2678 (long) read_register (MACL_REGNUM));
c906108c 2679
cc17453a
EZ
2680 printf_filtered ("GBR=%08lx VBR=%08lx",
2681 (long) read_register (GBR_REGNUM),
2682 (long) read_register (VBR_REGNUM));
2683
2684 printf_filtered (" SSR=%08lx SPC=%08lx",
f81353e4
EZ
2685 (long) read_register (tdep->SSR_REGNUM),
2686 (long) read_register (tdep->SPC_REGNUM));
cc17453a
EZ
2687
2688 printf_filtered (" DSR=%08lx",
f81353e4 2689 (long) read_register (tdep->DSR_REGNUM));
cc17453a
EZ
2690
2691 printf_filtered ("\nR0-R7 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
2692 (long) read_register (0),
2693 (long) read_register (1),
2694 (long) read_register (2),
2695 (long) read_register (3),
2696 (long) read_register (4),
2697 (long) read_register (5),
2698 (long) read_register (6),
2699 (long) read_register (7));
2700 printf_filtered ("R8-R15 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
2701 (long) read_register (8),
2702 (long) read_register (9),
2703 (long) read_register (10),
2704 (long) read_register (11),
2705 (long) read_register (12),
2706 (long) read_register (13),
2707 (long) read_register (14),
2708 (long) read_register (15));
2709
2710 printf_filtered ("A0G=%02lx A0=%08lx M0=%08lx X0=%08lx Y0=%08lx RS=%08lx MOD=%08lx\n",
f81353e4
EZ
2711 (long) read_register (tdep->A0G_REGNUM) & 0xff,
2712 (long) read_register (tdep->A0_REGNUM),
2713 (long) read_register (tdep->M0_REGNUM),
2714 (long) read_register (tdep->X0_REGNUM),
2715 (long) read_register (tdep->Y0_REGNUM),
2716 (long) read_register (tdep->RS_REGNUM),
2717 (long) read_register (tdep->MOD_REGNUM));
cc17453a 2718 printf_filtered ("A1G=%02lx A1=%08lx M1=%08lx X1=%08lx Y1=%08lx RE=%08lx\n",
f81353e4
EZ
2719 (long) read_register (tdep->A1G_REGNUM) & 0xff,
2720 (long) read_register (tdep->A1_REGNUM),
2721 (long) read_register (tdep->M1_REGNUM),
2722 (long) read_register (tdep->X1_REGNUM),
2723 (long) read_register (tdep->Y1_REGNUM),
2724 (long) read_register (tdep->RE_REGNUM));
c906108c
SS
2725}
2726
cc17453a 2727static void
fba45db2 2728sh4_show_regs (void)
cc17453a 2729{
f81353e4
EZ
2730 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
2731
2732 int pr = read_register (tdep->FPSCR_REGNUM) & 0x80000;
cc17453a
EZ
2733 printf_filtered ("PC=%s SR=%08lx PR=%08lx MACH=%08lx MACHL=%08lx\n",
2734 paddr (read_register (PC_REGNUM)),
f81353e4
EZ
2735 (long) read_register (tdep->SR_REGNUM),
2736 (long) read_register (tdep->PR_REGNUM),
cc17453a
EZ
2737 (long) read_register (MACH_REGNUM),
2738 (long) read_register (MACL_REGNUM));
2739
2740 printf_filtered ("GBR=%08lx VBR=%08lx",
2741 (long) read_register (GBR_REGNUM),
2742 (long) read_register (VBR_REGNUM));
2743 printf_filtered (" SSR=%08lx SPC=%08lx",
f81353e4
EZ
2744 (long) read_register (tdep->SSR_REGNUM),
2745 (long) read_register (tdep->SPC_REGNUM));
cc17453a 2746 printf_filtered (" FPUL=%08lx FPSCR=%08lx",
f81353e4
EZ
2747 (long) read_register (tdep->FPUL_REGNUM),
2748 (long) read_register (tdep->FPSCR_REGNUM));
cc17453a
EZ
2749
2750 printf_filtered ("\nR0-R7 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
2751 (long) read_register (0),
2752 (long) read_register (1),
2753 (long) read_register (2),
2754 (long) read_register (3),
2755 (long) read_register (4),
2756 (long) read_register (5),
2757 (long) read_register (6),
2758 (long) read_register (7));
2759 printf_filtered ("R8-R15 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
2760 (long) read_register (8),
2761 (long) read_register (9),
2762 (long) read_register (10),
2763 (long) read_register (11),
2764 (long) read_register (12),
2765 (long) read_register (13),
2766 (long) read_register (14),
2767 (long) read_register (15));
2768
2769 printf_filtered ((pr
2770 ? "DR0-DR6 %08lx%08lx %08lx%08lx %08lx%08lx %08lx%08lx\n"
2771 : "FP0-FP7 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n"),
2772 (long) read_register (FP0_REGNUM + 0),
2773 (long) read_register (FP0_REGNUM + 1),
2774 (long) read_register (FP0_REGNUM + 2),
2775 (long) read_register (FP0_REGNUM + 3),
2776 (long) read_register (FP0_REGNUM + 4),
2777 (long) read_register (FP0_REGNUM + 5),
2778 (long) read_register (FP0_REGNUM + 6),
2779 (long) read_register (FP0_REGNUM + 7));
2780 printf_filtered ((pr
2781 ? "DR8-DR14 %08lx%08lx %08lx%08lx %08lx%08lx %08lx%08lx\n"
2782 : "FP8-FP15 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n"),
2783 (long) read_register (FP0_REGNUM + 8),
2784 (long) read_register (FP0_REGNUM + 9),
2785 (long) read_register (FP0_REGNUM + 10),
2786 (long) read_register (FP0_REGNUM + 11),
2787 (long) read_register (FP0_REGNUM + 12),
2788 (long) read_register (FP0_REGNUM + 13),
2789 (long) read_register (FP0_REGNUM + 14),
2790 (long) read_register (FP0_REGNUM + 15));
2791}
2792
2793static void
fba45db2 2794sh_dsp_show_regs (void)
cc17453a 2795{
f81353e4
EZ
2796 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
2797
cc17453a
EZ
2798 printf_filtered ("PC=%s SR=%08lx PR=%08lx MACH=%08lx MACHL=%08lx\n",
2799 paddr (read_register (PC_REGNUM)),
f81353e4
EZ
2800 (long) read_register (tdep->SR_REGNUM),
2801 (long) read_register (tdep->PR_REGNUM),
cc17453a
EZ
2802 (long) read_register (MACH_REGNUM),
2803 (long) read_register (MACL_REGNUM));
2804
2805 printf_filtered ("GBR=%08lx VBR=%08lx",
2806 (long) read_register (GBR_REGNUM),
2807 (long) read_register (VBR_REGNUM));
2808
2809 printf_filtered (" DSR=%08lx",
f81353e4 2810 (long) read_register (tdep->DSR_REGNUM));
cc17453a
EZ
2811
2812 printf_filtered ("\nR0-R7 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
2813 (long) read_register (0),
2814 (long) read_register (1),
2815 (long) read_register (2),
2816 (long) read_register (3),
2817 (long) read_register (4),
2818 (long) read_register (5),
2819 (long) read_register (6),
2820 (long) read_register (7));
2821 printf_filtered ("R8-R15 %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
2822 (long) read_register (8),
2823 (long) read_register (9),
2824 (long) read_register (10),
2825 (long) read_register (11),
2826 (long) read_register (12),
2827 (long) read_register (13),
2828 (long) read_register (14),
2829 (long) read_register (15));
2830
2831 printf_filtered ("A0G=%02lx A0=%08lx M0=%08lx X0=%08lx Y0=%08lx RS=%08lx MOD=%08lx\n",
f81353e4
EZ
2832 (long) read_register (tdep->A0G_REGNUM) & 0xff,
2833 (long) read_register (tdep->A0_REGNUM),
2834 (long) read_register (tdep->M0_REGNUM),
2835 (long) read_register (tdep->X0_REGNUM),
2836 (long) read_register (tdep->Y0_REGNUM),
2837 (long) read_register (tdep->RS_REGNUM),
2838 (long) read_register (tdep->MOD_REGNUM));
cc17453a 2839 printf_filtered ("A1G=%02lx A1=%08lx M1=%08lx X1=%08lx Y1=%08lx RE=%08lx\n",
f81353e4
EZ
2840 (long) read_register (tdep->A1G_REGNUM) & 0xff,
2841 (long) read_register (tdep->A1_REGNUM),
2842 (long) read_register (tdep->M1_REGNUM),
2843 (long) read_register (tdep->X1_REGNUM),
2844 (long) read_register (tdep->Y1_REGNUM),
2845 (long) read_register (tdep->RE_REGNUM));
cc17453a
EZ
2846}
2847
283150cd
EZ
2848static void
2849sh64_show_media_regs (void)
2850{
2851 int i;
2852 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
2853
2854 printf_filtered ("PC=%s SR=%016llx \n",
2855 paddr (read_register (PC_REGNUM)),
2856 (long long) read_register (tdep->SR_REGNUM));
2857
2858 printf_filtered ("SSR=%016llx SPC=%016llx \n",
2859 (long long) read_register (tdep->SSR_REGNUM),
2860 (long long) read_register (tdep->SPC_REGNUM));
2861 printf_filtered ("FPSCR=%016lx\n ",
2862 (long) read_register (tdep->FPSCR_REGNUM));
2863
2864 for (i = 0; i < 64; i = i + 4)
2865 printf_filtered ("\nR%d-R%d %016llx %016llx %016llx %016llx\n",
2866 i, i + 3,
2867 (long long) read_register (i + 0),
2868 (long long) read_register (i + 1),
2869 (long long) read_register (i + 2),
2870 (long long) read_register (i + 3));
2871
2872 printf_filtered ("\n");
2873
2874 for (i = 0; i < 64; i = i + 8)
2875 printf_filtered ("FR%d-FR%d %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
2876 i, i + 7,
2877 (long) read_register (FP0_REGNUM + i + 0),
2878 (long) read_register (FP0_REGNUM + i + 1),
2879 (long) read_register (FP0_REGNUM + i + 2),
2880 (long) read_register (FP0_REGNUM + i + 3),
2881 (long) read_register (FP0_REGNUM + i + 4),
2882 (long) read_register (FP0_REGNUM + i + 5),
2883 (long) read_register (FP0_REGNUM + i + 6),
2884 (long) read_register (FP0_REGNUM + i + 7));
2885}
2886
2887static void
2888sh64_show_compact_regs (void)
2889{
2890 int i;
2891 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
2892
2893 printf_filtered ("PC=%s \n",
2894 paddr (read_register (tdep->PC_C_REGNUM)));
2895
2896 printf_filtered ("GBR=%08lx MACH=%08lx MACL=%08lx PR=%08lx T=%08lx\n",
2897 (long) read_register (tdep->GBR_C_REGNUM),
2898 (long) read_register (tdep->MACH_C_REGNUM),
2899 (long) read_register (tdep->MACL_C_REGNUM),
2900 (long) read_register (tdep->PR_C_REGNUM),
2901 (long) read_register (tdep->T_C_REGNUM));
2902 printf_filtered ("FPSCR=%08lx FPUL=%08lx\n",
2903 (long) read_register (tdep->FPSCR_REGNUM),
2904 (long) read_register (tdep->FPUL_REGNUM));
2905
2906 for (i = 0; i < 16; i = i + 4)
2907 printf_filtered ("\nR%d-R%d %08lx %08lx %08lx %08lx\n",
2908 i, i + 3,
2909 (long) read_register (i + 0),
2910 (long) read_register (i + 1),
2911 (long) read_register (i + 2),
2912 (long) read_register (i + 3));
2913
2914 printf_filtered ("\n");
2915
2916 for (i = 0; i < 16; i = i + 8)
2917 printf_filtered ("FR%d-FR%d %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
2918 i, i + 7,
2919 (long) read_register (FP0_REGNUM + i + 0),
2920 (long) read_register (FP0_REGNUM + i + 1),
2921 (long) read_register (FP0_REGNUM + i + 2),
2922 (long) read_register (FP0_REGNUM + i + 3),
2923 (long) read_register (FP0_REGNUM + i + 4),
2924 (long) read_register (FP0_REGNUM + i + 5),
2925 (long) read_register (FP0_REGNUM + i + 6),
2926 (long) read_register (FP0_REGNUM + i + 7));
2927}
2928
2929/*FIXME!!! This only shows the registers for shmedia, excluding the
2930 pseudo registers. */
2931static void
2932sh64_show_regs (void)
2933{
50abf9e5 2934 if (pc_is_isa32 (get_frame_pc (deprecated_selected_frame)))
283150cd
EZ
2935 sh64_show_media_regs ();
2936 else
2937 sh64_show_compact_regs ();
2938}
2939
53116e27
EZ
2940void sh_show_regs_command (char *args, int from_tty)
2941{
2942 if (sh_show_regs)
2943 (*sh_show_regs)();
2944}
2945
cc17453a
EZ
2946/* Index within `registers' of the first byte of the space for
2947 register N. */
2948static int
fba45db2 2949sh_default_register_byte (int reg_nr)
8db62801 2950{
cc17453a
EZ
2951 return (reg_nr * 4);
2952}
2953
53116e27 2954static int
fba45db2 2955sh_sh4_register_byte (int reg_nr)
53116e27 2956{
f81353e4
EZ
2957 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
2958
2959 if (reg_nr >= tdep->DR0_REGNUM
2960 && reg_nr <= tdep->DR_LAST_REGNUM)
53116e27 2961 return (dr_reg_base_num (reg_nr) * 4);
f81353e4
EZ
2962 else if (reg_nr >= tdep->FV0_REGNUM
2963 && reg_nr <= tdep->FV_LAST_REGNUM)
53116e27
EZ
2964 return (fv_reg_base_num (reg_nr) * 4);
2965 else
2966 return (reg_nr * 4);
2967}
2968
283150cd
EZ
2969/* *INDENT-OFF* */
2970/*
2971 SH MEDIA MODE (ISA 32)
2972 general registers (64-bit) 0-63
29730 r0, r1, r2, r3, r4, r5, r6, r7,
297464 r8, r9, r10, r11, r12, r13, r14, r15,
2975128 r16, r17, r18, r19, r20, r21, r22, r23,
2976192 r24, r25, r26, r27, r28, r29, r30, r31,
2977256 r32, r33, r34, r35, r36, r37, r38, r39,
2978320 r40, r41, r42, r43, r44, r45, r46, r47,
2979384 r48, r49, r50, r51, r52, r53, r54, r55,
2980448 r56, r57, r58, r59, r60, r61, r62, r63,
2981
2982 pc (64-bit) 64
2983512 pc,
2984
2985 status reg., saved status reg., saved pc reg. (64-bit) 65-67
2986520 sr, ssr, spc,
2987
2988 target registers (64-bit) 68-75
2989544 tr0, tr1, tr2, tr3, tr4, tr5, tr6, tr7,
2990
2991 floating point state control register (32-bit) 76
2992608 fpscr,
2993
2994 single precision floating point registers (32-bit) 77-140
2995612 fr0, fr1, fr2, fr3, fr4, fr5, fr6, fr7,
2996644 fr8, fr9, fr10, fr11, fr12, fr13, fr14, fr15,
2997676 fr16, fr17, fr18, fr19, fr20, fr21, fr22, fr23,
2998708 fr24, fr25, fr26, fr27, fr28, fr29, fr30, fr31,
2999740 fr32, fr33, fr34, fr35, fr36, fr37, fr38, fr39,
3000772 fr40, fr41, fr42, fr43, fr44, fr45, fr46, fr47,
3001804 fr48, fr49, fr50, fr51, fr52, fr53, fr54, fr55,
3002836 fr56, fr57, fr58, fr59, fr60, fr61, fr62, fr63,
3003
3004TOTAL SPACE FOR REGISTERS: 868 bytes
3005
3006From here on they are all pseudo registers: no memory allocated.
3007REGISTER_BYTE returns the register byte for the base register.
3008
3009 double precision registers (pseudo) 141-172
3010 dr0, dr2, dr4, dr6, dr8, dr10, dr12, dr14,
3011 dr16, dr18, dr20, dr22, dr24, dr26, dr28, dr30,
3012 dr32, dr34, dr36, dr38, dr40, dr42, dr44, dr46,
3013 dr48, dr50, dr52, dr54, dr56, dr58, dr60, dr62,
3014
3015 floating point pairs (pseudo) 173-204
3016 fp0, fp2, fp4, fp6, fp8, fp10, fp12, fp14,
3017 fp16, fp18, fp20, fp22, fp24, fp26, fp28, fp30,
3018 fp32, fp34, fp36, fp38, fp40, fp42, fp44, fp46,
3019 fp48, fp50, fp52, fp54, fp56, fp58, fp60, fp62,
3020
3021 floating point vectors (4 floating point regs) (pseudo) 205-220
3022 fv0, fv4, fv8, fv12, fv16, fv20, fv24, fv28,
3023 fv32, fv36, fv40, fv44, fv48, fv52, fv56, fv60,
3024
3025 SH COMPACT MODE (ISA 16) (all pseudo) 221-272
3026 r0_c, r1_c, r2_c, r3_c, r4_c, r5_c, r6_c, r7_c,
3027 r8_c, r9_c, r10_c, r11_c, r12_c, r13_c, r14_c, r15_c,
3028 pc_c,
3029 gbr_c, mach_c, macl_c, pr_c, t_c,
3030 fpscr_c, fpul_c,
3031 fr0_c, fr1_c, fr2_c, fr3_c, fr4_c, fr5_c, fr6_c, fr7_c,
3032 fr8_c, fr9_c, fr10_c, fr11_c, fr12_c, fr13_c, fr14_c, fr15_c
3033 dr0_c, dr2_c, dr4_c, dr6_c, dr8_c, dr10_c, dr12_c, dr14_c
3034 fv0_c, fv4_c, fv8_c, fv12_c
3035*/
3036/* *INDENT-ON* */
3037static int
3038sh_sh64_register_byte (int reg_nr)
3039{
3040 int base_regnum = -1;
3041 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
3042
3043 /* If it is a pseudo register, get the number of the first floating
3044 point register that is part of it. */
3045 if (reg_nr >= tdep->DR0_REGNUM
3046 && reg_nr <= tdep->DR_LAST_REGNUM)
3047 base_regnum = dr_reg_base_num (reg_nr);
3048
3049 else if (reg_nr >= tdep->FPP0_REGNUM
3050 && reg_nr <= tdep->FPP_LAST_REGNUM)
3051 base_regnum = fpp_reg_base_num (reg_nr);
3052
3053 else if (reg_nr >= tdep->FV0_REGNUM
3054 && reg_nr <= tdep->FV_LAST_REGNUM)
3055 base_regnum = fv_reg_base_num (reg_nr);
3056
3057 /* sh compact pseudo register. FPSCR is a pathological case, need to
3058 treat it as special. */
3059 else if ((reg_nr >= tdep->R0_C_REGNUM
3060 && reg_nr <= tdep->FV_LAST_C_REGNUM)
3061 && reg_nr != tdep->FPSCR_C_REGNUM)
3062 base_regnum = sh64_compact_reg_base_num (reg_nr);
3063
3064 /* Now return the offset in bytes within the register cache. */
3065 /* sh media pseudo register, i.e. any of DR, FFP, FV registers. */
3066 if (reg_nr >= tdep->DR0_REGNUM
3067 && reg_nr <= tdep->FV_LAST_REGNUM)
3068 return (base_regnum - FP0_REGNUM + 1) * 4
3069 + (tdep->TR7_REGNUM + 1) * 8;
3070
3071 /* sh compact pseudo register: general register */
3072 if ((reg_nr >= tdep->R0_C_REGNUM
3073 && reg_nr <= tdep->R_LAST_C_REGNUM))
3074 return (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
3075 ? base_regnum * 8 + 4
3076 : base_regnum * 8);
3077
3078 /* sh compact pseudo register: */
3079 if (reg_nr == tdep->PC_C_REGNUM
3080 || reg_nr == tdep->GBR_C_REGNUM
3081 || reg_nr == tdep->MACL_C_REGNUM
3082 || reg_nr == tdep->PR_C_REGNUM)
3083 return (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
3084 ? base_regnum * 8 + 4
3085 : base_regnum * 8);
3086
3087 if (reg_nr == tdep->MACH_C_REGNUM)
3088 return base_regnum * 8;
3089
3090 if (reg_nr == tdep->T_C_REGNUM)
3091 return base_regnum * 8; /* FIXME??? how do we get bit 0? Do we have to? */
3092
3093 /* sh compact pseudo register: floating point register */
3094 else if (reg_nr >=tdep->FP0_C_REGNUM
3095 && reg_nr <= tdep->FV_LAST_C_REGNUM)
3096 return (base_regnum - FP0_REGNUM) * 4
3097 + (tdep->TR7_REGNUM + 1) * 8 + 4;
3098
3099 else if (reg_nr == tdep->FPSCR_C_REGNUM)
3100 /* This is complicated, for now return the beginning of the
3101 architectural FPSCR register. */
3102 return (tdep->TR7_REGNUM + 1) * 8;
3103
3104 else if (reg_nr == tdep->FPUL_C_REGNUM)
3105 return ((base_regnum - FP0_REGNUM) * 4 +
3106 (tdep->TR7_REGNUM + 1) * 8 + 4);
3107
3108 /* It is not a pseudo register. */
3109 /* It is a 64 bit register. */
3110 else if (reg_nr <= tdep->TR7_REGNUM)
3111 return reg_nr * 8;
3112
3113 /* It is a 32 bit register. */
3114 else
3115 if (reg_nr == tdep->FPSCR_REGNUM)
3116 return (tdep->FPSCR_REGNUM * 8);
3117
3118 /* It is floating point 32-bit register */
3119 else
3120 return ((tdep->TR7_REGNUM + 1) * 8
3121 + (reg_nr - FP0_REGNUM + 1) * 4);
3122}
3123
cc17453a
EZ
3124/* Number of bytes of storage in the actual machine representation for
3125 register REG_NR. */
3126static int
fba45db2 3127sh_default_register_raw_size (int reg_nr)
cc17453a
EZ
3128{
3129 return 4;
3130}
3131
53116e27 3132static int
fba45db2 3133sh_sh4_register_raw_size (int reg_nr)
53116e27 3134{
f81353e4
EZ
3135 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
3136
3137 if (reg_nr >= tdep->DR0_REGNUM
3138 && reg_nr <= tdep->DR_LAST_REGNUM)
53116e27 3139 return 8;
f81353e4
EZ
3140 else if (reg_nr >= tdep->FV0_REGNUM
3141 && reg_nr <= tdep->FV_LAST_REGNUM)
53116e27
EZ
3142 return 16;
3143 else
3144 return 4;
3145}
3146
283150cd
EZ
3147static int
3148sh_sh64_register_raw_size (int reg_nr)
3149{
3150 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
3151
3152 if ((reg_nr >= tdep->DR0_REGNUM
3153 && reg_nr <= tdep->DR_LAST_REGNUM)
3154 || (reg_nr >= tdep->FPP0_REGNUM
3155 && reg_nr <= tdep->FPP_LAST_REGNUM)
3156 || (reg_nr >= tdep->DR0_C_REGNUM
3157 && reg_nr <= tdep->DR_LAST_C_REGNUM)
3158 || (reg_nr <= tdep->TR7_REGNUM))
3159 return 8;
3160
3161 else if ((reg_nr >= tdep->FV0_REGNUM
3162 && reg_nr <= tdep->FV_LAST_REGNUM)
3163 || (reg_nr >= tdep->FV0_C_REGNUM
3164 && reg_nr <= tdep->FV_LAST_C_REGNUM))
3165 return 16;
3166
3167 else /* this covers also the 32-bit SH compact registers. */
3168 return 4;
3169}
3170
cc17453a
EZ
3171/* Number of bytes of storage in the program's representation
3172 for register N. */
3173static int
fba45db2 3174sh_register_virtual_size (int reg_nr)
cc17453a
EZ
3175{
3176 return 4;
3177}
3178
283150cd
EZ
3179/* ??????? FIXME */
3180static int
3181sh_sh64_register_virtual_size (int reg_nr)
3182{
3183 if (reg_nr >= FP0_REGNUM
3184 && reg_nr <= gdbarch_tdep (current_gdbarch)->FP_LAST_REGNUM)
3185 return 4;
3186 else
3187 return 8;
3188}
3189
cc17453a
EZ
3190/* Return the GDB type object for the "standard" data type
3191 of data in register N. */
cc17453a 3192static struct type *
fba45db2 3193sh_sh3e_register_virtual_type (int reg_nr)
cc17453a 3194{
f81353e4
EZ
3195 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
3196
cc17453a 3197 if ((reg_nr >= FP0_REGNUM
f81353e4
EZ
3198 && (reg_nr <= tdep->FP_LAST_REGNUM))
3199 || (reg_nr == tdep->FPUL_REGNUM))
cc17453a 3200 return builtin_type_float;
8db62801 3201 else
cc17453a
EZ
3202 return builtin_type_int;
3203}
3204
7f4dbe94
EZ
3205static struct type *
3206sh_sh4_build_float_register_type (int high)
3207{
3208 struct type *temp;
3209
3210 temp = create_range_type (NULL, builtin_type_int, 0, high);
3211 return create_array_type (NULL, builtin_type_float, temp);
3212}
3213
53116e27 3214static struct type *
fba45db2 3215sh_sh4_register_virtual_type (int reg_nr)
53116e27 3216{
f81353e4
EZ
3217 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
3218
53116e27 3219 if ((reg_nr >= FP0_REGNUM
f81353e4
EZ
3220 && (reg_nr <= tdep->FP_LAST_REGNUM))
3221 || (reg_nr == tdep->FPUL_REGNUM))
53116e27 3222 return builtin_type_float;
f81353e4
EZ
3223 else if (reg_nr >= tdep->DR0_REGNUM
3224 && reg_nr <= tdep->DR_LAST_REGNUM)
53116e27 3225 return builtin_type_double;
f81353e4
EZ
3226 else if (reg_nr >= tdep->FV0_REGNUM
3227 && reg_nr <= tdep->FV_LAST_REGNUM)
53116e27
EZ
3228 return sh_sh4_build_float_register_type (3);
3229 else
3230 return builtin_type_int;
3231}
3232
283150cd
EZ
3233static struct type *
3234sh_sh64_register_virtual_type (int reg_nr)
3235{
3236 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
3237
3238 if ((reg_nr >= FP0_REGNUM
3239 && reg_nr <= tdep->FP_LAST_REGNUM)
3240 || (reg_nr >= tdep->FP0_C_REGNUM
3241 && reg_nr <= tdep->FP_LAST_C_REGNUM))
3242 return builtin_type_float;
3243 else if ((reg_nr >= tdep->DR0_REGNUM
3244 && reg_nr <= tdep->DR_LAST_REGNUM)
3245 || (reg_nr >= tdep->DR0_C_REGNUM
3246 && reg_nr <= tdep->DR_LAST_C_REGNUM))
3247 return builtin_type_double;
3248 else if (reg_nr >= tdep->FPP0_REGNUM
3249 && reg_nr <= tdep->FPP_LAST_REGNUM)
3250 return sh_sh4_build_float_register_type (1);
3251 else if ((reg_nr >= tdep->FV0_REGNUM
3252 && reg_nr <= tdep->FV_LAST_REGNUM)
3253 ||(reg_nr >= tdep->FV0_C_REGNUM
3254 && reg_nr <= tdep->FV_LAST_C_REGNUM))
3255 return sh_sh4_build_float_register_type (3);
3256 else if (reg_nr == tdep->FPSCR_REGNUM)
3257 return builtin_type_int;
3258 else if (reg_nr >= tdep->R0_C_REGNUM
3259 && reg_nr < tdep->FP0_C_REGNUM)
3260 return builtin_type_int;
3261 else
3262 return builtin_type_long_long;
3263}
3264
cc17453a 3265static struct type *
fba45db2 3266sh_default_register_virtual_type (int reg_nr)
cc17453a
EZ
3267{
3268 return builtin_type_int;
3269}
3270
fb409745
EZ
3271/* On the sh4, the DRi pseudo registers are problematic if the target
3272 is little endian. When the user writes one of those registers, for
3273 instance with 'ser var $dr0=1', we want the double to be stored
3274 like this:
3275 fr0 = 0x00 0x00 0x00 0x00 0x00 0xf0 0x3f
3276 fr1 = 0x00 0x00 0x00 0x00 0x00 0x00 0x00
3277
3278 This corresponds to little endian byte order & big endian word
3279 order. However if we let gdb write the register w/o conversion, it
3280 will write fr0 and fr1 this way:
3281 fr0 = 0x00 0x00 0x00 0x00 0x00 0x00 0x00
3282 fr1 = 0x00 0x00 0x00 0x00 0x00 0xf0 0x3f
3283 because it will consider fr0 and fr1 as a single LE stretch of memory.
3284
3285 To achieve what we want we must force gdb to store things in
3286 floatformat_ieee_double_littlebyte_bigword (which is defined in
3287 include/floatformat.h and libiberty/floatformat.c.
3288
3289 In case the target is big endian, there is no problem, the
3290 raw bytes will look like:
3291 fr0 = 0x3f 0xf0 0x00 0x00 0x00 0x00 0x00
3292 fr1 = 0x00 0x00 0x00 0x00 0x00 0x00 0x00
3293
3294 The other pseudo registers (the FVs) also don't pose a problem
3295 because they are stored as 4 individual FP elements. */
3296
7bd872fe 3297static void
fb409745
EZ
3298sh_sh4_register_convert_to_virtual (int regnum, struct type *type,
3299 char *from, char *to)
3300{
f81353e4
EZ
3301 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
3302
3303 if (regnum >= tdep->DR0_REGNUM
3304 && regnum <= tdep->DR_LAST_REGNUM)
fb409745
EZ
3305 {
3306 DOUBLEST val;
3307 floatformat_to_doublest (&floatformat_ieee_double_littlebyte_bigword, from, &val);
3bbfbb92 3308 store_floating (to, TYPE_LENGTH (type), val);
fb409745
EZ
3309 }
3310 else
3bbfbb92 3311 error ("sh_register_convert_to_virtual called with non DR register number");
fb409745
EZ
3312}
3313
283150cd
EZ
3314void
3315sh_sh64_register_convert_to_virtual (int regnum, struct type *type,
3316 char *from, char *to)
3317{
3318 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
3319
3320 if (TARGET_BYTE_ORDER != BFD_ENDIAN_LITTLE)
3321 {
3322 /* It is a no-op. */
3323 memcpy (to, from, REGISTER_RAW_SIZE (regnum));
3324 return;
3325 }
3326
3327 if ((regnum >= tdep->DR0_REGNUM
3328 && regnum <= tdep->DR_LAST_REGNUM)
3329 || (regnum >= tdep->DR0_C_REGNUM
3330 && regnum <= tdep->DR_LAST_C_REGNUM))
3331 {
3332 DOUBLEST val;
3333 floatformat_to_doublest (&floatformat_ieee_double_littlebyte_bigword, from, &val);
3334 store_floating(to, TYPE_LENGTH(type), val);
3335 }
3336 else
3337 error("sh_register_convert_to_virtual called with non DR register number");
3338}
3339
3340static void
3341sh_sh4_register_convert_to_raw (struct type *type, int regnum,
d8124050 3342 const void *from, void *to)
283150cd
EZ
3343{
3344 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
3345
3346 if (regnum >= tdep->DR0_REGNUM
3347 && regnum <= tdep->DR_LAST_REGNUM)
3348 {
3349 DOUBLEST val = extract_floating (from, TYPE_LENGTH(type));
3350 floatformat_from_doublest (&floatformat_ieee_double_littlebyte_bigword, &val, to);
3351 }
3352 else
3353 error("sh_register_convert_to_raw called with non DR register number");
3354}
3355
3356void
3357sh_sh64_register_convert_to_raw (struct type *type, int regnum,
d8124050 3358 const void *from, void *to)
fb409745 3359{
f81353e4
EZ
3360 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
3361
283150cd
EZ
3362 if (TARGET_BYTE_ORDER != BFD_ENDIAN_LITTLE)
3363 {
3364 /* It is a no-op. */
3365 memcpy (to, from, REGISTER_RAW_SIZE (regnum));
3366 return;
3367 }
3368
3369 if ((regnum >= tdep->DR0_REGNUM
3370 && regnum <= tdep->DR_LAST_REGNUM)
3371 || (regnum >= tdep->DR0_C_REGNUM
3372 && regnum <= tdep->DR_LAST_C_REGNUM))
fb409745
EZ
3373 {
3374 DOUBLEST val = extract_floating (from, TYPE_LENGTH(type));
3375 floatformat_from_doublest (&floatformat_ieee_double_littlebyte_bigword, &val, to);
3376 }
3377 else
3378 error("sh_register_convert_to_raw called with non DR register number");
3379}
3380
53116e27 3381void
d8124050
AC
3382sh_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache,
3383 int reg_nr, void *buffer)
53116e27
EZ
3384{
3385 int base_regnum, portion;
7bd872fe 3386 char *temp_buffer = (char*) alloca (MAX_REGISTER_RAW_SIZE);
d8124050 3387 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
53116e27 3388
7bd872fe
EZ
3389 if (reg_nr >= tdep->DR0_REGNUM
3390 && reg_nr <= tdep->DR_LAST_REGNUM)
3391 {
3392 base_regnum = dr_reg_base_num (reg_nr);
3393
3394 /* Build the value in the provided buffer. */
3395 /* Read the real regs for which this one is an alias. */
3396 for (portion = 0; portion < 2; portion++)
d8124050 3397 regcache_raw_read (regcache, base_regnum + portion,
0818c12a
AC
3398 (temp_buffer
3399 + REGISTER_RAW_SIZE (base_regnum) * portion));
7bd872fe
EZ
3400 /* We must pay attention to the endiannes. */
3401 sh_sh4_register_convert_to_virtual (reg_nr,
3402 REGISTER_VIRTUAL_TYPE (reg_nr),
3403 temp_buffer, buffer);
3404 }
3405 else if (reg_nr >= tdep->FV0_REGNUM
3406 && reg_nr <= tdep->FV_LAST_REGNUM)
53116e27 3407 {
7bd872fe
EZ
3408 base_regnum = fv_reg_base_num (reg_nr);
3409
3410 /* Read the real regs for which this one is an alias. */
3411 for (portion = 0; portion < 4; portion++)
d8124050
AC
3412 regcache_raw_read (regcache, base_regnum + portion,
3413 ((char *) buffer
3414 + REGISTER_RAW_SIZE (base_regnum) * portion));
53116e27
EZ
3415 }
3416}
3417
7bd872fe 3418static void
d8124050
AC
3419sh64_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache,
3420 int reg_nr, void *buffer)
283150cd
EZ
3421{
3422 int base_regnum;
3423 int portion;
3424 int offset = 0;
3425 char *temp_buffer = (char*) alloca (MAX_REGISTER_RAW_SIZE);
d8124050 3426 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
283150cd
EZ
3427
3428 if (reg_nr >= tdep->DR0_REGNUM
3429 && reg_nr <= tdep->DR_LAST_REGNUM)
3430 {
3431 base_regnum = dr_reg_base_num (reg_nr);
3432
3433 /* Build the value in the provided buffer. */
3434 /* DR regs are double precision registers obtained by
3435 concatenating 2 single precision floating point registers. */
3436 for (portion = 0; portion < 2; portion++)
d8124050 3437 regcache_raw_read (regcache, base_regnum + portion,
0818c12a
AC
3438 (temp_buffer
3439 + REGISTER_RAW_SIZE (base_regnum) * portion));
283150cd
EZ
3440
3441 /* We must pay attention to the endiannes. */
3442 sh_sh64_register_convert_to_virtual (reg_nr, REGISTER_VIRTUAL_TYPE (reg_nr),
3443 temp_buffer, buffer);
3444
3445 }
3446
3447 else if (reg_nr >= tdep->FPP0_REGNUM
3448 && reg_nr <= tdep->FPP_LAST_REGNUM)
3449 {
3450 base_regnum = fpp_reg_base_num (reg_nr);
3451
3452 /* Build the value in the provided buffer. */
3453 /* FPP regs are pairs of single precision registers obtained by
3454 concatenating 2 single precision floating point registers. */
3455 for (portion = 0; portion < 2; portion++)
d8124050
AC
3456 regcache_raw_read (regcache, base_regnum + portion,
3457 ((char *) buffer
0818c12a 3458 + REGISTER_RAW_SIZE (base_regnum) * portion));
283150cd
EZ
3459 }
3460
3461 else if (reg_nr >= tdep->FV0_REGNUM
3462 && reg_nr <= tdep->FV_LAST_REGNUM)
3463 {
3464 base_regnum = fv_reg_base_num (reg_nr);
3465
3466 /* Build the value in the provided buffer. */
3467 /* FV regs are vectors of single precision registers obtained by
3468 concatenating 4 single precision floating point registers. */
3469 for (portion = 0; portion < 4; portion++)
d8124050
AC
3470 regcache_raw_read (regcache, base_regnum + portion,
3471 ((char *) buffer
0818c12a 3472 + REGISTER_RAW_SIZE (base_regnum) * portion));
283150cd
EZ
3473 }
3474
3475 /* sh compact pseudo registers. 1-to-1 with a shmedia register */
3476 else if (reg_nr >= tdep->R0_C_REGNUM
3477 && reg_nr <= tdep->T_C_REGNUM)
3478 {
3479 base_regnum = sh64_compact_reg_base_num (reg_nr);
3480
3481 /* Build the value in the provided buffer. */
d8124050 3482 regcache_raw_read (regcache, base_regnum, temp_buffer);
283150cd
EZ
3483 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3484 offset = 4;
3485 memcpy (buffer, temp_buffer + offset, 4); /* get LOWER 32 bits only????*/
3486 }
3487
3488 else if (reg_nr >= tdep->FP0_C_REGNUM
3489 && reg_nr <= tdep->FP_LAST_C_REGNUM)
3490 {
3491 base_regnum = sh64_compact_reg_base_num (reg_nr);
3492
3493 /* Build the value in the provided buffer. */
3494 /* Floating point registers map 1-1 to the media fp regs,
3495 they have the same size and endienness. */
d8124050 3496 regcache_raw_read (regcache, base_regnum, buffer);
283150cd
EZ
3497 }
3498
3499 else if (reg_nr >= tdep->DR0_C_REGNUM
3500 && reg_nr <= tdep->DR_LAST_C_REGNUM)
3501 {
3502 base_regnum = sh64_compact_reg_base_num (reg_nr);
3503
3504 /* DR_C regs are double precision registers obtained by
3505 concatenating 2 single precision floating point registers. */
3506 for (portion = 0; portion < 2; portion++)
d8124050 3507 regcache_raw_read (regcache, base_regnum + portion,
0818c12a
AC
3508 (temp_buffer
3509 + REGISTER_RAW_SIZE (base_regnum) * portion));
283150cd
EZ
3510
3511 /* We must pay attention to the endiannes. */
3512 sh_sh64_register_convert_to_virtual (reg_nr, REGISTER_VIRTUAL_TYPE (reg_nr),
3513 temp_buffer, buffer);
3514 }
3515
3516 else if (reg_nr >= tdep->FV0_C_REGNUM
3517 && reg_nr <= tdep->FV_LAST_C_REGNUM)
3518 {
3519 base_regnum = sh64_compact_reg_base_num (reg_nr);
3520
3521 /* Build the value in the provided buffer. */
3522 /* FV_C regs are vectors of single precision registers obtained by
3523 concatenating 4 single precision floating point registers. */
3524 for (portion = 0; portion < 4; portion++)
d8124050
AC
3525 regcache_raw_read (regcache, base_regnum + portion,
3526 ((char *) buffer
0818c12a 3527 + REGISTER_RAW_SIZE (base_regnum) * portion));
283150cd
EZ
3528 }
3529
3530 else if (reg_nr == tdep->FPSCR_C_REGNUM)
3531 {
3532 int fpscr_base_regnum;
3533 int sr_base_regnum;
3534 unsigned int fpscr_value;
3535 unsigned int sr_value;
3536 unsigned int fpscr_c_value;
3537 unsigned int fpscr_c_part1_value;
3538 unsigned int fpscr_c_part2_value;
3539
3540 fpscr_base_regnum = tdep->FPSCR_REGNUM;
3541 sr_base_regnum = tdep->SR_REGNUM;
3542
3543 /* Build the value in the provided buffer. */
3544 /* FPSCR_C is a very weird register that contains sparse bits
3545 from the FPSCR and the SR architectural registers.
3546 Specifically: */
3547 /* *INDENT-OFF* */
3548 /*
3549 FPSRC_C bit
3550 0 Bit 0 of FPSCR
3551 1 reserved
3552 2-17 Bit 2-18 of FPSCR
3553 18-20 Bits 12,13,14 of SR
3554 21-31 reserved
3555 */
3556 /* *INDENT-ON* */
3557 /* Get FPSCR into a local buffer */
d8124050 3558 regcache_raw_read (regcache, fpscr_base_regnum, temp_buffer);
283150cd
EZ
3559 /* Get value as an int. */
3560 fpscr_value = extract_unsigned_integer (temp_buffer, 4);
3561 /* Get SR into a local buffer */
d8124050 3562 regcache_raw_read (regcache, sr_base_regnum, temp_buffer);
283150cd
EZ
3563 /* Get value as an int. */
3564 sr_value = extract_unsigned_integer (temp_buffer, 4);
3565 /* Build the new value. */
3566 fpscr_c_part1_value = fpscr_value & 0x3fffd;
3567 fpscr_c_part2_value = (sr_value & 0x7000) << 6;
3568 fpscr_c_value = fpscr_c_part1_value | fpscr_c_part2_value;
3569 /* Store that in out buffer!!! */
3570 store_unsigned_integer (buffer, 4, fpscr_c_value);
3571 /* FIXME There is surely an endianness gotcha here. */
3572 }
3573
3574 else if (reg_nr == tdep->FPUL_C_REGNUM)
3575 {
3576 base_regnum = sh64_compact_reg_base_num (reg_nr);
3577
3578 /* FPUL_C register is floating point register 32,
3579 same size, same endianness. */
d8124050 3580 regcache_raw_read (regcache, base_regnum, buffer);
283150cd
EZ
3581 }
3582}
3583
53116e27 3584void
d8124050
AC
3585sh_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
3586 int reg_nr, const void *buffer)
53116e27
EZ
3587{
3588 int base_regnum, portion;
7bd872fe 3589 char *temp_buffer = (char*) alloca (MAX_REGISTER_RAW_SIZE);
d8124050 3590 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
53116e27 3591
f81353e4
EZ
3592 if (reg_nr >= tdep->DR0_REGNUM
3593 && reg_nr <= tdep->DR_LAST_REGNUM)
53116e27
EZ
3594 {
3595 base_regnum = dr_reg_base_num (reg_nr);
3596
7bd872fe
EZ
3597 /* We must pay attention to the endiannes. */
3598 sh_sh4_register_convert_to_raw (REGISTER_VIRTUAL_TYPE (reg_nr), reg_nr,
3599 buffer, temp_buffer);
3600
53116e27
EZ
3601 /* Write the real regs for which this one is an alias. */
3602 for (portion = 0; portion < 2; portion++)
d8124050 3603 regcache_raw_write (regcache, base_regnum + portion,
0818c12a
AC
3604 (temp_buffer
3605 + REGISTER_RAW_SIZE (base_regnum) * portion));
53116e27 3606 }
f81353e4
EZ
3607 else if (reg_nr >= tdep->FV0_REGNUM
3608 && reg_nr <= tdep->FV_LAST_REGNUM)
53116e27
EZ
3609 {
3610 base_regnum = fv_reg_base_num (reg_nr);
3611
3612 /* Write the real regs for which this one is an alias. */
3613 for (portion = 0; portion < 4; portion++)
d8124050
AC
3614 regcache_raw_write (regcache, base_regnum + portion,
3615 ((char *) buffer
0818c12a 3616 + REGISTER_RAW_SIZE (base_regnum) * portion));
53116e27
EZ
3617 }
3618}
3619
283150cd 3620void
d8124050
AC
3621sh64_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
3622 int reg_nr, const void *buffer)
283150cd
EZ
3623{
3624 int base_regnum, portion;
3625 int offset;
3626 char *temp_buffer = (char*) alloca (MAX_REGISTER_RAW_SIZE);
d8124050 3627 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
283150cd
EZ
3628
3629 if (reg_nr >= tdep->DR0_REGNUM
3630 && reg_nr <= tdep->DR_LAST_REGNUM)
3631 {
3632 base_regnum = dr_reg_base_num (reg_nr);
3633 /* We must pay attention to the endiannes. */
3634 sh_sh64_register_convert_to_raw (REGISTER_VIRTUAL_TYPE (reg_nr), reg_nr,
3635 buffer, temp_buffer);
3636
3637
3638 /* Write the real regs for which this one is an alias. */
3639 for (portion = 0; portion < 2; portion++)
d8124050 3640 regcache_raw_write (regcache, base_regnum + portion,
0818c12a
AC
3641 (temp_buffer
3642 + REGISTER_RAW_SIZE (base_regnum) * portion));
283150cd
EZ
3643 }
3644
3645 else if (reg_nr >= tdep->FPP0_REGNUM
3646 && reg_nr <= tdep->FPP_LAST_REGNUM)
3647 {
3648 base_regnum = fpp_reg_base_num (reg_nr);
3649
3650 /* Write the real regs for which this one is an alias. */
3651 for (portion = 0; portion < 2; portion++)
d8124050
AC
3652 regcache_raw_write (regcache, base_regnum + portion,
3653 ((char *) buffer
0818c12a 3654 + REGISTER_RAW_SIZE (base_regnum) * portion));
283150cd
EZ
3655 }
3656
3657 else if (reg_nr >= tdep->FV0_REGNUM
3658 && reg_nr <= tdep->FV_LAST_REGNUM)
3659 {
3660 base_regnum = fv_reg_base_num (reg_nr);
3661
3662 /* Write the real regs for which this one is an alias. */
3663 for (portion = 0; portion < 4; portion++)
d8124050
AC
3664 regcache_raw_write (regcache, base_regnum + portion,
3665 ((char *) buffer
0818c12a 3666 + REGISTER_RAW_SIZE (base_regnum) * portion));
283150cd
EZ
3667 }
3668
3669 /* sh compact general pseudo registers. 1-to-1 with a shmedia
3670 register but only 4 bytes of it. */
3671 else if (reg_nr >= tdep->R0_C_REGNUM
3672 && reg_nr <= tdep->T_C_REGNUM)
3673 {
3674 base_regnum = sh64_compact_reg_base_num (reg_nr);
3675 /* reg_nr is 32 bit here, and base_regnum is 64 bits. */
3676 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
3677 offset = 4;
3678 else
3679 offset = 0;
3680 /* Let's read the value of the base register into a temporary
3681 buffer, so that overwriting the last four bytes with the new
3682 value of the pseudo will leave the upper 4 bytes unchanged. */
d8124050 3683 regcache_raw_read (regcache, base_regnum, temp_buffer);
283150cd
EZ
3684 /* Write as an 8 byte quantity */
3685 memcpy (temp_buffer + offset, buffer, 4);
d8124050 3686 regcache_raw_write (regcache, base_regnum, temp_buffer);
283150cd
EZ
3687 }
3688
3689 /* sh floating point compact pseudo registers. 1-to-1 with a shmedia
3690 registers. Both are 4 bytes. */
3691 else if (reg_nr >= tdep->FP0_C_REGNUM
3692 && reg_nr <= tdep->FP_LAST_C_REGNUM)
3693 {
3694 base_regnum = sh64_compact_reg_base_num (reg_nr);
d8124050 3695 regcache_raw_write (regcache, base_regnum, buffer);
283150cd
EZ
3696 }
3697
3698 else if (reg_nr >= tdep->DR0_C_REGNUM
3699 && reg_nr <= tdep->DR_LAST_C_REGNUM)
3700 {
3701 base_regnum = sh64_compact_reg_base_num (reg_nr);
3702 for (portion = 0; portion < 2; portion++)
3703 {
3704 /* We must pay attention to the endiannes. */
3705 sh_sh64_register_convert_to_raw (REGISTER_VIRTUAL_TYPE (reg_nr), reg_nr,
3706 buffer, temp_buffer);
3707
d8124050 3708 regcache_raw_write (regcache, base_regnum + portion,
0818c12a
AC
3709 (temp_buffer
3710 + REGISTER_RAW_SIZE (base_regnum) * portion));
283150cd
EZ
3711 }
3712 }
3713
3714 else if (reg_nr >= tdep->FV0_C_REGNUM
3715 && reg_nr <= tdep->FV_LAST_C_REGNUM)
3716 {
3717 base_regnum = sh64_compact_reg_base_num (reg_nr);
3718
3719 for (portion = 0; portion < 4; portion++)
3720 {
d8124050
AC
3721 regcache_raw_write (regcache, base_regnum + portion,
3722 ((char *) buffer
0818c12a 3723 + REGISTER_RAW_SIZE (base_regnum) * portion));
283150cd
EZ
3724 }
3725 }
3726
3727 else if (reg_nr == tdep->FPSCR_C_REGNUM)
3728 {
3729 int fpscr_base_regnum;
3730 int sr_base_regnum;
3731 unsigned int fpscr_value;
3732 unsigned int sr_value;
3733 unsigned int old_fpscr_value;
3734 unsigned int old_sr_value;
3735 unsigned int fpscr_c_value;
3736 unsigned int fpscr_mask;
3737 unsigned int sr_mask;
3738
3739 fpscr_base_regnum = tdep->FPSCR_REGNUM;
3740 sr_base_regnum = tdep->SR_REGNUM;
3741
3742 /* FPSCR_C is a very weird register that contains sparse bits
3743 from the FPSCR and the SR architectural registers.
3744 Specifically: */
3745 /* *INDENT-OFF* */
3746 /*
3747 FPSRC_C bit
3748 0 Bit 0 of FPSCR
3749 1 reserved
3750 2-17 Bit 2-18 of FPSCR
3751 18-20 Bits 12,13,14 of SR
3752 21-31 reserved
3753 */
3754 /* *INDENT-ON* */
3755 /* Get value as an int. */
3756 fpscr_c_value = extract_unsigned_integer (buffer, 4);
3757
3758 /* Build the new values. */
3759 fpscr_mask = 0x0003fffd;
3760 sr_mask = 0x001c0000;
3761
3762 fpscr_value = fpscr_c_value & fpscr_mask;
3763 sr_value = (fpscr_value & sr_mask) >> 6;
3764
d8124050 3765 regcache_raw_read (regcache, fpscr_base_regnum, temp_buffer);
283150cd
EZ
3766 old_fpscr_value = extract_unsigned_integer (temp_buffer, 4);
3767 old_fpscr_value &= 0xfffc0002;
3768 fpscr_value |= old_fpscr_value;
3769 store_unsigned_integer (temp_buffer, 4, fpscr_value);
d8124050 3770 regcache_raw_write (regcache, fpscr_base_regnum, temp_buffer);
283150cd 3771
d8124050 3772 regcache_raw_read (regcache, sr_base_regnum, temp_buffer);
283150cd
EZ
3773 old_sr_value = extract_unsigned_integer (temp_buffer, 4);
3774 old_sr_value &= 0xffff8fff;
3775 sr_value |= old_sr_value;
3776 store_unsigned_integer (temp_buffer, 4, sr_value);
d8124050 3777 regcache_raw_write (regcache, sr_base_regnum, temp_buffer);
283150cd
EZ
3778 }
3779
3780 else if (reg_nr == tdep->FPUL_C_REGNUM)
3781 {
3782 base_regnum = sh64_compact_reg_base_num (reg_nr);
d8124050 3783 regcache_raw_write (regcache, base_regnum, buffer);
283150cd
EZ
3784 }
3785}
3786
3bbfbb92 3787/* Floating point vector of 4 float registers. */
53116e27
EZ
3788static void
3789do_fv_register_info (int fv_regnum)
3790{
3791 int first_fp_reg_num = fv_reg_base_num (fv_regnum);
3792 printf_filtered ("fv%d\t0x%08x\t0x%08x\t0x%08x\t0x%08x\n",
3793 fv_regnum - gdbarch_tdep (current_gdbarch)->FV0_REGNUM,
3794 (int) read_register (first_fp_reg_num),
3795 (int) read_register (first_fp_reg_num + 1),
3796 (int) read_register (first_fp_reg_num + 2),
3797 (int) read_register (first_fp_reg_num + 3));
3798}
3799
283150cd
EZ
3800/* Floating point vector of 4 float registers, compact mode. */
3801static void
3802do_fv_c_register_info (int fv_regnum)
3803{
3804 int first_fp_reg_num = sh64_compact_reg_base_num (fv_regnum);
3805 printf_filtered ("fv%d_c\t0x%08x\t0x%08x\t0x%08x\t0x%08x\n",
3806 fv_regnum - gdbarch_tdep (current_gdbarch)->FV0_C_REGNUM,
3807 (int) read_register (first_fp_reg_num),
3808 (int) read_register (first_fp_reg_num + 1),
3809 (int) read_register (first_fp_reg_num + 2),
3810 (int) read_register (first_fp_reg_num + 3));
3811}
3812
3813/* Pairs of single regs. The DR are instead double precision
3814 registers. */
3815static void
3816do_fpp_register_info (int fpp_regnum)
3817{
3818 int first_fp_reg_num = fpp_reg_base_num (fpp_regnum);
3819
3820 printf_filtered ("fpp%d\t0x%08x\t0x%08x\n",
3821 fpp_regnum - gdbarch_tdep (current_gdbarch)->FPP0_REGNUM,
3822 (int) read_register (first_fp_reg_num),
3823 (int) read_register (first_fp_reg_num + 1));
3824}
3825
3bbfbb92 3826/* Double precision registers. */
53116e27
EZ
3827static void
3828do_dr_register_info (int dr_regnum)
3829{
3830 int first_fp_reg_num = dr_reg_base_num (dr_regnum);
3831
3832 printf_filtered ("dr%d\t0x%08x%08x\n",
3833 dr_regnum - gdbarch_tdep (current_gdbarch)->DR0_REGNUM,
3834 (int) read_register (first_fp_reg_num),
3835 (int) read_register (first_fp_reg_num + 1));
3836}
3837
283150cd
EZ
3838/* Double precision registers, compact mode. */
3839static void
3840do_dr_c_register_info (int dr_regnum)
3841{
3842 int first_fp_reg_num = sh64_compact_reg_base_num (dr_regnum);
3843
3844 printf_filtered ("dr%d_c\t0x%08x%08x\n",
3845 dr_regnum - gdbarch_tdep (current_gdbarch)->DR0_C_REGNUM,
3846 (int) read_register (first_fp_reg_num),
3847 (int) read_register (first_fp_reg_num +1));
3848}
3849
3850/* General register in compact mode. */
3851static void
3852do_r_c_register_info (int r_c_regnum)
3853{
3854 int regnum = sh64_compact_reg_base_num (r_c_regnum);
3855
3856 printf_filtered ("r%d_c\t0x%08x\n",
3857 r_c_regnum - gdbarch_tdep (current_gdbarch)->R0_C_REGNUM,
3858 /*FIXME!!!*/ (int) read_register (regnum));
3859}
3860
3861/* FIXME:!! THIS SHOULD TAKE CARE OF GETTING THE RIGHT PORTION OF THE
3862 shmedia REGISTERS. */
3863/* Control registers, compact mode. */
3864static void
3865do_cr_c_register_info (int cr_c_regnum)
3866{
3867 switch (cr_c_regnum)
3868 {
3869 case 237: printf_filtered ("pc_c\t0x%08x\n", (int) read_register (cr_c_regnum));
3870 break;
3871 case 238: printf_filtered ("gbr_c\t0x%08x\n", (int) read_register (cr_c_regnum));
3872 break;
3873 case 239: printf_filtered ("mach_c\t0x%08x\n", (int) read_register (cr_c_regnum));
3874 break;
3875 case 240: printf_filtered ("macl_c\t0x%08x\n", (int) read_register (cr_c_regnum));
3876 break;
3877 case 241: printf_filtered ("pr_c\t0x%08x\n", (int) read_register (cr_c_regnum));
3878 break;
3879 case 242: printf_filtered ("t_c\t0x%08x\n", (int) read_register (cr_c_regnum));
3880 break;
3881 case 243: printf_filtered ("fpscr_c\t0x%08x\n", (int) read_register (cr_c_regnum));
3882 break;
3883 case 244: printf_filtered ("fpul_c\t0x%08x\n", (int)read_register (cr_c_regnum));
3884 break;
3885 }
3886}
3887
53116e27
EZ
3888static void
3889sh_do_pseudo_register (int regnum)
3890{
f81353e4
EZ
3891 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
3892
53116e27 3893 if (regnum < NUM_REGS || regnum >= NUM_REGS + NUM_PSEUDO_REGS)
8e65ff28
AC
3894 internal_error (__FILE__, __LINE__,
3895 "Invalid pseudo register number %d\n", regnum);
f81353e4
EZ
3896 else if (regnum >= tdep->DR0_REGNUM
3897 && regnum < tdep->DR_LAST_REGNUM)
53116e27 3898 do_dr_register_info (regnum);
f81353e4
EZ
3899 else if (regnum >= tdep->FV0_REGNUM
3900 && regnum <= tdep->FV_LAST_REGNUM)
53116e27
EZ
3901 do_fv_register_info (regnum);
3902}
3903
53116e27
EZ
3904static void
3905sh_do_fp_register (int regnum)
3906{ /* do values for FP (float) regs */
3907 char *raw_buffer;
3908 double flt; /* double extracted from raw hex data */
3909 int inv;
3910 int j;
3911
3912 /* Allocate space for the float. */
3913 raw_buffer = (char *) alloca (REGISTER_RAW_SIZE (FP0_REGNUM));
3914
3915 /* Get the data in raw format. */
6e7f8b9c 3916 if (!frame_register_read (deprecated_selected_frame, regnum, raw_buffer))
53116e27
EZ
3917 error ("can't read register %d (%s)", regnum, REGISTER_NAME (regnum));
3918
3919 /* Get the register as a number */
3920 flt = unpack_double (builtin_type_float, raw_buffer, &inv);
3921
3922 /* Print the name and some spaces. */
3923 fputs_filtered (REGISTER_NAME (regnum), gdb_stdout);
3924 print_spaces_filtered (15 - strlen (REGISTER_NAME (regnum)), gdb_stdout);
3925
3926 /* Print the value. */
93d56215
AC
3927 if (inv)
3928 printf_filtered ("<invalid float>");
3929 else
3930 printf_filtered ("%-10.9g", flt);
53116e27
EZ
3931
3932 /* Print the fp register as hex. */
3933 printf_filtered ("\t(raw 0x");
3934 for (j = 0; j < REGISTER_RAW_SIZE (regnum); j++)
3935 {
d7449b42 3936 register int idx = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? j
53116e27
EZ
3937 : REGISTER_RAW_SIZE (regnum) - 1 - j;
3938 printf_filtered ("%02x", (unsigned char) raw_buffer[idx]);
3939 }
3940 printf_filtered (")");
3941 printf_filtered ("\n");
3942}
3943
283150cd
EZ
3944static void
3945sh64_do_pseudo_register (int regnum)
3946{
3947 /* All the sh64-compact mode registers are pseudo registers. */
3948 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
3949
3950 if (regnum < NUM_REGS
3951 || regnum >= NUM_REGS + NUM_PSEUDO_REGS_SH_MEDIA + NUM_PSEUDO_REGS_SH_COMPACT)
3952 internal_error (__FILE__, __LINE__,
3953 "Invalid pseudo register number %d\n", regnum);
3954
3955 else if ((regnum >= tdep->DR0_REGNUM
3956 && regnum <= tdep->DR_LAST_REGNUM))
3957 do_dr_register_info (regnum);
3958
3959 else if ((regnum >= tdep->DR0_C_REGNUM
3960 && regnum <= tdep->DR_LAST_C_REGNUM))
3961 do_dr_c_register_info (regnum);
3962
3963 else if ((regnum >= tdep->FV0_REGNUM
3964 && regnum <= tdep->FV_LAST_REGNUM))
3965 do_fv_register_info (regnum);
3966
3967 else if ((regnum >= tdep->FV0_C_REGNUM
3968 && regnum <= tdep->FV_LAST_C_REGNUM))
3969 do_fv_c_register_info (regnum);
3970
3971 else if (regnum >= tdep->FPP0_REGNUM
3972 && regnum <= tdep->FPP_LAST_REGNUM)
3973 do_fpp_register_info (regnum);
3974
3975 else if (regnum >= tdep->R0_C_REGNUM
3976 && regnum <= tdep->R_LAST_C_REGNUM)
3977 do_r_c_register_info (regnum); /* FIXME, this function will not print the right format */
3978
3979 else if (regnum >= tdep->FP0_C_REGNUM
3980 && regnum <= tdep->FP_LAST_C_REGNUM)
3981 sh_do_fp_register (regnum); /* this should work also for pseudoregs */
3982
3983 else if (regnum >= tdep->PC_C_REGNUM
3984 && regnum <= tdep->FPUL_C_REGNUM)
3985 do_cr_c_register_info (regnum);
3986
3987}
3988
53116e27
EZ
3989static void
3990sh_do_register (int regnum)
3991{
3992 char raw_buffer[MAX_REGISTER_RAW_SIZE];
3993
3994 fputs_filtered (REGISTER_NAME (regnum), gdb_stdout);
3995 print_spaces_filtered (15 - strlen (REGISTER_NAME (regnum)), gdb_stdout);
3996
3997 /* Get the data in raw format. */
6e7f8b9c 3998 if (!frame_register_read (deprecated_selected_frame, regnum, raw_buffer))
53116e27
EZ
3999 printf_filtered ("*value not available*\n");
4000
4001 val_print (REGISTER_VIRTUAL_TYPE (regnum), raw_buffer, 0, 0,
4002 gdb_stdout, 'x', 1, 0, Val_pretty_default);
4003 printf_filtered ("\t");
4004 val_print (REGISTER_VIRTUAL_TYPE (regnum), raw_buffer, 0, 0,
4005 gdb_stdout, 0, 1, 0, Val_pretty_default);
4006 printf_filtered ("\n");
4007}
4008
4009static void
4010sh_print_register (int regnum)
4011{
4012 if (regnum < 0 || regnum >= NUM_REGS + NUM_PSEUDO_REGS)
8e65ff28
AC
4013 internal_error (__FILE__, __LINE__,
4014 "Invalid register number %d\n", regnum);
53116e27 4015
e30839fe 4016 else if (regnum >= 0 && regnum < NUM_REGS)
53116e27
EZ
4017 {
4018 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT)
4019 sh_do_fp_register (regnum); /* FP regs */
4020 else
4021 sh_do_register (regnum); /* All other regs */
4022 }
4023
4024 else if (regnum < NUM_REGS + NUM_PSEUDO_REGS)
3bbfbb92 4025 do_pseudo_register (regnum);
53116e27
EZ
4026}
4027
4028void
4029sh_do_registers_info (int regnum, int fpregs)
4030{
4031 if (regnum != -1) /* do one specified register */
4032 {
4033 if (*(REGISTER_NAME (regnum)) == '\0')
4034 error ("Not a valid register for the current processor type");
4035
4036 sh_print_register (regnum);
4037 }
4038 else
4039 /* do all (or most) registers */
4040 {
4041 regnum = 0;
4042 while (regnum < NUM_REGS)
4043 {
4044 /* If the register name is empty, it is undefined for this
4045 processor, so don't display anything. */
4046 if (REGISTER_NAME (regnum) == NULL
4047 || *(REGISTER_NAME (regnum)) == '\0')
4048 {
4049 regnum++;
4050 continue;
4051 }
4052
4053 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT)
4054 {
4055 if (fpregs)
4056 {
4057 /* true for "INFO ALL-REGISTERS" command */
4058 sh_do_fp_register (regnum); /* FP regs */
4059 regnum ++;
4060 }
4061 else
e6c42fda 4062 regnum += (gdbarch_tdep (current_gdbarch)->FP_LAST_REGNUM - FP0_REGNUM); /* skip FP regs */
53116e27
EZ
4063 }
4064 else
4065 {
4066 sh_do_register (regnum); /* All other regs */
4067 regnum++;
4068 }
4069 }
4070
4071 if (fpregs)
4072 while (regnum < NUM_REGS + NUM_PSEUDO_REGS)
4073 {
3bbfbb92 4074 do_pseudo_register (regnum);
53116e27
EZ
4075 regnum++;
4076 }
4077 }
4078}
4079
283150cd
EZ
4080void
4081sh_compact_do_registers_info (int regnum, int fpregs)
4082{
4083 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
4084 if (regnum != -1) /* do one specified register */
4085 {
4086 if (*(REGISTER_NAME (regnum)) == '\0')
4087 error ("Not a valid register for the current processor type");
4088
4089 if (regnum >= 0 && regnum < tdep->R0_C_REGNUM)
4090 error ("Not a valid register for the current processor mode.");
4091
4092 sh_print_register (regnum);
4093 }
4094 else
4095 /* do all compact registers */
4096 {
4097 regnum = tdep->R0_C_REGNUM;
4098 while (regnum < NUM_REGS + NUM_PSEUDO_REGS)
4099 {
4100 do_pseudo_register (regnum);
4101 regnum++;
4102 }
4103 }
4104}
4105
4106void
4107sh64_do_registers_info (int regnum, int fpregs)
4108{
50abf9e5 4109 if (pc_is_isa32 (get_frame_pc (deprecated_selected_frame)))
283150cd
EZ
4110 sh_do_registers_info (regnum, fpregs);
4111 else
4112 sh_compact_do_registers_info (regnum, fpregs);
4113}
4114
1a8629c7
MS
4115#ifdef SVR4_SHARED_LIBS
4116
4117/* Fetch (and possibly build) an appropriate link_map_offsets structure
4118 for native i386 linux targets using the struct offsets defined in
4119 link.h (but without actual reference to that file).
4120
4121 This makes it possible to access i386-linux shared libraries from
4122 a gdb that was not built on an i386-linux host (for cross debugging).
4123 */
4124
4125struct link_map_offsets *
4126sh_linux_svr4_fetch_link_map_offsets (void)
4127{
4128 static struct link_map_offsets lmo;
4129 static struct link_map_offsets *lmp = 0;
4130
4131 if (lmp == 0)
4132 {
4133 lmp = &lmo;
4134
4135 lmo.r_debug_size = 8; /* 20 not actual size but all we need */
4136
4137 lmo.r_map_offset = 4;
4138 lmo.r_map_size = 4;
4139
4140 lmo.link_map_size = 20; /* 552 not actual size but all we need */
4141
4142 lmo.l_addr_offset = 0;
4143 lmo.l_addr_size = 4;
4144
4145 lmo.l_name_offset = 4;
4146 lmo.l_name_size = 4;
4147
4148 lmo.l_next_offset = 12;
4149 lmo.l_next_size = 4;
4150
4151 lmo.l_prev_offset = 16;
4152 lmo.l_prev_size = 4;
4153 }
4154
4155 return lmp;
4156}
4157#endif /* SVR4_SHARED_LIBS */
4158
2f14585c
JR
4159\f
4160enum
4161{
4162 DSP_DSR_REGNUM = 24,
4163 DSP_A0G_REGNUM,
4164 DSP_A0_REGNUM,
4165 DSP_A1G_REGNUM,
4166 DSP_A1_REGNUM,
4167 DSP_M0_REGNUM,
4168 DSP_M1_REGNUM,
4169 DSP_X0_REGNUM,
4170 DSP_X1_REGNUM,
4171 DSP_Y0_REGNUM,
4172 DSP_Y1_REGNUM,
4173
4174 DSP_MOD_REGNUM = 40,
4175
4176 DSP_RS_REGNUM = 43,
4177 DSP_RE_REGNUM,
4178
4179 DSP_R0_BANK_REGNUM = 51,
4180 DSP_R7_BANK_REGNUM = DSP_R0_BANK_REGNUM + 7
4181};
4182
4183static int
4184sh_dsp_register_sim_regno (int nr)
4185{
4186 if (legacy_register_sim_regno (nr) < 0)
4187 return legacy_register_sim_regno (nr);
4188 if (nr >= DSP_DSR_REGNUM && nr < DSP_Y1_REGNUM)
4189 return nr - DSP_DSR_REGNUM + SIM_SH_DSR_REGNUM;
4190 if (nr == DSP_MOD_REGNUM)
4191 return SIM_SH_MOD_REGNUM;
4192 if (nr == DSP_RS_REGNUM)
4193 return SIM_SH_RS_REGNUM;
4194 if (nr == DSP_RE_REGNUM)
4195 return SIM_SH_RE_REGNUM;
4196 if (nr >= DSP_R0_BANK_REGNUM && nr <= DSP_R7_BANK_REGNUM)
4197 return nr - DSP_R0_BANK_REGNUM + SIM_SH_R0_BANK_REGNUM;
4198 return nr;
4199}
d658f924 4200\f
cc17453a
EZ
4201static gdbarch_init_ftype sh_gdbarch_init;
4202
4203static struct gdbarch *
fba45db2 4204sh_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
cc17453a
EZ
4205{
4206 static LONGEST sh_call_dummy_words[] = {0};
4207 struct gdbarch *gdbarch;
4208 struct gdbarch_tdep *tdep;
4209 gdbarch_register_name_ftype *sh_register_name;
ebba8386 4210 gdbarch_deprecated_store_return_value_ftype *sh_store_return_value;
cc17453a 4211 gdbarch_register_virtual_type_ftype *sh_register_virtual_type;
d658f924 4212
4be87837
DJ
4213 /* If there is already a candidate, use it. */
4214 arches = gdbarch_list_lookup_by_info (arches, &info);
4215 if (arches != NULL)
4216 return arches->gdbarch;
cc17453a
EZ
4217
4218 /* None found, create a new architecture from the information
4219 provided. */
4220 tdep = XMALLOC (struct gdbarch_tdep);
4221 gdbarch = gdbarch_alloc (&info, tdep);
4222
a5afb99f
AC
4223 /* NOTE: cagney/2002-12-06: This can be deleted when this arch is
4224 ready to unwind the PC first (see frame.c:get_prev_frame()). */
4225 set_gdbarch_deprecated_init_frame_pc (gdbarch, init_frame_pc_default);
4226
cc17453a
EZ
4227 /* Initialize the register numbers that are not common to all the
4228 variants to -1, if necessary thse will be overwritten in the case
4229 statement below. */
4230 tdep->FPUL_REGNUM = -1;
4231 tdep->FPSCR_REGNUM = -1;
3bbfbb92 4232 tdep->PR_REGNUM = 17;
c62a7c7b 4233 tdep->SR_REGNUM = 22;
cc17453a 4234 tdep->DSR_REGNUM = -1;
e6c42fda 4235 tdep->FP_LAST_REGNUM = -1;
cc17453a
EZ
4236 tdep->A0G_REGNUM = -1;
4237 tdep->A0_REGNUM = -1;
4238 tdep->A1G_REGNUM = -1;
4239 tdep->A1_REGNUM = -1;
4240 tdep->M0_REGNUM = -1;
4241 tdep->M1_REGNUM = -1;
4242 tdep->X0_REGNUM = -1;
4243 tdep->X1_REGNUM = -1;
4244 tdep->Y0_REGNUM = -1;
4245 tdep->Y1_REGNUM = -1;
4246 tdep->MOD_REGNUM = -1;
4247 tdep->RS_REGNUM = -1;
4248 tdep->RE_REGNUM = -1;
4249 tdep->SSR_REGNUM = -1;
4250 tdep->SPC_REGNUM = -1;
53116e27 4251 tdep->DR0_REGNUM = -1;
e6c42fda 4252 tdep->DR_LAST_REGNUM = -1;
53116e27 4253 tdep->FV0_REGNUM = -1;
e6c42fda 4254 tdep->FV_LAST_REGNUM = -1;
3bbfbb92
EZ
4255 tdep->ARG0_REGNUM = 4;
4256 tdep->ARGLAST_REGNUM = 7;
4257 tdep->RETURN_REGNUM = 0;
4258 tdep->FLOAT_ARGLAST_REGNUM = -1;
a38d2a54 4259
283150cd
EZ
4260 tdep->sh_abi = SH_ABI_UNKNOWN;
4261
cc17453a 4262 set_gdbarch_fp0_regnum (gdbarch, -1);
53116e27
EZ
4263 set_gdbarch_num_pseudo_regs (gdbarch, 0);
4264 set_gdbarch_max_register_raw_size (gdbarch, 4);
4265 set_gdbarch_max_register_virtual_size (gdbarch, 4);
ec920329 4266 set_gdbarch_long_bit (gdbarch, 4 * TARGET_CHAR_BIT);
a38d2a54 4267 set_gdbarch_ptr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
88e04cc1 4268 set_gdbarch_num_regs (gdbarch, SH_DEFAULT_NUM_REGS);
a38d2a54
EZ
4269 set_gdbarch_sp_regnum (gdbarch, 15);
4270 set_gdbarch_fp_regnum (gdbarch, 14);
4271 set_gdbarch_pc_regnum (gdbarch, 16);
4272 set_gdbarch_register_size (gdbarch, 4);
88e04cc1 4273 set_gdbarch_register_bytes (gdbarch, SH_DEFAULT_NUM_REGS * 4);
903ad3a6 4274 set_gdbarch_deprecated_do_registers_info (gdbarch, sh_do_registers_info);
eaf90c5d 4275 set_gdbarch_breakpoint_from_pc (gdbarch, sh_breakpoint_from_pc);
3bbfbb92 4276 set_gdbarch_frame_chain (gdbarch, sh_frame_chain);
bdcdd535 4277 set_gdbarch_get_saved_register (gdbarch, deprecated_generic_get_saved_register);
3bbfbb92 4278 set_gdbarch_init_extra_frame_info (gdbarch, sh_init_extra_frame_info);
26e9b323 4279 set_gdbarch_deprecated_extract_return_value (gdbarch, sh_extract_return_value);
3bbfbb92
EZ
4280 set_gdbarch_push_arguments (gdbarch, sh_push_arguments);
4281 set_gdbarch_store_struct_return (gdbarch, sh_store_struct_return);
4282 set_gdbarch_use_struct_convention (gdbarch, sh_use_struct_convention);
26e9b323 4283 set_gdbarch_deprecated_extract_struct_value_address (gdbarch, sh_extract_struct_value_address);
3bbfbb92 4284 set_gdbarch_pop_frame (gdbarch, sh_pop_frame);
2bf0cb65 4285 set_gdbarch_print_insn (gdbarch, gdb_print_insn_sh);
2f14585c 4286 set_gdbarch_register_sim_regno (gdbarch, legacy_register_sim_regno);
3bbfbb92
EZ
4287 skip_prologue_hard_way = sh_skip_prologue_hard_way;
4288 do_pseudo_register = sh_do_pseudo_register;
cc17453a
EZ
4289
4290 switch (info.bfd_arch_info->mach)
8db62801 4291 {
cc17453a
EZ
4292 case bfd_mach_sh:
4293 sh_register_name = sh_sh_register_name;
4294 sh_show_regs = sh_generic_show_regs;
4295 sh_store_return_value = sh_default_store_return_value;
4296 sh_register_virtual_type = sh_default_register_virtual_type;
4297 set_gdbarch_frame_init_saved_regs (gdbarch, sh_nofp_frame_init_saved_regs);
53116e27
EZ
4298 set_gdbarch_register_raw_size (gdbarch, sh_default_register_raw_size);
4299 set_gdbarch_register_virtual_size (gdbarch, sh_default_register_raw_size);
4300 set_gdbarch_register_byte (gdbarch, sh_default_register_byte);
cc17453a
EZ
4301 break;
4302 case bfd_mach_sh2:
4303 sh_register_name = sh_sh_register_name;
4304 sh_show_regs = sh_generic_show_regs;
4305 sh_store_return_value = sh_default_store_return_value;
4306 sh_register_virtual_type = sh_default_register_virtual_type;
4307 set_gdbarch_frame_init_saved_regs (gdbarch, sh_nofp_frame_init_saved_regs);
53116e27
EZ
4308 set_gdbarch_register_raw_size (gdbarch, sh_default_register_raw_size);
4309 set_gdbarch_register_virtual_size (gdbarch, sh_default_register_raw_size);
4310 set_gdbarch_register_byte (gdbarch, sh_default_register_byte);
cc17453a
EZ
4311 break;
4312 case bfd_mach_sh_dsp:
4313 sh_register_name = sh_sh_dsp_register_name;
4314 sh_show_regs = sh_dsp_show_regs;
4315 sh_store_return_value = sh_default_store_return_value;
4316 sh_register_virtual_type = sh_default_register_virtual_type;
4317 set_gdbarch_frame_init_saved_regs (gdbarch, sh_nofp_frame_init_saved_regs);
53116e27
EZ
4318 set_gdbarch_register_raw_size (gdbarch, sh_default_register_raw_size);
4319 set_gdbarch_register_virtual_size (gdbarch, sh_default_register_raw_size);
4320 set_gdbarch_register_byte (gdbarch, sh_default_register_byte);
2f14585c 4321 set_gdbarch_register_sim_regno (gdbarch, sh_dsp_register_sim_regno);
cc17453a
EZ
4322 tdep->DSR_REGNUM = 24;
4323 tdep->A0G_REGNUM = 25;
4324 tdep->A0_REGNUM = 26;
4325 tdep->A1G_REGNUM = 27;
4326 tdep->A1_REGNUM = 28;
4327 tdep->M0_REGNUM = 29;
4328 tdep->M1_REGNUM = 30;
4329 tdep->X0_REGNUM = 31;
4330 tdep->X1_REGNUM = 32;
4331 tdep->Y0_REGNUM = 33;
4332 tdep->Y1_REGNUM = 34;
4333 tdep->MOD_REGNUM = 40;
4334 tdep->RS_REGNUM = 43;
4335 tdep->RE_REGNUM = 44;
4336 break;
4337 case bfd_mach_sh3:
4338 sh_register_name = sh_sh3_register_name;
4339 sh_show_regs = sh3_show_regs;
4340 sh_store_return_value = sh_default_store_return_value;
4341 sh_register_virtual_type = sh_default_register_virtual_type;
4342 set_gdbarch_frame_init_saved_regs (gdbarch, sh_nofp_frame_init_saved_regs);
53116e27
EZ
4343 set_gdbarch_register_raw_size (gdbarch, sh_default_register_raw_size);
4344 set_gdbarch_register_virtual_size (gdbarch, sh_default_register_raw_size);
4345 set_gdbarch_register_byte (gdbarch, sh_default_register_byte);
cc17453a
EZ
4346 tdep->SSR_REGNUM = 41;
4347 tdep->SPC_REGNUM = 42;
4348 break;
4349 case bfd_mach_sh3e:
4350 sh_register_name = sh_sh3e_register_name;
4351 sh_show_regs = sh3e_show_regs;
4352 sh_store_return_value = sh3e_sh4_store_return_value;
4353 sh_register_virtual_type = sh_sh3e_register_virtual_type;
4354 set_gdbarch_frame_init_saved_regs (gdbarch, sh_fp_frame_init_saved_regs);
53116e27
EZ
4355 set_gdbarch_register_raw_size (gdbarch, sh_default_register_raw_size);
4356 set_gdbarch_register_virtual_size (gdbarch, sh_default_register_raw_size);
4357 set_gdbarch_register_byte (gdbarch, sh_default_register_byte);
26e9b323 4358 set_gdbarch_deprecated_extract_return_value (gdbarch, sh3e_sh4_extract_return_value);
cc17453a
EZ
4359 set_gdbarch_fp0_regnum (gdbarch, 25);
4360 tdep->FPUL_REGNUM = 23;
4361 tdep->FPSCR_REGNUM = 24;
e6c42fda 4362 tdep->FP_LAST_REGNUM = 40;
cc17453a
EZ
4363 tdep->SSR_REGNUM = 41;
4364 tdep->SPC_REGNUM = 42;
4365 break;
4366 case bfd_mach_sh3_dsp:
4367 sh_register_name = sh_sh3_dsp_register_name;
4368 sh_show_regs = sh3_dsp_show_regs;
4369 sh_store_return_value = sh_default_store_return_value;
4370 sh_register_virtual_type = sh_default_register_virtual_type;
4371 set_gdbarch_frame_init_saved_regs (gdbarch, sh_nofp_frame_init_saved_regs);
53116e27
EZ
4372 set_gdbarch_register_raw_size (gdbarch, sh_default_register_raw_size);
4373 set_gdbarch_register_virtual_size (gdbarch, sh_default_register_raw_size);
4374 set_gdbarch_register_byte (gdbarch, sh_default_register_byte);
cc17453a
EZ
4375 tdep->DSR_REGNUM = 24;
4376 tdep->A0G_REGNUM = 25;
4377 tdep->A0_REGNUM = 26;
4378 tdep->A1G_REGNUM = 27;
4379 tdep->A1_REGNUM = 28;
4380 tdep->M0_REGNUM = 29;
4381 tdep->M1_REGNUM = 30;
4382 tdep->X0_REGNUM = 31;
4383 tdep->X1_REGNUM = 32;
4384 tdep->Y0_REGNUM = 33;
4385 tdep->Y1_REGNUM = 34;
4386 tdep->MOD_REGNUM = 40;
4387 tdep->RS_REGNUM = 43;
4388 tdep->RE_REGNUM = 44;
4389 tdep->SSR_REGNUM = 41;
4390 tdep->SPC_REGNUM = 42;
4391 break;
4392 case bfd_mach_sh4:
53116e27
EZ
4393 sh_register_name = sh_sh4_register_name;
4394 sh_show_regs = sh4_show_regs;
cc17453a 4395 sh_store_return_value = sh3e_sh4_store_return_value;
53116e27 4396 sh_register_virtual_type = sh_sh4_register_virtual_type;
cc17453a 4397 set_gdbarch_frame_init_saved_regs (gdbarch, sh_fp_frame_init_saved_regs);
26e9b323 4398 set_gdbarch_deprecated_extract_return_value (gdbarch, sh3e_sh4_extract_return_value);
cc17453a 4399 set_gdbarch_fp0_regnum (gdbarch, 25);
53116e27
EZ
4400 set_gdbarch_register_raw_size (gdbarch, sh_sh4_register_raw_size);
4401 set_gdbarch_register_virtual_size (gdbarch, sh_sh4_register_raw_size);
4402 set_gdbarch_register_byte (gdbarch, sh_sh4_register_byte);
4403 set_gdbarch_num_pseudo_regs (gdbarch, 12);
4404 set_gdbarch_max_register_raw_size (gdbarch, 4 * 4);
4405 set_gdbarch_max_register_virtual_size (gdbarch, 4 * 4);
d8124050
AC
4406 set_gdbarch_pseudo_register_read (gdbarch, sh_pseudo_register_read);
4407 set_gdbarch_pseudo_register_write (gdbarch, sh_pseudo_register_write);
cc17453a
EZ
4408 tdep->FPUL_REGNUM = 23;
4409 tdep->FPSCR_REGNUM = 24;
e6c42fda 4410 tdep->FP_LAST_REGNUM = 40;
cc17453a
EZ
4411 tdep->SSR_REGNUM = 41;
4412 tdep->SPC_REGNUM = 42;
53116e27 4413 tdep->DR0_REGNUM = 59;
e6c42fda 4414 tdep->DR_LAST_REGNUM = 66;
53116e27 4415 tdep->FV0_REGNUM = 67;
e6c42fda 4416 tdep->FV_LAST_REGNUM = 70;
cc17453a 4417 break;
283150cd
EZ
4418 case bfd_mach_sh5:
4419 tdep->PR_REGNUM = 18;
4420 tdep->SR_REGNUM = 65;
4421 tdep->FPSCR_REGNUM = SIM_SH64_FPCSR_REGNUM;
4422 tdep->FP_LAST_REGNUM = SIM_SH64_FR0_REGNUM + SIM_SH64_NR_FP_REGS - 1;
4423 tdep->SSR_REGNUM = SIM_SH64_SSR_REGNUM;
4424 tdep->SPC_REGNUM = SIM_SH64_SPC_REGNUM;
4425 tdep->TR7_REGNUM = SIM_SH64_TR0_REGNUM + 7;
4426 tdep->FPP0_REGNUM = 173;
4427 tdep->FPP_LAST_REGNUM = 204;
4428 tdep->DR0_REGNUM = 141;
4429 tdep->DR_LAST_REGNUM = 172;
4430 tdep->FV0_REGNUM = 205;
4431 tdep->FV_LAST_REGNUM = 220;
4432 tdep->R0_C_REGNUM = 221;
4433 tdep->R_LAST_C_REGNUM = 236;
4434 tdep->PC_C_REGNUM = 237;
4435 tdep->GBR_C_REGNUM = 238;
4436 tdep->MACH_C_REGNUM = 239;
4437 tdep->MACL_C_REGNUM = 240;
4438 tdep->PR_C_REGNUM = 241;
4439 tdep->T_C_REGNUM = 242;
4440 tdep->FPSCR_C_REGNUM = 243;
4441 tdep->FPUL_C_REGNUM = 244;
4442 tdep->FP0_C_REGNUM = 245;
4443 tdep->FP_LAST_C_REGNUM = 260;
4444 tdep->DR0_C_REGNUM = 261;
4445 tdep->DR_LAST_C_REGNUM = 268;
4446 tdep->FV0_C_REGNUM = 269;
4447 tdep->FV_LAST_C_REGNUM = 272;
4448 tdep->ARG0_REGNUM = 2;
4449 tdep->ARGLAST_REGNUM = 9;
4450 tdep->RETURN_REGNUM = 2;
4451 tdep->FLOAT_ARGLAST_REGNUM = 11;
4452
4453 set_gdbarch_num_pseudo_regs (gdbarch, NUM_PSEUDO_REGS_SH_MEDIA + NUM_PSEUDO_REGS_SH_COMPACT);
4454 set_gdbarch_fp0_regnum (gdbarch, SIM_SH64_FR0_REGNUM);
4455 set_gdbarch_pc_regnum (gdbarch, 64);
4456
4457 /* Determine the ABI */
4458 if (bfd_get_arch_size (info.abfd) == 64)
4459 {
4460 /* If the ABI is the 64-bit one, it can only be sh-media. */
4461 tdep->sh_abi = SH_ABI_64;
4462 set_gdbarch_ptr_bit (gdbarch, 8 * TARGET_CHAR_BIT);
4463 set_gdbarch_long_bit (gdbarch, 8 * TARGET_CHAR_BIT);
4464 }
4465 else
4466 {
4467 /* If the ABI is the 32-bit one it could be either media or
4468 compact. */
4469 tdep->sh_abi = SH_ABI_32;
4470 set_gdbarch_ptr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
4471 set_gdbarch_long_bit (gdbarch, 4 * TARGET_CHAR_BIT);
4472 }
4473
4474 /* the number of real registers is the same whether we are in
4475 ISA16(compact) or ISA32(media). */
4476 set_gdbarch_num_regs (gdbarch, SIM_SH64_NR_REGS);
4477 set_gdbarch_register_size (gdbarch, 8); /*????*/
4478 set_gdbarch_register_bytes (gdbarch,
4479 ((SIM_SH64_NR_FP_REGS + 1) * 4)
4480 + (SIM_SH64_NR_REGS - SIM_SH64_NR_FP_REGS -1) * 8);
4481
4482 sh_register_name = sh_sh64_register_name;
4483 sh_show_regs = sh64_show_regs;
4484 sh_register_virtual_type = sh_sh64_register_virtual_type;
4485 sh_store_return_value = sh64_store_return_value;
4486 skip_prologue_hard_way = sh64_skip_prologue_hard_way;
4487 do_pseudo_register = sh64_do_pseudo_register;
283150cd
EZ
4488 set_gdbarch_register_raw_size (gdbarch, sh_sh64_register_raw_size);
4489 set_gdbarch_register_virtual_size (gdbarch, sh_sh64_register_raw_size);
4490 set_gdbarch_register_byte (gdbarch, sh_sh64_register_byte);
4491 /* This seems awfully wrong!*/
4492 /*set_gdbarch_max_register_raw_size (gdbarch, 8);*/
4493 /* should include the size of the pseudo regs. */
4494 set_gdbarch_max_register_raw_size (gdbarch, 4 * 4);
4495 /* Or should that go in the virtual_size? */
4496 /*set_gdbarch_max_register_virtual_size (gdbarch, 8);*/
4497 set_gdbarch_max_register_virtual_size (gdbarch, 4 * 4);
d8124050
AC
4498 set_gdbarch_pseudo_register_read (gdbarch, sh64_pseudo_register_read);
4499 set_gdbarch_pseudo_register_write (gdbarch, sh64_pseudo_register_write);
283150cd 4500
903ad3a6 4501 set_gdbarch_deprecated_do_registers_info (gdbarch, sh64_do_registers_info);
283150cd
EZ
4502 set_gdbarch_frame_init_saved_regs (gdbarch, sh64_nofp_frame_init_saved_regs);
4503 set_gdbarch_breakpoint_from_pc (gdbarch, sh_sh64_breakpoint_from_pc);
4504 set_gdbarch_init_extra_frame_info (gdbarch, sh64_init_extra_frame_info);
4505 set_gdbarch_frame_chain (gdbarch, sh64_frame_chain);
4506 set_gdbarch_get_saved_register (gdbarch, sh64_get_saved_register);
26e9b323 4507 set_gdbarch_deprecated_extract_return_value (gdbarch, sh64_extract_return_value);
283150cd
EZ
4508 set_gdbarch_push_arguments (gdbarch, sh64_push_arguments);
4509 /*set_gdbarch_store_struct_return (gdbarch, sh64_store_struct_return);*/
26e9b323 4510 set_gdbarch_deprecated_extract_struct_value_address (gdbarch, sh64_extract_struct_value_address);
283150cd
EZ
4511 set_gdbarch_use_struct_convention (gdbarch, sh64_use_struct_convention);
4512 set_gdbarch_pop_frame (gdbarch, sh64_pop_frame);
4513 set_gdbarch_elf_make_msymbol_special (gdbarch,
4514 sh64_elf_make_msymbol_special);
4515 break;
cc17453a
EZ
4516 default:
4517 sh_register_name = sh_generic_register_name;
4518 sh_show_regs = sh_generic_show_regs;
4519 sh_store_return_value = sh_default_store_return_value;
4520 sh_register_virtual_type = sh_default_register_virtual_type;
4521 set_gdbarch_frame_init_saved_regs (gdbarch, sh_nofp_frame_init_saved_regs);
53116e27
EZ
4522 set_gdbarch_register_raw_size (gdbarch, sh_default_register_raw_size);
4523 set_gdbarch_register_virtual_size (gdbarch, sh_default_register_raw_size);
4524 set_gdbarch_register_byte (gdbarch, sh_default_register_byte);
cc17453a 4525 break;
8db62801 4526 }
cc17453a
EZ
4527
4528 set_gdbarch_read_pc (gdbarch, generic_target_read_pc);
4529 set_gdbarch_write_pc (gdbarch, generic_target_write_pc);
4530 set_gdbarch_read_fp (gdbarch, generic_target_read_fp);
cc17453a
EZ
4531 set_gdbarch_read_sp (gdbarch, generic_target_read_sp);
4532 set_gdbarch_write_sp (gdbarch, generic_target_write_sp);
4533
cc17453a 4534 set_gdbarch_register_name (gdbarch, sh_register_name);
cc17453a
EZ
4535 set_gdbarch_register_virtual_type (gdbarch, sh_register_virtual_type);
4536
cc17453a
EZ
4537 set_gdbarch_short_bit (gdbarch, 2 * TARGET_CHAR_BIT);
4538 set_gdbarch_int_bit (gdbarch, 4 * TARGET_CHAR_BIT);
cc17453a
EZ
4539 set_gdbarch_long_long_bit (gdbarch, 8 * TARGET_CHAR_BIT);
4540 set_gdbarch_float_bit (gdbarch, 4 * TARGET_CHAR_BIT);
4541 set_gdbarch_double_bit (gdbarch, 8 * TARGET_CHAR_BIT);
7079c36c 4542 set_gdbarch_long_double_bit (gdbarch, 8 * TARGET_CHAR_BIT);
cc17453a 4543
cc17453a 4544 set_gdbarch_call_dummy_length (gdbarch, 0);
cc17453a
EZ
4545 set_gdbarch_call_dummy_address (gdbarch, entry_point_address);
4546 set_gdbarch_call_dummy_breakpoint_offset_p (gdbarch, 1); /*???*/
4547 set_gdbarch_call_dummy_breakpoint_offset (gdbarch, 0);
4548 set_gdbarch_call_dummy_start_offset (gdbarch, 0);
cc17453a
EZ
4549 set_gdbarch_call_dummy_words (gdbarch, sh_call_dummy_words);
4550 set_gdbarch_sizeof_call_dummy_words (gdbarch, sizeof (sh_call_dummy_words));
4551 set_gdbarch_call_dummy_p (gdbarch, 1);
4552 set_gdbarch_call_dummy_stack_adjust_p (gdbarch, 0);
cc17453a 4553 set_gdbarch_fix_call_dummy (gdbarch, generic_fix_call_dummy);
cc17453a 4554
cc17453a
EZ
4555 set_gdbarch_push_dummy_frame (gdbarch, generic_push_dummy_frame);
4556 set_gdbarch_push_return_address (gdbarch, sh_push_return_address);
4557
ebba8386 4558 set_gdbarch_deprecated_store_return_value (gdbarch, sh_store_return_value);
cc17453a
EZ
4559 set_gdbarch_skip_prologue (gdbarch, sh_skip_prologue);
4560 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
4561 set_gdbarch_decr_pc_after_break (gdbarch, 0);
4562 set_gdbarch_function_start_offset (gdbarch, 0);
cc17453a
EZ
4563
4564 set_gdbarch_frame_args_skip (gdbarch, 0);
4565 set_gdbarch_frameless_function_invocation (gdbarch, frameless_look_for_prologue);
cc17453a 4566 set_gdbarch_frame_saved_pc (gdbarch, sh_frame_saved_pc);
cc17453a
EZ
4567 set_gdbarch_saved_pc_after_call (gdbarch, sh_saved_pc_after_call);
4568 set_gdbarch_frame_num_args (gdbarch, frame_num_args_unknown);
4569 set_gdbarch_believe_pcc_promotion (gdbarch, 1);
cc17453a 4570
4be87837
DJ
4571 /* Hook in ABI-specific overrides, if they have been registered. */
4572 gdbarch_init_osabi (info, gdbarch);
d658f924 4573
cc17453a 4574 return gdbarch;
8db62801
EZ
4575}
4576
d658f924
JT
4577static void
4578sh_dump_tdep (struct gdbarch *current_gdbarch, struct ui_file *file)
4579{
4580 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
4581
4582 if (tdep == NULL)
4583 return;
4584
4be87837 4585 /* FIXME: dump the rest of gdbarch_tdep. */
d658f924
JT
4586}
4587
c906108c 4588void
fba45db2 4589_initialize_sh_tdep (void)
c906108c
SS
4590{
4591 struct cmd_list_element *c;
cc17453a 4592
d658f924 4593 gdbarch_register (bfd_arch_sh, sh_gdbarch_init, sh_dump_tdep);
c906108c 4594
53116e27 4595 add_com ("regs", class_vars, sh_show_regs_command, "Print all registers");
c906108c 4596}
This page took 0.508914 seconds and 4 git commands to generate.