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