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