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