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