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