]>
Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Target-dependent code for the MIPS architecture, for GDB, the GNU Debugger. |
bf64bfd6 | 2 | |
cda5a58a AC |
3 | Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, |
4 | 1997, 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. | |
bf64bfd6 | 5 | |
c906108c SS |
6 | Contributed by Alessandro Forin([email protected]) at CMU |
7 | and by Per Bothner([email protected]) at U.Wisconsin. | |
8 | ||
c5aa993b | 9 | This file is part of GDB. |
c906108c | 10 | |
c5aa993b JM |
11 | This program is free software; you can redistribute it and/or modify |
12 | it under the terms of the GNU General Public License as published by | |
13 | the Free Software Foundation; either version 2 of the License, or | |
14 | (at your option) any later version. | |
c906108c | 15 | |
c5aa993b JM |
16 | This program is distributed in the hope that it will be useful, |
17 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 | GNU General Public License for more details. | |
c906108c | 20 | |
c5aa993b JM |
21 | You should have received a copy of the GNU General Public License |
22 | along with this program; if not, write to the Free Software | |
23 | Foundation, Inc., 59 Temple Place - Suite 330, | |
24 | Boston, MA 02111-1307, USA. */ | |
c906108c SS |
25 | |
26 | #include "defs.h" | |
27 | #include "gdb_string.h" | |
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" |
c906108c SS |
42 | |
43 | #include "opcode/mips.h" | |
c2d11a7d JM |
44 | #include "elf/mips.h" |
45 | #include "elf-bfd.h" | |
2475bac3 | 46 | #include "symcat.h" |
c906108c | 47 | |
dd824b04 DJ |
48 | /* A useful bit in the CP0 status register (PS_REGNUM). */ |
49 | /* This bit is set if we are emulating 32-bit FPRs on a 64-bit chip. */ | |
50 | #define ST0_FR (1 << 26) | |
51 | ||
b0069a17 AC |
52 | /* The sizes of floating point registers. */ |
53 | ||
54 | enum | |
55 | { | |
56 | MIPS_FPU_SINGLE_REGSIZE = 4, | |
57 | MIPS_FPU_DOUBLE_REGSIZE = 8 | |
58 | }; | |
59 | ||
0dadbba0 AC |
60 | /* All the possible MIPS ABIs. */ |
61 | ||
62 | enum mips_abi | |
63 | { | |
64 | MIPS_ABI_UNKNOWN, | |
65 | MIPS_ABI_N32, | |
66 | MIPS_ABI_O32, | |
67 | MIPS_ABI_O64, | |
68 | MIPS_ABI_EABI32, | |
69 | MIPS_ABI_EABI64 | |
70 | }; | |
71 | ||
cce74817 | 72 | struct frame_extra_info |
c5aa993b JM |
73 | { |
74 | mips_extra_func_info_t proc_desc; | |
75 | int num_args; | |
76 | }; | |
cce74817 | 77 | |
d929b26f AC |
78 | /* Various MIPS ISA options (related to stack analysis) can be |
79 | overridden dynamically. Establish an enum/array for managing | |
80 | them. */ | |
81 | ||
53904c9e AC |
82 | static const char size_auto[] = "auto"; |
83 | static const char size_32[] = "32"; | |
84 | static const char size_64[] = "64"; | |
d929b26f | 85 | |
53904c9e | 86 | static const char *size_enums[] = { |
d929b26f AC |
87 | size_auto, |
88 | size_32, | |
89 | size_64, | |
a5ea2558 AC |
90 | 0 |
91 | }; | |
92 | ||
7a292a7a SS |
93 | /* Some MIPS boards don't support floating point while others only |
94 | support single-precision floating-point operations. See also | |
95 | FP_REGISTER_DOUBLE. */ | |
c906108c SS |
96 | |
97 | enum mips_fpu_type | |
c5aa993b JM |
98 | { |
99 | MIPS_FPU_DOUBLE, /* Full double precision floating point. */ | |
100 | MIPS_FPU_SINGLE, /* Single precision floating point (R4650). */ | |
101 | MIPS_FPU_NONE /* No floating point. */ | |
102 | }; | |
c906108c SS |
103 | |
104 | #ifndef MIPS_DEFAULT_FPU_TYPE | |
105 | #define MIPS_DEFAULT_FPU_TYPE MIPS_FPU_DOUBLE | |
106 | #endif | |
107 | static int mips_fpu_type_auto = 1; | |
108 | static enum mips_fpu_type mips_fpu_type = MIPS_DEFAULT_FPU_TYPE; | |
7a292a7a | 109 | |
9ace0497 | 110 | static int mips_debug = 0; |
7a292a7a | 111 | |
c2d11a7d JM |
112 | /* MIPS specific per-architecture information */ |
113 | struct gdbarch_tdep | |
114 | { | |
115 | /* from the elf header */ | |
116 | int elf_flags; | |
70f80edf | 117 | |
c2d11a7d | 118 | /* mips options */ |
0dadbba0 | 119 | enum mips_abi mips_abi; |
acdb74a0 | 120 | const char *mips_abi_string; |
c2d11a7d JM |
121 | enum mips_fpu_type mips_fpu_type; |
122 | int mips_last_arg_regnum; | |
123 | int mips_last_fp_arg_regnum; | |
a5ea2558 | 124 | int mips_default_saved_regsize; |
c2d11a7d | 125 | int mips_fp_register_double; |
d929b26f AC |
126 | int mips_regs_have_home_p; |
127 | int mips_default_stack_argsize; | |
5213ab06 | 128 | int gdb_target_is_mips64; |
4014092b | 129 | int default_mask_address_p; |
70f80edf JT |
130 | |
131 | enum gdb_osabi osabi; | |
c2d11a7d JM |
132 | }; |
133 | ||
0dadbba0 | 134 | #define MIPS_EABI (gdbarch_tdep (current_gdbarch)->mips_abi == MIPS_ABI_EABI32 \ |
216a600b | 135 | || gdbarch_tdep (current_gdbarch)->mips_abi == MIPS_ABI_EABI64) |
c2d11a7d | 136 | |
c2d11a7d | 137 | #define MIPS_LAST_FP_ARG_REGNUM (gdbarch_tdep (current_gdbarch)->mips_last_fp_arg_regnum) |
c2d11a7d | 138 | |
c2d11a7d | 139 | #define MIPS_LAST_ARG_REGNUM (gdbarch_tdep (current_gdbarch)->mips_last_arg_regnum) |
c2d11a7d | 140 | |
c2d11a7d | 141 | #define MIPS_FPU_TYPE (gdbarch_tdep (current_gdbarch)->mips_fpu_type) |
c2d11a7d | 142 | |
d929b26f AC |
143 | /* Return the currently configured (or set) saved register size. */ |
144 | ||
a5ea2558 | 145 | #define MIPS_DEFAULT_SAVED_REGSIZE (gdbarch_tdep (current_gdbarch)->mips_default_saved_regsize) |
c2d11a7d | 146 | |
53904c9e | 147 | static const char *mips_saved_regsize_string = size_auto; |
d929b26f AC |
148 | |
149 | #define MIPS_SAVED_REGSIZE (mips_saved_regsize()) | |
150 | ||
151 | static unsigned int | |
acdb74a0 | 152 | mips_saved_regsize (void) |
d929b26f AC |
153 | { |
154 | if (mips_saved_regsize_string == size_auto) | |
155 | return MIPS_DEFAULT_SAVED_REGSIZE; | |
156 | else if (mips_saved_regsize_string == size_64) | |
157 | return 8; | |
158 | else /* if (mips_saved_regsize_string == size_32) */ | |
159 | return 4; | |
160 | } | |
161 | ||
dd824b04 DJ |
162 | /* Determine if a MIPS3 or later cpu is operating in MIPS{1,2} FPU |
163 | compatiblity mode. A return value of 1 means that we have | |
164 | physical 64-bit registers, but should treat them as 32-bit registers. */ | |
165 | ||
166 | static int | |
167 | mips2_fp_compat (void) | |
168 | { | |
169 | /* MIPS1 and MIPS2 have only 32 bit FPRs, and the FR bit is not | |
170 | meaningful. */ | |
171 | if (REGISTER_RAW_SIZE (FP0_REGNUM) == 4) | |
172 | return 0; | |
173 | ||
174 | #if 0 | |
175 | /* FIXME drow 2002-03-10: This is disabled until we can do it consistently, | |
176 | in all the places we deal with FP registers. PR gdb/413. */ | |
177 | /* Otherwise check the FR bit in the status register - it controls | |
178 | the FP compatiblity mode. If it is clear we are in compatibility | |
179 | mode. */ | |
180 | if ((read_register (PS_REGNUM) & ST0_FR) == 0) | |
181 | return 1; | |
182 | #endif | |
361d1df0 | 183 | |
dd824b04 DJ |
184 | return 0; |
185 | } | |
186 | ||
c2d11a7d JM |
187 | /* Indicate that the ABI makes use of double-precision registers |
188 | provided by the FPU (rather than combining pairs of registers to | |
189 | form double-precision values). Do not use "TARGET_IS_MIPS64" to | |
190 | determine if the ABI is using double-precision registers. See also | |
191 | MIPS_FPU_TYPE. */ | |
c2d11a7d | 192 | #define FP_REGISTER_DOUBLE (gdbarch_tdep (current_gdbarch)->mips_fp_register_double) |
c2d11a7d | 193 | |
d929b26f AC |
194 | /* Does the caller allocate a ``home'' for each register used in the |
195 | function call? The N32 ABI and MIPS_EABI do not, the others do. */ | |
196 | ||
d929b26f | 197 | #define MIPS_REGS_HAVE_HOME_P (gdbarch_tdep (current_gdbarch)->mips_regs_have_home_p) |
d929b26f AC |
198 | |
199 | /* The amount of space reserved on the stack for registers. This is | |
200 | different to MIPS_SAVED_REGSIZE as it determines the alignment of | |
201 | data allocated after the registers have run out. */ | |
202 | ||
0dadbba0 | 203 | #define MIPS_DEFAULT_STACK_ARGSIZE (gdbarch_tdep (current_gdbarch)->mips_default_stack_argsize) |
d929b26f AC |
204 | |
205 | #define MIPS_STACK_ARGSIZE (mips_stack_argsize ()) | |
206 | ||
53904c9e | 207 | static const char *mips_stack_argsize_string = size_auto; |
d929b26f AC |
208 | |
209 | static unsigned int | |
210 | mips_stack_argsize (void) | |
211 | { | |
212 | if (mips_stack_argsize_string == size_auto) | |
213 | return MIPS_DEFAULT_STACK_ARGSIZE; | |
214 | else if (mips_stack_argsize_string == size_64) | |
215 | return 8; | |
216 | else /* if (mips_stack_argsize_string == size_32) */ | |
217 | return 4; | |
218 | } | |
219 | ||
5213ab06 | 220 | #define GDB_TARGET_IS_MIPS64 (gdbarch_tdep (current_gdbarch)->gdb_target_is_mips64 + 0) |
c2d11a7d | 221 | |
92e1c15c | 222 | #define MIPS_DEFAULT_MASK_ADDRESS_P (gdbarch_tdep (current_gdbarch)->default_mask_address_p) |
92e1c15c | 223 | |
7a292a7a | 224 | #define VM_MIN_ADDRESS (CORE_ADDR)0x400000 |
c906108c | 225 | |
a14ed312 | 226 | int gdb_print_insn_mips (bfd_vma, disassemble_info *); |
c906108c | 227 | |
a14ed312 | 228 | static void mips_print_register (int, int); |
c906108c SS |
229 | |
230 | static mips_extra_func_info_t | |
479412cd | 231 | heuristic_proc_desc (CORE_ADDR, CORE_ADDR, struct frame_info *, int); |
c906108c | 232 | |
a14ed312 | 233 | static CORE_ADDR heuristic_proc_start (CORE_ADDR); |
c906108c | 234 | |
a14ed312 | 235 | static CORE_ADDR read_next_frame_reg (struct frame_info *, int); |
c906108c | 236 | |
a14ed312 | 237 | int mips_set_processor_type (char *); |
c906108c | 238 | |
a14ed312 | 239 | static void mips_show_processor_type_command (char *, int); |
c906108c | 240 | |
a14ed312 | 241 | static void reinit_frame_cache_sfunc (char *, int, struct cmd_list_element *); |
c906108c SS |
242 | |
243 | static mips_extra_func_info_t | |
479412cd | 244 | find_proc_desc (CORE_ADDR pc, struct frame_info *next_frame, int cur_frame); |
c906108c | 245 | |
a14ed312 KB |
246 | static CORE_ADDR after_prologue (CORE_ADDR pc, |
247 | mips_extra_func_info_t proc_desc); | |
c906108c | 248 | |
dd824b04 DJ |
249 | static void mips_read_fp_register_single (int regno, char *rare_buffer); |
250 | static void mips_read_fp_register_double (int regno, char *rare_buffer); | |
251 | ||
67b2c998 DJ |
252 | static struct type *mips_float_register_type (void); |
253 | static struct type *mips_double_register_type (void); | |
254 | ||
c906108c SS |
255 | /* This value is the model of MIPS in use. It is derived from the value |
256 | of the PrID register. */ | |
257 | ||
258 | char *mips_processor_type; | |
259 | ||
260 | char *tmp_mips_processor_type; | |
261 | ||
acdb74a0 AC |
262 | /* The list of available "set mips " and "show mips " commands */ |
263 | ||
264 | static struct cmd_list_element *setmipscmdlist = NULL; | |
265 | static struct cmd_list_element *showmipscmdlist = NULL; | |
266 | ||
c906108c SS |
267 | /* A set of original names, to be used when restoring back to generic |
268 | registers from a specific set. */ | |
269 | ||
cce74817 JM |
270 | char *mips_generic_reg_names[] = MIPS_REGISTER_NAMES; |
271 | char **mips_processor_reg_names = mips_generic_reg_names; | |
272 | ||
273 | char * | |
fba45db2 | 274 | mips_register_name (int i) |
cce74817 JM |
275 | { |
276 | return mips_processor_reg_names[i]; | |
277 | } | |
9846de1b | 278 | /* *INDENT-OFF* */ |
c906108c SS |
279 | /* Names of IDT R3041 registers. */ |
280 | ||
281 | char *mips_r3041_reg_names[] = { | |
282 | "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3", | |
283 | "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", | |
284 | "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7", | |
285 | "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra", | |
286 | "sr", "lo", "hi", "bad", "cause","pc", | |
287 | "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", | |
288 | "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", | |
289 | "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23", | |
290 | "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", | |
291 | "fsr", "fir", "fp", "", | |
292 | "", "", "bus", "ccfg", "", "", "", "", | |
293 | "", "", "port", "cmp", "", "", "epc", "prid", | |
294 | }; | |
295 | ||
296 | /* Names of IDT R3051 registers. */ | |
297 | ||
298 | char *mips_r3051_reg_names[] = { | |
299 | "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3", | |
300 | "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", | |
301 | "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7", | |
302 | "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra", | |
303 | "sr", "lo", "hi", "bad", "cause","pc", | |
304 | "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", | |
305 | "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", | |
306 | "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23", | |
307 | "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", | |
308 | "fsr", "fir", "fp", "", | |
309 | "inx", "rand", "elo", "", "ctxt", "", "", "", | |
310 | "", "", "ehi", "", "", "", "epc", "prid", | |
311 | }; | |
312 | ||
313 | /* Names of IDT R3081 registers. */ | |
314 | ||
315 | char *mips_r3081_reg_names[] = { | |
316 | "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3", | |
317 | "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", | |
318 | "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7", | |
319 | "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra", | |
320 | "sr", "lo", "hi", "bad", "cause","pc", | |
321 | "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", | |
322 | "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", | |
323 | "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23", | |
324 | "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", | |
325 | "fsr", "fir", "fp", "", | |
326 | "inx", "rand", "elo", "cfg", "ctxt", "", "", "", | |
327 | "", "", "ehi", "", "", "", "epc", "prid", | |
328 | }; | |
329 | ||
330 | /* Names of LSI 33k registers. */ | |
331 | ||
332 | char *mips_lsi33k_reg_names[] = { | |
333 | "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3", | |
334 | "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", | |
335 | "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7", | |
336 | "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra", | |
337 | "epc", "hi", "lo", "sr", "cause","badvaddr", | |
338 | "dcic", "bpc", "bda", "", "", "", "", "", | |
339 | "", "", "", "", "", "", "", "", | |
340 | "", "", "", "", "", "", "", "", | |
341 | "", "", "", "", "", "", "", "", | |
342 | "", "", "", "", | |
343 | "", "", "", "", "", "", "", "", | |
344 | "", "", "", "", "", "", "", "", | |
345 | }; | |
346 | ||
347 | struct { | |
348 | char *name; | |
349 | char **regnames; | |
350 | } mips_processor_type_table[] = { | |
351 | { "generic", mips_generic_reg_names }, | |
352 | { "r3041", mips_r3041_reg_names }, | |
353 | { "r3051", mips_r3051_reg_names }, | |
354 | { "r3071", mips_r3081_reg_names }, | |
355 | { "r3081", mips_r3081_reg_names }, | |
356 | { "lsi33k", mips_lsi33k_reg_names }, | |
357 | { NULL, NULL } | |
358 | }; | |
9846de1b | 359 | /* *INDENT-ON* */ |
c906108c | 360 | |
c5aa993b JM |
361 | |
362 | ||
363 | ||
c906108c | 364 | /* Table to translate MIPS16 register field to actual register number. */ |
c5aa993b JM |
365 | static int mips16_to_32_reg[8] = |
366 | {16, 17, 2, 3, 4, 5, 6, 7}; | |
c906108c SS |
367 | |
368 | /* Heuristic_proc_start may hunt through the text section for a long | |
369 | time across a 2400 baud serial line. Allows the user to limit this | |
370 | search. */ | |
371 | ||
372 | static unsigned int heuristic_fence_post = 0; | |
373 | ||
c5aa993b JM |
374 | #define PROC_LOW_ADDR(proc) ((proc)->pdr.adr) /* least address */ |
375 | #define PROC_HIGH_ADDR(proc) ((proc)->high_addr) /* upper address bound */ | |
c906108c SS |
376 | #define PROC_FRAME_OFFSET(proc) ((proc)->pdr.frameoffset) |
377 | #define PROC_FRAME_REG(proc) ((proc)->pdr.framereg) | |
378 | #define PROC_FRAME_ADJUST(proc) ((proc)->frame_adjust) | |
379 | #define PROC_REG_MASK(proc) ((proc)->pdr.regmask) | |
380 | #define PROC_FREG_MASK(proc) ((proc)->pdr.fregmask) | |
381 | #define PROC_REG_OFFSET(proc) ((proc)->pdr.regoffset) | |
382 | #define PROC_FREG_OFFSET(proc) ((proc)->pdr.fregoffset) | |
383 | #define PROC_PC_REG(proc) ((proc)->pdr.pcreg) | |
384 | #define PROC_SYMBOL(proc) (*(struct symbol**)&(proc)->pdr.isym) | |
385 | #define _PROC_MAGIC_ 0x0F0F0F0F | |
386 | #define PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym == _PROC_MAGIC_) | |
387 | #define SET_PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym = _PROC_MAGIC_) | |
388 | ||
389 | struct linked_proc_info | |
c5aa993b JM |
390 | { |
391 | struct mips_extra_func_info info; | |
392 | struct linked_proc_info *next; | |
393 | } | |
394 | *linked_proc_desc_table = NULL; | |
c906108c | 395 | |
cce74817 | 396 | void |
acdb74a0 | 397 | mips_print_extra_frame_info (struct frame_info *fi) |
cce74817 JM |
398 | { |
399 | if (fi | |
400 | && fi->extra_info | |
401 | && fi->extra_info->proc_desc | |
402 | && fi->extra_info->proc_desc->pdr.framereg < NUM_REGS) | |
d4f3574e | 403 | printf_filtered (" frame pointer is at %s+%s\n", |
cce74817 | 404 | REGISTER_NAME (fi->extra_info->proc_desc->pdr.framereg), |
d4f3574e | 405 | paddr_d (fi->extra_info->proc_desc->pdr.frameoffset)); |
cce74817 | 406 | } |
c906108c | 407 | |
46cd78fb AC |
408 | /* Number of bytes of storage in the actual machine representation for |
409 | register N. NOTE: This indirectly defines the register size | |
410 | transfered by the GDB protocol. */ | |
43e526b9 JM |
411 | |
412 | static int mips64_transfers_32bit_regs_p = 0; | |
413 | ||
414 | int | |
acdb74a0 | 415 | mips_register_raw_size (int reg_nr) |
43e526b9 JM |
416 | { |
417 | if (mips64_transfers_32bit_regs_p) | |
418 | return REGISTER_VIRTUAL_SIZE (reg_nr); | |
d02ee681 AC |
419 | else if (reg_nr >= FP0_REGNUM && reg_nr < FP0_REGNUM + 32 |
420 | && FP_REGISTER_DOUBLE) | |
421 | /* For MIPS_ABI_N32 (for example) we need 8 byte floating point | |
422 | registers. */ | |
423 | return 8; | |
43e526b9 JM |
424 | else |
425 | return MIPS_REGSIZE; | |
426 | } | |
427 | ||
46cd78fb AC |
428 | /* Convert between RAW and VIRTUAL registers. The RAW register size |
429 | defines the remote-gdb packet. */ | |
430 | ||
43e526b9 | 431 | int |
acdb74a0 | 432 | mips_register_convertible (int reg_nr) |
43e526b9 JM |
433 | { |
434 | if (mips64_transfers_32bit_regs_p) | |
435 | return 0; | |
436 | else | |
437 | return (REGISTER_RAW_SIZE (reg_nr) > REGISTER_VIRTUAL_SIZE (reg_nr)); | |
438 | } | |
439 | ||
440 | void | |
acdb74a0 AC |
441 | mips_register_convert_to_virtual (int n, struct type *virtual_type, |
442 | char *raw_buf, char *virt_buf) | |
43e526b9 | 443 | { |
d7449b42 | 444 | if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) |
43e526b9 JM |
445 | memcpy (virt_buf, |
446 | raw_buf + (REGISTER_RAW_SIZE (n) - TYPE_LENGTH (virtual_type)), | |
447 | TYPE_LENGTH (virtual_type)); | |
448 | else | |
449 | memcpy (virt_buf, | |
450 | raw_buf, | |
451 | TYPE_LENGTH (virtual_type)); | |
452 | } | |
453 | ||
454 | void | |
acdb74a0 AC |
455 | mips_register_convert_to_raw (struct type *virtual_type, int n, |
456 | char *virt_buf, char *raw_buf) | |
43e526b9 JM |
457 | { |
458 | memset (raw_buf, 0, REGISTER_RAW_SIZE (n)); | |
d7449b42 | 459 | if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) |
43e526b9 JM |
460 | memcpy (raw_buf + (REGISTER_RAW_SIZE (n) - TYPE_LENGTH (virtual_type)), |
461 | virt_buf, | |
462 | TYPE_LENGTH (virtual_type)); | |
463 | else | |
464 | memcpy (raw_buf, | |
465 | virt_buf, | |
466 | TYPE_LENGTH (virtual_type)); | |
467 | } | |
468 | ||
c906108c | 469 | /* Should the upper word of 64-bit addresses be zeroed? */ |
4014092b AC |
470 | enum cmd_auto_boolean mask_address_var = CMD_AUTO_BOOLEAN_AUTO; |
471 | ||
472 | static int | |
473 | mips_mask_address_p (void) | |
474 | { | |
475 | switch (mask_address_var) | |
476 | { | |
477 | case CMD_AUTO_BOOLEAN_TRUE: | |
478 | return 1; | |
479 | case CMD_AUTO_BOOLEAN_FALSE: | |
480 | return 0; | |
481 | break; | |
482 | case CMD_AUTO_BOOLEAN_AUTO: | |
92e1c15c | 483 | return MIPS_DEFAULT_MASK_ADDRESS_P; |
4014092b | 484 | default: |
8e65ff28 AC |
485 | internal_error (__FILE__, __LINE__, |
486 | "mips_mask_address_p: bad switch"); | |
4014092b | 487 | return -1; |
361d1df0 | 488 | } |
4014092b AC |
489 | } |
490 | ||
491 | static void | |
492 | show_mask_address (char *cmd, int from_tty) | |
493 | { | |
494 | switch (mask_address_var) | |
495 | { | |
496 | case CMD_AUTO_BOOLEAN_TRUE: | |
497 | printf_filtered ("The 32 bit mips address mask is enabled\n"); | |
498 | break; | |
499 | case CMD_AUTO_BOOLEAN_FALSE: | |
500 | printf_filtered ("The 32 bit mips address mask is disabled\n"); | |
501 | break; | |
502 | case CMD_AUTO_BOOLEAN_AUTO: | |
503 | printf_filtered ("The 32 bit address mask is set automatically. Currently %s\n", | |
504 | mips_mask_address_p () ? "enabled" : "disabled"); | |
505 | break; | |
506 | default: | |
8e65ff28 AC |
507 | internal_error (__FILE__, __LINE__, |
508 | "show_mask_address: bad switch"); | |
4014092b | 509 | break; |
361d1df0 | 510 | } |
4014092b | 511 | } |
c906108c SS |
512 | |
513 | /* Should call_function allocate stack space for a struct return? */ | |
514 | int | |
fba45db2 | 515 | mips_use_struct_convention (int gcc_p, struct type *type) |
c906108c SS |
516 | { |
517 | if (MIPS_EABI) | |
7a292a7a | 518 | return (TYPE_LENGTH (type) > 2 * MIPS_SAVED_REGSIZE); |
c906108c | 519 | else |
c5aa993b | 520 | return 1; /* Structures are returned by ref in extra arg0 */ |
c906108c SS |
521 | } |
522 | ||
523 | /* Tell if the program counter value in MEMADDR is in a MIPS16 function. */ | |
524 | ||
525 | static int | |
526 | pc_is_mips16 (bfd_vma memaddr) | |
527 | { | |
528 | struct minimal_symbol *sym; | |
529 | ||
530 | /* If bit 0 of the address is set, assume this is a MIPS16 address. */ | |
531 | if (IS_MIPS16_ADDR (memaddr)) | |
532 | return 1; | |
533 | ||
534 | /* A flag indicating that this is a MIPS16 function is stored by elfread.c in | |
535 | the high bit of the info field. Use this to decide if the function is | |
536 | MIPS16 or normal MIPS. */ | |
537 | sym = lookup_minimal_symbol_by_pc (memaddr); | |
538 | if (sym) | |
539 | return MSYMBOL_IS_SPECIAL (sym); | |
540 | else | |
541 | return 0; | |
542 | } | |
543 | ||
6c997a34 AC |
544 | /* MIPS believes that the PC has a sign extended value. Perhaphs the |
545 | all registers should be sign extended for simplicity? */ | |
546 | ||
547 | static CORE_ADDR | |
39f77062 | 548 | mips_read_pc (ptid_t ptid) |
6c997a34 | 549 | { |
39f77062 | 550 | return read_signed_register_pid (PC_REGNUM, ptid); |
6c997a34 | 551 | } |
c906108c SS |
552 | |
553 | /* This returns the PC of the first inst after the prologue. If we can't | |
554 | find the prologue, then return 0. */ | |
555 | ||
556 | static CORE_ADDR | |
acdb74a0 AC |
557 | after_prologue (CORE_ADDR pc, |
558 | mips_extra_func_info_t proc_desc) | |
c906108c SS |
559 | { |
560 | struct symtab_and_line sal; | |
561 | CORE_ADDR func_addr, func_end; | |
562 | ||
479412cd DJ |
563 | /* Pass cur_frame == 0 to find_proc_desc. We should not attempt |
564 | to read the stack pointer from the current machine state, because | |
565 | the current machine state has nothing to do with the information | |
566 | we need from the proc_desc; and the process may or may not exist | |
567 | right now. */ | |
c906108c | 568 | if (!proc_desc) |
479412cd | 569 | proc_desc = find_proc_desc (pc, NULL, 0); |
c906108c SS |
570 | |
571 | if (proc_desc) | |
572 | { | |
573 | /* If function is frameless, then we need to do it the hard way. I | |
c5aa993b | 574 | strongly suspect that frameless always means prologueless... */ |
c906108c SS |
575 | if (PROC_FRAME_REG (proc_desc) == SP_REGNUM |
576 | && PROC_FRAME_OFFSET (proc_desc) == 0) | |
577 | return 0; | |
578 | } | |
579 | ||
580 | if (!find_pc_partial_function (pc, NULL, &func_addr, &func_end)) | |
581 | return 0; /* Unknown */ | |
582 | ||
583 | sal = find_pc_line (func_addr, 0); | |
584 | ||
585 | if (sal.end < func_end) | |
586 | return sal.end; | |
587 | ||
588 | /* The line after the prologue is after the end of the function. In this | |
589 | case, tell the caller to find the prologue the hard way. */ | |
590 | ||
591 | return 0; | |
592 | } | |
593 | ||
594 | /* Decode a MIPS32 instruction that saves a register in the stack, and | |
595 | set the appropriate bit in the general register mask or float register mask | |
596 | to indicate which register is saved. This is a helper function | |
597 | for mips_find_saved_regs. */ | |
598 | ||
599 | static void | |
acdb74a0 AC |
600 | mips32_decode_reg_save (t_inst inst, unsigned long *gen_mask, |
601 | unsigned long *float_mask) | |
c906108c SS |
602 | { |
603 | int reg; | |
604 | ||
605 | if ((inst & 0xffe00000) == 0xafa00000 /* sw reg,n($sp) */ | |
606 | || (inst & 0xffe00000) == 0xafc00000 /* sw reg,n($r30) */ | |
607 | || (inst & 0xffe00000) == 0xffa00000) /* sd reg,n($sp) */ | |
608 | { | |
609 | /* It might be possible to use the instruction to | |
c5aa993b JM |
610 | find the offset, rather than the code below which |
611 | is based on things being in a certain order in the | |
612 | frame, but figuring out what the instruction's offset | |
613 | is relative to might be a little tricky. */ | |
c906108c SS |
614 | reg = (inst & 0x001f0000) >> 16; |
615 | *gen_mask |= (1 << reg); | |
616 | } | |
617 | else if ((inst & 0xffe00000) == 0xe7a00000 /* swc1 freg,n($sp) */ | |
c5aa993b JM |
618 | || (inst & 0xffe00000) == 0xe7c00000 /* swc1 freg,n($r30) */ |
619 | || (inst & 0xffe00000) == 0xf7a00000) /* sdc1 freg,n($sp) */ | |
c906108c SS |
620 | |
621 | { | |
622 | reg = ((inst & 0x001f0000) >> 16); | |
623 | *float_mask |= (1 << reg); | |
624 | } | |
625 | } | |
626 | ||
627 | /* Decode a MIPS16 instruction that saves a register in the stack, and | |
628 | set the appropriate bit in the general register or float register mask | |
629 | to indicate which register is saved. This is a helper function | |
630 | for mips_find_saved_regs. */ | |
631 | ||
632 | static void | |
acdb74a0 | 633 | mips16_decode_reg_save (t_inst inst, unsigned long *gen_mask) |
c906108c | 634 | { |
c5aa993b | 635 | if ((inst & 0xf800) == 0xd000) /* sw reg,n($sp) */ |
c906108c SS |
636 | { |
637 | int reg = mips16_to_32_reg[(inst & 0x700) >> 8]; | |
638 | *gen_mask |= (1 << reg); | |
639 | } | |
c5aa993b | 640 | else if ((inst & 0xff00) == 0xf900) /* sd reg,n($sp) */ |
c906108c SS |
641 | { |
642 | int reg = mips16_to_32_reg[(inst & 0xe0) >> 5]; | |
643 | *gen_mask |= (1 << reg); | |
644 | } | |
c5aa993b | 645 | else if ((inst & 0xff00) == 0x6200 /* sw $ra,n($sp) */ |
c906108c SS |
646 | || (inst & 0xff00) == 0xfa00) /* sd $ra,n($sp) */ |
647 | *gen_mask |= (1 << RA_REGNUM); | |
648 | } | |
649 | ||
650 | ||
651 | /* Fetch and return instruction from the specified location. If the PC | |
652 | is odd, assume it's a MIPS16 instruction; otherwise MIPS32. */ | |
653 | ||
654 | static t_inst | |
acdb74a0 | 655 | mips_fetch_instruction (CORE_ADDR addr) |
c906108c SS |
656 | { |
657 | char buf[MIPS_INSTLEN]; | |
658 | int instlen; | |
659 | int status; | |
660 | ||
661 | if (pc_is_mips16 (addr)) | |
662 | { | |
663 | instlen = MIPS16_INSTLEN; | |
664 | addr = UNMAKE_MIPS16_ADDR (addr); | |
665 | } | |
666 | else | |
c5aa993b | 667 | instlen = MIPS_INSTLEN; |
c906108c SS |
668 | status = read_memory_nobpt (addr, buf, instlen); |
669 | if (status) | |
670 | memory_error (status, addr); | |
671 | return extract_unsigned_integer (buf, instlen); | |
672 | } | |
673 | ||
674 | ||
675 | /* These the fields of 32 bit mips instructions */ | |
e135b889 DJ |
676 | #define mips32_op(x) (x >> 26) |
677 | #define itype_op(x) (x >> 26) | |
678 | #define itype_rs(x) ((x >> 21) & 0x1f) | |
c906108c | 679 | #define itype_rt(x) ((x >> 16) & 0x1f) |
e135b889 | 680 | #define itype_immediate(x) (x & 0xffff) |
c906108c | 681 | |
e135b889 DJ |
682 | #define jtype_op(x) (x >> 26) |
683 | #define jtype_target(x) (x & 0x03ffffff) | |
c906108c | 684 | |
e135b889 DJ |
685 | #define rtype_op(x) (x >> 26) |
686 | #define rtype_rs(x) ((x >> 21) & 0x1f) | |
687 | #define rtype_rt(x) ((x >> 16) & 0x1f) | |
688 | #define rtype_rd(x) ((x >> 11) & 0x1f) | |
689 | #define rtype_shamt(x) ((x >> 6) & 0x1f) | |
690 | #define rtype_funct(x) (x & 0x3f) | |
c906108c SS |
691 | |
692 | static CORE_ADDR | |
c5aa993b JM |
693 | mips32_relative_offset (unsigned long inst) |
694 | { | |
695 | long x; | |
696 | x = itype_immediate (inst); | |
697 | if (x & 0x8000) /* sign bit set */ | |
c906108c | 698 | { |
c5aa993b | 699 | x |= 0xffff0000; /* sign extension */ |
c906108c | 700 | } |
c5aa993b JM |
701 | x = x << 2; |
702 | return x; | |
c906108c SS |
703 | } |
704 | ||
705 | /* Determine whate to set a single step breakpoint while considering | |
706 | branch prediction */ | |
707 | CORE_ADDR | |
c5aa993b JM |
708 | mips32_next_pc (CORE_ADDR pc) |
709 | { | |
710 | unsigned long inst; | |
711 | int op; | |
712 | inst = mips_fetch_instruction (pc); | |
e135b889 | 713 | if ((inst & 0xe0000000) != 0) /* Not a special, jump or branch instruction */ |
c5aa993b | 714 | { |
e135b889 DJ |
715 | if (itype_op (inst) >> 2 == 5) |
716 | /* BEQL, BNEL, BLEZL, BGTZL: bits 0101xx */ | |
c5aa993b | 717 | { |
e135b889 | 718 | op = (itype_op (inst) & 0x03); |
c906108c SS |
719 | switch (op) |
720 | { | |
e135b889 DJ |
721 | case 0: /* BEQL */ |
722 | goto equal_branch; | |
723 | case 1: /* BNEL */ | |
724 | goto neq_branch; | |
725 | case 2: /* BLEZL */ | |
726 | goto less_branch; | |
727 | case 3: /* BGTZ */ | |
728 | goto greater_branch; | |
c5aa993b JM |
729 | default: |
730 | pc += 4; | |
c906108c SS |
731 | } |
732 | } | |
e135b889 DJ |
733 | else if (itype_op (inst) == 17 && itype_rs (inst) == 8) |
734 | /* BC1F, BC1FL, BC1T, BC1TL: 010001 01000 */ | |
735 | { | |
736 | int tf = itype_rt (inst) & 0x01; | |
737 | int cnum = itype_rt (inst) >> 2; | |
738 | int fcrcs = read_signed_register (FCRCS_REGNUM); | |
739 | int cond = ((fcrcs >> 24) & 0x0e) | ((fcrcs >> 23) & 0x01); | |
740 | ||
741 | if (((cond >> cnum) & 0x01) == tf) | |
742 | pc += mips32_relative_offset (inst) + 4; | |
743 | else | |
744 | pc += 8; | |
745 | } | |
c5aa993b JM |
746 | else |
747 | pc += 4; /* Not a branch, next instruction is easy */ | |
c906108c SS |
748 | } |
749 | else | |
c5aa993b JM |
750 | { /* This gets way messy */ |
751 | ||
c906108c | 752 | /* Further subdivide into SPECIAL, REGIMM and other */ |
e135b889 | 753 | switch (op = itype_op (inst) & 0x07) /* extract bits 28,27,26 */ |
c906108c | 754 | { |
c5aa993b JM |
755 | case 0: /* SPECIAL */ |
756 | op = rtype_funct (inst); | |
757 | switch (op) | |
758 | { | |
759 | case 8: /* JR */ | |
760 | case 9: /* JALR */ | |
6c997a34 AC |
761 | /* Set PC to that address */ |
762 | pc = read_signed_register (rtype_rs (inst)); | |
c5aa993b JM |
763 | break; |
764 | default: | |
765 | pc += 4; | |
766 | } | |
767 | ||
e135b889 | 768 | break; /* end SPECIAL */ |
c5aa993b | 769 | case 1: /* REGIMM */ |
c906108c | 770 | { |
e135b889 DJ |
771 | op = itype_rt (inst); /* branch condition */ |
772 | switch (op) | |
c906108c | 773 | { |
c5aa993b | 774 | case 0: /* BLTZ */ |
e135b889 DJ |
775 | case 2: /* BLTZL */ |
776 | case 16: /* BLTZAL */ | |
c5aa993b | 777 | case 18: /* BLTZALL */ |
c906108c | 778 | less_branch: |
6c997a34 | 779 | if (read_signed_register (itype_rs (inst)) < 0) |
c5aa993b JM |
780 | pc += mips32_relative_offset (inst) + 4; |
781 | else | |
782 | pc += 8; /* after the delay slot */ | |
783 | break; | |
e135b889 | 784 | case 1: /* BGEZ */ |
c5aa993b JM |
785 | case 3: /* BGEZL */ |
786 | case 17: /* BGEZAL */ | |
787 | case 19: /* BGEZALL */ | |
c906108c | 788 | greater_equal_branch: |
6c997a34 | 789 | if (read_signed_register (itype_rs (inst)) >= 0) |
c5aa993b JM |
790 | pc += mips32_relative_offset (inst) + 4; |
791 | else | |
792 | pc += 8; /* after the delay slot */ | |
793 | break; | |
e135b889 | 794 | /* All of the other instructions in the REGIMM category */ |
c5aa993b JM |
795 | default: |
796 | pc += 4; | |
c906108c SS |
797 | } |
798 | } | |
e135b889 | 799 | break; /* end REGIMM */ |
c5aa993b JM |
800 | case 2: /* J */ |
801 | case 3: /* JAL */ | |
802 | { | |
803 | unsigned long reg; | |
804 | reg = jtype_target (inst) << 2; | |
e135b889 | 805 | /* Upper four bits get never changed... */ |
c5aa993b | 806 | pc = reg + ((pc + 4) & 0xf0000000); |
c906108c | 807 | } |
c5aa993b JM |
808 | break; |
809 | /* FIXME case JALX : */ | |
810 | { | |
811 | unsigned long reg; | |
812 | reg = jtype_target (inst) << 2; | |
813 | pc = reg + ((pc + 4) & 0xf0000000) + 1; /* yes, +1 */ | |
c906108c SS |
814 | /* Add 1 to indicate 16 bit mode - Invert ISA mode */ |
815 | } | |
c5aa993b | 816 | break; /* The new PC will be alternate mode */ |
e135b889 | 817 | case 4: /* BEQ, BEQL */ |
c5aa993b | 818 | equal_branch: |
6c997a34 AC |
819 | if (read_signed_register (itype_rs (inst)) == |
820 | read_signed_register (itype_rt (inst))) | |
c5aa993b JM |
821 | pc += mips32_relative_offset (inst) + 4; |
822 | else | |
823 | pc += 8; | |
824 | break; | |
e135b889 | 825 | case 5: /* BNE, BNEL */ |
c5aa993b | 826 | neq_branch: |
6c997a34 | 827 | if (read_signed_register (itype_rs (inst)) != |
e135b889 | 828 | read_signed_register (itype_rt (inst))) |
c5aa993b JM |
829 | pc += mips32_relative_offset (inst) + 4; |
830 | else | |
831 | pc += 8; | |
832 | break; | |
e135b889 | 833 | case 6: /* BLEZ, BLEZL */ |
c906108c | 834 | less_zero_branch: |
6c997a34 | 835 | if (read_signed_register (itype_rs (inst) <= 0)) |
c5aa993b JM |
836 | pc += mips32_relative_offset (inst) + 4; |
837 | else | |
838 | pc += 8; | |
839 | break; | |
840 | case 7: | |
e135b889 DJ |
841 | default: |
842 | greater_branch: /* BGTZ, BGTZL */ | |
6c997a34 | 843 | if (read_signed_register (itype_rs (inst) > 0)) |
c5aa993b JM |
844 | pc += mips32_relative_offset (inst) + 4; |
845 | else | |
846 | pc += 8; | |
847 | break; | |
c5aa993b JM |
848 | } /* switch */ |
849 | } /* else */ | |
850 | return pc; | |
851 | } /* mips32_next_pc */ | |
c906108c SS |
852 | |
853 | /* Decoding the next place to set a breakpoint is irregular for the | |
e26cc349 | 854 | mips 16 variant, but fortunately, there fewer instructions. We have to cope |
c906108c SS |
855 | ith extensions for 16 bit instructions and a pair of actual 32 bit instructions. |
856 | We dont want to set a single step instruction on the extend instruction | |
857 | either. | |
c5aa993b | 858 | */ |
c906108c SS |
859 | |
860 | /* Lots of mips16 instruction formats */ | |
861 | /* Predicting jumps requires itype,ritype,i8type | |
862 | and their extensions extItype,extritype,extI8type | |
c5aa993b | 863 | */ |
c906108c SS |
864 | enum mips16_inst_fmts |
865 | { | |
c5aa993b JM |
866 | itype, /* 0 immediate 5,10 */ |
867 | ritype, /* 1 5,3,8 */ | |
868 | rrtype, /* 2 5,3,3,5 */ | |
869 | rritype, /* 3 5,3,3,5 */ | |
870 | rrrtype, /* 4 5,3,3,3,2 */ | |
871 | rriatype, /* 5 5,3,3,1,4 */ | |
872 | shifttype, /* 6 5,3,3,3,2 */ | |
873 | i8type, /* 7 5,3,8 */ | |
874 | i8movtype, /* 8 5,3,3,5 */ | |
875 | i8mov32rtype, /* 9 5,3,5,3 */ | |
876 | i64type, /* 10 5,3,8 */ | |
877 | ri64type, /* 11 5,3,3,5 */ | |
878 | jalxtype, /* 12 5,1,5,5,16 - a 32 bit instruction */ | |
879 | exiItype, /* 13 5,6,5,5,1,1,1,1,1,1,5 */ | |
880 | extRitype, /* 14 5,6,5,5,3,1,1,1,5 */ | |
881 | extRRItype, /* 15 5,5,5,5,3,3,5 */ | |
882 | extRRIAtype, /* 16 5,7,4,5,3,3,1,4 */ | |
883 | EXTshifttype, /* 17 5,5,1,1,1,1,1,1,5,3,3,1,1,1,2 */ | |
884 | extI8type, /* 18 5,6,5,5,3,1,1,1,5 */ | |
885 | extI64type, /* 19 5,6,5,5,3,1,1,1,5 */ | |
886 | extRi64type, /* 20 5,6,5,5,3,3,5 */ | |
887 | extshift64type /* 21 5,5,1,1,1,1,1,1,5,1,1,1,3,5 */ | |
888 | }; | |
12f02c2a AC |
889 | /* I am heaping all the fields of the formats into one structure and |
890 | then, only the fields which are involved in instruction extension */ | |
c906108c | 891 | struct upk_mips16 |
c5aa993b | 892 | { |
12f02c2a | 893 | CORE_ADDR offset; |
c5aa993b JM |
894 | unsigned int regx; /* Function in i8 type */ |
895 | unsigned int regy; | |
896 | }; | |
c906108c SS |
897 | |
898 | ||
12f02c2a AC |
899 | /* The EXT-I, EXT-ri nad EXT-I8 instructions all have the same format |
900 | for the bits which make up the immediatate extension. */ | |
c906108c | 901 | |
12f02c2a AC |
902 | static CORE_ADDR |
903 | extended_offset (unsigned int extension) | |
c906108c | 904 | { |
12f02c2a | 905 | CORE_ADDR value; |
c5aa993b JM |
906 | value = (extension >> 21) & 0x3f; /* * extract 15:11 */ |
907 | value = value << 6; | |
908 | value |= (extension >> 16) & 0x1f; /* extrace 10:5 */ | |
909 | value = value << 5; | |
910 | value |= extension & 0x01f; /* extract 4:0 */ | |
911 | return value; | |
c906108c SS |
912 | } |
913 | ||
914 | /* Only call this function if you know that this is an extendable | |
915 | instruction, It wont malfunction, but why make excess remote memory references? | |
916 | If the immediate operands get sign extended or somthing, do it after | |
917 | the extension is performed. | |
c5aa993b | 918 | */ |
c906108c SS |
919 | /* FIXME: Every one of these cases needs to worry about sign extension |
920 | when the offset is to be used in relative addressing */ | |
921 | ||
922 | ||
12f02c2a | 923 | static unsigned int |
c5aa993b | 924 | fetch_mips_16 (CORE_ADDR pc) |
c906108c | 925 | { |
c5aa993b JM |
926 | char buf[8]; |
927 | pc &= 0xfffffffe; /* clear the low order bit */ | |
928 | target_read_memory (pc, buf, 2); | |
929 | return extract_unsigned_integer (buf, 2); | |
c906108c SS |
930 | } |
931 | ||
932 | static void | |
c5aa993b | 933 | unpack_mips16 (CORE_ADDR pc, |
12f02c2a AC |
934 | unsigned int extension, |
935 | unsigned int inst, | |
936 | enum mips16_inst_fmts insn_format, | |
c5aa993b | 937 | struct upk_mips16 *upk) |
c906108c | 938 | { |
12f02c2a AC |
939 | CORE_ADDR offset; |
940 | int regx; | |
941 | int regy; | |
942 | switch (insn_format) | |
c906108c | 943 | { |
c5aa993b | 944 | case itype: |
c906108c | 945 | { |
12f02c2a AC |
946 | CORE_ADDR value; |
947 | if (extension) | |
c5aa993b JM |
948 | { |
949 | value = extended_offset (extension); | |
950 | value = value << 11; /* rom for the original value */ | |
12f02c2a | 951 | value |= inst & 0x7ff; /* eleven bits from instruction */ |
c906108c SS |
952 | } |
953 | else | |
c5aa993b | 954 | { |
12f02c2a | 955 | value = inst & 0x7ff; |
c5aa993b | 956 | /* FIXME : Consider sign extension */ |
c906108c | 957 | } |
12f02c2a AC |
958 | offset = value; |
959 | regx = -1; | |
960 | regy = -1; | |
c906108c | 961 | } |
c5aa993b JM |
962 | break; |
963 | case ritype: | |
964 | case i8type: | |
965 | { /* A register identifier and an offset */ | |
c906108c SS |
966 | /* Most of the fields are the same as I type but the |
967 | immediate value is of a different length */ | |
12f02c2a AC |
968 | CORE_ADDR value; |
969 | if (extension) | |
c906108c | 970 | { |
c5aa993b JM |
971 | value = extended_offset (extension); |
972 | value = value << 8; /* from the original instruction */ | |
12f02c2a AC |
973 | value |= inst & 0xff; /* eleven bits from instruction */ |
974 | regx = (extension >> 8) & 0x07; /* or i8 funct */ | |
c5aa993b JM |
975 | if (value & 0x4000) /* test the sign bit , bit 26 */ |
976 | { | |
977 | value &= ~0x3fff; /* remove the sign bit */ | |
978 | value = -value; | |
c906108c SS |
979 | } |
980 | } | |
c5aa993b JM |
981 | else |
982 | { | |
12f02c2a AC |
983 | value = inst & 0xff; /* 8 bits */ |
984 | regx = (inst >> 8) & 0x07; /* or i8 funct */ | |
c5aa993b JM |
985 | /* FIXME: Do sign extension , this format needs it */ |
986 | if (value & 0x80) /* THIS CONFUSES ME */ | |
987 | { | |
988 | value &= 0xef; /* remove the sign bit */ | |
989 | value = -value; | |
990 | } | |
c5aa993b | 991 | } |
12f02c2a AC |
992 | offset = value; |
993 | regy = -1; | |
c5aa993b | 994 | break; |
c906108c | 995 | } |
c5aa993b | 996 | case jalxtype: |
c906108c | 997 | { |
c5aa993b | 998 | unsigned long value; |
12f02c2a AC |
999 | unsigned int nexthalf; |
1000 | value = ((inst & 0x1f) << 5) | ((inst >> 5) & 0x1f); | |
c5aa993b JM |
1001 | value = value << 16; |
1002 | nexthalf = mips_fetch_instruction (pc + 2); /* low bit still set */ | |
1003 | value |= nexthalf; | |
12f02c2a AC |
1004 | offset = value; |
1005 | regx = -1; | |
1006 | regy = -1; | |
c5aa993b | 1007 | break; |
c906108c SS |
1008 | } |
1009 | default: | |
8e65ff28 AC |
1010 | internal_error (__FILE__, __LINE__, |
1011 | "bad switch"); | |
c906108c | 1012 | } |
12f02c2a AC |
1013 | upk->offset = offset; |
1014 | upk->regx = regx; | |
1015 | upk->regy = regy; | |
c906108c SS |
1016 | } |
1017 | ||
1018 | ||
c5aa993b JM |
1019 | static CORE_ADDR |
1020 | add_offset_16 (CORE_ADDR pc, int offset) | |
c906108c | 1021 | { |
c5aa993b JM |
1022 | return ((offset << 2) | ((pc + 2) & (0xf0000000))); |
1023 | ||
c906108c SS |
1024 | } |
1025 | ||
12f02c2a AC |
1026 | static CORE_ADDR |
1027 | extended_mips16_next_pc (CORE_ADDR pc, | |
1028 | unsigned int extension, | |
1029 | unsigned int insn) | |
c906108c | 1030 | { |
12f02c2a AC |
1031 | int op = (insn >> 11); |
1032 | switch (op) | |
c906108c | 1033 | { |
12f02c2a AC |
1034 | case 2: /* Branch */ |
1035 | { | |
1036 | CORE_ADDR offset; | |
1037 | struct upk_mips16 upk; | |
1038 | unpack_mips16 (pc, extension, insn, itype, &upk); | |
1039 | offset = upk.offset; | |
1040 | if (offset & 0x800) | |
1041 | { | |
1042 | offset &= 0xeff; | |
1043 | offset = -offset; | |
1044 | } | |
1045 | pc += (offset << 1) + 2; | |
1046 | break; | |
1047 | } | |
1048 | case 3: /* JAL , JALX - Watch out, these are 32 bit instruction */ | |
1049 | { | |
1050 | struct upk_mips16 upk; | |
1051 | unpack_mips16 (pc, extension, insn, jalxtype, &upk); | |
1052 | pc = add_offset_16 (pc, upk.offset); | |
1053 | if ((insn >> 10) & 0x01) /* Exchange mode */ | |
1054 | pc = pc & ~0x01; /* Clear low bit, indicate 32 bit mode */ | |
1055 | else | |
1056 | pc |= 0x01; | |
1057 | break; | |
1058 | } | |
1059 | case 4: /* beqz */ | |
1060 | { | |
1061 | struct upk_mips16 upk; | |
1062 | int reg; | |
1063 | unpack_mips16 (pc, extension, insn, ritype, &upk); | |
1064 | reg = read_signed_register (upk.regx); | |
1065 | if (reg == 0) | |
1066 | pc += (upk.offset << 1) + 2; | |
1067 | else | |
1068 | pc += 2; | |
1069 | break; | |
1070 | } | |
1071 | case 5: /* bnez */ | |
1072 | { | |
1073 | struct upk_mips16 upk; | |
1074 | int reg; | |
1075 | unpack_mips16 (pc, extension, insn, ritype, &upk); | |
1076 | reg = read_signed_register (upk.regx); | |
1077 | if (reg != 0) | |
1078 | pc += (upk.offset << 1) + 2; | |
1079 | else | |
1080 | pc += 2; | |
1081 | break; | |
1082 | } | |
1083 | case 12: /* I8 Formats btez btnez */ | |
1084 | { | |
1085 | struct upk_mips16 upk; | |
1086 | int reg; | |
1087 | unpack_mips16 (pc, extension, insn, i8type, &upk); | |
1088 | /* upk.regx contains the opcode */ | |
1089 | reg = read_signed_register (24); /* Test register is 24 */ | |
1090 | if (((upk.regx == 0) && (reg == 0)) /* BTEZ */ | |
1091 | || ((upk.regx == 1) && (reg != 0))) /* BTNEZ */ | |
1092 | /* pc = add_offset_16(pc,upk.offset) ; */ | |
1093 | pc += (upk.offset << 1) + 2; | |
1094 | else | |
1095 | pc += 2; | |
1096 | break; | |
1097 | } | |
1098 | case 29: /* RR Formats JR, JALR, JALR-RA */ | |
1099 | { | |
1100 | struct upk_mips16 upk; | |
1101 | /* upk.fmt = rrtype; */ | |
1102 | op = insn & 0x1f; | |
1103 | if (op == 0) | |
c5aa993b | 1104 | { |
12f02c2a AC |
1105 | int reg; |
1106 | upk.regx = (insn >> 8) & 0x07; | |
1107 | upk.regy = (insn >> 5) & 0x07; | |
1108 | switch (upk.regy) | |
c5aa993b | 1109 | { |
12f02c2a AC |
1110 | case 0: |
1111 | reg = upk.regx; | |
1112 | break; | |
1113 | case 1: | |
1114 | reg = 31; | |
1115 | break; /* Function return instruction */ | |
1116 | case 2: | |
1117 | reg = upk.regx; | |
1118 | break; | |
1119 | default: | |
1120 | reg = 31; | |
1121 | break; /* BOGUS Guess */ | |
c906108c | 1122 | } |
12f02c2a | 1123 | pc = read_signed_register (reg); |
c906108c | 1124 | } |
12f02c2a | 1125 | else |
c5aa993b | 1126 | pc += 2; |
12f02c2a AC |
1127 | break; |
1128 | } | |
1129 | case 30: | |
1130 | /* This is an instruction extension. Fetch the real instruction | |
1131 | (which follows the extension) and decode things based on | |
1132 | that. */ | |
1133 | { | |
1134 | pc += 2; | |
1135 | pc = extended_mips16_next_pc (pc, insn, fetch_mips_16 (pc)); | |
1136 | break; | |
1137 | } | |
1138 | default: | |
1139 | { | |
1140 | pc += 2; | |
1141 | break; | |
1142 | } | |
c906108c | 1143 | } |
c5aa993b | 1144 | return pc; |
12f02c2a | 1145 | } |
c906108c | 1146 | |
12f02c2a AC |
1147 | CORE_ADDR |
1148 | mips16_next_pc (CORE_ADDR pc) | |
1149 | { | |
1150 | unsigned int insn = fetch_mips_16 (pc); | |
1151 | return extended_mips16_next_pc (pc, 0, insn); | |
1152 | } | |
1153 | ||
1154 | /* The mips_next_pc function supports single_step when the remote | |
7e73cedf | 1155 | target monitor or stub is not developed enough to do a single_step. |
12f02c2a AC |
1156 | It works by decoding the current instruction and predicting where a |
1157 | branch will go. This isnt hard because all the data is available. | |
1158 | The MIPS32 and MIPS16 variants are quite different */ | |
c5aa993b JM |
1159 | CORE_ADDR |
1160 | mips_next_pc (CORE_ADDR pc) | |
c906108c | 1161 | { |
c5aa993b JM |
1162 | if (pc & 0x01) |
1163 | return mips16_next_pc (pc); | |
1164 | else | |
1165 | return mips32_next_pc (pc); | |
12f02c2a | 1166 | } |
c906108c SS |
1167 | |
1168 | /* Guaranteed to set fci->saved_regs to some values (it never leaves it | |
1169 | NULL). */ | |
1170 | ||
1171 | void | |
acdb74a0 | 1172 | mips_find_saved_regs (struct frame_info *fci) |
c906108c SS |
1173 | { |
1174 | int ireg; | |
1175 | CORE_ADDR reg_position; | |
1176 | /* r0 bit means kernel trap */ | |
1177 | int kernel_trap; | |
1178 | /* What registers have been saved? Bitmasks. */ | |
1179 | unsigned long gen_mask, float_mask; | |
1180 | mips_extra_func_info_t proc_desc; | |
1181 | t_inst inst; | |
1182 | ||
1183 | frame_saved_regs_zalloc (fci); | |
1184 | ||
1185 | /* If it is the frame for sigtramp, the saved registers are located | |
1186 | in a sigcontext structure somewhere on the stack. | |
1187 | If the stack layout for sigtramp changes we might have to change these | |
1188 | constants and the companion fixup_sigtramp in mdebugread.c */ | |
1189 | #ifndef SIGFRAME_BASE | |
1190 | /* To satisfy alignment restrictions, sigcontext is located 4 bytes | |
1191 | above the sigtramp frame. */ | |
1192 | #define SIGFRAME_BASE MIPS_REGSIZE | |
1193 | /* FIXME! Are these correct?? */ | |
1194 | #define SIGFRAME_PC_OFF (SIGFRAME_BASE + 2 * MIPS_REGSIZE) | |
1195 | #define SIGFRAME_REGSAVE_OFF (SIGFRAME_BASE + 3 * MIPS_REGSIZE) | |
1196 | #define SIGFRAME_FPREGSAVE_OFF \ | |
1197 | (SIGFRAME_REGSAVE_OFF + MIPS_NUMREGS * MIPS_REGSIZE + 3 * MIPS_REGSIZE) | |
1198 | #endif | |
1199 | #ifndef SIGFRAME_REG_SIZE | |
1200 | /* FIXME! Is this correct?? */ | |
1201 | #define SIGFRAME_REG_SIZE MIPS_REGSIZE | |
1202 | #endif | |
1203 | if (fci->signal_handler_caller) | |
1204 | { | |
1205 | for (ireg = 0; ireg < MIPS_NUMREGS; ireg++) | |
1206 | { | |
c5aa993b JM |
1207 | reg_position = fci->frame + SIGFRAME_REGSAVE_OFF |
1208 | + ireg * SIGFRAME_REG_SIZE; | |
1209 | fci->saved_regs[ireg] = reg_position; | |
c906108c SS |
1210 | } |
1211 | for (ireg = 0; ireg < MIPS_NUMREGS; ireg++) | |
1212 | { | |
c5aa993b JM |
1213 | reg_position = fci->frame + SIGFRAME_FPREGSAVE_OFF |
1214 | + ireg * SIGFRAME_REG_SIZE; | |
1215 | fci->saved_regs[FP0_REGNUM + ireg] = reg_position; | |
c906108c SS |
1216 | } |
1217 | fci->saved_regs[PC_REGNUM] = fci->frame + SIGFRAME_PC_OFF; | |
1218 | return; | |
1219 | } | |
1220 | ||
cce74817 | 1221 | proc_desc = fci->extra_info->proc_desc; |
c906108c SS |
1222 | if (proc_desc == NULL) |
1223 | /* I'm not sure how/whether this can happen. Normally when we can't | |
1224 | find a proc_desc, we "synthesize" one using heuristic_proc_desc | |
1225 | and set the saved_regs right away. */ | |
1226 | return; | |
1227 | ||
c5aa993b JM |
1228 | kernel_trap = PROC_REG_MASK (proc_desc) & 1; |
1229 | gen_mask = kernel_trap ? 0xFFFFFFFF : PROC_REG_MASK (proc_desc); | |
1230 | float_mask = kernel_trap ? 0xFFFFFFFF : PROC_FREG_MASK (proc_desc); | |
c906108c | 1231 | |
c5aa993b JM |
1232 | if ( /* In any frame other than the innermost or a frame interrupted by |
1233 | a signal, we assume that all registers have been saved. | |
1234 | This assumes that all register saves in a function happen before | |
1235 | the first function call. */ | |
1236 | (fci->next == NULL || fci->next->signal_handler_caller) | |
c906108c | 1237 | |
c5aa993b JM |
1238 | /* In a dummy frame we know exactly where things are saved. */ |
1239 | && !PROC_DESC_IS_DUMMY (proc_desc) | |
c906108c | 1240 | |
c5aa993b JM |
1241 | /* Don't bother unless we are inside a function prologue. Outside the |
1242 | prologue, we know where everything is. */ | |
c906108c | 1243 | |
c5aa993b | 1244 | && in_prologue (fci->pc, PROC_LOW_ADDR (proc_desc)) |
c906108c | 1245 | |
c5aa993b JM |
1246 | /* Not sure exactly what kernel_trap means, but if it means |
1247 | the kernel saves the registers without a prologue doing it, | |
1248 | we better not examine the prologue to see whether registers | |
1249 | have been saved yet. */ | |
1250 | && !kernel_trap) | |
c906108c SS |
1251 | { |
1252 | /* We need to figure out whether the registers that the proc_desc | |
c5aa993b | 1253 | claims are saved have been saved yet. */ |
c906108c SS |
1254 | |
1255 | CORE_ADDR addr; | |
1256 | ||
1257 | /* Bitmasks; set if we have found a save for the register. */ | |
1258 | unsigned long gen_save_found = 0; | |
1259 | unsigned long float_save_found = 0; | |
1260 | int instlen; | |
1261 | ||
1262 | /* If the address is odd, assume this is MIPS16 code. */ | |
1263 | addr = PROC_LOW_ADDR (proc_desc); | |
1264 | instlen = pc_is_mips16 (addr) ? MIPS16_INSTLEN : MIPS_INSTLEN; | |
1265 | ||
1266 | /* Scan through this function's instructions preceding the current | |
1267 | PC, and look for those that save registers. */ | |
1268 | while (addr < fci->pc) | |
1269 | { | |
1270 | inst = mips_fetch_instruction (addr); | |
1271 | if (pc_is_mips16 (addr)) | |
1272 | mips16_decode_reg_save (inst, &gen_save_found); | |
1273 | else | |
1274 | mips32_decode_reg_save (inst, &gen_save_found, &float_save_found); | |
1275 | addr += instlen; | |
1276 | } | |
1277 | gen_mask = gen_save_found; | |
1278 | float_mask = float_save_found; | |
1279 | } | |
1280 | ||
1281 | /* Fill in the offsets for the registers which gen_mask says | |
1282 | were saved. */ | |
1283 | reg_position = fci->frame + PROC_REG_OFFSET (proc_desc); | |
c5aa993b | 1284 | for (ireg = MIPS_NUMREGS - 1; gen_mask; --ireg, gen_mask <<= 1) |
c906108c SS |
1285 | if (gen_mask & 0x80000000) |
1286 | { | |
1287 | fci->saved_regs[ireg] = reg_position; | |
7a292a7a | 1288 | reg_position -= MIPS_SAVED_REGSIZE; |
c906108c SS |
1289 | } |
1290 | ||
1291 | /* The MIPS16 entry instruction saves $s0 and $s1 in the reverse order | |
1292 | of that normally used by gcc. Therefore, we have to fetch the first | |
1293 | instruction of the function, and if it's an entry instruction that | |
1294 | saves $s0 or $s1, correct their saved addresses. */ | |
1295 | if (pc_is_mips16 (PROC_LOW_ADDR (proc_desc))) | |
1296 | { | |
1297 | inst = mips_fetch_instruction (PROC_LOW_ADDR (proc_desc)); | |
c5aa993b | 1298 | if ((inst & 0xf81f) == 0xe809 && (inst & 0x700) != 0x700) /* entry */ |
c906108c SS |
1299 | { |
1300 | int reg; | |
1301 | int sreg_count = (inst >> 6) & 3; | |
c5aa993b | 1302 | |
c906108c SS |
1303 | /* Check if the ra register was pushed on the stack. */ |
1304 | reg_position = fci->frame + PROC_REG_OFFSET (proc_desc); | |
1305 | if (inst & 0x20) | |
7a292a7a | 1306 | reg_position -= MIPS_SAVED_REGSIZE; |
c906108c SS |
1307 | |
1308 | /* Check if the s0 and s1 registers were pushed on the stack. */ | |
c5aa993b | 1309 | for (reg = 16; reg < sreg_count + 16; reg++) |
c906108c SS |
1310 | { |
1311 | fci->saved_regs[reg] = reg_position; | |
7a292a7a | 1312 | reg_position -= MIPS_SAVED_REGSIZE; |
c906108c SS |
1313 | } |
1314 | } | |
1315 | } | |
1316 | ||
1317 | /* Fill in the offsets for the registers which float_mask says | |
1318 | were saved. */ | |
1319 | reg_position = fci->frame + PROC_FREG_OFFSET (proc_desc); | |
1320 | ||
1321 | /* The freg_offset points to where the first *double* register | |
1322 | is saved. So skip to the high-order word. */ | |
c5aa993b | 1323 | if (!GDB_TARGET_IS_MIPS64) |
7a292a7a | 1324 | reg_position += MIPS_SAVED_REGSIZE; |
c906108c SS |
1325 | |
1326 | /* Fill in the offsets for the float registers which float_mask says | |
1327 | were saved. */ | |
c5aa993b | 1328 | for (ireg = MIPS_NUMREGS - 1; float_mask; --ireg, float_mask <<= 1) |
c906108c SS |
1329 | if (float_mask & 0x80000000) |
1330 | { | |
c5aa993b | 1331 | fci->saved_regs[FP0_REGNUM + ireg] = reg_position; |
7a292a7a | 1332 | reg_position -= MIPS_SAVED_REGSIZE; |
c906108c SS |
1333 | } |
1334 | ||
1335 | fci->saved_regs[PC_REGNUM] = fci->saved_regs[RA_REGNUM]; | |
1336 | } | |
1337 | ||
1338 | static CORE_ADDR | |
acdb74a0 | 1339 | read_next_frame_reg (struct frame_info *fi, int regno) |
c906108c SS |
1340 | { |
1341 | for (; fi; fi = fi->next) | |
1342 | { | |
1343 | /* We have to get the saved sp from the sigcontext | |
c5aa993b | 1344 | if it is a signal handler frame. */ |
c906108c SS |
1345 | if (regno == SP_REGNUM && !fi->signal_handler_caller) |
1346 | return fi->frame; | |
1347 | else | |
1348 | { | |
1349 | if (fi->saved_regs == NULL) | |
1350 | mips_find_saved_regs (fi); | |
1351 | if (fi->saved_regs[regno]) | |
2acceee2 | 1352 | return read_memory_integer (ADDR_BITS_REMOVE (fi->saved_regs[regno]), MIPS_SAVED_REGSIZE); |
c906108c SS |
1353 | } |
1354 | } | |
6c997a34 | 1355 | return read_signed_register (regno); |
c906108c SS |
1356 | } |
1357 | ||
1358 | /* mips_addr_bits_remove - remove useless address bits */ | |
1359 | ||
875e1767 | 1360 | static CORE_ADDR |
acdb74a0 | 1361 | mips_addr_bits_remove (CORE_ADDR addr) |
c906108c | 1362 | { |
5213ab06 AC |
1363 | if (GDB_TARGET_IS_MIPS64) |
1364 | { | |
4014092b | 1365 | if (mips_mask_address_p () && (addr >> 32 == (CORE_ADDR) 0xffffffff)) |
5213ab06 AC |
1366 | { |
1367 | /* This hack is a work-around for existing boards using | |
1368 | PMON, the simulator, and any other 64-bit targets that | |
1369 | doesn't have true 64-bit addressing. On these targets, | |
1370 | the upper 32 bits of addresses are ignored by the | |
1371 | hardware. Thus, the PC or SP are likely to have been | |
1372 | sign extended to all 1s by instruction sequences that | |
1373 | load 32-bit addresses. For example, a typical piece of | |
4014092b AC |
1374 | code that loads an address is this: |
1375 | lui $r2, <upper 16 bits> | |
1376 | ori $r2, <lower 16 bits> | |
1377 | But the lui sign-extends the value such that the upper 32 | |
1378 | bits may be all 1s. The workaround is simply to mask off | |
1379 | these bits. In the future, gcc may be changed to support | |
1380 | true 64-bit addressing, and this masking will have to be | |
1381 | disabled. */ | |
5213ab06 AC |
1382 | addr &= (CORE_ADDR) 0xffffffff; |
1383 | } | |
1384 | } | |
4014092b | 1385 | else if (mips_mask_address_p ()) |
5213ab06 | 1386 | { |
4014092b AC |
1387 | /* FIXME: This is wrong! mips_addr_bits_remove() shouldn't be |
1388 | masking off bits, instead, the actual target should be asking | |
1389 | for the address to be converted to a valid pointer. */ | |
5213ab06 AC |
1390 | /* Even when GDB is configured for some 32-bit targets |
1391 | (e.g. mips-elf), BFD is configured to handle 64-bit targets, | |
1392 | so CORE_ADDR is 64 bits. So we still have to mask off | |
1393 | useless bits from addresses. */ | |
c5aa993b | 1394 | addr &= (CORE_ADDR) 0xffffffff; |
c906108c | 1395 | } |
c906108c SS |
1396 | return addr; |
1397 | } | |
1398 | ||
9022177c DJ |
1399 | /* mips_software_single_step() is called just before we want to resume |
1400 | the inferior, if we want to single-step it but there is no hardware | |
75c9abc6 | 1401 | or kernel single-step support (MIPS on GNU/Linux for example). We find |
9022177c DJ |
1402 | the target of the coming instruction and breakpoint it. |
1403 | ||
1404 | single_step is also called just after the inferior stops. If we had | |
1405 | set up a simulated single-step, we undo our damage. */ | |
1406 | ||
1407 | void | |
1408 | mips_software_single_step (enum target_signal sig, int insert_breakpoints_p) | |
1409 | { | |
1410 | static CORE_ADDR next_pc; | |
1411 | typedef char binsn_quantum[BREAKPOINT_MAX]; | |
1412 | static binsn_quantum break_mem; | |
1413 | CORE_ADDR pc; | |
1414 | ||
1415 | if (insert_breakpoints_p) | |
1416 | { | |
1417 | pc = read_register (PC_REGNUM); | |
1418 | next_pc = mips_next_pc (pc); | |
1419 | ||
1420 | target_insert_breakpoint (next_pc, break_mem); | |
1421 | } | |
1422 | else | |
1423 | target_remove_breakpoint (next_pc, break_mem); | |
1424 | } | |
1425 | ||
10312cc4 | 1426 | static void |
acdb74a0 | 1427 | mips_init_frame_pc_first (int fromleaf, struct frame_info *prev) |
c906108c SS |
1428 | { |
1429 | CORE_ADDR pc, tmp; | |
1430 | ||
1431 | pc = ((fromleaf) ? SAVED_PC_AFTER_CALL (prev->next) : | |
c5aa993b | 1432 | prev->next ? FRAME_SAVED_PC (prev->next) : read_pc ()); |
c906108c | 1433 | tmp = mips_skip_stub (pc); |
c5aa993b | 1434 | prev->pc = tmp ? tmp : pc; |
c906108c SS |
1435 | } |
1436 | ||
1437 | ||
1438 | CORE_ADDR | |
acdb74a0 | 1439 | mips_frame_saved_pc (struct frame_info *frame) |
c906108c SS |
1440 | { |
1441 | CORE_ADDR saved_pc; | |
cce74817 | 1442 | mips_extra_func_info_t proc_desc = frame->extra_info->proc_desc; |
c906108c SS |
1443 | /* We have to get the saved pc from the sigcontext |
1444 | if it is a signal handler frame. */ | |
1445 | int pcreg = frame->signal_handler_caller ? PC_REGNUM | |
c5aa993b | 1446 | : (proc_desc ? PROC_PC_REG (proc_desc) : RA_REGNUM); |
c906108c | 1447 | |
c5aa993b | 1448 | if (proc_desc && PROC_DESC_IS_DUMMY (proc_desc)) |
7a292a7a | 1449 | saved_pc = read_memory_integer (frame->frame - MIPS_SAVED_REGSIZE, MIPS_SAVED_REGSIZE); |
c906108c | 1450 | else |
7a292a7a | 1451 | saved_pc = read_next_frame_reg (frame, pcreg); |
c906108c SS |
1452 | |
1453 | return ADDR_BITS_REMOVE (saved_pc); | |
1454 | } | |
1455 | ||
1456 | static struct mips_extra_func_info temp_proc_desc; | |
cce74817 | 1457 | static CORE_ADDR temp_saved_regs[NUM_REGS]; |
c906108c SS |
1458 | |
1459 | /* Set a register's saved stack address in temp_saved_regs. If an address | |
1460 | has already been set for this register, do nothing; this way we will | |
1461 | only recognize the first save of a given register in a function prologue. | |
1462 | This is a helper function for mips{16,32}_heuristic_proc_desc. */ | |
1463 | ||
1464 | static void | |
acdb74a0 | 1465 | set_reg_offset (int regno, CORE_ADDR offset) |
c906108c | 1466 | { |
cce74817 JM |
1467 | if (temp_saved_regs[regno] == 0) |
1468 | temp_saved_regs[regno] = offset; | |
c906108c SS |
1469 | } |
1470 | ||
1471 | ||
1472 | /* Test whether the PC points to the return instruction at the | |
1473 | end of a function. */ | |
1474 | ||
c5aa993b | 1475 | static int |
acdb74a0 | 1476 | mips_about_to_return (CORE_ADDR pc) |
c906108c SS |
1477 | { |
1478 | if (pc_is_mips16 (pc)) | |
1479 | /* This mips16 case isn't necessarily reliable. Sometimes the compiler | |
1480 | generates a "jr $ra"; other times it generates code to load | |
1481 | the return address from the stack to an accessible register (such | |
1482 | as $a3), then a "jr" using that register. This second case | |
1483 | is almost impossible to distinguish from an indirect jump | |
1484 | used for switch statements, so we don't even try. */ | |
1485 | return mips_fetch_instruction (pc) == 0xe820; /* jr $ra */ | |
1486 | else | |
1487 | return mips_fetch_instruction (pc) == 0x3e00008; /* jr $ra */ | |
1488 | } | |
1489 | ||
1490 | ||
1491 | /* This fencepost looks highly suspicious to me. Removing it also | |
1492 | seems suspicious as it could affect remote debugging across serial | |
1493 | lines. */ | |
1494 | ||
1495 | static CORE_ADDR | |
acdb74a0 | 1496 | heuristic_proc_start (CORE_ADDR pc) |
c906108c | 1497 | { |
c5aa993b JM |
1498 | CORE_ADDR start_pc; |
1499 | CORE_ADDR fence; | |
1500 | int instlen; | |
1501 | int seen_adjsp = 0; | |
c906108c | 1502 | |
c5aa993b JM |
1503 | pc = ADDR_BITS_REMOVE (pc); |
1504 | start_pc = pc; | |
1505 | fence = start_pc - heuristic_fence_post; | |
1506 | if (start_pc == 0) | |
1507 | return 0; | |
c906108c | 1508 | |
c5aa993b JM |
1509 | if (heuristic_fence_post == UINT_MAX |
1510 | || fence < VM_MIN_ADDRESS) | |
1511 | fence = VM_MIN_ADDRESS; | |
c906108c | 1512 | |
c5aa993b | 1513 | instlen = pc_is_mips16 (pc) ? MIPS16_INSTLEN : MIPS_INSTLEN; |
c906108c | 1514 | |
c5aa993b JM |
1515 | /* search back for previous return */ |
1516 | for (start_pc -= instlen;; start_pc -= instlen) | |
1517 | if (start_pc < fence) | |
1518 | { | |
1519 | /* It's not clear to me why we reach this point when | |
1520 | stop_soon_quietly, but with this test, at least we | |
1521 | don't print out warnings for every child forked (eg, on | |
1522 | decstation). 22apr93 [email protected]. */ | |
1523 | if (!stop_soon_quietly) | |
c906108c | 1524 | { |
c5aa993b JM |
1525 | static int blurb_printed = 0; |
1526 | ||
1527 | warning ("Warning: GDB can't find the start of the function at 0x%s.", | |
1528 | paddr_nz (pc)); | |
1529 | ||
1530 | if (!blurb_printed) | |
c906108c | 1531 | { |
c5aa993b JM |
1532 | /* This actually happens frequently in embedded |
1533 | development, when you first connect to a board | |
1534 | and your stack pointer and pc are nowhere in | |
1535 | particular. This message needs to give people | |
1536 | in that situation enough information to | |
1537 | determine that it's no big deal. */ | |
1538 | printf_filtered ("\n\ | |
cd0fc7c3 SS |
1539 | GDB is unable to find the start of the function at 0x%s\n\ |
1540 | and thus can't determine the size of that function's stack frame.\n\ | |
1541 | This means that GDB may be unable to access that stack frame, or\n\ | |
1542 | the frames below it.\n\ | |
1543 | This problem is most likely caused by an invalid program counter or\n\ | |
1544 | stack pointer.\n\ | |
1545 | However, if you think GDB should simply search farther back\n\ | |
1546 | from 0x%s for code which looks like the beginning of a\n\ | |
1547 | function, you can increase the range of the search using the `set\n\ | |
1548 | heuristic-fence-post' command.\n", | |
c5aa993b JM |
1549 | paddr_nz (pc), paddr_nz (pc)); |
1550 | blurb_printed = 1; | |
c906108c | 1551 | } |
c906108c SS |
1552 | } |
1553 | ||
c5aa993b JM |
1554 | return 0; |
1555 | } | |
1556 | else if (pc_is_mips16 (start_pc)) | |
1557 | { | |
1558 | unsigned short inst; | |
1559 | ||
1560 | /* On MIPS16, any one of the following is likely to be the | |
1561 | start of a function: | |
1562 | entry | |
1563 | addiu sp,-n | |
1564 | daddiu sp,-n | |
1565 | extend -n followed by 'addiu sp,+n' or 'daddiu sp,+n' */ | |
1566 | inst = mips_fetch_instruction (start_pc); | |
1567 | if (((inst & 0xf81f) == 0xe809 && (inst & 0x700) != 0x700) /* entry */ | |
1568 | || (inst & 0xff80) == 0x6380 /* addiu sp,-n */ | |
1569 | || (inst & 0xff80) == 0xfb80 /* daddiu sp,-n */ | |
1570 | || ((inst & 0xf810) == 0xf010 && seen_adjsp)) /* extend -n */ | |
1571 | break; | |
1572 | else if ((inst & 0xff00) == 0x6300 /* addiu sp */ | |
1573 | || (inst & 0xff00) == 0xfb00) /* daddiu sp */ | |
1574 | seen_adjsp = 1; | |
1575 | else | |
1576 | seen_adjsp = 0; | |
1577 | } | |
1578 | else if (mips_about_to_return (start_pc)) | |
1579 | { | |
1580 | start_pc += 2 * MIPS_INSTLEN; /* skip return, and its delay slot */ | |
1581 | break; | |
1582 | } | |
1583 | ||
c5aa993b | 1584 | return start_pc; |
c906108c SS |
1585 | } |
1586 | ||
1587 | /* Fetch the immediate value from a MIPS16 instruction. | |
1588 | If the previous instruction was an EXTEND, use it to extend | |
1589 | the upper bits of the immediate value. This is a helper function | |
1590 | for mips16_heuristic_proc_desc. */ | |
1591 | ||
1592 | static int | |
acdb74a0 AC |
1593 | mips16_get_imm (unsigned short prev_inst, /* previous instruction */ |
1594 | unsigned short inst, /* current instruction */ | |
1595 | int nbits, /* number of bits in imm field */ | |
1596 | int scale, /* scale factor to be applied to imm */ | |
1597 | int is_signed) /* is the imm field signed? */ | |
c906108c SS |
1598 | { |
1599 | int offset; | |
1600 | ||
1601 | if ((prev_inst & 0xf800) == 0xf000) /* prev instruction was EXTEND? */ | |
1602 | { | |
1603 | offset = ((prev_inst & 0x1f) << 11) | (prev_inst & 0x7e0); | |
c5aa993b | 1604 | if (offset & 0x8000) /* check for negative extend */ |
c906108c SS |
1605 | offset = 0 - (0x10000 - (offset & 0xffff)); |
1606 | return offset | (inst & 0x1f); | |
1607 | } | |
1608 | else | |
1609 | { | |
1610 | int max_imm = 1 << nbits; | |
1611 | int mask = max_imm - 1; | |
1612 | int sign_bit = max_imm >> 1; | |
1613 | ||
1614 | offset = inst & mask; | |
1615 | if (is_signed && (offset & sign_bit)) | |
1616 | offset = 0 - (max_imm - offset); | |
1617 | return offset * scale; | |
1618 | } | |
1619 | } | |
1620 | ||
1621 | ||
1622 | /* Fill in values in temp_proc_desc based on the MIPS16 instruction | |
1623 | stream from start_pc to limit_pc. */ | |
1624 | ||
1625 | static void | |
acdb74a0 AC |
1626 | mips16_heuristic_proc_desc (CORE_ADDR start_pc, CORE_ADDR limit_pc, |
1627 | struct frame_info *next_frame, CORE_ADDR sp) | |
c906108c SS |
1628 | { |
1629 | CORE_ADDR cur_pc; | |
1630 | CORE_ADDR frame_addr = 0; /* Value of $r17, used as frame pointer */ | |
1631 | unsigned short prev_inst = 0; /* saved copy of previous instruction */ | |
1632 | unsigned inst = 0; /* current instruction */ | |
1633 | unsigned entry_inst = 0; /* the entry instruction */ | |
1634 | int reg, offset; | |
1635 | ||
c5aa993b JM |
1636 | PROC_FRAME_OFFSET (&temp_proc_desc) = 0; /* size of stack frame */ |
1637 | PROC_FRAME_ADJUST (&temp_proc_desc) = 0; /* offset of FP from SP */ | |
c906108c SS |
1638 | |
1639 | for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += MIPS16_INSTLEN) | |
1640 | { | |
1641 | /* Save the previous instruction. If it's an EXTEND, we'll extract | |
1642 | the immediate offset extension from it in mips16_get_imm. */ | |
1643 | prev_inst = inst; | |
1644 | ||
1645 | /* Fetch and decode the instruction. */ | |
1646 | inst = (unsigned short) mips_fetch_instruction (cur_pc); | |
c5aa993b | 1647 | if ((inst & 0xff00) == 0x6300 /* addiu sp */ |
c906108c SS |
1648 | || (inst & 0xff00) == 0xfb00) /* daddiu sp */ |
1649 | { | |
1650 | offset = mips16_get_imm (prev_inst, inst, 8, 8, 1); | |
c5aa993b JM |
1651 | if (offset < 0) /* negative stack adjustment? */ |
1652 | PROC_FRAME_OFFSET (&temp_proc_desc) -= offset; | |
c906108c SS |
1653 | else |
1654 | /* Exit loop if a positive stack adjustment is found, which | |
1655 | usually means that the stack cleanup code in the function | |
1656 | epilogue is reached. */ | |
1657 | break; | |
1658 | } | |
1659 | else if ((inst & 0xf800) == 0xd000) /* sw reg,n($sp) */ | |
1660 | { | |
1661 | offset = mips16_get_imm (prev_inst, inst, 8, 4, 0); | |
1662 | reg = mips16_to_32_reg[(inst & 0x700) >> 8]; | |
c5aa993b | 1663 | PROC_REG_MASK (&temp_proc_desc) |= (1 << reg); |
c906108c SS |
1664 | set_reg_offset (reg, sp + offset); |
1665 | } | |
1666 | else if ((inst & 0xff00) == 0xf900) /* sd reg,n($sp) */ | |
1667 | { | |
1668 | offset = mips16_get_imm (prev_inst, inst, 5, 8, 0); | |
1669 | reg = mips16_to_32_reg[(inst & 0xe0) >> 5]; | |
c5aa993b | 1670 | PROC_REG_MASK (&temp_proc_desc) |= (1 << reg); |
c906108c SS |
1671 | set_reg_offset (reg, sp + offset); |
1672 | } | |
1673 | else if ((inst & 0xff00) == 0x6200) /* sw $ra,n($sp) */ | |
1674 | { | |
1675 | offset = mips16_get_imm (prev_inst, inst, 8, 4, 0); | |
c5aa993b | 1676 | PROC_REG_MASK (&temp_proc_desc) |= (1 << RA_REGNUM); |
c906108c SS |
1677 | set_reg_offset (RA_REGNUM, sp + offset); |
1678 | } | |
1679 | else if ((inst & 0xff00) == 0xfa00) /* sd $ra,n($sp) */ | |
1680 | { | |
1681 | offset = mips16_get_imm (prev_inst, inst, 8, 8, 0); | |
c5aa993b | 1682 | PROC_REG_MASK (&temp_proc_desc) |= (1 << RA_REGNUM); |
c906108c SS |
1683 | set_reg_offset (RA_REGNUM, sp + offset); |
1684 | } | |
c5aa993b | 1685 | else if (inst == 0x673d) /* move $s1, $sp */ |
c906108c SS |
1686 | { |
1687 | frame_addr = sp; | |
1688 | PROC_FRAME_REG (&temp_proc_desc) = 17; | |
1689 | } | |
1690 | else if ((inst & 0xff00) == 0x0100) /* addiu $s1,sp,n */ | |
1691 | { | |
1692 | offset = mips16_get_imm (prev_inst, inst, 8, 4, 0); | |
1693 | frame_addr = sp + offset; | |
1694 | PROC_FRAME_REG (&temp_proc_desc) = 17; | |
1695 | PROC_FRAME_ADJUST (&temp_proc_desc) = offset; | |
1696 | } | |
1697 | else if ((inst & 0xFF00) == 0xd900) /* sw reg,offset($s1) */ | |
1698 | { | |
1699 | offset = mips16_get_imm (prev_inst, inst, 5, 4, 0); | |
1700 | reg = mips16_to_32_reg[(inst & 0xe0) >> 5]; | |
c5aa993b | 1701 | PROC_REG_MASK (&temp_proc_desc) |= 1 << reg; |
c906108c SS |
1702 | set_reg_offset (reg, frame_addr + offset); |
1703 | } | |
1704 | else if ((inst & 0xFF00) == 0x7900) /* sd reg,offset($s1) */ | |
1705 | { | |
1706 | offset = mips16_get_imm (prev_inst, inst, 5, 8, 0); | |
1707 | reg = mips16_to_32_reg[(inst & 0xe0) >> 5]; | |
c5aa993b | 1708 | PROC_REG_MASK (&temp_proc_desc) |= 1 << reg; |
c906108c SS |
1709 | set_reg_offset (reg, frame_addr + offset); |
1710 | } | |
c5aa993b JM |
1711 | else if ((inst & 0xf81f) == 0xe809 && (inst & 0x700) != 0x700) /* entry */ |
1712 | entry_inst = inst; /* save for later processing */ | |
c906108c | 1713 | else if ((inst & 0xf800) == 0x1800) /* jal(x) */ |
c5aa993b | 1714 | cur_pc += MIPS16_INSTLEN; /* 32-bit instruction */ |
c906108c SS |
1715 | } |
1716 | ||
c5aa993b JM |
1717 | /* The entry instruction is typically the first instruction in a function, |
1718 | and it stores registers at offsets relative to the value of the old SP | |
1719 | (before the prologue). But the value of the sp parameter to this | |
1720 | function is the new SP (after the prologue has been executed). So we | |
1721 | can't calculate those offsets until we've seen the entire prologue, | |
1722 | and can calculate what the old SP must have been. */ | |
1723 | if (entry_inst != 0) | |
1724 | { | |
1725 | int areg_count = (entry_inst >> 8) & 7; | |
1726 | int sreg_count = (entry_inst >> 6) & 3; | |
c906108c | 1727 | |
c5aa993b JM |
1728 | /* The entry instruction always subtracts 32 from the SP. */ |
1729 | PROC_FRAME_OFFSET (&temp_proc_desc) += 32; | |
c906108c | 1730 | |
c5aa993b JM |
1731 | /* Now we can calculate what the SP must have been at the |
1732 | start of the function prologue. */ | |
1733 | sp += PROC_FRAME_OFFSET (&temp_proc_desc); | |
c906108c | 1734 | |
c5aa993b JM |
1735 | /* Check if a0-a3 were saved in the caller's argument save area. */ |
1736 | for (reg = 4, offset = 0; reg < areg_count + 4; reg++) | |
1737 | { | |
1738 | PROC_REG_MASK (&temp_proc_desc) |= 1 << reg; | |
1739 | set_reg_offset (reg, sp + offset); | |
1740 | offset += MIPS_SAVED_REGSIZE; | |
1741 | } | |
c906108c | 1742 | |
c5aa993b JM |
1743 | /* Check if the ra register was pushed on the stack. */ |
1744 | offset = -4; | |
1745 | if (entry_inst & 0x20) | |
1746 | { | |
1747 | PROC_REG_MASK (&temp_proc_desc) |= 1 << RA_REGNUM; | |
1748 | set_reg_offset (RA_REGNUM, sp + offset); | |
1749 | offset -= MIPS_SAVED_REGSIZE; | |
1750 | } | |
c906108c | 1751 | |
c5aa993b JM |
1752 | /* Check if the s0 and s1 registers were pushed on the stack. */ |
1753 | for (reg = 16; reg < sreg_count + 16; reg++) | |
1754 | { | |
1755 | PROC_REG_MASK (&temp_proc_desc) |= 1 << reg; | |
1756 | set_reg_offset (reg, sp + offset); | |
1757 | offset -= MIPS_SAVED_REGSIZE; | |
1758 | } | |
1759 | } | |
c906108c SS |
1760 | } |
1761 | ||
1762 | static void | |
fba45db2 KB |
1763 | mips32_heuristic_proc_desc (CORE_ADDR start_pc, CORE_ADDR limit_pc, |
1764 | struct frame_info *next_frame, CORE_ADDR sp) | |
c906108c SS |
1765 | { |
1766 | CORE_ADDR cur_pc; | |
c5aa993b | 1767 | CORE_ADDR frame_addr = 0; /* Value of $r30. Used by gcc for frame-pointer */ |
c906108c | 1768 | restart: |
cce74817 | 1769 | memset (temp_saved_regs, '\0', SIZEOF_FRAME_SAVED_REGS); |
c5aa993b | 1770 | PROC_FRAME_OFFSET (&temp_proc_desc) = 0; |
c906108c SS |
1771 | PROC_FRAME_ADJUST (&temp_proc_desc) = 0; /* offset of FP from SP */ |
1772 | for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += MIPS_INSTLEN) | |
1773 | { | |
1774 | unsigned long inst, high_word, low_word; | |
1775 | int reg; | |
1776 | ||
1777 | /* Fetch the instruction. */ | |
1778 | inst = (unsigned long) mips_fetch_instruction (cur_pc); | |
1779 | ||
1780 | /* Save some code by pre-extracting some useful fields. */ | |
1781 | high_word = (inst >> 16) & 0xffff; | |
1782 | low_word = inst & 0xffff; | |
1783 | reg = high_word & 0x1f; | |
1784 | ||
c5aa993b | 1785 | if (high_word == 0x27bd /* addiu $sp,$sp,-i */ |
c906108c SS |
1786 | || high_word == 0x23bd /* addi $sp,$sp,-i */ |
1787 | || high_word == 0x67bd) /* daddiu $sp,$sp,-i */ | |
1788 | { | |
1789 | if (low_word & 0x8000) /* negative stack adjustment? */ | |
c5aa993b | 1790 | PROC_FRAME_OFFSET (&temp_proc_desc) += 0x10000 - low_word; |
c906108c SS |
1791 | else |
1792 | /* Exit loop if a positive stack adjustment is found, which | |
1793 | usually means that the stack cleanup code in the function | |
1794 | epilogue is reached. */ | |
1795 | break; | |
1796 | } | |
1797 | else if ((high_word & 0xFFE0) == 0xafa0) /* sw reg,offset($sp) */ | |
1798 | { | |
c5aa993b | 1799 | PROC_REG_MASK (&temp_proc_desc) |= 1 << reg; |
c906108c SS |
1800 | set_reg_offset (reg, sp + low_word); |
1801 | } | |
1802 | else if ((high_word & 0xFFE0) == 0xffa0) /* sd reg,offset($sp) */ | |
1803 | { | |
1804 | /* Irix 6.2 N32 ABI uses sd instructions for saving $gp and $ra, | |
1805 | but the register size used is only 32 bits. Make the address | |
1806 | for the saved register point to the lower 32 bits. */ | |
c5aa993b | 1807 | PROC_REG_MASK (&temp_proc_desc) |= 1 << reg; |
c906108c SS |
1808 | set_reg_offset (reg, sp + low_word + 8 - MIPS_REGSIZE); |
1809 | } | |
c5aa993b | 1810 | else if (high_word == 0x27be) /* addiu $30,$sp,size */ |
c906108c SS |
1811 | { |
1812 | /* Old gcc frame, r30 is virtual frame pointer. */ | |
c5aa993b JM |
1813 | if ((long) low_word != PROC_FRAME_OFFSET (&temp_proc_desc)) |
1814 | frame_addr = sp + low_word; | |
c906108c SS |
1815 | else if (PROC_FRAME_REG (&temp_proc_desc) == SP_REGNUM) |
1816 | { | |
1817 | unsigned alloca_adjust; | |
1818 | PROC_FRAME_REG (&temp_proc_desc) = 30; | |
c5aa993b JM |
1819 | frame_addr = read_next_frame_reg (next_frame, 30); |
1820 | alloca_adjust = (unsigned) (frame_addr - (sp + low_word)); | |
c906108c SS |
1821 | if (alloca_adjust > 0) |
1822 | { | |
1823 | /* FP > SP + frame_size. This may be because | |
1824 | * of an alloca or somethings similar. | |
1825 | * Fix sp to "pre-alloca" value, and try again. | |
1826 | */ | |
1827 | sp += alloca_adjust; | |
1828 | goto restart; | |
1829 | } | |
1830 | } | |
1831 | } | |
c5aa993b JM |
1832 | /* move $30,$sp. With different versions of gas this will be either |
1833 | `addu $30,$sp,$zero' or `or $30,$sp,$zero' or `daddu 30,sp,$0'. | |
1834 | Accept any one of these. */ | |
c906108c SS |
1835 | else if (inst == 0x03A0F021 || inst == 0x03a0f025 || inst == 0x03a0f02d) |
1836 | { | |
1837 | /* New gcc frame, virtual frame pointer is at r30 + frame_size. */ | |
1838 | if (PROC_FRAME_REG (&temp_proc_desc) == SP_REGNUM) | |
1839 | { | |
1840 | unsigned alloca_adjust; | |
1841 | PROC_FRAME_REG (&temp_proc_desc) = 30; | |
c5aa993b JM |
1842 | frame_addr = read_next_frame_reg (next_frame, 30); |
1843 | alloca_adjust = (unsigned) (frame_addr - sp); | |
c906108c SS |
1844 | if (alloca_adjust > 0) |
1845 | { | |
1846 | /* FP > SP + frame_size. This may be because | |
1847 | * of an alloca or somethings similar. | |
1848 | * Fix sp to "pre-alloca" value, and try again. | |
1849 | */ | |
1850 | sp += alloca_adjust; | |
1851 | goto restart; | |
1852 | } | |
1853 | } | |
1854 | } | |
c5aa993b | 1855 | else if ((high_word & 0xFFE0) == 0xafc0) /* sw reg,offset($30) */ |
c906108c | 1856 | { |
c5aa993b | 1857 | PROC_REG_MASK (&temp_proc_desc) |= 1 << reg; |
c906108c SS |
1858 | set_reg_offset (reg, frame_addr + low_word); |
1859 | } | |
1860 | } | |
1861 | } | |
1862 | ||
1863 | static mips_extra_func_info_t | |
acdb74a0 | 1864 | heuristic_proc_desc (CORE_ADDR start_pc, CORE_ADDR limit_pc, |
479412cd | 1865 | struct frame_info *next_frame, int cur_frame) |
c906108c | 1866 | { |
479412cd DJ |
1867 | CORE_ADDR sp; |
1868 | ||
1869 | if (cur_frame) | |
1870 | sp = read_next_frame_reg (next_frame, SP_REGNUM); | |
1871 | else | |
1872 | sp = 0; | |
c906108c | 1873 | |
c5aa993b JM |
1874 | if (start_pc == 0) |
1875 | return NULL; | |
1876 | memset (&temp_proc_desc, '\0', sizeof (temp_proc_desc)); | |
cce74817 | 1877 | memset (&temp_saved_regs, '\0', SIZEOF_FRAME_SAVED_REGS); |
c906108c SS |
1878 | PROC_LOW_ADDR (&temp_proc_desc) = start_pc; |
1879 | PROC_FRAME_REG (&temp_proc_desc) = SP_REGNUM; | |
1880 | PROC_PC_REG (&temp_proc_desc) = RA_REGNUM; | |
1881 | ||
1882 | if (start_pc + 200 < limit_pc) | |
1883 | limit_pc = start_pc + 200; | |
1884 | if (pc_is_mips16 (start_pc)) | |
1885 | mips16_heuristic_proc_desc (start_pc, limit_pc, next_frame, sp); | |
1886 | else | |
1887 | mips32_heuristic_proc_desc (start_pc, limit_pc, next_frame, sp); | |
1888 | return &temp_proc_desc; | |
1889 | } | |
1890 | ||
1891 | static mips_extra_func_info_t | |
acdb74a0 | 1892 | non_heuristic_proc_desc (CORE_ADDR pc, CORE_ADDR *addrptr) |
c906108c SS |
1893 | { |
1894 | CORE_ADDR startaddr; | |
1895 | mips_extra_func_info_t proc_desc; | |
c5aa993b | 1896 | struct block *b = block_for_pc (pc); |
c906108c SS |
1897 | struct symbol *sym; |
1898 | ||
1899 | find_pc_partial_function (pc, NULL, &startaddr, NULL); | |
1900 | if (addrptr) | |
1901 | *addrptr = startaddr; | |
1902 | if (b == NULL || PC_IN_CALL_DUMMY (pc, 0, 0)) | |
1903 | sym = NULL; | |
1904 | else | |
1905 | { | |
1906 | if (startaddr > BLOCK_START (b)) | |
1907 | /* This is the "pathological" case referred to in a comment in | |
1908 | print_frame_info. It might be better to move this check into | |
1909 | symbol reading. */ | |
1910 | sym = NULL; | |
1911 | else | |
1912 | sym = lookup_symbol (MIPS_EFI_SYMBOL_NAME, b, LABEL_NAMESPACE, 0, NULL); | |
1913 | } | |
1914 | ||
1915 | /* If we never found a PDR for this function in symbol reading, then | |
1916 | examine prologues to find the information. */ | |
1917 | if (sym) | |
1918 | { | |
1919 | proc_desc = (mips_extra_func_info_t) SYMBOL_VALUE (sym); | |
1920 | if (PROC_FRAME_REG (proc_desc) == -1) | |
1921 | return NULL; | |
1922 | else | |
1923 | return proc_desc; | |
1924 | } | |
1925 | else | |
1926 | return NULL; | |
1927 | } | |
1928 | ||
1929 | ||
1930 | static mips_extra_func_info_t | |
479412cd | 1931 | find_proc_desc (CORE_ADDR pc, struct frame_info *next_frame, int cur_frame) |
c906108c SS |
1932 | { |
1933 | mips_extra_func_info_t proc_desc; | |
1934 | CORE_ADDR startaddr; | |
1935 | ||
1936 | proc_desc = non_heuristic_proc_desc (pc, &startaddr); | |
1937 | ||
1938 | if (proc_desc) | |
1939 | { | |
1940 | /* IF this is the topmost frame AND | |
1941 | * (this proc does not have debugging information OR | |
1942 | * the PC is in the procedure prologue) | |
1943 | * THEN create a "heuristic" proc_desc (by analyzing | |
1944 | * the actual code) to replace the "official" proc_desc. | |
1945 | */ | |
1946 | if (next_frame == NULL) | |
1947 | { | |
1948 | struct symtab_and_line val; | |
1949 | struct symbol *proc_symbol = | |
c5aa993b | 1950 | PROC_DESC_IS_DUMMY (proc_desc) ? 0 : PROC_SYMBOL (proc_desc); |
c906108c SS |
1951 | |
1952 | if (proc_symbol) | |
1953 | { | |
1954 | val = find_pc_line (BLOCK_START | |
c5aa993b | 1955 | (SYMBOL_BLOCK_VALUE (proc_symbol)), |
c906108c SS |
1956 | 0); |
1957 | val.pc = val.end ? val.end : pc; | |
1958 | } | |
1959 | if (!proc_symbol || pc < val.pc) | |
1960 | { | |
1961 | mips_extra_func_info_t found_heuristic = | |
c5aa993b | 1962 | heuristic_proc_desc (PROC_LOW_ADDR (proc_desc), |
479412cd | 1963 | pc, next_frame, cur_frame); |
c906108c SS |
1964 | if (found_heuristic) |
1965 | proc_desc = found_heuristic; | |
1966 | } | |
1967 | } | |
1968 | } | |
1969 | else | |
1970 | { | |
1971 | /* Is linked_proc_desc_table really necessary? It only seems to be used | |
c5aa993b JM |
1972 | by procedure call dummys. However, the procedures being called ought |
1973 | to have their own proc_descs, and even if they don't, | |
1974 | heuristic_proc_desc knows how to create them! */ | |
c906108c SS |
1975 | |
1976 | register struct linked_proc_info *link; | |
1977 | ||
1978 | for (link = linked_proc_desc_table; link; link = link->next) | |
c5aa993b JM |
1979 | if (PROC_LOW_ADDR (&link->info) <= pc |
1980 | && PROC_HIGH_ADDR (&link->info) > pc) | |
c906108c SS |
1981 | return &link->info; |
1982 | ||
1983 | if (startaddr == 0) | |
1984 | startaddr = heuristic_proc_start (pc); | |
1985 | ||
1986 | proc_desc = | |
479412cd | 1987 | heuristic_proc_desc (startaddr, pc, next_frame, cur_frame); |
c906108c SS |
1988 | } |
1989 | return proc_desc; | |
1990 | } | |
1991 | ||
1992 | static CORE_ADDR | |
acdb74a0 AC |
1993 | get_frame_pointer (struct frame_info *frame, |
1994 | mips_extra_func_info_t proc_desc) | |
c906108c SS |
1995 | { |
1996 | return ADDR_BITS_REMOVE ( | |
c5aa993b JM |
1997 | read_next_frame_reg (frame, PROC_FRAME_REG (proc_desc)) + |
1998 | PROC_FRAME_OFFSET (proc_desc) - PROC_FRAME_ADJUST (proc_desc)); | |
c906108c SS |
1999 | } |
2000 | ||
2001 | mips_extra_func_info_t cached_proc_desc; | |
2002 | ||
2003 | CORE_ADDR | |
acdb74a0 | 2004 | mips_frame_chain (struct frame_info *frame) |
c906108c SS |
2005 | { |
2006 | mips_extra_func_info_t proc_desc; | |
2007 | CORE_ADDR tmp; | |
c5aa993b | 2008 | CORE_ADDR saved_pc = FRAME_SAVED_PC (frame); |
c906108c SS |
2009 | |
2010 | if (saved_pc == 0 || inside_entry_file (saved_pc)) | |
2011 | return 0; | |
2012 | ||
2013 | /* Check if the PC is inside a call stub. If it is, fetch the | |
2014 | PC of the caller of that stub. */ | |
2015 | if ((tmp = mips_skip_stub (saved_pc)) != 0) | |
2016 | saved_pc = tmp; | |
2017 | ||
2018 | /* Look up the procedure descriptor for this PC. */ | |
479412cd | 2019 | proc_desc = find_proc_desc (saved_pc, frame, 1); |
c906108c SS |
2020 | if (!proc_desc) |
2021 | return 0; | |
2022 | ||
2023 | cached_proc_desc = proc_desc; | |
2024 | ||
2025 | /* If no frame pointer and frame size is zero, we must be at end | |
2026 | of stack (or otherwise hosed). If we don't check frame size, | |
2027 | we loop forever if we see a zero size frame. */ | |
2028 | if (PROC_FRAME_REG (proc_desc) == SP_REGNUM | |
2029 | && PROC_FRAME_OFFSET (proc_desc) == 0 | |
c5aa993b JM |
2030 | /* The previous frame from a sigtramp frame might be frameless |
2031 | and have frame size zero. */ | |
c906108c SS |
2032 | && !frame->signal_handler_caller) |
2033 | return 0; | |
2034 | else | |
2035 | return get_frame_pointer (frame, proc_desc); | |
2036 | } | |
2037 | ||
2038 | void | |
acdb74a0 | 2039 | mips_init_extra_frame_info (int fromleaf, struct frame_info *fci) |
c906108c SS |
2040 | { |
2041 | int regnum; | |
2042 | ||
2043 | /* Use proc_desc calculated in frame_chain */ | |
2044 | mips_extra_func_info_t proc_desc = | |
479412cd | 2045 | fci->next ? cached_proc_desc : find_proc_desc (fci->pc, fci->next, 1); |
c906108c | 2046 | |
cce74817 JM |
2047 | fci->extra_info = (struct frame_extra_info *) |
2048 | frame_obstack_alloc (sizeof (struct frame_extra_info)); | |
2049 | ||
c906108c | 2050 | fci->saved_regs = NULL; |
cce74817 | 2051 | fci->extra_info->proc_desc = |
c906108c SS |
2052 | proc_desc == &temp_proc_desc ? 0 : proc_desc; |
2053 | if (proc_desc) | |
2054 | { | |
2055 | /* Fixup frame-pointer - only needed for top frame */ | |
2056 | /* This may not be quite right, if proc has a real frame register. | |
c5aa993b JM |
2057 | Get the value of the frame relative sp, procedure might have been |
2058 | interrupted by a signal at it's very start. */ | |
c906108c SS |
2059 | if (fci->pc == PROC_LOW_ADDR (proc_desc) |
2060 | && !PROC_DESC_IS_DUMMY (proc_desc)) | |
2061 | fci->frame = read_next_frame_reg (fci->next, SP_REGNUM); | |
2062 | else | |
2063 | fci->frame = get_frame_pointer (fci->next, proc_desc); | |
2064 | ||
2065 | if (proc_desc == &temp_proc_desc) | |
2066 | { | |
2067 | char *name; | |
2068 | ||
2069 | /* Do not set the saved registers for a sigtramp frame, | |
2070 | mips_find_saved_registers will do that for us. | |
2071 | We can't use fci->signal_handler_caller, it is not yet set. */ | |
2072 | find_pc_partial_function (fci->pc, &name, | |
c5aa993b | 2073 | (CORE_ADDR *) NULL, (CORE_ADDR *) NULL); |
d7bd68ca | 2074 | if (!PC_IN_SIGTRAMP (fci->pc, name)) |
c906108c | 2075 | { |
c5aa993b | 2076 | frame_saved_regs_zalloc (fci); |
cce74817 | 2077 | memcpy (fci->saved_regs, temp_saved_regs, SIZEOF_FRAME_SAVED_REGS); |
c906108c SS |
2078 | fci->saved_regs[PC_REGNUM] |
2079 | = fci->saved_regs[RA_REGNUM]; | |
2080 | } | |
2081 | } | |
2082 | ||
2083 | /* hack: if argument regs are saved, guess these contain args */ | |
cce74817 JM |
2084 | /* assume we can't tell how many args for now */ |
2085 | fci->extra_info->num_args = -1; | |
c906108c SS |
2086 | for (regnum = MIPS_LAST_ARG_REGNUM; regnum >= A0_REGNUM; regnum--) |
2087 | { | |
c5aa993b | 2088 | if (PROC_REG_MASK (proc_desc) & (1 << regnum)) |
c906108c | 2089 | { |
cce74817 | 2090 | fci->extra_info->num_args = regnum - A0_REGNUM + 1; |
c906108c SS |
2091 | break; |
2092 | } | |
c5aa993b | 2093 | } |
c906108c SS |
2094 | } |
2095 | } | |
2096 | ||
2097 | /* MIPS stack frames are almost impenetrable. When execution stops, | |
2098 | we basically have to look at symbol information for the function | |
2099 | that we stopped in, which tells us *which* register (if any) is | |
2100 | the base of the frame pointer, and what offset from that register | |
361d1df0 | 2101 | the frame itself is at. |
c906108c SS |
2102 | |
2103 | This presents a problem when trying to examine a stack in memory | |
2104 | (that isn't executing at the moment), using the "frame" command. We | |
2105 | don't have a PC, nor do we have any registers except SP. | |
2106 | ||
2107 | This routine takes two arguments, SP and PC, and tries to make the | |
2108 | cached frames look as if these two arguments defined a frame on the | |
2109 | cache. This allows the rest of info frame to extract the important | |
2110 | arguments without difficulty. */ | |
2111 | ||
2112 | struct frame_info * | |
acdb74a0 | 2113 | setup_arbitrary_frame (int argc, CORE_ADDR *argv) |
c906108c SS |
2114 | { |
2115 | if (argc != 2) | |
2116 | error ("MIPS frame specifications require two arguments: sp and pc"); | |
2117 | ||
2118 | return create_new_frame (argv[0], argv[1]); | |
2119 | } | |
2120 | ||
f09ded24 AC |
2121 | /* According to the current ABI, should the type be passed in a |
2122 | floating-point register (assuming that there is space)? When there | |
2123 | is no FPU, FP are not even considered as possibile candidates for | |
2124 | FP registers and, consequently this returns false - forces FP | |
2125 | arguments into integer registers. */ | |
2126 | ||
2127 | static int | |
2128 | fp_register_arg_p (enum type_code typecode, struct type *arg_type) | |
2129 | { | |
2130 | return ((typecode == TYPE_CODE_FLT | |
2131 | || (MIPS_EABI | |
2132 | && (typecode == TYPE_CODE_STRUCT || typecode == TYPE_CODE_UNION) | |
2133 | && TYPE_NFIELDS (arg_type) == 1 | |
2134 | && TYPE_CODE (TYPE_FIELD_TYPE (arg_type, 0)) == TYPE_CODE_FLT)) | |
2135 | && MIPS_FPU_TYPE != MIPS_FPU_NONE); | |
2136 | } | |
2137 | ||
49e790b0 DJ |
2138 | /* On o32, argument passing in GPRs depends on the alignment of the type being |
2139 | passed. Return 1 if this type must be aligned to a doubleword boundary. */ | |
2140 | ||
2141 | static int | |
2142 | mips_type_needs_double_align (struct type *type) | |
2143 | { | |
2144 | enum type_code typecode = TYPE_CODE (type); | |
361d1df0 | 2145 | |
49e790b0 DJ |
2146 | if (typecode == TYPE_CODE_FLT && TYPE_LENGTH (type) == 8) |
2147 | return 1; | |
2148 | else if (typecode == TYPE_CODE_STRUCT) | |
2149 | { | |
2150 | if (TYPE_NFIELDS (type) < 1) | |
2151 | return 0; | |
2152 | return mips_type_needs_double_align (TYPE_FIELD_TYPE (type, 0)); | |
2153 | } | |
2154 | else if (typecode == TYPE_CODE_UNION) | |
2155 | { | |
361d1df0 | 2156 | int i, n; |
49e790b0 DJ |
2157 | |
2158 | n = TYPE_NFIELDS (type); | |
2159 | for (i = 0; i < n; i++) | |
2160 | if (mips_type_needs_double_align (TYPE_FIELD_TYPE (type, i))) | |
2161 | return 1; | |
2162 | return 0; | |
2163 | } | |
2164 | return 0; | |
2165 | } | |
2166 | ||
c906108c | 2167 | CORE_ADDR |
acdb74a0 | 2168 | mips_push_arguments (int nargs, |
ea7c478f | 2169 | struct value **args, |
acdb74a0 AC |
2170 | CORE_ADDR sp, |
2171 | int struct_return, | |
2172 | CORE_ADDR struct_addr) | |
c906108c SS |
2173 | { |
2174 | int argreg; | |
2175 | int float_argreg; | |
2176 | int argnum; | |
2177 | int len = 0; | |
2178 | int stack_offset = 0; | |
2179 | ||
2180 | /* Macros to round N up or down to the next A boundary; A must be | |
2181 | a power of two. */ | |
2182 | #define ROUND_DOWN(n,a) ((n) & ~((a)-1)) | |
2183 | #define ROUND_UP(n,a) (((n)+(a)-1) & ~((a)-1)) | |
c5aa993b | 2184 | |
c906108c SS |
2185 | /* First ensure that the stack and structure return address (if any) |
2186 | are properly aligned. The stack has to be at least 64-bit aligned | |
2187 | even on 32-bit machines, because doubles must be 64-bit aligned. | |
2188 | On at least one MIPS variant, stack frames need to be 128-bit | |
2189 | aligned, so we round to this widest known alignment. */ | |
2190 | sp = ROUND_DOWN (sp, 16); | |
cce41527 | 2191 | struct_addr = ROUND_DOWN (struct_addr, 16); |
c5aa993b | 2192 | |
c906108c SS |
2193 | /* Now make space on the stack for the args. We allocate more |
2194 | than necessary for EABI, because the first few arguments are | |
2195 | passed in registers, but that's OK. */ | |
2196 | for (argnum = 0; argnum < nargs; argnum++) | |
cce41527 | 2197 | len += ROUND_UP (TYPE_LENGTH (VALUE_TYPE (args[argnum])), MIPS_STACK_ARGSIZE); |
c906108c SS |
2198 | sp -= ROUND_UP (len, 16); |
2199 | ||
9ace0497 AC |
2200 | if (mips_debug) |
2201 | fprintf_unfiltered (gdb_stdlog, "mips_push_arguments: sp=0x%lx allocated %d\n", | |
2202 | (long) sp, ROUND_UP (len, 16)); | |
2203 | ||
c906108c SS |
2204 | /* Initialize the integer and float register pointers. */ |
2205 | argreg = A0_REGNUM; | |
2206 | float_argreg = FPA0_REGNUM; | |
2207 | ||
2208 | /* the struct_return pointer occupies the first parameter-passing reg */ | |
2209 | if (struct_return) | |
9ace0497 AC |
2210 | { |
2211 | if (mips_debug) | |
2212 | fprintf_unfiltered (gdb_stdlog, | |
cce41527 | 2213 | "mips_push_arguments: struct_return reg=%d 0x%lx\n", |
9ace0497 AC |
2214 | argreg, (long) struct_addr); |
2215 | write_register (argreg++, struct_addr); | |
cce41527 AC |
2216 | if (MIPS_REGS_HAVE_HOME_P) |
2217 | stack_offset += MIPS_STACK_ARGSIZE; | |
9ace0497 | 2218 | } |
c906108c SS |
2219 | |
2220 | /* Now load as many as possible of the first arguments into | |
2221 | registers, and push the rest onto the stack. Loop thru args | |
2222 | from first to last. */ | |
2223 | for (argnum = 0; argnum < nargs; argnum++) | |
2224 | { | |
2225 | char *val; | |
2226 | char valbuf[MAX_REGISTER_RAW_SIZE]; | |
ea7c478f | 2227 | struct value *arg = args[argnum]; |
c906108c SS |
2228 | struct type *arg_type = check_typedef (VALUE_TYPE (arg)); |
2229 | int len = TYPE_LENGTH (arg_type); | |
2230 | enum type_code typecode = TYPE_CODE (arg_type); | |
2231 | ||
9ace0497 AC |
2232 | if (mips_debug) |
2233 | fprintf_unfiltered (gdb_stdlog, | |
2234 | "mips_push_arguments: %d len=%d type=%d", | |
acdb74a0 | 2235 | argnum + 1, len, (int) typecode); |
9ace0497 | 2236 | |
c906108c | 2237 | /* The EABI passes structures that do not fit in a register by |
c5aa993b | 2238 | reference. In all other cases, pass the structure by value. */ |
9ace0497 AC |
2239 | if (MIPS_EABI |
2240 | && len > MIPS_SAVED_REGSIZE | |
2241 | && (typecode == TYPE_CODE_STRUCT || typecode == TYPE_CODE_UNION)) | |
c906108c | 2242 | { |
7a292a7a | 2243 | store_address (valbuf, MIPS_SAVED_REGSIZE, VALUE_ADDRESS (arg)); |
c906108c | 2244 | typecode = TYPE_CODE_PTR; |
7a292a7a | 2245 | len = MIPS_SAVED_REGSIZE; |
c906108c | 2246 | val = valbuf; |
9ace0497 AC |
2247 | if (mips_debug) |
2248 | fprintf_unfiltered (gdb_stdlog, " push"); | |
c906108c SS |
2249 | } |
2250 | else | |
c5aa993b | 2251 | val = (char *) VALUE_CONTENTS (arg); |
c906108c SS |
2252 | |
2253 | /* 32-bit ABIs always start floating point arguments in an | |
acdb74a0 AC |
2254 | even-numbered floating point register. Round the FP register |
2255 | up before the check to see if there are any FP registers | |
2256 | left. Non MIPS_EABI targets also pass the FP in the integer | |
2257 | registers so also round up normal registers. */ | |
2258 | if (!FP_REGISTER_DOUBLE | |
2259 | && fp_register_arg_p (typecode, arg_type)) | |
2260 | { | |
2261 | if ((float_argreg & 1)) | |
2262 | float_argreg++; | |
2263 | } | |
c906108c SS |
2264 | |
2265 | /* Floating point arguments passed in registers have to be | |
2266 | treated specially. On 32-bit architectures, doubles | |
c5aa993b JM |
2267 | are passed in register pairs; the even register gets |
2268 | the low word, and the odd register gets the high word. | |
2269 | On non-EABI processors, the first two floating point arguments are | |
2270 | also copied to general registers, because MIPS16 functions | |
2271 | don't use float registers for arguments. This duplication of | |
2272 | arguments in general registers can't hurt non-MIPS16 functions | |
2273 | because those registers are normally skipped. */ | |
1012bd0e EZ |
2274 | /* MIPS_EABI squeezes a struct that contains a single floating |
2275 | point value into an FP register instead of pushing it onto the | |
9a0149c6 | 2276 | stack. */ |
f09ded24 AC |
2277 | if (fp_register_arg_p (typecode, arg_type) |
2278 | && float_argreg <= MIPS_LAST_FP_ARG_REGNUM) | |
c906108c SS |
2279 | { |
2280 | if (!FP_REGISTER_DOUBLE && len == 8) | |
2281 | { | |
d7449b42 | 2282 | int low_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 4 : 0; |
c906108c SS |
2283 | unsigned long regval; |
2284 | ||
2285 | /* Write the low word of the double to the even register(s). */ | |
c5aa993b | 2286 | regval = extract_unsigned_integer (val + low_offset, 4); |
9ace0497 | 2287 | if (mips_debug) |
acdb74a0 | 2288 | fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s", |
9ace0497 | 2289 | float_argreg, phex (regval, 4)); |
c906108c SS |
2290 | write_register (float_argreg++, regval); |
2291 | if (!MIPS_EABI) | |
9ace0497 AC |
2292 | { |
2293 | if (mips_debug) | |
acdb74a0 | 2294 | fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s", |
9ace0497 AC |
2295 | argreg, phex (regval, 4)); |
2296 | write_register (argreg++, regval); | |
2297 | } | |
c906108c SS |
2298 | |
2299 | /* Write the high word of the double to the odd register(s). */ | |
c5aa993b | 2300 | regval = extract_unsigned_integer (val + 4 - low_offset, 4); |
9ace0497 | 2301 | if (mips_debug) |
acdb74a0 | 2302 | fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s", |
9ace0497 | 2303 | float_argreg, phex (regval, 4)); |
c906108c SS |
2304 | write_register (float_argreg++, regval); |
2305 | if (!MIPS_EABI) | |
c5aa993b | 2306 | { |
9ace0497 | 2307 | if (mips_debug) |
acdb74a0 | 2308 | fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s", |
9ace0497 AC |
2309 | argreg, phex (regval, 4)); |
2310 | write_register (argreg++, regval); | |
c906108c SS |
2311 | } |
2312 | ||
2313 | } | |
2314 | else | |
2315 | { | |
2316 | /* This is a floating point value that fits entirely | |
2317 | in a single register. */ | |
53a5351d JM |
2318 | /* On 32 bit ABI's the float_argreg is further adjusted |
2319 | above to ensure that it is even register aligned. */ | |
9ace0497 AC |
2320 | LONGEST regval = extract_unsigned_integer (val, len); |
2321 | if (mips_debug) | |
acdb74a0 | 2322 | fprintf_unfiltered (gdb_stdlog, " - fpreg=%d val=%s", |
9ace0497 | 2323 | float_argreg, phex (regval, len)); |
c906108c SS |
2324 | write_register (float_argreg++, regval); |
2325 | if (!MIPS_EABI) | |
c5aa993b | 2326 | { |
53a5351d JM |
2327 | /* CAGNEY: 32 bit MIPS ABI's always reserve two FP |
2328 | registers for each argument. The below is (my | |
2329 | guess) to ensure that the corresponding integer | |
2330 | register has reserved the same space. */ | |
9ace0497 | 2331 | if (mips_debug) |
acdb74a0 | 2332 | fprintf_unfiltered (gdb_stdlog, " - reg=%d val=%s", |
9ace0497 | 2333 | argreg, phex (regval, len)); |
c906108c SS |
2334 | write_register (argreg, regval); |
2335 | argreg += FP_REGISTER_DOUBLE ? 1 : 2; | |
2336 | } | |
2337 | } | |
cce41527 AC |
2338 | /* Reserve space for the FP register. */ |
2339 | if (MIPS_REGS_HAVE_HOME_P) | |
2340 | stack_offset += ROUND_UP (len, MIPS_STACK_ARGSIZE); | |
c906108c SS |
2341 | } |
2342 | else | |
2343 | { | |
2344 | /* Copy the argument to general registers or the stack in | |
2345 | register-sized pieces. Large arguments are split between | |
2346 | registers and stack. */ | |
2347 | /* Note: structs whose size is not a multiple of MIPS_REGSIZE | |
2348 | are treated specially: Irix cc passes them in registers | |
2349 | where gcc sometimes puts them on the stack. For maximum | |
2350 | compatibility, we will put them in both places. */ | |
c5aa993b | 2351 | int odd_sized_struct = ((len > MIPS_SAVED_REGSIZE) && |
7a292a7a | 2352 | (len % MIPS_SAVED_REGSIZE != 0)); |
49e790b0 DJ |
2353 | /* Structures should be aligned to eight bytes (even arg registers) |
2354 | on MIPS_ABI_O32 if their first member has double precision. */ | |
2355 | if (gdbarch_tdep (current_gdbarch)->mips_abi == MIPS_ABI_O32 | |
2356 | && mips_type_needs_double_align (arg_type)) | |
2357 | { | |
2358 | if ((argreg & 1)) | |
2359 | argreg++; | |
2360 | } | |
f09ded24 AC |
2361 | /* Note: Floating-point values that didn't fit into an FP |
2362 | register are only written to memory. */ | |
c906108c SS |
2363 | while (len > 0) |
2364 | { | |
566f0f7a AC |
2365 | /* Rememer if the argument was written to the stack. */ |
2366 | int stack_used_p = 0; | |
7a292a7a | 2367 | int partial_len = len < MIPS_SAVED_REGSIZE ? len : MIPS_SAVED_REGSIZE; |
c906108c | 2368 | |
acdb74a0 AC |
2369 | if (mips_debug) |
2370 | fprintf_unfiltered (gdb_stdlog, " -- partial=%d", | |
2371 | partial_len); | |
2372 | ||
566f0f7a | 2373 | /* Write this portion of the argument to the stack. */ |
f09ded24 AC |
2374 | if (argreg > MIPS_LAST_ARG_REGNUM |
2375 | || odd_sized_struct | |
2376 | || fp_register_arg_p (typecode, arg_type)) | |
c906108c | 2377 | { |
c906108c SS |
2378 | /* Should shorter than int integer values be |
2379 | promoted to int before being stored? */ | |
c906108c | 2380 | int longword_offset = 0; |
9ace0497 | 2381 | CORE_ADDR addr; |
566f0f7a | 2382 | stack_used_p = 1; |
d7449b42 | 2383 | if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) |
7a292a7a | 2384 | { |
d929b26f | 2385 | if (MIPS_STACK_ARGSIZE == 8 && |
7a292a7a SS |
2386 | (typecode == TYPE_CODE_INT || |
2387 | typecode == TYPE_CODE_PTR || | |
2388 | typecode == TYPE_CODE_FLT) && len <= 4) | |
d929b26f | 2389 | longword_offset = MIPS_STACK_ARGSIZE - len; |
7a292a7a SS |
2390 | else if ((typecode == TYPE_CODE_STRUCT || |
2391 | typecode == TYPE_CODE_UNION) && | |
d929b26f AC |
2392 | TYPE_LENGTH (arg_type) < MIPS_STACK_ARGSIZE) |
2393 | longword_offset = MIPS_STACK_ARGSIZE - len; | |
7a292a7a | 2394 | } |
c5aa993b | 2395 | |
9ace0497 AC |
2396 | if (mips_debug) |
2397 | { | |
acdb74a0 | 2398 | fprintf_unfiltered (gdb_stdlog, " - stack_offset=0x%lx", |
9ace0497 AC |
2399 | (long) stack_offset); |
2400 | fprintf_unfiltered (gdb_stdlog, " longword_offset=0x%lx", | |
2401 | (long) longword_offset); | |
2402 | } | |
361d1df0 | 2403 | |
9ace0497 AC |
2404 | addr = sp + stack_offset + longword_offset; |
2405 | ||
2406 | if (mips_debug) | |
2407 | { | |
2408 | int i; | |
2409 | fprintf_unfiltered (gdb_stdlog, " @0x%lx ", (long) addr); | |
2410 | for (i = 0; i < partial_len; i++) | |
2411 | { | |
2412 | fprintf_unfiltered (gdb_stdlog, "%02x", val[i] & 0xff); | |
2413 | } | |
2414 | } | |
2415 | write_memory (addr, val, partial_len); | |
c906108c SS |
2416 | } |
2417 | ||
f09ded24 AC |
2418 | /* Note!!! This is NOT an else clause. Odd sized |
2419 | structs may go thru BOTH paths. Floating point | |
2420 | arguments will not. */ | |
566f0f7a AC |
2421 | /* Write this portion of the argument to a general |
2422 | purpose register. */ | |
f09ded24 AC |
2423 | if (argreg <= MIPS_LAST_ARG_REGNUM |
2424 | && !fp_register_arg_p (typecode, arg_type)) | |
c906108c | 2425 | { |
9ace0497 | 2426 | LONGEST regval = extract_unsigned_integer (val, partial_len); |
c906108c | 2427 | |
361d1df0 | 2428 | /* A non-floating-point argument being passed in a |
c906108c SS |
2429 | general register. If a struct or union, and if |
2430 | the remaining length is smaller than the register | |
2431 | size, we have to adjust the register value on | |
2432 | big endian targets. | |
2433 | ||
2434 | It does not seem to be necessary to do the | |
2435 | same for integral types. | |
2436 | ||
2437 | Also don't do this adjustment on EABI and O64 | |
675fb869 AC |
2438 | binaries. |
2439 | ||
2440 | cagney/2001-07-23: gdb/179: Also, GCC, when | |
2441 | outputting LE O32 with sizeof (struct) < | |
2442 | MIPS_SAVED_REGSIZE, generates a left shift as | |
2443 | part of storing the argument in a register a | |
2444 | register (the left shift isn't generated when | |
2445 | sizeof (struct) >= MIPS_SAVED_REGSIZE). Since it | |
2446 | is quite possible that this is GCC contradicting | |
2447 | the LE/O32 ABI, GDB has not been adjusted to | |
2448 | accommodate this. Either someone needs to | |
2449 | demonstrate that the LE/O32 ABI specifies such a | |
2450 | left shift OR this new ABI gets identified as | |
2451 | such and GDB gets tweaked accordingly. */ | |
c906108c SS |
2452 | |
2453 | if (!MIPS_EABI | |
7a292a7a | 2454 | && MIPS_SAVED_REGSIZE < 8 |
d7449b42 | 2455 | && TARGET_BYTE_ORDER == BFD_ENDIAN_BIG |
7a292a7a | 2456 | && partial_len < MIPS_SAVED_REGSIZE |
c906108c SS |
2457 | && (typecode == TYPE_CODE_STRUCT || |
2458 | typecode == TYPE_CODE_UNION)) | |
c5aa993b | 2459 | regval <<= ((MIPS_SAVED_REGSIZE - partial_len) * |
c906108c SS |
2460 | TARGET_CHAR_BIT); |
2461 | ||
9ace0497 | 2462 | if (mips_debug) |
acdb74a0 | 2463 | fprintf_filtered (gdb_stdlog, " - reg=%d val=%s", |
9ace0497 AC |
2464 | argreg, |
2465 | phex (regval, MIPS_SAVED_REGSIZE)); | |
c906108c SS |
2466 | write_register (argreg, regval); |
2467 | argreg++; | |
c5aa993b | 2468 | |
c906108c SS |
2469 | /* If this is the old ABI, prevent subsequent floating |
2470 | point arguments from being passed in floating point | |
2471 | registers. */ | |
2472 | if (!MIPS_EABI) | |
2473 | float_argreg = MIPS_LAST_FP_ARG_REGNUM + 1; | |
2474 | } | |
c5aa993b | 2475 | |
c906108c SS |
2476 | len -= partial_len; |
2477 | val += partial_len; | |
2478 | ||
566f0f7a AC |
2479 | /* Compute the the offset into the stack at which we |
2480 | will copy the next parameter. | |
2481 | ||
2482 | In older ABIs, the caller reserved space for | |
2483 | registers that contained arguments. This was loosely | |
2484 | refered to as their "home". Consequently, space is | |
2485 | always allocated. | |
c906108c | 2486 | |
566f0f7a AC |
2487 | In the new EABI (and the NABI32), the stack_offset |
2488 | only needs to be adjusted when it has been used.. */ | |
c906108c | 2489 | |
566f0f7a | 2490 | if (MIPS_REGS_HAVE_HOME_P || stack_used_p) |
d929b26f | 2491 | stack_offset += ROUND_UP (partial_len, MIPS_STACK_ARGSIZE); |
c906108c SS |
2492 | } |
2493 | } | |
9ace0497 AC |
2494 | if (mips_debug) |
2495 | fprintf_unfiltered (gdb_stdlog, "\n"); | |
c906108c SS |
2496 | } |
2497 | ||
0f71a2f6 JM |
2498 | /* Return adjusted stack pointer. */ |
2499 | return sp; | |
2500 | } | |
2501 | ||
2502 | CORE_ADDR | |
acdb74a0 | 2503 | mips_push_return_address (CORE_ADDR pc, CORE_ADDR sp) |
0f71a2f6 | 2504 | { |
c906108c SS |
2505 | /* Set the return address register to point to the entry |
2506 | point of the program, where a breakpoint lies in wait. */ | |
c5aa993b | 2507 | write_register (RA_REGNUM, CALL_DUMMY_ADDRESS ()); |
c906108c SS |
2508 | return sp; |
2509 | } | |
2510 | ||
2511 | static void | |
c5aa993b | 2512 | mips_push_register (CORE_ADDR * sp, int regno) |
c906108c SS |
2513 | { |
2514 | char buffer[MAX_REGISTER_RAW_SIZE]; | |
7a292a7a SS |
2515 | int regsize; |
2516 | int offset; | |
2517 | if (MIPS_SAVED_REGSIZE < REGISTER_RAW_SIZE (regno)) | |
2518 | { | |
2519 | regsize = MIPS_SAVED_REGSIZE; | |
d7449b42 | 2520 | offset = (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG |
7a292a7a SS |
2521 | ? REGISTER_RAW_SIZE (regno) - MIPS_SAVED_REGSIZE |
2522 | : 0); | |
2523 | } | |
2524 | else | |
2525 | { | |
2526 | regsize = REGISTER_RAW_SIZE (regno); | |
2527 | offset = 0; | |
2528 | } | |
c906108c SS |
2529 | *sp -= regsize; |
2530 | read_register_gen (regno, buffer); | |
7a292a7a | 2531 | write_memory (*sp, buffer + offset, regsize); |
c906108c SS |
2532 | } |
2533 | ||
2534 | /* MASK(i,j) == (1<<i) + (1<<(i+1)) + ... + (1<<j)). Assume i<=j<(MIPS_NUMREGS-1). */ | |
2535 | #define MASK(i,j) (((1 << ((j)+1))-1) ^ ((1 << (i))-1)) | |
2536 | ||
2537 | void | |
acdb74a0 | 2538 | mips_push_dummy_frame (void) |
c906108c SS |
2539 | { |
2540 | int ireg; | |
c5aa993b JM |
2541 | struct linked_proc_info *link = (struct linked_proc_info *) |
2542 | xmalloc (sizeof (struct linked_proc_info)); | |
c906108c | 2543 | mips_extra_func_info_t proc_desc = &link->info; |
6c997a34 | 2544 | CORE_ADDR sp = ADDR_BITS_REMOVE (read_signed_register (SP_REGNUM)); |
c906108c SS |
2545 | CORE_ADDR old_sp = sp; |
2546 | link->next = linked_proc_desc_table; | |
2547 | linked_proc_desc_table = link; | |
2548 | ||
2549 | /* FIXME! are these correct ? */ | |
c5aa993b | 2550 | #define PUSH_FP_REGNUM 16 /* must be a register preserved across calls */ |
c906108c SS |
2551 | #define GEN_REG_SAVE_MASK MASK(1,16)|MASK(24,28)|(1<<(MIPS_NUMREGS-1)) |
2552 | #define FLOAT_REG_SAVE_MASK MASK(0,19) | |
2553 | #define FLOAT_SINGLE_REG_SAVE_MASK \ | |
2554 | ((1<<18)|(1<<16)|(1<<14)|(1<<12)|(1<<10)|(1<<8)|(1<<6)|(1<<4)|(1<<2)|(1<<0)) | |
2555 | /* | |
2556 | * The registers we must save are all those not preserved across | |
2557 | * procedure calls. Dest_Reg (see tm-mips.h) must also be saved. | |
2558 | * In addition, we must save the PC, PUSH_FP_REGNUM, MMLO/-HI | |
2559 | * and FP Control/Status registers. | |
361d1df0 | 2560 | * |
c906108c SS |
2561 | * |
2562 | * Dummy frame layout: | |
2563 | * (high memory) | |
c5aa993b JM |
2564 | * Saved PC |
2565 | * Saved MMHI, MMLO, FPC_CSR | |
2566 | * Saved R31 | |
2567 | * Saved R28 | |
2568 | * ... | |
2569 | * Saved R1 | |
c906108c SS |
2570 | * Saved D18 (i.e. F19, F18) |
2571 | * ... | |
2572 | * Saved D0 (i.e. F1, F0) | |
c5aa993b | 2573 | * Argument build area and stack arguments written via mips_push_arguments |
c906108c SS |
2574 | * (low memory) |
2575 | */ | |
2576 | ||
2577 | /* Save special registers (PC, MMHI, MMLO, FPC_CSR) */ | |
c5aa993b JM |
2578 | PROC_FRAME_REG (proc_desc) = PUSH_FP_REGNUM; |
2579 | PROC_FRAME_OFFSET (proc_desc) = 0; | |
2580 | PROC_FRAME_ADJUST (proc_desc) = 0; | |
c906108c SS |
2581 | mips_push_register (&sp, PC_REGNUM); |
2582 | mips_push_register (&sp, HI_REGNUM); | |
2583 | mips_push_register (&sp, LO_REGNUM); | |
2584 | mips_push_register (&sp, MIPS_FPU_TYPE == MIPS_FPU_NONE ? 0 : FCRCS_REGNUM); | |
2585 | ||
2586 | /* Save general CPU registers */ | |
c5aa993b | 2587 | PROC_REG_MASK (proc_desc) = GEN_REG_SAVE_MASK; |
c906108c | 2588 | /* PROC_REG_OFFSET is the offset of the first saved register from FP. */ |
c5aa993b JM |
2589 | PROC_REG_OFFSET (proc_desc) = sp - old_sp - MIPS_SAVED_REGSIZE; |
2590 | for (ireg = 32; --ireg >= 0;) | |
2591 | if (PROC_REG_MASK (proc_desc) & (1 << ireg)) | |
c906108c SS |
2592 | mips_push_register (&sp, ireg); |
2593 | ||
2594 | /* Save floating point registers starting with high order word */ | |
c5aa993b | 2595 | PROC_FREG_MASK (proc_desc) = |
c906108c SS |
2596 | MIPS_FPU_TYPE == MIPS_FPU_DOUBLE ? FLOAT_REG_SAVE_MASK |
2597 | : MIPS_FPU_TYPE == MIPS_FPU_SINGLE ? FLOAT_SINGLE_REG_SAVE_MASK : 0; | |
2598 | /* PROC_FREG_OFFSET is the offset of the first saved *double* register | |
2599 | from FP. */ | |
c5aa993b JM |
2600 | PROC_FREG_OFFSET (proc_desc) = sp - old_sp - 8; |
2601 | for (ireg = 32; --ireg >= 0;) | |
2602 | if (PROC_FREG_MASK (proc_desc) & (1 << ireg)) | |
c906108c SS |
2603 | mips_push_register (&sp, ireg + FP0_REGNUM); |
2604 | ||
2605 | /* Update the frame pointer for the call dummy and the stack pointer. | |
2606 | Set the procedure's starting and ending addresses to point to the | |
2607 | call dummy address at the entry point. */ | |
2608 | write_register (PUSH_FP_REGNUM, old_sp); | |
2609 | write_register (SP_REGNUM, sp); | |
c5aa993b JM |
2610 | PROC_LOW_ADDR (proc_desc) = CALL_DUMMY_ADDRESS (); |
2611 | PROC_HIGH_ADDR (proc_desc) = CALL_DUMMY_ADDRESS () + 4; | |
2612 | SET_PROC_DESC_IS_DUMMY (proc_desc); | |
2613 | PROC_PC_REG (proc_desc) = RA_REGNUM; | |
c906108c SS |
2614 | } |
2615 | ||
2616 | void | |
acdb74a0 | 2617 | mips_pop_frame (void) |
c906108c SS |
2618 | { |
2619 | register int regnum; | |
2620 | struct frame_info *frame = get_current_frame (); | |
2621 | CORE_ADDR new_sp = FRAME_FP (frame); | |
2622 | ||
cce74817 | 2623 | mips_extra_func_info_t proc_desc = frame->extra_info->proc_desc; |
c906108c | 2624 | |
c5aa993b | 2625 | write_register (PC_REGNUM, FRAME_SAVED_PC (frame)); |
c906108c SS |
2626 | if (frame->saved_regs == NULL) |
2627 | mips_find_saved_regs (frame); | |
2628 | for (regnum = 0; regnum < NUM_REGS; regnum++) | |
2629 | { | |
2630 | if (regnum != SP_REGNUM && regnum != PC_REGNUM | |
2631 | && frame->saved_regs[regnum]) | |
2632 | write_register (regnum, | |
2633 | read_memory_integer (frame->saved_regs[regnum], | |
c5aa993b | 2634 | MIPS_SAVED_REGSIZE)); |
c906108c SS |
2635 | } |
2636 | write_register (SP_REGNUM, new_sp); | |
2637 | flush_cached_frames (); | |
2638 | ||
c5aa993b | 2639 | if (proc_desc && PROC_DESC_IS_DUMMY (proc_desc)) |
c906108c SS |
2640 | { |
2641 | struct linked_proc_info *pi_ptr, *prev_ptr; | |
2642 | ||
2643 | for (pi_ptr = linked_proc_desc_table, prev_ptr = NULL; | |
2644 | pi_ptr != NULL; | |
2645 | prev_ptr = pi_ptr, pi_ptr = pi_ptr->next) | |
2646 | { | |
2647 | if (&pi_ptr->info == proc_desc) | |
2648 | break; | |
2649 | } | |
2650 | ||
2651 | if (pi_ptr == NULL) | |
2652 | error ("Can't locate dummy extra frame info\n"); | |
2653 | ||
2654 | if (prev_ptr != NULL) | |
2655 | prev_ptr->next = pi_ptr->next; | |
2656 | else | |
2657 | linked_proc_desc_table = pi_ptr->next; | |
2658 | ||
b8c9b27d | 2659 | xfree (pi_ptr); |
c906108c SS |
2660 | |
2661 | write_register (HI_REGNUM, | |
c5aa993b | 2662 | read_memory_integer (new_sp - 2 * MIPS_SAVED_REGSIZE, |
7a292a7a | 2663 | MIPS_SAVED_REGSIZE)); |
c906108c | 2664 | write_register (LO_REGNUM, |
c5aa993b | 2665 | read_memory_integer (new_sp - 3 * MIPS_SAVED_REGSIZE, |
7a292a7a | 2666 | MIPS_SAVED_REGSIZE)); |
c906108c SS |
2667 | if (MIPS_FPU_TYPE != MIPS_FPU_NONE) |
2668 | write_register (FCRCS_REGNUM, | |
c5aa993b | 2669 | read_memory_integer (new_sp - 4 * MIPS_SAVED_REGSIZE, |
7a292a7a | 2670 | MIPS_SAVED_REGSIZE)); |
c906108c SS |
2671 | } |
2672 | } | |
2673 | ||
dd824b04 DJ |
2674 | /* Floating point register management. |
2675 | ||
2676 | Background: MIPS1 & 2 fp registers are 32 bits wide. To support | |
2677 | 64bit operations, these early MIPS cpus treat fp register pairs | |
2678 | (f0,f1) as a single register (d0). Later MIPS cpu's have 64 bit fp | |
2679 | registers and offer a compatibility mode that emulates the MIPS2 fp | |
2680 | model. When operating in MIPS2 fp compat mode, later cpu's split | |
2681 | double precision floats into two 32-bit chunks and store them in | |
2682 | consecutive fp regs. To display 64-bit floats stored in this | |
2683 | fashion, we have to combine 32 bits from f0 and 32 bits from f1. | |
2684 | Throw in user-configurable endianness and you have a real mess. | |
2685 | ||
2686 | The way this works is: | |
2687 | - If we are in 32-bit mode or on a 32-bit processor, then a 64-bit | |
2688 | double-precision value will be split across two logical registers. | |
2689 | The lower-numbered logical register will hold the low-order bits, | |
2690 | regardless of the processor's endianness. | |
2691 | - If we are on a 64-bit processor, and we are looking for a | |
2692 | single-precision value, it will be in the low ordered bits | |
2693 | of a 64-bit GPR (after mfc1, for example) or a 64-bit register | |
2694 | save slot in memory. | |
2695 | - If we are in 64-bit mode, everything is straightforward. | |
2696 | ||
2697 | Note that this code only deals with "live" registers at the top of the | |
2698 | stack. We will attempt to deal with saved registers later, when | |
2699 | the raw/cooked register interface is in place. (We need a general | |
2700 | interface that can deal with dynamic saved register sizes -- fp | |
2701 | regs could be 32 bits wide in one frame and 64 on the frame above | |
2702 | and below). */ | |
2703 | ||
67b2c998 DJ |
2704 | static struct type * |
2705 | mips_float_register_type (void) | |
2706 | { | |
361d1df0 | 2707 | if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) |
67b2c998 DJ |
2708 | return builtin_type_ieee_single_big; |
2709 | else | |
2710 | return builtin_type_ieee_single_little; | |
2711 | } | |
2712 | ||
2713 | static struct type * | |
2714 | mips_double_register_type (void) | |
2715 | { | |
361d1df0 | 2716 | if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) |
67b2c998 DJ |
2717 | return builtin_type_ieee_double_big; |
2718 | else | |
2719 | return builtin_type_ieee_double_little; | |
2720 | } | |
2721 | ||
dd824b04 DJ |
2722 | /* Copy a 32-bit single-precision value from the current frame |
2723 | into rare_buffer. */ | |
2724 | ||
2725 | static void | |
2726 | mips_read_fp_register_single (int regno, char *rare_buffer) | |
2727 | { | |
2728 | int raw_size = REGISTER_RAW_SIZE (regno); | |
2729 | char *raw_buffer = alloca (raw_size); | |
2730 | ||
cda5a58a | 2731 | if (!frame_register_read (selected_frame, regno, raw_buffer)) |
dd824b04 DJ |
2732 | error ("can't read register %d (%s)", regno, REGISTER_NAME (regno)); |
2733 | if (raw_size == 8) | |
2734 | { | |
2735 | /* We have a 64-bit value for this register. Find the low-order | |
2736 | 32 bits. */ | |
2737 | int offset; | |
2738 | ||
2739 | if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) | |
2740 | offset = 4; | |
2741 | else | |
2742 | offset = 0; | |
2743 | ||
2744 | memcpy (rare_buffer, raw_buffer + offset, 4); | |
2745 | } | |
2746 | else | |
2747 | { | |
2748 | memcpy (rare_buffer, raw_buffer, 4); | |
2749 | } | |
2750 | } | |
2751 | ||
2752 | /* Copy a 64-bit double-precision value from the current frame into | |
2753 | rare_buffer. This may include getting half of it from the next | |
2754 | register. */ | |
2755 | ||
2756 | static void | |
2757 | mips_read_fp_register_double (int regno, char *rare_buffer) | |
2758 | { | |
2759 | int raw_size = REGISTER_RAW_SIZE (regno); | |
2760 | ||
2761 | if (raw_size == 8 && !mips2_fp_compat ()) | |
2762 | { | |
2763 | /* We have a 64-bit value for this register, and we should use | |
2764 | all 64 bits. */ | |
cda5a58a | 2765 | if (!frame_register_read (selected_frame, regno, rare_buffer)) |
dd824b04 DJ |
2766 | error ("can't read register %d (%s)", regno, REGISTER_NAME (regno)); |
2767 | } | |
2768 | else | |
2769 | { | |
2770 | if ((regno - FP0_REGNUM) & 1) | |
2771 | internal_error (__FILE__, __LINE__, | |
2772 | "mips_read_fp_register_double: bad access to " | |
2773 | "odd-numbered FP register"); | |
2774 | ||
2775 | /* mips_read_fp_register_single will find the correct 32 bits from | |
2776 | each register. */ | |
2777 | if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) | |
2778 | { | |
2779 | mips_read_fp_register_single (regno, rare_buffer + 4); | |
2780 | mips_read_fp_register_single (regno + 1, rare_buffer); | |
2781 | } | |
361d1df0 | 2782 | else |
dd824b04 DJ |
2783 | { |
2784 | mips_read_fp_register_single (regno, rare_buffer); | |
2785 | mips_read_fp_register_single (regno + 1, rare_buffer + 4); | |
2786 | } | |
2787 | } | |
2788 | } | |
2789 | ||
c906108c | 2790 | static void |
acdb74a0 | 2791 | mips_print_register (int regnum, int all) |
c906108c SS |
2792 | { |
2793 | char raw_buffer[MAX_REGISTER_RAW_SIZE]; | |
2794 | ||
2795 | /* Get the data in raw format. */ | |
cda5a58a | 2796 | if (!frame_register_read (selected_frame, regnum, raw_buffer)) |
c906108c SS |
2797 | { |
2798 | printf_filtered ("%s: [Invalid]", REGISTER_NAME (regnum)); | |
2799 | return; | |
2800 | } | |
2801 | ||
dd824b04 DJ |
2802 | /* If we have a actual 32-bit floating point register (or we are in |
2803 | 32-bit compatibility mode), and the register is even-numbered, | |
2804 | also print it as a double (spanning two registers). */ | |
c906108c | 2805 | if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT |
dd824b04 DJ |
2806 | && (REGISTER_RAW_SIZE (regnum) == 4 |
2807 | || mips2_fp_compat ()) | |
c5aa993b | 2808 | && !((regnum - FP0_REGNUM) & 1)) |
dd824b04 DJ |
2809 | { |
2810 | char dbuffer[2 * MAX_REGISTER_RAW_SIZE]; | |
c906108c | 2811 | |
dd824b04 | 2812 | mips_read_fp_register_double (regnum, dbuffer); |
c906108c | 2813 | |
dd824b04 | 2814 | printf_filtered ("(d%d: ", regnum - FP0_REGNUM); |
67b2c998 | 2815 | val_print (mips_double_register_type (), dbuffer, 0, 0, |
dd824b04 DJ |
2816 | gdb_stdout, 0, 1, 0, Val_pretty_default); |
2817 | printf_filtered ("); "); | |
2818 | } | |
c906108c SS |
2819 | fputs_filtered (REGISTER_NAME (regnum), gdb_stdout); |
2820 | ||
2821 | /* The problem with printing numeric register names (r26, etc.) is that | |
2822 | the user can't use them on input. Probably the best solution is to | |
2823 | fix it so that either the numeric or the funky (a2, etc.) names | |
2824 | are accepted on input. */ | |
2825 | if (regnum < MIPS_NUMREGS) | |
2826 | printf_filtered ("(r%d): ", regnum); | |
2827 | else | |
2828 | printf_filtered (": "); | |
2829 | ||
2830 | /* If virtual format is floating, print it that way. */ | |
2831 | if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT) | |
dd824b04 DJ |
2832 | if (REGISTER_RAW_SIZE (regnum) == 8 && !mips2_fp_compat ()) |
2833 | { | |
2834 | /* We have a meaningful 64-bit value in this register. Show | |
2835 | it as a 32-bit float and a 64-bit double. */ | |
d7449b42 | 2836 | int offset = 4 * (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG); |
c906108c SS |
2837 | |
2838 | printf_filtered (" (float) "); | |
67b2c998 | 2839 | val_print (mips_float_register_type (), raw_buffer + offset, 0, 0, |
c906108c SS |
2840 | gdb_stdout, 0, 1, 0, Val_pretty_default); |
2841 | printf_filtered (", (double) "); | |
67b2c998 | 2842 | val_print (mips_double_register_type (), raw_buffer, 0, 0, |
c906108c SS |
2843 | gdb_stdout, 0, 1, 0, Val_pretty_default); |
2844 | } | |
2845 | else | |
2846 | val_print (REGISTER_VIRTUAL_TYPE (regnum), raw_buffer, 0, 0, | |
2847 | gdb_stdout, 0, 1, 0, Val_pretty_default); | |
2848 | /* Else print as integer in hex. */ | |
2849 | else | |
ed9a39eb JM |
2850 | { |
2851 | int offset; | |
2852 | ||
d7449b42 | 2853 | if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) |
ed9a39eb JM |
2854 | offset = REGISTER_RAW_SIZE (regnum) - REGISTER_VIRTUAL_SIZE (regnum); |
2855 | else | |
2856 | offset = 0; | |
361d1df0 | 2857 | |
ed9a39eb JM |
2858 | print_scalar_formatted (raw_buffer + offset, |
2859 | REGISTER_VIRTUAL_TYPE (regnum), | |
2860 | 'x', 0, gdb_stdout); | |
2861 | } | |
c906108c SS |
2862 | } |
2863 | ||
361d1df0 | 2864 | /* Replacement for generic do_registers_info. |
c906108c SS |
2865 | Print regs in pretty columns. */ |
2866 | ||
2867 | static int | |
acdb74a0 | 2868 | do_fp_register_row (int regnum) |
c5aa993b | 2869 | { /* do values for FP (float) regs */ |
dd824b04 | 2870 | char *raw_buffer; |
c906108c SS |
2871 | double doub, flt1, flt2; /* doubles extracted from raw hex data */ |
2872 | int inv1, inv2, inv3; | |
c5aa993b | 2873 | |
dd824b04 | 2874 | raw_buffer = (char *) alloca (2 * REGISTER_RAW_SIZE (FP0_REGNUM)); |
c906108c | 2875 | |
dd824b04 | 2876 | if (REGISTER_RAW_SIZE (regnum) == 4 || mips2_fp_compat ()) |
c906108c | 2877 | { |
dd824b04 DJ |
2878 | /* 4-byte registers: we can fit two registers per row. */ |
2879 | /* Also print every pair of 4-byte regs as an 8-byte double. */ | |
2880 | mips_read_fp_register_single (regnum, raw_buffer); | |
67b2c998 | 2881 | flt1 = unpack_double (mips_float_register_type (), raw_buffer, &inv1); |
c5aa993b | 2882 | |
dd824b04 | 2883 | mips_read_fp_register_single (regnum + 1, raw_buffer); |
67b2c998 | 2884 | flt2 = unpack_double (mips_float_register_type (), raw_buffer, &inv2); |
dd824b04 DJ |
2885 | |
2886 | mips_read_fp_register_double (regnum, raw_buffer); | |
67b2c998 | 2887 | doub = unpack_double (mips_double_register_type (), raw_buffer, &inv3); |
361d1df0 | 2888 | |
1adad886 AC |
2889 | printf_filtered (" %-5s", REGISTER_NAME (regnum)); |
2890 | if (inv1) | |
2891 | printf_filtered (": <invalid float>"); | |
2892 | else | |
2893 | printf_filtered ("%-17.9g", flt1); | |
2894 | ||
2895 | printf_filtered (" %-5s", REGISTER_NAME (regnum + 1)); | |
2896 | if (inv2) | |
2897 | printf_filtered (": <invalid float>"); | |
2898 | else | |
2899 | printf_filtered ("%-17.9g", flt2); | |
2900 | ||
2901 | printf_filtered (" dbl: "); | |
2902 | if (inv3) | |
2903 | printf_filtered ("<invalid double>"); | |
2904 | else | |
2905 | printf_filtered ("%-24.17g", doub); | |
2906 | printf_filtered ("\n"); | |
2907 | ||
c906108c | 2908 | /* may want to do hex display here (future enhancement) */ |
c5aa993b | 2909 | regnum += 2; |
c906108c SS |
2910 | } |
2911 | else | |
dd824b04 DJ |
2912 | { |
2913 | /* Eight byte registers: print each one as float AND as double. */ | |
2914 | mips_read_fp_register_single (regnum, raw_buffer); | |
67b2c998 | 2915 | flt1 = unpack_double (mips_double_register_type (), raw_buffer, &inv1); |
c906108c | 2916 | |
dd824b04 | 2917 | mips_read_fp_register_double (regnum, raw_buffer); |
67b2c998 | 2918 | doub = unpack_double (mips_double_register_type (), raw_buffer, &inv3); |
361d1df0 | 2919 | |
1adad886 AC |
2920 | printf_filtered (" %-5s: ", REGISTER_NAME (regnum)); |
2921 | if (inv1) | |
2922 | printf_filtered ("<invalid float>"); | |
2923 | else | |
2924 | printf_filtered ("flt: %-17.9g", flt1); | |
2925 | ||
2926 | printf_filtered (" dbl: "); | |
2927 | if (inv3) | |
2928 | printf_filtered ("<invalid double>"); | |
2929 | else | |
2930 | printf_filtered ("%-24.17g", doub); | |
2931 | ||
2932 | printf_filtered ("\n"); | |
c906108c SS |
2933 | /* may want to do hex display here (future enhancement) */ |
2934 | regnum++; | |
2935 | } | |
2936 | return regnum; | |
2937 | } | |
2938 | ||
2939 | /* Print a row's worth of GP (int) registers, with name labels above */ | |
2940 | ||
2941 | static int | |
acdb74a0 | 2942 | do_gp_register_row (int regnum) |
c906108c SS |
2943 | { |
2944 | /* do values for GP (int) regs */ | |
2945 | char raw_buffer[MAX_REGISTER_RAW_SIZE]; | |
2946 | int ncols = (MIPS_REGSIZE == 8 ? 4 : 8); /* display cols per row */ | |
2947 | int col, byte; | |
2948 | int start_regnum = regnum; | |
2949 | int numregs = NUM_REGS; | |
2950 | ||
2951 | ||
2952 | /* For GP registers, we print a separate row of names above the vals */ | |
2953 | printf_filtered (" "); | |
2954 | for (col = 0; col < ncols && regnum < numregs; regnum++) | |
2955 | { | |
2956 | if (*REGISTER_NAME (regnum) == '\0') | |
c5aa993b | 2957 | continue; /* unused register */ |
c906108c | 2958 | if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT) |
c5aa993b JM |
2959 | break; /* end the row: reached FP register */ |
2960 | printf_filtered (MIPS_REGSIZE == 8 ? "%17s" : "%9s", | |
c906108c SS |
2961 | REGISTER_NAME (regnum)); |
2962 | col++; | |
2963 | } | |
c5aa993b | 2964 | printf_filtered (start_regnum < MIPS_NUMREGS ? "\n R%-4d" : "\n ", |
c906108c SS |
2965 | start_regnum); /* print the R0 to R31 names */ |
2966 | ||
2967 | regnum = start_regnum; /* go back to start of row */ | |
2968 | /* now print the values in hex, 4 or 8 to the row */ | |
2969 | for (col = 0; col < ncols && regnum < numregs; regnum++) | |
2970 | { | |
2971 | if (*REGISTER_NAME (regnum) == '\0') | |
c5aa993b | 2972 | continue; /* unused register */ |
c906108c | 2973 | if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT) |
c5aa993b | 2974 | break; /* end row: reached FP register */ |
c906108c | 2975 | /* OK: get the data in raw format. */ |
cda5a58a | 2976 | if (!frame_register_read (selected_frame, regnum, raw_buffer)) |
c906108c SS |
2977 | error ("can't read register %d (%s)", regnum, REGISTER_NAME (regnum)); |
2978 | /* pad small registers */ | |
43e526b9 | 2979 | for (byte = 0; byte < (MIPS_REGSIZE - REGISTER_VIRTUAL_SIZE (regnum)); byte++) |
c906108c SS |
2980 | printf_filtered (" "); |
2981 | /* Now print the register value in hex, endian order. */ | |
d7449b42 | 2982 | if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) |
43e526b9 JM |
2983 | for (byte = REGISTER_RAW_SIZE (regnum) - REGISTER_VIRTUAL_SIZE (regnum); |
2984 | byte < REGISTER_RAW_SIZE (regnum); | |
2985 | byte++) | |
c906108c SS |
2986 | printf_filtered ("%02x", (unsigned char) raw_buffer[byte]); |
2987 | else | |
43e526b9 JM |
2988 | for (byte = REGISTER_VIRTUAL_SIZE (regnum) - 1; |
2989 | byte >= 0; | |
2990 | byte--) | |
c906108c SS |
2991 | printf_filtered ("%02x", (unsigned char) raw_buffer[byte]); |
2992 | printf_filtered (" "); | |
2993 | col++; | |
2994 | } | |
c5aa993b | 2995 | if (col > 0) /* ie. if we actually printed anything... */ |
c906108c SS |
2996 | printf_filtered ("\n"); |
2997 | ||
2998 | return regnum; | |
2999 | } | |
3000 | ||
3001 | /* MIPS_DO_REGISTERS_INFO(): called by "info register" command */ | |
3002 | ||
3003 | void | |
acdb74a0 | 3004 | mips_do_registers_info (int regnum, int fpregs) |
c906108c | 3005 | { |
c5aa993b | 3006 | if (regnum != -1) /* do one specified register */ |
c906108c SS |
3007 | { |
3008 | if (*(REGISTER_NAME (regnum)) == '\0') | |
3009 | error ("Not a valid register for the current processor type"); | |
3010 | ||
3011 | mips_print_register (regnum, 0); | |
3012 | printf_filtered ("\n"); | |
3013 | } | |
c5aa993b JM |
3014 | else |
3015 | /* do all (or most) registers */ | |
c906108c SS |
3016 | { |
3017 | regnum = 0; | |
3018 | while (regnum < NUM_REGS) | |
3019 | { | |
c5aa993b JM |
3020 | if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT) |
3021 | if (fpregs) /* true for "INFO ALL-REGISTERS" command */ | |
c906108c SS |
3022 | regnum = do_fp_register_row (regnum); /* FP regs */ |
3023 | else | |
3024 | regnum += MIPS_NUMREGS; /* skip floating point regs */ | |
3025 | else | |
3026 | regnum = do_gp_register_row (regnum); /* GP (int) regs */ | |
3027 | } | |
3028 | } | |
3029 | } | |
3030 | ||
3031 | /* Return number of args passed to a frame. described by FIP. | |
3032 | Can return -1, meaning no way to tell. */ | |
3033 | ||
3034 | int | |
acdb74a0 | 3035 | mips_frame_num_args (struct frame_info *frame) |
c906108c | 3036 | { |
c906108c SS |
3037 | return -1; |
3038 | } | |
3039 | ||
3040 | /* Is this a branch with a delay slot? */ | |
3041 | ||
a14ed312 | 3042 | static int is_delayed (unsigned long); |
c906108c SS |
3043 | |
3044 | static int | |
acdb74a0 | 3045 | is_delayed (unsigned long insn) |
c906108c SS |
3046 | { |
3047 | int i; | |
3048 | for (i = 0; i < NUMOPCODES; ++i) | |
3049 | if (mips_opcodes[i].pinfo != INSN_MACRO | |
3050 | && (insn & mips_opcodes[i].mask) == mips_opcodes[i].match) | |
3051 | break; | |
3052 | return (i < NUMOPCODES | |
3053 | && (mips_opcodes[i].pinfo & (INSN_UNCOND_BRANCH_DELAY | |
3054 | | INSN_COND_BRANCH_DELAY | |
3055 | | INSN_COND_BRANCH_LIKELY))); | |
3056 | } | |
3057 | ||
3058 | int | |
acdb74a0 | 3059 | mips_step_skips_delay (CORE_ADDR pc) |
c906108c SS |
3060 | { |
3061 | char buf[MIPS_INSTLEN]; | |
3062 | ||
3063 | /* There is no branch delay slot on MIPS16. */ | |
3064 | if (pc_is_mips16 (pc)) | |
3065 | return 0; | |
3066 | ||
3067 | if (target_read_memory (pc, buf, MIPS_INSTLEN) != 0) | |
3068 | /* If error reading memory, guess that it is not a delayed branch. */ | |
3069 | return 0; | |
c5aa993b | 3070 | return is_delayed ((unsigned long) extract_unsigned_integer (buf, MIPS_INSTLEN)); |
c906108c SS |
3071 | } |
3072 | ||
3073 | ||
3074 | /* Skip the PC past function prologue instructions (32-bit version). | |
3075 | This is a helper function for mips_skip_prologue. */ | |
3076 | ||
3077 | static CORE_ADDR | |
f7b9e9fc | 3078 | mips32_skip_prologue (CORE_ADDR pc) |
c906108c | 3079 | { |
c5aa993b JM |
3080 | t_inst inst; |
3081 | CORE_ADDR end_pc; | |
3082 | int seen_sp_adjust = 0; | |
3083 | int load_immediate_bytes = 0; | |
3084 | ||
3085 | /* Skip the typical prologue instructions. These are the stack adjustment | |
3086 | instruction and the instructions that save registers on the stack | |
3087 | or in the gcc frame. */ | |
3088 | for (end_pc = pc + 100; pc < end_pc; pc += MIPS_INSTLEN) | |
3089 | { | |
3090 | unsigned long high_word; | |
c906108c | 3091 | |
c5aa993b JM |
3092 | inst = mips_fetch_instruction (pc); |
3093 | high_word = (inst >> 16) & 0xffff; | |
c906108c | 3094 | |
c5aa993b JM |
3095 | if (high_word == 0x27bd /* addiu $sp,$sp,offset */ |
3096 | || high_word == 0x67bd) /* daddiu $sp,$sp,offset */ | |
3097 | seen_sp_adjust = 1; | |
3098 | else if (inst == 0x03a1e823 || /* subu $sp,$sp,$at */ | |
3099 | inst == 0x03a8e823) /* subu $sp,$sp,$t0 */ | |
3100 | seen_sp_adjust = 1; | |
3101 | else if (((inst & 0xFFE00000) == 0xAFA00000 /* sw reg,n($sp) */ | |
3102 | || (inst & 0xFFE00000) == 0xFFA00000) /* sd reg,n($sp) */ | |
3103 | && (inst & 0x001F0000)) /* reg != $zero */ | |
3104 | continue; | |
3105 | ||
3106 | else if ((inst & 0xFFE00000) == 0xE7A00000) /* swc1 freg,n($sp) */ | |
3107 | continue; | |
3108 | else if ((inst & 0xF3E00000) == 0xA3C00000 && (inst & 0x001F0000)) | |
3109 | /* sx reg,n($s8) */ | |
3110 | continue; /* reg != $zero */ | |
3111 | ||
3112 | /* move $s8,$sp. With different versions of gas this will be either | |
3113 | `addu $s8,$sp,$zero' or `or $s8,$sp,$zero' or `daddu s8,sp,$0'. | |
3114 | Accept any one of these. */ | |
3115 | else if (inst == 0x03A0F021 || inst == 0x03a0f025 || inst == 0x03a0f02d) | |
3116 | continue; | |
3117 | ||
3118 | else if ((inst & 0xFF9F07FF) == 0x00800021) /* move reg,$a0-$a3 */ | |
3119 | continue; | |
3120 | else if (high_word == 0x3c1c) /* lui $gp,n */ | |
3121 | continue; | |
3122 | else if (high_word == 0x279c) /* addiu $gp,$gp,n */ | |
3123 | continue; | |
3124 | else if (inst == 0x0399e021 /* addu $gp,$gp,$t9 */ | |
3125 | || inst == 0x033ce021) /* addu $gp,$t9,$gp */ | |
3126 | continue; | |
3127 | /* The following instructions load $at or $t0 with an immediate | |
3128 | value in preparation for a stack adjustment via | |
3129 | subu $sp,$sp,[$at,$t0]. These instructions could also initialize | |
3130 | a local variable, so we accept them only before a stack adjustment | |
3131 | instruction was seen. */ | |
3132 | else if (!seen_sp_adjust) | |
3133 | { | |
3134 | if (high_word == 0x3c01 || /* lui $at,n */ | |
3135 | high_word == 0x3c08) /* lui $t0,n */ | |
3136 | { | |
3137 | load_immediate_bytes += MIPS_INSTLEN; /* FIXME!! */ | |
3138 | continue; | |
3139 | } | |
3140 | else if (high_word == 0x3421 || /* ori $at,$at,n */ | |
3141 | high_word == 0x3508 || /* ori $t0,$t0,n */ | |
3142 | high_word == 0x3401 || /* ori $at,$zero,n */ | |
3143 | high_word == 0x3408) /* ori $t0,$zero,n */ | |
3144 | { | |
3145 | load_immediate_bytes += MIPS_INSTLEN; /* FIXME!! */ | |
3146 | continue; | |
3147 | } | |
3148 | else | |
3149 | break; | |
3150 | } | |
3151 | else | |
3152 | break; | |
c906108c SS |
3153 | } |
3154 | ||
c5aa993b JM |
3155 | /* In a frameless function, we might have incorrectly |
3156 | skipped some load immediate instructions. Undo the skipping | |
3157 | if the load immediate was not followed by a stack adjustment. */ | |
3158 | if (load_immediate_bytes && !seen_sp_adjust) | |
3159 | pc -= load_immediate_bytes; | |
3160 | return pc; | |
c906108c SS |
3161 | } |
3162 | ||
3163 | /* Skip the PC past function prologue instructions (16-bit version). | |
3164 | This is a helper function for mips_skip_prologue. */ | |
3165 | ||
3166 | static CORE_ADDR | |
f7b9e9fc | 3167 | mips16_skip_prologue (CORE_ADDR pc) |
c906108c | 3168 | { |
c5aa993b JM |
3169 | CORE_ADDR end_pc; |
3170 | int extend_bytes = 0; | |
3171 | int prev_extend_bytes; | |
c906108c | 3172 | |
c5aa993b JM |
3173 | /* Table of instructions likely to be found in a function prologue. */ |
3174 | static struct | |
c906108c SS |
3175 | { |
3176 | unsigned short inst; | |
3177 | unsigned short mask; | |
c5aa993b JM |
3178 | } |
3179 | table[] = | |
3180 | { | |
c906108c | 3181 | { |
c5aa993b JM |
3182 | 0x6300, 0xff00 |
3183 | } | |
3184 | , /* addiu $sp,offset */ | |
3185 | { | |
3186 | 0xfb00, 0xff00 | |
3187 | } | |
3188 | , /* daddiu $sp,offset */ | |
3189 | { | |
3190 | 0xd000, 0xf800 | |
3191 | } | |
3192 | , /* sw reg,n($sp) */ | |
3193 | { | |
3194 | 0xf900, 0xff00 | |
3195 | } | |
3196 | , /* sd reg,n($sp) */ | |
3197 | { | |
3198 | 0x6200, 0xff00 | |
3199 | } | |
3200 | , /* sw $ra,n($sp) */ | |
3201 | { | |
3202 | 0xfa00, 0xff00 | |
3203 | } | |
3204 | , /* sd $ra,n($sp) */ | |
3205 | { | |
3206 | 0x673d, 0xffff | |
3207 | } | |
3208 | , /* move $s1,sp */ | |
3209 | { | |
3210 | 0xd980, 0xff80 | |
3211 | } | |
3212 | , /* sw $a0-$a3,n($s1) */ | |
3213 | { | |
3214 | 0x6704, 0xff1c | |
3215 | } | |
3216 | , /* move reg,$a0-$a3 */ | |
3217 | { | |
3218 | 0xe809, 0xf81f | |
3219 | } | |
3220 | , /* entry pseudo-op */ | |
3221 | { | |
3222 | 0x0100, 0xff00 | |
3223 | } | |
3224 | , /* addiu $s1,$sp,n */ | |
3225 | { | |
3226 | 0, 0 | |
3227 | } /* end of table marker */ | |
3228 | }; | |
3229 | ||
3230 | /* Skip the typical prologue instructions. These are the stack adjustment | |
3231 | instruction and the instructions that save registers on the stack | |
3232 | or in the gcc frame. */ | |
3233 | for (end_pc = pc + 100; pc < end_pc; pc += MIPS16_INSTLEN) | |
3234 | { | |
3235 | unsigned short inst; | |
3236 | int i; | |
c906108c | 3237 | |
c5aa993b | 3238 | inst = mips_fetch_instruction (pc); |
c906108c | 3239 | |
c5aa993b JM |
3240 | /* Normally we ignore an extend instruction. However, if it is |
3241 | not followed by a valid prologue instruction, we must adjust | |
3242 | the pc back over the extend so that it won't be considered | |
3243 | part of the prologue. */ | |
3244 | if ((inst & 0xf800) == 0xf000) /* extend */ | |
3245 | { | |
3246 | extend_bytes = MIPS16_INSTLEN; | |
3247 | continue; | |
3248 | } | |
3249 | prev_extend_bytes = extend_bytes; | |
3250 | extend_bytes = 0; | |
c906108c | 3251 | |
c5aa993b JM |
3252 | /* Check for other valid prologue instructions besides extend. */ |
3253 | for (i = 0; table[i].mask != 0; i++) | |
3254 | if ((inst & table[i].mask) == table[i].inst) /* found, get out */ | |
3255 | break; | |
3256 | if (table[i].mask != 0) /* it was in table? */ | |
3257 | continue; /* ignore it */ | |
3258 | else | |
3259 | /* non-prologue */ | |
3260 | { | |
3261 | /* Return the current pc, adjusted backwards by 2 if | |
3262 | the previous instruction was an extend. */ | |
3263 | return pc - prev_extend_bytes; | |
3264 | } | |
c906108c SS |
3265 | } |
3266 | return pc; | |
3267 | } | |
3268 | ||
3269 | /* To skip prologues, I use this predicate. Returns either PC itself | |
3270 | if the code at PC does not look like a function prologue; otherwise | |
3271 | returns an address that (if we're lucky) follows the prologue. If | |
3272 | LENIENT, then we must skip everything which is involved in setting | |
3273 | up the frame (it's OK to skip more, just so long as we don't skip | |
3274 | anything which might clobber the registers which are being saved. | |
3275 | We must skip more in the case where part of the prologue is in the | |
3276 | delay slot of a non-prologue instruction). */ | |
3277 | ||
3278 | CORE_ADDR | |
f7b9e9fc | 3279 | mips_skip_prologue (CORE_ADDR pc) |
c906108c SS |
3280 | { |
3281 | /* See if we can determine the end of the prologue via the symbol table. | |
3282 | If so, then return either PC, or the PC after the prologue, whichever | |
3283 | is greater. */ | |
3284 | ||
3285 | CORE_ADDR post_prologue_pc = after_prologue (pc, NULL); | |
3286 | ||
3287 | if (post_prologue_pc != 0) | |
3288 | return max (pc, post_prologue_pc); | |
3289 | ||
3290 | /* Can't determine prologue from the symbol table, need to examine | |
3291 | instructions. */ | |
3292 | ||
3293 | if (pc_is_mips16 (pc)) | |
f7b9e9fc | 3294 | return mips16_skip_prologue (pc); |
c906108c | 3295 | else |
f7b9e9fc | 3296 | return mips32_skip_prologue (pc); |
c906108c | 3297 | } |
c906108c | 3298 | |
7a292a7a SS |
3299 | /* Determine how a return value is stored within the MIPS register |
3300 | file, given the return type `valtype'. */ | |
3301 | ||
3302 | struct return_value_word | |
3303 | { | |
3304 | int len; | |
3305 | int reg; | |
3306 | int reg_offset; | |
3307 | int buf_offset; | |
3308 | }; | |
3309 | ||
7a292a7a | 3310 | static void |
acdb74a0 AC |
3311 | return_value_location (struct type *valtype, |
3312 | struct return_value_word *hi, | |
3313 | struct return_value_word *lo) | |
7a292a7a SS |
3314 | { |
3315 | int len = TYPE_LENGTH (valtype); | |
c5aa993b | 3316 | |
7a292a7a SS |
3317 | if (TYPE_CODE (valtype) == TYPE_CODE_FLT |
3318 | && ((MIPS_FPU_TYPE == MIPS_FPU_DOUBLE && (len == 4 || len == 8)) | |
3319 | || (MIPS_FPU_TYPE == MIPS_FPU_SINGLE && len == 4))) | |
3320 | { | |
3321 | if (!FP_REGISTER_DOUBLE && len == 8) | |
3322 | { | |
3323 | /* We need to break a 64bit float in two 32 bit halves and | |
c5aa993b | 3324 | spread them across a floating-point register pair. */ |
d7449b42 AC |
3325 | lo->buf_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 4 : 0; |
3326 | hi->buf_offset = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? 0 : 4; | |
3327 | lo->reg_offset = ((TARGET_BYTE_ORDER == BFD_ENDIAN_BIG | |
7a292a7a SS |
3328 | && REGISTER_RAW_SIZE (FP0_REGNUM) == 8) |
3329 | ? 4 : 0); | |
3330 | hi->reg_offset = lo->reg_offset; | |
3331 | lo->reg = FP0_REGNUM + 0; | |
3332 | hi->reg = FP0_REGNUM + 1; | |
3333 | lo->len = 4; | |
3334 | hi->len = 4; | |
3335 | } | |
3336 | else | |
3337 | { | |
3338 | /* The floating point value fits in a single floating-point | |
c5aa993b | 3339 | register. */ |
d7449b42 | 3340 | lo->reg_offset = ((TARGET_BYTE_ORDER == BFD_ENDIAN_BIG |
7a292a7a SS |
3341 | && REGISTER_RAW_SIZE (FP0_REGNUM) == 8 |
3342 | && len == 4) | |
3343 | ? 4 : 0); | |
3344 | lo->reg = FP0_REGNUM; | |
3345 | lo->len = len; | |
3346 | lo->buf_offset = 0; | |
3347 | hi->len = 0; | |
3348 | hi->reg_offset = 0; | |
3349 | hi->buf_offset = 0; | |
3350 | hi->reg = 0; | |
3351 | } | |
3352 | } | |
3353 | else | |
3354 | { | |
3355 | /* Locate a result possibly spread across two registers. */ | |
3356 | int regnum = 2; | |
3357 | lo->reg = regnum + 0; | |
3358 | hi->reg = regnum + 1; | |
d7449b42 | 3359 | if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG |
7a292a7a SS |
3360 | && len < MIPS_SAVED_REGSIZE) |
3361 | { | |
3362 | /* "un-left-justify" the value in the low register */ | |
3363 | lo->reg_offset = MIPS_SAVED_REGSIZE - len; | |
3364 | lo->len = len; | |
3365 | hi->reg_offset = 0; | |
3366 | hi->len = 0; | |
3367 | } | |
d7449b42 | 3368 | else if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG |
7a292a7a SS |
3369 | && len > MIPS_SAVED_REGSIZE /* odd-size structs */ |
3370 | && len < MIPS_SAVED_REGSIZE * 2 | |
3371 | && (TYPE_CODE (valtype) == TYPE_CODE_STRUCT || | |
3372 | TYPE_CODE (valtype) == TYPE_CODE_UNION)) | |
3373 | { | |
3374 | /* "un-left-justify" the value spread across two registers. */ | |
3375 | lo->reg_offset = 2 * MIPS_SAVED_REGSIZE - len; | |
3376 | lo->len = MIPS_SAVED_REGSIZE - lo->reg_offset; | |
3377 | hi->reg_offset = 0; | |
3378 | hi->len = len - lo->len; | |
3379 | } | |
3380 | else | |
3381 | { | |
3382 | /* Only perform a partial copy of the second register. */ | |
3383 | lo->reg_offset = 0; | |
3384 | hi->reg_offset = 0; | |
3385 | if (len > MIPS_SAVED_REGSIZE) | |
3386 | { | |
3387 | lo->len = MIPS_SAVED_REGSIZE; | |
3388 | hi->len = len - MIPS_SAVED_REGSIZE; | |
3389 | } | |
3390 | else | |
3391 | { | |
3392 | lo->len = len; | |
3393 | hi->len = 0; | |
3394 | } | |
3395 | } | |
d7449b42 | 3396 | if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG |
7a292a7a SS |
3397 | && REGISTER_RAW_SIZE (regnum) == 8 |
3398 | && MIPS_SAVED_REGSIZE == 4) | |
3399 | { | |
3400 | /* Account for the fact that only the least-signficant part | |
c5aa993b | 3401 | of the register is being used */ |
7a292a7a SS |
3402 | lo->reg_offset += 4; |
3403 | hi->reg_offset += 4; | |
3404 | } | |
3405 | lo->buf_offset = 0; | |
3406 | hi->buf_offset = lo->len; | |
3407 | } | |
3408 | } | |
3409 | ||
3410 | /* Given a return value in `regbuf' with a type `valtype', extract and | |
3411 | copy its value into `valbuf'. */ | |
3412 | ||
c906108c | 3413 | void |
acdb74a0 AC |
3414 | mips_extract_return_value (struct type *valtype, |
3415 | char regbuf[REGISTER_BYTES], | |
3416 | char *valbuf) | |
c906108c | 3417 | { |
7a292a7a SS |
3418 | struct return_value_word lo; |
3419 | struct return_value_word hi; | |
99567b1b | 3420 | return_value_location (valtype, &hi, &lo); |
7a292a7a SS |
3421 | |
3422 | memcpy (valbuf + lo.buf_offset, | |
3423 | regbuf + REGISTER_BYTE (lo.reg) + lo.reg_offset, | |
3424 | lo.len); | |
3425 | ||
3426 | if (hi.len > 0) | |
3427 | memcpy (valbuf + hi.buf_offset, | |
3428 | regbuf + REGISTER_BYTE (hi.reg) + hi.reg_offset, | |
3429 | hi.len); | |
c906108c SS |
3430 | } |
3431 | ||
7a292a7a SS |
3432 | /* Given a return value in `valbuf' with a type `valtype', write it's |
3433 | value into the appropriate register. */ | |
3434 | ||
c906108c | 3435 | void |
acdb74a0 | 3436 | mips_store_return_value (struct type *valtype, char *valbuf) |
c906108c | 3437 | { |
7a292a7a SS |
3438 | char raw_buffer[MAX_REGISTER_RAW_SIZE]; |
3439 | struct return_value_word lo; | |
3440 | struct return_value_word hi; | |
99567b1b | 3441 | return_value_location (valtype, &hi, &lo); |
7a292a7a SS |
3442 | |
3443 | memset (raw_buffer, 0, sizeof (raw_buffer)); | |
3444 | memcpy (raw_buffer + lo.reg_offset, valbuf + lo.buf_offset, lo.len); | |
3445 | write_register_bytes (REGISTER_BYTE (lo.reg), | |
3446 | raw_buffer, | |
3447 | REGISTER_RAW_SIZE (lo.reg)); | |
c5aa993b | 3448 | |
7a292a7a SS |
3449 | if (hi.len > 0) |
3450 | { | |
3451 | memset (raw_buffer, 0, sizeof (raw_buffer)); | |
3452 | memcpy (raw_buffer + hi.reg_offset, valbuf + hi.buf_offset, hi.len); | |
3453 | write_register_bytes (REGISTER_BYTE (hi.reg), | |
3454 | raw_buffer, | |
3455 | REGISTER_RAW_SIZE (hi.reg)); | |
3456 | } | |
c906108c SS |
3457 | } |
3458 | ||
3459 | /* Exported procedure: Is PC in the signal trampoline code */ | |
3460 | ||
3461 | int | |
acdb74a0 | 3462 | in_sigtramp (CORE_ADDR pc, char *ignore) |
c906108c SS |
3463 | { |
3464 | if (sigtramp_address == 0) | |
3465 | fixup_sigtramp (); | |
3466 | return (pc >= sigtramp_address && pc < sigtramp_end); | |
3467 | } | |
3468 | ||
a5ea2558 AC |
3469 | /* Root of all "set mips "/"show mips " commands. This will eventually be |
3470 | used for all MIPS-specific commands. */ | |
3471 | ||
a5ea2558 | 3472 | static void |
acdb74a0 | 3473 | show_mips_command (char *args, int from_tty) |
a5ea2558 AC |
3474 | { |
3475 | help_list (showmipscmdlist, "show mips ", all_commands, gdb_stdout); | |
3476 | } | |
3477 | ||
a5ea2558 | 3478 | static void |
acdb74a0 | 3479 | set_mips_command (char *args, int from_tty) |
a5ea2558 AC |
3480 | { |
3481 | printf_unfiltered ("\"set mips\" must be followed by an appropriate subcommand.\n"); | |
3482 | help_list (setmipscmdlist, "set mips ", all_commands, gdb_stdout); | |
3483 | } | |
3484 | ||
c906108c SS |
3485 | /* Commands to show/set the MIPS FPU type. */ |
3486 | ||
c906108c | 3487 | static void |
acdb74a0 | 3488 | show_mipsfpu_command (char *args, int from_tty) |
c906108c | 3489 | { |
c906108c SS |
3490 | char *fpu; |
3491 | switch (MIPS_FPU_TYPE) | |
3492 | { | |
3493 | case MIPS_FPU_SINGLE: | |
3494 | fpu = "single-precision"; | |
3495 | break; | |
3496 | case MIPS_FPU_DOUBLE: | |
3497 | fpu = "double-precision"; | |
3498 | break; | |
3499 | case MIPS_FPU_NONE: | |
3500 | fpu = "absent (none)"; | |
3501 | break; | |
93d56215 AC |
3502 | default: |
3503 | internal_error (__FILE__, __LINE__, "bad switch"); | |
c906108c SS |
3504 | } |
3505 | if (mips_fpu_type_auto) | |
3506 | printf_unfiltered ("The MIPS floating-point coprocessor is set automatically (currently %s)\n", | |
3507 | fpu); | |
3508 | else | |
3509 | printf_unfiltered ("The MIPS floating-point coprocessor is assumed to be %s\n", | |
3510 | fpu); | |
3511 | } | |
3512 | ||
3513 | ||
c906108c | 3514 | static void |
acdb74a0 | 3515 | set_mipsfpu_command (char *args, int from_tty) |
c906108c SS |
3516 | { |
3517 | printf_unfiltered ("\"set mipsfpu\" must be followed by \"double\", \"single\",\"none\" or \"auto\".\n"); | |
3518 | show_mipsfpu_command (args, from_tty); | |
3519 | } | |
3520 | ||
c906108c | 3521 | static void |
acdb74a0 | 3522 | set_mipsfpu_single_command (char *args, int from_tty) |
c906108c SS |
3523 | { |
3524 | mips_fpu_type = MIPS_FPU_SINGLE; | |
3525 | mips_fpu_type_auto = 0; | |
9e364162 | 3526 | gdbarch_tdep (current_gdbarch)->mips_fpu_type = MIPS_FPU_SINGLE; |
c906108c SS |
3527 | } |
3528 | ||
c906108c | 3529 | static void |
acdb74a0 | 3530 | set_mipsfpu_double_command (char *args, int from_tty) |
c906108c SS |
3531 | { |
3532 | mips_fpu_type = MIPS_FPU_DOUBLE; | |
3533 | mips_fpu_type_auto = 0; | |
9e364162 | 3534 | gdbarch_tdep (current_gdbarch)->mips_fpu_type = MIPS_FPU_DOUBLE; |
c906108c SS |
3535 | } |
3536 | ||
c906108c | 3537 | static void |
acdb74a0 | 3538 | set_mipsfpu_none_command (char *args, int from_tty) |
c906108c SS |
3539 | { |
3540 | mips_fpu_type = MIPS_FPU_NONE; | |
3541 | mips_fpu_type_auto = 0; | |
9e364162 | 3542 | gdbarch_tdep (current_gdbarch)->mips_fpu_type = MIPS_FPU_NONE; |
c906108c SS |
3543 | } |
3544 | ||
c906108c | 3545 | static void |
acdb74a0 | 3546 | set_mipsfpu_auto_command (char *args, int from_tty) |
c906108c SS |
3547 | { |
3548 | mips_fpu_type_auto = 1; | |
3549 | } | |
3550 | ||
3551 | /* Command to set the processor type. */ | |
3552 | ||
3553 | void | |
acdb74a0 | 3554 | mips_set_processor_type_command (char *args, int from_tty) |
c906108c SS |
3555 | { |
3556 | int i; | |
3557 | ||
3558 | if (tmp_mips_processor_type == NULL || *tmp_mips_processor_type == '\0') | |
3559 | { | |
3560 | printf_unfiltered ("The known MIPS processor types are as follows:\n\n"); | |
3561 | for (i = 0; mips_processor_type_table[i].name != NULL; ++i) | |
3562 | printf_unfiltered ("%s\n", mips_processor_type_table[i].name); | |
3563 | ||
3564 | /* Restore the value. */ | |
4fcf66da | 3565 | tmp_mips_processor_type = xstrdup (mips_processor_type); |
c906108c SS |
3566 | |
3567 | return; | |
3568 | } | |
c5aa993b | 3569 | |
c906108c SS |
3570 | if (!mips_set_processor_type (tmp_mips_processor_type)) |
3571 | { | |
3572 | error ("Unknown processor type `%s'.", tmp_mips_processor_type); | |
3573 | /* Restore its value. */ | |
4fcf66da | 3574 | tmp_mips_processor_type = xstrdup (mips_processor_type); |
c906108c SS |
3575 | } |
3576 | } | |
3577 | ||
3578 | static void | |
acdb74a0 | 3579 | mips_show_processor_type_command (char *args, int from_tty) |
c906108c SS |
3580 | { |
3581 | } | |
3582 | ||
3583 | /* Modify the actual processor type. */ | |
3584 | ||
3585 | int | |
acdb74a0 | 3586 | mips_set_processor_type (char *str) |
c906108c | 3587 | { |
1012bd0e | 3588 | int i; |
c906108c SS |
3589 | |
3590 | if (str == NULL) | |
3591 | return 0; | |
3592 | ||
3593 | for (i = 0; mips_processor_type_table[i].name != NULL; ++i) | |
3594 | { | |
3595 | if (strcasecmp (str, mips_processor_type_table[i].name) == 0) | |
3596 | { | |
3597 | mips_processor_type = str; | |
cce74817 | 3598 | mips_processor_reg_names = mips_processor_type_table[i].regnames; |
c906108c | 3599 | return 1; |
c906108c SS |
3600 | /* FIXME tweak fpu flag too */ |
3601 | } | |
3602 | } | |
3603 | ||
3604 | return 0; | |
3605 | } | |
3606 | ||
3607 | /* Attempt to identify the particular processor model by reading the | |
3608 | processor id. */ | |
3609 | ||
3610 | char * | |
acdb74a0 | 3611 | mips_read_processor_type (void) |
c906108c SS |
3612 | { |
3613 | CORE_ADDR prid; | |
3614 | ||
3615 | prid = read_register (PRID_REGNUM); | |
3616 | ||
3617 | if ((prid & ~0xf) == 0x700) | |
c5aa993b | 3618 | return savestring ("r3041", strlen ("r3041")); |
c906108c SS |
3619 | |
3620 | return NULL; | |
3621 | } | |
3622 | ||
3623 | /* Just like reinit_frame_cache, but with the right arguments to be | |
3624 | callable as an sfunc. */ | |
3625 | ||
3626 | static void | |
acdb74a0 AC |
3627 | reinit_frame_cache_sfunc (char *args, int from_tty, |
3628 | struct cmd_list_element *c) | |
c906108c SS |
3629 | { |
3630 | reinit_frame_cache (); | |
3631 | } | |
3632 | ||
3633 | int | |
acdb74a0 | 3634 | gdb_print_insn_mips (bfd_vma memaddr, disassemble_info *info) |
c906108c SS |
3635 | { |
3636 | mips_extra_func_info_t proc_desc; | |
3637 | ||
3638 | /* Search for the function containing this address. Set the low bit | |
3639 | of the address when searching, in case we were given an even address | |
3640 | that is the start of a 16-bit function. If we didn't do this, | |
3641 | the search would fail because the symbol table says the function | |
3642 | starts at an odd address, i.e. 1 byte past the given address. */ | |
3643 | memaddr = ADDR_BITS_REMOVE (memaddr); | |
3644 | proc_desc = non_heuristic_proc_desc (MAKE_MIPS16_ADDR (memaddr), NULL); | |
3645 | ||
3646 | /* Make an attempt to determine if this is a 16-bit function. If | |
3647 | the procedure descriptor exists and the address therein is odd, | |
3648 | it's definitely a 16-bit function. Otherwise, we have to just | |
3649 | guess that if the address passed in is odd, it's 16-bits. */ | |
3650 | if (proc_desc) | |
361d1df0 | 3651 | info->mach = pc_is_mips16 (PROC_LOW_ADDR (proc_desc)) ? |
65c11066 | 3652 | bfd_mach_mips16 : TM_PRINT_INSN_MACH; |
c906108c | 3653 | else |
361d1df0 | 3654 | info->mach = pc_is_mips16 (memaddr) ? |
65c11066 | 3655 | bfd_mach_mips16 : TM_PRINT_INSN_MACH; |
c906108c SS |
3656 | |
3657 | /* Round down the instruction address to the appropriate boundary. */ | |
65c11066 | 3658 | memaddr &= (info->mach == bfd_mach_mips16 ? ~1 : ~3); |
c5aa993b | 3659 | |
c906108c | 3660 | /* Call the appropriate disassembler based on the target endian-ness. */ |
d7449b42 | 3661 | if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) |
c906108c SS |
3662 | return print_insn_big_mips (memaddr, info); |
3663 | else | |
3664 | return print_insn_little_mips (memaddr, info); | |
3665 | } | |
3666 | ||
3667 | /* Old-style breakpoint macros. | |
3668 | The IDT board uses an unusual breakpoint value, and sometimes gets | |
3669 | confused when it sees the usual MIPS breakpoint instruction. */ | |
3670 | ||
3671 | #define BIG_BREAKPOINT {0, 0x5, 0, 0xd} | |
3672 | #define LITTLE_BREAKPOINT {0xd, 0, 0x5, 0} | |
3673 | #define PMON_BIG_BREAKPOINT {0, 0, 0, 0xd} | |
3674 | #define PMON_LITTLE_BREAKPOINT {0xd, 0, 0, 0} | |
3675 | #define IDT_BIG_BREAKPOINT {0, 0, 0x0a, 0xd} | |
3676 | #define IDT_LITTLE_BREAKPOINT {0xd, 0x0a, 0, 0} | |
3677 | #define MIPS16_BIG_BREAKPOINT {0xe8, 0xa5} | |
3678 | #define MIPS16_LITTLE_BREAKPOINT {0xa5, 0xe8} | |
3679 | ||
3680 | /* This function implements the BREAKPOINT_FROM_PC macro. It uses the program | |
3681 | counter value to determine whether a 16- or 32-bit breakpoint should be | |
3682 | used. It returns a pointer to a string of bytes that encode a breakpoint | |
3683 | instruction, stores the length of the string to *lenptr, and adjusts pc | |
3684 | (if necessary) to point to the actual memory location where the | |
3685 | breakpoint should be inserted. */ | |
3686 | ||
f4f9705a | 3687 | const unsigned char * |
acdb74a0 | 3688 | mips_breakpoint_from_pc (CORE_ADDR * pcptr, int *lenptr) |
c906108c | 3689 | { |
d7449b42 | 3690 | if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) |
c906108c SS |
3691 | { |
3692 | if (pc_is_mips16 (*pcptr)) | |
3693 | { | |
1012bd0e EZ |
3694 | static unsigned char mips16_big_breakpoint[] = |
3695 | MIPS16_BIG_BREAKPOINT; | |
c906108c | 3696 | *pcptr = UNMAKE_MIPS16_ADDR (*pcptr); |
c5aa993b | 3697 | *lenptr = sizeof (mips16_big_breakpoint); |
c906108c SS |
3698 | return mips16_big_breakpoint; |
3699 | } | |
3700 | else | |
3701 | { | |
1012bd0e EZ |
3702 | static unsigned char big_breakpoint[] = BIG_BREAKPOINT; |
3703 | static unsigned char pmon_big_breakpoint[] = PMON_BIG_BREAKPOINT; | |
3704 | static unsigned char idt_big_breakpoint[] = IDT_BIG_BREAKPOINT; | |
c906108c | 3705 | |
c5aa993b | 3706 | *lenptr = sizeof (big_breakpoint); |
c906108c SS |
3707 | |
3708 | if (strcmp (target_shortname, "mips") == 0) | |
3709 | return idt_big_breakpoint; | |
3710 | else if (strcmp (target_shortname, "ddb") == 0 | |
3711 | || strcmp (target_shortname, "pmon") == 0 | |
3712 | || strcmp (target_shortname, "lsi") == 0) | |
3713 | return pmon_big_breakpoint; | |
3714 | else | |
3715 | return big_breakpoint; | |
3716 | } | |
3717 | } | |
3718 | else | |
3719 | { | |
3720 | if (pc_is_mips16 (*pcptr)) | |
3721 | { | |
1012bd0e EZ |
3722 | static unsigned char mips16_little_breakpoint[] = |
3723 | MIPS16_LITTLE_BREAKPOINT; | |
c906108c | 3724 | *pcptr = UNMAKE_MIPS16_ADDR (*pcptr); |
c5aa993b | 3725 | *lenptr = sizeof (mips16_little_breakpoint); |
c906108c SS |
3726 | return mips16_little_breakpoint; |
3727 | } | |
3728 | else | |
3729 | { | |
1012bd0e EZ |
3730 | static unsigned char little_breakpoint[] = LITTLE_BREAKPOINT; |
3731 | static unsigned char pmon_little_breakpoint[] = | |
3732 | PMON_LITTLE_BREAKPOINT; | |
3733 | static unsigned char idt_little_breakpoint[] = | |
3734 | IDT_LITTLE_BREAKPOINT; | |
c906108c | 3735 | |
c5aa993b | 3736 | *lenptr = sizeof (little_breakpoint); |
c906108c SS |
3737 | |
3738 | if (strcmp (target_shortname, "mips") == 0) | |
3739 | return idt_little_breakpoint; | |
3740 | else if (strcmp (target_shortname, "ddb") == 0 | |
3741 | || strcmp (target_shortname, "pmon") == 0 | |
3742 | || strcmp (target_shortname, "lsi") == 0) | |
3743 | return pmon_little_breakpoint; | |
3744 | else | |
3745 | return little_breakpoint; | |
3746 | } | |
3747 | } | |
3748 | } | |
3749 | ||
3750 | /* If PC is in a mips16 call or return stub, return the address of the target | |
3751 | PC, which is either the callee or the caller. There are several | |
3752 | cases which must be handled: | |
3753 | ||
3754 | * If the PC is in __mips16_ret_{d,s}f, this is a return stub and the | |
c5aa993b | 3755 | target PC is in $31 ($ra). |
c906108c | 3756 | * If the PC is in __mips16_call_stub_{1..10}, this is a call stub |
c5aa993b | 3757 | and the target PC is in $2. |
c906108c | 3758 | * If the PC at the start of __mips16_call_stub_{s,d}f_{0..10}, i.e. |
c5aa993b JM |
3759 | before the jal instruction, this is effectively a call stub |
3760 | and the the target PC is in $2. Otherwise this is effectively | |
3761 | a return stub and the target PC is in $18. | |
c906108c SS |
3762 | |
3763 | See the source code for the stubs in gcc/config/mips/mips16.S for | |
3764 | gory details. | |
3765 | ||
3766 | This function implements the SKIP_TRAMPOLINE_CODE macro. | |
c5aa993b | 3767 | */ |
c906108c SS |
3768 | |
3769 | CORE_ADDR | |
acdb74a0 | 3770 | mips_skip_stub (CORE_ADDR pc) |
c906108c SS |
3771 | { |
3772 | char *name; | |
3773 | CORE_ADDR start_addr; | |
3774 | ||
3775 | /* Find the starting address and name of the function containing the PC. */ | |
3776 | if (find_pc_partial_function (pc, &name, &start_addr, NULL) == 0) | |
3777 | return 0; | |
3778 | ||
3779 | /* If the PC is in __mips16_ret_{d,s}f, this is a return stub and the | |
3780 | target PC is in $31 ($ra). */ | |
3781 | if (strcmp (name, "__mips16_ret_sf") == 0 | |
3782 | || strcmp (name, "__mips16_ret_df") == 0) | |
6c997a34 | 3783 | return read_signed_register (RA_REGNUM); |
c906108c SS |
3784 | |
3785 | if (strncmp (name, "__mips16_call_stub_", 19) == 0) | |
3786 | { | |
3787 | /* If the PC is in __mips16_call_stub_{1..10}, this is a call stub | |
3788 | and the target PC is in $2. */ | |
3789 | if (name[19] >= '0' && name[19] <= '9') | |
6c997a34 | 3790 | return read_signed_register (2); |
c906108c SS |
3791 | |
3792 | /* If the PC at the start of __mips16_call_stub_{s,d}f_{0..10}, i.e. | |
c5aa993b JM |
3793 | before the jal instruction, this is effectively a call stub |
3794 | and the the target PC is in $2. Otherwise this is effectively | |
3795 | a return stub and the target PC is in $18. */ | |
c906108c SS |
3796 | else if (name[19] == 's' || name[19] == 'd') |
3797 | { | |
3798 | if (pc == start_addr) | |
3799 | { | |
3800 | /* Check if the target of the stub is a compiler-generated | |
c5aa993b JM |
3801 | stub. Such a stub for a function bar might have a name |
3802 | like __fn_stub_bar, and might look like this: | |
3803 | mfc1 $4,$f13 | |
3804 | mfc1 $5,$f12 | |
3805 | mfc1 $6,$f15 | |
3806 | mfc1 $7,$f14 | |
3807 | la $1,bar (becomes a lui/addiu pair) | |
3808 | jr $1 | |
3809 | So scan down to the lui/addi and extract the target | |
3810 | address from those two instructions. */ | |
c906108c | 3811 | |
6c997a34 | 3812 | CORE_ADDR target_pc = read_signed_register (2); |
c906108c SS |
3813 | t_inst inst; |
3814 | int i; | |
3815 | ||
3816 | /* See if the name of the target function is __fn_stub_*. */ | |
3817 | if (find_pc_partial_function (target_pc, &name, NULL, NULL) == 0) | |
3818 | return target_pc; | |
3819 | if (strncmp (name, "__fn_stub_", 10) != 0 | |
3820 | && strcmp (name, "etext") != 0 | |
3821 | && strcmp (name, "_etext") != 0) | |
3822 | return target_pc; | |
3823 | ||
3824 | /* Scan through this _fn_stub_ code for the lui/addiu pair. | |
c5aa993b JM |
3825 | The limit on the search is arbitrarily set to 20 |
3826 | instructions. FIXME. */ | |
c906108c SS |
3827 | for (i = 0, pc = 0; i < 20; i++, target_pc += MIPS_INSTLEN) |
3828 | { | |
c5aa993b JM |
3829 | inst = mips_fetch_instruction (target_pc); |
3830 | if ((inst & 0xffff0000) == 0x3c010000) /* lui $at */ | |
3831 | pc = (inst << 16) & 0xffff0000; /* high word */ | |
3832 | else if ((inst & 0xffff0000) == 0x24210000) /* addiu $at */ | |
3833 | return pc | (inst & 0xffff); /* low word */ | |
c906108c SS |
3834 | } |
3835 | ||
3836 | /* Couldn't find the lui/addui pair, so return stub address. */ | |
3837 | return target_pc; | |
3838 | } | |
3839 | else | |
3840 | /* This is the 'return' part of a call stub. The return | |
3841 | address is in $r18. */ | |
6c997a34 | 3842 | return read_signed_register (18); |
c906108c SS |
3843 | } |
3844 | } | |
c5aa993b | 3845 | return 0; /* not a stub */ |
c906108c SS |
3846 | } |
3847 | ||
3848 | ||
3849 | /* Return non-zero if the PC is inside a call thunk (aka stub or trampoline). | |
3850 | This implements the IN_SOLIB_CALL_TRAMPOLINE macro. */ | |
3851 | ||
3852 | int | |
acdb74a0 | 3853 | mips_in_call_stub (CORE_ADDR pc, char *name) |
c906108c SS |
3854 | { |
3855 | CORE_ADDR start_addr; | |
3856 | ||
3857 | /* Find the starting address of the function containing the PC. If the | |
3858 | caller didn't give us a name, look it up at the same time. */ | |
3859 | if (find_pc_partial_function (pc, name ? NULL : &name, &start_addr, NULL) == 0) | |
3860 | return 0; | |
3861 | ||
3862 | if (strncmp (name, "__mips16_call_stub_", 19) == 0) | |
3863 | { | |
3864 | /* If the PC is in __mips16_call_stub_{1..10}, this is a call stub. */ | |
3865 | if (name[19] >= '0' && name[19] <= '9') | |
3866 | return 1; | |
3867 | /* If the PC at the start of __mips16_call_stub_{s,d}f_{0..10}, i.e. | |
c5aa993b | 3868 | before the jal instruction, this is effectively a call stub. */ |
c906108c SS |
3869 | else if (name[19] == 's' || name[19] == 'd') |
3870 | return pc == start_addr; | |
3871 | } | |
3872 | ||
c5aa993b | 3873 | return 0; /* not a stub */ |
c906108c SS |
3874 | } |
3875 | ||
3876 | ||
3877 | /* Return non-zero if the PC is inside a return thunk (aka stub or trampoline). | |
3878 | This implements the IN_SOLIB_RETURN_TRAMPOLINE macro. */ | |
3879 | ||
3880 | int | |
acdb74a0 | 3881 | mips_in_return_stub (CORE_ADDR pc, char *name) |
c906108c SS |
3882 | { |
3883 | CORE_ADDR start_addr; | |
3884 | ||
3885 | /* Find the starting address of the function containing the PC. */ | |
3886 | if (find_pc_partial_function (pc, NULL, &start_addr, NULL) == 0) | |
3887 | return 0; | |
3888 | ||
3889 | /* If the PC is in __mips16_ret_{d,s}f, this is a return stub. */ | |
3890 | if (strcmp (name, "__mips16_ret_sf") == 0 | |
3891 | || strcmp (name, "__mips16_ret_df") == 0) | |
3892 | return 1; | |
3893 | ||
3894 | /* If the PC is in __mips16_call_stub_{s,d}f_{0..10} but not at the start, | |
c5aa993b | 3895 | i.e. after the jal instruction, this is effectively a return stub. */ |
c906108c SS |
3896 | if (strncmp (name, "__mips16_call_stub_", 19) == 0 |
3897 | && (name[19] == 's' || name[19] == 'd') | |
3898 | && pc != start_addr) | |
3899 | return 1; | |
3900 | ||
c5aa993b | 3901 | return 0; /* not a stub */ |
c906108c SS |
3902 | } |
3903 | ||
3904 | ||
3905 | /* Return non-zero if the PC is in a library helper function that should | |
3906 | be ignored. This implements the IGNORE_HELPER_CALL macro. */ | |
3907 | ||
3908 | int | |
acdb74a0 | 3909 | mips_ignore_helper (CORE_ADDR pc) |
c906108c SS |
3910 | { |
3911 | char *name; | |
3912 | ||
3913 | /* Find the starting address and name of the function containing the PC. */ | |
3914 | if (find_pc_partial_function (pc, &name, NULL, NULL) == 0) | |
3915 | return 0; | |
3916 | ||
3917 | /* If the PC is in __mips16_ret_{d,s}f, this is a library helper function | |
3918 | that we want to ignore. */ | |
3919 | return (strcmp (name, "__mips16_ret_sf") == 0 | |
3920 | || strcmp (name, "__mips16_ret_df") == 0); | |
3921 | } | |
3922 | ||
3923 | ||
3924 | /* Return a location where we can set a breakpoint that will be hit | |
3925 | when an inferior function call returns. This is normally the | |
3926 | program's entry point. Executables that don't have an entry | |
3927 | point (e.g. programs in ROM) should define a symbol __CALL_DUMMY_ADDRESS | |
3928 | whose address is the location where the breakpoint should be placed. */ | |
3929 | ||
3930 | CORE_ADDR | |
acdb74a0 | 3931 | mips_call_dummy_address (void) |
c906108c SS |
3932 | { |
3933 | struct minimal_symbol *sym; | |
3934 | ||
3935 | sym = lookup_minimal_symbol ("__CALL_DUMMY_ADDRESS", NULL, NULL); | |
3936 | if (sym) | |
3937 | return SYMBOL_VALUE_ADDRESS (sym); | |
3938 | else | |
3939 | return entry_point_address (); | |
3940 | } | |
3941 | ||
3942 | ||
9dcb560c | 3943 | /* If the current gcc for this target does not produce correct debugging |
b9a8e3bf JB |
3944 | information for float parameters, both prototyped and unprototyped, then |
3945 | define this macro. This forces gdb to always assume that floats are | |
3946 | passed as doubles and then converted in the callee. | |
3947 | ||
3948 | For the mips chip, it appears that the debug info marks the parameters as | |
3949 | floats regardless of whether the function is prototyped, but the actual | |
3950 | values are passed as doubles for the non-prototyped case and floats for | |
3951 | the prototyped case. Thus we choose to make the non-prototyped case work | |
3952 | for C and break the prototyped case, since the non-prototyped case is | |
3953 | probably much more common. (FIXME). */ | |
3954 | ||
3955 | static int | |
3956 | mips_coerce_float_to_double (struct type *formal, struct type *actual) | |
3957 | { | |
3958 | return current_language->la_language == language_c; | |
3959 | } | |
3960 | ||
47a8d4ba AC |
3961 | /* When debugging a 64 MIPS target running a 32 bit ABI, the size of |
3962 | the register stored on the stack (32) is different to its real raw | |
3963 | size (64). The below ensures that registers are fetched from the | |
3964 | stack using their ABI size and then stored into the RAW_BUFFER | |
3965 | using their raw size. | |
3966 | ||
3967 | The alternative to adding this function would be to add an ABI | |
3968 | macro - REGISTER_STACK_SIZE(). */ | |
3969 | ||
3970 | static void | |
acdb74a0 AC |
3971 | mips_get_saved_register (char *raw_buffer, |
3972 | int *optimized, | |
3973 | CORE_ADDR *addrp, | |
3974 | struct frame_info *frame, | |
3975 | int regnum, | |
3976 | enum lval_type *lval) | |
47a8d4ba AC |
3977 | { |
3978 | CORE_ADDR addr; | |
3979 | ||
3980 | if (!target_has_registers) | |
3981 | error ("No registers."); | |
3982 | ||
3983 | /* Normal systems don't optimize out things with register numbers. */ | |
3984 | if (optimized != NULL) | |
3985 | *optimized = 0; | |
3986 | addr = find_saved_register (frame, regnum); | |
3987 | if (addr != 0) | |
3988 | { | |
3989 | if (lval != NULL) | |
3990 | *lval = lval_memory; | |
3991 | if (regnum == SP_REGNUM) | |
3992 | { | |
3993 | if (raw_buffer != NULL) | |
3994 | { | |
3995 | /* Put it back in target format. */ | |
3996 | store_address (raw_buffer, REGISTER_RAW_SIZE (regnum), | |
3997 | (LONGEST) addr); | |
3998 | } | |
3999 | if (addrp != NULL) | |
4000 | *addrp = 0; | |
4001 | return; | |
4002 | } | |
4003 | if (raw_buffer != NULL) | |
4004 | { | |
4005 | LONGEST val; | |
4006 | if (regnum < 32) | |
4007 | /* Only MIPS_SAVED_REGSIZE bytes of GP registers are | |
4008 | saved. */ | |
4009 | val = read_memory_integer (addr, MIPS_SAVED_REGSIZE); | |
4010 | else | |
4011 | val = read_memory_integer (addr, REGISTER_RAW_SIZE (regnum)); | |
4012 | store_address (raw_buffer, REGISTER_RAW_SIZE (regnum), val); | |
4013 | } | |
4014 | } | |
4015 | else | |
4016 | { | |
4017 | if (lval != NULL) | |
4018 | *lval = lval_register; | |
4019 | addr = REGISTER_BYTE (regnum); | |
4020 | if (raw_buffer != NULL) | |
4021 | read_register_gen (regnum, raw_buffer); | |
4022 | } | |
4023 | if (addrp != NULL) | |
4024 | *addrp = addr; | |
4025 | } | |
2acceee2 | 4026 | |
f7b9e9fc AC |
4027 | /* Immediately after a function call, return the saved pc. |
4028 | Can't always go through the frames for this because on some machines | |
4029 | the new frame is not set up until the new function executes | |
4030 | some instructions. */ | |
4031 | ||
4032 | static CORE_ADDR | |
4033 | mips_saved_pc_after_call (struct frame_info *frame) | |
4034 | { | |
6c997a34 | 4035 | return read_signed_register (RA_REGNUM); |
f7b9e9fc AC |
4036 | } |
4037 | ||
4038 | ||
88c72b7d AC |
4039 | /* Convert a dbx stab register number (from `r' declaration) to a gdb |
4040 | REGNUM */ | |
4041 | ||
4042 | static int | |
4043 | mips_stab_reg_to_regnum (int num) | |
4044 | { | |
4045 | if (num < 32) | |
4046 | return num; | |
361d1df0 | 4047 | else |
88c72b7d AC |
4048 | return num + FP0_REGNUM - 38; |
4049 | } | |
4050 | ||
4051 | /* Convert a ecoff register number to a gdb REGNUM */ | |
4052 | ||
4053 | static int | |
4054 | mips_ecoff_reg_to_regnum (int num) | |
4055 | { | |
4056 | if (num < 32) | |
4057 | return num; | |
4058 | else | |
4059 | return num + FP0_REGNUM - 32; | |
4060 | } | |
4061 | ||
fc0c74b1 AC |
4062 | /* Convert an integer into an address. By first converting the value |
4063 | into a pointer and then extracting it signed, the address is | |
4064 | guarenteed to be correctly sign extended. */ | |
4065 | ||
4066 | static CORE_ADDR | |
4067 | mips_integer_to_address (struct type *type, void *buf) | |
4068 | { | |
4069 | char *tmp = alloca (TYPE_LENGTH (builtin_type_void_data_ptr)); | |
4070 | LONGEST val = unpack_long (type, buf); | |
4071 | store_signed_integer (tmp, TYPE_LENGTH (builtin_type_void_data_ptr), val); | |
4072 | return extract_signed_integer (tmp, | |
4073 | TYPE_LENGTH (builtin_type_void_data_ptr)); | |
4074 | } | |
4075 | ||
caaa3122 DJ |
4076 | static void |
4077 | mips_find_abi_section (bfd *abfd, asection *sect, void *obj) | |
4078 | { | |
4079 | enum mips_abi *abip = (enum mips_abi *) obj; | |
4080 | const char *name = bfd_get_section_name (abfd, sect); | |
4081 | ||
4082 | if (*abip != MIPS_ABI_UNKNOWN) | |
4083 | return; | |
4084 | ||
4085 | if (strncmp (name, ".mdebug.", 8) != 0) | |
4086 | return; | |
4087 | ||
4088 | if (strcmp (name, ".mdebug.abi32") == 0) | |
4089 | *abip = MIPS_ABI_O32; | |
4090 | else if (strcmp (name, ".mdebug.abiN32") == 0) | |
4091 | *abip = MIPS_ABI_N32; | |
4092 | else if (strcmp (name, ".mdebug.abiO64") == 0) | |
4093 | *abip = MIPS_ABI_O64; | |
4094 | else if (strcmp (name, ".mdebug.eabi32") == 0) | |
4095 | *abip = MIPS_ABI_EABI32; | |
4096 | else if (strcmp (name, ".mdebug.eabi64") == 0) | |
4097 | *abip = MIPS_ABI_EABI64; | |
4098 | else | |
4099 | warning ("unsupported ABI %s.", name + 8); | |
4100 | } | |
4101 | ||
c2d11a7d | 4102 | static struct gdbarch * |
acdb74a0 AC |
4103 | mips_gdbarch_init (struct gdbarch_info info, |
4104 | struct gdbarch_list *arches) | |
c2d11a7d JM |
4105 | { |
4106 | static LONGEST mips_call_dummy_words[] = | |
4107 | {0}; | |
4108 | struct gdbarch *gdbarch; | |
4109 | struct gdbarch_tdep *tdep; | |
4110 | int elf_flags; | |
0dadbba0 | 4111 | enum mips_abi mips_abi; |
70f80edf | 4112 | enum gdb_osabi osabi = GDB_OSABI_UNKNOWN; |
c2d11a7d | 4113 | |
1d06468c EZ |
4114 | /* Reset the disassembly info, in case it was set to something |
4115 | non-default. */ | |
4116 | tm_print_insn_info.flavour = bfd_target_unknown_flavour; | |
4117 | tm_print_insn_info.arch = bfd_arch_unknown; | |
4118 | tm_print_insn_info.mach = 0; | |
4119 | ||
70f80edf JT |
4120 | elf_flags = 0; |
4121 | ||
4122 | if (info.abfd) | |
4123 | { | |
4124 | /* First of all, extract the elf_flags, if available. */ | |
4125 | if (bfd_get_flavour (info.abfd) == bfd_target_elf_flavour) | |
4126 | elf_flags = elf_elfheader (info.abfd)->e_flags; | |
4127 | ||
4128 | /* Try to determine the OS ABI of the object we are loading. If | |
4129 | we end up with `unknown', just leave it that way. */ | |
4130 | osabi = gdbarch_lookup_osabi (info.abfd); | |
4131 | } | |
c2d11a7d | 4132 | |
0dadbba0 AC |
4133 | /* Check ELF_FLAGS to see if it specifies the ABI being used. */ |
4134 | switch ((elf_flags & EF_MIPS_ABI)) | |
4135 | { | |
4136 | case E_MIPS_ABI_O32: | |
4137 | mips_abi = MIPS_ABI_O32; | |
4138 | break; | |
4139 | case E_MIPS_ABI_O64: | |
4140 | mips_abi = MIPS_ABI_O64; | |
4141 | break; | |
4142 | case E_MIPS_ABI_EABI32: | |
4143 | mips_abi = MIPS_ABI_EABI32; | |
4144 | break; | |
4145 | case E_MIPS_ABI_EABI64: | |
4a7f7ba8 | 4146 | mips_abi = MIPS_ABI_EABI64; |
0dadbba0 AC |
4147 | break; |
4148 | default: | |
acdb74a0 AC |
4149 | if ((elf_flags & EF_MIPS_ABI2)) |
4150 | mips_abi = MIPS_ABI_N32; | |
4151 | else | |
4152 | mips_abi = MIPS_ABI_UNKNOWN; | |
0dadbba0 AC |
4153 | break; |
4154 | } | |
acdb74a0 | 4155 | |
caaa3122 DJ |
4156 | /* GCC creates a pseudo-section whose name describes the ABI. */ |
4157 | if (mips_abi == MIPS_ABI_UNKNOWN && info.abfd != NULL) | |
4158 | bfd_map_over_sections (info.abfd, mips_find_abi_section, &mips_abi); | |
4159 | ||
bf64bfd6 AC |
4160 | /* Try the architecture for any hint of the corect ABI */ |
4161 | if (mips_abi == MIPS_ABI_UNKNOWN | |
4162 | && info.bfd_arch_info != NULL | |
4163 | && info.bfd_arch_info->arch == bfd_arch_mips) | |
4164 | { | |
4165 | switch (info.bfd_arch_info->mach) | |
4166 | { | |
4167 | case bfd_mach_mips3900: | |
4168 | mips_abi = MIPS_ABI_EABI32; | |
4169 | break; | |
4170 | case bfd_mach_mips4100: | |
4171 | case bfd_mach_mips5000: | |
4172 | mips_abi = MIPS_ABI_EABI64; | |
4173 | break; | |
1d06468c EZ |
4174 | case bfd_mach_mips8000: |
4175 | case bfd_mach_mips10000: | |
4176 | mips_abi = MIPS_ABI_N32; | |
4177 | break; | |
bf64bfd6 AC |
4178 | } |
4179 | } | |
0dadbba0 AC |
4180 | #ifdef MIPS_DEFAULT_ABI |
4181 | if (mips_abi == MIPS_ABI_UNKNOWN) | |
4182 | mips_abi = MIPS_DEFAULT_ABI; | |
4183 | #endif | |
4b9b3959 AC |
4184 | |
4185 | if (gdbarch_debug) | |
4186 | { | |
4187 | fprintf_unfiltered (gdb_stdlog, | |
9ace0497 | 4188 | "mips_gdbarch_init: elf_flags = 0x%08x\n", |
4b9b3959 | 4189 | elf_flags); |
4b9b3959 AC |
4190 | fprintf_unfiltered (gdb_stdlog, |
4191 | "mips_gdbarch_init: mips_abi = %d\n", | |
4192 | mips_abi); | |
4193 | } | |
0dadbba0 | 4194 | |
c2d11a7d JM |
4195 | /* try to find a pre-existing architecture */ |
4196 | for (arches = gdbarch_list_lookup_by_info (arches, &info); | |
4197 | arches != NULL; | |
4198 | arches = gdbarch_list_lookup_by_info (arches->next, &info)) | |
4199 | { | |
4200 | /* MIPS needs to be pedantic about which ABI the object is | |
4201 | using. */ | |
9103eae0 | 4202 | if (gdbarch_tdep (arches->gdbarch)->elf_flags != elf_flags) |
c2d11a7d | 4203 | continue; |
9103eae0 | 4204 | if (gdbarch_tdep (arches->gdbarch)->mips_abi != mips_abi) |
0dadbba0 | 4205 | continue; |
70f80edf JT |
4206 | if (gdbarch_tdep (arches->gdbarch)->osabi == osabi) |
4207 | return arches->gdbarch; | |
c2d11a7d JM |
4208 | } |
4209 | ||
4210 | /* Need a new architecture. Fill in a target specific vector. */ | |
4211 | tdep = (struct gdbarch_tdep *) xmalloc (sizeof (struct gdbarch_tdep)); | |
4212 | gdbarch = gdbarch_alloc (&info, tdep); | |
4213 | tdep->elf_flags = elf_flags; | |
70f80edf | 4214 | tdep->osabi = osabi; |
c2d11a7d | 4215 | |
46cd78fb | 4216 | /* Initially set everything according to the default ABI/ISA. */ |
c2d11a7d JM |
4217 | set_gdbarch_short_bit (gdbarch, 16); |
4218 | set_gdbarch_int_bit (gdbarch, 32); | |
4219 | set_gdbarch_float_bit (gdbarch, 32); | |
4220 | set_gdbarch_double_bit (gdbarch, 64); | |
4221 | set_gdbarch_long_double_bit (gdbarch, 64); | |
46cd78fb | 4222 | set_gdbarch_register_raw_size (gdbarch, mips_register_raw_size); |
0dadbba0 | 4223 | tdep->mips_abi = mips_abi; |
1d06468c | 4224 | |
0dadbba0 | 4225 | switch (mips_abi) |
c2d11a7d | 4226 | { |
0dadbba0 | 4227 | case MIPS_ABI_O32: |
acdb74a0 | 4228 | tdep->mips_abi_string = "o32"; |
a5ea2558 | 4229 | tdep->mips_default_saved_regsize = 4; |
0dadbba0 | 4230 | tdep->mips_default_stack_argsize = 4; |
c2d11a7d | 4231 | tdep->mips_fp_register_double = 0; |
acdb74a0 AC |
4232 | tdep->mips_last_arg_regnum = A0_REGNUM + 4 - 1; |
4233 | tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 4 - 1; | |
0dadbba0 | 4234 | tdep->mips_regs_have_home_p = 1; |
5213ab06 | 4235 | tdep->gdb_target_is_mips64 = 0; |
4014092b | 4236 | tdep->default_mask_address_p = 0; |
c2d11a7d JM |
4237 | set_gdbarch_long_bit (gdbarch, 32); |
4238 | set_gdbarch_ptr_bit (gdbarch, 32); | |
4239 | set_gdbarch_long_long_bit (gdbarch, 64); | |
4240 | break; | |
0dadbba0 | 4241 | case MIPS_ABI_O64: |
acdb74a0 | 4242 | tdep->mips_abi_string = "o64"; |
a5ea2558 | 4243 | tdep->mips_default_saved_regsize = 8; |
0dadbba0 | 4244 | tdep->mips_default_stack_argsize = 8; |
c2d11a7d | 4245 | tdep->mips_fp_register_double = 1; |
acdb74a0 AC |
4246 | tdep->mips_last_arg_regnum = A0_REGNUM + 4 - 1; |
4247 | tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 4 - 1; | |
0dadbba0 | 4248 | tdep->mips_regs_have_home_p = 1; |
5213ab06 | 4249 | tdep->gdb_target_is_mips64 = 1; |
361d1df0 | 4250 | tdep->default_mask_address_p = 0; |
c2d11a7d JM |
4251 | set_gdbarch_long_bit (gdbarch, 32); |
4252 | set_gdbarch_ptr_bit (gdbarch, 32); | |
4253 | set_gdbarch_long_long_bit (gdbarch, 64); | |
4254 | break; | |
0dadbba0 | 4255 | case MIPS_ABI_EABI32: |
acdb74a0 | 4256 | tdep->mips_abi_string = "eabi32"; |
a5ea2558 | 4257 | tdep->mips_default_saved_regsize = 4; |
0dadbba0 | 4258 | tdep->mips_default_stack_argsize = 4; |
c2d11a7d | 4259 | tdep->mips_fp_register_double = 0; |
acdb74a0 AC |
4260 | tdep->mips_last_arg_regnum = A0_REGNUM + 8 - 1; |
4261 | tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 8 - 1; | |
0dadbba0 | 4262 | tdep->mips_regs_have_home_p = 0; |
5213ab06 | 4263 | tdep->gdb_target_is_mips64 = 0; |
4014092b | 4264 | tdep->default_mask_address_p = 0; |
c2d11a7d JM |
4265 | set_gdbarch_long_bit (gdbarch, 32); |
4266 | set_gdbarch_ptr_bit (gdbarch, 32); | |
4267 | set_gdbarch_long_long_bit (gdbarch, 64); | |
4268 | break; | |
0dadbba0 | 4269 | case MIPS_ABI_EABI64: |
3259a172 | 4270 | tdep->mips_abi_string = "eabi64"; |
a5ea2558 | 4271 | tdep->mips_default_saved_regsize = 8; |
0dadbba0 | 4272 | tdep->mips_default_stack_argsize = 8; |
c2d11a7d | 4273 | tdep->mips_fp_register_double = 1; |
acdb74a0 AC |
4274 | tdep->mips_last_arg_regnum = A0_REGNUM + 8 - 1; |
4275 | tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 8 - 1; | |
0dadbba0 | 4276 | tdep->mips_regs_have_home_p = 0; |
5213ab06 | 4277 | tdep->gdb_target_is_mips64 = 1; |
4014092b | 4278 | tdep->default_mask_address_p = 0; |
c2d11a7d JM |
4279 | set_gdbarch_long_bit (gdbarch, 64); |
4280 | set_gdbarch_ptr_bit (gdbarch, 64); | |
4281 | set_gdbarch_long_long_bit (gdbarch, 64); | |
4282 | break; | |
0dadbba0 | 4283 | case MIPS_ABI_N32: |
acdb74a0 | 4284 | tdep->mips_abi_string = "n32"; |
0dadbba0 AC |
4285 | tdep->mips_default_saved_regsize = 4; |
4286 | tdep->mips_default_stack_argsize = 8; | |
4287 | tdep->mips_fp_register_double = 1; | |
acdb74a0 AC |
4288 | tdep->mips_last_arg_regnum = A0_REGNUM + 8 - 1; |
4289 | tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 8 - 1; | |
0dadbba0 | 4290 | tdep->mips_regs_have_home_p = 0; |
5213ab06 | 4291 | tdep->gdb_target_is_mips64 = 0; |
4014092b | 4292 | tdep->default_mask_address_p = 0; |
0dadbba0 AC |
4293 | set_gdbarch_long_bit (gdbarch, 32); |
4294 | set_gdbarch_ptr_bit (gdbarch, 32); | |
4295 | set_gdbarch_long_long_bit (gdbarch, 64); | |
1d06468c EZ |
4296 | |
4297 | /* Set up the disassembler info, so that we get the right | |
4298 | register names from libopcodes. */ | |
4299 | tm_print_insn_info.flavour = bfd_target_elf_flavour; | |
4300 | tm_print_insn_info.arch = bfd_arch_mips; | |
4301 | if (info.bfd_arch_info != NULL | |
4302 | && info.bfd_arch_info->arch == bfd_arch_mips | |
4303 | && info.bfd_arch_info->mach) | |
4304 | tm_print_insn_info.mach = info.bfd_arch_info->mach; | |
4305 | else | |
4306 | tm_print_insn_info.mach = bfd_mach_mips8000; | |
0dadbba0 | 4307 | break; |
c2d11a7d | 4308 | default: |
acdb74a0 | 4309 | tdep->mips_abi_string = "default"; |
a5ea2558 | 4310 | tdep->mips_default_saved_regsize = MIPS_REGSIZE; |
0dadbba0 | 4311 | tdep->mips_default_stack_argsize = MIPS_REGSIZE; |
c2d11a7d | 4312 | tdep->mips_fp_register_double = (REGISTER_VIRTUAL_SIZE (FP0_REGNUM) == 8); |
acdb74a0 AC |
4313 | tdep->mips_last_arg_regnum = A0_REGNUM + 8 - 1; |
4314 | tdep->mips_last_fp_arg_regnum = FPA0_REGNUM + 8 - 1; | |
0dadbba0 | 4315 | tdep->mips_regs_have_home_p = 1; |
5213ab06 | 4316 | tdep->gdb_target_is_mips64 = 0; |
4014092b | 4317 | tdep->default_mask_address_p = 0; |
c2d11a7d JM |
4318 | set_gdbarch_long_bit (gdbarch, 32); |
4319 | set_gdbarch_ptr_bit (gdbarch, 32); | |
4320 | set_gdbarch_long_long_bit (gdbarch, 64); | |
4321 | break; | |
4322 | } | |
4323 | ||
a5ea2558 AC |
4324 | /* FIXME: jlarmour/2000-04-07: There *is* a flag EF_MIPS_32BIT_MODE |
4325 | that could indicate -gp32 BUT gas/config/tc-mips.c contains the | |
4326 | comment: | |
4327 | ||
4328 | ``We deliberately don't allow "-gp32" to set the MIPS_32BITMODE | |
4329 | flag in object files because to do so would make it impossible to | |
4330 | link with libraries compiled without "-gp32". This is | |
4331 | unnecessarily restrictive. | |
361d1df0 | 4332 | |
a5ea2558 AC |
4333 | We could solve this problem by adding "-gp32" multilibs to gcc, |
4334 | but to set this flag before gcc is built with such multilibs will | |
4335 | break too many systems.'' | |
4336 | ||
4337 | But even more unhelpfully, the default linker output target for | |
4338 | mips64-elf is elf32-bigmips, and has EF_MIPS_32BIT_MODE set, even | |
4339 | for 64-bit programs - you need to change the ABI to change this, | |
4340 | and not all gcc targets support that currently. Therefore using | |
4341 | this flag to detect 32-bit mode would do the wrong thing given | |
4342 | the current gcc - it would make GDB treat these 64-bit programs | |
4343 | as 32-bit programs by default. */ | |
4344 | ||
c2d11a7d JM |
4345 | /* enable/disable the MIPS FPU */ |
4346 | if (!mips_fpu_type_auto) | |
4347 | tdep->mips_fpu_type = mips_fpu_type; | |
4348 | else if (info.bfd_arch_info != NULL | |
4349 | && info.bfd_arch_info->arch == bfd_arch_mips) | |
4350 | switch (info.bfd_arch_info->mach) | |
4351 | { | |
b0069a17 | 4352 | case bfd_mach_mips3900: |
c2d11a7d | 4353 | case bfd_mach_mips4100: |
ed9a39eb | 4354 | case bfd_mach_mips4111: |
c2d11a7d JM |
4355 | tdep->mips_fpu_type = MIPS_FPU_NONE; |
4356 | break; | |
bf64bfd6 AC |
4357 | case bfd_mach_mips4650: |
4358 | tdep->mips_fpu_type = MIPS_FPU_SINGLE; | |
4359 | break; | |
c2d11a7d JM |
4360 | default: |
4361 | tdep->mips_fpu_type = MIPS_FPU_DOUBLE; | |
4362 | break; | |
4363 | } | |
4364 | else | |
4365 | tdep->mips_fpu_type = MIPS_FPU_DOUBLE; | |
4366 | ||
4367 | /* MIPS version of register names. NOTE: At present the MIPS | |
4368 | register name management is part way between the old - | |
4369 | #undef/#define REGISTER_NAMES and the new REGISTER_NAME(nr). | |
4370 | Further work on it is required. */ | |
4371 | set_gdbarch_register_name (gdbarch, mips_register_name); | |
6c997a34 | 4372 | set_gdbarch_read_pc (gdbarch, mips_read_pc); |
c2d11a7d JM |
4373 | set_gdbarch_write_pc (gdbarch, generic_target_write_pc); |
4374 | set_gdbarch_read_fp (gdbarch, generic_target_read_fp); | |
c2d11a7d JM |
4375 | set_gdbarch_read_sp (gdbarch, generic_target_read_sp); |
4376 | set_gdbarch_write_sp (gdbarch, generic_target_write_sp); | |
4377 | ||
875e1767 AC |
4378 | /* Add/remove bits from an address. The MIPS needs be careful to |
4379 | ensure that all 32 bit addresses are sign extended to 64 bits. */ | |
4380 | set_gdbarch_addr_bits_remove (gdbarch, mips_addr_bits_remove); | |
4381 | ||
10312cc4 AC |
4382 | /* There's a mess in stack frame creation. See comments in |
4383 | blockframe.c near reference to INIT_FRAME_PC_FIRST. */ | |
4384 | set_gdbarch_init_frame_pc_first (gdbarch, mips_init_frame_pc_first); | |
7824d2f2 | 4385 | set_gdbarch_init_frame_pc (gdbarch, init_frame_pc_noop); |
10312cc4 | 4386 | |
88c72b7d AC |
4387 | /* Map debug register numbers onto internal register numbers. */ |
4388 | set_gdbarch_stab_reg_to_regnum (gdbarch, mips_stab_reg_to_regnum); | |
4389 | set_gdbarch_ecoff_reg_to_regnum (gdbarch, mips_ecoff_reg_to_regnum); | |
4390 | ||
c2d11a7d JM |
4391 | /* Initialize a frame */ |
4392 | set_gdbarch_init_extra_frame_info (gdbarch, mips_init_extra_frame_info); | |
4393 | ||
4394 | /* MIPS version of CALL_DUMMY */ | |
4395 | ||
4396 | set_gdbarch_call_dummy_p (gdbarch, 1); | |
4397 | set_gdbarch_call_dummy_stack_adjust_p (gdbarch, 0); | |
4398 | set_gdbarch_use_generic_dummy_frames (gdbarch, 0); | |
4399 | set_gdbarch_call_dummy_location (gdbarch, AT_ENTRY_POINT); | |
4400 | set_gdbarch_call_dummy_address (gdbarch, mips_call_dummy_address); | |
4401 | set_gdbarch_call_dummy_start_offset (gdbarch, 0); | |
4402 | set_gdbarch_call_dummy_breakpoint_offset_p (gdbarch, 1); | |
4403 | set_gdbarch_call_dummy_breakpoint_offset (gdbarch, 0); | |
4404 | set_gdbarch_call_dummy_length (gdbarch, 0); | |
4405 | set_gdbarch_pc_in_call_dummy (gdbarch, pc_in_call_dummy_at_entry_point); | |
4406 | set_gdbarch_call_dummy_words (gdbarch, mips_call_dummy_words); | |
4407 | set_gdbarch_sizeof_call_dummy_words (gdbarch, sizeof (mips_call_dummy_words)); | |
4408 | set_gdbarch_push_return_address (gdbarch, mips_push_return_address); | |
4409 | set_gdbarch_push_arguments (gdbarch, mips_push_arguments); | |
4410 | set_gdbarch_register_convertible (gdbarch, generic_register_convertible_not); | |
b9a8e3bf | 4411 | set_gdbarch_coerce_float_to_double (gdbarch, mips_coerce_float_to_double); |
c2d11a7d | 4412 | |
c4093a6a | 4413 | set_gdbarch_frame_chain_valid (gdbarch, func_frame_chain_valid); |
47a8d4ba | 4414 | set_gdbarch_get_saved_register (gdbarch, mips_get_saved_register); |
c2d11a7d | 4415 | |
f7b9e9fc AC |
4416 | set_gdbarch_inner_than (gdbarch, core_addr_lessthan); |
4417 | set_gdbarch_breakpoint_from_pc (gdbarch, mips_breakpoint_from_pc); | |
4418 | set_gdbarch_decr_pc_after_break (gdbarch, 0); | |
f7b9e9fc AC |
4419 | |
4420 | set_gdbarch_skip_prologue (gdbarch, mips_skip_prologue); | |
4421 | set_gdbarch_saved_pc_after_call (gdbarch, mips_saved_pc_after_call); | |
4422 | ||
fc0c74b1 AC |
4423 | set_gdbarch_pointer_to_address (gdbarch, signed_pointer_to_address); |
4424 | set_gdbarch_address_to_pointer (gdbarch, address_to_signed_pointer); | |
4425 | set_gdbarch_integer_to_address (gdbarch, mips_integer_to_address); | |
70f80edf JT |
4426 | |
4427 | /* Hook in OS ABI-specific overrides, if they have been registered. */ | |
4428 | gdbarch_init_osabi (info, gdbarch, osabi); | |
4429 | ||
4b9b3959 AC |
4430 | return gdbarch; |
4431 | } | |
4432 | ||
4433 | static void | |
4434 | mips_dump_tdep (struct gdbarch *current_gdbarch, struct ui_file *file) | |
4435 | { | |
4436 | struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); | |
4437 | if (tdep != NULL) | |
c2d11a7d | 4438 | { |
acdb74a0 AC |
4439 | int ef_mips_arch; |
4440 | int ef_mips_32bitmode; | |
4441 | /* determine the ISA */ | |
4442 | switch (tdep->elf_flags & EF_MIPS_ARCH) | |
4443 | { | |
4444 | case E_MIPS_ARCH_1: | |
4445 | ef_mips_arch = 1; | |
4446 | break; | |
4447 | case E_MIPS_ARCH_2: | |
4448 | ef_mips_arch = 2; | |
4449 | break; | |
4450 | case E_MIPS_ARCH_3: | |
4451 | ef_mips_arch = 3; | |
4452 | break; | |
4453 | case E_MIPS_ARCH_4: | |
93d56215 | 4454 | ef_mips_arch = 4; |
acdb74a0 AC |
4455 | break; |
4456 | default: | |
93d56215 | 4457 | ef_mips_arch = 0; |
acdb74a0 AC |
4458 | break; |
4459 | } | |
4460 | /* determine the size of a pointer */ | |
4461 | ef_mips_32bitmode = (tdep->elf_flags & EF_MIPS_32BITMODE); | |
4b9b3959 AC |
4462 | fprintf_unfiltered (file, |
4463 | "mips_dump_tdep: tdep->elf_flags = 0x%x\n", | |
0dadbba0 | 4464 | tdep->elf_flags); |
4b9b3959 | 4465 | fprintf_unfiltered (file, |
acdb74a0 AC |
4466 | "mips_dump_tdep: ef_mips_32bitmode = %d\n", |
4467 | ef_mips_32bitmode); | |
4468 | fprintf_unfiltered (file, | |
4469 | "mips_dump_tdep: ef_mips_arch = %d\n", | |
4470 | ef_mips_arch); | |
4471 | fprintf_unfiltered (file, | |
4472 | "mips_dump_tdep: tdep->mips_abi = %d (%s)\n", | |
4473 | tdep->mips_abi, | |
4474 | tdep->mips_abi_string); | |
4014092b AC |
4475 | fprintf_unfiltered (file, |
4476 | "mips_dump_tdep: mips_mask_address_p() %d (default %d)\n", | |
4477 | mips_mask_address_p (), | |
4478 | tdep->default_mask_address_p); | |
c2d11a7d | 4479 | } |
4b9b3959 AC |
4480 | fprintf_unfiltered (file, |
4481 | "mips_dump_tdep: FP_REGISTER_DOUBLE = %d\n", | |
4482 | FP_REGISTER_DOUBLE); | |
4483 | fprintf_unfiltered (file, | |
4484 | "mips_dump_tdep: MIPS_DEFAULT_FPU_TYPE = %d (%s)\n", | |
4485 | MIPS_DEFAULT_FPU_TYPE, | |
4486 | (MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_NONE ? "none" | |
4487 | : MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_SINGLE ? "single" | |
4488 | : MIPS_DEFAULT_FPU_TYPE == MIPS_FPU_DOUBLE ? "double" | |
4489 | : "???")); | |
4490 | fprintf_unfiltered (file, | |
4491 | "mips_dump_tdep: MIPS_EABI = %d\n", | |
4492 | MIPS_EABI); | |
4493 | fprintf_unfiltered (file, | |
acdb74a0 AC |
4494 | "mips_dump_tdep: MIPS_LAST_FP_ARG_REGNUM = %d (%d regs)\n", |
4495 | MIPS_LAST_FP_ARG_REGNUM, | |
4496 | MIPS_LAST_FP_ARG_REGNUM - FPA0_REGNUM + 1); | |
4b9b3959 AC |
4497 | fprintf_unfiltered (file, |
4498 | "mips_dump_tdep: MIPS_FPU_TYPE = %d (%s)\n", | |
4499 | MIPS_FPU_TYPE, | |
4500 | (MIPS_FPU_TYPE == MIPS_FPU_NONE ? "none" | |
4501 | : MIPS_FPU_TYPE == MIPS_FPU_SINGLE ? "single" | |
4502 | : MIPS_FPU_TYPE == MIPS_FPU_DOUBLE ? "double" | |
4503 | : "???")); | |
4504 | fprintf_unfiltered (file, | |
4505 | "mips_dump_tdep: MIPS_DEFAULT_SAVED_REGSIZE = %d\n", | |
4506 | MIPS_DEFAULT_SAVED_REGSIZE); | |
4b9b3959 AC |
4507 | fprintf_unfiltered (file, |
4508 | "mips_dump_tdep: FP_REGISTER_DOUBLE = %d\n", | |
4509 | FP_REGISTER_DOUBLE); | |
4510 | fprintf_unfiltered (file, | |
4511 | "mips_dump_tdep: MIPS_REGS_HAVE_HOME_P = %d\n", | |
4512 | MIPS_REGS_HAVE_HOME_P); | |
4513 | fprintf_unfiltered (file, | |
4514 | "mips_dump_tdep: MIPS_DEFAULT_STACK_ARGSIZE = %d\n", | |
4515 | MIPS_DEFAULT_STACK_ARGSIZE); | |
4516 | fprintf_unfiltered (file, | |
4517 | "mips_dump_tdep: MIPS_STACK_ARGSIZE = %d\n", | |
4518 | MIPS_STACK_ARGSIZE); | |
4519 | fprintf_unfiltered (file, | |
4520 | "mips_dump_tdep: MIPS_REGSIZE = %d\n", | |
4521 | MIPS_REGSIZE); | |
2475bac3 AC |
4522 | fprintf_unfiltered (file, |
4523 | "mips_dump_tdep: A0_REGNUM = %d\n", | |
4524 | A0_REGNUM); | |
4525 | fprintf_unfiltered (file, | |
4526 | "mips_dump_tdep: ADDR_BITS_REMOVE # %s\n", | |
4527 | XSTRING (ADDR_BITS_REMOVE(ADDR))); | |
4528 | fprintf_unfiltered (file, | |
4529 | "mips_dump_tdep: ATTACH_DETACH # %s\n", | |
4530 | XSTRING (ATTACH_DETACH)); | |
4531 | fprintf_unfiltered (file, | |
4532 | "mips_dump_tdep: BADVADDR_REGNUM = %d\n", | |
4533 | BADVADDR_REGNUM); | |
4534 | fprintf_unfiltered (file, | |
4535 | "mips_dump_tdep: BIG_BREAKPOINT = delete?\n"); | |
4536 | fprintf_unfiltered (file, | |
4537 | "mips_dump_tdep: CAUSE_REGNUM = %d\n", | |
4538 | CAUSE_REGNUM); | |
4539 | fprintf_unfiltered (file, | |
4540 | "mips_dump_tdep: CPLUS_MARKER = %c\n", | |
4541 | CPLUS_MARKER); | |
4542 | fprintf_unfiltered (file, | |
4543 | "mips_dump_tdep: DEFAULT_MIPS_TYPE = %s\n", | |
4544 | DEFAULT_MIPS_TYPE); | |
4545 | fprintf_unfiltered (file, | |
4546 | "mips_dump_tdep: DO_REGISTERS_INFO # %s\n", | |
4547 | XSTRING (DO_REGISTERS_INFO)); | |
4548 | fprintf_unfiltered (file, | |
4549 | "mips_dump_tdep: DWARF_REG_TO_REGNUM # %s\n", | |
4550 | XSTRING (DWARF_REG_TO_REGNUM (REGNUM))); | |
4551 | fprintf_unfiltered (file, | |
4552 | "mips_dump_tdep: ECOFF_REG_TO_REGNUM # %s\n", | |
4553 | XSTRING (ECOFF_REG_TO_REGNUM (REGNUM))); | |
4554 | fprintf_unfiltered (file, | |
4555 | "mips_dump_tdep: ELF_MAKE_MSYMBOL_SPECIAL # %s\n", | |
4556 | XSTRING (ELF_MAKE_MSYMBOL_SPECIAL (SYM, MSYM))); | |
4557 | fprintf_unfiltered (file, | |
4558 | "mips_dump_tdep: FCRCS_REGNUM = %d\n", | |
4559 | FCRCS_REGNUM); | |
4560 | fprintf_unfiltered (file, | |
4561 | "mips_dump_tdep: FCRIR_REGNUM = %d\n", | |
4562 | FCRIR_REGNUM); | |
4563 | fprintf_unfiltered (file, | |
4564 | "mips_dump_tdep: FIRST_EMBED_REGNUM = %d\n", | |
4565 | FIRST_EMBED_REGNUM); | |
4566 | fprintf_unfiltered (file, | |
4567 | "mips_dump_tdep: FPA0_REGNUM = %d\n", | |
4568 | FPA0_REGNUM); | |
4569 | fprintf_unfiltered (file, | |
4570 | "mips_dump_tdep: GDB_TARGET_IS_MIPS64 = %d\n", | |
4571 | GDB_TARGET_IS_MIPS64); | |
4572 | fprintf_unfiltered (file, | |
4573 | "mips_dump_tdep: GDB_TARGET_MASK_DISAS_PC # %s\n", | |
4574 | XSTRING (GDB_TARGET_MASK_DISAS_PC (PC))); | |
4575 | fprintf_unfiltered (file, | |
4576 | "mips_dump_tdep: GDB_TARGET_UNMASK_DISAS_PC # %s\n", | |
4577 | XSTRING (GDB_TARGET_UNMASK_DISAS_PC (PC))); | |
4578 | fprintf_unfiltered (file, | |
4579 | "mips_dump_tdep: GEN_REG_SAVE_MASK = %d\n", | |
4580 | GEN_REG_SAVE_MASK); | |
4581 | fprintf_unfiltered (file, | |
4582 | "mips_dump_tdep: HAVE_NONSTEPPABLE_WATCHPOINT # %s\n", | |
4583 | XSTRING (HAVE_NONSTEPPABLE_WATCHPOINT)); | |
4584 | fprintf_unfiltered (file, | |
4585 | "mips_dump_tdep: HI_REGNUM = %d\n", | |
4586 | HI_REGNUM); | |
4587 | fprintf_unfiltered (file, | |
4588 | "mips_dump_tdep: IDT_BIG_BREAKPOINT = delete?\n"); | |
4589 | fprintf_unfiltered (file, | |
4590 | "mips_dump_tdep: IDT_LITTLE_BREAKPOINT = delete?\n"); | |
4591 | fprintf_unfiltered (file, | |
4592 | "mips_dump_tdep: IGNORE_HELPER_CALL # %s\n", | |
4593 | XSTRING (IGNORE_HELPER_CALL (PC))); | |
2475bac3 AC |
4594 | fprintf_unfiltered (file, |
4595 | "mips_dump_tdep: IN_SOLIB_CALL_TRAMPOLINE # %s\n", | |
4596 | XSTRING (IN_SOLIB_CALL_TRAMPOLINE (PC, NAME))); | |
4597 | fprintf_unfiltered (file, | |
4598 | "mips_dump_tdep: IN_SOLIB_RETURN_TRAMPOLINE # %s\n", | |
4599 | XSTRING (IN_SOLIB_RETURN_TRAMPOLINE (PC, NAME))); | |
4600 | fprintf_unfiltered (file, | |
4601 | "mips_dump_tdep: IS_MIPS16_ADDR = FIXME!\n"); | |
4602 | fprintf_unfiltered (file, | |
4603 | "mips_dump_tdep: LAST_EMBED_REGNUM = %d\n", | |
4604 | LAST_EMBED_REGNUM); | |
4605 | fprintf_unfiltered (file, | |
4606 | "mips_dump_tdep: LITTLE_BREAKPOINT = delete?\n"); | |
4607 | fprintf_unfiltered (file, | |
4608 | "mips_dump_tdep: LO_REGNUM = %d\n", | |
4609 | LO_REGNUM); | |
4610 | #ifdef MACHINE_CPROC_FP_OFFSET | |
4611 | fprintf_unfiltered (file, | |
4612 | "mips_dump_tdep: MACHINE_CPROC_FP_OFFSET = %d\n", | |
4613 | MACHINE_CPROC_FP_OFFSET); | |
4614 | #endif | |
4615 | #ifdef MACHINE_CPROC_PC_OFFSET | |
4616 | fprintf_unfiltered (file, | |
4617 | "mips_dump_tdep: MACHINE_CPROC_PC_OFFSET = %d\n", | |
4618 | MACHINE_CPROC_PC_OFFSET); | |
4619 | #endif | |
4620 | #ifdef MACHINE_CPROC_SP_OFFSET | |
4621 | fprintf_unfiltered (file, | |
4622 | "mips_dump_tdep: MACHINE_CPROC_SP_OFFSET = %d\n", | |
4623 | MACHINE_CPROC_SP_OFFSET); | |
4624 | #endif | |
4625 | fprintf_unfiltered (file, | |
4626 | "mips_dump_tdep: MAKE_MIPS16_ADDR = FIXME!\n"); | |
4627 | fprintf_unfiltered (file, | |
4628 | "mips_dump_tdep: MIPS16_BIG_BREAKPOINT = delete?\n"); | |
4629 | fprintf_unfiltered (file, | |
4630 | "mips_dump_tdep: MIPS16_INSTLEN = %d\n", | |
4631 | MIPS16_INSTLEN); | |
4632 | fprintf_unfiltered (file, | |
4633 | "mips_dump_tdep: MIPS16_LITTLE_BREAKPOINT = delete?\n"); | |
4634 | fprintf_unfiltered (file, | |
4635 | "mips_dump_tdep: MIPS_DEFAULT_ABI = FIXME!\n"); | |
4636 | fprintf_unfiltered (file, | |
4637 | "mips_dump_tdep: MIPS_EFI_SYMBOL_NAME = multi-arch!!\n"); | |
4638 | fprintf_unfiltered (file, | |
4639 | "mips_dump_tdep: MIPS_INSTLEN = %d\n", | |
4640 | MIPS_INSTLEN); | |
4641 | fprintf_unfiltered (file, | |
acdb74a0 AC |
4642 | "mips_dump_tdep: MIPS_LAST_ARG_REGNUM = %d (%d regs)\n", |
4643 | MIPS_LAST_ARG_REGNUM, | |
4644 | MIPS_LAST_ARG_REGNUM - A0_REGNUM + 1); | |
2475bac3 AC |
4645 | fprintf_unfiltered (file, |
4646 | "mips_dump_tdep: MIPS_NUMREGS = %d\n", | |
4647 | MIPS_NUMREGS); | |
4648 | fprintf_unfiltered (file, | |
4649 | "mips_dump_tdep: MIPS_REGISTER_NAMES = delete?\n"); | |
4650 | fprintf_unfiltered (file, | |
4651 | "mips_dump_tdep: MIPS_SAVED_REGSIZE = %d\n", | |
4652 | MIPS_SAVED_REGSIZE); | |
4653 | fprintf_unfiltered (file, | |
4654 | "mips_dump_tdep: MSYMBOL_IS_SPECIAL = function?\n"); | |
4655 | fprintf_unfiltered (file, | |
4656 | "mips_dump_tdep: MSYMBOL_SIZE # %s\n", | |
4657 | XSTRING (MSYMBOL_SIZE (MSYM))); | |
4658 | fprintf_unfiltered (file, | |
4659 | "mips_dump_tdep: OP_LDFPR = used?\n"); | |
4660 | fprintf_unfiltered (file, | |
4661 | "mips_dump_tdep: OP_LDGPR = used?\n"); | |
4662 | fprintf_unfiltered (file, | |
4663 | "mips_dump_tdep: PMON_BIG_BREAKPOINT = delete?\n"); | |
4664 | fprintf_unfiltered (file, | |
4665 | "mips_dump_tdep: PMON_LITTLE_BREAKPOINT = delete?\n"); | |
4666 | fprintf_unfiltered (file, | |
4667 | "mips_dump_tdep: PRID_REGNUM = %d\n", | |
4668 | PRID_REGNUM); | |
4669 | fprintf_unfiltered (file, | |
4670 | "mips_dump_tdep: PRINT_EXTRA_FRAME_INFO # %s\n", | |
4671 | XSTRING (PRINT_EXTRA_FRAME_INFO (FRAME))); | |
4672 | fprintf_unfiltered (file, | |
4673 | "mips_dump_tdep: PROC_DESC_IS_DUMMY = function?\n"); | |
4674 | fprintf_unfiltered (file, | |
4675 | "mips_dump_tdep: PROC_FRAME_ADJUST = function?\n"); | |
4676 | fprintf_unfiltered (file, | |
4677 | "mips_dump_tdep: PROC_FRAME_OFFSET = function?\n"); | |
4678 | fprintf_unfiltered (file, | |
4679 | "mips_dump_tdep: PROC_FRAME_REG = function?\n"); | |
4680 | fprintf_unfiltered (file, | |
4681 | "mips_dump_tdep: PROC_FREG_MASK = function?\n"); | |
4682 | fprintf_unfiltered (file, | |
4683 | "mips_dump_tdep: PROC_FREG_OFFSET = function?\n"); | |
4684 | fprintf_unfiltered (file, | |
4685 | "mips_dump_tdep: PROC_HIGH_ADDR = function?\n"); | |
4686 | fprintf_unfiltered (file, | |
4687 | "mips_dump_tdep: PROC_LOW_ADDR = function?\n"); | |
4688 | fprintf_unfiltered (file, | |
4689 | "mips_dump_tdep: PROC_PC_REG = function?\n"); | |
4690 | fprintf_unfiltered (file, | |
4691 | "mips_dump_tdep: PROC_REG_MASK = function?\n"); | |
4692 | fprintf_unfiltered (file, | |
4693 | "mips_dump_tdep: PROC_REG_OFFSET = function?\n"); | |
4694 | fprintf_unfiltered (file, | |
4695 | "mips_dump_tdep: PROC_SYMBOL = function?\n"); | |
4696 | fprintf_unfiltered (file, | |
4697 | "mips_dump_tdep: PS_REGNUM = %d\n", | |
4698 | PS_REGNUM); | |
4699 | fprintf_unfiltered (file, | |
4700 | "mips_dump_tdep: PUSH_FP_REGNUM = %d\n", | |
4701 | PUSH_FP_REGNUM); | |
4702 | fprintf_unfiltered (file, | |
4703 | "mips_dump_tdep: RA_REGNUM = %d\n", | |
4704 | RA_REGNUM); | |
4705 | fprintf_unfiltered (file, | |
4706 | "mips_dump_tdep: REGISTER_CONVERT_FROM_TYPE # %s\n", | |
4707 | XSTRING (REGISTER_CONVERT_FROM_TYPE (REGNUM, VALTYPE, RAW_BUFFER))); | |
4708 | fprintf_unfiltered (file, | |
4709 | "mips_dump_tdep: REGISTER_CONVERT_TO_TYPE # %s\n", | |
4710 | XSTRING (REGISTER_CONVERT_TO_TYPE (REGNUM, VALTYPE, RAW_BUFFER))); | |
4711 | fprintf_unfiltered (file, | |
4712 | "mips_dump_tdep: REGISTER_NAMES = delete?\n"); | |
4713 | fprintf_unfiltered (file, | |
4714 | "mips_dump_tdep: ROUND_DOWN = function?\n"); | |
4715 | fprintf_unfiltered (file, | |
4716 | "mips_dump_tdep: ROUND_UP = function?\n"); | |
4717 | #ifdef SAVED_BYTES | |
4718 | fprintf_unfiltered (file, | |
4719 | "mips_dump_tdep: SAVED_BYTES = %d\n", | |
4720 | SAVED_BYTES); | |
4721 | #endif | |
4722 | #ifdef SAVED_FP | |
4723 | fprintf_unfiltered (file, | |
4724 | "mips_dump_tdep: SAVED_FP = %d\n", | |
4725 | SAVED_FP); | |
4726 | #endif | |
4727 | #ifdef SAVED_PC | |
4728 | fprintf_unfiltered (file, | |
4729 | "mips_dump_tdep: SAVED_PC = %d\n", | |
4730 | SAVED_PC); | |
4731 | #endif | |
4732 | fprintf_unfiltered (file, | |
4733 | "mips_dump_tdep: SETUP_ARBITRARY_FRAME # %s\n", | |
4734 | XSTRING (SETUP_ARBITRARY_FRAME (NUMARGS, ARGS))); | |
4735 | fprintf_unfiltered (file, | |
4736 | "mips_dump_tdep: SET_PROC_DESC_IS_DUMMY = function?\n"); | |
4737 | fprintf_unfiltered (file, | |
4738 | "mips_dump_tdep: SIGFRAME_BASE = %d\n", | |
4739 | SIGFRAME_BASE); | |
4740 | fprintf_unfiltered (file, | |
4741 | "mips_dump_tdep: SIGFRAME_FPREGSAVE_OFF = %d\n", | |
4742 | SIGFRAME_FPREGSAVE_OFF); | |
4743 | fprintf_unfiltered (file, | |
4744 | "mips_dump_tdep: SIGFRAME_PC_OFF = %d\n", | |
4745 | SIGFRAME_PC_OFF); | |
4746 | fprintf_unfiltered (file, | |
4747 | "mips_dump_tdep: SIGFRAME_REGSAVE_OFF = %d\n", | |
4748 | SIGFRAME_REGSAVE_OFF); | |
4749 | fprintf_unfiltered (file, | |
4750 | "mips_dump_tdep: SIGFRAME_REG_SIZE = %d\n", | |
4751 | SIGFRAME_REG_SIZE); | |
4752 | fprintf_unfiltered (file, | |
4753 | "mips_dump_tdep: SKIP_TRAMPOLINE_CODE # %s\n", | |
4754 | XSTRING (SKIP_TRAMPOLINE_CODE (PC))); | |
4755 | fprintf_unfiltered (file, | |
4756 | "mips_dump_tdep: SOFTWARE_SINGLE_STEP # %s\n", | |
4757 | XSTRING (SOFTWARE_SINGLE_STEP (SIG, BP_P))); | |
4758 | fprintf_unfiltered (file, | |
b0ed3589 AC |
4759 | "mips_dump_tdep: SOFTWARE_SINGLE_STEP_P () = %d\n", |
4760 | SOFTWARE_SINGLE_STEP_P ()); | |
2475bac3 AC |
4761 | fprintf_unfiltered (file, |
4762 | "mips_dump_tdep: STAB_REG_TO_REGNUM # %s\n", | |
4763 | XSTRING (STAB_REG_TO_REGNUM (REGNUM))); | |
4764 | #ifdef STACK_END_ADDR | |
4765 | fprintf_unfiltered (file, | |
4766 | "mips_dump_tdep: STACK_END_ADDR = %d\n", | |
4767 | STACK_END_ADDR); | |
4768 | #endif | |
4769 | fprintf_unfiltered (file, | |
4770 | "mips_dump_tdep: STEP_SKIPS_DELAY # %s\n", | |
4771 | XSTRING (STEP_SKIPS_DELAY (PC))); | |
4772 | fprintf_unfiltered (file, | |
4773 | "mips_dump_tdep: STEP_SKIPS_DELAY_P = %d\n", | |
4774 | STEP_SKIPS_DELAY_P); | |
4775 | fprintf_unfiltered (file, | |
4776 | "mips_dump_tdep: STOPPED_BY_WATCHPOINT # %s\n", | |
4777 | XSTRING (STOPPED_BY_WATCHPOINT (WS))); | |
4778 | fprintf_unfiltered (file, | |
4779 | "mips_dump_tdep: T9_REGNUM = %d\n", | |
4780 | T9_REGNUM); | |
4781 | fprintf_unfiltered (file, | |
4782 | "mips_dump_tdep: TABULAR_REGISTER_OUTPUT = used?\n"); | |
4783 | fprintf_unfiltered (file, | |
4784 | "mips_dump_tdep: TARGET_CAN_USE_HARDWARE_WATCHPOINT # %s\n", | |
4785 | XSTRING (TARGET_CAN_USE_HARDWARE_WATCHPOINT (TYPE,CNT,OTHERTYPE))); | |
4786 | fprintf_unfiltered (file, | |
4787 | "mips_dump_tdep: TARGET_HAS_HARDWARE_WATCHPOINTS # %s\n", | |
4788 | XSTRING (TARGET_HAS_HARDWARE_WATCHPOINTS)); | |
4789 | fprintf_unfiltered (file, | |
4790 | "mips_dump_tdep: TARGET_MIPS = used?\n"); | |
4791 | fprintf_unfiltered (file, | |
4792 | "mips_dump_tdep: TM_PRINT_INSN_MACH # %s\n", | |
4793 | XSTRING (TM_PRINT_INSN_MACH)); | |
4794 | #ifdef TRACE_CLEAR | |
4795 | fprintf_unfiltered (file, | |
4796 | "mips_dump_tdep: TRACE_CLEAR # %s\n", | |
4797 | XSTRING (TRACE_CLEAR (THREAD, STATE))); | |
4798 | #endif | |
4799 | #ifdef TRACE_FLAVOR | |
4800 | fprintf_unfiltered (file, | |
4801 | "mips_dump_tdep: TRACE_FLAVOR = %d\n", | |
4802 | TRACE_FLAVOR); | |
4803 | #endif | |
4804 | #ifdef TRACE_FLAVOR_SIZE | |
4805 | fprintf_unfiltered (file, | |
4806 | "mips_dump_tdep: TRACE_FLAVOR_SIZE = %d\n", | |
4807 | TRACE_FLAVOR_SIZE); | |
4808 | #endif | |
4809 | #ifdef TRACE_SET | |
4810 | fprintf_unfiltered (file, | |
4811 | "mips_dump_tdep: TRACE_SET # %s\n", | |
4812 | XSTRING (TRACE_SET (X,STATE))); | |
4813 | #endif | |
4814 | fprintf_unfiltered (file, | |
4815 | "mips_dump_tdep: UNMAKE_MIPS16_ADDR = function?\n"); | |
4816 | #ifdef UNUSED_REGNUM | |
4817 | fprintf_unfiltered (file, | |
4818 | "mips_dump_tdep: UNUSED_REGNUM = %d\n", | |
4819 | UNUSED_REGNUM); | |
4820 | #endif | |
4821 | fprintf_unfiltered (file, | |
4822 | "mips_dump_tdep: V0_REGNUM = %d\n", | |
4823 | V0_REGNUM); | |
4824 | fprintf_unfiltered (file, | |
4825 | "mips_dump_tdep: VM_MIN_ADDRESS = %ld\n", | |
4826 | (long) VM_MIN_ADDRESS); | |
4827 | #ifdef VX_NUM_REGS | |
4828 | fprintf_unfiltered (file, | |
4829 | "mips_dump_tdep: VX_NUM_REGS = %d (used?)\n", | |
4830 | VX_NUM_REGS); | |
4831 | #endif | |
4832 | fprintf_unfiltered (file, | |
4833 | "mips_dump_tdep: ZERO_REGNUM = %d\n", | |
4834 | ZERO_REGNUM); | |
4835 | fprintf_unfiltered (file, | |
4836 | "mips_dump_tdep: _PROC_MAGIC_ = %d\n", | |
4837 | _PROC_MAGIC_); | |
70f80edf JT |
4838 | |
4839 | fprintf_unfiltered (file, | |
4840 | "mips_dump_tdep: OS ABI = %s\n", | |
4841 | gdbarch_osabi_name (tdep->osabi)); | |
c2d11a7d JM |
4842 | } |
4843 | ||
c906108c | 4844 | void |
acdb74a0 | 4845 | _initialize_mips_tdep (void) |
c906108c SS |
4846 | { |
4847 | static struct cmd_list_element *mipsfpulist = NULL; | |
4848 | struct cmd_list_element *c; | |
4849 | ||
4b9b3959 | 4850 | gdbarch_register (bfd_arch_mips, mips_gdbarch_init, mips_dump_tdep); |
c5aa993b | 4851 | if (!tm_print_insn) /* Someone may have already set it */ |
c906108c SS |
4852 | tm_print_insn = gdb_print_insn_mips; |
4853 | ||
a5ea2558 AC |
4854 | /* Add root prefix command for all "set mips"/"show mips" commands */ |
4855 | add_prefix_cmd ("mips", no_class, set_mips_command, | |
4856 | "Various MIPS specific commands.", | |
4857 | &setmipscmdlist, "set mips ", 0, &setlist); | |
4858 | ||
4859 | add_prefix_cmd ("mips", no_class, show_mips_command, | |
4860 | "Various MIPS specific commands.", | |
4861 | &showmipscmdlist, "show mips ", 0, &showlist); | |
4862 | ||
4863 | /* Allow the user to override the saved register size. */ | |
4864 | add_show_from_set (add_set_enum_cmd ("saved-gpreg-size", | |
1ed2a135 AC |
4865 | class_obscure, |
4866 | size_enums, | |
4867 | &mips_saved_regsize_string, "\ | |
a5ea2558 AC |
4868 | Set size of general purpose registers saved on the stack.\n\ |
4869 | This option can be set to one of:\n\ | |
4870 | 32 - Force GDB to treat saved GP registers as 32-bit\n\ | |
4871 | 64 - Force GDB to treat saved GP registers as 64-bit\n\ | |
4872 | auto - Allow GDB to use the target's default setting or autodetect the\n\ | |
4873 | saved GP register size from information contained in the executable.\n\ | |
4874 | (default: auto)", | |
1ed2a135 | 4875 | &setmipscmdlist), |
a5ea2558 AC |
4876 | &showmipscmdlist); |
4877 | ||
d929b26f AC |
4878 | /* Allow the user to override the argument stack size. */ |
4879 | add_show_from_set (add_set_enum_cmd ("stack-arg-size", | |
4880 | class_obscure, | |
4881 | size_enums, | |
1ed2a135 | 4882 | &mips_stack_argsize_string, "\ |
d929b26f AC |
4883 | Set the amount of stack space reserved for each argument.\n\ |
4884 | This option can be set to one of:\n\ | |
4885 | 32 - Force GDB to allocate 32-bit chunks per argument\n\ | |
4886 | 64 - Force GDB to allocate 64-bit chunks per argument\n\ | |
4887 | auto - Allow GDB to determine the correct setting from the current\n\ | |
4888 | target and executable (default)", | |
4889 | &setmipscmdlist), | |
4890 | &showmipscmdlist); | |
4891 | ||
c906108c SS |
4892 | /* Let the user turn off floating point and set the fence post for |
4893 | heuristic_proc_start. */ | |
4894 | ||
4895 | add_prefix_cmd ("mipsfpu", class_support, set_mipsfpu_command, | |
4896 | "Set use of MIPS floating-point coprocessor.", | |
4897 | &mipsfpulist, "set mipsfpu ", 0, &setlist); | |
4898 | add_cmd ("single", class_support, set_mipsfpu_single_command, | |
4899 | "Select single-precision MIPS floating-point coprocessor.", | |
4900 | &mipsfpulist); | |
4901 | add_cmd ("double", class_support, set_mipsfpu_double_command, | |
8e1a459b | 4902 | "Select double-precision MIPS floating-point coprocessor.", |
c906108c SS |
4903 | &mipsfpulist); |
4904 | add_alias_cmd ("on", "double", class_support, 1, &mipsfpulist); | |
4905 | add_alias_cmd ("yes", "double", class_support, 1, &mipsfpulist); | |
4906 | add_alias_cmd ("1", "double", class_support, 1, &mipsfpulist); | |
4907 | add_cmd ("none", class_support, set_mipsfpu_none_command, | |
4908 | "Select no MIPS floating-point coprocessor.", | |
4909 | &mipsfpulist); | |
4910 | add_alias_cmd ("off", "none", class_support, 1, &mipsfpulist); | |
4911 | add_alias_cmd ("no", "none", class_support, 1, &mipsfpulist); | |
4912 | add_alias_cmd ("0", "none", class_support, 1, &mipsfpulist); | |
4913 | add_cmd ("auto", class_support, set_mipsfpu_auto_command, | |
4914 | "Select MIPS floating-point coprocessor automatically.", | |
4915 | &mipsfpulist); | |
4916 | add_cmd ("mipsfpu", class_support, show_mipsfpu_command, | |
4917 | "Show current use of MIPS floating-point coprocessor target.", | |
4918 | &showlist); | |
4919 | ||
c906108c SS |
4920 | /* We really would like to have both "0" and "unlimited" work, but |
4921 | command.c doesn't deal with that. So make it a var_zinteger | |
4922 | because the user can always use "999999" or some such for unlimited. */ | |
4923 | c = add_set_cmd ("heuristic-fence-post", class_support, var_zinteger, | |
4924 | (char *) &heuristic_fence_post, | |
4925 | "\ | |
4926 | Set the distance searched for the start of a function.\n\ | |
4927 | If you are debugging a stripped executable, GDB needs to search through the\n\ | |
4928 | program for the start of a function. This command sets the distance of the\n\ | |
4929 | search. The only need to set it is when debugging a stripped executable.", | |
4930 | &setlist); | |
4931 | /* We need to throw away the frame cache when we set this, since it | |
4932 | might change our ability to get backtraces. */ | |
9f60d481 | 4933 | set_cmd_sfunc (c, reinit_frame_cache_sfunc); |
c906108c SS |
4934 | add_show_from_set (c, &showlist); |
4935 | ||
4936 | /* Allow the user to control whether the upper bits of 64-bit | |
4937 | addresses should be zeroed. */ | |
4014092b AC |
4938 | c = add_set_auto_boolean_cmd ("mask-address", no_class, &mask_address_var, |
4939 | "Set zeroing of upper 32 bits of 64-bit addresses.\n\ | |
4940 | Use \"on\" to enable the masking, \"off\" to disable it and \"auto\" to allow GDB to determine\n\ | |
4941 | the correct value.\n", | |
4942 | &setmipscmdlist); | |
4943 | add_cmd ("mask-address", no_class, show_mask_address, | |
4944 | "Show current mask-address value", &showmipscmdlist); | |
43e526b9 JM |
4945 | |
4946 | /* Allow the user to control the size of 32 bit registers within the | |
4947 | raw remote packet. */ | |
4948 | add_show_from_set (add_set_cmd ("remote-mips64-transfers-32bit-regs", | |
4949 | class_obscure, | |
4950 | var_boolean, | |
4951 | (char *)&mips64_transfers_32bit_regs_p, "\ | |
4952 | Set compatibility with MIPS targets that transfers 32 and 64 bit quantities.\n\ | |
4953 | Use \"on\" to enable backward compatibility with older MIPS 64 GDB+target\n\ | |
4954 | that would transfer 32 bits for some registers (e.g. SR, FSR) and\n\ | |
4955 | 64 bits for others. Use \"off\" to disable compatibility mode", | |
4956 | &setlist), | |
4957 | &showlist); | |
9ace0497 AC |
4958 | |
4959 | /* Debug this files internals. */ | |
4960 | add_show_from_set (add_set_cmd ("mips", class_maintenance, var_zinteger, | |
4961 | &mips_debug, "Set mips debugging.\n\ | |
4962 | When non-zero, mips specific debugging is enabled.", &setdebuglist), | |
4963 | &showdebuglist); | |
c906108c | 4964 | } |