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