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