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