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