]>
Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Target-dependent code for the MIPS architecture, for GDB, the GNU Debugger. |
bf64bfd6 | 2 | |
6aba47ca DJ |
3 | Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, |
4 | 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 | |
47a35522 | 5 | Free Software Foundation, Inc. |
bf64bfd6 | 6 | |
c906108c SS |
7 | Contributed by Alessandro Forin([email protected]) at CMU |
8 | and by Per Bothner([email protected]) at U.Wisconsin. | |
9 | ||
c5aa993b | 10 | This file is part of GDB. |
c906108c | 11 | |
c5aa993b JM |
12 | This program is free software; you can redistribute it and/or modify |
13 | it under the terms of the GNU General Public License as published by | |
14 | the Free Software Foundation; either version 2 of the License, or | |
15 | (at your option) any later version. | |
c906108c | 16 | |
c5aa993b JM |
17 | This program is distributed in the hope that it will be useful, |
18 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 | GNU General Public License for more details. | |
c906108c | 21 | |
c5aa993b JM |
22 | You should have received a copy of the GNU General Public License |
23 | along with this program; if not, write to the Free Software | |
197e01b6 EZ |
24 | Foundation, Inc., 51 Franklin Street, Fifth Floor, |
25 | Boston, MA 02110-1301, USA. */ | |
c906108c SS |
26 | |
27 | #include "defs.h" | |
28 | #include "gdb_string.h" | |
5e2e9765 | 29 | #include "gdb_assert.h" |
c906108c SS |
30 | #include "frame.h" |
31 | #include "inferior.h" | |
32 | #include "symtab.h" | |
33 | #include "value.h" | |
34 | #include "gdbcmd.h" | |
35 | #include "language.h" | |
36 | #include "gdbcore.h" | |
37 | #include "symfile.h" | |
38 | #include "objfiles.h" | |
39 | #include "gdbtypes.h" | |
40 | #include "target.h" | |
28d069e6 | 41 | #include "arch-utils.h" |
4e052eda | 42 | #include "regcache.h" |
70f80edf | 43 | #include "osabi.h" |
d1973055 | 44 | #include "mips-tdep.h" |
fe898f56 | 45 | #include "block.h" |
a4b8ebc8 | 46 | #include "reggroups.h" |
c906108c | 47 | #include "opcode/mips.h" |
c2d11a7d JM |
48 | #include "elf/mips.h" |
49 | #include "elf-bfd.h" | |
2475bac3 | 50 | #include "symcat.h" |
a4b8ebc8 | 51 | #include "sim-regno.h" |
a89aa300 | 52 | #include "dis-asm.h" |
edfae063 AC |
53 | #include "frame-unwind.h" |
54 | #include "frame-base.h" | |
55 | #include "trad-frame.h" | |
7d9b040b | 56 | #include "infcall.h" |
fed7ba43 | 57 | #include "floatformat.h" |
29709017 DJ |
58 | #include "remote.h" |
59 | #include "target-descriptions.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 | |
24e05951 | 65 | /* A useful bit in the CP0 status register (MIPS_PS_REGNUM). */ |
dd824b04 DJ |
66 | /* This bit is set if we are emulating 32-bit FPRs on a 64-bit chip. */ |
67 | #define ST0_FR (1 << 26) | |
68 | ||
b0069a17 AC |
69 | /* The sizes of floating point registers. */ |
70 | ||
71 | enum | |
72 | { | |
73 | MIPS_FPU_SINGLE_REGSIZE = 4, | |
74 | MIPS_FPU_DOUBLE_REGSIZE = 8 | |
75 | }; | |
76 | ||
0dadbba0 | 77 | |
2e4ebe70 DJ |
78 | static const char *mips_abi_string; |
79 | ||
80 | static const char *mips_abi_strings[] = { | |
81 | "auto", | |
82 | "n32", | |
83 | "o32", | |
28d169de | 84 | "n64", |
2e4ebe70 DJ |
85 | "o64", |
86 | "eabi32", | |
87 | "eabi64", | |
88 | NULL | |
89 | }; | |
90 | ||
d929b26f AC |
91 | /* Various MIPS ISA options (related to stack analysis) can be |
92 | overridden dynamically. Establish an enum/array for managing | |
93 | them. */ | |
94 | ||
53904c9e AC |
95 | static const char size_auto[] = "auto"; |
96 | static const char size_32[] = "32"; | |
97 | static const char size_64[] = "64"; | |
d929b26f | 98 | |
53904c9e | 99 | static const char *size_enums[] = { |
d929b26f AC |
100 | size_auto, |
101 | size_32, | |
102 | size_64, | |
a5ea2558 AC |
103 | 0 |
104 | }; | |
105 | ||
7a292a7a | 106 | /* Some MIPS boards don't support floating point while others only |
ceae6e75 | 107 | support single-precision floating-point operations. */ |
c906108c SS |
108 | |
109 | enum mips_fpu_type | |
6d82d43b AC |
110 | { |
111 | MIPS_FPU_DOUBLE, /* Full double precision floating point. */ | |
112 | MIPS_FPU_SINGLE, /* Single precision floating point (R4650). */ | |
113 | MIPS_FPU_NONE /* No floating point. */ | |
114 | }; | |
c906108c SS |
115 | |
116 | #ifndef MIPS_DEFAULT_FPU_TYPE | |
117 | #define MIPS_DEFAULT_FPU_TYPE MIPS_FPU_DOUBLE | |
118 | #endif | |
119 | static int mips_fpu_type_auto = 1; | |
120 | static enum mips_fpu_type mips_fpu_type = MIPS_DEFAULT_FPU_TYPE; | |
7a292a7a | 121 | |
9ace0497 | 122 | static int mips_debug = 0; |
7a292a7a | 123 | |
29709017 DJ |
124 | /* Properties (for struct target_desc) describing the g/G packet |
125 | layout. */ | |
126 | #define PROPERTY_GP32 "internal: transfers-32bit-registers" | |
127 | #define PROPERTY_GP64 "internal: transfers-64bit-registers" | |
128 | ||
c2d11a7d JM |
129 | /* MIPS specific per-architecture information */ |
130 | struct gdbarch_tdep | |
6d82d43b AC |
131 | { |
132 | /* from the elf header */ | |
133 | int elf_flags; | |
134 | ||
135 | /* mips options */ | |
136 | enum mips_abi mips_abi; | |
137 | enum mips_abi found_abi; | |
138 | enum mips_fpu_type mips_fpu_type; | |
139 | int mips_last_arg_regnum; | |
140 | int mips_last_fp_arg_regnum; | |
6d82d43b AC |
141 | int default_mask_address_p; |
142 | /* Is the target using 64-bit raw integer registers but only | |
143 | storing a left-aligned 32-bit value in each? */ | |
144 | int mips64_transfers_32bit_regs_p; | |
145 | /* Indexes for various registers. IRIX and embedded have | |
146 | different values. This contains the "public" fields. Don't | |
147 | add any that do not need to be public. */ | |
148 | const struct mips_regnum *regnum; | |
149 | /* Register names table for the current register set. */ | |
150 | const char **mips_processor_reg_names; | |
29709017 DJ |
151 | |
152 | /* The size of register data available from the target, if known. | |
153 | This doesn't quite obsolete the manual | |
154 | mips64_transfers_32bit_regs_p, since that is documented to force | |
155 | left alignment even for big endian (very strange). */ | |
156 | int register_size_valid_p; | |
157 | int register_size; | |
6d82d43b | 158 | }; |
c2d11a7d | 159 | |
fed7ba43 JB |
160 | static int |
161 | n32n64_floatformat_always_valid (const struct floatformat *fmt, | |
2244f671 | 162 | const void *from) |
fed7ba43 JB |
163 | { |
164 | return 1; | |
165 | } | |
166 | ||
167 | /* FIXME: brobecker/2004-08-08: Long Double values are 128 bit long. | |
168 | They are implemented as a pair of 64bit doubles where the high | |
169 | part holds the result of the operation rounded to double, and | |
170 | the low double holds the difference between the exact result and | |
171 | the rounded result. So "high" + "low" contains the result with | |
172 | added precision. Unfortunately, the floatformat structure used | |
173 | by GDB is not powerful enough to describe this format. As a temporary | |
174 | measure, we define a 128bit floatformat that only uses the high part. | |
175 | We lose a bit of precision but that's probably the best we can do | |
176 | for now with the current infrastructure. */ | |
177 | ||
178 | static const struct floatformat floatformat_n32n64_long_double_big = | |
179 | { | |
180 | floatformat_big, 128, 0, 1, 11, 1023, 2047, 12, 52, | |
181 | floatformat_intbit_no, | |
8da61cc4 | 182 | "floatformat_n32n64_long_double_big", |
fed7ba43 JB |
183 | n32n64_floatformat_always_valid |
184 | }; | |
185 | ||
8da61cc4 DJ |
186 | static const struct floatformat *floatformats_n32n64_long[BFD_ENDIAN_UNKNOWN] = |
187 | { | |
188 | &floatformat_n32n64_long_double_big, | |
189 | &floatformat_n32n64_long_double_big | |
190 | }; | |
191 | ||
56cea623 AC |
192 | const struct mips_regnum * |
193 | mips_regnum (struct gdbarch *gdbarch) | |
194 | { | |
195 | return gdbarch_tdep (gdbarch)->regnum; | |
196 | } | |
197 | ||
198 | static int | |
199 | mips_fpa0_regnum (struct gdbarch *gdbarch) | |
200 | { | |
201 | return mips_regnum (gdbarch)->fp0 + 12; | |
202 | } | |
203 | ||
0dadbba0 | 204 | #define MIPS_EABI (gdbarch_tdep (current_gdbarch)->mips_abi == MIPS_ABI_EABI32 \ |
216a600b | 205 | || gdbarch_tdep (current_gdbarch)->mips_abi == MIPS_ABI_EABI64) |
c2d11a7d | 206 | |
c2d11a7d | 207 | #define MIPS_LAST_FP_ARG_REGNUM (gdbarch_tdep (current_gdbarch)->mips_last_fp_arg_regnum) |
c2d11a7d | 208 | |
c2d11a7d | 209 | #define MIPS_LAST_ARG_REGNUM (gdbarch_tdep (current_gdbarch)->mips_last_arg_regnum) |
c2d11a7d | 210 | |
c2d11a7d | 211 | #define MIPS_FPU_TYPE (gdbarch_tdep (current_gdbarch)->mips_fpu_type) |
c2d11a7d | 212 | |
95404a3e AC |
213 | /* MIPS16 function addresses are odd (bit 0 is set). Here are some |
214 | functions to test, set, or clear bit 0 of addresses. */ | |
215 | ||
216 | static CORE_ADDR | |
217 | is_mips16_addr (CORE_ADDR addr) | |
218 | { | |
219 | return ((addr) & 1); | |
220 | } | |
221 | ||
95404a3e AC |
222 | static CORE_ADDR |
223 | unmake_mips16_addr (CORE_ADDR addr) | |
224 | { | |
5b652102 | 225 | return ((addr) & ~(CORE_ADDR) 1); |
95404a3e AC |
226 | } |
227 | ||
22540ece AC |
228 | /* Return the contents of register REGNUM as a signed integer. */ |
229 | ||
230 | static LONGEST | |
231 | read_signed_register (int regnum) | |
232 | { | |
1d93fe1a AC |
233 | LONGEST val; |
234 | regcache_cooked_read_signed (current_regcache, regnum, &val); | |
235 | return val; | |
22540ece AC |
236 | } |
237 | ||
238 | static LONGEST | |
239 | read_signed_register_pid (int regnum, ptid_t ptid) | |
240 | { | |
241 | ptid_t save_ptid; | |
242 | LONGEST retval; | |
243 | ||
244 | if (ptid_equal (ptid, inferior_ptid)) | |
245 | return read_signed_register (regnum); | |
246 | ||
247 | save_ptid = inferior_ptid; | |
248 | ||
249 | inferior_ptid = ptid; | |
250 | ||
251 | retval = read_signed_register (regnum); | |
252 | ||
253 | inferior_ptid = save_ptid; | |
254 | ||
255 | return retval; | |
256 | } | |
257 | ||
d1973055 KB |
258 | /* Return the MIPS ABI associated with GDBARCH. */ |
259 | enum mips_abi | |
260 | mips_abi (struct gdbarch *gdbarch) | |
261 | { | |
262 | return gdbarch_tdep (gdbarch)->mips_abi; | |
263 | } | |
264 | ||
4246e332 | 265 | int |
1b13c4f6 | 266 | mips_isa_regsize (struct gdbarch *gdbarch) |
4246e332 | 267 | { |
29709017 DJ |
268 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
269 | ||
270 | /* If we know how big the registers are, use that size. */ | |
271 | if (tdep->register_size_valid_p) | |
272 | return tdep->register_size; | |
273 | ||
274 | /* Fall back to the previous behavior. */ | |
4246e332 AC |
275 | return (gdbarch_bfd_arch_info (gdbarch)->bits_per_word |
276 | / gdbarch_bfd_arch_info (gdbarch)->bits_per_byte); | |
277 | } | |
278 | ||
480d3dd2 AC |
279 | /* Return the currently configured (or set) saved register size. */ |
280 | ||
1b13c4f6 | 281 | static const char *mips_abi_regsize_string = size_auto; |
480d3dd2 | 282 | |
e6bc2e8a | 283 | unsigned int |
13326b4e | 284 | mips_abi_regsize (struct gdbarch *gdbarch) |
d929b26f | 285 | { |
1b13c4f6 | 286 | if (mips_abi_regsize_string == size_auto) |
13326b4e AC |
287 | switch (mips_abi (gdbarch)) |
288 | { | |
289 | case MIPS_ABI_EABI32: | |
290 | case MIPS_ABI_O32: | |
291 | return 4; | |
292 | case MIPS_ABI_N32: | |
293 | case MIPS_ABI_N64: | |
294 | case MIPS_ABI_O64: | |
295 | case MIPS_ABI_EABI64: | |
296 | return 8; | |
297 | case MIPS_ABI_UNKNOWN: | |
298 | case MIPS_ABI_LAST: | |
299 | default: | |
e2e0b3e5 | 300 | internal_error (__FILE__, __LINE__, _("bad switch")); |
13326b4e | 301 | } |
1b13c4f6 | 302 | else if (mips_abi_regsize_string == size_64) |
d929b26f | 303 | return 8; |
1b13c4f6 | 304 | else /* if (mips_abi_regsize_string == size_32) */ |
d929b26f AC |
305 | return 4; |
306 | } | |
307 | ||
71b8ef93 | 308 | /* Functions for setting and testing a bit in a minimal symbol that |
5a89d8aa | 309 | marks it as 16-bit function. The MSB of the minimal symbol's |
f594e5e9 | 310 | "info" field is used for this purpose. |
5a89d8aa MS |
311 | |
312 | ELF_MAKE_MSYMBOL_SPECIAL tests whether an ELF symbol is "special", | |
313 | i.e. refers to a 16-bit function, and sets a "special" bit in a | |
314 | minimal symbol to mark it as a 16-bit function | |
315 | ||
f594e5e9 | 316 | MSYMBOL_IS_SPECIAL tests the "special" bit in a minimal symbol */ |
5a89d8aa | 317 | |
5a89d8aa | 318 | static void |
6d82d43b AC |
319 | mips_elf_make_msymbol_special (asymbol * sym, struct minimal_symbol *msym) |
320 | { | |
321 | if (((elf_symbol_type *) (sym))->internal_elf_sym.st_other == STO_MIPS16) | |
322 | { | |
323 | MSYMBOL_INFO (msym) = (char *) | |
324 | (((long) MSYMBOL_INFO (msym)) | 0x80000000); | |
325 | SYMBOL_VALUE_ADDRESS (msym) |= 1; | |
326 | } | |
5a89d8aa MS |
327 | } |
328 | ||
71b8ef93 MS |
329 | static int |
330 | msymbol_is_special (struct minimal_symbol *msym) | |
331 | { | |
332 | return (((long) MSYMBOL_INFO (msym) & 0x80000000) != 0); | |
333 | } | |
334 | ||
88658117 AC |
335 | /* XFER a value from the big/little/left end of the register. |
336 | Depending on the size of the value it might occupy the entire | |
337 | register or just part of it. Make an allowance for this, aligning | |
338 | things accordingly. */ | |
339 | ||
340 | static void | |
341 | mips_xfer_register (struct regcache *regcache, int reg_num, int length, | |
870cd05e MK |
342 | enum bfd_endian endian, gdb_byte *in, |
343 | const gdb_byte *out, int buf_offset) | |
88658117 | 344 | { |
88658117 | 345 | int reg_offset = 0; |
a4b8ebc8 | 346 | gdb_assert (reg_num >= NUM_REGS); |
cb1d2653 AC |
347 | /* Need to transfer the left or right part of the register, based on |
348 | the targets byte order. */ | |
88658117 AC |
349 | switch (endian) |
350 | { | |
351 | case BFD_ENDIAN_BIG: | |
719ec221 | 352 | reg_offset = register_size (current_gdbarch, reg_num) - length; |
88658117 AC |
353 | break; |
354 | case BFD_ENDIAN_LITTLE: | |
355 | reg_offset = 0; | |
356 | break; | |
6d82d43b | 357 | case BFD_ENDIAN_UNKNOWN: /* Indicates no alignment. */ |
88658117 AC |
358 | reg_offset = 0; |
359 | break; | |
360 | default: | |
e2e0b3e5 | 361 | internal_error (__FILE__, __LINE__, _("bad switch")); |
88658117 AC |
362 | } |
363 | if (mips_debug) | |
cb1d2653 AC |
364 | fprintf_unfiltered (gdb_stderr, |
365 | "xfer $%d, reg offset %d, buf offset %d, length %d, ", | |
366 | reg_num, reg_offset, buf_offset, length); | |
88658117 AC |
367 | if (mips_debug && out != NULL) |
368 | { | |
369 | int i; | |
cb1d2653 | 370 | fprintf_unfiltered (gdb_stdlog, "out "); |
88658117 | 371 | for (i = 0; i < length; i++) |
cb1d2653 | 372 | fprintf_unfiltered (gdb_stdlog, "%02x", out[buf_offset + i]); |
88658117 AC |
373 | } |
374 | if (in != NULL) | |
6d82d43b AC |
375 | regcache_cooked_read_part (regcache, reg_num, reg_offset, length, |
376 | in + buf_offset); | |
88658117 | 377 | if (out != NULL) |
6d82d43b AC |
378 | regcache_cooked_write_part (regcache, reg_num, reg_offset, length, |
379 | out + buf_offset); | |
88658117 AC |
380 | if (mips_debug && in != NULL) |
381 | { | |
382 | int i; | |
cb1d2653 | 383 | fprintf_unfiltered (gdb_stdlog, "in "); |
88658117 | 384 | for (i = 0; i < length; i++) |
cb1d2653 | 385 | fprintf_unfiltered (gdb_stdlog, "%02x", in[buf_offset + i]); |
88658117 AC |
386 | } |
387 | if (mips_debug) | |
388 | fprintf_unfiltered (gdb_stdlog, "\n"); | |
389 | } | |
390 | ||
dd824b04 DJ |
391 | /* Determine if a MIPS3 or later cpu is operating in MIPS{1,2} FPU |
392 | compatiblity mode. A return value of 1 means that we have | |
393 | physical 64-bit registers, but should treat them as 32-bit registers. */ | |
394 | ||
395 | static int | |
396 | mips2_fp_compat (void) | |
397 | { | |
398 | /* MIPS1 and MIPS2 have only 32 bit FPRs, and the FR bit is not | |
399 | meaningful. */ | |
6d82d43b AC |
400 | if (register_size (current_gdbarch, mips_regnum (current_gdbarch)->fp0) == |
401 | 4) | |
dd824b04 DJ |
402 | return 0; |
403 | ||
404 | #if 0 | |
405 | /* FIXME drow 2002-03-10: This is disabled until we can do it consistently, | |
406 | in all the places we deal with FP registers. PR gdb/413. */ | |
407 | /* Otherwise check the FR bit in the status register - it controls | |
408 | the FP compatiblity mode. If it is clear we are in compatibility | |
409 | mode. */ | |
24e05951 | 410 | if ((read_register (MIPS_PS_REGNUM) & ST0_FR) == 0) |
dd824b04 DJ |
411 | return 1; |
412 | #endif | |
361d1df0 | 413 | |
dd824b04 DJ |
414 | return 0; |
415 | } | |
416 | ||
d929b26f | 417 | /* The amount of space reserved on the stack for registers. This is |
1b13c4f6 | 418 | different to MIPS_ABI_REGSIZE as it determines the alignment of |
d929b26f AC |
419 | data allocated after the registers have run out. */ |
420 | ||
53904c9e | 421 | static const char *mips_stack_argsize_string = size_auto; |
d929b26f AC |
422 | |
423 | static unsigned int | |
13326b4e | 424 | mips_stack_argsize (struct gdbarch *gdbarch) |
d929b26f AC |
425 | { |
426 | if (mips_stack_argsize_string == size_auto) | |
13326b4e | 427 | return mips_abi_regsize (gdbarch); |
d929b26f AC |
428 | else if (mips_stack_argsize_string == size_64) |
429 | return 8; | |
6d82d43b | 430 | else /* if (mips_stack_argsize_string == size_32) */ |
d929b26f AC |
431 | return 4; |
432 | } | |
433 | ||
7a292a7a | 434 | #define VM_MIN_ADDRESS (CORE_ADDR)0x400000 |
c906108c | 435 | |
a14ed312 | 436 | static CORE_ADDR heuristic_proc_start (CORE_ADDR); |
c906108c | 437 | |
a14ed312 | 438 | static CORE_ADDR read_next_frame_reg (struct frame_info *, int); |
c906108c | 439 | |
a14ed312 | 440 | static void reinit_frame_cache_sfunc (char *, int, struct cmd_list_element *); |
c906108c | 441 | |
67b2c998 DJ |
442 | static struct type *mips_float_register_type (void); |
443 | static struct type *mips_double_register_type (void); | |
444 | ||
acdb74a0 AC |
445 | /* The list of available "set mips " and "show mips " commands */ |
446 | ||
447 | static struct cmd_list_element *setmipscmdlist = NULL; | |
448 | static struct cmd_list_element *showmipscmdlist = NULL; | |
449 | ||
5e2e9765 KB |
450 | /* Integer registers 0 thru 31 are handled explicitly by |
451 | mips_register_name(). Processor specific registers 32 and above | |
691c0433 AC |
452 | are listed in the followign tables. */ |
453 | ||
6d82d43b AC |
454 | enum |
455 | { NUM_MIPS_PROCESSOR_REGS = (90 - 32) }; | |
691c0433 AC |
456 | |
457 | /* Generic MIPS. */ | |
458 | ||
459 | static const char *mips_generic_reg_names[NUM_MIPS_PROCESSOR_REGS] = { | |
6d82d43b AC |
460 | "sr", "lo", "hi", "bad", "cause", "pc", |
461 | "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", | |
462 | "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", | |
463 | "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23", | |
464 | "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", | |
465 | "fsr", "fir", "" /*"fp" */ , "", | |
466 | "", "", "", "", "", "", "", "", | |
467 | "", "", "", "", "", "", "", "", | |
691c0433 AC |
468 | }; |
469 | ||
470 | /* Names of IDT R3041 registers. */ | |
471 | ||
472 | static const char *mips_r3041_reg_names[] = { | |
6d82d43b AC |
473 | "sr", "lo", "hi", "bad", "cause", "pc", |
474 | "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", | |
475 | "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", | |
476 | "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23", | |
477 | "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", | |
478 | "fsr", "fir", "", /*"fp" */ "", | |
479 | "", "", "bus", "ccfg", "", "", "", "", | |
480 | "", "", "port", "cmp", "", "", "epc", "prid", | |
691c0433 AC |
481 | }; |
482 | ||
483 | /* Names of tx39 registers. */ | |
484 | ||
485 | static const char *mips_tx39_reg_names[NUM_MIPS_PROCESSOR_REGS] = { | |
6d82d43b AC |
486 | "sr", "lo", "hi", "bad", "cause", "pc", |
487 | "", "", "", "", "", "", "", "", | |
488 | "", "", "", "", "", "", "", "", | |
489 | "", "", "", "", "", "", "", "", | |
490 | "", "", "", "", "", "", "", "", | |
491 | "", "", "", "", | |
492 | "", "", "", "", "", "", "", "", | |
493 | "", "", "config", "cache", "debug", "depc", "epc", "" | |
691c0433 AC |
494 | }; |
495 | ||
496 | /* Names of IRIX registers. */ | |
497 | static const char *mips_irix_reg_names[NUM_MIPS_PROCESSOR_REGS] = { | |
6d82d43b AC |
498 | "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", |
499 | "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", | |
500 | "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23", | |
501 | "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", | |
502 | "pc", "cause", "bad", "hi", "lo", "fsr", "fir" | |
691c0433 AC |
503 | }; |
504 | ||
cce74817 | 505 | |
5e2e9765 | 506 | /* Return the name of the register corresponding to REGNO. */ |
5a89d8aa | 507 | static const char * |
5e2e9765 | 508 | mips_register_name (int regno) |
cce74817 | 509 | { |
691c0433 | 510 | struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); |
5e2e9765 KB |
511 | /* GPR names for all ABIs other than n32/n64. */ |
512 | static char *mips_gpr_names[] = { | |
6d82d43b AC |
513 | "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3", |
514 | "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", | |
515 | "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7", | |
516 | "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra", | |
5e2e9765 KB |
517 | }; |
518 | ||
519 | /* GPR names for n32 and n64 ABIs. */ | |
520 | static char *mips_n32_n64_gpr_names[] = { | |
6d82d43b AC |
521 | "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3", |
522 | "a4", "a5", "a6", "a7", "t0", "t1", "t2", "t3", | |
523 | "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7", | |
524 | "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra" | |
5e2e9765 KB |
525 | }; |
526 | ||
527 | enum mips_abi abi = mips_abi (current_gdbarch); | |
528 | ||
a4b8ebc8 AC |
529 | /* Map [NUM_REGS .. 2*NUM_REGS) onto the raw registers, but then |
530 | don't make the raw register names visible. */ | |
531 | int rawnum = regno % NUM_REGS; | |
532 | if (regno < NUM_REGS) | |
533 | return ""; | |
534 | ||
5e2e9765 KB |
535 | /* The MIPS integer registers are always mapped from 0 to 31. The |
536 | names of the registers (which reflects the conventions regarding | |
537 | register use) vary depending on the ABI. */ | |
a4b8ebc8 | 538 | if (0 <= rawnum && rawnum < 32) |
5e2e9765 KB |
539 | { |
540 | if (abi == MIPS_ABI_N32 || abi == MIPS_ABI_N64) | |
a4b8ebc8 | 541 | return mips_n32_n64_gpr_names[rawnum]; |
5e2e9765 | 542 | else |
a4b8ebc8 | 543 | return mips_gpr_names[rawnum]; |
5e2e9765 | 544 | } |
a4b8ebc8 | 545 | else if (32 <= rawnum && rawnum < NUM_REGS) |
691c0433 AC |
546 | { |
547 | gdb_assert (rawnum - 32 < NUM_MIPS_PROCESSOR_REGS); | |
548 | return tdep->mips_processor_reg_names[rawnum - 32]; | |
549 | } | |
5e2e9765 KB |
550 | else |
551 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 552 | _("mips_register_name: bad register number %d"), rawnum); |
cce74817 | 553 | } |
5e2e9765 | 554 | |
a4b8ebc8 | 555 | /* Return the groups that a MIPS register can be categorised into. */ |
c5aa993b | 556 | |
a4b8ebc8 AC |
557 | static int |
558 | mips_register_reggroup_p (struct gdbarch *gdbarch, int regnum, | |
559 | struct reggroup *reggroup) | |
560 | { | |
561 | int vector_p; | |
562 | int float_p; | |
563 | int raw_p; | |
564 | int rawnum = regnum % NUM_REGS; | |
565 | int pseudo = regnum / NUM_REGS; | |
566 | if (reggroup == all_reggroup) | |
567 | return pseudo; | |
568 | vector_p = TYPE_VECTOR (register_type (gdbarch, regnum)); | |
569 | float_p = TYPE_CODE (register_type (gdbarch, regnum)) == TYPE_CODE_FLT; | |
570 | /* FIXME: cagney/2003-04-13: Can't yet use gdbarch_num_regs | |
571 | (gdbarch), as not all architectures are multi-arch. */ | |
572 | raw_p = rawnum < NUM_REGS; | |
6d82d43b | 573 | if (REGISTER_NAME (regnum) == NULL || REGISTER_NAME (regnum)[0] == '\0') |
a4b8ebc8 AC |
574 | return 0; |
575 | if (reggroup == float_reggroup) | |
576 | return float_p && pseudo; | |
577 | if (reggroup == vector_reggroup) | |
578 | return vector_p && pseudo; | |
579 | if (reggroup == general_reggroup) | |
580 | return (!vector_p && !float_p) && pseudo; | |
581 | /* Save the pseudo registers. Need to make certain that any code | |
582 | extracting register values from a saved register cache also uses | |
583 | pseudo registers. */ | |
584 | if (reggroup == save_reggroup) | |
585 | return raw_p && pseudo; | |
586 | /* Restore the same pseudo register. */ | |
587 | if (reggroup == restore_reggroup) | |
588 | return raw_p && pseudo; | |
6d82d43b | 589 | return 0; |
a4b8ebc8 AC |
590 | } |
591 | ||
592 | /* Map the symbol table registers which live in the range [1 * | |
593 | NUM_REGS .. 2 * NUM_REGS) back onto the corresponding raw | |
47ebcfbe | 594 | registers. Take care of alignment and size problems. */ |
c5aa993b | 595 | |
a4b8ebc8 AC |
596 | static void |
597 | mips_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache, | |
47a35522 | 598 | int cookednum, gdb_byte *buf) |
a4b8ebc8 | 599 | { |
47ebcfbe | 600 | int rawnum = cookednum % NUM_REGS; |
a4b8ebc8 | 601 | gdb_assert (cookednum >= NUM_REGS && cookednum < 2 * NUM_REGS); |
47ebcfbe | 602 | if (register_size (gdbarch, rawnum) == register_size (gdbarch, cookednum)) |
de38af99 | 603 | regcache_raw_read (regcache, rawnum, buf); |
6d82d43b AC |
604 | else if (register_size (gdbarch, rawnum) > |
605 | register_size (gdbarch, cookednum)) | |
47ebcfbe AC |
606 | { |
607 | if (gdbarch_tdep (gdbarch)->mips64_transfers_32bit_regs_p | |
608 | || TARGET_BYTE_ORDER == BFD_ENDIAN_LITTLE) | |
609 | regcache_raw_read_part (regcache, rawnum, 0, 4, buf); | |
610 | else | |
611 | regcache_raw_read_part (regcache, rawnum, 4, 4, buf); | |
612 | } | |
613 | else | |
e2e0b3e5 | 614 | internal_error (__FILE__, __LINE__, _("bad register size")); |
a4b8ebc8 AC |
615 | } |
616 | ||
617 | static void | |
6d82d43b AC |
618 | mips_pseudo_register_write (struct gdbarch *gdbarch, |
619 | struct regcache *regcache, int cookednum, | |
47a35522 | 620 | const gdb_byte *buf) |
a4b8ebc8 | 621 | { |
47ebcfbe | 622 | int rawnum = cookednum % NUM_REGS; |
a4b8ebc8 | 623 | gdb_assert (cookednum >= NUM_REGS && cookednum < 2 * NUM_REGS); |
47ebcfbe | 624 | if (register_size (gdbarch, rawnum) == register_size (gdbarch, cookednum)) |
de38af99 | 625 | regcache_raw_write (regcache, rawnum, buf); |
6d82d43b AC |
626 | else if (register_size (gdbarch, rawnum) > |
627 | register_size (gdbarch, cookednum)) | |
47ebcfbe AC |
628 | { |
629 | if (gdbarch_tdep (gdbarch)->mips64_transfers_32bit_regs_p | |
630 | || TARGET_BYTE_ORDER == BFD_ENDIAN_LITTLE) | |
631 | regcache_raw_write_part (regcache, rawnum, 0, 4, buf); | |
632 | else | |
633 | regcache_raw_write_part (regcache, rawnum, 4, 4, buf); | |
634 | } | |
635 | else | |
e2e0b3e5 | 636 | internal_error (__FILE__, __LINE__, _("bad register size")); |
a4b8ebc8 | 637 | } |
c5aa993b | 638 | |
c906108c | 639 | /* Table to translate MIPS16 register field to actual register number. */ |
6d82d43b | 640 | static int mips16_to_32_reg[8] = { 16, 17, 2, 3, 4, 5, 6, 7 }; |
c906108c SS |
641 | |
642 | /* Heuristic_proc_start may hunt through the text section for a long | |
643 | time across a 2400 baud serial line. Allows the user to limit this | |
644 | search. */ | |
645 | ||
646 | static unsigned int heuristic_fence_post = 0; | |
647 | ||
46cd78fb | 648 | /* Number of bytes of storage in the actual machine representation for |
719ec221 AC |
649 | register N. NOTE: This defines the pseudo register type so need to |
650 | rebuild the architecture vector. */ | |
43e526b9 JM |
651 | |
652 | static int mips64_transfers_32bit_regs_p = 0; | |
653 | ||
719ec221 AC |
654 | static void |
655 | set_mips64_transfers_32bit_regs (char *args, int from_tty, | |
656 | struct cmd_list_element *c) | |
43e526b9 | 657 | { |
719ec221 AC |
658 | struct gdbarch_info info; |
659 | gdbarch_info_init (&info); | |
660 | /* FIXME: cagney/2003-11-15: Should be setting a field in "info" | |
661 | instead of relying on globals. Doing that would let generic code | |
662 | handle the search for this specific architecture. */ | |
663 | if (!gdbarch_update_p (info)) | |
a4b8ebc8 | 664 | { |
719ec221 | 665 | mips64_transfers_32bit_regs_p = 0; |
8a3fe4f8 | 666 | error (_("32-bit compatibility mode not supported")); |
a4b8ebc8 | 667 | } |
a4b8ebc8 AC |
668 | } |
669 | ||
47ebcfbe | 670 | /* Convert to/from a register and the corresponding memory value. */ |
43e526b9 | 671 | |
ff2e87ac AC |
672 | static int |
673 | mips_convert_register_p (int regnum, struct type *type) | |
674 | { | |
675 | return (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG | |
719ec221 | 676 | && register_size (current_gdbarch, regnum) == 4 |
87783b8b AC |
677 | && (regnum % NUM_REGS) >= mips_regnum (current_gdbarch)->fp0 |
678 | && (regnum % NUM_REGS) < mips_regnum (current_gdbarch)->fp0 + 32 | |
6d82d43b | 679 | && TYPE_CODE (type) == TYPE_CODE_FLT && TYPE_LENGTH (type) == 8); |
ff2e87ac AC |
680 | } |
681 | ||
42c466d7 | 682 | static void |
ff2e87ac | 683 | mips_register_to_value (struct frame_info *frame, int regnum, |
47a35522 | 684 | struct type *type, gdb_byte *to) |
102182a9 | 685 | { |
47a35522 MK |
686 | get_frame_register (frame, regnum + 0, to + 4); |
687 | get_frame_register (frame, regnum + 1, to + 0); | |
102182a9 MS |
688 | } |
689 | ||
42c466d7 | 690 | static void |
ff2e87ac | 691 | mips_value_to_register (struct frame_info *frame, int regnum, |
47a35522 | 692 | struct type *type, const gdb_byte *from) |
102182a9 | 693 | { |
47a35522 MK |
694 | put_frame_register (frame, regnum + 0, from + 4); |
695 | put_frame_register (frame, regnum + 1, from + 0); | |
102182a9 MS |
696 | } |
697 | ||
a4b8ebc8 AC |
698 | /* Return the GDB type object for the "standard" data type of data in |
699 | register REG. */ | |
78fde5f8 KB |
700 | |
701 | static struct type * | |
a4b8ebc8 AC |
702 | mips_register_type (struct gdbarch *gdbarch, int regnum) |
703 | { | |
5ef80fb0 | 704 | gdb_assert (regnum >= 0 && regnum < 2 * NUM_REGS); |
56cea623 AC |
705 | if ((regnum % NUM_REGS) >= mips_regnum (current_gdbarch)->fp0 |
706 | && (regnum % NUM_REGS) < mips_regnum (current_gdbarch)->fp0 + 32) | |
a6425924 | 707 | { |
5ef80fb0 | 708 | /* The floating-point registers raw, or cooked, always match |
1b13c4f6 | 709 | mips_isa_regsize(), and also map 1:1, byte for byte. */ |
8da61cc4 DJ |
710 | if (mips_isa_regsize (gdbarch) == 4) |
711 | return builtin_type_ieee_single; | |
712 | else | |
713 | return builtin_type_ieee_double; | |
a6425924 | 714 | } |
d5ac5a39 AC |
715 | else if (regnum < NUM_REGS) |
716 | { | |
717 | /* The raw or ISA registers. These are all sized according to | |
718 | the ISA regsize. */ | |
719 | if (mips_isa_regsize (gdbarch) == 4) | |
720 | return builtin_type_int32; | |
721 | else | |
722 | return builtin_type_int64; | |
723 | } | |
78fde5f8 | 724 | else |
d5ac5a39 AC |
725 | { |
726 | /* The cooked or ABI registers. These are sized according to | |
727 | the ABI (with a few complications). */ | |
728 | if (regnum >= (NUM_REGS | |
729 | + mips_regnum (current_gdbarch)->fp_control_status) | |
607fc93c | 730 | && regnum <= NUM_REGS + MIPS_LAST_EMBED_REGNUM) |
d5ac5a39 AC |
731 | /* The pseudo/cooked view of the embedded registers is always |
732 | 32-bit. The raw view is handled below. */ | |
733 | return builtin_type_int32; | |
734 | else if (gdbarch_tdep (gdbarch)->mips64_transfers_32bit_regs_p) | |
735 | /* The target, while possibly using a 64-bit register buffer, | |
736 | is only transfering 32-bits of each integer register. | |
737 | Reflect this in the cooked/pseudo (ABI) register value. */ | |
738 | return builtin_type_int32; | |
739 | else if (mips_abi_regsize (gdbarch) == 4) | |
740 | /* The ABI is restricted to 32-bit registers (the ISA could be | |
741 | 32- or 64-bit). */ | |
742 | return builtin_type_int32; | |
743 | else | |
744 | /* 64-bit ABI. */ | |
745 | return builtin_type_int64; | |
746 | } | |
78fde5f8 KB |
747 | } |
748 | ||
bcb0cc15 MS |
749 | /* TARGET_READ_SP -- Remove useless bits from the stack pointer. */ |
750 | ||
751 | static CORE_ADDR | |
752 | mips_read_sp (void) | |
753 | { | |
f10683bb | 754 | return read_signed_register (MIPS_SP_REGNUM); |
bcb0cc15 MS |
755 | } |
756 | ||
c906108c | 757 | /* Should the upper word of 64-bit addresses be zeroed? */ |
7f19b9a2 | 758 | enum auto_boolean mask_address_var = AUTO_BOOLEAN_AUTO; |
4014092b AC |
759 | |
760 | static int | |
480d3dd2 | 761 | mips_mask_address_p (struct gdbarch_tdep *tdep) |
4014092b AC |
762 | { |
763 | switch (mask_address_var) | |
764 | { | |
7f19b9a2 | 765 | case AUTO_BOOLEAN_TRUE: |
4014092b | 766 | return 1; |
7f19b9a2 | 767 | case AUTO_BOOLEAN_FALSE: |
4014092b AC |
768 | return 0; |
769 | break; | |
7f19b9a2 | 770 | case AUTO_BOOLEAN_AUTO: |
480d3dd2 | 771 | return tdep->default_mask_address_p; |
4014092b | 772 | default: |
e2e0b3e5 | 773 | internal_error (__FILE__, __LINE__, _("mips_mask_address_p: bad switch")); |
4014092b | 774 | return -1; |
361d1df0 | 775 | } |
4014092b AC |
776 | } |
777 | ||
778 | static void | |
08546159 AC |
779 | show_mask_address (struct ui_file *file, int from_tty, |
780 | struct cmd_list_element *c, const char *value) | |
4014092b | 781 | { |
480d3dd2 | 782 | struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); |
08546159 AC |
783 | |
784 | deprecated_show_value_hack (file, from_tty, c, value); | |
4014092b AC |
785 | switch (mask_address_var) |
786 | { | |
7f19b9a2 | 787 | case AUTO_BOOLEAN_TRUE: |
4014092b AC |
788 | printf_filtered ("The 32 bit mips address mask is enabled\n"); |
789 | break; | |
7f19b9a2 | 790 | case AUTO_BOOLEAN_FALSE: |
4014092b AC |
791 | printf_filtered ("The 32 bit mips address mask is disabled\n"); |
792 | break; | |
7f19b9a2 | 793 | case AUTO_BOOLEAN_AUTO: |
6d82d43b AC |
794 | printf_filtered |
795 | ("The 32 bit address mask is set automatically. Currently %s\n", | |
796 | mips_mask_address_p (tdep) ? "enabled" : "disabled"); | |
4014092b AC |
797 | break; |
798 | default: | |
e2e0b3e5 | 799 | internal_error (__FILE__, __LINE__, _("show_mask_address: bad switch")); |
4014092b | 800 | break; |
361d1df0 | 801 | } |
4014092b | 802 | } |
c906108c | 803 | |
c906108c SS |
804 | /* Tell if the program counter value in MEMADDR is in a MIPS16 function. */ |
805 | ||
0fe7e7c8 AC |
806 | int |
807 | mips_pc_is_mips16 (CORE_ADDR memaddr) | |
c906108c SS |
808 | { |
809 | struct minimal_symbol *sym; | |
810 | ||
811 | /* If bit 0 of the address is set, assume this is a MIPS16 address. */ | |
95404a3e | 812 | if (is_mips16_addr (memaddr)) |
c906108c SS |
813 | return 1; |
814 | ||
815 | /* A flag indicating that this is a MIPS16 function is stored by elfread.c in | |
816 | the high bit of the info field. Use this to decide if the function is | |
817 | MIPS16 or normal MIPS. */ | |
818 | sym = lookup_minimal_symbol_by_pc (memaddr); | |
819 | if (sym) | |
71b8ef93 | 820 | return msymbol_is_special (sym); |
c906108c SS |
821 | else |
822 | return 0; | |
823 | } | |
824 | ||
b2fa5097 | 825 | /* MIPS believes that the PC has a sign extended value. Perhaps the |
6c997a34 AC |
826 | all registers should be sign extended for simplicity? */ |
827 | ||
828 | static CORE_ADDR | |
39f77062 | 829 | mips_read_pc (ptid_t ptid) |
6c997a34 | 830 | { |
b6cb9035 AC |
831 | return read_signed_register_pid (mips_regnum (current_gdbarch)->pc, ptid); |
832 | } | |
833 | ||
58dfe9ff AC |
834 | static CORE_ADDR |
835 | mips_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame) | |
836 | { | |
edfae063 AC |
837 | return frame_unwind_register_signed (next_frame, |
838 | NUM_REGS + mips_regnum (gdbarch)->pc); | |
839 | } | |
840 | ||
841 | /* Assuming NEXT_FRAME->prev is a dummy, return the frame ID of that | |
842 | dummy frame. The frame ID's base needs to match the TOS value | |
843 | saved by save_dummy_frame_tos(), and the PC match the dummy frame's | |
844 | breakpoint. */ | |
845 | ||
846 | static struct frame_id | |
847 | mips_unwind_dummy_id (struct gdbarch *gdbarch, struct frame_info *next_frame) | |
848 | { | |
f10683bb | 849 | return frame_id_build (frame_unwind_register_signed (next_frame, NUM_REGS + MIPS_SP_REGNUM), |
edfae063 | 850 | frame_pc_unwind (next_frame)); |
58dfe9ff AC |
851 | } |
852 | ||
b6cb9035 AC |
853 | static void |
854 | mips_write_pc (CORE_ADDR pc, ptid_t ptid) | |
855 | { | |
856 | write_register_pid (mips_regnum (current_gdbarch)->pc, pc, ptid); | |
6c997a34 | 857 | } |
c906108c | 858 | |
c906108c SS |
859 | /* Fetch and return instruction from the specified location. If the PC |
860 | is odd, assume it's a MIPS16 instruction; otherwise MIPS32. */ | |
861 | ||
d37cca3d | 862 | static ULONGEST |
acdb74a0 | 863 | mips_fetch_instruction (CORE_ADDR addr) |
c906108c | 864 | { |
47a35522 | 865 | gdb_byte buf[MIPS_INSN32_SIZE]; |
c906108c SS |
866 | int instlen; |
867 | int status; | |
868 | ||
0fe7e7c8 | 869 | if (mips_pc_is_mips16 (addr)) |
c906108c | 870 | { |
95ac2dcf | 871 | instlen = MIPS_INSN16_SIZE; |
95404a3e | 872 | addr = unmake_mips16_addr (addr); |
c906108c SS |
873 | } |
874 | else | |
95ac2dcf | 875 | instlen = MIPS_INSN32_SIZE; |
359a9262 | 876 | status = read_memory_nobpt (addr, buf, instlen); |
c906108c SS |
877 | if (status) |
878 | memory_error (status, addr); | |
879 | return extract_unsigned_integer (buf, instlen); | |
880 | } | |
881 | ||
c906108c | 882 | /* These the fields of 32 bit mips instructions */ |
e135b889 DJ |
883 | #define mips32_op(x) (x >> 26) |
884 | #define itype_op(x) (x >> 26) | |
885 | #define itype_rs(x) ((x >> 21) & 0x1f) | |
c906108c | 886 | #define itype_rt(x) ((x >> 16) & 0x1f) |
e135b889 | 887 | #define itype_immediate(x) (x & 0xffff) |
c906108c | 888 | |
e135b889 DJ |
889 | #define jtype_op(x) (x >> 26) |
890 | #define jtype_target(x) (x & 0x03ffffff) | |
c906108c | 891 | |
e135b889 DJ |
892 | #define rtype_op(x) (x >> 26) |
893 | #define rtype_rs(x) ((x >> 21) & 0x1f) | |
894 | #define rtype_rt(x) ((x >> 16) & 0x1f) | |
895 | #define rtype_rd(x) ((x >> 11) & 0x1f) | |
896 | #define rtype_shamt(x) ((x >> 6) & 0x1f) | |
897 | #define rtype_funct(x) (x & 0x3f) | |
c906108c | 898 | |
06987e64 MK |
899 | static LONGEST |
900 | mips32_relative_offset (ULONGEST inst) | |
c5aa993b | 901 | { |
06987e64 | 902 | return ((itype_immediate (inst) ^ 0x8000) - 0x8000) << 2; |
c906108c SS |
903 | } |
904 | ||
f49e4e6d MS |
905 | /* Determine where to set a single step breakpoint while considering |
906 | branch prediction. */ | |
5a89d8aa | 907 | static CORE_ADDR |
c5aa993b JM |
908 | mips32_next_pc (CORE_ADDR pc) |
909 | { | |
910 | unsigned long inst; | |
911 | int op; | |
912 | inst = mips_fetch_instruction (pc); | |
e135b889 | 913 | if ((inst & 0xe0000000) != 0) /* Not a special, jump or branch instruction */ |
c5aa993b | 914 | { |
e135b889 | 915 | if (itype_op (inst) >> 2 == 5) |
6d82d43b | 916 | /* BEQL, BNEL, BLEZL, BGTZL: bits 0101xx */ |
c5aa993b | 917 | { |
e135b889 | 918 | op = (itype_op (inst) & 0x03); |
c906108c SS |
919 | switch (op) |
920 | { | |
e135b889 DJ |
921 | case 0: /* BEQL */ |
922 | goto equal_branch; | |
923 | case 1: /* BNEL */ | |
924 | goto neq_branch; | |
925 | case 2: /* BLEZL */ | |
926 | goto less_branch; | |
927 | case 3: /* BGTZ */ | |
928 | goto greater_branch; | |
c5aa993b JM |
929 | default: |
930 | pc += 4; | |
c906108c SS |
931 | } |
932 | } | |
e135b889 | 933 | else if (itype_op (inst) == 17 && itype_rs (inst) == 8) |
6d82d43b | 934 | /* BC1F, BC1FL, BC1T, BC1TL: 010001 01000 */ |
e135b889 DJ |
935 | { |
936 | int tf = itype_rt (inst) & 0x01; | |
937 | int cnum = itype_rt (inst) >> 2; | |
6d82d43b AC |
938 | int fcrcs = |
939 | read_signed_register (mips_regnum (current_gdbarch)-> | |
940 | fp_control_status); | |
e135b889 DJ |
941 | int cond = ((fcrcs >> 24) & 0x0e) | ((fcrcs >> 23) & 0x01); |
942 | ||
943 | if (((cond >> cnum) & 0x01) == tf) | |
944 | pc += mips32_relative_offset (inst) + 4; | |
945 | else | |
946 | pc += 8; | |
947 | } | |
c5aa993b JM |
948 | else |
949 | pc += 4; /* Not a branch, next instruction is easy */ | |
c906108c SS |
950 | } |
951 | else | |
c5aa993b JM |
952 | { /* This gets way messy */ |
953 | ||
c906108c | 954 | /* Further subdivide into SPECIAL, REGIMM and other */ |
e135b889 | 955 | switch (op = itype_op (inst) & 0x07) /* extract bits 28,27,26 */ |
c906108c | 956 | { |
c5aa993b JM |
957 | case 0: /* SPECIAL */ |
958 | op = rtype_funct (inst); | |
959 | switch (op) | |
960 | { | |
961 | case 8: /* JR */ | |
962 | case 9: /* JALR */ | |
6c997a34 AC |
963 | /* Set PC to that address */ |
964 | pc = read_signed_register (rtype_rs (inst)); | |
c5aa993b JM |
965 | break; |
966 | default: | |
967 | pc += 4; | |
968 | } | |
969 | ||
6d82d43b | 970 | break; /* end SPECIAL */ |
c5aa993b | 971 | case 1: /* REGIMM */ |
c906108c | 972 | { |
e135b889 DJ |
973 | op = itype_rt (inst); /* branch condition */ |
974 | switch (op) | |
c906108c | 975 | { |
c5aa993b | 976 | case 0: /* BLTZ */ |
e135b889 DJ |
977 | case 2: /* BLTZL */ |
978 | case 16: /* BLTZAL */ | |
c5aa993b | 979 | case 18: /* BLTZALL */ |
c906108c | 980 | less_branch: |
6c997a34 | 981 | if (read_signed_register (itype_rs (inst)) < 0) |
c5aa993b JM |
982 | pc += mips32_relative_offset (inst) + 4; |
983 | else | |
984 | pc += 8; /* after the delay slot */ | |
985 | break; | |
e135b889 | 986 | case 1: /* BGEZ */ |
c5aa993b JM |
987 | case 3: /* BGEZL */ |
988 | case 17: /* BGEZAL */ | |
989 | case 19: /* BGEZALL */ | |
6c997a34 | 990 | if (read_signed_register (itype_rs (inst)) >= 0) |
c5aa993b JM |
991 | pc += mips32_relative_offset (inst) + 4; |
992 | else | |
993 | pc += 8; /* after the delay slot */ | |
994 | break; | |
e135b889 | 995 | /* All of the other instructions in the REGIMM category */ |
c5aa993b JM |
996 | default: |
997 | pc += 4; | |
c906108c SS |
998 | } |
999 | } | |
6d82d43b | 1000 | break; /* end REGIMM */ |
c5aa993b JM |
1001 | case 2: /* J */ |
1002 | case 3: /* JAL */ | |
1003 | { | |
1004 | unsigned long reg; | |
1005 | reg = jtype_target (inst) << 2; | |
e135b889 | 1006 | /* Upper four bits get never changed... */ |
5b652102 | 1007 | pc = reg + ((pc + 4) & ~(CORE_ADDR) 0x0fffffff); |
c906108c | 1008 | } |
c5aa993b JM |
1009 | break; |
1010 | /* FIXME case JALX : */ | |
1011 | { | |
1012 | unsigned long reg; | |
1013 | reg = jtype_target (inst) << 2; | |
5b652102 | 1014 | pc = reg + ((pc + 4) & ~(CORE_ADDR) 0x0fffffff) + 1; /* yes, +1 */ |
c906108c SS |
1015 | /* Add 1 to indicate 16 bit mode - Invert ISA mode */ |
1016 | } | |
c5aa993b | 1017 | break; /* The new PC will be alternate mode */ |
e135b889 | 1018 | case 4: /* BEQ, BEQL */ |
c5aa993b | 1019 | equal_branch: |
6c997a34 AC |
1020 | if (read_signed_register (itype_rs (inst)) == |
1021 | read_signed_register (itype_rt (inst))) | |
c5aa993b JM |
1022 | pc += mips32_relative_offset (inst) + 4; |
1023 | else | |
1024 | pc += 8; | |
1025 | break; | |
e135b889 | 1026 | case 5: /* BNE, BNEL */ |
c5aa993b | 1027 | neq_branch: |
6c997a34 | 1028 | if (read_signed_register (itype_rs (inst)) != |
e135b889 | 1029 | read_signed_register (itype_rt (inst))) |
c5aa993b JM |
1030 | pc += mips32_relative_offset (inst) + 4; |
1031 | else | |
1032 | pc += 8; | |
1033 | break; | |
e135b889 | 1034 | case 6: /* BLEZ, BLEZL */ |
1fd8cd20 | 1035 | if (read_signed_register (itype_rs (inst)) <= 0) |
c5aa993b JM |
1036 | pc += mips32_relative_offset (inst) + 4; |
1037 | else | |
1038 | pc += 8; | |
1039 | break; | |
1040 | case 7: | |
e135b889 DJ |
1041 | default: |
1042 | greater_branch: /* BGTZ, BGTZL */ | |
1fd8cd20 | 1043 | if (read_signed_register (itype_rs (inst)) > 0) |
c5aa993b JM |
1044 | pc += mips32_relative_offset (inst) + 4; |
1045 | else | |
1046 | pc += 8; | |
1047 | break; | |
c5aa993b JM |
1048 | } /* switch */ |
1049 | } /* else */ | |
1050 | return pc; | |
1051 | } /* mips32_next_pc */ | |
c906108c SS |
1052 | |
1053 | /* Decoding the next place to set a breakpoint is irregular for the | |
e26cc349 | 1054 | mips 16 variant, but fortunately, there fewer instructions. We have to cope |
c906108c SS |
1055 | ith extensions for 16 bit instructions and a pair of actual 32 bit instructions. |
1056 | We dont want to set a single step instruction on the extend instruction | |
1057 | either. | |
c5aa993b | 1058 | */ |
c906108c SS |
1059 | |
1060 | /* Lots of mips16 instruction formats */ | |
1061 | /* Predicting jumps requires itype,ritype,i8type | |
1062 | and their extensions extItype,extritype,extI8type | |
c5aa993b | 1063 | */ |
c906108c SS |
1064 | enum mips16_inst_fmts |
1065 | { | |
c5aa993b JM |
1066 | itype, /* 0 immediate 5,10 */ |
1067 | ritype, /* 1 5,3,8 */ | |
1068 | rrtype, /* 2 5,3,3,5 */ | |
1069 | rritype, /* 3 5,3,3,5 */ | |
1070 | rrrtype, /* 4 5,3,3,3,2 */ | |
1071 | rriatype, /* 5 5,3,3,1,4 */ | |
1072 | shifttype, /* 6 5,3,3,3,2 */ | |
1073 | i8type, /* 7 5,3,8 */ | |
1074 | i8movtype, /* 8 5,3,3,5 */ | |
1075 | i8mov32rtype, /* 9 5,3,5,3 */ | |
1076 | i64type, /* 10 5,3,8 */ | |
1077 | ri64type, /* 11 5,3,3,5 */ | |
1078 | jalxtype, /* 12 5,1,5,5,16 - a 32 bit instruction */ | |
1079 | exiItype, /* 13 5,6,5,5,1,1,1,1,1,1,5 */ | |
1080 | extRitype, /* 14 5,6,5,5,3,1,1,1,5 */ | |
1081 | extRRItype, /* 15 5,5,5,5,3,3,5 */ | |
1082 | extRRIAtype, /* 16 5,7,4,5,3,3,1,4 */ | |
1083 | EXTshifttype, /* 17 5,5,1,1,1,1,1,1,5,3,3,1,1,1,2 */ | |
1084 | extI8type, /* 18 5,6,5,5,3,1,1,1,5 */ | |
1085 | extI64type, /* 19 5,6,5,5,3,1,1,1,5 */ | |
1086 | extRi64type, /* 20 5,6,5,5,3,3,5 */ | |
1087 | extshift64type /* 21 5,5,1,1,1,1,1,1,5,1,1,1,3,5 */ | |
1088 | }; | |
12f02c2a AC |
1089 | /* I am heaping all the fields of the formats into one structure and |
1090 | then, only the fields which are involved in instruction extension */ | |
c906108c | 1091 | struct upk_mips16 |
6d82d43b AC |
1092 | { |
1093 | CORE_ADDR offset; | |
1094 | unsigned int regx; /* Function in i8 type */ | |
1095 | unsigned int regy; | |
1096 | }; | |
c906108c SS |
1097 | |
1098 | ||
12f02c2a AC |
1099 | /* The EXT-I, EXT-ri nad EXT-I8 instructions all have the same format |
1100 | for the bits which make up the immediatate extension. */ | |
c906108c | 1101 | |
12f02c2a AC |
1102 | static CORE_ADDR |
1103 | extended_offset (unsigned int extension) | |
c906108c | 1104 | { |
12f02c2a | 1105 | CORE_ADDR value; |
c5aa993b JM |
1106 | value = (extension >> 21) & 0x3f; /* * extract 15:11 */ |
1107 | value = value << 6; | |
1108 | value |= (extension >> 16) & 0x1f; /* extrace 10:5 */ | |
1109 | value = value << 5; | |
1110 | value |= extension & 0x01f; /* extract 4:0 */ | |
1111 | return value; | |
c906108c SS |
1112 | } |
1113 | ||
1114 | /* Only call this function if you know that this is an extendable | |
1115 | instruction, It wont malfunction, but why make excess remote memory references? | |
1116 | If the immediate operands get sign extended or somthing, do it after | |
1117 | the extension is performed. | |
c5aa993b | 1118 | */ |
c906108c SS |
1119 | /* FIXME: Every one of these cases needs to worry about sign extension |
1120 | when the offset is to be used in relative addressing */ | |
1121 | ||
1122 | ||
12f02c2a | 1123 | static unsigned int |
c5aa993b | 1124 | fetch_mips_16 (CORE_ADDR pc) |
c906108c | 1125 | { |
47a35522 | 1126 | gdb_byte buf[8]; |
c5aa993b JM |
1127 | pc &= 0xfffffffe; /* clear the low order bit */ |
1128 | target_read_memory (pc, buf, 2); | |
1129 | return extract_unsigned_integer (buf, 2); | |
c906108c SS |
1130 | } |
1131 | ||
1132 | static void | |
c5aa993b | 1133 | unpack_mips16 (CORE_ADDR pc, |
12f02c2a AC |
1134 | unsigned int extension, |
1135 | unsigned int inst, | |
6d82d43b | 1136 | enum mips16_inst_fmts insn_format, struct upk_mips16 *upk) |
c906108c | 1137 | { |
12f02c2a AC |
1138 | CORE_ADDR offset; |
1139 | int regx; | |
1140 | int regy; | |
1141 | switch (insn_format) | |
c906108c | 1142 | { |
c5aa993b | 1143 | case itype: |
c906108c | 1144 | { |
12f02c2a AC |
1145 | CORE_ADDR value; |
1146 | if (extension) | |
c5aa993b JM |
1147 | { |
1148 | value = extended_offset (extension); | |
1149 | value = value << 11; /* rom for the original value */ | |
6d82d43b | 1150 | value |= inst & 0x7ff; /* eleven bits from instruction */ |
c906108c SS |
1151 | } |
1152 | else | |
c5aa993b | 1153 | { |
12f02c2a | 1154 | value = inst & 0x7ff; |
c5aa993b | 1155 | /* FIXME : Consider sign extension */ |
c906108c | 1156 | } |
12f02c2a AC |
1157 | offset = value; |
1158 | regx = -1; | |
1159 | regy = -1; | |
c906108c | 1160 | } |
c5aa993b JM |
1161 | break; |
1162 | case ritype: | |
1163 | case i8type: | |
1164 | { /* A register identifier and an offset */ | |
c906108c SS |
1165 | /* Most of the fields are the same as I type but the |
1166 | immediate value is of a different length */ | |
12f02c2a AC |
1167 | CORE_ADDR value; |
1168 | if (extension) | |
c906108c | 1169 | { |
c5aa993b JM |
1170 | value = extended_offset (extension); |
1171 | value = value << 8; /* from the original instruction */ | |
12f02c2a AC |
1172 | value |= inst & 0xff; /* eleven bits from instruction */ |
1173 | regx = (extension >> 8) & 0x07; /* or i8 funct */ | |
c5aa993b JM |
1174 | if (value & 0x4000) /* test the sign bit , bit 26 */ |
1175 | { | |
1176 | value &= ~0x3fff; /* remove the sign bit */ | |
1177 | value = -value; | |
c906108c SS |
1178 | } |
1179 | } | |
c5aa993b JM |
1180 | else |
1181 | { | |
12f02c2a AC |
1182 | value = inst & 0xff; /* 8 bits */ |
1183 | regx = (inst >> 8) & 0x07; /* or i8 funct */ | |
c5aa993b JM |
1184 | /* FIXME: Do sign extension , this format needs it */ |
1185 | if (value & 0x80) /* THIS CONFUSES ME */ | |
1186 | { | |
1187 | value &= 0xef; /* remove the sign bit */ | |
1188 | value = -value; | |
1189 | } | |
c5aa993b | 1190 | } |
12f02c2a AC |
1191 | offset = value; |
1192 | regy = -1; | |
c5aa993b | 1193 | break; |
c906108c | 1194 | } |
c5aa993b | 1195 | case jalxtype: |
c906108c | 1196 | { |
c5aa993b | 1197 | unsigned long value; |
12f02c2a AC |
1198 | unsigned int nexthalf; |
1199 | value = ((inst & 0x1f) << 5) | ((inst >> 5) & 0x1f); | |
c5aa993b JM |
1200 | value = value << 16; |
1201 | nexthalf = mips_fetch_instruction (pc + 2); /* low bit still set */ | |
1202 | value |= nexthalf; | |
12f02c2a AC |
1203 | offset = value; |
1204 | regx = -1; | |
1205 | regy = -1; | |
c5aa993b | 1206 | break; |
c906108c SS |
1207 | } |
1208 | default: | |
e2e0b3e5 | 1209 | internal_error (__FILE__, __LINE__, _("bad switch")); |
c906108c | 1210 | } |
12f02c2a AC |
1211 | upk->offset = offset; |
1212 | upk->regx = regx; | |
1213 | upk->regy = regy; | |
c906108c SS |
1214 | } |
1215 | ||
1216 | ||
c5aa993b JM |
1217 | static CORE_ADDR |
1218 | add_offset_16 (CORE_ADDR pc, int offset) | |
c906108c | 1219 | { |
5b652102 | 1220 | return ((offset << 2) | ((pc + 2) & (~(CORE_ADDR) 0x0fffffff))); |
c906108c SS |
1221 | } |
1222 | ||
12f02c2a AC |
1223 | static CORE_ADDR |
1224 | extended_mips16_next_pc (CORE_ADDR pc, | |
6d82d43b | 1225 | unsigned int extension, unsigned int insn) |
c906108c | 1226 | { |
12f02c2a AC |
1227 | int op = (insn >> 11); |
1228 | switch (op) | |
c906108c | 1229 | { |
6d82d43b | 1230 | case 2: /* Branch */ |
12f02c2a AC |
1231 | { |
1232 | CORE_ADDR offset; | |
1233 | struct upk_mips16 upk; | |
1234 | unpack_mips16 (pc, extension, insn, itype, &upk); | |
1235 | offset = upk.offset; | |
1236 | if (offset & 0x800) | |
1237 | { | |
1238 | offset &= 0xeff; | |
1239 | offset = -offset; | |
1240 | } | |
1241 | pc += (offset << 1) + 2; | |
1242 | break; | |
1243 | } | |
6d82d43b | 1244 | case 3: /* JAL , JALX - Watch out, these are 32 bit instruction */ |
12f02c2a AC |
1245 | { |
1246 | struct upk_mips16 upk; | |
1247 | unpack_mips16 (pc, extension, insn, jalxtype, &upk); | |
1248 | pc = add_offset_16 (pc, upk.offset); | |
1249 | if ((insn >> 10) & 0x01) /* Exchange mode */ | |
1250 | pc = pc & ~0x01; /* Clear low bit, indicate 32 bit mode */ | |
1251 | else | |
1252 | pc |= 0x01; | |
1253 | break; | |
1254 | } | |
6d82d43b | 1255 | case 4: /* beqz */ |
12f02c2a AC |
1256 | { |
1257 | struct upk_mips16 upk; | |
1258 | int reg; | |
1259 | unpack_mips16 (pc, extension, insn, ritype, &upk); | |
1260 | reg = read_signed_register (upk.regx); | |
1261 | if (reg == 0) | |
1262 | pc += (upk.offset << 1) + 2; | |
1263 | else | |
1264 | pc += 2; | |
1265 | break; | |
1266 | } | |
6d82d43b | 1267 | case 5: /* bnez */ |
12f02c2a AC |
1268 | { |
1269 | struct upk_mips16 upk; | |
1270 | int reg; | |
1271 | unpack_mips16 (pc, extension, insn, ritype, &upk); | |
1272 | reg = read_signed_register (upk.regx); | |
1273 | if (reg != 0) | |
1274 | pc += (upk.offset << 1) + 2; | |
1275 | else | |
1276 | pc += 2; | |
1277 | break; | |
1278 | } | |
6d82d43b | 1279 | case 12: /* I8 Formats btez btnez */ |
12f02c2a AC |
1280 | { |
1281 | struct upk_mips16 upk; | |
1282 | int reg; | |
1283 | unpack_mips16 (pc, extension, insn, i8type, &upk); | |
1284 | /* upk.regx contains the opcode */ | |
1285 | reg = read_signed_register (24); /* Test register is 24 */ | |
1286 | if (((upk.regx == 0) && (reg == 0)) /* BTEZ */ | |
1287 | || ((upk.regx == 1) && (reg != 0))) /* BTNEZ */ | |
1288 | /* pc = add_offset_16(pc,upk.offset) ; */ | |
1289 | pc += (upk.offset << 1) + 2; | |
1290 | else | |
1291 | pc += 2; | |
1292 | break; | |
1293 | } | |
6d82d43b | 1294 | case 29: /* RR Formats JR, JALR, JALR-RA */ |
12f02c2a AC |
1295 | { |
1296 | struct upk_mips16 upk; | |
1297 | /* upk.fmt = rrtype; */ | |
1298 | op = insn & 0x1f; | |
1299 | if (op == 0) | |
c5aa993b | 1300 | { |
12f02c2a AC |
1301 | int reg; |
1302 | upk.regx = (insn >> 8) & 0x07; | |
1303 | upk.regy = (insn >> 5) & 0x07; | |
1304 | switch (upk.regy) | |
c5aa993b | 1305 | { |
12f02c2a AC |
1306 | case 0: |
1307 | reg = upk.regx; | |
1308 | break; | |
1309 | case 1: | |
1310 | reg = 31; | |
6d82d43b | 1311 | break; /* Function return instruction */ |
12f02c2a AC |
1312 | case 2: |
1313 | reg = upk.regx; | |
1314 | break; | |
1315 | default: | |
1316 | reg = 31; | |
6d82d43b | 1317 | break; /* BOGUS Guess */ |
c906108c | 1318 | } |
12f02c2a | 1319 | pc = read_signed_register (reg); |
c906108c | 1320 | } |
12f02c2a | 1321 | else |
c5aa993b | 1322 | pc += 2; |
12f02c2a AC |
1323 | break; |
1324 | } | |
1325 | case 30: | |
1326 | /* This is an instruction extension. Fetch the real instruction | |
1327 | (which follows the extension) and decode things based on | |
1328 | that. */ | |
1329 | { | |
1330 | pc += 2; | |
1331 | pc = extended_mips16_next_pc (pc, insn, fetch_mips_16 (pc)); | |
1332 | break; | |
1333 | } | |
1334 | default: | |
1335 | { | |
1336 | pc += 2; | |
1337 | break; | |
1338 | } | |
c906108c | 1339 | } |
c5aa993b | 1340 | return pc; |
12f02c2a | 1341 | } |
c906108c | 1342 | |
5a89d8aa | 1343 | static CORE_ADDR |
12f02c2a AC |
1344 | mips16_next_pc (CORE_ADDR pc) |
1345 | { | |
1346 | unsigned int insn = fetch_mips_16 (pc); | |
1347 | return extended_mips16_next_pc (pc, 0, insn); | |
1348 | } | |
1349 | ||
1350 | /* The mips_next_pc function supports single_step when the remote | |
7e73cedf | 1351 | target monitor or stub is not developed enough to do a single_step. |
12f02c2a AC |
1352 | It works by decoding the current instruction and predicting where a |
1353 | branch will go. This isnt hard because all the data is available. | |
1354 | The MIPS32 and MIPS16 variants are quite different */ | |
c5aa993b JM |
1355 | CORE_ADDR |
1356 | mips_next_pc (CORE_ADDR pc) | |
c906108c | 1357 | { |
c5aa993b JM |
1358 | if (pc & 0x01) |
1359 | return mips16_next_pc (pc); | |
1360 | else | |
1361 | return mips32_next_pc (pc); | |
12f02c2a | 1362 | } |
c906108c | 1363 | |
edfae063 AC |
1364 | struct mips_frame_cache |
1365 | { | |
1366 | CORE_ADDR base; | |
1367 | struct trad_frame_saved_reg *saved_regs; | |
1368 | }; | |
1369 | ||
29639122 JB |
1370 | /* Set a register's saved stack address in temp_saved_regs. If an |
1371 | address has already been set for this register, do nothing; this | |
1372 | way we will only recognize the first save of a given register in a | |
1373 | function prologue. | |
eec63939 | 1374 | |
29639122 JB |
1375 | For simplicity, save the address in both [0 .. NUM_REGS) and |
1376 | [NUM_REGS .. 2*NUM_REGS). Strictly speaking, only the second range | |
1377 | is used as it is only second range (the ABI instead of ISA | |
1378 | registers) that comes into play when finding saved registers in a | |
1379 | frame. */ | |
eec63939 AC |
1380 | |
1381 | static void | |
29639122 JB |
1382 | set_reg_offset (struct mips_frame_cache *this_cache, int regnum, |
1383 | CORE_ADDR offset) | |
eec63939 | 1384 | { |
29639122 JB |
1385 | if (this_cache != NULL |
1386 | && this_cache->saved_regs[regnum].addr == -1) | |
1387 | { | |
1388 | this_cache->saved_regs[regnum + 0 * NUM_REGS].addr = offset; | |
1389 | this_cache->saved_regs[regnum + 1 * NUM_REGS].addr = offset; | |
1390 | } | |
eec63939 AC |
1391 | } |
1392 | ||
eec63939 | 1393 | |
29639122 JB |
1394 | /* Fetch the immediate value from a MIPS16 instruction. |
1395 | If the previous instruction was an EXTEND, use it to extend | |
1396 | the upper bits of the immediate value. This is a helper function | |
1397 | for mips16_scan_prologue. */ | |
eec63939 | 1398 | |
29639122 JB |
1399 | static int |
1400 | mips16_get_imm (unsigned short prev_inst, /* previous instruction */ | |
1401 | unsigned short inst, /* current instruction */ | |
1402 | int nbits, /* number of bits in imm field */ | |
1403 | int scale, /* scale factor to be applied to imm */ | |
1404 | int is_signed) /* is the imm field signed? */ | |
eec63939 | 1405 | { |
29639122 | 1406 | int offset; |
eec63939 | 1407 | |
29639122 JB |
1408 | if ((prev_inst & 0xf800) == 0xf000) /* prev instruction was EXTEND? */ |
1409 | { | |
1410 | offset = ((prev_inst & 0x1f) << 11) | (prev_inst & 0x7e0); | |
1411 | if (offset & 0x8000) /* check for negative extend */ | |
1412 | offset = 0 - (0x10000 - (offset & 0xffff)); | |
1413 | return offset | (inst & 0x1f); | |
1414 | } | |
eec63939 | 1415 | else |
29639122 JB |
1416 | { |
1417 | int max_imm = 1 << nbits; | |
1418 | int mask = max_imm - 1; | |
1419 | int sign_bit = max_imm >> 1; | |
45c9dd44 | 1420 | |
29639122 JB |
1421 | offset = inst & mask; |
1422 | if (is_signed && (offset & sign_bit)) | |
1423 | offset = 0 - (max_imm - offset); | |
1424 | return offset * scale; | |
1425 | } | |
1426 | } | |
eec63939 | 1427 | |
65596487 | 1428 | |
29639122 JB |
1429 | /* Analyze the function prologue from START_PC to LIMIT_PC. Builds |
1430 | the associated FRAME_CACHE if not null. | |
1431 | Return the address of the first instruction past the prologue. */ | |
eec63939 | 1432 | |
29639122 JB |
1433 | static CORE_ADDR |
1434 | mips16_scan_prologue (CORE_ADDR start_pc, CORE_ADDR limit_pc, | |
1435 | struct frame_info *next_frame, | |
1436 | struct mips_frame_cache *this_cache) | |
1437 | { | |
1438 | CORE_ADDR cur_pc; | |
1439 | CORE_ADDR frame_addr = 0; /* Value of $r17, used as frame pointer */ | |
1440 | CORE_ADDR sp; | |
1441 | long frame_offset = 0; /* Size of stack frame. */ | |
1442 | long frame_adjust = 0; /* Offset of FP from SP. */ | |
1443 | int frame_reg = MIPS_SP_REGNUM; | |
1444 | unsigned short prev_inst = 0; /* saved copy of previous instruction */ | |
1445 | unsigned inst = 0; /* current instruction */ | |
1446 | unsigned entry_inst = 0; /* the entry instruction */ | |
1447 | int reg, offset; | |
a343eb3c | 1448 | |
29639122 JB |
1449 | int extend_bytes = 0; |
1450 | int prev_extend_bytes; | |
1451 | CORE_ADDR end_prologue_addr = 0; | |
a343eb3c | 1452 | |
29639122 JB |
1453 | /* Can be called when there's no process, and hence when there's no |
1454 | NEXT_FRAME. */ | |
1455 | if (next_frame != NULL) | |
1456 | sp = read_next_frame_reg (next_frame, NUM_REGS + MIPS_SP_REGNUM); | |
1457 | else | |
1458 | sp = 0; | |
eec63939 | 1459 | |
29639122 JB |
1460 | if (limit_pc > start_pc + 200) |
1461 | limit_pc = start_pc + 200; | |
eec63939 | 1462 | |
95ac2dcf | 1463 | for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += MIPS_INSN16_SIZE) |
29639122 JB |
1464 | { |
1465 | /* Save the previous instruction. If it's an EXTEND, we'll extract | |
1466 | the immediate offset extension from it in mips16_get_imm. */ | |
1467 | prev_inst = inst; | |
eec63939 | 1468 | |
29639122 JB |
1469 | /* Fetch and decode the instruction. */ |
1470 | inst = (unsigned short) mips_fetch_instruction (cur_pc); | |
eec63939 | 1471 | |
29639122 JB |
1472 | /* Normally we ignore extend instructions. However, if it is |
1473 | not followed by a valid prologue instruction, then this | |
1474 | instruction is not part of the prologue either. We must | |
1475 | remember in this case to adjust the end_prologue_addr back | |
1476 | over the extend. */ | |
1477 | if ((inst & 0xf800) == 0xf000) /* extend */ | |
1478 | { | |
95ac2dcf | 1479 | extend_bytes = MIPS_INSN16_SIZE; |
29639122 JB |
1480 | continue; |
1481 | } | |
eec63939 | 1482 | |
29639122 JB |
1483 | prev_extend_bytes = extend_bytes; |
1484 | extend_bytes = 0; | |
eec63939 | 1485 | |
29639122 JB |
1486 | if ((inst & 0xff00) == 0x6300 /* addiu sp */ |
1487 | || (inst & 0xff00) == 0xfb00) /* daddiu sp */ | |
1488 | { | |
1489 | offset = mips16_get_imm (prev_inst, inst, 8, 8, 1); | |
1490 | if (offset < 0) /* negative stack adjustment? */ | |
1491 | frame_offset -= offset; | |
1492 | else | |
1493 | /* Exit loop if a positive stack adjustment is found, which | |
1494 | usually means that the stack cleanup code in the function | |
1495 | epilogue is reached. */ | |
1496 | break; | |
1497 | } | |
1498 | else if ((inst & 0xf800) == 0xd000) /* sw reg,n($sp) */ | |
1499 | { | |
1500 | offset = mips16_get_imm (prev_inst, inst, 8, 4, 0); | |
1501 | reg = mips16_to_32_reg[(inst & 0x700) >> 8]; | |
1502 | set_reg_offset (this_cache, reg, sp + offset); | |
1503 | } | |
1504 | else if ((inst & 0xff00) == 0xf900) /* sd reg,n($sp) */ | |
1505 | { | |
1506 | offset = mips16_get_imm (prev_inst, inst, 5, 8, 0); | |
1507 | reg = mips16_to_32_reg[(inst & 0xe0) >> 5]; | |
1508 | set_reg_offset (this_cache, reg, sp + offset); | |
1509 | } | |
1510 | else if ((inst & 0xff00) == 0x6200) /* sw $ra,n($sp) */ | |
1511 | { | |
1512 | offset = mips16_get_imm (prev_inst, inst, 8, 4, 0); | |
4c7d22cb | 1513 | set_reg_offset (this_cache, MIPS_RA_REGNUM, sp + offset); |
29639122 JB |
1514 | } |
1515 | else if ((inst & 0xff00) == 0xfa00) /* sd $ra,n($sp) */ | |
1516 | { | |
1517 | offset = mips16_get_imm (prev_inst, inst, 8, 8, 0); | |
4c7d22cb | 1518 | set_reg_offset (this_cache, MIPS_RA_REGNUM, sp + offset); |
29639122 JB |
1519 | } |
1520 | else if (inst == 0x673d) /* move $s1, $sp */ | |
1521 | { | |
1522 | frame_addr = sp; | |
1523 | frame_reg = 17; | |
1524 | } | |
1525 | else if ((inst & 0xff00) == 0x0100) /* addiu $s1,sp,n */ | |
1526 | { | |
1527 | offset = mips16_get_imm (prev_inst, inst, 8, 4, 0); | |
1528 | frame_addr = sp + offset; | |
1529 | frame_reg = 17; | |
1530 | frame_adjust = offset; | |
1531 | } | |
1532 | else if ((inst & 0xFF00) == 0xd900) /* sw reg,offset($s1) */ | |
1533 | { | |
1534 | offset = mips16_get_imm (prev_inst, inst, 5, 4, 0); | |
1535 | reg = mips16_to_32_reg[(inst & 0xe0) >> 5]; | |
1536 | set_reg_offset (this_cache, reg, frame_addr + offset); | |
1537 | } | |
1538 | else if ((inst & 0xFF00) == 0x7900) /* sd reg,offset($s1) */ | |
1539 | { | |
1540 | offset = mips16_get_imm (prev_inst, inst, 5, 8, 0); | |
1541 | reg = mips16_to_32_reg[(inst & 0xe0) >> 5]; | |
1542 | set_reg_offset (this_cache, reg, frame_addr + offset); | |
1543 | } | |
1544 | else if ((inst & 0xf81f) == 0xe809 | |
1545 | && (inst & 0x700) != 0x700) /* entry */ | |
1546 | entry_inst = inst; /* save for later processing */ | |
1547 | else if ((inst & 0xf800) == 0x1800) /* jal(x) */ | |
95ac2dcf | 1548 | cur_pc += MIPS_INSN16_SIZE; /* 32-bit instruction */ |
29639122 JB |
1549 | else if ((inst & 0xff1c) == 0x6704) /* move reg,$a0-$a3 */ |
1550 | { | |
1551 | /* This instruction is part of the prologue, but we don't | |
1552 | need to do anything special to handle it. */ | |
1553 | } | |
1554 | else | |
1555 | { | |
1556 | /* This instruction is not an instruction typically found | |
1557 | in a prologue, so we must have reached the end of the | |
1558 | prologue. */ | |
1559 | if (end_prologue_addr == 0) | |
1560 | end_prologue_addr = cur_pc - prev_extend_bytes; | |
1561 | } | |
1562 | } | |
eec63939 | 1563 | |
29639122 JB |
1564 | /* The entry instruction is typically the first instruction in a function, |
1565 | and it stores registers at offsets relative to the value of the old SP | |
1566 | (before the prologue). But the value of the sp parameter to this | |
1567 | function is the new SP (after the prologue has been executed). So we | |
1568 | can't calculate those offsets until we've seen the entire prologue, | |
1569 | and can calculate what the old SP must have been. */ | |
1570 | if (entry_inst != 0) | |
1571 | { | |
1572 | int areg_count = (entry_inst >> 8) & 7; | |
1573 | int sreg_count = (entry_inst >> 6) & 3; | |
eec63939 | 1574 | |
29639122 JB |
1575 | /* The entry instruction always subtracts 32 from the SP. */ |
1576 | frame_offset += 32; | |
1577 | ||
1578 | /* Now we can calculate what the SP must have been at the | |
1579 | start of the function prologue. */ | |
1580 | sp += frame_offset; | |
1581 | ||
1582 | /* Check if a0-a3 were saved in the caller's argument save area. */ | |
1583 | for (reg = 4, offset = 0; reg < areg_count + 4; reg++) | |
1584 | { | |
1585 | set_reg_offset (this_cache, reg, sp + offset); | |
1586 | offset += mips_abi_regsize (current_gdbarch); | |
1587 | } | |
1588 | ||
1589 | /* Check if the ra register was pushed on the stack. */ | |
1590 | offset = -4; | |
1591 | if (entry_inst & 0x20) | |
1592 | { | |
4c7d22cb | 1593 | set_reg_offset (this_cache, MIPS_RA_REGNUM, sp + offset); |
29639122 JB |
1594 | offset -= mips_abi_regsize (current_gdbarch); |
1595 | } | |
1596 | ||
1597 | /* Check if the s0 and s1 registers were pushed on the stack. */ | |
1598 | for (reg = 16; reg < sreg_count + 16; reg++) | |
1599 | { | |
1600 | set_reg_offset (this_cache, reg, sp + offset); | |
1601 | offset -= mips_abi_regsize (current_gdbarch); | |
1602 | } | |
1603 | } | |
1604 | ||
1605 | if (this_cache != NULL) | |
1606 | { | |
1607 | this_cache->base = | |
1608 | (frame_unwind_register_signed (next_frame, NUM_REGS + frame_reg) | |
1609 | + frame_offset - frame_adjust); | |
1610 | /* FIXME: brobecker/2004-10-10: Just as in the mips32 case, we should | |
1611 | be able to get rid of the assignment below, evetually. But it's | |
1612 | still needed for now. */ | |
1613 | this_cache->saved_regs[NUM_REGS + mips_regnum (current_gdbarch)->pc] | |
4c7d22cb | 1614 | = this_cache->saved_regs[NUM_REGS + MIPS_RA_REGNUM]; |
29639122 JB |
1615 | } |
1616 | ||
1617 | /* If we didn't reach the end of the prologue when scanning the function | |
1618 | instructions, then set end_prologue_addr to the address of the | |
1619 | instruction immediately after the last one we scanned. */ | |
1620 | if (end_prologue_addr == 0) | |
1621 | end_prologue_addr = cur_pc; | |
1622 | ||
1623 | return end_prologue_addr; | |
eec63939 AC |
1624 | } |
1625 | ||
29639122 JB |
1626 | /* Heuristic unwinder for 16-bit MIPS instruction set (aka MIPS16). |
1627 | Procedures that use the 32-bit instruction set are handled by the | |
1628 | mips_insn32 unwinder. */ | |
1629 | ||
1630 | static struct mips_frame_cache * | |
1631 | mips_insn16_frame_cache (struct frame_info *next_frame, void **this_cache) | |
eec63939 | 1632 | { |
29639122 | 1633 | struct mips_frame_cache *cache; |
eec63939 AC |
1634 | |
1635 | if ((*this_cache) != NULL) | |
1636 | return (*this_cache); | |
29639122 JB |
1637 | cache = FRAME_OBSTACK_ZALLOC (struct mips_frame_cache); |
1638 | (*this_cache) = cache; | |
1639 | cache->saved_regs = trad_frame_alloc_saved_regs (next_frame); | |
eec63939 | 1640 | |
29639122 JB |
1641 | /* Analyze the function prologue. */ |
1642 | { | |
6de5b849 JB |
1643 | const CORE_ADDR pc = |
1644 | frame_unwind_address_in_block (next_frame, NORMAL_FRAME); | |
29639122 | 1645 | CORE_ADDR start_addr; |
eec63939 | 1646 | |
29639122 JB |
1647 | find_pc_partial_function (pc, NULL, &start_addr, NULL); |
1648 | if (start_addr == 0) | |
1649 | start_addr = heuristic_proc_start (pc); | |
1650 | /* We can't analyze the prologue if we couldn't find the begining | |
1651 | of the function. */ | |
1652 | if (start_addr == 0) | |
1653 | return cache; | |
eec63939 | 1654 | |
29639122 JB |
1655 | mips16_scan_prologue (start_addr, pc, next_frame, *this_cache); |
1656 | } | |
1657 | ||
1658 | /* SP_REGNUM, contains the value and not the address. */ | |
1659 | trad_frame_set_value (cache->saved_regs, NUM_REGS + MIPS_SP_REGNUM, cache->base); | |
eec63939 | 1660 | |
29639122 | 1661 | return (*this_cache); |
eec63939 AC |
1662 | } |
1663 | ||
1664 | static void | |
29639122 JB |
1665 | mips_insn16_frame_this_id (struct frame_info *next_frame, void **this_cache, |
1666 | struct frame_id *this_id) | |
eec63939 | 1667 | { |
29639122 JB |
1668 | struct mips_frame_cache *info = mips_insn16_frame_cache (next_frame, |
1669 | this_cache); | |
93d42b30 DJ |
1670 | (*this_id) = frame_id_build (info->base, |
1671 | frame_func_unwind (next_frame, NORMAL_FRAME)); | |
eec63939 AC |
1672 | } |
1673 | ||
1674 | static void | |
29639122 | 1675 | mips_insn16_frame_prev_register (struct frame_info *next_frame, |
eec63939 AC |
1676 | void **this_cache, |
1677 | int regnum, int *optimizedp, | |
1678 | enum lval_type *lvalp, CORE_ADDR *addrp, | |
a8a0fc4c | 1679 | int *realnump, gdb_byte *valuep) |
eec63939 | 1680 | { |
29639122 JB |
1681 | struct mips_frame_cache *info = mips_insn16_frame_cache (next_frame, |
1682 | this_cache); | |
1683 | trad_frame_get_prev_register (next_frame, info->saved_regs, regnum, | |
1684 | optimizedp, lvalp, addrp, realnump, valuep); | |
eec63939 AC |
1685 | } |
1686 | ||
29639122 | 1687 | static const struct frame_unwind mips_insn16_frame_unwind = |
eec63939 AC |
1688 | { |
1689 | NORMAL_FRAME, | |
29639122 JB |
1690 | mips_insn16_frame_this_id, |
1691 | mips_insn16_frame_prev_register | |
eec63939 AC |
1692 | }; |
1693 | ||
1694 | static const struct frame_unwind * | |
29639122 | 1695 | mips_insn16_frame_sniffer (struct frame_info *next_frame) |
eec63939 | 1696 | { |
6de5b849 | 1697 | CORE_ADDR pc = frame_pc_unwind (next_frame); |
0fe7e7c8 | 1698 | if (mips_pc_is_mips16 (pc)) |
29639122 JB |
1699 | return &mips_insn16_frame_unwind; |
1700 | return NULL; | |
eec63939 AC |
1701 | } |
1702 | ||
1703 | static CORE_ADDR | |
29639122 JB |
1704 | mips_insn16_frame_base_address (struct frame_info *next_frame, |
1705 | void **this_cache) | |
eec63939 | 1706 | { |
29639122 JB |
1707 | struct mips_frame_cache *info = mips_insn16_frame_cache (next_frame, |
1708 | this_cache); | |
1709 | return info->base; | |
eec63939 AC |
1710 | } |
1711 | ||
29639122 | 1712 | static const struct frame_base mips_insn16_frame_base = |
eec63939 | 1713 | { |
29639122 JB |
1714 | &mips_insn16_frame_unwind, |
1715 | mips_insn16_frame_base_address, | |
1716 | mips_insn16_frame_base_address, | |
1717 | mips_insn16_frame_base_address | |
eec63939 AC |
1718 | }; |
1719 | ||
1720 | static const struct frame_base * | |
29639122 | 1721 | mips_insn16_frame_base_sniffer (struct frame_info *next_frame) |
eec63939 | 1722 | { |
29639122 JB |
1723 | if (mips_insn16_frame_sniffer (next_frame) != NULL) |
1724 | return &mips_insn16_frame_base; | |
eec63939 AC |
1725 | else |
1726 | return NULL; | |
edfae063 AC |
1727 | } |
1728 | ||
29639122 JB |
1729 | /* Mark all the registers as unset in the saved_regs array |
1730 | of THIS_CACHE. Do nothing if THIS_CACHE is null. */ | |
1731 | ||
1732 | void | |
1733 | reset_saved_regs (struct mips_frame_cache *this_cache) | |
c906108c | 1734 | { |
29639122 JB |
1735 | if (this_cache == NULL || this_cache->saved_regs == NULL) |
1736 | return; | |
1737 | ||
1738 | { | |
1739 | const int num_regs = NUM_REGS; | |
1740 | int i; | |
64159455 | 1741 | |
29639122 JB |
1742 | for (i = 0; i < num_regs; i++) |
1743 | { | |
1744 | this_cache->saved_regs[i].addr = -1; | |
1745 | } | |
1746 | } | |
c906108c SS |
1747 | } |
1748 | ||
29639122 JB |
1749 | /* Analyze the function prologue from START_PC to LIMIT_PC. Builds |
1750 | the associated FRAME_CACHE if not null. | |
1751 | Return the address of the first instruction past the prologue. */ | |
c906108c | 1752 | |
875e1767 | 1753 | static CORE_ADDR |
29639122 JB |
1754 | mips32_scan_prologue (CORE_ADDR start_pc, CORE_ADDR limit_pc, |
1755 | struct frame_info *next_frame, | |
1756 | struct mips_frame_cache *this_cache) | |
c906108c | 1757 | { |
29639122 JB |
1758 | CORE_ADDR cur_pc; |
1759 | CORE_ADDR frame_addr = 0; /* Value of $r30. Used by gcc for frame-pointer */ | |
1760 | CORE_ADDR sp; | |
1761 | long frame_offset; | |
1762 | int frame_reg = MIPS_SP_REGNUM; | |
8fa9cfa1 | 1763 | |
29639122 JB |
1764 | CORE_ADDR end_prologue_addr = 0; |
1765 | int seen_sp_adjust = 0; | |
1766 | int load_immediate_bytes = 0; | |
8fa9cfa1 | 1767 | |
29639122 JB |
1768 | /* Can be called when there's no process, and hence when there's no |
1769 | NEXT_FRAME. */ | |
1770 | if (next_frame != NULL) | |
1771 | sp = read_next_frame_reg (next_frame, NUM_REGS + MIPS_SP_REGNUM); | |
8fa9cfa1 | 1772 | else |
29639122 | 1773 | sp = 0; |
9022177c | 1774 | |
29639122 JB |
1775 | if (limit_pc > start_pc + 200) |
1776 | limit_pc = start_pc + 200; | |
9022177c | 1777 | |
29639122 | 1778 | restart: |
9022177c | 1779 | |
29639122 | 1780 | frame_offset = 0; |
95ac2dcf | 1781 | for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += MIPS_INSN32_SIZE) |
9022177c | 1782 | { |
29639122 JB |
1783 | unsigned long inst, high_word, low_word; |
1784 | int reg; | |
9022177c | 1785 | |
29639122 JB |
1786 | /* Fetch the instruction. */ |
1787 | inst = (unsigned long) mips_fetch_instruction (cur_pc); | |
9022177c | 1788 | |
29639122 JB |
1789 | /* Save some code by pre-extracting some useful fields. */ |
1790 | high_word = (inst >> 16) & 0xffff; | |
1791 | low_word = inst & 0xffff; | |
1792 | reg = high_word & 0x1f; | |
fe29b929 | 1793 | |
29639122 JB |
1794 | if (high_word == 0x27bd /* addiu $sp,$sp,-i */ |
1795 | || high_word == 0x23bd /* addi $sp,$sp,-i */ | |
1796 | || high_word == 0x67bd) /* daddiu $sp,$sp,-i */ | |
1797 | { | |
1798 | if (low_word & 0x8000) /* negative stack adjustment? */ | |
1799 | frame_offset += 0x10000 - low_word; | |
1800 | else | |
1801 | /* Exit loop if a positive stack adjustment is found, which | |
1802 | usually means that the stack cleanup code in the function | |
1803 | epilogue is reached. */ | |
1804 | break; | |
1805 | seen_sp_adjust = 1; | |
1806 | } | |
1807 | else if ((high_word & 0xFFE0) == 0xafa0) /* sw reg,offset($sp) */ | |
1808 | { | |
1809 | set_reg_offset (this_cache, reg, sp + low_word); | |
1810 | } | |
1811 | else if ((high_word & 0xFFE0) == 0xffa0) /* sd reg,offset($sp) */ | |
1812 | { | |
1813 | /* Irix 6.2 N32 ABI uses sd instructions for saving $gp and $ra. */ | |
1814 | set_reg_offset (this_cache, reg, sp + low_word); | |
1815 | } | |
1816 | else if (high_word == 0x27be) /* addiu $30,$sp,size */ | |
1817 | { | |
1818 | /* Old gcc frame, r30 is virtual frame pointer. */ | |
1819 | if ((long) low_word != frame_offset) | |
1820 | frame_addr = sp + low_word; | |
1821 | else if (frame_reg == MIPS_SP_REGNUM) | |
1822 | { | |
1823 | unsigned alloca_adjust; | |
a4b8ebc8 | 1824 | |
29639122 JB |
1825 | frame_reg = 30; |
1826 | frame_addr = read_next_frame_reg (next_frame, NUM_REGS + 30); | |
1827 | alloca_adjust = (unsigned) (frame_addr - (sp + low_word)); | |
1828 | if (alloca_adjust > 0) | |
1829 | { | |
1830 | /* FP > SP + frame_size. This may be because of | |
1831 | an alloca or somethings similar. Fix sp to | |
1832 | "pre-alloca" value, and try again. */ | |
1833 | sp += alloca_adjust; | |
1834 | /* Need to reset the status of all registers. Otherwise, | |
1835 | we will hit a guard that prevents the new address | |
1836 | for each register to be recomputed during the second | |
1837 | pass. */ | |
1838 | reset_saved_regs (this_cache); | |
1839 | goto restart; | |
1840 | } | |
1841 | } | |
1842 | } | |
1843 | /* move $30,$sp. With different versions of gas this will be either | |
1844 | `addu $30,$sp,$zero' or `or $30,$sp,$zero' or `daddu 30,sp,$0'. | |
1845 | Accept any one of these. */ | |
1846 | else if (inst == 0x03A0F021 || inst == 0x03a0f025 || inst == 0x03a0f02d) | |
1847 | { | |
1848 | /* New gcc frame, virtual frame pointer is at r30 + frame_size. */ | |
1849 | if (frame_reg == MIPS_SP_REGNUM) | |
1850 | { | |
1851 | unsigned alloca_adjust; | |
c906108c | 1852 | |
29639122 JB |
1853 | frame_reg = 30; |
1854 | frame_addr = read_next_frame_reg (next_frame, NUM_REGS + 30); | |
1855 | alloca_adjust = (unsigned) (frame_addr - sp); | |
1856 | if (alloca_adjust > 0) | |
1857 | { | |
1858 | /* FP > SP + frame_size. This may be because of | |
1859 | an alloca or somethings similar. Fix sp to | |
1860 | "pre-alloca" value, and try again. */ | |
1861 | sp = frame_addr; | |
1862 | /* Need to reset the status of all registers. Otherwise, | |
1863 | we will hit a guard that prevents the new address | |
1864 | for each register to be recomputed during the second | |
1865 | pass. */ | |
1866 | reset_saved_regs (this_cache); | |
1867 | goto restart; | |
1868 | } | |
1869 | } | |
1870 | } | |
1871 | else if ((high_word & 0xFFE0) == 0xafc0) /* sw reg,offset($30) */ | |
1872 | { | |
1873 | set_reg_offset (this_cache, reg, frame_addr + low_word); | |
1874 | } | |
1875 | else if ((high_word & 0xFFE0) == 0xE7A0 /* swc1 freg,n($sp) */ | |
1876 | || (high_word & 0xF3E0) == 0xA3C0 /* sx reg,n($s8) */ | |
1877 | || (inst & 0xFF9F07FF) == 0x00800021 /* move reg,$a0-$a3 */ | |
1878 | || high_word == 0x3c1c /* lui $gp,n */ | |
1879 | || high_word == 0x279c /* addiu $gp,$gp,n */ | |
1880 | || inst == 0x0399e021 /* addu $gp,$gp,$t9 */ | |
1881 | || inst == 0x033ce021 /* addu $gp,$t9,$gp */ | |
1882 | ) | |
1883 | { | |
1884 | /* These instructions are part of the prologue, but we don't | |
1885 | need to do anything special to handle them. */ | |
1886 | } | |
1887 | /* The instructions below load $at or $t0 with an immediate | |
1888 | value in preparation for a stack adjustment via | |
1889 | subu $sp,$sp,[$at,$t0]. These instructions could also | |
1890 | initialize a local variable, so we accept them only before | |
1891 | a stack adjustment instruction was seen. */ | |
1892 | else if (!seen_sp_adjust | |
1893 | && (high_word == 0x3c01 /* lui $at,n */ | |
1894 | || high_word == 0x3c08 /* lui $t0,n */ | |
1895 | || high_word == 0x3421 /* ori $at,$at,n */ | |
1896 | || high_word == 0x3508 /* ori $t0,$t0,n */ | |
1897 | || high_word == 0x3401 /* ori $at,$zero,n */ | |
1898 | || high_word == 0x3408 /* ori $t0,$zero,n */ | |
1899 | )) | |
1900 | { | |
95ac2dcf | 1901 | load_immediate_bytes += MIPS_INSN32_SIZE; /* FIXME! */ |
29639122 JB |
1902 | } |
1903 | else | |
1904 | { | |
1905 | /* This instruction is not an instruction typically found | |
1906 | in a prologue, so we must have reached the end of the | |
1907 | prologue. */ | |
1908 | /* FIXME: brobecker/2004-10-10: Can't we just break out of this | |
1909 | loop now? Why would we need to continue scanning the function | |
1910 | instructions? */ | |
1911 | if (end_prologue_addr == 0) | |
1912 | end_prologue_addr = cur_pc; | |
1913 | } | |
a4b8ebc8 | 1914 | } |
c906108c | 1915 | |
29639122 JB |
1916 | if (this_cache != NULL) |
1917 | { | |
1918 | this_cache->base = | |
1919 | (frame_unwind_register_signed (next_frame, NUM_REGS + frame_reg) | |
1920 | + frame_offset); | |
1921 | /* FIXME: brobecker/2004-09-15: We should be able to get rid of | |
1922 | this assignment below, eventually. But it's still needed | |
1923 | for now. */ | |
1924 | this_cache->saved_regs[NUM_REGS + mips_regnum (current_gdbarch)->pc] | |
4c7d22cb | 1925 | = this_cache->saved_regs[NUM_REGS + MIPS_RA_REGNUM]; |
29639122 | 1926 | } |
c906108c | 1927 | |
29639122 JB |
1928 | /* If we didn't reach the end of the prologue when scanning the function |
1929 | instructions, then set end_prologue_addr to the address of the | |
1930 | instruction immediately after the last one we scanned. */ | |
1931 | /* brobecker/2004-10-10: I don't think this would ever happen, but | |
1932 | we may as well be careful and do our best if we have a null | |
1933 | end_prologue_addr. */ | |
1934 | if (end_prologue_addr == 0) | |
1935 | end_prologue_addr = cur_pc; | |
1936 | ||
1937 | /* In a frameless function, we might have incorrectly | |
1938 | skipped some load immediate instructions. Undo the skipping | |
1939 | if the load immediate was not followed by a stack adjustment. */ | |
1940 | if (load_immediate_bytes && !seen_sp_adjust) | |
1941 | end_prologue_addr -= load_immediate_bytes; | |
c906108c | 1942 | |
29639122 | 1943 | return end_prologue_addr; |
c906108c SS |
1944 | } |
1945 | ||
29639122 JB |
1946 | /* Heuristic unwinder for procedures using 32-bit instructions (covers |
1947 | both 32-bit and 64-bit MIPS ISAs). Procedures using 16-bit | |
1948 | instructions (a.k.a. MIPS16) are handled by the mips_insn16 | |
1949 | unwinder. */ | |
c906108c | 1950 | |
29639122 JB |
1951 | static struct mips_frame_cache * |
1952 | mips_insn32_frame_cache (struct frame_info *next_frame, void **this_cache) | |
c906108c | 1953 | { |
29639122 | 1954 | struct mips_frame_cache *cache; |
c906108c | 1955 | |
29639122 JB |
1956 | if ((*this_cache) != NULL) |
1957 | return (*this_cache); | |
c5aa993b | 1958 | |
29639122 JB |
1959 | cache = FRAME_OBSTACK_ZALLOC (struct mips_frame_cache); |
1960 | (*this_cache) = cache; | |
1961 | cache->saved_regs = trad_frame_alloc_saved_regs (next_frame); | |
c5aa993b | 1962 | |
29639122 JB |
1963 | /* Analyze the function prologue. */ |
1964 | { | |
6de5b849 JB |
1965 | const CORE_ADDR pc = |
1966 | frame_unwind_address_in_block (next_frame, NORMAL_FRAME); | |
29639122 | 1967 | CORE_ADDR start_addr; |
c906108c | 1968 | |
29639122 JB |
1969 | find_pc_partial_function (pc, NULL, &start_addr, NULL); |
1970 | if (start_addr == 0) | |
1971 | start_addr = heuristic_proc_start (pc); | |
1972 | /* We can't analyze the prologue if we couldn't find the begining | |
1973 | of the function. */ | |
1974 | if (start_addr == 0) | |
1975 | return cache; | |
c5aa993b | 1976 | |
29639122 JB |
1977 | mips32_scan_prologue (start_addr, pc, next_frame, *this_cache); |
1978 | } | |
1979 | ||
1980 | /* SP_REGNUM, contains the value and not the address. */ | |
1981 | trad_frame_set_value (cache->saved_regs, NUM_REGS + MIPS_SP_REGNUM, cache->base); | |
c5aa993b | 1982 | |
29639122 | 1983 | return (*this_cache); |
c906108c SS |
1984 | } |
1985 | ||
29639122 JB |
1986 | static void |
1987 | mips_insn32_frame_this_id (struct frame_info *next_frame, void **this_cache, | |
1988 | struct frame_id *this_id) | |
c906108c | 1989 | { |
29639122 JB |
1990 | struct mips_frame_cache *info = mips_insn32_frame_cache (next_frame, |
1991 | this_cache); | |
93d42b30 DJ |
1992 | (*this_id) = frame_id_build (info->base, |
1993 | frame_func_unwind (next_frame, NORMAL_FRAME)); | |
29639122 | 1994 | } |
c906108c | 1995 | |
29639122 JB |
1996 | static void |
1997 | mips_insn32_frame_prev_register (struct frame_info *next_frame, | |
1998 | void **this_cache, | |
1999 | int regnum, int *optimizedp, | |
2000 | enum lval_type *lvalp, CORE_ADDR *addrp, | |
a8a0fc4c | 2001 | int *realnump, gdb_byte *valuep) |
29639122 JB |
2002 | { |
2003 | struct mips_frame_cache *info = mips_insn32_frame_cache (next_frame, | |
2004 | this_cache); | |
2005 | trad_frame_get_prev_register (next_frame, info->saved_regs, regnum, | |
2006 | optimizedp, lvalp, addrp, realnump, valuep); | |
c906108c SS |
2007 | } |
2008 | ||
29639122 JB |
2009 | static const struct frame_unwind mips_insn32_frame_unwind = |
2010 | { | |
2011 | NORMAL_FRAME, | |
2012 | mips_insn32_frame_this_id, | |
2013 | mips_insn32_frame_prev_register | |
2014 | }; | |
c906108c | 2015 | |
29639122 JB |
2016 | static const struct frame_unwind * |
2017 | mips_insn32_frame_sniffer (struct frame_info *next_frame) | |
2018 | { | |
6de5b849 | 2019 | CORE_ADDR pc = frame_pc_unwind (next_frame); |
0fe7e7c8 | 2020 | if (! mips_pc_is_mips16 (pc)) |
29639122 JB |
2021 | return &mips_insn32_frame_unwind; |
2022 | return NULL; | |
2023 | } | |
c906108c | 2024 | |
1c645fec | 2025 | static CORE_ADDR |
29639122 JB |
2026 | mips_insn32_frame_base_address (struct frame_info *next_frame, |
2027 | void **this_cache) | |
c906108c | 2028 | { |
29639122 JB |
2029 | struct mips_frame_cache *info = mips_insn32_frame_cache (next_frame, |
2030 | this_cache); | |
2031 | return info->base; | |
2032 | } | |
c906108c | 2033 | |
29639122 JB |
2034 | static const struct frame_base mips_insn32_frame_base = |
2035 | { | |
2036 | &mips_insn32_frame_unwind, | |
2037 | mips_insn32_frame_base_address, | |
2038 | mips_insn32_frame_base_address, | |
2039 | mips_insn32_frame_base_address | |
2040 | }; | |
1c645fec | 2041 | |
29639122 JB |
2042 | static const struct frame_base * |
2043 | mips_insn32_frame_base_sniffer (struct frame_info *next_frame) | |
2044 | { | |
2045 | if (mips_insn32_frame_sniffer (next_frame) != NULL) | |
2046 | return &mips_insn32_frame_base; | |
a65bbe44 | 2047 | else |
29639122 JB |
2048 | return NULL; |
2049 | } | |
a65bbe44 | 2050 | |
29639122 JB |
2051 | static struct trad_frame_cache * |
2052 | mips_stub_frame_cache (struct frame_info *next_frame, void **this_cache) | |
2053 | { | |
2054 | CORE_ADDR pc; | |
2055 | CORE_ADDR start_addr; | |
2056 | CORE_ADDR stack_addr; | |
2057 | struct trad_frame_cache *this_trad_cache; | |
c906108c | 2058 | |
29639122 JB |
2059 | if ((*this_cache) != NULL) |
2060 | return (*this_cache); | |
2061 | this_trad_cache = trad_frame_cache_zalloc (next_frame); | |
2062 | (*this_cache) = this_trad_cache; | |
1c645fec | 2063 | |
29639122 | 2064 | /* The return address is in the link register. */ |
4c7d22cb | 2065 | trad_frame_set_reg_realreg (this_trad_cache, PC_REGNUM, MIPS_RA_REGNUM); |
1c645fec | 2066 | |
29639122 JB |
2067 | /* Frame ID, since it's a frameless / stackless function, no stack |
2068 | space is allocated and SP on entry is the current SP. */ | |
2069 | pc = frame_pc_unwind (next_frame); | |
2070 | find_pc_partial_function (pc, NULL, &start_addr, NULL); | |
4c7d22cb | 2071 | stack_addr = frame_unwind_register_signed (next_frame, MIPS_SP_REGNUM); |
29639122 | 2072 | trad_frame_set_id (this_trad_cache, frame_id_build (start_addr, stack_addr)); |
1c645fec | 2073 | |
29639122 JB |
2074 | /* Assume that the frame's base is the same as the |
2075 | stack-pointer. */ | |
2076 | trad_frame_set_this_base (this_trad_cache, stack_addr); | |
c906108c | 2077 | |
29639122 JB |
2078 | return this_trad_cache; |
2079 | } | |
c906108c | 2080 | |
29639122 JB |
2081 | static void |
2082 | mips_stub_frame_this_id (struct frame_info *next_frame, void **this_cache, | |
2083 | struct frame_id *this_id) | |
2084 | { | |
2085 | struct trad_frame_cache *this_trad_cache | |
2086 | = mips_stub_frame_cache (next_frame, this_cache); | |
2087 | trad_frame_get_id (this_trad_cache, this_id); | |
2088 | } | |
c906108c | 2089 | |
29639122 JB |
2090 | static void |
2091 | mips_stub_frame_prev_register (struct frame_info *next_frame, | |
2092 | void **this_cache, | |
2093 | int regnum, int *optimizedp, | |
2094 | enum lval_type *lvalp, CORE_ADDR *addrp, | |
a8a0fc4c | 2095 | int *realnump, gdb_byte *valuep) |
29639122 JB |
2096 | { |
2097 | struct trad_frame_cache *this_trad_cache | |
2098 | = mips_stub_frame_cache (next_frame, this_cache); | |
2099 | trad_frame_get_register (this_trad_cache, next_frame, regnum, optimizedp, | |
2100 | lvalp, addrp, realnump, valuep); | |
2101 | } | |
c906108c | 2102 | |
29639122 JB |
2103 | static const struct frame_unwind mips_stub_frame_unwind = |
2104 | { | |
2105 | NORMAL_FRAME, | |
2106 | mips_stub_frame_this_id, | |
2107 | mips_stub_frame_prev_register | |
2108 | }; | |
c906108c | 2109 | |
29639122 JB |
2110 | static const struct frame_unwind * |
2111 | mips_stub_frame_sniffer (struct frame_info *next_frame) | |
2112 | { | |
979b38e0 | 2113 | struct obj_section *s; |
93d42b30 | 2114 | CORE_ADDR pc = frame_unwind_address_in_block (next_frame, NORMAL_FRAME); |
979b38e0 | 2115 | |
29639122 JB |
2116 | if (in_plt_section (pc, NULL)) |
2117 | return &mips_stub_frame_unwind; | |
979b38e0 DJ |
2118 | |
2119 | /* Binutils for MIPS puts lazy resolution stubs into .MIPS.stubs. */ | |
2120 | s = find_pc_section (pc); | |
2121 | ||
2122 | if (s != NULL | |
2123 | && strcmp (bfd_get_section_name (s->objfile->obfd, s->the_bfd_section), | |
2124 | ".MIPS.stubs") == 0) | |
2125 | return &mips_stub_frame_unwind; | |
2126 | ||
2127 | return NULL; | |
29639122 | 2128 | } |
c906108c | 2129 | |
29639122 JB |
2130 | static CORE_ADDR |
2131 | mips_stub_frame_base_address (struct frame_info *next_frame, | |
2132 | void **this_cache) | |
2133 | { | |
2134 | struct trad_frame_cache *this_trad_cache | |
2135 | = mips_stub_frame_cache (next_frame, this_cache); | |
2136 | return trad_frame_get_this_base (this_trad_cache); | |
2137 | } | |
0fce0821 | 2138 | |
29639122 JB |
2139 | static const struct frame_base mips_stub_frame_base = |
2140 | { | |
2141 | &mips_stub_frame_unwind, | |
2142 | mips_stub_frame_base_address, | |
2143 | mips_stub_frame_base_address, | |
2144 | mips_stub_frame_base_address | |
2145 | }; | |
2146 | ||
2147 | static const struct frame_base * | |
2148 | mips_stub_frame_base_sniffer (struct frame_info *next_frame) | |
2149 | { | |
2150 | if (mips_stub_frame_sniffer (next_frame) != NULL) | |
2151 | return &mips_stub_frame_base; | |
2152 | else | |
2153 | return NULL; | |
2154 | } | |
2155 | ||
2156 | static CORE_ADDR | |
2157 | read_next_frame_reg (struct frame_info *fi, int regno) | |
2158 | { | |
2159 | /* Always a pseudo. */ | |
2160 | gdb_assert (regno >= NUM_REGS); | |
2161 | if (fi == NULL) | |
0fce0821 | 2162 | { |
29639122 JB |
2163 | LONGEST val; |
2164 | regcache_cooked_read_signed (current_regcache, regno, &val); | |
2165 | return val; | |
0fce0821 | 2166 | } |
29639122 JB |
2167 | else |
2168 | return frame_unwind_register_signed (fi, regno); | |
1c645fec | 2169 | |
c906108c SS |
2170 | } |
2171 | ||
29639122 | 2172 | /* mips_addr_bits_remove - remove useless address bits */ |
65596487 | 2173 | |
29639122 JB |
2174 | static CORE_ADDR |
2175 | mips_addr_bits_remove (CORE_ADDR addr) | |
65596487 | 2176 | { |
29639122 JB |
2177 | struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); |
2178 | if (mips_mask_address_p (tdep) && (((ULONGEST) addr) >> 32 == 0xffffffffUL)) | |
2179 | /* This hack is a work-around for existing boards using PMON, the | |
2180 | simulator, and any other 64-bit targets that doesn't have true | |
2181 | 64-bit addressing. On these targets, the upper 32 bits of | |
2182 | addresses are ignored by the hardware. Thus, the PC or SP are | |
2183 | likely to have been sign extended to all 1s by instruction | |
2184 | sequences that load 32-bit addresses. For example, a typical | |
2185 | piece of code that loads an address is this: | |
65596487 | 2186 | |
29639122 JB |
2187 | lui $r2, <upper 16 bits> |
2188 | ori $r2, <lower 16 bits> | |
65596487 | 2189 | |
29639122 JB |
2190 | But the lui sign-extends the value such that the upper 32 bits |
2191 | may be all 1s. The workaround is simply to mask off these | |
2192 | bits. In the future, gcc may be changed to support true 64-bit | |
2193 | addressing, and this masking will have to be disabled. */ | |
2194 | return addr &= 0xffffffffUL; | |
2195 | else | |
2196 | return addr; | |
65596487 JB |
2197 | } |
2198 | ||
29639122 JB |
2199 | /* mips_software_single_step() is called just before we want to resume |
2200 | the inferior, if we want to single-step it but there is no hardware | |
2201 | or kernel single-step support (MIPS on GNU/Linux for example). We find | |
2202 | the target of the coming instruction and breakpoint it. | |
1e05a7bf | 2203 | |
29639122 JB |
2204 | single_step is also called just after the inferior stops. If we had |
2205 | set up a simulated single-step, we undo our damage. */ | |
2206 | ||
2207 | void | |
2208 | mips_software_single_step (enum target_signal sig, int insert_breakpoints_p) | |
c906108c | 2209 | { |
8181d85f | 2210 | CORE_ADDR pc, next_pc; |
65596487 | 2211 | |
29639122 JB |
2212 | if (insert_breakpoints_p) |
2213 | { | |
2214 | pc = read_register (mips_regnum (current_gdbarch)->pc); | |
2215 | next_pc = mips_next_pc (pc); | |
98b4dd94 | 2216 | |
8181d85f | 2217 | insert_single_step_breakpoint (next_pc); |
29639122 | 2218 | } |
a65bbe44 | 2219 | else |
8181d85f | 2220 | remove_single_step_breakpoints (); |
29639122 | 2221 | } |
a65bbe44 | 2222 | |
29639122 JB |
2223 | /* Test whether the PC points to the return instruction at the |
2224 | end of a function. */ | |
65596487 | 2225 | |
29639122 JB |
2226 | static int |
2227 | mips_about_to_return (CORE_ADDR pc) | |
2228 | { | |
0fe7e7c8 | 2229 | if (mips_pc_is_mips16 (pc)) |
29639122 JB |
2230 | /* This mips16 case isn't necessarily reliable. Sometimes the compiler |
2231 | generates a "jr $ra"; other times it generates code to load | |
2232 | the return address from the stack to an accessible register (such | |
2233 | as $a3), then a "jr" using that register. This second case | |
2234 | is almost impossible to distinguish from an indirect jump | |
2235 | used for switch statements, so we don't even try. */ | |
2236 | return mips_fetch_instruction (pc) == 0xe820; /* jr $ra */ | |
2237 | else | |
2238 | return mips_fetch_instruction (pc) == 0x3e00008; /* jr $ra */ | |
2239 | } | |
c906108c | 2240 | |
c906108c | 2241 | |
29639122 JB |
2242 | /* This fencepost looks highly suspicious to me. Removing it also |
2243 | seems suspicious as it could affect remote debugging across serial | |
2244 | lines. */ | |
c906108c | 2245 | |
29639122 JB |
2246 | static CORE_ADDR |
2247 | heuristic_proc_start (CORE_ADDR pc) | |
2248 | { | |
2249 | CORE_ADDR start_pc; | |
2250 | CORE_ADDR fence; | |
2251 | int instlen; | |
2252 | int seen_adjsp = 0; | |
65596487 | 2253 | |
29639122 JB |
2254 | pc = ADDR_BITS_REMOVE (pc); |
2255 | start_pc = pc; | |
2256 | fence = start_pc - heuristic_fence_post; | |
2257 | if (start_pc == 0) | |
2258 | return 0; | |
65596487 | 2259 | |
29639122 JB |
2260 | if (heuristic_fence_post == UINT_MAX || fence < VM_MIN_ADDRESS) |
2261 | fence = VM_MIN_ADDRESS; | |
65596487 | 2262 | |
95ac2dcf | 2263 | instlen = mips_pc_is_mips16 (pc) ? MIPS_INSN16_SIZE : MIPS_INSN32_SIZE; |
98b4dd94 | 2264 | |
29639122 JB |
2265 | /* search back for previous return */ |
2266 | for (start_pc -= instlen;; start_pc -= instlen) | |
2267 | if (start_pc < fence) | |
2268 | { | |
2269 | /* It's not clear to me why we reach this point when | |
2270 | stop_soon, but with this test, at least we | |
2271 | don't print out warnings for every child forked (eg, on | |
2272 | decstation). 22apr93 [email protected]. */ | |
2273 | if (stop_soon == NO_STOP_QUIETLY) | |
2274 | { | |
2275 | static int blurb_printed = 0; | |
98b4dd94 | 2276 | |
8a3fe4f8 | 2277 | warning (_("GDB can't find the start of the function at 0x%s."), |
29639122 JB |
2278 | paddr_nz (pc)); |
2279 | ||
2280 | if (!blurb_printed) | |
2281 | { | |
2282 | /* This actually happens frequently in embedded | |
2283 | development, when you first connect to a board | |
2284 | and your stack pointer and pc are nowhere in | |
2285 | particular. This message needs to give people | |
2286 | in that situation enough information to | |
2287 | determine that it's no big deal. */ | |
2288 | printf_filtered ("\n\ | |
2289 | GDB is unable to find the start of the function at 0x%s\n\ | |
2290 | and thus can't determine the size of that function's stack frame.\n\ | |
2291 | This means that GDB may be unable to access that stack frame, or\n\ | |
2292 | the frames below it.\n\ | |
2293 | This problem is most likely caused by an invalid program counter or\n\ | |
2294 | stack pointer.\n\ | |
2295 | However, if you think GDB should simply search farther back\n\ | |
2296 | from 0x%s for code which looks like the beginning of a\n\ | |
2297 | function, you can increase the range of the search using the `set\n\ | |
2298 | heuristic-fence-post' command.\n", paddr_nz (pc), paddr_nz (pc)); | |
2299 | blurb_printed = 1; | |
2300 | } | |
2301 | } | |
2302 | ||
2303 | return 0; | |
2304 | } | |
0fe7e7c8 | 2305 | else if (mips_pc_is_mips16 (start_pc)) |
29639122 JB |
2306 | { |
2307 | unsigned short inst; | |
2308 | ||
2309 | /* On MIPS16, any one of the following is likely to be the | |
2310 | start of a function: | |
2311 | entry | |
2312 | addiu sp,-n | |
2313 | daddiu sp,-n | |
2314 | extend -n followed by 'addiu sp,+n' or 'daddiu sp,+n' */ | |
2315 | inst = mips_fetch_instruction (start_pc); | |
2316 | if (((inst & 0xf81f) == 0xe809 && (inst & 0x700) != 0x700) /* entry */ | |
2317 | || (inst & 0xff80) == 0x6380 /* addiu sp,-n */ | |
2318 | || (inst & 0xff80) == 0xfb80 /* daddiu sp,-n */ | |
2319 | || ((inst & 0xf810) == 0xf010 && seen_adjsp)) /* extend -n */ | |
2320 | break; | |
2321 | else if ((inst & 0xff00) == 0x6300 /* addiu sp */ | |
2322 | || (inst & 0xff00) == 0xfb00) /* daddiu sp */ | |
2323 | seen_adjsp = 1; | |
2324 | else | |
2325 | seen_adjsp = 0; | |
2326 | } | |
2327 | else if (mips_about_to_return (start_pc)) | |
2328 | { | |
4c7d22cb | 2329 | /* Skip return and its delay slot. */ |
95ac2dcf | 2330 | start_pc += 2 * MIPS_INSN32_SIZE; |
29639122 JB |
2331 | break; |
2332 | } | |
2333 | ||
2334 | return start_pc; | |
c906108c SS |
2335 | } |
2336 | ||
6c0d6680 DJ |
2337 | struct mips_objfile_private |
2338 | { | |
2339 | bfd_size_type size; | |
2340 | char *contents; | |
2341 | }; | |
2342 | ||
f09ded24 AC |
2343 | /* According to the current ABI, should the type be passed in a |
2344 | floating-point register (assuming that there is space)? When there | |
a1f5b845 | 2345 | is no FPU, FP are not even considered as possible candidates for |
f09ded24 AC |
2346 | FP registers and, consequently this returns false - forces FP |
2347 | arguments into integer registers. */ | |
2348 | ||
2349 | static int | |
2350 | fp_register_arg_p (enum type_code typecode, struct type *arg_type) | |
2351 | { | |
2352 | return ((typecode == TYPE_CODE_FLT | |
2353 | || (MIPS_EABI | |
6d82d43b AC |
2354 | && (typecode == TYPE_CODE_STRUCT |
2355 | || typecode == TYPE_CODE_UNION) | |
f09ded24 | 2356 | && TYPE_NFIELDS (arg_type) == 1 |
b2d6f210 MS |
2357 | && TYPE_CODE (check_typedef (TYPE_FIELD_TYPE (arg_type, 0))) |
2358 | == TYPE_CODE_FLT)) | |
c86b5b38 | 2359 | && MIPS_FPU_TYPE != MIPS_FPU_NONE); |
f09ded24 AC |
2360 | } |
2361 | ||
49e790b0 DJ |
2362 | /* On o32, argument passing in GPRs depends on the alignment of the type being |
2363 | passed. Return 1 if this type must be aligned to a doubleword boundary. */ | |
2364 | ||
2365 | static int | |
2366 | mips_type_needs_double_align (struct type *type) | |
2367 | { | |
2368 | enum type_code typecode = TYPE_CODE (type); | |
361d1df0 | 2369 | |
49e790b0 DJ |
2370 | if (typecode == TYPE_CODE_FLT && TYPE_LENGTH (type) == 8) |
2371 | return 1; | |
2372 | else if (typecode == TYPE_CODE_STRUCT) | |
2373 | { | |
2374 | if (TYPE_NFIELDS (type) < 1) | |
2375 | return 0; | |
2376 | return mips_type_needs_double_align (TYPE_FIELD_TYPE (type, 0)); | |
2377 | } | |
2378 | else if (typecode == TYPE_CODE_UNION) | |
2379 | { | |
361d1df0 | 2380 | int i, n; |
49e790b0 DJ |
2381 | |
2382 | n = TYPE_NFIELDS (type); | |
2383 | for (i = 0; i < n; i++) | |
2384 | if (mips_type_needs_double_align (TYPE_FIELD_TYPE (type, i))) | |
2385 | return 1; | |
2386 | return 0; | |
2387 | } | |
2388 | return 0; | |
2389 | } | |
2390 | ||
dc604539 AC |
2391 | /* Adjust the address downward (direction of stack growth) so that it |
2392 | is correctly aligned for a new stack frame. */ | |
2393 | static CORE_ADDR | |
2394 | mips_frame_align (struct gdbarch *gdbarch, CORE_ADDR addr) | |
2395 | { | |
5b03f266 | 2396 | return align_down (addr, 16); |
dc604539 AC |
2397 | } |
2398 | ||
f7ab6ec6 | 2399 | static CORE_ADDR |
7d9b040b | 2400 | mips_eabi_push_dummy_call (struct gdbarch *gdbarch, struct value *function, |
6d82d43b AC |
2401 | struct regcache *regcache, CORE_ADDR bp_addr, |
2402 | int nargs, struct value **args, CORE_ADDR sp, | |
2403 | int struct_return, CORE_ADDR struct_addr) | |
c906108c SS |
2404 | { |
2405 | int argreg; | |
2406 | int float_argreg; | |
2407 | int argnum; | |
2408 | int len = 0; | |
2409 | int stack_offset = 0; | |
480d3dd2 | 2410 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
7d9b040b | 2411 | CORE_ADDR func_addr = find_function_addr (function, NULL); |
c906108c | 2412 | |
25ab4790 AC |
2413 | /* For shared libraries, "t9" needs to point at the function |
2414 | address. */ | |
4c7d22cb | 2415 | regcache_cooked_write_signed (regcache, MIPS_T9_REGNUM, func_addr); |
25ab4790 AC |
2416 | |
2417 | /* Set the return address register to point to the entry point of | |
2418 | the program, where a breakpoint lies in wait. */ | |
4c7d22cb | 2419 | regcache_cooked_write_signed (regcache, MIPS_RA_REGNUM, bp_addr); |
25ab4790 | 2420 | |
c906108c | 2421 | /* First ensure that the stack and structure return address (if any) |
cb3d25d1 MS |
2422 | are properly aligned. The stack has to be at least 64-bit |
2423 | aligned even on 32-bit machines, because doubles must be 64-bit | |
2424 | aligned. For n32 and n64, stack frames need to be 128-bit | |
2425 | aligned, so we round to this widest known alignment. */ | |
2426 | ||
5b03f266 AC |
2427 | sp = align_down (sp, 16); |
2428 | struct_addr = align_down (struct_addr, 16); | |
c5aa993b | 2429 | |
46e0f506 | 2430 | /* Now make space on the stack for the args. We allocate more |
c906108c | 2431 | than necessary for EABI, because the first few arguments are |
46e0f506 | 2432 | passed in registers, but that's OK. */ |
c906108c | 2433 | for (argnum = 0; argnum < nargs; argnum++) |
4991999e | 2434 | len += align_up (TYPE_LENGTH (value_type (args[argnum])), |
13326b4e | 2435 | mips_stack_argsize (gdbarch)); |
5b03f266 | 2436 | sp -= align_up (len, 16); |
c906108c | 2437 | |
9ace0497 | 2438 | if (mips_debug) |
6d82d43b | 2439 | fprintf_unfiltered (gdb_stdlog, |
5b03f266 AC |
2440 | "mips_eabi_push_dummy_call: sp=0x%s allocated %ld\n", |
2441 | paddr_nz (sp), (long) align_up (len, 16)); | |
9ace0497 | 2442 | |
c906108c | 2443 | /* Initialize the integer and float register pointers. */ |
4c7d22cb | 2444 | argreg = MIPS_A0_REGNUM; |
56cea623 | 2445 | float_argreg = mips_fpa0_regnum (current_gdbarch); |
c906108c | 2446 | |
46e0f506 | 2447 | /* The struct_return pointer occupies the first parameter-passing reg. */ |
c906108c | 2448 | if (struct_return) |
9ace0497 AC |
2449 | { |
2450 | if (mips_debug) | |
2451 | fprintf_unfiltered (gdb_stdlog, | |
25ab4790 | 2452 | "mips_eabi_push_dummy_call: struct_return reg=%d 0x%s\n", |
cb3d25d1 | 2453 | argreg, paddr_nz (struct_addr)); |
9ace0497 AC |
2454 | write_register (argreg++, struct_addr); |
2455 | } | |
c906108c SS |
2456 | |
2457 | /* Now load as many as possible of the first arguments into | |
2458 | registers, and push the rest onto the stack. Loop thru args | |
2459 | from first to last. */ | |
2460 | for (argnum = 0; argnum < nargs; argnum++) | |
2461 | { | |
47a35522 MK |
2462 | const gdb_byte *val; |
2463 | gdb_byte valbuf[MAX_REGISTER_SIZE]; | |
ea7c478f | 2464 | struct value *arg = args[argnum]; |
4991999e | 2465 | struct type *arg_type = check_typedef (value_type (arg)); |
c906108c SS |
2466 | int len = TYPE_LENGTH (arg_type); |
2467 | enum type_code typecode = TYPE_CODE (arg_type); | |
2468 | ||
9ace0497 AC |
2469 | if (mips_debug) |
2470 | fprintf_unfiltered (gdb_stdlog, | |
25ab4790 | 2471 | "mips_eabi_push_dummy_call: %d len=%d type=%d", |
acdb74a0 | 2472 | argnum + 1, len, (int) typecode); |
9ace0497 | 2473 | |
c906108c | 2474 | /* The EABI passes structures that do not fit in a register by |
46e0f506 | 2475 | reference. */ |
13326b4e | 2476 | if (len > mips_abi_regsize (gdbarch) |
9ace0497 | 2477 | && (typecode == TYPE_CODE_STRUCT || typecode == TYPE_CODE_UNION)) |
c906108c | 2478 | { |
13326b4e | 2479 | store_unsigned_integer (valbuf, mips_abi_regsize (gdbarch), |
480d3dd2 | 2480 | VALUE_ADDRESS (arg)); |
c906108c | 2481 | typecode = TYPE_CODE_PTR; |
13326b4e | 2482 | len = mips_abi_regsize (gdbarch); |
c906108c | 2483 | val = valbuf; |
9ace0497 AC |
2484 | if (mips_debug) |
2485 | fprintf_unfiltered (gdb_stdlog, " push"); | |
c906108c SS |
2486 | } |
2487 | else | |
47a35522 | 2488 | val = value_contents (arg); |
c906108c SS |
2489 | |
2490 | /* 32-bit ABIs always start floating point arguments in an | |
acdb74a0 AC |
2491 | even-numbered floating point register. Round the FP register |
2492 | up before the check to see if there are any FP registers | |
46e0f506 MS |
2493 | left. Non MIPS_EABI targets also pass the FP in the integer |
2494 | registers so also round up normal registers. */ | |
ceae6e75 AC |
2495 | if (mips_abi_regsize (gdbarch) < 8 |
2496 | && fp_register_arg_p (typecode, arg_type)) | |
acdb74a0 AC |
2497 | { |
2498 | if ((float_argreg & 1)) | |
2499 | float_argreg++; | |
2500 | } | |
c906108c SS |
2501 | |
2502 | /* Floating point arguments passed in registers have to be | |
2503 | treated specially. On 32-bit architectures, doubles | |
c5aa993b JM |
2504 | are passed in register pairs; the even register gets |
2505 | the low word, and the odd register gets the high word. | |
2506 | On non-EABI processors, the first two floating point arguments are | |
2507 | also copied to general registers, because MIPS16 functions | |
2508 | don't use float registers for arguments. This duplication of | |
2509 | arguments in general registers can't hurt non-MIPS16 functions | |
2510 | because those registers are normally skipped. */ | |
1012bd0e EZ |
2511 | /* MIPS_EABI squeezes a struct that contains a single floating |
2512 | point value into an FP register instead of pushing it onto the | |
46e0f506 | 2513 | stack. */ |
f09ded24 AC |
2514 | if (fp_register_arg_p (typecode, arg_type) |
2515 | && float_argreg <= MIPS_LAST_FP_ARG_REGNUM) | |
c906108c | 2516 | { |
8b07f6d8 | 2517 | if (register_size (gdbarch, float_argreg) < 8 && len == 8) |
c906108c | 2518 | { |
d7449b42 | 2519 | int low_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 4 : 0; |
c906108c SS |
2520 | unsigned long regval; |
2521 | ||
2522 | /* Write the low word of the double to the even register(s). */ | |
c5aa993b | 2523 | regval = extract_unsigned_integer (val + low_offset, 4); |
9ace0497 | 2524 | if (mips_debug) |
acdb74a0 | 2525 | fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s", |
9ace0497 | 2526 | float_argreg, phex (regval, 4)); |
c906108c | 2527 | write_register (float_argreg++, regval); |
c906108c SS |
2528 | |
2529 | /* Write the high word of the double to the odd register(s). */ | |
c5aa993b | 2530 | regval = extract_unsigned_integer (val + 4 - low_offset, 4); |
9ace0497 | 2531 | if (mips_debug) |
acdb74a0 | 2532 | fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s", |
9ace0497 | 2533 | float_argreg, phex (regval, 4)); |
c906108c | 2534 | write_register (float_argreg++, regval); |
c906108c SS |
2535 | } |
2536 | else | |
2537 | { | |
2538 | /* This is a floating point value that fits entirely | |
2539 | in a single register. */ | |
53a5351d | 2540 | /* On 32 bit ABI's the float_argreg is further adjusted |
6d82d43b | 2541 | above to ensure that it is even register aligned. */ |
9ace0497 AC |
2542 | LONGEST regval = extract_unsigned_integer (val, len); |
2543 | if (mips_debug) | |
acdb74a0 | 2544 | fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s", |
9ace0497 | 2545 | float_argreg, phex (regval, len)); |
c906108c | 2546 | write_register (float_argreg++, regval); |
c906108c SS |
2547 | } |
2548 | } | |
2549 | else | |
2550 | { | |
2551 | /* Copy the argument to general registers or the stack in | |
2552 | register-sized pieces. Large arguments are split between | |
2553 | registers and stack. */ | |
4246e332 | 2554 | /* Note: structs whose size is not a multiple of |
d5ac5a39 AC |
2555 | mips_abi_regsize() are treated specially: Irix cc passes |
2556 | them in registers where gcc sometimes puts them on the | |
2557 | stack. For maximum compatibility, we will put them in | |
2558 | both places. */ | |
13326b4e AC |
2559 | int odd_sized_struct = ((len > mips_abi_regsize (gdbarch)) |
2560 | && (len % mips_abi_regsize (gdbarch) != 0)); | |
46e0f506 | 2561 | |
f09ded24 | 2562 | /* Note: Floating-point values that didn't fit into an FP |
6d82d43b | 2563 | register are only written to memory. */ |
c906108c SS |
2564 | while (len > 0) |
2565 | { | |
ebafbe83 | 2566 | /* Remember if the argument was written to the stack. */ |
566f0f7a | 2567 | int stack_used_p = 0; |
13326b4e AC |
2568 | int partial_len = (len < mips_abi_regsize (gdbarch) |
2569 | ? len : mips_abi_regsize (gdbarch)); | |
c906108c | 2570 | |
acdb74a0 AC |
2571 | if (mips_debug) |
2572 | fprintf_unfiltered (gdb_stdlog, " -- partial=%d", | |
2573 | partial_len); | |
2574 | ||
566f0f7a | 2575 | /* Write this portion of the argument to the stack. */ |
f09ded24 AC |
2576 | if (argreg > MIPS_LAST_ARG_REGNUM |
2577 | || odd_sized_struct | |
2578 | || fp_register_arg_p (typecode, arg_type)) | |
c906108c | 2579 | { |
c906108c SS |
2580 | /* Should shorter than int integer values be |
2581 | promoted to int before being stored? */ | |
c906108c | 2582 | int longword_offset = 0; |
9ace0497 | 2583 | CORE_ADDR addr; |
566f0f7a | 2584 | stack_used_p = 1; |
d7449b42 | 2585 | if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) |
7a292a7a | 2586 | { |
13326b4e | 2587 | if (mips_stack_argsize (gdbarch) == 8 |
480d3dd2 AC |
2588 | && (typecode == TYPE_CODE_INT |
2589 | || typecode == TYPE_CODE_PTR | |
6d82d43b | 2590 | || typecode == TYPE_CODE_FLT) && len <= 4) |
13326b4e | 2591 | longword_offset = mips_stack_argsize (gdbarch) - len; |
480d3dd2 AC |
2592 | else if ((typecode == TYPE_CODE_STRUCT |
2593 | || typecode == TYPE_CODE_UNION) | |
2594 | && (TYPE_LENGTH (arg_type) | |
13326b4e AC |
2595 | < mips_stack_argsize (gdbarch))) |
2596 | longword_offset = mips_stack_argsize (gdbarch) - len; | |
7a292a7a | 2597 | } |
c5aa993b | 2598 | |
9ace0497 AC |
2599 | if (mips_debug) |
2600 | { | |
cb3d25d1 MS |
2601 | fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s", |
2602 | paddr_nz (stack_offset)); | |
2603 | fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s", | |
2604 | paddr_nz (longword_offset)); | |
9ace0497 | 2605 | } |
361d1df0 | 2606 | |
9ace0497 AC |
2607 | addr = sp + stack_offset + longword_offset; |
2608 | ||
2609 | if (mips_debug) | |
2610 | { | |
2611 | int i; | |
6d82d43b | 2612 | fprintf_unfiltered (gdb_stdlog, " @0x%s ", |
cb3d25d1 | 2613 | paddr_nz (addr)); |
9ace0497 AC |
2614 | for (i = 0; i < partial_len; i++) |
2615 | { | |
6d82d43b | 2616 | fprintf_unfiltered (gdb_stdlog, "%02x", |
cb3d25d1 | 2617 | val[i] & 0xff); |
9ace0497 AC |
2618 | } |
2619 | } | |
2620 | write_memory (addr, val, partial_len); | |
c906108c SS |
2621 | } |
2622 | ||
f09ded24 AC |
2623 | /* Note!!! This is NOT an else clause. Odd sized |
2624 | structs may go thru BOTH paths. Floating point | |
46e0f506 | 2625 | arguments will not. */ |
566f0f7a | 2626 | /* Write this portion of the argument to a general |
6d82d43b | 2627 | purpose register. */ |
f09ded24 AC |
2628 | if (argreg <= MIPS_LAST_ARG_REGNUM |
2629 | && !fp_register_arg_p (typecode, arg_type)) | |
c906108c | 2630 | { |
6d82d43b AC |
2631 | LONGEST regval = |
2632 | extract_unsigned_integer (val, partial_len); | |
c906108c | 2633 | |
9ace0497 | 2634 | if (mips_debug) |
acdb74a0 | 2635 | fprintf_filtered (gdb_stdlog, " - reg=%d val=%s", |
9ace0497 | 2636 | argreg, |
6d82d43b | 2637 | phex (regval, |
13326b4e | 2638 | mips_abi_regsize (gdbarch))); |
c906108c SS |
2639 | write_register (argreg, regval); |
2640 | argreg++; | |
c906108c | 2641 | } |
c5aa993b | 2642 | |
c906108c SS |
2643 | len -= partial_len; |
2644 | val += partial_len; | |
2645 | ||
566f0f7a | 2646 | /* Compute the the offset into the stack at which we |
6d82d43b | 2647 | will copy the next parameter. |
566f0f7a | 2648 | |
566f0f7a | 2649 | In the new EABI (and the NABI32), the stack_offset |
46e0f506 | 2650 | only needs to be adjusted when it has been used. */ |
c906108c | 2651 | |
46e0f506 | 2652 | if (stack_used_p) |
480d3dd2 | 2653 | stack_offset += align_up (partial_len, |
13326b4e | 2654 | mips_stack_argsize (gdbarch)); |
c906108c SS |
2655 | } |
2656 | } | |
9ace0497 AC |
2657 | if (mips_debug) |
2658 | fprintf_unfiltered (gdb_stdlog, "\n"); | |
c906108c SS |
2659 | } |
2660 | ||
f10683bb | 2661 | regcache_cooked_write_signed (regcache, MIPS_SP_REGNUM, sp); |
310e9b6a | 2662 | |
0f71a2f6 JM |
2663 | /* Return adjusted stack pointer. */ |
2664 | return sp; | |
2665 | } | |
2666 | ||
a1f5b845 | 2667 | /* Determine the return value convention being used. */ |
6d82d43b | 2668 | |
9c8fdbfa AC |
2669 | static enum return_value_convention |
2670 | mips_eabi_return_value (struct gdbarch *gdbarch, | |
2671 | struct type *type, struct regcache *regcache, | |
47a35522 | 2672 | gdb_byte *readbuf, const gdb_byte *writebuf) |
6d82d43b | 2673 | { |
9c8fdbfa AC |
2674 | if (TYPE_LENGTH (type) > 2 * mips_abi_regsize (gdbarch)) |
2675 | return RETURN_VALUE_STRUCT_CONVENTION; | |
2676 | if (readbuf) | |
2677 | memset (readbuf, 0, TYPE_LENGTH (type)); | |
2678 | return RETURN_VALUE_REGISTER_CONVENTION; | |
6d82d43b AC |
2679 | } |
2680 | ||
6d82d43b AC |
2681 | |
2682 | /* N32/N64 ABI stuff. */ | |
ebafbe83 | 2683 | |
f7ab6ec6 | 2684 | static CORE_ADDR |
7d9b040b | 2685 | mips_n32n64_push_dummy_call (struct gdbarch *gdbarch, struct value *function, |
6d82d43b AC |
2686 | struct regcache *regcache, CORE_ADDR bp_addr, |
2687 | int nargs, struct value **args, CORE_ADDR sp, | |
2688 | int struct_return, CORE_ADDR struct_addr) | |
cb3d25d1 MS |
2689 | { |
2690 | int argreg; | |
2691 | int float_argreg; | |
2692 | int argnum; | |
2693 | int len = 0; | |
2694 | int stack_offset = 0; | |
480d3dd2 | 2695 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
7d9b040b | 2696 | CORE_ADDR func_addr = find_function_addr (function, NULL); |
cb3d25d1 | 2697 | |
25ab4790 AC |
2698 | /* For shared libraries, "t9" needs to point at the function |
2699 | address. */ | |
4c7d22cb | 2700 | regcache_cooked_write_signed (regcache, MIPS_T9_REGNUM, func_addr); |
25ab4790 AC |
2701 | |
2702 | /* Set the return address register to point to the entry point of | |
2703 | the program, where a breakpoint lies in wait. */ | |
4c7d22cb | 2704 | regcache_cooked_write_signed (regcache, MIPS_RA_REGNUM, bp_addr); |
25ab4790 | 2705 | |
cb3d25d1 MS |
2706 | /* First ensure that the stack and structure return address (if any) |
2707 | are properly aligned. The stack has to be at least 64-bit | |
2708 | aligned even on 32-bit machines, because doubles must be 64-bit | |
2709 | aligned. For n32 and n64, stack frames need to be 128-bit | |
2710 | aligned, so we round to this widest known alignment. */ | |
2711 | ||
5b03f266 AC |
2712 | sp = align_down (sp, 16); |
2713 | struct_addr = align_down (struct_addr, 16); | |
cb3d25d1 MS |
2714 | |
2715 | /* Now make space on the stack for the args. */ | |
2716 | for (argnum = 0; argnum < nargs; argnum++) | |
4991999e | 2717 | len += align_up (TYPE_LENGTH (value_type (args[argnum])), |
13326b4e | 2718 | mips_stack_argsize (gdbarch)); |
5b03f266 | 2719 | sp -= align_up (len, 16); |
cb3d25d1 MS |
2720 | |
2721 | if (mips_debug) | |
6d82d43b | 2722 | fprintf_unfiltered (gdb_stdlog, |
5b03f266 AC |
2723 | "mips_n32n64_push_dummy_call: sp=0x%s allocated %ld\n", |
2724 | paddr_nz (sp), (long) align_up (len, 16)); | |
cb3d25d1 MS |
2725 | |
2726 | /* Initialize the integer and float register pointers. */ | |
4c7d22cb | 2727 | argreg = MIPS_A0_REGNUM; |
56cea623 | 2728 | float_argreg = mips_fpa0_regnum (current_gdbarch); |
cb3d25d1 | 2729 | |
46e0f506 | 2730 | /* The struct_return pointer occupies the first parameter-passing reg. */ |
cb3d25d1 MS |
2731 | if (struct_return) |
2732 | { | |
2733 | if (mips_debug) | |
2734 | fprintf_unfiltered (gdb_stdlog, | |
25ab4790 | 2735 | "mips_n32n64_push_dummy_call: struct_return reg=%d 0x%s\n", |
cb3d25d1 MS |
2736 | argreg, paddr_nz (struct_addr)); |
2737 | write_register (argreg++, struct_addr); | |
2738 | } | |
2739 | ||
2740 | /* Now load as many as possible of the first arguments into | |
2741 | registers, and push the rest onto the stack. Loop thru args | |
2742 | from first to last. */ | |
2743 | for (argnum = 0; argnum < nargs; argnum++) | |
2744 | { | |
47a35522 | 2745 | const gdb_byte *val; |
cb3d25d1 | 2746 | struct value *arg = args[argnum]; |
4991999e | 2747 | struct type *arg_type = check_typedef (value_type (arg)); |
cb3d25d1 MS |
2748 | int len = TYPE_LENGTH (arg_type); |
2749 | enum type_code typecode = TYPE_CODE (arg_type); | |
2750 | ||
2751 | if (mips_debug) | |
2752 | fprintf_unfiltered (gdb_stdlog, | |
25ab4790 | 2753 | "mips_n32n64_push_dummy_call: %d len=%d type=%d", |
cb3d25d1 MS |
2754 | argnum + 1, len, (int) typecode); |
2755 | ||
47a35522 | 2756 | val = value_contents (arg); |
cb3d25d1 MS |
2757 | |
2758 | if (fp_register_arg_p (typecode, arg_type) | |
2759 | && float_argreg <= MIPS_LAST_FP_ARG_REGNUM) | |
2760 | { | |
2761 | /* This is a floating point value that fits entirely | |
2762 | in a single register. */ | |
2763 | /* On 32 bit ABI's the float_argreg is further adjusted | |
2764 | above to ensure that it is even register aligned. */ | |
2765 | LONGEST regval = extract_unsigned_integer (val, len); | |
2766 | if (mips_debug) | |
2767 | fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s", | |
2768 | float_argreg, phex (regval, len)); | |
2769 | write_register (float_argreg++, regval); | |
2770 | ||
2771 | if (mips_debug) | |
2772 | fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s", | |
2773 | argreg, phex (regval, len)); | |
2774 | write_register (argreg, regval); | |
2775 | argreg += 1; | |
2776 | } | |
2777 | else | |
2778 | { | |
2779 | /* Copy the argument to general registers or the stack in | |
2780 | register-sized pieces. Large arguments are split between | |
2781 | registers and stack. */ | |
4246e332 | 2782 | /* Note: structs whose size is not a multiple of |
d5ac5a39 AC |
2783 | mips_abi_regsize() are treated specially: Irix cc passes |
2784 | them in registers where gcc sometimes puts them on the | |
2785 | stack. For maximum compatibility, we will put them in | |
2786 | both places. */ | |
13326b4e AC |
2787 | int odd_sized_struct = ((len > mips_abi_regsize (gdbarch)) |
2788 | && (len % mips_abi_regsize (gdbarch) != 0)); | |
cb3d25d1 | 2789 | /* Note: Floating-point values that didn't fit into an FP |
6d82d43b | 2790 | register are only written to memory. */ |
cb3d25d1 MS |
2791 | while (len > 0) |
2792 | { | |
2793 | /* Rememer if the argument was written to the stack. */ | |
2794 | int stack_used_p = 0; | |
13326b4e AC |
2795 | int partial_len = (len < mips_abi_regsize (gdbarch) |
2796 | ? len : mips_abi_regsize (gdbarch)); | |
cb3d25d1 MS |
2797 | |
2798 | if (mips_debug) | |
2799 | fprintf_unfiltered (gdb_stdlog, " -- partial=%d", | |
2800 | partial_len); | |
2801 | ||
2802 | /* Write this portion of the argument to the stack. */ | |
2803 | if (argreg > MIPS_LAST_ARG_REGNUM | |
2804 | || odd_sized_struct | |
2805 | || fp_register_arg_p (typecode, arg_type)) | |
2806 | { | |
2807 | /* Should shorter than int integer values be | |
2808 | promoted to int before being stored? */ | |
2809 | int longword_offset = 0; | |
2810 | CORE_ADDR addr; | |
2811 | stack_used_p = 1; | |
2812 | if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) | |
2813 | { | |
13326b4e | 2814 | if (mips_stack_argsize (gdbarch) == 8 |
480d3dd2 AC |
2815 | && (typecode == TYPE_CODE_INT |
2816 | || typecode == TYPE_CODE_PTR | |
6d82d43b | 2817 | || typecode == TYPE_CODE_FLT) && len <= 4) |
13326b4e | 2818 | longword_offset = mips_stack_argsize (gdbarch) - len; |
cb3d25d1 MS |
2819 | } |
2820 | ||
2821 | if (mips_debug) | |
2822 | { | |
2823 | fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s", | |
2824 | paddr_nz (stack_offset)); | |
2825 | fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s", | |
2826 | paddr_nz (longword_offset)); | |
2827 | } | |
2828 | ||
2829 | addr = sp + stack_offset + longword_offset; | |
2830 | ||
2831 | if (mips_debug) | |
2832 | { | |
2833 | int i; | |
6d82d43b | 2834 | fprintf_unfiltered (gdb_stdlog, " @0x%s ", |
cb3d25d1 MS |
2835 | paddr_nz (addr)); |
2836 | for (i = 0; i < partial_len; i++) | |
2837 | { | |
6d82d43b | 2838 | fprintf_unfiltered (gdb_stdlog, "%02x", |
cb3d25d1 MS |
2839 | val[i] & 0xff); |
2840 | } | |
2841 | } | |
2842 | write_memory (addr, val, partial_len); | |
2843 | } | |
2844 | ||
2845 | /* Note!!! This is NOT an else clause. Odd sized | |
2846 | structs may go thru BOTH paths. Floating point | |
2847 | arguments will not. */ | |
2848 | /* Write this portion of the argument to a general | |
6d82d43b | 2849 | purpose register. */ |
cb3d25d1 MS |
2850 | if (argreg <= MIPS_LAST_ARG_REGNUM |
2851 | && !fp_register_arg_p (typecode, arg_type)) | |
2852 | { | |
6d82d43b AC |
2853 | LONGEST regval = |
2854 | extract_unsigned_integer (val, partial_len); | |
cb3d25d1 MS |
2855 | |
2856 | /* A non-floating-point argument being passed in a | |
2857 | general register. If a struct or union, and if | |
2858 | the remaining length is smaller than the register | |
2859 | size, we have to adjust the register value on | |
2860 | big endian targets. | |
2861 | ||
2862 | It does not seem to be necessary to do the | |
2863 | same for integral types. | |
2864 | ||
2865 | cagney/2001-07-23: gdb/179: Also, GCC, when | |
2866 | outputting LE O32 with sizeof (struct) < | |
1b13c4f6 | 2867 | mips_abi_regsize(), generates a left shift as |
cb3d25d1 MS |
2868 | part of storing the argument in a register a |
2869 | register (the left shift isn't generated when | |
1b13c4f6 | 2870 | sizeof (struct) >= mips_abi_regsize()). Since |
480d3dd2 AC |
2871 | it is quite possible that this is GCC |
2872 | contradicting the LE/O32 ABI, GDB has not been | |
2873 | adjusted to accommodate this. Either someone | |
2874 | needs to demonstrate that the LE/O32 ABI | |
2875 | specifies such a left shift OR this new ABI gets | |
2876 | identified as such and GDB gets tweaked | |
2877 | accordingly. */ | |
cb3d25d1 MS |
2878 | |
2879 | if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG | |
13326b4e | 2880 | && partial_len < mips_abi_regsize (gdbarch) |
cb3d25d1 MS |
2881 | && (typecode == TYPE_CODE_STRUCT || |
2882 | typecode == TYPE_CODE_UNION)) | |
13326b4e | 2883 | regval <<= ((mips_abi_regsize (gdbarch) - partial_len) * |
cb3d25d1 MS |
2884 | TARGET_CHAR_BIT); |
2885 | ||
2886 | if (mips_debug) | |
2887 | fprintf_filtered (gdb_stdlog, " - reg=%d val=%s", | |
2888 | argreg, | |
6d82d43b | 2889 | phex (regval, |
13326b4e | 2890 | mips_abi_regsize (gdbarch))); |
cb3d25d1 MS |
2891 | write_register (argreg, regval); |
2892 | argreg++; | |
2893 | } | |
2894 | ||
2895 | len -= partial_len; | |
2896 | val += partial_len; | |
2897 | ||
2898 | /* Compute the the offset into the stack at which we | |
6d82d43b | 2899 | will copy the next parameter. |
cb3d25d1 MS |
2900 | |
2901 | In N32 (N64?), the stack_offset only needs to be | |
2902 | adjusted when it has been used. */ | |
2903 | ||
2904 | if (stack_used_p) | |
480d3dd2 | 2905 | stack_offset += align_up (partial_len, |
13326b4e | 2906 | mips_stack_argsize (gdbarch)); |
cb3d25d1 MS |
2907 | } |
2908 | } | |
2909 | if (mips_debug) | |
2910 | fprintf_unfiltered (gdb_stdlog, "\n"); | |
2911 | } | |
2912 | ||
f10683bb | 2913 | regcache_cooked_write_signed (regcache, MIPS_SP_REGNUM, sp); |
310e9b6a | 2914 | |
cb3d25d1 MS |
2915 | /* Return adjusted stack pointer. */ |
2916 | return sp; | |
2917 | } | |
2918 | ||
6d82d43b AC |
2919 | static enum return_value_convention |
2920 | mips_n32n64_return_value (struct gdbarch *gdbarch, | |
2921 | struct type *type, struct regcache *regcache, | |
47a35522 | 2922 | gdb_byte *readbuf, const gdb_byte *writebuf) |
ebafbe83 | 2923 | { |
6d82d43b AC |
2924 | struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); |
2925 | if (TYPE_CODE (type) == TYPE_CODE_STRUCT | |
2926 | || TYPE_CODE (type) == TYPE_CODE_UNION | |
2927 | || TYPE_CODE (type) == TYPE_CODE_ARRAY | |
13326b4e | 2928 | || TYPE_LENGTH (type) > 2 * mips_abi_regsize (gdbarch)) |
6d82d43b | 2929 | return RETURN_VALUE_STRUCT_CONVENTION; |
d05f6826 DJ |
2930 | else if (TYPE_CODE (type) == TYPE_CODE_FLT |
2931 | && TYPE_LENGTH (type) == 16 | |
2932 | && tdep->mips_fpu_type != MIPS_FPU_NONE) | |
2933 | { | |
2934 | /* A 128-bit floating-point value fills both $f0 and $f2. The | |
2935 | two registers are used in the same as memory order, so the | |
2936 | eight bytes with the lower memory address are in $f0. */ | |
2937 | if (mips_debug) | |
2938 | fprintf_unfiltered (gdb_stderr, "Return float in $f0 and $f2\n"); | |
2939 | mips_xfer_register (regcache, | |
2940 | NUM_REGS + mips_regnum (current_gdbarch)->fp0, | |
2941 | 8, TARGET_BYTE_ORDER, readbuf, writebuf, 0); | |
2942 | mips_xfer_register (regcache, | |
2943 | NUM_REGS + mips_regnum (current_gdbarch)->fp0 + 2, | |
2944 | 8, TARGET_BYTE_ORDER, readbuf ? readbuf + 8 : readbuf, | |
2945 | writebuf ? writebuf + 8 : writebuf, 0); | |
2946 | return RETURN_VALUE_REGISTER_CONVENTION; | |
2947 | } | |
6d82d43b AC |
2948 | else if (TYPE_CODE (type) == TYPE_CODE_FLT |
2949 | && tdep->mips_fpu_type != MIPS_FPU_NONE) | |
2950 | { | |
2951 | /* A floating-point value belongs in the least significant part | |
2952 | of FP0. */ | |
2953 | if (mips_debug) | |
2954 | fprintf_unfiltered (gdb_stderr, "Return float in $fp0\n"); | |
2955 | mips_xfer_register (regcache, | |
2956 | NUM_REGS + mips_regnum (current_gdbarch)->fp0, | |
2957 | TYPE_LENGTH (type), | |
2958 | TARGET_BYTE_ORDER, readbuf, writebuf, 0); | |
2959 | return RETURN_VALUE_REGISTER_CONVENTION; | |
2960 | } | |
2961 | else if (TYPE_CODE (type) == TYPE_CODE_STRUCT | |
2962 | && TYPE_NFIELDS (type) <= 2 | |
2963 | && TYPE_NFIELDS (type) >= 1 | |
2964 | && ((TYPE_NFIELDS (type) == 1 | |
2965 | && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) | |
2966 | == TYPE_CODE_FLT)) | |
2967 | || (TYPE_NFIELDS (type) == 2 | |
2968 | && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) | |
2969 | == TYPE_CODE_FLT) | |
2970 | && (TYPE_CODE (TYPE_FIELD_TYPE (type, 1)) | |
2971 | == TYPE_CODE_FLT))) | |
2972 | && tdep->mips_fpu_type != MIPS_FPU_NONE) | |
2973 | { | |
2974 | /* A struct that contains one or two floats. Each value is part | |
2975 | in the least significant part of their floating point | |
2976 | register.. */ | |
6d82d43b AC |
2977 | int regnum; |
2978 | int field; | |
2979 | for (field = 0, regnum = mips_regnum (current_gdbarch)->fp0; | |
2980 | field < TYPE_NFIELDS (type); field++, regnum += 2) | |
2981 | { | |
2982 | int offset = (FIELD_BITPOS (TYPE_FIELDS (type)[field]) | |
2983 | / TARGET_CHAR_BIT); | |
2984 | if (mips_debug) | |
2985 | fprintf_unfiltered (gdb_stderr, "Return float struct+%d\n", | |
2986 | offset); | |
2987 | mips_xfer_register (regcache, NUM_REGS + regnum, | |
2988 | TYPE_LENGTH (TYPE_FIELD_TYPE (type, field)), | |
2989 | TARGET_BYTE_ORDER, readbuf, writebuf, offset); | |
2990 | } | |
2991 | return RETURN_VALUE_REGISTER_CONVENTION; | |
2992 | } | |
2993 | else if (TYPE_CODE (type) == TYPE_CODE_STRUCT | |
2994 | || TYPE_CODE (type) == TYPE_CODE_UNION) | |
2995 | { | |
2996 | /* A structure or union. Extract the left justified value, | |
2997 | regardless of the byte order. I.e. DO NOT USE | |
2998 | mips_xfer_lower. */ | |
2999 | int offset; | |
3000 | int regnum; | |
4c7d22cb | 3001 | for (offset = 0, regnum = MIPS_V0_REGNUM; |
6d82d43b AC |
3002 | offset < TYPE_LENGTH (type); |
3003 | offset += register_size (current_gdbarch, regnum), regnum++) | |
3004 | { | |
3005 | int xfer = register_size (current_gdbarch, regnum); | |
3006 | if (offset + xfer > TYPE_LENGTH (type)) | |
3007 | xfer = TYPE_LENGTH (type) - offset; | |
3008 | if (mips_debug) | |
3009 | fprintf_unfiltered (gdb_stderr, "Return struct+%d:%d in $%d\n", | |
3010 | offset, xfer, regnum); | |
3011 | mips_xfer_register (regcache, NUM_REGS + regnum, xfer, | |
3012 | BFD_ENDIAN_UNKNOWN, readbuf, writebuf, offset); | |
3013 | } | |
3014 | return RETURN_VALUE_REGISTER_CONVENTION; | |
3015 | } | |
3016 | else | |
3017 | { | |
3018 | /* A scalar extract each part but least-significant-byte | |
3019 | justified. */ | |
3020 | int offset; | |
3021 | int regnum; | |
4c7d22cb | 3022 | for (offset = 0, regnum = MIPS_V0_REGNUM; |
6d82d43b AC |
3023 | offset < TYPE_LENGTH (type); |
3024 | offset += register_size (current_gdbarch, regnum), regnum++) | |
3025 | { | |
3026 | int xfer = register_size (current_gdbarch, regnum); | |
6d82d43b AC |
3027 | if (offset + xfer > TYPE_LENGTH (type)) |
3028 | xfer = TYPE_LENGTH (type) - offset; | |
3029 | if (mips_debug) | |
3030 | fprintf_unfiltered (gdb_stderr, "Return scalar+%d:%d in $%d\n", | |
3031 | offset, xfer, regnum); | |
3032 | mips_xfer_register (regcache, NUM_REGS + regnum, xfer, | |
3033 | TARGET_BYTE_ORDER, readbuf, writebuf, offset); | |
3034 | } | |
3035 | return RETURN_VALUE_REGISTER_CONVENTION; | |
3036 | } | |
3037 | } | |
3038 | ||
3039 | /* O32 ABI stuff. */ | |
3040 | ||
3041 | static CORE_ADDR | |
7d9b040b | 3042 | mips_o32_push_dummy_call (struct gdbarch *gdbarch, struct value *function, |
6d82d43b AC |
3043 | struct regcache *regcache, CORE_ADDR bp_addr, |
3044 | int nargs, struct value **args, CORE_ADDR sp, | |
3045 | int struct_return, CORE_ADDR struct_addr) | |
3046 | { | |
3047 | int argreg; | |
3048 | int float_argreg; | |
3049 | int argnum; | |
3050 | int len = 0; | |
3051 | int stack_offset = 0; | |
3052 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
7d9b040b | 3053 | CORE_ADDR func_addr = find_function_addr (function, NULL); |
6d82d43b AC |
3054 | |
3055 | /* For shared libraries, "t9" needs to point at the function | |
3056 | address. */ | |
4c7d22cb | 3057 | regcache_cooked_write_signed (regcache, MIPS_T9_REGNUM, func_addr); |
6d82d43b AC |
3058 | |
3059 | /* Set the return address register to point to the entry point of | |
3060 | the program, where a breakpoint lies in wait. */ | |
4c7d22cb | 3061 | regcache_cooked_write_signed (regcache, MIPS_RA_REGNUM, bp_addr); |
6d82d43b AC |
3062 | |
3063 | /* First ensure that the stack and structure return address (if any) | |
3064 | are properly aligned. The stack has to be at least 64-bit | |
3065 | aligned even on 32-bit machines, because doubles must be 64-bit | |
ebafbe83 MS |
3066 | aligned. For n32 and n64, stack frames need to be 128-bit |
3067 | aligned, so we round to this widest known alignment. */ | |
3068 | ||
5b03f266 AC |
3069 | sp = align_down (sp, 16); |
3070 | struct_addr = align_down (struct_addr, 16); | |
ebafbe83 MS |
3071 | |
3072 | /* Now make space on the stack for the args. */ | |
3073 | for (argnum = 0; argnum < nargs; argnum++) | |
4991999e | 3074 | len += align_up (TYPE_LENGTH (value_type (args[argnum])), |
13326b4e | 3075 | mips_stack_argsize (gdbarch)); |
5b03f266 | 3076 | sp -= align_up (len, 16); |
ebafbe83 MS |
3077 | |
3078 | if (mips_debug) | |
6d82d43b | 3079 | fprintf_unfiltered (gdb_stdlog, |
5b03f266 AC |
3080 | "mips_o32_push_dummy_call: sp=0x%s allocated %ld\n", |
3081 | paddr_nz (sp), (long) align_up (len, 16)); | |
ebafbe83 MS |
3082 | |
3083 | /* Initialize the integer and float register pointers. */ | |
4c7d22cb | 3084 | argreg = MIPS_A0_REGNUM; |
56cea623 | 3085 | float_argreg = mips_fpa0_regnum (current_gdbarch); |
ebafbe83 | 3086 | |
bcb0cc15 | 3087 | /* The struct_return pointer occupies the first parameter-passing reg. */ |
ebafbe83 MS |
3088 | if (struct_return) |
3089 | { | |
3090 | if (mips_debug) | |
3091 | fprintf_unfiltered (gdb_stdlog, | |
25ab4790 | 3092 | "mips_o32_push_dummy_call: struct_return reg=%d 0x%s\n", |
ebafbe83 MS |
3093 | argreg, paddr_nz (struct_addr)); |
3094 | write_register (argreg++, struct_addr); | |
13326b4e | 3095 | stack_offset += mips_stack_argsize (gdbarch); |
ebafbe83 MS |
3096 | } |
3097 | ||
3098 | /* Now load as many as possible of the first arguments into | |
3099 | registers, and push the rest onto the stack. Loop thru args | |
3100 | from first to last. */ | |
3101 | for (argnum = 0; argnum < nargs; argnum++) | |
3102 | { | |
47a35522 | 3103 | const gdb_byte *val; |
ebafbe83 | 3104 | struct value *arg = args[argnum]; |
4991999e | 3105 | struct type *arg_type = check_typedef (value_type (arg)); |
ebafbe83 MS |
3106 | int len = TYPE_LENGTH (arg_type); |
3107 | enum type_code typecode = TYPE_CODE (arg_type); | |
3108 | ||
3109 | if (mips_debug) | |
3110 | fprintf_unfiltered (gdb_stdlog, | |
25ab4790 | 3111 | "mips_o32_push_dummy_call: %d len=%d type=%d", |
46cac009 AC |
3112 | argnum + 1, len, (int) typecode); |
3113 | ||
47a35522 | 3114 | val = value_contents (arg); |
46cac009 AC |
3115 | |
3116 | /* 32-bit ABIs always start floating point arguments in an | |
3117 | even-numbered floating point register. Round the FP register | |
3118 | up before the check to see if there are any FP registers | |
3119 | left. O32/O64 targets also pass the FP in the integer | |
3120 | registers so also round up normal registers. */ | |
ceae6e75 AC |
3121 | if (mips_abi_regsize (gdbarch) < 8 |
3122 | && fp_register_arg_p (typecode, arg_type)) | |
46cac009 AC |
3123 | { |
3124 | if ((float_argreg & 1)) | |
3125 | float_argreg++; | |
3126 | } | |
3127 | ||
3128 | /* Floating point arguments passed in registers have to be | |
3129 | treated specially. On 32-bit architectures, doubles | |
3130 | are passed in register pairs; the even register gets | |
3131 | the low word, and the odd register gets the high word. | |
3132 | On O32/O64, the first two floating point arguments are | |
3133 | also copied to general registers, because MIPS16 functions | |
3134 | don't use float registers for arguments. This duplication of | |
3135 | arguments in general registers can't hurt non-MIPS16 functions | |
3136 | because those registers are normally skipped. */ | |
3137 | ||
3138 | if (fp_register_arg_p (typecode, arg_type) | |
3139 | && float_argreg <= MIPS_LAST_FP_ARG_REGNUM) | |
3140 | { | |
8b07f6d8 | 3141 | if (register_size (gdbarch, float_argreg) < 8 && len == 8) |
46cac009 AC |
3142 | { |
3143 | int low_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 4 : 0; | |
3144 | unsigned long regval; | |
3145 | ||
3146 | /* Write the low word of the double to the even register(s). */ | |
3147 | regval = extract_unsigned_integer (val + low_offset, 4); | |
3148 | if (mips_debug) | |
3149 | fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s", | |
3150 | float_argreg, phex (regval, 4)); | |
3151 | write_register (float_argreg++, regval); | |
3152 | if (mips_debug) | |
3153 | fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s", | |
3154 | argreg, phex (regval, 4)); | |
3155 | write_register (argreg++, regval); | |
3156 | ||
3157 | /* Write the high word of the double to the odd register(s). */ | |
3158 | regval = extract_unsigned_integer (val + 4 - low_offset, 4); | |
3159 | if (mips_debug) | |
3160 | fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s", | |
3161 | float_argreg, phex (regval, 4)); | |
3162 | write_register (float_argreg++, regval); | |
3163 | ||
3164 | if (mips_debug) | |
3165 | fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s", | |
3166 | argreg, phex (regval, 4)); | |
3167 | write_register (argreg++, regval); | |
3168 | } | |
3169 | else | |
3170 | { | |
3171 | /* This is a floating point value that fits entirely | |
3172 | in a single register. */ | |
3173 | /* On 32 bit ABI's the float_argreg is further adjusted | |
6d82d43b | 3174 | above to ensure that it is even register aligned. */ |
46cac009 AC |
3175 | LONGEST regval = extract_unsigned_integer (val, len); |
3176 | if (mips_debug) | |
3177 | fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s", | |
3178 | float_argreg, phex (regval, len)); | |
3179 | write_register (float_argreg++, regval); | |
3180 | /* CAGNEY: 32 bit MIPS ABI's always reserve two FP | |
6d82d43b AC |
3181 | registers for each argument. The below is (my |
3182 | guess) to ensure that the corresponding integer | |
3183 | register has reserved the same space. */ | |
46cac009 AC |
3184 | if (mips_debug) |
3185 | fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s", | |
3186 | argreg, phex (regval, len)); | |
3187 | write_register (argreg, regval); | |
ceae6e75 | 3188 | argreg += (mips_abi_regsize (gdbarch) == 8) ? 1 : 2; |
46cac009 AC |
3189 | } |
3190 | /* Reserve space for the FP register. */ | |
13326b4e | 3191 | stack_offset += align_up (len, mips_stack_argsize (gdbarch)); |
46cac009 AC |
3192 | } |
3193 | else | |
3194 | { | |
3195 | /* Copy the argument to general registers or the stack in | |
3196 | register-sized pieces. Large arguments are split between | |
3197 | registers and stack. */ | |
4246e332 | 3198 | /* Note: structs whose size is not a multiple of |
d5ac5a39 AC |
3199 | mips_abi_regsize() are treated specially: Irix cc passes |
3200 | them in registers where gcc sometimes puts them on the | |
3201 | stack. For maximum compatibility, we will put them in | |
3202 | both places. */ | |
13326b4e AC |
3203 | int odd_sized_struct = ((len > mips_abi_regsize (gdbarch)) |
3204 | && (len % mips_abi_regsize (gdbarch) != 0)); | |
46cac009 AC |
3205 | /* Structures should be aligned to eight bytes (even arg registers) |
3206 | on MIPS_ABI_O32, if their first member has double precision. */ | |
13326b4e | 3207 | if (mips_abi_regsize (gdbarch) < 8 |
46cac009 AC |
3208 | && mips_type_needs_double_align (arg_type)) |
3209 | { | |
3210 | if ((argreg & 1)) | |
6d82d43b | 3211 | argreg++; |
46cac009 AC |
3212 | } |
3213 | /* Note: Floating-point values that didn't fit into an FP | |
6d82d43b | 3214 | register are only written to memory. */ |
46cac009 AC |
3215 | while (len > 0) |
3216 | { | |
3217 | /* Remember if the argument was written to the stack. */ | |
3218 | int stack_used_p = 0; | |
13326b4e AC |
3219 | int partial_len = (len < mips_abi_regsize (gdbarch) |
3220 | ? len : mips_abi_regsize (gdbarch)); | |
46cac009 AC |
3221 | |
3222 | if (mips_debug) | |
3223 | fprintf_unfiltered (gdb_stdlog, " -- partial=%d", | |
3224 | partial_len); | |
3225 | ||
3226 | /* Write this portion of the argument to the stack. */ | |
3227 | if (argreg > MIPS_LAST_ARG_REGNUM | |
3228 | || odd_sized_struct | |
3229 | || fp_register_arg_p (typecode, arg_type)) | |
3230 | { | |
3231 | /* Should shorter than int integer values be | |
3232 | promoted to int before being stored? */ | |
3233 | int longword_offset = 0; | |
3234 | CORE_ADDR addr; | |
3235 | stack_used_p = 1; | |
3236 | if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) | |
3237 | { | |
13326b4e | 3238 | if (mips_stack_argsize (gdbarch) == 8 |
480d3dd2 AC |
3239 | && (typecode == TYPE_CODE_INT |
3240 | || typecode == TYPE_CODE_PTR | |
6d82d43b | 3241 | || typecode == TYPE_CODE_FLT) && len <= 4) |
13326b4e | 3242 | longword_offset = mips_stack_argsize (gdbarch) - len; |
46cac009 AC |
3243 | } |
3244 | ||
3245 | if (mips_debug) | |
3246 | { | |
3247 | fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s", | |
3248 | paddr_nz (stack_offset)); | |
3249 | fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s", | |
3250 | paddr_nz (longword_offset)); | |
3251 | } | |
3252 | ||
3253 | addr = sp + stack_offset + longword_offset; | |
3254 | ||
3255 | if (mips_debug) | |
3256 | { | |
3257 | int i; | |
6d82d43b | 3258 | fprintf_unfiltered (gdb_stdlog, " @0x%s ", |
46cac009 AC |
3259 | paddr_nz (addr)); |
3260 | for (i = 0; i < partial_len; i++) | |
3261 | { | |
6d82d43b | 3262 | fprintf_unfiltered (gdb_stdlog, "%02x", |
46cac009 AC |
3263 | val[i] & 0xff); |
3264 | } | |
3265 | } | |
3266 | write_memory (addr, val, partial_len); | |
3267 | } | |
3268 | ||
3269 | /* Note!!! This is NOT an else clause. Odd sized | |
3270 | structs may go thru BOTH paths. Floating point | |
3271 | arguments will not. */ | |
3272 | /* Write this portion of the argument to a general | |
6d82d43b | 3273 | purpose register. */ |
46cac009 AC |
3274 | if (argreg <= MIPS_LAST_ARG_REGNUM |
3275 | && !fp_register_arg_p (typecode, arg_type)) | |
3276 | { | |
3277 | LONGEST regval = extract_signed_integer (val, partial_len); | |
4246e332 | 3278 | /* Value may need to be sign extended, because |
1b13c4f6 | 3279 | mips_isa_regsize() != mips_abi_regsize(). */ |
46cac009 AC |
3280 | |
3281 | /* A non-floating-point argument being passed in a | |
3282 | general register. If a struct or union, and if | |
3283 | the remaining length is smaller than the register | |
3284 | size, we have to adjust the register value on | |
3285 | big endian targets. | |
3286 | ||
3287 | It does not seem to be necessary to do the | |
3288 | same for integral types. | |
3289 | ||
3290 | Also don't do this adjustment on O64 binaries. | |
3291 | ||
3292 | cagney/2001-07-23: gdb/179: Also, GCC, when | |
3293 | outputting LE O32 with sizeof (struct) < | |
1b13c4f6 | 3294 | mips_abi_regsize(), generates a left shift as |
46cac009 AC |
3295 | part of storing the argument in a register a |
3296 | register (the left shift isn't generated when | |
1b13c4f6 | 3297 | sizeof (struct) >= mips_abi_regsize()). Since |
480d3dd2 AC |
3298 | it is quite possible that this is GCC |
3299 | contradicting the LE/O32 ABI, GDB has not been | |
3300 | adjusted to accommodate this. Either someone | |
3301 | needs to demonstrate that the LE/O32 ABI | |
3302 | specifies such a left shift OR this new ABI gets | |
3303 | identified as such and GDB gets tweaked | |
3304 | accordingly. */ | |
3305 | ||
13326b4e | 3306 | if (mips_abi_regsize (gdbarch) < 8 |
46cac009 | 3307 | && TARGET_BYTE_ORDER == BFD_ENDIAN_BIG |
13326b4e | 3308 | && partial_len < mips_abi_regsize (gdbarch) |
46cac009 AC |
3309 | && (typecode == TYPE_CODE_STRUCT || |
3310 | typecode == TYPE_CODE_UNION)) | |
13326b4e | 3311 | regval <<= ((mips_abi_regsize (gdbarch) - partial_len) * |
46cac009 AC |
3312 | TARGET_CHAR_BIT); |
3313 | ||
3314 | if (mips_debug) | |
3315 | fprintf_filtered (gdb_stdlog, " - reg=%d val=%s", | |
3316 | argreg, | |
6d82d43b | 3317 | phex (regval, |
13326b4e | 3318 | mips_abi_regsize (gdbarch))); |
46cac009 AC |
3319 | write_register (argreg, regval); |
3320 | argreg++; | |
3321 | ||
3322 | /* Prevent subsequent floating point arguments from | |
3323 | being passed in floating point registers. */ | |
3324 | float_argreg = MIPS_LAST_FP_ARG_REGNUM + 1; | |
3325 | } | |
3326 | ||
3327 | len -= partial_len; | |
3328 | val += partial_len; | |
3329 | ||
3330 | /* Compute the the offset into the stack at which we | |
6d82d43b | 3331 | will copy the next parameter. |
46cac009 | 3332 | |
6d82d43b AC |
3333 | In older ABIs, the caller reserved space for |
3334 | registers that contained arguments. This was loosely | |
3335 | refered to as their "home". Consequently, space is | |
3336 | always allocated. */ | |
46cac009 | 3337 | |
480d3dd2 | 3338 | stack_offset += align_up (partial_len, |
13326b4e | 3339 | mips_stack_argsize (gdbarch)); |
46cac009 AC |
3340 | } |
3341 | } | |
3342 | if (mips_debug) | |
3343 | fprintf_unfiltered (gdb_stdlog, "\n"); | |
3344 | } | |
3345 | ||
f10683bb | 3346 | regcache_cooked_write_signed (regcache, MIPS_SP_REGNUM, sp); |
310e9b6a | 3347 | |
46cac009 AC |
3348 | /* Return adjusted stack pointer. */ |
3349 | return sp; | |
3350 | } | |
3351 | ||
6d82d43b AC |
3352 | static enum return_value_convention |
3353 | mips_o32_return_value (struct gdbarch *gdbarch, struct type *type, | |
3354 | struct regcache *regcache, | |
47a35522 | 3355 | gdb_byte *readbuf, const gdb_byte *writebuf) |
6d82d43b AC |
3356 | { |
3357 | struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); | |
3358 | ||
3359 | if (TYPE_CODE (type) == TYPE_CODE_STRUCT | |
3360 | || TYPE_CODE (type) == TYPE_CODE_UNION | |
3361 | || TYPE_CODE (type) == TYPE_CODE_ARRAY) | |
3362 | return RETURN_VALUE_STRUCT_CONVENTION; | |
3363 | else if (TYPE_CODE (type) == TYPE_CODE_FLT | |
3364 | && TYPE_LENGTH (type) == 4 && tdep->mips_fpu_type != MIPS_FPU_NONE) | |
3365 | { | |
3366 | /* A single-precision floating-point value. It fits in the | |
3367 | least significant part of FP0. */ | |
3368 | if (mips_debug) | |
3369 | fprintf_unfiltered (gdb_stderr, "Return float in $fp0\n"); | |
3370 | mips_xfer_register (regcache, | |
3371 | NUM_REGS + mips_regnum (current_gdbarch)->fp0, | |
3372 | TYPE_LENGTH (type), | |
3373 | TARGET_BYTE_ORDER, readbuf, writebuf, 0); | |
3374 | return RETURN_VALUE_REGISTER_CONVENTION; | |
3375 | } | |
3376 | else if (TYPE_CODE (type) == TYPE_CODE_FLT | |
3377 | && TYPE_LENGTH (type) == 8 && tdep->mips_fpu_type != MIPS_FPU_NONE) | |
3378 | { | |
3379 | /* A double-precision floating-point value. The most | |
3380 | significant part goes in FP1, and the least significant in | |
3381 | FP0. */ | |
3382 | if (mips_debug) | |
3383 | fprintf_unfiltered (gdb_stderr, "Return float in $fp1/$fp0\n"); | |
3384 | switch (TARGET_BYTE_ORDER) | |
3385 | { | |
3386 | case BFD_ENDIAN_LITTLE: | |
3387 | mips_xfer_register (regcache, | |
3388 | NUM_REGS + mips_regnum (current_gdbarch)->fp0 + | |
3389 | 0, 4, TARGET_BYTE_ORDER, readbuf, writebuf, 0); | |
3390 | mips_xfer_register (regcache, | |
3391 | NUM_REGS + mips_regnum (current_gdbarch)->fp0 + | |
3392 | 1, 4, TARGET_BYTE_ORDER, readbuf, writebuf, 4); | |
3393 | break; | |
3394 | case BFD_ENDIAN_BIG: | |
3395 | mips_xfer_register (regcache, | |
3396 | NUM_REGS + mips_regnum (current_gdbarch)->fp0 + | |
3397 | 1, 4, TARGET_BYTE_ORDER, readbuf, writebuf, 0); | |
3398 | mips_xfer_register (regcache, | |
3399 | NUM_REGS + mips_regnum (current_gdbarch)->fp0 + | |
3400 | 0, 4, TARGET_BYTE_ORDER, readbuf, writebuf, 4); | |
3401 | break; | |
3402 | default: | |
e2e0b3e5 | 3403 | internal_error (__FILE__, __LINE__, _("bad switch")); |
6d82d43b AC |
3404 | } |
3405 | return RETURN_VALUE_REGISTER_CONVENTION; | |
3406 | } | |
3407 | #if 0 | |
3408 | else if (TYPE_CODE (type) == TYPE_CODE_STRUCT | |
3409 | && TYPE_NFIELDS (type) <= 2 | |
3410 | && TYPE_NFIELDS (type) >= 1 | |
3411 | && ((TYPE_NFIELDS (type) == 1 | |
3412 | && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) | |
3413 | == TYPE_CODE_FLT)) | |
3414 | || (TYPE_NFIELDS (type) == 2 | |
3415 | && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) | |
3416 | == TYPE_CODE_FLT) | |
3417 | && (TYPE_CODE (TYPE_FIELD_TYPE (type, 1)) | |
3418 | == TYPE_CODE_FLT))) | |
3419 | && tdep->mips_fpu_type != MIPS_FPU_NONE) | |
3420 | { | |
3421 | /* A struct that contains one or two floats. Each value is part | |
3422 | in the least significant part of their floating point | |
3423 | register.. */ | |
870cd05e | 3424 | gdb_byte reg[MAX_REGISTER_SIZE]; |
6d82d43b AC |
3425 | int regnum; |
3426 | int field; | |
3427 | for (field = 0, regnum = mips_regnum (current_gdbarch)->fp0; | |
3428 | field < TYPE_NFIELDS (type); field++, regnum += 2) | |
3429 | { | |
3430 | int offset = (FIELD_BITPOS (TYPE_FIELDS (type)[field]) | |
3431 | / TARGET_CHAR_BIT); | |
3432 | if (mips_debug) | |
3433 | fprintf_unfiltered (gdb_stderr, "Return float struct+%d\n", | |
3434 | offset); | |
3435 | mips_xfer_register (regcache, NUM_REGS + regnum, | |
3436 | TYPE_LENGTH (TYPE_FIELD_TYPE (type, field)), | |
3437 | TARGET_BYTE_ORDER, readbuf, writebuf, offset); | |
3438 | } | |
3439 | return RETURN_VALUE_REGISTER_CONVENTION; | |
3440 | } | |
3441 | #endif | |
3442 | #if 0 | |
3443 | else if (TYPE_CODE (type) == TYPE_CODE_STRUCT | |
3444 | || TYPE_CODE (type) == TYPE_CODE_UNION) | |
3445 | { | |
3446 | /* A structure or union. Extract the left justified value, | |
3447 | regardless of the byte order. I.e. DO NOT USE | |
3448 | mips_xfer_lower. */ | |
3449 | int offset; | |
3450 | int regnum; | |
4c7d22cb | 3451 | for (offset = 0, regnum = MIPS_V0_REGNUM; |
6d82d43b AC |
3452 | offset < TYPE_LENGTH (type); |
3453 | offset += register_size (current_gdbarch, regnum), regnum++) | |
3454 | { | |
3455 | int xfer = register_size (current_gdbarch, regnum); | |
3456 | if (offset + xfer > TYPE_LENGTH (type)) | |
3457 | xfer = TYPE_LENGTH (type) - offset; | |
3458 | if (mips_debug) | |
3459 | fprintf_unfiltered (gdb_stderr, "Return struct+%d:%d in $%d\n", | |
3460 | offset, xfer, regnum); | |
3461 | mips_xfer_register (regcache, NUM_REGS + regnum, xfer, | |
3462 | BFD_ENDIAN_UNKNOWN, readbuf, writebuf, offset); | |
3463 | } | |
3464 | return RETURN_VALUE_REGISTER_CONVENTION; | |
3465 | } | |
3466 | #endif | |
3467 | else | |
3468 | { | |
3469 | /* A scalar extract each part but least-significant-byte | |
3470 | justified. o32 thinks registers are 4 byte, regardless of | |
3471 | the ISA. mips_stack_argsize controls this. */ | |
3472 | int offset; | |
3473 | int regnum; | |
4c7d22cb | 3474 | for (offset = 0, regnum = MIPS_V0_REGNUM; |
6d82d43b | 3475 | offset < TYPE_LENGTH (type); |
13326b4e | 3476 | offset += mips_stack_argsize (gdbarch), regnum++) |
6d82d43b | 3477 | { |
13326b4e | 3478 | int xfer = mips_stack_argsize (gdbarch); |
6d82d43b AC |
3479 | if (offset + xfer > TYPE_LENGTH (type)) |
3480 | xfer = TYPE_LENGTH (type) - offset; | |
3481 | if (mips_debug) | |
3482 | fprintf_unfiltered (gdb_stderr, "Return scalar+%d:%d in $%d\n", | |
3483 | offset, xfer, regnum); | |
3484 | mips_xfer_register (regcache, NUM_REGS + regnum, xfer, | |
3485 | TARGET_BYTE_ORDER, readbuf, writebuf, offset); | |
3486 | } | |
3487 | return RETURN_VALUE_REGISTER_CONVENTION; | |
3488 | } | |
3489 | } | |
3490 | ||
3491 | /* O64 ABI. This is a hacked up kind of 64-bit version of the o32 | |
3492 | ABI. */ | |
46cac009 AC |
3493 | |
3494 | static CORE_ADDR | |
7d9b040b | 3495 | mips_o64_push_dummy_call (struct gdbarch *gdbarch, struct value *function, |
6d82d43b AC |
3496 | struct regcache *regcache, CORE_ADDR bp_addr, |
3497 | int nargs, | |
3498 | struct value **args, CORE_ADDR sp, | |
3499 | int struct_return, CORE_ADDR struct_addr) | |
46cac009 AC |
3500 | { |
3501 | int argreg; | |
3502 | int float_argreg; | |
3503 | int argnum; | |
3504 | int len = 0; | |
3505 | int stack_offset = 0; | |
480d3dd2 | 3506 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
7d9b040b | 3507 | CORE_ADDR func_addr = find_function_addr (function, NULL); |
46cac009 | 3508 | |
25ab4790 AC |
3509 | /* For shared libraries, "t9" needs to point at the function |
3510 | address. */ | |
4c7d22cb | 3511 | regcache_cooked_write_signed (regcache, MIPS_T9_REGNUM, func_addr); |
25ab4790 AC |
3512 | |
3513 | /* Set the return address register to point to the entry point of | |
3514 | the program, where a breakpoint lies in wait. */ | |
4c7d22cb | 3515 | regcache_cooked_write_signed (regcache, MIPS_RA_REGNUM, bp_addr); |
25ab4790 | 3516 | |
46cac009 AC |
3517 | /* First ensure that the stack and structure return address (if any) |
3518 | are properly aligned. The stack has to be at least 64-bit | |
3519 | aligned even on 32-bit machines, because doubles must be 64-bit | |
3520 | aligned. For n32 and n64, stack frames need to be 128-bit | |
3521 | aligned, so we round to this widest known alignment. */ | |
3522 | ||
5b03f266 AC |
3523 | sp = align_down (sp, 16); |
3524 | struct_addr = align_down (struct_addr, 16); | |
46cac009 AC |
3525 | |
3526 | /* Now make space on the stack for the args. */ | |
3527 | for (argnum = 0; argnum < nargs; argnum++) | |
4991999e | 3528 | len += align_up (TYPE_LENGTH (value_type (args[argnum])), |
13326b4e | 3529 | mips_stack_argsize (gdbarch)); |
5b03f266 | 3530 | sp -= align_up (len, 16); |
46cac009 AC |
3531 | |
3532 | if (mips_debug) | |
6d82d43b | 3533 | fprintf_unfiltered (gdb_stdlog, |
5b03f266 AC |
3534 | "mips_o64_push_dummy_call: sp=0x%s allocated %ld\n", |
3535 | paddr_nz (sp), (long) align_up (len, 16)); | |
46cac009 AC |
3536 | |
3537 | /* Initialize the integer and float register pointers. */ | |
4c7d22cb | 3538 | argreg = MIPS_A0_REGNUM; |
56cea623 | 3539 | float_argreg = mips_fpa0_regnum (current_gdbarch); |
46cac009 AC |
3540 | |
3541 | /* The struct_return pointer occupies the first parameter-passing reg. */ | |
3542 | if (struct_return) | |
3543 | { | |
3544 | if (mips_debug) | |
3545 | fprintf_unfiltered (gdb_stdlog, | |
25ab4790 | 3546 | "mips_o64_push_dummy_call: struct_return reg=%d 0x%s\n", |
46cac009 AC |
3547 | argreg, paddr_nz (struct_addr)); |
3548 | write_register (argreg++, struct_addr); | |
13326b4e | 3549 | stack_offset += mips_stack_argsize (gdbarch); |
46cac009 AC |
3550 | } |
3551 | ||
3552 | /* Now load as many as possible of the first arguments into | |
3553 | registers, and push the rest onto the stack. Loop thru args | |
3554 | from first to last. */ | |
3555 | for (argnum = 0; argnum < nargs; argnum++) | |
3556 | { | |
47a35522 | 3557 | const gdb_byte *val; |
46cac009 | 3558 | struct value *arg = args[argnum]; |
4991999e | 3559 | struct type *arg_type = check_typedef (value_type (arg)); |
46cac009 AC |
3560 | int len = TYPE_LENGTH (arg_type); |
3561 | enum type_code typecode = TYPE_CODE (arg_type); | |
3562 | ||
3563 | if (mips_debug) | |
3564 | fprintf_unfiltered (gdb_stdlog, | |
25ab4790 | 3565 | "mips_o64_push_dummy_call: %d len=%d type=%d", |
ebafbe83 MS |
3566 | argnum + 1, len, (int) typecode); |
3567 | ||
47a35522 | 3568 | val = value_contents (arg); |
ebafbe83 MS |
3569 | |
3570 | /* 32-bit ABIs always start floating point arguments in an | |
3571 | even-numbered floating point register. Round the FP register | |
3572 | up before the check to see if there are any FP registers | |
3573 | left. O32/O64 targets also pass the FP in the integer | |
3574 | registers so also round up normal registers. */ | |
ceae6e75 AC |
3575 | if (mips_abi_regsize (gdbarch) < 8 |
3576 | && fp_register_arg_p (typecode, arg_type)) | |
ebafbe83 MS |
3577 | { |
3578 | if ((float_argreg & 1)) | |
3579 | float_argreg++; | |
3580 | } | |
3581 | ||
3582 | /* Floating point arguments passed in registers have to be | |
3583 | treated specially. On 32-bit architectures, doubles | |
3584 | are passed in register pairs; the even register gets | |
3585 | the low word, and the odd register gets the high word. | |
3586 | On O32/O64, the first two floating point arguments are | |
3587 | also copied to general registers, because MIPS16 functions | |
3588 | don't use float registers for arguments. This duplication of | |
3589 | arguments in general registers can't hurt non-MIPS16 functions | |
3590 | because those registers are normally skipped. */ | |
3591 | ||
3592 | if (fp_register_arg_p (typecode, arg_type) | |
3593 | && float_argreg <= MIPS_LAST_FP_ARG_REGNUM) | |
3594 | { | |
ceae6e75 | 3595 | if (mips_abi_regsize (gdbarch) < 8 && len == 8) |
ebafbe83 MS |
3596 | { |
3597 | int low_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 4 : 0; | |
3598 | unsigned long regval; | |
3599 | ||
3600 | /* Write the low word of the double to the even register(s). */ | |
3601 | regval = extract_unsigned_integer (val + low_offset, 4); | |
3602 | if (mips_debug) | |
3603 | fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s", | |
3604 | float_argreg, phex (regval, 4)); | |
3605 | write_register (float_argreg++, regval); | |
3606 | if (mips_debug) | |
3607 | fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s", | |
3608 | argreg, phex (regval, 4)); | |
3609 | write_register (argreg++, regval); | |
3610 | ||
3611 | /* Write the high word of the double to the odd register(s). */ | |
3612 | regval = extract_unsigned_integer (val + 4 - low_offset, 4); | |
3613 | if (mips_debug) | |
3614 | fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s", | |
3615 | float_argreg, phex (regval, 4)); | |
3616 | write_register (float_argreg++, regval); | |
3617 | ||
3618 | if (mips_debug) | |
3619 | fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s", | |
3620 | argreg, phex (regval, 4)); | |
3621 | write_register (argreg++, regval); | |
3622 | } | |
3623 | else | |
3624 | { | |
3625 | /* This is a floating point value that fits entirely | |
3626 | in a single register. */ | |
3627 | /* On 32 bit ABI's the float_argreg is further adjusted | |
6d82d43b | 3628 | above to ensure that it is even register aligned. */ |
ebafbe83 MS |
3629 | LONGEST regval = extract_unsigned_integer (val, len); |
3630 | if (mips_debug) | |
3631 | fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s", | |
3632 | float_argreg, phex (regval, len)); | |
3633 | write_register (float_argreg++, regval); | |
3634 | /* CAGNEY: 32 bit MIPS ABI's always reserve two FP | |
6d82d43b AC |
3635 | registers for each argument. The below is (my |
3636 | guess) to ensure that the corresponding integer | |
3637 | register has reserved the same space. */ | |
ebafbe83 MS |
3638 | if (mips_debug) |
3639 | fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s", | |
3640 | argreg, phex (regval, len)); | |
3641 | write_register (argreg, regval); | |
ceae6e75 | 3642 | argreg += (mips_abi_regsize (gdbarch) == 8) ? 1 : 2; |
ebafbe83 MS |
3643 | } |
3644 | /* Reserve space for the FP register. */ | |
13326b4e | 3645 | stack_offset += align_up (len, mips_stack_argsize (gdbarch)); |
ebafbe83 MS |
3646 | } |
3647 | else | |
3648 | { | |
3649 | /* Copy the argument to general registers or the stack in | |
3650 | register-sized pieces. Large arguments are split between | |
3651 | registers and stack. */ | |
4246e332 | 3652 | /* Note: structs whose size is not a multiple of |
d5ac5a39 AC |
3653 | mips_abi_regsize() are treated specially: Irix cc passes |
3654 | them in registers where gcc sometimes puts them on the | |
3655 | stack. For maximum compatibility, we will put them in | |
3656 | both places. */ | |
13326b4e AC |
3657 | int odd_sized_struct = ((len > mips_abi_regsize (gdbarch)) |
3658 | && (len % mips_abi_regsize (gdbarch) != 0)); | |
ebafbe83 MS |
3659 | /* Structures should be aligned to eight bytes (even arg registers) |
3660 | on MIPS_ABI_O32, if their first member has double precision. */ | |
13326b4e | 3661 | if (mips_abi_regsize (gdbarch) < 8 |
ebafbe83 MS |
3662 | && mips_type_needs_double_align (arg_type)) |
3663 | { | |
3664 | if ((argreg & 1)) | |
6d82d43b | 3665 | argreg++; |
ebafbe83 MS |
3666 | } |
3667 | /* Note: Floating-point values that didn't fit into an FP | |
6d82d43b | 3668 | register are only written to memory. */ |
ebafbe83 MS |
3669 | while (len > 0) |
3670 | { | |
3671 | /* Remember if the argument was written to the stack. */ | |
3672 | int stack_used_p = 0; | |
13326b4e AC |
3673 | int partial_len = (len < mips_abi_regsize (gdbarch) |
3674 | ? len : mips_abi_regsize (gdbarch)); | |
ebafbe83 MS |
3675 | |
3676 | if (mips_debug) | |
3677 | fprintf_unfiltered (gdb_stdlog, " -- partial=%d", | |
3678 | partial_len); | |
3679 | ||
3680 | /* Write this portion of the argument to the stack. */ | |
3681 | if (argreg > MIPS_LAST_ARG_REGNUM | |
3682 | || odd_sized_struct | |
3683 | || fp_register_arg_p (typecode, arg_type)) | |
3684 | { | |
3685 | /* Should shorter than int integer values be | |
3686 | promoted to int before being stored? */ | |
3687 | int longword_offset = 0; | |
3688 | CORE_ADDR addr; | |
3689 | stack_used_p = 1; | |
3690 | if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) | |
3691 | { | |
13326b4e | 3692 | if (mips_stack_argsize (gdbarch) == 8 |
480d3dd2 AC |
3693 | && (typecode == TYPE_CODE_INT |
3694 | || typecode == TYPE_CODE_PTR | |
6d82d43b | 3695 | || typecode == TYPE_CODE_FLT) && len <= 4) |
13326b4e | 3696 | longword_offset = mips_stack_argsize (gdbarch) - len; |
ebafbe83 MS |
3697 | } |
3698 | ||
3699 | if (mips_debug) | |
3700 | { | |
3701 | fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s", | |
3702 | paddr_nz (stack_offset)); | |
3703 | fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s", | |
3704 | paddr_nz (longword_offset)); | |
3705 | } | |
3706 | ||
3707 | addr = sp + stack_offset + longword_offset; | |
3708 | ||
3709 | if (mips_debug) | |
3710 | { | |
3711 | int i; | |
6d82d43b | 3712 | fprintf_unfiltered (gdb_stdlog, " @0x%s ", |
ebafbe83 MS |
3713 | paddr_nz (addr)); |
3714 | for (i = 0; i < partial_len; i++) | |
3715 | { | |
6d82d43b | 3716 | fprintf_unfiltered (gdb_stdlog, "%02x", |
ebafbe83 MS |
3717 | val[i] & 0xff); |
3718 | } | |
3719 | } | |
3720 | write_memory (addr, val, partial_len); | |
3721 | } | |
3722 | ||
3723 | /* Note!!! This is NOT an else clause. Odd sized | |
3724 | structs may go thru BOTH paths. Floating point | |
3725 | arguments will not. */ | |
3726 | /* Write this portion of the argument to a general | |
6d82d43b | 3727 | purpose register. */ |
ebafbe83 MS |
3728 | if (argreg <= MIPS_LAST_ARG_REGNUM |
3729 | && !fp_register_arg_p (typecode, arg_type)) | |
3730 | { | |
3731 | LONGEST regval = extract_signed_integer (val, partial_len); | |
4246e332 | 3732 | /* Value may need to be sign extended, because |
1b13c4f6 | 3733 | mips_isa_regsize() != mips_abi_regsize(). */ |
ebafbe83 MS |
3734 | |
3735 | /* A non-floating-point argument being passed in a | |
3736 | general register. If a struct or union, and if | |
3737 | the remaining length is smaller than the register | |
3738 | size, we have to adjust the register value on | |
3739 | big endian targets. | |
3740 | ||
3741 | It does not seem to be necessary to do the | |
401835eb | 3742 | same for integral types. */ |
480d3dd2 | 3743 | |
401835eb | 3744 | if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG |
13326b4e | 3745 | && partial_len < mips_abi_regsize (gdbarch) |
ebafbe83 MS |
3746 | && (typecode == TYPE_CODE_STRUCT || |
3747 | typecode == TYPE_CODE_UNION)) | |
13326b4e | 3748 | regval <<= ((mips_abi_regsize (gdbarch) - partial_len) * |
ebafbe83 MS |
3749 | TARGET_CHAR_BIT); |
3750 | ||
3751 | if (mips_debug) | |
3752 | fprintf_filtered (gdb_stdlog, " - reg=%d val=%s", | |
3753 | argreg, | |
6d82d43b | 3754 | phex (regval, |
13326b4e | 3755 | mips_abi_regsize (gdbarch))); |
ebafbe83 MS |
3756 | write_register (argreg, regval); |
3757 | argreg++; | |
3758 | ||
3759 | /* Prevent subsequent floating point arguments from | |
3760 | being passed in floating point registers. */ | |
3761 | float_argreg = MIPS_LAST_FP_ARG_REGNUM + 1; | |
3762 | } | |
3763 | ||
3764 | len -= partial_len; | |
3765 | val += partial_len; | |
3766 | ||
3767 | /* Compute the the offset into the stack at which we | |
6d82d43b | 3768 | will copy the next parameter. |
ebafbe83 | 3769 | |
6d82d43b AC |
3770 | In older ABIs, the caller reserved space for |
3771 | registers that contained arguments. This was loosely | |
3772 | refered to as their "home". Consequently, space is | |
3773 | always allocated. */ | |
ebafbe83 | 3774 | |
480d3dd2 | 3775 | stack_offset += align_up (partial_len, |
13326b4e | 3776 | mips_stack_argsize (gdbarch)); |
ebafbe83 MS |
3777 | } |
3778 | } | |
3779 | if (mips_debug) | |
3780 | fprintf_unfiltered (gdb_stdlog, "\n"); | |
3781 | } | |
3782 | ||
f10683bb | 3783 | regcache_cooked_write_signed (regcache, MIPS_SP_REGNUM, sp); |
310e9b6a | 3784 | |
ebafbe83 MS |
3785 | /* Return adjusted stack pointer. */ |
3786 | return sp; | |
3787 | } | |
3788 | ||
9c8fdbfa AC |
3789 | static enum return_value_convention |
3790 | mips_o64_return_value (struct gdbarch *gdbarch, | |
3791 | struct type *type, struct regcache *regcache, | |
47a35522 | 3792 | gdb_byte *readbuf, const gdb_byte *writebuf) |
6d82d43b | 3793 | { |
7a076fd2 FF |
3794 | struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); |
3795 | ||
3796 | if (TYPE_CODE (type) == TYPE_CODE_STRUCT | |
3797 | || TYPE_CODE (type) == TYPE_CODE_UNION | |
3798 | || TYPE_CODE (type) == TYPE_CODE_ARRAY) | |
3799 | return RETURN_VALUE_STRUCT_CONVENTION; | |
3800 | else if (fp_register_arg_p (TYPE_CODE (type), type)) | |
3801 | { | |
3802 | /* A floating-point value. It fits in the least significant | |
3803 | part of FP0. */ | |
3804 | if (mips_debug) | |
3805 | fprintf_unfiltered (gdb_stderr, "Return float in $fp0\n"); | |
3806 | mips_xfer_register (regcache, | |
3807 | NUM_REGS + mips_regnum (current_gdbarch)->fp0, | |
3808 | TYPE_LENGTH (type), | |
3809 | TARGET_BYTE_ORDER, readbuf, writebuf, 0); | |
3810 | return RETURN_VALUE_REGISTER_CONVENTION; | |
3811 | } | |
3812 | else | |
3813 | { | |
3814 | /* A scalar extract each part but least-significant-byte | |
3815 | justified. */ | |
3816 | int offset; | |
3817 | int regnum; | |
3818 | for (offset = 0, regnum = MIPS_V0_REGNUM; | |
3819 | offset < TYPE_LENGTH (type); | |
3820 | offset += mips_stack_argsize (gdbarch), regnum++) | |
3821 | { | |
3822 | int xfer = mips_stack_argsize (gdbarch); | |
3823 | if (offset + xfer > TYPE_LENGTH (type)) | |
3824 | xfer = TYPE_LENGTH (type) - offset; | |
3825 | if (mips_debug) | |
3826 | fprintf_unfiltered (gdb_stderr, "Return scalar+%d:%d in $%d\n", | |
3827 | offset, xfer, regnum); | |
3828 | mips_xfer_register (regcache, NUM_REGS + regnum, xfer, | |
3829 | TARGET_BYTE_ORDER, readbuf, writebuf, offset); | |
3830 | } | |
3831 | return RETURN_VALUE_REGISTER_CONVENTION; | |
3832 | } | |
6d82d43b AC |
3833 | } |
3834 | ||
dd824b04 DJ |
3835 | /* Floating point register management. |
3836 | ||
3837 | Background: MIPS1 & 2 fp registers are 32 bits wide. To support | |
3838 | 64bit operations, these early MIPS cpus treat fp register pairs | |
3839 | (f0,f1) as a single register (d0). Later MIPS cpu's have 64 bit fp | |
3840 | registers and offer a compatibility mode that emulates the MIPS2 fp | |
3841 | model. When operating in MIPS2 fp compat mode, later cpu's split | |
3842 | double precision floats into two 32-bit chunks and store them in | |
3843 | consecutive fp regs. To display 64-bit floats stored in this | |
3844 | fashion, we have to combine 32 bits from f0 and 32 bits from f1. | |
3845 | Throw in user-configurable endianness and you have a real mess. | |
3846 | ||
3847 | The way this works is: | |
3848 | - If we are in 32-bit mode or on a 32-bit processor, then a 64-bit | |
3849 | double-precision value will be split across two logical registers. | |
3850 | The lower-numbered logical register will hold the low-order bits, | |
3851 | regardless of the processor's endianness. | |
3852 | - If we are on a 64-bit processor, and we are looking for a | |
3853 | single-precision value, it will be in the low ordered bits | |
3854 | of a 64-bit GPR (after mfc1, for example) or a 64-bit register | |
3855 | save slot in memory. | |
3856 | - If we are in 64-bit mode, everything is straightforward. | |
3857 | ||
3858 | Note that this code only deals with "live" registers at the top of the | |
3859 | stack. We will attempt to deal with saved registers later, when | |
3860 | the raw/cooked register interface is in place. (We need a general | |
3861 | interface that can deal with dynamic saved register sizes -- fp | |
3862 | regs could be 32 bits wide in one frame and 64 on the frame above | |
3863 | and below). */ | |
3864 | ||
67b2c998 DJ |
3865 | static struct type * |
3866 | mips_float_register_type (void) | |
3867 | { | |
8da61cc4 | 3868 | return builtin_type_ieee_single; |
67b2c998 DJ |
3869 | } |
3870 | ||
3871 | static struct type * | |
3872 | mips_double_register_type (void) | |
3873 | { | |
8da61cc4 | 3874 | return builtin_type_ieee_double; |
67b2c998 DJ |
3875 | } |
3876 | ||
dd824b04 DJ |
3877 | /* Copy a 32-bit single-precision value from the current frame |
3878 | into rare_buffer. */ | |
3879 | ||
3880 | static void | |
e11c53d2 | 3881 | mips_read_fp_register_single (struct frame_info *frame, int regno, |
47a35522 | 3882 | gdb_byte *rare_buffer) |
dd824b04 | 3883 | { |
719ec221 | 3884 | int raw_size = register_size (current_gdbarch, regno); |
47a35522 | 3885 | gdb_byte *raw_buffer = alloca (raw_size); |
dd824b04 | 3886 | |
e11c53d2 | 3887 | if (!frame_register_read (frame, regno, raw_buffer)) |
8a3fe4f8 | 3888 | error (_("can't read register %d (%s)"), regno, REGISTER_NAME (regno)); |
dd824b04 DJ |
3889 | if (raw_size == 8) |
3890 | { | |
3891 | /* We have a 64-bit value for this register. Find the low-order | |
6d82d43b | 3892 | 32 bits. */ |
dd824b04 DJ |
3893 | int offset; |
3894 | ||
3895 | if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) | |
3896 | offset = 4; | |
3897 | else | |
3898 | offset = 0; | |
3899 | ||
3900 | memcpy (rare_buffer, raw_buffer + offset, 4); | |
3901 | } | |
3902 | else | |
3903 | { | |
3904 | memcpy (rare_buffer, raw_buffer, 4); | |
3905 | } | |
3906 | } | |
3907 | ||
3908 | /* Copy a 64-bit double-precision value from the current frame into | |
3909 | rare_buffer. This may include getting half of it from the next | |
3910 | register. */ | |
3911 | ||
3912 | static void | |
e11c53d2 | 3913 | mips_read_fp_register_double (struct frame_info *frame, int regno, |
47a35522 | 3914 | gdb_byte *rare_buffer) |
dd824b04 | 3915 | { |
719ec221 | 3916 | int raw_size = register_size (current_gdbarch, regno); |
dd824b04 DJ |
3917 | |
3918 | if (raw_size == 8 && !mips2_fp_compat ()) | |
3919 | { | |
3920 | /* We have a 64-bit value for this register, and we should use | |
6d82d43b | 3921 | all 64 bits. */ |
e11c53d2 | 3922 | if (!frame_register_read (frame, regno, rare_buffer)) |
8a3fe4f8 | 3923 | error (_("can't read register %d (%s)"), regno, REGISTER_NAME (regno)); |
dd824b04 DJ |
3924 | } |
3925 | else | |
3926 | { | |
56cea623 | 3927 | if ((regno - mips_regnum (current_gdbarch)->fp0) & 1) |
dd824b04 | 3928 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 AC |
3929 | _("mips_read_fp_register_double: bad access to " |
3930 | "odd-numbered FP register")); | |
dd824b04 DJ |
3931 | |
3932 | /* mips_read_fp_register_single will find the correct 32 bits from | |
6d82d43b | 3933 | each register. */ |
dd824b04 DJ |
3934 | if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) |
3935 | { | |
e11c53d2 AC |
3936 | mips_read_fp_register_single (frame, regno, rare_buffer + 4); |
3937 | mips_read_fp_register_single (frame, regno + 1, rare_buffer); | |
dd824b04 | 3938 | } |
361d1df0 | 3939 | else |
dd824b04 | 3940 | { |
e11c53d2 AC |
3941 | mips_read_fp_register_single (frame, regno, rare_buffer); |
3942 | mips_read_fp_register_single (frame, regno + 1, rare_buffer + 4); | |
dd824b04 DJ |
3943 | } |
3944 | } | |
3945 | } | |
3946 | ||
c906108c | 3947 | static void |
e11c53d2 AC |
3948 | mips_print_fp_register (struct ui_file *file, struct frame_info *frame, |
3949 | int regnum) | |
c5aa993b | 3950 | { /* do values for FP (float) regs */ |
47a35522 | 3951 | gdb_byte *raw_buffer; |
3903d437 AC |
3952 | double doub, flt1; /* doubles extracted from raw hex data */ |
3953 | int inv1, inv2; | |
c5aa993b | 3954 | |
47a35522 MK |
3955 | raw_buffer = alloca (2 * register_size (current_gdbarch, |
3956 | mips_regnum (current_gdbarch)->fp0)); | |
c906108c | 3957 | |
e11c53d2 AC |
3958 | fprintf_filtered (file, "%s:", REGISTER_NAME (regnum)); |
3959 | fprintf_filtered (file, "%*s", 4 - (int) strlen (REGISTER_NAME (regnum)), | |
3960 | ""); | |
f0ef6b29 | 3961 | |
719ec221 | 3962 | if (register_size (current_gdbarch, regnum) == 4 || mips2_fp_compat ()) |
c906108c | 3963 | { |
f0ef6b29 KB |
3964 | /* 4-byte registers: Print hex and floating. Also print even |
3965 | numbered registers as doubles. */ | |
e11c53d2 | 3966 | mips_read_fp_register_single (frame, regnum, raw_buffer); |
67b2c998 | 3967 | flt1 = unpack_double (mips_float_register_type (), raw_buffer, &inv1); |
c5aa993b | 3968 | |
6d82d43b AC |
3969 | print_scalar_formatted (raw_buffer, builtin_type_uint32, 'x', 'w', |
3970 | file); | |
dd824b04 | 3971 | |
e11c53d2 | 3972 | fprintf_filtered (file, " flt: "); |
1adad886 | 3973 | if (inv1) |
e11c53d2 | 3974 | fprintf_filtered (file, " <invalid float> "); |
1adad886 | 3975 | else |
e11c53d2 | 3976 | fprintf_filtered (file, "%-17.9g", flt1); |
1adad886 | 3977 | |
f0ef6b29 KB |
3978 | if (regnum % 2 == 0) |
3979 | { | |
e11c53d2 | 3980 | mips_read_fp_register_double (frame, regnum, raw_buffer); |
f0ef6b29 | 3981 | doub = unpack_double (mips_double_register_type (), raw_buffer, |
6d82d43b | 3982 | &inv2); |
1adad886 | 3983 | |
e11c53d2 | 3984 | fprintf_filtered (file, " dbl: "); |
f0ef6b29 | 3985 | if (inv2) |
e11c53d2 | 3986 | fprintf_filtered (file, "<invalid double>"); |
f0ef6b29 | 3987 | else |
e11c53d2 | 3988 | fprintf_filtered (file, "%-24.17g", doub); |
f0ef6b29 | 3989 | } |
c906108c SS |
3990 | } |
3991 | else | |
dd824b04 | 3992 | { |
f0ef6b29 | 3993 | /* Eight byte registers: print each one as hex, float and double. */ |
e11c53d2 | 3994 | mips_read_fp_register_single (frame, regnum, raw_buffer); |
2f38ef89 | 3995 | flt1 = unpack_double (mips_float_register_type (), raw_buffer, &inv1); |
c906108c | 3996 | |
e11c53d2 | 3997 | mips_read_fp_register_double (frame, regnum, raw_buffer); |
f0ef6b29 KB |
3998 | doub = unpack_double (mips_double_register_type (), raw_buffer, &inv2); |
3999 | ||
361d1df0 | 4000 | |
6d82d43b AC |
4001 | print_scalar_formatted (raw_buffer, builtin_type_uint64, 'x', 'g', |
4002 | file); | |
f0ef6b29 | 4003 | |
e11c53d2 | 4004 | fprintf_filtered (file, " flt: "); |
1adad886 | 4005 | if (inv1) |
e11c53d2 | 4006 | fprintf_filtered (file, "<invalid float>"); |
1adad886 | 4007 | else |
e11c53d2 | 4008 | fprintf_filtered (file, "%-17.9g", flt1); |
1adad886 | 4009 | |
e11c53d2 | 4010 | fprintf_filtered (file, " dbl: "); |
f0ef6b29 | 4011 | if (inv2) |
e11c53d2 | 4012 | fprintf_filtered (file, "<invalid double>"); |
1adad886 | 4013 | else |
e11c53d2 | 4014 | fprintf_filtered (file, "%-24.17g", doub); |
f0ef6b29 KB |
4015 | } |
4016 | } | |
4017 | ||
4018 | static void | |
e11c53d2 AC |
4019 | mips_print_register (struct ui_file *file, struct frame_info *frame, |
4020 | int regnum, int all) | |
f0ef6b29 | 4021 | { |
a4b8ebc8 | 4022 | struct gdbarch *gdbarch = get_frame_arch (frame); |
47a35522 | 4023 | gdb_byte raw_buffer[MAX_REGISTER_SIZE]; |
f0ef6b29 | 4024 | int offset; |
1adad886 | 4025 | |
7b9ee6a8 | 4026 | if (TYPE_CODE (register_type (gdbarch, regnum)) == TYPE_CODE_FLT) |
f0ef6b29 | 4027 | { |
e11c53d2 | 4028 | mips_print_fp_register (file, frame, regnum); |
f0ef6b29 KB |
4029 | return; |
4030 | } | |
4031 | ||
4032 | /* Get the data in raw format. */ | |
e11c53d2 | 4033 | if (!frame_register_read (frame, regnum, raw_buffer)) |
f0ef6b29 | 4034 | { |
e11c53d2 | 4035 | fprintf_filtered (file, "%s: [Invalid]", REGISTER_NAME (regnum)); |
f0ef6b29 | 4036 | return; |
c906108c | 4037 | } |
f0ef6b29 | 4038 | |
e11c53d2 | 4039 | fputs_filtered (REGISTER_NAME (regnum), file); |
f0ef6b29 KB |
4040 | |
4041 | /* The problem with printing numeric register names (r26, etc.) is that | |
4042 | the user can't use them on input. Probably the best solution is to | |
4043 | fix it so that either the numeric or the funky (a2, etc.) names | |
4044 | are accepted on input. */ | |
4045 | if (regnum < MIPS_NUMREGS) | |
e11c53d2 | 4046 | fprintf_filtered (file, "(r%d): ", regnum); |
f0ef6b29 | 4047 | else |
e11c53d2 | 4048 | fprintf_filtered (file, ": "); |
f0ef6b29 KB |
4049 | |
4050 | if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) | |
6d82d43b AC |
4051 | offset = |
4052 | register_size (current_gdbarch, | |
4053 | regnum) - register_size (current_gdbarch, regnum); | |
f0ef6b29 KB |
4054 | else |
4055 | offset = 0; | |
4056 | ||
6d82d43b | 4057 | print_scalar_formatted (raw_buffer + offset, |
7b9ee6a8 | 4058 | register_type (gdbarch, regnum), 'x', 0, |
6d82d43b | 4059 | file); |
c906108c SS |
4060 | } |
4061 | ||
f0ef6b29 KB |
4062 | /* Replacement for generic do_registers_info. |
4063 | Print regs in pretty columns. */ | |
4064 | ||
4065 | static int | |
e11c53d2 AC |
4066 | print_fp_register_row (struct ui_file *file, struct frame_info *frame, |
4067 | int regnum) | |
f0ef6b29 | 4068 | { |
e11c53d2 AC |
4069 | fprintf_filtered (file, " "); |
4070 | mips_print_fp_register (file, frame, regnum); | |
4071 | fprintf_filtered (file, "\n"); | |
f0ef6b29 KB |
4072 | return regnum + 1; |
4073 | } | |
4074 | ||
4075 | ||
c906108c SS |
4076 | /* Print a row's worth of GP (int) registers, with name labels above */ |
4077 | ||
4078 | static int | |
e11c53d2 | 4079 | print_gp_register_row (struct ui_file *file, struct frame_info *frame, |
a4b8ebc8 | 4080 | int start_regnum) |
c906108c | 4081 | { |
a4b8ebc8 | 4082 | struct gdbarch *gdbarch = get_frame_arch (frame); |
c906108c | 4083 | /* do values for GP (int) regs */ |
47a35522 | 4084 | gdb_byte raw_buffer[MAX_REGISTER_SIZE]; |
d5ac5a39 | 4085 | int ncols = (mips_abi_regsize (gdbarch) == 8 ? 4 : 8); /* display cols per row */ |
c906108c | 4086 | int col, byte; |
a4b8ebc8 | 4087 | int regnum; |
c906108c SS |
4088 | |
4089 | /* For GP registers, we print a separate row of names above the vals */ | |
a4b8ebc8 | 4090 | for (col = 0, regnum = start_regnum; |
6d82d43b | 4091 | col < ncols && regnum < NUM_REGS + NUM_PSEUDO_REGS; regnum++) |
c906108c SS |
4092 | { |
4093 | if (*REGISTER_NAME (regnum) == '\0') | |
c5aa993b | 4094 | continue; /* unused register */ |
7b9ee6a8 | 4095 | if (TYPE_CODE (register_type (gdbarch, regnum)) == |
6d82d43b | 4096 | TYPE_CODE_FLT) |
c5aa993b | 4097 | break; /* end the row: reached FP register */ |
d05f6826 DJ |
4098 | if (col == 0) |
4099 | fprintf_filtered (file, " "); | |
6d82d43b | 4100 | fprintf_filtered (file, |
d5ac5a39 | 4101 | mips_abi_regsize (current_gdbarch) == 8 ? "%17s" : "%9s", |
e11c53d2 | 4102 | REGISTER_NAME (regnum)); |
c906108c SS |
4103 | col++; |
4104 | } | |
d05f6826 DJ |
4105 | |
4106 | if (col == 0) | |
4107 | return regnum; | |
4108 | ||
a4b8ebc8 | 4109 | /* print the R0 to R31 names */ |
20e6603c AC |
4110 | if ((start_regnum % NUM_REGS) < MIPS_NUMREGS) |
4111 | fprintf_filtered (file, "\n R%-4d", start_regnum % NUM_REGS); | |
4112 | else | |
4113 | fprintf_filtered (file, "\n "); | |
c906108c | 4114 | |
c906108c | 4115 | /* now print the values in hex, 4 or 8 to the row */ |
a4b8ebc8 | 4116 | for (col = 0, regnum = start_regnum; |
6d82d43b | 4117 | col < ncols && regnum < NUM_REGS + NUM_PSEUDO_REGS; regnum++) |
c906108c SS |
4118 | { |
4119 | if (*REGISTER_NAME (regnum) == '\0') | |
c5aa993b | 4120 | continue; /* unused register */ |
7b9ee6a8 | 4121 | if (TYPE_CODE (register_type (gdbarch, regnum)) == |
6d82d43b | 4122 | TYPE_CODE_FLT) |
c5aa993b | 4123 | break; /* end row: reached FP register */ |
c906108c | 4124 | /* OK: get the data in raw format. */ |
e11c53d2 | 4125 | if (!frame_register_read (frame, regnum, raw_buffer)) |
8a3fe4f8 | 4126 | error (_("can't read register %d (%s)"), regnum, REGISTER_NAME (regnum)); |
c906108c | 4127 | /* pad small registers */ |
4246e332 | 4128 | for (byte = 0; |
d5ac5a39 | 4129 | byte < (mips_abi_regsize (current_gdbarch) |
6d82d43b | 4130 | - register_size (current_gdbarch, regnum)); byte++) |
c906108c SS |
4131 | printf_filtered (" "); |
4132 | /* Now print the register value in hex, endian order. */ | |
d7449b42 | 4133 | if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) |
6d82d43b AC |
4134 | for (byte = |
4135 | register_size (current_gdbarch, | |
4136 | regnum) - register_size (current_gdbarch, regnum); | |
4137 | byte < register_size (current_gdbarch, regnum); byte++) | |
47a35522 | 4138 | fprintf_filtered (file, "%02x", raw_buffer[byte]); |
c906108c | 4139 | else |
c73e8f27 | 4140 | for (byte = register_size (current_gdbarch, regnum) - 1; |
6d82d43b | 4141 | byte >= 0; byte--) |
47a35522 | 4142 | fprintf_filtered (file, "%02x", raw_buffer[byte]); |
e11c53d2 | 4143 | fprintf_filtered (file, " "); |
c906108c SS |
4144 | col++; |
4145 | } | |
c5aa993b | 4146 | if (col > 0) /* ie. if we actually printed anything... */ |
e11c53d2 | 4147 | fprintf_filtered (file, "\n"); |
c906108c SS |
4148 | |
4149 | return regnum; | |
4150 | } | |
4151 | ||
4152 | /* MIPS_DO_REGISTERS_INFO(): called by "info register" command */ | |
4153 | ||
bf1f5b4c | 4154 | static void |
e11c53d2 AC |
4155 | mips_print_registers_info (struct gdbarch *gdbarch, struct ui_file *file, |
4156 | struct frame_info *frame, int regnum, int all) | |
c906108c | 4157 | { |
c5aa993b | 4158 | if (regnum != -1) /* do one specified register */ |
c906108c | 4159 | { |
a4b8ebc8 | 4160 | gdb_assert (regnum >= NUM_REGS); |
c906108c | 4161 | if (*(REGISTER_NAME (regnum)) == '\0') |
8a3fe4f8 | 4162 | error (_("Not a valid register for the current processor type")); |
c906108c | 4163 | |
e11c53d2 AC |
4164 | mips_print_register (file, frame, regnum, 0); |
4165 | fprintf_filtered (file, "\n"); | |
c906108c | 4166 | } |
c5aa993b JM |
4167 | else |
4168 | /* do all (or most) registers */ | |
c906108c | 4169 | { |
a4b8ebc8 AC |
4170 | regnum = NUM_REGS; |
4171 | while (regnum < NUM_REGS + NUM_PSEUDO_REGS) | |
c906108c | 4172 | { |
7b9ee6a8 | 4173 | if (TYPE_CODE (register_type (gdbarch, regnum)) == |
6d82d43b | 4174 | TYPE_CODE_FLT) |
e11c53d2 AC |
4175 | { |
4176 | if (all) /* true for "INFO ALL-REGISTERS" command */ | |
4177 | regnum = print_fp_register_row (file, frame, regnum); | |
4178 | else | |
4179 | regnum += MIPS_NUMREGS; /* skip floating point regs */ | |
4180 | } | |
c906108c | 4181 | else |
e11c53d2 | 4182 | regnum = print_gp_register_row (file, frame, regnum); |
c906108c SS |
4183 | } |
4184 | } | |
4185 | } | |
4186 | ||
c906108c SS |
4187 | /* Is this a branch with a delay slot? */ |
4188 | ||
c906108c | 4189 | static int |
acdb74a0 | 4190 | is_delayed (unsigned long insn) |
c906108c SS |
4191 | { |
4192 | int i; | |
4193 | for (i = 0; i < NUMOPCODES; ++i) | |
4194 | if (mips_opcodes[i].pinfo != INSN_MACRO | |
4195 | && (insn & mips_opcodes[i].mask) == mips_opcodes[i].match) | |
4196 | break; | |
4197 | return (i < NUMOPCODES | |
4198 | && (mips_opcodes[i].pinfo & (INSN_UNCOND_BRANCH_DELAY | |
4199 | | INSN_COND_BRANCH_DELAY | |
4200 | | INSN_COND_BRANCH_LIKELY))); | |
4201 | } | |
4202 | ||
4203 | int | |
3352ef37 AC |
4204 | mips_single_step_through_delay (struct gdbarch *gdbarch, |
4205 | struct frame_info *frame) | |
c906108c | 4206 | { |
3352ef37 | 4207 | CORE_ADDR pc = get_frame_pc (frame); |
47a35522 | 4208 | gdb_byte buf[MIPS_INSN32_SIZE]; |
c906108c SS |
4209 | |
4210 | /* There is no branch delay slot on MIPS16. */ | |
0fe7e7c8 | 4211 | if (mips_pc_is_mips16 (pc)) |
c906108c SS |
4212 | return 0; |
4213 | ||
06648491 MK |
4214 | if (!breakpoint_here_p (pc + 4)) |
4215 | return 0; | |
4216 | ||
3352ef37 AC |
4217 | if (!safe_frame_unwind_memory (frame, pc, buf, sizeof buf)) |
4218 | /* If error reading memory, guess that it is not a delayed | |
4219 | branch. */ | |
c906108c | 4220 | return 0; |
4c7d22cb | 4221 | return is_delayed (extract_unsigned_integer (buf, sizeof buf)); |
c906108c SS |
4222 | } |
4223 | ||
6d82d43b AC |
4224 | /* To skip prologues, I use this predicate. Returns either PC itself |
4225 | if the code at PC does not look like a function prologue; otherwise | |
4226 | returns an address that (if we're lucky) follows the prologue. If | |
4227 | LENIENT, then we must skip everything which is involved in setting | |
4228 | up the frame (it's OK to skip more, just so long as we don't skip | |
4229 | anything which might clobber the registers which are being saved. | |
4230 | We must skip more in the case where part of the prologue is in the | |
4231 | delay slot of a non-prologue instruction). */ | |
4232 | ||
4233 | static CORE_ADDR | |
4234 | mips_skip_prologue (CORE_ADDR pc) | |
4235 | { | |
8b622e6a AC |
4236 | CORE_ADDR limit_pc; |
4237 | CORE_ADDR func_addr; | |
4238 | ||
6d82d43b AC |
4239 | /* See if we can determine the end of the prologue via the symbol table. |
4240 | If so, then return either PC, or the PC after the prologue, whichever | |
4241 | is greater. */ | |
8b622e6a AC |
4242 | if (find_pc_partial_function (pc, NULL, &func_addr, NULL)) |
4243 | { | |
4244 | CORE_ADDR post_prologue_pc = skip_prologue_using_sal (func_addr); | |
4245 | if (post_prologue_pc != 0) | |
4246 | return max (pc, post_prologue_pc); | |
4247 | } | |
6d82d43b AC |
4248 | |
4249 | /* Can't determine prologue from the symbol table, need to examine | |
4250 | instructions. */ | |
4251 | ||
98b4dd94 JB |
4252 | /* Find an upper limit on the function prologue using the debug |
4253 | information. If the debug information could not be used to provide | |
4254 | that bound, then use an arbitrary large number as the upper bound. */ | |
4255 | limit_pc = skip_prologue_using_sal (pc); | |
4256 | if (limit_pc == 0) | |
4257 | limit_pc = pc + 100; /* Magic. */ | |
4258 | ||
0fe7e7c8 | 4259 | if (mips_pc_is_mips16 (pc)) |
a65bbe44 | 4260 | return mips16_scan_prologue (pc, limit_pc, NULL, NULL); |
6d82d43b | 4261 | else |
a65bbe44 | 4262 | return mips32_scan_prologue (pc, limit_pc, NULL, NULL); |
88658117 AC |
4263 | } |
4264 | ||
a5ea2558 AC |
4265 | /* Root of all "set mips "/"show mips " commands. This will eventually be |
4266 | used for all MIPS-specific commands. */ | |
4267 | ||
a5ea2558 | 4268 | static void |
acdb74a0 | 4269 | show_mips_command (char *args, int from_tty) |
a5ea2558 AC |
4270 | { |
4271 | help_list (showmipscmdlist, "show mips ", all_commands, gdb_stdout); | |
4272 | } | |
4273 | ||
a5ea2558 | 4274 | static void |
acdb74a0 | 4275 | set_mips_command (char *args, int from_tty) |
a5ea2558 | 4276 | { |
6d82d43b AC |
4277 | printf_unfiltered |
4278 | ("\"set mips\" must be followed by an appropriate subcommand.\n"); | |
a5ea2558 AC |
4279 | help_list (setmipscmdlist, "set mips ", all_commands, gdb_stdout); |
4280 | } | |
4281 | ||
c906108c SS |
4282 | /* Commands to show/set the MIPS FPU type. */ |
4283 | ||
c906108c | 4284 | static void |
acdb74a0 | 4285 | show_mipsfpu_command (char *args, int from_tty) |
c906108c | 4286 | { |
c906108c SS |
4287 | char *fpu; |
4288 | switch (MIPS_FPU_TYPE) | |
4289 | { | |
4290 | case MIPS_FPU_SINGLE: | |
4291 | fpu = "single-precision"; | |
4292 | break; | |
4293 | case MIPS_FPU_DOUBLE: | |
4294 | fpu = "double-precision"; | |
4295 | break; | |
4296 | case MIPS_FPU_NONE: | |
4297 | fpu = "absent (none)"; | |
4298 | break; | |
93d56215 | 4299 | default: |
e2e0b3e5 | 4300 | internal_error (__FILE__, __LINE__, _("bad switch")); |
c906108c SS |
4301 | } |
4302 | if (mips_fpu_type_auto) | |
6d82d43b AC |
4303 | printf_unfiltered |
4304 | ("The MIPS floating-point coprocessor is set automatically (currently %s)\n", | |
4305 | fpu); | |
c906108c | 4306 | else |
6d82d43b AC |
4307 | printf_unfiltered |
4308 | ("The MIPS floating-point coprocessor is assumed to be %s\n", fpu); | |
c906108c SS |
4309 | } |
4310 | ||
4311 | ||
c906108c | 4312 | static void |
acdb74a0 | 4313 | set_mipsfpu_command (char *args, int from_tty) |
c906108c | 4314 | { |
6d82d43b AC |
4315 | printf_unfiltered |
4316 | ("\"set mipsfpu\" must be followed by \"double\", \"single\",\"none\" or \"auto\".\n"); | |
c906108c SS |
4317 | show_mipsfpu_command (args, from_tty); |
4318 | } | |
4319 | ||
c906108c | 4320 | static void |
acdb74a0 | 4321 | set_mipsfpu_single_command (char *args, int from_tty) |
c906108c | 4322 | { |
8d5838b5 AC |
4323 | struct gdbarch_info info; |
4324 | gdbarch_info_init (&info); | |
c906108c SS |
4325 | mips_fpu_type = MIPS_FPU_SINGLE; |
4326 | mips_fpu_type_auto = 0; | |
8d5838b5 AC |
4327 | /* FIXME: cagney/2003-11-15: Should be setting a field in "info" |
4328 | instead of relying on globals. Doing that would let generic code | |
4329 | handle the search for this specific architecture. */ | |
4330 | if (!gdbarch_update_p (info)) | |
e2e0b3e5 | 4331 | internal_error (__FILE__, __LINE__, _("set mipsfpu failed")); |
c906108c SS |
4332 | } |
4333 | ||
c906108c | 4334 | static void |
acdb74a0 | 4335 | set_mipsfpu_double_command (char *args, int from_tty) |
c906108c | 4336 | { |
8d5838b5 AC |
4337 | struct gdbarch_info info; |
4338 | gdbarch_info_init (&info); | |
c906108c SS |
4339 | mips_fpu_type = MIPS_FPU_DOUBLE; |
4340 | mips_fpu_type_auto = 0; | |
8d5838b5 AC |
4341 | /* FIXME: cagney/2003-11-15: Should be setting a field in "info" |
4342 | instead of relying on globals. Doing that would let generic code | |
4343 | handle the search for this specific architecture. */ | |
4344 | if (!gdbarch_update_p (info)) | |
e2e0b3e5 | 4345 | internal_error (__FILE__, __LINE__, _("set mipsfpu failed")); |
c906108c SS |
4346 | } |
4347 | ||
c906108c | 4348 | static void |
acdb74a0 | 4349 | set_mipsfpu_none_command (char *args, int from_tty) |
c906108c | 4350 | { |
8d5838b5 AC |
4351 | struct gdbarch_info info; |
4352 | gdbarch_info_init (&info); | |
c906108c SS |
4353 | mips_fpu_type = MIPS_FPU_NONE; |
4354 | mips_fpu_type_auto = 0; | |
8d5838b5 AC |
4355 | /* FIXME: cagney/2003-11-15: Should be setting a field in "info" |
4356 | instead of relying on globals. Doing that would let generic code | |
4357 | handle the search for this specific architecture. */ | |
4358 | if (!gdbarch_update_p (info)) | |
e2e0b3e5 | 4359 | internal_error (__FILE__, __LINE__, _("set mipsfpu failed")); |
c906108c SS |
4360 | } |
4361 | ||
c906108c | 4362 | static void |
acdb74a0 | 4363 | set_mipsfpu_auto_command (char *args, int from_tty) |
c906108c SS |
4364 | { |
4365 | mips_fpu_type_auto = 1; | |
4366 | } | |
4367 | ||
c906108c | 4368 | /* Attempt to identify the particular processor model by reading the |
691c0433 AC |
4369 | processor id. NOTE: cagney/2003-11-15: Firstly it isn't clear that |
4370 | the relevant processor still exists (it dates back to '94) and | |
4371 | secondly this is not the way to do this. The processor type should | |
4372 | be set by forcing an architecture change. */ | |
c906108c | 4373 | |
691c0433 AC |
4374 | void |
4375 | deprecated_mips_set_processor_regs_hack (void) | |
c906108c | 4376 | { |
691c0433 | 4377 | struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); |
c906108c SS |
4378 | CORE_ADDR prid; |
4379 | ||
a5c9623c | 4380 | prid = read_register (MIPS_PRID_REGNUM); |
c906108c SS |
4381 | |
4382 | if ((prid & ~0xf) == 0x700) | |
691c0433 | 4383 | tdep->mips_processor_reg_names = mips_r3041_reg_names; |
c906108c SS |
4384 | } |
4385 | ||
4386 | /* Just like reinit_frame_cache, but with the right arguments to be | |
4387 | callable as an sfunc. */ | |
4388 | ||
4389 | static void | |
acdb74a0 AC |
4390 | reinit_frame_cache_sfunc (char *args, int from_tty, |
4391 | struct cmd_list_element *c) | |
c906108c SS |
4392 | { |
4393 | reinit_frame_cache (); | |
4394 | } | |
4395 | ||
a89aa300 AC |
4396 | static int |
4397 | gdb_print_insn_mips (bfd_vma memaddr, struct disassemble_info *info) | |
c906108c | 4398 | { |
e5ab0dce | 4399 | struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); |
c906108c | 4400 | |
d31431ed AC |
4401 | /* FIXME: cagney/2003-06-26: Is this even necessary? The |
4402 | disassembler needs to be able to locally determine the ISA, and | |
4403 | not rely on GDB. Otherwize the stand-alone 'objdump -d' will not | |
4404 | work. */ | |
ec4045ea AC |
4405 | if (mips_pc_is_mips16 (memaddr)) |
4406 | info->mach = bfd_mach_mips16; | |
c906108c SS |
4407 | |
4408 | /* Round down the instruction address to the appropriate boundary. */ | |
65c11066 | 4409 | memaddr &= (info->mach == bfd_mach_mips16 ? ~1 : ~3); |
c5aa993b | 4410 | |
e5ab0dce | 4411 | /* Set the disassembler options. */ |
6d82d43b | 4412 | if (tdep->mips_abi == MIPS_ABI_N32 || tdep->mips_abi == MIPS_ABI_N64) |
e5ab0dce AC |
4413 | { |
4414 | /* Set up the disassembler info, so that we get the right | |
6d82d43b | 4415 | register names from libopcodes. */ |
e5ab0dce AC |
4416 | if (tdep->mips_abi == MIPS_ABI_N32) |
4417 | info->disassembler_options = "gpr-names=n32"; | |
4418 | else | |
4419 | info->disassembler_options = "gpr-names=64"; | |
4420 | info->flavour = bfd_target_elf_flavour; | |
4421 | } | |
4422 | else | |
4423 | /* This string is not recognized explicitly by the disassembler, | |
4424 | but it tells the disassembler to not try to guess the ABI from | |
4425 | the bfd elf headers, such that, if the user overrides the ABI | |
4426 | of a program linked as NewABI, the disassembly will follow the | |
4427 | register naming conventions specified by the user. */ | |
4428 | info->disassembler_options = "gpr-names=32"; | |
4429 | ||
c906108c | 4430 | /* Call the appropriate disassembler based on the target endian-ness. */ |
d7449b42 | 4431 | if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) |
c906108c SS |
4432 | return print_insn_big_mips (memaddr, info); |
4433 | else | |
4434 | return print_insn_little_mips (memaddr, info); | |
4435 | } | |
4436 | ||
c906108c SS |
4437 | /* This function implements the BREAKPOINT_FROM_PC macro. It uses the program |
4438 | counter value to determine whether a 16- or 32-bit breakpoint should be | |
4439 | used. It returns a pointer to a string of bytes that encode a breakpoint | |
4440 | instruction, stores the length of the string to *lenptr, and adjusts pc | |
4441 | (if necessary) to point to the actual memory location where the | |
4442 | breakpoint should be inserted. */ | |
4443 | ||
47a35522 | 4444 | static const gdb_byte * |
6d82d43b | 4445 | mips_breakpoint_from_pc (CORE_ADDR *pcptr, int *lenptr) |
c906108c | 4446 | { |
d7449b42 | 4447 | if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) |
c906108c | 4448 | { |
0fe7e7c8 | 4449 | if (mips_pc_is_mips16 (*pcptr)) |
c906108c | 4450 | { |
47a35522 | 4451 | static gdb_byte mips16_big_breakpoint[] = { 0xe8, 0xa5 }; |
95404a3e | 4452 | *pcptr = unmake_mips16_addr (*pcptr); |
c5aa993b | 4453 | *lenptr = sizeof (mips16_big_breakpoint); |
c906108c SS |
4454 | return mips16_big_breakpoint; |
4455 | } | |
4456 | else | |
4457 | { | |
aaab4dba AC |
4458 | /* The IDT board uses an unusual breakpoint value, and |
4459 | sometimes gets confused when it sees the usual MIPS | |
4460 | breakpoint instruction. */ | |
47a35522 MK |
4461 | static gdb_byte big_breakpoint[] = { 0, 0x5, 0, 0xd }; |
4462 | static gdb_byte pmon_big_breakpoint[] = { 0, 0, 0, 0xd }; | |
4463 | static gdb_byte idt_big_breakpoint[] = { 0, 0, 0x0a, 0xd }; | |
c906108c | 4464 | |
c5aa993b | 4465 | *lenptr = sizeof (big_breakpoint); |
c906108c SS |
4466 | |
4467 | if (strcmp (target_shortname, "mips") == 0) | |
4468 | return idt_big_breakpoint; | |
4469 | else if (strcmp (target_shortname, "ddb") == 0 | |
4470 | || strcmp (target_shortname, "pmon") == 0 | |
4471 | || strcmp (target_shortname, "lsi") == 0) | |
4472 | return pmon_big_breakpoint; | |
4473 | else | |
4474 | return big_breakpoint; | |
4475 | } | |
4476 | } | |
4477 | else | |
4478 | { | |
0fe7e7c8 | 4479 | if (mips_pc_is_mips16 (*pcptr)) |
c906108c | 4480 | { |
47a35522 | 4481 | static gdb_byte mips16_little_breakpoint[] = { 0xa5, 0xe8 }; |
95404a3e | 4482 | *pcptr = unmake_mips16_addr (*pcptr); |
c5aa993b | 4483 | *lenptr = sizeof (mips16_little_breakpoint); |
c906108c SS |
4484 | return mips16_little_breakpoint; |
4485 | } | |
4486 | else | |
4487 | { | |
47a35522 MK |
4488 | static gdb_byte little_breakpoint[] = { 0xd, 0, 0x5, 0 }; |
4489 | static gdb_byte pmon_little_breakpoint[] = { 0xd, 0, 0, 0 }; | |
4490 | static gdb_byte idt_little_breakpoint[] = { 0xd, 0x0a, 0, 0 }; | |
c906108c | 4491 | |
c5aa993b | 4492 | *lenptr = sizeof (little_breakpoint); |
c906108c SS |
4493 | |
4494 | if (strcmp (target_shortname, "mips") == 0) | |
4495 | return idt_little_breakpoint; | |
4496 | else if (strcmp (target_shortname, "ddb") == 0 | |
4497 | || strcmp (target_shortname, "pmon") == 0 | |
4498 | || strcmp (target_shortname, "lsi") == 0) | |
4499 | return pmon_little_breakpoint; | |
4500 | else | |
4501 | return little_breakpoint; | |
4502 | } | |
4503 | } | |
4504 | } | |
4505 | ||
4506 | /* If PC is in a mips16 call or return stub, return the address of the target | |
4507 | PC, which is either the callee or the caller. There are several | |
4508 | cases which must be handled: | |
4509 | ||
4510 | * If the PC is in __mips16_ret_{d,s}f, this is a return stub and the | |
c5aa993b | 4511 | target PC is in $31 ($ra). |
c906108c | 4512 | * If the PC is in __mips16_call_stub_{1..10}, this is a call stub |
c5aa993b | 4513 | and the target PC is in $2. |
c906108c | 4514 | * If the PC at the start of __mips16_call_stub_{s,d}f_{0..10}, i.e. |
c5aa993b JM |
4515 | before the jal instruction, this is effectively a call stub |
4516 | and the the target PC is in $2. Otherwise this is effectively | |
4517 | a return stub and the target PC is in $18. | |
c906108c SS |
4518 | |
4519 | See the source code for the stubs in gcc/config/mips/mips16.S for | |
e7d6a6d2 | 4520 | gory details. */ |
c906108c | 4521 | |
757a7cc6 | 4522 | static CORE_ADDR |
e7d6a6d2 | 4523 | mips_skip_trampoline_code (CORE_ADDR pc) |
c906108c SS |
4524 | { |
4525 | char *name; | |
4526 | CORE_ADDR start_addr; | |
4527 | ||
4528 | /* Find the starting address and name of the function containing the PC. */ | |
4529 | if (find_pc_partial_function (pc, &name, &start_addr, NULL) == 0) | |
4530 | return 0; | |
4531 | ||
4532 | /* If the PC is in __mips16_ret_{d,s}f, this is a return stub and the | |
4533 | target PC is in $31 ($ra). */ | |
4534 | if (strcmp (name, "__mips16_ret_sf") == 0 | |
4535 | || strcmp (name, "__mips16_ret_df") == 0) | |
4c7d22cb | 4536 | return read_signed_register (MIPS_RA_REGNUM); |
c906108c SS |
4537 | |
4538 | if (strncmp (name, "__mips16_call_stub_", 19) == 0) | |
4539 | { | |
4540 | /* If the PC is in __mips16_call_stub_{1..10}, this is a call stub | |
4541 | and the target PC is in $2. */ | |
4542 | if (name[19] >= '0' && name[19] <= '9') | |
6c997a34 | 4543 | return read_signed_register (2); |
c906108c SS |
4544 | |
4545 | /* If the PC at the start of __mips16_call_stub_{s,d}f_{0..10}, i.e. | |
c5aa993b JM |
4546 | before the jal instruction, this is effectively a call stub |
4547 | and the the target PC is in $2. Otherwise this is effectively | |
4548 | a return stub and the target PC is in $18. */ | |
c906108c SS |
4549 | else if (name[19] == 's' || name[19] == 'd') |
4550 | { | |
4551 | if (pc == start_addr) | |
4552 | { | |
4553 | /* Check if the target of the stub is a compiler-generated | |
c5aa993b JM |
4554 | stub. Such a stub for a function bar might have a name |
4555 | like __fn_stub_bar, and might look like this: | |
4556 | mfc1 $4,$f13 | |
4557 | mfc1 $5,$f12 | |
4558 | mfc1 $6,$f15 | |
4559 | mfc1 $7,$f14 | |
4560 | la $1,bar (becomes a lui/addiu pair) | |
4561 | jr $1 | |
4562 | So scan down to the lui/addi and extract the target | |
4563 | address from those two instructions. */ | |
c906108c | 4564 | |
6c997a34 | 4565 | CORE_ADDR target_pc = read_signed_register (2); |
d37cca3d | 4566 | ULONGEST inst; |
c906108c SS |
4567 | int i; |
4568 | ||
4569 | /* See if the name of the target function is __fn_stub_*. */ | |
6d82d43b AC |
4570 | if (find_pc_partial_function (target_pc, &name, NULL, NULL) == |
4571 | 0) | |
c906108c SS |
4572 | return target_pc; |
4573 | if (strncmp (name, "__fn_stub_", 10) != 0 | |
4574 | && strcmp (name, "etext") != 0 | |
4575 | && strcmp (name, "_etext") != 0) | |
4576 | return target_pc; | |
4577 | ||
4578 | /* Scan through this _fn_stub_ code for the lui/addiu pair. | |
c5aa993b JM |
4579 | The limit on the search is arbitrarily set to 20 |
4580 | instructions. FIXME. */ | |
95ac2dcf | 4581 | for (i = 0, pc = 0; i < 20; i++, target_pc += MIPS_INSN32_SIZE) |
c906108c | 4582 | { |
c5aa993b JM |
4583 | inst = mips_fetch_instruction (target_pc); |
4584 | if ((inst & 0xffff0000) == 0x3c010000) /* lui $at */ | |
4585 | pc = (inst << 16) & 0xffff0000; /* high word */ | |
4586 | else if ((inst & 0xffff0000) == 0x24210000) /* addiu $at */ | |
4587 | return pc | (inst & 0xffff); /* low word */ | |
c906108c SS |
4588 | } |
4589 | ||
4590 | /* Couldn't find the lui/addui pair, so return stub address. */ | |
4591 | return target_pc; | |
4592 | } | |
4593 | else | |
4594 | /* This is the 'return' part of a call stub. The return | |
4595 | address is in $r18. */ | |
6c997a34 | 4596 | return read_signed_register (18); |
c906108c SS |
4597 | } |
4598 | } | |
c5aa993b | 4599 | return 0; /* not a stub */ |
c906108c SS |
4600 | } |
4601 | ||
a4b8ebc8 AC |
4602 | /* Convert a dbx stab register number (from `r' declaration) to a GDB |
4603 | [1 * NUM_REGS .. 2 * NUM_REGS) REGNUM. */ | |
88c72b7d AC |
4604 | |
4605 | static int | |
4606 | mips_stab_reg_to_regnum (int num) | |
4607 | { | |
a4b8ebc8 | 4608 | int regnum; |
2f38ef89 | 4609 | if (num >= 0 && num < 32) |
a4b8ebc8 | 4610 | regnum = num; |
2f38ef89 | 4611 | else if (num >= 38 && num < 70) |
56cea623 | 4612 | regnum = num + mips_regnum (current_gdbarch)->fp0 - 38; |
040b99fd | 4613 | else if (num == 70) |
56cea623 | 4614 | regnum = mips_regnum (current_gdbarch)->hi; |
040b99fd | 4615 | else if (num == 71) |
56cea623 | 4616 | regnum = mips_regnum (current_gdbarch)->lo; |
2f38ef89 | 4617 | else |
a4b8ebc8 AC |
4618 | /* This will hopefully (eventually) provoke a warning. Should |
4619 | we be calling complaint() here? */ | |
4620 | return NUM_REGS + NUM_PSEUDO_REGS; | |
4621 | return NUM_REGS + regnum; | |
88c72b7d AC |
4622 | } |
4623 | ||
2f38ef89 | 4624 | |
a4b8ebc8 AC |
4625 | /* Convert a dwarf, dwarf2, or ecoff register number to a GDB [1 * |
4626 | NUM_REGS .. 2 * NUM_REGS) REGNUM. */ | |
88c72b7d AC |
4627 | |
4628 | static int | |
2f38ef89 | 4629 | mips_dwarf_dwarf2_ecoff_reg_to_regnum (int num) |
88c72b7d | 4630 | { |
a4b8ebc8 | 4631 | int regnum; |
2f38ef89 | 4632 | if (num >= 0 && num < 32) |
a4b8ebc8 | 4633 | regnum = num; |
2f38ef89 | 4634 | else if (num >= 32 && num < 64) |
56cea623 | 4635 | regnum = num + mips_regnum (current_gdbarch)->fp0 - 32; |
040b99fd | 4636 | else if (num == 64) |
56cea623 | 4637 | regnum = mips_regnum (current_gdbarch)->hi; |
040b99fd | 4638 | else if (num == 65) |
56cea623 | 4639 | regnum = mips_regnum (current_gdbarch)->lo; |
2f38ef89 | 4640 | else |
a4b8ebc8 AC |
4641 | /* This will hopefully (eventually) provoke a warning. Should we |
4642 | be calling complaint() here? */ | |
4643 | return NUM_REGS + NUM_PSEUDO_REGS; | |
4644 | return NUM_REGS + regnum; | |
4645 | } | |
4646 | ||
4647 | static int | |
4648 | mips_register_sim_regno (int regnum) | |
4649 | { | |
4650 | /* Only makes sense to supply raw registers. */ | |
4651 | gdb_assert (regnum >= 0 && regnum < NUM_REGS); | |
4652 | /* FIXME: cagney/2002-05-13: Need to look at the pseudo register to | |
4653 | decide if it is valid. Should instead define a standard sim/gdb | |
4654 | register numbering scheme. */ | |
4655 | if (REGISTER_NAME (NUM_REGS + regnum) != NULL | |
4656 | && REGISTER_NAME (NUM_REGS + regnum)[0] != '\0') | |
4657 | return regnum; | |
4658 | else | |
6d82d43b | 4659 | return LEGACY_SIM_REGNO_IGNORE; |
88c72b7d AC |
4660 | } |
4661 | ||
2f38ef89 | 4662 | |
4844f454 CV |
4663 | /* Convert an integer into an address. Extracting the value signed |
4664 | guarantees a correctly sign extended address. */ | |
fc0c74b1 AC |
4665 | |
4666 | static CORE_ADDR | |
79dd2d24 | 4667 | mips_integer_to_address (struct gdbarch *gdbarch, |
870cd05e | 4668 | struct type *type, const gdb_byte *buf) |
fc0c74b1 | 4669 | { |
4844f454 | 4670 | return (CORE_ADDR) extract_signed_integer (buf, TYPE_LENGTH (type)); |
fc0c74b1 AC |
4671 | } |
4672 | ||
caaa3122 DJ |
4673 | static void |
4674 | mips_find_abi_section (bfd *abfd, asection *sect, void *obj) | |
4675 | { | |
4676 | enum mips_abi *abip = (enum mips_abi *) obj; | |
4677 | const char *name = bfd_get_section_name (abfd, sect); | |
4678 | ||
4679 | if (*abip != MIPS_ABI_UNKNOWN) | |
4680 | return; | |
4681 | ||
4682 | if (strncmp (name, ".mdebug.", 8) != 0) | |
4683 | return; | |
4684 | ||
4685 | if (strcmp (name, ".mdebug.abi32") == 0) | |
4686 | *abip = MIPS_ABI_O32; | |
4687 | else if (strcmp (name, ".mdebug.abiN32") == 0) | |
4688 | *abip = MIPS_ABI_N32; | |
62a49b2c | 4689 | else if (strcmp (name, ".mdebug.abi64") == 0) |
e3bddbfa | 4690 | *abip = MIPS_ABI_N64; |
caaa3122 DJ |
4691 | else if (strcmp (name, ".mdebug.abiO64") == 0) |
4692 | *abip = MIPS_ABI_O64; | |
4693 | else if (strcmp (name, ".mdebug.eabi32") == 0) | |
4694 | *abip = MIPS_ABI_EABI32; | |
4695 | else if (strcmp (name, ".mdebug.eabi64") == 0) | |
4696 | *abip = MIPS_ABI_EABI64; | |
4697 | else | |
8a3fe4f8 | 4698 | warning (_("unsupported ABI %s."), name + 8); |
caaa3122 DJ |
4699 | } |
4700 | ||
22e47e37 FF |
4701 | static void |
4702 | mips_find_long_section (bfd *abfd, asection *sect, void *obj) | |
4703 | { | |
4704 | int *lbp = (int *) obj; | |
4705 | const char *name = bfd_get_section_name (abfd, sect); | |
4706 | ||
4707 | if (strncmp (name, ".gcc_compiled_long32", 20) == 0) | |
4708 | *lbp = 32; | |
4709 | else if (strncmp (name, ".gcc_compiled_long64", 20) == 0) | |
4710 | *lbp = 64; | |
4711 | else if (strncmp (name, ".gcc_compiled_long", 18) == 0) | |
4712 | warning (_("unrecognized .gcc_compiled_longXX")); | |
4713 | } | |
4714 | ||
2e4ebe70 DJ |
4715 | static enum mips_abi |
4716 | global_mips_abi (void) | |
4717 | { | |
4718 | int i; | |
4719 | ||
4720 | for (i = 0; mips_abi_strings[i] != NULL; i++) | |
4721 | if (mips_abi_strings[i] == mips_abi_string) | |
4722 | return (enum mips_abi) i; | |
4723 | ||
e2e0b3e5 | 4724 | internal_error (__FILE__, __LINE__, _("unknown ABI string")); |
2e4ebe70 DJ |
4725 | } |
4726 | ||
29709017 DJ |
4727 | static void |
4728 | mips_register_g_packet_guesses (struct gdbarch *gdbarch) | |
4729 | { | |
4730 | static struct target_desc *tdesc_gp32, *tdesc_gp64; | |
4731 | ||
4732 | if (tdesc_gp32 == NULL) | |
4733 | { | |
4734 | /* Create feature sets with the appropriate properties. The values | |
4735 | are not important. */ | |
4736 | ||
4737 | tdesc_gp32 = allocate_target_description (); | |
4738 | set_tdesc_property (tdesc_gp32, PROPERTY_GP32, ""); | |
4739 | ||
4740 | tdesc_gp64 = allocate_target_description (); | |
4741 | set_tdesc_property (tdesc_gp64, PROPERTY_GP64, ""); | |
4742 | } | |
4743 | ||
4744 | /* If the size matches the set of 32-bit or 64-bit integer registers, | |
4745 | assume that's what we've got. */ | |
4746 | register_remote_g_packet_guess (gdbarch, 38 * 4, tdesc_gp32); | |
4747 | register_remote_g_packet_guess (gdbarch, 38 * 8, tdesc_gp64); | |
4748 | ||
4749 | /* If the size matches the full set of registers GDB traditionally | |
4750 | knows about, including floating point, for either 32-bit or | |
4751 | 64-bit, assume that's what we've got. */ | |
4752 | register_remote_g_packet_guess (gdbarch, 90 * 4, tdesc_gp32); | |
4753 | register_remote_g_packet_guess (gdbarch, 90 * 8, tdesc_gp64); | |
4754 | ||
4755 | /* Otherwise we don't have a useful guess. */ | |
4756 | } | |
4757 | ||
c2d11a7d | 4758 | static struct gdbarch * |
6d82d43b | 4759 | mips_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) |
c2d11a7d | 4760 | { |
c2d11a7d JM |
4761 | struct gdbarch *gdbarch; |
4762 | struct gdbarch_tdep *tdep; | |
4763 | int elf_flags; | |
2e4ebe70 | 4764 | enum mips_abi mips_abi, found_abi, wanted_abi; |
a4b8ebc8 | 4765 | int num_regs; |
8d5838b5 | 4766 | enum mips_fpu_type fpu_type; |
c2d11a7d | 4767 | |
ec03c1ac AC |
4768 | /* First of all, extract the elf_flags, if available. */ |
4769 | if (info.abfd && bfd_get_flavour (info.abfd) == bfd_target_elf_flavour) | |
4770 | elf_flags = elf_elfheader (info.abfd)->e_flags; | |
6214a8a1 AC |
4771 | else if (arches != NULL) |
4772 | elf_flags = gdbarch_tdep (arches->gdbarch)->elf_flags; | |
ec03c1ac AC |
4773 | else |
4774 | elf_flags = 0; | |
4775 | if (gdbarch_debug) | |
4776 | fprintf_unfiltered (gdb_stdlog, | |
6d82d43b | 4777 | "mips_gdbarch_init: elf_flags = 0x%08x\n", elf_flags); |
c2d11a7d | 4778 | |
102182a9 | 4779 | /* Check ELF_FLAGS to see if it specifies the ABI being used. */ |
0dadbba0 AC |
4780 | switch ((elf_flags & EF_MIPS_ABI)) |
4781 | { | |
4782 | case E_MIPS_ABI_O32: | |
ec03c1ac | 4783 | found_abi = MIPS_ABI_O32; |
0dadbba0 AC |
4784 | break; |
4785 | case E_MIPS_ABI_O64: | |
ec03c1ac | 4786 | found_abi = MIPS_ABI_O64; |
0dadbba0 AC |
4787 | break; |
4788 | case E_MIPS_ABI_EABI32: | |
ec03c1ac | 4789 | found_abi = MIPS_ABI_EABI32; |
0dadbba0 AC |
4790 | break; |
4791 | case E_MIPS_ABI_EABI64: | |
ec03c1ac | 4792 | found_abi = MIPS_ABI_EABI64; |
0dadbba0 AC |
4793 | break; |
4794 | default: | |
acdb74a0 | 4795 | if ((elf_flags & EF_MIPS_ABI2)) |
ec03c1ac | 4796 | found_abi = MIPS_ABI_N32; |
acdb74a0 | 4797 | else |
ec03c1ac | 4798 | found_abi = MIPS_ABI_UNKNOWN; |
0dadbba0 AC |
4799 | break; |
4800 | } | |
acdb74a0 | 4801 | |
caaa3122 | 4802 | /* GCC creates a pseudo-section whose name describes the ABI. */ |
ec03c1ac AC |
4803 | if (found_abi == MIPS_ABI_UNKNOWN && info.abfd != NULL) |
4804 | bfd_map_over_sections (info.abfd, mips_find_abi_section, &found_abi); | |
caaa3122 | 4805 | |
dc305454 | 4806 | /* If we have no useful BFD information, use the ABI from the last |
ec03c1ac AC |
4807 | MIPS architecture (if there is one). */ |
4808 | if (found_abi == MIPS_ABI_UNKNOWN && info.abfd == NULL && arches != NULL) | |
4809 | found_abi = gdbarch_tdep (arches->gdbarch)->found_abi; | |
2e4ebe70 | 4810 | |
32a6503c | 4811 | /* Try the architecture for any hint of the correct ABI. */ |
ec03c1ac | 4812 | if (found_abi == MIPS_ABI_UNKNOWN |
bf64bfd6 AC |
4813 | && info.bfd_arch_info != NULL |
4814 | && info.bfd_arch_info->arch == bfd_arch_mips) | |
4815 | { | |
4816 | switch (info.bfd_arch_info->mach) | |
4817 | { | |
4818 | case bfd_mach_mips3900: | |
ec03c1ac | 4819 | found_abi = MIPS_ABI_EABI32; |
bf64bfd6 AC |
4820 | break; |
4821 | case bfd_mach_mips4100: | |
4822 | case bfd_mach_mips5000: | |
ec03c1ac | 4823 | found_abi = MIPS_ABI_EABI64; |
bf64bfd6 | 4824 | break; |
1d06468c EZ |
4825 | case bfd_mach_mips8000: |
4826 | case bfd_mach_mips10000: | |
32a6503c KB |
4827 | /* On Irix, ELF64 executables use the N64 ABI. The |
4828 | pseudo-sections which describe the ABI aren't present | |
4829 | on IRIX. (Even for executables created by gcc.) */ | |
28d169de KB |
4830 | if (bfd_get_flavour (info.abfd) == bfd_target_elf_flavour |
4831 | && elf_elfheader (info.abfd)->e_ident[EI_CLASS] == ELFCLASS64) | |
ec03c1ac | 4832 | found_abi = MIPS_ABI_N64; |
28d169de | 4833 | else |
ec03c1ac | 4834 | found_abi = MIPS_ABI_N32; |
1d06468c | 4835 | break; |
bf64bfd6 AC |
4836 | } |
4837 | } | |
2e4ebe70 | 4838 | |
26c53e50 DJ |
4839 | /* Default 64-bit objects to N64 instead of O32. */ |
4840 | if (found_abi == MIPS_ABI_UNKNOWN | |
4841 | && info.abfd != NULL | |
4842 | && bfd_get_flavour (info.abfd) == bfd_target_elf_flavour | |
4843 | && elf_elfheader (info.abfd)->e_ident[EI_CLASS] == ELFCLASS64) | |
4844 | found_abi = MIPS_ABI_N64; | |
4845 | ||
ec03c1ac AC |
4846 | if (gdbarch_debug) |
4847 | fprintf_unfiltered (gdb_stdlog, "mips_gdbarch_init: found_abi = %d\n", | |
4848 | found_abi); | |
4849 | ||
4850 | /* What has the user specified from the command line? */ | |
4851 | wanted_abi = global_mips_abi (); | |
4852 | if (gdbarch_debug) | |
4853 | fprintf_unfiltered (gdb_stdlog, "mips_gdbarch_init: wanted_abi = %d\n", | |
4854 | wanted_abi); | |
2e4ebe70 DJ |
4855 | |
4856 | /* Now that we have found what the ABI for this binary would be, | |
4857 | check whether the user is overriding it. */ | |
2e4ebe70 DJ |
4858 | if (wanted_abi != MIPS_ABI_UNKNOWN) |
4859 | mips_abi = wanted_abi; | |
ec03c1ac AC |
4860 | else if (found_abi != MIPS_ABI_UNKNOWN) |
4861 | mips_abi = found_abi; | |
4862 | else | |
4863 | mips_abi = MIPS_ABI_O32; | |
4864 | if (gdbarch_debug) | |
4865 | fprintf_unfiltered (gdb_stdlog, "mips_gdbarch_init: mips_abi = %d\n", | |
4866 | mips_abi); | |
2e4ebe70 | 4867 | |
ec03c1ac | 4868 | /* Also used when doing an architecture lookup. */ |
4b9b3959 | 4869 | if (gdbarch_debug) |
ec03c1ac AC |
4870 | fprintf_unfiltered (gdb_stdlog, |
4871 | "mips_gdbarch_init: mips64_transfers_32bit_regs_p = %d\n", | |
4872 | mips64_transfers_32bit_regs_p); | |
0dadbba0 | 4873 | |
8d5838b5 AC |
4874 | /* Determine the MIPS FPU type. */ |
4875 | if (!mips_fpu_type_auto) | |
4876 | fpu_type = mips_fpu_type; | |
4877 | else if (info.bfd_arch_info != NULL | |
4878 | && info.bfd_arch_info->arch == bfd_arch_mips) | |
4879 | switch (info.bfd_arch_info->mach) | |
4880 | { | |
4881 | case bfd_mach_mips3900: | |
4882 | case bfd_mach_mips4100: | |
4883 | case bfd_mach_mips4111: | |
a9d61c86 | 4884 | case bfd_mach_mips4120: |
8d5838b5 AC |
4885 | fpu_type = MIPS_FPU_NONE; |
4886 | break; | |
4887 | case bfd_mach_mips4650: | |
4888 | fpu_type = MIPS_FPU_SINGLE; | |
4889 | break; | |
4890 | default: | |
4891 | fpu_type = MIPS_FPU_DOUBLE; | |
4892 | break; | |
4893 | } | |
4894 | else if (arches != NULL) | |
4895 | fpu_type = gdbarch_tdep (arches->gdbarch)->mips_fpu_type; | |
4896 | else | |
4897 | fpu_type = MIPS_FPU_DOUBLE; | |
4898 | if (gdbarch_debug) | |
4899 | fprintf_unfiltered (gdb_stdlog, | |
6d82d43b | 4900 | "mips_gdbarch_init: fpu_type = %d\n", fpu_type); |
8d5838b5 | 4901 | |
29709017 DJ |
4902 | /* Check for blatant incompatibilities. */ |
4903 | ||
4904 | /* If we have only 32-bit registers, then we can't debug a 64-bit | |
4905 | ABI. */ | |
4906 | if (info.target_desc | |
4907 | && tdesc_property (info.target_desc, PROPERTY_GP32) != NULL | |
4908 | && mips_abi != MIPS_ABI_EABI32 | |
4909 | && mips_abi != MIPS_ABI_O32) | |
4910 | return NULL; | |
4911 | ||
c2d11a7d JM |
4912 | /* try to find a pre-existing architecture */ |
4913 | for (arches = gdbarch_list_lookup_by_info (arches, &info); | |
4914 | arches != NULL; | |
4915 | arches = gdbarch_list_lookup_by_info (arches->next, &info)) | |
4916 | { | |
4917 | /* MIPS needs to be pedantic about which ABI the object is | |
102182a9 | 4918 | using. */ |
9103eae0 | 4919 | if (gdbarch_tdep (arches->gdbarch)->elf_flags != elf_flags) |
c2d11a7d | 4920 | continue; |
9103eae0 | 4921 | if (gdbarch_tdep (arches->gdbarch)->mips_abi != mips_abi) |
0dadbba0 | 4922 | continue; |
719ec221 AC |
4923 | /* Need to be pedantic about which register virtual size is |
4924 | used. */ | |
4925 | if (gdbarch_tdep (arches->gdbarch)->mips64_transfers_32bit_regs_p | |
4926 | != mips64_transfers_32bit_regs_p) | |
4927 | continue; | |
8d5838b5 AC |
4928 | /* Be pedantic about which FPU is selected. */ |
4929 | if (gdbarch_tdep (arches->gdbarch)->mips_fpu_type != fpu_type) | |
4930 | continue; | |
4be87837 | 4931 | return arches->gdbarch; |
c2d11a7d JM |
4932 | } |
4933 | ||
102182a9 | 4934 | /* Need a new architecture. Fill in a target specific vector. */ |
c2d11a7d JM |
4935 | tdep = (struct gdbarch_tdep *) xmalloc (sizeof (struct gdbarch_tdep)); |
4936 | gdbarch = gdbarch_alloc (&info, tdep); | |
4937 | tdep->elf_flags = elf_flags; | |
719ec221 | 4938 | tdep->mips64_transfers_32bit_regs_p = mips64_transfers_32bit_regs_p; |
ec03c1ac AC |
4939 | tdep->found_abi = found_abi; |
4940 | tdep->mips_abi = mips_abi; | |
8d5838b5 | 4941 | tdep->mips_fpu_type = fpu_type; |
29709017 DJ |
4942 | tdep->register_size_valid_p = 0; |
4943 | tdep->register_size = 0; | |
4944 | ||
4945 | if (info.target_desc) | |
4946 | { | |
4947 | /* Some useful properties can be inferred from the target. */ | |
4948 | if (tdesc_property (info.target_desc, PROPERTY_GP32) != NULL) | |
4949 | { | |
4950 | tdep->register_size_valid_p = 1; | |
4951 | tdep->register_size = 4; | |
4952 | } | |
4953 | else if (tdesc_property (info.target_desc, PROPERTY_GP64) != NULL) | |
4954 | { | |
4955 | tdep->register_size_valid_p = 1; | |
4956 | tdep->register_size = 8; | |
4957 | } | |
4958 | } | |
c2d11a7d | 4959 | |
102182a9 | 4960 | /* Initially set everything according to the default ABI/ISA. */ |
c2d11a7d JM |
4961 | set_gdbarch_short_bit (gdbarch, 16); |
4962 | set_gdbarch_int_bit (gdbarch, 32); | |
4963 | set_gdbarch_float_bit (gdbarch, 32); | |
4964 | set_gdbarch_double_bit (gdbarch, 64); | |
4965 | set_gdbarch_long_double_bit (gdbarch, 64); | |
a4b8ebc8 AC |
4966 | set_gdbarch_register_reggroup_p (gdbarch, mips_register_reggroup_p); |
4967 | set_gdbarch_pseudo_register_read (gdbarch, mips_pseudo_register_read); | |
4968 | set_gdbarch_pseudo_register_write (gdbarch, mips_pseudo_register_write); | |
1d06468c | 4969 | |
6d82d43b | 4970 | set_gdbarch_elf_make_msymbol_special (gdbarch, |
f7ab6ec6 MS |
4971 | mips_elf_make_msymbol_special); |
4972 | ||
16e109ca | 4973 | /* Fill in the OS dependant register numbers and names. */ |
56cea623 | 4974 | { |
16e109ca | 4975 | const char **reg_names; |
56cea623 AC |
4976 | struct mips_regnum *regnum = GDBARCH_OBSTACK_ZALLOC (gdbarch, |
4977 | struct mips_regnum); | |
56cea623 AC |
4978 | if (info.osabi == GDB_OSABI_IRIX) |
4979 | { | |
4980 | regnum->fp0 = 32; | |
4981 | regnum->pc = 64; | |
4982 | regnum->cause = 65; | |
4983 | regnum->badvaddr = 66; | |
4984 | regnum->hi = 67; | |
4985 | regnum->lo = 68; | |
4986 | regnum->fp_control_status = 69; | |
4987 | regnum->fp_implementation_revision = 70; | |
4988 | num_regs = 71; | |
16e109ca | 4989 | reg_names = mips_irix_reg_names; |
56cea623 AC |
4990 | } |
4991 | else | |
4992 | { | |
4993 | regnum->lo = MIPS_EMBED_LO_REGNUM; | |
4994 | regnum->hi = MIPS_EMBED_HI_REGNUM; | |
4995 | regnum->badvaddr = MIPS_EMBED_BADVADDR_REGNUM; | |
4996 | regnum->cause = MIPS_EMBED_CAUSE_REGNUM; | |
4997 | regnum->pc = MIPS_EMBED_PC_REGNUM; | |
4998 | regnum->fp0 = MIPS_EMBED_FP0_REGNUM; | |
4999 | regnum->fp_control_status = 70; | |
5000 | regnum->fp_implementation_revision = 71; | |
5001 | num_regs = 90; | |
16e109ca AC |
5002 | if (info.bfd_arch_info != NULL |
5003 | && info.bfd_arch_info->mach == bfd_mach_mips3900) | |
5004 | reg_names = mips_tx39_reg_names; | |
5005 | else | |
5006 | reg_names = mips_generic_reg_names; | |
56cea623 AC |
5007 | } |
5008 | /* FIXME: cagney/2003-11-15: For MIPS, hasn't PC_REGNUM been | |
5009 | replaced by read_pc? */ | |
f10683bb MH |
5010 | set_gdbarch_pc_regnum (gdbarch, regnum->pc + num_regs); |
5011 | set_gdbarch_sp_regnum (gdbarch, MIPS_SP_REGNUM + num_regs); | |
56cea623 AC |
5012 | set_gdbarch_fp0_regnum (gdbarch, regnum->fp0); |
5013 | set_gdbarch_num_regs (gdbarch, num_regs); | |
5014 | set_gdbarch_num_pseudo_regs (gdbarch, num_regs); | |
16e109ca AC |
5015 | set_gdbarch_register_name (gdbarch, mips_register_name); |
5016 | tdep->mips_processor_reg_names = reg_names; | |
5017 | tdep->regnum = regnum; | |
56cea623 | 5018 | } |
fe29b929 | 5019 | |
0dadbba0 | 5020 | switch (mips_abi) |
c2d11a7d | 5021 | { |
0dadbba0 | 5022 | case MIPS_ABI_O32: |
25ab4790 | 5023 | set_gdbarch_push_dummy_call (gdbarch, mips_o32_push_dummy_call); |
29dfb2ac | 5024 | set_gdbarch_return_value (gdbarch, mips_o32_return_value); |
4c7d22cb | 5025 | tdep->mips_last_arg_regnum = MIPS_A0_REGNUM + 4 - 1; |
56cea623 | 5026 | tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 4 - 1; |
4014092b | 5027 | tdep->default_mask_address_p = 0; |
c2d11a7d JM |
5028 | set_gdbarch_long_bit (gdbarch, 32); |
5029 | set_gdbarch_ptr_bit (gdbarch, 32); | |
5030 | set_gdbarch_long_long_bit (gdbarch, 64); | |
5031 | break; | |
0dadbba0 | 5032 | case MIPS_ABI_O64: |
25ab4790 | 5033 | set_gdbarch_push_dummy_call (gdbarch, mips_o64_push_dummy_call); |
9c8fdbfa | 5034 | set_gdbarch_return_value (gdbarch, mips_o64_return_value); |
4c7d22cb | 5035 | tdep->mips_last_arg_regnum = MIPS_A0_REGNUM + 4 - 1; |
56cea623 | 5036 | tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 4 - 1; |
361d1df0 | 5037 | tdep->default_mask_address_p = 0; |
c2d11a7d JM |
5038 | set_gdbarch_long_bit (gdbarch, 32); |
5039 | set_gdbarch_ptr_bit (gdbarch, 32); | |
5040 | set_gdbarch_long_long_bit (gdbarch, 64); | |
5041 | break; | |
0dadbba0 | 5042 | case MIPS_ABI_EABI32: |
25ab4790 | 5043 | set_gdbarch_push_dummy_call (gdbarch, mips_eabi_push_dummy_call); |
9c8fdbfa | 5044 | set_gdbarch_return_value (gdbarch, mips_eabi_return_value); |
4c7d22cb | 5045 | tdep->mips_last_arg_regnum = MIPS_A0_REGNUM + 8 - 1; |
56cea623 | 5046 | tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 8 - 1; |
4014092b | 5047 | tdep->default_mask_address_p = 0; |
c2d11a7d JM |
5048 | set_gdbarch_long_bit (gdbarch, 32); |
5049 | set_gdbarch_ptr_bit (gdbarch, 32); | |
5050 | set_gdbarch_long_long_bit (gdbarch, 64); | |
5051 | break; | |
0dadbba0 | 5052 | case MIPS_ABI_EABI64: |
25ab4790 | 5053 | set_gdbarch_push_dummy_call (gdbarch, mips_eabi_push_dummy_call); |
9c8fdbfa | 5054 | set_gdbarch_return_value (gdbarch, mips_eabi_return_value); |
4c7d22cb | 5055 | tdep->mips_last_arg_regnum = MIPS_A0_REGNUM + 8 - 1; |
56cea623 | 5056 | tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 8 - 1; |
4014092b | 5057 | tdep->default_mask_address_p = 0; |
c2d11a7d JM |
5058 | set_gdbarch_long_bit (gdbarch, 64); |
5059 | set_gdbarch_ptr_bit (gdbarch, 64); | |
5060 | set_gdbarch_long_long_bit (gdbarch, 64); | |
5061 | break; | |
0dadbba0 | 5062 | case MIPS_ABI_N32: |
25ab4790 | 5063 | set_gdbarch_push_dummy_call (gdbarch, mips_n32n64_push_dummy_call); |
29dfb2ac | 5064 | set_gdbarch_return_value (gdbarch, mips_n32n64_return_value); |
4c7d22cb | 5065 | tdep->mips_last_arg_regnum = MIPS_A0_REGNUM + 8 - 1; |
56cea623 | 5066 | tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 8 - 1; |
4014092b | 5067 | tdep->default_mask_address_p = 0; |
0dadbba0 AC |
5068 | set_gdbarch_long_bit (gdbarch, 32); |
5069 | set_gdbarch_ptr_bit (gdbarch, 32); | |
5070 | set_gdbarch_long_long_bit (gdbarch, 64); | |
fed7ba43 | 5071 | set_gdbarch_long_double_bit (gdbarch, 128); |
8da61cc4 | 5072 | set_gdbarch_long_double_format (gdbarch, floatformats_n32n64_long); |
28d169de KB |
5073 | break; |
5074 | case MIPS_ABI_N64: | |
25ab4790 | 5075 | set_gdbarch_push_dummy_call (gdbarch, mips_n32n64_push_dummy_call); |
29dfb2ac | 5076 | set_gdbarch_return_value (gdbarch, mips_n32n64_return_value); |
4c7d22cb | 5077 | tdep->mips_last_arg_regnum = MIPS_A0_REGNUM + 8 - 1; |
56cea623 | 5078 | tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 8 - 1; |
28d169de KB |
5079 | tdep->default_mask_address_p = 0; |
5080 | set_gdbarch_long_bit (gdbarch, 64); | |
5081 | set_gdbarch_ptr_bit (gdbarch, 64); | |
5082 | set_gdbarch_long_long_bit (gdbarch, 64); | |
fed7ba43 | 5083 | set_gdbarch_long_double_bit (gdbarch, 128); |
8da61cc4 | 5084 | set_gdbarch_long_double_format (gdbarch, floatformats_n32n64_long); |
0dadbba0 | 5085 | break; |
c2d11a7d | 5086 | default: |
e2e0b3e5 | 5087 | internal_error (__FILE__, __LINE__, _("unknown ABI in switch")); |
c2d11a7d JM |
5088 | } |
5089 | ||
22e47e37 FF |
5090 | /* GCC creates a pseudo-section whose name specifies the size of |
5091 | longs, since -mlong32 or -mlong64 may be used independent of | |
5092 | other options. How those options affect pointer sizes is ABI and | |
5093 | architecture dependent, so use them to override the default sizes | |
5094 | set by the ABI. This table shows the relationship between ABI, | |
5095 | -mlongXX, and size of pointers: | |
5096 | ||
5097 | ABI -mlongXX ptr bits | |
5098 | --- -------- -------- | |
5099 | o32 32 32 | |
5100 | o32 64 32 | |
5101 | n32 32 32 | |
5102 | n32 64 64 | |
5103 | o64 32 32 | |
5104 | o64 64 64 | |
5105 | n64 32 32 | |
5106 | n64 64 64 | |
5107 | eabi32 32 32 | |
5108 | eabi32 64 32 | |
5109 | eabi64 32 32 | |
5110 | eabi64 64 64 | |
5111 | ||
5112 | Note that for o32 and eabi32, pointers are always 32 bits | |
5113 | regardless of any -mlongXX option. For all others, pointers and | |
5114 | longs are the same, as set by -mlongXX or set by defaults. | |
5115 | */ | |
5116 | ||
5117 | if (info.abfd != NULL) | |
5118 | { | |
5119 | int long_bit = 0; | |
5120 | ||
5121 | bfd_map_over_sections (info.abfd, mips_find_long_section, &long_bit); | |
5122 | if (long_bit) | |
5123 | { | |
5124 | set_gdbarch_long_bit (gdbarch, long_bit); | |
5125 | switch (mips_abi) | |
5126 | { | |
5127 | case MIPS_ABI_O32: | |
5128 | case MIPS_ABI_EABI32: | |
5129 | break; | |
5130 | case MIPS_ABI_N32: | |
5131 | case MIPS_ABI_O64: | |
5132 | case MIPS_ABI_N64: | |
5133 | case MIPS_ABI_EABI64: | |
5134 | set_gdbarch_ptr_bit (gdbarch, long_bit); | |
5135 | break; | |
5136 | default: | |
5137 | internal_error (__FILE__, __LINE__, _("unknown ABI in switch")); | |
5138 | } | |
5139 | } | |
5140 | } | |
5141 | ||
a5ea2558 AC |
5142 | /* FIXME: jlarmour/2000-04-07: There *is* a flag EF_MIPS_32BIT_MODE |
5143 | that could indicate -gp32 BUT gas/config/tc-mips.c contains the | |
5144 | comment: | |
5145 | ||
5146 | ``We deliberately don't allow "-gp32" to set the MIPS_32BITMODE | |
5147 | flag in object files because to do so would make it impossible to | |
102182a9 | 5148 | link with libraries compiled without "-gp32". This is |
a5ea2558 | 5149 | unnecessarily restrictive. |
361d1df0 | 5150 | |
a5ea2558 AC |
5151 | We could solve this problem by adding "-gp32" multilibs to gcc, |
5152 | but to set this flag before gcc is built with such multilibs will | |
5153 | break too many systems.'' | |
5154 | ||
5155 | But even more unhelpfully, the default linker output target for | |
5156 | mips64-elf is elf32-bigmips, and has EF_MIPS_32BIT_MODE set, even | |
5157 | for 64-bit programs - you need to change the ABI to change this, | |
102182a9 | 5158 | and not all gcc targets support that currently. Therefore using |
a5ea2558 AC |
5159 | this flag to detect 32-bit mode would do the wrong thing given |
5160 | the current gcc - it would make GDB treat these 64-bit programs | |
102182a9 | 5161 | as 32-bit programs by default. */ |
a5ea2558 | 5162 | |
6c997a34 | 5163 | set_gdbarch_read_pc (gdbarch, mips_read_pc); |
b6cb9035 | 5164 | set_gdbarch_write_pc (gdbarch, mips_write_pc); |
bcb0cc15 | 5165 | set_gdbarch_read_sp (gdbarch, mips_read_sp); |
c2d11a7d | 5166 | |
102182a9 MS |
5167 | /* Add/remove bits from an address. The MIPS needs be careful to |
5168 | ensure that all 32 bit addresses are sign extended to 64 bits. */ | |
875e1767 AC |
5169 | set_gdbarch_addr_bits_remove (gdbarch, mips_addr_bits_remove); |
5170 | ||
58dfe9ff AC |
5171 | /* Unwind the frame. */ |
5172 | set_gdbarch_unwind_pc (gdbarch, mips_unwind_pc); | |
edfae063 | 5173 | set_gdbarch_unwind_dummy_id (gdbarch, mips_unwind_dummy_id); |
10312cc4 | 5174 | |
102182a9 | 5175 | /* Map debug register numbers onto internal register numbers. */ |
88c72b7d | 5176 | set_gdbarch_stab_reg_to_regnum (gdbarch, mips_stab_reg_to_regnum); |
6d82d43b AC |
5177 | set_gdbarch_ecoff_reg_to_regnum (gdbarch, |
5178 | mips_dwarf_dwarf2_ecoff_reg_to_regnum); | |
5179 | set_gdbarch_dwarf_reg_to_regnum (gdbarch, | |
5180 | mips_dwarf_dwarf2_ecoff_reg_to_regnum); | |
5181 | set_gdbarch_dwarf2_reg_to_regnum (gdbarch, | |
5182 | mips_dwarf_dwarf2_ecoff_reg_to_regnum); | |
a4b8ebc8 | 5183 | set_gdbarch_register_sim_regno (gdbarch, mips_register_sim_regno); |
88c72b7d | 5184 | |
c2d11a7d JM |
5185 | /* MIPS version of CALL_DUMMY */ |
5186 | ||
9710e734 AC |
5187 | /* NOTE: cagney/2003-08-05: Eventually call dummy location will be |
5188 | replaced by a command, and all targets will default to on stack | |
5189 | (regardless of the stack's execute status). */ | |
5190 | set_gdbarch_call_dummy_location (gdbarch, AT_SYMBOL); | |
dc604539 | 5191 | set_gdbarch_frame_align (gdbarch, mips_frame_align); |
d05285fa | 5192 | |
87783b8b AC |
5193 | set_gdbarch_convert_register_p (gdbarch, mips_convert_register_p); |
5194 | set_gdbarch_register_to_value (gdbarch, mips_register_to_value); | |
5195 | set_gdbarch_value_to_register (gdbarch, mips_value_to_register); | |
5196 | ||
f7b9e9fc AC |
5197 | set_gdbarch_inner_than (gdbarch, core_addr_lessthan); |
5198 | set_gdbarch_breakpoint_from_pc (gdbarch, mips_breakpoint_from_pc); | |
f7b9e9fc AC |
5199 | |
5200 | set_gdbarch_skip_prologue (gdbarch, mips_skip_prologue); | |
f7b9e9fc | 5201 | |
fc0c74b1 AC |
5202 | set_gdbarch_pointer_to_address (gdbarch, signed_pointer_to_address); |
5203 | set_gdbarch_address_to_pointer (gdbarch, address_to_signed_pointer); | |
5204 | set_gdbarch_integer_to_address (gdbarch, mips_integer_to_address); | |
70f80edf | 5205 | |
a4b8ebc8 | 5206 | set_gdbarch_register_type (gdbarch, mips_register_type); |
78fde5f8 | 5207 | |
e11c53d2 | 5208 | set_gdbarch_print_registers_info (gdbarch, mips_print_registers_info); |
bf1f5b4c | 5209 | |
e5ab0dce AC |
5210 | set_gdbarch_print_insn (gdbarch, gdb_print_insn_mips); |
5211 | ||
3a3bc038 AC |
5212 | /* FIXME: cagney/2003-08-29: The macros HAVE_STEPPABLE_WATCHPOINT, |
5213 | HAVE_NONSTEPPABLE_WATCHPOINT, and HAVE_CONTINUABLE_WATCHPOINT | |
5214 | need to all be folded into the target vector. Since they are | |
5215 | being used as guards for STOPPED_BY_WATCHPOINT, why not have | |
5216 | STOPPED_BY_WATCHPOINT return the type of watchpoint that the code | |
5217 | is sitting on? */ | |
5218 | set_gdbarch_have_nonsteppable_watchpoint (gdbarch, 1); | |
5219 | ||
e7d6a6d2 | 5220 | set_gdbarch_skip_trampoline_code (gdbarch, mips_skip_trampoline_code); |
757a7cc6 | 5221 | |
3352ef37 AC |
5222 | set_gdbarch_single_step_through_delay (gdbarch, mips_single_step_through_delay); |
5223 | ||
0d5de010 DJ |
5224 | /* Virtual tables. */ |
5225 | set_gdbarch_vbit_in_delta (gdbarch, 1); | |
5226 | ||
29709017 DJ |
5227 | mips_register_g_packet_guesses (gdbarch); |
5228 | ||
6de918a6 DJ |
5229 | /* Hook in OS ABI-specific overrides, if they have been registered. */ |
5230 | gdbarch_init_osabi (info, gdbarch); | |
757a7cc6 | 5231 | |
5792a79b | 5232 | /* Unwind the frame. */ |
eec63939 | 5233 | frame_unwind_append_sniffer (gdbarch, mips_stub_frame_sniffer); |
45c9dd44 AC |
5234 | frame_unwind_append_sniffer (gdbarch, mips_insn16_frame_sniffer); |
5235 | frame_unwind_append_sniffer (gdbarch, mips_insn32_frame_sniffer); | |
eec63939 | 5236 | frame_base_append_sniffer (gdbarch, mips_stub_frame_base_sniffer); |
45c9dd44 AC |
5237 | frame_base_append_sniffer (gdbarch, mips_insn16_frame_base_sniffer); |
5238 | frame_base_append_sniffer (gdbarch, mips_insn32_frame_base_sniffer); | |
5792a79b | 5239 | |
4b9b3959 AC |
5240 | return gdbarch; |
5241 | } | |
5242 | ||
2e4ebe70 | 5243 | static void |
6d82d43b | 5244 | mips_abi_update (char *ignore_args, int from_tty, struct cmd_list_element *c) |
2e4ebe70 DJ |
5245 | { |
5246 | struct gdbarch_info info; | |
5247 | ||
5248 | /* Force the architecture to update, and (if it's a MIPS architecture) | |
5249 | mips_gdbarch_init will take care of the rest. */ | |
5250 | gdbarch_info_init (&info); | |
5251 | gdbarch_update_p (info); | |
5252 | } | |
5253 | ||
ad188201 KB |
5254 | /* Print out which MIPS ABI is in use. */ |
5255 | ||
5256 | static void | |
1f8ca57c JB |
5257 | show_mips_abi (struct ui_file *file, |
5258 | int from_tty, | |
5259 | struct cmd_list_element *ignored_cmd, | |
5260 | const char *ignored_value) | |
ad188201 KB |
5261 | { |
5262 | if (gdbarch_bfd_arch_info (current_gdbarch)->arch != bfd_arch_mips) | |
1f8ca57c JB |
5263 | fprintf_filtered |
5264 | (file, | |
5265 | "The MIPS ABI is unknown because the current architecture " | |
5266 | "is not MIPS.\n"); | |
ad188201 KB |
5267 | else |
5268 | { | |
5269 | enum mips_abi global_abi = global_mips_abi (); | |
5270 | enum mips_abi actual_abi = mips_abi (current_gdbarch); | |
5271 | const char *actual_abi_str = mips_abi_strings[actual_abi]; | |
5272 | ||
5273 | if (global_abi == MIPS_ABI_UNKNOWN) | |
1f8ca57c JB |
5274 | fprintf_filtered |
5275 | (file, | |
5276 | "The MIPS ABI is set automatically (currently \"%s\").\n", | |
6d82d43b | 5277 | actual_abi_str); |
ad188201 | 5278 | else if (global_abi == actual_abi) |
1f8ca57c JB |
5279 | fprintf_filtered |
5280 | (file, | |
5281 | "The MIPS ABI is assumed to be \"%s\" (due to user setting).\n", | |
6d82d43b | 5282 | actual_abi_str); |
ad188201 KB |
5283 | else |
5284 | { | |
5285 | /* Probably shouldn't happen... */ | |
1f8ca57c JB |
5286 | fprintf_filtered |
5287 | (file, | |
5288 | "The (auto detected) MIPS ABI \"%s\" is in use even though the user setting was \"%s\".\n", | |
6d82d43b | 5289 | actual_abi_str, mips_abi_strings[global_abi]); |
ad188201 KB |
5290 | } |
5291 | } | |
5292 | } | |
5293 | ||
4b9b3959 AC |
5294 | static void |
5295 | mips_dump_tdep (struct gdbarch *current_gdbarch, struct ui_file *file) | |
5296 | { | |
5297 | struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); | |
5298 | if (tdep != NULL) | |
c2d11a7d | 5299 | { |
acdb74a0 AC |
5300 | int ef_mips_arch; |
5301 | int ef_mips_32bitmode; | |
f49e4e6d | 5302 | /* Determine the ISA. */ |
acdb74a0 AC |
5303 | switch (tdep->elf_flags & EF_MIPS_ARCH) |
5304 | { | |
5305 | case E_MIPS_ARCH_1: | |
5306 | ef_mips_arch = 1; | |
5307 | break; | |
5308 | case E_MIPS_ARCH_2: | |
5309 | ef_mips_arch = 2; | |
5310 | break; | |
5311 | case E_MIPS_ARCH_3: | |
5312 | ef_mips_arch = 3; | |
5313 | break; | |
5314 | case E_MIPS_ARCH_4: | |
93d56215 | 5315 | ef_mips_arch = 4; |
acdb74a0 AC |
5316 | break; |
5317 | default: | |
93d56215 | 5318 | ef_mips_arch = 0; |
acdb74a0 AC |
5319 | break; |
5320 | } | |
f49e4e6d | 5321 | /* Determine the size of a pointer. */ |
acdb74a0 | 5322 | ef_mips_32bitmode = (tdep->elf_flags & EF_MIPS_32BITMODE); |
4b9b3959 AC |
5323 | fprintf_unfiltered (file, |
5324 | "mips_dump_tdep: tdep->elf_flags = 0x%x\n", | |
0dadbba0 | 5325 | tdep->elf_flags); |
4b9b3959 | 5326 | fprintf_unfiltered (file, |
acdb74a0 AC |
5327 | "mips_dump_tdep: ef_mips_32bitmode = %d\n", |
5328 | ef_mips_32bitmode); | |
5329 | fprintf_unfiltered (file, | |
5330 | "mips_dump_tdep: ef_mips_arch = %d\n", | |
5331 | ef_mips_arch); | |
5332 | fprintf_unfiltered (file, | |
5333 | "mips_dump_tdep: tdep->mips_abi = %d (%s)\n", | |
6d82d43b | 5334 | tdep->mips_abi, mips_abi_strings[tdep->mips_abi]); |
4014092b AC |
5335 | fprintf_unfiltered (file, |
5336 | "mips_dump_tdep: mips_mask_address_p() %d (default %d)\n", | |
480d3dd2 | 5337 | mips_mask_address_p (tdep), |
4014092b | 5338 | tdep->default_mask_address_p); |
c2d11a7d | 5339 | } |
4b9b3959 AC |
5340 | fprintf_unfiltered (file, |
5341 | "mips_dump_tdep: MIPS_DEFAULT_FPU_TYPE = %d (%s)\n", | |
5342 | MIPS_DEFAULT_FPU_TYPE, | |
5343 | (MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_NONE ? "none" | |
5344 | : MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_SINGLE ? "single" | |
5345 | : MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_DOUBLE ? "double" | |
5346 | : "???")); | |
6d82d43b | 5347 | fprintf_unfiltered (file, "mips_dump_tdep: MIPS_EABI = %d\n", MIPS_EABI); |
4b9b3959 AC |
5348 | fprintf_unfiltered (file, |
5349 | "mips_dump_tdep: MIPS_FPU_TYPE = %d (%s)\n", | |
5350 | MIPS_FPU_TYPE, | |
5351 | (MIPS_FPU_TYPE == MIPS_FPU_NONE ? "none" | |
5352 | : MIPS_FPU_TYPE == MIPS_FPU_SINGLE ? "single" | |
5353 | : MIPS_FPU_TYPE == MIPS_FPU_DOUBLE ? "double" | |
5354 | : "???")); | |
4b9b3959 | 5355 | fprintf_unfiltered (file, |
480d3dd2 | 5356 | "mips_dump_tdep: mips_stack_argsize() = %d\n", |
13326b4e | 5357 | mips_stack_argsize (current_gdbarch)); |
c2d11a7d JM |
5358 | } |
5359 | ||
6d82d43b | 5360 | extern initialize_file_ftype _initialize_mips_tdep; /* -Wmissing-prototypes */ |
a78f21af | 5361 | |
c906108c | 5362 | void |
acdb74a0 | 5363 | _initialize_mips_tdep (void) |
c906108c SS |
5364 | { |
5365 | static struct cmd_list_element *mipsfpulist = NULL; | |
5366 | struct cmd_list_element *c; | |
5367 | ||
6d82d43b | 5368 | mips_abi_string = mips_abi_strings[MIPS_ABI_UNKNOWN]; |
2e4ebe70 DJ |
5369 | if (MIPS_ABI_LAST + 1 |
5370 | != sizeof (mips_abi_strings) / sizeof (mips_abi_strings[0])) | |
e2e0b3e5 | 5371 | internal_error (__FILE__, __LINE__, _("mips_abi_strings out of sync")); |
2e4ebe70 | 5372 | |
4b9b3959 | 5373 | gdbarch_register (bfd_arch_mips, mips_gdbarch_init, mips_dump_tdep); |
c906108c | 5374 | |
8d5f9dcb DJ |
5375 | mips_pdr_data = register_objfile_data (); |
5376 | ||
a5ea2558 AC |
5377 | /* Add root prefix command for all "set mips"/"show mips" commands */ |
5378 | add_prefix_cmd ("mips", no_class, set_mips_command, | |
1bedd215 | 5379 | _("Various MIPS specific commands."), |
a5ea2558 AC |
5380 | &setmipscmdlist, "set mips ", 0, &setlist); |
5381 | ||
5382 | add_prefix_cmd ("mips", no_class, show_mips_command, | |
1bedd215 | 5383 | _("Various MIPS specific commands."), |
a5ea2558 AC |
5384 | &showmipscmdlist, "show mips ", 0, &showlist); |
5385 | ||
5386 | /* Allow the user to override the saved register size. */ | |
1b295c3d | 5387 | add_setshow_enum_cmd ("saved-gpreg-size", class_obscure, |
7915a72c AC |
5388 | size_enums, &mips_abi_regsize_string, _("\ |
5389 | Set size of general purpose registers saved on the stack."), _("\ | |
5390 | Show size of general purpose registers saved on the stack."), _("\ | |
a5ea2558 AC |
5391 | This option can be set to one of:\n\ |
5392 | 32 - Force GDB to treat saved GP registers as 32-bit\n\ | |
5393 | 64 - Force GDB to treat saved GP registers as 64-bit\n\ | |
5394 | auto - Allow GDB to use the target's default setting or autodetect the\n\ | |
7915a72c AC |
5395 | saved GP register size from information contained in the\n\ |
5396 | executable (default)."), | |
2c5b56ce | 5397 | NULL, |
7915a72c | 5398 | NULL, /* FIXME: i18n: Size of general purpose registers saved on the stack is %s. */ |
2c5b56ce | 5399 | &setmipscmdlist, &showmipscmdlist); |
a5ea2558 | 5400 | |
d929b26f | 5401 | /* Allow the user to override the argument stack size. */ |
1b295c3d | 5402 | add_setshow_enum_cmd ("stack-arg-size", class_obscure, |
7915a72c AC |
5403 | size_enums, &mips_stack_argsize_string, _("\ |
5404 | Set the amount of stack space reserved for each argument."), _("\ | |
5405 | Show the amount of stack space reserved for each argument."), _("\ | |
d929b26f AC |
5406 | This option can be set to one of:\n\ |
5407 | 32 - Force GDB to allocate 32-bit chunks per argument\n\ | |
5408 | 64 - Force GDB to allocate 64-bit chunks per argument\n\ | |
5409 | auto - Allow GDB to determine the correct setting from the current\n\ | |
7915a72c | 5410 | target and executable (default)"), |
2c5b56ce | 5411 | NULL, |
7915a72c | 5412 | NULL, /* FIXME: i18n: The amount of stack space reserved for each argument is %s. */ |
2c5b56ce | 5413 | &setmipscmdlist, &showmipscmdlist); |
d929b26f | 5414 | |
2e4ebe70 | 5415 | /* Allow the user to override the ABI. */ |
7ab04401 AC |
5416 | add_setshow_enum_cmd ("abi", class_obscure, mips_abi_strings, |
5417 | &mips_abi_string, _("\ | |
5418 | Set the MIPS ABI used by this program."), _("\ | |
5419 | Show the MIPS ABI used by this program."), _("\ | |
5420 | This option can be set to one of:\n\ | |
5421 | auto - the default ABI associated with the current binary\n\ | |
5422 | o32\n\ | |
5423 | o64\n\ | |
5424 | n32\n\ | |
5425 | n64\n\ | |
5426 | eabi32\n\ | |
5427 | eabi64"), | |
5428 | mips_abi_update, | |
5429 | show_mips_abi, | |
5430 | &setmipscmdlist, &showmipscmdlist); | |
2e4ebe70 | 5431 | |
c906108c SS |
5432 | /* Let the user turn off floating point and set the fence post for |
5433 | heuristic_proc_start. */ | |
5434 | ||
5435 | add_prefix_cmd ("mipsfpu", class_support, set_mipsfpu_command, | |
1bedd215 | 5436 | _("Set use of MIPS floating-point coprocessor."), |
c906108c SS |
5437 | &mipsfpulist, "set mipsfpu ", 0, &setlist); |
5438 | add_cmd ("single", class_support, set_mipsfpu_single_command, | |
1a966eab | 5439 | _("Select single-precision MIPS floating-point coprocessor."), |
c906108c SS |
5440 | &mipsfpulist); |
5441 | add_cmd ("double", class_support, set_mipsfpu_double_command, | |
1a966eab | 5442 | _("Select double-precision MIPS floating-point coprocessor."), |
c906108c SS |
5443 | &mipsfpulist); |
5444 | add_alias_cmd ("on", "double", class_support, 1, &mipsfpulist); | |
5445 | add_alias_cmd ("yes", "double", class_support, 1, &mipsfpulist); | |
5446 | add_alias_cmd ("1", "double", class_support, 1, &mipsfpulist); | |
5447 | add_cmd ("none", class_support, set_mipsfpu_none_command, | |
1a966eab | 5448 | _("Select no MIPS floating-point coprocessor."), &mipsfpulist); |
c906108c SS |
5449 | add_alias_cmd ("off", "none", class_support, 1, &mipsfpulist); |
5450 | add_alias_cmd ("no", "none", class_support, 1, &mipsfpulist); | |
5451 | add_alias_cmd ("0", "none", class_support, 1, &mipsfpulist); | |
5452 | add_cmd ("auto", class_support, set_mipsfpu_auto_command, | |
1a966eab | 5453 | _("Select MIPS floating-point coprocessor automatically."), |
c906108c SS |
5454 | &mipsfpulist); |
5455 | add_cmd ("mipsfpu", class_support, show_mipsfpu_command, | |
1a966eab | 5456 | _("Show current use of MIPS floating-point coprocessor target."), |
c906108c SS |
5457 | &showlist); |
5458 | ||
c906108c SS |
5459 | /* We really would like to have both "0" and "unlimited" work, but |
5460 | command.c doesn't deal with that. So make it a var_zinteger | |
5461 | because the user can always use "999999" or some such for unlimited. */ | |
6bcadd06 | 5462 | add_setshow_zinteger_cmd ("heuristic-fence-post", class_support, |
7915a72c AC |
5463 | &heuristic_fence_post, _("\ |
5464 | Set the distance searched for the start of a function."), _("\ | |
5465 | Show the distance searched for the start of a function."), _("\ | |
c906108c SS |
5466 | If you are debugging a stripped executable, GDB needs to search through the\n\ |
5467 | program for the start of a function. This command sets the distance of the\n\ | |
7915a72c | 5468 | search. The only need to set it is when debugging a stripped executable."), |
2c5b56ce | 5469 | reinit_frame_cache_sfunc, |
7915a72c | 5470 | NULL, /* FIXME: i18n: The distance searched for the start of a function is %s. */ |
6bcadd06 | 5471 | &setlist, &showlist); |
c906108c SS |
5472 | |
5473 | /* Allow the user to control whether the upper bits of 64-bit | |
5474 | addresses should be zeroed. */ | |
7915a72c AC |
5475 | add_setshow_auto_boolean_cmd ("mask-address", no_class, |
5476 | &mask_address_var, _("\ | |
5477 | Set zeroing of upper 32 bits of 64-bit addresses."), _("\ | |
5478 | Show zeroing of upper 32 bits of 64-bit addresses."), _("\ | |
e9e68a56 | 5479 | Use \"on\" to enable the masking, \"off\" to disable it and \"auto\" to \n\ |
7915a72c | 5480 | allow GDB to determine the correct value."), |
08546159 AC |
5481 | NULL, show_mask_address, |
5482 | &setmipscmdlist, &showmipscmdlist); | |
43e526b9 JM |
5483 | |
5484 | /* Allow the user to control the size of 32 bit registers within the | |
5485 | raw remote packet. */ | |
b3f42336 | 5486 | add_setshow_boolean_cmd ("remote-mips64-transfers-32bit-regs", class_obscure, |
7915a72c AC |
5487 | &mips64_transfers_32bit_regs_p, _("\ |
5488 | Set compatibility with 64-bit MIPS target that transfers 32-bit quantities."), | |
5489 | _("\ | |
5490 | Show compatibility with 64-bit MIPS target that transfers 32-bit quantities."), | |
5491 | _("\ | |
719ec221 AC |
5492 | Use \"on\" to enable backward compatibility with older MIPS 64 GDB+target\n\ |
5493 | that would transfer 32 bits for some registers (e.g. SR, FSR) and\n\ | |
7915a72c | 5494 | 64 bits for others. Use \"off\" to disable compatibility mode"), |
2c5b56ce | 5495 | set_mips64_transfers_32bit_regs, |
7915a72c | 5496 | NULL, /* FIXME: i18n: Compatibility with 64-bit MIPS target that transfers 32-bit quantities is %s. */ |
7915a72c | 5497 | &setlist, &showlist); |
9ace0497 AC |
5498 | |
5499 | /* Debug this files internals. */ | |
6bcadd06 | 5500 | add_setshow_zinteger_cmd ("mips", class_maintenance, |
7915a72c AC |
5501 | &mips_debug, _("\ |
5502 | Set mips debugging."), _("\ | |
5503 | Show mips debugging."), _("\ | |
5504 | When non-zero, mips specific debugging is enabled."), | |
2c5b56ce | 5505 | NULL, |
7915a72c | 5506 | NULL, /* FIXME: i18n: Mips debugging is currently %s. */ |
6bcadd06 | 5507 | &setdebuglist, &showdebuglist); |
c906108c | 5508 | } |