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