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