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