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