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