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