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