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