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