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