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