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