GDB (API)
|
00001 /* Target-dependent code for the Motorola 88000 series. 00002 00003 Copyright (C) 2004-2013 Free Software Foundation, Inc. 00004 00005 This file is part of GDB. 00006 00007 This program is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation; either version 3 of the License, or 00010 (at your option) any later version. 00011 00012 This program is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 00019 00020 #include "defs.h" 00021 #include "arch-utils.h" 00022 #include "dis-asm.h" 00023 #include "frame.h" 00024 #include "frame-base.h" 00025 #include "frame-unwind.h" 00026 #include "gdbcore.h" 00027 #include "gdbtypes.h" 00028 #include "regcache.h" 00029 #include "regset.h" 00030 #include "symtab.h" 00031 #include "trad-frame.h" 00032 #include "value.h" 00033 00034 #include "gdb_assert.h" 00035 #include "gdb_string.h" 00036 00037 #include "m88k-tdep.h" 00038 00039 /* Fetch the instruction at PC. */ 00040 00041 static unsigned long 00042 m88k_fetch_instruction (CORE_ADDR pc, enum bfd_endian byte_order) 00043 { 00044 return read_memory_unsigned_integer (pc, 4, byte_order); 00045 } 00046 00047 /* Register information. */ 00048 00049 /* Return the name of register REGNUM. */ 00050 00051 static const char * 00052 m88k_register_name (struct gdbarch *gdbarch, int regnum) 00053 { 00054 static char *register_names[] = 00055 { 00056 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", 00057 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", 00058 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", 00059 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31", 00060 "epsr", "fpsr", "fpcr", "sxip", "snip", "sfip" 00061 }; 00062 00063 if (regnum >= 0 && regnum < ARRAY_SIZE (register_names)) 00064 return register_names[regnum]; 00065 00066 return NULL; 00067 } 00068 00069 /* Return the GDB type object for the "standard" data type of data in 00070 register REGNUM. */ 00071 00072 static struct type * 00073 m88k_register_type (struct gdbarch *gdbarch, int regnum) 00074 { 00075 /* SXIP, SNIP, SFIP and R1 contain code addresses. */ 00076 if ((regnum >= M88K_SXIP_REGNUM && regnum <= M88K_SFIP_REGNUM) 00077 || regnum == M88K_R1_REGNUM) 00078 return builtin_type (gdbarch)->builtin_func_ptr; 00079 00080 /* R30 and R31 typically contains data addresses. */ 00081 if (regnum == M88K_R30_REGNUM || regnum == M88K_R31_REGNUM) 00082 return builtin_type (gdbarch)->builtin_data_ptr; 00083 00084 return builtin_type (gdbarch)->builtin_int32; 00085 } 00086 00087 00088 static CORE_ADDR 00089 m88k_addr_bits_remove (struct gdbarch *gdbarch, CORE_ADDR addr) 00090 { 00091 /* All instructures are 4-byte aligned. The lower 2 bits of SXIP, 00092 SNIP and SFIP are used for special purposes: bit 0 is the 00093 exception bit and bit 1 is the valid bit. */ 00094 return addr & ~0x3; 00095 } 00096 00097 /* Use the program counter to determine the contents and size of a 00098 breakpoint instruction. Return a pointer to a string of bytes that 00099 encode a breakpoint instruction, store the length of the string in 00100 *LEN and optionally adjust *PC to point to the correct memory 00101 location for inserting the breakpoint. */ 00102 00103 static const gdb_byte * 00104 m88k_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pc, int *len) 00105 { 00106 /* tb 0,r0,511 */ 00107 static gdb_byte break_insn[] = { 0xf0, 0x00, 0xd1, 0xff }; 00108 00109 *len = sizeof (break_insn); 00110 return break_insn; 00111 } 00112 00113 static CORE_ADDR 00114 m88k_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame) 00115 { 00116 CORE_ADDR pc; 00117 00118 pc = frame_unwind_register_unsigned (next_frame, M88K_SXIP_REGNUM); 00119 return m88k_addr_bits_remove (gdbarch, pc); 00120 } 00121 00122 static void 00123 m88k_write_pc (struct regcache *regcache, CORE_ADDR pc) 00124 { 00125 /* According to the MC88100 RISC Microprocessor User's Manual, 00126 section 6.4.3.1.2: 00127 00128 "... can be made to return to a particular instruction by placing 00129 a valid instruction address in the SNIP and the next sequential 00130 instruction address in the SFIP (with V bits set and E bits 00131 clear). The rte resumes execution at the instruction pointed to 00132 by the SNIP, then the SFIP." 00133 00134 The E bit is the least significant bit (bit 0). The V (valid) 00135 bit is bit 1. This is why we logical or 2 into the values we are 00136 writing below. It turns out that SXIP plays no role when 00137 returning from an exception so nothing special has to be done 00138 with it. We could even (presumably) give it a totally bogus 00139 value. */ 00140 00141 regcache_cooked_write_unsigned (regcache, M88K_SXIP_REGNUM, pc); 00142 regcache_cooked_write_unsigned (regcache, M88K_SNIP_REGNUM, pc | 2); 00143 regcache_cooked_write_unsigned (regcache, M88K_SFIP_REGNUM, (pc + 4) | 2); 00144 } 00145 00146 00147 /* The functions on this page are intended to be used to classify 00148 function arguments. */ 00149 00150 /* Check whether TYPE is "Integral or Pointer". */ 00151 00152 static int 00153 m88k_integral_or_pointer_p (const struct type *type) 00154 { 00155 switch (TYPE_CODE (type)) 00156 { 00157 case TYPE_CODE_INT: 00158 case TYPE_CODE_BOOL: 00159 case TYPE_CODE_CHAR: 00160 case TYPE_CODE_ENUM: 00161 case TYPE_CODE_RANGE: 00162 { 00163 /* We have byte, half-word, word and extended-word/doubleword 00164 integral types. */ 00165 int len = TYPE_LENGTH (type); 00166 return (len == 1 || len == 2 || len == 4 || len == 8); 00167 } 00168 return 1; 00169 case TYPE_CODE_PTR: 00170 case TYPE_CODE_REF: 00171 { 00172 /* Allow only 32-bit pointers. */ 00173 return (TYPE_LENGTH (type) == 4); 00174 } 00175 return 1; 00176 default: 00177 break; 00178 } 00179 00180 return 0; 00181 } 00182 00183 /* Check whether TYPE is "Floating". */ 00184 00185 static int 00186 m88k_floating_p (const struct type *type) 00187 { 00188 switch (TYPE_CODE (type)) 00189 { 00190 case TYPE_CODE_FLT: 00191 { 00192 int len = TYPE_LENGTH (type); 00193 return (len == 4 || len == 8); 00194 } 00195 default: 00196 break; 00197 } 00198 00199 return 0; 00200 } 00201 00202 /* Check whether TYPE is "Structure or Union". */ 00203 00204 static int 00205 m88k_structure_or_union_p (const struct type *type) 00206 { 00207 switch (TYPE_CODE (type)) 00208 { 00209 case TYPE_CODE_STRUCT: 00210 case TYPE_CODE_UNION: 00211 return 1; 00212 default: 00213 break; 00214 } 00215 00216 return 0; 00217 } 00218 00219 /* Check whether TYPE has 8-byte alignment. */ 00220 00221 static int 00222 m88k_8_byte_align_p (struct type *type) 00223 { 00224 if (m88k_structure_or_union_p (type)) 00225 { 00226 int i; 00227 00228 for (i = 0; i < TYPE_NFIELDS (type); i++) 00229 { 00230 struct type *subtype = check_typedef (TYPE_FIELD_TYPE (type, i)); 00231 00232 if (m88k_8_byte_align_p (subtype)) 00233 return 1; 00234 } 00235 } 00236 00237 if (m88k_integral_or_pointer_p (type) || m88k_floating_p (type)) 00238 return (TYPE_LENGTH (type) == 8); 00239 00240 return 0; 00241 } 00242 00243 /* Check whether TYPE can be passed in a register. */ 00244 00245 static int 00246 m88k_in_register_p (struct type *type) 00247 { 00248 if (m88k_integral_or_pointer_p (type) || m88k_floating_p (type)) 00249 return 1; 00250 00251 if (m88k_structure_or_union_p (type) && TYPE_LENGTH (type) == 4) 00252 return 1; 00253 00254 return 0; 00255 } 00256 00257 static CORE_ADDR 00258 m88k_store_arguments (struct regcache *regcache, int nargs, 00259 struct value **args, CORE_ADDR sp) 00260 { 00261 struct gdbarch *gdbarch = get_regcache_arch (regcache); 00262 int num_register_words = 0; 00263 int num_stack_words = 0; 00264 int i; 00265 00266 for (i = 0; i < nargs; i++) 00267 { 00268 struct type *type = value_type (args[i]); 00269 int len = TYPE_LENGTH (type); 00270 00271 if (m88k_integral_or_pointer_p (type) && len < 4) 00272 { 00273 args[i] = value_cast (builtin_type (gdbarch)->builtin_int32, 00274 args[i]); 00275 type = value_type (args[i]); 00276 len = TYPE_LENGTH (type); 00277 } 00278 00279 if (m88k_in_register_p (type)) 00280 { 00281 int num_words = 0; 00282 00283 if (num_register_words % 2 == 1 && m88k_8_byte_align_p (type)) 00284 num_words++; 00285 00286 num_words += ((len + 3) / 4); 00287 if (num_register_words + num_words <= 8) 00288 { 00289 num_register_words += num_words; 00290 continue; 00291 } 00292 00293 /* We've run out of available registers. Pass the argument 00294 on the stack. */ 00295 } 00296 00297 if (num_stack_words % 2 == 1 && m88k_8_byte_align_p (type)) 00298 num_stack_words++; 00299 00300 num_stack_words += ((len + 3) / 4); 00301 } 00302 00303 /* Allocate stack space. */ 00304 sp = align_down (sp - 32 - num_stack_words * 4, 16); 00305 num_stack_words = num_register_words = 0; 00306 00307 for (i = 0; i < nargs; i++) 00308 { 00309 const bfd_byte *valbuf = value_contents (args[i]); 00310 struct type *type = value_type (args[i]); 00311 int len = TYPE_LENGTH (type); 00312 int stack_word = num_stack_words; 00313 00314 if (m88k_in_register_p (type)) 00315 { 00316 int register_word = num_register_words; 00317 00318 if (register_word % 2 == 1 && m88k_8_byte_align_p (type)) 00319 register_word++; 00320 00321 gdb_assert (len == 4 || len == 8); 00322 00323 if (register_word + len / 8 < 8) 00324 { 00325 int regnum = M88K_R2_REGNUM + register_word; 00326 00327 regcache_raw_write (regcache, regnum, valbuf); 00328 if (len > 4) 00329 regcache_raw_write (regcache, regnum + 1, valbuf + 4); 00330 00331 num_register_words = (register_word + len / 4); 00332 continue; 00333 } 00334 } 00335 00336 if (stack_word % 2 == -1 && m88k_8_byte_align_p (type)) 00337 stack_word++; 00338 00339 write_memory (sp + stack_word * 4, valbuf, len); 00340 num_stack_words = (stack_word + (len + 3) / 4); 00341 } 00342 00343 return sp; 00344 } 00345 00346 static CORE_ADDR 00347 m88k_push_dummy_call (struct gdbarch *gdbarch, struct value *function, 00348 struct regcache *regcache, CORE_ADDR bp_addr, int nargs, 00349 struct value **args, CORE_ADDR sp, int struct_return, 00350 CORE_ADDR struct_addr) 00351 { 00352 /* Set up the function arguments. */ 00353 sp = m88k_store_arguments (regcache, nargs, args, sp); 00354 gdb_assert (sp % 16 == 0); 00355 00356 /* Store return value address. */ 00357 if (struct_return) 00358 regcache_raw_write_unsigned (regcache, M88K_R12_REGNUM, struct_addr); 00359 00360 /* Store the stack pointer and return address in the appropriate 00361 registers. */ 00362 regcache_raw_write_unsigned (regcache, M88K_R31_REGNUM, sp); 00363 regcache_raw_write_unsigned (regcache, M88K_R1_REGNUM, bp_addr); 00364 00365 /* Return the stack pointer. */ 00366 return sp; 00367 } 00368 00369 static struct frame_id 00370 m88k_dummy_id (struct gdbarch *arch, struct frame_info *this_frame) 00371 { 00372 CORE_ADDR sp; 00373 00374 sp = get_frame_register_unsigned (this_frame, M88K_R31_REGNUM); 00375 return frame_id_build (sp, get_frame_pc (this_frame)); 00376 } 00377 00378 00379 /* Determine, for architecture GDBARCH, how a return value of TYPE 00380 should be returned. If it is supposed to be returned in registers, 00381 and READBUF is non-zero, read the appropriate value from REGCACHE, 00382 and copy it into READBUF. If WRITEBUF is non-zero, write the value 00383 from WRITEBUF into REGCACHE. */ 00384 00385 static enum return_value_convention 00386 m88k_return_value (struct gdbarch *gdbarch, struct value *function, 00387 struct type *type, struct regcache *regcache, 00388 gdb_byte *readbuf, const gdb_byte *writebuf) 00389 { 00390 int len = TYPE_LENGTH (type); 00391 gdb_byte buf[8]; 00392 00393 if (!m88k_integral_or_pointer_p (type) && !m88k_floating_p (type)) 00394 return RETURN_VALUE_STRUCT_CONVENTION; 00395 00396 if (readbuf) 00397 { 00398 /* Read the contents of R2 and (if necessary) R3. */ 00399 regcache_cooked_read (regcache, M88K_R2_REGNUM, buf); 00400 if (len > 4) 00401 { 00402 regcache_cooked_read (regcache, M88K_R3_REGNUM, buf + 4); 00403 gdb_assert (len == 8); 00404 memcpy (readbuf, buf, len); 00405 } 00406 else 00407 { 00408 /* Just stripping off any unused bytes should preserve the 00409 signed-ness just fine. */ 00410 memcpy (readbuf, buf + 4 - len, len); 00411 } 00412 } 00413 00414 if (writebuf) 00415 { 00416 /* Read the contents to R2 and (if necessary) R3. */ 00417 if (len > 4) 00418 { 00419 gdb_assert (len == 8); 00420 memcpy (buf, writebuf, 8); 00421 regcache_cooked_write (regcache, M88K_R3_REGNUM, buf + 4); 00422 } 00423 else 00424 { 00425 /* ??? Do we need to do any sign-extension here? */ 00426 memcpy (buf + 4 - len, writebuf, len); 00427 } 00428 regcache_cooked_write (regcache, M88K_R2_REGNUM, buf); 00429 } 00430 00431 return RETURN_VALUE_REGISTER_CONVENTION; 00432 } 00433 00434 /* Default frame unwinder. */ 00435 00436 struct m88k_frame_cache 00437 { 00438 /* Base address. */ 00439 CORE_ADDR base; 00440 CORE_ADDR pc; 00441 00442 int sp_offset; 00443 int fp_offset; 00444 00445 /* Table of saved registers. */ 00446 struct trad_frame_saved_reg *saved_regs; 00447 }; 00448 00449 /* Prologue analysis. */ 00450 00451 /* Macros for extracting fields from instructions. */ 00452 00453 #define BITMASK(pos, width) (((0x1 << (width)) - 1) << (pos)) 00454 #define EXTRACT_FIELD(val, pos, width) ((val) >> (pos) & BITMASK (0, width)) 00455 #define SUBU_OFFSET(x) ((unsigned)(x & 0xFFFF)) 00456 #define ST_OFFSET(x) ((unsigned)((x) & 0xFFFF)) 00457 #define ST_SRC(x) EXTRACT_FIELD ((x), 21, 5) 00458 #define ADDU_OFFSET(x) ((unsigned)(x & 0xFFFF)) 00459 00460 /* Possible actions to be taken by the prologue analyzer for the 00461 instructions it encounters. */ 00462 00463 enum m88k_prologue_insn_action 00464 { 00465 M88K_PIA_SKIP, /* Ignore. */ 00466 M88K_PIA_NOTE_ST, /* Note register store. */ 00467 M88K_PIA_NOTE_STD, /* Note register pair store. */ 00468 M88K_PIA_NOTE_SP_ADJUSTMENT, /* Note stack pointer adjustment. */ 00469 M88K_PIA_NOTE_FP_ASSIGNMENT, /* Note frame pointer assignment. */ 00470 M88K_PIA_NOTE_BRANCH, /* Note branch. */ 00471 M88K_PIA_NOTE_PROLOGUE_END /* Note end of prologue. */ 00472 }; 00473 00474 /* Table of instructions that may comprise a function prologue. */ 00475 00476 struct m88k_prologue_insn 00477 { 00478 unsigned long insn; 00479 unsigned long mask; 00480 enum m88k_prologue_insn_action action; 00481 }; 00482 00483 struct m88k_prologue_insn m88k_prologue_insn_table[] = 00484 { 00485 /* Various register move instructions. */ 00486 { 0x58000000, 0xf800ffff, M88K_PIA_SKIP }, /* or/or.u with immed of 0 */ 00487 { 0xf4005800, 0xfc1fffe0, M88K_PIA_SKIP }, /* or rd,r0,rs */ 00488 { 0xf4005800, 0xfc00ffff, M88K_PIA_SKIP }, /* or rd,rs,r0 */ 00489 00490 /* Various other instructions. */ 00491 { 0x58000000, 0xf8000000, M88K_PIA_SKIP }, /* or/or.u */ 00492 00493 /* Stack pointer setup: "subu sp,sp,n" where n is a multiple of 8. */ 00494 { 0x67ff0000, 0xffff0007, M88K_PIA_NOTE_SP_ADJUSTMENT }, 00495 00496 /* Frame pointer assignment: "addu r30,r31,n". */ 00497 { 0x63df0000, 0xffff0000, M88K_PIA_NOTE_FP_ASSIGNMENT }, 00498 00499 /* Store to stack instructions; either "st rx,sp,n" or "st.d rx,sp,n". */ 00500 { 0x241f0000, 0xfc1f0000, M88K_PIA_NOTE_ST }, /* st rx,sp,n */ 00501 { 0x201f0000, 0xfc1f0000, M88K_PIA_NOTE_STD }, /* st.d rs,sp,n */ 00502 00503 /* Instructions needed for setting up r25 for pic code. */ 00504 { 0x5f200000, 0xffff0000, M88K_PIA_SKIP }, /* or.u r25,r0,offset_high */ 00505 { 0xcc000002, 0xffffffff, M88K_PIA_SKIP }, /* bsr.n Lab */ 00506 { 0x5b390000, 0xffff0000, M88K_PIA_SKIP }, /* or r25,r25,offset_low */ 00507 { 0xf7396001, 0xffffffff, M88K_PIA_SKIP }, /* Lab: addu r25,r25,r1 */ 00508 00509 /* Various branch or jump instructions which have a delay slot -- 00510 these do not form part of the prologue, but the instruction in 00511 the delay slot might be a store instruction which should be 00512 noted. */ 00513 { 0xc4000000, 0xe4000000, M88K_PIA_NOTE_BRANCH }, 00514 /* br.n, bsr.n, bb0.n, or bb1.n */ 00515 { 0xec000000, 0xfc000000, M88K_PIA_NOTE_BRANCH }, /* bcnd.n */ 00516 { 0xf400c400, 0xfffff7e0, M88K_PIA_NOTE_BRANCH }, /* jmp.n or jsr.n */ 00517 00518 /* Catch all. Ends prologue analysis. */ 00519 { 0x00000000, 0x00000000, M88K_PIA_NOTE_PROLOGUE_END } 00520 }; 00521 00522 /* Do a full analysis of the function prologue at PC and update CACHE 00523 accordingly. Bail out early if LIMIT is reached. Return the 00524 address where the analysis stopped. If LIMIT points beyond the 00525 function prologue, the return address should be the end of the 00526 prologue. */ 00527 00528 static CORE_ADDR 00529 m88k_analyze_prologue (struct gdbarch *gdbarch, 00530 CORE_ADDR pc, CORE_ADDR limit, 00531 struct m88k_frame_cache *cache) 00532 { 00533 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 00534 CORE_ADDR end = limit; 00535 00536 /* Provide a dummy cache if necessary. */ 00537 if (cache == NULL) 00538 { 00539 size_t sizeof_saved_regs = 00540 (M88K_R31_REGNUM + 1) * sizeof (struct trad_frame_saved_reg); 00541 00542 cache = alloca (sizeof (struct m88k_frame_cache)); 00543 cache->saved_regs = alloca (sizeof_saved_regs); 00544 00545 /* We only initialize the members we care about. */ 00546 cache->saved_regs[M88K_R1_REGNUM].addr = -1; 00547 cache->fp_offset = -1; 00548 } 00549 00550 while (pc < limit) 00551 { 00552 struct m88k_prologue_insn *pi = m88k_prologue_insn_table; 00553 unsigned long insn = m88k_fetch_instruction (pc, byte_order); 00554 00555 while ((insn & pi->mask) != pi->insn) 00556 pi++; 00557 00558 switch (pi->action) 00559 { 00560 case M88K_PIA_SKIP: 00561 /* If we have a frame pointer, and R1 has been saved, 00562 consider this instruction as not being part of the 00563 prologue. */ 00564 if (cache->fp_offset != -1 00565 && cache->saved_regs[M88K_R1_REGNUM].addr != -1) 00566 return min (pc, end); 00567 break; 00568 00569 case M88K_PIA_NOTE_ST: 00570 case M88K_PIA_NOTE_STD: 00571 /* If no frame has been allocated, the stores aren't part of 00572 the prologue. */ 00573 if (cache->sp_offset == 0) 00574 return min (pc, end); 00575 00576 /* Record location of saved registers. */ 00577 { 00578 int regnum = ST_SRC (insn) + M88K_R0_REGNUM; 00579 ULONGEST offset = ST_OFFSET (insn); 00580 00581 cache->saved_regs[regnum].addr = offset; 00582 if (pi->action == M88K_PIA_NOTE_STD && regnum < M88K_R31_REGNUM) 00583 cache->saved_regs[regnum + 1].addr = offset + 4; 00584 } 00585 break; 00586 00587 case M88K_PIA_NOTE_SP_ADJUSTMENT: 00588 /* A second stack pointer adjustment isn't part of the 00589 prologue. */ 00590 if (cache->sp_offset != 0) 00591 return min (pc, end); 00592 00593 /* Store stack pointer adjustment. */ 00594 cache->sp_offset = -SUBU_OFFSET (insn); 00595 break; 00596 00597 case M88K_PIA_NOTE_FP_ASSIGNMENT: 00598 /* A second frame pointer assignment isn't part of the 00599 prologue. */ 00600 if (cache->fp_offset != -1) 00601 return min (pc, end); 00602 00603 /* Record frame pointer assignment. */ 00604 cache->fp_offset = ADDU_OFFSET (insn); 00605 break; 00606 00607 case M88K_PIA_NOTE_BRANCH: 00608 /* The branch instruction isn't part of the prologue, but 00609 the instruction in the delay slot might be. Limit the 00610 prologue analysis to the delay slot and record the branch 00611 instruction as the end of the prologue. */ 00612 limit = min (limit, pc + 2 * M88K_INSN_SIZE); 00613 end = pc; 00614 break; 00615 00616 case M88K_PIA_NOTE_PROLOGUE_END: 00617 return min (pc, end); 00618 } 00619 00620 pc += M88K_INSN_SIZE; 00621 } 00622 00623 return end; 00624 } 00625 00626 /* An upper limit to the size of the prologue. */ 00627 const int m88k_max_prologue_size = 128 * M88K_INSN_SIZE; 00628 00629 /* Return the address of first real instruction of the function 00630 starting at PC. */ 00631 00632 static CORE_ADDR 00633 m88k_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc) 00634 { 00635 struct symtab_and_line sal; 00636 CORE_ADDR func_start, func_end; 00637 00638 /* This is the preferred method, find the end of the prologue by 00639 using the debugging information. */ 00640 if (find_pc_partial_function (pc, NULL, &func_start, &func_end)) 00641 { 00642 sal = find_pc_line (func_start, 0); 00643 00644 if (sal.end < func_end && pc <= sal.end) 00645 return sal.end; 00646 } 00647 00648 return m88k_analyze_prologue (gdbarch, pc, pc + m88k_max_prologue_size, 00649 NULL); 00650 } 00651 00652 static struct m88k_frame_cache * 00653 m88k_frame_cache (struct frame_info *this_frame, void **this_cache) 00654 { 00655 struct gdbarch *gdbarch = get_frame_arch (this_frame); 00656 struct m88k_frame_cache *cache; 00657 CORE_ADDR frame_sp; 00658 00659 if (*this_cache) 00660 return *this_cache; 00661 00662 cache = FRAME_OBSTACK_ZALLOC (struct m88k_frame_cache); 00663 cache->saved_regs = trad_frame_alloc_saved_regs (this_frame); 00664 cache->fp_offset = -1; 00665 00666 cache->pc = get_frame_func (this_frame); 00667 if (cache->pc != 0) 00668 m88k_analyze_prologue (gdbarch, cache->pc, get_frame_pc (this_frame), 00669 cache); 00670 00671 /* Calculate the stack pointer used in the prologue. */ 00672 if (cache->fp_offset != -1) 00673 { 00674 CORE_ADDR fp; 00675 00676 fp = get_frame_register_unsigned (this_frame, M88K_R30_REGNUM); 00677 frame_sp = fp - cache->fp_offset; 00678 } 00679 else 00680 { 00681 /* If we know where the return address is saved, we can take a 00682 solid guess at what the frame pointer should be. */ 00683 if (cache->saved_regs[M88K_R1_REGNUM].addr != -1) 00684 cache->fp_offset = cache->saved_regs[M88K_R1_REGNUM].addr - 4; 00685 frame_sp = get_frame_register_unsigned (this_frame, M88K_R31_REGNUM); 00686 } 00687 00688 /* Now that we know the stack pointer, adjust the location of the 00689 saved registers. */ 00690 { 00691 int regnum; 00692 00693 for (regnum = M88K_R0_REGNUM; regnum < M88K_R31_REGNUM; regnum ++) 00694 if (cache->saved_regs[regnum].addr != -1) 00695 cache->saved_regs[regnum].addr += frame_sp; 00696 } 00697 00698 /* Calculate the frame's base. */ 00699 cache->base = frame_sp - cache->sp_offset; 00700 trad_frame_set_value (cache->saved_regs, M88K_R31_REGNUM, cache->base); 00701 00702 /* Identify SXIP with the return address in R1. */ 00703 cache->saved_regs[M88K_SXIP_REGNUM] = cache->saved_regs[M88K_R1_REGNUM]; 00704 00705 *this_cache = cache; 00706 return cache; 00707 } 00708 00709 static void 00710 m88k_frame_this_id (struct frame_info *this_frame, void **this_cache, 00711 struct frame_id *this_id) 00712 { 00713 struct m88k_frame_cache *cache = m88k_frame_cache (this_frame, this_cache); 00714 00715 /* This marks the outermost frame. */ 00716 if (cache->base == 0) 00717 return; 00718 00719 (*this_id) = frame_id_build (cache->base, cache->pc); 00720 } 00721 00722 static struct value * 00723 m88k_frame_prev_register (struct frame_info *this_frame, 00724 void **this_cache, int regnum) 00725 { 00726 struct m88k_frame_cache *cache = m88k_frame_cache (this_frame, this_cache); 00727 00728 if (regnum == M88K_SNIP_REGNUM || regnum == M88K_SFIP_REGNUM) 00729 { 00730 struct value *value; 00731 CORE_ADDR pc; 00732 00733 value = trad_frame_get_prev_register (this_frame, cache->saved_regs, 00734 M88K_SXIP_REGNUM); 00735 pc = value_as_long (value); 00736 release_value (value); 00737 value_free (value); 00738 00739 if (regnum == M88K_SFIP_REGNUM) 00740 pc += 4; 00741 00742 return frame_unwind_got_constant (this_frame, regnum, pc + 4); 00743 } 00744 00745 return trad_frame_get_prev_register (this_frame, cache->saved_regs, regnum); 00746 } 00747 00748 static const struct frame_unwind m88k_frame_unwind = 00749 { 00750 NORMAL_FRAME, 00751 default_frame_unwind_stop_reason, 00752 m88k_frame_this_id, 00753 m88k_frame_prev_register, 00754 NULL, 00755 default_frame_sniffer 00756 }; 00757 00758 00759 static CORE_ADDR 00760 m88k_frame_base_address (struct frame_info *this_frame, void **this_cache) 00761 { 00762 struct m88k_frame_cache *cache = m88k_frame_cache (this_frame, this_cache); 00763 00764 if (cache->fp_offset != -1) 00765 return cache->base + cache->sp_offset + cache->fp_offset; 00766 00767 return 0; 00768 } 00769 00770 static const struct frame_base m88k_frame_base = 00771 { 00772 &m88k_frame_unwind, 00773 m88k_frame_base_address, 00774 m88k_frame_base_address, 00775 m88k_frame_base_address 00776 }; 00777 00778 00779 /* Core file support. */ 00780 00781 /* Supply register REGNUM from the buffer specified by GREGS and LEN 00782 in the general-purpose register set REGSET to register cache 00783 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */ 00784 00785 static void 00786 m88k_supply_gregset (const struct regset *regset, 00787 struct regcache *regcache, 00788 int regnum, const void *gregs, size_t len) 00789 { 00790 const gdb_byte *regs = gregs; 00791 int i; 00792 00793 for (i = 0; i < M88K_NUM_REGS; i++) 00794 { 00795 if (regnum == i || regnum == -1) 00796 regcache_raw_supply (regcache, i, regs + i * 4); 00797 } 00798 } 00799 00800 /* Motorola 88000 register set. */ 00801 00802 static struct regset m88k_gregset = 00803 { 00804 NULL, 00805 m88k_supply_gregset 00806 }; 00807 00808 /* Return the appropriate register set for the core section identified 00809 by SECT_NAME and SECT_SIZE. */ 00810 00811 static const struct regset * 00812 m88k_regset_from_core_section (struct gdbarch *gdbarch, 00813 const char *sect_name, size_t sect_size) 00814 { 00815 if (strcmp (sect_name, ".reg") == 0 && sect_size >= M88K_NUM_REGS * 4) 00816 return &m88k_gregset; 00817 00818 return NULL; 00819 } 00820 00821 00822 static struct gdbarch * 00823 m88k_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) 00824 { 00825 struct gdbarch *gdbarch; 00826 00827 /* If there is already a candidate, use it. */ 00828 arches = gdbarch_list_lookup_by_info (arches, &info); 00829 if (arches != NULL) 00830 return arches->gdbarch; 00831 00832 /* Allocate space for the new architecture. */ 00833 gdbarch = gdbarch_alloc (&info, NULL); 00834 00835 /* There is no real `long double'. */ 00836 set_gdbarch_long_double_bit (gdbarch, 64); 00837 set_gdbarch_long_double_format (gdbarch, floatformats_ieee_double); 00838 00839 set_gdbarch_num_regs (gdbarch, M88K_NUM_REGS); 00840 set_gdbarch_register_name (gdbarch, m88k_register_name); 00841 set_gdbarch_register_type (gdbarch, m88k_register_type); 00842 00843 /* Register numbers of various important registers. */ 00844 set_gdbarch_sp_regnum (gdbarch, M88K_R31_REGNUM); 00845 set_gdbarch_pc_regnum (gdbarch, M88K_SXIP_REGNUM); 00846 00847 /* Core file support. */ 00848 set_gdbarch_regset_from_core_section 00849 (gdbarch, m88k_regset_from_core_section); 00850 00851 set_gdbarch_print_insn (gdbarch, print_insn_m88k); 00852 00853 set_gdbarch_skip_prologue (gdbarch, m88k_skip_prologue); 00854 00855 /* Stack grows downward. */ 00856 set_gdbarch_inner_than (gdbarch, core_addr_lessthan); 00857 00858 /* Call dummy code. */ 00859 set_gdbarch_push_dummy_call (gdbarch, m88k_push_dummy_call); 00860 set_gdbarch_dummy_id (gdbarch, m88k_dummy_id); 00861 00862 /* Return value info. */ 00863 set_gdbarch_return_value (gdbarch, m88k_return_value); 00864 00865 set_gdbarch_addr_bits_remove (gdbarch, m88k_addr_bits_remove); 00866 set_gdbarch_breakpoint_from_pc (gdbarch, m88k_breakpoint_from_pc); 00867 set_gdbarch_unwind_pc (gdbarch, m88k_unwind_pc); 00868 set_gdbarch_write_pc (gdbarch, m88k_write_pc); 00869 00870 frame_base_set_default (gdbarch, &m88k_frame_base); 00871 frame_unwind_append_unwinder (gdbarch, &m88k_frame_unwind); 00872 00873 return gdbarch; 00874 } 00875 00876 00877 /* Provide a prototype to silence -Wmissing-prototypes. */ 00878 void _initialize_m88k_tdep (void); 00879 00880 void 00881 _initialize_m88k_tdep (void) 00882 { 00883 gdbarch_register (bfd_arch_m88k, m88k_gdbarch_init, NULL); 00884 }