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