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