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