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