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