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