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