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