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