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