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