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