GDB (API)
|
00001 /* Target-dependent code for SPARC. 00002 00003 Copyright (C) 2003-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 "dwarf2-frame.h" 00024 #include "floatformat.h" 00025 #include "frame.h" 00026 #include "frame-base.h" 00027 #include "frame-unwind.h" 00028 #include "gdbcore.h" 00029 #include "gdbtypes.h" 00030 #include "inferior.h" 00031 #include "symtab.h" 00032 #include "objfiles.h" 00033 #include "osabi.h" 00034 #include "regcache.h" 00035 #include "target.h" 00036 #include "value.h" 00037 00038 #include "gdb_assert.h" 00039 #include "gdb_string.h" 00040 00041 #include "sparc-tdep.h" 00042 #include "sparc-ravenscar-thread.h" 00043 00044 struct regset; 00045 00046 /* This file implements the SPARC 32-bit ABI as defined by the section 00047 "Low-Level System Information" of the SPARC Compliance Definition 00048 (SCD) 2.4.1, which is the 32-bit System V psABI for SPARC. The SCD 00049 lists changes with respect to the original 32-bit psABI as defined 00050 in the "System V ABI, SPARC Processor Supplement". 00051 00052 Note that if we talk about SunOS, we mean SunOS 4.x, which was 00053 BSD-based, which is sometimes (retroactively?) referred to as 00054 Solaris 1.x. If we talk about Solaris we mean Solaris 2.x and 00055 above (Solaris 7, 8 and 9 are nothing but Solaris 2.7, 2.8 and 2.9 00056 suffering from severe version number inflation). Solaris 2.x is 00057 also known as SunOS 5.x, since that's what uname(1) says. Solaris 00058 2.x is SVR4-based. */ 00059 00060 /* Please use the sparc32_-prefix for 32-bit specific code, the 00061 sparc64_-prefix for 64-bit specific code and the sparc_-prefix for 00062 code that can handle both. The 64-bit specific code lives in 00063 sparc64-tdep.c; don't add any here. */ 00064 00065 /* The SPARC Floating-Point Quad-Precision format is similar to 00066 big-endian IA-64 Quad-Precision format. */ 00067 #define floatformats_sparc_quad floatformats_ia64_quad 00068 00069 /* The stack pointer is offset from the stack frame by a BIAS of 2047 00070 (0x7ff) for 64-bit code. BIAS is likely to be defined on SPARC 00071 hosts, so undefine it first. */ 00072 #undef BIAS 00073 #define BIAS 2047 00074 00075 /* Macros to extract fields from SPARC instructions. */ 00076 #define X_OP(i) (((i) >> 30) & 0x3) 00077 #define X_RD(i) (((i) >> 25) & 0x1f) 00078 #define X_A(i) (((i) >> 29) & 1) 00079 #define X_COND(i) (((i) >> 25) & 0xf) 00080 #define X_OP2(i) (((i) >> 22) & 0x7) 00081 #define X_IMM22(i) ((i) & 0x3fffff) 00082 #define X_OP3(i) (((i) >> 19) & 0x3f) 00083 #define X_RS1(i) (((i) >> 14) & 0x1f) 00084 #define X_RS2(i) ((i) & 0x1f) 00085 #define X_I(i) (((i) >> 13) & 1) 00086 /* Sign extension macros. */ 00087 #define X_DISP22(i) ((X_IMM22 (i) ^ 0x200000) - 0x200000) 00088 #define X_DISP19(i) ((((i) & 0x7ffff) ^ 0x40000) - 0x40000) 00089 #define X_DISP10(i) ((((((i) >> 11) && 0x300) | (((i) >> 5) & 0xff)) ^ 0x200) - 0x200) 00090 #define X_SIMM13(i) ((((i) & 0x1fff) ^ 0x1000) - 0x1000) 00091 00092 /* Fetch the instruction at PC. Instructions are always big-endian 00093 even if the processor operates in little-endian mode. */ 00094 00095 unsigned long 00096 sparc_fetch_instruction (CORE_ADDR pc) 00097 { 00098 gdb_byte buf[4]; 00099 unsigned long insn; 00100 int i; 00101 00102 /* If we can't read the instruction at PC, return zero. */ 00103 if (target_read_memory (pc, buf, sizeof (buf))) 00104 return 0; 00105 00106 insn = 0; 00107 for (i = 0; i < sizeof (buf); i++) 00108 insn = (insn << 8) | buf[i]; 00109 return insn; 00110 } 00111 00112 00113 /* Return non-zero if the instruction corresponding to PC is an "unimp" 00114 instruction. */ 00115 00116 static int 00117 sparc_is_unimp_insn (CORE_ADDR pc) 00118 { 00119 const unsigned long insn = sparc_fetch_instruction (pc); 00120 00121 return ((insn & 0xc1c00000) == 0); 00122 } 00123 00124 /* OpenBSD/sparc includes StackGhost, which according to the author's 00125 website http://stackghost.cerias.purdue.edu "... transparently and 00126 automatically protects applications' stack frames; more 00127 specifically, it guards the return pointers. The protection 00128 mechanisms require no application source or binary modification and 00129 imposes only a negligible performance penalty." 00130 00131 The same website provides the following description of how 00132 StackGhost works: 00133 00134 "StackGhost interfaces with the kernel trap handler that would 00135 normally write out registers to the stack and the handler that 00136 would read them back in. By XORing a cookie into the 00137 return-address saved in the user stack when it is actually written 00138 to the stack, and then XOR it out when the return-address is pulled 00139 from the stack, StackGhost can cause attacker corrupted return 00140 pointers to behave in a manner the attacker cannot predict. 00141 StackGhost can also use several unused bits in the return pointer 00142 to detect a smashed return pointer and abort the process." 00143 00144 For GDB this means that whenever we're reading %i7 from a stack 00145 frame's window save area, we'll have to XOR the cookie. 00146 00147 More information on StackGuard can be found on in: 00148 00149 Mike Frantzen and Mike Shuey. "StackGhost: Hardware Facilitated 00150 Stack Protection." 2001. Published in USENIX Security Symposium 00151 '01. */ 00152 00153 /* Fetch StackGhost Per-Process XOR cookie. */ 00154 00155 ULONGEST 00156 sparc_fetch_wcookie (struct gdbarch *gdbarch) 00157 { 00158 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 00159 struct target_ops *ops = ¤t_target; 00160 gdb_byte buf[8]; 00161 int len; 00162 00163 len = target_read (ops, TARGET_OBJECT_WCOOKIE, NULL, buf, 0, 8); 00164 if (len == -1) 00165 return 0; 00166 00167 /* We should have either an 32-bit or an 64-bit cookie. */ 00168 gdb_assert (len == 4 || len == 8); 00169 00170 return extract_unsigned_integer (buf, len, byte_order); 00171 } 00172 00173 00174 /* The functions on this page are intended to be used to classify 00175 function arguments. */ 00176 00177 /* Check whether TYPE is "Integral or Pointer". */ 00178 00179 static int 00180 sparc_integral_or_pointer_p (const struct type *type) 00181 { 00182 int len = TYPE_LENGTH (type); 00183 00184 switch (TYPE_CODE (type)) 00185 { 00186 case TYPE_CODE_INT: 00187 case TYPE_CODE_BOOL: 00188 case TYPE_CODE_CHAR: 00189 case TYPE_CODE_ENUM: 00190 case TYPE_CODE_RANGE: 00191 /* We have byte, half-word, word and extended-word/doubleword 00192 integral types. The doubleword is an extension to the 00193 original 32-bit ABI by the SCD 2.4.x. */ 00194 return (len == 1 || len == 2 || len == 4 || len == 8); 00195 case TYPE_CODE_PTR: 00196 case TYPE_CODE_REF: 00197 /* Allow either 32-bit or 64-bit pointers. */ 00198 return (len == 4 || len == 8); 00199 default: 00200 break; 00201 } 00202 00203 return 0; 00204 } 00205 00206 /* Check whether TYPE is "Floating". */ 00207 00208 static int 00209 sparc_floating_p (const struct type *type) 00210 { 00211 switch (TYPE_CODE (type)) 00212 { 00213 case TYPE_CODE_FLT: 00214 { 00215 int len = TYPE_LENGTH (type); 00216 return (len == 4 || len == 8 || len == 16); 00217 } 00218 default: 00219 break; 00220 } 00221 00222 return 0; 00223 } 00224 00225 /* Check whether TYPE is "Complex Floating". */ 00226 00227 static int 00228 sparc_complex_floating_p (const struct type *type) 00229 { 00230 switch (TYPE_CODE (type)) 00231 { 00232 case TYPE_CODE_COMPLEX: 00233 { 00234 int len = TYPE_LENGTH (type); 00235 return (len == 8 || len == 16 || len == 32); 00236 } 00237 default: 00238 break; 00239 } 00240 00241 return 0; 00242 } 00243 00244 /* Check whether TYPE is "Structure or Union". 00245 00246 In terms of Ada subprogram calls, arrays are treated the same as 00247 struct and union types. So this function also returns non-zero 00248 for array types. */ 00249 00250 static int 00251 sparc_structure_or_union_p (const struct type *type) 00252 { 00253 switch (TYPE_CODE (type)) 00254 { 00255 case TYPE_CODE_STRUCT: 00256 case TYPE_CODE_UNION: 00257 case TYPE_CODE_ARRAY: 00258 return 1; 00259 default: 00260 break; 00261 } 00262 00263 return 0; 00264 } 00265 00266 /* Register information. */ 00267 00268 static const char *sparc32_register_names[] = 00269 { 00270 "g0", "g1", "g2", "g3", "g4", "g5", "g6", "g7", 00271 "o0", "o1", "o2", "o3", "o4", "o5", "sp", "o7", 00272 "l0", "l1", "l2", "l3", "l4", "l5", "l6", "l7", 00273 "i0", "i1", "i2", "i3", "i4", "i5", "fp", "i7", 00274 00275 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", 00276 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", 00277 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23", 00278 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", 00279 00280 "y", "psr", "wim", "tbr", "pc", "npc", "fsr", "csr" 00281 }; 00282 00283 /* Total number of registers. */ 00284 #define SPARC32_NUM_REGS ARRAY_SIZE (sparc32_register_names) 00285 00286 /* We provide the aliases %d0..%d30 for the floating registers as 00287 "psuedo" registers. */ 00288 00289 static const char *sparc32_pseudo_register_names[] = 00290 { 00291 "d0", "d2", "d4", "d6", "d8", "d10", "d12", "d14", 00292 "d16", "d18", "d20", "d22", "d24", "d26", "d28", "d30" 00293 }; 00294 00295 /* Total number of pseudo registers. */ 00296 #define SPARC32_NUM_PSEUDO_REGS ARRAY_SIZE (sparc32_pseudo_register_names) 00297 00298 /* Return the name of register REGNUM. */ 00299 00300 static const char * 00301 sparc32_register_name (struct gdbarch *gdbarch, int regnum) 00302 { 00303 if (regnum >= 0 && regnum < SPARC32_NUM_REGS) 00304 return sparc32_register_names[regnum]; 00305 00306 if (regnum < SPARC32_NUM_REGS + SPARC32_NUM_PSEUDO_REGS) 00307 return sparc32_pseudo_register_names[regnum - SPARC32_NUM_REGS]; 00308 00309 return NULL; 00310 } 00311 00312 /* Construct types for ISA-specific registers. */ 00313 00314 static struct type * 00315 sparc_psr_type (struct gdbarch *gdbarch) 00316 { 00317 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); 00318 00319 if (!tdep->sparc_psr_type) 00320 { 00321 struct type *type; 00322 00323 type = arch_flags_type (gdbarch, "builtin_type_sparc_psr", 4); 00324 append_flags_type_flag (type, 5, "ET"); 00325 append_flags_type_flag (type, 6, "PS"); 00326 append_flags_type_flag (type, 7, "S"); 00327 append_flags_type_flag (type, 12, "EF"); 00328 append_flags_type_flag (type, 13, "EC"); 00329 00330 tdep->sparc_psr_type = type; 00331 } 00332 00333 return tdep->sparc_psr_type; 00334 } 00335 00336 static struct type * 00337 sparc_fsr_type (struct gdbarch *gdbarch) 00338 { 00339 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); 00340 00341 if (!tdep->sparc_fsr_type) 00342 { 00343 struct type *type; 00344 00345 type = arch_flags_type (gdbarch, "builtin_type_sparc_fsr", 4); 00346 append_flags_type_flag (type, 0, "NXA"); 00347 append_flags_type_flag (type, 1, "DZA"); 00348 append_flags_type_flag (type, 2, "UFA"); 00349 append_flags_type_flag (type, 3, "OFA"); 00350 append_flags_type_flag (type, 4, "NVA"); 00351 append_flags_type_flag (type, 5, "NXC"); 00352 append_flags_type_flag (type, 6, "DZC"); 00353 append_flags_type_flag (type, 7, "UFC"); 00354 append_flags_type_flag (type, 8, "OFC"); 00355 append_flags_type_flag (type, 9, "NVC"); 00356 append_flags_type_flag (type, 22, "NS"); 00357 append_flags_type_flag (type, 23, "NXM"); 00358 append_flags_type_flag (type, 24, "DZM"); 00359 append_flags_type_flag (type, 25, "UFM"); 00360 append_flags_type_flag (type, 26, "OFM"); 00361 append_flags_type_flag (type, 27, "NVM"); 00362 00363 tdep->sparc_fsr_type = type; 00364 } 00365 00366 return tdep->sparc_fsr_type; 00367 } 00368 00369 /* Return the GDB type object for the "standard" data type of data in 00370 register REGNUM. */ 00371 00372 static struct type * 00373 sparc32_register_type (struct gdbarch *gdbarch, int regnum) 00374 { 00375 if (regnum >= SPARC_F0_REGNUM && regnum <= SPARC_F31_REGNUM) 00376 return builtin_type (gdbarch)->builtin_float; 00377 00378 if (regnum >= SPARC32_D0_REGNUM && regnum <= SPARC32_D30_REGNUM) 00379 return builtin_type (gdbarch)->builtin_double; 00380 00381 if (regnum == SPARC_SP_REGNUM || regnum == SPARC_FP_REGNUM) 00382 return builtin_type (gdbarch)->builtin_data_ptr; 00383 00384 if (regnum == SPARC32_PC_REGNUM || regnum == SPARC32_NPC_REGNUM) 00385 return builtin_type (gdbarch)->builtin_func_ptr; 00386 00387 if (regnum == SPARC32_PSR_REGNUM) 00388 return sparc_psr_type (gdbarch); 00389 00390 if (regnum == SPARC32_FSR_REGNUM) 00391 return sparc_fsr_type (gdbarch); 00392 00393 return builtin_type (gdbarch)->builtin_int32; 00394 } 00395 00396 static enum register_status 00397 sparc32_pseudo_register_read (struct gdbarch *gdbarch, 00398 struct regcache *regcache, 00399 int regnum, gdb_byte *buf) 00400 { 00401 enum register_status status; 00402 00403 gdb_assert (regnum >= SPARC32_D0_REGNUM && regnum <= SPARC32_D30_REGNUM); 00404 00405 regnum = SPARC_F0_REGNUM + 2 * (regnum - SPARC32_D0_REGNUM); 00406 status = regcache_raw_read (regcache, regnum, buf); 00407 if (status == REG_VALID) 00408 status = regcache_raw_read (regcache, regnum + 1, buf + 4); 00409 return status; 00410 } 00411 00412 static void 00413 sparc32_pseudo_register_write (struct gdbarch *gdbarch, 00414 struct regcache *regcache, 00415 int regnum, const gdb_byte *buf) 00416 { 00417 gdb_assert (regnum >= SPARC32_D0_REGNUM && regnum <= SPARC32_D30_REGNUM); 00418 00419 regnum = SPARC_F0_REGNUM + 2 * (regnum - SPARC32_D0_REGNUM); 00420 regcache_raw_write (regcache, regnum, buf); 00421 regcache_raw_write (regcache, regnum + 1, buf + 4); 00422 } 00423 00424 00425 static CORE_ADDR 00426 sparc32_frame_align (struct gdbarch *gdbarch, CORE_ADDR address) 00427 { 00428 /* The ABI requires double-word alignment. */ 00429 return address & ~0x7; 00430 } 00431 00432 static CORE_ADDR 00433 sparc32_push_dummy_code (struct gdbarch *gdbarch, CORE_ADDR sp, 00434 CORE_ADDR funcaddr, 00435 struct value **args, int nargs, 00436 struct type *value_type, 00437 CORE_ADDR *real_pc, CORE_ADDR *bp_addr, 00438 struct regcache *regcache) 00439 { 00440 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 00441 00442 *bp_addr = sp - 4; 00443 *real_pc = funcaddr; 00444 00445 if (using_struct_return (gdbarch, NULL, value_type)) 00446 { 00447 gdb_byte buf[4]; 00448 00449 /* This is an UNIMP instruction. */ 00450 store_unsigned_integer (buf, 4, byte_order, 00451 TYPE_LENGTH (value_type) & 0x1fff); 00452 write_memory (sp - 8, buf, 4); 00453 return sp - 8; 00454 } 00455 00456 return sp - 4; 00457 } 00458 00459 static CORE_ADDR 00460 sparc32_store_arguments (struct regcache *regcache, int nargs, 00461 struct value **args, CORE_ADDR sp, 00462 int struct_return, CORE_ADDR struct_addr) 00463 { 00464 struct gdbarch *gdbarch = get_regcache_arch (regcache); 00465 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 00466 /* Number of words in the "parameter array". */ 00467 int num_elements = 0; 00468 int element = 0; 00469 int i; 00470 00471 for (i = 0; i < nargs; i++) 00472 { 00473 struct type *type = value_type (args[i]); 00474 int len = TYPE_LENGTH (type); 00475 00476 if (sparc_structure_or_union_p (type) 00477 || (sparc_floating_p (type) && len == 16) 00478 || sparc_complex_floating_p (type)) 00479 { 00480 /* Structure, Union and Quad-Precision Arguments. */ 00481 sp -= len; 00482 00483 /* Use doubleword alignment for these values. That's always 00484 correct, and wasting a few bytes shouldn't be a problem. */ 00485 sp &= ~0x7; 00486 00487 write_memory (sp, value_contents (args[i]), len); 00488 args[i] = value_from_pointer (lookup_pointer_type (type), sp); 00489 num_elements++; 00490 } 00491 else if (sparc_floating_p (type)) 00492 { 00493 /* Floating arguments. */ 00494 gdb_assert (len == 4 || len == 8); 00495 num_elements += (len / 4); 00496 } 00497 else 00498 { 00499 /* Integral and pointer arguments. */ 00500 gdb_assert (sparc_integral_or_pointer_p (type)); 00501 00502 if (len < 4) 00503 args[i] = value_cast (builtin_type (gdbarch)->builtin_int32, 00504 args[i]); 00505 num_elements += ((len + 3) / 4); 00506 } 00507 } 00508 00509 /* Always allocate at least six words. */ 00510 sp -= max (6, num_elements) * 4; 00511 00512 /* The psABI says that "Software convention requires space for the 00513 struct/union return value pointer, even if the word is unused." */ 00514 sp -= 4; 00515 00516 /* The psABI says that "Although software convention and the 00517 operating system require every stack frame to be doubleword 00518 aligned." */ 00519 sp &= ~0x7; 00520 00521 for (i = 0; i < nargs; i++) 00522 { 00523 const bfd_byte *valbuf = value_contents (args[i]); 00524 struct type *type = value_type (args[i]); 00525 int len = TYPE_LENGTH (type); 00526 00527 gdb_assert (len == 4 || len == 8); 00528 00529 if (element < 6) 00530 { 00531 int regnum = SPARC_O0_REGNUM + element; 00532 00533 regcache_cooked_write (regcache, regnum, valbuf); 00534 if (len > 4 && element < 5) 00535 regcache_cooked_write (regcache, regnum + 1, valbuf + 4); 00536 } 00537 00538 /* Always store the argument in memory. */ 00539 write_memory (sp + 4 + element * 4, valbuf, len); 00540 element += len / 4; 00541 } 00542 00543 gdb_assert (element == num_elements); 00544 00545 if (struct_return) 00546 { 00547 gdb_byte buf[4]; 00548 00549 store_unsigned_integer (buf, 4, byte_order, struct_addr); 00550 write_memory (sp, buf, 4); 00551 } 00552 00553 return sp; 00554 } 00555 00556 static CORE_ADDR 00557 sparc32_push_dummy_call (struct gdbarch *gdbarch, struct value *function, 00558 struct regcache *regcache, CORE_ADDR bp_addr, 00559 int nargs, struct value **args, CORE_ADDR sp, 00560 int struct_return, CORE_ADDR struct_addr) 00561 { 00562 CORE_ADDR call_pc = (struct_return ? (bp_addr - 12) : (bp_addr - 8)); 00563 00564 /* Set return address. */ 00565 regcache_cooked_write_unsigned (regcache, SPARC_O7_REGNUM, call_pc); 00566 00567 /* Set up function arguments. */ 00568 sp = sparc32_store_arguments (regcache, nargs, args, sp, 00569 struct_return, struct_addr); 00570 00571 /* Allocate the 16-word window save area. */ 00572 sp -= 16 * 4; 00573 00574 /* Stack should be doubleword aligned at this point. */ 00575 gdb_assert (sp % 8 == 0); 00576 00577 /* Finally, update the stack pointer. */ 00578 regcache_cooked_write_unsigned (regcache, SPARC_SP_REGNUM, sp); 00579 00580 return sp; 00581 } 00582 00583 00584 /* Use the program counter to determine the contents and size of a 00585 breakpoint instruction. Return a pointer to a string of bytes that 00586 encode a breakpoint instruction, store the length of the string in 00587 *LEN and optionally adjust *PC to point to the correct memory 00588 location for inserting the breakpoint. */ 00589 00590 static const gdb_byte * 00591 sparc_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pc, int *len) 00592 { 00593 static const gdb_byte break_insn[] = { 0x91, 0xd0, 0x20, 0x01 }; 00594 00595 *len = sizeof (break_insn); 00596 return break_insn; 00597 } 00598 00599 00600 /* Allocate and initialize a frame cache. */ 00601 00602 static struct sparc_frame_cache * 00603 sparc_alloc_frame_cache (void) 00604 { 00605 struct sparc_frame_cache *cache; 00606 00607 cache = FRAME_OBSTACK_ZALLOC (struct sparc_frame_cache); 00608 00609 /* Base address. */ 00610 cache->base = 0; 00611 cache->pc = 0; 00612 00613 /* Frameless until proven otherwise. */ 00614 cache->frameless_p = 1; 00615 cache->frame_offset = 0; 00616 cache->saved_regs_mask = 0; 00617 cache->copied_regs_mask = 0; 00618 cache->struct_return_p = 0; 00619 00620 return cache; 00621 } 00622 00623 /* GCC generates several well-known sequences of instructions at the begining 00624 of each function prologue when compiling with -fstack-check. If one of 00625 such sequences starts at START_PC, then return the address of the 00626 instruction immediately past this sequence. Otherwise, return START_PC. */ 00627 00628 static CORE_ADDR 00629 sparc_skip_stack_check (const CORE_ADDR start_pc) 00630 { 00631 CORE_ADDR pc = start_pc; 00632 unsigned long insn; 00633 int offset_stack_checking_sequence = 0; 00634 int probing_loop = 0; 00635 00636 /* With GCC, all stack checking sequences begin with the same two 00637 instructions, plus an optional one in the case of a probing loop: 00638 00639 sethi <some immediate>, %g1 00640 sub %sp, %g1, %g1 00641 00642 or: 00643 00644 sethi <some immediate>, %g1 00645 sethi <some immediate>, %g4 00646 sub %sp, %g1, %g1 00647 00648 or: 00649 00650 sethi <some immediate>, %g1 00651 sub %sp, %g1, %g1 00652 sethi <some immediate>, %g4 00653 00654 If the optional instruction is found (setting g4), assume that a 00655 probing loop will follow. */ 00656 00657 /* sethi <some immediate>, %g1 */ 00658 insn = sparc_fetch_instruction (pc); 00659 pc = pc + 4; 00660 if (!(X_OP (insn) == 0 && X_OP2 (insn) == 0x4 && X_RD (insn) == 1)) 00661 return start_pc; 00662 00663 /* optional: sethi <some immediate>, %g4 */ 00664 insn = sparc_fetch_instruction (pc); 00665 pc = pc + 4; 00666 if (X_OP (insn) == 0 && X_OP2 (insn) == 0x4 && X_RD (insn) == 4) 00667 { 00668 probing_loop = 1; 00669 insn = sparc_fetch_instruction (pc); 00670 pc = pc + 4; 00671 } 00672 00673 /* sub %sp, %g1, %g1 */ 00674 if (!(X_OP (insn) == 2 && X_OP3 (insn) == 0x4 && !X_I(insn) 00675 && X_RD (insn) == 1 && X_RS1 (insn) == 14 && X_RS2 (insn) == 1)) 00676 return start_pc; 00677 00678 insn = sparc_fetch_instruction (pc); 00679 pc = pc + 4; 00680 00681 /* optional: sethi <some immediate>, %g4 */ 00682 if (X_OP (insn) == 0 && X_OP2 (insn) == 0x4 && X_RD (insn) == 4) 00683 { 00684 probing_loop = 1; 00685 insn = sparc_fetch_instruction (pc); 00686 pc = pc + 4; 00687 } 00688 00689 /* First possible sequence: 00690 [first two instructions above] 00691 clr [%g1 - some immediate] */ 00692 00693 /* clr [%g1 - some immediate] */ 00694 if (X_OP (insn) == 3 && X_OP3(insn) == 0x4 && X_I(insn) 00695 && X_RS1 (insn) == 1 && X_RD (insn) == 0) 00696 { 00697 /* Valid stack-check sequence, return the new PC. */ 00698 return pc; 00699 } 00700 00701 /* Second possible sequence: A small number of probes. 00702 [first two instructions above] 00703 clr [%g1] 00704 add %g1, -<some immediate>, %g1 00705 clr [%g1] 00706 [repeat the two instructions above any (small) number of times] 00707 clr [%g1 - some immediate] */ 00708 00709 /* clr [%g1] */ 00710 else if (X_OP (insn) == 3 && X_OP3(insn) == 0x4 && !X_I(insn) 00711 && X_RS1 (insn) == 1 && X_RD (insn) == 0) 00712 { 00713 while (1) 00714 { 00715 /* add %g1, -<some immediate>, %g1 */ 00716 insn = sparc_fetch_instruction (pc); 00717 pc = pc + 4; 00718 if (!(X_OP (insn) == 2 && X_OP3(insn) == 0 && X_I(insn) 00719 && X_RS1 (insn) == 1 && X_RD (insn) == 1)) 00720 break; 00721 00722 /* clr [%g1] */ 00723 insn = sparc_fetch_instruction (pc); 00724 pc = pc + 4; 00725 if (!(X_OP (insn) == 3 && X_OP3(insn) == 0x4 && !X_I(insn) 00726 && X_RD (insn) == 0 && X_RS1 (insn) == 1)) 00727 return start_pc; 00728 } 00729 00730 /* clr [%g1 - some immediate] */ 00731 if (!(X_OP (insn) == 3 && X_OP3(insn) == 0x4 && X_I(insn) 00732 && X_RS1 (insn) == 1 && X_RD (insn) == 0)) 00733 return start_pc; 00734 00735 /* We found a valid stack-check sequence, return the new PC. */ 00736 return pc; 00737 } 00738 00739 /* Third sequence: A probing loop. 00740 [first three instructions above] 00741 sub %g1, %g4, %g4 00742 cmp %g1, %g4 00743 be <disp> 00744 add %g1, -<some immediate>, %g1 00745 ba <disp> 00746 clr [%g1] 00747 00748 And an optional last probe for the remainder: 00749 00750 clr [%g4 - some immediate] */ 00751 00752 if (probing_loop) 00753 { 00754 /* sub %g1, %g4, %g4 */ 00755 if (!(X_OP (insn) == 2 && X_OP3 (insn) == 0x4 && !X_I(insn) 00756 && X_RD (insn) == 4 && X_RS1 (insn) == 1 && X_RS2 (insn) == 4)) 00757 return start_pc; 00758 00759 /* cmp %g1, %g4 */ 00760 insn = sparc_fetch_instruction (pc); 00761 pc = pc + 4; 00762 if (!(X_OP (insn) == 2 && X_OP3 (insn) == 0x14 && !X_I(insn) 00763 && X_RD (insn) == 0 && X_RS1 (insn) == 1 && X_RS2 (insn) == 4)) 00764 return start_pc; 00765 00766 /* be <disp> */ 00767 insn = sparc_fetch_instruction (pc); 00768 pc = pc + 4; 00769 if (!(X_OP (insn) == 0 && X_COND (insn) == 0x1)) 00770 return start_pc; 00771 00772 /* add %g1, -<some immediate>, %g1 */ 00773 insn = sparc_fetch_instruction (pc); 00774 pc = pc + 4; 00775 if (!(X_OP (insn) == 2 && X_OP3(insn) == 0 && X_I(insn) 00776 && X_RS1 (insn) == 1 && X_RD (insn) == 1)) 00777 return start_pc; 00778 00779 /* ba <disp> */ 00780 insn = sparc_fetch_instruction (pc); 00781 pc = pc + 4; 00782 if (!(X_OP (insn) == 0 && X_COND (insn) == 0x8)) 00783 return start_pc; 00784 00785 /* clr [%g1] (st %g0, [%g1] or st %g0, [%g1+0]) */ 00786 insn = sparc_fetch_instruction (pc); 00787 pc = pc + 4; 00788 if (!(X_OP (insn) == 3 && X_OP3(insn) == 0x4 00789 && X_RD (insn) == 0 && X_RS1 (insn) == 1 00790 && (!X_I(insn) || X_SIMM13 (insn) == 0))) 00791 return start_pc; 00792 00793 /* We found a valid stack-check sequence, return the new PC. */ 00794 00795 /* optional: clr [%g4 - some immediate] */ 00796 insn = sparc_fetch_instruction (pc); 00797 pc = pc + 4; 00798 if (!(X_OP (insn) == 3 && X_OP3(insn) == 0x4 && X_I(insn) 00799 && X_RS1 (insn) == 4 && X_RD (insn) == 0)) 00800 return pc - 4; 00801 else 00802 return pc; 00803 } 00804 00805 /* No stack check code in our prologue, return the start_pc. */ 00806 return start_pc; 00807 } 00808 00809 /* Record the effect of a SAVE instruction on CACHE. */ 00810 00811 void 00812 sparc_record_save_insn (struct sparc_frame_cache *cache) 00813 { 00814 /* The frame is set up. */ 00815 cache->frameless_p = 0; 00816 00817 /* The frame pointer contains the CFA. */ 00818 cache->frame_offset = 0; 00819 00820 /* The `local' and `in' registers are all saved. */ 00821 cache->saved_regs_mask = 0xffff; 00822 00823 /* The `out' registers are all renamed. */ 00824 cache->copied_regs_mask = 0xff; 00825 } 00826 00827 /* Do a full analysis of the prologue at PC and update CACHE accordingly. 00828 Bail out early if CURRENT_PC is reached. Return the address where 00829 the analysis stopped. 00830 00831 We handle both the traditional register window model and the single 00832 register window (aka flat) model. */ 00833 00834 CORE_ADDR 00835 sparc_analyze_prologue (struct gdbarch *gdbarch, CORE_ADDR pc, 00836 CORE_ADDR current_pc, struct sparc_frame_cache *cache) 00837 { 00838 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); 00839 unsigned long insn; 00840 int offset = 0; 00841 int dest = -1; 00842 00843 pc = sparc_skip_stack_check (pc); 00844 00845 if (current_pc <= pc) 00846 return current_pc; 00847 00848 /* We have to handle to "Procedure Linkage Table" (PLT) special. On 00849 SPARC the linker usually defines a symbol (typically 00850 _PROCEDURE_LINKAGE_TABLE_) at the start of the .plt section. 00851 This symbol makes us end up here with PC pointing at the start of 00852 the PLT and CURRENT_PC probably pointing at a PLT entry. If we 00853 would do our normal prologue analysis, we would probably conclude 00854 that we've got a frame when in reality we don't, since the 00855 dynamic linker patches up the first PLT with some code that 00856 starts with a SAVE instruction. Patch up PC such that it points 00857 at the start of our PLT entry. */ 00858 if (tdep->plt_entry_size > 0 && in_plt_section (current_pc)) 00859 pc = current_pc - ((current_pc - pc) % tdep->plt_entry_size); 00860 00861 insn = sparc_fetch_instruction (pc); 00862 00863 /* Recognize store insns and record their sources. */ 00864 while (X_OP (insn) == 3 00865 && (X_OP3 (insn) == 0x4 /* stw */ 00866 || X_OP3 (insn) == 0x7 /* std */ 00867 || X_OP3 (insn) == 0xe) /* stx */ 00868 && X_RS1 (insn) == SPARC_SP_REGNUM) 00869 { 00870 int regnum = X_RD (insn); 00871 00872 /* Recognize stores into the corresponding stack slots. */ 00873 if (regnum >= SPARC_L0_REGNUM && regnum <= SPARC_I7_REGNUM 00874 && ((X_I (insn) 00875 && X_SIMM13 (insn) == (X_OP3 (insn) == 0xe 00876 ? (regnum - SPARC_L0_REGNUM) * 8 + BIAS 00877 : (regnum - SPARC_L0_REGNUM) * 4)) 00878 || (!X_I (insn) && regnum == SPARC_L0_REGNUM))) 00879 { 00880 cache->saved_regs_mask |= (1 << (regnum - SPARC_L0_REGNUM)); 00881 if (X_OP3 (insn) == 0x7) 00882 cache->saved_regs_mask |= (1 << (regnum + 1 - SPARC_L0_REGNUM)); 00883 } 00884 00885 offset += 4; 00886 00887 insn = sparc_fetch_instruction (pc + offset); 00888 } 00889 00890 /* Recognize a SETHI insn and record its destination. */ 00891 if (X_OP (insn) == 0 && X_OP2 (insn) == 0x04) 00892 { 00893 dest = X_RD (insn); 00894 offset += 4; 00895 00896 insn = sparc_fetch_instruction (pc + offset); 00897 } 00898 00899 /* Allow for an arithmetic operation on DEST or %g1. */ 00900 if (X_OP (insn) == 2 && X_I (insn) 00901 && (X_RD (insn) == 1 || X_RD (insn) == dest)) 00902 { 00903 offset += 4; 00904 00905 insn = sparc_fetch_instruction (pc + offset); 00906 } 00907 00908 /* Check for the SAVE instruction that sets up the frame. */ 00909 if (X_OP (insn) == 2 && X_OP3 (insn) == 0x3c) 00910 { 00911 sparc_record_save_insn (cache); 00912 offset += 4; 00913 return pc + offset; 00914 } 00915 00916 /* Check for an arithmetic operation on %sp. */ 00917 if (X_OP (insn) == 2 00918 && (X_OP3 (insn) == 0 || X_OP3 (insn) == 0x4) 00919 && X_RS1 (insn) == SPARC_SP_REGNUM 00920 && X_RD (insn) == SPARC_SP_REGNUM) 00921 { 00922 if (X_I (insn)) 00923 { 00924 cache->frame_offset = X_SIMM13 (insn); 00925 if (X_OP3 (insn) == 0) 00926 cache->frame_offset = -cache->frame_offset; 00927 } 00928 offset += 4; 00929 00930 insn = sparc_fetch_instruction (pc + offset); 00931 00932 /* Check for an arithmetic operation that sets up the frame. */ 00933 if (X_OP (insn) == 2 00934 && (X_OP3 (insn) == 0 || X_OP3 (insn) == 0x4) 00935 && X_RS1 (insn) == SPARC_SP_REGNUM 00936 && X_RD (insn) == SPARC_FP_REGNUM) 00937 { 00938 cache->frameless_p = 0; 00939 cache->frame_offset = 0; 00940 /* We could check that the amount subtracted to %sp above is the 00941 same as the one added here, but this seems superfluous. */ 00942 cache->copied_regs_mask |= 0x40; 00943 offset += 4; 00944 00945 insn = sparc_fetch_instruction (pc + offset); 00946 } 00947 00948 /* Check for a move (or) operation that copies the return register. */ 00949 if (X_OP (insn) == 2 00950 && X_OP3 (insn) == 0x2 00951 && !X_I (insn) 00952 && X_RS1 (insn) == SPARC_G0_REGNUM 00953 && X_RS2 (insn) == SPARC_O7_REGNUM 00954 && X_RD (insn) == SPARC_I7_REGNUM) 00955 { 00956 cache->copied_regs_mask |= 0x80; 00957 offset += 4; 00958 } 00959 00960 return pc + offset; 00961 } 00962 00963 return pc; 00964 } 00965 00966 static CORE_ADDR 00967 sparc_unwind_pc (struct gdbarch *gdbarch, struct frame_info *this_frame) 00968 { 00969 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); 00970 return frame_unwind_register_unsigned (this_frame, tdep->pc_regnum); 00971 } 00972 00973 /* Return PC of first real instruction of the function starting at 00974 START_PC. */ 00975 00976 static CORE_ADDR 00977 sparc32_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc) 00978 { 00979 struct symtab_and_line sal; 00980 CORE_ADDR func_start, func_end; 00981 struct sparc_frame_cache cache; 00982 00983 /* This is the preferred method, find the end of the prologue by 00984 using the debugging information. */ 00985 if (find_pc_partial_function (start_pc, NULL, &func_start, &func_end)) 00986 { 00987 sal = find_pc_line (func_start, 0); 00988 00989 if (sal.end < func_end 00990 && start_pc <= sal.end) 00991 return sal.end; 00992 } 00993 00994 start_pc = sparc_analyze_prologue (gdbarch, start_pc, 0xffffffffUL, &cache); 00995 00996 /* The psABI says that "Although the first 6 words of arguments 00997 reside in registers, the standard stack frame reserves space for 00998 them.". It also suggests that a function may use that space to 00999 "write incoming arguments 0 to 5" into that space, and that's 01000 indeed what GCC seems to be doing. In that case GCC will 01001 generate debug information that points to the stack slots instead 01002 of the registers, so we should consider the instructions that 01003 write out these incoming arguments onto the stack. */ 01004 01005 while (1) 01006 { 01007 unsigned long insn = sparc_fetch_instruction (start_pc); 01008 01009 /* Recognize instructions that store incoming arguments into the 01010 corresponding stack slots. */ 01011 if (X_OP (insn) == 3 && (X_OP3 (insn) & 0x3c) == 0x04 01012 && X_I (insn) && X_RS1 (insn) == SPARC_FP_REGNUM) 01013 { 01014 int regnum = X_RD (insn); 01015 01016 /* Case of arguments still in %o[0..5]. */ 01017 if (regnum >= SPARC_O0_REGNUM && regnum <= SPARC_O5_REGNUM 01018 && !(cache.copied_regs_mask & (1 << (regnum - SPARC_O0_REGNUM))) 01019 && X_SIMM13 (insn) == 68 + (regnum - SPARC_O0_REGNUM) * 4) 01020 { 01021 start_pc += 4; 01022 continue; 01023 } 01024 01025 /* Case of arguments copied into %i[0..5]. */ 01026 if (regnum >= SPARC_I0_REGNUM && regnum <= SPARC_I5_REGNUM 01027 && (cache.copied_regs_mask & (1 << (regnum - SPARC_I0_REGNUM))) 01028 && X_SIMM13 (insn) == 68 + (regnum - SPARC_I0_REGNUM) * 4) 01029 { 01030 start_pc += 4; 01031 continue; 01032 } 01033 } 01034 01035 break; 01036 } 01037 01038 return start_pc; 01039 } 01040 01041 /* Normal frames. */ 01042 01043 struct sparc_frame_cache * 01044 sparc_frame_cache (struct frame_info *this_frame, void **this_cache) 01045 { 01046 struct sparc_frame_cache *cache; 01047 01048 if (*this_cache) 01049 return *this_cache; 01050 01051 cache = sparc_alloc_frame_cache (); 01052 *this_cache = cache; 01053 01054 cache->pc = get_frame_func (this_frame); 01055 if (cache->pc != 0) 01056 sparc_analyze_prologue (get_frame_arch (this_frame), cache->pc, 01057 get_frame_pc (this_frame), cache); 01058 01059 if (cache->frameless_p) 01060 { 01061 /* This function is frameless, so %fp (%i6) holds the frame 01062 pointer for our calling frame. Use %sp (%o6) as this frame's 01063 base address. */ 01064 cache->base = 01065 get_frame_register_unsigned (this_frame, SPARC_SP_REGNUM); 01066 } 01067 else 01068 { 01069 /* For normal frames, %fp (%i6) holds the frame pointer, the 01070 base address for the current stack frame. */ 01071 cache->base = 01072 get_frame_register_unsigned (this_frame, SPARC_FP_REGNUM); 01073 } 01074 01075 cache->base += cache->frame_offset; 01076 01077 if (cache->base & 1) 01078 cache->base += BIAS; 01079 01080 return cache; 01081 } 01082 01083 static int 01084 sparc32_struct_return_from_sym (struct symbol *sym) 01085 { 01086 struct type *type = check_typedef (SYMBOL_TYPE (sym)); 01087 enum type_code code = TYPE_CODE (type); 01088 01089 if (code == TYPE_CODE_FUNC || code == TYPE_CODE_METHOD) 01090 { 01091 type = check_typedef (TYPE_TARGET_TYPE (type)); 01092 if (sparc_structure_or_union_p (type) 01093 || (sparc_floating_p (type) && TYPE_LENGTH (type) == 16)) 01094 return 1; 01095 } 01096 01097 return 0; 01098 } 01099 01100 struct sparc_frame_cache * 01101 sparc32_frame_cache (struct frame_info *this_frame, void **this_cache) 01102 { 01103 struct sparc_frame_cache *cache; 01104 struct symbol *sym; 01105 01106 if (*this_cache) 01107 return *this_cache; 01108 01109 cache = sparc_frame_cache (this_frame, this_cache); 01110 01111 sym = find_pc_function (cache->pc); 01112 if (sym) 01113 { 01114 cache->struct_return_p = sparc32_struct_return_from_sym (sym); 01115 } 01116 else 01117 { 01118 /* There is no debugging information for this function to 01119 help us determine whether this function returns a struct 01120 or not. So we rely on another heuristic which is to check 01121 the instruction at the return address and see if this is 01122 an "unimp" instruction. If it is, then it is a struct-return 01123 function. */ 01124 CORE_ADDR pc; 01125 int regnum = 01126 (cache->copied_regs_mask & 0x80) ? SPARC_I7_REGNUM : SPARC_O7_REGNUM; 01127 01128 pc = get_frame_register_unsigned (this_frame, regnum) + 8; 01129 if (sparc_is_unimp_insn (pc)) 01130 cache->struct_return_p = 1; 01131 } 01132 01133 return cache; 01134 } 01135 01136 static void 01137 sparc32_frame_this_id (struct frame_info *this_frame, void **this_cache, 01138 struct frame_id *this_id) 01139 { 01140 struct sparc_frame_cache *cache = 01141 sparc32_frame_cache (this_frame, this_cache); 01142 01143 /* This marks the outermost frame. */ 01144 if (cache->base == 0) 01145 return; 01146 01147 (*this_id) = frame_id_build (cache->base, cache->pc); 01148 } 01149 01150 static struct value * 01151 sparc32_frame_prev_register (struct frame_info *this_frame, 01152 void **this_cache, int regnum) 01153 { 01154 struct gdbarch *gdbarch = get_frame_arch (this_frame); 01155 struct sparc_frame_cache *cache = 01156 sparc32_frame_cache (this_frame, this_cache); 01157 01158 if (regnum == SPARC32_PC_REGNUM || regnum == SPARC32_NPC_REGNUM) 01159 { 01160 CORE_ADDR pc = (regnum == SPARC32_NPC_REGNUM) ? 4 : 0; 01161 01162 /* If this functions has a Structure, Union or Quad-Precision 01163 return value, we have to skip the UNIMP instruction that encodes 01164 the size of the structure. */ 01165 if (cache->struct_return_p) 01166 pc += 4; 01167 01168 regnum = 01169 (cache->copied_regs_mask & 0x80) ? SPARC_I7_REGNUM : SPARC_O7_REGNUM; 01170 pc += get_frame_register_unsigned (this_frame, regnum) + 8; 01171 return frame_unwind_got_constant (this_frame, regnum, pc); 01172 } 01173 01174 /* Handle StackGhost. */ 01175 { 01176 ULONGEST wcookie = sparc_fetch_wcookie (gdbarch); 01177 01178 if (wcookie != 0 && !cache->frameless_p && regnum == SPARC_I7_REGNUM) 01179 { 01180 CORE_ADDR addr = cache->base + (regnum - SPARC_L0_REGNUM) * 4; 01181 ULONGEST i7; 01182 01183 /* Read the value in from memory. */ 01184 i7 = get_frame_memory_unsigned (this_frame, addr, 4); 01185 return frame_unwind_got_constant (this_frame, regnum, i7 ^ wcookie); 01186 } 01187 } 01188 01189 /* The previous frame's `local' and `in' registers may have been saved 01190 in the register save area. */ 01191 if (regnum >= SPARC_L0_REGNUM && regnum <= SPARC_I7_REGNUM 01192 && (cache->saved_regs_mask & (1 << (regnum - SPARC_L0_REGNUM)))) 01193 { 01194 CORE_ADDR addr = cache->base + (regnum - SPARC_L0_REGNUM) * 4; 01195 01196 return frame_unwind_got_memory (this_frame, regnum, addr); 01197 } 01198 01199 /* The previous frame's `out' registers may be accessible as the current 01200 frame's `in' registers. */ 01201 if (regnum >= SPARC_O0_REGNUM && regnum <= SPARC_O7_REGNUM 01202 && (cache->copied_regs_mask & (1 << (regnum - SPARC_O0_REGNUM)))) 01203 regnum += (SPARC_I0_REGNUM - SPARC_O0_REGNUM); 01204 01205 return frame_unwind_got_register (this_frame, regnum, regnum); 01206 } 01207 01208 static const struct frame_unwind sparc32_frame_unwind = 01209 { 01210 NORMAL_FRAME, 01211 default_frame_unwind_stop_reason, 01212 sparc32_frame_this_id, 01213 sparc32_frame_prev_register, 01214 NULL, 01215 default_frame_sniffer 01216 }; 01217 01218 01219 static CORE_ADDR 01220 sparc32_frame_base_address (struct frame_info *this_frame, void **this_cache) 01221 { 01222 struct sparc_frame_cache *cache = 01223 sparc32_frame_cache (this_frame, this_cache); 01224 01225 return cache->base; 01226 } 01227 01228 static const struct frame_base sparc32_frame_base = 01229 { 01230 &sparc32_frame_unwind, 01231 sparc32_frame_base_address, 01232 sparc32_frame_base_address, 01233 sparc32_frame_base_address 01234 }; 01235 01236 static struct frame_id 01237 sparc_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame) 01238 { 01239 CORE_ADDR sp; 01240 01241 sp = get_frame_register_unsigned (this_frame, SPARC_SP_REGNUM); 01242 if (sp & 1) 01243 sp += BIAS; 01244 return frame_id_build (sp, get_frame_pc (this_frame)); 01245 } 01246 01247 01248 /* Extract a function return value of TYPE from REGCACHE, and copy 01249 that into VALBUF. */ 01250 01251 static void 01252 sparc32_extract_return_value (struct type *type, struct regcache *regcache, 01253 gdb_byte *valbuf) 01254 { 01255 int len = TYPE_LENGTH (type); 01256 gdb_byte buf[32]; 01257 01258 gdb_assert (!sparc_structure_or_union_p (type)); 01259 gdb_assert (!(sparc_floating_p (type) && len == 16)); 01260 01261 if (sparc_floating_p (type) || sparc_complex_floating_p (type)) 01262 { 01263 /* Floating return values. */ 01264 regcache_cooked_read (regcache, SPARC_F0_REGNUM, buf); 01265 if (len > 4) 01266 regcache_cooked_read (regcache, SPARC_F1_REGNUM, buf + 4); 01267 if (len > 8) 01268 { 01269 regcache_cooked_read (regcache, SPARC_F2_REGNUM, buf + 8); 01270 regcache_cooked_read (regcache, SPARC_F3_REGNUM, buf + 12); 01271 } 01272 if (len > 16) 01273 { 01274 regcache_cooked_read (regcache, SPARC_F4_REGNUM, buf + 16); 01275 regcache_cooked_read (regcache, SPARC_F5_REGNUM, buf + 20); 01276 regcache_cooked_read (regcache, SPARC_F6_REGNUM, buf + 24); 01277 regcache_cooked_read (regcache, SPARC_F7_REGNUM, buf + 28); 01278 } 01279 memcpy (valbuf, buf, len); 01280 } 01281 else 01282 { 01283 /* Integral and pointer return values. */ 01284 gdb_assert (sparc_integral_or_pointer_p (type)); 01285 01286 regcache_cooked_read (regcache, SPARC_O0_REGNUM, buf); 01287 if (len > 4) 01288 { 01289 regcache_cooked_read (regcache, SPARC_O1_REGNUM, buf + 4); 01290 gdb_assert (len == 8); 01291 memcpy (valbuf, buf, 8); 01292 } 01293 else 01294 { 01295 /* Just stripping off any unused bytes should preserve the 01296 signed-ness just fine. */ 01297 memcpy (valbuf, buf + 4 - len, len); 01298 } 01299 } 01300 } 01301 01302 /* Store the function return value of type TYPE from VALBUF into 01303 REGCACHE. */ 01304 01305 static void 01306 sparc32_store_return_value (struct type *type, struct regcache *regcache, 01307 const gdb_byte *valbuf) 01308 { 01309 int len = TYPE_LENGTH (type); 01310 gdb_byte buf[8]; 01311 01312 gdb_assert (!sparc_structure_or_union_p (type)); 01313 gdb_assert (!(sparc_floating_p (type) && len == 16)); 01314 gdb_assert (len <= 8); 01315 01316 if (sparc_floating_p (type) || sparc_complex_floating_p (type)) 01317 { 01318 /* Floating return values. */ 01319 memcpy (buf, valbuf, len); 01320 regcache_cooked_write (regcache, SPARC_F0_REGNUM, buf); 01321 if (len > 4) 01322 regcache_cooked_write (regcache, SPARC_F1_REGNUM, buf + 4); 01323 if (len > 8) 01324 { 01325 regcache_cooked_write (regcache, SPARC_F2_REGNUM, buf + 8); 01326 regcache_cooked_write (regcache, SPARC_F3_REGNUM, buf + 12); 01327 } 01328 if (len > 16) 01329 { 01330 regcache_cooked_write (regcache, SPARC_F4_REGNUM, buf + 16); 01331 regcache_cooked_write (regcache, SPARC_F5_REGNUM, buf + 20); 01332 regcache_cooked_write (regcache, SPARC_F6_REGNUM, buf + 24); 01333 regcache_cooked_write (regcache, SPARC_F7_REGNUM, buf + 28); 01334 } 01335 } 01336 else 01337 { 01338 /* Integral and pointer return values. */ 01339 gdb_assert (sparc_integral_or_pointer_p (type)); 01340 01341 if (len > 4) 01342 { 01343 gdb_assert (len == 8); 01344 memcpy (buf, valbuf, 8); 01345 regcache_cooked_write (regcache, SPARC_O1_REGNUM, buf + 4); 01346 } 01347 else 01348 { 01349 /* ??? Do we need to do any sign-extension here? */ 01350 memcpy (buf + 4 - len, valbuf, len); 01351 } 01352 regcache_cooked_write (regcache, SPARC_O0_REGNUM, buf); 01353 } 01354 } 01355 01356 static enum return_value_convention 01357 sparc32_return_value (struct gdbarch *gdbarch, struct value *function, 01358 struct type *type, struct regcache *regcache, 01359 gdb_byte *readbuf, const gdb_byte *writebuf) 01360 { 01361 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 01362 01363 /* The psABI says that "...every stack frame reserves the word at 01364 %fp+64. If a function returns a structure, union, or 01365 quad-precision value, this word should hold the address of the 01366 object into which the return value should be copied." This 01367 guarantees that we can always find the return value, not just 01368 before the function returns. */ 01369 01370 if (sparc_structure_or_union_p (type) 01371 || (sparc_floating_p (type) && TYPE_LENGTH (type) == 16)) 01372 { 01373 ULONGEST sp; 01374 CORE_ADDR addr; 01375 01376 if (readbuf) 01377 { 01378 regcache_cooked_read_unsigned (regcache, SPARC_SP_REGNUM, &sp); 01379 addr = read_memory_unsigned_integer (sp + 64, 4, byte_order); 01380 read_memory (addr, readbuf, TYPE_LENGTH (type)); 01381 } 01382 if (writebuf) 01383 { 01384 regcache_cooked_read_unsigned (regcache, SPARC_SP_REGNUM, &sp); 01385 addr = read_memory_unsigned_integer (sp + 64, 4, byte_order); 01386 write_memory (addr, writebuf, TYPE_LENGTH (type)); 01387 } 01388 01389 return RETURN_VALUE_ABI_PRESERVES_ADDRESS; 01390 } 01391 01392 if (readbuf) 01393 sparc32_extract_return_value (type, regcache, readbuf); 01394 if (writebuf) 01395 sparc32_store_return_value (type, regcache, writebuf); 01396 01397 return RETURN_VALUE_REGISTER_CONVENTION; 01398 } 01399 01400 static int 01401 sparc32_stabs_argument_has_addr (struct gdbarch *gdbarch, struct type *type) 01402 { 01403 return (sparc_structure_or_union_p (type) 01404 || (sparc_floating_p (type) && TYPE_LENGTH (type) == 16) 01405 || sparc_complex_floating_p (type)); 01406 } 01407 01408 static int 01409 sparc32_dwarf2_struct_return_p (struct frame_info *this_frame) 01410 { 01411 CORE_ADDR pc = get_frame_address_in_block (this_frame); 01412 struct symbol *sym = find_pc_function (pc); 01413 01414 if (sym) 01415 return sparc32_struct_return_from_sym (sym); 01416 return 0; 01417 } 01418 01419 static void 01420 sparc32_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum, 01421 struct dwarf2_frame_state_reg *reg, 01422 struct frame_info *this_frame) 01423 { 01424 int off; 01425 01426 switch (regnum) 01427 { 01428 case SPARC_G0_REGNUM: 01429 /* Since %g0 is always zero, there is no point in saving it, and 01430 people will be inclined omit it from the CFI. Make sure we 01431 don't warn about that. */ 01432 reg->how = DWARF2_FRAME_REG_SAME_VALUE; 01433 break; 01434 case SPARC_SP_REGNUM: 01435 reg->how = DWARF2_FRAME_REG_CFA; 01436 break; 01437 case SPARC32_PC_REGNUM: 01438 case SPARC32_NPC_REGNUM: 01439 reg->how = DWARF2_FRAME_REG_RA_OFFSET; 01440 off = 8; 01441 if (sparc32_dwarf2_struct_return_p (this_frame)) 01442 off += 4; 01443 if (regnum == SPARC32_NPC_REGNUM) 01444 off += 4; 01445 reg->loc.offset = off; 01446 break; 01447 } 01448 } 01449 01450 01451 /* The SPARC Architecture doesn't have hardware single-step support, 01452 and most operating systems don't implement it either, so we provide 01453 software single-step mechanism. */ 01454 01455 static CORE_ADDR 01456 sparc_analyze_control_transfer (struct frame_info *frame, 01457 CORE_ADDR pc, CORE_ADDR *npc) 01458 { 01459 unsigned long insn = sparc_fetch_instruction (pc); 01460 int conditional_p = X_COND (insn) & 0x7; 01461 int branch_p = 0, fused_p = 0; 01462 long offset = 0; /* Must be signed for sign-extend. */ 01463 01464 if (X_OP (insn) == 0 && X_OP2 (insn) == 3) 01465 { 01466 if ((insn & 0x10000000) == 0) 01467 { 01468 /* Branch on Integer Register with Prediction (BPr). */ 01469 branch_p = 1; 01470 conditional_p = 1; 01471 } 01472 else 01473 { 01474 /* Compare and Branch */ 01475 branch_p = 1; 01476 fused_p = 1; 01477 offset = 4 * X_DISP10 (insn); 01478 } 01479 } 01480 else if (X_OP (insn) == 0 && X_OP2 (insn) == 6) 01481 { 01482 /* Branch on Floating-Point Condition Codes (FBfcc). */ 01483 branch_p = 1; 01484 offset = 4 * X_DISP22 (insn); 01485 } 01486 else if (X_OP (insn) == 0 && X_OP2 (insn) == 5) 01487 { 01488 /* Branch on Floating-Point Condition Codes with Prediction 01489 (FBPfcc). */ 01490 branch_p = 1; 01491 offset = 4 * X_DISP19 (insn); 01492 } 01493 else if (X_OP (insn) == 0 && X_OP2 (insn) == 2) 01494 { 01495 /* Branch on Integer Condition Codes (Bicc). */ 01496 branch_p = 1; 01497 offset = 4 * X_DISP22 (insn); 01498 } 01499 else if (X_OP (insn) == 0 && X_OP2 (insn) == 1) 01500 { 01501 /* Branch on Integer Condition Codes with Prediction (BPcc). */ 01502 branch_p = 1; 01503 offset = 4 * X_DISP19 (insn); 01504 } 01505 else if (X_OP (insn) == 2 && X_OP3 (insn) == 0x3a) 01506 { 01507 /* Trap instruction (TRAP). */ 01508 return gdbarch_tdep (get_frame_arch (frame))->step_trap (frame, insn); 01509 } 01510 01511 /* FIXME: Handle DONE and RETRY instructions. */ 01512 01513 if (branch_p) 01514 { 01515 if (fused_p) 01516 { 01517 /* Fused compare-and-branch instructions are non-delayed, 01518 and do not have an annuling capability. So we need to 01519 always set a breakpoint on both the NPC and the branch 01520 target address. */ 01521 gdb_assert (offset != 0); 01522 return pc + offset; 01523 } 01524 else if (conditional_p) 01525 { 01526 /* For conditional branches, return nPC + 4 iff the annul 01527 bit is 1. */ 01528 return (X_A (insn) ? *npc + 4 : 0); 01529 } 01530 else 01531 { 01532 /* For unconditional branches, return the target if its 01533 specified condition is "always" and return nPC + 4 if the 01534 condition is "never". If the annul bit is 1, set *NPC to 01535 zero. */ 01536 if (X_COND (insn) == 0x0) 01537 pc = *npc, offset = 4; 01538 if (X_A (insn)) 01539 *npc = 0; 01540 01541 gdb_assert (offset != 0); 01542 return pc + offset; 01543 } 01544 } 01545 01546 return 0; 01547 } 01548 01549 static CORE_ADDR 01550 sparc_step_trap (struct frame_info *frame, unsigned long insn) 01551 { 01552 return 0; 01553 } 01554 01555 int 01556 sparc_software_single_step (struct frame_info *frame) 01557 { 01558 struct gdbarch *arch = get_frame_arch (frame); 01559 struct gdbarch_tdep *tdep = gdbarch_tdep (arch); 01560 struct address_space *aspace = get_frame_address_space (frame); 01561 CORE_ADDR npc, nnpc; 01562 01563 CORE_ADDR pc, orig_npc; 01564 01565 pc = get_frame_register_unsigned (frame, tdep->pc_regnum); 01566 orig_npc = npc = get_frame_register_unsigned (frame, tdep->npc_regnum); 01567 01568 /* Analyze the instruction at PC. */ 01569 nnpc = sparc_analyze_control_transfer (frame, pc, &npc); 01570 if (npc != 0) 01571 insert_single_step_breakpoint (arch, aspace, npc); 01572 01573 if (nnpc != 0) 01574 insert_single_step_breakpoint (arch, aspace, nnpc); 01575 01576 /* Assert that we have set at least one breakpoint, and that 01577 they're not set at the same spot - unless we're going 01578 from here straight to NULL, i.e. a call or jump to 0. */ 01579 gdb_assert (npc != 0 || nnpc != 0 || orig_npc == 0); 01580 gdb_assert (nnpc != npc || orig_npc == 0); 01581 01582 return 1; 01583 } 01584 01585 static void 01586 sparc_write_pc (struct regcache *regcache, CORE_ADDR pc) 01587 { 01588 struct gdbarch_tdep *tdep = gdbarch_tdep (get_regcache_arch (regcache)); 01589 01590 regcache_cooked_write_unsigned (regcache, tdep->pc_regnum, pc); 01591 regcache_cooked_write_unsigned (regcache, tdep->npc_regnum, pc + 4); 01592 } 01593 01594 01595 /* Return the appropriate register set for the core section identified 01596 by SECT_NAME and SECT_SIZE. */ 01597 01598 static const struct regset * 01599 sparc_regset_from_core_section (struct gdbarch *gdbarch, 01600 const char *sect_name, size_t sect_size) 01601 { 01602 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); 01603 01604 if (strcmp (sect_name, ".reg") == 0 && sect_size >= tdep->sizeof_gregset) 01605 return tdep->gregset; 01606 01607 if (strcmp (sect_name, ".reg2") == 0 && sect_size >= tdep->sizeof_fpregset) 01608 return tdep->fpregset; 01609 01610 return NULL; 01611 } 01612 01613 01614 static struct gdbarch * 01615 sparc32_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) 01616 { 01617 struct gdbarch_tdep *tdep; 01618 struct gdbarch *gdbarch; 01619 01620 /* If there is already a candidate, use it. */ 01621 arches = gdbarch_list_lookup_by_info (arches, &info); 01622 if (arches != NULL) 01623 return arches->gdbarch; 01624 01625 /* Allocate space for the new architecture. */ 01626 tdep = XZALLOC (struct gdbarch_tdep); 01627 gdbarch = gdbarch_alloc (&info, tdep); 01628 01629 tdep->pc_regnum = SPARC32_PC_REGNUM; 01630 tdep->npc_regnum = SPARC32_NPC_REGNUM; 01631 tdep->step_trap = sparc_step_trap; 01632 01633 set_gdbarch_long_double_bit (gdbarch, 128); 01634 set_gdbarch_long_double_format (gdbarch, floatformats_sparc_quad); 01635 01636 set_gdbarch_num_regs (gdbarch, SPARC32_NUM_REGS); 01637 set_gdbarch_register_name (gdbarch, sparc32_register_name); 01638 set_gdbarch_register_type (gdbarch, sparc32_register_type); 01639 set_gdbarch_num_pseudo_regs (gdbarch, SPARC32_NUM_PSEUDO_REGS); 01640 set_gdbarch_pseudo_register_read (gdbarch, sparc32_pseudo_register_read); 01641 set_gdbarch_pseudo_register_write (gdbarch, sparc32_pseudo_register_write); 01642 01643 /* Register numbers of various important registers. */ 01644 set_gdbarch_sp_regnum (gdbarch, SPARC_SP_REGNUM); /* %sp */ 01645 set_gdbarch_pc_regnum (gdbarch, SPARC32_PC_REGNUM); /* %pc */ 01646 set_gdbarch_fp0_regnum (gdbarch, SPARC_F0_REGNUM); /* %f0 */ 01647 01648 /* Call dummy code. */ 01649 set_gdbarch_frame_align (gdbarch, sparc32_frame_align); 01650 set_gdbarch_call_dummy_location (gdbarch, ON_STACK); 01651 set_gdbarch_push_dummy_code (gdbarch, sparc32_push_dummy_code); 01652 set_gdbarch_push_dummy_call (gdbarch, sparc32_push_dummy_call); 01653 01654 set_gdbarch_return_value (gdbarch, sparc32_return_value); 01655 set_gdbarch_stabs_argument_has_addr 01656 (gdbarch, sparc32_stabs_argument_has_addr); 01657 01658 set_gdbarch_skip_prologue (gdbarch, sparc32_skip_prologue); 01659 01660 /* Stack grows downward. */ 01661 set_gdbarch_inner_than (gdbarch, core_addr_lessthan); 01662 01663 set_gdbarch_breakpoint_from_pc (gdbarch, sparc_breakpoint_from_pc); 01664 01665 set_gdbarch_frame_args_skip (gdbarch, 8); 01666 01667 set_gdbarch_print_insn (gdbarch, print_insn_sparc); 01668 01669 set_gdbarch_software_single_step (gdbarch, sparc_software_single_step); 01670 set_gdbarch_write_pc (gdbarch, sparc_write_pc); 01671 01672 set_gdbarch_dummy_id (gdbarch, sparc_dummy_id); 01673 01674 set_gdbarch_unwind_pc (gdbarch, sparc_unwind_pc); 01675 01676 frame_base_set_default (gdbarch, &sparc32_frame_base); 01677 01678 /* Hook in the DWARF CFI frame unwinder. */ 01679 dwarf2_frame_set_init_reg (gdbarch, sparc32_dwarf2_frame_init_reg); 01680 /* FIXME: kettenis/20050423: Don't enable the unwinder until the 01681 StackGhost issues have been resolved. */ 01682 01683 /* Hook in ABI-specific overrides, if they have been registered. */ 01684 gdbarch_init_osabi (info, gdbarch); 01685 01686 frame_unwind_append_unwinder (gdbarch, &sparc32_frame_unwind); 01687 01688 /* If we have register sets, enable the generic core file support. */ 01689 if (tdep->gregset) 01690 set_gdbarch_regset_from_core_section (gdbarch, 01691 sparc_regset_from_core_section); 01692 01693 register_sparc_ravenscar_ops (gdbarch); 01694 01695 return gdbarch; 01696 } 01697 01698 /* Helper functions for dealing with register windows. */ 01699 01700 void 01701 sparc_supply_rwindow (struct regcache *regcache, CORE_ADDR sp, int regnum) 01702 { 01703 struct gdbarch *gdbarch = get_regcache_arch (regcache); 01704 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 01705 int offset = 0; 01706 gdb_byte buf[8]; 01707 int i; 01708 01709 if (sp & 1) 01710 { 01711 /* Registers are 64-bit. */ 01712 sp += BIAS; 01713 01714 for (i = SPARC_L0_REGNUM; i <= SPARC_I7_REGNUM; i++) 01715 { 01716 if (regnum == i || regnum == -1) 01717 { 01718 target_read_memory (sp + ((i - SPARC_L0_REGNUM) * 8), buf, 8); 01719 01720 /* Handle StackGhost. */ 01721 if (i == SPARC_I7_REGNUM) 01722 { 01723 ULONGEST wcookie = sparc_fetch_wcookie (gdbarch); 01724 ULONGEST i7; 01725 01726 i7 = extract_unsigned_integer (buf + offset, 8, byte_order); 01727 store_unsigned_integer (buf + offset, 8, byte_order, 01728 i7 ^ wcookie); 01729 } 01730 01731 regcache_raw_supply (regcache, i, buf); 01732 } 01733 } 01734 } 01735 else 01736 { 01737 /* Registers are 32-bit. Toss any sign-extension of the stack 01738 pointer. */ 01739 sp &= 0xffffffffUL; 01740 01741 /* Clear out the top half of the temporary buffer, and put the 01742 register value in the bottom half if we're in 64-bit mode. */ 01743 if (gdbarch_ptr_bit (get_regcache_arch (regcache)) == 64) 01744 { 01745 memset (buf, 0, 4); 01746 offset = 4; 01747 } 01748 01749 for (i = SPARC_L0_REGNUM; i <= SPARC_I7_REGNUM; i++) 01750 { 01751 if (regnum == i || regnum == -1) 01752 { 01753 target_read_memory (sp + ((i - SPARC_L0_REGNUM) * 4), 01754 buf + offset, 4); 01755 01756 /* Handle StackGhost. */ 01757 if (i == SPARC_I7_REGNUM) 01758 { 01759 ULONGEST wcookie = sparc_fetch_wcookie (gdbarch); 01760 ULONGEST i7; 01761 01762 i7 = extract_unsigned_integer (buf + offset, 4, byte_order); 01763 store_unsigned_integer (buf + offset, 4, byte_order, 01764 i7 ^ wcookie); 01765 } 01766 01767 regcache_raw_supply (regcache, i, buf); 01768 } 01769 } 01770 } 01771 } 01772 01773 void 01774 sparc_collect_rwindow (const struct regcache *regcache, 01775 CORE_ADDR sp, int regnum) 01776 { 01777 struct gdbarch *gdbarch = get_regcache_arch (regcache); 01778 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 01779 int offset = 0; 01780 gdb_byte buf[8]; 01781 int i; 01782 01783 if (sp & 1) 01784 { 01785 /* Registers are 64-bit. */ 01786 sp += BIAS; 01787 01788 for (i = SPARC_L0_REGNUM; i <= SPARC_I7_REGNUM; i++) 01789 { 01790 if (regnum == -1 || regnum == SPARC_SP_REGNUM || regnum == i) 01791 { 01792 regcache_raw_collect (regcache, i, buf); 01793 01794 /* Handle StackGhost. */ 01795 if (i == SPARC_I7_REGNUM) 01796 { 01797 ULONGEST wcookie = sparc_fetch_wcookie (gdbarch); 01798 ULONGEST i7; 01799 01800 i7 = extract_unsigned_integer (buf + offset, 8, byte_order); 01801 store_unsigned_integer (buf, 8, byte_order, i7 ^ wcookie); 01802 } 01803 01804 target_write_memory (sp + ((i - SPARC_L0_REGNUM) * 8), buf, 8); 01805 } 01806 } 01807 } 01808 else 01809 { 01810 /* Registers are 32-bit. Toss any sign-extension of the stack 01811 pointer. */ 01812 sp &= 0xffffffffUL; 01813 01814 /* Only use the bottom half if we're in 64-bit mode. */ 01815 if (gdbarch_ptr_bit (get_regcache_arch (regcache)) == 64) 01816 offset = 4; 01817 01818 for (i = SPARC_L0_REGNUM; i <= SPARC_I7_REGNUM; i++) 01819 { 01820 if (regnum == -1 || regnum == SPARC_SP_REGNUM || regnum == i) 01821 { 01822 regcache_raw_collect (regcache, i, buf); 01823 01824 /* Handle StackGhost. */ 01825 if (i == SPARC_I7_REGNUM) 01826 { 01827 ULONGEST wcookie = sparc_fetch_wcookie (gdbarch); 01828 ULONGEST i7; 01829 01830 i7 = extract_unsigned_integer (buf + offset, 4, byte_order); 01831 store_unsigned_integer (buf + offset, 4, byte_order, 01832 i7 ^ wcookie); 01833 } 01834 01835 target_write_memory (sp + ((i - SPARC_L0_REGNUM) * 4), 01836 buf + offset, 4); 01837 } 01838 } 01839 } 01840 } 01841 01842 /* Helper functions for dealing with register sets. */ 01843 01844 void 01845 sparc32_supply_gregset (const struct sparc_gregset *gregset, 01846 struct regcache *regcache, 01847 int regnum, const void *gregs) 01848 { 01849 const gdb_byte *regs = gregs; 01850 gdb_byte zero[4] = { 0 }; 01851 int i; 01852 01853 if (regnum == SPARC32_PSR_REGNUM || regnum == -1) 01854 regcache_raw_supply (regcache, SPARC32_PSR_REGNUM, 01855 regs + gregset->r_psr_offset); 01856 01857 if (regnum == SPARC32_PC_REGNUM || regnum == -1) 01858 regcache_raw_supply (regcache, SPARC32_PC_REGNUM, 01859 regs + gregset->r_pc_offset); 01860 01861 if (regnum == SPARC32_NPC_REGNUM || regnum == -1) 01862 regcache_raw_supply (regcache, SPARC32_NPC_REGNUM, 01863 regs + gregset->r_npc_offset); 01864 01865 if (regnum == SPARC32_Y_REGNUM || regnum == -1) 01866 regcache_raw_supply (regcache, SPARC32_Y_REGNUM, 01867 regs + gregset->r_y_offset); 01868 01869 if (regnum == SPARC_G0_REGNUM || regnum == -1) 01870 regcache_raw_supply (regcache, SPARC_G0_REGNUM, &zero); 01871 01872 if ((regnum >= SPARC_G1_REGNUM && regnum <= SPARC_O7_REGNUM) || regnum == -1) 01873 { 01874 int offset = gregset->r_g1_offset; 01875 01876 for (i = SPARC_G1_REGNUM; i <= SPARC_O7_REGNUM; i++) 01877 { 01878 if (regnum == i || regnum == -1) 01879 regcache_raw_supply (regcache, i, regs + offset); 01880 offset += 4; 01881 } 01882 } 01883 01884 if ((regnum >= SPARC_L0_REGNUM && regnum <= SPARC_I7_REGNUM) || regnum == -1) 01885 { 01886 /* Not all of the register set variants include Locals and 01887 Inputs. For those that don't, we read them off the stack. */ 01888 if (gregset->r_l0_offset == -1) 01889 { 01890 ULONGEST sp; 01891 01892 regcache_cooked_read_unsigned (regcache, SPARC_SP_REGNUM, &sp); 01893 sparc_supply_rwindow (regcache, sp, regnum); 01894 } 01895 else 01896 { 01897 int offset = gregset->r_l0_offset; 01898 01899 for (i = SPARC_L0_REGNUM; i <= SPARC_I7_REGNUM; i++) 01900 { 01901 if (regnum == i || regnum == -1) 01902 regcache_raw_supply (regcache, i, regs + offset); 01903 offset += 4; 01904 } 01905 } 01906 } 01907 } 01908 01909 void 01910 sparc32_collect_gregset (const struct sparc_gregset *gregset, 01911 const struct regcache *regcache, 01912 int regnum, void *gregs) 01913 { 01914 gdb_byte *regs = gregs; 01915 int i; 01916 01917 if (regnum == SPARC32_PSR_REGNUM || regnum == -1) 01918 regcache_raw_collect (regcache, SPARC32_PSR_REGNUM, 01919 regs + gregset->r_psr_offset); 01920 01921 if (regnum == SPARC32_PC_REGNUM || regnum == -1) 01922 regcache_raw_collect (regcache, SPARC32_PC_REGNUM, 01923 regs + gregset->r_pc_offset); 01924 01925 if (regnum == SPARC32_NPC_REGNUM || regnum == -1) 01926 regcache_raw_collect (regcache, SPARC32_NPC_REGNUM, 01927 regs + gregset->r_npc_offset); 01928 01929 if (regnum == SPARC32_Y_REGNUM || regnum == -1) 01930 regcache_raw_collect (regcache, SPARC32_Y_REGNUM, 01931 regs + gregset->r_y_offset); 01932 01933 if ((regnum >= SPARC_G1_REGNUM && regnum <= SPARC_O7_REGNUM) || regnum == -1) 01934 { 01935 int offset = gregset->r_g1_offset; 01936 01937 /* %g0 is always zero. */ 01938 for (i = SPARC_G1_REGNUM; i <= SPARC_O7_REGNUM; i++) 01939 { 01940 if (regnum == i || regnum == -1) 01941 regcache_raw_collect (regcache, i, regs + offset); 01942 offset += 4; 01943 } 01944 } 01945 01946 if ((regnum >= SPARC_L0_REGNUM && regnum <= SPARC_I7_REGNUM) || regnum == -1) 01947 { 01948 /* Not all of the register set variants include Locals and 01949 Inputs. For those that don't, we read them off the stack. */ 01950 if (gregset->r_l0_offset != -1) 01951 { 01952 int offset = gregset->r_l0_offset; 01953 01954 for (i = SPARC_L0_REGNUM; i <= SPARC_I7_REGNUM; i++) 01955 { 01956 if (regnum == i || regnum == -1) 01957 regcache_raw_collect (regcache, i, regs + offset); 01958 offset += 4; 01959 } 01960 } 01961 } 01962 } 01963 01964 void 01965 sparc32_supply_fpregset (const struct sparc_fpregset *fpregset, 01966 struct regcache *regcache, 01967 int regnum, const void *fpregs) 01968 { 01969 const gdb_byte *regs = fpregs; 01970 int i; 01971 01972 for (i = 0; i < 32; i++) 01973 { 01974 if (regnum == (SPARC_F0_REGNUM + i) || regnum == -1) 01975 regcache_raw_supply (regcache, SPARC_F0_REGNUM + i, 01976 regs + fpregset->r_f0_offset + (i * 4)); 01977 } 01978 01979 if (regnum == SPARC32_FSR_REGNUM || regnum == -1) 01980 regcache_raw_supply (regcache, SPARC32_FSR_REGNUM, 01981 regs + fpregset->r_fsr_offset); 01982 } 01983 01984 void 01985 sparc32_collect_fpregset (const struct sparc_fpregset *fpregset, 01986 const struct regcache *regcache, 01987 int regnum, void *fpregs) 01988 { 01989 gdb_byte *regs = fpregs; 01990 int i; 01991 01992 for (i = 0; i < 32; i++) 01993 { 01994 if (regnum == (SPARC_F0_REGNUM + i) || regnum == -1) 01995 regcache_raw_collect (regcache, SPARC_F0_REGNUM + i, 01996 regs + fpregset->r_f0_offset + (i * 4)); 01997 } 01998 01999 if (regnum == SPARC32_FSR_REGNUM || regnum == -1) 02000 regcache_raw_collect (regcache, SPARC32_FSR_REGNUM, 02001 regs + fpregset->r_fsr_offset); 02002 } 02003 02004 02005 /* SunOS 4. */ 02006 02007 /* From <machine/reg.h>. */ 02008 const struct sparc_gregset sparc32_sunos4_gregset = 02009 { 02010 0 * 4, /* %psr */ 02011 1 * 4, /* %pc */ 02012 2 * 4, /* %npc */ 02013 3 * 4, /* %y */ 02014 -1, /* %wim */ 02015 -1, /* %tbr */ 02016 4 * 4, /* %g1 */ 02017 -1 /* %l0 */ 02018 }; 02019 02020 const struct sparc_fpregset sparc32_sunos4_fpregset = 02021 { 02022 0 * 4, /* %f0 */ 02023 33 * 4, /* %fsr */ 02024 }; 02025 02026 const struct sparc_fpregset sparc32_bsd_fpregset = 02027 { 02028 0 * 4, /* %f0 */ 02029 32 * 4, /* %fsr */ 02030 }; 02031 02032 02033 /* Provide a prototype to silence -Wmissing-prototypes. */ 02034 void _initialize_sparc_tdep (void); 02035 02036 void 02037 _initialize_sparc_tdep (void) 02038 { 02039 register_gdbarch_init (bfd_arch_sparc, sparc32_gdbarch_init); 02040 }