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