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