Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Target-dependent code for the MIPS architecture, for GDB, the GNU Debugger. |
bf64bfd6 | 2 | |
cda5a58a | 3 | Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, |
16e109ca AC |
4 | 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software |
5 | 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 | |
24 | Foundation, Inc., 59 Temple Place - Suite 330, | |
25 | Boston, MA 02111-1307, 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" |
c906108c | 58 | |
8d5f9dcb DJ |
59 | static const struct objfile_data *mips_pdr_data; |
60 | ||
5bbcb741 | 61 | static struct type *mips_register_type (struct gdbarch *gdbarch, int regnum); |
e0f7ec59 | 62 | |
dd824b04 DJ |
63 | /* A useful bit in the CP0 status register (PS_REGNUM). */ |
64 | /* This bit is set if we are emulating 32-bit FPRs on a 64-bit chip. */ | |
65 | #define ST0_FR (1 << 26) | |
66 | ||
b0069a17 AC |
67 | /* The sizes of floating point registers. */ |
68 | ||
69 | enum | |
70 | { | |
71 | MIPS_FPU_SINGLE_REGSIZE = 4, | |
72 | MIPS_FPU_DOUBLE_REGSIZE = 8 | |
73 | }; | |
74 | ||
0dadbba0 | 75 | |
2e4ebe70 DJ |
76 | static const char *mips_abi_string; |
77 | ||
78 | static const char *mips_abi_strings[] = { | |
79 | "auto", | |
80 | "n32", | |
81 | "o32", | |
28d169de | 82 | "n64", |
2e4ebe70 DJ |
83 | "o64", |
84 | "eabi32", | |
85 | "eabi64", | |
86 | NULL | |
87 | }; | |
88 | ||
cce74817 | 89 | struct frame_extra_info |
6d82d43b AC |
90 | { |
91 | mips_extra_func_info_t proc_desc; | |
92 | int num_args; | |
93 | }; | |
cce74817 | 94 | |
d929b26f AC |
95 | /* Various MIPS ISA options (related to stack analysis) can be |
96 | overridden dynamically. Establish an enum/array for managing | |
97 | them. */ | |
98 | ||
53904c9e AC |
99 | static const char size_auto[] = "auto"; |
100 | static const char size_32[] = "32"; | |
101 | static const char size_64[] = "64"; | |
d929b26f | 102 | |
53904c9e | 103 | static const char *size_enums[] = { |
d929b26f AC |
104 | size_auto, |
105 | size_32, | |
106 | size_64, | |
a5ea2558 AC |
107 | 0 |
108 | }; | |
109 | ||
7a292a7a | 110 | /* Some MIPS boards don't support floating point while others only |
ceae6e75 | 111 | support single-precision floating-point operations. */ |
c906108c SS |
112 | |
113 | enum mips_fpu_type | |
6d82d43b AC |
114 | { |
115 | MIPS_FPU_DOUBLE, /* Full double precision floating point. */ | |
116 | MIPS_FPU_SINGLE, /* Single precision floating point (R4650). */ | |
117 | MIPS_FPU_NONE /* No floating point. */ | |
118 | }; | |
c906108c SS |
119 | |
120 | #ifndef MIPS_DEFAULT_FPU_TYPE | |
121 | #define MIPS_DEFAULT_FPU_TYPE MIPS_FPU_DOUBLE | |
122 | #endif | |
123 | static int mips_fpu_type_auto = 1; | |
124 | static enum mips_fpu_type mips_fpu_type = MIPS_DEFAULT_FPU_TYPE; | |
7a292a7a | 125 | |
9ace0497 | 126 | static int mips_debug = 0; |
7a292a7a | 127 | |
c2d11a7d JM |
128 | /* MIPS specific per-architecture information */ |
129 | struct gdbarch_tdep | |
6d82d43b AC |
130 | { |
131 | /* from the elf header */ | |
132 | int elf_flags; | |
133 | ||
134 | /* mips options */ | |
135 | enum mips_abi mips_abi; | |
136 | enum mips_abi found_abi; | |
137 | enum mips_fpu_type mips_fpu_type; | |
138 | int mips_last_arg_regnum; | |
139 | int mips_last_fp_arg_regnum; | |
6d82d43b AC |
140 | int default_mask_address_p; |
141 | /* Is the target using 64-bit raw integer registers but only | |
142 | storing a left-aligned 32-bit value in each? */ | |
143 | int mips64_transfers_32bit_regs_p; | |
144 | /* Indexes for various registers. IRIX and embedded have | |
145 | different values. This contains the "public" fields. Don't | |
146 | add any that do not need to be public. */ | |
147 | const struct mips_regnum *regnum; | |
148 | /* Register names table for the current register set. */ | |
149 | const char **mips_processor_reg_names; | |
150 | }; | |
c2d11a7d | 151 | |
fed7ba43 JB |
152 | static int |
153 | n32n64_floatformat_always_valid (const struct floatformat *fmt, | |
154 | const char *from) | |
155 | { | |
156 | return 1; | |
157 | } | |
158 | ||
159 | /* FIXME: brobecker/2004-08-08: Long Double values are 128 bit long. | |
160 | They are implemented as a pair of 64bit doubles where the high | |
161 | part holds the result of the operation rounded to double, and | |
162 | the low double holds the difference between the exact result and | |
163 | the rounded result. So "high" + "low" contains the result with | |
164 | added precision. Unfortunately, the floatformat structure used | |
165 | by GDB is not powerful enough to describe this format. As a temporary | |
166 | measure, we define a 128bit floatformat that only uses the high part. | |
167 | We lose a bit of precision but that's probably the best we can do | |
168 | for now with the current infrastructure. */ | |
169 | ||
170 | static const struct floatformat floatformat_n32n64_long_double_big = | |
171 | { | |
172 | floatformat_big, 128, 0, 1, 11, 1023, 2047, 12, 52, | |
173 | floatformat_intbit_no, | |
174 | "floatformat_ieee_double_big", | |
175 | n32n64_floatformat_always_valid | |
176 | }; | |
177 | ||
56cea623 AC |
178 | const struct mips_regnum * |
179 | mips_regnum (struct gdbarch *gdbarch) | |
180 | { | |
181 | return gdbarch_tdep (gdbarch)->regnum; | |
182 | } | |
183 | ||
184 | static int | |
185 | mips_fpa0_regnum (struct gdbarch *gdbarch) | |
186 | { | |
187 | return mips_regnum (gdbarch)->fp0 + 12; | |
188 | } | |
189 | ||
0dadbba0 | 190 | #define MIPS_EABI (gdbarch_tdep (current_gdbarch)->mips_abi == MIPS_ABI_EABI32 \ |
216a600b | 191 | || gdbarch_tdep (current_gdbarch)->mips_abi == MIPS_ABI_EABI64) |
c2d11a7d | 192 | |
c2d11a7d | 193 | #define MIPS_LAST_FP_ARG_REGNUM (gdbarch_tdep (current_gdbarch)->mips_last_fp_arg_regnum) |
c2d11a7d | 194 | |
c2d11a7d | 195 | #define MIPS_LAST_ARG_REGNUM (gdbarch_tdep (current_gdbarch)->mips_last_arg_regnum) |
c2d11a7d | 196 | |
c2d11a7d | 197 | #define MIPS_FPU_TYPE (gdbarch_tdep (current_gdbarch)->mips_fpu_type) |
c2d11a7d | 198 | |
95404a3e AC |
199 | /* MIPS16 function addresses are odd (bit 0 is set). Here are some |
200 | functions to test, set, or clear bit 0 of addresses. */ | |
201 | ||
202 | static CORE_ADDR | |
203 | is_mips16_addr (CORE_ADDR addr) | |
204 | { | |
205 | return ((addr) & 1); | |
206 | } | |
207 | ||
208 | static CORE_ADDR | |
209 | make_mips16_addr (CORE_ADDR addr) | |
210 | { | |
211 | return ((addr) | 1); | |
212 | } | |
213 | ||
214 | static CORE_ADDR | |
215 | unmake_mips16_addr (CORE_ADDR addr) | |
216 | { | |
217 | return ((addr) & ~1); | |
218 | } | |
219 | ||
22540ece AC |
220 | /* Return the contents of register REGNUM as a signed integer. */ |
221 | ||
222 | static LONGEST | |
223 | read_signed_register (int regnum) | |
224 | { | |
719ec221 | 225 | void *buf = alloca (register_size (current_gdbarch, regnum)); |
22540ece | 226 | deprecated_read_register_gen (regnum, buf); |
6d82d43b AC |
227 | return (extract_signed_integer |
228 | (buf, register_size (current_gdbarch, regnum))); | |
22540ece AC |
229 | } |
230 | ||
231 | static LONGEST | |
232 | read_signed_register_pid (int regnum, ptid_t ptid) | |
233 | { | |
234 | ptid_t save_ptid; | |
235 | LONGEST retval; | |
236 | ||
237 | if (ptid_equal (ptid, inferior_ptid)) | |
238 | return read_signed_register (regnum); | |
239 | ||
240 | save_ptid = inferior_ptid; | |
241 | ||
242 | inferior_ptid = ptid; | |
243 | ||
244 | retval = read_signed_register (regnum); | |
245 | ||
246 | inferior_ptid = save_ptid; | |
247 | ||
248 | return retval; | |
249 | } | |
250 | ||
d1973055 KB |
251 | /* Return the MIPS ABI associated with GDBARCH. */ |
252 | enum mips_abi | |
253 | mips_abi (struct gdbarch *gdbarch) | |
254 | { | |
255 | return gdbarch_tdep (gdbarch)->mips_abi; | |
256 | } | |
257 | ||
4246e332 | 258 | int |
1b13c4f6 | 259 | mips_isa_regsize (struct gdbarch *gdbarch) |
4246e332 AC |
260 | { |
261 | return (gdbarch_bfd_arch_info (gdbarch)->bits_per_word | |
262 | / gdbarch_bfd_arch_info (gdbarch)->bits_per_byte); | |
263 | } | |
264 | ||
480d3dd2 AC |
265 | /* Return the currently configured (or set) saved register size. */ |
266 | ||
1b13c4f6 | 267 | static const char *mips_abi_regsize_string = size_auto; |
480d3dd2 | 268 | |
d929b26f | 269 | static unsigned int |
13326b4e | 270 | mips_abi_regsize (struct gdbarch *gdbarch) |
d929b26f | 271 | { |
1b13c4f6 | 272 | if (mips_abi_regsize_string == size_auto) |
13326b4e AC |
273 | switch (mips_abi (gdbarch)) |
274 | { | |
275 | case MIPS_ABI_EABI32: | |
276 | case MIPS_ABI_O32: | |
277 | return 4; | |
278 | case MIPS_ABI_N32: | |
279 | case MIPS_ABI_N64: | |
280 | case MIPS_ABI_O64: | |
281 | case MIPS_ABI_EABI64: | |
282 | return 8; | |
283 | case MIPS_ABI_UNKNOWN: | |
284 | case MIPS_ABI_LAST: | |
285 | default: | |
286 | internal_error (__FILE__, __LINE__, "bad switch"); | |
287 | } | |
1b13c4f6 | 288 | else if (mips_abi_regsize_string == size_64) |
d929b26f | 289 | return 8; |
1b13c4f6 | 290 | else /* if (mips_abi_regsize_string == size_32) */ |
d929b26f AC |
291 | return 4; |
292 | } | |
293 | ||
71b8ef93 | 294 | /* Functions for setting and testing a bit in a minimal symbol that |
5a89d8aa | 295 | marks it as 16-bit function. The MSB of the minimal symbol's |
f594e5e9 | 296 | "info" field is used for this purpose. |
5a89d8aa MS |
297 | |
298 | ELF_MAKE_MSYMBOL_SPECIAL tests whether an ELF symbol is "special", | |
299 | i.e. refers to a 16-bit function, and sets a "special" bit in a | |
300 | minimal symbol to mark it as a 16-bit function | |
301 | ||
f594e5e9 | 302 | MSYMBOL_IS_SPECIAL tests the "special" bit in a minimal symbol */ |
5a89d8aa | 303 | |
5a89d8aa | 304 | static void |
6d82d43b AC |
305 | mips_elf_make_msymbol_special (asymbol * sym, struct minimal_symbol *msym) |
306 | { | |
307 | if (((elf_symbol_type *) (sym))->internal_elf_sym.st_other == STO_MIPS16) | |
308 | { | |
309 | MSYMBOL_INFO (msym) = (char *) | |
310 | (((long) MSYMBOL_INFO (msym)) | 0x80000000); | |
311 | SYMBOL_VALUE_ADDRESS (msym) |= 1; | |
312 | } | |
5a89d8aa MS |
313 | } |
314 | ||
71b8ef93 MS |
315 | static int |
316 | msymbol_is_special (struct minimal_symbol *msym) | |
317 | { | |
318 | return (((long) MSYMBOL_INFO (msym) & 0x80000000) != 0); | |
319 | } | |
320 | ||
88658117 AC |
321 | /* XFER a value from the big/little/left end of the register. |
322 | Depending on the size of the value it might occupy the entire | |
323 | register or just part of it. Make an allowance for this, aligning | |
324 | things accordingly. */ | |
325 | ||
326 | static void | |
327 | mips_xfer_register (struct regcache *regcache, int reg_num, int length, | |
6d82d43b AC |
328 | enum bfd_endian endian, bfd_byte * in, |
329 | const bfd_byte * out, int buf_offset) | |
88658117 | 330 | { |
88658117 | 331 | int reg_offset = 0; |
a4b8ebc8 | 332 | gdb_assert (reg_num >= NUM_REGS); |
cb1d2653 AC |
333 | /* Need to transfer the left or right part of the register, based on |
334 | the targets byte order. */ | |
88658117 AC |
335 | switch (endian) |
336 | { | |
337 | case BFD_ENDIAN_BIG: | |
719ec221 | 338 | reg_offset = register_size (current_gdbarch, reg_num) - length; |
88658117 AC |
339 | break; |
340 | case BFD_ENDIAN_LITTLE: | |
341 | reg_offset = 0; | |
342 | break; | |
6d82d43b | 343 | case BFD_ENDIAN_UNKNOWN: /* Indicates no alignment. */ |
88658117 AC |
344 | reg_offset = 0; |
345 | break; | |
346 | default: | |
347 | internal_error (__FILE__, __LINE__, "bad switch"); | |
348 | } | |
349 | if (mips_debug) | |
cb1d2653 AC |
350 | fprintf_unfiltered (gdb_stderr, |
351 | "xfer $%d, reg offset %d, buf offset %d, length %d, ", | |
352 | reg_num, reg_offset, buf_offset, length); | |
88658117 AC |
353 | if (mips_debug && out != NULL) |
354 | { | |
355 | int i; | |
cb1d2653 | 356 | fprintf_unfiltered (gdb_stdlog, "out "); |
88658117 | 357 | for (i = 0; i < length; i++) |
cb1d2653 | 358 | fprintf_unfiltered (gdb_stdlog, "%02x", out[buf_offset + i]); |
88658117 AC |
359 | } |
360 | if (in != NULL) | |
6d82d43b AC |
361 | regcache_cooked_read_part (regcache, reg_num, reg_offset, length, |
362 | in + buf_offset); | |
88658117 | 363 | if (out != NULL) |
6d82d43b AC |
364 | regcache_cooked_write_part (regcache, reg_num, reg_offset, length, |
365 | out + buf_offset); | |
88658117 AC |
366 | if (mips_debug && in != NULL) |
367 | { | |
368 | int i; | |
cb1d2653 | 369 | fprintf_unfiltered (gdb_stdlog, "in "); |
88658117 | 370 | for (i = 0; i < length; i++) |
cb1d2653 | 371 | fprintf_unfiltered (gdb_stdlog, "%02x", in[buf_offset + i]); |
88658117 AC |
372 | } |
373 | if (mips_debug) | |
374 | fprintf_unfiltered (gdb_stdlog, "\n"); | |
375 | } | |
376 | ||
dd824b04 DJ |
377 | /* Determine if a MIPS3 or later cpu is operating in MIPS{1,2} FPU |
378 | compatiblity mode. A return value of 1 means that we have | |
379 | physical 64-bit registers, but should treat them as 32-bit registers. */ | |
380 | ||
381 | static int | |
382 | mips2_fp_compat (void) | |
383 | { | |
384 | /* MIPS1 and MIPS2 have only 32 bit FPRs, and the FR bit is not | |
385 | meaningful. */ | |
6d82d43b AC |
386 | if (register_size (current_gdbarch, mips_regnum (current_gdbarch)->fp0) == |
387 | 4) | |
dd824b04 DJ |
388 | return 0; |
389 | ||
390 | #if 0 | |
391 | /* FIXME drow 2002-03-10: This is disabled until we can do it consistently, | |
392 | in all the places we deal with FP registers. PR gdb/413. */ | |
393 | /* Otherwise check the FR bit in the status register - it controls | |
394 | the FP compatiblity mode. If it is clear we are in compatibility | |
395 | mode. */ | |
396 | if ((read_register (PS_REGNUM) & ST0_FR) == 0) | |
397 | return 1; | |
398 | #endif | |
361d1df0 | 399 | |
dd824b04 DJ |
400 | return 0; |
401 | } | |
402 | ||
d929b26f | 403 | /* The amount of space reserved on the stack for registers. This is |
1b13c4f6 | 404 | different to MIPS_ABI_REGSIZE as it determines the alignment of |
d929b26f AC |
405 | data allocated after the registers have run out. */ |
406 | ||
53904c9e | 407 | static const char *mips_stack_argsize_string = size_auto; |
d929b26f AC |
408 | |
409 | static unsigned int | |
13326b4e | 410 | mips_stack_argsize (struct gdbarch *gdbarch) |
d929b26f AC |
411 | { |
412 | if (mips_stack_argsize_string == size_auto) | |
13326b4e | 413 | return mips_abi_regsize (gdbarch); |
d929b26f AC |
414 | else if (mips_stack_argsize_string == size_64) |
415 | return 8; | |
6d82d43b | 416 | else /* if (mips_stack_argsize_string == size_32) */ |
d929b26f AC |
417 | return 4; |
418 | } | |
419 | ||
7a292a7a | 420 | #define VM_MIN_ADDRESS (CORE_ADDR)0x400000 |
c906108c | 421 | |
c9343fd1 | 422 | struct mips_frame_cache; |
570b8f7c | 423 | static mips_extra_func_info_t heuristic_proc_desc (CORE_ADDR, CORE_ADDR, |
c9343fd1 AC |
424 | struct frame_info *, |
425 | struct mips_frame_cache *); | |
eec63939 AC |
426 | static mips_extra_func_info_t non_heuristic_proc_desc (CORE_ADDR pc, |
427 | CORE_ADDR *addrptr); | |
c906108c | 428 | |
a14ed312 | 429 | static CORE_ADDR heuristic_proc_start (CORE_ADDR); |
c906108c | 430 | |
a14ed312 | 431 | static CORE_ADDR read_next_frame_reg (struct frame_info *, int); |
c906108c | 432 | |
a14ed312 | 433 | static void reinit_frame_cache_sfunc (char *, int, struct cmd_list_element *); |
c906108c | 434 | |
177f84a3 | 435 | static CORE_ADDR after_prologue (CORE_ADDR pc); |
c906108c | 436 | |
67b2c998 DJ |
437 | static struct type *mips_float_register_type (void); |
438 | static struct type *mips_double_register_type (void); | |
439 | ||
acdb74a0 AC |
440 | /* The list of available "set mips " and "show mips " commands */ |
441 | ||
442 | static struct cmd_list_element *setmipscmdlist = NULL; | |
443 | static struct cmd_list_element *showmipscmdlist = NULL; | |
444 | ||
5e2e9765 KB |
445 | /* Integer registers 0 thru 31 are handled explicitly by |
446 | mips_register_name(). Processor specific registers 32 and above | |
691c0433 AC |
447 | are listed in the followign tables. */ |
448 | ||
6d82d43b AC |
449 | enum |
450 | { NUM_MIPS_PROCESSOR_REGS = (90 - 32) }; | |
691c0433 AC |
451 | |
452 | /* Generic MIPS. */ | |
453 | ||
454 | static const char *mips_generic_reg_names[NUM_MIPS_PROCESSOR_REGS] = { | |
6d82d43b AC |
455 | "sr", "lo", "hi", "bad", "cause", "pc", |
456 | "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", | |
457 | "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", | |
458 | "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23", | |
459 | "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", | |
460 | "fsr", "fir", "" /*"fp" */ , "", | |
461 | "", "", "", "", "", "", "", "", | |
462 | "", "", "", "", "", "", "", "", | |
691c0433 AC |
463 | }; |
464 | ||
465 | /* Names of IDT R3041 registers. */ | |
466 | ||
467 | static const char *mips_r3041_reg_names[] = { | |
6d82d43b AC |
468 | "sr", "lo", "hi", "bad", "cause", "pc", |
469 | "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", | |
470 | "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", | |
471 | "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23", | |
472 | "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", | |
473 | "fsr", "fir", "", /*"fp" */ "", | |
474 | "", "", "bus", "ccfg", "", "", "", "", | |
475 | "", "", "port", "cmp", "", "", "epc", "prid", | |
691c0433 AC |
476 | }; |
477 | ||
478 | /* Names of tx39 registers. */ | |
479 | ||
480 | static const char *mips_tx39_reg_names[NUM_MIPS_PROCESSOR_REGS] = { | |
6d82d43b AC |
481 | "sr", "lo", "hi", "bad", "cause", "pc", |
482 | "", "", "", "", "", "", "", "", | |
483 | "", "", "", "", "", "", "", "", | |
484 | "", "", "", "", "", "", "", "", | |
485 | "", "", "", "", "", "", "", "", | |
486 | "", "", "", "", | |
487 | "", "", "", "", "", "", "", "", | |
488 | "", "", "config", "cache", "debug", "depc", "epc", "" | |
691c0433 AC |
489 | }; |
490 | ||
491 | /* Names of IRIX registers. */ | |
492 | static const char *mips_irix_reg_names[NUM_MIPS_PROCESSOR_REGS] = { | |
6d82d43b AC |
493 | "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", |
494 | "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", | |
495 | "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23", | |
496 | "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", | |
497 | "pc", "cause", "bad", "hi", "lo", "fsr", "fir" | |
691c0433 AC |
498 | }; |
499 | ||
cce74817 | 500 | |
5e2e9765 | 501 | /* Return the name of the register corresponding to REGNO. */ |
5a89d8aa | 502 | static const char * |
5e2e9765 | 503 | mips_register_name (int regno) |
cce74817 | 504 | { |
691c0433 | 505 | struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); |
5e2e9765 KB |
506 | /* GPR names for all ABIs other than n32/n64. */ |
507 | static char *mips_gpr_names[] = { | |
6d82d43b AC |
508 | "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3", |
509 | "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", | |
510 | "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7", | |
511 | "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra", | |
5e2e9765 KB |
512 | }; |
513 | ||
514 | /* GPR names for n32 and n64 ABIs. */ | |
515 | static char *mips_n32_n64_gpr_names[] = { | |
6d82d43b AC |
516 | "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3", |
517 | "a4", "a5", "a6", "a7", "t0", "t1", "t2", "t3", | |
518 | "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7", | |
519 | "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra" | |
5e2e9765 KB |
520 | }; |
521 | ||
522 | enum mips_abi abi = mips_abi (current_gdbarch); | |
523 | ||
a4b8ebc8 AC |
524 | /* Map [NUM_REGS .. 2*NUM_REGS) onto the raw registers, but then |
525 | don't make the raw register names visible. */ | |
526 | int rawnum = regno % NUM_REGS; | |
527 | if (regno < NUM_REGS) | |
528 | return ""; | |
529 | ||
5e2e9765 KB |
530 | /* The MIPS integer registers are always mapped from 0 to 31. The |
531 | names of the registers (which reflects the conventions regarding | |
532 | register use) vary depending on the ABI. */ | |
a4b8ebc8 | 533 | if (0 <= rawnum && rawnum < 32) |
5e2e9765 KB |
534 | { |
535 | if (abi == MIPS_ABI_N32 || abi == MIPS_ABI_N64) | |
a4b8ebc8 | 536 | return mips_n32_n64_gpr_names[rawnum]; |
5e2e9765 | 537 | else |
a4b8ebc8 | 538 | return mips_gpr_names[rawnum]; |
5e2e9765 | 539 | } |
a4b8ebc8 | 540 | else if (32 <= rawnum && rawnum < NUM_REGS) |
691c0433 AC |
541 | { |
542 | gdb_assert (rawnum - 32 < NUM_MIPS_PROCESSOR_REGS); | |
543 | return tdep->mips_processor_reg_names[rawnum - 32]; | |
544 | } | |
5e2e9765 KB |
545 | else |
546 | internal_error (__FILE__, __LINE__, | |
a4b8ebc8 | 547 | "mips_register_name: bad register number %d", rawnum); |
cce74817 | 548 | } |
5e2e9765 | 549 | |
a4b8ebc8 | 550 | /* Return the groups that a MIPS register can be categorised into. */ |
c5aa993b | 551 | |
a4b8ebc8 AC |
552 | static int |
553 | mips_register_reggroup_p (struct gdbarch *gdbarch, int regnum, | |
554 | struct reggroup *reggroup) | |
555 | { | |
556 | int vector_p; | |
557 | int float_p; | |
558 | int raw_p; | |
559 | int rawnum = regnum % NUM_REGS; | |
560 | int pseudo = regnum / NUM_REGS; | |
561 | if (reggroup == all_reggroup) | |
562 | return pseudo; | |
563 | vector_p = TYPE_VECTOR (register_type (gdbarch, regnum)); | |
564 | float_p = TYPE_CODE (register_type (gdbarch, regnum)) == TYPE_CODE_FLT; | |
565 | /* FIXME: cagney/2003-04-13: Can't yet use gdbarch_num_regs | |
566 | (gdbarch), as not all architectures are multi-arch. */ | |
567 | raw_p = rawnum < NUM_REGS; | |
6d82d43b | 568 | if (REGISTER_NAME (regnum) == NULL || REGISTER_NAME (regnum)[0] == '\0') |
a4b8ebc8 AC |
569 | return 0; |
570 | if (reggroup == float_reggroup) | |
571 | return float_p && pseudo; | |
572 | if (reggroup == vector_reggroup) | |
573 | return vector_p && pseudo; | |
574 | if (reggroup == general_reggroup) | |
575 | return (!vector_p && !float_p) && pseudo; | |
576 | /* Save the pseudo registers. Need to make certain that any code | |
577 | extracting register values from a saved register cache also uses | |
578 | pseudo registers. */ | |
579 | if (reggroup == save_reggroup) | |
580 | return raw_p && pseudo; | |
581 | /* Restore the same pseudo register. */ | |
582 | if (reggroup == restore_reggroup) | |
583 | return raw_p && pseudo; | |
6d82d43b | 584 | return 0; |
a4b8ebc8 AC |
585 | } |
586 | ||
587 | /* Map the symbol table registers which live in the range [1 * | |
588 | NUM_REGS .. 2 * NUM_REGS) back onto the corresponding raw | |
47ebcfbe | 589 | registers. Take care of alignment and size problems. */ |
c5aa993b | 590 | |
a4b8ebc8 AC |
591 | static void |
592 | mips_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache, | |
593 | int cookednum, void *buf) | |
594 | { | |
47ebcfbe | 595 | int rawnum = cookednum % NUM_REGS; |
a4b8ebc8 | 596 | gdb_assert (cookednum >= NUM_REGS && cookednum < 2 * NUM_REGS); |
47ebcfbe | 597 | if (register_size (gdbarch, rawnum) == register_size (gdbarch, cookednum)) |
de38af99 | 598 | regcache_raw_read (regcache, rawnum, buf); |
6d82d43b AC |
599 | else if (register_size (gdbarch, rawnum) > |
600 | register_size (gdbarch, cookednum)) | |
47ebcfbe AC |
601 | { |
602 | if (gdbarch_tdep (gdbarch)->mips64_transfers_32bit_regs_p | |
603 | || TARGET_BYTE_ORDER == BFD_ENDIAN_LITTLE) | |
604 | regcache_raw_read_part (regcache, rawnum, 0, 4, buf); | |
605 | else | |
606 | regcache_raw_read_part (regcache, rawnum, 4, 4, buf); | |
607 | } | |
608 | else | |
609 | internal_error (__FILE__, __LINE__, "bad register size"); | |
a4b8ebc8 AC |
610 | } |
611 | ||
612 | static void | |
6d82d43b AC |
613 | mips_pseudo_register_write (struct gdbarch *gdbarch, |
614 | struct regcache *regcache, int cookednum, | |
615 | const void *buf) | |
a4b8ebc8 | 616 | { |
47ebcfbe | 617 | int rawnum = cookednum % NUM_REGS; |
a4b8ebc8 | 618 | gdb_assert (cookednum >= NUM_REGS && cookednum < 2 * NUM_REGS); |
47ebcfbe | 619 | if (register_size (gdbarch, rawnum) == register_size (gdbarch, cookednum)) |
de38af99 | 620 | regcache_raw_write (regcache, rawnum, buf); |
6d82d43b AC |
621 | else if (register_size (gdbarch, rawnum) > |
622 | register_size (gdbarch, cookednum)) | |
47ebcfbe AC |
623 | { |
624 | if (gdbarch_tdep (gdbarch)->mips64_transfers_32bit_regs_p | |
625 | || TARGET_BYTE_ORDER == BFD_ENDIAN_LITTLE) | |
626 | regcache_raw_write_part (regcache, rawnum, 0, 4, buf); | |
627 | else | |
628 | regcache_raw_write_part (regcache, rawnum, 4, 4, buf); | |
629 | } | |
630 | else | |
631 | internal_error (__FILE__, __LINE__, "bad register size"); | |
a4b8ebc8 | 632 | } |
c5aa993b | 633 | |
c906108c | 634 | /* Table to translate MIPS16 register field to actual register number. */ |
6d82d43b | 635 | static int mips16_to_32_reg[8] = { 16, 17, 2, 3, 4, 5, 6, 7 }; |
c906108c SS |
636 | |
637 | /* Heuristic_proc_start may hunt through the text section for a long | |
638 | time across a 2400 baud serial line. Allows the user to limit this | |
639 | search. */ | |
640 | ||
641 | static unsigned int heuristic_fence_post = 0; | |
642 | ||
c5aa993b JM |
643 | #define PROC_LOW_ADDR(proc) ((proc)->pdr.adr) /* least address */ |
644 | #define PROC_HIGH_ADDR(proc) ((proc)->high_addr) /* upper address bound */ | |
c906108c SS |
645 | #define PROC_FRAME_OFFSET(proc) ((proc)->pdr.frameoffset) |
646 | #define PROC_FRAME_REG(proc) ((proc)->pdr.framereg) | |
647 | #define PROC_FRAME_ADJUST(proc) ((proc)->frame_adjust) | |
648 | #define PROC_REG_MASK(proc) ((proc)->pdr.regmask) | |
649 | #define PROC_FREG_MASK(proc) ((proc)->pdr.fregmask) | |
650 | #define PROC_REG_OFFSET(proc) ((proc)->pdr.regoffset) | |
651 | #define PROC_FREG_OFFSET(proc) ((proc)->pdr.fregoffset) | |
652 | #define PROC_PC_REG(proc) ((proc)->pdr.pcreg) | |
6c0d6680 DJ |
653 | /* FIXME drow/2002-06-10: If a pointer on the host is bigger than a long, |
654 | this will corrupt pdr.iline. Fortunately we don't use it. */ | |
c906108c SS |
655 | #define PROC_SYMBOL(proc) (*(struct symbol**)&(proc)->pdr.isym) |
656 | #define _PROC_MAGIC_ 0x0F0F0F0F | |
c906108c | 657 | |
46cd78fb | 658 | /* Number of bytes of storage in the actual machine representation for |
719ec221 AC |
659 | register N. NOTE: This defines the pseudo register type so need to |
660 | rebuild the architecture vector. */ | |
43e526b9 JM |
661 | |
662 | static int mips64_transfers_32bit_regs_p = 0; | |
663 | ||
719ec221 AC |
664 | static void |
665 | set_mips64_transfers_32bit_regs (char *args, int from_tty, | |
666 | struct cmd_list_element *c) | |
43e526b9 | 667 | { |
719ec221 AC |
668 | struct gdbarch_info info; |
669 | gdbarch_info_init (&info); | |
670 | /* FIXME: cagney/2003-11-15: Should be setting a field in "info" | |
671 | instead of relying on globals. Doing that would let generic code | |
672 | handle the search for this specific architecture. */ | |
673 | if (!gdbarch_update_p (info)) | |
a4b8ebc8 | 674 | { |
719ec221 AC |
675 | mips64_transfers_32bit_regs_p = 0; |
676 | error ("32-bit compatibility mode not supported"); | |
a4b8ebc8 | 677 | } |
a4b8ebc8 AC |
678 | } |
679 | ||
47ebcfbe | 680 | /* Convert to/from a register and the corresponding memory value. */ |
43e526b9 | 681 | |
ff2e87ac AC |
682 | static int |
683 | mips_convert_register_p (int regnum, struct type *type) | |
684 | { | |
685 | return (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG | |
719ec221 | 686 | && register_size (current_gdbarch, regnum) == 4 |
87783b8b AC |
687 | && (regnum % NUM_REGS) >= mips_regnum (current_gdbarch)->fp0 |
688 | && (regnum % NUM_REGS) < mips_regnum (current_gdbarch)->fp0 + 32 | |
6d82d43b | 689 | && TYPE_CODE (type) == TYPE_CODE_FLT && TYPE_LENGTH (type) == 8); |
ff2e87ac AC |
690 | } |
691 | ||
42c466d7 | 692 | static void |
ff2e87ac AC |
693 | mips_register_to_value (struct frame_info *frame, int regnum, |
694 | struct type *type, void *to) | |
102182a9 | 695 | { |
7f5f525d AC |
696 | get_frame_register (frame, regnum + 0, (char *) to + 4); |
697 | get_frame_register (frame, regnum + 1, (char *) to + 0); | |
102182a9 MS |
698 | } |
699 | ||
42c466d7 | 700 | static void |
ff2e87ac AC |
701 | mips_value_to_register (struct frame_info *frame, int regnum, |
702 | struct type *type, const void *from) | |
102182a9 | 703 | { |
ff2e87ac AC |
704 | put_frame_register (frame, regnum + 0, (const char *) from + 4); |
705 | put_frame_register (frame, regnum + 1, (const char *) from + 0); | |
102182a9 MS |
706 | } |
707 | ||
a4b8ebc8 AC |
708 | /* Return the GDB type object for the "standard" data type of data in |
709 | register REG. */ | |
78fde5f8 KB |
710 | |
711 | static struct type * | |
a4b8ebc8 AC |
712 | mips_register_type (struct gdbarch *gdbarch, int regnum) |
713 | { | |
5ef80fb0 | 714 | gdb_assert (regnum >= 0 && regnum < 2 * NUM_REGS); |
56cea623 AC |
715 | if ((regnum % NUM_REGS) >= mips_regnum (current_gdbarch)->fp0 |
716 | && (regnum % NUM_REGS) < mips_regnum (current_gdbarch)->fp0 + 32) | |
a6425924 | 717 | { |
5ef80fb0 | 718 | /* The floating-point registers raw, or cooked, always match |
1b13c4f6 | 719 | mips_isa_regsize(), and also map 1:1, byte for byte. */ |
5ef80fb0 AC |
720 | switch (gdbarch_byte_order (gdbarch)) |
721 | { | |
722 | case BFD_ENDIAN_BIG: | |
1b13c4f6 | 723 | if (mips_isa_regsize (gdbarch) == 4) |
5ef80fb0 AC |
724 | return builtin_type_ieee_single_big; |
725 | else | |
726 | return builtin_type_ieee_double_big; | |
727 | case BFD_ENDIAN_LITTLE: | |
1b13c4f6 | 728 | if (mips_isa_regsize (gdbarch) == 4) |
5ef80fb0 AC |
729 | return builtin_type_ieee_single_little; |
730 | else | |
731 | return builtin_type_ieee_double_little; | |
732 | case BFD_ENDIAN_UNKNOWN: | |
733 | default: | |
734 | internal_error (__FILE__, __LINE__, "bad switch"); | |
735 | } | |
a6425924 | 736 | } |
d5ac5a39 AC |
737 | else if (regnum < NUM_REGS) |
738 | { | |
739 | /* The raw or ISA registers. These are all sized according to | |
740 | the ISA regsize. */ | |
741 | if (mips_isa_regsize (gdbarch) == 4) | |
742 | return builtin_type_int32; | |
743 | else | |
744 | return builtin_type_int64; | |
745 | } | |
78fde5f8 | 746 | else |
d5ac5a39 AC |
747 | { |
748 | /* The cooked or ABI registers. These are sized according to | |
749 | the ABI (with a few complications). */ | |
750 | if (regnum >= (NUM_REGS | |
751 | + mips_regnum (current_gdbarch)->fp_control_status) | |
752 | && regnum <= NUM_REGS + LAST_EMBED_REGNUM) | |
753 | /* The pseudo/cooked view of the embedded registers is always | |
754 | 32-bit. The raw view is handled below. */ | |
755 | return builtin_type_int32; | |
756 | else if (gdbarch_tdep (gdbarch)->mips64_transfers_32bit_regs_p) | |
757 | /* The target, while possibly using a 64-bit register buffer, | |
758 | is only transfering 32-bits of each integer register. | |
759 | Reflect this in the cooked/pseudo (ABI) register value. */ | |
760 | return builtin_type_int32; | |
761 | else if (mips_abi_regsize (gdbarch) == 4) | |
762 | /* The ABI is restricted to 32-bit registers (the ISA could be | |
763 | 32- or 64-bit). */ | |
764 | return builtin_type_int32; | |
765 | else | |
766 | /* 64-bit ABI. */ | |
767 | return builtin_type_int64; | |
768 | } | |
78fde5f8 KB |
769 | } |
770 | ||
bcb0cc15 MS |
771 | /* TARGET_READ_SP -- Remove useless bits from the stack pointer. */ |
772 | ||
773 | static CORE_ADDR | |
774 | mips_read_sp (void) | |
775 | { | |
f10683bb | 776 | return read_signed_register (MIPS_SP_REGNUM); |
bcb0cc15 MS |
777 | } |
778 | ||
c906108c | 779 | /* Should the upper word of 64-bit addresses be zeroed? */ |
7f19b9a2 | 780 | enum auto_boolean mask_address_var = AUTO_BOOLEAN_AUTO; |
4014092b AC |
781 | |
782 | static int | |
480d3dd2 | 783 | mips_mask_address_p (struct gdbarch_tdep *tdep) |
4014092b AC |
784 | { |
785 | switch (mask_address_var) | |
786 | { | |
7f19b9a2 | 787 | case AUTO_BOOLEAN_TRUE: |
4014092b | 788 | return 1; |
7f19b9a2 | 789 | case AUTO_BOOLEAN_FALSE: |
4014092b AC |
790 | return 0; |
791 | break; | |
7f19b9a2 | 792 | case AUTO_BOOLEAN_AUTO: |
480d3dd2 | 793 | return tdep->default_mask_address_p; |
4014092b | 794 | default: |
6d82d43b | 795 | internal_error (__FILE__, __LINE__, "mips_mask_address_p: bad switch"); |
4014092b | 796 | return -1; |
361d1df0 | 797 | } |
4014092b AC |
798 | } |
799 | ||
800 | static void | |
e9e68a56 | 801 | show_mask_address (char *cmd, int from_tty, struct cmd_list_element *c) |
4014092b | 802 | { |
480d3dd2 | 803 | struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); |
4014092b AC |
804 | switch (mask_address_var) |
805 | { | |
7f19b9a2 | 806 | case AUTO_BOOLEAN_TRUE: |
4014092b AC |
807 | printf_filtered ("The 32 bit mips address mask is enabled\n"); |
808 | break; | |
7f19b9a2 | 809 | case AUTO_BOOLEAN_FALSE: |
4014092b AC |
810 | printf_filtered ("The 32 bit mips address mask is disabled\n"); |
811 | break; | |
7f19b9a2 | 812 | case AUTO_BOOLEAN_AUTO: |
6d82d43b AC |
813 | printf_filtered |
814 | ("The 32 bit address mask is set automatically. Currently %s\n", | |
815 | mips_mask_address_p (tdep) ? "enabled" : "disabled"); | |
4014092b AC |
816 | break; |
817 | default: | |
6d82d43b | 818 | internal_error (__FILE__, __LINE__, "show_mask_address: bad switch"); |
4014092b | 819 | break; |
361d1df0 | 820 | } |
4014092b | 821 | } |
c906108c | 822 | |
c906108c SS |
823 | /* Tell if the program counter value in MEMADDR is in a MIPS16 function. */ |
824 | ||
825 | static int | |
826 | pc_is_mips16 (bfd_vma memaddr) | |
827 | { | |
828 | struct minimal_symbol *sym; | |
829 | ||
830 | /* If bit 0 of the address is set, assume this is a MIPS16 address. */ | |
95404a3e | 831 | if (is_mips16_addr (memaddr)) |
c906108c SS |
832 | return 1; |
833 | ||
834 | /* A flag indicating that this is a MIPS16 function is stored by elfread.c in | |
835 | the high bit of the info field. Use this to decide if the function is | |
836 | MIPS16 or normal MIPS. */ | |
837 | sym = lookup_minimal_symbol_by_pc (memaddr); | |
838 | if (sym) | |
71b8ef93 | 839 | return msymbol_is_special (sym); |
c906108c SS |
840 | else |
841 | return 0; | |
842 | } | |
843 | ||
b2fa5097 | 844 | /* MIPS believes that the PC has a sign extended value. Perhaps the |
6c997a34 AC |
845 | all registers should be sign extended for simplicity? */ |
846 | ||
847 | static CORE_ADDR | |
39f77062 | 848 | mips_read_pc (ptid_t ptid) |
6c997a34 | 849 | { |
b6cb9035 AC |
850 | return read_signed_register_pid (mips_regnum (current_gdbarch)->pc, ptid); |
851 | } | |
852 | ||
58dfe9ff AC |
853 | static CORE_ADDR |
854 | mips_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame) | |
855 | { | |
edfae063 AC |
856 | return frame_unwind_register_signed (next_frame, |
857 | NUM_REGS + mips_regnum (gdbarch)->pc); | |
858 | } | |
859 | ||
860 | /* Assuming NEXT_FRAME->prev is a dummy, return the frame ID of that | |
861 | dummy frame. The frame ID's base needs to match the TOS value | |
862 | saved by save_dummy_frame_tos(), and the PC match the dummy frame's | |
863 | breakpoint. */ | |
864 | ||
865 | static struct frame_id | |
866 | mips_unwind_dummy_id (struct gdbarch *gdbarch, struct frame_info *next_frame) | |
867 | { | |
f10683bb | 868 | return frame_id_build (frame_unwind_register_signed (next_frame, NUM_REGS + MIPS_SP_REGNUM), |
edfae063 | 869 | frame_pc_unwind (next_frame)); |
58dfe9ff AC |
870 | } |
871 | ||
b6cb9035 AC |
872 | static void |
873 | mips_write_pc (CORE_ADDR pc, ptid_t ptid) | |
874 | { | |
875 | write_register_pid (mips_regnum (current_gdbarch)->pc, pc, ptid); | |
6c997a34 | 876 | } |
c906108c SS |
877 | |
878 | /* This returns the PC of the first inst after the prologue. If we can't | |
879 | find the prologue, then return 0. */ | |
880 | ||
881 | static CORE_ADDR | |
177f84a3 | 882 | after_prologue (CORE_ADDR pc) |
c906108c | 883 | { |
177f84a3 | 884 | mips_extra_func_info_t proc_desc; |
c906108c SS |
885 | struct symtab_and_line sal; |
886 | CORE_ADDR func_addr, func_end; | |
283be873 AC |
887 | CORE_ADDR startaddr = 0; |
888 | ||
889 | /* Pass a NULL next_frame to heuristic_proc_desc. We should not | |
890 | attempt to read the stack pointer from the current machine state, | |
891 | because the current machine state has nothing to do with the | |
892 | information we need from the proc_desc; and the process may or | |
893 | may not exist right now. */ | |
894 | proc_desc = non_heuristic_proc_desc (pc, &startaddr); | |
895 | if (proc_desc) | |
896 | { | |
897 | /* IF this is the topmost frame AND (this proc does not have | |
898 | debugging information OR the PC is in the procedure prologue) | |
899 | THEN create a "heuristic" proc_desc (by analyzing the actual | |
900 | code) to replace the "official" proc_desc. */ | |
901 | struct symtab_and_line val; | |
fb603883 | 902 | if (PROC_SYMBOL (proc_desc)) |
283be873 AC |
903 | { |
904 | val = find_pc_line (BLOCK_START | |
fb603883 AC |
905 | (SYMBOL_BLOCK_VALUE (PROC_SYMBOL (proc_desc))), |
906 | 0); | |
283be873 AC |
907 | val.pc = val.end ? val.end : pc; |
908 | } | |
fb603883 | 909 | if (!PROC_SYMBOL (proc_desc) || pc < val.pc) |
283be873 AC |
910 | { |
911 | mips_extra_func_info_t found_heuristic = | |
c9343fd1 | 912 | heuristic_proc_desc (PROC_LOW_ADDR (proc_desc), pc, NULL, NULL); |
283be873 AC |
913 | if (found_heuristic) |
914 | proc_desc = found_heuristic; | |
915 | } | |
916 | } | |
917 | else | |
918 | { | |
919 | if (startaddr == 0) | |
920 | startaddr = heuristic_proc_start (pc); | |
c906108c | 921 | |
c9343fd1 | 922 | proc_desc = heuristic_proc_desc (startaddr, pc, NULL, NULL); |
283be873 | 923 | } |
c906108c SS |
924 | |
925 | if (proc_desc) | |
926 | { | |
927 | /* If function is frameless, then we need to do it the hard way. I | |
c5aa993b | 928 | strongly suspect that frameless always means prologueless... */ |
f10683bb | 929 | if (PROC_FRAME_REG (proc_desc) == MIPS_SP_REGNUM |
c906108c SS |
930 | && PROC_FRAME_OFFSET (proc_desc) == 0) |
931 | return 0; | |
932 | } | |
933 | ||
934 | if (!find_pc_partial_function (pc, NULL, &func_addr, &func_end)) | |
935 | return 0; /* Unknown */ | |
936 | ||
937 | sal = find_pc_line (func_addr, 0); | |
938 | ||
939 | if (sal.end < func_end) | |
940 | return sal.end; | |
941 | ||
942 | /* The line after the prologue is after the end of the function. In this | |
943 | case, tell the caller to find the prologue the hard way. */ | |
944 | ||
945 | return 0; | |
946 | } | |
947 | ||
948 | /* Decode a MIPS32 instruction that saves a register in the stack, and | |
949 | set the appropriate bit in the general register mask or float register mask | |
950 | to indicate which register is saved. This is a helper function | |
951 | for mips_find_saved_regs. */ | |
952 | ||
953 | static void | |
acdb74a0 AC |
954 | mips32_decode_reg_save (t_inst inst, unsigned long *gen_mask, |
955 | unsigned long *float_mask) | |
c906108c SS |
956 | { |
957 | int reg; | |
958 | ||
6d82d43b | 959 | if ((inst & 0xffe00000) == 0xafa00000 /* sw reg,n($sp) */ |
c906108c SS |
960 | || (inst & 0xffe00000) == 0xafc00000 /* sw reg,n($r30) */ |
961 | || (inst & 0xffe00000) == 0xffa00000) /* sd reg,n($sp) */ | |
962 | { | |
963 | /* It might be possible to use the instruction to | |
c5aa993b JM |
964 | find the offset, rather than the code below which |
965 | is based on things being in a certain order in the | |
966 | frame, but figuring out what the instruction's offset | |
967 | is relative to might be a little tricky. */ | |
c906108c SS |
968 | reg = (inst & 0x001f0000) >> 16; |
969 | *gen_mask |= (1 << reg); | |
970 | } | |
971 | else if ((inst & 0xffe00000) == 0xe7a00000 /* swc1 freg,n($sp) */ | |
6d82d43b | 972 | || (inst & 0xffe00000) == 0xe7c00000 /* swc1 freg,n($r30) */ |
c5aa993b | 973 | || (inst & 0xffe00000) == 0xf7a00000) /* sdc1 freg,n($sp) */ |
c906108c SS |
974 | |
975 | { | |
976 | reg = ((inst & 0x001f0000) >> 16); | |
977 | *float_mask |= (1 << reg); | |
978 | } | |
979 | } | |
980 | ||
981 | /* Decode a MIPS16 instruction that saves a register in the stack, and | |
982 | set the appropriate bit in the general register or float register mask | |
983 | to indicate which register is saved. This is a helper function | |
984 | for mips_find_saved_regs. */ | |
985 | ||
986 | static void | |
acdb74a0 | 987 | mips16_decode_reg_save (t_inst inst, unsigned long *gen_mask) |
c906108c | 988 | { |
c5aa993b | 989 | if ((inst & 0xf800) == 0xd000) /* sw reg,n($sp) */ |
c906108c SS |
990 | { |
991 | int reg = mips16_to_32_reg[(inst & 0x700) >> 8]; | |
992 | *gen_mask |= (1 << reg); | |
993 | } | |
c5aa993b | 994 | else if ((inst & 0xff00) == 0xf900) /* sd reg,n($sp) */ |
c906108c SS |
995 | { |
996 | int reg = mips16_to_32_reg[(inst & 0xe0) >> 5]; | |
997 | *gen_mask |= (1 << reg); | |
998 | } | |
c5aa993b | 999 | else if ((inst & 0xff00) == 0x6200 /* sw $ra,n($sp) */ |
c906108c SS |
1000 | || (inst & 0xff00) == 0xfa00) /* sd $ra,n($sp) */ |
1001 | *gen_mask |= (1 << RA_REGNUM); | |
1002 | } | |
1003 | ||
1004 | ||
1005 | /* Fetch and return instruction from the specified location. If the PC | |
1006 | is odd, assume it's a MIPS16 instruction; otherwise MIPS32. */ | |
1007 | ||
1008 | static t_inst | |
acdb74a0 | 1009 | mips_fetch_instruction (CORE_ADDR addr) |
c906108c SS |
1010 | { |
1011 | char buf[MIPS_INSTLEN]; | |
1012 | int instlen; | |
1013 | int status; | |
1014 | ||
1015 | if (pc_is_mips16 (addr)) | |
1016 | { | |
1017 | instlen = MIPS16_INSTLEN; | |
95404a3e | 1018 | addr = unmake_mips16_addr (addr); |
c906108c SS |
1019 | } |
1020 | else | |
c5aa993b | 1021 | instlen = MIPS_INSTLEN; |
1f602b35 | 1022 | status = deprecated_read_memory_nobpt (addr, buf, instlen); |
c906108c SS |
1023 | if (status) |
1024 | memory_error (status, addr); | |
1025 | return extract_unsigned_integer (buf, instlen); | |
1026 | } | |
1027 | ||
edfae063 AC |
1028 | static ULONGEST |
1029 | mips16_fetch_instruction (CORE_ADDR addr) | |
1030 | { | |
1031 | char buf[MIPS_INSTLEN]; | |
1032 | int instlen; | |
1033 | int status; | |
1034 | ||
1035 | instlen = MIPS16_INSTLEN; | |
1036 | addr = unmake_mips16_addr (addr); | |
1f602b35 | 1037 | status = deprecated_read_memory_nobpt (addr, buf, instlen); |
edfae063 AC |
1038 | if (status) |
1039 | memory_error (status, addr); | |
1040 | return extract_unsigned_integer (buf, instlen); | |
1041 | } | |
1042 | ||
1043 | static ULONGEST | |
1044 | mips32_fetch_instruction (CORE_ADDR addr) | |
1045 | { | |
1046 | char buf[MIPS_INSTLEN]; | |
1047 | int instlen; | |
1048 | int status; | |
1049 | instlen = MIPS_INSTLEN; | |
1f602b35 | 1050 | status = deprecated_read_memory_nobpt (addr, buf, instlen); |
edfae063 AC |
1051 | if (status) |
1052 | memory_error (status, addr); | |
1053 | return extract_unsigned_integer (buf, instlen); | |
1054 | } | |
1055 | ||
c906108c SS |
1056 | |
1057 | /* These the fields of 32 bit mips instructions */ | |
e135b889 DJ |
1058 | #define mips32_op(x) (x >> 26) |
1059 | #define itype_op(x) (x >> 26) | |
1060 | #define itype_rs(x) ((x >> 21) & 0x1f) | |
c906108c | 1061 | #define itype_rt(x) ((x >> 16) & 0x1f) |
e135b889 | 1062 | #define itype_immediate(x) (x & 0xffff) |
c906108c | 1063 | |
e135b889 DJ |
1064 | #define jtype_op(x) (x >> 26) |
1065 | #define jtype_target(x) (x & 0x03ffffff) | |
c906108c | 1066 | |
e135b889 DJ |
1067 | #define rtype_op(x) (x >> 26) |
1068 | #define rtype_rs(x) ((x >> 21) & 0x1f) | |
1069 | #define rtype_rt(x) ((x >> 16) & 0x1f) | |
1070 | #define rtype_rd(x) ((x >> 11) & 0x1f) | |
1071 | #define rtype_shamt(x) ((x >> 6) & 0x1f) | |
1072 | #define rtype_funct(x) (x & 0x3f) | |
c906108c SS |
1073 | |
1074 | static CORE_ADDR | |
c5aa993b JM |
1075 | mips32_relative_offset (unsigned long inst) |
1076 | { | |
1077 | long x; | |
1078 | x = itype_immediate (inst); | |
1079 | if (x & 0x8000) /* sign bit set */ | |
c906108c | 1080 | { |
c5aa993b | 1081 | x |= 0xffff0000; /* sign extension */ |
c906108c | 1082 | } |
c5aa993b JM |
1083 | x = x << 2; |
1084 | return x; | |
c906108c SS |
1085 | } |
1086 | ||
1087 | /* Determine whate to set a single step breakpoint while considering | |
1088 | branch prediction */ | |
5a89d8aa | 1089 | static CORE_ADDR |
c5aa993b JM |
1090 | mips32_next_pc (CORE_ADDR pc) |
1091 | { | |
1092 | unsigned long inst; | |
1093 | int op; | |
1094 | inst = mips_fetch_instruction (pc); | |
e135b889 | 1095 | if ((inst & 0xe0000000) != 0) /* Not a special, jump or branch instruction */ |
c5aa993b | 1096 | { |
e135b889 | 1097 | if (itype_op (inst) >> 2 == 5) |
6d82d43b | 1098 | /* BEQL, BNEL, BLEZL, BGTZL: bits 0101xx */ |
c5aa993b | 1099 | { |
e135b889 | 1100 | op = (itype_op (inst) & 0x03); |
c906108c SS |
1101 | switch (op) |
1102 | { | |
e135b889 DJ |
1103 | case 0: /* BEQL */ |
1104 | goto equal_branch; | |
1105 | case 1: /* BNEL */ | |
1106 | goto neq_branch; | |
1107 | case 2: /* BLEZL */ | |
1108 | goto less_branch; | |
1109 | case 3: /* BGTZ */ | |
1110 | goto greater_branch; | |
c5aa993b JM |
1111 | default: |
1112 | pc += 4; | |
c906108c SS |
1113 | } |
1114 | } | |
e135b889 | 1115 | else if (itype_op (inst) == 17 && itype_rs (inst) == 8) |
6d82d43b | 1116 | /* BC1F, BC1FL, BC1T, BC1TL: 010001 01000 */ |
e135b889 DJ |
1117 | { |
1118 | int tf = itype_rt (inst) & 0x01; | |
1119 | int cnum = itype_rt (inst) >> 2; | |
6d82d43b AC |
1120 | int fcrcs = |
1121 | read_signed_register (mips_regnum (current_gdbarch)-> | |
1122 | fp_control_status); | |
e135b889 DJ |
1123 | int cond = ((fcrcs >> 24) & 0x0e) | ((fcrcs >> 23) & 0x01); |
1124 | ||
1125 | if (((cond >> cnum) & 0x01) == tf) | |
1126 | pc += mips32_relative_offset (inst) + 4; | |
1127 | else | |
1128 | pc += 8; | |
1129 | } | |
c5aa993b JM |
1130 | else |
1131 | pc += 4; /* Not a branch, next instruction is easy */ | |
c906108c SS |
1132 | } |
1133 | else | |
c5aa993b JM |
1134 | { /* This gets way messy */ |
1135 | ||
c906108c | 1136 | /* Further subdivide into SPECIAL, REGIMM and other */ |
e135b889 | 1137 | switch (op = itype_op (inst) & 0x07) /* extract bits 28,27,26 */ |
c906108c | 1138 | { |
c5aa993b JM |
1139 | case 0: /* SPECIAL */ |
1140 | op = rtype_funct (inst); | |
1141 | switch (op) | |
1142 | { | |
1143 | case 8: /* JR */ | |
1144 | case 9: /* JALR */ | |
6c997a34 AC |
1145 | /* Set PC to that address */ |
1146 | pc = read_signed_register (rtype_rs (inst)); | |
c5aa993b JM |
1147 | break; |
1148 | default: | |
1149 | pc += 4; | |
1150 | } | |
1151 | ||
6d82d43b | 1152 | break; /* end SPECIAL */ |
c5aa993b | 1153 | case 1: /* REGIMM */ |
c906108c | 1154 | { |
e135b889 DJ |
1155 | op = itype_rt (inst); /* branch condition */ |
1156 | switch (op) | |
c906108c | 1157 | { |
c5aa993b | 1158 | case 0: /* BLTZ */ |
e135b889 DJ |
1159 | case 2: /* BLTZL */ |
1160 | case 16: /* BLTZAL */ | |
c5aa993b | 1161 | case 18: /* BLTZALL */ |
c906108c | 1162 | less_branch: |
6c997a34 | 1163 | if (read_signed_register (itype_rs (inst)) < 0) |
c5aa993b JM |
1164 | pc += mips32_relative_offset (inst) + 4; |
1165 | else | |
1166 | pc += 8; /* after the delay slot */ | |
1167 | break; | |
e135b889 | 1168 | case 1: /* BGEZ */ |
c5aa993b JM |
1169 | case 3: /* BGEZL */ |
1170 | case 17: /* BGEZAL */ | |
1171 | case 19: /* BGEZALL */ | |
6c997a34 | 1172 | if (read_signed_register (itype_rs (inst)) >= 0) |
c5aa993b JM |
1173 | pc += mips32_relative_offset (inst) + 4; |
1174 | else | |
1175 | pc += 8; /* after the delay slot */ | |
1176 | break; | |
e135b889 | 1177 | /* All of the other instructions in the REGIMM category */ |
c5aa993b JM |
1178 | default: |
1179 | pc += 4; | |
c906108c SS |
1180 | } |
1181 | } | |
6d82d43b | 1182 | break; /* end REGIMM */ |
c5aa993b JM |
1183 | case 2: /* J */ |
1184 | case 3: /* JAL */ | |
1185 | { | |
1186 | unsigned long reg; | |
1187 | reg = jtype_target (inst) << 2; | |
e135b889 | 1188 | /* Upper four bits get never changed... */ |
c5aa993b | 1189 | pc = reg + ((pc + 4) & 0xf0000000); |
c906108c | 1190 | } |
c5aa993b JM |
1191 | break; |
1192 | /* FIXME case JALX : */ | |
1193 | { | |
1194 | unsigned long reg; | |
1195 | reg = jtype_target (inst) << 2; | |
1196 | pc = reg + ((pc + 4) & 0xf0000000) + 1; /* yes, +1 */ | |
c906108c SS |
1197 | /* Add 1 to indicate 16 bit mode - Invert ISA mode */ |
1198 | } | |
c5aa993b | 1199 | break; /* The new PC will be alternate mode */ |
e135b889 | 1200 | case 4: /* BEQ, BEQL */ |
c5aa993b | 1201 | equal_branch: |
6c997a34 AC |
1202 | if (read_signed_register (itype_rs (inst)) == |
1203 | read_signed_register (itype_rt (inst))) | |
c5aa993b JM |
1204 | pc += mips32_relative_offset (inst) + 4; |
1205 | else | |
1206 | pc += 8; | |
1207 | break; | |
e135b889 | 1208 | case 5: /* BNE, BNEL */ |
c5aa993b | 1209 | neq_branch: |
6c997a34 | 1210 | if (read_signed_register (itype_rs (inst)) != |
e135b889 | 1211 | read_signed_register (itype_rt (inst))) |
c5aa993b JM |
1212 | pc += mips32_relative_offset (inst) + 4; |
1213 | else | |
1214 | pc += 8; | |
1215 | break; | |
e135b889 | 1216 | case 6: /* BLEZ, BLEZL */ |
6c997a34 | 1217 | if (read_signed_register (itype_rs (inst) <= 0)) |
c5aa993b JM |
1218 | pc += mips32_relative_offset (inst) + 4; |
1219 | else | |
1220 | pc += 8; | |
1221 | break; | |
1222 | case 7: | |
e135b889 DJ |
1223 | default: |
1224 | greater_branch: /* BGTZ, BGTZL */ | |
6c997a34 | 1225 | if (read_signed_register (itype_rs (inst) > 0)) |
c5aa993b JM |
1226 | pc += mips32_relative_offset (inst) + 4; |
1227 | else | |
1228 | pc += 8; | |
1229 | break; | |
c5aa993b JM |
1230 | } /* switch */ |
1231 | } /* else */ | |
1232 | return pc; | |
1233 | } /* mips32_next_pc */ | |
c906108c SS |
1234 | |
1235 | /* Decoding the next place to set a breakpoint is irregular for the | |
e26cc349 | 1236 | mips 16 variant, but fortunately, there fewer instructions. We have to cope |
c906108c SS |
1237 | ith extensions for 16 bit instructions and a pair of actual 32 bit instructions. |
1238 | We dont want to set a single step instruction on the extend instruction | |
1239 | either. | |
c5aa993b | 1240 | */ |
c906108c SS |
1241 | |
1242 | /* Lots of mips16 instruction formats */ | |
1243 | /* Predicting jumps requires itype,ritype,i8type | |
1244 | and their extensions extItype,extritype,extI8type | |
c5aa993b | 1245 | */ |
c906108c SS |
1246 | enum mips16_inst_fmts |
1247 | { | |
c5aa993b JM |
1248 | itype, /* 0 immediate 5,10 */ |
1249 | ritype, /* 1 5,3,8 */ | |
1250 | rrtype, /* 2 5,3,3,5 */ | |
1251 | rritype, /* 3 5,3,3,5 */ | |
1252 | rrrtype, /* 4 5,3,3,3,2 */ | |
1253 | rriatype, /* 5 5,3,3,1,4 */ | |
1254 | shifttype, /* 6 5,3,3,3,2 */ | |
1255 | i8type, /* 7 5,3,8 */ | |
1256 | i8movtype, /* 8 5,3,3,5 */ | |
1257 | i8mov32rtype, /* 9 5,3,5,3 */ | |
1258 | i64type, /* 10 5,3,8 */ | |
1259 | ri64type, /* 11 5,3,3,5 */ | |
1260 | jalxtype, /* 12 5,1,5,5,16 - a 32 bit instruction */ | |
1261 | exiItype, /* 13 5,6,5,5,1,1,1,1,1,1,5 */ | |
1262 | extRitype, /* 14 5,6,5,5,3,1,1,1,5 */ | |
1263 | extRRItype, /* 15 5,5,5,5,3,3,5 */ | |
1264 | extRRIAtype, /* 16 5,7,4,5,3,3,1,4 */ | |
1265 | EXTshifttype, /* 17 5,5,1,1,1,1,1,1,5,3,3,1,1,1,2 */ | |
1266 | extI8type, /* 18 5,6,5,5,3,1,1,1,5 */ | |
1267 | extI64type, /* 19 5,6,5,5,3,1,1,1,5 */ | |
1268 | extRi64type, /* 20 5,6,5,5,3,3,5 */ | |
1269 | extshift64type /* 21 5,5,1,1,1,1,1,1,5,1,1,1,3,5 */ | |
1270 | }; | |
12f02c2a AC |
1271 | /* I am heaping all the fields of the formats into one structure and |
1272 | then, only the fields which are involved in instruction extension */ | |
c906108c | 1273 | struct upk_mips16 |
6d82d43b AC |
1274 | { |
1275 | CORE_ADDR offset; | |
1276 | unsigned int regx; /* Function in i8 type */ | |
1277 | unsigned int regy; | |
1278 | }; | |
c906108c SS |
1279 | |
1280 | ||
12f02c2a AC |
1281 | /* The EXT-I, EXT-ri nad EXT-I8 instructions all have the same format |
1282 | for the bits which make up the immediatate extension. */ | |
c906108c | 1283 | |
12f02c2a AC |
1284 | static CORE_ADDR |
1285 | extended_offset (unsigned int extension) | |
c906108c | 1286 | { |
12f02c2a | 1287 | CORE_ADDR value; |
c5aa993b JM |
1288 | value = (extension >> 21) & 0x3f; /* * extract 15:11 */ |
1289 | value = value << 6; | |
1290 | value |= (extension >> 16) & 0x1f; /* extrace 10:5 */ | |
1291 | value = value << 5; | |
1292 | value |= extension & 0x01f; /* extract 4:0 */ | |
1293 | return value; | |
c906108c SS |
1294 | } |
1295 | ||
1296 | /* Only call this function if you know that this is an extendable | |
1297 | instruction, It wont malfunction, but why make excess remote memory references? | |
1298 | If the immediate operands get sign extended or somthing, do it after | |
1299 | the extension is performed. | |
c5aa993b | 1300 | */ |
c906108c SS |
1301 | /* FIXME: Every one of these cases needs to worry about sign extension |
1302 | when the offset is to be used in relative addressing */ | |
1303 | ||
1304 | ||
12f02c2a | 1305 | static unsigned int |
c5aa993b | 1306 | fetch_mips_16 (CORE_ADDR pc) |
c906108c | 1307 | { |
c5aa993b JM |
1308 | char buf[8]; |
1309 | pc &= 0xfffffffe; /* clear the low order bit */ | |
1310 | target_read_memory (pc, buf, 2); | |
1311 | return extract_unsigned_integer (buf, 2); | |
c906108c SS |
1312 | } |
1313 | ||
1314 | static void | |
c5aa993b | 1315 | unpack_mips16 (CORE_ADDR pc, |
12f02c2a AC |
1316 | unsigned int extension, |
1317 | unsigned int inst, | |
6d82d43b | 1318 | enum mips16_inst_fmts insn_format, struct upk_mips16 *upk) |
c906108c | 1319 | { |
12f02c2a AC |
1320 | CORE_ADDR offset; |
1321 | int regx; | |
1322 | int regy; | |
1323 | switch (insn_format) | |
c906108c | 1324 | { |
c5aa993b | 1325 | case itype: |
c906108c | 1326 | { |
12f02c2a AC |
1327 | CORE_ADDR value; |
1328 | if (extension) | |
c5aa993b JM |
1329 | { |
1330 | value = extended_offset (extension); | |
1331 | value = value << 11; /* rom for the original value */ | |
6d82d43b | 1332 | value |= inst & 0x7ff; /* eleven bits from instruction */ |
c906108c SS |
1333 | } |
1334 | else | |
c5aa993b | 1335 | { |
12f02c2a | 1336 | value = inst & 0x7ff; |
c5aa993b | 1337 | /* FIXME : Consider sign extension */ |
c906108c | 1338 | } |
12f02c2a AC |
1339 | offset = value; |
1340 | regx = -1; | |
1341 | regy = -1; | |
c906108c | 1342 | } |
c5aa993b JM |
1343 | break; |
1344 | case ritype: | |
1345 | case i8type: | |
1346 | { /* A register identifier and an offset */ | |
c906108c SS |
1347 | /* Most of the fields are the same as I type but the |
1348 | immediate value is of a different length */ | |
12f02c2a AC |
1349 | CORE_ADDR value; |
1350 | if (extension) | |
c906108c | 1351 | { |
c5aa993b JM |
1352 | value = extended_offset (extension); |
1353 | value = value << 8; /* from the original instruction */ | |
12f02c2a AC |
1354 | value |= inst & 0xff; /* eleven bits from instruction */ |
1355 | regx = (extension >> 8) & 0x07; /* or i8 funct */ | |
c5aa993b JM |
1356 | if (value & 0x4000) /* test the sign bit , bit 26 */ |
1357 | { | |
1358 | value &= ~0x3fff; /* remove the sign bit */ | |
1359 | value = -value; | |
c906108c SS |
1360 | } |
1361 | } | |
c5aa993b JM |
1362 | else |
1363 | { | |
12f02c2a AC |
1364 | value = inst & 0xff; /* 8 bits */ |
1365 | regx = (inst >> 8) & 0x07; /* or i8 funct */ | |
c5aa993b JM |
1366 | /* FIXME: Do sign extension , this format needs it */ |
1367 | if (value & 0x80) /* THIS CONFUSES ME */ | |
1368 | { | |
1369 | value &= 0xef; /* remove the sign bit */ | |
1370 | value = -value; | |
1371 | } | |
c5aa993b | 1372 | } |
12f02c2a AC |
1373 | offset = value; |
1374 | regy = -1; | |
c5aa993b | 1375 | break; |
c906108c | 1376 | } |
c5aa993b | 1377 | case jalxtype: |
c906108c | 1378 | { |
c5aa993b | 1379 | unsigned long value; |
12f02c2a AC |
1380 | unsigned int nexthalf; |
1381 | value = ((inst & 0x1f) << 5) | ((inst >> 5) & 0x1f); | |
c5aa993b JM |
1382 | value = value << 16; |
1383 | nexthalf = mips_fetch_instruction (pc + 2); /* low bit still set */ | |
1384 | value |= nexthalf; | |
12f02c2a AC |
1385 | offset = value; |
1386 | regx = -1; | |
1387 | regy = -1; | |
c5aa993b | 1388 | break; |
c906108c SS |
1389 | } |
1390 | default: | |
6d82d43b | 1391 | internal_error (__FILE__, __LINE__, "bad switch"); |
c906108c | 1392 | } |
12f02c2a AC |
1393 | upk->offset = offset; |
1394 | upk->regx = regx; | |
1395 | upk->regy = regy; | |
c906108c SS |
1396 | } |
1397 | ||
1398 | ||
c5aa993b JM |
1399 | static CORE_ADDR |
1400 | add_offset_16 (CORE_ADDR pc, int offset) | |
c906108c | 1401 | { |
c5aa993b | 1402 | return ((offset << 2) | ((pc + 2) & (0xf0000000))); |
c906108c SS |
1403 | } |
1404 | ||
12f02c2a AC |
1405 | static CORE_ADDR |
1406 | extended_mips16_next_pc (CORE_ADDR pc, | |
6d82d43b | 1407 | unsigned int extension, unsigned int insn) |
c906108c | 1408 | { |
12f02c2a AC |
1409 | int op = (insn >> 11); |
1410 | switch (op) | |
c906108c | 1411 | { |
6d82d43b | 1412 | case 2: /* Branch */ |
12f02c2a AC |
1413 | { |
1414 | CORE_ADDR offset; | |
1415 | struct upk_mips16 upk; | |
1416 | unpack_mips16 (pc, extension, insn, itype, &upk); | |
1417 | offset = upk.offset; | |
1418 | if (offset & 0x800) | |
1419 | { | |
1420 | offset &= 0xeff; | |
1421 | offset = -offset; | |
1422 | } | |
1423 | pc += (offset << 1) + 2; | |
1424 | break; | |
1425 | } | |
6d82d43b | 1426 | case 3: /* JAL , JALX - Watch out, these are 32 bit instruction */ |
12f02c2a AC |
1427 | { |
1428 | struct upk_mips16 upk; | |
1429 | unpack_mips16 (pc, extension, insn, jalxtype, &upk); | |
1430 | pc = add_offset_16 (pc, upk.offset); | |
1431 | if ((insn >> 10) & 0x01) /* Exchange mode */ | |
1432 | pc = pc & ~0x01; /* Clear low bit, indicate 32 bit mode */ | |
1433 | else | |
1434 | pc |= 0x01; | |
1435 | break; | |
1436 | } | |
6d82d43b | 1437 | case 4: /* beqz */ |
12f02c2a AC |
1438 | { |
1439 | struct upk_mips16 upk; | |
1440 | int reg; | |
1441 | unpack_mips16 (pc, extension, insn, ritype, &upk); | |
1442 | reg = read_signed_register (upk.regx); | |
1443 | if (reg == 0) | |
1444 | pc += (upk.offset << 1) + 2; | |
1445 | else | |
1446 | pc += 2; | |
1447 | break; | |
1448 | } | |
6d82d43b | 1449 | case 5: /* bnez */ |
12f02c2a AC |
1450 | { |
1451 | struct upk_mips16 upk; | |
1452 | int reg; | |
1453 | unpack_mips16 (pc, extension, insn, ritype, &upk); | |
1454 | reg = read_signed_register (upk.regx); | |
1455 | if (reg != 0) | |
1456 | pc += (upk.offset << 1) + 2; | |
1457 | else | |
1458 | pc += 2; | |
1459 | break; | |
1460 | } | |
6d82d43b | 1461 | case 12: /* I8 Formats btez btnez */ |
12f02c2a AC |
1462 | { |
1463 | struct upk_mips16 upk; | |
1464 | int reg; | |
1465 | unpack_mips16 (pc, extension, insn, i8type, &upk); | |
1466 | /* upk.regx contains the opcode */ | |
1467 | reg = read_signed_register (24); /* Test register is 24 */ | |
1468 | if (((upk.regx == 0) && (reg == 0)) /* BTEZ */ | |
1469 | || ((upk.regx == 1) && (reg != 0))) /* BTNEZ */ | |
1470 | /* pc = add_offset_16(pc,upk.offset) ; */ | |
1471 | pc += (upk.offset << 1) + 2; | |
1472 | else | |
1473 | pc += 2; | |
1474 | break; | |
1475 | } | |
6d82d43b | 1476 | case 29: /* RR Formats JR, JALR, JALR-RA */ |
12f02c2a AC |
1477 | { |
1478 | struct upk_mips16 upk; | |
1479 | /* upk.fmt = rrtype; */ | |
1480 | op = insn & 0x1f; | |
1481 | if (op == 0) | |
c5aa993b | 1482 | { |
12f02c2a AC |
1483 | int reg; |
1484 | upk.regx = (insn >> 8) & 0x07; | |
1485 | upk.regy = (insn >> 5) & 0x07; | |
1486 | switch (upk.regy) | |
c5aa993b | 1487 | { |
12f02c2a AC |
1488 | case 0: |
1489 | reg = upk.regx; | |
1490 | break; | |
1491 | case 1: | |
1492 | reg = 31; | |
6d82d43b | 1493 | break; /* Function return instruction */ |
12f02c2a AC |
1494 | case 2: |
1495 | reg = upk.regx; | |
1496 | break; | |
1497 | default: | |
1498 | reg = 31; | |
6d82d43b | 1499 | break; /* BOGUS Guess */ |
c906108c | 1500 | } |
12f02c2a | 1501 | pc = read_signed_register (reg); |
c906108c | 1502 | } |
12f02c2a | 1503 | else |
c5aa993b | 1504 | pc += 2; |
12f02c2a AC |
1505 | break; |
1506 | } | |
1507 | case 30: | |
1508 | /* This is an instruction extension. Fetch the real instruction | |
1509 | (which follows the extension) and decode things based on | |
1510 | that. */ | |
1511 | { | |
1512 | pc += 2; | |
1513 | pc = extended_mips16_next_pc (pc, insn, fetch_mips_16 (pc)); | |
1514 | break; | |
1515 | } | |
1516 | default: | |
1517 | { | |
1518 | pc += 2; | |
1519 | break; | |
1520 | } | |
c906108c | 1521 | } |
c5aa993b | 1522 | return pc; |
12f02c2a | 1523 | } |
c906108c | 1524 | |
5a89d8aa | 1525 | static CORE_ADDR |
12f02c2a AC |
1526 | mips16_next_pc (CORE_ADDR pc) |
1527 | { | |
1528 | unsigned int insn = fetch_mips_16 (pc); | |
1529 | return extended_mips16_next_pc (pc, 0, insn); | |
1530 | } | |
1531 | ||
1532 | /* The mips_next_pc function supports single_step when the remote | |
7e73cedf | 1533 | target monitor or stub is not developed enough to do a single_step. |
12f02c2a AC |
1534 | It works by decoding the current instruction and predicting where a |
1535 | branch will go. This isnt hard because all the data is available. | |
1536 | The MIPS32 and MIPS16 variants are quite different */ | |
c5aa993b JM |
1537 | CORE_ADDR |
1538 | mips_next_pc (CORE_ADDR pc) | |
c906108c | 1539 | { |
c5aa993b JM |
1540 | if (pc & 0x01) |
1541 | return mips16_next_pc (pc); | |
1542 | else | |
1543 | return mips32_next_pc (pc); | |
12f02c2a | 1544 | } |
c906108c | 1545 | |
edfae063 AC |
1546 | struct mips_frame_cache |
1547 | { | |
1548 | CORE_ADDR base; | |
1549 | struct trad_frame_saved_reg *saved_regs; | |
1550 | }; | |
1551 | ||
1552 | ||
1553 | static struct mips_frame_cache * | |
1554 | mips_mdebug_frame_cache (struct frame_info *next_frame, void **this_cache) | |
1555 | { | |
0d5febcc | 1556 | CORE_ADDR startaddr = 0; |
edfae063 AC |
1557 | mips_extra_func_info_t proc_desc; |
1558 | struct mips_frame_cache *cache; | |
1559 | struct gdbarch *gdbarch = get_frame_arch (next_frame); | |
1560 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
1561 | /* r0 bit means kernel trap */ | |
1562 | int kernel_trap; | |
1563 | /* What registers have been saved? Bitmasks. */ | |
1564 | unsigned long gen_mask, float_mask; | |
1565 | ||
1566 | if ((*this_cache) != NULL) | |
1567 | return (*this_cache); | |
1568 | cache = FRAME_OBSTACK_ZALLOC (struct mips_frame_cache); | |
1569 | (*this_cache) = cache; | |
1570 | cache->saved_regs = trad_frame_alloc_saved_regs (next_frame); | |
1571 | ||
1572 | /* Get the mdebug proc descriptor. */ | |
0d5febcc AC |
1573 | proc_desc = non_heuristic_proc_desc (frame_pc_unwind (next_frame), |
1574 | &startaddr); | |
1575 | /* Must be true. This is only called when the sniffer detected a | |
1576 | proc descriptor. */ | |
1577 | gdb_assert (proc_desc != NULL); | |
edfae063 AC |
1578 | |
1579 | /* Extract the frame's base. */ | |
1580 | cache->base = (frame_unwind_register_signed (next_frame, NUM_REGS + PROC_FRAME_REG (proc_desc)) | |
1581 | + PROC_FRAME_OFFSET (proc_desc) - PROC_FRAME_ADJUST (proc_desc)); | |
1582 | ||
1583 | kernel_trap = PROC_REG_MASK (proc_desc) & 1; | |
1584 | gen_mask = kernel_trap ? 0xFFFFFFFF : PROC_REG_MASK (proc_desc); | |
1585 | float_mask = kernel_trap ? 0xFFFFFFFF : PROC_FREG_MASK (proc_desc); | |
1586 | ||
9733cfe1 AC |
1587 | /* Must be true. The in_prologue case is left for the heuristic |
1588 | unwinder. This is always used on kernel traps. */ | |
1589 | gdb_assert (!in_prologue (frame_pc_unwind (next_frame), PROC_LOW_ADDR (proc_desc)) | |
1590 | || kernel_trap); | |
edfae063 AC |
1591 | |
1592 | /* Fill in the offsets for the registers which gen_mask says were | |
1593 | saved. */ | |
1594 | { | |
4fbbbd07 | 1595 | CORE_ADDR reg_position = (cache->base + PROC_REG_OFFSET (proc_desc)); |
edfae063 | 1596 | int ireg; |
4fbbbd07 | 1597 | |
edfae063 AC |
1598 | for (ireg = MIPS_NUMREGS - 1; gen_mask; --ireg, gen_mask <<= 1) |
1599 | if (gen_mask & 0x80000000) | |
1600 | { | |
1601 | cache->saved_regs[NUM_REGS + ireg].addr = reg_position; | |
13326b4e | 1602 | reg_position -= mips_abi_regsize (gdbarch); |
edfae063 AC |
1603 | } |
1604 | } | |
1605 | ||
1606 | /* The MIPS16 entry instruction saves $s0 and $s1 in the reverse | |
1607 | order of that normally used by gcc. Therefore, we have to fetch | |
1608 | the first instruction of the function, and if it's an entry | |
1609 | instruction that saves $s0 or $s1, correct their saved addresses. */ | |
1610 | if (pc_is_mips16 (PROC_LOW_ADDR (proc_desc))) | |
1611 | { | |
1612 | ULONGEST inst = mips16_fetch_instruction (PROC_LOW_ADDR (proc_desc)); | |
1613 | if ((inst & 0xf81f) == 0xe809 && (inst & 0x700) != 0x700) | |
1614 | /* entry */ | |
1615 | { | |
1616 | int reg; | |
1617 | int sreg_count = (inst >> 6) & 3; | |
1618 | ||
1619 | /* Check if the ra register was pushed on the stack. */ | |
1620 | CORE_ADDR reg_position = (cache->base | |
1621 | + PROC_REG_OFFSET (proc_desc)); | |
1622 | if (inst & 0x20) | |
13326b4e | 1623 | reg_position -= mips_abi_regsize (gdbarch); |
edfae063 AC |
1624 | |
1625 | /* Check if the s0 and s1 registers were pushed on the | |
1626 | stack. */ | |
1627 | /* NOTE: cagney/2004-02-08: Huh? This is doing no such | |
1628 | check. */ | |
1629 | for (reg = 16; reg < sreg_count + 16; reg++) | |
1630 | { | |
1631 | cache->saved_regs[NUM_REGS + reg].addr = reg_position; | |
13326b4e | 1632 | reg_position -= mips_abi_regsize (gdbarch); |
edfae063 AC |
1633 | } |
1634 | } | |
1635 | } | |
1636 | ||
1637 | /* Fill in the offsets for the registers which float_mask says were | |
1638 | saved. */ | |
1639 | { | |
1640 | CORE_ADDR reg_position = (cache->base | |
1641 | + PROC_FREG_OFFSET (proc_desc)); | |
1642 | int ireg; | |
1643 | /* Fill in the offsets for the float registers which float_mask | |
1644 | says were saved. */ | |
1645 | for (ireg = MIPS_NUMREGS - 1; float_mask; --ireg, float_mask <<= 1) | |
1646 | if (float_mask & 0x80000000) | |
1647 | { | |
13326b4e | 1648 | if (mips_abi_regsize (gdbarch) == 4 |
edfae063 AC |
1649 | && TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) |
1650 | { | |
1651 | /* On a big endian 32 bit ABI, floating point registers | |
1652 | are paired to form doubles such that the most | |
1653 | significant part is in $f[N+1] and the least | |
1654 | significant in $f[N] vis: $f[N+1] ||| $f[N]. The | |
1655 | registers are also spilled as a pair and stored as a | |
1656 | double. | |
1657 | ||
1658 | When little-endian the least significant part is | |
1659 | stored first leading to the memory order $f[N] and | |
1660 | then $f[N+1]. | |
1661 | ||
1662 | Unfortunately, when big-endian the most significant | |
1663 | part of the double is stored first, and the least | |
1664 | significant is stored second. This leads to the | |
1665 | registers being ordered in memory as firt $f[N+1] and | |
1666 | then $f[N]. | |
1667 | ||
1668 | For the big-endian case make certain that the | |
1669 | addresses point at the correct (swapped) locations | |
1670 | $f[N] and $f[N+1] pair (keep in mind that | |
1671 | reg_position is decremented each time through the | |
1672 | loop). */ | |
1673 | if ((ireg & 1)) | |
1674 | cache->saved_regs[NUM_REGS + mips_regnum (current_gdbarch)->fp0 + ireg] | |
13326b4e | 1675 | .addr = reg_position - mips_abi_regsize (gdbarch); |
edfae063 AC |
1676 | else |
1677 | cache->saved_regs[NUM_REGS + mips_regnum (current_gdbarch)->fp0 + ireg] | |
13326b4e | 1678 | .addr = reg_position + mips_abi_regsize (gdbarch); |
edfae063 AC |
1679 | } |
1680 | else | |
1681 | cache->saved_regs[NUM_REGS + mips_regnum (current_gdbarch)->fp0 + ireg] | |
1682 | .addr = reg_position; | |
13326b4e | 1683 | reg_position -= mips_abi_regsize (gdbarch); |
edfae063 AC |
1684 | } |
1685 | ||
1686 | cache->saved_regs[NUM_REGS + mips_regnum (current_gdbarch)->pc] | |
1687 | = cache->saved_regs[NUM_REGS + RA_REGNUM]; | |
1688 | } | |
1689 | ||
1690 | /* SP_REGNUM, contains the value and not the address. */ | |
f10683bb | 1691 | trad_frame_set_value (cache->saved_regs, NUM_REGS + MIPS_SP_REGNUM, cache->base); |
edfae063 AC |
1692 | |
1693 | return (*this_cache); | |
1694 | } | |
1695 | ||
1696 | static void | |
1697 | mips_mdebug_frame_this_id (struct frame_info *next_frame, void **this_cache, | |
1698 | struct frame_id *this_id) | |
1699 | { | |
1700 | struct mips_frame_cache *info = mips_mdebug_frame_cache (next_frame, | |
1701 | this_cache); | |
1702 | (*this_id) = frame_id_build (info->base, frame_func_unwind (next_frame)); | |
1703 | } | |
1704 | ||
1705 | static void | |
1706 | mips_mdebug_frame_prev_register (struct frame_info *next_frame, | |
1707 | void **this_cache, | |
1708 | int regnum, int *optimizedp, | |
1709 | enum lval_type *lvalp, CORE_ADDR *addrp, | |
1710 | int *realnump, void *valuep) | |
1711 | { | |
1712 | struct mips_frame_cache *info = mips_mdebug_frame_cache (next_frame, | |
1713 | this_cache); | |
1f67027d AC |
1714 | trad_frame_get_prev_register (next_frame, info->saved_regs, regnum, |
1715 | optimizedp, lvalp, addrp, realnump, valuep); | |
edfae063 AC |
1716 | } |
1717 | ||
1718 | static const struct frame_unwind mips_mdebug_frame_unwind = | |
1719 | { | |
1720 | NORMAL_FRAME, | |
1721 | mips_mdebug_frame_this_id, | |
1722 | mips_mdebug_frame_prev_register | |
1723 | }; | |
1724 | ||
1725 | static const struct frame_unwind * | |
1726 | mips_mdebug_frame_sniffer (struct frame_info *next_frame) | |
1727 | { | |
eec63939 AC |
1728 | CORE_ADDR pc = frame_pc_unwind (next_frame); |
1729 | CORE_ADDR startaddr = 0; | |
1730 | mips_extra_func_info_t proc_desc; | |
1731 | int kernel_trap; | |
1732 | ||
1733 | /* Only use the mdebug frame unwinder on mdebug frames where all the | |
1734 | registers have been saved. Leave hard cases such as no mdebug or | |
1735 | in prologue for the heuristic unwinders. */ | |
1736 | ||
1737 | proc_desc = non_heuristic_proc_desc (pc, &startaddr); | |
1738 | if (proc_desc == NULL) | |
1739 | return NULL; | |
1740 | ||
1741 | /* Not sure exactly what kernel_trap means, but if it means the | |
1742 | kernel saves the registers without a prologue doing it, we better | |
1743 | not examine the prologue to see whether registers have been saved | |
1744 | yet. */ | |
1745 | kernel_trap = PROC_REG_MASK (proc_desc) & 1; | |
1746 | if (kernel_trap) | |
1747 | return &mips_mdebug_frame_unwind; | |
1748 | ||
1749 | /* In any frame other than the innermost or a frame interrupted by a | |
1750 | signal, we assume that all registers have been saved. This | |
1751 | assumes that all register saves in a function happen before the | |
1752 | first function call. */ | |
1753 | if (!in_prologue (pc, PROC_LOW_ADDR (proc_desc))) | |
1754 | return &mips_mdebug_frame_unwind; | |
1755 | ||
1756 | return NULL; | |
edfae063 AC |
1757 | } |
1758 | ||
1759 | static CORE_ADDR | |
1760 | mips_mdebug_frame_base_address (struct frame_info *next_frame, | |
1761 | void **this_cache) | |
1762 | { | |
1763 | struct mips_frame_cache *info = mips_mdebug_frame_cache (next_frame, | |
1764 | this_cache); | |
1765 | return info->base; | |
1766 | } | |
1767 | ||
1768 | static const struct frame_base mips_mdebug_frame_base = { | |
1769 | &mips_mdebug_frame_unwind, | |
1770 | mips_mdebug_frame_base_address, | |
1771 | mips_mdebug_frame_base_address, | |
1772 | mips_mdebug_frame_base_address | |
1773 | }; | |
1774 | ||
1775 | static const struct frame_base * | |
1776 | mips_mdebug_frame_base_sniffer (struct frame_info *next_frame) | |
1777 | { | |
eec63939 AC |
1778 | if (mips_mdebug_frame_sniffer (next_frame) != NULL) |
1779 | return &mips_mdebug_frame_base; | |
1780 | else | |
1781 | return NULL; | |
1782 | } | |
1783 | ||
45c9dd44 AC |
1784 | /* Heuristic unwinder for 16-bit MIPS instruction set (aka MIPS16). |
1785 | Procedures that use the 32-bit instruction set are handled by the | |
1786 | mips_insn32 unwinder. */ | |
1787 | ||
eec63939 | 1788 | static struct mips_frame_cache * |
45c9dd44 | 1789 | mips_insn16_frame_cache (struct frame_info *next_frame, void **this_cache) |
eec63939 AC |
1790 | { |
1791 | mips_extra_func_info_t proc_desc; | |
1792 | struct mips_frame_cache *cache; | |
1793 | struct gdbarch *gdbarch = get_frame_arch (next_frame); | |
1794 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
1795 | /* r0 bit means kernel trap */ | |
1796 | int kernel_trap; | |
1797 | /* What registers have been saved? Bitmasks. */ | |
1798 | unsigned long gen_mask, float_mask; | |
1799 | ||
1800 | if ((*this_cache) != NULL) | |
1801 | return (*this_cache); | |
1802 | cache = FRAME_OBSTACK_ZALLOC (struct mips_frame_cache); | |
1803 | (*this_cache) = cache; | |
1804 | cache->saved_regs = trad_frame_alloc_saved_regs (next_frame); | |
1805 | ||
0d5febcc AC |
1806 | /* Synthesize a proc descriptor. */ |
1807 | { | |
1808 | const CORE_ADDR pc = frame_pc_unwind (next_frame); | |
1809 | CORE_ADDR start_addr; | |
eec63939 | 1810 | |
0d5febcc AC |
1811 | find_pc_partial_function (pc, NULL, &start_addr, NULL); |
1812 | if (start_addr == 0) | |
1813 | start_addr = heuristic_proc_start (pc); | |
1814 | ||
c9343fd1 | 1815 | #ifdef NOT_YET |
90edbfbc | 1816 | proc_desc = heuristic_proc_desc (start_addr, pc, next_frame, *this_cache); |
c9343fd1 AC |
1817 | #else |
1818 | proc_desc = heuristic_proc_desc (start_addr, pc, next_frame, NULL); | |
1819 | #endif | |
0d5febcc AC |
1820 | } |
1821 | ||
eec63939 AC |
1822 | /* Extract the frame's base. */ |
1823 | cache->base = (frame_unwind_register_signed (next_frame, NUM_REGS + PROC_FRAME_REG (proc_desc)) | |
1824 | + PROC_FRAME_OFFSET (proc_desc) - PROC_FRAME_ADJUST (proc_desc)); | |
1825 | ||
1826 | kernel_trap = PROC_REG_MASK (proc_desc) & 1; | |
1827 | gen_mask = kernel_trap ? 0xFFFFFFFF : PROC_REG_MASK (proc_desc); | |
1828 | float_mask = kernel_trap ? 0xFFFFFFFF : PROC_FREG_MASK (proc_desc); | |
1829 | ||
1830 | /* In any frame other than the innermost or a frame interrupted by a | |
1831 | signal, we assume that all registers have been saved. This | |
1832 | assumes that all register saves in a function happen before the | |
1833 | first function call. */ | |
1834 | if (in_prologue (frame_pc_unwind (next_frame), PROC_LOW_ADDR (proc_desc)) | |
1835 | /* Not sure exactly what kernel_trap means, but if it means the | |
1836 | kernel saves the registers without a prologue doing it, we | |
1837 | better not examine the prologue to see whether registers | |
1838 | have been saved yet. */ | |
1839 | && !kernel_trap) | |
1840 | { | |
1841 | /* We need to figure out whether the registers that the | |
1842 | proc_desc claims are saved have been saved yet. */ | |
1843 | ||
1844 | CORE_ADDR addr; | |
1845 | ||
1846 | /* Bitmasks; set if we have found a save for the register. */ | |
1847 | unsigned long gen_save_found = 0; | |
1848 | unsigned long float_save_found = 0; | |
1849 | int mips16; | |
1850 | ||
1851 | /* If the address is odd, assume this is MIPS16 code. */ | |
1852 | addr = PROC_LOW_ADDR (proc_desc); | |
1853 | mips16 = pc_is_mips16 (addr); | |
1854 | ||
1855 | /* Scan through this function's instructions preceding the | |
1856 | current PC, and look for those that save registers. */ | |
1857 | while (addr < frame_pc_unwind (next_frame)) | |
1858 | { | |
1859 | if (mips16) | |
1860 | { | |
1861 | mips16_decode_reg_save (mips16_fetch_instruction (addr), | |
1862 | &gen_save_found); | |
1863 | addr += MIPS16_INSTLEN; | |
1864 | } | |
1865 | else | |
1866 | { | |
1867 | mips32_decode_reg_save (mips32_fetch_instruction (addr), | |
1868 | &gen_save_found, &float_save_found); | |
1869 | addr += MIPS_INSTLEN; | |
1870 | } | |
1871 | } | |
1872 | gen_mask = gen_save_found; | |
1873 | float_mask = float_save_found; | |
1874 | } | |
1875 | ||
1876 | /* Fill in the offsets for the registers which gen_mask says were | |
1877 | saved. */ | |
1878 | { | |
1879 | CORE_ADDR reg_position = (cache->base | |
1880 | + PROC_REG_OFFSET (proc_desc)); | |
1881 | int ireg; | |
1882 | for (ireg = MIPS_NUMREGS - 1; gen_mask; --ireg, gen_mask <<= 1) | |
1883 | if (gen_mask & 0x80000000) | |
1884 | { | |
1885 | cache->saved_regs[NUM_REGS + ireg].addr = reg_position; | |
1886 | reg_position -= mips_abi_regsize (gdbarch); | |
1887 | } | |
1888 | } | |
1889 | ||
1890 | /* The MIPS16 entry instruction saves $s0 and $s1 in the reverse | |
1891 | order of that normally used by gcc. Therefore, we have to fetch | |
1892 | the first instruction of the function, and if it's an entry | |
1893 | instruction that saves $s0 or $s1, correct their saved addresses. */ | |
1894 | if (pc_is_mips16 (PROC_LOW_ADDR (proc_desc))) | |
1895 | { | |
1896 | ULONGEST inst = mips16_fetch_instruction (PROC_LOW_ADDR (proc_desc)); | |
1897 | if ((inst & 0xf81f) == 0xe809 && (inst & 0x700) != 0x700) | |
1898 | /* entry */ | |
1899 | { | |
1900 | int reg; | |
1901 | int sreg_count = (inst >> 6) & 3; | |
1902 | ||
1903 | /* Check if the ra register was pushed on the stack. */ | |
1904 | CORE_ADDR reg_position = (cache->base | |
1905 | + PROC_REG_OFFSET (proc_desc)); | |
1906 | if (inst & 0x20) | |
1907 | reg_position -= mips_abi_regsize (gdbarch); | |
1908 | ||
1909 | /* Check if the s0 and s1 registers were pushed on the | |
1910 | stack. */ | |
1911 | /* NOTE: cagney/2004-02-08: Huh? This is doing no such | |
1912 | check. */ | |
1913 | for (reg = 16; reg < sreg_count + 16; reg++) | |
1914 | { | |
1915 | cache->saved_regs[NUM_REGS + reg].addr = reg_position; | |
1916 | reg_position -= mips_abi_regsize (gdbarch); | |
1917 | } | |
1918 | } | |
1919 | } | |
1920 | ||
1921 | /* Fill in the offsets for the registers which float_mask says were | |
1922 | saved. */ | |
1923 | { | |
1924 | CORE_ADDR reg_position = (cache->base | |
1925 | + PROC_FREG_OFFSET (proc_desc)); | |
1926 | int ireg; | |
1927 | /* Fill in the offsets for the float registers which float_mask | |
1928 | says were saved. */ | |
1929 | for (ireg = MIPS_NUMREGS - 1; float_mask; --ireg, float_mask <<= 1) | |
1930 | if (float_mask & 0x80000000) | |
1931 | { | |
1932 | if (mips_abi_regsize (gdbarch) == 4 | |
1933 | && TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) | |
1934 | { | |
1935 | /* On a big endian 32 bit ABI, floating point registers | |
1936 | are paired to form doubles such that the most | |
1937 | significant part is in $f[N+1] and the least | |
1938 | significant in $f[N] vis: $f[N+1] ||| $f[N]. The | |
1939 | registers are also spilled as a pair and stored as a | |
1940 | double. | |
1941 | ||
1942 | When little-endian the least significant part is | |
1943 | stored first leading to the memory order $f[N] and | |
1944 | then $f[N+1]. | |
1945 | ||
1946 | Unfortunately, when big-endian the most significant | |
1947 | part of the double is stored first, and the least | |
1948 | significant is stored second. This leads to the | |
1949 | registers being ordered in memory as firt $f[N+1] and | |
1950 | then $f[N]. | |
1951 | ||
1952 | For the big-endian case make certain that the | |
1953 | addresses point at the correct (swapped) locations | |
1954 | $f[N] and $f[N+1] pair (keep in mind that | |
1955 | reg_position is decremented each time through the | |
1956 | loop). */ | |
1957 | if ((ireg & 1)) | |
1958 | cache->saved_regs[NUM_REGS + mips_regnum (current_gdbarch)->fp0 + ireg] | |
1959 | .addr = reg_position - mips_abi_regsize (gdbarch); | |
1960 | else | |
1961 | cache->saved_regs[NUM_REGS + mips_regnum (current_gdbarch)->fp0 + ireg] | |
1962 | .addr = reg_position + mips_abi_regsize (gdbarch); | |
1963 | } | |
1964 | else | |
1965 | cache->saved_regs[NUM_REGS + mips_regnum (current_gdbarch)->fp0 + ireg] | |
1966 | .addr = reg_position; | |
1967 | reg_position -= mips_abi_regsize (gdbarch); | |
1968 | } | |
1969 | ||
1970 | cache->saved_regs[NUM_REGS + mips_regnum (current_gdbarch)->pc] | |
1971 | = cache->saved_regs[NUM_REGS + RA_REGNUM]; | |
1972 | } | |
1973 | ||
1974 | /* SP_REGNUM, contains the value and not the address. */ | |
1975 | trad_frame_set_value (cache->saved_regs, NUM_REGS + MIPS_SP_REGNUM, cache->base); | |
1976 | ||
1977 | return (*this_cache); | |
1978 | } | |
1979 | ||
1980 | static void | |
45c9dd44 | 1981 | mips_insn16_frame_this_id (struct frame_info *next_frame, void **this_cache, |
eec63939 AC |
1982 | struct frame_id *this_id) |
1983 | { | |
45c9dd44 | 1984 | struct mips_frame_cache *info = mips_insn16_frame_cache (next_frame, |
eec63939 AC |
1985 | this_cache); |
1986 | (*this_id) = frame_id_build (info->base, frame_func_unwind (next_frame)); | |
1987 | } | |
1988 | ||
1989 | static void | |
45c9dd44 | 1990 | mips_insn16_frame_prev_register (struct frame_info *next_frame, |
eec63939 AC |
1991 | void **this_cache, |
1992 | int regnum, int *optimizedp, | |
1993 | enum lval_type *lvalp, CORE_ADDR *addrp, | |
1994 | int *realnump, void *valuep) | |
1995 | { | |
45c9dd44 | 1996 | struct mips_frame_cache *info = mips_insn16_frame_cache (next_frame, |
eec63939 AC |
1997 | this_cache); |
1998 | trad_frame_get_prev_register (next_frame, info->saved_regs, regnum, | |
1999 | optimizedp, lvalp, addrp, realnump, valuep); | |
2000 | } | |
2001 | ||
45c9dd44 | 2002 | static const struct frame_unwind mips_insn16_frame_unwind = |
eec63939 AC |
2003 | { |
2004 | NORMAL_FRAME, | |
45c9dd44 AC |
2005 | mips_insn16_frame_this_id, |
2006 | mips_insn16_frame_prev_register | |
eec63939 AC |
2007 | }; |
2008 | ||
2009 | static const struct frame_unwind * | |
45c9dd44 | 2010 | mips_insn16_frame_sniffer (struct frame_info *next_frame) |
eec63939 AC |
2011 | { |
2012 | CORE_ADDR pc = frame_pc_unwind (next_frame); | |
2013 | if (pc_is_mips16 (pc)) | |
45c9dd44 | 2014 | return &mips_insn16_frame_unwind; |
eec63939 AC |
2015 | return NULL; |
2016 | } | |
2017 | ||
2018 | static CORE_ADDR | |
45c9dd44 | 2019 | mips_insn16_frame_base_address (struct frame_info *next_frame, |
eec63939 AC |
2020 | void **this_cache) |
2021 | { | |
45c9dd44 | 2022 | struct mips_frame_cache *info = mips_insn16_frame_cache (next_frame, |
eec63939 AC |
2023 | this_cache); |
2024 | return info->base; | |
2025 | } | |
2026 | ||
45c9dd44 | 2027 | static const struct frame_base mips_insn16_frame_base = |
eec63939 | 2028 | { |
45c9dd44 AC |
2029 | &mips_insn16_frame_unwind, |
2030 | mips_insn16_frame_base_address, | |
2031 | mips_insn16_frame_base_address, | |
2032 | mips_insn16_frame_base_address | |
eec63939 AC |
2033 | }; |
2034 | ||
2035 | static const struct frame_base * | |
45c9dd44 | 2036 | mips_insn16_frame_base_sniffer (struct frame_info *next_frame) |
eec63939 | 2037 | { |
45c9dd44 AC |
2038 | if (mips_insn16_frame_sniffer (next_frame) != NULL) |
2039 | return &mips_insn16_frame_base; | |
eec63939 AC |
2040 | else |
2041 | return NULL; | |
2042 | } | |
2043 | ||
45c9dd44 AC |
2044 | /* Heuristic unwinder for procedures using 32-bit instructions (covers |
2045 | both 32-bit and 64-bit MIPS ISAs). Procedures using 16-bit | |
2046 | instructions (a.k.a. MIPS16) are handled by the mips_insn16 | |
2047 | unwinder. */ | |
2048 | ||
eec63939 | 2049 | static struct mips_frame_cache * |
45c9dd44 | 2050 | mips_insn32_frame_cache (struct frame_info *next_frame, void **this_cache) |
eec63939 AC |
2051 | { |
2052 | mips_extra_func_info_t proc_desc; | |
2053 | struct mips_frame_cache *cache; | |
2054 | struct gdbarch *gdbarch = get_frame_arch (next_frame); | |
2055 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
2056 | /* r0 bit means kernel trap */ | |
2057 | int kernel_trap; | |
2058 | /* What registers have been saved? Bitmasks. */ | |
2059 | unsigned long gen_mask, float_mask; | |
2060 | ||
2061 | if ((*this_cache) != NULL) | |
2062 | return (*this_cache); | |
2063 | cache = FRAME_OBSTACK_ZALLOC (struct mips_frame_cache); | |
2064 | (*this_cache) = cache; | |
2065 | cache->saved_regs = trad_frame_alloc_saved_regs (next_frame); | |
2066 | ||
a343eb3c JB |
2067 | /* Synthesize a proc descriptor. */ |
2068 | { | |
2069 | const CORE_ADDR pc = frame_pc_unwind (next_frame); | |
2070 | CORE_ADDR start_addr; | |
2071 | ||
2072 | find_pc_partial_function (pc, NULL, &start_addr, NULL); | |
2073 | if (start_addr == 0) | |
2074 | start_addr = heuristic_proc_start (pc); | |
2075 | ||
c9343fd1 | 2076 | #ifdef NOT_YET |
90edbfbc | 2077 | proc_desc = heuristic_proc_desc (start_addr, pc, next_frame, *this_cache); |
c9343fd1 AC |
2078 | #else |
2079 | proc_desc = heuristic_proc_desc (start_addr, pc, next_frame, NULL); | |
2080 | #endif | |
a343eb3c JB |
2081 | } |
2082 | ||
eec63939 AC |
2083 | if (proc_desc == NULL) |
2084 | /* I'm not sure how/whether this can happen. Normally when we | |
2085 | can't find a proc_desc, we "synthesize" one using | |
2086 | heuristic_proc_desc and set the saved_regs right away. */ | |
2087 | return cache; | |
2088 | ||
2089 | /* Extract the frame's base. */ | |
2090 | cache->base = (frame_unwind_register_signed (next_frame, NUM_REGS + PROC_FRAME_REG (proc_desc)) | |
2091 | + PROC_FRAME_OFFSET (proc_desc) - PROC_FRAME_ADJUST (proc_desc)); | |
2092 | ||
2093 | kernel_trap = PROC_REG_MASK (proc_desc) & 1; | |
2094 | gen_mask = kernel_trap ? 0xFFFFFFFF : PROC_REG_MASK (proc_desc); | |
2095 | float_mask = kernel_trap ? 0xFFFFFFFF : PROC_FREG_MASK (proc_desc); | |
2096 | ||
2097 | /* In any frame other than the innermost or a frame interrupted by a | |
2098 | signal, we assume that all registers have been saved. This | |
2099 | assumes that all register saves in a function happen before the | |
2100 | first function call. */ | |
2101 | if (in_prologue (frame_pc_unwind (next_frame), PROC_LOW_ADDR (proc_desc)) | |
2102 | /* Not sure exactly what kernel_trap means, but if it means the | |
2103 | kernel saves the registers without a prologue doing it, we | |
2104 | better not examine the prologue to see whether registers | |
2105 | have been saved yet. */ | |
2106 | && !kernel_trap) | |
2107 | { | |
2108 | /* We need to figure out whether the registers that the | |
2109 | proc_desc claims are saved have been saved yet. */ | |
2110 | ||
2111 | CORE_ADDR addr; | |
2112 | ||
2113 | /* Bitmasks; set if we have found a save for the register. */ | |
2114 | unsigned long gen_save_found = 0; | |
2115 | unsigned long float_save_found = 0; | |
eec63939 | 2116 | |
eec63939 | 2117 | addr = PROC_LOW_ADDR (proc_desc); |
eec63939 AC |
2118 | |
2119 | /* Scan through this function's instructions preceding the | |
2120 | current PC, and look for those that save registers. */ | |
2121 | while (addr < frame_pc_unwind (next_frame)) | |
2122 | { | |
8ac2e020 JB |
2123 | mips32_decode_reg_save (mips32_fetch_instruction (addr), |
2124 | &gen_save_found, &float_save_found); | |
2125 | addr += MIPS_INSTLEN; | |
eec63939 AC |
2126 | } |
2127 | gen_mask = gen_save_found; | |
2128 | float_mask = float_save_found; | |
2129 | } | |
2130 | ||
2131 | /* Fill in the offsets for the registers which gen_mask says were | |
2132 | saved. */ | |
2133 | { | |
2134 | CORE_ADDR reg_position = (cache->base | |
2135 | + PROC_REG_OFFSET (proc_desc)); | |
2136 | int ireg; | |
2137 | for (ireg = MIPS_NUMREGS - 1; gen_mask; --ireg, gen_mask <<= 1) | |
2138 | if (gen_mask & 0x80000000) | |
2139 | { | |
2140 | cache->saved_regs[NUM_REGS + ireg].addr = reg_position; | |
2141 | reg_position -= mips_abi_regsize (gdbarch); | |
2142 | } | |
2143 | } | |
2144 | ||
eec63939 AC |
2145 | /* Fill in the offsets for the registers which float_mask says were |
2146 | saved. */ | |
2147 | { | |
8ac2e020 | 2148 | CORE_ADDR reg_position = (cache->base + PROC_FREG_OFFSET (proc_desc)); |
eec63939 | 2149 | int ireg; |
8ac2e020 | 2150 | |
eec63939 AC |
2151 | /* Fill in the offsets for the float registers which float_mask |
2152 | says were saved. */ | |
2153 | for (ireg = MIPS_NUMREGS - 1; float_mask; --ireg, float_mask <<= 1) | |
2154 | if (float_mask & 0x80000000) | |
2155 | { | |
8ac2e020 JB |
2156 | const int regno = |
2157 | NUM_REGS + mips_regnum (current_gdbarch)->fp0 + ireg; | |
2158 | ||
eec63939 AC |
2159 | if (mips_abi_regsize (gdbarch) == 4 |
2160 | && TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) | |
2161 | { | |
2162 | /* On a big endian 32 bit ABI, floating point registers | |
2163 | are paired to form doubles such that the most | |
2164 | significant part is in $f[N+1] and the least | |
2165 | significant in $f[N] vis: $f[N+1] ||| $f[N]. The | |
2166 | registers are also spilled as a pair and stored as a | |
2167 | double. | |
2168 | ||
2169 | When little-endian the least significant part is | |
2170 | stored first leading to the memory order $f[N] and | |
2171 | then $f[N+1]. | |
2172 | ||
2173 | Unfortunately, when big-endian the most significant | |
2174 | part of the double is stored first, and the least | |
2175 | significant is stored second. This leads to the | |
2176 | registers being ordered in memory as firt $f[N+1] and | |
2177 | then $f[N]. | |
2178 | ||
2179 | For the big-endian case make certain that the | |
2180 | addresses point at the correct (swapped) locations | |
2181 | $f[N] and $f[N+1] pair (keep in mind that | |
2182 | reg_position is decremented each time through the | |
2183 | loop). */ | |
2184 | if ((ireg & 1)) | |
8ac2e020 JB |
2185 | cache->saved_regs[regno].addr = |
2186 | reg_position - mips_abi_regsize (gdbarch); | |
eec63939 | 2187 | else |
8ac2e020 JB |
2188 | cache->saved_regs[regno].addr = |
2189 | reg_position + mips_abi_regsize (gdbarch); | |
eec63939 AC |
2190 | } |
2191 | else | |
8ac2e020 | 2192 | cache->saved_regs[regno].addr = reg_position; |
eec63939 AC |
2193 | reg_position -= mips_abi_regsize (gdbarch); |
2194 | } | |
2195 | ||
2196 | cache->saved_regs[NUM_REGS + mips_regnum (current_gdbarch)->pc] | |
2197 | = cache->saved_regs[NUM_REGS + RA_REGNUM]; | |
2198 | } | |
2199 | ||
2200 | /* SP_REGNUM, contains the value and not the address. */ | |
2201 | trad_frame_set_value (cache->saved_regs, NUM_REGS + MIPS_SP_REGNUM, cache->base); | |
2202 | ||
2203 | return (*this_cache); | |
2204 | } | |
2205 | ||
2206 | static void | |
45c9dd44 | 2207 | mips_insn32_frame_this_id (struct frame_info *next_frame, void **this_cache, |
eec63939 AC |
2208 | struct frame_id *this_id) |
2209 | { | |
45c9dd44 | 2210 | struct mips_frame_cache *info = mips_insn32_frame_cache (next_frame, |
eec63939 AC |
2211 | this_cache); |
2212 | (*this_id) = frame_id_build (info->base, frame_func_unwind (next_frame)); | |
2213 | } | |
2214 | ||
2215 | static void | |
45c9dd44 | 2216 | mips_insn32_frame_prev_register (struct frame_info *next_frame, |
eec63939 AC |
2217 | void **this_cache, |
2218 | int regnum, int *optimizedp, | |
2219 | enum lval_type *lvalp, CORE_ADDR *addrp, | |
2220 | int *realnump, void *valuep) | |
2221 | { | |
45c9dd44 | 2222 | struct mips_frame_cache *info = mips_insn32_frame_cache (next_frame, |
eec63939 AC |
2223 | this_cache); |
2224 | trad_frame_get_prev_register (next_frame, info->saved_regs, regnum, | |
2225 | optimizedp, lvalp, addrp, realnump, valuep); | |
2226 | } | |
2227 | ||
45c9dd44 | 2228 | static const struct frame_unwind mips_insn32_frame_unwind = |
eec63939 AC |
2229 | { |
2230 | NORMAL_FRAME, | |
45c9dd44 AC |
2231 | mips_insn32_frame_this_id, |
2232 | mips_insn32_frame_prev_register | |
eec63939 AC |
2233 | }; |
2234 | ||
2235 | static const struct frame_unwind * | |
45c9dd44 | 2236 | mips_insn32_frame_sniffer (struct frame_info *next_frame) |
eec63939 AC |
2237 | { |
2238 | CORE_ADDR pc = frame_pc_unwind (next_frame); | |
2239 | if (! pc_is_mips16 (pc)) | |
45c9dd44 | 2240 | return &mips_insn32_frame_unwind; |
eec63939 AC |
2241 | return NULL; |
2242 | } | |
2243 | ||
2244 | static CORE_ADDR | |
45c9dd44 | 2245 | mips_insn32_frame_base_address (struct frame_info *next_frame, |
eec63939 AC |
2246 | void **this_cache) |
2247 | { | |
45c9dd44 | 2248 | struct mips_frame_cache *info = mips_insn32_frame_cache (next_frame, |
eec63939 AC |
2249 | this_cache); |
2250 | return info->base; | |
2251 | } | |
2252 | ||
45c9dd44 | 2253 | static const struct frame_base mips_insn32_frame_base = |
eec63939 | 2254 | { |
45c9dd44 AC |
2255 | &mips_insn32_frame_unwind, |
2256 | mips_insn32_frame_base_address, | |
2257 | mips_insn32_frame_base_address, | |
2258 | mips_insn32_frame_base_address | |
eec63939 AC |
2259 | }; |
2260 | ||
2261 | static const struct frame_base * | |
45c9dd44 | 2262 | mips_insn32_frame_base_sniffer (struct frame_info *next_frame) |
eec63939 | 2263 | { |
45c9dd44 AC |
2264 | if (mips_insn32_frame_sniffer (next_frame) != NULL) |
2265 | return &mips_insn32_frame_base; | |
eec63939 AC |
2266 | else |
2267 | return NULL; | |
2268 | } | |
2269 | ||
2270 | static struct trad_frame_cache * | |
2271 | mips_stub_frame_cache (struct frame_info *next_frame, void **this_cache) | |
2272 | { | |
2273 | CORE_ADDR pc; | |
2274 | CORE_ADDR start_addr; | |
2275 | CORE_ADDR stack_addr; | |
2276 | struct trad_frame_cache *this_trad_cache; | |
2277 | ||
2278 | if ((*this_cache) != NULL) | |
2279 | return (*this_cache); | |
2280 | this_trad_cache = trad_frame_cache_zalloc (next_frame); | |
2281 | (*this_cache) = this_trad_cache; | |
2282 | ||
2283 | /* The return address is in the link register. */ | |
2284 | trad_frame_set_reg_realreg (this_trad_cache, PC_REGNUM, RA_REGNUM); | |
2285 | ||
2286 | /* Frame ID, since it's a frameless / stackless function, no stack | |
2287 | space is allocated and SP on entry is the current SP. */ | |
2288 | pc = frame_pc_unwind (next_frame); | |
2289 | find_pc_partial_function (pc, NULL, &start_addr, NULL); | |
2290 | stack_addr = frame_unwind_register_signed (next_frame, SP_REGNUM); | |
2291 | trad_frame_set_id (this_trad_cache, frame_id_build (start_addr, stack_addr)); | |
2292 | ||
2293 | /* Assume that the frame's base is the same as the | |
2294 | stack-pointer. */ | |
2295 | trad_frame_set_this_base (this_trad_cache, stack_addr); | |
2296 | ||
2297 | return this_trad_cache; | |
2298 | } | |
2299 | ||
2300 | static void | |
2301 | mips_stub_frame_this_id (struct frame_info *next_frame, void **this_cache, | |
2302 | struct frame_id *this_id) | |
2303 | { | |
2304 | struct trad_frame_cache *this_trad_cache | |
2305 | = mips_stub_frame_cache (next_frame, this_cache); | |
2306 | trad_frame_get_id (this_trad_cache, this_id); | |
2307 | } | |
2308 | ||
2309 | static void | |
2310 | mips_stub_frame_prev_register (struct frame_info *next_frame, | |
2311 | void **this_cache, | |
2312 | int regnum, int *optimizedp, | |
2313 | enum lval_type *lvalp, CORE_ADDR *addrp, | |
2314 | int *realnump, void *valuep) | |
2315 | { | |
2316 | struct trad_frame_cache *this_trad_cache | |
2317 | = mips_stub_frame_cache (next_frame, this_cache); | |
2318 | trad_frame_get_register (this_trad_cache, next_frame, regnum, optimizedp, | |
2319 | lvalp, addrp, realnump, valuep); | |
2320 | } | |
2321 | ||
2322 | static const struct frame_unwind mips_stub_frame_unwind = | |
2323 | { | |
2324 | NORMAL_FRAME, | |
2325 | mips_stub_frame_this_id, | |
2326 | mips_stub_frame_prev_register | |
2327 | }; | |
2328 | ||
2329 | static const struct frame_unwind * | |
2330 | mips_stub_frame_sniffer (struct frame_info *next_frame) | |
2331 | { | |
2332 | CORE_ADDR pc = frame_pc_unwind (next_frame); | |
2333 | if (in_plt_section (pc, NULL)) | |
2334 | return &mips_stub_frame_unwind; | |
2335 | else | |
2336 | return NULL; | |
2337 | } | |
2338 | ||
2339 | static CORE_ADDR | |
2340 | mips_stub_frame_base_address (struct frame_info *next_frame, | |
2341 | void **this_cache) | |
2342 | { | |
2343 | struct trad_frame_cache *this_trad_cache | |
2344 | = mips_stub_frame_cache (next_frame, this_cache); | |
2345 | return trad_frame_get_this_base (this_trad_cache); | |
2346 | } | |
2347 | ||
2348 | static const struct frame_base mips_stub_frame_base = | |
2349 | { | |
2350 | &mips_stub_frame_unwind, | |
2351 | mips_stub_frame_base_address, | |
2352 | mips_stub_frame_base_address, | |
2353 | mips_stub_frame_base_address | |
2354 | }; | |
2355 | ||
2356 | static const struct frame_base * | |
2357 | mips_stub_frame_base_sniffer (struct frame_info *next_frame) | |
2358 | { | |
2359 | if (mips_stub_frame_sniffer (next_frame) != NULL) | |
2360 | return &mips_stub_frame_base; | |
2361 | else | |
2362 | return NULL; | |
edfae063 AC |
2363 | } |
2364 | ||
c906108c | 2365 | static CORE_ADDR |
acdb74a0 | 2366 | read_next_frame_reg (struct frame_info *fi, int regno) |
c906108c | 2367 | { |
a4b8ebc8 AC |
2368 | /* Always a pseudo. */ |
2369 | gdb_assert (regno >= NUM_REGS); | |
f796e4be | 2370 | if (fi == NULL) |
c906108c | 2371 | { |
a4b8ebc8 AC |
2372 | LONGEST val; |
2373 | regcache_cooked_read_signed (current_regcache, regno, &val); | |
2374 | return val; | |
f796e4be | 2375 | } |
f10683bb MH |
2376 | else if ((regno % NUM_REGS) == MIPS_SP_REGNUM) |
2377 | /* MIPS_SP_REGNUM is special, its value is stored in saved_regs. | |
a4b8ebc8 AC |
2378 | In fact, it is so special that it can even only be fetched |
2379 | using a raw register number! Once this code as been converted | |
2380 | to frame-unwind the problem goes away. */ | |
2381 | return frame_unwind_register_signed (fi, regno % NUM_REGS); | |
f796e4be | 2382 | else |
a4b8ebc8 | 2383 | return frame_unwind_register_signed (fi, regno); |
64159455 | 2384 | |
c906108c SS |
2385 | } |
2386 | ||
2387 | /* mips_addr_bits_remove - remove useless address bits */ | |
2388 | ||
875e1767 | 2389 | static CORE_ADDR |
acdb74a0 | 2390 | mips_addr_bits_remove (CORE_ADDR addr) |
c906108c | 2391 | { |
480d3dd2 | 2392 | struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); |
6d82d43b | 2393 | if (mips_mask_address_p (tdep) && (((ULONGEST) addr) >> 32 == 0xffffffffUL)) |
8fa9cfa1 AC |
2394 | /* This hack is a work-around for existing boards using PMON, the |
2395 | simulator, and any other 64-bit targets that doesn't have true | |
2396 | 64-bit addressing. On these targets, the upper 32 bits of | |
2397 | addresses are ignored by the hardware. Thus, the PC or SP are | |
2398 | likely to have been sign extended to all 1s by instruction | |
2399 | sequences that load 32-bit addresses. For example, a typical | |
2400 | piece of code that loads an address is this: | |
2401 | ||
2402 | lui $r2, <upper 16 bits> | |
2403 | ori $r2, <lower 16 bits> | |
2404 | ||
2405 | But the lui sign-extends the value such that the upper 32 bits | |
2406 | may be all 1s. The workaround is simply to mask off these | |
2407 | bits. In the future, gcc may be changed to support true 64-bit | |
2408 | addressing, and this masking will have to be disabled. */ | |
2409 | return addr &= 0xffffffffUL; | |
2410 | else | |
2411 | return addr; | |
c906108c SS |
2412 | } |
2413 | ||
9022177c DJ |
2414 | /* mips_software_single_step() is called just before we want to resume |
2415 | the inferior, if we want to single-step it but there is no hardware | |
75c9abc6 | 2416 | or kernel single-step support (MIPS on GNU/Linux for example). We find |
9022177c DJ |
2417 | the target of the coming instruction and breakpoint it. |
2418 | ||
2419 | single_step is also called just after the inferior stops. If we had | |
2420 | set up a simulated single-step, we undo our damage. */ | |
2421 | ||
2422 | void | |
2423 | mips_software_single_step (enum target_signal sig, int insert_breakpoints_p) | |
2424 | { | |
2425 | static CORE_ADDR next_pc; | |
2426 | typedef char binsn_quantum[BREAKPOINT_MAX]; | |
2427 | static binsn_quantum break_mem; | |
2428 | CORE_ADDR pc; | |
2429 | ||
2430 | if (insert_breakpoints_p) | |
2431 | { | |
b6cb9035 | 2432 | pc = read_register (mips_regnum (current_gdbarch)->pc); |
9022177c DJ |
2433 | next_pc = mips_next_pc (pc); |
2434 | ||
2435 | target_insert_breakpoint (next_pc, break_mem); | |
2436 | } | |
2437 | else | |
2438 | target_remove_breakpoint (next_pc, break_mem); | |
2439 | } | |
2440 | ||
c906108c | 2441 | static struct mips_extra_func_info temp_proc_desc; |
fe29b929 | 2442 | |
e0f7ec59 AC |
2443 | /* Set a register's saved stack address in temp_saved_regs. If an |
2444 | address has already been set for this register, do nothing; this | |
2445 | way we will only recognize the first save of a given register in a | |
a4b8ebc8 AC |
2446 | function prologue. |
2447 | ||
2448 | For simplicity, save the address in both [0 .. NUM_REGS) and | |
2449 | [NUM_REGS .. 2*NUM_REGS). Strictly speaking, only the second range | |
2450 | is used as it is only second range (the ABI instead of ISA | |
2451 | registers) that comes into play when finding saved registers in a | |
2452 | frame. */ | |
c906108c SS |
2453 | |
2454 | static void | |
c9343fd1 AC |
2455 | set_reg_offset (struct mips_frame_cache *this_cache, int regnum, |
2456 | CORE_ADDR offset) | |
c906108c | 2457 | { |
c9343fd1 AC |
2458 | if (this_cache != NULL |
2459 | && this_cache->saved_regs[regnum].addr == 0) | |
a4b8ebc8 | 2460 | { |
c9343fd1 AC |
2461 | this_cache->saved_regs[regnum + 0 * NUM_REGS].addr = offset; |
2462 | this_cache->saved_regs[regnum + 1 * NUM_REGS].addr = offset; | |
a4b8ebc8 | 2463 | } |
c906108c SS |
2464 | } |
2465 | ||
2466 | ||
2467 | /* Test whether the PC points to the return instruction at the | |
2468 | end of a function. */ | |
2469 | ||
c5aa993b | 2470 | static int |
acdb74a0 | 2471 | mips_about_to_return (CORE_ADDR pc) |
c906108c SS |
2472 | { |
2473 | if (pc_is_mips16 (pc)) | |
2474 | /* This mips16 case isn't necessarily reliable. Sometimes the compiler | |
2475 | generates a "jr $ra"; other times it generates code to load | |
2476 | the return address from the stack to an accessible register (such | |
2477 | as $a3), then a "jr" using that register. This second case | |
2478 | is almost impossible to distinguish from an indirect jump | |
2479 | used for switch statements, so we don't even try. */ | |
2480 | return mips_fetch_instruction (pc) == 0xe820; /* jr $ra */ | |
2481 | else | |
2482 | return mips_fetch_instruction (pc) == 0x3e00008; /* jr $ra */ | |
2483 | } | |
2484 | ||
2485 | ||
2486 | /* This fencepost looks highly suspicious to me. Removing it also | |
2487 | seems suspicious as it could affect remote debugging across serial | |
2488 | lines. */ | |
2489 | ||
2490 | static CORE_ADDR | |
acdb74a0 | 2491 | heuristic_proc_start (CORE_ADDR pc) |
c906108c | 2492 | { |
c5aa993b JM |
2493 | CORE_ADDR start_pc; |
2494 | CORE_ADDR fence; | |
2495 | int instlen; | |
2496 | int seen_adjsp = 0; | |
c906108c | 2497 | |
c5aa993b JM |
2498 | pc = ADDR_BITS_REMOVE (pc); |
2499 | start_pc = pc; | |
2500 | fence = start_pc - heuristic_fence_post; | |
2501 | if (start_pc == 0) | |
2502 | return 0; | |
c906108c | 2503 | |
6d82d43b | 2504 | if (heuristic_fence_post == UINT_MAX || fence < VM_MIN_ADDRESS) |
c5aa993b | 2505 | fence = VM_MIN_ADDRESS; |
c906108c | 2506 | |
c5aa993b | 2507 | instlen = pc_is_mips16 (pc) ? MIPS16_INSTLEN : MIPS_INSTLEN; |
c906108c | 2508 | |
c5aa993b JM |
2509 | /* search back for previous return */ |
2510 | for (start_pc -= instlen;; start_pc -= instlen) | |
2511 | if (start_pc < fence) | |
2512 | { | |
2513 | /* It's not clear to me why we reach this point when | |
c0236d92 | 2514 | stop_soon, but with this test, at least we |
c5aa993b JM |
2515 | don't print out warnings for every child forked (eg, on |
2516 | decstation). 22apr93 rich@cygnus.com. */ | |
c0236d92 | 2517 | if (stop_soon == NO_STOP_QUIETLY) |
c906108c | 2518 | { |
c5aa993b JM |
2519 | static int blurb_printed = 0; |
2520 | ||
dc305454 MS |
2521 | warning ("GDB can't find the start of the function at 0x%s.", |
2522 | paddr_nz (pc)); | |
c5aa993b JM |
2523 | |
2524 | if (!blurb_printed) | |
c906108c | 2525 | { |
c5aa993b JM |
2526 | /* This actually happens frequently in embedded |
2527 | development, when you first connect to a board | |
2528 | and your stack pointer and pc are nowhere in | |
2529 | particular. This message needs to give people | |
2530 | in that situation enough information to | |
2531 | determine that it's no big deal. */ | |
2532 | printf_filtered ("\n\ | |
cd0fc7c3 SS |
2533 | GDB is unable to find the start of the function at 0x%s\n\ |
2534 | and thus can't determine the size of that function's stack frame.\n\ | |
2535 | This means that GDB may be unable to access that stack frame, or\n\ | |
2536 | the frames below it.\n\ | |
2537 | This problem is most likely caused by an invalid program counter or\n\ | |
2538 | stack pointer.\n\ | |
2539 | However, if you think GDB should simply search farther back\n\ | |
2540 | from 0x%s for code which looks like the beginning of a\n\ | |
2541 | function, you can increase the range of the search using the `set\n\ | |
6d82d43b | 2542 | heuristic-fence-post' command.\n", paddr_nz (pc), paddr_nz (pc)); |
c5aa993b | 2543 | blurb_printed = 1; |
c906108c | 2544 | } |
c906108c SS |
2545 | } |
2546 | ||
c5aa993b JM |
2547 | return 0; |
2548 | } | |
2549 | else if (pc_is_mips16 (start_pc)) | |
2550 | { | |
2551 | unsigned short inst; | |
2552 | ||
2553 | /* On MIPS16, any one of the following is likely to be the | |
2554 | start of a function: | |
2555 | entry | |
2556 | addiu sp,-n | |
2557 | daddiu sp,-n | |
2558 | extend -n followed by 'addiu sp,+n' or 'daddiu sp,+n' */ | |
2559 | inst = mips_fetch_instruction (start_pc); | |
2560 | if (((inst & 0xf81f) == 0xe809 && (inst & 0x700) != 0x700) /* entry */ | |
2561 | || (inst & 0xff80) == 0x6380 /* addiu sp,-n */ | |
2562 | || (inst & 0xff80) == 0xfb80 /* daddiu sp,-n */ | |
2563 | || ((inst & 0xf810) == 0xf010 && seen_adjsp)) /* extend -n */ | |
2564 | break; | |
2565 | else if ((inst & 0xff00) == 0x6300 /* addiu sp */ | |
2566 | || (inst & 0xff00) == 0xfb00) /* daddiu sp */ | |
2567 | seen_adjsp = 1; | |
2568 | else | |
2569 | seen_adjsp = 0; | |
2570 | } | |
2571 | else if (mips_about_to_return (start_pc)) | |
2572 | { | |
2573 | start_pc += 2 * MIPS_INSTLEN; /* skip return, and its delay slot */ | |
2574 | break; | |
2575 | } | |
2576 | ||
c5aa993b | 2577 | return start_pc; |
c906108c SS |
2578 | } |
2579 | ||
2580 | /* Fetch the immediate value from a MIPS16 instruction. | |
2581 | If the previous instruction was an EXTEND, use it to extend | |
2582 | the upper bits of the immediate value. This is a helper function | |
2583 | for mips16_heuristic_proc_desc. */ | |
2584 | ||
2585 | static int | |
acdb74a0 AC |
2586 | mips16_get_imm (unsigned short prev_inst, /* previous instruction */ |
2587 | unsigned short inst, /* current instruction */ | |
6d82d43b AC |
2588 | int nbits, /* number of bits in imm field */ |
2589 | int scale, /* scale factor to be applied to imm */ | |
2590 | int is_signed) /* is the imm field signed? */ | |
c906108c SS |
2591 | { |
2592 | int offset; | |
2593 | ||
2594 | if ((prev_inst & 0xf800) == 0xf000) /* prev instruction was EXTEND? */ | |
2595 | { | |
2596 | offset = ((prev_inst & 0x1f) << 11) | (prev_inst & 0x7e0); | |
c5aa993b | 2597 | if (offset & 0x8000) /* check for negative extend */ |
c906108c SS |
2598 | offset = 0 - (0x10000 - (offset & 0xffff)); |
2599 | return offset | (inst & 0x1f); | |
2600 | } | |
2601 | else | |
2602 | { | |
2603 | int max_imm = 1 << nbits; | |
2604 | int mask = max_imm - 1; | |
2605 | int sign_bit = max_imm >> 1; | |
2606 | ||
2607 | offset = inst & mask; | |
2608 | if (is_signed && (offset & sign_bit)) | |
2609 | offset = 0 - (max_imm - offset); | |
2610 | return offset * scale; | |
2611 | } | |
2612 | } | |
2613 | ||
2614 | ||
2615 | /* Fill in values in temp_proc_desc based on the MIPS16 instruction | |
2616 | stream from start_pc to limit_pc. */ | |
2617 | ||
2618 | static void | |
acdb74a0 | 2619 | mips16_heuristic_proc_desc (CORE_ADDR start_pc, CORE_ADDR limit_pc, |
c9343fd1 AC |
2620 | CORE_ADDR sp, |
2621 | struct frame_info *next_frame, | |
2622 | struct mips_frame_cache *this_cache) | |
c906108c SS |
2623 | { |
2624 | CORE_ADDR cur_pc; | |
2625 | CORE_ADDR frame_addr = 0; /* Value of $r17, used as frame pointer */ | |
2626 | unsigned short prev_inst = 0; /* saved copy of previous instruction */ | |
2627 | unsigned inst = 0; /* current instruction */ | |
2628 | unsigned entry_inst = 0; /* the entry instruction */ | |
2629 | int reg, offset; | |
480d3dd2 | 2630 | struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); |
c906108c | 2631 | |
c5aa993b JM |
2632 | PROC_FRAME_OFFSET (&temp_proc_desc) = 0; /* size of stack frame */ |
2633 | PROC_FRAME_ADJUST (&temp_proc_desc) = 0; /* offset of FP from SP */ | |
c906108c SS |
2634 | |
2635 | for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += MIPS16_INSTLEN) | |
2636 | { | |
2637 | /* Save the previous instruction. If it's an EXTEND, we'll extract | |
2638 | the immediate offset extension from it in mips16_get_imm. */ | |
2639 | prev_inst = inst; | |
2640 | ||
2641 | /* Fetch and decode the instruction. */ | |
2642 | inst = (unsigned short) mips_fetch_instruction (cur_pc); | |
c5aa993b | 2643 | if ((inst & 0xff00) == 0x6300 /* addiu sp */ |
6d82d43b | 2644 | || (inst & 0xff00) == 0xfb00) /* daddiu sp */ |
c906108c SS |
2645 | { |
2646 | offset = mips16_get_imm (prev_inst, inst, 8, 8, 1); | |
c5aa993b JM |
2647 | if (offset < 0) /* negative stack adjustment? */ |
2648 | PROC_FRAME_OFFSET (&temp_proc_desc) -= offset; | |
c906108c SS |
2649 | else |
2650 | /* Exit loop if a positive stack adjustment is found, which | |
2651 | usually means that the stack cleanup code in the function | |
2652 | epilogue is reached. */ | |
2653 | break; | |
2654 | } | |
2655 | else if ((inst & 0xf800) == 0xd000) /* sw reg,n($sp) */ | |
2656 | { | |
2657 | offset = mips16_get_imm (prev_inst, inst, 8, 4, 0); | |
2658 | reg = mips16_to_32_reg[(inst & 0x700) >> 8]; | |
c5aa993b | 2659 | PROC_REG_MASK (&temp_proc_desc) |= (1 << reg); |
c9343fd1 | 2660 | set_reg_offset (this_cache, reg, sp + offset); |
c906108c SS |
2661 | } |
2662 | else if ((inst & 0xff00) == 0xf900) /* sd reg,n($sp) */ | |
2663 | { | |
2664 | offset = mips16_get_imm (prev_inst, inst, 5, 8, 0); | |
2665 | reg = mips16_to_32_reg[(inst & 0xe0) >> 5]; | |
c5aa993b | 2666 | PROC_REG_MASK (&temp_proc_desc) |= (1 << reg); |
c9343fd1 | 2667 | set_reg_offset (this_cache, reg, sp + offset); |
c906108c SS |
2668 | } |
2669 | else if ((inst & 0xff00) == 0x6200) /* sw $ra,n($sp) */ | |
2670 | { | |
2671 | offset = mips16_get_imm (prev_inst, inst, 8, 4, 0); | |
c5aa993b | 2672 | PROC_REG_MASK (&temp_proc_desc) |= (1 << RA_REGNUM); |
c9343fd1 | 2673 | set_reg_offset (this_cache, RA_REGNUM, sp + offset); |
c906108c SS |
2674 | } |
2675 | else if ((inst & 0xff00) == 0xfa00) /* sd $ra,n($sp) */ | |
2676 | { | |
2677 | offset = mips16_get_imm (prev_inst, inst, 8, 8, 0); | |
c5aa993b | 2678 | PROC_REG_MASK (&temp_proc_desc) |= (1 << RA_REGNUM); |
c9343fd1 | 2679 | set_reg_offset (this_cache, RA_REGNUM, sp + offset); |
c906108c | 2680 | } |
c5aa993b | 2681 | else if (inst == 0x673d) /* move $s1, $sp */ |
c906108c SS |
2682 | { |
2683 | frame_addr = sp; | |
2684 | PROC_FRAME_REG (&temp_proc_desc) = 17; | |
2685 | } | |
2686 | else if ((inst & 0xff00) == 0x0100) /* addiu $s1,sp,n */ | |
2687 | { | |
2688 | offset = mips16_get_imm (prev_inst, inst, 8, 4, 0); | |
2689 | frame_addr = sp + offset; | |
2690 | PROC_FRAME_REG (&temp_proc_desc) = 17; | |
2691 | PROC_FRAME_ADJUST (&temp_proc_desc) = offset; | |
2692 | } | |
2693 | else if ((inst & 0xFF00) == 0xd900) /* sw reg,offset($s1) */ | |
2694 | { | |
2695 | offset = mips16_get_imm (prev_inst, inst, 5, 4, 0); | |
2696 | reg = mips16_to_32_reg[(inst & 0xe0) >> 5]; | |
c5aa993b | 2697 | PROC_REG_MASK (&temp_proc_desc) |= 1 << reg; |
c9343fd1 | 2698 | set_reg_offset (this_cache, reg, frame_addr + offset); |
c906108c SS |
2699 | } |
2700 | else if ((inst & 0xFF00) == 0x7900) /* sd reg,offset($s1) */ | |
2701 | { | |
2702 | offset = mips16_get_imm (prev_inst, inst, 5, 8, 0); | |
2703 | reg = mips16_to_32_reg[(inst & 0xe0) >> 5]; | |
c5aa993b | 2704 | PROC_REG_MASK (&temp_proc_desc) |= 1 << reg; |
c9343fd1 | 2705 | set_reg_offset (this_cache, reg, frame_addr + offset); |
c906108c | 2706 | } |
c5aa993b JM |
2707 | else if ((inst & 0xf81f) == 0xe809 && (inst & 0x700) != 0x700) /* entry */ |
2708 | entry_inst = inst; /* save for later processing */ | |
c906108c | 2709 | else if ((inst & 0xf800) == 0x1800) /* jal(x) */ |
c5aa993b | 2710 | cur_pc += MIPS16_INSTLEN; /* 32-bit instruction */ |
c906108c SS |
2711 | } |
2712 | ||
c5aa993b JM |
2713 | /* The entry instruction is typically the first instruction in a function, |
2714 | and it stores registers at offsets relative to the value of the old SP | |
2715 | (before the prologue). But the value of the sp parameter to this | |
2716 | function is the new SP (after the prologue has been executed). So we | |
2717 | can't calculate those offsets until we've seen the entire prologue, | |
2718 | and can calculate what the old SP must have been. */ | |
2719 | if (entry_inst != 0) | |
2720 | { | |
2721 | int areg_count = (entry_inst >> 8) & 7; | |
2722 | int sreg_count = (entry_inst >> 6) & 3; | |
c906108c | 2723 | |
c5aa993b JM |
2724 | /* The entry instruction always subtracts 32 from the SP. */ |
2725 | PROC_FRAME_OFFSET (&temp_proc_desc) += 32; | |
c906108c | 2726 | |
c5aa993b JM |
2727 | /* Now we can calculate what the SP must have been at the |
2728 | start of the function prologue. */ | |
2729 | sp += PROC_FRAME_OFFSET (&temp_proc_desc); | |
c906108c | 2730 | |
c5aa993b JM |
2731 | /* Check if a0-a3 were saved in the caller's argument save area. */ |
2732 | for (reg = 4, offset = 0; reg < areg_count + 4; reg++) | |
2733 | { | |
2734 | PROC_REG_MASK (&temp_proc_desc) |= 1 << reg; | |
c9343fd1 | 2735 | set_reg_offset (this_cache, reg, sp + offset); |
13326b4e | 2736 | offset += mips_abi_regsize (current_gdbarch); |
c5aa993b | 2737 | } |
c906108c | 2738 | |
c5aa993b JM |
2739 | /* Check if the ra register was pushed on the stack. */ |
2740 | offset = -4; | |
2741 | if (entry_inst & 0x20) | |
2742 | { | |
2743 | PROC_REG_MASK (&temp_proc_desc) |= 1 << RA_REGNUM; | |
c9343fd1 | 2744 | set_reg_offset (this_cache, RA_REGNUM, sp + offset); |
13326b4e | 2745 | offset -= mips_abi_regsize (current_gdbarch); |
c5aa993b | 2746 | } |
c906108c | 2747 | |
c5aa993b JM |
2748 | /* Check if the s0 and s1 registers were pushed on the stack. */ |
2749 | for (reg = 16; reg < sreg_count + 16; reg++) | |
2750 | { | |
2751 | PROC_REG_MASK (&temp_proc_desc) |= 1 << reg; | |
c9343fd1 | 2752 | set_reg_offset (this_cache, reg, sp + offset); |
13326b4e | 2753 | offset -= mips_abi_regsize (current_gdbarch); |
c5aa993b JM |
2754 | } |
2755 | } | |
c906108c SS |
2756 | } |
2757 | ||
2758 | static void | |
fba45db2 | 2759 | mips32_heuristic_proc_desc (CORE_ADDR start_pc, CORE_ADDR limit_pc, |
c9343fd1 AC |
2760 | CORE_ADDR sp, struct frame_info *next_frame, |
2761 | struct mips_frame_cache *this_cache) | |
c906108c SS |
2762 | { |
2763 | CORE_ADDR cur_pc; | |
c5aa993b | 2764 | CORE_ADDR frame_addr = 0; /* Value of $r30. Used by gcc for frame-pointer */ |
c906108c | 2765 | restart: |
c5aa993b | 2766 | PROC_FRAME_OFFSET (&temp_proc_desc) = 0; |
c906108c SS |
2767 | PROC_FRAME_ADJUST (&temp_proc_desc) = 0; /* offset of FP from SP */ |
2768 | for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += MIPS_INSTLEN) | |
2769 | { | |
2770 | unsigned long inst, high_word, low_word; | |
2771 | int reg; | |
2772 | ||
2773 | /* Fetch the instruction. */ | |
2774 | inst = (unsigned long) mips_fetch_instruction (cur_pc); | |
2775 | ||
2776 | /* Save some code by pre-extracting some useful fields. */ | |
2777 | high_word = (inst >> 16) & 0xffff; | |
2778 | low_word = inst & 0xffff; | |
2779 | reg = high_word & 0x1f; | |
2780 | ||
c5aa993b | 2781 | if (high_word == 0x27bd /* addiu $sp,$sp,-i */ |
c906108c SS |
2782 | || high_word == 0x23bd /* addi $sp,$sp,-i */ |
2783 | || high_word == 0x67bd) /* daddiu $sp,$sp,-i */ | |
2784 | { | |
2785 | if (low_word & 0x8000) /* negative stack adjustment? */ | |
c5aa993b | 2786 | PROC_FRAME_OFFSET (&temp_proc_desc) += 0x10000 - low_word; |
c906108c SS |
2787 | else |
2788 | /* Exit loop if a positive stack adjustment is found, which | |
2789 | usually means that the stack cleanup code in the function | |
2790 | epilogue is reached. */ | |
2791 | break; | |
2792 | } | |
2793 | else if ((high_word & 0xFFE0) == 0xafa0) /* sw reg,offset($sp) */ | |
2794 | { | |
c5aa993b | 2795 | PROC_REG_MASK (&temp_proc_desc) |= 1 << reg; |
c9343fd1 | 2796 | set_reg_offset (this_cache, reg, sp + low_word); |
c906108c SS |
2797 | } |
2798 | else if ((high_word & 0xFFE0) == 0xffa0) /* sd reg,offset($sp) */ | |
2799 | { | |
d5ac5a39 AC |
2800 | /* Irix 6.2 N32 ABI uses sd instructions for saving $gp and |
2801 | $ra. */ | |
c5aa993b | 2802 | PROC_REG_MASK (&temp_proc_desc) |= 1 << reg; |
c9343fd1 | 2803 | set_reg_offset (this_cache, reg, sp + low_word); |
c906108c | 2804 | } |
c5aa993b | 2805 | else if (high_word == 0x27be) /* addiu $30,$sp,size */ |
c906108c SS |
2806 | { |
2807 | /* Old gcc frame, r30 is virtual frame pointer. */ | |
c5aa993b JM |
2808 | if ((long) low_word != PROC_FRAME_OFFSET (&temp_proc_desc)) |
2809 | frame_addr = sp + low_word; | |
f10683bb | 2810 | else if (PROC_FRAME_REG (&temp_proc_desc) == MIPS_SP_REGNUM) |
c906108c SS |
2811 | { |
2812 | unsigned alloca_adjust; | |
2813 | PROC_FRAME_REG (&temp_proc_desc) = 30; | |
a4b8ebc8 | 2814 | frame_addr = read_next_frame_reg (next_frame, NUM_REGS + 30); |
c5aa993b | 2815 | alloca_adjust = (unsigned) (frame_addr - (sp + low_word)); |
c906108c SS |
2816 | if (alloca_adjust > 0) |
2817 | { | |
2818 | /* FP > SP + frame_size. This may be because | |
2819 | * of an alloca or somethings similar. | |
2820 | * Fix sp to "pre-alloca" value, and try again. | |
2821 | */ | |
2822 | sp += alloca_adjust; | |
2823 | goto restart; | |
2824 | } | |
2825 | } | |
2826 | } | |
c5aa993b JM |
2827 | /* move $30,$sp. With different versions of gas this will be either |
2828 | `addu $30,$sp,$zero' or `or $30,$sp,$zero' or `daddu 30,sp,$0'. | |
2829 | Accept any one of these. */ | |
c906108c SS |
2830 | else if (inst == 0x03A0F021 || inst == 0x03a0f025 || inst == 0x03a0f02d) |
2831 | { | |
2832 | /* New gcc frame, virtual frame pointer is at r30 + frame_size. */ | |
f10683bb | 2833 | if (PROC_FRAME_REG (&temp_proc_desc) == MIPS_SP_REGNUM) |
c906108c SS |
2834 | { |
2835 | unsigned alloca_adjust; | |
2836 | PROC_FRAME_REG (&temp_proc_desc) = 30; | |
a4b8ebc8 | 2837 | frame_addr = read_next_frame_reg (next_frame, NUM_REGS + 30); |
c5aa993b | 2838 | alloca_adjust = (unsigned) (frame_addr - sp); |
c906108c SS |
2839 | if (alloca_adjust > 0) |
2840 | { | |
2841 | /* FP > SP + frame_size. This may be because | |
2842 | * of an alloca or somethings similar. | |
2843 | * Fix sp to "pre-alloca" value, and try again. | |
2844 | */ | |
2845 | sp += alloca_adjust; | |
2846 | goto restart; | |
2847 | } | |
2848 | } | |
2849 | } | |
c5aa993b | 2850 | else if ((high_word & 0xFFE0) == 0xafc0) /* sw reg,offset($30) */ |
c906108c | 2851 | { |
c5aa993b | 2852 | PROC_REG_MASK (&temp_proc_desc) |= 1 << reg; |
c9343fd1 | 2853 | set_reg_offset (this_cache, reg, frame_addr + low_word); |
c906108c SS |
2854 | } |
2855 | } | |
2856 | } | |
2857 | ||
2858 | static mips_extra_func_info_t | |
acdb74a0 | 2859 | heuristic_proc_desc (CORE_ADDR start_pc, CORE_ADDR limit_pc, |
c9343fd1 AC |
2860 | struct frame_info *next_frame, |
2861 | struct mips_frame_cache *this_cache) | |
c906108c | 2862 | { |
479412cd DJ |
2863 | CORE_ADDR sp; |
2864 | ||
465f7520 AC |
2865 | /* Can be called when there's no process, and hence when there's no |
2866 | NEXT_FRAME. */ | |
2867 | if (next_frame != NULL) | |
f10683bb | 2868 | sp = read_next_frame_reg (next_frame, NUM_REGS + MIPS_SP_REGNUM); |
479412cd DJ |
2869 | else |
2870 | sp = 0; | |
c906108c | 2871 | |
c5aa993b JM |
2872 | if (start_pc == 0) |
2873 | return NULL; | |
2874 | memset (&temp_proc_desc, '\0', sizeof (temp_proc_desc)); | |
c906108c | 2875 | PROC_LOW_ADDR (&temp_proc_desc) = start_pc; |
f10683bb | 2876 | PROC_FRAME_REG (&temp_proc_desc) = MIPS_SP_REGNUM; |
c906108c SS |
2877 | PROC_PC_REG (&temp_proc_desc) = RA_REGNUM; |
2878 | ||
2879 | if (start_pc + 200 < limit_pc) | |
2880 | limit_pc = start_pc + 200; | |
2881 | if (pc_is_mips16 (start_pc)) | |
c9343fd1 AC |
2882 | mips16_heuristic_proc_desc (start_pc, limit_pc, sp, |
2883 | next_frame, this_cache); | |
c906108c | 2884 | else |
c9343fd1 AC |
2885 | mips32_heuristic_proc_desc (start_pc, limit_pc, sp, |
2886 | next_frame, this_cache); | |
c906108c SS |
2887 | return &temp_proc_desc; |
2888 | } | |
2889 | ||
6c0d6680 DJ |
2890 | struct mips_objfile_private |
2891 | { | |
2892 | bfd_size_type size; | |
2893 | char *contents; | |
2894 | }; | |
2895 | ||
2896 | /* Global used to communicate between non_heuristic_proc_desc and | |
2897 | compare_pdr_entries within qsort (). */ | |
2898 | static bfd *the_bfd; | |
2899 | ||
2900 | static int | |
2901 | compare_pdr_entries (const void *a, const void *b) | |
2902 | { | |
2903 | CORE_ADDR lhs = bfd_get_32 (the_bfd, (bfd_byte *) a); | |
2904 | CORE_ADDR rhs = bfd_get_32 (the_bfd, (bfd_byte *) b); | |
2905 | ||
2906 | if (lhs < rhs) | |
2907 | return -1; | |
2908 | else if (lhs == rhs) | |
2909 | return 0; | |
2910 | else | |
2911 | return 1; | |
2912 | } | |
2913 | ||
c906108c | 2914 | static mips_extra_func_info_t |
acdb74a0 | 2915 | non_heuristic_proc_desc (CORE_ADDR pc, CORE_ADDR *addrptr) |
c906108c SS |
2916 | { |
2917 | CORE_ADDR startaddr; | |
2918 | mips_extra_func_info_t proc_desc; | |
c5aa993b | 2919 | struct block *b = block_for_pc (pc); |
c906108c | 2920 | struct symbol *sym; |
6c0d6680 DJ |
2921 | struct obj_section *sec; |
2922 | struct mips_objfile_private *priv; | |
2923 | ||
c906108c SS |
2924 | find_pc_partial_function (pc, NULL, &startaddr, NULL); |
2925 | if (addrptr) | |
2926 | *addrptr = startaddr; | |
6c0d6680 DJ |
2927 | |
2928 | priv = NULL; | |
2929 | ||
2930 | sec = find_pc_section (pc); | |
2931 | if (sec != NULL) | |
c906108c | 2932 | { |
8d5f9dcb | 2933 | priv = (struct mips_objfile_private *) objfile_data (sec->objfile, mips_pdr_data); |
6c0d6680 DJ |
2934 | |
2935 | /* Search the ".pdr" section generated by GAS. This includes most of | |
6d82d43b | 2936 | the information normally found in ECOFF PDRs. */ |
6c0d6680 DJ |
2937 | |
2938 | the_bfd = sec->objfile->obfd; | |
2939 | if (priv == NULL | |
2940 | && (the_bfd->format == bfd_object | |
2941 | && bfd_get_flavour (the_bfd) == bfd_target_elf_flavour | |
2942 | && elf_elfheader (the_bfd)->e_ident[EI_CLASS] == ELFCLASS64)) | |
2943 | { | |
2944 | /* Right now GAS only outputs the address as a four-byte sequence. | |
2945 | This means that we should not bother with this method on 64-bit | |
2946 | targets (until that is fixed). */ | |
2947 | ||
8b92e4d5 | 2948 | priv = obstack_alloc (&sec->objfile->objfile_obstack, |
6c0d6680 DJ |
2949 | sizeof (struct mips_objfile_private)); |
2950 | priv->size = 0; | |
8d5f9dcb | 2951 | set_objfile_data (sec->objfile, mips_pdr_data, priv); |
6c0d6680 DJ |
2952 | } |
2953 | else if (priv == NULL) | |
2954 | { | |
2955 | asection *bfdsec; | |
2956 | ||
8b92e4d5 | 2957 | priv = obstack_alloc (&sec->objfile->objfile_obstack, |
6c0d6680 DJ |
2958 | sizeof (struct mips_objfile_private)); |
2959 | ||
2960 | bfdsec = bfd_get_section_by_name (sec->objfile->obfd, ".pdr"); | |
2961 | if (bfdsec != NULL) | |
2962 | { | |
2963 | priv->size = bfd_section_size (sec->objfile->obfd, bfdsec); | |
8b92e4d5 | 2964 | priv->contents = obstack_alloc (&sec->objfile->objfile_obstack, |
6c0d6680 DJ |
2965 | priv->size); |
2966 | bfd_get_section_contents (sec->objfile->obfd, bfdsec, | |
2967 | priv->contents, 0, priv->size); | |
2968 | ||
2969 | /* In general, the .pdr section is sorted. However, in the | |
6d82d43b AC |
2970 | presence of multiple code sections (and other corner cases) |
2971 | it can become unsorted. Sort it so that we can use a faster | |
2972 | binary search. */ | |
2973 | qsort (priv->contents, priv->size / 32, 32, | |
2974 | compare_pdr_entries); | |
6c0d6680 DJ |
2975 | } |
2976 | else | |
2977 | priv->size = 0; | |
2978 | ||
8d5f9dcb | 2979 | set_objfile_data (sec->objfile, mips_pdr_data, priv); |
6c0d6680 DJ |
2980 | } |
2981 | the_bfd = NULL; | |
2982 | ||
2983 | if (priv->size != 0) | |
2984 | { | |
2985 | int low, mid, high; | |
2986 | char *ptr; | |
34fcf120 | 2987 | CORE_ADDR pdr_pc; |
6c0d6680 DJ |
2988 | |
2989 | low = 0; | |
2990 | high = priv->size / 32; | |
2991 | ||
34fcf120 DJ |
2992 | /* We've found a .pdr section describing this objfile. We want to |
2993 | find the entry which describes this code address. The .pdr | |
2994 | information is not very descriptive; we have only a function | |
2995 | start address. We have to look for the closest entry, because | |
2996 | the local symbol at the beginning of this function may have | |
2997 | been stripped - so if we ask the symbol table for the start | |
2998 | address we may get a preceding global function. */ | |
2999 | ||
3000 | /* First, find the last .pdr entry starting at or before PC. */ | |
6c0d6680 DJ |
3001 | do |
3002 | { | |
6c0d6680 DJ |
3003 | mid = (low + high) / 2; |
3004 | ||
3005 | ptr = priv->contents + mid * 32; | |
3006 | pdr_pc = bfd_get_signed_32 (sec->objfile->obfd, ptr); | |
3007 | pdr_pc += ANOFFSET (sec->objfile->section_offsets, | |
3008 | SECT_OFF_TEXT (sec->objfile)); | |
34fcf120 DJ |
3009 | |
3010 | if (pdr_pc > pc) | |
6c0d6680 DJ |
3011 | high = mid; |
3012 | else | |
3013 | low = mid + 1; | |
3014 | } | |
3015 | while (low != high); | |
3016 | ||
34fcf120 DJ |
3017 | /* Both low and high point one past the PDR of interest. If |
3018 | both are zero, that means this PC is before any region | |
3019 | covered by a PDR, i.e. pdr_pc for the first PDR entry is | |
3020 | greater than PC. */ | |
3021 | if (low > 0) | |
3022 | { | |
3023 | ptr = priv->contents + (low - 1) * 32; | |
3024 | pdr_pc = bfd_get_signed_32 (sec->objfile->obfd, ptr); | |
3025 | pdr_pc += ANOFFSET (sec->objfile->section_offsets, | |
3026 | SECT_OFF_TEXT (sec->objfile)); | |
3027 | } | |
3028 | ||
3029 | /* We don't have a range, so we have no way to know for sure | |
3030 | whether we're in the correct PDR or a PDR for a preceding | |
3031 | function and the current function was a stripped local | |
3032 | symbol. But if the PDR's PC is at least as great as the | |
3033 | best guess from the symbol table, assume that it does cover | |
3034 | the right area; if a .pdr section is present at all then | |
3035 | nearly every function will have an entry. The biggest exception | |
3036 | will be the dynamic linker stubs; conveniently these are | |
3037 | placed before .text instead of after. */ | |
3038 | ||
3039 | if (pc >= pdr_pc && pdr_pc >= startaddr) | |
6c0d6680 DJ |
3040 | { |
3041 | struct symbol *sym = find_pc_function (pc); | |
3042 | ||
34fcf120 DJ |
3043 | if (addrptr) |
3044 | *addrptr = pdr_pc; | |
3045 | ||
6c0d6680 DJ |
3046 | /* Fill in what we need of the proc_desc. */ |
3047 | proc_desc = (mips_extra_func_info_t) | |
8b92e4d5 | 3048 | obstack_alloc (&sec->objfile->objfile_obstack, |
6c0d6680 | 3049 | sizeof (struct mips_extra_func_info)); |
34fcf120 | 3050 | PROC_LOW_ADDR (proc_desc) = pdr_pc; |
6c0d6680 DJ |
3051 | |
3052 | /* Only used for dummy frames. */ | |
3053 | PROC_HIGH_ADDR (proc_desc) = 0; | |
3054 | ||
3055 | PROC_FRAME_OFFSET (proc_desc) | |
3056 | = bfd_get_32 (sec->objfile->obfd, ptr + 20); | |
3057 | PROC_FRAME_REG (proc_desc) = bfd_get_32 (sec->objfile->obfd, | |
3058 | ptr + 24); | |
3059 | PROC_FRAME_ADJUST (proc_desc) = 0; | |
3060 | PROC_REG_MASK (proc_desc) = bfd_get_32 (sec->objfile->obfd, | |
3061 | ptr + 4); | |
3062 | PROC_FREG_MASK (proc_desc) = bfd_get_32 (sec->objfile->obfd, | |
3063 | ptr + 12); | |
3064 | PROC_REG_OFFSET (proc_desc) = bfd_get_32 (sec->objfile->obfd, | |
3065 | ptr + 8); | |
3066 | PROC_FREG_OFFSET (proc_desc) | |
3067 | = bfd_get_32 (sec->objfile->obfd, ptr + 16); | |
3068 | PROC_PC_REG (proc_desc) = bfd_get_32 (sec->objfile->obfd, | |
3069 | ptr + 28); | |
3070 | proc_desc->pdr.isym = (long) sym; | |
3071 | ||
3072 | return proc_desc; | |
3073 | } | |
3074 | } | |
c906108c SS |
3075 | } |
3076 | ||
6c0d6680 DJ |
3077 | if (b == NULL) |
3078 | return NULL; | |
3079 | ||
3080 | if (startaddr > BLOCK_START (b)) | |
3081 | { | |
3082 | /* This is the "pathological" case referred to in a comment in | |
6d82d43b AC |
3083 | print_frame_info. It might be better to move this check into |
3084 | symbol reading. */ | |
6c0d6680 DJ |
3085 | return NULL; |
3086 | } | |
3087 | ||
176620f1 | 3088 | sym = lookup_symbol (MIPS_EFI_SYMBOL_NAME, b, LABEL_DOMAIN, 0, NULL); |
6c0d6680 | 3089 | |
c906108c SS |
3090 | /* If we never found a PDR for this function in symbol reading, then |
3091 | examine prologues to find the information. */ | |
3092 | if (sym) | |
3093 | { | |
3094 | proc_desc = (mips_extra_func_info_t) SYMBOL_VALUE (sym); | |
3095 | if (PROC_FRAME_REG (proc_desc) == -1) | |
3096 | return NULL; | |
3097 | else | |
3098 | return proc_desc; | |
3099 | } | |
3100 | else | |
3101 | return NULL; | |
3102 | } | |
3103 | ||
c906108c SS |
3104 | /* MIPS stack frames are almost impenetrable. When execution stops, |
3105 | we basically have to look at symbol information for the function | |
3106 | that we stopped in, which tells us *which* register (if any) is | |
3107 | the base of the frame pointer, and what offset from that register | |
361d1df0 | 3108 | the frame itself is at. |
c906108c SS |
3109 | |
3110 | This presents a problem when trying to examine a stack in memory | |
3111 | (that isn't executing at the moment), using the "frame" command. We | |
3112 | don't have a PC, nor do we have any registers except SP. | |
3113 | ||
3114 | This routine takes two arguments, SP and PC, and tries to make the | |
3115 | cached frames look as if these two arguments defined a frame on the | |
3116 | cache. This allows the rest of info frame to extract the important | |
3117 | arguments without difficulty. */ | |
3118 | ||
3119 | struct frame_info * | |
acdb74a0 | 3120 | setup_arbitrary_frame (int argc, CORE_ADDR *argv) |
c906108c SS |
3121 | { |
3122 | if (argc != 2) | |
3123 | error ("MIPS frame specifications require two arguments: sp and pc"); | |
3124 | ||
3125 | return create_new_frame (argv[0], argv[1]); | |
3126 | } | |
3127 | ||
f09ded24 AC |
3128 | /* According to the current ABI, should the type be passed in a |
3129 | floating-point register (assuming that there is space)? When there | |
3130 | is no FPU, FP are not even considered as possibile candidates for | |
3131 | FP registers and, consequently this returns false - forces FP | |
3132 | arguments into integer registers. */ | |
3133 | ||
3134 | static int | |
3135 | fp_register_arg_p (enum type_code typecode, struct type *arg_type) | |
3136 | { | |
3137 | return ((typecode == TYPE_CODE_FLT | |
3138 | || (MIPS_EABI | |
6d82d43b AC |
3139 | && (typecode == TYPE_CODE_STRUCT |
3140 | || typecode == TYPE_CODE_UNION) | |
f09ded24 AC |
3141 | && TYPE_NFIELDS (arg_type) == 1 |
3142 | && TYPE_CODE (TYPE_FIELD_TYPE (arg_type, 0)) == TYPE_CODE_FLT)) | |
c86b5b38 | 3143 | && MIPS_FPU_TYPE != MIPS_FPU_NONE); |
f09ded24 AC |
3144 | } |
3145 | ||
49e790b0 DJ |
3146 | /* On o32, argument passing in GPRs depends on the alignment of the type being |
3147 | passed. Return 1 if this type must be aligned to a doubleword boundary. */ | |
3148 | ||
3149 | static int | |
3150 | mips_type_needs_double_align (struct type *type) | |
3151 | { | |
3152 | enum type_code typecode = TYPE_CODE (type); | |
361d1df0 | 3153 | |
49e790b0 DJ |
3154 | if (typecode == TYPE_CODE_FLT && TYPE_LENGTH (type) == 8) |
3155 | return 1; | |
3156 | else if (typecode == TYPE_CODE_STRUCT) | |
3157 | { | |
3158 | if (TYPE_NFIELDS (type) < 1) | |
3159 | return 0; | |
3160 | return mips_type_needs_double_align (TYPE_FIELD_TYPE (type, 0)); | |
3161 | } | |
3162 | else if (typecode == TYPE_CODE_UNION) | |
3163 | { | |
361d1df0 | 3164 | int i, n; |
49e790b0 DJ |
3165 | |
3166 | n = TYPE_NFIELDS (type); | |
3167 | for (i = 0; i < n; i++) | |
3168 | if (mips_type_needs_double_align (TYPE_FIELD_TYPE (type, i))) | |
3169 | return 1; | |
3170 | return 0; | |
3171 | } | |
3172 | return 0; | |
3173 | } | |
3174 | ||
dc604539 AC |
3175 | /* Adjust the address downward (direction of stack growth) so that it |
3176 | is correctly aligned for a new stack frame. */ | |
3177 | static CORE_ADDR | |
3178 | mips_frame_align (struct gdbarch *gdbarch, CORE_ADDR addr) | |
3179 | { | |
5b03f266 | 3180 | return align_down (addr, 16); |
dc604539 AC |
3181 | } |
3182 | ||
6d82d43b AC |
3183 | /* Determine how a return value is stored within the MIPS register |
3184 | file, given the return type `valtype'. */ | |
3185 | ||
3186 | struct return_value_word | |
3187 | { | |
3188 | int len; | |
3189 | int reg; | |
3190 | int reg_offset; | |
3191 | int buf_offset; | |
3192 | }; | |
3193 | ||
3194 | static void | |
3195 | return_value_location (struct type *valtype, | |
3196 | struct return_value_word *hi, | |
3197 | struct return_value_word *lo) | |
3198 | { | |
3199 | int len = TYPE_LENGTH (valtype); | |
3200 | struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); | |
3201 | ||
3202 | if (TYPE_CODE (valtype) == TYPE_CODE_FLT | |
3203 | && ((MIPS_FPU_TYPE == MIPS_FPU_DOUBLE && (len == 4 || len == 8)) | |
3204 | || (MIPS_FPU_TYPE == MIPS_FPU_SINGLE && len == 4))) | |
3205 | { | |
ceae6e75 | 3206 | if (mips_abi_regsize (current_gdbarch) < 8 && len == 8) |
6d82d43b AC |
3207 | { |
3208 | /* We need to break a 64bit float in two 32 bit halves and | |
ceae6e75 | 3209 | spread them across a floating-point register pair. */ |
6d82d43b AC |
3210 | lo->buf_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 4 : 0; |
3211 | hi->buf_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 0 : 4; | |
3212 | lo->reg_offset = ((TARGET_BYTE_ORDER == BFD_ENDIAN_BIG | |
3213 | && register_size (current_gdbarch, | |
3214 | mips_regnum (current_gdbarch)-> | |
3215 | fp0) == 8) ? 4 : 0); | |
3216 | hi->reg_offset = lo->reg_offset; | |
3217 | lo->reg = mips_regnum (current_gdbarch)->fp0 + 0; | |
3218 | hi->reg = mips_regnum (current_gdbarch)->fp0 + 1; | |
3219 | lo->len = 4; | |
3220 | hi->len = 4; | |
3221 | } | |
3222 | else | |
3223 | { | |
3224 | /* The floating point value fits in a single floating-point | |
3225 | register. */ | |
3226 | lo->reg_offset = ((TARGET_BYTE_ORDER == BFD_ENDIAN_BIG | |
3227 | && register_size (current_gdbarch, | |
3228 | mips_regnum (current_gdbarch)-> | |
3229 | fp0) == 8 | |
3230 | && len == 4) ? 4 : 0); | |
3231 | lo->reg = mips_regnum (current_gdbarch)->fp0; | |
3232 | lo->len = len; | |
3233 | lo->buf_offset = 0; | |
3234 | hi->len = 0; | |
3235 | hi->reg_offset = 0; | |
3236 | hi->buf_offset = 0; | |
3237 | hi->reg = 0; | |
3238 | } | |
3239 | } | |
3240 | else | |
3241 | { | |
3242 | /* Locate a result possibly spread across two registers. */ | |
3243 | int regnum = 2; | |
3244 | lo->reg = regnum + 0; | |
3245 | hi->reg = regnum + 1; | |
3246 | if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG | |
13326b4e | 3247 | && len < mips_abi_regsize (current_gdbarch)) |
6d82d43b AC |
3248 | { |
3249 | /* "un-left-justify" the value in the low register */ | |
13326b4e | 3250 | lo->reg_offset = mips_abi_regsize (current_gdbarch) - len; |
6d82d43b AC |
3251 | lo->len = len; |
3252 | hi->reg_offset = 0; | |
3253 | hi->len = 0; | |
3254 | } | |
13326b4e AC |
3255 | else if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG && len > mips_abi_regsize (current_gdbarch) /* odd-size structs */ |
3256 | && len < mips_abi_regsize (current_gdbarch) * 2 | |
6d82d43b AC |
3257 | && (TYPE_CODE (valtype) == TYPE_CODE_STRUCT || |
3258 | TYPE_CODE (valtype) == TYPE_CODE_UNION)) | |
3259 | { | |
3260 | /* "un-left-justify" the value spread across two registers. */ | |
13326b4e AC |
3261 | lo->reg_offset = 2 * mips_abi_regsize (current_gdbarch) - len; |
3262 | lo->len = mips_abi_regsize (current_gdbarch) - lo->reg_offset; | |
6d82d43b AC |
3263 | hi->reg_offset = 0; |
3264 | hi->len = len - lo->len; | |
3265 | } | |
3266 | else | |
3267 | { | |
3268 | /* Only perform a partial copy of the second register. */ | |
3269 | lo->reg_offset = 0; | |
3270 | hi->reg_offset = 0; | |
13326b4e | 3271 | if (len > mips_abi_regsize (current_gdbarch)) |
6d82d43b | 3272 | { |
13326b4e AC |
3273 | lo->len = mips_abi_regsize (current_gdbarch); |
3274 | hi->len = len - mips_abi_regsize (current_gdbarch); | |
6d82d43b AC |
3275 | } |
3276 | else | |
3277 | { | |
3278 | lo->len = len; | |
3279 | hi->len = 0; | |
3280 | } | |
3281 | } | |
3282 | if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG | |
3283 | && register_size (current_gdbarch, regnum) == 8 | |
13326b4e | 3284 | && mips_abi_regsize (current_gdbarch) == 4) |
6d82d43b AC |
3285 | { |
3286 | /* Account for the fact that only the least-signficant part | |
3287 | of the register is being used */ | |
3288 | lo->reg_offset += 4; | |
3289 | hi->reg_offset += 4; | |
3290 | } | |
3291 | lo->buf_offset = 0; | |
3292 | hi->buf_offset = lo->len; | |
3293 | } | |
3294 | } | |
3295 | ||
3296 | /* Should call_function allocate stack space for a struct return? */ | |
3297 | ||
3298 | static int | |
3299 | mips_eabi_use_struct_convention (int gcc_p, struct type *type) | |
3300 | { | |
3301 | struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); | |
13326b4e | 3302 | return (TYPE_LENGTH (type) > 2 * mips_abi_regsize (current_gdbarch)); |
6d82d43b AC |
3303 | } |
3304 | ||
3305 | /* Should call_function pass struct by reference? | |
3306 | For each architecture, structs are passed either by | |
3307 | value or by reference, depending on their size. */ | |
3308 | ||
3309 | static int | |
3310 | mips_eabi_reg_struct_has_addr (int gcc_p, struct type *type) | |
3311 | { | |
3312 | enum type_code typecode = TYPE_CODE (check_typedef (type)); | |
3313 | int len = TYPE_LENGTH (check_typedef (type)); | |
3314 | struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); | |
3315 | ||
3316 | if (typecode == TYPE_CODE_STRUCT || typecode == TYPE_CODE_UNION) | |
13326b4e | 3317 | return (len > mips_abi_regsize (current_gdbarch)); |
6d82d43b AC |
3318 | |
3319 | return 0; | |
3320 | } | |
3321 | ||
f7ab6ec6 | 3322 | static CORE_ADDR |
7d9b040b | 3323 | mips_eabi_push_dummy_call (struct gdbarch *gdbarch, struct value *function, |
6d82d43b AC |
3324 | struct regcache *regcache, CORE_ADDR bp_addr, |
3325 | int nargs, struct value **args, CORE_ADDR sp, | |
3326 | int struct_return, CORE_ADDR struct_addr) | |
c906108c SS |
3327 | { |
3328 | int argreg; | |
3329 | int float_argreg; | |
3330 | int argnum; | |
3331 | int len = 0; | |
3332 | int stack_offset = 0; | |
480d3dd2 | 3333 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
7d9b040b | 3334 | CORE_ADDR func_addr = find_function_addr (function, NULL); |
c906108c | 3335 | |
25ab4790 AC |
3336 | /* For shared libraries, "t9" needs to point at the function |
3337 | address. */ | |
3338 | regcache_cooked_write_signed (regcache, T9_REGNUM, func_addr); | |
3339 | ||
3340 | /* Set the return address register to point to the entry point of | |
3341 | the program, where a breakpoint lies in wait. */ | |
3342 | regcache_cooked_write_signed (regcache, RA_REGNUM, bp_addr); | |
3343 | ||
c906108c | 3344 | /* First ensure that the stack and structure return address (if any) |
cb3d25d1 MS |
3345 | are properly aligned. The stack has to be at least 64-bit |
3346 | aligned even on 32-bit machines, because doubles must be 64-bit | |
3347 | aligned. For n32 and n64, stack frames need to be 128-bit | |
3348 | aligned, so we round to this widest known alignment. */ | |
3349 | ||
5b03f266 AC |
3350 | sp = align_down (sp, 16); |
3351 | struct_addr = align_down (struct_addr, 16); | |
c5aa993b | 3352 | |
46e0f506 | 3353 | /* Now make space on the stack for the args. We allocate more |
c906108c | 3354 | than necessary for EABI, because the first few arguments are |
46e0f506 | 3355 | passed in registers, but that's OK. */ |
c906108c | 3356 | for (argnum = 0; argnum < nargs; argnum++) |
6d82d43b | 3357 | len += align_up (TYPE_LENGTH (VALUE_TYPE (args[argnum])), |
13326b4e | 3358 | mips_stack_argsize (gdbarch)); |
5b03f266 | 3359 | sp -= align_up (len, 16); |
c906108c | 3360 | |
9ace0497 | 3361 | if (mips_debug) |
6d82d43b | 3362 | fprintf_unfiltered (gdb_stdlog, |
5b03f266 AC |
3363 | "mips_eabi_push_dummy_call: sp=0x%s allocated %ld\n", |
3364 | paddr_nz (sp), (long) align_up (len, 16)); | |
9ace0497 | 3365 | |
c906108c SS |
3366 | /* Initialize the integer and float register pointers. */ |
3367 | argreg = A0_REGNUM; | |
56cea623 | 3368 | float_argreg = mips_fpa0_regnum (current_gdbarch); |
c906108c | 3369 | |
46e0f506 | 3370 | /* The struct_return pointer occupies the first parameter-passing reg. */ |
c906108c | 3371 | if (struct_return) |
9ace0497 AC |
3372 | { |
3373 | if (mips_debug) | |
3374 | fprintf_unfiltered (gdb_stdlog, | |
25ab4790 | 3375 | "mips_eabi_push_dummy_call: struct_return reg=%d 0x%s\n", |
cb3d25d1 | 3376 | argreg, paddr_nz (struct_addr)); |
9ace0497 AC |
3377 | write_register (argreg++, struct_addr); |
3378 | } | |
c906108c SS |
3379 | |
3380 | /* Now load as many as possible of the first arguments into | |
3381 | registers, and push the rest onto the stack. Loop thru args | |
3382 | from first to last. */ | |
3383 | for (argnum = 0; argnum < nargs; argnum++) | |
3384 | { | |
3385 | char *val; | |
d9d9c31f | 3386 | char valbuf[MAX_REGISTER_SIZE]; |
ea7c478f | 3387 | struct value *arg = args[argnum]; |
c906108c SS |
3388 | struct type *arg_type = check_typedef (VALUE_TYPE (arg)); |
3389 | int len = TYPE_LENGTH (arg_type); | |
3390 | enum type_code typecode = TYPE_CODE (arg_type); | |
3391 | ||
9ace0497 AC |
3392 | if (mips_debug) |
3393 | fprintf_unfiltered (gdb_stdlog, | |
25ab4790 | 3394 | "mips_eabi_push_dummy_call: %d len=%d type=%d", |
acdb74a0 | 3395 | argnum + 1, len, (int) typecode); |
9ace0497 | 3396 | |
c906108c | 3397 | /* The EABI passes structures that do not fit in a register by |
46e0f506 | 3398 | reference. */ |
13326b4e | 3399 | if (len > mips_abi_regsize (gdbarch) |
9ace0497 | 3400 | && (typecode == TYPE_CODE_STRUCT || typecode == TYPE_CODE_UNION)) |
c906108c | 3401 | { |
13326b4e | 3402 | store_unsigned_integer (valbuf, mips_abi_regsize (gdbarch), |
480d3dd2 | 3403 | VALUE_ADDRESS (arg)); |
c906108c | 3404 | typecode = TYPE_CODE_PTR; |
13326b4e | 3405 | len = mips_abi_regsize (gdbarch); |
c906108c | 3406 | val = valbuf; |
9ace0497 AC |
3407 | if (mips_debug) |
3408 | fprintf_unfiltered (gdb_stdlog, " push"); | |
c906108c SS |
3409 | } |
3410 | else | |
c5aa993b | 3411 | val = (char *) VALUE_CONTENTS (arg); |
c906108c SS |
3412 | |
3413 | /* 32-bit ABIs always start floating point arguments in an | |
acdb74a0 AC |
3414 | even-numbered floating point register. Round the FP register |
3415 | up before the check to see if there are any FP registers | |
46e0f506 MS |
3416 | left. Non MIPS_EABI targets also pass the FP in the integer |
3417 | registers so also round up normal registers. */ | |
ceae6e75 AC |
3418 | if (mips_abi_regsize (gdbarch) < 8 |
3419 | && fp_register_arg_p (typecode, arg_type)) | |
acdb74a0 AC |
3420 | { |
3421 | if ((float_argreg & 1)) | |
3422 | float_argreg++; | |
3423 | } | |
c906108c SS |
3424 | |
3425 | /* Floating point arguments passed in registers have to be | |
3426 | treated specially. On 32-bit architectures, doubles | |
c5aa993b JM |
3427 | are passed in register pairs; the even register gets |
3428 | the low word, and the odd register gets the high word. | |
3429 | On non-EABI processors, the first two floating point arguments are | |
3430 | also copied to general registers, because MIPS16 functions | |
3431 | don't use float registers for arguments. This duplication of | |
3432 | arguments in general registers can't hurt non-MIPS16 functions | |
3433 | because those registers are normally skipped. */ | |
1012bd0e EZ |
3434 | /* MIPS_EABI squeezes a struct that contains a single floating |
3435 | point value into an FP register instead of pushing it onto the | |
46e0f506 | 3436 | stack. */ |
f09ded24 AC |
3437 | if (fp_register_arg_p (typecode, arg_type) |
3438 | && float_argreg <= MIPS_LAST_FP_ARG_REGNUM) | |
c906108c | 3439 | { |
ceae6e75 | 3440 | if (mips_abi_regsize (gdbarch) < 8 && len == 8) |
c906108c | 3441 | { |
d7449b42 | 3442 | int low_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 4 : 0; |
c906108c SS |
3443 | unsigned long regval; |
3444 | ||
3445 | /* Write the low word of the double to the even register(s). */ | |
c5aa993b | 3446 | regval = extract_unsigned_integer (val + low_offset, 4); |
9ace0497 | 3447 | if (mips_debug) |
acdb74a0 | 3448 | fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s", |
9ace0497 | 3449 | float_argreg, phex (regval, 4)); |
c906108c | 3450 | write_register (float_argreg++, regval); |
c906108c SS |
3451 | |
3452 | /* Write the high word of the double to the odd register(s). */ | |
c5aa993b | 3453 | regval = extract_unsigned_integer (val + 4 - low_offset, 4); |
9ace0497 | 3454 | if (mips_debug) |
acdb74a0 | 3455 | fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s", |
9ace0497 | 3456 | float_argreg, phex (regval, 4)); |
c906108c | 3457 | write_register (float_argreg++, regval); |
c906108c SS |
3458 | } |
3459 | else | |
3460 | { | |
3461 | /* This is a floating point value that fits entirely | |
3462 | in a single register. */ | |
53a5351d | 3463 | /* On 32 bit ABI's the float_argreg is further adjusted |
6d82d43b | 3464 | above to ensure that it is even register aligned. */ |
9ace0497 AC |
3465 | LONGEST regval = extract_unsigned_integer (val, len); |
3466 | if (mips_debug) | |
acdb74a0 | 3467 | fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s", |
9ace0497 | 3468 | float_argreg, phex (regval, len)); |
c906108c | 3469 | write_register (float_argreg++, regval); |
c906108c SS |
3470 | } |
3471 | } | |
3472 | else | |
3473 | { | |
3474 | /* Copy the argument to general registers or the stack in | |
3475 | register-sized pieces. Large arguments are split between | |
3476 | registers and stack. */ | |
4246e332 | 3477 | /* Note: structs whose size is not a multiple of |
d5ac5a39 AC |
3478 | mips_abi_regsize() are treated specially: Irix cc passes |
3479 | them in registers where gcc sometimes puts them on the | |
3480 | stack. For maximum compatibility, we will put them in | |
3481 | both places. */ | |
13326b4e AC |
3482 | int odd_sized_struct = ((len > mips_abi_regsize (gdbarch)) |
3483 | && (len % mips_abi_regsize (gdbarch) != 0)); | |
46e0f506 | 3484 | |
f09ded24 | 3485 | /* Note: Floating-point values that didn't fit into an FP |
6d82d43b | 3486 | register are only written to memory. */ |
c906108c SS |
3487 | while (len > 0) |
3488 | { | |
ebafbe83 | 3489 | /* Remember if the argument was written to the stack. */ |
566f0f7a | 3490 | int stack_used_p = 0; |
13326b4e AC |
3491 | int partial_len = (len < mips_abi_regsize (gdbarch) |
3492 | ? len : mips_abi_regsize (gdbarch)); | |
c906108c | 3493 | |
acdb74a0 AC |
3494 | if (mips_debug) |
3495 | fprintf_unfiltered (gdb_stdlog, " -- partial=%d", | |
3496 | partial_len); | |
3497 | ||
566f0f7a | 3498 | /* Write this portion of the argument to the stack. */ |
f09ded24 AC |
3499 | if (argreg > MIPS_LAST_ARG_REGNUM |
3500 | || odd_sized_struct | |
3501 | || fp_register_arg_p (typecode, arg_type)) | |
c906108c | 3502 | { |
c906108c SS |
3503 | /* Should shorter than int integer values be |
3504 | promoted to int before being stored? */ | |
c906108c | 3505 | int longword_offset = 0; |
9ace0497 | 3506 | CORE_ADDR addr; |
566f0f7a | 3507 | stack_used_p = 1; |
d7449b42 | 3508 | if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) |
7a292a7a | 3509 | { |
13326b4e | 3510 | if (mips_stack_argsize (gdbarch) == 8 |
480d3dd2 AC |
3511 | && (typecode == TYPE_CODE_INT |
3512 | || typecode == TYPE_CODE_PTR | |
6d82d43b | 3513 | || typecode == TYPE_CODE_FLT) && len <= 4) |
13326b4e | 3514 | longword_offset = mips_stack_argsize (gdbarch) - len; |
480d3dd2 AC |
3515 | else if ((typecode == TYPE_CODE_STRUCT |
3516 | || typecode == TYPE_CODE_UNION) | |
3517 | && (TYPE_LENGTH (arg_type) | |
13326b4e AC |
3518 | < mips_stack_argsize (gdbarch))) |
3519 | longword_offset = mips_stack_argsize (gdbarch) - len; | |
7a292a7a | 3520 | } |
c5aa993b | 3521 | |
9ace0497 AC |
3522 | if (mips_debug) |
3523 | { | |
cb3d25d1 MS |
3524 | fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s", |
3525 | paddr_nz (stack_offset)); | |
3526 | fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s", | |
3527 | paddr_nz (longword_offset)); | |
9ace0497 | 3528 | } |
361d1df0 | 3529 | |
9ace0497 AC |
3530 | addr = sp + stack_offset + longword_offset; |
3531 | ||
3532 | if (mips_debug) | |
3533 | { | |
3534 | int i; | |
6d82d43b | 3535 | fprintf_unfiltered (gdb_stdlog, " @0x%s ", |
cb3d25d1 | 3536 | paddr_nz (addr)); |
9ace0497 AC |
3537 | for (i = 0; i < partial_len; i++) |
3538 | { | |
6d82d43b | 3539 | fprintf_unfiltered (gdb_stdlog, "%02x", |
cb3d25d1 | 3540 | val[i] & 0xff); |
9ace0497 AC |
3541 | } |
3542 | } | |
3543 | write_memory (addr, val, partial_len); | |
c906108c SS |
3544 | } |
3545 | ||
f09ded24 AC |
3546 | /* Note!!! This is NOT an else clause. Odd sized |
3547 | structs may go thru BOTH paths. Floating point | |
46e0f506 | 3548 | arguments will not. */ |
566f0f7a | 3549 | /* Write this portion of the argument to a general |
6d82d43b | 3550 | purpose register. */ |
f09ded24 AC |
3551 | if (argreg <= MIPS_LAST_ARG_REGNUM |
3552 | && !fp_register_arg_p (typecode, arg_type)) | |
c906108c | 3553 | { |
6d82d43b AC |
3554 | LONGEST regval = |
3555 | extract_unsigned_integer (val, partial_len); | |
c906108c | 3556 | |
9ace0497 | 3557 | if (mips_debug) |
acdb74a0 | 3558 | fprintf_filtered (gdb_stdlog, " - reg=%d val=%s", |
9ace0497 | 3559 | argreg, |
6d82d43b | 3560 | phex (regval, |
13326b4e | 3561 | mips_abi_regsize (gdbarch))); |
c906108c SS |
3562 | write_register (argreg, regval); |
3563 | argreg++; | |
c906108c | 3564 | } |
c5aa993b | 3565 | |
c906108c SS |
3566 | len -= partial_len; |
3567 | val += partial_len; | |
3568 | ||
566f0f7a | 3569 | /* Compute the the offset into the stack at which we |
6d82d43b | 3570 | will copy the next parameter. |
566f0f7a | 3571 | |
566f0f7a | 3572 | In the new EABI (and the NABI32), the stack_offset |
46e0f506 | 3573 | only needs to be adjusted when it has been used. */ |
c906108c | 3574 | |
46e0f506 | 3575 | if (stack_used_p) |
480d3dd2 | 3576 | stack_offset += align_up (partial_len, |
13326b4e | 3577 | mips_stack_argsize (gdbarch)); |
c906108c SS |
3578 | } |
3579 | } | |
9ace0497 AC |
3580 | if (mips_debug) |
3581 | fprintf_unfiltered (gdb_stdlog, "\n"); | |
c906108c SS |
3582 | } |
3583 | ||
f10683bb | 3584 | regcache_cooked_write_signed (regcache, MIPS_SP_REGNUM, sp); |
310e9b6a | 3585 | |
0f71a2f6 JM |
3586 | /* Return adjusted stack pointer. */ |
3587 | return sp; | |
3588 | } | |
3589 | ||
6d82d43b AC |
3590 | /* Given a return value in `regbuf' with a type `valtype', extract and |
3591 | copy its value into `valbuf'. */ | |
3592 | ||
3593 | static void | |
3594 | mips_eabi_extract_return_value (struct type *valtype, | |
3595 | char regbuf[], char *valbuf) | |
3596 | { | |
3597 | struct return_value_word lo; | |
3598 | struct return_value_word hi; | |
3599 | return_value_location (valtype, &hi, &lo); | |
3600 | ||
3601 | memcpy (valbuf + lo.buf_offset, | |
3602 | regbuf + DEPRECATED_REGISTER_BYTE (NUM_REGS + lo.reg) + | |
3603 | lo.reg_offset, lo.len); | |
3604 | ||
3605 | if (hi.len > 0) | |
3606 | memcpy (valbuf + hi.buf_offset, | |
3607 | regbuf + DEPRECATED_REGISTER_BYTE (NUM_REGS + hi.reg) + | |
3608 | hi.reg_offset, hi.len); | |
3609 | } | |
3610 | ||
3611 | /* Given a return value in `valbuf' with a type `valtype', write it's | |
3612 | value into the appropriate register. */ | |
3613 | ||
3614 | static void | |
3615 | mips_eabi_store_return_value (struct type *valtype, char *valbuf) | |
3616 | { | |
3617 | char raw_buffer[MAX_REGISTER_SIZE]; | |
3618 | struct return_value_word lo; | |
3619 | struct return_value_word hi; | |
3620 | return_value_location (valtype, &hi, &lo); | |
3621 | ||
3622 | memset (raw_buffer, 0, sizeof (raw_buffer)); | |
3623 | memcpy (raw_buffer + lo.reg_offset, valbuf + lo.buf_offset, lo.len); | |
3624 | deprecated_write_register_bytes (DEPRECATED_REGISTER_BYTE (lo.reg), | |
3625 | raw_buffer, register_size (current_gdbarch, | |
3626 | lo.reg)); | |
3627 | ||
3628 | if (hi.len > 0) | |
3629 | { | |
3630 | memset (raw_buffer, 0, sizeof (raw_buffer)); | |
3631 | memcpy (raw_buffer + hi.reg_offset, valbuf + hi.buf_offset, hi.len); | |
3632 | deprecated_write_register_bytes (DEPRECATED_REGISTER_BYTE (hi.reg), | |
3633 | raw_buffer, | |
3634 | register_size (current_gdbarch, | |
3635 | hi.reg)); | |
3636 | } | |
3637 | } | |
3638 | ||
3639 | /* N32/N64 ABI stuff. */ | |
ebafbe83 | 3640 | |
f7ab6ec6 | 3641 | static CORE_ADDR |
7d9b040b | 3642 | mips_n32n64_push_dummy_call (struct gdbarch *gdbarch, struct value *function, |
6d82d43b AC |
3643 | struct regcache *regcache, CORE_ADDR bp_addr, |
3644 | int nargs, struct value **args, CORE_ADDR sp, | |
3645 | int struct_return, CORE_ADDR struct_addr) | |
cb3d25d1 MS |
3646 | { |
3647 | int argreg; | |
3648 | int float_argreg; | |
3649 | int argnum; | |
3650 | int len = 0; | |
3651 | int stack_offset = 0; | |
480d3dd2 | 3652 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
7d9b040b | 3653 | CORE_ADDR func_addr = find_function_addr (function, NULL); |
cb3d25d1 | 3654 | |
25ab4790 AC |
3655 | /* For shared libraries, "t9" needs to point at the function |
3656 | address. */ | |
3657 | regcache_cooked_write_signed (regcache, T9_REGNUM, func_addr); | |
3658 | ||
3659 | /* Set the return address register to point to the entry point of | |
3660 | the program, where a breakpoint lies in wait. */ | |
3661 | regcache_cooked_write_signed (regcache, RA_REGNUM, bp_addr); | |
3662 | ||
cb3d25d1 MS |
3663 | /* First ensure that the stack and structure return address (if any) |
3664 | are properly aligned. The stack has to be at least 64-bit | |
3665 | aligned even on 32-bit machines, because doubles must be 64-bit | |
3666 | aligned. For n32 and n64, stack frames need to be 128-bit | |
3667 | aligned, so we round to this widest known alignment. */ | |
3668 | ||
5b03f266 AC |
3669 | sp = align_down (sp, 16); |
3670 | struct_addr = align_down (struct_addr, 16); | |
cb3d25d1 MS |
3671 | |
3672 | /* Now make space on the stack for the args. */ | |
3673 | for (argnum = 0; argnum < nargs; argnum++) | |
6d82d43b | 3674 | len += align_up (TYPE_LENGTH (VALUE_TYPE (args[argnum])), |
13326b4e | 3675 | mips_stack_argsize (gdbarch)); |
5b03f266 | 3676 | sp -= align_up (len, 16); |
cb3d25d1 MS |
3677 | |
3678 | if (mips_debug) | |
6d82d43b | 3679 | fprintf_unfiltered (gdb_stdlog, |
5b03f266 AC |
3680 | "mips_n32n64_push_dummy_call: sp=0x%s allocated %ld\n", |
3681 | paddr_nz (sp), (long) align_up (len, 16)); | |
cb3d25d1 MS |
3682 | |
3683 | /* Initialize the integer and float register pointers. */ | |
3684 | argreg = A0_REGNUM; | |
56cea623 | 3685 | float_argreg = mips_fpa0_regnum (current_gdbarch); |
cb3d25d1 | 3686 | |
46e0f506 | 3687 | /* The struct_return pointer occupies the first parameter-passing reg. */ |
cb3d25d1 MS |
3688 | if (struct_return) |
3689 | { | |
3690 | if (mips_debug) | |
3691 | fprintf_unfiltered (gdb_stdlog, | |
25ab4790 | 3692 | "mips_n32n64_push_dummy_call: struct_return reg=%d 0x%s\n", |
cb3d25d1 MS |
3693 | argreg, paddr_nz (struct_addr)); |
3694 | write_register (argreg++, struct_addr); | |
3695 | } | |
3696 | ||
3697 | /* Now load as many as possible of the first arguments into | |
3698 | registers, and push the rest onto the stack. Loop thru args | |
3699 | from first to last. */ | |
3700 | for (argnum = 0; argnum < nargs; argnum++) | |
3701 | { | |
3702 | char *val; | |
cb3d25d1 MS |
3703 | struct value *arg = args[argnum]; |
3704 | struct type *arg_type = check_typedef (VALUE_TYPE (arg)); | |
3705 | int len = TYPE_LENGTH (arg_type); | |
3706 | enum type_code typecode = TYPE_CODE (arg_type); | |
3707 | ||
3708 | if (mips_debug) | |
3709 | fprintf_unfiltered (gdb_stdlog, | |
25ab4790 | 3710 | "mips_n32n64_push_dummy_call: %d len=%d type=%d", |
cb3d25d1 MS |
3711 | argnum + 1, len, (int) typecode); |
3712 | ||
3713 | val = (char *) VALUE_CONTENTS (arg); | |
3714 | ||
3715 | if (fp_register_arg_p (typecode, arg_type) | |
3716 | && float_argreg <= MIPS_LAST_FP_ARG_REGNUM) | |
3717 | { | |
3718 | /* This is a floating point value that fits entirely | |
3719 | in a single register. */ | |
3720 | /* On 32 bit ABI's the float_argreg is further adjusted | |
3721 | above to ensure that it is even register aligned. */ | |
3722 | LONGEST regval = extract_unsigned_integer (val, len); | |
3723 | if (mips_debug) | |
3724 | fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s", | |
3725 | float_argreg, phex (regval, len)); | |
3726 | write_register (float_argreg++, regval); | |
3727 | ||
3728 | if (mips_debug) | |
3729 | fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s", | |
3730 | argreg, phex (regval, len)); | |
3731 | write_register (argreg, regval); | |
3732 | argreg += 1; | |
3733 | } | |
3734 | else | |
3735 | { | |
3736 | /* Copy the argument to general registers or the stack in | |
3737 | register-sized pieces. Large arguments are split between | |
3738 | registers and stack. */ | |
4246e332 | 3739 | /* Note: structs whose size is not a multiple of |
d5ac5a39 AC |
3740 | mips_abi_regsize() are treated specially: Irix cc passes |
3741 | them in registers where gcc sometimes puts them on the | |
3742 | stack. For maximum compatibility, we will put them in | |
3743 | both places. */ | |
13326b4e AC |
3744 | int odd_sized_struct = ((len > mips_abi_regsize (gdbarch)) |
3745 | && (len % mips_abi_regsize (gdbarch) != 0)); | |
cb3d25d1 | 3746 | /* Note: Floating-point values that didn't fit into an FP |
6d82d43b | 3747 | register are only written to memory. */ |
cb3d25d1 MS |
3748 | while (len > 0) |
3749 | { | |
3750 | /* Rememer if the argument was written to the stack. */ | |
3751 | int stack_used_p = 0; | |
13326b4e AC |
3752 | int partial_len = (len < mips_abi_regsize (gdbarch) |
3753 | ? len : mips_abi_regsize (gdbarch)); | |
cb3d25d1 MS |
3754 | |
3755 | if (mips_debug) | |
3756 | fprintf_unfiltered (gdb_stdlog, " -- partial=%d", | |
3757 | partial_len); | |
3758 | ||
3759 | /* Write this portion of the argument to the stack. */ | |
3760 | if (argreg > MIPS_LAST_ARG_REGNUM | |
3761 | || odd_sized_struct | |
3762 | || fp_register_arg_p (typecode, arg_type)) | |
3763 | { | |
3764 | /* Should shorter than int integer values be | |
3765 | promoted to int before being stored? */ | |
3766 | int longword_offset = 0; | |
3767 | CORE_ADDR addr; | |
3768 | stack_used_p = 1; | |
3769 | if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) | |
3770 | { | |
13326b4e | 3771 | if (mips_stack_argsize (gdbarch) == 8 |
480d3dd2 AC |
3772 | && (typecode == TYPE_CODE_INT |
3773 | || typecode == TYPE_CODE_PTR | |
6d82d43b | 3774 | || typecode == TYPE_CODE_FLT) && len <= 4) |
13326b4e | 3775 | longword_offset = mips_stack_argsize (gdbarch) - len; |
cb3d25d1 MS |
3776 | } |
3777 | ||
3778 | if (mips_debug) | |
3779 | { | |
3780 | fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s", | |
3781 | paddr_nz (stack_offset)); | |
3782 | fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s", | |
3783 | paddr_nz (longword_offset)); | |
3784 | } | |
3785 | ||
3786 | addr = sp + stack_offset + longword_offset; | |
3787 | ||
3788 | if (mips_debug) | |
3789 | { | |
3790 | int i; | |
6d82d43b | 3791 | fprintf_unfiltered (gdb_stdlog, " @0x%s ", |
cb3d25d1 MS |
3792 | paddr_nz (addr)); |
3793 | for (i = 0; i < partial_len; i++) | |
3794 | { | |
6d82d43b | 3795 | fprintf_unfiltered (gdb_stdlog, "%02x", |
cb3d25d1 MS |
3796 | val[i] & 0xff); |
3797 | } | |
3798 | } | |
3799 | write_memory (addr, val, partial_len); | |
3800 | } | |
3801 | ||
3802 | /* Note!!! This is NOT an else clause. Odd sized | |
3803 | structs may go thru BOTH paths. Floating point | |
3804 | arguments will not. */ | |
3805 | /* Write this portion of the argument to a general | |
6d82d43b | 3806 | purpose register. */ |
cb3d25d1 MS |
3807 | if (argreg <= MIPS_LAST_ARG_REGNUM |
3808 | && !fp_register_arg_p (typecode, arg_type)) | |
3809 | { | |
6d82d43b AC |
3810 | LONGEST regval = |
3811 | extract_unsigned_integer (val, partial_len); | |
cb3d25d1 MS |
3812 | |
3813 | /* A non-floating-point argument being passed in a | |
3814 | general register. If a struct or union, and if | |
3815 | the remaining length is smaller than the register | |
3816 | size, we have to adjust the register value on | |
3817 | big endian targets. | |
3818 | ||
3819 | It does not seem to be necessary to do the | |
3820 | same for integral types. | |
3821 | ||
3822 | cagney/2001-07-23: gdb/179: Also, GCC, when | |
3823 | outputting LE O32 with sizeof (struct) < | |
1b13c4f6 | 3824 | mips_abi_regsize(), generates a left shift as |
cb3d25d1 MS |
3825 | part of storing the argument in a register a |
3826 | register (the left shift isn't generated when | |
1b13c4f6 | 3827 | sizeof (struct) >= mips_abi_regsize()). Since |
480d3dd2 AC |
3828 | it is quite possible that this is GCC |
3829 | contradicting the LE/O32 ABI, GDB has not been | |
3830 | adjusted to accommodate this. Either someone | |
3831 | needs to demonstrate that the LE/O32 ABI | |
3832 | specifies such a left shift OR this new ABI gets | |
3833 | identified as such and GDB gets tweaked | |
3834 | accordingly. */ | |
cb3d25d1 MS |
3835 | |
3836 | if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG | |
13326b4e | 3837 | && partial_len < mips_abi_regsize (gdbarch) |
cb3d25d1 MS |
3838 | && (typecode == TYPE_CODE_STRUCT || |
3839 | typecode == TYPE_CODE_UNION)) | |
13326b4e | 3840 | regval <<= ((mips_abi_regsize (gdbarch) - partial_len) * |
cb3d25d1 MS |
3841 | TARGET_CHAR_BIT); |
3842 | ||
3843 | if (mips_debug) | |
3844 | fprintf_filtered (gdb_stdlog, " - reg=%d val=%s", | |
3845 | argreg, | |
6d82d43b | 3846 | phex (regval, |
13326b4e | 3847 | mips_abi_regsize (gdbarch))); |
cb3d25d1 MS |
3848 | write_register (argreg, regval); |
3849 | argreg++; | |
3850 | } | |
3851 | ||
3852 | len -= partial_len; | |
3853 | val += partial_len; | |
3854 | ||
3855 | /* Compute the the offset into the stack at which we | |
6d82d43b | 3856 | will copy the next parameter. |
cb3d25d1 MS |
3857 | |
3858 | In N32 (N64?), the stack_offset only needs to be | |
3859 | adjusted when it has been used. */ | |
3860 | ||
3861 | if (stack_used_p) | |
480d3dd2 | 3862 | stack_offset += align_up (partial_len, |
13326b4e | 3863 | mips_stack_argsize (gdbarch)); |
cb3d25d1 MS |
3864 | } |
3865 | } | |
3866 | if (mips_debug) | |
3867 | fprintf_unfiltered (gdb_stdlog, "\n"); | |
3868 | } | |
3869 | ||
f10683bb | 3870 | regcache_cooked_write_signed (regcache, MIPS_SP_REGNUM, sp); |
310e9b6a | 3871 | |
cb3d25d1 MS |
3872 | /* Return adjusted stack pointer. */ |
3873 | return sp; | |
3874 | } | |
3875 | ||
6d82d43b AC |
3876 | static enum return_value_convention |
3877 | mips_n32n64_return_value (struct gdbarch *gdbarch, | |
3878 | struct type *type, struct regcache *regcache, | |
3879 | void *readbuf, const void *writebuf) | |
ebafbe83 | 3880 | { |
6d82d43b AC |
3881 | struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); |
3882 | if (TYPE_CODE (type) == TYPE_CODE_STRUCT | |
3883 | || TYPE_CODE (type) == TYPE_CODE_UNION | |
3884 | || TYPE_CODE (type) == TYPE_CODE_ARRAY | |
13326b4e | 3885 | || TYPE_LENGTH (type) > 2 * mips_abi_regsize (gdbarch)) |
6d82d43b AC |
3886 | return RETURN_VALUE_STRUCT_CONVENTION; |
3887 | else if (TYPE_CODE (type) == TYPE_CODE_FLT | |
3888 | && tdep->mips_fpu_type != MIPS_FPU_NONE) | |
3889 | { | |
3890 | /* A floating-point value belongs in the least significant part | |
3891 | of FP0. */ | |
3892 | if (mips_debug) | |
3893 | fprintf_unfiltered (gdb_stderr, "Return float in $fp0\n"); | |
3894 | mips_xfer_register (regcache, | |
3895 | NUM_REGS + mips_regnum (current_gdbarch)->fp0, | |
3896 | TYPE_LENGTH (type), | |
3897 | TARGET_BYTE_ORDER, readbuf, writebuf, 0); | |
3898 | return RETURN_VALUE_REGISTER_CONVENTION; | |
3899 | } | |
3900 | else if (TYPE_CODE (type) == TYPE_CODE_STRUCT | |
3901 | && TYPE_NFIELDS (type) <= 2 | |
3902 | && TYPE_NFIELDS (type) >= 1 | |
3903 | && ((TYPE_NFIELDS (type) == 1 | |
3904 | && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) | |
3905 | == TYPE_CODE_FLT)) | |
3906 | || (TYPE_NFIELDS (type) == 2 | |
3907 | && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) | |
3908 | == TYPE_CODE_FLT) | |
3909 | && (TYPE_CODE (TYPE_FIELD_TYPE (type, 1)) | |
3910 | == TYPE_CODE_FLT))) | |
3911 | && tdep->mips_fpu_type != MIPS_FPU_NONE) | |
3912 | { | |
3913 | /* A struct that contains one or two floats. Each value is part | |
3914 | in the least significant part of their floating point | |
3915 | register.. */ | |
6d82d43b AC |
3916 | int regnum; |
3917 | int field; | |
3918 | for (field = 0, regnum = mips_regnum (current_gdbarch)->fp0; | |
3919 | field < TYPE_NFIELDS (type); field++, regnum += 2) | |
3920 | { | |
3921 | int offset = (FIELD_BITPOS (TYPE_FIELDS (type)[field]) | |
3922 | / TARGET_CHAR_BIT); | |
3923 | if (mips_debug) | |
3924 | fprintf_unfiltered (gdb_stderr, "Return float struct+%d\n", | |
3925 | offset); | |
3926 | mips_xfer_register (regcache, NUM_REGS + regnum, | |
3927 | TYPE_LENGTH (TYPE_FIELD_TYPE (type, field)), | |
3928 | TARGET_BYTE_ORDER, readbuf, writebuf, offset); | |
3929 | } | |
3930 | return RETURN_VALUE_REGISTER_CONVENTION; | |
3931 | } | |
3932 | else if (TYPE_CODE (type) == TYPE_CODE_STRUCT | |
3933 | || TYPE_CODE (type) == TYPE_CODE_UNION) | |
3934 | { | |
3935 | /* A structure or union. Extract the left justified value, | |
3936 | regardless of the byte order. I.e. DO NOT USE | |
3937 | mips_xfer_lower. */ | |
3938 | int offset; | |
3939 | int regnum; | |
3940 | for (offset = 0, regnum = V0_REGNUM; | |
3941 | offset < TYPE_LENGTH (type); | |
3942 | offset += register_size (current_gdbarch, regnum), regnum++) | |
3943 | { | |
3944 | int xfer = register_size (current_gdbarch, regnum); | |
3945 | if (offset + xfer > TYPE_LENGTH (type)) | |
3946 | xfer = TYPE_LENGTH (type) - offset; | |
3947 | if (mips_debug) | |
3948 | fprintf_unfiltered (gdb_stderr, "Return struct+%d:%d in $%d\n", | |
3949 | offset, xfer, regnum); | |
3950 | mips_xfer_register (regcache, NUM_REGS + regnum, xfer, | |
3951 | BFD_ENDIAN_UNKNOWN, readbuf, writebuf, offset); | |
3952 | } | |
3953 | return RETURN_VALUE_REGISTER_CONVENTION; | |
3954 | } | |
3955 | else | |
3956 | { | |
3957 | /* A scalar extract each part but least-significant-byte | |
3958 | justified. */ | |
3959 | int offset; | |
3960 | int regnum; | |
3961 | for (offset = 0, regnum = V0_REGNUM; | |
3962 | offset < TYPE_LENGTH (type); | |
3963 | offset += register_size (current_gdbarch, regnum), regnum++) | |
3964 | { | |
3965 | int xfer = register_size (current_gdbarch, regnum); | |
6d82d43b AC |
3966 | if (offset + xfer > TYPE_LENGTH (type)) |
3967 | xfer = TYPE_LENGTH (type) - offset; | |
3968 | if (mips_debug) | |
3969 | fprintf_unfiltered (gdb_stderr, "Return scalar+%d:%d in $%d\n", | |
3970 | offset, xfer, regnum); | |
3971 | mips_xfer_register (regcache, NUM_REGS + regnum, xfer, | |
3972 | TARGET_BYTE_ORDER, readbuf, writebuf, offset); | |
3973 | } | |
3974 | return RETURN_VALUE_REGISTER_CONVENTION; | |
3975 | } | |
3976 | } | |
3977 | ||
3978 | /* O32 ABI stuff. */ | |
3979 | ||
3980 | static CORE_ADDR | |
7d9b040b | 3981 | mips_o32_push_dummy_call (struct gdbarch *gdbarch, struct value *function, |
6d82d43b AC |
3982 | struct regcache *regcache, CORE_ADDR bp_addr, |
3983 | int nargs, struct value **args, CORE_ADDR sp, | |
3984 | int struct_return, CORE_ADDR struct_addr) | |
3985 | { | |
3986 | int argreg; | |
3987 | int float_argreg; | |
3988 | int argnum; | |
3989 | int len = 0; | |
3990 | int stack_offset = 0; | |
3991 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
7d9b040b | 3992 | CORE_ADDR func_addr = find_function_addr (function, NULL); |
6d82d43b AC |
3993 | |
3994 | /* For shared libraries, "t9" needs to point at the function | |
3995 | address. */ | |
3996 | regcache_cooked_write_signed (regcache, T9_REGNUM, func_addr); | |
3997 | ||
3998 | /* Set the return address register to point to the entry point of | |
3999 | the program, where a breakpoint lies in wait. */ | |
4000 | regcache_cooked_write_signed (regcache, RA_REGNUM, bp_addr); | |
4001 | ||
4002 | /* First ensure that the stack and structure return address (if any) | |
4003 | are properly aligned. The stack has to be at least 64-bit | |
4004 | aligned even on 32-bit machines, because doubles must be 64-bit | |
ebafbe83 MS |
4005 | aligned. For n32 and n64, stack frames need to be 128-bit |
4006 | aligned, so we round to this widest known alignment. */ | |
4007 | ||
5b03f266 AC |
4008 | sp = align_down (sp, 16); |
4009 | struct_addr = align_down (struct_addr, 16); | |
ebafbe83 MS |
4010 | |
4011 | /* Now make space on the stack for the args. */ | |
4012 | for (argnum = 0; argnum < nargs; argnum++) | |
6d82d43b | 4013 | len += align_up (TYPE_LENGTH (VALUE_TYPE (args[argnum])), |
13326b4e | 4014 | mips_stack_argsize (gdbarch)); |
5b03f266 | 4015 | sp -= align_up (len, 16); |
ebafbe83 MS |
4016 | |
4017 | if (mips_debug) | |
6d82d43b | 4018 | fprintf_unfiltered (gdb_stdlog, |
5b03f266 AC |
4019 | "mips_o32_push_dummy_call: sp=0x%s allocated %ld\n", |
4020 | paddr_nz (sp), (long) align_up (len, 16)); | |
ebafbe83 MS |
4021 | |
4022 | /* Initialize the integer and float register pointers. */ | |
4023 | argreg = A0_REGNUM; | |
56cea623 | 4024 | float_argreg = mips_fpa0_regnum (current_gdbarch); |
ebafbe83 | 4025 | |
bcb0cc15 | 4026 | /* The struct_return pointer occupies the first parameter-passing reg. */ |
ebafbe83 MS |
4027 | if (struct_return) |
4028 | { | |
4029 | if (mips_debug) | |
4030 | fprintf_unfiltered (gdb_stdlog, | |
25ab4790 | 4031 | "mips_o32_push_dummy_call: struct_return reg=%d 0x%s\n", |
ebafbe83 MS |
4032 | argreg, paddr_nz (struct_addr)); |
4033 | write_register (argreg++, struct_addr); | |
13326b4e | 4034 | stack_offset += mips_stack_argsize (gdbarch); |
ebafbe83 MS |
4035 | } |
4036 | ||
4037 | /* Now load as many as possible of the first arguments into | |
4038 | registers, and push the rest onto the stack. Loop thru args | |
4039 | from first to last. */ | |
4040 | for (argnum = 0; argnum < nargs; argnum++) | |
4041 | { | |
4042 | char *val; | |
ebafbe83 MS |
4043 | struct value *arg = args[argnum]; |
4044 | struct type *arg_type = check_typedef (VALUE_TYPE (arg)); | |
4045 | int len = TYPE_LENGTH (arg_type); | |
4046 | enum type_code typecode = TYPE_CODE (arg_type); | |
4047 | ||
4048 | if (mips_debug) | |
4049 | fprintf_unfiltered (gdb_stdlog, | |
25ab4790 | 4050 | "mips_o32_push_dummy_call: %d len=%d type=%d", |
46cac009 AC |
4051 | argnum + 1, len, (int) typecode); |
4052 | ||
4053 | val = (char *) VALUE_CONTENTS (arg); | |
4054 | ||
4055 | /* 32-bit ABIs always start floating point arguments in an | |
4056 | even-numbered floating point register. Round the FP register | |
4057 | up before the check to see if there are any FP registers | |
4058 | left. O32/O64 targets also pass the FP in the integer | |
4059 | registers so also round up normal registers. */ | |
ceae6e75 AC |
4060 | if (mips_abi_regsize (gdbarch) < 8 |
4061 | && fp_register_arg_p (typecode, arg_type)) | |
46cac009 AC |
4062 | { |
4063 | if ((float_argreg & 1)) | |
4064 | float_argreg++; | |
4065 | } | |
4066 | ||
4067 | /* Floating point arguments passed in registers have to be | |
4068 | treated specially. On 32-bit architectures, doubles | |
4069 | are passed in register pairs; the even register gets | |
4070 | the low word, and the odd register gets the high word. | |
4071 | On O32/O64, the first two floating point arguments are | |
4072 | also copied to general registers, because MIPS16 functions | |
4073 | don't use float registers for arguments. This duplication of | |
4074 | arguments in general registers can't hurt non-MIPS16 functions | |
4075 | because those registers are normally skipped. */ | |
4076 | ||
4077 | if (fp_register_arg_p (typecode, arg_type) | |
4078 | && float_argreg <= MIPS_LAST_FP_ARG_REGNUM) | |
4079 | { | |
ceae6e75 | 4080 | if (mips_abi_regsize (gdbarch) < 8 && len == 8) |
46cac009 AC |
4081 | { |
4082 | int low_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 4 : 0; | |
4083 | unsigned long regval; | |
4084 | ||
4085 | /* Write the low word of the double to the even register(s). */ | |
4086 | regval = extract_unsigned_integer (val + low_offset, 4); | |
4087 | if (mips_debug) | |
4088 | fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s", | |
4089 | float_argreg, phex (regval, 4)); | |
4090 | write_register (float_argreg++, regval); | |
4091 | if (mips_debug) | |
4092 | fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s", | |
4093 | argreg, phex (regval, 4)); | |
4094 | write_register (argreg++, regval); | |
4095 | ||
4096 | /* Write the high word of the double to the odd register(s). */ | |
4097 | regval = extract_unsigned_integer (val + 4 - low_offset, 4); | |
4098 | if (mips_debug) | |
4099 | fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s", | |
4100 | float_argreg, phex (regval, 4)); | |
4101 | write_register (float_argreg++, regval); | |
4102 | ||
4103 | if (mips_debug) | |
4104 | fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s", | |
4105 | argreg, phex (regval, 4)); | |
4106 | write_register (argreg++, regval); | |
4107 | } | |
4108 | else | |
4109 | { | |
4110 | /* This is a floating point value that fits entirely | |
4111 | in a single register. */ | |
4112 | /* On 32 bit ABI's the float_argreg is further adjusted | |
6d82d43b | 4113 | above to ensure that it is even register aligned. */ |
46cac009 AC |
4114 | LONGEST regval = extract_unsigned_integer (val, len); |
4115 | if (mips_debug) | |
4116 | fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s", | |
4117 | float_argreg, phex (regval, len)); | |
4118 | write_register (float_argreg++, regval); | |
4119 | /* CAGNEY: 32 bit MIPS ABI's always reserve two FP | |
6d82d43b AC |
4120 | registers for each argument. The below is (my |
4121 | guess) to ensure that the corresponding integer | |
4122 | register has reserved the same space. */ | |
46cac009 AC |
4123 | if (mips_debug) |
4124 | fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s", | |
4125 | argreg, phex (regval, len)); | |
4126 | write_register (argreg, regval); | |
ceae6e75 | 4127 | argreg += (mips_abi_regsize (gdbarch) == 8) ? 1 : 2; |
46cac009 AC |
4128 | } |
4129 | /* Reserve space for the FP register. */ | |
13326b4e | 4130 | stack_offset += align_up (len, mips_stack_argsize (gdbarch)); |
46cac009 AC |
4131 | } |
4132 | else | |
4133 | { | |
4134 | /* Copy the argument to general registers or the stack in | |
4135 | register-sized pieces. Large arguments are split between | |
4136 | registers and stack. */ | |
4246e332 | 4137 | /* Note: structs whose size is not a multiple of |
d5ac5a39 AC |
4138 | mips_abi_regsize() are treated specially: Irix cc passes |
4139 | them in registers where gcc sometimes puts them on the | |
4140 | stack. For maximum compatibility, we will put them in | |
4141 | both places. */ | |
13326b4e AC |
4142 | int odd_sized_struct = ((len > mips_abi_regsize (gdbarch)) |
4143 | && (len % mips_abi_regsize (gdbarch) != 0)); | |
46cac009 AC |
4144 | /* Structures should be aligned to eight bytes (even arg registers) |
4145 | on MIPS_ABI_O32, if their first member has double precision. */ | |
13326b4e | 4146 | if (mips_abi_regsize (gdbarch) < 8 |
46cac009 AC |
4147 | && mips_type_needs_double_align (arg_type)) |
4148 | { | |
4149 | if ((argreg & 1)) | |
6d82d43b | 4150 | argreg++; |
46cac009 AC |
4151 | } |
4152 | /* Note: Floating-point values that didn't fit into an FP | |
6d82d43b | 4153 | register are only written to memory. */ |
46cac009 AC |
4154 | while (len > 0) |
4155 | { | |
4156 | /* Remember if the argument was written to the stack. */ | |
4157 | int stack_used_p = 0; | |
13326b4e AC |
4158 | int partial_len = (len < mips_abi_regsize (gdbarch) |
4159 | ? len : mips_abi_regsize (gdbarch)); | |
46cac009 AC |
4160 | |
4161 | if (mips_debug) | |
4162 | fprintf_unfiltered (gdb_stdlog, " -- partial=%d", | |
4163 | partial_len); | |
4164 | ||
4165 | /* Write this portion of the argument to the stack. */ | |
4166 | if (argreg > MIPS_LAST_ARG_REGNUM | |
4167 | || odd_sized_struct | |
4168 | || fp_register_arg_p (typecode, arg_type)) | |
4169 | { | |
4170 | /* Should shorter than int integer values be | |
4171 | promoted to int before being stored? */ | |
4172 | int longword_offset = 0; | |
4173 | CORE_ADDR addr; | |
4174 | stack_used_p = 1; | |
4175 | if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) | |
4176 | { | |
13326b4e | 4177 | if (mips_stack_argsize (gdbarch) == 8 |
480d3dd2 AC |
4178 | && (typecode == TYPE_CODE_INT |
4179 | || typecode == TYPE_CODE_PTR | |
6d82d43b | 4180 | || typecode == TYPE_CODE_FLT) && len <= 4) |
13326b4e | 4181 | longword_offset = mips_stack_argsize (gdbarch) - len; |
46cac009 AC |
4182 | } |
4183 | ||
4184 | if (mips_debug) | |
4185 | { | |
4186 | fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s", | |
4187 | paddr_nz (stack_offset)); | |
4188 | fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s", | |
4189 | paddr_nz (longword_offset)); | |
4190 | } | |
4191 | ||
4192 | addr = sp + stack_offset + longword_offset; | |
4193 | ||
4194 | if (mips_debug) | |
4195 | { | |
4196 | int i; | |
6d82d43b | 4197 | fprintf_unfiltered (gdb_stdlog, " @0x%s ", |
46cac009 AC |
4198 | paddr_nz (addr)); |
4199 | for (i = 0; i < partial_len; i++) | |
4200 | { | |
6d82d43b | 4201 | fprintf_unfiltered (gdb_stdlog, "%02x", |
46cac009 AC |
4202 | val[i] & 0xff); |
4203 | } | |
4204 | } | |
4205 | write_memory (addr, val, partial_len); | |
4206 | } | |
4207 | ||
4208 | /* Note!!! This is NOT an else clause. Odd sized | |
4209 | structs may go thru BOTH paths. Floating point | |
4210 | arguments will not. */ | |
4211 | /* Write this portion of the argument to a general | |
6d82d43b | 4212 | purpose register. */ |
46cac009 AC |
4213 | if (argreg <= MIPS_LAST_ARG_REGNUM |
4214 | && !fp_register_arg_p (typecode, arg_type)) | |
4215 | { | |
4216 | LONGEST regval = extract_signed_integer (val, partial_len); | |
4246e332 | 4217 | /* Value may need to be sign extended, because |
1b13c4f6 | 4218 | mips_isa_regsize() != mips_abi_regsize(). */ |
46cac009 AC |
4219 | |
4220 | /* A non-floating-point argument being passed in a | |
4221 | general register. If a struct or union, and if | |
4222 | the remaining length is smaller than the register | |
4223 | size, we have to adjust the register value on | |
4224 | big endian targets. | |
4225 | ||
4226 | It does not seem to be necessary to do the | |
4227 | same for integral types. | |
4228 | ||
4229 | Also don't do this adjustment on O64 binaries. | |
4230 | ||
4231 | cagney/2001-07-23: gdb/179: Also, GCC, when | |
4232 | outputting LE O32 with sizeof (struct) < | |
1b13c4f6 | 4233 | mips_abi_regsize(), generates a left shift as |
46cac009 AC |
4234 | part of storing the argument in a register a |
4235 | register (the left shift isn't generated when | |
1b13c4f6 | 4236 | sizeof (struct) >= mips_abi_regsize()). Since |
480d3dd2 AC |
4237 | it is quite possible that this is GCC |
4238 | contradicting the LE/O32 ABI, GDB has not been | |
4239 | adjusted to accommodate this. Either someone | |
4240 | needs to demonstrate that the LE/O32 ABI | |
4241 | specifies such a left shift OR this new ABI gets | |
4242 | identified as such and GDB gets tweaked | |
4243 | accordingly. */ | |
4244 | ||
13326b4e | 4245 | if (mips_abi_regsize (gdbarch) < 8 |
46cac009 | 4246 | && TARGET_BYTE_ORDER == BFD_ENDIAN_BIG |
13326b4e | 4247 | && partial_len < mips_abi_regsize (gdbarch) |
46cac009 AC |
4248 | && (typecode == TYPE_CODE_STRUCT || |
4249 | typecode == TYPE_CODE_UNION)) | |
13326b4e | 4250 | regval <<= ((mips_abi_regsize (gdbarch) - partial_len) * |
46cac009 AC |
4251 | TARGET_CHAR_BIT); |
4252 | ||
4253 | if (mips_debug) | |
4254 | fprintf_filtered (gdb_stdlog, " - reg=%d val=%s", | |
4255 | argreg, | |
6d82d43b | 4256 | phex (regval, |
13326b4e | 4257 | mips_abi_regsize (gdbarch))); |
46cac009 AC |
4258 | write_register (argreg, regval); |
4259 | argreg++; | |
4260 | ||
4261 | /* Prevent subsequent floating point arguments from | |
4262 | being passed in floating point registers. */ | |
4263 | float_argreg = MIPS_LAST_FP_ARG_REGNUM + 1; | |
4264 | } | |
4265 | ||
4266 | len -= partial_len; | |
4267 | val += partial_len; | |
4268 | ||
4269 | /* Compute the the offset into the stack at which we | |
6d82d43b | 4270 | will copy the next parameter. |
46cac009 | 4271 | |
6d82d43b AC |
4272 | In older ABIs, the caller reserved space for |
4273 | registers that contained arguments. This was loosely | |
4274 | refered to as their "home". Consequently, space is | |
4275 | always allocated. */ | |
46cac009 | 4276 | |
480d3dd2 | 4277 | stack_offset += align_up (partial_len, |
13326b4e | 4278 | mips_stack_argsize (gdbarch)); |
46cac009 AC |
4279 | } |
4280 | } | |
4281 | if (mips_debug) | |
4282 | fprintf_unfiltered (gdb_stdlog, "\n"); | |
4283 | } | |
4284 | ||
f10683bb | 4285 | regcache_cooked_write_signed (regcache, MIPS_SP_REGNUM, sp); |
310e9b6a | 4286 | |
46cac009 AC |
4287 | /* Return adjusted stack pointer. */ |
4288 | return sp; | |
4289 | } | |
4290 | ||
6d82d43b AC |
4291 | static enum return_value_convention |
4292 | mips_o32_return_value (struct gdbarch *gdbarch, struct type *type, | |
4293 | struct regcache *regcache, | |
4294 | void *readbuf, const void *writebuf) | |
4295 | { | |
4296 | struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); | |
4297 | ||
4298 | if (TYPE_CODE (type) == TYPE_CODE_STRUCT | |
4299 | || TYPE_CODE (type) == TYPE_CODE_UNION | |
4300 | || TYPE_CODE (type) == TYPE_CODE_ARRAY) | |
4301 | return RETURN_VALUE_STRUCT_CONVENTION; | |
4302 | else if (TYPE_CODE (type) == TYPE_CODE_FLT | |
4303 | && TYPE_LENGTH (type) == 4 && tdep->mips_fpu_type != MIPS_FPU_NONE) | |
4304 | { | |
4305 | /* A single-precision floating-point value. It fits in the | |
4306 | least significant part of FP0. */ | |
4307 | if (mips_debug) | |
4308 | fprintf_unfiltered (gdb_stderr, "Return float in $fp0\n"); | |
4309 | mips_xfer_register (regcache, | |
4310 | NUM_REGS + mips_regnum (current_gdbarch)->fp0, | |
4311 | TYPE_LENGTH (type), | |
4312 | TARGET_BYTE_ORDER, readbuf, writebuf, 0); | |
4313 | return RETURN_VALUE_REGISTER_CONVENTION; | |
4314 | } | |
4315 | else if (TYPE_CODE (type) == TYPE_CODE_FLT | |
4316 | && TYPE_LENGTH (type) == 8 && tdep->mips_fpu_type != MIPS_FPU_NONE) | |
4317 | { | |
4318 | /* A double-precision floating-point value. The most | |
4319 | significant part goes in FP1, and the least significant in | |
4320 | FP0. */ | |
4321 | if (mips_debug) | |
4322 | fprintf_unfiltered (gdb_stderr, "Return float in $fp1/$fp0\n"); | |
4323 | switch (TARGET_BYTE_ORDER) | |
4324 | { | |
4325 | case BFD_ENDIAN_LITTLE: | |
4326 | mips_xfer_register (regcache, | |
4327 | NUM_REGS + mips_regnum (current_gdbarch)->fp0 + | |
4328 | 0, 4, TARGET_BYTE_ORDER, readbuf, writebuf, 0); | |
4329 | mips_xfer_register (regcache, | |
4330 | NUM_REGS + mips_regnum (current_gdbarch)->fp0 + | |
4331 | 1, 4, TARGET_BYTE_ORDER, readbuf, writebuf, 4); | |
4332 | break; | |
4333 | case BFD_ENDIAN_BIG: | |
4334 | mips_xfer_register (regcache, | |
4335 | NUM_REGS + mips_regnum (current_gdbarch)->fp0 + | |
4336 | 1, 4, TARGET_BYTE_ORDER, readbuf, writebuf, 0); | |
4337 | mips_xfer_register (regcache, | |
4338 | NUM_REGS + mips_regnum (current_gdbarch)->fp0 + | |
4339 | 0, 4, TARGET_BYTE_ORDER, readbuf, writebuf, 4); | |
4340 | break; | |
4341 | default: | |
4342 | internal_error (__FILE__, __LINE__, "bad switch"); | |
4343 | } | |
4344 | return RETURN_VALUE_REGISTER_CONVENTION; | |
4345 | } | |
4346 | #if 0 | |
4347 | else if (TYPE_CODE (type) == TYPE_CODE_STRUCT | |
4348 | && TYPE_NFIELDS (type) <= 2 | |
4349 | && TYPE_NFIELDS (type) >= 1 | |
4350 | && ((TYPE_NFIELDS (type) == 1 | |
4351 | && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) | |
4352 | == TYPE_CODE_FLT)) | |
4353 | || (TYPE_NFIELDS (type) == 2 | |
4354 | && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) | |
4355 | == TYPE_CODE_FLT) | |
4356 | && (TYPE_CODE (TYPE_FIELD_TYPE (type, 1)) | |
4357 | == TYPE_CODE_FLT))) | |
4358 | && tdep->mips_fpu_type != MIPS_FPU_NONE) | |
4359 | { | |
4360 | /* A struct that contains one or two floats. Each value is part | |
4361 | in the least significant part of their floating point | |
4362 | register.. */ | |
4363 | bfd_byte reg[MAX_REGISTER_SIZE]; | |
4364 | int regnum; | |
4365 | int field; | |
4366 | for (field = 0, regnum = mips_regnum (current_gdbarch)->fp0; | |
4367 | field < TYPE_NFIELDS (type); field++, regnum += 2) | |
4368 | { | |
4369 | int offset = (FIELD_BITPOS (TYPE_FIELDS (type)[field]) | |
4370 | / TARGET_CHAR_BIT); | |
4371 | if (mips_debug) | |
4372 | fprintf_unfiltered (gdb_stderr, "Return float struct+%d\n", | |
4373 | offset); | |
4374 | mips_xfer_register (regcache, NUM_REGS + regnum, | |
4375 | TYPE_LENGTH (TYPE_FIELD_TYPE (type, field)), | |
4376 | TARGET_BYTE_ORDER, readbuf, writebuf, offset); | |
4377 | } | |
4378 | return RETURN_VALUE_REGISTER_CONVENTION; | |
4379 | } | |
4380 | #endif | |
4381 | #if 0 | |
4382 | else if (TYPE_CODE (type) == TYPE_CODE_STRUCT | |
4383 | || TYPE_CODE (type) == TYPE_CODE_UNION) | |
4384 | { | |
4385 | /* A structure or union. Extract the left justified value, | |
4386 | regardless of the byte order. I.e. DO NOT USE | |
4387 | mips_xfer_lower. */ | |
4388 | int offset; | |
4389 | int regnum; | |
4390 | for (offset = 0, regnum = V0_REGNUM; | |
4391 | offset < TYPE_LENGTH (type); | |
4392 | offset += register_size (current_gdbarch, regnum), regnum++) | |
4393 | { | |
4394 | int xfer = register_size (current_gdbarch, regnum); | |
4395 | if (offset + xfer > TYPE_LENGTH (type)) | |
4396 | xfer = TYPE_LENGTH (type) - offset; | |
4397 | if (mips_debug) | |
4398 | fprintf_unfiltered (gdb_stderr, "Return struct+%d:%d in $%d\n", | |
4399 | offset, xfer, regnum); | |
4400 | mips_xfer_register (regcache, NUM_REGS + regnum, xfer, | |
4401 | BFD_ENDIAN_UNKNOWN, readbuf, writebuf, offset); | |
4402 | } | |
4403 | return RETURN_VALUE_REGISTER_CONVENTION; | |
4404 | } | |
4405 | #endif | |
4406 | else | |
4407 | { | |
4408 | /* A scalar extract each part but least-significant-byte | |
4409 | justified. o32 thinks registers are 4 byte, regardless of | |
4410 | the ISA. mips_stack_argsize controls this. */ | |
4411 | int offset; | |
4412 | int regnum; | |
4413 | for (offset = 0, regnum = V0_REGNUM; | |
4414 | offset < TYPE_LENGTH (type); | |
13326b4e | 4415 | offset += mips_stack_argsize (gdbarch), regnum++) |
6d82d43b | 4416 | { |
13326b4e | 4417 | int xfer = mips_stack_argsize (gdbarch); |
6d82d43b AC |
4418 | if (offset + xfer > TYPE_LENGTH (type)) |
4419 | xfer = TYPE_LENGTH (type) - offset; | |
4420 | if (mips_debug) | |
4421 | fprintf_unfiltered (gdb_stderr, "Return scalar+%d:%d in $%d\n", | |
4422 | offset, xfer, regnum); | |
4423 | mips_xfer_register (regcache, NUM_REGS + regnum, xfer, | |
4424 | TARGET_BYTE_ORDER, readbuf, writebuf, offset); | |
4425 | } | |
4426 | return RETURN_VALUE_REGISTER_CONVENTION; | |
4427 | } | |
4428 | } | |
4429 | ||
4430 | /* O64 ABI. This is a hacked up kind of 64-bit version of the o32 | |
4431 | ABI. */ | |
46cac009 AC |
4432 | |
4433 | static CORE_ADDR | |
7d9b040b | 4434 | mips_o64_push_dummy_call (struct gdbarch *gdbarch, struct value *function, |
6d82d43b AC |
4435 | struct regcache *regcache, CORE_ADDR bp_addr, |
4436 | int nargs, | |
4437 | struct value **args, CORE_ADDR sp, | |
4438 | int struct_return, CORE_ADDR struct_addr) | |
46cac009 AC |
4439 | { |
4440 | int argreg; | |
4441 | int float_argreg; | |
4442 | int argnum; | |
4443 | int len = 0; | |
4444 | int stack_offset = 0; | |
480d3dd2 | 4445 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
7d9b040b | 4446 | CORE_ADDR func_addr = find_function_addr (function, NULL); |
46cac009 | 4447 | |
25ab4790 AC |
4448 | /* For shared libraries, "t9" needs to point at the function |
4449 | address. */ | |
4450 | regcache_cooked_write_signed (regcache, T9_REGNUM, func_addr); | |
4451 | ||
4452 | /* Set the return address register to point to the entry point of | |
4453 | the program, where a breakpoint lies in wait. */ | |
4454 | regcache_cooked_write_signed (regcache, RA_REGNUM, bp_addr); | |
4455 | ||
46cac009 AC |
4456 | /* First ensure that the stack and structure return address (if any) |
4457 | are properly aligned. The stack has to be at least 64-bit | |
4458 | aligned even on 32-bit machines, because doubles must be 64-bit | |
4459 | aligned. For n32 and n64, stack frames need to be 128-bit | |
4460 | aligned, so we round to this widest known alignment. */ | |
4461 | ||
5b03f266 AC |
4462 | sp = align_down (sp, 16); |
4463 | struct_addr = align_down (struct_addr, 16); | |
46cac009 AC |
4464 | |
4465 | /* Now make space on the stack for the args. */ | |
4466 | for (argnum = 0; argnum < nargs; argnum++) | |
6d82d43b | 4467 | len += align_up (TYPE_LENGTH (VALUE_TYPE (args[argnum])), |
13326b4e | 4468 | mips_stack_argsize (gdbarch)); |
5b03f266 | 4469 | sp -= align_up (len, 16); |
46cac009 AC |
4470 | |
4471 | if (mips_debug) | |
6d82d43b | 4472 | fprintf_unfiltered (gdb_stdlog, |
5b03f266 AC |
4473 | "mips_o64_push_dummy_call: sp=0x%s allocated %ld\n", |
4474 | paddr_nz (sp), (long) align_up (len, 16)); | |
46cac009 AC |
4475 | |
4476 | /* Initialize the integer and float register pointers. */ | |
4477 | argreg = A0_REGNUM; | |
56cea623 | 4478 | float_argreg = mips_fpa0_regnum (current_gdbarch); |
46cac009 AC |
4479 | |
4480 | /* The struct_return pointer occupies the first parameter-passing reg. */ | |
4481 | if (struct_return) | |
4482 | { | |
4483 | if (mips_debug) | |
4484 | fprintf_unfiltered (gdb_stdlog, | |
25ab4790 | 4485 | "mips_o64_push_dummy_call: struct_return reg=%d 0x%s\n", |
46cac009 AC |
4486 | argreg, paddr_nz (struct_addr)); |
4487 | write_register (argreg++, struct_addr); | |
13326b4e | 4488 | stack_offset += mips_stack_argsize (gdbarch); |
46cac009 AC |
4489 | } |
4490 | ||
4491 | /* Now load as many as possible of the first arguments into | |
4492 | registers, and push the rest onto the stack. Loop thru args | |
4493 | from first to last. */ | |
4494 | for (argnum = 0; argnum < nargs; argnum++) | |
4495 | { | |
4496 | char *val; | |
46cac009 AC |
4497 | struct value *arg = args[argnum]; |
4498 | struct type *arg_type = check_typedef (VALUE_TYPE (arg)); | |
4499 | int len = TYPE_LENGTH (arg_type); | |
4500 | enum type_code typecode = TYPE_CODE (arg_type); | |
4501 | ||
4502 | if (mips_debug) | |
4503 | fprintf_unfiltered (gdb_stdlog, | |
25ab4790 | 4504 | "mips_o64_push_dummy_call: %d len=%d type=%d", |
ebafbe83 MS |
4505 | argnum + 1, len, (int) typecode); |
4506 | ||
4507 | val = (char *) VALUE_CONTENTS (arg); | |
4508 | ||
4509 | /* 32-bit ABIs always start floating point arguments in an | |
4510 | even-numbered floating point register. Round the FP register | |
4511 | up before the check to see if there are any FP registers | |
4512 | left. O32/O64 targets also pass the FP in the integer | |
4513 | registers so also round up normal registers. */ | |
ceae6e75 AC |
4514 | if (mips_abi_regsize (gdbarch) < 8 |
4515 | && fp_register_arg_p (typecode, arg_type)) | |
ebafbe83 MS |
4516 | { |
4517 | if ((float_argreg & 1)) | |
4518 | float_argreg++; | |
4519 | } | |
4520 | ||
4521 | /* Floating point arguments passed in registers have to be | |
4522 | treated specially. On 32-bit architectures, doubles | |
4523 | are passed in register pairs; the even register gets | |
4524 | the low word, and the odd register gets the high word. | |
4525 | On O32/O64, the first two floating point arguments are | |
4526 | also copied to general registers, because MIPS16 functions | |
4527 | don't use float registers for arguments. This duplication of | |
4528 | arguments in general registers can't hurt non-MIPS16 functions | |
4529 | because those registers are normally skipped. */ | |
4530 | ||
4531 | if (fp_register_arg_p (typecode, arg_type) | |
4532 | && float_argreg <= MIPS_LAST_FP_ARG_REGNUM) | |
4533 | { | |
ceae6e75 | 4534 | if (mips_abi_regsize (gdbarch) < 8 && len == 8) |
ebafbe83 MS |
4535 | { |
4536 | int low_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 4 : 0; | |
4537 | unsigned long regval; | |
4538 | ||
4539 | /* Write the low word of the double to the even register(s). */ | |
4540 | regval = extract_unsigned_integer (val + low_offset, 4); | |
4541 | if (mips_debug) | |
4542 | fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s", | |
4543 | float_argreg, phex (regval, 4)); | |
4544 | write_register (float_argreg++, regval); | |
4545 | if (mips_debug) | |
4546 | fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s", | |
4547 | argreg, phex (regval, 4)); | |
4548 | write_register (argreg++, regval); | |
4549 | ||
4550 | /* Write the high word of the double to the odd register(s). */ | |
4551 | regval = extract_unsigned_integer (val + 4 - low_offset, 4); | |
4552 | if (mips_debug) | |
4553 | fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s", | |
4554 | float_argreg, phex (regval, 4)); | |
4555 | write_register (float_argreg++, regval); | |
4556 | ||
4557 | if (mips_debug) | |
4558 | fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s", | |
4559 | argreg, phex (regval, 4)); | |
4560 | write_register (argreg++, regval); | |
4561 | } | |
4562 | else | |
4563 | { | |
4564 | /* This is a floating point value that fits entirely | |
4565 | in a single register. */ | |
4566 | /* On 32 bit ABI's the float_argreg is further adjusted | |
6d82d43b | 4567 | above to ensure that it is even register aligned. */ |
ebafbe83 MS |
4568 | LONGEST regval = extract_unsigned_integer (val, len); |
4569 | if (mips_debug) | |
4570 | fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s", | |
4571 | float_argreg, phex (regval, len)); | |
4572 | write_register (float_argreg++, regval); | |
4573 | /* CAGNEY: 32 bit MIPS ABI's always reserve two FP | |
6d82d43b AC |
4574 | registers for each argument. The below is (my |
4575 | guess) to ensure that the corresponding integer | |
4576 | register has reserved the same space. */ | |
ebafbe83 MS |
4577 | if (mips_debug) |
4578 | fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s", | |
4579 | argreg, phex (regval, len)); | |
4580 | write_register (argreg, regval); | |
ceae6e75 | 4581 | argreg += (mips_abi_regsize (gdbarch) == 8) ? 1 : 2; |
ebafbe83 MS |
4582 | } |
4583 | /* Reserve space for the FP register. */ | |
13326b4e | 4584 | stack_offset += align_up (len, mips_stack_argsize (gdbarch)); |
ebafbe83 MS |
4585 | } |
4586 | else | |
4587 | { | |
4588 | /* Copy the argument to general registers or the stack in | |
4589 | register-sized pieces. Large arguments are split between | |
4590 | registers and stack. */ | |
4246e332 | 4591 | /* Note: structs whose size is not a multiple of |
d5ac5a39 AC |
4592 | mips_abi_regsize() are treated specially: Irix cc passes |
4593 | them in registers where gcc sometimes puts them on the | |
4594 | stack. For maximum compatibility, we will put them in | |
4595 | both places. */ | |
13326b4e AC |
4596 | int odd_sized_struct = ((len > mips_abi_regsize (gdbarch)) |
4597 | && (len % mips_abi_regsize (gdbarch) != 0)); | |
ebafbe83 MS |
4598 | /* Structures should be aligned to eight bytes (even arg registers) |
4599 | on MIPS_ABI_O32, if their first member has double precision. */ | |
13326b4e | 4600 | if (mips_abi_regsize (gdbarch) < 8 |
ebafbe83 MS |
4601 | && mips_type_needs_double_align (arg_type)) |
4602 | { | |
4603 | if ((argreg & 1)) | |
6d82d43b | 4604 | argreg++; |
ebafbe83 MS |
4605 | } |
4606 | /* Note: Floating-point values that didn't fit into an FP | |
6d82d43b | 4607 | register are only written to memory. */ |
ebafbe83 MS |
4608 | while (len > 0) |
4609 | { | |
4610 | /* Remember if the argument was written to the stack. */ | |
4611 | int stack_used_p = 0; | |
13326b4e AC |
4612 | int partial_len = (len < mips_abi_regsize (gdbarch) |
4613 | ? len : mips_abi_regsize (gdbarch)); | |
ebafbe83 MS |
4614 | |
4615 | if (mips_debug) | |
4616 | fprintf_unfiltered (gdb_stdlog, " -- partial=%d", | |
4617 | partial_len); | |
4618 | ||
4619 | /* Write this portion of the argument to the stack. */ | |
4620 | if (argreg > MIPS_LAST_ARG_REGNUM | |
4621 | || odd_sized_struct | |
4622 | || fp_register_arg_p (typecode, arg_type)) | |
4623 | { | |
4624 | /* Should shorter than int integer values be | |
4625 | promoted to int before being stored? */ | |
4626 | int longword_offset = 0; | |
4627 | CORE_ADDR addr; | |
4628 | stack_used_p = 1; | |
4629 | if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) | |
4630 | { | |
13326b4e | 4631 | if (mips_stack_argsize (gdbarch) == 8 |
480d3dd2 AC |
4632 | && (typecode == TYPE_CODE_INT |
4633 | || typecode == TYPE_CODE_PTR | |
6d82d43b | 4634 | || typecode == TYPE_CODE_FLT) && len <= 4) |
13326b4e | 4635 | longword_offset = mips_stack_argsize (gdbarch) - len; |
ebafbe83 MS |
4636 | } |
4637 | ||
4638 | if (mips_debug) | |
4639 | { | |
4640 | fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s", | |
4641 | paddr_nz (stack_offset)); | |
4642 | fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s", | |
4643 | paddr_nz (longword_offset)); | |
4644 | } | |
4645 | ||
4646 | addr = sp + stack_offset + longword_offset; | |
4647 | ||
4648 | if (mips_debug) | |
4649 | { | |
4650 | int i; | |
6d82d43b | 4651 | fprintf_unfiltered (gdb_stdlog, " @0x%s ", |
ebafbe83 MS |
4652 | paddr_nz (addr)); |
4653 | for (i = 0; i < partial_len; i++) | |
4654 | { | |
6d82d43b | 4655 | fprintf_unfiltered (gdb_stdlog, "%02x", |
ebafbe83 MS |
4656 | val[i] & 0xff); |
4657 | } | |
4658 | } | |
4659 | write_memory (addr, val, partial_len); | |
4660 | } | |
4661 | ||
4662 | /* Note!!! This is NOT an else clause. Odd sized | |
4663 | structs may go thru BOTH paths. Floating point | |
4664 | arguments will not. */ | |
4665 | /* Write this portion of the argument to a general | |
6d82d43b | 4666 | purpose register. */ |
ebafbe83 MS |
4667 | if (argreg <= MIPS_LAST_ARG_REGNUM |
4668 | && !fp_register_arg_p (typecode, arg_type)) | |
4669 | { | |
4670 | LONGEST regval = extract_signed_integer (val, partial_len); | |
4246e332 | 4671 | /* Value may need to be sign extended, because |
1b13c4f6 | 4672 | mips_isa_regsize() != mips_abi_regsize(). */ |
ebafbe83 MS |
4673 | |
4674 | /* A non-floating-point argument being passed in a | |
4675 | general register. If a struct or union, and if | |
4676 | the remaining length is smaller than the register | |
4677 | size, we have to adjust the register value on | |
4678 | big endian targets. | |
4679 | ||
4680 | It does not seem to be necessary to do the | |
4681 | same for integral types. | |
4682 | ||
4683 | Also don't do this adjustment on O64 binaries. | |
4684 | ||
4685 | cagney/2001-07-23: gdb/179: Also, GCC, when | |
4686 | outputting LE O32 with sizeof (struct) < | |
1b13c4f6 | 4687 | mips_abi_regsize(), generates a left shift as |
ebafbe83 MS |
4688 | part of storing the argument in a register a |
4689 | register (the left shift isn't generated when | |
1b13c4f6 | 4690 | sizeof (struct) >= mips_abi_regsize()). Since |
480d3dd2 AC |
4691 | it is quite possible that this is GCC |
4692 | contradicting the LE/O32 ABI, GDB has not been | |
4693 | adjusted to accommodate this. Either someone | |
4694 | needs to demonstrate that the LE/O32 ABI | |
4695 | specifies such a left shift OR this new ABI gets | |
4696 | identified as such and GDB gets tweaked | |
4697 | accordingly. */ | |
4698 | ||
13326b4e | 4699 | if (mips_abi_regsize (gdbarch) < 8 |
ebafbe83 | 4700 | && TARGET_BYTE_ORDER == BFD_ENDIAN_BIG |
13326b4e | 4701 | && partial_len < mips_abi_regsize (gdbarch) |
ebafbe83 MS |
4702 | && (typecode == TYPE_CODE_STRUCT || |
4703 | typecode == TYPE_CODE_UNION)) | |
13326b4e | 4704 | regval <<= ((mips_abi_regsize (gdbarch) - partial_len) * |
ebafbe83 MS |
4705 | TARGET_CHAR_BIT); |
4706 | ||
4707 | if (mips_debug) | |
4708 | fprintf_filtered (gdb_stdlog, " - reg=%d val=%s", | |
4709 | argreg, | |
6d82d43b | 4710 | phex (regval, |
13326b4e | 4711 | mips_abi_regsize (gdbarch))); |
ebafbe83 MS |
4712 | write_register (argreg, regval); |
4713 | argreg++; | |
4714 | ||
4715 | /* Prevent subsequent floating point arguments from | |
4716 | being passed in floating point registers. */ | |
4717 | float_argreg = MIPS_LAST_FP_ARG_REGNUM + 1; | |
4718 | } | |
4719 | ||
4720 | len -= partial_len; | |
4721 | val += partial_len; | |
4722 | ||
4723 | /* Compute the the offset into the stack at which we | |
6d82d43b | 4724 | will copy the next parameter. |
ebafbe83 | 4725 | |
6d82d43b AC |
4726 | In older ABIs, the caller reserved space for |
4727 | registers that contained arguments. This was loosely | |
4728 | refered to as their "home". Consequently, space is | |
4729 | always allocated. */ | |
ebafbe83 | 4730 | |
480d3dd2 | 4731 | stack_offset += align_up (partial_len, |
13326b4e | 4732 | mips_stack_argsize (gdbarch)); |
ebafbe83 MS |
4733 | } |
4734 | } | |
4735 | if (mips_debug) | |
4736 | fprintf_unfiltered (gdb_stdlog, "\n"); | |
4737 | } | |
4738 | ||
f10683bb | 4739 | regcache_cooked_write_signed (regcache, MIPS_SP_REGNUM, sp); |
310e9b6a | 4740 | |
ebafbe83 MS |
4741 | /* Return adjusted stack pointer. */ |
4742 | return sp; | |
4743 | } | |
4744 | ||
f7ab6ec6 | 4745 | static void |
6d82d43b AC |
4746 | mips_o64_extract_return_value (struct type *valtype, |
4747 | char regbuf[], char *valbuf) | |
c906108c | 4748 | { |
6d82d43b AC |
4749 | struct return_value_word lo; |
4750 | struct return_value_word hi; | |
4751 | return_value_location (valtype, &hi, &lo); | |
c906108c | 4752 | |
6d82d43b AC |
4753 | memcpy (valbuf + lo.buf_offset, |
4754 | regbuf + DEPRECATED_REGISTER_BYTE (NUM_REGS + lo.reg) + | |
4755 | lo.reg_offset, lo.len); | |
4756 | ||
4757 | if (hi.len > 0) | |
4758 | memcpy (valbuf + hi.buf_offset, | |
4759 | regbuf + DEPRECATED_REGISTER_BYTE (NUM_REGS + hi.reg) + | |
4760 | hi.reg_offset, hi.len); | |
4761 | } | |
4762 | ||
4763 | static void | |
4764 | mips_o64_store_return_value (struct type *valtype, char *valbuf) | |
4765 | { | |
4766 | char raw_buffer[MAX_REGISTER_SIZE]; | |
4767 | struct return_value_word lo; | |
4768 | struct return_value_word hi; | |
4769 | return_value_location (valtype, &hi, &lo); | |
4770 | ||
4771 | memset (raw_buffer, 0, sizeof (raw_buffer)); | |
4772 | memcpy (raw_buffer + lo.reg_offset, valbuf + lo.buf_offset, lo.len); | |
4773 | deprecated_write_register_bytes (DEPRECATED_REGISTER_BYTE (lo.reg), | |
4774 | raw_buffer, register_size (current_gdbarch, | |
4775 | lo.reg)); | |
4776 | ||
4777 | if (hi.len > 0) | |
4778 | { | |
4779 | memset (raw_buffer, 0, sizeof (raw_buffer)); | |
4780 | memcpy (raw_buffer + hi.reg_offset, valbuf + hi.buf_offset, hi.len); | |
4781 | deprecated_write_register_bytes (DEPRECATED_REGISTER_BYTE (hi.reg), | |
4782 | raw_buffer, | |
4783 | register_size (current_gdbarch, | |
4784 | hi.reg)); | |
4785 | } | |
4786 | } | |
4787 | ||
dd824b04 DJ |
4788 | /* Floating point register management. |
4789 | ||
4790 | Background: MIPS1 & 2 fp registers are 32 bits wide. To support | |
4791 | 64bit operations, these early MIPS cpus treat fp register pairs | |
4792 | (f0,f1) as a single register (d0). Later MIPS cpu's have 64 bit fp | |
4793 | registers and offer a compatibility mode that emulates the MIPS2 fp | |
4794 | model. When operating in MIPS2 fp compat mode, later cpu's split | |
4795 | double precision floats into two 32-bit chunks and store them in | |
4796 | consecutive fp regs. To display 64-bit floats stored in this | |
4797 | fashion, we have to combine 32 bits from f0 and 32 bits from f1. | |
4798 | Throw in user-configurable endianness and you have a real mess. | |
4799 | ||
4800 | The way this works is: | |
4801 | - If we are in 32-bit mode or on a 32-bit processor, then a 64-bit | |
4802 | double-precision value will be split across two logical registers. | |
4803 | The lower-numbered logical register will hold the low-order bits, | |
4804 | regardless of the processor's endianness. | |
4805 | - If we are on a 64-bit processor, and we are looking for a | |
4806 | single-precision value, it will be in the low ordered bits | |
4807 | of a 64-bit GPR (after mfc1, for example) or a 64-bit register | |
4808 | save slot in memory. | |
4809 | - If we are in 64-bit mode, everything is straightforward. | |
4810 | ||
4811 | Note that this code only deals with "live" registers at the top of the | |
4812 | stack. We will attempt to deal with saved registers later, when | |
4813 | the raw/cooked register interface is in place. (We need a general | |
4814 | interface that can deal with dynamic saved register sizes -- fp | |
4815 | regs could be 32 bits wide in one frame and 64 on the frame above | |
4816 | and below). */ | |
4817 | ||
67b2c998 DJ |
4818 | static struct type * |
4819 | mips_float_register_type (void) | |
4820 | { | |
361d1df0 | 4821 | if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) |
67b2c998 DJ |
4822 | return builtin_type_ieee_single_big; |
4823 | else | |
4824 | return builtin_type_ieee_single_little; | |
4825 | } | |
4826 | ||
4827 | static struct type * | |
4828 | mips_double_register_type (void) | |
4829 | { | |
361d1df0 | 4830 | if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) |
67b2c998 DJ |
4831 | return builtin_type_ieee_double_big; |
4832 | else | |
4833 | return builtin_type_ieee_double_little; | |
4834 | } | |
4835 | ||
dd824b04 DJ |
4836 | /* Copy a 32-bit single-precision value from the current frame |
4837 | into rare_buffer. */ | |
4838 | ||
4839 | static void | |
e11c53d2 AC |
4840 | mips_read_fp_register_single (struct frame_info *frame, int regno, |
4841 | char *rare_buffer) | |
dd824b04 | 4842 | { |
719ec221 | 4843 | int raw_size = register_size (current_gdbarch, regno); |
dd824b04 DJ |
4844 | char *raw_buffer = alloca (raw_size); |
4845 | ||
e11c53d2 | 4846 | if (!frame_register_read (frame, regno, raw_buffer)) |
dd824b04 DJ |
4847 | error ("can't read register %d (%s)", regno, REGISTER_NAME (regno)); |
4848 | if (raw_size == 8) | |
4849 | { | |
4850 | /* We have a 64-bit value for this register. Find the low-order | |
6d82d43b | 4851 | 32 bits. */ |
dd824b04 DJ |
4852 | int offset; |
4853 | ||
4854 | if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) | |
4855 | offset = 4; | |
4856 | else | |
4857 | offset = 0; | |
4858 | ||
4859 | memcpy (rare_buffer, raw_buffer + offset, 4); | |
4860 | } | |
4861 | else | |
4862 | { | |
4863 | memcpy (rare_buffer, raw_buffer, 4); | |
4864 | } | |
4865 | } | |
4866 | ||
4867 | /* Copy a 64-bit double-precision value from the current frame into | |
4868 | rare_buffer. This may include getting half of it from the next | |
4869 | register. */ | |
4870 | ||
4871 | static void | |
e11c53d2 AC |
4872 | mips_read_fp_register_double (struct frame_info *frame, int regno, |
4873 | char *rare_buffer) | |
dd824b04 | 4874 | { |
719ec221 | 4875 | int raw_size = register_size (current_gdbarch, regno); |
dd824b04 DJ |
4876 | |
4877 | if (raw_size == 8 && !mips2_fp_compat ()) | |
4878 | { | |
4879 | /* We have a 64-bit value for this register, and we should use | |
6d82d43b | 4880 | all 64 bits. */ |
e11c53d2 | 4881 | if (!frame_register_read (frame, regno, rare_buffer)) |
dd824b04 DJ |
4882 | error ("can't read register %d (%s)", regno, REGISTER_NAME (regno)); |
4883 | } | |
4884 | else | |
4885 | { | |
56cea623 | 4886 | if ((regno - mips_regnum (current_gdbarch)->fp0) & 1) |
dd824b04 DJ |
4887 | internal_error (__FILE__, __LINE__, |
4888 | "mips_read_fp_register_double: bad access to " | |
4889 | "odd-numbered FP register"); | |
4890 | ||
4891 | /* mips_read_fp_register_single will find the correct 32 bits from | |
6d82d43b | 4892 | each register. */ |
dd824b04 DJ |
4893 | if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) |
4894 | { | |
e11c53d2 AC |
4895 | mips_read_fp_register_single (frame, regno, rare_buffer + 4); |
4896 | mips_read_fp_register_single (frame, regno + 1, rare_buffer); | |
dd824b04 | 4897 | } |
361d1df0 | 4898 | else |
dd824b04 | 4899 | { |
e11c53d2 AC |
4900 | mips_read_fp_register_single (frame, regno, rare_buffer); |
4901 | mips_read_fp_register_single (frame, regno + 1, rare_buffer + 4); | |
dd824b04 DJ |
4902 | } |
4903 | } | |
4904 | } | |
4905 | ||
c906108c | 4906 | static void |
e11c53d2 AC |
4907 | mips_print_fp_register (struct ui_file *file, struct frame_info *frame, |
4908 | int regnum) | |
c5aa993b | 4909 | { /* do values for FP (float) regs */ |
dd824b04 | 4910 | char *raw_buffer; |
3903d437 AC |
4911 | double doub, flt1; /* doubles extracted from raw hex data */ |
4912 | int inv1, inv2; | |
c5aa993b | 4913 | |
6d82d43b AC |
4914 | raw_buffer = |
4915 | (char *) alloca (2 * | |
4916 | register_size (current_gdbarch, | |
4917 | mips_regnum (current_gdbarch)->fp0)); | |
c906108c | 4918 | |
e11c53d2 AC |
4919 | fprintf_filtered (file, "%s:", REGISTER_NAME (regnum)); |
4920 | fprintf_filtered (file, "%*s", 4 - (int) strlen (REGISTER_NAME (regnum)), | |
4921 | ""); | |
f0ef6b29 | 4922 | |
719ec221 | 4923 | if (register_size (current_gdbarch, regnum) == 4 || mips2_fp_compat ()) |
c906108c | 4924 | { |
f0ef6b29 KB |
4925 | /* 4-byte registers: Print hex and floating. Also print even |
4926 | numbered registers as doubles. */ | |
e11c53d2 | 4927 | mips_read_fp_register_single (frame, regnum, raw_buffer); |
67b2c998 | 4928 | flt1 = unpack_double (mips_float_register_type (), raw_buffer, &inv1); |
c5aa993b | 4929 | |
6d82d43b AC |
4930 | print_scalar_formatted (raw_buffer, builtin_type_uint32, 'x', 'w', |
4931 | file); | |
dd824b04 | 4932 | |
e11c53d2 | 4933 | fprintf_filtered (file, " flt: "); |
1adad886 | 4934 | if (inv1) |
e11c53d2 | 4935 | fprintf_filtered (file, " <invalid float> "); |
1adad886 | 4936 | else |
e11c53d2 | 4937 | fprintf_filtered (file, "%-17.9g", flt1); |
1adad886 | 4938 | |
f0ef6b29 KB |
4939 | if (regnum % 2 == 0) |
4940 | { | |
e11c53d2 | 4941 | mips_read_fp_register_double (frame, regnum, raw_buffer); |
f0ef6b29 | 4942 | doub = unpack_double (mips_double_register_type (), raw_buffer, |
6d82d43b | 4943 | &inv2); |
1adad886 | 4944 | |
e11c53d2 | 4945 | fprintf_filtered (file, " dbl: "); |
f0ef6b29 | 4946 | if (inv2) |
e11c53d2 | 4947 | fprintf_filtered (file, "<invalid double>"); |
f0ef6b29 | 4948 | else |
e11c53d2 | 4949 | fprintf_filtered (file, "%-24.17g", doub); |
f0ef6b29 | 4950 | } |
c906108c SS |
4951 | } |
4952 | else | |
dd824b04 | 4953 | { |
f0ef6b29 | 4954 | /* Eight byte registers: print each one as hex, float and double. */ |
e11c53d2 | 4955 | mips_read_fp_register_single (frame, regnum, raw_buffer); |
2f38ef89 | 4956 | flt1 = unpack_double (mips_float_register_type (), raw_buffer, &inv1); |
c906108c | 4957 | |
e11c53d2 | 4958 | mips_read_fp_register_double (frame, regnum, raw_buffer); |
f0ef6b29 KB |
4959 | doub = unpack_double (mips_double_register_type (), raw_buffer, &inv2); |
4960 | ||
361d1df0 | 4961 | |
6d82d43b AC |
4962 | print_scalar_formatted (raw_buffer, builtin_type_uint64, 'x', 'g', |
4963 | file); | |
f0ef6b29 | 4964 | |
e11c53d2 | 4965 | fprintf_filtered (file, " flt: "); |
1adad886 | 4966 | if (inv1) |
e11c53d2 | 4967 | fprintf_filtered (file, "<invalid float>"); |
1adad886 | 4968 | else |
e11c53d2 | 4969 | fprintf_filtered (file, "%-17.9g", flt1); |
1adad886 | 4970 | |
e11c53d2 | 4971 | fprintf_filtered (file, " dbl: "); |
f0ef6b29 | 4972 | if (inv2) |
e11c53d2 | 4973 | fprintf_filtered (file, "<invalid double>"); |
1adad886 | 4974 | else |
e11c53d2 | 4975 | fprintf_filtered (file, "%-24.17g", doub); |
f0ef6b29 KB |
4976 | } |
4977 | } | |
4978 | ||
4979 | static void | |
e11c53d2 AC |
4980 | mips_print_register (struct ui_file *file, struct frame_info *frame, |
4981 | int regnum, int all) | |
f0ef6b29 | 4982 | { |
a4b8ebc8 | 4983 | struct gdbarch *gdbarch = get_frame_arch (frame); |
d9d9c31f | 4984 | char raw_buffer[MAX_REGISTER_SIZE]; |
f0ef6b29 | 4985 | int offset; |
1adad886 | 4986 | |
a4b8ebc8 | 4987 | if (TYPE_CODE (gdbarch_register_type (gdbarch, regnum)) == TYPE_CODE_FLT) |
f0ef6b29 | 4988 | { |
e11c53d2 | 4989 | mips_print_fp_register (file, frame, regnum); |
f0ef6b29 KB |
4990 | return; |
4991 | } | |
4992 | ||
4993 | /* Get the data in raw format. */ | |
e11c53d2 | 4994 | if (!frame_register_read (frame, regnum, raw_buffer)) |
f0ef6b29 | 4995 | { |
e11c53d2 | 4996 | fprintf_filtered (file, "%s: [Invalid]", REGISTER_NAME (regnum)); |
f0ef6b29 | 4997 | return; |
c906108c | 4998 | } |
f0ef6b29 | 4999 | |
e11c53d2 | 5000 | fputs_filtered (REGISTER_NAME (regnum), file); |
f0ef6b29 KB |
5001 | |
5002 | /* The problem with printing numeric register names (r26, etc.) is that | |
5003 | the user can't use them on input. Probably the best solution is to | |
5004 | fix it so that either the numeric or the funky (a2, etc.) names | |
5005 | are accepted on input. */ | |
5006 | if (regnum < MIPS_NUMREGS) | |
e11c53d2 | 5007 | fprintf_filtered (file, "(r%d): ", regnum); |
f0ef6b29 | 5008 | else |
e11c53d2 | 5009 | fprintf_filtered (file, ": "); |
f0ef6b29 KB |
5010 | |
5011 | if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) | |
6d82d43b AC |
5012 | offset = |
5013 | register_size (current_gdbarch, | |
5014 | regnum) - register_size (current_gdbarch, regnum); | |
f0ef6b29 KB |
5015 | else |
5016 | offset = 0; | |
5017 | ||
6d82d43b AC |
5018 | print_scalar_formatted (raw_buffer + offset, |
5019 | gdbarch_register_type (gdbarch, regnum), 'x', 0, | |
5020 | file); | |
c906108c SS |
5021 | } |
5022 | ||
f0ef6b29 KB |
5023 | /* Replacement for generic do_registers_info. |
5024 | Print regs in pretty columns. */ | |
5025 | ||
5026 | static int | |
e11c53d2 AC |
5027 | print_fp_register_row (struct ui_file *file, struct frame_info *frame, |
5028 | int regnum) | |
f0ef6b29 | 5029 | { |
e11c53d2 AC |
5030 | fprintf_filtered (file, " "); |
5031 | mips_print_fp_register (file, frame, regnum); | |
5032 | fprintf_filtered (file, "\n"); | |
f0ef6b29 KB |
5033 | return regnum + 1; |
5034 | } | |
5035 | ||
5036 | ||
c906108c SS |
5037 | /* Print a row's worth of GP (int) registers, with name labels above */ |
5038 | ||
5039 | static int | |
e11c53d2 | 5040 | print_gp_register_row (struct ui_file *file, struct frame_info *frame, |
a4b8ebc8 | 5041 | int start_regnum) |
c906108c | 5042 | { |
a4b8ebc8 | 5043 | struct gdbarch *gdbarch = get_frame_arch (frame); |
c906108c | 5044 | /* do values for GP (int) regs */ |
d9d9c31f | 5045 | char raw_buffer[MAX_REGISTER_SIZE]; |
d5ac5a39 | 5046 | int ncols = (mips_abi_regsize (gdbarch) == 8 ? 4 : 8); /* display cols per row */ |
c906108c | 5047 | int col, byte; |
a4b8ebc8 | 5048 | int regnum; |
c906108c SS |
5049 | |
5050 | /* For GP registers, we print a separate row of names above the vals */ | |
e11c53d2 | 5051 | fprintf_filtered (file, " "); |
a4b8ebc8 | 5052 | for (col = 0, regnum = start_regnum; |
6d82d43b | 5053 | col < ncols && regnum < NUM_REGS + NUM_PSEUDO_REGS; regnum++) |
c906108c SS |
5054 | { |
5055 | if (*REGISTER_NAME (regnum) == '\0') | |
c5aa993b | 5056 | continue; /* unused register */ |
6d82d43b AC |
5057 | if (TYPE_CODE (gdbarch_register_type (gdbarch, regnum)) == |
5058 | TYPE_CODE_FLT) | |
c5aa993b | 5059 | break; /* end the row: reached FP register */ |
6d82d43b | 5060 | fprintf_filtered (file, |
d5ac5a39 | 5061 | mips_abi_regsize (current_gdbarch) == 8 ? "%17s" : "%9s", |
e11c53d2 | 5062 | REGISTER_NAME (regnum)); |
c906108c SS |
5063 | col++; |
5064 | } | |
a4b8ebc8 | 5065 | /* print the R0 to R31 names */ |
20e6603c AC |
5066 | if ((start_regnum % NUM_REGS) < MIPS_NUMREGS) |
5067 | fprintf_filtered (file, "\n R%-4d", start_regnum % NUM_REGS); | |
5068 | else | |
5069 | fprintf_filtered (file, "\n "); | |
c906108c | 5070 | |
c906108c | 5071 | /* now print the values in hex, 4 or 8 to the row */ |
a4b8ebc8 | 5072 | for (col = 0, regnum = start_regnum; |
6d82d43b | 5073 | col < ncols && regnum < NUM_REGS + NUM_PSEUDO_REGS; regnum++) |
c906108c SS |
5074 | { |
5075 | if (*REGISTER_NAME (regnum) == '\0') | |
c5aa993b | 5076 | continue; /* unused register */ |
6d82d43b AC |
5077 | if (TYPE_CODE (gdbarch_register_type (gdbarch, regnum)) == |
5078 | TYPE_CODE_FLT) | |
c5aa993b | 5079 | break; /* end row: reached FP register */ |
c906108c | 5080 | /* OK: get the data in raw format. */ |
e11c53d2 | 5081 | if (!frame_register_read (frame, regnum, raw_buffer)) |
c906108c SS |
5082 | error ("can't read register %d (%s)", regnum, REGISTER_NAME (regnum)); |
5083 | /* pad small registers */ | |
4246e332 | 5084 | for (byte = 0; |
d5ac5a39 | 5085 | byte < (mips_abi_regsize (current_gdbarch) |
6d82d43b | 5086 | - register_size (current_gdbarch, regnum)); byte++) |
c906108c SS |
5087 | printf_filtered (" "); |
5088 | /* Now print the register value in hex, endian order. */ | |
d7449b42 | 5089 | if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) |
6d82d43b AC |
5090 | for (byte = |
5091 | register_size (current_gdbarch, | |
5092 | regnum) - register_size (current_gdbarch, regnum); | |
5093 | byte < register_size (current_gdbarch, regnum); byte++) | |
e11c53d2 | 5094 | fprintf_filtered (file, "%02x", (unsigned char) raw_buffer[byte]); |
c906108c | 5095 | else |
c73e8f27 | 5096 | for (byte = register_size (current_gdbarch, regnum) - 1; |
6d82d43b | 5097 | byte >= 0; byte--) |
e11c53d2 AC |
5098 | fprintf_filtered (file, "%02x", (unsigned char) raw_buffer[byte]); |
5099 | fprintf_filtered (file, " "); | |
c906108c SS |
5100 | col++; |
5101 | } | |
c5aa993b | 5102 | if (col > 0) /* ie. if we actually printed anything... */ |
e11c53d2 | 5103 | fprintf_filtered (file, "\n"); |
c906108c SS |
5104 | |
5105 | return regnum; | |
5106 | } | |
5107 | ||
5108 | /* MIPS_DO_REGISTERS_INFO(): called by "info register" command */ | |
5109 | ||
bf1f5b4c | 5110 | static void |
e11c53d2 AC |
5111 | mips_print_registers_info (struct gdbarch *gdbarch, struct ui_file *file, |
5112 | struct frame_info *frame, int regnum, int all) | |
c906108c | 5113 | { |
c5aa993b | 5114 | if (regnum != -1) /* do one specified register */ |
c906108c | 5115 | { |
a4b8ebc8 | 5116 | gdb_assert (regnum >= NUM_REGS); |
c906108c SS |
5117 | if (*(REGISTER_NAME (regnum)) == '\0') |
5118 | error ("Not a valid register for the current processor type"); | |
5119 | ||
e11c53d2 AC |
5120 | mips_print_register (file, frame, regnum, 0); |
5121 | fprintf_filtered (file, "\n"); | |
c906108c | 5122 | } |
c5aa993b JM |
5123 | else |
5124 | /* do all (or most) registers */ | |
c906108c | 5125 | { |
a4b8ebc8 AC |
5126 | regnum = NUM_REGS; |
5127 | while (regnum < NUM_REGS + NUM_PSEUDO_REGS) | |
c906108c | 5128 | { |
6d82d43b AC |
5129 | if (TYPE_CODE (gdbarch_register_type (gdbarch, regnum)) == |
5130 | TYPE_CODE_FLT) | |
e11c53d2 AC |
5131 | { |
5132 | if (all) /* true for "INFO ALL-REGISTERS" command */ | |
5133 | regnum = print_fp_register_row (file, frame, regnum); | |
5134 | else | |
5135 | regnum += MIPS_NUMREGS; /* skip floating point regs */ | |
5136 | } | |
c906108c | 5137 | else |
e11c53d2 | 5138 | regnum = print_gp_register_row (file, frame, regnum); |
c906108c SS |
5139 | } |
5140 | } | |
5141 | } | |
5142 | ||
c906108c SS |
5143 | /* Is this a branch with a delay slot? */ |
5144 | ||
a14ed312 | 5145 | static int is_delayed (unsigned long); |
c906108c SS |
5146 | |
5147 | static int | |
acdb74a0 | 5148 | is_delayed (unsigned long insn) |
c906108c SS |
5149 | { |
5150 | int i; | |
5151 | for (i = 0; i < NUMOPCODES; ++i) | |
5152 | if (mips_opcodes[i].pinfo != INSN_MACRO | |
5153 | && (insn & mips_opcodes[i].mask) == mips_opcodes[i].match) | |
5154 | break; | |
5155 | return (i < NUMOPCODES | |
5156 | && (mips_opcodes[i].pinfo & (INSN_UNCOND_BRANCH_DELAY | |
5157 | | INSN_COND_BRANCH_DELAY | |
5158 | | INSN_COND_BRANCH_LIKELY))); | |
5159 | } | |
5160 | ||
5161 | int | |
acdb74a0 | 5162 | mips_step_skips_delay (CORE_ADDR pc) |
c906108c SS |
5163 | { |
5164 | char buf[MIPS_INSTLEN]; | |
5165 | ||
5166 | /* There is no branch delay slot on MIPS16. */ | |
5167 | if (pc_is_mips16 (pc)) | |
5168 | return 0; | |
5169 | ||
5170 | if (target_read_memory (pc, buf, MIPS_INSTLEN) != 0) | |
5171 | /* If error reading memory, guess that it is not a delayed branch. */ | |
5172 | return 0; | |
6d82d43b AC |
5173 | return is_delayed ((unsigned long) |
5174 | extract_unsigned_integer (buf, MIPS_INSTLEN)); | |
c906108c SS |
5175 | } |
5176 | ||
c906108c SS |
5177 | /* Skip the PC past function prologue instructions (32-bit version). |
5178 | This is a helper function for mips_skip_prologue. */ | |
5179 | ||
5180 | static CORE_ADDR | |
f7b9e9fc | 5181 | mips32_skip_prologue (CORE_ADDR pc) |
c906108c | 5182 | { |
c5aa993b JM |
5183 | t_inst inst; |
5184 | CORE_ADDR end_pc; | |
5185 | int seen_sp_adjust = 0; | |
5186 | int load_immediate_bytes = 0; | |
5187 | ||
74da7425 AC |
5188 | /* Find an upper bound on the prologue. */ |
5189 | end_pc = skip_prologue_using_sal (pc); | |
5190 | if (end_pc == 0) | |
6d82d43b | 5191 | end_pc = pc + 100; /* Magic. */ |
74da7425 | 5192 | |
c5aa993b JM |
5193 | /* Skip the typical prologue instructions. These are the stack adjustment |
5194 | instruction and the instructions that save registers on the stack | |
5195 | or in the gcc frame. */ | |
74da7425 | 5196 | for (; pc < end_pc; pc += MIPS_INSTLEN) |
c5aa993b JM |
5197 | { |
5198 | unsigned long high_word; | |
c906108c | 5199 | |
c5aa993b JM |
5200 | inst = mips_fetch_instruction (pc); |
5201 | high_word = (inst >> 16) & 0xffff; | |
c906108c | 5202 | |
c5aa993b JM |
5203 | if (high_word == 0x27bd /* addiu $sp,$sp,offset */ |
5204 | || high_word == 0x67bd) /* daddiu $sp,$sp,offset */ | |
5205 | seen_sp_adjust = 1; | |
5206 | else if (inst == 0x03a1e823 || /* subu $sp,$sp,$at */ | |
5207 | inst == 0x03a8e823) /* subu $sp,$sp,$t0 */ | |
5208 | seen_sp_adjust = 1; | |
5209 | else if (((inst & 0xFFE00000) == 0xAFA00000 /* sw reg,n($sp) */ | |
5210 | || (inst & 0xFFE00000) == 0xFFA00000) /* sd reg,n($sp) */ | |
5211 | && (inst & 0x001F0000)) /* reg != $zero */ | |
5212 | continue; | |
5213 | ||
5214 | else if ((inst & 0xFFE00000) == 0xE7A00000) /* swc1 freg,n($sp) */ | |
5215 | continue; | |
5216 | else if ((inst & 0xF3E00000) == 0xA3C00000 && (inst & 0x001F0000)) | |
5217 | /* sx reg,n($s8) */ | |
5218 | continue; /* reg != $zero */ | |
5219 | ||
5220 | /* move $s8,$sp. With different versions of gas this will be either | |
5221 | `addu $s8,$sp,$zero' or `or $s8,$sp,$zero' or `daddu s8,sp,$0'. | |
5222 | Accept any one of these. */ | |
5223 | else if (inst == 0x03A0F021 || inst == 0x03a0f025 || inst == 0x03a0f02d) | |
5224 | continue; | |
5225 | ||
5226 | else if ((inst & 0xFF9F07FF) == 0x00800021) /* move reg,$a0-$a3 */ | |
5227 | continue; | |
6d82d43b AC |
5228 | else if (high_word == 0x3c1c) /* lui $gp,n */ |
5229 | continue; | |
5230 | else if (high_word == 0x279c) /* addiu $gp,$gp,n */ | |
5231 | continue; | |
5232 | else if (inst == 0x0399e021 /* addu $gp,$gp,$t9 */ | |
5233 | || inst == 0x033ce021) /* addu $gp,$t9,$gp */ | |
5234 | continue; | |
5235 | /* The following instructions load $at or $t0 with an immediate | |
5236 | value in preparation for a stack adjustment via | |
5237 | subu $sp,$sp,[$at,$t0]. These instructions could also initialize | |
5238 | a local variable, so we accept them only before a stack adjustment | |
5239 | instruction was seen. */ | |
5240 | else if (!seen_sp_adjust) | |
cb1d2653 | 5241 | { |
6d82d43b AC |
5242 | if (high_word == 0x3c01 || /* lui $at,n */ |
5243 | high_word == 0x3c08) /* lui $t0,n */ | |
5244 | { | |
5245 | load_immediate_bytes += MIPS_INSTLEN; /* FIXME!! */ | |
5246 | continue; | |
5247 | } | |
5248 | else if (high_word == 0x3421 || /* ori $at,$at,n */ | |
5249 | high_word == 0x3508 || /* ori $t0,$t0,n */ | |
5250 | high_word == 0x3401 || /* ori $at,$zero,n */ | |
5251 | high_word == 0x3408) /* ori $t0,$zero,n */ | |
5252 | { | |
5253 | load_immediate_bytes += MIPS_INSTLEN; /* FIXME!! */ | |
5254 | continue; | |
5255 | } | |
5256 | else | |
5257 | break; | |
cb1d2653 | 5258 | } |
6d82d43b AC |
5259 | else |
5260 | break; | |
46cac009 | 5261 | } |
6d82d43b AC |
5262 | |
5263 | /* In a frameless function, we might have incorrectly | |
5264 | skipped some load immediate instructions. Undo the skipping | |
5265 | if the load immediate was not followed by a stack adjustment. */ | |
5266 | if (load_immediate_bytes && !seen_sp_adjust) | |
5267 | pc -= load_immediate_bytes; | |
5268 | return pc; | |
46cac009 AC |
5269 | } |
5270 | ||
6d82d43b AC |
5271 | /* Skip the PC past function prologue instructions (16-bit version). |
5272 | This is a helper function for mips_skip_prologue. */ | |
cb1d2653 | 5273 | |
6d82d43b AC |
5274 | static CORE_ADDR |
5275 | mips16_skip_prologue (CORE_ADDR pc) | |
c906108c | 5276 | { |
6d82d43b AC |
5277 | CORE_ADDR end_pc; |
5278 | int extend_bytes = 0; | |
5279 | int prev_extend_bytes; | |
5280 | ||
5281 | /* Table of instructions likely to be found in a function prologue. */ | |
5282 | static struct | |
5283 | { | |
5284 | unsigned short inst; | |
5285 | unsigned short mask; | |
5286 | } | |
5287 | table[] = | |
5288 | { | |
7a292a7a | 5289 | { |
6d82d43b AC |
5290 | 0x6300, 0xff00} |
5291 | , /* addiu $sp,offset */ | |
88658117 | 5292 | { |
6d82d43b AC |
5293 | 0xfb00, 0xff00} |
5294 | , /* daddiu $sp,offset */ | |
88658117 | 5295 | { |
6d82d43b AC |
5296 | 0xd000, 0xf800} |
5297 | , /* sw reg,n($sp) */ | |
5298 | { | |
5299 | 0xf900, 0xff00} | |
5300 | , /* sd reg,n($sp) */ | |
5301 | { | |
5302 | 0x6200, 0xff00} | |
5303 | , /* sw $ra,n($sp) */ | |
5304 | { | |
5305 | 0xfa00, 0xff00} | |
5306 | , /* sd $ra,n($sp) */ | |
5307 | { | |
5308 | 0x673d, 0xffff} | |
5309 | , /* move $s1,sp */ | |
5310 | { | |
5311 | 0xd980, 0xff80} | |
5312 | , /* sw $a0-$a3,n($s1) */ | |
5313 | { | |
5314 | 0x6704, 0xff1c} | |
5315 | , /* move reg,$a0-$a3 */ | |
5316 | { | |
5317 | 0xe809, 0xf81f} | |
5318 | , /* entry pseudo-op */ | |
5319 | { | |
5320 | 0x0100, 0xff00} | |
5321 | , /* addiu $s1,$sp,n */ | |
5322 | { | |
5323 | 0, 0} /* end of table marker */ | |
5324 | }; | |
5325 | ||
5326 | /* Find an upper bound on the prologue. */ | |
5327 | end_pc = skip_prologue_using_sal (pc); | |
5328 | if (end_pc == 0) | |
5329 | end_pc = pc + 100; /* Magic. */ | |
5330 | ||
5331 | /* Skip the typical prologue instructions. These are the stack adjustment | |
5332 | instruction and the instructions that save registers on the stack | |
5333 | or in the gcc frame. */ | |
5334 | for (; pc < end_pc; pc += MIPS16_INSTLEN) | |
5335 | { | |
5336 | unsigned short inst; | |
5337 | int i; | |
5338 | ||
5339 | inst = mips_fetch_instruction (pc); | |
5340 | ||
5341 | /* Normally we ignore an extend instruction. However, if it is | |
5342 | not followed by a valid prologue instruction, we must adjust | |
5343 | the pc back over the extend so that it won't be considered | |
5344 | part of the prologue. */ | |
5345 | if ((inst & 0xf800) == 0xf000) /* extend */ | |
88658117 | 5346 | { |
6d82d43b AC |
5347 | extend_bytes = MIPS16_INSTLEN; |
5348 | continue; | |
88658117 | 5349 | } |
6d82d43b AC |
5350 | prev_extend_bytes = extend_bytes; |
5351 | extend_bytes = 0; | |
5352 | ||
5353 | /* Check for other valid prologue instructions besides extend. */ | |
5354 | for (i = 0; table[i].mask != 0; i++) | |
5355 | if ((inst & table[i].mask) == table[i].inst) /* found, get out */ | |
5356 | break; | |
5357 | if (table[i].mask != 0) /* it was in table? */ | |
5358 | continue; /* ignore it */ | |
5359 | else | |
5360 | /* non-prologue */ | |
88658117 | 5361 | { |
6d82d43b AC |
5362 | /* Return the current pc, adjusted backwards by 2 if |
5363 | the previous instruction was an extend. */ | |
5364 | return pc - prev_extend_bytes; | |
88658117 AC |
5365 | } |
5366 | } | |
6d82d43b AC |
5367 | return pc; |
5368 | } | |
5369 | ||
5370 | /* To skip prologues, I use this predicate. Returns either PC itself | |
5371 | if the code at PC does not look like a function prologue; otherwise | |
5372 | returns an address that (if we're lucky) follows the prologue. If | |
5373 | LENIENT, then we must skip everything which is involved in setting | |
5374 | up the frame (it's OK to skip more, just so long as we don't skip | |
5375 | anything which might clobber the registers which are being saved. | |
5376 | We must skip more in the case where part of the prologue is in the | |
5377 | delay slot of a non-prologue instruction). */ | |
5378 | ||
5379 | static CORE_ADDR | |
5380 | mips_skip_prologue (CORE_ADDR pc) | |
5381 | { | |
5382 | /* See if we can determine the end of the prologue via the symbol table. | |
5383 | If so, then return either PC, or the PC after the prologue, whichever | |
5384 | is greater. */ | |
5385 | ||
177f84a3 | 5386 | CORE_ADDR post_prologue_pc = after_prologue (pc); |
6d82d43b AC |
5387 | |
5388 | if (post_prologue_pc != 0) | |
5389 | return max (pc, post_prologue_pc); | |
5390 | ||
5391 | /* Can't determine prologue from the symbol table, need to examine | |
5392 | instructions. */ | |
5393 | ||
5394 | if (pc_is_mips16 (pc)) | |
5395 | return mips16_skip_prologue (pc); | |
5396 | else | |
5397 | return mips32_skip_prologue (pc); | |
88658117 AC |
5398 | } |
5399 | ||
a5ea2558 AC |
5400 | /* Root of all "set mips "/"show mips " commands. This will eventually be |
5401 | used for all MIPS-specific commands. */ | |
5402 | ||
a5ea2558 | 5403 | static void |
acdb74a0 | 5404 | show_mips_command (char *args, int from_tty) |
a5ea2558 AC |
5405 | { |
5406 | help_list (showmipscmdlist, "show mips ", all_commands, gdb_stdout); | |
5407 | } | |
5408 | ||
a5ea2558 | 5409 | static void |
acdb74a0 | 5410 | set_mips_command (char *args, int from_tty) |
a5ea2558 | 5411 | { |
6d82d43b AC |
5412 | printf_unfiltered |
5413 | ("\"set mips\" must be followed by an appropriate subcommand.\n"); | |
a5ea2558 AC |
5414 | help_list (setmipscmdlist, "set mips ", all_commands, gdb_stdout); |
5415 | } | |
5416 | ||
c906108c SS |
5417 | /* Commands to show/set the MIPS FPU type. */ |
5418 | ||
c906108c | 5419 | static void |
acdb74a0 | 5420 | show_mipsfpu_command (char *args, int from_tty) |
c906108c | 5421 | { |
c906108c SS |
5422 | char *fpu; |
5423 | switch (MIPS_FPU_TYPE) | |
5424 | { | |
5425 | case MIPS_FPU_SINGLE: | |
5426 | fpu = "single-precision"; | |
5427 | break; | |
5428 | case MIPS_FPU_DOUBLE: | |
5429 | fpu = "double-precision"; | |
5430 | break; | |
5431 | case MIPS_FPU_NONE: | |
5432 | fpu = "absent (none)"; | |
5433 | break; | |
93d56215 AC |
5434 | default: |
5435 | internal_error (__FILE__, __LINE__, "bad switch"); | |
c906108c SS |
5436 | } |
5437 | if (mips_fpu_type_auto) | |
6d82d43b AC |
5438 | printf_unfiltered |
5439 | ("The MIPS floating-point coprocessor is set automatically (currently %s)\n", | |
5440 | fpu); | |
c906108c | 5441 | else |
6d82d43b AC |
5442 | printf_unfiltered |
5443 | ("The MIPS floating-point coprocessor is assumed to be %s\n", fpu); | |
c906108c SS |
5444 | } |
5445 | ||
5446 | ||
c906108c | 5447 | static void |
acdb74a0 | 5448 | set_mipsfpu_command (char *args, int from_tty) |
c906108c | 5449 | { |
6d82d43b AC |
5450 | printf_unfiltered |
5451 | ("\"set mipsfpu\" must be followed by \"double\", \"single\",\"none\" or \"auto\".\n"); | |
c906108c SS |
5452 | show_mipsfpu_command (args, from_tty); |
5453 | } | |
5454 | ||
c906108c | 5455 | static void |
acdb74a0 | 5456 | set_mipsfpu_single_command (char *args, int from_tty) |
c906108c | 5457 | { |
8d5838b5 AC |
5458 | struct gdbarch_info info; |
5459 | gdbarch_info_init (&info); | |
c906108c SS |
5460 | mips_fpu_type = MIPS_FPU_SINGLE; |
5461 | mips_fpu_type_auto = 0; | |
8d5838b5 AC |
5462 | /* FIXME: cagney/2003-11-15: Should be setting a field in "info" |
5463 | instead of relying on globals. Doing that would let generic code | |
5464 | handle the search for this specific architecture. */ | |
5465 | if (!gdbarch_update_p (info)) | |
5466 | internal_error (__FILE__, __LINE__, "set mipsfpu failed"); | |
c906108c SS |
5467 | } |
5468 | ||
c906108c | 5469 | static void |
acdb74a0 | 5470 | set_mipsfpu_double_command (char *args, int from_tty) |
c906108c | 5471 | { |
8d5838b5 AC |
5472 | struct gdbarch_info info; |
5473 | gdbarch_info_init (&info); | |
c906108c SS |
5474 | mips_fpu_type = MIPS_FPU_DOUBLE; |
5475 | mips_fpu_type_auto = 0; | |
8d5838b5 AC |
5476 | /* FIXME: cagney/2003-11-15: Should be setting a field in "info" |
5477 | instead of relying on globals. Doing that would let generic code | |
5478 | handle the search for this specific architecture. */ | |
5479 | if (!gdbarch_update_p (info)) | |
5480 | internal_error (__FILE__, __LINE__, "set mipsfpu failed"); | |
c906108c SS |
5481 | } |
5482 | ||
c906108c | 5483 | static void |
acdb74a0 | 5484 | set_mipsfpu_none_command (char *args, int from_tty) |
c906108c | 5485 | { |
8d5838b5 AC |
5486 | struct gdbarch_info info; |
5487 | gdbarch_info_init (&info); | |
c906108c SS |
5488 | mips_fpu_type = MIPS_FPU_NONE; |
5489 | mips_fpu_type_auto = 0; | |
8d5838b5 AC |
5490 | /* FIXME: cagney/2003-11-15: Should be setting a field in "info" |
5491 | instead of relying on globals. Doing that would let generic code | |
5492 | handle the search for this specific architecture. */ | |
5493 | if (!gdbarch_update_p (info)) | |
5494 | internal_error (__FILE__, __LINE__, "set mipsfpu failed"); | |
c906108c SS |
5495 | } |
5496 | ||
c906108c | 5497 | static void |
acdb74a0 | 5498 | set_mipsfpu_auto_command (char *args, int from_tty) |
c906108c SS |
5499 | { |
5500 | mips_fpu_type_auto = 1; | |
5501 | } | |
5502 | ||
c906108c | 5503 | /* Attempt to identify the particular processor model by reading the |
691c0433 AC |
5504 | processor id. NOTE: cagney/2003-11-15: Firstly it isn't clear that |
5505 | the relevant processor still exists (it dates back to '94) and | |
5506 | secondly this is not the way to do this. The processor type should | |
5507 | be set by forcing an architecture change. */ | |
c906108c | 5508 | |
691c0433 AC |
5509 | void |
5510 | deprecated_mips_set_processor_regs_hack (void) | |
c906108c | 5511 | { |
691c0433 | 5512 | struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); |
c906108c SS |
5513 | CORE_ADDR prid; |
5514 | ||
5515 | prid = read_register (PRID_REGNUM); | |
5516 | ||
5517 | if ((prid & ~0xf) == 0x700) | |
691c0433 | 5518 | tdep->mips_processor_reg_names = mips_r3041_reg_names; |
c906108c SS |
5519 | } |
5520 | ||
5521 | /* Just like reinit_frame_cache, but with the right arguments to be | |
5522 | callable as an sfunc. */ | |
5523 | ||
5524 | static void | |
acdb74a0 AC |
5525 | reinit_frame_cache_sfunc (char *args, int from_tty, |
5526 | struct cmd_list_element *c) | |
c906108c SS |
5527 | { |
5528 | reinit_frame_cache (); | |
5529 | } | |
5530 | ||
a89aa300 AC |
5531 | static int |
5532 | gdb_print_insn_mips (bfd_vma memaddr, struct disassemble_info *info) | |
c906108c | 5533 | { |
e5ab0dce | 5534 | struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); |
c906108c SS |
5535 | mips_extra_func_info_t proc_desc; |
5536 | ||
5537 | /* Search for the function containing this address. Set the low bit | |
5538 | of the address when searching, in case we were given an even address | |
5539 | that is the start of a 16-bit function. If we didn't do this, | |
5540 | the search would fail because the symbol table says the function | |
5541 | starts at an odd address, i.e. 1 byte past the given address. */ | |
5542 | memaddr = ADDR_BITS_REMOVE (memaddr); | |
95404a3e | 5543 | proc_desc = non_heuristic_proc_desc (make_mips16_addr (memaddr), NULL); |
c906108c SS |
5544 | |
5545 | /* Make an attempt to determine if this is a 16-bit function. If | |
5546 | the procedure descriptor exists and the address therein is odd, | |
5547 | it's definitely a 16-bit function. Otherwise, we have to just | |
5548 | guess that if the address passed in is odd, it's 16-bits. */ | |
d31431ed AC |
5549 | /* FIXME: cagney/2003-06-26: Is this even necessary? The |
5550 | disassembler needs to be able to locally determine the ISA, and | |
5551 | not rely on GDB. Otherwize the stand-alone 'objdump -d' will not | |
5552 | work. */ | |
c906108c | 5553 | if (proc_desc) |
d31431ed AC |
5554 | { |
5555 | if (pc_is_mips16 (PROC_LOW_ADDR (proc_desc))) | |
6d82d43b | 5556 | info->mach = bfd_mach_mips16; |
d31431ed | 5557 | } |
c906108c | 5558 | else |
d31431ed AC |
5559 | { |
5560 | if (pc_is_mips16 (memaddr)) | |
6d82d43b AC |
5561 | info->mach = bfd_mach_mips16; |
5562 | } | |
c906108c SS |
5563 | |
5564 | /* Round down the instruction address to the appropriate boundary. */ | |
65c11066 | 5565 | memaddr &= (info->mach == bfd_mach_mips16 ? ~1 : ~3); |
c5aa993b | 5566 | |
e5ab0dce | 5567 | /* Set the disassembler options. */ |
6d82d43b | 5568 | if (tdep->mips_abi == MIPS_ABI_N32 || tdep->mips_abi == MIPS_ABI_N64) |
e5ab0dce AC |
5569 | { |
5570 | /* Set up the disassembler info, so that we get the right | |
6d82d43b | 5571 | register names from libopcodes. */ |
e5ab0dce AC |
5572 | if (tdep->mips_abi == MIPS_ABI_N32) |
5573 | info->disassembler_options = "gpr-names=n32"; | |
5574 | else | |
5575 | info->disassembler_options = "gpr-names=64"; | |
5576 | info->flavour = bfd_target_elf_flavour; | |
5577 | } | |
5578 | else | |
5579 | /* This string is not recognized explicitly by the disassembler, | |
5580 | but it tells the disassembler to not try to guess the ABI from | |
5581 | the bfd elf headers, such that, if the user overrides the ABI | |
5582 | of a program linked as NewABI, the disassembly will follow the | |
5583 | register naming conventions specified by the user. */ | |
5584 | info->disassembler_options = "gpr-names=32"; | |
5585 | ||
c906108c | 5586 | /* Call the appropriate disassembler based on the target endian-ness. */ |
d7449b42 | 5587 | if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) |
c906108c SS |
5588 | return print_insn_big_mips (memaddr, info); |
5589 | else | |
5590 | return print_insn_little_mips (memaddr, info); | |
5591 | } | |
5592 | ||
c906108c SS |
5593 | /* This function implements the BREAKPOINT_FROM_PC macro. It uses the program |
5594 | counter value to determine whether a 16- or 32-bit breakpoint should be | |
5595 | used. It returns a pointer to a string of bytes that encode a breakpoint | |
5596 | instruction, stores the length of the string to *lenptr, and adjusts pc | |
5597 | (if necessary) to point to the actual memory location where the | |
5598 | breakpoint should be inserted. */ | |
5599 | ||
f7ab6ec6 | 5600 | static const unsigned char * |
6d82d43b | 5601 | mips_breakpoint_from_pc (CORE_ADDR *pcptr, int *lenptr) |
c906108c | 5602 | { |
d7449b42 | 5603 | if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) |
c906108c SS |
5604 | { |
5605 | if (pc_is_mips16 (*pcptr)) | |
5606 | { | |
6d82d43b | 5607 | static unsigned char mips16_big_breakpoint[] = { 0xe8, 0xa5 }; |
95404a3e | 5608 | *pcptr = unmake_mips16_addr (*pcptr); |
c5aa993b | 5609 | *lenptr = sizeof (mips16_big_breakpoint); |
c906108c SS |
5610 | return mips16_big_breakpoint; |
5611 | } | |
5612 | else | |
5613 | { | |
aaab4dba AC |
5614 | /* The IDT board uses an unusual breakpoint value, and |
5615 | sometimes gets confused when it sees the usual MIPS | |
5616 | breakpoint instruction. */ | |
6d82d43b AC |
5617 | static unsigned char big_breakpoint[] = { 0, 0x5, 0, 0xd }; |
5618 | static unsigned char pmon_big_breakpoint[] = { 0, 0, 0, 0xd }; | |
5619 | static unsigned char idt_big_breakpoint[] = { 0, 0, 0x0a, 0xd }; | |
c906108c | 5620 | |
c5aa993b | 5621 | *lenptr = sizeof (big_breakpoint); |
c906108c SS |
5622 | |
5623 | if (strcmp (target_shortname, "mips") == 0) | |
5624 | return idt_big_breakpoint; | |
5625 | else if (strcmp (target_shortname, "ddb") == 0 | |
5626 | || strcmp (target_shortname, "pmon") == 0 | |
5627 | || strcmp (target_shortname, "lsi") == 0) | |
5628 | return pmon_big_breakpoint; | |
5629 | else | |
5630 | return big_breakpoint; | |
5631 | } | |
5632 | } | |
5633 | else | |
5634 | { | |
5635 | if (pc_is_mips16 (*pcptr)) | |
5636 | { | |
6d82d43b | 5637 | static unsigned char mips16_little_breakpoint[] = { 0xa5, 0xe8 }; |
95404a3e | 5638 | *pcptr = unmake_mips16_addr (*pcptr); |
c5aa993b | 5639 | *lenptr = sizeof (mips16_little_breakpoint); |
c906108c SS |
5640 | return mips16_little_breakpoint; |
5641 | } | |
5642 | else | |
5643 | { | |
6d82d43b AC |
5644 | static unsigned char little_breakpoint[] = { 0xd, 0, 0x5, 0 }; |
5645 | static unsigned char pmon_little_breakpoint[] = { 0xd, 0, 0, 0 }; | |
5646 | static unsigned char idt_little_breakpoint[] = { 0xd, 0x0a, 0, 0 }; | |
c906108c | 5647 | |
c5aa993b | 5648 | *lenptr = sizeof (little_breakpoint); |
c906108c SS |
5649 | |
5650 | if (strcmp (target_shortname, "mips") == 0) | |
5651 | return idt_little_breakpoint; | |
5652 | else if (strcmp (target_shortname, "ddb") == 0 | |
5653 | || strcmp (target_shortname, "pmon") == 0 | |
5654 | || strcmp (target_shortname, "lsi") == 0) | |
5655 | return pmon_little_breakpoint; | |
5656 | else | |
5657 | return little_breakpoint; | |
5658 | } | |
5659 | } | |
5660 | } | |
5661 | ||
5662 | /* If PC is in a mips16 call or return stub, return the address of the target | |
5663 | PC, which is either the callee or the caller. There are several | |
5664 | cases which must be handled: | |
5665 | ||
5666 | * If the PC is in __mips16_ret_{d,s}f, this is a return stub and the | |
c5aa993b | 5667 | target PC is in $31 ($ra). |
c906108c | 5668 | * If the PC is in __mips16_call_stub_{1..10}, this is a call stub |
c5aa993b | 5669 | and the target PC is in $2. |
c906108c | 5670 | * If the PC at the start of __mips16_call_stub_{s,d}f_{0..10}, i.e. |
c5aa993b JM |
5671 | before the jal instruction, this is effectively a call stub |
5672 | and the the target PC is in $2. Otherwise this is effectively | |
5673 | a return stub and the target PC is in $18. | |
c906108c SS |
5674 | |
5675 | See the source code for the stubs in gcc/config/mips/mips16.S for | |
5676 | gory details. | |
5677 | ||
5678 | This function implements the SKIP_TRAMPOLINE_CODE macro. | |
c5aa993b | 5679 | */ |
c906108c | 5680 | |
757a7cc6 | 5681 | static CORE_ADDR |
acdb74a0 | 5682 | mips_skip_stub (CORE_ADDR pc) |
c906108c SS |
5683 | { |
5684 | char *name; | |
5685 | CORE_ADDR start_addr; | |
5686 | ||
5687 | /* Find the starting address and name of the function containing the PC. */ | |
5688 | if (find_pc_partial_function (pc, &name, &start_addr, NULL) == 0) | |
5689 | return 0; | |
5690 | ||
5691 | /* If the PC is in __mips16_ret_{d,s}f, this is a return stub and the | |
5692 | target PC is in $31 ($ra). */ | |
5693 | if (strcmp (name, "__mips16_ret_sf") == 0 | |
5694 | || strcmp (name, "__mips16_ret_df") == 0) | |
6c997a34 | 5695 | return read_signed_register (RA_REGNUM); |
c906108c SS |
5696 | |
5697 | if (strncmp (name, "__mips16_call_stub_", 19) == 0) | |
5698 | { | |
5699 | /* If the PC is in __mips16_call_stub_{1..10}, this is a call stub | |
5700 | and the target PC is in $2. */ | |
5701 | if (name[19] >= '0' && name[19] <= '9') | |
6c997a34 | 5702 | return read_signed_register (2); |
c906108c SS |
5703 | |
5704 | /* If the PC at the start of __mips16_call_stub_{s,d}f_{0..10}, i.e. | |
c5aa993b JM |
5705 | before the jal instruction, this is effectively a call stub |
5706 | and the the target PC is in $2. Otherwise this is effectively | |
5707 | a return stub and the target PC is in $18. */ | |
c906108c SS |
5708 | else if (name[19] == 's' || name[19] == 'd') |
5709 | { | |
5710 | if (pc == start_addr) | |
5711 | { | |
5712 | /* Check if the target of the stub is a compiler-generated | |
c5aa993b JM |
5713 | stub. Such a stub for a function bar might have a name |
5714 | like __fn_stub_bar, and might look like this: | |
5715 | mfc1 $4,$f13 | |
5716 | mfc1 $5,$f12 | |
5717 | mfc1 $6,$f15 | |
5718 | mfc1 $7,$f14 | |
5719 | la $1,bar (becomes a lui/addiu pair) | |
5720 | jr $1 | |
5721 | So scan down to the lui/addi and extract the target | |
5722 | address from those two instructions. */ | |
c906108c | 5723 | |
6c997a34 | 5724 | CORE_ADDR target_pc = read_signed_register (2); |
c906108c SS |
5725 | t_inst inst; |
5726 | int i; | |
5727 | ||
5728 | /* See if the name of the target function is __fn_stub_*. */ | |
6d82d43b AC |
5729 | if (find_pc_partial_function (target_pc, &name, NULL, NULL) == |
5730 | 0) | |
c906108c SS |
5731 | return target_pc; |
5732 | if (strncmp (name, "__fn_stub_", 10) != 0 | |
5733 | && strcmp (name, "etext") != 0 | |
5734 | && strcmp (name, "_etext") != 0) | |
5735 | return target_pc; | |
5736 | ||
5737 | /* Scan through this _fn_stub_ code for the lui/addiu pair. | |
c5aa993b JM |
5738 | The limit on the search is arbitrarily set to 20 |
5739 | instructions. FIXME. */ | |
c906108c SS |
5740 | for (i = 0, pc = 0; i < 20; i++, target_pc += MIPS_INSTLEN) |
5741 | { | |
c5aa993b JM |
5742 | inst = mips_fetch_instruction (target_pc); |
5743 | if ((inst & 0xffff0000) == 0x3c010000) /* lui $at */ | |
5744 | pc = (inst << 16) & 0xffff0000; /* high word */ | |
5745 | else if ((inst & 0xffff0000) == 0x24210000) /* addiu $at */ | |
5746 | return pc | (inst & 0xffff); /* low word */ | |
c906108c SS |
5747 | } |
5748 | ||
5749 | /* Couldn't find the lui/addui pair, so return stub address. */ | |
5750 | return target_pc; | |
5751 | } | |
5752 | else | |
5753 | /* This is the 'return' part of a call stub. The return | |
5754 | address is in $r18. */ | |
6c997a34 | 5755 | return read_signed_register (18); |
c906108c SS |
5756 | } |
5757 | } | |
c5aa993b | 5758 | return 0; /* not a stub */ |
c906108c SS |
5759 | } |
5760 | ||
5761 | ||
5762 | /* Return non-zero if the PC is inside a call thunk (aka stub or trampoline). | |
5763 | This implements the IN_SOLIB_CALL_TRAMPOLINE macro. */ | |
5764 | ||
757a7cc6 | 5765 | static int |
acdb74a0 | 5766 | mips_in_call_stub (CORE_ADDR pc, char *name) |
c906108c SS |
5767 | { |
5768 | CORE_ADDR start_addr; | |
5769 | ||
5770 | /* Find the starting address of the function containing the PC. If the | |
5771 | caller didn't give us a name, look it up at the same time. */ | |
6d82d43b AC |
5772 | if (find_pc_partial_function (pc, name ? NULL : &name, &start_addr, NULL) == |
5773 | 0) | |
c906108c SS |
5774 | return 0; |
5775 | ||
5776 | if (strncmp (name, "__mips16_call_stub_", 19) == 0) | |
5777 | { | |
5778 | /* If the PC is in __mips16_call_stub_{1..10}, this is a call stub. */ | |
5779 | if (name[19] >= '0' && name[19] <= '9') | |
5780 | return 1; | |
5781 | /* If the PC at the start of __mips16_call_stub_{s,d}f_{0..10}, i.e. | |
c5aa993b | 5782 | before the jal instruction, this is effectively a call stub. */ |
c906108c SS |
5783 | else if (name[19] == 's' || name[19] == 'd') |
5784 | return pc == start_addr; | |
5785 | } | |
5786 | ||
c5aa993b | 5787 | return 0; /* not a stub */ |
c906108c SS |
5788 | } |
5789 | ||
5790 | ||
5791 | /* Return non-zero if the PC is inside a return thunk (aka stub or trampoline). | |
5792 | This implements the IN_SOLIB_RETURN_TRAMPOLINE macro. */ | |
5793 | ||
e41b17f0 | 5794 | static int |
acdb74a0 | 5795 | mips_in_return_stub (CORE_ADDR pc, char *name) |
c906108c SS |
5796 | { |
5797 | CORE_ADDR start_addr; | |
5798 | ||
5799 | /* Find the starting address of the function containing the PC. */ | |
5800 | if (find_pc_partial_function (pc, NULL, &start_addr, NULL) == 0) | |
5801 | return 0; | |
5802 | ||
5803 | /* If the PC is in __mips16_ret_{d,s}f, this is a return stub. */ | |
5804 | if (strcmp (name, "__mips16_ret_sf") == 0 | |
5805 | || strcmp (name, "__mips16_ret_df") == 0) | |
5806 | return 1; | |
5807 | ||
5808 | /* If the PC is in __mips16_call_stub_{s,d}f_{0..10} but not at the start, | |
c5aa993b | 5809 | i.e. after the jal instruction, this is effectively a return stub. */ |
c906108c | 5810 | if (strncmp (name, "__mips16_call_stub_", 19) == 0 |
6d82d43b | 5811 | && (name[19] == 's' || name[19] == 'd') && pc != start_addr) |
c906108c SS |
5812 | return 1; |
5813 | ||
c5aa993b | 5814 | return 0; /* not a stub */ |
c906108c SS |
5815 | } |
5816 | ||
5817 | ||
a53c66de AC |
5818 | /* Return non-zero if the PC is in a library helper function that |
5819 | should be ignored. This implements the | |
5820 | DEPRECATED_IGNORE_HELPER_CALL macro. */ | |
c906108c SS |
5821 | |
5822 | int | |
acdb74a0 | 5823 | mips_ignore_helper (CORE_ADDR pc) |
c906108c SS |
5824 | { |
5825 | char *name; | |
5826 | ||
5827 | /* Find the starting address and name of the function containing the PC. */ | |
5828 | if (find_pc_partial_function (pc, &name, NULL, NULL) == 0) | |
5829 | return 0; | |
5830 | ||
5831 | /* If the PC is in __mips16_ret_{d,s}f, this is a library helper function | |
5832 | that we want to ignore. */ | |
5833 | return (strcmp (name, "__mips16_ret_sf") == 0 | |
5834 | || strcmp (name, "__mips16_ret_df") == 0); | |
5835 | } | |
5836 | ||
5837 | ||
a4b8ebc8 AC |
5838 | /* Convert a dbx stab register number (from `r' declaration) to a GDB |
5839 | [1 * NUM_REGS .. 2 * NUM_REGS) REGNUM. */ | |
88c72b7d AC |
5840 | |
5841 | static int | |
5842 | mips_stab_reg_to_regnum (int num) | |
5843 | { | |
a4b8ebc8 | 5844 | int regnum; |
2f38ef89 | 5845 | if (num >= 0 && num < 32) |
a4b8ebc8 | 5846 | regnum = num; |
2f38ef89 | 5847 | else if (num >= 38 && num < 70) |
56cea623 | 5848 | regnum = num + mips_regnum (current_gdbarch)->fp0 - 38; |
040b99fd | 5849 | else if (num == 70) |
56cea623 | 5850 | regnum = mips_regnum (current_gdbarch)->hi; |
040b99fd | 5851 | else if (num == 71) |
56cea623 | 5852 | regnum = mips_regnum (current_gdbarch)->lo; |
2f38ef89 | 5853 | else |
a4b8ebc8 AC |
5854 | /* This will hopefully (eventually) provoke a warning. Should |
5855 | we be calling complaint() here? */ | |
5856 | return NUM_REGS + NUM_PSEUDO_REGS; | |
5857 | return NUM_REGS + regnum; | |
88c72b7d AC |
5858 | } |
5859 | ||
2f38ef89 | 5860 | |
a4b8ebc8 AC |
5861 | /* Convert a dwarf, dwarf2, or ecoff register number to a GDB [1 * |
5862 | NUM_REGS .. 2 * NUM_REGS) REGNUM. */ | |
88c72b7d AC |
5863 | |
5864 | static int | |
2f38ef89 | 5865 | mips_dwarf_dwarf2_ecoff_reg_to_regnum (int num) |
88c72b7d | 5866 | { |
a4b8ebc8 | 5867 | int regnum; |
2f38ef89 | 5868 | if (num >= 0 && num < 32) |
a4b8ebc8 | 5869 | regnum = num; |
2f38ef89 | 5870 | else if (num >= 32 && num < 64) |
56cea623 | 5871 | regnum = num + mips_regnum (current_gdbarch)->fp0 - 32; |
040b99fd | 5872 | else if (num == 64) |
56cea623 | 5873 | regnum = mips_regnum (current_gdbarch)->hi; |
040b99fd | 5874 | else if (num == 65) |
56cea623 | 5875 | regnum = mips_regnum (current_gdbarch)->lo; |
2f38ef89 | 5876 | else |
a4b8ebc8 AC |
5877 | /* This will hopefully (eventually) provoke a warning. Should we |
5878 | be calling complaint() here? */ | |
5879 | return NUM_REGS + NUM_PSEUDO_REGS; | |
5880 | return NUM_REGS + regnum; | |
5881 | } | |
5882 | ||
5883 | static int | |
5884 | mips_register_sim_regno (int regnum) | |
5885 | { | |
5886 | /* Only makes sense to supply raw registers. */ | |
5887 | gdb_assert (regnum >= 0 && regnum < NUM_REGS); | |
5888 | /* FIXME: cagney/2002-05-13: Need to look at the pseudo register to | |
5889 | decide if it is valid. Should instead define a standard sim/gdb | |
5890 | register numbering scheme. */ | |
5891 | if (REGISTER_NAME (NUM_REGS + regnum) != NULL | |
5892 | && REGISTER_NAME (NUM_REGS + regnum)[0] != '\0') | |
5893 | return regnum; | |
5894 | else | |
6d82d43b | 5895 | return LEGACY_SIM_REGNO_IGNORE; |
88c72b7d AC |
5896 | } |
5897 | ||
2f38ef89 | 5898 | |
fc0c74b1 AC |
5899 | /* Convert an integer into an address. By first converting the value |
5900 | into a pointer and then extracting it signed, the address is | |
5901 | guarenteed to be correctly sign extended. */ | |
5902 | ||
5903 | static CORE_ADDR | |
5904 | mips_integer_to_address (struct type *type, void *buf) | |
5905 | { | |
5906 | char *tmp = alloca (TYPE_LENGTH (builtin_type_void_data_ptr)); | |
5907 | LONGEST val = unpack_long (type, buf); | |
5908 | store_signed_integer (tmp, TYPE_LENGTH (builtin_type_void_data_ptr), val); | |
5909 | return extract_signed_integer (tmp, | |
5910 | TYPE_LENGTH (builtin_type_void_data_ptr)); | |
5911 | } | |
5912 | ||
caaa3122 DJ |
5913 | static void |
5914 | mips_find_abi_section (bfd *abfd, asection *sect, void *obj) | |
5915 | { | |
5916 | enum mips_abi *abip = (enum mips_abi *) obj; | |
5917 | const char *name = bfd_get_section_name (abfd, sect); | |
5918 | ||
5919 | if (*abip != MIPS_ABI_UNKNOWN) | |
5920 | return; | |
5921 | ||
5922 | if (strncmp (name, ".mdebug.", 8) != 0) | |
5923 | return; | |
5924 | ||
5925 | if (strcmp (name, ".mdebug.abi32") == 0) | |
5926 | *abip = MIPS_ABI_O32; | |
5927 | else if (strcmp (name, ".mdebug.abiN32") == 0) | |
5928 | *abip = MIPS_ABI_N32; | |
62a49b2c | 5929 | else if (strcmp (name, ".mdebug.abi64") == 0) |
e3bddbfa | 5930 | *abip = MIPS_ABI_N64; |
caaa3122 DJ |
5931 | else if (strcmp (name, ".mdebug.abiO64") == 0) |
5932 | *abip = MIPS_ABI_O64; | |
5933 | else if (strcmp (name, ".mdebug.eabi32") == 0) | |
5934 | *abip = MIPS_ABI_EABI32; | |
5935 | else if (strcmp (name, ".mdebug.eabi64") == 0) | |
5936 | *abip = MIPS_ABI_EABI64; | |
5937 | else | |
5938 | warning ("unsupported ABI %s.", name + 8); | |
5939 | } | |
5940 | ||
2e4ebe70 DJ |
5941 | static enum mips_abi |
5942 | global_mips_abi (void) | |
5943 | { | |
5944 | int i; | |
5945 | ||
5946 | for (i = 0; mips_abi_strings[i] != NULL; i++) | |
5947 | if (mips_abi_strings[i] == mips_abi_string) | |
5948 | return (enum mips_abi) i; | |
5949 | ||
6d82d43b | 5950 | internal_error (__FILE__, __LINE__, "unknown ABI string"); |
2e4ebe70 DJ |
5951 | } |
5952 | ||
c2d11a7d | 5953 | static struct gdbarch * |
6d82d43b | 5954 | mips_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) |
c2d11a7d | 5955 | { |
c2d11a7d JM |
5956 | struct gdbarch *gdbarch; |
5957 | struct gdbarch_tdep *tdep; | |
5958 | int elf_flags; | |
2e4ebe70 | 5959 | enum mips_abi mips_abi, found_abi, wanted_abi; |
a4b8ebc8 | 5960 | int num_regs; |
8d5838b5 | 5961 | enum mips_fpu_type fpu_type; |
c2d11a7d | 5962 | |
ec03c1ac AC |
5963 | /* First of all, extract the elf_flags, if available. */ |
5964 | if (info.abfd && bfd_get_flavour (info.abfd) == bfd_target_elf_flavour) | |
5965 | elf_flags = elf_elfheader (info.abfd)->e_flags; | |
6214a8a1 AC |
5966 | else if (arches != NULL) |
5967 | elf_flags = gdbarch_tdep (arches->gdbarch)->elf_flags; | |
ec03c1ac AC |
5968 | else |
5969 | elf_flags = 0; | |
5970 | if (gdbarch_debug) | |
5971 | fprintf_unfiltered (gdb_stdlog, | |
6d82d43b | 5972 | "mips_gdbarch_init: elf_flags = 0x%08x\n", elf_flags); |
c2d11a7d | 5973 | |
102182a9 | 5974 | /* Check ELF_FLAGS to see if it specifies the ABI being used. */ |
0dadbba0 AC |
5975 | switch ((elf_flags & EF_MIPS_ABI)) |
5976 | { | |
5977 | case E_MIPS_ABI_O32: | |
ec03c1ac | 5978 | found_abi = MIPS_ABI_O32; |
0dadbba0 AC |
5979 | break; |
5980 | case E_MIPS_ABI_O64: | |
ec03c1ac | 5981 | found_abi = MIPS_ABI_O64; |
0dadbba0 AC |
5982 | break; |
5983 | case E_MIPS_ABI_EABI32: | |
ec03c1ac | 5984 | found_abi = MIPS_ABI_EABI32; |
0dadbba0 AC |
5985 | break; |
5986 | case E_MIPS_ABI_EABI64: | |
ec03c1ac | 5987 | found_abi = MIPS_ABI_EABI64; |
0dadbba0 AC |
5988 | break; |
5989 | default: | |
acdb74a0 | 5990 | if ((elf_flags & EF_MIPS_ABI2)) |
ec03c1ac | 5991 | found_abi = MIPS_ABI_N32; |
acdb74a0 | 5992 | else |
ec03c1ac | 5993 | found_abi = MIPS_ABI_UNKNOWN; |
0dadbba0 AC |
5994 | break; |
5995 | } | |
acdb74a0 | 5996 | |
caaa3122 | 5997 | /* GCC creates a pseudo-section whose name describes the ABI. */ |
ec03c1ac AC |
5998 | if (found_abi == MIPS_ABI_UNKNOWN && info.abfd != NULL) |
5999 | bfd_map_over_sections (info.abfd, mips_find_abi_section, &found_abi); | |
caaa3122 | 6000 | |
dc305454 | 6001 | /* If we have no useful BFD information, use the ABI from the last |
ec03c1ac AC |
6002 | MIPS architecture (if there is one). */ |
6003 | if (found_abi == MIPS_ABI_UNKNOWN && info.abfd == NULL && arches != NULL) | |
6004 | found_abi = gdbarch_tdep (arches->gdbarch)->found_abi; | |
2e4ebe70 | 6005 | |
32a6503c | 6006 | /* Try the architecture for any hint of the correct ABI. */ |
ec03c1ac | 6007 | if (found_abi == MIPS_ABI_UNKNOWN |
bf64bfd6 AC |
6008 | && info.bfd_arch_info != NULL |
6009 | && info.bfd_arch_info->arch == bfd_arch_mips) | |
6010 | { | |
6011 | switch (info.bfd_arch_info->mach) | |
6012 | { | |
6013 | case bfd_mach_mips3900: | |
ec03c1ac | 6014 | found_abi = MIPS_ABI_EABI32; |
bf64bfd6 AC |
6015 | break; |
6016 | case bfd_mach_mips4100: | |
6017 | case bfd_mach_mips5000: | |
ec03c1ac | 6018 | found_abi = MIPS_ABI_EABI64; |
bf64bfd6 | 6019 | break; |
1d06468c EZ |
6020 | case bfd_mach_mips8000: |
6021 | case bfd_mach_mips10000: | |
32a6503c KB |
6022 | /* On Irix, ELF64 executables use the N64 ABI. The |
6023 | pseudo-sections which describe the ABI aren't present | |
6024 | on IRIX. (Even for executables created by gcc.) */ | |
28d169de KB |
6025 | if (bfd_get_flavour (info.abfd) == bfd_target_elf_flavour |
6026 | && elf_elfheader (info.abfd)->e_ident[EI_CLASS] == ELFCLASS64) | |
ec03c1ac | 6027 | found_abi = MIPS_ABI_N64; |
28d169de | 6028 | else |
ec03c1ac | 6029 | found_abi = MIPS_ABI_N32; |
1d06468c | 6030 | break; |
bf64bfd6 AC |
6031 | } |
6032 | } | |
2e4ebe70 | 6033 | |
ec03c1ac AC |
6034 | if (gdbarch_debug) |
6035 | fprintf_unfiltered (gdb_stdlog, "mips_gdbarch_init: found_abi = %d\n", | |
6036 | found_abi); | |
6037 | ||
6038 | /* What has the user specified from the command line? */ | |
6039 | wanted_abi = global_mips_abi (); | |
6040 | if (gdbarch_debug) | |
6041 | fprintf_unfiltered (gdb_stdlog, "mips_gdbarch_init: wanted_abi = %d\n", | |
6042 | wanted_abi); | |
2e4ebe70 DJ |
6043 | |
6044 | /* Now that we have found what the ABI for this binary would be, | |
6045 | check whether the user is overriding it. */ | |
2e4ebe70 DJ |
6046 | if (wanted_abi != MIPS_ABI_UNKNOWN) |
6047 | mips_abi = wanted_abi; | |
ec03c1ac AC |
6048 | else if (found_abi != MIPS_ABI_UNKNOWN) |
6049 | mips_abi = found_abi; | |
6050 | else | |
6051 | mips_abi = MIPS_ABI_O32; | |
6052 | if (gdbarch_debug) | |
6053 | fprintf_unfiltered (gdb_stdlog, "mips_gdbarch_init: mips_abi = %d\n", | |
6054 | mips_abi); | |
2e4ebe70 | 6055 | |
ec03c1ac | 6056 | /* Also used when doing an architecture lookup. */ |
4b9b3959 | 6057 | if (gdbarch_debug) |
ec03c1ac AC |
6058 | fprintf_unfiltered (gdb_stdlog, |
6059 | "mips_gdbarch_init: mips64_transfers_32bit_regs_p = %d\n", | |
6060 | mips64_transfers_32bit_regs_p); | |
0dadbba0 | 6061 | |
8d5838b5 AC |
6062 | /* Determine the MIPS FPU type. */ |
6063 | if (!mips_fpu_type_auto) | |
6064 | fpu_type = mips_fpu_type; | |
6065 | else if (info.bfd_arch_info != NULL | |
6066 | && info.bfd_arch_info->arch == bfd_arch_mips) | |
6067 | switch (info.bfd_arch_info->mach) | |
6068 | { | |
6069 | case bfd_mach_mips3900: | |
6070 | case bfd_mach_mips4100: | |
6071 | case bfd_mach_mips4111: | |
a9d61c86 | 6072 | case bfd_mach_mips4120: |
8d5838b5 AC |
6073 | fpu_type = MIPS_FPU_NONE; |
6074 | break; | |
6075 | case bfd_mach_mips4650: | |
6076 | fpu_type = MIPS_FPU_SINGLE; | |
6077 | break; | |
6078 | default: | |
6079 | fpu_type = MIPS_FPU_DOUBLE; | |
6080 | break; | |
6081 | } | |
6082 | else if (arches != NULL) | |
6083 | fpu_type = gdbarch_tdep (arches->gdbarch)->mips_fpu_type; | |
6084 | else | |
6085 | fpu_type = MIPS_FPU_DOUBLE; | |
6086 | if (gdbarch_debug) | |
6087 | fprintf_unfiltered (gdb_stdlog, | |
6d82d43b | 6088 | "mips_gdbarch_init: fpu_type = %d\n", fpu_type); |
8d5838b5 | 6089 | |
c2d11a7d JM |
6090 | /* try to find a pre-existing architecture */ |
6091 | for (arches = gdbarch_list_lookup_by_info (arches, &info); | |
6092 | arches != NULL; | |
6093 | arches = gdbarch_list_lookup_by_info (arches->next, &info)) | |
6094 | { | |
6095 | /* MIPS needs to be pedantic about which ABI the object is | |
102182a9 | 6096 | using. */ |
9103eae0 | 6097 | if (gdbarch_tdep (arches->gdbarch)->elf_flags != elf_flags) |
c2d11a7d | 6098 | continue; |
9103eae0 | 6099 | if (gdbarch_tdep (arches->gdbarch)->mips_abi != mips_abi) |
0dadbba0 | 6100 | continue; |
719ec221 AC |
6101 | /* Need to be pedantic about which register virtual size is |
6102 | used. */ | |
6103 | if (gdbarch_tdep (arches->gdbarch)->mips64_transfers_32bit_regs_p | |
6104 | != mips64_transfers_32bit_regs_p) | |
6105 | continue; | |
8d5838b5 AC |
6106 | /* Be pedantic about which FPU is selected. */ |
6107 | if (gdbarch_tdep (arches->gdbarch)->mips_fpu_type != fpu_type) | |
6108 | continue; | |
4be87837 | 6109 | return arches->gdbarch; |
c2d11a7d JM |
6110 | } |
6111 | ||
102182a9 | 6112 | /* Need a new architecture. Fill in a target specific vector. */ |
c2d11a7d JM |
6113 | tdep = (struct gdbarch_tdep *) xmalloc (sizeof (struct gdbarch_tdep)); |
6114 | gdbarch = gdbarch_alloc (&info, tdep); | |
6115 | tdep->elf_flags = elf_flags; | |
719ec221 | 6116 | tdep->mips64_transfers_32bit_regs_p = mips64_transfers_32bit_regs_p; |
ec03c1ac AC |
6117 | tdep->found_abi = found_abi; |
6118 | tdep->mips_abi = mips_abi; | |
8d5838b5 | 6119 | tdep->mips_fpu_type = fpu_type; |
c2d11a7d | 6120 | |
102182a9 | 6121 | /* Initially set everything according to the default ABI/ISA. */ |
c2d11a7d JM |
6122 | set_gdbarch_short_bit (gdbarch, 16); |
6123 | set_gdbarch_int_bit (gdbarch, 32); | |
6124 | set_gdbarch_float_bit (gdbarch, 32); | |
6125 | set_gdbarch_double_bit (gdbarch, 64); | |
6126 | set_gdbarch_long_double_bit (gdbarch, 64); | |
a4b8ebc8 AC |
6127 | set_gdbarch_register_reggroup_p (gdbarch, mips_register_reggroup_p); |
6128 | set_gdbarch_pseudo_register_read (gdbarch, mips_pseudo_register_read); | |
6129 | set_gdbarch_pseudo_register_write (gdbarch, mips_pseudo_register_write); | |
1d06468c | 6130 | |
6d82d43b | 6131 | set_gdbarch_elf_make_msymbol_special (gdbarch, |
f7ab6ec6 MS |
6132 | mips_elf_make_msymbol_special); |
6133 | ||
16e109ca | 6134 | /* Fill in the OS dependant register numbers and names. */ |
56cea623 | 6135 | { |
16e109ca | 6136 | const char **reg_names; |
56cea623 AC |
6137 | struct mips_regnum *regnum = GDBARCH_OBSTACK_ZALLOC (gdbarch, |
6138 | struct mips_regnum); | |
56cea623 AC |
6139 | if (info.osabi == GDB_OSABI_IRIX) |
6140 | { | |
6141 | regnum->fp0 = 32; | |
6142 | regnum->pc = 64; | |
6143 | regnum->cause = 65; | |
6144 | regnum->badvaddr = 66; | |
6145 | regnum->hi = 67; | |
6146 | regnum->lo = 68; | |
6147 | regnum->fp_control_status = 69; | |
6148 | regnum->fp_implementation_revision = 70; | |
6149 | num_regs = 71; | |
16e109ca | 6150 | reg_names = mips_irix_reg_names; |
56cea623 AC |
6151 | } |
6152 | else | |
6153 | { | |
6154 | regnum->lo = MIPS_EMBED_LO_REGNUM; | |
6155 | regnum->hi = MIPS_EMBED_HI_REGNUM; | |
6156 | regnum->badvaddr = MIPS_EMBED_BADVADDR_REGNUM; | |
6157 | regnum->cause = MIPS_EMBED_CAUSE_REGNUM; | |
6158 | regnum->pc = MIPS_EMBED_PC_REGNUM; | |
6159 | regnum->fp0 = MIPS_EMBED_FP0_REGNUM; | |
6160 | regnum->fp_control_status = 70; | |
6161 | regnum->fp_implementation_revision = 71; | |
6162 | num_regs = 90; | |
16e109ca AC |
6163 | if (info.bfd_arch_info != NULL |
6164 | && info.bfd_arch_info->mach == bfd_mach_mips3900) | |
6165 | reg_names = mips_tx39_reg_names; | |
6166 | else | |
6167 | reg_names = mips_generic_reg_names; | |
56cea623 AC |
6168 | } |
6169 | /* FIXME: cagney/2003-11-15: For MIPS, hasn't PC_REGNUM been | |
6170 | replaced by read_pc? */ | |
f10683bb MH |
6171 | set_gdbarch_pc_regnum (gdbarch, regnum->pc + num_regs); |
6172 | set_gdbarch_sp_regnum (gdbarch, MIPS_SP_REGNUM + num_regs); | |
56cea623 AC |
6173 | set_gdbarch_fp0_regnum (gdbarch, regnum->fp0); |
6174 | set_gdbarch_num_regs (gdbarch, num_regs); | |
6175 | set_gdbarch_num_pseudo_regs (gdbarch, num_regs); | |
16e109ca AC |
6176 | set_gdbarch_register_name (gdbarch, mips_register_name); |
6177 | tdep->mips_processor_reg_names = reg_names; | |
6178 | tdep->regnum = regnum; | |
56cea623 | 6179 | } |
fe29b929 | 6180 | |
0dadbba0 | 6181 | switch (mips_abi) |
c2d11a7d | 6182 | { |
0dadbba0 | 6183 | case MIPS_ABI_O32: |
25ab4790 | 6184 | set_gdbarch_push_dummy_call (gdbarch, mips_o32_push_dummy_call); |
29dfb2ac | 6185 | set_gdbarch_return_value (gdbarch, mips_o32_return_value); |
acdb74a0 | 6186 | tdep->mips_last_arg_regnum = A0_REGNUM + 4 - 1; |
56cea623 | 6187 | tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 4 - 1; |
4014092b | 6188 | tdep->default_mask_address_p = 0; |
c2d11a7d JM |
6189 | set_gdbarch_long_bit (gdbarch, 32); |
6190 | set_gdbarch_ptr_bit (gdbarch, 32); | |
6191 | set_gdbarch_long_long_bit (gdbarch, 64); | |
6192 | break; | |
0dadbba0 | 6193 | case MIPS_ABI_O64: |
25ab4790 | 6194 | set_gdbarch_push_dummy_call (gdbarch, mips_o64_push_dummy_call); |
6d82d43b AC |
6195 | set_gdbarch_deprecated_store_return_value (gdbarch, |
6196 | mips_o64_store_return_value); | |
6197 | set_gdbarch_deprecated_extract_return_value (gdbarch, | |
6198 | mips_o64_extract_return_value); | |
acdb74a0 | 6199 | tdep->mips_last_arg_regnum = A0_REGNUM + 4 - 1; |
56cea623 | 6200 | tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 4 - 1; |
361d1df0 | 6201 | tdep->default_mask_address_p = 0; |
c2d11a7d JM |
6202 | set_gdbarch_long_bit (gdbarch, 32); |
6203 | set_gdbarch_ptr_bit (gdbarch, 32); | |
6204 | set_gdbarch_long_long_bit (gdbarch, 64); | |
b5622e8d | 6205 | set_gdbarch_deprecated_use_struct_convention (gdbarch, always_use_struct_convention); |
c2d11a7d | 6206 | break; |
0dadbba0 | 6207 | case MIPS_ABI_EABI32: |
25ab4790 | 6208 | set_gdbarch_push_dummy_call (gdbarch, mips_eabi_push_dummy_call); |
6d82d43b AC |
6209 | set_gdbarch_deprecated_store_return_value (gdbarch, |
6210 | mips_eabi_store_return_value); | |
6211 | set_gdbarch_deprecated_extract_return_value (gdbarch, | |
6212 | mips_eabi_extract_return_value); | |
acdb74a0 | 6213 | tdep->mips_last_arg_regnum = A0_REGNUM + 8 - 1; |
56cea623 | 6214 | tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 8 - 1; |
4014092b | 6215 | tdep->default_mask_address_p = 0; |
c2d11a7d JM |
6216 | set_gdbarch_long_bit (gdbarch, 32); |
6217 | set_gdbarch_ptr_bit (gdbarch, 32); | |
6218 | set_gdbarch_long_long_bit (gdbarch, 64); | |
2110b94f MK |
6219 | set_gdbarch_deprecated_reg_struct_has_addr |
6220 | (gdbarch, mips_eabi_reg_struct_has_addr); | |
b5622e8d | 6221 | set_gdbarch_deprecated_use_struct_convention (gdbarch, mips_eabi_use_struct_convention); |
c2d11a7d | 6222 | break; |
0dadbba0 | 6223 | case MIPS_ABI_EABI64: |
25ab4790 | 6224 | set_gdbarch_push_dummy_call (gdbarch, mips_eabi_push_dummy_call); |
6d82d43b AC |
6225 | set_gdbarch_deprecated_store_return_value (gdbarch, |
6226 | mips_eabi_store_return_value); | |
6227 | set_gdbarch_deprecated_extract_return_value (gdbarch, | |
6228 | mips_eabi_extract_return_value); | |
acdb74a0 | 6229 | tdep->mips_last_arg_regnum = A0_REGNUM + 8 - 1; |
56cea623 | 6230 | tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 8 - 1; |
4014092b | 6231 | tdep->default_mask_address_p = 0; |
c2d11a7d JM |
6232 | set_gdbarch_long_bit (gdbarch, 64); |
6233 | set_gdbarch_ptr_bit (gdbarch, 64); | |
6234 | set_gdbarch_long_long_bit (gdbarch, 64); | |
2110b94f MK |
6235 | set_gdbarch_deprecated_reg_struct_has_addr |
6236 | (gdbarch, mips_eabi_reg_struct_has_addr); | |
b5622e8d | 6237 | set_gdbarch_deprecated_use_struct_convention (gdbarch, mips_eabi_use_struct_convention); |
c2d11a7d | 6238 | break; |
0dadbba0 | 6239 | case MIPS_ABI_N32: |
25ab4790 | 6240 | set_gdbarch_push_dummy_call (gdbarch, mips_n32n64_push_dummy_call); |
29dfb2ac | 6241 | set_gdbarch_return_value (gdbarch, mips_n32n64_return_value); |
acdb74a0 | 6242 | tdep->mips_last_arg_regnum = A0_REGNUM + 8 - 1; |
56cea623 | 6243 | tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 8 - 1; |
4014092b | 6244 | tdep->default_mask_address_p = 0; |
0dadbba0 AC |
6245 | set_gdbarch_long_bit (gdbarch, 32); |
6246 | set_gdbarch_ptr_bit (gdbarch, 32); | |
6247 | set_gdbarch_long_long_bit (gdbarch, 64); | |
fed7ba43 JB |
6248 | set_gdbarch_long_double_bit (gdbarch, 128); |
6249 | set_gdbarch_long_double_format (gdbarch, | |
6250 | &floatformat_n32n64_long_double_big); | |
28d169de KB |
6251 | break; |
6252 | case MIPS_ABI_N64: | |
25ab4790 | 6253 | set_gdbarch_push_dummy_call (gdbarch, mips_n32n64_push_dummy_call); |
29dfb2ac | 6254 | set_gdbarch_return_value (gdbarch, mips_n32n64_return_value); |
28d169de | 6255 | tdep->mips_last_arg_regnum = A0_REGNUM + 8 - 1; |
56cea623 | 6256 | tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 8 - 1; |
28d169de KB |
6257 | tdep->default_mask_address_p = 0; |
6258 | set_gdbarch_long_bit (gdbarch, 64); | |
6259 | set_gdbarch_ptr_bit (gdbarch, 64); | |
6260 | set_gdbarch_long_long_bit (gdbarch, 64); | |
fed7ba43 JB |
6261 | set_gdbarch_long_double_bit (gdbarch, 128); |
6262 | set_gdbarch_long_double_format (gdbarch, | |
6263 | &floatformat_n32n64_long_double_big); | |
0dadbba0 | 6264 | break; |
c2d11a7d | 6265 | default: |
6d82d43b | 6266 | internal_error (__FILE__, __LINE__, "unknown ABI in switch"); |
c2d11a7d JM |
6267 | } |
6268 | ||
a5ea2558 AC |
6269 | /* FIXME: jlarmour/2000-04-07: There *is* a flag EF_MIPS_32BIT_MODE |
6270 | that could indicate -gp32 BUT gas/config/tc-mips.c contains the | |
6271 | comment: | |
6272 | ||
6273 | ``We deliberately don't allow "-gp32" to set the MIPS_32BITMODE | |
6274 | flag in object files because to do so would make it impossible to | |
102182a9 | 6275 | link with libraries compiled without "-gp32". This is |
a5ea2558 | 6276 | unnecessarily restrictive. |
361d1df0 | 6277 | |
a5ea2558 AC |
6278 | We could solve this problem by adding "-gp32" multilibs to gcc, |
6279 | but to set this flag before gcc is built with such multilibs will | |
6280 | break too many systems.'' | |
6281 | ||
6282 | But even more unhelpfully, the default linker output target for | |
6283 | mips64-elf is elf32-bigmips, and has EF_MIPS_32BIT_MODE set, even | |
6284 | for 64-bit programs - you need to change the ABI to change this, | |
102182a9 | 6285 | and not all gcc targets support that currently. Therefore using |
a5ea2558 AC |
6286 | this flag to detect 32-bit mode would do the wrong thing given |
6287 | the current gcc - it would make GDB treat these 64-bit programs | |
102182a9 | 6288 | as 32-bit programs by default. */ |
a5ea2558 | 6289 | |
6c997a34 | 6290 | set_gdbarch_read_pc (gdbarch, mips_read_pc); |
b6cb9035 | 6291 | set_gdbarch_write_pc (gdbarch, mips_write_pc); |
bcb0cc15 | 6292 | set_gdbarch_read_sp (gdbarch, mips_read_sp); |
c2d11a7d | 6293 | |
102182a9 MS |
6294 | /* Add/remove bits from an address. The MIPS needs be careful to |
6295 | ensure that all 32 bit addresses are sign extended to 64 bits. */ | |
875e1767 AC |
6296 | set_gdbarch_addr_bits_remove (gdbarch, mips_addr_bits_remove); |
6297 | ||
58dfe9ff AC |
6298 | /* Unwind the frame. */ |
6299 | set_gdbarch_unwind_pc (gdbarch, mips_unwind_pc); | |
edfae063 | 6300 | set_gdbarch_unwind_dummy_id (gdbarch, mips_unwind_dummy_id); |
10312cc4 | 6301 | |
102182a9 | 6302 | /* Map debug register numbers onto internal register numbers. */ |
88c72b7d | 6303 | set_gdbarch_stab_reg_to_regnum (gdbarch, mips_stab_reg_to_regnum); |
6d82d43b AC |
6304 | set_gdbarch_ecoff_reg_to_regnum (gdbarch, |
6305 | mips_dwarf_dwarf2_ecoff_reg_to_regnum); | |
6306 | set_gdbarch_dwarf_reg_to_regnum (gdbarch, | |
6307 | mips_dwarf_dwarf2_ecoff_reg_to_regnum); | |
6308 | set_gdbarch_dwarf2_reg_to_regnum (gdbarch, | |
6309 | mips_dwarf_dwarf2_ecoff_reg_to_regnum); | |
a4b8ebc8 | 6310 | set_gdbarch_register_sim_regno (gdbarch, mips_register_sim_regno); |
88c72b7d | 6311 | |
c2d11a7d JM |
6312 | /* MIPS version of CALL_DUMMY */ |
6313 | ||
9710e734 AC |
6314 | /* NOTE: cagney/2003-08-05: Eventually call dummy location will be |
6315 | replaced by a command, and all targets will default to on stack | |
6316 | (regardless of the stack's execute status). */ | |
6317 | set_gdbarch_call_dummy_location (gdbarch, AT_SYMBOL); | |
dc604539 | 6318 | set_gdbarch_frame_align (gdbarch, mips_frame_align); |
d05285fa | 6319 | |
87783b8b AC |
6320 | set_gdbarch_convert_register_p (gdbarch, mips_convert_register_p); |
6321 | set_gdbarch_register_to_value (gdbarch, mips_register_to_value); | |
6322 | set_gdbarch_value_to_register (gdbarch, mips_value_to_register); | |
6323 | ||
f7b9e9fc AC |
6324 | set_gdbarch_inner_than (gdbarch, core_addr_lessthan); |
6325 | set_gdbarch_breakpoint_from_pc (gdbarch, mips_breakpoint_from_pc); | |
f7b9e9fc AC |
6326 | |
6327 | set_gdbarch_skip_prologue (gdbarch, mips_skip_prologue); | |
f7b9e9fc | 6328 | |
fc0c74b1 AC |
6329 | set_gdbarch_pointer_to_address (gdbarch, signed_pointer_to_address); |
6330 | set_gdbarch_address_to_pointer (gdbarch, address_to_signed_pointer); | |
6331 | set_gdbarch_integer_to_address (gdbarch, mips_integer_to_address); | |
70f80edf | 6332 | |
a4b8ebc8 | 6333 | set_gdbarch_register_type (gdbarch, mips_register_type); |
78fde5f8 | 6334 | |
e11c53d2 | 6335 | set_gdbarch_print_registers_info (gdbarch, mips_print_registers_info); |
bf1f5b4c | 6336 | |
e5ab0dce AC |
6337 | set_gdbarch_print_insn (gdbarch, gdb_print_insn_mips); |
6338 | ||
3a3bc038 AC |
6339 | /* FIXME: cagney/2003-08-29: The macros HAVE_STEPPABLE_WATCHPOINT, |
6340 | HAVE_NONSTEPPABLE_WATCHPOINT, and HAVE_CONTINUABLE_WATCHPOINT | |
6341 | need to all be folded into the target vector. Since they are | |
6342 | being used as guards for STOPPED_BY_WATCHPOINT, why not have | |
6343 | STOPPED_BY_WATCHPOINT return the type of watchpoint that the code | |
6344 | is sitting on? */ | |
6345 | set_gdbarch_have_nonsteppable_watchpoint (gdbarch, 1); | |
6346 | ||
757a7cc6 MS |
6347 | set_gdbarch_skip_trampoline_code (gdbarch, mips_skip_stub); |
6348 | ||
6de918a6 DJ |
6349 | /* NOTE drow/2004-02-11: We overload the core solib trampoline code |
6350 | to support MIPS16. This is a bad thing. Make sure not to do it | |
6351 | if we have an OS ABI that actually supports shared libraries, since | |
6352 | shared library support is more important. If we have an OS someday | |
6353 | that supports both shared libraries and MIPS16, we'll have to find | |
6354 | a better place for these. */ | |
6355 | if (info.osabi == GDB_OSABI_UNKNOWN) | |
6356 | { | |
6357 | set_gdbarch_in_solib_call_trampoline (gdbarch, mips_in_call_stub); | |
6358 | set_gdbarch_in_solib_return_trampoline (gdbarch, mips_in_return_stub); | |
6359 | } | |
6360 | ||
6361 | /* Hook in OS ABI-specific overrides, if they have been registered. */ | |
6362 | gdbarch_init_osabi (info, gdbarch); | |
757a7cc6 | 6363 | |
5792a79b | 6364 | /* Unwind the frame. */ |
eec63939 | 6365 | frame_unwind_append_sniffer (gdbarch, mips_stub_frame_sniffer); |
5792a79b | 6366 | frame_unwind_append_sniffer (gdbarch, mips_mdebug_frame_sniffer); |
45c9dd44 AC |
6367 | frame_unwind_append_sniffer (gdbarch, mips_insn16_frame_sniffer); |
6368 | frame_unwind_append_sniffer (gdbarch, mips_insn32_frame_sniffer); | |
eec63939 | 6369 | frame_base_append_sniffer (gdbarch, mips_stub_frame_base_sniffer); |
5792a79b | 6370 | frame_base_append_sniffer (gdbarch, mips_mdebug_frame_base_sniffer); |
45c9dd44 AC |
6371 | frame_base_append_sniffer (gdbarch, mips_insn16_frame_base_sniffer); |
6372 | frame_base_append_sniffer (gdbarch, mips_insn32_frame_base_sniffer); | |
5792a79b | 6373 | |
4b9b3959 AC |
6374 | return gdbarch; |
6375 | } | |
6376 | ||
2e4ebe70 | 6377 | static void |
6d82d43b | 6378 | mips_abi_update (char *ignore_args, int from_tty, struct cmd_list_element *c) |
2e4ebe70 DJ |
6379 | { |
6380 | struct gdbarch_info info; | |
6381 | ||
6382 | /* Force the architecture to update, and (if it's a MIPS architecture) | |
6383 | mips_gdbarch_init will take care of the rest. */ | |
6384 | gdbarch_info_init (&info); | |
6385 | gdbarch_update_p (info); | |
6386 | } | |
6387 | ||
ad188201 KB |
6388 | /* Print out which MIPS ABI is in use. */ |
6389 | ||
6390 | static void | |
6391 | show_mips_abi (char *ignore_args, int from_tty) | |
6392 | { | |
6393 | if (gdbarch_bfd_arch_info (current_gdbarch)->arch != bfd_arch_mips) | |
6d82d43b AC |
6394 | printf_filtered |
6395 | ("The MIPS ABI is unknown because the current architecture is not MIPS.\n"); | |
ad188201 KB |
6396 | else |
6397 | { | |
6398 | enum mips_abi global_abi = global_mips_abi (); | |
6399 | enum mips_abi actual_abi = mips_abi (current_gdbarch); | |
6400 | const char *actual_abi_str = mips_abi_strings[actual_abi]; | |
6401 | ||
6402 | if (global_abi == MIPS_ABI_UNKNOWN) | |
6d82d43b AC |
6403 | printf_filtered |
6404 | ("The MIPS ABI is set automatically (currently \"%s\").\n", | |
6405 | actual_abi_str); | |
ad188201 | 6406 | else if (global_abi == actual_abi) |
6d82d43b AC |
6407 | printf_filtered |
6408 | ("The MIPS ABI is assumed to be \"%s\" (due to user setting).\n", | |
6409 | actual_abi_str); | |
ad188201 KB |
6410 | else |
6411 | { | |
6412 | /* Probably shouldn't happen... */ | |
6d82d43b AC |
6413 | printf_filtered |
6414 | ("The (auto detected) MIPS ABI \"%s\" is in use even though the user setting was \"%s\".\n", | |
6415 | actual_abi_str, mips_abi_strings[global_abi]); | |
ad188201 KB |
6416 | } |
6417 | } | |
6418 | } | |
6419 | ||
4b9b3959 AC |
6420 | static void |
6421 | mips_dump_tdep (struct gdbarch *current_gdbarch, struct ui_file *file) | |
6422 | { | |
6423 | struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); | |
6424 | if (tdep != NULL) | |
c2d11a7d | 6425 | { |
acdb74a0 AC |
6426 | int ef_mips_arch; |
6427 | int ef_mips_32bitmode; | |
6428 | /* determine the ISA */ | |
6429 | switch (tdep->elf_flags & EF_MIPS_ARCH) | |
6430 | { | |
6431 | case E_MIPS_ARCH_1: | |
6432 | ef_mips_arch = 1; | |
6433 | break; | |
6434 | case E_MIPS_ARCH_2: | |
6435 | ef_mips_arch = 2; | |
6436 | break; | |
6437 | case E_MIPS_ARCH_3: | |
6438 | ef_mips_arch = 3; | |
6439 | break; | |
6440 | case E_MIPS_ARCH_4: | |
93d56215 | 6441 | ef_mips_arch = 4; |
acdb74a0 AC |
6442 | break; |
6443 | default: | |
93d56215 | 6444 | ef_mips_arch = 0; |
acdb74a0 AC |
6445 | break; |
6446 | } | |
6447 | /* determine the size of a pointer */ | |
6448 | ef_mips_32bitmode = (tdep->elf_flags & EF_MIPS_32BITMODE); | |
4b9b3959 AC |
6449 | fprintf_unfiltered (file, |
6450 | "mips_dump_tdep: tdep->elf_flags = 0x%x\n", | |
0dadbba0 | 6451 | tdep->elf_flags); |
4b9b3959 | 6452 | fprintf_unfiltered (file, |
acdb74a0 AC |
6453 | "mips_dump_tdep: ef_mips_32bitmode = %d\n", |
6454 | ef_mips_32bitmode); | |
6455 | fprintf_unfiltered (file, | |
6456 | "mips_dump_tdep: ef_mips_arch = %d\n", | |
6457 | ef_mips_arch); | |
6458 | fprintf_unfiltered (file, | |
6459 | "mips_dump_tdep: tdep->mips_abi = %d (%s)\n", | |
6d82d43b | 6460 | tdep->mips_abi, mips_abi_strings[tdep->mips_abi]); |
4014092b AC |
6461 | fprintf_unfiltered (file, |
6462 | "mips_dump_tdep: mips_mask_address_p() %d (default %d)\n", | |
480d3dd2 | 6463 | mips_mask_address_p (tdep), |
4014092b | 6464 | tdep->default_mask_address_p); |
c2d11a7d | 6465 | } |
4b9b3959 AC |
6466 | fprintf_unfiltered (file, |
6467 | "mips_dump_tdep: MIPS_DEFAULT_FPU_TYPE = %d (%s)\n", | |
6468 | MIPS_DEFAULT_FPU_TYPE, | |
6469 | (MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_NONE ? "none" | |
6470 | : MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_SINGLE ? "single" | |
6471 | : MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_DOUBLE ? "double" | |
6472 | : "???")); | |
6d82d43b | 6473 | fprintf_unfiltered (file, "mips_dump_tdep: MIPS_EABI = %d\n", MIPS_EABI); |
4b9b3959 AC |
6474 | fprintf_unfiltered (file, |
6475 | "mips_dump_tdep: MIPS_FPU_TYPE = %d (%s)\n", | |
6476 | MIPS_FPU_TYPE, | |
6477 | (MIPS_FPU_TYPE == MIPS_FPU_NONE ? "none" | |
6478 | : MIPS_FPU_TYPE == MIPS_FPU_SINGLE ? "single" | |
6479 | : MIPS_FPU_TYPE == MIPS_FPU_DOUBLE ? "double" | |
6480 | : "???")); | |
4b9b3959 | 6481 | fprintf_unfiltered (file, |
480d3dd2 | 6482 | "mips_dump_tdep: mips_stack_argsize() = %d\n", |
13326b4e | 6483 | mips_stack_argsize (current_gdbarch)); |
6d82d43b | 6484 | fprintf_unfiltered (file, "mips_dump_tdep: A0_REGNUM = %d\n", A0_REGNUM); |
2475bac3 AC |
6485 | fprintf_unfiltered (file, |
6486 | "mips_dump_tdep: ADDR_BITS_REMOVE # %s\n", | |
6d82d43b | 6487 | XSTRING (ADDR_BITS_REMOVE (ADDR))); |
2475bac3 AC |
6488 | fprintf_unfiltered (file, |
6489 | "mips_dump_tdep: ATTACH_DETACH # %s\n", | |
6490 | XSTRING (ATTACH_DETACH)); | |
2475bac3 AC |
6491 | fprintf_unfiltered (file, |
6492 | "mips_dump_tdep: DWARF_REG_TO_REGNUM # %s\n", | |
6493 | XSTRING (DWARF_REG_TO_REGNUM (REGNUM))); | |
6494 | fprintf_unfiltered (file, | |
6495 | "mips_dump_tdep: ECOFF_REG_TO_REGNUM # %s\n", | |
6496 | XSTRING (ECOFF_REG_TO_REGNUM (REGNUM))); | |
2475bac3 AC |
6497 | fprintf_unfiltered (file, |
6498 | "mips_dump_tdep: FIRST_EMBED_REGNUM = %d\n", | |
6499 | FIRST_EMBED_REGNUM); | |
2475bac3 | 6500 | fprintf_unfiltered (file, |
a53c66de AC |
6501 | "mips_dump_tdep: DEPRECATED_IGNORE_HELPER_CALL # %s\n", |
6502 | XSTRING (DEPRECATED_IGNORE_HELPER_CALL (PC))); | |
2475bac3 AC |
6503 | fprintf_unfiltered (file, |
6504 | "mips_dump_tdep: IN_SOLIB_CALL_TRAMPOLINE # %s\n", | |
6505 | XSTRING (IN_SOLIB_CALL_TRAMPOLINE (PC, NAME))); | |
6506 | fprintf_unfiltered (file, | |
6507 | "mips_dump_tdep: IN_SOLIB_RETURN_TRAMPOLINE # %s\n", | |
6508 | XSTRING (IN_SOLIB_RETURN_TRAMPOLINE (PC, NAME))); | |
2475bac3 AC |
6509 | fprintf_unfiltered (file, |
6510 | "mips_dump_tdep: LAST_EMBED_REGNUM = %d\n", | |
6511 | LAST_EMBED_REGNUM); | |
2475bac3 AC |
6512 | #ifdef MACHINE_CPROC_FP_OFFSET |
6513 | fprintf_unfiltered (file, | |
6514 | "mips_dump_tdep: MACHINE_CPROC_FP_OFFSET = %d\n", | |
6515 | MACHINE_CPROC_FP_OFFSET); | |
6516 | #endif | |
6517 | #ifdef MACHINE_CPROC_PC_OFFSET | |
6518 | fprintf_unfiltered (file, | |
6519 | "mips_dump_tdep: MACHINE_CPROC_PC_OFFSET = %d\n", | |
6520 | MACHINE_CPROC_PC_OFFSET); | |
6521 | #endif | |
6522 | #ifdef MACHINE_CPROC_SP_OFFSET | |
6523 | fprintf_unfiltered (file, | |
6524 | "mips_dump_tdep: MACHINE_CPROC_SP_OFFSET = %d\n", | |
6525 | MACHINE_CPROC_SP_OFFSET); | |
6526 | #endif | |
2475bac3 AC |
6527 | fprintf_unfiltered (file, |
6528 | "mips_dump_tdep: MIPS16_INSTLEN = %d\n", | |
6529 | MIPS16_INSTLEN); | |
6d82d43b | 6530 | fprintf_unfiltered (file, "mips_dump_tdep: MIPS_DEFAULT_ABI = FIXME!\n"); |
2475bac3 AC |
6531 | fprintf_unfiltered (file, |
6532 | "mips_dump_tdep: MIPS_EFI_SYMBOL_NAME = multi-arch!!\n"); | |
6533 | fprintf_unfiltered (file, | |
6d82d43b | 6534 | "mips_dump_tdep: MIPS_INSTLEN = %d\n", MIPS_INSTLEN); |
2475bac3 | 6535 | fprintf_unfiltered (file, |
acdb74a0 AC |
6536 | "mips_dump_tdep: MIPS_LAST_ARG_REGNUM = %d (%d regs)\n", |
6537 | MIPS_LAST_ARG_REGNUM, | |
6538 | MIPS_LAST_ARG_REGNUM - A0_REGNUM + 1); | |
2475bac3 | 6539 | fprintf_unfiltered (file, |
6d82d43b | 6540 | "mips_dump_tdep: MIPS_NUMREGS = %d\n", MIPS_NUMREGS); |
2475bac3 | 6541 | fprintf_unfiltered (file, |
1b13c4f6 | 6542 | "mips_dump_tdep: mips_abi_regsize() = %d\n", |
13326b4e | 6543 | mips_abi_regsize (current_gdbarch)); |
2475bac3 | 6544 | fprintf_unfiltered (file, |
6d82d43b | 6545 | "mips_dump_tdep: PRID_REGNUM = %d\n", PRID_REGNUM); |
2475bac3 AC |
6546 | fprintf_unfiltered (file, |
6547 | "mips_dump_tdep: PROC_FRAME_ADJUST = function?\n"); | |
6548 | fprintf_unfiltered (file, | |
6549 | "mips_dump_tdep: PROC_FRAME_OFFSET = function?\n"); | |
6d82d43b AC |
6550 | fprintf_unfiltered (file, "mips_dump_tdep: PROC_FRAME_REG = function?\n"); |
6551 | fprintf_unfiltered (file, "mips_dump_tdep: PROC_FREG_MASK = function?\n"); | |
6552 | fprintf_unfiltered (file, "mips_dump_tdep: PROC_FREG_OFFSET = function?\n"); | |
6553 | fprintf_unfiltered (file, "mips_dump_tdep: PROC_HIGH_ADDR = function?\n"); | |
6554 | fprintf_unfiltered (file, "mips_dump_tdep: PROC_LOW_ADDR = function?\n"); | |
6555 | fprintf_unfiltered (file, "mips_dump_tdep: PROC_PC_REG = function?\n"); | |
6556 | fprintf_unfiltered (file, "mips_dump_tdep: PROC_REG_MASK = function?\n"); | |
6557 | fprintf_unfiltered (file, "mips_dump_tdep: PROC_REG_OFFSET = function?\n"); | |
6558 | fprintf_unfiltered (file, "mips_dump_tdep: PROC_SYMBOL = function?\n"); | |
6559 | fprintf_unfiltered (file, "mips_dump_tdep: PS_REGNUM = %d\n", PS_REGNUM); | |
6560 | fprintf_unfiltered (file, "mips_dump_tdep: RA_REGNUM = %d\n", RA_REGNUM); | |
2475bac3 AC |
6561 | #ifdef SAVED_BYTES |
6562 | fprintf_unfiltered (file, | |
6d82d43b | 6563 | "mips_dump_tdep: SAVED_BYTES = %d\n", SAVED_BYTES); |
2475bac3 AC |
6564 | #endif |
6565 | #ifdef SAVED_FP | |
6d82d43b | 6566 | fprintf_unfiltered (file, "mips_dump_tdep: SAVED_FP = %d\n", SAVED_FP); |
2475bac3 AC |
6567 | #endif |
6568 | #ifdef SAVED_PC | |
6d82d43b | 6569 | fprintf_unfiltered (file, "mips_dump_tdep: SAVED_PC = %d\n", SAVED_PC); |
2475bac3 AC |
6570 | #endif |
6571 | fprintf_unfiltered (file, | |
6572 | "mips_dump_tdep: SETUP_ARBITRARY_FRAME # %s\n", | |
6573 | XSTRING (SETUP_ARBITRARY_FRAME (NUMARGS, ARGS))); | |
2475bac3 AC |
6574 | fprintf_unfiltered (file, |
6575 | "mips_dump_tdep: SKIP_TRAMPOLINE_CODE # %s\n", | |
6576 | XSTRING (SKIP_TRAMPOLINE_CODE (PC))); | |
6577 | fprintf_unfiltered (file, | |
6578 | "mips_dump_tdep: SOFTWARE_SINGLE_STEP # %s\n", | |
6579 | XSTRING (SOFTWARE_SINGLE_STEP (SIG, BP_P))); | |
6580 | fprintf_unfiltered (file, | |
b0ed3589 AC |
6581 | "mips_dump_tdep: SOFTWARE_SINGLE_STEP_P () = %d\n", |
6582 | SOFTWARE_SINGLE_STEP_P ()); | |
2475bac3 AC |
6583 | fprintf_unfiltered (file, |
6584 | "mips_dump_tdep: STAB_REG_TO_REGNUM # %s\n", | |
6585 | XSTRING (STAB_REG_TO_REGNUM (REGNUM))); | |
6586 | #ifdef STACK_END_ADDR | |
6587 | fprintf_unfiltered (file, | |
6588 | "mips_dump_tdep: STACK_END_ADDR = %d\n", | |
6589 | STACK_END_ADDR); | |
6590 | #endif | |
6591 | fprintf_unfiltered (file, | |
6592 | "mips_dump_tdep: STEP_SKIPS_DELAY # %s\n", | |
6593 | XSTRING (STEP_SKIPS_DELAY (PC))); | |
6594 | fprintf_unfiltered (file, | |
6595 | "mips_dump_tdep: STEP_SKIPS_DELAY_P = %d\n", | |
6596 | STEP_SKIPS_DELAY_P); | |
6597 | fprintf_unfiltered (file, | |
6598 | "mips_dump_tdep: STOPPED_BY_WATCHPOINT # %s\n", | |
6599 | XSTRING (STOPPED_BY_WATCHPOINT (WS))); | |
6d82d43b | 6600 | fprintf_unfiltered (file, "mips_dump_tdep: T9_REGNUM = %d\n", T9_REGNUM); |
2475bac3 AC |
6601 | fprintf_unfiltered (file, |
6602 | "mips_dump_tdep: TABULAR_REGISTER_OUTPUT = used?\n"); | |
6603 | fprintf_unfiltered (file, | |
6604 | "mips_dump_tdep: TARGET_CAN_USE_HARDWARE_WATCHPOINT # %s\n", | |
6d82d43b AC |
6605 | XSTRING (TARGET_CAN_USE_HARDWARE_WATCHPOINT |
6606 | (TYPE, CNT, OTHERTYPE))); | |
2475bac3 AC |
6607 | fprintf_unfiltered (file, |
6608 | "mips_dump_tdep: TARGET_HAS_HARDWARE_WATCHPOINTS # %s\n", | |
6609 | XSTRING (TARGET_HAS_HARDWARE_WATCHPOINTS)); | |
2475bac3 AC |
6610 | #ifdef TRACE_CLEAR |
6611 | fprintf_unfiltered (file, | |
6612 | "mips_dump_tdep: TRACE_CLEAR # %s\n", | |
6613 | XSTRING (TRACE_CLEAR (THREAD, STATE))); | |
6614 | #endif | |
6615 | #ifdef TRACE_FLAVOR | |
6616 | fprintf_unfiltered (file, | |
6d82d43b | 6617 | "mips_dump_tdep: TRACE_FLAVOR = %d\n", TRACE_FLAVOR); |
2475bac3 AC |
6618 | #endif |
6619 | #ifdef TRACE_FLAVOR_SIZE | |
6620 | fprintf_unfiltered (file, | |
6621 | "mips_dump_tdep: TRACE_FLAVOR_SIZE = %d\n", | |
6622 | TRACE_FLAVOR_SIZE); | |
6623 | #endif | |
6624 | #ifdef TRACE_SET | |
6625 | fprintf_unfiltered (file, | |
6626 | "mips_dump_tdep: TRACE_SET # %s\n", | |
6d82d43b | 6627 | XSTRING (TRACE_SET (X, STATE))); |
2475bac3 | 6628 | #endif |
2475bac3 AC |
6629 | #ifdef UNUSED_REGNUM |
6630 | fprintf_unfiltered (file, | |
6d82d43b | 6631 | "mips_dump_tdep: UNUSED_REGNUM = %d\n", UNUSED_REGNUM); |
2475bac3 | 6632 | #endif |
6d82d43b | 6633 | fprintf_unfiltered (file, "mips_dump_tdep: V0_REGNUM = %d\n", V0_REGNUM); |
2475bac3 AC |
6634 | fprintf_unfiltered (file, |
6635 | "mips_dump_tdep: VM_MIN_ADDRESS = %ld\n", | |
6636 | (long) VM_MIN_ADDRESS); | |
2475bac3 | 6637 | fprintf_unfiltered (file, |
6d82d43b | 6638 | "mips_dump_tdep: ZERO_REGNUM = %d\n", ZERO_REGNUM); |
c2d11a7d JM |
6639 | } |
6640 | ||
6d82d43b | 6641 | extern initialize_file_ftype _initialize_mips_tdep; /* -Wmissing-prototypes */ |
a78f21af | 6642 | |
c906108c | 6643 | void |
acdb74a0 | 6644 | _initialize_mips_tdep (void) |
c906108c SS |
6645 | { |
6646 | static struct cmd_list_element *mipsfpulist = NULL; | |
6647 | struct cmd_list_element *c; | |
6648 | ||
6d82d43b | 6649 | mips_abi_string = mips_abi_strings[MIPS_ABI_UNKNOWN]; |
2e4ebe70 DJ |
6650 | if (MIPS_ABI_LAST + 1 |
6651 | != sizeof (mips_abi_strings) / sizeof (mips_abi_strings[0])) | |
6652 | internal_error (__FILE__, __LINE__, "mips_abi_strings out of sync"); | |
6653 | ||
4b9b3959 | 6654 | gdbarch_register (bfd_arch_mips, mips_gdbarch_init, mips_dump_tdep); |
c906108c | 6655 | |
8d5f9dcb DJ |
6656 | mips_pdr_data = register_objfile_data (); |
6657 | ||
a5ea2558 AC |
6658 | /* Add root prefix command for all "set mips"/"show mips" commands */ |
6659 | add_prefix_cmd ("mips", no_class, set_mips_command, | |
6660 | "Various MIPS specific commands.", | |
6661 | &setmipscmdlist, "set mips ", 0, &setlist); | |
6662 | ||
6663 | add_prefix_cmd ("mips", no_class, show_mips_command, | |
6664 | "Various MIPS specific commands.", | |
6665 | &showmipscmdlist, "show mips ", 0, &showlist); | |
6666 | ||
6667 | /* Allow the user to override the saved register size. */ | |
cb1a6d5f AC |
6668 | deprecated_add_show_from_set (add_set_enum_cmd ("saved-gpreg-size", |
6669 | class_obscure, | |
6670 | size_enums, | |
6671 | &mips_abi_regsize_string, "\ | |
a5ea2558 AC |
6672 | Set size of general purpose registers saved on the stack.\n\ |
6673 | This option can be set to one of:\n\ | |
6674 | 32 - Force GDB to treat saved GP registers as 32-bit\n\ | |
6675 | 64 - Force GDB to treat saved GP registers as 64-bit\n\ | |
6676 | auto - Allow GDB to use the target's default setting or autodetect the\n\ | |
6677 | saved GP register size from information contained in the executable.\n\ | |
6d82d43b | 6678 | (default: auto)", &setmipscmdlist), &showmipscmdlist); |
a5ea2558 | 6679 | |
d929b26f | 6680 | /* Allow the user to override the argument stack size. */ |
cb1a6d5f AC |
6681 | deprecated_add_show_from_set |
6682 | (add_set_enum_cmd ("stack-arg-size", | |
6683 | class_obscure, | |
6684 | size_enums, | |
6685 | &mips_stack_argsize_string, "\ | |
d929b26f AC |
6686 | Set the amount of stack space reserved for each argument.\n\ |
6687 | This option can be set to one of:\n\ | |
6688 | 32 - Force GDB to allocate 32-bit chunks per argument\n\ | |
6689 | 64 - Force GDB to allocate 64-bit chunks per argument\n\ | |
6690 | auto - Allow GDB to determine the correct setting from the current\n\ | |
cb1a6d5f AC |
6691 | target and executable (default)", &setmipscmdlist), |
6692 | &showmipscmdlist); | |
d929b26f | 6693 | |
2e4ebe70 DJ |
6694 | /* Allow the user to override the ABI. */ |
6695 | c = add_set_enum_cmd | |
6696 | ("abi", class_obscure, mips_abi_strings, &mips_abi_string, | |
6697 | "Set the ABI used by this program.\n" | |
6698 | "This option can be set to one of:\n" | |
6699 | " auto - the default ABI associated with the current binary\n" | |
6700 | " o32\n" | |
6d82d43b | 6701 | " o64\n" " n32\n" " n64\n" " eabi32\n" " eabi64", &setmipscmdlist); |
2e4ebe70 | 6702 | set_cmd_sfunc (c, mips_abi_update); |
ad188201 | 6703 | add_cmd ("abi", class_obscure, show_mips_abi, |
6d82d43b | 6704 | "Show ABI in use by MIPS target", &showmipscmdlist); |
2e4ebe70 | 6705 | |
c906108c SS |
6706 | /* Let the user turn off floating point and set the fence post for |
6707 | heuristic_proc_start. */ | |
6708 | ||
6709 | add_prefix_cmd ("mipsfpu", class_support, set_mipsfpu_command, | |
6710 | "Set use of MIPS floating-point coprocessor.", | |
6711 | &mipsfpulist, "set mipsfpu ", 0, &setlist); | |
6712 | add_cmd ("single", class_support, set_mipsfpu_single_command, | |
6713 | "Select single-precision MIPS floating-point coprocessor.", | |
6714 | &mipsfpulist); | |
6715 | add_cmd ("double", class_support, set_mipsfpu_double_command, | |
8e1a459b | 6716 | "Select double-precision MIPS floating-point coprocessor.", |
c906108c SS |
6717 | &mipsfpulist); |
6718 | add_alias_cmd ("on", "double", class_support, 1, &mipsfpulist); | |
6719 | add_alias_cmd ("yes", "double", class_support, 1, &mipsfpulist); | |
6720 | add_alias_cmd ("1", "double", class_support, 1, &mipsfpulist); | |
6721 | add_cmd ("none", class_support, set_mipsfpu_none_command, | |
6d82d43b | 6722 | "Select no MIPS floating-point coprocessor.", &mipsfpulist); |
c906108c SS |
6723 | add_alias_cmd ("off", "none", class_support, 1, &mipsfpulist); |
6724 | add_alias_cmd ("no", "none", class_support, 1, &mipsfpulist); | |
6725 | add_alias_cmd ("0", "none", class_support, 1, &mipsfpulist); | |
6726 | add_cmd ("auto", class_support, set_mipsfpu_auto_command, | |
6727 | "Select MIPS floating-point coprocessor automatically.", | |
6728 | &mipsfpulist); | |
6729 | add_cmd ("mipsfpu", class_support, show_mipsfpu_command, | |
6730 | "Show current use of MIPS floating-point coprocessor target.", | |
6731 | &showlist); | |
6732 | ||
c906108c SS |
6733 | /* We really would like to have both "0" and "unlimited" work, but |
6734 | command.c doesn't deal with that. So make it a var_zinteger | |
6735 | because the user can always use "999999" or some such for unlimited. */ | |
6736 | c = add_set_cmd ("heuristic-fence-post", class_support, var_zinteger, | |
6d82d43b | 6737 | (char *) &heuristic_fence_post, "\ |
c906108c SS |
6738 | Set the distance searched for the start of a function.\n\ |
6739 | If you are debugging a stripped executable, GDB needs to search through the\n\ | |
6740 | program for the start of a function. This command sets the distance of the\n\ | |
6d82d43b | 6741 | search. The only need to set it is when debugging a stripped executable.", &setlist); |
c906108c SS |
6742 | /* We need to throw away the frame cache when we set this, since it |
6743 | might change our ability to get backtraces. */ | |
9f60d481 | 6744 | set_cmd_sfunc (c, reinit_frame_cache_sfunc); |
cb1a6d5f | 6745 | deprecated_add_show_from_set (c, &showlist); |
c906108c SS |
6746 | |
6747 | /* Allow the user to control whether the upper bits of 64-bit | |
6748 | addresses should be zeroed. */ | |
e9e68a56 | 6749 | add_setshow_auto_boolean_cmd ("mask-address", no_class, &mask_address_var, "\ |
3b64bf98 AC |
6750 | Set zeroing of upper 32 bits of 64-bit addresses.", "\ |
6751 | Show zeroing of upper 32 bits of 64-bit addresses.", "\ | |
e9e68a56 AC |
6752 | Use \"on\" to enable the masking, \"off\" to disable it and \"auto\" to \n\ |
6753 | allow GDB to determine the correct value.\n", "\ | |
3b64bf98 | 6754 | Zerroing of upper 32 bits of 64-bit address is %s.", |
6d82d43b | 6755 | NULL, show_mask_address, &setmipscmdlist, &showmipscmdlist); |
43e526b9 JM |
6756 | |
6757 | /* Allow the user to control the size of 32 bit registers within the | |
6758 | raw remote packet. */ | |
b3f42336 AC |
6759 | add_setshow_boolean_cmd ("remote-mips64-transfers-32bit-regs", class_obscure, |
6760 | &mips64_transfers_32bit_regs_p, "\ | |
3b64bf98 AC |
6761 | Set compatibility with 64-bit MIPS target that transfers 32-bit quantities.", "\ |
6762 | Show compatibility with 64-bit MIPS target that transfers 32-bit quantities.", "\ | |
719ec221 AC |
6763 | Use \"on\" to enable backward compatibility with older MIPS 64 GDB+target\n\ |
6764 | that would transfer 32 bits for some registers (e.g. SR, FSR) and\n\ | |
6d82d43b | 6765 | 64 bits for others. Use \"off\" to disable compatibility mode", "\ |
3b64bf98 AC |
6766 | Compatibility with 64-bit MIPS target that transfers 32-bit quantities is %s.", |
6767 | set_mips64_transfers_32bit_regs, NULL, &setlist, &showlist); | |
9ace0497 AC |
6768 | |
6769 | /* Debug this files internals. */ | |
cb1a6d5f AC |
6770 | deprecated_add_show_from_set |
6771 | (add_set_cmd ("mips", class_maintenance, var_zinteger, | |
6772 | &mips_debug, "Set mips debugging.\n\ | |
6773 | When non-zero, mips specific debugging is enabled.", &setdebuglist), | |
6774 | &showdebuglist); | |
c906108c | 6775 | } |