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