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