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