| 1 | /* Target-dependent code for the MIPS architecture, for GDB, the GNU Debugger. |
| 2 | Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996 |
| 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. |
| 6 | |
| 7 | This file is part of GDB. |
| 8 | |
| 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. |
| 13 | |
| 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. |
| 18 | |
| 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. */ |
| 22 | |
| 23 | #include "defs.h" |
| 24 | #include "gdb_string.h" |
| 25 | #include "frame.h" |
| 26 | #include "inferior.h" |
| 27 | #include "symtab.h" |
| 28 | #include "value.h" |
| 29 | #include "gdbcmd.h" |
| 30 | #include "language.h" |
| 31 | #include "gdbcore.h" |
| 32 | #include "symfile.h" |
| 33 | #include "objfiles.h" |
| 34 | #include "gdbtypes.h" |
| 35 | #include "target.h" |
| 36 | |
| 37 | #include "opcode/mips.h" |
| 38 | |
| 39 | #define VM_MIN_ADDRESS (CORE_ADDR)0x400000 |
| 40 | |
| 41 | /* FIXME: Put this declaration in frame.h. */ |
| 42 | extern struct obstack frame_cache_obstack; |
| 43 | |
| 44 | #if 0 |
| 45 | static int mips_in_lenient_prologue PARAMS ((CORE_ADDR, CORE_ADDR)); |
| 46 | #endif |
| 47 | |
| 48 | int gdb_print_insn_mips PARAMS ((bfd_vma, disassemble_info *)); |
| 49 | |
| 50 | static void mips_print_register PARAMS ((int, int)); |
| 51 | |
| 52 | static mips_extra_func_info_t |
| 53 | heuristic_proc_desc PARAMS ((CORE_ADDR, CORE_ADDR, struct frame_info *)); |
| 54 | |
| 55 | static CORE_ADDR heuristic_proc_start PARAMS ((CORE_ADDR)); |
| 56 | |
| 57 | static CORE_ADDR read_next_frame_reg PARAMS ((struct frame_info *, int)); |
| 58 | |
| 59 | static void mips_set_fpu_command PARAMS ((char *, int, |
| 60 | struct cmd_list_element *)); |
| 61 | |
| 62 | static void mips_show_fpu_command PARAMS ((char *, int, |
| 63 | struct cmd_list_element *)); |
| 64 | |
| 65 | void mips_set_processor_type_command PARAMS ((char *, int)); |
| 66 | |
| 67 | int mips_set_processor_type PARAMS ((char *)); |
| 68 | |
| 69 | static void mips_show_processor_type_command PARAMS ((char *, int)); |
| 70 | |
| 71 | static void reinit_frame_cache_sfunc PARAMS ((char *, int, |
| 72 | struct cmd_list_element *)); |
| 73 | |
| 74 | static mips_extra_func_info_t |
| 75 | find_proc_desc PARAMS ((CORE_ADDR pc, struct frame_info *next_frame)); |
| 76 | |
| 77 | static CORE_ADDR after_prologue PARAMS ((CORE_ADDR pc, |
| 78 | mips_extra_func_info_t proc_desc)); |
| 79 | |
| 80 | /* This value is the model of MIPS in use. It is derived from the value |
| 81 | of the PrID register. */ |
| 82 | |
| 83 | char *mips_processor_type; |
| 84 | |
| 85 | char *tmp_mips_processor_type; |
| 86 | |
| 87 | /* Some MIPS boards don't support floating point, so we permit the |
| 88 | user to turn it off. */ |
| 89 | |
| 90 | enum mips_fpu_type mips_fpu; |
| 91 | |
| 92 | static char *mips_fpu_string; |
| 93 | |
| 94 | /* A set of original names, to be used when restoring back to generic |
| 95 | registers from a specific set. */ |
| 96 | |
| 97 | char *mips_generic_reg_names[] = REGISTER_NAMES; |
| 98 | |
| 99 | /* Names of IDT R3041 registers. */ |
| 100 | |
| 101 | char *mips_r3041_reg_names[] = { |
| 102 | "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3", |
| 103 | "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", |
| 104 | "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7", |
| 105 | "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra", |
| 106 | "sr", "lo", "hi", "bad", "cause","pc", |
| 107 | "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", |
| 108 | "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", |
| 109 | "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23", |
| 110 | "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", |
| 111 | "fsr", "fir", "fp", "", |
| 112 | "", "", "bus", "ccfg", "", "", "", "", |
| 113 | "", "", "port", "cmp", "", "", "epc", "prid", |
| 114 | }; |
| 115 | |
| 116 | /* Names of IDT R3051 registers. */ |
| 117 | |
| 118 | char *mips_r3051_reg_names[] = { |
| 119 | "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3", |
| 120 | "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", |
| 121 | "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7", |
| 122 | "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra", |
| 123 | "sr", "lo", "hi", "bad", "cause","pc", |
| 124 | "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", |
| 125 | "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", |
| 126 | "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23", |
| 127 | "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", |
| 128 | "fsr", "fir", "fp", "", |
| 129 | "inx", "rand", "elo", "", "ctxt", "", "", "", |
| 130 | "", "", "ehi", "", "", "", "epc", "prid", |
| 131 | }; |
| 132 | |
| 133 | /* Names of IDT R3081 registers. */ |
| 134 | |
| 135 | char *mips_r3081_reg_names[] = { |
| 136 | "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3", |
| 137 | "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", |
| 138 | "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7", |
| 139 | "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra", |
| 140 | "sr", "lo", "hi", "bad", "cause","pc", |
| 141 | "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", |
| 142 | "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", |
| 143 | "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23", |
| 144 | "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", |
| 145 | "fsr", "fir", "fp", "", |
| 146 | "inx", "rand", "elo", "cfg", "ctxt", "", "", "", |
| 147 | "", "", "ehi", "", "", "", "epc", "prid", |
| 148 | }; |
| 149 | |
| 150 | /* Names of LSI 33k registers. */ |
| 151 | |
| 152 | char *mips_lsi33k_reg_names[] = { |
| 153 | "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3", |
| 154 | "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", |
| 155 | "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7", |
| 156 | "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra", |
| 157 | "epc", "hi", "lo", "sr", "cause","badvaddr", |
| 158 | "dcic", "bpc", "bda", "", "", "", "", "", |
| 159 | "", "", "", "", "", "", "", "", |
| 160 | "", "", "", "", "", "", "", "", |
| 161 | "", "", "", "", "", "", "", "", |
| 162 | "", "", "", "", |
| 163 | "", "", "", "", "", "", "", "", |
| 164 | "", "", "", "", "", "", "", "", |
| 165 | }; |
| 166 | |
| 167 | struct { |
| 168 | char *name; |
| 169 | char **regnames; |
| 170 | } mips_processor_type_table[] = { |
| 171 | { "generic", mips_generic_reg_names }, |
| 172 | { "r3041", mips_r3041_reg_names }, |
| 173 | { "r3051", mips_r3051_reg_names }, |
| 174 | { "r3071", mips_r3081_reg_names }, |
| 175 | { "r3081", mips_r3081_reg_names }, |
| 176 | { "lsi33k", mips_lsi33k_reg_names }, |
| 177 | { NULL, NULL } |
| 178 | }; |
| 179 | |
| 180 | /* Table to translate MIPS16 register field to actual register number. */ |
| 181 | static int mips16_to_32_reg[8] = { 16, 17, 2, 3, 4, 5, 6, 7 }; |
| 182 | |
| 183 | /* Heuristic_proc_start may hunt through the text section for a long |
| 184 | time across a 2400 baud serial line. Allows the user to limit this |
| 185 | search. */ |
| 186 | |
| 187 | static unsigned int heuristic_fence_post = 0; |
| 188 | |
| 189 | #define PROC_LOW_ADDR(proc) ((proc)->pdr.adr) /* least address */ |
| 190 | #define PROC_HIGH_ADDR(proc) ((proc)->high_addr) /* upper address bound */ |
| 191 | #define PROC_FRAME_OFFSET(proc) ((proc)->pdr.frameoffset) |
| 192 | #define PROC_FRAME_REG(proc) ((proc)->pdr.framereg) |
| 193 | #define PROC_FRAME_ADJUST(proc) ((proc)->frame_adjust) |
| 194 | #define PROC_REG_MASK(proc) ((proc)->pdr.regmask) |
| 195 | #define PROC_FREG_MASK(proc) ((proc)->pdr.fregmask) |
| 196 | #define PROC_REG_OFFSET(proc) ((proc)->pdr.regoffset) |
| 197 | #define PROC_FREG_OFFSET(proc) ((proc)->pdr.fregoffset) |
| 198 | #define PROC_PC_REG(proc) ((proc)->pdr.pcreg) |
| 199 | #define PROC_SYMBOL(proc) (*(struct symbol**)&(proc)->pdr.isym) |
| 200 | #define _PROC_MAGIC_ 0x0F0F0F0F |
| 201 | #define PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym == _PROC_MAGIC_) |
| 202 | #define SET_PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym = _PROC_MAGIC_) |
| 203 | |
| 204 | struct linked_proc_info |
| 205 | { |
| 206 | struct mips_extra_func_info info; |
| 207 | struct linked_proc_info *next; |
| 208 | } *linked_proc_desc_table = NULL; |
| 209 | |
| 210 | |
| 211 | /* Tell if the program counter value in MEMADDR is in a MIPS16 function. */ |
| 212 | |
| 213 | static int |
| 214 | pc_is_mips16 (bfd_vma memaddr) |
| 215 | { |
| 216 | struct minimal_symbol *sym; |
| 217 | |
| 218 | /* If bit 0 of the address is set, assume this is a MIPS16 address. */ |
| 219 | if (IS_MIPS16_ADDR (memaddr)) |
| 220 | return 1; |
| 221 | |
| 222 | /* A flag indicating that this is a MIPS16 function is stored by elfread.c in |
| 223 | the high bit of the info field. Use this to decide if the function is |
| 224 | MIPS16 or normal MIPS. */ |
| 225 | sym = lookup_minimal_symbol_by_pc (memaddr); |
| 226 | if (sym) |
| 227 | return MSYMBOL_IS_SPECIAL (sym); |
| 228 | else |
| 229 | return 0; |
| 230 | } |
| 231 | |
| 232 | |
| 233 | /* This returns the PC of the first inst after the prologue. If we can't |
| 234 | find the prologue, then return 0. */ |
| 235 | |
| 236 | static CORE_ADDR |
| 237 | after_prologue (pc, proc_desc) |
| 238 | CORE_ADDR pc; |
| 239 | mips_extra_func_info_t proc_desc; |
| 240 | { |
| 241 | struct symtab_and_line sal; |
| 242 | CORE_ADDR func_addr, func_end; |
| 243 | |
| 244 | if (!proc_desc) |
| 245 | proc_desc = find_proc_desc (pc, NULL); |
| 246 | |
| 247 | if (proc_desc) |
| 248 | { |
| 249 | /* If function is frameless, then we need to do it the hard way. I |
| 250 | strongly suspect that frameless always means prologueless... */ |
| 251 | if (PROC_FRAME_REG (proc_desc) == SP_REGNUM |
| 252 | && PROC_FRAME_OFFSET (proc_desc) == 0) |
| 253 | return 0; |
| 254 | } |
| 255 | |
| 256 | if (!find_pc_partial_function (pc, NULL, &func_addr, &func_end)) |
| 257 | return 0; /* Unknown */ |
| 258 | |
| 259 | sal = find_pc_line (func_addr, 0); |
| 260 | |
| 261 | if (sal.end < func_end) |
| 262 | return sal.end; |
| 263 | |
| 264 | /* The line after the prologue is after the end of the function. In this |
| 265 | case, tell the caller to find the prologue the hard way. */ |
| 266 | |
| 267 | return 0; |
| 268 | } |
| 269 | |
| 270 | /* Decode a MIPS32 instruction that saves a register in the stack, and |
| 271 | set the appropriate bit in the general register mask or float register mask |
| 272 | to indicate which register is saved. This is a helper function |
| 273 | for mips_find_saved_regs. */ |
| 274 | |
| 275 | static void |
| 276 | mips32_decode_reg_save (inst, gen_mask, float_mask) |
| 277 | t_inst inst; |
| 278 | unsigned long *gen_mask; |
| 279 | unsigned long *float_mask; |
| 280 | { |
| 281 | int reg; |
| 282 | |
| 283 | if ((inst & 0xffe00000) == 0xafa00000 /* sw reg,n($sp) */ |
| 284 | || (inst & 0xffe00000) == 0xafc00000 /* sw reg,n($r30) */ |
| 285 | || (inst & 0xffe00000) == 0xffa00000) /* sd reg,n($sp) */ |
| 286 | { |
| 287 | /* It might be possible to use the instruction to |
| 288 | find the offset, rather than the code below which |
| 289 | is based on things being in a certain order in the |
| 290 | frame, but figuring out what the instruction's offset |
| 291 | is relative to might be a little tricky. */ |
| 292 | reg = (inst & 0x001f0000) >> 16; |
| 293 | *gen_mask |= (1 << reg); |
| 294 | } |
| 295 | else if ((inst & 0xffe00000) == 0xe7a00000 /* swc1 freg,n($sp) */ |
| 296 | || (inst & 0xffe00000) == 0xe7c00000 /* swc1 freg,n($r30) */ |
| 297 | || (inst & 0xffe00000) == 0xf7a00000)/* sdc1 freg,n($sp) */ |
| 298 | |
| 299 | { |
| 300 | reg = ((inst & 0x001f0000) >> 16); |
| 301 | *float_mask |= (1 << reg); |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | /* Decode a MIPS16 instruction that saves a register in the stack, and |
| 306 | set the appropriate bit in the general register or float register mask |
| 307 | to indicate which register is saved. This is a helper function |
| 308 | for mips_find_saved_regs. */ |
| 309 | |
| 310 | static void |
| 311 | mips16_decode_reg_save (inst, gen_mask) |
| 312 | t_inst inst; |
| 313 | unsigned long *gen_mask; |
| 314 | { |
| 315 | if ((inst & 0xf800) == 0xd000) /* sw reg,n($sp) */ |
| 316 | { |
| 317 | int reg = mips16_to_32_reg[(inst & 0x700) >> 8]; |
| 318 | *gen_mask |= (1 << reg); |
| 319 | } |
| 320 | else if ((inst & 0xff00) == 0xf900) /* sd reg,n($sp) */ |
| 321 | { |
| 322 | int reg = mips16_to_32_reg[(inst & 0xe0) >> 5]; |
| 323 | *gen_mask |= (1 << reg); |
| 324 | } |
| 325 | else if ((inst & 0xff00) == 0x6200 /* sw $ra,n($sp) */ |
| 326 | || (inst & 0xff00) == 0xfa00) /* sd $ra,n($sp) */ |
| 327 | *gen_mask |= (1 << RA_REGNUM); |
| 328 | } |
| 329 | |
| 330 | |
| 331 | /* Fetch and return instruction from the specified location. If the PC |
| 332 | is odd, assume it's a MIPS16 instruction; otherwise MIPS32. */ |
| 333 | |
| 334 | static t_inst |
| 335 | mips_fetch_instruction (addr) |
| 336 | CORE_ADDR addr; |
| 337 | { |
| 338 | char buf[MIPS_INSTLEN]; |
| 339 | int instlen; |
| 340 | int status; |
| 341 | |
| 342 | if (pc_is_mips16 (addr)) |
| 343 | { |
| 344 | instlen = MIPS16_INSTLEN; |
| 345 | addr = UNMAKE_MIPS16_ADDR (addr); |
| 346 | } |
| 347 | else |
| 348 | instlen = MIPS_INSTLEN; |
| 349 | status = read_memory_nobpt (addr, buf, instlen); |
| 350 | if (status) |
| 351 | memory_error (status, addr); |
| 352 | return extract_unsigned_integer (buf, instlen); |
| 353 | } |
| 354 | |
| 355 | |
| 356 | /* These the fields of 32 bit mips instructions */ |
| 357 | #define mips32_op(x) (x >> 25) |
| 358 | #define itype_op(x) (x >> 25) |
| 359 | #define itype_rs(x) ((x >> 21)& 0x1f) |
| 360 | #define itype_rt(x) ((x >> 16) & 0x1f) |
| 361 | #define itype_immediate(x) ( x & 0xffff) |
| 362 | |
| 363 | #define jtype_op(x) (x >> 25) |
| 364 | #define jtype_target(x) ( x & 0x03fffff) |
| 365 | |
| 366 | #define rtype_op(x) (x >>25) |
| 367 | #define rtype_rs(x) ((x>>21) & 0x1f) |
| 368 | #define rtype_rt(x) ((x>>16) & 0x1f) |
| 369 | #define rtype_rd(x) ((x>>11) & 0x1f) |
| 370 | #define rtype_shamt(x) ((x>>6) & 0x1f) |
| 371 | #define rtype_funct(x) (x & 0x3f ) |
| 372 | |
| 373 | static CORE_ADDR |
| 374 | mips32_relative_offset(unsigned long inst) |
| 375 | { long x ; |
| 376 | x = itype_immediate(inst) ; |
| 377 | if (x & 0x8000) /* sign bit set */ |
| 378 | { |
| 379 | x |= 0xffff0000 ; /* sign extension */ |
| 380 | } |
| 381 | x = x << 2 ; |
| 382 | return x ; |
| 383 | } |
| 384 | |
| 385 | /* Determine whate to set a single step breakpoint while considering |
| 386 | branch prediction */ |
| 387 | CORE_ADDR |
| 388 | mips32_next_pc(CORE_ADDR pc) |
| 389 | { |
| 390 | unsigned long inst ; |
| 391 | int op ; |
| 392 | inst = mips_fetch_instruction(pc) ; |
| 393 | if ((inst & 0xe0000000) != 0) /* Not a special, junp or branch instruction */ |
| 394 | { if ((inst >> 27) == 5) /* BEQL BNEZ BLEZL BGTZE , bits 0101xx */ |
| 395 | { op = ((inst >> 25) & 0x03) ; |
| 396 | switch (op) |
| 397 | { |
| 398 | case 0 : goto equal_branch ; /* BEQL */ |
| 399 | case 1 : goto neq_branch ; /* BNEZ */ |
| 400 | case 2 : goto less_branch ; /* BLEZ */ |
| 401 | case 3 : goto greater_branch ; /* BGTZ */ |
| 402 | default : pc += 4 ; |
| 403 | } |
| 404 | } |
| 405 | else pc += 4 ; /* Not a branch, next instruction is easy */ |
| 406 | } |
| 407 | else |
| 408 | { /* This gets way messy */ |
| 409 | |
| 410 | /* Further subdivide into SPECIAL, REGIMM and other */ |
| 411 | switch (op = ((inst >> 26) & 0x07)) /* extract bits 28,27,26 */ |
| 412 | { |
| 413 | case 0 : /* SPECIAL */ |
| 414 | op = rtype_funct(inst) ; |
| 415 | switch (op) |
| 416 | { |
| 417 | case 8 : /* JR */ |
| 418 | case 9 : /* JALR */ |
| 419 | pc = read_register(rtype_rs(inst)) ; /* Set PC to that address */ |
| 420 | break ; |
| 421 | default: pc += 4 ; |
| 422 | } |
| 423 | |
| 424 | break ; /* end special */ |
| 425 | case 1 : /* REGIMM */ |
| 426 | { |
| 427 | op = jtype_op(inst) ; /* branch condition */ |
| 428 | switch (jtype_op(inst)) |
| 429 | { |
| 430 | case 0 : /* BLTZ */ |
| 431 | case 2 : /* BLTXL */ |
| 432 | case 16 : /* BLTZALL */ |
| 433 | case 18 : /* BLTZALL */ |
| 434 | less_branch: |
| 435 | if (read_register(itype_rs(inst)) < 0) |
| 436 | pc += mips32_relative_offset(inst) + 4 ; |
| 437 | else pc += 8 ; /* after the delay slot */ |
| 438 | break ; |
| 439 | case 1 : /* GEZ */ |
| 440 | case 3 : /* BGEZL */ |
| 441 | case 17 : /* BGEZAL */ |
| 442 | case 19 : /* BGEZALL */ |
| 443 | greater_equal_branch: |
| 444 | if (read_register(itype_rs(inst)) >= 0) |
| 445 | pc += mips32_relative_offset(inst) + 4 ; |
| 446 | else pc += 8 ; /* after the delay slot */ |
| 447 | break ; |
| 448 | /* All of the other intructions in the REGIMM catagory */ |
| 449 | default: pc += 4 ; |
| 450 | } |
| 451 | } |
| 452 | break ; /* end REGIMM */ |
| 453 | case 2 : /* J */ |
| 454 | case 3 : /* JAL */ |
| 455 | { unsigned long reg ; |
| 456 | reg = jtype_target(inst) << 2 ; |
| 457 | pc = reg + ((pc+4) & 0xf0000000) ; |
| 458 | /* Whats this mysterious 0xf000000 adjustment ??? */ |
| 459 | } |
| 460 | break ; |
| 461 | /* FIXME case JALX :*/ |
| 462 | { unsigned long reg ; |
| 463 | reg = jtype_target(inst) << 2 ; |
| 464 | pc = reg + ((pc+4) & 0xf0000000) + 1 ; /* yes, +1 */ |
| 465 | /* Add 1 to indicate 16 bit mode - Invert ISA mode */ |
| 466 | } |
| 467 | break ; /* The new PC will be alternate mode */ |
| 468 | case 4 : /* BEQ , BEQL */ |
| 469 | equal_branch : |
| 470 | if (read_register(itype_rs(inst)) == |
| 471 | read_register(itype_rt(inst))) |
| 472 | pc += mips32_relative_offset(inst) + 4 ; |
| 473 | else pc += 8 ; |
| 474 | break ; |
| 475 | case 5 : /* BNE , BNEL */ |
| 476 | neq_branch : |
| 477 | if (read_register(itype_rs(inst)) != |
| 478 | read_register(itype_rs(inst))) |
| 479 | pc += mips32_relative_offset(inst) + 4 ; |
| 480 | else pc += 8 ; |
| 481 | break ; |
| 482 | case 6 : /* BLEZ , BLEZL */ |
| 483 | less_zero_branch: |
| 484 | if (read_register(itype_rs(inst) <= 0)) |
| 485 | pc += mips32_relative_offset(inst) + 4 ; |
| 486 | else pc += 8 ; |
| 487 | break ; |
| 488 | case 7 : |
| 489 | greater_branch : /* BGTZ BGTZL */ |
| 490 | if (read_register(itype_rs(inst) > 0)) |
| 491 | pc += mips32_relative_offset(inst) + 4 ; |
| 492 | else pc += 8 ; |
| 493 | break ; |
| 494 | default : pc += 8 ; |
| 495 | } /* switch */ |
| 496 | } /* else */ |
| 497 | return pc ; |
| 498 | } /* mips32_next_pc */ |
| 499 | |
| 500 | /* Decoding the next place to set a breakpoint is irregular for the |
| 501 | mips 16 variant, but fortunatly, there fewer instructions. We have to cope |
| 502 | ith extensions for 16 bit instructions and a pair of actual 32 bit instructions. |
| 503 | We dont want to set a single step instruction on the extend instruction |
| 504 | either. |
| 505 | */ |
| 506 | |
| 507 | /* Lots of mips16 instruction formats */ |
| 508 | /* Predicting jumps requires itype,ritype,i8type |
| 509 | and their extensions extItype,extritype,extI8type |
| 510 | */ |
| 511 | enum mips16_inst_fmts |
| 512 | { |
| 513 | itype, /* 0 immediate 5,10 */ |
| 514 | ritype, /* 1 5,3,8 */ |
| 515 | rrtype, /* 2 5,3,3,5 */ |
| 516 | rritype, /* 3 5,3,3,5 */ |
| 517 | rrrtype, /* 4 5,3,3,3,2 */ |
| 518 | rriatype, /* 5 5,3,3,1,4 */ |
| 519 | shifttype, /* 6 5,3,3,3,2 */ |
| 520 | i8type, /* 7 5,3,8 */ |
| 521 | i8movtype, /* 8 5,3,3,5 */ |
| 522 | i8mov32rtype, /* 9 5,3,5,3 */ |
| 523 | i64type, /* 10 5,3,8 */ |
| 524 | ri64type, /* 11 5,3,3,5 */ |
| 525 | jalxtype, /* 12 5,1,5,5,16 - a 32 bit instruction */ |
| 526 | exiItype, /* 13 5,6,5,5,1,1,1,1,1,1,5 */ |
| 527 | extRitype, /* 14 5,6,5,5,3,1,1,1,5 */ |
| 528 | extRRItype, /* 15 5,5,5,5,3,3,5 */ |
| 529 | extRRIAtype, /* 16 5,7,4,5,3,3,1,4 */ |
| 530 | EXTshifttype, /* 17 5,5,1,1,1,1,1,1,5,3,3,1,1,1,2 */ |
| 531 | extI8type, /* 18 5,6,5,5,3,1,1,1,5 */ |
| 532 | extI64type, /* 19 5,6,5,5,3,1,1,1,5 */ |
| 533 | extRi64type, /* 20 5,6,5,5,3,3,5 */ |
| 534 | extshift64type /* 21 5,5,1,1,1,1,1,1,5,1,1,1,3,5 */ |
| 535 | } ; |
| 536 | /* I am heaping all the fields of the formats into one structure and then, |
| 537 | only the fields which are involved in instruction extension */ |
| 538 | struct upk_mips16 |
| 539 | { |
| 540 | unsigned short inst ; |
| 541 | enum mips16_inst_fmts fmt ; |
| 542 | unsigned long offset ; |
| 543 | unsigned int regx ; /* Function in i8 type */ |
| 544 | unsigned int regy ; |
| 545 | } ; |
| 546 | |
| 547 | |
| 548 | |
| 549 | static void print_unpack(char * comment, |
| 550 | struct upk_mips16 * u) |
| 551 | { |
| 552 | printf("%s %04x ,f(%d) off(%08x) (x(%x) y(%x)\n", |
| 553 | comment,u->inst,u->fmt,u->offset,u->regx,u->regy) ; |
| 554 | } |
| 555 | |
| 556 | /* The EXT-I, EXT-ri nad EXT-I8 instructions all have the same |
| 557 | format for the bits which make up the immediatate extension. |
| 558 | */ |
| 559 | static unsigned long |
| 560 | extended_offset(unsigned long extension) |
| 561 | { |
| 562 | unsigned long value ; |
| 563 | value = (extension >> 21) & 0x3f ; /* * extract 15:11 */ |
| 564 | value = value << 6 ; |
| 565 | value |= (extension >> 16) & 0x1f ; /* extrace 10:5 */ |
| 566 | value = value << 5 ; |
| 567 | value |= extension & 0x01f ; /* extract 4:0 */ |
| 568 | return value ; |
| 569 | } |
| 570 | |
| 571 | /* Only call this function if you know that this is an extendable |
| 572 | instruction, It wont malfunction, but why make excess remote memory references? |
| 573 | If the immediate operands get sign extended or somthing, do it after |
| 574 | the extension is performed. |
| 575 | */ |
| 576 | /* FIXME: Every one of these cases needs to worry about sign extension |
| 577 | when the offset is to be used in relative addressing */ |
| 578 | |
| 579 | |
| 580 | static unsigned short fetch_mips_16(CORE_ADDR pc) |
| 581 | { |
| 582 | char buf[8] ; |
| 583 | pc &= 0xfffffffe ; /* clear the low order bit */ |
| 584 | target_read_memory(pc,buf,2) ; |
| 585 | return extract_unsigned_integer(buf,2) ; |
| 586 | } |
| 587 | |
| 588 | static void |
| 589 | unpack_mips16(CORE_ADDR pc, |
| 590 | struct upk_mips16 * upk) |
| 591 | { |
| 592 | CORE_ADDR extpc ; |
| 593 | unsigned long extension ; |
| 594 | int extended ; |
| 595 | extpc = (pc - 4) & ~0x01 ; /* Extensions are 32 bit instructions */ |
| 596 | /* Decrement to previous address and loose the 16bit mode flag */ |
| 597 | /* return if the instruction was extendable, but not actually extended */ |
| 598 | extended = ((mips32_op(extension) == 30) ? 1 : 0) ; |
| 599 | if (extended) { extension = mips_fetch_instruction(extpc) ;} |
| 600 | switch (upk->fmt) |
| 601 | { |
| 602 | case itype : |
| 603 | { |
| 604 | unsigned long value ; |
| 605 | if (extended) |
| 606 | { value = extended_offset(extension) ; |
| 607 | value = value << 11 ; /* rom for the original value */ |
| 608 | value |= upk->inst & 0x7ff ; /* eleven bits from instruction */ |
| 609 | } |
| 610 | else |
| 611 | { value = upk->inst & 0x7ff ; |
| 612 | /* FIXME : Consider sign extension */ |
| 613 | } |
| 614 | upk->offset = value ; |
| 615 | } |
| 616 | break ; |
| 617 | case ritype : |
| 618 | case i8type : |
| 619 | { /* A register identifier and an offset */ |
| 620 | /* Most of the fields are the same as I type but the |
| 621 | immediate value is of a different length */ |
| 622 | unsigned long value ; |
| 623 | if (extended) |
| 624 | { |
| 625 | value = extended_offset(extension) ; |
| 626 | value = value << 8 ; /* from the original instruction */ |
| 627 | value |= upk->inst & 0xff ; /* eleven bits from instruction */ |
| 628 | upk->regx = (extension >> 8) & 0x07 ; /* or i8 funct */ |
| 629 | if (value & 0x4000) /* test the sign bit , bit 26 */ |
| 630 | { value &= ~ 0x3fff ; /* remove the sign bit */ |
| 631 | value = -value ; |
| 632 | } |
| 633 | } |
| 634 | else { |
| 635 | value = upk->inst & 0xff ; /* 8 bits */ |
| 636 | upk->regx = (upk->inst >> 8) & 0x07 ; /* or i8 funct */ |
| 637 | /* FIXME: Do sign extension , this format needs it */ |
| 638 | if (value & 0x80) /* THIS CONFUSES ME */ |
| 639 | { value &= 0xef ; /* remove the sign bit */ |
| 640 | value = -value ; |
| 641 | } |
| 642 | |
| 643 | } |
| 644 | upk->offset = value ; |
| 645 | break ; |
| 646 | } |
| 647 | case jalxtype : |
| 648 | { |
| 649 | unsigned long value ; |
| 650 | unsigned short nexthalf ; |
| 651 | value = ((upk->inst & 0x1f) << 5) | ((upk->inst >> 5) & 0x1f) ; |
| 652 | value = value << 16 ; |
| 653 | nexthalf = mips_fetch_instruction(pc+2) ; /* low bit still set */ |
| 654 | value |= nexthalf ; |
| 655 | upk->offset = value ; |
| 656 | break ; |
| 657 | } |
| 658 | default: |
| 659 | printf_filtered("Decoding unimplemented instruction format type\n") ; |
| 660 | break ; |
| 661 | } |
| 662 | /* print_unpack("UPK",upk) ; */ |
| 663 | } |
| 664 | |
| 665 | |
| 666 | #define mips16_op(x) (x >> 11) |
| 667 | |
| 668 | /* This is a map of the opcodes which ae known to perform branches */ |
| 669 | static unsigned char map16[32] = |
| 670 | { 0,0,1,1,1,1,0,0, |
| 671 | 0,0,0,0,1,0,0,0, |
| 672 | 0,0,0,0,0,0,0,0, |
| 673 | 0,0,0,0,0,1,1,0 |
| 674 | } ; |
| 675 | |
| 676 | static CORE_ADDR add_offset_16(CORE_ADDR pc, int offset) |
| 677 | { |
| 678 | return ((offset << 2) | ((pc + 2) & (0xf0000000))) ; |
| 679 | |
| 680 | } |
| 681 | |
| 682 | |
| 683 | |
| 684 | static struct upk_mips16 upk ; |
| 685 | |
| 686 | CORE_ADDR mips16_next_pc(CORE_ADDR pc) |
| 687 | { |
| 688 | int op ; |
| 689 | t_inst inst ; |
| 690 | /* inst = mips_fetch_instruction(pc) ; - This doesnt always work */ |
| 691 | inst = fetch_mips_16(pc) ; |
| 692 | upk.inst = inst ; |
| 693 | op = mips16_op(upk.inst) ; |
| 694 | if (map16[op]) |
| 695 | { |
| 696 | int reg ; |
| 697 | switch (op) |
| 698 | { |
| 699 | case 2 : /* Branch */ |
| 700 | upk.fmt = itype ; |
| 701 | unpack_mips16(pc,&upk) ; |
| 702 | { long offset ; |
| 703 | offset = upk.offset ; |
| 704 | if (offset & 0x800) |
| 705 | { offset &= 0xeff ; |
| 706 | offset = - offset ; |
| 707 | } |
| 708 | pc += (offset << 1) + 2 ; |
| 709 | } |
| 710 | break ; |
| 711 | case 3 : /* JAL , JALX - Watch out, these are 32 bit instruction*/ |
| 712 | upk.fmt = jalxtype ; |
| 713 | unpack_mips16(pc,&upk) ; |
| 714 | pc = add_offset_16(pc,upk.offset) ; |
| 715 | if ((upk.inst >> 10) & 0x01) /* Exchange mode */ |
| 716 | pc = pc & ~ 0x01 ; /* Clear low bit, indicate 32 bit mode */ |
| 717 | else pc |= 0x01 ; |
| 718 | break ; |
| 719 | case 4 : /* beqz */ |
| 720 | upk.fmt = ritype ; |
| 721 | unpack_mips16(pc,&upk) ; |
| 722 | reg = read_register(upk.regx) ; |
| 723 | if (reg == 0) |
| 724 | pc += (upk.offset << 1) + 2 ; |
| 725 | else pc += 2 ; |
| 726 | break ; |
| 727 | case 5 : /* bnez */ |
| 728 | upk.fmt = ritype ; |
| 729 | unpack_mips16(pc,&upk) ; |
| 730 | reg = read_register(upk.regx) ; |
| 731 | if (reg != 0) |
| 732 | pc += (upk.offset << 1) + 2 ; |
| 733 | else pc += 2 ; |
| 734 | break ; |
| 735 | case 12 : /* I8 Formats btez btnez */ |
| 736 | upk.fmt = i8type ; |
| 737 | unpack_mips16(pc,&upk) ; |
| 738 | /* upk.regx contains the opcode */ |
| 739 | reg = read_register(24) ; /* Test register is 24 */ |
| 740 | if (((upk.regx == 0) && (reg == 0)) /* BTEZ */ |
| 741 | || ((upk.regx == 1 ) && (reg != 0))) /* BTNEZ */ |
| 742 | /* pc = add_offset_16(pc,upk.offset) ; */ |
| 743 | pc += (upk.offset << 1) + 2 ; |
| 744 | else pc += 2 ; |
| 745 | break ; |
| 746 | case 29 : /* RR Formats JR, JALR, JALR-RA */ |
| 747 | upk.fmt = rrtype ; |
| 748 | op = upk.inst & 0x1f ; |
| 749 | if (op == 0) |
| 750 | { |
| 751 | upk.regx = (upk.inst >> 8) & 0x07 ; |
| 752 | upk.regy = (upk.inst >> 5) & 0x07 ; |
| 753 | switch (upk.regy) |
| 754 | { |
| 755 | case 0 : reg = upk.regx ; break ; |
| 756 | case 1 : reg = 31 ; break ; /* Function return instruction*/ |
| 757 | case 2 : reg = upk.regx ; break ; |
| 758 | default: reg = 31 ; break ; /* BOGUS Guess */ |
| 759 | } |
| 760 | pc = read_register(reg) ; |
| 761 | } |
| 762 | else pc += 2 ; |
| 763 | break ; |
| 764 | case 30 : /* This is an extend instruction */ |
| 765 | pc += 4 ; /* Dont be setting breakpints on the second half */ |
| 766 | break ; |
| 767 | default : |
| 768 | printf("Filtered - next PC probably incorrrect due to jump inst\n"); |
| 769 | pc += 2 ; |
| 770 | break ; |
| 771 | } |
| 772 | } |
| 773 | else pc+= 2 ; /* just a good old instruction */ |
| 774 | /* See if we CAN actually break on the next instruction */ |
| 775 | /* printf("NXTm16PC %08x\n",(unsigned long)pc) ; */ |
| 776 | return pc ; |
| 777 | } /* mips16_next_pc */ |
| 778 | |
| 779 | /* The mips_next_pc function supports single_tep when the remote target monitor or |
| 780 | stub is not developed enough to so a single_step. |
| 781 | It works by decoding the current instruction and predicting where a branch |
| 782 | will go. This isnt hard because all the data is available. |
| 783 | The MIPS32 and MIPS16 variants are quite different |
| 784 | */ |
| 785 | CORE_ADDR mips_next_pc(CORE_ADDR pc) |
| 786 | { |
| 787 | t_inst inst ; |
| 788 | /* inst = mips_fetch_instruction(pc) ; */ |
| 789 | /* if (pc_is_mips16) <----- This is failing */ |
| 790 | if (pc & 0x01) |
| 791 | return mips16_next_pc(pc) ; |
| 792 | else return mips32_next_pc(pc) ; |
| 793 | } /* mips_next_pc */ |
| 794 | |
| 795 | /* Guaranteed to set fci->saved_regs to some values (it never leaves it |
| 796 | NULL). */ |
| 797 | |
| 798 | void |
| 799 | mips_find_saved_regs (fci) |
| 800 | struct frame_info *fci; |
| 801 | { |
| 802 | int ireg; |
| 803 | CORE_ADDR reg_position; |
| 804 | /* r0 bit means kernel trap */ |
| 805 | int kernel_trap; |
| 806 | /* What registers have been saved? Bitmasks. */ |
| 807 | unsigned long gen_mask, float_mask; |
| 808 | mips_extra_func_info_t proc_desc; |
| 809 | t_inst inst; |
| 810 | |
| 811 | fci->saved_regs = (struct frame_saved_regs *) |
| 812 | obstack_alloc (&frame_cache_obstack, sizeof(struct frame_saved_regs)); |
| 813 | memset (fci->saved_regs, 0, sizeof (struct frame_saved_regs)); |
| 814 | |
| 815 | /* If it is the frame for sigtramp, the saved registers are located |
| 816 | in a sigcontext structure somewhere on the stack. |
| 817 | If the stack layout for sigtramp changes we might have to change these |
| 818 | constants and the companion fixup_sigtramp in mdebugread.c */ |
| 819 | #ifndef SIGFRAME_BASE |
| 820 | /* To satisfy alignment restrictions, sigcontext is located 4 bytes |
| 821 | above the sigtramp frame. */ |
| 822 | #define SIGFRAME_BASE MIPS_REGSIZE |
| 823 | /* FIXME! Are these correct?? */ |
| 824 | #define SIGFRAME_PC_OFF (SIGFRAME_BASE + 2 * MIPS_REGSIZE) |
| 825 | #define SIGFRAME_REGSAVE_OFF (SIGFRAME_BASE + 3 * MIPS_REGSIZE) |
| 826 | #define SIGFRAME_FPREGSAVE_OFF \ |
| 827 | (SIGFRAME_REGSAVE_OFF + MIPS_NUMREGS * MIPS_REGSIZE + 3 * MIPS_REGSIZE) |
| 828 | #endif |
| 829 | #ifndef SIGFRAME_REG_SIZE |
| 830 | /* FIXME! Is this correct?? */ |
| 831 | #define SIGFRAME_REG_SIZE MIPS_REGSIZE |
| 832 | #endif |
| 833 | if (fci->signal_handler_caller) |
| 834 | { |
| 835 | for (ireg = 0; ireg < MIPS_NUMREGS; ireg++) |
| 836 | { |
| 837 | reg_position = fci->frame + SIGFRAME_REGSAVE_OFF |
| 838 | + ireg * SIGFRAME_REG_SIZE; |
| 839 | fci->saved_regs->regs[ireg] = reg_position; |
| 840 | } |
| 841 | for (ireg = 0; ireg < MIPS_NUMREGS; ireg++) |
| 842 | { |
| 843 | reg_position = fci->frame + SIGFRAME_FPREGSAVE_OFF |
| 844 | + ireg * SIGFRAME_REG_SIZE; |
| 845 | fci->saved_regs->regs[FP0_REGNUM + ireg] = reg_position; |
| 846 | } |
| 847 | fci->saved_regs->regs[PC_REGNUM] = fci->frame + SIGFRAME_PC_OFF; |
| 848 | return; |
| 849 | } |
| 850 | |
| 851 | proc_desc = fci->proc_desc; |
| 852 | if (proc_desc == NULL) |
| 853 | /* I'm not sure how/whether this can happen. Normally when we can't |
| 854 | find a proc_desc, we "synthesize" one using heuristic_proc_desc |
| 855 | and set the saved_regs right away. */ |
| 856 | return; |
| 857 | |
| 858 | kernel_trap = PROC_REG_MASK(proc_desc) & 1; |
| 859 | gen_mask = kernel_trap ? 0xFFFFFFFF : PROC_REG_MASK(proc_desc); |
| 860 | float_mask = kernel_trap ? 0xFFFFFFFF : PROC_FREG_MASK(proc_desc); |
| 861 | |
| 862 | if (/* In any frame other than the innermost or a frame interrupted by |
| 863 | a signal, we assume that all registers have been saved. |
| 864 | This assumes that all register saves in a function happen before |
| 865 | the first function call. */ |
| 866 | (fci->next == NULL || fci->next->signal_handler_caller) |
| 867 | |
| 868 | /* In a dummy frame we know exactly where things are saved. */ |
| 869 | && !PROC_DESC_IS_DUMMY (proc_desc) |
| 870 | |
| 871 | /* Don't bother unless we are inside a function prologue. Outside the |
| 872 | prologue, we know where everything is. */ |
| 873 | |
| 874 | && in_prologue (fci->pc, PROC_LOW_ADDR (proc_desc)) |
| 875 | |
| 876 | /* Not sure exactly what kernel_trap means, but if it means |
| 877 | the kernel saves the registers without a prologue doing it, |
| 878 | we better not examine the prologue to see whether registers |
| 879 | have been saved yet. */ |
| 880 | && !kernel_trap) |
| 881 | { |
| 882 | /* We need to figure out whether the registers that the proc_desc |
| 883 | claims are saved have been saved yet. */ |
| 884 | |
| 885 | CORE_ADDR addr; |
| 886 | |
| 887 | /* Bitmasks; set if we have found a save for the register. */ |
| 888 | unsigned long gen_save_found = 0; |
| 889 | unsigned long float_save_found = 0; |
| 890 | int instlen; |
| 891 | |
| 892 | /* If the address is odd, assume this is MIPS16 code. */ |
| 893 | addr = PROC_LOW_ADDR (proc_desc); |
| 894 | instlen = pc_is_mips16 (addr) ? MIPS16_INSTLEN : MIPS_INSTLEN; |
| 895 | |
| 896 | /* Scan through this function's instructions preceding the current |
| 897 | PC, and look for those that save registers. */ |
| 898 | while (addr < fci->pc) |
| 899 | { |
| 900 | inst = mips_fetch_instruction (addr); |
| 901 | if (pc_is_mips16 (addr)) |
| 902 | mips16_decode_reg_save (inst, &gen_save_found); |
| 903 | else |
| 904 | mips32_decode_reg_save (inst, &gen_save_found, &float_save_found); |
| 905 | addr += instlen; |
| 906 | } |
| 907 | gen_mask = gen_save_found; |
| 908 | float_mask = float_save_found; |
| 909 | } |
| 910 | |
| 911 | /* Fill in the offsets for the registers which gen_mask says |
| 912 | were saved. */ |
| 913 | reg_position = fci->frame + PROC_REG_OFFSET (proc_desc); |
| 914 | for (ireg= MIPS_NUMREGS-1; gen_mask; --ireg, gen_mask <<= 1) |
| 915 | if (gen_mask & 0x80000000) |
| 916 | { |
| 917 | fci->saved_regs->regs[ireg] = reg_position; |
| 918 | reg_position -= MIPS_REGSIZE; |
| 919 | } |
| 920 | |
| 921 | /* The MIPS16 entry instruction saves $s0 and $s1 in the reverse order |
| 922 | of that normally used by gcc. Therefore, we have to fetch the first |
| 923 | instruction of the function, and if it's an entry instruction that |
| 924 | saves $s0 or $s1, correct their saved addresses. */ |
| 925 | if (pc_is_mips16 (PROC_LOW_ADDR (proc_desc))) |
| 926 | { |
| 927 | inst = mips_fetch_instruction (PROC_LOW_ADDR (proc_desc)); |
| 928 | if ((inst & 0xf81f) == 0xe809 && (inst & 0x700) != 0x700) /* entry */ |
| 929 | { |
| 930 | int reg; |
| 931 | int sreg_count = (inst >> 6) & 3; |
| 932 | |
| 933 | /* Check if the ra register was pushed on the stack. */ |
| 934 | reg_position = fci->frame + PROC_REG_OFFSET (proc_desc); |
| 935 | if (inst & 0x20) |
| 936 | reg_position -= MIPS_REGSIZE; |
| 937 | |
| 938 | /* Check if the s0 and s1 registers were pushed on the stack. */ |
| 939 | for (reg = 16; reg < sreg_count+16; reg++) |
| 940 | { |
| 941 | fci->saved_regs->regs[reg] = reg_position; |
| 942 | reg_position -= MIPS_REGSIZE; |
| 943 | } |
| 944 | } |
| 945 | } |
| 946 | |
| 947 | /* Fill in the offsets for the registers which float_mask says |
| 948 | were saved. */ |
| 949 | reg_position = fci->frame + PROC_FREG_OFFSET (proc_desc); |
| 950 | |
| 951 | /* The freg_offset points to where the first *double* register |
| 952 | is saved. So skip to the high-order word. */ |
| 953 | if (! GDB_TARGET_IS_MIPS64) |
| 954 | reg_position += MIPS_REGSIZE; |
| 955 | |
| 956 | /* Fill in the offsets for the float registers which float_mask says |
| 957 | were saved. */ |
| 958 | for (ireg = MIPS_NUMREGS-1; float_mask; --ireg, float_mask <<= 1) |
| 959 | if (float_mask & 0x80000000) |
| 960 | { |
| 961 | fci->saved_regs->regs[FP0_REGNUM+ireg] = reg_position; |
| 962 | reg_position -= MIPS_REGSIZE; |
| 963 | } |
| 964 | |
| 965 | fci->saved_regs->regs[PC_REGNUM] = fci->saved_regs->regs[RA_REGNUM]; |
| 966 | } |
| 967 | |
| 968 | static CORE_ADDR |
| 969 | read_next_frame_reg(fi, regno) |
| 970 | struct frame_info *fi; |
| 971 | int regno; |
| 972 | { |
| 973 | for (; fi; fi = fi->next) |
| 974 | { |
| 975 | /* We have to get the saved sp from the sigcontext |
| 976 | if it is a signal handler frame. */ |
| 977 | if (regno == SP_REGNUM && !fi->signal_handler_caller) |
| 978 | return fi->frame; |
| 979 | else |
| 980 | { |
| 981 | if (fi->saved_regs == NULL) |
| 982 | mips_find_saved_regs (fi); |
| 983 | if (fi->saved_regs->regs[regno]) |
| 984 | return read_memory_integer(fi->saved_regs->regs[regno], MIPS_REGSIZE); |
| 985 | } |
| 986 | } |
| 987 | return read_register (regno); |
| 988 | } |
| 989 | |
| 990 | /* mips_addr_bits_remove - remove useless address bits */ |
| 991 | |
| 992 | CORE_ADDR |
| 993 | mips_addr_bits_remove (addr) |
| 994 | CORE_ADDR addr; |
| 995 | { |
| 996 | #if GDB_TARGET_IS_MIPS64 |
| 997 | if ((addr >> 32 == (CORE_ADDR)0xffffffff) |
| 998 | && (strcmp (target_shortname,"pmon")==0 |
| 999 | || strcmp (target_shortname,"ddb")==0 |
| 1000 | || strcmp (target_shortname,"sim")==0)) |
| 1001 | { |
| 1002 | /* This hack is a work-around for existing boards using PMON, |
| 1003 | the simulator, and any other 64-bit targets that doesn't have |
| 1004 | true 64-bit addressing. On these targets, the upper 32 bits |
| 1005 | of addresses are ignored by the hardware. Thus, the PC or SP |
| 1006 | are likely to have been sign extended to all 1s by instruction |
| 1007 | sequences that load 32-bit addresses. For example, a typical |
| 1008 | piece of code that loads an address is this: |
| 1009 | lui $r2, <upper 16 bits> |
| 1010 | ori $r2, <lower 16 bits> |
| 1011 | But the lui sign-extends the value such that the upper 32 bits |
| 1012 | may be all 1s. The workaround is simply to mask off these bits. |
| 1013 | In the future, gcc may be changed to support true 64-bit |
| 1014 | addressing, and this masking will have to be disabled. */ |
| 1015 | addr &= (CORE_ADDR)0xffffffff; |
| 1016 | } |
| 1017 | #else |
| 1018 | /* Even when GDB is configured for some 32-bit targets (e.g. mips-elf), |
| 1019 | BFD is configured to handle 64-bit targets, so CORE_ADDR is 64 bits. |
| 1020 | So we still have to mask off useless bits from addresses. */ |
| 1021 | addr &= (CORE_ADDR)0xffffffff; |
| 1022 | #endif |
| 1023 | |
| 1024 | return addr; |
| 1025 | } |
| 1026 | |
| 1027 | void |
| 1028 | mips_init_frame_pc_first (fromleaf, prev) |
| 1029 | int fromleaf; |
| 1030 | struct frame_info *prev; |
| 1031 | { |
| 1032 | CORE_ADDR pc, tmp; |
| 1033 | |
| 1034 | pc = ((fromleaf) ? SAVED_PC_AFTER_CALL (prev->next) : |
| 1035 | prev->next ? FRAME_SAVED_PC (prev->next) : read_pc ()); |
| 1036 | tmp = mips_skip_stub (pc); |
| 1037 | prev->pc = tmp ? tmp : pc; |
| 1038 | } |
| 1039 | |
| 1040 | |
| 1041 | CORE_ADDR |
| 1042 | mips_frame_saved_pc(frame) |
| 1043 | struct frame_info *frame; |
| 1044 | { |
| 1045 | CORE_ADDR saved_pc; |
| 1046 | mips_extra_func_info_t proc_desc = frame->proc_desc; |
| 1047 | /* We have to get the saved pc from the sigcontext |
| 1048 | if it is a signal handler frame. */ |
| 1049 | int pcreg = frame->signal_handler_caller ? PC_REGNUM |
| 1050 | : (proc_desc ? PROC_PC_REG(proc_desc) : RA_REGNUM); |
| 1051 | |
| 1052 | if (proc_desc && PROC_DESC_IS_DUMMY(proc_desc)) |
| 1053 | saved_pc = read_memory_integer(frame->frame - MIPS_REGSIZE, MIPS_REGSIZE); |
| 1054 | else |
| 1055 | saved_pc = read_next_frame_reg(frame, pcreg); |
| 1056 | |
| 1057 | return ADDR_BITS_REMOVE (saved_pc); |
| 1058 | } |
| 1059 | |
| 1060 | static struct mips_extra_func_info temp_proc_desc; |
| 1061 | static struct frame_saved_regs temp_saved_regs; |
| 1062 | |
| 1063 | /* Set a register's saved stack address in temp_saved_regs. If an address |
| 1064 | has already been set for this register, do nothing; this way we will |
| 1065 | only recognize the first save of a given register in a function prologue. |
| 1066 | This is a helper function for mips{16,32}_heuristic_proc_desc. */ |
| 1067 | |
| 1068 | static void |
| 1069 | set_reg_offset (regno, offset) |
| 1070 | int regno; |
| 1071 | CORE_ADDR offset; |
| 1072 | { |
| 1073 | if (temp_saved_regs.regs[regno] == 0) |
| 1074 | temp_saved_regs.regs[regno] = offset; |
| 1075 | } |
| 1076 | |
| 1077 | |
| 1078 | /* This fencepost looks highly suspicious to me. Removing it also |
| 1079 | seems suspicious as it could affect remote debugging across serial |
| 1080 | lines. */ |
| 1081 | |
| 1082 | static CORE_ADDR |
| 1083 | heuristic_proc_start(pc) |
| 1084 | CORE_ADDR pc; |
| 1085 | { |
| 1086 | CORE_ADDR start_pc; |
| 1087 | CORE_ADDR fence; |
| 1088 | int instlen; |
| 1089 | int seen_adjsp = 0; |
| 1090 | |
| 1091 | pc = ADDR_BITS_REMOVE (pc); |
| 1092 | start_pc = pc; |
| 1093 | fence = start_pc - heuristic_fence_post; |
| 1094 | if (start_pc == 0) return 0; |
| 1095 | |
| 1096 | if (heuristic_fence_post == UINT_MAX |
| 1097 | || fence < VM_MIN_ADDRESS) |
| 1098 | fence = VM_MIN_ADDRESS; |
| 1099 | |
| 1100 | instlen = pc_is_mips16 (pc) ? MIPS16_INSTLEN : MIPS_INSTLEN; |
| 1101 | |
| 1102 | /* search back for previous return */ |
| 1103 | for (start_pc -= instlen; ; start_pc -= instlen) |
| 1104 | if (start_pc < fence) |
| 1105 | { |
| 1106 | /* It's not clear to me why we reach this point when |
| 1107 | stop_soon_quietly, but with this test, at least we |
| 1108 | don't print out warnings for every child forked (eg, on |
| 1109 | decstation). 22apr93 rich@cygnus.com. */ |
| 1110 | if (!stop_soon_quietly) |
| 1111 | { |
| 1112 | static int blurb_printed = 0; |
| 1113 | |
| 1114 | if (fence == VM_MIN_ADDRESS) |
| 1115 | warning("Hit beginning of text section without finding"); |
| 1116 | else |
| 1117 | warning("Hit heuristic-fence-post without finding"); |
| 1118 | |
| 1119 | warning("enclosing function for address 0x%s", paddr_nz (pc)); |
| 1120 | if (!blurb_printed) |
| 1121 | { |
| 1122 | printf_filtered ("\ |
| 1123 | This warning occurs if you are debugging a function without any symbols\n\ |
| 1124 | (for example, in a stripped executable). In that case, you may wish to\n\ |
| 1125 | increase the size of the search with the `set heuristic-fence-post' command.\n\ |
| 1126 | \n\ |
| 1127 | Otherwise, you told GDB there was a function where there isn't one, or\n\ |
| 1128 | (more likely) you have encountered a bug in GDB.\n"); |
| 1129 | blurb_printed = 1; |
| 1130 | } |
| 1131 | } |
| 1132 | |
| 1133 | return 0; |
| 1134 | } |
| 1135 | else if (pc_is_mips16 (start_pc)) |
| 1136 | { |
| 1137 | unsigned short inst; |
| 1138 | |
| 1139 | /* On MIPS16, any one of the following is likely to be the |
| 1140 | start of a function: |
| 1141 | entry |
| 1142 | addiu sp,-n |
| 1143 | daddiu sp,-n |
| 1144 | extend -n followed by 'addiu sp,+n' or 'daddiu sp,+n' */ |
| 1145 | inst = mips_fetch_instruction (start_pc); |
| 1146 | if (((inst & 0xf81f) == 0xe809 && (inst & 0x700) != 0x700) /* entry */ |
| 1147 | || (inst & 0xff80) == 0x6380 /* addiu sp,-n */ |
| 1148 | || (inst & 0xff80) == 0xfb80 /* daddiu sp,-n */ |
| 1149 | || ((inst & 0xf810) == 0xf010 && seen_adjsp)) /* extend -n */ |
| 1150 | break; |
| 1151 | else if ((inst & 0xff00) == 0x6300 /* addiu sp */ |
| 1152 | || (inst & 0xff00) == 0xfb00) /* daddiu sp */ |
| 1153 | seen_adjsp = 1; |
| 1154 | else |
| 1155 | seen_adjsp = 0; |
| 1156 | } |
| 1157 | else if (ABOUT_TO_RETURN(start_pc)) |
| 1158 | { |
| 1159 | start_pc += 2 * MIPS_INSTLEN; /* skip return, and its delay slot */ |
| 1160 | break; |
| 1161 | } |
| 1162 | |
| 1163 | #if 0 |
| 1164 | /* skip nops (usually 1) 0 - is this */ |
| 1165 | while (start_pc < pc && read_memory_integer (start_pc, MIPS_INSTLEN) == 0) |
| 1166 | start_pc += MIPS_INSTLEN; |
| 1167 | #endif |
| 1168 | return start_pc; |
| 1169 | } |
| 1170 | |
| 1171 | /* Fetch the immediate value from a MIPS16 instruction. |
| 1172 | If the previous instruction was an EXTEND, use it to extend |
| 1173 | the upper bits of the immediate value. This is a helper function |
| 1174 | for mips16_heuristic_proc_desc. */ |
| 1175 | |
| 1176 | static int |
| 1177 | mips16_get_imm (prev_inst, inst, nbits, scale, is_signed) |
| 1178 | unsigned short prev_inst; /* previous instruction */ |
| 1179 | unsigned short inst; /* current instruction */ |
| 1180 | int nbits; /* number of bits in imm field */ |
| 1181 | int scale; /* scale factor to be applied to imm */ |
| 1182 | int is_signed; /* is the imm field signed? */ |
| 1183 | { |
| 1184 | int offset; |
| 1185 | |
| 1186 | if ((prev_inst & 0xf800) == 0xf000) /* prev instruction was EXTEND? */ |
| 1187 | { |
| 1188 | offset = ((prev_inst & 0x1f) << 11) | (prev_inst & 0x7e0); |
| 1189 | if (offset & 0x8000) /* check for negative extend */ |
| 1190 | offset = 0 - (0x10000 - (offset & 0xffff)); |
| 1191 | return offset | (inst & 0x1f); |
| 1192 | } |
| 1193 | else |
| 1194 | { |
| 1195 | int max_imm = 1 << nbits; |
| 1196 | int mask = max_imm - 1; |
| 1197 | int sign_bit = max_imm >> 1; |
| 1198 | |
| 1199 | offset = inst & mask; |
| 1200 | if (is_signed && (offset & sign_bit)) |
| 1201 | offset = 0 - (max_imm - offset); |
| 1202 | return offset * scale; |
| 1203 | } |
| 1204 | } |
| 1205 | |
| 1206 | |
| 1207 | /* Fill in values in temp_proc_desc based on the MIPS16 instruction |
| 1208 | stream from start_pc to limit_pc. */ |
| 1209 | |
| 1210 | static void |
| 1211 | mips16_heuristic_proc_desc(start_pc, limit_pc, next_frame, sp) |
| 1212 | CORE_ADDR start_pc, limit_pc; |
| 1213 | struct frame_info *next_frame; |
| 1214 | CORE_ADDR sp; |
| 1215 | { |
| 1216 | CORE_ADDR cur_pc; |
| 1217 | CORE_ADDR frame_addr = 0; /* Value of $r17, used as frame pointer */ |
| 1218 | unsigned short prev_inst = 0; /* saved copy of previous instruction */ |
| 1219 | unsigned inst = 0; /* current instruction */ |
| 1220 | unsigned entry_inst = 0; /* the entry instruction */ |
| 1221 | int reg, offset; |
| 1222 | |
| 1223 | PROC_FRAME_OFFSET(&temp_proc_desc) = 0; /* size of stack frame */ |
| 1224 | PROC_FRAME_ADJUST(&temp_proc_desc) = 0; /* offset of FP from SP */ |
| 1225 | |
| 1226 | for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += MIPS16_INSTLEN) |
| 1227 | { |
| 1228 | /* Save the previous instruction. If it's an EXTEND, we'll extract |
| 1229 | the immediate offset extension from it in mips16_get_imm. */ |
| 1230 | prev_inst = inst; |
| 1231 | |
| 1232 | /* Fetch and decode the instruction. */ |
| 1233 | inst = (unsigned short) mips_fetch_instruction (cur_pc); |
| 1234 | if ((inst & 0xff00) == 0x6300 /* addiu sp */ |
| 1235 | || (inst & 0xff00) == 0xfb00) /* daddiu sp */ |
| 1236 | { |
| 1237 | offset = mips16_get_imm (prev_inst, inst, 8, 8, 1); |
| 1238 | if (offset < 0) /* negative stack adjustment? */ |
| 1239 | PROC_FRAME_OFFSET(&temp_proc_desc) -= offset; |
| 1240 | else |
| 1241 | /* Exit loop if a positive stack adjustment is found, which |
| 1242 | usually means that the stack cleanup code in the function |
| 1243 | epilogue is reached. */ |
| 1244 | break; |
| 1245 | } |
| 1246 | else if ((inst & 0xf800) == 0xd000) /* sw reg,n($sp) */ |
| 1247 | { |
| 1248 | offset = mips16_get_imm (prev_inst, inst, 8, 4, 0); |
| 1249 | reg = mips16_to_32_reg[(inst & 0x700) >> 8]; |
| 1250 | PROC_REG_MASK(&temp_proc_desc) |= (1 << reg); |
| 1251 | set_reg_offset (reg, sp + offset); |
| 1252 | } |
| 1253 | else if ((inst & 0xff00) == 0xf900) /* sd reg,n($sp) */ |
| 1254 | { |
| 1255 | offset = mips16_get_imm (prev_inst, inst, 5, 8, 0); |
| 1256 | reg = mips16_to_32_reg[(inst & 0xe0) >> 5]; |
| 1257 | PROC_REG_MASK(&temp_proc_desc) |= (1 << reg); |
| 1258 | set_reg_offset (reg, sp + offset); |
| 1259 | } |
| 1260 | else if ((inst & 0xff00) == 0x6200) /* sw $ra,n($sp) */ |
| 1261 | { |
| 1262 | offset = mips16_get_imm (prev_inst, inst, 8, 4, 0); |
| 1263 | PROC_REG_MASK(&temp_proc_desc) |= (1 << RA_REGNUM); |
| 1264 | set_reg_offset (RA_REGNUM, sp + offset); |
| 1265 | } |
| 1266 | else if ((inst & 0xff00) == 0xfa00) /* sd $ra,n($sp) */ |
| 1267 | { |
| 1268 | offset = mips16_get_imm (prev_inst, inst, 8, 8, 0); |
| 1269 | PROC_REG_MASK(&temp_proc_desc) |= (1 << RA_REGNUM); |
| 1270 | set_reg_offset (RA_REGNUM, sp + offset); |
| 1271 | } |
| 1272 | else if (inst == 0x673d) /* move $s1, $sp */ |
| 1273 | { |
| 1274 | frame_addr = sp; |
| 1275 | PROC_FRAME_REG (&temp_proc_desc) = 17; |
| 1276 | } |
| 1277 | else if ((inst & 0xff00) == 0x0100) /* addiu $s1,sp,n */ |
| 1278 | { |
| 1279 | offset = mips16_get_imm (prev_inst, inst, 8, 4, 0); |
| 1280 | frame_addr = sp + offset; |
| 1281 | PROC_FRAME_REG (&temp_proc_desc) = 17; |
| 1282 | PROC_FRAME_ADJUST (&temp_proc_desc) = offset; |
| 1283 | } |
| 1284 | else if ((inst & 0xFF00) == 0xd900) /* sw reg,offset($s1) */ |
| 1285 | { |
| 1286 | offset = mips16_get_imm (prev_inst, inst, 5, 4, 0); |
| 1287 | reg = mips16_to_32_reg[(inst & 0xe0) >> 5]; |
| 1288 | PROC_REG_MASK(&temp_proc_desc) |= 1 << reg; |
| 1289 | set_reg_offset (reg, frame_addr + offset); |
| 1290 | } |
| 1291 | else if ((inst & 0xFF00) == 0x7900) /* sd reg,offset($s1) */ |
| 1292 | { |
| 1293 | offset = mips16_get_imm (prev_inst, inst, 5, 8, 0); |
| 1294 | reg = mips16_to_32_reg[(inst & 0xe0) >> 5]; |
| 1295 | PROC_REG_MASK(&temp_proc_desc) |= 1 << reg; |
| 1296 | set_reg_offset (reg, frame_addr + offset); |
| 1297 | } |
| 1298 | else if ((inst & 0xf81f) == 0xe809 && (inst & 0x700) != 0x700) /* entry */ |
| 1299 | entry_inst = inst; /* save for later processing */ |
| 1300 | else if ((inst & 0xf800) == 0x1800) /* jal(x) */ |
| 1301 | cur_pc += MIPS16_INSTLEN; /* 32-bit instruction */ |
| 1302 | } |
| 1303 | |
| 1304 | /* The entry instruction is typically the first instruction in a function, |
| 1305 | and it stores registers at offsets relative to the value of the old SP |
| 1306 | (before the prologue). But the value of the sp parameter to this |
| 1307 | function is the new SP (after the prologue has been executed). So we |
| 1308 | can't calculate those offsets until we've seen the entire prologue, |
| 1309 | and can calculate what the old SP must have been. */ |
| 1310 | if (entry_inst != 0) |
| 1311 | { |
| 1312 | int areg_count = (entry_inst >> 8) & 7; |
| 1313 | int sreg_count = (entry_inst >> 6) & 3; |
| 1314 | |
| 1315 | /* The entry instruction always subtracts 32 from the SP. */ |
| 1316 | PROC_FRAME_OFFSET(&temp_proc_desc) += 32; |
| 1317 | |
| 1318 | /* Now we can calculate what the SP must have been at the |
| 1319 | start of the function prologue. */ |
| 1320 | sp += PROC_FRAME_OFFSET(&temp_proc_desc); |
| 1321 | |
| 1322 | /* Check if a0-a3 were saved in the caller's argument save area. */ |
| 1323 | for (reg = 4, offset = 0; reg < areg_count+4; reg++) |
| 1324 | { |
| 1325 | PROC_REG_MASK(&temp_proc_desc) |= 1 << reg; |
| 1326 | set_reg_offset (reg, sp + offset); |
| 1327 | offset += MIPS_REGSIZE; |
| 1328 | } |
| 1329 | |
| 1330 | /* Check if the ra register was pushed on the stack. */ |
| 1331 | offset = -4; |
| 1332 | if (entry_inst & 0x20) |
| 1333 | { |
| 1334 | PROC_REG_MASK(&temp_proc_desc) |= 1 << RA_REGNUM; |
| 1335 | set_reg_offset (RA_REGNUM, sp + offset); |
| 1336 | offset -= MIPS_REGSIZE; |
| 1337 | } |
| 1338 | |
| 1339 | /* Check if the s0 and s1 registers were pushed on the stack. */ |
| 1340 | for (reg = 16; reg < sreg_count+16; reg++) |
| 1341 | { |
| 1342 | PROC_REG_MASK(&temp_proc_desc) |= 1 << reg; |
| 1343 | set_reg_offset (reg, sp + offset); |
| 1344 | offset -= MIPS_REGSIZE; |
| 1345 | } |
| 1346 | } |
| 1347 | } |
| 1348 | |
| 1349 | static void |
| 1350 | mips32_heuristic_proc_desc(start_pc, limit_pc, next_frame, sp) |
| 1351 | CORE_ADDR start_pc, limit_pc; |
| 1352 | struct frame_info *next_frame; |
| 1353 | CORE_ADDR sp; |
| 1354 | { |
| 1355 | CORE_ADDR cur_pc; |
| 1356 | CORE_ADDR frame_addr = 0; /* Value of $r30. Used by gcc for frame-pointer */ |
| 1357 | restart: |
| 1358 | PROC_FRAME_OFFSET(&temp_proc_desc) = 0; |
| 1359 | PROC_FRAME_ADJUST (&temp_proc_desc) = 0; /* offset of FP from SP */ |
| 1360 | for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += MIPS_INSTLEN) |
| 1361 | { |
| 1362 | unsigned long inst, high_word, low_word; |
| 1363 | int reg; |
| 1364 | |
| 1365 | /* Fetch the instruction. */ |
| 1366 | inst = (unsigned long) mips_fetch_instruction (cur_pc); |
| 1367 | |
| 1368 | /* Save some code by pre-extracting some useful fields. */ |
| 1369 | high_word = (inst >> 16) & 0xffff; |
| 1370 | low_word = inst & 0xffff; |
| 1371 | reg = high_word & 0x1f; |
| 1372 | |
| 1373 | if (high_word == 0x27bd /* addiu $sp,$sp,-i */ |
| 1374 | || high_word == 0x23bd /* addi $sp,$sp,-i */ |
| 1375 | || high_word == 0x67bd) /* daddiu $sp,$sp,-i */ |
| 1376 | { |
| 1377 | if (low_word & 0x8000) /* negative stack adjustment? */ |
| 1378 | PROC_FRAME_OFFSET(&temp_proc_desc) += 0x10000 - low_word; |
| 1379 | else |
| 1380 | /* Exit loop if a positive stack adjustment is found, which |
| 1381 | usually means that the stack cleanup code in the function |
| 1382 | epilogue is reached. */ |
| 1383 | break; |
| 1384 | } |
| 1385 | else if ((high_word & 0xFFE0) == 0xafa0) /* sw reg,offset($sp) */ |
| 1386 | { |
| 1387 | PROC_REG_MASK(&temp_proc_desc) |= 1 << reg; |
| 1388 | set_reg_offset (reg, sp + low_word); |
| 1389 | } |
| 1390 | else if ((high_word & 0xFFE0) == 0xffa0) /* sd reg,offset($sp) */ |
| 1391 | { |
| 1392 | /* Irix 6.2 N32 ABI uses sd instructions for saving $gp and $ra, |
| 1393 | but the register size used is only 32 bits. Make the address |
| 1394 | for the saved register point to the lower 32 bits. */ |
| 1395 | PROC_REG_MASK(&temp_proc_desc) |= 1 << reg; |
| 1396 | set_reg_offset (reg, sp + low_word + 8 - MIPS_REGSIZE); |
| 1397 | } |
| 1398 | else if (high_word == 0x27be) /* addiu $30,$sp,size */ |
| 1399 | { |
| 1400 | /* Old gcc frame, r30 is virtual frame pointer. */ |
| 1401 | if ((long)low_word != PROC_FRAME_OFFSET(&temp_proc_desc)) |
| 1402 | frame_addr = sp + low_word; |
| 1403 | else if (PROC_FRAME_REG (&temp_proc_desc) == SP_REGNUM) |
| 1404 | { |
| 1405 | unsigned alloca_adjust; |
| 1406 | PROC_FRAME_REG (&temp_proc_desc) = 30; |
| 1407 | frame_addr = read_next_frame_reg(next_frame, 30); |
| 1408 | alloca_adjust = (unsigned)(frame_addr - (sp + low_word)); |
| 1409 | if (alloca_adjust > 0) |
| 1410 | { |
| 1411 | /* FP > SP + frame_size. This may be because |
| 1412 | * of an alloca or somethings similar. |
| 1413 | * Fix sp to "pre-alloca" value, and try again. |
| 1414 | */ |
| 1415 | sp += alloca_adjust; |
| 1416 | goto restart; |
| 1417 | } |
| 1418 | } |
| 1419 | } |
| 1420 | /* move $30,$sp. With different versions of gas this will be either |
| 1421 | `addu $30,$sp,$zero' or `or $30,$sp,$zero' or `daddu 30,sp,$0'. |
| 1422 | Accept any one of these. */ |
| 1423 | else if (inst == 0x03A0F021 || inst == 0x03a0f025 || inst == 0x03a0f02d) |
| 1424 | { |
| 1425 | /* New gcc frame, virtual frame pointer is at r30 + frame_size. */ |
| 1426 | if (PROC_FRAME_REG (&temp_proc_desc) == SP_REGNUM) |
| 1427 | { |
| 1428 | unsigned alloca_adjust; |
| 1429 | PROC_FRAME_REG (&temp_proc_desc) = 30; |
| 1430 | frame_addr = read_next_frame_reg(next_frame, 30); |
| 1431 | alloca_adjust = (unsigned)(frame_addr - sp); |
| 1432 | if (alloca_adjust > 0) |
| 1433 | { |
| 1434 | /* FP > SP + frame_size. This may be because |
| 1435 | * of an alloca or somethings similar. |
| 1436 | * Fix sp to "pre-alloca" value, and try again. |
| 1437 | */ |
| 1438 | sp += alloca_adjust; |
| 1439 | goto restart; |
| 1440 | } |
| 1441 | } |
| 1442 | } |
| 1443 | else if ((high_word & 0xFFE0) == 0xafc0) /* sw reg,offset($30) */ |
| 1444 | { |
| 1445 | PROC_REG_MASK(&temp_proc_desc) |= 1 << reg; |
| 1446 | set_reg_offset (reg, frame_addr + low_word); |
| 1447 | } |
| 1448 | } |
| 1449 | } |
| 1450 | |
| 1451 | static mips_extra_func_info_t |
| 1452 | heuristic_proc_desc(start_pc, limit_pc, next_frame) |
| 1453 | CORE_ADDR start_pc, limit_pc; |
| 1454 | struct frame_info *next_frame; |
| 1455 | { |
| 1456 | CORE_ADDR sp = read_next_frame_reg (next_frame, SP_REGNUM); |
| 1457 | |
| 1458 | if (start_pc == 0) return NULL; |
| 1459 | memset (&temp_proc_desc, '\0', sizeof(temp_proc_desc)); |
| 1460 | memset (&temp_saved_regs, '\0', sizeof(struct frame_saved_regs)); |
| 1461 | PROC_LOW_ADDR (&temp_proc_desc) = start_pc; |
| 1462 | PROC_FRAME_REG (&temp_proc_desc) = SP_REGNUM; |
| 1463 | PROC_PC_REG (&temp_proc_desc) = RA_REGNUM; |
| 1464 | |
| 1465 | if (start_pc + 200 < limit_pc) |
| 1466 | limit_pc = start_pc + 200; |
| 1467 | if (pc_is_mips16 (start_pc)) |
| 1468 | mips16_heuristic_proc_desc (start_pc, limit_pc, next_frame, sp); |
| 1469 | else |
| 1470 | mips32_heuristic_proc_desc (start_pc, limit_pc, next_frame, sp); |
| 1471 | return &temp_proc_desc; |
| 1472 | } |
| 1473 | |
| 1474 | static mips_extra_func_info_t |
| 1475 | non_heuristic_proc_desc (pc, addrptr) |
| 1476 | CORE_ADDR pc; |
| 1477 | CORE_ADDR *addrptr; |
| 1478 | { |
| 1479 | CORE_ADDR startaddr; |
| 1480 | mips_extra_func_info_t proc_desc; |
| 1481 | struct block *b = block_for_pc(pc); |
| 1482 | struct symbol *sym; |
| 1483 | |
| 1484 | find_pc_partial_function (pc, NULL, &startaddr, NULL); |
| 1485 | if (addrptr) |
| 1486 | *addrptr = startaddr; |
| 1487 | if (b == NULL || PC_IN_CALL_DUMMY (pc, 0, 0)) |
| 1488 | sym = NULL; |
| 1489 | else |
| 1490 | { |
| 1491 | if (startaddr > BLOCK_START (b)) |
| 1492 | /* This is the "pathological" case referred to in a comment in |
| 1493 | print_frame_info. It might be better to move this check into |
| 1494 | symbol reading. */ |
| 1495 | sym = NULL; |
| 1496 | else |
| 1497 | sym = lookup_symbol (MIPS_EFI_SYMBOL_NAME, b, LABEL_NAMESPACE, 0, NULL); |
| 1498 | } |
| 1499 | |
| 1500 | /* If we never found a PDR for this function in symbol reading, then |
| 1501 | examine prologues to find the information. */ |
| 1502 | if (sym) |
| 1503 | { |
| 1504 | proc_desc = (mips_extra_func_info_t) SYMBOL_VALUE (sym); |
| 1505 | if (PROC_FRAME_REG (proc_desc) == -1) |
| 1506 | return NULL; |
| 1507 | else |
| 1508 | return proc_desc; |
| 1509 | } |
| 1510 | else |
| 1511 | return NULL; |
| 1512 | } |
| 1513 | |
| 1514 | |
| 1515 | static mips_extra_func_info_t |
| 1516 | find_proc_desc (pc, next_frame) |
| 1517 | CORE_ADDR pc; |
| 1518 | struct frame_info *next_frame; |
| 1519 | { |
| 1520 | mips_extra_func_info_t proc_desc; |
| 1521 | CORE_ADDR startaddr; |
| 1522 | |
| 1523 | proc_desc = non_heuristic_proc_desc (pc, &startaddr); |
| 1524 | |
| 1525 | if (proc_desc) |
| 1526 | { |
| 1527 | /* IF this is the topmost frame AND |
| 1528 | * (this proc does not have debugging information OR |
| 1529 | * the PC is in the procedure prologue) |
| 1530 | * THEN create a "heuristic" proc_desc (by analyzing |
| 1531 | * the actual code) to replace the "official" proc_desc. |
| 1532 | */ |
| 1533 | if (next_frame == NULL) |
| 1534 | { |
| 1535 | struct symtab_and_line val; |
| 1536 | struct symbol *proc_symbol = |
| 1537 | PROC_DESC_IS_DUMMY(proc_desc) ? 0 : PROC_SYMBOL(proc_desc); |
| 1538 | |
| 1539 | if (proc_symbol) |
| 1540 | { |
| 1541 | val = find_pc_line (BLOCK_START |
| 1542 | (SYMBOL_BLOCK_VALUE(proc_symbol)), |
| 1543 | 0); |
| 1544 | val.pc = val.end ? val.end : pc; |
| 1545 | } |
| 1546 | if (!proc_symbol || pc < val.pc) |
| 1547 | { |
| 1548 | mips_extra_func_info_t found_heuristic = |
| 1549 | heuristic_proc_desc (PROC_LOW_ADDR (proc_desc), |
| 1550 | pc, next_frame); |
| 1551 | if (found_heuristic) |
| 1552 | proc_desc = found_heuristic; |
| 1553 | } |
| 1554 | } |
| 1555 | } |
| 1556 | else |
| 1557 | { |
| 1558 | /* Is linked_proc_desc_table really necessary? It only seems to be used |
| 1559 | by procedure call dummys. However, the procedures being called ought |
| 1560 | to have their own proc_descs, and even if they don't, |
| 1561 | heuristic_proc_desc knows how to create them! */ |
| 1562 | |
| 1563 | register struct linked_proc_info *link; |
| 1564 | |
| 1565 | for (link = linked_proc_desc_table; link; link = link->next) |
| 1566 | if (PROC_LOW_ADDR(&link->info) <= pc |
| 1567 | && PROC_HIGH_ADDR(&link->info) > pc) |
| 1568 | return &link->info; |
| 1569 | |
| 1570 | if (startaddr == 0) |
| 1571 | startaddr = heuristic_proc_start (pc); |
| 1572 | |
| 1573 | proc_desc = |
| 1574 | heuristic_proc_desc (startaddr, pc, next_frame); |
| 1575 | } |
| 1576 | return proc_desc; |
| 1577 | } |
| 1578 | |
| 1579 | static CORE_ADDR |
| 1580 | get_frame_pointer(frame, proc_desc) |
| 1581 | struct frame_info *frame; |
| 1582 | mips_extra_func_info_t proc_desc; |
| 1583 | { |
| 1584 | return ADDR_BITS_REMOVE ( |
| 1585 | read_next_frame_reg (frame, PROC_FRAME_REG (proc_desc)) + |
| 1586 | PROC_FRAME_OFFSET (proc_desc) - PROC_FRAME_ADJUST (proc_desc)); |
| 1587 | } |
| 1588 | |
| 1589 | mips_extra_func_info_t cached_proc_desc; |
| 1590 | |
| 1591 | CORE_ADDR |
| 1592 | mips_frame_chain(frame) |
| 1593 | struct frame_info *frame; |
| 1594 | { |
| 1595 | mips_extra_func_info_t proc_desc; |
| 1596 | CORE_ADDR tmp; |
| 1597 | CORE_ADDR saved_pc = FRAME_SAVED_PC(frame); |
| 1598 | |
| 1599 | if (saved_pc == 0 || inside_entry_file (saved_pc)) |
| 1600 | return 0; |
| 1601 | |
| 1602 | /* Check if the PC is inside a call stub. If it is, fetch the |
| 1603 | PC of the caller of that stub. */ |
| 1604 | if ((tmp = mips_skip_stub (saved_pc)) != 0) |
| 1605 | saved_pc = tmp; |
| 1606 | |
| 1607 | /* Look up the procedure descriptor for this PC. */ |
| 1608 | proc_desc = find_proc_desc(saved_pc, frame); |
| 1609 | if (!proc_desc) |
| 1610 | return 0; |
| 1611 | |
| 1612 | cached_proc_desc = proc_desc; |
| 1613 | |
| 1614 | /* If no frame pointer and frame size is zero, we must be at end |
| 1615 | of stack (or otherwise hosed). If we don't check frame size, |
| 1616 | we loop forever if we see a zero size frame. */ |
| 1617 | if (PROC_FRAME_REG (proc_desc) == SP_REGNUM |
| 1618 | && PROC_FRAME_OFFSET (proc_desc) == 0 |
| 1619 | /* The previous frame from a sigtramp frame might be frameless |
| 1620 | and have frame size zero. */ |
| 1621 | && !frame->signal_handler_caller) |
| 1622 | return 0; |
| 1623 | else |
| 1624 | return get_frame_pointer (frame, proc_desc); |
| 1625 | } |
| 1626 | |
| 1627 | void |
| 1628 | init_extra_frame_info(fci) |
| 1629 | struct frame_info *fci; |
| 1630 | { |
| 1631 | int regnum; |
| 1632 | |
| 1633 | /* Use proc_desc calculated in frame_chain */ |
| 1634 | mips_extra_func_info_t proc_desc = |
| 1635 | fci->next ? cached_proc_desc : find_proc_desc(fci->pc, fci->next); |
| 1636 | |
| 1637 | fci->saved_regs = NULL; |
| 1638 | fci->proc_desc = |
| 1639 | proc_desc == &temp_proc_desc ? 0 : proc_desc; |
| 1640 | if (proc_desc) |
| 1641 | { |
| 1642 | /* Fixup frame-pointer - only needed for top frame */ |
| 1643 | /* This may not be quite right, if proc has a real frame register. |
| 1644 | Get the value of the frame relative sp, procedure might have been |
| 1645 | interrupted by a signal at it's very start. */ |
| 1646 | if (fci->pc == PROC_LOW_ADDR (proc_desc) |
| 1647 | && !PROC_DESC_IS_DUMMY (proc_desc)) |
| 1648 | fci->frame = read_next_frame_reg (fci->next, SP_REGNUM); |
| 1649 | else |
| 1650 | fci->frame = get_frame_pointer (fci->next, proc_desc); |
| 1651 | |
| 1652 | if (proc_desc == &temp_proc_desc) |
| 1653 | { |
| 1654 | char *name; |
| 1655 | |
| 1656 | /* Do not set the saved registers for a sigtramp frame, |
| 1657 | mips_find_saved_registers will do that for us. |
| 1658 | We can't use fci->signal_handler_caller, it is not yet set. */ |
| 1659 | find_pc_partial_function (fci->pc, &name, |
| 1660 | (CORE_ADDR *)NULL,(CORE_ADDR *)NULL); |
| 1661 | if (!IN_SIGTRAMP (fci->pc, name)) |
| 1662 | { |
| 1663 | fci->saved_regs = (struct frame_saved_regs*) |
| 1664 | obstack_alloc (&frame_cache_obstack, |
| 1665 | sizeof (struct frame_saved_regs)); |
| 1666 | *fci->saved_regs = temp_saved_regs; |
| 1667 | fci->saved_regs->regs[PC_REGNUM] |
| 1668 | = fci->saved_regs->regs[RA_REGNUM]; |
| 1669 | } |
| 1670 | } |
| 1671 | |
| 1672 | /* hack: if argument regs are saved, guess these contain args */ |
| 1673 | fci->num_args = -1; /* assume we can't tell how many args for now */ |
| 1674 | for (regnum = MIPS_LAST_ARG_REGNUM; regnum >= A0_REGNUM; regnum--) |
| 1675 | { |
| 1676 | if (PROC_REG_MASK(proc_desc) & (1 << regnum)) |
| 1677 | { |
| 1678 | fci->num_args = regnum - A0_REGNUM + 1; |
| 1679 | break; |
| 1680 | } |
| 1681 | } |
| 1682 | } |
| 1683 | } |
| 1684 | |
| 1685 | /* MIPS stack frames are almost impenetrable. When execution stops, |
| 1686 | we basically have to look at symbol information for the function |
| 1687 | that we stopped in, which tells us *which* register (if any) is |
| 1688 | the base of the frame pointer, and what offset from that register |
| 1689 | the frame itself is at. |
| 1690 | |
| 1691 | This presents a problem when trying to examine a stack in memory |
| 1692 | (that isn't executing at the moment), using the "frame" command. We |
| 1693 | don't have a PC, nor do we have any registers except SP. |
| 1694 | |
| 1695 | This routine takes two arguments, SP and PC, and tries to make the |
| 1696 | cached frames look as if these two arguments defined a frame on the |
| 1697 | cache. This allows the rest of info frame to extract the important |
| 1698 | arguments without difficulty. */ |
| 1699 | |
| 1700 | struct frame_info * |
| 1701 | setup_arbitrary_frame (argc, argv) |
| 1702 | int argc; |
| 1703 | CORE_ADDR *argv; |
| 1704 | { |
| 1705 | if (argc != 2) |
| 1706 | error ("MIPS frame specifications require two arguments: sp and pc"); |
| 1707 | |
| 1708 | return create_new_frame (argv[0], argv[1]); |
| 1709 | } |
| 1710 | |
| 1711 | CORE_ADDR |
| 1712 | mips_push_arguments(nargs, args, sp, struct_return, struct_addr) |
| 1713 | int nargs; |
| 1714 | value_ptr *args; |
| 1715 | CORE_ADDR sp; |
| 1716 | int struct_return; |
| 1717 | CORE_ADDR struct_addr; |
| 1718 | { |
| 1719 | int argreg; |
| 1720 | int float_argreg; |
| 1721 | int argnum; |
| 1722 | int len = 0; |
| 1723 | int stack_offset = 0; |
| 1724 | |
| 1725 | /* Macros to round N up or down to the next A boundary; A must be |
| 1726 | a power of two. */ |
| 1727 | #define ROUND_DOWN(n,a) ((n) & ~((a)-1)) |
| 1728 | #define ROUND_UP(n,a) (((n)+(a)-1) & ~((a)-1)) |
| 1729 | |
| 1730 | /* First ensure that the stack and structure return address (if any) |
| 1731 | are properly aligned. The stack has to be 64-bit aligned even |
| 1732 | on 32-bit machines, because doubles must be 64-bit aligned. */ |
| 1733 | sp = ROUND_DOWN (sp, 8); |
| 1734 | struct_addr = ROUND_DOWN (struct_addr, MIPS_REGSIZE); |
| 1735 | |
| 1736 | /* Now make space on the stack for the args. We allocate more |
| 1737 | than necessary for EABI, because the first few arguments are |
| 1738 | passed in registers, but that's OK. */ |
| 1739 | for (argnum = 0; argnum < nargs; argnum++) |
| 1740 | len += ROUND_UP (TYPE_LENGTH(VALUE_TYPE(args[argnum])), MIPS_REGSIZE); |
| 1741 | sp -= ROUND_UP (len, 8); |
| 1742 | |
| 1743 | /* Initialize the integer and float register pointers. */ |
| 1744 | argreg = A0_REGNUM; |
| 1745 | float_argreg = FPA0_REGNUM; |
| 1746 | |
| 1747 | /* the struct_return pointer occupies the first parameter-passing reg */ |
| 1748 | if (struct_return) |
| 1749 | write_register (argreg++, struct_addr); |
| 1750 | |
| 1751 | /* Now load as many as possible of the first arguments into |
| 1752 | registers, and push the rest onto the stack. Loop thru args |
| 1753 | from first to last. */ |
| 1754 | for (argnum = 0; argnum < nargs; argnum++) |
| 1755 | { |
| 1756 | char *val; |
| 1757 | char valbuf[MAX_REGISTER_RAW_SIZE]; |
| 1758 | value_ptr arg = args[argnum]; |
| 1759 | struct type *arg_type = check_typedef (VALUE_TYPE (arg)); |
| 1760 | int len = TYPE_LENGTH (arg_type); |
| 1761 | enum type_code typecode = TYPE_CODE (arg_type); |
| 1762 | |
| 1763 | /* The EABI passes structures that do not fit in a register by |
| 1764 | reference. In all other cases, pass the structure by value. */ |
| 1765 | if (MIPS_EABI && len > MIPS_REGSIZE && |
| 1766 | (typecode == TYPE_CODE_STRUCT || typecode == TYPE_CODE_UNION)) |
| 1767 | { |
| 1768 | store_address (valbuf, MIPS_REGSIZE, VALUE_ADDRESS (arg)); |
| 1769 | typecode = TYPE_CODE_PTR; |
| 1770 | len = MIPS_REGSIZE; |
| 1771 | val = valbuf; |
| 1772 | } |
| 1773 | else |
| 1774 | val = (char *)VALUE_CONTENTS (arg); |
| 1775 | |
| 1776 | /* 32-bit ABIs always start floating point arguments in an |
| 1777 | even-numbered floating point register. */ |
| 1778 | if (!GDB_TARGET_IS_MIPS64 && typecode == TYPE_CODE_FLT |
| 1779 | && (float_argreg & 1)) |
| 1780 | float_argreg++; |
| 1781 | |
| 1782 | /* Floating point arguments passed in registers have to be |
| 1783 | treated specially. On 32-bit architectures, doubles |
| 1784 | are passed in register pairs; the even register gets |
| 1785 | the low word, and the odd register gets the high word. |
| 1786 | On non-EABI processors, the first two floating point arguments are |
| 1787 | also copied to general registers, because MIPS16 functions |
| 1788 | don't use float registers for arguments. This duplication of |
| 1789 | arguments in general registers can't hurt non-MIPS16 functions |
| 1790 | because those registers are normally skipped. */ |
| 1791 | if (typecode == TYPE_CODE_FLT |
| 1792 | && float_argreg <= MIPS_LAST_FP_ARG_REGNUM |
| 1793 | && mips_fpu != MIPS_FPU_NONE) |
| 1794 | { |
| 1795 | if (!GDB_TARGET_IS_MIPS64 && len == 8) |
| 1796 | { |
| 1797 | int low_offset = TARGET_BYTE_ORDER == BIG_ENDIAN ? 4 : 0; |
| 1798 | unsigned long regval; |
| 1799 | |
| 1800 | /* Write the low word of the double to the even register(s). */ |
| 1801 | regval = extract_unsigned_integer (val+low_offset, 4); |
| 1802 | write_register (float_argreg++, regval); |
| 1803 | if (!MIPS_EABI) |
| 1804 | write_register (argreg+1, regval); |
| 1805 | |
| 1806 | /* Write the high word of the double to the odd register(s). */ |
| 1807 | regval = extract_unsigned_integer (val+4-low_offset, 4); |
| 1808 | write_register (float_argreg++, regval); |
| 1809 | if (!MIPS_EABI) |
| 1810 | { |
| 1811 | write_register (argreg, regval); |
| 1812 | argreg += 2; |
| 1813 | } |
| 1814 | |
| 1815 | } |
| 1816 | else |
| 1817 | { |
| 1818 | /* This is a floating point value that fits entirely |
| 1819 | in a single register. */ |
| 1820 | CORE_ADDR regval = extract_address (val, len); |
| 1821 | write_register (float_argreg++, regval); |
| 1822 | if (!MIPS_EABI) |
| 1823 | { |
| 1824 | write_register (argreg, regval); |
| 1825 | argreg += GDB_TARGET_IS_MIPS64 ? 1 : 2; |
| 1826 | } |
| 1827 | } |
| 1828 | } |
| 1829 | else |
| 1830 | { |
| 1831 | /* Copy the argument to general registers or the stack in |
| 1832 | register-sized pieces. Large arguments are split between |
| 1833 | registers and stack. */ |
| 1834 | /* Note: structs whose size is not a multiple of MIPS_REGSIZE |
| 1835 | are treated specially: Irix cc passes them in registers |
| 1836 | where gcc sometimes puts them on the stack. For maximum |
| 1837 | compatibility, we will put them in both places. */ |
| 1838 | |
| 1839 | int odd_sized_struct = ((len > MIPS_REGSIZE) && |
| 1840 | (len % MIPS_REGSIZE != 0)); |
| 1841 | while (len > 0) |
| 1842 | { |
| 1843 | int partial_len = len < MIPS_REGSIZE ? len : MIPS_REGSIZE; |
| 1844 | |
| 1845 | if (argreg > MIPS_LAST_ARG_REGNUM || odd_sized_struct) |
| 1846 | { |
| 1847 | /* Write this portion of the argument to the stack. */ |
| 1848 | /* Should shorter than int integer values be |
| 1849 | promoted to int before being stored? */ |
| 1850 | |
| 1851 | int longword_offset = 0; |
| 1852 | if (TARGET_BYTE_ORDER == BIG_ENDIAN) |
| 1853 | if (MIPS_REGSIZE == 8 && |
| 1854 | (typecode == TYPE_CODE_INT || |
| 1855 | typecode == TYPE_CODE_PTR || |
| 1856 | typecode == TYPE_CODE_FLT) && len <= 4) |
| 1857 | longword_offset = MIPS_REGSIZE - len; |
| 1858 | else if ((typecode == TYPE_CODE_STRUCT || |
| 1859 | typecode == TYPE_CODE_UNION) && |
| 1860 | TYPE_LENGTH (arg_type) < MIPS_REGSIZE) |
| 1861 | longword_offset = MIPS_REGSIZE - len; |
| 1862 | |
| 1863 | write_memory (sp + stack_offset + longword_offset, |
| 1864 | val, partial_len); |
| 1865 | } |
| 1866 | |
| 1867 | /* Note!!! This is NOT an else clause. |
| 1868 | Odd sized structs may go thru BOTH paths. */ |
| 1869 | if (argreg <= MIPS_LAST_ARG_REGNUM) |
| 1870 | { |
| 1871 | CORE_ADDR regval = extract_address (val, partial_len); |
| 1872 | |
| 1873 | /* A non-floating-point argument being passed in a |
| 1874 | general register. If a struct or union, and if |
| 1875 | the remaining length is smaller than the register |
| 1876 | size, we have to adjust the register value on |
| 1877 | big endian targets. |
| 1878 | |
| 1879 | It does not seem to be necessary to do the |
| 1880 | same for integral types. |
| 1881 | |
| 1882 | Also don't do this adjustment on EABI targets. */ |
| 1883 | |
| 1884 | if (!MIPS_EABI && |
| 1885 | TARGET_BYTE_ORDER == BIG_ENDIAN && |
| 1886 | partial_len < MIPS_REGSIZE && |
| 1887 | (typecode == TYPE_CODE_STRUCT || |
| 1888 | typecode == TYPE_CODE_UNION)) |
| 1889 | regval <<= ((MIPS_REGSIZE - partial_len) * |
| 1890 | TARGET_CHAR_BIT); |
| 1891 | |
| 1892 | write_register (argreg, regval); |
| 1893 | argreg++; |
| 1894 | |
| 1895 | /* If this is the old ABI, prevent subsequent floating |
| 1896 | point arguments from being passed in floating point |
| 1897 | registers. */ |
| 1898 | if (!MIPS_EABI) |
| 1899 | float_argreg = MIPS_LAST_FP_ARG_REGNUM + 1; |
| 1900 | } |
| 1901 | |
| 1902 | len -= partial_len; |
| 1903 | val += partial_len; |
| 1904 | |
| 1905 | /* The offset onto the stack at which we will start |
| 1906 | copying parameters (after the registers are used up) |
| 1907 | begins at (4 * MIPS_REGSIZE) in the old ABI. This |
| 1908 | leaves room for the "home" area for register parameters. |
| 1909 | |
| 1910 | In the new EABI, the 8 register parameters do not |
| 1911 | have "home" stack space reserved for them, so the |
| 1912 | stack offset does not get incremented until after |
| 1913 | we have used up the 8 parameter registers. */ |
| 1914 | if (!(MIPS_EABI && argnum < 8)) |
| 1915 | stack_offset += ROUND_UP (partial_len, MIPS_REGSIZE); |
| 1916 | } |
| 1917 | } |
| 1918 | } |
| 1919 | |
| 1920 | /* Set the return address register to point to the entry |
| 1921 | point of the program, where a breakpoint lies in wait. */ |
| 1922 | write_register (RA_REGNUM, CALL_DUMMY_ADDRESS()); |
| 1923 | |
| 1924 | /* Return adjusted stack pointer. */ |
| 1925 | return sp; |
| 1926 | } |
| 1927 | |
| 1928 | static void |
| 1929 | mips_push_register(CORE_ADDR *sp, int regno) |
| 1930 | { |
| 1931 | char buffer[MAX_REGISTER_RAW_SIZE]; |
| 1932 | int regsize = REGISTER_RAW_SIZE (regno); |
| 1933 | |
| 1934 | *sp -= regsize; |
| 1935 | read_register_gen (regno, buffer); |
| 1936 | write_memory (*sp, buffer, regsize); |
| 1937 | } |
| 1938 | |
| 1939 | /* MASK(i,j) == (1<<i) + (1<<(i+1)) + ... + (1<<j)). Assume i<=j<(MIPS_NUMREGS-1). */ |
| 1940 | #define MASK(i,j) (((1 << ((j)+1))-1) ^ ((1 << (i))-1)) |
| 1941 | |
| 1942 | void |
| 1943 | mips_push_dummy_frame() |
| 1944 | { |
| 1945 | int ireg; |
| 1946 | struct linked_proc_info *link = (struct linked_proc_info*) |
| 1947 | xmalloc(sizeof(struct linked_proc_info)); |
| 1948 | mips_extra_func_info_t proc_desc = &link->info; |
| 1949 | CORE_ADDR sp = ADDR_BITS_REMOVE (read_register (SP_REGNUM)); |
| 1950 | CORE_ADDR old_sp = sp; |
| 1951 | link->next = linked_proc_desc_table; |
| 1952 | linked_proc_desc_table = link; |
| 1953 | |
| 1954 | /* FIXME! are these correct ? */ |
| 1955 | #define PUSH_FP_REGNUM 16 /* must be a register preserved across calls */ |
| 1956 | #define GEN_REG_SAVE_MASK MASK(1,16)|MASK(24,28)|(1<<(MIPS_NUMREGS-1)) |
| 1957 | #define FLOAT_REG_SAVE_MASK MASK(0,19) |
| 1958 | #define FLOAT_SINGLE_REG_SAVE_MASK \ |
| 1959 | ((1<<18)|(1<<16)|(1<<14)|(1<<12)|(1<<10)|(1<<8)|(1<<6)|(1<<4)|(1<<2)|(1<<0)) |
| 1960 | /* |
| 1961 | * The registers we must save are all those not preserved across |
| 1962 | * procedure calls. Dest_Reg (see tm-mips.h) must also be saved. |
| 1963 | * In addition, we must save the PC, PUSH_FP_REGNUM, MMLO/-HI |
| 1964 | * and FP Control/Status registers. |
| 1965 | * |
| 1966 | * |
| 1967 | * Dummy frame layout: |
| 1968 | * (high memory) |
| 1969 | * Saved PC |
| 1970 | * Saved MMHI, MMLO, FPC_CSR |
| 1971 | * Saved R31 |
| 1972 | * Saved R28 |
| 1973 | * ... |
| 1974 | * Saved R1 |
| 1975 | * Saved D18 (i.e. F19, F18) |
| 1976 | * ... |
| 1977 | * Saved D0 (i.e. F1, F0) |
| 1978 | * Argument build area and stack arguments written via mips_push_arguments |
| 1979 | * (low memory) |
| 1980 | */ |
| 1981 | |
| 1982 | /* Save special registers (PC, MMHI, MMLO, FPC_CSR) */ |
| 1983 | PROC_FRAME_REG(proc_desc) = PUSH_FP_REGNUM; |
| 1984 | PROC_FRAME_OFFSET(proc_desc) = 0; |
| 1985 | PROC_FRAME_ADJUST(proc_desc) = 0; |
| 1986 | mips_push_register (&sp, PC_REGNUM); |
| 1987 | mips_push_register (&sp, HI_REGNUM); |
| 1988 | mips_push_register (&sp, LO_REGNUM); |
| 1989 | mips_push_register (&sp, mips_fpu == MIPS_FPU_NONE ? 0 : FCRCS_REGNUM); |
| 1990 | |
| 1991 | /* Save general CPU registers */ |
| 1992 | PROC_REG_MASK(proc_desc) = GEN_REG_SAVE_MASK; |
| 1993 | PROC_REG_OFFSET(proc_desc) = sp - old_sp; /* offset of (Saved R31) from FP */ |
| 1994 | for (ireg = 32; --ireg >= 0; ) |
| 1995 | if (PROC_REG_MASK(proc_desc) & (1 << ireg)) |
| 1996 | mips_push_register (&sp, ireg); |
| 1997 | |
| 1998 | /* Save floating point registers starting with high order word */ |
| 1999 | PROC_FREG_MASK(proc_desc) = |
| 2000 | mips_fpu == MIPS_FPU_DOUBLE ? FLOAT_REG_SAVE_MASK |
| 2001 | : mips_fpu == MIPS_FPU_SINGLE ? FLOAT_SINGLE_REG_SAVE_MASK : 0; |
| 2002 | PROC_FREG_OFFSET(proc_desc) = sp - old_sp; /* offset of (Saved D18) from FP */ |
| 2003 | for (ireg = 32; --ireg >= 0; ) |
| 2004 | if (PROC_FREG_MASK(proc_desc) & (1 << ireg)) |
| 2005 | mips_push_register (&sp, ireg + FP0_REGNUM); |
| 2006 | |
| 2007 | /* Update the frame pointer for the call dummy and the stack pointer. |
| 2008 | Set the procedure's starting and ending addresses to point to the |
| 2009 | call dummy address at the entry point. */ |
| 2010 | write_register (PUSH_FP_REGNUM, old_sp); |
| 2011 | write_register (SP_REGNUM, sp); |
| 2012 | PROC_LOW_ADDR(proc_desc) = CALL_DUMMY_ADDRESS(); |
| 2013 | PROC_HIGH_ADDR(proc_desc) = CALL_DUMMY_ADDRESS() + 4; |
| 2014 | SET_PROC_DESC_IS_DUMMY(proc_desc); |
| 2015 | PROC_PC_REG(proc_desc) = RA_REGNUM; |
| 2016 | } |
| 2017 | |
| 2018 | void |
| 2019 | mips_pop_frame() |
| 2020 | { |
| 2021 | register int regnum; |
| 2022 | struct frame_info *frame = get_current_frame (); |
| 2023 | CORE_ADDR new_sp = FRAME_FP (frame); |
| 2024 | |
| 2025 | mips_extra_func_info_t proc_desc = frame->proc_desc; |
| 2026 | |
| 2027 | write_register (PC_REGNUM, FRAME_SAVED_PC(frame)); |
| 2028 | if (frame->saved_regs == NULL) |
| 2029 | mips_find_saved_regs (frame); |
| 2030 | for (regnum = 0; regnum < NUM_REGS; regnum++) |
| 2031 | { |
| 2032 | if (regnum != SP_REGNUM && regnum != PC_REGNUM |
| 2033 | && frame->saved_regs->regs[regnum]) |
| 2034 | write_register (regnum, |
| 2035 | read_memory_integer (frame->saved_regs->regs[regnum], |
| 2036 | MIPS_REGSIZE)); |
| 2037 | } |
| 2038 | write_register (SP_REGNUM, new_sp); |
| 2039 | flush_cached_frames (); |
| 2040 | |
| 2041 | if (proc_desc && PROC_DESC_IS_DUMMY(proc_desc)) |
| 2042 | { |
| 2043 | struct linked_proc_info *pi_ptr, *prev_ptr; |
| 2044 | |
| 2045 | for (pi_ptr = linked_proc_desc_table, prev_ptr = NULL; |
| 2046 | pi_ptr != NULL; |
| 2047 | prev_ptr = pi_ptr, pi_ptr = pi_ptr->next) |
| 2048 | { |
| 2049 | if (&pi_ptr->info == proc_desc) |
| 2050 | break; |
| 2051 | } |
| 2052 | |
| 2053 | if (pi_ptr == NULL) |
| 2054 | error ("Can't locate dummy extra frame info\n"); |
| 2055 | |
| 2056 | if (prev_ptr != NULL) |
| 2057 | prev_ptr->next = pi_ptr->next; |
| 2058 | else |
| 2059 | linked_proc_desc_table = pi_ptr->next; |
| 2060 | |
| 2061 | free (pi_ptr); |
| 2062 | |
| 2063 | write_register (HI_REGNUM, |
| 2064 | read_memory_integer (new_sp - 2*MIPS_REGSIZE, MIPS_REGSIZE)); |
| 2065 | write_register (LO_REGNUM, |
| 2066 | read_memory_integer (new_sp - 3*MIPS_REGSIZE, MIPS_REGSIZE)); |
| 2067 | if (mips_fpu != MIPS_FPU_NONE) |
| 2068 | write_register (FCRCS_REGNUM, |
| 2069 | read_memory_integer (new_sp - 4*MIPS_REGSIZE, MIPS_REGSIZE)); |
| 2070 | } |
| 2071 | } |
| 2072 | |
| 2073 | static void |
| 2074 | mips_print_register (regnum, all) |
| 2075 | int regnum, all; |
| 2076 | { |
| 2077 | char raw_buffer[MAX_REGISTER_RAW_SIZE]; |
| 2078 | |
| 2079 | /* Get the data in raw format. */ |
| 2080 | if (read_relative_register_raw_bytes (regnum, raw_buffer)) |
| 2081 | { |
| 2082 | printf_filtered ("%s: [Invalid]", reg_names[regnum]); |
| 2083 | return; |
| 2084 | } |
| 2085 | |
| 2086 | /* If an even floating point register, also print as double. */ |
| 2087 | if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT |
| 2088 | && !((regnum-FP0_REGNUM) & 1)) |
| 2089 | if (REGISTER_RAW_SIZE(regnum) == 4) /* this would be silly on MIPS64 */ |
| 2090 | { |
| 2091 | char dbuffer[2 * MAX_REGISTER_RAW_SIZE]; |
| 2092 | |
| 2093 | read_relative_register_raw_bytes (regnum, dbuffer); |
| 2094 | read_relative_register_raw_bytes (regnum+1, dbuffer+MIPS_REGSIZE); |
| 2095 | REGISTER_CONVERT_TO_TYPE (regnum, builtin_type_double, dbuffer); |
| 2096 | |
| 2097 | printf_filtered ("(d%d: ", regnum-FP0_REGNUM); |
| 2098 | val_print (builtin_type_double, dbuffer, 0, |
| 2099 | gdb_stdout, 0, 1, 0, Val_pretty_default); |
| 2100 | printf_filtered ("); "); |
| 2101 | } |
| 2102 | fputs_filtered (reg_names[regnum], gdb_stdout); |
| 2103 | |
| 2104 | /* The problem with printing numeric register names (r26, etc.) is that |
| 2105 | the user can't use them on input. Probably the best solution is to |
| 2106 | fix it so that either the numeric or the funky (a2, etc.) names |
| 2107 | are accepted on input. */ |
| 2108 | if (regnum < MIPS_NUMREGS) |
| 2109 | printf_filtered ("(r%d): ", regnum); |
| 2110 | else |
| 2111 | printf_filtered (": "); |
| 2112 | |
| 2113 | /* If virtual format is floating, print it that way. */ |
| 2114 | if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT) |
| 2115 | if (REGISTER_RAW_SIZE(regnum) == 8) |
| 2116 | { /* show 8-byte floats as float AND double: */ |
| 2117 | int offset = 4 * (TARGET_BYTE_ORDER == BIG_ENDIAN); |
| 2118 | |
| 2119 | printf_filtered (" (float) "); |
| 2120 | val_print (builtin_type_float, raw_buffer + offset, 0, |
| 2121 | gdb_stdout, 0, 1, 0, Val_pretty_default); |
| 2122 | printf_filtered (", (double) "); |
| 2123 | val_print (builtin_type_double, raw_buffer, 0, |
| 2124 | gdb_stdout, 0, 1, 0, Val_pretty_default); |
| 2125 | } |
| 2126 | else |
| 2127 | val_print (REGISTER_VIRTUAL_TYPE (regnum), raw_buffer, 0, |
| 2128 | gdb_stdout, 0, 1, 0, Val_pretty_default); |
| 2129 | /* Else print as integer in hex. */ |
| 2130 | else |
| 2131 | print_scalar_formatted (raw_buffer, REGISTER_VIRTUAL_TYPE (regnum), |
| 2132 | 'x', 0, gdb_stdout); |
| 2133 | } |
| 2134 | |
| 2135 | /* Replacement for generic do_registers_info. |
| 2136 | Print regs in pretty columns. */ |
| 2137 | |
| 2138 | static int |
| 2139 | do_fp_register_row (regnum) |
| 2140 | int regnum; |
| 2141 | { /* do values for FP (float) regs */ |
| 2142 | char *raw_buffer[2]; |
| 2143 | char *dbl_buffer; |
| 2144 | /* use HI and LO to control the order of combining two flt regs */ |
| 2145 | int HI = (TARGET_BYTE_ORDER == BIG_ENDIAN); |
| 2146 | int LO = (TARGET_BYTE_ORDER != BIG_ENDIAN); |
| 2147 | double doub, flt1, flt2; /* doubles extracted from raw hex data */ |
| 2148 | int inv1, inv2, inv3; |
| 2149 | |
| 2150 | raw_buffer[0] = (char *) alloca (REGISTER_RAW_SIZE (FP0_REGNUM)); |
| 2151 | raw_buffer[1] = (char *) alloca (REGISTER_RAW_SIZE (FP0_REGNUM)); |
| 2152 | dbl_buffer = (char *) alloca (2 * REGISTER_RAW_SIZE (FP0_REGNUM)); |
| 2153 | |
| 2154 | /* Get the data in raw format. */ |
| 2155 | if (read_relative_register_raw_bytes (regnum, raw_buffer[HI])) |
| 2156 | error ("can't read register %d (%s)", regnum, reg_names[regnum]); |
| 2157 | if (REGISTER_RAW_SIZE(regnum) == 4) |
| 2158 | { |
| 2159 | /* 4-byte registers: we can fit two registers per row. */ |
| 2160 | /* Also print every pair of 4-byte regs as an 8-byte double. */ |
| 2161 | if (read_relative_register_raw_bytes (regnum + 1, raw_buffer[LO])) |
| 2162 | error ("can't read register %d (%s)", |
| 2163 | regnum + 1, reg_names[regnum + 1]); |
| 2164 | |
| 2165 | /* copy the two floats into one double, and unpack both */ |
| 2166 | memcpy (dbl_buffer, raw_buffer, sizeof(dbl_buffer)); |
| 2167 | flt1 = unpack_double (builtin_type_float, raw_buffer[HI], &inv1); |
| 2168 | flt2 = unpack_double (builtin_type_float, raw_buffer[LO], &inv2); |
| 2169 | doub = unpack_double (builtin_type_double, dbl_buffer, &inv3); |
| 2170 | |
| 2171 | printf_filtered (inv1 ? " %-5s: <invalid float>" : |
| 2172 | " %-5s%-17.9g", reg_names[regnum], flt1); |
| 2173 | printf_filtered (inv2 ? " %-5s: <invalid float>" : |
| 2174 | " %-5s%-17.9g", reg_names[regnum + 1], flt2); |
| 2175 | printf_filtered (inv3 ? " dbl: <invalid double>\n" : |
| 2176 | " dbl: %-24.17g\n", doub); |
| 2177 | /* may want to do hex display here (future enhancement) */ |
| 2178 | regnum +=2; |
| 2179 | } |
| 2180 | else |
| 2181 | { /* eight byte registers: print each one as float AND as double. */ |
| 2182 | int offset = 4 * (TARGET_BYTE_ORDER == BIG_ENDIAN); |
| 2183 | |
| 2184 | memcpy (dbl_buffer, raw_buffer[HI], sizeof(dbl_buffer)); |
| 2185 | flt1 = unpack_double (builtin_type_float, |
| 2186 | &raw_buffer[HI][offset], &inv1); |
| 2187 | doub = unpack_double (builtin_type_double, dbl_buffer, &inv3); |
| 2188 | |
| 2189 | printf_filtered (inv1 ? " %-5s: <invalid float>" : |
| 2190 | " %-5s flt: %-17.9g", reg_names[regnum], flt1); |
| 2191 | printf_filtered (inv3 ? " dbl: <invalid double>\n" : |
| 2192 | " dbl: %-24.17g\n", doub); |
| 2193 | /* may want to do hex display here (future enhancement) */ |
| 2194 | regnum++; |
| 2195 | } |
| 2196 | return regnum; |
| 2197 | } |
| 2198 | |
| 2199 | /* Print a row's worth of GP (int) registers, with name labels above */ |
| 2200 | |
| 2201 | static int |
| 2202 | do_gp_register_row (regnum) |
| 2203 | int regnum; |
| 2204 | { |
| 2205 | /* do values for GP (int) regs */ |
| 2206 | char raw_buffer[MAX_REGISTER_RAW_SIZE]; |
| 2207 | int ncols = (MIPS_REGSIZE == 8 ? 4 : 8); /* display cols per row */ |
| 2208 | int col, byte; |
| 2209 | int start_regnum = regnum; |
| 2210 | int numregs = NUM_REGS; |
| 2211 | |
| 2212 | /* start-sanitize-sky */ |
| 2213 | #ifdef NUM_R5900_REGS |
| 2214 | numregs = NUM_R5900_REGS; |
| 2215 | #endif |
| 2216 | /* end-sanitize-sky */ |
| 2217 | |
| 2218 | /* For GP registers, we print a separate row of names above the vals */ |
| 2219 | printf_filtered (" "); |
| 2220 | for (col = 0; col < ncols && regnum < numregs; regnum++) |
| 2221 | { |
| 2222 | if (*reg_names[regnum] == '\0') |
| 2223 | continue; /* unused register */ |
| 2224 | if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT) |
| 2225 | break; /* end the row: reached FP register */ |
| 2226 | printf_filtered (MIPS_REGSIZE == 8 ? "%17s" : "%9s", |
| 2227 | reg_names[regnum]); |
| 2228 | col++; |
| 2229 | } |
| 2230 | printf_filtered (start_regnum < MIPS_NUMREGS ? "\n R%-4d" : "\n ", |
| 2231 | start_regnum); /* print the R0 to R31 names */ |
| 2232 | |
| 2233 | regnum = start_regnum; /* go back to start of row */ |
| 2234 | /* now print the values in hex, 4 or 8 to the row */ |
| 2235 | for (col = 0; col < ncols && regnum < numregs; regnum++) |
| 2236 | { |
| 2237 | if (*reg_names[regnum] == '\0') |
| 2238 | continue; /* unused register */ |
| 2239 | if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT) |
| 2240 | break; /* end row: reached FP register */ |
| 2241 | /* OK: get the data in raw format. */ |
| 2242 | if (read_relative_register_raw_bytes (regnum, raw_buffer)) |
| 2243 | error ("can't read register %d (%s)", regnum, reg_names[regnum]); |
| 2244 | /* pad small registers */ |
| 2245 | for (byte = 0; byte < (MIPS_REGSIZE - REGISTER_RAW_SIZE (regnum)); byte++) |
| 2246 | printf_filtered (" "); |
| 2247 | /* Now print the register value in hex, endian order. */ |
| 2248 | if (TARGET_BYTE_ORDER == BIG_ENDIAN) |
| 2249 | for (byte = 0; byte < REGISTER_RAW_SIZE (regnum); byte++) |
| 2250 | printf_filtered ("%02x", (unsigned char) raw_buffer[byte]); |
| 2251 | else |
| 2252 | for (byte = REGISTER_RAW_SIZE (regnum) - 1; byte >= 0; byte--) |
| 2253 | printf_filtered ("%02x", (unsigned char) raw_buffer[byte]); |
| 2254 | printf_filtered (" "); |
| 2255 | col++; |
| 2256 | } |
| 2257 | if (col > 0) /* ie. if we actually printed anything... */ |
| 2258 | printf_filtered ("\n"); |
| 2259 | |
| 2260 | return regnum; |
| 2261 | } |
| 2262 | |
| 2263 | /* MIPS_DO_REGISTERS_INFO(): called by "info register" command */ |
| 2264 | |
| 2265 | void |
| 2266 | mips_do_registers_info (regnum, fpregs) |
| 2267 | int regnum; |
| 2268 | int fpregs; |
| 2269 | { |
| 2270 | if (regnum != -1) /* do one specified register */ |
| 2271 | { |
| 2272 | if (*(reg_names[regnum]) == '\0') |
| 2273 | error ("Not a valid register for the current processor type"); |
| 2274 | |
| 2275 | mips_print_register (regnum, 0); |
| 2276 | printf_filtered ("\n"); |
| 2277 | } |
| 2278 | else /* do all (or most) registers */ |
| 2279 | { |
| 2280 | regnum = 0; |
| 2281 | while (regnum < NUM_REGS) |
| 2282 | { |
| 2283 | if (TYPE_CODE(REGISTER_VIRTUAL_TYPE (regnum)) == TYPE_CODE_FLT) |
| 2284 | if (fpregs) /* true for "INFO ALL-REGISTERS" command */ |
| 2285 | regnum = do_fp_register_row (regnum); /* FP regs */ |
| 2286 | else |
| 2287 | regnum += MIPS_NUMREGS; /* skip floating point regs */ |
| 2288 | else |
| 2289 | regnum = do_gp_register_row (regnum); /* GP (int) regs */ |
| 2290 | /* start-sanitize-sky */ |
| 2291 | #ifdef NUM_R5900_REGS |
| 2292 | /* For the sky project, NUM_REGS includes the vector slaves, |
| 2293 | which are handled elsewhere */ |
| 2294 | if (regnum >= NUM_R5900_REGS) |
| 2295 | break; |
| 2296 | #endif |
| 2297 | /* end-sanitize-sky */ |
| 2298 | } |
| 2299 | } |
| 2300 | } |
| 2301 | |
| 2302 | /* Return number of args passed to a frame. described by FIP. |
| 2303 | Can return -1, meaning no way to tell. */ |
| 2304 | |
| 2305 | int |
| 2306 | mips_frame_num_args (frame) |
| 2307 | struct frame_info *frame; |
| 2308 | { |
| 2309 | #if 0 /* FIXME Use or lose this! */ |
| 2310 | struct chain_info_t *p; |
| 2311 | |
| 2312 | p = mips_find_cached_frame (FRAME_FP (frame)); |
| 2313 | if (p->valid) |
| 2314 | return p->the_info.numargs; |
| 2315 | #endif |
| 2316 | return -1; |
| 2317 | } |
| 2318 | |
| 2319 | /* Is this a branch with a delay slot? */ |
| 2320 | |
| 2321 | static int is_delayed PARAMS ((unsigned long)); |
| 2322 | |
| 2323 | static int |
| 2324 | is_delayed (insn) |
| 2325 | unsigned long insn; |
| 2326 | { |
| 2327 | int i; |
| 2328 | for (i = 0; i < NUMOPCODES; ++i) |
| 2329 | if (mips_opcodes[i].pinfo != INSN_MACRO |
| 2330 | && (insn & mips_opcodes[i].mask) == mips_opcodes[i].match) |
| 2331 | break; |
| 2332 | return (i < NUMOPCODES |
| 2333 | && (mips_opcodes[i].pinfo & (INSN_UNCOND_BRANCH_DELAY |
| 2334 | | INSN_COND_BRANCH_DELAY |
| 2335 | | INSN_COND_BRANCH_LIKELY))); |
| 2336 | } |
| 2337 | |
| 2338 | int |
| 2339 | mips_step_skips_delay (pc) |
| 2340 | CORE_ADDR pc; |
| 2341 | { |
| 2342 | char buf[MIPS_INSTLEN]; |
| 2343 | |
| 2344 | /* There is no branch delay slot on MIPS16. */ |
| 2345 | if (pc_is_mips16 (pc)) |
| 2346 | return 0; |
| 2347 | |
| 2348 | if (target_read_memory (pc, buf, MIPS_INSTLEN) != 0) |
| 2349 | /* If error reading memory, guess that it is not a delayed branch. */ |
| 2350 | return 0; |
| 2351 | return is_delayed ((unsigned long)extract_unsigned_integer (buf, MIPS_INSTLEN)); |
| 2352 | } |
| 2353 | |
| 2354 | |
| 2355 | /* Skip the PC past function prologue instructions (32-bit version). |
| 2356 | This is a helper function for mips_skip_prologue. */ |
| 2357 | |
| 2358 | static CORE_ADDR |
| 2359 | mips32_skip_prologue (pc, lenient) |
| 2360 | CORE_ADDR pc; /* starting PC to search from */ |
| 2361 | int lenient; |
| 2362 | { |
| 2363 | t_inst inst; |
| 2364 | CORE_ADDR end_pc; |
| 2365 | int seen_sp_adjust = 0; |
| 2366 | int load_immediate_bytes = 0; |
| 2367 | |
| 2368 | /* Skip the typical prologue instructions. These are the stack adjustment |
| 2369 | instruction and the instructions that save registers on the stack |
| 2370 | or in the gcc frame. */ |
| 2371 | for (end_pc = pc + 100; pc < end_pc; pc += MIPS_INSTLEN) |
| 2372 | { |
| 2373 | unsigned long high_word; |
| 2374 | |
| 2375 | inst = mips_fetch_instruction (pc); |
| 2376 | high_word = (inst >> 16) & 0xffff; |
| 2377 | |
| 2378 | #if 0 |
| 2379 | if (lenient && is_delayed (inst)) |
| 2380 | continue; |
| 2381 | #endif |
| 2382 | |
| 2383 | if (high_word == 0x27bd /* addiu $sp,$sp,offset */ |
| 2384 | || high_word == 0x67bd) /* daddiu $sp,$sp,offset */ |
| 2385 | seen_sp_adjust = 1; |
| 2386 | else if (inst == 0x03a1e823 || /* subu $sp,$sp,$at */ |
| 2387 | inst == 0x03a8e823) /* subu $sp,$sp,$t0 */ |
| 2388 | seen_sp_adjust = 1; |
| 2389 | else if (((inst & 0xFFE00000) == 0xAFA00000 /* sw reg,n($sp) */ |
| 2390 | || (inst & 0xFFE00000) == 0xFFA00000) /* sd reg,n($sp) */ |
| 2391 | && (inst & 0x001F0000)) /* reg != $zero */ |
| 2392 | continue; |
| 2393 | |
| 2394 | else if ((inst & 0xFFE00000) == 0xE7A00000) /* swc1 freg,n($sp) */ |
| 2395 | continue; |
| 2396 | else if ((inst & 0xF3E00000) == 0xA3C00000 && (inst & 0x001F0000)) |
| 2397 | /* sx reg,n($s8) */ |
| 2398 | continue; /* reg != $zero */ |
| 2399 | |
| 2400 | /* move $s8,$sp. With different versions of gas this will be either |
| 2401 | `addu $s8,$sp,$zero' or `or $s8,$sp,$zero' or `daddu s8,sp,$0'. |
| 2402 | Accept any one of these. */ |
| 2403 | else if (inst == 0x03A0F021 || inst == 0x03a0f025 || inst == 0x03a0f02d) |
| 2404 | continue; |
| 2405 | |
| 2406 | else if ((inst & 0xFF9F07FF) == 0x00800021) /* move reg,$a0-$a3 */ |
| 2407 | continue; |
| 2408 | else if (high_word == 0x3c1c) /* lui $gp,n */ |
| 2409 | continue; |
| 2410 | else if (high_word == 0x279c) /* addiu $gp,$gp,n */ |
| 2411 | continue; |
| 2412 | else if (inst == 0x0399e021 /* addu $gp,$gp,$t9 */ |
| 2413 | || inst == 0x033ce021) /* addu $gp,$t9,$gp */ |
| 2414 | continue; |
| 2415 | /* The following instructions load $at or $t0 with an immediate |
| 2416 | value in preparation for a stack adjustment via |
| 2417 | subu $sp,$sp,[$at,$t0]. These instructions could also initialize |
| 2418 | a local variable, so we accept them only before a stack adjustment |
| 2419 | instruction was seen. */ |
| 2420 | else if (!seen_sp_adjust) |
| 2421 | { |
| 2422 | if (high_word == 0x3c01 || /* lui $at,n */ |
| 2423 | high_word == 0x3c08) /* lui $t0,n */ |
| 2424 | { |
| 2425 | load_immediate_bytes += MIPS_INSTLEN; /* FIXME!! */ |
| 2426 | continue; |
| 2427 | } |
| 2428 | else if (high_word == 0x3421 || /* ori $at,$at,n */ |
| 2429 | high_word == 0x3508 || /* ori $t0,$t0,n */ |
| 2430 | high_word == 0x3401 || /* ori $at,$zero,n */ |
| 2431 | high_word == 0x3408) /* ori $t0,$zero,n */ |
| 2432 | { |
| 2433 | load_immediate_bytes += MIPS_INSTLEN; /* FIXME!! */ |
| 2434 | continue; |
| 2435 | } |
| 2436 | else |
| 2437 | break; |
| 2438 | } |
| 2439 | else |
| 2440 | break; |
| 2441 | } |
| 2442 | |
| 2443 | /* In a frameless function, we might have incorrectly |
| 2444 | skipped some load immediate instructions. Undo the skipping |
| 2445 | if the load immediate was not followed by a stack adjustment. */ |
| 2446 | if (load_immediate_bytes && !seen_sp_adjust) |
| 2447 | pc -= load_immediate_bytes; |
| 2448 | return pc; |
| 2449 | } |
| 2450 | |
| 2451 | /* Skip the PC past function prologue instructions (16-bit version). |
| 2452 | This is a helper function for mips_skip_prologue. */ |
| 2453 | |
| 2454 | static CORE_ADDR |
| 2455 | mips16_skip_prologue (pc, lenient) |
| 2456 | CORE_ADDR pc; /* starting PC to search from */ |
| 2457 | int lenient; |
| 2458 | { |
| 2459 | CORE_ADDR end_pc; |
| 2460 | int extend_bytes = 0; |
| 2461 | int prev_extend_bytes; |
| 2462 | |
| 2463 | /* Table of instructions likely to be found in a function prologue. */ |
| 2464 | static struct |
| 2465 | { |
| 2466 | unsigned short inst; |
| 2467 | unsigned short mask; |
| 2468 | } table[] = |
| 2469 | { |
| 2470 | { 0x6300, 0xff00 }, /* addiu $sp,offset */ |
| 2471 | { 0xfb00, 0xff00 }, /* daddiu $sp,offset */ |
| 2472 | { 0xd000, 0xf800 }, /* sw reg,n($sp) */ |
| 2473 | { 0xf900, 0xff00 }, /* sd reg,n($sp) */ |
| 2474 | { 0x6200, 0xff00 }, /* sw $ra,n($sp) */ |
| 2475 | { 0xfa00, 0xff00 }, /* sd $ra,n($sp) */ |
| 2476 | { 0x673d, 0xffff }, /* move $s1,sp */ |
| 2477 | { 0xd980, 0xff80 }, /* sw $a0-$a3,n($s1) */ |
| 2478 | { 0x6704, 0xff1c }, /* move reg,$a0-$a3 */ |
| 2479 | { 0xe809, 0xf81f }, /* entry pseudo-op */ |
| 2480 | { 0x0100, 0xff00 }, /* addiu $s1,$sp,n */ |
| 2481 | { 0, 0 } /* end of table marker */ |
| 2482 | }; |
| 2483 | |
| 2484 | /* Skip the typical prologue instructions. These are the stack adjustment |
| 2485 | instruction and the instructions that save registers on the stack |
| 2486 | or in the gcc frame. */ |
| 2487 | for (end_pc = pc + 100; pc < end_pc; pc += MIPS16_INSTLEN) |
| 2488 | { |
| 2489 | unsigned short inst; |
| 2490 | int i; |
| 2491 | |
| 2492 | inst = mips_fetch_instruction (pc); |
| 2493 | |
| 2494 | /* Normally we ignore an extend instruction. However, if it is |
| 2495 | not followed by a valid prologue instruction, we must adjust |
| 2496 | the pc back over the extend so that it won't be considered |
| 2497 | part of the prologue. */ |
| 2498 | if ((inst & 0xf800) == 0xf000) /* extend */ |
| 2499 | { |
| 2500 | extend_bytes = MIPS16_INSTLEN; |
| 2501 | continue; |
| 2502 | } |
| 2503 | prev_extend_bytes = extend_bytes; |
| 2504 | extend_bytes = 0; |
| 2505 | |
| 2506 | /* Check for other valid prologue instructions besides extend. */ |
| 2507 | for (i = 0; table[i].mask != 0; i++) |
| 2508 | if ((inst & table[i].mask) == table[i].inst) /* found, get out */ |
| 2509 | break; |
| 2510 | if (table[i].mask != 0) /* it was in table? */ |
| 2511 | continue; /* ignore it */ |
| 2512 | else /* non-prologue */ |
| 2513 | { |
| 2514 | /* Return the current pc, adjusted backwards by 2 if |
| 2515 | the previous instruction was an extend. */ |
| 2516 | return pc - prev_extend_bytes; |
| 2517 | } |
| 2518 | } |
| 2519 | return pc; |
| 2520 | } |
| 2521 | |
| 2522 | /* To skip prologues, I use this predicate. Returns either PC itself |
| 2523 | if the code at PC does not look like a function prologue; otherwise |
| 2524 | returns an address that (if we're lucky) follows the prologue. If |
| 2525 | LENIENT, then we must skip everything which is involved in setting |
| 2526 | up the frame (it's OK to skip more, just so long as we don't skip |
| 2527 | anything which might clobber the registers which are being saved. |
| 2528 | We must skip more in the case where part of the prologue is in the |
| 2529 | delay slot of a non-prologue instruction). */ |
| 2530 | |
| 2531 | CORE_ADDR |
| 2532 | mips_skip_prologue (pc, lenient) |
| 2533 | CORE_ADDR pc; |
| 2534 | int lenient; |
| 2535 | { |
| 2536 | /* See if we can determine the end of the prologue via the symbol table. |
| 2537 | If so, then return either PC, or the PC after the prologue, whichever |
| 2538 | is greater. */ |
| 2539 | |
| 2540 | CORE_ADDR post_prologue_pc = after_prologue (pc, NULL); |
| 2541 | |
| 2542 | if (post_prologue_pc != 0) |
| 2543 | return max (pc, post_prologue_pc); |
| 2544 | |
| 2545 | /* Can't determine prologue from the symbol table, need to examine |
| 2546 | instructions. */ |
| 2547 | |
| 2548 | if (pc_is_mips16 (pc)) |
| 2549 | return mips16_skip_prologue (pc, lenient); |
| 2550 | else |
| 2551 | return mips32_skip_prologue (pc, lenient); |
| 2552 | } |
| 2553 | |
| 2554 | #if 0 |
| 2555 | /* The lenient prologue stuff should be superseded by the code in |
| 2556 | init_extra_frame_info which looks to see whether the stores mentioned |
| 2557 | in the proc_desc have actually taken place. */ |
| 2558 | |
| 2559 | /* Is address PC in the prologue (loosely defined) for function at |
| 2560 | STARTADDR? */ |
| 2561 | |
| 2562 | static int |
| 2563 | mips_in_lenient_prologue (startaddr, pc) |
| 2564 | CORE_ADDR startaddr; |
| 2565 | CORE_ADDR pc; |
| 2566 | { |
| 2567 | CORE_ADDR end_prologue = mips_skip_prologue (startaddr, 1); |
| 2568 | return pc >= startaddr && pc < end_prologue; |
| 2569 | } |
| 2570 | #endif |
| 2571 | |
| 2572 | /* Given a return value in `regbuf' with a type `valtype', |
| 2573 | extract and copy its value into `valbuf'. */ |
| 2574 | void |
| 2575 | mips_extract_return_value (valtype, regbuf, valbuf) |
| 2576 | struct type *valtype; |
| 2577 | char regbuf[REGISTER_BYTES]; |
| 2578 | char *valbuf; |
| 2579 | { |
| 2580 | int regnum; |
| 2581 | int offset = 0; |
| 2582 | int len = TYPE_LENGTH (valtype); |
| 2583 | |
| 2584 | regnum = 2; |
| 2585 | if (TYPE_CODE (valtype) == TYPE_CODE_FLT |
| 2586 | && (mips_fpu == MIPS_FPU_DOUBLE |
| 2587 | || (mips_fpu == MIPS_FPU_SINGLE && len <= MIPS_FPU_SINGLE_REGSIZE))) |
| 2588 | regnum = FP0_REGNUM; |
| 2589 | |
| 2590 | if (TARGET_BYTE_ORDER == BIG_ENDIAN) |
| 2591 | { /* "un-left-justify" the value from the register */ |
| 2592 | if (len < REGISTER_RAW_SIZE (regnum)) |
| 2593 | offset = REGISTER_RAW_SIZE (regnum) - len; |
| 2594 | if (len > REGISTER_RAW_SIZE (regnum) && /* odd-size structs */ |
| 2595 | len < REGISTER_RAW_SIZE (regnum) * 2 && |
| 2596 | (TYPE_CODE (valtype) == TYPE_CODE_STRUCT || |
| 2597 | TYPE_CODE (valtype) == TYPE_CODE_UNION)) |
| 2598 | offset = 2 * REGISTER_RAW_SIZE (regnum) - len; |
| 2599 | } |
| 2600 | memcpy (valbuf, regbuf + REGISTER_BYTE (regnum) + offset, len); |
| 2601 | REGISTER_CONVERT_TO_TYPE (regnum, valtype, valbuf); |
| 2602 | } |
| 2603 | |
| 2604 | /* Given a return value in `regbuf' with a type `valtype', |
| 2605 | write it's value into the appropriate register. */ |
| 2606 | void |
| 2607 | mips_store_return_value (valtype, valbuf) |
| 2608 | struct type *valtype; |
| 2609 | char *valbuf; |
| 2610 | { |
| 2611 | int regnum; |
| 2612 | int offset = 0; |
| 2613 | int len = TYPE_LENGTH (valtype); |
| 2614 | char raw_buffer[MAX_REGISTER_RAW_SIZE]; |
| 2615 | |
| 2616 | regnum = 2; |
| 2617 | if (TYPE_CODE (valtype) == TYPE_CODE_FLT |
| 2618 | && (mips_fpu == MIPS_FPU_DOUBLE |
| 2619 | || (mips_fpu == MIPS_FPU_SINGLE && len <= MIPS_REGSIZE))) |
| 2620 | regnum = FP0_REGNUM; |
| 2621 | |
| 2622 | if (TARGET_BYTE_ORDER == BIG_ENDIAN) |
| 2623 | { /* "left-justify" the value in the register */ |
| 2624 | if (len < REGISTER_RAW_SIZE (regnum)) |
| 2625 | offset = REGISTER_RAW_SIZE (regnum) - len; |
| 2626 | if (len > REGISTER_RAW_SIZE (regnum) && /* odd-size structs */ |
| 2627 | len < REGISTER_RAW_SIZE (regnum) * 2 && |
| 2628 | (TYPE_CODE (valtype) == TYPE_CODE_STRUCT || |
| 2629 | TYPE_CODE (valtype) == TYPE_CODE_UNION)) |
| 2630 | offset = 2 * REGISTER_RAW_SIZE (regnum) - len; |
| 2631 | } |
| 2632 | memcpy(raw_buffer + offset, valbuf, len); |
| 2633 | REGISTER_CONVERT_FROM_TYPE(regnum, valtype, raw_buffer); |
| 2634 | write_register_bytes(REGISTER_BYTE (regnum), raw_buffer, |
| 2635 | len > REGISTER_RAW_SIZE (regnum) ? |
| 2636 | len : REGISTER_RAW_SIZE (regnum)); |
| 2637 | } |
| 2638 | |
| 2639 | /* Exported procedure: Is PC in the signal trampoline code */ |
| 2640 | |
| 2641 | int |
| 2642 | in_sigtramp (pc, ignore) |
| 2643 | CORE_ADDR pc; |
| 2644 | char *ignore; /* function name */ |
| 2645 | { |
| 2646 | if (sigtramp_address == 0) |
| 2647 | fixup_sigtramp (); |
| 2648 | return (pc >= sigtramp_address && pc < sigtramp_end); |
| 2649 | } |
| 2650 | |
| 2651 | /* Command to set FPU type. mips_fpu_string will have been set to the |
| 2652 | user's argument. Set mips_fpu based on mips_fpu_string, and then |
| 2653 | canonicalize mips_fpu_string. */ |
| 2654 | |
| 2655 | /*ARGSUSED*/ |
| 2656 | static void |
| 2657 | mips_set_fpu_command (args, from_tty, c) |
| 2658 | char *args; |
| 2659 | int from_tty; |
| 2660 | struct cmd_list_element *c; |
| 2661 | { |
| 2662 | char *err = NULL; |
| 2663 | |
| 2664 | if (mips_fpu_string == NULL || *mips_fpu_string == '\0') |
| 2665 | mips_fpu = MIPS_FPU_DOUBLE; |
| 2666 | else if (strcasecmp (mips_fpu_string, "double") == 0 |
| 2667 | || strcasecmp (mips_fpu_string, "on") == 0 |
| 2668 | || strcasecmp (mips_fpu_string, "1") == 0 |
| 2669 | || strcasecmp (mips_fpu_string, "yes") == 0) |
| 2670 | mips_fpu = MIPS_FPU_DOUBLE; |
| 2671 | else if (strcasecmp (mips_fpu_string, "none") == 0 |
| 2672 | || strcasecmp (mips_fpu_string, "off") == 0 |
| 2673 | || strcasecmp (mips_fpu_string, "0") == 0 |
| 2674 | || strcasecmp (mips_fpu_string, "no") == 0) |
| 2675 | mips_fpu = MIPS_FPU_NONE; |
| 2676 | else if (strcasecmp (mips_fpu_string, "single") == 0) |
| 2677 | mips_fpu = MIPS_FPU_SINGLE; |
| 2678 | else |
| 2679 | err = strsave (mips_fpu_string); |
| 2680 | |
| 2681 | if (mips_fpu_string != NULL) |
| 2682 | free (mips_fpu_string); |
| 2683 | |
| 2684 | switch (mips_fpu) |
| 2685 | { |
| 2686 | case MIPS_FPU_DOUBLE: |
| 2687 | mips_fpu_string = strsave ("double"); |
| 2688 | break; |
| 2689 | case MIPS_FPU_SINGLE: |
| 2690 | mips_fpu_string = strsave ("single"); |
| 2691 | break; |
| 2692 | case MIPS_FPU_NONE: |
| 2693 | mips_fpu_string = strsave ("none"); |
| 2694 | break; |
| 2695 | } |
| 2696 | |
| 2697 | if (err != NULL) |
| 2698 | { |
| 2699 | struct cleanup *cleanups = make_cleanup (free, err); |
| 2700 | error ("Unknown FPU type `%s'. Use `double', `none', or `single'.", |
| 2701 | err); |
| 2702 | do_cleanups (cleanups); |
| 2703 | } |
| 2704 | } |
| 2705 | |
| 2706 | static void |
| 2707 | mips_show_fpu_command (args, from_tty, c) |
| 2708 | char *args; |
| 2709 | int from_tty; |
| 2710 | struct cmd_list_element *c; |
| 2711 | { |
| 2712 | } |
| 2713 | |
| 2714 | /* Command to set the processor type. */ |
| 2715 | |
| 2716 | void |
| 2717 | mips_set_processor_type_command (args, from_tty) |
| 2718 | char *args; |
| 2719 | int from_tty; |
| 2720 | { |
| 2721 | int i; |
| 2722 | |
| 2723 | if (tmp_mips_processor_type == NULL || *tmp_mips_processor_type == '\0') |
| 2724 | { |
| 2725 | printf_unfiltered ("The known MIPS processor types are as follows:\n\n"); |
| 2726 | for (i = 0; mips_processor_type_table[i].name != NULL; ++i) |
| 2727 | printf_unfiltered ("%s\n", mips_processor_type_table[i].name); |
| 2728 | |
| 2729 | /* Restore the value. */ |
| 2730 | tmp_mips_processor_type = strsave (mips_processor_type); |
| 2731 | |
| 2732 | return; |
| 2733 | } |
| 2734 | |
| 2735 | if (!mips_set_processor_type (tmp_mips_processor_type)) |
| 2736 | { |
| 2737 | error ("Unknown processor type `%s'.", tmp_mips_processor_type); |
| 2738 | /* Restore its value. */ |
| 2739 | tmp_mips_processor_type = strsave (mips_processor_type); |
| 2740 | } |
| 2741 | } |
| 2742 | |
| 2743 | static void |
| 2744 | mips_show_processor_type_command (args, from_tty) |
| 2745 | char *args; |
| 2746 | int from_tty; |
| 2747 | { |
| 2748 | } |
| 2749 | |
| 2750 | /* Modify the actual processor type. */ |
| 2751 | |
| 2752 | int |
| 2753 | mips_set_processor_type (str) |
| 2754 | char *str; |
| 2755 | { |
| 2756 | int i, j; |
| 2757 | |
| 2758 | if (str == NULL) |
| 2759 | return 0; |
| 2760 | |
| 2761 | for (i = 0; mips_processor_type_table[i].name != NULL; ++i) |
| 2762 | { |
| 2763 | if (strcasecmp (str, mips_processor_type_table[i].name) == 0) |
| 2764 | { |
| 2765 | mips_processor_type = str; |
| 2766 | |
| 2767 | for (j = 0; j < NUM_REGS; ++j) |
| 2768 | reg_names[j] = mips_processor_type_table[i].regnames[j]; |
| 2769 | |
| 2770 | return 1; |
| 2771 | |
| 2772 | /* FIXME tweak fpu flag too */ |
| 2773 | } |
| 2774 | } |
| 2775 | |
| 2776 | return 0; |
| 2777 | } |
| 2778 | |
| 2779 | /* Attempt to identify the particular processor model by reading the |
| 2780 | processor id. */ |
| 2781 | |
| 2782 | char * |
| 2783 | mips_read_processor_type () |
| 2784 | { |
| 2785 | CORE_ADDR prid; |
| 2786 | |
| 2787 | prid = read_register (PRID_REGNUM); |
| 2788 | |
| 2789 | if ((prid & ~0xf) == 0x700) |
| 2790 | return savestring ("r3041", strlen("r3041")); |
| 2791 | |
| 2792 | return NULL; |
| 2793 | } |
| 2794 | |
| 2795 | /* Just like reinit_frame_cache, but with the right arguments to be |
| 2796 | callable as an sfunc. */ |
| 2797 | |
| 2798 | static void |
| 2799 | reinit_frame_cache_sfunc (args, from_tty, c) |
| 2800 | char *args; |
| 2801 | int from_tty; |
| 2802 | struct cmd_list_element *c; |
| 2803 | { |
| 2804 | reinit_frame_cache (); |
| 2805 | } |
| 2806 | |
| 2807 | int |
| 2808 | gdb_print_insn_mips (memaddr, info) |
| 2809 | bfd_vma memaddr; |
| 2810 | disassemble_info *info; |
| 2811 | { |
| 2812 | mips_extra_func_info_t proc_desc; |
| 2813 | |
| 2814 | /* Search for the function containing this address. Set the low bit |
| 2815 | of the address when searching, in case we were given an even address |
| 2816 | that is the start of a 16-bit function. If we didn't do this, |
| 2817 | the search would fail because the symbol table says the function |
| 2818 | starts at an odd address, i.e. 1 byte past the given address. */ |
| 2819 | memaddr = ADDR_BITS_REMOVE (memaddr); |
| 2820 | proc_desc = non_heuristic_proc_desc (MAKE_MIPS16_ADDR (memaddr), NULL); |
| 2821 | |
| 2822 | /* Make an attempt to determine if this is a 16-bit function. If |
| 2823 | the procedure descriptor exists and the address therein is odd, |
| 2824 | it's definitely a 16-bit function. Otherwise, we have to just |
| 2825 | guess that if the address passed in is odd, it's 16-bits. */ |
| 2826 | if (proc_desc) |
| 2827 | info->mach = pc_is_mips16 (PROC_LOW_ADDR (proc_desc)) ? 16 : TM_PRINT_INSN_MACH; |
| 2828 | else |
| 2829 | info->mach = pc_is_mips16 (memaddr) ? 16 : TM_PRINT_INSN_MACH; |
| 2830 | |
| 2831 | /* Round down the instruction address to the appropriate boundary. */ |
| 2832 | memaddr &= (info->mach == 16 ? ~1 : ~3); |
| 2833 | |
| 2834 | /* Call the appropriate disassembler based on the target endian-ness. */ |
| 2835 | if (TARGET_BYTE_ORDER == BIG_ENDIAN) |
| 2836 | return print_insn_big_mips (memaddr, info); |
| 2837 | else |
| 2838 | return print_insn_little_mips (memaddr, info); |
| 2839 | } |
| 2840 | |
| 2841 | /* This function implements the BREAKPOINT_FROM_PC macro. It uses the program |
| 2842 | counter value to determine whether a 16- or 32-bit breakpoint should be |
| 2843 | used. It returns a pointer to a string of bytes that encode a breakpoint |
| 2844 | instruction, stores the length of the string to *lenptr, and adjusts pc |
| 2845 | (if necessary) to point to the actual memory location where the |
| 2846 | breakpoint should be inserted. */ |
| 2847 | |
| 2848 | unsigned char *mips_breakpoint_from_pc (pcptr, lenptr) |
| 2849 | CORE_ADDR *pcptr; |
| 2850 | int *lenptr; |
| 2851 | { |
| 2852 | if (TARGET_BYTE_ORDER == BIG_ENDIAN) |
| 2853 | { |
| 2854 | if (pc_is_mips16 (*pcptr)) |
| 2855 | { |
| 2856 | static char mips16_big_breakpoint[] = MIPS16_BIG_BREAKPOINT; |
| 2857 | *pcptr = UNMAKE_MIPS16_ADDR (*pcptr); |
| 2858 | *lenptr = sizeof(mips16_big_breakpoint); |
| 2859 | return mips16_big_breakpoint; |
| 2860 | } |
| 2861 | else |
| 2862 | { |
| 2863 | static char big_breakpoint[] = BIG_BREAKPOINT; |
| 2864 | static char pmon_big_breakpoint[] = PMON_BIG_BREAKPOINT; |
| 2865 | static char idt_big_breakpoint[] = IDT_BIG_BREAKPOINT; |
| 2866 | |
| 2867 | *lenptr = sizeof(big_breakpoint); |
| 2868 | |
| 2869 | if (strcmp (target_shortname, "mips") == 0) |
| 2870 | return idt_big_breakpoint; |
| 2871 | else if (strcmp (target_shortname, "ddb") == 0 |
| 2872 | || strcmp (target_shortname, "pmon") == 0 |
| 2873 | || strcmp (target_shortname, "lsi") == 0) |
| 2874 | return pmon_big_breakpoint; |
| 2875 | else |
| 2876 | return big_breakpoint; |
| 2877 | } |
| 2878 | } |
| 2879 | else |
| 2880 | { |
| 2881 | if (pc_is_mips16 (*pcptr)) |
| 2882 | { |
| 2883 | static char mips16_little_breakpoint[] = MIPS16_LITTLE_BREAKPOINT; |
| 2884 | *pcptr = UNMAKE_MIPS16_ADDR (*pcptr); |
| 2885 | *lenptr = sizeof(mips16_little_breakpoint); |
| 2886 | return mips16_little_breakpoint; |
| 2887 | } |
| 2888 | else |
| 2889 | { |
| 2890 | static char little_breakpoint[] = LITTLE_BREAKPOINT; |
| 2891 | static char pmon_little_breakpoint[] = PMON_LITTLE_BREAKPOINT; |
| 2892 | static char idt_little_breakpoint[] = IDT_LITTLE_BREAKPOINT; |
| 2893 | |
| 2894 | *lenptr = sizeof(little_breakpoint); |
| 2895 | |
| 2896 | if (strcmp (target_shortname, "mips") == 0) |
| 2897 | return idt_little_breakpoint; |
| 2898 | else if (strcmp (target_shortname, "ddb") == 0 |
| 2899 | || strcmp (target_shortname, "pmon") == 0 |
| 2900 | || strcmp (target_shortname, "lsi") == 0) |
| 2901 | return pmon_little_breakpoint; |
| 2902 | else |
| 2903 | return little_breakpoint; |
| 2904 | } |
| 2905 | } |
| 2906 | } |
| 2907 | |
| 2908 | /* Test whether the PC points to the return instruction at the |
| 2909 | end of a function. This implements the ABOUT_TO_RETURN macro. */ |
| 2910 | |
| 2911 | int |
| 2912 | mips_about_to_return (pc) |
| 2913 | CORE_ADDR pc; |
| 2914 | { |
| 2915 | if (pc_is_mips16 (pc)) |
| 2916 | /* This mips16 case isn't necessarily reliable. Sometimes the compiler |
| 2917 | generates a "jr $ra"; other times it generates code to load |
| 2918 | the return address from the stack to an accessible register (such |
| 2919 | as $a3), then a "jr" using that register. This second case |
| 2920 | is almost impossible to distinguish from an indirect jump |
| 2921 | used for switch statements, so we don't even try. */ |
| 2922 | return mips_fetch_instruction (pc) == 0xe820; /* jr $ra */ |
| 2923 | else |
| 2924 | return mips_fetch_instruction (pc) == 0x3e00008; /* jr $ra */ |
| 2925 | } |
| 2926 | |
| 2927 | |
| 2928 | /* If PC is in a mips16 call or return stub, return the address of the target |
| 2929 | PC, which is either the callee or the caller. There are several |
| 2930 | cases which must be handled: |
| 2931 | |
| 2932 | * If the PC is in __mips16_ret_{d,s}f, this is a return stub and the |
| 2933 | target PC is in $31 ($ra). |
| 2934 | * If the PC is in __mips16_call_stub_{1..10}, this is a call stub |
| 2935 | and the target PC is in $2. |
| 2936 | * If the PC at the start of __mips16_call_stub_{s,d}f_{0..10}, i.e. |
| 2937 | before the jal instruction, this is effectively a call stub |
| 2938 | and the the target PC is in $2. Otherwise this is effectively |
| 2939 | a return stub and the target PC is in $18. |
| 2940 | |
| 2941 | See the source code for the stubs in gcc/config/mips/mips16.S for |
| 2942 | gory details. |
| 2943 | |
| 2944 | This function implements the SKIP_TRAMPOLINE_CODE macro. |
| 2945 | */ |
| 2946 | |
| 2947 | CORE_ADDR |
| 2948 | mips_skip_stub (pc) |
| 2949 | CORE_ADDR pc; |
| 2950 | { |
| 2951 | char *name; |
| 2952 | CORE_ADDR start_addr; |
| 2953 | |
| 2954 | /* Find the starting address and name of the function containing the PC. */ |
| 2955 | if (find_pc_partial_function (pc, &name, &start_addr, NULL) == 0) |
| 2956 | return 0; |
| 2957 | |
| 2958 | /* If the PC is in __mips16_ret_{d,s}f, this is a return stub and the |
| 2959 | target PC is in $31 ($ra). */ |
| 2960 | if (strcmp (name, "__mips16_ret_sf") == 0 |
| 2961 | || strcmp (name, "__mips16_ret_df") == 0) |
| 2962 | return read_register (RA_REGNUM); |
| 2963 | |
| 2964 | if (strncmp (name, "__mips16_call_stub_", 19) == 0) |
| 2965 | { |
| 2966 | /* If the PC is in __mips16_call_stub_{1..10}, this is a call stub |
| 2967 | and the target PC is in $2. */ |
| 2968 | if (name[19] >= '0' && name[19] <= '9') |
| 2969 | return read_register (2); |
| 2970 | |
| 2971 | /* If the PC at the start of __mips16_call_stub_{s,d}f_{0..10}, i.e. |
| 2972 | before the jal instruction, this is effectively a call stub |
| 2973 | and the the target PC is in $2. Otherwise this is effectively |
| 2974 | a return stub and the target PC is in $18. */ |
| 2975 | else if (name[19] == 's' || name[19] == 'd') |
| 2976 | { |
| 2977 | if (pc == start_addr) |
| 2978 | { |
| 2979 | /* Check if the target of the stub is a compiler-generated |
| 2980 | stub. Such a stub for a function bar might have a name |
| 2981 | like __fn_stub_bar, and might look like this: |
| 2982 | mfc1 $4,$f13 |
| 2983 | mfc1 $5,$f12 |
| 2984 | mfc1 $6,$f15 |
| 2985 | mfc1 $7,$f14 |
| 2986 | la $1,bar (becomes a lui/addiu pair) |
| 2987 | jr $1 |
| 2988 | So scan down to the lui/addi and extract the target |
| 2989 | address from those two instructions. */ |
| 2990 | |
| 2991 | CORE_ADDR target_pc = read_register (2); |
| 2992 | t_inst inst; |
| 2993 | int i; |
| 2994 | |
| 2995 | /* See if the name of the target function is __fn_stub_*. */ |
| 2996 | if (find_pc_partial_function (target_pc, &name, NULL, NULL) == 0) |
| 2997 | return target_pc; |
| 2998 | if (strncmp (name, "__fn_stub_", 10) != 0 |
| 2999 | && strcmp (name, "etext") != 0 |
| 3000 | && strcmp (name, "_etext") != 0) |
| 3001 | return target_pc; |
| 3002 | |
| 3003 | /* Scan through this _fn_stub_ code for the lui/addiu pair. |
| 3004 | The limit on the search is arbitrarily set to 20 |
| 3005 | instructions. FIXME. */ |
| 3006 | for (i = 0, pc = 0; i < 20; i++, target_pc += MIPS_INSTLEN) |
| 3007 | { |
| 3008 | inst = mips_fetch_instruction (target_pc); |
| 3009 | if ((inst & 0xffff0000) == 0x3c010000) /* lui $at */ |
| 3010 | pc = (inst << 16) & 0xffff0000; /* high word */ |
| 3011 | else if ((inst & 0xffff0000) == 0x24210000) /* addiu $at */ |
| 3012 | return pc | (inst & 0xffff); /* low word */ |
| 3013 | } |
| 3014 | |
| 3015 | /* Couldn't find the lui/addui pair, so return stub address. */ |
| 3016 | return target_pc; |
| 3017 | } |
| 3018 | else |
| 3019 | /* This is the 'return' part of a call stub. The return |
| 3020 | address is in $r18. */ |
| 3021 | return read_register (18); |
| 3022 | } |
| 3023 | } |
| 3024 | return 0; /* not a stub */ |
| 3025 | } |
| 3026 | |
| 3027 | |
| 3028 | /* Return non-zero if the PC is inside a call thunk (aka stub or trampoline). |
| 3029 | This implements the IN_SOLIB_CALL_TRAMPOLINE macro. */ |
| 3030 | |
| 3031 | int |
| 3032 | mips_in_call_stub (pc, name) |
| 3033 | CORE_ADDR pc; |
| 3034 | char *name; |
| 3035 | { |
| 3036 | CORE_ADDR start_addr; |
| 3037 | |
| 3038 | /* Find the starting address of the function containing the PC. If the |
| 3039 | caller didn't give us a name, look it up at the same time. */ |
| 3040 | if (find_pc_partial_function (pc, name ? NULL : &name, &start_addr, NULL) == 0) |
| 3041 | return 0; |
| 3042 | |
| 3043 | if (strncmp (name, "__mips16_call_stub_", 19) == 0) |
| 3044 | { |
| 3045 | /* If the PC is in __mips16_call_stub_{1..10}, this is a call stub. */ |
| 3046 | if (name[19] >= '0' && name[19] <= '9') |
| 3047 | return 1; |
| 3048 | /* If the PC at the start of __mips16_call_stub_{s,d}f_{0..10}, i.e. |
| 3049 | before the jal instruction, this is effectively a call stub. */ |
| 3050 | else if (name[19] == 's' || name[19] == 'd') |
| 3051 | return pc == start_addr; |
| 3052 | } |
| 3053 | |
| 3054 | return 0; /* not a stub */ |
| 3055 | } |
| 3056 | |
| 3057 | |
| 3058 | /* Return non-zero if the PC is inside a return thunk (aka stub or trampoline). |
| 3059 | This implements the IN_SOLIB_RETURN_TRAMPOLINE macro. */ |
| 3060 | |
| 3061 | int |
| 3062 | mips_in_return_stub (pc, name) |
| 3063 | CORE_ADDR pc; |
| 3064 | char *name; |
| 3065 | { |
| 3066 | CORE_ADDR start_addr; |
| 3067 | |
| 3068 | /* Find the starting address of the function containing the PC. */ |
| 3069 | if (find_pc_partial_function (pc, NULL, &start_addr, NULL) == 0) |
| 3070 | return 0; |
| 3071 | |
| 3072 | /* If the PC is in __mips16_ret_{d,s}f, this is a return stub. */ |
| 3073 | if (strcmp (name, "__mips16_ret_sf") == 0 |
| 3074 | || strcmp (name, "__mips16_ret_df") == 0) |
| 3075 | return 1; |
| 3076 | |
| 3077 | /* If the PC is in __mips16_call_stub_{s,d}f_{0..10} but not at the start, |
| 3078 | i.e. after the jal instruction, this is effectively a return stub. */ |
| 3079 | if (strncmp (name, "__mips16_call_stub_", 19) == 0 |
| 3080 | && (name[19] == 's' || name[19] == 'd') |
| 3081 | && pc != start_addr) |
| 3082 | return 1; |
| 3083 | |
| 3084 | return 0; /* not a stub */ |
| 3085 | } |
| 3086 | |
| 3087 | |
| 3088 | /* Return non-zero if the PC is in a library helper function that should |
| 3089 | be ignored. This implements the IGNORE_HELPER_CALL macro. */ |
| 3090 | |
| 3091 | int |
| 3092 | mips_ignore_helper (pc) |
| 3093 | CORE_ADDR pc; |
| 3094 | { |
| 3095 | char *name; |
| 3096 | |
| 3097 | /* Find the starting address and name of the function containing the PC. */ |
| 3098 | if (find_pc_partial_function (pc, &name, NULL, NULL) == 0) |
| 3099 | return 0; |
| 3100 | |
| 3101 | /* If the PC is in __mips16_ret_{d,s}f, this is a library helper function |
| 3102 | that we want to ignore. */ |
| 3103 | return (strcmp (name, "__mips16_ret_sf") == 0 |
| 3104 | || strcmp (name, "__mips16_ret_df") == 0); |
| 3105 | } |
| 3106 | |
| 3107 | |
| 3108 | void |
| 3109 | _initialize_mips_tdep () |
| 3110 | { |
| 3111 | struct cmd_list_element *c; |
| 3112 | |
| 3113 | if (!tm_print_insn) /* Someone may have already set it */ |
| 3114 | tm_print_insn = gdb_print_insn_mips; |
| 3115 | |
| 3116 | /* Let the user turn off floating point and set the fence post for |
| 3117 | heuristic_proc_start. */ |
| 3118 | |
| 3119 | c = add_set_cmd ("mipsfpu", class_support, var_string_noescape, |
| 3120 | (char *) &mips_fpu_string, |
| 3121 | "Set use of floating point coprocessor.\n\ |
| 3122 | Set to `none' to avoid using floating point instructions when calling\n\ |
| 3123 | functions or dealing with return values. Set to `single' to use only\n\ |
| 3124 | single precision floating point as on the R4650. Set to `double' for\n\ |
| 3125 | normal floating point support.", |
| 3126 | &setlist); |
| 3127 | c->function.sfunc = mips_set_fpu_command; |
| 3128 | c = add_show_from_set (c, &showlist); |
| 3129 | c->function.sfunc = mips_show_fpu_command; |
| 3130 | |
| 3131 | #ifndef MIPS_DEFAULT_FPU_TYPE |
| 3132 | mips_fpu = MIPS_FPU_DOUBLE; |
| 3133 | mips_fpu_string = strsave ("double"); |
| 3134 | #else |
| 3135 | mips_fpu = MIPS_DEFAULT_FPU_TYPE; |
| 3136 | switch (mips_fpu) |
| 3137 | { |
| 3138 | case MIPS_FPU_DOUBLE: mips_fpu_string = strsave ("double"); break; |
| 3139 | case MIPS_FPU_SINGLE: mips_fpu_string = strsave ("single"); break; |
| 3140 | case MIPS_FPU_NONE: mips_fpu_string = strsave ("none"); break; |
| 3141 | } |
| 3142 | #endif |
| 3143 | |
| 3144 | c = add_set_cmd ("processor", class_support, var_string_noescape, |
| 3145 | (char *) &tmp_mips_processor_type, |
| 3146 | "Set the type of MIPS processor in use.\n\ |
| 3147 | Set this to be able to access processor-type-specific registers.\n\ |
| 3148 | ", |
| 3149 | &setlist); |
| 3150 | c->function.cfunc = mips_set_processor_type_command; |
| 3151 | c = add_show_from_set (c, &showlist); |
| 3152 | c->function.cfunc = mips_show_processor_type_command; |
| 3153 | |
| 3154 | tmp_mips_processor_type = strsave (DEFAULT_MIPS_TYPE); |
| 3155 | mips_set_processor_type_command (strsave (DEFAULT_MIPS_TYPE), 0); |
| 3156 | |
| 3157 | /* We really would like to have both "0" and "unlimited" work, but |
| 3158 | command.c doesn't deal with that. So make it a var_zinteger |
| 3159 | because the user can always use "999999" or some such for unlimited. */ |
| 3160 | c = add_set_cmd ("heuristic-fence-post", class_support, var_zinteger, |
| 3161 | (char *) &heuristic_fence_post, |
| 3162 | "\ |
| 3163 | Set the distance searched for the start of a function.\n\ |
| 3164 | If you are debugging a stripped executable, GDB needs to search through the\n\ |
| 3165 | program for the start of a function. This command sets the distance of the\n\ |
| 3166 | search. The only need to set it is when debugging a stripped executable.", |
| 3167 | &setlist); |
| 3168 | /* We need to throw away the frame cache when we set this, since it |
| 3169 | might change our ability to get backtraces. */ |
| 3170 | c->function.sfunc = reinit_frame_cache_sfunc; |
| 3171 | add_show_from_set (c, &showlist); |
| 3172 | } |