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