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