GDB (API)
|
00001 /* Target-dependent code for the Fujitsu FR-V, for GDB, the GNU Debugger. 00002 00003 Copyright (C) 2002-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 "gdb_string.h" 00022 #include "inferior.h" 00023 #include "gdbcore.h" 00024 #include "arch-utils.h" 00025 #include "regcache.h" 00026 #include "frame.h" 00027 #include "frame-unwind.h" 00028 #include "frame-base.h" 00029 #include "trad-frame.h" 00030 #include "dis-asm.h" 00031 #include "gdb_assert.h" 00032 #include "sim-regno.h" 00033 #include "gdb/sim-frv.h" 00034 #include "opcodes/frv-desc.h" /* for the H_SPR_... enums */ 00035 #include "symtab.h" 00036 #include "elf-bfd.h" 00037 #include "elf/frv.h" 00038 #include "osabi.h" 00039 #include "infcall.h" 00040 #include "solib.h" 00041 #include "frv-tdep.h" 00042 00043 extern void _initialize_frv_tdep (void); 00044 00045 struct frv_unwind_cache /* was struct frame_extra_info */ 00046 { 00047 /* The previous frame's inner-most stack address. Used as this 00048 frame ID's stack_addr. */ 00049 CORE_ADDR prev_sp; 00050 00051 /* The frame's base, optionally used by the high-level debug info. */ 00052 CORE_ADDR base; 00053 00054 /* Table indicating the location of each and every register. */ 00055 struct trad_frame_saved_reg *saved_regs; 00056 }; 00057 00058 /* A structure describing a particular variant of the FRV. 00059 We allocate and initialize one of these structures when we create 00060 the gdbarch object for a variant. 00061 00062 At the moment, all the FR variants we support differ only in which 00063 registers are present; the portable code of GDB knows that 00064 registers whose names are the empty string don't exist, so the 00065 `register_names' array captures all the per-variant information we 00066 need. 00067 00068 in the future, if we need to have per-variant maps for raw size, 00069 virtual type, etc., we should replace register_names with an array 00070 of structures, each of which gives all the necessary info for one 00071 register. Don't stick parallel arrays in here --- that's so 00072 Fortran. */ 00073 struct gdbarch_tdep 00074 { 00075 /* Which ABI is in use? */ 00076 enum frv_abi frv_abi; 00077 00078 /* How many general-purpose registers does this variant have? */ 00079 int num_gprs; 00080 00081 /* How many floating-point registers does this variant have? */ 00082 int num_fprs; 00083 00084 /* How many hardware watchpoints can it support? */ 00085 int num_hw_watchpoints; 00086 00087 /* How many hardware breakpoints can it support? */ 00088 int num_hw_breakpoints; 00089 00090 /* Register names. */ 00091 char **register_names; 00092 }; 00093 00094 /* Return the FR-V ABI associated with GDBARCH. */ 00095 enum frv_abi 00096 frv_abi (struct gdbarch *gdbarch) 00097 { 00098 return gdbarch_tdep (gdbarch)->frv_abi; 00099 } 00100 00101 /* Fetch the interpreter and executable loadmap addresses (for shared 00102 library support) for the FDPIC ABI. Return 0 if successful, -1 if 00103 not. (E.g, -1 will be returned if the ABI isn't the FDPIC ABI.) */ 00104 int 00105 frv_fdpic_loadmap_addresses (struct gdbarch *gdbarch, CORE_ADDR *interp_addr, 00106 CORE_ADDR *exec_addr) 00107 { 00108 if (frv_abi (gdbarch) != FRV_ABI_FDPIC) 00109 return -1; 00110 else 00111 { 00112 struct regcache *regcache = get_current_regcache (); 00113 00114 if (interp_addr != NULL) 00115 { 00116 ULONGEST val; 00117 regcache_cooked_read_unsigned (regcache, 00118 fdpic_loadmap_interp_regnum, &val); 00119 *interp_addr = val; 00120 } 00121 if (exec_addr != NULL) 00122 { 00123 ULONGEST val; 00124 regcache_cooked_read_unsigned (regcache, 00125 fdpic_loadmap_exec_regnum, &val); 00126 *exec_addr = val; 00127 } 00128 return 0; 00129 } 00130 } 00131 00132 /* Allocate a new variant structure, and set up default values for all 00133 the fields. */ 00134 static struct gdbarch_tdep * 00135 new_variant (void) 00136 { 00137 struct gdbarch_tdep *var; 00138 int r; 00139 00140 var = xmalloc (sizeof (*var)); 00141 memset (var, 0, sizeof (*var)); 00142 00143 var->frv_abi = FRV_ABI_EABI; 00144 var->num_gprs = 64; 00145 var->num_fprs = 64; 00146 var->num_hw_watchpoints = 0; 00147 var->num_hw_breakpoints = 0; 00148 00149 /* By default, don't supply any general-purpose or floating-point 00150 register names. */ 00151 var->register_names 00152 = (char **) xmalloc ((frv_num_regs + frv_num_pseudo_regs) 00153 * sizeof (char *)); 00154 for (r = 0; r < frv_num_regs + frv_num_pseudo_regs; r++) 00155 var->register_names[r] = ""; 00156 00157 /* Do, however, supply default names for the known special-purpose 00158 registers. */ 00159 00160 var->register_names[pc_regnum] = "pc"; 00161 var->register_names[lr_regnum] = "lr"; 00162 var->register_names[lcr_regnum] = "lcr"; 00163 00164 var->register_names[psr_regnum] = "psr"; 00165 var->register_names[ccr_regnum] = "ccr"; 00166 var->register_names[cccr_regnum] = "cccr"; 00167 var->register_names[tbr_regnum] = "tbr"; 00168 00169 /* Debug registers. */ 00170 var->register_names[brr_regnum] = "brr"; 00171 var->register_names[dbar0_regnum] = "dbar0"; 00172 var->register_names[dbar1_regnum] = "dbar1"; 00173 var->register_names[dbar2_regnum] = "dbar2"; 00174 var->register_names[dbar3_regnum] = "dbar3"; 00175 00176 /* iacc0 (Only found on MB93405.) */ 00177 var->register_names[iacc0h_regnum] = "iacc0h"; 00178 var->register_names[iacc0l_regnum] = "iacc0l"; 00179 var->register_names[iacc0_regnum] = "iacc0"; 00180 00181 /* fsr0 (Found on FR555 and FR501.) */ 00182 var->register_names[fsr0_regnum] = "fsr0"; 00183 00184 /* acc0 - acc7. The architecture provides for the possibility of many 00185 more (up to 64 total), but we don't want to make that big of a hole 00186 in the G packet. If we need more in the future, we'll add them 00187 elsewhere. */ 00188 for (r = acc0_regnum; r <= acc7_regnum; r++) 00189 { 00190 char *buf; 00191 buf = xstrprintf ("acc%d", r - acc0_regnum); 00192 var->register_names[r] = buf; 00193 } 00194 00195 /* accg0 - accg7: These are one byte registers. The remote protocol 00196 provides the raw values packed four into a slot. accg0123 and 00197 accg4567 correspond to accg0 - accg3 and accg4-accg7 respectively. 00198 We don't provide names for accg0123 and accg4567 since the user will 00199 likely not want to see these raw values. */ 00200 00201 for (r = accg0_regnum; r <= accg7_regnum; r++) 00202 { 00203 char *buf; 00204 buf = xstrprintf ("accg%d", r - accg0_regnum); 00205 var->register_names[r] = buf; 00206 } 00207 00208 /* msr0 and msr1. */ 00209 00210 var->register_names[msr0_regnum] = "msr0"; 00211 var->register_names[msr1_regnum] = "msr1"; 00212 00213 /* gner and fner registers. */ 00214 var->register_names[gner0_regnum] = "gner0"; 00215 var->register_names[gner1_regnum] = "gner1"; 00216 var->register_names[fner0_regnum] = "fner0"; 00217 var->register_names[fner1_regnum] = "fner1"; 00218 00219 return var; 00220 } 00221 00222 00223 /* Indicate that the variant VAR has NUM_GPRS general-purpose 00224 registers, and fill in the names array appropriately. */ 00225 static void 00226 set_variant_num_gprs (struct gdbarch_tdep *var, int num_gprs) 00227 { 00228 int r; 00229 00230 var->num_gprs = num_gprs; 00231 00232 for (r = 0; r < num_gprs; ++r) 00233 { 00234 char buf[20]; 00235 00236 xsnprintf (buf, sizeof (buf), "gr%d", r); 00237 var->register_names[first_gpr_regnum + r] = xstrdup (buf); 00238 } 00239 } 00240 00241 00242 /* Indicate that the variant VAR has NUM_FPRS floating-point 00243 registers, and fill in the names array appropriately. */ 00244 static void 00245 set_variant_num_fprs (struct gdbarch_tdep *var, int num_fprs) 00246 { 00247 int r; 00248 00249 var->num_fprs = num_fprs; 00250 00251 for (r = 0; r < num_fprs; ++r) 00252 { 00253 char buf[20]; 00254 00255 xsnprintf (buf, sizeof (buf), "fr%d", r); 00256 var->register_names[first_fpr_regnum + r] = xstrdup (buf); 00257 } 00258 } 00259 00260 static void 00261 set_variant_abi_fdpic (struct gdbarch_tdep *var) 00262 { 00263 var->frv_abi = FRV_ABI_FDPIC; 00264 var->register_names[fdpic_loadmap_exec_regnum] = xstrdup ("loadmap_exec"); 00265 var->register_names[fdpic_loadmap_interp_regnum] 00266 = xstrdup ("loadmap_interp"); 00267 } 00268 00269 static void 00270 set_variant_scratch_registers (struct gdbarch_tdep *var) 00271 { 00272 var->register_names[scr0_regnum] = xstrdup ("scr0"); 00273 var->register_names[scr1_regnum] = xstrdup ("scr1"); 00274 var->register_names[scr2_regnum] = xstrdup ("scr2"); 00275 var->register_names[scr3_regnum] = xstrdup ("scr3"); 00276 } 00277 00278 static const char * 00279 frv_register_name (struct gdbarch *gdbarch, int reg) 00280 { 00281 if (reg < 0) 00282 return "?toosmall?"; 00283 if (reg >= frv_num_regs + frv_num_pseudo_regs) 00284 return "?toolarge?"; 00285 00286 return gdbarch_tdep (gdbarch)->register_names[reg]; 00287 } 00288 00289 00290 static struct type * 00291 frv_register_type (struct gdbarch *gdbarch, int reg) 00292 { 00293 if (reg >= first_fpr_regnum && reg <= last_fpr_regnum) 00294 return builtin_type (gdbarch)->builtin_float; 00295 else if (reg == iacc0_regnum) 00296 return builtin_type (gdbarch)->builtin_int64; 00297 else 00298 return builtin_type (gdbarch)->builtin_int32; 00299 } 00300 00301 static enum register_status 00302 frv_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache, 00303 int reg, gdb_byte *buffer) 00304 { 00305 enum register_status status; 00306 00307 if (reg == iacc0_regnum) 00308 { 00309 status = regcache_raw_read (regcache, iacc0h_regnum, buffer); 00310 if (status == REG_VALID) 00311 status = regcache_raw_read (regcache, iacc0l_regnum, (bfd_byte *) buffer + 4); 00312 } 00313 else if (accg0_regnum <= reg && reg <= accg7_regnum) 00314 { 00315 /* The accg raw registers have four values in each slot with the 00316 lowest register number occupying the first byte. */ 00317 00318 int raw_regnum = accg0123_regnum + (reg - accg0_regnum) / 4; 00319 int byte_num = (reg - accg0_regnum) % 4; 00320 gdb_byte buf[4]; 00321 00322 status = regcache_raw_read (regcache, raw_regnum, buf); 00323 if (status == REG_VALID) 00324 { 00325 memset (buffer, 0, 4); 00326 /* FR-V is big endian, so put the requested byte in the 00327 first byte of the buffer allocated to hold the 00328 pseudo-register. */ 00329 buffer[0] = buf[byte_num]; 00330 } 00331 } 00332 else 00333 gdb_assert_not_reached ("invalid pseudo register number"); 00334 00335 return status; 00336 } 00337 00338 static void 00339 frv_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache, 00340 int reg, const gdb_byte *buffer) 00341 { 00342 if (reg == iacc0_regnum) 00343 { 00344 regcache_raw_write (regcache, iacc0h_regnum, buffer); 00345 regcache_raw_write (regcache, iacc0l_regnum, (bfd_byte *) buffer + 4); 00346 } 00347 else if (accg0_regnum <= reg && reg <= accg7_regnum) 00348 { 00349 /* The accg raw registers have four values in each slot with the 00350 lowest register number occupying the first byte. */ 00351 00352 int raw_regnum = accg0123_regnum + (reg - accg0_regnum) / 4; 00353 int byte_num = (reg - accg0_regnum) % 4; 00354 gdb_byte buf[4]; 00355 00356 regcache_raw_read (regcache, raw_regnum, buf); 00357 buf[byte_num] = ((bfd_byte *) buffer)[0]; 00358 regcache_raw_write (regcache, raw_regnum, buf); 00359 } 00360 } 00361 00362 static int 00363 frv_register_sim_regno (struct gdbarch *gdbarch, int reg) 00364 { 00365 static const int spr_map[] = 00366 { 00367 H_SPR_PSR, /* psr_regnum */ 00368 H_SPR_CCR, /* ccr_regnum */ 00369 H_SPR_CCCR, /* cccr_regnum */ 00370 -1, /* fdpic_loadmap_exec_regnum */ 00371 -1, /* fdpic_loadmap_interp_regnum */ 00372 -1, /* 134 */ 00373 H_SPR_TBR, /* tbr_regnum */ 00374 H_SPR_BRR, /* brr_regnum */ 00375 H_SPR_DBAR0, /* dbar0_regnum */ 00376 H_SPR_DBAR1, /* dbar1_regnum */ 00377 H_SPR_DBAR2, /* dbar2_regnum */ 00378 H_SPR_DBAR3, /* dbar3_regnum */ 00379 H_SPR_SCR0, /* scr0_regnum */ 00380 H_SPR_SCR1, /* scr1_regnum */ 00381 H_SPR_SCR2, /* scr2_regnum */ 00382 H_SPR_SCR3, /* scr3_regnum */ 00383 H_SPR_LR, /* lr_regnum */ 00384 H_SPR_LCR, /* lcr_regnum */ 00385 H_SPR_IACC0H, /* iacc0h_regnum */ 00386 H_SPR_IACC0L, /* iacc0l_regnum */ 00387 H_SPR_FSR0, /* fsr0_regnum */ 00388 /* FIXME: Add infrastructure for fetching/setting ACC and ACCG regs. */ 00389 -1, /* acc0_regnum */ 00390 -1, /* acc1_regnum */ 00391 -1, /* acc2_regnum */ 00392 -1, /* acc3_regnum */ 00393 -1, /* acc4_regnum */ 00394 -1, /* acc5_regnum */ 00395 -1, /* acc6_regnum */ 00396 -1, /* acc7_regnum */ 00397 -1, /* acc0123_regnum */ 00398 -1, /* acc4567_regnum */ 00399 H_SPR_MSR0, /* msr0_regnum */ 00400 H_SPR_MSR1, /* msr1_regnum */ 00401 H_SPR_GNER0, /* gner0_regnum */ 00402 H_SPR_GNER1, /* gner1_regnum */ 00403 H_SPR_FNER0, /* fner0_regnum */ 00404 H_SPR_FNER1, /* fner1_regnum */ 00405 }; 00406 00407 gdb_assert (reg >= 0 && reg < gdbarch_num_regs (gdbarch)); 00408 00409 if (first_gpr_regnum <= reg && reg <= last_gpr_regnum) 00410 return reg - first_gpr_regnum + SIM_FRV_GR0_REGNUM; 00411 else if (first_fpr_regnum <= reg && reg <= last_fpr_regnum) 00412 return reg - first_fpr_regnum + SIM_FRV_FR0_REGNUM; 00413 else if (pc_regnum == reg) 00414 return SIM_FRV_PC_REGNUM; 00415 else if (reg >= first_spr_regnum 00416 && reg < first_spr_regnum + sizeof (spr_map) / sizeof (spr_map[0])) 00417 { 00418 int spr_reg_offset = spr_map[reg - first_spr_regnum]; 00419 00420 if (spr_reg_offset < 0) 00421 return SIM_REGNO_DOES_NOT_EXIST; 00422 else 00423 return SIM_FRV_SPR0_REGNUM + spr_reg_offset; 00424 } 00425 00426 internal_error (__FILE__, __LINE__, _("Bad register number %d"), reg); 00427 } 00428 00429 static const unsigned char * 00430 frv_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr, int *lenp) 00431 { 00432 static unsigned char breakpoint[] = {0xc0, 0x70, 0x00, 0x01}; 00433 *lenp = sizeof (breakpoint); 00434 return breakpoint; 00435 } 00436 00437 /* Define the maximum number of instructions which may be packed into a 00438 bundle (VLIW instruction). */ 00439 static const int max_instrs_per_bundle = 8; 00440 00441 /* Define the size (in bytes) of an FR-V instruction. */ 00442 static const int frv_instr_size = 4; 00443 00444 /* Adjust a breakpoint's address to account for the FR-V architecture's 00445 constraint that a break instruction must not appear as any but the 00446 first instruction in the bundle. */ 00447 static CORE_ADDR 00448 frv_adjust_breakpoint_address (struct gdbarch *gdbarch, CORE_ADDR bpaddr) 00449 { 00450 int count = max_instrs_per_bundle; 00451 CORE_ADDR addr = bpaddr - frv_instr_size; 00452 CORE_ADDR func_start = get_pc_function_start (bpaddr); 00453 00454 /* Find the end of the previous packing sequence. This will be indicated 00455 by either attempting to access some inaccessible memory or by finding 00456 an instruction word whose packing bit is set to one. */ 00457 while (count-- > 0 && addr >= func_start) 00458 { 00459 gdb_byte instr[frv_instr_size]; 00460 int status; 00461 00462 status = target_read_memory (addr, instr, sizeof instr); 00463 00464 if (status != 0) 00465 break; 00466 00467 /* This is a big endian architecture, so byte zero will have most 00468 significant byte. The most significant bit of this byte is the 00469 packing bit. */ 00470 if (instr[0] & 0x80) 00471 break; 00472 00473 addr -= frv_instr_size; 00474 } 00475 00476 if (count > 0) 00477 bpaddr = addr + frv_instr_size; 00478 00479 return bpaddr; 00480 } 00481 00482 00483 /* Return true if REG is a caller-saves ("scratch") register, 00484 false otherwise. */ 00485 static int 00486 is_caller_saves_reg (int reg) 00487 { 00488 return ((4 <= reg && reg <= 7) 00489 || (14 <= reg && reg <= 15) 00490 || (32 <= reg && reg <= 47)); 00491 } 00492 00493 00494 /* Return true if REG is a callee-saves register, false otherwise. */ 00495 static int 00496 is_callee_saves_reg (int reg) 00497 { 00498 return ((16 <= reg && reg <= 31) 00499 || (48 <= reg && reg <= 63)); 00500 } 00501 00502 00503 /* Return true if REG is an argument register, false otherwise. */ 00504 static int 00505 is_argument_reg (int reg) 00506 { 00507 return (8 <= reg && reg <= 13); 00508 } 00509 00510 /* Scan an FR-V prologue, starting at PC, until frame->PC. 00511 If FRAME is non-zero, fill in its saved_regs with appropriate addresses. 00512 We assume FRAME's saved_regs array has already been allocated and cleared. 00513 Return the first PC value after the prologue. 00514 00515 Note that, for unoptimized code, we almost don't need this function 00516 at all; all arguments and locals live on the stack, so we just need 00517 the FP to find everything. The catch: structures passed by value 00518 have their addresses living in registers; they're never spilled to 00519 the stack. So if you ever want to be able to get to these 00520 arguments in any frame but the top, you'll need to do this serious 00521 prologue analysis. */ 00522 static CORE_ADDR 00523 frv_analyze_prologue (struct gdbarch *gdbarch, CORE_ADDR pc, 00524 struct frame_info *this_frame, 00525 struct frv_unwind_cache *info) 00526 { 00527 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 00528 00529 /* When writing out instruction bitpatterns, we use the following 00530 letters to label instruction fields: 00531 P - The parallel bit. We don't use this. 00532 J - The register number of GRj in the instruction description. 00533 K - The register number of GRk in the instruction description. 00534 I - The register number of GRi. 00535 S - a signed imediate offset. 00536 U - an unsigned immediate offset. 00537 00538 The dots below the numbers indicate where hex digit boundaries 00539 fall, to make it easier to check the numbers. */ 00540 00541 /* Non-zero iff we've seen the instruction that initializes the 00542 frame pointer for this function's frame. */ 00543 int fp_set = 0; 00544 00545 /* If fp_set is non_zero, then this is the distance from 00546 the stack pointer to frame pointer: fp = sp + fp_offset. */ 00547 int fp_offset = 0; 00548 00549 /* Total size of frame prior to any alloca operations. */ 00550 int framesize = 0; 00551 00552 /* Flag indicating if lr has been saved on the stack. */ 00553 int lr_saved_on_stack = 0; 00554 00555 /* The number of the general-purpose register we saved the return 00556 address ("link register") in, or -1 if we haven't moved it yet. */ 00557 int lr_save_reg = -1; 00558 00559 /* Offset (from sp) at which lr has been saved on the stack. */ 00560 00561 int lr_sp_offset = 0; 00562 00563 /* If gr_saved[i] is non-zero, then we've noticed that general 00564 register i has been saved at gr_sp_offset[i] from the stack 00565 pointer. */ 00566 char gr_saved[64]; 00567 int gr_sp_offset[64]; 00568 00569 /* The address of the most recently scanned prologue instruction. */ 00570 CORE_ADDR last_prologue_pc; 00571 00572 /* The address of the next instruction. */ 00573 CORE_ADDR next_pc; 00574 00575 /* The upper bound to of the pc values to scan. */ 00576 CORE_ADDR lim_pc; 00577 00578 memset (gr_saved, 0, sizeof (gr_saved)); 00579 00580 last_prologue_pc = pc; 00581 00582 /* Try to compute an upper limit (on how far to scan) based on the 00583 line number info. */ 00584 lim_pc = skip_prologue_using_sal (gdbarch, pc); 00585 /* If there's no line number info, lim_pc will be 0. In that case, 00586 set the limit to be 100 instructions away from pc. Hopefully, this 00587 will be far enough away to account for the entire prologue. Don't 00588 worry about overshooting the end of the function. The scan loop 00589 below contains some checks to avoid scanning unreasonably far. */ 00590 if (lim_pc == 0) 00591 lim_pc = pc + 400; 00592 00593 /* If we have a frame, we don't want to scan past the frame's pc. This 00594 will catch those cases where the pc is in the prologue. */ 00595 if (this_frame) 00596 { 00597 CORE_ADDR frame_pc = get_frame_pc (this_frame); 00598 if (frame_pc < lim_pc) 00599 lim_pc = frame_pc; 00600 } 00601 00602 /* Scan the prologue. */ 00603 while (pc < lim_pc) 00604 { 00605 gdb_byte buf[frv_instr_size]; 00606 LONGEST op; 00607 00608 if (target_read_memory (pc, buf, sizeof buf) != 0) 00609 break; 00610 op = extract_signed_integer (buf, sizeof buf, byte_order); 00611 00612 next_pc = pc + 4; 00613 00614 /* The tests in this chain of ifs should be in order of 00615 decreasing selectivity, so that more particular patterns get 00616 to fire before less particular patterns. */ 00617 00618 /* Some sort of control transfer instruction: stop scanning prologue. 00619 Integer Conditional Branch: 00620 X XXXX XX 0000110 XX XXXXXXXXXXXXXXXX 00621 Floating-point / media Conditional Branch: 00622 X XXXX XX 0000111 XX XXXXXXXXXXXXXXXX 00623 LCR Conditional Branch to LR 00624 X XXXX XX 0001110 XX XX 001 X XXXXXXXXXX 00625 Integer conditional Branches to LR 00626 X XXXX XX 0001110 XX XX 010 X XXXXXXXXXX 00627 X XXXX XX 0001110 XX XX 011 X XXXXXXXXXX 00628 Floating-point/Media Branches to LR 00629 X XXXX XX 0001110 XX XX 110 X XXXXXXXXXX 00630 X XXXX XX 0001110 XX XX 111 X XXXXXXXXXX 00631 Jump and Link 00632 X XXXXX X 0001100 XXXXXX XXXXXX XXXXXX 00633 X XXXXX X 0001101 XXXXXX XXXXXX XXXXXX 00634 Call 00635 X XXXXXX 0001111 XXXXXXXXXXXXXXXXXX 00636 Return from Trap 00637 X XXXXX X 0000101 XXXXXX XXXXXX XXXXXX 00638 Integer Conditional Trap 00639 X XXXX XX 0000100 XXXXXX XXXX 00 XXXXXX 00640 X XXXX XX 0011100 XXXXXX XXXXXXXXXXXX 00641 Floating-point /media Conditional Trap 00642 X XXXX XX 0000100 XXXXXX XXXX 01 XXXXXX 00643 X XXXX XX 0011101 XXXXXX XXXXXXXXXXXX 00644 Break 00645 X XXXX XX 0000100 XXXXXX XXXX 11 XXXXXX 00646 Media Trap 00647 X XXXX XX 0000100 XXXXXX XXXX 10 XXXXXX */ 00648 if ((op & 0x01d80000) == 0x00180000 /* Conditional branches and Call */ 00649 || (op & 0x01f80000) == 0x00300000 /* Jump and Link */ 00650 || (op & 0x01f80000) == 0x00100000 /* Return from Trap, Trap */ 00651 || (op & 0x01f80000) == 0x00700000) /* Trap immediate */ 00652 { 00653 /* Stop scanning; not in prologue any longer. */ 00654 break; 00655 } 00656 00657 /* Loading something from memory into fp probably means that 00658 we're in the epilogue. Stop scanning the prologue. 00659 ld @(GRi, GRk), fp 00660 X 000010 0000010 XXXXXX 000100 XXXXXX 00661 ldi @(GRi, d12), fp 00662 X 000010 0110010 XXXXXX XXXXXXXXXXXX */ 00663 else if ((op & 0x7ffc0fc0) == 0x04080100 00664 || (op & 0x7ffc0000) == 0x04c80000) 00665 { 00666 break; 00667 } 00668 00669 /* Setting the FP from the SP: 00670 ori sp, 0, fp 00671 P 000010 0100010 000001 000000000000 = 0x04881000 00672 0 111111 1111111 111111 111111111111 = 0x7fffffff 00673 . . . . . . . . 00674 We treat this as part of the prologue. */ 00675 else if ((op & 0x7fffffff) == 0x04881000) 00676 { 00677 fp_set = 1; 00678 fp_offset = 0; 00679 last_prologue_pc = next_pc; 00680 } 00681 00682 /* Move the link register to the scratch register grJ, before saving: 00683 movsg lr, grJ 00684 P 000100 0000011 010000 000111 JJJJJJ = 0x080d01c0 00685 0 111111 1111111 111111 111111 000000 = 0x7fffffc0 00686 . . . . . . . . 00687 We treat this as part of the prologue. */ 00688 else if ((op & 0x7fffffc0) == 0x080d01c0) 00689 { 00690 int gr_j = op & 0x3f; 00691 00692 /* If we're moving it to a scratch register, that's fine. */ 00693 if (is_caller_saves_reg (gr_j)) 00694 { 00695 lr_save_reg = gr_j; 00696 last_prologue_pc = next_pc; 00697 } 00698 } 00699 00700 /* To save multiple callee-saves registers on the stack, at 00701 offset zero: 00702 00703 std grK,@(sp,gr0) 00704 P KKKKKK 0000011 000001 000011 000000 = 0x000c10c0 00705 0 000000 1111111 111111 111111 111111 = 0x01ffffff 00706 00707 stq grK,@(sp,gr0) 00708 P KKKKKK 0000011 000001 000100 000000 = 0x000c1100 00709 0 000000 1111111 111111 111111 111111 = 0x01ffffff 00710 . . . . . . . . 00711 We treat this as part of the prologue, and record the register's 00712 saved address in the frame structure. */ 00713 else if ((op & 0x01ffffff) == 0x000c10c0 00714 || (op & 0x01ffffff) == 0x000c1100) 00715 { 00716 int gr_k = ((op >> 25) & 0x3f); 00717 int ope = ((op >> 6) & 0x3f); 00718 int count; 00719 int i; 00720 00721 /* Is it an std or an stq? */ 00722 if (ope == 0x03) 00723 count = 2; 00724 else 00725 count = 4; 00726 00727 /* Is it really a callee-saves register? */ 00728 if (is_callee_saves_reg (gr_k)) 00729 { 00730 for (i = 0; i < count; i++) 00731 { 00732 gr_saved[gr_k + i] = 1; 00733 gr_sp_offset[gr_k + i] = 4 * i; 00734 } 00735 last_prologue_pc = next_pc; 00736 } 00737 } 00738 00739 /* Adjusting the stack pointer. (The stack pointer is GR1.) 00740 addi sp, S, sp 00741 P 000001 0010000 000001 SSSSSSSSSSSS = 0x02401000 00742 0 111111 1111111 111111 000000000000 = 0x7ffff000 00743 . . . . . . . . 00744 We treat this as part of the prologue. */ 00745 else if ((op & 0x7ffff000) == 0x02401000) 00746 { 00747 if (framesize == 0) 00748 { 00749 /* Sign-extend the twelve-bit field. 00750 (Isn't there a better way to do this?) */ 00751 int s = (((op & 0xfff) - 0x800) & 0xfff) - 0x800; 00752 00753 framesize -= s; 00754 last_prologue_pc = pc; 00755 } 00756 else 00757 { 00758 /* If the prologue is being adjusted again, we've 00759 likely gone too far; i.e. we're probably in the 00760 epilogue. */ 00761 break; 00762 } 00763 } 00764 00765 /* Setting the FP to a constant distance from the SP: 00766 addi sp, S, fp 00767 P 000010 0010000 000001 SSSSSSSSSSSS = 0x04401000 00768 0 111111 1111111 111111 000000000000 = 0x7ffff000 00769 . . . . . . . . 00770 We treat this as part of the prologue. */ 00771 else if ((op & 0x7ffff000) == 0x04401000) 00772 { 00773 /* Sign-extend the twelve-bit field. 00774 (Isn't there a better way to do this?) */ 00775 int s = (((op & 0xfff) - 0x800) & 0xfff) - 0x800; 00776 fp_set = 1; 00777 fp_offset = s; 00778 last_prologue_pc = pc; 00779 } 00780 00781 /* To spill an argument register to a scratch register: 00782 ori GRi, 0, GRk 00783 P KKKKKK 0100010 IIIIII 000000000000 = 0x00880000 00784 0 000000 1111111 000000 111111111111 = 0x01fc0fff 00785 . . . . . . . . 00786 For the time being, we treat this as a prologue instruction, 00787 assuming that GRi is an argument register. This one's kind 00788 of suspicious, because it seems like it could be part of a 00789 legitimate body instruction. But we only come here when the 00790 source info wasn't helpful, so we have to do the best we can. 00791 Hopefully once GCC and GDB agree on how to emit line number 00792 info for prologues, then this code will never come into play. */ 00793 else if ((op & 0x01fc0fff) == 0x00880000) 00794 { 00795 int gr_i = ((op >> 12) & 0x3f); 00796 00797 /* Make sure that the source is an arg register; if it is, we'll 00798 treat it as a prologue instruction. */ 00799 if (is_argument_reg (gr_i)) 00800 last_prologue_pc = next_pc; 00801 } 00802 00803 /* To spill 16-bit values to the stack: 00804 sthi GRk, @(fp, s) 00805 P KKKKKK 1010001 000010 SSSSSSSSSSSS = 0x01442000 00806 0 000000 1111111 111111 000000000000 = 0x01fff000 00807 . . . . . . . . 00808 And for 8-bit values, we use STB instructions. 00809 stbi GRk, @(fp, s) 00810 P KKKKKK 1010000 000010 SSSSSSSSSSSS = 0x01402000 00811 0 000000 1111111 111111 000000000000 = 0x01fff000 00812 . . . . . . . . 00813 We check that GRk is really an argument register, and treat 00814 all such as part of the prologue. */ 00815 else if ( (op & 0x01fff000) == 0x01442000 00816 || (op & 0x01fff000) == 0x01402000) 00817 { 00818 int gr_k = ((op >> 25) & 0x3f); 00819 00820 /* Make sure that GRk is really an argument register; treat 00821 it as a prologue instruction if so. */ 00822 if (is_argument_reg (gr_k)) 00823 last_prologue_pc = next_pc; 00824 } 00825 00826 /* To save multiple callee-saves register on the stack, at a 00827 non-zero offset: 00828 00829 stdi GRk, @(sp, s) 00830 P KKKKKK 1010011 000001 SSSSSSSSSSSS = 0x014c1000 00831 0 000000 1111111 111111 000000000000 = 0x01fff000 00832 . . . . . . . . 00833 stqi GRk, @(sp, s) 00834 P KKKKKK 1010100 000001 SSSSSSSSSSSS = 0x01501000 00835 0 000000 1111111 111111 000000000000 = 0x01fff000 00836 . . . . . . . . 00837 We treat this as part of the prologue, and record the register's 00838 saved address in the frame structure. */ 00839 else if ((op & 0x01fff000) == 0x014c1000 00840 || (op & 0x01fff000) == 0x01501000) 00841 { 00842 int gr_k = ((op >> 25) & 0x3f); 00843 int count; 00844 int i; 00845 00846 /* Is it a stdi or a stqi? */ 00847 if ((op & 0x01fff000) == 0x014c1000) 00848 count = 2; 00849 else 00850 count = 4; 00851 00852 /* Is it really a callee-saves register? */ 00853 if (is_callee_saves_reg (gr_k)) 00854 { 00855 /* Sign-extend the twelve-bit field. 00856 (Isn't there a better way to do this?) */ 00857 int s = (((op & 0xfff) - 0x800) & 0xfff) - 0x800; 00858 00859 for (i = 0; i < count; i++) 00860 { 00861 gr_saved[gr_k + i] = 1; 00862 gr_sp_offset[gr_k + i] = s + (4 * i); 00863 } 00864 last_prologue_pc = next_pc; 00865 } 00866 } 00867 00868 /* Storing any kind of integer register at any constant offset 00869 from any other register. 00870 00871 st GRk, @(GRi, gr0) 00872 P KKKKKK 0000011 IIIIII 000010 000000 = 0x000c0080 00873 0 000000 1111111 000000 111111 111111 = 0x01fc0fff 00874 . . . . . . . . 00875 sti GRk, @(GRi, d12) 00876 P KKKKKK 1010010 IIIIII SSSSSSSSSSSS = 0x01480000 00877 0 000000 1111111 000000 000000000000 = 0x01fc0000 00878 . . . . . . . . 00879 These could be almost anything, but a lot of prologue 00880 instructions fall into this pattern, so let's decode the 00881 instruction once, and then work at a higher level. */ 00882 else if (((op & 0x01fc0fff) == 0x000c0080) 00883 || ((op & 0x01fc0000) == 0x01480000)) 00884 { 00885 int gr_k = ((op >> 25) & 0x3f); 00886 int gr_i = ((op >> 12) & 0x3f); 00887 int offset; 00888 00889 /* Are we storing with gr0 as an offset, or using an 00890 immediate value? */ 00891 if ((op & 0x01fc0fff) == 0x000c0080) 00892 offset = 0; 00893 else 00894 offset = (((op & 0xfff) - 0x800) & 0xfff) - 0x800; 00895 00896 /* If the address isn't relative to the SP or FP, it's not a 00897 prologue instruction. */ 00898 if (gr_i != sp_regnum && gr_i != fp_regnum) 00899 { 00900 /* Do nothing; not a prologue instruction. */ 00901 } 00902 00903 /* Saving the old FP in the new frame (relative to the SP). */ 00904 else if (gr_k == fp_regnum && gr_i == sp_regnum) 00905 { 00906 gr_saved[fp_regnum] = 1; 00907 gr_sp_offset[fp_regnum] = offset; 00908 last_prologue_pc = next_pc; 00909 } 00910 00911 /* Saving callee-saves register(s) on the stack, relative to 00912 the SP. */ 00913 else if (gr_i == sp_regnum 00914 && is_callee_saves_reg (gr_k)) 00915 { 00916 gr_saved[gr_k] = 1; 00917 if (gr_i == sp_regnum) 00918 gr_sp_offset[gr_k] = offset; 00919 else 00920 gr_sp_offset[gr_k] = offset + fp_offset; 00921 last_prologue_pc = next_pc; 00922 } 00923 00924 /* Saving the scratch register holding the return address. */ 00925 else if (lr_save_reg != -1 00926 && gr_k == lr_save_reg) 00927 { 00928 lr_saved_on_stack = 1; 00929 if (gr_i == sp_regnum) 00930 lr_sp_offset = offset; 00931 else 00932 lr_sp_offset = offset + fp_offset; 00933 last_prologue_pc = next_pc; 00934 } 00935 00936 /* Spilling int-sized arguments to the stack. */ 00937 else if (is_argument_reg (gr_k)) 00938 last_prologue_pc = next_pc; 00939 } 00940 pc = next_pc; 00941 } 00942 00943 if (this_frame && info) 00944 { 00945 int i; 00946 ULONGEST this_base; 00947 00948 /* If we know the relationship between the stack and frame 00949 pointers, record the addresses of the registers we noticed. 00950 Note that we have to do this as a separate step at the end, 00951 because instructions may save relative to the SP, but we need 00952 their addresses relative to the FP. */ 00953 if (fp_set) 00954 this_base = get_frame_register_unsigned (this_frame, fp_regnum); 00955 else 00956 this_base = get_frame_register_unsigned (this_frame, sp_regnum); 00957 00958 for (i = 0; i < 64; i++) 00959 if (gr_saved[i]) 00960 info->saved_regs[i].addr = this_base - fp_offset + gr_sp_offset[i]; 00961 00962 info->prev_sp = this_base - fp_offset + framesize; 00963 info->base = this_base; 00964 00965 /* If LR was saved on the stack, record its location. */ 00966 if (lr_saved_on_stack) 00967 info->saved_regs[lr_regnum].addr 00968 = this_base - fp_offset + lr_sp_offset; 00969 00970 /* The call instruction moves the caller's PC in the callee's LR. 00971 Since this is an unwind, do the reverse. Copy the location of LR 00972 into PC (the address / regnum) so that a request for PC will be 00973 converted into a request for the LR. */ 00974 info->saved_regs[pc_regnum] = info->saved_regs[lr_regnum]; 00975 00976 /* Save the previous frame's computed SP value. */ 00977 trad_frame_set_value (info->saved_regs, sp_regnum, info->prev_sp); 00978 } 00979 00980 return last_prologue_pc; 00981 } 00982 00983 00984 static CORE_ADDR 00985 frv_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc) 00986 { 00987 CORE_ADDR func_addr, func_end, new_pc; 00988 00989 new_pc = pc; 00990 00991 /* If the line table has entry for a line *within* the function 00992 (i.e., not in the prologue, and not past the end), then that's 00993 our location. */ 00994 if (find_pc_partial_function (pc, NULL, &func_addr, &func_end)) 00995 { 00996 struct symtab_and_line sal; 00997 00998 sal = find_pc_line (func_addr, 0); 00999 01000 if (sal.line != 0 && sal.end < func_end) 01001 { 01002 new_pc = sal.end; 01003 } 01004 } 01005 01006 /* The FR-V prologue is at least five instructions long (twenty bytes). 01007 If we didn't find a real source location past that, then 01008 do a full analysis of the prologue. */ 01009 if (new_pc < pc + 20) 01010 new_pc = frv_analyze_prologue (gdbarch, pc, 0, 0); 01011 01012 return new_pc; 01013 } 01014 01015 01016 /* Examine the instruction pointed to by PC. If it corresponds to 01017 a call to __main, return the address of the next instruction. 01018 Otherwise, return PC. */ 01019 01020 static CORE_ADDR 01021 frv_skip_main_prologue (struct gdbarch *gdbarch, CORE_ADDR pc) 01022 { 01023 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 01024 gdb_byte buf[4]; 01025 unsigned long op; 01026 CORE_ADDR orig_pc = pc; 01027 01028 if (target_read_memory (pc, buf, 4)) 01029 return pc; 01030 op = extract_unsigned_integer (buf, 4, byte_order); 01031 01032 /* In PIC code, GR15 may be loaded from some offset off of FP prior 01033 to the call instruction. 01034 01035 Skip over this instruction if present. It won't be present in 01036 non-PIC code, and even in PIC code, it might not be present. 01037 (This is due to the fact that GR15, the FDPIC register, already 01038 contains the correct value.) 01039 01040 The general form of the LDI is given first, followed by the 01041 specific instruction with the GRi and GRk filled in as FP and 01042 GR15. 01043 01044 ldi @(GRi, d12), GRk 01045 P KKKKKK 0110010 IIIIII SSSSSSSSSSSS = 0x00c80000 01046 0 000000 1111111 000000 000000000000 = 0x01fc0000 01047 . . . . . . . . 01048 ldi @(FP, d12), GR15 01049 P KKKKKK 0110010 IIIIII SSSSSSSSSSSS = 0x1ec82000 01050 0 001111 1111111 000010 000000000000 = 0x7ffff000 01051 . . . . . . . . */ 01052 01053 if ((op & 0x7ffff000) == 0x1ec82000) 01054 { 01055 pc += 4; 01056 if (target_read_memory (pc, buf, 4)) 01057 return orig_pc; 01058 op = extract_unsigned_integer (buf, 4, byte_order); 01059 } 01060 01061 /* The format of an FRV CALL instruction is as follows: 01062 01063 call label24 01064 P HHHHHH 0001111 LLLLLLLLLLLLLLLLLL = 0x003c0000 01065 0 000000 1111111 000000000000000000 = 0x01fc0000 01066 . . . . . . . . 01067 01068 where label24 is constructed by concatenating the H bits with the 01069 L bits. The call target is PC + (4 * sign_ext(label24)). */ 01070 01071 if ((op & 0x01fc0000) == 0x003c0000) 01072 { 01073 LONGEST displ; 01074 CORE_ADDR call_dest; 01075 struct bound_minimal_symbol s; 01076 01077 displ = ((op & 0xfe000000) >> 7) | (op & 0x0003ffff); 01078 if ((displ & 0x00800000) != 0) 01079 displ |= ~((LONGEST) 0x00ffffff); 01080 01081 call_dest = pc + 4 * displ; 01082 s = lookup_minimal_symbol_by_pc (call_dest); 01083 01084 if (s.minsym != NULL 01085 && SYMBOL_LINKAGE_NAME (s.minsym) != NULL 01086 && strcmp (SYMBOL_LINKAGE_NAME (s.minsym), "__main") == 0) 01087 { 01088 pc += 4; 01089 return pc; 01090 } 01091 } 01092 return orig_pc; 01093 } 01094 01095 01096 static struct frv_unwind_cache * 01097 frv_frame_unwind_cache (struct frame_info *this_frame, 01098 void **this_prologue_cache) 01099 { 01100 struct gdbarch *gdbarch = get_frame_arch (this_frame); 01101 struct frv_unwind_cache *info; 01102 01103 if ((*this_prologue_cache)) 01104 return (*this_prologue_cache); 01105 01106 info = FRAME_OBSTACK_ZALLOC (struct frv_unwind_cache); 01107 (*this_prologue_cache) = info; 01108 info->saved_regs = trad_frame_alloc_saved_regs (this_frame); 01109 01110 /* Prologue analysis does the rest... */ 01111 frv_analyze_prologue (gdbarch, 01112 get_frame_func (this_frame), this_frame, info); 01113 01114 return info; 01115 } 01116 01117 static void 01118 frv_extract_return_value (struct type *type, struct regcache *regcache, 01119 gdb_byte *valbuf) 01120 { 01121 struct gdbarch *gdbarch = get_regcache_arch (regcache); 01122 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 01123 int len = TYPE_LENGTH (type); 01124 01125 if (len <= 4) 01126 { 01127 ULONGEST gpr8_val; 01128 regcache_cooked_read_unsigned (regcache, 8, &gpr8_val); 01129 store_unsigned_integer (valbuf, len, byte_order, gpr8_val); 01130 } 01131 else if (len == 8) 01132 { 01133 ULONGEST regval; 01134 01135 regcache_cooked_read_unsigned (regcache, 8, ®val); 01136 store_unsigned_integer (valbuf, 4, byte_order, regval); 01137 regcache_cooked_read_unsigned (regcache, 9, ®val); 01138 store_unsigned_integer ((bfd_byte *) valbuf + 4, 4, byte_order, regval); 01139 } 01140 else 01141 internal_error (__FILE__, __LINE__, 01142 _("Illegal return value length: %d"), len); 01143 } 01144 01145 static CORE_ADDR 01146 frv_frame_align (struct gdbarch *gdbarch, CORE_ADDR sp) 01147 { 01148 /* Require dword alignment. */ 01149 return align_down (sp, 8); 01150 } 01151 01152 static CORE_ADDR 01153 find_func_descr (struct gdbarch *gdbarch, CORE_ADDR entry_point) 01154 { 01155 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 01156 CORE_ADDR descr; 01157 gdb_byte valbuf[4]; 01158 CORE_ADDR start_addr; 01159 01160 /* If we can't find the function in the symbol table, then we assume 01161 that the function address is already in descriptor form. */ 01162 if (!find_pc_partial_function (entry_point, NULL, &start_addr, NULL) 01163 || entry_point != start_addr) 01164 return entry_point; 01165 01166 descr = frv_fdpic_find_canonical_descriptor (entry_point); 01167 01168 if (descr != 0) 01169 return descr; 01170 01171 /* Construct a non-canonical descriptor from space allocated on 01172 the stack. */ 01173 01174 descr = value_as_long (value_allocate_space_in_inferior (8)); 01175 store_unsigned_integer (valbuf, 4, byte_order, entry_point); 01176 write_memory (descr, valbuf, 4); 01177 store_unsigned_integer (valbuf, 4, byte_order, 01178 frv_fdpic_find_global_pointer (entry_point)); 01179 write_memory (descr + 4, valbuf, 4); 01180 return descr; 01181 } 01182 01183 static CORE_ADDR 01184 frv_convert_from_func_ptr_addr (struct gdbarch *gdbarch, CORE_ADDR addr, 01185 struct target_ops *targ) 01186 { 01187 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 01188 CORE_ADDR entry_point; 01189 CORE_ADDR got_address; 01190 01191 entry_point = get_target_memory_unsigned (targ, addr, 4, byte_order); 01192 got_address = get_target_memory_unsigned (targ, addr + 4, 4, byte_order); 01193 01194 if (got_address == frv_fdpic_find_global_pointer (entry_point)) 01195 return entry_point; 01196 else 01197 return addr; 01198 } 01199 01200 static CORE_ADDR 01201 frv_push_dummy_call (struct gdbarch *gdbarch, struct value *function, 01202 struct regcache *regcache, CORE_ADDR bp_addr, 01203 int nargs, struct value **args, CORE_ADDR sp, 01204 int struct_return, CORE_ADDR struct_addr) 01205 { 01206 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 01207 int argreg; 01208 int argnum; 01209 const gdb_byte *val; 01210 gdb_byte valbuf[4]; 01211 struct value *arg; 01212 struct type *arg_type; 01213 int len; 01214 enum type_code typecode; 01215 CORE_ADDR regval; 01216 int stack_space; 01217 int stack_offset; 01218 enum frv_abi abi = frv_abi (gdbarch); 01219 CORE_ADDR func_addr = find_function_addr (function, NULL); 01220 01221 #if 0 01222 printf("Push %d args at sp = %x, struct_return=%d (%x)\n", 01223 nargs, (int) sp, struct_return, struct_addr); 01224 #endif 01225 01226 stack_space = 0; 01227 for (argnum = 0; argnum < nargs; ++argnum) 01228 stack_space += align_up (TYPE_LENGTH (value_type (args[argnum])), 4); 01229 01230 stack_space -= (6 * 4); 01231 if (stack_space > 0) 01232 sp -= stack_space; 01233 01234 /* Make sure stack is dword aligned. */ 01235 sp = align_down (sp, 8); 01236 01237 stack_offset = 0; 01238 01239 argreg = 8; 01240 01241 if (struct_return) 01242 regcache_cooked_write_unsigned (regcache, struct_return_regnum, 01243 struct_addr); 01244 01245 for (argnum = 0; argnum < nargs; ++argnum) 01246 { 01247 arg = args[argnum]; 01248 arg_type = check_typedef (value_type (arg)); 01249 len = TYPE_LENGTH (arg_type); 01250 typecode = TYPE_CODE (arg_type); 01251 01252 if (typecode == TYPE_CODE_STRUCT || typecode == TYPE_CODE_UNION) 01253 { 01254 store_unsigned_integer (valbuf, 4, byte_order, 01255 value_address (arg)); 01256 typecode = TYPE_CODE_PTR; 01257 len = 4; 01258 val = valbuf; 01259 } 01260 else if (abi == FRV_ABI_FDPIC 01261 && len == 4 01262 && typecode == TYPE_CODE_PTR 01263 && TYPE_CODE (TYPE_TARGET_TYPE (arg_type)) == TYPE_CODE_FUNC) 01264 { 01265 /* The FDPIC ABI requires function descriptors to be passed instead 01266 of entry points. */ 01267 CORE_ADDR addr = extract_unsigned_integer 01268 (value_contents (arg), 4, byte_order); 01269 addr = find_func_descr (gdbarch, addr); 01270 store_unsigned_integer (valbuf, 4, byte_order, addr); 01271 typecode = TYPE_CODE_PTR; 01272 len = 4; 01273 val = valbuf; 01274 } 01275 else 01276 { 01277 val = value_contents (arg); 01278 } 01279 01280 while (len > 0) 01281 { 01282 int partial_len = (len < 4 ? len : 4); 01283 01284 if (argreg < 14) 01285 { 01286 regval = extract_unsigned_integer (val, partial_len, byte_order); 01287 #if 0 01288 printf(" Argnum %d data %x -> reg %d\n", 01289 argnum, (int) regval, argreg); 01290 #endif 01291 regcache_cooked_write_unsigned (regcache, argreg, regval); 01292 ++argreg; 01293 } 01294 else 01295 { 01296 #if 0 01297 printf(" Argnum %d data %x -> offset %d (%x)\n", 01298 argnum, *((int *)val), stack_offset, 01299 (int) (sp + stack_offset)); 01300 #endif 01301 write_memory (sp + stack_offset, val, partial_len); 01302 stack_offset += align_up (partial_len, 4); 01303 } 01304 len -= partial_len; 01305 val += partial_len; 01306 } 01307 } 01308 01309 /* Set the return address. For the frv, the return breakpoint is 01310 always at BP_ADDR. */ 01311 regcache_cooked_write_unsigned (regcache, lr_regnum, bp_addr); 01312 01313 if (abi == FRV_ABI_FDPIC) 01314 { 01315 /* Set the GOT register for the FDPIC ABI. */ 01316 regcache_cooked_write_unsigned 01317 (regcache, first_gpr_regnum + 15, 01318 frv_fdpic_find_global_pointer (func_addr)); 01319 } 01320 01321 /* Finally, update the SP register. */ 01322 regcache_cooked_write_unsigned (regcache, sp_regnum, sp); 01323 01324 return sp; 01325 } 01326 01327 static void 01328 frv_store_return_value (struct type *type, struct regcache *regcache, 01329 const gdb_byte *valbuf) 01330 { 01331 int len = TYPE_LENGTH (type); 01332 01333 if (len <= 4) 01334 { 01335 bfd_byte val[4]; 01336 memset (val, 0, sizeof (val)); 01337 memcpy (val + (4 - len), valbuf, len); 01338 regcache_cooked_write (regcache, 8, val); 01339 } 01340 else if (len == 8) 01341 { 01342 regcache_cooked_write (regcache, 8, valbuf); 01343 regcache_cooked_write (regcache, 9, (bfd_byte *) valbuf + 4); 01344 } 01345 else 01346 internal_error (__FILE__, __LINE__, 01347 _("Don't know how to return a %d-byte value."), len); 01348 } 01349 01350 static enum return_value_convention 01351 frv_return_value (struct gdbarch *gdbarch, struct value *function, 01352 struct type *valtype, struct regcache *regcache, 01353 gdb_byte *readbuf, const gdb_byte *writebuf) 01354 { 01355 int struct_return = TYPE_CODE (valtype) == TYPE_CODE_STRUCT 01356 || TYPE_CODE (valtype) == TYPE_CODE_UNION 01357 || TYPE_CODE (valtype) == TYPE_CODE_ARRAY; 01358 01359 if (writebuf != NULL) 01360 { 01361 gdb_assert (!struct_return); 01362 frv_store_return_value (valtype, regcache, writebuf); 01363 } 01364 01365 if (readbuf != NULL) 01366 { 01367 gdb_assert (!struct_return); 01368 frv_extract_return_value (valtype, regcache, readbuf); 01369 } 01370 01371 if (struct_return) 01372 return RETURN_VALUE_STRUCT_CONVENTION; 01373 else 01374 return RETURN_VALUE_REGISTER_CONVENTION; 01375 } 01376 01377 static CORE_ADDR 01378 frv_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame) 01379 { 01380 return frame_unwind_register_unsigned (next_frame, pc_regnum); 01381 } 01382 01383 /* Given a GDB frame, determine the address of the calling function's 01384 frame. This will be used to create a new GDB frame struct. */ 01385 01386 static void 01387 frv_frame_this_id (struct frame_info *this_frame, 01388 void **this_prologue_cache, struct frame_id *this_id) 01389 { 01390 struct frv_unwind_cache *info 01391 = frv_frame_unwind_cache (this_frame, this_prologue_cache); 01392 CORE_ADDR base; 01393 CORE_ADDR func; 01394 struct minimal_symbol *msym_stack; 01395 struct frame_id id; 01396 01397 /* The FUNC is easy. */ 01398 func = get_frame_func (this_frame); 01399 01400 /* Check if the stack is empty. */ 01401 msym_stack = lookup_minimal_symbol ("_stack", NULL, NULL); 01402 if (msym_stack && info->base == SYMBOL_VALUE_ADDRESS (msym_stack)) 01403 return; 01404 01405 /* Hopefully the prologue analysis either correctly determined the 01406 frame's base (which is the SP from the previous frame), or set 01407 that base to "NULL". */ 01408 base = info->prev_sp; 01409 if (base == 0) 01410 return; 01411 01412 id = frame_id_build (base, func); 01413 (*this_id) = id; 01414 } 01415 01416 static struct value * 01417 frv_frame_prev_register (struct frame_info *this_frame, 01418 void **this_prologue_cache, int regnum) 01419 { 01420 struct frv_unwind_cache *info 01421 = frv_frame_unwind_cache (this_frame, this_prologue_cache); 01422 return trad_frame_get_prev_register (this_frame, info->saved_regs, regnum); 01423 } 01424 01425 static const struct frame_unwind frv_frame_unwind = { 01426 NORMAL_FRAME, 01427 default_frame_unwind_stop_reason, 01428 frv_frame_this_id, 01429 frv_frame_prev_register, 01430 NULL, 01431 default_frame_sniffer 01432 }; 01433 01434 static CORE_ADDR 01435 frv_frame_base_address (struct frame_info *this_frame, void **this_cache) 01436 { 01437 struct frv_unwind_cache *info 01438 = frv_frame_unwind_cache (this_frame, this_cache); 01439 return info->base; 01440 } 01441 01442 static const struct frame_base frv_frame_base = { 01443 &frv_frame_unwind, 01444 frv_frame_base_address, 01445 frv_frame_base_address, 01446 frv_frame_base_address 01447 }; 01448 01449 static CORE_ADDR 01450 frv_unwind_sp (struct gdbarch *gdbarch, struct frame_info *next_frame) 01451 { 01452 return frame_unwind_register_unsigned (next_frame, sp_regnum); 01453 } 01454 01455 01456 /* Assuming THIS_FRAME is a dummy, return the frame ID of that dummy 01457 frame. The frame ID's base needs to match the TOS value saved by 01458 save_dummy_frame_tos(), and the PC match the dummy frame's breakpoint. */ 01459 01460 static struct frame_id 01461 frv_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame) 01462 { 01463 CORE_ADDR sp = get_frame_register_unsigned (this_frame, sp_regnum); 01464 return frame_id_build (sp, get_frame_pc (this_frame)); 01465 } 01466 01467 static struct gdbarch * 01468 frv_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) 01469 { 01470 struct gdbarch *gdbarch; 01471 struct gdbarch_tdep *var; 01472 int elf_flags = 0; 01473 01474 /* Check to see if we've already built an appropriate architecture 01475 object for this executable. */ 01476 arches = gdbarch_list_lookup_by_info (arches, &info); 01477 if (arches) 01478 return arches->gdbarch; 01479 01480 /* Select the right tdep structure for this variant. */ 01481 var = new_variant (); 01482 switch (info.bfd_arch_info->mach) 01483 { 01484 case bfd_mach_frv: 01485 case bfd_mach_frvsimple: 01486 case bfd_mach_fr500: 01487 case bfd_mach_frvtomcat: 01488 case bfd_mach_fr550: 01489 set_variant_num_gprs (var, 64); 01490 set_variant_num_fprs (var, 64); 01491 break; 01492 01493 case bfd_mach_fr400: 01494 case bfd_mach_fr450: 01495 set_variant_num_gprs (var, 32); 01496 set_variant_num_fprs (var, 32); 01497 break; 01498 01499 default: 01500 /* Never heard of this variant. */ 01501 return 0; 01502 } 01503 01504 /* Extract the ELF flags, if available. */ 01505 if (info.abfd && bfd_get_flavour (info.abfd) == bfd_target_elf_flavour) 01506 elf_flags = elf_elfheader (info.abfd)->e_flags; 01507 01508 if (elf_flags & EF_FRV_FDPIC) 01509 set_variant_abi_fdpic (var); 01510 01511 if (elf_flags & EF_FRV_CPU_FR450) 01512 set_variant_scratch_registers (var); 01513 01514 gdbarch = gdbarch_alloc (&info, var); 01515 01516 set_gdbarch_short_bit (gdbarch, 16); 01517 set_gdbarch_int_bit (gdbarch, 32); 01518 set_gdbarch_long_bit (gdbarch, 32); 01519 set_gdbarch_long_long_bit (gdbarch, 64); 01520 set_gdbarch_float_bit (gdbarch, 32); 01521 set_gdbarch_double_bit (gdbarch, 64); 01522 set_gdbarch_long_double_bit (gdbarch, 64); 01523 set_gdbarch_ptr_bit (gdbarch, 32); 01524 01525 set_gdbarch_num_regs (gdbarch, frv_num_regs); 01526 set_gdbarch_num_pseudo_regs (gdbarch, frv_num_pseudo_regs); 01527 01528 set_gdbarch_sp_regnum (gdbarch, sp_regnum); 01529 set_gdbarch_deprecated_fp_regnum (gdbarch, fp_regnum); 01530 set_gdbarch_pc_regnum (gdbarch, pc_regnum); 01531 01532 set_gdbarch_register_name (gdbarch, frv_register_name); 01533 set_gdbarch_register_type (gdbarch, frv_register_type); 01534 set_gdbarch_register_sim_regno (gdbarch, frv_register_sim_regno); 01535 01536 set_gdbarch_pseudo_register_read (gdbarch, frv_pseudo_register_read); 01537 set_gdbarch_pseudo_register_write (gdbarch, frv_pseudo_register_write); 01538 01539 set_gdbarch_skip_prologue (gdbarch, frv_skip_prologue); 01540 set_gdbarch_skip_main_prologue (gdbarch, frv_skip_main_prologue); 01541 set_gdbarch_breakpoint_from_pc (gdbarch, frv_breakpoint_from_pc); 01542 set_gdbarch_adjust_breakpoint_address 01543 (gdbarch, frv_adjust_breakpoint_address); 01544 01545 set_gdbarch_return_value (gdbarch, frv_return_value); 01546 01547 /* Frame stuff. */ 01548 set_gdbarch_unwind_pc (gdbarch, frv_unwind_pc); 01549 set_gdbarch_unwind_sp (gdbarch, frv_unwind_sp); 01550 set_gdbarch_frame_align (gdbarch, frv_frame_align); 01551 frame_base_set_default (gdbarch, &frv_frame_base); 01552 /* We set the sniffer lower down after the OSABI hooks have been 01553 established. */ 01554 01555 /* Settings for calling functions in the inferior. */ 01556 set_gdbarch_push_dummy_call (gdbarch, frv_push_dummy_call); 01557 set_gdbarch_dummy_id (gdbarch, frv_dummy_id); 01558 01559 /* Settings that should be unnecessary. */ 01560 set_gdbarch_inner_than (gdbarch, core_addr_lessthan); 01561 01562 /* Hardware watchpoint / breakpoint support. */ 01563 switch (info.bfd_arch_info->mach) 01564 { 01565 case bfd_mach_frv: 01566 case bfd_mach_frvsimple: 01567 case bfd_mach_fr500: 01568 case bfd_mach_frvtomcat: 01569 /* fr500-style hardware debugging support. */ 01570 var->num_hw_watchpoints = 4; 01571 var->num_hw_breakpoints = 4; 01572 break; 01573 01574 case bfd_mach_fr400: 01575 case bfd_mach_fr450: 01576 /* fr400-style hardware debugging support. */ 01577 var->num_hw_watchpoints = 2; 01578 var->num_hw_breakpoints = 4; 01579 break; 01580 01581 default: 01582 /* Otherwise, assume we don't have hardware debugging support. */ 01583 var->num_hw_watchpoints = 0; 01584 var->num_hw_breakpoints = 0; 01585 break; 01586 } 01587 01588 set_gdbarch_print_insn (gdbarch, print_insn_frv); 01589 if (frv_abi (gdbarch) == FRV_ABI_FDPIC) 01590 set_gdbarch_convert_from_func_ptr_addr (gdbarch, 01591 frv_convert_from_func_ptr_addr); 01592 01593 set_solib_ops (gdbarch, &frv_so_ops); 01594 01595 /* Hook in ABI-specific overrides, if they have been registered. */ 01596 gdbarch_init_osabi (info, gdbarch); 01597 01598 /* Set the fallback (prologue based) frame sniffer. */ 01599 frame_unwind_append_unwinder (gdbarch, &frv_frame_unwind); 01600 01601 /* Enable TLS support. */ 01602 set_gdbarch_fetch_tls_load_module_address (gdbarch, 01603 frv_fetch_objfile_link_map); 01604 01605 return gdbarch; 01606 } 01607 01608 void 01609 _initialize_frv_tdep (void) 01610 { 01611 register_gdbarch_init (bfd_arch_frv, frv_gdbarch_init); 01612 }