Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Target-dependent code for the MIPS architecture, for GDB, the GNU Debugger. |
bf64bfd6 | 2 | |
ecd75fc8 | 3 | Copyright (C) 1988-2014 Free Software Foundation, Inc. |
bf64bfd6 | 4 | |
c906108c SS |
5 | Contributed by Alessandro Forin(af@cs.cmu.edu) at CMU |
6 | and by Per Bothner(bothner@cs.wisc.edu) at U.Wisconsin. | |
7 | ||
c5aa993b | 8 | This file is part of GDB. |
c906108c | 9 | |
c5aa993b JM |
10 | This program is free software; you can redistribute it and/or modify |
11 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 12 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 13 | (at your option) any later version. |
c906108c | 14 | |
c5aa993b JM |
15 | This program is distributed in the hope that it will be useful, |
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | GNU General Public License for more details. | |
c906108c | 19 | |
c5aa993b | 20 | You should have received a copy of the GNU General Public License |
a9762ec7 | 21 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
22 | |
23 | #include "defs.h" | |
0e9f083f | 24 | #include <string.h> |
5e2e9765 | 25 | #include "gdb_assert.h" |
c906108c SS |
26 | #include "frame.h" |
27 | #include "inferior.h" | |
28 | #include "symtab.h" | |
29 | #include "value.h" | |
30 | #include "gdbcmd.h" | |
31 | #include "language.h" | |
32 | #include "gdbcore.h" | |
33 | #include "symfile.h" | |
34 | #include "objfiles.h" | |
35 | #include "gdbtypes.h" | |
36 | #include "target.h" | |
28d069e6 | 37 | #include "arch-utils.h" |
4e052eda | 38 | #include "regcache.h" |
70f80edf | 39 | #include "osabi.h" |
d1973055 | 40 | #include "mips-tdep.h" |
fe898f56 | 41 | #include "block.h" |
a4b8ebc8 | 42 | #include "reggroups.h" |
c906108c | 43 | #include "opcode/mips.h" |
c2d11a7d JM |
44 | #include "elf/mips.h" |
45 | #include "elf-bfd.h" | |
2475bac3 | 46 | #include "symcat.h" |
a4b8ebc8 | 47 | #include "sim-regno.h" |
a89aa300 | 48 | #include "dis-asm.h" |
edfae063 AC |
49 | #include "frame-unwind.h" |
50 | #include "frame-base.h" | |
51 | #include "trad-frame.h" | |
7d9b040b | 52 | #include "infcall.h" |
fed7ba43 | 53 | #include "floatformat.h" |
29709017 DJ |
54 | #include "remote.h" |
55 | #include "target-descriptions.h" | |
2bd0c3d7 | 56 | #include "dwarf2-frame.h" |
f8b73d13 | 57 | #include "user-regs.h" |
79a45b7d | 58 | #include "valprint.h" |
175ff332 | 59 | #include "ax.h" |
c906108c | 60 | |
8d5f9dcb DJ |
61 | static const struct objfile_data *mips_pdr_data; |
62 | ||
5bbcb741 | 63 | static struct type *mips_register_type (struct gdbarch *gdbarch, int regnum); |
e0f7ec59 | 64 | |
4cc0665f MR |
65 | static int mips32_instruction_has_delay_slot (struct gdbarch *, CORE_ADDR); |
66 | static int micromips_instruction_has_delay_slot (struct gdbarch *, CORE_ADDR, | |
67 | int); | |
68 | static int mips16_instruction_has_delay_slot (struct gdbarch *, CORE_ADDR, | |
69 | int); | |
70 | ||
24e05951 | 71 | /* A useful bit in the CP0 status register (MIPS_PS_REGNUM). */ |
dd824b04 DJ |
72 | /* This bit is set if we are emulating 32-bit FPRs on a 64-bit chip. */ |
73 | #define ST0_FR (1 << 26) | |
74 | ||
b0069a17 AC |
75 | /* The sizes of floating point registers. */ |
76 | ||
77 | enum | |
78 | { | |
79 | MIPS_FPU_SINGLE_REGSIZE = 4, | |
80 | MIPS_FPU_DOUBLE_REGSIZE = 8 | |
81 | }; | |
82 | ||
1a69e1e4 DJ |
83 | enum |
84 | { | |
85 | MIPS32_REGSIZE = 4, | |
86 | MIPS64_REGSIZE = 8 | |
87 | }; | |
0dadbba0 | 88 | |
2e4ebe70 DJ |
89 | static const char *mips_abi_string; |
90 | ||
40478521 | 91 | static const char *const mips_abi_strings[] = { |
2e4ebe70 DJ |
92 | "auto", |
93 | "n32", | |
94 | "o32", | |
28d169de | 95 | "n64", |
2e4ebe70 DJ |
96 | "o64", |
97 | "eabi32", | |
98 | "eabi64", | |
99 | NULL | |
100 | }; | |
101 | ||
4cc0665f MR |
102 | /* For backwards compatibility we default to MIPS16. This flag is |
103 | overridden as soon as unambiguous ELF file flags tell us the | |
104 | compressed ISA encoding used. */ | |
105 | static const char mips_compression_mips16[] = "mips16"; | |
106 | static const char mips_compression_micromips[] = "micromips"; | |
107 | static const char *const mips_compression_strings[] = | |
108 | { | |
109 | mips_compression_mips16, | |
110 | mips_compression_micromips, | |
111 | NULL | |
112 | }; | |
113 | ||
114 | static const char *mips_compression_string = mips_compression_mips16; | |
115 | ||
f8b73d13 DJ |
116 | /* The standard register names, and all the valid aliases for them. */ |
117 | struct register_alias | |
118 | { | |
119 | const char *name; | |
120 | int regnum; | |
121 | }; | |
122 | ||
123 | /* Aliases for o32 and most other ABIs. */ | |
124 | const struct register_alias mips_o32_aliases[] = { | |
125 | { "ta0", 12 }, | |
126 | { "ta1", 13 }, | |
127 | { "ta2", 14 }, | |
128 | { "ta3", 15 } | |
129 | }; | |
130 | ||
131 | /* Aliases for n32 and n64. */ | |
132 | const struct register_alias mips_n32_n64_aliases[] = { | |
133 | { "ta0", 8 }, | |
134 | { "ta1", 9 }, | |
135 | { "ta2", 10 }, | |
136 | { "ta3", 11 } | |
137 | }; | |
138 | ||
139 | /* Aliases for ABI-independent registers. */ | |
140 | const struct register_alias mips_register_aliases[] = { | |
141 | /* The architecture manuals specify these ABI-independent names for | |
142 | the GPRs. */ | |
143 | #define R(n) { "r" #n, n } | |
144 | R(0), R(1), R(2), R(3), R(4), R(5), R(6), R(7), | |
145 | R(8), R(9), R(10), R(11), R(12), R(13), R(14), R(15), | |
146 | R(16), R(17), R(18), R(19), R(20), R(21), R(22), R(23), | |
147 | R(24), R(25), R(26), R(27), R(28), R(29), R(30), R(31), | |
148 | #undef R | |
149 | ||
150 | /* k0 and k1 are sometimes called these instead (for "kernel | |
151 | temp"). */ | |
152 | { "kt0", 26 }, | |
153 | { "kt1", 27 }, | |
154 | ||
155 | /* This is the traditional GDB name for the CP0 status register. */ | |
156 | { "sr", MIPS_PS_REGNUM }, | |
157 | ||
158 | /* This is the traditional GDB name for the CP0 BadVAddr register. */ | |
159 | { "bad", MIPS_EMBED_BADVADDR_REGNUM }, | |
160 | ||
161 | /* This is the traditional GDB name for the FCSR. */ | |
162 | { "fsr", MIPS_EMBED_FP0_REGNUM + 32 } | |
163 | }; | |
164 | ||
865093a3 AR |
165 | const struct register_alias mips_numeric_register_aliases[] = { |
166 | #define R(n) { #n, n } | |
167 | R(0), R(1), R(2), R(3), R(4), R(5), R(6), R(7), | |
168 | R(8), R(9), R(10), R(11), R(12), R(13), R(14), R(15), | |
169 | R(16), R(17), R(18), R(19), R(20), R(21), R(22), R(23), | |
170 | R(24), R(25), R(26), R(27), R(28), R(29), R(30), R(31), | |
171 | #undef R | |
172 | }; | |
173 | ||
c906108c SS |
174 | #ifndef MIPS_DEFAULT_FPU_TYPE |
175 | #define MIPS_DEFAULT_FPU_TYPE MIPS_FPU_DOUBLE | |
176 | #endif | |
177 | static int mips_fpu_type_auto = 1; | |
178 | static enum mips_fpu_type mips_fpu_type = MIPS_DEFAULT_FPU_TYPE; | |
7a292a7a | 179 | |
ccce17b0 | 180 | static unsigned int mips_debug = 0; |
7a292a7a | 181 | |
29709017 DJ |
182 | /* Properties (for struct target_desc) describing the g/G packet |
183 | layout. */ | |
184 | #define PROPERTY_GP32 "internal: transfers-32bit-registers" | |
185 | #define PROPERTY_GP64 "internal: transfers-64bit-registers" | |
186 | ||
4eb0ad19 DJ |
187 | struct target_desc *mips_tdesc_gp32; |
188 | struct target_desc *mips_tdesc_gp64; | |
189 | ||
56cea623 AC |
190 | const struct mips_regnum * |
191 | mips_regnum (struct gdbarch *gdbarch) | |
192 | { | |
193 | return gdbarch_tdep (gdbarch)->regnum; | |
194 | } | |
195 | ||
196 | static int | |
197 | mips_fpa0_regnum (struct gdbarch *gdbarch) | |
198 | { | |
199 | return mips_regnum (gdbarch)->fp0 + 12; | |
200 | } | |
201 | ||
004159a2 MR |
202 | /* Return 1 if REGNUM refers to a floating-point general register, raw |
203 | or cooked. Otherwise return 0. */ | |
204 | ||
205 | static int | |
206 | mips_float_register_p (struct gdbarch *gdbarch, int regnum) | |
207 | { | |
208 | int rawnum = regnum % gdbarch_num_regs (gdbarch); | |
209 | ||
210 | return (rawnum >= mips_regnum (gdbarch)->fp0 | |
211 | && rawnum < mips_regnum (gdbarch)->fp0 + 32); | |
212 | } | |
213 | ||
74ed0bb4 MD |
214 | #define MIPS_EABI(gdbarch) (gdbarch_tdep (gdbarch)->mips_abi \ |
215 | == MIPS_ABI_EABI32 \ | |
216 | || gdbarch_tdep (gdbarch)->mips_abi == MIPS_ABI_EABI64) | |
c2d11a7d | 217 | |
025bb325 MS |
218 | #define MIPS_LAST_FP_ARG_REGNUM(gdbarch) \ |
219 | (gdbarch_tdep (gdbarch)->mips_last_fp_arg_regnum) | |
c2d11a7d | 220 | |
025bb325 MS |
221 | #define MIPS_LAST_ARG_REGNUM(gdbarch) \ |
222 | (gdbarch_tdep (gdbarch)->mips_last_arg_regnum) | |
c2d11a7d | 223 | |
74ed0bb4 | 224 | #define MIPS_FPU_TYPE(gdbarch) (gdbarch_tdep (gdbarch)->mips_fpu_type) |
c2d11a7d | 225 | |
d1973055 KB |
226 | /* Return the MIPS ABI associated with GDBARCH. */ |
227 | enum mips_abi | |
228 | mips_abi (struct gdbarch *gdbarch) | |
229 | { | |
230 | return gdbarch_tdep (gdbarch)->mips_abi; | |
231 | } | |
232 | ||
4246e332 | 233 | int |
1b13c4f6 | 234 | mips_isa_regsize (struct gdbarch *gdbarch) |
4246e332 | 235 | { |
29709017 DJ |
236 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
237 | ||
238 | /* If we know how big the registers are, use that size. */ | |
239 | if (tdep->register_size_valid_p) | |
240 | return tdep->register_size; | |
241 | ||
242 | /* Fall back to the previous behavior. */ | |
4246e332 AC |
243 | return (gdbarch_bfd_arch_info (gdbarch)->bits_per_word |
244 | / gdbarch_bfd_arch_info (gdbarch)->bits_per_byte); | |
245 | } | |
246 | ||
025bb325 | 247 | /* Return the currently configured (or set) saved register size. */ |
480d3dd2 | 248 | |
e6bc2e8a | 249 | unsigned int |
13326b4e | 250 | mips_abi_regsize (struct gdbarch *gdbarch) |
d929b26f | 251 | { |
1a69e1e4 DJ |
252 | switch (mips_abi (gdbarch)) |
253 | { | |
254 | case MIPS_ABI_EABI32: | |
255 | case MIPS_ABI_O32: | |
256 | return 4; | |
257 | case MIPS_ABI_N32: | |
258 | case MIPS_ABI_N64: | |
259 | case MIPS_ABI_O64: | |
260 | case MIPS_ABI_EABI64: | |
261 | return 8; | |
262 | case MIPS_ABI_UNKNOWN: | |
263 | case MIPS_ABI_LAST: | |
264 | default: | |
265 | internal_error (__FILE__, __LINE__, _("bad switch")); | |
266 | } | |
d929b26f AC |
267 | } |
268 | ||
4cc0665f MR |
269 | /* MIPS16/microMIPS function addresses are odd (bit 0 is set). Here |
270 | are some functions to handle addresses associated with compressed | |
271 | code including but not limited to testing, setting, or clearing | |
272 | bit 0 of such addresses. */ | |
742c84f6 | 273 | |
4cc0665f MR |
274 | /* Return one iff compressed code is the MIPS16 instruction set. */ |
275 | ||
276 | static int | |
277 | is_mips16_isa (struct gdbarch *gdbarch) | |
278 | { | |
279 | return gdbarch_tdep (gdbarch)->mips_isa == ISA_MIPS16; | |
280 | } | |
281 | ||
282 | /* Return one iff compressed code is the microMIPS instruction set. */ | |
283 | ||
284 | static int | |
285 | is_micromips_isa (struct gdbarch *gdbarch) | |
286 | { | |
287 | return gdbarch_tdep (gdbarch)->mips_isa == ISA_MICROMIPS; | |
288 | } | |
289 | ||
290 | /* Return one iff ADDR denotes compressed code. */ | |
291 | ||
292 | static int | |
293 | is_compact_addr (CORE_ADDR addr) | |
742c84f6 MR |
294 | { |
295 | return ((addr) & 1); | |
296 | } | |
297 | ||
4cc0665f MR |
298 | /* Return one iff ADDR denotes standard ISA code. */ |
299 | ||
300 | static int | |
301 | is_mips_addr (CORE_ADDR addr) | |
302 | { | |
303 | return !is_compact_addr (addr); | |
304 | } | |
305 | ||
306 | /* Return one iff ADDR denotes MIPS16 code. */ | |
307 | ||
308 | static int | |
309 | is_mips16_addr (struct gdbarch *gdbarch, CORE_ADDR addr) | |
310 | { | |
311 | return is_compact_addr (addr) && is_mips16_isa (gdbarch); | |
312 | } | |
313 | ||
314 | /* Return one iff ADDR denotes microMIPS code. */ | |
315 | ||
316 | static int | |
317 | is_micromips_addr (struct gdbarch *gdbarch, CORE_ADDR addr) | |
318 | { | |
319 | return is_compact_addr (addr) && is_micromips_isa (gdbarch); | |
320 | } | |
321 | ||
322 | /* Strip the ISA (compression) bit off from ADDR. */ | |
323 | ||
742c84f6 | 324 | static CORE_ADDR |
4cc0665f | 325 | unmake_compact_addr (CORE_ADDR addr) |
742c84f6 MR |
326 | { |
327 | return ((addr) & ~(CORE_ADDR) 1); | |
328 | } | |
329 | ||
4cc0665f MR |
330 | /* Add the ISA (compression) bit to ADDR. */ |
331 | ||
742c84f6 | 332 | static CORE_ADDR |
4cc0665f | 333 | make_compact_addr (CORE_ADDR addr) |
742c84f6 MR |
334 | { |
335 | return ((addr) | (CORE_ADDR) 1); | |
336 | } | |
337 | ||
71b8ef93 | 338 | /* Functions for setting and testing a bit in a minimal symbol that |
4cc0665f MR |
339 | marks it as MIPS16 or microMIPS function. The MSB of the minimal |
340 | symbol's "info" field is used for this purpose. | |
5a89d8aa | 341 | |
4cc0665f MR |
342 | gdbarch_elf_make_msymbol_special tests whether an ELF symbol is |
343 | "special", i.e. refers to a MIPS16 or microMIPS function, and sets | |
344 | one of the "special" bits in a minimal symbol to mark it accordingly. | |
345 | The test checks an ELF-private flag that is valid for true function | |
1bbce132 MR |
346 | symbols only; for synthetic symbols such as for PLT stubs that have |
347 | no ELF-private part at all the MIPS BFD backend arranges for this | |
348 | information to be carried in the asymbol's udata field instead. | |
5a89d8aa | 349 | |
4cc0665f MR |
350 | msymbol_is_mips16 and msymbol_is_micromips test the "special" bit |
351 | in a minimal symbol. */ | |
5a89d8aa | 352 | |
5a89d8aa | 353 | static void |
6d82d43b AC |
354 | mips_elf_make_msymbol_special (asymbol * sym, struct minimal_symbol *msym) |
355 | { | |
4cc0665f | 356 | elf_symbol_type *elfsym = (elf_symbol_type *) sym; |
1bbce132 | 357 | unsigned char st_other; |
4cc0665f | 358 | |
1bbce132 MR |
359 | if ((sym->flags & BSF_SYNTHETIC) == 0) |
360 | st_other = elfsym->internal_elf_sym.st_other; | |
361 | else if ((sym->flags & BSF_FUNCTION) != 0) | |
362 | st_other = sym->udata.i; | |
363 | else | |
4cc0665f MR |
364 | return; |
365 | ||
1bbce132 | 366 | if (ELF_ST_IS_MICROMIPS (st_other)) |
4cc0665f | 367 | MSYMBOL_TARGET_FLAG_2 (msym) = 1; |
1bbce132 | 368 | else if (ELF_ST_IS_MIPS16 (st_other)) |
4cc0665f MR |
369 | MSYMBOL_TARGET_FLAG_1 (msym) = 1; |
370 | } | |
371 | ||
372 | /* Return one iff MSYM refers to standard ISA code. */ | |
373 | ||
374 | static int | |
375 | msymbol_is_mips (struct minimal_symbol *msym) | |
376 | { | |
377 | return !(MSYMBOL_TARGET_FLAG_1 (msym) | MSYMBOL_TARGET_FLAG_2 (msym)); | |
5a89d8aa MS |
378 | } |
379 | ||
4cc0665f MR |
380 | /* Return one iff MSYM refers to MIPS16 code. */ |
381 | ||
71b8ef93 | 382 | static int |
4cc0665f | 383 | msymbol_is_mips16 (struct minimal_symbol *msym) |
71b8ef93 | 384 | { |
b887350f | 385 | return MSYMBOL_TARGET_FLAG_1 (msym); |
71b8ef93 MS |
386 | } |
387 | ||
4cc0665f MR |
388 | /* Return one iff MSYM refers to microMIPS code. */ |
389 | ||
390 | static int | |
391 | msymbol_is_micromips (struct minimal_symbol *msym) | |
392 | { | |
393 | return MSYMBOL_TARGET_FLAG_2 (msym); | |
394 | } | |
395 | ||
88658117 AC |
396 | /* XFER a value from the big/little/left end of the register. |
397 | Depending on the size of the value it might occupy the entire | |
398 | register or just part of it. Make an allowance for this, aligning | |
399 | things accordingly. */ | |
400 | ||
401 | static void | |
ba32f989 DJ |
402 | mips_xfer_register (struct gdbarch *gdbarch, struct regcache *regcache, |
403 | int reg_num, int length, | |
870cd05e MK |
404 | enum bfd_endian endian, gdb_byte *in, |
405 | const gdb_byte *out, int buf_offset) | |
88658117 | 406 | { |
88658117 | 407 | int reg_offset = 0; |
72a155b4 UW |
408 | |
409 | gdb_assert (reg_num >= gdbarch_num_regs (gdbarch)); | |
cb1d2653 AC |
410 | /* Need to transfer the left or right part of the register, based on |
411 | the targets byte order. */ | |
88658117 AC |
412 | switch (endian) |
413 | { | |
414 | case BFD_ENDIAN_BIG: | |
72a155b4 | 415 | reg_offset = register_size (gdbarch, reg_num) - length; |
88658117 AC |
416 | break; |
417 | case BFD_ENDIAN_LITTLE: | |
418 | reg_offset = 0; | |
419 | break; | |
6d82d43b | 420 | case BFD_ENDIAN_UNKNOWN: /* Indicates no alignment. */ |
88658117 AC |
421 | reg_offset = 0; |
422 | break; | |
423 | default: | |
e2e0b3e5 | 424 | internal_error (__FILE__, __LINE__, _("bad switch")); |
88658117 AC |
425 | } |
426 | if (mips_debug) | |
cb1d2653 AC |
427 | fprintf_unfiltered (gdb_stderr, |
428 | "xfer $%d, reg offset %d, buf offset %d, length %d, ", | |
429 | reg_num, reg_offset, buf_offset, length); | |
88658117 AC |
430 | if (mips_debug && out != NULL) |
431 | { | |
432 | int i; | |
cb1d2653 | 433 | fprintf_unfiltered (gdb_stdlog, "out "); |
88658117 | 434 | for (i = 0; i < length; i++) |
cb1d2653 | 435 | fprintf_unfiltered (gdb_stdlog, "%02x", out[buf_offset + i]); |
88658117 AC |
436 | } |
437 | if (in != NULL) | |
6d82d43b AC |
438 | regcache_cooked_read_part (regcache, reg_num, reg_offset, length, |
439 | in + buf_offset); | |
88658117 | 440 | if (out != NULL) |
6d82d43b AC |
441 | regcache_cooked_write_part (regcache, reg_num, reg_offset, length, |
442 | out + buf_offset); | |
88658117 AC |
443 | if (mips_debug && in != NULL) |
444 | { | |
445 | int i; | |
cb1d2653 | 446 | fprintf_unfiltered (gdb_stdlog, "in "); |
88658117 | 447 | for (i = 0; i < length; i++) |
cb1d2653 | 448 | fprintf_unfiltered (gdb_stdlog, "%02x", in[buf_offset + i]); |
88658117 AC |
449 | } |
450 | if (mips_debug) | |
451 | fprintf_unfiltered (gdb_stdlog, "\n"); | |
452 | } | |
453 | ||
dd824b04 DJ |
454 | /* Determine if a MIPS3 or later cpu is operating in MIPS{1,2} FPU |
455 | compatiblity mode. A return value of 1 means that we have | |
456 | physical 64-bit registers, but should treat them as 32-bit registers. */ | |
457 | ||
458 | static int | |
9c9acae0 | 459 | mips2_fp_compat (struct frame_info *frame) |
dd824b04 | 460 | { |
72a155b4 | 461 | struct gdbarch *gdbarch = get_frame_arch (frame); |
dd824b04 DJ |
462 | /* MIPS1 and MIPS2 have only 32 bit FPRs, and the FR bit is not |
463 | meaningful. */ | |
72a155b4 | 464 | if (register_size (gdbarch, mips_regnum (gdbarch)->fp0) == 4) |
dd824b04 DJ |
465 | return 0; |
466 | ||
467 | #if 0 | |
468 | /* FIXME drow 2002-03-10: This is disabled until we can do it consistently, | |
469 | in all the places we deal with FP registers. PR gdb/413. */ | |
470 | /* Otherwise check the FR bit in the status register - it controls | |
471 | the FP compatiblity mode. If it is clear we are in compatibility | |
472 | mode. */ | |
9c9acae0 | 473 | if ((get_frame_register_unsigned (frame, MIPS_PS_REGNUM) & ST0_FR) == 0) |
dd824b04 DJ |
474 | return 1; |
475 | #endif | |
361d1df0 | 476 | |
dd824b04 DJ |
477 | return 0; |
478 | } | |
479 | ||
7a292a7a | 480 | #define VM_MIN_ADDRESS (CORE_ADDR)0x400000 |
c906108c | 481 | |
74ed0bb4 | 482 | static CORE_ADDR heuristic_proc_start (struct gdbarch *, CORE_ADDR); |
c906108c | 483 | |
a14ed312 | 484 | static void reinit_frame_cache_sfunc (char *, int, struct cmd_list_element *); |
c906108c | 485 | |
025bb325 | 486 | /* The list of available "set mips " and "show mips " commands. */ |
acdb74a0 AC |
487 | |
488 | static struct cmd_list_element *setmipscmdlist = NULL; | |
489 | static struct cmd_list_element *showmipscmdlist = NULL; | |
490 | ||
5e2e9765 KB |
491 | /* Integer registers 0 thru 31 are handled explicitly by |
492 | mips_register_name(). Processor specific registers 32 and above | |
8a9fc081 | 493 | are listed in the following tables. */ |
691c0433 | 494 | |
6d82d43b AC |
495 | enum |
496 | { NUM_MIPS_PROCESSOR_REGS = (90 - 32) }; | |
691c0433 AC |
497 | |
498 | /* Generic MIPS. */ | |
499 | ||
500 | static const char *mips_generic_reg_names[NUM_MIPS_PROCESSOR_REGS] = { | |
6d82d43b AC |
501 | "sr", "lo", "hi", "bad", "cause", "pc", |
502 | "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", | |
503 | "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", | |
504 | "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23", | |
505 | "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", | |
1faeff08 | 506 | "fsr", "fir", |
691c0433 AC |
507 | }; |
508 | ||
509 | /* Names of IDT R3041 registers. */ | |
510 | ||
511 | static const char *mips_r3041_reg_names[] = { | |
6d82d43b AC |
512 | "sr", "lo", "hi", "bad", "cause", "pc", |
513 | "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", | |
514 | "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", | |
515 | "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23", | |
516 | "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", | |
517 | "fsr", "fir", "", /*"fp" */ "", | |
518 | "", "", "bus", "ccfg", "", "", "", "", | |
519 | "", "", "port", "cmp", "", "", "epc", "prid", | |
691c0433 AC |
520 | }; |
521 | ||
522 | /* Names of tx39 registers. */ | |
523 | ||
524 | static const char *mips_tx39_reg_names[NUM_MIPS_PROCESSOR_REGS] = { | |
6d82d43b AC |
525 | "sr", "lo", "hi", "bad", "cause", "pc", |
526 | "", "", "", "", "", "", "", "", | |
527 | "", "", "", "", "", "", "", "", | |
528 | "", "", "", "", "", "", "", "", | |
529 | "", "", "", "", "", "", "", "", | |
530 | "", "", "", "", | |
531 | "", "", "", "", "", "", "", "", | |
1faeff08 | 532 | "", "", "config", "cache", "debug", "depc", "epc", |
691c0433 AC |
533 | }; |
534 | ||
535 | /* Names of IRIX registers. */ | |
536 | static const char *mips_irix_reg_names[NUM_MIPS_PROCESSOR_REGS] = { | |
6d82d43b AC |
537 | "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", |
538 | "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", | |
539 | "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23", | |
540 | "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", | |
541 | "pc", "cause", "bad", "hi", "lo", "fsr", "fir" | |
691c0433 AC |
542 | }; |
543 | ||
44099a67 | 544 | /* Names of registers with Linux kernels. */ |
1faeff08 MR |
545 | static const char *mips_linux_reg_names[NUM_MIPS_PROCESSOR_REGS] = { |
546 | "sr", "lo", "hi", "bad", "cause", "pc", | |
547 | "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", | |
548 | "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", | |
549 | "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23", | |
550 | "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", | |
551 | "fsr", "fir" | |
552 | }; | |
553 | ||
cce74817 | 554 | |
5e2e9765 | 555 | /* Return the name of the register corresponding to REGNO. */ |
5a89d8aa | 556 | static const char * |
d93859e2 | 557 | mips_register_name (struct gdbarch *gdbarch, int regno) |
cce74817 | 558 | { |
d93859e2 | 559 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
5e2e9765 KB |
560 | /* GPR names for all ABIs other than n32/n64. */ |
561 | static char *mips_gpr_names[] = { | |
6d82d43b AC |
562 | "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3", |
563 | "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", | |
564 | "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7", | |
565 | "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra", | |
5e2e9765 KB |
566 | }; |
567 | ||
568 | /* GPR names for n32 and n64 ABIs. */ | |
569 | static char *mips_n32_n64_gpr_names[] = { | |
6d82d43b AC |
570 | "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3", |
571 | "a4", "a5", "a6", "a7", "t0", "t1", "t2", "t3", | |
572 | "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7", | |
573 | "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra" | |
5e2e9765 KB |
574 | }; |
575 | ||
d93859e2 | 576 | enum mips_abi abi = mips_abi (gdbarch); |
5e2e9765 | 577 | |
f57d151a | 578 | /* Map [gdbarch_num_regs .. 2*gdbarch_num_regs) onto the raw registers, |
6229fbea HZ |
579 | but then don't make the raw register names visible. This (upper) |
580 | range of user visible register numbers are the pseudo-registers. | |
581 | ||
582 | This approach was adopted accommodate the following scenario: | |
583 | It is possible to debug a 64-bit device using a 32-bit | |
584 | programming model. In such instances, the raw registers are | |
585 | configured to be 64-bits wide, while the pseudo registers are | |
586 | configured to be 32-bits wide. The registers that the user | |
587 | sees - the pseudo registers - match the users expectations | |
588 | given the programming model being used. */ | |
d93859e2 UW |
589 | int rawnum = regno % gdbarch_num_regs (gdbarch); |
590 | if (regno < gdbarch_num_regs (gdbarch)) | |
a4b8ebc8 AC |
591 | return ""; |
592 | ||
5e2e9765 KB |
593 | /* The MIPS integer registers are always mapped from 0 to 31. The |
594 | names of the registers (which reflects the conventions regarding | |
595 | register use) vary depending on the ABI. */ | |
a4b8ebc8 | 596 | if (0 <= rawnum && rawnum < 32) |
5e2e9765 KB |
597 | { |
598 | if (abi == MIPS_ABI_N32 || abi == MIPS_ABI_N64) | |
a4b8ebc8 | 599 | return mips_n32_n64_gpr_names[rawnum]; |
5e2e9765 | 600 | else |
a4b8ebc8 | 601 | return mips_gpr_names[rawnum]; |
5e2e9765 | 602 | } |
d93859e2 UW |
603 | else if (tdesc_has_registers (gdbarch_target_desc (gdbarch))) |
604 | return tdesc_register_name (gdbarch, rawnum); | |
605 | else if (32 <= rawnum && rawnum < gdbarch_num_regs (gdbarch)) | |
691c0433 AC |
606 | { |
607 | gdb_assert (rawnum - 32 < NUM_MIPS_PROCESSOR_REGS); | |
1faeff08 MR |
608 | if (tdep->mips_processor_reg_names[rawnum - 32]) |
609 | return tdep->mips_processor_reg_names[rawnum - 32]; | |
610 | return ""; | |
691c0433 | 611 | } |
5e2e9765 KB |
612 | else |
613 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 614 | _("mips_register_name: bad register number %d"), rawnum); |
cce74817 | 615 | } |
5e2e9765 | 616 | |
a4b8ebc8 | 617 | /* Return the groups that a MIPS register can be categorised into. */ |
c5aa993b | 618 | |
a4b8ebc8 AC |
619 | static int |
620 | mips_register_reggroup_p (struct gdbarch *gdbarch, int regnum, | |
621 | struct reggroup *reggroup) | |
622 | { | |
623 | int vector_p; | |
624 | int float_p; | |
625 | int raw_p; | |
72a155b4 UW |
626 | int rawnum = regnum % gdbarch_num_regs (gdbarch); |
627 | int pseudo = regnum / gdbarch_num_regs (gdbarch); | |
a4b8ebc8 AC |
628 | if (reggroup == all_reggroup) |
629 | return pseudo; | |
630 | vector_p = TYPE_VECTOR (register_type (gdbarch, regnum)); | |
631 | float_p = TYPE_CODE (register_type (gdbarch, regnum)) == TYPE_CODE_FLT; | |
632 | /* FIXME: cagney/2003-04-13: Can't yet use gdbarch_num_regs | |
633 | (gdbarch), as not all architectures are multi-arch. */ | |
72a155b4 UW |
634 | raw_p = rawnum < gdbarch_num_regs (gdbarch); |
635 | if (gdbarch_register_name (gdbarch, regnum) == NULL | |
636 | || gdbarch_register_name (gdbarch, regnum)[0] == '\0') | |
a4b8ebc8 AC |
637 | return 0; |
638 | if (reggroup == float_reggroup) | |
639 | return float_p && pseudo; | |
640 | if (reggroup == vector_reggroup) | |
641 | return vector_p && pseudo; | |
642 | if (reggroup == general_reggroup) | |
643 | return (!vector_p && !float_p) && pseudo; | |
644 | /* Save the pseudo registers. Need to make certain that any code | |
645 | extracting register values from a saved register cache also uses | |
646 | pseudo registers. */ | |
647 | if (reggroup == save_reggroup) | |
648 | return raw_p && pseudo; | |
649 | /* Restore the same pseudo register. */ | |
650 | if (reggroup == restore_reggroup) | |
651 | return raw_p && pseudo; | |
6d82d43b | 652 | return 0; |
a4b8ebc8 AC |
653 | } |
654 | ||
f8b73d13 DJ |
655 | /* Return the groups that a MIPS register can be categorised into. |
656 | This version is only used if we have a target description which | |
657 | describes real registers (and their groups). */ | |
658 | ||
659 | static int | |
660 | mips_tdesc_register_reggroup_p (struct gdbarch *gdbarch, int regnum, | |
661 | struct reggroup *reggroup) | |
662 | { | |
663 | int rawnum = regnum % gdbarch_num_regs (gdbarch); | |
664 | int pseudo = regnum / gdbarch_num_regs (gdbarch); | |
665 | int ret; | |
666 | ||
667 | /* Only save, restore, and display the pseudo registers. Need to | |
668 | make certain that any code extracting register values from a | |
669 | saved register cache also uses pseudo registers. | |
670 | ||
671 | Note: saving and restoring the pseudo registers is slightly | |
672 | strange; if we have 64 bits, we should save and restore all | |
673 | 64 bits. But this is hard and has little benefit. */ | |
674 | if (!pseudo) | |
675 | return 0; | |
676 | ||
677 | ret = tdesc_register_in_reggroup_p (gdbarch, rawnum, reggroup); | |
678 | if (ret != -1) | |
679 | return ret; | |
680 | ||
681 | return mips_register_reggroup_p (gdbarch, regnum, reggroup); | |
682 | } | |
683 | ||
a4b8ebc8 | 684 | /* Map the symbol table registers which live in the range [1 * |
f57d151a | 685 | gdbarch_num_regs .. 2 * gdbarch_num_regs) back onto the corresponding raw |
47ebcfbe | 686 | registers. Take care of alignment and size problems. */ |
c5aa993b | 687 | |
05d1431c | 688 | static enum register_status |
a4b8ebc8 | 689 | mips_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache, |
47a35522 | 690 | int cookednum, gdb_byte *buf) |
a4b8ebc8 | 691 | { |
72a155b4 UW |
692 | int rawnum = cookednum % gdbarch_num_regs (gdbarch); |
693 | gdb_assert (cookednum >= gdbarch_num_regs (gdbarch) | |
694 | && cookednum < 2 * gdbarch_num_regs (gdbarch)); | |
47ebcfbe | 695 | if (register_size (gdbarch, rawnum) == register_size (gdbarch, cookednum)) |
05d1431c | 696 | return regcache_raw_read (regcache, rawnum, buf); |
6d82d43b AC |
697 | else if (register_size (gdbarch, rawnum) > |
698 | register_size (gdbarch, cookednum)) | |
47ebcfbe | 699 | { |
8bdf35dc | 700 | if (gdbarch_tdep (gdbarch)->mips64_transfers_32bit_regs_p) |
05d1431c | 701 | return regcache_raw_read_part (regcache, rawnum, 0, 4, buf); |
47ebcfbe | 702 | else |
8bdf35dc KB |
703 | { |
704 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); | |
705 | LONGEST regval; | |
05d1431c PA |
706 | enum register_status status; |
707 | ||
708 | status = regcache_raw_read_signed (regcache, rawnum, ®val); | |
709 | if (status == REG_VALID) | |
710 | store_signed_integer (buf, 4, byte_order, regval); | |
711 | return status; | |
8bdf35dc | 712 | } |
47ebcfbe AC |
713 | } |
714 | else | |
e2e0b3e5 | 715 | internal_error (__FILE__, __LINE__, _("bad register size")); |
a4b8ebc8 AC |
716 | } |
717 | ||
718 | static void | |
6d82d43b AC |
719 | mips_pseudo_register_write (struct gdbarch *gdbarch, |
720 | struct regcache *regcache, int cookednum, | |
47a35522 | 721 | const gdb_byte *buf) |
a4b8ebc8 | 722 | { |
72a155b4 UW |
723 | int rawnum = cookednum % gdbarch_num_regs (gdbarch); |
724 | gdb_assert (cookednum >= gdbarch_num_regs (gdbarch) | |
725 | && cookednum < 2 * gdbarch_num_regs (gdbarch)); | |
47ebcfbe | 726 | if (register_size (gdbarch, rawnum) == register_size (gdbarch, cookednum)) |
de38af99 | 727 | regcache_raw_write (regcache, rawnum, buf); |
6d82d43b AC |
728 | else if (register_size (gdbarch, rawnum) > |
729 | register_size (gdbarch, cookednum)) | |
47ebcfbe | 730 | { |
8bdf35dc | 731 | if (gdbarch_tdep (gdbarch)->mips64_transfers_32bit_regs_p) |
47ebcfbe AC |
732 | regcache_raw_write_part (regcache, rawnum, 0, 4, buf); |
733 | else | |
8bdf35dc KB |
734 | { |
735 | /* Sign extend the shortened version of the register prior | |
736 | to placing it in the raw register. This is required for | |
737 | some mips64 parts in order to avoid unpredictable behavior. */ | |
738 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); | |
739 | LONGEST regval = extract_signed_integer (buf, 4, byte_order); | |
740 | regcache_raw_write_signed (regcache, rawnum, regval); | |
741 | } | |
47ebcfbe AC |
742 | } |
743 | else | |
e2e0b3e5 | 744 | internal_error (__FILE__, __LINE__, _("bad register size")); |
a4b8ebc8 | 745 | } |
c5aa993b | 746 | |
175ff332 HZ |
747 | static int |
748 | mips_ax_pseudo_register_collect (struct gdbarch *gdbarch, | |
749 | struct agent_expr *ax, int reg) | |
750 | { | |
751 | int rawnum = reg % gdbarch_num_regs (gdbarch); | |
752 | gdb_assert (reg >= gdbarch_num_regs (gdbarch) | |
753 | && reg < 2 * gdbarch_num_regs (gdbarch)); | |
754 | ||
755 | ax_reg_mask (ax, rawnum); | |
756 | ||
757 | return 0; | |
758 | } | |
759 | ||
760 | static int | |
761 | mips_ax_pseudo_register_push_stack (struct gdbarch *gdbarch, | |
762 | struct agent_expr *ax, int reg) | |
763 | { | |
764 | int rawnum = reg % gdbarch_num_regs (gdbarch); | |
765 | gdb_assert (reg >= gdbarch_num_regs (gdbarch) | |
766 | && reg < 2 * gdbarch_num_regs (gdbarch)); | |
767 | if (register_size (gdbarch, rawnum) >= register_size (gdbarch, reg)) | |
768 | { | |
769 | ax_reg (ax, rawnum); | |
770 | ||
771 | if (register_size (gdbarch, rawnum) > register_size (gdbarch, reg)) | |
772 | { | |
773 | if (!gdbarch_tdep (gdbarch)->mips64_transfers_32bit_regs_p | |
774 | || gdbarch_byte_order (gdbarch) != BFD_ENDIAN_BIG) | |
775 | { | |
776 | ax_const_l (ax, 32); | |
777 | ax_simple (ax, aop_lsh); | |
778 | } | |
779 | ax_const_l (ax, 32); | |
780 | ax_simple (ax, aop_rsh_signed); | |
781 | } | |
782 | } | |
783 | else | |
784 | internal_error (__FILE__, __LINE__, _("bad register size")); | |
785 | ||
786 | return 0; | |
787 | } | |
788 | ||
4cc0665f | 789 | /* Table to translate 3-bit register field to actual register number. */ |
d467df4e | 790 | static const signed char mips_reg3_to_reg[8] = { 16, 17, 2, 3, 4, 5, 6, 7 }; |
c906108c SS |
791 | |
792 | /* Heuristic_proc_start may hunt through the text section for a long | |
793 | time across a 2400 baud serial line. Allows the user to limit this | |
794 | search. */ | |
795 | ||
44096aee | 796 | static int heuristic_fence_post = 0; |
c906108c | 797 | |
46cd78fb | 798 | /* Number of bytes of storage in the actual machine representation for |
719ec221 AC |
799 | register N. NOTE: This defines the pseudo register type so need to |
800 | rebuild the architecture vector. */ | |
43e526b9 JM |
801 | |
802 | static int mips64_transfers_32bit_regs_p = 0; | |
803 | ||
719ec221 AC |
804 | static void |
805 | set_mips64_transfers_32bit_regs (char *args, int from_tty, | |
806 | struct cmd_list_element *c) | |
43e526b9 | 807 | { |
719ec221 AC |
808 | struct gdbarch_info info; |
809 | gdbarch_info_init (&info); | |
810 | /* FIXME: cagney/2003-11-15: Should be setting a field in "info" | |
811 | instead of relying on globals. Doing that would let generic code | |
812 | handle the search for this specific architecture. */ | |
813 | if (!gdbarch_update_p (info)) | |
a4b8ebc8 | 814 | { |
719ec221 | 815 | mips64_transfers_32bit_regs_p = 0; |
8a3fe4f8 | 816 | error (_("32-bit compatibility mode not supported")); |
a4b8ebc8 | 817 | } |
a4b8ebc8 AC |
818 | } |
819 | ||
47ebcfbe | 820 | /* Convert to/from a register and the corresponding memory value. */ |
43e526b9 | 821 | |
ee51a8c7 KB |
822 | /* This predicate tests for the case of an 8 byte floating point |
823 | value that is being transferred to or from a pair of floating point | |
824 | registers each of which are (or are considered to be) only 4 bytes | |
825 | wide. */ | |
ff2e87ac | 826 | static int |
ee51a8c7 KB |
827 | mips_convert_register_float_case_p (struct gdbarch *gdbarch, int regnum, |
828 | struct type *type) | |
ff2e87ac | 829 | { |
0abe36f5 MD |
830 | return (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG |
831 | && register_size (gdbarch, regnum) == 4 | |
004159a2 | 832 | && mips_float_register_p (gdbarch, regnum) |
6d82d43b | 833 | && TYPE_CODE (type) == TYPE_CODE_FLT && TYPE_LENGTH (type) == 8); |
ff2e87ac AC |
834 | } |
835 | ||
ee51a8c7 KB |
836 | /* This predicate tests for the case of a value of less than 8 |
837 | bytes in width that is being transfered to or from an 8 byte | |
838 | general purpose register. */ | |
839 | static int | |
840 | mips_convert_register_gpreg_case_p (struct gdbarch *gdbarch, int regnum, | |
841 | struct type *type) | |
842 | { | |
843 | int num_regs = gdbarch_num_regs (gdbarch); | |
844 | ||
845 | return (register_size (gdbarch, regnum) == 8 | |
846 | && regnum % num_regs > 0 && regnum % num_regs < 32 | |
847 | && TYPE_LENGTH (type) < 8); | |
848 | } | |
849 | ||
850 | static int | |
025bb325 MS |
851 | mips_convert_register_p (struct gdbarch *gdbarch, |
852 | int regnum, struct type *type) | |
ee51a8c7 | 853 | { |
eaa05d59 MR |
854 | return (mips_convert_register_float_case_p (gdbarch, regnum, type) |
855 | || mips_convert_register_gpreg_case_p (gdbarch, regnum, type)); | |
ee51a8c7 KB |
856 | } |
857 | ||
8dccd430 | 858 | static int |
ff2e87ac | 859 | mips_register_to_value (struct frame_info *frame, int regnum, |
8dccd430 PA |
860 | struct type *type, gdb_byte *to, |
861 | int *optimizedp, int *unavailablep) | |
102182a9 | 862 | { |
ee51a8c7 KB |
863 | struct gdbarch *gdbarch = get_frame_arch (frame); |
864 | ||
865 | if (mips_convert_register_float_case_p (gdbarch, regnum, type)) | |
866 | { | |
867 | get_frame_register (frame, regnum + 0, to + 4); | |
868 | get_frame_register (frame, regnum + 1, to + 0); | |
8dccd430 PA |
869 | |
870 | if (!get_frame_register_bytes (frame, regnum + 0, 0, 4, to + 4, | |
871 | optimizedp, unavailablep)) | |
872 | return 0; | |
873 | ||
874 | if (!get_frame_register_bytes (frame, regnum + 1, 0, 4, to + 0, | |
875 | optimizedp, unavailablep)) | |
876 | return 0; | |
877 | *optimizedp = *unavailablep = 0; | |
878 | return 1; | |
ee51a8c7 KB |
879 | } |
880 | else if (mips_convert_register_gpreg_case_p (gdbarch, regnum, type)) | |
881 | { | |
882 | int len = TYPE_LENGTH (type); | |
8dccd430 PA |
883 | CORE_ADDR offset; |
884 | ||
885 | offset = gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG ? 8 - len : 0; | |
886 | if (!get_frame_register_bytes (frame, regnum, offset, len, to, | |
887 | optimizedp, unavailablep)) | |
888 | return 0; | |
889 | ||
890 | *optimizedp = *unavailablep = 0; | |
891 | return 1; | |
ee51a8c7 KB |
892 | } |
893 | else | |
894 | { | |
895 | internal_error (__FILE__, __LINE__, | |
896 | _("mips_register_to_value: unrecognized case")); | |
897 | } | |
102182a9 MS |
898 | } |
899 | ||
42c466d7 | 900 | static void |
ff2e87ac | 901 | mips_value_to_register (struct frame_info *frame, int regnum, |
47a35522 | 902 | struct type *type, const gdb_byte *from) |
102182a9 | 903 | { |
ee51a8c7 KB |
904 | struct gdbarch *gdbarch = get_frame_arch (frame); |
905 | ||
906 | if (mips_convert_register_float_case_p (gdbarch, regnum, type)) | |
907 | { | |
908 | put_frame_register (frame, regnum + 0, from + 4); | |
909 | put_frame_register (frame, regnum + 1, from + 0); | |
910 | } | |
911 | else if (mips_convert_register_gpreg_case_p (gdbarch, regnum, type)) | |
912 | { | |
913 | gdb_byte fill[8]; | |
914 | int len = TYPE_LENGTH (type); | |
915 | ||
916 | /* Sign extend values, irrespective of type, that are stored to | |
917 | a 64-bit general purpose register. (32-bit unsigned values | |
918 | are stored as signed quantities within a 64-bit register. | |
919 | When performing an operation, in compiled code, that combines | |
920 | a 32-bit unsigned value with a signed 64-bit value, a type | |
921 | conversion is first performed that zeroes out the high 32 bits.) */ | |
922 | if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) | |
923 | { | |
924 | if (from[0] & 0x80) | |
925 | store_signed_integer (fill, 8, BFD_ENDIAN_BIG, -1); | |
926 | else | |
927 | store_signed_integer (fill, 8, BFD_ENDIAN_BIG, 0); | |
928 | put_frame_register_bytes (frame, regnum, 0, 8 - len, fill); | |
929 | put_frame_register_bytes (frame, regnum, 8 - len, len, from); | |
930 | } | |
931 | else | |
932 | { | |
933 | if (from[len-1] & 0x80) | |
934 | store_signed_integer (fill, 8, BFD_ENDIAN_LITTLE, -1); | |
935 | else | |
936 | store_signed_integer (fill, 8, BFD_ENDIAN_LITTLE, 0); | |
937 | put_frame_register_bytes (frame, regnum, 0, len, from); | |
938 | put_frame_register_bytes (frame, regnum, len, 8 - len, fill); | |
939 | } | |
940 | } | |
941 | else | |
942 | { | |
943 | internal_error (__FILE__, __LINE__, | |
944 | _("mips_value_to_register: unrecognized case")); | |
945 | } | |
102182a9 MS |
946 | } |
947 | ||
a4b8ebc8 AC |
948 | /* Return the GDB type object for the "standard" data type of data in |
949 | register REG. */ | |
78fde5f8 KB |
950 | |
951 | static struct type * | |
a4b8ebc8 AC |
952 | mips_register_type (struct gdbarch *gdbarch, int regnum) |
953 | { | |
72a155b4 | 954 | gdb_assert (regnum >= 0 && regnum < 2 * gdbarch_num_regs (gdbarch)); |
004159a2 | 955 | if (mips_float_register_p (gdbarch, regnum)) |
a6425924 | 956 | { |
5ef80fb0 | 957 | /* The floating-point registers raw, or cooked, always match |
1b13c4f6 | 958 | mips_isa_regsize(), and also map 1:1, byte for byte. */ |
8da61cc4 | 959 | if (mips_isa_regsize (gdbarch) == 4) |
27067745 | 960 | return builtin_type (gdbarch)->builtin_float; |
8da61cc4 | 961 | else |
27067745 | 962 | return builtin_type (gdbarch)->builtin_double; |
a6425924 | 963 | } |
72a155b4 | 964 | else if (regnum < gdbarch_num_regs (gdbarch)) |
d5ac5a39 AC |
965 | { |
966 | /* The raw or ISA registers. These are all sized according to | |
967 | the ISA regsize. */ | |
968 | if (mips_isa_regsize (gdbarch) == 4) | |
df4df182 | 969 | return builtin_type (gdbarch)->builtin_int32; |
d5ac5a39 | 970 | else |
df4df182 | 971 | return builtin_type (gdbarch)->builtin_int64; |
d5ac5a39 | 972 | } |
78fde5f8 | 973 | else |
d5ac5a39 | 974 | { |
1faeff08 MR |
975 | int rawnum = regnum - gdbarch_num_regs (gdbarch); |
976 | ||
d5ac5a39 AC |
977 | /* The cooked or ABI registers. These are sized according to |
978 | the ABI (with a few complications). */ | |
1faeff08 MR |
979 | if (rawnum == mips_regnum (gdbarch)->fp_control_status |
980 | || rawnum == mips_regnum (gdbarch)->fp_implementation_revision) | |
981 | return builtin_type (gdbarch)->builtin_int32; | |
982 | else if (gdbarch_osabi (gdbarch) != GDB_OSABI_IRIX | |
983 | && gdbarch_osabi (gdbarch) != GDB_OSABI_LINUX | |
984 | && rawnum >= MIPS_FIRST_EMBED_REGNUM | |
985 | && rawnum <= MIPS_LAST_EMBED_REGNUM) | |
d5ac5a39 AC |
986 | /* The pseudo/cooked view of the embedded registers is always |
987 | 32-bit. The raw view is handled below. */ | |
df4df182 | 988 | return builtin_type (gdbarch)->builtin_int32; |
d5ac5a39 AC |
989 | else if (gdbarch_tdep (gdbarch)->mips64_transfers_32bit_regs_p) |
990 | /* The target, while possibly using a 64-bit register buffer, | |
991 | is only transfering 32-bits of each integer register. | |
992 | Reflect this in the cooked/pseudo (ABI) register value. */ | |
df4df182 | 993 | return builtin_type (gdbarch)->builtin_int32; |
d5ac5a39 AC |
994 | else if (mips_abi_regsize (gdbarch) == 4) |
995 | /* The ABI is restricted to 32-bit registers (the ISA could be | |
996 | 32- or 64-bit). */ | |
df4df182 | 997 | return builtin_type (gdbarch)->builtin_int32; |
d5ac5a39 AC |
998 | else |
999 | /* 64-bit ABI. */ | |
df4df182 | 1000 | return builtin_type (gdbarch)->builtin_int64; |
d5ac5a39 | 1001 | } |
78fde5f8 KB |
1002 | } |
1003 | ||
f8b73d13 DJ |
1004 | /* Return the GDB type for the pseudo register REGNUM, which is the |
1005 | ABI-level view. This function is only called if there is a target | |
1006 | description which includes registers, so we know precisely the | |
1007 | types of hardware registers. */ | |
1008 | ||
1009 | static struct type * | |
1010 | mips_pseudo_register_type (struct gdbarch *gdbarch, int regnum) | |
1011 | { | |
1012 | const int num_regs = gdbarch_num_regs (gdbarch); | |
f8b73d13 DJ |
1013 | int rawnum = regnum % num_regs; |
1014 | struct type *rawtype; | |
1015 | ||
1016 | gdb_assert (regnum >= num_regs && regnum < 2 * num_regs); | |
1017 | ||
1018 | /* Absent registers are still absent. */ | |
1019 | rawtype = gdbarch_register_type (gdbarch, rawnum); | |
1020 | if (TYPE_LENGTH (rawtype) == 0) | |
1021 | return rawtype; | |
1022 | ||
de13fcf2 | 1023 | if (mips_float_register_p (gdbarch, rawnum)) |
f8b73d13 DJ |
1024 | /* Present the floating point registers however the hardware did; |
1025 | do not try to convert between FPU layouts. */ | |
1026 | return rawtype; | |
1027 | ||
f8b73d13 DJ |
1028 | /* Use pointer types for registers if we can. For n32 we can not, |
1029 | since we do not have a 64-bit pointer type. */ | |
0dfff4cb UW |
1030 | if (mips_abi_regsize (gdbarch) |
1031 | == TYPE_LENGTH (builtin_type (gdbarch)->builtin_data_ptr)) | |
f8b73d13 | 1032 | { |
1faeff08 MR |
1033 | if (rawnum == MIPS_SP_REGNUM |
1034 | || rawnum == mips_regnum (gdbarch)->badvaddr) | |
0dfff4cb | 1035 | return builtin_type (gdbarch)->builtin_data_ptr; |
1faeff08 | 1036 | else if (rawnum == mips_regnum (gdbarch)->pc) |
0dfff4cb | 1037 | return builtin_type (gdbarch)->builtin_func_ptr; |
f8b73d13 DJ |
1038 | } |
1039 | ||
1040 | if (mips_abi_regsize (gdbarch) == 4 && TYPE_LENGTH (rawtype) == 8 | |
1faeff08 MR |
1041 | && ((rawnum >= MIPS_ZERO_REGNUM && rawnum <= MIPS_PS_REGNUM) |
1042 | || rawnum == mips_regnum (gdbarch)->lo | |
1043 | || rawnum == mips_regnum (gdbarch)->hi | |
1044 | || rawnum == mips_regnum (gdbarch)->badvaddr | |
1045 | || rawnum == mips_regnum (gdbarch)->cause | |
1046 | || rawnum == mips_regnum (gdbarch)->pc | |
1047 | || (mips_regnum (gdbarch)->dspacc != -1 | |
1048 | && rawnum >= mips_regnum (gdbarch)->dspacc | |
1049 | && rawnum < mips_regnum (gdbarch)->dspacc + 6))) | |
df4df182 | 1050 | return builtin_type (gdbarch)->builtin_int32; |
f8b73d13 | 1051 | |
1faeff08 MR |
1052 | if (gdbarch_osabi (gdbarch) != GDB_OSABI_IRIX |
1053 | && gdbarch_osabi (gdbarch) != GDB_OSABI_LINUX | |
1054 | && rawnum >= MIPS_EMBED_FP0_REGNUM + 32 | |
1055 | && rawnum <= MIPS_LAST_EMBED_REGNUM) | |
1056 | { | |
1057 | /* The pseudo/cooked view of embedded registers is always | |
1058 | 32-bit, even if the target transfers 64-bit values for them. | |
1059 | New targets relying on XML descriptions should only transfer | |
1060 | the necessary 32 bits, but older versions of GDB expected 64, | |
1061 | so allow the target to provide 64 bits without interfering | |
1062 | with the displayed type. */ | |
1063 | return builtin_type (gdbarch)->builtin_int32; | |
1064 | } | |
1065 | ||
f8b73d13 DJ |
1066 | /* For all other registers, pass through the hardware type. */ |
1067 | return rawtype; | |
1068 | } | |
bcb0cc15 | 1069 | |
025bb325 | 1070 | /* Should the upper word of 64-bit addresses be zeroed? */ |
7f19b9a2 | 1071 | enum auto_boolean mask_address_var = AUTO_BOOLEAN_AUTO; |
4014092b AC |
1072 | |
1073 | static int | |
480d3dd2 | 1074 | mips_mask_address_p (struct gdbarch_tdep *tdep) |
4014092b AC |
1075 | { |
1076 | switch (mask_address_var) | |
1077 | { | |
7f19b9a2 | 1078 | case AUTO_BOOLEAN_TRUE: |
4014092b | 1079 | return 1; |
7f19b9a2 | 1080 | case AUTO_BOOLEAN_FALSE: |
4014092b AC |
1081 | return 0; |
1082 | break; | |
7f19b9a2 | 1083 | case AUTO_BOOLEAN_AUTO: |
480d3dd2 | 1084 | return tdep->default_mask_address_p; |
4014092b | 1085 | default: |
025bb325 MS |
1086 | internal_error (__FILE__, __LINE__, |
1087 | _("mips_mask_address_p: bad switch")); | |
4014092b | 1088 | return -1; |
361d1df0 | 1089 | } |
4014092b AC |
1090 | } |
1091 | ||
1092 | static void | |
08546159 AC |
1093 | show_mask_address (struct ui_file *file, int from_tty, |
1094 | struct cmd_list_element *c, const char *value) | |
4014092b | 1095 | { |
f5656ead | 1096 | struct gdbarch_tdep *tdep = gdbarch_tdep (target_gdbarch ()); |
08546159 AC |
1097 | |
1098 | deprecated_show_value_hack (file, from_tty, c, value); | |
4014092b AC |
1099 | switch (mask_address_var) |
1100 | { | |
7f19b9a2 | 1101 | case AUTO_BOOLEAN_TRUE: |
4014092b AC |
1102 | printf_filtered ("The 32 bit mips address mask is enabled\n"); |
1103 | break; | |
7f19b9a2 | 1104 | case AUTO_BOOLEAN_FALSE: |
4014092b AC |
1105 | printf_filtered ("The 32 bit mips address mask is disabled\n"); |
1106 | break; | |
7f19b9a2 | 1107 | case AUTO_BOOLEAN_AUTO: |
6d82d43b AC |
1108 | printf_filtered |
1109 | ("The 32 bit address mask is set automatically. Currently %s\n", | |
1110 | mips_mask_address_p (tdep) ? "enabled" : "disabled"); | |
4014092b AC |
1111 | break; |
1112 | default: | |
e2e0b3e5 | 1113 | internal_error (__FILE__, __LINE__, _("show_mask_address: bad switch")); |
4014092b | 1114 | break; |
361d1df0 | 1115 | } |
4014092b | 1116 | } |
c906108c | 1117 | |
4cc0665f MR |
1118 | /* Tell if the program counter value in MEMADDR is in a standard ISA |
1119 | function. */ | |
1120 | ||
1121 | int | |
1122 | mips_pc_is_mips (CORE_ADDR memaddr) | |
1123 | { | |
7cbd4a93 | 1124 | struct bound_minimal_symbol sym; |
4cc0665f MR |
1125 | |
1126 | /* Flags indicating that this is a MIPS16 or microMIPS function is | |
1127 | stored by elfread.c in the high bit of the info field. Use this | |
1128 | to decide if the function is standard MIPS. Otherwise if bit 0 | |
1129 | of the address is clear, then this is a standard MIPS function. */ | |
1130 | sym = lookup_minimal_symbol_by_pc (memaddr); | |
7cbd4a93 TT |
1131 | if (sym.minsym) |
1132 | return msymbol_is_mips (sym.minsym); | |
4cc0665f MR |
1133 | else |
1134 | return is_mips_addr (memaddr); | |
1135 | } | |
1136 | ||
c906108c SS |
1137 | /* Tell if the program counter value in MEMADDR is in a MIPS16 function. */ |
1138 | ||
0fe7e7c8 | 1139 | int |
4cc0665f | 1140 | mips_pc_is_mips16 (struct gdbarch *gdbarch, CORE_ADDR memaddr) |
c906108c | 1141 | { |
7cbd4a93 | 1142 | struct bound_minimal_symbol sym; |
c906108c | 1143 | |
91912e4d MR |
1144 | /* A flag indicating that this is a MIPS16 function is stored by |
1145 | elfread.c in the high bit of the info field. Use this to decide | |
4cc0665f MR |
1146 | if the function is MIPS16. Otherwise if bit 0 of the address is |
1147 | set, then ELF file flags will tell if this is a MIPS16 function. */ | |
1148 | sym = lookup_minimal_symbol_by_pc (memaddr); | |
7cbd4a93 TT |
1149 | if (sym.minsym) |
1150 | return msymbol_is_mips16 (sym.minsym); | |
4cc0665f MR |
1151 | else |
1152 | return is_mips16_addr (gdbarch, memaddr); | |
1153 | } | |
1154 | ||
1155 | /* Tell if the program counter value in MEMADDR is in a microMIPS function. */ | |
1156 | ||
1157 | int | |
1158 | mips_pc_is_micromips (struct gdbarch *gdbarch, CORE_ADDR memaddr) | |
1159 | { | |
7cbd4a93 | 1160 | struct bound_minimal_symbol sym; |
4cc0665f MR |
1161 | |
1162 | /* A flag indicating that this is a microMIPS function is stored by | |
1163 | elfread.c in the high bit of the info field. Use this to decide | |
1164 | if the function is microMIPS. Otherwise if bit 0 of the address | |
1165 | is set, then ELF file flags will tell if this is a microMIPS | |
1166 | function. */ | |
1167 | sym = lookup_minimal_symbol_by_pc (memaddr); | |
7cbd4a93 TT |
1168 | if (sym.minsym) |
1169 | return msymbol_is_micromips (sym.minsym); | |
4cc0665f MR |
1170 | else |
1171 | return is_micromips_addr (gdbarch, memaddr); | |
1172 | } | |
1173 | ||
1174 | /* Tell the ISA type of the function the program counter value in MEMADDR | |
1175 | is in. */ | |
1176 | ||
1177 | static enum mips_isa | |
1178 | mips_pc_isa (struct gdbarch *gdbarch, CORE_ADDR memaddr) | |
1179 | { | |
7cbd4a93 | 1180 | struct bound_minimal_symbol sym; |
4cc0665f MR |
1181 | |
1182 | /* A flag indicating that this is a MIPS16 or a microMIPS function | |
1183 | is stored by elfread.c in the high bit of the info field. Use | |
1184 | this to decide if the function is MIPS16 or microMIPS or normal | |
1185 | MIPS. Otherwise if bit 0 of the address is set, then ELF file | |
1186 | flags will tell if this is a MIPS16 or a microMIPS function. */ | |
c906108c | 1187 | sym = lookup_minimal_symbol_by_pc (memaddr); |
7cbd4a93 | 1188 | if (sym.minsym) |
4cc0665f | 1189 | { |
7cbd4a93 | 1190 | if (msymbol_is_micromips (sym.minsym)) |
4cc0665f | 1191 | return ISA_MICROMIPS; |
7cbd4a93 | 1192 | else if (msymbol_is_mips16 (sym.minsym)) |
4cc0665f MR |
1193 | return ISA_MIPS16; |
1194 | else | |
1195 | return ISA_MIPS; | |
1196 | } | |
c906108c | 1197 | else |
4cc0665f MR |
1198 | { |
1199 | if (is_mips_addr (memaddr)) | |
1200 | return ISA_MIPS; | |
1201 | else if (is_micromips_addr (gdbarch, memaddr)) | |
1202 | return ISA_MICROMIPS; | |
1203 | else | |
1204 | return ISA_MIPS16; | |
1205 | } | |
c906108c SS |
1206 | } |
1207 | ||
14132e89 MR |
1208 | /* Various MIPS16 thunk (aka stub or trampoline) names. */ |
1209 | ||
1210 | static const char mips_str_mips16_call_stub[] = "__mips16_call_stub_"; | |
1211 | static const char mips_str_mips16_ret_stub[] = "__mips16_ret_"; | |
1212 | static const char mips_str_call_fp_stub[] = "__call_stub_fp_"; | |
1213 | static const char mips_str_call_stub[] = "__call_stub_"; | |
1214 | static const char mips_str_fn_stub[] = "__fn_stub_"; | |
1215 | ||
1216 | /* This is used as a PIC thunk prefix. */ | |
1217 | ||
1218 | static const char mips_str_pic[] = ".pic."; | |
1219 | ||
1220 | /* Return non-zero if the PC is inside a call thunk (aka stub or | |
1221 | trampoline) that should be treated as a temporary frame. */ | |
1222 | ||
1223 | static int | |
1224 | mips_in_frame_stub (CORE_ADDR pc) | |
1225 | { | |
1226 | CORE_ADDR start_addr; | |
1227 | const char *name; | |
1228 | ||
1229 | /* Find the starting address of the function containing the PC. */ | |
1230 | if (find_pc_partial_function (pc, &name, &start_addr, NULL) == 0) | |
1231 | return 0; | |
1232 | ||
1233 | /* If the PC is in __mips16_call_stub_*, this is a call/return stub. */ | |
1234 | if (strncmp (name, mips_str_mips16_call_stub, | |
1235 | strlen (mips_str_mips16_call_stub)) == 0) | |
1236 | return 1; | |
1237 | /* If the PC is in __call_stub_*, this is a call/return or a call stub. */ | |
1238 | if (strncmp (name, mips_str_call_stub, strlen (mips_str_call_stub)) == 0) | |
1239 | return 1; | |
1240 | /* If the PC is in __fn_stub_*, this is a call stub. */ | |
1241 | if (strncmp (name, mips_str_fn_stub, strlen (mips_str_fn_stub)) == 0) | |
1242 | return 1; | |
1243 | ||
1244 | return 0; /* Not a stub. */ | |
1245 | } | |
1246 | ||
b2fa5097 | 1247 | /* MIPS believes that the PC has a sign extended value. Perhaps the |
025bb325 | 1248 | all registers should be sign extended for simplicity? */ |
6c997a34 AC |
1249 | |
1250 | static CORE_ADDR | |
61a1198a | 1251 | mips_read_pc (struct regcache *regcache) |
6c997a34 | 1252 | { |
8376de04 | 1253 | int regnum = gdbarch_pc_regnum (get_regcache_arch (regcache)); |
70242eb1 | 1254 | LONGEST pc; |
8376de04 | 1255 | |
61a1198a | 1256 | regcache_cooked_read_signed (regcache, regnum, &pc); |
4cc0665f MR |
1257 | if (is_compact_addr (pc)) |
1258 | pc = unmake_compact_addr (pc); | |
61a1198a | 1259 | return pc; |
b6cb9035 AC |
1260 | } |
1261 | ||
58dfe9ff AC |
1262 | static CORE_ADDR |
1263 | mips_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame) | |
1264 | { | |
14132e89 | 1265 | CORE_ADDR pc; |
930bd0e0 | 1266 | |
8376de04 | 1267 | pc = frame_unwind_register_signed (next_frame, gdbarch_pc_regnum (gdbarch)); |
4cc0665f MR |
1268 | if (is_compact_addr (pc)) |
1269 | pc = unmake_compact_addr (pc); | |
14132e89 MR |
1270 | /* macro/2012-04-20: This hack skips over MIPS16 call thunks as |
1271 | intermediate frames. In this case we can get the caller's address | |
1272 | from $ra, or if $ra contains an address within a thunk as well, then | |
1273 | it must be in the return path of __mips16_call_stub_{s,d}{f,c}_{0..10} | |
1274 | and thus the caller's address is in $s2. */ | |
1275 | if (frame_relative_level (next_frame) >= 0 && mips_in_frame_stub (pc)) | |
1276 | { | |
1277 | pc = frame_unwind_register_signed | |
1278 | (next_frame, gdbarch_num_regs (gdbarch) + MIPS_RA_REGNUM); | |
4cc0665f MR |
1279 | if (is_compact_addr (pc)) |
1280 | pc = unmake_compact_addr (pc); | |
14132e89 MR |
1281 | if (mips_in_frame_stub (pc)) |
1282 | { | |
1283 | pc = frame_unwind_register_signed | |
1284 | (next_frame, gdbarch_num_regs (gdbarch) + MIPS_S2_REGNUM); | |
4cc0665f MR |
1285 | if (is_compact_addr (pc)) |
1286 | pc = unmake_compact_addr (pc); | |
14132e89 MR |
1287 | } |
1288 | } | |
930bd0e0 | 1289 | return pc; |
edfae063 AC |
1290 | } |
1291 | ||
30244cd8 UW |
1292 | static CORE_ADDR |
1293 | mips_unwind_sp (struct gdbarch *gdbarch, struct frame_info *next_frame) | |
1294 | { | |
72a155b4 UW |
1295 | return frame_unwind_register_signed |
1296 | (next_frame, gdbarch_num_regs (gdbarch) + MIPS_SP_REGNUM); | |
30244cd8 UW |
1297 | } |
1298 | ||
b8a22b94 | 1299 | /* Assuming THIS_FRAME is a dummy, return the frame ID of that |
edfae063 AC |
1300 | dummy frame. The frame ID's base needs to match the TOS value |
1301 | saved by save_dummy_frame_tos(), and the PC match the dummy frame's | |
1302 | breakpoint. */ | |
1303 | ||
1304 | static struct frame_id | |
b8a22b94 | 1305 | mips_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame) |
edfae063 | 1306 | { |
f57d151a | 1307 | return frame_id_build |
b8a22b94 DJ |
1308 | (get_frame_register_signed (this_frame, |
1309 | gdbarch_num_regs (gdbarch) | |
1310 | + MIPS_SP_REGNUM), | |
1311 | get_frame_pc (this_frame)); | |
58dfe9ff AC |
1312 | } |
1313 | ||
5a439849 MR |
1314 | /* Implement the "write_pc" gdbarch method. */ |
1315 | ||
1316 | void | |
61a1198a | 1317 | mips_write_pc (struct regcache *regcache, CORE_ADDR pc) |
b6cb9035 | 1318 | { |
8376de04 MR |
1319 | int regnum = gdbarch_pc_regnum (get_regcache_arch (regcache)); |
1320 | ||
4cc0665f | 1321 | if (mips_pc_is_mips (pc)) |
930bd0e0 | 1322 | regcache_cooked_write_unsigned (regcache, regnum, pc); |
4cc0665f MR |
1323 | else |
1324 | regcache_cooked_write_unsigned (regcache, regnum, make_compact_addr (pc)); | |
6c997a34 | 1325 | } |
c906108c | 1326 | |
4cc0665f MR |
1327 | /* Fetch and return instruction from the specified location. Handle |
1328 | MIPS16/microMIPS as appropriate. */ | |
c906108c | 1329 | |
d37cca3d | 1330 | static ULONGEST |
4cc0665f MR |
1331 | mips_fetch_instruction (struct gdbarch *gdbarch, |
1332 | enum mips_isa isa, CORE_ADDR addr, int *statusp) | |
c906108c | 1333 | { |
e17a4113 | 1334 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
47a35522 | 1335 | gdb_byte buf[MIPS_INSN32_SIZE]; |
c906108c SS |
1336 | int instlen; |
1337 | int status; | |
1338 | ||
4cc0665f | 1339 | switch (isa) |
c906108c | 1340 | { |
4cc0665f MR |
1341 | case ISA_MICROMIPS: |
1342 | case ISA_MIPS16: | |
95ac2dcf | 1343 | instlen = MIPS_INSN16_SIZE; |
4cc0665f MR |
1344 | addr = unmake_compact_addr (addr); |
1345 | break; | |
1346 | case ISA_MIPS: | |
1347 | instlen = MIPS_INSN32_SIZE; | |
1348 | break; | |
1349 | default: | |
1350 | internal_error (__FILE__, __LINE__, _("invalid ISA")); | |
1351 | break; | |
c906108c | 1352 | } |
8defab1a | 1353 | status = target_read_memory (addr, buf, instlen); |
4cc0665f MR |
1354 | if (statusp != NULL) |
1355 | *statusp = status; | |
c906108c | 1356 | if (status) |
4cc0665f MR |
1357 | { |
1358 | if (statusp == NULL) | |
1359 | memory_error (status, addr); | |
1360 | return 0; | |
1361 | } | |
e17a4113 | 1362 | return extract_unsigned_integer (buf, instlen, byte_order); |
c906108c SS |
1363 | } |
1364 | ||
025bb325 | 1365 | /* These are the fields of 32 bit mips instructions. */ |
e135b889 DJ |
1366 | #define mips32_op(x) (x >> 26) |
1367 | #define itype_op(x) (x >> 26) | |
1368 | #define itype_rs(x) ((x >> 21) & 0x1f) | |
c906108c | 1369 | #define itype_rt(x) ((x >> 16) & 0x1f) |
e135b889 | 1370 | #define itype_immediate(x) (x & 0xffff) |
c906108c | 1371 | |
e135b889 DJ |
1372 | #define jtype_op(x) (x >> 26) |
1373 | #define jtype_target(x) (x & 0x03ffffff) | |
c906108c | 1374 | |
e135b889 DJ |
1375 | #define rtype_op(x) (x >> 26) |
1376 | #define rtype_rs(x) ((x >> 21) & 0x1f) | |
1377 | #define rtype_rt(x) ((x >> 16) & 0x1f) | |
1378 | #define rtype_rd(x) ((x >> 11) & 0x1f) | |
1379 | #define rtype_shamt(x) ((x >> 6) & 0x1f) | |
1380 | #define rtype_funct(x) (x & 0x3f) | |
c906108c | 1381 | |
4cc0665f MR |
1382 | /* MicroMIPS instruction fields. */ |
1383 | #define micromips_op(x) ((x) >> 10) | |
1384 | ||
1385 | /* 16-bit/32-bit-high-part instruction formats, B and S refer to the lowest | |
1386 | bit and the size respectively of the field extracted. */ | |
1387 | #define b0s4_imm(x) ((x) & 0xf) | |
1388 | #define b0s5_imm(x) ((x) & 0x1f) | |
1389 | #define b0s5_reg(x) ((x) & 0x1f) | |
1390 | #define b0s7_imm(x) ((x) & 0x7f) | |
1391 | #define b0s10_imm(x) ((x) & 0x3ff) | |
1392 | #define b1s4_imm(x) (((x) >> 1) & 0xf) | |
1393 | #define b1s9_imm(x) (((x) >> 1) & 0x1ff) | |
1394 | #define b2s3_cc(x) (((x) >> 2) & 0x7) | |
1395 | #define b4s2_regl(x) (((x) >> 4) & 0x3) | |
1396 | #define b5s5_op(x) (((x) >> 5) & 0x1f) | |
1397 | #define b5s5_reg(x) (((x) >> 5) & 0x1f) | |
1398 | #define b6s4_op(x) (((x) >> 6) & 0xf) | |
1399 | #define b7s3_reg(x) (((x) >> 7) & 0x7) | |
1400 | ||
1401 | /* 32-bit instruction formats, B and S refer to the lowest bit and the size | |
1402 | respectively of the field extracted. */ | |
1403 | #define b0s6_op(x) ((x) & 0x3f) | |
1404 | #define b0s11_op(x) ((x) & 0x7ff) | |
1405 | #define b0s12_imm(x) ((x) & 0xfff) | |
1406 | #define b0s16_imm(x) ((x) & 0xffff) | |
1407 | #define b0s26_imm(x) ((x) & 0x3ffffff) | |
1408 | #define b6s10_ext(x) (((x) >> 6) & 0x3ff) | |
1409 | #define b11s5_reg(x) (((x) >> 11) & 0x1f) | |
1410 | #define b12s4_op(x) (((x) >> 12) & 0xf) | |
1411 | ||
1412 | /* Return the size in bytes of the instruction INSN encoded in the ISA | |
1413 | instruction set. */ | |
1414 | ||
1415 | static int | |
1416 | mips_insn_size (enum mips_isa isa, ULONGEST insn) | |
1417 | { | |
1418 | switch (isa) | |
1419 | { | |
1420 | case ISA_MICROMIPS: | |
1421 | if (micromips_op (insn) == 0x1f) | |
1422 | return 3 * MIPS_INSN16_SIZE; | |
1423 | else if (((micromips_op (insn) & 0x4) == 0x4) | |
1424 | || ((micromips_op (insn) & 0x7) == 0x0)) | |
1425 | return 2 * MIPS_INSN16_SIZE; | |
1426 | else | |
1427 | return MIPS_INSN16_SIZE; | |
1428 | case ISA_MIPS16: | |
1429 | if ((insn & 0xf800) == 0xf000) | |
1430 | return 2 * MIPS_INSN16_SIZE; | |
1431 | else | |
1432 | return MIPS_INSN16_SIZE; | |
1433 | case ISA_MIPS: | |
1434 | return MIPS_INSN32_SIZE; | |
1435 | } | |
1436 | internal_error (__FILE__, __LINE__, _("invalid ISA")); | |
1437 | } | |
1438 | ||
06987e64 MK |
1439 | static LONGEST |
1440 | mips32_relative_offset (ULONGEST inst) | |
c5aa993b | 1441 | { |
06987e64 | 1442 | return ((itype_immediate (inst) ^ 0x8000) - 0x8000) << 2; |
c906108c SS |
1443 | } |
1444 | ||
a385295e MR |
1445 | /* Determine the address of the next instruction executed after the INST |
1446 | floating condition branch instruction at PC. COUNT specifies the | |
1447 | number of the floating condition bits tested by the branch. */ | |
1448 | ||
1449 | static CORE_ADDR | |
1450 | mips32_bc1_pc (struct gdbarch *gdbarch, struct frame_info *frame, | |
1451 | ULONGEST inst, CORE_ADDR pc, int count) | |
1452 | { | |
1453 | int fcsr = mips_regnum (gdbarch)->fp_control_status; | |
1454 | int cnum = (itype_rt (inst) >> 2) & (count - 1); | |
1455 | int tf = itype_rt (inst) & 1; | |
1456 | int mask = (1 << count) - 1; | |
1457 | ULONGEST fcs; | |
1458 | int cond; | |
1459 | ||
1460 | if (fcsr == -1) | |
1461 | /* No way to handle; it'll most likely trap anyway. */ | |
1462 | return pc; | |
1463 | ||
1464 | fcs = get_frame_register_unsigned (frame, fcsr); | |
1465 | cond = ((fcs >> 24) & 0xfe) | ((fcs >> 23) & 0x01); | |
1466 | ||
1467 | if (((cond >> cnum) & mask) != mask * !tf) | |
1468 | pc += mips32_relative_offset (inst); | |
1469 | else | |
1470 | pc += 4; | |
1471 | ||
1472 | return pc; | |
1473 | } | |
1474 | ||
f94363d7 AP |
1475 | /* Return nonzero if the gdbarch is an Octeon series. */ |
1476 | ||
1477 | static int | |
1478 | is_octeon (struct gdbarch *gdbarch) | |
1479 | { | |
1480 | const struct bfd_arch_info *info = gdbarch_bfd_arch_info (gdbarch); | |
1481 | ||
1482 | return (info->mach == bfd_mach_mips_octeon | |
1483 | || info->mach == bfd_mach_mips_octeonp | |
1484 | || info->mach == bfd_mach_mips_octeon2); | |
1485 | } | |
1486 | ||
1487 | /* Return true if the OP represents the Octeon's BBIT instruction. */ | |
1488 | ||
1489 | static int | |
1490 | is_octeon_bbit_op (int op, struct gdbarch *gdbarch) | |
1491 | { | |
1492 | if (!is_octeon (gdbarch)) | |
1493 | return 0; | |
1494 | /* BBIT0 is encoded as LWC2: 110 010. */ | |
1495 | /* BBIT032 is encoded as LDC2: 110 110. */ | |
1496 | /* BBIT1 is encoded as SWC2: 111 010. */ | |
1497 | /* BBIT132 is encoded as SDC2: 111 110. */ | |
1498 | if (op == 50 || op == 54 || op == 58 || op == 62) | |
1499 | return 1; | |
1500 | return 0; | |
1501 | } | |
1502 | ||
1503 | ||
f49e4e6d MS |
1504 | /* Determine where to set a single step breakpoint while considering |
1505 | branch prediction. */ | |
78a59c2f | 1506 | |
5a89d8aa | 1507 | static CORE_ADDR |
0b1b3e42 | 1508 | mips32_next_pc (struct frame_info *frame, CORE_ADDR pc) |
c5aa993b | 1509 | { |
e17a4113 | 1510 | struct gdbarch *gdbarch = get_frame_arch (frame); |
c5aa993b JM |
1511 | unsigned long inst; |
1512 | int op; | |
4cc0665f | 1513 | inst = mips_fetch_instruction (gdbarch, ISA_MIPS, pc, NULL); |
4f5bcb50 | 1514 | op = itype_op (inst); |
025bb325 MS |
1515 | if ((inst & 0xe0000000) != 0) /* Not a special, jump or branch |
1516 | instruction. */ | |
c5aa993b | 1517 | { |
4f5bcb50 | 1518 | if (op >> 2 == 5) |
6d82d43b | 1519 | /* BEQL, BNEL, BLEZL, BGTZL: bits 0101xx */ |
c5aa993b | 1520 | { |
4f5bcb50 | 1521 | switch (op & 0x03) |
c906108c | 1522 | { |
e135b889 DJ |
1523 | case 0: /* BEQL */ |
1524 | goto equal_branch; | |
1525 | case 1: /* BNEL */ | |
1526 | goto neq_branch; | |
1527 | case 2: /* BLEZL */ | |
1528 | goto less_branch; | |
313628cc | 1529 | case 3: /* BGTZL */ |
e135b889 | 1530 | goto greater_branch; |
c5aa993b JM |
1531 | default: |
1532 | pc += 4; | |
c906108c SS |
1533 | } |
1534 | } | |
4f5bcb50 | 1535 | else if (op == 17 && itype_rs (inst) == 8) |
6d82d43b | 1536 | /* BC1F, BC1FL, BC1T, BC1TL: 010001 01000 */ |
a385295e | 1537 | pc = mips32_bc1_pc (gdbarch, frame, inst, pc + 4, 1); |
4f5bcb50 | 1538 | else if (op == 17 && itype_rs (inst) == 9 |
a385295e MR |
1539 | && (itype_rt (inst) & 2) == 0) |
1540 | /* BC1ANY2F, BC1ANY2T: 010001 01001 xxx0x */ | |
1541 | pc = mips32_bc1_pc (gdbarch, frame, inst, pc + 4, 2); | |
4f5bcb50 | 1542 | else if (op == 17 && itype_rs (inst) == 10 |
a385295e MR |
1543 | && (itype_rt (inst) & 2) == 0) |
1544 | /* BC1ANY4F, BC1ANY4T: 010001 01010 xxx0x */ | |
1545 | pc = mips32_bc1_pc (gdbarch, frame, inst, pc + 4, 4); | |
4f5bcb50 | 1546 | else if (op == 29) |
9e8da49c MR |
1547 | /* JALX: 011101 */ |
1548 | /* The new PC will be alternate mode. */ | |
1549 | { | |
1550 | unsigned long reg; | |
1551 | ||
1552 | reg = jtype_target (inst) << 2; | |
1553 | /* Add 1 to indicate 16-bit mode -- invert ISA mode. */ | |
1554 | pc = ((pc + 4) & ~(CORE_ADDR) 0x0fffffff) + reg + 1; | |
1555 | } | |
f94363d7 AP |
1556 | else if (is_octeon_bbit_op (op, gdbarch)) |
1557 | { | |
1558 | int bit, branch_if; | |
1559 | ||
1560 | branch_if = op == 58 || op == 62; | |
1561 | bit = itype_rt (inst); | |
1562 | ||
1563 | /* Take into account the *32 instructions. */ | |
1564 | if (op == 54 || op == 62) | |
1565 | bit += 32; | |
1566 | ||
1567 | if (((get_frame_register_signed (frame, | |
1568 | itype_rs (inst)) >> bit) & 1) | |
1569 | == branch_if) | |
1570 | pc += mips32_relative_offset (inst) + 4; | |
1571 | else | |
1572 | pc += 8; /* After the delay slot. */ | |
1573 | } | |
1574 | ||
c5aa993b | 1575 | else |
025bb325 | 1576 | pc += 4; /* Not a branch, next instruction is easy. */ |
c906108c SS |
1577 | } |
1578 | else | |
025bb325 | 1579 | { /* This gets way messy. */ |
c5aa993b | 1580 | |
025bb325 | 1581 | /* Further subdivide into SPECIAL, REGIMM and other. */ |
4f5bcb50 | 1582 | switch (op & 0x07) /* Extract bits 28,27,26. */ |
c906108c | 1583 | { |
c5aa993b JM |
1584 | case 0: /* SPECIAL */ |
1585 | op = rtype_funct (inst); | |
1586 | switch (op) | |
1587 | { | |
1588 | case 8: /* JR */ | |
1589 | case 9: /* JALR */ | |
025bb325 | 1590 | /* Set PC to that address. */ |
0b1b3e42 | 1591 | pc = get_frame_register_signed (frame, rtype_rs (inst)); |
c5aa993b | 1592 | break; |
e38d4e1a DJ |
1593 | case 12: /* SYSCALL */ |
1594 | { | |
1595 | struct gdbarch_tdep *tdep; | |
1596 | ||
1597 | tdep = gdbarch_tdep (get_frame_arch (frame)); | |
1598 | if (tdep->syscall_next_pc != NULL) | |
1599 | pc = tdep->syscall_next_pc (frame); | |
1600 | else | |
1601 | pc += 4; | |
1602 | } | |
1603 | break; | |
c5aa993b JM |
1604 | default: |
1605 | pc += 4; | |
1606 | } | |
1607 | ||
6d82d43b | 1608 | break; /* end SPECIAL */ |
025bb325 | 1609 | case 1: /* REGIMM */ |
c906108c | 1610 | { |
e135b889 DJ |
1611 | op = itype_rt (inst); /* branch condition */ |
1612 | switch (op) | |
c906108c | 1613 | { |
c5aa993b | 1614 | case 0: /* BLTZ */ |
e135b889 DJ |
1615 | case 2: /* BLTZL */ |
1616 | case 16: /* BLTZAL */ | |
c5aa993b | 1617 | case 18: /* BLTZALL */ |
c906108c | 1618 | less_branch: |
0b1b3e42 | 1619 | if (get_frame_register_signed (frame, itype_rs (inst)) < 0) |
c5aa993b JM |
1620 | pc += mips32_relative_offset (inst) + 4; |
1621 | else | |
1622 | pc += 8; /* after the delay slot */ | |
1623 | break; | |
e135b889 | 1624 | case 1: /* BGEZ */ |
c5aa993b JM |
1625 | case 3: /* BGEZL */ |
1626 | case 17: /* BGEZAL */ | |
1627 | case 19: /* BGEZALL */ | |
0b1b3e42 | 1628 | if (get_frame_register_signed (frame, itype_rs (inst)) >= 0) |
c5aa993b JM |
1629 | pc += mips32_relative_offset (inst) + 4; |
1630 | else | |
1631 | pc += 8; /* after the delay slot */ | |
1632 | break; | |
a385295e MR |
1633 | case 0x1c: /* BPOSGE32 */ |
1634 | case 0x1e: /* BPOSGE64 */ | |
1635 | pc += 4; | |
1636 | if (itype_rs (inst) == 0) | |
1637 | { | |
1638 | unsigned int pos = (op & 2) ? 64 : 32; | |
1639 | int dspctl = mips_regnum (gdbarch)->dspctl; | |
1640 | ||
1641 | if (dspctl == -1) | |
1642 | /* No way to handle; it'll most likely trap anyway. */ | |
1643 | break; | |
1644 | ||
1645 | if ((get_frame_register_unsigned (frame, | |
1646 | dspctl) & 0x7f) >= pos) | |
1647 | pc += mips32_relative_offset (inst); | |
1648 | else | |
1649 | pc += 4; | |
1650 | } | |
1651 | break; | |
e135b889 | 1652 | /* All of the other instructions in the REGIMM category */ |
c5aa993b JM |
1653 | default: |
1654 | pc += 4; | |
c906108c SS |
1655 | } |
1656 | } | |
6d82d43b | 1657 | break; /* end REGIMM */ |
c5aa993b JM |
1658 | case 2: /* J */ |
1659 | case 3: /* JAL */ | |
1660 | { | |
1661 | unsigned long reg; | |
1662 | reg = jtype_target (inst) << 2; | |
025bb325 | 1663 | /* Upper four bits get never changed... */ |
5b652102 | 1664 | pc = reg + ((pc + 4) & ~(CORE_ADDR) 0x0fffffff); |
c906108c | 1665 | } |
c5aa993b | 1666 | break; |
e135b889 | 1667 | case 4: /* BEQ, BEQL */ |
c5aa993b | 1668 | equal_branch: |
0b1b3e42 UW |
1669 | if (get_frame_register_signed (frame, itype_rs (inst)) == |
1670 | get_frame_register_signed (frame, itype_rt (inst))) | |
c5aa993b JM |
1671 | pc += mips32_relative_offset (inst) + 4; |
1672 | else | |
1673 | pc += 8; | |
1674 | break; | |
e135b889 | 1675 | case 5: /* BNE, BNEL */ |
c5aa993b | 1676 | neq_branch: |
0b1b3e42 UW |
1677 | if (get_frame_register_signed (frame, itype_rs (inst)) != |
1678 | get_frame_register_signed (frame, itype_rt (inst))) | |
c5aa993b JM |
1679 | pc += mips32_relative_offset (inst) + 4; |
1680 | else | |
1681 | pc += 8; | |
1682 | break; | |
e135b889 | 1683 | case 6: /* BLEZ, BLEZL */ |
0b1b3e42 | 1684 | if (get_frame_register_signed (frame, itype_rs (inst)) <= 0) |
c5aa993b JM |
1685 | pc += mips32_relative_offset (inst) + 4; |
1686 | else | |
1687 | pc += 8; | |
1688 | break; | |
1689 | case 7: | |
e135b889 DJ |
1690 | default: |
1691 | greater_branch: /* BGTZ, BGTZL */ | |
0b1b3e42 | 1692 | if (get_frame_register_signed (frame, itype_rs (inst)) > 0) |
c5aa993b JM |
1693 | pc += mips32_relative_offset (inst) + 4; |
1694 | else | |
1695 | pc += 8; | |
1696 | break; | |
c5aa993b JM |
1697 | } /* switch */ |
1698 | } /* else */ | |
1699 | return pc; | |
1700 | } /* mips32_next_pc */ | |
c906108c | 1701 | |
4cc0665f MR |
1702 | /* Extract the 7-bit signed immediate offset from the microMIPS instruction |
1703 | INSN. */ | |
1704 | ||
1705 | static LONGEST | |
1706 | micromips_relative_offset7 (ULONGEST insn) | |
1707 | { | |
1708 | return ((b0s7_imm (insn) ^ 0x40) - 0x40) << 1; | |
1709 | } | |
1710 | ||
1711 | /* Extract the 10-bit signed immediate offset from the microMIPS instruction | |
1712 | INSN. */ | |
1713 | ||
1714 | static LONGEST | |
1715 | micromips_relative_offset10 (ULONGEST insn) | |
1716 | { | |
1717 | return ((b0s10_imm (insn) ^ 0x200) - 0x200) << 1; | |
1718 | } | |
1719 | ||
1720 | /* Extract the 16-bit signed immediate offset from the microMIPS instruction | |
1721 | INSN. */ | |
1722 | ||
1723 | static LONGEST | |
1724 | micromips_relative_offset16 (ULONGEST insn) | |
1725 | { | |
1726 | return ((b0s16_imm (insn) ^ 0x8000) - 0x8000) << 1; | |
1727 | } | |
1728 | ||
1729 | /* Return the size in bytes of the microMIPS instruction at the address PC. */ | |
1730 | ||
1731 | static int | |
1732 | micromips_pc_insn_size (struct gdbarch *gdbarch, CORE_ADDR pc) | |
1733 | { | |
1734 | ULONGEST insn; | |
1735 | ||
1736 | insn = mips_fetch_instruction (gdbarch, ISA_MICROMIPS, pc, NULL); | |
1737 | return mips_insn_size (ISA_MICROMIPS, insn); | |
1738 | } | |
1739 | ||
1740 | /* Calculate the address of the next microMIPS instruction to execute | |
1741 | after the INSN coprocessor 1 conditional branch instruction at the | |
1742 | address PC. COUNT denotes the number of coprocessor condition bits | |
1743 | examined by the branch. */ | |
1744 | ||
1745 | static CORE_ADDR | |
1746 | micromips_bc1_pc (struct gdbarch *gdbarch, struct frame_info *frame, | |
1747 | ULONGEST insn, CORE_ADDR pc, int count) | |
1748 | { | |
1749 | int fcsr = mips_regnum (gdbarch)->fp_control_status; | |
1750 | int cnum = b2s3_cc (insn >> 16) & (count - 1); | |
1751 | int tf = b5s5_op (insn >> 16) & 1; | |
1752 | int mask = (1 << count) - 1; | |
1753 | ULONGEST fcs; | |
1754 | int cond; | |
1755 | ||
1756 | if (fcsr == -1) | |
1757 | /* No way to handle; it'll most likely trap anyway. */ | |
1758 | return pc; | |
1759 | ||
1760 | fcs = get_frame_register_unsigned (frame, fcsr); | |
1761 | cond = ((fcs >> 24) & 0xfe) | ((fcs >> 23) & 0x01); | |
1762 | ||
1763 | if (((cond >> cnum) & mask) != mask * !tf) | |
1764 | pc += micromips_relative_offset16 (insn); | |
1765 | else | |
1766 | pc += micromips_pc_insn_size (gdbarch, pc); | |
1767 | ||
1768 | return pc; | |
1769 | } | |
1770 | ||
1771 | /* Calculate the address of the next microMIPS instruction to execute | |
1772 | after the instruction at the address PC. */ | |
1773 | ||
1774 | static CORE_ADDR | |
1775 | micromips_next_pc (struct frame_info *frame, CORE_ADDR pc) | |
1776 | { | |
1777 | struct gdbarch *gdbarch = get_frame_arch (frame); | |
1778 | ULONGEST insn; | |
1779 | ||
1780 | insn = mips_fetch_instruction (gdbarch, ISA_MICROMIPS, pc, NULL); | |
1781 | pc += MIPS_INSN16_SIZE; | |
1782 | switch (mips_insn_size (ISA_MICROMIPS, insn)) | |
1783 | { | |
1784 | /* 48-bit instructions. */ | |
1785 | case 3 * MIPS_INSN16_SIZE: /* POOL48A: bits 011111 */ | |
1786 | /* No branch or jump instructions in this category. */ | |
1787 | pc += 2 * MIPS_INSN16_SIZE; | |
1788 | break; | |
1789 | ||
1790 | /* 32-bit instructions. */ | |
1791 | case 2 * MIPS_INSN16_SIZE: | |
1792 | insn <<= 16; | |
1793 | insn |= mips_fetch_instruction (gdbarch, ISA_MICROMIPS, pc, NULL); | |
1794 | pc += MIPS_INSN16_SIZE; | |
1795 | switch (micromips_op (insn >> 16)) | |
1796 | { | |
1797 | case 0x00: /* POOL32A: bits 000000 */ | |
1798 | if (b0s6_op (insn) == 0x3c | |
1799 | /* POOL32Axf: bits 000000 ... 111100 */ | |
1800 | && (b6s10_ext (insn) & 0x2bf) == 0x3c) | |
1801 | /* JALR, JALR.HB: 000000 000x111100 111100 */ | |
1802 | /* JALRS, JALRS.HB: 000000 010x111100 111100 */ | |
1803 | pc = get_frame_register_signed (frame, b0s5_reg (insn >> 16)); | |
1804 | break; | |
1805 | ||
1806 | case 0x10: /* POOL32I: bits 010000 */ | |
1807 | switch (b5s5_op (insn >> 16)) | |
1808 | { | |
1809 | case 0x00: /* BLTZ: bits 010000 00000 */ | |
1810 | case 0x01: /* BLTZAL: bits 010000 00001 */ | |
1811 | case 0x11: /* BLTZALS: bits 010000 10001 */ | |
1812 | if (get_frame_register_signed (frame, | |
1813 | b0s5_reg (insn >> 16)) < 0) | |
1814 | pc += micromips_relative_offset16 (insn); | |
1815 | else | |
1816 | pc += micromips_pc_insn_size (gdbarch, pc); | |
1817 | break; | |
1818 | ||
1819 | case 0x02: /* BGEZ: bits 010000 00010 */ | |
1820 | case 0x03: /* BGEZAL: bits 010000 00011 */ | |
1821 | case 0x13: /* BGEZALS: bits 010000 10011 */ | |
1822 | if (get_frame_register_signed (frame, | |
1823 | b0s5_reg (insn >> 16)) >= 0) | |
1824 | pc += micromips_relative_offset16 (insn); | |
1825 | else | |
1826 | pc += micromips_pc_insn_size (gdbarch, pc); | |
1827 | break; | |
1828 | ||
1829 | case 0x04: /* BLEZ: bits 010000 00100 */ | |
1830 | if (get_frame_register_signed (frame, | |
1831 | b0s5_reg (insn >> 16)) <= 0) | |
1832 | pc += micromips_relative_offset16 (insn); | |
1833 | else | |
1834 | pc += micromips_pc_insn_size (gdbarch, pc); | |
1835 | break; | |
1836 | ||
1837 | case 0x05: /* BNEZC: bits 010000 00101 */ | |
1838 | if (get_frame_register_signed (frame, | |
1839 | b0s5_reg (insn >> 16)) != 0) | |
1840 | pc += micromips_relative_offset16 (insn); | |
1841 | break; | |
1842 | ||
1843 | case 0x06: /* BGTZ: bits 010000 00110 */ | |
1844 | if (get_frame_register_signed (frame, | |
1845 | b0s5_reg (insn >> 16)) > 0) | |
1846 | pc += micromips_relative_offset16 (insn); | |
1847 | else | |
1848 | pc += micromips_pc_insn_size (gdbarch, pc); | |
1849 | break; | |
1850 | ||
1851 | case 0x07: /* BEQZC: bits 010000 00111 */ | |
1852 | if (get_frame_register_signed (frame, | |
1853 | b0s5_reg (insn >> 16)) == 0) | |
1854 | pc += micromips_relative_offset16 (insn); | |
1855 | break; | |
1856 | ||
1857 | case 0x14: /* BC2F: bits 010000 10100 xxx00 */ | |
1858 | case 0x15: /* BC2T: bits 010000 10101 xxx00 */ | |
1859 | if (((insn >> 16) & 0x3) == 0x0) | |
1860 | /* BC2F, BC2T: don't know how to handle these. */ | |
1861 | break; | |
1862 | break; | |
1863 | ||
1864 | case 0x1a: /* BPOSGE64: bits 010000 11010 */ | |
1865 | case 0x1b: /* BPOSGE32: bits 010000 11011 */ | |
1866 | { | |
1867 | unsigned int pos = (b5s5_op (insn >> 16) & 1) ? 32 : 64; | |
1868 | int dspctl = mips_regnum (gdbarch)->dspctl; | |
1869 | ||
1870 | if (dspctl == -1) | |
1871 | /* No way to handle; it'll most likely trap anyway. */ | |
1872 | break; | |
1873 | ||
1874 | if ((get_frame_register_unsigned (frame, | |
1875 | dspctl) & 0x7f) >= pos) | |
1876 | pc += micromips_relative_offset16 (insn); | |
1877 | else | |
1878 | pc += micromips_pc_insn_size (gdbarch, pc); | |
1879 | } | |
1880 | break; | |
1881 | ||
1882 | case 0x1c: /* BC1F: bits 010000 11100 xxx00 */ | |
1883 | /* BC1ANY2F: bits 010000 11100 xxx01 */ | |
1884 | case 0x1d: /* BC1T: bits 010000 11101 xxx00 */ | |
1885 | /* BC1ANY2T: bits 010000 11101 xxx01 */ | |
1886 | if (((insn >> 16) & 0x2) == 0x0) | |
1887 | pc = micromips_bc1_pc (gdbarch, frame, insn, pc, | |
1888 | ((insn >> 16) & 0x1) + 1); | |
1889 | break; | |
1890 | ||
1891 | case 0x1e: /* BC1ANY4F: bits 010000 11110 xxx01 */ | |
1892 | case 0x1f: /* BC1ANY4T: bits 010000 11111 xxx01 */ | |
1893 | if (((insn >> 16) & 0x3) == 0x1) | |
1894 | pc = micromips_bc1_pc (gdbarch, frame, insn, pc, 4); | |
1895 | break; | |
1896 | } | |
1897 | break; | |
1898 | ||
1899 | case 0x1d: /* JALS: bits 011101 */ | |
1900 | case 0x35: /* J: bits 110101 */ | |
1901 | case 0x3d: /* JAL: bits 111101 */ | |
1902 | pc = ((pc | 0x7fffffe) ^ 0x7fffffe) | (b0s26_imm (insn) << 1); | |
1903 | break; | |
1904 | ||
1905 | case 0x25: /* BEQ: bits 100101 */ | |
1906 | if (get_frame_register_signed (frame, b0s5_reg (insn >> 16)) | |
1907 | == get_frame_register_signed (frame, b5s5_reg (insn >> 16))) | |
1908 | pc += micromips_relative_offset16 (insn); | |
1909 | else | |
1910 | pc += micromips_pc_insn_size (gdbarch, pc); | |
1911 | break; | |
1912 | ||
1913 | case 0x2d: /* BNE: bits 101101 */ | |
1914 | if (get_frame_register_signed (frame, b0s5_reg (insn >> 16)) | |
1915 | != get_frame_register_signed (frame, b5s5_reg (insn >> 16))) | |
1916 | pc += micromips_relative_offset16 (insn); | |
1917 | else | |
1918 | pc += micromips_pc_insn_size (gdbarch, pc); | |
1919 | break; | |
1920 | ||
1921 | case 0x3c: /* JALX: bits 111100 */ | |
1922 | pc = ((pc | 0xfffffff) ^ 0xfffffff) | (b0s26_imm (insn) << 2); | |
1923 | break; | |
1924 | } | |
1925 | break; | |
1926 | ||
1927 | /* 16-bit instructions. */ | |
1928 | case MIPS_INSN16_SIZE: | |
1929 | switch (micromips_op (insn)) | |
1930 | { | |
1931 | case 0x11: /* POOL16C: bits 010001 */ | |
1932 | if ((b5s5_op (insn) & 0x1c) == 0xc) | |
1933 | /* JR16, JRC, JALR16, JALRS16: 010001 011xx */ | |
1934 | pc = get_frame_register_signed (frame, b0s5_reg (insn)); | |
1935 | else if (b5s5_op (insn) == 0x18) | |
1936 | /* JRADDIUSP: bits 010001 11000 */ | |
1937 | pc = get_frame_register_signed (frame, MIPS_RA_REGNUM); | |
1938 | break; | |
1939 | ||
1940 | case 0x23: /* BEQZ16: bits 100011 */ | |
1941 | { | |
1942 | int rs = mips_reg3_to_reg[b7s3_reg (insn)]; | |
1943 | ||
1944 | if (get_frame_register_signed (frame, rs) == 0) | |
1945 | pc += micromips_relative_offset7 (insn); | |
1946 | else | |
1947 | pc += micromips_pc_insn_size (gdbarch, pc); | |
1948 | } | |
1949 | break; | |
1950 | ||
1951 | case 0x2b: /* BNEZ16: bits 101011 */ | |
1952 | { | |
1953 | int rs = mips_reg3_to_reg[b7s3_reg (insn)]; | |
1954 | ||
1955 | if (get_frame_register_signed (frame, rs) != 0) | |
1956 | pc += micromips_relative_offset7 (insn); | |
1957 | else | |
1958 | pc += micromips_pc_insn_size (gdbarch, pc); | |
1959 | } | |
1960 | break; | |
1961 | ||
1962 | case 0x33: /* B16: bits 110011 */ | |
1963 | pc += micromips_relative_offset10 (insn); | |
1964 | break; | |
1965 | } | |
1966 | break; | |
1967 | } | |
1968 | ||
1969 | return pc; | |
1970 | } | |
1971 | ||
c906108c | 1972 | /* Decoding the next place to set a breakpoint is irregular for the |
025bb325 MS |
1973 | mips 16 variant, but fortunately, there fewer instructions. We have |
1974 | to cope ith extensions for 16 bit instructions and a pair of actual | |
1975 | 32 bit instructions. We dont want to set a single step instruction | |
1976 | on the extend instruction either. */ | |
c906108c SS |
1977 | |
1978 | /* Lots of mips16 instruction formats */ | |
1979 | /* Predicting jumps requires itype,ritype,i8type | |
025bb325 | 1980 | and their extensions extItype,extritype,extI8type. */ |
c906108c SS |
1981 | enum mips16_inst_fmts |
1982 | { | |
c5aa993b JM |
1983 | itype, /* 0 immediate 5,10 */ |
1984 | ritype, /* 1 5,3,8 */ | |
1985 | rrtype, /* 2 5,3,3,5 */ | |
1986 | rritype, /* 3 5,3,3,5 */ | |
1987 | rrrtype, /* 4 5,3,3,3,2 */ | |
1988 | rriatype, /* 5 5,3,3,1,4 */ | |
1989 | shifttype, /* 6 5,3,3,3,2 */ | |
1990 | i8type, /* 7 5,3,8 */ | |
1991 | i8movtype, /* 8 5,3,3,5 */ | |
1992 | i8mov32rtype, /* 9 5,3,5,3 */ | |
1993 | i64type, /* 10 5,3,8 */ | |
1994 | ri64type, /* 11 5,3,3,5 */ | |
1995 | jalxtype, /* 12 5,1,5,5,16 - a 32 bit instruction */ | |
1996 | exiItype, /* 13 5,6,5,5,1,1,1,1,1,1,5 */ | |
1997 | extRitype, /* 14 5,6,5,5,3,1,1,1,5 */ | |
1998 | extRRItype, /* 15 5,5,5,5,3,3,5 */ | |
1999 | extRRIAtype, /* 16 5,7,4,5,3,3,1,4 */ | |
2000 | EXTshifttype, /* 17 5,5,1,1,1,1,1,1,5,3,3,1,1,1,2 */ | |
2001 | extI8type, /* 18 5,6,5,5,3,1,1,1,5 */ | |
2002 | extI64type, /* 19 5,6,5,5,3,1,1,1,5 */ | |
2003 | extRi64type, /* 20 5,6,5,5,3,3,5 */ | |
2004 | extshift64type /* 21 5,5,1,1,1,1,1,1,5,1,1,1,3,5 */ | |
2005 | }; | |
12f02c2a | 2006 | /* I am heaping all the fields of the formats into one structure and |
025bb325 | 2007 | then, only the fields which are involved in instruction extension. */ |
c906108c | 2008 | struct upk_mips16 |
6d82d43b AC |
2009 | { |
2010 | CORE_ADDR offset; | |
025bb325 | 2011 | unsigned int regx; /* Function in i8 type. */ |
6d82d43b AC |
2012 | unsigned int regy; |
2013 | }; | |
c906108c SS |
2014 | |
2015 | ||
12f02c2a | 2016 | /* The EXT-I, EXT-ri nad EXT-I8 instructions all have the same format |
c68cf8ad | 2017 | for the bits which make up the immediate extension. */ |
c906108c | 2018 | |
12f02c2a AC |
2019 | static CORE_ADDR |
2020 | extended_offset (unsigned int extension) | |
c906108c | 2021 | { |
12f02c2a | 2022 | CORE_ADDR value; |
130854df | 2023 | |
4c2051c6 | 2024 | value = (extension >> 16) & 0x1f; /* Extract 15:11. */ |
c5aa993b | 2025 | value = value << 6; |
4c2051c6 | 2026 | value |= (extension >> 21) & 0x3f; /* Extract 10:5. */ |
c5aa993b | 2027 | value = value << 5; |
130854df MR |
2028 | value |= extension & 0x1f; /* Extract 4:0. */ |
2029 | ||
c5aa993b | 2030 | return value; |
c906108c SS |
2031 | } |
2032 | ||
2033 | /* Only call this function if you know that this is an extendable | |
bcf1ea1e MR |
2034 | instruction. It won't malfunction, but why make excess remote memory |
2035 | references? If the immediate operands get sign extended or something, | |
2036 | do it after the extension is performed. */ | |
c906108c | 2037 | /* FIXME: Every one of these cases needs to worry about sign extension |
bcf1ea1e | 2038 | when the offset is to be used in relative addressing. */ |
c906108c | 2039 | |
12f02c2a | 2040 | static unsigned int |
e17a4113 | 2041 | fetch_mips_16 (struct gdbarch *gdbarch, CORE_ADDR pc) |
c906108c | 2042 | { |
e17a4113 | 2043 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
47a35522 | 2044 | gdb_byte buf[8]; |
a2fb2cee MR |
2045 | |
2046 | pc = unmake_compact_addr (pc); /* Clear the low order bit. */ | |
c5aa993b | 2047 | target_read_memory (pc, buf, 2); |
e17a4113 | 2048 | return extract_unsigned_integer (buf, 2, byte_order); |
c906108c SS |
2049 | } |
2050 | ||
2051 | static void | |
e17a4113 | 2052 | unpack_mips16 (struct gdbarch *gdbarch, CORE_ADDR pc, |
12f02c2a AC |
2053 | unsigned int extension, |
2054 | unsigned int inst, | |
6d82d43b | 2055 | enum mips16_inst_fmts insn_format, struct upk_mips16 *upk) |
c906108c | 2056 | { |
12f02c2a AC |
2057 | CORE_ADDR offset; |
2058 | int regx; | |
2059 | int regy; | |
2060 | switch (insn_format) | |
c906108c | 2061 | { |
c5aa993b | 2062 | case itype: |
c906108c | 2063 | { |
12f02c2a AC |
2064 | CORE_ADDR value; |
2065 | if (extension) | |
c5aa993b | 2066 | { |
4c2051c6 MR |
2067 | value = extended_offset ((extension << 16) | inst); |
2068 | value = (value ^ 0x8000) - 0x8000; /* Sign-extend. */ | |
c906108c SS |
2069 | } |
2070 | else | |
c5aa993b | 2071 | { |
12f02c2a | 2072 | value = inst & 0x7ff; |
4c2051c6 | 2073 | value = (value ^ 0x400) - 0x400; /* Sign-extend. */ |
c906108c | 2074 | } |
12f02c2a AC |
2075 | offset = value; |
2076 | regx = -1; | |
2077 | regy = -1; | |
c906108c | 2078 | } |
c5aa993b JM |
2079 | break; |
2080 | case ritype: | |
2081 | case i8type: | |
025bb325 | 2082 | { /* A register identifier and an offset. */ |
c906108c | 2083 | /* Most of the fields are the same as I type but the |
025bb325 | 2084 | immediate value is of a different length. */ |
12f02c2a AC |
2085 | CORE_ADDR value; |
2086 | if (extension) | |
c906108c | 2087 | { |
4c2051c6 MR |
2088 | value = extended_offset ((extension << 16) | inst); |
2089 | value = (value ^ 0x8000) - 0x8000; /* Sign-extend. */ | |
c906108c | 2090 | } |
c5aa993b JM |
2091 | else |
2092 | { | |
4c2051c6 MR |
2093 | value = inst & 0xff; /* 8 bits */ |
2094 | value = (value ^ 0x80) - 0x80; /* Sign-extend. */ | |
c5aa993b | 2095 | } |
12f02c2a | 2096 | offset = value; |
4c2051c6 | 2097 | regx = (inst >> 8) & 0x07; /* i8 funct */ |
12f02c2a | 2098 | regy = -1; |
c5aa993b | 2099 | break; |
c906108c | 2100 | } |
c5aa993b | 2101 | case jalxtype: |
c906108c | 2102 | { |
c5aa993b | 2103 | unsigned long value; |
12f02c2a AC |
2104 | unsigned int nexthalf; |
2105 | value = ((inst & 0x1f) << 5) | ((inst >> 5) & 0x1f); | |
c5aa993b | 2106 | value = value << 16; |
4cc0665f MR |
2107 | nexthalf = mips_fetch_instruction (gdbarch, ISA_MIPS16, pc + 2, NULL); |
2108 | /* Low bit still set. */ | |
c5aa993b | 2109 | value |= nexthalf; |
12f02c2a AC |
2110 | offset = value; |
2111 | regx = -1; | |
2112 | regy = -1; | |
c5aa993b | 2113 | break; |
c906108c SS |
2114 | } |
2115 | default: | |
e2e0b3e5 | 2116 | internal_error (__FILE__, __LINE__, _("bad switch")); |
c906108c | 2117 | } |
12f02c2a AC |
2118 | upk->offset = offset; |
2119 | upk->regx = regx; | |
2120 | upk->regy = regy; | |
c906108c SS |
2121 | } |
2122 | ||
2123 | ||
c5aa993b JM |
2124 | static CORE_ADDR |
2125 | add_offset_16 (CORE_ADDR pc, int offset) | |
c906108c | 2126 | { |
5b652102 | 2127 | return ((offset << 2) | ((pc + 2) & (~(CORE_ADDR) 0x0fffffff))); |
c906108c SS |
2128 | } |
2129 | ||
12f02c2a | 2130 | static CORE_ADDR |
0b1b3e42 | 2131 | extended_mips16_next_pc (struct frame_info *frame, CORE_ADDR pc, |
6d82d43b | 2132 | unsigned int extension, unsigned int insn) |
c906108c | 2133 | { |
e17a4113 | 2134 | struct gdbarch *gdbarch = get_frame_arch (frame); |
12f02c2a AC |
2135 | int op = (insn >> 11); |
2136 | switch (op) | |
c906108c | 2137 | { |
6d82d43b | 2138 | case 2: /* Branch */ |
12f02c2a | 2139 | { |
12f02c2a | 2140 | struct upk_mips16 upk; |
e17a4113 | 2141 | unpack_mips16 (gdbarch, pc, extension, insn, itype, &upk); |
4c2051c6 | 2142 | pc += (upk.offset << 1) + 2; |
12f02c2a AC |
2143 | break; |
2144 | } | |
025bb325 MS |
2145 | case 3: /* JAL , JALX - Watch out, these are 32 bit |
2146 | instructions. */ | |
12f02c2a AC |
2147 | { |
2148 | struct upk_mips16 upk; | |
e17a4113 | 2149 | unpack_mips16 (gdbarch, pc, extension, insn, jalxtype, &upk); |
12f02c2a AC |
2150 | pc = add_offset_16 (pc, upk.offset); |
2151 | if ((insn >> 10) & 0x01) /* Exchange mode */ | |
025bb325 | 2152 | pc = pc & ~0x01; /* Clear low bit, indicate 32 bit mode. */ |
12f02c2a AC |
2153 | else |
2154 | pc |= 0x01; | |
2155 | break; | |
2156 | } | |
6d82d43b | 2157 | case 4: /* beqz */ |
12f02c2a AC |
2158 | { |
2159 | struct upk_mips16 upk; | |
2160 | int reg; | |
e17a4113 | 2161 | unpack_mips16 (gdbarch, pc, extension, insn, ritype, &upk); |
4cc0665f | 2162 | reg = get_frame_register_signed (frame, mips_reg3_to_reg[upk.regx]); |
12f02c2a AC |
2163 | if (reg == 0) |
2164 | pc += (upk.offset << 1) + 2; | |
2165 | else | |
2166 | pc += 2; | |
2167 | break; | |
2168 | } | |
6d82d43b | 2169 | case 5: /* bnez */ |
12f02c2a AC |
2170 | { |
2171 | struct upk_mips16 upk; | |
2172 | int reg; | |
e17a4113 | 2173 | unpack_mips16 (gdbarch, pc, extension, insn, ritype, &upk); |
4cc0665f | 2174 | reg = get_frame_register_signed (frame, mips_reg3_to_reg[upk.regx]); |
12f02c2a AC |
2175 | if (reg != 0) |
2176 | pc += (upk.offset << 1) + 2; | |
2177 | else | |
2178 | pc += 2; | |
2179 | break; | |
2180 | } | |
6d82d43b | 2181 | case 12: /* I8 Formats btez btnez */ |
12f02c2a AC |
2182 | { |
2183 | struct upk_mips16 upk; | |
2184 | int reg; | |
e17a4113 | 2185 | unpack_mips16 (gdbarch, pc, extension, insn, i8type, &upk); |
12f02c2a | 2186 | /* upk.regx contains the opcode */ |
0b1b3e42 | 2187 | reg = get_frame_register_signed (frame, 24); /* Test register is 24 */ |
12f02c2a AC |
2188 | if (((upk.regx == 0) && (reg == 0)) /* BTEZ */ |
2189 | || ((upk.regx == 1) && (reg != 0))) /* BTNEZ */ | |
2190 | /* pc = add_offset_16(pc,upk.offset) ; */ | |
2191 | pc += (upk.offset << 1) + 2; | |
2192 | else | |
2193 | pc += 2; | |
2194 | break; | |
2195 | } | |
6d82d43b | 2196 | case 29: /* RR Formats JR, JALR, JALR-RA */ |
12f02c2a AC |
2197 | { |
2198 | struct upk_mips16 upk; | |
2199 | /* upk.fmt = rrtype; */ | |
2200 | op = insn & 0x1f; | |
2201 | if (op == 0) | |
c5aa993b | 2202 | { |
12f02c2a AC |
2203 | int reg; |
2204 | upk.regx = (insn >> 8) & 0x07; | |
2205 | upk.regy = (insn >> 5) & 0x07; | |
4c2051c6 | 2206 | if ((upk.regy & 1) == 0) |
4cc0665f | 2207 | reg = mips_reg3_to_reg[upk.regx]; |
4c2051c6 MR |
2208 | else |
2209 | reg = 31; /* Function return instruction. */ | |
0b1b3e42 | 2210 | pc = get_frame_register_signed (frame, reg); |
c906108c | 2211 | } |
12f02c2a | 2212 | else |
c5aa993b | 2213 | pc += 2; |
12f02c2a AC |
2214 | break; |
2215 | } | |
2216 | case 30: | |
2217 | /* This is an instruction extension. Fetch the real instruction | |
2218 | (which follows the extension) and decode things based on | |
025bb325 | 2219 | that. */ |
12f02c2a AC |
2220 | { |
2221 | pc += 2; | |
e17a4113 UW |
2222 | pc = extended_mips16_next_pc (frame, pc, insn, |
2223 | fetch_mips_16 (gdbarch, pc)); | |
12f02c2a AC |
2224 | break; |
2225 | } | |
2226 | default: | |
2227 | { | |
2228 | pc += 2; | |
2229 | break; | |
2230 | } | |
c906108c | 2231 | } |
c5aa993b | 2232 | return pc; |
12f02c2a | 2233 | } |
c906108c | 2234 | |
5a89d8aa | 2235 | static CORE_ADDR |
0b1b3e42 | 2236 | mips16_next_pc (struct frame_info *frame, CORE_ADDR pc) |
12f02c2a | 2237 | { |
e17a4113 UW |
2238 | struct gdbarch *gdbarch = get_frame_arch (frame); |
2239 | unsigned int insn = fetch_mips_16 (gdbarch, pc); | |
0b1b3e42 | 2240 | return extended_mips16_next_pc (frame, pc, 0, insn); |
12f02c2a AC |
2241 | } |
2242 | ||
2243 | /* The mips_next_pc function supports single_step when the remote | |
7e73cedf | 2244 | target monitor or stub is not developed enough to do a single_step. |
12f02c2a | 2245 | It works by decoding the current instruction and predicting where a |
1aee363c | 2246 | branch will go. This isn't hard because all the data is available. |
4cc0665f | 2247 | The MIPS32, MIPS16 and microMIPS variants are quite different. */ |
ad527d2e | 2248 | static CORE_ADDR |
0b1b3e42 | 2249 | mips_next_pc (struct frame_info *frame, CORE_ADDR pc) |
c906108c | 2250 | { |
4cc0665f MR |
2251 | struct gdbarch *gdbarch = get_frame_arch (frame); |
2252 | ||
2253 | if (mips_pc_is_mips16 (gdbarch, pc)) | |
0b1b3e42 | 2254 | return mips16_next_pc (frame, pc); |
4cc0665f MR |
2255 | else if (mips_pc_is_micromips (gdbarch, pc)) |
2256 | return micromips_next_pc (frame, pc); | |
c5aa993b | 2257 | else |
0b1b3e42 | 2258 | return mips32_next_pc (frame, pc); |
12f02c2a | 2259 | } |
c906108c | 2260 | |
edfae063 AC |
2261 | struct mips_frame_cache |
2262 | { | |
2263 | CORE_ADDR base; | |
2264 | struct trad_frame_saved_reg *saved_regs; | |
2265 | }; | |
2266 | ||
29639122 JB |
2267 | /* Set a register's saved stack address in temp_saved_regs. If an |
2268 | address has already been set for this register, do nothing; this | |
2269 | way we will only recognize the first save of a given register in a | |
2270 | function prologue. | |
eec63939 | 2271 | |
f57d151a UW |
2272 | For simplicity, save the address in both [0 .. gdbarch_num_regs) and |
2273 | [gdbarch_num_regs .. 2*gdbarch_num_regs). | |
2274 | Strictly speaking, only the second range is used as it is only second | |
2275 | range (the ABI instead of ISA registers) that comes into play when finding | |
2276 | saved registers in a frame. */ | |
eec63939 AC |
2277 | |
2278 | static void | |
74ed0bb4 MD |
2279 | set_reg_offset (struct gdbarch *gdbarch, struct mips_frame_cache *this_cache, |
2280 | int regnum, CORE_ADDR offset) | |
eec63939 | 2281 | { |
29639122 JB |
2282 | if (this_cache != NULL |
2283 | && this_cache->saved_regs[regnum].addr == -1) | |
2284 | { | |
74ed0bb4 MD |
2285 | this_cache->saved_regs[regnum + 0 * gdbarch_num_regs (gdbarch)].addr |
2286 | = offset; | |
2287 | this_cache->saved_regs[regnum + 1 * gdbarch_num_regs (gdbarch)].addr | |
2288 | = offset; | |
29639122 | 2289 | } |
eec63939 AC |
2290 | } |
2291 | ||
eec63939 | 2292 | |
29639122 JB |
2293 | /* Fetch the immediate value from a MIPS16 instruction. |
2294 | If the previous instruction was an EXTEND, use it to extend | |
2295 | the upper bits of the immediate value. This is a helper function | |
2296 | for mips16_scan_prologue. */ | |
eec63939 | 2297 | |
29639122 JB |
2298 | static int |
2299 | mips16_get_imm (unsigned short prev_inst, /* previous instruction */ | |
2300 | unsigned short inst, /* current instruction */ | |
2301 | int nbits, /* number of bits in imm field */ | |
2302 | int scale, /* scale factor to be applied to imm */ | |
025bb325 | 2303 | int is_signed) /* is the imm field signed? */ |
eec63939 | 2304 | { |
29639122 | 2305 | int offset; |
eec63939 | 2306 | |
29639122 JB |
2307 | if ((prev_inst & 0xf800) == 0xf000) /* prev instruction was EXTEND? */ |
2308 | { | |
2309 | offset = ((prev_inst & 0x1f) << 11) | (prev_inst & 0x7e0); | |
2310 | if (offset & 0x8000) /* check for negative extend */ | |
2311 | offset = 0 - (0x10000 - (offset & 0xffff)); | |
2312 | return offset | (inst & 0x1f); | |
2313 | } | |
eec63939 | 2314 | else |
29639122 JB |
2315 | { |
2316 | int max_imm = 1 << nbits; | |
2317 | int mask = max_imm - 1; | |
2318 | int sign_bit = max_imm >> 1; | |
45c9dd44 | 2319 | |
29639122 JB |
2320 | offset = inst & mask; |
2321 | if (is_signed && (offset & sign_bit)) | |
2322 | offset = 0 - (max_imm - offset); | |
2323 | return offset * scale; | |
2324 | } | |
2325 | } | |
eec63939 | 2326 | |
65596487 | 2327 | |
29639122 JB |
2328 | /* Analyze the function prologue from START_PC to LIMIT_PC. Builds |
2329 | the associated FRAME_CACHE if not null. | |
2330 | Return the address of the first instruction past the prologue. */ | |
eec63939 | 2331 | |
29639122 | 2332 | static CORE_ADDR |
e17a4113 UW |
2333 | mips16_scan_prologue (struct gdbarch *gdbarch, |
2334 | CORE_ADDR start_pc, CORE_ADDR limit_pc, | |
b8a22b94 | 2335 | struct frame_info *this_frame, |
29639122 JB |
2336 | struct mips_frame_cache *this_cache) |
2337 | { | |
2338 | CORE_ADDR cur_pc; | |
025bb325 | 2339 | CORE_ADDR frame_addr = 0; /* Value of $r17, used as frame pointer. */ |
29639122 JB |
2340 | CORE_ADDR sp; |
2341 | long frame_offset = 0; /* Size of stack frame. */ | |
2342 | long frame_adjust = 0; /* Offset of FP from SP. */ | |
2343 | int frame_reg = MIPS_SP_REGNUM; | |
025bb325 | 2344 | unsigned short prev_inst = 0; /* saved copy of previous instruction. */ |
29639122 JB |
2345 | unsigned inst = 0; /* current instruction */ |
2346 | unsigned entry_inst = 0; /* the entry instruction */ | |
2207132d | 2347 | unsigned save_inst = 0; /* the save instruction */ |
29639122 | 2348 | int reg, offset; |
a343eb3c | 2349 | |
29639122 JB |
2350 | int extend_bytes = 0; |
2351 | int prev_extend_bytes; | |
2352 | CORE_ADDR end_prologue_addr = 0; | |
a343eb3c | 2353 | |
29639122 | 2354 | /* Can be called when there's no process, and hence when there's no |
b8a22b94 DJ |
2355 | THIS_FRAME. */ |
2356 | if (this_frame != NULL) | |
2357 | sp = get_frame_register_signed (this_frame, | |
2358 | gdbarch_num_regs (gdbarch) | |
2359 | + MIPS_SP_REGNUM); | |
29639122 JB |
2360 | else |
2361 | sp = 0; | |
eec63939 | 2362 | |
29639122 JB |
2363 | if (limit_pc > start_pc + 200) |
2364 | limit_pc = start_pc + 200; | |
eec63939 | 2365 | |
95ac2dcf | 2366 | for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += MIPS_INSN16_SIZE) |
29639122 JB |
2367 | { |
2368 | /* Save the previous instruction. If it's an EXTEND, we'll extract | |
2369 | the immediate offset extension from it in mips16_get_imm. */ | |
2370 | prev_inst = inst; | |
eec63939 | 2371 | |
025bb325 | 2372 | /* Fetch and decode the instruction. */ |
4cc0665f MR |
2373 | inst = (unsigned short) mips_fetch_instruction (gdbarch, ISA_MIPS16, |
2374 | cur_pc, NULL); | |
eec63939 | 2375 | |
29639122 JB |
2376 | /* Normally we ignore extend instructions. However, if it is |
2377 | not followed by a valid prologue instruction, then this | |
2378 | instruction is not part of the prologue either. We must | |
2379 | remember in this case to adjust the end_prologue_addr back | |
2380 | over the extend. */ | |
2381 | if ((inst & 0xf800) == 0xf000) /* extend */ | |
2382 | { | |
95ac2dcf | 2383 | extend_bytes = MIPS_INSN16_SIZE; |
29639122 JB |
2384 | continue; |
2385 | } | |
eec63939 | 2386 | |
29639122 JB |
2387 | prev_extend_bytes = extend_bytes; |
2388 | extend_bytes = 0; | |
eec63939 | 2389 | |
29639122 JB |
2390 | if ((inst & 0xff00) == 0x6300 /* addiu sp */ |
2391 | || (inst & 0xff00) == 0xfb00) /* daddiu sp */ | |
2392 | { | |
2393 | offset = mips16_get_imm (prev_inst, inst, 8, 8, 1); | |
025bb325 | 2394 | if (offset < 0) /* Negative stack adjustment? */ |
29639122 JB |
2395 | frame_offset -= offset; |
2396 | else | |
2397 | /* Exit loop if a positive stack adjustment is found, which | |
2398 | usually means that the stack cleanup code in the function | |
2399 | epilogue is reached. */ | |
2400 | break; | |
2401 | } | |
2402 | else if ((inst & 0xf800) == 0xd000) /* sw reg,n($sp) */ | |
2403 | { | |
2404 | offset = mips16_get_imm (prev_inst, inst, 8, 4, 0); | |
4cc0665f | 2405 | reg = mips_reg3_to_reg[(inst & 0x700) >> 8]; |
74ed0bb4 | 2406 | set_reg_offset (gdbarch, this_cache, reg, sp + offset); |
29639122 JB |
2407 | } |
2408 | else if ((inst & 0xff00) == 0xf900) /* sd reg,n($sp) */ | |
2409 | { | |
2410 | offset = mips16_get_imm (prev_inst, inst, 5, 8, 0); | |
4cc0665f | 2411 | reg = mips_reg3_to_reg[(inst & 0xe0) >> 5]; |
74ed0bb4 | 2412 | set_reg_offset (gdbarch, this_cache, reg, sp + offset); |
29639122 JB |
2413 | } |
2414 | else if ((inst & 0xff00) == 0x6200) /* sw $ra,n($sp) */ | |
2415 | { | |
2416 | offset = mips16_get_imm (prev_inst, inst, 8, 4, 0); | |
74ed0bb4 | 2417 | set_reg_offset (gdbarch, this_cache, MIPS_RA_REGNUM, sp + offset); |
29639122 JB |
2418 | } |
2419 | else if ((inst & 0xff00) == 0xfa00) /* sd $ra,n($sp) */ | |
2420 | { | |
2421 | offset = mips16_get_imm (prev_inst, inst, 8, 8, 0); | |
74ed0bb4 | 2422 | set_reg_offset (gdbarch, this_cache, MIPS_RA_REGNUM, sp + offset); |
29639122 JB |
2423 | } |
2424 | else if (inst == 0x673d) /* move $s1, $sp */ | |
2425 | { | |
2426 | frame_addr = sp; | |
2427 | frame_reg = 17; | |
2428 | } | |
2429 | else if ((inst & 0xff00) == 0x0100) /* addiu $s1,sp,n */ | |
2430 | { | |
2431 | offset = mips16_get_imm (prev_inst, inst, 8, 4, 0); | |
2432 | frame_addr = sp + offset; | |
2433 | frame_reg = 17; | |
2434 | frame_adjust = offset; | |
2435 | } | |
2436 | else if ((inst & 0xFF00) == 0xd900) /* sw reg,offset($s1) */ | |
2437 | { | |
2438 | offset = mips16_get_imm (prev_inst, inst, 5, 4, 0); | |
4cc0665f | 2439 | reg = mips_reg3_to_reg[(inst & 0xe0) >> 5]; |
74ed0bb4 | 2440 | set_reg_offset (gdbarch, this_cache, reg, frame_addr + offset); |
29639122 JB |
2441 | } |
2442 | else if ((inst & 0xFF00) == 0x7900) /* sd reg,offset($s1) */ | |
2443 | { | |
2444 | offset = mips16_get_imm (prev_inst, inst, 5, 8, 0); | |
4cc0665f | 2445 | reg = mips_reg3_to_reg[(inst & 0xe0) >> 5]; |
74ed0bb4 | 2446 | set_reg_offset (gdbarch, this_cache, reg, frame_addr + offset); |
29639122 JB |
2447 | } |
2448 | else if ((inst & 0xf81f) == 0xe809 | |
2449 | && (inst & 0x700) != 0x700) /* entry */ | |
025bb325 | 2450 | entry_inst = inst; /* Save for later processing. */ |
2207132d MR |
2451 | else if ((inst & 0xff80) == 0x6480) /* save */ |
2452 | { | |
025bb325 | 2453 | save_inst = inst; /* Save for later processing. */ |
2207132d MR |
2454 | if (prev_extend_bytes) /* extend */ |
2455 | save_inst |= prev_inst << 16; | |
2456 | } | |
29639122 | 2457 | else if ((inst & 0xf800) == 0x1800) /* jal(x) */ |
95ac2dcf | 2458 | cur_pc += MIPS_INSN16_SIZE; /* 32-bit instruction */ |
29639122 JB |
2459 | else if ((inst & 0xff1c) == 0x6704) /* move reg,$a0-$a3 */ |
2460 | { | |
2461 | /* This instruction is part of the prologue, but we don't | |
2462 | need to do anything special to handle it. */ | |
2463 | } | |
2464 | else | |
2465 | { | |
2466 | /* This instruction is not an instruction typically found | |
2467 | in a prologue, so we must have reached the end of the | |
2468 | prologue. */ | |
2469 | if (end_prologue_addr == 0) | |
2470 | end_prologue_addr = cur_pc - prev_extend_bytes; | |
2471 | } | |
2472 | } | |
eec63939 | 2473 | |
29639122 JB |
2474 | /* The entry instruction is typically the first instruction in a function, |
2475 | and it stores registers at offsets relative to the value of the old SP | |
2476 | (before the prologue). But the value of the sp parameter to this | |
2477 | function is the new SP (after the prologue has been executed). So we | |
2478 | can't calculate those offsets until we've seen the entire prologue, | |
025bb325 | 2479 | and can calculate what the old SP must have been. */ |
29639122 JB |
2480 | if (entry_inst != 0) |
2481 | { | |
2482 | int areg_count = (entry_inst >> 8) & 7; | |
2483 | int sreg_count = (entry_inst >> 6) & 3; | |
eec63939 | 2484 | |
29639122 JB |
2485 | /* The entry instruction always subtracts 32 from the SP. */ |
2486 | frame_offset += 32; | |
2487 | ||
2488 | /* Now we can calculate what the SP must have been at the | |
2489 | start of the function prologue. */ | |
2490 | sp += frame_offset; | |
2491 | ||
2492 | /* Check if a0-a3 were saved in the caller's argument save area. */ | |
2493 | for (reg = 4, offset = 0; reg < areg_count + 4; reg++) | |
2494 | { | |
74ed0bb4 | 2495 | set_reg_offset (gdbarch, this_cache, reg, sp + offset); |
72a155b4 | 2496 | offset += mips_abi_regsize (gdbarch); |
29639122 JB |
2497 | } |
2498 | ||
2499 | /* Check if the ra register was pushed on the stack. */ | |
2500 | offset = -4; | |
2501 | if (entry_inst & 0x20) | |
2502 | { | |
74ed0bb4 | 2503 | set_reg_offset (gdbarch, this_cache, MIPS_RA_REGNUM, sp + offset); |
72a155b4 | 2504 | offset -= mips_abi_regsize (gdbarch); |
29639122 JB |
2505 | } |
2506 | ||
2507 | /* Check if the s0 and s1 registers were pushed on the stack. */ | |
2508 | for (reg = 16; reg < sreg_count + 16; reg++) | |
2509 | { | |
74ed0bb4 | 2510 | set_reg_offset (gdbarch, this_cache, reg, sp + offset); |
72a155b4 | 2511 | offset -= mips_abi_regsize (gdbarch); |
29639122 JB |
2512 | } |
2513 | } | |
2514 | ||
2207132d MR |
2515 | /* The SAVE instruction is similar to ENTRY, except that defined by the |
2516 | MIPS16e ASE of the MIPS Architecture. Unlike with ENTRY though, the | |
2517 | size of the frame is specified as an immediate field of instruction | |
2518 | and an extended variation exists which lets additional registers and | |
2519 | frame space to be specified. The instruction always treats registers | |
2520 | as 32-bit so its usefulness for 64-bit ABIs is questionable. */ | |
2521 | if (save_inst != 0 && mips_abi_regsize (gdbarch) == 4) | |
2522 | { | |
2523 | static int args_table[16] = { | |
2524 | 0, 0, 0, 0, 1, 1, 1, 1, | |
2525 | 2, 2, 2, 0, 3, 3, 4, -1, | |
2526 | }; | |
2527 | static int astatic_table[16] = { | |
2528 | 0, 1, 2, 3, 0, 1, 2, 3, | |
2529 | 0, 1, 2, 4, 0, 1, 0, -1, | |
2530 | }; | |
2531 | int aregs = (save_inst >> 16) & 0xf; | |
2532 | int xsregs = (save_inst >> 24) & 0x7; | |
2533 | int args = args_table[aregs]; | |
2534 | int astatic = astatic_table[aregs]; | |
2535 | long frame_size; | |
2536 | ||
2537 | if (args < 0) | |
2538 | { | |
2539 | warning (_("Invalid number of argument registers encoded in SAVE.")); | |
2540 | args = 0; | |
2541 | } | |
2542 | if (astatic < 0) | |
2543 | { | |
2544 | warning (_("Invalid number of static registers encoded in SAVE.")); | |
2545 | astatic = 0; | |
2546 | } | |
2547 | ||
2548 | /* For standard SAVE the frame size of 0 means 128. */ | |
2549 | frame_size = ((save_inst >> 16) & 0xf0) | (save_inst & 0xf); | |
2550 | if (frame_size == 0 && (save_inst >> 16) == 0) | |
2551 | frame_size = 16; | |
2552 | frame_size *= 8; | |
2553 | frame_offset += frame_size; | |
2554 | ||
2555 | /* Now we can calculate what the SP must have been at the | |
2556 | start of the function prologue. */ | |
2557 | sp += frame_offset; | |
2558 | ||
2559 | /* Check if A0-A3 were saved in the caller's argument save area. */ | |
2560 | for (reg = MIPS_A0_REGNUM, offset = 0; reg < args + 4; reg++) | |
2561 | { | |
74ed0bb4 | 2562 | set_reg_offset (gdbarch, this_cache, reg, sp + offset); |
2207132d MR |
2563 | offset += mips_abi_regsize (gdbarch); |
2564 | } | |
2565 | ||
2566 | offset = -4; | |
2567 | ||
2568 | /* Check if the RA register was pushed on the stack. */ | |
2569 | if (save_inst & 0x40) | |
2570 | { | |
74ed0bb4 | 2571 | set_reg_offset (gdbarch, this_cache, MIPS_RA_REGNUM, sp + offset); |
2207132d MR |
2572 | offset -= mips_abi_regsize (gdbarch); |
2573 | } | |
2574 | ||
2575 | /* Check if the S8 register was pushed on the stack. */ | |
2576 | if (xsregs > 6) | |
2577 | { | |
74ed0bb4 | 2578 | set_reg_offset (gdbarch, this_cache, 30, sp + offset); |
2207132d MR |
2579 | offset -= mips_abi_regsize (gdbarch); |
2580 | xsregs--; | |
2581 | } | |
2582 | /* Check if S2-S7 were pushed on the stack. */ | |
2583 | for (reg = 18 + xsregs - 1; reg > 18 - 1; reg--) | |
2584 | { | |
74ed0bb4 | 2585 | set_reg_offset (gdbarch, this_cache, reg, sp + offset); |
2207132d MR |
2586 | offset -= mips_abi_regsize (gdbarch); |
2587 | } | |
2588 | ||
2589 | /* Check if the S1 register was pushed on the stack. */ | |
2590 | if (save_inst & 0x10) | |
2591 | { | |
74ed0bb4 | 2592 | set_reg_offset (gdbarch, this_cache, 17, sp + offset); |
2207132d MR |
2593 | offset -= mips_abi_regsize (gdbarch); |
2594 | } | |
2595 | /* Check if the S0 register was pushed on the stack. */ | |
2596 | if (save_inst & 0x20) | |
2597 | { | |
74ed0bb4 | 2598 | set_reg_offset (gdbarch, this_cache, 16, sp + offset); |
2207132d MR |
2599 | offset -= mips_abi_regsize (gdbarch); |
2600 | } | |
2601 | ||
4cc0665f MR |
2602 | /* Check if A0-A3 were pushed on the stack. */ |
2603 | for (reg = MIPS_A0_REGNUM + 3; reg > MIPS_A0_REGNUM + 3 - astatic; reg--) | |
2604 | { | |
2605 | set_reg_offset (gdbarch, this_cache, reg, sp + offset); | |
2606 | offset -= mips_abi_regsize (gdbarch); | |
2607 | } | |
2608 | } | |
2609 | ||
2610 | if (this_cache != NULL) | |
2611 | { | |
2612 | this_cache->base = | |
2613 | (get_frame_register_signed (this_frame, | |
2614 | gdbarch_num_regs (gdbarch) + frame_reg) | |
2615 | + frame_offset - frame_adjust); | |
2616 | /* FIXME: brobecker/2004-10-10: Just as in the mips32 case, we should | |
2617 | be able to get rid of the assignment below, evetually. But it's | |
2618 | still needed for now. */ | |
2619 | this_cache->saved_regs[gdbarch_num_regs (gdbarch) | |
2620 | + mips_regnum (gdbarch)->pc] | |
2621 | = this_cache->saved_regs[gdbarch_num_regs (gdbarch) + MIPS_RA_REGNUM]; | |
2622 | } | |
2623 | ||
2624 | /* If we didn't reach the end of the prologue when scanning the function | |
2625 | instructions, then set end_prologue_addr to the address of the | |
2626 | instruction immediately after the last one we scanned. */ | |
2627 | if (end_prologue_addr == 0) | |
2628 | end_prologue_addr = cur_pc; | |
2629 | ||
2630 | return end_prologue_addr; | |
2631 | } | |
2632 | ||
2633 | /* Heuristic unwinder for 16-bit MIPS instruction set (aka MIPS16). | |
2634 | Procedures that use the 32-bit instruction set are handled by the | |
2635 | mips_insn32 unwinder. */ | |
2636 | ||
2637 | static struct mips_frame_cache * | |
2638 | mips_insn16_frame_cache (struct frame_info *this_frame, void **this_cache) | |
2639 | { | |
2640 | struct gdbarch *gdbarch = get_frame_arch (this_frame); | |
2641 | struct mips_frame_cache *cache; | |
2642 | ||
2643 | if ((*this_cache) != NULL) | |
2644 | return (*this_cache); | |
2645 | cache = FRAME_OBSTACK_ZALLOC (struct mips_frame_cache); | |
2646 | (*this_cache) = cache; | |
2647 | cache->saved_regs = trad_frame_alloc_saved_regs (this_frame); | |
2648 | ||
2649 | /* Analyze the function prologue. */ | |
2650 | { | |
2651 | const CORE_ADDR pc = get_frame_address_in_block (this_frame); | |
2652 | CORE_ADDR start_addr; | |
2653 | ||
2654 | find_pc_partial_function (pc, NULL, &start_addr, NULL); | |
2655 | if (start_addr == 0) | |
2656 | start_addr = heuristic_proc_start (gdbarch, pc); | |
2657 | /* We can't analyze the prologue if we couldn't find the begining | |
2658 | of the function. */ | |
2659 | if (start_addr == 0) | |
2660 | return cache; | |
2661 | ||
2662 | mips16_scan_prologue (gdbarch, start_addr, pc, this_frame, *this_cache); | |
2663 | } | |
2664 | ||
2665 | /* gdbarch_sp_regnum contains the value and not the address. */ | |
2666 | trad_frame_set_value (cache->saved_regs, | |
2667 | gdbarch_num_regs (gdbarch) + MIPS_SP_REGNUM, | |
2668 | cache->base); | |
2669 | ||
2670 | return (*this_cache); | |
2671 | } | |
2672 | ||
2673 | static void | |
2674 | mips_insn16_frame_this_id (struct frame_info *this_frame, void **this_cache, | |
2675 | struct frame_id *this_id) | |
2676 | { | |
2677 | struct mips_frame_cache *info = mips_insn16_frame_cache (this_frame, | |
2678 | this_cache); | |
2679 | /* This marks the outermost frame. */ | |
2680 | if (info->base == 0) | |
2681 | return; | |
2682 | (*this_id) = frame_id_build (info->base, get_frame_func (this_frame)); | |
2683 | } | |
2684 | ||
2685 | static struct value * | |
2686 | mips_insn16_frame_prev_register (struct frame_info *this_frame, | |
2687 | void **this_cache, int regnum) | |
2688 | { | |
2689 | struct mips_frame_cache *info = mips_insn16_frame_cache (this_frame, | |
2690 | this_cache); | |
2691 | return trad_frame_get_prev_register (this_frame, info->saved_regs, regnum); | |
2692 | } | |
2693 | ||
2694 | static int | |
2695 | mips_insn16_frame_sniffer (const struct frame_unwind *self, | |
2696 | struct frame_info *this_frame, void **this_cache) | |
2697 | { | |
2698 | struct gdbarch *gdbarch = get_frame_arch (this_frame); | |
2699 | CORE_ADDR pc = get_frame_pc (this_frame); | |
2700 | if (mips_pc_is_mips16 (gdbarch, pc)) | |
2701 | return 1; | |
2702 | return 0; | |
2703 | } | |
2704 | ||
2705 | static const struct frame_unwind mips_insn16_frame_unwind = | |
2706 | { | |
2707 | NORMAL_FRAME, | |
2708 | default_frame_unwind_stop_reason, | |
2709 | mips_insn16_frame_this_id, | |
2710 | mips_insn16_frame_prev_register, | |
2711 | NULL, | |
2712 | mips_insn16_frame_sniffer | |
2713 | }; | |
2714 | ||
2715 | static CORE_ADDR | |
2716 | mips_insn16_frame_base_address (struct frame_info *this_frame, | |
2717 | void **this_cache) | |
2718 | { | |
2719 | struct mips_frame_cache *info = mips_insn16_frame_cache (this_frame, | |
2720 | this_cache); | |
2721 | return info->base; | |
2722 | } | |
2723 | ||
2724 | static const struct frame_base mips_insn16_frame_base = | |
2725 | { | |
2726 | &mips_insn16_frame_unwind, | |
2727 | mips_insn16_frame_base_address, | |
2728 | mips_insn16_frame_base_address, | |
2729 | mips_insn16_frame_base_address | |
2730 | }; | |
2731 | ||
2732 | static const struct frame_base * | |
2733 | mips_insn16_frame_base_sniffer (struct frame_info *this_frame) | |
2734 | { | |
2735 | struct gdbarch *gdbarch = get_frame_arch (this_frame); | |
2736 | CORE_ADDR pc = get_frame_pc (this_frame); | |
2737 | if (mips_pc_is_mips16 (gdbarch, pc)) | |
2738 | return &mips_insn16_frame_base; | |
2739 | else | |
2740 | return NULL; | |
2741 | } | |
2742 | ||
2743 | /* Decode a 9-bit signed immediate argument of ADDIUSP -- -2 is mapped | |
2744 | to -258, -1 -- to -257, 0 -- to 256, 1 -- to 257 and other values are | |
2745 | interpreted directly, and then multiplied by 4. */ | |
2746 | ||
2747 | static int | |
2748 | micromips_decode_imm9 (int imm) | |
2749 | { | |
2750 | imm = (imm ^ 0x100) - 0x100; | |
2751 | if (imm > -3 && imm < 2) | |
2752 | imm ^= 0x100; | |
2753 | return imm << 2; | |
2754 | } | |
2755 | ||
2756 | /* Analyze the function prologue from START_PC to LIMIT_PC. Return | |
2757 | the address of the first instruction past the prologue. */ | |
2758 | ||
2759 | static CORE_ADDR | |
2760 | micromips_scan_prologue (struct gdbarch *gdbarch, | |
2761 | CORE_ADDR start_pc, CORE_ADDR limit_pc, | |
2762 | struct frame_info *this_frame, | |
2763 | struct mips_frame_cache *this_cache) | |
2764 | { | |
2765 | CORE_ADDR end_prologue_addr = 0; | |
2766 | int prev_non_prologue_insn = 0; | |
2767 | int frame_reg = MIPS_SP_REGNUM; | |
2768 | int this_non_prologue_insn; | |
2769 | int non_prologue_insns = 0; | |
2770 | long frame_offset = 0; /* Size of stack frame. */ | |
2771 | long frame_adjust = 0; /* Offset of FP from SP. */ | |
2772 | CORE_ADDR frame_addr = 0; /* Value of $30, used as frame pointer. */ | |
2773 | CORE_ADDR prev_pc; | |
2774 | CORE_ADDR cur_pc; | |
2775 | ULONGEST insn; /* current instruction */ | |
2776 | CORE_ADDR sp; | |
2777 | long offset; | |
2778 | long sp_adj; | |
2779 | long v1_off = 0; /* The assumption is LUI will replace it. */ | |
2780 | int reglist; | |
2781 | int breg; | |
2782 | int dreg; | |
2783 | int sreg; | |
2784 | int treg; | |
2785 | int loc; | |
2786 | int op; | |
2787 | int s; | |
2788 | int i; | |
2789 | ||
2790 | /* Can be called when there's no process, and hence when there's no | |
2791 | THIS_FRAME. */ | |
2792 | if (this_frame != NULL) | |
2793 | sp = get_frame_register_signed (this_frame, | |
2794 | gdbarch_num_regs (gdbarch) | |
2795 | + MIPS_SP_REGNUM); | |
2796 | else | |
2797 | sp = 0; | |
2798 | ||
2799 | if (limit_pc > start_pc + 200) | |
2800 | limit_pc = start_pc + 200; | |
2801 | prev_pc = start_pc; | |
2802 | ||
2803 | /* Permit at most one non-prologue non-control-transfer instruction | |
2804 | in the middle which may have been reordered by the compiler for | |
2805 | optimisation. */ | |
2806 | for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += loc) | |
2807 | { | |
2808 | this_non_prologue_insn = 0; | |
2809 | sp_adj = 0; | |
2810 | loc = 0; | |
2811 | insn = mips_fetch_instruction (gdbarch, ISA_MICROMIPS, cur_pc, NULL); | |
2812 | loc += MIPS_INSN16_SIZE; | |
2813 | switch (mips_insn_size (ISA_MICROMIPS, insn)) | |
2814 | { | |
2815 | /* 48-bit instructions. */ | |
2816 | case 3 * MIPS_INSN16_SIZE: | |
2817 | /* No prologue instructions in this category. */ | |
2818 | this_non_prologue_insn = 1; | |
2819 | loc += 2 * MIPS_INSN16_SIZE; | |
2820 | break; | |
2821 | ||
2822 | /* 32-bit instructions. */ | |
2823 | case 2 * MIPS_INSN16_SIZE: | |
2824 | insn <<= 16; | |
2825 | insn |= mips_fetch_instruction (gdbarch, | |
2826 | ISA_MICROMIPS, cur_pc + loc, NULL); | |
2827 | loc += MIPS_INSN16_SIZE; | |
2828 | switch (micromips_op (insn >> 16)) | |
2829 | { | |
2830 | /* Record $sp/$fp adjustment. */ | |
2831 | /* Discard (D)ADDU $gp,$jp used for PIC code. */ | |
2832 | case 0x0: /* POOL32A: bits 000000 */ | |
2833 | case 0x16: /* POOL32S: bits 010110 */ | |
2834 | op = b0s11_op (insn); | |
2835 | sreg = b0s5_reg (insn >> 16); | |
2836 | treg = b5s5_reg (insn >> 16); | |
2837 | dreg = b11s5_reg (insn); | |
2838 | if (op == 0x1d0 | |
2839 | /* SUBU: bits 000000 00111010000 */ | |
2840 | /* DSUBU: bits 010110 00111010000 */ | |
2841 | && dreg == MIPS_SP_REGNUM && sreg == MIPS_SP_REGNUM | |
2842 | && treg == 3) | |
2843 | /* (D)SUBU $sp, $v1 */ | |
2844 | sp_adj = v1_off; | |
2845 | else if (op != 0x150 | |
2846 | /* ADDU: bits 000000 00101010000 */ | |
2847 | /* DADDU: bits 010110 00101010000 */ | |
2848 | || dreg != 28 || sreg != 28 || treg != MIPS_T9_REGNUM) | |
2849 | this_non_prologue_insn = 1; | |
2850 | break; | |
2851 | ||
2852 | case 0x8: /* POOL32B: bits 001000 */ | |
2853 | op = b12s4_op (insn); | |
2854 | breg = b0s5_reg (insn >> 16); | |
2855 | reglist = sreg = b5s5_reg (insn >> 16); | |
2856 | offset = (b0s12_imm (insn) ^ 0x800) - 0x800; | |
2857 | if ((op == 0x9 || op == 0xc) | |
2858 | /* SWP: bits 001000 1001 */ | |
2859 | /* SDP: bits 001000 1100 */ | |
2860 | && breg == MIPS_SP_REGNUM && sreg < MIPS_RA_REGNUM) | |
2861 | /* S[DW]P reg,offset($sp) */ | |
2862 | { | |
2863 | s = 4 << ((b12s4_op (insn) & 0x4) == 0x4); | |
2864 | set_reg_offset (gdbarch, this_cache, | |
2865 | sreg, sp + offset); | |
2866 | set_reg_offset (gdbarch, this_cache, | |
2867 | sreg + 1, sp + offset + s); | |
2868 | } | |
2869 | else if ((op == 0xd || op == 0xf) | |
2870 | /* SWM: bits 001000 1101 */ | |
2871 | /* SDM: bits 001000 1111 */ | |
2872 | && breg == MIPS_SP_REGNUM | |
2873 | /* SWM reglist,offset($sp) */ | |
2874 | && ((reglist >= 1 && reglist <= 9) | |
2875 | || (reglist >= 16 && reglist <= 25))) | |
2876 | { | |
2877 | int sreglist = min(reglist & 0xf, 8); | |
2878 | ||
2879 | s = 4 << ((b12s4_op (insn) & 0x2) == 0x2); | |
2880 | for (i = 0; i < sreglist; i++) | |
2881 | set_reg_offset (gdbarch, this_cache, 16 + i, sp + s * i); | |
2882 | if ((reglist & 0xf) > 8) | |
2883 | set_reg_offset (gdbarch, this_cache, 30, sp + s * i++); | |
2884 | if ((reglist & 0x10) == 0x10) | |
2885 | set_reg_offset (gdbarch, this_cache, | |
2886 | MIPS_RA_REGNUM, sp + s * i++); | |
2887 | } | |
2888 | else | |
2889 | this_non_prologue_insn = 1; | |
2890 | break; | |
2891 | ||
2892 | /* Record $sp/$fp adjustment. */ | |
2893 | /* Discard (D)ADDIU $gp used for PIC code. */ | |
2894 | case 0xc: /* ADDIU: bits 001100 */ | |
2895 | case 0x17: /* DADDIU: bits 010111 */ | |
2896 | sreg = b0s5_reg (insn >> 16); | |
2897 | dreg = b5s5_reg (insn >> 16); | |
2898 | offset = (b0s16_imm (insn) ^ 0x8000) - 0x8000; | |
2899 | if (sreg == MIPS_SP_REGNUM && dreg == MIPS_SP_REGNUM) | |
2900 | /* (D)ADDIU $sp, imm */ | |
2901 | sp_adj = offset; | |
2902 | else if (sreg == MIPS_SP_REGNUM && dreg == 30) | |
2903 | /* (D)ADDIU $fp, $sp, imm */ | |
2904 | { | |
2905 | frame_addr = sp + offset; | |
2906 | frame_adjust = offset; | |
2907 | frame_reg = 30; | |
2908 | } | |
2909 | else if (sreg != 28 || dreg != 28) | |
2910 | /* (D)ADDIU $gp, imm */ | |
2911 | this_non_prologue_insn = 1; | |
2912 | break; | |
2913 | ||
2914 | /* LUI $v1 is used for larger $sp adjustments. */ | |
3356937a | 2915 | /* Discard LUI $gp used for PIC code. */ |
4cc0665f MR |
2916 | case 0x10: /* POOL32I: bits 010000 */ |
2917 | if (b5s5_op (insn >> 16) == 0xd | |
2918 | /* LUI: bits 010000 001101 */ | |
2919 | && b0s5_reg (insn >> 16) == 3) | |
2920 | /* LUI $v1, imm */ | |
2921 | v1_off = ((b0s16_imm (insn) << 16) ^ 0x80000000) - 0x80000000; | |
2922 | else if (b5s5_op (insn >> 16) != 0xd | |
2923 | /* LUI: bits 010000 001101 */ | |
2924 | || b0s5_reg (insn >> 16) != 28) | |
2925 | /* LUI $gp, imm */ | |
2926 | this_non_prologue_insn = 1; | |
2927 | break; | |
2928 | ||
2929 | /* ORI $v1 is used for larger $sp adjustments. */ | |
2930 | case 0x14: /* ORI: bits 010100 */ | |
2931 | sreg = b0s5_reg (insn >> 16); | |
2932 | dreg = b5s5_reg (insn >> 16); | |
2933 | if (sreg == 3 && dreg == 3) | |
2934 | /* ORI $v1, imm */ | |
2935 | v1_off |= b0s16_imm (insn); | |
2936 | else | |
2937 | this_non_prologue_insn = 1; | |
2938 | break; | |
2939 | ||
2940 | case 0x26: /* SWC1: bits 100110 */ | |
2941 | case 0x2e: /* SDC1: bits 101110 */ | |
2942 | breg = b0s5_reg (insn >> 16); | |
2943 | if (breg != MIPS_SP_REGNUM) | |
2944 | /* S[DW]C1 reg,offset($sp) */ | |
2945 | this_non_prologue_insn = 1; | |
2946 | break; | |
2947 | ||
2948 | case 0x36: /* SD: bits 110110 */ | |
2949 | case 0x3e: /* SW: bits 111110 */ | |
2950 | breg = b0s5_reg (insn >> 16); | |
2951 | sreg = b5s5_reg (insn >> 16); | |
2952 | offset = (b0s16_imm (insn) ^ 0x8000) - 0x8000; | |
2953 | if (breg == MIPS_SP_REGNUM) | |
2954 | /* S[DW] reg,offset($sp) */ | |
2955 | set_reg_offset (gdbarch, this_cache, sreg, sp + offset); | |
2956 | else | |
2957 | this_non_prologue_insn = 1; | |
2958 | break; | |
2959 | ||
2960 | default: | |
2961 | this_non_prologue_insn = 1; | |
2962 | break; | |
2963 | } | |
2964 | break; | |
2965 | ||
2966 | /* 16-bit instructions. */ | |
2967 | case MIPS_INSN16_SIZE: | |
2968 | switch (micromips_op (insn)) | |
2969 | { | |
2970 | case 0x3: /* MOVE: bits 000011 */ | |
2971 | sreg = b0s5_reg (insn); | |
2972 | dreg = b5s5_reg (insn); | |
2973 | if (sreg == MIPS_SP_REGNUM && dreg == 30) | |
2974 | /* MOVE $fp, $sp */ | |
2975 | { | |
2976 | frame_addr = sp; | |
2977 | frame_reg = 30; | |
2978 | } | |
2979 | else if ((sreg & 0x1c) != 0x4) | |
2980 | /* MOVE reg, $a0-$a3 */ | |
2981 | this_non_prologue_insn = 1; | |
2982 | break; | |
2983 | ||
2984 | case 0x11: /* POOL16C: bits 010001 */ | |
2985 | if (b6s4_op (insn) == 0x5) | |
2986 | /* SWM: bits 010001 0101 */ | |
2987 | { | |
2988 | offset = ((b0s4_imm (insn) << 2) ^ 0x20) - 0x20; | |
2989 | reglist = b4s2_regl (insn); | |
2990 | for (i = 0; i <= reglist; i++) | |
2991 | set_reg_offset (gdbarch, this_cache, 16 + i, sp + 4 * i); | |
2992 | set_reg_offset (gdbarch, this_cache, | |
2993 | MIPS_RA_REGNUM, sp + 4 * i++); | |
2994 | } | |
2995 | else | |
2996 | this_non_prologue_insn = 1; | |
2997 | break; | |
2998 | ||
2999 | case 0x13: /* POOL16D: bits 010011 */ | |
3000 | if ((insn & 0x1) == 0x1) | |
3001 | /* ADDIUSP: bits 010011 1 */ | |
3002 | sp_adj = micromips_decode_imm9 (b1s9_imm (insn)); | |
3003 | else if (b5s5_reg (insn) == MIPS_SP_REGNUM) | |
3004 | /* ADDIUS5: bits 010011 0 */ | |
3005 | /* ADDIUS5 $sp, imm */ | |
3006 | sp_adj = (b1s4_imm (insn) ^ 8) - 8; | |
3007 | else | |
3008 | this_non_prologue_insn = 1; | |
3009 | break; | |
3010 | ||
3011 | case 0x32: /* SWSP: bits 110010 */ | |
3012 | offset = b0s5_imm (insn) << 2; | |
3013 | sreg = b5s5_reg (insn); | |
3014 | set_reg_offset (gdbarch, this_cache, sreg, sp + offset); | |
3015 | break; | |
3016 | ||
3017 | default: | |
3018 | this_non_prologue_insn = 1; | |
3019 | break; | |
3020 | } | |
3021 | break; | |
3022 | } | |
3023 | if (sp_adj < 0) | |
3024 | frame_offset -= sp_adj; | |
3025 | ||
3026 | non_prologue_insns += this_non_prologue_insn; | |
3027 | /* Enough non-prologue insns seen or positive stack adjustment? */ | |
3028 | if (end_prologue_addr == 0 && (non_prologue_insns > 1 || sp_adj > 0)) | |
2207132d | 3029 | { |
4cc0665f MR |
3030 | end_prologue_addr = prev_non_prologue_insn ? prev_pc : cur_pc; |
3031 | break; | |
2207132d | 3032 | } |
4cc0665f MR |
3033 | prev_non_prologue_insn = this_non_prologue_insn; |
3034 | prev_pc = cur_pc; | |
2207132d MR |
3035 | } |
3036 | ||
29639122 JB |
3037 | if (this_cache != NULL) |
3038 | { | |
3039 | this_cache->base = | |
4cc0665f | 3040 | (get_frame_register_signed (this_frame, |
b8a22b94 | 3041 | gdbarch_num_regs (gdbarch) + frame_reg) |
4cc0665f | 3042 | + frame_offset - frame_adjust); |
29639122 | 3043 | /* FIXME: brobecker/2004-10-10: Just as in the mips32 case, we should |
4cc0665f MR |
3044 | be able to get rid of the assignment below, evetually. But it's |
3045 | still needed for now. */ | |
72a155b4 UW |
3046 | this_cache->saved_regs[gdbarch_num_regs (gdbarch) |
3047 | + mips_regnum (gdbarch)->pc] | |
4cc0665f | 3048 | = this_cache->saved_regs[gdbarch_num_regs (gdbarch) + MIPS_RA_REGNUM]; |
29639122 JB |
3049 | } |
3050 | ||
3051 | /* If we didn't reach the end of the prologue when scanning the function | |
3052 | instructions, then set end_prologue_addr to the address of the | |
4cc0665f MR |
3053 | instruction immediately after the last one we scanned. Unless the |
3054 | last one looked like a non-prologue instruction (and we looked ahead), | |
3055 | in which case use its address instead. */ | |
29639122 | 3056 | if (end_prologue_addr == 0) |
4cc0665f | 3057 | end_prologue_addr = prev_non_prologue_insn ? prev_pc : cur_pc; |
29639122 JB |
3058 | |
3059 | return end_prologue_addr; | |
eec63939 AC |
3060 | } |
3061 | ||
4cc0665f | 3062 | /* Heuristic unwinder for procedures using microMIPS instructions. |
29639122 | 3063 | Procedures that use the 32-bit instruction set are handled by the |
4cc0665f | 3064 | mips_insn32 unwinder. Likewise MIPS16 and the mips_insn16 unwinder. */ |
29639122 JB |
3065 | |
3066 | static struct mips_frame_cache * | |
4cc0665f | 3067 | mips_micro_frame_cache (struct frame_info *this_frame, void **this_cache) |
eec63939 | 3068 | { |
e17a4113 | 3069 | struct gdbarch *gdbarch = get_frame_arch (this_frame); |
29639122 | 3070 | struct mips_frame_cache *cache; |
eec63939 AC |
3071 | |
3072 | if ((*this_cache) != NULL) | |
3073 | return (*this_cache); | |
4cc0665f | 3074 | |
29639122 JB |
3075 | cache = FRAME_OBSTACK_ZALLOC (struct mips_frame_cache); |
3076 | (*this_cache) = cache; | |
b8a22b94 | 3077 | cache->saved_regs = trad_frame_alloc_saved_regs (this_frame); |
eec63939 | 3078 | |
29639122 JB |
3079 | /* Analyze the function prologue. */ |
3080 | { | |
b8a22b94 | 3081 | const CORE_ADDR pc = get_frame_address_in_block (this_frame); |
29639122 | 3082 | CORE_ADDR start_addr; |
eec63939 | 3083 | |
29639122 JB |
3084 | find_pc_partial_function (pc, NULL, &start_addr, NULL); |
3085 | if (start_addr == 0) | |
4cc0665f | 3086 | start_addr = heuristic_proc_start (get_frame_arch (this_frame), pc); |
29639122 JB |
3087 | /* We can't analyze the prologue if we couldn't find the begining |
3088 | of the function. */ | |
3089 | if (start_addr == 0) | |
3090 | return cache; | |
eec63939 | 3091 | |
4cc0665f | 3092 | micromips_scan_prologue (gdbarch, start_addr, pc, this_frame, *this_cache); |
29639122 | 3093 | } |
4cc0665f | 3094 | |
3e8c568d | 3095 | /* gdbarch_sp_regnum contains the value and not the address. */ |
72a155b4 | 3096 | trad_frame_set_value (cache->saved_regs, |
e17a4113 | 3097 | gdbarch_num_regs (gdbarch) + MIPS_SP_REGNUM, |
72a155b4 | 3098 | cache->base); |
eec63939 | 3099 | |
29639122 | 3100 | return (*this_cache); |
eec63939 AC |
3101 | } |
3102 | ||
3103 | static void | |
4cc0665f MR |
3104 | mips_micro_frame_this_id (struct frame_info *this_frame, void **this_cache, |
3105 | struct frame_id *this_id) | |
eec63939 | 3106 | { |
4cc0665f MR |
3107 | struct mips_frame_cache *info = mips_micro_frame_cache (this_frame, |
3108 | this_cache); | |
21327321 DJ |
3109 | /* This marks the outermost frame. */ |
3110 | if (info->base == 0) | |
3111 | return; | |
b8a22b94 | 3112 | (*this_id) = frame_id_build (info->base, get_frame_func (this_frame)); |
eec63939 AC |
3113 | } |
3114 | ||
b8a22b94 | 3115 | static struct value * |
4cc0665f MR |
3116 | mips_micro_frame_prev_register (struct frame_info *this_frame, |
3117 | void **this_cache, int regnum) | |
eec63939 | 3118 | { |
4cc0665f MR |
3119 | struct mips_frame_cache *info = mips_micro_frame_cache (this_frame, |
3120 | this_cache); | |
b8a22b94 DJ |
3121 | return trad_frame_get_prev_register (this_frame, info->saved_regs, regnum); |
3122 | } | |
3123 | ||
3124 | static int | |
4cc0665f MR |
3125 | mips_micro_frame_sniffer (const struct frame_unwind *self, |
3126 | struct frame_info *this_frame, void **this_cache) | |
b8a22b94 | 3127 | { |
4cc0665f | 3128 | struct gdbarch *gdbarch = get_frame_arch (this_frame); |
b8a22b94 | 3129 | CORE_ADDR pc = get_frame_pc (this_frame); |
4cc0665f MR |
3130 | |
3131 | if (mips_pc_is_micromips (gdbarch, pc)) | |
b8a22b94 DJ |
3132 | return 1; |
3133 | return 0; | |
eec63939 AC |
3134 | } |
3135 | ||
4cc0665f | 3136 | static const struct frame_unwind mips_micro_frame_unwind = |
eec63939 AC |
3137 | { |
3138 | NORMAL_FRAME, | |
8fbca658 | 3139 | default_frame_unwind_stop_reason, |
4cc0665f MR |
3140 | mips_micro_frame_this_id, |
3141 | mips_micro_frame_prev_register, | |
b8a22b94 | 3142 | NULL, |
4cc0665f | 3143 | mips_micro_frame_sniffer |
eec63939 AC |
3144 | }; |
3145 | ||
eec63939 | 3146 | static CORE_ADDR |
4cc0665f MR |
3147 | mips_micro_frame_base_address (struct frame_info *this_frame, |
3148 | void **this_cache) | |
eec63939 | 3149 | { |
4cc0665f MR |
3150 | struct mips_frame_cache *info = mips_micro_frame_cache (this_frame, |
3151 | this_cache); | |
29639122 | 3152 | return info->base; |
eec63939 AC |
3153 | } |
3154 | ||
4cc0665f | 3155 | static const struct frame_base mips_micro_frame_base = |
eec63939 | 3156 | { |
4cc0665f MR |
3157 | &mips_micro_frame_unwind, |
3158 | mips_micro_frame_base_address, | |
3159 | mips_micro_frame_base_address, | |
3160 | mips_micro_frame_base_address | |
eec63939 AC |
3161 | }; |
3162 | ||
3163 | static const struct frame_base * | |
4cc0665f | 3164 | mips_micro_frame_base_sniffer (struct frame_info *this_frame) |
eec63939 | 3165 | { |
4cc0665f | 3166 | struct gdbarch *gdbarch = get_frame_arch (this_frame); |
b8a22b94 | 3167 | CORE_ADDR pc = get_frame_pc (this_frame); |
4cc0665f MR |
3168 | |
3169 | if (mips_pc_is_micromips (gdbarch, pc)) | |
3170 | return &mips_micro_frame_base; | |
eec63939 AC |
3171 | else |
3172 | return NULL; | |
edfae063 AC |
3173 | } |
3174 | ||
29639122 JB |
3175 | /* Mark all the registers as unset in the saved_regs array |
3176 | of THIS_CACHE. Do nothing if THIS_CACHE is null. */ | |
3177 | ||
74ed0bb4 MD |
3178 | static void |
3179 | reset_saved_regs (struct gdbarch *gdbarch, struct mips_frame_cache *this_cache) | |
c906108c | 3180 | { |
29639122 JB |
3181 | if (this_cache == NULL || this_cache->saved_regs == NULL) |
3182 | return; | |
3183 | ||
3184 | { | |
74ed0bb4 | 3185 | const int num_regs = gdbarch_num_regs (gdbarch); |
29639122 | 3186 | int i; |
64159455 | 3187 | |
29639122 JB |
3188 | for (i = 0; i < num_regs; i++) |
3189 | { | |
3190 | this_cache->saved_regs[i].addr = -1; | |
3191 | } | |
3192 | } | |
c906108c SS |
3193 | } |
3194 | ||
025bb325 | 3195 | /* Analyze the function prologue from START_PC to LIMIT_PC. Builds |
29639122 JB |
3196 | the associated FRAME_CACHE if not null. |
3197 | Return the address of the first instruction past the prologue. */ | |
c906108c | 3198 | |
875e1767 | 3199 | static CORE_ADDR |
e17a4113 UW |
3200 | mips32_scan_prologue (struct gdbarch *gdbarch, |
3201 | CORE_ADDR start_pc, CORE_ADDR limit_pc, | |
b8a22b94 | 3202 | struct frame_info *this_frame, |
29639122 | 3203 | struct mips_frame_cache *this_cache) |
c906108c | 3204 | { |
29639122 | 3205 | CORE_ADDR cur_pc; |
025bb325 MS |
3206 | CORE_ADDR frame_addr = 0; /* Value of $r30. Used by gcc for |
3207 | frame-pointer. */ | |
29639122 JB |
3208 | CORE_ADDR sp; |
3209 | long frame_offset; | |
3210 | int frame_reg = MIPS_SP_REGNUM; | |
8fa9cfa1 | 3211 | |
29639122 JB |
3212 | CORE_ADDR end_prologue_addr = 0; |
3213 | int seen_sp_adjust = 0; | |
3214 | int load_immediate_bytes = 0; | |
db5f024e | 3215 | int in_delay_slot = 0; |
7d1e6fb8 | 3216 | int regsize_is_64_bits = (mips_abi_regsize (gdbarch) == 8); |
8fa9cfa1 | 3217 | |
29639122 | 3218 | /* Can be called when there's no process, and hence when there's no |
b8a22b94 DJ |
3219 | THIS_FRAME. */ |
3220 | if (this_frame != NULL) | |
3221 | sp = get_frame_register_signed (this_frame, | |
3222 | gdbarch_num_regs (gdbarch) | |
3223 | + MIPS_SP_REGNUM); | |
8fa9cfa1 | 3224 | else |
29639122 | 3225 | sp = 0; |
9022177c | 3226 | |
29639122 JB |
3227 | if (limit_pc > start_pc + 200) |
3228 | limit_pc = start_pc + 200; | |
9022177c | 3229 | |
29639122 | 3230 | restart: |
9022177c | 3231 | |
29639122 | 3232 | frame_offset = 0; |
95ac2dcf | 3233 | for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += MIPS_INSN32_SIZE) |
9022177c | 3234 | { |
29639122 JB |
3235 | unsigned long inst, high_word, low_word; |
3236 | int reg; | |
9022177c | 3237 | |
025bb325 | 3238 | /* Fetch the instruction. */ |
4cc0665f MR |
3239 | inst = (unsigned long) mips_fetch_instruction (gdbarch, ISA_MIPS, |
3240 | cur_pc, NULL); | |
9022177c | 3241 | |
29639122 JB |
3242 | /* Save some code by pre-extracting some useful fields. */ |
3243 | high_word = (inst >> 16) & 0xffff; | |
3244 | low_word = inst & 0xffff; | |
3245 | reg = high_word & 0x1f; | |
fe29b929 | 3246 | |
025bb325 | 3247 | if (high_word == 0x27bd /* addiu $sp,$sp,-i */ |
29639122 JB |
3248 | || high_word == 0x23bd /* addi $sp,$sp,-i */ |
3249 | || high_word == 0x67bd) /* daddiu $sp,$sp,-i */ | |
3250 | { | |
025bb325 | 3251 | if (low_word & 0x8000) /* Negative stack adjustment? */ |
29639122 JB |
3252 | frame_offset += 0x10000 - low_word; |
3253 | else | |
3254 | /* Exit loop if a positive stack adjustment is found, which | |
3255 | usually means that the stack cleanup code in the function | |
3256 | epilogue is reached. */ | |
3257 | break; | |
3258 | seen_sp_adjust = 1; | |
3259 | } | |
7d1e6fb8 KB |
3260 | else if (((high_word & 0xFFE0) == 0xafa0) /* sw reg,offset($sp) */ |
3261 | && !regsize_is_64_bits) | |
29639122 | 3262 | { |
74ed0bb4 | 3263 | set_reg_offset (gdbarch, this_cache, reg, sp + low_word); |
29639122 | 3264 | } |
7d1e6fb8 KB |
3265 | else if (((high_word & 0xFFE0) == 0xffa0) /* sd reg,offset($sp) */ |
3266 | && regsize_is_64_bits) | |
29639122 JB |
3267 | { |
3268 | /* Irix 6.2 N32 ABI uses sd instructions for saving $gp and $ra. */ | |
74ed0bb4 | 3269 | set_reg_offset (gdbarch, this_cache, reg, sp + low_word); |
29639122 JB |
3270 | } |
3271 | else if (high_word == 0x27be) /* addiu $30,$sp,size */ | |
3272 | { | |
3273 | /* Old gcc frame, r30 is virtual frame pointer. */ | |
3274 | if ((long) low_word != frame_offset) | |
3275 | frame_addr = sp + low_word; | |
b8a22b94 | 3276 | else if (this_frame && frame_reg == MIPS_SP_REGNUM) |
29639122 JB |
3277 | { |
3278 | unsigned alloca_adjust; | |
a4b8ebc8 | 3279 | |
29639122 | 3280 | frame_reg = 30; |
b8a22b94 DJ |
3281 | frame_addr = get_frame_register_signed |
3282 | (this_frame, gdbarch_num_regs (gdbarch) + 30); | |
ca9c94ef | 3283 | frame_offset = 0; |
d2ca4222 | 3284 | |
29639122 JB |
3285 | alloca_adjust = (unsigned) (frame_addr - (sp + low_word)); |
3286 | if (alloca_adjust > 0) | |
3287 | { | |
025bb325 | 3288 | /* FP > SP + frame_size. This may be because of |
29639122 JB |
3289 | an alloca or somethings similar. Fix sp to |
3290 | "pre-alloca" value, and try again. */ | |
3291 | sp += alloca_adjust; | |
3292 | /* Need to reset the status of all registers. Otherwise, | |
3293 | we will hit a guard that prevents the new address | |
3294 | for each register to be recomputed during the second | |
3295 | pass. */ | |
74ed0bb4 | 3296 | reset_saved_regs (gdbarch, this_cache); |
29639122 JB |
3297 | goto restart; |
3298 | } | |
3299 | } | |
3300 | } | |
3301 | /* move $30,$sp. With different versions of gas this will be either | |
3302 | `addu $30,$sp,$zero' or `or $30,$sp,$zero' or `daddu 30,sp,$0'. | |
3303 | Accept any one of these. */ | |
3304 | else if (inst == 0x03A0F021 || inst == 0x03a0f025 || inst == 0x03a0f02d) | |
3305 | { | |
3306 | /* New gcc frame, virtual frame pointer is at r30 + frame_size. */ | |
b8a22b94 | 3307 | if (this_frame && frame_reg == MIPS_SP_REGNUM) |
29639122 JB |
3308 | { |
3309 | unsigned alloca_adjust; | |
c906108c | 3310 | |
29639122 | 3311 | frame_reg = 30; |
b8a22b94 DJ |
3312 | frame_addr = get_frame_register_signed |
3313 | (this_frame, gdbarch_num_regs (gdbarch) + 30); | |
d2ca4222 | 3314 | |
29639122 JB |
3315 | alloca_adjust = (unsigned) (frame_addr - sp); |
3316 | if (alloca_adjust > 0) | |
3317 | { | |
025bb325 | 3318 | /* FP > SP + frame_size. This may be because of |
29639122 JB |
3319 | an alloca or somethings similar. Fix sp to |
3320 | "pre-alloca" value, and try again. */ | |
3321 | sp = frame_addr; | |
3322 | /* Need to reset the status of all registers. Otherwise, | |
3323 | we will hit a guard that prevents the new address | |
3324 | for each register to be recomputed during the second | |
3325 | pass. */ | |
74ed0bb4 | 3326 | reset_saved_regs (gdbarch, this_cache); |
29639122 JB |
3327 | goto restart; |
3328 | } | |
3329 | } | |
3330 | } | |
7d1e6fb8 KB |
3331 | else if ((high_word & 0xFFE0) == 0xafc0 /* sw reg,offset($30) */ |
3332 | && !regsize_is_64_bits) | |
29639122 | 3333 | { |
74ed0bb4 | 3334 | set_reg_offset (gdbarch, this_cache, reg, frame_addr + low_word); |
29639122 JB |
3335 | } |
3336 | else if ((high_word & 0xFFE0) == 0xE7A0 /* swc1 freg,n($sp) */ | |
3337 | || (high_word & 0xF3E0) == 0xA3C0 /* sx reg,n($s8) */ | |
3338 | || (inst & 0xFF9F07FF) == 0x00800021 /* move reg,$a0-$a3 */ | |
3339 | || high_word == 0x3c1c /* lui $gp,n */ | |
3340 | || high_word == 0x279c /* addiu $gp,$gp,n */ | |
3341 | || inst == 0x0399e021 /* addu $gp,$gp,$t9 */ | |
3342 | || inst == 0x033ce021 /* addu $gp,$t9,$gp */ | |
3343 | ) | |
19080931 MR |
3344 | { |
3345 | /* These instructions are part of the prologue, but we don't | |
3346 | need to do anything special to handle them. */ | |
3347 | } | |
29639122 JB |
3348 | /* The instructions below load $at or $t0 with an immediate |
3349 | value in preparation for a stack adjustment via | |
025bb325 | 3350 | subu $sp,$sp,[$at,$t0]. These instructions could also |
29639122 JB |
3351 | initialize a local variable, so we accept them only before |
3352 | a stack adjustment instruction was seen. */ | |
3353 | else if (!seen_sp_adjust | |
19080931 MR |
3354 | && (high_word == 0x3c01 /* lui $at,n */ |
3355 | || high_word == 0x3c08 /* lui $t0,n */ | |
3356 | || high_word == 0x3421 /* ori $at,$at,n */ | |
3357 | || high_word == 0x3508 /* ori $t0,$t0,n */ | |
3358 | || high_word == 0x3401 /* ori $at,$zero,n */ | |
3359 | || high_word == 0x3408 /* ori $t0,$zero,n */ | |
3360 | )) | |
3361 | { | |
3362 | if (end_prologue_addr == 0) | |
3363 | load_immediate_bytes += MIPS_INSN32_SIZE; /* FIXME! */ | |
3364 | } | |
29639122 | 3365 | else |
19080931 MR |
3366 | { |
3367 | /* This instruction is not an instruction typically found | |
3368 | in a prologue, so we must have reached the end of the | |
3369 | prologue. */ | |
3370 | /* FIXME: brobecker/2004-10-10: Can't we just break out of this | |
3371 | loop now? Why would we need to continue scanning the function | |
3372 | instructions? */ | |
3373 | if (end_prologue_addr == 0) | |
3374 | end_prologue_addr = cur_pc; | |
3375 | ||
3376 | /* Check for branches and jumps. For now, only jump to | |
3377 | register are caught (i.e. returns). */ | |
3378 | if ((itype_op (inst) & 0x07) == 0 && rtype_funct (inst) == 8) | |
3379 | in_delay_slot = 1; | |
3380 | } | |
db5f024e DJ |
3381 | |
3382 | /* If the previous instruction was a jump, we must have reached | |
3383 | the end of the prologue by now. Stop scanning so that we do | |
3384 | not go past the function return. */ | |
3385 | if (in_delay_slot) | |
3386 | break; | |
a4b8ebc8 | 3387 | } |
c906108c | 3388 | |
29639122 JB |
3389 | if (this_cache != NULL) |
3390 | { | |
3391 | this_cache->base = | |
b8a22b94 DJ |
3392 | (get_frame_register_signed (this_frame, |
3393 | gdbarch_num_regs (gdbarch) + frame_reg) | |
29639122 JB |
3394 | + frame_offset); |
3395 | /* FIXME: brobecker/2004-09-15: We should be able to get rid of | |
3396 | this assignment below, eventually. But it's still needed | |
3397 | for now. */ | |
72a155b4 UW |
3398 | this_cache->saved_regs[gdbarch_num_regs (gdbarch) |
3399 | + mips_regnum (gdbarch)->pc] | |
3400 | = this_cache->saved_regs[gdbarch_num_regs (gdbarch) | |
f57d151a | 3401 | + MIPS_RA_REGNUM]; |
29639122 | 3402 | } |
c906108c | 3403 | |
29639122 JB |
3404 | /* If we didn't reach the end of the prologue when scanning the function |
3405 | instructions, then set end_prologue_addr to the address of the | |
3406 | instruction immediately after the last one we scanned. */ | |
3407 | /* brobecker/2004-10-10: I don't think this would ever happen, but | |
3408 | we may as well be careful and do our best if we have a null | |
3409 | end_prologue_addr. */ | |
3410 | if (end_prologue_addr == 0) | |
3411 | end_prologue_addr = cur_pc; | |
3412 | ||
3413 | /* In a frameless function, we might have incorrectly | |
025bb325 | 3414 | skipped some load immediate instructions. Undo the skipping |
29639122 JB |
3415 | if the load immediate was not followed by a stack adjustment. */ |
3416 | if (load_immediate_bytes && !seen_sp_adjust) | |
3417 | end_prologue_addr -= load_immediate_bytes; | |
c906108c | 3418 | |
29639122 | 3419 | return end_prologue_addr; |
c906108c SS |
3420 | } |
3421 | ||
29639122 JB |
3422 | /* Heuristic unwinder for procedures using 32-bit instructions (covers |
3423 | both 32-bit and 64-bit MIPS ISAs). Procedures using 16-bit | |
3424 | instructions (a.k.a. MIPS16) are handled by the mips_insn16 | |
4cc0665f | 3425 | unwinder. Likewise microMIPS and the mips_micro unwinder. */ |
c906108c | 3426 | |
29639122 | 3427 | static struct mips_frame_cache * |
b8a22b94 | 3428 | mips_insn32_frame_cache (struct frame_info *this_frame, void **this_cache) |
c906108c | 3429 | { |
e17a4113 | 3430 | struct gdbarch *gdbarch = get_frame_arch (this_frame); |
29639122 | 3431 | struct mips_frame_cache *cache; |
c906108c | 3432 | |
29639122 JB |
3433 | if ((*this_cache) != NULL) |
3434 | return (*this_cache); | |
c5aa993b | 3435 | |
29639122 JB |
3436 | cache = FRAME_OBSTACK_ZALLOC (struct mips_frame_cache); |
3437 | (*this_cache) = cache; | |
b8a22b94 | 3438 | cache->saved_regs = trad_frame_alloc_saved_regs (this_frame); |
c5aa993b | 3439 | |
29639122 JB |
3440 | /* Analyze the function prologue. */ |
3441 | { | |
b8a22b94 | 3442 | const CORE_ADDR pc = get_frame_address_in_block (this_frame); |
29639122 | 3443 | CORE_ADDR start_addr; |
c906108c | 3444 | |
29639122 JB |
3445 | find_pc_partial_function (pc, NULL, &start_addr, NULL); |
3446 | if (start_addr == 0) | |
e17a4113 | 3447 | start_addr = heuristic_proc_start (gdbarch, pc); |
29639122 JB |
3448 | /* We can't analyze the prologue if we couldn't find the begining |
3449 | of the function. */ | |
3450 | if (start_addr == 0) | |
3451 | return cache; | |
c5aa993b | 3452 | |
e17a4113 | 3453 | mips32_scan_prologue (gdbarch, start_addr, pc, this_frame, *this_cache); |
29639122 JB |
3454 | } |
3455 | ||
3e8c568d | 3456 | /* gdbarch_sp_regnum contains the value and not the address. */ |
f57d151a | 3457 | trad_frame_set_value (cache->saved_regs, |
e17a4113 | 3458 | gdbarch_num_regs (gdbarch) + MIPS_SP_REGNUM, |
f57d151a | 3459 | cache->base); |
c5aa993b | 3460 | |
29639122 | 3461 | return (*this_cache); |
c906108c SS |
3462 | } |
3463 | ||
29639122 | 3464 | static void |
b8a22b94 | 3465 | mips_insn32_frame_this_id (struct frame_info *this_frame, void **this_cache, |
29639122 | 3466 | struct frame_id *this_id) |
c906108c | 3467 | { |
b8a22b94 | 3468 | struct mips_frame_cache *info = mips_insn32_frame_cache (this_frame, |
29639122 | 3469 | this_cache); |
21327321 DJ |
3470 | /* This marks the outermost frame. */ |
3471 | if (info->base == 0) | |
3472 | return; | |
b8a22b94 | 3473 | (*this_id) = frame_id_build (info->base, get_frame_func (this_frame)); |
29639122 | 3474 | } |
c906108c | 3475 | |
b8a22b94 DJ |
3476 | static struct value * |
3477 | mips_insn32_frame_prev_register (struct frame_info *this_frame, | |
3478 | void **this_cache, int regnum) | |
29639122 | 3479 | { |
b8a22b94 | 3480 | struct mips_frame_cache *info = mips_insn32_frame_cache (this_frame, |
29639122 | 3481 | this_cache); |
b8a22b94 DJ |
3482 | return trad_frame_get_prev_register (this_frame, info->saved_regs, regnum); |
3483 | } | |
3484 | ||
3485 | static int | |
3486 | mips_insn32_frame_sniffer (const struct frame_unwind *self, | |
3487 | struct frame_info *this_frame, void **this_cache) | |
3488 | { | |
3489 | CORE_ADDR pc = get_frame_pc (this_frame); | |
4cc0665f | 3490 | if (mips_pc_is_mips (pc)) |
b8a22b94 DJ |
3491 | return 1; |
3492 | return 0; | |
c906108c SS |
3493 | } |
3494 | ||
29639122 JB |
3495 | static const struct frame_unwind mips_insn32_frame_unwind = |
3496 | { | |
3497 | NORMAL_FRAME, | |
8fbca658 | 3498 | default_frame_unwind_stop_reason, |
29639122 | 3499 | mips_insn32_frame_this_id, |
b8a22b94 DJ |
3500 | mips_insn32_frame_prev_register, |
3501 | NULL, | |
3502 | mips_insn32_frame_sniffer | |
29639122 | 3503 | }; |
c906108c | 3504 | |
1c645fec | 3505 | static CORE_ADDR |
b8a22b94 | 3506 | mips_insn32_frame_base_address (struct frame_info *this_frame, |
29639122 | 3507 | void **this_cache) |
c906108c | 3508 | { |
b8a22b94 | 3509 | struct mips_frame_cache *info = mips_insn32_frame_cache (this_frame, |
29639122 JB |
3510 | this_cache); |
3511 | return info->base; | |
3512 | } | |
c906108c | 3513 | |
29639122 JB |
3514 | static const struct frame_base mips_insn32_frame_base = |
3515 | { | |
3516 | &mips_insn32_frame_unwind, | |
3517 | mips_insn32_frame_base_address, | |
3518 | mips_insn32_frame_base_address, | |
3519 | mips_insn32_frame_base_address | |
3520 | }; | |
1c645fec | 3521 | |
29639122 | 3522 | static const struct frame_base * |
b8a22b94 | 3523 | mips_insn32_frame_base_sniffer (struct frame_info *this_frame) |
29639122 | 3524 | { |
b8a22b94 | 3525 | CORE_ADDR pc = get_frame_pc (this_frame); |
4cc0665f | 3526 | if (mips_pc_is_mips (pc)) |
29639122 | 3527 | return &mips_insn32_frame_base; |
a65bbe44 | 3528 | else |
29639122 JB |
3529 | return NULL; |
3530 | } | |
a65bbe44 | 3531 | |
29639122 | 3532 | static struct trad_frame_cache * |
b8a22b94 | 3533 | mips_stub_frame_cache (struct frame_info *this_frame, void **this_cache) |
29639122 JB |
3534 | { |
3535 | CORE_ADDR pc; | |
3536 | CORE_ADDR start_addr; | |
3537 | CORE_ADDR stack_addr; | |
3538 | struct trad_frame_cache *this_trad_cache; | |
b8a22b94 DJ |
3539 | struct gdbarch *gdbarch = get_frame_arch (this_frame); |
3540 | int num_regs = gdbarch_num_regs (gdbarch); | |
c906108c | 3541 | |
29639122 JB |
3542 | if ((*this_cache) != NULL) |
3543 | return (*this_cache); | |
b8a22b94 | 3544 | this_trad_cache = trad_frame_cache_zalloc (this_frame); |
29639122 | 3545 | (*this_cache) = this_trad_cache; |
1c645fec | 3546 | |
29639122 | 3547 | /* The return address is in the link register. */ |
3e8c568d | 3548 | trad_frame_set_reg_realreg (this_trad_cache, |
72a155b4 | 3549 | gdbarch_pc_regnum (gdbarch), |
b8a22b94 | 3550 | num_regs + MIPS_RA_REGNUM); |
1c645fec | 3551 | |
29639122 JB |
3552 | /* Frame ID, since it's a frameless / stackless function, no stack |
3553 | space is allocated and SP on entry is the current SP. */ | |
b8a22b94 | 3554 | pc = get_frame_pc (this_frame); |
29639122 | 3555 | find_pc_partial_function (pc, NULL, &start_addr, NULL); |
b8a22b94 DJ |
3556 | stack_addr = get_frame_register_signed (this_frame, |
3557 | num_regs + MIPS_SP_REGNUM); | |
aa6c981f | 3558 | trad_frame_set_id (this_trad_cache, frame_id_build (stack_addr, start_addr)); |
1c645fec | 3559 | |
29639122 JB |
3560 | /* Assume that the frame's base is the same as the |
3561 | stack-pointer. */ | |
3562 | trad_frame_set_this_base (this_trad_cache, stack_addr); | |
c906108c | 3563 | |
29639122 JB |
3564 | return this_trad_cache; |
3565 | } | |
c906108c | 3566 | |
29639122 | 3567 | static void |
b8a22b94 | 3568 | mips_stub_frame_this_id (struct frame_info *this_frame, void **this_cache, |
29639122 JB |
3569 | struct frame_id *this_id) |
3570 | { | |
3571 | struct trad_frame_cache *this_trad_cache | |
b8a22b94 | 3572 | = mips_stub_frame_cache (this_frame, this_cache); |
29639122 JB |
3573 | trad_frame_get_id (this_trad_cache, this_id); |
3574 | } | |
c906108c | 3575 | |
b8a22b94 DJ |
3576 | static struct value * |
3577 | mips_stub_frame_prev_register (struct frame_info *this_frame, | |
3578 | void **this_cache, int regnum) | |
29639122 JB |
3579 | { |
3580 | struct trad_frame_cache *this_trad_cache | |
b8a22b94 DJ |
3581 | = mips_stub_frame_cache (this_frame, this_cache); |
3582 | return trad_frame_get_register (this_trad_cache, this_frame, regnum); | |
29639122 | 3583 | } |
c906108c | 3584 | |
b8a22b94 DJ |
3585 | static int |
3586 | mips_stub_frame_sniffer (const struct frame_unwind *self, | |
3587 | struct frame_info *this_frame, void **this_cache) | |
29639122 | 3588 | { |
aa6c981f | 3589 | gdb_byte dummy[4]; |
979b38e0 | 3590 | struct obj_section *s; |
b8a22b94 | 3591 | CORE_ADDR pc = get_frame_address_in_block (this_frame); |
7cbd4a93 | 3592 | struct bound_minimal_symbol msym; |
979b38e0 | 3593 | |
aa6c981f | 3594 | /* Use the stub unwinder for unreadable code. */ |
b8a22b94 DJ |
3595 | if (target_read_memory (get_frame_pc (this_frame), dummy, 4) != 0) |
3596 | return 1; | |
aa6c981f | 3597 | |
3e5d3a5a | 3598 | if (in_plt_section (pc) || in_mips_stubs_section (pc)) |
b8a22b94 | 3599 | return 1; |
979b38e0 | 3600 | |
db5f024e DJ |
3601 | /* Calling a PIC function from a non-PIC function passes through a |
3602 | stub. The stub for foo is named ".pic.foo". */ | |
3603 | msym = lookup_minimal_symbol_by_pc (pc); | |
7cbd4a93 TT |
3604 | if (msym.minsym != NULL |
3605 | && SYMBOL_LINKAGE_NAME (msym.minsym) != NULL | |
3606 | && strncmp (SYMBOL_LINKAGE_NAME (msym.minsym), ".pic.", 5) == 0) | |
db5f024e DJ |
3607 | return 1; |
3608 | ||
b8a22b94 | 3609 | return 0; |
29639122 | 3610 | } |
c906108c | 3611 | |
b8a22b94 DJ |
3612 | static const struct frame_unwind mips_stub_frame_unwind = |
3613 | { | |
3614 | NORMAL_FRAME, | |
8fbca658 | 3615 | default_frame_unwind_stop_reason, |
b8a22b94 DJ |
3616 | mips_stub_frame_this_id, |
3617 | mips_stub_frame_prev_register, | |
3618 | NULL, | |
3619 | mips_stub_frame_sniffer | |
3620 | }; | |
3621 | ||
29639122 | 3622 | static CORE_ADDR |
b8a22b94 | 3623 | mips_stub_frame_base_address (struct frame_info *this_frame, |
29639122 JB |
3624 | void **this_cache) |
3625 | { | |
3626 | struct trad_frame_cache *this_trad_cache | |
b8a22b94 | 3627 | = mips_stub_frame_cache (this_frame, this_cache); |
29639122 JB |
3628 | return trad_frame_get_this_base (this_trad_cache); |
3629 | } | |
0fce0821 | 3630 | |
29639122 JB |
3631 | static const struct frame_base mips_stub_frame_base = |
3632 | { | |
3633 | &mips_stub_frame_unwind, | |
3634 | mips_stub_frame_base_address, | |
3635 | mips_stub_frame_base_address, | |
3636 | mips_stub_frame_base_address | |
3637 | }; | |
3638 | ||
3639 | static const struct frame_base * | |
b8a22b94 | 3640 | mips_stub_frame_base_sniffer (struct frame_info *this_frame) |
29639122 | 3641 | { |
b8a22b94 | 3642 | if (mips_stub_frame_sniffer (&mips_stub_frame_unwind, this_frame, NULL)) |
29639122 JB |
3643 | return &mips_stub_frame_base; |
3644 | else | |
3645 | return NULL; | |
3646 | } | |
3647 | ||
29639122 | 3648 | /* mips_addr_bits_remove - remove useless address bits */ |
65596487 | 3649 | |
29639122 | 3650 | static CORE_ADDR |
24568a2c | 3651 | mips_addr_bits_remove (struct gdbarch *gdbarch, CORE_ADDR addr) |
65596487 | 3652 | { |
24568a2c | 3653 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
930bd0e0 | 3654 | |
4cc0665f MR |
3655 | if (is_compact_addr (addr)) |
3656 | addr = unmake_compact_addr (addr); | |
930bd0e0 | 3657 | |
29639122 JB |
3658 | if (mips_mask_address_p (tdep) && (((ULONGEST) addr) >> 32 == 0xffffffffUL)) |
3659 | /* This hack is a work-around for existing boards using PMON, the | |
3660 | simulator, and any other 64-bit targets that doesn't have true | |
3661 | 64-bit addressing. On these targets, the upper 32 bits of | |
3662 | addresses are ignored by the hardware. Thus, the PC or SP are | |
3663 | likely to have been sign extended to all 1s by instruction | |
3664 | sequences that load 32-bit addresses. For example, a typical | |
3665 | piece of code that loads an address is this: | |
65596487 | 3666 | |
29639122 JB |
3667 | lui $r2, <upper 16 bits> |
3668 | ori $r2, <lower 16 bits> | |
65596487 | 3669 | |
29639122 JB |
3670 | But the lui sign-extends the value such that the upper 32 bits |
3671 | may be all 1s. The workaround is simply to mask off these | |
3672 | bits. In the future, gcc may be changed to support true 64-bit | |
3673 | addressing, and this masking will have to be disabled. */ | |
3674 | return addr &= 0xffffffffUL; | |
3675 | else | |
3676 | return addr; | |
65596487 JB |
3677 | } |
3678 | ||
3d5f6d12 DJ |
3679 | |
3680 | /* Checks for an atomic sequence of instructions beginning with a LL/LLD | |
3681 | instruction and ending with a SC/SCD instruction. If such a sequence | |
3682 | is found, attempt to step through it. A breakpoint is placed at the end of | |
3683 | the sequence. */ | |
3684 | ||
4cc0665f MR |
3685 | /* Instructions used during single-stepping of atomic sequences, standard |
3686 | ISA version. */ | |
3687 | #define LL_OPCODE 0x30 | |
3688 | #define LLD_OPCODE 0x34 | |
3689 | #define SC_OPCODE 0x38 | |
3690 | #define SCD_OPCODE 0x3c | |
3691 | ||
3d5f6d12 | 3692 | static int |
4cc0665f MR |
3693 | mips_deal_with_atomic_sequence (struct gdbarch *gdbarch, |
3694 | struct address_space *aspace, CORE_ADDR pc) | |
3d5f6d12 DJ |
3695 | { |
3696 | CORE_ADDR breaks[2] = {-1, -1}; | |
3697 | CORE_ADDR loc = pc; | |
3698 | CORE_ADDR branch_bp; /* Breakpoint at branch instruction's destination. */ | |
4cc0665f | 3699 | ULONGEST insn; |
3d5f6d12 DJ |
3700 | int insn_count; |
3701 | int index; | |
3702 | int last_breakpoint = 0; /* Defaults to 0 (no breakpoints placed). */ | |
3703 | const int atomic_sequence_length = 16; /* Instruction sequence length. */ | |
3704 | ||
4cc0665f | 3705 | insn = mips_fetch_instruction (gdbarch, ISA_MIPS, loc, NULL); |
3d5f6d12 DJ |
3706 | /* Assume all atomic sequences start with a ll/lld instruction. */ |
3707 | if (itype_op (insn) != LL_OPCODE && itype_op (insn) != LLD_OPCODE) | |
3708 | return 0; | |
3709 | ||
3710 | /* Assume that no atomic sequence is longer than "atomic_sequence_length" | |
3711 | instructions. */ | |
3712 | for (insn_count = 0; insn_count < atomic_sequence_length; ++insn_count) | |
3713 | { | |
3714 | int is_branch = 0; | |
3715 | loc += MIPS_INSN32_SIZE; | |
4cc0665f | 3716 | insn = mips_fetch_instruction (gdbarch, ISA_MIPS, loc, NULL); |
3d5f6d12 DJ |
3717 | |
3718 | /* Assume that there is at most one branch in the atomic | |
3719 | sequence. If a branch is found, put a breakpoint in its | |
3720 | destination address. */ | |
3721 | switch (itype_op (insn)) | |
3722 | { | |
3723 | case 0: /* SPECIAL */ | |
3724 | if (rtype_funct (insn) >> 1 == 4) /* JR, JALR */ | |
025bb325 | 3725 | return 0; /* fallback to the standard single-step code. */ |
3d5f6d12 DJ |
3726 | break; |
3727 | case 1: /* REGIMM */ | |
a385295e MR |
3728 | is_branch = ((itype_rt (insn) & 0xc) == 0 /* B{LT,GE}Z* */ |
3729 | || ((itype_rt (insn) & 0x1e) == 0 | |
3730 | && itype_rs (insn) == 0)); /* BPOSGE* */ | |
3d5f6d12 DJ |
3731 | break; |
3732 | case 2: /* J */ | |
3733 | case 3: /* JAL */ | |
025bb325 | 3734 | return 0; /* fallback to the standard single-step code. */ |
3d5f6d12 DJ |
3735 | case 4: /* BEQ */ |
3736 | case 5: /* BNE */ | |
3737 | case 6: /* BLEZ */ | |
3738 | case 7: /* BGTZ */ | |
3739 | case 20: /* BEQL */ | |
3740 | case 21: /* BNEL */ | |
3741 | case 22: /* BLEZL */ | |
3742 | case 23: /* BGTTL */ | |
3743 | is_branch = 1; | |
3744 | break; | |
3745 | case 17: /* COP1 */ | |
a385295e MR |
3746 | is_branch = ((itype_rs (insn) == 9 || itype_rs (insn) == 10) |
3747 | && (itype_rt (insn) & 0x2) == 0); | |
3748 | if (is_branch) /* BC1ANY2F, BC1ANY2T, BC1ANY4F, BC1ANY4T */ | |
3749 | break; | |
3750 | /* Fall through. */ | |
3d5f6d12 DJ |
3751 | case 18: /* COP2 */ |
3752 | case 19: /* COP3 */ | |
3753 | is_branch = (itype_rs (insn) == 8); /* BCzF, BCzFL, BCzT, BCzTL */ | |
3754 | break; | |
3755 | } | |
3756 | if (is_branch) | |
3757 | { | |
3758 | branch_bp = loc + mips32_relative_offset (insn) + 4; | |
3759 | if (last_breakpoint >= 1) | |
3760 | return 0; /* More than one branch found, fallback to the | |
3761 | standard single-step code. */ | |
3762 | breaks[1] = branch_bp; | |
3763 | last_breakpoint++; | |
3764 | } | |
3765 | ||
3766 | if (itype_op (insn) == SC_OPCODE || itype_op (insn) == SCD_OPCODE) | |
3767 | break; | |
3768 | } | |
3769 | ||
3770 | /* Assume that the atomic sequence ends with a sc/scd instruction. */ | |
3771 | if (itype_op (insn) != SC_OPCODE && itype_op (insn) != SCD_OPCODE) | |
3772 | return 0; | |
3773 | ||
3774 | loc += MIPS_INSN32_SIZE; | |
3775 | ||
3776 | /* Insert a breakpoint right after the end of the atomic sequence. */ | |
3777 | breaks[0] = loc; | |
3778 | ||
3779 | /* Check for duplicated breakpoints. Check also for a breakpoint | |
025bb325 | 3780 | placed (branch instruction's destination) in the atomic sequence. */ |
3d5f6d12 DJ |
3781 | if (last_breakpoint && pc <= breaks[1] && breaks[1] <= breaks[0]) |
3782 | last_breakpoint = 0; | |
3783 | ||
3784 | /* Effectively inserts the breakpoints. */ | |
3785 | for (index = 0; index <= last_breakpoint; index++) | |
6c95b8df | 3786 | insert_single_step_breakpoint (gdbarch, aspace, breaks[index]); |
3d5f6d12 DJ |
3787 | |
3788 | return 1; | |
3789 | } | |
3790 | ||
4cc0665f MR |
3791 | static int |
3792 | micromips_deal_with_atomic_sequence (struct gdbarch *gdbarch, | |
3793 | struct address_space *aspace, | |
3794 | CORE_ADDR pc) | |
3795 | { | |
3796 | const int atomic_sequence_length = 16; /* Instruction sequence length. */ | |
3797 | int last_breakpoint = 0; /* Defaults to 0 (no breakpoints placed). */ | |
3798 | CORE_ADDR breaks[2] = {-1, -1}; | |
4b844a38 AT |
3799 | CORE_ADDR branch_bp = 0; /* Breakpoint at branch instruction's |
3800 | destination. */ | |
4cc0665f MR |
3801 | CORE_ADDR loc = pc; |
3802 | int sc_found = 0; | |
3803 | ULONGEST insn; | |
3804 | int insn_count; | |
3805 | int index; | |
3806 | ||
3807 | /* Assume all atomic sequences start with a ll/lld instruction. */ | |
3808 | insn = mips_fetch_instruction (gdbarch, ISA_MICROMIPS, loc, NULL); | |
3809 | if (micromips_op (insn) != 0x18) /* POOL32C: bits 011000 */ | |
3810 | return 0; | |
3811 | loc += MIPS_INSN16_SIZE; | |
3812 | insn <<= 16; | |
3813 | insn |= mips_fetch_instruction (gdbarch, ISA_MICROMIPS, loc, NULL); | |
3814 | if ((b12s4_op (insn) & 0xb) != 0x3) /* LL, LLD: bits 011000 0x11 */ | |
3815 | return 0; | |
3816 | loc += MIPS_INSN16_SIZE; | |
3817 | ||
3818 | /* Assume all atomic sequences end with an sc/scd instruction. Assume | |
3819 | that no atomic sequence is longer than "atomic_sequence_length" | |
3820 | instructions. */ | |
3821 | for (insn_count = 0; | |
3822 | !sc_found && insn_count < atomic_sequence_length; | |
3823 | ++insn_count) | |
3824 | { | |
3825 | int is_branch = 0; | |
3826 | ||
3827 | insn = mips_fetch_instruction (gdbarch, ISA_MICROMIPS, loc, NULL); | |
3828 | loc += MIPS_INSN16_SIZE; | |
3829 | ||
3830 | /* Assume that there is at most one conditional branch in the | |
3831 | atomic sequence. If a branch is found, put a breakpoint in | |
3832 | its destination address. */ | |
3833 | switch (mips_insn_size (ISA_MICROMIPS, insn)) | |
3834 | { | |
3835 | /* 48-bit instructions. */ | |
3836 | case 3 * MIPS_INSN16_SIZE: /* POOL48A: bits 011111 */ | |
3837 | loc += 2 * MIPS_INSN16_SIZE; | |
3838 | break; | |
3839 | ||
3840 | /* 32-bit instructions. */ | |
3841 | case 2 * MIPS_INSN16_SIZE: | |
3842 | switch (micromips_op (insn)) | |
3843 | { | |
3844 | case 0x10: /* POOL32I: bits 010000 */ | |
3845 | if ((b5s5_op (insn) & 0x18) != 0x0 | |
3846 | /* BLTZ, BLTZAL, BGEZ, BGEZAL: 010000 000xx */ | |
3847 | /* BLEZ, BNEZC, BGTZ, BEQZC: 010000 001xx */ | |
3848 | && (b5s5_op (insn) & 0x1d) != 0x11 | |
3849 | /* BLTZALS, BGEZALS: bits 010000 100x1 */ | |
3850 | && ((b5s5_op (insn) & 0x1e) != 0x14 | |
3851 | || (insn & 0x3) != 0x0) | |
3852 | /* BC2F, BC2T: bits 010000 1010x xxx00 */ | |
3853 | && (b5s5_op (insn) & 0x1e) != 0x1a | |
3854 | /* BPOSGE64, BPOSGE32: bits 010000 1101x */ | |
3855 | && ((b5s5_op (insn) & 0x1e) != 0x1c | |
3856 | || (insn & 0x3) != 0x0) | |
3857 | /* BC1F, BC1T: bits 010000 1110x xxx00 */ | |
3858 | && ((b5s5_op (insn) & 0x1c) != 0x1c | |
3859 | || (insn & 0x3) != 0x1)) | |
3860 | /* BC1ANY*: bits 010000 111xx xxx01 */ | |
3861 | break; | |
3862 | /* Fall through. */ | |
3863 | ||
3864 | case 0x25: /* BEQ: bits 100101 */ | |
3865 | case 0x2d: /* BNE: bits 101101 */ | |
3866 | insn <<= 16; | |
3867 | insn |= mips_fetch_instruction (gdbarch, | |
3868 | ISA_MICROMIPS, loc, NULL); | |
3869 | branch_bp = (loc + MIPS_INSN16_SIZE | |
3870 | + micromips_relative_offset16 (insn)); | |
3871 | is_branch = 1; | |
3872 | break; | |
3873 | ||
3874 | case 0x00: /* POOL32A: bits 000000 */ | |
3875 | insn <<= 16; | |
3876 | insn |= mips_fetch_instruction (gdbarch, | |
3877 | ISA_MICROMIPS, loc, NULL); | |
3878 | if (b0s6_op (insn) != 0x3c | |
3879 | /* POOL32Axf: bits 000000 ... 111100 */ | |
3880 | || (b6s10_ext (insn) & 0x2bf) != 0x3c) | |
3881 | /* JALR, JALR.HB: 000000 000x111100 111100 */ | |
3882 | /* JALRS, JALRS.HB: 000000 010x111100 111100 */ | |
3883 | break; | |
3884 | /* Fall through. */ | |
3885 | ||
3886 | case 0x1d: /* JALS: bits 011101 */ | |
3887 | case 0x35: /* J: bits 110101 */ | |
3888 | case 0x3d: /* JAL: bits 111101 */ | |
3889 | case 0x3c: /* JALX: bits 111100 */ | |
3890 | return 0; /* Fall back to the standard single-step code. */ | |
3891 | ||
3892 | case 0x18: /* POOL32C: bits 011000 */ | |
3893 | if ((b12s4_op (insn) & 0xb) == 0xb) | |
3894 | /* SC, SCD: bits 011000 1x11 */ | |
3895 | sc_found = 1; | |
3896 | break; | |
3897 | } | |
3898 | loc += MIPS_INSN16_SIZE; | |
3899 | break; | |
3900 | ||
3901 | /* 16-bit instructions. */ | |
3902 | case MIPS_INSN16_SIZE: | |
3903 | switch (micromips_op (insn)) | |
3904 | { | |
3905 | case 0x23: /* BEQZ16: bits 100011 */ | |
3906 | case 0x2b: /* BNEZ16: bits 101011 */ | |
3907 | branch_bp = loc + micromips_relative_offset7 (insn); | |
3908 | is_branch = 1; | |
3909 | break; | |
3910 | ||
3911 | case 0x11: /* POOL16C: bits 010001 */ | |
3912 | if ((b5s5_op (insn) & 0x1c) != 0xc | |
3913 | /* JR16, JRC, JALR16, JALRS16: 010001 011xx */ | |
3914 | && b5s5_op (insn) != 0x18) | |
3915 | /* JRADDIUSP: bits 010001 11000 */ | |
3916 | break; | |
3917 | return 0; /* Fall back to the standard single-step code. */ | |
3918 | ||
3919 | case 0x33: /* B16: bits 110011 */ | |
3920 | return 0; /* Fall back to the standard single-step code. */ | |
3921 | } | |
3922 | break; | |
3923 | } | |
3924 | if (is_branch) | |
3925 | { | |
3926 | if (last_breakpoint >= 1) | |
3927 | return 0; /* More than one branch found, fallback to the | |
3928 | standard single-step code. */ | |
3929 | breaks[1] = branch_bp; | |
3930 | last_breakpoint++; | |
3931 | } | |
3932 | } | |
3933 | if (!sc_found) | |
3934 | return 0; | |
3935 | ||
3936 | /* Insert a breakpoint right after the end of the atomic sequence. */ | |
3937 | breaks[0] = loc; | |
3938 | ||
3939 | /* Check for duplicated breakpoints. Check also for a breakpoint | |
3940 | placed (branch instruction's destination) in the atomic sequence */ | |
3941 | if (last_breakpoint && pc <= breaks[1] && breaks[1] <= breaks[0]) | |
3942 | last_breakpoint = 0; | |
3943 | ||
3944 | /* Effectively inserts the breakpoints. */ | |
3945 | for (index = 0; index <= last_breakpoint; index++) | |
3373342d | 3946 | insert_single_step_breakpoint (gdbarch, aspace, breaks[index]); |
4cc0665f MR |
3947 | |
3948 | return 1; | |
3949 | } | |
3950 | ||
3951 | static int | |
3952 | deal_with_atomic_sequence (struct gdbarch *gdbarch, | |
3953 | struct address_space *aspace, CORE_ADDR pc) | |
3954 | { | |
3955 | if (mips_pc_is_mips (pc)) | |
3956 | return mips_deal_with_atomic_sequence (gdbarch, aspace, pc); | |
3957 | else if (mips_pc_is_micromips (gdbarch, pc)) | |
3958 | return micromips_deal_with_atomic_sequence (gdbarch, aspace, pc); | |
3959 | else | |
3960 | return 0; | |
3961 | } | |
3962 | ||
29639122 JB |
3963 | /* mips_software_single_step() is called just before we want to resume |
3964 | the inferior, if we want to single-step it but there is no hardware | |
3965 | or kernel single-step support (MIPS on GNU/Linux for example). We find | |
e0cd558a | 3966 | the target of the coming instruction and breakpoint it. */ |
29639122 | 3967 | |
e6590a1b | 3968 | int |
0b1b3e42 | 3969 | mips_software_single_step (struct frame_info *frame) |
c906108c | 3970 | { |
a6d9a66e | 3971 | struct gdbarch *gdbarch = get_frame_arch (frame); |
6c95b8df | 3972 | struct address_space *aspace = get_frame_address_space (frame); |
8181d85f | 3973 | CORE_ADDR pc, next_pc; |
65596487 | 3974 | |
0b1b3e42 | 3975 | pc = get_frame_pc (frame); |
6c95b8df | 3976 | if (deal_with_atomic_sequence (gdbarch, aspace, pc)) |
3d5f6d12 DJ |
3977 | return 1; |
3978 | ||
0b1b3e42 | 3979 | next_pc = mips_next_pc (frame, pc); |
e6590a1b | 3980 | |
6c95b8df | 3981 | insert_single_step_breakpoint (gdbarch, aspace, next_pc); |
e6590a1b | 3982 | return 1; |
29639122 | 3983 | } |
a65bbe44 | 3984 | |
29639122 | 3985 | /* Test whether the PC points to the return instruction at the |
025bb325 | 3986 | end of a function. */ |
65596487 | 3987 | |
29639122 | 3988 | static int |
e17a4113 | 3989 | mips_about_to_return (struct gdbarch *gdbarch, CORE_ADDR pc) |
29639122 | 3990 | { |
6321c22a MR |
3991 | ULONGEST insn; |
3992 | ULONGEST hint; | |
3993 | ||
3994 | /* This used to check for MIPS16, but this piece of code is never | |
4cc0665f MR |
3995 | called for MIPS16 functions. And likewise microMIPS ones. */ |
3996 | gdb_assert (mips_pc_is_mips (pc)); | |
6321c22a | 3997 | |
4cc0665f | 3998 | insn = mips_fetch_instruction (gdbarch, ISA_MIPS, pc, NULL); |
6321c22a MR |
3999 | hint = 0x7c0; |
4000 | return (insn & ~hint) == 0x3e00008; /* jr(.hb) $ra */ | |
29639122 | 4001 | } |
c906108c | 4002 | |
c906108c | 4003 | |
29639122 JB |
4004 | /* This fencepost looks highly suspicious to me. Removing it also |
4005 | seems suspicious as it could affect remote debugging across serial | |
4006 | lines. */ | |
c906108c | 4007 | |
29639122 | 4008 | static CORE_ADDR |
74ed0bb4 | 4009 | heuristic_proc_start (struct gdbarch *gdbarch, CORE_ADDR pc) |
29639122 JB |
4010 | { |
4011 | CORE_ADDR start_pc; | |
4012 | CORE_ADDR fence; | |
4013 | int instlen; | |
4014 | int seen_adjsp = 0; | |
d6b48e9c | 4015 | struct inferior *inf; |
65596487 | 4016 | |
74ed0bb4 | 4017 | pc = gdbarch_addr_bits_remove (gdbarch, pc); |
29639122 JB |
4018 | start_pc = pc; |
4019 | fence = start_pc - heuristic_fence_post; | |
4020 | if (start_pc == 0) | |
4021 | return 0; | |
65596487 | 4022 | |
44096aee | 4023 | if (heuristic_fence_post == -1 || fence < VM_MIN_ADDRESS) |
29639122 | 4024 | fence = VM_MIN_ADDRESS; |
65596487 | 4025 | |
4cc0665f | 4026 | instlen = mips_pc_is_mips (pc) ? MIPS_INSN32_SIZE : MIPS_INSN16_SIZE; |
98b4dd94 | 4027 | |
d6b48e9c PA |
4028 | inf = current_inferior (); |
4029 | ||
025bb325 | 4030 | /* Search back for previous return. */ |
29639122 JB |
4031 | for (start_pc -= instlen;; start_pc -= instlen) |
4032 | if (start_pc < fence) | |
4033 | { | |
4034 | /* It's not clear to me why we reach this point when | |
4035 | stop_soon, but with this test, at least we | |
4036 | don't print out warnings for every child forked (eg, on | |
4037 | decstation). 22apr93 rich@cygnus.com. */ | |
16c381f0 | 4038 | if (inf->control.stop_soon == NO_STOP_QUIETLY) |
29639122 JB |
4039 | { |
4040 | static int blurb_printed = 0; | |
98b4dd94 | 4041 | |
5af949e3 UW |
4042 | warning (_("GDB can't find the start of the function at %s."), |
4043 | paddress (gdbarch, pc)); | |
29639122 JB |
4044 | |
4045 | if (!blurb_printed) | |
4046 | { | |
4047 | /* This actually happens frequently in embedded | |
4048 | development, when you first connect to a board | |
4049 | and your stack pointer and pc are nowhere in | |
4050 | particular. This message needs to give people | |
4051 | in that situation enough information to | |
4052 | determine that it's no big deal. */ | |
4053 | printf_filtered ("\n\ | |
5af949e3 | 4054 | GDB is unable to find the start of the function at %s\n\ |
29639122 JB |
4055 | and thus can't determine the size of that function's stack frame.\n\ |
4056 | This means that GDB may be unable to access that stack frame, or\n\ | |
4057 | the frames below it.\n\ | |
4058 | This problem is most likely caused by an invalid program counter or\n\ | |
4059 | stack pointer.\n\ | |
4060 | However, if you think GDB should simply search farther back\n\ | |
5af949e3 | 4061 | from %s for code which looks like the beginning of a\n\ |
29639122 | 4062 | function, you can increase the range of the search using the `set\n\ |
5af949e3 UW |
4063 | heuristic-fence-post' command.\n", |
4064 | paddress (gdbarch, pc), paddress (gdbarch, pc)); | |
29639122 JB |
4065 | blurb_printed = 1; |
4066 | } | |
4067 | } | |
4068 | ||
4069 | return 0; | |
4070 | } | |
4cc0665f | 4071 | else if (mips_pc_is_mips16 (gdbarch, start_pc)) |
29639122 JB |
4072 | { |
4073 | unsigned short inst; | |
4074 | ||
4075 | /* On MIPS16, any one of the following is likely to be the | |
4076 | start of a function: | |
193774b3 MR |
4077 | extend save |
4078 | save | |
29639122 JB |
4079 | entry |
4080 | addiu sp,-n | |
4081 | daddiu sp,-n | |
025bb325 | 4082 | extend -n followed by 'addiu sp,+n' or 'daddiu sp,+n'. */ |
4cc0665f | 4083 | inst = mips_fetch_instruction (gdbarch, ISA_MIPS16, start_pc, NULL); |
193774b3 MR |
4084 | if ((inst & 0xff80) == 0x6480) /* save */ |
4085 | { | |
4086 | if (start_pc - instlen >= fence) | |
4087 | { | |
4cc0665f MR |
4088 | inst = mips_fetch_instruction (gdbarch, ISA_MIPS16, |
4089 | start_pc - instlen, NULL); | |
193774b3 MR |
4090 | if ((inst & 0xf800) == 0xf000) /* extend */ |
4091 | start_pc -= instlen; | |
4092 | } | |
4093 | break; | |
4094 | } | |
4095 | else if (((inst & 0xf81f) == 0xe809 | |
4096 | && (inst & 0x700) != 0x700) /* entry */ | |
4097 | || (inst & 0xff80) == 0x6380 /* addiu sp,-n */ | |
4098 | || (inst & 0xff80) == 0xfb80 /* daddiu sp,-n */ | |
4099 | || ((inst & 0xf810) == 0xf010 && seen_adjsp)) /* extend -n */ | |
29639122 JB |
4100 | break; |
4101 | else if ((inst & 0xff00) == 0x6300 /* addiu sp */ | |
4102 | || (inst & 0xff00) == 0xfb00) /* daddiu sp */ | |
4103 | seen_adjsp = 1; | |
4104 | else | |
4105 | seen_adjsp = 0; | |
4106 | } | |
4cc0665f MR |
4107 | else if (mips_pc_is_micromips (gdbarch, start_pc)) |
4108 | { | |
4109 | ULONGEST insn; | |
4110 | int stop = 0; | |
4111 | long offset; | |
4112 | int dreg; | |
4113 | int sreg; | |
4114 | ||
4115 | /* On microMIPS, any one of the following is likely to be the | |
4116 | start of a function: | |
4117 | ADDIUSP -imm | |
4118 | (D)ADDIU $sp, -imm | |
4119 | LUI $gp, imm */ | |
4120 | insn = mips_fetch_instruction (gdbarch, ISA_MICROMIPS, pc, NULL); | |
4121 | switch (micromips_op (insn)) | |
4122 | { | |
4123 | case 0xc: /* ADDIU: bits 001100 */ | |
4124 | case 0x17: /* DADDIU: bits 010111 */ | |
4125 | sreg = b0s5_reg (insn); | |
4126 | dreg = b5s5_reg (insn); | |
4127 | insn <<= 16; | |
4128 | insn |= mips_fetch_instruction (gdbarch, ISA_MICROMIPS, | |
4129 | pc + MIPS_INSN16_SIZE, NULL); | |
4130 | offset = (b0s16_imm (insn) ^ 0x8000) - 0x8000; | |
4131 | if (sreg == MIPS_SP_REGNUM && dreg == MIPS_SP_REGNUM | |
4132 | /* (D)ADDIU $sp, imm */ | |
4133 | && offset < 0) | |
4134 | stop = 1; | |
4135 | break; | |
4136 | ||
4137 | case 0x10: /* POOL32I: bits 010000 */ | |
4138 | if (b5s5_op (insn) == 0xd | |
4139 | /* LUI: bits 010000 001101 */ | |
4140 | && b0s5_reg (insn >> 16) == 28) | |
4141 | /* LUI $gp, imm */ | |
4142 | stop = 1; | |
4143 | break; | |
4144 | ||
4145 | case 0x13: /* POOL16D: bits 010011 */ | |
4146 | if ((insn & 0x1) == 0x1) | |
4147 | /* ADDIUSP: bits 010011 1 */ | |
4148 | { | |
4149 | offset = micromips_decode_imm9 (b1s9_imm (insn)); | |
4150 | if (offset < 0) | |
4151 | /* ADDIUSP -imm */ | |
4152 | stop = 1; | |
4153 | } | |
4154 | else | |
4155 | /* ADDIUS5: bits 010011 0 */ | |
4156 | { | |
4157 | dreg = b5s5_reg (insn); | |
4158 | offset = (b1s4_imm (insn) ^ 8) - 8; | |
4159 | if (dreg == MIPS_SP_REGNUM && offset < 0) | |
4160 | /* ADDIUS5 $sp, -imm */ | |
4161 | stop = 1; | |
4162 | } | |
4163 | break; | |
4164 | } | |
4165 | if (stop) | |
4166 | break; | |
4167 | } | |
e17a4113 | 4168 | else if (mips_about_to_return (gdbarch, start_pc)) |
29639122 | 4169 | { |
4c7d22cb | 4170 | /* Skip return and its delay slot. */ |
95ac2dcf | 4171 | start_pc += 2 * MIPS_INSN32_SIZE; |
29639122 JB |
4172 | break; |
4173 | } | |
4174 | ||
4175 | return start_pc; | |
c906108c SS |
4176 | } |
4177 | ||
6c0d6680 DJ |
4178 | struct mips_objfile_private |
4179 | { | |
4180 | bfd_size_type size; | |
4181 | char *contents; | |
4182 | }; | |
4183 | ||
f09ded24 AC |
4184 | /* According to the current ABI, should the type be passed in a |
4185 | floating-point register (assuming that there is space)? When there | |
a1f5b845 | 4186 | is no FPU, FP are not even considered as possible candidates for |
f09ded24 | 4187 | FP registers and, consequently this returns false - forces FP |
025bb325 | 4188 | arguments into integer registers. */ |
f09ded24 AC |
4189 | |
4190 | static int | |
74ed0bb4 MD |
4191 | fp_register_arg_p (struct gdbarch *gdbarch, enum type_code typecode, |
4192 | struct type *arg_type) | |
f09ded24 AC |
4193 | { |
4194 | return ((typecode == TYPE_CODE_FLT | |
74ed0bb4 | 4195 | || (MIPS_EABI (gdbarch) |
6d82d43b AC |
4196 | && (typecode == TYPE_CODE_STRUCT |
4197 | || typecode == TYPE_CODE_UNION) | |
f09ded24 | 4198 | && TYPE_NFIELDS (arg_type) == 1 |
b2d6f210 MS |
4199 | && TYPE_CODE (check_typedef (TYPE_FIELD_TYPE (arg_type, 0))) |
4200 | == TYPE_CODE_FLT)) | |
74ed0bb4 | 4201 | && MIPS_FPU_TYPE(gdbarch) != MIPS_FPU_NONE); |
f09ded24 AC |
4202 | } |
4203 | ||
49e790b0 | 4204 | /* On o32, argument passing in GPRs depends on the alignment of the type being |
025bb325 | 4205 | passed. Return 1 if this type must be aligned to a doubleword boundary. */ |
49e790b0 DJ |
4206 | |
4207 | static int | |
4208 | mips_type_needs_double_align (struct type *type) | |
4209 | { | |
4210 | enum type_code typecode = TYPE_CODE (type); | |
361d1df0 | 4211 | |
49e790b0 DJ |
4212 | if (typecode == TYPE_CODE_FLT && TYPE_LENGTH (type) == 8) |
4213 | return 1; | |
4214 | else if (typecode == TYPE_CODE_STRUCT) | |
4215 | { | |
4216 | if (TYPE_NFIELDS (type) < 1) | |
4217 | return 0; | |
4218 | return mips_type_needs_double_align (TYPE_FIELD_TYPE (type, 0)); | |
4219 | } | |
4220 | else if (typecode == TYPE_CODE_UNION) | |
4221 | { | |
361d1df0 | 4222 | int i, n; |
49e790b0 DJ |
4223 | |
4224 | n = TYPE_NFIELDS (type); | |
4225 | for (i = 0; i < n; i++) | |
4226 | if (mips_type_needs_double_align (TYPE_FIELD_TYPE (type, i))) | |
4227 | return 1; | |
4228 | return 0; | |
4229 | } | |
4230 | return 0; | |
4231 | } | |
4232 | ||
dc604539 AC |
4233 | /* Adjust the address downward (direction of stack growth) so that it |
4234 | is correctly aligned for a new stack frame. */ | |
4235 | static CORE_ADDR | |
4236 | mips_frame_align (struct gdbarch *gdbarch, CORE_ADDR addr) | |
4237 | { | |
5b03f266 | 4238 | return align_down (addr, 16); |
dc604539 AC |
4239 | } |
4240 | ||
8ae38c14 | 4241 | /* Implement the "push_dummy_code" gdbarch method. */ |
2c76a0c7 JB |
4242 | |
4243 | static CORE_ADDR | |
4244 | mips_push_dummy_code (struct gdbarch *gdbarch, CORE_ADDR sp, | |
4245 | CORE_ADDR funaddr, struct value **args, | |
4246 | int nargs, struct type *value_type, | |
4247 | CORE_ADDR *real_pc, CORE_ADDR *bp_addr, | |
4248 | struct regcache *regcache) | |
4249 | { | |
2c76a0c7 | 4250 | static gdb_byte nop_insn[] = { 0, 0, 0, 0 }; |
2e81047f MR |
4251 | CORE_ADDR nop_addr; |
4252 | CORE_ADDR bp_slot; | |
2c76a0c7 JB |
4253 | |
4254 | /* Reserve enough room on the stack for our breakpoint instruction. */ | |
2e81047f MR |
4255 | bp_slot = sp - sizeof (nop_insn); |
4256 | ||
4257 | /* Return to microMIPS mode if calling microMIPS code to avoid | |
4258 | triggering an address error exception on processors that only | |
4259 | support microMIPS execution. */ | |
4260 | *bp_addr = (mips_pc_is_micromips (gdbarch, funaddr) | |
4261 | ? make_compact_addr (bp_slot) : bp_slot); | |
2c76a0c7 JB |
4262 | |
4263 | /* The breakpoint layer automatically adjusts the address of | |
4264 | breakpoints inserted in a branch delay slot. With enough | |
4265 | bad luck, the 4 bytes located just before our breakpoint | |
4266 | instruction could look like a branch instruction, and thus | |
4267 | trigger the adjustement, and break the function call entirely. | |
4268 | So, we reserve those 4 bytes and write a nop instruction | |
4269 | to prevent that from happening. */ | |
2e81047f | 4270 | nop_addr = bp_slot - sizeof (nop_insn); |
2c76a0c7 JB |
4271 | write_memory (nop_addr, nop_insn, sizeof (nop_insn)); |
4272 | sp = mips_frame_align (gdbarch, nop_addr); | |
4273 | ||
4274 | /* Inferior resumes at the function entry point. */ | |
4275 | *real_pc = funaddr; | |
4276 | ||
4277 | return sp; | |
4278 | } | |
4279 | ||
f7ab6ec6 | 4280 | static CORE_ADDR |
7d9b040b | 4281 | mips_eabi_push_dummy_call (struct gdbarch *gdbarch, struct value *function, |
6d82d43b AC |
4282 | struct regcache *regcache, CORE_ADDR bp_addr, |
4283 | int nargs, struct value **args, CORE_ADDR sp, | |
4284 | int struct_return, CORE_ADDR struct_addr) | |
c906108c SS |
4285 | { |
4286 | int argreg; | |
4287 | int float_argreg; | |
4288 | int argnum; | |
4289 | int len = 0; | |
4290 | int stack_offset = 0; | |
e17a4113 | 4291 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
7d9b040b | 4292 | CORE_ADDR func_addr = find_function_addr (function, NULL); |
1a69e1e4 | 4293 | int regsize = mips_abi_regsize (gdbarch); |
c906108c | 4294 | |
25ab4790 AC |
4295 | /* For shared libraries, "t9" needs to point at the function |
4296 | address. */ | |
4c7d22cb | 4297 | regcache_cooked_write_signed (regcache, MIPS_T9_REGNUM, func_addr); |
25ab4790 AC |
4298 | |
4299 | /* Set the return address register to point to the entry point of | |
4300 | the program, where a breakpoint lies in wait. */ | |
4c7d22cb | 4301 | regcache_cooked_write_signed (regcache, MIPS_RA_REGNUM, bp_addr); |
25ab4790 | 4302 | |
c906108c | 4303 | /* First ensure that the stack and structure return address (if any) |
cb3d25d1 MS |
4304 | are properly aligned. The stack has to be at least 64-bit |
4305 | aligned even on 32-bit machines, because doubles must be 64-bit | |
4306 | aligned. For n32 and n64, stack frames need to be 128-bit | |
4307 | aligned, so we round to this widest known alignment. */ | |
4308 | ||
5b03f266 AC |
4309 | sp = align_down (sp, 16); |
4310 | struct_addr = align_down (struct_addr, 16); | |
c5aa993b | 4311 | |
46e0f506 | 4312 | /* Now make space on the stack for the args. We allocate more |
c906108c | 4313 | than necessary for EABI, because the first few arguments are |
46e0f506 | 4314 | passed in registers, but that's OK. */ |
c906108c | 4315 | for (argnum = 0; argnum < nargs; argnum++) |
1a69e1e4 | 4316 | len += align_up (TYPE_LENGTH (value_type (args[argnum])), regsize); |
5b03f266 | 4317 | sp -= align_up (len, 16); |
c906108c | 4318 | |
9ace0497 | 4319 | if (mips_debug) |
6d82d43b | 4320 | fprintf_unfiltered (gdb_stdlog, |
5af949e3 UW |
4321 | "mips_eabi_push_dummy_call: sp=%s allocated %ld\n", |
4322 | paddress (gdbarch, sp), (long) align_up (len, 16)); | |
9ace0497 | 4323 | |
c906108c | 4324 | /* Initialize the integer and float register pointers. */ |
4c7d22cb | 4325 | argreg = MIPS_A0_REGNUM; |
72a155b4 | 4326 | float_argreg = mips_fpa0_regnum (gdbarch); |
c906108c | 4327 | |
46e0f506 | 4328 | /* The struct_return pointer occupies the first parameter-passing reg. */ |
c906108c | 4329 | if (struct_return) |
9ace0497 AC |
4330 | { |
4331 | if (mips_debug) | |
4332 | fprintf_unfiltered (gdb_stdlog, | |
025bb325 MS |
4333 | "mips_eabi_push_dummy_call: " |
4334 | "struct_return reg=%d %s\n", | |
5af949e3 | 4335 | argreg, paddress (gdbarch, struct_addr)); |
9c9acae0 | 4336 | regcache_cooked_write_unsigned (regcache, argreg++, struct_addr); |
9ace0497 | 4337 | } |
c906108c SS |
4338 | |
4339 | /* Now load as many as possible of the first arguments into | |
4340 | registers, and push the rest onto the stack. Loop thru args | |
4341 | from first to last. */ | |
4342 | for (argnum = 0; argnum < nargs; argnum++) | |
4343 | { | |
47a35522 MK |
4344 | const gdb_byte *val; |
4345 | gdb_byte valbuf[MAX_REGISTER_SIZE]; | |
ea7c478f | 4346 | struct value *arg = args[argnum]; |
4991999e | 4347 | struct type *arg_type = check_typedef (value_type (arg)); |
c906108c SS |
4348 | int len = TYPE_LENGTH (arg_type); |
4349 | enum type_code typecode = TYPE_CODE (arg_type); | |
4350 | ||
9ace0497 AC |
4351 | if (mips_debug) |
4352 | fprintf_unfiltered (gdb_stdlog, | |
25ab4790 | 4353 | "mips_eabi_push_dummy_call: %d len=%d type=%d", |
acdb74a0 | 4354 | argnum + 1, len, (int) typecode); |
9ace0497 | 4355 | |
930bd0e0 KB |
4356 | /* Function pointer arguments to mips16 code need to be made into |
4357 | mips16 pointers. */ | |
4358 | if (typecode == TYPE_CODE_PTR | |
4359 | && TYPE_CODE (TYPE_TARGET_TYPE (arg_type)) == TYPE_CODE_FUNC) | |
4360 | { | |
4361 | CORE_ADDR addr = extract_signed_integer (value_contents (arg), | |
4362 | len, byte_order); | |
4cc0665f MR |
4363 | if (mips_pc_is_mips (addr)) |
4364 | val = value_contents (arg); | |
4365 | else | |
930bd0e0 KB |
4366 | { |
4367 | store_signed_integer (valbuf, len, byte_order, | |
4cc0665f | 4368 | make_compact_addr (addr)); |
930bd0e0 KB |
4369 | val = valbuf; |
4370 | } | |
930bd0e0 | 4371 | } |
c906108c | 4372 | /* The EABI passes structures that do not fit in a register by |
46e0f506 | 4373 | reference. */ |
930bd0e0 | 4374 | else if (len > regsize |
9ace0497 | 4375 | && (typecode == TYPE_CODE_STRUCT || typecode == TYPE_CODE_UNION)) |
c906108c | 4376 | { |
e17a4113 UW |
4377 | store_unsigned_integer (valbuf, regsize, byte_order, |
4378 | value_address (arg)); | |
c906108c | 4379 | typecode = TYPE_CODE_PTR; |
1a69e1e4 | 4380 | len = regsize; |
c906108c | 4381 | val = valbuf; |
9ace0497 AC |
4382 | if (mips_debug) |
4383 | fprintf_unfiltered (gdb_stdlog, " push"); | |
c906108c SS |
4384 | } |
4385 | else | |
47a35522 | 4386 | val = value_contents (arg); |
c906108c SS |
4387 | |
4388 | /* 32-bit ABIs always start floating point arguments in an | |
acdb74a0 AC |
4389 | even-numbered floating point register. Round the FP register |
4390 | up before the check to see if there are any FP registers | |
46e0f506 MS |
4391 | left. Non MIPS_EABI targets also pass the FP in the integer |
4392 | registers so also round up normal registers. */ | |
74ed0bb4 | 4393 | if (regsize < 8 && fp_register_arg_p (gdbarch, typecode, arg_type)) |
acdb74a0 AC |
4394 | { |
4395 | if ((float_argreg & 1)) | |
4396 | float_argreg++; | |
4397 | } | |
c906108c SS |
4398 | |
4399 | /* Floating point arguments passed in registers have to be | |
4400 | treated specially. On 32-bit architectures, doubles | |
c5aa993b JM |
4401 | are passed in register pairs; the even register gets |
4402 | the low word, and the odd register gets the high word. | |
4403 | On non-EABI processors, the first two floating point arguments are | |
4404 | also copied to general registers, because MIPS16 functions | |
4405 | don't use float registers for arguments. This duplication of | |
4406 | arguments in general registers can't hurt non-MIPS16 functions | |
4407 | because those registers are normally skipped. */ | |
1012bd0e EZ |
4408 | /* MIPS_EABI squeezes a struct that contains a single floating |
4409 | point value into an FP register instead of pushing it onto the | |
46e0f506 | 4410 | stack. */ |
74ed0bb4 MD |
4411 | if (fp_register_arg_p (gdbarch, typecode, arg_type) |
4412 | && float_argreg <= MIPS_LAST_FP_ARG_REGNUM (gdbarch)) | |
c906108c | 4413 | { |
6da397e0 KB |
4414 | /* EABI32 will pass doubles in consecutive registers, even on |
4415 | 64-bit cores. At one time, we used to check the size of | |
4416 | `float_argreg' to determine whether or not to pass doubles | |
4417 | in consecutive registers, but this is not sufficient for | |
4418 | making the ABI determination. */ | |
4419 | if (len == 8 && mips_abi (gdbarch) == MIPS_ABI_EABI32) | |
c906108c | 4420 | { |
72a155b4 | 4421 | int low_offset = gdbarch_byte_order (gdbarch) |
4c6b5505 | 4422 | == BFD_ENDIAN_BIG ? 4 : 0; |
a8852dc5 | 4423 | long regval; |
c906108c SS |
4424 | |
4425 | /* Write the low word of the double to the even register(s). */ | |
a8852dc5 KB |
4426 | regval = extract_signed_integer (val + low_offset, |
4427 | 4, byte_order); | |
9ace0497 | 4428 | if (mips_debug) |
acdb74a0 | 4429 | fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s", |
9ace0497 | 4430 | float_argreg, phex (regval, 4)); |
a8852dc5 | 4431 | regcache_cooked_write_signed (regcache, float_argreg++, regval); |
c906108c SS |
4432 | |
4433 | /* Write the high word of the double to the odd register(s). */ | |
a8852dc5 KB |
4434 | regval = extract_signed_integer (val + 4 - low_offset, |
4435 | 4, byte_order); | |
9ace0497 | 4436 | if (mips_debug) |
acdb74a0 | 4437 | fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s", |
9ace0497 | 4438 | float_argreg, phex (regval, 4)); |
a8852dc5 | 4439 | regcache_cooked_write_signed (regcache, float_argreg++, regval); |
c906108c SS |
4440 | } |
4441 | else | |
4442 | { | |
4443 | /* This is a floating point value that fits entirely | |
4444 | in a single register. */ | |
53a5351d | 4445 | /* On 32 bit ABI's the float_argreg is further adjusted |
6d82d43b | 4446 | above to ensure that it is even register aligned. */ |
a8852dc5 | 4447 | LONGEST regval = extract_signed_integer (val, len, byte_order); |
9ace0497 | 4448 | if (mips_debug) |
acdb74a0 | 4449 | fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s", |
9ace0497 | 4450 | float_argreg, phex (regval, len)); |
a8852dc5 | 4451 | regcache_cooked_write_signed (regcache, float_argreg++, regval); |
c906108c SS |
4452 | } |
4453 | } | |
4454 | else | |
4455 | { | |
4456 | /* Copy the argument to general registers or the stack in | |
4457 | register-sized pieces. Large arguments are split between | |
4458 | registers and stack. */ | |
1a69e1e4 DJ |
4459 | /* Note: structs whose size is not a multiple of regsize |
4460 | are treated specially: Irix cc passes | |
d5ac5a39 AC |
4461 | them in registers where gcc sometimes puts them on the |
4462 | stack. For maximum compatibility, we will put them in | |
4463 | both places. */ | |
1a69e1e4 | 4464 | int odd_sized_struct = (len > regsize && len % regsize != 0); |
46e0f506 | 4465 | |
f09ded24 | 4466 | /* Note: Floating-point values that didn't fit into an FP |
6d82d43b | 4467 | register are only written to memory. */ |
c906108c SS |
4468 | while (len > 0) |
4469 | { | |
ebafbe83 | 4470 | /* Remember if the argument was written to the stack. */ |
566f0f7a | 4471 | int stack_used_p = 0; |
1a69e1e4 | 4472 | int partial_len = (len < regsize ? len : regsize); |
c906108c | 4473 | |
acdb74a0 AC |
4474 | if (mips_debug) |
4475 | fprintf_unfiltered (gdb_stdlog, " -- partial=%d", | |
4476 | partial_len); | |
4477 | ||
566f0f7a | 4478 | /* Write this portion of the argument to the stack. */ |
74ed0bb4 | 4479 | if (argreg > MIPS_LAST_ARG_REGNUM (gdbarch) |
f09ded24 | 4480 | || odd_sized_struct |
74ed0bb4 | 4481 | || fp_register_arg_p (gdbarch, typecode, arg_type)) |
c906108c | 4482 | { |
c906108c | 4483 | /* Should shorter than int integer values be |
025bb325 | 4484 | promoted to int before being stored? */ |
c906108c | 4485 | int longword_offset = 0; |
9ace0497 | 4486 | CORE_ADDR addr; |
566f0f7a | 4487 | stack_used_p = 1; |
72a155b4 | 4488 | if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) |
7a292a7a | 4489 | { |
1a69e1e4 | 4490 | if (regsize == 8 |
480d3dd2 AC |
4491 | && (typecode == TYPE_CODE_INT |
4492 | || typecode == TYPE_CODE_PTR | |
6d82d43b | 4493 | || typecode == TYPE_CODE_FLT) && len <= 4) |
1a69e1e4 | 4494 | longword_offset = regsize - len; |
480d3dd2 AC |
4495 | else if ((typecode == TYPE_CODE_STRUCT |
4496 | || typecode == TYPE_CODE_UNION) | |
1a69e1e4 DJ |
4497 | && TYPE_LENGTH (arg_type) < regsize) |
4498 | longword_offset = regsize - len; | |
7a292a7a | 4499 | } |
c5aa993b | 4500 | |
9ace0497 AC |
4501 | if (mips_debug) |
4502 | { | |
5af949e3 UW |
4503 | fprintf_unfiltered (gdb_stdlog, " - stack_offset=%s", |
4504 | paddress (gdbarch, stack_offset)); | |
4505 | fprintf_unfiltered (gdb_stdlog, " longword_offset=%s", | |
4506 | paddress (gdbarch, longword_offset)); | |
9ace0497 | 4507 | } |
361d1df0 | 4508 | |
9ace0497 AC |
4509 | addr = sp + stack_offset + longword_offset; |
4510 | ||
4511 | if (mips_debug) | |
4512 | { | |
4513 | int i; | |
5af949e3 UW |
4514 | fprintf_unfiltered (gdb_stdlog, " @%s ", |
4515 | paddress (gdbarch, addr)); | |
9ace0497 AC |
4516 | for (i = 0; i < partial_len; i++) |
4517 | { | |
6d82d43b | 4518 | fprintf_unfiltered (gdb_stdlog, "%02x", |
cb3d25d1 | 4519 | val[i] & 0xff); |
9ace0497 AC |
4520 | } |
4521 | } | |
4522 | write_memory (addr, val, partial_len); | |
c906108c SS |
4523 | } |
4524 | ||
f09ded24 AC |
4525 | /* Note!!! This is NOT an else clause. Odd sized |
4526 | structs may go thru BOTH paths. Floating point | |
46e0f506 | 4527 | arguments will not. */ |
566f0f7a | 4528 | /* Write this portion of the argument to a general |
6d82d43b | 4529 | purpose register. */ |
74ed0bb4 MD |
4530 | if (argreg <= MIPS_LAST_ARG_REGNUM (gdbarch) |
4531 | && !fp_register_arg_p (gdbarch, typecode, arg_type)) | |
c906108c | 4532 | { |
6d82d43b | 4533 | LONGEST regval = |
a8852dc5 | 4534 | extract_signed_integer (val, partial_len, byte_order); |
c906108c | 4535 | |
9ace0497 | 4536 | if (mips_debug) |
acdb74a0 | 4537 | fprintf_filtered (gdb_stdlog, " - reg=%d val=%s", |
9ace0497 | 4538 | argreg, |
1a69e1e4 | 4539 | phex (regval, regsize)); |
a8852dc5 | 4540 | regcache_cooked_write_signed (regcache, argreg, regval); |
c906108c | 4541 | argreg++; |
c906108c | 4542 | } |
c5aa993b | 4543 | |
c906108c SS |
4544 | len -= partial_len; |
4545 | val += partial_len; | |
4546 | ||
b021a221 MS |
4547 | /* Compute the offset into the stack at which we will |
4548 | copy the next parameter. | |
566f0f7a | 4549 | |
566f0f7a | 4550 | In the new EABI (and the NABI32), the stack_offset |
46e0f506 | 4551 | only needs to be adjusted when it has been used. */ |
c906108c | 4552 | |
46e0f506 | 4553 | if (stack_used_p) |
1a69e1e4 | 4554 | stack_offset += align_up (partial_len, regsize); |
c906108c SS |
4555 | } |
4556 | } | |
9ace0497 AC |
4557 | if (mips_debug) |
4558 | fprintf_unfiltered (gdb_stdlog, "\n"); | |
c906108c SS |
4559 | } |
4560 | ||
f10683bb | 4561 | regcache_cooked_write_signed (regcache, MIPS_SP_REGNUM, sp); |
310e9b6a | 4562 | |
0f71a2f6 JM |
4563 | /* Return adjusted stack pointer. */ |
4564 | return sp; | |
4565 | } | |
4566 | ||
a1f5b845 | 4567 | /* Determine the return value convention being used. */ |
6d82d43b | 4568 | |
9c8fdbfa | 4569 | static enum return_value_convention |
6a3a010b | 4570 | mips_eabi_return_value (struct gdbarch *gdbarch, struct value *function, |
9c8fdbfa | 4571 | struct type *type, struct regcache *regcache, |
47a35522 | 4572 | gdb_byte *readbuf, const gdb_byte *writebuf) |
6d82d43b | 4573 | { |
609ba780 JM |
4574 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
4575 | int fp_return_type = 0; | |
4576 | int offset, regnum, xfer; | |
4577 | ||
9c8fdbfa AC |
4578 | if (TYPE_LENGTH (type) > 2 * mips_abi_regsize (gdbarch)) |
4579 | return RETURN_VALUE_STRUCT_CONVENTION; | |
609ba780 JM |
4580 | |
4581 | /* Floating point type? */ | |
4582 | if (tdep->mips_fpu_type != MIPS_FPU_NONE) | |
4583 | { | |
4584 | if (TYPE_CODE (type) == TYPE_CODE_FLT) | |
4585 | fp_return_type = 1; | |
4586 | /* Structs with a single field of float type | |
4587 | are returned in a floating point register. */ | |
4588 | if ((TYPE_CODE (type) == TYPE_CODE_STRUCT | |
4589 | || TYPE_CODE (type) == TYPE_CODE_UNION) | |
4590 | && TYPE_NFIELDS (type) == 1) | |
4591 | { | |
4592 | struct type *fieldtype = TYPE_FIELD_TYPE (type, 0); | |
4593 | ||
4594 | if (TYPE_CODE (check_typedef (fieldtype)) == TYPE_CODE_FLT) | |
4595 | fp_return_type = 1; | |
4596 | } | |
4597 | } | |
4598 | ||
4599 | if (fp_return_type) | |
4600 | { | |
4601 | /* A floating-point value belongs in the least significant part | |
4602 | of FP0/FP1. */ | |
4603 | if (mips_debug) | |
4604 | fprintf_unfiltered (gdb_stderr, "Return float in $fp0\n"); | |
4605 | regnum = mips_regnum (gdbarch)->fp0; | |
4606 | } | |
4607 | else | |
4608 | { | |
4609 | /* An integer value goes in V0/V1. */ | |
4610 | if (mips_debug) | |
4611 | fprintf_unfiltered (gdb_stderr, "Return scalar in $v0\n"); | |
4612 | regnum = MIPS_V0_REGNUM; | |
4613 | } | |
4614 | for (offset = 0; | |
4615 | offset < TYPE_LENGTH (type); | |
4616 | offset += mips_abi_regsize (gdbarch), regnum++) | |
4617 | { | |
4618 | xfer = mips_abi_regsize (gdbarch); | |
4619 | if (offset + xfer > TYPE_LENGTH (type)) | |
4620 | xfer = TYPE_LENGTH (type) - offset; | |
4621 | mips_xfer_register (gdbarch, regcache, | |
4622 | gdbarch_num_regs (gdbarch) + regnum, xfer, | |
4623 | gdbarch_byte_order (gdbarch), readbuf, writebuf, | |
4624 | offset); | |
4625 | } | |
4626 | ||
9c8fdbfa | 4627 | return RETURN_VALUE_REGISTER_CONVENTION; |
6d82d43b AC |
4628 | } |
4629 | ||
6d82d43b AC |
4630 | |
4631 | /* N32/N64 ABI stuff. */ | |
ebafbe83 | 4632 | |
8d26208a DJ |
4633 | /* Search for a naturally aligned double at OFFSET inside a struct |
4634 | ARG_TYPE. The N32 / N64 ABIs pass these in floating point | |
4635 | registers. */ | |
4636 | ||
4637 | static int | |
74ed0bb4 MD |
4638 | mips_n32n64_fp_arg_chunk_p (struct gdbarch *gdbarch, struct type *arg_type, |
4639 | int offset) | |
8d26208a DJ |
4640 | { |
4641 | int i; | |
4642 | ||
4643 | if (TYPE_CODE (arg_type) != TYPE_CODE_STRUCT) | |
4644 | return 0; | |
4645 | ||
74ed0bb4 | 4646 | if (MIPS_FPU_TYPE (gdbarch) != MIPS_FPU_DOUBLE) |
8d26208a DJ |
4647 | return 0; |
4648 | ||
4649 | if (TYPE_LENGTH (arg_type) < offset + MIPS64_REGSIZE) | |
4650 | return 0; | |
4651 | ||
4652 | for (i = 0; i < TYPE_NFIELDS (arg_type); i++) | |
4653 | { | |
4654 | int pos; | |
4655 | struct type *field_type; | |
4656 | ||
4657 | /* We're only looking at normal fields. */ | |
5bc60cfb | 4658 | if (field_is_static (&TYPE_FIELD (arg_type, i)) |
8d26208a DJ |
4659 | || (TYPE_FIELD_BITPOS (arg_type, i) % 8) != 0) |
4660 | continue; | |
4661 | ||
4662 | /* If we have gone past the offset, there is no double to pass. */ | |
4663 | pos = TYPE_FIELD_BITPOS (arg_type, i) / 8; | |
4664 | if (pos > offset) | |
4665 | return 0; | |
4666 | ||
4667 | field_type = check_typedef (TYPE_FIELD_TYPE (arg_type, i)); | |
4668 | ||
4669 | /* If this field is entirely before the requested offset, go | |
4670 | on to the next one. */ | |
4671 | if (pos + TYPE_LENGTH (field_type) <= offset) | |
4672 | continue; | |
4673 | ||
4674 | /* If this is our special aligned double, we can stop. */ | |
4675 | if (TYPE_CODE (field_type) == TYPE_CODE_FLT | |
4676 | && TYPE_LENGTH (field_type) == MIPS64_REGSIZE) | |
4677 | return 1; | |
4678 | ||
4679 | /* This field starts at or before the requested offset, and | |
4680 | overlaps it. If it is a structure, recurse inwards. */ | |
74ed0bb4 | 4681 | return mips_n32n64_fp_arg_chunk_p (gdbarch, field_type, offset - pos); |
8d26208a DJ |
4682 | } |
4683 | ||
4684 | return 0; | |
4685 | } | |
4686 | ||
f7ab6ec6 | 4687 | static CORE_ADDR |
7d9b040b | 4688 | mips_n32n64_push_dummy_call (struct gdbarch *gdbarch, struct value *function, |
6d82d43b AC |
4689 | struct regcache *regcache, CORE_ADDR bp_addr, |
4690 | int nargs, struct value **args, CORE_ADDR sp, | |
4691 | int struct_return, CORE_ADDR struct_addr) | |
cb3d25d1 MS |
4692 | { |
4693 | int argreg; | |
4694 | int float_argreg; | |
4695 | int argnum; | |
4696 | int len = 0; | |
4697 | int stack_offset = 0; | |
e17a4113 | 4698 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
7d9b040b | 4699 | CORE_ADDR func_addr = find_function_addr (function, NULL); |
cb3d25d1 | 4700 | |
25ab4790 AC |
4701 | /* For shared libraries, "t9" needs to point at the function |
4702 | address. */ | |
4c7d22cb | 4703 | regcache_cooked_write_signed (regcache, MIPS_T9_REGNUM, func_addr); |
25ab4790 AC |
4704 | |
4705 | /* Set the return address register to point to the entry point of | |
4706 | the program, where a breakpoint lies in wait. */ | |
4c7d22cb | 4707 | regcache_cooked_write_signed (regcache, MIPS_RA_REGNUM, bp_addr); |
25ab4790 | 4708 | |
cb3d25d1 MS |
4709 | /* First ensure that the stack and structure return address (if any) |
4710 | are properly aligned. The stack has to be at least 64-bit | |
4711 | aligned even on 32-bit machines, because doubles must be 64-bit | |
4712 | aligned. For n32 and n64, stack frames need to be 128-bit | |
4713 | aligned, so we round to this widest known alignment. */ | |
4714 | ||
5b03f266 AC |
4715 | sp = align_down (sp, 16); |
4716 | struct_addr = align_down (struct_addr, 16); | |
cb3d25d1 MS |
4717 | |
4718 | /* Now make space on the stack for the args. */ | |
4719 | for (argnum = 0; argnum < nargs; argnum++) | |
1a69e1e4 | 4720 | len += align_up (TYPE_LENGTH (value_type (args[argnum])), MIPS64_REGSIZE); |
5b03f266 | 4721 | sp -= align_up (len, 16); |
cb3d25d1 MS |
4722 | |
4723 | if (mips_debug) | |
6d82d43b | 4724 | fprintf_unfiltered (gdb_stdlog, |
5af949e3 UW |
4725 | "mips_n32n64_push_dummy_call: sp=%s allocated %ld\n", |
4726 | paddress (gdbarch, sp), (long) align_up (len, 16)); | |
cb3d25d1 MS |
4727 | |
4728 | /* Initialize the integer and float register pointers. */ | |
4c7d22cb | 4729 | argreg = MIPS_A0_REGNUM; |
72a155b4 | 4730 | float_argreg = mips_fpa0_regnum (gdbarch); |
cb3d25d1 | 4731 | |
46e0f506 | 4732 | /* The struct_return pointer occupies the first parameter-passing reg. */ |
cb3d25d1 MS |
4733 | if (struct_return) |
4734 | { | |
4735 | if (mips_debug) | |
4736 | fprintf_unfiltered (gdb_stdlog, | |
025bb325 MS |
4737 | "mips_n32n64_push_dummy_call: " |
4738 | "struct_return reg=%d %s\n", | |
5af949e3 | 4739 | argreg, paddress (gdbarch, struct_addr)); |
9c9acae0 | 4740 | regcache_cooked_write_unsigned (regcache, argreg++, struct_addr); |
cb3d25d1 MS |
4741 | } |
4742 | ||
4743 | /* Now load as many as possible of the first arguments into | |
4744 | registers, and push the rest onto the stack. Loop thru args | |
4745 | from first to last. */ | |
4746 | for (argnum = 0; argnum < nargs; argnum++) | |
4747 | { | |
47a35522 | 4748 | const gdb_byte *val; |
cb3d25d1 | 4749 | struct value *arg = args[argnum]; |
4991999e | 4750 | struct type *arg_type = check_typedef (value_type (arg)); |
cb3d25d1 MS |
4751 | int len = TYPE_LENGTH (arg_type); |
4752 | enum type_code typecode = TYPE_CODE (arg_type); | |
4753 | ||
4754 | if (mips_debug) | |
4755 | fprintf_unfiltered (gdb_stdlog, | |
25ab4790 | 4756 | "mips_n32n64_push_dummy_call: %d len=%d type=%d", |
cb3d25d1 MS |
4757 | argnum + 1, len, (int) typecode); |
4758 | ||
47a35522 | 4759 | val = value_contents (arg); |
cb3d25d1 | 4760 | |
5b68030f JM |
4761 | /* A 128-bit long double value requires an even-odd pair of |
4762 | floating-point registers. */ | |
4763 | if (len == 16 | |
4764 | && fp_register_arg_p (gdbarch, typecode, arg_type) | |
4765 | && (float_argreg & 1)) | |
4766 | { | |
4767 | float_argreg++; | |
4768 | argreg++; | |
4769 | } | |
4770 | ||
74ed0bb4 MD |
4771 | if (fp_register_arg_p (gdbarch, typecode, arg_type) |
4772 | && argreg <= MIPS_LAST_ARG_REGNUM (gdbarch)) | |
cb3d25d1 MS |
4773 | { |
4774 | /* This is a floating point value that fits entirely | |
5b68030f JM |
4775 | in a single register or a pair of registers. */ |
4776 | int reglen = (len <= MIPS64_REGSIZE ? len : MIPS64_REGSIZE); | |
e17a4113 | 4777 | LONGEST regval = extract_unsigned_integer (val, reglen, byte_order); |
cb3d25d1 MS |
4778 | if (mips_debug) |
4779 | fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s", | |
5b68030f | 4780 | float_argreg, phex (regval, reglen)); |
8d26208a | 4781 | regcache_cooked_write_unsigned (regcache, float_argreg, regval); |
cb3d25d1 MS |
4782 | |
4783 | if (mips_debug) | |
4784 | fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s", | |
5b68030f | 4785 | argreg, phex (regval, reglen)); |
9c9acae0 | 4786 | regcache_cooked_write_unsigned (regcache, argreg, regval); |
8d26208a DJ |
4787 | float_argreg++; |
4788 | argreg++; | |
5b68030f JM |
4789 | if (len == 16) |
4790 | { | |
e17a4113 UW |
4791 | regval = extract_unsigned_integer (val + reglen, |
4792 | reglen, byte_order); | |
5b68030f JM |
4793 | if (mips_debug) |
4794 | fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s", | |
4795 | float_argreg, phex (regval, reglen)); | |
4796 | regcache_cooked_write_unsigned (regcache, float_argreg, regval); | |
4797 | ||
4798 | if (mips_debug) | |
4799 | fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s", | |
4800 | argreg, phex (regval, reglen)); | |
4801 | regcache_cooked_write_unsigned (regcache, argreg, regval); | |
4802 | float_argreg++; | |
4803 | argreg++; | |
4804 | } | |
cb3d25d1 MS |
4805 | } |
4806 | else | |
4807 | { | |
4808 | /* Copy the argument to general registers or the stack in | |
4809 | register-sized pieces. Large arguments are split between | |
4810 | registers and stack. */ | |
ab2e1992 MR |
4811 | /* For N32/N64, structs, unions, or other composite types are |
4812 | treated as a sequence of doublewords, and are passed in integer | |
4813 | or floating point registers as though they were simple scalar | |
4814 | parameters to the extent that they fit, with any excess on the | |
4815 | stack packed according to the normal memory layout of the | |
4816 | object. | |
4817 | The caller does not reserve space for the register arguments; | |
4818 | the callee is responsible for reserving it if required. */ | |
cb3d25d1 | 4819 | /* Note: Floating-point values that didn't fit into an FP |
6d82d43b | 4820 | register are only written to memory. */ |
cb3d25d1 MS |
4821 | while (len > 0) |
4822 | { | |
ad018eee | 4823 | /* Remember if the argument was written to the stack. */ |
cb3d25d1 | 4824 | int stack_used_p = 0; |
1a69e1e4 | 4825 | int partial_len = (len < MIPS64_REGSIZE ? len : MIPS64_REGSIZE); |
cb3d25d1 MS |
4826 | |
4827 | if (mips_debug) | |
4828 | fprintf_unfiltered (gdb_stdlog, " -- partial=%d", | |
4829 | partial_len); | |
4830 | ||
74ed0bb4 MD |
4831 | if (fp_register_arg_p (gdbarch, typecode, arg_type)) |
4832 | gdb_assert (argreg > MIPS_LAST_ARG_REGNUM (gdbarch)); | |
8d26208a | 4833 | |
cb3d25d1 | 4834 | /* Write this portion of the argument to the stack. */ |
74ed0bb4 | 4835 | if (argreg > MIPS_LAST_ARG_REGNUM (gdbarch)) |
cb3d25d1 MS |
4836 | { |
4837 | /* Should shorter than int integer values be | |
025bb325 | 4838 | promoted to int before being stored? */ |
cb3d25d1 MS |
4839 | int longword_offset = 0; |
4840 | CORE_ADDR addr; | |
4841 | stack_used_p = 1; | |
72a155b4 | 4842 | if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) |
cb3d25d1 | 4843 | { |
1a69e1e4 | 4844 | if ((typecode == TYPE_CODE_INT |
5b68030f | 4845 | || typecode == TYPE_CODE_PTR) |
1a69e1e4 DJ |
4846 | && len <= 4) |
4847 | longword_offset = MIPS64_REGSIZE - len; | |
cb3d25d1 MS |
4848 | } |
4849 | ||
4850 | if (mips_debug) | |
4851 | { | |
5af949e3 UW |
4852 | fprintf_unfiltered (gdb_stdlog, " - stack_offset=%s", |
4853 | paddress (gdbarch, stack_offset)); | |
4854 | fprintf_unfiltered (gdb_stdlog, " longword_offset=%s", | |
4855 | paddress (gdbarch, longword_offset)); | |
cb3d25d1 MS |
4856 | } |
4857 | ||
4858 | addr = sp + stack_offset + longword_offset; | |
4859 | ||
4860 | if (mips_debug) | |
4861 | { | |
4862 | int i; | |
5af949e3 UW |
4863 | fprintf_unfiltered (gdb_stdlog, " @%s ", |
4864 | paddress (gdbarch, addr)); | |
cb3d25d1 MS |
4865 | for (i = 0; i < partial_len; i++) |
4866 | { | |
6d82d43b | 4867 | fprintf_unfiltered (gdb_stdlog, "%02x", |
cb3d25d1 MS |
4868 | val[i] & 0xff); |
4869 | } | |
4870 | } | |
4871 | write_memory (addr, val, partial_len); | |
4872 | } | |
4873 | ||
4874 | /* Note!!! This is NOT an else clause. Odd sized | |
8d26208a | 4875 | structs may go thru BOTH paths. */ |
cb3d25d1 | 4876 | /* Write this portion of the argument to a general |
6d82d43b | 4877 | purpose register. */ |
74ed0bb4 | 4878 | if (argreg <= MIPS_LAST_ARG_REGNUM (gdbarch)) |
cb3d25d1 | 4879 | { |
5863b5d5 MR |
4880 | LONGEST regval; |
4881 | ||
4882 | /* Sign extend pointers, 32-bit integers and signed | |
4883 | 16-bit and 8-bit integers; everything else is taken | |
4884 | as is. */ | |
4885 | ||
4886 | if ((partial_len == 4 | |
4887 | && (typecode == TYPE_CODE_PTR | |
4888 | || typecode == TYPE_CODE_INT)) | |
4889 | || (partial_len < 4 | |
4890 | && typecode == TYPE_CODE_INT | |
4891 | && !TYPE_UNSIGNED (arg_type))) | |
e17a4113 UW |
4892 | regval = extract_signed_integer (val, partial_len, |
4893 | byte_order); | |
5863b5d5 | 4894 | else |
e17a4113 UW |
4895 | regval = extract_unsigned_integer (val, partial_len, |
4896 | byte_order); | |
cb3d25d1 MS |
4897 | |
4898 | /* A non-floating-point argument being passed in a | |
4899 | general register. If a struct or union, and if | |
4900 | the remaining length is smaller than the register | |
4901 | size, we have to adjust the register value on | |
4902 | big endian targets. | |
4903 | ||
4904 | It does not seem to be necessary to do the | |
1a69e1e4 | 4905 | same for integral types. */ |
cb3d25d1 | 4906 | |
72a155b4 | 4907 | if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG |
1a69e1e4 | 4908 | && partial_len < MIPS64_REGSIZE |
06f9a1af MR |
4909 | && (typecode == TYPE_CODE_STRUCT |
4910 | || typecode == TYPE_CODE_UNION)) | |
1a69e1e4 | 4911 | regval <<= ((MIPS64_REGSIZE - partial_len) |
9ecf7166 | 4912 | * TARGET_CHAR_BIT); |
cb3d25d1 MS |
4913 | |
4914 | if (mips_debug) | |
4915 | fprintf_filtered (gdb_stdlog, " - reg=%d val=%s", | |
4916 | argreg, | |
1a69e1e4 | 4917 | phex (regval, MIPS64_REGSIZE)); |
9c9acae0 | 4918 | regcache_cooked_write_unsigned (regcache, argreg, regval); |
8d26208a | 4919 | |
74ed0bb4 | 4920 | if (mips_n32n64_fp_arg_chunk_p (gdbarch, arg_type, |
8d26208a DJ |
4921 | TYPE_LENGTH (arg_type) - len)) |
4922 | { | |
4923 | if (mips_debug) | |
4924 | fprintf_filtered (gdb_stdlog, " - fpreg=%d val=%s", | |
4925 | float_argreg, | |
4926 | phex (regval, MIPS64_REGSIZE)); | |
4927 | regcache_cooked_write_unsigned (regcache, float_argreg, | |
4928 | regval); | |
4929 | } | |
4930 | ||
4931 | float_argreg++; | |
cb3d25d1 MS |
4932 | argreg++; |
4933 | } | |
4934 | ||
4935 | len -= partial_len; | |
4936 | val += partial_len; | |
4937 | ||
b021a221 MS |
4938 | /* Compute the offset into the stack at which we will |
4939 | copy the next parameter. | |
cb3d25d1 MS |
4940 | |
4941 | In N32 (N64?), the stack_offset only needs to be | |
4942 | adjusted when it has been used. */ | |
4943 | ||
4944 | if (stack_used_p) | |
1a69e1e4 | 4945 | stack_offset += align_up (partial_len, MIPS64_REGSIZE); |
cb3d25d1 MS |
4946 | } |
4947 | } | |
4948 | if (mips_debug) | |
4949 | fprintf_unfiltered (gdb_stdlog, "\n"); | |
4950 | } | |
4951 | ||
f10683bb | 4952 | regcache_cooked_write_signed (regcache, MIPS_SP_REGNUM, sp); |
310e9b6a | 4953 | |
cb3d25d1 MS |
4954 | /* Return adjusted stack pointer. */ |
4955 | return sp; | |
4956 | } | |
4957 | ||
6d82d43b | 4958 | static enum return_value_convention |
6a3a010b | 4959 | mips_n32n64_return_value (struct gdbarch *gdbarch, struct value *function, |
6d82d43b | 4960 | struct type *type, struct regcache *regcache, |
47a35522 | 4961 | gdb_byte *readbuf, const gdb_byte *writebuf) |
ebafbe83 | 4962 | { |
72a155b4 | 4963 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
b18bb924 MR |
4964 | |
4965 | /* From MIPSpro N32 ABI Handbook, Document Number: 007-2816-004 | |
4966 | ||
4967 | Function results are returned in $2 (and $3 if needed), or $f0 (and $f2 | |
4968 | if needed), as appropriate for the type. Composite results (struct, | |
4969 | union, or array) are returned in $2/$f0 and $3/$f2 according to the | |
4970 | following rules: | |
4971 | ||
4972 | * A struct with only one or two floating point fields is returned in $f0 | |
4973 | (and $f2 if necessary). This is a generalization of the Fortran COMPLEX | |
4974 | case. | |
4975 | ||
f08877ba | 4976 | * Any other composite results of at most 128 bits are returned in |
b18bb924 MR |
4977 | $2 (first 64 bits) and $3 (remainder, if necessary). |
4978 | ||
4979 | * Larger composite results are handled by converting the function to a | |
4980 | procedure with an implicit first parameter, which is a pointer to an area | |
4981 | reserved by the caller to receive the result. [The o32-bit ABI requires | |
4982 | that all composite results be handled by conversion to implicit first | |
4983 | parameters. The MIPS/SGI Fortran implementation has always made a | |
4984 | specific exception to return COMPLEX results in the floating point | |
4985 | registers.] */ | |
4986 | ||
f08877ba | 4987 | if (TYPE_LENGTH (type) > 2 * MIPS64_REGSIZE) |
6d82d43b | 4988 | return RETURN_VALUE_STRUCT_CONVENTION; |
d05f6826 DJ |
4989 | else if (TYPE_CODE (type) == TYPE_CODE_FLT |
4990 | && TYPE_LENGTH (type) == 16 | |
4991 | && tdep->mips_fpu_type != MIPS_FPU_NONE) | |
4992 | { | |
4993 | /* A 128-bit floating-point value fills both $f0 and $f2. The | |
4994 | two registers are used in the same as memory order, so the | |
4995 | eight bytes with the lower memory address are in $f0. */ | |
4996 | if (mips_debug) | |
4997 | fprintf_unfiltered (gdb_stderr, "Return float in $f0 and $f2\n"); | |
ba32f989 | 4998 | mips_xfer_register (gdbarch, regcache, |
dca9aa3a MR |
4999 | (gdbarch_num_regs (gdbarch) |
5000 | + mips_regnum (gdbarch)->fp0), | |
72a155b4 | 5001 | 8, gdbarch_byte_order (gdbarch), |
4c6b5505 | 5002 | readbuf, writebuf, 0); |
ba32f989 | 5003 | mips_xfer_register (gdbarch, regcache, |
dca9aa3a MR |
5004 | (gdbarch_num_regs (gdbarch) |
5005 | + mips_regnum (gdbarch)->fp0 + 2), | |
72a155b4 | 5006 | 8, gdbarch_byte_order (gdbarch), |
4c6b5505 | 5007 | readbuf ? readbuf + 8 : readbuf, |
d05f6826 DJ |
5008 | writebuf ? writebuf + 8 : writebuf, 0); |
5009 | return RETURN_VALUE_REGISTER_CONVENTION; | |
5010 | } | |
6d82d43b AC |
5011 | else if (TYPE_CODE (type) == TYPE_CODE_FLT |
5012 | && tdep->mips_fpu_type != MIPS_FPU_NONE) | |
5013 | { | |
59aa1faa | 5014 | /* A single or double floating-point value that fits in FP0. */ |
6d82d43b AC |
5015 | if (mips_debug) |
5016 | fprintf_unfiltered (gdb_stderr, "Return float in $fp0\n"); | |
ba32f989 | 5017 | mips_xfer_register (gdbarch, regcache, |
dca9aa3a MR |
5018 | (gdbarch_num_regs (gdbarch) |
5019 | + mips_regnum (gdbarch)->fp0), | |
6d82d43b | 5020 | TYPE_LENGTH (type), |
72a155b4 | 5021 | gdbarch_byte_order (gdbarch), |
4c6b5505 | 5022 | readbuf, writebuf, 0); |
6d82d43b AC |
5023 | return RETURN_VALUE_REGISTER_CONVENTION; |
5024 | } | |
5025 | else if (TYPE_CODE (type) == TYPE_CODE_STRUCT | |
5026 | && TYPE_NFIELDS (type) <= 2 | |
5027 | && TYPE_NFIELDS (type) >= 1 | |
5028 | && ((TYPE_NFIELDS (type) == 1 | |
b18bb924 | 5029 | && (TYPE_CODE (check_typedef (TYPE_FIELD_TYPE (type, 0))) |
6d82d43b AC |
5030 | == TYPE_CODE_FLT)) |
5031 | || (TYPE_NFIELDS (type) == 2 | |
b18bb924 | 5032 | && (TYPE_CODE (check_typedef (TYPE_FIELD_TYPE (type, 0))) |
6d82d43b | 5033 | == TYPE_CODE_FLT) |
b18bb924 | 5034 | && (TYPE_CODE (check_typedef (TYPE_FIELD_TYPE (type, 1))) |
5b68030f | 5035 | == TYPE_CODE_FLT)))) |
6d82d43b AC |
5036 | { |
5037 | /* A struct that contains one or two floats. Each value is part | |
5038 | in the least significant part of their floating point | |
5b68030f | 5039 | register (or GPR, for soft float). */ |
6d82d43b AC |
5040 | int regnum; |
5041 | int field; | |
5b68030f JM |
5042 | for (field = 0, regnum = (tdep->mips_fpu_type != MIPS_FPU_NONE |
5043 | ? mips_regnum (gdbarch)->fp0 | |
5044 | : MIPS_V0_REGNUM); | |
6d82d43b AC |
5045 | field < TYPE_NFIELDS (type); field++, regnum += 2) |
5046 | { | |
5047 | int offset = (FIELD_BITPOS (TYPE_FIELDS (type)[field]) | |
5048 | / TARGET_CHAR_BIT); | |
5049 | if (mips_debug) | |
5050 | fprintf_unfiltered (gdb_stderr, "Return float struct+%d\n", | |
5051 | offset); | |
5b68030f JM |
5052 | if (TYPE_LENGTH (TYPE_FIELD_TYPE (type, field)) == 16) |
5053 | { | |
5054 | /* A 16-byte long double field goes in two consecutive | |
5055 | registers. */ | |
5056 | mips_xfer_register (gdbarch, regcache, | |
5057 | gdbarch_num_regs (gdbarch) + regnum, | |
5058 | 8, | |
5059 | gdbarch_byte_order (gdbarch), | |
5060 | readbuf, writebuf, offset); | |
5061 | mips_xfer_register (gdbarch, regcache, | |
5062 | gdbarch_num_regs (gdbarch) + regnum + 1, | |
5063 | 8, | |
5064 | gdbarch_byte_order (gdbarch), | |
5065 | readbuf, writebuf, offset + 8); | |
5066 | } | |
5067 | else | |
5068 | mips_xfer_register (gdbarch, regcache, | |
5069 | gdbarch_num_regs (gdbarch) + regnum, | |
5070 | TYPE_LENGTH (TYPE_FIELD_TYPE (type, field)), | |
5071 | gdbarch_byte_order (gdbarch), | |
5072 | readbuf, writebuf, offset); | |
6d82d43b AC |
5073 | } |
5074 | return RETURN_VALUE_REGISTER_CONVENTION; | |
5075 | } | |
5076 | else if (TYPE_CODE (type) == TYPE_CODE_STRUCT | |
f08877ba JB |
5077 | || TYPE_CODE (type) == TYPE_CODE_UNION |
5078 | || TYPE_CODE (type) == TYPE_CODE_ARRAY) | |
6d82d43b | 5079 | { |
f08877ba | 5080 | /* A composite type. Extract the left justified value, |
6d82d43b AC |
5081 | regardless of the byte order. I.e. DO NOT USE |
5082 | mips_xfer_lower. */ | |
5083 | int offset; | |
5084 | int regnum; | |
4c7d22cb | 5085 | for (offset = 0, regnum = MIPS_V0_REGNUM; |
6d82d43b | 5086 | offset < TYPE_LENGTH (type); |
72a155b4 | 5087 | offset += register_size (gdbarch, regnum), regnum++) |
6d82d43b | 5088 | { |
72a155b4 | 5089 | int xfer = register_size (gdbarch, regnum); |
6d82d43b AC |
5090 | if (offset + xfer > TYPE_LENGTH (type)) |
5091 | xfer = TYPE_LENGTH (type) - offset; | |
5092 | if (mips_debug) | |
5093 | fprintf_unfiltered (gdb_stderr, "Return struct+%d:%d in $%d\n", | |
5094 | offset, xfer, regnum); | |
ba32f989 DJ |
5095 | mips_xfer_register (gdbarch, regcache, |
5096 | gdbarch_num_regs (gdbarch) + regnum, | |
72a155b4 UW |
5097 | xfer, BFD_ENDIAN_UNKNOWN, readbuf, writebuf, |
5098 | offset); | |
6d82d43b AC |
5099 | } |
5100 | return RETURN_VALUE_REGISTER_CONVENTION; | |
5101 | } | |
5102 | else | |
5103 | { | |
5104 | /* A scalar extract each part but least-significant-byte | |
5105 | justified. */ | |
5106 | int offset; | |
5107 | int regnum; | |
4c7d22cb | 5108 | for (offset = 0, regnum = MIPS_V0_REGNUM; |
6d82d43b | 5109 | offset < TYPE_LENGTH (type); |
72a155b4 | 5110 | offset += register_size (gdbarch, regnum), regnum++) |
6d82d43b | 5111 | { |
72a155b4 | 5112 | int xfer = register_size (gdbarch, regnum); |
6d82d43b AC |
5113 | if (offset + xfer > TYPE_LENGTH (type)) |
5114 | xfer = TYPE_LENGTH (type) - offset; | |
5115 | if (mips_debug) | |
5116 | fprintf_unfiltered (gdb_stderr, "Return scalar+%d:%d in $%d\n", | |
5117 | offset, xfer, regnum); | |
ba32f989 DJ |
5118 | mips_xfer_register (gdbarch, regcache, |
5119 | gdbarch_num_regs (gdbarch) + regnum, | |
72a155b4 | 5120 | xfer, gdbarch_byte_order (gdbarch), |
4c6b5505 | 5121 | readbuf, writebuf, offset); |
6d82d43b AC |
5122 | } |
5123 | return RETURN_VALUE_REGISTER_CONVENTION; | |
5124 | } | |
5125 | } | |
5126 | ||
6a3a010b MR |
5127 | /* Which registers to use for passing floating-point values between |
5128 | function calls, one of floating-point, general and both kinds of | |
5129 | registers. O32 and O64 use different register kinds for standard | |
5130 | MIPS and MIPS16 code; to make the handling of cases where we may | |
5131 | not know what kind of code is being used (e.g. no debug information) | |
5132 | easier we sometimes use both kinds. */ | |
5133 | ||
5134 | enum mips_fval_reg | |
5135 | { | |
5136 | mips_fval_fpr, | |
5137 | mips_fval_gpr, | |
5138 | mips_fval_both | |
5139 | }; | |
5140 | ||
6d82d43b AC |
5141 | /* O32 ABI stuff. */ |
5142 | ||
5143 | static CORE_ADDR | |
7d9b040b | 5144 | mips_o32_push_dummy_call (struct gdbarch *gdbarch, struct value *function, |
6d82d43b AC |
5145 | struct regcache *regcache, CORE_ADDR bp_addr, |
5146 | int nargs, struct value **args, CORE_ADDR sp, | |
5147 | int struct_return, CORE_ADDR struct_addr) | |
5148 | { | |
5149 | int argreg; | |
5150 | int float_argreg; | |
5151 | int argnum; | |
5152 | int len = 0; | |
5153 | int stack_offset = 0; | |
e17a4113 | 5154 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
7d9b040b | 5155 | CORE_ADDR func_addr = find_function_addr (function, NULL); |
6d82d43b AC |
5156 | |
5157 | /* For shared libraries, "t9" needs to point at the function | |
5158 | address. */ | |
4c7d22cb | 5159 | regcache_cooked_write_signed (regcache, MIPS_T9_REGNUM, func_addr); |
6d82d43b AC |
5160 | |
5161 | /* Set the return address register to point to the entry point of | |
5162 | the program, where a breakpoint lies in wait. */ | |
4c7d22cb | 5163 | regcache_cooked_write_signed (regcache, MIPS_RA_REGNUM, bp_addr); |
6d82d43b AC |
5164 | |
5165 | /* First ensure that the stack and structure return address (if any) | |
5166 | are properly aligned. The stack has to be at least 64-bit | |
5167 | aligned even on 32-bit machines, because doubles must be 64-bit | |
ebafbe83 MS |
5168 | aligned. For n32 and n64, stack frames need to be 128-bit |
5169 | aligned, so we round to this widest known alignment. */ | |
5170 | ||
5b03f266 AC |
5171 | sp = align_down (sp, 16); |
5172 | struct_addr = align_down (struct_addr, 16); | |
ebafbe83 MS |
5173 | |
5174 | /* Now make space on the stack for the args. */ | |
5175 | for (argnum = 0; argnum < nargs; argnum++) | |
968b5391 MR |
5176 | { |
5177 | struct type *arg_type = check_typedef (value_type (args[argnum])); | |
968b5391 MR |
5178 | |
5179 | /* Align to double-word if necessary. */ | |
2afd3f0a | 5180 | if (mips_type_needs_double_align (arg_type)) |
1a69e1e4 | 5181 | len = align_up (len, MIPS32_REGSIZE * 2); |
968b5391 | 5182 | /* Allocate space on the stack. */ |
354ecfd5 | 5183 | len += align_up (TYPE_LENGTH (arg_type), MIPS32_REGSIZE); |
968b5391 | 5184 | } |
5b03f266 | 5185 | sp -= align_up (len, 16); |
ebafbe83 MS |
5186 | |
5187 | if (mips_debug) | |
6d82d43b | 5188 | fprintf_unfiltered (gdb_stdlog, |
5af949e3 UW |
5189 | "mips_o32_push_dummy_call: sp=%s allocated %ld\n", |
5190 | paddress (gdbarch, sp), (long) align_up (len, 16)); | |
ebafbe83 MS |
5191 | |
5192 | /* Initialize the integer and float register pointers. */ | |
4c7d22cb | 5193 | argreg = MIPS_A0_REGNUM; |
72a155b4 | 5194 | float_argreg = mips_fpa0_regnum (gdbarch); |
ebafbe83 | 5195 | |
bcb0cc15 | 5196 | /* The struct_return pointer occupies the first parameter-passing reg. */ |
ebafbe83 MS |
5197 | if (struct_return) |
5198 | { | |
5199 | if (mips_debug) | |
5200 | fprintf_unfiltered (gdb_stdlog, | |
025bb325 MS |
5201 | "mips_o32_push_dummy_call: " |
5202 | "struct_return reg=%d %s\n", | |
5af949e3 | 5203 | argreg, paddress (gdbarch, struct_addr)); |
9c9acae0 | 5204 | regcache_cooked_write_unsigned (regcache, argreg++, struct_addr); |
1a69e1e4 | 5205 | stack_offset += MIPS32_REGSIZE; |
ebafbe83 MS |
5206 | } |
5207 | ||
5208 | /* Now load as many as possible of the first arguments into | |
5209 | registers, and push the rest onto the stack. Loop thru args | |
5210 | from first to last. */ | |
5211 | for (argnum = 0; argnum < nargs; argnum++) | |
5212 | { | |
47a35522 | 5213 | const gdb_byte *val; |
ebafbe83 | 5214 | struct value *arg = args[argnum]; |
4991999e | 5215 | struct type *arg_type = check_typedef (value_type (arg)); |
ebafbe83 MS |
5216 | int len = TYPE_LENGTH (arg_type); |
5217 | enum type_code typecode = TYPE_CODE (arg_type); | |
5218 | ||
5219 | if (mips_debug) | |
5220 | fprintf_unfiltered (gdb_stdlog, | |
25ab4790 | 5221 | "mips_o32_push_dummy_call: %d len=%d type=%d", |
46cac009 AC |
5222 | argnum + 1, len, (int) typecode); |
5223 | ||
47a35522 | 5224 | val = value_contents (arg); |
46cac009 AC |
5225 | |
5226 | /* 32-bit ABIs always start floating point arguments in an | |
5227 | even-numbered floating point register. Round the FP register | |
5228 | up before the check to see if there are any FP registers | |
6a3a010b MR |
5229 | left. O32 targets also pass the FP in the integer registers |
5230 | so also round up normal registers. */ | |
74ed0bb4 | 5231 | if (fp_register_arg_p (gdbarch, typecode, arg_type)) |
46cac009 AC |
5232 | { |
5233 | if ((float_argreg & 1)) | |
5234 | float_argreg++; | |
5235 | } | |
5236 | ||
5237 | /* Floating point arguments passed in registers have to be | |
6a3a010b MR |
5238 | treated specially. On 32-bit architectures, doubles are |
5239 | passed in register pairs; the even FP register gets the | |
5240 | low word, and the odd FP register gets the high word. | |
5241 | On O32, the first two floating point arguments are also | |
5242 | copied to general registers, following their memory order, | |
5243 | because MIPS16 functions don't use float registers for | |
5244 | arguments. This duplication of arguments in general | |
5245 | registers can't hurt non-MIPS16 functions, because those | |
5246 | registers are normally skipped. */ | |
46cac009 | 5247 | |
74ed0bb4 MD |
5248 | if (fp_register_arg_p (gdbarch, typecode, arg_type) |
5249 | && float_argreg <= MIPS_LAST_FP_ARG_REGNUM (gdbarch)) | |
46cac009 | 5250 | { |
8b07f6d8 | 5251 | if (register_size (gdbarch, float_argreg) < 8 && len == 8) |
46cac009 | 5252 | { |
6a3a010b MR |
5253 | int freg_offset = gdbarch_byte_order (gdbarch) |
5254 | == BFD_ENDIAN_BIG ? 1 : 0; | |
46cac009 AC |
5255 | unsigned long regval; |
5256 | ||
6a3a010b MR |
5257 | /* First word. */ |
5258 | regval = extract_unsigned_integer (val, 4, byte_order); | |
46cac009 AC |
5259 | if (mips_debug) |
5260 | fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s", | |
6a3a010b MR |
5261 | float_argreg + freg_offset, |
5262 | phex (regval, 4)); | |
025bb325 | 5263 | regcache_cooked_write_unsigned (regcache, |
6a3a010b MR |
5264 | float_argreg++ + freg_offset, |
5265 | regval); | |
46cac009 AC |
5266 | if (mips_debug) |
5267 | fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s", | |
5268 | argreg, phex (regval, 4)); | |
9c9acae0 | 5269 | regcache_cooked_write_unsigned (regcache, argreg++, regval); |
46cac009 | 5270 | |
6a3a010b MR |
5271 | /* Second word. */ |
5272 | regval = extract_unsigned_integer (val + 4, 4, byte_order); | |
46cac009 AC |
5273 | if (mips_debug) |
5274 | fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s", | |
6a3a010b MR |
5275 | float_argreg - freg_offset, |
5276 | phex (regval, 4)); | |
025bb325 | 5277 | regcache_cooked_write_unsigned (regcache, |
6a3a010b MR |
5278 | float_argreg++ - freg_offset, |
5279 | regval); | |
46cac009 AC |
5280 | if (mips_debug) |
5281 | fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s", | |
5282 | argreg, phex (regval, 4)); | |
9c9acae0 | 5283 | regcache_cooked_write_unsigned (regcache, argreg++, regval); |
46cac009 AC |
5284 | } |
5285 | else | |
5286 | { | |
5287 | /* This is a floating point value that fits entirely | |
5288 | in a single register. */ | |
5289 | /* On 32 bit ABI's the float_argreg is further adjusted | |
6d82d43b | 5290 | above to ensure that it is even register aligned. */ |
e17a4113 | 5291 | LONGEST regval = extract_unsigned_integer (val, len, byte_order); |
46cac009 AC |
5292 | if (mips_debug) |
5293 | fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s", | |
5294 | float_argreg, phex (regval, len)); | |
025bb325 MS |
5295 | regcache_cooked_write_unsigned (regcache, |
5296 | float_argreg++, regval); | |
5b68030f JM |
5297 | /* Although two FP registers are reserved for each |
5298 | argument, only one corresponding integer register is | |
5299 | reserved. */ | |
46cac009 AC |
5300 | if (mips_debug) |
5301 | fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s", | |
5302 | argreg, phex (regval, len)); | |
5b68030f | 5303 | regcache_cooked_write_unsigned (regcache, argreg++, regval); |
46cac009 AC |
5304 | } |
5305 | /* Reserve space for the FP register. */ | |
1a69e1e4 | 5306 | stack_offset += align_up (len, MIPS32_REGSIZE); |
46cac009 AC |
5307 | } |
5308 | else | |
5309 | { | |
5310 | /* Copy the argument to general registers or the stack in | |
5311 | register-sized pieces. Large arguments are split between | |
5312 | registers and stack. */ | |
1a69e1e4 DJ |
5313 | /* Note: structs whose size is not a multiple of MIPS32_REGSIZE |
5314 | are treated specially: Irix cc passes | |
d5ac5a39 AC |
5315 | them in registers where gcc sometimes puts them on the |
5316 | stack. For maximum compatibility, we will put them in | |
5317 | both places. */ | |
1a69e1e4 DJ |
5318 | int odd_sized_struct = (len > MIPS32_REGSIZE |
5319 | && len % MIPS32_REGSIZE != 0); | |
46cac009 AC |
5320 | /* Structures should be aligned to eight bytes (even arg registers) |
5321 | on MIPS_ABI_O32, if their first member has double precision. */ | |
2afd3f0a | 5322 | if (mips_type_needs_double_align (arg_type)) |
46cac009 AC |
5323 | { |
5324 | if ((argreg & 1)) | |
968b5391 MR |
5325 | { |
5326 | argreg++; | |
1a69e1e4 | 5327 | stack_offset += MIPS32_REGSIZE; |
968b5391 | 5328 | } |
46cac009 | 5329 | } |
46cac009 AC |
5330 | while (len > 0) |
5331 | { | |
5332 | /* Remember if the argument was written to the stack. */ | |
5333 | int stack_used_p = 0; | |
1a69e1e4 | 5334 | int partial_len = (len < MIPS32_REGSIZE ? len : MIPS32_REGSIZE); |
46cac009 AC |
5335 | |
5336 | if (mips_debug) | |
5337 | fprintf_unfiltered (gdb_stdlog, " -- partial=%d", | |
5338 | partial_len); | |
5339 | ||
5340 | /* Write this portion of the argument to the stack. */ | |
74ed0bb4 | 5341 | if (argreg > MIPS_LAST_ARG_REGNUM (gdbarch) |
968b5391 | 5342 | || odd_sized_struct) |
46cac009 AC |
5343 | { |
5344 | /* Should shorter than int integer values be | |
025bb325 | 5345 | promoted to int before being stored? */ |
46cac009 AC |
5346 | int longword_offset = 0; |
5347 | CORE_ADDR addr; | |
5348 | stack_used_p = 1; | |
46cac009 AC |
5349 | |
5350 | if (mips_debug) | |
5351 | { | |
5af949e3 UW |
5352 | fprintf_unfiltered (gdb_stdlog, " - stack_offset=%s", |
5353 | paddress (gdbarch, stack_offset)); | |
5354 | fprintf_unfiltered (gdb_stdlog, " longword_offset=%s", | |
5355 | paddress (gdbarch, longword_offset)); | |
46cac009 AC |
5356 | } |
5357 | ||
5358 | addr = sp + stack_offset + longword_offset; | |
5359 | ||
5360 | if (mips_debug) | |
5361 | { | |
5362 | int i; | |
5af949e3 UW |
5363 | fprintf_unfiltered (gdb_stdlog, " @%s ", |
5364 | paddress (gdbarch, addr)); | |
46cac009 AC |
5365 | for (i = 0; i < partial_len; i++) |
5366 | { | |
6d82d43b | 5367 | fprintf_unfiltered (gdb_stdlog, "%02x", |
46cac009 AC |
5368 | val[i] & 0xff); |
5369 | } | |
5370 | } | |
5371 | write_memory (addr, val, partial_len); | |
5372 | } | |
5373 | ||
5374 | /* Note!!! This is NOT an else clause. Odd sized | |
968b5391 | 5375 | structs may go thru BOTH paths. */ |
46cac009 | 5376 | /* Write this portion of the argument to a general |
6d82d43b | 5377 | purpose register. */ |
74ed0bb4 | 5378 | if (argreg <= MIPS_LAST_ARG_REGNUM (gdbarch)) |
46cac009 | 5379 | { |
e17a4113 UW |
5380 | LONGEST regval = extract_signed_integer (val, partial_len, |
5381 | byte_order); | |
4246e332 | 5382 | /* Value may need to be sign extended, because |
1b13c4f6 | 5383 | mips_isa_regsize() != mips_abi_regsize(). */ |
46cac009 AC |
5384 | |
5385 | /* A non-floating-point argument being passed in a | |
5386 | general register. If a struct or union, and if | |
5387 | the remaining length is smaller than the register | |
5388 | size, we have to adjust the register value on | |
5389 | big endian targets. | |
5390 | ||
5391 | It does not seem to be necessary to do the | |
5392 | same for integral types. | |
5393 | ||
5394 | Also don't do this adjustment on O64 binaries. | |
5395 | ||
5396 | cagney/2001-07-23: gdb/179: Also, GCC, when | |
5397 | outputting LE O32 with sizeof (struct) < | |
e914cb17 MR |
5398 | mips_abi_regsize(), generates a left shift |
5399 | as part of storing the argument in a register | |
5400 | (the left shift isn't generated when | |
1b13c4f6 | 5401 | sizeof (struct) >= mips_abi_regsize()). Since |
480d3dd2 AC |
5402 | it is quite possible that this is GCC |
5403 | contradicting the LE/O32 ABI, GDB has not been | |
5404 | adjusted to accommodate this. Either someone | |
5405 | needs to demonstrate that the LE/O32 ABI | |
5406 | specifies such a left shift OR this new ABI gets | |
5407 | identified as such and GDB gets tweaked | |
5408 | accordingly. */ | |
5409 | ||
72a155b4 | 5410 | if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG |
1a69e1e4 | 5411 | && partial_len < MIPS32_REGSIZE |
06f9a1af MR |
5412 | && (typecode == TYPE_CODE_STRUCT |
5413 | || typecode == TYPE_CODE_UNION)) | |
1a69e1e4 | 5414 | regval <<= ((MIPS32_REGSIZE - partial_len) |
9ecf7166 | 5415 | * TARGET_CHAR_BIT); |
46cac009 AC |
5416 | |
5417 | if (mips_debug) | |
5418 | fprintf_filtered (gdb_stdlog, " - reg=%d val=%s", | |
5419 | argreg, | |
1a69e1e4 | 5420 | phex (regval, MIPS32_REGSIZE)); |
9c9acae0 | 5421 | regcache_cooked_write_unsigned (regcache, argreg, regval); |
46cac009 AC |
5422 | argreg++; |
5423 | ||
5424 | /* Prevent subsequent floating point arguments from | |
5425 | being passed in floating point registers. */ | |
74ed0bb4 | 5426 | float_argreg = MIPS_LAST_FP_ARG_REGNUM (gdbarch) + 1; |
46cac009 AC |
5427 | } |
5428 | ||
5429 | len -= partial_len; | |
5430 | val += partial_len; | |
5431 | ||
b021a221 MS |
5432 | /* Compute the offset into the stack at which we will |
5433 | copy the next parameter. | |
46cac009 | 5434 | |
6d82d43b AC |
5435 | In older ABIs, the caller reserved space for |
5436 | registers that contained arguments. This was loosely | |
5437 | refered to as their "home". Consequently, space is | |
5438 | always allocated. */ | |
46cac009 | 5439 | |
1a69e1e4 | 5440 | stack_offset += align_up (partial_len, MIPS32_REGSIZE); |
46cac009 AC |
5441 | } |
5442 | } | |
5443 | if (mips_debug) | |
5444 | fprintf_unfiltered (gdb_stdlog, "\n"); | |
5445 | } | |
5446 | ||
f10683bb | 5447 | regcache_cooked_write_signed (regcache, MIPS_SP_REGNUM, sp); |
310e9b6a | 5448 | |
46cac009 AC |
5449 | /* Return adjusted stack pointer. */ |
5450 | return sp; | |
5451 | } | |
5452 | ||
6d82d43b | 5453 | static enum return_value_convention |
6a3a010b | 5454 | mips_o32_return_value (struct gdbarch *gdbarch, struct value *function, |
c055b101 | 5455 | struct type *type, struct regcache *regcache, |
47a35522 | 5456 | gdb_byte *readbuf, const gdb_byte *writebuf) |
6d82d43b | 5457 | { |
6a3a010b | 5458 | CORE_ADDR func_addr = function ? find_function_addr (function, NULL) : 0; |
4cc0665f | 5459 | int mips16 = mips_pc_is_mips16 (gdbarch, func_addr); |
72a155b4 | 5460 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
6a3a010b | 5461 | enum mips_fval_reg fval_reg; |
6d82d43b | 5462 | |
6a3a010b | 5463 | fval_reg = readbuf ? mips16 ? mips_fval_gpr : mips_fval_fpr : mips_fval_both; |
6d82d43b AC |
5464 | if (TYPE_CODE (type) == TYPE_CODE_STRUCT |
5465 | || TYPE_CODE (type) == TYPE_CODE_UNION | |
5466 | || TYPE_CODE (type) == TYPE_CODE_ARRAY) | |
5467 | return RETURN_VALUE_STRUCT_CONVENTION; | |
5468 | else if (TYPE_CODE (type) == TYPE_CODE_FLT | |
5469 | && TYPE_LENGTH (type) == 4 && tdep->mips_fpu_type != MIPS_FPU_NONE) | |
5470 | { | |
6a3a010b MR |
5471 | /* A single-precision floating-point value. If reading in or copying, |
5472 | then we get it from/put it to FP0 for standard MIPS code or GPR2 | |
5473 | for MIPS16 code. If writing out only, then we put it to both FP0 | |
5474 | and GPR2. We do not support reading in with no function known, if | |
5475 | this safety check ever triggers, then we'll have to try harder. */ | |
5476 | gdb_assert (function || !readbuf); | |
6d82d43b | 5477 | if (mips_debug) |
6a3a010b MR |
5478 | switch (fval_reg) |
5479 | { | |
5480 | case mips_fval_fpr: | |
5481 | fprintf_unfiltered (gdb_stderr, "Return float in $fp0\n"); | |
5482 | break; | |
5483 | case mips_fval_gpr: | |
5484 | fprintf_unfiltered (gdb_stderr, "Return float in $2\n"); | |
5485 | break; | |
5486 | case mips_fval_both: | |
5487 | fprintf_unfiltered (gdb_stderr, "Return float in $fp0 and $2\n"); | |
5488 | break; | |
5489 | } | |
5490 | if (fval_reg != mips_fval_gpr) | |
5491 | mips_xfer_register (gdbarch, regcache, | |
5492 | (gdbarch_num_regs (gdbarch) | |
5493 | + mips_regnum (gdbarch)->fp0), | |
5494 | TYPE_LENGTH (type), | |
5495 | gdbarch_byte_order (gdbarch), | |
5496 | readbuf, writebuf, 0); | |
5497 | if (fval_reg != mips_fval_fpr) | |
5498 | mips_xfer_register (gdbarch, regcache, | |
5499 | gdbarch_num_regs (gdbarch) + 2, | |
5500 | TYPE_LENGTH (type), | |
5501 | gdbarch_byte_order (gdbarch), | |
5502 | readbuf, writebuf, 0); | |
6d82d43b AC |
5503 | return RETURN_VALUE_REGISTER_CONVENTION; |
5504 | } | |
5505 | else if (TYPE_CODE (type) == TYPE_CODE_FLT | |
5506 | && TYPE_LENGTH (type) == 8 && tdep->mips_fpu_type != MIPS_FPU_NONE) | |
5507 | { | |
6a3a010b MR |
5508 | /* A double-precision floating-point value. If reading in or copying, |
5509 | then we get it from/put it to FP1 and FP0 for standard MIPS code or | |
5510 | GPR2 and GPR3 for MIPS16 code. If writing out only, then we put it | |
5511 | to both FP1/FP0 and GPR2/GPR3. We do not support reading in with | |
5512 | no function known, if this safety check ever triggers, then we'll | |
5513 | have to try harder. */ | |
5514 | gdb_assert (function || !readbuf); | |
6d82d43b | 5515 | if (mips_debug) |
6a3a010b MR |
5516 | switch (fval_reg) |
5517 | { | |
5518 | case mips_fval_fpr: | |
5519 | fprintf_unfiltered (gdb_stderr, "Return float in $fp1/$fp0\n"); | |
5520 | break; | |
5521 | case mips_fval_gpr: | |
5522 | fprintf_unfiltered (gdb_stderr, "Return float in $2/$3\n"); | |
5523 | break; | |
5524 | case mips_fval_both: | |
5525 | fprintf_unfiltered (gdb_stderr, | |
5526 | "Return float in $fp1/$fp0 and $2/$3\n"); | |
5527 | break; | |
5528 | } | |
5529 | if (fval_reg != mips_fval_gpr) | |
6d82d43b | 5530 | { |
6a3a010b MR |
5531 | /* The most significant part goes in FP1, and the least significant |
5532 | in FP0. */ | |
5533 | switch (gdbarch_byte_order (gdbarch)) | |
5534 | { | |
5535 | case BFD_ENDIAN_LITTLE: | |
5536 | mips_xfer_register (gdbarch, regcache, | |
5537 | (gdbarch_num_regs (gdbarch) | |
5538 | + mips_regnum (gdbarch)->fp0 + 0), | |
5539 | 4, gdbarch_byte_order (gdbarch), | |
5540 | readbuf, writebuf, 0); | |
5541 | mips_xfer_register (gdbarch, regcache, | |
5542 | (gdbarch_num_regs (gdbarch) | |
5543 | + mips_regnum (gdbarch)->fp0 + 1), | |
5544 | 4, gdbarch_byte_order (gdbarch), | |
5545 | readbuf, writebuf, 4); | |
5546 | break; | |
5547 | case BFD_ENDIAN_BIG: | |
5548 | mips_xfer_register (gdbarch, regcache, | |
5549 | (gdbarch_num_regs (gdbarch) | |
5550 | + mips_regnum (gdbarch)->fp0 + 1), | |
5551 | 4, gdbarch_byte_order (gdbarch), | |
5552 | readbuf, writebuf, 0); | |
5553 | mips_xfer_register (gdbarch, regcache, | |
5554 | (gdbarch_num_regs (gdbarch) | |
5555 | + mips_regnum (gdbarch)->fp0 + 0), | |
5556 | 4, gdbarch_byte_order (gdbarch), | |
5557 | readbuf, writebuf, 4); | |
5558 | break; | |
5559 | default: | |
5560 | internal_error (__FILE__, __LINE__, _("bad switch")); | |
5561 | } | |
5562 | } | |
5563 | if (fval_reg != mips_fval_fpr) | |
5564 | { | |
5565 | /* The two 32-bit parts are always placed in GPR2 and GPR3 | |
5566 | following these registers' memory order. */ | |
ba32f989 | 5567 | mips_xfer_register (gdbarch, regcache, |
6a3a010b | 5568 | gdbarch_num_regs (gdbarch) + 2, |
72a155b4 | 5569 | 4, gdbarch_byte_order (gdbarch), |
4c6b5505 | 5570 | readbuf, writebuf, 0); |
ba32f989 | 5571 | mips_xfer_register (gdbarch, regcache, |
6a3a010b | 5572 | gdbarch_num_regs (gdbarch) + 3, |
72a155b4 | 5573 | 4, gdbarch_byte_order (gdbarch), |
4c6b5505 | 5574 | readbuf, writebuf, 4); |
6d82d43b AC |
5575 | } |
5576 | return RETURN_VALUE_REGISTER_CONVENTION; | |
5577 | } | |
5578 | #if 0 | |
5579 | else if (TYPE_CODE (type) == TYPE_CODE_STRUCT | |
5580 | && TYPE_NFIELDS (type) <= 2 | |
5581 | && TYPE_NFIELDS (type) >= 1 | |
5582 | && ((TYPE_NFIELDS (type) == 1 | |
5583 | && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) | |
5584 | == TYPE_CODE_FLT)) | |
5585 | || (TYPE_NFIELDS (type) == 2 | |
5586 | && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) | |
5587 | == TYPE_CODE_FLT) | |
5588 | && (TYPE_CODE (TYPE_FIELD_TYPE (type, 1)) | |
5589 | == TYPE_CODE_FLT))) | |
5590 | && tdep->mips_fpu_type != MIPS_FPU_NONE) | |
5591 | { | |
5592 | /* A struct that contains one or two floats. Each value is part | |
5593 | in the least significant part of their floating point | |
5594 | register.. */ | |
870cd05e | 5595 | gdb_byte reg[MAX_REGISTER_SIZE]; |
6d82d43b AC |
5596 | int regnum; |
5597 | int field; | |
72a155b4 | 5598 | for (field = 0, regnum = mips_regnum (gdbarch)->fp0; |
6d82d43b AC |
5599 | field < TYPE_NFIELDS (type); field++, regnum += 2) |
5600 | { | |
5601 | int offset = (FIELD_BITPOS (TYPE_FIELDS (type)[field]) | |
5602 | / TARGET_CHAR_BIT); | |
5603 | if (mips_debug) | |
5604 | fprintf_unfiltered (gdb_stderr, "Return float struct+%d\n", | |
5605 | offset); | |
ba32f989 DJ |
5606 | mips_xfer_register (gdbarch, regcache, |
5607 | gdbarch_num_regs (gdbarch) + regnum, | |
6d82d43b | 5608 | TYPE_LENGTH (TYPE_FIELD_TYPE (type, field)), |
72a155b4 | 5609 | gdbarch_byte_order (gdbarch), |
4c6b5505 | 5610 | readbuf, writebuf, offset); |
6d82d43b AC |
5611 | } |
5612 | return RETURN_VALUE_REGISTER_CONVENTION; | |
5613 | } | |
5614 | #endif | |
5615 | #if 0 | |
5616 | else if (TYPE_CODE (type) == TYPE_CODE_STRUCT | |
5617 | || TYPE_CODE (type) == TYPE_CODE_UNION) | |
5618 | { | |
5619 | /* A structure or union. Extract the left justified value, | |
5620 | regardless of the byte order. I.e. DO NOT USE | |
5621 | mips_xfer_lower. */ | |
5622 | int offset; | |
5623 | int regnum; | |
4c7d22cb | 5624 | for (offset = 0, regnum = MIPS_V0_REGNUM; |
6d82d43b | 5625 | offset < TYPE_LENGTH (type); |
72a155b4 | 5626 | offset += register_size (gdbarch, regnum), regnum++) |
6d82d43b | 5627 | { |
72a155b4 | 5628 | int xfer = register_size (gdbarch, regnum); |
6d82d43b AC |
5629 | if (offset + xfer > TYPE_LENGTH (type)) |
5630 | xfer = TYPE_LENGTH (type) - offset; | |
5631 | if (mips_debug) | |
5632 | fprintf_unfiltered (gdb_stderr, "Return struct+%d:%d in $%d\n", | |
5633 | offset, xfer, regnum); | |
ba32f989 DJ |
5634 | mips_xfer_register (gdbarch, regcache, |
5635 | gdbarch_num_regs (gdbarch) + regnum, xfer, | |
6d82d43b AC |
5636 | BFD_ENDIAN_UNKNOWN, readbuf, writebuf, offset); |
5637 | } | |
5638 | return RETURN_VALUE_REGISTER_CONVENTION; | |
5639 | } | |
5640 | #endif | |
5641 | else | |
5642 | { | |
5643 | /* A scalar extract each part but least-significant-byte | |
5644 | justified. o32 thinks registers are 4 byte, regardless of | |
1a69e1e4 | 5645 | the ISA. */ |
6d82d43b AC |
5646 | int offset; |
5647 | int regnum; | |
4c7d22cb | 5648 | for (offset = 0, regnum = MIPS_V0_REGNUM; |
6d82d43b | 5649 | offset < TYPE_LENGTH (type); |
1a69e1e4 | 5650 | offset += MIPS32_REGSIZE, regnum++) |
6d82d43b | 5651 | { |
1a69e1e4 | 5652 | int xfer = MIPS32_REGSIZE; |
6d82d43b AC |
5653 | if (offset + xfer > TYPE_LENGTH (type)) |
5654 | xfer = TYPE_LENGTH (type) - offset; | |
5655 | if (mips_debug) | |
5656 | fprintf_unfiltered (gdb_stderr, "Return scalar+%d:%d in $%d\n", | |
5657 | offset, xfer, regnum); | |
ba32f989 DJ |
5658 | mips_xfer_register (gdbarch, regcache, |
5659 | gdbarch_num_regs (gdbarch) + regnum, xfer, | |
72a155b4 | 5660 | gdbarch_byte_order (gdbarch), |
4c6b5505 | 5661 | readbuf, writebuf, offset); |
6d82d43b AC |
5662 | } |
5663 | return RETURN_VALUE_REGISTER_CONVENTION; | |
5664 | } | |
5665 | } | |
5666 | ||
5667 | /* O64 ABI. This is a hacked up kind of 64-bit version of the o32 | |
5668 | ABI. */ | |
46cac009 AC |
5669 | |
5670 | static CORE_ADDR | |
7d9b040b | 5671 | mips_o64_push_dummy_call (struct gdbarch *gdbarch, struct value *function, |
6d82d43b AC |
5672 | struct regcache *regcache, CORE_ADDR bp_addr, |
5673 | int nargs, | |
5674 | struct value **args, CORE_ADDR sp, | |
5675 | int struct_return, CORE_ADDR struct_addr) | |
46cac009 AC |
5676 | { |
5677 | int argreg; | |
5678 | int float_argreg; | |
5679 | int argnum; | |
5680 | int len = 0; | |
5681 | int stack_offset = 0; | |
e17a4113 | 5682 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
7d9b040b | 5683 | CORE_ADDR func_addr = find_function_addr (function, NULL); |
46cac009 | 5684 | |
25ab4790 AC |
5685 | /* For shared libraries, "t9" needs to point at the function |
5686 | address. */ | |
4c7d22cb | 5687 | regcache_cooked_write_signed (regcache, MIPS_T9_REGNUM, func_addr); |
25ab4790 AC |
5688 | |
5689 | /* Set the return address register to point to the entry point of | |
5690 | the program, where a breakpoint lies in wait. */ | |
4c7d22cb | 5691 | regcache_cooked_write_signed (regcache, MIPS_RA_REGNUM, bp_addr); |
25ab4790 | 5692 | |
46cac009 AC |
5693 | /* First ensure that the stack and structure return address (if any) |
5694 | are properly aligned. The stack has to be at least 64-bit | |
5695 | aligned even on 32-bit machines, because doubles must be 64-bit | |
5696 | aligned. For n32 and n64, stack frames need to be 128-bit | |
5697 | aligned, so we round to this widest known alignment. */ | |
5698 | ||
5b03f266 AC |
5699 | sp = align_down (sp, 16); |
5700 | struct_addr = align_down (struct_addr, 16); | |
46cac009 AC |
5701 | |
5702 | /* Now make space on the stack for the args. */ | |
5703 | for (argnum = 0; argnum < nargs; argnum++) | |
968b5391 MR |
5704 | { |
5705 | struct type *arg_type = check_typedef (value_type (args[argnum])); | |
968b5391 | 5706 | |
968b5391 | 5707 | /* Allocate space on the stack. */ |
354ecfd5 | 5708 | len += align_up (TYPE_LENGTH (arg_type), MIPS64_REGSIZE); |
968b5391 | 5709 | } |
5b03f266 | 5710 | sp -= align_up (len, 16); |
46cac009 AC |
5711 | |
5712 | if (mips_debug) | |
6d82d43b | 5713 | fprintf_unfiltered (gdb_stdlog, |
5af949e3 UW |
5714 | "mips_o64_push_dummy_call: sp=%s allocated %ld\n", |
5715 | paddress (gdbarch, sp), (long) align_up (len, 16)); | |
46cac009 AC |
5716 | |
5717 | /* Initialize the integer and float register pointers. */ | |
4c7d22cb | 5718 | argreg = MIPS_A0_REGNUM; |
72a155b4 | 5719 | float_argreg = mips_fpa0_regnum (gdbarch); |
46cac009 AC |
5720 | |
5721 | /* The struct_return pointer occupies the first parameter-passing reg. */ | |
5722 | if (struct_return) | |
5723 | { | |
5724 | if (mips_debug) | |
5725 | fprintf_unfiltered (gdb_stdlog, | |
025bb325 MS |
5726 | "mips_o64_push_dummy_call: " |
5727 | "struct_return reg=%d %s\n", | |
5af949e3 | 5728 | argreg, paddress (gdbarch, struct_addr)); |
9c9acae0 | 5729 | regcache_cooked_write_unsigned (regcache, argreg++, struct_addr); |
1a69e1e4 | 5730 | stack_offset += MIPS64_REGSIZE; |
46cac009 AC |
5731 | } |
5732 | ||
5733 | /* Now load as many as possible of the first arguments into | |
5734 | registers, and push the rest onto the stack. Loop thru args | |
5735 | from first to last. */ | |
5736 | for (argnum = 0; argnum < nargs; argnum++) | |
5737 | { | |
47a35522 | 5738 | const gdb_byte *val; |
930bd0e0 | 5739 | gdb_byte valbuf[MAX_REGISTER_SIZE]; |
46cac009 | 5740 | struct value *arg = args[argnum]; |
4991999e | 5741 | struct type *arg_type = check_typedef (value_type (arg)); |
46cac009 AC |
5742 | int len = TYPE_LENGTH (arg_type); |
5743 | enum type_code typecode = TYPE_CODE (arg_type); | |
5744 | ||
5745 | if (mips_debug) | |
5746 | fprintf_unfiltered (gdb_stdlog, | |
25ab4790 | 5747 | "mips_o64_push_dummy_call: %d len=%d type=%d", |
ebafbe83 MS |
5748 | argnum + 1, len, (int) typecode); |
5749 | ||
47a35522 | 5750 | val = value_contents (arg); |
ebafbe83 | 5751 | |
930bd0e0 KB |
5752 | /* Function pointer arguments to mips16 code need to be made into |
5753 | mips16 pointers. */ | |
5754 | if (typecode == TYPE_CODE_PTR | |
5755 | && TYPE_CODE (TYPE_TARGET_TYPE (arg_type)) == TYPE_CODE_FUNC) | |
5756 | { | |
5757 | CORE_ADDR addr = extract_signed_integer (value_contents (arg), | |
5758 | len, byte_order); | |
4cc0665f | 5759 | if (!mips_pc_is_mips (addr)) |
930bd0e0 KB |
5760 | { |
5761 | store_signed_integer (valbuf, len, byte_order, | |
4cc0665f | 5762 | make_compact_addr (addr)); |
930bd0e0 KB |
5763 | val = valbuf; |
5764 | } | |
5765 | } | |
5766 | ||
ebafbe83 | 5767 | /* Floating point arguments passed in registers have to be |
6a3a010b MR |
5768 | treated specially. On 32-bit architectures, doubles are |
5769 | passed in register pairs; the even FP register gets the | |
5770 | low word, and the odd FP register gets the high word. | |
5771 | On O64, the first two floating point arguments are also | |
5772 | copied to general registers, because MIPS16 functions | |
5773 | don't use float registers for arguments. This duplication | |
5774 | of arguments in general registers can't hurt non-MIPS16 | |
5775 | functions because those registers are normally skipped. */ | |
ebafbe83 | 5776 | |
74ed0bb4 MD |
5777 | if (fp_register_arg_p (gdbarch, typecode, arg_type) |
5778 | && float_argreg <= MIPS_LAST_FP_ARG_REGNUM (gdbarch)) | |
ebafbe83 | 5779 | { |
e17a4113 | 5780 | LONGEST regval = extract_unsigned_integer (val, len, byte_order); |
2afd3f0a MR |
5781 | if (mips_debug) |
5782 | fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s", | |
5783 | float_argreg, phex (regval, len)); | |
9c9acae0 | 5784 | regcache_cooked_write_unsigned (regcache, float_argreg++, regval); |
2afd3f0a MR |
5785 | if (mips_debug) |
5786 | fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s", | |
5787 | argreg, phex (regval, len)); | |
9c9acae0 | 5788 | regcache_cooked_write_unsigned (regcache, argreg, regval); |
2afd3f0a | 5789 | argreg++; |
ebafbe83 | 5790 | /* Reserve space for the FP register. */ |
1a69e1e4 | 5791 | stack_offset += align_up (len, MIPS64_REGSIZE); |
ebafbe83 MS |
5792 | } |
5793 | else | |
5794 | { | |
5795 | /* Copy the argument to general registers or the stack in | |
5796 | register-sized pieces. Large arguments are split between | |
5797 | registers and stack. */ | |
1a69e1e4 | 5798 | /* Note: structs whose size is not a multiple of MIPS64_REGSIZE |
436aafc4 MR |
5799 | are treated specially: Irix cc passes them in registers |
5800 | where gcc sometimes puts them on the stack. For maximum | |
5801 | compatibility, we will put them in both places. */ | |
1a69e1e4 DJ |
5802 | int odd_sized_struct = (len > MIPS64_REGSIZE |
5803 | && len % MIPS64_REGSIZE != 0); | |
ebafbe83 MS |
5804 | while (len > 0) |
5805 | { | |
5806 | /* Remember if the argument was written to the stack. */ | |
5807 | int stack_used_p = 0; | |
1a69e1e4 | 5808 | int partial_len = (len < MIPS64_REGSIZE ? len : MIPS64_REGSIZE); |
ebafbe83 MS |
5809 | |
5810 | if (mips_debug) | |
5811 | fprintf_unfiltered (gdb_stdlog, " -- partial=%d", | |
5812 | partial_len); | |
5813 | ||
5814 | /* Write this portion of the argument to the stack. */ | |
74ed0bb4 | 5815 | if (argreg > MIPS_LAST_ARG_REGNUM (gdbarch) |
968b5391 | 5816 | || odd_sized_struct) |
ebafbe83 MS |
5817 | { |
5818 | /* Should shorter than int integer values be | |
025bb325 | 5819 | promoted to int before being stored? */ |
ebafbe83 MS |
5820 | int longword_offset = 0; |
5821 | CORE_ADDR addr; | |
5822 | stack_used_p = 1; | |
72a155b4 | 5823 | if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) |
ebafbe83 | 5824 | { |
1a69e1e4 DJ |
5825 | if ((typecode == TYPE_CODE_INT |
5826 | || typecode == TYPE_CODE_PTR | |
5827 | || typecode == TYPE_CODE_FLT) | |
5828 | && len <= 4) | |
5829 | longword_offset = MIPS64_REGSIZE - len; | |
ebafbe83 MS |
5830 | } |
5831 | ||
5832 | if (mips_debug) | |
5833 | { | |
5af949e3 UW |
5834 | fprintf_unfiltered (gdb_stdlog, " - stack_offset=%s", |
5835 | paddress (gdbarch, stack_offset)); | |
5836 | fprintf_unfiltered (gdb_stdlog, " longword_offset=%s", | |
5837 | paddress (gdbarch, longword_offset)); | |
ebafbe83 MS |
5838 | } |
5839 | ||
5840 | addr = sp + stack_offset + longword_offset; | |
5841 | ||
5842 | if (mips_debug) | |
5843 | { | |
5844 | int i; | |
5af949e3 UW |
5845 | fprintf_unfiltered (gdb_stdlog, " @%s ", |
5846 | paddress (gdbarch, addr)); | |
ebafbe83 MS |
5847 | for (i = 0; i < partial_len; i++) |
5848 | { | |
6d82d43b | 5849 | fprintf_unfiltered (gdb_stdlog, "%02x", |
ebafbe83 MS |
5850 | val[i] & 0xff); |
5851 | } | |
5852 | } | |
5853 | write_memory (addr, val, partial_len); | |
5854 | } | |
5855 | ||
5856 | /* Note!!! This is NOT an else clause. Odd sized | |
968b5391 | 5857 | structs may go thru BOTH paths. */ |
ebafbe83 | 5858 | /* Write this portion of the argument to a general |
6d82d43b | 5859 | purpose register. */ |
74ed0bb4 | 5860 | if (argreg <= MIPS_LAST_ARG_REGNUM (gdbarch)) |
ebafbe83 | 5861 | { |
e17a4113 UW |
5862 | LONGEST regval = extract_signed_integer (val, partial_len, |
5863 | byte_order); | |
4246e332 | 5864 | /* Value may need to be sign extended, because |
1b13c4f6 | 5865 | mips_isa_regsize() != mips_abi_regsize(). */ |
ebafbe83 MS |
5866 | |
5867 | /* A non-floating-point argument being passed in a | |
5868 | general register. If a struct or union, and if | |
5869 | the remaining length is smaller than the register | |
5870 | size, we have to adjust the register value on | |
5871 | big endian targets. | |
5872 | ||
5873 | It does not seem to be necessary to do the | |
025bb325 | 5874 | same for integral types. */ |
480d3dd2 | 5875 | |
72a155b4 | 5876 | if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG |
1a69e1e4 | 5877 | && partial_len < MIPS64_REGSIZE |
06f9a1af MR |
5878 | && (typecode == TYPE_CODE_STRUCT |
5879 | || typecode == TYPE_CODE_UNION)) | |
1a69e1e4 | 5880 | regval <<= ((MIPS64_REGSIZE - partial_len) |
9ecf7166 | 5881 | * TARGET_CHAR_BIT); |
ebafbe83 MS |
5882 | |
5883 | if (mips_debug) | |
5884 | fprintf_filtered (gdb_stdlog, " - reg=%d val=%s", | |
5885 | argreg, | |
1a69e1e4 | 5886 | phex (regval, MIPS64_REGSIZE)); |
9c9acae0 | 5887 | regcache_cooked_write_unsigned (regcache, argreg, regval); |
ebafbe83 MS |
5888 | argreg++; |
5889 | ||
5890 | /* Prevent subsequent floating point arguments from | |
5891 | being passed in floating point registers. */ | |
74ed0bb4 | 5892 | float_argreg = MIPS_LAST_FP_ARG_REGNUM (gdbarch) + 1; |
ebafbe83 MS |
5893 | } |
5894 | ||
5895 | len -= partial_len; | |
5896 | val += partial_len; | |
5897 | ||
b021a221 MS |
5898 | /* Compute the offset into the stack at which we will |
5899 | copy the next parameter. | |
ebafbe83 | 5900 | |
6d82d43b AC |
5901 | In older ABIs, the caller reserved space for |
5902 | registers that contained arguments. This was loosely | |
5903 | refered to as their "home". Consequently, space is | |
5904 | always allocated. */ | |
ebafbe83 | 5905 | |
1a69e1e4 | 5906 | stack_offset += align_up (partial_len, MIPS64_REGSIZE); |
ebafbe83 MS |
5907 | } |
5908 | } | |
5909 | if (mips_debug) | |
5910 | fprintf_unfiltered (gdb_stdlog, "\n"); | |
5911 | } | |
5912 | ||
f10683bb | 5913 | regcache_cooked_write_signed (regcache, MIPS_SP_REGNUM, sp); |
310e9b6a | 5914 | |
ebafbe83 MS |
5915 | /* Return adjusted stack pointer. */ |
5916 | return sp; | |
5917 | } | |
5918 | ||
9c8fdbfa | 5919 | static enum return_value_convention |
6a3a010b | 5920 | mips_o64_return_value (struct gdbarch *gdbarch, struct value *function, |
9c8fdbfa | 5921 | struct type *type, struct regcache *regcache, |
47a35522 | 5922 | gdb_byte *readbuf, const gdb_byte *writebuf) |
6d82d43b | 5923 | { |
6a3a010b | 5924 | CORE_ADDR func_addr = function ? find_function_addr (function, NULL) : 0; |
4cc0665f | 5925 | int mips16 = mips_pc_is_mips16 (gdbarch, func_addr); |
72a155b4 | 5926 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
6a3a010b | 5927 | enum mips_fval_reg fval_reg; |
7a076fd2 | 5928 | |
6a3a010b | 5929 | fval_reg = readbuf ? mips16 ? mips_fval_gpr : mips_fval_fpr : mips_fval_both; |
7a076fd2 FF |
5930 | if (TYPE_CODE (type) == TYPE_CODE_STRUCT |
5931 | || TYPE_CODE (type) == TYPE_CODE_UNION | |
5932 | || TYPE_CODE (type) == TYPE_CODE_ARRAY) | |
5933 | return RETURN_VALUE_STRUCT_CONVENTION; | |
74ed0bb4 | 5934 | else if (fp_register_arg_p (gdbarch, TYPE_CODE (type), type)) |
7a076fd2 | 5935 | { |
6a3a010b MR |
5936 | /* A floating-point value. If reading in or copying, then we get it |
5937 | from/put it to FP0 for standard MIPS code or GPR2 for MIPS16 code. | |
5938 | If writing out only, then we put it to both FP0 and GPR2. We do | |
5939 | not support reading in with no function known, if this safety | |
5940 | check ever triggers, then we'll have to try harder. */ | |
5941 | gdb_assert (function || !readbuf); | |
7a076fd2 | 5942 | if (mips_debug) |
6a3a010b MR |
5943 | switch (fval_reg) |
5944 | { | |
5945 | case mips_fval_fpr: | |
5946 | fprintf_unfiltered (gdb_stderr, "Return float in $fp0\n"); | |
5947 | break; | |
5948 | case mips_fval_gpr: | |
5949 | fprintf_unfiltered (gdb_stderr, "Return float in $2\n"); | |
5950 | break; | |
5951 | case mips_fval_both: | |
5952 | fprintf_unfiltered (gdb_stderr, "Return float in $fp0 and $2\n"); | |
5953 | break; | |
5954 | } | |
5955 | if (fval_reg != mips_fval_gpr) | |
5956 | mips_xfer_register (gdbarch, regcache, | |
5957 | (gdbarch_num_regs (gdbarch) | |
5958 | + mips_regnum (gdbarch)->fp0), | |
5959 | TYPE_LENGTH (type), | |
5960 | gdbarch_byte_order (gdbarch), | |
5961 | readbuf, writebuf, 0); | |
5962 | if (fval_reg != mips_fval_fpr) | |
5963 | mips_xfer_register (gdbarch, regcache, | |
5964 | gdbarch_num_regs (gdbarch) + 2, | |
5965 | TYPE_LENGTH (type), | |
5966 | gdbarch_byte_order (gdbarch), | |
5967 | readbuf, writebuf, 0); | |
7a076fd2 FF |
5968 | return RETURN_VALUE_REGISTER_CONVENTION; |
5969 | } | |
5970 | else | |
5971 | { | |
5972 | /* A scalar extract each part but least-significant-byte | |
025bb325 | 5973 | justified. */ |
7a076fd2 FF |
5974 | int offset; |
5975 | int regnum; | |
5976 | for (offset = 0, regnum = MIPS_V0_REGNUM; | |
5977 | offset < TYPE_LENGTH (type); | |
1a69e1e4 | 5978 | offset += MIPS64_REGSIZE, regnum++) |
7a076fd2 | 5979 | { |
1a69e1e4 | 5980 | int xfer = MIPS64_REGSIZE; |
7a076fd2 FF |
5981 | if (offset + xfer > TYPE_LENGTH (type)) |
5982 | xfer = TYPE_LENGTH (type) - offset; | |
5983 | if (mips_debug) | |
5984 | fprintf_unfiltered (gdb_stderr, "Return scalar+%d:%d in $%d\n", | |
5985 | offset, xfer, regnum); | |
ba32f989 DJ |
5986 | mips_xfer_register (gdbarch, regcache, |
5987 | gdbarch_num_regs (gdbarch) + regnum, | |
72a155b4 | 5988 | xfer, gdbarch_byte_order (gdbarch), |
4c6b5505 | 5989 | readbuf, writebuf, offset); |
7a076fd2 FF |
5990 | } |
5991 | return RETURN_VALUE_REGISTER_CONVENTION; | |
5992 | } | |
6d82d43b AC |
5993 | } |
5994 | ||
dd824b04 DJ |
5995 | /* Floating point register management. |
5996 | ||
5997 | Background: MIPS1 & 2 fp registers are 32 bits wide. To support | |
5998 | 64bit operations, these early MIPS cpus treat fp register pairs | |
5999 | (f0,f1) as a single register (d0). Later MIPS cpu's have 64 bit fp | |
6000 | registers and offer a compatibility mode that emulates the MIPS2 fp | |
6001 | model. When operating in MIPS2 fp compat mode, later cpu's split | |
6002 | double precision floats into two 32-bit chunks and store them in | |
6003 | consecutive fp regs. To display 64-bit floats stored in this | |
6004 | fashion, we have to combine 32 bits from f0 and 32 bits from f1. | |
6005 | Throw in user-configurable endianness and you have a real mess. | |
6006 | ||
6007 | The way this works is: | |
6008 | - If we are in 32-bit mode or on a 32-bit processor, then a 64-bit | |
6009 | double-precision value will be split across two logical registers. | |
6010 | The lower-numbered logical register will hold the low-order bits, | |
6011 | regardless of the processor's endianness. | |
6012 | - If we are on a 64-bit processor, and we are looking for a | |
6013 | single-precision value, it will be in the low ordered bits | |
6014 | of a 64-bit GPR (after mfc1, for example) or a 64-bit register | |
6015 | save slot in memory. | |
6016 | - If we are in 64-bit mode, everything is straightforward. | |
6017 | ||
6018 | Note that this code only deals with "live" registers at the top of the | |
6019 | stack. We will attempt to deal with saved registers later, when | |
025bb325 | 6020 | the raw/cooked register interface is in place. (We need a general |
dd824b04 DJ |
6021 | interface that can deal with dynamic saved register sizes -- fp |
6022 | regs could be 32 bits wide in one frame and 64 on the frame above | |
6023 | and below). */ | |
6024 | ||
6025 | /* Copy a 32-bit single-precision value from the current frame | |
6026 | into rare_buffer. */ | |
6027 | ||
6028 | static void | |
e11c53d2 | 6029 | mips_read_fp_register_single (struct frame_info *frame, int regno, |
47a35522 | 6030 | gdb_byte *rare_buffer) |
dd824b04 | 6031 | { |
72a155b4 UW |
6032 | struct gdbarch *gdbarch = get_frame_arch (frame); |
6033 | int raw_size = register_size (gdbarch, regno); | |
47a35522 | 6034 | gdb_byte *raw_buffer = alloca (raw_size); |
dd824b04 | 6035 | |
ca9d61b9 | 6036 | if (!deprecated_frame_register_read (frame, regno, raw_buffer)) |
c9f4d572 | 6037 | error (_("can't read register %d (%s)"), |
72a155b4 | 6038 | regno, gdbarch_register_name (gdbarch, regno)); |
dd824b04 DJ |
6039 | if (raw_size == 8) |
6040 | { | |
6041 | /* We have a 64-bit value for this register. Find the low-order | |
6d82d43b | 6042 | 32 bits. */ |
dd824b04 DJ |
6043 | int offset; |
6044 | ||
72a155b4 | 6045 | if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) |
dd824b04 DJ |
6046 | offset = 4; |
6047 | else | |
6048 | offset = 0; | |
6049 | ||
6050 | memcpy (rare_buffer, raw_buffer + offset, 4); | |
6051 | } | |
6052 | else | |
6053 | { | |
6054 | memcpy (rare_buffer, raw_buffer, 4); | |
6055 | } | |
6056 | } | |
6057 | ||
6058 | /* Copy a 64-bit double-precision value from the current frame into | |
6059 | rare_buffer. This may include getting half of it from the next | |
6060 | register. */ | |
6061 | ||
6062 | static void | |
e11c53d2 | 6063 | mips_read_fp_register_double (struct frame_info *frame, int regno, |
47a35522 | 6064 | gdb_byte *rare_buffer) |
dd824b04 | 6065 | { |
72a155b4 UW |
6066 | struct gdbarch *gdbarch = get_frame_arch (frame); |
6067 | int raw_size = register_size (gdbarch, regno); | |
dd824b04 | 6068 | |
9c9acae0 | 6069 | if (raw_size == 8 && !mips2_fp_compat (frame)) |
dd824b04 DJ |
6070 | { |
6071 | /* We have a 64-bit value for this register, and we should use | |
6d82d43b | 6072 | all 64 bits. */ |
ca9d61b9 | 6073 | if (!deprecated_frame_register_read (frame, regno, rare_buffer)) |
c9f4d572 | 6074 | error (_("can't read register %d (%s)"), |
72a155b4 | 6075 | regno, gdbarch_register_name (gdbarch, regno)); |
dd824b04 DJ |
6076 | } |
6077 | else | |
6078 | { | |
72a155b4 | 6079 | int rawnum = regno % gdbarch_num_regs (gdbarch); |
82e91389 | 6080 | |
72a155b4 | 6081 | if ((rawnum - mips_regnum (gdbarch)->fp0) & 1) |
dd824b04 | 6082 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 AC |
6083 | _("mips_read_fp_register_double: bad access to " |
6084 | "odd-numbered FP register")); | |
dd824b04 DJ |
6085 | |
6086 | /* mips_read_fp_register_single will find the correct 32 bits from | |
6d82d43b | 6087 | each register. */ |
72a155b4 | 6088 | if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) |
dd824b04 | 6089 | { |
e11c53d2 AC |
6090 | mips_read_fp_register_single (frame, regno, rare_buffer + 4); |
6091 | mips_read_fp_register_single (frame, regno + 1, rare_buffer); | |
dd824b04 | 6092 | } |
361d1df0 | 6093 | else |
dd824b04 | 6094 | { |
e11c53d2 AC |
6095 | mips_read_fp_register_single (frame, regno, rare_buffer); |
6096 | mips_read_fp_register_single (frame, regno + 1, rare_buffer + 4); | |
dd824b04 DJ |
6097 | } |
6098 | } | |
6099 | } | |
6100 | ||
c906108c | 6101 | static void |
e11c53d2 AC |
6102 | mips_print_fp_register (struct ui_file *file, struct frame_info *frame, |
6103 | int regnum) | |
025bb325 | 6104 | { /* Do values for FP (float) regs. */ |
72a155b4 | 6105 | struct gdbarch *gdbarch = get_frame_arch (frame); |
47a35522 | 6106 | gdb_byte *raw_buffer; |
025bb325 | 6107 | double doub, flt1; /* Doubles extracted from raw hex data. */ |
3903d437 | 6108 | int inv1, inv2; |
c5aa993b | 6109 | |
025bb325 MS |
6110 | raw_buffer = alloca (2 * register_size (gdbarch, |
6111 | mips_regnum (gdbarch)->fp0)); | |
c906108c | 6112 | |
72a155b4 | 6113 | fprintf_filtered (file, "%s:", gdbarch_register_name (gdbarch, regnum)); |
c9f4d572 | 6114 | fprintf_filtered (file, "%*s", |
72a155b4 | 6115 | 4 - (int) strlen (gdbarch_register_name (gdbarch, regnum)), |
e11c53d2 | 6116 | ""); |
f0ef6b29 | 6117 | |
72a155b4 | 6118 | if (register_size (gdbarch, regnum) == 4 || mips2_fp_compat (frame)) |
c906108c | 6119 | { |
79a45b7d TT |
6120 | struct value_print_options opts; |
6121 | ||
f0ef6b29 KB |
6122 | /* 4-byte registers: Print hex and floating. Also print even |
6123 | numbered registers as doubles. */ | |
e11c53d2 | 6124 | mips_read_fp_register_single (frame, regnum, raw_buffer); |
025bb325 MS |
6125 | flt1 = unpack_double (builtin_type (gdbarch)->builtin_float, |
6126 | raw_buffer, &inv1); | |
c5aa993b | 6127 | |
79a45b7d | 6128 | get_formatted_print_options (&opts, 'x'); |
df4df182 UW |
6129 | print_scalar_formatted (raw_buffer, |
6130 | builtin_type (gdbarch)->builtin_uint32, | |
6131 | &opts, 'w', file); | |
dd824b04 | 6132 | |
e11c53d2 | 6133 | fprintf_filtered (file, " flt: "); |
1adad886 | 6134 | if (inv1) |
e11c53d2 | 6135 | fprintf_filtered (file, " <invalid float> "); |
1adad886 | 6136 | else |
e11c53d2 | 6137 | fprintf_filtered (file, "%-17.9g", flt1); |
1adad886 | 6138 | |
72a155b4 | 6139 | if ((regnum - gdbarch_num_regs (gdbarch)) % 2 == 0) |
f0ef6b29 | 6140 | { |
e11c53d2 | 6141 | mips_read_fp_register_double (frame, regnum, raw_buffer); |
27067745 UW |
6142 | doub = unpack_double (builtin_type (gdbarch)->builtin_double, |
6143 | raw_buffer, &inv2); | |
1adad886 | 6144 | |
e11c53d2 | 6145 | fprintf_filtered (file, " dbl: "); |
f0ef6b29 | 6146 | if (inv2) |
e11c53d2 | 6147 | fprintf_filtered (file, "<invalid double>"); |
f0ef6b29 | 6148 | else |
e11c53d2 | 6149 | fprintf_filtered (file, "%-24.17g", doub); |
f0ef6b29 | 6150 | } |
c906108c SS |
6151 | } |
6152 | else | |
dd824b04 | 6153 | { |
79a45b7d TT |
6154 | struct value_print_options opts; |
6155 | ||
f0ef6b29 | 6156 | /* Eight byte registers: print each one as hex, float and double. */ |
e11c53d2 | 6157 | mips_read_fp_register_single (frame, regnum, raw_buffer); |
27067745 UW |
6158 | flt1 = unpack_double (builtin_type (gdbarch)->builtin_float, |
6159 | raw_buffer, &inv1); | |
c906108c | 6160 | |
e11c53d2 | 6161 | mips_read_fp_register_double (frame, regnum, raw_buffer); |
27067745 UW |
6162 | doub = unpack_double (builtin_type (gdbarch)->builtin_double, |
6163 | raw_buffer, &inv2); | |
f0ef6b29 | 6164 | |
79a45b7d | 6165 | get_formatted_print_options (&opts, 'x'); |
df4df182 UW |
6166 | print_scalar_formatted (raw_buffer, |
6167 | builtin_type (gdbarch)->builtin_uint64, | |
6168 | &opts, 'g', file); | |
f0ef6b29 | 6169 | |
e11c53d2 | 6170 | fprintf_filtered (file, " flt: "); |
1adad886 | 6171 | if (inv1) |
e11c53d2 | 6172 | fprintf_filtered (file, "<invalid float>"); |
1adad886 | 6173 | else |
e11c53d2 | 6174 | fprintf_filtered (file, "%-17.9g", flt1); |
1adad886 | 6175 | |
e11c53d2 | 6176 | fprintf_filtered (file, " dbl: "); |
f0ef6b29 | 6177 | if (inv2) |
e11c53d2 | 6178 | fprintf_filtered (file, "<invalid double>"); |
1adad886 | 6179 | else |
e11c53d2 | 6180 | fprintf_filtered (file, "%-24.17g", doub); |
f0ef6b29 KB |
6181 | } |
6182 | } | |
6183 | ||
6184 | static void | |
e11c53d2 | 6185 | mips_print_register (struct ui_file *file, struct frame_info *frame, |
0cc93a06 | 6186 | int regnum) |
f0ef6b29 | 6187 | { |
a4b8ebc8 | 6188 | struct gdbarch *gdbarch = get_frame_arch (frame); |
79a45b7d | 6189 | struct value_print_options opts; |
de15c4ab | 6190 | struct value *val; |
1adad886 | 6191 | |
004159a2 | 6192 | if (mips_float_register_p (gdbarch, regnum)) |
f0ef6b29 | 6193 | { |
e11c53d2 | 6194 | mips_print_fp_register (file, frame, regnum); |
f0ef6b29 KB |
6195 | return; |
6196 | } | |
6197 | ||
de15c4ab PA |
6198 | val = get_frame_register_value (frame, regnum); |
6199 | if (value_optimized_out (val)) | |
f0ef6b29 | 6200 | { |
c9f4d572 | 6201 | fprintf_filtered (file, "%s: [Invalid]", |
72a155b4 | 6202 | gdbarch_register_name (gdbarch, regnum)); |
f0ef6b29 | 6203 | return; |
c906108c | 6204 | } |
f0ef6b29 | 6205 | |
72a155b4 | 6206 | fputs_filtered (gdbarch_register_name (gdbarch, regnum), file); |
f0ef6b29 KB |
6207 | |
6208 | /* The problem with printing numeric register names (r26, etc.) is that | |
6209 | the user can't use them on input. Probably the best solution is to | |
6210 | fix it so that either the numeric or the funky (a2, etc.) names | |
6211 | are accepted on input. */ | |
6212 | if (regnum < MIPS_NUMREGS) | |
e11c53d2 | 6213 | fprintf_filtered (file, "(r%d): ", regnum); |
f0ef6b29 | 6214 | else |
e11c53d2 | 6215 | fprintf_filtered (file, ": "); |
f0ef6b29 | 6216 | |
79a45b7d | 6217 | get_formatted_print_options (&opts, 'x'); |
de15c4ab PA |
6218 | val_print_scalar_formatted (value_type (val), |
6219 | value_contents_for_printing (val), | |
6220 | value_embedded_offset (val), | |
6221 | val, | |
6222 | &opts, 0, file); | |
c906108c SS |
6223 | } |
6224 | ||
f0ef6b29 KB |
6225 | /* Replacement for generic do_registers_info. |
6226 | Print regs in pretty columns. */ | |
6227 | ||
6228 | static int | |
e11c53d2 AC |
6229 | print_fp_register_row (struct ui_file *file, struct frame_info *frame, |
6230 | int regnum) | |
f0ef6b29 | 6231 | { |
e11c53d2 AC |
6232 | fprintf_filtered (file, " "); |
6233 | mips_print_fp_register (file, frame, regnum); | |
6234 | fprintf_filtered (file, "\n"); | |
f0ef6b29 KB |
6235 | return regnum + 1; |
6236 | } | |
6237 | ||
6238 | ||
025bb325 | 6239 | /* Print a row's worth of GP (int) registers, with name labels above. */ |
c906108c SS |
6240 | |
6241 | static int | |
e11c53d2 | 6242 | print_gp_register_row (struct ui_file *file, struct frame_info *frame, |
a4b8ebc8 | 6243 | int start_regnum) |
c906108c | 6244 | { |
a4b8ebc8 | 6245 | struct gdbarch *gdbarch = get_frame_arch (frame); |
025bb325 | 6246 | /* Do values for GP (int) regs. */ |
47a35522 | 6247 | gdb_byte raw_buffer[MAX_REGISTER_SIZE]; |
025bb325 MS |
6248 | int ncols = (mips_abi_regsize (gdbarch) == 8 ? 4 : 8); /* display cols |
6249 | per row. */ | |
c906108c | 6250 | int col, byte; |
a4b8ebc8 | 6251 | int regnum; |
c906108c | 6252 | |
025bb325 | 6253 | /* For GP registers, we print a separate row of names above the vals. */ |
a4b8ebc8 | 6254 | for (col = 0, regnum = start_regnum; |
72a155b4 UW |
6255 | col < ncols && regnum < gdbarch_num_regs (gdbarch) |
6256 | + gdbarch_num_pseudo_regs (gdbarch); | |
f57d151a | 6257 | regnum++) |
c906108c | 6258 | { |
72a155b4 | 6259 | if (*gdbarch_register_name (gdbarch, regnum) == '\0') |
c5aa993b | 6260 | continue; /* unused register */ |
004159a2 | 6261 | if (mips_float_register_p (gdbarch, regnum)) |
025bb325 | 6262 | break; /* End the row: reached FP register. */ |
0cc93a06 | 6263 | /* Large registers are handled separately. */ |
72a155b4 | 6264 | if (register_size (gdbarch, regnum) > mips_abi_regsize (gdbarch)) |
0cc93a06 DJ |
6265 | { |
6266 | if (col > 0) | |
6267 | break; /* End the row before this register. */ | |
6268 | ||
6269 | /* Print this register on a row by itself. */ | |
6270 | mips_print_register (file, frame, regnum); | |
6271 | fprintf_filtered (file, "\n"); | |
6272 | return regnum + 1; | |
6273 | } | |
d05f6826 DJ |
6274 | if (col == 0) |
6275 | fprintf_filtered (file, " "); | |
6d82d43b | 6276 | fprintf_filtered (file, |
72a155b4 UW |
6277 | mips_abi_regsize (gdbarch) == 8 ? "%17s" : "%9s", |
6278 | gdbarch_register_name (gdbarch, regnum)); | |
c906108c SS |
6279 | col++; |
6280 | } | |
d05f6826 DJ |
6281 | |
6282 | if (col == 0) | |
6283 | return regnum; | |
6284 | ||
025bb325 | 6285 | /* Print the R0 to R31 names. */ |
72a155b4 | 6286 | if ((start_regnum % gdbarch_num_regs (gdbarch)) < MIPS_NUMREGS) |
f57d151a | 6287 | fprintf_filtered (file, "\n R%-4d", |
72a155b4 | 6288 | start_regnum % gdbarch_num_regs (gdbarch)); |
20e6603c AC |
6289 | else |
6290 | fprintf_filtered (file, "\n "); | |
c906108c | 6291 | |
025bb325 | 6292 | /* Now print the values in hex, 4 or 8 to the row. */ |
a4b8ebc8 | 6293 | for (col = 0, regnum = start_regnum; |
72a155b4 UW |
6294 | col < ncols && regnum < gdbarch_num_regs (gdbarch) |
6295 | + gdbarch_num_pseudo_regs (gdbarch); | |
f57d151a | 6296 | regnum++) |
c906108c | 6297 | { |
72a155b4 | 6298 | if (*gdbarch_register_name (gdbarch, regnum) == '\0') |
c5aa993b | 6299 | continue; /* unused register */ |
004159a2 | 6300 | if (mips_float_register_p (gdbarch, regnum)) |
025bb325 | 6301 | break; /* End row: reached FP register. */ |
72a155b4 | 6302 | if (register_size (gdbarch, regnum) > mips_abi_regsize (gdbarch)) |
0cc93a06 DJ |
6303 | break; /* End row: large register. */ |
6304 | ||
c906108c | 6305 | /* OK: get the data in raw format. */ |
ca9d61b9 | 6306 | if (!deprecated_frame_register_read (frame, regnum, raw_buffer)) |
c9f4d572 | 6307 | error (_("can't read register %d (%s)"), |
72a155b4 | 6308 | regnum, gdbarch_register_name (gdbarch, regnum)); |
c906108c | 6309 | /* pad small registers */ |
4246e332 | 6310 | for (byte = 0; |
72a155b4 UW |
6311 | byte < (mips_abi_regsize (gdbarch) |
6312 | - register_size (gdbarch, regnum)); byte++) | |
c906108c | 6313 | printf_filtered (" "); |
025bb325 | 6314 | /* Now print the register value in hex, endian order. */ |
72a155b4 | 6315 | if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) |
6d82d43b | 6316 | for (byte = |
72a155b4 UW |
6317 | register_size (gdbarch, regnum) - register_size (gdbarch, regnum); |
6318 | byte < register_size (gdbarch, regnum); byte++) | |
47a35522 | 6319 | fprintf_filtered (file, "%02x", raw_buffer[byte]); |
c906108c | 6320 | else |
72a155b4 | 6321 | for (byte = register_size (gdbarch, regnum) - 1; |
6d82d43b | 6322 | byte >= 0; byte--) |
47a35522 | 6323 | fprintf_filtered (file, "%02x", raw_buffer[byte]); |
e11c53d2 | 6324 | fprintf_filtered (file, " "); |
c906108c SS |
6325 | col++; |
6326 | } | |
025bb325 | 6327 | if (col > 0) /* ie. if we actually printed anything... */ |
e11c53d2 | 6328 | fprintf_filtered (file, "\n"); |
c906108c SS |
6329 | |
6330 | return regnum; | |
6331 | } | |
6332 | ||
025bb325 | 6333 | /* MIPS_DO_REGISTERS_INFO(): called by "info register" command. */ |
c906108c | 6334 | |
bf1f5b4c | 6335 | static void |
e11c53d2 AC |
6336 | mips_print_registers_info (struct gdbarch *gdbarch, struct ui_file *file, |
6337 | struct frame_info *frame, int regnum, int all) | |
c906108c | 6338 | { |
025bb325 | 6339 | if (regnum != -1) /* Do one specified register. */ |
c906108c | 6340 | { |
72a155b4 UW |
6341 | gdb_assert (regnum >= gdbarch_num_regs (gdbarch)); |
6342 | if (*(gdbarch_register_name (gdbarch, regnum)) == '\0') | |
8a3fe4f8 | 6343 | error (_("Not a valid register for the current processor type")); |
c906108c | 6344 | |
0cc93a06 | 6345 | mips_print_register (file, frame, regnum); |
e11c53d2 | 6346 | fprintf_filtered (file, "\n"); |
c906108c | 6347 | } |
c5aa993b | 6348 | else |
025bb325 | 6349 | /* Do all (or most) registers. */ |
c906108c | 6350 | { |
72a155b4 UW |
6351 | regnum = gdbarch_num_regs (gdbarch); |
6352 | while (regnum < gdbarch_num_regs (gdbarch) | |
6353 | + gdbarch_num_pseudo_regs (gdbarch)) | |
c906108c | 6354 | { |
004159a2 | 6355 | if (mips_float_register_p (gdbarch, regnum)) |
e11c53d2 | 6356 | { |
025bb325 | 6357 | if (all) /* True for "INFO ALL-REGISTERS" command. */ |
e11c53d2 AC |
6358 | regnum = print_fp_register_row (file, frame, regnum); |
6359 | else | |
025bb325 | 6360 | regnum += MIPS_NUMREGS; /* Skip floating point regs. */ |
e11c53d2 | 6361 | } |
c906108c | 6362 | else |
e11c53d2 | 6363 | regnum = print_gp_register_row (file, frame, regnum); |
c906108c SS |
6364 | } |
6365 | } | |
6366 | } | |
6367 | ||
63807e1d | 6368 | static int |
3352ef37 AC |
6369 | mips_single_step_through_delay (struct gdbarch *gdbarch, |
6370 | struct frame_info *frame) | |
c906108c | 6371 | { |
e17a4113 | 6372 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
3352ef37 | 6373 | CORE_ADDR pc = get_frame_pc (frame); |
4cc0665f MR |
6374 | struct address_space *aspace; |
6375 | enum mips_isa isa; | |
6376 | ULONGEST insn; | |
6377 | int status; | |
6378 | int size; | |
6379 | ||
6380 | if ((mips_pc_is_mips (pc) | |
6381 | && !mips32_instruction_has_delay_slot (gdbarch, pc)) | |
6382 | || (mips_pc_is_micromips (gdbarch, pc) | |
6383 | && !micromips_instruction_has_delay_slot (gdbarch, pc, 0)) | |
6384 | || (mips_pc_is_mips16 (gdbarch, pc) | |
6385 | && !mips16_instruction_has_delay_slot (gdbarch, pc, 0))) | |
06648491 MK |
6386 | return 0; |
6387 | ||
4cc0665f MR |
6388 | isa = mips_pc_isa (gdbarch, pc); |
6389 | /* _has_delay_slot above will have validated the read. */ | |
6390 | insn = mips_fetch_instruction (gdbarch, isa, pc, NULL); | |
6391 | size = mips_insn_size (isa, insn); | |
6392 | aspace = get_frame_address_space (frame); | |
6393 | return breakpoint_here_p (aspace, pc + size) != no_breakpoint_here; | |
c906108c SS |
6394 | } |
6395 | ||
6d82d43b AC |
6396 | /* To skip prologues, I use this predicate. Returns either PC itself |
6397 | if the code at PC does not look like a function prologue; otherwise | |
6398 | returns an address that (if we're lucky) follows the prologue. If | |
6399 | LENIENT, then we must skip everything which is involved in setting | |
6400 | up the frame (it's OK to skip more, just so long as we don't skip | |
6401 | anything which might clobber the registers which are being saved. | |
6402 | We must skip more in the case where part of the prologue is in the | |
6403 | delay slot of a non-prologue instruction). */ | |
6404 | ||
6405 | static CORE_ADDR | |
6093d2eb | 6406 | mips_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc) |
6d82d43b | 6407 | { |
8b622e6a AC |
6408 | CORE_ADDR limit_pc; |
6409 | CORE_ADDR func_addr; | |
6410 | ||
6d82d43b AC |
6411 | /* See if we can determine the end of the prologue via the symbol table. |
6412 | If so, then return either PC, or the PC after the prologue, whichever | |
6413 | is greater. */ | |
8b622e6a AC |
6414 | if (find_pc_partial_function (pc, NULL, &func_addr, NULL)) |
6415 | { | |
d80b854b UW |
6416 | CORE_ADDR post_prologue_pc |
6417 | = skip_prologue_using_sal (gdbarch, func_addr); | |
8b622e6a AC |
6418 | if (post_prologue_pc != 0) |
6419 | return max (pc, post_prologue_pc); | |
6420 | } | |
6d82d43b AC |
6421 | |
6422 | /* Can't determine prologue from the symbol table, need to examine | |
6423 | instructions. */ | |
6424 | ||
98b4dd94 JB |
6425 | /* Find an upper limit on the function prologue using the debug |
6426 | information. If the debug information could not be used to provide | |
6427 | that bound, then use an arbitrary large number as the upper bound. */ | |
d80b854b | 6428 | limit_pc = skip_prologue_using_sal (gdbarch, pc); |
98b4dd94 JB |
6429 | if (limit_pc == 0) |
6430 | limit_pc = pc + 100; /* Magic. */ | |
6431 | ||
4cc0665f | 6432 | if (mips_pc_is_mips16 (gdbarch, pc)) |
e17a4113 | 6433 | return mips16_scan_prologue (gdbarch, pc, limit_pc, NULL, NULL); |
4cc0665f MR |
6434 | else if (mips_pc_is_micromips (gdbarch, pc)) |
6435 | return micromips_scan_prologue (gdbarch, pc, limit_pc, NULL, NULL); | |
6d82d43b | 6436 | else |
e17a4113 | 6437 | return mips32_scan_prologue (gdbarch, pc, limit_pc, NULL, NULL); |
88658117 AC |
6438 | } |
6439 | ||
97ab0fdd MR |
6440 | /* Check whether the PC is in a function epilogue (32-bit version). |
6441 | This is a helper function for mips_in_function_epilogue_p. */ | |
6442 | static int | |
e17a4113 | 6443 | mips32_in_function_epilogue_p (struct gdbarch *gdbarch, CORE_ADDR pc) |
97ab0fdd MR |
6444 | { |
6445 | CORE_ADDR func_addr = 0, func_end = 0; | |
6446 | ||
6447 | if (find_pc_partial_function (pc, NULL, &func_addr, &func_end)) | |
6448 | { | |
6449 | /* The MIPS epilogue is max. 12 bytes long. */ | |
6450 | CORE_ADDR addr = func_end - 12; | |
6451 | ||
6452 | if (addr < func_addr + 4) | |
6453 | addr = func_addr + 4; | |
6454 | if (pc < addr) | |
6455 | return 0; | |
6456 | ||
6457 | for (; pc < func_end; pc += MIPS_INSN32_SIZE) | |
6458 | { | |
6459 | unsigned long high_word; | |
6460 | unsigned long inst; | |
6461 | ||
4cc0665f | 6462 | inst = mips_fetch_instruction (gdbarch, ISA_MIPS, pc, NULL); |
97ab0fdd MR |
6463 | high_word = (inst >> 16) & 0xffff; |
6464 | ||
6465 | if (high_word != 0x27bd /* addiu $sp,$sp,offset */ | |
6466 | && high_word != 0x67bd /* daddiu $sp,$sp,offset */ | |
6467 | && inst != 0x03e00008 /* jr $ra */ | |
6468 | && inst != 0x00000000) /* nop */ | |
6469 | return 0; | |
6470 | } | |
6471 | ||
6472 | return 1; | |
6473 | } | |
6474 | ||
6475 | return 0; | |
6476 | } | |
6477 | ||
4cc0665f MR |
6478 | /* Check whether the PC is in a function epilogue (microMIPS version). |
6479 | This is a helper function for mips_in_function_epilogue_p. */ | |
6480 | ||
6481 | static int | |
6482 | micromips_in_function_epilogue_p (struct gdbarch *gdbarch, CORE_ADDR pc) | |
6483 | { | |
6484 | CORE_ADDR func_addr = 0; | |
6485 | CORE_ADDR func_end = 0; | |
6486 | CORE_ADDR addr; | |
6487 | ULONGEST insn; | |
6488 | long offset; | |
6489 | int dreg; | |
6490 | int sreg; | |
6491 | int loc; | |
6492 | ||
6493 | if (!find_pc_partial_function (pc, NULL, &func_addr, &func_end)) | |
6494 | return 0; | |
6495 | ||
6496 | /* The microMIPS epilogue is max. 12 bytes long. */ | |
6497 | addr = func_end - 12; | |
6498 | ||
6499 | if (addr < func_addr + 2) | |
6500 | addr = func_addr + 2; | |
6501 | if (pc < addr) | |
6502 | return 0; | |
6503 | ||
6504 | for (; pc < func_end; pc += loc) | |
6505 | { | |
6506 | loc = 0; | |
6507 | insn = mips_fetch_instruction (gdbarch, ISA_MICROMIPS, pc, NULL); | |
6508 | loc += MIPS_INSN16_SIZE; | |
6509 | switch (mips_insn_size (ISA_MICROMIPS, insn)) | |
6510 | { | |
6511 | /* 48-bit instructions. */ | |
6512 | case 3 * MIPS_INSN16_SIZE: | |
6513 | /* No epilogue instructions in this category. */ | |
6514 | return 0; | |
6515 | ||
6516 | /* 32-bit instructions. */ | |
6517 | case 2 * MIPS_INSN16_SIZE: | |
6518 | insn <<= 16; | |
6519 | insn |= mips_fetch_instruction (gdbarch, | |
6520 | ISA_MICROMIPS, pc + loc, NULL); | |
6521 | loc += MIPS_INSN16_SIZE; | |
6522 | switch (micromips_op (insn >> 16)) | |
6523 | { | |
6524 | case 0xc: /* ADDIU: bits 001100 */ | |
6525 | case 0x17: /* DADDIU: bits 010111 */ | |
6526 | sreg = b0s5_reg (insn >> 16); | |
6527 | dreg = b5s5_reg (insn >> 16); | |
6528 | offset = (b0s16_imm (insn) ^ 0x8000) - 0x8000; | |
6529 | if (sreg == MIPS_SP_REGNUM && dreg == MIPS_SP_REGNUM | |
6530 | /* (D)ADDIU $sp, imm */ | |
6531 | && offset >= 0) | |
6532 | break; | |
6533 | return 0; | |
6534 | ||
6535 | default: | |
6536 | return 0; | |
6537 | } | |
6538 | break; | |
6539 | ||
6540 | /* 16-bit instructions. */ | |
6541 | case MIPS_INSN16_SIZE: | |
6542 | switch (micromips_op (insn)) | |
6543 | { | |
6544 | case 0x3: /* MOVE: bits 000011 */ | |
6545 | sreg = b0s5_reg (insn); | |
6546 | dreg = b5s5_reg (insn); | |
6547 | if (sreg == 0 && dreg == 0) | |
6548 | /* MOVE $zero, $zero aka NOP */ | |
6549 | break; | |
6550 | return 0; | |
6551 | ||
6552 | case 0x11: /* POOL16C: bits 010001 */ | |
6553 | if (b5s5_op (insn) == 0x18 | |
6554 | /* JRADDIUSP: bits 010011 11000 */ | |
6555 | || (b5s5_op (insn) == 0xd | |
6556 | /* JRC: bits 010011 01101 */ | |
6557 | && b0s5_reg (insn) == MIPS_RA_REGNUM)) | |
6558 | /* JRC $ra */ | |
6559 | break; | |
6560 | return 0; | |
6561 | ||
6562 | case 0x13: /* POOL16D: bits 010011 */ | |
6563 | offset = micromips_decode_imm9 (b1s9_imm (insn)); | |
6564 | if ((insn & 0x1) == 0x1 | |
6565 | /* ADDIUSP: bits 010011 1 */ | |
6566 | && offset > 0) | |
6567 | break; | |
6568 | return 0; | |
6569 | ||
6570 | default: | |
6571 | return 0; | |
6572 | } | |
6573 | } | |
6574 | } | |
6575 | ||
6576 | return 1; | |
6577 | } | |
6578 | ||
97ab0fdd MR |
6579 | /* Check whether the PC is in a function epilogue (16-bit version). |
6580 | This is a helper function for mips_in_function_epilogue_p. */ | |
6581 | static int | |
e17a4113 | 6582 | mips16_in_function_epilogue_p (struct gdbarch *gdbarch, CORE_ADDR pc) |
97ab0fdd MR |
6583 | { |
6584 | CORE_ADDR func_addr = 0, func_end = 0; | |
6585 | ||
6586 | if (find_pc_partial_function (pc, NULL, &func_addr, &func_end)) | |
6587 | { | |
6588 | /* The MIPS epilogue is max. 12 bytes long. */ | |
6589 | CORE_ADDR addr = func_end - 12; | |
6590 | ||
6591 | if (addr < func_addr + 4) | |
6592 | addr = func_addr + 4; | |
6593 | if (pc < addr) | |
6594 | return 0; | |
6595 | ||
6596 | for (; pc < func_end; pc += MIPS_INSN16_SIZE) | |
6597 | { | |
6598 | unsigned short inst; | |
6599 | ||
4cc0665f | 6600 | inst = mips_fetch_instruction (gdbarch, ISA_MIPS16, pc, NULL); |
97ab0fdd MR |
6601 | |
6602 | if ((inst & 0xf800) == 0xf000) /* extend */ | |
6603 | continue; | |
6604 | ||
6605 | if (inst != 0x6300 /* addiu $sp,offset */ | |
6606 | && inst != 0xfb00 /* daddiu $sp,$sp,offset */ | |
6607 | && inst != 0xe820 /* jr $ra */ | |
6608 | && inst != 0xe8a0 /* jrc $ra */ | |
6609 | && inst != 0x6500) /* nop */ | |
6610 | return 0; | |
6611 | } | |
6612 | ||
6613 | return 1; | |
6614 | } | |
6615 | ||
6616 | return 0; | |
6617 | } | |
6618 | ||
6619 | /* The epilogue is defined here as the area at the end of a function, | |
6620 | after an instruction which destroys the function's stack frame. */ | |
6621 | static int | |
6622 | mips_in_function_epilogue_p (struct gdbarch *gdbarch, CORE_ADDR pc) | |
6623 | { | |
4cc0665f | 6624 | if (mips_pc_is_mips16 (gdbarch, pc)) |
e17a4113 | 6625 | return mips16_in_function_epilogue_p (gdbarch, pc); |
4cc0665f MR |
6626 | else if (mips_pc_is_micromips (gdbarch, pc)) |
6627 | return micromips_in_function_epilogue_p (gdbarch, pc); | |
97ab0fdd | 6628 | else |
e17a4113 | 6629 | return mips32_in_function_epilogue_p (gdbarch, pc); |
97ab0fdd MR |
6630 | } |
6631 | ||
025bb325 | 6632 | /* Root of all "set mips "/"show mips " commands. This will eventually be |
a5ea2558 AC |
6633 | used for all MIPS-specific commands. */ |
6634 | ||
a5ea2558 | 6635 | static void |
acdb74a0 | 6636 | show_mips_command (char *args, int from_tty) |
a5ea2558 AC |
6637 | { |
6638 | help_list (showmipscmdlist, "show mips ", all_commands, gdb_stdout); | |
6639 | } | |
6640 | ||
a5ea2558 | 6641 | static void |
acdb74a0 | 6642 | set_mips_command (char *args, int from_tty) |
a5ea2558 | 6643 | { |
6d82d43b AC |
6644 | printf_unfiltered |
6645 | ("\"set mips\" must be followed by an appropriate subcommand.\n"); | |
a5ea2558 AC |
6646 | help_list (setmipscmdlist, "set mips ", all_commands, gdb_stdout); |
6647 | } | |
6648 | ||
c906108c SS |
6649 | /* Commands to show/set the MIPS FPU type. */ |
6650 | ||
c906108c | 6651 | static void |
acdb74a0 | 6652 | show_mipsfpu_command (char *args, int from_tty) |
c906108c | 6653 | { |
c906108c | 6654 | char *fpu; |
6ca0852e | 6655 | |
f5656ead | 6656 | if (gdbarch_bfd_arch_info (target_gdbarch ())->arch != bfd_arch_mips) |
6ca0852e UW |
6657 | { |
6658 | printf_unfiltered | |
6659 | ("The MIPS floating-point coprocessor is unknown " | |
6660 | "because the current architecture is not MIPS.\n"); | |
6661 | return; | |
6662 | } | |
6663 | ||
f5656ead | 6664 | switch (MIPS_FPU_TYPE (target_gdbarch ())) |
c906108c SS |
6665 | { |
6666 | case MIPS_FPU_SINGLE: | |
6667 | fpu = "single-precision"; | |
6668 | break; | |
6669 | case MIPS_FPU_DOUBLE: | |
6670 | fpu = "double-precision"; | |
6671 | break; | |
6672 | case MIPS_FPU_NONE: | |
6673 | fpu = "absent (none)"; | |
6674 | break; | |
93d56215 | 6675 | default: |
e2e0b3e5 | 6676 | internal_error (__FILE__, __LINE__, _("bad switch")); |
c906108c SS |
6677 | } |
6678 | if (mips_fpu_type_auto) | |
025bb325 MS |
6679 | printf_unfiltered ("The MIPS floating-point coprocessor " |
6680 | "is set automatically (currently %s)\n", | |
6681 | fpu); | |
c906108c | 6682 | else |
6d82d43b AC |
6683 | printf_unfiltered |
6684 | ("The MIPS floating-point coprocessor is assumed to be %s\n", fpu); | |
c906108c SS |
6685 | } |
6686 | ||
6687 | ||
c906108c | 6688 | static void |
acdb74a0 | 6689 | set_mipsfpu_command (char *args, int from_tty) |
c906108c | 6690 | { |
025bb325 MS |
6691 | printf_unfiltered ("\"set mipsfpu\" must be followed by \"double\", " |
6692 | "\"single\",\"none\" or \"auto\".\n"); | |
c906108c SS |
6693 | show_mipsfpu_command (args, from_tty); |
6694 | } | |
6695 | ||
c906108c | 6696 | static void |
acdb74a0 | 6697 | set_mipsfpu_single_command (char *args, int from_tty) |
c906108c | 6698 | { |
8d5838b5 AC |
6699 | struct gdbarch_info info; |
6700 | gdbarch_info_init (&info); | |
c906108c SS |
6701 | mips_fpu_type = MIPS_FPU_SINGLE; |
6702 | mips_fpu_type_auto = 0; | |
8d5838b5 AC |
6703 | /* FIXME: cagney/2003-11-15: Should be setting a field in "info" |
6704 | instead of relying on globals. Doing that would let generic code | |
6705 | handle the search for this specific architecture. */ | |
6706 | if (!gdbarch_update_p (info)) | |
e2e0b3e5 | 6707 | internal_error (__FILE__, __LINE__, _("set mipsfpu failed")); |
c906108c SS |
6708 | } |
6709 | ||
c906108c | 6710 | static void |
acdb74a0 | 6711 | set_mipsfpu_double_command (char *args, int from_tty) |
c906108c | 6712 | { |
8d5838b5 AC |
6713 | struct gdbarch_info info; |
6714 | gdbarch_info_init (&info); | |
c906108c SS |
6715 | mips_fpu_type = MIPS_FPU_DOUBLE; |
6716 | mips_fpu_type_auto = 0; | |
8d5838b5 AC |
6717 | /* FIXME: cagney/2003-11-15: Should be setting a field in "info" |
6718 | instead of relying on globals. Doing that would let generic code | |
6719 | handle the search for this specific architecture. */ | |
6720 | if (!gdbarch_update_p (info)) | |
e2e0b3e5 | 6721 | internal_error (__FILE__, __LINE__, _("set mipsfpu failed")); |
c906108c SS |
6722 | } |
6723 | ||
c906108c | 6724 | static void |
acdb74a0 | 6725 | set_mipsfpu_none_command (char *args, int from_tty) |
c906108c | 6726 | { |
8d5838b5 AC |
6727 | struct gdbarch_info info; |
6728 | gdbarch_info_init (&info); | |
c906108c SS |
6729 | mips_fpu_type = MIPS_FPU_NONE; |
6730 | mips_fpu_type_auto = 0; | |
8d5838b5 AC |
6731 | /* FIXME: cagney/2003-11-15: Should be setting a field in "info" |
6732 | instead of relying on globals. Doing that would let generic code | |
6733 | handle the search for this specific architecture. */ | |
6734 | if (!gdbarch_update_p (info)) | |
e2e0b3e5 | 6735 | internal_error (__FILE__, __LINE__, _("set mipsfpu failed")); |
c906108c SS |
6736 | } |
6737 | ||
c906108c | 6738 | static void |
acdb74a0 | 6739 | set_mipsfpu_auto_command (char *args, int from_tty) |
c906108c SS |
6740 | { |
6741 | mips_fpu_type_auto = 1; | |
6742 | } | |
6743 | ||
c906108c | 6744 | /* Attempt to identify the particular processor model by reading the |
691c0433 AC |
6745 | processor id. NOTE: cagney/2003-11-15: Firstly it isn't clear that |
6746 | the relevant processor still exists (it dates back to '94) and | |
6747 | secondly this is not the way to do this. The processor type should | |
6748 | be set by forcing an architecture change. */ | |
c906108c | 6749 | |
691c0433 AC |
6750 | void |
6751 | deprecated_mips_set_processor_regs_hack (void) | |
c906108c | 6752 | { |
bb486190 UW |
6753 | struct regcache *regcache = get_current_regcache (); |
6754 | struct gdbarch *gdbarch = get_regcache_arch (regcache); | |
6755 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
a9614958 | 6756 | ULONGEST prid; |
c906108c | 6757 | |
bb486190 | 6758 | regcache_cooked_read_unsigned (regcache, MIPS_PRID_REGNUM, &prid); |
c906108c | 6759 | if ((prid & ~0xf) == 0x700) |
691c0433 | 6760 | tdep->mips_processor_reg_names = mips_r3041_reg_names; |
c906108c SS |
6761 | } |
6762 | ||
6763 | /* Just like reinit_frame_cache, but with the right arguments to be | |
6764 | callable as an sfunc. */ | |
6765 | ||
6766 | static void | |
acdb74a0 AC |
6767 | reinit_frame_cache_sfunc (char *args, int from_tty, |
6768 | struct cmd_list_element *c) | |
c906108c SS |
6769 | { |
6770 | reinit_frame_cache (); | |
6771 | } | |
6772 | ||
a89aa300 AC |
6773 | static int |
6774 | gdb_print_insn_mips (bfd_vma memaddr, struct disassemble_info *info) | |
c906108c | 6775 | { |
4cc0665f MR |
6776 | struct gdbarch *gdbarch = info->application_data; |
6777 | ||
d31431ed AC |
6778 | /* FIXME: cagney/2003-06-26: Is this even necessary? The |
6779 | disassembler needs to be able to locally determine the ISA, and | |
6780 | not rely on GDB. Otherwize the stand-alone 'objdump -d' will not | |
6781 | work. */ | |
4cc0665f | 6782 | if (mips_pc_is_mips16 (gdbarch, memaddr)) |
ec4045ea | 6783 | info->mach = bfd_mach_mips16; |
4cc0665f MR |
6784 | else if (mips_pc_is_micromips (gdbarch, memaddr)) |
6785 | info->mach = bfd_mach_mips_micromips; | |
c906108c SS |
6786 | |
6787 | /* Round down the instruction address to the appropriate boundary. */ | |
4cc0665f MR |
6788 | memaddr &= (info->mach == bfd_mach_mips16 |
6789 | || info->mach == bfd_mach_mips_micromips) ? ~1 : ~3; | |
c5aa993b | 6790 | |
e5ab0dce | 6791 | /* Set the disassembler options. */ |
9dae60cc | 6792 | if (!info->disassembler_options) |
e5ab0dce AC |
6793 | /* This string is not recognized explicitly by the disassembler, |
6794 | but it tells the disassembler to not try to guess the ABI from | |
6795 | the bfd elf headers, such that, if the user overrides the ABI | |
6796 | of a program linked as NewABI, the disassembly will follow the | |
6797 | register naming conventions specified by the user. */ | |
6798 | info->disassembler_options = "gpr-names=32"; | |
6799 | ||
c906108c | 6800 | /* Call the appropriate disassembler based on the target endian-ness. */ |
40887e1a | 6801 | if (info->endian == BFD_ENDIAN_BIG) |
c906108c SS |
6802 | return print_insn_big_mips (memaddr, info); |
6803 | else | |
6804 | return print_insn_little_mips (memaddr, info); | |
6805 | } | |
6806 | ||
9dae60cc UW |
6807 | static int |
6808 | gdb_print_insn_mips_n32 (bfd_vma memaddr, struct disassemble_info *info) | |
6809 | { | |
6810 | /* Set up the disassembler info, so that we get the right | |
6811 | register names from libopcodes. */ | |
6812 | info->disassembler_options = "gpr-names=n32"; | |
6813 | info->flavour = bfd_target_elf_flavour; | |
6814 | ||
6815 | return gdb_print_insn_mips (memaddr, info); | |
6816 | } | |
6817 | ||
6818 | static int | |
6819 | gdb_print_insn_mips_n64 (bfd_vma memaddr, struct disassemble_info *info) | |
6820 | { | |
6821 | /* Set up the disassembler info, so that we get the right | |
6822 | register names from libopcodes. */ | |
6823 | info->disassembler_options = "gpr-names=64"; | |
6824 | info->flavour = bfd_target_elf_flavour; | |
6825 | ||
6826 | return gdb_print_insn_mips (memaddr, info); | |
6827 | } | |
6828 | ||
025bb325 MS |
6829 | /* This function implements gdbarch_breakpoint_from_pc. It uses the |
6830 | program counter value to determine whether a 16- or 32-bit breakpoint | |
6831 | should be used. It returns a pointer to a string of bytes that encode a | |
6832 | breakpoint instruction, stores the length of the string to *lenptr, and | |
6833 | adjusts pc (if necessary) to point to the actual memory location where | |
6834 | the breakpoint should be inserted. */ | |
c906108c | 6835 | |
47a35522 | 6836 | static const gdb_byte * |
025bb325 MS |
6837 | mips_breakpoint_from_pc (struct gdbarch *gdbarch, |
6838 | CORE_ADDR *pcptr, int *lenptr) | |
c906108c | 6839 | { |
4cc0665f MR |
6840 | CORE_ADDR pc = *pcptr; |
6841 | ||
67d57894 | 6842 | if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) |
c906108c | 6843 | { |
4cc0665f | 6844 | if (mips_pc_is_mips16 (gdbarch, pc)) |
c906108c | 6845 | { |
47a35522 | 6846 | static gdb_byte mips16_big_breakpoint[] = { 0xe8, 0xa5 }; |
4cc0665f | 6847 | *pcptr = unmake_compact_addr (pc); |
c5aa993b | 6848 | *lenptr = sizeof (mips16_big_breakpoint); |
c906108c SS |
6849 | return mips16_big_breakpoint; |
6850 | } | |
4cc0665f MR |
6851 | else if (mips_pc_is_micromips (gdbarch, pc)) |
6852 | { | |
6853 | static gdb_byte micromips16_big_breakpoint[] = { 0x46, 0x85 }; | |
6854 | static gdb_byte micromips32_big_breakpoint[] = { 0, 0x5, 0, 0x7 }; | |
6855 | ULONGEST insn; | |
6856 | int status; | |
6857 | int size; | |
6858 | ||
6859 | insn = mips_fetch_instruction (gdbarch, ISA_MICROMIPS, pc, &status); | |
6860 | size = status ? 2 | |
6861 | : mips_insn_size (ISA_MICROMIPS, insn) == 2 ? 2 : 4; | |
6862 | *pcptr = unmake_compact_addr (pc); | |
6863 | *lenptr = size; | |
6864 | return (size == 2) ? micromips16_big_breakpoint | |
6865 | : micromips32_big_breakpoint; | |
6866 | } | |
c906108c SS |
6867 | else |
6868 | { | |
aaab4dba AC |
6869 | /* The IDT board uses an unusual breakpoint value, and |
6870 | sometimes gets confused when it sees the usual MIPS | |
6871 | breakpoint instruction. */ | |
47a35522 MK |
6872 | static gdb_byte big_breakpoint[] = { 0, 0x5, 0, 0xd }; |
6873 | static gdb_byte pmon_big_breakpoint[] = { 0, 0, 0, 0xd }; | |
6874 | static gdb_byte idt_big_breakpoint[] = { 0, 0, 0x0a, 0xd }; | |
f2ec0ecf | 6875 | /* Likewise, IRIX appears to expect a different breakpoint, |
025bb325 | 6876 | although this is not apparent until you try to use pthreads. */ |
f2ec0ecf | 6877 | static gdb_byte irix_big_breakpoint[] = { 0, 0, 0, 0xd }; |
c906108c | 6878 | |
c5aa993b | 6879 | *lenptr = sizeof (big_breakpoint); |
c906108c SS |
6880 | |
6881 | if (strcmp (target_shortname, "mips") == 0) | |
6882 | return idt_big_breakpoint; | |
6883 | else if (strcmp (target_shortname, "ddb") == 0 | |
6884 | || strcmp (target_shortname, "pmon") == 0 | |
6885 | || strcmp (target_shortname, "lsi") == 0) | |
6886 | return pmon_big_breakpoint; | |
f2ec0ecf JB |
6887 | else if (gdbarch_osabi (gdbarch) == GDB_OSABI_IRIX) |
6888 | return irix_big_breakpoint; | |
c906108c SS |
6889 | else |
6890 | return big_breakpoint; | |
6891 | } | |
6892 | } | |
6893 | else | |
6894 | { | |
4cc0665f | 6895 | if (mips_pc_is_mips16 (gdbarch, pc)) |
c906108c | 6896 | { |
47a35522 | 6897 | static gdb_byte mips16_little_breakpoint[] = { 0xa5, 0xe8 }; |
4cc0665f | 6898 | *pcptr = unmake_compact_addr (pc); |
c5aa993b | 6899 | *lenptr = sizeof (mips16_little_breakpoint); |
c906108c SS |
6900 | return mips16_little_breakpoint; |
6901 | } | |
4cc0665f MR |
6902 | else if (mips_pc_is_micromips (gdbarch, pc)) |
6903 | { | |
6904 | static gdb_byte micromips16_little_breakpoint[] = { 0x85, 0x46 }; | |
6905 | static gdb_byte micromips32_little_breakpoint[] = { 0x5, 0, 0x7, 0 }; | |
6906 | ULONGEST insn; | |
6907 | int status; | |
6908 | int size; | |
6909 | ||
6910 | insn = mips_fetch_instruction (gdbarch, ISA_MICROMIPS, pc, &status); | |
6911 | size = status ? 2 | |
6912 | : mips_insn_size (ISA_MICROMIPS, insn) == 2 ? 2 : 4; | |
6913 | *pcptr = unmake_compact_addr (pc); | |
6914 | *lenptr = size; | |
6915 | return (size == 2) ? micromips16_little_breakpoint | |
6916 | : micromips32_little_breakpoint; | |
6917 | } | |
c906108c SS |
6918 | else |
6919 | { | |
47a35522 MK |
6920 | static gdb_byte little_breakpoint[] = { 0xd, 0, 0x5, 0 }; |
6921 | static gdb_byte pmon_little_breakpoint[] = { 0xd, 0, 0, 0 }; | |
6922 | static gdb_byte idt_little_breakpoint[] = { 0xd, 0x0a, 0, 0 }; | |
c906108c | 6923 | |
c5aa993b | 6924 | *lenptr = sizeof (little_breakpoint); |
c906108c SS |
6925 | |
6926 | if (strcmp (target_shortname, "mips") == 0) | |
6927 | return idt_little_breakpoint; | |
6928 | else if (strcmp (target_shortname, "ddb") == 0 | |
6929 | || strcmp (target_shortname, "pmon") == 0 | |
6930 | || strcmp (target_shortname, "lsi") == 0) | |
6931 | return pmon_little_breakpoint; | |
6932 | else | |
6933 | return little_breakpoint; | |
6934 | } | |
6935 | } | |
6936 | } | |
6937 | ||
4cc0665f MR |
6938 | /* Determine the remote breakpoint kind suitable for the PC. The following |
6939 | kinds are used: | |
6940 | ||
6941 | * 2 -- 16-bit MIPS16 mode breakpoint, | |
6942 | ||
6943 | * 3 -- 16-bit microMIPS mode breakpoint, | |
6944 | ||
6945 | * 4 -- 32-bit standard MIPS mode breakpoint, | |
6946 | ||
6947 | * 5 -- 32-bit microMIPS mode breakpoint. */ | |
6948 | ||
6949 | static void | |
6950 | mips_remote_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr, | |
6951 | int *kindptr) | |
6952 | { | |
6953 | CORE_ADDR pc = *pcptr; | |
6954 | ||
6955 | if (mips_pc_is_mips16 (gdbarch, pc)) | |
6956 | { | |
6957 | *pcptr = unmake_compact_addr (pc); | |
6958 | *kindptr = 2; | |
6959 | } | |
6960 | else if (mips_pc_is_micromips (gdbarch, pc)) | |
6961 | { | |
6962 | ULONGEST insn; | |
6963 | int status; | |
6964 | int size; | |
6965 | ||
6966 | insn = mips_fetch_instruction (gdbarch, ISA_MICROMIPS, pc, &status); | |
6967 | size = status ? 2 : mips_insn_size (ISA_MICROMIPS, insn) == 2 ? 2 : 4; | |
6968 | *pcptr = unmake_compact_addr (pc); | |
6969 | *kindptr = size | 1; | |
6970 | } | |
6971 | else | |
6972 | *kindptr = 4; | |
6973 | } | |
6974 | ||
c8cef75f MR |
6975 | /* Return non-zero if the ADDR instruction has a branch delay slot |
6976 | (i.e. it is a jump or branch instruction). This function is based | |
6977 | on mips32_next_pc. */ | |
6978 | ||
6979 | static int | |
6980 | mips32_instruction_has_delay_slot (struct gdbarch *gdbarch, CORE_ADDR addr) | |
6981 | { | |
c8cef75f MR |
6982 | unsigned long inst; |
6983 | int status; | |
6984 | int op; | |
a385295e MR |
6985 | int rs; |
6986 | int rt; | |
c8cef75f | 6987 | |
4cc0665f | 6988 | inst = mips_fetch_instruction (gdbarch, ISA_MIPS, addr, &status); |
c8cef75f MR |
6989 | if (status) |
6990 | return 0; | |
6991 | ||
c8cef75f MR |
6992 | op = itype_op (inst); |
6993 | if ((inst & 0xe0000000) != 0) | |
a385295e MR |
6994 | { |
6995 | rs = itype_rs (inst); | |
6996 | rt = itype_rt (inst); | |
f94363d7 AP |
6997 | return (is_octeon_bbit_op (op, gdbarch) |
6998 | || op >> 2 == 5 /* BEQL, BNEL, BLEZL, BGTZL: bits 0101xx */ | |
a385295e MR |
6999 | || op == 29 /* JALX: bits 011101 */ |
7000 | || (op == 17 | |
7001 | && (rs == 8 | |
c8cef75f | 7002 | /* BC1F, BC1FL, BC1T, BC1TL: 010001 01000 */ |
a385295e MR |
7003 | || (rs == 9 && (rt & 0x2) == 0) |
7004 | /* BC1ANY2F, BC1ANY2T: bits 010001 01001 */ | |
7005 | || (rs == 10 && (rt & 0x2) == 0)))); | |
7006 | /* BC1ANY4F, BC1ANY4T: bits 010001 01010 */ | |
7007 | } | |
c8cef75f MR |
7008 | else |
7009 | switch (op & 0x07) /* extract bits 28,27,26 */ | |
7010 | { | |
7011 | case 0: /* SPECIAL */ | |
7012 | op = rtype_funct (inst); | |
7013 | return (op == 8 /* JR */ | |
7014 | || op == 9); /* JALR */ | |
7015 | break; /* end SPECIAL */ | |
7016 | case 1: /* REGIMM */ | |
a385295e MR |
7017 | rs = itype_rs (inst); |
7018 | rt = itype_rt (inst); /* branch condition */ | |
7019 | return ((rt & 0xc) == 0 | |
c8cef75f MR |
7020 | /* BLTZ, BLTZL, BGEZ, BGEZL: bits 000xx */ |
7021 | /* BLTZAL, BLTZALL, BGEZAL, BGEZALL: 100xx */ | |
a385295e MR |
7022 | || ((rt & 0x1e) == 0x1c && rs == 0)); |
7023 | /* BPOSGE32, BPOSGE64: bits 1110x */ | |
c8cef75f MR |
7024 | break; /* end REGIMM */ |
7025 | default: /* J, JAL, BEQ, BNE, BLEZ, BGTZ */ | |
7026 | return 1; | |
7027 | break; | |
7028 | } | |
7029 | } | |
7030 | ||
7031 | /* Return non-zero if the ADDR instruction, which must be a 32-bit | |
7032 | instruction if MUSTBE32 is set or can be any instruction otherwise, | |
7033 | has a branch delay slot (i.e. it is a non-compact jump instruction). */ | |
7034 | ||
4cc0665f MR |
7035 | static int |
7036 | micromips_instruction_has_delay_slot (struct gdbarch *gdbarch, | |
7037 | CORE_ADDR addr, int mustbe32) | |
7038 | { | |
7039 | ULONGEST insn; | |
7040 | int status; | |
7041 | ||
7042 | insn = mips_fetch_instruction (gdbarch, ISA_MICROMIPS, addr, &status); | |
7043 | if (status) | |
7044 | return 0; | |
7045 | ||
7046 | if (!mustbe32) /* 16-bit instructions. */ | |
7047 | return (micromips_op (insn) == 0x11 | |
7048 | /* POOL16C: bits 010001 */ | |
7049 | && (b5s5_op (insn) == 0xc | |
7050 | /* JR16: bits 010001 01100 */ | |
7051 | || (b5s5_op (insn) & 0x1e) == 0xe)) | |
7052 | /* JALR16, JALRS16: bits 010001 0111x */ | |
7053 | || (micromips_op (insn) & 0x37) == 0x23 | |
7054 | /* BEQZ16, BNEZ16: bits 10x011 */ | |
7055 | || micromips_op (insn) == 0x33; | |
7056 | /* B16: bits 110011 */ | |
7057 | ||
7058 | /* 32-bit instructions. */ | |
7059 | if (micromips_op (insn) == 0x0) | |
7060 | /* POOL32A: bits 000000 */ | |
7061 | { | |
7062 | insn <<= 16; | |
7063 | insn |= mips_fetch_instruction (gdbarch, ISA_MICROMIPS, addr, &status); | |
7064 | if (status) | |
7065 | return 0; | |
7066 | return b0s6_op (insn) == 0x3c | |
7067 | /* POOL32Axf: bits 000000 ... 111100 */ | |
7068 | && (b6s10_ext (insn) & 0x2bf) == 0x3c; | |
7069 | /* JALR, JALR.HB: 000000 000x111100 111100 */ | |
7070 | /* JALRS, JALRS.HB: 000000 010x111100 111100 */ | |
7071 | } | |
7072 | ||
7073 | return (micromips_op (insn) == 0x10 | |
7074 | /* POOL32I: bits 010000 */ | |
7075 | && ((b5s5_op (insn) & 0x1c) == 0x0 | |
7076 | /* BLTZ, BLTZAL, BGEZ, BGEZAL: 010000 000xx */ | |
7077 | || (b5s5_op (insn) & 0x1d) == 0x4 | |
7078 | /* BLEZ, BGTZ: bits 010000 001x0 */ | |
7079 | || (b5s5_op (insn) & 0x1d) == 0x11 | |
7080 | /* BLTZALS, BGEZALS: bits 010000 100x1 */ | |
7081 | || ((b5s5_op (insn) & 0x1e) == 0x14 | |
7082 | && (insn & 0x3) == 0x0) | |
7083 | /* BC2F, BC2T: bits 010000 1010x xxx00 */ | |
7084 | || (b5s5_op (insn) & 0x1e) == 0x1a | |
7085 | /* BPOSGE64, BPOSGE32: bits 010000 1101x */ | |
7086 | || ((b5s5_op (insn) & 0x1e) == 0x1c | |
7087 | && (insn & 0x3) == 0x0) | |
7088 | /* BC1F, BC1T: bits 010000 1110x xxx00 */ | |
7089 | || ((b5s5_op (insn) & 0x1c) == 0x1c | |
7090 | && (insn & 0x3) == 0x1))) | |
7091 | /* BC1ANY*: bits 010000 111xx xxx01 */ | |
7092 | || (micromips_op (insn) & 0x1f) == 0x1d | |
7093 | /* JALS, JAL: bits x11101 */ | |
7094 | || (micromips_op (insn) & 0x37) == 0x25 | |
7095 | /* BEQ, BNE: bits 10x101 */ | |
7096 | || micromips_op (insn) == 0x35 | |
7097 | /* J: bits 110101 */ | |
7098 | || micromips_op (insn) == 0x3c; | |
7099 | /* JALX: bits 111100 */ | |
7100 | } | |
7101 | ||
c8cef75f MR |
7102 | static int |
7103 | mips16_instruction_has_delay_slot (struct gdbarch *gdbarch, CORE_ADDR addr, | |
7104 | int mustbe32) | |
7105 | { | |
c8cef75f MR |
7106 | unsigned short inst; |
7107 | int status; | |
7108 | ||
4cc0665f | 7109 | inst = mips_fetch_instruction (gdbarch, ISA_MIPS16, addr, &status); |
c8cef75f MR |
7110 | if (status) |
7111 | return 0; | |
7112 | ||
c8cef75f MR |
7113 | if (!mustbe32) |
7114 | return (inst & 0xf89f) == 0xe800; /* JR/JALR (16-bit instruction) */ | |
7115 | return (inst & 0xf800) == 0x1800; /* JAL/JALX (32-bit instruction) */ | |
7116 | } | |
7117 | ||
7118 | /* Calculate the starting address of the MIPS memory segment BPADDR is in. | |
7119 | This assumes KSSEG exists. */ | |
7120 | ||
7121 | static CORE_ADDR | |
7122 | mips_segment_boundary (CORE_ADDR bpaddr) | |
7123 | { | |
7124 | CORE_ADDR mask = CORE_ADDR_MAX; | |
7125 | int segsize; | |
7126 | ||
7127 | if (sizeof (CORE_ADDR) == 8) | |
7128 | /* Get the topmost two bits of bpaddr in a 32-bit safe manner (avoid | |
7129 | a compiler warning produced where CORE_ADDR is a 32-bit type even | |
7130 | though in that case this is dead code). */ | |
7131 | switch (bpaddr >> ((sizeof (CORE_ADDR) << 3) - 2) & 3) | |
7132 | { | |
7133 | case 3: | |
7134 | if (bpaddr == (bfd_signed_vma) (int32_t) bpaddr) | |
7135 | segsize = 29; /* 32-bit compatibility segment */ | |
7136 | else | |
7137 | segsize = 62; /* xkseg */ | |
7138 | break; | |
7139 | case 2: /* xkphys */ | |
7140 | segsize = 59; | |
7141 | break; | |
7142 | default: /* xksseg (1), xkuseg/kuseg (0) */ | |
7143 | segsize = 62; | |
7144 | break; | |
7145 | } | |
7146 | else if (bpaddr & 0x80000000) /* kernel segment */ | |
7147 | segsize = 29; | |
7148 | else | |
7149 | segsize = 31; /* user segment */ | |
7150 | mask <<= segsize; | |
7151 | return bpaddr & mask; | |
7152 | } | |
7153 | ||
7154 | /* Move the breakpoint at BPADDR out of any branch delay slot by shifting | |
7155 | it backwards if necessary. Return the address of the new location. */ | |
7156 | ||
7157 | static CORE_ADDR | |
7158 | mips_adjust_breakpoint_address (struct gdbarch *gdbarch, CORE_ADDR bpaddr) | |
7159 | { | |
22e048c9 | 7160 | CORE_ADDR prev_addr; |
c8cef75f MR |
7161 | CORE_ADDR boundary; |
7162 | CORE_ADDR func_addr; | |
7163 | ||
7164 | /* If a breakpoint is set on the instruction in a branch delay slot, | |
7165 | GDB gets confused. When the breakpoint is hit, the PC isn't on | |
7166 | the instruction in the branch delay slot, the PC will point to | |
7167 | the branch instruction. Since the PC doesn't match any known | |
7168 | breakpoints, GDB reports a trap exception. | |
7169 | ||
7170 | There are two possible fixes for this problem. | |
7171 | ||
7172 | 1) When the breakpoint gets hit, see if the BD bit is set in the | |
7173 | Cause register (which indicates the last exception occurred in a | |
7174 | branch delay slot). If the BD bit is set, fix the PC to point to | |
7175 | the instruction in the branch delay slot. | |
7176 | ||
7177 | 2) When the user sets the breakpoint, don't allow him to set the | |
7178 | breakpoint on the instruction in the branch delay slot. Instead | |
7179 | move the breakpoint to the branch instruction (which will have | |
7180 | the same result). | |
7181 | ||
7182 | The problem with the first solution is that if the user then | |
7183 | single-steps the processor, the branch instruction will get | |
7184 | skipped (since GDB thinks the PC is on the instruction in the | |
7185 | branch delay slot). | |
7186 | ||
7187 | So, we'll use the second solution. To do this we need to know if | |
7188 | the instruction we're trying to set the breakpoint on is in the | |
7189 | branch delay slot. */ | |
7190 | ||
7191 | boundary = mips_segment_boundary (bpaddr); | |
7192 | ||
7193 | /* Make sure we don't scan back before the beginning of the current | |
7194 | function, since we may fetch constant data or insns that look like | |
7195 | a jump. Of course we might do that anyway if the compiler has | |
7196 | moved constants inline. :-( */ | |
7197 | if (find_pc_partial_function (bpaddr, NULL, &func_addr, NULL) | |
7198 | && func_addr > boundary && func_addr <= bpaddr) | |
7199 | boundary = func_addr; | |
7200 | ||
4cc0665f | 7201 | if (mips_pc_is_mips (bpaddr)) |
c8cef75f MR |
7202 | { |
7203 | if (bpaddr == boundary) | |
7204 | return bpaddr; | |
7205 | ||
7206 | /* If the previous instruction has a branch delay slot, we have | |
7207 | to move the breakpoint to the branch instruction. */ | |
7208 | prev_addr = bpaddr - 4; | |
7209 | if (mips32_instruction_has_delay_slot (gdbarch, prev_addr)) | |
7210 | bpaddr = prev_addr; | |
7211 | } | |
7212 | else | |
7213 | { | |
4cc0665f | 7214 | int (*instruction_has_delay_slot) (struct gdbarch *, CORE_ADDR, int); |
c8cef75f MR |
7215 | CORE_ADDR addr, jmpaddr; |
7216 | int i; | |
7217 | ||
4cc0665f | 7218 | boundary = unmake_compact_addr (boundary); |
c8cef75f MR |
7219 | |
7220 | /* The only MIPS16 instructions with delay slots are JAL, JALX, | |
7221 | JALR and JR. An absolute JAL/JALX is always 4 bytes long, | |
7222 | so try for that first, then try the 2 byte JALR/JR. | |
4cc0665f MR |
7223 | The microMIPS ASE has a whole range of jumps and branches |
7224 | with delay slots, some of which take 4 bytes and some take | |
7225 | 2 bytes, so the idea is the same. | |
c8cef75f MR |
7226 | FIXME: We have to assume that bpaddr is not the second half |
7227 | of an extended instruction. */ | |
4cc0665f MR |
7228 | instruction_has_delay_slot = (mips_pc_is_micromips (gdbarch, bpaddr) |
7229 | ? micromips_instruction_has_delay_slot | |
7230 | : mips16_instruction_has_delay_slot); | |
c8cef75f MR |
7231 | |
7232 | jmpaddr = 0; | |
7233 | addr = bpaddr; | |
7234 | for (i = 1; i < 4; i++) | |
7235 | { | |
4cc0665f | 7236 | if (unmake_compact_addr (addr) == boundary) |
c8cef75f | 7237 | break; |
4cc0665f MR |
7238 | addr -= MIPS_INSN16_SIZE; |
7239 | if (i == 1 && instruction_has_delay_slot (gdbarch, addr, 0)) | |
c8cef75f MR |
7240 | /* Looks like a JR/JALR at [target-1], but it could be |
7241 | the second word of a previous JAL/JALX, so record it | |
7242 | and check back one more. */ | |
7243 | jmpaddr = addr; | |
4cc0665f | 7244 | else if (i > 1 && instruction_has_delay_slot (gdbarch, addr, 1)) |
c8cef75f MR |
7245 | { |
7246 | if (i == 2) | |
7247 | /* Looks like a JAL/JALX at [target-2], but it could also | |
7248 | be the second word of a previous JAL/JALX, record it, | |
7249 | and check back one more. */ | |
7250 | jmpaddr = addr; | |
7251 | else | |
7252 | /* Looks like a JAL/JALX at [target-3], so any previously | |
7253 | recorded JAL/JALX or JR/JALR must be wrong, because: | |
7254 | ||
7255 | >-3: JAL | |
7256 | -2: JAL-ext (can't be JAL/JALX) | |
7257 | -1: bdslot (can't be JR/JALR) | |
7258 | 0: target insn | |
7259 | ||
7260 | Of course it could be another JAL-ext which looks | |
7261 | like a JAL, but in that case we'd have broken out | |
7262 | of this loop at [target-2]: | |
7263 | ||
7264 | -4: JAL | |
7265 | >-3: JAL-ext | |
7266 | -2: bdslot (can't be jmp) | |
7267 | -1: JR/JALR | |
7268 | 0: target insn */ | |
7269 | jmpaddr = 0; | |
7270 | } | |
7271 | else | |
7272 | { | |
7273 | /* Not a jump instruction: if we're at [target-1] this | |
7274 | could be the second word of a JAL/JALX, so continue; | |
7275 | otherwise we're done. */ | |
7276 | if (i > 1) | |
7277 | break; | |
7278 | } | |
7279 | } | |
7280 | ||
7281 | if (jmpaddr) | |
7282 | bpaddr = jmpaddr; | |
7283 | } | |
7284 | ||
7285 | return bpaddr; | |
7286 | } | |
7287 | ||
14132e89 MR |
7288 | /* Return non-zero if SUFFIX is one of the numeric suffixes used for MIPS16 |
7289 | call stubs, one of 1, 2, 5, 6, 9, 10, or, if ZERO is non-zero, also 0. */ | |
7290 | ||
7291 | static int | |
7292 | mips_is_stub_suffix (const char *suffix, int zero) | |
7293 | { | |
7294 | switch (suffix[0]) | |
7295 | { | |
7296 | case '0': | |
7297 | return zero && suffix[1] == '\0'; | |
7298 | case '1': | |
7299 | return suffix[1] == '\0' || (suffix[1] == '0' && suffix[2] == '\0'); | |
7300 | case '2': | |
7301 | case '5': | |
7302 | case '6': | |
7303 | case '9': | |
7304 | return suffix[1] == '\0'; | |
7305 | default: | |
7306 | return 0; | |
7307 | } | |
7308 | } | |
7309 | ||
7310 | /* Return non-zero if MODE is one of the mode infixes used for MIPS16 | |
7311 | call stubs, one of sf, df, sc, or dc. */ | |
7312 | ||
7313 | static int | |
7314 | mips_is_stub_mode (const char *mode) | |
7315 | { | |
7316 | return ((mode[0] == 's' || mode[0] == 'd') | |
7317 | && (mode[1] == 'f' || mode[1] == 'c')); | |
7318 | } | |
7319 | ||
7320 | /* Code at PC is a compiler-generated stub. Such a stub for a function | |
7321 | bar might have a name like __fn_stub_bar, and might look like this: | |
7322 | ||
7323 | mfc1 $4, $f13 | |
7324 | mfc1 $5, $f12 | |
7325 | mfc1 $6, $f15 | |
7326 | mfc1 $7, $f14 | |
7327 | ||
7328 | followed by (or interspersed with): | |
7329 | ||
7330 | j bar | |
7331 | ||
7332 | or: | |
7333 | ||
7334 | lui $25, %hi(bar) | |
7335 | addiu $25, $25, %lo(bar) | |
7336 | jr $25 | |
7337 | ||
7338 | ($1 may be used in old code; for robustness we accept any register) | |
7339 | or, in PIC code: | |
7340 | ||
7341 | lui $28, %hi(_gp_disp) | |
7342 | addiu $28, $28, %lo(_gp_disp) | |
7343 | addu $28, $28, $25 | |
7344 | lw $25, %got(bar) | |
7345 | addiu $25, $25, %lo(bar) | |
7346 | jr $25 | |
7347 | ||
7348 | In the case of a __call_stub_bar stub, the sequence to set up | |
7349 | arguments might look like this: | |
7350 | ||
7351 | mtc1 $4, $f13 | |
7352 | mtc1 $5, $f12 | |
7353 | mtc1 $6, $f15 | |
7354 | mtc1 $7, $f14 | |
7355 | ||
7356 | followed by (or interspersed with) one of the jump sequences above. | |
7357 | ||
7358 | In the case of a __call_stub_fp_bar stub, JAL or JALR is used instead | |
7359 | of J or JR, respectively, followed by: | |
7360 | ||
7361 | mfc1 $2, $f0 | |
7362 | mfc1 $3, $f1 | |
7363 | jr $18 | |
7364 | ||
7365 | We are at the beginning of the stub here, and scan down and extract | |
7366 | the target address from the jump immediate instruction or, if a jump | |
7367 | register instruction is used, from the register referred. Return | |
7368 | the value of PC calculated or 0 if inconclusive. | |
7369 | ||
7370 | The limit on the search is arbitrarily set to 20 instructions. FIXME. */ | |
7371 | ||
7372 | static CORE_ADDR | |
7373 | mips_get_mips16_fn_stub_pc (struct frame_info *frame, CORE_ADDR pc) | |
7374 | { | |
7375 | struct gdbarch *gdbarch = get_frame_arch (frame); | |
7376 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); | |
7377 | int addrreg = MIPS_ZERO_REGNUM; | |
7378 | CORE_ADDR start_pc = pc; | |
7379 | CORE_ADDR target_pc = 0; | |
7380 | CORE_ADDR addr = 0; | |
7381 | CORE_ADDR gp = 0; | |
7382 | int status = 0; | |
7383 | int i; | |
7384 | ||
7385 | for (i = 0; | |
7386 | status == 0 && target_pc == 0 && i < 20; | |
7387 | i++, pc += MIPS_INSN32_SIZE) | |
7388 | { | |
4cc0665f | 7389 | ULONGEST inst = mips_fetch_instruction (gdbarch, ISA_MIPS, pc, NULL); |
14132e89 MR |
7390 | CORE_ADDR imm; |
7391 | int rt; | |
7392 | int rs; | |
7393 | int rd; | |
7394 | ||
7395 | switch (itype_op (inst)) | |
7396 | { | |
7397 | case 0: /* SPECIAL */ | |
7398 | switch (rtype_funct (inst)) | |
7399 | { | |
7400 | case 8: /* JR */ | |
7401 | case 9: /* JALR */ | |
7402 | rs = rtype_rs (inst); | |
7403 | if (rs == MIPS_GP_REGNUM) | |
7404 | target_pc = gp; /* Hmm... */ | |
7405 | else if (rs == addrreg) | |
7406 | target_pc = addr; | |
7407 | break; | |
7408 | ||
7409 | case 0x21: /* ADDU */ | |
7410 | rt = rtype_rt (inst); | |
7411 | rs = rtype_rs (inst); | |
7412 | rd = rtype_rd (inst); | |
7413 | if (rd == MIPS_GP_REGNUM | |
7414 | && ((rs == MIPS_GP_REGNUM && rt == MIPS_T9_REGNUM) | |
7415 | || (rs == MIPS_T9_REGNUM && rt == MIPS_GP_REGNUM))) | |
7416 | gp += start_pc; | |
7417 | break; | |
7418 | } | |
7419 | break; | |
7420 | ||
7421 | case 2: /* J */ | |
7422 | case 3: /* JAL */ | |
7423 | target_pc = jtype_target (inst) << 2; | |
7424 | target_pc += ((pc + 4) & ~(CORE_ADDR) 0x0fffffff); | |
7425 | break; | |
7426 | ||
7427 | case 9: /* ADDIU */ | |
7428 | rt = itype_rt (inst); | |
7429 | rs = itype_rs (inst); | |
7430 | if (rt == rs) | |
7431 | { | |
7432 | imm = (itype_immediate (inst) ^ 0x8000) - 0x8000; | |
7433 | if (rt == MIPS_GP_REGNUM) | |
7434 | gp += imm; | |
7435 | else if (rt == addrreg) | |
7436 | addr += imm; | |
7437 | } | |
7438 | break; | |
7439 | ||
7440 | case 0xf: /* LUI */ | |
7441 | rt = itype_rt (inst); | |
7442 | imm = ((itype_immediate (inst) ^ 0x8000) - 0x8000) << 16; | |
7443 | if (rt == MIPS_GP_REGNUM) | |
7444 | gp = imm; | |
7445 | else if (rt != MIPS_ZERO_REGNUM) | |
7446 | { | |
7447 | addrreg = rt; | |
7448 | addr = imm; | |
7449 | } | |
7450 | break; | |
7451 | ||
7452 | case 0x23: /* LW */ | |
7453 | rt = itype_rt (inst); | |
7454 | rs = itype_rs (inst); | |
7455 | imm = (itype_immediate (inst) ^ 0x8000) - 0x8000; | |
7456 | if (gp != 0 && rs == MIPS_GP_REGNUM) | |
7457 | { | |
7458 | gdb_byte buf[4]; | |
7459 | ||
7460 | memset (buf, 0, sizeof (buf)); | |
7461 | status = target_read_memory (gp + imm, buf, sizeof (buf)); | |
7462 | addrreg = rt; | |
7463 | addr = extract_signed_integer (buf, sizeof (buf), byte_order); | |
7464 | } | |
7465 | break; | |
7466 | } | |
7467 | } | |
7468 | ||
7469 | return target_pc; | |
7470 | } | |
7471 | ||
7472 | /* If PC is in a MIPS16 call or return stub, return the address of the | |
7473 | target PC, which is either the callee or the caller. There are several | |
c906108c SS |
7474 | cases which must be handled: |
7475 | ||
14132e89 MR |
7476 | * If the PC is in __mips16_ret_{d,s}{f,c}, this is a return stub |
7477 | and the target PC is in $31 ($ra). | |
c906108c | 7478 | * If the PC is in __mips16_call_stub_{1..10}, this is a call stub |
14132e89 MR |
7479 | and the target PC is in $2. |
7480 | * If the PC at the start of __mips16_call_stub_{s,d}{f,c}_{0..10}, | |
7481 | i.e. before the JALR instruction, this is effectively a call stub | |
7482 | and the target PC is in $2. Otherwise this is effectively | |
7483 | a return stub and the target PC is in $18. | |
7484 | * If the PC is at the start of __call_stub_fp_*, i.e. before the | |
7485 | JAL or JALR instruction, this is effectively a call stub and the | |
7486 | target PC is buried in the instruction stream. Otherwise this | |
7487 | is effectively a return stub and the target PC is in $18. | |
7488 | * If the PC is in __call_stub_* or in __fn_stub_*, this is a call | |
7489 | stub and the target PC is buried in the instruction stream. | |
7490 | ||
7491 | See the source code for the stubs in gcc/config/mips/mips16.S, or the | |
7492 | stub builder in gcc/config/mips/mips.c (mips16_build_call_stub) for the | |
e7d6a6d2 | 7493 | gory details. */ |
c906108c | 7494 | |
757a7cc6 | 7495 | static CORE_ADDR |
db5f024e | 7496 | mips_skip_mips16_trampoline_code (struct frame_info *frame, CORE_ADDR pc) |
c906108c | 7497 | { |
e17a4113 | 7498 | struct gdbarch *gdbarch = get_frame_arch (frame); |
c906108c | 7499 | CORE_ADDR start_addr; |
14132e89 MR |
7500 | const char *name; |
7501 | size_t prefixlen; | |
c906108c SS |
7502 | |
7503 | /* Find the starting address and name of the function containing the PC. */ | |
7504 | if (find_pc_partial_function (pc, &name, &start_addr, NULL) == 0) | |
7505 | return 0; | |
7506 | ||
14132e89 MR |
7507 | /* If the PC is in __mips16_ret_{d,s}{f,c}, this is a return stub |
7508 | and the target PC is in $31 ($ra). */ | |
7509 | prefixlen = strlen (mips_str_mips16_ret_stub); | |
7510 | if (strncmp (name, mips_str_mips16_ret_stub, prefixlen) == 0 | |
7511 | && mips_is_stub_mode (name + prefixlen) | |
7512 | && name[prefixlen + 2] == '\0') | |
7513 | return get_frame_register_signed | |
7514 | (frame, gdbarch_num_regs (gdbarch) + MIPS_RA_REGNUM); | |
7515 | ||
7516 | /* If the PC is in __mips16_call_stub_*, this is one of the call | |
7517 | call/return stubs. */ | |
7518 | prefixlen = strlen (mips_str_mips16_call_stub); | |
7519 | if (strncmp (name, mips_str_mips16_call_stub, prefixlen) == 0) | |
c906108c SS |
7520 | { |
7521 | /* If the PC is in __mips16_call_stub_{1..10}, this is a call stub | |
7522 | and the target PC is in $2. */ | |
14132e89 MR |
7523 | if (mips_is_stub_suffix (name + prefixlen, 0)) |
7524 | return get_frame_register_signed | |
7525 | (frame, gdbarch_num_regs (gdbarch) + MIPS_V0_REGNUM); | |
c906108c | 7526 | |
14132e89 MR |
7527 | /* If the PC at the start of __mips16_call_stub_{s,d}{f,c}_{0..10}, |
7528 | i.e. before the JALR instruction, this is effectively a call stub | |
b021a221 | 7529 | and the target PC is in $2. Otherwise this is effectively |
c5aa993b | 7530 | a return stub and the target PC is in $18. */ |
14132e89 MR |
7531 | else if (mips_is_stub_mode (name + prefixlen) |
7532 | && name[prefixlen + 2] == '_' | |
7533 | && mips_is_stub_suffix (name + prefixlen + 3, 0)) | |
c906108c SS |
7534 | { |
7535 | if (pc == start_addr) | |
14132e89 MR |
7536 | /* This is the 'call' part of a call stub. The return |
7537 | address is in $2. */ | |
7538 | return get_frame_register_signed | |
7539 | (frame, gdbarch_num_regs (gdbarch) + MIPS_V0_REGNUM); | |
c906108c SS |
7540 | else |
7541 | /* This is the 'return' part of a call stub. The return | |
14132e89 MR |
7542 | address is in $18. */ |
7543 | return get_frame_register_signed | |
7544 | (frame, gdbarch_num_regs (gdbarch) + MIPS_S2_REGNUM); | |
c906108c | 7545 | } |
14132e89 MR |
7546 | else |
7547 | return 0; /* Not a stub. */ | |
7548 | } | |
7549 | ||
7550 | /* If the PC is in __call_stub_* or __fn_stub*, this is one of the | |
7551 | compiler-generated call or call/return stubs. */ | |
7552 | if (strncmp (name, mips_str_fn_stub, strlen (mips_str_fn_stub)) == 0 | |
7553 | || strncmp (name, mips_str_call_stub, strlen (mips_str_call_stub)) == 0) | |
7554 | { | |
7555 | if (pc == start_addr) | |
7556 | /* This is the 'call' part of a call stub. Call this helper | |
7557 | to scan through this code for interesting instructions | |
7558 | and determine the final PC. */ | |
7559 | return mips_get_mips16_fn_stub_pc (frame, pc); | |
7560 | else | |
7561 | /* This is the 'return' part of a call stub. The return address | |
7562 | is in $18. */ | |
7563 | return get_frame_register_signed | |
7564 | (frame, gdbarch_num_regs (gdbarch) + MIPS_S2_REGNUM); | |
c906108c | 7565 | } |
14132e89 MR |
7566 | |
7567 | return 0; /* Not a stub. */ | |
7568 | } | |
7569 | ||
7570 | /* Return non-zero if the PC is inside a return thunk (aka stub or trampoline). | |
7571 | This implements the IN_SOLIB_RETURN_TRAMPOLINE macro. */ | |
7572 | ||
7573 | static int | |
7574 | mips_in_return_stub (struct gdbarch *gdbarch, CORE_ADDR pc, const char *name) | |
7575 | { | |
7576 | CORE_ADDR start_addr; | |
7577 | size_t prefixlen; | |
7578 | ||
7579 | /* Find the starting address of the function containing the PC. */ | |
7580 | if (find_pc_partial_function (pc, NULL, &start_addr, NULL) == 0) | |
7581 | return 0; | |
7582 | ||
7583 | /* If the PC is in __mips16_call_stub_{s,d}{f,c}_{0..10} but not at | |
7584 | the start, i.e. after the JALR instruction, this is effectively | |
7585 | a return stub. */ | |
7586 | prefixlen = strlen (mips_str_mips16_call_stub); | |
7587 | if (pc != start_addr | |
7588 | && strncmp (name, mips_str_mips16_call_stub, prefixlen) == 0 | |
7589 | && mips_is_stub_mode (name + prefixlen) | |
7590 | && name[prefixlen + 2] == '_' | |
7591 | && mips_is_stub_suffix (name + prefixlen + 3, 1)) | |
7592 | return 1; | |
7593 | ||
7594 | /* If the PC is in __call_stub_fp_* but not at the start, i.e. after | |
7595 | the JAL or JALR instruction, this is effectively a return stub. */ | |
7596 | prefixlen = strlen (mips_str_call_fp_stub); | |
7597 | if (pc != start_addr | |
7598 | && strncmp (name, mips_str_call_fp_stub, prefixlen) == 0) | |
7599 | return 1; | |
7600 | ||
7601 | /* Consume the .pic. prefix of any PIC stub, this function must return | |
7602 | true when the PC is in a PIC stub of a __mips16_ret_{d,s}{f,c} stub | |
7603 | or the call stub path will trigger in handle_inferior_event causing | |
7604 | it to go astray. */ | |
7605 | prefixlen = strlen (mips_str_pic); | |
7606 | if (strncmp (name, mips_str_pic, prefixlen) == 0) | |
7607 | name += prefixlen; | |
7608 | ||
7609 | /* If the PC is in __mips16_ret_{d,s}{f,c}, this is a return stub. */ | |
7610 | prefixlen = strlen (mips_str_mips16_ret_stub); | |
7611 | if (strncmp (name, mips_str_mips16_ret_stub, prefixlen) == 0 | |
7612 | && mips_is_stub_mode (name + prefixlen) | |
7613 | && name[prefixlen + 2] == '\0') | |
7614 | return 1; | |
7615 | ||
7616 | return 0; /* Not a stub. */ | |
c906108c SS |
7617 | } |
7618 | ||
db5f024e DJ |
7619 | /* If the current PC is the start of a non-PIC-to-PIC stub, return the |
7620 | PC of the stub target. The stub just loads $t9 and jumps to it, | |
7621 | so that $t9 has the correct value at function entry. */ | |
7622 | ||
7623 | static CORE_ADDR | |
7624 | mips_skip_pic_trampoline_code (struct frame_info *frame, CORE_ADDR pc) | |
7625 | { | |
e17a4113 UW |
7626 | struct gdbarch *gdbarch = get_frame_arch (frame); |
7627 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); | |
7cbd4a93 | 7628 | struct bound_minimal_symbol msym; |
db5f024e DJ |
7629 | int i; |
7630 | gdb_byte stub_code[16]; | |
7631 | int32_t stub_words[4]; | |
7632 | ||
7633 | /* The stub for foo is named ".pic.foo", and is either two | |
7634 | instructions inserted before foo or a three instruction sequence | |
7635 | which jumps to foo. */ | |
7636 | msym = lookup_minimal_symbol_by_pc (pc); | |
7cbd4a93 TT |
7637 | if (msym.minsym == NULL |
7638 | || SYMBOL_VALUE_ADDRESS (msym.minsym) != pc | |
7639 | || SYMBOL_LINKAGE_NAME (msym.minsym) == NULL | |
7640 | || strncmp (SYMBOL_LINKAGE_NAME (msym.minsym), ".pic.", 5) != 0) | |
db5f024e DJ |
7641 | return 0; |
7642 | ||
7643 | /* A two-instruction header. */ | |
7cbd4a93 | 7644 | if (MSYMBOL_SIZE (msym.minsym) == 8) |
db5f024e DJ |
7645 | return pc + 8; |
7646 | ||
7647 | /* A three-instruction (plus delay slot) trampoline. */ | |
7cbd4a93 | 7648 | if (MSYMBOL_SIZE (msym.minsym) == 16) |
db5f024e DJ |
7649 | { |
7650 | if (target_read_memory (pc, stub_code, 16) != 0) | |
7651 | return 0; | |
7652 | for (i = 0; i < 4; i++) | |
e17a4113 UW |
7653 | stub_words[i] = extract_unsigned_integer (stub_code + i * 4, |
7654 | 4, byte_order); | |
db5f024e DJ |
7655 | |
7656 | /* A stub contains these instructions: | |
7657 | lui t9, %hi(target) | |
7658 | j target | |
7659 | addiu t9, t9, %lo(target) | |
7660 | nop | |
7661 | ||
7662 | This works even for N64, since stubs are only generated with | |
7663 | -msym32. */ | |
7664 | if ((stub_words[0] & 0xffff0000U) == 0x3c190000 | |
7665 | && (stub_words[1] & 0xfc000000U) == 0x08000000 | |
7666 | && (stub_words[2] & 0xffff0000U) == 0x27390000 | |
7667 | && stub_words[3] == 0x00000000) | |
34b192ce MR |
7668 | return ((((stub_words[0] & 0x0000ffff) << 16) |
7669 | + (stub_words[2] & 0x0000ffff)) ^ 0x8000) - 0x8000; | |
db5f024e DJ |
7670 | } |
7671 | ||
7672 | /* Not a recognized stub. */ | |
7673 | return 0; | |
7674 | } | |
7675 | ||
7676 | static CORE_ADDR | |
7677 | mips_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc) | |
7678 | { | |
14132e89 | 7679 | CORE_ADDR requested_pc = pc; |
db5f024e | 7680 | CORE_ADDR target_pc; |
14132e89 MR |
7681 | CORE_ADDR new_pc; |
7682 | ||
7683 | do | |
7684 | { | |
7685 | target_pc = pc; | |
db5f024e | 7686 | |
14132e89 MR |
7687 | new_pc = mips_skip_mips16_trampoline_code (frame, pc); |
7688 | if (new_pc) | |
7689 | { | |
7690 | pc = new_pc; | |
4cc0665f MR |
7691 | if (is_compact_addr (pc)) |
7692 | pc = unmake_compact_addr (pc); | |
14132e89 | 7693 | } |
db5f024e | 7694 | |
14132e89 MR |
7695 | new_pc = find_solib_trampoline_target (frame, pc); |
7696 | if (new_pc) | |
7697 | { | |
7698 | pc = new_pc; | |
4cc0665f MR |
7699 | if (is_compact_addr (pc)) |
7700 | pc = unmake_compact_addr (pc); | |
14132e89 | 7701 | } |
db5f024e | 7702 | |
14132e89 MR |
7703 | new_pc = mips_skip_pic_trampoline_code (frame, pc); |
7704 | if (new_pc) | |
7705 | { | |
7706 | pc = new_pc; | |
4cc0665f MR |
7707 | if (is_compact_addr (pc)) |
7708 | pc = unmake_compact_addr (pc); | |
14132e89 MR |
7709 | } |
7710 | } | |
7711 | while (pc != target_pc); | |
db5f024e | 7712 | |
14132e89 | 7713 | return pc != requested_pc ? pc : 0; |
db5f024e DJ |
7714 | } |
7715 | ||
a4b8ebc8 | 7716 | /* Convert a dbx stab register number (from `r' declaration) to a GDB |
f57d151a | 7717 | [1 * gdbarch_num_regs .. 2 * gdbarch_num_regs) REGNUM. */ |
88c72b7d AC |
7718 | |
7719 | static int | |
d3f73121 | 7720 | mips_stab_reg_to_regnum (struct gdbarch *gdbarch, int num) |
88c72b7d | 7721 | { |
a4b8ebc8 | 7722 | int regnum; |
2f38ef89 | 7723 | if (num >= 0 && num < 32) |
a4b8ebc8 | 7724 | regnum = num; |
2f38ef89 | 7725 | else if (num >= 38 && num < 70) |
d3f73121 | 7726 | regnum = num + mips_regnum (gdbarch)->fp0 - 38; |
040b99fd | 7727 | else if (num == 70) |
d3f73121 | 7728 | regnum = mips_regnum (gdbarch)->hi; |
040b99fd | 7729 | else if (num == 71) |
d3f73121 | 7730 | regnum = mips_regnum (gdbarch)->lo; |
1faeff08 MR |
7731 | else if (mips_regnum (gdbarch)->dspacc != -1 && num >= 72 && num < 78) |
7732 | regnum = num + mips_regnum (gdbarch)->dspacc - 72; | |
2f38ef89 | 7733 | else |
a4b8ebc8 AC |
7734 | /* This will hopefully (eventually) provoke a warning. Should |
7735 | we be calling complaint() here? */ | |
d3f73121 MD |
7736 | return gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch); |
7737 | return gdbarch_num_regs (gdbarch) + regnum; | |
88c72b7d AC |
7738 | } |
7739 | ||
2f38ef89 | 7740 | |
a4b8ebc8 | 7741 | /* Convert a dwarf, dwarf2, or ecoff register number to a GDB [1 * |
f57d151a | 7742 | gdbarch_num_regs .. 2 * gdbarch_num_regs) REGNUM. */ |
88c72b7d AC |
7743 | |
7744 | static int | |
d3f73121 | 7745 | mips_dwarf_dwarf2_ecoff_reg_to_regnum (struct gdbarch *gdbarch, int num) |
88c72b7d | 7746 | { |
a4b8ebc8 | 7747 | int regnum; |
2f38ef89 | 7748 | if (num >= 0 && num < 32) |
a4b8ebc8 | 7749 | regnum = num; |
2f38ef89 | 7750 | else if (num >= 32 && num < 64) |
d3f73121 | 7751 | regnum = num + mips_regnum (gdbarch)->fp0 - 32; |
040b99fd | 7752 | else if (num == 64) |
d3f73121 | 7753 | regnum = mips_regnum (gdbarch)->hi; |
040b99fd | 7754 | else if (num == 65) |
d3f73121 | 7755 | regnum = mips_regnum (gdbarch)->lo; |
1faeff08 MR |
7756 | else if (mips_regnum (gdbarch)->dspacc != -1 && num >= 66 && num < 72) |
7757 | regnum = num + mips_regnum (gdbarch)->dspacc - 66; | |
2f38ef89 | 7758 | else |
a4b8ebc8 AC |
7759 | /* This will hopefully (eventually) provoke a warning. Should we |
7760 | be calling complaint() here? */ | |
d3f73121 MD |
7761 | return gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch); |
7762 | return gdbarch_num_regs (gdbarch) + regnum; | |
a4b8ebc8 AC |
7763 | } |
7764 | ||
7765 | static int | |
e7faf938 | 7766 | mips_register_sim_regno (struct gdbarch *gdbarch, int regnum) |
a4b8ebc8 AC |
7767 | { |
7768 | /* Only makes sense to supply raw registers. */ | |
e7faf938 | 7769 | gdb_assert (regnum >= 0 && regnum < gdbarch_num_regs (gdbarch)); |
a4b8ebc8 AC |
7770 | /* FIXME: cagney/2002-05-13: Need to look at the pseudo register to |
7771 | decide if it is valid. Should instead define a standard sim/gdb | |
7772 | register numbering scheme. */ | |
e7faf938 MD |
7773 | if (gdbarch_register_name (gdbarch, |
7774 | gdbarch_num_regs (gdbarch) + regnum) != NULL | |
7775 | && gdbarch_register_name (gdbarch, | |
025bb325 MS |
7776 | gdbarch_num_regs (gdbarch) |
7777 | + regnum)[0] != '\0') | |
a4b8ebc8 AC |
7778 | return regnum; |
7779 | else | |
6d82d43b | 7780 | return LEGACY_SIM_REGNO_IGNORE; |
88c72b7d AC |
7781 | } |
7782 | ||
2f38ef89 | 7783 | |
4844f454 CV |
7784 | /* Convert an integer into an address. Extracting the value signed |
7785 | guarantees a correctly sign extended address. */ | |
fc0c74b1 AC |
7786 | |
7787 | static CORE_ADDR | |
79dd2d24 | 7788 | mips_integer_to_address (struct gdbarch *gdbarch, |
870cd05e | 7789 | struct type *type, const gdb_byte *buf) |
fc0c74b1 | 7790 | { |
e17a4113 UW |
7791 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
7792 | return extract_signed_integer (buf, TYPE_LENGTH (type), byte_order); | |
fc0c74b1 AC |
7793 | } |
7794 | ||
82e91389 DJ |
7795 | /* Dummy virtual frame pointer method. This is no more or less accurate |
7796 | than most other architectures; we just need to be explicit about it, | |
7797 | because the pseudo-register gdbarch_sp_regnum will otherwise lead to | |
7798 | an assertion failure. */ | |
7799 | ||
7800 | static void | |
a54fba4c MD |
7801 | mips_virtual_frame_pointer (struct gdbarch *gdbarch, |
7802 | CORE_ADDR pc, int *reg, LONGEST *offset) | |
82e91389 DJ |
7803 | { |
7804 | *reg = MIPS_SP_REGNUM; | |
7805 | *offset = 0; | |
7806 | } | |
7807 | ||
caaa3122 DJ |
7808 | static void |
7809 | mips_find_abi_section (bfd *abfd, asection *sect, void *obj) | |
7810 | { | |
7811 | enum mips_abi *abip = (enum mips_abi *) obj; | |
7812 | const char *name = bfd_get_section_name (abfd, sect); | |
7813 | ||
7814 | if (*abip != MIPS_ABI_UNKNOWN) | |
7815 | return; | |
7816 | ||
7817 | if (strncmp (name, ".mdebug.", 8) != 0) | |
7818 | return; | |
7819 | ||
7820 | if (strcmp (name, ".mdebug.abi32") == 0) | |
7821 | *abip = MIPS_ABI_O32; | |
7822 | else if (strcmp (name, ".mdebug.abiN32") == 0) | |
7823 | *abip = MIPS_ABI_N32; | |
62a49b2c | 7824 | else if (strcmp (name, ".mdebug.abi64") == 0) |
e3bddbfa | 7825 | *abip = MIPS_ABI_N64; |
caaa3122 DJ |
7826 | else if (strcmp (name, ".mdebug.abiO64") == 0) |
7827 | *abip = MIPS_ABI_O64; | |
7828 | else if (strcmp (name, ".mdebug.eabi32") == 0) | |
7829 | *abip = MIPS_ABI_EABI32; | |
7830 | else if (strcmp (name, ".mdebug.eabi64") == 0) | |
7831 | *abip = MIPS_ABI_EABI64; | |
7832 | else | |
8a3fe4f8 | 7833 | warning (_("unsupported ABI %s."), name + 8); |
caaa3122 DJ |
7834 | } |
7835 | ||
22e47e37 FF |
7836 | static void |
7837 | mips_find_long_section (bfd *abfd, asection *sect, void *obj) | |
7838 | { | |
7839 | int *lbp = (int *) obj; | |
7840 | const char *name = bfd_get_section_name (abfd, sect); | |
7841 | ||
7842 | if (strncmp (name, ".gcc_compiled_long32", 20) == 0) | |
7843 | *lbp = 32; | |
7844 | else if (strncmp (name, ".gcc_compiled_long64", 20) == 0) | |
7845 | *lbp = 64; | |
7846 | else if (strncmp (name, ".gcc_compiled_long", 18) == 0) | |
7847 | warning (_("unrecognized .gcc_compiled_longXX")); | |
7848 | } | |
7849 | ||
2e4ebe70 DJ |
7850 | static enum mips_abi |
7851 | global_mips_abi (void) | |
7852 | { | |
7853 | int i; | |
7854 | ||
7855 | for (i = 0; mips_abi_strings[i] != NULL; i++) | |
7856 | if (mips_abi_strings[i] == mips_abi_string) | |
7857 | return (enum mips_abi) i; | |
7858 | ||
e2e0b3e5 | 7859 | internal_error (__FILE__, __LINE__, _("unknown ABI string")); |
2e4ebe70 DJ |
7860 | } |
7861 | ||
4cc0665f MR |
7862 | /* Return the default compressed instruction set, either of MIPS16 |
7863 | or microMIPS, selected when none could have been determined from | |
7864 | the ELF header of the binary being executed (or no binary has been | |
7865 | selected. */ | |
7866 | ||
7867 | static enum mips_isa | |
7868 | global_mips_compression (void) | |
7869 | { | |
7870 | int i; | |
7871 | ||
7872 | for (i = 0; mips_compression_strings[i] != NULL; i++) | |
7873 | if (mips_compression_strings[i] == mips_compression_string) | |
7874 | return (enum mips_isa) i; | |
7875 | ||
7876 | internal_error (__FILE__, __LINE__, _("unknown compressed ISA string")); | |
7877 | } | |
7878 | ||
29709017 DJ |
7879 | static void |
7880 | mips_register_g_packet_guesses (struct gdbarch *gdbarch) | |
7881 | { | |
29709017 DJ |
7882 | /* If the size matches the set of 32-bit or 64-bit integer registers, |
7883 | assume that's what we've got. */ | |
4eb0ad19 DJ |
7884 | register_remote_g_packet_guess (gdbarch, 38 * 4, mips_tdesc_gp32); |
7885 | register_remote_g_packet_guess (gdbarch, 38 * 8, mips_tdesc_gp64); | |
29709017 DJ |
7886 | |
7887 | /* If the size matches the full set of registers GDB traditionally | |
7888 | knows about, including floating point, for either 32-bit or | |
7889 | 64-bit, assume that's what we've got. */ | |
4eb0ad19 DJ |
7890 | register_remote_g_packet_guess (gdbarch, 90 * 4, mips_tdesc_gp32); |
7891 | register_remote_g_packet_guess (gdbarch, 90 * 8, mips_tdesc_gp64); | |
29709017 DJ |
7892 | |
7893 | /* Otherwise we don't have a useful guess. */ | |
7894 | } | |
7895 | ||
f8b73d13 DJ |
7896 | static struct value * |
7897 | value_of_mips_user_reg (struct frame_info *frame, const void *baton) | |
7898 | { | |
7899 | const int *reg_p = baton; | |
7900 | return value_of_register (*reg_p, frame); | |
7901 | } | |
7902 | ||
c2d11a7d | 7903 | static struct gdbarch * |
6d82d43b | 7904 | mips_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) |
c2d11a7d | 7905 | { |
c2d11a7d JM |
7906 | struct gdbarch *gdbarch; |
7907 | struct gdbarch_tdep *tdep; | |
7908 | int elf_flags; | |
2e4ebe70 | 7909 | enum mips_abi mips_abi, found_abi, wanted_abi; |
f8b73d13 | 7910 | int i, num_regs; |
8d5838b5 | 7911 | enum mips_fpu_type fpu_type; |
f8b73d13 | 7912 | struct tdesc_arch_data *tdesc_data = NULL; |
d929bc19 | 7913 | int elf_fpu_type = Val_GNU_MIPS_ABI_FP_ANY; |
1faeff08 MR |
7914 | const char **reg_names; |
7915 | struct mips_regnum mips_regnum, *regnum; | |
4cc0665f | 7916 | enum mips_isa mips_isa; |
1faeff08 MR |
7917 | int dspacc; |
7918 | int dspctl; | |
7919 | ||
7920 | /* Fill in the OS dependent register numbers and names. */ | |
7921 | if (info.osabi == GDB_OSABI_IRIX) | |
7922 | { | |
7923 | mips_regnum.fp0 = 32; | |
7924 | mips_regnum.pc = 64; | |
7925 | mips_regnum.cause = 65; | |
7926 | mips_regnum.badvaddr = 66; | |
7927 | mips_regnum.hi = 67; | |
7928 | mips_regnum.lo = 68; | |
7929 | mips_regnum.fp_control_status = 69; | |
7930 | mips_regnum.fp_implementation_revision = 70; | |
7931 | mips_regnum.dspacc = dspacc = -1; | |
7932 | mips_regnum.dspctl = dspctl = -1; | |
7933 | num_regs = 71; | |
7934 | reg_names = mips_irix_reg_names; | |
7935 | } | |
7936 | else if (info.osabi == GDB_OSABI_LINUX) | |
7937 | { | |
7938 | mips_regnum.fp0 = 38; | |
7939 | mips_regnum.pc = 37; | |
7940 | mips_regnum.cause = 36; | |
7941 | mips_regnum.badvaddr = 35; | |
7942 | mips_regnum.hi = 34; | |
7943 | mips_regnum.lo = 33; | |
7944 | mips_regnum.fp_control_status = 70; | |
7945 | mips_regnum.fp_implementation_revision = 71; | |
7946 | mips_regnum.dspacc = -1; | |
7947 | mips_regnum.dspctl = -1; | |
7948 | dspacc = 72; | |
7949 | dspctl = 78; | |
7950 | num_regs = 79; | |
7951 | reg_names = mips_linux_reg_names; | |
7952 | } | |
7953 | else | |
7954 | { | |
7955 | mips_regnum.lo = MIPS_EMBED_LO_REGNUM; | |
7956 | mips_regnum.hi = MIPS_EMBED_HI_REGNUM; | |
7957 | mips_regnum.badvaddr = MIPS_EMBED_BADVADDR_REGNUM; | |
7958 | mips_regnum.cause = MIPS_EMBED_CAUSE_REGNUM; | |
7959 | mips_regnum.pc = MIPS_EMBED_PC_REGNUM; | |
7960 | mips_regnum.fp0 = MIPS_EMBED_FP0_REGNUM; | |
7961 | mips_regnum.fp_control_status = 70; | |
7962 | mips_regnum.fp_implementation_revision = 71; | |
7963 | mips_regnum.dspacc = dspacc = -1; | |
7964 | mips_regnum.dspctl = dspctl = -1; | |
7965 | num_regs = MIPS_LAST_EMBED_REGNUM + 1; | |
7966 | if (info.bfd_arch_info != NULL | |
7967 | && info.bfd_arch_info->mach == bfd_mach_mips3900) | |
7968 | reg_names = mips_tx39_reg_names; | |
7969 | else | |
7970 | reg_names = mips_generic_reg_names; | |
7971 | } | |
f8b73d13 DJ |
7972 | |
7973 | /* Check any target description for validity. */ | |
7974 | if (tdesc_has_registers (info.target_desc)) | |
7975 | { | |
7976 | static const char *const mips_gprs[] = { | |
7977 | "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", | |
7978 | "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", | |
7979 | "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", | |
7980 | "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31" | |
7981 | }; | |
7982 | static const char *const mips_fprs[] = { | |
7983 | "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", | |
7984 | "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", | |
7985 | "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23", | |
7986 | "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", | |
7987 | }; | |
7988 | ||
7989 | const struct tdesc_feature *feature; | |
7990 | int valid_p; | |
7991 | ||
7992 | feature = tdesc_find_feature (info.target_desc, | |
7993 | "org.gnu.gdb.mips.cpu"); | |
7994 | if (feature == NULL) | |
7995 | return NULL; | |
7996 | ||
7997 | tdesc_data = tdesc_data_alloc (); | |
7998 | ||
7999 | valid_p = 1; | |
8000 | for (i = MIPS_ZERO_REGNUM; i <= MIPS_RA_REGNUM; i++) | |
8001 | valid_p &= tdesc_numbered_register (feature, tdesc_data, i, | |
8002 | mips_gprs[i]); | |
8003 | ||
8004 | ||
8005 | valid_p &= tdesc_numbered_register (feature, tdesc_data, | |
1faeff08 | 8006 | mips_regnum.lo, "lo"); |
f8b73d13 | 8007 | valid_p &= tdesc_numbered_register (feature, tdesc_data, |
1faeff08 | 8008 | mips_regnum.hi, "hi"); |
f8b73d13 | 8009 | valid_p &= tdesc_numbered_register (feature, tdesc_data, |
1faeff08 | 8010 | mips_regnum.pc, "pc"); |
f8b73d13 DJ |
8011 | |
8012 | if (!valid_p) | |
8013 | { | |
8014 | tdesc_data_cleanup (tdesc_data); | |
8015 | return NULL; | |
8016 | } | |
8017 | ||
8018 | feature = tdesc_find_feature (info.target_desc, | |
8019 | "org.gnu.gdb.mips.cp0"); | |
8020 | if (feature == NULL) | |
8021 | { | |
8022 | tdesc_data_cleanup (tdesc_data); | |
8023 | return NULL; | |
8024 | } | |
8025 | ||
8026 | valid_p = 1; | |
8027 | valid_p &= tdesc_numbered_register (feature, tdesc_data, | |
1faeff08 | 8028 | mips_regnum.badvaddr, "badvaddr"); |
f8b73d13 DJ |
8029 | valid_p &= tdesc_numbered_register (feature, tdesc_data, |
8030 | MIPS_PS_REGNUM, "status"); | |
8031 | valid_p &= tdesc_numbered_register (feature, tdesc_data, | |
1faeff08 | 8032 | mips_regnum.cause, "cause"); |
f8b73d13 DJ |
8033 | |
8034 | if (!valid_p) | |
8035 | { | |
8036 | tdesc_data_cleanup (tdesc_data); | |
8037 | return NULL; | |
8038 | } | |
8039 | ||
8040 | /* FIXME drow/2007-05-17: The FPU should be optional. The MIPS | |
8041 | backend is not prepared for that, though. */ | |
8042 | feature = tdesc_find_feature (info.target_desc, | |
8043 | "org.gnu.gdb.mips.fpu"); | |
8044 | if (feature == NULL) | |
8045 | { | |
8046 | tdesc_data_cleanup (tdesc_data); | |
8047 | return NULL; | |
8048 | } | |
8049 | ||
8050 | valid_p = 1; | |
8051 | for (i = 0; i < 32; i++) | |
8052 | valid_p &= tdesc_numbered_register (feature, tdesc_data, | |
1faeff08 | 8053 | i + mips_regnum.fp0, mips_fprs[i]); |
f8b73d13 DJ |
8054 | |
8055 | valid_p &= tdesc_numbered_register (feature, tdesc_data, | |
1faeff08 MR |
8056 | mips_regnum.fp_control_status, |
8057 | "fcsr"); | |
8058 | valid_p | |
8059 | &= tdesc_numbered_register (feature, tdesc_data, | |
8060 | mips_regnum.fp_implementation_revision, | |
8061 | "fir"); | |
f8b73d13 DJ |
8062 | |
8063 | if (!valid_p) | |
8064 | { | |
8065 | tdesc_data_cleanup (tdesc_data); | |
8066 | return NULL; | |
8067 | } | |
8068 | ||
1faeff08 MR |
8069 | if (dspacc >= 0) |
8070 | { | |
8071 | feature = tdesc_find_feature (info.target_desc, | |
8072 | "org.gnu.gdb.mips.dsp"); | |
8073 | /* The DSP registers are optional; it's OK if they are absent. */ | |
8074 | if (feature != NULL) | |
8075 | { | |
8076 | i = 0; | |
8077 | valid_p = 1; | |
8078 | valid_p &= tdesc_numbered_register (feature, tdesc_data, | |
8079 | dspacc + i++, "hi1"); | |
8080 | valid_p &= tdesc_numbered_register (feature, tdesc_data, | |
8081 | dspacc + i++, "lo1"); | |
8082 | valid_p &= tdesc_numbered_register (feature, tdesc_data, | |
8083 | dspacc + i++, "hi2"); | |
8084 | valid_p &= tdesc_numbered_register (feature, tdesc_data, | |
8085 | dspacc + i++, "lo2"); | |
8086 | valid_p &= tdesc_numbered_register (feature, tdesc_data, | |
8087 | dspacc + i++, "hi3"); | |
8088 | valid_p &= tdesc_numbered_register (feature, tdesc_data, | |
8089 | dspacc + i++, "lo3"); | |
8090 | ||
8091 | valid_p &= tdesc_numbered_register (feature, tdesc_data, | |
8092 | dspctl, "dspctl"); | |
8093 | ||
8094 | if (!valid_p) | |
8095 | { | |
8096 | tdesc_data_cleanup (tdesc_data); | |
8097 | return NULL; | |
8098 | } | |
8099 | ||
8100 | mips_regnum.dspacc = dspacc; | |
8101 | mips_regnum.dspctl = dspctl; | |
8102 | } | |
8103 | } | |
8104 | ||
f8b73d13 DJ |
8105 | /* It would be nice to detect an attempt to use a 64-bit ABI |
8106 | when only 32-bit registers are provided. */ | |
1faeff08 | 8107 | reg_names = NULL; |
f8b73d13 | 8108 | } |
c2d11a7d | 8109 | |
ec03c1ac AC |
8110 | /* First of all, extract the elf_flags, if available. */ |
8111 | if (info.abfd && bfd_get_flavour (info.abfd) == bfd_target_elf_flavour) | |
8112 | elf_flags = elf_elfheader (info.abfd)->e_flags; | |
6214a8a1 AC |
8113 | else if (arches != NULL) |
8114 | elf_flags = gdbarch_tdep (arches->gdbarch)->elf_flags; | |
ec03c1ac AC |
8115 | else |
8116 | elf_flags = 0; | |
8117 | if (gdbarch_debug) | |
8118 | fprintf_unfiltered (gdb_stdlog, | |
6d82d43b | 8119 | "mips_gdbarch_init: elf_flags = 0x%08x\n", elf_flags); |
c2d11a7d | 8120 | |
102182a9 | 8121 | /* Check ELF_FLAGS to see if it specifies the ABI being used. */ |
0dadbba0 AC |
8122 | switch ((elf_flags & EF_MIPS_ABI)) |
8123 | { | |
8124 | case E_MIPS_ABI_O32: | |
ec03c1ac | 8125 | found_abi = MIPS_ABI_O32; |
0dadbba0 AC |
8126 | break; |
8127 | case E_MIPS_ABI_O64: | |
ec03c1ac | 8128 | found_abi = MIPS_ABI_O64; |
0dadbba0 AC |
8129 | break; |
8130 | case E_MIPS_ABI_EABI32: | |
ec03c1ac | 8131 | found_abi = MIPS_ABI_EABI32; |
0dadbba0 AC |
8132 | break; |
8133 | case E_MIPS_ABI_EABI64: | |
ec03c1ac | 8134 | found_abi = MIPS_ABI_EABI64; |
0dadbba0 AC |
8135 | break; |
8136 | default: | |
acdb74a0 | 8137 | if ((elf_flags & EF_MIPS_ABI2)) |
ec03c1ac | 8138 | found_abi = MIPS_ABI_N32; |
acdb74a0 | 8139 | else |
ec03c1ac | 8140 | found_abi = MIPS_ABI_UNKNOWN; |
0dadbba0 AC |
8141 | break; |
8142 | } | |
acdb74a0 | 8143 | |
caaa3122 | 8144 | /* GCC creates a pseudo-section whose name describes the ABI. */ |
ec03c1ac AC |
8145 | if (found_abi == MIPS_ABI_UNKNOWN && info.abfd != NULL) |
8146 | bfd_map_over_sections (info.abfd, mips_find_abi_section, &found_abi); | |
caaa3122 | 8147 | |
dc305454 | 8148 | /* If we have no useful BFD information, use the ABI from the last |
ec03c1ac AC |
8149 | MIPS architecture (if there is one). */ |
8150 | if (found_abi == MIPS_ABI_UNKNOWN && info.abfd == NULL && arches != NULL) | |
8151 | found_abi = gdbarch_tdep (arches->gdbarch)->found_abi; | |
2e4ebe70 | 8152 | |
32a6503c | 8153 | /* Try the architecture for any hint of the correct ABI. */ |
ec03c1ac | 8154 | if (found_abi == MIPS_ABI_UNKNOWN |
bf64bfd6 AC |
8155 | && info.bfd_arch_info != NULL |
8156 | && info.bfd_arch_info->arch == bfd_arch_mips) | |
8157 | { | |
8158 | switch (info.bfd_arch_info->mach) | |
8159 | { | |
8160 | case bfd_mach_mips3900: | |
ec03c1ac | 8161 | found_abi = MIPS_ABI_EABI32; |
bf64bfd6 AC |
8162 | break; |
8163 | case bfd_mach_mips4100: | |
8164 | case bfd_mach_mips5000: | |
ec03c1ac | 8165 | found_abi = MIPS_ABI_EABI64; |
bf64bfd6 | 8166 | break; |
1d06468c EZ |
8167 | case bfd_mach_mips8000: |
8168 | case bfd_mach_mips10000: | |
32a6503c KB |
8169 | /* On Irix, ELF64 executables use the N64 ABI. The |
8170 | pseudo-sections which describe the ABI aren't present | |
8171 | on IRIX. (Even for executables created by gcc.) */ | |
28d169de KB |
8172 | if (bfd_get_flavour (info.abfd) == bfd_target_elf_flavour |
8173 | && elf_elfheader (info.abfd)->e_ident[EI_CLASS] == ELFCLASS64) | |
ec03c1ac | 8174 | found_abi = MIPS_ABI_N64; |
28d169de | 8175 | else |
ec03c1ac | 8176 | found_abi = MIPS_ABI_N32; |
1d06468c | 8177 | break; |
bf64bfd6 AC |
8178 | } |
8179 | } | |
2e4ebe70 | 8180 | |
26c53e50 DJ |
8181 | /* Default 64-bit objects to N64 instead of O32. */ |
8182 | if (found_abi == MIPS_ABI_UNKNOWN | |
8183 | && info.abfd != NULL | |
8184 | && bfd_get_flavour (info.abfd) == bfd_target_elf_flavour | |
8185 | && elf_elfheader (info.abfd)->e_ident[EI_CLASS] == ELFCLASS64) | |
8186 | found_abi = MIPS_ABI_N64; | |
8187 | ||
ec03c1ac AC |
8188 | if (gdbarch_debug) |
8189 | fprintf_unfiltered (gdb_stdlog, "mips_gdbarch_init: found_abi = %d\n", | |
8190 | found_abi); | |
8191 | ||
8192 | /* What has the user specified from the command line? */ | |
8193 | wanted_abi = global_mips_abi (); | |
8194 | if (gdbarch_debug) | |
8195 | fprintf_unfiltered (gdb_stdlog, "mips_gdbarch_init: wanted_abi = %d\n", | |
8196 | wanted_abi); | |
2e4ebe70 DJ |
8197 | |
8198 | /* Now that we have found what the ABI for this binary would be, | |
8199 | check whether the user is overriding it. */ | |
2e4ebe70 DJ |
8200 | if (wanted_abi != MIPS_ABI_UNKNOWN) |
8201 | mips_abi = wanted_abi; | |
ec03c1ac AC |
8202 | else if (found_abi != MIPS_ABI_UNKNOWN) |
8203 | mips_abi = found_abi; | |
8204 | else | |
8205 | mips_abi = MIPS_ABI_O32; | |
8206 | if (gdbarch_debug) | |
8207 | fprintf_unfiltered (gdb_stdlog, "mips_gdbarch_init: mips_abi = %d\n", | |
8208 | mips_abi); | |
2e4ebe70 | 8209 | |
4cc0665f MR |
8210 | /* Determine the default compressed ISA. */ |
8211 | if ((elf_flags & EF_MIPS_ARCH_ASE_MICROMIPS) != 0 | |
8212 | && (elf_flags & EF_MIPS_ARCH_ASE_M16) == 0) | |
8213 | mips_isa = ISA_MICROMIPS; | |
8214 | else if ((elf_flags & EF_MIPS_ARCH_ASE_M16) != 0 | |
8215 | && (elf_flags & EF_MIPS_ARCH_ASE_MICROMIPS) == 0) | |
8216 | mips_isa = ISA_MIPS16; | |
8217 | else | |
8218 | mips_isa = global_mips_compression (); | |
8219 | mips_compression_string = mips_compression_strings[mips_isa]; | |
8220 | ||
ec03c1ac | 8221 | /* Also used when doing an architecture lookup. */ |
4b9b3959 | 8222 | if (gdbarch_debug) |
ec03c1ac | 8223 | fprintf_unfiltered (gdb_stdlog, |
025bb325 MS |
8224 | "mips_gdbarch_init: " |
8225 | "mips64_transfers_32bit_regs_p = %d\n", | |
ec03c1ac | 8226 | mips64_transfers_32bit_regs_p); |
0dadbba0 | 8227 | |
8d5838b5 | 8228 | /* Determine the MIPS FPU type. */ |
609ca2b9 DJ |
8229 | #ifdef HAVE_ELF |
8230 | if (info.abfd | |
8231 | && bfd_get_flavour (info.abfd) == bfd_target_elf_flavour) | |
8232 | elf_fpu_type = bfd_elf_get_obj_attr_int (info.abfd, OBJ_ATTR_GNU, | |
8233 | Tag_GNU_MIPS_ABI_FP); | |
8234 | #endif /* HAVE_ELF */ | |
8235 | ||
8d5838b5 AC |
8236 | if (!mips_fpu_type_auto) |
8237 | fpu_type = mips_fpu_type; | |
d929bc19 | 8238 | else if (elf_fpu_type != Val_GNU_MIPS_ABI_FP_ANY) |
609ca2b9 DJ |
8239 | { |
8240 | switch (elf_fpu_type) | |
8241 | { | |
d929bc19 | 8242 | case Val_GNU_MIPS_ABI_FP_DOUBLE: |
609ca2b9 DJ |
8243 | fpu_type = MIPS_FPU_DOUBLE; |
8244 | break; | |
d929bc19 | 8245 | case Val_GNU_MIPS_ABI_FP_SINGLE: |
609ca2b9 DJ |
8246 | fpu_type = MIPS_FPU_SINGLE; |
8247 | break; | |
d929bc19 | 8248 | case Val_GNU_MIPS_ABI_FP_SOFT: |
609ca2b9 DJ |
8249 | default: |
8250 | /* Soft float or unknown. */ | |
8251 | fpu_type = MIPS_FPU_NONE; | |
8252 | break; | |
8253 | } | |
8254 | } | |
8d5838b5 AC |
8255 | else if (info.bfd_arch_info != NULL |
8256 | && info.bfd_arch_info->arch == bfd_arch_mips) | |
8257 | switch (info.bfd_arch_info->mach) | |
8258 | { | |
8259 | case bfd_mach_mips3900: | |
8260 | case bfd_mach_mips4100: | |
8261 | case bfd_mach_mips4111: | |
a9d61c86 | 8262 | case bfd_mach_mips4120: |
8d5838b5 AC |
8263 | fpu_type = MIPS_FPU_NONE; |
8264 | break; | |
8265 | case bfd_mach_mips4650: | |
8266 | fpu_type = MIPS_FPU_SINGLE; | |
8267 | break; | |
8268 | default: | |
8269 | fpu_type = MIPS_FPU_DOUBLE; | |
8270 | break; | |
8271 | } | |
8272 | else if (arches != NULL) | |
8273 | fpu_type = gdbarch_tdep (arches->gdbarch)->mips_fpu_type; | |
8274 | else | |
8275 | fpu_type = MIPS_FPU_DOUBLE; | |
8276 | if (gdbarch_debug) | |
8277 | fprintf_unfiltered (gdb_stdlog, | |
6d82d43b | 8278 | "mips_gdbarch_init: fpu_type = %d\n", fpu_type); |
8d5838b5 | 8279 | |
29709017 DJ |
8280 | /* Check for blatant incompatibilities. */ |
8281 | ||
8282 | /* If we have only 32-bit registers, then we can't debug a 64-bit | |
8283 | ABI. */ | |
8284 | if (info.target_desc | |
8285 | && tdesc_property (info.target_desc, PROPERTY_GP32) != NULL | |
8286 | && mips_abi != MIPS_ABI_EABI32 | |
8287 | && mips_abi != MIPS_ABI_O32) | |
f8b73d13 DJ |
8288 | { |
8289 | if (tdesc_data != NULL) | |
8290 | tdesc_data_cleanup (tdesc_data); | |
8291 | return NULL; | |
8292 | } | |
29709017 | 8293 | |
025bb325 | 8294 | /* Try to find a pre-existing architecture. */ |
c2d11a7d JM |
8295 | for (arches = gdbarch_list_lookup_by_info (arches, &info); |
8296 | arches != NULL; | |
8297 | arches = gdbarch_list_lookup_by_info (arches->next, &info)) | |
8298 | { | |
8299 | /* MIPS needs to be pedantic about which ABI the object is | |
102182a9 | 8300 | using. */ |
9103eae0 | 8301 | if (gdbarch_tdep (arches->gdbarch)->elf_flags != elf_flags) |
c2d11a7d | 8302 | continue; |
9103eae0 | 8303 | if (gdbarch_tdep (arches->gdbarch)->mips_abi != mips_abi) |
0dadbba0 | 8304 | continue; |
719ec221 AC |
8305 | /* Need to be pedantic about which register virtual size is |
8306 | used. */ | |
8307 | if (gdbarch_tdep (arches->gdbarch)->mips64_transfers_32bit_regs_p | |
8308 | != mips64_transfers_32bit_regs_p) | |
8309 | continue; | |
8d5838b5 AC |
8310 | /* Be pedantic about which FPU is selected. */ |
8311 | if (gdbarch_tdep (arches->gdbarch)->mips_fpu_type != fpu_type) | |
8312 | continue; | |
f8b73d13 DJ |
8313 | |
8314 | if (tdesc_data != NULL) | |
8315 | tdesc_data_cleanup (tdesc_data); | |
4be87837 | 8316 | return arches->gdbarch; |
c2d11a7d JM |
8317 | } |
8318 | ||
102182a9 | 8319 | /* Need a new architecture. Fill in a target specific vector. */ |
c2d11a7d JM |
8320 | tdep = (struct gdbarch_tdep *) xmalloc (sizeof (struct gdbarch_tdep)); |
8321 | gdbarch = gdbarch_alloc (&info, tdep); | |
8322 | tdep->elf_flags = elf_flags; | |
719ec221 | 8323 | tdep->mips64_transfers_32bit_regs_p = mips64_transfers_32bit_regs_p; |
ec03c1ac AC |
8324 | tdep->found_abi = found_abi; |
8325 | tdep->mips_abi = mips_abi; | |
4cc0665f | 8326 | tdep->mips_isa = mips_isa; |
8d5838b5 | 8327 | tdep->mips_fpu_type = fpu_type; |
29709017 DJ |
8328 | tdep->register_size_valid_p = 0; |
8329 | tdep->register_size = 0; | |
50e8a0d5 HZ |
8330 | tdep->gregset = NULL; |
8331 | tdep->gregset64 = NULL; | |
8332 | tdep->fpregset = NULL; | |
8333 | tdep->fpregset64 = NULL; | |
29709017 DJ |
8334 | |
8335 | if (info.target_desc) | |
8336 | { | |
8337 | /* Some useful properties can be inferred from the target. */ | |
8338 | if (tdesc_property (info.target_desc, PROPERTY_GP32) != NULL) | |
8339 | { | |
8340 | tdep->register_size_valid_p = 1; | |
8341 | tdep->register_size = 4; | |
8342 | } | |
8343 | else if (tdesc_property (info.target_desc, PROPERTY_GP64) != NULL) | |
8344 | { | |
8345 | tdep->register_size_valid_p = 1; | |
8346 | tdep->register_size = 8; | |
8347 | } | |
8348 | } | |
c2d11a7d | 8349 | |
102182a9 | 8350 | /* Initially set everything according to the default ABI/ISA. */ |
c2d11a7d JM |
8351 | set_gdbarch_short_bit (gdbarch, 16); |
8352 | set_gdbarch_int_bit (gdbarch, 32); | |
8353 | set_gdbarch_float_bit (gdbarch, 32); | |
8354 | set_gdbarch_double_bit (gdbarch, 64); | |
8355 | set_gdbarch_long_double_bit (gdbarch, 64); | |
a4b8ebc8 AC |
8356 | set_gdbarch_register_reggroup_p (gdbarch, mips_register_reggroup_p); |
8357 | set_gdbarch_pseudo_register_read (gdbarch, mips_pseudo_register_read); | |
8358 | set_gdbarch_pseudo_register_write (gdbarch, mips_pseudo_register_write); | |
1d06468c | 8359 | |
175ff332 HZ |
8360 | set_gdbarch_ax_pseudo_register_collect (gdbarch, |
8361 | mips_ax_pseudo_register_collect); | |
8362 | set_gdbarch_ax_pseudo_register_push_stack | |
8363 | (gdbarch, mips_ax_pseudo_register_push_stack); | |
8364 | ||
6d82d43b | 8365 | set_gdbarch_elf_make_msymbol_special (gdbarch, |
f7ab6ec6 MS |
8366 | mips_elf_make_msymbol_special); |
8367 | ||
1faeff08 MR |
8368 | regnum = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct mips_regnum); |
8369 | *regnum = mips_regnum; | |
1faeff08 MR |
8370 | set_gdbarch_fp0_regnum (gdbarch, regnum->fp0); |
8371 | set_gdbarch_num_regs (gdbarch, num_regs); | |
8372 | set_gdbarch_num_pseudo_regs (gdbarch, num_regs); | |
8373 | set_gdbarch_register_name (gdbarch, mips_register_name); | |
8374 | set_gdbarch_virtual_frame_pointer (gdbarch, mips_virtual_frame_pointer); | |
8375 | tdep->mips_processor_reg_names = reg_names; | |
8376 | tdep->regnum = regnum; | |
fe29b929 | 8377 | |
0dadbba0 | 8378 | switch (mips_abi) |
c2d11a7d | 8379 | { |
0dadbba0 | 8380 | case MIPS_ABI_O32: |
25ab4790 | 8381 | set_gdbarch_push_dummy_call (gdbarch, mips_o32_push_dummy_call); |
29dfb2ac | 8382 | set_gdbarch_return_value (gdbarch, mips_o32_return_value); |
4c7d22cb | 8383 | tdep->mips_last_arg_regnum = MIPS_A0_REGNUM + 4 - 1; |
56cea623 | 8384 | tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 4 - 1; |
4014092b | 8385 | tdep->default_mask_address_p = 0; |
c2d11a7d JM |
8386 | set_gdbarch_long_bit (gdbarch, 32); |
8387 | set_gdbarch_ptr_bit (gdbarch, 32); | |
8388 | set_gdbarch_long_long_bit (gdbarch, 64); | |
8389 | break; | |
0dadbba0 | 8390 | case MIPS_ABI_O64: |
25ab4790 | 8391 | set_gdbarch_push_dummy_call (gdbarch, mips_o64_push_dummy_call); |
9c8fdbfa | 8392 | set_gdbarch_return_value (gdbarch, mips_o64_return_value); |
4c7d22cb | 8393 | tdep->mips_last_arg_regnum = MIPS_A0_REGNUM + 4 - 1; |
56cea623 | 8394 | tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 4 - 1; |
361d1df0 | 8395 | tdep->default_mask_address_p = 0; |
c2d11a7d JM |
8396 | set_gdbarch_long_bit (gdbarch, 32); |
8397 | set_gdbarch_ptr_bit (gdbarch, 32); | |
8398 | set_gdbarch_long_long_bit (gdbarch, 64); | |
8399 | break; | |
0dadbba0 | 8400 | case MIPS_ABI_EABI32: |
25ab4790 | 8401 | set_gdbarch_push_dummy_call (gdbarch, mips_eabi_push_dummy_call); |
9c8fdbfa | 8402 | set_gdbarch_return_value (gdbarch, mips_eabi_return_value); |
4c7d22cb | 8403 | tdep->mips_last_arg_regnum = MIPS_A0_REGNUM + 8 - 1; |
56cea623 | 8404 | tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 8 - 1; |
4014092b | 8405 | tdep->default_mask_address_p = 0; |
c2d11a7d JM |
8406 | set_gdbarch_long_bit (gdbarch, 32); |
8407 | set_gdbarch_ptr_bit (gdbarch, 32); | |
8408 | set_gdbarch_long_long_bit (gdbarch, 64); | |
8409 | break; | |
0dadbba0 | 8410 | case MIPS_ABI_EABI64: |
25ab4790 | 8411 | set_gdbarch_push_dummy_call (gdbarch, mips_eabi_push_dummy_call); |
9c8fdbfa | 8412 | set_gdbarch_return_value (gdbarch, mips_eabi_return_value); |
4c7d22cb | 8413 | tdep->mips_last_arg_regnum = MIPS_A0_REGNUM + 8 - 1; |
56cea623 | 8414 | tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 8 - 1; |
4014092b | 8415 | tdep->default_mask_address_p = 0; |
c2d11a7d JM |
8416 | set_gdbarch_long_bit (gdbarch, 64); |
8417 | set_gdbarch_ptr_bit (gdbarch, 64); | |
8418 | set_gdbarch_long_long_bit (gdbarch, 64); | |
8419 | break; | |
0dadbba0 | 8420 | case MIPS_ABI_N32: |
25ab4790 | 8421 | set_gdbarch_push_dummy_call (gdbarch, mips_n32n64_push_dummy_call); |
29dfb2ac | 8422 | set_gdbarch_return_value (gdbarch, mips_n32n64_return_value); |
4c7d22cb | 8423 | tdep->mips_last_arg_regnum = MIPS_A0_REGNUM + 8 - 1; |
56cea623 | 8424 | tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 8 - 1; |
4014092b | 8425 | tdep->default_mask_address_p = 0; |
0dadbba0 AC |
8426 | set_gdbarch_long_bit (gdbarch, 32); |
8427 | set_gdbarch_ptr_bit (gdbarch, 32); | |
8428 | set_gdbarch_long_long_bit (gdbarch, 64); | |
fed7ba43 | 8429 | set_gdbarch_long_double_bit (gdbarch, 128); |
b14d30e1 | 8430 | set_gdbarch_long_double_format (gdbarch, floatformats_ibm_long_double); |
28d169de KB |
8431 | break; |
8432 | case MIPS_ABI_N64: | |
25ab4790 | 8433 | set_gdbarch_push_dummy_call (gdbarch, mips_n32n64_push_dummy_call); |
29dfb2ac | 8434 | set_gdbarch_return_value (gdbarch, mips_n32n64_return_value); |
4c7d22cb | 8435 | tdep->mips_last_arg_regnum = MIPS_A0_REGNUM + 8 - 1; |
56cea623 | 8436 | tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 8 - 1; |
28d169de KB |
8437 | tdep->default_mask_address_p = 0; |
8438 | set_gdbarch_long_bit (gdbarch, 64); | |
8439 | set_gdbarch_ptr_bit (gdbarch, 64); | |
8440 | set_gdbarch_long_long_bit (gdbarch, 64); | |
fed7ba43 | 8441 | set_gdbarch_long_double_bit (gdbarch, 128); |
b14d30e1 | 8442 | set_gdbarch_long_double_format (gdbarch, floatformats_ibm_long_double); |
0dadbba0 | 8443 | break; |
c2d11a7d | 8444 | default: |
e2e0b3e5 | 8445 | internal_error (__FILE__, __LINE__, _("unknown ABI in switch")); |
c2d11a7d JM |
8446 | } |
8447 | ||
22e47e37 FF |
8448 | /* GCC creates a pseudo-section whose name specifies the size of |
8449 | longs, since -mlong32 or -mlong64 may be used independent of | |
8450 | other options. How those options affect pointer sizes is ABI and | |
8451 | architecture dependent, so use them to override the default sizes | |
8452 | set by the ABI. This table shows the relationship between ABI, | |
8453 | -mlongXX, and size of pointers: | |
8454 | ||
8455 | ABI -mlongXX ptr bits | |
8456 | --- -------- -------- | |
8457 | o32 32 32 | |
8458 | o32 64 32 | |
8459 | n32 32 32 | |
8460 | n32 64 64 | |
8461 | o64 32 32 | |
8462 | o64 64 64 | |
8463 | n64 32 32 | |
8464 | n64 64 64 | |
8465 | eabi32 32 32 | |
8466 | eabi32 64 32 | |
8467 | eabi64 32 32 | |
8468 | eabi64 64 64 | |
8469 | ||
8470 | Note that for o32 and eabi32, pointers are always 32 bits | |
8471 | regardless of any -mlongXX option. For all others, pointers and | |
025bb325 | 8472 | longs are the same, as set by -mlongXX or set by defaults. */ |
22e47e37 FF |
8473 | |
8474 | if (info.abfd != NULL) | |
8475 | { | |
8476 | int long_bit = 0; | |
8477 | ||
8478 | bfd_map_over_sections (info.abfd, mips_find_long_section, &long_bit); | |
8479 | if (long_bit) | |
8480 | { | |
8481 | set_gdbarch_long_bit (gdbarch, long_bit); | |
8482 | switch (mips_abi) | |
8483 | { | |
8484 | case MIPS_ABI_O32: | |
8485 | case MIPS_ABI_EABI32: | |
8486 | break; | |
8487 | case MIPS_ABI_N32: | |
8488 | case MIPS_ABI_O64: | |
8489 | case MIPS_ABI_N64: | |
8490 | case MIPS_ABI_EABI64: | |
8491 | set_gdbarch_ptr_bit (gdbarch, long_bit); | |
8492 | break; | |
8493 | default: | |
8494 | internal_error (__FILE__, __LINE__, _("unknown ABI in switch")); | |
8495 | } | |
8496 | } | |
8497 | } | |
8498 | ||
a5ea2558 AC |
8499 | /* FIXME: jlarmour/2000-04-07: There *is* a flag EF_MIPS_32BIT_MODE |
8500 | that could indicate -gp32 BUT gas/config/tc-mips.c contains the | |
8501 | comment: | |
8502 | ||
8503 | ``We deliberately don't allow "-gp32" to set the MIPS_32BITMODE | |
8504 | flag in object files because to do so would make it impossible to | |
102182a9 | 8505 | link with libraries compiled without "-gp32". This is |
a5ea2558 | 8506 | unnecessarily restrictive. |
361d1df0 | 8507 | |
a5ea2558 AC |
8508 | We could solve this problem by adding "-gp32" multilibs to gcc, |
8509 | but to set this flag before gcc is built with such multilibs will | |
8510 | break too many systems.'' | |
8511 | ||
8512 | But even more unhelpfully, the default linker output target for | |
8513 | mips64-elf is elf32-bigmips, and has EF_MIPS_32BIT_MODE set, even | |
8514 | for 64-bit programs - you need to change the ABI to change this, | |
102182a9 | 8515 | and not all gcc targets support that currently. Therefore using |
a5ea2558 AC |
8516 | this flag to detect 32-bit mode would do the wrong thing given |
8517 | the current gcc - it would make GDB treat these 64-bit programs | |
102182a9 | 8518 | as 32-bit programs by default. */ |
a5ea2558 | 8519 | |
6c997a34 | 8520 | set_gdbarch_read_pc (gdbarch, mips_read_pc); |
b6cb9035 | 8521 | set_gdbarch_write_pc (gdbarch, mips_write_pc); |
c2d11a7d | 8522 | |
102182a9 MS |
8523 | /* Add/remove bits from an address. The MIPS needs be careful to |
8524 | ensure that all 32 bit addresses are sign extended to 64 bits. */ | |
875e1767 AC |
8525 | set_gdbarch_addr_bits_remove (gdbarch, mips_addr_bits_remove); |
8526 | ||
58dfe9ff AC |
8527 | /* Unwind the frame. */ |
8528 | set_gdbarch_unwind_pc (gdbarch, mips_unwind_pc); | |
30244cd8 | 8529 | set_gdbarch_unwind_sp (gdbarch, mips_unwind_sp); |
b8a22b94 | 8530 | set_gdbarch_dummy_id (gdbarch, mips_dummy_id); |
10312cc4 | 8531 | |
102182a9 | 8532 | /* Map debug register numbers onto internal register numbers. */ |
88c72b7d | 8533 | set_gdbarch_stab_reg_to_regnum (gdbarch, mips_stab_reg_to_regnum); |
6d82d43b AC |
8534 | set_gdbarch_ecoff_reg_to_regnum (gdbarch, |
8535 | mips_dwarf_dwarf2_ecoff_reg_to_regnum); | |
6d82d43b AC |
8536 | set_gdbarch_dwarf2_reg_to_regnum (gdbarch, |
8537 | mips_dwarf_dwarf2_ecoff_reg_to_regnum); | |
a4b8ebc8 | 8538 | set_gdbarch_register_sim_regno (gdbarch, mips_register_sim_regno); |
88c72b7d | 8539 | |
025bb325 | 8540 | /* MIPS version of CALL_DUMMY. */ |
c2d11a7d | 8541 | |
2c76a0c7 JB |
8542 | set_gdbarch_call_dummy_location (gdbarch, ON_STACK); |
8543 | set_gdbarch_push_dummy_code (gdbarch, mips_push_dummy_code); | |
dc604539 | 8544 | set_gdbarch_frame_align (gdbarch, mips_frame_align); |
d05285fa | 8545 | |
87783b8b AC |
8546 | set_gdbarch_convert_register_p (gdbarch, mips_convert_register_p); |
8547 | set_gdbarch_register_to_value (gdbarch, mips_register_to_value); | |
8548 | set_gdbarch_value_to_register (gdbarch, mips_value_to_register); | |
8549 | ||
f7b9e9fc AC |
8550 | set_gdbarch_inner_than (gdbarch, core_addr_lessthan); |
8551 | set_gdbarch_breakpoint_from_pc (gdbarch, mips_breakpoint_from_pc); | |
4cc0665f MR |
8552 | set_gdbarch_remote_breakpoint_from_pc (gdbarch, |
8553 | mips_remote_breakpoint_from_pc); | |
c8cef75f MR |
8554 | set_gdbarch_adjust_breakpoint_address (gdbarch, |
8555 | mips_adjust_breakpoint_address); | |
f7b9e9fc AC |
8556 | |
8557 | set_gdbarch_skip_prologue (gdbarch, mips_skip_prologue); | |
f7b9e9fc | 8558 | |
97ab0fdd MR |
8559 | set_gdbarch_in_function_epilogue_p (gdbarch, mips_in_function_epilogue_p); |
8560 | ||
fc0c74b1 AC |
8561 | set_gdbarch_pointer_to_address (gdbarch, signed_pointer_to_address); |
8562 | set_gdbarch_address_to_pointer (gdbarch, address_to_signed_pointer); | |
8563 | set_gdbarch_integer_to_address (gdbarch, mips_integer_to_address); | |
70f80edf | 8564 | |
a4b8ebc8 | 8565 | set_gdbarch_register_type (gdbarch, mips_register_type); |
78fde5f8 | 8566 | |
e11c53d2 | 8567 | set_gdbarch_print_registers_info (gdbarch, mips_print_registers_info); |
bf1f5b4c | 8568 | |
9dae60cc UW |
8569 | if (mips_abi == MIPS_ABI_N32) |
8570 | set_gdbarch_print_insn (gdbarch, gdb_print_insn_mips_n32); | |
8571 | else if (mips_abi == MIPS_ABI_N64) | |
8572 | set_gdbarch_print_insn (gdbarch, gdb_print_insn_mips_n64); | |
8573 | else | |
8574 | set_gdbarch_print_insn (gdbarch, gdb_print_insn_mips); | |
e5ab0dce | 8575 | |
d92524f1 PM |
8576 | /* FIXME: cagney/2003-08-29: The macros target_have_steppable_watchpoint, |
8577 | HAVE_NONSTEPPABLE_WATCHPOINT, and target_have_continuable_watchpoint | |
3a3bc038 | 8578 | need to all be folded into the target vector. Since they are |
d92524f1 PM |
8579 | being used as guards for target_stopped_by_watchpoint, why not have |
8580 | target_stopped_by_watchpoint return the type of watchpoint that the code | |
3a3bc038 AC |
8581 | is sitting on? */ |
8582 | set_gdbarch_have_nonsteppable_watchpoint (gdbarch, 1); | |
8583 | ||
e7d6a6d2 | 8584 | set_gdbarch_skip_trampoline_code (gdbarch, mips_skip_trampoline_code); |
757a7cc6 | 8585 | |
14132e89 MR |
8586 | /* NOTE drow/2012-04-25: We overload the core solib trampoline code |
8587 | to support MIPS16. This is a bad thing. Make sure not to do it | |
8588 | if we have an OS ABI that actually supports shared libraries, since | |
8589 | shared library support is more important. If we have an OS someday | |
8590 | that supports both shared libraries and MIPS16, we'll have to find | |
8591 | a better place for these. | |
8592 | macro/2012-04-25: But that applies to return trampolines only and | |
8593 | currently no MIPS OS ABI uses shared libraries that have them. */ | |
8594 | set_gdbarch_in_solib_return_trampoline (gdbarch, mips_in_return_stub); | |
8595 | ||
025bb325 MS |
8596 | set_gdbarch_single_step_through_delay (gdbarch, |
8597 | mips_single_step_through_delay); | |
3352ef37 | 8598 | |
0d5de010 DJ |
8599 | /* Virtual tables. */ |
8600 | set_gdbarch_vbit_in_delta (gdbarch, 1); | |
8601 | ||
29709017 DJ |
8602 | mips_register_g_packet_guesses (gdbarch); |
8603 | ||
6de918a6 | 8604 | /* Hook in OS ABI-specific overrides, if they have been registered. */ |
822b6570 | 8605 | info.tdep_info = (void *) tdesc_data; |
6de918a6 | 8606 | gdbarch_init_osabi (info, gdbarch); |
757a7cc6 | 8607 | |
9aac7884 MR |
8608 | /* The hook may have adjusted num_regs, fetch the final value and |
8609 | set pc_regnum and sp_regnum now that it has been fixed. */ | |
9aac7884 MR |
8610 | num_regs = gdbarch_num_regs (gdbarch); |
8611 | set_gdbarch_pc_regnum (gdbarch, regnum->pc + num_regs); | |
8612 | set_gdbarch_sp_regnum (gdbarch, MIPS_SP_REGNUM + num_regs); | |
8613 | ||
5792a79b | 8614 | /* Unwind the frame. */ |
b8a22b94 DJ |
8615 | dwarf2_append_unwinders (gdbarch); |
8616 | frame_unwind_append_unwinder (gdbarch, &mips_stub_frame_unwind); | |
8617 | frame_unwind_append_unwinder (gdbarch, &mips_insn16_frame_unwind); | |
4cc0665f | 8618 | frame_unwind_append_unwinder (gdbarch, &mips_micro_frame_unwind); |
b8a22b94 | 8619 | frame_unwind_append_unwinder (gdbarch, &mips_insn32_frame_unwind); |
2bd0c3d7 | 8620 | frame_base_append_sniffer (gdbarch, dwarf2_frame_base_sniffer); |
eec63939 | 8621 | frame_base_append_sniffer (gdbarch, mips_stub_frame_base_sniffer); |
45c9dd44 | 8622 | frame_base_append_sniffer (gdbarch, mips_insn16_frame_base_sniffer); |
4cc0665f | 8623 | frame_base_append_sniffer (gdbarch, mips_micro_frame_base_sniffer); |
45c9dd44 | 8624 | frame_base_append_sniffer (gdbarch, mips_insn32_frame_base_sniffer); |
5792a79b | 8625 | |
f8b73d13 DJ |
8626 | if (tdesc_data) |
8627 | { | |
8628 | set_tdesc_pseudo_register_type (gdbarch, mips_pseudo_register_type); | |
7cc46491 | 8629 | tdesc_use_registers (gdbarch, info.target_desc, tdesc_data); |
f8b73d13 DJ |
8630 | |
8631 | /* Override the normal target description methods to handle our | |
8632 | dual real and pseudo registers. */ | |
8633 | set_gdbarch_register_name (gdbarch, mips_register_name); | |
025bb325 MS |
8634 | set_gdbarch_register_reggroup_p (gdbarch, |
8635 | mips_tdesc_register_reggroup_p); | |
f8b73d13 DJ |
8636 | |
8637 | num_regs = gdbarch_num_regs (gdbarch); | |
8638 | set_gdbarch_num_pseudo_regs (gdbarch, num_regs); | |
8639 | set_gdbarch_pc_regnum (gdbarch, tdep->regnum->pc + num_regs); | |
8640 | set_gdbarch_sp_regnum (gdbarch, MIPS_SP_REGNUM + num_regs); | |
8641 | } | |
8642 | ||
8643 | /* Add ABI-specific aliases for the registers. */ | |
8644 | if (mips_abi == MIPS_ABI_N32 || mips_abi == MIPS_ABI_N64) | |
8645 | for (i = 0; i < ARRAY_SIZE (mips_n32_n64_aliases); i++) | |
8646 | user_reg_add (gdbarch, mips_n32_n64_aliases[i].name, | |
8647 | value_of_mips_user_reg, &mips_n32_n64_aliases[i].regnum); | |
8648 | else | |
8649 | for (i = 0; i < ARRAY_SIZE (mips_o32_aliases); i++) | |
8650 | user_reg_add (gdbarch, mips_o32_aliases[i].name, | |
8651 | value_of_mips_user_reg, &mips_o32_aliases[i].regnum); | |
8652 | ||
8653 | /* Add some other standard aliases. */ | |
8654 | for (i = 0; i < ARRAY_SIZE (mips_register_aliases); i++) | |
8655 | user_reg_add (gdbarch, mips_register_aliases[i].name, | |
8656 | value_of_mips_user_reg, &mips_register_aliases[i].regnum); | |
8657 | ||
865093a3 AR |
8658 | for (i = 0; i < ARRAY_SIZE (mips_numeric_register_aliases); i++) |
8659 | user_reg_add (gdbarch, mips_numeric_register_aliases[i].name, | |
8660 | value_of_mips_user_reg, | |
8661 | &mips_numeric_register_aliases[i].regnum); | |
8662 | ||
4b9b3959 AC |
8663 | return gdbarch; |
8664 | } | |
8665 | ||
2e4ebe70 | 8666 | static void |
6d82d43b | 8667 | mips_abi_update (char *ignore_args, int from_tty, struct cmd_list_element *c) |
2e4ebe70 DJ |
8668 | { |
8669 | struct gdbarch_info info; | |
8670 | ||
8671 | /* Force the architecture to update, and (if it's a MIPS architecture) | |
8672 | mips_gdbarch_init will take care of the rest. */ | |
8673 | gdbarch_info_init (&info); | |
8674 | gdbarch_update_p (info); | |
8675 | } | |
8676 | ||
ad188201 KB |
8677 | /* Print out which MIPS ABI is in use. */ |
8678 | ||
8679 | static void | |
1f8ca57c JB |
8680 | show_mips_abi (struct ui_file *file, |
8681 | int from_tty, | |
8682 | struct cmd_list_element *ignored_cmd, | |
8683 | const char *ignored_value) | |
ad188201 | 8684 | { |
f5656ead | 8685 | if (gdbarch_bfd_arch_info (target_gdbarch ())->arch != bfd_arch_mips) |
1f8ca57c JB |
8686 | fprintf_filtered |
8687 | (file, | |
8688 | "The MIPS ABI is unknown because the current architecture " | |
8689 | "is not MIPS.\n"); | |
ad188201 KB |
8690 | else |
8691 | { | |
8692 | enum mips_abi global_abi = global_mips_abi (); | |
f5656ead | 8693 | enum mips_abi actual_abi = mips_abi (target_gdbarch ()); |
ad188201 KB |
8694 | const char *actual_abi_str = mips_abi_strings[actual_abi]; |
8695 | ||
8696 | if (global_abi == MIPS_ABI_UNKNOWN) | |
1f8ca57c JB |
8697 | fprintf_filtered |
8698 | (file, | |
8699 | "The MIPS ABI is set automatically (currently \"%s\").\n", | |
6d82d43b | 8700 | actual_abi_str); |
ad188201 | 8701 | else if (global_abi == actual_abi) |
1f8ca57c JB |
8702 | fprintf_filtered |
8703 | (file, | |
8704 | "The MIPS ABI is assumed to be \"%s\" (due to user setting).\n", | |
6d82d43b | 8705 | actual_abi_str); |
ad188201 KB |
8706 | else |
8707 | { | |
8708 | /* Probably shouldn't happen... */ | |
025bb325 MS |
8709 | fprintf_filtered (file, |
8710 | "The (auto detected) MIPS ABI \"%s\" is in use " | |
8711 | "even though the user setting was \"%s\".\n", | |
6d82d43b | 8712 | actual_abi_str, mips_abi_strings[global_abi]); |
ad188201 KB |
8713 | } |
8714 | } | |
8715 | } | |
8716 | ||
4cc0665f MR |
8717 | /* Print out which MIPS compressed ISA encoding is used. */ |
8718 | ||
8719 | static void | |
8720 | show_mips_compression (struct ui_file *file, int from_tty, | |
8721 | struct cmd_list_element *c, const char *value) | |
8722 | { | |
8723 | fprintf_filtered (file, _("The compressed ISA encoding used is %s.\n"), | |
8724 | value); | |
8725 | } | |
8726 | ||
4b9b3959 | 8727 | static void |
72a155b4 | 8728 | mips_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file) |
4b9b3959 | 8729 | { |
72a155b4 | 8730 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
4b9b3959 | 8731 | if (tdep != NULL) |
c2d11a7d | 8732 | { |
acdb74a0 AC |
8733 | int ef_mips_arch; |
8734 | int ef_mips_32bitmode; | |
f49e4e6d | 8735 | /* Determine the ISA. */ |
acdb74a0 AC |
8736 | switch (tdep->elf_flags & EF_MIPS_ARCH) |
8737 | { | |
8738 | case E_MIPS_ARCH_1: | |
8739 | ef_mips_arch = 1; | |
8740 | break; | |
8741 | case E_MIPS_ARCH_2: | |
8742 | ef_mips_arch = 2; | |
8743 | break; | |
8744 | case E_MIPS_ARCH_3: | |
8745 | ef_mips_arch = 3; | |
8746 | break; | |
8747 | case E_MIPS_ARCH_4: | |
93d56215 | 8748 | ef_mips_arch = 4; |
acdb74a0 AC |
8749 | break; |
8750 | default: | |
93d56215 | 8751 | ef_mips_arch = 0; |
acdb74a0 AC |
8752 | break; |
8753 | } | |
f49e4e6d | 8754 | /* Determine the size of a pointer. */ |
acdb74a0 | 8755 | ef_mips_32bitmode = (tdep->elf_flags & EF_MIPS_32BITMODE); |
4b9b3959 AC |
8756 | fprintf_unfiltered (file, |
8757 | "mips_dump_tdep: tdep->elf_flags = 0x%x\n", | |
0dadbba0 | 8758 | tdep->elf_flags); |
4b9b3959 | 8759 | fprintf_unfiltered (file, |
acdb74a0 AC |
8760 | "mips_dump_tdep: ef_mips_32bitmode = %d\n", |
8761 | ef_mips_32bitmode); | |
8762 | fprintf_unfiltered (file, | |
8763 | "mips_dump_tdep: ef_mips_arch = %d\n", | |
8764 | ef_mips_arch); | |
8765 | fprintf_unfiltered (file, | |
8766 | "mips_dump_tdep: tdep->mips_abi = %d (%s)\n", | |
6d82d43b | 8767 | tdep->mips_abi, mips_abi_strings[tdep->mips_abi]); |
4014092b | 8768 | fprintf_unfiltered (file, |
025bb325 MS |
8769 | "mips_dump_tdep: " |
8770 | "mips_mask_address_p() %d (default %d)\n", | |
480d3dd2 | 8771 | mips_mask_address_p (tdep), |
4014092b | 8772 | tdep->default_mask_address_p); |
c2d11a7d | 8773 | } |
4b9b3959 AC |
8774 | fprintf_unfiltered (file, |
8775 | "mips_dump_tdep: MIPS_DEFAULT_FPU_TYPE = %d (%s)\n", | |
8776 | MIPS_DEFAULT_FPU_TYPE, | |
8777 | (MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_NONE ? "none" | |
8778 | : MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_SINGLE ? "single" | |
8779 | : MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_DOUBLE ? "double" | |
8780 | : "???")); | |
74ed0bb4 MD |
8781 | fprintf_unfiltered (file, "mips_dump_tdep: MIPS_EABI = %d\n", |
8782 | MIPS_EABI (gdbarch)); | |
4b9b3959 AC |
8783 | fprintf_unfiltered (file, |
8784 | "mips_dump_tdep: MIPS_FPU_TYPE = %d (%s)\n", | |
74ed0bb4 MD |
8785 | MIPS_FPU_TYPE (gdbarch), |
8786 | (MIPS_FPU_TYPE (gdbarch) == MIPS_FPU_NONE ? "none" | |
8787 | : MIPS_FPU_TYPE (gdbarch) == MIPS_FPU_SINGLE ? "single" | |
8788 | : MIPS_FPU_TYPE (gdbarch) == MIPS_FPU_DOUBLE ? "double" | |
4b9b3959 | 8789 | : "???")); |
c2d11a7d JM |
8790 | } |
8791 | ||
025bb325 | 8792 | extern initialize_file_ftype _initialize_mips_tdep; /* -Wmissing-prototypes */ |
a78f21af | 8793 | |
c906108c | 8794 | void |
acdb74a0 | 8795 | _initialize_mips_tdep (void) |
c906108c SS |
8796 | { |
8797 | static struct cmd_list_element *mipsfpulist = NULL; | |
8798 | struct cmd_list_element *c; | |
8799 | ||
6d82d43b | 8800 | mips_abi_string = mips_abi_strings[MIPS_ABI_UNKNOWN]; |
2e4ebe70 DJ |
8801 | if (MIPS_ABI_LAST + 1 |
8802 | != sizeof (mips_abi_strings) / sizeof (mips_abi_strings[0])) | |
e2e0b3e5 | 8803 | internal_error (__FILE__, __LINE__, _("mips_abi_strings out of sync")); |
2e4ebe70 | 8804 | |
4b9b3959 | 8805 | gdbarch_register (bfd_arch_mips, mips_gdbarch_init, mips_dump_tdep); |
c906108c | 8806 | |
8d5f9dcb DJ |
8807 | mips_pdr_data = register_objfile_data (); |
8808 | ||
4eb0ad19 DJ |
8809 | /* Create feature sets with the appropriate properties. The values |
8810 | are not important. */ | |
8811 | mips_tdesc_gp32 = allocate_target_description (); | |
8812 | set_tdesc_property (mips_tdesc_gp32, PROPERTY_GP32, ""); | |
8813 | ||
8814 | mips_tdesc_gp64 = allocate_target_description (); | |
8815 | set_tdesc_property (mips_tdesc_gp64, PROPERTY_GP64, ""); | |
8816 | ||
025bb325 | 8817 | /* Add root prefix command for all "set mips"/"show mips" commands. */ |
a5ea2558 | 8818 | add_prefix_cmd ("mips", no_class, set_mips_command, |
1bedd215 | 8819 | _("Various MIPS specific commands."), |
a5ea2558 AC |
8820 | &setmipscmdlist, "set mips ", 0, &setlist); |
8821 | ||
8822 | add_prefix_cmd ("mips", no_class, show_mips_command, | |
1bedd215 | 8823 | _("Various MIPS specific commands."), |
a5ea2558 AC |
8824 | &showmipscmdlist, "show mips ", 0, &showlist); |
8825 | ||
025bb325 | 8826 | /* Allow the user to override the ABI. */ |
7ab04401 AC |
8827 | add_setshow_enum_cmd ("abi", class_obscure, mips_abi_strings, |
8828 | &mips_abi_string, _("\ | |
8829 | Set the MIPS ABI used by this program."), _("\ | |
8830 | Show the MIPS ABI used by this program."), _("\ | |
8831 | This option can be set to one of:\n\ | |
8832 | auto - the default ABI associated with the current binary\n\ | |
8833 | o32\n\ | |
8834 | o64\n\ | |
8835 | n32\n\ | |
8836 | n64\n\ | |
8837 | eabi32\n\ | |
8838 | eabi64"), | |
8839 | mips_abi_update, | |
8840 | show_mips_abi, | |
8841 | &setmipscmdlist, &showmipscmdlist); | |
2e4ebe70 | 8842 | |
4cc0665f MR |
8843 | /* Allow the user to set the ISA to assume for compressed code if ELF |
8844 | file flags don't tell or there is no program file selected. This | |
8845 | setting is updated whenever unambiguous ELF file flags are interpreted, | |
8846 | and carried over to subsequent sessions. */ | |
8847 | add_setshow_enum_cmd ("compression", class_obscure, mips_compression_strings, | |
8848 | &mips_compression_string, _("\ | |
8849 | Set the compressed ISA encoding used by MIPS code."), _("\ | |
8850 | Show the compressed ISA encoding used by MIPS code."), _("\ | |
8851 | Select the compressed ISA encoding used in functions that have no symbol\n\ | |
8852 | information available. The encoding can be set to either of:\n\ | |
8853 | mips16\n\ | |
8854 | micromips\n\ | |
8855 | and is updated automatically from ELF file flags if available."), | |
8856 | mips_abi_update, | |
8857 | show_mips_compression, | |
8858 | &setmipscmdlist, &showmipscmdlist); | |
8859 | ||
c906108c SS |
8860 | /* Let the user turn off floating point and set the fence post for |
8861 | heuristic_proc_start. */ | |
8862 | ||
8863 | add_prefix_cmd ("mipsfpu", class_support, set_mipsfpu_command, | |
1bedd215 | 8864 | _("Set use of MIPS floating-point coprocessor."), |
c906108c SS |
8865 | &mipsfpulist, "set mipsfpu ", 0, &setlist); |
8866 | add_cmd ("single", class_support, set_mipsfpu_single_command, | |
1a966eab | 8867 | _("Select single-precision MIPS floating-point coprocessor."), |
c906108c SS |
8868 | &mipsfpulist); |
8869 | add_cmd ("double", class_support, set_mipsfpu_double_command, | |
1a966eab | 8870 | _("Select double-precision MIPS floating-point coprocessor."), |
c906108c SS |
8871 | &mipsfpulist); |
8872 | add_alias_cmd ("on", "double", class_support, 1, &mipsfpulist); | |
8873 | add_alias_cmd ("yes", "double", class_support, 1, &mipsfpulist); | |
8874 | add_alias_cmd ("1", "double", class_support, 1, &mipsfpulist); | |
8875 | add_cmd ("none", class_support, set_mipsfpu_none_command, | |
1a966eab | 8876 | _("Select no MIPS floating-point coprocessor."), &mipsfpulist); |
c906108c SS |
8877 | add_alias_cmd ("off", "none", class_support, 1, &mipsfpulist); |
8878 | add_alias_cmd ("no", "none", class_support, 1, &mipsfpulist); | |
8879 | add_alias_cmd ("0", "none", class_support, 1, &mipsfpulist); | |
8880 | add_cmd ("auto", class_support, set_mipsfpu_auto_command, | |
1a966eab | 8881 | _("Select MIPS floating-point coprocessor automatically."), |
c906108c SS |
8882 | &mipsfpulist); |
8883 | add_cmd ("mipsfpu", class_support, show_mipsfpu_command, | |
1a966eab | 8884 | _("Show current use of MIPS floating-point coprocessor target."), |
c906108c SS |
8885 | &showlist); |
8886 | ||
c906108c SS |
8887 | /* We really would like to have both "0" and "unlimited" work, but |
8888 | command.c doesn't deal with that. So make it a var_zinteger | |
8889 | because the user can always use "999999" or some such for unlimited. */ | |
6bcadd06 | 8890 | add_setshow_zinteger_cmd ("heuristic-fence-post", class_support, |
7915a72c AC |
8891 | &heuristic_fence_post, _("\ |
8892 | Set the distance searched for the start of a function."), _("\ | |
8893 | Show the distance searched for the start of a function."), _("\ | |
c906108c SS |
8894 | If you are debugging a stripped executable, GDB needs to search through the\n\ |
8895 | program for the start of a function. This command sets the distance of the\n\ | |
7915a72c | 8896 | search. The only need to set it is when debugging a stripped executable."), |
2c5b56ce | 8897 | reinit_frame_cache_sfunc, |
025bb325 MS |
8898 | NULL, /* FIXME: i18n: The distance searched for |
8899 | the start of a function is %s. */ | |
6bcadd06 | 8900 | &setlist, &showlist); |
c906108c SS |
8901 | |
8902 | /* Allow the user to control whether the upper bits of 64-bit | |
8903 | addresses should be zeroed. */ | |
7915a72c AC |
8904 | add_setshow_auto_boolean_cmd ("mask-address", no_class, |
8905 | &mask_address_var, _("\ | |
8906 | Set zeroing of upper 32 bits of 64-bit addresses."), _("\ | |
8907 | Show zeroing of upper 32 bits of 64-bit addresses."), _("\ | |
cce7e648 | 8908 | Use \"on\" to enable the masking, \"off\" to disable it and \"auto\" to\n\ |
7915a72c | 8909 | allow GDB to determine the correct value."), |
08546159 AC |
8910 | NULL, show_mask_address, |
8911 | &setmipscmdlist, &showmipscmdlist); | |
43e526b9 JM |
8912 | |
8913 | /* Allow the user to control the size of 32 bit registers within the | |
8914 | raw remote packet. */ | |
b3f42336 | 8915 | add_setshow_boolean_cmd ("remote-mips64-transfers-32bit-regs", class_obscure, |
7915a72c AC |
8916 | &mips64_transfers_32bit_regs_p, _("\ |
8917 | Set compatibility with 64-bit MIPS target that transfers 32-bit quantities."), | |
8918 | _("\ | |
8919 | Show compatibility with 64-bit MIPS target that transfers 32-bit quantities."), | |
8920 | _("\ | |
719ec221 AC |
8921 | Use \"on\" to enable backward compatibility with older MIPS 64 GDB+target\n\ |
8922 | that would transfer 32 bits for some registers (e.g. SR, FSR) and\n\ | |
7915a72c | 8923 | 64 bits for others. Use \"off\" to disable compatibility mode"), |
2c5b56ce | 8924 | set_mips64_transfers_32bit_regs, |
025bb325 MS |
8925 | NULL, /* FIXME: i18n: Compatibility with 64-bit |
8926 | MIPS target that transfers 32-bit | |
8927 | quantities is %s. */ | |
7915a72c | 8928 | &setlist, &showlist); |
9ace0497 | 8929 | |
025bb325 | 8930 | /* Debug this files internals. */ |
ccce17b0 YQ |
8931 | add_setshow_zuinteger_cmd ("mips", class_maintenance, |
8932 | &mips_debug, _("\ | |
7915a72c AC |
8933 | Set mips debugging."), _("\ |
8934 | Show mips debugging."), _("\ | |
8935 | When non-zero, mips specific debugging is enabled."), | |
ccce17b0 YQ |
8936 | NULL, |
8937 | NULL, /* FIXME: i18n: Mips debugging is | |
8938 | currently %s. */ | |
8939 | &setdebuglist, &showdebuglist); | |
c906108c | 8940 | } |