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