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