GDB (API)
|
00001 /* Target-dependent code for the Sanyo Xstormy16a (LC590000) processor. 00002 00003 Copyright (C) 2001-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 "frame.h" 00022 #include "frame-base.h" 00023 #include "frame-unwind.h" 00024 #include "dwarf2-frame.h" 00025 #include "symtab.h" 00026 #include "gdbtypes.h" 00027 #include "gdbcmd.h" 00028 #include "gdbcore.h" 00029 #include "value.h" 00030 #include "dis-asm.h" 00031 #include "inferior.h" 00032 #include "gdb_string.h" 00033 #include "gdb_assert.h" 00034 #include "arch-utils.h" 00035 #include "floatformat.h" 00036 #include "regcache.h" 00037 #include "doublest.h" 00038 #include "osabi.h" 00039 #include "objfiles.h" 00040 00041 enum gdb_regnum 00042 { 00043 /* Xstormy16 has 16 general purpose registers (R0-R15) plus PC. 00044 Functions will return their values in register R2-R7 as they fit. 00045 Otherwise a hidden pointer to an big enough area is given as argument 00046 to the function in r2. Further arguments are beginning in r3 then. 00047 R13 is used as frame pointer when GCC compiles w/o optimization 00048 R14 is used as "PSW", displaying the CPU status. 00049 R15 is used implicitely as stack pointer. */ 00050 E_R0_REGNUM, 00051 E_R1_REGNUM, 00052 E_R2_REGNUM, E_1ST_ARG_REGNUM = E_R2_REGNUM, E_PTR_RET_REGNUM = E_R2_REGNUM, 00053 E_R3_REGNUM, 00054 E_R4_REGNUM, 00055 E_R5_REGNUM, 00056 E_R6_REGNUM, 00057 E_R7_REGNUM, E_LST_ARG_REGNUM = E_R7_REGNUM, 00058 E_R8_REGNUM, 00059 E_R9_REGNUM, 00060 E_R10_REGNUM, 00061 E_R11_REGNUM, 00062 E_R12_REGNUM, 00063 E_R13_REGNUM, E_FP_REGNUM = E_R13_REGNUM, 00064 E_R14_REGNUM, E_PSW_REGNUM = E_R14_REGNUM, 00065 E_R15_REGNUM, E_SP_REGNUM = E_R15_REGNUM, 00066 E_PC_REGNUM, 00067 E_NUM_REGS 00068 }; 00069 00070 /* Use an invalid address value as 'not available' marker. */ 00071 enum { REG_UNAVAIL = (CORE_ADDR) -1 }; 00072 00073 struct xstormy16_frame_cache 00074 { 00075 /* Base address. */ 00076 CORE_ADDR base; 00077 CORE_ADDR pc; 00078 LONGEST framesize; 00079 int uses_fp; 00080 CORE_ADDR saved_regs[E_NUM_REGS]; 00081 CORE_ADDR saved_sp; 00082 }; 00083 00084 /* Size of instructions, registers, etc. */ 00085 enum 00086 { 00087 xstormy16_inst_size = 2, 00088 xstormy16_reg_size = 2, 00089 xstormy16_pc_size = 4 00090 }; 00091 00092 /* Size of return datatype which fits into the remaining return registers. */ 00093 #define E_MAX_RETTYPE_SIZE(regnum) ((E_LST_ARG_REGNUM - (regnum) + 1) \ 00094 * xstormy16_reg_size) 00095 00096 /* Size of return datatype which fits into all return registers. */ 00097 enum 00098 { 00099 E_MAX_RETTYPE_SIZE_IN_REGS = E_MAX_RETTYPE_SIZE (E_R2_REGNUM) 00100 }; 00101 00102 /* Function: xstormy16_register_name 00103 Returns the name of the standard Xstormy16 register N. */ 00104 00105 static const char * 00106 xstormy16_register_name (struct gdbarch *gdbarch, int regnum) 00107 { 00108 static char *register_names[] = { 00109 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", 00110 "r8", "r9", "r10", "r11", "r12", "r13", 00111 "psw", "sp", "pc" 00112 }; 00113 00114 if (regnum < 0 || regnum >= E_NUM_REGS) 00115 internal_error (__FILE__, __LINE__, 00116 _("xstormy16_register_name: illegal register number %d"), 00117 regnum); 00118 else 00119 return register_names[regnum]; 00120 00121 } 00122 00123 static struct type * 00124 xstormy16_register_type (struct gdbarch *gdbarch, int regnum) 00125 { 00126 if (regnum == E_PC_REGNUM) 00127 return builtin_type (gdbarch)->builtin_uint32; 00128 else 00129 return builtin_type (gdbarch)->builtin_uint16; 00130 } 00131 00132 /* Function: xstormy16_type_is_scalar 00133 Makes the decision if a given type is a scalar types. Scalar 00134 types are returned in the registers r2-r7 as they fit. */ 00135 00136 static int 00137 xstormy16_type_is_scalar (struct type *t) 00138 { 00139 return (TYPE_CODE(t) != TYPE_CODE_STRUCT 00140 && TYPE_CODE(t) != TYPE_CODE_UNION 00141 && TYPE_CODE(t) != TYPE_CODE_ARRAY); 00142 } 00143 00144 /* Function: xstormy16_use_struct_convention 00145 Returns non-zero if the given struct type will be returned using 00146 a special convention, rather than the normal function return method. 00147 7sed in the contexts of the "return" command, and of 00148 target function calls from the debugger. */ 00149 00150 static int 00151 xstormy16_use_struct_convention (struct type *type) 00152 { 00153 return !xstormy16_type_is_scalar (type) 00154 || TYPE_LENGTH (type) > E_MAX_RETTYPE_SIZE_IN_REGS; 00155 } 00156 00157 /* Function: xstormy16_extract_return_value 00158 Find a function's return value in the appropriate registers (in 00159 regbuf), and copy it into valbuf. */ 00160 00161 static void 00162 xstormy16_extract_return_value (struct type *type, struct regcache *regcache, 00163 gdb_byte *valbuf) 00164 { 00165 int len = TYPE_LENGTH (type); 00166 int i, regnum = E_1ST_ARG_REGNUM; 00167 00168 for (i = 0; i < len; i += xstormy16_reg_size) 00169 regcache_raw_read (regcache, regnum++, valbuf + i); 00170 } 00171 00172 /* Function: xstormy16_store_return_value 00173 Copy the function return value from VALBUF into the 00174 proper location for a function return. 00175 Called only in the context of the "return" command. */ 00176 00177 static void 00178 xstormy16_store_return_value (struct type *type, struct regcache *regcache, 00179 const gdb_byte *valbuf) 00180 { 00181 if (TYPE_LENGTH (type) == 1) 00182 { 00183 /* Add leading zeros to the value. */ 00184 gdb_byte buf[xstormy16_reg_size]; 00185 memset (buf, 0, xstormy16_reg_size); 00186 memcpy (buf, valbuf, 1); 00187 regcache_raw_write (regcache, E_1ST_ARG_REGNUM, buf); 00188 } 00189 else 00190 { 00191 int len = TYPE_LENGTH (type); 00192 int i, regnum = E_1ST_ARG_REGNUM; 00193 00194 for (i = 0; i < len; i += xstormy16_reg_size) 00195 regcache_raw_write (regcache, regnum++, valbuf + i); 00196 } 00197 } 00198 00199 static enum return_value_convention 00200 xstormy16_return_value (struct gdbarch *gdbarch, struct value *function, 00201 struct type *type, struct regcache *regcache, 00202 gdb_byte *readbuf, const gdb_byte *writebuf) 00203 { 00204 if (xstormy16_use_struct_convention (type)) 00205 return RETURN_VALUE_STRUCT_CONVENTION; 00206 if (writebuf) 00207 xstormy16_store_return_value (type, regcache, writebuf); 00208 else if (readbuf) 00209 xstormy16_extract_return_value (type, regcache, readbuf); 00210 return RETURN_VALUE_REGISTER_CONVENTION; 00211 } 00212 00213 static CORE_ADDR 00214 xstormy16_frame_align (struct gdbarch *gdbarch, CORE_ADDR addr) 00215 { 00216 if (addr & 1) 00217 ++addr; 00218 return addr; 00219 } 00220 00221 /* Function: xstormy16_push_dummy_call 00222 Setup the function arguments for GDB to call a function in the inferior. 00223 Called only in the context of a target function call from the debugger. 00224 Returns the value of the SP register after the args are pushed. */ 00225 00226 static CORE_ADDR 00227 xstormy16_push_dummy_call (struct gdbarch *gdbarch, 00228 struct value *function, 00229 struct regcache *regcache, 00230 CORE_ADDR bp_addr, int nargs, 00231 struct value **args, 00232 CORE_ADDR sp, int struct_return, 00233 CORE_ADDR struct_addr) 00234 { 00235 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 00236 CORE_ADDR stack_dest = sp; 00237 int argreg = E_1ST_ARG_REGNUM; 00238 int i, j; 00239 int typelen, slacklen; 00240 const gdb_byte *val; 00241 gdb_byte buf[xstormy16_pc_size]; 00242 00243 /* If struct_return is true, then the struct return address will 00244 consume one argument-passing register. */ 00245 if (struct_return) 00246 { 00247 regcache_cooked_write_unsigned (regcache, E_PTR_RET_REGNUM, struct_addr); 00248 argreg++; 00249 } 00250 00251 /* Arguments are passed in R2-R7 as they fit. If an argument doesn't 00252 fit in the remaining registers we're switching over to the stack. 00253 No argument is put on stack partially and as soon as we switched 00254 over to stack no further argument is put in a register even if it 00255 would fit in the remaining unused registers. */ 00256 for (i = 0; i < nargs && argreg <= E_LST_ARG_REGNUM; i++) 00257 { 00258 typelen = TYPE_LENGTH (value_enclosing_type (args[i])); 00259 if (typelen > E_MAX_RETTYPE_SIZE (argreg)) 00260 break; 00261 00262 /* Put argument into registers wordwise. */ 00263 val = value_contents (args[i]); 00264 for (j = 0; j < typelen; j += xstormy16_reg_size) 00265 { 00266 ULONGEST regval; 00267 int size = (typelen - j == 1) ? 1 : xstormy16_reg_size; 00268 00269 regval = extract_unsigned_integer (val + j, size, byte_order); 00270 regcache_cooked_write_unsigned (regcache, argreg++, regval); 00271 } 00272 } 00273 00274 /* Align SP */ 00275 stack_dest = xstormy16_frame_align (gdbarch, stack_dest); 00276 00277 /* Loop backwards through remaining arguments and push them on the stack, 00278 wordaligned. */ 00279 for (j = nargs - 1; j >= i; j--) 00280 { 00281 gdb_byte *val; 00282 struct cleanup *back_to; 00283 const gdb_byte *bytes = value_contents (args[j]); 00284 00285 typelen = TYPE_LENGTH (value_enclosing_type (args[j])); 00286 slacklen = typelen & 1; 00287 val = xmalloc (typelen + slacklen); 00288 back_to = make_cleanup (xfree, val); 00289 memcpy (val, bytes, typelen); 00290 memset (val + typelen, 0, slacklen); 00291 00292 /* Now write this data to the stack. The stack grows upwards. */ 00293 write_memory (stack_dest, val, typelen + slacklen); 00294 stack_dest += typelen + slacklen; 00295 do_cleanups (back_to); 00296 } 00297 00298 store_unsigned_integer (buf, xstormy16_pc_size, byte_order, bp_addr); 00299 write_memory (stack_dest, buf, xstormy16_pc_size); 00300 stack_dest += xstormy16_pc_size; 00301 00302 /* Update stack pointer. */ 00303 regcache_cooked_write_unsigned (regcache, E_SP_REGNUM, stack_dest); 00304 00305 /* Return the new stack pointer minus the return address slot since 00306 that's what DWARF2/GCC uses as the frame's CFA. */ 00307 return stack_dest - xstormy16_pc_size; 00308 } 00309 00310 /* Function: xstormy16_scan_prologue 00311 Decode the instructions within the given address range. 00312 Decide when we must have reached the end of the function prologue. 00313 If a frame_info pointer is provided, fill in its saved_regs etc. 00314 00315 Returns the address of the first instruction after the prologue. */ 00316 00317 static CORE_ADDR 00318 xstormy16_analyze_prologue (struct gdbarch *gdbarch, 00319 CORE_ADDR start_addr, CORE_ADDR end_addr, 00320 struct xstormy16_frame_cache *cache, 00321 struct frame_info *this_frame) 00322 { 00323 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 00324 CORE_ADDR next_addr; 00325 ULONGEST inst, inst2; 00326 LONGEST offset; 00327 int regnum; 00328 00329 /* Initialize framesize with size of PC put on stack by CALLF inst. */ 00330 cache->saved_regs[E_PC_REGNUM] = 0; 00331 cache->framesize = xstormy16_pc_size; 00332 00333 if (start_addr >= end_addr) 00334 return end_addr; 00335 00336 for (next_addr = start_addr; 00337 next_addr < end_addr; next_addr += xstormy16_inst_size) 00338 { 00339 inst = read_memory_unsigned_integer (next_addr, 00340 xstormy16_inst_size, byte_order); 00341 inst2 = read_memory_unsigned_integer (next_addr + xstormy16_inst_size, 00342 xstormy16_inst_size, byte_order); 00343 00344 if (inst >= 0x0082 && inst <= 0x008d) /* push r2 .. push r13 */ 00345 { 00346 regnum = inst & 0x000f; 00347 cache->saved_regs[regnum] = cache->framesize; 00348 cache->framesize += xstormy16_reg_size; 00349 } 00350 00351 /* Optional stack allocation for args and local vars <= 4 byte. */ 00352 else if (inst == 0x301f || inst == 0x303f) /* inc r15, #0x1/#0x3 */ 00353 { 00354 cache->framesize += ((inst & 0x0030) >> 4) + 1; 00355 } 00356 00357 /* optional stack allocation for args and local vars > 4 && < 16 byte */ 00358 else if ((inst & 0xff0f) == 0x510f) /* 51Hf add r15, #0xH */ 00359 { 00360 cache->framesize += (inst & 0x00f0) >> 4; 00361 } 00362 00363 /* Optional stack allocation for args and local vars >= 16 byte. */ 00364 else if (inst == 0x314f && inst2 >= 0x0010) /* 314f HHHH add r15, #0xH */ 00365 { 00366 cache->framesize += inst2; 00367 next_addr += xstormy16_inst_size; 00368 } 00369 00370 else if (inst == 0x46fd) /* mov r13, r15 */ 00371 { 00372 cache->uses_fp = 1; 00373 } 00374 00375 /* optional copying of args in r2-r7 to r10-r13. */ 00376 /* Probably only in optimized case but legal action for prologue. */ 00377 else if ((inst & 0xff00) == 0x4600 /* 46SD mov rD, rS */ 00378 && (inst & 0x00f0) >= 0x0020 && (inst & 0x00f0) <= 0x0070 00379 && (inst & 0x000f) >= 0x00a0 && (inst & 0x000f) <= 0x000d) 00380 ; 00381 00382 /* Optional copying of args in r2-r7 to stack. */ 00383 /* 72DS HHHH mov.b (rD, 0xHHHH), r(S-8) 00384 (bit3 always 1, bit2-0 = reg) */ 00385 /* 73DS HHHH mov.w (rD, 0xHHHH), r(S-8) */ 00386 else if ((inst & 0xfed8) == 0x72d8 && (inst & 0x0007) >= 2) 00387 { 00388 regnum = inst & 0x0007; 00389 /* Only 12 of 16 bits of the argument are used for the 00390 signed offset. */ 00391 offset = (LONGEST) (inst2 & 0x0fff); 00392 if (offset & 0x0800) 00393 offset -= 0x1000; 00394 00395 cache->saved_regs[regnum] = cache->framesize + offset; 00396 next_addr += xstormy16_inst_size; 00397 } 00398 00399 else /* Not a prologue instruction. */ 00400 break; 00401 } 00402 00403 return next_addr; 00404 } 00405 00406 /* Function: xstormy16_skip_prologue 00407 If the input address is in a function prologue, 00408 returns the address of the end of the prologue; 00409 else returns the input address. 00410 00411 Note: the input address is likely to be the function start, 00412 since this function is mainly used for advancing a breakpoint 00413 to the first line, or stepping to the first line when we have 00414 stepped into a function call. */ 00415 00416 static CORE_ADDR 00417 xstormy16_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc) 00418 { 00419 CORE_ADDR func_addr = 0, func_end = 0; 00420 const char *func_name; 00421 00422 if (find_pc_partial_function (pc, &func_name, &func_addr, &func_end)) 00423 { 00424 struct symtab_and_line sal; 00425 struct symbol *sym; 00426 struct xstormy16_frame_cache cache; 00427 CORE_ADDR plg_end; 00428 00429 memset (&cache, 0, sizeof cache); 00430 00431 /* Don't trust line number debug info in frameless functions. */ 00432 plg_end = xstormy16_analyze_prologue (gdbarch, func_addr, func_end, 00433 &cache, NULL); 00434 if (!cache.uses_fp) 00435 return plg_end; 00436 00437 /* Found a function. */ 00438 sym = lookup_symbol (func_name, NULL, VAR_DOMAIN, NULL); 00439 /* Don't use line number debug info for assembly source files. */ 00440 if (sym && SYMBOL_LANGUAGE (sym) != language_asm) 00441 { 00442 sal = find_pc_line (func_addr, 0); 00443 if (sal.end && sal.end < func_end) 00444 { 00445 /* Found a line number, use it as end of prologue. */ 00446 return sal.end; 00447 } 00448 } 00449 /* No useable line symbol. Use result of prologue parsing method. */ 00450 return plg_end; 00451 } 00452 00453 /* No function symbol -- just return the PC. */ 00454 00455 return (CORE_ADDR) pc; 00456 } 00457 00458 /* The epilogue is defined here as the area at the end of a function, 00459 either on the `ret' instruction itself or after an instruction which 00460 destroys the function's stack frame. */ 00461 static int 00462 xstormy16_in_function_epilogue_p (struct gdbarch *gdbarch, CORE_ADDR pc) 00463 { 00464 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 00465 CORE_ADDR func_addr = 0, func_end = 0; 00466 00467 if (find_pc_partial_function (pc, NULL, &func_addr, &func_end)) 00468 { 00469 ULONGEST inst, inst2; 00470 CORE_ADDR addr = func_end - xstormy16_inst_size; 00471 00472 /* The Xstormy16 epilogue is max. 14 bytes long. */ 00473 if (pc < func_end - 7 * xstormy16_inst_size) 00474 return 0; 00475 00476 /* Check if we're on a `ret' instruction. Otherwise it's 00477 too dangerous to proceed. */ 00478 inst = read_memory_unsigned_integer (addr, 00479 xstormy16_inst_size, byte_order); 00480 if (inst != 0x0003) 00481 return 0; 00482 00483 while ((addr -= xstormy16_inst_size) >= func_addr) 00484 { 00485 inst = read_memory_unsigned_integer (addr, 00486 xstormy16_inst_size, 00487 byte_order); 00488 if (inst >= 0x009a && inst <= 0x009d) /* pop r10...r13 */ 00489 continue; 00490 if (inst == 0x305f || inst == 0x307f) /* dec r15, #0x1/#0x3 */ 00491 break; 00492 inst2 = read_memory_unsigned_integer (addr - xstormy16_inst_size, 00493 xstormy16_inst_size, 00494 byte_order); 00495 if (inst2 == 0x314f && inst >= 0x8000) /* add r15, neg. value */ 00496 { 00497 addr -= xstormy16_inst_size; 00498 break; 00499 } 00500 return 0; 00501 } 00502 if (pc > addr) 00503 return 1; 00504 } 00505 return 0; 00506 } 00507 00508 static const unsigned char * 00509 xstormy16_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr, 00510 int *lenptr) 00511 { 00512 static unsigned char breakpoint[] = { 0x06, 0x0 }; 00513 *lenptr = sizeof (breakpoint); 00514 return breakpoint; 00515 } 00516 00517 /* Given a pointer to a jump table entry, return the address 00518 of the function it jumps to. Return 0 if not found. */ 00519 static CORE_ADDR 00520 xstormy16_resolve_jmp_table_entry (struct gdbarch *gdbarch, CORE_ADDR faddr) 00521 { 00522 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 00523 struct obj_section *faddr_sect = find_pc_section (faddr); 00524 00525 if (faddr_sect) 00526 { 00527 LONGEST inst, inst2, addr; 00528 gdb_byte buf[2 * xstormy16_inst_size]; 00529 00530 /* Return faddr if it's not pointing into the jump table. */ 00531 if (strcmp (faddr_sect->the_bfd_section->name, ".plt")) 00532 return faddr; 00533 00534 if (!target_read_memory (faddr, buf, sizeof buf)) 00535 { 00536 inst = extract_unsigned_integer (buf, 00537 xstormy16_inst_size, byte_order); 00538 inst2 = extract_unsigned_integer (buf + xstormy16_inst_size, 00539 xstormy16_inst_size, byte_order); 00540 addr = inst2 << 8 | (inst & 0xff); 00541 return addr; 00542 } 00543 } 00544 return 0; 00545 } 00546 00547 /* Given a function's address, attempt to find (and return) the 00548 address of the corresponding jump table entry. Return 0 if 00549 not found. */ 00550 static CORE_ADDR 00551 xstormy16_find_jmp_table_entry (struct gdbarch *gdbarch, CORE_ADDR faddr) 00552 { 00553 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 00554 struct obj_section *faddr_sect = find_pc_section (faddr); 00555 00556 if (faddr_sect) 00557 { 00558 struct obj_section *osect; 00559 00560 /* Return faddr if it's already a pointer to a jump table entry. */ 00561 if (!strcmp (faddr_sect->the_bfd_section->name, ".plt")) 00562 return faddr; 00563 00564 ALL_OBJFILE_OSECTIONS (faddr_sect->objfile, osect) 00565 { 00566 if (!strcmp (osect->the_bfd_section->name, ".plt")) 00567 break; 00568 } 00569 00570 if (osect < faddr_sect->objfile->sections_end) 00571 { 00572 CORE_ADDR addr, endaddr; 00573 00574 addr = obj_section_addr (osect); 00575 endaddr = obj_section_endaddr (osect); 00576 00577 for (; addr < endaddr; addr += 2 * xstormy16_inst_size) 00578 { 00579 LONGEST inst, inst2, faddr2; 00580 gdb_byte buf[2 * xstormy16_inst_size]; 00581 00582 if (target_read_memory (addr, buf, sizeof buf)) 00583 return 0; 00584 inst = extract_unsigned_integer (buf, 00585 xstormy16_inst_size, 00586 byte_order); 00587 inst2 = extract_unsigned_integer (buf + xstormy16_inst_size, 00588 xstormy16_inst_size, 00589 byte_order); 00590 faddr2 = inst2 << 8 | (inst & 0xff); 00591 if (faddr == faddr2) 00592 return addr; 00593 } 00594 } 00595 } 00596 return 0; 00597 } 00598 00599 static CORE_ADDR 00600 xstormy16_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc) 00601 { 00602 struct gdbarch *gdbarch = get_frame_arch (frame); 00603 CORE_ADDR tmp = xstormy16_resolve_jmp_table_entry (gdbarch, pc); 00604 00605 if (tmp && tmp != pc) 00606 return tmp; 00607 return 0; 00608 } 00609 00610 /* Function pointers are 16 bit. The address space is 24 bit, using 00611 32 bit addresses. Pointers to functions on the XStormy16 are implemented 00612 by using 16 bit pointers, which are either direct pointers in case the 00613 function begins below 0x10000, or indirect pointers into a jump table. 00614 The next two functions convert 16 bit pointers into 24 (32) bit addresses 00615 and vice versa. */ 00616 00617 static CORE_ADDR 00618 xstormy16_pointer_to_address (struct gdbarch *gdbarch, 00619 struct type *type, const gdb_byte *buf) 00620 { 00621 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 00622 enum type_code target = TYPE_CODE (TYPE_TARGET_TYPE (type)); 00623 CORE_ADDR addr 00624 = extract_unsigned_integer (buf, TYPE_LENGTH (type), byte_order); 00625 00626 if (target == TYPE_CODE_FUNC || target == TYPE_CODE_METHOD) 00627 { 00628 CORE_ADDR addr2 = xstormy16_resolve_jmp_table_entry (gdbarch, addr); 00629 if (addr2) 00630 addr = addr2; 00631 } 00632 00633 return addr; 00634 } 00635 00636 static void 00637 xstormy16_address_to_pointer (struct gdbarch *gdbarch, 00638 struct type *type, gdb_byte *buf, CORE_ADDR addr) 00639 { 00640 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 00641 enum type_code target = TYPE_CODE (TYPE_TARGET_TYPE (type)); 00642 00643 if (target == TYPE_CODE_FUNC || target == TYPE_CODE_METHOD) 00644 { 00645 CORE_ADDR addr2 = xstormy16_find_jmp_table_entry (gdbarch, addr); 00646 if (addr2) 00647 addr = addr2; 00648 } 00649 store_unsigned_integer (buf, TYPE_LENGTH (type), byte_order, addr); 00650 } 00651 00652 static struct xstormy16_frame_cache * 00653 xstormy16_alloc_frame_cache (void) 00654 { 00655 struct xstormy16_frame_cache *cache; 00656 int i; 00657 00658 cache = FRAME_OBSTACK_ZALLOC (struct xstormy16_frame_cache); 00659 00660 cache->base = 0; 00661 cache->saved_sp = 0; 00662 cache->pc = 0; 00663 cache->uses_fp = 0; 00664 cache->framesize = 0; 00665 for (i = 0; i < E_NUM_REGS; ++i) 00666 cache->saved_regs[i] = REG_UNAVAIL; 00667 00668 return cache; 00669 } 00670 00671 static struct xstormy16_frame_cache * 00672 xstormy16_frame_cache (struct frame_info *this_frame, void **this_cache) 00673 { 00674 struct gdbarch *gdbarch = get_frame_arch (this_frame); 00675 struct xstormy16_frame_cache *cache; 00676 CORE_ADDR current_pc; 00677 int i; 00678 00679 if (*this_cache) 00680 return *this_cache; 00681 00682 cache = xstormy16_alloc_frame_cache (); 00683 *this_cache = cache; 00684 00685 cache->base = get_frame_register_unsigned (this_frame, E_FP_REGNUM); 00686 if (cache->base == 0) 00687 return cache; 00688 00689 cache->pc = get_frame_func (this_frame); 00690 current_pc = get_frame_pc (this_frame); 00691 if (cache->pc) 00692 xstormy16_analyze_prologue (gdbarch, cache->pc, current_pc, 00693 cache, this_frame); 00694 00695 if (!cache->uses_fp) 00696 cache->base = get_frame_register_unsigned (this_frame, E_SP_REGNUM); 00697 00698 cache->saved_sp = cache->base - cache->framesize; 00699 00700 for (i = 0; i < E_NUM_REGS; ++i) 00701 if (cache->saved_regs[i] != REG_UNAVAIL) 00702 cache->saved_regs[i] += cache->saved_sp; 00703 00704 return cache; 00705 } 00706 00707 static struct value * 00708 xstormy16_frame_prev_register (struct frame_info *this_frame, 00709 void **this_cache, int regnum) 00710 { 00711 struct xstormy16_frame_cache *cache = xstormy16_frame_cache (this_frame, 00712 this_cache); 00713 gdb_assert (regnum >= 0); 00714 00715 if (regnum == E_SP_REGNUM && cache->saved_sp) 00716 return frame_unwind_got_constant (this_frame, regnum, cache->saved_sp); 00717 00718 if (regnum < E_NUM_REGS && cache->saved_regs[regnum] != REG_UNAVAIL) 00719 return frame_unwind_got_memory (this_frame, regnum, 00720 cache->saved_regs[regnum]); 00721 00722 return frame_unwind_got_register (this_frame, regnum, regnum); 00723 } 00724 00725 static void 00726 xstormy16_frame_this_id (struct frame_info *this_frame, void **this_cache, 00727 struct frame_id *this_id) 00728 { 00729 struct xstormy16_frame_cache *cache = xstormy16_frame_cache (this_frame, 00730 this_cache); 00731 00732 /* This marks the outermost frame. */ 00733 if (cache->base == 0) 00734 return; 00735 00736 *this_id = frame_id_build (cache->saved_sp, cache->pc); 00737 } 00738 00739 static CORE_ADDR 00740 xstormy16_frame_base_address (struct frame_info *this_frame, void **this_cache) 00741 { 00742 struct xstormy16_frame_cache *cache = xstormy16_frame_cache (this_frame, 00743 this_cache); 00744 return cache->base; 00745 } 00746 00747 static const struct frame_unwind xstormy16_frame_unwind = { 00748 NORMAL_FRAME, 00749 default_frame_unwind_stop_reason, 00750 xstormy16_frame_this_id, 00751 xstormy16_frame_prev_register, 00752 NULL, 00753 default_frame_sniffer 00754 }; 00755 00756 static const struct frame_base xstormy16_frame_base = { 00757 &xstormy16_frame_unwind, 00758 xstormy16_frame_base_address, 00759 xstormy16_frame_base_address, 00760 xstormy16_frame_base_address 00761 }; 00762 00763 static CORE_ADDR 00764 xstormy16_unwind_sp (struct gdbarch *gdbarch, struct frame_info *next_frame) 00765 { 00766 return frame_unwind_register_unsigned (next_frame, E_SP_REGNUM); 00767 } 00768 00769 static CORE_ADDR 00770 xstormy16_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame) 00771 { 00772 return frame_unwind_register_unsigned (next_frame, E_PC_REGNUM); 00773 } 00774 00775 static struct frame_id 00776 xstormy16_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame) 00777 { 00778 CORE_ADDR sp = get_frame_register_unsigned (this_frame, E_SP_REGNUM); 00779 return frame_id_build (sp, get_frame_pc (this_frame)); 00780 } 00781 00782 00783 /* Function: xstormy16_gdbarch_init 00784 Initializer function for the xstormy16 gdbarch vector. 00785 Called by gdbarch. Sets up the gdbarch vector(s) for this target. */ 00786 00787 static struct gdbarch * 00788 xstormy16_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) 00789 { 00790 struct gdbarch *gdbarch; 00791 00792 /* find a candidate among the list of pre-declared architectures. */ 00793 arches = gdbarch_list_lookup_by_info (arches, &info); 00794 if (arches != NULL) 00795 return (arches->gdbarch); 00796 00797 gdbarch = gdbarch_alloc (&info, NULL); 00798 00799 /* 00800 * Basic register fields and methods, datatype sizes and stuff. 00801 */ 00802 00803 set_gdbarch_num_regs (gdbarch, E_NUM_REGS); 00804 set_gdbarch_num_pseudo_regs (gdbarch, 0); 00805 set_gdbarch_sp_regnum (gdbarch, E_SP_REGNUM); 00806 set_gdbarch_pc_regnum (gdbarch, E_PC_REGNUM); 00807 set_gdbarch_register_name (gdbarch, xstormy16_register_name); 00808 set_gdbarch_register_type (gdbarch, xstormy16_register_type); 00809 00810 set_gdbarch_char_signed (gdbarch, 0); 00811 set_gdbarch_short_bit (gdbarch, 2 * TARGET_CHAR_BIT); 00812 set_gdbarch_int_bit (gdbarch, 2 * TARGET_CHAR_BIT); 00813 set_gdbarch_long_bit (gdbarch, 4 * TARGET_CHAR_BIT); 00814 set_gdbarch_long_long_bit (gdbarch, 8 * TARGET_CHAR_BIT); 00815 00816 set_gdbarch_float_bit (gdbarch, 4 * TARGET_CHAR_BIT); 00817 set_gdbarch_double_bit (gdbarch, 8 * TARGET_CHAR_BIT); 00818 set_gdbarch_long_double_bit (gdbarch, 8 * TARGET_CHAR_BIT); 00819 00820 set_gdbarch_ptr_bit (gdbarch, 2 * TARGET_CHAR_BIT); 00821 set_gdbarch_addr_bit (gdbarch, 4 * TARGET_CHAR_BIT); 00822 set_gdbarch_dwarf2_addr_size (gdbarch, 4); 00823 00824 set_gdbarch_address_to_pointer (gdbarch, xstormy16_address_to_pointer); 00825 set_gdbarch_pointer_to_address (gdbarch, xstormy16_pointer_to_address); 00826 00827 /* Stack grows up. */ 00828 set_gdbarch_inner_than (gdbarch, core_addr_greaterthan); 00829 00830 /* 00831 * Frame Info 00832 */ 00833 set_gdbarch_unwind_sp (gdbarch, xstormy16_unwind_sp); 00834 set_gdbarch_unwind_pc (gdbarch, xstormy16_unwind_pc); 00835 set_gdbarch_dummy_id (gdbarch, xstormy16_dummy_id); 00836 set_gdbarch_frame_align (gdbarch, xstormy16_frame_align); 00837 frame_base_set_default (gdbarch, &xstormy16_frame_base); 00838 00839 set_gdbarch_skip_prologue (gdbarch, xstormy16_skip_prologue); 00840 set_gdbarch_in_function_epilogue_p (gdbarch, 00841 xstormy16_in_function_epilogue_p); 00842 00843 /* These values and methods are used when gdb calls a target function. */ 00844 set_gdbarch_push_dummy_call (gdbarch, xstormy16_push_dummy_call); 00845 set_gdbarch_breakpoint_from_pc (gdbarch, xstormy16_breakpoint_from_pc); 00846 set_gdbarch_return_value (gdbarch, xstormy16_return_value); 00847 00848 set_gdbarch_skip_trampoline_code (gdbarch, xstormy16_skip_trampoline_code); 00849 00850 set_gdbarch_print_insn (gdbarch, print_insn_xstormy16); 00851 00852 gdbarch_init_osabi (info, gdbarch); 00853 00854 dwarf2_append_unwinders (gdbarch); 00855 frame_unwind_append_unwinder (gdbarch, &xstormy16_frame_unwind); 00856 00857 return gdbarch; 00858 } 00859 00860 /* Function: _initialize_xstormy16_tdep 00861 Initializer function for the Sanyo Xstormy16a module. 00862 Called by gdb at start-up. */ 00863 00864 /* -Wmissing-prototypes */ 00865 extern initialize_file_ftype _initialize_xstormy16_tdep; 00866 00867 void 00868 _initialize_xstormy16_tdep (void) 00869 { 00870 register_gdbarch_init (bfd_arch_xstormy16, xstormy16_gdbarch_init); 00871 }