]>
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([email protected]) at CMU |
8 | and by Per Bothner([email protected]) 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" |
edfae063 AC |
53 | #include "frame-unwind.h" |
54 | #include "frame-base.h" | |
55 | #include "trad-frame.h" | |
7d9b040b | 56 | #include "infcall.h" |
fed7ba43 | 57 | #include "floatformat.h" |
c906108c | 58 | |
8d5f9dcb DJ |
59 | static const struct objfile_data *mips_pdr_data; |
60 | ||
5bbcb741 | 61 | static struct type *mips_register_type (struct gdbarch *gdbarch, int regnum); |
e0f7ec59 | 62 | |
24e05951 | 63 | /* A useful bit in the CP0 status register (MIPS_PS_REGNUM). */ |
dd824b04 DJ |
64 | /* This bit is set if we are emulating 32-bit FPRs on a 64-bit chip. */ |
65 | #define ST0_FR (1 << 26) | |
66 | ||
b0069a17 AC |
67 | /* The sizes of floating point registers. */ |
68 | ||
69 | enum | |
70 | { | |
71 | MIPS_FPU_SINGLE_REGSIZE = 4, | |
72 | MIPS_FPU_DOUBLE_REGSIZE = 8 | |
73 | }; | |
74 | ||
0dadbba0 | 75 | |
2e4ebe70 DJ |
76 | static const char *mips_abi_string; |
77 | ||
78 | static const char *mips_abi_strings[] = { | |
79 | "auto", | |
80 | "n32", | |
81 | "o32", | |
28d169de | 82 | "n64", |
2e4ebe70 DJ |
83 | "o64", |
84 | "eabi32", | |
85 | "eabi64", | |
86 | NULL | |
87 | }; | |
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 | 104 | /* Some MIPS boards don't support floating point while others only |
ceae6e75 | 105 | support single-precision floating-point operations. */ |
c906108c SS |
106 | |
107 | enum mips_fpu_type | |
6d82d43b AC |
108 | { |
109 | MIPS_FPU_DOUBLE, /* Full double precision floating point. */ | |
110 | MIPS_FPU_SINGLE, /* Single precision floating point (R4650). */ | |
111 | MIPS_FPU_NONE /* No floating point. */ | |
112 | }; | |
c906108c SS |
113 | |
114 | #ifndef MIPS_DEFAULT_FPU_TYPE | |
115 | #define MIPS_DEFAULT_FPU_TYPE MIPS_FPU_DOUBLE | |
116 | #endif | |
117 | static int mips_fpu_type_auto = 1; | |
118 | static enum mips_fpu_type mips_fpu_type = MIPS_DEFAULT_FPU_TYPE; | |
7a292a7a | 119 | |
9ace0497 | 120 | static int mips_debug = 0; |
7a292a7a | 121 | |
c2d11a7d JM |
122 | /* MIPS specific per-architecture information */ |
123 | struct gdbarch_tdep | |
6d82d43b AC |
124 | { |
125 | /* from the elf header */ | |
126 | int elf_flags; | |
127 | ||
128 | /* mips options */ | |
129 | enum mips_abi mips_abi; | |
130 | enum mips_abi found_abi; | |
131 | enum mips_fpu_type mips_fpu_type; | |
132 | int mips_last_arg_regnum; | |
133 | int mips_last_fp_arg_regnum; | |
6d82d43b AC |
134 | int default_mask_address_p; |
135 | /* Is the target using 64-bit raw integer registers but only | |
136 | storing a left-aligned 32-bit value in each? */ | |
137 | int mips64_transfers_32bit_regs_p; | |
138 | /* Indexes for various registers. IRIX and embedded have | |
139 | different values. This contains the "public" fields. Don't | |
140 | add any that do not need to be public. */ | |
141 | const struct mips_regnum *regnum; | |
142 | /* Register names table for the current register set. */ | |
143 | const char **mips_processor_reg_names; | |
144 | }; | |
c2d11a7d | 145 | |
fed7ba43 JB |
146 | static int |
147 | n32n64_floatformat_always_valid (const struct floatformat *fmt, | |
148 | const char *from) | |
149 | { | |
150 | return 1; | |
151 | } | |
152 | ||
153 | /* FIXME: brobecker/2004-08-08: Long Double values are 128 bit long. | |
154 | They are implemented as a pair of 64bit doubles where the high | |
155 | part holds the result of the operation rounded to double, and | |
156 | the low double holds the difference between the exact result and | |
157 | the rounded result. So "high" + "low" contains the result with | |
158 | added precision. Unfortunately, the floatformat structure used | |
159 | by GDB is not powerful enough to describe this format. As a temporary | |
160 | measure, we define a 128bit floatformat that only uses the high part. | |
161 | We lose a bit of precision but that's probably the best we can do | |
162 | for now with the current infrastructure. */ | |
163 | ||
164 | static const struct floatformat floatformat_n32n64_long_double_big = | |
165 | { | |
166 | floatformat_big, 128, 0, 1, 11, 1023, 2047, 12, 52, | |
167 | floatformat_intbit_no, | |
168 | "floatformat_ieee_double_big", | |
169 | n32n64_floatformat_always_valid | |
170 | }; | |
171 | ||
56cea623 AC |
172 | const struct mips_regnum * |
173 | mips_regnum (struct gdbarch *gdbarch) | |
174 | { | |
175 | return gdbarch_tdep (gdbarch)->regnum; | |
176 | } | |
177 | ||
178 | static int | |
179 | mips_fpa0_regnum (struct gdbarch *gdbarch) | |
180 | { | |
181 | return mips_regnum (gdbarch)->fp0 + 12; | |
182 | } | |
183 | ||
0dadbba0 | 184 | #define MIPS_EABI (gdbarch_tdep (current_gdbarch)->mips_abi == MIPS_ABI_EABI32 \ |
216a600b | 185 | || gdbarch_tdep (current_gdbarch)->mips_abi == MIPS_ABI_EABI64) |
c2d11a7d | 186 | |
c2d11a7d | 187 | #define MIPS_LAST_FP_ARG_REGNUM (gdbarch_tdep (current_gdbarch)->mips_last_fp_arg_regnum) |
c2d11a7d | 188 | |
c2d11a7d | 189 | #define MIPS_LAST_ARG_REGNUM (gdbarch_tdep (current_gdbarch)->mips_last_arg_regnum) |
c2d11a7d | 190 | |
c2d11a7d | 191 | #define MIPS_FPU_TYPE (gdbarch_tdep (current_gdbarch)->mips_fpu_type) |
c2d11a7d | 192 | |
95404a3e AC |
193 | /* MIPS16 function addresses are odd (bit 0 is set). Here are some |
194 | functions to test, set, or clear bit 0 of addresses. */ | |
195 | ||
196 | static CORE_ADDR | |
197 | is_mips16_addr (CORE_ADDR addr) | |
198 | { | |
199 | return ((addr) & 1); | |
200 | } | |
201 | ||
95404a3e AC |
202 | static CORE_ADDR |
203 | unmake_mips16_addr (CORE_ADDR addr) | |
204 | { | |
205 | return ((addr) & ~1); | |
206 | } | |
207 | ||
22540ece AC |
208 | /* Return the contents of register REGNUM as a signed integer. */ |
209 | ||
210 | static LONGEST | |
211 | read_signed_register (int regnum) | |
212 | { | |
1d93fe1a AC |
213 | LONGEST val; |
214 | regcache_cooked_read_signed (current_regcache, regnum, &val); | |
215 | return val; | |
22540ece AC |
216 | } |
217 | ||
218 | static LONGEST | |
219 | read_signed_register_pid (int regnum, ptid_t ptid) | |
220 | { | |
221 | ptid_t save_ptid; | |
222 | LONGEST retval; | |
223 | ||
224 | if (ptid_equal (ptid, inferior_ptid)) | |
225 | return read_signed_register (regnum); | |
226 | ||
227 | save_ptid = inferior_ptid; | |
228 | ||
229 | inferior_ptid = ptid; | |
230 | ||
231 | retval = read_signed_register (regnum); | |
232 | ||
233 | inferior_ptid = save_ptid; | |
234 | ||
235 | return retval; | |
236 | } | |
237 | ||
d1973055 KB |
238 | /* Return the MIPS ABI associated with GDBARCH. */ |
239 | enum mips_abi | |
240 | mips_abi (struct gdbarch *gdbarch) | |
241 | { | |
242 | return gdbarch_tdep (gdbarch)->mips_abi; | |
243 | } | |
244 | ||
4246e332 | 245 | int |
1b13c4f6 | 246 | mips_isa_regsize (struct gdbarch *gdbarch) |
4246e332 AC |
247 | { |
248 | return (gdbarch_bfd_arch_info (gdbarch)->bits_per_word | |
249 | / gdbarch_bfd_arch_info (gdbarch)->bits_per_byte); | |
250 | } | |
251 | ||
480d3dd2 AC |
252 | /* Return the currently configured (or set) saved register size. */ |
253 | ||
1b13c4f6 | 254 | static const char *mips_abi_regsize_string = size_auto; |
480d3dd2 | 255 | |
e6bc2e8a | 256 | unsigned int |
13326b4e | 257 | mips_abi_regsize (struct gdbarch *gdbarch) |
d929b26f | 258 | { |
1b13c4f6 | 259 | if (mips_abi_regsize_string == size_auto) |
13326b4e AC |
260 | switch (mips_abi (gdbarch)) |
261 | { | |
262 | case MIPS_ABI_EABI32: | |
263 | case MIPS_ABI_O32: | |
264 | return 4; | |
265 | case MIPS_ABI_N32: | |
266 | case MIPS_ABI_N64: | |
267 | case MIPS_ABI_O64: | |
268 | case MIPS_ABI_EABI64: | |
269 | return 8; | |
270 | case MIPS_ABI_UNKNOWN: | |
271 | case MIPS_ABI_LAST: | |
272 | default: | |
273 | internal_error (__FILE__, __LINE__, "bad switch"); | |
274 | } | |
1b13c4f6 | 275 | else if (mips_abi_regsize_string == size_64) |
d929b26f | 276 | return 8; |
1b13c4f6 | 277 | else /* if (mips_abi_regsize_string == size_32) */ |
d929b26f AC |
278 | return 4; |
279 | } | |
280 | ||
71b8ef93 | 281 | /* Functions for setting and testing a bit in a minimal symbol that |
5a89d8aa | 282 | marks it as 16-bit function. The MSB of the minimal symbol's |
f594e5e9 | 283 | "info" field is used for this purpose. |
5a89d8aa MS |
284 | |
285 | ELF_MAKE_MSYMBOL_SPECIAL tests whether an ELF symbol is "special", | |
286 | i.e. refers to a 16-bit function, and sets a "special" bit in a | |
287 | minimal symbol to mark it as a 16-bit function | |
288 | ||
f594e5e9 | 289 | MSYMBOL_IS_SPECIAL tests the "special" bit in a minimal symbol */ |
5a89d8aa | 290 | |
5a89d8aa | 291 | static void |
6d82d43b AC |
292 | mips_elf_make_msymbol_special (asymbol * sym, struct minimal_symbol *msym) |
293 | { | |
294 | if (((elf_symbol_type *) (sym))->internal_elf_sym.st_other == STO_MIPS16) | |
295 | { | |
296 | MSYMBOL_INFO (msym) = (char *) | |
297 | (((long) MSYMBOL_INFO (msym)) | 0x80000000); | |
298 | SYMBOL_VALUE_ADDRESS (msym) |= 1; | |
299 | } | |
5a89d8aa MS |
300 | } |
301 | ||
71b8ef93 MS |
302 | static int |
303 | msymbol_is_special (struct minimal_symbol *msym) | |
304 | { | |
305 | return (((long) MSYMBOL_INFO (msym) & 0x80000000) != 0); | |
306 | } | |
307 | ||
88658117 AC |
308 | /* XFER a value from the big/little/left end of the register. |
309 | Depending on the size of the value it might occupy the entire | |
310 | register or just part of it. Make an allowance for this, aligning | |
311 | things accordingly. */ | |
312 | ||
313 | static void | |
314 | mips_xfer_register (struct regcache *regcache, int reg_num, int length, | |
6d82d43b AC |
315 | enum bfd_endian endian, bfd_byte * in, |
316 | const bfd_byte * out, int buf_offset) | |
88658117 | 317 | { |
88658117 | 318 | int reg_offset = 0; |
a4b8ebc8 | 319 | gdb_assert (reg_num >= NUM_REGS); |
cb1d2653 AC |
320 | /* Need to transfer the left or right part of the register, based on |
321 | the targets byte order. */ | |
88658117 AC |
322 | switch (endian) |
323 | { | |
324 | case BFD_ENDIAN_BIG: | |
719ec221 | 325 | reg_offset = register_size (current_gdbarch, reg_num) - length; |
88658117 AC |
326 | break; |
327 | case BFD_ENDIAN_LITTLE: | |
328 | reg_offset = 0; | |
329 | break; | |
6d82d43b | 330 | case BFD_ENDIAN_UNKNOWN: /* Indicates no alignment. */ |
88658117 AC |
331 | reg_offset = 0; |
332 | break; | |
333 | default: | |
334 | internal_error (__FILE__, __LINE__, "bad switch"); | |
335 | } | |
336 | if (mips_debug) | |
cb1d2653 AC |
337 | fprintf_unfiltered (gdb_stderr, |
338 | "xfer $%d, reg offset %d, buf offset %d, length %d, ", | |
339 | reg_num, reg_offset, buf_offset, length); | |
88658117 AC |
340 | if (mips_debug && out != NULL) |
341 | { | |
342 | int i; | |
cb1d2653 | 343 | fprintf_unfiltered (gdb_stdlog, "out "); |
88658117 | 344 | for (i = 0; i < length; i++) |
cb1d2653 | 345 | fprintf_unfiltered (gdb_stdlog, "%02x", out[buf_offset + i]); |
88658117 AC |
346 | } |
347 | if (in != NULL) | |
6d82d43b AC |
348 | regcache_cooked_read_part (regcache, reg_num, reg_offset, length, |
349 | in + buf_offset); | |
88658117 | 350 | if (out != NULL) |
6d82d43b AC |
351 | regcache_cooked_write_part (regcache, reg_num, reg_offset, length, |
352 | out + buf_offset); | |
88658117 AC |
353 | if (mips_debug && in != NULL) |
354 | { | |
355 | int i; | |
cb1d2653 | 356 | fprintf_unfiltered (gdb_stdlog, "in "); |
88658117 | 357 | for (i = 0; i < length; i++) |
cb1d2653 | 358 | fprintf_unfiltered (gdb_stdlog, "%02x", in[buf_offset + i]); |
88658117 AC |
359 | } |
360 | if (mips_debug) | |
361 | fprintf_unfiltered (gdb_stdlog, "\n"); | |
362 | } | |
363 | ||
dd824b04 DJ |
364 | /* Determine if a MIPS3 or later cpu is operating in MIPS{1,2} FPU |
365 | compatiblity mode. A return value of 1 means that we have | |
366 | physical 64-bit registers, but should treat them as 32-bit registers. */ | |
367 | ||
368 | static int | |
369 | mips2_fp_compat (void) | |
370 | { | |
371 | /* MIPS1 and MIPS2 have only 32 bit FPRs, and the FR bit is not | |
372 | meaningful. */ | |
6d82d43b AC |
373 | if (register_size (current_gdbarch, mips_regnum (current_gdbarch)->fp0) == |
374 | 4) | |
dd824b04 DJ |
375 | return 0; |
376 | ||
377 | #if 0 | |
378 | /* FIXME drow 2002-03-10: This is disabled until we can do it consistently, | |
379 | in all the places we deal with FP registers. PR gdb/413. */ | |
380 | /* Otherwise check the FR bit in the status register - it controls | |
381 | the FP compatiblity mode. If it is clear we are in compatibility | |
382 | mode. */ | |
24e05951 | 383 | if ((read_register (MIPS_PS_REGNUM) & ST0_FR) == 0) |
dd824b04 DJ |
384 | return 1; |
385 | #endif | |
361d1df0 | 386 | |
dd824b04 DJ |
387 | return 0; |
388 | } | |
389 | ||
d929b26f | 390 | /* The amount of space reserved on the stack for registers. This is |
1b13c4f6 | 391 | different to MIPS_ABI_REGSIZE as it determines the alignment of |
d929b26f AC |
392 | data allocated after the registers have run out. */ |
393 | ||
53904c9e | 394 | static const char *mips_stack_argsize_string = size_auto; |
d929b26f AC |
395 | |
396 | static unsigned int | |
13326b4e | 397 | mips_stack_argsize (struct gdbarch *gdbarch) |
d929b26f AC |
398 | { |
399 | if (mips_stack_argsize_string == size_auto) | |
13326b4e | 400 | return mips_abi_regsize (gdbarch); |
d929b26f AC |
401 | else if (mips_stack_argsize_string == size_64) |
402 | return 8; | |
6d82d43b | 403 | else /* if (mips_stack_argsize_string == size_32) */ |
d929b26f AC |
404 | return 4; |
405 | } | |
406 | ||
7a292a7a | 407 | #define VM_MIN_ADDRESS (CORE_ADDR)0x400000 |
c906108c | 408 | |
a14ed312 | 409 | static CORE_ADDR heuristic_proc_start (CORE_ADDR); |
c906108c | 410 | |
a14ed312 | 411 | static CORE_ADDR read_next_frame_reg (struct frame_info *, int); |
c906108c | 412 | |
a14ed312 | 413 | static void reinit_frame_cache_sfunc (char *, int, struct cmd_list_element *); |
c906108c | 414 | |
67b2c998 DJ |
415 | static struct type *mips_float_register_type (void); |
416 | static struct type *mips_double_register_type (void); | |
417 | ||
acdb74a0 AC |
418 | /* The list of available "set mips " and "show mips " commands */ |
419 | ||
420 | static struct cmd_list_element *setmipscmdlist = NULL; | |
421 | static struct cmd_list_element *showmipscmdlist = NULL; | |
422 | ||
5e2e9765 KB |
423 | /* Integer registers 0 thru 31 are handled explicitly by |
424 | mips_register_name(). Processor specific registers 32 and above | |
691c0433 AC |
425 | are listed in the followign tables. */ |
426 | ||
6d82d43b AC |
427 | enum |
428 | { NUM_MIPS_PROCESSOR_REGS = (90 - 32) }; | |
691c0433 AC |
429 | |
430 | /* Generic MIPS. */ | |
431 | ||
432 | static const char *mips_generic_reg_names[NUM_MIPS_PROCESSOR_REGS] = { | |
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 | "", "", "", "", "", "", "", "", | |
440 | "", "", "", "", "", "", "", "", | |
691c0433 AC |
441 | }; |
442 | ||
443 | /* Names of IDT R3041 registers. */ | |
444 | ||
445 | static const char *mips_r3041_reg_names[] = { | |
6d82d43b AC |
446 | "sr", "lo", "hi", "bad", "cause", "pc", |
447 | "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", | |
448 | "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", | |
449 | "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23", | |
450 | "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", | |
451 | "fsr", "fir", "", /*"fp" */ "", | |
452 | "", "", "bus", "ccfg", "", "", "", "", | |
453 | "", "", "port", "cmp", "", "", "epc", "prid", | |
691c0433 AC |
454 | }; |
455 | ||
456 | /* Names of tx39 registers. */ | |
457 | ||
458 | static const char *mips_tx39_reg_names[NUM_MIPS_PROCESSOR_REGS] = { | |
6d82d43b AC |
459 | "sr", "lo", "hi", "bad", "cause", "pc", |
460 | "", "", "", "", "", "", "", "", | |
461 | "", "", "", "", "", "", "", "", | |
462 | "", "", "", "", "", "", "", "", | |
463 | "", "", "", "", "", "", "", "", | |
464 | "", "", "", "", | |
465 | "", "", "", "", "", "", "", "", | |
466 | "", "", "config", "cache", "debug", "depc", "epc", "" | |
691c0433 AC |
467 | }; |
468 | ||
469 | /* Names of IRIX registers. */ | |
470 | static const char *mips_irix_reg_names[NUM_MIPS_PROCESSOR_REGS] = { | |
6d82d43b AC |
471 | "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", |
472 | "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", | |
473 | "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23", | |
474 | "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", | |
475 | "pc", "cause", "bad", "hi", "lo", "fsr", "fir" | |
691c0433 AC |
476 | }; |
477 | ||
cce74817 | 478 | |
5e2e9765 | 479 | /* Return the name of the register corresponding to REGNO. */ |
5a89d8aa | 480 | static const char * |
5e2e9765 | 481 | mips_register_name (int regno) |
cce74817 | 482 | { |
691c0433 | 483 | struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); |
5e2e9765 KB |
484 | /* GPR names for all ABIs other than n32/n64. */ |
485 | static char *mips_gpr_names[] = { | |
6d82d43b AC |
486 | "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3", |
487 | "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", | |
488 | "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7", | |
489 | "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra", | |
5e2e9765 KB |
490 | }; |
491 | ||
492 | /* GPR names for n32 and n64 ABIs. */ | |
493 | static char *mips_n32_n64_gpr_names[] = { | |
6d82d43b AC |
494 | "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3", |
495 | "a4", "a5", "a6", "a7", "t0", "t1", "t2", "t3", | |
496 | "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7", | |
497 | "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra" | |
5e2e9765 KB |
498 | }; |
499 | ||
500 | enum mips_abi abi = mips_abi (current_gdbarch); | |
501 | ||
a4b8ebc8 AC |
502 | /* Map [NUM_REGS .. 2*NUM_REGS) onto the raw registers, but then |
503 | don't make the raw register names visible. */ | |
504 | int rawnum = regno % NUM_REGS; | |
505 | if (regno < NUM_REGS) | |
506 | return ""; | |
507 | ||
5e2e9765 KB |
508 | /* The MIPS integer registers are always mapped from 0 to 31. The |
509 | names of the registers (which reflects the conventions regarding | |
510 | register use) vary depending on the ABI. */ | |
a4b8ebc8 | 511 | if (0 <= rawnum && rawnum < 32) |
5e2e9765 KB |
512 | { |
513 | if (abi == MIPS_ABI_N32 || abi == MIPS_ABI_N64) | |
a4b8ebc8 | 514 | return mips_n32_n64_gpr_names[rawnum]; |
5e2e9765 | 515 | else |
a4b8ebc8 | 516 | return mips_gpr_names[rawnum]; |
5e2e9765 | 517 | } |
a4b8ebc8 | 518 | else if (32 <= rawnum && rawnum < NUM_REGS) |
691c0433 AC |
519 | { |
520 | gdb_assert (rawnum - 32 < NUM_MIPS_PROCESSOR_REGS); | |
521 | return tdep->mips_processor_reg_names[rawnum - 32]; | |
522 | } | |
5e2e9765 KB |
523 | else |
524 | internal_error (__FILE__, __LINE__, | |
a4b8ebc8 | 525 | "mips_register_name: bad register number %d", rawnum); |
cce74817 | 526 | } |
5e2e9765 | 527 | |
a4b8ebc8 | 528 | /* Return the groups that a MIPS register can be categorised into. */ |
c5aa993b | 529 | |
a4b8ebc8 AC |
530 | static int |
531 | mips_register_reggroup_p (struct gdbarch *gdbarch, int regnum, | |
532 | struct reggroup *reggroup) | |
533 | { | |
534 | int vector_p; | |
535 | int float_p; | |
536 | int raw_p; | |
537 | int rawnum = regnum % NUM_REGS; | |
538 | int pseudo = regnum / NUM_REGS; | |
539 | if (reggroup == all_reggroup) | |
540 | return pseudo; | |
541 | vector_p = TYPE_VECTOR (register_type (gdbarch, regnum)); | |
542 | float_p = TYPE_CODE (register_type (gdbarch, regnum)) == TYPE_CODE_FLT; | |
543 | /* FIXME: cagney/2003-04-13: Can't yet use gdbarch_num_regs | |
544 | (gdbarch), as not all architectures are multi-arch. */ | |
545 | raw_p = rawnum < NUM_REGS; | |
6d82d43b | 546 | if (REGISTER_NAME (regnum) == NULL || REGISTER_NAME (regnum)[0] == '\0') |
a4b8ebc8 AC |
547 | return 0; |
548 | if (reggroup == float_reggroup) | |
549 | return float_p && pseudo; | |
550 | if (reggroup == vector_reggroup) | |
551 | return vector_p && pseudo; | |
552 | if (reggroup == general_reggroup) | |
553 | return (!vector_p && !float_p) && pseudo; | |
554 | /* Save the pseudo registers. Need to make certain that any code | |
555 | extracting register values from a saved register cache also uses | |
556 | pseudo registers. */ | |
557 | if (reggroup == save_reggroup) | |
558 | return raw_p && pseudo; | |
559 | /* Restore the same pseudo register. */ | |
560 | if (reggroup == restore_reggroup) | |
561 | return raw_p && pseudo; | |
6d82d43b | 562 | return 0; |
a4b8ebc8 AC |
563 | } |
564 | ||
565 | /* Map the symbol table registers which live in the range [1 * | |
566 | NUM_REGS .. 2 * NUM_REGS) back onto the corresponding raw | |
47ebcfbe | 567 | registers. Take care of alignment and size problems. */ |
c5aa993b | 568 | |
a4b8ebc8 AC |
569 | static void |
570 | mips_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache, | |
571 | int cookednum, void *buf) | |
572 | { | |
47ebcfbe | 573 | int rawnum = cookednum % NUM_REGS; |
a4b8ebc8 | 574 | gdb_assert (cookednum >= NUM_REGS && cookednum < 2 * NUM_REGS); |
47ebcfbe | 575 | if (register_size (gdbarch, rawnum) == register_size (gdbarch, cookednum)) |
de38af99 | 576 | regcache_raw_read (regcache, rawnum, buf); |
6d82d43b AC |
577 | else if (register_size (gdbarch, rawnum) > |
578 | register_size (gdbarch, cookednum)) | |
47ebcfbe AC |
579 | { |
580 | if (gdbarch_tdep (gdbarch)->mips64_transfers_32bit_regs_p | |
581 | || TARGET_BYTE_ORDER == BFD_ENDIAN_LITTLE) | |
582 | regcache_raw_read_part (regcache, rawnum, 0, 4, buf); | |
583 | else | |
584 | regcache_raw_read_part (regcache, rawnum, 4, 4, buf); | |
585 | } | |
586 | else | |
587 | internal_error (__FILE__, __LINE__, "bad register size"); | |
a4b8ebc8 AC |
588 | } |
589 | ||
590 | static void | |
6d82d43b AC |
591 | mips_pseudo_register_write (struct gdbarch *gdbarch, |
592 | struct regcache *regcache, int cookednum, | |
593 | const void *buf) | |
a4b8ebc8 | 594 | { |
47ebcfbe | 595 | int rawnum = cookednum % NUM_REGS; |
a4b8ebc8 | 596 | gdb_assert (cookednum >= NUM_REGS && cookednum < 2 * NUM_REGS); |
47ebcfbe | 597 | if (register_size (gdbarch, rawnum) == register_size (gdbarch, cookednum)) |
de38af99 | 598 | regcache_raw_write (regcache, rawnum, buf); |
6d82d43b AC |
599 | else if (register_size (gdbarch, rawnum) > |
600 | register_size (gdbarch, cookednum)) | |
47ebcfbe AC |
601 | { |
602 | if (gdbarch_tdep (gdbarch)->mips64_transfers_32bit_regs_p | |
603 | || TARGET_BYTE_ORDER == BFD_ENDIAN_LITTLE) | |
604 | regcache_raw_write_part (regcache, rawnum, 0, 4, buf); | |
605 | else | |
606 | regcache_raw_write_part (regcache, rawnum, 4, 4, buf); | |
607 | } | |
608 | else | |
609 | internal_error (__FILE__, __LINE__, "bad register size"); | |
a4b8ebc8 | 610 | } |
c5aa993b | 611 | |
c906108c | 612 | /* Table to translate MIPS16 register field to actual register number. */ |
6d82d43b | 613 | static int mips16_to_32_reg[8] = { 16, 17, 2, 3, 4, 5, 6, 7 }; |
c906108c SS |
614 | |
615 | /* Heuristic_proc_start may hunt through the text section for a long | |
616 | time across a 2400 baud serial line. Allows the user to limit this | |
617 | search. */ | |
618 | ||
619 | static unsigned int heuristic_fence_post = 0; | |
620 | ||
46cd78fb | 621 | /* Number of bytes of storage in the actual machine representation for |
719ec221 AC |
622 | register N. NOTE: This defines the pseudo register type so need to |
623 | rebuild the architecture vector. */ | |
43e526b9 JM |
624 | |
625 | static int mips64_transfers_32bit_regs_p = 0; | |
626 | ||
719ec221 AC |
627 | static void |
628 | set_mips64_transfers_32bit_regs (char *args, int from_tty, | |
629 | struct cmd_list_element *c) | |
43e526b9 | 630 | { |
719ec221 AC |
631 | struct gdbarch_info info; |
632 | gdbarch_info_init (&info); | |
633 | /* FIXME: cagney/2003-11-15: Should be setting a field in "info" | |
634 | instead of relying on globals. Doing that would let generic code | |
635 | handle the search for this specific architecture. */ | |
636 | if (!gdbarch_update_p (info)) | |
a4b8ebc8 | 637 | { |
719ec221 AC |
638 | mips64_transfers_32bit_regs_p = 0; |
639 | error ("32-bit compatibility mode not supported"); | |
a4b8ebc8 | 640 | } |
a4b8ebc8 AC |
641 | } |
642 | ||
47ebcfbe | 643 | /* Convert to/from a register and the corresponding memory value. */ |
43e526b9 | 644 | |
ff2e87ac AC |
645 | static int |
646 | mips_convert_register_p (int regnum, struct type *type) | |
647 | { | |
648 | return (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG | |
719ec221 | 649 | && register_size (current_gdbarch, regnum) == 4 |
87783b8b AC |
650 | && (regnum % NUM_REGS) >= mips_regnum (current_gdbarch)->fp0 |
651 | && (regnum % NUM_REGS) < mips_regnum (current_gdbarch)->fp0 + 32 | |
6d82d43b | 652 | && TYPE_CODE (type) == TYPE_CODE_FLT && TYPE_LENGTH (type) == 8); |
ff2e87ac AC |
653 | } |
654 | ||
42c466d7 | 655 | static void |
ff2e87ac AC |
656 | mips_register_to_value (struct frame_info *frame, int regnum, |
657 | struct type *type, void *to) | |
102182a9 | 658 | { |
7f5f525d AC |
659 | get_frame_register (frame, regnum + 0, (char *) to + 4); |
660 | get_frame_register (frame, regnum + 1, (char *) to + 0); | |
102182a9 MS |
661 | } |
662 | ||
42c466d7 | 663 | static void |
ff2e87ac AC |
664 | mips_value_to_register (struct frame_info *frame, int regnum, |
665 | struct type *type, const void *from) | |
102182a9 | 666 | { |
ff2e87ac AC |
667 | put_frame_register (frame, regnum + 0, (const char *) from + 4); |
668 | put_frame_register (frame, regnum + 1, (const char *) from + 0); | |
102182a9 MS |
669 | } |
670 | ||
a4b8ebc8 AC |
671 | /* Return the GDB type object for the "standard" data type of data in |
672 | register REG. */ | |
78fde5f8 KB |
673 | |
674 | static struct type * | |
a4b8ebc8 AC |
675 | mips_register_type (struct gdbarch *gdbarch, int regnum) |
676 | { | |
5ef80fb0 | 677 | gdb_assert (regnum >= 0 && regnum < 2 * NUM_REGS); |
56cea623 AC |
678 | if ((regnum % NUM_REGS) >= mips_regnum (current_gdbarch)->fp0 |
679 | && (regnum % NUM_REGS) < mips_regnum (current_gdbarch)->fp0 + 32) | |
a6425924 | 680 | { |
5ef80fb0 | 681 | /* The floating-point registers raw, or cooked, always match |
1b13c4f6 | 682 | mips_isa_regsize(), and also map 1:1, byte for byte. */ |
5ef80fb0 AC |
683 | switch (gdbarch_byte_order (gdbarch)) |
684 | { | |
685 | case BFD_ENDIAN_BIG: | |
1b13c4f6 | 686 | if (mips_isa_regsize (gdbarch) == 4) |
5ef80fb0 AC |
687 | return builtin_type_ieee_single_big; |
688 | else | |
689 | return builtin_type_ieee_double_big; | |
690 | case BFD_ENDIAN_LITTLE: | |
1b13c4f6 | 691 | if (mips_isa_regsize (gdbarch) == 4) |
5ef80fb0 AC |
692 | return builtin_type_ieee_single_little; |
693 | else | |
694 | return builtin_type_ieee_double_little; | |
695 | case BFD_ENDIAN_UNKNOWN: | |
696 | default: | |
697 | internal_error (__FILE__, __LINE__, "bad switch"); | |
698 | } | |
a6425924 | 699 | } |
d5ac5a39 AC |
700 | else if (regnum < NUM_REGS) |
701 | { | |
702 | /* The raw or ISA registers. These are all sized according to | |
703 | the ISA regsize. */ | |
704 | if (mips_isa_regsize (gdbarch) == 4) | |
705 | return builtin_type_int32; | |
706 | else | |
707 | return builtin_type_int64; | |
708 | } | |
78fde5f8 | 709 | else |
d5ac5a39 AC |
710 | { |
711 | /* The cooked or ABI registers. These are sized according to | |
712 | the ABI (with a few complications). */ | |
713 | if (regnum >= (NUM_REGS | |
714 | + mips_regnum (current_gdbarch)->fp_control_status) | |
607fc93c | 715 | && regnum <= NUM_REGS + MIPS_LAST_EMBED_REGNUM) |
d5ac5a39 AC |
716 | /* The pseudo/cooked view of the embedded registers is always |
717 | 32-bit. The raw view is handled below. */ | |
718 | return builtin_type_int32; | |
719 | else if (gdbarch_tdep (gdbarch)->mips64_transfers_32bit_regs_p) | |
720 | /* The target, while possibly using a 64-bit register buffer, | |
721 | is only transfering 32-bits of each integer register. | |
722 | Reflect this in the cooked/pseudo (ABI) register value. */ | |
723 | return builtin_type_int32; | |
724 | else if (mips_abi_regsize (gdbarch) == 4) | |
725 | /* The ABI is restricted to 32-bit registers (the ISA could be | |
726 | 32- or 64-bit). */ | |
727 | return builtin_type_int32; | |
728 | else | |
729 | /* 64-bit ABI. */ | |
730 | return builtin_type_int64; | |
731 | } | |
78fde5f8 KB |
732 | } |
733 | ||
bcb0cc15 MS |
734 | /* TARGET_READ_SP -- Remove useless bits from the stack pointer. */ |
735 | ||
736 | static CORE_ADDR | |
737 | mips_read_sp (void) | |
738 | { | |
f10683bb | 739 | return read_signed_register (MIPS_SP_REGNUM); |
bcb0cc15 MS |
740 | } |
741 | ||
c906108c | 742 | /* Should the upper word of 64-bit addresses be zeroed? */ |
7f19b9a2 | 743 | enum auto_boolean mask_address_var = AUTO_BOOLEAN_AUTO; |
4014092b AC |
744 | |
745 | static int | |
480d3dd2 | 746 | mips_mask_address_p (struct gdbarch_tdep *tdep) |
4014092b AC |
747 | { |
748 | switch (mask_address_var) | |
749 | { | |
7f19b9a2 | 750 | case AUTO_BOOLEAN_TRUE: |
4014092b | 751 | return 1; |
7f19b9a2 | 752 | case AUTO_BOOLEAN_FALSE: |
4014092b AC |
753 | return 0; |
754 | break; | |
7f19b9a2 | 755 | case AUTO_BOOLEAN_AUTO: |
480d3dd2 | 756 | return tdep->default_mask_address_p; |
4014092b | 757 | default: |
6d82d43b | 758 | internal_error (__FILE__, __LINE__, "mips_mask_address_p: bad switch"); |
4014092b | 759 | return -1; |
361d1df0 | 760 | } |
4014092b AC |
761 | } |
762 | ||
763 | static void | |
e9e68a56 | 764 | show_mask_address (char *cmd, int from_tty, struct cmd_list_element *c) |
4014092b | 765 | { |
480d3dd2 | 766 | struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); |
4014092b AC |
767 | switch (mask_address_var) |
768 | { | |
7f19b9a2 | 769 | case AUTO_BOOLEAN_TRUE: |
4014092b AC |
770 | printf_filtered ("The 32 bit mips address mask is enabled\n"); |
771 | break; | |
7f19b9a2 | 772 | case AUTO_BOOLEAN_FALSE: |
4014092b AC |
773 | printf_filtered ("The 32 bit mips address mask is disabled\n"); |
774 | break; | |
7f19b9a2 | 775 | case AUTO_BOOLEAN_AUTO: |
6d82d43b AC |
776 | printf_filtered |
777 | ("The 32 bit address mask is set automatically. Currently %s\n", | |
778 | mips_mask_address_p (tdep) ? "enabled" : "disabled"); | |
4014092b AC |
779 | break; |
780 | default: | |
6d82d43b | 781 | internal_error (__FILE__, __LINE__, "show_mask_address: bad switch"); |
4014092b | 782 | break; |
361d1df0 | 783 | } |
4014092b | 784 | } |
c906108c | 785 | |
c906108c SS |
786 | /* Tell if the program counter value in MEMADDR is in a MIPS16 function. */ |
787 | ||
0fe7e7c8 AC |
788 | int |
789 | mips_pc_is_mips16 (CORE_ADDR memaddr) | |
c906108c SS |
790 | { |
791 | struct minimal_symbol *sym; | |
792 | ||
793 | /* If bit 0 of the address is set, assume this is a MIPS16 address. */ | |
95404a3e | 794 | if (is_mips16_addr (memaddr)) |
c906108c SS |
795 | return 1; |
796 | ||
797 | /* A flag indicating that this is a MIPS16 function is stored by elfread.c in | |
798 | the high bit of the info field. Use this to decide if the function is | |
799 | MIPS16 or normal MIPS. */ | |
800 | sym = lookup_minimal_symbol_by_pc (memaddr); | |
801 | if (sym) | |
71b8ef93 | 802 | return msymbol_is_special (sym); |
c906108c SS |
803 | else |
804 | return 0; | |
805 | } | |
806 | ||
b2fa5097 | 807 | /* MIPS believes that the PC has a sign extended value. Perhaps the |
6c997a34 AC |
808 | all registers should be sign extended for simplicity? */ |
809 | ||
810 | static CORE_ADDR | |
39f77062 | 811 | mips_read_pc (ptid_t ptid) |
6c997a34 | 812 | { |
b6cb9035 AC |
813 | return read_signed_register_pid (mips_regnum (current_gdbarch)->pc, ptid); |
814 | } | |
815 | ||
58dfe9ff AC |
816 | static CORE_ADDR |
817 | mips_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame) | |
818 | { | |
edfae063 AC |
819 | return frame_unwind_register_signed (next_frame, |
820 | NUM_REGS + mips_regnum (gdbarch)->pc); | |
821 | } | |
822 | ||
823 | /* Assuming NEXT_FRAME->prev is a dummy, return the frame ID of that | |
824 | dummy frame. The frame ID's base needs to match the TOS value | |
825 | saved by save_dummy_frame_tos(), and the PC match the dummy frame's | |
826 | breakpoint. */ | |
827 | ||
828 | static struct frame_id | |
829 | mips_unwind_dummy_id (struct gdbarch *gdbarch, struct frame_info *next_frame) | |
830 | { | |
f10683bb | 831 | return frame_id_build (frame_unwind_register_signed (next_frame, NUM_REGS + MIPS_SP_REGNUM), |
edfae063 | 832 | frame_pc_unwind (next_frame)); |
58dfe9ff AC |
833 | } |
834 | ||
b6cb9035 AC |
835 | static void |
836 | mips_write_pc (CORE_ADDR pc, ptid_t ptid) | |
837 | { | |
838 | write_register_pid (mips_regnum (current_gdbarch)->pc, pc, ptid); | |
6c997a34 | 839 | } |
c906108c | 840 | |
c906108c SS |
841 | /* Fetch and return instruction from the specified location. If the PC |
842 | is odd, assume it's a MIPS16 instruction; otherwise MIPS32. */ | |
843 | ||
d37cca3d | 844 | static ULONGEST |
acdb74a0 | 845 | mips_fetch_instruction (CORE_ADDR addr) |
c906108c | 846 | { |
95ac2dcf | 847 | char buf[MIPS_INSN32_SIZE]; |
c906108c SS |
848 | int instlen; |
849 | int status; | |
850 | ||
0fe7e7c8 | 851 | if (mips_pc_is_mips16 (addr)) |
c906108c | 852 | { |
95ac2dcf | 853 | instlen = MIPS_INSN16_SIZE; |
95404a3e | 854 | addr = unmake_mips16_addr (addr); |
c906108c SS |
855 | } |
856 | else | |
95ac2dcf | 857 | instlen = MIPS_INSN32_SIZE; |
1f602b35 | 858 | status = deprecated_read_memory_nobpt (addr, buf, instlen); |
c906108c SS |
859 | if (status) |
860 | memory_error (status, addr); | |
861 | return extract_unsigned_integer (buf, instlen); | |
862 | } | |
863 | ||
c906108c | 864 | /* These the fields of 32 bit mips instructions */ |
e135b889 DJ |
865 | #define mips32_op(x) (x >> 26) |
866 | #define itype_op(x) (x >> 26) | |
867 | #define itype_rs(x) ((x >> 21) & 0x1f) | |
c906108c | 868 | #define itype_rt(x) ((x >> 16) & 0x1f) |
e135b889 | 869 | #define itype_immediate(x) (x & 0xffff) |
c906108c | 870 | |
e135b889 DJ |
871 | #define jtype_op(x) (x >> 26) |
872 | #define jtype_target(x) (x & 0x03ffffff) | |
c906108c | 873 | |
e135b889 DJ |
874 | #define rtype_op(x) (x >> 26) |
875 | #define rtype_rs(x) ((x >> 21) & 0x1f) | |
876 | #define rtype_rt(x) ((x >> 16) & 0x1f) | |
877 | #define rtype_rd(x) ((x >> 11) & 0x1f) | |
878 | #define rtype_shamt(x) ((x >> 6) & 0x1f) | |
879 | #define rtype_funct(x) (x & 0x3f) | |
c906108c SS |
880 | |
881 | static CORE_ADDR | |
c5aa993b JM |
882 | mips32_relative_offset (unsigned long inst) |
883 | { | |
884 | long x; | |
885 | x = itype_immediate (inst); | |
886 | if (x & 0x8000) /* sign bit set */ | |
c906108c | 887 | { |
c5aa993b | 888 | x |= 0xffff0000; /* sign extension */ |
c906108c | 889 | } |
c5aa993b JM |
890 | x = x << 2; |
891 | return x; | |
c906108c SS |
892 | } |
893 | ||
894 | /* Determine whate to set a single step breakpoint while considering | |
895 | branch prediction */ | |
5a89d8aa | 896 | static CORE_ADDR |
c5aa993b JM |
897 | mips32_next_pc (CORE_ADDR pc) |
898 | { | |
899 | unsigned long inst; | |
900 | int op; | |
901 | inst = mips_fetch_instruction (pc); | |
e135b889 | 902 | if ((inst & 0xe0000000) != 0) /* Not a special, jump or branch instruction */ |
c5aa993b | 903 | { |
e135b889 | 904 | if (itype_op (inst) >> 2 == 5) |
6d82d43b | 905 | /* BEQL, BNEL, BLEZL, BGTZL: bits 0101xx */ |
c5aa993b | 906 | { |
e135b889 | 907 | op = (itype_op (inst) & 0x03); |
c906108c SS |
908 | switch (op) |
909 | { | |
e135b889 DJ |
910 | case 0: /* BEQL */ |
911 | goto equal_branch; | |
912 | case 1: /* BNEL */ | |
913 | goto neq_branch; | |
914 | case 2: /* BLEZL */ | |
915 | goto less_branch; | |
916 | case 3: /* BGTZ */ | |
917 | goto greater_branch; | |
c5aa993b JM |
918 | default: |
919 | pc += 4; | |
c906108c SS |
920 | } |
921 | } | |
e135b889 | 922 | else if (itype_op (inst) == 17 && itype_rs (inst) == 8) |
6d82d43b | 923 | /* BC1F, BC1FL, BC1T, BC1TL: 010001 01000 */ |
e135b889 DJ |
924 | { |
925 | int tf = itype_rt (inst) & 0x01; | |
926 | int cnum = itype_rt (inst) >> 2; | |
6d82d43b AC |
927 | int fcrcs = |
928 | read_signed_register (mips_regnum (current_gdbarch)-> | |
929 | fp_control_status); | |
e135b889 DJ |
930 | int cond = ((fcrcs >> 24) & 0x0e) | ((fcrcs >> 23) & 0x01); |
931 | ||
932 | if (((cond >> cnum) & 0x01) == tf) | |
933 | pc += mips32_relative_offset (inst) + 4; | |
934 | else | |
935 | pc += 8; | |
936 | } | |
c5aa993b JM |
937 | else |
938 | pc += 4; /* Not a branch, next instruction is easy */ | |
c906108c SS |
939 | } |
940 | else | |
c5aa993b JM |
941 | { /* This gets way messy */ |
942 | ||
c906108c | 943 | /* Further subdivide into SPECIAL, REGIMM and other */ |
e135b889 | 944 | switch (op = itype_op (inst) & 0x07) /* extract bits 28,27,26 */ |
c906108c | 945 | { |
c5aa993b JM |
946 | case 0: /* SPECIAL */ |
947 | op = rtype_funct (inst); | |
948 | switch (op) | |
949 | { | |
950 | case 8: /* JR */ | |
951 | case 9: /* JALR */ | |
6c997a34 AC |
952 | /* Set PC to that address */ |
953 | pc = read_signed_register (rtype_rs (inst)); | |
c5aa993b JM |
954 | break; |
955 | default: | |
956 | pc += 4; | |
957 | } | |
958 | ||
6d82d43b | 959 | break; /* end SPECIAL */ |
c5aa993b | 960 | case 1: /* REGIMM */ |
c906108c | 961 | { |
e135b889 DJ |
962 | op = itype_rt (inst); /* branch condition */ |
963 | switch (op) | |
c906108c | 964 | { |
c5aa993b | 965 | case 0: /* BLTZ */ |
e135b889 DJ |
966 | case 2: /* BLTZL */ |
967 | case 16: /* BLTZAL */ | |
c5aa993b | 968 | case 18: /* BLTZALL */ |
c906108c | 969 | less_branch: |
6c997a34 | 970 | if (read_signed_register (itype_rs (inst)) < 0) |
c5aa993b JM |
971 | pc += mips32_relative_offset (inst) + 4; |
972 | else | |
973 | pc += 8; /* after the delay slot */ | |
974 | break; | |
e135b889 | 975 | case 1: /* BGEZ */ |
c5aa993b JM |
976 | case 3: /* BGEZL */ |
977 | case 17: /* BGEZAL */ | |
978 | case 19: /* BGEZALL */ | |
6c997a34 | 979 | if (read_signed_register (itype_rs (inst)) >= 0) |
c5aa993b JM |
980 | pc += mips32_relative_offset (inst) + 4; |
981 | else | |
982 | pc += 8; /* after the delay slot */ | |
983 | break; | |
e135b889 | 984 | /* All of the other instructions in the REGIMM category */ |
c5aa993b JM |
985 | default: |
986 | pc += 4; | |
c906108c SS |
987 | } |
988 | } | |
6d82d43b | 989 | break; /* end REGIMM */ |
c5aa993b JM |
990 | case 2: /* J */ |
991 | case 3: /* JAL */ | |
992 | { | |
993 | unsigned long reg; | |
994 | reg = jtype_target (inst) << 2; | |
e135b889 | 995 | /* Upper four bits get never changed... */ |
c5aa993b | 996 | pc = reg + ((pc + 4) & 0xf0000000); |
c906108c | 997 | } |
c5aa993b JM |
998 | break; |
999 | /* FIXME case JALX : */ | |
1000 | { | |
1001 | unsigned long reg; | |
1002 | reg = jtype_target (inst) << 2; | |
1003 | pc = reg + ((pc + 4) & 0xf0000000) + 1; /* yes, +1 */ | |
c906108c SS |
1004 | /* Add 1 to indicate 16 bit mode - Invert ISA mode */ |
1005 | } | |
c5aa993b | 1006 | break; /* The new PC will be alternate mode */ |
e135b889 | 1007 | case 4: /* BEQ, BEQL */ |
c5aa993b | 1008 | equal_branch: |
6c997a34 AC |
1009 | if (read_signed_register (itype_rs (inst)) == |
1010 | read_signed_register (itype_rt (inst))) | |
c5aa993b JM |
1011 | pc += mips32_relative_offset (inst) + 4; |
1012 | else | |
1013 | pc += 8; | |
1014 | break; | |
e135b889 | 1015 | case 5: /* BNE, BNEL */ |
c5aa993b | 1016 | neq_branch: |
6c997a34 | 1017 | if (read_signed_register (itype_rs (inst)) != |
e135b889 | 1018 | read_signed_register (itype_rt (inst))) |
c5aa993b JM |
1019 | pc += mips32_relative_offset (inst) + 4; |
1020 | else | |
1021 | pc += 8; | |
1022 | break; | |
e135b889 | 1023 | case 6: /* BLEZ, BLEZL */ |
1fd8cd20 | 1024 | if (read_signed_register (itype_rs (inst)) <= 0) |
c5aa993b JM |
1025 | pc += mips32_relative_offset (inst) + 4; |
1026 | else | |
1027 | pc += 8; | |
1028 | break; | |
1029 | case 7: | |
e135b889 DJ |
1030 | default: |
1031 | greater_branch: /* BGTZ, BGTZL */ | |
1fd8cd20 | 1032 | if (read_signed_register (itype_rs (inst)) > 0) |
c5aa993b JM |
1033 | pc += mips32_relative_offset (inst) + 4; |
1034 | else | |
1035 | pc += 8; | |
1036 | break; | |
c5aa993b JM |
1037 | } /* switch */ |
1038 | } /* else */ | |
1039 | return pc; | |
1040 | } /* mips32_next_pc */ | |
c906108c SS |
1041 | |
1042 | /* Decoding the next place to set a breakpoint is irregular for the | |
e26cc349 | 1043 | mips 16 variant, but fortunately, there fewer instructions. We have to cope |
c906108c SS |
1044 | ith extensions for 16 bit instructions and a pair of actual 32 bit instructions. |
1045 | We dont want to set a single step instruction on the extend instruction | |
1046 | either. | |
c5aa993b | 1047 | */ |
c906108c SS |
1048 | |
1049 | /* Lots of mips16 instruction formats */ | |
1050 | /* Predicting jumps requires itype,ritype,i8type | |
1051 | and their extensions extItype,extritype,extI8type | |
c5aa993b | 1052 | */ |
c906108c SS |
1053 | enum mips16_inst_fmts |
1054 | { | |
c5aa993b JM |
1055 | itype, /* 0 immediate 5,10 */ |
1056 | ritype, /* 1 5,3,8 */ | |
1057 | rrtype, /* 2 5,3,3,5 */ | |
1058 | rritype, /* 3 5,3,3,5 */ | |
1059 | rrrtype, /* 4 5,3,3,3,2 */ | |
1060 | rriatype, /* 5 5,3,3,1,4 */ | |
1061 | shifttype, /* 6 5,3,3,3,2 */ | |
1062 | i8type, /* 7 5,3,8 */ | |
1063 | i8movtype, /* 8 5,3,3,5 */ | |
1064 | i8mov32rtype, /* 9 5,3,5,3 */ | |
1065 | i64type, /* 10 5,3,8 */ | |
1066 | ri64type, /* 11 5,3,3,5 */ | |
1067 | jalxtype, /* 12 5,1,5,5,16 - a 32 bit instruction */ | |
1068 | exiItype, /* 13 5,6,5,5,1,1,1,1,1,1,5 */ | |
1069 | extRitype, /* 14 5,6,5,5,3,1,1,1,5 */ | |
1070 | extRRItype, /* 15 5,5,5,5,3,3,5 */ | |
1071 | extRRIAtype, /* 16 5,7,4,5,3,3,1,4 */ | |
1072 | EXTshifttype, /* 17 5,5,1,1,1,1,1,1,5,3,3,1,1,1,2 */ | |
1073 | extI8type, /* 18 5,6,5,5,3,1,1,1,5 */ | |
1074 | extI64type, /* 19 5,6,5,5,3,1,1,1,5 */ | |
1075 | extRi64type, /* 20 5,6,5,5,3,3,5 */ | |
1076 | extshift64type /* 21 5,5,1,1,1,1,1,1,5,1,1,1,3,5 */ | |
1077 | }; | |
12f02c2a AC |
1078 | /* I am heaping all the fields of the formats into one structure and |
1079 | then, only the fields which are involved in instruction extension */ | |
c906108c | 1080 | struct upk_mips16 |
6d82d43b AC |
1081 | { |
1082 | CORE_ADDR offset; | |
1083 | unsigned int regx; /* Function in i8 type */ | |
1084 | unsigned int regy; | |
1085 | }; | |
c906108c SS |
1086 | |
1087 | ||
12f02c2a AC |
1088 | /* The EXT-I, EXT-ri nad EXT-I8 instructions all have the same format |
1089 | for the bits which make up the immediatate extension. */ | |
c906108c | 1090 | |
12f02c2a AC |
1091 | static CORE_ADDR |
1092 | extended_offset (unsigned int extension) | |
c906108c | 1093 | { |
12f02c2a | 1094 | CORE_ADDR value; |
c5aa993b JM |
1095 | value = (extension >> 21) & 0x3f; /* * extract 15:11 */ |
1096 | value = value << 6; | |
1097 | value |= (extension >> 16) & 0x1f; /* extrace 10:5 */ | |
1098 | value = value << 5; | |
1099 | value |= extension & 0x01f; /* extract 4:0 */ | |
1100 | return value; | |
c906108c SS |
1101 | } |
1102 | ||
1103 | /* Only call this function if you know that this is an extendable | |
1104 | instruction, It wont malfunction, but why make excess remote memory references? | |
1105 | If the immediate operands get sign extended or somthing, do it after | |
1106 | the extension is performed. | |
c5aa993b | 1107 | */ |
c906108c SS |
1108 | /* FIXME: Every one of these cases needs to worry about sign extension |
1109 | when the offset is to be used in relative addressing */ | |
1110 | ||
1111 | ||
12f02c2a | 1112 | static unsigned int |
c5aa993b | 1113 | fetch_mips_16 (CORE_ADDR pc) |
c906108c | 1114 | { |
c5aa993b JM |
1115 | char buf[8]; |
1116 | pc &= 0xfffffffe; /* clear the low order bit */ | |
1117 | target_read_memory (pc, buf, 2); | |
1118 | return extract_unsigned_integer (buf, 2); | |
c906108c SS |
1119 | } |
1120 | ||
1121 | static void | |
c5aa993b | 1122 | unpack_mips16 (CORE_ADDR pc, |
12f02c2a AC |
1123 | unsigned int extension, |
1124 | unsigned int inst, | |
6d82d43b | 1125 | enum mips16_inst_fmts insn_format, struct upk_mips16 *upk) |
c906108c | 1126 | { |
12f02c2a AC |
1127 | CORE_ADDR offset; |
1128 | int regx; | |
1129 | int regy; | |
1130 | switch (insn_format) | |
c906108c | 1131 | { |
c5aa993b | 1132 | case itype: |
c906108c | 1133 | { |
12f02c2a AC |
1134 | CORE_ADDR value; |
1135 | if (extension) | |
c5aa993b JM |
1136 | { |
1137 | value = extended_offset (extension); | |
1138 | value = value << 11; /* rom for the original value */ | |
6d82d43b | 1139 | value |= inst & 0x7ff; /* eleven bits from instruction */ |
c906108c SS |
1140 | } |
1141 | else | |
c5aa993b | 1142 | { |
12f02c2a | 1143 | value = inst & 0x7ff; |
c5aa993b | 1144 | /* FIXME : Consider sign extension */ |
c906108c | 1145 | } |
12f02c2a AC |
1146 | offset = value; |
1147 | regx = -1; | |
1148 | regy = -1; | |
c906108c | 1149 | } |
c5aa993b JM |
1150 | break; |
1151 | case ritype: | |
1152 | case i8type: | |
1153 | { /* A register identifier and an offset */ | |
c906108c SS |
1154 | /* Most of the fields are the same as I type but the |
1155 | immediate value is of a different length */ | |
12f02c2a AC |
1156 | CORE_ADDR value; |
1157 | if (extension) | |
c906108c | 1158 | { |
c5aa993b JM |
1159 | value = extended_offset (extension); |
1160 | value = value << 8; /* from the original instruction */ | |
12f02c2a AC |
1161 | value |= inst & 0xff; /* eleven bits from instruction */ |
1162 | regx = (extension >> 8) & 0x07; /* or i8 funct */ | |
c5aa993b JM |
1163 | if (value & 0x4000) /* test the sign bit , bit 26 */ |
1164 | { | |
1165 | value &= ~0x3fff; /* remove the sign bit */ | |
1166 | value = -value; | |
c906108c SS |
1167 | } |
1168 | } | |
c5aa993b JM |
1169 | else |
1170 | { | |
12f02c2a AC |
1171 | value = inst & 0xff; /* 8 bits */ |
1172 | regx = (inst >> 8) & 0x07; /* or i8 funct */ | |
c5aa993b JM |
1173 | /* FIXME: Do sign extension , this format needs it */ |
1174 | if (value & 0x80) /* THIS CONFUSES ME */ | |
1175 | { | |
1176 | value &= 0xef; /* remove the sign bit */ | |
1177 | value = -value; | |
1178 | } | |
c5aa993b | 1179 | } |
12f02c2a AC |
1180 | offset = value; |
1181 | regy = -1; | |
c5aa993b | 1182 | break; |
c906108c | 1183 | } |
c5aa993b | 1184 | case jalxtype: |
c906108c | 1185 | { |
c5aa993b | 1186 | unsigned long value; |
12f02c2a AC |
1187 | unsigned int nexthalf; |
1188 | value = ((inst & 0x1f) << 5) | ((inst >> 5) & 0x1f); | |
c5aa993b JM |
1189 | value = value << 16; |
1190 | nexthalf = mips_fetch_instruction (pc + 2); /* low bit still set */ | |
1191 | value |= nexthalf; | |
12f02c2a AC |
1192 | offset = value; |
1193 | regx = -1; | |
1194 | regy = -1; | |
c5aa993b | 1195 | break; |
c906108c SS |
1196 | } |
1197 | default: | |
6d82d43b | 1198 | internal_error (__FILE__, __LINE__, "bad switch"); |
c906108c | 1199 | } |
12f02c2a AC |
1200 | upk->offset = offset; |
1201 | upk->regx = regx; | |
1202 | upk->regy = regy; | |
c906108c SS |
1203 | } |
1204 | ||
1205 | ||
c5aa993b JM |
1206 | static CORE_ADDR |
1207 | add_offset_16 (CORE_ADDR pc, int offset) | |
c906108c | 1208 | { |
c5aa993b | 1209 | return ((offset << 2) | ((pc + 2) & (0xf0000000))); |
c906108c SS |
1210 | } |
1211 | ||
12f02c2a AC |
1212 | static CORE_ADDR |
1213 | extended_mips16_next_pc (CORE_ADDR pc, | |
6d82d43b | 1214 | unsigned int extension, unsigned int insn) |
c906108c | 1215 | { |
12f02c2a AC |
1216 | int op = (insn >> 11); |
1217 | switch (op) | |
c906108c | 1218 | { |
6d82d43b | 1219 | case 2: /* Branch */ |
12f02c2a AC |
1220 | { |
1221 | CORE_ADDR offset; | |
1222 | struct upk_mips16 upk; | |
1223 | unpack_mips16 (pc, extension, insn, itype, &upk); | |
1224 | offset = upk.offset; | |
1225 | if (offset & 0x800) | |
1226 | { | |
1227 | offset &= 0xeff; | |
1228 | offset = -offset; | |
1229 | } | |
1230 | pc += (offset << 1) + 2; | |
1231 | break; | |
1232 | } | |
6d82d43b | 1233 | case 3: /* JAL , JALX - Watch out, these are 32 bit instruction */ |
12f02c2a AC |
1234 | { |
1235 | struct upk_mips16 upk; | |
1236 | unpack_mips16 (pc, extension, insn, jalxtype, &upk); | |
1237 | pc = add_offset_16 (pc, upk.offset); | |
1238 | if ((insn >> 10) & 0x01) /* Exchange mode */ | |
1239 | pc = pc & ~0x01; /* Clear low bit, indicate 32 bit mode */ | |
1240 | else | |
1241 | pc |= 0x01; | |
1242 | break; | |
1243 | } | |
6d82d43b | 1244 | case 4: /* beqz */ |
12f02c2a AC |
1245 | { |
1246 | struct upk_mips16 upk; | |
1247 | int reg; | |
1248 | unpack_mips16 (pc, extension, insn, ritype, &upk); | |
1249 | reg = read_signed_register (upk.regx); | |
1250 | if (reg == 0) | |
1251 | pc += (upk.offset << 1) + 2; | |
1252 | else | |
1253 | pc += 2; | |
1254 | break; | |
1255 | } | |
6d82d43b | 1256 | case 5: /* bnez */ |
12f02c2a AC |
1257 | { |
1258 | struct upk_mips16 upk; | |
1259 | int reg; | |
1260 | unpack_mips16 (pc, extension, insn, ritype, &upk); | |
1261 | reg = read_signed_register (upk.regx); | |
1262 | if (reg != 0) | |
1263 | pc += (upk.offset << 1) + 2; | |
1264 | else | |
1265 | pc += 2; | |
1266 | break; | |
1267 | } | |
6d82d43b | 1268 | case 12: /* I8 Formats btez btnez */ |
12f02c2a AC |
1269 | { |
1270 | struct upk_mips16 upk; | |
1271 | int reg; | |
1272 | unpack_mips16 (pc, extension, insn, i8type, &upk); | |
1273 | /* upk.regx contains the opcode */ | |
1274 | reg = read_signed_register (24); /* Test register is 24 */ | |
1275 | if (((upk.regx == 0) && (reg == 0)) /* BTEZ */ | |
1276 | || ((upk.regx == 1) && (reg != 0))) /* BTNEZ */ | |
1277 | /* pc = add_offset_16(pc,upk.offset) ; */ | |
1278 | pc += (upk.offset << 1) + 2; | |
1279 | else | |
1280 | pc += 2; | |
1281 | break; | |
1282 | } | |
6d82d43b | 1283 | case 29: /* RR Formats JR, JALR, JALR-RA */ |
12f02c2a AC |
1284 | { |
1285 | struct upk_mips16 upk; | |
1286 | /* upk.fmt = rrtype; */ | |
1287 | op = insn & 0x1f; | |
1288 | if (op == 0) | |
c5aa993b | 1289 | { |
12f02c2a AC |
1290 | int reg; |
1291 | upk.regx = (insn >> 8) & 0x07; | |
1292 | upk.regy = (insn >> 5) & 0x07; | |
1293 | switch (upk.regy) | |
c5aa993b | 1294 | { |
12f02c2a AC |
1295 | case 0: |
1296 | reg = upk.regx; | |
1297 | break; | |
1298 | case 1: | |
1299 | reg = 31; | |
6d82d43b | 1300 | break; /* Function return instruction */ |
12f02c2a AC |
1301 | case 2: |
1302 | reg = upk.regx; | |
1303 | break; | |
1304 | default: | |
1305 | reg = 31; | |
6d82d43b | 1306 | break; /* BOGUS Guess */ |
c906108c | 1307 | } |
12f02c2a | 1308 | pc = read_signed_register (reg); |
c906108c | 1309 | } |
12f02c2a | 1310 | else |
c5aa993b | 1311 | pc += 2; |
12f02c2a AC |
1312 | break; |
1313 | } | |
1314 | case 30: | |
1315 | /* This is an instruction extension. Fetch the real instruction | |
1316 | (which follows the extension) and decode things based on | |
1317 | that. */ | |
1318 | { | |
1319 | pc += 2; | |
1320 | pc = extended_mips16_next_pc (pc, insn, fetch_mips_16 (pc)); | |
1321 | break; | |
1322 | } | |
1323 | default: | |
1324 | { | |
1325 | pc += 2; | |
1326 | break; | |
1327 | } | |
c906108c | 1328 | } |
c5aa993b | 1329 | return pc; |
12f02c2a | 1330 | } |
c906108c | 1331 | |
5a89d8aa | 1332 | static CORE_ADDR |
12f02c2a AC |
1333 | mips16_next_pc (CORE_ADDR pc) |
1334 | { | |
1335 | unsigned int insn = fetch_mips_16 (pc); | |
1336 | return extended_mips16_next_pc (pc, 0, insn); | |
1337 | } | |
1338 | ||
1339 | /* The mips_next_pc function supports single_step when the remote | |
7e73cedf | 1340 | target monitor or stub is not developed enough to do a single_step. |
12f02c2a AC |
1341 | It works by decoding the current instruction and predicting where a |
1342 | branch will go. This isnt hard because all the data is available. | |
1343 | The MIPS32 and MIPS16 variants are quite different */ | |
c5aa993b JM |
1344 | CORE_ADDR |
1345 | mips_next_pc (CORE_ADDR pc) | |
c906108c | 1346 | { |
c5aa993b JM |
1347 | if (pc & 0x01) |
1348 | return mips16_next_pc (pc); | |
1349 | else | |
1350 | return mips32_next_pc (pc); | |
12f02c2a | 1351 | } |
c906108c | 1352 | |
edfae063 AC |
1353 | struct mips_frame_cache |
1354 | { | |
1355 | CORE_ADDR base; | |
1356 | struct trad_frame_saved_reg *saved_regs; | |
1357 | }; | |
1358 | ||
29639122 JB |
1359 | /* Set a register's saved stack address in temp_saved_regs. If an |
1360 | address has already been set for this register, do nothing; this | |
1361 | way we will only recognize the first save of a given register in a | |
1362 | function prologue. | |
eec63939 | 1363 | |
29639122 JB |
1364 | For simplicity, save the address in both [0 .. NUM_REGS) and |
1365 | [NUM_REGS .. 2*NUM_REGS). Strictly speaking, only the second range | |
1366 | is used as it is only second range (the ABI instead of ISA | |
1367 | registers) that comes into play when finding saved registers in a | |
1368 | frame. */ | |
eec63939 AC |
1369 | |
1370 | static void | |
29639122 JB |
1371 | set_reg_offset (struct mips_frame_cache *this_cache, int regnum, |
1372 | CORE_ADDR offset) | |
eec63939 | 1373 | { |
29639122 JB |
1374 | if (this_cache != NULL |
1375 | && this_cache->saved_regs[regnum].addr == -1) | |
1376 | { | |
1377 | this_cache->saved_regs[regnum + 0 * NUM_REGS].addr = offset; | |
1378 | this_cache->saved_regs[regnum + 1 * NUM_REGS].addr = offset; | |
1379 | } | |
eec63939 AC |
1380 | } |
1381 | ||
eec63939 | 1382 | |
29639122 JB |
1383 | /* Fetch the immediate value from a MIPS16 instruction. |
1384 | If the previous instruction was an EXTEND, use it to extend | |
1385 | the upper bits of the immediate value. This is a helper function | |
1386 | for mips16_scan_prologue. */ | |
eec63939 | 1387 | |
29639122 JB |
1388 | static int |
1389 | mips16_get_imm (unsigned short prev_inst, /* previous instruction */ | |
1390 | unsigned short inst, /* current instruction */ | |
1391 | int nbits, /* number of bits in imm field */ | |
1392 | int scale, /* scale factor to be applied to imm */ | |
1393 | int is_signed) /* is the imm field signed? */ | |
eec63939 | 1394 | { |
29639122 | 1395 | int offset; |
eec63939 | 1396 | |
29639122 JB |
1397 | if ((prev_inst & 0xf800) == 0xf000) /* prev instruction was EXTEND? */ |
1398 | { | |
1399 | offset = ((prev_inst & 0x1f) << 11) | (prev_inst & 0x7e0); | |
1400 | if (offset & 0x8000) /* check for negative extend */ | |
1401 | offset = 0 - (0x10000 - (offset & 0xffff)); | |
1402 | return offset | (inst & 0x1f); | |
1403 | } | |
eec63939 | 1404 | else |
29639122 JB |
1405 | { |
1406 | int max_imm = 1 << nbits; | |
1407 | int mask = max_imm - 1; | |
1408 | int sign_bit = max_imm >> 1; | |
45c9dd44 | 1409 | |
29639122 JB |
1410 | offset = inst & mask; |
1411 | if (is_signed && (offset & sign_bit)) | |
1412 | offset = 0 - (max_imm - offset); | |
1413 | return offset * scale; | |
1414 | } | |
1415 | } | |
eec63939 | 1416 | |
65596487 | 1417 | |
29639122 JB |
1418 | /* Analyze the function prologue from START_PC to LIMIT_PC. Builds |
1419 | the associated FRAME_CACHE if not null. | |
1420 | Return the address of the first instruction past the prologue. */ | |
eec63939 | 1421 | |
29639122 JB |
1422 | static CORE_ADDR |
1423 | mips16_scan_prologue (CORE_ADDR start_pc, CORE_ADDR limit_pc, | |
1424 | struct frame_info *next_frame, | |
1425 | struct mips_frame_cache *this_cache) | |
1426 | { | |
1427 | CORE_ADDR cur_pc; | |
1428 | CORE_ADDR frame_addr = 0; /* Value of $r17, used as frame pointer */ | |
1429 | CORE_ADDR sp; | |
1430 | long frame_offset = 0; /* Size of stack frame. */ | |
1431 | long frame_adjust = 0; /* Offset of FP from SP. */ | |
1432 | int frame_reg = MIPS_SP_REGNUM; | |
1433 | unsigned short prev_inst = 0; /* saved copy of previous instruction */ | |
1434 | unsigned inst = 0; /* current instruction */ | |
1435 | unsigned entry_inst = 0; /* the entry instruction */ | |
1436 | int reg, offset; | |
a343eb3c | 1437 | |
29639122 JB |
1438 | int extend_bytes = 0; |
1439 | int prev_extend_bytes; | |
1440 | CORE_ADDR end_prologue_addr = 0; | |
a343eb3c | 1441 | |
29639122 JB |
1442 | /* Can be called when there's no process, and hence when there's no |
1443 | NEXT_FRAME. */ | |
1444 | if (next_frame != NULL) | |
1445 | sp = read_next_frame_reg (next_frame, NUM_REGS + MIPS_SP_REGNUM); | |
1446 | else | |
1447 | sp = 0; | |
eec63939 | 1448 | |
29639122 JB |
1449 | if (limit_pc > start_pc + 200) |
1450 | limit_pc = start_pc + 200; | |
eec63939 | 1451 | |
95ac2dcf | 1452 | for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += MIPS_INSN16_SIZE) |
29639122 JB |
1453 | { |
1454 | /* Save the previous instruction. If it's an EXTEND, we'll extract | |
1455 | the immediate offset extension from it in mips16_get_imm. */ | |
1456 | prev_inst = inst; | |
eec63939 | 1457 | |
29639122 JB |
1458 | /* Fetch and decode the instruction. */ |
1459 | inst = (unsigned short) mips_fetch_instruction (cur_pc); | |
eec63939 | 1460 | |
29639122 JB |
1461 | /* Normally we ignore extend instructions. However, if it is |
1462 | not followed by a valid prologue instruction, then this | |
1463 | instruction is not part of the prologue either. We must | |
1464 | remember in this case to adjust the end_prologue_addr back | |
1465 | over the extend. */ | |
1466 | if ((inst & 0xf800) == 0xf000) /* extend */ | |
1467 | { | |
95ac2dcf | 1468 | extend_bytes = MIPS_INSN16_SIZE; |
29639122 JB |
1469 | continue; |
1470 | } | |
eec63939 | 1471 | |
29639122 JB |
1472 | prev_extend_bytes = extend_bytes; |
1473 | extend_bytes = 0; | |
eec63939 | 1474 | |
29639122 JB |
1475 | if ((inst & 0xff00) == 0x6300 /* addiu sp */ |
1476 | || (inst & 0xff00) == 0xfb00) /* daddiu sp */ | |
1477 | { | |
1478 | offset = mips16_get_imm (prev_inst, inst, 8, 8, 1); | |
1479 | if (offset < 0) /* negative stack adjustment? */ | |
1480 | frame_offset -= offset; | |
1481 | else | |
1482 | /* Exit loop if a positive stack adjustment is found, which | |
1483 | usually means that the stack cleanup code in the function | |
1484 | epilogue is reached. */ | |
1485 | break; | |
1486 | } | |
1487 | else if ((inst & 0xf800) == 0xd000) /* sw reg,n($sp) */ | |
1488 | { | |
1489 | offset = mips16_get_imm (prev_inst, inst, 8, 4, 0); | |
1490 | reg = mips16_to_32_reg[(inst & 0x700) >> 8]; | |
1491 | set_reg_offset (this_cache, reg, sp + offset); | |
1492 | } | |
1493 | else if ((inst & 0xff00) == 0xf900) /* sd reg,n($sp) */ | |
1494 | { | |
1495 | offset = mips16_get_imm (prev_inst, inst, 5, 8, 0); | |
1496 | reg = mips16_to_32_reg[(inst & 0xe0) >> 5]; | |
1497 | set_reg_offset (this_cache, reg, sp + offset); | |
1498 | } | |
1499 | else if ((inst & 0xff00) == 0x6200) /* sw $ra,n($sp) */ | |
1500 | { | |
1501 | offset = mips16_get_imm (prev_inst, inst, 8, 4, 0); | |
4c7d22cb | 1502 | set_reg_offset (this_cache, MIPS_RA_REGNUM, sp + offset); |
29639122 JB |
1503 | } |
1504 | else if ((inst & 0xff00) == 0xfa00) /* sd $ra,n($sp) */ | |
1505 | { | |
1506 | offset = mips16_get_imm (prev_inst, inst, 8, 8, 0); | |
4c7d22cb | 1507 | set_reg_offset (this_cache, MIPS_RA_REGNUM, sp + offset); |
29639122 JB |
1508 | } |
1509 | else if (inst == 0x673d) /* move $s1, $sp */ | |
1510 | { | |
1511 | frame_addr = sp; | |
1512 | frame_reg = 17; | |
1513 | } | |
1514 | else if ((inst & 0xff00) == 0x0100) /* addiu $s1,sp,n */ | |
1515 | { | |
1516 | offset = mips16_get_imm (prev_inst, inst, 8, 4, 0); | |
1517 | frame_addr = sp + offset; | |
1518 | frame_reg = 17; | |
1519 | frame_adjust = offset; | |
1520 | } | |
1521 | else if ((inst & 0xFF00) == 0xd900) /* sw reg,offset($s1) */ | |
1522 | { | |
1523 | offset = mips16_get_imm (prev_inst, inst, 5, 4, 0); | |
1524 | reg = mips16_to_32_reg[(inst & 0xe0) >> 5]; | |
1525 | set_reg_offset (this_cache, reg, frame_addr + offset); | |
1526 | } | |
1527 | else if ((inst & 0xFF00) == 0x7900) /* sd reg,offset($s1) */ | |
1528 | { | |
1529 | offset = mips16_get_imm (prev_inst, inst, 5, 8, 0); | |
1530 | reg = mips16_to_32_reg[(inst & 0xe0) >> 5]; | |
1531 | set_reg_offset (this_cache, reg, frame_addr + offset); | |
1532 | } | |
1533 | else if ((inst & 0xf81f) == 0xe809 | |
1534 | && (inst & 0x700) != 0x700) /* entry */ | |
1535 | entry_inst = inst; /* save for later processing */ | |
1536 | else if ((inst & 0xf800) == 0x1800) /* jal(x) */ | |
95ac2dcf | 1537 | cur_pc += MIPS_INSN16_SIZE; /* 32-bit instruction */ |
29639122 JB |
1538 | else if ((inst & 0xff1c) == 0x6704) /* move reg,$a0-$a3 */ |
1539 | { | |
1540 | /* This instruction is part of the prologue, but we don't | |
1541 | need to do anything special to handle it. */ | |
1542 | } | |
1543 | else | |
1544 | { | |
1545 | /* This instruction is not an instruction typically found | |
1546 | in a prologue, so we must have reached the end of the | |
1547 | prologue. */ | |
1548 | if (end_prologue_addr == 0) | |
1549 | end_prologue_addr = cur_pc - prev_extend_bytes; | |
1550 | } | |
1551 | } | |
eec63939 | 1552 | |
29639122 JB |
1553 | /* The entry instruction is typically the first instruction in a function, |
1554 | and it stores registers at offsets relative to the value of the old SP | |
1555 | (before the prologue). But the value of the sp parameter to this | |
1556 | function is the new SP (after the prologue has been executed). So we | |
1557 | can't calculate those offsets until we've seen the entire prologue, | |
1558 | and can calculate what the old SP must have been. */ | |
1559 | if (entry_inst != 0) | |
1560 | { | |
1561 | int areg_count = (entry_inst >> 8) & 7; | |
1562 | int sreg_count = (entry_inst >> 6) & 3; | |
eec63939 | 1563 | |
29639122 JB |
1564 | /* The entry instruction always subtracts 32 from the SP. */ |
1565 | frame_offset += 32; | |
1566 | ||
1567 | /* Now we can calculate what the SP must have been at the | |
1568 | start of the function prologue. */ | |
1569 | sp += frame_offset; | |
1570 | ||
1571 | /* Check if a0-a3 were saved in the caller's argument save area. */ | |
1572 | for (reg = 4, offset = 0; reg < areg_count + 4; reg++) | |
1573 | { | |
1574 | set_reg_offset (this_cache, reg, sp + offset); | |
1575 | offset += mips_abi_regsize (current_gdbarch); | |
1576 | } | |
1577 | ||
1578 | /* Check if the ra register was pushed on the stack. */ | |
1579 | offset = -4; | |
1580 | if (entry_inst & 0x20) | |
1581 | { | |
4c7d22cb | 1582 | set_reg_offset (this_cache, MIPS_RA_REGNUM, sp + offset); |
29639122 JB |
1583 | offset -= mips_abi_regsize (current_gdbarch); |
1584 | } | |
1585 | ||
1586 | /* Check if the s0 and s1 registers were pushed on the stack. */ | |
1587 | for (reg = 16; reg < sreg_count + 16; reg++) | |
1588 | { | |
1589 | set_reg_offset (this_cache, reg, sp + offset); | |
1590 | offset -= mips_abi_regsize (current_gdbarch); | |
1591 | } | |
1592 | } | |
1593 | ||
1594 | if (this_cache != NULL) | |
1595 | { | |
1596 | this_cache->base = | |
1597 | (frame_unwind_register_signed (next_frame, NUM_REGS + frame_reg) | |
1598 | + frame_offset - frame_adjust); | |
1599 | /* FIXME: brobecker/2004-10-10: Just as in the mips32 case, we should | |
1600 | be able to get rid of the assignment below, evetually. But it's | |
1601 | still needed for now. */ | |
1602 | this_cache->saved_regs[NUM_REGS + mips_regnum (current_gdbarch)->pc] | |
4c7d22cb | 1603 | = this_cache->saved_regs[NUM_REGS + MIPS_RA_REGNUM]; |
29639122 JB |
1604 | } |
1605 | ||
1606 | /* If we didn't reach the end of the prologue when scanning the function | |
1607 | instructions, then set end_prologue_addr to the address of the | |
1608 | instruction immediately after the last one we scanned. */ | |
1609 | if (end_prologue_addr == 0) | |
1610 | end_prologue_addr = cur_pc; | |
1611 | ||
1612 | return end_prologue_addr; | |
eec63939 AC |
1613 | } |
1614 | ||
29639122 JB |
1615 | /* Heuristic unwinder for 16-bit MIPS instruction set (aka MIPS16). |
1616 | Procedures that use the 32-bit instruction set are handled by the | |
1617 | mips_insn32 unwinder. */ | |
1618 | ||
1619 | static struct mips_frame_cache * | |
1620 | mips_insn16_frame_cache (struct frame_info *next_frame, void **this_cache) | |
eec63939 | 1621 | { |
29639122 | 1622 | struct mips_frame_cache *cache; |
eec63939 AC |
1623 | |
1624 | if ((*this_cache) != NULL) | |
1625 | return (*this_cache); | |
29639122 JB |
1626 | cache = FRAME_OBSTACK_ZALLOC (struct mips_frame_cache); |
1627 | (*this_cache) = cache; | |
1628 | cache->saved_regs = trad_frame_alloc_saved_regs (next_frame); | |
eec63939 | 1629 | |
29639122 JB |
1630 | /* Analyze the function prologue. */ |
1631 | { | |
1632 | const CORE_ADDR pc = frame_pc_unwind (next_frame); | |
1633 | CORE_ADDR start_addr; | |
eec63939 | 1634 | |
29639122 JB |
1635 | find_pc_partial_function (pc, NULL, &start_addr, NULL); |
1636 | if (start_addr == 0) | |
1637 | start_addr = heuristic_proc_start (pc); | |
1638 | /* We can't analyze the prologue if we couldn't find the begining | |
1639 | of the function. */ | |
1640 | if (start_addr == 0) | |
1641 | return cache; | |
eec63939 | 1642 | |
29639122 JB |
1643 | mips16_scan_prologue (start_addr, pc, next_frame, *this_cache); |
1644 | } | |
1645 | ||
1646 | /* SP_REGNUM, contains the value and not the address. */ | |
1647 | trad_frame_set_value (cache->saved_regs, NUM_REGS + MIPS_SP_REGNUM, cache->base); | |
eec63939 | 1648 | |
29639122 | 1649 | return (*this_cache); |
eec63939 AC |
1650 | } |
1651 | ||
1652 | static void | |
29639122 JB |
1653 | mips_insn16_frame_this_id (struct frame_info *next_frame, void **this_cache, |
1654 | struct frame_id *this_id) | |
eec63939 | 1655 | { |
29639122 JB |
1656 | struct mips_frame_cache *info = mips_insn16_frame_cache (next_frame, |
1657 | this_cache); | |
1658 | (*this_id) = frame_id_build (info->base, frame_func_unwind (next_frame)); | |
eec63939 AC |
1659 | } |
1660 | ||
1661 | static void | |
29639122 | 1662 | mips_insn16_frame_prev_register (struct frame_info *next_frame, |
eec63939 AC |
1663 | void **this_cache, |
1664 | int regnum, int *optimizedp, | |
1665 | enum lval_type *lvalp, CORE_ADDR *addrp, | |
1666 | int *realnump, void *valuep) | |
1667 | { | |
29639122 JB |
1668 | struct mips_frame_cache *info = mips_insn16_frame_cache (next_frame, |
1669 | this_cache); | |
1670 | trad_frame_get_prev_register (next_frame, info->saved_regs, regnum, | |
1671 | optimizedp, lvalp, addrp, realnump, valuep); | |
eec63939 AC |
1672 | } |
1673 | ||
29639122 | 1674 | static const struct frame_unwind mips_insn16_frame_unwind = |
eec63939 AC |
1675 | { |
1676 | NORMAL_FRAME, | |
29639122 JB |
1677 | mips_insn16_frame_this_id, |
1678 | mips_insn16_frame_prev_register | |
eec63939 AC |
1679 | }; |
1680 | ||
1681 | static const struct frame_unwind * | |
29639122 | 1682 | mips_insn16_frame_sniffer (struct frame_info *next_frame) |
eec63939 AC |
1683 | { |
1684 | CORE_ADDR pc = frame_pc_unwind (next_frame); | |
0fe7e7c8 | 1685 | if (mips_pc_is_mips16 (pc)) |
29639122 JB |
1686 | return &mips_insn16_frame_unwind; |
1687 | return NULL; | |
eec63939 AC |
1688 | } |
1689 | ||
1690 | static CORE_ADDR | |
29639122 JB |
1691 | mips_insn16_frame_base_address (struct frame_info *next_frame, |
1692 | void **this_cache) | |
eec63939 | 1693 | { |
29639122 JB |
1694 | struct mips_frame_cache *info = mips_insn16_frame_cache (next_frame, |
1695 | this_cache); | |
1696 | return info->base; | |
eec63939 AC |
1697 | } |
1698 | ||
29639122 | 1699 | static const struct frame_base mips_insn16_frame_base = |
eec63939 | 1700 | { |
29639122 JB |
1701 | &mips_insn16_frame_unwind, |
1702 | mips_insn16_frame_base_address, | |
1703 | mips_insn16_frame_base_address, | |
1704 | mips_insn16_frame_base_address | |
eec63939 AC |
1705 | }; |
1706 | ||
1707 | static const struct frame_base * | |
29639122 | 1708 | mips_insn16_frame_base_sniffer (struct frame_info *next_frame) |
eec63939 | 1709 | { |
29639122 JB |
1710 | if (mips_insn16_frame_sniffer (next_frame) != NULL) |
1711 | return &mips_insn16_frame_base; | |
eec63939 AC |
1712 | else |
1713 | return NULL; | |
edfae063 AC |
1714 | } |
1715 | ||
29639122 JB |
1716 | /* Mark all the registers as unset in the saved_regs array |
1717 | of THIS_CACHE. Do nothing if THIS_CACHE is null. */ | |
1718 | ||
1719 | void | |
1720 | reset_saved_regs (struct mips_frame_cache *this_cache) | |
c906108c | 1721 | { |
29639122 JB |
1722 | if (this_cache == NULL || this_cache->saved_regs == NULL) |
1723 | return; | |
1724 | ||
1725 | { | |
1726 | const int num_regs = NUM_REGS; | |
1727 | int i; | |
64159455 | 1728 | |
29639122 JB |
1729 | for (i = 0; i < num_regs; i++) |
1730 | { | |
1731 | this_cache->saved_regs[i].addr = -1; | |
1732 | } | |
1733 | } | |
c906108c SS |
1734 | } |
1735 | ||
29639122 JB |
1736 | /* Analyze the function prologue from START_PC to LIMIT_PC. Builds |
1737 | the associated FRAME_CACHE if not null. | |
1738 | Return the address of the first instruction past the prologue. */ | |
c906108c | 1739 | |
875e1767 | 1740 | static CORE_ADDR |
29639122 JB |
1741 | mips32_scan_prologue (CORE_ADDR start_pc, CORE_ADDR limit_pc, |
1742 | struct frame_info *next_frame, | |
1743 | struct mips_frame_cache *this_cache) | |
c906108c | 1744 | { |
29639122 JB |
1745 | CORE_ADDR cur_pc; |
1746 | CORE_ADDR frame_addr = 0; /* Value of $r30. Used by gcc for frame-pointer */ | |
1747 | CORE_ADDR sp; | |
1748 | long frame_offset; | |
1749 | int frame_reg = MIPS_SP_REGNUM; | |
8fa9cfa1 | 1750 | |
29639122 JB |
1751 | CORE_ADDR end_prologue_addr = 0; |
1752 | int seen_sp_adjust = 0; | |
1753 | int load_immediate_bytes = 0; | |
8fa9cfa1 | 1754 | |
29639122 JB |
1755 | /* Can be called when there's no process, and hence when there's no |
1756 | NEXT_FRAME. */ | |
1757 | if (next_frame != NULL) | |
1758 | sp = read_next_frame_reg (next_frame, NUM_REGS + MIPS_SP_REGNUM); | |
8fa9cfa1 | 1759 | else |
29639122 | 1760 | sp = 0; |
9022177c | 1761 | |
29639122 JB |
1762 | if (limit_pc > start_pc + 200) |
1763 | limit_pc = start_pc + 200; | |
9022177c | 1764 | |
29639122 | 1765 | restart: |
9022177c | 1766 | |
29639122 | 1767 | frame_offset = 0; |
95ac2dcf | 1768 | for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += MIPS_INSN32_SIZE) |
9022177c | 1769 | { |
29639122 JB |
1770 | unsigned long inst, high_word, low_word; |
1771 | int reg; | |
9022177c | 1772 | |
29639122 JB |
1773 | /* Fetch the instruction. */ |
1774 | inst = (unsigned long) mips_fetch_instruction (cur_pc); | |
9022177c | 1775 | |
29639122 JB |
1776 | /* Save some code by pre-extracting some useful fields. */ |
1777 | high_word = (inst >> 16) & 0xffff; | |
1778 | low_word = inst & 0xffff; | |
1779 | reg = high_word & 0x1f; | |
fe29b929 | 1780 | |
29639122 JB |
1781 | if (high_word == 0x27bd /* addiu $sp,$sp,-i */ |
1782 | || high_word == 0x23bd /* addi $sp,$sp,-i */ | |
1783 | || high_word == 0x67bd) /* daddiu $sp,$sp,-i */ | |
1784 | { | |
1785 | if (low_word & 0x8000) /* negative stack adjustment? */ | |
1786 | frame_offset += 0x10000 - low_word; | |
1787 | else | |
1788 | /* Exit loop if a positive stack adjustment is found, which | |
1789 | usually means that the stack cleanup code in the function | |
1790 | epilogue is reached. */ | |
1791 | break; | |
1792 | seen_sp_adjust = 1; | |
1793 | } | |
1794 | else if ((high_word & 0xFFE0) == 0xafa0) /* sw reg,offset($sp) */ | |
1795 | { | |
1796 | set_reg_offset (this_cache, reg, sp + low_word); | |
1797 | } | |
1798 | else if ((high_word & 0xFFE0) == 0xffa0) /* sd reg,offset($sp) */ | |
1799 | { | |
1800 | /* Irix 6.2 N32 ABI uses sd instructions for saving $gp and $ra. */ | |
1801 | set_reg_offset (this_cache, reg, sp + low_word); | |
1802 | } | |
1803 | else if (high_word == 0x27be) /* addiu $30,$sp,size */ | |
1804 | { | |
1805 | /* Old gcc frame, r30 is virtual frame pointer. */ | |
1806 | if ((long) low_word != frame_offset) | |
1807 | frame_addr = sp + low_word; | |
1808 | else if (frame_reg == MIPS_SP_REGNUM) | |
1809 | { | |
1810 | unsigned alloca_adjust; | |
a4b8ebc8 | 1811 | |
29639122 JB |
1812 | frame_reg = 30; |
1813 | frame_addr = read_next_frame_reg (next_frame, NUM_REGS + 30); | |
1814 | alloca_adjust = (unsigned) (frame_addr - (sp + low_word)); | |
1815 | if (alloca_adjust > 0) | |
1816 | { | |
1817 | /* FP > SP + frame_size. This may be because of | |
1818 | an alloca or somethings similar. Fix sp to | |
1819 | "pre-alloca" value, and try again. */ | |
1820 | sp += alloca_adjust; | |
1821 | /* Need to reset the status of all registers. Otherwise, | |
1822 | we will hit a guard that prevents the new address | |
1823 | for each register to be recomputed during the second | |
1824 | pass. */ | |
1825 | reset_saved_regs (this_cache); | |
1826 | goto restart; | |
1827 | } | |
1828 | } | |
1829 | } | |
1830 | /* move $30,$sp. With different versions of gas this will be either | |
1831 | `addu $30,$sp,$zero' or `or $30,$sp,$zero' or `daddu 30,sp,$0'. | |
1832 | Accept any one of these. */ | |
1833 | else if (inst == 0x03A0F021 || inst == 0x03a0f025 || inst == 0x03a0f02d) | |
1834 | { | |
1835 | /* New gcc frame, virtual frame pointer is at r30 + frame_size. */ | |
1836 | if (frame_reg == MIPS_SP_REGNUM) | |
1837 | { | |
1838 | unsigned alloca_adjust; | |
c906108c | 1839 | |
29639122 JB |
1840 | frame_reg = 30; |
1841 | frame_addr = read_next_frame_reg (next_frame, NUM_REGS + 30); | |
1842 | alloca_adjust = (unsigned) (frame_addr - sp); | |
1843 | if (alloca_adjust > 0) | |
1844 | { | |
1845 | /* FP > SP + frame_size. This may be because of | |
1846 | an alloca or somethings similar. Fix sp to | |
1847 | "pre-alloca" value, and try again. */ | |
1848 | sp = frame_addr; | |
1849 | /* Need to reset the status of all registers. Otherwise, | |
1850 | we will hit a guard that prevents the new address | |
1851 | for each register to be recomputed during the second | |
1852 | pass. */ | |
1853 | reset_saved_regs (this_cache); | |
1854 | goto restart; | |
1855 | } | |
1856 | } | |
1857 | } | |
1858 | else if ((high_word & 0xFFE0) == 0xafc0) /* sw reg,offset($30) */ | |
1859 | { | |
1860 | set_reg_offset (this_cache, reg, frame_addr + low_word); | |
1861 | } | |
1862 | else if ((high_word & 0xFFE0) == 0xE7A0 /* swc1 freg,n($sp) */ | |
1863 | || (high_word & 0xF3E0) == 0xA3C0 /* sx reg,n($s8) */ | |
1864 | || (inst & 0xFF9F07FF) == 0x00800021 /* move reg,$a0-$a3 */ | |
1865 | || high_word == 0x3c1c /* lui $gp,n */ | |
1866 | || high_word == 0x279c /* addiu $gp,$gp,n */ | |
1867 | || inst == 0x0399e021 /* addu $gp,$gp,$t9 */ | |
1868 | || inst == 0x033ce021 /* addu $gp,$t9,$gp */ | |
1869 | ) | |
1870 | { | |
1871 | /* These instructions are part of the prologue, but we don't | |
1872 | need to do anything special to handle them. */ | |
1873 | } | |
1874 | /* The instructions below load $at or $t0 with an immediate | |
1875 | value in preparation for a stack adjustment via | |
1876 | subu $sp,$sp,[$at,$t0]. These instructions could also | |
1877 | initialize a local variable, so we accept them only before | |
1878 | a stack adjustment instruction was seen. */ | |
1879 | else if (!seen_sp_adjust | |
1880 | && (high_word == 0x3c01 /* lui $at,n */ | |
1881 | || high_word == 0x3c08 /* lui $t0,n */ | |
1882 | || high_word == 0x3421 /* ori $at,$at,n */ | |
1883 | || high_word == 0x3508 /* ori $t0,$t0,n */ | |
1884 | || high_word == 0x3401 /* ori $at,$zero,n */ | |
1885 | || high_word == 0x3408 /* ori $t0,$zero,n */ | |
1886 | )) | |
1887 | { | |
95ac2dcf | 1888 | load_immediate_bytes += MIPS_INSN32_SIZE; /* FIXME! */ |
29639122 JB |
1889 | } |
1890 | else | |
1891 | { | |
1892 | /* This instruction is not an instruction typically found | |
1893 | in a prologue, so we must have reached the end of the | |
1894 | prologue. */ | |
1895 | /* FIXME: brobecker/2004-10-10: Can't we just break out of this | |
1896 | loop now? Why would we need to continue scanning the function | |
1897 | instructions? */ | |
1898 | if (end_prologue_addr == 0) | |
1899 | end_prologue_addr = cur_pc; | |
1900 | } | |
a4b8ebc8 | 1901 | } |
c906108c | 1902 | |
29639122 JB |
1903 | if (this_cache != NULL) |
1904 | { | |
1905 | this_cache->base = | |
1906 | (frame_unwind_register_signed (next_frame, NUM_REGS + frame_reg) | |
1907 | + frame_offset); | |
1908 | /* FIXME: brobecker/2004-09-15: We should be able to get rid of | |
1909 | this assignment below, eventually. But it's still needed | |
1910 | for now. */ | |
1911 | this_cache->saved_regs[NUM_REGS + mips_regnum (current_gdbarch)->pc] | |
4c7d22cb | 1912 | = this_cache->saved_regs[NUM_REGS + MIPS_RA_REGNUM]; |
29639122 | 1913 | } |
c906108c | 1914 | |
29639122 JB |
1915 | /* If we didn't reach the end of the prologue when scanning the function |
1916 | instructions, then set end_prologue_addr to the address of the | |
1917 | instruction immediately after the last one we scanned. */ | |
1918 | /* brobecker/2004-10-10: I don't think this would ever happen, but | |
1919 | we may as well be careful and do our best if we have a null | |
1920 | end_prologue_addr. */ | |
1921 | if (end_prologue_addr == 0) | |
1922 | end_prologue_addr = cur_pc; | |
1923 | ||
1924 | /* In a frameless function, we might have incorrectly | |
1925 | skipped some load immediate instructions. Undo the skipping | |
1926 | if the load immediate was not followed by a stack adjustment. */ | |
1927 | if (load_immediate_bytes && !seen_sp_adjust) | |
1928 | end_prologue_addr -= load_immediate_bytes; | |
c906108c | 1929 | |
29639122 | 1930 | return end_prologue_addr; |
c906108c SS |
1931 | } |
1932 | ||
29639122 JB |
1933 | /* Heuristic unwinder for procedures using 32-bit instructions (covers |
1934 | both 32-bit and 64-bit MIPS ISAs). Procedures using 16-bit | |
1935 | instructions (a.k.a. MIPS16) are handled by the mips_insn16 | |
1936 | unwinder. */ | |
c906108c | 1937 | |
29639122 JB |
1938 | static struct mips_frame_cache * |
1939 | mips_insn32_frame_cache (struct frame_info *next_frame, void **this_cache) | |
c906108c | 1940 | { |
29639122 | 1941 | struct mips_frame_cache *cache; |
c906108c | 1942 | |
29639122 JB |
1943 | if ((*this_cache) != NULL) |
1944 | return (*this_cache); | |
c5aa993b | 1945 | |
29639122 JB |
1946 | cache = FRAME_OBSTACK_ZALLOC (struct mips_frame_cache); |
1947 | (*this_cache) = cache; | |
1948 | cache->saved_regs = trad_frame_alloc_saved_regs (next_frame); | |
c5aa993b | 1949 | |
29639122 JB |
1950 | /* Analyze the function prologue. */ |
1951 | { | |
1952 | const CORE_ADDR pc = frame_pc_unwind (next_frame); | |
1953 | CORE_ADDR start_addr; | |
c906108c | 1954 | |
29639122 JB |
1955 | find_pc_partial_function (pc, NULL, &start_addr, NULL); |
1956 | if (start_addr == 0) | |
1957 | start_addr = heuristic_proc_start (pc); | |
1958 | /* We can't analyze the prologue if we couldn't find the begining | |
1959 | of the function. */ | |
1960 | if (start_addr == 0) | |
1961 | return cache; | |
c5aa993b | 1962 | |
29639122 JB |
1963 | mips32_scan_prologue (start_addr, pc, next_frame, *this_cache); |
1964 | } | |
1965 | ||
1966 | /* SP_REGNUM, contains the value and not the address. */ | |
1967 | trad_frame_set_value (cache->saved_regs, NUM_REGS + MIPS_SP_REGNUM, cache->base); | |
c5aa993b | 1968 | |
29639122 | 1969 | return (*this_cache); |
c906108c SS |
1970 | } |
1971 | ||
29639122 JB |
1972 | static void |
1973 | mips_insn32_frame_this_id (struct frame_info *next_frame, void **this_cache, | |
1974 | struct frame_id *this_id) | |
c906108c | 1975 | { |
29639122 JB |
1976 | struct mips_frame_cache *info = mips_insn32_frame_cache (next_frame, |
1977 | this_cache); | |
1978 | (*this_id) = frame_id_build (info->base, frame_func_unwind (next_frame)); | |
1979 | } | |
c906108c | 1980 | |
29639122 JB |
1981 | static void |
1982 | mips_insn32_frame_prev_register (struct frame_info *next_frame, | |
1983 | void **this_cache, | |
1984 | int regnum, int *optimizedp, | |
1985 | enum lval_type *lvalp, CORE_ADDR *addrp, | |
1986 | int *realnump, void *valuep) | |
1987 | { | |
1988 | struct mips_frame_cache *info = mips_insn32_frame_cache (next_frame, | |
1989 | this_cache); | |
1990 | trad_frame_get_prev_register (next_frame, info->saved_regs, regnum, | |
1991 | optimizedp, lvalp, addrp, realnump, valuep); | |
c906108c SS |
1992 | } |
1993 | ||
29639122 JB |
1994 | static const struct frame_unwind mips_insn32_frame_unwind = |
1995 | { | |
1996 | NORMAL_FRAME, | |
1997 | mips_insn32_frame_this_id, | |
1998 | mips_insn32_frame_prev_register | |
1999 | }; | |
c906108c | 2000 | |
29639122 JB |
2001 | static const struct frame_unwind * |
2002 | mips_insn32_frame_sniffer (struct frame_info *next_frame) | |
2003 | { | |
2004 | CORE_ADDR pc = frame_pc_unwind (next_frame); | |
0fe7e7c8 | 2005 | if (! mips_pc_is_mips16 (pc)) |
29639122 JB |
2006 | return &mips_insn32_frame_unwind; |
2007 | return NULL; | |
2008 | } | |
c906108c | 2009 | |
1c645fec | 2010 | static CORE_ADDR |
29639122 JB |
2011 | mips_insn32_frame_base_address (struct frame_info *next_frame, |
2012 | void **this_cache) | |
c906108c | 2013 | { |
29639122 JB |
2014 | struct mips_frame_cache *info = mips_insn32_frame_cache (next_frame, |
2015 | this_cache); | |
2016 | return info->base; | |
2017 | } | |
c906108c | 2018 | |
29639122 JB |
2019 | static const struct frame_base mips_insn32_frame_base = |
2020 | { | |
2021 | &mips_insn32_frame_unwind, | |
2022 | mips_insn32_frame_base_address, | |
2023 | mips_insn32_frame_base_address, | |
2024 | mips_insn32_frame_base_address | |
2025 | }; | |
1c645fec | 2026 | |
29639122 JB |
2027 | static const struct frame_base * |
2028 | mips_insn32_frame_base_sniffer (struct frame_info *next_frame) | |
2029 | { | |
2030 | if (mips_insn32_frame_sniffer (next_frame) != NULL) | |
2031 | return &mips_insn32_frame_base; | |
a65bbe44 | 2032 | else |
29639122 JB |
2033 | return NULL; |
2034 | } | |
a65bbe44 | 2035 | |
29639122 JB |
2036 | static struct trad_frame_cache * |
2037 | mips_stub_frame_cache (struct frame_info *next_frame, void **this_cache) | |
2038 | { | |
2039 | CORE_ADDR pc; | |
2040 | CORE_ADDR start_addr; | |
2041 | CORE_ADDR stack_addr; | |
2042 | struct trad_frame_cache *this_trad_cache; | |
c906108c | 2043 | |
29639122 JB |
2044 | if ((*this_cache) != NULL) |
2045 | return (*this_cache); | |
2046 | this_trad_cache = trad_frame_cache_zalloc (next_frame); | |
2047 | (*this_cache) = this_trad_cache; | |
1c645fec | 2048 | |
29639122 | 2049 | /* The return address is in the link register. */ |
4c7d22cb | 2050 | trad_frame_set_reg_realreg (this_trad_cache, PC_REGNUM, MIPS_RA_REGNUM); |
1c645fec | 2051 | |
29639122 JB |
2052 | /* Frame ID, since it's a frameless / stackless function, no stack |
2053 | space is allocated and SP on entry is the current SP. */ | |
2054 | pc = frame_pc_unwind (next_frame); | |
2055 | find_pc_partial_function (pc, NULL, &start_addr, NULL); | |
4c7d22cb | 2056 | stack_addr = frame_unwind_register_signed (next_frame, MIPS_SP_REGNUM); |
29639122 | 2057 | trad_frame_set_id (this_trad_cache, frame_id_build (start_addr, stack_addr)); |
1c645fec | 2058 | |
29639122 JB |
2059 | /* Assume that the frame's base is the same as the |
2060 | stack-pointer. */ | |
2061 | trad_frame_set_this_base (this_trad_cache, stack_addr); | |
c906108c | 2062 | |
29639122 JB |
2063 | return this_trad_cache; |
2064 | } | |
c906108c | 2065 | |
29639122 JB |
2066 | static void |
2067 | mips_stub_frame_this_id (struct frame_info *next_frame, void **this_cache, | |
2068 | struct frame_id *this_id) | |
2069 | { | |
2070 | struct trad_frame_cache *this_trad_cache | |
2071 | = mips_stub_frame_cache (next_frame, this_cache); | |
2072 | trad_frame_get_id (this_trad_cache, this_id); | |
2073 | } | |
c906108c | 2074 | |
29639122 JB |
2075 | static void |
2076 | mips_stub_frame_prev_register (struct frame_info *next_frame, | |
2077 | void **this_cache, | |
2078 | int regnum, int *optimizedp, | |
2079 | enum lval_type *lvalp, CORE_ADDR *addrp, | |
2080 | int *realnump, void *valuep) | |
2081 | { | |
2082 | struct trad_frame_cache *this_trad_cache | |
2083 | = mips_stub_frame_cache (next_frame, this_cache); | |
2084 | trad_frame_get_register (this_trad_cache, next_frame, regnum, optimizedp, | |
2085 | lvalp, addrp, realnump, valuep); | |
2086 | } | |
c906108c | 2087 | |
29639122 JB |
2088 | static const struct frame_unwind mips_stub_frame_unwind = |
2089 | { | |
2090 | NORMAL_FRAME, | |
2091 | mips_stub_frame_this_id, | |
2092 | mips_stub_frame_prev_register | |
2093 | }; | |
c906108c | 2094 | |
29639122 JB |
2095 | static const struct frame_unwind * |
2096 | mips_stub_frame_sniffer (struct frame_info *next_frame) | |
2097 | { | |
2098 | CORE_ADDR pc = frame_pc_unwind (next_frame); | |
2099 | if (in_plt_section (pc, NULL)) | |
2100 | return &mips_stub_frame_unwind; | |
2101 | else | |
2102 | return NULL; | |
2103 | } | |
c906108c | 2104 | |
29639122 JB |
2105 | static CORE_ADDR |
2106 | mips_stub_frame_base_address (struct frame_info *next_frame, | |
2107 | void **this_cache) | |
2108 | { | |
2109 | struct trad_frame_cache *this_trad_cache | |
2110 | = mips_stub_frame_cache (next_frame, this_cache); | |
2111 | return trad_frame_get_this_base (this_trad_cache); | |
2112 | } | |
0fce0821 | 2113 | |
29639122 JB |
2114 | static const struct frame_base mips_stub_frame_base = |
2115 | { | |
2116 | &mips_stub_frame_unwind, | |
2117 | mips_stub_frame_base_address, | |
2118 | mips_stub_frame_base_address, | |
2119 | mips_stub_frame_base_address | |
2120 | }; | |
2121 | ||
2122 | static const struct frame_base * | |
2123 | mips_stub_frame_base_sniffer (struct frame_info *next_frame) | |
2124 | { | |
2125 | if (mips_stub_frame_sniffer (next_frame) != NULL) | |
2126 | return &mips_stub_frame_base; | |
2127 | else | |
2128 | return NULL; | |
2129 | } | |
2130 | ||
2131 | static CORE_ADDR | |
2132 | read_next_frame_reg (struct frame_info *fi, int regno) | |
2133 | { | |
2134 | /* Always a pseudo. */ | |
2135 | gdb_assert (regno >= NUM_REGS); | |
2136 | if (fi == NULL) | |
0fce0821 | 2137 | { |
29639122 JB |
2138 | LONGEST val; |
2139 | regcache_cooked_read_signed (current_regcache, regno, &val); | |
2140 | return val; | |
0fce0821 | 2141 | } |
29639122 JB |
2142 | else |
2143 | return frame_unwind_register_signed (fi, regno); | |
1c645fec | 2144 | |
c906108c SS |
2145 | } |
2146 | ||
29639122 | 2147 | /* mips_addr_bits_remove - remove useless address bits */ |
65596487 | 2148 | |
29639122 JB |
2149 | static CORE_ADDR |
2150 | mips_addr_bits_remove (CORE_ADDR addr) | |
65596487 | 2151 | { |
29639122 JB |
2152 | struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); |
2153 | if (mips_mask_address_p (tdep) && (((ULONGEST) addr) >> 32 == 0xffffffffUL)) | |
2154 | /* This hack is a work-around for existing boards using PMON, the | |
2155 | simulator, and any other 64-bit targets that doesn't have true | |
2156 | 64-bit addressing. On these targets, the upper 32 bits of | |
2157 | addresses are ignored by the hardware. Thus, the PC or SP are | |
2158 | likely to have been sign extended to all 1s by instruction | |
2159 | sequences that load 32-bit addresses. For example, a typical | |
2160 | piece of code that loads an address is this: | |
65596487 | 2161 | |
29639122 JB |
2162 | lui $r2, <upper 16 bits> |
2163 | ori $r2, <lower 16 bits> | |
65596487 | 2164 | |
29639122 JB |
2165 | But the lui sign-extends the value such that the upper 32 bits |
2166 | may be all 1s. The workaround is simply to mask off these | |
2167 | bits. In the future, gcc may be changed to support true 64-bit | |
2168 | addressing, and this masking will have to be disabled. */ | |
2169 | return addr &= 0xffffffffUL; | |
2170 | else | |
2171 | return addr; | |
65596487 JB |
2172 | } |
2173 | ||
29639122 JB |
2174 | /* mips_software_single_step() is called just before we want to resume |
2175 | the inferior, if we want to single-step it but there is no hardware | |
2176 | or kernel single-step support (MIPS on GNU/Linux for example). We find | |
2177 | the target of the coming instruction and breakpoint it. | |
1e05a7bf | 2178 | |
29639122 JB |
2179 | single_step is also called just after the inferior stops. If we had |
2180 | set up a simulated single-step, we undo our damage. */ | |
2181 | ||
2182 | void | |
2183 | mips_software_single_step (enum target_signal sig, int insert_breakpoints_p) | |
c906108c | 2184 | { |
29639122 JB |
2185 | static CORE_ADDR next_pc; |
2186 | typedef char binsn_quantum[BREAKPOINT_MAX]; | |
2187 | static binsn_quantum break_mem; | |
2188 | CORE_ADDR pc; | |
65596487 | 2189 | |
29639122 JB |
2190 | if (insert_breakpoints_p) |
2191 | { | |
2192 | pc = read_register (mips_regnum (current_gdbarch)->pc); | |
2193 | next_pc = mips_next_pc (pc); | |
98b4dd94 | 2194 | |
29639122 JB |
2195 | target_insert_breakpoint (next_pc, break_mem); |
2196 | } | |
a65bbe44 | 2197 | else |
29639122 JB |
2198 | target_remove_breakpoint (next_pc, break_mem); |
2199 | } | |
a65bbe44 | 2200 | |
29639122 JB |
2201 | /* Test whether the PC points to the return instruction at the |
2202 | end of a function. */ | |
65596487 | 2203 | |
29639122 JB |
2204 | static int |
2205 | mips_about_to_return (CORE_ADDR pc) | |
2206 | { | |
0fe7e7c8 | 2207 | if (mips_pc_is_mips16 (pc)) |
29639122 JB |
2208 | /* This mips16 case isn't necessarily reliable. Sometimes the compiler |
2209 | generates a "jr $ra"; other times it generates code to load | |
2210 | the return address from the stack to an accessible register (such | |
2211 | as $a3), then a "jr" using that register. This second case | |
2212 | is almost impossible to distinguish from an indirect jump | |
2213 | used for switch statements, so we don't even try. */ | |
2214 | return mips_fetch_instruction (pc) == 0xe820; /* jr $ra */ | |
2215 | else | |
2216 | return mips_fetch_instruction (pc) == 0x3e00008; /* jr $ra */ | |
2217 | } | |
c906108c | 2218 | |
c906108c | 2219 | |
29639122 JB |
2220 | /* This fencepost looks highly suspicious to me. Removing it also |
2221 | seems suspicious as it could affect remote debugging across serial | |
2222 | lines. */ | |
c906108c | 2223 | |
29639122 JB |
2224 | static CORE_ADDR |
2225 | heuristic_proc_start (CORE_ADDR pc) | |
2226 | { | |
2227 | CORE_ADDR start_pc; | |
2228 | CORE_ADDR fence; | |
2229 | int instlen; | |
2230 | int seen_adjsp = 0; | |
65596487 | 2231 | |
29639122 JB |
2232 | pc = ADDR_BITS_REMOVE (pc); |
2233 | start_pc = pc; | |
2234 | fence = start_pc - heuristic_fence_post; | |
2235 | if (start_pc == 0) | |
2236 | return 0; | |
65596487 | 2237 | |
29639122 JB |
2238 | if (heuristic_fence_post == UINT_MAX || fence < VM_MIN_ADDRESS) |
2239 | fence = VM_MIN_ADDRESS; | |
65596487 | 2240 | |
95ac2dcf | 2241 | instlen = mips_pc_is_mips16 (pc) ? MIPS_INSN16_SIZE : MIPS_INSN32_SIZE; |
98b4dd94 | 2242 | |
29639122 JB |
2243 | /* search back for previous return */ |
2244 | for (start_pc -= instlen;; start_pc -= instlen) | |
2245 | if (start_pc < fence) | |
2246 | { | |
2247 | /* It's not clear to me why we reach this point when | |
2248 | stop_soon, but with this test, at least we | |
2249 | don't print out warnings for every child forked (eg, on | |
2250 | decstation). 22apr93 [email protected]. */ | |
2251 | if (stop_soon == NO_STOP_QUIETLY) | |
2252 | { | |
2253 | static int blurb_printed = 0; | |
98b4dd94 | 2254 | |
29639122 JB |
2255 | warning ("GDB can't find the start of the function at 0x%s.", |
2256 | paddr_nz (pc)); | |
2257 | ||
2258 | if (!blurb_printed) | |
2259 | { | |
2260 | /* This actually happens frequently in embedded | |
2261 | development, when you first connect to a board | |
2262 | and your stack pointer and pc are nowhere in | |
2263 | particular. This message needs to give people | |
2264 | in that situation enough information to | |
2265 | determine that it's no big deal. */ | |
2266 | printf_filtered ("\n\ | |
2267 | GDB is unable to find the start of the function at 0x%s\n\ | |
2268 | and thus can't determine the size of that function's stack frame.\n\ | |
2269 | This means that GDB may be unable to access that stack frame, or\n\ | |
2270 | the frames below it.\n\ | |
2271 | This problem is most likely caused by an invalid program counter or\n\ | |
2272 | stack pointer.\n\ | |
2273 | However, if you think GDB should simply search farther back\n\ | |
2274 | from 0x%s for code which looks like the beginning of a\n\ | |
2275 | function, you can increase the range of the search using the `set\n\ | |
2276 | heuristic-fence-post' command.\n", paddr_nz (pc), paddr_nz (pc)); | |
2277 | blurb_printed = 1; | |
2278 | } | |
2279 | } | |
2280 | ||
2281 | return 0; | |
2282 | } | |
0fe7e7c8 | 2283 | else if (mips_pc_is_mips16 (start_pc)) |
29639122 JB |
2284 | { |
2285 | unsigned short inst; | |
2286 | ||
2287 | /* On MIPS16, any one of the following is likely to be the | |
2288 | start of a function: | |
2289 | entry | |
2290 | addiu sp,-n | |
2291 | daddiu sp,-n | |
2292 | extend -n followed by 'addiu sp,+n' or 'daddiu sp,+n' */ | |
2293 | inst = mips_fetch_instruction (start_pc); | |
2294 | if (((inst & 0xf81f) == 0xe809 && (inst & 0x700) != 0x700) /* entry */ | |
2295 | || (inst & 0xff80) == 0x6380 /* addiu sp,-n */ | |
2296 | || (inst & 0xff80) == 0xfb80 /* daddiu sp,-n */ | |
2297 | || ((inst & 0xf810) == 0xf010 && seen_adjsp)) /* extend -n */ | |
2298 | break; | |
2299 | else if ((inst & 0xff00) == 0x6300 /* addiu sp */ | |
2300 | || (inst & 0xff00) == 0xfb00) /* daddiu sp */ | |
2301 | seen_adjsp = 1; | |
2302 | else | |
2303 | seen_adjsp = 0; | |
2304 | } | |
2305 | else if (mips_about_to_return (start_pc)) | |
2306 | { | |
4c7d22cb | 2307 | /* Skip return and its delay slot. */ |
95ac2dcf | 2308 | start_pc += 2 * MIPS_INSN32_SIZE; |
29639122 JB |
2309 | break; |
2310 | } | |
2311 | ||
2312 | return start_pc; | |
c906108c SS |
2313 | } |
2314 | ||
6c0d6680 DJ |
2315 | struct mips_objfile_private |
2316 | { | |
2317 | bfd_size_type size; | |
2318 | char *contents; | |
2319 | }; | |
2320 | ||
f09ded24 AC |
2321 | /* According to the current ABI, should the type be passed in a |
2322 | floating-point register (assuming that there is space)? When there | |
2323 | is no FPU, FP are not even considered as possibile candidates for | |
2324 | FP registers and, consequently this returns false - forces FP | |
2325 | arguments into integer registers. */ | |
2326 | ||
2327 | static int | |
2328 | fp_register_arg_p (enum type_code typecode, struct type *arg_type) | |
2329 | { | |
2330 | return ((typecode == TYPE_CODE_FLT | |
2331 | || (MIPS_EABI | |
6d82d43b AC |
2332 | && (typecode == TYPE_CODE_STRUCT |
2333 | || typecode == TYPE_CODE_UNION) | |
f09ded24 AC |
2334 | && TYPE_NFIELDS (arg_type) == 1 |
2335 | && TYPE_CODE (TYPE_FIELD_TYPE (arg_type, 0)) == TYPE_CODE_FLT)) | |
c86b5b38 | 2336 | && MIPS_FPU_TYPE != MIPS_FPU_NONE); |
f09ded24 AC |
2337 | } |
2338 | ||
49e790b0 DJ |
2339 | /* On o32, argument passing in GPRs depends on the alignment of the type being |
2340 | passed. Return 1 if this type must be aligned to a doubleword boundary. */ | |
2341 | ||
2342 | static int | |
2343 | mips_type_needs_double_align (struct type *type) | |
2344 | { | |
2345 | enum type_code typecode = TYPE_CODE (type); | |
361d1df0 | 2346 | |
49e790b0 DJ |
2347 | if (typecode == TYPE_CODE_FLT && TYPE_LENGTH (type) == 8) |
2348 | return 1; | |
2349 | else if (typecode == TYPE_CODE_STRUCT) | |
2350 | { | |
2351 | if (TYPE_NFIELDS (type) < 1) | |
2352 | return 0; | |
2353 | return mips_type_needs_double_align (TYPE_FIELD_TYPE (type, 0)); | |
2354 | } | |
2355 | else if (typecode == TYPE_CODE_UNION) | |
2356 | { | |
361d1df0 | 2357 | int i, n; |
49e790b0 DJ |
2358 | |
2359 | n = TYPE_NFIELDS (type); | |
2360 | for (i = 0; i < n; i++) | |
2361 | if (mips_type_needs_double_align (TYPE_FIELD_TYPE (type, i))) | |
2362 | return 1; | |
2363 | return 0; | |
2364 | } | |
2365 | return 0; | |
2366 | } | |
2367 | ||
dc604539 AC |
2368 | /* Adjust the address downward (direction of stack growth) so that it |
2369 | is correctly aligned for a new stack frame. */ | |
2370 | static CORE_ADDR | |
2371 | mips_frame_align (struct gdbarch *gdbarch, CORE_ADDR addr) | |
2372 | { | |
5b03f266 | 2373 | return align_down (addr, 16); |
dc604539 AC |
2374 | } |
2375 | ||
f7ab6ec6 | 2376 | static CORE_ADDR |
7d9b040b | 2377 | mips_eabi_push_dummy_call (struct gdbarch *gdbarch, struct value *function, |
6d82d43b AC |
2378 | struct regcache *regcache, CORE_ADDR bp_addr, |
2379 | int nargs, struct value **args, CORE_ADDR sp, | |
2380 | int struct_return, CORE_ADDR struct_addr) | |
c906108c SS |
2381 | { |
2382 | int argreg; | |
2383 | int float_argreg; | |
2384 | int argnum; | |
2385 | int len = 0; | |
2386 | int stack_offset = 0; | |
480d3dd2 | 2387 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
7d9b040b | 2388 | CORE_ADDR func_addr = find_function_addr (function, NULL); |
c906108c | 2389 | |
25ab4790 AC |
2390 | /* For shared libraries, "t9" needs to point at the function |
2391 | address. */ | |
4c7d22cb | 2392 | regcache_cooked_write_signed (regcache, MIPS_T9_REGNUM, func_addr); |
25ab4790 AC |
2393 | |
2394 | /* Set the return address register to point to the entry point of | |
2395 | the program, where a breakpoint lies in wait. */ | |
4c7d22cb | 2396 | regcache_cooked_write_signed (regcache, MIPS_RA_REGNUM, bp_addr); |
25ab4790 | 2397 | |
c906108c | 2398 | /* First ensure that the stack and structure return address (if any) |
cb3d25d1 MS |
2399 | are properly aligned. The stack has to be at least 64-bit |
2400 | aligned even on 32-bit machines, because doubles must be 64-bit | |
2401 | aligned. For n32 and n64, stack frames need to be 128-bit | |
2402 | aligned, so we round to this widest known alignment. */ | |
2403 | ||
5b03f266 AC |
2404 | sp = align_down (sp, 16); |
2405 | struct_addr = align_down (struct_addr, 16); | |
c5aa993b | 2406 | |
46e0f506 | 2407 | /* Now make space on the stack for the args. We allocate more |
c906108c | 2408 | than necessary for EABI, because the first few arguments are |
46e0f506 | 2409 | passed in registers, but that's OK. */ |
c906108c | 2410 | for (argnum = 0; argnum < nargs; argnum++) |
6d82d43b | 2411 | len += align_up (TYPE_LENGTH (VALUE_TYPE (args[argnum])), |
13326b4e | 2412 | mips_stack_argsize (gdbarch)); |
5b03f266 | 2413 | sp -= align_up (len, 16); |
c906108c | 2414 | |
9ace0497 | 2415 | if (mips_debug) |
6d82d43b | 2416 | fprintf_unfiltered (gdb_stdlog, |
5b03f266 AC |
2417 | "mips_eabi_push_dummy_call: sp=0x%s allocated %ld\n", |
2418 | paddr_nz (sp), (long) align_up (len, 16)); | |
9ace0497 | 2419 | |
c906108c | 2420 | /* Initialize the integer and float register pointers. */ |
4c7d22cb | 2421 | argreg = MIPS_A0_REGNUM; |
56cea623 | 2422 | float_argreg = mips_fpa0_regnum (current_gdbarch); |
c906108c | 2423 | |
46e0f506 | 2424 | /* The struct_return pointer occupies the first parameter-passing reg. */ |
c906108c | 2425 | if (struct_return) |
9ace0497 AC |
2426 | { |
2427 | if (mips_debug) | |
2428 | fprintf_unfiltered (gdb_stdlog, | |
25ab4790 | 2429 | "mips_eabi_push_dummy_call: struct_return reg=%d 0x%s\n", |
cb3d25d1 | 2430 | argreg, paddr_nz (struct_addr)); |
9ace0497 AC |
2431 | write_register (argreg++, struct_addr); |
2432 | } | |
c906108c SS |
2433 | |
2434 | /* Now load as many as possible of the first arguments into | |
2435 | registers, and push the rest onto the stack. Loop thru args | |
2436 | from first to last. */ | |
2437 | for (argnum = 0; argnum < nargs; argnum++) | |
2438 | { | |
2439 | char *val; | |
d9d9c31f | 2440 | char valbuf[MAX_REGISTER_SIZE]; |
ea7c478f | 2441 | struct value *arg = args[argnum]; |
c906108c SS |
2442 | struct type *arg_type = check_typedef (VALUE_TYPE (arg)); |
2443 | int len = TYPE_LENGTH (arg_type); | |
2444 | enum type_code typecode = TYPE_CODE (arg_type); | |
2445 | ||
9ace0497 AC |
2446 | if (mips_debug) |
2447 | fprintf_unfiltered (gdb_stdlog, | |
25ab4790 | 2448 | "mips_eabi_push_dummy_call: %d len=%d type=%d", |
acdb74a0 | 2449 | argnum + 1, len, (int) typecode); |
9ace0497 | 2450 | |
c906108c | 2451 | /* The EABI passes structures that do not fit in a register by |
46e0f506 | 2452 | reference. */ |
13326b4e | 2453 | if (len > mips_abi_regsize (gdbarch) |
9ace0497 | 2454 | && (typecode == TYPE_CODE_STRUCT || typecode == TYPE_CODE_UNION)) |
c906108c | 2455 | { |
13326b4e | 2456 | store_unsigned_integer (valbuf, mips_abi_regsize (gdbarch), |
480d3dd2 | 2457 | VALUE_ADDRESS (arg)); |
c906108c | 2458 | typecode = TYPE_CODE_PTR; |
13326b4e | 2459 | len = mips_abi_regsize (gdbarch); |
c906108c | 2460 | val = valbuf; |
9ace0497 AC |
2461 | if (mips_debug) |
2462 | fprintf_unfiltered (gdb_stdlog, " push"); | |
c906108c SS |
2463 | } |
2464 | else | |
c5aa993b | 2465 | val = (char *) VALUE_CONTENTS (arg); |
c906108c SS |
2466 | |
2467 | /* 32-bit ABIs always start floating point arguments in an | |
acdb74a0 AC |
2468 | even-numbered floating point register. Round the FP register |
2469 | up before the check to see if there are any FP registers | |
46e0f506 MS |
2470 | left. Non MIPS_EABI targets also pass the FP in the integer |
2471 | registers so also round up normal registers. */ | |
ceae6e75 AC |
2472 | if (mips_abi_regsize (gdbarch) < 8 |
2473 | && fp_register_arg_p (typecode, arg_type)) | |
acdb74a0 AC |
2474 | { |
2475 | if ((float_argreg & 1)) | |
2476 | float_argreg++; | |
2477 | } | |
c906108c SS |
2478 | |
2479 | /* Floating point arguments passed in registers have to be | |
2480 | treated specially. On 32-bit architectures, doubles | |
c5aa993b JM |
2481 | are passed in register pairs; the even register gets |
2482 | the low word, and the odd register gets the high word. | |
2483 | On non-EABI processors, the first two floating point arguments are | |
2484 | also copied to general registers, because MIPS16 functions | |
2485 | don't use float registers for arguments. This duplication of | |
2486 | arguments in general registers can't hurt non-MIPS16 functions | |
2487 | because those registers are normally skipped. */ | |
1012bd0e EZ |
2488 | /* MIPS_EABI squeezes a struct that contains a single floating |
2489 | point value into an FP register instead of pushing it onto the | |
46e0f506 | 2490 | stack. */ |
f09ded24 AC |
2491 | if (fp_register_arg_p (typecode, arg_type) |
2492 | && float_argreg <= MIPS_LAST_FP_ARG_REGNUM) | |
c906108c | 2493 | { |
ceae6e75 | 2494 | if (mips_abi_regsize (gdbarch) < 8 && len == 8) |
c906108c | 2495 | { |
d7449b42 | 2496 | int low_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 4 : 0; |
c906108c SS |
2497 | unsigned long regval; |
2498 | ||
2499 | /* Write the low word of the double to the even register(s). */ | |
c5aa993b | 2500 | regval = extract_unsigned_integer (val + low_offset, 4); |
9ace0497 | 2501 | if (mips_debug) |
acdb74a0 | 2502 | fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s", |
9ace0497 | 2503 | float_argreg, phex (regval, 4)); |
c906108c | 2504 | write_register (float_argreg++, regval); |
c906108c SS |
2505 | |
2506 | /* Write the high word of the double to the odd register(s). */ | |
c5aa993b | 2507 | regval = extract_unsigned_integer (val + 4 - low_offset, 4); |
9ace0497 | 2508 | if (mips_debug) |
acdb74a0 | 2509 | fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s", |
9ace0497 | 2510 | float_argreg, phex (regval, 4)); |
c906108c | 2511 | write_register (float_argreg++, regval); |
c906108c SS |
2512 | } |
2513 | else | |
2514 | { | |
2515 | /* This is a floating point value that fits entirely | |
2516 | in a single register. */ | |
53a5351d | 2517 | /* On 32 bit ABI's the float_argreg is further adjusted |
6d82d43b | 2518 | above to ensure that it is even register aligned. */ |
9ace0497 AC |
2519 | LONGEST regval = extract_unsigned_integer (val, len); |
2520 | if (mips_debug) | |
acdb74a0 | 2521 | fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s", |
9ace0497 | 2522 | float_argreg, phex (regval, len)); |
c906108c | 2523 | write_register (float_argreg++, regval); |
c906108c SS |
2524 | } |
2525 | } | |
2526 | else | |
2527 | { | |
2528 | /* Copy the argument to general registers or the stack in | |
2529 | register-sized pieces. Large arguments are split between | |
2530 | registers and stack. */ | |
4246e332 | 2531 | /* Note: structs whose size is not a multiple of |
d5ac5a39 AC |
2532 | mips_abi_regsize() are treated specially: Irix cc passes |
2533 | them in registers where gcc sometimes puts them on the | |
2534 | stack. For maximum compatibility, we will put them in | |
2535 | both places. */ | |
13326b4e AC |
2536 | int odd_sized_struct = ((len > mips_abi_regsize (gdbarch)) |
2537 | && (len % mips_abi_regsize (gdbarch) != 0)); | |
46e0f506 | 2538 | |
f09ded24 | 2539 | /* Note: Floating-point values that didn't fit into an FP |
6d82d43b | 2540 | register are only written to memory. */ |
c906108c SS |
2541 | while (len > 0) |
2542 | { | |
ebafbe83 | 2543 | /* Remember if the argument was written to the stack. */ |
566f0f7a | 2544 | int stack_used_p = 0; |
13326b4e AC |
2545 | int partial_len = (len < mips_abi_regsize (gdbarch) |
2546 | ? len : mips_abi_regsize (gdbarch)); | |
c906108c | 2547 | |
acdb74a0 AC |
2548 | if (mips_debug) |
2549 | fprintf_unfiltered (gdb_stdlog, " -- partial=%d", | |
2550 | partial_len); | |
2551 | ||
566f0f7a | 2552 | /* Write this portion of the argument to the stack. */ |
f09ded24 AC |
2553 | if (argreg > MIPS_LAST_ARG_REGNUM |
2554 | || odd_sized_struct | |
2555 | || fp_register_arg_p (typecode, arg_type)) | |
c906108c | 2556 | { |
c906108c SS |
2557 | /* Should shorter than int integer values be |
2558 | promoted to int before being stored? */ | |
c906108c | 2559 | int longword_offset = 0; |
9ace0497 | 2560 | CORE_ADDR addr; |
566f0f7a | 2561 | stack_used_p = 1; |
d7449b42 | 2562 | if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) |
7a292a7a | 2563 | { |
13326b4e | 2564 | if (mips_stack_argsize (gdbarch) == 8 |
480d3dd2 AC |
2565 | && (typecode == TYPE_CODE_INT |
2566 | || typecode == TYPE_CODE_PTR | |
6d82d43b | 2567 | || typecode == TYPE_CODE_FLT) && len <= 4) |
13326b4e | 2568 | longword_offset = mips_stack_argsize (gdbarch) - len; |
480d3dd2 AC |
2569 | else if ((typecode == TYPE_CODE_STRUCT |
2570 | || typecode == TYPE_CODE_UNION) | |
2571 | && (TYPE_LENGTH (arg_type) | |
13326b4e AC |
2572 | < mips_stack_argsize (gdbarch))) |
2573 | longword_offset = mips_stack_argsize (gdbarch) - len; | |
7a292a7a | 2574 | } |
c5aa993b | 2575 | |
9ace0497 AC |
2576 | if (mips_debug) |
2577 | { | |
cb3d25d1 MS |
2578 | fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s", |
2579 | paddr_nz (stack_offset)); | |
2580 | fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s", | |
2581 | paddr_nz (longword_offset)); | |
9ace0497 | 2582 | } |
361d1df0 | 2583 | |
9ace0497 AC |
2584 | addr = sp + stack_offset + longword_offset; |
2585 | ||
2586 | if (mips_debug) | |
2587 | { | |
2588 | int i; | |
6d82d43b | 2589 | fprintf_unfiltered (gdb_stdlog, " @0x%s ", |
cb3d25d1 | 2590 | paddr_nz (addr)); |
9ace0497 AC |
2591 | for (i = 0; i < partial_len; i++) |
2592 | { | |
6d82d43b | 2593 | fprintf_unfiltered (gdb_stdlog, "%02x", |
cb3d25d1 | 2594 | val[i] & 0xff); |
9ace0497 AC |
2595 | } |
2596 | } | |
2597 | write_memory (addr, val, partial_len); | |
c906108c SS |
2598 | } |
2599 | ||
f09ded24 AC |
2600 | /* Note!!! This is NOT an else clause. Odd sized |
2601 | structs may go thru BOTH paths. Floating point | |
46e0f506 | 2602 | arguments will not. */ |
566f0f7a | 2603 | /* Write this portion of the argument to a general |
6d82d43b | 2604 | purpose register. */ |
f09ded24 AC |
2605 | if (argreg <= MIPS_LAST_ARG_REGNUM |
2606 | && !fp_register_arg_p (typecode, arg_type)) | |
c906108c | 2607 | { |
6d82d43b AC |
2608 | LONGEST regval = |
2609 | extract_unsigned_integer (val, partial_len); | |
c906108c | 2610 | |
9ace0497 | 2611 | if (mips_debug) |
acdb74a0 | 2612 | fprintf_filtered (gdb_stdlog, " - reg=%d val=%s", |
9ace0497 | 2613 | argreg, |
6d82d43b | 2614 | phex (regval, |
13326b4e | 2615 | mips_abi_regsize (gdbarch))); |
c906108c SS |
2616 | write_register (argreg, regval); |
2617 | argreg++; | |
c906108c | 2618 | } |
c5aa993b | 2619 | |
c906108c SS |
2620 | len -= partial_len; |
2621 | val += partial_len; | |
2622 | ||
566f0f7a | 2623 | /* Compute the the offset into the stack at which we |
6d82d43b | 2624 | will copy the next parameter. |
566f0f7a | 2625 | |
566f0f7a | 2626 | In the new EABI (and the NABI32), the stack_offset |
46e0f506 | 2627 | only needs to be adjusted when it has been used. */ |
c906108c | 2628 | |
46e0f506 | 2629 | if (stack_used_p) |
480d3dd2 | 2630 | stack_offset += align_up (partial_len, |
13326b4e | 2631 | mips_stack_argsize (gdbarch)); |
c906108c SS |
2632 | } |
2633 | } | |
9ace0497 AC |
2634 | if (mips_debug) |
2635 | fprintf_unfiltered (gdb_stdlog, "\n"); | |
c906108c SS |
2636 | } |
2637 | ||
f10683bb | 2638 | regcache_cooked_write_signed (regcache, MIPS_SP_REGNUM, sp); |
310e9b6a | 2639 | |
0f71a2f6 JM |
2640 | /* Return adjusted stack pointer. */ |
2641 | return sp; | |
2642 | } | |
2643 | ||
9c8fdbfa | 2644 | /* Determin the return value convention being used. */ |
6d82d43b | 2645 | |
9c8fdbfa AC |
2646 | static enum return_value_convention |
2647 | mips_eabi_return_value (struct gdbarch *gdbarch, | |
2648 | struct type *type, struct regcache *regcache, | |
2649 | void *readbuf, const void *writebuf) | |
6d82d43b | 2650 | { |
9c8fdbfa AC |
2651 | if (TYPE_LENGTH (type) > 2 * mips_abi_regsize (gdbarch)) |
2652 | return RETURN_VALUE_STRUCT_CONVENTION; | |
2653 | if (readbuf) | |
2654 | memset (readbuf, 0, TYPE_LENGTH (type)); | |
2655 | return RETURN_VALUE_REGISTER_CONVENTION; | |
6d82d43b AC |
2656 | } |
2657 | ||
6d82d43b AC |
2658 | |
2659 | /* N32/N64 ABI stuff. */ | |
ebafbe83 | 2660 | |
f7ab6ec6 | 2661 | static CORE_ADDR |
7d9b040b | 2662 | mips_n32n64_push_dummy_call (struct gdbarch *gdbarch, struct value *function, |
6d82d43b AC |
2663 | struct regcache *regcache, CORE_ADDR bp_addr, |
2664 | int nargs, struct value **args, CORE_ADDR sp, | |
2665 | int struct_return, CORE_ADDR struct_addr) | |
cb3d25d1 MS |
2666 | { |
2667 | int argreg; | |
2668 | int float_argreg; | |
2669 | int argnum; | |
2670 | int len = 0; | |
2671 | int stack_offset = 0; | |
480d3dd2 | 2672 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
7d9b040b | 2673 | CORE_ADDR func_addr = find_function_addr (function, NULL); |
cb3d25d1 | 2674 | |
25ab4790 AC |
2675 | /* For shared libraries, "t9" needs to point at the function |
2676 | address. */ | |
4c7d22cb | 2677 | regcache_cooked_write_signed (regcache, MIPS_T9_REGNUM, func_addr); |
25ab4790 AC |
2678 | |
2679 | /* Set the return address register to point to the entry point of | |
2680 | the program, where a breakpoint lies in wait. */ | |
4c7d22cb | 2681 | regcache_cooked_write_signed (regcache, MIPS_RA_REGNUM, bp_addr); |
25ab4790 | 2682 | |
cb3d25d1 MS |
2683 | /* First ensure that the stack and structure return address (if any) |
2684 | are properly aligned. The stack has to be at least 64-bit | |
2685 | aligned even on 32-bit machines, because doubles must be 64-bit | |
2686 | aligned. For n32 and n64, stack frames need to be 128-bit | |
2687 | aligned, so we round to this widest known alignment. */ | |
2688 | ||
5b03f266 AC |
2689 | sp = align_down (sp, 16); |
2690 | struct_addr = align_down (struct_addr, 16); | |
cb3d25d1 MS |
2691 | |
2692 | /* Now make space on the stack for the args. */ | |
2693 | for (argnum = 0; argnum < nargs; argnum++) | |
6d82d43b | 2694 | len += align_up (TYPE_LENGTH (VALUE_TYPE (args[argnum])), |
13326b4e | 2695 | mips_stack_argsize (gdbarch)); |
5b03f266 | 2696 | sp -= align_up (len, 16); |
cb3d25d1 MS |
2697 | |
2698 | if (mips_debug) | |
6d82d43b | 2699 | fprintf_unfiltered (gdb_stdlog, |
5b03f266 AC |
2700 | "mips_n32n64_push_dummy_call: sp=0x%s allocated %ld\n", |
2701 | paddr_nz (sp), (long) align_up (len, 16)); | |
cb3d25d1 MS |
2702 | |
2703 | /* Initialize the integer and float register pointers. */ | |
4c7d22cb | 2704 | argreg = MIPS_A0_REGNUM; |
56cea623 | 2705 | float_argreg = mips_fpa0_regnum (current_gdbarch); |
cb3d25d1 | 2706 | |
46e0f506 | 2707 | /* The struct_return pointer occupies the first parameter-passing reg. */ |
cb3d25d1 MS |
2708 | if (struct_return) |
2709 | { | |
2710 | if (mips_debug) | |
2711 | fprintf_unfiltered (gdb_stdlog, | |
25ab4790 | 2712 | "mips_n32n64_push_dummy_call: struct_return reg=%d 0x%s\n", |
cb3d25d1 MS |
2713 | argreg, paddr_nz (struct_addr)); |
2714 | write_register (argreg++, struct_addr); | |
2715 | } | |
2716 | ||
2717 | /* Now load as many as possible of the first arguments into | |
2718 | registers, and push the rest onto the stack. Loop thru args | |
2719 | from first to last. */ | |
2720 | for (argnum = 0; argnum < nargs; argnum++) | |
2721 | { | |
2722 | char *val; | |
cb3d25d1 MS |
2723 | struct value *arg = args[argnum]; |
2724 | struct type *arg_type = check_typedef (VALUE_TYPE (arg)); | |
2725 | int len = TYPE_LENGTH (arg_type); | |
2726 | enum type_code typecode = TYPE_CODE (arg_type); | |
2727 | ||
2728 | if (mips_debug) | |
2729 | fprintf_unfiltered (gdb_stdlog, | |
25ab4790 | 2730 | "mips_n32n64_push_dummy_call: %d len=%d type=%d", |
cb3d25d1 MS |
2731 | argnum + 1, len, (int) typecode); |
2732 | ||
2733 | val = (char *) VALUE_CONTENTS (arg); | |
2734 | ||
2735 | if (fp_register_arg_p (typecode, arg_type) | |
2736 | && float_argreg <= MIPS_LAST_FP_ARG_REGNUM) | |
2737 | { | |
2738 | /* This is a floating point value that fits entirely | |
2739 | in a single register. */ | |
2740 | /* On 32 bit ABI's the float_argreg is further adjusted | |
2741 | above to ensure that it is even register aligned. */ | |
2742 | LONGEST regval = extract_unsigned_integer (val, len); | |
2743 | if (mips_debug) | |
2744 | fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s", | |
2745 | float_argreg, phex (regval, len)); | |
2746 | write_register (float_argreg++, regval); | |
2747 | ||
2748 | if (mips_debug) | |
2749 | fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s", | |
2750 | argreg, phex (regval, len)); | |
2751 | write_register (argreg, regval); | |
2752 | argreg += 1; | |
2753 | } | |
2754 | else | |
2755 | { | |
2756 | /* Copy the argument to general registers or the stack in | |
2757 | register-sized pieces. Large arguments are split between | |
2758 | registers and stack. */ | |
4246e332 | 2759 | /* Note: structs whose size is not a multiple of |
d5ac5a39 AC |
2760 | mips_abi_regsize() are treated specially: Irix cc passes |
2761 | them in registers where gcc sometimes puts them on the | |
2762 | stack. For maximum compatibility, we will put them in | |
2763 | both places. */ | |
13326b4e AC |
2764 | int odd_sized_struct = ((len > mips_abi_regsize (gdbarch)) |
2765 | && (len % mips_abi_regsize (gdbarch) != 0)); | |
cb3d25d1 | 2766 | /* Note: Floating-point values that didn't fit into an FP |
6d82d43b | 2767 | register are only written to memory. */ |
cb3d25d1 MS |
2768 | while (len > 0) |
2769 | { | |
2770 | /* Rememer if the argument was written to the stack. */ | |
2771 | int stack_used_p = 0; | |
13326b4e AC |
2772 | int partial_len = (len < mips_abi_regsize (gdbarch) |
2773 | ? len : mips_abi_regsize (gdbarch)); | |
cb3d25d1 MS |
2774 | |
2775 | if (mips_debug) | |
2776 | fprintf_unfiltered (gdb_stdlog, " -- partial=%d", | |
2777 | partial_len); | |
2778 | ||
2779 | /* Write this portion of the argument to the stack. */ | |
2780 | if (argreg > MIPS_LAST_ARG_REGNUM | |
2781 | || odd_sized_struct | |
2782 | || fp_register_arg_p (typecode, arg_type)) | |
2783 | { | |
2784 | /* Should shorter than int integer values be | |
2785 | promoted to int before being stored? */ | |
2786 | int longword_offset = 0; | |
2787 | CORE_ADDR addr; | |
2788 | stack_used_p = 1; | |
2789 | if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) | |
2790 | { | |
13326b4e | 2791 | if (mips_stack_argsize (gdbarch) == 8 |
480d3dd2 AC |
2792 | && (typecode == TYPE_CODE_INT |
2793 | || typecode == TYPE_CODE_PTR | |
6d82d43b | 2794 | || typecode == TYPE_CODE_FLT) && len <= 4) |
13326b4e | 2795 | longword_offset = mips_stack_argsize (gdbarch) - len; |
cb3d25d1 MS |
2796 | } |
2797 | ||
2798 | if (mips_debug) | |
2799 | { | |
2800 | fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s", | |
2801 | paddr_nz (stack_offset)); | |
2802 | fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s", | |
2803 | paddr_nz (longword_offset)); | |
2804 | } | |
2805 | ||
2806 | addr = sp + stack_offset + longword_offset; | |
2807 | ||
2808 | if (mips_debug) | |
2809 | { | |
2810 | int i; | |
6d82d43b | 2811 | fprintf_unfiltered (gdb_stdlog, " @0x%s ", |
cb3d25d1 MS |
2812 | paddr_nz (addr)); |
2813 | for (i = 0; i < partial_len; i++) | |
2814 | { | |
6d82d43b | 2815 | fprintf_unfiltered (gdb_stdlog, "%02x", |
cb3d25d1 MS |
2816 | val[i] & 0xff); |
2817 | } | |
2818 | } | |
2819 | write_memory (addr, val, partial_len); | |
2820 | } | |
2821 | ||
2822 | /* Note!!! This is NOT an else clause. Odd sized | |
2823 | structs may go thru BOTH paths. Floating point | |
2824 | arguments will not. */ | |
2825 | /* Write this portion of the argument to a general | |
6d82d43b | 2826 | purpose register. */ |
cb3d25d1 MS |
2827 | if (argreg <= MIPS_LAST_ARG_REGNUM |
2828 | && !fp_register_arg_p (typecode, arg_type)) | |
2829 | { | |
6d82d43b AC |
2830 | LONGEST regval = |
2831 | extract_unsigned_integer (val, partial_len); | |
cb3d25d1 MS |
2832 | |
2833 | /* A non-floating-point argument being passed in a | |
2834 | general register. If a struct or union, and if | |
2835 | the remaining length is smaller than the register | |
2836 | size, we have to adjust the register value on | |
2837 | big endian targets. | |
2838 | ||
2839 | It does not seem to be necessary to do the | |
2840 | same for integral types. | |
2841 | ||
2842 | cagney/2001-07-23: gdb/179: Also, GCC, when | |
2843 | outputting LE O32 with sizeof (struct) < | |
1b13c4f6 | 2844 | mips_abi_regsize(), generates a left shift as |
cb3d25d1 MS |
2845 | part of storing the argument in a register a |
2846 | register (the left shift isn't generated when | |
1b13c4f6 | 2847 | sizeof (struct) >= mips_abi_regsize()). Since |
480d3dd2 AC |
2848 | it is quite possible that this is GCC |
2849 | contradicting the LE/O32 ABI, GDB has not been | |
2850 | adjusted to accommodate this. Either someone | |
2851 | needs to demonstrate that the LE/O32 ABI | |
2852 | specifies such a left shift OR this new ABI gets | |
2853 | identified as such and GDB gets tweaked | |
2854 | accordingly. */ | |
cb3d25d1 MS |
2855 | |
2856 | if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG | |
13326b4e | 2857 | && partial_len < mips_abi_regsize (gdbarch) |
cb3d25d1 MS |
2858 | && (typecode == TYPE_CODE_STRUCT || |
2859 | typecode == TYPE_CODE_UNION)) | |
13326b4e | 2860 | regval <<= ((mips_abi_regsize (gdbarch) - partial_len) * |
cb3d25d1 MS |
2861 | TARGET_CHAR_BIT); |
2862 | ||
2863 | if (mips_debug) | |
2864 | fprintf_filtered (gdb_stdlog, " - reg=%d val=%s", | |
2865 | argreg, | |
6d82d43b | 2866 | phex (regval, |
13326b4e | 2867 | mips_abi_regsize (gdbarch))); |
cb3d25d1 MS |
2868 | write_register (argreg, regval); |
2869 | argreg++; | |
2870 | } | |
2871 | ||
2872 | len -= partial_len; | |
2873 | val += partial_len; | |
2874 | ||
2875 | /* Compute the the offset into the stack at which we | |
6d82d43b | 2876 | will copy the next parameter. |
cb3d25d1 MS |
2877 | |
2878 | In N32 (N64?), the stack_offset only needs to be | |
2879 | adjusted when it has been used. */ | |
2880 | ||
2881 | if (stack_used_p) | |
480d3dd2 | 2882 | stack_offset += align_up (partial_len, |
13326b4e | 2883 | mips_stack_argsize (gdbarch)); |
cb3d25d1 MS |
2884 | } |
2885 | } | |
2886 | if (mips_debug) | |
2887 | fprintf_unfiltered (gdb_stdlog, "\n"); | |
2888 | } | |
2889 | ||
f10683bb | 2890 | regcache_cooked_write_signed (regcache, MIPS_SP_REGNUM, sp); |
310e9b6a | 2891 | |
cb3d25d1 MS |
2892 | /* Return adjusted stack pointer. */ |
2893 | return sp; | |
2894 | } | |
2895 | ||
6d82d43b AC |
2896 | static enum return_value_convention |
2897 | mips_n32n64_return_value (struct gdbarch *gdbarch, | |
2898 | struct type *type, struct regcache *regcache, | |
2899 | void *readbuf, const void *writebuf) | |
ebafbe83 | 2900 | { |
6d82d43b AC |
2901 | struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); |
2902 | if (TYPE_CODE (type) == TYPE_CODE_STRUCT | |
2903 | || TYPE_CODE (type) == TYPE_CODE_UNION | |
2904 | || TYPE_CODE (type) == TYPE_CODE_ARRAY | |
13326b4e | 2905 | || TYPE_LENGTH (type) > 2 * mips_abi_regsize (gdbarch)) |
6d82d43b AC |
2906 | return RETURN_VALUE_STRUCT_CONVENTION; |
2907 | else if (TYPE_CODE (type) == TYPE_CODE_FLT | |
2908 | && tdep->mips_fpu_type != MIPS_FPU_NONE) | |
2909 | { | |
2910 | /* A floating-point value belongs in the least significant part | |
2911 | of FP0. */ | |
2912 | if (mips_debug) | |
2913 | fprintf_unfiltered (gdb_stderr, "Return float in $fp0\n"); | |
2914 | mips_xfer_register (regcache, | |
2915 | NUM_REGS + mips_regnum (current_gdbarch)->fp0, | |
2916 | TYPE_LENGTH (type), | |
2917 | TARGET_BYTE_ORDER, readbuf, writebuf, 0); | |
2918 | return RETURN_VALUE_REGISTER_CONVENTION; | |
2919 | } | |
2920 | else if (TYPE_CODE (type) == TYPE_CODE_STRUCT | |
2921 | && TYPE_NFIELDS (type) <= 2 | |
2922 | && TYPE_NFIELDS (type) >= 1 | |
2923 | && ((TYPE_NFIELDS (type) == 1 | |
2924 | && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) | |
2925 | == TYPE_CODE_FLT)) | |
2926 | || (TYPE_NFIELDS (type) == 2 | |
2927 | && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) | |
2928 | == TYPE_CODE_FLT) | |
2929 | && (TYPE_CODE (TYPE_FIELD_TYPE (type, 1)) | |
2930 | == TYPE_CODE_FLT))) | |
2931 | && tdep->mips_fpu_type != MIPS_FPU_NONE) | |
2932 | { | |
2933 | /* A struct that contains one or two floats. Each value is part | |
2934 | in the least significant part of their floating point | |
2935 | register.. */ | |
6d82d43b AC |
2936 | int regnum; |
2937 | int field; | |
2938 | for (field = 0, regnum = mips_regnum (current_gdbarch)->fp0; | |
2939 | field < TYPE_NFIELDS (type); field++, regnum += 2) | |
2940 | { | |
2941 | int offset = (FIELD_BITPOS (TYPE_FIELDS (type)[field]) | |
2942 | / TARGET_CHAR_BIT); | |
2943 | if (mips_debug) | |
2944 | fprintf_unfiltered (gdb_stderr, "Return float struct+%d\n", | |
2945 | offset); | |
2946 | mips_xfer_register (regcache, NUM_REGS + regnum, | |
2947 | TYPE_LENGTH (TYPE_FIELD_TYPE (type, field)), | |
2948 | TARGET_BYTE_ORDER, readbuf, writebuf, offset); | |
2949 | } | |
2950 | return RETURN_VALUE_REGISTER_CONVENTION; | |
2951 | } | |
2952 | else if (TYPE_CODE (type) == TYPE_CODE_STRUCT | |
2953 | || TYPE_CODE (type) == TYPE_CODE_UNION) | |
2954 | { | |
2955 | /* A structure or union. Extract the left justified value, | |
2956 | regardless of the byte order. I.e. DO NOT USE | |
2957 | mips_xfer_lower. */ | |
2958 | int offset; | |
2959 | int regnum; | |
4c7d22cb | 2960 | for (offset = 0, regnum = MIPS_V0_REGNUM; |
6d82d43b AC |
2961 | offset < TYPE_LENGTH (type); |
2962 | offset += register_size (current_gdbarch, regnum), regnum++) | |
2963 | { | |
2964 | int xfer = register_size (current_gdbarch, regnum); | |
2965 | if (offset + xfer > TYPE_LENGTH (type)) | |
2966 | xfer = TYPE_LENGTH (type) - offset; | |
2967 | if (mips_debug) | |
2968 | fprintf_unfiltered (gdb_stderr, "Return struct+%d:%d in $%d\n", | |
2969 | offset, xfer, regnum); | |
2970 | mips_xfer_register (regcache, NUM_REGS + regnum, xfer, | |
2971 | BFD_ENDIAN_UNKNOWN, readbuf, writebuf, offset); | |
2972 | } | |
2973 | return RETURN_VALUE_REGISTER_CONVENTION; | |
2974 | } | |
2975 | else | |
2976 | { | |
2977 | /* A scalar extract each part but least-significant-byte | |
2978 | justified. */ | |
2979 | int offset; | |
2980 | int regnum; | |
4c7d22cb | 2981 | for (offset = 0, regnum = MIPS_V0_REGNUM; |
6d82d43b AC |
2982 | offset < TYPE_LENGTH (type); |
2983 | offset += register_size (current_gdbarch, regnum), regnum++) | |
2984 | { | |
2985 | int xfer = register_size (current_gdbarch, regnum); | |
6d82d43b AC |
2986 | if (offset + xfer > TYPE_LENGTH (type)) |
2987 | xfer = TYPE_LENGTH (type) - offset; | |
2988 | if (mips_debug) | |
2989 | fprintf_unfiltered (gdb_stderr, "Return scalar+%d:%d in $%d\n", | |
2990 | offset, xfer, regnum); | |
2991 | mips_xfer_register (regcache, NUM_REGS + regnum, xfer, | |
2992 | TARGET_BYTE_ORDER, readbuf, writebuf, offset); | |
2993 | } | |
2994 | return RETURN_VALUE_REGISTER_CONVENTION; | |
2995 | } | |
2996 | } | |
2997 | ||
2998 | /* O32 ABI stuff. */ | |
2999 | ||
3000 | static CORE_ADDR | |
7d9b040b | 3001 | mips_o32_push_dummy_call (struct gdbarch *gdbarch, struct value *function, |
6d82d43b AC |
3002 | struct regcache *regcache, CORE_ADDR bp_addr, |
3003 | int nargs, struct value **args, CORE_ADDR sp, | |
3004 | int struct_return, CORE_ADDR struct_addr) | |
3005 | { | |
3006 | int argreg; | |
3007 | int float_argreg; | |
3008 | int argnum; | |
3009 | int len = 0; | |
3010 | int stack_offset = 0; | |
3011 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
7d9b040b | 3012 | CORE_ADDR func_addr = find_function_addr (function, NULL); |
6d82d43b AC |
3013 | |
3014 | /* For shared libraries, "t9" needs to point at the function | |
3015 | address. */ | |
4c7d22cb | 3016 | regcache_cooked_write_signed (regcache, MIPS_T9_REGNUM, func_addr); |
6d82d43b AC |
3017 | |
3018 | /* Set the return address register to point to the entry point of | |
3019 | the program, where a breakpoint lies in wait. */ | |
4c7d22cb | 3020 | regcache_cooked_write_signed (regcache, MIPS_RA_REGNUM, bp_addr); |
6d82d43b AC |
3021 | |
3022 | /* First ensure that the stack and structure return address (if any) | |
3023 | are properly aligned. The stack has to be at least 64-bit | |
3024 | aligned even on 32-bit machines, because doubles must be 64-bit | |
ebafbe83 MS |
3025 | aligned. For n32 and n64, stack frames need to be 128-bit |
3026 | aligned, so we round to this widest known alignment. */ | |
3027 | ||
5b03f266 AC |
3028 | sp = align_down (sp, 16); |
3029 | struct_addr = align_down (struct_addr, 16); | |
ebafbe83 MS |
3030 | |
3031 | /* Now make space on the stack for the args. */ | |
3032 | for (argnum = 0; argnum < nargs; argnum++) | |
6d82d43b | 3033 | len += align_up (TYPE_LENGTH (VALUE_TYPE (args[argnum])), |
13326b4e | 3034 | mips_stack_argsize (gdbarch)); |
5b03f266 | 3035 | sp -= align_up (len, 16); |
ebafbe83 MS |
3036 | |
3037 | if (mips_debug) | |
6d82d43b | 3038 | fprintf_unfiltered (gdb_stdlog, |
5b03f266 AC |
3039 | "mips_o32_push_dummy_call: sp=0x%s allocated %ld\n", |
3040 | paddr_nz (sp), (long) align_up (len, 16)); | |
ebafbe83 MS |
3041 | |
3042 | /* Initialize the integer and float register pointers. */ | |
4c7d22cb | 3043 | argreg = MIPS_A0_REGNUM; |
56cea623 | 3044 | float_argreg = mips_fpa0_regnum (current_gdbarch); |
ebafbe83 | 3045 | |
bcb0cc15 | 3046 | /* The struct_return pointer occupies the first parameter-passing reg. */ |
ebafbe83 MS |
3047 | if (struct_return) |
3048 | { | |
3049 | if (mips_debug) | |
3050 | fprintf_unfiltered (gdb_stdlog, | |
25ab4790 | 3051 | "mips_o32_push_dummy_call: struct_return reg=%d 0x%s\n", |
ebafbe83 MS |
3052 | argreg, paddr_nz (struct_addr)); |
3053 | write_register (argreg++, struct_addr); | |
13326b4e | 3054 | stack_offset += mips_stack_argsize (gdbarch); |
ebafbe83 MS |
3055 | } |
3056 | ||
3057 | /* Now load as many as possible of the first arguments into | |
3058 | registers, and push the rest onto the stack. Loop thru args | |
3059 | from first to last. */ | |
3060 | for (argnum = 0; argnum < nargs; argnum++) | |
3061 | { | |
3062 | char *val; | |
ebafbe83 MS |
3063 | struct value *arg = args[argnum]; |
3064 | struct type *arg_type = check_typedef (VALUE_TYPE (arg)); | |
3065 | int len = TYPE_LENGTH (arg_type); | |
3066 | enum type_code typecode = TYPE_CODE (arg_type); | |
3067 | ||
3068 | if (mips_debug) | |
3069 | fprintf_unfiltered (gdb_stdlog, | |
25ab4790 | 3070 | "mips_o32_push_dummy_call: %d len=%d type=%d", |
46cac009 AC |
3071 | argnum + 1, len, (int) typecode); |
3072 | ||
3073 | val = (char *) VALUE_CONTENTS (arg); | |
3074 | ||
3075 | /* 32-bit ABIs always start floating point arguments in an | |
3076 | even-numbered floating point register. Round the FP register | |
3077 | up before the check to see if there are any FP registers | |
3078 | left. O32/O64 targets also pass the FP in the integer | |
3079 | registers so also round up normal registers. */ | |
ceae6e75 AC |
3080 | if (mips_abi_regsize (gdbarch) < 8 |
3081 | && fp_register_arg_p (typecode, arg_type)) | |
46cac009 AC |
3082 | { |
3083 | if ((float_argreg & 1)) | |
3084 | float_argreg++; | |
3085 | } | |
3086 | ||
3087 | /* Floating point arguments passed in registers have to be | |
3088 | treated specially. On 32-bit architectures, doubles | |
3089 | are passed in register pairs; the even register gets | |
3090 | the low word, and the odd register gets the high word. | |
3091 | On O32/O64, the first two floating point arguments are | |
3092 | also copied to general registers, because MIPS16 functions | |
3093 | don't use float registers for arguments. This duplication of | |
3094 | arguments in general registers can't hurt non-MIPS16 functions | |
3095 | because those registers are normally skipped. */ | |
3096 | ||
3097 | if (fp_register_arg_p (typecode, arg_type) | |
3098 | && float_argreg <= MIPS_LAST_FP_ARG_REGNUM) | |
3099 | { | |
ceae6e75 | 3100 | if (mips_abi_regsize (gdbarch) < 8 && len == 8) |
46cac009 AC |
3101 | { |
3102 | int low_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 4 : 0; | |
3103 | unsigned long regval; | |
3104 | ||
3105 | /* Write the low word of the double to the even register(s). */ | |
3106 | regval = extract_unsigned_integer (val + low_offset, 4); | |
3107 | if (mips_debug) | |
3108 | fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s", | |
3109 | float_argreg, phex (regval, 4)); | |
3110 | write_register (float_argreg++, regval); | |
3111 | if (mips_debug) | |
3112 | fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s", | |
3113 | argreg, phex (regval, 4)); | |
3114 | write_register (argreg++, regval); | |
3115 | ||
3116 | /* Write the high word of the double to the odd register(s). */ | |
3117 | regval = extract_unsigned_integer (val + 4 - low_offset, 4); | |
3118 | if (mips_debug) | |
3119 | fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s", | |
3120 | float_argreg, phex (regval, 4)); | |
3121 | write_register (float_argreg++, regval); | |
3122 | ||
3123 | if (mips_debug) | |
3124 | fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s", | |
3125 | argreg, phex (regval, 4)); | |
3126 | write_register (argreg++, regval); | |
3127 | } | |
3128 | else | |
3129 | { | |
3130 | /* This is a floating point value that fits entirely | |
3131 | in a single register. */ | |
3132 | /* On 32 bit ABI's the float_argreg is further adjusted | |
6d82d43b | 3133 | above to ensure that it is even register aligned. */ |
46cac009 AC |
3134 | LONGEST regval = extract_unsigned_integer (val, len); |
3135 | if (mips_debug) | |
3136 | fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s", | |
3137 | float_argreg, phex (regval, len)); | |
3138 | write_register (float_argreg++, regval); | |
3139 | /* CAGNEY: 32 bit MIPS ABI's always reserve two FP | |
6d82d43b AC |
3140 | registers for each argument. The below is (my |
3141 | guess) to ensure that the corresponding integer | |
3142 | register has reserved the same space. */ | |
46cac009 AC |
3143 | if (mips_debug) |
3144 | fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s", | |
3145 | argreg, phex (regval, len)); | |
3146 | write_register (argreg, regval); | |
ceae6e75 | 3147 | argreg += (mips_abi_regsize (gdbarch) == 8) ? 1 : 2; |
46cac009 AC |
3148 | } |
3149 | /* Reserve space for the FP register. */ | |
13326b4e | 3150 | stack_offset += align_up (len, mips_stack_argsize (gdbarch)); |
46cac009 AC |
3151 | } |
3152 | else | |
3153 | { | |
3154 | /* Copy the argument to general registers or the stack in | |
3155 | register-sized pieces. Large arguments are split between | |
3156 | registers and stack. */ | |
4246e332 | 3157 | /* Note: structs whose size is not a multiple of |
d5ac5a39 AC |
3158 | mips_abi_regsize() are treated specially: Irix cc passes |
3159 | them in registers where gcc sometimes puts them on the | |
3160 | stack. For maximum compatibility, we will put them in | |
3161 | both places. */ | |
13326b4e AC |
3162 | int odd_sized_struct = ((len > mips_abi_regsize (gdbarch)) |
3163 | && (len % mips_abi_regsize (gdbarch) != 0)); | |
46cac009 AC |
3164 | /* Structures should be aligned to eight bytes (even arg registers) |
3165 | on MIPS_ABI_O32, if their first member has double precision. */ | |
13326b4e | 3166 | if (mips_abi_regsize (gdbarch) < 8 |
46cac009 AC |
3167 | && mips_type_needs_double_align (arg_type)) |
3168 | { | |
3169 | if ((argreg & 1)) | |
6d82d43b | 3170 | argreg++; |
46cac009 AC |
3171 | } |
3172 | /* Note: Floating-point values that didn't fit into an FP | |
6d82d43b | 3173 | register are only written to memory. */ |
46cac009 AC |
3174 | while (len > 0) |
3175 | { | |
3176 | /* Remember if the argument was written to the stack. */ | |
3177 | int stack_used_p = 0; | |
13326b4e AC |
3178 | int partial_len = (len < mips_abi_regsize (gdbarch) |
3179 | ? len : mips_abi_regsize (gdbarch)); | |
46cac009 AC |
3180 | |
3181 | if (mips_debug) | |
3182 | fprintf_unfiltered (gdb_stdlog, " -- partial=%d", | |
3183 | partial_len); | |
3184 | ||
3185 | /* Write this portion of the argument to the stack. */ | |
3186 | if (argreg > MIPS_LAST_ARG_REGNUM | |
3187 | || odd_sized_struct | |
3188 | || fp_register_arg_p (typecode, arg_type)) | |
3189 | { | |
3190 | /* Should shorter than int integer values be | |
3191 | promoted to int before being stored? */ | |
3192 | int longword_offset = 0; | |
3193 | CORE_ADDR addr; | |
3194 | stack_used_p = 1; | |
3195 | if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) | |
3196 | { | |
13326b4e | 3197 | if (mips_stack_argsize (gdbarch) == 8 |
480d3dd2 AC |
3198 | && (typecode == TYPE_CODE_INT |
3199 | || typecode == TYPE_CODE_PTR | |
6d82d43b | 3200 | || typecode == TYPE_CODE_FLT) && len <= 4) |
13326b4e | 3201 | longword_offset = mips_stack_argsize (gdbarch) - len; |
46cac009 AC |
3202 | } |
3203 | ||
3204 | if (mips_debug) | |
3205 | { | |
3206 | fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s", | |
3207 | paddr_nz (stack_offset)); | |
3208 | fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s", | |
3209 | paddr_nz (longword_offset)); | |
3210 | } | |
3211 | ||
3212 | addr = sp + stack_offset + longword_offset; | |
3213 | ||
3214 | if (mips_debug) | |
3215 | { | |
3216 | int i; | |
6d82d43b | 3217 | fprintf_unfiltered (gdb_stdlog, " @0x%s ", |
46cac009 AC |
3218 | paddr_nz (addr)); |
3219 | for (i = 0; i < partial_len; i++) | |
3220 | { | |
6d82d43b | 3221 | fprintf_unfiltered (gdb_stdlog, "%02x", |
46cac009 AC |
3222 | val[i] & 0xff); |
3223 | } | |
3224 | } | |
3225 | write_memory (addr, val, partial_len); | |
3226 | } | |
3227 | ||
3228 | /* Note!!! This is NOT an else clause. Odd sized | |
3229 | structs may go thru BOTH paths. Floating point | |
3230 | arguments will not. */ | |
3231 | /* Write this portion of the argument to a general | |
6d82d43b | 3232 | purpose register. */ |
46cac009 AC |
3233 | if (argreg <= MIPS_LAST_ARG_REGNUM |
3234 | && !fp_register_arg_p (typecode, arg_type)) | |
3235 | { | |
3236 | LONGEST regval = extract_signed_integer (val, partial_len); | |
4246e332 | 3237 | /* Value may need to be sign extended, because |
1b13c4f6 | 3238 | mips_isa_regsize() != mips_abi_regsize(). */ |
46cac009 AC |
3239 | |
3240 | /* A non-floating-point argument being passed in a | |
3241 | general register. If a struct or union, and if | |
3242 | the remaining length is smaller than the register | |
3243 | size, we have to adjust the register value on | |
3244 | big endian targets. | |
3245 | ||
3246 | It does not seem to be necessary to do the | |
3247 | same for integral types. | |
3248 | ||
3249 | Also don't do this adjustment on O64 binaries. | |
3250 | ||
3251 | cagney/2001-07-23: gdb/179: Also, GCC, when | |
3252 | outputting LE O32 with sizeof (struct) < | |
1b13c4f6 | 3253 | mips_abi_regsize(), generates a left shift as |
46cac009 AC |
3254 | part of storing the argument in a register a |
3255 | register (the left shift isn't generated when | |
1b13c4f6 | 3256 | sizeof (struct) >= mips_abi_regsize()). Since |
480d3dd2 AC |
3257 | it is quite possible that this is GCC |
3258 | contradicting the LE/O32 ABI, GDB has not been | |
3259 | adjusted to accommodate this. Either someone | |
3260 | needs to demonstrate that the LE/O32 ABI | |
3261 | specifies such a left shift OR this new ABI gets | |
3262 | identified as such and GDB gets tweaked | |
3263 | accordingly. */ | |
3264 | ||
13326b4e | 3265 | if (mips_abi_regsize (gdbarch) < 8 |
46cac009 | 3266 | && TARGET_BYTE_ORDER == BFD_ENDIAN_BIG |
13326b4e | 3267 | && partial_len < mips_abi_regsize (gdbarch) |
46cac009 AC |
3268 | && (typecode == TYPE_CODE_STRUCT || |
3269 | typecode == TYPE_CODE_UNION)) | |
13326b4e | 3270 | regval <<= ((mips_abi_regsize (gdbarch) - partial_len) * |
46cac009 AC |
3271 | TARGET_CHAR_BIT); |
3272 | ||
3273 | if (mips_debug) | |
3274 | fprintf_filtered (gdb_stdlog, " - reg=%d val=%s", | |
3275 | argreg, | |
6d82d43b | 3276 | phex (regval, |
13326b4e | 3277 | mips_abi_regsize (gdbarch))); |
46cac009 AC |
3278 | write_register (argreg, regval); |
3279 | argreg++; | |
3280 | ||
3281 | /* Prevent subsequent floating point arguments from | |
3282 | being passed in floating point registers. */ | |
3283 | float_argreg = MIPS_LAST_FP_ARG_REGNUM + 1; | |
3284 | } | |
3285 | ||
3286 | len -= partial_len; | |
3287 | val += partial_len; | |
3288 | ||
3289 | /* Compute the the offset into the stack at which we | |
6d82d43b | 3290 | will copy the next parameter. |
46cac009 | 3291 | |
6d82d43b AC |
3292 | In older ABIs, the caller reserved space for |
3293 | registers that contained arguments. This was loosely | |
3294 | refered to as their "home". Consequently, space is | |
3295 | always allocated. */ | |
46cac009 | 3296 | |
480d3dd2 | 3297 | stack_offset += align_up (partial_len, |
13326b4e | 3298 | mips_stack_argsize (gdbarch)); |
46cac009 AC |
3299 | } |
3300 | } | |
3301 | if (mips_debug) | |
3302 | fprintf_unfiltered (gdb_stdlog, "\n"); | |
3303 | } | |
3304 | ||
f10683bb | 3305 | regcache_cooked_write_signed (regcache, MIPS_SP_REGNUM, sp); |
310e9b6a | 3306 | |
46cac009 AC |
3307 | /* Return adjusted stack pointer. */ |
3308 | return sp; | |
3309 | } | |
3310 | ||
6d82d43b AC |
3311 | static enum return_value_convention |
3312 | mips_o32_return_value (struct gdbarch *gdbarch, struct type *type, | |
3313 | struct regcache *regcache, | |
3314 | void *readbuf, const void *writebuf) | |
3315 | { | |
3316 | struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); | |
3317 | ||
3318 | if (TYPE_CODE (type) == TYPE_CODE_STRUCT | |
3319 | || TYPE_CODE (type) == TYPE_CODE_UNION | |
3320 | || TYPE_CODE (type) == TYPE_CODE_ARRAY) | |
3321 | return RETURN_VALUE_STRUCT_CONVENTION; | |
3322 | else if (TYPE_CODE (type) == TYPE_CODE_FLT | |
3323 | && TYPE_LENGTH (type) == 4 && tdep->mips_fpu_type != MIPS_FPU_NONE) | |
3324 | { | |
3325 | /* A single-precision floating-point value. It fits in the | |
3326 | least significant part of FP0. */ | |
3327 | if (mips_debug) | |
3328 | fprintf_unfiltered (gdb_stderr, "Return float in $fp0\n"); | |
3329 | mips_xfer_register (regcache, | |
3330 | NUM_REGS + mips_regnum (current_gdbarch)->fp0, | |
3331 | TYPE_LENGTH (type), | |
3332 | TARGET_BYTE_ORDER, readbuf, writebuf, 0); | |
3333 | return RETURN_VALUE_REGISTER_CONVENTION; | |
3334 | } | |
3335 | else if (TYPE_CODE (type) == TYPE_CODE_FLT | |
3336 | && TYPE_LENGTH (type) == 8 && tdep->mips_fpu_type != MIPS_FPU_NONE) | |
3337 | { | |
3338 | /* A double-precision floating-point value. The most | |
3339 | significant part goes in FP1, and the least significant in | |
3340 | FP0. */ | |
3341 | if (mips_debug) | |
3342 | fprintf_unfiltered (gdb_stderr, "Return float in $fp1/$fp0\n"); | |
3343 | switch (TARGET_BYTE_ORDER) | |
3344 | { | |
3345 | case BFD_ENDIAN_LITTLE: | |
3346 | mips_xfer_register (regcache, | |
3347 | NUM_REGS + mips_regnum (current_gdbarch)->fp0 + | |
3348 | 0, 4, TARGET_BYTE_ORDER, readbuf, writebuf, 0); | |
3349 | mips_xfer_register (regcache, | |
3350 | NUM_REGS + mips_regnum (current_gdbarch)->fp0 + | |
3351 | 1, 4, TARGET_BYTE_ORDER, readbuf, writebuf, 4); | |
3352 | break; | |
3353 | case BFD_ENDIAN_BIG: | |
3354 | mips_xfer_register (regcache, | |
3355 | NUM_REGS + mips_regnum (current_gdbarch)->fp0 + | |
3356 | 1, 4, TARGET_BYTE_ORDER, readbuf, writebuf, 0); | |
3357 | mips_xfer_register (regcache, | |
3358 | NUM_REGS + mips_regnum (current_gdbarch)->fp0 + | |
3359 | 0, 4, TARGET_BYTE_ORDER, readbuf, writebuf, 4); | |
3360 | break; | |
3361 | default: | |
3362 | internal_error (__FILE__, __LINE__, "bad switch"); | |
3363 | } | |
3364 | return RETURN_VALUE_REGISTER_CONVENTION; | |
3365 | } | |
3366 | #if 0 | |
3367 | else if (TYPE_CODE (type) == TYPE_CODE_STRUCT | |
3368 | && TYPE_NFIELDS (type) <= 2 | |
3369 | && TYPE_NFIELDS (type) >= 1 | |
3370 | && ((TYPE_NFIELDS (type) == 1 | |
3371 | && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) | |
3372 | == TYPE_CODE_FLT)) | |
3373 | || (TYPE_NFIELDS (type) == 2 | |
3374 | && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) | |
3375 | == TYPE_CODE_FLT) | |
3376 | && (TYPE_CODE (TYPE_FIELD_TYPE (type, 1)) | |
3377 | == TYPE_CODE_FLT))) | |
3378 | && tdep->mips_fpu_type != MIPS_FPU_NONE) | |
3379 | { | |
3380 | /* A struct that contains one or two floats. Each value is part | |
3381 | in the least significant part of their floating point | |
3382 | register.. */ | |
3383 | bfd_byte reg[MAX_REGISTER_SIZE]; | |
3384 | int regnum; | |
3385 | int field; | |
3386 | for (field = 0, regnum = mips_regnum (current_gdbarch)->fp0; | |
3387 | field < TYPE_NFIELDS (type); field++, regnum += 2) | |
3388 | { | |
3389 | int offset = (FIELD_BITPOS (TYPE_FIELDS (type)[field]) | |
3390 | / TARGET_CHAR_BIT); | |
3391 | if (mips_debug) | |
3392 | fprintf_unfiltered (gdb_stderr, "Return float struct+%d\n", | |
3393 | offset); | |
3394 | mips_xfer_register (regcache, NUM_REGS + regnum, | |
3395 | TYPE_LENGTH (TYPE_FIELD_TYPE (type, field)), | |
3396 | TARGET_BYTE_ORDER, readbuf, writebuf, offset); | |
3397 | } | |
3398 | return RETURN_VALUE_REGISTER_CONVENTION; | |
3399 | } | |
3400 | #endif | |
3401 | #if 0 | |
3402 | else if (TYPE_CODE (type) == TYPE_CODE_STRUCT | |
3403 | || TYPE_CODE (type) == TYPE_CODE_UNION) | |
3404 | { | |
3405 | /* A structure or union. Extract the left justified value, | |
3406 | regardless of the byte order. I.e. DO NOT USE | |
3407 | mips_xfer_lower. */ | |
3408 | int offset; | |
3409 | int regnum; | |
4c7d22cb | 3410 | for (offset = 0, regnum = MIPS_V0_REGNUM; |
6d82d43b AC |
3411 | offset < TYPE_LENGTH (type); |
3412 | offset += register_size (current_gdbarch, regnum), regnum++) | |
3413 | { | |
3414 | int xfer = register_size (current_gdbarch, regnum); | |
3415 | if (offset + xfer > TYPE_LENGTH (type)) | |
3416 | xfer = TYPE_LENGTH (type) - offset; | |
3417 | if (mips_debug) | |
3418 | fprintf_unfiltered (gdb_stderr, "Return struct+%d:%d in $%d\n", | |
3419 | offset, xfer, regnum); | |
3420 | mips_xfer_register (regcache, NUM_REGS + regnum, xfer, | |
3421 | BFD_ENDIAN_UNKNOWN, readbuf, writebuf, offset); | |
3422 | } | |
3423 | return RETURN_VALUE_REGISTER_CONVENTION; | |
3424 | } | |
3425 | #endif | |
3426 | else | |
3427 | { | |
3428 | /* A scalar extract each part but least-significant-byte | |
3429 | justified. o32 thinks registers are 4 byte, regardless of | |
3430 | the ISA. mips_stack_argsize controls this. */ | |
3431 | int offset; | |
3432 | int regnum; | |
4c7d22cb | 3433 | for (offset = 0, regnum = MIPS_V0_REGNUM; |
6d82d43b | 3434 | offset < TYPE_LENGTH (type); |
13326b4e | 3435 | offset += mips_stack_argsize (gdbarch), regnum++) |
6d82d43b | 3436 | { |
13326b4e | 3437 | int xfer = mips_stack_argsize (gdbarch); |
6d82d43b AC |
3438 | if (offset + xfer > TYPE_LENGTH (type)) |
3439 | xfer = TYPE_LENGTH (type) - offset; | |
3440 | if (mips_debug) | |
3441 | fprintf_unfiltered (gdb_stderr, "Return scalar+%d:%d in $%d\n", | |
3442 | offset, xfer, regnum); | |
3443 | mips_xfer_register (regcache, NUM_REGS + regnum, xfer, | |
3444 | TARGET_BYTE_ORDER, readbuf, writebuf, offset); | |
3445 | } | |
3446 | return RETURN_VALUE_REGISTER_CONVENTION; | |
3447 | } | |
3448 | } | |
3449 | ||
3450 | /* O64 ABI. This is a hacked up kind of 64-bit version of the o32 | |
3451 | ABI. */ | |
46cac009 AC |
3452 | |
3453 | static CORE_ADDR | |
7d9b040b | 3454 | mips_o64_push_dummy_call (struct gdbarch *gdbarch, struct value *function, |
6d82d43b AC |
3455 | struct regcache *regcache, CORE_ADDR bp_addr, |
3456 | int nargs, | |
3457 | struct value **args, CORE_ADDR sp, | |
3458 | int struct_return, CORE_ADDR struct_addr) | |
46cac009 AC |
3459 | { |
3460 | int argreg; | |
3461 | int float_argreg; | |
3462 | int argnum; | |
3463 | int len = 0; | |
3464 | int stack_offset = 0; | |
480d3dd2 | 3465 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
7d9b040b | 3466 | CORE_ADDR func_addr = find_function_addr (function, NULL); |
46cac009 | 3467 | |
25ab4790 AC |
3468 | /* For shared libraries, "t9" needs to point at the function |
3469 | address. */ | |
4c7d22cb | 3470 | regcache_cooked_write_signed (regcache, MIPS_T9_REGNUM, func_addr); |
25ab4790 AC |
3471 | |
3472 | /* Set the return address register to point to the entry point of | |
3473 | the program, where a breakpoint lies in wait. */ | |
4c7d22cb | 3474 | regcache_cooked_write_signed (regcache, MIPS_RA_REGNUM, bp_addr); |
25ab4790 | 3475 | |
46cac009 AC |
3476 | /* First ensure that the stack and structure return address (if any) |
3477 | are properly aligned. The stack has to be at least 64-bit | |
3478 | aligned even on 32-bit machines, because doubles must be 64-bit | |
3479 | aligned. For n32 and n64, stack frames need to be 128-bit | |
3480 | aligned, so we round to this widest known alignment. */ | |
3481 | ||
5b03f266 AC |
3482 | sp = align_down (sp, 16); |
3483 | struct_addr = align_down (struct_addr, 16); | |
46cac009 AC |
3484 | |
3485 | /* Now make space on the stack for the args. */ | |
3486 | for (argnum = 0; argnum < nargs; argnum++) | |
6d82d43b | 3487 | len += align_up (TYPE_LENGTH (VALUE_TYPE (args[argnum])), |
13326b4e | 3488 | mips_stack_argsize (gdbarch)); |
5b03f266 | 3489 | sp -= align_up (len, 16); |
46cac009 AC |
3490 | |
3491 | if (mips_debug) | |
6d82d43b | 3492 | fprintf_unfiltered (gdb_stdlog, |
5b03f266 AC |
3493 | "mips_o64_push_dummy_call: sp=0x%s allocated %ld\n", |
3494 | paddr_nz (sp), (long) align_up (len, 16)); | |
46cac009 AC |
3495 | |
3496 | /* Initialize the integer and float register pointers. */ | |
4c7d22cb | 3497 | argreg = MIPS_A0_REGNUM; |
56cea623 | 3498 | float_argreg = mips_fpa0_regnum (current_gdbarch); |
46cac009 AC |
3499 | |
3500 | /* The struct_return pointer occupies the first parameter-passing reg. */ | |
3501 | if (struct_return) | |
3502 | { | |
3503 | if (mips_debug) | |
3504 | fprintf_unfiltered (gdb_stdlog, | |
25ab4790 | 3505 | "mips_o64_push_dummy_call: struct_return reg=%d 0x%s\n", |
46cac009 AC |
3506 | argreg, paddr_nz (struct_addr)); |
3507 | write_register (argreg++, struct_addr); | |
13326b4e | 3508 | stack_offset += mips_stack_argsize (gdbarch); |
46cac009 AC |
3509 | } |
3510 | ||
3511 | /* Now load as many as possible of the first arguments into | |
3512 | registers, and push the rest onto the stack. Loop thru args | |
3513 | from first to last. */ | |
3514 | for (argnum = 0; argnum < nargs; argnum++) | |
3515 | { | |
3516 | char *val; | |
46cac009 AC |
3517 | struct value *arg = args[argnum]; |
3518 | struct type *arg_type = check_typedef (VALUE_TYPE (arg)); | |
3519 | int len = TYPE_LENGTH (arg_type); | |
3520 | enum type_code typecode = TYPE_CODE (arg_type); | |
3521 | ||
3522 | if (mips_debug) | |
3523 | fprintf_unfiltered (gdb_stdlog, | |
25ab4790 | 3524 | "mips_o64_push_dummy_call: %d len=%d type=%d", |
ebafbe83 MS |
3525 | argnum + 1, len, (int) typecode); |
3526 | ||
3527 | val = (char *) VALUE_CONTENTS (arg); | |
3528 | ||
3529 | /* 32-bit ABIs always start floating point arguments in an | |
3530 | even-numbered floating point register. Round the FP register | |
3531 | up before the check to see if there are any FP registers | |
3532 | left. O32/O64 targets also pass the FP in the integer | |
3533 | registers so also round up normal registers. */ | |
ceae6e75 AC |
3534 | if (mips_abi_regsize (gdbarch) < 8 |
3535 | && fp_register_arg_p (typecode, arg_type)) | |
ebafbe83 MS |
3536 | { |
3537 | if ((float_argreg & 1)) | |
3538 | float_argreg++; | |
3539 | } | |
3540 | ||
3541 | /* Floating point arguments passed in registers have to be | |
3542 | treated specially. On 32-bit architectures, doubles | |
3543 | are passed in register pairs; the even register gets | |
3544 | the low word, and the odd register gets the high word. | |
3545 | On O32/O64, the first two floating point arguments are | |
3546 | also copied to general registers, because MIPS16 functions | |
3547 | don't use float registers for arguments. This duplication of | |
3548 | arguments in general registers can't hurt non-MIPS16 functions | |
3549 | because those registers are normally skipped. */ | |
3550 | ||
3551 | if (fp_register_arg_p (typecode, arg_type) | |
3552 | && float_argreg <= MIPS_LAST_FP_ARG_REGNUM) | |
3553 | { | |
ceae6e75 | 3554 | if (mips_abi_regsize (gdbarch) < 8 && len == 8) |
ebafbe83 MS |
3555 | { |
3556 | int low_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 4 : 0; | |
3557 | unsigned long regval; | |
3558 | ||
3559 | /* Write the low word of the double to the even register(s). */ | |
3560 | regval = extract_unsigned_integer (val + low_offset, 4); | |
3561 | if (mips_debug) | |
3562 | fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s", | |
3563 | float_argreg, phex (regval, 4)); | |
3564 | write_register (float_argreg++, regval); | |
3565 | if (mips_debug) | |
3566 | fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s", | |
3567 | argreg, phex (regval, 4)); | |
3568 | write_register (argreg++, regval); | |
3569 | ||
3570 | /* Write the high word of the double to the odd register(s). */ | |
3571 | regval = extract_unsigned_integer (val + 4 - low_offset, 4); | |
3572 | if (mips_debug) | |
3573 | fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s", | |
3574 | float_argreg, phex (regval, 4)); | |
3575 | write_register (float_argreg++, regval); | |
3576 | ||
3577 | if (mips_debug) | |
3578 | fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s", | |
3579 | argreg, phex (regval, 4)); | |
3580 | write_register (argreg++, regval); | |
3581 | } | |
3582 | else | |
3583 | { | |
3584 | /* This is a floating point value that fits entirely | |
3585 | in a single register. */ | |
3586 | /* On 32 bit ABI's the float_argreg is further adjusted | |
6d82d43b | 3587 | above to ensure that it is even register aligned. */ |
ebafbe83 MS |
3588 | LONGEST regval = extract_unsigned_integer (val, len); |
3589 | if (mips_debug) | |
3590 | fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s", | |
3591 | float_argreg, phex (regval, len)); | |
3592 | write_register (float_argreg++, regval); | |
3593 | /* CAGNEY: 32 bit MIPS ABI's always reserve two FP | |
6d82d43b AC |
3594 | registers for each argument. The below is (my |
3595 | guess) to ensure that the corresponding integer | |
3596 | register has reserved the same space. */ | |
ebafbe83 MS |
3597 | if (mips_debug) |
3598 | fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s", | |
3599 | argreg, phex (regval, len)); | |
3600 | write_register (argreg, regval); | |
ceae6e75 | 3601 | argreg += (mips_abi_regsize (gdbarch) == 8) ? 1 : 2; |
ebafbe83 MS |
3602 | } |
3603 | /* Reserve space for the FP register. */ | |
13326b4e | 3604 | stack_offset += align_up (len, mips_stack_argsize (gdbarch)); |
ebafbe83 MS |
3605 | } |
3606 | else | |
3607 | { | |
3608 | /* Copy the argument to general registers or the stack in | |
3609 | register-sized pieces. Large arguments are split between | |
3610 | registers and stack. */ | |
4246e332 | 3611 | /* Note: structs whose size is not a multiple of |
d5ac5a39 AC |
3612 | mips_abi_regsize() are treated specially: Irix cc passes |
3613 | them in registers where gcc sometimes puts them on the | |
3614 | stack. For maximum compatibility, we will put them in | |
3615 | both places. */ | |
13326b4e AC |
3616 | int odd_sized_struct = ((len > mips_abi_regsize (gdbarch)) |
3617 | && (len % mips_abi_regsize (gdbarch) != 0)); | |
ebafbe83 MS |
3618 | /* Structures should be aligned to eight bytes (even arg registers) |
3619 | on MIPS_ABI_O32, if their first member has double precision. */ | |
13326b4e | 3620 | if (mips_abi_regsize (gdbarch) < 8 |
ebafbe83 MS |
3621 | && mips_type_needs_double_align (arg_type)) |
3622 | { | |
3623 | if ((argreg & 1)) | |
6d82d43b | 3624 | argreg++; |
ebafbe83 MS |
3625 | } |
3626 | /* Note: Floating-point values that didn't fit into an FP | |
6d82d43b | 3627 | register are only written to memory. */ |
ebafbe83 MS |
3628 | while (len > 0) |
3629 | { | |
3630 | /* Remember if the argument was written to the stack. */ | |
3631 | int stack_used_p = 0; | |
13326b4e AC |
3632 | int partial_len = (len < mips_abi_regsize (gdbarch) |
3633 | ? len : mips_abi_regsize (gdbarch)); | |
ebafbe83 MS |
3634 | |
3635 | if (mips_debug) | |
3636 | fprintf_unfiltered (gdb_stdlog, " -- partial=%d", | |
3637 | partial_len); | |
3638 | ||
3639 | /* Write this portion of the argument to the stack. */ | |
3640 | if (argreg > MIPS_LAST_ARG_REGNUM | |
3641 | || odd_sized_struct | |
3642 | || fp_register_arg_p (typecode, arg_type)) | |
3643 | { | |
3644 | /* Should shorter than int integer values be | |
3645 | promoted to int before being stored? */ | |
3646 | int longword_offset = 0; | |
3647 | CORE_ADDR addr; | |
3648 | stack_used_p = 1; | |
3649 | if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) | |
3650 | { | |
13326b4e | 3651 | if (mips_stack_argsize (gdbarch) == 8 |
480d3dd2 AC |
3652 | && (typecode == TYPE_CODE_INT |
3653 | || typecode == TYPE_CODE_PTR | |
6d82d43b | 3654 | || typecode == TYPE_CODE_FLT) && len <= 4) |
13326b4e | 3655 | longword_offset = mips_stack_argsize (gdbarch) - len; |
ebafbe83 MS |
3656 | } |
3657 | ||
3658 | if (mips_debug) | |
3659 | { | |
3660 | fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%s", | |
3661 | paddr_nz (stack_offset)); | |
3662 | fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%s", | |
3663 | paddr_nz (longword_offset)); | |
3664 | } | |
3665 | ||
3666 | addr = sp + stack_offset + longword_offset; | |
3667 | ||
3668 | if (mips_debug) | |
3669 | { | |
3670 | int i; | |
6d82d43b | 3671 | fprintf_unfiltered (gdb_stdlog, " @0x%s ", |
ebafbe83 MS |
3672 | paddr_nz (addr)); |
3673 | for (i = 0; i < partial_len; i++) | |
3674 | { | |
6d82d43b | 3675 | fprintf_unfiltered (gdb_stdlog, "%02x", |
ebafbe83 MS |
3676 | val[i] & 0xff); |
3677 | } | |
3678 | } | |
3679 | write_memory (addr, val, partial_len); | |
3680 | } | |
3681 | ||
3682 | /* Note!!! This is NOT an else clause. Odd sized | |
3683 | structs may go thru BOTH paths. Floating point | |
3684 | arguments will not. */ | |
3685 | /* Write this portion of the argument to a general | |
6d82d43b | 3686 | purpose register. */ |
ebafbe83 MS |
3687 | if (argreg <= MIPS_LAST_ARG_REGNUM |
3688 | && !fp_register_arg_p (typecode, arg_type)) | |
3689 | { | |
3690 | LONGEST regval = extract_signed_integer (val, partial_len); | |
4246e332 | 3691 | /* Value may need to be sign extended, because |
1b13c4f6 | 3692 | mips_isa_regsize() != mips_abi_regsize(). */ |
ebafbe83 MS |
3693 | |
3694 | /* A non-floating-point argument being passed in a | |
3695 | general register. If a struct or union, and if | |
3696 | the remaining length is smaller than the register | |
3697 | size, we have to adjust the register value on | |
3698 | big endian targets. | |
3699 | ||
3700 | It does not seem to be necessary to do the | |
3701 | same for integral types. | |
3702 | ||
3703 | Also don't do this adjustment on O64 binaries. | |
3704 | ||
3705 | cagney/2001-07-23: gdb/179: Also, GCC, when | |
3706 | outputting LE O32 with sizeof (struct) < | |
1b13c4f6 | 3707 | mips_abi_regsize(), generates a left shift as |
ebafbe83 MS |
3708 | part of storing the argument in a register a |
3709 | register (the left shift isn't generated when | |
1b13c4f6 | 3710 | sizeof (struct) >= mips_abi_regsize()). Since |
480d3dd2 AC |
3711 | it is quite possible that this is GCC |
3712 | contradicting the LE/O32 ABI, GDB has not been | |
3713 | adjusted to accommodate this. Either someone | |
3714 | needs to demonstrate that the LE/O32 ABI | |
3715 | specifies such a left shift OR this new ABI gets | |
3716 | identified as such and GDB gets tweaked | |
3717 | accordingly. */ | |
3718 | ||
13326b4e | 3719 | if (mips_abi_regsize (gdbarch) < 8 |
ebafbe83 | 3720 | && TARGET_BYTE_ORDER == BFD_ENDIAN_BIG |
13326b4e | 3721 | && partial_len < mips_abi_regsize (gdbarch) |
ebafbe83 MS |
3722 | && (typecode == TYPE_CODE_STRUCT || |
3723 | typecode == TYPE_CODE_UNION)) | |
13326b4e | 3724 | regval <<= ((mips_abi_regsize (gdbarch) - partial_len) * |
ebafbe83 MS |
3725 | TARGET_CHAR_BIT); |
3726 | ||
3727 | if (mips_debug) | |
3728 | fprintf_filtered (gdb_stdlog, " - reg=%d val=%s", | |
3729 | argreg, | |
6d82d43b | 3730 | phex (regval, |
13326b4e | 3731 | mips_abi_regsize (gdbarch))); |
ebafbe83 MS |
3732 | write_register (argreg, regval); |
3733 | argreg++; | |
3734 | ||
3735 | /* Prevent subsequent floating point arguments from | |
3736 | being passed in floating point registers. */ | |
3737 | float_argreg = MIPS_LAST_FP_ARG_REGNUM + 1; | |
3738 | } | |
3739 | ||
3740 | len -= partial_len; | |
3741 | val += partial_len; | |
3742 | ||
3743 | /* Compute the the offset into the stack at which we | |
6d82d43b | 3744 | will copy the next parameter. |
ebafbe83 | 3745 | |
6d82d43b AC |
3746 | In older ABIs, the caller reserved space for |
3747 | registers that contained arguments. This was loosely | |
3748 | refered to as their "home". Consequently, space is | |
3749 | always allocated. */ | |
ebafbe83 | 3750 | |
480d3dd2 | 3751 | stack_offset += align_up (partial_len, |
13326b4e | 3752 | mips_stack_argsize (gdbarch)); |
ebafbe83 MS |
3753 | } |
3754 | } | |
3755 | if (mips_debug) | |
3756 | fprintf_unfiltered (gdb_stdlog, "\n"); | |
3757 | } | |
3758 | ||
f10683bb | 3759 | regcache_cooked_write_signed (regcache, MIPS_SP_REGNUM, sp); |
310e9b6a | 3760 | |
ebafbe83 MS |
3761 | /* Return adjusted stack pointer. */ |
3762 | return sp; | |
3763 | } | |
3764 | ||
9c8fdbfa AC |
3765 | static enum return_value_convention |
3766 | mips_o64_return_value (struct gdbarch *gdbarch, | |
3767 | struct type *type, struct regcache *regcache, | |
3768 | void *readbuf, const void *writebuf) | |
6d82d43b | 3769 | { |
9c8fdbfa | 3770 | return RETURN_VALUE_STRUCT_CONVENTION; |
6d82d43b AC |
3771 | } |
3772 | ||
dd824b04 DJ |
3773 | /* Floating point register management. |
3774 | ||
3775 | Background: MIPS1 & 2 fp registers are 32 bits wide. To support | |
3776 | 64bit operations, these early MIPS cpus treat fp register pairs | |
3777 | (f0,f1) as a single register (d0). Later MIPS cpu's have 64 bit fp | |
3778 | registers and offer a compatibility mode that emulates the MIPS2 fp | |
3779 | model. When operating in MIPS2 fp compat mode, later cpu's split | |
3780 | double precision floats into two 32-bit chunks and store them in | |
3781 | consecutive fp regs. To display 64-bit floats stored in this | |
3782 | fashion, we have to combine 32 bits from f0 and 32 bits from f1. | |
3783 | Throw in user-configurable endianness and you have a real mess. | |
3784 | ||
3785 | The way this works is: | |
3786 | - If we are in 32-bit mode or on a 32-bit processor, then a 64-bit | |
3787 | double-precision value will be split across two logical registers. | |
3788 | The lower-numbered logical register will hold the low-order bits, | |
3789 | regardless of the processor's endianness. | |
3790 | - If we are on a 64-bit processor, and we are looking for a | |
3791 | single-precision value, it will be in the low ordered bits | |
3792 | of a 64-bit GPR (after mfc1, for example) or a 64-bit register | |
3793 | save slot in memory. | |
3794 | - If we are in 64-bit mode, everything is straightforward. | |
3795 | ||
3796 | Note that this code only deals with "live" registers at the top of the | |
3797 | stack. We will attempt to deal with saved registers later, when | |
3798 | the raw/cooked register interface is in place. (We need a general | |
3799 | interface that can deal with dynamic saved register sizes -- fp | |
3800 | regs could be 32 bits wide in one frame and 64 on the frame above | |
3801 | and below). */ | |
3802 | ||
67b2c998 DJ |
3803 | static struct type * |
3804 | mips_float_register_type (void) | |
3805 | { | |
361d1df0 | 3806 | if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) |
67b2c998 DJ |
3807 | return builtin_type_ieee_single_big; |
3808 | else | |
3809 | return builtin_type_ieee_single_little; | |
3810 | } | |
3811 | ||
3812 | static struct type * | |
3813 | mips_double_register_type (void) | |
3814 | { | |
361d1df0 | 3815 | if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) |
67b2c998 DJ |
3816 | return builtin_type_ieee_double_big; |
3817 | else | |
3818 | return builtin_type_ieee_double_little; | |
3819 | } | |
3820 | ||
dd824b04 DJ |
3821 | /* Copy a 32-bit single-precision value from the current frame |
3822 | into rare_buffer. */ | |
3823 | ||
3824 | static void | |
e11c53d2 AC |
3825 | mips_read_fp_register_single (struct frame_info *frame, int regno, |
3826 | char *rare_buffer) | |
dd824b04 | 3827 | { |
719ec221 | 3828 | int raw_size = register_size (current_gdbarch, regno); |
dd824b04 DJ |
3829 | char *raw_buffer = alloca (raw_size); |
3830 | ||
e11c53d2 | 3831 | if (!frame_register_read (frame, regno, raw_buffer)) |
dd824b04 DJ |
3832 | error ("can't read register %d (%s)", regno, REGISTER_NAME (regno)); |
3833 | if (raw_size == 8) | |
3834 | { | |
3835 | /* We have a 64-bit value for this register. Find the low-order | |
6d82d43b | 3836 | 32 bits. */ |
dd824b04 DJ |
3837 | int offset; |
3838 | ||
3839 | if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) | |
3840 | offset = 4; | |
3841 | else | |
3842 | offset = 0; | |
3843 | ||
3844 | memcpy (rare_buffer, raw_buffer + offset, 4); | |
3845 | } | |
3846 | else | |
3847 | { | |
3848 | memcpy (rare_buffer, raw_buffer, 4); | |
3849 | } | |
3850 | } | |
3851 | ||
3852 | /* Copy a 64-bit double-precision value from the current frame into | |
3853 | rare_buffer. This may include getting half of it from the next | |
3854 | register. */ | |
3855 | ||
3856 | static void | |
e11c53d2 AC |
3857 | mips_read_fp_register_double (struct frame_info *frame, int regno, |
3858 | char *rare_buffer) | |
dd824b04 | 3859 | { |
719ec221 | 3860 | int raw_size = register_size (current_gdbarch, regno); |
dd824b04 DJ |
3861 | |
3862 | if (raw_size == 8 && !mips2_fp_compat ()) | |
3863 | { | |
3864 | /* We have a 64-bit value for this register, and we should use | |
6d82d43b | 3865 | all 64 bits. */ |
e11c53d2 | 3866 | if (!frame_register_read (frame, regno, rare_buffer)) |
dd824b04 DJ |
3867 | error ("can't read register %d (%s)", regno, REGISTER_NAME (regno)); |
3868 | } | |
3869 | else | |
3870 | { | |
56cea623 | 3871 | if ((regno - mips_regnum (current_gdbarch)->fp0) & 1) |
dd824b04 DJ |
3872 | internal_error (__FILE__, __LINE__, |
3873 | "mips_read_fp_register_double: bad access to " | |
3874 | "odd-numbered FP register"); | |
3875 | ||
3876 | /* mips_read_fp_register_single will find the correct 32 bits from | |
6d82d43b | 3877 | each register. */ |
dd824b04 DJ |
3878 | if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) |
3879 | { | |
e11c53d2 AC |
3880 | mips_read_fp_register_single (frame, regno, rare_buffer + 4); |
3881 | mips_read_fp_register_single (frame, regno + 1, rare_buffer); | |
dd824b04 | 3882 | } |
361d1df0 | 3883 | else |
dd824b04 | 3884 | { |
e11c53d2 AC |
3885 | mips_read_fp_register_single (frame, regno, rare_buffer); |
3886 | mips_read_fp_register_single (frame, regno + 1, rare_buffer + 4); | |
dd824b04 DJ |
3887 | } |
3888 | } | |
3889 | } | |
3890 | ||
c906108c | 3891 | static void |
e11c53d2 AC |
3892 | mips_print_fp_register (struct ui_file *file, struct frame_info *frame, |
3893 | int regnum) | |
c5aa993b | 3894 | { /* do values for FP (float) regs */ |
dd824b04 | 3895 | char *raw_buffer; |
3903d437 AC |
3896 | double doub, flt1; /* doubles extracted from raw hex data */ |
3897 | int inv1, inv2; | |
c5aa993b | 3898 | |
6d82d43b AC |
3899 | raw_buffer = |
3900 | (char *) alloca (2 * | |
3901 | register_size (current_gdbarch, | |
3902 | mips_regnum (current_gdbarch)->fp0)); | |
c906108c | 3903 | |
e11c53d2 AC |
3904 | fprintf_filtered (file, "%s:", REGISTER_NAME (regnum)); |
3905 | fprintf_filtered (file, "%*s", 4 - (int) strlen (REGISTER_NAME (regnum)), | |
3906 | ""); | |
f0ef6b29 | 3907 | |
719ec221 | 3908 | if (register_size (current_gdbarch, regnum) == 4 || mips2_fp_compat ()) |
c906108c | 3909 | { |
f0ef6b29 KB |
3910 | /* 4-byte registers: Print hex and floating. Also print even |
3911 | numbered registers as doubles. */ | |
e11c53d2 | 3912 | mips_read_fp_register_single (frame, regnum, raw_buffer); |
67b2c998 | 3913 | flt1 = unpack_double (mips_float_register_type (), raw_buffer, &inv1); |
c5aa993b | 3914 | |
6d82d43b AC |
3915 | print_scalar_formatted (raw_buffer, builtin_type_uint32, 'x', 'w', |
3916 | file); | |
dd824b04 | 3917 | |
e11c53d2 | 3918 | fprintf_filtered (file, " flt: "); |
1adad886 | 3919 | if (inv1) |
e11c53d2 | 3920 | fprintf_filtered (file, " <invalid float> "); |
1adad886 | 3921 | else |
e11c53d2 | 3922 | fprintf_filtered (file, "%-17.9g", flt1); |
1adad886 | 3923 | |
f0ef6b29 KB |
3924 | if (regnum % 2 == 0) |
3925 | { | |
e11c53d2 | 3926 | mips_read_fp_register_double (frame, regnum, raw_buffer); |
f0ef6b29 | 3927 | doub = unpack_double (mips_double_register_type (), raw_buffer, |
6d82d43b | 3928 | &inv2); |
1adad886 | 3929 | |
e11c53d2 | 3930 | fprintf_filtered (file, " dbl: "); |
f0ef6b29 | 3931 | if (inv2) |
e11c53d2 | 3932 | fprintf_filtered (file, "<invalid double>"); |
f0ef6b29 | 3933 | else |
e11c53d2 | 3934 | fprintf_filtered (file, "%-24.17g", doub); |
f0ef6b29 | 3935 | } |
c906108c SS |
3936 | } |
3937 | else | |
dd824b04 | 3938 | { |
f0ef6b29 | 3939 | /* Eight byte registers: print each one as hex, float and double. */ |
e11c53d2 | 3940 | mips_read_fp_register_single (frame, regnum, raw_buffer); |
2f38ef89 | 3941 | flt1 = unpack_double (mips_float_register_type (), raw_buffer, &inv1); |
c906108c | 3942 | |
e11c53d2 | 3943 | mips_read_fp_register_double (frame, regnum, raw_buffer); |
f0ef6b29 KB |
3944 | doub = unpack_double (mips_double_register_type (), raw_buffer, &inv2); |
3945 | ||
361d1df0 | 3946 | |
6d82d43b AC |
3947 | print_scalar_formatted (raw_buffer, builtin_type_uint64, 'x', 'g', |
3948 | file); | |
f0ef6b29 | 3949 | |
e11c53d2 | 3950 | fprintf_filtered (file, " flt: "); |
1adad886 | 3951 | if (inv1) |
e11c53d2 | 3952 | fprintf_filtered (file, "<invalid float>"); |
1adad886 | 3953 | else |
e11c53d2 | 3954 | fprintf_filtered (file, "%-17.9g", flt1); |
1adad886 | 3955 | |
e11c53d2 | 3956 | fprintf_filtered (file, " dbl: "); |
f0ef6b29 | 3957 | if (inv2) |
e11c53d2 | 3958 | fprintf_filtered (file, "<invalid double>"); |
1adad886 | 3959 | else |
e11c53d2 | 3960 | fprintf_filtered (file, "%-24.17g", doub); |
f0ef6b29 KB |
3961 | } |
3962 | } | |
3963 | ||
3964 | static void | |
e11c53d2 AC |
3965 | mips_print_register (struct ui_file *file, struct frame_info *frame, |
3966 | int regnum, int all) | |
f0ef6b29 | 3967 | { |
a4b8ebc8 | 3968 | struct gdbarch *gdbarch = get_frame_arch (frame); |
d9d9c31f | 3969 | char raw_buffer[MAX_REGISTER_SIZE]; |
f0ef6b29 | 3970 | int offset; |
1adad886 | 3971 | |
a4b8ebc8 | 3972 | if (TYPE_CODE (gdbarch_register_type (gdbarch, regnum)) == TYPE_CODE_FLT) |
f0ef6b29 | 3973 | { |
e11c53d2 | 3974 | mips_print_fp_register (file, frame, regnum); |
f0ef6b29 KB |
3975 | return; |
3976 | } | |
3977 | ||
3978 | /* Get the data in raw format. */ | |
e11c53d2 | 3979 | if (!frame_register_read (frame, regnum, raw_buffer)) |
f0ef6b29 | 3980 | { |
e11c53d2 | 3981 | fprintf_filtered (file, "%s: [Invalid]", REGISTER_NAME (regnum)); |
f0ef6b29 | 3982 | return; |
c906108c | 3983 | } |
f0ef6b29 | 3984 | |
e11c53d2 | 3985 | fputs_filtered (REGISTER_NAME (regnum), file); |
f0ef6b29 KB |
3986 | |
3987 | /* The problem with printing numeric register names (r26, etc.) is that | |
3988 | the user can't use them on input. Probably the best solution is to | |
3989 | fix it so that either the numeric or the funky (a2, etc.) names | |
3990 | are accepted on input. */ | |
3991 | if (regnum < MIPS_NUMREGS) | |
e11c53d2 | 3992 | fprintf_filtered (file, "(r%d): ", regnum); |
f0ef6b29 | 3993 | else |
e11c53d2 | 3994 | fprintf_filtered (file, ": "); |
f0ef6b29 KB |
3995 | |
3996 | if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) | |
6d82d43b AC |
3997 | offset = |
3998 | register_size (current_gdbarch, | |
3999 | regnum) - register_size (current_gdbarch, regnum); | |
f0ef6b29 KB |
4000 | else |
4001 | offset = 0; | |
4002 | ||
6d82d43b AC |
4003 | print_scalar_formatted (raw_buffer + offset, |
4004 | gdbarch_register_type (gdbarch, regnum), 'x', 0, | |
4005 | file); | |
c906108c SS |
4006 | } |
4007 | ||
f0ef6b29 KB |
4008 | /* Replacement for generic do_registers_info. |
4009 | Print regs in pretty columns. */ | |
4010 | ||
4011 | static int | |
e11c53d2 AC |
4012 | print_fp_register_row (struct ui_file *file, struct frame_info *frame, |
4013 | int regnum) | |
f0ef6b29 | 4014 | { |
e11c53d2 AC |
4015 | fprintf_filtered (file, " "); |
4016 | mips_print_fp_register (file, frame, regnum); | |
4017 | fprintf_filtered (file, "\n"); | |
f0ef6b29 KB |
4018 | return regnum + 1; |
4019 | } | |
4020 | ||
4021 | ||
c906108c SS |
4022 | /* Print a row's worth of GP (int) registers, with name labels above */ |
4023 | ||
4024 | static int | |
e11c53d2 | 4025 | print_gp_register_row (struct ui_file *file, struct frame_info *frame, |
a4b8ebc8 | 4026 | int start_regnum) |
c906108c | 4027 | { |
a4b8ebc8 | 4028 | struct gdbarch *gdbarch = get_frame_arch (frame); |
c906108c | 4029 | /* do values for GP (int) regs */ |
d9d9c31f | 4030 | char raw_buffer[MAX_REGISTER_SIZE]; |
d5ac5a39 | 4031 | int ncols = (mips_abi_regsize (gdbarch) == 8 ? 4 : 8); /* display cols per row */ |
c906108c | 4032 | int col, byte; |
a4b8ebc8 | 4033 | int regnum; |
c906108c SS |
4034 | |
4035 | /* For GP registers, we print a separate row of names above the vals */ | |
e11c53d2 | 4036 | fprintf_filtered (file, " "); |
a4b8ebc8 | 4037 | for (col = 0, regnum = start_regnum; |
6d82d43b | 4038 | col < ncols && regnum < NUM_REGS + NUM_PSEUDO_REGS; regnum++) |
c906108c SS |
4039 | { |
4040 | if (*REGISTER_NAME (regnum) == '\0') | |
c5aa993b | 4041 | continue; /* unused register */ |
6d82d43b AC |
4042 | if (TYPE_CODE (gdbarch_register_type (gdbarch, regnum)) == |
4043 | TYPE_CODE_FLT) | |
c5aa993b | 4044 | break; /* end the row: reached FP register */ |
6d82d43b | 4045 | fprintf_filtered (file, |
d5ac5a39 | 4046 | mips_abi_regsize (current_gdbarch) == 8 ? "%17s" : "%9s", |
e11c53d2 | 4047 | REGISTER_NAME (regnum)); |
c906108c SS |
4048 | col++; |
4049 | } | |
a4b8ebc8 | 4050 | /* print the R0 to R31 names */ |
20e6603c AC |
4051 | if ((start_regnum % NUM_REGS) < MIPS_NUMREGS) |
4052 | fprintf_filtered (file, "\n R%-4d", start_regnum % NUM_REGS); | |
4053 | else | |
4054 | fprintf_filtered (file, "\n "); | |
c906108c | 4055 | |
c906108c | 4056 | /* now print the values in hex, 4 or 8 to the row */ |
a4b8ebc8 | 4057 | for (col = 0, regnum = start_regnum; |
6d82d43b | 4058 | col < ncols && regnum < NUM_REGS + NUM_PSEUDO_REGS; regnum++) |
c906108c SS |
4059 | { |
4060 | if (*REGISTER_NAME (regnum) == '\0') | |
c5aa993b | 4061 | continue; /* unused register */ |
6d82d43b AC |
4062 | if (TYPE_CODE (gdbarch_register_type (gdbarch, regnum)) == |
4063 | TYPE_CODE_FLT) | |
c5aa993b | 4064 | break; /* end row: reached FP register */ |
c906108c | 4065 | /* OK: get the data in raw format. */ |
e11c53d2 | 4066 | if (!frame_register_read (frame, regnum, raw_buffer)) |
c906108c SS |
4067 | error ("can't read register %d (%s)", regnum, REGISTER_NAME (regnum)); |
4068 | /* pad small registers */ | |
4246e332 | 4069 | for (byte = 0; |
d5ac5a39 | 4070 | byte < (mips_abi_regsize (current_gdbarch) |
6d82d43b | 4071 | - register_size (current_gdbarch, regnum)); byte++) |
c906108c SS |
4072 | printf_filtered (" "); |
4073 | /* Now print the register value in hex, endian order. */ | |
d7449b42 | 4074 | if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) |
6d82d43b AC |
4075 | for (byte = |
4076 | register_size (current_gdbarch, | |
4077 | regnum) - register_size (current_gdbarch, regnum); | |
4078 | byte < register_size (current_gdbarch, regnum); byte++) | |
e11c53d2 | 4079 | fprintf_filtered (file, "%02x", (unsigned char) raw_buffer[byte]); |
c906108c | 4080 | else |
c73e8f27 | 4081 | for (byte = register_size (current_gdbarch, regnum) - 1; |
6d82d43b | 4082 | byte >= 0; byte--) |
e11c53d2 AC |
4083 | fprintf_filtered (file, "%02x", (unsigned char) raw_buffer[byte]); |
4084 | fprintf_filtered (file, " "); | |
c906108c SS |
4085 | col++; |
4086 | } | |
c5aa993b | 4087 | if (col > 0) /* ie. if we actually printed anything... */ |
e11c53d2 | 4088 | fprintf_filtered (file, "\n"); |
c906108c SS |
4089 | |
4090 | return regnum; | |
4091 | } | |
4092 | ||
4093 | /* MIPS_DO_REGISTERS_INFO(): called by "info register" command */ | |
4094 | ||
bf1f5b4c | 4095 | static void |
e11c53d2 AC |
4096 | mips_print_registers_info (struct gdbarch *gdbarch, struct ui_file *file, |
4097 | struct frame_info *frame, int regnum, int all) | |
c906108c | 4098 | { |
c5aa993b | 4099 | if (regnum != -1) /* do one specified register */ |
c906108c | 4100 | { |
a4b8ebc8 | 4101 | gdb_assert (regnum >= NUM_REGS); |
c906108c SS |
4102 | if (*(REGISTER_NAME (regnum)) == '\0') |
4103 | error ("Not a valid register for the current processor type"); | |
4104 | ||
e11c53d2 AC |
4105 | mips_print_register (file, frame, regnum, 0); |
4106 | fprintf_filtered (file, "\n"); | |
c906108c | 4107 | } |
c5aa993b JM |
4108 | else |
4109 | /* do all (or most) registers */ | |
c906108c | 4110 | { |
a4b8ebc8 AC |
4111 | regnum = NUM_REGS; |
4112 | while (regnum < NUM_REGS + NUM_PSEUDO_REGS) | |
c906108c | 4113 | { |
6d82d43b AC |
4114 | if (TYPE_CODE (gdbarch_register_type (gdbarch, regnum)) == |
4115 | TYPE_CODE_FLT) | |
e11c53d2 AC |
4116 | { |
4117 | if (all) /* true for "INFO ALL-REGISTERS" command */ | |
4118 | regnum = print_fp_register_row (file, frame, regnum); | |
4119 | else | |
4120 | regnum += MIPS_NUMREGS; /* skip floating point regs */ | |
4121 | } | |
c906108c | 4122 | else |
e11c53d2 | 4123 | regnum = print_gp_register_row (file, frame, regnum); |
c906108c SS |
4124 | } |
4125 | } | |
4126 | } | |
4127 | ||
c906108c SS |
4128 | /* Is this a branch with a delay slot? */ |
4129 | ||
c906108c | 4130 | static int |
acdb74a0 | 4131 | is_delayed (unsigned long insn) |
c906108c SS |
4132 | { |
4133 | int i; | |
4134 | for (i = 0; i < NUMOPCODES; ++i) | |
4135 | if (mips_opcodes[i].pinfo != INSN_MACRO | |
4136 | && (insn & mips_opcodes[i].mask) == mips_opcodes[i].match) | |
4137 | break; | |
4138 | return (i < NUMOPCODES | |
4139 | && (mips_opcodes[i].pinfo & (INSN_UNCOND_BRANCH_DELAY | |
4140 | | INSN_COND_BRANCH_DELAY | |
4141 | | INSN_COND_BRANCH_LIKELY))); | |
4142 | } | |
4143 | ||
4144 | int | |
3352ef37 AC |
4145 | mips_single_step_through_delay (struct gdbarch *gdbarch, |
4146 | struct frame_info *frame) | |
c906108c | 4147 | { |
3352ef37 | 4148 | CORE_ADDR pc = get_frame_pc (frame); |
95ac2dcf | 4149 | char buf[MIPS_INSN32_SIZE]; |
c906108c SS |
4150 | |
4151 | /* There is no branch delay slot on MIPS16. */ | |
0fe7e7c8 | 4152 | if (mips_pc_is_mips16 (pc)) |
c906108c SS |
4153 | return 0; |
4154 | ||
3352ef37 AC |
4155 | if (!safe_frame_unwind_memory (frame, pc, buf, sizeof buf)) |
4156 | /* If error reading memory, guess that it is not a delayed | |
4157 | branch. */ | |
c906108c | 4158 | return 0; |
4c7d22cb | 4159 | return is_delayed (extract_unsigned_integer (buf, sizeof buf)); |
c906108c SS |
4160 | } |
4161 | ||
6d82d43b AC |
4162 | /* To skip prologues, I use this predicate. Returns either PC itself |
4163 | if the code at PC does not look like a function prologue; otherwise | |
4164 | returns an address that (if we're lucky) follows the prologue. If | |
4165 | LENIENT, then we must skip everything which is involved in setting | |
4166 | up the frame (it's OK to skip more, just so long as we don't skip | |
4167 | anything which might clobber the registers which are being saved. | |
4168 | We must skip more in the case where part of the prologue is in the | |
4169 | delay slot of a non-prologue instruction). */ | |
4170 | ||
4171 | static CORE_ADDR | |
4172 | mips_skip_prologue (CORE_ADDR pc) | |
4173 | { | |
8b622e6a AC |
4174 | CORE_ADDR limit_pc; |
4175 | CORE_ADDR func_addr; | |
4176 | ||
6d82d43b AC |
4177 | /* See if we can determine the end of the prologue via the symbol table. |
4178 | If so, then return either PC, or the PC after the prologue, whichever | |
4179 | is greater. */ | |
8b622e6a AC |
4180 | if (find_pc_partial_function (pc, NULL, &func_addr, NULL)) |
4181 | { | |
4182 | CORE_ADDR post_prologue_pc = skip_prologue_using_sal (func_addr); | |
4183 | if (post_prologue_pc != 0) | |
4184 | return max (pc, post_prologue_pc); | |
4185 | } | |
6d82d43b AC |
4186 | |
4187 | /* Can't determine prologue from the symbol table, need to examine | |
4188 | instructions. */ | |
4189 | ||
98b4dd94 JB |
4190 | /* Find an upper limit on the function prologue using the debug |
4191 | information. If the debug information could not be used to provide | |
4192 | that bound, then use an arbitrary large number as the upper bound. */ | |
4193 | limit_pc = skip_prologue_using_sal (pc); | |
4194 | if (limit_pc == 0) | |
4195 | limit_pc = pc + 100; /* Magic. */ | |
4196 | ||
0fe7e7c8 | 4197 | if (mips_pc_is_mips16 (pc)) |
a65bbe44 | 4198 | return mips16_scan_prologue (pc, limit_pc, NULL, NULL); |
6d82d43b | 4199 | else |
a65bbe44 | 4200 | return mips32_scan_prologue (pc, limit_pc, NULL, NULL); |
88658117 AC |
4201 | } |
4202 | ||
a5ea2558 AC |
4203 | /* Root of all "set mips "/"show mips " commands. This will eventually be |
4204 | used for all MIPS-specific commands. */ | |
4205 | ||
a5ea2558 | 4206 | static void |
acdb74a0 | 4207 | show_mips_command (char *args, int from_tty) |
a5ea2558 AC |
4208 | { |
4209 | help_list (showmipscmdlist, "show mips ", all_commands, gdb_stdout); | |
4210 | } | |
4211 | ||
a5ea2558 | 4212 | static void |
acdb74a0 | 4213 | set_mips_command (char *args, int from_tty) |
a5ea2558 | 4214 | { |
6d82d43b AC |
4215 | printf_unfiltered |
4216 | ("\"set mips\" must be followed by an appropriate subcommand.\n"); | |
a5ea2558 AC |
4217 | help_list (setmipscmdlist, "set mips ", all_commands, gdb_stdout); |
4218 | } | |
4219 | ||
c906108c SS |
4220 | /* Commands to show/set the MIPS FPU type. */ |
4221 | ||
c906108c | 4222 | static void |
acdb74a0 | 4223 | show_mipsfpu_command (char *args, int from_tty) |
c906108c | 4224 | { |
c906108c SS |
4225 | char *fpu; |
4226 | switch (MIPS_FPU_TYPE) | |
4227 | { | |
4228 | case MIPS_FPU_SINGLE: | |
4229 | fpu = "single-precision"; | |
4230 | break; | |
4231 | case MIPS_FPU_DOUBLE: | |
4232 | fpu = "double-precision"; | |
4233 | break; | |
4234 | case MIPS_FPU_NONE: | |
4235 | fpu = "absent (none)"; | |
4236 | break; | |
93d56215 AC |
4237 | default: |
4238 | internal_error (__FILE__, __LINE__, "bad switch"); | |
c906108c SS |
4239 | } |
4240 | if (mips_fpu_type_auto) | |
6d82d43b AC |
4241 | printf_unfiltered |
4242 | ("The MIPS floating-point coprocessor is set automatically (currently %s)\n", | |
4243 | fpu); | |
c906108c | 4244 | else |
6d82d43b AC |
4245 | printf_unfiltered |
4246 | ("The MIPS floating-point coprocessor is assumed to be %s\n", fpu); | |
c906108c SS |
4247 | } |
4248 | ||
4249 | ||
c906108c | 4250 | static void |
acdb74a0 | 4251 | set_mipsfpu_command (char *args, int from_tty) |
c906108c | 4252 | { |
6d82d43b AC |
4253 | printf_unfiltered |
4254 | ("\"set mipsfpu\" must be followed by \"double\", \"single\",\"none\" or \"auto\".\n"); | |
c906108c SS |
4255 | show_mipsfpu_command (args, from_tty); |
4256 | } | |
4257 | ||
c906108c | 4258 | static void |
acdb74a0 | 4259 | set_mipsfpu_single_command (char *args, int from_tty) |
c906108c | 4260 | { |
8d5838b5 AC |
4261 | struct gdbarch_info info; |
4262 | gdbarch_info_init (&info); | |
c906108c SS |
4263 | mips_fpu_type = MIPS_FPU_SINGLE; |
4264 | mips_fpu_type_auto = 0; | |
8d5838b5 AC |
4265 | /* FIXME: cagney/2003-11-15: Should be setting a field in "info" |
4266 | instead of relying on globals. Doing that would let generic code | |
4267 | handle the search for this specific architecture. */ | |
4268 | if (!gdbarch_update_p (info)) | |
4269 | internal_error (__FILE__, __LINE__, "set mipsfpu failed"); | |
c906108c SS |
4270 | } |
4271 | ||
c906108c | 4272 | static void |
acdb74a0 | 4273 | set_mipsfpu_double_command (char *args, int from_tty) |
c906108c | 4274 | { |
8d5838b5 AC |
4275 | struct gdbarch_info info; |
4276 | gdbarch_info_init (&info); | |
c906108c SS |
4277 | mips_fpu_type = MIPS_FPU_DOUBLE; |
4278 | mips_fpu_type_auto = 0; | |
8d5838b5 AC |
4279 | /* FIXME: cagney/2003-11-15: Should be setting a field in "info" |
4280 | instead of relying on globals. Doing that would let generic code | |
4281 | handle the search for this specific architecture. */ | |
4282 | if (!gdbarch_update_p (info)) | |
4283 | internal_error (__FILE__, __LINE__, "set mipsfpu failed"); | |
c906108c SS |
4284 | } |
4285 | ||
c906108c | 4286 | static void |
acdb74a0 | 4287 | set_mipsfpu_none_command (char *args, int from_tty) |
c906108c | 4288 | { |
8d5838b5 AC |
4289 | struct gdbarch_info info; |
4290 | gdbarch_info_init (&info); | |
c906108c SS |
4291 | mips_fpu_type = MIPS_FPU_NONE; |
4292 | mips_fpu_type_auto = 0; | |
8d5838b5 AC |
4293 | /* FIXME: cagney/2003-11-15: Should be setting a field in "info" |
4294 | instead of relying on globals. Doing that would let generic code | |
4295 | handle the search for this specific architecture. */ | |
4296 | if (!gdbarch_update_p (info)) | |
4297 | internal_error (__FILE__, __LINE__, "set mipsfpu failed"); | |
c906108c SS |
4298 | } |
4299 | ||
c906108c | 4300 | static void |
acdb74a0 | 4301 | set_mipsfpu_auto_command (char *args, int from_tty) |
c906108c SS |
4302 | { |
4303 | mips_fpu_type_auto = 1; | |
4304 | } | |
4305 | ||
c906108c | 4306 | /* Attempt to identify the particular processor model by reading the |
691c0433 AC |
4307 | processor id. NOTE: cagney/2003-11-15: Firstly it isn't clear that |
4308 | the relevant processor still exists (it dates back to '94) and | |
4309 | secondly this is not the way to do this. The processor type should | |
4310 | be set by forcing an architecture change. */ | |
c906108c | 4311 | |
691c0433 AC |
4312 | void |
4313 | deprecated_mips_set_processor_regs_hack (void) | |
c906108c | 4314 | { |
691c0433 | 4315 | struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); |
c906108c SS |
4316 | CORE_ADDR prid; |
4317 | ||
a5c9623c | 4318 | prid = read_register (MIPS_PRID_REGNUM); |
c906108c SS |
4319 | |
4320 | if ((prid & ~0xf) == 0x700) | |
691c0433 | 4321 | tdep->mips_processor_reg_names = mips_r3041_reg_names; |
c906108c SS |
4322 | } |
4323 | ||
4324 | /* Just like reinit_frame_cache, but with the right arguments to be | |
4325 | callable as an sfunc. */ | |
4326 | ||
4327 | static void | |
acdb74a0 AC |
4328 | reinit_frame_cache_sfunc (char *args, int from_tty, |
4329 | struct cmd_list_element *c) | |
c906108c SS |
4330 | { |
4331 | reinit_frame_cache (); | |
4332 | } | |
4333 | ||
a89aa300 AC |
4334 | static int |
4335 | gdb_print_insn_mips (bfd_vma memaddr, struct disassemble_info *info) | |
c906108c | 4336 | { |
e5ab0dce | 4337 | struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); |
c906108c | 4338 | |
d31431ed AC |
4339 | /* FIXME: cagney/2003-06-26: Is this even necessary? The |
4340 | disassembler needs to be able to locally determine the ISA, and | |
4341 | not rely on GDB. Otherwize the stand-alone 'objdump -d' will not | |
4342 | work. */ | |
ec4045ea AC |
4343 | if (mips_pc_is_mips16 (memaddr)) |
4344 | info->mach = bfd_mach_mips16; | |
c906108c SS |
4345 | |
4346 | /* Round down the instruction address to the appropriate boundary. */ | |
65c11066 | 4347 | memaddr &= (info->mach == bfd_mach_mips16 ? ~1 : ~3); |
c5aa993b | 4348 | |
e5ab0dce | 4349 | /* Set the disassembler options. */ |
6d82d43b | 4350 | if (tdep->mips_abi == MIPS_ABI_N32 || tdep->mips_abi == MIPS_ABI_N64) |
e5ab0dce AC |
4351 | { |
4352 | /* Set up the disassembler info, so that we get the right | |
6d82d43b | 4353 | register names from libopcodes. */ |
e5ab0dce AC |
4354 | if (tdep->mips_abi == MIPS_ABI_N32) |
4355 | info->disassembler_options = "gpr-names=n32"; | |
4356 | else | |
4357 | info->disassembler_options = "gpr-names=64"; | |
4358 | info->flavour = bfd_target_elf_flavour; | |
4359 | } | |
4360 | else | |
4361 | /* This string is not recognized explicitly by the disassembler, | |
4362 | but it tells the disassembler to not try to guess the ABI from | |
4363 | the bfd elf headers, such that, if the user overrides the ABI | |
4364 | of a program linked as NewABI, the disassembly will follow the | |
4365 | register naming conventions specified by the user. */ | |
4366 | info->disassembler_options = "gpr-names=32"; | |
4367 | ||
c906108c | 4368 | /* Call the appropriate disassembler based on the target endian-ness. */ |
d7449b42 | 4369 | if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) |
c906108c SS |
4370 | return print_insn_big_mips (memaddr, info); |
4371 | else | |
4372 | return print_insn_little_mips (memaddr, info); | |
4373 | } | |
4374 | ||
c906108c SS |
4375 | /* This function implements the BREAKPOINT_FROM_PC macro. It uses the program |
4376 | counter value to determine whether a 16- or 32-bit breakpoint should be | |
4377 | used. It returns a pointer to a string of bytes that encode a breakpoint | |
4378 | instruction, stores the length of the string to *lenptr, and adjusts pc | |
4379 | (if necessary) to point to the actual memory location where the | |
4380 | breakpoint should be inserted. */ | |
4381 | ||
f7ab6ec6 | 4382 | static const unsigned char * |
6d82d43b | 4383 | mips_breakpoint_from_pc (CORE_ADDR *pcptr, int *lenptr) |
c906108c | 4384 | { |
d7449b42 | 4385 | if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) |
c906108c | 4386 | { |
0fe7e7c8 | 4387 | if (mips_pc_is_mips16 (*pcptr)) |
c906108c | 4388 | { |
6d82d43b | 4389 | static unsigned char mips16_big_breakpoint[] = { 0xe8, 0xa5 }; |
95404a3e | 4390 | *pcptr = unmake_mips16_addr (*pcptr); |
c5aa993b | 4391 | *lenptr = sizeof (mips16_big_breakpoint); |
c906108c SS |
4392 | return mips16_big_breakpoint; |
4393 | } | |
4394 | else | |
4395 | { | |
aaab4dba AC |
4396 | /* The IDT board uses an unusual breakpoint value, and |
4397 | sometimes gets confused when it sees the usual MIPS | |
4398 | breakpoint instruction. */ | |
6d82d43b AC |
4399 | static unsigned char big_breakpoint[] = { 0, 0x5, 0, 0xd }; |
4400 | static unsigned char pmon_big_breakpoint[] = { 0, 0, 0, 0xd }; | |
4401 | static unsigned char idt_big_breakpoint[] = { 0, 0, 0x0a, 0xd }; | |
c906108c | 4402 | |
c5aa993b | 4403 | *lenptr = sizeof (big_breakpoint); |
c906108c SS |
4404 | |
4405 | if (strcmp (target_shortname, "mips") == 0) | |
4406 | return idt_big_breakpoint; | |
4407 | else if (strcmp (target_shortname, "ddb") == 0 | |
4408 | || strcmp (target_shortname, "pmon") == 0 | |
4409 | || strcmp (target_shortname, "lsi") == 0) | |
4410 | return pmon_big_breakpoint; | |
4411 | else | |
4412 | return big_breakpoint; | |
4413 | } | |
4414 | } | |
4415 | else | |
4416 | { | |
0fe7e7c8 | 4417 | if (mips_pc_is_mips16 (*pcptr)) |
c906108c | 4418 | { |
6d82d43b | 4419 | static unsigned char mips16_little_breakpoint[] = { 0xa5, 0xe8 }; |
95404a3e | 4420 | *pcptr = unmake_mips16_addr (*pcptr); |
c5aa993b | 4421 | *lenptr = sizeof (mips16_little_breakpoint); |
c906108c SS |
4422 | return mips16_little_breakpoint; |
4423 | } | |
4424 | else | |
4425 | { | |
6d82d43b AC |
4426 | static unsigned char little_breakpoint[] = { 0xd, 0, 0x5, 0 }; |
4427 | static unsigned char pmon_little_breakpoint[] = { 0xd, 0, 0, 0 }; | |
4428 | static unsigned char idt_little_breakpoint[] = { 0xd, 0x0a, 0, 0 }; | |
c906108c | 4429 | |
c5aa993b | 4430 | *lenptr = sizeof (little_breakpoint); |
c906108c SS |
4431 | |
4432 | if (strcmp (target_shortname, "mips") == 0) | |
4433 | return idt_little_breakpoint; | |
4434 | else if (strcmp (target_shortname, "ddb") == 0 | |
4435 | || strcmp (target_shortname, "pmon") == 0 | |
4436 | || strcmp (target_shortname, "lsi") == 0) | |
4437 | return pmon_little_breakpoint; | |
4438 | else | |
4439 | return little_breakpoint; | |
4440 | } | |
4441 | } | |
4442 | } | |
4443 | ||
4444 | /* If PC is in a mips16 call or return stub, return the address of the target | |
4445 | PC, which is either the callee or the caller. There are several | |
4446 | cases which must be handled: | |
4447 | ||
4448 | * If the PC is in __mips16_ret_{d,s}f, this is a return stub and the | |
c5aa993b | 4449 | target PC is in $31 ($ra). |
c906108c | 4450 | * If the PC is in __mips16_call_stub_{1..10}, this is a call stub |
c5aa993b | 4451 | and the target PC is in $2. |
c906108c | 4452 | * If the PC at the start of __mips16_call_stub_{s,d}f_{0..10}, i.e. |
c5aa993b JM |
4453 | before the jal instruction, this is effectively a call stub |
4454 | and the the target PC is in $2. Otherwise this is effectively | |
4455 | a return stub and the target PC is in $18. | |
c906108c SS |
4456 | |
4457 | See the source code for the stubs in gcc/config/mips/mips16.S for | |
e7d6a6d2 | 4458 | gory details. */ |
c906108c | 4459 | |
757a7cc6 | 4460 | static CORE_ADDR |
e7d6a6d2 | 4461 | mips_skip_trampoline_code (CORE_ADDR pc) |
c906108c SS |
4462 | { |
4463 | char *name; | |
4464 | CORE_ADDR start_addr; | |
4465 | ||
4466 | /* Find the starting address and name of the function containing the PC. */ | |
4467 | if (find_pc_partial_function (pc, &name, &start_addr, NULL) == 0) | |
4468 | return 0; | |
4469 | ||
4470 | /* If the PC is in __mips16_ret_{d,s}f, this is a return stub and the | |
4471 | target PC is in $31 ($ra). */ | |
4472 | if (strcmp (name, "__mips16_ret_sf") == 0 | |
4473 | || strcmp (name, "__mips16_ret_df") == 0) | |
4c7d22cb | 4474 | return read_signed_register (MIPS_RA_REGNUM); |
c906108c SS |
4475 | |
4476 | if (strncmp (name, "__mips16_call_stub_", 19) == 0) | |
4477 | { | |
4478 | /* If the PC is in __mips16_call_stub_{1..10}, this is a call stub | |
4479 | and the target PC is in $2. */ | |
4480 | if (name[19] >= '0' && name[19] <= '9') | |
6c997a34 | 4481 | return read_signed_register (2); |
c906108c SS |
4482 | |
4483 | /* If the PC at the start of __mips16_call_stub_{s,d}f_{0..10}, i.e. | |
c5aa993b JM |
4484 | before the jal instruction, this is effectively a call stub |
4485 | and the the target PC is in $2. Otherwise this is effectively | |
4486 | a return stub and the target PC is in $18. */ | |
c906108c SS |
4487 | else if (name[19] == 's' || name[19] == 'd') |
4488 | { | |
4489 | if (pc == start_addr) | |
4490 | { | |
4491 | /* Check if the target of the stub is a compiler-generated | |
c5aa993b JM |
4492 | stub. Such a stub for a function bar might have a name |
4493 | like __fn_stub_bar, and might look like this: | |
4494 | mfc1 $4,$f13 | |
4495 | mfc1 $5,$f12 | |
4496 | mfc1 $6,$f15 | |
4497 | mfc1 $7,$f14 | |
4498 | la $1,bar (becomes a lui/addiu pair) | |
4499 | jr $1 | |
4500 | So scan down to the lui/addi and extract the target | |
4501 | address from those two instructions. */ | |
c906108c | 4502 | |
6c997a34 | 4503 | CORE_ADDR target_pc = read_signed_register (2); |
d37cca3d | 4504 | ULONGEST inst; |
c906108c SS |
4505 | int i; |
4506 | ||
4507 | /* See if the name of the target function is __fn_stub_*. */ | |
6d82d43b AC |
4508 | if (find_pc_partial_function (target_pc, &name, NULL, NULL) == |
4509 | 0) | |
c906108c SS |
4510 | return target_pc; |
4511 | if (strncmp (name, "__fn_stub_", 10) != 0 | |
4512 | && strcmp (name, "etext") != 0 | |
4513 | && strcmp (name, "_etext") != 0) | |
4514 | return target_pc; | |
4515 | ||
4516 | /* Scan through this _fn_stub_ code for the lui/addiu pair. | |
c5aa993b JM |
4517 | The limit on the search is arbitrarily set to 20 |
4518 | instructions. FIXME. */ | |
95ac2dcf | 4519 | for (i = 0, pc = 0; i < 20; i++, target_pc += MIPS_INSN32_SIZE) |
c906108c | 4520 | { |
c5aa993b JM |
4521 | inst = mips_fetch_instruction (target_pc); |
4522 | if ((inst & 0xffff0000) == 0x3c010000) /* lui $at */ | |
4523 | pc = (inst << 16) & 0xffff0000; /* high word */ | |
4524 | else if ((inst & 0xffff0000) == 0x24210000) /* addiu $at */ | |
4525 | return pc | (inst & 0xffff); /* low word */ | |
c906108c SS |
4526 | } |
4527 | ||
4528 | /* Couldn't find the lui/addui pair, so return stub address. */ | |
4529 | return target_pc; | |
4530 | } | |
4531 | else | |
4532 | /* This is the 'return' part of a call stub. The return | |
4533 | address is in $r18. */ | |
6c997a34 | 4534 | return read_signed_register (18); |
c906108c SS |
4535 | } |
4536 | } | |
c5aa993b | 4537 | return 0; /* not a stub */ |
c906108c SS |
4538 | } |
4539 | ||
a4b8ebc8 AC |
4540 | /* Convert a dbx stab register number (from `r' declaration) to a GDB |
4541 | [1 * NUM_REGS .. 2 * NUM_REGS) REGNUM. */ | |
88c72b7d AC |
4542 | |
4543 | static int | |
4544 | mips_stab_reg_to_regnum (int num) | |
4545 | { | |
a4b8ebc8 | 4546 | int regnum; |
2f38ef89 | 4547 | if (num >= 0 && num < 32) |
a4b8ebc8 | 4548 | regnum = num; |
2f38ef89 | 4549 | else if (num >= 38 && num < 70) |
56cea623 | 4550 | regnum = num + mips_regnum (current_gdbarch)->fp0 - 38; |
040b99fd | 4551 | else if (num == 70) |
56cea623 | 4552 | regnum = mips_regnum (current_gdbarch)->hi; |
040b99fd | 4553 | else if (num == 71) |
56cea623 | 4554 | regnum = mips_regnum (current_gdbarch)->lo; |
2f38ef89 | 4555 | else |
a4b8ebc8 AC |
4556 | /* This will hopefully (eventually) provoke a warning. Should |
4557 | we be calling complaint() here? */ | |
4558 | return NUM_REGS + NUM_PSEUDO_REGS; | |
4559 | return NUM_REGS + regnum; | |
88c72b7d AC |
4560 | } |
4561 | ||
2f38ef89 | 4562 | |
a4b8ebc8 AC |
4563 | /* Convert a dwarf, dwarf2, or ecoff register number to a GDB [1 * |
4564 | NUM_REGS .. 2 * NUM_REGS) REGNUM. */ | |
88c72b7d AC |
4565 | |
4566 | static int | |
2f38ef89 | 4567 | mips_dwarf_dwarf2_ecoff_reg_to_regnum (int num) |
88c72b7d | 4568 | { |
a4b8ebc8 | 4569 | int regnum; |
2f38ef89 | 4570 | if (num >= 0 && num < 32) |
a4b8ebc8 | 4571 | regnum = num; |
2f38ef89 | 4572 | else if (num >= 32 && num < 64) |
56cea623 | 4573 | regnum = num + mips_regnum (current_gdbarch)->fp0 - 32; |
040b99fd | 4574 | else if (num == 64) |
56cea623 | 4575 | regnum = mips_regnum (current_gdbarch)->hi; |
040b99fd | 4576 | else if (num == 65) |
56cea623 | 4577 | regnum = mips_regnum (current_gdbarch)->lo; |
2f38ef89 | 4578 | else |
a4b8ebc8 AC |
4579 | /* This will hopefully (eventually) provoke a warning. Should we |
4580 | be calling complaint() here? */ | |
4581 | return NUM_REGS + NUM_PSEUDO_REGS; | |
4582 | return NUM_REGS + regnum; | |
4583 | } | |
4584 | ||
4585 | static int | |
4586 | mips_register_sim_regno (int regnum) | |
4587 | { | |
4588 | /* Only makes sense to supply raw registers. */ | |
4589 | gdb_assert (regnum >= 0 && regnum < NUM_REGS); | |
4590 | /* FIXME: cagney/2002-05-13: Need to look at the pseudo register to | |
4591 | decide if it is valid. Should instead define a standard sim/gdb | |
4592 | register numbering scheme. */ | |
4593 | if (REGISTER_NAME (NUM_REGS + regnum) != NULL | |
4594 | && REGISTER_NAME (NUM_REGS + regnum)[0] != '\0') | |
4595 | return regnum; | |
4596 | else | |
6d82d43b | 4597 | return LEGACY_SIM_REGNO_IGNORE; |
88c72b7d AC |
4598 | } |
4599 | ||
2f38ef89 | 4600 | |
fc0c74b1 AC |
4601 | /* Convert an integer into an address. By first converting the value |
4602 | into a pointer and then extracting it signed, the address is | |
4603 | guarenteed to be correctly sign extended. */ | |
4604 | ||
4605 | static CORE_ADDR | |
4606 | mips_integer_to_address (struct type *type, void *buf) | |
4607 | { | |
4608 | char *tmp = alloca (TYPE_LENGTH (builtin_type_void_data_ptr)); | |
4609 | LONGEST val = unpack_long (type, buf); | |
4610 | store_signed_integer (tmp, TYPE_LENGTH (builtin_type_void_data_ptr), val); | |
4611 | return extract_signed_integer (tmp, | |
4612 | TYPE_LENGTH (builtin_type_void_data_ptr)); | |
4613 | } | |
4614 | ||
caaa3122 DJ |
4615 | static void |
4616 | mips_find_abi_section (bfd *abfd, asection *sect, void *obj) | |
4617 | { | |
4618 | enum mips_abi *abip = (enum mips_abi *) obj; | |
4619 | const char *name = bfd_get_section_name (abfd, sect); | |
4620 | ||
4621 | if (*abip != MIPS_ABI_UNKNOWN) | |
4622 | return; | |
4623 | ||
4624 | if (strncmp (name, ".mdebug.", 8) != 0) | |
4625 | return; | |
4626 | ||
4627 | if (strcmp (name, ".mdebug.abi32") == 0) | |
4628 | *abip = MIPS_ABI_O32; | |
4629 | else if (strcmp (name, ".mdebug.abiN32") == 0) | |
4630 | *abip = MIPS_ABI_N32; | |
62a49b2c | 4631 | else if (strcmp (name, ".mdebug.abi64") == 0) |
e3bddbfa | 4632 | *abip = MIPS_ABI_N64; |
caaa3122 DJ |
4633 | else if (strcmp (name, ".mdebug.abiO64") == 0) |
4634 | *abip = MIPS_ABI_O64; | |
4635 | else if (strcmp (name, ".mdebug.eabi32") == 0) | |
4636 | *abip = MIPS_ABI_EABI32; | |
4637 | else if (strcmp (name, ".mdebug.eabi64") == 0) | |
4638 | *abip = MIPS_ABI_EABI64; | |
4639 | else | |
4640 | warning ("unsupported ABI %s.", name + 8); | |
4641 | } | |
4642 | ||
2e4ebe70 DJ |
4643 | static enum mips_abi |
4644 | global_mips_abi (void) | |
4645 | { | |
4646 | int i; | |
4647 | ||
4648 | for (i = 0; mips_abi_strings[i] != NULL; i++) | |
4649 | if (mips_abi_strings[i] == mips_abi_string) | |
4650 | return (enum mips_abi) i; | |
4651 | ||
6d82d43b | 4652 | internal_error (__FILE__, __LINE__, "unknown ABI string"); |
2e4ebe70 DJ |
4653 | } |
4654 | ||
c2d11a7d | 4655 | static struct gdbarch * |
6d82d43b | 4656 | mips_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) |
c2d11a7d | 4657 | { |
c2d11a7d JM |
4658 | struct gdbarch *gdbarch; |
4659 | struct gdbarch_tdep *tdep; | |
4660 | int elf_flags; | |
2e4ebe70 | 4661 | enum mips_abi mips_abi, found_abi, wanted_abi; |
a4b8ebc8 | 4662 | int num_regs; |
8d5838b5 | 4663 | enum mips_fpu_type fpu_type; |
c2d11a7d | 4664 | |
ec03c1ac AC |
4665 | /* First of all, extract the elf_flags, if available. */ |
4666 | if (info.abfd && bfd_get_flavour (info.abfd) == bfd_target_elf_flavour) | |
4667 | elf_flags = elf_elfheader (info.abfd)->e_flags; | |
6214a8a1 AC |
4668 | else if (arches != NULL) |
4669 | elf_flags = gdbarch_tdep (arches->gdbarch)->elf_flags; | |
ec03c1ac AC |
4670 | else |
4671 | elf_flags = 0; | |
4672 | if (gdbarch_debug) | |
4673 | fprintf_unfiltered (gdb_stdlog, | |
6d82d43b | 4674 | "mips_gdbarch_init: elf_flags = 0x%08x\n", elf_flags); |
c2d11a7d | 4675 | |
102182a9 | 4676 | /* Check ELF_FLAGS to see if it specifies the ABI being used. */ |
0dadbba0 AC |
4677 | switch ((elf_flags & EF_MIPS_ABI)) |
4678 | { | |
4679 | case E_MIPS_ABI_O32: | |
ec03c1ac | 4680 | found_abi = MIPS_ABI_O32; |
0dadbba0 AC |
4681 | break; |
4682 | case E_MIPS_ABI_O64: | |
ec03c1ac | 4683 | found_abi = MIPS_ABI_O64; |
0dadbba0 AC |
4684 | break; |
4685 | case E_MIPS_ABI_EABI32: | |
ec03c1ac | 4686 | found_abi = MIPS_ABI_EABI32; |
0dadbba0 AC |
4687 | break; |
4688 | case E_MIPS_ABI_EABI64: | |
ec03c1ac | 4689 | found_abi = MIPS_ABI_EABI64; |
0dadbba0 AC |
4690 | break; |
4691 | default: | |
acdb74a0 | 4692 | if ((elf_flags & EF_MIPS_ABI2)) |
ec03c1ac | 4693 | found_abi = MIPS_ABI_N32; |
acdb74a0 | 4694 | else |
ec03c1ac | 4695 | found_abi = MIPS_ABI_UNKNOWN; |
0dadbba0 AC |
4696 | break; |
4697 | } | |
acdb74a0 | 4698 | |
caaa3122 | 4699 | /* GCC creates a pseudo-section whose name describes the ABI. */ |
ec03c1ac AC |
4700 | if (found_abi == MIPS_ABI_UNKNOWN && info.abfd != NULL) |
4701 | bfd_map_over_sections (info.abfd, mips_find_abi_section, &found_abi); | |
caaa3122 | 4702 | |
dc305454 | 4703 | /* If we have no useful BFD information, use the ABI from the last |
ec03c1ac AC |
4704 | MIPS architecture (if there is one). */ |
4705 | if (found_abi == MIPS_ABI_UNKNOWN && info.abfd == NULL && arches != NULL) | |
4706 | found_abi = gdbarch_tdep (arches->gdbarch)->found_abi; | |
2e4ebe70 | 4707 | |
32a6503c | 4708 | /* Try the architecture for any hint of the correct ABI. */ |
ec03c1ac | 4709 | if (found_abi == MIPS_ABI_UNKNOWN |
bf64bfd6 AC |
4710 | && info.bfd_arch_info != NULL |
4711 | && info.bfd_arch_info->arch == bfd_arch_mips) | |
4712 | { | |
4713 | switch (info.bfd_arch_info->mach) | |
4714 | { | |
4715 | case bfd_mach_mips3900: | |
ec03c1ac | 4716 | found_abi = MIPS_ABI_EABI32; |
bf64bfd6 AC |
4717 | break; |
4718 | case bfd_mach_mips4100: | |
4719 | case bfd_mach_mips5000: | |
ec03c1ac | 4720 | found_abi = MIPS_ABI_EABI64; |
bf64bfd6 | 4721 | break; |
1d06468c EZ |
4722 | case bfd_mach_mips8000: |
4723 | case bfd_mach_mips10000: | |
32a6503c KB |
4724 | /* On Irix, ELF64 executables use the N64 ABI. The |
4725 | pseudo-sections which describe the ABI aren't present | |
4726 | on IRIX. (Even for executables created by gcc.) */ | |
28d169de KB |
4727 | if (bfd_get_flavour (info.abfd) == bfd_target_elf_flavour |
4728 | && elf_elfheader (info.abfd)->e_ident[EI_CLASS] == ELFCLASS64) | |
ec03c1ac | 4729 | found_abi = MIPS_ABI_N64; |
28d169de | 4730 | else |
ec03c1ac | 4731 | found_abi = MIPS_ABI_N32; |
1d06468c | 4732 | break; |
bf64bfd6 AC |
4733 | } |
4734 | } | |
2e4ebe70 | 4735 | |
ec03c1ac AC |
4736 | if (gdbarch_debug) |
4737 | fprintf_unfiltered (gdb_stdlog, "mips_gdbarch_init: found_abi = %d\n", | |
4738 | found_abi); | |
4739 | ||
4740 | /* What has the user specified from the command line? */ | |
4741 | wanted_abi = global_mips_abi (); | |
4742 | if (gdbarch_debug) | |
4743 | fprintf_unfiltered (gdb_stdlog, "mips_gdbarch_init: wanted_abi = %d\n", | |
4744 | wanted_abi); | |
2e4ebe70 DJ |
4745 | |
4746 | /* Now that we have found what the ABI for this binary would be, | |
4747 | check whether the user is overriding it. */ | |
2e4ebe70 DJ |
4748 | if (wanted_abi != MIPS_ABI_UNKNOWN) |
4749 | mips_abi = wanted_abi; | |
ec03c1ac AC |
4750 | else if (found_abi != MIPS_ABI_UNKNOWN) |
4751 | mips_abi = found_abi; | |
4752 | else | |
4753 | mips_abi = MIPS_ABI_O32; | |
4754 | if (gdbarch_debug) | |
4755 | fprintf_unfiltered (gdb_stdlog, "mips_gdbarch_init: mips_abi = %d\n", | |
4756 | mips_abi); | |
2e4ebe70 | 4757 | |
ec03c1ac | 4758 | /* Also used when doing an architecture lookup. */ |
4b9b3959 | 4759 | if (gdbarch_debug) |
ec03c1ac AC |
4760 | fprintf_unfiltered (gdb_stdlog, |
4761 | "mips_gdbarch_init: mips64_transfers_32bit_regs_p = %d\n", | |
4762 | mips64_transfers_32bit_regs_p); | |
0dadbba0 | 4763 | |
8d5838b5 AC |
4764 | /* Determine the MIPS FPU type. */ |
4765 | if (!mips_fpu_type_auto) | |
4766 | fpu_type = mips_fpu_type; | |
4767 | else if (info.bfd_arch_info != NULL | |
4768 | && info.bfd_arch_info->arch == bfd_arch_mips) | |
4769 | switch (info.bfd_arch_info->mach) | |
4770 | { | |
4771 | case bfd_mach_mips3900: | |
4772 | case bfd_mach_mips4100: | |
4773 | case bfd_mach_mips4111: | |
a9d61c86 | 4774 | case bfd_mach_mips4120: |
8d5838b5 AC |
4775 | fpu_type = MIPS_FPU_NONE; |
4776 | break; | |
4777 | case bfd_mach_mips4650: | |
4778 | fpu_type = MIPS_FPU_SINGLE; | |
4779 | break; | |
4780 | default: | |
4781 | fpu_type = MIPS_FPU_DOUBLE; | |
4782 | break; | |
4783 | } | |
4784 | else if (arches != NULL) | |
4785 | fpu_type = gdbarch_tdep (arches->gdbarch)->mips_fpu_type; | |
4786 | else | |
4787 | fpu_type = MIPS_FPU_DOUBLE; | |
4788 | if (gdbarch_debug) | |
4789 | fprintf_unfiltered (gdb_stdlog, | |
6d82d43b | 4790 | "mips_gdbarch_init: fpu_type = %d\n", fpu_type); |
8d5838b5 | 4791 | |
c2d11a7d JM |
4792 | /* try to find a pre-existing architecture */ |
4793 | for (arches = gdbarch_list_lookup_by_info (arches, &info); | |
4794 | arches != NULL; | |
4795 | arches = gdbarch_list_lookup_by_info (arches->next, &info)) | |
4796 | { | |
4797 | /* MIPS needs to be pedantic about which ABI the object is | |
102182a9 | 4798 | using. */ |
9103eae0 | 4799 | if (gdbarch_tdep (arches->gdbarch)->elf_flags != elf_flags) |
c2d11a7d | 4800 | continue; |
9103eae0 | 4801 | if (gdbarch_tdep (arches->gdbarch)->mips_abi != mips_abi) |
0dadbba0 | 4802 | continue; |
719ec221 AC |
4803 | /* Need to be pedantic about which register virtual size is |
4804 | used. */ | |
4805 | if (gdbarch_tdep (arches->gdbarch)->mips64_transfers_32bit_regs_p | |
4806 | != mips64_transfers_32bit_regs_p) | |
4807 | continue; | |
8d5838b5 AC |
4808 | /* Be pedantic about which FPU is selected. */ |
4809 | if (gdbarch_tdep (arches->gdbarch)->mips_fpu_type != fpu_type) | |
4810 | continue; | |
4be87837 | 4811 | return arches->gdbarch; |
c2d11a7d JM |
4812 | } |
4813 | ||
102182a9 | 4814 | /* Need a new architecture. Fill in a target specific vector. */ |
c2d11a7d JM |
4815 | tdep = (struct gdbarch_tdep *) xmalloc (sizeof (struct gdbarch_tdep)); |
4816 | gdbarch = gdbarch_alloc (&info, tdep); | |
4817 | tdep->elf_flags = elf_flags; | |
719ec221 | 4818 | tdep->mips64_transfers_32bit_regs_p = mips64_transfers_32bit_regs_p; |
ec03c1ac AC |
4819 | tdep->found_abi = found_abi; |
4820 | tdep->mips_abi = mips_abi; | |
8d5838b5 | 4821 | tdep->mips_fpu_type = fpu_type; |
c2d11a7d | 4822 | |
102182a9 | 4823 | /* Initially set everything according to the default ABI/ISA. */ |
c2d11a7d JM |
4824 | set_gdbarch_short_bit (gdbarch, 16); |
4825 | set_gdbarch_int_bit (gdbarch, 32); | |
4826 | set_gdbarch_float_bit (gdbarch, 32); | |
4827 | set_gdbarch_double_bit (gdbarch, 64); | |
4828 | set_gdbarch_long_double_bit (gdbarch, 64); | |
a4b8ebc8 AC |
4829 | set_gdbarch_register_reggroup_p (gdbarch, mips_register_reggroup_p); |
4830 | set_gdbarch_pseudo_register_read (gdbarch, mips_pseudo_register_read); | |
4831 | set_gdbarch_pseudo_register_write (gdbarch, mips_pseudo_register_write); | |
1d06468c | 4832 | |
6d82d43b | 4833 | set_gdbarch_elf_make_msymbol_special (gdbarch, |
f7ab6ec6 MS |
4834 | mips_elf_make_msymbol_special); |
4835 | ||
16e109ca | 4836 | /* Fill in the OS dependant register numbers and names. */ |
56cea623 | 4837 | { |
16e109ca | 4838 | const char **reg_names; |
56cea623 AC |
4839 | struct mips_regnum *regnum = GDBARCH_OBSTACK_ZALLOC (gdbarch, |
4840 | struct mips_regnum); | |
56cea623 AC |
4841 | if (info.osabi == GDB_OSABI_IRIX) |
4842 | { | |
4843 | regnum->fp0 = 32; | |
4844 | regnum->pc = 64; | |
4845 | regnum->cause = 65; | |
4846 | regnum->badvaddr = 66; | |
4847 | regnum->hi = 67; | |
4848 | regnum->lo = 68; | |
4849 | regnum->fp_control_status = 69; | |
4850 | regnum->fp_implementation_revision = 70; | |
4851 | num_regs = 71; | |
16e109ca | 4852 | reg_names = mips_irix_reg_names; |
56cea623 AC |
4853 | } |
4854 | else | |
4855 | { | |
4856 | regnum->lo = MIPS_EMBED_LO_REGNUM; | |
4857 | regnum->hi = MIPS_EMBED_HI_REGNUM; | |
4858 | regnum->badvaddr = MIPS_EMBED_BADVADDR_REGNUM; | |
4859 | regnum->cause = MIPS_EMBED_CAUSE_REGNUM; | |
4860 | regnum->pc = MIPS_EMBED_PC_REGNUM; | |
4861 | regnum->fp0 = MIPS_EMBED_FP0_REGNUM; | |
4862 | regnum->fp_control_status = 70; | |
4863 | regnum->fp_implementation_revision = 71; | |
4864 | num_regs = 90; | |
16e109ca AC |
4865 | if (info.bfd_arch_info != NULL |
4866 | && info.bfd_arch_info->mach == bfd_mach_mips3900) | |
4867 | reg_names = mips_tx39_reg_names; | |
4868 | else | |
4869 | reg_names = mips_generic_reg_names; | |
56cea623 AC |
4870 | } |
4871 | /* FIXME: cagney/2003-11-15: For MIPS, hasn't PC_REGNUM been | |
4872 | replaced by read_pc? */ | |
f10683bb MH |
4873 | set_gdbarch_pc_regnum (gdbarch, regnum->pc + num_regs); |
4874 | set_gdbarch_sp_regnum (gdbarch, MIPS_SP_REGNUM + num_regs); | |
56cea623 AC |
4875 | set_gdbarch_fp0_regnum (gdbarch, regnum->fp0); |
4876 | set_gdbarch_num_regs (gdbarch, num_regs); | |
4877 | set_gdbarch_num_pseudo_regs (gdbarch, num_regs); | |
16e109ca AC |
4878 | set_gdbarch_register_name (gdbarch, mips_register_name); |
4879 | tdep->mips_processor_reg_names = reg_names; | |
4880 | tdep->regnum = regnum; | |
56cea623 | 4881 | } |
fe29b929 | 4882 | |
0dadbba0 | 4883 | switch (mips_abi) |
c2d11a7d | 4884 | { |
0dadbba0 | 4885 | case MIPS_ABI_O32: |
25ab4790 | 4886 | set_gdbarch_push_dummy_call (gdbarch, mips_o32_push_dummy_call); |
29dfb2ac | 4887 | set_gdbarch_return_value (gdbarch, mips_o32_return_value); |
4c7d22cb | 4888 | tdep->mips_last_arg_regnum = MIPS_A0_REGNUM + 4 - 1; |
56cea623 | 4889 | tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 4 - 1; |
4014092b | 4890 | tdep->default_mask_address_p = 0; |
c2d11a7d JM |
4891 | set_gdbarch_long_bit (gdbarch, 32); |
4892 | set_gdbarch_ptr_bit (gdbarch, 32); | |
4893 | set_gdbarch_long_long_bit (gdbarch, 64); | |
4894 | break; | |
0dadbba0 | 4895 | case MIPS_ABI_O64: |
25ab4790 | 4896 | set_gdbarch_push_dummy_call (gdbarch, mips_o64_push_dummy_call); |
9c8fdbfa | 4897 | set_gdbarch_return_value (gdbarch, mips_o64_return_value); |
4c7d22cb | 4898 | tdep->mips_last_arg_regnum = MIPS_A0_REGNUM + 4 - 1; |
56cea623 | 4899 | tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 4 - 1; |
361d1df0 | 4900 | tdep->default_mask_address_p = 0; |
c2d11a7d JM |
4901 | set_gdbarch_long_bit (gdbarch, 32); |
4902 | set_gdbarch_ptr_bit (gdbarch, 32); | |
4903 | set_gdbarch_long_long_bit (gdbarch, 64); | |
4904 | break; | |
0dadbba0 | 4905 | case MIPS_ABI_EABI32: |
25ab4790 | 4906 | set_gdbarch_push_dummy_call (gdbarch, mips_eabi_push_dummy_call); |
9c8fdbfa | 4907 | set_gdbarch_return_value (gdbarch, mips_eabi_return_value); |
4c7d22cb | 4908 | tdep->mips_last_arg_regnum = MIPS_A0_REGNUM + 8 - 1; |
56cea623 | 4909 | tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 8 - 1; |
4014092b | 4910 | tdep->default_mask_address_p = 0; |
c2d11a7d JM |
4911 | set_gdbarch_long_bit (gdbarch, 32); |
4912 | set_gdbarch_ptr_bit (gdbarch, 32); | |
4913 | set_gdbarch_long_long_bit (gdbarch, 64); | |
4914 | break; | |
0dadbba0 | 4915 | case MIPS_ABI_EABI64: |
25ab4790 | 4916 | set_gdbarch_push_dummy_call (gdbarch, mips_eabi_push_dummy_call); |
9c8fdbfa | 4917 | set_gdbarch_return_value (gdbarch, mips_eabi_return_value); |
4c7d22cb | 4918 | tdep->mips_last_arg_regnum = MIPS_A0_REGNUM + 8 - 1; |
56cea623 | 4919 | tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 8 - 1; |
4014092b | 4920 | tdep->default_mask_address_p = 0; |
c2d11a7d JM |
4921 | set_gdbarch_long_bit (gdbarch, 64); |
4922 | set_gdbarch_ptr_bit (gdbarch, 64); | |
4923 | set_gdbarch_long_long_bit (gdbarch, 64); | |
4924 | break; | |
0dadbba0 | 4925 | case MIPS_ABI_N32: |
25ab4790 | 4926 | set_gdbarch_push_dummy_call (gdbarch, mips_n32n64_push_dummy_call); |
29dfb2ac | 4927 | set_gdbarch_return_value (gdbarch, mips_n32n64_return_value); |
4c7d22cb | 4928 | tdep->mips_last_arg_regnum = MIPS_A0_REGNUM + 8 - 1; |
56cea623 | 4929 | tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 8 - 1; |
4014092b | 4930 | tdep->default_mask_address_p = 0; |
0dadbba0 AC |
4931 | set_gdbarch_long_bit (gdbarch, 32); |
4932 | set_gdbarch_ptr_bit (gdbarch, 32); | |
4933 | set_gdbarch_long_long_bit (gdbarch, 64); | |
fed7ba43 JB |
4934 | set_gdbarch_long_double_bit (gdbarch, 128); |
4935 | set_gdbarch_long_double_format (gdbarch, | |
4936 | &floatformat_n32n64_long_double_big); | |
28d169de KB |
4937 | break; |
4938 | case MIPS_ABI_N64: | |
25ab4790 | 4939 | set_gdbarch_push_dummy_call (gdbarch, mips_n32n64_push_dummy_call); |
29dfb2ac | 4940 | set_gdbarch_return_value (gdbarch, mips_n32n64_return_value); |
4c7d22cb | 4941 | tdep->mips_last_arg_regnum = MIPS_A0_REGNUM + 8 - 1; |
56cea623 | 4942 | tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 8 - 1; |
28d169de KB |
4943 | tdep->default_mask_address_p = 0; |
4944 | set_gdbarch_long_bit (gdbarch, 64); | |
4945 | set_gdbarch_ptr_bit (gdbarch, 64); | |
4946 | set_gdbarch_long_long_bit (gdbarch, 64); | |
fed7ba43 JB |
4947 | set_gdbarch_long_double_bit (gdbarch, 128); |
4948 | set_gdbarch_long_double_format (gdbarch, | |
4949 | &floatformat_n32n64_long_double_big); | |
0dadbba0 | 4950 | break; |
c2d11a7d | 4951 | default: |
6d82d43b | 4952 | internal_error (__FILE__, __LINE__, "unknown ABI in switch"); |
c2d11a7d JM |
4953 | } |
4954 | ||
a5ea2558 AC |
4955 | /* FIXME: jlarmour/2000-04-07: There *is* a flag EF_MIPS_32BIT_MODE |
4956 | that could indicate -gp32 BUT gas/config/tc-mips.c contains the | |
4957 | comment: | |
4958 | ||
4959 | ``We deliberately don't allow "-gp32" to set the MIPS_32BITMODE | |
4960 | flag in object files because to do so would make it impossible to | |
102182a9 | 4961 | link with libraries compiled without "-gp32". This is |
a5ea2558 | 4962 | unnecessarily restrictive. |
361d1df0 | 4963 | |
a5ea2558 AC |
4964 | We could solve this problem by adding "-gp32" multilibs to gcc, |
4965 | but to set this flag before gcc is built with such multilibs will | |
4966 | break too many systems.'' | |
4967 | ||
4968 | But even more unhelpfully, the default linker output target for | |
4969 | mips64-elf is elf32-bigmips, and has EF_MIPS_32BIT_MODE set, even | |
4970 | for 64-bit programs - you need to change the ABI to change this, | |
102182a9 | 4971 | and not all gcc targets support that currently. Therefore using |
a5ea2558 AC |
4972 | this flag to detect 32-bit mode would do the wrong thing given |
4973 | the current gcc - it would make GDB treat these 64-bit programs | |
102182a9 | 4974 | as 32-bit programs by default. */ |
a5ea2558 | 4975 | |
6c997a34 | 4976 | set_gdbarch_read_pc (gdbarch, mips_read_pc); |
b6cb9035 | 4977 | set_gdbarch_write_pc (gdbarch, mips_write_pc); |
bcb0cc15 | 4978 | set_gdbarch_read_sp (gdbarch, mips_read_sp); |
c2d11a7d | 4979 | |
102182a9 MS |
4980 | /* Add/remove bits from an address. The MIPS needs be careful to |
4981 | ensure that all 32 bit addresses are sign extended to 64 bits. */ | |
875e1767 AC |
4982 | set_gdbarch_addr_bits_remove (gdbarch, mips_addr_bits_remove); |
4983 | ||
58dfe9ff AC |
4984 | /* Unwind the frame. */ |
4985 | set_gdbarch_unwind_pc (gdbarch, mips_unwind_pc); | |
edfae063 | 4986 | set_gdbarch_unwind_dummy_id (gdbarch, mips_unwind_dummy_id); |
10312cc4 | 4987 | |
102182a9 | 4988 | /* Map debug register numbers onto internal register numbers. */ |
88c72b7d | 4989 | set_gdbarch_stab_reg_to_regnum (gdbarch, mips_stab_reg_to_regnum); |
6d82d43b AC |
4990 | set_gdbarch_ecoff_reg_to_regnum (gdbarch, |
4991 | mips_dwarf_dwarf2_ecoff_reg_to_regnum); | |
4992 | set_gdbarch_dwarf_reg_to_regnum (gdbarch, | |
4993 | mips_dwarf_dwarf2_ecoff_reg_to_regnum); | |
4994 | set_gdbarch_dwarf2_reg_to_regnum (gdbarch, | |
4995 | mips_dwarf_dwarf2_ecoff_reg_to_regnum); | |
a4b8ebc8 | 4996 | set_gdbarch_register_sim_regno (gdbarch, mips_register_sim_regno); |
88c72b7d | 4997 | |
c2d11a7d JM |
4998 | /* MIPS version of CALL_DUMMY */ |
4999 | ||
9710e734 AC |
5000 | /* NOTE: cagney/2003-08-05: Eventually call dummy location will be |
5001 | replaced by a command, and all targets will default to on stack | |
5002 | (regardless of the stack's execute status). */ | |
5003 | set_gdbarch_call_dummy_location (gdbarch, AT_SYMBOL); | |
dc604539 | 5004 | set_gdbarch_frame_align (gdbarch, mips_frame_align); |
d05285fa | 5005 | |
87783b8b AC |
5006 | set_gdbarch_convert_register_p (gdbarch, mips_convert_register_p); |
5007 | set_gdbarch_register_to_value (gdbarch, mips_register_to_value); | |
5008 | set_gdbarch_value_to_register (gdbarch, mips_value_to_register); | |
5009 | ||
f7b9e9fc AC |
5010 | set_gdbarch_inner_than (gdbarch, core_addr_lessthan); |
5011 | set_gdbarch_breakpoint_from_pc (gdbarch, mips_breakpoint_from_pc); | |
f7b9e9fc AC |
5012 | |
5013 | set_gdbarch_skip_prologue (gdbarch, mips_skip_prologue); | |
f7b9e9fc | 5014 | |
fc0c74b1 AC |
5015 | set_gdbarch_pointer_to_address (gdbarch, signed_pointer_to_address); |
5016 | set_gdbarch_address_to_pointer (gdbarch, address_to_signed_pointer); | |
5017 | set_gdbarch_integer_to_address (gdbarch, mips_integer_to_address); | |
70f80edf | 5018 | |
a4b8ebc8 | 5019 | set_gdbarch_register_type (gdbarch, mips_register_type); |
78fde5f8 | 5020 | |
e11c53d2 | 5021 | set_gdbarch_print_registers_info (gdbarch, mips_print_registers_info); |
bf1f5b4c | 5022 | |
e5ab0dce AC |
5023 | set_gdbarch_print_insn (gdbarch, gdb_print_insn_mips); |
5024 | ||
3a3bc038 AC |
5025 | /* FIXME: cagney/2003-08-29: The macros HAVE_STEPPABLE_WATCHPOINT, |
5026 | HAVE_NONSTEPPABLE_WATCHPOINT, and HAVE_CONTINUABLE_WATCHPOINT | |
5027 | need to all be folded into the target vector. Since they are | |
5028 | being used as guards for STOPPED_BY_WATCHPOINT, why not have | |
5029 | STOPPED_BY_WATCHPOINT return the type of watchpoint that the code | |
5030 | is sitting on? */ | |
5031 | set_gdbarch_have_nonsteppable_watchpoint (gdbarch, 1); | |
5032 | ||
e7d6a6d2 | 5033 | set_gdbarch_skip_trampoline_code (gdbarch, mips_skip_trampoline_code); |
757a7cc6 | 5034 | |
3352ef37 AC |
5035 | set_gdbarch_single_step_through_delay (gdbarch, mips_single_step_through_delay); |
5036 | ||
6de918a6 DJ |
5037 | /* Hook in OS ABI-specific overrides, if they have been registered. */ |
5038 | gdbarch_init_osabi (info, gdbarch); | |
757a7cc6 | 5039 | |
5792a79b | 5040 | /* Unwind the frame. */ |
eec63939 | 5041 | frame_unwind_append_sniffer (gdbarch, mips_stub_frame_sniffer); |
45c9dd44 AC |
5042 | frame_unwind_append_sniffer (gdbarch, mips_insn16_frame_sniffer); |
5043 | frame_unwind_append_sniffer (gdbarch, mips_insn32_frame_sniffer); | |
eec63939 | 5044 | frame_base_append_sniffer (gdbarch, mips_stub_frame_base_sniffer); |
45c9dd44 AC |
5045 | frame_base_append_sniffer (gdbarch, mips_insn16_frame_base_sniffer); |
5046 | frame_base_append_sniffer (gdbarch, mips_insn32_frame_base_sniffer); | |
5792a79b | 5047 | |
4b9b3959 AC |
5048 | return gdbarch; |
5049 | } | |
5050 | ||
2e4ebe70 | 5051 | static void |
6d82d43b | 5052 | mips_abi_update (char *ignore_args, int from_tty, struct cmd_list_element *c) |
2e4ebe70 DJ |
5053 | { |
5054 | struct gdbarch_info info; | |
5055 | ||
5056 | /* Force the architecture to update, and (if it's a MIPS architecture) | |
5057 | mips_gdbarch_init will take care of the rest. */ | |
5058 | gdbarch_info_init (&info); | |
5059 | gdbarch_update_p (info); | |
5060 | } | |
5061 | ||
ad188201 KB |
5062 | /* Print out which MIPS ABI is in use. */ |
5063 | ||
5064 | static void | |
5065 | show_mips_abi (char *ignore_args, int from_tty) | |
5066 | { | |
5067 | if (gdbarch_bfd_arch_info (current_gdbarch)->arch != bfd_arch_mips) | |
6d82d43b AC |
5068 | printf_filtered |
5069 | ("The MIPS ABI is unknown because the current architecture is not MIPS.\n"); | |
ad188201 KB |
5070 | else |
5071 | { | |
5072 | enum mips_abi global_abi = global_mips_abi (); | |
5073 | enum mips_abi actual_abi = mips_abi (current_gdbarch); | |
5074 | const char *actual_abi_str = mips_abi_strings[actual_abi]; | |
5075 | ||
5076 | if (global_abi == MIPS_ABI_UNKNOWN) | |
6d82d43b AC |
5077 | printf_filtered |
5078 | ("The MIPS ABI is set automatically (currently \"%s\").\n", | |
5079 | actual_abi_str); | |
ad188201 | 5080 | else if (global_abi == actual_abi) |
6d82d43b AC |
5081 | printf_filtered |
5082 | ("The MIPS ABI is assumed to be \"%s\" (due to user setting).\n", | |
5083 | actual_abi_str); | |
ad188201 KB |
5084 | else |
5085 | { | |
5086 | /* Probably shouldn't happen... */ | |
6d82d43b AC |
5087 | printf_filtered |
5088 | ("The (auto detected) MIPS ABI \"%s\" is in use even though the user setting was \"%s\".\n", | |
5089 | actual_abi_str, mips_abi_strings[global_abi]); | |
ad188201 KB |
5090 | } |
5091 | } | |
5092 | } | |
5093 | ||
4b9b3959 AC |
5094 | static void |
5095 | mips_dump_tdep (struct gdbarch *current_gdbarch, struct ui_file *file) | |
5096 | { | |
5097 | struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); | |
5098 | if (tdep != NULL) | |
c2d11a7d | 5099 | { |
acdb74a0 AC |
5100 | int ef_mips_arch; |
5101 | int ef_mips_32bitmode; | |
5102 | /* determine the ISA */ | |
5103 | switch (tdep->elf_flags & EF_MIPS_ARCH) | |
5104 | { | |
5105 | case E_MIPS_ARCH_1: | |
5106 | ef_mips_arch = 1; | |
5107 | break; | |
5108 | case E_MIPS_ARCH_2: | |
5109 | ef_mips_arch = 2; | |
5110 | break; | |
5111 | case E_MIPS_ARCH_3: | |
5112 | ef_mips_arch = 3; | |
5113 | break; | |
5114 | case E_MIPS_ARCH_4: | |
93d56215 | 5115 | ef_mips_arch = 4; |
acdb74a0 AC |
5116 | break; |
5117 | default: | |
93d56215 | 5118 | ef_mips_arch = 0; |
acdb74a0 AC |
5119 | break; |
5120 | } | |
5121 | /* determine the size of a pointer */ | |
5122 | ef_mips_32bitmode = (tdep->elf_flags & EF_MIPS_32BITMODE); | |
4b9b3959 AC |
5123 | fprintf_unfiltered (file, |
5124 | "mips_dump_tdep: tdep->elf_flags = 0x%x\n", | |
0dadbba0 | 5125 | tdep->elf_flags); |
4b9b3959 | 5126 | fprintf_unfiltered (file, |
acdb74a0 AC |
5127 | "mips_dump_tdep: ef_mips_32bitmode = %d\n", |
5128 | ef_mips_32bitmode); | |
5129 | fprintf_unfiltered (file, | |
5130 | "mips_dump_tdep: ef_mips_arch = %d\n", | |
5131 | ef_mips_arch); | |
5132 | fprintf_unfiltered (file, | |
5133 | "mips_dump_tdep: tdep->mips_abi = %d (%s)\n", | |
6d82d43b | 5134 | tdep->mips_abi, mips_abi_strings[tdep->mips_abi]); |
4014092b AC |
5135 | fprintf_unfiltered (file, |
5136 | "mips_dump_tdep: mips_mask_address_p() %d (default %d)\n", | |
480d3dd2 | 5137 | mips_mask_address_p (tdep), |
4014092b | 5138 | tdep->default_mask_address_p); |
c2d11a7d | 5139 | } |
4b9b3959 AC |
5140 | fprintf_unfiltered (file, |
5141 | "mips_dump_tdep: MIPS_DEFAULT_FPU_TYPE = %d (%s)\n", | |
5142 | MIPS_DEFAULT_FPU_TYPE, | |
5143 | (MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_NONE ? "none" | |
5144 | : MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_SINGLE ? "single" | |
5145 | : MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_DOUBLE ? "double" | |
5146 | : "???")); | |
6d82d43b | 5147 | fprintf_unfiltered (file, "mips_dump_tdep: MIPS_EABI = %d\n", MIPS_EABI); |
4b9b3959 AC |
5148 | fprintf_unfiltered (file, |
5149 | "mips_dump_tdep: MIPS_FPU_TYPE = %d (%s)\n", | |
5150 | MIPS_FPU_TYPE, | |
5151 | (MIPS_FPU_TYPE == MIPS_FPU_NONE ? "none" | |
5152 | : MIPS_FPU_TYPE == MIPS_FPU_SINGLE ? "single" | |
5153 | : MIPS_FPU_TYPE == MIPS_FPU_DOUBLE ? "double" | |
5154 | : "???")); | |
4b9b3959 | 5155 | fprintf_unfiltered (file, |
480d3dd2 | 5156 | "mips_dump_tdep: mips_stack_argsize() = %d\n", |
13326b4e | 5157 | mips_stack_argsize (current_gdbarch)); |
c2d11a7d JM |
5158 | } |
5159 | ||
6d82d43b | 5160 | extern initialize_file_ftype _initialize_mips_tdep; /* -Wmissing-prototypes */ |
a78f21af | 5161 | |
c906108c | 5162 | void |
acdb74a0 | 5163 | _initialize_mips_tdep (void) |
c906108c SS |
5164 | { |
5165 | static struct cmd_list_element *mipsfpulist = NULL; | |
5166 | struct cmd_list_element *c; | |
5167 | ||
6d82d43b | 5168 | mips_abi_string = mips_abi_strings[MIPS_ABI_UNKNOWN]; |
2e4ebe70 DJ |
5169 | if (MIPS_ABI_LAST + 1 |
5170 | != sizeof (mips_abi_strings) / sizeof (mips_abi_strings[0])) | |
5171 | internal_error (__FILE__, __LINE__, "mips_abi_strings out of sync"); | |
5172 | ||
4b9b3959 | 5173 | gdbarch_register (bfd_arch_mips, mips_gdbarch_init, mips_dump_tdep); |
c906108c | 5174 | |
8d5f9dcb DJ |
5175 | mips_pdr_data = register_objfile_data (); |
5176 | ||
a5ea2558 AC |
5177 | /* Add root prefix command for all "set mips"/"show mips" commands */ |
5178 | add_prefix_cmd ("mips", no_class, set_mips_command, | |
5179 | "Various MIPS specific commands.", | |
5180 | &setmipscmdlist, "set mips ", 0, &setlist); | |
5181 | ||
5182 | add_prefix_cmd ("mips", no_class, show_mips_command, | |
5183 | "Various MIPS specific commands.", | |
5184 | &showmipscmdlist, "show mips ", 0, &showlist); | |
5185 | ||
5186 | /* Allow the user to override the saved register size. */ | |
1b295c3d AC |
5187 | add_setshow_enum_cmd ("saved-gpreg-size", class_obscure, |
5188 | size_enums, &mips_abi_regsize_string, "\ | |
5189 | Set size of general purpose registers saved on the stack.\n", "\ | |
5190 | Show size of general purpose registers saved on the stack.\n", "\ | |
a5ea2558 AC |
5191 | This option can be set to one of:\n\ |
5192 | 32 - Force GDB to treat saved GP registers as 32-bit\n\ | |
5193 | 64 - Force GDB to treat saved GP registers as 64-bit\n\ | |
5194 | auto - Allow GDB to use the target's default setting or autodetect the\n\ | |
5195 | saved GP register size from information contained in the executable.\n\ | |
1b295c3d AC |
5196 | (default: auto)", "\ |
5197 | Size of general purpose registers saved on the stack is %s.\n", | |
5198 | NULL, NULL, &setmipscmdlist, &showmipscmdlist); | |
a5ea2558 | 5199 | |
d929b26f | 5200 | /* Allow the user to override the argument stack size. */ |
1b295c3d AC |
5201 | add_setshow_enum_cmd ("stack-arg-size", class_obscure, |
5202 | size_enums, &mips_stack_argsize_string, "\ | |
5203 | Set the amount of stack space reserved for each argument.\n", "\ | |
5204 | Show the amount of stack space reserved for each argument.\n", "\ | |
d929b26f AC |
5205 | This option can be set to one of:\n\ |
5206 | 32 - Force GDB to allocate 32-bit chunks per argument\n\ | |
5207 | 64 - Force GDB to allocate 64-bit chunks per argument\n\ | |
5208 | auto - Allow GDB to determine the correct setting from the current\n\ | |
1b295c3d AC |
5209 | target and executable (default)", "\ |
5210 | The amount of stack space reserved for each argument is %s.\n", | |
5211 | NULL, NULL, &setmipscmdlist, &showmipscmdlist); | |
d929b26f | 5212 | |
2e4ebe70 DJ |
5213 | /* Allow the user to override the ABI. */ |
5214 | c = add_set_enum_cmd | |
5215 | ("abi", class_obscure, mips_abi_strings, &mips_abi_string, | |
5216 | "Set the ABI used by this program.\n" | |
5217 | "This option can be set to one of:\n" | |
5218 | " auto - the default ABI associated with the current binary\n" | |
5219 | " o32\n" | |
6d82d43b | 5220 | " o64\n" " n32\n" " n64\n" " eabi32\n" " eabi64", &setmipscmdlist); |
2e4ebe70 | 5221 | set_cmd_sfunc (c, mips_abi_update); |
ad188201 | 5222 | add_cmd ("abi", class_obscure, show_mips_abi, |
6d82d43b | 5223 | "Show ABI in use by MIPS target", &showmipscmdlist); |
2e4ebe70 | 5224 | |
c906108c SS |
5225 | /* Let the user turn off floating point and set the fence post for |
5226 | heuristic_proc_start. */ | |
5227 | ||
5228 | add_prefix_cmd ("mipsfpu", class_support, set_mipsfpu_command, | |
5229 | "Set use of MIPS floating-point coprocessor.", | |
5230 | &mipsfpulist, "set mipsfpu ", 0, &setlist); | |
5231 | add_cmd ("single", class_support, set_mipsfpu_single_command, | |
5232 | "Select single-precision MIPS floating-point coprocessor.", | |
5233 | &mipsfpulist); | |
5234 | add_cmd ("double", class_support, set_mipsfpu_double_command, | |
8e1a459b | 5235 | "Select double-precision MIPS floating-point coprocessor.", |
c906108c SS |
5236 | &mipsfpulist); |
5237 | add_alias_cmd ("on", "double", class_support, 1, &mipsfpulist); | |
5238 | add_alias_cmd ("yes", "double", class_support, 1, &mipsfpulist); | |
5239 | add_alias_cmd ("1", "double", class_support, 1, &mipsfpulist); | |
5240 | add_cmd ("none", class_support, set_mipsfpu_none_command, | |
6d82d43b | 5241 | "Select no MIPS floating-point coprocessor.", &mipsfpulist); |
c906108c SS |
5242 | add_alias_cmd ("off", "none", class_support, 1, &mipsfpulist); |
5243 | add_alias_cmd ("no", "none", class_support, 1, &mipsfpulist); | |
5244 | add_alias_cmd ("0", "none", class_support, 1, &mipsfpulist); | |
5245 | add_cmd ("auto", class_support, set_mipsfpu_auto_command, | |
5246 | "Select MIPS floating-point coprocessor automatically.", | |
5247 | &mipsfpulist); | |
5248 | add_cmd ("mipsfpu", class_support, show_mipsfpu_command, | |
5249 | "Show current use of MIPS floating-point coprocessor target.", | |
5250 | &showlist); | |
5251 | ||
c906108c SS |
5252 | /* We really would like to have both "0" and "unlimited" work, but |
5253 | command.c doesn't deal with that. So make it a var_zinteger | |
5254 | because the user can always use "999999" or some such for unlimited. */ | |
6bcadd06 AC |
5255 | add_setshow_zinteger_cmd ("heuristic-fence-post", class_support, |
5256 | &heuristic_fence_post, "\ | |
5257 | Set the distance searched for the start of a function.\n", "\ | |
5258 | Show the distance searched for the start of a function.\n", "\ | |
c906108c SS |
5259 | If you are debugging a stripped executable, GDB needs to search through the\n\ |
5260 | program for the start of a function. This command sets the distance of the\n\ | |
6bcadd06 AC |
5261 | search. The only need to set it is when debugging a stripped executable.", "\ |
5262 | The distance searched for the start of a function is %s.\n", | |
5263 | reinit_frame_cache_sfunc, NULL, | |
5264 | &setlist, &showlist); | |
c906108c SS |
5265 | |
5266 | /* Allow the user to control whether the upper bits of 64-bit | |
5267 | addresses should be zeroed. */ | |
e9e68a56 | 5268 | add_setshow_auto_boolean_cmd ("mask-address", no_class, &mask_address_var, "\ |
3b64bf98 AC |
5269 | Set zeroing of upper 32 bits of 64-bit addresses.", "\ |
5270 | Show zeroing of upper 32 bits of 64-bit addresses.", "\ | |
e9e68a56 AC |
5271 | Use \"on\" to enable the masking, \"off\" to disable it and \"auto\" to \n\ |
5272 | allow GDB to determine the correct value.\n", "\ | |
3b64bf98 | 5273 | Zerroing of upper 32 bits of 64-bit address is %s.", |
6d82d43b | 5274 | NULL, show_mask_address, &setmipscmdlist, &showmipscmdlist); |
43e526b9 JM |
5275 | |
5276 | /* Allow the user to control the size of 32 bit registers within the | |
5277 | raw remote packet. */ | |
b3f42336 AC |
5278 | add_setshow_boolean_cmd ("remote-mips64-transfers-32bit-regs", class_obscure, |
5279 | &mips64_transfers_32bit_regs_p, "\ | |
3b64bf98 AC |
5280 | Set compatibility with 64-bit MIPS target that transfers 32-bit quantities.", "\ |
5281 | Show compatibility with 64-bit MIPS target that transfers 32-bit quantities.", "\ | |
719ec221 AC |
5282 | Use \"on\" to enable backward compatibility with older MIPS 64 GDB+target\n\ |
5283 | that would transfer 32 bits for some registers (e.g. SR, FSR) and\n\ | |
6d82d43b | 5284 | 64 bits for others. Use \"off\" to disable compatibility mode", "\ |
3b64bf98 AC |
5285 | Compatibility with 64-bit MIPS target that transfers 32-bit quantities is %s.", |
5286 | set_mips64_transfers_32bit_regs, NULL, &setlist, &showlist); | |
9ace0497 AC |
5287 | |
5288 | /* Debug this files internals. */ | |
6bcadd06 AC |
5289 | add_setshow_zinteger_cmd ("mips", class_maintenance, |
5290 | &mips_debug, "\ | |
5291 | Set mips debugging.\n", "\ | |
5292 | Show mips debugging.\n", "\ | |
5293 | When non-zero, mips specific debugging is enabled.\n", "\ | |
5294 | Mips debugging is currently %s.\n", | |
5295 | NULL, NULL, | |
5296 | &setdebuglist, &showdebuglist); | |
c906108c | 5297 | } |