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