1 /* Target-dependent code for the MIPS architecture, for GDB, the GNU Debugger.
2 Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998
3 Free Software Foundation, Inc.
4 Contributed by Alessandro Forin(af@cs.cmu.edu) at CMU
5 and by Per Bothner(bothner@cs.wisc.edu) at U.Wisconsin.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
24 #include "gdb_string.h"
37 #include "opcode/mips.h"
39 /* Some MIPS boards don't support floating point while others only
40 support single-precision floating-point operations. See also
41 FP_REGISTER_DOUBLE. */
45 MIPS_FPU_DOUBLE, /* Full double precision floating point. */
46 MIPS_FPU_SINGLE, /* Single precision floating point (R4650). */
47 MIPS_FPU_NONE /* No floating point. */
50 #ifndef MIPS_DEFAULT_FPU_TYPE
51 #define MIPS_DEFAULT_FPU_TYPE MIPS_FPU_DOUBLE
53 static int mips_fpu_type_auto = 1;
54 static enum mips_fpu_type mips_fpu_type = MIPS_DEFAULT_FPU_TYPE;
55 #define MIPS_FPU_TYPE mips_fpu_type
57 #ifndef MIPS_SAVED_REGSIZE
58 #define MIPS_SAVED_REGSIZE MIPS_REGSIZE
61 /* Do not use "TARGET_IS_MIPS64" to test the size of floating point registers */
62 #ifndef FP_REGISTER_DOUBLE
63 #define FP_REGISTER_DOUBLE (REGISTER_VIRTUAL_SIZE(FP0_REGNUM) == 8)
67 #define VM_MIN_ADDRESS (CORE_ADDR)0x400000
70 static int mips_in_lenient_prologue PARAMS ((CORE_ADDR, CORE_ADDR));
73 int gdb_print_insn_mips PARAMS ((bfd_vma, disassemble_info *));
75 static void mips_print_register PARAMS ((int, int));
77 static mips_extra_func_info_t
78 heuristic_proc_desc PARAMS ((CORE_ADDR, CORE_ADDR, struct frame_info *));
80 static CORE_ADDR heuristic_proc_start PARAMS ((CORE_ADDR));
82 static CORE_ADDR read_next_frame_reg PARAMS ((struct frame_info *, int));
84 void mips_set_processor_type_command PARAMS ((char *, int));
86 int mips_set_processor_type PARAMS ((char *));
88 static void mips_show_processor_type_command PARAMS ((char *, int));
90 static void reinit_frame_cache_sfunc PARAMS ((char *, int,
91 struct cmd_list_element *));
93 static mips_extra_func_info_t
94 find_proc_desc PARAMS ((CORE_ADDR pc, struct frame_info *next_frame));
96 static CORE_ADDR after_prologue PARAMS ((CORE_ADDR pc,
97 mips_extra_func_info_t proc_desc));
99 /* This value is the model of MIPS in use. It is derived from the value
100 of the PrID register. */
102 char *mips_processor_type;
104 char *tmp_mips_processor_type;
106 /* A set of original names, to be used when restoring back to generic
107 registers from a specific set. */
109 char *mips_generic_reg_names[] = REGISTER_NAMES;
111 /* Names of IDT R3041 registers. */
113 char *mips_r3041_reg_names[] = {
114 "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
115 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
116 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
117 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra",
118 "sr", "lo", "hi", "bad", "cause","pc",
119 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
120 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
121 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
122 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
123 "fsr", "fir", "fp", "",
124 "", "", "bus", "ccfg", "", "", "", "",
125 "", "", "port", "cmp", "", "", "epc", "prid",
128 /* Names of IDT R3051 registers. */
130 char *mips_r3051_reg_names[] = {
131 "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
132 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
133 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
134 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra",
135 "sr", "lo", "hi", "bad", "cause","pc",
136 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
137 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
138 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
139 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
140 "fsr", "fir", "fp", "",
141 "inx", "rand", "elo", "", "ctxt", "", "", "",
142 "", "", "ehi", "", "", "", "epc", "prid",
145 /* Names of IDT R3081 registers. */
147 char *mips_r3081_reg_names[] = {
148 "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
149 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
150 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
151 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra",
152 "sr", "lo", "hi", "bad", "cause","pc",
153 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
154 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
155 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
156 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
157 "fsr", "fir", "fp", "",
158 "inx", "rand", "elo", "cfg", "ctxt", "", "", "",
159 "", "", "ehi", "", "", "", "epc", "prid",
162 /* Names of LSI 33k registers. */
164 char *mips_lsi33k_reg_names[] = {
165 "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
166 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
167 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
168 "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra",
169 "epc", "hi", "lo", "sr", "cause","badvaddr",
170 "dcic", "bpc", "bda", "", "", "", "", "",
171 "", "", "", "", "", "", "", "",
172 "", "", "", "", "", "", "", "",
173 "", "", "", "", "", "", "", "",
175 "", "", "", "", "", "", "", "",
176 "", "", "", "", "", "", "", "",
182 } mips_processor_type_table[] = {
183 { "generic", mips_generic_reg_names },
184 { "r3041", mips_r3041_reg_names },
185 { "r3051", mips_r3051_reg_names },
186 { "r3071", mips_r3081_reg_names },
187 { "r3081", mips_r3081_reg_names },
188 { "lsi33k", mips_lsi33k_reg_names },
192 /* Table to translate MIPS16 register field to actual register number. */
193 static int mips16_to_32_reg[8] = { 16, 17, 2, 3, 4, 5, 6, 7 };
195 /* Heuristic_proc_start may hunt through the text section for a long
196 time across a 2400 baud serial line. Allows the user to limit this
199 static unsigned int heuristic_fence_post = 0;
201 #define PROC_LOW_ADDR(proc) ((proc)->pdr.adr) /* least address */
202 #define PROC_HIGH_ADDR(proc) ((proc)->high_addr) /* upper address bound */
203 #define PROC_FRAME_OFFSET(proc) ((proc)->pdr.frameoffset)
204 #define PROC_FRAME_REG(proc) ((proc)->pdr.framereg)
205 #define PROC_FRAME_ADJUST(proc) ((proc)->frame_adjust)
206 #define PROC_REG_MASK(proc) ((proc)->pdr.regmask)
207 #define PROC_FREG_MASK(proc) ((proc)->pdr.fregmask)
208 #define PROC_REG_OFFSET(proc) ((proc)->pdr.regoffset)
209 #define PROC_FREG_OFFSET(proc) ((proc)->pdr.fregoffset)
210 #define PROC_PC_REG(proc) ((proc)->pdr.pcreg)
211 #define PROC_SYMBOL(proc) (*(struct symbol**)&(proc)->pdr.isym)
212 #define _PROC_MAGIC_ 0x0F0F0F0F
213 #define PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym == _PROC_MAGIC_)
214 #define SET_PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym = _PROC_MAGIC_)
216 struct linked_proc_info
218 struct mips_extra_func_info info;
219 struct linked_proc_info *next;
220 } *linked_proc_desc_table = NULL;
223 /* Should the upper word of 64-bit addresses be zeroed? */
224 static int mask_address_p = 1;
226 /* Should call_function allocate stack space for a struct return? */
228 mips_use_struct_convention (gcc_p, type)
233 return (TYPE_LENGTH (type) > 2 * MIPS_SAVED_REGSIZE);
235 return 1; /* Structures are returned by ref in extra arg0 */
238 /* Tell if the program counter value in MEMADDR is in a MIPS16 function. */
241 pc_is_mips16 (bfd_vma memaddr)
243 struct minimal_symbol *sym;
245 /* If bit 0 of the address is set, assume this is a MIPS16 address. */
246 if (IS_MIPS16_ADDR (memaddr))
249 /* A flag indicating that this is a MIPS16 function is stored by elfread.c in
250 the high bit of the info field. Use this to decide if the function is
251 MIPS16 or normal MIPS. */
252 sym = lookup_minimal_symbol_by_pc (memaddr);
254 return MSYMBOL_IS_SPECIAL (sym);
260 /* This returns the PC of the first inst after the prologue. If we can't
261 find the prologue, then return 0. */
264 after_prologue (pc, proc_desc)
266 mips_extra_func_info_t proc_desc;
268 struct symtab_and_line sal;
269 CORE_ADDR func_addr, func_end;
272 proc_desc = find_proc_desc (pc, NULL);
276 /* If function is frameless, then we need to do it the hard way. I
277 strongly suspect that frameless always means prologueless... */
278 if (PROC_FRAME_REG (proc_desc) == SP_REGNUM
279 && PROC_FRAME_OFFSET (proc_desc) == 0)
283 if (!find_pc_partial_function (pc, NULL, &func_addr, &func_end))
284 return 0; /* Unknown */
286 sal = find_pc_line (func_addr, 0);
288 if (sal.end < func_end)
291 /* The line after the prologue is after the end of the function. In this
292 case, tell the caller to find the prologue the hard way. */
297 /* Decode a MIPS32 instruction that saves a register in the stack, and
298 set the appropriate bit in the general register mask or float register mask
299 to indicate which register is saved. This is a helper function
300 for mips_find_saved_regs. */
303 mips32_decode_reg_save (inst, gen_mask, float_mask)
305 unsigned long *gen_mask;
306 unsigned long *float_mask;
310 if ((inst & 0xffe00000) == 0xafa00000 /* sw reg,n($sp) */
311 || (inst & 0xffe00000) == 0xafc00000 /* sw reg,n($r30) */
312 || (inst & 0xffe00000) == 0xffa00000) /* sd reg,n($sp) */
314 /* It might be possible to use the instruction to
315 find the offset, rather than the code below which
316 is based on things being in a certain order in the
317 frame, but figuring out what the instruction's offset
318 is relative to might be a little tricky. */
319 reg = (inst & 0x001f0000) >> 16;
320 *gen_mask |= (1 << reg);
322 else if ((inst & 0xffe00000) == 0xe7a00000 /* swc1 freg,n($sp) */
323 || (inst & 0xffe00000) == 0xe7c00000 /* swc1 freg,n($r30) */
324 || (inst & 0xffe00000) == 0xf7a00000)/* sdc1 freg,n($sp) */
327 reg = ((inst & 0x001f0000) >> 16);
328 *float_mask |= (1 << reg);
332 /* Decode a MIPS16 instruction that saves a register in the stack, and
333 set the appropriate bit in the general register or float register mask
334 to indicate which register is saved. This is a helper function
335 for mips_find_saved_regs. */
338 mips16_decode_reg_save (inst, gen_mask)
340 unsigned long *gen_mask;
342 if ((inst & 0xf800) == 0xd000) /* sw reg,n($sp) */
344 int reg = mips16_to_32_reg[(inst & 0x700) >> 8];
345 *gen_mask |= (1 << reg);
347 else if ((inst & 0xff00) == 0xf900) /* sd reg,n($sp) */
349 int reg = mips16_to_32_reg[(inst & 0xe0) >> 5];
350 *gen_mask |= (1 << reg);
352 else if ((inst & 0xff00) == 0x6200 /* sw $ra,n($sp) */
353 || (inst & 0xff00) == 0xfa00) /* sd $ra,n($sp) */
354 *gen_mask |= (1 << RA_REGNUM);
358 /* Fetch and return instruction from the specified location. If the PC
359 is odd, assume it's a MIPS16 instruction; otherwise MIPS32. */
362 mips_fetch_instruction (addr)
365 char buf[MIPS_INSTLEN];
369 if (pc_is_mips16 (addr))
371 instlen = MIPS16_INSTLEN;
372 addr = UNMAKE_MIPS16_ADDR (addr);
375 instlen = MIPS_INSTLEN;
376 status = read_memory_nobpt (addr, buf, instlen);
378 memory_error (status, addr);
379 return extract_unsigned_integer (buf, instlen);
383 /* These the fields of 32 bit mips instructions */
384 #define mips32_op(x) (x >> 25)
385 #define itype_op(x) (x >> 25)
386 #define itype_rs(x) ((x >> 21)& 0x1f)
387 #define itype_rt(x) ((x >> 16) & 0x1f)
388 #define itype_immediate(x) ( x & 0xffff)
390 #define jtype_op(x) (x >> 25)
391 #define jtype_target(x) ( x & 0x03fffff)
393 #define rtype_op(x) (x >>25)
394 #define rtype_rs(x) ((x>>21) & 0x1f)
395 #define rtype_rt(x) ((x>>16) & 0x1f)
396 #define rtype_rd(x) ((x>>11) & 0x1f)
397 #define rtype_shamt(x) ((x>>6) & 0x1f)
398 #define rtype_funct(x) (x & 0x3f )
401 mips32_relative_offset(unsigned long inst)
403 x = itype_immediate(inst) ;
404 if (x & 0x8000) /* sign bit set */
406 x |= 0xffff0000 ; /* sign extension */
412 /* Determine whate to set a single step breakpoint while considering
415 mips32_next_pc(CORE_ADDR pc)
419 inst = mips_fetch_instruction(pc) ;
420 if ((inst & 0xe0000000) != 0) /* Not a special, junp or branch instruction */
421 { if ((inst >> 27) == 5) /* BEQL BNEZ BLEZL BGTZE , bits 0101xx */
422 { op = ((inst >> 25) & 0x03) ;
425 case 0 : goto equal_branch ; /* BEQL */
426 case 1 : goto neq_branch ; /* BNEZ */
427 case 2 : goto less_branch ; /* BLEZ */
428 case 3 : goto greater_branch ; /* BGTZ */
432 else pc += 4 ; /* Not a branch, next instruction is easy */
435 { /* This gets way messy */
437 /* Further subdivide into SPECIAL, REGIMM and other */
438 switch (op = ((inst >> 26) & 0x07)) /* extract bits 28,27,26 */
440 case 0 : /* SPECIAL */
441 op = rtype_funct(inst) ;
446 pc = read_register(rtype_rs(inst)) ; /* Set PC to that address */
451 break ; /* end special */
452 case 1 : /* REGIMM */
454 op = jtype_op(inst) ; /* branch condition */
455 switch (jtype_op(inst))
459 case 16 : /* BLTZALL */
460 case 18 : /* BLTZALL */
462 if (read_register(itype_rs(inst)) < 0)
463 pc += mips32_relative_offset(inst) + 4 ;
464 else pc += 8 ; /* after the delay slot */
468 case 17 : /* BGEZAL */
469 case 19 : /* BGEZALL */
470 greater_equal_branch:
471 if (read_register(itype_rs(inst)) >= 0)
472 pc += mips32_relative_offset(inst) + 4 ;
473 else pc += 8 ; /* after the delay slot */
475 /* All of the other intructions in the REGIMM catagory */
479 break ; /* end REGIMM */
482 { unsigned long reg ;
483 reg = jtype_target(inst) << 2 ;
484 pc = reg + ((pc+4) & 0xf0000000) ;
485 /* Whats this mysterious 0xf000000 adjustment ??? */
488 /* FIXME case JALX :*/
489 { unsigned long reg ;
490 reg = jtype_target(inst) << 2 ;
491 pc = reg + ((pc+4) & 0xf0000000) + 1 ; /* yes, +1 */
492 /* Add 1 to indicate 16 bit mode - Invert ISA mode */
494 break ; /* The new PC will be alternate mode */
495 case 4 : /* BEQ , BEQL */
497 if (read_register(itype_rs(inst)) ==
498 read_register(itype_rt(inst)))
499 pc += mips32_relative_offset(inst) + 4 ;
502 case 5 : /* BNE , BNEL */
504 if (read_register(itype_rs(inst)) !=
505 read_register(itype_rs(inst)))
506 pc += mips32_relative_offset(inst) + 4 ;
509 case 6 : /* BLEZ , BLEZL */
511 if (read_register(itype_rs(inst) <= 0))
512 pc += mips32_relative_offset(inst) + 4 ;
516 greater_branch : /* BGTZ BGTZL */
517 if (read_register(itype_rs(inst) > 0))
518 pc += mips32_relative_offset(inst) + 4 ;
525 } /* mips32_next_pc */
527 /* Decoding the next place to set a breakpoint is irregular for the
528 mips 16 variant, but fortunatly, there fewer instructions. We have to cope
529 ith extensions for 16 bit instructions and a pair of actual 32 bit instructions.
530 We dont want to set a single step instruction on the extend instruction
534 /* Lots of mips16 instruction formats */
535 /* Predicting jumps requires itype,ritype,i8type
536 and their extensions extItype,extritype,extI8type
538 enum mips16_inst_fmts
540 itype, /* 0 immediate 5,10 */
541 ritype, /* 1 5,3,8 */
542 rrtype, /* 2 5,3,3,5 */
543 rritype, /* 3 5,3,3,5 */
544 rrrtype, /* 4 5,3,3,3,2 */
545 rriatype, /* 5 5,3,3,1,4 */
546 shifttype, /* 6 5,3,3,3,2 */
547 i8type, /* 7 5,3,8 */
548 i8movtype, /* 8 5,3,3,5 */
549 i8mov32rtype, /* 9 5,3,5,3 */
550 i64type, /* 10 5,3,8 */
551 ri64type, /* 11 5,3,3,5 */
552 jalxtype, /* 12 5,1,5,5,16 - a 32 bit instruction */
553 exiItype, /* 13 5,6,5,5,1,1,1,1,1,1,5 */
554 extRitype, /* 14 5,6,5,5,3,1,1,1,5 */
555 extRRItype, /* 15 5,5,5,5,3,3,5 */
556 extRRIAtype, /* 16 5,7,4,5,3,3,1,4 */
557 EXTshifttype, /* 17 5,5,1,1,1,1,1,1,5,3,3,1,1,1,2 */
558 extI8type, /* 18 5,6,5,5,3,1,1,1,5 */
559 extI64type, /* 19 5,6,5,5,3,1,1,1,5 */
560 extRi64type, /* 20 5,6,5,5,3,3,5 */
561 extshift64type /* 21 5,5,1,1,1,1,1,1,5,1,1,1,3,5 */
563 /* I am heaping all the fields of the formats into one structure and then,
564 only the fields which are involved in instruction extension */
567 unsigned short inst ;
568 enum mips16_inst_fmts fmt ;
569 unsigned long offset ;
570 unsigned int regx ; /* Function in i8 type */
576 static void print_unpack(char * comment,
577 struct upk_mips16 * u)
579 printf("%s %04x ,f(%d) off(%08x) (x(%x) y(%x)\n",
580 comment,u->inst,u->fmt,u->offset,u->regx,u->regy) ;
583 /* The EXT-I, EXT-ri nad EXT-I8 instructions all have the same
584 format for the bits which make up the immediatate extension.
587 extended_offset(unsigned long extension)
589 unsigned long value ;
590 value = (extension >> 21) & 0x3f ; /* * extract 15:11 */
592 value |= (extension >> 16) & 0x1f ; /* extrace 10:5 */
594 value |= extension & 0x01f ; /* extract 4:0 */
598 /* Only call this function if you know that this is an extendable
599 instruction, It wont malfunction, but why make excess remote memory references?
600 If the immediate operands get sign extended or somthing, do it after
601 the extension is performed.
603 /* FIXME: Every one of these cases needs to worry about sign extension
604 when the offset is to be used in relative addressing */
607 static unsigned short fetch_mips_16(CORE_ADDR pc)
610 pc &= 0xfffffffe ; /* clear the low order bit */
611 target_read_memory(pc,buf,2) ;
612 return extract_unsigned_integer(buf,2) ;
616 unpack_mips16(CORE_ADDR pc,
617 struct upk_mips16 * upk)
620 unsigned long extension ;
622 extpc = (pc - 4) & ~0x01 ; /* Extensions are 32 bit instructions */
623 /* Decrement to previous address and loose the 16bit mode flag */
624 /* return if the instruction was extendable, but not actually extended */
625 extended = ((mips32_op(extension) == 30) ? 1 : 0) ;
626 if (extended) { extension = mips_fetch_instruction(extpc) ;}
631 unsigned long value ;
633 { value = extended_offset(extension) ;
634 value = value << 11 ; /* rom for the original value */
635 value |= upk->inst & 0x7ff ; /* eleven bits from instruction */
638 { value = upk->inst & 0x7ff ;
639 /* FIXME : Consider sign extension */
641 upk->offset = value ;
646 { /* A register identifier and an offset */
647 /* Most of the fields are the same as I type but the
648 immediate value is of a different length */
649 unsigned long value ;
652 value = extended_offset(extension) ;
653 value = value << 8 ; /* from the original instruction */
654 value |= upk->inst & 0xff ; /* eleven bits from instruction */
655 upk->regx = (extension >> 8) & 0x07 ; /* or i8 funct */
656 if (value & 0x4000) /* test the sign bit , bit 26 */
657 { value &= ~ 0x3fff ; /* remove the sign bit */
662 value = upk->inst & 0xff ; /* 8 bits */
663 upk->regx = (upk->inst >> 8) & 0x07 ; /* or i8 funct */
664 /* FIXME: Do sign extension , this format needs it */
665 if (value & 0x80) /* THIS CONFUSES ME */
666 { value &= 0xef ; /* remove the sign bit */
671 upk->offset = value ;
676 unsigned long value ;
677 unsigned short nexthalf ;
678 value = ((upk->inst & 0x1f) << 5) | ((upk->inst >> 5) & 0x1f) ;
679 value = value << 16 ;
680 nexthalf = mips_fetch_instruction(pc+2) ; /* low bit still set */
682 upk->offset = value ;
686 printf_filtered("Decoding unimplemented instruction format type\n") ;
689 /* print_unpack("UPK",upk) ; */
693 #define mips16_op(x) (x >> 11)
695 /* This is a map of the opcodes which ae known to perform branches */
696 static unsigned char map16[32] =
703 static CORE_ADDR add_offset_16(CORE_ADDR pc, int offset)
705 return ((offset << 2) | ((pc + 2) & (0xf0000000))) ;
711 static struct upk_mips16 upk ;
713 CORE_ADDR mips16_next_pc(CORE_ADDR pc)
717 /* inst = mips_fetch_instruction(pc) ; - This doesnt always work */
718 inst = fetch_mips_16(pc) ;
720 op = mips16_op(upk.inst) ;
726 case 2 : /* Branch */
728 unpack_mips16(pc,&upk) ;
730 offset = upk.offset ;
735 pc += (offset << 1) + 2 ;
738 case 3 : /* JAL , JALX - Watch out, these are 32 bit instruction*/
740 unpack_mips16(pc,&upk) ;
741 pc = add_offset_16(pc,upk.offset) ;
742 if ((upk.inst >> 10) & 0x01) /* Exchange mode */
743 pc = pc & ~ 0x01 ; /* Clear low bit, indicate 32 bit mode */
748 unpack_mips16(pc,&upk) ;
749 reg = read_register(upk.regx) ;
751 pc += (upk.offset << 1) + 2 ;
756 unpack_mips16(pc,&upk) ;
757 reg = read_register(upk.regx) ;
759 pc += (upk.offset << 1) + 2 ;
762 case 12 : /* I8 Formats btez btnez */
764 unpack_mips16(pc,&upk) ;
765 /* upk.regx contains the opcode */
766 reg = read_register(24) ; /* Test register is 24 */
767 if (((upk.regx == 0) && (reg == 0)) /* BTEZ */
768 || ((upk.regx == 1 ) && (reg != 0))) /* BTNEZ */
769 /* pc = add_offset_16(pc,upk.offset) ; */
770 pc += (upk.offset << 1) + 2 ;
773 case 29 : /* RR Formats JR, JALR, JALR-RA */
775 op = upk.inst & 0x1f ;
778 upk.regx = (upk.inst >> 8) & 0x07 ;
779 upk.regy = (upk.inst >> 5) & 0x07 ;
782 case 0 : reg = upk.regx ; break ;
783 case 1 : reg = 31 ; break ; /* Function return instruction*/
784 case 2 : reg = upk.regx ; break ;
785 default: reg = 31 ; break ; /* BOGUS Guess */
787 pc = read_register(reg) ;
791 case 30 : /* This is an extend instruction */
792 pc += 4 ; /* Dont be setting breakpints on the second half */
795 printf("Filtered - next PC probably incorrrect due to jump inst\n");
800 else pc+= 2 ; /* just a good old instruction */
801 /* See if we CAN actually break on the next instruction */
802 /* printf("NXTm16PC %08x\n",(unsigned long)pc) ; */
804 } /* mips16_next_pc */
806 /* The mips_next_pc function supports single_tep when the remote target monitor or
807 stub is not developed enough to so a single_step.
808 It works by decoding the current instruction and predicting where a branch
809 will go. This isnt hard because all the data is available.
810 The MIPS32 and MIPS16 variants are quite different
812 CORE_ADDR mips_next_pc(CORE_ADDR pc)
815 /* inst = mips_fetch_instruction(pc) ; */
816 /* if (pc_is_mips16) <----- This is failing */
818 return mips16_next_pc(pc) ;
819 else return mips32_next_pc(pc) ;
822 /* Guaranteed to set fci->saved_regs to some values (it never leaves it
826 mips_find_saved_regs (fci)
827 struct frame_info *fci;
830 CORE_ADDR reg_position;
831 /* r0 bit means kernel trap */
833 /* What registers have been saved? Bitmasks. */
834 unsigned long gen_mask, float_mask;
835 mips_extra_func_info_t proc_desc;
838 frame_saved_regs_zalloc (fci);
840 /* If it is the frame for sigtramp, the saved registers are located
841 in a sigcontext structure somewhere on the stack.
842 If the stack layout for sigtramp changes we might have to change these
843 constants and the companion fixup_sigtramp in mdebugread.c */
844 #ifndef SIGFRAME_BASE
845 /* To satisfy alignment restrictions, sigcontext is located 4 bytes
846 above the sigtramp frame. */
847 #define SIGFRAME_BASE MIPS_REGSIZE
848 /* FIXME! Are these correct?? */
849 #define SIGFRAME_PC_OFF (SIGFRAME_BASE + 2 * MIPS_REGSIZE)
850 #define SIGFRAME_REGSAVE_OFF (SIGFRAME_BASE + 3 * MIPS_REGSIZE)
851 #define SIGFRAME_FPREGSAVE_OFF \
852 (SIGFRAME_REGSAVE_OFF + MIPS_NUMREGS * MIPS_REGSIZE + 3 * MIPS_REGSIZE)
854 #ifndef SIGFRAME_REG_SIZE
855 /* FIXME! Is this correct?? */
856 #define SIGFRAME_REG_SIZE MIPS_REGSIZE
858 if (fci->signal_handler_caller)
860 for (ireg = 0; ireg < MIPS_NUMREGS; ireg++)
862 reg_position = fci->frame + SIGFRAME_REGSAVE_OFF
863 + ireg * SIGFRAME_REG_SIZE;
864 fci->saved_regs[ireg] = reg_position;
866 for (ireg = 0; ireg < MIPS_NUMREGS; ireg++)
868 reg_position = fci->frame + SIGFRAME_FPREGSAVE_OFF
869 + ireg * SIGFRAME_REG_SIZE;
870 fci->saved_regs[FP0_REGNUM + ireg] = reg_position;
872 fci->saved_regs[PC_REGNUM] = fci->frame + SIGFRAME_PC_OFF;
876 proc_desc = fci->proc_desc;
877 if (proc_desc == NULL)
878 /* I'm not sure how/whether this can happen. Normally when we can't
879 find a proc_desc, we "synthesize" one using heuristic_proc_desc
880 and set the saved_regs right away. */
883 kernel_trap = PROC_REG_MASK(proc_desc) & 1;
884 gen_mask = kernel_trap ? 0xFFFFFFFF : PROC_REG_MASK(proc_desc);
885 float_mask = kernel_trap ? 0xFFFFFFFF : PROC_FREG_MASK(proc_desc);
887 if (/* In any frame other than the innermost or a frame interrupted by
888 a signal, we assume that all registers have been saved.
889 This assumes that all register saves in a function happen before
890 the first function call. */
891 (fci->next == NULL || fci->next->signal_handler_caller)
893 /* In a dummy frame we know exactly where things are saved. */
894 && !PROC_DESC_IS_DUMMY (proc_desc)
896 /* Don't bother unless we are inside a function prologue. Outside the
897 prologue, we know where everything is. */
899 && in_prologue (fci->pc, PROC_LOW_ADDR (proc_desc))
901 /* Not sure exactly what kernel_trap means, but if it means
902 the kernel saves the registers without a prologue doing it,
903 we better not examine the prologue to see whether registers
904 have been saved yet. */
907 /* We need to figure out whether the registers that the proc_desc
908 claims are saved have been saved yet. */
912 /* Bitmasks; set if we have found a save for the register. */
913 unsigned long gen_save_found = 0;
914 unsigned long float_save_found = 0;
917 /* If the address is odd, assume this is MIPS16 code. */
918 addr = PROC_LOW_ADDR (proc_desc);
919 instlen = pc_is_mips16 (addr) ? MIPS16_INSTLEN : MIPS_INSTLEN;
921 /* Scan through this function's instructions preceding the current
922 PC, and look for those that save registers. */
923 while (addr < fci->pc)
925 inst = mips_fetch_instruction (addr);
926 if (pc_is_mips16 (addr))
927 mips16_decode_reg_save (inst, &gen_save_found);
929 mips32_decode_reg_save (inst, &gen_save_found, &float_save_found);
932 gen_mask = gen_save_found;
933 float_mask = float_save_found;
936 /* Fill in the offsets for the registers which gen_mask says
938 reg_position = fci->frame + PROC_REG_OFFSET (proc_desc);
939 for (ireg= MIPS_NUMREGS-1; gen_mask; --ireg, gen_mask <<= 1)
940 if (gen_mask & 0x80000000)
942 fci->saved_regs[ireg] = reg_position;
943 reg_position -= MIPS_SAVED_REGSIZE;
946 /* The MIPS16 entry instruction saves $s0 and $s1 in the reverse order
947 of that normally used by gcc. Therefore, we have to fetch the first
948 instruction of the function, and if it's an entry instruction that
949 saves $s0 or $s1, correct their saved addresses. */
950 if (pc_is_mips16 (PROC_LOW_ADDR (proc_desc)))
952 inst = mips_fetch_instruction (PROC_LOW_ADDR (proc_desc));
953 if ((inst & 0xf81f) == 0xe809 && (inst & 0x700) != 0x700) /* entry */
956 int sreg_count = (inst >> 6) & 3;
958 /* Check if the ra register was pushed on the stack. */
959 reg_position = fci->frame + PROC_REG_OFFSET (proc_desc);
961 reg_position -= MIPS_SAVED_REGSIZE;
963 /* Check if the s0 and s1 registers were pushed on the stack. */
964 for (reg = 16; reg < sreg_count+16; reg++)
966 fci->saved_regs[reg] = reg_position;
967 reg_position -= MIPS_SAVED_REGSIZE;
972 /* Fill in the offsets for the registers which float_mask says
974 reg_position = fci->frame + PROC_FREG_OFFSET (proc_desc);
976 /* The freg_offset points to where the first *double* register
977 is saved. So skip to the high-order word. */
978 if (! GDB_TARGET_IS_MIPS64)
979 reg_position += MIPS_SAVED_REGSIZE;
981 /* Fill in the offsets for the float registers which float_mask says
983 for (ireg = MIPS_NUMREGS-1; float_mask; --ireg, float_mask <<= 1)
984 if (float_mask & 0x80000000)
986 fci->saved_regs[FP0_REGNUM+ireg] = reg_position;
987 reg_position -= MIPS_SAVED_REGSIZE;
990 fci->saved_regs[PC_REGNUM] = fci->saved_regs[RA_REGNUM];
994 read_next_frame_reg(fi, regno)
995 struct frame_info *fi;
998 for (; fi; fi = fi->next)
1000 /* We have to get the saved sp from the sigcontext
1001 if it is a signal handler frame. */
1002 if (regno == SP_REGNUM && !fi->signal_handler_caller)
1006 if (fi->saved_regs == NULL)
1007 mips_find_saved_regs (fi);
1008 if (fi->saved_regs[regno])
1009 return read_memory_integer(fi->saved_regs[regno], MIPS_SAVED_REGSIZE);
1012 return read_register (regno);
1015 /* mips_addr_bits_remove - remove useless address bits */
1018 mips_addr_bits_remove (addr)
1021 #if GDB_TARGET_IS_MIPS64
1022 if (mask_address_p && (addr >> 32 == (CORE_ADDR)0xffffffff))
1024 /* This hack is a work-around for existing boards using PMON,
1025 the simulator, and any other 64-bit targets that doesn't have
1026 true 64-bit addressing. On these targets, the upper 32 bits
1027 of addresses are ignored by the hardware. Thus, the PC or SP
1028 are likely to have been sign extended to all 1s by instruction
1029 sequences that load 32-bit addresses. For example, a typical
1030 piece of code that loads an address is this:
1031 lui $r2, <upper 16 bits>
1032 ori $r2, <lower 16 bits>
1033 But the lui sign-extends the value such that the upper 32 bits
1034 may be all 1s. The workaround is simply to mask off these bits.
1035 In the future, gcc may be changed to support true 64-bit
1036 addressing, and this masking will have to be disabled. */
1037 addr &= (CORE_ADDR)0xffffffff;
1040 /* Even when GDB is configured for some 32-bit targets (e.g. mips-elf),
1041 BFD is configured to handle 64-bit targets, so CORE_ADDR is 64 bits.
1042 So we still have to mask off useless bits from addresses. */
1043 addr &= (CORE_ADDR)0xffffffff;
1050 mips_init_frame_pc_first (fromleaf, prev)
1052 struct frame_info *prev;
1056 pc = ((fromleaf) ? SAVED_PC_AFTER_CALL (prev->next) :
1057 prev->next ? FRAME_SAVED_PC (prev->next) : read_pc ());
1058 tmp = mips_skip_stub (pc);
1059 prev->pc = tmp ? tmp : pc;
1064 mips_frame_saved_pc(frame)
1065 struct frame_info *frame;
1068 mips_extra_func_info_t proc_desc = frame->proc_desc;
1069 /* We have to get the saved pc from the sigcontext
1070 if it is a signal handler frame. */
1071 int pcreg = frame->signal_handler_caller ? PC_REGNUM
1072 : (proc_desc ? PROC_PC_REG(proc_desc) : RA_REGNUM);
1074 if (proc_desc && PROC_DESC_IS_DUMMY(proc_desc))
1075 saved_pc = read_memory_integer (frame->frame - MIPS_SAVED_REGSIZE, MIPS_SAVED_REGSIZE);
1077 saved_pc = read_next_frame_reg (frame, pcreg);
1079 return ADDR_BITS_REMOVE (saved_pc);
1082 static struct mips_extra_func_info temp_proc_desc;
1083 static struct frame_saved_regs temp_saved_regs;
1085 /* Set a register's saved stack address in temp_saved_regs. If an address
1086 has already been set for this register, do nothing; this way we will
1087 only recognize the first save of a given register in a function prologue.
1088 This is a helper function for mips{16,32}_heuristic_proc_desc. */
1091 set_reg_offset (regno, offset)
1095 if (temp_saved_regs.regs[regno] == 0)
1096 temp_saved_regs.regs[regno] = offset;
1100 /* Test whether the PC points to the return instruction at the
1101 end of a function. */
1104 mips_about_to_return (pc)
1107 if (pc_is_mips16 (pc))
1108 /* This mips16 case isn't necessarily reliable. Sometimes the compiler
1109 generates a "jr $ra"; other times it generates code to load
1110 the return address from the stack to an accessible register (such
1111 as $a3), then a "jr" using that register. This second case
1112 is almost impossible to distinguish from an indirect jump
1113 used for switch statements, so we don't even try. */
1114 return mips_fetch_instruction (pc) == 0xe820; /* jr $ra */
1116 return mips_fetch_instruction (pc) == 0x3e00008; /* jr $ra */
1120 /* This fencepost looks highly suspicious to me. Removing it also
1121 seems suspicious as it could affect remote debugging across serial
1125 heuristic_proc_start (pc)
1133 pc = ADDR_BITS_REMOVE (pc);
1135 fence = start_pc - heuristic_fence_post;
1136 if (start_pc == 0) return 0;
1138 if (heuristic_fence_post == UINT_MAX
1139 || fence < VM_MIN_ADDRESS)
1140 fence = VM_MIN_ADDRESS;
1142 instlen = pc_is_mips16 (pc) ? MIPS16_INSTLEN : MIPS_INSTLEN;
1144 /* search back for previous return */
1145 for (start_pc -= instlen; ; start_pc -= instlen)
1146 if (start_pc < fence)
1148 /* It's not clear to me why we reach this point when
1149 stop_soon_quietly, but with this test, at least we
1150 don't print out warnings for every child forked (eg, on
1151 decstation). 22apr93 rich@cygnus.com. */
1152 if (!stop_soon_quietly)
1154 static int blurb_printed = 0;
1156 if (fence == VM_MIN_ADDRESS)
1157 warning("Hit beginning of text section without finding");
1159 warning("Hit heuristic-fence-post without finding");
1161 warning("enclosing function for address 0x%s", paddr_nz (pc));
1165 This warning occurs if you are debugging a function without any symbols\n\
1166 (for example, in a stripped executable). In that case, you may wish to\n\
1167 increase the size of the search with the `set heuristic-fence-post' command.\n\
1169 Otherwise, you told GDB there was a function where there isn't one, or\n\
1170 (more likely) you have encountered a bug in GDB.\n");
1177 else if (pc_is_mips16 (start_pc))
1179 unsigned short inst;
1181 /* On MIPS16, any one of the following is likely to be the
1182 start of a function:
1186 extend -n followed by 'addiu sp,+n' or 'daddiu sp,+n' */
1187 inst = mips_fetch_instruction (start_pc);
1188 if (((inst & 0xf81f) == 0xe809 && (inst & 0x700) != 0x700) /* entry */
1189 || (inst & 0xff80) == 0x6380 /* addiu sp,-n */
1190 || (inst & 0xff80) == 0xfb80 /* daddiu sp,-n */
1191 || ((inst & 0xf810) == 0xf010 && seen_adjsp)) /* extend -n */
1193 else if ((inst & 0xff00) == 0x6300 /* addiu sp */
1194 || (inst & 0xff00) == 0xfb00) /* daddiu sp */
1199 else if (mips_about_to_return (start_pc))
1201 start_pc += 2 * MIPS_INSTLEN; /* skip return, and its delay slot */
1206 /* skip nops (usually 1) 0 - is this */
1207 while (start_pc < pc && read_memory_integer (start_pc, MIPS_INSTLEN) == 0)
1208 start_pc += MIPS_INSTLEN;
1213 /* Fetch the immediate value from a MIPS16 instruction.
1214 If the previous instruction was an EXTEND, use it to extend
1215 the upper bits of the immediate value. This is a helper function
1216 for mips16_heuristic_proc_desc. */
1219 mips16_get_imm (prev_inst, inst, nbits, scale, is_signed)
1220 unsigned short prev_inst; /* previous instruction */
1221 unsigned short inst; /* current instruction */
1222 int nbits; /* number of bits in imm field */
1223 int scale; /* scale factor to be applied to imm */
1224 int is_signed; /* is the imm field signed? */
1228 if ((prev_inst & 0xf800) == 0xf000) /* prev instruction was EXTEND? */
1230 offset = ((prev_inst & 0x1f) << 11) | (prev_inst & 0x7e0);
1231 if (offset & 0x8000) /* check for negative extend */
1232 offset = 0 - (0x10000 - (offset & 0xffff));
1233 return offset | (inst & 0x1f);
1237 int max_imm = 1 << nbits;
1238 int mask = max_imm - 1;
1239 int sign_bit = max_imm >> 1;
1241 offset = inst & mask;
1242 if (is_signed && (offset & sign_bit))
1243 offset = 0 - (max_imm - offset);
1244 return offset * scale;
1249 /* Fill in values in temp_proc_desc based on the MIPS16 instruction
1250 stream from start_pc to limit_pc. */
1253 mips16_heuristic_proc_desc(start_pc, limit_pc, next_frame, sp)
1254 CORE_ADDR start_pc, limit_pc;
1255 struct frame_info *next_frame;
1259 CORE_ADDR frame_addr = 0; /* Value of $r17, used as frame pointer */
1260 unsigned short prev_inst = 0; /* saved copy of previous instruction */
1261 unsigned inst = 0; /* current instruction */
1262 unsigned entry_inst = 0; /* the entry instruction */
1265 PROC_FRAME_OFFSET(&temp_proc_desc) = 0; /* size of stack frame */
1266 PROC_FRAME_ADJUST(&temp_proc_desc) = 0; /* offset of FP from SP */
1268 for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += MIPS16_INSTLEN)
1270 /* Save the previous instruction. If it's an EXTEND, we'll extract
1271 the immediate offset extension from it in mips16_get_imm. */
1274 /* Fetch and decode the instruction. */
1275 inst = (unsigned short) mips_fetch_instruction (cur_pc);
1276 if ((inst & 0xff00) == 0x6300 /* addiu sp */
1277 || (inst & 0xff00) == 0xfb00) /* daddiu sp */
1279 offset = mips16_get_imm (prev_inst, inst, 8, 8, 1);
1280 if (offset < 0) /* negative stack adjustment? */
1281 PROC_FRAME_OFFSET(&temp_proc_desc) -= offset;
1283 /* Exit loop if a positive stack adjustment is found, which
1284 usually means that the stack cleanup code in the function
1285 epilogue is reached. */
1288 else if ((inst & 0xf800) == 0xd000) /* sw reg,n($sp) */
1290 offset = mips16_get_imm (prev_inst, inst, 8, 4, 0);
1291 reg = mips16_to_32_reg[(inst & 0x700) >> 8];
1292 PROC_REG_MASK(&temp_proc_desc) |= (1 << reg);
1293 set_reg_offset (reg, sp + offset);
1295 else if ((inst & 0xff00) == 0xf900) /* sd reg,n($sp) */
1297 offset = mips16_get_imm (prev_inst, inst, 5, 8, 0);
1298 reg = mips16_to_32_reg[(inst & 0xe0) >> 5];
1299 PROC_REG_MASK(&temp_proc_desc) |= (1 << reg);
1300 set_reg_offset (reg, sp + offset);
1302 else if ((inst & 0xff00) == 0x6200) /* sw $ra,n($sp) */
1304 offset = mips16_get_imm (prev_inst, inst, 8, 4, 0);
1305 PROC_REG_MASK(&temp_proc_desc) |= (1 << RA_REGNUM);
1306 set_reg_offset (RA_REGNUM, sp + offset);
1308 else if ((inst & 0xff00) == 0xfa00) /* sd $ra,n($sp) */
1310 offset = mips16_get_imm (prev_inst, inst, 8, 8, 0);
1311 PROC_REG_MASK(&temp_proc_desc) |= (1 << RA_REGNUM);
1312 set_reg_offset (RA_REGNUM, sp + offset);
1314 else if (inst == 0x673d) /* move $s1, $sp */
1317 PROC_FRAME_REG (&temp_proc_desc) = 17;
1319 else if ((inst & 0xff00) == 0x0100) /* addiu $s1,sp,n */
1321 offset = mips16_get_imm (prev_inst, inst, 8, 4, 0);
1322 frame_addr = sp + offset;
1323 PROC_FRAME_REG (&temp_proc_desc) = 17;
1324 PROC_FRAME_ADJUST (&temp_proc_desc) = offset;
1326 else if ((inst & 0xFF00) == 0xd900) /* sw reg,offset($s1) */
1328 offset = mips16_get_imm (prev_inst, inst, 5, 4, 0);
1329 reg = mips16_to_32_reg[(inst & 0xe0) >> 5];
1330 PROC_REG_MASK(&temp_proc_desc) |= 1 << reg;
1331 set_reg_offset (reg, frame_addr + offset);
1333 else if ((inst & 0xFF00) == 0x7900) /* sd reg,offset($s1) */
1335 offset = mips16_get_imm (prev_inst, inst, 5, 8, 0);
1336 reg = mips16_to_32_reg[(inst & 0xe0) >> 5];
1337 PROC_REG_MASK(&temp_proc_desc) |= 1 << reg;
1338 set_reg_offset (reg, frame_addr + offset);
1340 else if ((inst & 0xf81f) == 0xe809 && (inst & 0x700) != 0x700) /* entry */
1341 entry_inst = inst; /* save for later processing */
1342 else if ((inst & 0xf800) == 0x1800) /* jal(x) */
1343 cur_pc += MIPS16_INSTLEN; /* 32-bit instruction */
1346 /* The entry instruction is typically the first instruction in a function,
1347 and it stores registers at offsets relative to the value of the old SP
1348 (before the prologue). But the value of the sp parameter to this
1349 function is the new SP (after the prologue has been executed). So we
1350 can't calculate those offsets until we've seen the entire prologue,
1351 and can calculate what the old SP must have been. */
1352 if (entry_inst != 0)
1354 int areg_count = (entry_inst >> 8) & 7;
1355 int sreg_count = (entry_inst >> 6) & 3;
1357 /* The entry instruction always subtracts 32 from the SP. */
1358 PROC_FRAME_OFFSET(&temp_proc_desc) += 32;
1360 /* Now we can calculate what the SP must have been at the
1361 start of the function prologue. */
1362 sp += PROC_FRAME_OFFSET(&temp_proc_desc);
1364 /* Check if a0-a3 were saved in the caller's argument save area. */
1365 for (reg = 4, offset = 0; reg < areg_count+4; reg++)
1367 PROC_REG_MASK(&temp_proc_desc) |= 1 << reg;
1368 set_reg_offset (reg, sp + offset);
1369 offset += MIPS_SAVED_REGSIZE;
1372 /* Check if the ra register was pushed on the stack. */
1374 if (entry_inst & 0x20)
1376 PROC_REG_MASK(&temp_proc_desc) |= 1 << RA_REGNUM;
1377 set_reg_offset (RA_REGNUM, sp + offset);
1378 offset -= MIPS_SAVED_REGSIZE;
1381 /* Check if the s0 and s1 registers were pushed on the stack. */
1382 for (reg = 16; reg < sreg_count+16; reg++)
1384 PROC_REG_MASK(&temp_proc_desc) |= 1 << reg;
1385 set_reg_offset (reg, sp + offset);
1386 offset -= MIPS_SAVED_REGSIZE;
1392 mips32_heuristic_proc_desc(start_pc, limit_pc, next_frame, sp)
1393 CORE_ADDR start_pc, limit_pc;
1394 struct frame_info *next_frame;
1398 CORE_ADDR frame_addr = 0; /* Value of $r30. Used by gcc for frame-pointer */
1400 memset (&temp_saved_regs, '\0', sizeof(struct frame_saved_regs));
1401 PROC_FRAME_OFFSET(&temp_proc_desc) = 0;
1402 PROC_FRAME_ADJUST (&temp_proc_desc) = 0; /* offset of FP from SP */
1403 for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += MIPS_INSTLEN)
1405 unsigned long inst, high_word, low_word;
1408 /* Fetch the instruction. */
1409 inst = (unsigned long) mips_fetch_instruction (cur_pc);
1411 /* Save some code by pre-extracting some useful fields. */
1412 high_word = (inst >> 16) & 0xffff;
1413 low_word = inst & 0xffff;
1414 reg = high_word & 0x1f;
1416 if (high_word == 0x27bd /* addiu $sp,$sp,-i */
1417 || high_word == 0x23bd /* addi $sp,$sp,-i */
1418 || high_word == 0x67bd) /* daddiu $sp,$sp,-i */
1420 if (low_word & 0x8000) /* negative stack adjustment? */
1421 PROC_FRAME_OFFSET(&temp_proc_desc) += 0x10000 - low_word;
1423 /* Exit loop if a positive stack adjustment is found, which
1424 usually means that the stack cleanup code in the function
1425 epilogue is reached. */
1428 else if ((high_word & 0xFFE0) == 0xafa0) /* sw reg,offset($sp) */
1430 PROC_REG_MASK(&temp_proc_desc) |= 1 << reg;
1431 set_reg_offset (reg, sp + low_word);
1433 else if ((high_word & 0xFFE0) == 0xffa0) /* sd reg,offset($sp) */
1435 /* Irix 6.2 N32 ABI uses sd instructions for saving $gp and $ra,
1436 but the register size used is only 32 bits. Make the address
1437 for the saved register point to the lower 32 bits. */
1438 PROC_REG_MASK(&temp_proc_desc) |= 1 << reg;
1439 set_reg_offset (reg, sp + low_word + 8 - MIPS_REGSIZE);
1441 else if (high_word == 0x27be) /* addiu $30,$sp,size */
1443 /* Old gcc frame, r30 is virtual frame pointer. */
1444 if ((long)low_word != PROC_FRAME_OFFSET(&temp_proc_desc))
1445 frame_addr = sp + low_word;
1446 else if (PROC_FRAME_REG (&temp_proc_desc) == SP_REGNUM)
1448 unsigned alloca_adjust;
1449 PROC_FRAME_REG (&temp_proc_desc) = 30;
1450 frame_addr = read_next_frame_reg(next_frame, 30);
1451 alloca_adjust = (unsigned)(frame_addr - (sp + low_word));
1452 if (alloca_adjust > 0)
1454 /* FP > SP + frame_size. This may be because
1455 * of an alloca or somethings similar.
1456 * Fix sp to "pre-alloca" value, and try again.
1458 sp += alloca_adjust;
1463 /* move $30,$sp. With different versions of gas this will be either
1464 `addu $30,$sp,$zero' or `or $30,$sp,$zero' or `daddu 30,sp,$0'.
1465 Accept any one of these. */
1466 else if (inst == 0x03A0F021 || inst == 0x03a0f025 || inst == 0x03a0f02d)
1468 /* New gcc frame, virtual frame pointer is at r30 + frame_size. */
1469 if (PROC_FRAME_REG (&temp_proc_desc) == SP_REGNUM)
1471 unsigned alloca_adjust;
1472 PROC_FRAME_REG (&temp_proc_desc) = 30;
1473 frame_addr = read_next_frame_reg(next_frame, 30);
1474 alloca_adjust = (unsigned)(frame_addr - sp);
1475 if (alloca_adjust > 0)
1477 /* FP > SP + frame_size. This may be because
1478 * of an alloca or somethings similar.
1479 * Fix sp to "pre-alloca" value, and try again.
1481 sp += alloca_adjust;
1486 else if ((high_word & 0xFFE0) == 0xafc0) /* sw reg,offset($30) */
1488 PROC_REG_MASK(&temp_proc_desc) |= 1 << reg;
1489 set_reg_offset (reg, frame_addr + low_word);
1494 static mips_extra_func_info_t
1495 heuristic_proc_desc(start_pc, limit_pc, next_frame)
1496 CORE_ADDR start_pc, limit_pc;
1497 struct frame_info *next_frame;
1499 CORE_ADDR sp = read_next_frame_reg (next_frame, SP_REGNUM);
1501 if (start_pc == 0) return NULL;
1502 memset (&temp_proc_desc, '\0', sizeof(temp_proc_desc));
1503 memset (&temp_saved_regs, '\0', sizeof(struct frame_saved_regs));
1504 PROC_LOW_ADDR (&temp_proc_desc) = start_pc;
1505 PROC_FRAME_REG (&temp_proc_desc) = SP_REGNUM;
1506 PROC_PC_REG (&temp_proc_desc) = RA_REGNUM;
1508 if (start_pc + 200 < limit_pc)
1509 limit_pc = start_pc + 200;
1510 if (pc_is_mips16 (start_pc))
1511 mips16_heuristic_proc_desc (start_pc, limit_pc, next_frame, sp);
1513 mips32_heuristic_proc_desc (start_pc, limit_pc, next_frame, sp);
1514 return &temp_proc_desc;
1517 static mips_extra_func_info_t
1518 non_heuristic_proc_desc (pc, addrptr)
1522 CORE_ADDR startaddr;
1523 mips_extra_func_info_t proc_desc;
1524 struct block *b = block_for_pc(pc);
1527 find_pc_partial_function (pc, NULL, &startaddr, NULL);
1529 *addrptr = startaddr;
1530 if (b == NULL || PC_IN_CALL_DUMMY (pc, 0, 0))
1534 if (startaddr > BLOCK_START (b))
1535 /* This is the "pathological" case referred to in a comment in
1536 print_frame_info. It might be better to move this check into
1540 sym = lookup_symbol (MIPS_EFI_SYMBOL_NAME, b, LABEL_NAMESPACE, 0, NULL);
1543 /* If we never found a PDR for this function in symbol reading, then
1544 examine prologues to find the information. */
1547 proc_desc = (mips_extra_func_info_t) SYMBOL_VALUE (sym);
1548 if (PROC_FRAME_REG (proc_desc) == -1)
1558 static mips_extra_func_info_t
1559 find_proc_desc (pc, next_frame)
1561 struct frame_info *next_frame;
1563 mips_extra_func_info_t proc_desc;
1564 CORE_ADDR startaddr;
1566 proc_desc = non_heuristic_proc_desc (pc, &startaddr);
1570 /* IF this is the topmost frame AND
1571 * (this proc does not have debugging information OR
1572 * the PC is in the procedure prologue)
1573 * THEN create a "heuristic" proc_desc (by analyzing
1574 * the actual code) to replace the "official" proc_desc.
1576 if (next_frame == NULL)
1578 struct symtab_and_line val;
1579 struct symbol *proc_symbol =
1580 PROC_DESC_IS_DUMMY(proc_desc) ? 0 : PROC_SYMBOL(proc_desc);
1584 val = find_pc_line (BLOCK_START
1585 (SYMBOL_BLOCK_VALUE(proc_symbol)),
1587 val.pc = val.end ? val.end : pc;
1589 if (!proc_symbol || pc < val.pc)
1591 mips_extra_func_info_t found_heuristic =
1592 heuristic_proc_desc (PROC_LOW_ADDR (proc_desc),
1594 if (found_heuristic)
1595 proc_desc = found_heuristic;
1601 /* Is linked_proc_desc_table really necessary? It only seems to be used
1602 by procedure call dummys. However, the procedures being called ought
1603 to have their own proc_descs, and even if they don't,
1604 heuristic_proc_desc knows how to create them! */
1606 register struct linked_proc_info *link;
1608 for (link = linked_proc_desc_table; link; link = link->next)
1609 if (PROC_LOW_ADDR(&link->info) <= pc
1610 && PROC_HIGH_ADDR(&link->info) > pc)
1614 startaddr = heuristic_proc_start (pc);
1617 heuristic_proc_desc (startaddr, pc, next_frame);
1623 get_frame_pointer(frame, proc_desc)
1624 struct frame_info *frame;
1625 mips_extra_func_info_t proc_desc;
1627 return ADDR_BITS_REMOVE (
1628 read_next_frame_reg (frame, PROC_FRAME_REG (proc_desc)) +
1629 PROC_FRAME_OFFSET (proc_desc) - PROC_FRAME_ADJUST (proc_desc));
1632 mips_extra_func_info_t cached_proc_desc;
1635 mips_frame_chain(frame)
1636 struct frame_info *frame;
1638 mips_extra_func_info_t proc_desc;
1640 CORE_ADDR saved_pc = FRAME_SAVED_PC(frame);
1642 if (saved_pc == 0 || inside_entry_file (saved_pc))
1645 /* Check if the PC is inside a call stub. If it is, fetch the
1646 PC of the caller of that stub. */
1647 if ((tmp = mips_skip_stub (saved_pc)) != 0)
1650 /* Look up the procedure descriptor for this PC. */
1651 proc_desc = find_proc_desc(saved_pc, frame);
1655 cached_proc_desc = proc_desc;
1657 /* If no frame pointer and frame size is zero, we must be at end
1658 of stack (or otherwise hosed). If we don't check frame size,
1659 we loop forever if we see a zero size frame. */
1660 if (PROC_FRAME_REG (proc_desc) == SP_REGNUM
1661 && PROC_FRAME_OFFSET (proc_desc) == 0
1662 /* The previous frame from a sigtramp frame might be frameless
1663 and have frame size zero. */
1664 && !frame->signal_handler_caller)
1667 return get_frame_pointer (frame, proc_desc);
1671 init_extra_frame_info(fci)
1672 struct frame_info *fci;
1676 /* Use proc_desc calculated in frame_chain */
1677 mips_extra_func_info_t proc_desc =
1678 fci->next ? cached_proc_desc : find_proc_desc(fci->pc, fci->next);
1680 fci->saved_regs = NULL;
1682 proc_desc == &temp_proc_desc ? 0 : proc_desc;
1685 /* Fixup frame-pointer - only needed for top frame */
1686 /* This may not be quite right, if proc has a real frame register.
1687 Get the value of the frame relative sp, procedure might have been
1688 interrupted by a signal at it's very start. */
1689 if (fci->pc == PROC_LOW_ADDR (proc_desc)
1690 && !PROC_DESC_IS_DUMMY (proc_desc))
1691 fci->frame = read_next_frame_reg (fci->next, SP_REGNUM);
1693 fci->frame = get_frame_pointer (fci->next, proc_desc);
1695 if (proc_desc == &temp_proc_desc)
1699 /* Do not set the saved registers for a sigtramp frame,
1700 mips_find_saved_registers will do that for us.
1701 We can't use fci->signal_handler_caller, it is not yet set. */
1702 find_pc_partial_function (fci->pc, &name,
1703 (CORE_ADDR *)NULL,(CORE_ADDR *)NULL);
1704 if (!IN_SIGTRAMP (fci->pc, name))
1706 fci->saved_regs = (CORE_ADDR*)
1707 frame_obstack_alloc (SIZEOF_FRAME_SAVED_REGS);
1708 memcpy (fci->saved_regs, temp_saved_regs.regs, SIZEOF_FRAME_SAVED_REGS);
1709 fci->saved_regs[PC_REGNUM]
1710 = fci->saved_regs[RA_REGNUM];
1714 /* hack: if argument regs are saved, guess these contain args */
1715 fci->num_args = -1; /* assume we can't tell how many args for now */
1716 for (regnum = MIPS_LAST_ARG_REGNUM; regnum >= A0_REGNUM; regnum--)
1718 if (PROC_REG_MASK(proc_desc) & (1 << regnum))
1720 fci->num_args = regnum - A0_REGNUM + 1;
1727 /* MIPS stack frames are almost impenetrable. When execution stops,
1728 we basically have to look at symbol information for the function
1729 that we stopped in, which tells us *which* register (if any) is
1730 the base of the frame pointer, and what offset from that register
1731 the frame itself is at.
1733 This presents a problem when trying to examine a stack in memory
1734 (that isn't executing at the moment), using the "frame" command. We
1735 don't have a PC, nor do we have any registers except SP.
1737 This routine takes two arguments, SP and PC, and tries to make the
1738 cached frames look as if these two arguments defined a frame on the
1739 cache. This allows the rest of info frame to extract the important
1740 arguments without difficulty. */
1743 setup_arbitrary_frame (argc, argv)
1748 error ("MIPS frame specifications require two arguments: sp and pc");
1750 return create_new_frame (argv[0], argv[1]);
1754 * STACK_ARGSIZE -- how many bytes does a pushed function arg take up on the stack?
1756 * For n32 ABI, eight.
1757 * For all others, he same as the size of a general register.
1759 #if defined (_MIPS_SIM_NABI32) && _MIPS_SIM == _MIPS_SIM_NABI32
1760 #define MIPS_NABI32 1
1761 #define STACK_ARGSIZE 8
1763 #define MIPS_NABI32 0
1764 #define STACK_ARGSIZE MIPS_SAVED_REGSIZE
1768 mips_push_arguments(nargs, args, sp, struct_return, struct_addr)
1773 CORE_ADDR struct_addr;
1779 int stack_offset = 0;
1781 /* Macros to round N up or down to the next A boundary; A must be
1783 #define ROUND_DOWN(n,a) ((n) & ~((a)-1))
1784 #define ROUND_UP(n,a) (((n)+(a)-1) & ~((a)-1))
1786 /* First ensure that the stack and structure return address (if any)
1787 are properly aligned. The stack has to be at least 64-bit aligned
1788 even on 32-bit machines, because doubles must be 64-bit aligned.
1789 On at least one MIPS variant, stack frames need to be 128-bit
1790 aligned, so we round to this widest known alignment. */
1791 sp = ROUND_DOWN (sp, 16);
1792 struct_addr = ROUND_DOWN (struct_addr, MIPS_SAVED_REGSIZE);
1794 /* Now make space on the stack for the args. We allocate more
1795 than necessary for EABI, because the first few arguments are
1796 passed in registers, but that's OK. */
1797 for (argnum = 0; argnum < nargs; argnum++)
1798 len += ROUND_UP (TYPE_LENGTH(VALUE_TYPE(args[argnum])), MIPS_SAVED_REGSIZE);
1799 sp -= ROUND_UP (len, 16);
1801 /* Initialize the integer and float register pointers. */
1803 float_argreg = FPA0_REGNUM;
1805 /* the struct_return pointer occupies the first parameter-passing reg */
1807 write_register (argreg++, struct_addr);
1809 /* Now load as many as possible of the first arguments into
1810 registers, and push the rest onto the stack. Loop thru args
1811 from first to last. */
1812 for (argnum = 0; argnum < nargs; argnum++)
1815 char valbuf[MAX_REGISTER_RAW_SIZE];
1816 value_ptr arg = args[argnum];
1817 struct type *arg_type = check_typedef (VALUE_TYPE (arg));
1818 int len = TYPE_LENGTH (arg_type);
1819 enum type_code typecode = TYPE_CODE (arg_type);
1821 /* The EABI passes structures that do not fit in a register by
1822 reference. In all other cases, pass the structure by value. */
1823 if (MIPS_EABI && len > MIPS_SAVED_REGSIZE &&
1824 (typecode == TYPE_CODE_STRUCT || typecode == TYPE_CODE_UNION))
1826 store_address (valbuf, MIPS_SAVED_REGSIZE, VALUE_ADDRESS (arg));
1827 typecode = TYPE_CODE_PTR;
1828 len = MIPS_SAVED_REGSIZE;
1832 val = (char *)VALUE_CONTENTS (arg);
1834 /* 32-bit ABIs always start floating point arguments in an
1835 even-numbered floating point register. */
1836 if (!FP_REGISTER_DOUBLE && typecode == TYPE_CODE_FLT
1837 && (float_argreg & 1))
1840 /* Floating point arguments passed in registers have to be
1841 treated specially. On 32-bit architectures, doubles
1842 are passed in register pairs; the even register gets
1843 the low word, and the odd register gets the high word.
1844 On non-EABI processors, the first two floating point arguments are
1845 also copied to general registers, because MIPS16 functions
1846 don't use float registers for arguments. This duplication of
1847 arguments in general registers can't hurt non-MIPS16 functions
1848 because those registers are normally skipped. */
1849 if (typecode == TYPE_CODE_FLT
1850 && float_argreg <= MIPS_LAST_FP_ARG_REGNUM
1851 && MIPS_FPU_TYPE != MIPS_FPU_NONE)
1853 if (!FP_REGISTER_DOUBLE && len == 8)
1855 int low_offset = TARGET_BYTE_ORDER == BIG_ENDIAN ? 4 : 0;
1856 unsigned long regval;
1858 /* Write the low word of the double to the even register(s). */
1859 regval = extract_unsigned_integer (val+low_offset, 4);
1860 write_register (float_argreg++, regval);
1862 write_register (argreg+1, regval);
1864 /* Write the high word of the double to the odd register(s). */
1865 regval = extract_unsigned_integer (val+4-low_offset, 4);
1866 write_register (float_argreg++, regval);
1869 write_register (argreg, regval);
1876 /* This is a floating point value that fits entirely
1877 in a single register. */
1878 CORE_ADDR regval = extract_address (val, len);
1879 write_register (float_argreg++, regval);
1882 write_register (argreg, regval);
1883 argreg += FP_REGISTER_DOUBLE ? 1 : 2;
1889 /* Copy the argument to general registers or the stack in
1890 register-sized pieces. Large arguments are split between
1891 registers and stack. */
1892 /* Note: structs whose size is not a multiple of MIPS_REGSIZE
1893 are treated specially: Irix cc passes them in registers
1894 where gcc sometimes puts them on the stack. For maximum
1895 compatibility, we will put them in both places. */
1897 int odd_sized_struct = ((len > MIPS_SAVED_REGSIZE) &&
1898 (len % MIPS_SAVED_REGSIZE != 0));
1901 int partial_len = len < MIPS_SAVED_REGSIZE ? len : MIPS_SAVED_REGSIZE;
1903 if (argreg > MIPS_LAST_ARG_REGNUM || odd_sized_struct)
1905 /* Write this portion of the argument to the stack. */
1906 /* Should shorter than int integer values be
1907 promoted to int before being stored? */
1909 int longword_offset = 0;
1910 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
1912 if (STACK_ARGSIZE == 8 &&
1913 (typecode == TYPE_CODE_INT ||
1914 typecode == TYPE_CODE_PTR ||
1915 typecode == TYPE_CODE_FLT) && len <= 4)
1916 longword_offset = STACK_ARGSIZE - len;
1917 else if ((typecode == TYPE_CODE_STRUCT ||
1918 typecode == TYPE_CODE_UNION) &&
1919 TYPE_LENGTH (arg_type) < STACK_ARGSIZE)
1920 longword_offset = STACK_ARGSIZE - len;
1923 write_memory (sp + stack_offset + longword_offset,
1927 /* Note!!! This is NOT an else clause.
1928 Odd sized structs may go thru BOTH paths. */
1929 if (argreg <= MIPS_LAST_ARG_REGNUM)
1931 CORE_ADDR regval = extract_address (val, partial_len);
1933 /* A non-floating-point argument being passed in a
1934 general register. If a struct or union, and if
1935 the remaining length is smaller than the register
1936 size, we have to adjust the register value on
1939 It does not seem to be necessary to do the
1940 same for integral types.
1942 Also don't do this adjustment on EABI and O64
1946 && MIPS_SAVED_REGSIZE < 8
1947 && TARGET_BYTE_ORDER == BIG_ENDIAN
1948 && partial_len < MIPS_SAVED_REGSIZE
1949 && (typecode == TYPE_CODE_STRUCT ||
1950 typecode == TYPE_CODE_UNION))
1951 regval <<= ((MIPS_SAVED_REGSIZE - partial_len) *
1954 write_register (argreg, regval);
1957 /* If this is the old ABI, prevent subsequent floating
1958 point arguments from being passed in floating point
1961 float_argreg = MIPS_LAST_FP_ARG_REGNUM + 1;
1967 /* The offset onto the stack at which we will start
1968 copying parameters (after the registers are used up)
1969 begins at (4 * MIPS_REGSIZE) in the old ABI. This
1970 leaves room for the "home" area for register parameters.
1972 In the new EABI (and the NABI32), the 8 register parameters
1973 do not have "home" stack space reserved for them, so the
1974 stack offset does not get incremented until after
1975 we have used up the 8 parameter registers. */
1977 if (!(MIPS_EABI || MIPS_NABI32) ||
1979 stack_offset += ROUND_UP (partial_len, STACK_ARGSIZE);
1984 /* Set the return address register to point to the entry
1985 point of the program, where a breakpoint lies in wait. */
1986 write_register (RA_REGNUM, CALL_DUMMY_ADDRESS());
1988 /* Return adjusted stack pointer. */
1993 mips_push_register (CORE_ADDR *sp, int regno)
1995 char buffer[MAX_REGISTER_RAW_SIZE];
1998 if (MIPS_SAVED_REGSIZE < REGISTER_RAW_SIZE (regno))
2000 regsize = MIPS_SAVED_REGSIZE;
2001 offset = (TARGET_BYTE_ORDER == BIG_ENDIAN
2002 ? REGISTER_RAW_SIZE (regno) - MIPS_SAVED_REGSIZE
2007 regsize = REGISTER_RAW_SIZE (regno);
2011 read_register_gen (regno, buffer);
2012 write_memory (*sp, buffer + offset, regsize);
2015 /* MASK(i,j) == (1<<i) + (1<<(i+1)) + ... + (1<<j)). Assume i<=j<(MIPS_NUMREGS-1). */
2016 #define MASK(i,j) (((1 << ((j)+1))-1) ^ ((1 << (i))-1))
2019 mips_push_dummy_frame ()
2022 struct linked_proc_info *link = (struct linked_proc_info*)
2023 xmalloc(sizeof(struct linked_proc_info));
2024 mips_extra_func_info_t proc_desc = &link->info;
2025 CORE_ADDR sp = ADDR_BITS_REMOVE (read_register (SP_REGNUM));
2026 CORE_ADDR old_sp = sp;
2027 link->next = linked_proc_desc_table;
2028 linked_proc_desc_table = link;
2030 /* FIXME! are these correct ? */
2031 #define PUSH_FP_REGNUM 16 /* must be a register preserved across calls */
2032 #define GEN_REG_SAVE_MASK MASK(1,16)|MASK(24,28)|(1<<(MIPS_NUMREGS-1))
2033 #define FLOAT_REG_SAVE_MASK MASK(0,19)
2034 #define FLOAT_SINGLE_REG_SAVE_MASK \
2035 ((1<<18)|(1<<16)|(1<<14)|(1<<12)|(1<<10)|(1<<8)|(1<<6)|(1<<4)|(1<<2)|(1<<0))
2037 * The registers we must save are all those not preserved across
2038 * procedure calls. Dest_Reg (see tm-mips.h) must also be saved.
2039 * In addition, we must save the PC, PUSH_FP_REGNUM, MMLO/-HI
2040 * and FP Control/Status registers.
2043 * Dummy frame layout:
2046 * Saved MMHI, MMLO, FPC_CSR
2051 * Saved D18 (i.e. F19, F18)
2053 * Saved D0 (i.e. F1, F0)
2054 * Argument build area and stack arguments written via mips_push_arguments
2058 /* Save special registers (PC, MMHI, MMLO, FPC_CSR) */
2059 PROC_FRAME_REG(proc_desc) = PUSH_FP_REGNUM;
2060 PROC_FRAME_OFFSET(proc_desc) = 0;
2061 PROC_FRAME_ADJUST(proc_desc) = 0;
2062 mips_push_register (&sp, PC_REGNUM);
2063 mips_push_register (&sp, HI_REGNUM);
2064 mips_push_register (&sp, LO_REGNUM);
2065 mips_push_register (&sp, MIPS_FPU_TYPE == MIPS_FPU_NONE ? 0 : FCRCS_REGNUM);
2067 /* Save general CPU registers */
2068 PROC_REG_MASK(proc_desc) = GEN_REG_SAVE_MASK;
2069 /* PROC_REG_OFFSET is the offset of the first saved register from FP. */
2070 PROC_REG_OFFSET(proc_desc) = sp - old_sp - MIPS_SAVED_REGSIZE;
2071 for (ireg = 32; --ireg >= 0; )
2072 if (PROC_REG_MASK(proc_desc) & (1 << ireg))
2073 mips_push_register (&sp, ireg);
2075 /* Save floating point registers starting with high order word */
2076 PROC_FREG_MASK(proc_desc) =
2077 MIPS_FPU_TYPE == MIPS_FPU_DOUBLE ? FLOAT_REG_SAVE_MASK
2078 : MIPS_FPU_TYPE == MIPS_FPU_SINGLE ? FLOAT_SINGLE_REG_SAVE_MASK : 0;
2079 /* PROC_FREG_OFFSET is the offset of the first saved *double* register
2081 PROC_FREG_OFFSET(proc_desc) = sp - old_sp - 8;
2082 for (ireg = 32; --ireg >= 0; )
2083 if (PROC_FREG_MASK(proc_desc) & (1 << ireg))
2084 mips_push_register (&sp, ireg + FP0_REGNUM);
2086 /* Update the frame pointer for the call dummy and the stack pointer.
2087 Set the procedure's starting and ending addresses to point to the
2088 call dummy address at the entry point. */
2089 write_register (PUSH_FP_REGNUM, old_sp);
2090 write_register (SP_REGNUM, sp);
2091 PROC_LOW_ADDR(proc_desc) = CALL_DUMMY_ADDRESS();
2092 PROC_HIGH_ADDR(proc_desc) = CALL_DUMMY_ADDRESS() + 4;
2093 SET_PROC_DESC_IS_DUMMY(proc_desc);
2094 PROC_PC_REG(proc_desc) = RA_REGNUM;
2100 register int regnum;
2101 struct frame_info *frame = get_current_frame ();
2102 CORE_ADDR new_sp = FRAME_FP (frame);
2104 mips_extra_func_info_t proc_desc = frame->proc_desc;
2106 write_register (PC_REGNUM, FRAME_SAVED_PC(frame));
2107 if (frame->saved_regs == NULL)
2108 mips_find_saved_regs (frame);
2109 for (regnum = 0; regnum < NUM_REGS; regnum++)
2111 if (regnum != SP_REGNUM && regnum != PC_REGNUM
2112 && frame->saved_regs[regnum])
2113 write_register (regnum,
2114 read_memory_integer (frame->saved_regs[regnum],
2115 MIPS_SAVED_REGSIZE));
2117 write_register (SP_REGNUM, new_sp);
2118 flush_cached_frames ();
2120 if (proc_desc && PROC_DESC_IS_DUMMY(proc_desc))
2122 struct linked_proc_info *pi_ptr, *prev_ptr;
2124 for (pi_ptr = linked_proc_desc_table, prev_ptr = NULL;
2126 prev_ptr = pi_ptr, pi_ptr = pi_ptr->next)
2128 if (&pi_ptr->info == proc_desc)
2133 error ("Can't locate dummy extra frame info\n");
2135 if (prev_ptr != NULL)
2136 prev_ptr->next = pi_ptr->next;
2138 linked_proc_desc_table = pi_ptr->next;
2142 write_register (HI_REGNUM,
2143 read_memory_integer (new_sp - 2*MIPS_SAVED_REGSIZE,
2144 MIPS_SAVED_REGSIZE));
2145 write_register (LO_REGNUM,
2146 read_memory_integer (new_sp - 3*MIPS_SAVED_REGSIZE,
2147 MIPS_SAVED_REGSIZE));
2148 if (MIPS_FPU_TYPE != MIPS_FPU_NONE)
2149 write_register (FCRCS_REGNUM,
2150 read_memory_integer (new_sp - 4*MIPS_SAVED_REGSIZE,
2151 MIPS_SAVED_REGSIZE));
2156 mips_print_register (regnum, all)
2159 char raw_buffer[MAX_REGISTER_RAW_SIZE];
2161 /* Get the data in raw format. */
2162 if (read_relative_register_raw_bytes (regnum, raw_buffer))
2164 printf_filtered ("%s: [Invalid]", REGISTER_NAME (regnum));
2168 /* If an even floating point register, also print as double. */
2169 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT
2170 && !((regnum-FP0_REGNUM) & 1))
2171 if (REGISTER_RAW_SIZE(regnum) == 4) /* this would be silly on MIPS64 or N32 (Irix 6) */
2173 char dbuffer[2 * MAX_REGISTER_RAW_SIZE];
2175 read_relative_register_raw_bytes (regnum, dbuffer);
2176 read_relative_register_raw_bytes (regnum+1, dbuffer+MIPS_REGSIZE);
2177 REGISTER_CONVERT_TO_TYPE (regnum, builtin_type_double, dbuffer);
2179 printf_filtered ("(d%d: ", regnum-FP0_REGNUM);
2180 val_print (builtin_type_double, dbuffer, 0, 0,
2181 gdb_stdout, 0, 1, 0, Val_pretty_default);
2182 printf_filtered ("); ");
2184 fputs_filtered (REGISTER_NAME (regnum), gdb_stdout);
2186 /* The problem with printing numeric register names (r26, etc.) is that
2187 the user can't use them on input. Probably the best solution is to
2188 fix it so that either the numeric or the funky (a2, etc.) names
2189 are accepted on input. */
2190 if (regnum < MIPS_NUMREGS)
2191 printf_filtered ("(r%d): ", regnum);
2193 printf_filtered (": ");
2195 /* If virtual format is floating, print it that way. */
2196 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT)
2197 if (FP_REGISTER_DOUBLE)
2198 { /* show 8-byte floats as float AND double: */
2199 int offset = 4 * (TARGET_BYTE_ORDER == BIG_ENDIAN);
2201 printf_filtered (" (float) ");
2202 val_print (builtin_type_float, raw_buffer + offset, 0, 0,
2203 gdb_stdout, 0, 1, 0, Val_pretty_default);
2204 printf_filtered (", (double) ");
2205 val_print (builtin_type_double, raw_buffer, 0, 0,
2206 gdb_stdout, 0, 1, 0, Val_pretty_default);
2209 val_print (REGISTER_VIRTUAL_TYPE (regnum), raw_buffer, 0, 0,
2210 gdb_stdout, 0, 1, 0, Val_pretty_default);
2211 /* Else print as integer in hex. */
2213 print_scalar_formatted (raw_buffer, REGISTER_VIRTUAL_TYPE (regnum),
2214 'x', 0, gdb_stdout);
2217 /* Replacement for generic do_registers_info.
2218 Print regs in pretty columns. */
2221 do_fp_register_row (regnum)
2223 { /* do values for FP (float) regs */
2224 char *raw_buffer[2];
2226 /* use HI and LO to control the order of combining two flt regs */
2227 int HI = (TARGET_BYTE_ORDER == BIG_ENDIAN);
2228 int LO = (TARGET_BYTE_ORDER != BIG_ENDIAN);
2229 double doub, flt1, flt2; /* doubles extracted from raw hex data */
2230 int inv1, inv2, inv3;
2232 raw_buffer[0] = (char *) alloca (REGISTER_RAW_SIZE (FP0_REGNUM));
2233 raw_buffer[1] = (char *) alloca (REGISTER_RAW_SIZE (FP0_REGNUM));
2234 dbl_buffer = (char *) alloca (2 * REGISTER_RAW_SIZE (FP0_REGNUM));
2236 /* Get the data in raw format. */
2237 if (read_relative_register_raw_bytes (regnum, raw_buffer[HI]))
2238 error ("can't read register %d (%s)", regnum, REGISTER_NAME (regnum));
2239 if (REGISTER_RAW_SIZE(regnum) == 4)
2241 /* 4-byte registers: we can fit two registers per row. */
2242 /* Also print every pair of 4-byte regs as an 8-byte double. */
2243 if (read_relative_register_raw_bytes (regnum + 1, raw_buffer[LO]))
2244 error ("can't read register %d (%s)",
2245 regnum + 1, REGISTER_NAME (regnum + 1));
2247 /* copy the two floats into one double, and unpack both */
2248 memcpy (dbl_buffer, raw_buffer, sizeof(dbl_buffer));
2249 flt1 = unpack_double (builtin_type_float, raw_buffer[HI], &inv1);
2250 flt2 = unpack_double (builtin_type_float, raw_buffer[LO], &inv2);
2251 doub = unpack_double (builtin_type_double, dbl_buffer, &inv3);
2253 printf_filtered (inv1 ? " %-5s: <invalid float>" :
2254 " %-5s%-17.9g", REGISTER_NAME (regnum), flt1);
2255 printf_filtered (inv2 ? " %-5s: <invalid float>" :
2256 " %-5s%-17.9g", REGISTER_NAME (regnum + 1), flt2);
2257 printf_filtered (inv3 ? " dbl: <invalid double>\n" :
2258 " dbl: %-24.17g\n", doub);
2259 /* may want to do hex display here (future enhancement) */
2263 { /* eight byte registers: print each one as float AND as double. */
2264 int offset = 4 * (TARGET_BYTE_ORDER == BIG_ENDIAN);
2266 memcpy (dbl_buffer, raw_buffer[HI], sizeof(dbl_buffer));
2267 flt1 = unpack_double (builtin_type_float,
2268 &raw_buffer[HI][offset], &inv1);
2269 doub = unpack_double (builtin_type_double, dbl_buffer, &inv3);
2271 printf_filtered (inv1 ? " %-5s: <invalid float>" :
2272 " %-5s flt: %-17.9g", REGISTER_NAME (regnum), flt1);
2273 printf_filtered (inv3 ? " dbl: <invalid double>\n" :
2274 " dbl: %-24.17g\n", doub);
2275 /* may want to do hex display here (future enhancement) */
2281 /* Print a row's worth of GP (int) registers, with name labels above */
2284 do_gp_register_row (regnum)
2287 /* do values for GP (int) regs */
2288 char raw_buffer[MAX_REGISTER_RAW_SIZE];
2289 int ncols = (MIPS_REGSIZE == 8 ? 4 : 8); /* display cols per row */
2291 int start_regnum = regnum;
2292 int numregs = NUM_REGS;
2295 /* For GP registers, we print a separate row of names above the vals */
2296 printf_filtered (" ");
2297 for (col = 0; col < ncols && regnum < numregs; regnum++)
2299 if (*REGISTER_NAME (regnum) == '\0')
2300 continue; /* unused register */
2301 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT)
2302 break; /* end the row: reached FP register */
2303 printf_filtered (MIPS_REGSIZE == 8 ? "%17s" : "%9s",
2304 REGISTER_NAME (regnum));
2307 printf_filtered (start_regnum < MIPS_NUMREGS ? "\n R%-4d" : "\n ",
2308 start_regnum); /* print the R0 to R31 names */
2310 regnum = start_regnum; /* go back to start of row */
2311 /* now print the values in hex, 4 or 8 to the row */
2312 for (col = 0; col < ncols && regnum < numregs; regnum++)
2314 if (*REGISTER_NAME (regnum) == '\0')
2315 continue; /* unused register */
2316 if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT)
2317 break; /* end row: reached FP register */
2318 /* OK: get the data in raw format. */
2319 if (read_relative_register_raw_bytes (regnum, raw_buffer))
2320 error ("can't read register %d (%s)", regnum, REGISTER_NAME (regnum));
2321 /* pad small registers */
2322 for (byte = 0; byte < (MIPS_REGSIZE - REGISTER_RAW_SIZE (regnum)); byte++)
2323 printf_filtered (" ");
2324 /* Now print the register value in hex, endian order. */
2325 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
2326 for (byte = 0; byte < REGISTER_RAW_SIZE (regnum); byte++)
2327 printf_filtered ("%02x", (unsigned char) raw_buffer[byte]);
2329 for (byte = REGISTER_RAW_SIZE (regnum) - 1; byte >= 0; byte--)
2330 printf_filtered ("%02x", (unsigned char) raw_buffer[byte]);
2331 printf_filtered (" ");
2334 if (col > 0) /* ie. if we actually printed anything... */
2335 printf_filtered ("\n");
2340 /* MIPS_DO_REGISTERS_INFO(): called by "info register" command */
2343 mips_do_registers_info (regnum, fpregs)
2347 if (regnum != -1) /* do one specified register */
2349 if (*(REGISTER_NAME (regnum)) == '\0')
2350 error ("Not a valid register for the current processor type");
2352 mips_print_register (regnum, 0);
2353 printf_filtered ("\n");
2355 else /* do all (or most) registers */
2358 while (regnum < NUM_REGS)
2360 if (TYPE_CODE(REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT)
2361 if (fpregs) /* true for "INFO ALL-REGISTERS" command */
2362 regnum = do_fp_register_row (regnum); /* FP regs */
2364 regnum += MIPS_NUMREGS; /* skip floating point regs */
2366 regnum = do_gp_register_row (regnum); /* GP (int) regs */
2371 /* Return number of args passed to a frame. described by FIP.
2372 Can return -1, meaning no way to tell. */
2375 mips_frame_num_args (frame)
2376 struct frame_info *frame;
2378 #if 0 /* FIXME Use or lose this! */
2379 struct chain_info_t *p;
2381 p = mips_find_cached_frame (FRAME_FP (frame));
2383 return p->the_info.numargs;
2388 /* Is this a branch with a delay slot? */
2390 static int is_delayed PARAMS ((unsigned long));
2397 for (i = 0; i < NUMOPCODES; ++i)
2398 if (mips_opcodes[i].pinfo != INSN_MACRO
2399 && (insn & mips_opcodes[i].mask) == mips_opcodes[i].match)
2401 return (i < NUMOPCODES
2402 && (mips_opcodes[i].pinfo & (INSN_UNCOND_BRANCH_DELAY
2403 | INSN_COND_BRANCH_DELAY
2404 | INSN_COND_BRANCH_LIKELY)));
2408 mips_step_skips_delay (pc)
2411 char buf[MIPS_INSTLEN];
2413 /* There is no branch delay slot on MIPS16. */
2414 if (pc_is_mips16 (pc))
2417 if (target_read_memory (pc, buf, MIPS_INSTLEN) != 0)
2418 /* If error reading memory, guess that it is not a delayed branch. */
2420 return is_delayed ((unsigned long)extract_unsigned_integer (buf, MIPS_INSTLEN));
2424 /* Skip the PC past function prologue instructions (32-bit version).
2425 This is a helper function for mips_skip_prologue. */
2428 mips32_skip_prologue (pc, lenient)
2429 CORE_ADDR pc; /* starting PC to search from */
2434 int seen_sp_adjust = 0;
2435 int load_immediate_bytes = 0;
2437 /* Skip the typical prologue instructions. These are the stack adjustment
2438 instruction and the instructions that save registers on the stack
2439 or in the gcc frame. */
2440 for (end_pc = pc + 100; pc < end_pc; pc += MIPS_INSTLEN)
2442 unsigned long high_word;
2444 inst = mips_fetch_instruction (pc);
2445 high_word = (inst >> 16) & 0xffff;
2448 if (lenient && is_delayed (inst))
2452 if (high_word == 0x27bd /* addiu $sp,$sp,offset */
2453 || high_word == 0x67bd) /* daddiu $sp,$sp,offset */
2455 else if (inst == 0x03a1e823 || /* subu $sp,$sp,$at */
2456 inst == 0x03a8e823) /* subu $sp,$sp,$t0 */
2458 else if (((inst & 0xFFE00000) == 0xAFA00000 /* sw reg,n($sp) */
2459 || (inst & 0xFFE00000) == 0xFFA00000) /* sd reg,n($sp) */
2460 && (inst & 0x001F0000)) /* reg != $zero */
2463 else if ((inst & 0xFFE00000) == 0xE7A00000) /* swc1 freg,n($sp) */
2465 else if ((inst & 0xF3E00000) == 0xA3C00000 && (inst & 0x001F0000))
2467 continue; /* reg != $zero */
2469 /* move $s8,$sp. With different versions of gas this will be either
2470 `addu $s8,$sp,$zero' or `or $s8,$sp,$zero' or `daddu s8,sp,$0'.
2471 Accept any one of these. */
2472 else if (inst == 0x03A0F021 || inst == 0x03a0f025 || inst == 0x03a0f02d)
2475 else if ((inst & 0xFF9F07FF) == 0x00800021) /* move reg,$a0-$a3 */
2477 else if (high_word == 0x3c1c) /* lui $gp,n */
2479 else if (high_word == 0x279c) /* addiu $gp,$gp,n */
2481 else if (inst == 0x0399e021 /* addu $gp,$gp,$t9 */
2482 || inst == 0x033ce021) /* addu $gp,$t9,$gp */
2484 /* The following instructions load $at or $t0 with an immediate
2485 value in preparation for a stack adjustment via
2486 subu $sp,$sp,[$at,$t0]. These instructions could also initialize
2487 a local variable, so we accept them only before a stack adjustment
2488 instruction was seen. */
2489 else if (!seen_sp_adjust)
2491 if (high_word == 0x3c01 || /* lui $at,n */
2492 high_word == 0x3c08) /* lui $t0,n */
2494 load_immediate_bytes += MIPS_INSTLEN; /* FIXME!! */
2497 else if (high_word == 0x3421 || /* ori $at,$at,n */
2498 high_word == 0x3508 || /* ori $t0,$t0,n */
2499 high_word == 0x3401 || /* ori $at,$zero,n */
2500 high_word == 0x3408) /* ori $t0,$zero,n */
2502 load_immediate_bytes += MIPS_INSTLEN; /* FIXME!! */
2512 /* In a frameless function, we might have incorrectly
2513 skipped some load immediate instructions. Undo the skipping
2514 if the load immediate was not followed by a stack adjustment. */
2515 if (load_immediate_bytes && !seen_sp_adjust)
2516 pc -= load_immediate_bytes;
2520 /* Skip the PC past function prologue instructions (16-bit version).
2521 This is a helper function for mips_skip_prologue. */
2524 mips16_skip_prologue (pc, lenient)
2525 CORE_ADDR pc; /* starting PC to search from */
2529 int extend_bytes = 0;
2530 int prev_extend_bytes;
2532 /* Table of instructions likely to be found in a function prologue. */
2535 unsigned short inst;
2536 unsigned short mask;
2539 { 0x6300, 0xff00 }, /* addiu $sp,offset */
2540 { 0xfb00, 0xff00 }, /* daddiu $sp,offset */
2541 { 0xd000, 0xf800 }, /* sw reg,n($sp) */
2542 { 0xf900, 0xff00 }, /* sd reg,n($sp) */
2543 { 0x6200, 0xff00 }, /* sw $ra,n($sp) */
2544 { 0xfa00, 0xff00 }, /* sd $ra,n($sp) */
2545 { 0x673d, 0xffff }, /* move $s1,sp */
2546 { 0xd980, 0xff80 }, /* sw $a0-$a3,n($s1) */
2547 { 0x6704, 0xff1c }, /* move reg,$a0-$a3 */
2548 { 0xe809, 0xf81f }, /* entry pseudo-op */
2549 { 0x0100, 0xff00 }, /* addiu $s1,$sp,n */
2550 { 0, 0 } /* end of table marker */
2553 /* Skip the typical prologue instructions. These are the stack adjustment
2554 instruction and the instructions that save registers on the stack
2555 or in the gcc frame. */
2556 for (end_pc = pc + 100; pc < end_pc; pc += MIPS16_INSTLEN)
2558 unsigned short inst;
2561 inst = mips_fetch_instruction (pc);
2563 /* Normally we ignore an extend instruction. However, if it is
2564 not followed by a valid prologue instruction, we must adjust
2565 the pc back over the extend so that it won't be considered
2566 part of the prologue. */
2567 if ((inst & 0xf800) == 0xf000) /* extend */
2569 extend_bytes = MIPS16_INSTLEN;
2572 prev_extend_bytes = extend_bytes;
2575 /* Check for other valid prologue instructions besides extend. */
2576 for (i = 0; table[i].mask != 0; i++)
2577 if ((inst & table[i].mask) == table[i].inst) /* found, get out */
2579 if (table[i].mask != 0) /* it was in table? */
2580 continue; /* ignore it */
2581 else /* non-prologue */
2583 /* Return the current pc, adjusted backwards by 2 if
2584 the previous instruction was an extend. */
2585 return pc - prev_extend_bytes;
2591 /* To skip prologues, I use this predicate. Returns either PC itself
2592 if the code at PC does not look like a function prologue; otherwise
2593 returns an address that (if we're lucky) follows the prologue. If
2594 LENIENT, then we must skip everything which is involved in setting
2595 up the frame (it's OK to skip more, just so long as we don't skip
2596 anything which might clobber the registers which are being saved.
2597 We must skip more in the case where part of the prologue is in the
2598 delay slot of a non-prologue instruction). */
2601 mips_skip_prologue (pc, lenient)
2605 /* See if we can determine the end of the prologue via the symbol table.
2606 If so, then return either PC, or the PC after the prologue, whichever
2609 CORE_ADDR post_prologue_pc = after_prologue (pc, NULL);
2611 if (post_prologue_pc != 0)
2612 return max (pc, post_prologue_pc);
2614 /* Can't determine prologue from the symbol table, need to examine
2617 if (pc_is_mips16 (pc))
2618 return mips16_skip_prologue (pc, lenient);
2620 return mips32_skip_prologue (pc, lenient);
2624 /* The lenient prologue stuff should be superseded by the code in
2625 init_extra_frame_info which looks to see whether the stores mentioned
2626 in the proc_desc have actually taken place. */
2628 /* Is address PC in the prologue (loosely defined) for function at
2632 mips_in_lenient_prologue (startaddr, pc)
2633 CORE_ADDR startaddr;
2636 CORE_ADDR end_prologue = mips_skip_prologue (startaddr, 1);
2637 return pc >= startaddr && pc < end_prologue;
2641 /* Determine how a return value is stored within the MIPS register
2642 file, given the return type `valtype'. */
2644 struct return_value_word
2652 static void return_value_location PARAMS ((struct type *, struct return_value_word *, struct return_value_word *));
2655 return_value_location (valtype, hi, lo)
2656 struct type *valtype;
2657 struct return_value_word *hi;
2658 struct return_value_word *lo;
2660 int len = TYPE_LENGTH (valtype);
2662 if (TYPE_CODE (valtype) == TYPE_CODE_FLT
2663 && ((MIPS_FPU_TYPE == MIPS_FPU_DOUBLE && (len == 4 || len == 8))
2664 || (MIPS_FPU_TYPE == MIPS_FPU_SINGLE && len == 4)))
2666 if (!FP_REGISTER_DOUBLE && len == 8)
2668 /* We need to break a 64bit float in two 32 bit halves and
2669 spread them across a floating-point register pair. */
2670 lo->buf_offset = TARGET_BYTE_ORDER == BIG_ENDIAN ? 4 : 0;
2671 hi->buf_offset = TARGET_BYTE_ORDER == BIG_ENDIAN ? 0 : 4;
2672 lo->reg_offset = ((TARGET_BYTE_ORDER == BIG_ENDIAN
2673 && REGISTER_RAW_SIZE (FP0_REGNUM) == 8)
2675 hi->reg_offset = lo->reg_offset;
2676 lo->reg = FP0_REGNUM + 0;
2677 hi->reg = FP0_REGNUM + 1;
2683 /* The floating point value fits in a single floating-point
2685 lo->reg_offset = ((TARGET_BYTE_ORDER == BIG_ENDIAN
2686 && REGISTER_RAW_SIZE (FP0_REGNUM) == 8
2689 lo->reg = FP0_REGNUM;
2700 /* Locate a result possibly spread across two registers. */
2702 lo->reg = regnum + 0;
2703 hi->reg = regnum + 1;
2704 if (TARGET_BYTE_ORDER == BIG_ENDIAN
2705 && len < MIPS_SAVED_REGSIZE)
2707 /* "un-left-justify" the value in the low register */
2708 lo->reg_offset = MIPS_SAVED_REGSIZE - len;
2713 else if (TARGET_BYTE_ORDER == BIG_ENDIAN
2714 && len > MIPS_SAVED_REGSIZE /* odd-size structs */
2715 && len < MIPS_SAVED_REGSIZE * 2
2716 && (TYPE_CODE (valtype) == TYPE_CODE_STRUCT ||
2717 TYPE_CODE (valtype) == TYPE_CODE_UNION))
2719 /* "un-left-justify" the value spread across two registers. */
2720 lo->reg_offset = 2 * MIPS_SAVED_REGSIZE - len;
2721 lo->len = MIPS_SAVED_REGSIZE - lo->reg_offset;
2723 hi->len = len - lo->len;
2727 /* Only perform a partial copy of the second register. */
2730 if (len > MIPS_SAVED_REGSIZE)
2732 lo->len = MIPS_SAVED_REGSIZE;
2733 hi->len = len - MIPS_SAVED_REGSIZE;
2741 if (TARGET_BYTE_ORDER == BIG_ENDIAN
2742 && REGISTER_RAW_SIZE (regnum) == 8
2743 && MIPS_SAVED_REGSIZE == 4)
2745 /* Account for the fact that only the least-signficant part
2746 of the register is being used */
2747 lo->reg_offset += 4;
2748 hi->reg_offset += 4;
2751 hi->buf_offset = lo->len;
2755 /* Given a return value in `regbuf' with a type `valtype', extract and
2756 copy its value into `valbuf'. */
2759 mips_extract_return_value (valtype, regbuf, valbuf)
2760 struct type *valtype;
2761 char regbuf[REGISTER_BYTES];
2764 struct return_value_word lo;
2765 struct return_value_word hi;
2766 return_value_location (valtype, &lo, &hi);
2768 memcpy (valbuf + lo.buf_offset,
2769 regbuf + REGISTER_BYTE (lo.reg) + lo.reg_offset,
2773 memcpy (valbuf + hi.buf_offset,
2774 regbuf + REGISTER_BYTE (hi.reg) + hi.reg_offset,
2780 int len = TYPE_LENGTH (valtype);
2783 if (TYPE_CODE (valtype) == TYPE_CODE_FLT
2784 && (MIPS_FPU_TYPE == MIPS_FPU_DOUBLE
2785 || (MIPS_FPU_TYPE == MIPS_FPU_SINGLE
2786 && len <= MIPS_FPU_SINGLE_REGSIZE)))
2787 regnum = FP0_REGNUM;
2789 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
2790 { /* "un-left-justify" the value from the register */
2791 if (len < REGISTER_RAW_SIZE (regnum))
2792 offset = REGISTER_RAW_SIZE (regnum) - len;
2793 if (len > REGISTER_RAW_SIZE (regnum) && /* odd-size structs */
2794 len < REGISTER_RAW_SIZE (regnum) * 2 &&
2795 (TYPE_CODE (valtype) == TYPE_CODE_STRUCT ||
2796 TYPE_CODE (valtype) == TYPE_CODE_UNION))
2797 offset = 2 * REGISTER_RAW_SIZE (regnum) - len;
2799 memcpy (valbuf, regbuf + REGISTER_BYTE (regnum) + offset, len);
2800 REGISTER_CONVERT_TO_TYPE (regnum, valtype, valbuf);
2804 /* Given a return value in `valbuf' with a type `valtype', write it's
2805 value into the appropriate register. */
2808 mips_store_return_value (valtype, valbuf)
2809 struct type *valtype;
2812 char raw_buffer[MAX_REGISTER_RAW_SIZE];
2813 struct return_value_word lo;
2814 struct return_value_word hi;
2815 return_value_location (valtype, &lo, &hi);
2817 memset (raw_buffer, 0, sizeof (raw_buffer));
2818 memcpy (raw_buffer + lo.reg_offset, valbuf + lo.buf_offset, lo.len);
2819 write_register_bytes (REGISTER_BYTE (lo.reg),
2821 REGISTER_RAW_SIZE (lo.reg));
2825 memset (raw_buffer, 0, sizeof (raw_buffer));
2826 memcpy (raw_buffer + hi.reg_offset, valbuf + hi.buf_offset, hi.len);
2827 write_register_bytes (REGISTER_BYTE (hi.reg),
2829 REGISTER_RAW_SIZE (hi.reg));
2835 int len = TYPE_LENGTH (valtype);
2836 char raw_buffer[MAX_REGISTER_RAW_SIZE];
2839 if (TYPE_CODE (valtype) == TYPE_CODE_FLT
2840 && (MIPS_FPU_TYPE == MIPS_FPU_DOUBLE
2841 || (MIPS_FPU_TYPE == MIPS_FPU_SINGLE
2842 && len <= MIPS_REGSIZE)))
2843 regnum = FP0_REGNUM;
2845 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
2846 { /* "left-justify" the value in the register */
2847 if (len < REGISTER_RAW_SIZE (regnum))
2848 offset = REGISTER_RAW_SIZE (regnum) - len;
2849 if (len > REGISTER_RAW_SIZE (regnum) && /* odd-size structs */
2850 len < REGISTER_RAW_SIZE (regnum) * 2 &&
2851 (TYPE_CODE (valtype) == TYPE_CODE_STRUCT ||
2852 TYPE_CODE (valtype) == TYPE_CODE_UNION))
2853 offset = 2 * REGISTER_RAW_SIZE (regnum) - len;
2855 memcpy(raw_buffer + offset, valbuf, len);
2856 REGISTER_CONVERT_FROM_TYPE(regnum, valtype, raw_buffer);
2857 write_register_bytes(REGISTER_BYTE (regnum), raw_buffer,
2858 len > REGISTER_RAW_SIZE (regnum) ?
2859 len : REGISTER_RAW_SIZE (regnum));
2863 /* Exported procedure: Is PC in the signal trampoline code */
2866 in_sigtramp (pc, ignore)
2868 char *ignore; /* function name */
2870 if (sigtramp_address == 0)
2872 return (pc >= sigtramp_address && pc < sigtramp_end);
2875 /* Commands to show/set the MIPS FPU type. */
2877 static void show_mipsfpu_command PARAMS ((char *, int));
2879 show_mipsfpu_command (args, from_tty)
2885 switch (MIPS_FPU_TYPE)
2887 case MIPS_FPU_SINGLE:
2888 fpu = "single-precision";
2890 case MIPS_FPU_DOUBLE:
2891 fpu = "double-precision";
2894 fpu = "absent (none)";
2897 if (mips_fpu_type_auto)
2898 printf_unfiltered ("The MIPS floating-point coprocessor is set automatically (currently %s)\n",
2901 printf_unfiltered ("The MIPS floating-point coprocessor is assumed to be %s\n",
2906 static void set_mipsfpu_command PARAMS ((char *, int));
2908 set_mipsfpu_command (args, from_tty)
2912 printf_unfiltered ("\"set mipsfpu\" must be followed by \"double\", \"single\",\"none\" or \"auto\".\n");
2913 show_mipsfpu_command (args, from_tty);
2916 static void set_mipsfpu_single_command PARAMS ((char *, int));
2918 set_mipsfpu_single_command (args, from_tty)
2922 mips_fpu_type = MIPS_FPU_SINGLE;
2923 mips_fpu_type_auto = 0;
2926 static void set_mipsfpu_double_command PARAMS ((char *, int));
2928 set_mipsfpu_double_command (args, from_tty)
2932 mips_fpu_type = MIPS_FPU_DOUBLE;
2933 mips_fpu_type_auto = 0;
2936 static void set_mipsfpu_none_command PARAMS ((char *, int));
2938 set_mipsfpu_none_command (args, from_tty)
2942 mips_fpu_type = MIPS_FPU_NONE;
2943 mips_fpu_type_auto = 0;
2946 static void set_mipsfpu_auto_command PARAMS ((char *, int));
2948 set_mipsfpu_auto_command (args, from_tty)
2952 mips_fpu_type_auto = 1;
2955 /* Command to set the processor type. */
2958 mips_set_processor_type_command (args, from_tty)
2964 if (tmp_mips_processor_type == NULL || *tmp_mips_processor_type == '\0')
2966 printf_unfiltered ("The known MIPS processor types are as follows:\n\n");
2967 for (i = 0; mips_processor_type_table[i].name != NULL; ++i)
2968 printf_unfiltered ("%s\n", mips_processor_type_table[i].name);
2970 /* Restore the value. */
2971 tmp_mips_processor_type = strsave (mips_processor_type);
2976 if (!mips_set_processor_type (tmp_mips_processor_type))
2978 error ("Unknown processor type `%s'.", tmp_mips_processor_type);
2979 /* Restore its value. */
2980 tmp_mips_processor_type = strsave (mips_processor_type);
2985 mips_show_processor_type_command (args, from_tty)
2991 /* Modify the actual processor type. */
2994 mips_set_processor_type (str)
3002 for (i = 0; mips_processor_type_table[i].name != NULL; ++i)
3004 if (strcasecmp (str, mips_processor_type_table[i].name) == 0)
3006 mips_processor_type = str;
3008 for (j = 0; j < NUM_REGS; ++j)
3009 /* FIXME - MIPS should be defining REGISTER_NAME() instead */
3010 gdb_register_names[j] = mips_processor_type_table[i].regnames[j];
3014 /* FIXME tweak fpu flag too */
3021 /* Attempt to identify the particular processor model by reading the
3025 mips_read_processor_type ()
3029 prid = read_register (PRID_REGNUM);
3031 if ((prid & ~0xf) == 0x700)
3032 return savestring ("r3041", strlen("r3041"));
3037 /* Just like reinit_frame_cache, but with the right arguments to be
3038 callable as an sfunc. */
3041 reinit_frame_cache_sfunc (args, from_tty, c)
3044 struct cmd_list_element *c;
3046 reinit_frame_cache ();
3050 gdb_print_insn_mips (memaddr, info)
3052 disassemble_info *info;
3054 mips_extra_func_info_t proc_desc;
3056 /* Search for the function containing this address. Set the low bit
3057 of the address when searching, in case we were given an even address
3058 that is the start of a 16-bit function. If we didn't do this,
3059 the search would fail because the symbol table says the function
3060 starts at an odd address, i.e. 1 byte past the given address. */
3061 memaddr = ADDR_BITS_REMOVE (memaddr);
3062 proc_desc = non_heuristic_proc_desc (MAKE_MIPS16_ADDR (memaddr), NULL);
3064 /* Make an attempt to determine if this is a 16-bit function. If
3065 the procedure descriptor exists and the address therein is odd,
3066 it's definitely a 16-bit function. Otherwise, we have to just
3067 guess that if the address passed in is odd, it's 16-bits. */
3069 info->mach = pc_is_mips16 (PROC_LOW_ADDR (proc_desc)) ? 16 : TM_PRINT_INSN_MACH;
3071 info->mach = pc_is_mips16 (memaddr) ? 16 : TM_PRINT_INSN_MACH;
3073 /* Round down the instruction address to the appropriate boundary. */
3074 memaddr &= (info->mach == 16 ? ~1 : ~3);
3076 /* Call the appropriate disassembler based on the target endian-ness. */
3077 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
3078 return print_insn_big_mips (memaddr, info);
3080 return print_insn_little_mips (memaddr, info);
3083 /* Old-style breakpoint macros.
3084 The IDT board uses an unusual breakpoint value, and sometimes gets
3085 confused when it sees the usual MIPS breakpoint instruction. */
3087 #define BIG_BREAKPOINT {0, 0x5, 0, 0xd}
3088 #define LITTLE_BREAKPOINT {0xd, 0, 0x5, 0}
3089 #define PMON_BIG_BREAKPOINT {0, 0, 0, 0xd}
3090 #define PMON_LITTLE_BREAKPOINT {0xd, 0, 0, 0}
3091 #define IDT_BIG_BREAKPOINT {0, 0, 0x0a, 0xd}
3092 #define IDT_LITTLE_BREAKPOINT {0xd, 0x0a, 0, 0}
3093 #define MIPS16_BIG_BREAKPOINT {0xe8, 0xa5}
3094 #define MIPS16_LITTLE_BREAKPOINT {0xa5, 0xe8}
3096 /* This function implements the BREAKPOINT_FROM_PC macro. It uses the program
3097 counter value to determine whether a 16- or 32-bit breakpoint should be
3098 used. It returns a pointer to a string of bytes that encode a breakpoint
3099 instruction, stores the length of the string to *lenptr, and adjusts pc
3100 (if necessary) to point to the actual memory location where the
3101 breakpoint should be inserted. */
3103 unsigned char *mips_breakpoint_from_pc (pcptr, lenptr)
3107 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
3109 if (pc_is_mips16 (*pcptr))
3111 static char mips16_big_breakpoint[] = MIPS16_BIG_BREAKPOINT;
3112 *pcptr = UNMAKE_MIPS16_ADDR (*pcptr);
3113 *lenptr = sizeof(mips16_big_breakpoint);
3114 return mips16_big_breakpoint;
3118 static char big_breakpoint[] = BIG_BREAKPOINT;
3119 static char pmon_big_breakpoint[] = PMON_BIG_BREAKPOINT;
3120 static char idt_big_breakpoint[] = IDT_BIG_BREAKPOINT;
3122 *lenptr = sizeof(big_breakpoint);
3124 if (strcmp (target_shortname, "mips") == 0)
3125 return idt_big_breakpoint;
3126 else if (strcmp (target_shortname, "ddb") == 0
3127 || strcmp (target_shortname, "pmon") == 0
3128 || strcmp (target_shortname, "lsi") == 0)
3129 return pmon_big_breakpoint;
3131 return big_breakpoint;
3136 if (pc_is_mips16 (*pcptr))
3138 static char mips16_little_breakpoint[] = MIPS16_LITTLE_BREAKPOINT;
3139 *pcptr = UNMAKE_MIPS16_ADDR (*pcptr);
3140 *lenptr = sizeof(mips16_little_breakpoint);
3141 return mips16_little_breakpoint;
3145 static char little_breakpoint[] = LITTLE_BREAKPOINT;
3146 static char pmon_little_breakpoint[] = PMON_LITTLE_BREAKPOINT;
3147 static char idt_little_breakpoint[] = IDT_LITTLE_BREAKPOINT;
3149 *lenptr = sizeof(little_breakpoint);
3151 if (strcmp (target_shortname, "mips") == 0)
3152 return idt_little_breakpoint;
3153 else if (strcmp (target_shortname, "ddb") == 0
3154 || strcmp (target_shortname, "pmon") == 0
3155 || strcmp (target_shortname, "lsi") == 0)
3156 return pmon_little_breakpoint;
3158 return little_breakpoint;
3163 /* If PC is in a mips16 call or return stub, return the address of the target
3164 PC, which is either the callee or the caller. There are several
3165 cases which must be handled:
3167 * If the PC is in __mips16_ret_{d,s}f, this is a return stub and the
3168 target PC is in $31 ($ra).
3169 * If the PC is in __mips16_call_stub_{1..10}, this is a call stub
3170 and the target PC is in $2.
3171 * If the PC at the start of __mips16_call_stub_{s,d}f_{0..10}, i.e.
3172 before the jal instruction, this is effectively a call stub
3173 and the the target PC is in $2. Otherwise this is effectively
3174 a return stub and the target PC is in $18.
3176 See the source code for the stubs in gcc/config/mips/mips16.S for
3179 This function implements the SKIP_TRAMPOLINE_CODE macro.
3187 CORE_ADDR start_addr;
3189 /* Find the starting address and name of the function containing the PC. */
3190 if (find_pc_partial_function (pc, &name, &start_addr, NULL) == 0)
3193 /* If the PC is in __mips16_ret_{d,s}f, this is a return stub and the
3194 target PC is in $31 ($ra). */
3195 if (strcmp (name, "__mips16_ret_sf") == 0
3196 || strcmp (name, "__mips16_ret_df") == 0)
3197 return read_register (RA_REGNUM);
3199 if (strncmp (name, "__mips16_call_stub_", 19) == 0)
3201 /* If the PC is in __mips16_call_stub_{1..10}, this is a call stub
3202 and the target PC is in $2. */
3203 if (name[19] >= '0' && name[19] <= '9')
3204 return read_register (2);
3206 /* If the PC at the start of __mips16_call_stub_{s,d}f_{0..10}, i.e.
3207 before the jal instruction, this is effectively a call stub
3208 and the the target PC is in $2. Otherwise this is effectively
3209 a return stub and the target PC is in $18. */
3210 else if (name[19] == 's' || name[19] == 'd')
3212 if (pc == start_addr)
3214 /* Check if the target of the stub is a compiler-generated
3215 stub. Such a stub for a function bar might have a name
3216 like __fn_stub_bar, and might look like this:
3221 la $1,bar (becomes a lui/addiu pair)
3223 So scan down to the lui/addi and extract the target
3224 address from those two instructions. */
3226 CORE_ADDR target_pc = read_register (2);
3230 /* See if the name of the target function is __fn_stub_*. */
3231 if (find_pc_partial_function (target_pc, &name, NULL, NULL) == 0)
3233 if (strncmp (name, "__fn_stub_", 10) != 0
3234 && strcmp (name, "etext") != 0
3235 && strcmp (name, "_etext") != 0)
3238 /* Scan through this _fn_stub_ code for the lui/addiu pair.
3239 The limit on the search is arbitrarily set to 20
3240 instructions. FIXME. */
3241 for (i = 0, pc = 0; i < 20; i++, target_pc += MIPS_INSTLEN)
3243 inst = mips_fetch_instruction (target_pc);
3244 if ((inst & 0xffff0000) == 0x3c010000) /* lui $at */
3245 pc = (inst << 16) & 0xffff0000; /* high word */
3246 else if ((inst & 0xffff0000) == 0x24210000) /* addiu $at */
3247 return pc | (inst & 0xffff); /* low word */
3250 /* Couldn't find the lui/addui pair, so return stub address. */
3254 /* This is the 'return' part of a call stub. The return
3255 address is in $r18. */
3256 return read_register (18);
3259 return 0; /* not a stub */
3263 /* Return non-zero if the PC is inside a call thunk (aka stub or trampoline).
3264 This implements the IN_SOLIB_CALL_TRAMPOLINE macro. */
3267 mips_in_call_stub (pc, name)
3271 CORE_ADDR start_addr;
3273 /* Find the starting address of the function containing the PC. If the
3274 caller didn't give us a name, look it up at the same time. */
3275 if (find_pc_partial_function (pc, name ? NULL : &name, &start_addr, NULL) == 0)
3278 if (strncmp (name, "__mips16_call_stub_", 19) == 0)
3280 /* If the PC is in __mips16_call_stub_{1..10}, this is a call stub. */
3281 if (name[19] >= '0' && name[19] <= '9')
3283 /* If the PC at the start of __mips16_call_stub_{s,d}f_{0..10}, i.e.
3284 before the jal instruction, this is effectively a call stub. */
3285 else if (name[19] == 's' || name[19] == 'd')
3286 return pc == start_addr;
3289 return 0; /* not a stub */
3293 /* Return non-zero if the PC is inside a return thunk (aka stub or trampoline).
3294 This implements the IN_SOLIB_RETURN_TRAMPOLINE macro. */
3297 mips_in_return_stub (pc, name)
3301 CORE_ADDR start_addr;
3303 /* Find the starting address of the function containing the PC. */
3304 if (find_pc_partial_function (pc, NULL, &start_addr, NULL) == 0)
3307 /* If the PC is in __mips16_ret_{d,s}f, this is a return stub. */
3308 if (strcmp (name, "__mips16_ret_sf") == 0
3309 || strcmp (name, "__mips16_ret_df") == 0)
3312 /* If the PC is in __mips16_call_stub_{s,d}f_{0..10} but not at the start,
3313 i.e. after the jal instruction, this is effectively a return stub. */
3314 if (strncmp (name, "__mips16_call_stub_", 19) == 0
3315 && (name[19] == 's' || name[19] == 'd')
3316 && pc != start_addr)
3319 return 0; /* not a stub */
3323 /* Return non-zero if the PC is in a library helper function that should
3324 be ignored. This implements the IGNORE_HELPER_CALL macro. */
3327 mips_ignore_helper (pc)
3332 /* Find the starting address and name of the function containing the PC. */
3333 if (find_pc_partial_function (pc, &name, NULL, NULL) == 0)
3336 /* If the PC is in __mips16_ret_{d,s}f, this is a library helper function
3337 that we want to ignore. */
3338 return (strcmp (name, "__mips16_ret_sf") == 0
3339 || strcmp (name, "__mips16_ret_df") == 0);
3343 /* Return a location where we can set a breakpoint that will be hit
3344 when an inferior function call returns. This is normally the
3345 program's entry point. Executables that don't have an entry
3346 point (e.g. programs in ROM) should define a symbol __CALL_DUMMY_ADDRESS
3347 whose address is the location where the breakpoint should be placed. */
3350 mips_call_dummy_address ()
3352 struct minimal_symbol *sym;
3354 sym = lookup_minimal_symbol ("__CALL_DUMMY_ADDRESS", NULL, NULL);
3356 return SYMBOL_VALUE_ADDRESS (sym);
3358 return entry_point_address ();
3363 _initialize_mips_tdep ()
3365 static struct cmd_list_element *mipsfpulist = NULL;
3366 struct cmd_list_element *c;
3368 if (!tm_print_insn) /* Someone may have already set it */
3369 tm_print_insn = gdb_print_insn_mips;
3371 /* Let the user turn off floating point and set the fence post for
3372 heuristic_proc_start. */
3374 add_prefix_cmd ("mipsfpu", class_support, set_mipsfpu_command,
3375 "Set use of MIPS floating-point coprocessor.",
3376 &mipsfpulist, "set mipsfpu ", 0, &setlist);
3377 add_cmd ("single", class_support, set_mipsfpu_single_command,
3378 "Select single-precision MIPS floating-point coprocessor.",
3380 add_cmd ("double", class_support, set_mipsfpu_double_command,
3381 "Select double-precision MIPS floating-point coprocessor .",
3383 add_alias_cmd ("on", "double", class_support, 1, &mipsfpulist);
3384 add_alias_cmd ("yes", "double", class_support, 1, &mipsfpulist);
3385 add_alias_cmd ("1", "double", class_support, 1, &mipsfpulist);
3386 add_cmd ("none", class_support, set_mipsfpu_none_command,
3387 "Select no MIPS floating-point coprocessor.",
3389 add_alias_cmd ("off", "none", class_support, 1, &mipsfpulist);
3390 add_alias_cmd ("no", "none", class_support, 1, &mipsfpulist);
3391 add_alias_cmd ("0", "none", class_support, 1, &mipsfpulist);
3392 add_cmd ("auto", class_support, set_mipsfpu_auto_command,
3393 "Select MIPS floating-point coprocessor automatically.",
3395 add_cmd ("mipsfpu", class_support, show_mipsfpu_command,
3396 "Show current use of MIPS floating-point coprocessor target.",
3399 c = add_set_cmd ("processor", class_support, var_string_noescape,
3400 (char *) &tmp_mips_processor_type,
3401 "Set the type of MIPS processor in use.\n\
3402 Set this to be able to access processor-type-specific registers.\n\
3405 c->function.cfunc = mips_set_processor_type_command;
3406 c = add_show_from_set (c, &showlist);
3407 c->function.cfunc = mips_show_processor_type_command;
3409 tmp_mips_processor_type = strsave (DEFAULT_MIPS_TYPE);
3410 mips_set_processor_type_command (strsave (DEFAULT_MIPS_TYPE), 0);
3412 /* We really would like to have both "0" and "unlimited" work, but
3413 command.c doesn't deal with that. So make it a var_zinteger
3414 because the user can always use "999999" or some such for unlimited. */
3415 c = add_set_cmd ("heuristic-fence-post", class_support, var_zinteger,
3416 (char *) &heuristic_fence_post,
3418 Set the distance searched for the start of a function.\n\
3419 If you are debugging a stripped executable, GDB needs to search through the\n\
3420 program for the start of a function. This command sets the distance of the\n\
3421 search. The only need to set it is when debugging a stripped executable.",
3423 /* We need to throw away the frame cache when we set this, since it
3424 might change our ability to get backtraces. */
3425 c->function.sfunc = reinit_frame_cache_sfunc;
3426 add_show_from_set (c, &showlist);
3428 /* Allow the user to control whether the upper bits of 64-bit
3429 addresses should be zeroed. */
3431 (add_set_cmd ("mask-address", no_class, var_boolean, (char *)&mask_address_p,
3432 "Set zeroing of upper 32 bits of 64-bit addresses.\n\
3433 Use \"on\" to enable the masking, and \"off\" to disable it.\n\
3434 Without an argument, zeroing of upper address bits is enabled.", &setlist),