Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Target-dependent code for the MIPS architecture, for GDB, the GNU Debugger. |
bf64bfd6 | 2 | |
28e7fd62 | 3 | Copyright (C) 1988-2013 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" | |
24 | #include "gdb_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 | |
346 | symbols only; in particular synthetic symbols such as for PLT stubs | |
347 | have no ELF-private part at all. | |
5a89d8aa | 348 | |
4cc0665f MR |
349 | msymbol_is_mips16 and msymbol_is_micromips test the "special" bit |
350 | in a minimal symbol. */ | |
5a89d8aa | 351 | |
5a89d8aa | 352 | static void |
6d82d43b AC |
353 | mips_elf_make_msymbol_special (asymbol * sym, struct minimal_symbol *msym) |
354 | { | |
4cc0665f MR |
355 | elf_symbol_type *elfsym = (elf_symbol_type *) sym; |
356 | ||
357 | if ((sym->flags & BSF_SYNTHETIC) != 0) | |
358 | return; | |
359 | ||
360 | if (ELF_ST_IS_MICROMIPS (elfsym->internal_elf_sym.st_other)) | |
361 | MSYMBOL_TARGET_FLAG_2 (msym) = 1; | |
362 | else if (ELF_ST_IS_MIPS16 (elfsym->internal_elf_sym.st_other)) | |
363 | MSYMBOL_TARGET_FLAG_1 (msym) = 1; | |
364 | } | |
365 | ||
366 | /* Return one iff MSYM refers to standard ISA code. */ | |
367 | ||
368 | static int | |
369 | msymbol_is_mips (struct minimal_symbol *msym) | |
370 | { | |
371 | return !(MSYMBOL_TARGET_FLAG_1 (msym) | MSYMBOL_TARGET_FLAG_2 (msym)); | |
5a89d8aa MS |
372 | } |
373 | ||
4cc0665f MR |
374 | /* Return one iff MSYM refers to MIPS16 code. */ |
375 | ||
71b8ef93 | 376 | static int |
4cc0665f | 377 | msymbol_is_mips16 (struct minimal_symbol *msym) |
71b8ef93 | 378 | { |
b887350f | 379 | return MSYMBOL_TARGET_FLAG_1 (msym); |
71b8ef93 MS |
380 | } |
381 | ||
4cc0665f MR |
382 | /* Return one iff MSYM refers to microMIPS code. */ |
383 | ||
384 | static int | |
385 | msymbol_is_micromips (struct minimal_symbol *msym) | |
386 | { | |
387 | return MSYMBOL_TARGET_FLAG_2 (msym); | |
388 | } | |
389 | ||
88658117 AC |
390 | /* XFER a value from the big/little/left end of the register. |
391 | Depending on the size of the value it might occupy the entire | |
392 | register or just part of it. Make an allowance for this, aligning | |
393 | things accordingly. */ | |
394 | ||
395 | static void | |
ba32f989 DJ |
396 | mips_xfer_register (struct gdbarch *gdbarch, struct regcache *regcache, |
397 | int reg_num, int length, | |
870cd05e MK |
398 | enum bfd_endian endian, gdb_byte *in, |
399 | const gdb_byte *out, int buf_offset) | |
88658117 | 400 | { |
88658117 | 401 | int reg_offset = 0; |
72a155b4 UW |
402 | |
403 | gdb_assert (reg_num >= gdbarch_num_regs (gdbarch)); | |
cb1d2653 AC |
404 | /* Need to transfer the left or right part of the register, based on |
405 | the targets byte order. */ | |
88658117 AC |
406 | switch (endian) |
407 | { | |
408 | case BFD_ENDIAN_BIG: | |
72a155b4 | 409 | reg_offset = register_size (gdbarch, reg_num) - length; |
88658117 AC |
410 | break; |
411 | case BFD_ENDIAN_LITTLE: | |
412 | reg_offset = 0; | |
413 | break; | |
6d82d43b | 414 | case BFD_ENDIAN_UNKNOWN: /* Indicates no alignment. */ |
88658117 AC |
415 | reg_offset = 0; |
416 | break; | |
417 | default: | |
e2e0b3e5 | 418 | internal_error (__FILE__, __LINE__, _("bad switch")); |
88658117 AC |
419 | } |
420 | if (mips_debug) | |
cb1d2653 AC |
421 | fprintf_unfiltered (gdb_stderr, |
422 | "xfer $%d, reg offset %d, buf offset %d, length %d, ", | |
423 | reg_num, reg_offset, buf_offset, length); | |
88658117 AC |
424 | if (mips_debug && out != NULL) |
425 | { | |
426 | int i; | |
cb1d2653 | 427 | fprintf_unfiltered (gdb_stdlog, "out "); |
88658117 | 428 | for (i = 0; i < length; i++) |
cb1d2653 | 429 | fprintf_unfiltered (gdb_stdlog, "%02x", out[buf_offset + i]); |
88658117 AC |
430 | } |
431 | if (in != NULL) | |
6d82d43b AC |
432 | regcache_cooked_read_part (regcache, reg_num, reg_offset, length, |
433 | in + buf_offset); | |
88658117 | 434 | if (out != NULL) |
6d82d43b AC |
435 | regcache_cooked_write_part (regcache, reg_num, reg_offset, length, |
436 | out + buf_offset); | |
88658117 AC |
437 | if (mips_debug && in != NULL) |
438 | { | |
439 | int i; | |
cb1d2653 | 440 | fprintf_unfiltered (gdb_stdlog, "in "); |
88658117 | 441 | for (i = 0; i < length; i++) |
cb1d2653 | 442 | fprintf_unfiltered (gdb_stdlog, "%02x", in[buf_offset + i]); |
88658117 AC |
443 | } |
444 | if (mips_debug) | |
445 | fprintf_unfiltered (gdb_stdlog, "\n"); | |
446 | } | |
447 | ||
dd824b04 DJ |
448 | /* Determine if a MIPS3 or later cpu is operating in MIPS{1,2} FPU |
449 | compatiblity mode. A return value of 1 means that we have | |
450 | physical 64-bit registers, but should treat them as 32-bit registers. */ | |
451 | ||
452 | static int | |
9c9acae0 | 453 | mips2_fp_compat (struct frame_info *frame) |
dd824b04 | 454 | { |
72a155b4 | 455 | struct gdbarch *gdbarch = get_frame_arch (frame); |
dd824b04 DJ |
456 | /* MIPS1 and MIPS2 have only 32 bit FPRs, and the FR bit is not |
457 | meaningful. */ | |
72a155b4 | 458 | if (register_size (gdbarch, mips_regnum (gdbarch)->fp0) == 4) |
dd824b04 DJ |
459 | return 0; |
460 | ||
461 | #if 0 | |
462 | /* FIXME drow 2002-03-10: This is disabled until we can do it consistently, | |
463 | in all the places we deal with FP registers. PR gdb/413. */ | |
464 | /* Otherwise check the FR bit in the status register - it controls | |
465 | the FP compatiblity mode. If it is clear we are in compatibility | |
466 | mode. */ | |
9c9acae0 | 467 | if ((get_frame_register_unsigned (frame, MIPS_PS_REGNUM) & ST0_FR) == 0) |
dd824b04 DJ |
468 | return 1; |
469 | #endif | |
361d1df0 | 470 | |
dd824b04 DJ |
471 | return 0; |
472 | } | |
473 | ||
7a292a7a | 474 | #define VM_MIN_ADDRESS (CORE_ADDR)0x400000 |
c906108c | 475 | |
74ed0bb4 | 476 | static CORE_ADDR heuristic_proc_start (struct gdbarch *, CORE_ADDR); |
c906108c | 477 | |
a14ed312 | 478 | static void reinit_frame_cache_sfunc (char *, int, struct cmd_list_element *); |
c906108c | 479 | |
025bb325 | 480 | /* The list of available "set mips " and "show mips " commands. */ |
acdb74a0 AC |
481 | |
482 | static struct cmd_list_element *setmipscmdlist = NULL; | |
483 | static struct cmd_list_element *showmipscmdlist = NULL; | |
484 | ||
5e2e9765 KB |
485 | /* Integer registers 0 thru 31 are handled explicitly by |
486 | mips_register_name(). Processor specific registers 32 and above | |
8a9fc081 | 487 | are listed in the following tables. */ |
691c0433 | 488 | |
6d82d43b AC |
489 | enum |
490 | { NUM_MIPS_PROCESSOR_REGS = (90 - 32) }; | |
691c0433 AC |
491 | |
492 | /* Generic MIPS. */ | |
493 | ||
494 | static const char *mips_generic_reg_names[NUM_MIPS_PROCESSOR_REGS] = { | |
6d82d43b AC |
495 | "sr", "lo", "hi", "bad", "cause", "pc", |
496 | "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", | |
497 | "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", | |
498 | "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23", | |
499 | "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", | |
1faeff08 | 500 | "fsr", "fir", |
691c0433 AC |
501 | }; |
502 | ||
503 | /* Names of IDT R3041 registers. */ | |
504 | ||
505 | static const char *mips_r3041_reg_names[] = { | |
6d82d43b AC |
506 | "sr", "lo", "hi", "bad", "cause", "pc", |
507 | "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", | |
508 | "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", | |
509 | "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23", | |
510 | "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", | |
511 | "fsr", "fir", "", /*"fp" */ "", | |
512 | "", "", "bus", "ccfg", "", "", "", "", | |
513 | "", "", "port", "cmp", "", "", "epc", "prid", | |
691c0433 AC |
514 | }; |
515 | ||
516 | /* Names of tx39 registers. */ | |
517 | ||
518 | static const char *mips_tx39_reg_names[NUM_MIPS_PROCESSOR_REGS] = { | |
6d82d43b AC |
519 | "sr", "lo", "hi", "bad", "cause", "pc", |
520 | "", "", "", "", "", "", "", "", | |
521 | "", "", "", "", "", "", "", "", | |
522 | "", "", "", "", "", "", "", "", | |
523 | "", "", "", "", "", "", "", "", | |
524 | "", "", "", "", | |
525 | "", "", "", "", "", "", "", "", | |
1faeff08 | 526 | "", "", "config", "cache", "debug", "depc", "epc", |
691c0433 AC |
527 | }; |
528 | ||
529 | /* Names of IRIX registers. */ | |
530 | static const char *mips_irix_reg_names[NUM_MIPS_PROCESSOR_REGS] = { | |
6d82d43b AC |
531 | "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", |
532 | "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", | |
533 | "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23", | |
534 | "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", | |
535 | "pc", "cause", "bad", "hi", "lo", "fsr", "fir" | |
691c0433 AC |
536 | }; |
537 | ||
44099a67 | 538 | /* Names of registers with Linux kernels. */ |
1faeff08 MR |
539 | static const char *mips_linux_reg_names[NUM_MIPS_PROCESSOR_REGS] = { |
540 | "sr", "lo", "hi", "bad", "cause", "pc", | |
541 | "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", | |
542 | "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", | |
543 | "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23", | |
544 | "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", | |
545 | "fsr", "fir" | |
546 | }; | |
547 | ||
cce74817 | 548 | |
5e2e9765 | 549 | /* Return the name of the register corresponding to REGNO. */ |
5a89d8aa | 550 | static const char * |
d93859e2 | 551 | mips_register_name (struct gdbarch *gdbarch, int regno) |
cce74817 | 552 | { |
d93859e2 | 553 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
5e2e9765 KB |
554 | /* GPR names for all ABIs other than n32/n64. */ |
555 | static char *mips_gpr_names[] = { | |
6d82d43b AC |
556 | "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3", |
557 | "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", | |
558 | "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7", | |
559 | "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra", | |
5e2e9765 KB |
560 | }; |
561 | ||
562 | /* GPR names for n32 and n64 ABIs. */ | |
563 | static char *mips_n32_n64_gpr_names[] = { | |
6d82d43b AC |
564 | "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3", |
565 | "a4", "a5", "a6", "a7", "t0", "t1", "t2", "t3", | |
566 | "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7", | |
567 | "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra" | |
5e2e9765 KB |
568 | }; |
569 | ||
d93859e2 | 570 | enum mips_abi abi = mips_abi (gdbarch); |
5e2e9765 | 571 | |
f57d151a | 572 | /* Map [gdbarch_num_regs .. 2*gdbarch_num_regs) onto the raw registers, |
6229fbea HZ |
573 | but then don't make the raw register names visible. This (upper) |
574 | range of user visible register numbers are the pseudo-registers. | |
575 | ||
576 | This approach was adopted accommodate the following scenario: | |
577 | It is possible to debug a 64-bit device using a 32-bit | |
578 | programming model. In such instances, the raw registers are | |
579 | configured to be 64-bits wide, while the pseudo registers are | |
580 | configured to be 32-bits wide. The registers that the user | |
581 | sees - the pseudo registers - match the users expectations | |
582 | given the programming model being used. */ | |
d93859e2 UW |
583 | int rawnum = regno % gdbarch_num_regs (gdbarch); |
584 | if (regno < gdbarch_num_regs (gdbarch)) | |
a4b8ebc8 AC |
585 | return ""; |
586 | ||
5e2e9765 KB |
587 | /* The MIPS integer registers are always mapped from 0 to 31. The |
588 | names of the registers (which reflects the conventions regarding | |
589 | register use) vary depending on the ABI. */ | |
a4b8ebc8 | 590 | if (0 <= rawnum && rawnum < 32) |
5e2e9765 KB |
591 | { |
592 | if (abi == MIPS_ABI_N32 || abi == MIPS_ABI_N64) | |
a4b8ebc8 | 593 | return mips_n32_n64_gpr_names[rawnum]; |
5e2e9765 | 594 | else |
a4b8ebc8 | 595 | return mips_gpr_names[rawnum]; |
5e2e9765 | 596 | } |
d93859e2 UW |
597 | else if (tdesc_has_registers (gdbarch_target_desc (gdbarch))) |
598 | return tdesc_register_name (gdbarch, rawnum); | |
599 | else if (32 <= rawnum && rawnum < gdbarch_num_regs (gdbarch)) | |
691c0433 AC |
600 | { |
601 | gdb_assert (rawnum - 32 < NUM_MIPS_PROCESSOR_REGS); | |
1faeff08 MR |
602 | if (tdep->mips_processor_reg_names[rawnum - 32]) |
603 | return tdep->mips_processor_reg_names[rawnum - 32]; | |
604 | return ""; | |
691c0433 | 605 | } |
5e2e9765 KB |
606 | else |
607 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 608 | _("mips_register_name: bad register number %d"), rawnum); |
cce74817 | 609 | } |
5e2e9765 | 610 | |
a4b8ebc8 | 611 | /* Return the groups that a MIPS register can be categorised into. */ |
c5aa993b | 612 | |
a4b8ebc8 AC |
613 | static int |
614 | mips_register_reggroup_p (struct gdbarch *gdbarch, int regnum, | |
615 | struct reggroup *reggroup) | |
616 | { | |
617 | int vector_p; | |
618 | int float_p; | |
619 | int raw_p; | |
72a155b4 UW |
620 | int rawnum = regnum % gdbarch_num_regs (gdbarch); |
621 | int pseudo = regnum / gdbarch_num_regs (gdbarch); | |
a4b8ebc8 AC |
622 | if (reggroup == all_reggroup) |
623 | return pseudo; | |
624 | vector_p = TYPE_VECTOR (register_type (gdbarch, regnum)); | |
625 | float_p = TYPE_CODE (register_type (gdbarch, regnum)) == TYPE_CODE_FLT; | |
626 | /* FIXME: cagney/2003-04-13: Can't yet use gdbarch_num_regs | |
627 | (gdbarch), as not all architectures are multi-arch. */ | |
72a155b4 UW |
628 | raw_p = rawnum < gdbarch_num_regs (gdbarch); |
629 | if (gdbarch_register_name (gdbarch, regnum) == NULL | |
630 | || gdbarch_register_name (gdbarch, regnum)[0] == '\0') | |
a4b8ebc8 AC |
631 | return 0; |
632 | if (reggroup == float_reggroup) | |
633 | return float_p && pseudo; | |
634 | if (reggroup == vector_reggroup) | |
635 | return vector_p && pseudo; | |
636 | if (reggroup == general_reggroup) | |
637 | return (!vector_p && !float_p) && pseudo; | |
638 | /* Save the pseudo registers. Need to make certain that any code | |
639 | extracting register values from a saved register cache also uses | |
640 | pseudo registers. */ | |
641 | if (reggroup == save_reggroup) | |
642 | return raw_p && pseudo; | |
643 | /* Restore the same pseudo register. */ | |
644 | if (reggroup == restore_reggroup) | |
645 | return raw_p && pseudo; | |
6d82d43b | 646 | return 0; |
a4b8ebc8 AC |
647 | } |
648 | ||
f8b73d13 DJ |
649 | /* Return the groups that a MIPS register can be categorised into. |
650 | This version is only used if we have a target description which | |
651 | describes real registers (and their groups). */ | |
652 | ||
653 | static int | |
654 | mips_tdesc_register_reggroup_p (struct gdbarch *gdbarch, int regnum, | |
655 | struct reggroup *reggroup) | |
656 | { | |
657 | int rawnum = regnum % gdbarch_num_regs (gdbarch); | |
658 | int pseudo = regnum / gdbarch_num_regs (gdbarch); | |
659 | int ret; | |
660 | ||
661 | /* Only save, restore, and display the pseudo registers. Need to | |
662 | make certain that any code extracting register values from a | |
663 | saved register cache also uses pseudo registers. | |
664 | ||
665 | Note: saving and restoring the pseudo registers is slightly | |
666 | strange; if we have 64 bits, we should save and restore all | |
667 | 64 bits. But this is hard and has little benefit. */ | |
668 | if (!pseudo) | |
669 | return 0; | |
670 | ||
671 | ret = tdesc_register_in_reggroup_p (gdbarch, rawnum, reggroup); | |
672 | if (ret != -1) | |
673 | return ret; | |
674 | ||
675 | return mips_register_reggroup_p (gdbarch, regnum, reggroup); | |
676 | } | |
677 | ||
a4b8ebc8 | 678 | /* Map the symbol table registers which live in the range [1 * |
f57d151a | 679 | gdbarch_num_regs .. 2 * gdbarch_num_regs) back onto the corresponding raw |
47ebcfbe | 680 | registers. Take care of alignment and size problems. */ |
c5aa993b | 681 | |
05d1431c | 682 | static enum register_status |
a4b8ebc8 | 683 | mips_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache, |
47a35522 | 684 | int cookednum, gdb_byte *buf) |
a4b8ebc8 | 685 | { |
72a155b4 UW |
686 | int rawnum = cookednum % gdbarch_num_regs (gdbarch); |
687 | gdb_assert (cookednum >= gdbarch_num_regs (gdbarch) | |
688 | && cookednum < 2 * gdbarch_num_regs (gdbarch)); | |
47ebcfbe | 689 | if (register_size (gdbarch, rawnum) == register_size (gdbarch, cookednum)) |
05d1431c | 690 | return regcache_raw_read (regcache, rawnum, buf); |
6d82d43b AC |
691 | else if (register_size (gdbarch, rawnum) > |
692 | register_size (gdbarch, cookednum)) | |
47ebcfbe | 693 | { |
8bdf35dc | 694 | if (gdbarch_tdep (gdbarch)->mips64_transfers_32bit_regs_p) |
05d1431c | 695 | return regcache_raw_read_part (regcache, rawnum, 0, 4, buf); |
47ebcfbe | 696 | else |
8bdf35dc KB |
697 | { |
698 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); | |
699 | LONGEST regval; | |
05d1431c PA |
700 | enum register_status status; |
701 | ||
702 | status = regcache_raw_read_signed (regcache, rawnum, ®val); | |
703 | if (status == REG_VALID) | |
704 | store_signed_integer (buf, 4, byte_order, regval); | |
705 | return status; | |
8bdf35dc | 706 | } |
47ebcfbe AC |
707 | } |
708 | else | |
e2e0b3e5 | 709 | internal_error (__FILE__, __LINE__, _("bad register size")); |
a4b8ebc8 AC |
710 | } |
711 | ||
712 | static void | |
6d82d43b AC |
713 | mips_pseudo_register_write (struct gdbarch *gdbarch, |
714 | struct regcache *regcache, int cookednum, | |
47a35522 | 715 | const gdb_byte *buf) |
a4b8ebc8 | 716 | { |
72a155b4 UW |
717 | int rawnum = cookednum % gdbarch_num_regs (gdbarch); |
718 | gdb_assert (cookednum >= gdbarch_num_regs (gdbarch) | |
719 | && cookednum < 2 * gdbarch_num_regs (gdbarch)); | |
47ebcfbe | 720 | if (register_size (gdbarch, rawnum) == register_size (gdbarch, cookednum)) |
de38af99 | 721 | regcache_raw_write (regcache, rawnum, buf); |
6d82d43b AC |
722 | else if (register_size (gdbarch, rawnum) > |
723 | register_size (gdbarch, cookednum)) | |
47ebcfbe | 724 | { |
8bdf35dc | 725 | if (gdbarch_tdep (gdbarch)->mips64_transfers_32bit_regs_p) |
47ebcfbe AC |
726 | regcache_raw_write_part (regcache, rawnum, 0, 4, buf); |
727 | else | |
8bdf35dc KB |
728 | { |
729 | /* Sign extend the shortened version of the register prior | |
730 | to placing it in the raw register. This is required for | |
731 | some mips64 parts in order to avoid unpredictable behavior. */ | |
732 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); | |
733 | LONGEST regval = extract_signed_integer (buf, 4, byte_order); | |
734 | regcache_raw_write_signed (regcache, rawnum, regval); | |
735 | } | |
47ebcfbe AC |
736 | } |
737 | else | |
e2e0b3e5 | 738 | internal_error (__FILE__, __LINE__, _("bad register size")); |
a4b8ebc8 | 739 | } |
c5aa993b | 740 | |
175ff332 HZ |
741 | static int |
742 | mips_ax_pseudo_register_collect (struct gdbarch *gdbarch, | |
743 | struct agent_expr *ax, int reg) | |
744 | { | |
745 | int rawnum = reg % gdbarch_num_regs (gdbarch); | |
746 | gdb_assert (reg >= gdbarch_num_regs (gdbarch) | |
747 | && reg < 2 * gdbarch_num_regs (gdbarch)); | |
748 | ||
749 | ax_reg_mask (ax, rawnum); | |
750 | ||
751 | return 0; | |
752 | } | |
753 | ||
754 | static int | |
755 | mips_ax_pseudo_register_push_stack (struct gdbarch *gdbarch, | |
756 | struct agent_expr *ax, int reg) | |
757 | { | |
758 | int rawnum = reg % gdbarch_num_regs (gdbarch); | |
759 | gdb_assert (reg >= gdbarch_num_regs (gdbarch) | |
760 | && reg < 2 * gdbarch_num_regs (gdbarch)); | |
761 | if (register_size (gdbarch, rawnum) >= register_size (gdbarch, reg)) | |
762 | { | |
763 | ax_reg (ax, rawnum); | |
764 | ||
765 | if (register_size (gdbarch, rawnum) > register_size (gdbarch, reg)) | |
766 | { | |
767 | if (!gdbarch_tdep (gdbarch)->mips64_transfers_32bit_regs_p | |
768 | || gdbarch_byte_order (gdbarch) != BFD_ENDIAN_BIG) | |
769 | { | |
770 | ax_const_l (ax, 32); | |
771 | ax_simple (ax, aop_lsh); | |
772 | } | |
773 | ax_const_l (ax, 32); | |
774 | ax_simple (ax, aop_rsh_signed); | |
775 | } | |
776 | } | |
777 | else | |
778 | internal_error (__FILE__, __LINE__, _("bad register size")); | |
779 | ||
780 | return 0; | |
781 | } | |
782 | ||
4cc0665f | 783 | /* Table to translate 3-bit register field to actual register number. */ |
d467df4e | 784 | static const signed char mips_reg3_to_reg[8] = { 16, 17, 2, 3, 4, 5, 6, 7 }; |
c906108c SS |
785 | |
786 | /* Heuristic_proc_start may hunt through the text section for a long | |
787 | time across a 2400 baud serial line. Allows the user to limit this | |
788 | search. */ | |
789 | ||
44096aee | 790 | static int heuristic_fence_post = 0; |
c906108c | 791 | |
46cd78fb | 792 | /* Number of bytes of storage in the actual machine representation for |
719ec221 AC |
793 | register N. NOTE: This defines the pseudo register type so need to |
794 | rebuild the architecture vector. */ | |
43e526b9 JM |
795 | |
796 | static int mips64_transfers_32bit_regs_p = 0; | |
797 | ||
719ec221 AC |
798 | static void |
799 | set_mips64_transfers_32bit_regs (char *args, int from_tty, | |
800 | struct cmd_list_element *c) | |
43e526b9 | 801 | { |
719ec221 AC |
802 | struct gdbarch_info info; |
803 | gdbarch_info_init (&info); | |
804 | /* FIXME: cagney/2003-11-15: Should be setting a field in "info" | |
805 | instead of relying on globals. Doing that would let generic code | |
806 | handle the search for this specific architecture. */ | |
807 | if (!gdbarch_update_p (info)) | |
a4b8ebc8 | 808 | { |
719ec221 | 809 | mips64_transfers_32bit_regs_p = 0; |
8a3fe4f8 | 810 | error (_("32-bit compatibility mode not supported")); |
a4b8ebc8 | 811 | } |
a4b8ebc8 AC |
812 | } |
813 | ||
47ebcfbe | 814 | /* Convert to/from a register and the corresponding memory value. */ |
43e526b9 | 815 | |
ee51a8c7 KB |
816 | /* This predicate tests for the case of an 8 byte floating point |
817 | value that is being transferred to or from a pair of floating point | |
818 | registers each of which are (or are considered to be) only 4 bytes | |
819 | wide. */ | |
ff2e87ac | 820 | static int |
ee51a8c7 KB |
821 | mips_convert_register_float_case_p (struct gdbarch *gdbarch, int regnum, |
822 | struct type *type) | |
ff2e87ac | 823 | { |
0abe36f5 MD |
824 | return (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG |
825 | && register_size (gdbarch, regnum) == 4 | |
004159a2 | 826 | && mips_float_register_p (gdbarch, regnum) |
6d82d43b | 827 | && TYPE_CODE (type) == TYPE_CODE_FLT && TYPE_LENGTH (type) == 8); |
ff2e87ac AC |
828 | } |
829 | ||
ee51a8c7 KB |
830 | /* This predicate tests for the case of a value of less than 8 |
831 | bytes in width that is being transfered to or from an 8 byte | |
832 | general purpose register. */ | |
833 | static int | |
834 | mips_convert_register_gpreg_case_p (struct gdbarch *gdbarch, int regnum, | |
835 | struct type *type) | |
836 | { | |
837 | int num_regs = gdbarch_num_regs (gdbarch); | |
838 | ||
839 | return (register_size (gdbarch, regnum) == 8 | |
840 | && regnum % num_regs > 0 && regnum % num_regs < 32 | |
841 | && TYPE_LENGTH (type) < 8); | |
842 | } | |
843 | ||
844 | static int | |
025bb325 MS |
845 | mips_convert_register_p (struct gdbarch *gdbarch, |
846 | int regnum, struct type *type) | |
ee51a8c7 | 847 | { |
eaa05d59 MR |
848 | return (mips_convert_register_float_case_p (gdbarch, regnum, type) |
849 | || mips_convert_register_gpreg_case_p (gdbarch, regnum, type)); | |
ee51a8c7 KB |
850 | } |
851 | ||
8dccd430 | 852 | static int |
ff2e87ac | 853 | mips_register_to_value (struct frame_info *frame, int regnum, |
8dccd430 PA |
854 | struct type *type, gdb_byte *to, |
855 | int *optimizedp, int *unavailablep) | |
102182a9 | 856 | { |
ee51a8c7 KB |
857 | struct gdbarch *gdbarch = get_frame_arch (frame); |
858 | ||
859 | if (mips_convert_register_float_case_p (gdbarch, regnum, type)) | |
860 | { | |
861 | get_frame_register (frame, regnum + 0, to + 4); | |
862 | get_frame_register (frame, regnum + 1, to + 0); | |
8dccd430 PA |
863 | |
864 | if (!get_frame_register_bytes (frame, regnum + 0, 0, 4, to + 4, | |
865 | optimizedp, unavailablep)) | |
866 | return 0; | |
867 | ||
868 | if (!get_frame_register_bytes (frame, regnum + 1, 0, 4, to + 0, | |
869 | optimizedp, unavailablep)) | |
870 | return 0; | |
871 | *optimizedp = *unavailablep = 0; | |
872 | return 1; | |
ee51a8c7 KB |
873 | } |
874 | else if (mips_convert_register_gpreg_case_p (gdbarch, regnum, type)) | |
875 | { | |
876 | int len = TYPE_LENGTH (type); | |
8dccd430 PA |
877 | CORE_ADDR offset; |
878 | ||
879 | offset = gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG ? 8 - len : 0; | |
880 | if (!get_frame_register_bytes (frame, regnum, offset, len, to, | |
881 | optimizedp, unavailablep)) | |
882 | return 0; | |
883 | ||
884 | *optimizedp = *unavailablep = 0; | |
885 | return 1; | |
ee51a8c7 KB |
886 | } |
887 | else | |
888 | { | |
889 | internal_error (__FILE__, __LINE__, | |
890 | _("mips_register_to_value: unrecognized case")); | |
891 | } | |
102182a9 MS |
892 | } |
893 | ||
42c466d7 | 894 | static void |
ff2e87ac | 895 | mips_value_to_register (struct frame_info *frame, int regnum, |
47a35522 | 896 | struct type *type, const gdb_byte *from) |
102182a9 | 897 | { |
ee51a8c7 KB |
898 | struct gdbarch *gdbarch = get_frame_arch (frame); |
899 | ||
900 | if (mips_convert_register_float_case_p (gdbarch, regnum, type)) | |
901 | { | |
902 | put_frame_register (frame, regnum + 0, from + 4); | |
903 | put_frame_register (frame, regnum + 1, from + 0); | |
904 | } | |
905 | else if (mips_convert_register_gpreg_case_p (gdbarch, regnum, type)) | |
906 | { | |
907 | gdb_byte fill[8]; | |
908 | int len = TYPE_LENGTH (type); | |
909 | ||
910 | /* Sign extend values, irrespective of type, that are stored to | |
911 | a 64-bit general purpose register. (32-bit unsigned values | |
912 | are stored as signed quantities within a 64-bit register. | |
913 | When performing an operation, in compiled code, that combines | |
914 | a 32-bit unsigned value with a signed 64-bit value, a type | |
915 | conversion is first performed that zeroes out the high 32 bits.) */ | |
916 | if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) | |
917 | { | |
918 | if (from[0] & 0x80) | |
919 | store_signed_integer (fill, 8, BFD_ENDIAN_BIG, -1); | |
920 | else | |
921 | store_signed_integer (fill, 8, BFD_ENDIAN_BIG, 0); | |
922 | put_frame_register_bytes (frame, regnum, 0, 8 - len, fill); | |
923 | put_frame_register_bytes (frame, regnum, 8 - len, len, from); | |
924 | } | |
925 | else | |
926 | { | |
927 | if (from[len-1] & 0x80) | |
928 | store_signed_integer (fill, 8, BFD_ENDIAN_LITTLE, -1); | |
929 | else | |
930 | store_signed_integer (fill, 8, BFD_ENDIAN_LITTLE, 0); | |
931 | put_frame_register_bytes (frame, regnum, 0, len, from); | |
932 | put_frame_register_bytes (frame, regnum, len, 8 - len, fill); | |
933 | } | |
934 | } | |
935 | else | |
936 | { | |
937 | internal_error (__FILE__, __LINE__, | |
938 | _("mips_value_to_register: unrecognized case")); | |
939 | } | |
102182a9 MS |
940 | } |
941 | ||
a4b8ebc8 AC |
942 | /* Return the GDB type object for the "standard" data type of data in |
943 | register REG. */ | |
78fde5f8 KB |
944 | |
945 | static struct type * | |
a4b8ebc8 AC |
946 | mips_register_type (struct gdbarch *gdbarch, int regnum) |
947 | { | |
72a155b4 | 948 | gdb_assert (regnum >= 0 && regnum < 2 * gdbarch_num_regs (gdbarch)); |
004159a2 | 949 | if (mips_float_register_p (gdbarch, regnum)) |
a6425924 | 950 | { |
5ef80fb0 | 951 | /* The floating-point registers raw, or cooked, always match |
1b13c4f6 | 952 | mips_isa_regsize(), and also map 1:1, byte for byte. */ |
8da61cc4 | 953 | if (mips_isa_regsize (gdbarch) == 4) |
27067745 | 954 | return builtin_type (gdbarch)->builtin_float; |
8da61cc4 | 955 | else |
27067745 | 956 | return builtin_type (gdbarch)->builtin_double; |
a6425924 | 957 | } |
72a155b4 | 958 | else if (regnum < gdbarch_num_regs (gdbarch)) |
d5ac5a39 AC |
959 | { |
960 | /* The raw or ISA registers. These are all sized according to | |
961 | the ISA regsize. */ | |
962 | if (mips_isa_regsize (gdbarch) == 4) | |
df4df182 | 963 | return builtin_type (gdbarch)->builtin_int32; |
d5ac5a39 | 964 | else |
df4df182 | 965 | return builtin_type (gdbarch)->builtin_int64; |
d5ac5a39 | 966 | } |
78fde5f8 | 967 | else |
d5ac5a39 | 968 | { |
1faeff08 MR |
969 | int rawnum = regnum - gdbarch_num_regs (gdbarch); |
970 | ||
d5ac5a39 AC |
971 | /* The cooked or ABI registers. These are sized according to |
972 | the ABI (with a few complications). */ | |
1faeff08 MR |
973 | if (rawnum == mips_regnum (gdbarch)->fp_control_status |
974 | || rawnum == mips_regnum (gdbarch)->fp_implementation_revision) | |
975 | return builtin_type (gdbarch)->builtin_int32; | |
976 | else if (gdbarch_osabi (gdbarch) != GDB_OSABI_IRIX | |
977 | && gdbarch_osabi (gdbarch) != GDB_OSABI_LINUX | |
978 | && rawnum >= MIPS_FIRST_EMBED_REGNUM | |
979 | && rawnum <= MIPS_LAST_EMBED_REGNUM) | |
d5ac5a39 AC |
980 | /* The pseudo/cooked view of the embedded registers is always |
981 | 32-bit. The raw view is handled below. */ | |
df4df182 | 982 | return builtin_type (gdbarch)->builtin_int32; |
d5ac5a39 AC |
983 | else if (gdbarch_tdep (gdbarch)->mips64_transfers_32bit_regs_p) |
984 | /* The target, while possibly using a 64-bit register buffer, | |
985 | is only transfering 32-bits of each integer register. | |
986 | Reflect this in the cooked/pseudo (ABI) register value. */ | |
df4df182 | 987 | return builtin_type (gdbarch)->builtin_int32; |
d5ac5a39 AC |
988 | else if (mips_abi_regsize (gdbarch) == 4) |
989 | /* The ABI is restricted to 32-bit registers (the ISA could be | |
990 | 32- or 64-bit). */ | |
df4df182 | 991 | return builtin_type (gdbarch)->builtin_int32; |
d5ac5a39 AC |
992 | else |
993 | /* 64-bit ABI. */ | |
df4df182 | 994 | return builtin_type (gdbarch)->builtin_int64; |
d5ac5a39 | 995 | } |
78fde5f8 KB |
996 | } |
997 | ||
f8b73d13 DJ |
998 | /* Return the GDB type for the pseudo register REGNUM, which is the |
999 | ABI-level view. This function is only called if there is a target | |
1000 | description which includes registers, so we know precisely the | |
1001 | types of hardware registers. */ | |
1002 | ||
1003 | static struct type * | |
1004 | mips_pseudo_register_type (struct gdbarch *gdbarch, int regnum) | |
1005 | { | |
1006 | const int num_regs = gdbarch_num_regs (gdbarch); | |
f8b73d13 DJ |
1007 | int rawnum = regnum % num_regs; |
1008 | struct type *rawtype; | |
1009 | ||
1010 | gdb_assert (regnum >= num_regs && regnum < 2 * num_regs); | |
1011 | ||
1012 | /* Absent registers are still absent. */ | |
1013 | rawtype = gdbarch_register_type (gdbarch, rawnum); | |
1014 | if (TYPE_LENGTH (rawtype) == 0) | |
1015 | return rawtype; | |
1016 | ||
de13fcf2 | 1017 | if (mips_float_register_p (gdbarch, rawnum)) |
f8b73d13 DJ |
1018 | /* Present the floating point registers however the hardware did; |
1019 | do not try to convert between FPU layouts. */ | |
1020 | return rawtype; | |
1021 | ||
f8b73d13 DJ |
1022 | /* Use pointer types for registers if we can. For n32 we can not, |
1023 | since we do not have a 64-bit pointer type. */ | |
0dfff4cb UW |
1024 | if (mips_abi_regsize (gdbarch) |
1025 | == TYPE_LENGTH (builtin_type (gdbarch)->builtin_data_ptr)) | |
f8b73d13 | 1026 | { |
1faeff08 MR |
1027 | if (rawnum == MIPS_SP_REGNUM |
1028 | || rawnum == mips_regnum (gdbarch)->badvaddr) | |
0dfff4cb | 1029 | return builtin_type (gdbarch)->builtin_data_ptr; |
1faeff08 | 1030 | else if (rawnum == mips_regnum (gdbarch)->pc) |
0dfff4cb | 1031 | return builtin_type (gdbarch)->builtin_func_ptr; |
f8b73d13 DJ |
1032 | } |
1033 | ||
1034 | if (mips_abi_regsize (gdbarch) == 4 && TYPE_LENGTH (rawtype) == 8 | |
1faeff08 MR |
1035 | && ((rawnum >= MIPS_ZERO_REGNUM && rawnum <= MIPS_PS_REGNUM) |
1036 | || rawnum == mips_regnum (gdbarch)->lo | |
1037 | || rawnum == mips_regnum (gdbarch)->hi | |
1038 | || rawnum == mips_regnum (gdbarch)->badvaddr | |
1039 | || rawnum == mips_regnum (gdbarch)->cause | |
1040 | || rawnum == mips_regnum (gdbarch)->pc | |
1041 | || (mips_regnum (gdbarch)->dspacc != -1 | |
1042 | && rawnum >= mips_regnum (gdbarch)->dspacc | |
1043 | && rawnum < mips_regnum (gdbarch)->dspacc + 6))) | |
df4df182 | 1044 | return builtin_type (gdbarch)->builtin_int32; |
f8b73d13 | 1045 | |
1faeff08 MR |
1046 | if (gdbarch_osabi (gdbarch) != GDB_OSABI_IRIX |
1047 | && gdbarch_osabi (gdbarch) != GDB_OSABI_LINUX | |
1048 | && rawnum >= MIPS_EMBED_FP0_REGNUM + 32 | |
1049 | && rawnum <= MIPS_LAST_EMBED_REGNUM) | |
1050 | { | |
1051 | /* The pseudo/cooked view of embedded registers is always | |
1052 | 32-bit, even if the target transfers 64-bit values for them. | |
1053 | New targets relying on XML descriptions should only transfer | |
1054 | the necessary 32 bits, but older versions of GDB expected 64, | |
1055 | so allow the target to provide 64 bits without interfering | |
1056 | with the displayed type. */ | |
1057 | return builtin_type (gdbarch)->builtin_int32; | |
1058 | } | |
1059 | ||
f8b73d13 DJ |
1060 | /* For all other registers, pass through the hardware type. */ |
1061 | return rawtype; | |
1062 | } | |
bcb0cc15 | 1063 | |
025bb325 | 1064 | /* Should the upper word of 64-bit addresses be zeroed? */ |
7f19b9a2 | 1065 | enum auto_boolean mask_address_var = AUTO_BOOLEAN_AUTO; |
4014092b AC |
1066 | |
1067 | static int | |
480d3dd2 | 1068 | mips_mask_address_p (struct gdbarch_tdep *tdep) |
4014092b AC |
1069 | { |
1070 | switch (mask_address_var) | |
1071 | { | |
7f19b9a2 | 1072 | case AUTO_BOOLEAN_TRUE: |
4014092b | 1073 | return 1; |
7f19b9a2 | 1074 | case AUTO_BOOLEAN_FALSE: |
4014092b AC |
1075 | return 0; |
1076 | break; | |
7f19b9a2 | 1077 | case AUTO_BOOLEAN_AUTO: |
480d3dd2 | 1078 | return tdep->default_mask_address_p; |
4014092b | 1079 | default: |
025bb325 MS |
1080 | internal_error (__FILE__, __LINE__, |
1081 | _("mips_mask_address_p: bad switch")); | |
4014092b | 1082 | return -1; |
361d1df0 | 1083 | } |
4014092b AC |
1084 | } |
1085 | ||
1086 | static void | |
08546159 AC |
1087 | show_mask_address (struct ui_file *file, int from_tty, |
1088 | struct cmd_list_element *c, const char *value) | |
4014092b | 1089 | { |
f5656ead | 1090 | struct gdbarch_tdep *tdep = gdbarch_tdep (target_gdbarch ()); |
08546159 AC |
1091 | |
1092 | deprecated_show_value_hack (file, from_tty, c, value); | |
4014092b AC |
1093 | switch (mask_address_var) |
1094 | { | |
7f19b9a2 | 1095 | case AUTO_BOOLEAN_TRUE: |
4014092b AC |
1096 | printf_filtered ("The 32 bit mips address mask is enabled\n"); |
1097 | break; | |
7f19b9a2 | 1098 | case AUTO_BOOLEAN_FALSE: |
4014092b AC |
1099 | printf_filtered ("The 32 bit mips address mask is disabled\n"); |
1100 | break; | |
7f19b9a2 | 1101 | case AUTO_BOOLEAN_AUTO: |
6d82d43b AC |
1102 | printf_filtered |
1103 | ("The 32 bit address mask is set automatically. Currently %s\n", | |
1104 | mips_mask_address_p (tdep) ? "enabled" : "disabled"); | |
4014092b AC |
1105 | break; |
1106 | default: | |
e2e0b3e5 | 1107 | internal_error (__FILE__, __LINE__, _("show_mask_address: bad switch")); |
4014092b | 1108 | break; |
361d1df0 | 1109 | } |
4014092b | 1110 | } |
c906108c | 1111 | |
4cc0665f MR |
1112 | /* Tell if the program counter value in MEMADDR is in a standard ISA |
1113 | function. */ | |
1114 | ||
1115 | int | |
1116 | mips_pc_is_mips (CORE_ADDR memaddr) | |
1117 | { | |
7cbd4a93 | 1118 | struct bound_minimal_symbol sym; |
4cc0665f MR |
1119 | |
1120 | /* Flags indicating that this is a MIPS16 or microMIPS function is | |
1121 | stored by elfread.c in the high bit of the info field. Use this | |
1122 | to decide if the function is standard MIPS. Otherwise if bit 0 | |
1123 | of the address is clear, then this is a standard MIPS function. */ | |
1124 | sym = lookup_minimal_symbol_by_pc (memaddr); | |
7cbd4a93 TT |
1125 | if (sym.minsym) |
1126 | return msymbol_is_mips (sym.minsym); | |
4cc0665f MR |
1127 | else |
1128 | return is_mips_addr (memaddr); | |
1129 | } | |
1130 | ||
c906108c SS |
1131 | /* Tell if the program counter value in MEMADDR is in a MIPS16 function. */ |
1132 | ||
0fe7e7c8 | 1133 | int |
4cc0665f | 1134 | mips_pc_is_mips16 (struct gdbarch *gdbarch, CORE_ADDR memaddr) |
c906108c | 1135 | { |
7cbd4a93 | 1136 | struct bound_minimal_symbol sym; |
c906108c | 1137 | |
91912e4d MR |
1138 | /* A flag indicating that this is a MIPS16 function is stored by |
1139 | elfread.c in the high bit of the info field. Use this to decide | |
4cc0665f MR |
1140 | if the function is MIPS16. Otherwise if bit 0 of the address is |
1141 | set, then ELF file flags will tell if this is a MIPS16 function. */ | |
1142 | sym = lookup_minimal_symbol_by_pc (memaddr); | |
7cbd4a93 TT |
1143 | if (sym.minsym) |
1144 | return msymbol_is_mips16 (sym.minsym); | |
4cc0665f MR |
1145 | else |
1146 | return is_mips16_addr (gdbarch, memaddr); | |
1147 | } | |
1148 | ||
1149 | /* Tell if the program counter value in MEMADDR is in a microMIPS function. */ | |
1150 | ||
1151 | int | |
1152 | mips_pc_is_micromips (struct gdbarch *gdbarch, CORE_ADDR memaddr) | |
1153 | { | |
7cbd4a93 | 1154 | struct bound_minimal_symbol sym; |
4cc0665f MR |
1155 | |
1156 | /* A flag indicating that this is a microMIPS function is stored by | |
1157 | elfread.c in the high bit of the info field. Use this to decide | |
1158 | if the function is microMIPS. Otherwise if bit 0 of the address | |
1159 | is set, then ELF file flags will tell if this is a microMIPS | |
1160 | function. */ | |
1161 | sym = lookup_minimal_symbol_by_pc (memaddr); | |
7cbd4a93 TT |
1162 | if (sym.minsym) |
1163 | return msymbol_is_micromips (sym.minsym); | |
4cc0665f MR |
1164 | else |
1165 | return is_micromips_addr (gdbarch, memaddr); | |
1166 | } | |
1167 | ||
1168 | /* Tell the ISA type of the function the program counter value in MEMADDR | |
1169 | is in. */ | |
1170 | ||
1171 | static enum mips_isa | |
1172 | mips_pc_isa (struct gdbarch *gdbarch, CORE_ADDR memaddr) | |
1173 | { | |
7cbd4a93 | 1174 | struct bound_minimal_symbol sym; |
4cc0665f MR |
1175 | |
1176 | /* A flag indicating that this is a MIPS16 or a microMIPS function | |
1177 | is stored by elfread.c in the high bit of the info field. Use | |
1178 | this to decide if the function is MIPS16 or microMIPS or normal | |
1179 | MIPS. Otherwise if bit 0 of the address is set, then ELF file | |
1180 | flags will tell if this is a MIPS16 or a microMIPS function. */ | |
c906108c | 1181 | sym = lookup_minimal_symbol_by_pc (memaddr); |
7cbd4a93 | 1182 | if (sym.minsym) |
4cc0665f | 1183 | { |
7cbd4a93 | 1184 | if (msymbol_is_micromips (sym.minsym)) |
4cc0665f | 1185 | return ISA_MICROMIPS; |
7cbd4a93 | 1186 | else if (msymbol_is_mips16 (sym.minsym)) |
4cc0665f MR |
1187 | return ISA_MIPS16; |
1188 | else | |
1189 | return ISA_MIPS; | |
1190 | } | |
c906108c | 1191 | else |
4cc0665f MR |
1192 | { |
1193 | if (is_mips_addr (memaddr)) | |
1194 | return ISA_MIPS; | |
1195 | else if (is_micromips_addr (gdbarch, memaddr)) | |
1196 | return ISA_MICROMIPS; | |
1197 | else | |
1198 | return ISA_MIPS16; | |
1199 | } | |
c906108c SS |
1200 | } |
1201 | ||
14132e89 MR |
1202 | /* Various MIPS16 thunk (aka stub or trampoline) names. */ |
1203 | ||
1204 | static const char mips_str_mips16_call_stub[] = "__mips16_call_stub_"; | |
1205 | static const char mips_str_mips16_ret_stub[] = "__mips16_ret_"; | |
1206 | static const char mips_str_call_fp_stub[] = "__call_stub_fp_"; | |
1207 | static const char mips_str_call_stub[] = "__call_stub_"; | |
1208 | static const char mips_str_fn_stub[] = "__fn_stub_"; | |
1209 | ||
1210 | /* This is used as a PIC thunk prefix. */ | |
1211 | ||
1212 | static const char mips_str_pic[] = ".pic."; | |
1213 | ||
1214 | /* Return non-zero if the PC is inside a call thunk (aka stub or | |
1215 | trampoline) that should be treated as a temporary frame. */ | |
1216 | ||
1217 | static int | |
1218 | mips_in_frame_stub (CORE_ADDR pc) | |
1219 | { | |
1220 | CORE_ADDR start_addr; | |
1221 | const char *name; | |
1222 | ||
1223 | /* Find the starting address of the function containing the PC. */ | |
1224 | if (find_pc_partial_function (pc, &name, &start_addr, NULL) == 0) | |
1225 | return 0; | |
1226 | ||
1227 | /* If the PC is in __mips16_call_stub_*, this is a call/return stub. */ | |
1228 | if (strncmp (name, mips_str_mips16_call_stub, | |
1229 | strlen (mips_str_mips16_call_stub)) == 0) | |
1230 | return 1; | |
1231 | /* If the PC is in __call_stub_*, this is a call/return or a call stub. */ | |
1232 | if (strncmp (name, mips_str_call_stub, strlen (mips_str_call_stub)) == 0) | |
1233 | return 1; | |
1234 | /* If the PC is in __fn_stub_*, this is a call stub. */ | |
1235 | if (strncmp (name, mips_str_fn_stub, strlen (mips_str_fn_stub)) == 0) | |
1236 | return 1; | |
1237 | ||
1238 | return 0; /* Not a stub. */ | |
1239 | } | |
1240 | ||
b2fa5097 | 1241 | /* MIPS believes that the PC has a sign extended value. Perhaps the |
025bb325 | 1242 | all registers should be sign extended for simplicity? */ |
6c997a34 AC |
1243 | |
1244 | static CORE_ADDR | |
61a1198a | 1245 | mips_read_pc (struct regcache *regcache) |
6c997a34 | 1246 | { |
8376de04 | 1247 | int regnum = gdbarch_pc_regnum (get_regcache_arch (regcache)); |
70242eb1 | 1248 | LONGEST pc; |
8376de04 | 1249 | |
61a1198a | 1250 | regcache_cooked_read_signed (regcache, regnum, &pc); |
4cc0665f MR |
1251 | if (is_compact_addr (pc)) |
1252 | pc = unmake_compact_addr (pc); | |
61a1198a | 1253 | return pc; |
b6cb9035 AC |
1254 | } |
1255 | ||
58dfe9ff AC |
1256 | static CORE_ADDR |
1257 | mips_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame) | |
1258 | { | |
14132e89 | 1259 | CORE_ADDR pc; |
930bd0e0 | 1260 | |
8376de04 | 1261 | pc = frame_unwind_register_signed (next_frame, gdbarch_pc_regnum (gdbarch)); |
4cc0665f MR |
1262 | if (is_compact_addr (pc)) |
1263 | pc = unmake_compact_addr (pc); | |
14132e89 MR |
1264 | /* macro/2012-04-20: This hack skips over MIPS16 call thunks as |
1265 | intermediate frames. In this case we can get the caller's address | |
1266 | from $ra, or if $ra contains an address within a thunk as well, then | |
1267 | it must be in the return path of __mips16_call_stub_{s,d}{f,c}_{0..10} | |
1268 | and thus the caller's address is in $s2. */ | |
1269 | if (frame_relative_level (next_frame) >= 0 && mips_in_frame_stub (pc)) | |
1270 | { | |
1271 | pc = frame_unwind_register_signed | |
1272 | (next_frame, gdbarch_num_regs (gdbarch) + MIPS_RA_REGNUM); | |
4cc0665f MR |
1273 | if (is_compact_addr (pc)) |
1274 | pc = unmake_compact_addr (pc); | |
14132e89 MR |
1275 | if (mips_in_frame_stub (pc)) |
1276 | { | |
1277 | pc = frame_unwind_register_signed | |
1278 | (next_frame, gdbarch_num_regs (gdbarch) + MIPS_S2_REGNUM); | |
4cc0665f MR |
1279 | if (is_compact_addr (pc)) |
1280 | pc = unmake_compact_addr (pc); | |
14132e89 MR |
1281 | } |
1282 | } | |
930bd0e0 | 1283 | return pc; |
edfae063 AC |
1284 | } |
1285 | ||
30244cd8 UW |
1286 | static CORE_ADDR |
1287 | mips_unwind_sp (struct gdbarch *gdbarch, struct frame_info *next_frame) | |
1288 | { | |
72a155b4 UW |
1289 | return frame_unwind_register_signed |
1290 | (next_frame, gdbarch_num_regs (gdbarch) + MIPS_SP_REGNUM); | |
30244cd8 UW |
1291 | } |
1292 | ||
b8a22b94 | 1293 | /* Assuming THIS_FRAME is a dummy, return the frame ID of that |
edfae063 AC |
1294 | dummy frame. The frame ID's base needs to match the TOS value |
1295 | saved by save_dummy_frame_tos(), and the PC match the dummy frame's | |
1296 | breakpoint. */ | |
1297 | ||
1298 | static struct frame_id | |
b8a22b94 | 1299 | mips_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame) |
edfae063 | 1300 | { |
f57d151a | 1301 | return frame_id_build |
b8a22b94 DJ |
1302 | (get_frame_register_signed (this_frame, |
1303 | gdbarch_num_regs (gdbarch) | |
1304 | + MIPS_SP_REGNUM), | |
1305 | get_frame_pc (this_frame)); | |
58dfe9ff AC |
1306 | } |
1307 | ||
5a439849 MR |
1308 | /* Implement the "write_pc" gdbarch method. */ |
1309 | ||
1310 | void | |
61a1198a | 1311 | mips_write_pc (struct regcache *regcache, CORE_ADDR pc) |
b6cb9035 | 1312 | { |
8376de04 MR |
1313 | int regnum = gdbarch_pc_regnum (get_regcache_arch (regcache)); |
1314 | ||
4cc0665f | 1315 | if (mips_pc_is_mips (pc)) |
930bd0e0 | 1316 | regcache_cooked_write_unsigned (regcache, regnum, pc); |
4cc0665f MR |
1317 | else |
1318 | regcache_cooked_write_unsigned (regcache, regnum, make_compact_addr (pc)); | |
6c997a34 | 1319 | } |
c906108c | 1320 | |
4cc0665f MR |
1321 | /* Fetch and return instruction from the specified location. Handle |
1322 | MIPS16/microMIPS as appropriate. */ | |
c906108c | 1323 | |
d37cca3d | 1324 | static ULONGEST |
4cc0665f MR |
1325 | mips_fetch_instruction (struct gdbarch *gdbarch, |
1326 | enum mips_isa isa, CORE_ADDR addr, int *statusp) | |
c906108c | 1327 | { |
e17a4113 | 1328 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
47a35522 | 1329 | gdb_byte buf[MIPS_INSN32_SIZE]; |
c906108c SS |
1330 | int instlen; |
1331 | int status; | |
1332 | ||
4cc0665f | 1333 | switch (isa) |
c906108c | 1334 | { |
4cc0665f MR |
1335 | case ISA_MICROMIPS: |
1336 | case ISA_MIPS16: | |
95ac2dcf | 1337 | instlen = MIPS_INSN16_SIZE; |
4cc0665f MR |
1338 | addr = unmake_compact_addr (addr); |
1339 | break; | |
1340 | case ISA_MIPS: | |
1341 | instlen = MIPS_INSN32_SIZE; | |
1342 | break; | |
1343 | default: | |
1344 | internal_error (__FILE__, __LINE__, _("invalid ISA")); | |
1345 | break; | |
c906108c | 1346 | } |
8defab1a | 1347 | status = target_read_memory (addr, buf, instlen); |
4cc0665f MR |
1348 | if (statusp != NULL) |
1349 | *statusp = status; | |
c906108c | 1350 | if (status) |
4cc0665f MR |
1351 | { |
1352 | if (statusp == NULL) | |
1353 | memory_error (status, addr); | |
1354 | return 0; | |
1355 | } | |
e17a4113 | 1356 | return extract_unsigned_integer (buf, instlen, byte_order); |
c906108c SS |
1357 | } |
1358 | ||
025bb325 | 1359 | /* These are the fields of 32 bit mips instructions. */ |
e135b889 DJ |
1360 | #define mips32_op(x) (x >> 26) |
1361 | #define itype_op(x) (x >> 26) | |
1362 | #define itype_rs(x) ((x >> 21) & 0x1f) | |
c906108c | 1363 | #define itype_rt(x) ((x >> 16) & 0x1f) |
e135b889 | 1364 | #define itype_immediate(x) (x & 0xffff) |
c906108c | 1365 | |
e135b889 DJ |
1366 | #define jtype_op(x) (x >> 26) |
1367 | #define jtype_target(x) (x & 0x03ffffff) | |
c906108c | 1368 | |
e135b889 DJ |
1369 | #define rtype_op(x) (x >> 26) |
1370 | #define rtype_rs(x) ((x >> 21) & 0x1f) | |
1371 | #define rtype_rt(x) ((x >> 16) & 0x1f) | |
1372 | #define rtype_rd(x) ((x >> 11) & 0x1f) | |
1373 | #define rtype_shamt(x) ((x >> 6) & 0x1f) | |
1374 | #define rtype_funct(x) (x & 0x3f) | |
c906108c | 1375 | |
4cc0665f MR |
1376 | /* MicroMIPS instruction fields. */ |
1377 | #define micromips_op(x) ((x) >> 10) | |
1378 | ||
1379 | /* 16-bit/32-bit-high-part instruction formats, B and S refer to the lowest | |
1380 | bit and the size respectively of the field extracted. */ | |
1381 | #define b0s4_imm(x) ((x) & 0xf) | |
1382 | #define b0s5_imm(x) ((x) & 0x1f) | |
1383 | #define b0s5_reg(x) ((x) & 0x1f) | |
1384 | #define b0s7_imm(x) ((x) & 0x7f) | |
1385 | #define b0s10_imm(x) ((x) & 0x3ff) | |
1386 | #define b1s4_imm(x) (((x) >> 1) & 0xf) | |
1387 | #define b1s9_imm(x) (((x) >> 1) & 0x1ff) | |
1388 | #define b2s3_cc(x) (((x) >> 2) & 0x7) | |
1389 | #define b4s2_regl(x) (((x) >> 4) & 0x3) | |
1390 | #define b5s5_op(x) (((x) >> 5) & 0x1f) | |
1391 | #define b5s5_reg(x) (((x) >> 5) & 0x1f) | |
1392 | #define b6s4_op(x) (((x) >> 6) & 0xf) | |
1393 | #define b7s3_reg(x) (((x) >> 7) & 0x7) | |
1394 | ||
1395 | /* 32-bit instruction formats, B and S refer to the lowest bit and the size | |
1396 | respectively of the field extracted. */ | |
1397 | #define b0s6_op(x) ((x) & 0x3f) | |
1398 | #define b0s11_op(x) ((x) & 0x7ff) | |
1399 | #define b0s12_imm(x) ((x) & 0xfff) | |
1400 | #define b0s16_imm(x) ((x) & 0xffff) | |
1401 | #define b0s26_imm(x) ((x) & 0x3ffffff) | |
1402 | #define b6s10_ext(x) (((x) >> 6) & 0x3ff) | |
1403 | #define b11s5_reg(x) (((x) >> 11) & 0x1f) | |
1404 | #define b12s4_op(x) (((x) >> 12) & 0xf) | |
1405 | ||
1406 | /* Return the size in bytes of the instruction INSN encoded in the ISA | |
1407 | instruction set. */ | |
1408 | ||
1409 | static int | |
1410 | mips_insn_size (enum mips_isa isa, ULONGEST insn) | |
1411 | { | |
1412 | switch (isa) | |
1413 | { | |
1414 | case ISA_MICROMIPS: | |
1415 | if (micromips_op (insn) == 0x1f) | |
1416 | return 3 * MIPS_INSN16_SIZE; | |
1417 | else if (((micromips_op (insn) & 0x4) == 0x4) | |
1418 | || ((micromips_op (insn) & 0x7) == 0x0)) | |
1419 | return 2 * MIPS_INSN16_SIZE; | |
1420 | else | |
1421 | return MIPS_INSN16_SIZE; | |
1422 | case ISA_MIPS16: | |
1423 | if ((insn & 0xf800) == 0xf000) | |
1424 | return 2 * MIPS_INSN16_SIZE; | |
1425 | else | |
1426 | return MIPS_INSN16_SIZE; | |
1427 | case ISA_MIPS: | |
1428 | return MIPS_INSN32_SIZE; | |
1429 | } | |
1430 | internal_error (__FILE__, __LINE__, _("invalid ISA")); | |
1431 | } | |
1432 | ||
06987e64 MK |
1433 | static LONGEST |
1434 | mips32_relative_offset (ULONGEST inst) | |
c5aa993b | 1435 | { |
06987e64 | 1436 | return ((itype_immediate (inst) ^ 0x8000) - 0x8000) << 2; |
c906108c SS |
1437 | } |
1438 | ||
a385295e MR |
1439 | /* Determine the address of the next instruction executed after the INST |
1440 | floating condition branch instruction at PC. COUNT specifies the | |
1441 | number of the floating condition bits tested by the branch. */ | |
1442 | ||
1443 | static CORE_ADDR | |
1444 | mips32_bc1_pc (struct gdbarch *gdbarch, struct frame_info *frame, | |
1445 | ULONGEST inst, CORE_ADDR pc, int count) | |
1446 | { | |
1447 | int fcsr = mips_regnum (gdbarch)->fp_control_status; | |
1448 | int cnum = (itype_rt (inst) >> 2) & (count - 1); | |
1449 | int tf = itype_rt (inst) & 1; | |
1450 | int mask = (1 << count) - 1; | |
1451 | ULONGEST fcs; | |
1452 | int cond; | |
1453 | ||
1454 | if (fcsr == -1) | |
1455 | /* No way to handle; it'll most likely trap anyway. */ | |
1456 | return pc; | |
1457 | ||
1458 | fcs = get_frame_register_unsigned (frame, fcsr); | |
1459 | cond = ((fcs >> 24) & 0xfe) | ((fcs >> 23) & 0x01); | |
1460 | ||
1461 | if (((cond >> cnum) & mask) != mask * !tf) | |
1462 | pc += mips32_relative_offset (inst); | |
1463 | else | |
1464 | pc += 4; | |
1465 | ||
1466 | return pc; | |
1467 | } | |
1468 | ||
f94363d7 AP |
1469 | /* Return nonzero if the gdbarch is an Octeon series. */ |
1470 | ||
1471 | static int | |
1472 | is_octeon (struct gdbarch *gdbarch) | |
1473 | { | |
1474 | const struct bfd_arch_info *info = gdbarch_bfd_arch_info (gdbarch); | |
1475 | ||
1476 | return (info->mach == bfd_mach_mips_octeon | |
1477 | || info->mach == bfd_mach_mips_octeonp | |
1478 | || info->mach == bfd_mach_mips_octeon2); | |
1479 | } | |
1480 | ||
1481 | /* Return true if the OP represents the Octeon's BBIT instruction. */ | |
1482 | ||
1483 | static int | |
1484 | is_octeon_bbit_op (int op, struct gdbarch *gdbarch) | |
1485 | { | |
1486 | if (!is_octeon (gdbarch)) | |
1487 | return 0; | |
1488 | /* BBIT0 is encoded as LWC2: 110 010. */ | |
1489 | /* BBIT032 is encoded as LDC2: 110 110. */ | |
1490 | /* BBIT1 is encoded as SWC2: 111 010. */ | |
1491 | /* BBIT132 is encoded as SDC2: 111 110. */ | |
1492 | if (op == 50 || op == 54 || op == 58 || op == 62) | |
1493 | return 1; | |
1494 | return 0; | |
1495 | } | |
1496 | ||
1497 | ||
f49e4e6d MS |
1498 | /* Determine where to set a single step breakpoint while considering |
1499 | branch prediction. */ | |
78a59c2f | 1500 | |
5a89d8aa | 1501 | static CORE_ADDR |
0b1b3e42 | 1502 | mips32_next_pc (struct frame_info *frame, CORE_ADDR pc) |
c5aa993b | 1503 | { |
e17a4113 | 1504 | struct gdbarch *gdbarch = get_frame_arch (frame); |
c5aa993b JM |
1505 | unsigned long inst; |
1506 | int op; | |
4cc0665f | 1507 | inst = mips_fetch_instruction (gdbarch, ISA_MIPS, pc, NULL); |
4f5bcb50 | 1508 | op = itype_op (inst); |
025bb325 MS |
1509 | if ((inst & 0xe0000000) != 0) /* Not a special, jump or branch |
1510 | instruction. */ | |
c5aa993b | 1511 | { |
4f5bcb50 | 1512 | if (op >> 2 == 5) |
6d82d43b | 1513 | /* BEQL, BNEL, BLEZL, BGTZL: bits 0101xx */ |
c5aa993b | 1514 | { |
4f5bcb50 | 1515 | switch (op & 0x03) |
c906108c | 1516 | { |
e135b889 DJ |
1517 | case 0: /* BEQL */ |
1518 | goto equal_branch; | |
1519 | case 1: /* BNEL */ | |
1520 | goto neq_branch; | |
1521 | case 2: /* BLEZL */ | |
1522 | goto less_branch; | |
313628cc | 1523 | case 3: /* BGTZL */ |
e135b889 | 1524 | goto greater_branch; |
c5aa993b JM |
1525 | default: |
1526 | pc += 4; | |
c906108c SS |
1527 | } |
1528 | } | |
4f5bcb50 | 1529 | else if (op == 17 && itype_rs (inst) == 8) |
6d82d43b | 1530 | /* BC1F, BC1FL, BC1T, BC1TL: 010001 01000 */ |
a385295e | 1531 | pc = mips32_bc1_pc (gdbarch, frame, inst, pc + 4, 1); |
4f5bcb50 | 1532 | else if (op == 17 && itype_rs (inst) == 9 |
a385295e MR |
1533 | && (itype_rt (inst) & 2) == 0) |
1534 | /* BC1ANY2F, BC1ANY2T: 010001 01001 xxx0x */ | |
1535 | pc = mips32_bc1_pc (gdbarch, frame, inst, pc + 4, 2); | |
4f5bcb50 | 1536 | else if (op == 17 && itype_rs (inst) == 10 |
a385295e MR |
1537 | && (itype_rt (inst) & 2) == 0) |
1538 | /* BC1ANY4F, BC1ANY4T: 010001 01010 xxx0x */ | |
1539 | pc = mips32_bc1_pc (gdbarch, frame, inst, pc + 4, 4); | |
4f5bcb50 | 1540 | else if (op == 29) |
9e8da49c MR |
1541 | /* JALX: 011101 */ |
1542 | /* The new PC will be alternate mode. */ | |
1543 | { | |
1544 | unsigned long reg; | |
1545 | ||
1546 | reg = jtype_target (inst) << 2; | |
1547 | /* Add 1 to indicate 16-bit mode -- invert ISA mode. */ | |
1548 | pc = ((pc + 4) & ~(CORE_ADDR) 0x0fffffff) + reg + 1; | |
1549 | } | |
f94363d7 AP |
1550 | else if (is_octeon_bbit_op (op, gdbarch)) |
1551 | { | |
1552 | int bit, branch_if; | |
1553 | ||
1554 | branch_if = op == 58 || op == 62; | |
1555 | bit = itype_rt (inst); | |
1556 | ||
1557 | /* Take into account the *32 instructions. */ | |
1558 | if (op == 54 || op == 62) | |
1559 | bit += 32; | |
1560 | ||
1561 | if (((get_frame_register_signed (frame, | |
1562 | itype_rs (inst)) >> bit) & 1) | |
1563 | == branch_if) | |
1564 | pc += mips32_relative_offset (inst) + 4; | |
1565 | else | |
1566 | pc += 8; /* After the delay slot. */ | |
1567 | } | |
1568 | ||
c5aa993b | 1569 | else |
025bb325 | 1570 | pc += 4; /* Not a branch, next instruction is easy. */ |
c906108c SS |
1571 | } |
1572 | else | |
025bb325 | 1573 | { /* This gets way messy. */ |
c5aa993b | 1574 | |
025bb325 | 1575 | /* Further subdivide into SPECIAL, REGIMM and other. */ |
4f5bcb50 | 1576 | switch (op & 0x07) /* Extract bits 28,27,26. */ |
c906108c | 1577 | { |
c5aa993b JM |
1578 | case 0: /* SPECIAL */ |
1579 | op = rtype_funct (inst); | |
1580 | switch (op) | |
1581 | { | |
1582 | case 8: /* JR */ | |
1583 | case 9: /* JALR */ | |
025bb325 | 1584 | /* Set PC to that address. */ |
0b1b3e42 | 1585 | pc = get_frame_register_signed (frame, rtype_rs (inst)); |
c5aa993b | 1586 | break; |
e38d4e1a DJ |
1587 | case 12: /* SYSCALL */ |
1588 | { | |
1589 | struct gdbarch_tdep *tdep; | |
1590 | ||
1591 | tdep = gdbarch_tdep (get_frame_arch (frame)); | |
1592 | if (tdep->syscall_next_pc != NULL) | |
1593 | pc = tdep->syscall_next_pc (frame); | |
1594 | else | |
1595 | pc += 4; | |
1596 | } | |
1597 | break; | |
c5aa993b JM |
1598 | default: |
1599 | pc += 4; | |
1600 | } | |
1601 | ||
6d82d43b | 1602 | break; /* end SPECIAL */ |
025bb325 | 1603 | case 1: /* REGIMM */ |
c906108c | 1604 | { |
e135b889 DJ |
1605 | op = itype_rt (inst); /* branch condition */ |
1606 | switch (op) | |
c906108c | 1607 | { |
c5aa993b | 1608 | case 0: /* BLTZ */ |
e135b889 DJ |
1609 | case 2: /* BLTZL */ |
1610 | case 16: /* BLTZAL */ | |
c5aa993b | 1611 | case 18: /* BLTZALL */ |
c906108c | 1612 | less_branch: |
0b1b3e42 | 1613 | if (get_frame_register_signed (frame, itype_rs (inst)) < 0) |
c5aa993b JM |
1614 | pc += mips32_relative_offset (inst) + 4; |
1615 | else | |
1616 | pc += 8; /* after the delay slot */ | |
1617 | break; | |
e135b889 | 1618 | case 1: /* BGEZ */ |
c5aa993b JM |
1619 | case 3: /* BGEZL */ |
1620 | case 17: /* BGEZAL */ | |
1621 | case 19: /* BGEZALL */ | |
0b1b3e42 | 1622 | if (get_frame_register_signed (frame, itype_rs (inst)) >= 0) |
c5aa993b JM |
1623 | pc += mips32_relative_offset (inst) + 4; |
1624 | else | |
1625 | pc += 8; /* after the delay slot */ | |
1626 | break; | |
a385295e MR |
1627 | case 0x1c: /* BPOSGE32 */ |
1628 | case 0x1e: /* BPOSGE64 */ | |
1629 | pc += 4; | |
1630 | if (itype_rs (inst) == 0) | |
1631 | { | |
1632 | unsigned int pos = (op & 2) ? 64 : 32; | |
1633 | int dspctl = mips_regnum (gdbarch)->dspctl; | |
1634 | ||
1635 | if (dspctl == -1) | |
1636 | /* No way to handle; it'll most likely trap anyway. */ | |
1637 | break; | |
1638 | ||
1639 | if ((get_frame_register_unsigned (frame, | |
1640 | dspctl) & 0x7f) >= pos) | |
1641 | pc += mips32_relative_offset (inst); | |
1642 | else | |
1643 | pc += 4; | |
1644 | } | |
1645 | break; | |
e135b889 | 1646 | /* All of the other instructions in the REGIMM category */ |
c5aa993b JM |
1647 | default: |
1648 | pc += 4; | |
c906108c SS |
1649 | } |
1650 | } | |
6d82d43b | 1651 | break; /* end REGIMM */ |
c5aa993b JM |
1652 | case 2: /* J */ |
1653 | case 3: /* JAL */ | |
1654 | { | |
1655 | unsigned long reg; | |
1656 | reg = jtype_target (inst) << 2; | |
025bb325 | 1657 | /* Upper four bits get never changed... */ |
5b652102 | 1658 | pc = reg + ((pc + 4) & ~(CORE_ADDR) 0x0fffffff); |
c906108c | 1659 | } |
c5aa993b | 1660 | break; |
e135b889 | 1661 | case 4: /* BEQ, BEQL */ |
c5aa993b | 1662 | equal_branch: |
0b1b3e42 UW |
1663 | if (get_frame_register_signed (frame, itype_rs (inst)) == |
1664 | get_frame_register_signed (frame, itype_rt (inst))) | |
c5aa993b JM |
1665 | pc += mips32_relative_offset (inst) + 4; |
1666 | else | |
1667 | pc += 8; | |
1668 | break; | |
e135b889 | 1669 | case 5: /* BNE, BNEL */ |
c5aa993b | 1670 | neq_branch: |
0b1b3e42 UW |
1671 | if (get_frame_register_signed (frame, itype_rs (inst)) != |
1672 | get_frame_register_signed (frame, itype_rt (inst))) | |
c5aa993b JM |
1673 | pc += mips32_relative_offset (inst) + 4; |
1674 | else | |
1675 | pc += 8; | |
1676 | break; | |
e135b889 | 1677 | case 6: /* BLEZ, BLEZL */ |
0b1b3e42 | 1678 | if (get_frame_register_signed (frame, itype_rs (inst)) <= 0) |
c5aa993b JM |
1679 | pc += mips32_relative_offset (inst) + 4; |
1680 | else | |
1681 | pc += 8; | |
1682 | break; | |
1683 | case 7: | |
e135b889 DJ |
1684 | default: |
1685 | greater_branch: /* BGTZ, BGTZL */ | |
0b1b3e42 | 1686 | if (get_frame_register_signed (frame, itype_rs (inst)) > 0) |
c5aa993b JM |
1687 | pc += mips32_relative_offset (inst) + 4; |
1688 | else | |
1689 | pc += 8; | |
1690 | break; | |
c5aa993b JM |
1691 | } /* switch */ |
1692 | } /* else */ | |
1693 | return pc; | |
1694 | } /* mips32_next_pc */ | |
c906108c | 1695 | |
4cc0665f MR |
1696 | /* Extract the 7-bit signed immediate offset from the microMIPS instruction |
1697 | INSN. */ | |
1698 | ||
1699 | static LONGEST | |
1700 | micromips_relative_offset7 (ULONGEST insn) | |
1701 | { | |
1702 | return ((b0s7_imm (insn) ^ 0x40) - 0x40) << 1; | |
1703 | } | |
1704 | ||
1705 | /* Extract the 10-bit signed immediate offset from the microMIPS instruction | |
1706 | INSN. */ | |
1707 | ||
1708 | static LONGEST | |
1709 | micromips_relative_offset10 (ULONGEST insn) | |
1710 | { | |
1711 | return ((b0s10_imm (insn) ^ 0x200) - 0x200) << 1; | |
1712 | } | |
1713 | ||
1714 | /* Extract the 16-bit signed immediate offset from the microMIPS instruction | |
1715 | INSN. */ | |
1716 | ||
1717 | static LONGEST | |
1718 | micromips_relative_offset16 (ULONGEST insn) | |
1719 | { | |
1720 | return ((b0s16_imm (insn) ^ 0x8000) - 0x8000) << 1; | |
1721 | } | |
1722 | ||
1723 | /* Return the size in bytes of the microMIPS instruction at the address PC. */ | |
1724 | ||
1725 | static int | |
1726 | micromips_pc_insn_size (struct gdbarch *gdbarch, CORE_ADDR pc) | |
1727 | { | |
1728 | ULONGEST insn; | |
1729 | ||
1730 | insn = mips_fetch_instruction (gdbarch, ISA_MICROMIPS, pc, NULL); | |
1731 | return mips_insn_size (ISA_MICROMIPS, insn); | |
1732 | } | |
1733 | ||
1734 | /* Calculate the address of the next microMIPS instruction to execute | |
1735 | after the INSN coprocessor 1 conditional branch instruction at the | |
1736 | address PC. COUNT denotes the number of coprocessor condition bits | |
1737 | examined by the branch. */ | |
1738 | ||
1739 | static CORE_ADDR | |
1740 | micromips_bc1_pc (struct gdbarch *gdbarch, struct frame_info *frame, | |
1741 | ULONGEST insn, CORE_ADDR pc, int count) | |
1742 | { | |
1743 | int fcsr = mips_regnum (gdbarch)->fp_control_status; | |
1744 | int cnum = b2s3_cc (insn >> 16) & (count - 1); | |
1745 | int tf = b5s5_op (insn >> 16) & 1; | |
1746 | int mask = (1 << count) - 1; | |
1747 | ULONGEST fcs; | |
1748 | int cond; | |
1749 | ||
1750 | if (fcsr == -1) | |
1751 | /* No way to handle; it'll most likely trap anyway. */ | |
1752 | return pc; | |
1753 | ||
1754 | fcs = get_frame_register_unsigned (frame, fcsr); | |
1755 | cond = ((fcs >> 24) & 0xfe) | ((fcs >> 23) & 0x01); | |
1756 | ||
1757 | if (((cond >> cnum) & mask) != mask * !tf) | |
1758 | pc += micromips_relative_offset16 (insn); | |
1759 | else | |
1760 | pc += micromips_pc_insn_size (gdbarch, pc); | |
1761 | ||
1762 | return pc; | |
1763 | } | |
1764 | ||
1765 | /* Calculate the address of the next microMIPS instruction to execute | |
1766 | after the instruction at the address PC. */ | |
1767 | ||
1768 | static CORE_ADDR | |
1769 | micromips_next_pc (struct frame_info *frame, CORE_ADDR pc) | |
1770 | { | |
1771 | struct gdbarch *gdbarch = get_frame_arch (frame); | |
1772 | ULONGEST insn; | |
1773 | ||
1774 | insn = mips_fetch_instruction (gdbarch, ISA_MICROMIPS, pc, NULL); | |
1775 | pc += MIPS_INSN16_SIZE; | |
1776 | switch (mips_insn_size (ISA_MICROMIPS, insn)) | |
1777 | { | |
1778 | /* 48-bit instructions. */ | |
1779 | case 3 * MIPS_INSN16_SIZE: /* POOL48A: bits 011111 */ | |
1780 | /* No branch or jump instructions in this category. */ | |
1781 | pc += 2 * MIPS_INSN16_SIZE; | |
1782 | break; | |
1783 | ||
1784 | /* 32-bit instructions. */ | |
1785 | case 2 * MIPS_INSN16_SIZE: | |
1786 | insn <<= 16; | |
1787 | insn |= mips_fetch_instruction (gdbarch, ISA_MICROMIPS, pc, NULL); | |
1788 | pc += MIPS_INSN16_SIZE; | |
1789 | switch (micromips_op (insn >> 16)) | |
1790 | { | |
1791 | case 0x00: /* POOL32A: bits 000000 */ | |
1792 | if (b0s6_op (insn) == 0x3c | |
1793 | /* POOL32Axf: bits 000000 ... 111100 */ | |
1794 | && (b6s10_ext (insn) & 0x2bf) == 0x3c) | |
1795 | /* JALR, JALR.HB: 000000 000x111100 111100 */ | |
1796 | /* JALRS, JALRS.HB: 000000 010x111100 111100 */ | |
1797 | pc = get_frame_register_signed (frame, b0s5_reg (insn >> 16)); | |
1798 | break; | |
1799 | ||
1800 | case 0x10: /* POOL32I: bits 010000 */ | |
1801 | switch (b5s5_op (insn >> 16)) | |
1802 | { | |
1803 | case 0x00: /* BLTZ: bits 010000 00000 */ | |
1804 | case 0x01: /* BLTZAL: bits 010000 00001 */ | |
1805 | case 0x11: /* BLTZALS: bits 010000 10001 */ | |
1806 | if (get_frame_register_signed (frame, | |
1807 | b0s5_reg (insn >> 16)) < 0) | |
1808 | pc += micromips_relative_offset16 (insn); | |
1809 | else | |
1810 | pc += micromips_pc_insn_size (gdbarch, pc); | |
1811 | break; | |
1812 | ||
1813 | case 0x02: /* BGEZ: bits 010000 00010 */ | |
1814 | case 0x03: /* BGEZAL: bits 010000 00011 */ | |
1815 | case 0x13: /* BGEZALS: bits 010000 10011 */ | |
1816 | if (get_frame_register_signed (frame, | |
1817 | b0s5_reg (insn >> 16)) >= 0) | |
1818 | pc += micromips_relative_offset16 (insn); | |
1819 | else | |
1820 | pc += micromips_pc_insn_size (gdbarch, pc); | |
1821 | break; | |
1822 | ||
1823 | case 0x04: /* BLEZ: bits 010000 00100 */ | |
1824 | if (get_frame_register_signed (frame, | |
1825 | b0s5_reg (insn >> 16)) <= 0) | |
1826 | pc += micromips_relative_offset16 (insn); | |
1827 | else | |
1828 | pc += micromips_pc_insn_size (gdbarch, pc); | |
1829 | break; | |
1830 | ||
1831 | case 0x05: /* BNEZC: bits 010000 00101 */ | |
1832 | if (get_frame_register_signed (frame, | |
1833 | b0s5_reg (insn >> 16)) != 0) | |
1834 | pc += micromips_relative_offset16 (insn); | |
1835 | break; | |
1836 | ||
1837 | case 0x06: /* BGTZ: bits 010000 00110 */ | |
1838 | if (get_frame_register_signed (frame, | |
1839 | b0s5_reg (insn >> 16)) > 0) | |
1840 | pc += micromips_relative_offset16 (insn); | |
1841 | else | |
1842 | pc += micromips_pc_insn_size (gdbarch, pc); | |
1843 | break; | |
1844 | ||
1845 | case 0x07: /* BEQZC: bits 010000 00111 */ | |
1846 | if (get_frame_register_signed (frame, | |
1847 | b0s5_reg (insn >> 16)) == 0) | |
1848 | pc += micromips_relative_offset16 (insn); | |
1849 | break; | |
1850 | ||
1851 | case 0x14: /* BC2F: bits 010000 10100 xxx00 */ | |
1852 | case 0x15: /* BC2T: bits 010000 10101 xxx00 */ | |
1853 | if (((insn >> 16) & 0x3) == 0x0) | |
1854 | /* BC2F, BC2T: don't know how to handle these. */ | |
1855 | break; | |
1856 | break; | |
1857 | ||
1858 | case 0x1a: /* BPOSGE64: bits 010000 11010 */ | |
1859 | case 0x1b: /* BPOSGE32: bits 010000 11011 */ | |
1860 | { | |
1861 | unsigned int pos = (b5s5_op (insn >> 16) & 1) ? 32 : 64; | |
1862 | int dspctl = mips_regnum (gdbarch)->dspctl; | |
1863 | ||
1864 | if (dspctl == -1) | |
1865 | /* No way to handle; it'll most likely trap anyway. */ | |
1866 | break; | |
1867 | ||
1868 | if ((get_frame_register_unsigned (frame, | |
1869 | dspctl) & 0x7f) >= pos) | |
1870 | pc += micromips_relative_offset16 (insn); | |
1871 | else | |
1872 | pc += micromips_pc_insn_size (gdbarch, pc); | |
1873 | } | |
1874 | break; | |
1875 | ||
1876 | case 0x1c: /* BC1F: bits 010000 11100 xxx00 */ | |
1877 | /* BC1ANY2F: bits 010000 11100 xxx01 */ | |
1878 | case 0x1d: /* BC1T: bits 010000 11101 xxx00 */ | |
1879 | /* BC1ANY2T: bits 010000 11101 xxx01 */ | |
1880 | if (((insn >> 16) & 0x2) == 0x0) | |
1881 | pc = micromips_bc1_pc (gdbarch, frame, insn, pc, | |
1882 | ((insn >> 16) & 0x1) + 1); | |
1883 | break; | |
1884 | ||
1885 | case 0x1e: /* BC1ANY4F: bits 010000 11110 xxx01 */ | |
1886 | case 0x1f: /* BC1ANY4T: bits 010000 11111 xxx01 */ | |
1887 | if (((insn >> 16) & 0x3) == 0x1) | |
1888 | pc = micromips_bc1_pc (gdbarch, frame, insn, pc, 4); | |
1889 | break; | |
1890 | } | |
1891 | break; | |
1892 | ||
1893 | case 0x1d: /* JALS: bits 011101 */ | |
1894 | case 0x35: /* J: bits 110101 */ | |
1895 | case 0x3d: /* JAL: bits 111101 */ | |
1896 | pc = ((pc | 0x7fffffe) ^ 0x7fffffe) | (b0s26_imm (insn) << 1); | |
1897 | break; | |
1898 | ||
1899 | case 0x25: /* BEQ: bits 100101 */ | |
1900 | if (get_frame_register_signed (frame, b0s5_reg (insn >> 16)) | |
1901 | == get_frame_register_signed (frame, b5s5_reg (insn >> 16))) | |
1902 | pc += micromips_relative_offset16 (insn); | |
1903 | else | |
1904 | pc += micromips_pc_insn_size (gdbarch, pc); | |
1905 | break; | |
1906 | ||
1907 | case 0x2d: /* BNE: bits 101101 */ | |
1908 | if (get_frame_register_signed (frame, b0s5_reg (insn >> 16)) | |
1909 | != get_frame_register_signed (frame, b5s5_reg (insn >> 16))) | |
1910 | pc += micromips_relative_offset16 (insn); | |
1911 | else | |
1912 | pc += micromips_pc_insn_size (gdbarch, pc); | |
1913 | break; | |
1914 | ||
1915 | case 0x3c: /* JALX: bits 111100 */ | |
1916 | pc = ((pc | 0xfffffff) ^ 0xfffffff) | (b0s26_imm (insn) << 2); | |
1917 | break; | |
1918 | } | |
1919 | break; | |
1920 | ||
1921 | /* 16-bit instructions. */ | |
1922 | case MIPS_INSN16_SIZE: | |
1923 | switch (micromips_op (insn)) | |
1924 | { | |
1925 | case 0x11: /* POOL16C: bits 010001 */ | |
1926 | if ((b5s5_op (insn) & 0x1c) == 0xc) | |
1927 | /* JR16, JRC, JALR16, JALRS16: 010001 011xx */ | |
1928 | pc = get_frame_register_signed (frame, b0s5_reg (insn)); | |
1929 | else if (b5s5_op (insn) == 0x18) | |
1930 | /* JRADDIUSP: bits 010001 11000 */ | |
1931 | pc = get_frame_register_signed (frame, MIPS_RA_REGNUM); | |
1932 | break; | |
1933 | ||
1934 | case 0x23: /* BEQZ16: bits 100011 */ | |
1935 | { | |
1936 | int rs = mips_reg3_to_reg[b7s3_reg (insn)]; | |
1937 | ||
1938 | if (get_frame_register_signed (frame, rs) == 0) | |
1939 | pc += micromips_relative_offset7 (insn); | |
1940 | else | |
1941 | pc += micromips_pc_insn_size (gdbarch, pc); | |
1942 | } | |
1943 | break; | |
1944 | ||
1945 | case 0x2b: /* BNEZ16: bits 101011 */ | |
1946 | { | |
1947 | int rs = mips_reg3_to_reg[b7s3_reg (insn)]; | |
1948 | ||
1949 | if (get_frame_register_signed (frame, rs) != 0) | |
1950 | pc += micromips_relative_offset7 (insn); | |
1951 | else | |
1952 | pc += micromips_pc_insn_size (gdbarch, pc); | |
1953 | } | |
1954 | break; | |
1955 | ||
1956 | case 0x33: /* B16: bits 110011 */ | |
1957 | pc += micromips_relative_offset10 (insn); | |
1958 | break; | |
1959 | } | |
1960 | break; | |
1961 | } | |
1962 | ||
1963 | return pc; | |
1964 | } | |
1965 | ||
c906108c | 1966 | /* Decoding the next place to set a breakpoint is irregular for the |
025bb325 MS |
1967 | mips 16 variant, but fortunately, there fewer instructions. We have |
1968 | to cope ith extensions for 16 bit instructions and a pair of actual | |
1969 | 32 bit instructions. We dont want to set a single step instruction | |
1970 | on the extend instruction either. */ | |
c906108c SS |
1971 | |
1972 | /* Lots of mips16 instruction formats */ | |
1973 | /* Predicting jumps requires itype,ritype,i8type | |
025bb325 | 1974 | and their extensions extItype,extritype,extI8type. */ |
c906108c SS |
1975 | enum mips16_inst_fmts |
1976 | { | |
c5aa993b JM |
1977 | itype, /* 0 immediate 5,10 */ |
1978 | ritype, /* 1 5,3,8 */ | |
1979 | rrtype, /* 2 5,3,3,5 */ | |
1980 | rritype, /* 3 5,3,3,5 */ | |
1981 | rrrtype, /* 4 5,3,3,3,2 */ | |
1982 | rriatype, /* 5 5,3,3,1,4 */ | |
1983 | shifttype, /* 6 5,3,3,3,2 */ | |
1984 | i8type, /* 7 5,3,8 */ | |
1985 | i8movtype, /* 8 5,3,3,5 */ | |
1986 | i8mov32rtype, /* 9 5,3,5,3 */ | |
1987 | i64type, /* 10 5,3,8 */ | |
1988 | ri64type, /* 11 5,3,3,5 */ | |
1989 | jalxtype, /* 12 5,1,5,5,16 - a 32 bit instruction */ | |
1990 | exiItype, /* 13 5,6,5,5,1,1,1,1,1,1,5 */ | |
1991 | extRitype, /* 14 5,6,5,5,3,1,1,1,5 */ | |
1992 | extRRItype, /* 15 5,5,5,5,3,3,5 */ | |
1993 | extRRIAtype, /* 16 5,7,4,5,3,3,1,4 */ | |
1994 | EXTshifttype, /* 17 5,5,1,1,1,1,1,1,5,3,3,1,1,1,2 */ | |
1995 | extI8type, /* 18 5,6,5,5,3,1,1,1,5 */ | |
1996 | extI64type, /* 19 5,6,5,5,3,1,1,1,5 */ | |
1997 | extRi64type, /* 20 5,6,5,5,3,3,5 */ | |
1998 | extshift64type /* 21 5,5,1,1,1,1,1,1,5,1,1,1,3,5 */ | |
1999 | }; | |
12f02c2a | 2000 | /* I am heaping all the fields of the formats into one structure and |
025bb325 | 2001 | then, only the fields which are involved in instruction extension. */ |
c906108c | 2002 | struct upk_mips16 |
6d82d43b AC |
2003 | { |
2004 | CORE_ADDR offset; | |
025bb325 | 2005 | unsigned int regx; /* Function in i8 type. */ |
6d82d43b AC |
2006 | unsigned int regy; |
2007 | }; | |
c906108c SS |
2008 | |
2009 | ||
12f02c2a | 2010 | /* The EXT-I, EXT-ri nad EXT-I8 instructions all have the same format |
c68cf8ad | 2011 | for the bits which make up the immediate extension. */ |
c906108c | 2012 | |
12f02c2a AC |
2013 | static CORE_ADDR |
2014 | extended_offset (unsigned int extension) | |
c906108c | 2015 | { |
12f02c2a | 2016 | CORE_ADDR value; |
130854df | 2017 | |
4c2051c6 | 2018 | value = (extension >> 16) & 0x1f; /* Extract 15:11. */ |
c5aa993b | 2019 | value = value << 6; |
4c2051c6 | 2020 | value |= (extension >> 21) & 0x3f; /* Extract 10:5. */ |
c5aa993b | 2021 | value = value << 5; |
130854df MR |
2022 | value |= extension & 0x1f; /* Extract 4:0. */ |
2023 | ||
c5aa993b | 2024 | return value; |
c906108c SS |
2025 | } |
2026 | ||
2027 | /* Only call this function if you know that this is an extendable | |
bcf1ea1e MR |
2028 | instruction. It won't malfunction, but why make excess remote memory |
2029 | references? If the immediate operands get sign extended or something, | |
2030 | do it after the extension is performed. */ | |
c906108c | 2031 | /* FIXME: Every one of these cases needs to worry about sign extension |
bcf1ea1e | 2032 | when the offset is to be used in relative addressing. */ |
c906108c | 2033 | |
12f02c2a | 2034 | static unsigned int |
e17a4113 | 2035 | fetch_mips_16 (struct gdbarch *gdbarch, CORE_ADDR pc) |
c906108c | 2036 | { |
e17a4113 | 2037 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
47a35522 | 2038 | gdb_byte buf[8]; |
025bb325 | 2039 | pc &= 0xfffffffe; /* Clear the low order bit. */ |
c5aa993b | 2040 | target_read_memory (pc, buf, 2); |
e17a4113 | 2041 | return extract_unsigned_integer (buf, 2, byte_order); |
c906108c SS |
2042 | } |
2043 | ||
2044 | static void | |
e17a4113 | 2045 | unpack_mips16 (struct gdbarch *gdbarch, CORE_ADDR pc, |
12f02c2a AC |
2046 | unsigned int extension, |
2047 | unsigned int inst, | |
6d82d43b | 2048 | enum mips16_inst_fmts insn_format, struct upk_mips16 *upk) |
c906108c | 2049 | { |
12f02c2a AC |
2050 | CORE_ADDR offset; |
2051 | int regx; | |
2052 | int regy; | |
2053 | switch (insn_format) | |
c906108c | 2054 | { |
c5aa993b | 2055 | case itype: |
c906108c | 2056 | { |
12f02c2a AC |
2057 | CORE_ADDR value; |
2058 | if (extension) | |
c5aa993b | 2059 | { |
4c2051c6 MR |
2060 | value = extended_offset ((extension << 16) | inst); |
2061 | value = (value ^ 0x8000) - 0x8000; /* Sign-extend. */ | |
c906108c SS |
2062 | } |
2063 | else | |
c5aa993b | 2064 | { |
12f02c2a | 2065 | value = inst & 0x7ff; |
4c2051c6 | 2066 | value = (value ^ 0x400) - 0x400; /* Sign-extend. */ |
c906108c | 2067 | } |
12f02c2a AC |
2068 | offset = value; |
2069 | regx = -1; | |
2070 | regy = -1; | |
c906108c | 2071 | } |
c5aa993b JM |
2072 | break; |
2073 | case ritype: | |
2074 | case i8type: | |
025bb325 | 2075 | { /* A register identifier and an offset. */ |
c906108c | 2076 | /* Most of the fields are the same as I type but the |
025bb325 | 2077 | immediate value is of a different length. */ |
12f02c2a AC |
2078 | CORE_ADDR value; |
2079 | if (extension) | |
c906108c | 2080 | { |
4c2051c6 MR |
2081 | value = extended_offset ((extension << 16) | inst); |
2082 | value = (value ^ 0x8000) - 0x8000; /* Sign-extend. */ | |
c906108c | 2083 | } |
c5aa993b JM |
2084 | else |
2085 | { | |
4c2051c6 MR |
2086 | value = inst & 0xff; /* 8 bits */ |
2087 | value = (value ^ 0x80) - 0x80; /* Sign-extend. */ | |
c5aa993b | 2088 | } |
12f02c2a | 2089 | offset = value; |
4c2051c6 | 2090 | regx = (inst >> 8) & 0x07; /* i8 funct */ |
12f02c2a | 2091 | regy = -1; |
c5aa993b | 2092 | break; |
c906108c | 2093 | } |
c5aa993b | 2094 | case jalxtype: |
c906108c | 2095 | { |
c5aa993b | 2096 | unsigned long value; |
12f02c2a AC |
2097 | unsigned int nexthalf; |
2098 | value = ((inst & 0x1f) << 5) | ((inst >> 5) & 0x1f); | |
c5aa993b | 2099 | value = value << 16; |
4cc0665f MR |
2100 | nexthalf = mips_fetch_instruction (gdbarch, ISA_MIPS16, pc + 2, NULL); |
2101 | /* Low bit still set. */ | |
c5aa993b | 2102 | value |= nexthalf; |
12f02c2a AC |
2103 | offset = value; |
2104 | regx = -1; | |
2105 | regy = -1; | |
c5aa993b | 2106 | break; |
c906108c SS |
2107 | } |
2108 | default: | |
e2e0b3e5 | 2109 | internal_error (__FILE__, __LINE__, _("bad switch")); |
c906108c | 2110 | } |
12f02c2a AC |
2111 | upk->offset = offset; |
2112 | upk->regx = regx; | |
2113 | upk->regy = regy; | |
c906108c SS |
2114 | } |
2115 | ||
2116 | ||
c5aa993b JM |
2117 | static CORE_ADDR |
2118 | add_offset_16 (CORE_ADDR pc, int offset) | |
c906108c | 2119 | { |
5b652102 | 2120 | return ((offset << 2) | ((pc + 2) & (~(CORE_ADDR) 0x0fffffff))); |
c906108c SS |
2121 | } |
2122 | ||
12f02c2a | 2123 | static CORE_ADDR |
0b1b3e42 | 2124 | extended_mips16_next_pc (struct frame_info *frame, CORE_ADDR pc, |
6d82d43b | 2125 | unsigned int extension, unsigned int insn) |
c906108c | 2126 | { |
e17a4113 | 2127 | struct gdbarch *gdbarch = get_frame_arch (frame); |
12f02c2a AC |
2128 | int op = (insn >> 11); |
2129 | switch (op) | |
c906108c | 2130 | { |
6d82d43b | 2131 | case 2: /* Branch */ |
12f02c2a | 2132 | { |
12f02c2a | 2133 | struct upk_mips16 upk; |
e17a4113 | 2134 | unpack_mips16 (gdbarch, pc, extension, insn, itype, &upk); |
4c2051c6 | 2135 | pc += (upk.offset << 1) + 2; |
12f02c2a AC |
2136 | break; |
2137 | } | |
025bb325 MS |
2138 | case 3: /* JAL , JALX - Watch out, these are 32 bit |
2139 | instructions. */ | |
12f02c2a AC |
2140 | { |
2141 | struct upk_mips16 upk; | |
e17a4113 | 2142 | unpack_mips16 (gdbarch, pc, extension, insn, jalxtype, &upk); |
12f02c2a AC |
2143 | pc = add_offset_16 (pc, upk.offset); |
2144 | if ((insn >> 10) & 0x01) /* Exchange mode */ | |
025bb325 | 2145 | pc = pc & ~0x01; /* Clear low bit, indicate 32 bit mode. */ |
12f02c2a AC |
2146 | else |
2147 | pc |= 0x01; | |
2148 | break; | |
2149 | } | |
6d82d43b | 2150 | case 4: /* beqz */ |
12f02c2a AC |
2151 | { |
2152 | struct upk_mips16 upk; | |
2153 | int reg; | |
e17a4113 | 2154 | unpack_mips16 (gdbarch, pc, extension, insn, ritype, &upk); |
4cc0665f | 2155 | reg = get_frame_register_signed (frame, mips_reg3_to_reg[upk.regx]); |
12f02c2a AC |
2156 | if (reg == 0) |
2157 | pc += (upk.offset << 1) + 2; | |
2158 | else | |
2159 | pc += 2; | |
2160 | break; | |
2161 | } | |
6d82d43b | 2162 | case 5: /* bnez */ |
12f02c2a AC |
2163 | { |
2164 | struct upk_mips16 upk; | |
2165 | int reg; | |
e17a4113 | 2166 | unpack_mips16 (gdbarch, pc, extension, insn, ritype, &upk); |
4cc0665f | 2167 | reg = get_frame_register_signed (frame, mips_reg3_to_reg[upk.regx]); |
12f02c2a AC |
2168 | if (reg != 0) |
2169 | pc += (upk.offset << 1) + 2; | |
2170 | else | |
2171 | pc += 2; | |
2172 | break; | |
2173 | } | |
6d82d43b | 2174 | case 12: /* I8 Formats btez btnez */ |
12f02c2a AC |
2175 | { |
2176 | struct upk_mips16 upk; | |
2177 | int reg; | |
e17a4113 | 2178 | unpack_mips16 (gdbarch, pc, extension, insn, i8type, &upk); |
12f02c2a | 2179 | /* upk.regx contains the opcode */ |
0b1b3e42 | 2180 | reg = get_frame_register_signed (frame, 24); /* Test register is 24 */ |
12f02c2a AC |
2181 | if (((upk.regx == 0) && (reg == 0)) /* BTEZ */ |
2182 | || ((upk.regx == 1) && (reg != 0))) /* BTNEZ */ | |
2183 | /* pc = add_offset_16(pc,upk.offset) ; */ | |
2184 | pc += (upk.offset << 1) + 2; | |
2185 | else | |
2186 | pc += 2; | |
2187 | break; | |
2188 | } | |
6d82d43b | 2189 | case 29: /* RR Formats JR, JALR, JALR-RA */ |
12f02c2a AC |
2190 | { |
2191 | struct upk_mips16 upk; | |
2192 | /* upk.fmt = rrtype; */ | |
2193 | op = insn & 0x1f; | |
2194 | if (op == 0) | |
c5aa993b | 2195 | { |
12f02c2a AC |
2196 | int reg; |
2197 | upk.regx = (insn >> 8) & 0x07; | |
2198 | upk.regy = (insn >> 5) & 0x07; | |
4c2051c6 | 2199 | if ((upk.regy & 1) == 0) |
4cc0665f | 2200 | reg = mips_reg3_to_reg[upk.regx]; |
4c2051c6 MR |
2201 | else |
2202 | reg = 31; /* Function return instruction. */ | |
0b1b3e42 | 2203 | pc = get_frame_register_signed (frame, reg); |
c906108c | 2204 | } |
12f02c2a | 2205 | else |
c5aa993b | 2206 | pc += 2; |
12f02c2a AC |
2207 | break; |
2208 | } | |
2209 | case 30: | |
2210 | /* This is an instruction extension. Fetch the real instruction | |
2211 | (which follows the extension) and decode things based on | |
025bb325 | 2212 | that. */ |
12f02c2a AC |
2213 | { |
2214 | pc += 2; | |
e17a4113 UW |
2215 | pc = extended_mips16_next_pc (frame, pc, insn, |
2216 | fetch_mips_16 (gdbarch, pc)); | |
12f02c2a AC |
2217 | break; |
2218 | } | |
2219 | default: | |
2220 | { | |
2221 | pc += 2; | |
2222 | break; | |
2223 | } | |
c906108c | 2224 | } |
c5aa993b | 2225 | return pc; |
12f02c2a | 2226 | } |
c906108c | 2227 | |
5a89d8aa | 2228 | static CORE_ADDR |
0b1b3e42 | 2229 | mips16_next_pc (struct frame_info *frame, CORE_ADDR pc) |
12f02c2a | 2230 | { |
e17a4113 UW |
2231 | struct gdbarch *gdbarch = get_frame_arch (frame); |
2232 | unsigned int insn = fetch_mips_16 (gdbarch, pc); | |
0b1b3e42 | 2233 | return extended_mips16_next_pc (frame, pc, 0, insn); |
12f02c2a AC |
2234 | } |
2235 | ||
2236 | /* The mips_next_pc function supports single_step when the remote | |
7e73cedf | 2237 | target monitor or stub is not developed enough to do a single_step. |
12f02c2a | 2238 | It works by decoding the current instruction and predicting where a |
025bb325 | 2239 | branch will go. This isnt hard because all the data is available. |
4cc0665f | 2240 | The MIPS32, MIPS16 and microMIPS variants are quite different. */ |
ad527d2e | 2241 | static CORE_ADDR |
0b1b3e42 | 2242 | mips_next_pc (struct frame_info *frame, CORE_ADDR pc) |
c906108c | 2243 | { |
4cc0665f MR |
2244 | struct gdbarch *gdbarch = get_frame_arch (frame); |
2245 | ||
2246 | if (mips_pc_is_mips16 (gdbarch, pc)) | |
0b1b3e42 | 2247 | return mips16_next_pc (frame, pc); |
4cc0665f MR |
2248 | else if (mips_pc_is_micromips (gdbarch, pc)) |
2249 | return micromips_next_pc (frame, pc); | |
c5aa993b | 2250 | else |
0b1b3e42 | 2251 | return mips32_next_pc (frame, pc); |
12f02c2a | 2252 | } |
c906108c | 2253 | |
edfae063 AC |
2254 | struct mips_frame_cache |
2255 | { | |
2256 | CORE_ADDR base; | |
2257 | struct trad_frame_saved_reg *saved_regs; | |
2258 | }; | |
2259 | ||
29639122 JB |
2260 | /* Set a register's saved stack address in temp_saved_regs. If an |
2261 | address has already been set for this register, do nothing; this | |
2262 | way we will only recognize the first save of a given register in a | |
2263 | function prologue. | |
eec63939 | 2264 | |
f57d151a UW |
2265 | For simplicity, save the address in both [0 .. gdbarch_num_regs) and |
2266 | [gdbarch_num_regs .. 2*gdbarch_num_regs). | |
2267 | Strictly speaking, only the second range is used as it is only second | |
2268 | range (the ABI instead of ISA registers) that comes into play when finding | |
2269 | saved registers in a frame. */ | |
eec63939 AC |
2270 | |
2271 | static void | |
74ed0bb4 MD |
2272 | set_reg_offset (struct gdbarch *gdbarch, struct mips_frame_cache *this_cache, |
2273 | int regnum, CORE_ADDR offset) | |
eec63939 | 2274 | { |
29639122 JB |
2275 | if (this_cache != NULL |
2276 | && this_cache->saved_regs[regnum].addr == -1) | |
2277 | { | |
74ed0bb4 MD |
2278 | this_cache->saved_regs[regnum + 0 * gdbarch_num_regs (gdbarch)].addr |
2279 | = offset; | |
2280 | this_cache->saved_regs[regnum + 1 * gdbarch_num_regs (gdbarch)].addr | |
2281 | = offset; | |
29639122 | 2282 | } |
eec63939 AC |
2283 | } |
2284 | ||
eec63939 | 2285 | |
29639122 JB |
2286 | /* Fetch the immediate value from a MIPS16 instruction. |
2287 | If the previous instruction was an EXTEND, use it to extend | |
2288 | the upper bits of the immediate value. This is a helper function | |
2289 | for mips16_scan_prologue. */ | |
eec63939 | 2290 | |
29639122 JB |
2291 | static int |
2292 | mips16_get_imm (unsigned short prev_inst, /* previous instruction */ | |
2293 | unsigned short inst, /* current instruction */ | |
2294 | int nbits, /* number of bits in imm field */ | |
2295 | int scale, /* scale factor to be applied to imm */ | |
025bb325 | 2296 | int is_signed) /* is the imm field signed? */ |
eec63939 | 2297 | { |
29639122 | 2298 | int offset; |
eec63939 | 2299 | |
29639122 JB |
2300 | if ((prev_inst & 0xf800) == 0xf000) /* prev instruction was EXTEND? */ |
2301 | { | |
2302 | offset = ((prev_inst & 0x1f) << 11) | (prev_inst & 0x7e0); | |
2303 | if (offset & 0x8000) /* check for negative extend */ | |
2304 | offset = 0 - (0x10000 - (offset & 0xffff)); | |
2305 | return offset | (inst & 0x1f); | |
2306 | } | |
eec63939 | 2307 | else |
29639122 JB |
2308 | { |
2309 | int max_imm = 1 << nbits; | |
2310 | int mask = max_imm - 1; | |
2311 | int sign_bit = max_imm >> 1; | |
45c9dd44 | 2312 | |
29639122 JB |
2313 | offset = inst & mask; |
2314 | if (is_signed && (offset & sign_bit)) | |
2315 | offset = 0 - (max_imm - offset); | |
2316 | return offset * scale; | |
2317 | } | |
2318 | } | |
eec63939 | 2319 | |
65596487 | 2320 | |
29639122 JB |
2321 | /* Analyze the function prologue from START_PC to LIMIT_PC. Builds |
2322 | the associated FRAME_CACHE if not null. | |
2323 | Return the address of the first instruction past the prologue. */ | |
eec63939 | 2324 | |
29639122 | 2325 | static CORE_ADDR |
e17a4113 UW |
2326 | mips16_scan_prologue (struct gdbarch *gdbarch, |
2327 | CORE_ADDR start_pc, CORE_ADDR limit_pc, | |
b8a22b94 | 2328 | struct frame_info *this_frame, |
29639122 JB |
2329 | struct mips_frame_cache *this_cache) |
2330 | { | |
2331 | CORE_ADDR cur_pc; | |
025bb325 | 2332 | CORE_ADDR frame_addr = 0; /* Value of $r17, used as frame pointer. */ |
29639122 JB |
2333 | CORE_ADDR sp; |
2334 | long frame_offset = 0; /* Size of stack frame. */ | |
2335 | long frame_adjust = 0; /* Offset of FP from SP. */ | |
2336 | int frame_reg = MIPS_SP_REGNUM; | |
025bb325 | 2337 | unsigned short prev_inst = 0; /* saved copy of previous instruction. */ |
29639122 JB |
2338 | unsigned inst = 0; /* current instruction */ |
2339 | unsigned entry_inst = 0; /* the entry instruction */ | |
2207132d | 2340 | unsigned save_inst = 0; /* the save instruction */ |
29639122 | 2341 | int reg, offset; |
a343eb3c | 2342 | |
29639122 JB |
2343 | int extend_bytes = 0; |
2344 | int prev_extend_bytes; | |
2345 | CORE_ADDR end_prologue_addr = 0; | |
a343eb3c | 2346 | |
29639122 | 2347 | /* Can be called when there's no process, and hence when there's no |
b8a22b94 DJ |
2348 | THIS_FRAME. */ |
2349 | if (this_frame != NULL) | |
2350 | sp = get_frame_register_signed (this_frame, | |
2351 | gdbarch_num_regs (gdbarch) | |
2352 | + MIPS_SP_REGNUM); | |
29639122 JB |
2353 | else |
2354 | sp = 0; | |
eec63939 | 2355 | |
29639122 JB |
2356 | if (limit_pc > start_pc + 200) |
2357 | limit_pc = start_pc + 200; | |
eec63939 | 2358 | |
95ac2dcf | 2359 | for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += MIPS_INSN16_SIZE) |
29639122 JB |
2360 | { |
2361 | /* Save the previous instruction. If it's an EXTEND, we'll extract | |
2362 | the immediate offset extension from it in mips16_get_imm. */ | |
2363 | prev_inst = inst; | |
eec63939 | 2364 | |
025bb325 | 2365 | /* Fetch and decode the instruction. */ |
4cc0665f MR |
2366 | inst = (unsigned short) mips_fetch_instruction (gdbarch, ISA_MIPS16, |
2367 | cur_pc, NULL); | |
eec63939 | 2368 | |
29639122 JB |
2369 | /* Normally we ignore extend instructions. However, if it is |
2370 | not followed by a valid prologue instruction, then this | |
2371 | instruction is not part of the prologue either. We must | |
2372 | remember in this case to adjust the end_prologue_addr back | |
2373 | over the extend. */ | |
2374 | if ((inst & 0xf800) == 0xf000) /* extend */ | |
2375 | { | |
95ac2dcf | 2376 | extend_bytes = MIPS_INSN16_SIZE; |
29639122 JB |
2377 | continue; |
2378 | } | |
eec63939 | 2379 | |
29639122 JB |
2380 | prev_extend_bytes = extend_bytes; |
2381 | extend_bytes = 0; | |
eec63939 | 2382 | |
29639122 JB |
2383 | if ((inst & 0xff00) == 0x6300 /* addiu sp */ |
2384 | || (inst & 0xff00) == 0xfb00) /* daddiu sp */ | |
2385 | { | |
2386 | offset = mips16_get_imm (prev_inst, inst, 8, 8, 1); | |
025bb325 | 2387 | if (offset < 0) /* Negative stack adjustment? */ |
29639122 JB |
2388 | frame_offset -= offset; |
2389 | else | |
2390 | /* Exit loop if a positive stack adjustment is found, which | |
2391 | usually means that the stack cleanup code in the function | |
2392 | epilogue is reached. */ | |
2393 | break; | |
2394 | } | |
2395 | else if ((inst & 0xf800) == 0xd000) /* sw reg,n($sp) */ | |
2396 | { | |
2397 | offset = mips16_get_imm (prev_inst, inst, 8, 4, 0); | |
4cc0665f | 2398 | reg = mips_reg3_to_reg[(inst & 0x700) >> 8]; |
74ed0bb4 | 2399 | set_reg_offset (gdbarch, this_cache, reg, sp + offset); |
29639122 JB |
2400 | } |
2401 | else if ((inst & 0xff00) == 0xf900) /* sd reg,n($sp) */ | |
2402 | { | |
2403 | offset = mips16_get_imm (prev_inst, inst, 5, 8, 0); | |
4cc0665f | 2404 | reg = mips_reg3_to_reg[(inst & 0xe0) >> 5]; |
74ed0bb4 | 2405 | set_reg_offset (gdbarch, this_cache, reg, sp + offset); |
29639122 JB |
2406 | } |
2407 | else if ((inst & 0xff00) == 0x6200) /* sw $ra,n($sp) */ | |
2408 | { | |
2409 | offset = mips16_get_imm (prev_inst, inst, 8, 4, 0); | |
74ed0bb4 | 2410 | set_reg_offset (gdbarch, this_cache, MIPS_RA_REGNUM, sp + offset); |
29639122 JB |
2411 | } |
2412 | else if ((inst & 0xff00) == 0xfa00) /* sd $ra,n($sp) */ | |
2413 | { | |
2414 | offset = mips16_get_imm (prev_inst, inst, 8, 8, 0); | |
74ed0bb4 | 2415 | set_reg_offset (gdbarch, this_cache, MIPS_RA_REGNUM, sp + offset); |
29639122 JB |
2416 | } |
2417 | else if (inst == 0x673d) /* move $s1, $sp */ | |
2418 | { | |
2419 | frame_addr = sp; | |
2420 | frame_reg = 17; | |
2421 | } | |
2422 | else if ((inst & 0xff00) == 0x0100) /* addiu $s1,sp,n */ | |
2423 | { | |
2424 | offset = mips16_get_imm (prev_inst, inst, 8, 4, 0); | |
2425 | frame_addr = sp + offset; | |
2426 | frame_reg = 17; | |
2427 | frame_adjust = offset; | |
2428 | } | |
2429 | else if ((inst & 0xFF00) == 0xd900) /* sw reg,offset($s1) */ | |
2430 | { | |
2431 | offset = mips16_get_imm (prev_inst, inst, 5, 4, 0); | |
4cc0665f | 2432 | reg = mips_reg3_to_reg[(inst & 0xe0) >> 5]; |
74ed0bb4 | 2433 | set_reg_offset (gdbarch, this_cache, reg, frame_addr + offset); |
29639122 JB |
2434 | } |
2435 | else if ((inst & 0xFF00) == 0x7900) /* sd reg,offset($s1) */ | |
2436 | { | |
2437 | offset = mips16_get_imm (prev_inst, inst, 5, 8, 0); | |
4cc0665f | 2438 | reg = mips_reg3_to_reg[(inst & 0xe0) >> 5]; |
74ed0bb4 | 2439 | set_reg_offset (gdbarch, this_cache, reg, frame_addr + offset); |
29639122 JB |
2440 | } |
2441 | else if ((inst & 0xf81f) == 0xe809 | |
2442 | && (inst & 0x700) != 0x700) /* entry */ | |
025bb325 | 2443 | entry_inst = inst; /* Save for later processing. */ |
2207132d MR |
2444 | else if ((inst & 0xff80) == 0x6480) /* save */ |
2445 | { | |
025bb325 | 2446 | save_inst = inst; /* Save for later processing. */ |
2207132d MR |
2447 | if (prev_extend_bytes) /* extend */ |
2448 | save_inst |= prev_inst << 16; | |
2449 | } | |
29639122 | 2450 | else if ((inst & 0xf800) == 0x1800) /* jal(x) */ |
95ac2dcf | 2451 | cur_pc += MIPS_INSN16_SIZE; /* 32-bit instruction */ |
29639122 JB |
2452 | else if ((inst & 0xff1c) == 0x6704) /* move reg,$a0-$a3 */ |
2453 | { | |
2454 | /* This instruction is part of the prologue, but we don't | |
2455 | need to do anything special to handle it. */ | |
2456 | } | |
2457 | else | |
2458 | { | |
2459 | /* This instruction is not an instruction typically found | |
2460 | in a prologue, so we must have reached the end of the | |
2461 | prologue. */ | |
2462 | if (end_prologue_addr == 0) | |
2463 | end_prologue_addr = cur_pc - prev_extend_bytes; | |
2464 | } | |
2465 | } | |
eec63939 | 2466 | |
29639122 JB |
2467 | /* The entry instruction is typically the first instruction in a function, |
2468 | and it stores registers at offsets relative to the value of the old SP | |
2469 | (before the prologue). But the value of the sp parameter to this | |
2470 | function is the new SP (after the prologue has been executed). So we | |
2471 | can't calculate those offsets until we've seen the entire prologue, | |
025bb325 | 2472 | and can calculate what the old SP must have been. */ |
29639122 JB |
2473 | if (entry_inst != 0) |
2474 | { | |
2475 | int areg_count = (entry_inst >> 8) & 7; | |
2476 | int sreg_count = (entry_inst >> 6) & 3; | |
eec63939 | 2477 | |
29639122 JB |
2478 | /* The entry instruction always subtracts 32 from the SP. */ |
2479 | frame_offset += 32; | |
2480 | ||
2481 | /* Now we can calculate what the SP must have been at the | |
2482 | start of the function prologue. */ | |
2483 | sp += frame_offset; | |
2484 | ||
2485 | /* Check if a0-a3 were saved in the caller's argument save area. */ | |
2486 | for (reg = 4, offset = 0; reg < areg_count + 4; reg++) | |
2487 | { | |
74ed0bb4 | 2488 | set_reg_offset (gdbarch, this_cache, reg, sp + offset); |
72a155b4 | 2489 | offset += mips_abi_regsize (gdbarch); |
29639122 JB |
2490 | } |
2491 | ||
2492 | /* Check if the ra register was pushed on the stack. */ | |
2493 | offset = -4; | |
2494 | if (entry_inst & 0x20) | |
2495 | { | |
74ed0bb4 | 2496 | set_reg_offset (gdbarch, this_cache, MIPS_RA_REGNUM, sp + offset); |
72a155b4 | 2497 | offset -= mips_abi_regsize (gdbarch); |
29639122 JB |
2498 | } |
2499 | ||
2500 | /* Check if the s0 and s1 registers were pushed on the stack. */ | |
2501 | for (reg = 16; reg < sreg_count + 16; reg++) | |
2502 | { | |
74ed0bb4 | 2503 | set_reg_offset (gdbarch, this_cache, reg, sp + offset); |
72a155b4 | 2504 | offset -= mips_abi_regsize (gdbarch); |
29639122 JB |
2505 | } |
2506 | } | |
2507 | ||
2207132d MR |
2508 | /* The SAVE instruction is similar to ENTRY, except that defined by the |
2509 | MIPS16e ASE of the MIPS Architecture. Unlike with ENTRY though, the | |
2510 | size of the frame is specified as an immediate field of instruction | |
2511 | and an extended variation exists which lets additional registers and | |
2512 | frame space to be specified. The instruction always treats registers | |
2513 | as 32-bit so its usefulness for 64-bit ABIs is questionable. */ | |
2514 | if (save_inst != 0 && mips_abi_regsize (gdbarch) == 4) | |
2515 | { | |
2516 | static int args_table[16] = { | |
2517 | 0, 0, 0, 0, 1, 1, 1, 1, | |
2518 | 2, 2, 2, 0, 3, 3, 4, -1, | |
2519 | }; | |
2520 | static int astatic_table[16] = { | |
2521 | 0, 1, 2, 3, 0, 1, 2, 3, | |
2522 | 0, 1, 2, 4, 0, 1, 0, -1, | |
2523 | }; | |
2524 | int aregs = (save_inst >> 16) & 0xf; | |
2525 | int xsregs = (save_inst >> 24) & 0x7; | |
2526 | int args = args_table[aregs]; | |
2527 | int astatic = astatic_table[aregs]; | |
2528 | long frame_size; | |
2529 | ||
2530 | if (args < 0) | |
2531 | { | |
2532 | warning (_("Invalid number of argument registers encoded in SAVE.")); | |
2533 | args = 0; | |
2534 | } | |
2535 | if (astatic < 0) | |
2536 | { | |
2537 | warning (_("Invalid number of static registers encoded in SAVE.")); | |
2538 | astatic = 0; | |
2539 | } | |
2540 | ||
2541 | /* For standard SAVE the frame size of 0 means 128. */ | |
2542 | frame_size = ((save_inst >> 16) & 0xf0) | (save_inst & 0xf); | |
2543 | if (frame_size == 0 && (save_inst >> 16) == 0) | |
2544 | frame_size = 16; | |
2545 | frame_size *= 8; | |
2546 | frame_offset += frame_size; | |
2547 | ||
2548 | /* Now we can calculate what the SP must have been at the | |
2549 | start of the function prologue. */ | |
2550 | sp += frame_offset; | |
2551 | ||
2552 | /* Check if A0-A3 were saved in the caller's argument save area. */ | |
2553 | for (reg = MIPS_A0_REGNUM, offset = 0; reg < args + 4; reg++) | |
2554 | { | |
74ed0bb4 | 2555 | set_reg_offset (gdbarch, this_cache, reg, sp + offset); |
2207132d MR |
2556 | offset += mips_abi_regsize (gdbarch); |
2557 | } | |
2558 | ||
2559 | offset = -4; | |
2560 | ||
2561 | /* Check if the RA register was pushed on the stack. */ | |
2562 | if (save_inst & 0x40) | |
2563 | { | |
74ed0bb4 | 2564 | set_reg_offset (gdbarch, this_cache, MIPS_RA_REGNUM, sp + offset); |
2207132d MR |
2565 | offset -= mips_abi_regsize (gdbarch); |
2566 | } | |
2567 | ||
2568 | /* Check if the S8 register was pushed on the stack. */ | |
2569 | if (xsregs > 6) | |
2570 | { | |
74ed0bb4 | 2571 | set_reg_offset (gdbarch, this_cache, 30, sp + offset); |
2207132d MR |
2572 | offset -= mips_abi_regsize (gdbarch); |
2573 | xsregs--; | |
2574 | } | |
2575 | /* Check if S2-S7 were pushed on the stack. */ | |
2576 | for (reg = 18 + xsregs - 1; reg > 18 - 1; reg--) | |
2577 | { | |
74ed0bb4 | 2578 | set_reg_offset (gdbarch, this_cache, reg, sp + offset); |
2207132d MR |
2579 | offset -= mips_abi_regsize (gdbarch); |
2580 | } | |
2581 | ||
2582 | /* Check if the S1 register was pushed on the stack. */ | |
2583 | if (save_inst & 0x10) | |
2584 | { | |
74ed0bb4 | 2585 | set_reg_offset (gdbarch, this_cache, 17, sp + offset); |
2207132d MR |
2586 | offset -= mips_abi_regsize (gdbarch); |
2587 | } | |
2588 | /* Check if the S0 register was pushed on the stack. */ | |
2589 | if (save_inst & 0x20) | |
2590 | { | |
74ed0bb4 | 2591 | set_reg_offset (gdbarch, this_cache, 16, sp + offset); |
2207132d MR |
2592 | offset -= mips_abi_regsize (gdbarch); |
2593 | } | |
2594 | ||
4cc0665f MR |
2595 | /* Check if A0-A3 were pushed on the stack. */ |
2596 | for (reg = MIPS_A0_REGNUM + 3; reg > MIPS_A0_REGNUM + 3 - astatic; reg--) | |
2597 | { | |
2598 | set_reg_offset (gdbarch, this_cache, reg, sp + offset); | |
2599 | offset -= mips_abi_regsize (gdbarch); | |
2600 | } | |
2601 | } | |
2602 | ||
2603 | if (this_cache != NULL) | |
2604 | { | |
2605 | this_cache->base = | |
2606 | (get_frame_register_signed (this_frame, | |
2607 | gdbarch_num_regs (gdbarch) + frame_reg) | |
2608 | + frame_offset - frame_adjust); | |
2609 | /* FIXME: brobecker/2004-10-10: Just as in the mips32 case, we should | |
2610 | be able to get rid of the assignment below, evetually. But it's | |
2611 | still needed for now. */ | |
2612 | this_cache->saved_regs[gdbarch_num_regs (gdbarch) | |
2613 | + mips_regnum (gdbarch)->pc] | |
2614 | = this_cache->saved_regs[gdbarch_num_regs (gdbarch) + MIPS_RA_REGNUM]; | |
2615 | } | |
2616 | ||
2617 | /* If we didn't reach the end of the prologue when scanning the function | |
2618 | instructions, then set end_prologue_addr to the address of the | |
2619 | instruction immediately after the last one we scanned. */ | |
2620 | if (end_prologue_addr == 0) | |
2621 | end_prologue_addr = cur_pc; | |
2622 | ||
2623 | return end_prologue_addr; | |
2624 | } | |
2625 | ||
2626 | /* Heuristic unwinder for 16-bit MIPS instruction set (aka MIPS16). | |
2627 | Procedures that use the 32-bit instruction set are handled by the | |
2628 | mips_insn32 unwinder. */ | |
2629 | ||
2630 | static struct mips_frame_cache * | |
2631 | mips_insn16_frame_cache (struct frame_info *this_frame, void **this_cache) | |
2632 | { | |
2633 | struct gdbarch *gdbarch = get_frame_arch (this_frame); | |
2634 | struct mips_frame_cache *cache; | |
2635 | ||
2636 | if ((*this_cache) != NULL) | |
2637 | return (*this_cache); | |
2638 | cache = FRAME_OBSTACK_ZALLOC (struct mips_frame_cache); | |
2639 | (*this_cache) = cache; | |
2640 | cache->saved_regs = trad_frame_alloc_saved_regs (this_frame); | |
2641 | ||
2642 | /* Analyze the function prologue. */ | |
2643 | { | |
2644 | const CORE_ADDR pc = get_frame_address_in_block (this_frame); | |
2645 | CORE_ADDR start_addr; | |
2646 | ||
2647 | find_pc_partial_function (pc, NULL, &start_addr, NULL); | |
2648 | if (start_addr == 0) | |
2649 | start_addr = heuristic_proc_start (gdbarch, pc); | |
2650 | /* We can't analyze the prologue if we couldn't find the begining | |
2651 | of the function. */ | |
2652 | if (start_addr == 0) | |
2653 | return cache; | |
2654 | ||
2655 | mips16_scan_prologue (gdbarch, start_addr, pc, this_frame, *this_cache); | |
2656 | } | |
2657 | ||
2658 | /* gdbarch_sp_regnum contains the value and not the address. */ | |
2659 | trad_frame_set_value (cache->saved_regs, | |
2660 | gdbarch_num_regs (gdbarch) + MIPS_SP_REGNUM, | |
2661 | cache->base); | |
2662 | ||
2663 | return (*this_cache); | |
2664 | } | |
2665 | ||
2666 | static void | |
2667 | mips_insn16_frame_this_id (struct frame_info *this_frame, void **this_cache, | |
2668 | struct frame_id *this_id) | |
2669 | { | |
2670 | struct mips_frame_cache *info = mips_insn16_frame_cache (this_frame, | |
2671 | this_cache); | |
2672 | /* This marks the outermost frame. */ | |
2673 | if (info->base == 0) | |
2674 | return; | |
2675 | (*this_id) = frame_id_build (info->base, get_frame_func (this_frame)); | |
2676 | } | |
2677 | ||
2678 | static struct value * | |
2679 | mips_insn16_frame_prev_register (struct frame_info *this_frame, | |
2680 | void **this_cache, int regnum) | |
2681 | { | |
2682 | struct mips_frame_cache *info = mips_insn16_frame_cache (this_frame, | |
2683 | this_cache); | |
2684 | return trad_frame_get_prev_register (this_frame, info->saved_regs, regnum); | |
2685 | } | |
2686 | ||
2687 | static int | |
2688 | mips_insn16_frame_sniffer (const struct frame_unwind *self, | |
2689 | struct frame_info *this_frame, void **this_cache) | |
2690 | { | |
2691 | struct gdbarch *gdbarch = get_frame_arch (this_frame); | |
2692 | CORE_ADDR pc = get_frame_pc (this_frame); | |
2693 | if (mips_pc_is_mips16 (gdbarch, pc)) | |
2694 | return 1; | |
2695 | return 0; | |
2696 | } | |
2697 | ||
2698 | static const struct frame_unwind mips_insn16_frame_unwind = | |
2699 | { | |
2700 | NORMAL_FRAME, | |
2701 | default_frame_unwind_stop_reason, | |
2702 | mips_insn16_frame_this_id, | |
2703 | mips_insn16_frame_prev_register, | |
2704 | NULL, | |
2705 | mips_insn16_frame_sniffer | |
2706 | }; | |
2707 | ||
2708 | static CORE_ADDR | |
2709 | mips_insn16_frame_base_address (struct frame_info *this_frame, | |
2710 | void **this_cache) | |
2711 | { | |
2712 | struct mips_frame_cache *info = mips_insn16_frame_cache (this_frame, | |
2713 | this_cache); | |
2714 | return info->base; | |
2715 | } | |
2716 | ||
2717 | static const struct frame_base mips_insn16_frame_base = | |
2718 | { | |
2719 | &mips_insn16_frame_unwind, | |
2720 | mips_insn16_frame_base_address, | |
2721 | mips_insn16_frame_base_address, | |
2722 | mips_insn16_frame_base_address | |
2723 | }; | |
2724 | ||
2725 | static const struct frame_base * | |
2726 | mips_insn16_frame_base_sniffer (struct frame_info *this_frame) | |
2727 | { | |
2728 | struct gdbarch *gdbarch = get_frame_arch (this_frame); | |
2729 | CORE_ADDR pc = get_frame_pc (this_frame); | |
2730 | if (mips_pc_is_mips16 (gdbarch, pc)) | |
2731 | return &mips_insn16_frame_base; | |
2732 | else | |
2733 | return NULL; | |
2734 | } | |
2735 | ||
2736 | /* Decode a 9-bit signed immediate argument of ADDIUSP -- -2 is mapped | |
2737 | to -258, -1 -- to -257, 0 -- to 256, 1 -- to 257 and other values are | |
2738 | interpreted directly, and then multiplied by 4. */ | |
2739 | ||
2740 | static int | |
2741 | micromips_decode_imm9 (int imm) | |
2742 | { | |
2743 | imm = (imm ^ 0x100) - 0x100; | |
2744 | if (imm > -3 && imm < 2) | |
2745 | imm ^= 0x100; | |
2746 | return imm << 2; | |
2747 | } | |
2748 | ||
2749 | /* Analyze the function prologue from START_PC to LIMIT_PC. Return | |
2750 | the address of the first instruction past the prologue. */ | |
2751 | ||
2752 | static CORE_ADDR | |
2753 | micromips_scan_prologue (struct gdbarch *gdbarch, | |
2754 | CORE_ADDR start_pc, CORE_ADDR limit_pc, | |
2755 | struct frame_info *this_frame, | |
2756 | struct mips_frame_cache *this_cache) | |
2757 | { | |
2758 | CORE_ADDR end_prologue_addr = 0; | |
2759 | int prev_non_prologue_insn = 0; | |
2760 | int frame_reg = MIPS_SP_REGNUM; | |
2761 | int this_non_prologue_insn; | |
2762 | int non_prologue_insns = 0; | |
2763 | long frame_offset = 0; /* Size of stack frame. */ | |
2764 | long frame_adjust = 0; /* Offset of FP from SP. */ | |
2765 | CORE_ADDR frame_addr = 0; /* Value of $30, used as frame pointer. */ | |
2766 | CORE_ADDR prev_pc; | |
2767 | CORE_ADDR cur_pc; | |
2768 | ULONGEST insn; /* current instruction */ | |
2769 | CORE_ADDR sp; | |
2770 | long offset; | |
2771 | long sp_adj; | |
2772 | long v1_off = 0; /* The assumption is LUI will replace it. */ | |
2773 | int reglist; | |
2774 | int breg; | |
2775 | int dreg; | |
2776 | int sreg; | |
2777 | int treg; | |
2778 | int loc; | |
2779 | int op; | |
2780 | int s; | |
2781 | int i; | |
2782 | ||
2783 | /* Can be called when there's no process, and hence when there's no | |
2784 | THIS_FRAME. */ | |
2785 | if (this_frame != NULL) | |
2786 | sp = get_frame_register_signed (this_frame, | |
2787 | gdbarch_num_regs (gdbarch) | |
2788 | + MIPS_SP_REGNUM); | |
2789 | else | |
2790 | sp = 0; | |
2791 | ||
2792 | if (limit_pc > start_pc + 200) | |
2793 | limit_pc = start_pc + 200; | |
2794 | prev_pc = start_pc; | |
2795 | ||
2796 | /* Permit at most one non-prologue non-control-transfer instruction | |
2797 | in the middle which may have been reordered by the compiler for | |
2798 | optimisation. */ | |
2799 | for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += loc) | |
2800 | { | |
2801 | this_non_prologue_insn = 0; | |
2802 | sp_adj = 0; | |
2803 | loc = 0; | |
2804 | insn = mips_fetch_instruction (gdbarch, ISA_MICROMIPS, cur_pc, NULL); | |
2805 | loc += MIPS_INSN16_SIZE; | |
2806 | switch (mips_insn_size (ISA_MICROMIPS, insn)) | |
2807 | { | |
2808 | /* 48-bit instructions. */ | |
2809 | case 3 * MIPS_INSN16_SIZE: | |
2810 | /* No prologue instructions in this category. */ | |
2811 | this_non_prologue_insn = 1; | |
2812 | loc += 2 * MIPS_INSN16_SIZE; | |
2813 | break; | |
2814 | ||
2815 | /* 32-bit instructions. */ | |
2816 | case 2 * MIPS_INSN16_SIZE: | |
2817 | insn <<= 16; | |
2818 | insn |= mips_fetch_instruction (gdbarch, | |
2819 | ISA_MICROMIPS, cur_pc + loc, NULL); | |
2820 | loc += MIPS_INSN16_SIZE; | |
2821 | switch (micromips_op (insn >> 16)) | |
2822 | { | |
2823 | /* Record $sp/$fp adjustment. */ | |
2824 | /* Discard (D)ADDU $gp,$jp used for PIC code. */ | |
2825 | case 0x0: /* POOL32A: bits 000000 */ | |
2826 | case 0x16: /* POOL32S: bits 010110 */ | |
2827 | op = b0s11_op (insn); | |
2828 | sreg = b0s5_reg (insn >> 16); | |
2829 | treg = b5s5_reg (insn >> 16); | |
2830 | dreg = b11s5_reg (insn); | |
2831 | if (op == 0x1d0 | |
2832 | /* SUBU: bits 000000 00111010000 */ | |
2833 | /* DSUBU: bits 010110 00111010000 */ | |
2834 | && dreg == MIPS_SP_REGNUM && sreg == MIPS_SP_REGNUM | |
2835 | && treg == 3) | |
2836 | /* (D)SUBU $sp, $v1 */ | |
2837 | sp_adj = v1_off; | |
2838 | else if (op != 0x150 | |
2839 | /* ADDU: bits 000000 00101010000 */ | |
2840 | /* DADDU: bits 010110 00101010000 */ | |
2841 | || dreg != 28 || sreg != 28 || treg != MIPS_T9_REGNUM) | |
2842 | this_non_prologue_insn = 1; | |
2843 | break; | |
2844 | ||
2845 | case 0x8: /* POOL32B: bits 001000 */ | |
2846 | op = b12s4_op (insn); | |
2847 | breg = b0s5_reg (insn >> 16); | |
2848 | reglist = sreg = b5s5_reg (insn >> 16); | |
2849 | offset = (b0s12_imm (insn) ^ 0x800) - 0x800; | |
2850 | if ((op == 0x9 || op == 0xc) | |
2851 | /* SWP: bits 001000 1001 */ | |
2852 | /* SDP: bits 001000 1100 */ | |
2853 | && breg == MIPS_SP_REGNUM && sreg < MIPS_RA_REGNUM) | |
2854 | /* S[DW]P reg,offset($sp) */ | |
2855 | { | |
2856 | s = 4 << ((b12s4_op (insn) & 0x4) == 0x4); | |
2857 | set_reg_offset (gdbarch, this_cache, | |
2858 | sreg, sp + offset); | |
2859 | set_reg_offset (gdbarch, this_cache, | |
2860 | sreg + 1, sp + offset + s); | |
2861 | } | |
2862 | else if ((op == 0xd || op == 0xf) | |
2863 | /* SWM: bits 001000 1101 */ | |
2864 | /* SDM: bits 001000 1111 */ | |
2865 | && breg == MIPS_SP_REGNUM | |
2866 | /* SWM reglist,offset($sp) */ | |
2867 | && ((reglist >= 1 && reglist <= 9) | |
2868 | || (reglist >= 16 && reglist <= 25))) | |
2869 | { | |
2870 | int sreglist = min(reglist & 0xf, 8); | |
2871 | ||
2872 | s = 4 << ((b12s4_op (insn) & 0x2) == 0x2); | |
2873 | for (i = 0; i < sreglist; i++) | |
2874 | set_reg_offset (gdbarch, this_cache, 16 + i, sp + s * i); | |
2875 | if ((reglist & 0xf) > 8) | |
2876 | set_reg_offset (gdbarch, this_cache, 30, sp + s * i++); | |
2877 | if ((reglist & 0x10) == 0x10) | |
2878 | set_reg_offset (gdbarch, this_cache, | |
2879 | MIPS_RA_REGNUM, sp + s * i++); | |
2880 | } | |
2881 | else | |
2882 | this_non_prologue_insn = 1; | |
2883 | break; | |
2884 | ||
2885 | /* Record $sp/$fp adjustment. */ | |
2886 | /* Discard (D)ADDIU $gp used for PIC code. */ | |
2887 | case 0xc: /* ADDIU: bits 001100 */ | |
2888 | case 0x17: /* DADDIU: bits 010111 */ | |
2889 | sreg = b0s5_reg (insn >> 16); | |
2890 | dreg = b5s5_reg (insn >> 16); | |
2891 | offset = (b0s16_imm (insn) ^ 0x8000) - 0x8000; | |
2892 | if (sreg == MIPS_SP_REGNUM && dreg == MIPS_SP_REGNUM) | |
2893 | /* (D)ADDIU $sp, imm */ | |
2894 | sp_adj = offset; | |
2895 | else if (sreg == MIPS_SP_REGNUM && dreg == 30) | |
2896 | /* (D)ADDIU $fp, $sp, imm */ | |
2897 | { | |
2898 | frame_addr = sp + offset; | |
2899 | frame_adjust = offset; | |
2900 | frame_reg = 30; | |
2901 | } | |
2902 | else if (sreg != 28 || dreg != 28) | |
2903 | /* (D)ADDIU $gp, imm */ | |
2904 | this_non_prologue_insn = 1; | |
2905 | break; | |
2906 | ||
2907 | /* LUI $v1 is used for larger $sp adjustments. */ | |
2908 | /* Discard LUI $gp is used for PIC code. */ | |
2909 | case 0x10: /* POOL32I: bits 010000 */ | |
2910 | if (b5s5_op (insn >> 16) == 0xd | |
2911 | /* LUI: bits 010000 001101 */ | |
2912 | && b0s5_reg (insn >> 16) == 3) | |
2913 | /* LUI $v1, imm */ | |
2914 | v1_off = ((b0s16_imm (insn) << 16) ^ 0x80000000) - 0x80000000; | |
2915 | else if (b5s5_op (insn >> 16) != 0xd | |
2916 | /* LUI: bits 010000 001101 */ | |
2917 | || b0s5_reg (insn >> 16) != 28) | |
2918 | /* LUI $gp, imm */ | |
2919 | this_non_prologue_insn = 1; | |
2920 | break; | |
2921 | ||
2922 | /* ORI $v1 is used for larger $sp adjustments. */ | |
2923 | case 0x14: /* ORI: bits 010100 */ | |
2924 | sreg = b0s5_reg (insn >> 16); | |
2925 | dreg = b5s5_reg (insn >> 16); | |
2926 | if (sreg == 3 && dreg == 3) | |
2927 | /* ORI $v1, imm */ | |
2928 | v1_off |= b0s16_imm (insn); | |
2929 | else | |
2930 | this_non_prologue_insn = 1; | |
2931 | break; | |
2932 | ||
2933 | case 0x26: /* SWC1: bits 100110 */ | |
2934 | case 0x2e: /* SDC1: bits 101110 */ | |
2935 | breg = b0s5_reg (insn >> 16); | |
2936 | if (breg != MIPS_SP_REGNUM) | |
2937 | /* S[DW]C1 reg,offset($sp) */ | |
2938 | this_non_prologue_insn = 1; | |
2939 | break; | |
2940 | ||
2941 | case 0x36: /* SD: bits 110110 */ | |
2942 | case 0x3e: /* SW: bits 111110 */ | |
2943 | breg = b0s5_reg (insn >> 16); | |
2944 | sreg = b5s5_reg (insn >> 16); | |
2945 | offset = (b0s16_imm (insn) ^ 0x8000) - 0x8000; | |
2946 | if (breg == MIPS_SP_REGNUM) | |
2947 | /* S[DW] reg,offset($sp) */ | |
2948 | set_reg_offset (gdbarch, this_cache, sreg, sp + offset); | |
2949 | else | |
2950 | this_non_prologue_insn = 1; | |
2951 | break; | |
2952 | ||
2953 | default: | |
2954 | this_non_prologue_insn = 1; | |
2955 | break; | |
2956 | } | |
2957 | break; | |
2958 | ||
2959 | /* 16-bit instructions. */ | |
2960 | case MIPS_INSN16_SIZE: | |
2961 | switch (micromips_op (insn)) | |
2962 | { | |
2963 | case 0x3: /* MOVE: bits 000011 */ | |
2964 | sreg = b0s5_reg (insn); | |
2965 | dreg = b5s5_reg (insn); | |
2966 | if (sreg == MIPS_SP_REGNUM && dreg == 30) | |
2967 | /* MOVE $fp, $sp */ | |
2968 | { | |
2969 | frame_addr = sp; | |
2970 | frame_reg = 30; | |
2971 | } | |
2972 | else if ((sreg & 0x1c) != 0x4) | |
2973 | /* MOVE reg, $a0-$a3 */ | |
2974 | this_non_prologue_insn = 1; | |
2975 | break; | |
2976 | ||
2977 | case 0x11: /* POOL16C: bits 010001 */ | |
2978 | if (b6s4_op (insn) == 0x5) | |
2979 | /* SWM: bits 010001 0101 */ | |
2980 | { | |
2981 | offset = ((b0s4_imm (insn) << 2) ^ 0x20) - 0x20; | |
2982 | reglist = b4s2_regl (insn); | |
2983 | for (i = 0; i <= reglist; i++) | |
2984 | set_reg_offset (gdbarch, this_cache, 16 + i, sp + 4 * i); | |
2985 | set_reg_offset (gdbarch, this_cache, | |
2986 | MIPS_RA_REGNUM, sp + 4 * i++); | |
2987 | } | |
2988 | else | |
2989 | this_non_prologue_insn = 1; | |
2990 | break; | |
2991 | ||
2992 | case 0x13: /* POOL16D: bits 010011 */ | |
2993 | if ((insn & 0x1) == 0x1) | |
2994 | /* ADDIUSP: bits 010011 1 */ | |
2995 | sp_adj = micromips_decode_imm9 (b1s9_imm (insn)); | |
2996 | else if (b5s5_reg (insn) == MIPS_SP_REGNUM) | |
2997 | /* ADDIUS5: bits 010011 0 */ | |
2998 | /* ADDIUS5 $sp, imm */ | |
2999 | sp_adj = (b1s4_imm (insn) ^ 8) - 8; | |
3000 | else | |
3001 | this_non_prologue_insn = 1; | |
3002 | break; | |
3003 | ||
3004 | case 0x32: /* SWSP: bits 110010 */ | |
3005 | offset = b0s5_imm (insn) << 2; | |
3006 | sreg = b5s5_reg (insn); | |
3007 | set_reg_offset (gdbarch, this_cache, sreg, sp + offset); | |
3008 | break; | |
3009 | ||
3010 | default: | |
3011 | this_non_prologue_insn = 1; | |
3012 | break; | |
3013 | } | |
3014 | break; | |
3015 | } | |
3016 | if (sp_adj < 0) | |
3017 | frame_offset -= sp_adj; | |
3018 | ||
3019 | non_prologue_insns += this_non_prologue_insn; | |
3020 | /* Enough non-prologue insns seen or positive stack adjustment? */ | |
3021 | if (end_prologue_addr == 0 && (non_prologue_insns > 1 || sp_adj > 0)) | |
2207132d | 3022 | { |
4cc0665f MR |
3023 | end_prologue_addr = prev_non_prologue_insn ? prev_pc : cur_pc; |
3024 | break; | |
2207132d | 3025 | } |
4cc0665f MR |
3026 | prev_non_prologue_insn = this_non_prologue_insn; |
3027 | prev_pc = cur_pc; | |
2207132d MR |
3028 | } |
3029 | ||
29639122 JB |
3030 | if (this_cache != NULL) |
3031 | { | |
3032 | this_cache->base = | |
4cc0665f | 3033 | (get_frame_register_signed (this_frame, |
b8a22b94 | 3034 | gdbarch_num_regs (gdbarch) + frame_reg) |
4cc0665f | 3035 | + frame_offset - frame_adjust); |
29639122 | 3036 | /* FIXME: brobecker/2004-10-10: Just as in the mips32 case, we should |
4cc0665f MR |
3037 | be able to get rid of the assignment below, evetually. But it's |
3038 | still needed for now. */ | |
72a155b4 UW |
3039 | this_cache->saved_regs[gdbarch_num_regs (gdbarch) |
3040 | + mips_regnum (gdbarch)->pc] | |
4cc0665f | 3041 | = this_cache->saved_regs[gdbarch_num_regs (gdbarch) + MIPS_RA_REGNUM]; |
29639122 JB |
3042 | } |
3043 | ||
3044 | /* If we didn't reach the end of the prologue when scanning the function | |
3045 | instructions, then set end_prologue_addr to the address of the | |
4cc0665f MR |
3046 | instruction immediately after the last one we scanned. Unless the |
3047 | last one looked like a non-prologue instruction (and we looked ahead), | |
3048 | in which case use its address instead. */ | |
29639122 | 3049 | if (end_prologue_addr == 0) |
4cc0665f | 3050 | end_prologue_addr = prev_non_prologue_insn ? prev_pc : cur_pc; |
29639122 JB |
3051 | |
3052 | return end_prologue_addr; | |
eec63939 AC |
3053 | } |
3054 | ||
4cc0665f | 3055 | /* Heuristic unwinder for procedures using microMIPS instructions. |
29639122 | 3056 | Procedures that use the 32-bit instruction set are handled by the |
4cc0665f | 3057 | mips_insn32 unwinder. Likewise MIPS16 and the mips_insn16 unwinder. */ |
29639122 JB |
3058 | |
3059 | static struct mips_frame_cache * | |
4cc0665f | 3060 | mips_micro_frame_cache (struct frame_info *this_frame, void **this_cache) |
eec63939 | 3061 | { |
e17a4113 | 3062 | struct gdbarch *gdbarch = get_frame_arch (this_frame); |
29639122 | 3063 | struct mips_frame_cache *cache; |
eec63939 AC |
3064 | |
3065 | if ((*this_cache) != NULL) | |
3066 | return (*this_cache); | |
4cc0665f | 3067 | |
29639122 JB |
3068 | cache = FRAME_OBSTACK_ZALLOC (struct mips_frame_cache); |
3069 | (*this_cache) = cache; | |
b8a22b94 | 3070 | cache->saved_regs = trad_frame_alloc_saved_regs (this_frame); |
eec63939 | 3071 | |
29639122 JB |
3072 | /* Analyze the function prologue. */ |
3073 | { | |
b8a22b94 | 3074 | const CORE_ADDR pc = get_frame_address_in_block (this_frame); |
29639122 | 3075 | CORE_ADDR start_addr; |
eec63939 | 3076 | |
29639122 JB |
3077 | find_pc_partial_function (pc, NULL, &start_addr, NULL); |
3078 | if (start_addr == 0) | |
4cc0665f | 3079 | start_addr = heuristic_proc_start (get_frame_arch (this_frame), pc); |
29639122 JB |
3080 | /* We can't analyze the prologue if we couldn't find the begining |
3081 | of the function. */ | |
3082 | if (start_addr == 0) | |
3083 | return cache; | |
eec63939 | 3084 | |
4cc0665f | 3085 | micromips_scan_prologue (gdbarch, start_addr, pc, this_frame, *this_cache); |
29639122 | 3086 | } |
4cc0665f | 3087 | |
3e8c568d | 3088 | /* gdbarch_sp_regnum contains the value and not the address. */ |
72a155b4 | 3089 | trad_frame_set_value (cache->saved_regs, |
e17a4113 | 3090 | gdbarch_num_regs (gdbarch) + MIPS_SP_REGNUM, |
72a155b4 | 3091 | cache->base); |
eec63939 | 3092 | |
29639122 | 3093 | return (*this_cache); |
eec63939 AC |
3094 | } |
3095 | ||
3096 | static void | |
4cc0665f MR |
3097 | mips_micro_frame_this_id (struct frame_info *this_frame, void **this_cache, |
3098 | struct frame_id *this_id) | |
eec63939 | 3099 | { |
4cc0665f MR |
3100 | struct mips_frame_cache *info = mips_micro_frame_cache (this_frame, |
3101 | this_cache); | |
21327321 DJ |
3102 | /* This marks the outermost frame. */ |
3103 | if (info->base == 0) | |
3104 | return; | |
b8a22b94 | 3105 | (*this_id) = frame_id_build (info->base, get_frame_func (this_frame)); |
eec63939 AC |
3106 | } |
3107 | ||
b8a22b94 | 3108 | static struct value * |
4cc0665f MR |
3109 | mips_micro_frame_prev_register (struct frame_info *this_frame, |
3110 | void **this_cache, int regnum) | |
eec63939 | 3111 | { |
4cc0665f MR |
3112 | struct mips_frame_cache *info = mips_micro_frame_cache (this_frame, |
3113 | this_cache); | |
b8a22b94 DJ |
3114 | return trad_frame_get_prev_register (this_frame, info->saved_regs, regnum); |
3115 | } | |
3116 | ||
3117 | static int | |
4cc0665f MR |
3118 | mips_micro_frame_sniffer (const struct frame_unwind *self, |
3119 | struct frame_info *this_frame, void **this_cache) | |
b8a22b94 | 3120 | { |
4cc0665f | 3121 | struct gdbarch *gdbarch = get_frame_arch (this_frame); |
b8a22b94 | 3122 | CORE_ADDR pc = get_frame_pc (this_frame); |
4cc0665f MR |
3123 | |
3124 | if (mips_pc_is_micromips (gdbarch, pc)) | |
b8a22b94 DJ |
3125 | return 1; |
3126 | return 0; | |
eec63939 AC |
3127 | } |
3128 | ||
4cc0665f | 3129 | static const struct frame_unwind mips_micro_frame_unwind = |
eec63939 AC |
3130 | { |
3131 | NORMAL_FRAME, | |
8fbca658 | 3132 | default_frame_unwind_stop_reason, |
4cc0665f MR |
3133 | mips_micro_frame_this_id, |
3134 | mips_micro_frame_prev_register, | |
b8a22b94 | 3135 | NULL, |
4cc0665f | 3136 | mips_micro_frame_sniffer |
eec63939 AC |
3137 | }; |
3138 | ||
eec63939 | 3139 | static CORE_ADDR |
4cc0665f MR |
3140 | mips_micro_frame_base_address (struct frame_info *this_frame, |
3141 | void **this_cache) | |
eec63939 | 3142 | { |
4cc0665f MR |
3143 | struct mips_frame_cache *info = mips_micro_frame_cache (this_frame, |
3144 | this_cache); | |
29639122 | 3145 | return info->base; |
eec63939 AC |
3146 | } |
3147 | ||
4cc0665f | 3148 | static const struct frame_base mips_micro_frame_base = |
eec63939 | 3149 | { |
4cc0665f MR |
3150 | &mips_micro_frame_unwind, |
3151 | mips_micro_frame_base_address, | |
3152 | mips_micro_frame_base_address, | |
3153 | mips_micro_frame_base_address | |
eec63939 AC |
3154 | }; |
3155 | ||
3156 | static const struct frame_base * | |
4cc0665f | 3157 | mips_micro_frame_base_sniffer (struct frame_info *this_frame) |
eec63939 | 3158 | { |
4cc0665f | 3159 | struct gdbarch *gdbarch = get_frame_arch (this_frame); |
b8a22b94 | 3160 | CORE_ADDR pc = get_frame_pc (this_frame); |
4cc0665f MR |
3161 | |
3162 | if (mips_pc_is_micromips (gdbarch, pc)) | |
3163 | return &mips_micro_frame_base; | |
eec63939 AC |
3164 | else |
3165 | return NULL; | |
edfae063 AC |
3166 | } |
3167 | ||
29639122 JB |
3168 | /* Mark all the registers as unset in the saved_regs array |
3169 | of THIS_CACHE. Do nothing if THIS_CACHE is null. */ | |
3170 | ||
74ed0bb4 MD |
3171 | static void |
3172 | reset_saved_regs (struct gdbarch *gdbarch, struct mips_frame_cache *this_cache) | |
c906108c | 3173 | { |
29639122 JB |
3174 | if (this_cache == NULL || this_cache->saved_regs == NULL) |
3175 | return; | |
3176 | ||
3177 | { | |
74ed0bb4 | 3178 | const int num_regs = gdbarch_num_regs (gdbarch); |
29639122 | 3179 | int i; |
64159455 | 3180 | |
29639122 JB |
3181 | for (i = 0; i < num_regs; i++) |
3182 | { | |
3183 | this_cache->saved_regs[i].addr = -1; | |
3184 | } | |
3185 | } | |
c906108c SS |
3186 | } |
3187 | ||
025bb325 | 3188 | /* Analyze the function prologue from START_PC to LIMIT_PC. Builds |
29639122 JB |
3189 | the associated FRAME_CACHE if not null. |
3190 | Return the address of the first instruction past the prologue. */ | |
c906108c | 3191 | |
875e1767 | 3192 | static CORE_ADDR |
e17a4113 UW |
3193 | mips32_scan_prologue (struct gdbarch *gdbarch, |
3194 | CORE_ADDR start_pc, CORE_ADDR limit_pc, | |
b8a22b94 | 3195 | struct frame_info *this_frame, |
29639122 | 3196 | struct mips_frame_cache *this_cache) |
c906108c | 3197 | { |
29639122 | 3198 | CORE_ADDR cur_pc; |
025bb325 MS |
3199 | CORE_ADDR frame_addr = 0; /* Value of $r30. Used by gcc for |
3200 | frame-pointer. */ | |
29639122 JB |
3201 | CORE_ADDR sp; |
3202 | long frame_offset; | |
3203 | int frame_reg = MIPS_SP_REGNUM; | |
8fa9cfa1 | 3204 | |
29639122 JB |
3205 | CORE_ADDR end_prologue_addr = 0; |
3206 | int seen_sp_adjust = 0; | |
3207 | int load_immediate_bytes = 0; | |
db5f024e | 3208 | int in_delay_slot = 0; |
7d1e6fb8 | 3209 | int regsize_is_64_bits = (mips_abi_regsize (gdbarch) == 8); |
8fa9cfa1 | 3210 | |
29639122 | 3211 | /* Can be called when there's no process, and hence when there's no |
b8a22b94 DJ |
3212 | THIS_FRAME. */ |
3213 | if (this_frame != NULL) | |
3214 | sp = get_frame_register_signed (this_frame, | |
3215 | gdbarch_num_regs (gdbarch) | |
3216 | + MIPS_SP_REGNUM); | |
8fa9cfa1 | 3217 | else |
29639122 | 3218 | sp = 0; |
9022177c | 3219 | |
29639122 JB |
3220 | if (limit_pc > start_pc + 200) |
3221 | limit_pc = start_pc + 200; | |
9022177c | 3222 | |
29639122 | 3223 | restart: |
9022177c | 3224 | |
29639122 | 3225 | frame_offset = 0; |
95ac2dcf | 3226 | for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += MIPS_INSN32_SIZE) |
9022177c | 3227 | { |
29639122 JB |
3228 | unsigned long inst, high_word, low_word; |
3229 | int reg; | |
9022177c | 3230 | |
025bb325 | 3231 | /* Fetch the instruction. */ |
4cc0665f MR |
3232 | inst = (unsigned long) mips_fetch_instruction (gdbarch, ISA_MIPS, |
3233 | cur_pc, NULL); | |
9022177c | 3234 | |
29639122 JB |
3235 | /* Save some code by pre-extracting some useful fields. */ |
3236 | high_word = (inst >> 16) & 0xffff; | |
3237 | low_word = inst & 0xffff; | |
3238 | reg = high_word & 0x1f; | |
fe29b929 | 3239 | |
025bb325 | 3240 | if (high_word == 0x27bd /* addiu $sp,$sp,-i */ |
29639122 JB |
3241 | || high_word == 0x23bd /* addi $sp,$sp,-i */ |
3242 | || high_word == 0x67bd) /* daddiu $sp,$sp,-i */ | |
3243 | { | |
025bb325 | 3244 | if (low_word & 0x8000) /* Negative stack adjustment? */ |
29639122 JB |
3245 | frame_offset += 0x10000 - low_word; |
3246 | else | |
3247 | /* Exit loop if a positive stack adjustment is found, which | |
3248 | usually means that the stack cleanup code in the function | |
3249 | epilogue is reached. */ | |
3250 | break; | |
3251 | seen_sp_adjust = 1; | |
3252 | } | |
7d1e6fb8 KB |
3253 | else if (((high_word & 0xFFE0) == 0xafa0) /* sw reg,offset($sp) */ |
3254 | && !regsize_is_64_bits) | |
29639122 | 3255 | { |
74ed0bb4 | 3256 | set_reg_offset (gdbarch, this_cache, reg, sp + low_word); |
29639122 | 3257 | } |
7d1e6fb8 KB |
3258 | else if (((high_word & 0xFFE0) == 0xffa0) /* sd reg,offset($sp) */ |
3259 | && regsize_is_64_bits) | |
29639122 JB |
3260 | { |
3261 | /* Irix 6.2 N32 ABI uses sd instructions for saving $gp and $ra. */ | |
74ed0bb4 | 3262 | set_reg_offset (gdbarch, this_cache, reg, sp + low_word); |
29639122 JB |
3263 | } |
3264 | else if (high_word == 0x27be) /* addiu $30,$sp,size */ | |
3265 | { | |
3266 | /* Old gcc frame, r30 is virtual frame pointer. */ | |
3267 | if ((long) low_word != frame_offset) | |
3268 | frame_addr = sp + low_word; | |
b8a22b94 | 3269 | else if (this_frame && frame_reg == MIPS_SP_REGNUM) |
29639122 JB |
3270 | { |
3271 | unsigned alloca_adjust; | |
a4b8ebc8 | 3272 | |
29639122 | 3273 | frame_reg = 30; |
b8a22b94 DJ |
3274 | frame_addr = get_frame_register_signed |
3275 | (this_frame, gdbarch_num_regs (gdbarch) + 30); | |
ca9c94ef | 3276 | frame_offset = 0; |
d2ca4222 | 3277 | |
29639122 JB |
3278 | alloca_adjust = (unsigned) (frame_addr - (sp + low_word)); |
3279 | if (alloca_adjust > 0) | |
3280 | { | |
025bb325 | 3281 | /* FP > SP + frame_size. This may be because of |
29639122 JB |
3282 | an alloca or somethings similar. Fix sp to |
3283 | "pre-alloca" value, and try again. */ | |
3284 | sp += alloca_adjust; | |
3285 | /* Need to reset the status of all registers. Otherwise, | |
3286 | we will hit a guard that prevents the new address | |
3287 | for each register to be recomputed during the second | |
3288 | pass. */ | |
74ed0bb4 | 3289 | reset_saved_regs (gdbarch, this_cache); |
29639122 JB |
3290 | goto restart; |
3291 | } | |
3292 | } | |
3293 | } | |
3294 | /* move $30,$sp. With different versions of gas this will be either | |
3295 | `addu $30,$sp,$zero' or `or $30,$sp,$zero' or `daddu 30,sp,$0'. | |
3296 | Accept any one of these. */ | |
3297 | else if (inst == 0x03A0F021 || inst == 0x03a0f025 || inst == 0x03a0f02d) | |
3298 | { | |
3299 | /* New gcc frame, virtual frame pointer is at r30 + frame_size. */ | |
b8a22b94 | 3300 | if (this_frame && frame_reg == MIPS_SP_REGNUM) |
29639122 JB |
3301 | { |
3302 | unsigned alloca_adjust; | |
c906108c | 3303 | |
29639122 | 3304 | frame_reg = 30; |
b8a22b94 DJ |
3305 | frame_addr = get_frame_register_signed |
3306 | (this_frame, gdbarch_num_regs (gdbarch) + 30); | |
d2ca4222 | 3307 | |
29639122 JB |
3308 | alloca_adjust = (unsigned) (frame_addr - sp); |
3309 | if (alloca_adjust > 0) | |
3310 | { | |
025bb325 | 3311 | /* FP > SP + frame_size. This may be because of |
29639122 JB |
3312 | an alloca or somethings similar. Fix sp to |
3313 | "pre-alloca" value, and try again. */ | |
3314 | sp = frame_addr; | |
3315 | /* Need to reset the status of all registers. Otherwise, | |
3316 | we will hit a guard that prevents the new address | |
3317 | for each register to be recomputed during the second | |
3318 | pass. */ | |
74ed0bb4 | 3319 | reset_saved_regs (gdbarch, this_cache); |
29639122 JB |
3320 | goto restart; |
3321 | } | |
3322 | } | |
3323 | } | |
7d1e6fb8 KB |
3324 | else if ((high_word & 0xFFE0) == 0xafc0 /* sw reg,offset($30) */ |
3325 | && !regsize_is_64_bits) | |
29639122 | 3326 | { |
74ed0bb4 | 3327 | set_reg_offset (gdbarch, this_cache, reg, frame_addr + low_word); |
29639122 JB |
3328 | } |
3329 | else if ((high_word & 0xFFE0) == 0xE7A0 /* swc1 freg,n($sp) */ | |
3330 | || (high_word & 0xF3E0) == 0xA3C0 /* sx reg,n($s8) */ | |
3331 | || (inst & 0xFF9F07FF) == 0x00800021 /* move reg,$a0-$a3 */ | |
3332 | || high_word == 0x3c1c /* lui $gp,n */ | |
3333 | || high_word == 0x279c /* addiu $gp,$gp,n */ | |
3334 | || inst == 0x0399e021 /* addu $gp,$gp,$t9 */ | |
3335 | || inst == 0x033ce021 /* addu $gp,$t9,$gp */ | |
3336 | ) | |
19080931 MR |
3337 | { |
3338 | /* These instructions are part of the prologue, but we don't | |
3339 | need to do anything special to handle them. */ | |
3340 | } | |
29639122 JB |
3341 | /* The instructions below load $at or $t0 with an immediate |
3342 | value in preparation for a stack adjustment via | |
025bb325 | 3343 | subu $sp,$sp,[$at,$t0]. These instructions could also |
29639122 JB |
3344 | initialize a local variable, so we accept them only before |
3345 | a stack adjustment instruction was seen. */ | |
3346 | else if (!seen_sp_adjust | |
19080931 MR |
3347 | && (high_word == 0x3c01 /* lui $at,n */ |
3348 | || high_word == 0x3c08 /* lui $t0,n */ | |
3349 | || high_word == 0x3421 /* ori $at,$at,n */ | |
3350 | || high_word == 0x3508 /* ori $t0,$t0,n */ | |
3351 | || high_word == 0x3401 /* ori $at,$zero,n */ | |
3352 | || high_word == 0x3408 /* ori $t0,$zero,n */ | |
3353 | )) | |
3354 | { | |
3355 | if (end_prologue_addr == 0) | |
3356 | load_immediate_bytes += MIPS_INSN32_SIZE; /* FIXME! */ | |
3357 | } | |
29639122 | 3358 | else |
19080931 MR |
3359 | { |
3360 | /* This instruction is not an instruction typically found | |
3361 | in a prologue, so we must have reached the end of the | |
3362 | prologue. */ | |
3363 | /* FIXME: brobecker/2004-10-10: Can't we just break out of this | |
3364 | loop now? Why would we need to continue scanning the function | |
3365 | instructions? */ | |
3366 | if (end_prologue_addr == 0) | |
3367 | end_prologue_addr = cur_pc; | |
3368 | ||
3369 | /* Check for branches and jumps. For now, only jump to | |
3370 | register are caught (i.e. returns). */ | |
3371 | if ((itype_op (inst) & 0x07) == 0 && rtype_funct (inst) == 8) | |
3372 | in_delay_slot = 1; | |
3373 | } | |
db5f024e DJ |
3374 | |
3375 | /* If the previous instruction was a jump, we must have reached | |
3376 | the end of the prologue by now. Stop scanning so that we do | |
3377 | not go past the function return. */ | |
3378 | if (in_delay_slot) | |
3379 | break; | |
a4b8ebc8 | 3380 | } |
c906108c | 3381 | |
29639122 JB |
3382 | if (this_cache != NULL) |
3383 | { | |
3384 | this_cache->base = | |
b8a22b94 DJ |
3385 | (get_frame_register_signed (this_frame, |
3386 | gdbarch_num_regs (gdbarch) + frame_reg) | |
29639122 JB |
3387 | + frame_offset); |
3388 | /* FIXME: brobecker/2004-09-15: We should be able to get rid of | |
3389 | this assignment below, eventually. But it's still needed | |
3390 | for now. */ | |
72a155b4 UW |
3391 | this_cache->saved_regs[gdbarch_num_regs (gdbarch) |
3392 | + mips_regnum (gdbarch)->pc] | |
3393 | = this_cache->saved_regs[gdbarch_num_regs (gdbarch) | |
f57d151a | 3394 | + MIPS_RA_REGNUM]; |
29639122 | 3395 | } |
c906108c | 3396 | |
29639122 JB |
3397 | /* If we didn't reach the end of the prologue when scanning the function |
3398 | instructions, then set end_prologue_addr to the address of the | |
3399 | instruction immediately after the last one we scanned. */ | |
3400 | /* brobecker/2004-10-10: I don't think this would ever happen, but | |
3401 | we may as well be careful and do our best if we have a null | |
3402 | end_prologue_addr. */ | |
3403 | if (end_prologue_addr == 0) | |
3404 | end_prologue_addr = cur_pc; | |
3405 | ||
3406 | /* In a frameless function, we might have incorrectly | |
025bb325 | 3407 | skipped some load immediate instructions. Undo the skipping |
29639122 JB |
3408 | if the load immediate was not followed by a stack adjustment. */ |
3409 | if (load_immediate_bytes && !seen_sp_adjust) | |
3410 | end_prologue_addr -= load_immediate_bytes; | |
c906108c | 3411 | |
29639122 | 3412 | return end_prologue_addr; |
c906108c SS |
3413 | } |
3414 | ||
29639122 JB |
3415 | /* Heuristic unwinder for procedures using 32-bit instructions (covers |
3416 | both 32-bit and 64-bit MIPS ISAs). Procedures using 16-bit | |
3417 | instructions (a.k.a. MIPS16) are handled by the mips_insn16 | |
4cc0665f | 3418 | unwinder. Likewise microMIPS and the mips_micro unwinder. */ |
c906108c | 3419 | |
29639122 | 3420 | static struct mips_frame_cache * |
b8a22b94 | 3421 | mips_insn32_frame_cache (struct frame_info *this_frame, void **this_cache) |
c906108c | 3422 | { |
e17a4113 | 3423 | struct gdbarch *gdbarch = get_frame_arch (this_frame); |
29639122 | 3424 | struct mips_frame_cache *cache; |
c906108c | 3425 | |
29639122 JB |
3426 | if ((*this_cache) != NULL) |
3427 | return (*this_cache); | |
c5aa993b | 3428 | |
29639122 JB |
3429 | cache = FRAME_OBSTACK_ZALLOC (struct mips_frame_cache); |
3430 | (*this_cache) = cache; | |
b8a22b94 | 3431 | cache->saved_regs = trad_frame_alloc_saved_regs (this_frame); |
c5aa993b | 3432 | |
29639122 JB |
3433 | /* Analyze the function prologue. */ |
3434 | { | |
b8a22b94 | 3435 | const CORE_ADDR pc = get_frame_address_in_block (this_frame); |
29639122 | 3436 | CORE_ADDR start_addr; |
c906108c | 3437 | |
29639122 JB |
3438 | find_pc_partial_function (pc, NULL, &start_addr, NULL); |
3439 | if (start_addr == 0) | |
e17a4113 | 3440 | start_addr = heuristic_proc_start (gdbarch, pc); |
29639122 JB |
3441 | /* We can't analyze the prologue if we couldn't find the begining |
3442 | of the function. */ | |
3443 | if (start_addr == 0) | |
3444 | return cache; | |
c5aa993b | 3445 | |
e17a4113 | 3446 | mips32_scan_prologue (gdbarch, start_addr, pc, this_frame, *this_cache); |
29639122 JB |
3447 | } |
3448 | ||
3e8c568d | 3449 | /* gdbarch_sp_regnum contains the value and not the address. */ |
f57d151a | 3450 | trad_frame_set_value (cache->saved_regs, |
e17a4113 | 3451 | gdbarch_num_regs (gdbarch) + MIPS_SP_REGNUM, |
f57d151a | 3452 | cache->base); |
c5aa993b | 3453 | |
29639122 | 3454 | return (*this_cache); |
c906108c SS |
3455 | } |
3456 | ||
29639122 | 3457 | static void |
b8a22b94 | 3458 | mips_insn32_frame_this_id (struct frame_info *this_frame, void **this_cache, |
29639122 | 3459 | struct frame_id *this_id) |
c906108c | 3460 | { |
b8a22b94 | 3461 | struct mips_frame_cache *info = mips_insn32_frame_cache (this_frame, |
29639122 | 3462 | this_cache); |
21327321 DJ |
3463 | /* This marks the outermost frame. */ |
3464 | if (info->base == 0) | |
3465 | return; | |
b8a22b94 | 3466 | (*this_id) = frame_id_build (info->base, get_frame_func (this_frame)); |
29639122 | 3467 | } |
c906108c | 3468 | |
b8a22b94 DJ |
3469 | static struct value * |
3470 | mips_insn32_frame_prev_register (struct frame_info *this_frame, | |
3471 | void **this_cache, int regnum) | |
29639122 | 3472 | { |
b8a22b94 | 3473 | struct mips_frame_cache *info = mips_insn32_frame_cache (this_frame, |
29639122 | 3474 | this_cache); |
b8a22b94 DJ |
3475 | return trad_frame_get_prev_register (this_frame, info->saved_regs, regnum); |
3476 | } | |
3477 | ||
3478 | static int | |
3479 | mips_insn32_frame_sniffer (const struct frame_unwind *self, | |
3480 | struct frame_info *this_frame, void **this_cache) | |
3481 | { | |
3482 | CORE_ADDR pc = get_frame_pc (this_frame); | |
4cc0665f | 3483 | if (mips_pc_is_mips (pc)) |
b8a22b94 DJ |
3484 | return 1; |
3485 | return 0; | |
c906108c SS |
3486 | } |
3487 | ||
29639122 JB |
3488 | static const struct frame_unwind mips_insn32_frame_unwind = |
3489 | { | |
3490 | NORMAL_FRAME, | |
8fbca658 | 3491 | default_frame_unwind_stop_reason, |
29639122 | 3492 | mips_insn32_frame_this_id, |
b8a22b94 DJ |
3493 | mips_insn32_frame_prev_register, |
3494 | NULL, | |
3495 | mips_insn32_frame_sniffer | |
29639122 | 3496 | }; |
c906108c | 3497 | |
1c645fec | 3498 | static CORE_ADDR |
b8a22b94 | 3499 | mips_insn32_frame_base_address (struct frame_info *this_frame, |
29639122 | 3500 | void **this_cache) |
c906108c | 3501 | { |
b8a22b94 | 3502 | struct mips_frame_cache *info = mips_insn32_frame_cache (this_frame, |
29639122 JB |
3503 | this_cache); |
3504 | return info->base; | |
3505 | } | |
c906108c | 3506 | |
29639122 JB |
3507 | static const struct frame_base mips_insn32_frame_base = |
3508 | { | |
3509 | &mips_insn32_frame_unwind, | |
3510 | mips_insn32_frame_base_address, | |
3511 | mips_insn32_frame_base_address, | |
3512 | mips_insn32_frame_base_address | |
3513 | }; | |
1c645fec | 3514 | |
29639122 | 3515 | static const struct frame_base * |
b8a22b94 | 3516 | mips_insn32_frame_base_sniffer (struct frame_info *this_frame) |
29639122 | 3517 | { |
b8a22b94 | 3518 | CORE_ADDR pc = get_frame_pc (this_frame); |
4cc0665f | 3519 | if (mips_pc_is_mips (pc)) |
29639122 | 3520 | return &mips_insn32_frame_base; |
a65bbe44 | 3521 | else |
29639122 JB |
3522 | return NULL; |
3523 | } | |
a65bbe44 | 3524 | |
29639122 | 3525 | static struct trad_frame_cache * |
b8a22b94 | 3526 | mips_stub_frame_cache (struct frame_info *this_frame, void **this_cache) |
29639122 JB |
3527 | { |
3528 | CORE_ADDR pc; | |
3529 | CORE_ADDR start_addr; | |
3530 | CORE_ADDR stack_addr; | |
3531 | struct trad_frame_cache *this_trad_cache; | |
b8a22b94 DJ |
3532 | struct gdbarch *gdbarch = get_frame_arch (this_frame); |
3533 | int num_regs = gdbarch_num_regs (gdbarch); | |
c906108c | 3534 | |
29639122 JB |
3535 | if ((*this_cache) != NULL) |
3536 | return (*this_cache); | |
b8a22b94 | 3537 | this_trad_cache = trad_frame_cache_zalloc (this_frame); |
29639122 | 3538 | (*this_cache) = this_trad_cache; |
1c645fec | 3539 | |
29639122 | 3540 | /* The return address is in the link register. */ |
3e8c568d | 3541 | trad_frame_set_reg_realreg (this_trad_cache, |
72a155b4 | 3542 | gdbarch_pc_regnum (gdbarch), |
b8a22b94 | 3543 | num_regs + MIPS_RA_REGNUM); |
1c645fec | 3544 | |
29639122 JB |
3545 | /* Frame ID, since it's a frameless / stackless function, no stack |
3546 | space is allocated and SP on entry is the current SP. */ | |
b8a22b94 | 3547 | pc = get_frame_pc (this_frame); |
29639122 | 3548 | find_pc_partial_function (pc, NULL, &start_addr, NULL); |
b8a22b94 DJ |
3549 | stack_addr = get_frame_register_signed (this_frame, |
3550 | num_regs + MIPS_SP_REGNUM); | |
aa6c981f | 3551 | trad_frame_set_id (this_trad_cache, frame_id_build (stack_addr, start_addr)); |
1c645fec | 3552 | |
29639122 JB |
3553 | /* Assume that the frame's base is the same as the |
3554 | stack-pointer. */ | |
3555 | trad_frame_set_this_base (this_trad_cache, stack_addr); | |
c906108c | 3556 | |
29639122 JB |
3557 | return this_trad_cache; |
3558 | } | |
c906108c | 3559 | |
29639122 | 3560 | static void |
b8a22b94 | 3561 | mips_stub_frame_this_id (struct frame_info *this_frame, void **this_cache, |
29639122 JB |
3562 | struct frame_id *this_id) |
3563 | { | |
3564 | struct trad_frame_cache *this_trad_cache | |
b8a22b94 | 3565 | = mips_stub_frame_cache (this_frame, this_cache); |
29639122 JB |
3566 | trad_frame_get_id (this_trad_cache, this_id); |
3567 | } | |
c906108c | 3568 | |
b8a22b94 DJ |
3569 | static struct value * |
3570 | mips_stub_frame_prev_register (struct frame_info *this_frame, | |
3571 | void **this_cache, int regnum) | |
29639122 JB |
3572 | { |
3573 | struct trad_frame_cache *this_trad_cache | |
b8a22b94 DJ |
3574 | = mips_stub_frame_cache (this_frame, this_cache); |
3575 | return trad_frame_get_register (this_trad_cache, this_frame, regnum); | |
29639122 | 3576 | } |
c906108c | 3577 | |
b8a22b94 DJ |
3578 | static int |
3579 | mips_stub_frame_sniffer (const struct frame_unwind *self, | |
3580 | struct frame_info *this_frame, void **this_cache) | |
29639122 | 3581 | { |
aa6c981f | 3582 | gdb_byte dummy[4]; |
979b38e0 | 3583 | struct obj_section *s; |
b8a22b94 | 3584 | CORE_ADDR pc = get_frame_address_in_block (this_frame); |
7cbd4a93 | 3585 | struct bound_minimal_symbol msym; |
979b38e0 | 3586 | |
aa6c981f | 3587 | /* Use the stub unwinder for unreadable code. */ |
b8a22b94 DJ |
3588 | if (target_read_memory (get_frame_pc (this_frame), dummy, 4) != 0) |
3589 | return 1; | |
aa6c981f | 3590 | |
3e5d3a5a | 3591 | if (in_plt_section (pc) || in_mips_stubs_section (pc)) |
b8a22b94 | 3592 | return 1; |
979b38e0 | 3593 | |
db5f024e DJ |
3594 | /* Calling a PIC function from a non-PIC function passes through a |
3595 | stub. The stub for foo is named ".pic.foo". */ | |
3596 | msym = lookup_minimal_symbol_by_pc (pc); | |
7cbd4a93 TT |
3597 | if (msym.minsym != NULL |
3598 | && SYMBOL_LINKAGE_NAME (msym.minsym) != NULL | |
3599 | && strncmp (SYMBOL_LINKAGE_NAME (msym.minsym), ".pic.", 5) == 0) | |
db5f024e DJ |
3600 | return 1; |
3601 | ||
b8a22b94 | 3602 | return 0; |
29639122 | 3603 | } |
c906108c | 3604 | |
b8a22b94 DJ |
3605 | static const struct frame_unwind mips_stub_frame_unwind = |
3606 | { | |
3607 | NORMAL_FRAME, | |
8fbca658 | 3608 | default_frame_unwind_stop_reason, |
b8a22b94 DJ |
3609 | mips_stub_frame_this_id, |
3610 | mips_stub_frame_prev_register, | |
3611 | NULL, | |
3612 | mips_stub_frame_sniffer | |
3613 | }; | |
3614 | ||
29639122 | 3615 | static CORE_ADDR |
b8a22b94 | 3616 | mips_stub_frame_base_address (struct frame_info *this_frame, |
29639122 JB |
3617 | void **this_cache) |
3618 | { | |
3619 | struct trad_frame_cache *this_trad_cache | |
b8a22b94 | 3620 | = mips_stub_frame_cache (this_frame, this_cache); |
29639122 JB |
3621 | return trad_frame_get_this_base (this_trad_cache); |
3622 | } | |
0fce0821 | 3623 | |
29639122 JB |
3624 | static const struct frame_base mips_stub_frame_base = |
3625 | { | |
3626 | &mips_stub_frame_unwind, | |
3627 | mips_stub_frame_base_address, | |
3628 | mips_stub_frame_base_address, | |
3629 | mips_stub_frame_base_address | |
3630 | }; | |
3631 | ||
3632 | static const struct frame_base * | |
b8a22b94 | 3633 | mips_stub_frame_base_sniffer (struct frame_info *this_frame) |
29639122 | 3634 | { |
b8a22b94 | 3635 | if (mips_stub_frame_sniffer (&mips_stub_frame_unwind, this_frame, NULL)) |
29639122 JB |
3636 | return &mips_stub_frame_base; |
3637 | else | |
3638 | return NULL; | |
3639 | } | |
3640 | ||
29639122 | 3641 | /* mips_addr_bits_remove - remove useless address bits */ |
65596487 | 3642 | |
29639122 | 3643 | static CORE_ADDR |
24568a2c | 3644 | mips_addr_bits_remove (struct gdbarch *gdbarch, CORE_ADDR addr) |
65596487 | 3645 | { |
24568a2c | 3646 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
930bd0e0 | 3647 | |
4cc0665f MR |
3648 | if (is_compact_addr (addr)) |
3649 | addr = unmake_compact_addr (addr); | |
930bd0e0 | 3650 | |
29639122 JB |
3651 | if (mips_mask_address_p (tdep) && (((ULONGEST) addr) >> 32 == 0xffffffffUL)) |
3652 | /* This hack is a work-around for existing boards using PMON, the | |
3653 | simulator, and any other 64-bit targets that doesn't have true | |
3654 | 64-bit addressing. On these targets, the upper 32 bits of | |
3655 | addresses are ignored by the hardware. Thus, the PC or SP are | |
3656 | likely to have been sign extended to all 1s by instruction | |
3657 | sequences that load 32-bit addresses. For example, a typical | |
3658 | piece of code that loads an address is this: | |
65596487 | 3659 | |
29639122 JB |
3660 | lui $r2, <upper 16 bits> |
3661 | ori $r2, <lower 16 bits> | |
65596487 | 3662 | |
29639122 JB |
3663 | But the lui sign-extends the value such that the upper 32 bits |
3664 | may be all 1s. The workaround is simply to mask off these | |
3665 | bits. In the future, gcc may be changed to support true 64-bit | |
3666 | addressing, and this masking will have to be disabled. */ | |
3667 | return addr &= 0xffffffffUL; | |
3668 | else | |
3669 | return addr; | |
65596487 JB |
3670 | } |
3671 | ||
3d5f6d12 DJ |
3672 | |
3673 | /* Checks for an atomic sequence of instructions beginning with a LL/LLD | |
3674 | instruction and ending with a SC/SCD instruction. If such a sequence | |
3675 | is found, attempt to step through it. A breakpoint is placed at the end of | |
3676 | the sequence. */ | |
3677 | ||
4cc0665f MR |
3678 | /* Instructions used during single-stepping of atomic sequences, standard |
3679 | ISA version. */ | |
3680 | #define LL_OPCODE 0x30 | |
3681 | #define LLD_OPCODE 0x34 | |
3682 | #define SC_OPCODE 0x38 | |
3683 | #define SCD_OPCODE 0x3c | |
3684 | ||
3d5f6d12 | 3685 | static int |
4cc0665f MR |
3686 | mips_deal_with_atomic_sequence (struct gdbarch *gdbarch, |
3687 | struct address_space *aspace, CORE_ADDR pc) | |
3d5f6d12 DJ |
3688 | { |
3689 | CORE_ADDR breaks[2] = {-1, -1}; | |
3690 | CORE_ADDR loc = pc; | |
3691 | CORE_ADDR branch_bp; /* Breakpoint at branch instruction's destination. */ | |
4cc0665f | 3692 | ULONGEST insn; |
3d5f6d12 DJ |
3693 | int insn_count; |
3694 | int index; | |
3695 | int last_breakpoint = 0; /* Defaults to 0 (no breakpoints placed). */ | |
3696 | const int atomic_sequence_length = 16; /* Instruction sequence length. */ | |
3697 | ||
4cc0665f | 3698 | insn = mips_fetch_instruction (gdbarch, ISA_MIPS, loc, NULL); |
3d5f6d12 DJ |
3699 | /* Assume all atomic sequences start with a ll/lld instruction. */ |
3700 | if (itype_op (insn) != LL_OPCODE && itype_op (insn) != LLD_OPCODE) | |
3701 | return 0; | |
3702 | ||
3703 | /* Assume that no atomic sequence is longer than "atomic_sequence_length" | |
3704 | instructions. */ | |
3705 | for (insn_count = 0; insn_count < atomic_sequence_length; ++insn_count) | |
3706 | { | |
3707 | int is_branch = 0; | |
3708 | loc += MIPS_INSN32_SIZE; | |
4cc0665f | 3709 | insn = mips_fetch_instruction (gdbarch, ISA_MIPS, loc, NULL); |
3d5f6d12 DJ |
3710 | |
3711 | /* Assume that there is at most one branch in the atomic | |
3712 | sequence. If a branch is found, put a breakpoint in its | |
3713 | destination address. */ | |
3714 | switch (itype_op (insn)) | |
3715 | { | |
3716 | case 0: /* SPECIAL */ | |
3717 | if (rtype_funct (insn) >> 1 == 4) /* JR, JALR */ | |
025bb325 | 3718 | return 0; /* fallback to the standard single-step code. */ |
3d5f6d12 DJ |
3719 | break; |
3720 | case 1: /* REGIMM */ | |
a385295e MR |
3721 | is_branch = ((itype_rt (insn) & 0xc) == 0 /* B{LT,GE}Z* */ |
3722 | || ((itype_rt (insn) & 0x1e) == 0 | |
3723 | && itype_rs (insn) == 0)); /* BPOSGE* */ | |
3d5f6d12 DJ |
3724 | break; |
3725 | case 2: /* J */ | |
3726 | case 3: /* JAL */ | |
025bb325 | 3727 | return 0; /* fallback to the standard single-step code. */ |
3d5f6d12 DJ |
3728 | case 4: /* BEQ */ |
3729 | case 5: /* BNE */ | |
3730 | case 6: /* BLEZ */ | |
3731 | case 7: /* BGTZ */ | |
3732 | case 20: /* BEQL */ | |
3733 | case 21: /* BNEL */ | |
3734 | case 22: /* BLEZL */ | |
3735 | case 23: /* BGTTL */ | |
3736 | is_branch = 1; | |
3737 | break; | |
3738 | case 17: /* COP1 */ | |
a385295e MR |
3739 | is_branch = ((itype_rs (insn) == 9 || itype_rs (insn) == 10) |
3740 | && (itype_rt (insn) & 0x2) == 0); | |
3741 | if (is_branch) /* BC1ANY2F, BC1ANY2T, BC1ANY4F, BC1ANY4T */ | |
3742 | break; | |
3743 | /* Fall through. */ | |
3d5f6d12 DJ |
3744 | case 18: /* COP2 */ |
3745 | case 19: /* COP3 */ | |
3746 | is_branch = (itype_rs (insn) == 8); /* BCzF, BCzFL, BCzT, BCzTL */ | |
3747 | break; | |
3748 | } | |
3749 | if (is_branch) | |
3750 | { | |
3751 | branch_bp = loc + mips32_relative_offset (insn) + 4; | |
3752 | if (last_breakpoint >= 1) | |
3753 | return 0; /* More than one branch found, fallback to the | |
3754 | standard single-step code. */ | |
3755 | breaks[1] = branch_bp; | |
3756 | last_breakpoint++; | |
3757 | } | |
3758 | ||
3759 | if (itype_op (insn) == SC_OPCODE || itype_op (insn) == SCD_OPCODE) | |
3760 | break; | |
3761 | } | |
3762 | ||
3763 | /* Assume that the atomic sequence ends with a sc/scd instruction. */ | |
3764 | if (itype_op (insn) != SC_OPCODE && itype_op (insn) != SCD_OPCODE) | |
3765 | return 0; | |
3766 | ||
3767 | loc += MIPS_INSN32_SIZE; | |
3768 | ||
3769 | /* Insert a breakpoint right after the end of the atomic sequence. */ | |
3770 | breaks[0] = loc; | |
3771 | ||
3772 | /* Check for duplicated breakpoints. Check also for a breakpoint | |
025bb325 | 3773 | placed (branch instruction's destination) in the atomic sequence. */ |
3d5f6d12 DJ |
3774 | if (last_breakpoint && pc <= breaks[1] && breaks[1] <= breaks[0]) |
3775 | last_breakpoint = 0; | |
3776 | ||
3777 | /* Effectively inserts the breakpoints. */ | |
3778 | for (index = 0; index <= last_breakpoint; index++) | |
6c95b8df | 3779 | insert_single_step_breakpoint (gdbarch, aspace, breaks[index]); |
3d5f6d12 DJ |
3780 | |
3781 | return 1; | |
3782 | } | |
3783 | ||
4cc0665f MR |
3784 | static int |
3785 | micromips_deal_with_atomic_sequence (struct gdbarch *gdbarch, | |
3786 | struct address_space *aspace, | |
3787 | CORE_ADDR pc) | |
3788 | { | |
3789 | const int atomic_sequence_length = 16; /* Instruction sequence length. */ | |
3790 | int last_breakpoint = 0; /* Defaults to 0 (no breakpoints placed). */ | |
3791 | CORE_ADDR breaks[2] = {-1, -1}; | |
4b844a38 AT |
3792 | CORE_ADDR branch_bp = 0; /* Breakpoint at branch instruction's |
3793 | destination. */ | |
4cc0665f MR |
3794 | CORE_ADDR loc = pc; |
3795 | int sc_found = 0; | |
3796 | ULONGEST insn; | |
3797 | int insn_count; | |
3798 | int index; | |
3799 | ||
3800 | /* Assume all atomic sequences start with a ll/lld instruction. */ | |
3801 | insn = mips_fetch_instruction (gdbarch, ISA_MICROMIPS, loc, NULL); | |
3802 | if (micromips_op (insn) != 0x18) /* POOL32C: bits 011000 */ | |
3803 | return 0; | |
3804 | loc += MIPS_INSN16_SIZE; | |
3805 | insn <<= 16; | |
3806 | insn |= mips_fetch_instruction (gdbarch, ISA_MICROMIPS, loc, NULL); | |
3807 | if ((b12s4_op (insn) & 0xb) != 0x3) /* LL, LLD: bits 011000 0x11 */ | |
3808 | return 0; | |
3809 | loc += MIPS_INSN16_SIZE; | |
3810 | ||
3811 | /* Assume all atomic sequences end with an sc/scd instruction. Assume | |
3812 | that no atomic sequence is longer than "atomic_sequence_length" | |
3813 | instructions. */ | |
3814 | for (insn_count = 0; | |
3815 | !sc_found && insn_count < atomic_sequence_length; | |
3816 | ++insn_count) | |
3817 | { | |
3818 | int is_branch = 0; | |
3819 | ||
3820 | insn = mips_fetch_instruction (gdbarch, ISA_MICROMIPS, loc, NULL); | |
3821 | loc += MIPS_INSN16_SIZE; | |
3822 | ||
3823 | /* Assume that there is at most one conditional branch in the | |
3824 | atomic sequence. If a branch is found, put a breakpoint in | |
3825 | its destination address. */ | |
3826 | switch (mips_insn_size (ISA_MICROMIPS, insn)) | |
3827 | { | |
3828 | /* 48-bit instructions. */ | |
3829 | case 3 * MIPS_INSN16_SIZE: /* POOL48A: bits 011111 */ | |
3830 | loc += 2 * MIPS_INSN16_SIZE; | |
3831 | break; | |
3832 | ||
3833 | /* 32-bit instructions. */ | |
3834 | case 2 * MIPS_INSN16_SIZE: | |
3835 | switch (micromips_op (insn)) | |
3836 | { | |
3837 | case 0x10: /* POOL32I: bits 010000 */ | |
3838 | if ((b5s5_op (insn) & 0x18) != 0x0 | |
3839 | /* BLTZ, BLTZAL, BGEZ, BGEZAL: 010000 000xx */ | |
3840 | /* BLEZ, BNEZC, BGTZ, BEQZC: 010000 001xx */ | |
3841 | && (b5s5_op (insn) & 0x1d) != 0x11 | |
3842 | /* BLTZALS, BGEZALS: bits 010000 100x1 */ | |
3843 | && ((b5s5_op (insn) & 0x1e) != 0x14 | |
3844 | || (insn & 0x3) != 0x0) | |
3845 | /* BC2F, BC2T: bits 010000 1010x xxx00 */ | |
3846 | && (b5s5_op (insn) & 0x1e) != 0x1a | |
3847 | /* BPOSGE64, BPOSGE32: bits 010000 1101x */ | |
3848 | && ((b5s5_op (insn) & 0x1e) != 0x1c | |
3849 | || (insn & 0x3) != 0x0) | |
3850 | /* BC1F, BC1T: bits 010000 1110x xxx00 */ | |
3851 | && ((b5s5_op (insn) & 0x1c) != 0x1c | |
3852 | || (insn & 0x3) != 0x1)) | |
3853 | /* BC1ANY*: bits 010000 111xx xxx01 */ | |
3854 | break; | |
3855 | /* Fall through. */ | |
3856 | ||
3857 | case 0x25: /* BEQ: bits 100101 */ | |
3858 | case 0x2d: /* BNE: bits 101101 */ | |
3859 | insn <<= 16; | |
3860 | insn |= mips_fetch_instruction (gdbarch, | |
3861 | ISA_MICROMIPS, loc, NULL); | |
3862 | branch_bp = (loc + MIPS_INSN16_SIZE | |
3863 | + micromips_relative_offset16 (insn)); | |
3864 | is_branch = 1; | |
3865 | break; | |
3866 | ||
3867 | case 0x00: /* POOL32A: bits 000000 */ | |
3868 | insn <<= 16; | |
3869 | insn |= mips_fetch_instruction (gdbarch, | |
3870 | ISA_MICROMIPS, loc, NULL); | |
3871 | if (b0s6_op (insn) != 0x3c | |
3872 | /* POOL32Axf: bits 000000 ... 111100 */ | |
3873 | || (b6s10_ext (insn) & 0x2bf) != 0x3c) | |
3874 | /* JALR, JALR.HB: 000000 000x111100 111100 */ | |
3875 | /* JALRS, JALRS.HB: 000000 010x111100 111100 */ | |
3876 | break; | |
3877 | /* Fall through. */ | |
3878 | ||
3879 | case 0x1d: /* JALS: bits 011101 */ | |
3880 | case 0x35: /* J: bits 110101 */ | |
3881 | case 0x3d: /* JAL: bits 111101 */ | |
3882 | case 0x3c: /* JALX: bits 111100 */ | |
3883 | return 0; /* Fall back to the standard single-step code. */ | |
3884 | ||
3885 | case 0x18: /* POOL32C: bits 011000 */ | |
3886 | if ((b12s4_op (insn) & 0xb) == 0xb) | |
3887 | /* SC, SCD: bits 011000 1x11 */ | |
3888 | sc_found = 1; | |
3889 | break; | |
3890 | } | |
3891 | loc += MIPS_INSN16_SIZE; | |
3892 | break; | |
3893 | ||
3894 | /* 16-bit instructions. */ | |
3895 | case MIPS_INSN16_SIZE: | |
3896 | switch (micromips_op (insn)) | |
3897 | { | |
3898 | case 0x23: /* BEQZ16: bits 100011 */ | |
3899 | case 0x2b: /* BNEZ16: bits 101011 */ | |
3900 | branch_bp = loc + micromips_relative_offset7 (insn); | |
3901 | is_branch = 1; | |
3902 | break; | |
3903 | ||
3904 | case 0x11: /* POOL16C: bits 010001 */ | |
3905 | if ((b5s5_op (insn) & 0x1c) != 0xc | |
3906 | /* JR16, JRC, JALR16, JALRS16: 010001 011xx */ | |
3907 | && b5s5_op (insn) != 0x18) | |
3908 | /* JRADDIUSP: bits 010001 11000 */ | |
3909 | break; | |
3910 | return 0; /* Fall back to the standard single-step code. */ | |
3911 | ||
3912 | case 0x33: /* B16: bits 110011 */ | |
3913 | return 0; /* Fall back to the standard single-step code. */ | |
3914 | } | |
3915 | break; | |
3916 | } | |
3917 | if (is_branch) | |
3918 | { | |
3919 | if (last_breakpoint >= 1) | |
3920 | return 0; /* More than one branch found, fallback to the | |
3921 | standard single-step code. */ | |
3922 | breaks[1] = branch_bp; | |
3923 | last_breakpoint++; | |
3924 | } | |
3925 | } | |
3926 | if (!sc_found) | |
3927 | return 0; | |
3928 | ||
3929 | /* Insert a breakpoint right after the end of the atomic sequence. */ | |
3930 | breaks[0] = loc; | |
3931 | ||
3932 | /* Check for duplicated breakpoints. Check also for a breakpoint | |
3933 | placed (branch instruction's destination) in the atomic sequence */ | |
3934 | if (last_breakpoint && pc <= breaks[1] && breaks[1] <= breaks[0]) | |
3935 | last_breakpoint = 0; | |
3936 | ||
3937 | /* Effectively inserts the breakpoints. */ | |
3938 | for (index = 0; index <= last_breakpoint; index++) | |
3939 | insert_single_step_breakpoint (gdbarch, aspace, breaks[index]); | |
3940 | ||
3941 | return 1; | |
3942 | } | |
3943 | ||
3944 | static int | |
3945 | deal_with_atomic_sequence (struct gdbarch *gdbarch, | |
3946 | struct address_space *aspace, CORE_ADDR pc) | |
3947 | { | |
3948 | if (mips_pc_is_mips (pc)) | |
3949 | return mips_deal_with_atomic_sequence (gdbarch, aspace, pc); | |
3950 | else if (mips_pc_is_micromips (gdbarch, pc)) | |
3951 | return micromips_deal_with_atomic_sequence (gdbarch, aspace, pc); | |
3952 | else | |
3953 | return 0; | |
3954 | } | |
3955 | ||
29639122 JB |
3956 | /* mips_software_single_step() is called just before we want to resume |
3957 | the inferior, if we want to single-step it but there is no hardware | |
3958 | or kernel single-step support (MIPS on GNU/Linux for example). We find | |
e0cd558a | 3959 | the target of the coming instruction and breakpoint it. */ |
29639122 | 3960 | |
e6590a1b | 3961 | int |
0b1b3e42 | 3962 | mips_software_single_step (struct frame_info *frame) |
c906108c | 3963 | { |
a6d9a66e | 3964 | struct gdbarch *gdbarch = get_frame_arch (frame); |
6c95b8df | 3965 | struct address_space *aspace = get_frame_address_space (frame); |
8181d85f | 3966 | CORE_ADDR pc, next_pc; |
65596487 | 3967 | |
0b1b3e42 | 3968 | pc = get_frame_pc (frame); |
6c95b8df | 3969 | if (deal_with_atomic_sequence (gdbarch, aspace, pc)) |
3d5f6d12 DJ |
3970 | return 1; |
3971 | ||
0b1b3e42 | 3972 | next_pc = mips_next_pc (frame, pc); |
e6590a1b | 3973 | |
6c95b8df | 3974 | insert_single_step_breakpoint (gdbarch, aspace, next_pc); |
e6590a1b | 3975 | return 1; |
29639122 | 3976 | } |
a65bbe44 | 3977 | |
29639122 | 3978 | /* Test whether the PC points to the return instruction at the |
025bb325 | 3979 | end of a function. */ |
65596487 | 3980 | |
29639122 | 3981 | static int |
e17a4113 | 3982 | mips_about_to_return (struct gdbarch *gdbarch, CORE_ADDR pc) |
29639122 | 3983 | { |
6321c22a MR |
3984 | ULONGEST insn; |
3985 | ULONGEST hint; | |
3986 | ||
3987 | /* This used to check for MIPS16, but this piece of code is never | |
4cc0665f MR |
3988 | called for MIPS16 functions. And likewise microMIPS ones. */ |
3989 | gdb_assert (mips_pc_is_mips (pc)); | |
6321c22a | 3990 | |
4cc0665f | 3991 | insn = mips_fetch_instruction (gdbarch, ISA_MIPS, pc, NULL); |
6321c22a MR |
3992 | hint = 0x7c0; |
3993 | return (insn & ~hint) == 0x3e00008; /* jr(.hb) $ra */ | |
29639122 | 3994 | } |
c906108c | 3995 | |
c906108c | 3996 | |
29639122 JB |
3997 | /* This fencepost looks highly suspicious to me. Removing it also |
3998 | seems suspicious as it could affect remote debugging across serial | |
3999 | lines. */ | |
c906108c | 4000 | |
29639122 | 4001 | static CORE_ADDR |
74ed0bb4 | 4002 | heuristic_proc_start (struct gdbarch *gdbarch, CORE_ADDR pc) |
29639122 JB |
4003 | { |
4004 | CORE_ADDR start_pc; | |
4005 | CORE_ADDR fence; | |
4006 | int instlen; | |
4007 | int seen_adjsp = 0; | |
d6b48e9c | 4008 | struct inferior *inf; |
65596487 | 4009 | |
74ed0bb4 | 4010 | pc = gdbarch_addr_bits_remove (gdbarch, pc); |
29639122 JB |
4011 | start_pc = pc; |
4012 | fence = start_pc - heuristic_fence_post; | |
4013 | if (start_pc == 0) | |
4014 | return 0; | |
65596487 | 4015 | |
44096aee | 4016 | if (heuristic_fence_post == -1 || fence < VM_MIN_ADDRESS) |
29639122 | 4017 | fence = VM_MIN_ADDRESS; |
65596487 | 4018 | |
4cc0665f | 4019 | instlen = mips_pc_is_mips (pc) ? MIPS_INSN32_SIZE : MIPS_INSN16_SIZE; |
98b4dd94 | 4020 | |
d6b48e9c PA |
4021 | inf = current_inferior (); |
4022 | ||
025bb325 | 4023 | /* Search back for previous return. */ |
29639122 JB |
4024 | for (start_pc -= instlen;; start_pc -= instlen) |
4025 | if (start_pc < fence) | |
4026 | { | |
4027 | /* It's not clear to me why we reach this point when | |
4028 | stop_soon, but with this test, at least we | |
4029 | don't print out warnings for every child forked (eg, on | |
4030 | decstation). 22apr93 rich@cygnus.com. */ | |
16c381f0 | 4031 | if (inf->control.stop_soon == NO_STOP_QUIETLY) |
29639122 JB |
4032 | { |
4033 | static int blurb_printed = 0; | |
98b4dd94 | 4034 | |
5af949e3 UW |
4035 | warning (_("GDB can't find the start of the function at %s."), |
4036 | paddress (gdbarch, pc)); | |
29639122 JB |
4037 | |
4038 | if (!blurb_printed) | |
4039 | { | |
4040 | /* This actually happens frequently in embedded | |
4041 | development, when you first connect to a board | |
4042 | and your stack pointer and pc are nowhere in | |
4043 | particular. This message needs to give people | |
4044 | in that situation enough information to | |
4045 | determine that it's no big deal. */ | |
4046 | printf_filtered ("\n\ | |
5af949e3 | 4047 | GDB is unable to find the start of the function at %s\n\ |
29639122 JB |
4048 | and thus can't determine the size of that function's stack frame.\n\ |
4049 | This means that GDB may be unable to access that stack frame, or\n\ | |
4050 | the frames below it.\n\ | |
4051 | This problem is most likely caused by an invalid program counter or\n\ | |
4052 | stack pointer.\n\ | |
4053 | However, if you think GDB should simply search farther back\n\ | |
5af949e3 | 4054 | from %s for code which looks like the beginning of a\n\ |
29639122 | 4055 | function, you can increase the range of the search using the `set\n\ |
5af949e3 UW |
4056 | heuristic-fence-post' command.\n", |
4057 | paddress (gdbarch, pc), paddress (gdbarch, pc)); | |
29639122 JB |
4058 | blurb_printed = 1; |
4059 | } | |
4060 | } | |
4061 | ||
4062 | return 0; | |
4063 | } | |
4cc0665f | 4064 | else if (mips_pc_is_mips16 (gdbarch, start_pc)) |
29639122 JB |
4065 | { |
4066 | unsigned short inst; | |
4067 | ||
4068 | /* On MIPS16, any one of the following is likely to be the | |
4069 | start of a function: | |
193774b3 MR |
4070 | extend save |
4071 | save | |
29639122 JB |
4072 | entry |
4073 | addiu sp,-n | |
4074 | daddiu sp,-n | |
025bb325 | 4075 | extend -n followed by 'addiu sp,+n' or 'daddiu sp,+n'. */ |
4cc0665f | 4076 | inst = mips_fetch_instruction (gdbarch, ISA_MIPS16, start_pc, NULL); |
193774b3 MR |
4077 | if ((inst & 0xff80) == 0x6480) /* save */ |
4078 | { | |
4079 | if (start_pc - instlen >= fence) | |
4080 | { | |
4cc0665f MR |
4081 | inst = mips_fetch_instruction (gdbarch, ISA_MIPS16, |
4082 | start_pc - instlen, NULL); | |
193774b3 MR |
4083 | if ((inst & 0xf800) == 0xf000) /* extend */ |
4084 | start_pc -= instlen; | |
4085 | } | |
4086 | break; | |
4087 | } | |
4088 | else if (((inst & 0xf81f) == 0xe809 | |
4089 | && (inst & 0x700) != 0x700) /* entry */ | |
4090 | || (inst & 0xff80) == 0x6380 /* addiu sp,-n */ | |
4091 | || (inst & 0xff80) == 0xfb80 /* daddiu sp,-n */ | |
4092 | || ((inst & 0xf810) == 0xf010 && seen_adjsp)) /* extend -n */ | |
29639122 JB |
4093 | break; |
4094 | else if ((inst & 0xff00) == 0x6300 /* addiu sp */ | |
4095 | || (inst & 0xff00) == 0xfb00) /* daddiu sp */ | |
4096 | seen_adjsp = 1; | |
4097 | else | |
4098 | seen_adjsp = 0; | |
4099 | } | |
4cc0665f MR |
4100 | else if (mips_pc_is_micromips (gdbarch, start_pc)) |
4101 | { | |
4102 | ULONGEST insn; | |
4103 | int stop = 0; | |
4104 | long offset; | |
4105 | int dreg; | |
4106 | int sreg; | |
4107 | ||
4108 | /* On microMIPS, any one of the following is likely to be the | |
4109 | start of a function: | |
4110 | ADDIUSP -imm | |
4111 | (D)ADDIU $sp, -imm | |
4112 | LUI $gp, imm */ | |
4113 | insn = mips_fetch_instruction (gdbarch, ISA_MICROMIPS, pc, NULL); | |
4114 | switch (micromips_op (insn)) | |
4115 | { | |
4116 | case 0xc: /* ADDIU: bits 001100 */ | |
4117 | case 0x17: /* DADDIU: bits 010111 */ | |
4118 | sreg = b0s5_reg (insn); | |
4119 | dreg = b5s5_reg (insn); | |
4120 | insn <<= 16; | |
4121 | insn |= mips_fetch_instruction (gdbarch, ISA_MICROMIPS, | |
4122 | pc + MIPS_INSN16_SIZE, NULL); | |
4123 | offset = (b0s16_imm (insn) ^ 0x8000) - 0x8000; | |
4124 | if (sreg == MIPS_SP_REGNUM && dreg == MIPS_SP_REGNUM | |
4125 | /* (D)ADDIU $sp, imm */ | |
4126 | && offset < 0) | |
4127 | stop = 1; | |
4128 | break; | |
4129 | ||
4130 | case 0x10: /* POOL32I: bits 010000 */ | |
4131 | if (b5s5_op (insn) == 0xd | |
4132 | /* LUI: bits 010000 001101 */ | |
4133 | && b0s5_reg (insn >> 16) == 28) | |
4134 | /* LUI $gp, imm */ | |
4135 | stop = 1; | |
4136 | break; | |
4137 | ||
4138 | case 0x13: /* POOL16D: bits 010011 */ | |
4139 | if ((insn & 0x1) == 0x1) | |
4140 | /* ADDIUSP: bits 010011 1 */ | |
4141 | { | |
4142 | offset = micromips_decode_imm9 (b1s9_imm (insn)); | |
4143 | if (offset < 0) | |
4144 | /* ADDIUSP -imm */ | |
4145 | stop = 1; | |
4146 | } | |
4147 | else | |
4148 | /* ADDIUS5: bits 010011 0 */ | |
4149 | { | |
4150 | dreg = b5s5_reg (insn); | |
4151 | offset = (b1s4_imm (insn) ^ 8) - 8; | |
4152 | if (dreg == MIPS_SP_REGNUM && offset < 0) | |
4153 | /* ADDIUS5 $sp, -imm */ | |
4154 | stop = 1; | |
4155 | } | |
4156 | break; | |
4157 | } | |
4158 | if (stop) | |
4159 | break; | |
4160 | } | |
e17a4113 | 4161 | else if (mips_about_to_return (gdbarch, start_pc)) |
29639122 | 4162 | { |
4c7d22cb | 4163 | /* Skip return and its delay slot. */ |
95ac2dcf | 4164 | start_pc += 2 * MIPS_INSN32_SIZE; |
29639122 JB |
4165 | break; |
4166 | } | |
4167 | ||
4168 | return start_pc; | |
c906108c SS |
4169 | } |
4170 | ||
6c0d6680 DJ |
4171 | struct mips_objfile_private |
4172 | { | |
4173 | bfd_size_type size; | |
4174 | char *contents; | |
4175 | }; | |
4176 | ||
f09ded24 AC |
4177 | /* According to the current ABI, should the type be passed in a |
4178 | floating-point register (assuming that there is space)? When there | |
a1f5b845 | 4179 | is no FPU, FP are not even considered as possible candidates for |
f09ded24 | 4180 | FP registers and, consequently this returns false - forces FP |
025bb325 | 4181 | arguments into integer registers. */ |
f09ded24 AC |
4182 | |
4183 | static int | |
74ed0bb4 MD |
4184 | fp_register_arg_p (struct gdbarch *gdbarch, enum type_code typecode, |
4185 | struct type *arg_type) | |
f09ded24 AC |
4186 | { |
4187 | return ((typecode == TYPE_CODE_FLT | |
74ed0bb4 | 4188 | || (MIPS_EABI (gdbarch) |
6d82d43b AC |
4189 | && (typecode == TYPE_CODE_STRUCT |
4190 | || typecode == TYPE_CODE_UNION) | |
f09ded24 | 4191 | && TYPE_NFIELDS (arg_type) == 1 |
b2d6f210 MS |
4192 | && TYPE_CODE (check_typedef (TYPE_FIELD_TYPE (arg_type, 0))) |
4193 | == TYPE_CODE_FLT)) | |
74ed0bb4 | 4194 | && MIPS_FPU_TYPE(gdbarch) != MIPS_FPU_NONE); |
f09ded24 AC |
4195 | } |
4196 | ||
49e790b0 | 4197 | /* On o32, argument passing in GPRs depends on the alignment of the type being |
025bb325 | 4198 | passed. Return 1 if this type must be aligned to a doubleword boundary. */ |
49e790b0 DJ |
4199 | |
4200 | static int | |
4201 | mips_type_needs_double_align (struct type *type) | |
4202 | { | |
4203 | enum type_code typecode = TYPE_CODE (type); | |
361d1df0 | 4204 | |
49e790b0 DJ |
4205 | if (typecode == TYPE_CODE_FLT && TYPE_LENGTH (type) == 8) |
4206 | return 1; | |
4207 | else if (typecode == TYPE_CODE_STRUCT) | |
4208 | { | |
4209 | if (TYPE_NFIELDS (type) < 1) | |
4210 | return 0; | |
4211 | return mips_type_needs_double_align (TYPE_FIELD_TYPE (type, 0)); | |
4212 | } | |
4213 | else if (typecode == TYPE_CODE_UNION) | |
4214 | { | |
361d1df0 | 4215 | int i, n; |
49e790b0 DJ |
4216 | |
4217 | n = TYPE_NFIELDS (type); | |
4218 | for (i = 0; i < n; i++) | |
4219 | if (mips_type_needs_double_align (TYPE_FIELD_TYPE (type, i))) | |
4220 | return 1; | |
4221 | return 0; | |
4222 | } | |
4223 | return 0; | |
4224 | } | |
4225 | ||
dc604539 AC |
4226 | /* Adjust the address downward (direction of stack growth) so that it |
4227 | is correctly aligned for a new stack frame. */ | |
4228 | static CORE_ADDR | |
4229 | mips_frame_align (struct gdbarch *gdbarch, CORE_ADDR addr) | |
4230 | { | |
5b03f266 | 4231 | return align_down (addr, 16); |
dc604539 AC |
4232 | } |
4233 | ||
8ae38c14 | 4234 | /* Implement the "push_dummy_code" gdbarch method. */ |
2c76a0c7 JB |
4235 | |
4236 | static CORE_ADDR | |
4237 | mips_push_dummy_code (struct gdbarch *gdbarch, CORE_ADDR sp, | |
4238 | CORE_ADDR funaddr, struct value **args, | |
4239 | int nargs, struct type *value_type, | |
4240 | CORE_ADDR *real_pc, CORE_ADDR *bp_addr, | |
4241 | struct regcache *regcache) | |
4242 | { | |
2c76a0c7 | 4243 | static gdb_byte nop_insn[] = { 0, 0, 0, 0 }; |
2e81047f MR |
4244 | CORE_ADDR nop_addr; |
4245 | CORE_ADDR bp_slot; | |
2c76a0c7 JB |
4246 | |
4247 | /* Reserve enough room on the stack for our breakpoint instruction. */ | |
2e81047f MR |
4248 | bp_slot = sp - sizeof (nop_insn); |
4249 | ||
4250 | /* Return to microMIPS mode if calling microMIPS code to avoid | |
4251 | triggering an address error exception on processors that only | |
4252 | support microMIPS execution. */ | |
4253 | *bp_addr = (mips_pc_is_micromips (gdbarch, funaddr) | |
4254 | ? make_compact_addr (bp_slot) : bp_slot); | |
2c76a0c7 JB |
4255 | |
4256 | /* The breakpoint layer automatically adjusts the address of | |
4257 | breakpoints inserted in a branch delay slot. With enough | |
4258 | bad luck, the 4 bytes located just before our breakpoint | |
4259 | instruction could look like a branch instruction, and thus | |
4260 | trigger the adjustement, and break the function call entirely. | |
4261 | So, we reserve those 4 bytes and write a nop instruction | |
4262 | to prevent that from happening. */ | |
2e81047f | 4263 | nop_addr = bp_slot - sizeof (nop_insn); |
2c76a0c7 JB |
4264 | write_memory (nop_addr, nop_insn, sizeof (nop_insn)); |
4265 | sp = mips_frame_align (gdbarch, nop_addr); | |
4266 | ||
4267 | /* Inferior resumes at the function entry point. */ | |
4268 | *real_pc = funaddr; | |
4269 | ||
4270 | return sp; | |
4271 | } | |
4272 | ||
f7ab6ec6 | 4273 | static CORE_ADDR |
7d9b040b | 4274 | mips_eabi_push_dummy_call (struct gdbarch *gdbarch, struct value *function, |
6d82d43b AC |
4275 | struct regcache *regcache, CORE_ADDR bp_addr, |
4276 | int nargs, struct value **args, CORE_ADDR sp, | |
4277 | int struct_return, CORE_ADDR struct_addr) | |
c906108c SS |
4278 | { |
4279 | int argreg; | |
4280 | int float_argreg; | |
4281 | int argnum; | |
4282 | int len = 0; | |
4283 | int stack_offset = 0; | |
e17a4113 | 4284 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
7d9b040b | 4285 | CORE_ADDR func_addr = find_function_addr (function, NULL); |
1a69e1e4 | 4286 | int regsize = mips_abi_regsize (gdbarch); |
c906108c | 4287 | |
25ab4790 AC |
4288 | /* For shared libraries, "t9" needs to point at the function |
4289 | address. */ | |
4c7d22cb | 4290 | regcache_cooked_write_signed (regcache, MIPS_T9_REGNUM, func_addr); |
25ab4790 AC |
4291 | |
4292 | /* Set the return address register to point to the entry point of | |
4293 | the program, where a breakpoint lies in wait. */ | |
4c7d22cb | 4294 | regcache_cooked_write_signed (regcache, MIPS_RA_REGNUM, bp_addr); |
25ab4790 | 4295 | |
c906108c | 4296 | /* First ensure that the stack and structure return address (if any) |
cb3d25d1 MS |
4297 | are properly aligned. The stack has to be at least 64-bit |
4298 | aligned even on 32-bit machines, because doubles must be 64-bit | |
4299 | aligned. For n32 and n64, stack frames need to be 128-bit | |
4300 | aligned, so we round to this widest known alignment. */ | |
4301 | ||
5b03f266 AC |
4302 | sp = align_down (sp, 16); |
4303 | struct_addr = align_down (struct_addr, 16); | |
c5aa993b | 4304 | |
46e0f506 | 4305 | /* Now make space on the stack for the args. We allocate more |
c906108c | 4306 | than necessary for EABI, because the first few arguments are |
46e0f506 | 4307 | passed in registers, but that's OK. */ |
c906108c | 4308 | for (argnum = 0; argnum < nargs; argnum++) |
1a69e1e4 | 4309 | len += align_up (TYPE_LENGTH (value_type (args[argnum])), regsize); |
5b03f266 | 4310 | sp -= align_up (len, 16); |
c906108c | 4311 | |
9ace0497 | 4312 | if (mips_debug) |
6d82d43b | 4313 | fprintf_unfiltered (gdb_stdlog, |
5af949e3 UW |
4314 | "mips_eabi_push_dummy_call: sp=%s allocated %ld\n", |
4315 | paddress (gdbarch, sp), (long) align_up (len, 16)); | |
9ace0497 | 4316 | |
c906108c | 4317 | /* Initialize the integer and float register pointers. */ |
4c7d22cb | 4318 | argreg = MIPS_A0_REGNUM; |
72a155b4 | 4319 | float_argreg = mips_fpa0_regnum (gdbarch); |
c906108c | 4320 | |
46e0f506 | 4321 | /* The struct_return pointer occupies the first parameter-passing reg. */ |
c906108c | 4322 | if (struct_return) |
9ace0497 AC |
4323 | { |
4324 | if (mips_debug) | |
4325 | fprintf_unfiltered (gdb_stdlog, | |
025bb325 MS |
4326 | "mips_eabi_push_dummy_call: " |
4327 | "struct_return reg=%d %s\n", | |
5af949e3 | 4328 | argreg, paddress (gdbarch, struct_addr)); |
9c9acae0 | 4329 | regcache_cooked_write_unsigned (regcache, argreg++, struct_addr); |
9ace0497 | 4330 | } |
c906108c SS |
4331 | |
4332 | /* Now load as many as possible of the first arguments into | |
4333 | registers, and push the rest onto the stack. Loop thru args | |
4334 | from first to last. */ | |
4335 | for (argnum = 0; argnum < nargs; argnum++) | |
4336 | { | |
47a35522 MK |
4337 | const gdb_byte *val; |
4338 | gdb_byte valbuf[MAX_REGISTER_SIZE]; | |
ea7c478f | 4339 | struct value *arg = args[argnum]; |
4991999e | 4340 | struct type *arg_type = check_typedef (value_type (arg)); |
c906108c SS |
4341 | int len = TYPE_LENGTH (arg_type); |
4342 | enum type_code typecode = TYPE_CODE (arg_type); | |
4343 | ||
9ace0497 AC |
4344 | if (mips_debug) |
4345 | fprintf_unfiltered (gdb_stdlog, | |
25ab4790 | 4346 | "mips_eabi_push_dummy_call: %d len=%d type=%d", |
acdb74a0 | 4347 | argnum + 1, len, (int) typecode); |
9ace0497 | 4348 | |
930bd0e0 KB |
4349 | /* Function pointer arguments to mips16 code need to be made into |
4350 | mips16 pointers. */ | |
4351 | if (typecode == TYPE_CODE_PTR | |
4352 | && TYPE_CODE (TYPE_TARGET_TYPE (arg_type)) == TYPE_CODE_FUNC) | |
4353 | { | |
4354 | CORE_ADDR addr = extract_signed_integer (value_contents (arg), | |
4355 | len, byte_order); | |
4cc0665f MR |
4356 | if (mips_pc_is_mips (addr)) |
4357 | val = value_contents (arg); | |
4358 | else | |
930bd0e0 KB |
4359 | { |
4360 | store_signed_integer (valbuf, len, byte_order, | |
4cc0665f | 4361 | make_compact_addr (addr)); |
930bd0e0 KB |
4362 | val = valbuf; |
4363 | } | |
930bd0e0 | 4364 | } |
c906108c | 4365 | /* The EABI passes structures that do not fit in a register by |
46e0f506 | 4366 | reference. */ |
930bd0e0 | 4367 | else if (len > regsize |
9ace0497 | 4368 | && (typecode == TYPE_CODE_STRUCT || typecode == TYPE_CODE_UNION)) |
c906108c | 4369 | { |
e17a4113 UW |
4370 | store_unsigned_integer (valbuf, regsize, byte_order, |
4371 | value_address (arg)); | |
c906108c | 4372 | typecode = TYPE_CODE_PTR; |
1a69e1e4 | 4373 | len = regsize; |
c906108c | 4374 | val = valbuf; |
9ace0497 AC |
4375 | if (mips_debug) |
4376 | fprintf_unfiltered (gdb_stdlog, " push"); | |
c906108c SS |
4377 | } |
4378 | else | |
47a35522 | 4379 | val = value_contents (arg); |
c906108c SS |
4380 | |
4381 | /* 32-bit ABIs always start floating point arguments in an | |
acdb74a0 AC |
4382 | even-numbered floating point register. Round the FP register |
4383 | up before the check to see if there are any FP registers | |
46e0f506 MS |
4384 | left. Non MIPS_EABI targets also pass the FP in the integer |
4385 | registers so also round up normal registers. */ | |
74ed0bb4 | 4386 | if (regsize < 8 && fp_register_arg_p (gdbarch, typecode, arg_type)) |
acdb74a0 AC |
4387 | { |
4388 | if ((float_argreg & 1)) | |
4389 | float_argreg++; | |
4390 | } | |
c906108c SS |
4391 | |
4392 | /* Floating point arguments passed in registers have to be | |
4393 | treated specially. On 32-bit architectures, doubles | |
c5aa993b JM |
4394 | are passed in register pairs; the even register gets |
4395 | the low word, and the odd register gets the high word. | |
4396 | On non-EABI processors, the first two floating point arguments are | |
4397 | also copied to general registers, because MIPS16 functions | |
4398 | don't use float registers for arguments. This duplication of | |
4399 | arguments in general registers can't hurt non-MIPS16 functions | |
4400 | because those registers are normally skipped. */ | |
1012bd0e EZ |
4401 | /* MIPS_EABI squeezes a struct that contains a single floating |
4402 | point value into an FP register instead of pushing it onto the | |
46e0f506 | 4403 | stack. */ |
74ed0bb4 MD |
4404 | if (fp_register_arg_p (gdbarch, typecode, arg_type) |
4405 | && float_argreg <= MIPS_LAST_FP_ARG_REGNUM (gdbarch)) | |
c906108c | 4406 | { |
6da397e0 KB |
4407 | /* EABI32 will pass doubles in consecutive registers, even on |
4408 | 64-bit cores. At one time, we used to check the size of | |
4409 | `float_argreg' to determine whether or not to pass doubles | |
4410 | in consecutive registers, but this is not sufficient for | |
4411 | making the ABI determination. */ | |
4412 | if (len == 8 && mips_abi (gdbarch) == MIPS_ABI_EABI32) | |
c906108c | 4413 | { |
72a155b4 | 4414 | int low_offset = gdbarch_byte_order (gdbarch) |
4c6b5505 | 4415 | == BFD_ENDIAN_BIG ? 4 : 0; |
a8852dc5 | 4416 | long regval; |
c906108c SS |
4417 | |
4418 | /* Write the low word of the double to the even register(s). */ | |
a8852dc5 KB |
4419 | regval = extract_signed_integer (val + low_offset, |
4420 | 4, byte_order); | |
9ace0497 | 4421 | if (mips_debug) |
acdb74a0 | 4422 | fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s", |
9ace0497 | 4423 | float_argreg, phex (regval, 4)); |
a8852dc5 | 4424 | regcache_cooked_write_signed (regcache, float_argreg++, regval); |
c906108c SS |
4425 | |
4426 | /* Write the high word of the double to the odd register(s). */ | |
a8852dc5 KB |
4427 | regval = extract_signed_integer (val + 4 - low_offset, |
4428 | 4, byte_order); | |
9ace0497 | 4429 | if (mips_debug) |
acdb74a0 | 4430 | fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s", |
9ace0497 | 4431 | float_argreg, phex (regval, 4)); |
a8852dc5 | 4432 | regcache_cooked_write_signed (regcache, float_argreg++, regval); |
c906108c SS |
4433 | } |
4434 | else | |
4435 | { | |
4436 | /* This is a floating point value that fits entirely | |
4437 | in a single register. */ | |
53a5351d | 4438 | /* On 32 bit ABI's the float_argreg is further adjusted |
6d82d43b | 4439 | above to ensure that it is even register aligned. */ |
a8852dc5 | 4440 | LONGEST regval = extract_signed_integer (val, len, byte_order); |
9ace0497 | 4441 | if (mips_debug) |
acdb74a0 | 4442 | fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s", |
9ace0497 | 4443 | float_argreg, phex (regval, len)); |
a8852dc5 | 4444 | regcache_cooked_write_signed (regcache, float_argreg++, regval); |
c906108c SS |
4445 | } |
4446 | } | |
4447 | else | |
4448 | { | |
4449 | /* Copy the argument to general registers or the stack in | |
4450 | register-sized pieces. Large arguments are split between | |
4451 | registers and stack. */ | |
1a69e1e4 DJ |
4452 | /* Note: structs whose size is not a multiple of regsize |
4453 | are treated specially: Irix cc passes | |
d5ac5a39 AC |
4454 | them in registers where gcc sometimes puts them on the |
4455 | stack. For maximum compatibility, we will put them in | |
4456 | both places. */ | |
1a69e1e4 | 4457 | int odd_sized_struct = (len > regsize && len % regsize != 0); |
46e0f506 | 4458 | |
f09ded24 | 4459 | /* Note: Floating-point values that didn't fit into an FP |
6d82d43b | 4460 | register are only written to memory. */ |
c906108c SS |
4461 | while (len > 0) |
4462 | { | |
ebafbe83 | 4463 | /* Remember if the argument was written to the stack. */ |
566f0f7a | 4464 | int stack_used_p = 0; |
1a69e1e4 | 4465 | int partial_len = (len < regsize ? len : regsize); |
c906108c | 4466 | |
acdb74a0 AC |
4467 | if (mips_debug) |
4468 | fprintf_unfiltered (gdb_stdlog, " -- partial=%d", | |
4469 | partial_len); | |
4470 | ||
566f0f7a | 4471 | /* Write this portion of the argument to the stack. */ |
74ed0bb4 | 4472 | if (argreg > MIPS_LAST_ARG_REGNUM (gdbarch) |
f09ded24 | 4473 | || odd_sized_struct |
74ed0bb4 | 4474 | || fp_register_arg_p (gdbarch, typecode, arg_type)) |
c906108c | 4475 | { |
c906108c | 4476 | /* Should shorter than int integer values be |
025bb325 | 4477 | promoted to int before being stored? */ |
c906108c | 4478 | int longword_offset = 0; |
9ace0497 | 4479 | CORE_ADDR addr; |
566f0f7a | 4480 | stack_used_p = 1; |
72a155b4 | 4481 | if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) |
7a292a7a | 4482 | { |
1a69e1e4 | 4483 | if (regsize == 8 |
480d3dd2 AC |
4484 | && (typecode == TYPE_CODE_INT |
4485 | || typecode == TYPE_CODE_PTR | |
6d82d43b | 4486 | || typecode == TYPE_CODE_FLT) && len <= 4) |
1a69e1e4 | 4487 | longword_offset = regsize - len; |
480d3dd2 AC |
4488 | else if ((typecode == TYPE_CODE_STRUCT |
4489 | || typecode == TYPE_CODE_UNION) | |
1a69e1e4 DJ |
4490 | && TYPE_LENGTH (arg_type) < regsize) |
4491 | longword_offset = regsize - len; | |
7a292a7a | 4492 | } |
c5aa993b | 4493 | |
9ace0497 AC |
4494 | if (mips_debug) |
4495 | { | |
5af949e3 UW |
4496 | fprintf_unfiltered (gdb_stdlog, " - stack_offset=%s", |
4497 | paddress (gdbarch, stack_offset)); | |
4498 | fprintf_unfiltered (gdb_stdlog, " longword_offset=%s", | |
4499 | paddress (gdbarch, longword_offset)); | |
9ace0497 | 4500 | } |
361d1df0 | 4501 | |
9ace0497 AC |
4502 | addr = sp + stack_offset + longword_offset; |
4503 | ||
4504 | if (mips_debug) | |
4505 | { | |
4506 | int i; | |
5af949e3 UW |
4507 | fprintf_unfiltered (gdb_stdlog, " @%s ", |
4508 | paddress (gdbarch, addr)); | |
9ace0497 AC |
4509 | for (i = 0; i < partial_len; i++) |
4510 | { | |
6d82d43b | 4511 | fprintf_unfiltered (gdb_stdlog, "%02x", |
cb3d25d1 | 4512 | val[i] & 0xff); |
9ace0497 AC |
4513 | } |
4514 | } | |
4515 | write_memory (addr, val, partial_len); | |
c906108c SS |
4516 | } |
4517 | ||
f09ded24 AC |
4518 | /* Note!!! This is NOT an else clause. Odd sized |
4519 | structs may go thru BOTH paths. Floating point | |
46e0f506 | 4520 | arguments will not. */ |
566f0f7a | 4521 | /* Write this portion of the argument to a general |
6d82d43b | 4522 | purpose register. */ |
74ed0bb4 MD |
4523 | if (argreg <= MIPS_LAST_ARG_REGNUM (gdbarch) |
4524 | && !fp_register_arg_p (gdbarch, typecode, arg_type)) | |
c906108c | 4525 | { |
6d82d43b | 4526 | LONGEST regval = |
a8852dc5 | 4527 | extract_signed_integer (val, partial_len, byte_order); |
c906108c | 4528 | |
9ace0497 | 4529 | if (mips_debug) |
acdb74a0 | 4530 | fprintf_filtered (gdb_stdlog, " - reg=%d val=%s", |
9ace0497 | 4531 | argreg, |
1a69e1e4 | 4532 | phex (regval, regsize)); |
a8852dc5 | 4533 | regcache_cooked_write_signed (regcache, argreg, regval); |
c906108c | 4534 | argreg++; |
c906108c | 4535 | } |
c5aa993b | 4536 | |
c906108c SS |
4537 | len -= partial_len; |
4538 | val += partial_len; | |
4539 | ||
b021a221 MS |
4540 | /* Compute the offset into the stack at which we will |
4541 | copy the next parameter. | |
566f0f7a | 4542 | |
566f0f7a | 4543 | In the new EABI (and the NABI32), the stack_offset |
46e0f506 | 4544 | only needs to be adjusted when it has been used. */ |
c906108c | 4545 | |
46e0f506 | 4546 | if (stack_used_p) |
1a69e1e4 | 4547 | stack_offset += align_up (partial_len, regsize); |
c906108c SS |
4548 | } |
4549 | } | |
9ace0497 AC |
4550 | if (mips_debug) |
4551 | fprintf_unfiltered (gdb_stdlog, "\n"); | |
c906108c SS |
4552 | } |
4553 | ||
f10683bb | 4554 | regcache_cooked_write_signed (regcache, MIPS_SP_REGNUM, sp); |
310e9b6a | 4555 | |
0f71a2f6 JM |
4556 | /* Return adjusted stack pointer. */ |
4557 | return sp; | |
4558 | } | |
4559 | ||
a1f5b845 | 4560 | /* Determine the return value convention being used. */ |
6d82d43b | 4561 | |
9c8fdbfa | 4562 | static enum return_value_convention |
6a3a010b | 4563 | mips_eabi_return_value (struct gdbarch *gdbarch, struct value *function, |
9c8fdbfa | 4564 | struct type *type, struct regcache *regcache, |
47a35522 | 4565 | gdb_byte *readbuf, const gdb_byte *writebuf) |
6d82d43b | 4566 | { |
609ba780 JM |
4567 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
4568 | int fp_return_type = 0; | |
4569 | int offset, regnum, xfer; | |
4570 | ||
9c8fdbfa AC |
4571 | if (TYPE_LENGTH (type) > 2 * mips_abi_regsize (gdbarch)) |
4572 | return RETURN_VALUE_STRUCT_CONVENTION; | |
609ba780 JM |
4573 | |
4574 | /* Floating point type? */ | |
4575 | if (tdep->mips_fpu_type != MIPS_FPU_NONE) | |
4576 | { | |
4577 | if (TYPE_CODE (type) == TYPE_CODE_FLT) | |
4578 | fp_return_type = 1; | |
4579 | /* Structs with a single field of float type | |
4580 | are returned in a floating point register. */ | |
4581 | if ((TYPE_CODE (type) == TYPE_CODE_STRUCT | |
4582 | || TYPE_CODE (type) == TYPE_CODE_UNION) | |
4583 | && TYPE_NFIELDS (type) == 1) | |
4584 | { | |
4585 | struct type *fieldtype = TYPE_FIELD_TYPE (type, 0); | |
4586 | ||
4587 | if (TYPE_CODE (check_typedef (fieldtype)) == TYPE_CODE_FLT) | |
4588 | fp_return_type = 1; | |
4589 | } | |
4590 | } | |
4591 | ||
4592 | if (fp_return_type) | |
4593 | { | |
4594 | /* A floating-point value belongs in the least significant part | |
4595 | of FP0/FP1. */ | |
4596 | if (mips_debug) | |
4597 | fprintf_unfiltered (gdb_stderr, "Return float in $fp0\n"); | |
4598 | regnum = mips_regnum (gdbarch)->fp0; | |
4599 | } | |
4600 | else | |
4601 | { | |
4602 | /* An integer value goes in V0/V1. */ | |
4603 | if (mips_debug) | |
4604 | fprintf_unfiltered (gdb_stderr, "Return scalar in $v0\n"); | |
4605 | regnum = MIPS_V0_REGNUM; | |
4606 | } | |
4607 | for (offset = 0; | |
4608 | offset < TYPE_LENGTH (type); | |
4609 | offset += mips_abi_regsize (gdbarch), regnum++) | |
4610 | { | |
4611 | xfer = mips_abi_regsize (gdbarch); | |
4612 | if (offset + xfer > TYPE_LENGTH (type)) | |
4613 | xfer = TYPE_LENGTH (type) - offset; | |
4614 | mips_xfer_register (gdbarch, regcache, | |
4615 | gdbarch_num_regs (gdbarch) + regnum, xfer, | |
4616 | gdbarch_byte_order (gdbarch), readbuf, writebuf, | |
4617 | offset); | |
4618 | } | |
4619 | ||
9c8fdbfa | 4620 | return RETURN_VALUE_REGISTER_CONVENTION; |
6d82d43b AC |
4621 | } |
4622 | ||
6d82d43b AC |
4623 | |
4624 | /* N32/N64 ABI stuff. */ | |
ebafbe83 | 4625 | |
8d26208a DJ |
4626 | /* Search for a naturally aligned double at OFFSET inside a struct |
4627 | ARG_TYPE. The N32 / N64 ABIs pass these in floating point | |
4628 | registers. */ | |
4629 | ||
4630 | static int | |
74ed0bb4 MD |
4631 | mips_n32n64_fp_arg_chunk_p (struct gdbarch *gdbarch, struct type *arg_type, |
4632 | int offset) | |
8d26208a DJ |
4633 | { |
4634 | int i; | |
4635 | ||
4636 | if (TYPE_CODE (arg_type) != TYPE_CODE_STRUCT) | |
4637 | return 0; | |
4638 | ||
74ed0bb4 | 4639 | if (MIPS_FPU_TYPE (gdbarch) != MIPS_FPU_DOUBLE) |
8d26208a DJ |
4640 | return 0; |
4641 | ||
4642 | if (TYPE_LENGTH (arg_type) < offset + MIPS64_REGSIZE) | |
4643 | return 0; | |
4644 | ||
4645 | for (i = 0; i < TYPE_NFIELDS (arg_type); i++) | |
4646 | { | |
4647 | int pos; | |
4648 | struct type *field_type; | |
4649 | ||
4650 | /* We're only looking at normal fields. */ | |
5bc60cfb | 4651 | if (field_is_static (&TYPE_FIELD (arg_type, i)) |
8d26208a DJ |
4652 | || (TYPE_FIELD_BITPOS (arg_type, i) % 8) != 0) |
4653 | continue; | |
4654 | ||
4655 | /* If we have gone past the offset, there is no double to pass. */ | |
4656 | pos = TYPE_FIELD_BITPOS (arg_type, i) / 8; | |
4657 | if (pos > offset) | |
4658 | return 0; | |
4659 | ||
4660 | field_type = check_typedef (TYPE_FIELD_TYPE (arg_type, i)); | |
4661 | ||
4662 | /* If this field is entirely before the requested offset, go | |
4663 | on to the next one. */ | |
4664 | if (pos + TYPE_LENGTH (field_type) <= offset) | |
4665 | continue; | |
4666 | ||
4667 | /* If this is our special aligned double, we can stop. */ | |
4668 | if (TYPE_CODE (field_type) == TYPE_CODE_FLT | |
4669 | && TYPE_LENGTH (field_type) == MIPS64_REGSIZE) | |
4670 | return 1; | |
4671 | ||
4672 | /* This field starts at or before the requested offset, and | |
4673 | overlaps it. If it is a structure, recurse inwards. */ | |
74ed0bb4 | 4674 | return mips_n32n64_fp_arg_chunk_p (gdbarch, field_type, offset - pos); |
8d26208a DJ |
4675 | } |
4676 | ||
4677 | return 0; | |
4678 | } | |
4679 | ||
f7ab6ec6 | 4680 | static CORE_ADDR |
7d9b040b | 4681 | mips_n32n64_push_dummy_call (struct gdbarch *gdbarch, struct value *function, |
6d82d43b AC |
4682 | struct regcache *regcache, CORE_ADDR bp_addr, |
4683 | int nargs, struct value **args, CORE_ADDR sp, | |
4684 | int struct_return, CORE_ADDR struct_addr) | |
cb3d25d1 MS |
4685 | { |
4686 | int argreg; | |
4687 | int float_argreg; | |
4688 | int argnum; | |
4689 | int len = 0; | |
4690 | int stack_offset = 0; | |
e17a4113 | 4691 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
7d9b040b | 4692 | CORE_ADDR func_addr = find_function_addr (function, NULL); |
cb3d25d1 | 4693 | |
25ab4790 AC |
4694 | /* For shared libraries, "t9" needs to point at the function |
4695 | address. */ | |
4c7d22cb | 4696 | regcache_cooked_write_signed (regcache, MIPS_T9_REGNUM, func_addr); |
25ab4790 AC |
4697 | |
4698 | /* Set the return address register to point to the entry point of | |
4699 | the program, where a breakpoint lies in wait. */ | |
4c7d22cb | 4700 | regcache_cooked_write_signed (regcache, MIPS_RA_REGNUM, bp_addr); |
25ab4790 | 4701 | |
cb3d25d1 MS |
4702 | /* First ensure that the stack and structure return address (if any) |
4703 | are properly aligned. The stack has to be at least 64-bit | |
4704 | aligned even on 32-bit machines, because doubles must be 64-bit | |
4705 | aligned. For n32 and n64, stack frames need to be 128-bit | |
4706 | aligned, so we round to this widest known alignment. */ | |
4707 | ||
5b03f266 AC |
4708 | sp = align_down (sp, 16); |
4709 | struct_addr = align_down (struct_addr, 16); | |
cb3d25d1 MS |
4710 | |
4711 | /* Now make space on the stack for the args. */ | |
4712 | for (argnum = 0; argnum < nargs; argnum++) | |
1a69e1e4 | 4713 | len += align_up (TYPE_LENGTH (value_type (args[argnum])), MIPS64_REGSIZE); |
5b03f266 | 4714 | sp -= align_up (len, 16); |
cb3d25d1 MS |
4715 | |
4716 | if (mips_debug) | |
6d82d43b | 4717 | fprintf_unfiltered (gdb_stdlog, |
5af949e3 UW |
4718 | "mips_n32n64_push_dummy_call: sp=%s allocated %ld\n", |
4719 | paddress (gdbarch, sp), (long) align_up (len, 16)); | |
cb3d25d1 MS |
4720 | |
4721 | /* Initialize the integer and float register pointers. */ | |
4c7d22cb | 4722 | argreg = MIPS_A0_REGNUM; |
72a155b4 | 4723 | float_argreg = mips_fpa0_regnum (gdbarch); |
cb3d25d1 | 4724 | |
46e0f506 | 4725 | /* The struct_return pointer occupies the first parameter-passing reg. */ |
cb3d25d1 MS |
4726 | if (struct_return) |
4727 | { | |
4728 | if (mips_debug) | |
4729 | fprintf_unfiltered (gdb_stdlog, | |
025bb325 MS |
4730 | "mips_n32n64_push_dummy_call: " |
4731 | "struct_return reg=%d %s\n", | |
5af949e3 | 4732 | argreg, paddress (gdbarch, struct_addr)); |
9c9acae0 | 4733 | regcache_cooked_write_unsigned (regcache, argreg++, struct_addr); |
cb3d25d1 MS |
4734 | } |
4735 | ||
4736 | /* Now load as many as possible of the first arguments into | |
4737 | registers, and push the rest onto the stack. Loop thru args | |
4738 | from first to last. */ | |
4739 | for (argnum = 0; argnum < nargs; argnum++) | |
4740 | { | |
47a35522 | 4741 | const gdb_byte *val; |
cb3d25d1 | 4742 | struct value *arg = args[argnum]; |
4991999e | 4743 | struct type *arg_type = check_typedef (value_type (arg)); |
cb3d25d1 MS |
4744 | int len = TYPE_LENGTH (arg_type); |
4745 | enum type_code typecode = TYPE_CODE (arg_type); | |
4746 | ||
4747 | if (mips_debug) | |
4748 | fprintf_unfiltered (gdb_stdlog, | |
25ab4790 | 4749 | "mips_n32n64_push_dummy_call: %d len=%d type=%d", |
cb3d25d1 MS |
4750 | argnum + 1, len, (int) typecode); |
4751 | ||
47a35522 | 4752 | val = value_contents (arg); |
cb3d25d1 | 4753 | |
5b68030f JM |
4754 | /* A 128-bit long double value requires an even-odd pair of |
4755 | floating-point registers. */ | |
4756 | if (len == 16 | |
4757 | && fp_register_arg_p (gdbarch, typecode, arg_type) | |
4758 | && (float_argreg & 1)) | |
4759 | { | |
4760 | float_argreg++; | |
4761 | argreg++; | |
4762 | } | |
4763 | ||
74ed0bb4 MD |
4764 | if (fp_register_arg_p (gdbarch, typecode, arg_type) |
4765 | && argreg <= MIPS_LAST_ARG_REGNUM (gdbarch)) | |
cb3d25d1 MS |
4766 | { |
4767 | /* This is a floating point value that fits entirely | |
5b68030f JM |
4768 | in a single register or a pair of registers. */ |
4769 | int reglen = (len <= MIPS64_REGSIZE ? len : MIPS64_REGSIZE); | |
e17a4113 | 4770 | LONGEST regval = extract_unsigned_integer (val, reglen, byte_order); |
cb3d25d1 MS |
4771 | if (mips_debug) |
4772 | fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s", | |
5b68030f | 4773 | float_argreg, phex (regval, reglen)); |
8d26208a | 4774 | regcache_cooked_write_unsigned (regcache, float_argreg, regval); |
cb3d25d1 MS |
4775 | |
4776 | if (mips_debug) | |
4777 | fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s", | |
5b68030f | 4778 | argreg, phex (regval, reglen)); |
9c9acae0 | 4779 | regcache_cooked_write_unsigned (regcache, argreg, regval); |
8d26208a DJ |
4780 | float_argreg++; |
4781 | argreg++; | |
5b68030f JM |
4782 | if (len == 16) |
4783 | { | |
e17a4113 UW |
4784 | regval = extract_unsigned_integer (val + reglen, |
4785 | reglen, byte_order); | |
5b68030f JM |
4786 | if (mips_debug) |
4787 | fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s", | |
4788 | float_argreg, phex (regval, reglen)); | |
4789 | regcache_cooked_write_unsigned (regcache, float_argreg, regval); | |
4790 | ||
4791 | if (mips_debug) | |
4792 | fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s", | |
4793 | argreg, phex (regval, reglen)); | |
4794 | regcache_cooked_write_unsigned (regcache, argreg, regval); | |
4795 | float_argreg++; | |
4796 | argreg++; | |
4797 | } | |
cb3d25d1 MS |
4798 | } |
4799 | else | |
4800 | { | |
4801 | /* Copy the argument to general registers or the stack in | |
4802 | register-sized pieces. Large arguments are split between | |
4803 | registers and stack. */ | |
ab2e1992 MR |
4804 | /* For N32/N64, structs, unions, or other composite types are |
4805 | treated as a sequence of doublewords, and are passed in integer | |
4806 | or floating point registers as though they were simple scalar | |
4807 | parameters to the extent that they fit, with any excess on the | |
4808 | stack packed according to the normal memory layout of the | |
4809 | object. | |
4810 | The caller does not reserve space for the register arguments; | |
4811 | the callee is responsible for reserving it if required. */ | |
cb3d25d1 | 4812 | /* Note: Floating-point values that didn't fit into an FP |
6d82d43b | 4813 | register are only written to memory. */ |
cb3d25d1 MS |
4814 | while (len > 0) |
4815 | { | |
ad018eee | 4816 | /* Remember if the argument was written to the stack. */ |
cb3d25d1 | 4817 | int stack_used_p = 0; |
1a69e1e4 | 4818 | int partial_len = (len < MIPS64_REGSIZE ? len : MIPS64_REGSIZE); |
cb3d25d1 MS |
4819 | |
4820 | if (mips_debug) | |
4821 | fprintf_unfiltered (gdb_stdlog, " -- partial=%d", | |
4822 | partial_len); | |
4823 | ||
74ed0bb4 MD |
4824 | if (fp_register_arg_p (gdbarch, typecode, arg_type)) |
4825 | gdb_assert (argreg > MIPS_LAST_ARG_REGNUM (gdbarch)); | |
8d26208a | 4826 | |
cb3d25d1 | 4827 | /* Write this portion of the argument to the stack. */ |
74ed0bb4 | 4828 | if (argreg > MIPS_LAST_ARG_REGNUM (gdbarch)) |
cb3d25d1 MS |
4829 | { |
4830 | /* Should shorter than int integer values be | |
025bb325 | 4831 | promoted to int before being stored? */ |
cb3d25d1 MS |
4832 | int longword_offset = 0; |
4833 | CORE_ADDR addr; | |
4834 | stack_used_p = 1; | |
72a155b4 | 4835 | if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) |
cb3d25d1 | 4836 | { |
1a69e1e4 | 4837 | if ((typecode == TYPE_CODE_INT |
5b68030f | 4838 | || typecode == TYPE_CODE_PTR) |
1a69e1e4 DJ |
4839 | && len <= 4) |
4840 | longword_offset = MIPS64_REGSIZE - len; | |
cb3d25d1 MS |
4841 | } |
4842 | ||
4843 | if (mips_debug) | |
4844 | { | |
5af949e3 UW |
4845 | fprintf_unfiltered (gdb_stdlog, " - stack_offset=%s", |
4846 | paddress (gdbarch, stack_offset)); | |
4847 | fprintf_unfiltered (gdb_stdlog, " longword_offset=%s", | |
4848 | paddress (gdbarch, longword_offset)); | |
cb3d25d1 MS |
4849 | } |
4850 | ||
4851 | addr = sp + stack_offset + longword_offset; | |
4852 | ||
4853 | if (mips_debug) | |
4854 | { | |
4855 | int i; | |
5af949e3 UW |
4856 | fprintf_unfiltered (gdb_stdlog, " @%s ", |
4857 | paddress (gdbarch, addr)); | |
cb3d25d1 MS |
4858 | for (i = 0; i < partial_len; i++) |
4859 | { | |
6d82d43b | 4860 | fprintf_unfiltered (gdb_stdlog, "%02x", |
cb3d25d1 MS |
4861 | val[i] & 0xff); |
4862 | } | |
4863 | } | |
4864 | write_memory (addr, val, partial_len); | |
4865 | } | |
4866 | ||
4867 | /* Note!!! This is NOT an else clause. Odd sized | |
8d26208a | 4868 | structs may go thru BOTH paths. */ |
cb3d25d1 | 4869 | /* Write this portion of the argument to a general |
6d82d43b | 4870 | purpose register. */ |
74ed0bb4 | 4871 | if (argreg <= MIPS_LAST_ARG_REGNUM (gdbarch)) |
cb3d25d1 | 4872 | { |
5863b5d5 MR |
4873 | LONGEST regval; |
4874 | ||
4875 | /* Sign extend pointers, 32-bit integers and signed | |
4876 | 16-bit and 8-bit integers; everything else is taken | |
4877 | as is. */ | |
4878 | ||
4879 | if ((partial_len == 4 | |
4880 | && (typecode == TYPE_CODE_PTR | |
4881 | || typecode == TYPE_CODE_INT)) | |
4882 | || (partial_len < 4 | |
4883 | && typecode == TYPE_CODE_INT | |
4884 | && !TYPE_UNSIGNED (arg_type))) | |
e17a4113 UW |
4885 | regval = extract_signed_integer (val, partial_len, |
4886 | byte_order); | |
5863b5d5 | 4887 | else |
e17a4113 UW |
4888 | regval = extract_unsigned_integer (val, partial_len, |
4889 | byte_order); | |
cb3d25d1 MS |
4890 | |
4891 | /* A non-floating-point argument being passed in a | |
4892 | general register. If a struct or union, and if | |
4893 | the remaining length is smaller than the register | |
4894 | size, we have to adjust the register value on | |
4895 | big endian targets. | |
4896 | ||
4897 | It does not seem to be necessary to do the | |
1a69e1e4 | 4898 | same for integral types. */ |
cb3d25d1 | 4899 | |
72a155b4 | 4900 | if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG |
1a69e1e4 | 4901 | && partial_len < MIPS64_REGSIZE |
06f9a1af MR |
4902 | && (typecode == TYPE_CODE_STRUCT |
4903 | || typecode == TYPE_CODE_UNION)) | |
1a69e1e4 | 4904 | regval <<= ((MIPS64_REGSIZE - partial_len) |
9ecf7166 | 4905 | * TARGET_CHAR_BIT); |
cb3d25d1 MS |
4906 | |
4907 | if (mips_debug) | |
4908 | fprintf_filtered (gdb_stdlog, " - reg=%d val=%s", | |
4909 | argreg, | |
1a69e1e4 | 4910 | phex (regval, MIPS64_REGSIZE)); |
9c9acae0 | 4911 | regcache_cooked_write_unsigned (regcache, argreg, regval); |
8d26208a | 4912 | |
74ed0bb4 | 4913 | if (mips_n32n64_fp_arg_chunk_p (gdbarch, arg_type, |
8d26208a DJ |
4914 | TYPE_LENGTH (arg_type) - len)) |
4915 | { | |
4916 | if (mips_debug) | |
4917 | fprintf_filtered (gdb_stdlog, " - fpreg=%d val=%s", | |
4918 | float_argreg, | |
4919 | phex (regval, MIPS64_REGSIZE)); | |
4920 | regcache_cooked_write_unsigned (regcache, float_argreg, | |
4921 | regval); | |
4922 | } | |
4923 | ||
4924 | float_argreg++; | |
cb3d25d1 MS |
4925 | argreg++; |
4926 | } | |
4927 | ||
4928 | len -= partial_len; | |
4929 | val += partial_len; | |
4930 | ||
b021a221 MS |
4931 | /* Compute the offset into the stack at which we will |
4932 | copy the next parameter. | |
cb3d25d1 MS |
4933 | |
4934 | In N32 (N64?), the stack_offset only needs to be | |
4935 | adjusted when it has been used. */ | |
4936 | ||
4937 | if (stack_used_p) | |
1a69e1e4 | 4938 | stack_offset += align_up (partial_len, MIPS64_REGSIZE); |
cb3d25d1 MS |
4939 | } |
4940 | } | |
4941 | if (mips_debug) | |
4942 | fprintf_unfiltered (gdb_stdlog, "\n"); | |
4943 | } | |
4944 | ||
f10683bb | 4945 | regcache_cooked_write_signed (regcache, MIPS_SP_REGNUM, sp); |
310e9b6a | 4946 | |
cb3d25d1 MS |
4947 | /* Return adjusted stack pointer. */ |
4948 | return sp; | |
4949 | } | |
4950 | ||
6d82d43b | 4951 | static enum return_value_convention |
6a3a010b | 4952 | mips_n32n64_return_value (struct gdbarch *gdbarch, struct value *function, |
6d82d43b | 4953 | struct type *type, struct regcache *regcache, |
47a35522 | 4954 | gdb_byte *readbuf, const gdb_byte *writebuf) |
ebafbe83 | 4955 | { |
72a155b4 | 4956 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
b18bb924 MR |
4957 | |
4958 | /* From MIPSpro N32 ABI Handbook, Document Number: 007-2816-004 | |
4959 | ||
4960 | Function results are returned in $2 (and $3 if needed), or $f0 (and $f2 | |
4961 | if needed), as appropriate for the type. Composite results (struct, | |
4962 | union, or array) are returned in $2/$f0 and $3/$f2 according to the | |
4963 | following rules: | |
4964 | ||
4965 | * A struct with only one or two floating point fields is returned in $f0 | |
4966 | (and $f2 if necessary). This is a generalization of the Fortran COMPLEX | |
4967 | case. | |
4968 | ||
f08877ba | 4969 | * Any other composite results of at most 128 bits are returned in |
b18bb924 MR |
4970 | $2 (first 64 bits) and $3 (remainder, if necessary). |
4971 | ||
4972 | * Larger composite results are handled by converting the function to a | |
4973 | procedure with an implicit first parameter, which is a pointer to an area | |
4974 | reserved by the caller to receive the result. [The o32-bit ABI requires | |
4975 | that all composite results be handled by conversion to implicit first | |
4976 | parameters. The MIPS/SGI Fortran implementation has always made a | |
4977 | specific exception to return COMPLEX results in the floating point | |
4978 | registers.] */ | |
4979 | ||
f08877ba | 4980 | if (TYPE_LENGTH (type) > 2 * MIPS64_REGSIZE) |
6d82d43b | 4981 | return RETURN_VALUE_STRUCT_CONVENTION; |
d05f6826 DJ |
4982 | else if (TYPE_CODE (type) == TYPE_CODE_FLT |
4983 | && TYPE_LENGTH (type) == 16 | |
4984 | && tdep->mips_fpu_type != MIPS_FPU_NONE) | |
4985 | { | |
4986 | /* A 128-bit floating-point value fills both $f0 and $f2. The | |
4987 | two registers are used in the same as memory order, so the | |
4988 | eight bytes with the lower memory address are in $f0. */ | |
4989 | if (mips_debug) | |
4990 | fprintf_unfiltered (gdb_stderr, "Return float in $f0 and $f2\n"); | |
ba32f989 | 4991 | mips_xfer_register (gdbarch, regcache, |
dca9aa3a MR |
4992 | (gdbarch_num_regs (gdbarch) |
4993 | + mips_regnum (gdbarch)->fp0), | |
72a155b4 | 4994 | 8, gdbarch_byte_order (gdbarch), |
4c6b5505 | 4995 | readbuf, writebuf, 0); |
ba32f989 | 4996 | mips_xfer_register (gdbarch, regcache, |
dca9aa3a MR |
4997 | (gdbarch_num_regs (gdbarch) |
4998 | + mips_regnum (gdbarch)->fp0 + 2), | |
72a155b4 | 4999 | 8, gdbarch_byte_order (gdbarch), |
4c6b5505 | 5000 | readbuf ? readbuf + 8 : readbuf, |
d05f6826 DJ |
5001 | writebuf ? writebuf + 8 : writebuf, 0); |
5002 | return RETURN_VALUE_REGISTER_CONVENTION; | |
5003 | } | |
6d82d43b AC |
5004 | else if (TYPE_CODE (type) == TYPE_CODE_FLT |
5005 | && tdep->mips_fpu_type != MIPS_FPU_NONE) | |
5006 | { | |
59aa1faa | 5007 | /* A single or double floating-point value that fits in FP0. */ |
6d82d43b AC |
5008 | if (mips_debug) |
5009 | fprintf_unfiltered (gdb_stderr, "Return float in $fp0\n"); | |
ba32f989 | 5010 | mips_xfer_register (gdbarch, regcache, |
dca9aa3a MR |
5011 | (gdbarch_num_regs (gdbarch) |
5012 | + mips_regnum (gdbarch)->fp0), | |
6d82d43b | 5013 | TYPE_LENGTH (type), |
72a155b4 | 5014 | gdbarch_byte_order (gdbarch), |
4c6b5505 | 5015 | readbuf, writebuf, 0); |
6d82d43b AC |
5016 | return RETURN_VALUE_REGISTER_CONVENTION; |
5017 | } | |
5018 | else if (TYPE_CODE (type) == TYPE_CODE_STRUCT | |
5019 | && TYPE_NFIELDS (type) <= 2 | |
5020 | && TYPE_NFIELDS (type) >= 1 | |
5021 | && ((TYPE_NFIELDS (type) == 1 | |
b18bb924 | 5022 | && (TYPE_CODE (check_typedef (TYPE_FIELD_TYPE (type, 0))) |
6d82d43b AC |
5023 | == TYPE_CODE_FLT)) |
5024 | || (TYPE_NFIELDS (type) == 2 | |
b18bb924 | 5025 | && (TYPE_CODE (check_typedef (TYPE_FIELD_TYPE (type, 0))) |
6d82d43b | 5026 | == TYPE_CODE_FLT) |
b18bb924 | 5027 | && (TYPE_CODE (check_typedef (TYPE_FIELD_TYPE (type, 1))) |
5b68030f | 5028 | == TYPE_CODE_FLT)))) |
6d82d43b AC |
5029 | { |
5030 | /* A struct that contains one or two floats. Each value is part | |
5031 | in the least significant part of their floating point | |
5b68030f | 5032 | register (or GPR, for soft float). */ |
6d82d43b AC |
5033 | int regnum; |
5034 | int field; | |
5b68030f JM |
5035 | for (field = 0, regnum = (tdep->mips_fpu_type != MIPS_FPU_NONE |
5036 | ? mips_regnum (gdbarch)->fp0 | |
5037 | : MIPS_V0_REGNUM); | |
6d82d43b AC |
5038 | field < TYPE_NFIELDS (type); field++, regnum += 2) |
5039 | { | |
5040 | int offset = (FIELD_BITPOS (TYPE_FIELDS (type)[field]) | |
5041 | / TARGET_CHAR_BIT); | |
5042 | if (mips_debug) | |
5043 | fprintf_unfiltered (gdb_stderr, "Return float struct+%d\n", | |
5044 | offset); | |
5b68030f JM |
5045 | if (TYPE_LENGTH (TYPE_FIELD_TYPE (type, field)) == 16) |
5046 | { | |
5047 | /* A 16-byte long double field goes in two consecutive | |
5048 | registers. */ | |
5049 | mips_xfer_register (gdbarch, regcache, | |
5050 | gdbarch_num_regs (gdbarch) + regnum, | |
5051 | 8, | |
5052 | gdbarch_byte_order (gdbarch), | |
5053 | readbuf, writebuf, offset); | |
5054 | mips_xfer_register (gdbarch, regcache, | |
5055 | gdbarch_num_regs (gdbarch) + regnum + 1, | |
5056 | 8, | |
5057 | gdbarch_byte_order (gdbarch), | |
5058 | readbuf, writebuf, offset + 8); | |
5059 | } | |
5060 | else | |
5061 | mips_xfer_register (gdbarch, regcache, | |
5062 | gdbarch_num_regs (gdbarch) + regnum, | |
5063 | TYPE_LENGTH (TYPE_FIELD_TYPE (type, field)), | |
5064 | gdbarch_byte_order (gdbarch), | |
5065 | readbuf, writebuf, offset); | |
6d82d43b AC |
5066 | } |
5067 | return RETURN_VALUE_REGISTER_CONVENTION; | |
5068 | } | |
5069 | else if (TYPE_CODE (type) == TYPE_CODE_STRUCT | |
f08877ba JB |
5070 | || TYPE_CODE (type) == TYPE_CODE_UNION |
5071 | || TYPE_CODE (type) == TYPE_CODE_ARRAY) | |
6d82d43b | 5072 | { |
f08877ba | 5073 | /* A composite type. Extract the left justified value, |
6d82d43b AC |
5074 | regardless of the byte order. I.e. DO NOT USE |
5075 | mips_xfer_lower. */ | |
5076 | int offset; | |
5077 | int regnum; | |
4c7d22cb | 5078 | for (offset = 0, regnum = MIPS_V0_REGNUM; |
6d82d43b | 5079 | offset < TYPE_LENGTH (type); |
72a155b4 | 5080 | offset += register_size (gdbarch, regnum), regnum++) |
6d82d43b | 5081 | { |
72a155b4 | 5082 | int xfer = register_size (gdbarch, regnum); |
6d82d43b AC |
5083 | if (offset + xfer > TYPE_LENGTH (type)) |
5084 | xfer = TYPE_LENGTH (type) - offset; | |
5085 | if (mips_debug) | |
5086 | fprintf_unfiltered (gdb_stderr, "Return struct+%d:%d in $%d\n", | |
5087 | offset, xfer, regnum); | |
ba32f989 DJ |
5088 | mips_xfer_register (gdbarch, regcache, |
5089 | gdbarch_num_regs (gdbarch) + regnum, | |
72a155b4 UW |
5090 | xfer, BFD_ENDIAN_UNKNOWN, readbuf, writebuf, |
5091 | offset); | |
6d82d43b AC |
5092 | } |
5093 | return RETURN_VALUE_REGISTER_CONVENTION; | |
5094 | } | |
5095 | else | |
5096 | { | |
5097 | /* A scalar extract each part but least-significant-byte | |
5098 | justified. */ | |
5099 | int offset; | |
5100 | int regnum; | |
4c7d22cb | 5101 | for (offset = 0, regnum = MIPS_V0_REGNUM; |
6d82d43b | 5102 | offset < TYPE_LENGTH (type); |
72a155b4 | 5103 | offset += register_size (gdbarch, regnum), regnum++) |
6d82d43b | 5104 | { |
72a155b4 | 5105 | int xfer = register_size (gdbarch, regnum); |
6d82d43b AC |
5106 | if (offset + xfer > TYPE_LENGTH (type)) |
5107 | xfer = TYPE_LENGTH (type) - offset; | |
5108 | if (mips_debug) | |
5109 | fprintf_unfiltered (gdb_stderr, "Return scalar+%d:%d in $%d\n", | |
5110 | offset, xfer, regnum); | |
ba32f989 DJ |
5111 | mips_xfer_register (gdbarch, regcache, |
5112 | gdbarch_num_regs (gdbarch) + regnum, | |
72a155b4 | 5113 | xfer, gdbarch_byte_order (gdbarch), |
4c6b5505 | 5114 | readbuf, writebuf, offset); |
6d82d43b AC |
5115 | } |
5116 | return RETURN_VALUE_REGISTER_CONVENTION; | |
5117 | } | |
5118 | } | |
5119 | ||
6a3a010b MR |
5120 | /* Which registers to use for passing floating-point values between |
5121 | function calls, one of floating-point, general and both kinds of | |
5122 | registers. O32 and O64 use different register kinds for standard | |
5123 | MIPS and MIPS16 code; to make the handling of cases where we may | |
5124 | not know what kind of code is being used (e.g. no debug information) | |
5125 | easier we sometimes use both kinds. */ | |
5126 | ||
5127 | enum mips_fval_reg | |
5128 | { | |
5129 | mips_fval_fpr, | |
5130 | mips_fval_gpr, | |
5131 | mips_fval_both | |
5132 | }; | |
5133 | ||
6d82d43b AC |
5134 | /* O32 ABI stuff. */ |
5135 | ||
5136 | static CORE_ADDR | |
7d9b040b | 5137 | mips_o32_push_dummy_call (struct gdbarch *gdbarch, struct value *function, |
6d82d43b AC |
5138 | struct regcache *regcache, CORE_ADDR bp_addr, |
5139 | int nargs, struct value **args, CORE_ADDR sp, | |
5140 | int struct_return, CORE_ADDR struct_addr) | |
5141 | { | |
5142 | int argreg; | |
5143 | int float_argreg; | |
5144 | int argnum; | |
5145 | int len = 0; | |
5146 | int stack_offset = 0; | |
e17a4113 | 5147 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
7d9b040b | 5148 | CORE_ADDR func_addr = find_function_addr (function, NULL); |
6d82d43b AC |
5149 | |
5150 | /* For shared libraries, "t9" needs to point at the function | |
5151 | address. */ | |
4c7d22cb | 5152 | regcache_cooked_write_signed (regcache, MIPS_T9_REGNUM, func_addr); |
6d82d43b AC |
5153 | |
5154 | /* Set the return address register to point to the entry point of | |
5155 | the program, where a breakpoint lies in wait. */ | |
4c7d22cb | 5156 | regcache_cooked_write_signed (regcache, MIPS_RA_REGNUM, bp_addr); |
6d82d43b AC |
5157 | |
5158 | /* First ensure that the stack and structure return address (if any) | |
5159 | are properly aligned. The stack has to be at least 64-bit | |
5160 | aligned even on 32-bit machines, because doubles must be 64-bit | |
ebafbe83 MS |
5161 | aligned. For n32 and n64, stack frames need to be 128-bit |
5162 | aligned, so we round to this widest known alignment. */ | |
5163 | ||
5b03f266 AC |
5164 | sp = align_down (sp, 16); |
5165 | struct_addr = align_down (struct_addr, 16); | |
ebafbe83 MS |
5166 | |
5167 | /* Now make space on the stack for the args. */ | |
5168 | for (argnum = 0; argnum < nargs; argnum++) | |
968b5391 MR |
5169 | { |
5170 | struct type *arg_type = check_typedef (value_type (args[argnum])); | |
968b5391 MR |
5171 | |
5172 | /* Align to double-word if necessary. */ | |
2afd3f0a | 5173 | if (mips_type_needs_double_align (arg_type)) |
1a69e1e4 | 5174 | len = align_up (len, MIPS32_REGSIZE * 2); |
968b5391 | 5175 | /* Allocate space on the stack. */ |
354ecfd5 | 5176 | len += align_up (TYPE_LENGTH (arg_type), MIPS32_REGSIZE); |
968b5391 | 5177 | } |
5b03f266 | 5178 | sp -= align_up (len, 16); |
ebafbe83 MS |
5179 | |
5180 | if (mips_debug) | |
6d82d43b | 5181 | fprintf_unfiltered (gdb_stdlog, |
5af949e3 UW |
5182 | "mips_o32_push_dummy_call: sp=%s allocated %ld\n", |
5183 | paddress (gdbarch, sp), (long) align_up (len, 16)); | |
ebafbe83 MS |
5184 | |
5185 | /* Initialize the integer and float register pointers. */ | |
4c7d22cb | 5186 | argreg = MIPS_A0_REGNUM; |
72a155b4 | 5187 | float_argreg = mips_fpa0_regnum (gdbarch); |
ebafbe83 | 5188 | |
bcb0cc15 | 5189 | /* The struct_return pointer occupies the first parameter-passing reg. */ |
ebafbe83 MS |
5190 | if (struct_return) |
5191 | { | |
5192 | if (mips_debug) | |
5193 | fprintf_unfiltered (gdb_stdlog, | |
025bb325 MS |
5194 | "mips_o32_push_dummy_call: " |
5195 | "struct_return reg=%d %s\n", | |
5af949e3 | 5196 | argreg, paddress (gdbarch, struct_addr)); |
9c9acae0 | 5197 | regcache_cooked_write_unsigned (regcache, argreg++, struct_addr); |
1a69e1e4 | 5198 | stack_offset += MIPS32_REGSIZE; |
ebafbe83 MS |
5199 | } |
5200 | ||
5201 | /* Now load as many as possible of the first arguments into | |
5202 | registers, and push the rest onto the stack. Loop thru args | |
5203 | from first to last. */ | |
5204 | for (argnum = 0; argnum < nargs; argnum++) | |
5205 | { | |
47a35522 | 5206 | const gdb_byte *val; |
ebafbe83 | 5207 | struct value *arg = args[argnum]; |
4991999e | 5208 | struct type *arg_type = check_typedef (value_type (arg)); |
ebafbe83 MS |
5209 | int len = TYPE_LENGTH (arg_type); |
5210 | enum type_code typecode = TYPE_CODE (arg_type); | |
5211 | ||
5212 | if (mips_debug) | |
5213 | fprintf_unfiltered (gdb_stdlog, | |
25ab4790 | 5214 | "mips_o32_push_dummy_call: %d len=%d type=%d", |
46cac009 AC |
5215 | argnum + 1, len, (int) typecode); |
5216 | ||
47a35522 | 5217 | val = value_contents (arg); |
46cac009 AC |
5218 | |
5219 | /* 32-bit ABIs always start floating point arguments in an | |
5220 | even-numbered floating point register. Round the FP register | |
5221 | up before the check to see if there are any FP registers | |
6a3a010b MR |
5222 | left. O32 targets also pass the FP in the integer registers |
5223 | so also round up normal registers. */ | |
74ed0bb4 | 5224 | if (fp_register_arg_p (gdbarch, typecode, arg_type)) |
46cac009 AC |
5225 | { |
5226 | if ((float_argreg & 1)) | |
5227 | float_argreg++; | |
5228 | } | |
5229 | ||
5230 | /* Floating point arguments passed in registers have to be | |
6a3a010b MR |
5231 | treated specially. On 32-bit architectures, doubles are |
5232 | passed in register pairs; the even FP register gets the | |
5233 | low word, and the odd FP register gets the high word. | |
5234 | On O32, the first two floating point arguments are also | |
5235 | copied to general registers, following their memory order, | |
5236 | because MIPS16 functions don't use float registers for | |
5237 | arguments. This duplication of arguments in general | |
5238 | registers can't hurt non-MIPS16 functions, because those | |
5239 | registers are normally skipped. */ | |
46cac009 | 5240 | |
74ed0bb4 MD |
5241 | if (fp_register_arg_p (gdbarch, typecode, arg_type) |
5242 | && float_argreg <= MIPS_LAST_FP_ARG_REGNUM (gdbarch)) | |
46cac009 | 5243 | { |
8b07f6d8 | 5244 | if (register_size (gdbarch, float_argreg) < 8 && len == 8) |
46cac009 | 5245 | { |
6a3a010b MR |
5246 | int freg_offset = gdbarch_byte_order (gdbarch) |
5247 | == BFD_ENDIAN_BIG ? 1 : 0; | |
46cac009 AC |
5248 | unsigned long regval; |
5249 | ||
6a3a010b MR |
5250 | /* First word. */ |
5251 | regval = extract_unsigned_integer (val, 4, byte_order); | |
46cac009 AC |
5252 | if (mips_debug) |
5253 | fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s", | |
6a3a010b MR |
5254 | float_argreg + freg_offset, |
5255 | phex (regval, 4)); | |
025bb325 | 5256 | regcache_cooked_write_unsigned (regcache, |
6a3a010b MR |
5257 | float_argreg++ + freg_offset, |
5258 | regval); | |
46cac009 AC |
5259 | if (mips_debug) |
5260 | fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s", | |
5261 | argreg, phex (regval, 4)); | |
9c9acae0 | 5262 | regcache_cooked_write_unsigned (regcache, argreg++, regval); |
46cac009 | 5263 | |
6a3a010b MR |
5264 | /* Second word. */ |
5265 | regval = extract_unsigned_integer (val + 4, 4, byte_order); | |
46cac009 AC |
5266 | if (mips_debug) |
5267 | fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s", | |
6a3a010b MR |
5268 | float_argreg - freg_offset, |
5269 | phex (regval, 4)); | |
025bb325 | 5270 | regcache_cooked_write_unsigned (regcache, |
6a3a010b MR |
5271 | float_argreg++ - freg_offset, |
5272 | regval); | |
46cac009 AC |
5273 | if (mips_debug) |
5274 | fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s", | |
5275 | argreg, phex (regval, 4)); | |
9c9acae0 | 5276 | regcache_cooked_write_unsigned (regcache, argreg++, regval); |
46cac009 AC |
5277 | } |
5278 | else | |
5279 | { | |
5280 | /* This is a floating point value that fits entirely | |
5281 | in a single register. */ | |
5282 | /* On 32 bit ABI's the float_argreg is further adjusted | |
6d82d43b | 5283 | above to ensure that it is even register aligned. */ |
e17a4113 | 5284 | LONGEST regval = extract_unsigned_integer (val, len, byte_order); |
46cac009 AC |
5285 | if (mips_debug) |
5286 | fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s", | |
5287 | float_argreg, phex (regval, len)); | |
025bb325 MS |
5288 | regcache_cooked_write_unsigned (regcache, |
5289 | float_argreg++, regval); | |
5b68030f JM |
5290 | /* Although two FP registers are reserved for each |
5291 | argument, only one corresponding integer register is | |
5292 | reserved. */ | |
46cac009 AC |
5293 | if (mips_debug) |
5294 | fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s", | |
5295 | argreg, phex (regval, len)); | |
5b68030f | 5296 | regcache_cooked_write_unsigned (regcache, argreg++, regval); |
46cac009 AC |
5297 | } |
5298 | /* Reserve space for the FP register. */ | |
1a69e1e4 | 5299 | stack_offset += align_up (len, MIPS32_REGSIZE); |
46cac009 AC |
5300 | } |
5301 | else | |
5302 | { | |
5303 | /* Copy the argument to general registers or the stack in | |
5304 | register-sized pieces. Large arguments are split between | |
5305 | registers and stack. */ | |
1a69e1e4 DJ |
5306 | /* Note: structs whose size is not a multiple of MIPS32_REGSIZE |
5307 | are treated specially: Irix cc passes | |
d5ac5a39 AC |
5308 | them in registers where gcc sometimes puts them on the |
5309 | stack. For maximum compatibility, we will put them in | |
5310 | both places. */ | |
1a69e1e4 DJ |
5311 | int odd_sized_struct = (len > MIPS32_REGSIZE |
5312 | && len % MIPS32_REGSIZE != 0); | |
46cac009 AC |
5313 | /* Structures should be aligned to eight bytes (even arg registers) |
5314 | on MIPS_ABI_O32, if their first member has double precision. */ | |
2afd3f0a | 5315 | if (mips_type_needs_double_align (arg_type)) |
46cac009 AC |
5316 | { |
5317 | if ((argreg & 1)) | |
968b5391 MR |
5318 | { |
5319 | argreg++; | |
1a69e1e4 | 5320 | stack_offset += MIPS32_REGSIZE; |
968b5391 | 5321 | } |
46cac009 | 5322 | } |
46cac009 AC |
5323 | while (len > 0) |
5324 | { | |
5325 | /* Remember if the argument was written to the stack. */ | |
5326 | int stack_used_p = 0; | |
1a69e1e4 | 5327 | int partial_len = (len < MIPS32_REGSIZE ? len : MIPS32_REGSIZE); |
46cac009 AC |
5328 | |
5329 | if (mips_debug) | |
5330 | fprintf_unfiltered (gdb_stdlog, " -- partial=%d", | |
5331 | partial_len); | |
5332 | ||
5333 | /* Write this portion of the argument to the stack. */ | |
74ed0bb4 | 5334 | if (argreg > MIPS_LAST_ARG_REGNUM (gdbarch) |
968b5391 | 5335 | || odd_sized_struct) |
46cac009 AC |
5336 | { |
5337 | /* Should shorter than int integer values be | |
025bb325 | 5338 | promoted to int before being stored? */ |
46cac009 AC |
5339 | int longword_offset = 0; |
5340 | CORE_ADDR addr; | |
5341 | stack_used_p = 1; | |
46cac009 AC |
5342 | |
5343 | if (mips_debug) | |
5344 | { | |
5af949e3 UW |
5345 | fprintf_unfiltered (gdb_stdlog, " - stack_offset=%s", |
5346 | paddress (gdbarch, stack_offset)); | |
5347 | fprintf_unfiltered (gdb_stdlog, " longword_offset=%s", | |
5348 | paddress (gdbarch, longword_offset)); | |
46cac009 AC |
5349 | } |
5350 | ||
5351 | addr = sp + stack_offset + longword_offset; | |
5352 | ||
5353 | if (mips_debug) | |
5354 | { | |
5355 | int i; | |
5af949e3 UW |
5356 | fprintf_unfiltered (gdb_stdlog, " @%s ", |
5357 | paddress (gdbarch, addr)); | |
46cac009 AC |
5358 | for (i = 0; i < partial_len; i++) |
5359 | { | |
6d82d43b | 5360 | fprintf_unfiltered (gdb_stdlog, "%02x", |
46cac009 AC |
5361 | val[i] & 0xff); |
5362 | } | |
5363 | } | |
5364 | write_memory (addr, val, partial_len); | |
5365 | } | |
5366 | ||
5367 | /* Note!!! This is NOT an else clause. Odd sized | |
968b5391 | 5368 | structs may go thru BOTH paths. */ |
46cac009 | 5369 | /* Write this portion of the argument to a general |
6d82d43b | 5370 | purpose register. */ |
74ed0bb4 | 5371 | if (argreg <= MIPS_LAST_ARG_REGNUM (gdbarch)) |
46cac009 | 5372 | { |
e17a4113 UW |
5373 | LONGEST regval = extract_signed_integer (val, partial_len, |
5374 | byte_order); | |
4246e332 | 5375 | /* Value may need to be sign extended, because |
1b13c4f6 | 5376 | mips_isa_regsize() != mips_abi_regsize(). */ |
46cac009 AC |
5377 | |
5378 | /* A non-floating-point argument being passed in a | |
5379 | general register. If a struct or union, and if | |
5380 | the remaining length is smaller than the register | |
5381 | size, we have to adjust the register value on | |
5382 | big endian targets. | |
5383 | ||
5384 | It does not seem to be necessary to do the | |
5385 | same for integral types. | |
5386 | ||
5387 | Also don't do this adjustment on O64 binaries. | |
5388 | ||
5389 | cagney/2001-07-23: gdb/179: Also, GCC, when | |
5390 | outputting LE O32 with sizeof (struct) < | |
e914cb17 MR |
5391 | mips_abi_regsize(), generates a left shift |
5392 | as part of storing the argument in a register | |
5393 | (the left shift isn't generated when | |
1b13c4f6 | 5394 | sizeof (struct) >= mips_abi_regsize()). Since |
480d3dd2 AC |
5395 | it is quite possible that this is GCC |
5396 | contradicting the LE/O32 ABI, GDB has not been | |
5397 | adjusted to accommodate this. Either someone | |
5398 | needs to demonstrate that the LE/O32 ABI | |
5399 | specifies such a left shift OR this new ABI gets | |
5400 | identified as such and GDB gets tweaked | |
5401 | accordingly. */ | |
5402 | ||
72a155b4 | 5403 | if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG |
1a69e1e4 | 5404 | && partial_len < MIPS32_REGSIZE |
06f9a1af MR |
5405 | && (typecode == TYPE_CODE_STRUCT |
5406 | || typecode == TYPE_CODE_UNION)) | |
1a69e1e4 | 5407 | regval <<= ((MIPS32_REGSIZE - partial_len) |
9ecf7166 | 5408 | * TARGET_CHAR_BIT); |
46cac009 AC |
5409 | |
5410 | if (mips_debug) | |
5411 | fprintf_filtered (gdb_stdlog, " - reg=%d val=%s", | |
5412 | argreg, | |
1a69e1e4 | 5413 | phex (regval, MIPS32_REGSIZE)); |
9c9acae0 | 5414 | regcache_cooked_write_unsigned (regcache, argreg, regval); |
46cac009 AC |
5415 | argreg++; |
5416 | ||
5417 | /* Prevent subsequent floating point arguments from | |
5418 | being passed in floating point registers. */ | |
74ed0bb4 | 5419 | float_argreg = MIPS_LAST_FP_ARG_REGNUM (gdbarch) + 1; |
46cac009 AC |
5420 | } |
5421 | ||
5422 | len -= partial_len; | |
5423 | val += partial_len; | |
5424 | ||
b021a221 MS |
5425 | /* Compute the offset into the stack at which we will |
5426 | copy the next parameter. | |
46cac009 | 5427 | |
6d82d43b AC |
5428 | In older ABIs, the caller reserved space for |
5429 | registers that contained arguments. This was loosely | |
5430 | refered to as their "home". Consequently, space is | |
5431 | always allocated. */ | |
46cac009 | 5432 | |
1a69e1e4 | 5433 | stack_offset += align_up (partial_len, MIPS32_REGSIZE); |
46cac009 AC |
5434 | } |
5435 | } | |
5436 | if (mips_debug) | |
5437 | fprintf_unfiltered (gdb_stdlog, "\n"); | |
5438 | } | |
5439 | ||
f10683bb | 5440 | regcache_cooked_write_signed (regcache, MIPS_SP_REGNUM, sp); |
310e9b6a | 5441 | |
46cac009 AC |
5442 | /* Return adjusted stack pointer. */ |
5443 | return sp; | |
5444 | } | |
5445 | ||
6d82d43b | 5446 | static enum return_value_convention |
6a3a010b | 5447 | mips_o32_return_value (struct gdbarch *gdbarch, struct value *function, |
c055b101 | 5448 | struct type *type, struct regcache *regcache, |
47a35522 | 5449 | gdb_byte *readbuf, const gdb_byte *writebuf) |
6d82d43b | 5450 | { |
6a3a010b | 5451 | CORE_ADDR func_addr = function ? find_function_addr (function, NULL) : 0; |
4cc0665f | 5452 | int mips16 = mips_pc_is_mips16 (gdbarch, func_addr); |
72a155b4 | 5453 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
6a3a010b | 5454 | enum mips_fval_reg fval_reg; |
6d82d43b | 5455 | |
6a3a010b | 5456 | fval_reg = readbuf ? mips16 ? mips_fval_gpr : mips_fval_fpr : mips_fval_both; |
6d82d43b AC |
5457 | if (TYPE_CODE (type) == TYPE_CODE_STRUCT |
5458 | || TYPE_CODE (type) == TYPE_CODE_UNION | |
5459 | || TYPE_CODE (type) == TYPE_CODE_ARRAY) | |
5460 | return RETURN_VALUE_STRUCT_CONVENTION; | |
5461 | else if (TYPE_CODE (type) == TYPE_CODE_FLT | |
5462 | && TYPE_LENGTH (type) == 4 && tdep->mips_fpu_type != MIPS_FPU_NONE) | |
5463 | { | |
6a3a010b MR |
5464 | /* A single-precision floating-point value. If reading in or copying, |
5465 | then we get it from/put it to FP0 for standard MIPS code or GPR2 | |
5466 | for MIPS16 code. If writing out only, then we put it to both FP0 | |
5467 | and GPR2. We do not support reading in with no function known, if | |
5468 | this safety check ever triggers, then we'll have to try harder. */ | |
5469 | gdb_assert (function || !readbuf); | |
6d82d43b | 5470 | if (mips_debug) |
6a3a010b MR |
5471 | switch (fval_reg) |
5472 | { | |
5473 | case mips_fval_fpr: | |
5474 | fprintf_unfiltered (gdb_stderr, "Return float in $fp0\n"); | |
5475 | break; | |
5476 | case mips_fval_gpr: | |
5477 | fprintf_unfiltered (gdb_stderr, "Return float in $2\n"); | |
5478 | break; | |
5479 | case mips_fval_both: | |
5480 | fprintf_unfiltered (gdb_stderr, "Return float in $fp0 and $2\n"); | |
5481 | break; | |
5482 | } | |
5483 | if (fval_reg != mips_fval_gpr) | |
5484 | mips_xfer_register (gdbarch, regcache, | |
5485 | (gdbarch_num_regs (gdbarch) | |
5486 | + mips_regnum (gdbarch)->fp0), | |
5487 | TYPE_LENGTH (type), | |
5488 | gdbarch_byte_order (gdbarch), | |
5489 | readbuf, writebuf, 0); | |
5490 | if (fval_reg != mips_fval_fpr) | |
5491 | mips_xfer_register (gdbarch, regcache, | |
5492 | gdbarch_num_regs (gdbarch) + 2, | |
5493 | TYPE_LENGTH (type), | |
5494 | gdbarch_byte_order (gdbarch), | |
5495 | readbuf, writebuf, 0); | |
6d82d43b AC |
5496 | return RETURN_VALUE_REGISTER_CONVENTION; |
5497 | } | |
5498 | else if (TYPE_CODE (type) == TYPE_CODE_FLT | |
5499 | && TYPE_LENGTH (type) == 8 && tdep->mips_fpu_type != MIPS_FPU_NONE) | |
5500 | { | |
6a3a010b MR |
5501 | /* A double-precision floating-point value. If reading in or copying, |
5502 | then we get it from/put it to FP1 and FP0 for standard MIPS code or | |
5503 | GPR2 and GPR3 for MIPS16 code. If writing out only, then we put it | |
5504 | to both FP1/FP0 and GPR2/GPR3. We do not support reading in with | |
5505 | no function known, if this safety check ever triggers, then we'll | |
5506 | have to try harder. */ | |
5507 | gdb_assert (function || !readbuf); | |
6d82d43b | 5508 | if (mips_debug) |
6a3a010b MR |
5509 | switch (fval_reg) |
5510 | { | |
5511 | case mips_fval_fpr: | |
5512 | fprintf_unfiltered (gdb_stderr, "Return float in $fp1/$fp0\n"); | |
5513 | break; | |
5514 | case mips_fval_gpr: | |
5515 | fprintf_unfiltered (gdb_stderr, "Return float in $2/$3\n"); | |
5516 | break; | |
5517 | case mips_fval_both: | |
5518 | fprintf_unfiltered (gdb_stderr, | |
5519 | "Return float in $fp1/$fp0 and $2/$3\n"); | |
5520 | break; | |
5521 | } | |
5522 | if (fval_reg != mips_fval_gpr) | |
6d82d43b | 5523 | { |
6a3a010b MR |
5524 | /* The most significant part goes in FP1, and the least significant |
5525 | in FP0. */ | |
5526 | switch (gdbarch_byte_order (gdbarch)) | |
5527 | { | |
5528 | case BFD_ENDIAN_LITTLE: | |
5529 | mips_xfer_register (gdbarch, regcache, | |
5530 | (gdbarch_num_regs (gdbarch) | |
5531 | + mips_regnum (gdbarch)->fp0 + 0), | |
5532 | 4, gdbarch_byte_order (gdbarch), | |
5533 | readbuf, writebuf, 0); | |
5534 | mips_xfer_register (gdbarch, regcache, | |
5535 | (gdbarch_num_regs (gdbarch) | |
5536 | + mips_regnum (gdbarch)->fp0 + 1), | |
5537 | 4, gdbarch_byte_order (gdbarch), | |
5538 | readbuf, writebuf, 4); | |
5539 | break; | |
5540 | case BFD_ENDIAN_BIG: | |
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, 0); | |
5546 | mips_xfer_register (gdbarch, regcache, | |
5547 | (gdbarch_num_regs (gdbarch) | |
5548 | + mips_regnum (gdbarch)->fp0 + 0), | |
5549 | 4, gdbarch_byte_order (gdbarch), | |
5550 | readbuf, writebuf, 4); | |
5551 | break; | |
5552 | default: | |
5553 | internal_error (__FILE__, __LINE__, _("bad switch")); | |
5554 | } | |
5555 | } | |
5556 | if (fval_reg != mips_fval_fpr) | |
5557 | { | |
5558 | /* The two 32-bit parts are always placed in GPR2 and GPR3 | |
5559 | following these registers' memory order. */ | |
ba32f989 | 5560 | mips_xfer_register (gdbarch, regcache, |
6a3a010b | 5561 | gdbarch_num_regs (gdbarch) + 2, |
72a155b4 | 5562 | 4, gdbarch_byte_order (gdbarch), |
4c6b5505 | 5563 | readbuf, writebuf, 0); |
ba32f989 | 5564 | mips_xfer_register (gdbarch, regcache, |
6a3a010b | 5565 | gdbarch_num_regs (gdbarch) + 3, |
72a155b4 | 5566 | 4, gdbarch_byte_order (gdbarch), |
4c6b5505 | 5567 | readbuf, writebuf, 4); |
6d82d43b AC |
5568 | } |
5569 | return RETURN_VALUE_REGISTER_CONVENTION; | |
5570 | } | |
5571 | #if 0 | |
5572 | else if (TYPE_CODE (type) == TYPE_CODE_STRUCT | |
5573 | && TYPE_NFIELDS (type) <= 2 | |
5574 | && TYPE_NFIELDS (type) >= 1 | |
5575 | && ((TYPE_NFIELDS (type) == 1 | |
5576 | && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) | |
5577 | == TYPE_CODE_FLT)) | |
5578 | || (TYPE_NFIELDS (type) == 2 | |
5579 | && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) | |
5580 | == TYPE_CODE_FLT) | |
5581 | && (TYPE_CODE (TYPE_FIELD_TYPE (type, 1)) | |
5582 | == TYPE_CODE_FLT))) | |
5583 | && tdep->mips_fpu_type != MIPS_FPU_NONE) | |
5584 | { | |
5585 | /* A struct that contains one or two floats. Each value is part | |
5586 | in the least significant part of their floating point | |
5587 | register.. */ | |
870cd05e | 5588 | gdb_byte reg[MAX_REGISTER_SIZE]; |
6d82d43b AC |
5589 | int regnum; |
5590 | int field; | |
72a155b4 | 5591 | for (field = 0, regnum = mips_regnum (gdbarch)->fp0; |
6d82d43b AC |
5592 | field < TYPE_NFIELDS (type); field++, regnum += 2) |
5593 | { | |
5594 | int offset = (FIELD_BITPOS (TYPE_FIELDS (type)[field]) | |
5595 | / TARGET_CHAR_BIT); | |
5596 | if (mips_debug) | |
5597 | fprintf_unfiltered (gdb_stderr, "Return float struct+%d\n", | |
5598 | offset); | |
ba32f989 DJ |
5599 | mips_xfer_register (gdbarch, regcache, |
5600 | gdbarch_num_regs (gdbarch) + regnum, | |
6d82d43b | 5601 | TYPE_LENGTH (TYPE_FIELD_TYPE (type, field)), |
72a155b4 | 5602 | gdbarch_byte_order (gdbarch), |
4c6b5505 | 5603 | readbuf, writebuf, offset); |
6d82d43b AC |
5604 | } |
5605 | return RETURN_VALUE_REGISTER_CONVENTION; | |
5606 | } | |
5607 | #endif | |
5608 | #if 0 | |
5609 | else if (TYPE_CODE (type) == TYPE_CODE_STRUCT | |
5610 | || TYPE_CODE (type) == TYPE_CODE_UNION) | |
5611 | { | |
5612 | /* A structure or union. Extract the left justified value, | |
5613 | regardless of the byte order. I.e. DO NOT USE | |
5614 | mips_xfer_lower. */ | |
5615 | int offset; | |
5616 | int regnum; | |
4c7d22cb | 5617 | for (offset = 0, regnum = MIPS_V0_REGNUM; |
6d82d43b | 5618 | offset < TYPE_LENGTH (type); |
72a155b4 | 5619 | offset += register_size (gdbarch, regnum), regnum++) |
6d82d43b | 5620 | { |
72a155b4 | 5621 | int xfer = register_size (gdbarch, regnum); |
6d82d43b AC |
5622 | if (offset + xfer > TYPE_LENGTH (type)) |
5623 | xfer = TYPE_LENGTH (type) - offset; | |
5624 | if (mips_debug) | |
5625 | fprintf_unfiltered (gdb_stderr, "Return struct+%d:%d in $%d\n", | |
5626 | offset, xfer, regnum); | |
ba32f989 DJ |
5627 | mips_xfer_register (gdbarch, regcache, |
5628 | gdbarch_num_regs (gdbarch) + regnum, xfer, | |
6d82d43b AC |
5629 | BFD_ENDIAN_UNKNOWN, readbuf, writebuf, offset); |
5630 | } | |
5631 | return RETURN_VALUE_REGISTER_CONVENTION; | |
5632 | } | |
5633 | #endif | |
5634 | else | |
5635 | { | |
5636 | /* A scalar extract each part but least-significant-byte | |
5637 | justified. o32 thinks registers are 4 byte, regardless of | |
1a69e1e4 | 5638 | the ISA. */ |
6d82d43b AC |
5639 | int offset; |
5640 | int regnum; | |
4c7d22cb | 5641 | for (offset = 0, regnum = MIPS_V0_REGNUM; |
6d82d43b | 5642 | offset < TYPE_LENGTH (type); |
1a69e1e4 | 5643 | offset += MIPS32_REGSIZE, regnum++) |
6d82d43b | 5644 | { |
1a69e1e4 | 5645 | int xfer = MIPS32_REGSIZE; |
6d82d43b AC |
5646 | if (offset + xfer > TYPE_LENGTH (type)) |
5647 | xfer = TYPE_LENGTH (type) - offset; | |
5648 | if (mips_debug) | |
5649 | fprintf_unfiltered (gdb_stderr, "Return scalar+%d:%d in $%d\n", | |
5650 | offset, xfer, regnum); | |
ba32f989 DJ |
5651 | mips_xfer_register (gdbarch, regcache, |
5652 | gdbarch_num_regs (gdbarch) + regnum, xfer, | |
72a155b4 | 5653 | gdbarch_byte_order (gdbarch), |
4c6b5505 | 5654 | readbuf, writebuf, offset); |
6d82d43b AC |
5655 | } |
5656 | return RETURN_VALUE_REGISTER_CONVENTION; | |
5657 | } | |
5658 | } | |
5659 | ||
5660 | /* O64 ABI. This is a hacked up kind of 64-bit version of the o32 | |
5661 | ABI. */ | |
46cac009 AC |
5662 | |
5663 | static CORE_ADDR | |
7d9b040b | 5664 | mips_o64_push_dummy_call (struct gdbarch *gdbarch, struct value *function, |
6d82d43b AC |
5665 | struct regcache *regcache, CORE_ADDR bp_addr, |
5666 | int nargs, | |
5667 | struct value **args, CORE_ADDR sp, | |
5668 | int struct_return, CORE_ADDR struct_addr) | |
46cac009 AC |
5669 | { |
5670 | int argreg; | |
5671 | int float_argreg; | |
5672 | int argnum; | |
5673 | int len = 0; | |
5674 | int stack_offset = 0; | |
e17a4113 | 5675 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
7d9b040b | 5676 | CORE_ADDR func_addr = find_function_addr (function, NULL); |
46cac009 | 5677 | |
25ab4790 AC |
5678 | /* For shared libraries, "t9" needs to point at the function |
5679 | address. */ | |
4c7d22cb | 5680 | regcache_cooked_write_signed (regcache, MIPS_T9_REGNUM, func_addr); |
25ab4790 AC |
5681 | |
5682 | /* Set the return address register to point to the entry point of | |
5683 | the program, where a breakpoint lies in wait. */ | |
4c7d22cb | 5684 | regcache_cooked_write_signed (regcache, MIPS_RA_REGNUM, bp_addr); |
25ab4790 | 5685 | |
46cac009 AC |
5686 | /* First ensure that the stack and structure return address (if any) |
5687 | are properly aligned. The stack has to be at least 64-bit | |
5688 | aligned even on 32-bit machines, because doubles must be 64-bit | |
5689 | aligned. For n32 and n64, stack frames need to be 128-bit | |
5690 | aligned, so we round to this widest known alignment. */ | |
5691 | ||
5b03f266 AC |
5692 | sp = align_down (sp, 16); |
5693 | struct_addr = align_down (struct_addr, 16); | |
46cac009 AC |
5694 | |
5695 | /* Now make space on the stack for the args. */ | |
5696 | for (argnum = 0; argnum < nargs; argnum++) | |
968b5391 MR |
5697 | { |
5698 | struct type *arg_type = check_typedef (value_type (args[argnum])); | |
968b5391 | 5699 | |
968b5391 | 5700 | /* Allocate space on the stack. */ |
354ecfd5 | 5701 | len += align_up (TYPE_LENGTH (arg_type), MIPS64_REGSIZE); |
968b5391 | 5702 | } |
5b03f266 | 5703 | sp -= align_up (len, 16); |
46cac009 AC |
5704 | |
5705 | if (mips_debug) | |
6d82d43b | 5706 | fprintf_unfiltered (gdb_stdlog, |
5af949e3 UW |
5707 | "mips_o64_push_dummy_call: sp=%s allocated %ld\n", |
5708 | paddress (gdbarch, sp), (long) align_up (len, 16)); | |
46cac009 AC |
5709 | |
5710 | /* Initialize the integer and float register pointers. */ | |
4c7d22cb | 5711 | argreg = MIPS_A0_REGNUM; |
72a155b4 | 5712 | float_argreg = mips_fpa0_regnum (gdbarch); |
46cac009 AC |
5713 | |
5714 | /* The struct_return pointer occupies the first parameter-passing reg. */ | |
5715 | if (struct_return) | |
5716 | { | |
5717 | if (mips_debug) | |
5718 | fprintf_unfiltered (gdb_stdlog, | |
025bb325 MS |
5719 | "mips_o64_push_dummy_call: " |
5720 | "struct_return reg=%d %s\n", | |
5af949e3 | 5721 | argreg, paddress (gdbarch, struct_addr)); |
9c9acae0 | 5722 | regcache_cooked_write_unsigned (regcache, argreg++, struct_addr); |
1a69e1e4 | 5723 | stack_offset += MIPS64_REGSIZE; |
46cac009 AC |
5724 | } |
5725 | ||
5726 | /* Now load as many as possible of the first arguments into | |
5727 | registers, and push the rest onto the stack. Loop thru args | |
5728 | from first to last. */ | |
5729 | for (argnum = 0; argnum < nargs; argnum++) | |
5730 | { | |
47a35522 | 5731 | const gdb_byte *val; |
930bd0e0 | 5732 | gdb_byte valbuf[MAX_REGISTER_SIZE]; |
46cac009 | 5733 | struct value *arg = args[argnum]; |
4991999e | 5734 | struct type *arg_type = check_typedef (value_type (arg)); |
46cac009 AC |
5735 | int len = TYPE_LENGTH (arg_type); |
5736 | enum type_code typecode = TYPE_CODE (arg_type); | |
5737 | ||
5738 | if (mips_debug) | |
5739 | fprintf_unfiltered (gdb_stdlog, | |
25ab4790 | 5740 | "mips_o64_push_dummy_call: %d len=%d type=%d", |
ebafbe83 MS |
5741 | argnum + 1, len, (int) typecode); |
5742 | ||
47a35522 | 5743 | val = value_contents (arg); |
ebafbe83 | 5744 | |
930bd0e0 KB |
5745 | /* Function pointer arguments to mips16 code need to be made into |
5746 | mips16 pointers. */ | |
5747 | if (typecode == TYPE_CODE_PTR | |
5748 | && TYPE_CODE (TYPE_TARGET_TYPE (arg_type)) == TYPE_CODE_FUNC) | |
5749 | { | |
5750 | CORE_ADDR addr = extract_signed_integer (value_contents (arg), | |
5751 | len, byte_order); | |
4cc0665f | 5752 | if (!mips_pc_is_mips (addr)) |
930bd0e0 KB |
5753 | { |
5754 | store_signed_integer (valbuf, len, byte_order, | |
4cc0665f | 5755 | make_compact_addr (addr)); |
930bd0e0 KB |
5756 | val = valbuf; |
5757 | } | |
5758 | } | |
5759 | ||
ebafbe83 | 5760 | /* Floating point arguments passed in registers have to be |
6a3a010b MR |
5761 | treated specially. On 32-bit architectures, doubles are |
5762 | passed in register pairs; the even FP register gets the | |
5763 | low word, and the odd FP register gets the high word. | |
5764 | On O64, the first two floating point arguments are also | |
5765 | copied to general registers, because MIPS16 functions | |
5766 | don't use float registers for arguments. This duplication | |
5767 | of arguments in general registers can't hurt non-MIPS16 | |
5768 | functions because those registers are normally skipped. */ | |
ebafbe83 | 5769 | |
74ed0bb4 MD |
5770 | if (fp_register_arg_p (gdbarch, typecode, arg_type) |
5771 | && float_argreg <= MIPS_LAST_FP_ARG_REGNUM (gdbarch)) | |
ebafbe83 | 5772 | { |
e17a4113 | 5773 | LONGEST regval = extract_unsigned_integer (val, len, byte_order); |
2afd3f0a MR |
5774 | if (mips_debug) |
5775 | fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s", | |
5776 | float_argreg, phex (regval, len)); | |
9c9acae0 | 5777 | regcache_cooked_write_unsigned (regcache, float_argreg++, regval); |
2afd3f0a MR |
5778 | if (mips_debug) |
5779 | fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s", | |
5780 | argreg, phex (regval, len)); | |
9c9acae0 | 5781 | regcache_cooked_write_unsigned (regcache, argreg, regval); |
2afd3f0a | 5782 | argreg++; |
ebafbe83 | 5783 | /* Reserve space for the FP register. */ |
1a69e1e4 | 5784 | stack_offset += align_up (len, MIPS64_REGSIZE); |
ebafbe83 MS |
5785 | } |
5786 | else | |
5787 | { | |
5788 | /* Copy the argument to general registers or the stack in | |
5789 | register-sized pieces. Large arguments are split between | |
5790 | registers and stack. */ | |
1a69e1e4 | 5791 | /* Note: structs whose size is not a multiple of MIPS64_REGSIZE |
436aafc4 MR |
5792 | are treated specially: Irix cc passes them in registers |
5793 | where gcc sometimes puts them on the stack. For maximum | |
5794 | compatibility, we will put them in both places. */ | |
1a69e1e4 DJ |
5795 | int odd_sized_struct = (len > MIPS64_REGSIZE |
5796 | && len % MIPS64_REGSIZE != 0); | |
ebafbe83 MS |
5797 | while (len > 0) |
5798 | { | |
5799 | /* Remember if the argument was written to the stack. */ | |
5800 | int stack_used_p = 0; | |
1a69e1e4 | 5801 | int partial_len = (len < MIPS64_REGSIZE ? len : MIPS64_REGSIZE); |
ebafbe83 MS |
5802 | |
5803 | if (mips_debug) | |
5804 | fprintf_unfiltered (gdb_stdlog, " -- partial=%d", | |
5805 | partial_len); | |
5806 | ||
5807 | /* Write this portion of the argument to the stack. */ | |
74ed0bb4 | 5808 | if (argreg > MIPS_LAST_ARG_REGNUM (gdbarch) |
968b5391 | 5809 | || odd_sized_struct) |
ebafbe83 MS |
5810 | { |
5811 | /* Should shorter than int integer values be | |
025bb325 | 5812 | promoted to int before being stored? */ |
ebafbe83 MS |
5813 | int longword_offset = 0; |
5814 | CORE_ADDR addr; | |
5815 | stack_used_p = 1; | |
72a155b4 | 5816 | if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) |
ebafbe83 | 5817 | { |
1a69e1e4 DJ |
5818 | if ((typecode == TYPE_CODE_INT |
5819 | || typecode == TYPE_CODE_PTR | |
5820 | || typecode == TYPE_CODE_FLT) | |
5821 | && len <= 4) | |
5822 | longword_offset = MIPS64_REGSIZE - len; | |
ebafbe83 MS |
5823 | } |
5824 | ||
5825 | if (mips_debug) | |
5826 | { | |
5af949e3 UW |
5827 | fprintf_unfiltered (gdb_stdlog, " - stack_offset=%s", |
5828 | paddress (gdbarch, stack_offset)); | |
5829 | fprintf_unfiltered (gdb_stdlog, " longword_offset=%s", | |
5830 | paddress (gdbarch, longword_offset)); | |
ebafbe83 MS |
5831 | } |
5832 | ||
5833 | addr = sp + stack_offset + longword_offset; | |
5834 | ||
5835 | if (mips_debug) | |
5836 | { | |
5837 | int i; | |
5af949e3 UW |
5838 | fprintf_unfiltered (gdb_stdlog, " @%s ", |
5839 | paddress (gdbarch, addr)); | |
ebafbe83 MS |
5840 | for (i = 0; i < partial_len; i++) |
5841 | { | |
6d82d43b | 5842 | fprintf_unfiltered (gdb_stdlog, "%02x", |
ebafbe83 MS |
5843 | val[i] & 0xff); |
5844 | } | |
5845 | } | |
5846 | write_memory (addr, val, partial_len); | |
5847 | } | |
5848 | ||
5849 | /* Note!!! This is NOT an else clause. Odd sized | |
968b5391 | 5850 | structs may go thru BOTH paths. */ |
ebafbe83 | 5851 | /* Write this portion of the argument to a general |
6d82d43b | 5852 | purpose register. */ |
74ed0bb4 | 5853 | if (argreg <= MIPS_LAST_ARG_REGNUM (gdbarch)) |
ebafbe83 | 5854 | { |
e17a4113 UW |
5855 | LONGEST regval = extract_signed_integer (val, partial_len, |
5856 | byte_order); | |
4246e332 | 5857 | /* Value may need to be sign extended, because |
1b13c4f6 | 5858 | mips_isa_regsize() != mips_abi_regsize(). */ |
ebafbe83 MS |
5859 | |
5860 | /* A non-floating-point argument being passed in a | |
5861 | general register. If a struct or union, and if | |
5862 | the remaining length is smaller than the register | |
5863 | size, we have to adjust the register value on | |
5864 | big endian targets. | |
5865 | ||
5866 | It does not seem to be necessary to do the | |
025bb325 | 5867 | same for integral types. */ |
480d3dd2 | 5868 | |
72a155b4 | 5869 | if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG |
1a69e1e4 | 5870 | && partial_len < MIPS64_REGSIZE |
06f9a1af MR |
5871 | && (typecode == TYPE_CODE_STRUCT |
5872 | || typecode == TYPE_CODE_UNION)) | |
1a69e1e4 | 5873 | regval <<= ((MIPS64_REGSIZE - partial_len) |
9ecf7166 | 5874 | * TARGET_CHAR_BIT); |
ebafbe83 MS |
5875 | |
5876 | if (mips_debug) | |
5877 | fprintf_filtered (gdb_stdlog, " - reg=%d val=%s", | |
5878 | argreg, | |
1a69e1e4 | 5879 | phex (regval, MIPS64_REGSIZE)); |
9c9acae0 | 5880 | regcache_cooked_write_unsigned (regcache, argreg, regval); |
ebafbe83 MS |
5881 | argreg++; |
5882 | ||
5883 | /* Prevent subsequent floating point arguments from | |
5884 | being passed in floating point registers. */ | |
74ed0bb4 | 5885 | float_argreg = MIPS_LAST_FP_ARG_REGNUM (gdbarch) + 1; |
ebafbe83 MS |
5886 | } |
5887 | ||
5888 | len -= partial_len; | |
5889 | val += partial_len; | |
5890 | ||
b021a221 MS |
5891 | /* Compute the offset into the stack at which we will |
5892 | copy the next parameter. | |
ebafbe83 | 5893 | |
6d82d43b AC |
5894 | In older ABIs, the caller reserved space for |
5895 | registers that contained arguments. This was loosely | |
5896 | refered to as their "home". Consequently, space is | |
5897 | always allocated. */ | |
ebafbe83 | 5898 | |
1a69e1e4 | 5899 | stack_offset += align_up (partial_len, MIPS64_REGSIZE); |
ebafbe83 MS |
5900 | } |
5901 | } | |
5902 | if (mips_debug) | |
5903 | fprintf_unfiltered (gdb_stdlog, "\n"); | |
5904 | } | |
5905 | ||
f10683bb | 5906 | regcache_cooked_write_signed (regcache, MIPS_SP_REGNUM, sp); |
310e9b6a | 5907 | |
ebafbe83 MS |
5908 | /* Return adjusted stack pointer. */ |
5909 | return sp; | |
5910 | } | |
5911 | ||
9c8fdbfa | 5912 | static enum return_value_convention |
6a3a010b | 5913 | mips_o64_return_value (struct gdbarch *gdbarch, struct value *function, |
9c8fdbfa | 5914 | struct type *type, struct regcache *regcache, |
47a35522 | 5915 | gdb_byte *readbuf, const gdb_byte *writebuf) |
6d82d43b | 5916 | { |
6a3a010b | 5917 | CORE_ADDR func_addr = function ? find_function_addr (function, NULL) : 0; |
4cc0665f | 5918 | int mips16 = mips_pc_is_mips16 (gdbarch, func_addr); |
72a155b4 | 5919 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
6a3a010b | 5920 | enum mips_fval_reg fval_reg; |
7a076fd2 | 5921 | |
6a3a010b | 5922 | fval_reg = readbuf ? mips16 ? mips_fval_gpr : mips_fval_fpr : mips_fval_both; |
7a076fd2 FF |
5923 | if (TYPE_CODE (type) == TYPE_CODE_STRUCT |
5924 | || TYPE_CODE (type) == TYPE_CODE_UNION | |
5925 | || TYPE_CODE (type) == TYPE_CODE_ARRAY) | |
5926 | return RETURN_VALUE_STRUCT_CONVENTION; | |
74ed0bb4 | 5927 | else if (fp_register_arg_p (gdbarch, TYPE_CODE (type), type)) |
7a076fd2 | 5928 | { |
6a3a010b MR |
5929 | /* A floating-point value. If reading in or copying, then we get it |
5930 | from/put it to FP0 for standard MIPS code or GPR2 for MIPS16 code. | |
5931 | If writing out only, then we put it to both FP0 and GPR2. We do | |
5932 | not support reading in with no function known, if this safety | |
5933 | check ever triggers, then we'll have to try harder. */ | |
5934 | gdb_assert (function || !readbuf); | |
7a076fd2 | 5935 | if (mips_debug) |
6a3a010b MR |
5936 | switch (fval_reg) |
5937 | { | |
5938 | case mips_fval_fpr: | |
5939 | fprintf_unfiltered (gdb_stderr, "Return float in $fp0\n"); | |
5940 | break; | |
5941 | case mips_fval_gpr: | |
5942 | fprintf_unfiltered (gdb_stderr, "Return float in $2\n"); | |
5943 | break; | |
5944 | case mips_fval_both: | |
5945 | fprintf_unfiltered (gdb_stderr, "Return float in $fp0 and $2\n"); | |
5946 | break; | |
5947 | } | |
5948 | if (fval_reg != mips_fval_gpr) | |
5949 | mips_xfer_register (gdbarch, regcache, | |
5950 | (gdbarch_num_regs (gdbarch) | |
5951 | + mips_regnum (gdbarch)->fp0), | |
5952 | TYPE_LENGTH (type), | |
5953 | gdbarch_byte_order (gdbarch), | |
5954 | readbuf, writebuf, 0); | |
5955 | if (fval_reg != mips_fval_fpr) | |
5956 | mips_xfer_register (gdbarch, regcache, | |
5957 | gdbarch_num_regs (gdbarch) + 2, | |
5958 | TYPE_LENGTH (type), | |
5959 | gdbarch_byte_order (gdbarch), | |
5960 | readbuf, writebuf, 0); | |
7a076fd2 FF |
5961 | return RETURN_VALUE_REGISTER_CONVENTION; |
5962 | } | |
5963 | else | |
5964 | { | |
5965 | /* A scalar extract each part but least-significant-byte | |
025bb325 | 5966 | justified. */ |
7a076fd2 FF |
5967 | int offset; |
5968 | int regnum; | |
5969 | for (offset = 0, regnum = MIPS_V0_REGNUM; | |
5970 | offset < TYPE_LENGTH (type); | |
1a69e1e4 | 5971 | offset += MIPS64_REGSIZE, regnum++) |
7a076fd2 | 5972 | { |
1a69e1e4 | 5973 | int xfer = MIPS64_REGSIZE; |
7a076fd2 FF |
5974 | if (offset + xfer > TYPE_LENGTH (type)) |
5975 | xfer = TYPE_LENGTH (type) - offset; | |
5976 | if (mips_debug) | |
5977 | fprintf_unfiltered (gdb_stderr, "Return scalar+%d:%d in $%d\n", | |
5978 | offset, xfer, regnum); | |
ba32f989 DJ |
5979 | mips_xfer_register (gdbarch, regcache, |
5980 | gdbarch_num_regs (gdbarch) + regnum, | |
72a155b4 | 5981 | xfer, gdbarch_byte_order (gdbarch), |
4c6b5505 | 5982 | readbuf, writebuf, offset); |
7a076fd2 FF |
5983 | } |
5984 | return RETURN_VALUE_REGISTER_CONVENTION; | |
5985 | } | |
6d82d43b AC |
5986 | } |
5987 | ||
dd824b04 DJ |
5988 | /* Floating point register management. |
5989 | ||
5990 | Background: MIPS1 & 2 fp registers are 32 bits wide. To support | |
5991 | 64bit operations, these early MIPS cpus treat fp register pairs | |
5992 | (f0,f1) as a single register (d0). Later MIPS cpu's have 64 bit fp | |
5993 | registers and offer a compatibility mode that emulates the MIPS2 fp | |
5994 | model. When operating in MIPS2 fp compat mode, later cpu's split | |
5995 | double precision floats into two 32-bit chunks and store them in | |
5996 | consecutive fp regs. To display 64-bit floats stored in this | |
5997 | fashion, we have to combine 32 bits from f0 and 32 bits from f1. | |
5998 | Throw in user-configurable endianness and you have a real mess. | |
5999 | ||
6000 | The way this works is: | |
6001 | - If we are in 32-bit mode or on a 32-bit processor, then a 64-bit | |
6002 | double-precision value will be split across two logical registers. | |
6003 | The lower-numbered logical register will hold the low-order bits, | |
6004 | regardless of the processor's endianness. | |
6005 | - If we are on a 64-bit processor, and we are looking for a | |
6006 | single-precision value, it will be in the low ordered bits | |
6007 | of a 64-bit GPR (after mfc1, for example) or a 64-bit register | |
6008 | save slot in memory. | |
6009 | - If we are in 64-bit mode, everything is straightforward. | |
6010 | ||
6011 | Note that this code only deals with "live" registers at the top of the | |
6012 | stack. We will attempt to deal with saved registers later, when | |
025bb325 | 6013 | the raw/cooked register interface is in place. (We need a general |
dd824b04 DJ |
6014 | interface that can deal with dynamic saved register sizes -- fp |
6015 | regs could be 32 bits wide in one frame and 64 on the frame above | |
6016 | and below). */ | |
6017 | ||
6018 | /* Copy a 32-bit single-precision value from the current frame | |
6019 | into rare_buffer. */ | |
6020 | ||
6021 | static void | |
e11c53d2 | 6022 | mips_read_fp_register_single (struct frame_info *frame, int regno, |
47a35522 | 6023 | gdb_byte *rare_buffer) |
dd824b04 | 6024 | { |
72a155b4 UW |
6025 | struct gdbarch *gdbarch = get_frame_arch (frame); |
6026 | int raw_size = register_size (gdbarch, regno); | |
47a35522 | 6027 | gdb_byte *raw_buffer = alloca (raw_size); |
dd824b04 | 6028 | |
ca9d61b9 | 6029 | if (!deprecated_frame_register_read (frame, regno, raw_buffer)) |
c9f4d572 | 6030 | error (_("can't read register %d (%s)"), |
72a155b4 | 6031 | regno, gdbarch_register_name (gdbarch, regno)); |
dd824b04 DJ |
6032 | if (raw_size == 8) |
6033 | { | |
6034 | /* We have a 64-bit value for this register. Find the low-order | |
6d82d43b | 6035 | 32 bits. */ |
dd824b04 DJ |
6036 | int offset; |
6037 | ||
72a155b4 | 6038 | if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) |
dd824b04 DJ |
6039 | offset = 4; |
6040 | else | |
6041 | offset = 0; | |
6042 | ||
6043 | memcpy (rare_buffer, raw_buffer + offset, 4); | |
6044 | } | |
6045 | else | |
6046 | { | |
6047 | memcpy (rare_buffer, raw_buffer, 4); | |
6048 | } | |
6049 | } | |
6050 | ||
6051 | /* Copy a 64-bit double-precision value from the current frame into | |
6052 | rare_buffer. This may include getting half of it from the next | |
6053 | register. */ | |
6054 | ||
6055 | static void | |
e11c53d2 | 6056 | mips_read_fp_register_double (struct frame_info *frame, int regno, |
47a35522 | 6057 | gdb_byte *rare_buffer) |
dd824b04 | 6058 | { |
72a155b4 UW |
6059 | struct gdbarch *gdbarch = get_frame_arch (frame); |
6060 | int raw_size = register_size (gdbarch, regno); | |
dd824b04 | 6061 | |
9c9acae0 | 6062 | if (raw_size == 8 && !mips2_fp_compat (frame)) |
dd824b04 DJ |
6063 | { |
6064 | /* We have a 64-bit value for this register, and we should use | |
6d82d43b | 6065 | all 64 bits. */ |
ca9d61b9 | 6066 | if (!deprecated_frame_register_read (frame, regno, rare_buffer)) |
c9f4d572 | 6067 | error (_("can't read register %d (%s)"), |
72a155b4 | 6068 | regno, gdbarch_register_name (gdbarch, regno)); |
dd824b04 DJ |
6069 | } |
6070 | else | |
6071 | { | |
72a155b4 | 6072 | int rawnum = regno % gdbarch_num_regs (gdbarch); |
82e91389 | 6073 | |
72a155b4 | 6074 | if ((rawnum - mips_regnum (gdbarch)->fp0) & 1) |
dd824b04 | 6075 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 AC |
6076 | _("mips_read_fp_register_double: bad access to " |
6077 | "odd-numbered FP register")); | |
dd824b04 DJ |
6078 | |
6079 | /* mips_read_fp_register_single will find the correct 32 bits from | |
6d82d43b | 6080 | each register. */ |
72a155b4 | 6081 | if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) |
dd824b04 | 6082 | { |
e11c53d2 AC |
6083 | mips_read_fp_register_single (frame, regno, rare_buffer + 4); |
6084 | mips_read_fp_register_single (frame, regno + 1, rare_buffer); | |
dd824b04 | 6085 | } |
361d1df0 | 6086 | else |
dd824b04 | 6087 | { |
e11c53d2 AC |
6088 | mips_read_fp_register_single (frame, regno, rare_buffer); |
6089 | mips_read_fp_register_single (frame, regno + 1, rare_buffer + 4); | |
dd824b04 DJ |
6090 | } |
6091 | } | |
6092 | } | |
6093 | ||
c906108c | 6094 | static void |
e11c53d2 AC |
6095 | mips_print_fp_register (struct ui_file *file, struct frame_info *frame, |
6096 | int regnum) | |
025bb325 | 6097 | { /* Do values for FP (float) regs. */ |
72a155b4 | 6098 | struct gdbarch *gdbarch = get_frame_arch (frame); |
47a35522 | 6099 | gdb_byte *raw_buffer; |
025bb325 | 6100 | double doub, flt1; /* Doubles extracted from raw hex data. */ |
3903d437 | 6101 | int inv1, inv2; |
c5aa993b | 6102 | |
025bb325 MS |
6103 | raw_buffer = alloca (2 * register_size (gdbarch, |
6104 | mips_regnum (gdbarch)->fp0)); | |
c906108c | 6105 | |
72a155b4 | 6106 | fprintf_filtered (file, "%s:", gdbarch_register_name (gdbarch, regnum)); |
c9f4d572 | 6107 | fprintf_filtered (file, "%*s", |
72a155b4 | 6108 | 4 - (int) strlen (gdbarch_register_name (gdbarch, regnum)), |
e11c53d2 | 6109 | ""); |
f0ef6b29 | 6110 | |
72a155b4 | 6111 | if (register_size (gdbarch, regnum) == 4 || mips2_fp_compat (frame)) |
c906108c | 6112 | { |
79a45b7d TT |
6113 | struct value_print_options opts; |
6114 | ||
f0ef6b29 KB |
6115 | /* 4-byte registers: Print hex and floating. Also print even |
6116 | numbered registers as doubles. */ | |
e11c53d2 | 6117 | mips_read_fp_register_single (frame, regnum, raw_buffer); |
025bb325 MS |
6118 | flt1 = unpack_double (builtin_type (gdbarch)->builtin_float, |
6119 | raw_buffer, &inv1); | |
c5aa993b | 6120 | |
79a45b7d | 6121 | get_formatted_print_options (&opts, 'x'); |
df4df182 UW |
6122 | print_scalar_formatted (raw_buffer, |
6123 | builtin_type (gdbarch)->builtin_uint32, | |
6124 | &opts, 'w', file); | |
dd824b04 | 6125 | |
e11c53d2 | 6126 | fprintf_filtered (file, " flt: "); |
1adad886 | 6127 | if (inv1) |
e11c53d2 | 6128 | fprintf_filtered (file, " <invalid float> "); |
1adad886 | 6129 | else |
e11c53d2 | 6130 | fprintf_filtered (file, "%-17.9g", flt1); |
1adad886 | 6131 | |
72a155b4 | 6132 | if ((regnum - gdbarch_num_regs (gdbarch)) % 2 == 0) |
f0ef6b29 | 6133 | { |
e11c53d2 | 6134 | mips_read_fp_register_double (frame, regnum, raw_buffer); |
27067745 UW |
6135 | doub = unpack_double (builtin_type (gdbarch)->builtin_double, |
6136 | raw_buffer, &inv2); | |
1adad886 | 6137 | |
e11c53d2 | 6138 | fprintf_filtered (file, " dbl: "); |
f0ef6b29 | 6139 | if (inv2) |
e11c53d2 | 6140 | fprintf_filtered (file, "<invalid double>"); |
f0ef6b29 | 6141 | else |
e11c53d2 | 6142 | fprintf_filtered (file, "%-24.17g", doub); |
f0ef6b29 | 6143 | } |
c906108c SS |
6144 | } |
6145 | else | |
dd824b04 | 6146 | { |
79a45b7d TT |
6147 | struct value_print_options opts; |
6148 | ||
f0ef6b29 | 6149 | /* Eight byte registers: print each one as hex, float and double. */ |
e11c53d2 | 6150 | mips_read_fp_register_single (frame, regnum, raw_buffer); |
27067745 UW |
6151 | flt1 = unpack_double (builtin_type (gdbarch)->builtin_float, |
6152 | raw_buffer, &inv1); | |
c906108c | 6153 | |
e11c53d2 | 6154 | mips_read_fp_register_double (frame, regnum, raw_buffer); |
27067745 UW |
6155 | doub = unpack_double (builtin_type (gdbarch)->builtin_double, |
6156 | raw_buffer, &inv2); | |
f0ef6b29 | 6157 | |
79a45b7d | 6158 | get_formatted_print_options (&opts, 'x'); |
df4df182 UW |
6159 | print_scalar_formatted (raw_buffer, |
6160 | builtin_type (gdbarch)->builtin_uint64, | |
6161 | &opts, 'g', file); | |
f0ef6b29 | 6162 | |
e11c53d2 | 6163 | fprintf_filtered (file, " flt: "); |
1adad886 | 6164 | if (inv1) |
e11c53d2 | 6165 | fprintf_filtered (file, "<invalid float>"); |
1adad886 | 6166 | else |
e11c53d2 | 6167 | fprintf_filtered (file, "%-17.9g", flt1); |
1adad886 | 6168 | |
e11c53d2 | 6169 | fprintf_filtered (file, " dbl: "); |
f0ef6b29 | 6170 | if (inv2) |
e11c53d2 | 6171 | fprintf_filtered (file, "<invalid double>"); |
1adad886 | 6172 | else |
e11c53d2 | 6173 | fprintf_filtered (file, "%-24.17g", doub); |
f0ef6b29 KB |
6174 | } |
6175 | } | |
6176 | ||
6177 | static void | |
e11c53d2 | 6178 | mips_print_register (struct ui_file *file, struct frame_info *frame, |
0cc93a06 | 6179 | int regnum) |
f0ef6b29 | 6180 | { |
a4b8ebc8 | 6181 | struct gdbarch *gdbarch = get_frame_arch (frame); |
79a45b7d | 6182 | struct value_print_options opts; |
de15c4ab | 6183 | struct value *val; |
1adad886 | 6184 | |
004159a2 | 6185 | if (mips_float_register_p (gdbarch, regnum)) |
f0ef6b29 | 6186 | { |
e11c53d2 | 6187 | mips_print_fp_register (file, frame, regnum); |
f0ef6b29 KB |
6188 | return; |
6189 | } | |
6190 | ||
de15c4ab PA |
6191 | val = get_frame_register_value (frame, regnum); |
6192 | if (value_optimized_out (val)) | |
f0ef6b29 | 6193 | { |
c9f4d572 | 6194 | fprintf_filtered (file, "%s: [Invalid]", |
72a155b4 | 6195 | gdbarch_register_name (gdbarch, regnum)); |
f0ef6b29 | 6196 | return; |
c906108c | 6197 | } |
f0ef6b29 | 6198 | |
72a155b4 | 6199 | fputs_filtered (gdbarch_register_name (gdbarch, regnum), file); |
f0ef6b29 KB |
6200 | |
6201 | /* The problem with printing numeric register names (r26, etc.) is that | |
6202 | the user can't use them on input. Probably the best solution is to | |
6203 | fix it so that either the numeric or the funky (a2, etc.) names | |
6204 | are accepted on input. */ | |
6205 | if (regnum < MIPS_NUMREGS) | |
e11c53d2 | 6206 | fprintf_filtered (file, "(r%d): ", regnum); |
f0ef6b29 | 6207 | else |
e11c53d2 | 6208 | fprintf_filtered (file, ": "); |
f0ef6b29 | 6209 | |
79a45b7d | 6210 | get_formatted_print_options (&opts, 'x'); |
de15c4ab PA |
6211 | val_print_scalar_formatted (value_type (val), |
6212 | value_contents_for_printing (val), | |
6213 | value_embedded_offset (val), | |
6214 | val, | |
6215 | &opts, 0, file); | |
c906108c SS |
6216 | } |
6217 | ||
f0ef6b29 KB |
6218 | /* Replacement for generic do_registers_info. |
6219 | Print regs in pretty columns. */ | |
6220 | ||
6221 | static int | |
e11c53d2 AC |
6222 | print_fp_register_row (struct ui_file *file, struct frame_info *frame, |
6223 | int regnum) | |
f0ef6b29 | 6224 | { |
e11c53d2 AC |
6225 | fprintf_filtered (file, " "); |
6226 | mips_print_fp_register (file, frame, regnum); | |
6227 | fprintf_filtered (file, "\n"); | |
f0ef6b29 KB |
6228 | return regnum + 1; |
6229 | } | |
6230 | ||
6231 | ||
025bb325 | 6232 | /* Print a row's worth of GP (int) registers, with name labels above. */ |
c906108c SS |
6233 | |
6234 | static int | |
e11c53d2 | 6235 | print_gp_register_row (struct ui_file *file, struct frame_info *frame, |
a4b8ebc8 | 6236 | int start_regnum) |
c906108c | 6237 | { |
a4b8ebc8 | 6238 | struct gdbarch *gdbarch = get_frame_arch (frame); |
025bb325 | 6239 | /* Do values for GP (int) regs. */ |
47a35522 | 6240 | gdb_byte raw_buffer[MAX_REGISTER_SIZE]; |
025bb325 MS |
6241 | int ncols = (mips_abi_regsize (gdbarch) == 8 ? 4 : 8); /* display cols |
6242 | per row. */ | |
c906108c | 6243 | int col, byte; |
a4b8ebc8 | 6244 | int regnum; |
c906108c | 6245 | |
025bb325 | 6246 | /* For GP registers, we print a separate row of names above the vals. */ |
a4b8ebc8 | 6247 | for (col = 0, regnum = start_regnum; |
72a155b4 UW |
6248 | col < ncols && regnum < gdbarch_num_regs (gdbarch) |
6249 | + gdbarch_num_pseudo_regs (gdbarch); | |
f57d151a | 6250 | regnum++) |
c906108c | 6251 | { |
72a155b4 | 6252 | if (*gdbarch_register_name (gdbarch, regnum) == '\0') |
c5aa993b | 6253 | continue; /* unused register */ |
004159a2 | 6254 | if (mips_float_register_p (gdbarch, regnum)) |
025bb325 | 6255 | break; /* End the row: reached FP register. */ |
0cc93a06 | 6256 | /* Large registers are handled separately. */ |
72a155b4 | 6257 | if (register_size (gdbarch, regnum) > mips_abi_regsize (gdbarch)) |
0cc93a06 DJ |
6258 | { |
6259 | if (col > 0) | |
6260 | break; /* End the row before this register. */ | |
6261 | ||
6262 | /* Print this register on a row by itself. */ | |
6263 | mips_print_register (file, frame, regnum); | |
6264 | fprintf_filtered (file, "\n"); | |
6265 | return regnum + 1; | |
6266 | } | |
d05f6826 DJ |
6267 | if (col == 0) |
6268 | fprintf_filtered (file, " "); | |
6d82d43b | 6269 | fprintf_filtered (file, |
72a155b4 UW |
6270 | mips_abi_regsize (gdbarch) == 8 ? "%17s" : "%9s", |
6271 | gdbarch_register_name (gdbarch, regnum)); | |
c906108c SS |
6272 | col++; |
6273 | } | |
d05f6826 DJ |
6274 | |
6275 | if (col == 0) | |
6276 | return regnum; | |
6277 | ||
025bb325 | 6278 | /* Print the R0 to R31 names. */ |
72a155b4 | 6279 | if ((start_regnum % gdbarch_num_regs (gdbarch)) < MIPS_NUMREGS) |
f57d151a | 6280 | fprintf_filtered (file, "\n R%-4d", |
72a155b4 | 6281 | start_regnum % gdbarch_num_regs (gdbarch)); |
20e6603c AC |
6282 | else |
6283 | fprintf_filtered (file, "\n "); | |
c906108c | 6284 | |
025bb325 | 6285 | /* Now print the values in hex, 4 or 8 to the row. */ |
a4b8ebc8 | 6286 | for (col = 0, regnum = start_regnum; |
72a155b4 UW |
6287 | col < ncols && regnum < gdbarch_num_regs (gdbarch) |
6288 | + gdbarch_num_pseudo_regs (gdbarch); | |
f57d151a | 6289 | regnum++) |
c906108c | 6290 | { |
72a155b4 | 6291 | if (*gdbarch_register_name (gdbarch, regnum) == '\0') |
c5aa993b | 6292 | continue; /* unused register */ |
004159a2 | 6293 | if (mips_float_register_p (gdbarch, regnum)) |
025bb325 | 6294 | break; /* End row: reached FP register. */ |
72a155b4 | 6295 | if (register_size (gdbarch, regnum) > mips_abi_regsize (gdbarch)) |
0cc93a06 DJ |
6296 | break; /* End row: large register. */ |
6297 | ||
c906108c | 6298 | /* OK: get the data in raw format. */ |
ca9d61b9 | 6299 | if (!deprecated_frame_register_read (frame, regnum, raw_buffer)) |
c9f4d572 | 6300 | error (_("can't read register %d (%s)"), |
72a155b4 | 6301 | regnum, gdbarch_register_name (gdbarch, regnum)); |
c906108c | 6302 | /* pad small registers */ |
4246e332 | 6303 | for (byte = 0; |
72a155b4 UW |
6304 | byte < (mips_abi_regsize (gdbarch) |
6305 | - register_size (gdbarch, regnum)); byte++) | |
c906108c | 6306 | printf_filtered (" "); |
025bb325 | 6307 | /* Now print the register value in hex, endian order. */ |
72a155b4 | 6308 | if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) |
6d82d43b | 6309 | for (byte = |
72a155b4 UW |
6310 | register_size (gdbarch, regnum) - register_size (gdbarch, regnum); |
6311 | byte < register_size (gdbarch, regnum); byte++) | |
47a35522 | 6312 | fprintf_filtered (file, "%02x", raw_buffer[byte]); |
c906108c | 6313 | else |
72a155b4 | 6314 | for (byte = register_size (gdbarch, regnum) - 1; |
6d82d43b | 6315 | byte >= 0; byte--) |
47a35522 | 6316 | fprintf_filtered (file, "%02x", raw_buffer[byte]); |
e11c53d2 | 6317 | fprintf_filtered (file, " "); |
c906108c SS |
6318 | col++; |
6319 | } | |
025bb325 | 6320 | if (col > 0) /* ie. if we actually printed anything... */ |
e11c53d2 | 6321 | fprintf_filtered (file, "\n"); |
c906108c SS |
6322 | |
6323 | return regnum; | |
6324 | } | |
6325 | ||
025bb325 | 6326 | /* MIPS_DO_REGISTERS_INFO(): called by "info register" command. */ |
c906108c | 6327 | |
bf1f5b4c | 6328 | static void |
e11c53d2 AC |
6329 | mips_print_registers_info (struct gdbarch *gdbarch, struct ui_file *file, |
6330 | struct frame_info *frame, int regnum, int all) | |
c906108c | 6331 | { |
025bb325 | 6332 | if (regnum != -1) /* Do one specified register. */ |
c906108c | 6333 | { |
72a155b4 UW |
6334 | gdb_assert (regnum >= gdbarch_num_regs (gdbarch)); |
6335 | if (*(gdbarch_register_name (gdbarch, regnum)) == '\0') | |
8a3fe4f8 | 6336 | error (_("Not a valid register for the current processor type")); |
c906108c | 6337 | |
0cc93a06 | 6338 | mips_print_register (file, frame, regnum); |
e11c53d2 | 6339 | fprintf_filtered (file, "\n"); |
c906108c | 6340 | } |
c5aa993b | 6341 | else |
025bb325 | 6342 | /* Do all (or most) registers. */ |
c906108c | 6343 | { |
72a155b4 UW |
6344 | regnum = gdbarch_num_regs (gdbarch); |
6345 | while (regnum < gdbarch_num_regs (gdbarch) | |
6346 | + gdbarch_num_pseudo_regs (gdbarch)) | |
c906108c | 6347 | { |
004159a2 | 6348 | if (mips_float_register_p (gdbarch, regnum)) |
e11c53d2 | 6349 | { |
025bb325 | 6350 | if (all) /* True for "INFO ALL-REGISTERS" command. */ |
e11c53d2 AC |
6351 | regnum = print_fp_register_row (file, frame, regnum); |
6352 | else | |
025bb325 | 6353 | regnum += MIPS_NUMREGS; /* Skip floating point regs. */ |
e11c53d2 | 6354 | } |
c906108c | 6355 | else |
e11c53d2 | 6356 | regnum = print_gp_register_row (file, frame, regnum); |
c906108c SS |
6357 | } |
6358 | } | |
6359 | } | |
6360 | ||
63807e1d | 6361 | static int |
3352ef37 AC |
6362 | mips_single_step_through_delay (struct gdbarch *gdbarch, |
6363 | struct frame_info *frame) | |
c906108c | 6364 | { |
e17a4113 | 6365 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
3352ef37 | 6366 | CORE_ADDR pc = get_frame_pc (frame); |
4cc0665f MR |
6367 | struct address_space *aspace; |
6368 | enum mips_isa isa; | |
6369 | ULONGEST insn; | |
6370 | int status; | |
6371 | int size; | |
6372 | ||
6373 | if ((mips_pc_is_mips (pc) | |
6374 | && !mips32_instruction_has_delay_slot (gdbarch, pc)) | |
6375 | || (mips_pc_is_micromips (gdbarch, pc) | |
6376 | && !micromips_instruction_has_delay_slot (gdbarch, pc, 0)) | |
6377 | || (mips_pc_is_mips16 (gdbarch, pc) | |
6378 | && !mips16_instruction_has_delay_slot (gdbarch, pc, 0))) | |
06648491 MK |
6379 | return 0; |
6380 | ||
4cc0665f MR |
6381 | isa = mips_pc_isa (gdbarch, pc); |
6382 | /* _has_delay_slot above will have validated the read. */ | |
6383 | insn = mips_fetch_instruction (gdbarch, isa, pc, NULL); | |
6384 | size = mips_insn_size (isa, insn); | |
6385 | aspace = get_frame_address_space (frame); | |
6386 | return breakpoint_here_p (aspace, pc + size) != no_breakpoint_here; | |
c906108c SS |
6387 | } |
6388 | ||
6d82d43b AC |
6389 | /* To skip prologues, I use this predicate. Returns either PC itself |
6390 | if the code at PC does not look like a function prologue; otherwise | |
6391 | returns an address that (if we're lucky) follows the prologue. If | |
6392 | LENIENT, then we must skip everything which is involved in setting | |
6393 | up the frame (it's OK to skip more, just so long as we don't skip | |
6394 | anything which might clobber the registers which are being saved. | |
6395 | We must skip more in the case where part of the prologue is in the | |
6396 | delay slot of a non-prologue instruction). */ | |
6397 | ||
6398 | static CORE_ADDR | |
6093d2eb | 6399 | mips_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc) |
6d82d43b | 6400 | { |
8b622e6a AC |
6401 | CORE_ADDR limit_pc; |
6402 | CORE_ADDR func_addr; | |
6403 | ||
6d82d43b AC |
6404 | /* See if we can determine the end of the prologue via the symbol table. |
6405 | If so, then return either PC, or the PC after the prologue, whichever | |
6406 | is greater. */ | |
8b622e6a AC |
6407 | if (find_pc_partial_function (pc, NULL, &func_addr, NULL)) |
6408 | { | |
d80b854b UW |
6409 | CORE_ADDR post_prologue_pc |
6410 | = skip_prologue_using_sal (gdbarch, func_addr); | |
8b622e6a AC |
6411 | if (post_prologue_pc != 0) |
6412 | return max (pc, post_prologue_pc); | |
6413 | } | |
6d82d43b AC |
6414 | |
6415 | /* Can't determine prologue from the symbol table, need to examine | |
6416 | instructions. */ | |
6417 | ||
98b4dd94 JB |
6418 | /* Find an upper limit on the function prologue using the debug |
6419 | information. If the debug information could not be used to provide | |
6420 | that bound, then use an arbitrary large number as the upper bound. */ | |
d80b854b | 6421 | limit_pc = skip_prologue_using_sal (gdbarch, pc); |
98b4dd94 JB |
6422 | if (limit_pc == 0) |
6423 | limit_pc = pc + 100; /* Magic. */ | |
6424 | ||
4cc0665f | 6425 | if (mips_pc_is_mips16 (gdbarch, pc)) |
e17a4113 | 6426 | return mips16_scan_prologue (gdbarch, pc, limit_pc, NULL, NULL); |
4cc0665f MR |
6427 | else if (mips_pc_is_micromips (gdbarch, pc)) |
6428 | return micromips_scan_prologue (gdbarch, pc, limit_pc, NULL, NULL); | |
6d82d43b | 6429 | else |
e17a4113 | 6430 | return mips32_scan_prologue (gdbarch, pc, limit_pc, NULL, NULL); |
88658117 AC |
6431 | } |
6432 | ||
97ab0fdd MR |
6433 | /* Check whether the PC is in a function epilogue (32-bit version). |
6434 | This is a helper function for mips_in_function_epilogue_p. */ | |
6435 | static int | |
e17a4113 | 6436 | mips32_in_function_epilogue_p (struct gdbarch *gdbarch, CORE_ADDR pc) |
97ab0fdd MR |
6437 | { |
6438 | CORE_ADDR func_addr = 0, func_end = 0; | |
6439 | ||
6440 | if (find_pc_partial_function (pc, NULL, &func_addr, &func_end)) | |
6441 | { | |
6442 | /* The MIPS epilogue is max. 12 bytes long. */ | |
6443 | CORE_ADDR addr = func_end - 12; | |
6444 | ||
6445 | if (addr < func_addr + 4) | |
6446 | addr = func_addr + 4; | |
6447 | if (pc < addr) | |
6448 | return 0; | |
6449 | ||
6450 | for (; pc < func_end; pc += MIPS_INSN32_SIZE) | |
6451 | { | |
6452 | unsigned long high_word; | |
6453 | unsigned long inst; | |
6454 | ||
4cc0665f | 6455 | inst = mips_fetch_instruction (gdbarch, ISA_MIPS, pc, NULL); |
97ab0fdd MR |
6456 | high_word = (inst >> 16) & 0xffff; |
6457 | ||
6458 | if (high_word != 0x27bd /* addiu $sp,$sp,offset */ | |
6459 | && high_word != 0x67bd /* daddiu $sp,$sp,offset */ | |
6460 | && inst != 0x03e00008 /* jr $ra */ | |
6461 | && inst != 0x00000000) /* nop */ | |
6462 | return 0; | |
6463 | } | |
6464 | ||
6465 | return 1; | |
6466 | } | |
6467 | ||
6468 | return 0; | |
6469 | } | |
6470 | ||
4cc0665f MR |
6471 | /* Check whether the PC is in a function epilogue (microMIPS version). |
6472 | This is a helper function for mips_in_function_epilogue_p. */ | |
6473 | ||
6474 | static int | |
6475 | micromips_in_function_epilogue_p (struct gdbarch *gdbarch, CORE_ADDR pc) | |
6476 | { | |
6477 | CORE_ADDR func_addr = 0; | |
6478 | CORE_ADDR func_end = 0; | |
6479 | CORE_ADDR addr; | |
6480 | ULONGEST insn; | |
6481 | long offset; | |
6482 | int dreg; | |
6483 | int sreg; | |
6484 | int loc; | |
6485 | ||
6486 | if (!find_pc_partial_function (pc, NULL, &func_addr, &func_end)) | |
6487 | return 0; | |
6488 | ||
6489 | /* The microMIPS epilogue is max. 12 bytes long. */ | |
6490 | addr = func_end - 12; | |
6491 | ||
6492 | if (addr < func_addr + 2) | |
6493 | addr = func_addr + 2; | |
6494 | if (pc < addr) | |
6495 | return 0; | |
6496 | ||
6497 | for (; pc < func_end; pc += loc) | |
6498 | { | |
6499 | loc = 0; | |
6500 | insn = mips_fetch_instruction (gdbarch, ISA_MICROMIPS, pc, NULL); | |
6501 | loc += MIPS_INSN16_SIZE; | |
6502 | switch (mips_insn_size (ISA_MICROMIPS, insn)) | |
6503 | { | |
6504 | /* 48-bit instructions. */ | |
6505 | case 3 * MIPS_INSN16_SIZE: | |
6506 | /* No epilogue instructions in this category. */ | |
6507 | return 0; | |
6508 | ||
6509 | /* 32-bit instructions. */ | |
6510 | case 2 * MIPS_INSN16_SIZE: | |
6511 | insn <<= 16; | |
6512 | insn |= mips_fetch_instruction (gdbarch, | |
6513 | ISA_MICROMIPS, pc + loc, NULL); | |
6514 | loc += MIPS_INSN16_SIZE; | |
6515 | switch (micromips_op (insn >> 16)) | |
6516 | { | |
6517 | case 0xc: /* ADDIU: bits 001100 */ | |
6518 | case 0x17: /* DADDIU: bits 010111 */ | |
6519 | sreg = b0s5_reg (insn >> 16); | |
6520 | dreg = b5s5_reg (insn >> 16); | |
6521 | offset = (b0s16_imm (insn) ^ 0x8000) - 0x8000; | |
6522 | if (sreg == MIPS_SP_REGNUM && dreg == MIPS_SP_REGNUM | |
6523 | /* (D)ADDIU $sp, imm */ | |
6524 | && offset >= 0) | |
6525 | break; | |
6526 | return 0; | |
6527 | ||
6528 | default: | |
6529 | return 0; | |
6530 | } | |
6531 | break; | |
6532 | ||
6533 | /* 16-bit instructions. */ | |
6534 | case MIPS_INSN16_SIZE: | |
6535 | switch (micromips_op (insn)) | |
6536 | { | |
6537 | case 0x3: /* MOVE: bits 000011 */ | |
6538 | sreg = b0s5_reg (insn); | |
6539 | dreg = b5s5_reg (insn); | |
6540 | if (sreg == 0 && dreg == 0) | |
6541 | /* MOVE $zero, $zero aka NOP */ | |
6542 | break; | |
6543 | return 0; | |
6544 | ||
6545 | case 0x11: /* POOL16C: bits 010001 */ | |
6546 | if (b5s5_op (insn) == 0x18 | |
6547 | /* JRADDIUSP: bits 010011 11000 */ | |
6548 | || (b5s5_op (insn) == 0xd | |
6549 | /* JRC: bits 010011 01101 */ | |
6550 | && b0s5_reg (insn) == MIPS_RA_REGNUM)) | |
6551 | /* JRC $ra */ | |
6552 | break; | |
6553 | return 0; | |
6554 | ||
6555 | case 0x13: /* POOL16D: bits 010011 */ | |
6556 | offset = micromips_decode_imm9 (b1s9_imm (insn)); | |
6557 | if ((insn & 0x1) == 0x1 | |
6558 | /* ADDIUSP: bits 010011 1 */ | |
6559 | && offset > 0) | |
6560 | break; | |
6561 | return 0; | |
6562 | ||
6563 | default: | |
6564 | return 0; | |
6565 | } | |
6566 | } | |
6567 | } | |
6568 | ||
6569 | return 1; | |
6570 | } | |
6571 | ||
97ab0fdd MR |
6572 | /* Check whether the PC is in a function epilogue (16-bit version). |
6573 | This is a helper function for mips_in_function_epilogue_p. */ | |
6574 | static int | |
e17a4113 | 6575 | mips16_in_function_epilogue_p (struct gdbarch *gdbarch, CORE_ADDR pc) |
97ab0fdd MR |
6576 | { |
6577 | CORE_ADDR func_addr = 0, func_end = 0; | |
6578 | ||
6579 | if (find_pc_partial_function (pc, NULL, &func_addr, &func_end)) | |
6580 | { | |
6581 | /* The MIPS epilogue is max. 12 bytes long. */ | |
6582 | CORE_ADDR addr = func_end - 12; | |
6583 | ||
6584 | if (addr < func_addr + 4) | |
6585 | addr = func_addr + 4; | |
6586 | if (pc < addr) | |
6587 | return 0; | |
6588 | ||
6589 | for (; pc < func_end; pc += MIPS_INSN16_SIZE) | |
6590 | { | |
6591 | unsigned short inst; | |
6592 | ||
4cc0665f | 6593 | inst = mips_fetch_instruction (gdbarch, ISA_MIPS16, pc, NULL); |
97ab0fdd MR |
6594 | |
6595 | if ((inst & 0xf800) == 0xf000) /* extend */ | |
6596 | continue; | |
6597 | ||
6598 | if (inst != 0x6300 /* addiu $sp,offset */ | |
6599 | && inst != 0xfb00 /* daddiu $sp,$sp,offset */ | |
6600 | && inst != 0xe820 /* jr $ra */ | |
6601 | && inst != 0xe8a0 /* jrc $ra */ | |
6602 | && inst != 0x6500) /* nop */ | |
6603 | return 0; | |
6604 | } | |
6605 | ||
6606 | return 1; | |
6607 | } | |
6608 | ||
6609 | return 0; | |
6610 | } | |
6611 | ||
6612 | /* The epilogue is defined here as the area at the end of a function, | |
6613 | after an instruction which destroys the function's stack frame. */ | |
6614 | static int | |
6615 | mips_in_function_epilogue_p (struct gdbarch *gdbarch, CORE_ADDR pc) | |
6616 | { | |
4cc0665f | 6617 | if (mips_pc_is_mips16 (gdbarch, pc)) |
e17a4113 | 6618 | return mips16_in_function_epilogue_p (gdbarch, pc); |
4cc0665f MR |
6619 | else if (mips_pc_is_micromips (gdbarch, pc)) |
6620 | return micromips_in_function_epilogue_p (gdbarch, pc); | |
97ab0fdd | 6621 | else |
e17a4113 | 6622 | return mips32_in_function_epilogue_p (gdbarch, pc); |
97ab0fdd MR |
6623 | } |
6624 | ||
025bb325 | 6625 | /* Root of all "set mips "/"show mips " commands. This will eventually be |
a5ea2558 AC |
6626 | used for all MIPS-specific commands. */ |
6627 | ||
a5ea2558 | 6628 | static void |
acdb74a0 | 6629 | show_mips_command (char *args, int from_tty) |
a5ea2558 AC |
6630 | { |
6631 | help_list (showmipscmdlist, "show mips ", all_commands, gdb_stdout); | |
6632 | } | |
6633 | ||
a5ea2558 | 6634 | static void |
acdb74a0 | 6635 | set_mips_command (char *args, int from_tty) |
a5ea2558 | 6636 | { |
6d82d43b AC |
6637 | printf_unfiltered |
6638 | ("\"set mips\" must be followed by an appropriate subcommand.\n"); | |
a5ea2558 AC |
6639 | help_list (setmipscmdlist, "set mips ", all_commands, gdb_stdout); |
6640 | } | |
6641 | ||
c906108c SS |
6642 | /* Commands to show/set the MIPS FPU type. */ |
6643 | ||
c906108c | 6644 | static void |
acdb74a0 | 6645 | show_mipsfpu_command (char *args, int from_tty) |
c906108c | 6646 | { |
c906108c | 6647 | char *fpu; |
6ca0852e | 6648 | |
f5656ead | 6649 | if (gdbarch_bfd_arch_info (target_gdbarch ())->arch != bfd_arch_mips) |
6ca0852e UW |
6650 | { |
6651 | printf_unfiltered | |
6652 | ("The MIPS floating-point coprocessor is unknown " | |
6653 | "because the current architecture is not MIPS.\n"); | |
6654 | return; | |
6655 | } | |
6656 | ||
f5656ead | 6657 | switch (MIPS_FPU_TYPE (target_gdbarch ())) |
c906108c SS |
6658 | { |
6659 | case MIPS_FPU_SINGLE: | |
6660 | fpu = "single-precision"; | |
6661 | break; | |
6662 | case MIPS_FPU_DOUBLE: | |
6663 | fpu = "double-precision"; | |
6664 | break; | |
6665 | case MIPS_FPU_NONE: | |
6666 | fpu = "absent (none)"; | |
6667 | break; | |
93d56215 | 6668 | default: |
e2e0b3e5 | 6669 | internal_error (__FILE__, __LINE__, _("bad switch")); |
c906108c SS |
6670 | } |
6671 | if (mips_fpu_type_auto) | |
025bb325 MS |
6672 | printf_unfiltered ("The MIPS floating-point coprocessor " |
6673 | "is set automatically (currently %s)\n", | |
6674 | fpu); | |
c906108c | 6675 | else |
6d82d43b AC |
6676 | printf_unfiltered |
6677 | ("The MIPS floating-point coprocessor is assumed to be %s\n", fpu); | |
c906108c SS |
6678 | } |
6679 | ||
6680 | ||
c906108c | 6681 | static void |
acdb74a0 | 6682 | set_mipsfpu_command (char *args, int from_tty) |
c906108c | 6683 | { |
025bb325 MS |
6684 | printf_unfiltered ("\"set mipsfpu\" must be followed by \"double\", " |
6685 | "\"single\",\"none\" or \"auto\".\n"); | |
c906108c SS |
6686 | show_mipsfpu_command (args, from_tty); |
6687 | } | |
6688 | ||
c906108c | 6689 | static void |
acdb74a0 | 6690 | set_mipsfpu_single_command (char *args, int from_tty) |
c906108c | 6691 | { |
8d5838b5 AC |
6692 | struct gdbarch_info info; |
6693 | gdbarch_info_init (&info); | |
c906108c SS |
6694 | mips_fpu_type = MIPS_FPU_SINGLE; |
6695 | mips_fpu_type_auto = 0; | |
8d5838b5 AC |
6696 | /* FIXME: cagney/2003-11-15: Should be setting a field in "info" |
6697 | instead of relying on globals. Doing that would let generic code | |
6698 | handle the search for this specific architecture. */ | |
6699 | if (!gdbarch_update_p (info)) | |
e2e0b3e5 | 6700 | internal_error (__FILE__, __LINE__, _("set mipsfpu failed")); |
c906108c SS |
6701 | } |
6702 | ||
c906108c | 6703 | static void |
acdb74a0 | 6704 | set_mipsfpu_double_command (char *args, int from_tty) |
c906108c | 6705 | { |
8d5838b5 AC |
6706 | struct gdbarch_info info; |
6707 | gdbarch_info_init (&info); | |
c906108c SS |
6708 | mips_fpu_type = MIPS_FPU_DOUBLE; |
6709 | mips_fpu_type_auto = 0; | |
8d5838b5 AC |
6710 | /* FIXME: cagney/2003-11-15: Should be setting a field in "info" |
6711 | instead of relying on globals. Doing that would let generic code | |
6712 | handle the search for this specific architecture. */ | |
6713 | if (!gdbarch_update_p (info)) | |
e2e0b3e5 | 6714 | internal_error (__FILE__, __LINE__, _("set mipsfpu failed")); |
c906108c SS |
6715 | } |
6716 | ||
c906108c | 6717 | static void |
acdb74a0 | 6718 | set_mipsfpu_none_command (char *args, int from_tty) |
c906108c | 6719 | { |
8d5838b5 AC |
6720 | struct gdbarch_info info; |
6721 | gdbarch_info_init (&info); | |
c906108c SS |
6722 | mips_fpu_type = MIPS_FPU_NONE; |
6723 | mips_fpu_type_auto = 0; | |
8d5838b5 AC |
6724 | /* FIXME: cagney/2003-11-15: Should be setting a field in "info" |
6725 | instead of relying on globals. Doing that would let generic code | |
6726 | handle the search for this specific architecture. */ | |
6727 | if (!gdbarch_update_p (info)) | |
e2e0b3e5 | 6728 | internal_error (__FILE__, __LINE__, _("set mipsfpu failed")); |
c906108c SS |
6729 | } |
6730 | ||
c906108c | 6731 | static void |
acdb74a0 | 6732 | set_mipsfpu_auto_command (char *args, int from_tty) |
c906108c SS |
6733 | { |
6734 | mips_fpu_type_auto = 1; | |
6735 | } | |
6736 | ||
c906108c | 6737 | /* Attempt to identify the particular processor model by reading the |
691c0433 AC |
6738 | processor id. NOTE: cagney/2003-11-15: Firstly it isn't clear that |
6739 | the relevant processor still exists (it dates back to '94) and | |
6740 | secondly this is not the way to do this. The processor type should | |
6741 | be set by forcing an architecture change. */ | |
c906108c | 6742 | |
691c0433 AC |
6743 | void |
6744 | deprecated_mips_set_processor_regs_hack (void) | |
c906108c | 6745 | { |
bb486190 UW |
6746 | struct regcache *regcache = get_current_regcache (); |
6747 | struct gdbarch *gdbarch = get_regcache_arch (regcache); | |
6748 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
a9614958 | 6749 | ULONGEST prid; |
c906108c | 6750 | |
bb486190 | 6751 | regcache_cooked_read_unsigned (regcache, MIPS_PRID_REGNUM, &prid); |
c906108c | 6752 | if ((prid & ~0xf) == 0x700) |
691c0433 | 6753 | tdep->mips_processor_reg_names = mips_r3041_reg_names; |
c906108c SS |
6754 | } |
6755 | ||
6756 | /* Just like reinit_frame_cache, but with the right arguments to be | |
6757 | callable as an sfunc. */ | |
6758 | ||
6759 | static void | |
acdb74a0 AC |
6760 | reinit_frame_cache_sfunc (char *args, int from_tty, |
6761 | struct cmd_list_element *c) | |
c906108c SS |
6762 | { |
6763 | reinit_frame_cache (); | |
6764 | } | |
6765 | ||
a89aa300 AC |
6766 | static int |
6767 | gdb_print_insn_mips (bfd_vma memaddr, struct disassemble_info *info) | |
c906108c | 6768 | { |
4cc0665f MR |
6769 | struct gdbarch *gdbarch = info->application_data; |
6770 | ||
d31431ed AC |
6771 | /* FIXME: cagney/2003-06-26: Is this even necessary? The |
6772 | disassembler needs to be able to locally determine the ISA, and | |
6773 | not rely on GDB. Otherwize the stand-alone 'objdump -d' will not | |
6774 | work. */ | |
4cc0665f | 6775 | if (mips_pc_is_mips16 (gdbarch, memaddr)) |
ec4045ea | 6776 | info->mach = bfd_mach_mips16; |
4cc0665f MR |
6777 | else if (mips_pc_is_micromips (gdbarch, memaddr)) |
6778 | info->mach = bfd_mach_mips_micromips; | |
c906108c SS |
6779 | |
6780 | /* Round down the instruction address to the appropriate boundary. */ | |
4cc0665f MR |
6781 | memaddr &= (info->mach == bfd_mach_mips16 |
6782 | || info->mach == bfd_mach_mips_micromips) ? ~1 : ~3; | |
c5aa993b | 6783 | |
e5ab0dce | 6784 | /* Set the disassembler options. */ |
9dae60cc | 6785 | if (!info->disassembler_options) |
e5ab0dce AC |
6786 | /* This string is not recognized explicitly by the disassembler, |
6787 | but it tells the disassembler to not try to guess the ABI from | |
6788 | the bfd elf headers, such that, if the user overrides the ABI | |
6789 | of a program linked as NewABI, the disassembly will follow the | |
6790 | register naming conventions specified by the user. */ | |
6791 | info->disassembler_options = "gpr-names=32"; | |
6792 | ||
c906108c | 6793 | /* Call the appropriate disassembler based on the target endian-ness. */ |
40887e1a | 6794 | if (info->endian == BFD_ENDIAN_BIG) |
c906108c SS |
6795 | return print_insn_big_mips (memaddr, info); |
6796 | else | |
6797 | return print_insn_little_mips (memaddr, info); | |
6798 | } | |
6799 | ||
9dae60cc UW |
6800 | static int |
6801 | gdb_print_insn_mips_n32 (bfd_vma memaddr, struct disassemble_info *info) | |
6802 | { | |
6803 | /* Set up the disassembler info, so that we get the right | |
6804 | register names from libopcodes. */ | |
6805 | info->disassembler_options = "gpr-names=n32"; | |
6806 | info->flavour = bfd_target_elf_flavour; | |
6807 | ||
6808 | return gdb_print_insn_mips (memaddr, info); | |
6809 | } | |
6810 | ||
6811 | static int | |
6812 | gdb_print_insn_mips_n64 (bfd_vma memaddr, struct disassemble_info *info) | |
6813 | { | |
6814 | /* Set up the disassembler info, so that we get the right | |
6815 | register names from libopcodes. */ | |
6816 | info->disassembler_options = "gpr-names=64"; | |
6817 | info->flavour = bfd_target_elf_flavour; | |
6818 | ||
6819 | return gdb_print_insn_mips (memaddr, info); | |
6820 | } | |
6821 | ||
025bb325 MS |
6822 | /* This function implements gdbarch_breakpoint_from_pc. It uses the |
6823 | program counter value to determine whether a 16- or 32-bit breakpoint | |
6824 | should be used. It returns a pointer to a string of bytes that encode a | |
6825 | breakpoint instruction, stores the length of the string to *lenptr, and | |
6826 | adjusts pc (if necessary) to point to the actual memory location where | |
6827 | the breakpoint should be inserted. */ | |
c906108c | 6828 | |
47a35522 | 6829 | static const gdb_byte * |
025bb325 MS |
6830 | mips_breakpoint_from_pc (struct gdbarch *gdbarch, |
6831 | CORE_ADDR *pcptr, int *lenptr) | |
c906108c | 6832 | { |
4cc0665f MR |
6833 | CORE_ADDR pc = *pcptr; |
6834 | ||
67d57894 | 6835 | if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) |
c906108c | 6836 | { |
4cc0665f | 6837 | if (mips_pc_is_mips16 (gdbarch, pc)) |
c906108c | 6838 | { |
47a35522 | 6839 | static gdb_byte mips16_big_breakpoint[] = { 0xe8, 0xa5 }; |
4cc0665f | 6840 | *pcptr = unmake_compact_addr (pc); |
c5aa993b | 6841 | *lenptr = sizeof (mips16_big_breakpoint); |
c906108c SS |
6842 | return mips16_big_breakpoint; |
6843 | } | |
4cc0665f MR |
6844 | else if (mips_pc_is_micromips (gdbarch, pc)) |
6845 | { | |
6846 | static gdb_byte micromips16_big_breakpoint[] = { 0x46, 0x85 }; | |
6847 | static gdb_byte micromips32_big_breakpoint[] = { 0, 0x5, 0, 0x7 }; | |
6848 | ULONGEST insn; | |
6849 | int status; | |
6850 | int size; | |
6851 | ||
6852 | insn = mips_fetch_instruction (gdbarch, ISA_MICROMIPS, pc, &status); | |
6853 | size = status ? 2 | |
6854 | : mips_insn_size (ISA_MICROMIPS, insn) == 2 ? 2 : 4; | |
6855 | *pcptr = unmake_compact_addr (pc); | |
6856 | *lenptr = size; | |
6857 | return (size == 2) ? micromips16_big_breakpoint | |
6858 | : micromips32_big_breakpoint; | |
6859 | } | |
c906108c SS |
6860 | else |
6861 | { | |
aaab4dba AC |
6862 | /* The IDT board uses an unusual breakpoint value, and |
6863 | sometimes gets confused when it sees the usual MIPS | |
6864 | breakpoint instruction. */ | |
47a35522 MK |
6865 | static gdb_byte big_breakpoint[] = { 0, 0x5, 0, 0xd }; |
6866 | static gdb_byte pmon_big_breakpoint[] = { 0, 0, 0, 0xd }; | |
6867 | static gdb_byte idt_big_breakpoint[] = { 0, 0, 0x0a, 0xd }; | |
f2ec0ecf | 6868 | /* Likewise, IRIX appears to expect a different breakpoint, |
025bb325 | 6869 | although this is not apparent until you try to use pthreads. */ |
f2ec0ecf | 6870 | static gdb_byte irix_big_breakpoint[] = { 0, 0, 0, 0xd }; |
c906108c | 6871 | |
c5aa993b | 6872 | *lenptr = sizeof (big_breakpoint); |
c906108c SS |
6873 | |
6874 | if (strcmp (target_shortname, "mips") == 0) | |
6875 | return idt_big_breakpoint; | |
6876 | else if (strcmp (target_shortname, "ddb") == 0 | |
6877 | || strcmp (target_shortname, "pmon") == 0 | |
6878 | || strcmp (target_shortname, "lsi") == 0) | |
6879 | return pmon_big_breakpoint; | |
f2ec0ecf JB |
6880 | else if (gdbarch_osabi (gdbarch) == GDB_OSABI_IRIX) |
6881 | return irix_big_breakpoint; | |
c906108c SS |
6882 | else |
6883 | return big_breakpoint; | |
6884 | } | |
6885 | } | |
6886 | else | |
6887 | { | |
4cc0665f | 6888 | if (mips_pc_is_mips16 (gdbarch, pc)) |
c906108c | 6889 | { |
47a35522 | 6890 | static gdb_byte mips16_little_breakpoint[] = { 0xa5, 0xe8 }; |
4cc0665f | 6891 | *pcptr = unmake_compact_addr (pc); |
c5aa993b | 6892 | *lenptr = sizeof (mips16_little_breakpoint); |
c906108c SS |
6893 | return mips16_little_breakpoint; |
6894 | } | |
4cc0665f MR |
6895 | else if (mips_pc_is_micromips (gdbarch, pc)) |
6896 | { | |
6897 | static gdb_byte micromips16_little_breakpoint[] = { 0x85, 0x46 }; | |
6898 | static gdb_byte micromips32_little_breakpoint[] = { 0x5, 0, 0x7, 0 }; | |
6899 | ULONGEST insn; | |
6900 | int status; | |
6901 | int size; | |
6902 | ||
6903 | insn = mips_fetch_instruction (gdbarch, ISA_MICROMIPS, pc, &status); | |
6904 | size = status ? 2 | |
6905 | : mips_insn_size (ISA_MICROMIPS, insn) == 2 ? 2 : 4; | |
6906 | *pcptr = unmake_compact_addr (pc); | |
6907 | *lenptr = size; | |
6908 | return (size == 2) ? micromips16_little_breakpoint | |
6909 | : micromips32_little_breakpoint; | |
6910 | } | |
c906108c SS |
6911 | else |
6912 | { | |
47a35522 MK |
6913 | static gdb_byte little_breakpoint[] = { 0xd, 0, 0x5, 0 }; |
6914 | static gdb_byte pmon_little_breakpoint[] = { 0xd, 0, 0, 0 }; | |
6915 | static gdb_byte idt_little_breakpoint[] = { 0xd, 0x0a, 0, 0 }; | |
c906108c | 6916 | |
c5aa993b | 6917 | *lenptr = sizeof (little_breakpoint); |
c906108c SS |
6918 | |
6919 | if (strcmp (target_shortname, "mips") == 0) | |
6920 | return idt_little_breakpoint; | |
6921 | else if (strcmp (target_shortname, "ddb") == 0 | |
6922 | || strcmp (target_shortname, "pmon") == 0 | |
6923 | || strcmp (target_shortname, "lsi") == 0) | |
6924 | return pmon_little_breakpoint; | |
6925 | else | |
6926 | return little_breakpoint; | |
6927 | } | |
6928 | } | |
6929 | } | |
6930 | ||
4cc0665f MR |
6931 | /* Determine the remote breakpoint kind suitable for the PC. The following |
6932 | kinds are used: | |
6933 | ||
6934 | * 2 -- 16-bit MIPS16 mode breakpoint, | |
6935 | ||
6936 | * 3 -- 16-bit microMIPS mode breakpoint, | |
6937 | ||
6938 | * 4 -- 32-bit standard MIPS mode breakpoint, | |
6939 | ||
6940 | * 5 -- 32-bit microMIPS mode breakpoint. */ | |
6941 | ||
6942 | static void | |
6943 | mips_remote_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr, | |
6944 | int *kindptr) | |
6945 | { | |
6946 | CORE_ADDR pc = *pcptr; | |
6947 | ||
6948 | if (mips_pc_is_mips16 (gdbarch, pc)) | |
6949 | { | |
6950 | *pcptr = unmake_compact_addr (pc); | |
6951 | *kindptr = 2; | |
6952 | } | |
6953 | else if (mips_pc_is_micromips (gdbarch, pc)) | |
6954 | { | |
6955 | ULONGEST insn; | |
6956 | int status; | |
6957 | int size; | |
6958 | ||
6959 | insn = mips_fetch_instruction (gdbarch, ISA_MICROMIPS, pc, &status); | |
6960 | size = status ? 2 : mips_insn_size (ISA_MICROMIPS, insn) == 2 ? 2 : 4; | |
6961 | *pcptr = unmake_compact_addr (pc); | |
6962 | *kindptr = size | 1; | |
6963 | } | |
6964 | else | |
6965 | *kindptr = 4; | |
6966 | } | |
6967 | ||
c8cef75f MR |
6968 | /* Return non-zero if the ADDR instruction has a branch delay slot |
6969 | (i.e. it is a jump or branch instruction). This function is based | |
6970 | on mips32_next_pc. */ | |
6971 | ||
6972 | static int | |
6973 | mips32_instruction_has_delay_slot (struct gdbarch *gdbarch, CORE_ADDR addr) | |
6974 | { | |
c8cef75f MR |
6975 | unsigned long inst; |
6976 | int status; | |
6977 | int op; | |
a385295e MR |
6978 | int rs; |
6979 | int rt; | |
c8cef75f | 6980 | |
4cc0665f | 6981 | inst = mips_fetch_instruction (gdbarch, ISA_MIPS, addr, &status); |
c8cef75f MR |
6982 | if (status) |
6983 | return 0; | |
6984 | ||
c8cef75f MR |
6985 | op = itype_op (inst); |
6986 | if ((inst & 0xe0000000) != 0) | |
a385295e MR |
6987 | { |
6988 | rs = itype_rs (inst); | |
6989 | rt = itype_rt (inst); | |
f94363d7 AP |
6990 | return (is_octeon_bbit_op (op, gdbarch) |
6991 | || op >> 2 == 5 /* BEQL, BNEL, BLEZL, BGTZL: bits 0101xx */ | |
a385295e MR |
6992 | || op == 29 /* JALX: bits 011101 */ |
6993 | || (op == 17 | |
6994 | && (rs == 8 | |
c8cef75f | 6995 | /* BC1F, BC1FL, BC1T, BC1TL: 010001 01000 */ |
a385295e MR |
6996 | || (rs == 9 && (rt & 0x2) == 0) |
6997 | /* BC1ANY2F, BC1ANY2T: bits 010001 01001 */ | |
6998 | || (rs == 10 && (rt & 0x2) == 0)))); | |
6999 | /* BC1ANY4F, BC1ANY4T: bits 010001 01010 */ | |
7000 | } | |
c8cef75f MR |
7001 | else |
7002 | switch (op & 0x07) /* extract bits 28,27,26 */ | |
7003 | { | |
7004 | case 0: /* SPECIAL */ | |
7005 | op = rtype_funct (inst); | |
7006 | return (op == 8 /* JR */ | |
7007 | || op == 9); /* JALR */ | |
7008 | break; /* end SPECIAL */ | |
7009 | case 1: /* REGIMM */ | |
a385295e MR |
7010 | rs = itype_rs (inst); |
7011 | rt = itype_rt (inst); /* branch condition */ | |
7012 | return ((rt & 0xc) == 0 | |
c8cef75f MR |
7013 | /* BLTZ, BLTZL, BGEZ, BGEZL: bits 000xx */ |
7014 | /* BLTZAL, BLTZALL, BGEZAL, BGEZALL: 100xx */ | |
a385295e MR |
7015 | || ((rt & 0x1e) == 0x1c && rs == 0)); |
7016 | /* BPOSGE32, BPOSGE64: bits 1110x */ | |
c8cef75f MR |
7017 | break; /* end REGIMM */ |
7018 | default: /* J, JAL, BEQ, BNE, BLEZ, BGTZ */ | |
7019 | return 1; | |
7020 | break; | |
7021 | } | |
7022 | } | |
7023 | ||
7024 | /* Return non-zero if the ADDR instruction, which must be a 32-bit | |
7025 | instruction if MUSTBE32 is set or can be any instruction otherwise, | |
7026 | has a branch delay slot (i.e. it is a non-compact jump instruction). */ | |
7027 | ||
4cc0665f MR |
7028 | static int |
7029 | micromips_instruction_has_delay_slot (struct gdbarch *gdbarch, | |
7030 | CORE_ADDR addr, int mustbe32) | |
7031 | { | |
7032 | ULONGEST insn; | |
7033 | int status; | |
7034 | ||
7035 | insn = mips_fetch_instruction (gdbarch, ISA_MICROMIPS, addr, &status); | |
7036 | if (status) | |
7037 | return 0; | |
7038 | ||
7039 | if (!mustbe32) /* 16-bit instructions. */ | |
7040 | return (micromips_op (insn) == 0x11 | |
7041 | /* POOL16C: bits 010001 */ | |
7042 | && (b5s5_op (insn) == 0xc | |
7043 | /* JR16: bits 010001 01100 */ | |
7044 | || (b5s5_op (insn) & 0x1e) == 0xe)) | |
7045 | /* JALR16, JALRS16: bits 010001 0111x */ | |
7046 | || (micromips_op (insn) & 0x37) == 0x23 | |
7047 | /* BEQZ16, BNEZ16: bits 10x011 */ | |
7048 | || micromips_op (insn) == 0x33; | |
7049 | /* B16: bits 110011 */ | |
7050 | ||
7051 | /* 32-bit instructions. */ | |
7052 | if (micromips_op (insn) == 0x0) | |
7053 | /* POOL32A: bits 000000 */ | |
7054 | { | |
7055 | insn <<= 16; | |
7056 | insn |= mips_fetch_instruction (gdbarch, ISA_MICROMIPS, addr, &status); | |
7057 | if (status) | |
7058 | return 0; | |
7059 | return b0s6_op (insn) == 0x3c | |
7060 | /* POOL32Axf: bits 000000 ... 111100 */ | |
7061 | && (b6s10_ext (insn) & 0x2bf) == 0x3c; | |
7062 | /* JALR, JALR.HB: 000000 000x111100 111100 */ | |
7063 | /* JALRS, JALRS.HB: 000000 010x111100 111100 */ | |
7064 | } | |
7065 | ||
7066 | return (micromips_op (insn) == 0x10 | |
7067 | /* POOL32I: bits 010000 */ | |
7068 | && ((b5s5_op (insn) & 0x1c) == 0x0 | |
7069 | /* BLTZ, BLTZAL, BGEZ, BGEZAL: 010000 000xx */ | |
7070 | || (b5s5_op (insn) & 0x1d) == 0x4 | |
7071 | /* BLEZ, BGTZ: bits 010000 001x0 */ | |
7072 | || (b5s5_op (insn) & 0x1d) == 0x11 | |
7073 | /* BLTZALS, BGEZALS: bits 010000 100x1 */ | |
7074 | || ((b5s5_op (insn) & 0x1e) == 0x14 | |
7075 | && (insn & 0x3) == 0x0) | |
7076 | /* BC2F, BC2T: bits 010000 1010x xxx00 */ | |
7077 | || (b5s5_op (insn) & 0x1e) == 0x1a | |
7078 | /* BPOSGE64, BPOSGE32: bits 010000 1101x */ | |
7079 | || ((b5s5_op (insn) & 0x1e) == 0x1c | |
7080 | && (insn & 0x3) == 0x0) | |
7081 | /* BC1F, BC1T: bits 010000 1110x xxx00 */ | |
7082 | || ((b5s5_op (insn) & 0x1c) == 0x1c | |
7083 | && (insn & 0x3) == 0x1))) | |
7084 | /* BC1ANY*: bits 010000 111xx xxx01 */ | |
7085 | || (micromips_op (insn) & 0x1f) == 0x1d | |
7086 | /* JALS, JAL: bits x11101 */ | |
7087 | || (micromips_op (insn) & 0x37) == 0x25 | |
7088 | /* BEQ, BNE: bits 10x101 */ | |
7089 | || micromips_op (insn) == 0x35 | |
7090 | /* J: bits 110101 */ | |
7091 | || micromips_op (insn) == 0x3c; | |
7092 | /* JALX: bits 111100 */ | |
7093 | } | |
7094 | ||
c8cef75f MR |
7095 | static int |
7096 | mips16_instruction_has_delay_slot (struct gdbarch *gdbarch, CORE_ADDR addr, | |
7097 | int mustbe32) | |
7098 | { | |
c8cef75f MR |
7099 | unsigned short inst; |
7100 | int status; | |
7101 | ||
4cc0665f | 7102 | inst = mips_fetch_instruction (gdbarch, ISA_MIPS16, addr, &status); |
c8cef75f MR |
7103 | if (status) |
7104 | return 0; | |
7105 | ||
c8cef75f MR |
7106 | if (!mustbe32) |
7107 | return (inst & 0xf89f) == 0xe800; /* JR/JALR (16-bit instruction) */ | |
7108 | return (inst & 0xf800) == 0x1800; /* JAL/JALX (32-bit instruction) */ | |
7109 | } | |
7110 | ||
7111 | /* Calculate the starting address of the MIPS memory segment BPADDR is in. | |
7112 | This assumes KSSEG exists. */ | |
7113 | ||
7114 | static CORE_ADDR | |
7115 | mips_segment_boundary (CORE_ADDR bpaddr) | |
7116 | { | |
7117 | CORE_ADDR mask = CORE_ADDR_MAX; | |
7118 | int segsize; | |
7119 | ||
7120 | if (sizeof (CORE_ADDR) == 8) | |
7121 | /* Get the topmost two bits of bpaddr in a 32-bit safe manner (avoid | |
7122 | a compiler warning produced where CORE_ADDR is a 32-bit type even | |
7123 | though in that case this is dead code). */ | |
7124 | switch (bpaddr >> ((sizeof (CORE_ADDR) << 3) - 2) & 3) | |
7125 | { | |
7126 | case 3: | |
7127 | if (bpaddr == (bfd_signed_vma) (int32_t) bpaddr) | |
7128 | segsize = 29; /* 32-bit compatibility segment */ | |
7129 | else | |
7130 | segsize = 62; /* xkseg */ | |
7131 | break; | |
7132 | case 2: /* xkphys */ | |
7133 | segsize = 59; | |
7134 | break; | |
7135 | default: /* xksseg (1), xkuseg/kuseg (0) */ | |
7136 | segsize = 62; | |
7137 | break; | |
7138 | } | |
7139 | else if (bpaddr & 0x80000000) /* kernel segment */ | |
7140 | segsize = 29; | |
7141 | else | |
7142 | segsize = 31; /* user segment */ | |
7143 | mask <<= segsize; | |
7144 | return bpaddr & mask; | |
7145 | } | |
7146 | ||
7147 | /* Move the breakpoint at BPADDR out of any branch delay slot by shifting | |
7148 | it backwards if necessary. Return the address of the new location. */ | |
7149 | ||
7150 | static CORE_ADDR | |
7151 | mips_adjust_breakpoint_address (struct gdbarch *gdbarch, CORE_ADDR bpaddr) | |
7152 | { | |
22e048c9 | 7153 | CORE_ADDR prev_addr; |
c8cef75f MR |
7154 | CORE_ADDR boundary; |
7155 | CORE_ADDR func_addr; | |
7156 | ||
7157 | /* If a breakpoint is set on the instruction in a branch delay slot, | |
7158 | GDB gets confused. When the breakpoint is hit, the PC isn't on | |
7159 | the instruction in the branch delay slot, the PC will point to | |
7160 | the branch instruction. Since the PC doesn't match any known | |
7161 | breakpoints, GDB reports a trap exception. | |
7162 | ||
7163 | There are two possible fixes for this problem. | |
7164 | ||
7165 | 1) When the breakpoint gets hit, see if the BD bit is set in the | |
7166 | Cause register (which indicates the last exception occurred in a | |
7167 | branch delay slot). If the BD bit is set, fix the PC to point to | |
7168 | the instruction in the branch delay slot. | |
7169 | ||
7170 | 2) When the user sets the breakpoint, don't allow him to set the | |
7171 | breakpoint on the instruction in the branch delay slot. Instead | |
7172 | move the breakpoint to the branch instruction (which will have | |
7173 | the same result). | |
7174 | ||
7175 | The problem with the first solution is that if the user then | |
7176 | single-steps the processor, the branch instruction will get | |
7177 | skipped (since GDB thinks the PC is on the instruction in the | |
7178 | branch delay slot). | |
7179 | ||
7180 | So, we'll use the second solution. To do this we need to know if | |
7181 | the instruction we're trying to set the breakpoint on is in the | |
7182 | branch delay slot. */ | |
7183 | ||
7184 | boundary = mips_segment_boundary (bpaddr); | |
7185 | ||
7186 | /* Make sure we don't scan back before the beginning of the current | |
7187 | function, since we may fetch constant data or insns that look like | |
7188 | a jump. Of course we might do that anyway if the compiler has | |
7189 | moved constants inline. :-( */ | |
7190 | if (find_pc_partial_function (bpaddr, NULL, &func_addr, NULL) | |
7191 | && func_addr > boundary && func_addr <= bpaddr) | |
7192 | boundary = func_addr; | |
7193 | ||
4cc0665f | 7194 | if (mips_pc_is_mips (bpaddr)) |
c8cef75f MR |
7195 | { |
7196 | if (bpaddr == boundary) | |
7197 | return bpaddr; | |
7198 | ||
7199 | /* If the previous instruction has a branch delay slot, we have | |
7200 | to move the breakpoint to the branch instruction. */ | |
7201 | prev_addr = bpaddr - 4; | |
7202 | if (mips32_instruction_has_delay_slot (gdbarch, prev_addr)) | |
7203 | bpaddr = prev_addr; | |
7204 | } | |
7205 | else | |
7206 | { | |
4cc0665f | 7207 | int (*instruction_has_delay_slot) (struct gdbarch *, CORE_ADDR, int); |
c8cef75f MR |
7208 | CORE_ADDR addr, jmpaddr; |
7209 | int i; | |
7210 | ||
4cc0665f | 7211 | boundary = unmake_compact_addr (boundary); |
c8cef75f MR |
7212 | |
7213 | /* The only MIPS16 instructions with delay slots are JAL, JALX, | |
7214 | JALR and JR. An absolute JAL/JALX is always 4 bytes long, | |
7215 | so try for that first, then try the 2 byte JALR/JR. | |
4cc0665f MR |
7216 | The microMIPS ASE has a whole range of jumps and branches |
7217 | with delay slots, some of which take 4 bytes and some take | |
7218 | 2 bytes, so the idea is the same. | |
c8cef75f MR |
7219 | FIXME: We have to assume that bpaddr is not the second half |
7220 | of an extended instruction. */ | |
4cc0665f MR |
7221 | instruction_has_delay_slot = (mips_pc_is_micromips (gdbarch, bpaddr) |
7222 | ? micromips_instruction_has_delay_slot | |
7223 | : mips16_instruction_has_delay_slot); | |
c8cef75f MR |
7224 | |
7225 | jmpaddr = 0; | |
7226 | addr = bpaddr; | |
7227 | for (i = 1; i < 4; i++) | |
7228 | { | |
4cc0665f | 7229 | if (unmake_compact_addr (addr) == boundary) |
c8cef75f | 7230 | break; |
4cc0665f MR |
7231 | addr -= MIPS_INSN16_SIZE; |
7232 | if (i == 1 && instruction_has_delay_slot (gdbarch, addr, 0)) | |
c8cef75f MR |
7233 | /* Looks like a JR/JALR at [target-1], but it could be |
7234 | the second word of a previous JAL/JALX, so record it | |
7235 | and check back one more. */ | |
7236 | jmpaddr = addr; | |
4cc0665f | 7237 | else if (i > 1 && instruction_has_delay_slot (gdbarch, addr, 1)) |
c8cef75f MR |
7238 | { |
7239 | if (i == 2) | |
7240 | /* Looks like a JAL/JALX at [target-2], but it could also | |
7241 | be the second word of a previous JAL/JALX, record it, | |
7242 | and check back one more. */ | |
7243 | jmpaddr = addr; | |
7244 | else | |
7245 | /* Looks like a JAL/JALX at [target-3], so any previously | |
7246 | recorded JAL/JALX or JR/JALR must be wrong, because: | |
7247 | ||
7248 | >-3: JAL | |
7249 | -2: JAL-ext (can't be JAL/JALX) | |
7250 | -1: bdslot (can't be JR/JALR) | |
7251 | 0: target insn | |
7252 | ||
7253 | Of course it could be another JAL-ext which looks | |
7254 | like a JAL, but in that case we'd have broken out | |
7255 | of this loop at [target-2]: | |
7256 | ||
7257 | -4: JAL | |
7258 | >-3: JAL-ext | |
7259 | -2: bdslot (can't be jmp) | |
7260 | -1: JR/JALR | |
7261 | 0: target insn */ | |
7262 | jmpaddr = 0; | |
7263 | } | |
7264 | else | |
7265 | { | |
7266 | /* Not a jump instruction: if we're at [target-1] this | |
7267 | could be the second word of a JAL/JALX, so continue; | |
7268 | otherwise we're done. */ | |
7269 | if (i > 1) | |
7270 | break; | |
7271 | } | |
7272 | } | |
7273 | ||
7274 | if (jmpaddr) | |
7275 | bpaddr = jmpaddr; | |
7276 | } | |
7277 | ||
7278 | return bpaddr; | |
7279 | } | |
7280 | ||
14132e89 MR |
7281 | /* Return non-zero if SUFFIX is one of the numeric suffixes used for MIPS16 |
7282 | call stubs, one of 1, 2, 5, 6, 9, 10, or, if ZERO is non-zero, also 0. */ | |
7283 | ||
7284 | static int | |
7285 | mips_is_stub_suffix (const char *suffix, int zero) | |
7286 | { | |
7287 | switch (suffix[0]) | |
7288 | { | |
7289 | case '0': | |
7290 | return zero && suffix[1] == '\0'; | |
7291 | case '1': | |
7292 | return suffix[1] == '\0' || (suffix[1] == '0' && suffix[2] == '\0'); | |
7293 | case '2': | |
7294 | case '5': | |
7295 | case '6': | |
7296 | case '9': | |
7297 | return suffix[1] == '\0'; | |
7298 | default: | |
7299 | return 0; | |
7300 | } | |
7301 | } | |
7302 | ||
7303 | /* Return non-zero if MODE is one of the mode infixes used for MIPS16 | |
7304 | call stubs, one of sf, df, sc, or dc. */ | |
7305 | ||
7306 | static int | |
7307 | mips_is_stub_mode (const char *mode) | |
7308 | { | |
7309 | return ((mode[0] == 's' || mode[0] == 'd') | |
7310 | && (mode[1] == 'f' || mode[1] == 'c')); | |
7311 | } | |
7312 | ||
7313 | /* Code at PC is a compiler-generated stub. Such a stub for a function | |
7314 | bar might have a name like __fn_stub_bar, and might look like this: | |
7315 | ||
7316 | mfc1 $4, $f13 | |
7317 | mfc1 $5, $f12 | |
7318 | mfc1 $6, $f15 | |
7319 | mfc1 $7, $f14 | |
7320 | ||
7321 | followed by (or interspersed with): | |
7322 | ||
7323 | j bar | |
7324 | ||
7325 | or: | |
7326 | ||
7327 | lui $25, %hi(bar) | |
7328 | addiu $25, $25, %lo(bar) | |
7329 | jr $25 | |
7330 | ||
7331 | ($1 may be used in old code; for robustness we accept any register) | |
7332 | or, in PIC code: | |
7333 | ||
7334 | lui $28, %hi(_gp_disp) | |
7335 | addiu $28, $28, %lo(_gp_disp) | |
7336 | addu $28, $28, $25 | |
7337 | lw $25, %got(bar) | |
7338 | addiu $25, $25, %lo(bar) | |
7339 | jr $25 | |
7340 | ||
7341 | In the case of a __call_stub_bar stub, the sequence to set up | |
7342 | arguments might look like this: | |
7343 | ||
7344 | mtc1 $4, $f13 | |
7345 | mtc1 $5, $f12 | |
7346 | mtc1 $6, $f15 | |
7347 | mtc1 $7, $f14 | |
7348 | ||
7349 | followed by (or interspersed with) one of the jump sequences above. | |
7350 | ||
7351 | In the case of a __call_stub_fp_bar stub, JAL or JALR is used instead | |
7352 | of J or JR, respectively, followed by: | |
7353 | ||
7354 | mfc1 $2, $f0 | |
7355 | mfc1 $3, $f1 | |
7356 | jr $18 | |
7357 | ||
7358 | We are at the beginning of the stub here, and scan down and extract | |
7359 | the target address from the jump immediate instruction or, if a jump | |
7360 | register instruction is used, from the register referred. Return | |
7361 | the value of PC calculated or 0 if inconclusive. | |
7362 | ||
7363 | The limit on the search is arbitrarily set to 20 instructions. FIXME. */ | |
7364 | ||
7365 | static CORE_ADDR | |
7366 | mips_get_mips16_fn_stub_pc (struct frame_info *frame, CORE_ADDR pc) | |
7367 | { | |
7368 | struct gdbarch *gdbarch = get_frame_arch (frame); | |
7369 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); | |
7370 | int addrreg = MIPS_ZERO_REGNUM; | |
7371 | CORE_ADDR start_pc = pc; | |
7372 | CORE_ADDR target_pc = 0; | |
7373 | CORE_ADDR addr = 0; | |
7374 | CORE_ADDR gp = 0; | |
7375 | int status = 0; | |
7376 | int i; | |
7377 | ||
7378 | for (i = 0; | |
7379 | status == 0 && target_pc == 0 && i < 20; | |
7380 | i++, pc += MIPS_INSN32_SIZE) | |
7381 | { | |
4cc0665f | 7382 | ULONGEST inst = mips_fetch_instruction (gdbarch, ISA_MIPS, pc, NULL); |
14132e89 MR |
7383 | CORE_ADDR imm; |
7384 | int rt; | |
7385 | int rs; | |
7386 | int rd; | |
7387 | ||
7388 | switch (itype_op (inst)) | |
7389 | { | |
7390 | case 0: /* SPECIAL */ | |
7391 | switch (rtype_funct (inst)) | |
7392 | { | |
7393 | case 8: /* JR */ | |
7394 | case 9: /* JALR */ | |
7395 | rs = rtype_rs (inst); | |
7396 | if (rs == MIPS_GP_REGNUM) | |
7397 | target_pc = gp; /* Hmm... */ | |
7398 | else if (rs == addrreg) | |
7399 | target_pc = addr; | |
7400 | break; | |
7401 | ||
7402 | case 0x21: /* ADDU */ | |
7403 | rt = rtype_rt (inst); | |
7404 | rs = rtype_rs (inst); | |
7405 | rd = rtype_rd (inst); | |
7406 | if (rd == MIPS_GP_REGNUM | |
7407 | && ((rs == MIPS_GP_REGNUM && rt == MIPS_T9_REGNUM) | |
7408 | || (rs == MIPS_T9_REGNUM && rt == MIPS_GP_REGNUM))) | |
7409 | gp += start_pc; | |
7410 | break; | |
7411 | } | |
7412 | break; | |
7413 | ||
7414 | case 2: /* J */ | |
7415 | case 3: /* JAL */ | |
7416 | target_pc = jtype_target (inst) << 2; | |
7417 | target_pc += ((pc + 4) & ~(CORE_ADDR) 0x0fffffff); | |
7418 | break; | |
7419 | ||
7420 | case 9: /* ADDIU */ | |
7421 | rt = itype_rt (inst); | |
7422 | rs = itype_rs (inst); | |
7423 | if (rt == rs) | |
7424 | { | |
7425 | imm = (itype_immediate (inst) ^ 0x8000) - 0x8000; | |
7426 | if (rt == MIPS_GP_REGNUM) | |
7427 | gp += imm; | |
7428 | else if (rt == addrreg) | |
7429 | addr += imm; | |
7430 | } | |
7431 | break; | |
7432 | ||
7433 | case 0xf: /* LUI */ | |
7434 | rt = itype_rt (inst); | |
7435 | imm = ((itype_immediate (inst) ^ 0x8000) - 0x8000) << 16; | |
7436 | if (rt == MIPS_GP_REGNUM) | |
7437 | gp = imm; | |
7438 | else if (rt != MIPS_ZERO_REGNUM) | |
7439 | { | |
7440 | addrreg = rt; | |
7441 | addr = imm; | |
7442 | } | |
7443 | break; | |
7444 | ||
7445 | case 0x23: /* LW */ | |
7446 | rt = itype_rt (inst); | |
7447 | rs = itype_rs (inst); | |
7448 | imm = (itype_immediate (inst) ^ 0x8000) - 0x8000; | |
7449 | if (gp != 0 && rs == MIPS_GP_REGNUM) | |
7450 | { | |
7451 | gdb_byte buf[4]; | |
7452 | ||
7453 | memset (buf, 0, sizeof (buf)); | |
7454 | status = target_read_memory (gp + imm, buf, sizeof (buf)); | |
7455 | addrreg = rt; | |
7456 | addr = extract_signed_integer (buf, sizeof (buf), byte_order); | |
7457 | } | |
7458 | break; | |
7459 | } | |
7460 | } | |
7461 | ||
7462 | return target_pc; | |
7463 | } | |
7464 | ||
7465 | /* If PC is in a MIPS16 call or return stub, return the address of the | |
7466 | target PC, which is either the callee or the caller. There are several | |
c906108c SS |
7467 | cases which must be handled: |
7468 | ||
14132e89 MR |
7469 | * If the PC is in __mips16_ret_{d,s}{f,c}, this is a return stub |
7470 | and the target PC is in $31 ($ra). | |
c906108c | 7471 | * If the PC is in __mips16_call_stub_{1..10}, this is a call stub |
14132e89 MR |
7472 | and the target PC is in $2. |
7473 | * If the PC at the start of __mips16_call_stub_{s,d}{f,c}_{0..10}, | |
7474 | i.e. before the JALR instruction, this is effectively a call stub | |
7475 | and the target PC is in $2. Otherwise this is effectively | |
7476 | a return stub and the target PC is in $18. | |
7477 | * If the PC is at the start of __call_stub_fp_*, i.e. before the | |
7478 | JAL or JALR instruction, this is effectively a call stub and the | |
7479 | target PC is buried in the instruction stream. Otherwise this | |
7480 | is effectively a return stub and the target PC is in $18. | |
7481 | * If the PC is in __call_stub_* or in __fn_stub_*, this is a call | |
7482 | stub and the target PC is buried in the instruction stream. | |
7483 | ||
7484 | See the source code for the stubs in gcc/config/mips/mips16.S, or the | |
7485 | stub builder in gcc/config/mips/mips.c (mips16_build_call_stub) for the | |
e7d6a6d2 | 7486 | gory details. */ |
c906108c | 7487 | |
757a7cc6 | 7488 | static CORE_ADDR |
db5f024e | 7489 | mips_skip_mips16_trampoline_code (struct frame_info *frame, CORE_ADDR pc) |
c906108c | 7490 | { |
e17a4113 | 7491 | struct gdbarch *gdbarch = get_frame_arch (frame); |
c906108c | 7492 | CORE_ADDR start_addr; |
14132e89 MR |
7493 | const char *name; |
7494 | size_t prefixlen; | |
c906108c SS |
7495 | |
7496 | /* Find the starting address and name of the function containing the PC. */ | |
7497 | if (find_pc_partial_function (pc, &name, &start_addr, NULL) == 0) | |
7498 | return 0; | |
7499 | ||
14132e89 MR |
7500 | /* If the PC is in __mips16_ret_{d,s}{f,c}, this is a return stub |
7501 | and the target PC is in $31 ($ra). */ | |
7502 | prefixlen = strlen (mips_str_mips16_ret_stub); | |
7503 | if (strncmp (name, mips_str_mips16_ret_stub, prefixlen) == 0 | |
7504 | && mips_is_stub_mode (name + prefixlen) | |
7505 | && name[prefixlen + 2] == '\0') | |
7506 | return get_frame_register_signed | |
7507 | (frame, gdbarch_num_regs (gdbarch) + MIPS_RA_REGNUM); | |
7508 | ||
7509 | /* If the PC is in __mips16_call_stub_*, this is one of the call | |
7510 | call/return stubs. */ | |
7511 | prefixlen = strlen (mips_str_mips16_call_stub); | |
7512 | if (strncmp (name, mips_str_mips16_call_stub, prefixlen) == 0) | |
c906108c SS |
7513 | { |
7514 | /* If the PC is in __mips16_call_stub_{1..10}, this is a call stub | |
7515 | and the target PC is in $2. */ | |
14132e89 MR |
7516 | if (mips_is_stub_suffix (name + prefixlen, 0)) |
7517 | return get_frame_register_signed | |
7518 | (frame, gdbarch_num_regs (gdbarch) + MIPS_V0_REGNUM); | |
c906108c | 7519 | |
14132e89 MR |
7520 | /* If the PC at the start of __mips16_call_stub_{s,d}{f,c}_{0..10}, |
7521 | i.e. before the JALR instruction, this is effectively a call stub | |
b021a221 | 7522 | and the target PC is in $2. Otherwise this is effectively |
c5aa993b | 7523 | a return stub and the target PC is in $18. */ |
14132e89 MR |
7524 | else if (mips_is_stub_mode (name + prefixlen) |
7525 | && name[prefixlen + 2] == '_' | |
7526 | && mips_is_stub_suffix (name + prefixlen + 3, 0)) | |
c906108c SS |
7527 | { |
7528 | if (pc == start_addr) | |
14132e89 MR |
7529 | /* This is the 'call' part of a call stub. The return |
7530 | address is in $2. */ | |
7531 | return get_frame_register_signed | |
7532 | (frame, gdbarch_num_regs (gdbarch) + MIPS_V0_REGNUM); | |
c906108c SS |
7533 | else |
7534 | /* This is the 'return' part of a call stub. The return | |
14132e89 MR |
7535 | address is in $18. */ |
7536 | return get_frame_register_signed | |
7537 | (frame, gdbarch_num_regs (gdbarch) + MIPS_S2_REGNUM); | |
c906108c | 7538 | } |
14132e89 MR |
7539 | else |
7540 | return 0; /* Not a stub. */ | |
7541 | } | |
7542 | ||
7543 | /* If the PC is in __call_stub_* or __fn_stub*, this is one of the | |
7544 | compiler-generated call or call/return stubs. */ | |
7545 | if (strncmp (name, mips_str_fn_stub, strlen (mips_str_fn_stub)) == 0 | |
7546 | || strncmp (name, mips_str_call_stub, strlen (mips_str_call_stub)) == 0) | |
7547 | { | |
7548 | if (pc == start_addr) | |
7549 | /* This is the 'call' part of a call stub. Call this helper | |
7550 | to scan through this code for interesting instructions | |
7551 | and determine the final PC. */ | |
7552 | return mips_get_mips16_fn_stub_pc (frame, pc); | |
7553 | else | |
7554 | /* This is the 'return' part of a call stub. The return address | |
7555 | is in $18. */ | |
7556 | return get_frame_register_signed | |
7557 | (frame, gdbarch_num_regs (gdbarch) + MIPS_S2_REGNUM); | |
c906108c | 7558 | } |
14132e89 MR |
7559 | |
7560 | return 0; /* Not a stub. */ | |
7561 | } | |
7562 | ||
7563 | /* Return non-zero if the PC is inside a return thunk (aka stub or trampoline). | |
7564 | This implements the IN_SOLIB_RETURN_TRAMPOLINE macro. */ | |
7565 | ||
7566 | static int | |
7567 | mips_in_return_stub (struct gdbarch *gdbarch, CORE_ADDR pc, const char *name) | |
7568 | { | |
7569 | CORE_ADDR start_addr; | |
7570 | size_t prefixlen; | |
7571 | ||
7572 | /* Find the starting address of the function containing the PC. */ | |
7573 | if (find_pc_partial_function (pc, NULL, &start_addr, NULL) == 0) | |
7574 | return 0; | |
7575 | ||
7576 | /* If the PC is in __mips16_call_stub_{s,d}{f,c}_{0..10} but not at | |
7577 | the start, i.e. after the JALR instruction, this is effectively | |
7578 | a return stub. */ | |
7579 | prefixlen = strlen (mips_str_mips16_call_stub); | |
7580 | if (pc != start_addr | |
7581 | && strncmp (name, mips_str_mips16_call_stub, prefixlen) == 0 | |
7582 | && mips_is_stub_mode (name + prefixlen) | |
7583 | && name[prefixlen + 2] == '_' | |
7584 | && mips_is_stub_suffix (name + prefixlen + 3, 1)) | |
7585 | return 1; | |
7586 | ||
7587 | /* If the PC is in __call_stub_fp_* but not at the start, i.e. after | |
7588 | the JAL or JALR instruction, this is effectively a return stub. */ | |
7589 | prefixlen = strlen (mips_str_call_fp_stub); | |
7590 | if (pc != start_addr | |
7591 | && strncmp (name, mips_str_call_fp_stub, prefixlen) == 0) | |
7592 | return 1; | |
7593 | ||
7594 | /* Consume the .pic. prefix of any PIC stub, this function must return | |
7595 | true when the PC is in a PIC stub of a __mips16_ret_{d,s}{f,c} stub | |
7596 | or the call stub path will trigger in handle_inferior_event causing | |
7597 | it to go astray. */ | |
7598 | prefixlen = strlen (mips_str_pic); | |
7599 | if (strncmp (name, mips_str_pic, prefixlen) == 0) | |
7600 | name += prefixlen; | |
7601 | ||
7602 | /* If the PC is in __mips16_ret_{d,s}{f,c}, this is a return stub. */ | |
7603 | prefixlen = strlen (mips_str_mips16_ret_stub); | |
7604 | if (strncmp (name, mips_str_mips16_ret_stub, prefixlen) == 0 | |
7605 | && mips_is_stub_mode (name + prefixlen) | |
7606 | && name[prefixlen + 2] == '\0') | |
7607 | return 1; | |
7608 | ||
7609 | return 0; /* Not a stub. */ | |
c906108c SS |
7610 | } |
7611 | ||
db5f024e DJ |
7612 | /* If the current PC is the start of a non-PIC-to-PIC stub, return the |
7613 | PC of the stub target. The stub just loads $t9 and jumps to it, | |
7614 | so that $t9 has the correct value at function entry. */ | |
7615 | ||
7616 | static CORE_ADDR | |
7617 | mips_skip_pic_trampoline_code (struct frame_info *frame, CORE_ADDR pc) | |
7618 | { | |
e17a4113 UW |
7619 | struct gdbarch *gdbarch = get_frame_arch (frame); |
7620 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); | |
7cbd4a93 | 7621 | struct bound_minimal_symbol msym; |
db5f024e DJ |
7622 | int i; |
7623 | gdb_byte stub_code[16]; | |
7624 | int32_t stub_words[4]; | |
7625 | ||
7626 | /* The stub for foo is named ".pic.foo", and is either two | |
7627 | instructions inserted before foo or a three instruction sequence | |
7628 | which jumps to foo. */ | |
7629 | msym = lookup_minimal_symbol_by_pc (pc); | |
7cbd4a93 TT |
7630 | if (msym.minsym == NULL |
7631 | || SYMBOL_VALUE_ADDRESS (msym.minsym) != pc | |
7632 | || SYMBOL_LINKAGE_NAME (msym.minsym) == NULL | |
7633 | || strncmp (SYMBOL_LINKAGE_NAME (msym.minsym), ".pic.", 5) != 0) | |
db5f024e DJ |
7634 | return 0; |
7635 | ||
7636 | /* A two-instruction header. */ | |
7cbd4a93 | 7637 | if (MSYMBOL_SIZE (msym.minsym) == 8) |
db5f024e DJ |
7638 | return pc + 8; |
7639 | ||
7640 | /* A three-instruction (plus delay slot) trampoline. */ | |
7cbd4a93 | 7641 | if (MSYMBOL_SIZE (msym.minsym) == 16) |
db5f024e DJ |
7642 | { |
7643 | if (target_read_memory (pc, stub_code, 16) != 0) | |
7644 | return 0; | |
7645 | for (i = 0; i < 4; i++) | |
e17a4113 UW |
7646 | stub_words[i] = extract_unsigned_integer (stub_code + i * 4, |
7647 | 4, byte_order); | |
db5f024e DJ |
7648 | |
7649 | /* A stub contains these instructions: | |
7650 | lui t9, %hi(target) | |
7651 | j target | |
7652 | addiu t9, t9, %lo(target) | |
7653 | nop | |
7654 | ||
7655 | This works even for N64, since stubs are only generated with | |
7656 | -msym32. */ | |
7657 | if ((stub_words[0] & 0xffff0000U) == 0x3c190000 | |
7658 | && (stub_words[1] & 0xfc000000U) == 0x08000000 | |
7659 | && (stub_words[2] & 0xffff0000U) == 0x27390000 | |
7660 | && stub_words[3] == 0x00000000) | |
34b192ce MR |
7661 | return ((((stub_words[0] & 0x0000ffff) << 16) |
7662 | + (stub_words[2] & 0x0000ffff)) ^ 0x8000) - 0x8000; | |
db5f024e DJ |
7663 | } |
7664 | ||
7665 | /* Not a recognized stub. */ | |
7666 | return 0; | |
7667 | } | |
7668 | ||
7669 | static CORE_ADDR | |
7670 | mips_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc) | |
7671 | { | |
14132e89 | 7672 | CORE_ADDR requested_pc = pc; |
db5f024e | 7673 | CORE_ADDR target_pc; |
14132e89 MR |
7674 | CORE_ADDR new_pc; |
7675 | ||
7676 | do | |
7677 | { | |
7678 | target_pc = pc; | |
db5f024e | 7679 | |
14132e89 MR |
7680 | new_pc = mips_skip_mips16_trampoline_code (frame, pc); |
7681 | if (new_pc) | |
7682 | { | |
7683 | pc = new_pc; | |
4cc0665f MR |
7684 | if (is_compact_addr (pc)) |
7685 | pc = unmake_compact_addr (pc); | |
14132e89 | 7686 | } |
db5f024e | 7687 | |
14132e89 MR |
7688 | new_pc = find_solib_trampoline_target (frame, pc); |
7689 | if (new_pc) | |
7690 | { | |
7691 | pc = new_pc; | |
4cc0665f MR |
7692 | if (is_compact_addr (pc)) |
7693 | pc = unmake_compact_addr (pc); | |
14132e89 | 7694 | } |
db5f024e | 7695 | |
14132e89 MR |
7696 | new_pc = mips_skip_pic_trampoline_code (frame, pc); |
7697 | if (new_pc) | |
7698 | { | |
7699 | pc = new_pc; | |
4cc0665f MR |
7700 | if (is_compact_addr (pc)) |
7701 | pc = unmake_compact_addr (pc); | |
14132e89 MR |
7702 | } |
7703 | } | |
7704 | while (pc != target_pc); | |
db5f024e | 7705 | |
14132e89 | 7706 | return pc != requested_pc ? pc : 0; |
db5f024e DJ |
7707 | } |
7708 | ||
a4b8ebc8 | 7709 | /* Convert a dbx stab register number (from `r' declaration) to a GDB |
f57d151a | 7710 | [1 * gdbarch_num_regs .. 2 * gdbarch_num_regs) REGNUM. */ |
88c72b7d AC |
7711 | |
7712 | static int | |
d3f73121 | 7713 | mips_stab_reg_to_regnum (struct gdbarch *gdbarch, int num) |
88c72b7d | 7714 | { |
a4b8ebc8 | 7715 | int regnum; |
2f38ef89 | 7716 | if (num >= 0 && num < 32) |
a4b8ebc8 | 7717 | regnum = num; |
2f38ef89 | 7718 | else if (num >= 38 && num < 70) |
d3f73121 | 7719 | regnum = num + mips_regnum (gdbarch)->fp0 - 38; |
040b99fd | 7720 | else if (num == 70) |
d3f73121 | 7721 | regnum = mips_regnum (gdbarch)->hi; |
040b99fd | 7722 | else if (num == 71) |
d3f73121 | 7723 | regnum = mips_regnum (gdbarch)->lo; |
1faeff08 MR |
7724 | else if (mips_regnum (gdbarch)->dspacc != -1 && num >= 72 && num < 78) |
7725 | regnum = num + mips_regnum (gdbarch)->dspacc - 72; | |
2f38ef89 | 7726 | else |
a4b8ebc8 AC |
7727 | /* This will hopefully (eventually) provoke a warning. Should |
7728 | we be calling complaint() here? */ | |
d3f73121 MD |
7729 | return gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch); |
7730 | return gdbarch_num_regs (gdbarch) + regnum; | |
88c72b7d AC |
7731 | } |
7732 | ||
2f38ef89 | 7733 | |
a4b8ebc8 | 7734 | /* Convert a dwarf, dwarf2, or ecoff register number to a GDB [1 * |
f57d151a | 7735 | gdbarch_num_regs .. 2 * gdbarch_num_regs) REGNUM. */ |
88c72b7d AC |
7736 | |
7737 | static int | |
d3f73121 | 7738 | mips_dwarf_dwarf2_ecoff_reg_to_regnum (struct gdbarch *gdbarch, int num) |
88c72b7d | 7739 | { |
a4b8ebc8 | 7740 | int regnum; |
2f38ef89 | 7741 | if (num >= 0 && num < 32) |
a4b8ebc8 | 7742 | regnum = num; |
2f38ef89 | 7743 | else if (num >= 32 && num < 64) |
d3f73121 | 7744 | regnum = num + mips_regnum (gdbarch)->fp0 - 32; |
040b99fd | 7745 | else if (num == 64) |
d3f73121 | 7746 | regnum = mips_regnum (gdbarch)->hi; |
040b99fd | 7747 | else if (num == 65) |
d3f73121 | 7748 | regnum = mips_regnum (gdbarch)->lo; |
1faeff08 MR |
7749 | else if (mips_regnum (gdbarch)->dspacc != -1 && num >= 66 && num < 72) |
7750 | regnum = num + mips_regnum (gdbarch)->dspacc - 66; | |
2f38ef89 | 7751 | else |
a4b8ebc8 AC |
7752 | /* This will hopefully (eventually) provoke a warning. Should we |
7753 | be calling complaint() here? */ | |
d3f73121 MD |
7754 | return gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch); |
7755 | return gdbarch_num_regs (gdbarch) + regnum; | |
a4b8ebc8 AC |
7756 | } |
7757 | ||
7758 | static int | |
e7faf938 | 7759 | mips_register_sim_regno (struct gdbarch *gdbarch, int regnum) |
a4b8ebc8 AC |
7760 | { |
7761 | /* Only makes sense to supply raw registers. */ | |
e7faf938 | 7762 | gdb_assert (regnum >= 0 && regnum < gdbarch_num_regs (gdbarch)); |
a4b8ebc8 AC |
7763 | /* FIXME: cagney/2002-05-13: Need to look at the pseudo register to |
7764 | decide if it is valid. Should instead define a standard sim/gdb | |
7765 | register numbering scheme. */ | |
e7faf938 MD |
7766 | if (gdbarch_register_name (gdbarch, |
7767 | gdbarch_num_regs (gdbarch) + regnum) != NULL | |
7768 | && gdbarch_register_name (gdbarch, | |
025bb325 MS |
7769 | gdbarch_num_regs (gdbarch) |
7770 | + regnum)[0] != '\0') | |
a4b8ebc8 AC |
7771 | return regnum; |
7772 | else | |
6d82d43b | 7773 | return LEGACY_SIM_REGNO_IGNORE; |
88c72b7d AC |
7774 | } |
7775 | ||
2f38ef89 | 7776 | |
4844f454 CV |
7777 | /* Convert an integer into an address. Extracting the value signed |
7778 | guarantees a correctly sign extended address. */ | |
fc0c74b1 AC |
7779 | |
7780 | static CORE_ADDR | |
79dd2d24 | 7781 | mips_integer_to_address (struct gdbarch *gdbarch, |
870cd05e | 7782 | struct type *type, const gdb_byte *buf) |
fc0c74b1 | 7783 | { |
e17a4113 UW |
7784 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
7785 | return extract_signed_integer (buf, TYPE_LENGTH (type), byte_order); | |
fc0c74b1 AC |
7786 | } |
7787 | ||
82e91389 DJ |
7788 | /* Dummy virtual frame pointer method. This is no more or less accurate |
7789 | than most other architectures; we just need to be explicit about it, | |
7790 | because the pseudo-register gdbarch_sp_regnum will otherwise lead to | |
7791 | an assertion failure. */ | |
7792 | ||
7793 | static void | |
a54fba4c MD |
7794 | mips_virtual_frame_pointer (struct gdbarch *gdbarch, |
7795 | CORE_ADDR pc, int *reg, LONGEST *offset) | |
82e91389 DJ |
7796 | { |
7797 | *reg = MIPS_SP_REGNUM; | |
7798 | *offset = 0; | |
7799 | } | |
7800 | ||
caaa3122 DJ |
7801 | static void |
7802 | mips_find_abi_section (bfd *abfd, asection *sect, void *obj) | |
7803 | { | |
7804 | enum mips_abi *abip = (enum mips_abi *) obj; | |
7805 | const char *name = bfd_get_section_name (abfd, sect); | |
7806 | ||
7807 | if (*abip != MIPS_ABI_UNKNOWN) | |
7808 | return; | |
7809 | ||
7810 | if (strncmp (name, ".mdebug.", 8) != 0) | |
7811 | return; | |
7812 | ||
7813 | if (strcmp (name, ".mdebug.abi32") == 0) | |
7814 | *abip = MIPS_ABI_O32; | |
7815 | else if (strcmp (name, ".mdebug.abiN32") == 0) | |
7816 | *abip = MIPS_ABI_N32; | |
62a49b2c | 7817 | else if (strcmp (name, ".mdebug.abi64") == 0) |
e3bddbfa | 7818 | *abip = MIPS_ABI_N64; |
caaa3122 DJ |
7819 | else if (strcmp (name, ".mdebug.abiO64") == 0) |
7820 | *abip = MIPS_ABI_O64; | |
7821 | else if (strcmp (name, ".mdebug.eabi32") == 0) | |
7822 | *abip = MIPS_ABI_EABI32; | |
7823 | else if (strcmp (name, ".mdebug.eabi64") == 0) | |
7824 | *abip = MIPS_ABI_EABI64; | |
7825 | else | |
8a3fe4f8 | 7826 | warning (_("unsupported ABI %s."), name + 8); |
caaa3122 DJ |
7827 | } |
7828 | ||
22e47e37 FF |
7829 | static void |
7830 | mips_find_long_section (bfd *abfd, asection *sect, void *obj) | |
7831 | { | |
7832 | int *lbp = (int *) obj; | |
7833 | const char *name = bfd_get_section_name (abfd, sect); | |
7834 | ||
7835 | if (strncmp (name, ".gcc_compiled_long32", 20) == 0) | |
7836 | *lbp = 32; | |
7837 | else if (strncmp (name, ".gcc_compiled_long64", 20) == 0) | |
7838 | *lbp = 64; | |
7839 | else if (strncmp (name, ".gcc_compiled_long", 18) == 0) | |
7840 | warning (_("unrecognized .gcc_compiled_longXX")); | |
7841 | } | |
7842 | ||
2e4ebe70 DJ |
7843 | static enum mips_abi |
7844 | global_mips_abi (void) | |
7845 | { | |
7846 | int i; | |
7847 | ||
7848 | for (i = 0; mips_abi_strings[i] != NULL; i++) | |
7849 | if (mips_abi_strings[i] == mips_abi_string) | |
7850 | return (enum mips_abi) i; | |
7851 | ||
e2e0b3e5 | 7852 | internal_error (__FILE__, __LINE__, _("unknown ABI string")); |
2e4ebe70 DJ |
7853 | } |
7854 | ||
4cc0665f MR |
7855 | /* Return the default compressed instruction set, either of MIPS16 |
7856 | or microMIPS, selected when none could have been determined from | |
7857 | the ELF header of the binary being executed (or no binary has been | |
7858 | selected. */ | |
7859 | ||
7860 | static enum mips_isa | |
7861 | global_mips_compression (void) | |
7862 | { | |
7863 | int i; | |
7864 | ||
7865 | for (i = 0; mips_compression_strings[i] != NULL; i++) | |
7866 | if (mips_compression_strings[i] == mips_compression_string) | |
7867 | return (enum mips_isa) i; | |
7868 | ||
7869 | internal_error (__FILE__, __LINE__, _("unknown compressed ISA string")); | |
7870 | } | |
7871 | ||
29709017 DJ |
7872 | static void |
7873 | mips_register_g_packet_guesses (struct gdbarch *gdbarch) | |
7874 | { | |
29709017 DJ |
7875 | /* If the size matches the set of 32-bit or 64-bit integer registers, |
7876 | assume that's what we've got. */ | |
4eb0ad19 DJ |
7877 | register_remote_g_packet_guess (gdbarch, 38 * 4, mips_tdesc_gp32); |
7878 | register_remote_g_packet_guess (gdbarch, 38 * 8, mips_tdesc_gp64); | |
29709017 DJ |
7879 | |
7880 | /* If the size matches the full set of registers GDB traditionally | |
7881 | knows about, including floating point, for either 32-bit or | |
7882 | 64-bit, assume that's what we've got. */ | |
4eb0ad19 DJ |
7883 | register_remote_g_packet_guess (gdbarch, 90 * 4, mips_tdesc_gp32); |
7884 | register_remote_g_packet_guess (gdbarch, 90 * 8, mips_tdesc_gp64); | |
29709017 DJ |
7885 | |
7886 | /* Otherwise we don't have a useful guess. */ | |
7887 | } | |
7888 | ||
f8b73d13 DJ |
7889 | static struct value * |
7890 | value_of_mips_user_reg (struct frame_info *frame, const void *baton) | |
7891 | { | |
7892 | const int *reg_p = baton; | |
7893 | return value_of_register (*reg_p, frame); | |
7894 | } | |
7895 | ||
c2d11a7d | 7896 | static struct gdbarch * |
6d82d43b | 7897 | mips_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) |
c2d11a7d | 7898 | { |
c2d11a7d JM |
7899 | struct gdbarch *gdbarch; |
7900 | struct gdbarch_tdep *tdep; | |
7901 | int elf_flags; | |
2e4ebe70 | 7902 | enum mips_abi mips_abi, found_abi, wanted_abi; |
f8b73d13 | 7903 | int i, num_regs; |
8d5838b5 | 7904 | enum mips_fpu_type fpu_type; |
f8b73d13 | 7905 | struct tdesc_arch_data *tdesc_data = NULL; |
609ca2b9 | 7906 | int elf_fpu_type = 0; |
1faeff08 MR |
7907 | const char **reg_names; |
7908 | struct mips_regnum mips_regnum, *regnum; | |
4cc0665f | 7909 | enum mips_isa mips_isa; |
1faeff08 MR |
7910 | int dspacc; |
7911 | int dspctl; | |
7912 | ||
7913 | /* Fill in the OS dependent register numbers and names. */ | |
7914 | if (info.osabi == GDB_OSABI_IRIX) | |
7915 | { | |
7916 | mips_regnum.fp0 = 32; | |
7917 | mips_regnum.pc = 64; | |
7918 | mips_regnum.cause = 65; | |
7919 | mips_regnum.badvaddr = 66; | |
7920 | mips_regnum.hi = 67; | |
7921 | mips_regnum.lo = 68; | |
7922 | mips_regnum.fp_control_status = 69; | |
7923 | mips_regnum.fp_implementation_revision = 70; | |
7924 | mips_regnum.dspacc = dspacc = -1; | |
7925 | mips_regnum.dspctl = dspctl = -1; | |
7926 | num_regs = 71; | |
7927 | reg_names = mips_irix_reg_names; | |
7928 | } | |
7929 | else if (info.osabi == GDB_OSABI_LINUX) | |
7930 | { | |
7931 | mips_regnum.fp0 = 38; | |
7932 | mips_regnum.pc = 37; | |
7933 | mips_regnum.cause = 36; | |
7934 | mips_regnum.badvaddr = 35; | |
7935 | mips_regnum.hi = 34; | |
7936 | mips_regnum.lo = 33; | |
7937 | mips_regnum.fp_control_status = 70; | |
7938 | mips_regnum.fp_implementation_revision = 71; | |
7939 | mips_regnum.dspacc = -1; | |
7940 | mips_regnum.dspctl = -1; | |
7941 | dspacc = 72; | |
7942 | dspctl = 78; | |
7943 | num_regs = 79; | |
7944 | reg_names = mips_linux_reg_names; | |
7945 | } | |
7946 | else | |
7947 | { | |
7948 | mips_regnum.lo = MIPS_EMBED_LO_REGNUM; | |
7949 | mips_regnum.hi = MIPS_EMBED_HI_REGNUM; | |
7950 | mips_regnum.badvaddr = MIPS_EMBED_BADVADDR_REGNUM; | |
7951 | mips_regnum.cause = MIPS_EMBED_CAUSE_REGNUM; | |
7952 | mips_regnum.pc = MIPS_EMBED_PC_REGNUM; | |
7953 | mips_regnum.fp0 = MIPS_EMBED_FP0_REGNUM; | |
7954 | mips_regnum.fp_control_status = 70; | |
7955 | mips_regnum.fp_implementation_revision = 71; | |
7956 | mips_regnum.dspacc = dspacc = -1; | |
7957 | mips_regnum.dspctl = dspctl = -1; | |
7958 | num_regs = MIPS_LAST_EMBED_REGNUM + 1; | |
7959 | if (info.bfd_arch_info != NULL | |
7960 | && info.bfd_arch_info->mach == bfd_mach_mips3900) | |
7961 | reg_names = mips_tx39_reg_names; | |
7962 | else | |
7963 | reg_names = mips_generic_reg_names; | |
7964 | } | |
f8b73d13 DJ |
7965 | |
7966 | /* Check any target description for validity. */ | |
7967 | if (tdesc_has_registers (info.target_desc)) | |
7968 | { | |
7969 | static const char *const mips_gprs[] = { | |
7970 | "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", | |
7971 | "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", | |
7972 | "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", | |
7973 | "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31" | |
7974 | }; | |
7975 | static const char *const mips_fprs[] = { | |
7976 | "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", | |
7977 | "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", | |
7978 | "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23", | |
7979 | "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", | |
7980 | }; | |
7981 | ||
7982 | const struct tdesc_feature *feature; | |
7983 | int valid_p; | |
7984 | ||
7985 | feature = tdesc_find_feature (info.target_desc, | |
7986 | "org.gnu.gdb.mips.cpu"); | |
7987 | if (feature == NULL) | |
7988 | return NULL; | |
7989 | ||
7990 | tdesc_data = tdesc_data_alloc (); | |
7991 | ||
7992 | valid_p = 1; | |
7993 | for (i = MIPS_ZERO_REGNUM; i <= MIPS_RA_REGNUM; i++) | |
7994 | valid_p &= tdesc_numbered_register (feature, tdesc_data, i, | |
7995 | mips_gprs[i]); | |
7996 | ||
7997 | ||
7998 | valid_p &= tdesc_numbered_register (feature, tdesc_data, | |
1faeff08 | 7999 | mips_regnum.lo, "lo"); |
f8b73d13 | 8000 | valid_p &= tdesc_numbered_register (feature, tdesc_data, |
1faeff08 | 8001 | mips_regnum.hi, "hi"); |
f8b73d13 | 8002 | valid_p &= tdesc_numbered_register (feature, tdesc_data, |
1faeff08 | 8003 | mips_regnum.pc, "pc"); |
f8b73d13 DJ |
8004 | |
8005 | if (!valid_p) | |
8006 | { | |
8007 | tdesc_data_cleanup (tdesc_data); | |
8008 | return NULL; | |
8009 | } | |
8010 | ||
8011 | feature = tdesc_find_feature (info.target_desc, | |
8012 | "org.gnu.gdb.mips.cp0"); | |
8013 | if (feature == NULL) | |
8014 | { | |
8015 | tdesc_data_cleanup (tdesc_data); | |
8016 | return NULL; | |
8017 | } | |
8018 | ||
8019 | valid_p = 1; | |
8020 | valid_p &= tdesc_numbered_register (feature, tdesc_data, | |
1faeff08 | 8021 | mips_regnum.badvaddr, "badvaddr"); |
f8b73d13 DJ |
8022 | valid_p &= tdesc_numbered_register (feature, tdesc_data, |
8023 | MIPS_PS_REGNUM, "status"); | |
8024 | valid_p &= tdesc_numbered_register (feature, tdesc_data, | |
1faeff08 | 8025 | mips_regnum.cause, "cause"); |
f8b73d13 DJ |
8026 | |
8027 | if (!valid_p) | |
8028 | { | |
8029 | tdesc_data_cleanup (tdesc_data); | |
8030 | return NULL; | |
8031 | } | |
8032 | ||
8033 | /* FIXME drow/2007-05-17: The FPU should be optional. The MIPS | |
8034 | backend is not prepared for that, though. */ | |
8035 | feature = tdesc_find_feature (info.target_desc, | |
8036 | "org.gnu.gdb.mips.fpu"); | |
8037 | if (feature == NULL) | |
8038 | { | |
8039 | tdesc_data_cleanup (tdesc_data); | |
8040 | return NULL; | |
8041 | } | |
8042 | ||
8043 | valid_p = 1; | |
8044 | for (i = 0; i < 32; i++) | |
8045 | valid_p &= tdesc_numbered_register (feature, tdesc_data, | |
1faeff08 | 8046 | i + mips_regnum.fp0, mips_fprs[i]); |
f8b73d13 DJ |
8047 | |
8048 | valid_p &= tdesc_numbered_register (feature, tdesc_data, | |
1faeff08 MR |
8049 | mips_regnum.fp_control_status, |
8050 | "fcsr"); | |
8051 | valid_p | |
8052 | &= tdesc_numbered_register (feature, tdesc_data, | |
8053 | mips_regnum.fp_implementation_revision, | |
8054 | "fir"); | |
f8b73d13 DJ |
8055 | |
8056 | if (!valid_p) | |
8057 | { | |
8058 | tdesc_data_cleanup (tdesc_data); | |
8059 | return NULL; | |
8060 | } | |
8061 | ||
1faeff08 MR |
8062 | if (dspacc >= 0) |
8063 | { | |
8064 | feature = tdesc_find_feature (info.target_desc, | |
8065 | "org.gnu.gdb.mips.dsp"); | |
8066 | /* The DSP registers are optional; it's OK if they are absent. */ | |
8067 | if (feature != NULL) | |
8068 | { | |
8069 | i = 0; | |
8070 | valid_p = 1; | |
8071 | valid_p &= tdesc_numbered_register (feature, tdesc_data, | |
8072 | dspacc + i++, "hi1"); | |
8073 | valid_p &= tdesc_numbered_register (feature, tdesc_data, | |
8074 | dspacc + i++, "lo1"); | |
8075 | valid_p &= tdesc_numbered_register (feature, tdesc_data, | |
8076 | dspacc + i++, "hi2"); | |
8077 | valid_p &= tdesc_numbered_register (feature, tdesc_data, | |
8078 | dspacc + i++, "lo2"); | |
8079 | valid_p &= tdesc_numbered_register (feature, tdesc_data, | |
8080 | dspacc + i++, "hi3"); | |
8081 | valid_p &= tdesc_numbered_register (feature, tdesc_data, | |
8082 | dspacc + i++, "lo3"); | |
8083 | ||
8084 | valid_p &= tdesc_numbered_register (feature, tdesc_data, | |
8085 | dspctl, "dspctl"); | |
8086 | ||
8087 | if (!valid_p) | |
8088 | { | |
8089 | tdesc_data_cleanup (tdesc_data); | |
8090 | return NULL; | |
8091 | } | |
8092 | ||
8093 | mips_regnum.dspacc = dspacc; | |
8094 | mips_regnum.dspctl = dspctl; | |
8095 | } | |
8096 | } | |
8097 | ||
f8b73d13 DJ |
8098 | /* It would be nice to detect an attempt to use a 64-bit ABI |
8099 | when only 32-bit registers are provided. */ | |
1faeff08 | 8100 | reg_names = NULL; |
f8b73d13 | 8101 | } |
c2d11a7d | 8102 | |
ec03c1ac AC |
8103 | /* First of all, extract the elf_flags, if available. */ |
8104 | if (info.abfd && bfd_get_flavour (info.abfd) == bfd_target_elf_flavour) | |
8105 | elf_flags = elf_elfheader (info.abfd)->e_flags; | |
6214a8a1 AC |
8106 | else if (arches != NULL) |
8107 | elf_flags = gdbarch_tdep (arches->gdbarch)->elf_flags; | |
ec03c1ac AC |
8108 | else |
8109 | elf_flags = 0; | |
8110 | if (gdbarch_debug) | |
8111 | fprintf_unfiltered (gdb_stdlog, | |
6d82d43b | 8112 | "mips_gdbarch_init: elf_flags = 0x%08x\n", elf_flags); |
c2d11a7d | 8113 | |
102182a9 | 8114 | /* Check ELF_FLAGS to see if it specifies the ABI being used. */ |
0dadbba0 AC |
8115 | switch ((elf_flags & EF_MIPS_ABI)) |
8116 | { | |
8117 | case E_MIPS_ABI_O32: | |
ec03c1ac | 8118 | found_abi = MIPS_ABI_O32; |
0dadbba0 AC |
8119 | break; |
8120 | case E_MIPS_ABI_O64: | |
ec03c1ac | 8121 | found_abi = MIPS_ABI_O64; |
0dadbba0 AC |
8122 | break; |
8123 | case E_MIPS_ABI_EABI32: | |
ec03c1ac | 8124 | found_abi = MIPS_ABI_EABI32; |
0dadbba0 AC |
8125 | break; |
8126 | case E_MIPS_ABI_EABI64: | |
ec03c1ac | 8127 | found_abi = MIPS_ABI_EABI64; |
0dadbba0 AC |
8128 | break; |
8129 | default: | |
acdb74a0 | 8130 | if ((elf_flags & EF_MIPS_ABI2)) |
ec03c1ac | 8131 | found_abi = MIPS_ABI_N32; |
acdb74a0 | 8132 | else |
ec03c1ac | 8133 | found_abi = MIPS_ABI_UNKNOWN; |
0dadbba0 AC |
8134 | break; |
8135 | } | |
acdb74a0 | 8136 | |
caaa3122 | 8137 | /* GCC creates a pseudo-section whose name describes the ABI. */ |
ec03c1ac AC |
8138 | if (found_abi == MIPS_ABI_UNKNOWN && info.abfd != NULL) |
8139 | bfd_map_over_sections (info.abfd, mips_find_abi_section, &found_abi); | |
caaa3122 | 8140 | |
dc305454 | 8141 | /* If we have no useful BFD information, use the ABI from the last |
ec03c1ac AC |
8142 | MIPS architecture (if there is one). */ |
8143 | if (found_abi == MIPS_ABI_UNKNOWN && info.abfd == NULL && arches != NULL) | |
8144 | found_abi = gdbarch_tdep (arches->gdbarch)->found_abi; | |
2e4ebe70 | 8145 | |
32a6503c | 8146 | /* Try the architecture for any hint of the correct ABI. */ |
ec03c1ac | 8147 | if (found_abi == MIPS_ABI_UNKNOWN |
bf64bfd6 AC |
8148 | && info.bfd_arch_info != NULL |
8149 | && info.bfd_arch_info->arch == bfd_arch_mips) | |
8150 | { | |
8151 | switch (info.bfd_arch_info->mach) | |
8152 | { | |
8153 | case bfd_mach_mips3900: | |
ec03c1ac | 8154 | found_abi = MIPS_ABI_EABI32; |
bf64bfd6 AC |
8155 | break; |
8156 | case bfd_mach_mips4100: | |
8157 | case bfd_mach_mips5000: | |
ec03c1ac | 8158 | found_abi = MIPS_ABI_EABI64; |
bf64bfd6 | 8159 | break; |
1d06468c EZ |
8160 | case bfd_mach_mips8000: |
8161 | case bfd_mach_mips10000: | |
32a6503c KB |
8162 | /* On Irix, ELF64 executables use the N64 ABI. The |
8163 | pseudo-sections which describe the ABI aren't present | |
8164 | on IRIX. (Even for executables created by gcc.) */ | |
28d169de KB |
8165 | if (bfd_get_flavour (info.abfd) == bfd_target_elf_flavour |
8166 | && elf_elfheader (info.abfd)->e_ident[EI_CLASS] == ELFCLASS64) | |
ec03c1ac | 8167 | found_abi = MIPS_ABI_N64; |
28d169de | 8168 | else |
ec03c1ac | 8169 | found_abi = MIPS_ABI_N32; |
1d06468c | 8170 | break; |
bf64bfd6 AC |
8171 | } |
8172 | } | |
2e4ebe70 | 8173 | |
26c53e50 DJ |
8174 | /* Default 64-bit objects to N64 instead of O32. */ |
8175 | if (found_abi == MIPS_ABI_UNKNOWN | |
8176 | && info.abfd != NULL | |
8177 | && bfd_get_flavour (info.abfd) == bfd_target_elf_flavour | |
8178 | && elf_elfheader (info.abfd)->e_ident[EI_CLASS] == ELFCLASS64) | |
8179 | found_abi = MIPS_ABI_N64; | |
8180 | ||
ec03c1ac AC |
8181 | if (gdbarch_debug) |
8182 | fprintf_unfiltered (gdb_stdlog, "mips_gdbarch_init: found_abi = %d\n", | |
8183 | found_abi); | |
8184 | ||
8185 | /* What has the user specified from the command line? */ | |
8186 | wanted_abi = global_mips_abi (); | |
8187 | if (gdbarch_debug) | |
8188 | fprintf_unfiltered (gdb_stdlog, "mips_gdbarch_init: wanted_abi = %d\n", | |
8189 | wanted_abi); | |
2e4ebe70 DJ |
8190 | |
8191 | /* Now that we have found what the ABI for this binary would be, | |
8192 | check whether the user is overriding it. */ | |
2e4ebe70 DJ |
8193 | if (wanted_abi != MIPS_ABI_UNKNOWN) |
8194 | mips_abi = wanted_abi; | |
ec03c1ac AC |
8195 | else if (found_abi != MIPS_ABI_UNKNOWN) |
8196 | mips_abi = found_abi; | |
8197 | else | |
8198 | mips_abi = MIPS_ABI_O32; | |
8199 | if (gdbarch_debug) | |
8200 | fprintf_unfiltered (gdb_stdlog, "mips_gdbarch_init: mips_abi = %d\n", | |
8201 | mips_abi); | |
2e4ebe70 | 8202 | |
4cc0665f MR |
8203 | /* Determine the default compressed ISA. */ |
8204 | if ((elf_flags & EF_MIPS_ARCH_ASE_MICROMIPS) != 0 | |
8205 | && (elf_flags & EF_MIPS_ARCH_ASE_M16) == 0) | |
8206 | mips_isa = ISA_MICROMIPS; | |
8207 | else if ((elf_flags & EF_MIPS_ARCH_ASE_M16) != 0 | |
8208 | && (elf_flags & EF_MIPS_ARCH_ASE_MICROMIPS) == 0) | |
8209 | mips_isa = ISA_MIPS16; | |
8210 | else | |
8211 | mips_isa = global_mips_compression (); | |
8212 | mips_compression_string = mips_compression_strings[mips_isa]; | |
8213 | ||
ec03c1ac | 8214 | /* Also used when doing an architecture lookup. */ |
4b9b3959 | 8215 | if (gdbarch_debug) |
ec03c1ac | 8216 | fprintf_unfiltered (gdb_stdlog, |
025bb325 MS |
8217 | "mips_gdbarch_init: " |
8218 | "mips64_transfers_32bit_regs_p = %d\n", | |
ec03c1ac | 8219 | mips64_transfers_32bit_regs_p); |
0dadbba0 | 8220 | |
8d5838b5 | 8221 | /* Determine the MIPS FPU type. */ |
609ca2b9 DJ |
8222 | #ifdef HAVE_ELF |
8223 | if (info.abfd | |
8224 | && bfd_get_flavour (info.abfd) == bfd_target_elf_flavour) | |
8225 | elf_fpu_type = bfd_elf_get_obj_attr_int (info.abfd, OBJ_ATTR_GNU, | |
8226 | Tag_GNU_MIPS_ABI_FP); | |
8227 | #endif /* HAVE_ELF */ | |
8228 | ||
8d5838b5 AC |
8229 | if (!mips_fpu_type_auto) |
8230 | fpu_type = mips_fpu_type; | |
609ca2b9 DJ |
8231 | else if (elf_fpu_type != 0) |
8232 | { | |
8233 | switch (elf_fpu_type) | |
8234 | { | |
8235 | case 1: | |
8236 | fpu_type = MIPS_FPU_DOUBLE; | |
8237 | break; | |
8238 | case 2: | |
8239 | fpu_type = MIPS_FPU_SINGLE; | |
8240 | break; | |
8241 | case 3: | |
8242 | default: | |
8243 | /* Soft float or unknown. */ | |
8244 | fpu_type = MIPS_FPU_NONE; | |
8245 | break; | |
8246 | } | |
8247 | } | |
8d5838b5 AC |
8248 | else if (info.bfd_arch_info != NULL |
8249 | && info.bfd_arch_info->arch == bfd_arch_mips) | |
8250 | switch (info.bfd_arch_info->mach) | |
8251 | { | |
8252 | case bfd_mach_mips3900: | |
8253 | case bfd_mach_mips4100: | |
8254 | case bfd_mach_mips4111: | |
a9d61c86 | 8255 | case bfd_mach_mips4120: |
8d5838b5 AC |
8256 | fpu_type = MIPS_FPU_NONE; |
8257 | break; | |
8258 | case bfd_mach_mips4650: | |
8259 | fpu_type = MIPS_FPU_SINGLE; | |
8260 | break; | |
8261 | default: | |
8262 | fpu_type = MIPS_FPU_DOUBLE; | |
8263 | break; | |
8264 | } | |
8265 | else if (arches != NULL) | |
8266 | fpu_type = gdbarch_tdep (arches->gdbarch)->mips_fpu_type; | |
8267 | else | |
8268 | fpu_type = MIPS_FPU_DOUBLE; | |
8269 | if (gdbarch_debug) | |
8270 | fprintf_unfiltered (gdb_stdlog, | |
6d82d43b | 8271 | "mips_gdbarch_init: fpu_type = %d\n", fpu_type); |
8d5838b5 | 8272 | |
29709017 DJ |
8273 | /* Check for blatant incompatibilities. */ |
8274 | ||
8275 | /* If we have only 32-bit registers, then we can't debug a 64-bit | |
8276 | ABI. */ | |
8277 | if (info.target_desc | |
8278 | && tdesc_property (info.target_desc, PROPERTY_GP32) != NULL | |
8279 | && mips_abi != MIPS_ABI_EABI32 | |
8280 | && mips_abi != MIPS_ABI_O32) | |
f8b73d13 DJ |
8281 | { |
8282 | if (tdesc_data != NULL) | |
8283 | tdesc_data_cleanup (tdesc_data); | |
8284 | return NULL; | |
8285 | } | |
29709017 | 8286 | |
025bb325 | 8287 | /* Try to find a pre-existing architecture. */ |
c2d11a7d JM |
8288 | for (arches = gdbarch_list_lookup_by_info (arches, &info); |
8289 | arches != NULL; | |
8290 | arches = gdbarch_list_lookup_by_info (arches->next, &info)) | |
8291 | { | |
8292 | /* MIPS needs to be pedantic about which ABI the object is | |
102182a9 | 8293 | using. */ |
9103eae0 | 8294 | if (gdbarch_tdep (arches->gdbarch)->elf_flags != elf_flags) |
c2d11a7d | 8295 | continue; |
9103eae0 | 8296 | if (gdbarch_tdep (arches->gdbarch)->mips_abi != mips_abi) |
0dadbba0 | 8297 | continue; |
719ec221 AC |
8298 | /* Need to be pedantic about which register virtual size is |
8299 | used. */ | |
8300 | if (gdbarch_tdep (arches->gdbarch)->mips64_transfers_32bit_regs_p | |
8301 | != mips64_transfers_32bit_regs_p) | |
8302 | continue; | |
8d5838b5 AC |
8303 | /* Be pedantic about which FPU is selected. */ |
8304 | if (gdbarch_tdep (arches->gdbarch)->mips_fpu_type != fpu_type) | |
8305 | continue; | |
f8b73d13 DJ |
8306 | |
8307 | if (tdesc_data != NULL) | |
8308 | tdesc_data_cleanup (tdesc_data); | |
4be87837 | 8309 | return arches->gdbarch; |
c2d11a7d JM |
8310 | } |
8311 | ||
102182a9 | 8312 | /* Need a new architecture. Fill in a target specific vector. */ |
c2d11a7d JM |
8313 | tdep = (struct gdbarch_tdep *) xmalloc (sizeof (struct gdbarch_tdep)); |
8314 | gdbarch = gdbarch_alloc (&info, tdep); | |
8315 | tdep->elf_flags = elf_flags; | |
719ec221 | 8316 | tdep->mips64_transfers_32bit_regs_p = mips64_transfers_32bit_regs_p; |
ec03c1ac AC |
8317 | tdep->found_abi = found_abi; |
8318 | tdep->mips_abi = mips_abi; | |
4cc0665f | 8319 | tdep->mips_isa = mips_isa; |
8d5838b5 | 8320 | tdep->mips_fpu_type = fpu_type; |
29709017 DJ |
8321 | tdep->register_size_valid_p = 0; |
8322 | tdep->register_size = 0; | |
50e8a0d5 HZ |
8323 | tdep->gregset = NULL; |
8324 | tdep->gregset64 = NULL; | |
8325 | tdep->fpregset = NULL; | |
8326 | tdep->fpregset64 = NULL; | |
29709017 DJ |
8327 | |
8328 | if (info.target_desc) | |
8329 | { | |
8330 | /* Some useful properties can be inferred from the target. */ | |
8331 | if (tdesc_property (info.target_desc, PROPERTY_GP32) != NULL) | |
8332 | { | |
8333 | tdep->register_size_valid_p = 1; | |
8334 | tdep->register_size = 4; | |
8335 | } | |
8336 | else if (tdesc_property (info.target_desc, PROPERTY_GP64) != NULL) | |
8337 | { | |
8338 | tdep->register_size_valid_p = 1; | |
8339 | tdep->register_size = 8; | |
8340 | } | |
8341 | } | |
c2d11a7d | 8342 | |
102182a9 | 8343 | /* Initially set everything according to the default ABI/ISA. */ |
c2d11a7d JM |
8344 | set_gdbarch_short_bit (gdbarch, 16); |
8345 | set_gdbarch_int_bit (gdbarch, 32); | |
8346 | set_gdbarch_float_bit (gdbarch, 32); | |
8347 | set_gdbarch_double_bit (gdbarch, 64); | |
8348 | set_gdbarch_long_double_bit (gdbarch, 64); | |
a4b8ebc8 AC |
8349 | set_gdbarch_register_reggroup_p (gdbarch, mips_register_reggroup_p); |
8350 | set_gdbarch_pseudo_register_read (gdbarch, mips_pseudo_register_read); | |
8351 | set_gdbarch_pseudo_register_write (gdbarch, mips_pseudo_register_write); | |
1d06468c | 8352 | |
175ff332 HZ |
8353 | set_gdbarch_ax_pseudo_register_collect (gdbarch, |
8354 | mips_ax_pseudo_register_collect); | |
8355 | set_gdbarch_ax_pseudo_register_push_stack | |
8356 | (gdbarch, mips_ax_pseudo_register_push_stack); | |
8357 | ||
6d82d43b | 8358 | set_gdbarch_elf_make_msymbol_special (gdbarch, |
f7ab6ec6 MS |
8359 | mips_elf_make_msymbol_special); |
8360 | ||
1faeff08 MR |
8361 | regnum = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct mips_regnum); |
8362 | *regnum = mips_regnum; | |
1faeff08 MR |
8363 | set_gdbarch_fp0_regnum (gdbarch, regnum->fp0); |
8364 | set_gdbarch_num_regs (gdbarch, num_regs); | |
8365 | set_gdbarch_num_pseudo_regs (gdbarch, num_regs); | |
8366 | set_gdbarch_register_name (gdbarch, mips_register_name); | |
8367 | set_gdbarch_virtual_frame_pointer (gdbarch, mips_virtual_frame_pointer); | |
8368 | tdep->mips_processor_reg_names = reg_names; | |
8369 | tdep->regnum = regnum; | |
fe29b929 | 8370 | |
0dadbba0 | 8371 | switch (mips_abi) |
c2d11a7d | 8372 | { |
0dadbba0 | 8373 | case MIPS_ABI_O32: |
25ab4790 | 8374 | set_gdbarch_push_dummy_call (gdbarch, mips_o32_push_dummy_call); |
29dfb2ac | 8375 | set_gdbarch_return_value (gdbarch, mips_o32_return_value); |
4c7d22cb | 8376 | tdep->mips_last_arg_regnum = MIPS_A0_REGNUM + 4 - 1; |
56cea623 | 8377 | tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 4 - 1; |
4014092b | 8378 | tdep->default_mask_address_p = 0; |
c2d11a7d JM |
8379 | set_gdbarch_long_bit (gdbarch, 32); |
8380 | set_gdbarch_ptr_bit (gdbarch, 32); | |
8381 | set_gdbarch_long_long_bit (gdbarch, 64); | |
8382 | break; | |
0dadbba0 | 8383 | case MIPS_ABI_O64: |
25ab4790 | 8384 | set_gdbarch_push_dummy_call (gdbarch, mips_o64_push_dummy_call); |
9c8fdbfa | 8385 | set_gdbarch_return_value (gdbarch, mips_o64_return_value); |
4c7d22cb | 8386 | tdep->mips_last_arg_regnum = MIPS_A0_REGNUM + 4 - 1; |
56cea623 | 8387 | tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 4 - 1; |
361d1df0 | 8388 | tdep->default_mask_address_p = 0; |
c2d11a7d JM |
8389 | set_gdbarch_long_bit (gdbarch, 32); |
8390 | set_gdbarch_ptr_bit (gdbarch, 32); | |
8391 | set_gdbarch_long_long_bit (gdbarch, 64); | |
8392 | break; | |
0dadbba0 | 8393 | case MIPS_ABI_EABI32: |
25ab4790 | 8394 | set_gdbarch_push_dummy_call (gdbarch, mips_eabi_push_dummy_call); |
9c8fdbfa | 8395 | set_gdbarch_return_value (gdbarch, mips_eabi_return_value); |
4c7d22cb | 8396 | tdep->mips_last_arg_regnum = MIPS_A0_REGNUM + 8 - 1; |
56cea623 | 8397 | tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 8 - 1; |
4014092b | 8398 | tdep->default_mask_address_p = 0; |
c2d11a7d JM |
8399 | set_gdbarch_long_bit (gdbarch, 32); |
8400 | set_gdbarch_ptr_bit (gdbarch, 32); | |
8401 | set_gdbarch_long_long_bit (gdbarch, 64); | |
8402 | break; | |
0dadbba0 | 8403 | case MIPS_ABI_EABI64: |
25ab4790 | 8404 | set_gdbarch_push_dummy_call (gdbarch, mips_eabi_push_dummy_call); |
9c8fdbfa | 8405 | set_gdbarch_return_value (gdbarch, mips_eabi_return_value); |
4c7d22cb | 8406 | tdep->mips_last_arg_regnum = MIPS_A0_REGNUM + 8 - 1; |
56cea623 | 8407 | tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 8 - 1; |
4014092b | 8408 | tdep->default_mask_address_p = 0; |
c2d11a7d JM |
8409 | set_gdbarch_long_bit (gdbarch, 64); |
8410 | set_gdbarch_ptr_bit (gdbarch, 64); | |
8411 | set_gdbarch_long_long_bit (gdbarch, 64); | |
8412 | break; | |
0dadbba0 | 8413 | case MIPS_ABI_N32: |
25ab4790 | 8414 | set_gdbarch_push_dummy_call (gdbarch, mips_n32n64_push_dummy_call); |
29dfb2ac | 8415 | set_gdbarch_return_value (gdbarch, mips_n32n64_return_value); |
4c7d22cb | 8416 | tdep->mips_last_arg_regnum = MIPS_A0_REGNUM + 8 - 1; |
56cea623 | 8417 | tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 8 - 1; |
4014092b | 8418 | tdep->default_mask_address_p = 0; |
0dadbba0 AC |
8419 | set_gdbarch_long_bit (gdbarch, 32); |
8420 | set_gdbarch_ptr_bit (gdbarch, 32); | |
8421 | set_gdbarch_long_long_bit (gdbarch, 64); | |
fed7ba43 | 8422 | set_gdbarch_long_double_bit (gdbarch, 128); |
b14d30e1 | 8423 | set_gdbarch_long_double_format (gdbarch, floatformats_ibm_long_double); |
28d169de KB |
8424 | break; |
8425 | case MIPS_ABI_N64: | |
25ab4790 | 8426 | set_gdbarch_push_dummy_call (gdbarch, mips_n32n64_push_dummy_call); |
29dfb2ac | 8427 | set_gdbarch_return_value (gdbarch, mips_n32n64_return_value); |
4c7d22cb | 8428 | tdep->mips_last_arg_regnum = MIPS_A0_REGNUM + 8 - 1; |
56cea623 | 8429 | tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 8 - 1; |
28d169de KB |
8430 | tdep->default_mask_address_p = 0; |
8431 | set_gdbarch_long_bit (gdbarch, 64); | |
8432 | set_gdbarch_ptr_bit (gdbarch, 64); | |
8433 | set_gdbarch_long_long_bit (gdbarch, 64); | |
fed7ba43 | 8434 | set_gdbarch_long_double_bit (gdbarch, 128); |
b14d30e1 | 8435 | set_gdbarch_long_double_format (gdbarch, floatformats_ibm_long_double); |
0dadbba0 | 8436 | break; |
c2d11a7d | 8437 | default: |
e2e0b3e5 | 8438 | internal_error (__FILE__, __LINE__, _("unknown ABI in switch")); |
c2d11a7d JM |
8439 | } |
8440 | ||
22e47e37 FF |
8441 | /* GCC creates a pseudo-section whose name specifies the size of |
8442 | longs, since -mlong32 or -mlong64 may be used independent of | |
8443 | other options. How those options affect pointer sizes is ABI and | |
8444 | architecture dependent, so use them to override the default sizes | |
8445 | set by the ABI. This table shows the relationship between ABI, | |
8446 | -mlongXX, and size of pointers: | |
8447 | ||
8448 | ABI -mlongXX ptr bits | |
8449 | --- -------- -------- | |
8450 | o32 32 32 | |
8451 | o32 64 32 | |
8452 | n32 32 32 | |
8453 | n32 64 64 | |
8454 | o64 32 32 | |
8455 | o64 64 64 | |
8456 | n64 32 32 | |
8457 | n64 64 64 | |
8458 | eabi32 32 32 | |
8459 | eabi32 64 32 | |
8460 | eabi64 32 32 | |
8461 | eabi64 64 64 | |
8462 | ||
8463 | Note that for o32 and eabi32, pointers are always 32 bits | |
8464 | regardless of any -mlongXX option. For all others, pointers and | |
025bb325 | 8465 | longs are the same, as set by -mlongXX or set by defaults. */ |
22e47e37 FF |
8466 | |
8467 | if (info.abfd != NULL) | |
8468 | { | |
8469 | int long_bit = 0; | |
8470 | ||
8471 | bfd_map_over_sections (info.abfd, mips_find_long_section, &long_bit); | |
8472 | if (long_bit) | |
8473 | { | |
8474 | set_gdbarch_long_bit (gdbarch, long_bit); | |
8475 | switch (mips_abi) | |
8476 | { | |
8477 | case MIPS_ABI_O32: | |
8478 | case MIPS_ABI_EABI32: | |
8479 | break; | |
8480 | case MIPS_ABI_N32: | |
8481 | case MIPS_ABI_O64: | |
8482 | case MIPS_ABI_N64: | |
8483 | case MIPS_ABI_EABI64: | |
8484 | set_gdbarch_ptr_bit (gdbarch, long_bit); | |
8485 | break; | |
8486 | default: | |
8487 | internal_error (__FILE__, __LINE__, _("unknown ABI in switch")); | |
8488 | } | |
8489 | } | |
8490 | } | |
8491 | ||
a5ea2558 AC |
8492 | /* FIXME: jlarmour/2000-04-07: There *is* a flag EF_MIPS_32BIT_MODE |
8493 | that could indicate -gp32 BUT gas/config/tc-mips.c contains the | |
8494 | comment: | |
8495 | ||
8496 | ``We deliberately don't allow "-gp32" to set the MIPS_32BITMODE | |
8497 | flag in object files because to do so would make it impossible to | |
102182a9 | 8498 | link with libraries compiled without "-gp32". This is |
a5ea2558 | 8499 | unnecessarily restrictive. |
361d1df0 | 8500 | |
a5ea2558 AC |
8501 | We could solve this problem by adding "-gp32" multilibs to gcc, |
8502 | but to set this flag before gcc is built with such multilibs will | |
8503 | break too many systems.'' | |
8504 | ||
8505 | But even more unhelpfully, the default linker output target for | |
8506 | mips64-elf is elf32-bigmips, and has EF_MIPS_32BIT_MODE set, even | |
8507 | for 64-bit programs - you need to change the ABI to change this, | |
102182a9 | 8508 | and not all gcc targets support that currently. Therefore using |
a5ea2558 AC |
8509 | this flag to detect 32-bit mode would do the wrong thing given |
8510 | the current gcc - it would make GDB treat these 64-bit programs | |
102182a9 | 8511 | as 32-bit programs by default. */ |
a5ea2558 | 8512 | |
6c997a34 | 8513 | set_gdbarch_read_pc (gdbarch, mips_read_pc); |
b6cb9035 | 8514 | set_gdbarch_write_pc (gdbarch, mips_write_pc); |
c2d11a7d | 8515 | |
102182a9 MS |
8516 | /* Add/remove bits from an address. The MIPS needs be careful to |
8517 | ensure that all 32 bit addresses are sign extended to 64 bits. */ | |
875e1767 AC |
8518 | set_gdbarch_addr_bits_remove (gdbarch, mips_addr_bits_remove); |
8519 | ||
58dfe9ff AC |
8520 | /* Unwind the frame. */ |
8521 | set_gdbarch_unwind_pc (gdbarch, mips_unwind_pc); | |
30244cd8 | 8522 | set_gdbarch_unwind_sp (gdbarch, mips_unwind_sp); |
b8a22b94 | 8523 | set_gdbarch_dummy_id (gdbarch, mips_dummy_id); |
10312cc4 | 8524 | |
102182a9 | 8525 | /* Map debug register numbers onto internal register numbers. */ |
88c72b7d | 8526 | set_gdbarch_stab_reg_to_regnum (gdbarch, mips_stab_reg_to_regnum); |
6d82d43b AC |
8527 | set_gdbarch_ecoff_reg_to_regnum (gdbarch, |
8528 | mips_dwarf_dwarf2_ecoff_reg_to_regnum); | |
6d82d43b AC |
8529 | set_gdbarch_dwarf2_reg_to_regnum (gdbarch, |
8530 | mips_dwarf_dwarf2_ecoff_reg_to_regnum); | |
a4b8ebc8 | 8531 | set_gdbarch_register_sim_regno (gdbarch, mips_register_sim_regno); |
88c72b7d | 8532 | |
025bb325 | 8533 | /* MIPS version of CALL_DUMMY. */ |
c2d11a7d | 8534 | |
2c76a0c7 JB |
8535 | set_gdbarch_call_dummy_location (gdbarch, ON_STACK); |
8536 | set_gdbarch_push_dummy_code (gdbarch, mips_push_dummy_code); | |
dc604539 | 8537 | set_gdbarch_frame_align (gdbarch, mips_frame_align); |
d05285fa | 8538 | |
87783b8b AC |
8539 | set_gdbarch_convert_register_p (gdbarch, mips_convert_register_p); |
8540 | set_gdbarch_register_to_value (gdbarch, mips_register_to_value); | |
8541 | set_gdbarch_value_to_register (gdbarch, mips_value_to_register); | |
8542 | ||
f7b9e9fc AC |
8543 | set_gdbarch_inner_than (gdbarch, core_addr_lessthan); |
8544 | set_gdbarch_breakpoint_from_pc (gdbarch, mips_breakpoint_from_pc); | |
4cc0665f MR |
8545 | set_gdbarch_remote_breakpoint_from_pc (gdbarch, |
8546 | mips_remote_breakpoint_from_pc); | |
c8cef75f MR |
8547 | set_gdbarch_adjust_breakpoint_address (gdbarch, |
8548 | mips_adjust_breakpoint_address); | |
f7b9e9fc AC |
8549 | |
8550 | set_gdbarch_skip_prologue (gdbarch, mips_skip_prologue); | |
f7b9e9fc | 8551 | |
97ab0fdd MR |
8552 | set_gdbarch_in_function_epilogue_p (gdbarch, mips_in_function_epilogue_p); |
8553 | ||
fc0c74b1 AC |
8554 | set_gdbarch_pointer_to_address (gdbarch, signed_pointer_to_address); |
8555 | set_gdbarch_address_to_pointer (gdbarch, address_to_signed_pointer); | |
8556 | set_gdbarch_integer_to_address (gdbarch, mips_integer_to_address); | |
70f80edf | 8557 | |
a4b8ebc8 | 8558 | set_gdbarch_register_type (gdbarch, mips_register_type); |
78fde5f8 | 8559 | |
e11c53d2 | 8560 | set_gdbarch_print_registers_info (gdbarch, mips_print_registers_info); |
bf1f5b4c | 8561 | |
9dae60cc UW |
8562 | if (mips_abi == MIPS_ABI_N32) |
8563 | set_gdbarch_print_insn (gdbarch, gdb_print_insn_mips_n32); | |
8564 | else if (mips_abi == MIPS_ABI_N64) | |
8565 | set_gdbarch_print_insn (gdbarch, gdb_print_insn_mips_n64); | |
8566 | else | |
8567 | set_gdbarch_print_insn (gdbarch, gdb_print_insn_mips); | |
e5ab0dce | 8568 | |
d92524f1 PM |
8569 | /* FIXME: cagney/2003-08-29: The macros target_have_steppable_watchpoint, |
8570 | HAVE_NONSTEPPABLE_WATCHPOINT, and target_have_continuable_watchpoint | |
3a3bc038 | 8571 | need to all be folded into the target vector. Since they are |
d92524f1 PM |
8572 | being used as guards for target_stopped_by_watchpoint, why not have |
8573 | target_stopped_by_watchpoint return the type of watchpoint that the code | |
3a3bc038 AC |
8574 | is sitting on? */ |
8575 | set_gdbarch_have_nonsteppable_watchpoint (gdbarch, 1); | |
8576 | ||
e7d6a6d2 | 8577 | set_gdbarch_skip_trampoline_code (gdbarch, mips_skip_trampoline_code); |
757a7cc6 | 8578 | |
14132e89 MR |
8579 | /* NOTE drow/2012-04-25: We overload the core solib trampoline code |
8580 | to support MIPS16. This is a bad thing. Make sure not to do it | |
8581 | if we have an OS ABI that actually supports shared libraries, since | |
8582 | shared library support is more important. If we have an OS someday | |
8583 | that supports both shared libraries and MIPS16, we'll have to find | |
8584 | a better place for these. | |
8585 | macro/2012-04-25: But that applies to return trampolines only and | |
8586 | currently no MIPS OS ABI uses shared libraries that have them. */ | |
8587 | set_gdbarch_in_solib_return_trampoline (gdbarch, mips_in_return_stub); | |
8588 | ||
025bb325 MS |
8589 | set_gdbarch_single_step_through_delay (gdbarch, |
8590 | mips_single_step_through_delay); | |
3352ef37 | 8591 | |
0d5de010 DJ |
8592 | /* Virtual tables. */ |
8593 | set_gdbarch_vbit_in_delta (gdbarch, 1); | |
8594 | ||
29709017 DJ |
8595 | mips_register_g_packet_guesses (gdbarch); |
8596 | ||
6de918a6 | 8597 | /* Hook in OS ABI-specific overrides, if they have been registered. */ |
822b6570 | 8598 | info.tdep_info = (void *) tdesc_data; |
6de918a6 | 8599 | gdbarch_init_osabi (info, gdbarch); |
757a7cc6 | 8600 | |
9aac7884 MR |
8601 | /* The hook may have adjusted num_regs, fetch the final value and |
8602 | set pc_regnum and sp_regnum now that it has been fixed. */ | |
9aac7884 MR |
8603 | num_regs = gdbarch_num_regs (gdbarch); |
8604 | set_gdbarch_pc_regnum (gdbarch, regnum->pc + num_regs); | |
8605 | set_gdbarch_sp_regnum (gdbarch, MIPS_SP_REGNUM + num_regs); | |
8606 | ||
5792a79b | 8607 | /* Unwind the frame. */ |
b8a22b94 DJ |
8608 | dwarf2_append_unwinders (gdbarch); |
8609 | frame_unwind_append_unwinder (gdbarch, &mips_stub_frame_unwind); | |
8610 | frame_unwind_append_unwinder (gdbarch, &mips_insn16_frame_unwind); | |
4cc0665f | 8611 | frame_unwind_append_unwinder (gdbarch, &mips_micro_frame_unwind); |
b8a22b94 | 8612 | frame_unwind_append_unwinder (gdbarch, &mips_insn32_frame_unwind); |
2bd0c3d7 | 8613 | frame_base_append_sniffer (gdbarch, dwarf2_frame_base_sniffer); |
eec63939 | 8614 | frame_base_append_sniffer (gdbarch, mips_stub_frame_base_sniffer); |
45c9dd44 | 8615 | frame_base_append_sniffer (gdbarch, mips_insn16_frame_base_sniffer); |
4cc0665f | 8616 | frame_base_append_sniffer (gdbarch, mips_micro_frame_base_sniffer); |
45c9dd44 | 8617 | frame_base_append_sniffer (gdbarch, mips_insn32_frame_base_sniffer); |
5792a79b | 8618 | |
f8b73d13 DJ |
8619 | if (tdesc_data) |
8620 | { | |
8621 | set_tdesc_pseudo_register_type (gdbarch, mips_pseudo_register_type); | |
7cc46491 | 8622 | tdesc_use_registers (gdbarch, info.target_desc, tdesc_data); |
f8b73d13 DJ |
8623 | |
8624 | /* Override the normal target description methods to handle our | |
8625 | dual real and pseudo registers. */ | |
8626 | set_gdbarch_register_name (gdbarch, mips_register_name); | |
025bb325 MS |
8627 | set_gdbarch_register_reggroup_p (gdbarch, |
8628 | mips_tdesc_register_reggroup_p); | |
f8b73d13 DJ |
8629 | |
8630 | num_regs = gdbarch_num_regs (gdbarch); | |
8631 | set_gdbarch_num_pseudo_regs (gdbarch, num_regs); | |
8632 | set_gdbarch_pc_regnum (gdbarch, tdep->regnum->pc + num_regs); | |
8633 | set_gdbarch_sp_regnum (gdbarch, MIPS_SP_REGNUM + num_regs); | |
8634 | } | |
8635 | ||
8636 | /* Add ABI-specific aliases for the registers. */ | |
8637 | if (mips_abi == MIPS_ABI_N32 || mips_abi == MIPS_ABI_N64) | |
8638 | for (i = 0; i < ARRAY_SIZE (mips_n32_n64_aliases); i++) | |
8639 | user_reg_add (gdbarch, mips_n32_n64_aliases[i].name, | |
8640 | value_of_mips_user_reg, &mips_n32_n64_aliases[i].regnum); | |
8641 | else | |
8642 | for (i = 0; i < ARRAY_SIZE (mips_o32_aliases); i++) | |
8643 | user_reg_add (gdbarch, mips_o32_aliases[i].name, | |
8644 | value_of_mips_user_reg, &mips_o32_aliases[i].regnum); | |
8645 | ||
8646 | /* Add some other standard aliases. */ | |
8647 | for (i = 0; i < ARRAY_SIZE (mips_register_aliases); i++) | |
8648 | user_reg_add (gdbarch, mips_register_aliases[i].name, | |
8649 | value_of_mips_user_reg, &mips_register_aliases[i].regnum); | |
8650 | ||
865093a3 AR |
8651 | for (i = 0; i < ARRAY_SIZE (mips_numeric_register_aliases); i++) |
8652 | user_reg_add (gdbarch, mips_numeric_register_aliases[i].name, | |
8653 | value_of_mips_user_reg, | |
8654 | &mips_numeric_register_aliases[i].regnum); | |
8655 | ||
4b9b3959 AC |
8656 | return gdbarch; |
8657 | } | |
8658 | ||
2e4ebe70 | 8659 | static void |
6d82d43b | 8660 | mips_abi_update (char *ignore_args, int from_tty, struct cmd_list_element *c) |
2e4ebe70 DJ |
8661 | { |
8662 | struct gdbarch_info info; | |
8663 | ||
8664 | /* Force the architecture to update, and (if it's a MIPS architecture) | |
8665 | mips_gdbarch_init will take care of the rest. */ | |
8666 | gdbarch_info_init (&info); | |
8667 | gdbarch_update_p (info); | |
8668 | } | |
8669 | ||
ad188201 KB |
8670 | /* Print out which MIPS ABI is in use. */ |
8671 | ||
8672 | static void | |
1f8ca57c JB |
8673 | show_mips_abi (struct ui_file *file, |
8674 | int from_tty, | |
8675 | struct cmd_list_element *ignored_cmd, | |
8676 | const char *ignored_value) | |
ad188201 | 8677 | { |
f5656ead | 8678 | if (gdbarch_bfd_arch_info (target_gdbarch ())->arch != bfd_arch_mips) |
1f8ca57c JB |
8679 | fprintf_filtered |
8680 | (file, | |
8681 | "The MIPS ABI is unknown because the current architecture " | |
8682 | "is not MIPS.\n"); | |
ad188201 KB |
8683 | else |
8684 | { | |
8685 | enum mips_abi global_abi = global_mips_abi (); | |
f5656ead | 8686 | enum mips_abi actual_abi = mips_abi (target_gdbarch ()); |
ad188201 KB |
8687 | const char *actual_abi_str = mips_abi_strings[actual_abi]; |
8688 | ||
8689 | if (global_abi == MIPS_ABI_UNKNOWN) | |
1f8ca57c JB |
8690 | fprintf_filtered |
8691 | (file, | |
8692 | "The MIPS ABI is set automatically (currently \"%s\").\n", | |
6d82d43b | 8693 | actual_abi_str); |
ad188201 | 8694 | else if (global_abi == actual_abi) |
1f8ca57c JB |
8695 | fprintf_filtered |
8696 | (file, | |
8697 | "The MIPS ABI is assumed to be \"%s\" (due to user setting).\n", | |
6d82d43b | 8698 | actual_abi_str); |
ad188201 KB |
8699 | else |
8700 | { | |
8701 | /* Probably shouldn't happen... */ | |
025bb325 MS |
8702 | fprintf_filtered (file, |
8703 | "The (auto detected) MIPS ABI \"%s\" is in use " | |
8704 | "even though the user setting was \"%s\".\n", | |
6d82d43b | 8705 | actual_abi_str, mips_abi_strings[global_abi]); |
ad188201 KB |
8706 | } |
8707 | } | |
8708 | } | |
8709 | ||
4cc0665f MR |
8710 | /* Print out which MIPS compressed ISA encoding is used. */ |
8711 | ||
8712 | static void | |
8713 | show_mips_compression (struct ui_file *file, int from_tty, | |
8714 | struct cmd_list_element *c, const char *value) | |
8715 | { | |
8716 | fprintf_filtered (file, _("The compressed ISA encoding used is %s.\n"), | |
8717 | value); | |
8718 | } | |
8719 | ||
4b9b3959 | 8720 | static void |
72a155b4 | 8721 | mips_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file) |
4b9b3959 | 8722 | { |
72a155b4 | 8723 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
4b9b3959 | 8724 | if (tdep != NULL) |
c2d11a7d | 8725 | { |
acdb74a0 AC |
8726 | int ef_mips_arch; |
8727 | int ef_mips_32bitmode; | |
f49e4e6d | 8728 | /* Determine the ISA. */ |
acdb74a0 AC |
8729 | switch (tdep->elf_flags & EF_MIPS_ARCH) |
8730 | { | |
8731 | case E_MIPS_ARCH_1: | |
8732 | ef_mips_arch = 1; | |
8733 | break; | |
8734 | case E_MIPS_ARCH_2: | |
8735 | ef_mips_arch = 2; | |
8736 | break; | |
8737 | case E_MIPS_ARCH_3: | |
8738 | ef_mips_arch = 3; | |
8739 | break; | |
8740 | case E_MIPS_ARCH_4: | |
93d56215 | 8741 | ef_mips_arch = 4; |
acdb74a0 AC |
8742 | break; |
8743 | default: | |
93d56215 | 8744 | ef_mips_arch = 0; |
acdb74a0 AC |
8745 | break; |
8746 | } | |
f49e4e6d | 8747 | /* Determine the size of a pointer. */ |
acdb74a0 | 8748 | ef_mips_32bitmode = (tdep->elf_flags & EF_MIPS_32BITMODE); |
4b9b3959 AC |
8749 | fprintf_unfiltered (file, |
8750 | "mips_dump_tdep: tdep->elf_flags = 0x%x\n", | |
0dadbba0 | 8751 | tdep->elf_flags); |
4b9b3959 | 8752 | fprintf_unfiltered (file, |
acdb74a0 AC |
8753 | "mips_dump_tdep: ef_mips_32bitmode = %d\n", |
8754 | ef_mips_32bitmode); | |
8755 | fprintf_unfiltered (file, | |
8756 | "mips_dump_tdep: ef_mips_arch = %d\n", | |
8757 | ef_mips_arch); | |
8758 | fprintf_unfiltered (file, | |
8759 | "mips_dump_tdep: tdep->mips_abi = %d (%s)\n", | |
6d82d43b | 8760 | tdep->mips_abi, mips_abi_strings[tdep->mips_abi]); |
4014092b | 8761 | fprintf_unfiltered (file, |
025bb325 MS |
8762 | "mips_dump_tdep: " |
8763 | "mips_mask_address_p() %d (default %d)\n", | |
480d3dd2 | 8764 | mips_mask_address_p (tdep), |
4014092b | 8765 | tdep->default_mask_address_p); |
c2d11a7d | 8766 | } |
4b9b3959 AC |
8767 | fprintf_unfiltered (file, |
8768 | "mips_dump_tdep: MIPS_DEFAULT_FPU_TYPE = %d (%s)\n", | |
8769 | MIPS_DEFAULT_FPU_TYPE, | |
8770 | (MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_NONE ? "none" | |
8771 | : MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_SINGLE ? "single" | |
8772 | : MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_DOUBLE ? "double" | |
8773 | : "???")); | |
74ed0bb4 MD |
8774 | fprintf_unfiltered (file, "mips_dump_tdep: MIPS_EABI = %d\n", |
8775 | MIPS_EABI (gdbarch)); | |
4b9b3959 AC |
8776 | fprintf_unfiltered (file, |
8777 | "mips_dump_tdep: MIPS_FPU_TYPE = %d (%s)\n", | |
74ed0bb4 MD |
8778 | MIPS_FPU_TYPE (gdbarch), |
8779 | (MIPS_FPU_TYPE (gdbarch) == MIPS_FPU_NONE ? "none" | |
8780 | : MIPS_FPU_TYPE (gdbarch) == MIPS_FPU_SINGLE ? "single" | |
8781 | : MIPS_FPU_TYPE (gdbarch) == MIPS_FPU_DOUBLE ? "double" | |
4b9b3959 | 8782 | : "???")); |
c2d11a7d JM |
8783 | } |
8784 | ||
025bb325 | 8785 | extern initialize_file_ftype _initialize_mips_tdep; /* -Wmissing-prototypes */ |
a78f21af | 8786 | |
c906108c | 8787 | void |
acdb74a0 | 8788 | _initialize_mips_tdep (void) |
c906108c SS |
8789 | { |
8790 | static struct cmd_list_element *mipsfpulist = NULL; | |
8791 | struct cmd_list_element *c; | |
8792 | ||
6d82d43b | 8793 | mips_abi_string = mips_abi_strings[MIPS_ABI_UNKNOWN]; |
2e4ebe70 DJ |
8794 | if (MIPS_ABI_LAST + 1 |
8795 | != sizeof (mips_abi_strings) / sizeof (mips_abi_strings[0])) | |
e2e0b3e5 | 8796 | internal_error (__FILE__, __LINE__, _("mips_abi_strings out of sync")); |
2e4ebe70 | 8797 | |
4b9b3959 | 8798 | gdbarch_register (bfd_arch_mips, mips_gdbarch_init, mips_dump_tdep); |
c906108c | 8799 | |
8d5f9dcb DJ |
8800 | mips_pdr_data = register_objfile_data (); |
8801 | ||
4eb0ad19 DJ |
8802 | /* Create feature sets with the appropriate properties. The values |
8803 | are not important. */ | |
8804 | mips_tdesc_gp32 = allocate_target_description (); | |
8805 | set_tdesc_property (mips_tdesc_gp32, PROPERTY_GP32, ""); | |
8806 | ||
8807 | mips_tdesc_gp64 = allocate_target_description (); | |
8808 | set_tdesc_property (mips_tdesc_gp64, PROPERTY_GP64, ""); | |
8809 | ||
025bb325 | 8810 | /* Add root prefix command for all "set mips"/"show mips" commands. */ |
a5ea2558 | 8811 | add_prefix_cmd ("mips", no_class, set_mips_command, |
1bedd215 | 8812 | _("Various MIPS specific commands."), |
a5ea2558 AC |
8813 | &setmipscmdlist, "set mips ", 0, &setlist); |
8814 | ||
8815 | add_prefix_cmd ("mips", no_class, show_mips_command, | |
1bedd215 | 8816 | _("Various MIPS specific commands."), |
a5ea2558 AC |
8817 | &showmipscmdlist, "show mips ", 0, &showlist); |
8818 | ||
025bb325 | 8819 | /* Allow the user to override the ABI. */ |
7ab04401 AC |
8820 | add_setshow_enum_cmd ("abi", class_obscure, mips_abi_strings, |
8821 | &mips_abi_string, _("\ | |
8822 | Set the MIPS ABI used by this program."), _("\ | |
8823 | Show the MIPS ABI used by this program."), _("\ | |
8824 | This option can be set to one of:\n\ | |
8825 | auto - the default ABI associated with the current binary\n\ | |
8826 | o32\n\ | |
8827 | o64\n\ | |
8828 | n32\n\ | |
8829 | n64\n\ | |
8830 | eabi32\n\ | |
8831 | eabi64"), | |
8832 | mips_abi_update, | |
8833 | show_mips_abi, | |
8834 | &setmipscmdlist, &showmipscmdlist); | |
2e4ebe70 | 8835 | |
4cc0665f MR |
8836 | /* Allow the user to set the ISA to assume for compressed code if ELF |
8837 | file flags don't tell or there is no program file selected. This | |
8838 | setting is updated whenever unambiguous ELF file flags are interpreted, | |
8839 | and carried over to subsequent sessions. */ | |
8840 | add_setshow_enum_cmd ("compression", class_obscure, mips_compression_strings, | |
8841 | &mips_compression_string, _("\ | |
8842 | Set the compressed ISA encoding used by MIPS code."), _("\ | |
8843 | Show the compressed ISA encoding used by MIPS code."), _("\ | |
8844 | Select the compressed ISA encoding used in functions that have no symbol\n\ | |
8845 | information available. The encoding can be set to either of:\n\ | |
8846 | mips16\n\ | |
8847 | micromips\n\ | |
8848 | and is updated automatically from ELF file flags if available."), | |
8849 | mips_abi_update, | |
8850 | show_mips_compression, | |
8851 | &setmipscmdlist, &showmipscmdlist); | |
8852 | ||
c906108c SS |
8853 | /* Let the user turn off floating point and set the fence post for |
8854 | heuristic_proc_start. */ | |
8855 | ||
8856 | add_prefix_cmd ("mipsfpu", class_support, set_mipsfpu_command, | |
1bedd215 | 8857 | _("Set use of MIPS floating-point coprocessor."), |
c906108c SS |
8858 | &mipsfpulist, "set mipsfpu ", 0, &setlist); |
8859 | add_cmd ("single", class_support, set_mipsfpu_single_command, | |
1a966eab | 8860 | _("Select single-precision MIPS floating-point coprocessor."), |
c906108c SS |
8861 | &mipsfpulist); |
8862 | add_cmd ("double", class_support, set_mipsfpu_double_command, | |
1a966eab | 8863 | _("Select double-precision MIPS floating-point coprocessor."), |
c906108c SS |
8864 | &mipsfpulist); |
8865 | add_alias_cmd ("on", "double", class_support, 1, &mipsfpulist); | |
8866 | add_alias_cmd ("yes", "double", class_support, 1, &mipsfpulist); | |
8867 | add_alias_cmd ("1", "double", class_support, 1, &mipsfpulist); | |
8868 | add_cmd ("none", class_support, set_mipsfpu_none_command, | |
1a966eab | 8869 | _("Select no MIPS floating-point coprocessor."), &mipsfpulist); |
c906108c SS |
8870 | add_alias_cmd ("off", "none", class_support, 1, &mipsfpulist); |
8871 | add_alias_cmd ("no", "none", class_support, 1, &mipsfpulist); | |
8872 | add_alias_cmd ("0", "none", class_support, 1, &mipsfpulist); | |
8873 | add_cmd ("auto", class_support, set_mipsfpu_auto_command, | |
1a966eab | 8874 | _("Select MIPS floating-point coprocessor automatically."), |
c906108c SS |
8875 | &mipsfpulist); |
8876 | add_cmd ("mipsfpu", class_support, show_mipsfpu_command, | |
1a966eab | 8877 | _("Show current use of MIPS floating-point coprocessor target."), |
c906108c SS |
8878 | &showlist); |
8879 | ||
c906108c SS |
8880 | /* We really would like to have both "0" and "unlimited" work, but |
8881 | command.c doesn't deal with that. So make it a var_zinteger | |
8882 | because the user can always use "999999" or some such for unlimited. */ | |
6bcadd06 | 8883 | add_setshow_zinteger_cmd ("heuristic-fence-post", class_support, |
7915a72c AC |
8884 | &heuristic_fence_post, _("\ |
8885 | Set the distance searched for the start of a function."), _("\ | |
8886 | Show the distance searched for the start of a function."), _("\ | |
c906108c SS |
8887 | If you are debugging a stripped executable, GDB needs to search through the\n\ |
8888 | program for the start of a function. This command sets the distance of the\n\ | |
7915a72c | 8889 | search. The only need to set it is when debugging a stripped executable."), |
2c5b56ce | 8890 | reinit_frame_cache_sfunc, |
025bb325 MS |
8891 | NULL, /* FIXME: i18n: The distance searched for |
8892 | the start of a function is %s. */ | |
6bcadd06 | 8893 | &setlist, &showlist); |
c906108c SS |
8894 | |
8895 | /* Allow the user to control whether the upper bits of 64-bit | |
8896 | addresses should be zeroed. */ | |
7915a72c AC |
8897 | add_setshow_auto_boolean_cmd ("mask-address", no_class, |
8898 | &mask_address_var, _("\ | |
8899 | Set zeroing of upper 32 bits of 64-bit addresses."), _("\ | |
8900 | Show zeroing of upper 32 bits of 64-bit addresses."), _("\ | |
cce7e648 | 8901 | Use \"on\" to enable the masking, \"off\" to disable it and \"auto\" to\n\ |
7915a72c | 8902 | allow GDB to determine the correct value."), |
08546159 AC |
8903 | NULL, show_mask_address, |
8904 | &setmipscmdlist, &showmipscmdlist); | |
43e526b9 JM |
8905 | |
8906 | /* Allow the user to control the size of 32 bit registers within the | |
8907 | raw remote packet. */ | |
b3f42336 | 8908 | add_setshow_boolean_cmd ("remote-mips64-transfers-32bit-regs", class_obscure, |
7915a72c AC |
8909 | &mips64_transfers_32bit_regs_p, _("\ |
8910 | Set compatibility with 64-bit MIPS target that transfers 32-bit quantities."), | |
8911 | _("\ | |
8912 | Show compatibility with 64-bit MIPS target that transfers 32-bit quantities."), | |
8913 | _("\ | |
719ec221 AC |
8914 | Use \"on\" to enable backward compatibility with older MIPS 64 GDB+target\n\ |
8915 | that would transfer 32 bits for some registers (e.g. SR, FSR) and\n\ | |
7915a72c | 8916 | 64 bits for others. Use \"off\" to disable compatibility mode"), |
2c5b56ce | 8917 | set_mips64_transfers_32bit_regs, |
025bb325 MS |
8918 | NULL, /* FIXME: i18n: Compatibility with 64-bit |
8919 | MIPS target that transfers 32-bit | |
8920 | quantities is %s. */ | |
7915a72c | 8921 | &setlist, &showlist); |
9ace0497 | 8922 | |
025bb325 | 8923 | /* Debug this files internals. */ |
ccce17b0 YQ |
8924 | add_setshow_zuinteger_cmd ("mips", class_maintenance, |
8925 | &mips_debug, _("\ | |
7915a72c AC |
8926 | Set mips debugging."), _("\ |
8927 | Show mips debugging."), _("\ | |
8928 | When non-zero, mips specific debugging is enabled."), | |
ccce17b0 YQ |
8929 | NULL, |
8930 | NULL, /* FIXME: i18n: Mips debugging is | |
8931 | currently %s. */ | |
8932 | &setdebuglist, &showdebuglist); | |
c906108c | 8933 | } |