GDB (API)
|
00001 /* Target-dependent code for UltraSPARC. 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 "dwarf2-frame.h" 00023 #include "floatformat.h" 00024 #include "frame.h" 00025 #include "frame-base.h" 00026 #include "frame-unwind.h" 00027 #include "gdbcore.h" 00028 #include "gdbtypes.h" 00029 #include "inferior.h" 00030 #include "symtab.h" 00031 #include "objfiles.h" 00032 #include "osabi.h" 00033 #include "regcache.h" 00034 #include "target.h" 00035 #include "value.h" 00036 00037 #include "gdb_assert.h" 00038 #include "gdb_string.h" 00039 00040 #include "sparc64-tdep.h" 00041 00042 /* This file implements the SPARC 64-bit ABI as defined by the 00043 section "Low-Level System Information" of the SPARC Compliance 00044 Definition (SCD) 2.4.1, which is the 64-bit System V psABI for 00045 SPARC. */ 00046 00047 /* Please use the sparc32_-prefix for 32-bit specific code, the 00048 sparc64_-prefix for 64-bit specific code and the sparc_-prefix for 00049 code can handle both. */ 00050 00051 /* The functions on this page are intended to be used to classify 00052 function arguments. */ 00053 00054 /* Check whether TYPE is "Integral or Pointer". */ 00055 00056 static int 00057 sparc64_integral_or_pointer_p (const struct type *type) 00058 { 00059 switch (TYPE_CODE (type)) 00060 { 00061 case TYPE_CODE_INT: 00062 case TYPE_CODE_BOOL: 00063 case TYPE_CODE_CHAR: 00064 case TYPE_CODE_ENUM: 00065 case TYPE_CODE_RANGE: 00066 { 00067 int len = TYPE_LENGTH (type); 00068 gdb_assert (len == 1 || len == 2 || len == 4 || len == 8); 00069 } 00070 return 1; 00071 case TYPE_CODE_PTR: 00072 case TYPE_CODE_REF: 00073 { 00074 int len = TYPE_LENGTH (type); 00075 gdb_assert (len == 8); 00076 } 00077 return 1; 00078 default: 00079 break; 00080 } 00081 00082 return 0; 00083 } 00084 00085 /* Check whether TYPE is "Floating". */ 00086 00087 static int 00088 sparc64_floating_p (const struct type *type) 00089 { 00090 switch (TYPE_CODE (type)) 00091 { 00092 case TYPE_CODE_FLT: 00093 { 00094 int len = TYPE_LENGTH (type); 00095 gdb_assert (len == 4 || len == 8 || len == 16); 00096 } 00097 return 1; 00098 default: 00099 break; 00100 } 00101 00102 return 0; 00103 } 00104 00105 /* Check whether TYPE is "Complex Floating". */ 00106 00107 static int 00108 sparc64_complex_floating_p (const struct type *type) 00109 { 00110 switch (TYPE_CODE (type)) 00111 { 00112 case TYPE_CODE_COMPLEX: 00113 { 00114 int len = TYPE_LENGTH (type); 00115 gdb_assert (len == 8 || len == 16 || len == 32); 00116 } 00117 return 1; 00118 default: 00119 break; 00120 } 00121 00122 return 0; 00123 } 00124 00125 /* Check whether TYPE is "Structure or Union". 00126 00127 In terms of Ada subprogram calls, arrays are treated the same as 00128 struct and union types. So this function also returns non-zero 00129 for array types. */ 00130 00131 static int 00132 sparc64_structure_or_union_p (const struct type *type) 00133 { 00134 switch (TYPE_CODE (type)) 00135 { 00136 case TYPE_CODE_STRUCT: 00137 case TYPE_CODE_UNION: 00138 case TYPE_CODE_ARRAY: 00139 return 1; 00140 default: 00141 break; 00142 } 00143 00144 return 0; 00145 } 00146 00147 00148 /* Construct types for ISA-specific registers. */ 00149 00150 static struct type * 00151 sparc64_pstate_type (struct gdbarch *gdbarch) 00152 { 00153 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); 00154 00155 if (!tdep->sparc64_pstate_type) 00156 { 00157 struct type *type; 00158 00159 type = arch_flags_type (gdbarch, "builtin_type_sparc64_pstate", 8); 00160 append_flags_type_flag (type, 0, "AG"); 00161 append_flags_type_flag (type, 1, "IE"); 00162 append_flags_type_flag (type, 2, "PRIV"); 00163 append_flags_type_flag (type, 3, "AM"); 00164 append_flags_type_flag (type, 4, "PEF"); 00165 append_flags_type_flag (type, 5, "RED"); 00166 append_flags_type_flag (type, 8, "TLE"); 00167 append_flags_type_flag (type, 9, "CLE"); 00168 append_flags_type_flag (type, 10, "PID0"); 00169 append_flags_type_flag (type, 11, "PID1"); 00170 00171 tdep->sparc64_pstate_type = type; 00172 } 00173 00174 return tdep->sparc64_pstate_type; 00175 } 00176 00177 static struct type * 00178 sparc64_fsr_type (struct gdbarch *gdbarch) 00179 { 00180 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); 00181 00182 if (!tdep->sparc64_fsr_type) 00183 { 00184 struct type *type; 00185 00186 type = arch_flags_type (gdbarch, "builtin_type_sparc64_fsr", 8); 00187 append_flags_type_flag (type, 0, "NXA"); 00188 append_flags_type_flag (type, 1, "DZA"); 00189 append_flags_type_flag (type, 2, "UFA"); 00190 append_flags_type_flag (type, 3, "OFA"); 00191 append_flags_type_flag (type, 4, "NVA"); 00192 append_flags_type_flag (type, 5, "NXC"); 00193 append_flags_type_flag (type, 6, "DZC"); 00194 append_flags_type_flag (type, 7, "UFC"); 00195 append_flags_type_flag (type, 8, "OFC"); 00196 append_flags_type_flag (type, 9, "NVC"); 00197 append_flags_type_flag (type, 22, "NS"); 00198 append_flags_type_flag (type, 23, "NXM"); 00199 append_flags_type_flag (type, 24, "DZM"); 00200 append_flags_type_flag (type, 25, "UFM"); 00201 append_flags_type_flag (type, 26, "OFM"); 00202 append_flags_type_flag (type, 27, "NVM"); 00203 00204 tdep->sparc64_fsr_type = type; 00205 } 00206 00207 return tdep->sparc64_fsr_type; 00208 } 00209 00210 static struct type * 00211 sparc64_fprs_type (struct gdbarch *gdbarch) 00212 { 00213 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); 00214 00215 if (!tdep->sparc64_fprs_type) 00216 { 00217 struct type *type; 00218 00219 type = arch_flags_type (gdbarch, "builtin_type_sparc64_fprs", 8); 00220 append_flags_type_flag (type, 0, "DL"); 00221 append_flags_type_flag (type, 1, "DU"); 00222 append_flags_type_flag (type, 2, "FEF"); 00223 00224 tdep->sparc64_fprs_type = type; 00225 } 00226 00227 return tdep->sparc64_fprs_type; 00228 } 00229 00230 00231 /* Register information. */ 00232 00233 static const char *sparc64_register_names[] = 00234 { 00235 "g0", "g1", "g2", "g3", "g4", "g5", "g6", "g7", 00236 "o0", "o1", "o2", "o3", "o4", "o5", "sp", "o7", 00237 "l0", "l1", "l2", "l3", "l4", "l5", "l6", "l7", 00238 "i0", "i1", "i2", "i3", "i4", "i5", "fp", "i7", 00239 00240 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", 00241 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", 00242 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23", 00243 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", 00244 "f32", "f34", "f36", "f38", "f40", "f42", "f44", "f46", 00245 "f48", "f50", "f52", "f54", "f56", "f58", "f60", "f62", 00246 00247 "pc", "npc", 00248 00249 /* FIXME: Give "state" a name until we start using register groups. */ 00250 "state", 00251 "fsr", 00252 "fprs", 00253 "y", 00254 }; 00255 00256 /* Total number of registers. */ 00257 #define SPARC64_NUM_REGS ARRAY_SIZE (sparc64_register_names) 00258 00259 /* We provide the aliases %d0..%d62 and %q0..%q60 for the floating 00260 registers as "psuedo" registers. */ 00261 00262 static const char *sparc64_pseudo_register_names[] = 00263 { 00264 "cwp", "pstate", "asi", "ccr", 00265 00266 "d0", "d2", "d4", "d6", "d8", "d10", "d12", "d14", 00267 "d16", "d18", "d20", "d22", "d24", "d26", "d28", "d30", 00268 "d32", "d34", "d36", "d38", "d40", "d42", "d44", "d46", 00269 "d48", "d50", "d52", "d54", "d56", "d58", "d60", "d62", 00270 00271 "q0", "q4", "q8", "q12", "q16", "q20", "q24", "q28", 00272 "q32", "q36", "q40", "q44", "q48", "q52", "q56", "q60", 00273 }; 00274 00275 /* Total number of pseudo registers. */ 00276 #define SPARC64_NUM_PSEUDO_REGS ARRAY_SIZE (sparc64_pseudo_register_names) 00277 00278 /* Return the name of register REGNUM. */ 00279 00280 static const char * 00281 sparc64_register_name (struct gdbarch *gdbarch, int regnum) 00282 { 00283 if (regnum >= 0 && regnum < SPARC64_NUM_REGS) 00284 return sparc64_register_names[regnum]; 00285 00286 if (regnum >= SPARC64_NUM_REGS 00287 && regnum < SPARC64_NUM_REGS + SPARC64_NUM_PSEUDO_REGS) 00288 return sparc64_pseudo_register_names[regnum - SPARC64_NUM_REGS]; 00289 00290 return NULL; 00291 } 00292 00293 /* Return the GDB type object for the "standard" data type of data in 00294 register REGNUM. */ 00295 00296 static struct type * 00297 sparc64_register_type (struct gdbarch *gdbarch, int regnum) 00298 { 00299 /* Raw registers. */ 00300 00301 if (regnum == SPARC_SP_REGNUM || regnum == SPARC_FP_REGNUM) 00302 return builtin_type (gdbarch)->builtin_data_ptr; 00303 if (regnum >= SPARC_G0_REGNUM && regnum <= SPARC_I7_REGNUM) 00304 return builtin_type (gdbarch)->builtin_int64; 00305 if (regnum >= SPARC_F0_REGNUM && regnum <= SPARC_F31_REGNUM) 00306 return builtin_type (gdbarch)->builtin_float; 00307 if (regnum >= SPARC64_F32_REGNUM && regnum <= SPARC64_F62_REGNUM) 00308 return builtin_type (gdbarch)->builtin_double; 00309 if (regnum == SPARC64_PC_REGNUM || regnum == SPARC64_NPC_REGNUM) 00310 return builtin_type (gdbarch)->builtin_func_ptr; 00311 /* This raw register contains the contents of %cwp, %pstate, %asi 00312 and %ccr as laid out in a %tstate register. */ 00313 if (regnum == SPARC64_STATE_REGNUM) 00314 return builtin_type (gdbarch)->builtin_int64; 00315 if (regnum == SPARC64_FSR_REGNUM) 00316 return sparc64_fsr_type (gdbarch); 00317 if (regnum == SPARC64_FPRS_REGNUM) 00318 return sparc64_fprs_type (gdbarch); 00319 /* "Although Y is a 64-bit register, its high-order 32 bits are 00320 reserved and always read as 0." */ 00321 if (regnum == SPARC64_Y_REGNUM) 00322 return builtin_type (gdbarch)->builtin_int64; 00323 00324 /* Pseudo registers. */ 00325 00326 if (regnum == SPARC64_CWP_REGNUM) 00327 return builtin_type (gdbarch)->builtin_int64; 00328 if (regnum == SPARC64_PSTATE_REGNUM) 00329 return sparc64_pstate_type (gdbarch); 00330 if (regnum == SPARC64_ASI_REGNUM) 00331 return builtin_type (gdbarch)->builtin_int64; 00332 if (regnum == SPARC64_CCR_REGNUM) 00333 return builtin_type (gdbarch)->builtin_int64; 00334 if (regnum >= SPARC64_D0_REGNUM && regnum <= SPARC64_D62_REGNUM) 00335 return builtin_type (gdbarch)->builtin_double; 00336 if (regnum >= SPARC64_Q0_REGNUM && regnum <= SPARC64_Q60_REGNUM) 00337 return builtin_type (gdbarch)->builtin_long_double; 00338 00339 internal_error (__FILE__, __LINE__, _("invalid regnum")); 00340 } 00341 00342 static enum register_status 00343 sparc64_pseudo_register_read (struct gdbarch *gdbarch, 00344 struct regcache *regcache, 00345 int regnum, gdb_byte *buf) 00346 { 00347 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 00348 enum register_status status; 00349 00350 gdb_assert (regnum >= SPARC64_NUM_REGS); 00351 00352 if (regnum >= SPARC64_D0_REGNUM && regnum <= SPARC64_D30_REGNUM) 00353 { 00354 regnum = SPARC_F0_REGNUM + 2 * (regnum - SPARC64_D0_REGNUM); 00355 status = regcache_raw_read (regcache, regnum, buf); 00356 if (status == REG_VALID) 00357 status = regcache_raw_read (regcache, regnum + 1, buf + 4); 00358 return status; 00359 } 00360 else if (regnum >= SPARC64_D32_REGNUM && regnum <= SPARC64_D62_REGNUM) 00361 { 00362 regnum = SPARC64_F32_REGNUM + (regnum - SPARC64_D32_REGNUM); 00363 return regcache_raw_read (regcache, regnum, buf); 00364 } 00365 else if (regnum >= SPARC64_Q0_REGNUM && regnum <= SPARC64_Q28_REGNUM) 00366 { 00367 regnum = SPARC_F0_REGNUM + 4 * (regnum - SPARC64_Q0_REGNUM); 00368 00369 status = regcache_raw_read (regcache, regnum, buf); 00370 if (status == REG_VALID) 00371 status = regcache_raw_read (regcache, regnum + 1, buf + 4); 00372 if (status == REG_VALID) 00373 status = regcache_raw_read (regcache, regnum + 2, buf + 8); 00374 if (status == REG_VALID) 00375 status = regcache_raw_read (regcache, regnum + 3, buf + 12); 00376 00377 return status; 00378 } 00379 else if (regnum >= SPARC64_Q32_REGNUM && regnum <= SPARC64_Q60_REGNUM) 00380 { 00381 regnum = SPARC64_F32_REGNUM + 2 * (regnum - SPARC64_Q32_REGNUM); 00382 00383 status = regcache_raw_read (regcache, regnum, buf); 00384 if (status == REG_VALID) 00385 status = regcache_raw_read (regcache, regnum + 1, buf + 8); 00386 00387 return status; 00388 } 00389 else if (regnum == SPARC64_CWP_REGNUM 00390 || regnum == SPARC64_PSTATE_REGNUM 00391 || regnum == SPARC64_ASI_REGNUM 00392 || regnum == SPARC64_CCR_REGNUM) 00393 { 00394 ULONGEST state; 00395 00396 status = regcache_raw_read_unsigned (regcache, SPARC64_STATE_REGNUM, &state); 00397 if (status != REG_VALID) 00398 return status; 00399 00400 switch (regnum) 00401 { 00402 case SPARC64_CWP_REGNUM: 00403 state = (state >> 0) & ((1 << 5) - 1); 00404 break; 00405 case SPARC64_PSTATE_REGNUM: 00406 state = (state >> 8) & ((1 << 12) - 1); 00407 break; 00408 case SPARC64_ASI_REGNUM: 00409 state = (state >> 24) & ((1 << 8) - 1); 00410 break; 00411 case SPARC64_CCR_REGNUM: 00412 state = (state >> 32) & ((1 << 8) - 1); 00413 break; 00414 } 00415 store_unsigned_integer (buf, 8, byte_order, state); 00416 } 00417 00418 return REG_VALID; 00419 } 00420 00421 static void 00422 sparc64_pseudo_register_write (struct gdbarch *gdbarch, 00423 struct regcache *regcache, 00424 int regnum, const gdb_byte *buf) 00425 { 00426 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 00427 gdb_assert (regnum >= SPARC64_NUM_REGS); 00428 00429 if (regnum >= SPARC64_D0_REGNUM && regnum <= SPARC64_D30_REGNUM) 00430 { 00431 regnum = SPARC_F0_REGNUM + 2 * (regnum - SPARC64_D0_REGNUM); 00432 regcache_raw_write (regcache, regnum, buf); 00433 regcache_raw_write (regcache, regnum + 1, buf + 4); 00434 } 00435 else if (regnum >= SPARC64_D32_REGNUM && regnum <= SPARC64_D62_REGNUM) 00436 { 00437 regnum = SPARC64_F32_REGNUM + (regnum - SPARC64_D32_REGNUM); 00438 regcache_raw_write (regcache, regnum, buf); 00439 } 00440 else if (regnum >= SPARC64_Q0_REGNUM && regnum <= SPARC64_Q28_REGNUM) 00441 { 00442 regnum = SPARC_F0_REGNUM + 4 * (regnum - SPARC64_Q0_REGNUM); 00443 regcache_raw_write (regcache, regnum, buf); 00444 regcache_raw_write (regcache, regnum + 1, buf + 4); 00445 regcache_raw_write (regcache, regnum + 2, buf + 8); 00446 regcache_raw_write (regcache, regnum + 3, buf + 12); 00447 } 00448 else if (regnum >= SPARC64_Q32_REGNUM && regnum <= SPARC64_Q60_REGNUM) 00449 { 00450 regnum = SPARC64_F32_REGNUM + 2 * (regnum - SPARC64_Q32_REGNUM); 00451 regcache_raw_write (regcache, regnum, buf); 00452 regcache_raw_write (regcache, regnum + 1, buf + 8); 00453 } 00454 else if (regnum == SPARC64_CWP_REGNUM 00455 || regnum == SPARC64_PSTATE_REGNUM 00456 || regnum == SPARC64_ASI_REGNUM 00457 || regnum == SPARC64_CCR_REGNUM) 00458 { 00459 ULONGEST state, bits; 00460 00461 regcache_raw_read_unsigned (regcache, SPARC64_STATE_REGNUM, &state); 00462 bits = extract_unsigned_integer (buf, 8, byte_order); 00463 switch (regnum) 00464 { 00465 case SPARC64_CWP_REGNUM: 00466 state |= ((bits & ((1 << 5) - 1)) << 0); 00467 break; 00468 case SPARC64_PSTATE_REGNUM: 00469 state |= ((bits & ((1 << 12) - 1)) << 8); 00470 break; 00471 case SPARC64_ASI_REGNUM: 00472 state |= ((bits & ((1 << 8) - 1)) << 24); 00473 break; 00474 case SPARC64_CCR_REGNUM: 00475 state |= ((bits & ((1 << 8) - 1)) << 32); 00476 break; 00477 } 00478 regcache_raw_write_unsigned (regcache, SPARC64_STATE_REGNUM, state); 00479 } 00480 } 00481 00482 00483 /* Return PC of first real instruction of the function starting at 00484 START_PC. */ 00485 00486 static CORE_ADDR 00487 sparc64_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc) 00488 { 00489 struct symtab_and_line sal; 00490 CORE_ADDR func_start, func_end; 00491 struct sparc_frame_cache cache; 00492 00493 /* This is the preferred method, find the end of the prologue by 00494 using the debugging information. */ 00495 if (find_pc_partial_function (start_pc, NULL, &func_start, &func_end)) 00496 { 00497 sal = find_pc_line (func_start, 0); 00498 00499 if (sal.end < func_end 00500 && start_pc <= sal.end) 00501 return sal.end; 00502 } 00503 00504 return sparc_analyze_prologue (gdbarch, start_pc, 0xffffffffffffffffULL, 00505 &cache); 00506 } 00507 00508 /* Normal frames. */ 00509 00510 static struct sparc_frame_cache * 00511 sparc64_frame_cache (struct frame_info *this_frame, void **this_cache) 00512 { 00513 return sparc_frame_cache (this_frame, this_cache); 00514 } 00515 00516 static void 00517 sparc64_frame_this_id (struct frame_info *this_frame, void **this_cache, 00518 struct frame_id *this_id) 00519 { 00520 struct sparc_frame_cache *cache = 00521 sparc64_frame_cache (this_frame, this_cache); 00522 00523 /* This marks the outermost frame. */ 00524 if (cache->base == 0) 00525 return; 00526 00527 (*this_id) = frame_id_build (cache->base, cache->pc); 00528 } 00529 00530 static struct value * 00531 sparc64_frame_prev_register (struct frame_info *this_frame, void **this_cache, 00532 int regnum) 00533 { 00534 struct gdbarch *gdbarch = get_frame_arch (this_frame); 00535 struct sparc_frame_cache *cache = 00536 sparc64_frame_cache (this_frame, this_cache); 00537 00538 if (regnum == SPARC64_PC_REGNUM || regnum == SPARC64_NPC_REGNUM) 00539 { 00540 CORE_ADDR pc = (regnum == SPARC64_NPC_REGNUM) ? 4 : 0; 00541 00542 regnum = 00543 (cache->copied_regs_mask & 0x80) ? SPARC_I7_REGNUM : SPARC_O7_REGNUM; 00544 pc += get_frame_register_unsigned (this_frame, regnum) + 8; 00545 return frame_unwind_got_constant (this_frame, regnum, pc); 00546 } 00547 00548 /* Handle StackGhost. */ 00549 { 00550 ULONGEST wcookie = sparc_fetch_wcookie (gdbarch); 00551 00552 if (wcookie != 0 && !cache->frameless_p && regnum == SPARC_I7_REGNUM) 00553 { 00554 CORE_ADDR addr = cache->base + (regnum - SPARC_L0_REGNUM) * 8; 00555 ULONGEST i7; 00556 00557 /* Read the value in from memory. */ 00558 i7 = get_frame_memory_unsigned (this_frame, addr, 8); 00559 return frame_unwind_got_constant (this_frame, regnum, i7 ^ wcookie); 00560 } 00561 } 00562 00563 /* The previous frame's `local' and `in' registers may have been saved 00564 in the register save area. */ 00565 if (regnum >= SPARC_L0_REGNUM && regnum <= SPARC_I7_REGNUM 00566 && (cache->saved_regs_mask & (1 << (regnum - SPARC_L0_REGNUM)))) 00567 { 00568 CORE_ADDR addr = cache->base + (regnum - SPARC_L0_REGNUM) * 8; 00569 00570 return frame_unwind_got_memory (this_frame, regnum, addr); 00571 } 00572 00573 /* The previous frame's `out' registers may be accessible as the current 00574 frame's `in' registers. */ 00575 if (regnum >= SPARC_O0_REGNUM && regnum <= SPARC_O7_REGNUM 00576 && (cache->copied_regs_mask & (1 << (regnum - SPARC_O0_REGNUM)))) 00577 regnum += (SPARC_I0_REGNUM - SPARC_O0_REGNUM); 00578 00579 return frame_unwind_got_register (this_frame, regnum, regnum); 00580 } 00581 00582 static const struct frame_unwind sparc64_frame_unwind = 00583 { 00584 NORMAL_FRAME, 00585 default_frame_unwind_stop_reason, 00586 sparc64_frame_this_id, 00587 sparc64_frame_prev_register, 00588 NULL, 00589 default_frame_sniffer 00590 }; 00591 00592 00593 static CORE_ADDR 00594 sparc64_frame_base_address (struct frame_info *this_frame, void **this_cache) 00595 { 00596 struct sparc_frame_cache *cache = 00597 sparc64_frame_cache (this_frame, this_cache); 00598 00599 return cache->base; 00600 } 00601 00602 static const struct frame_base sparc64_frame_base = 00603 { 00604 &sparc64_frame_unwind, 00605 sparc64_frame_base_address, 00606 sparc64_frame_base_address, 00607 sparc64_frame_base_address 00608 }; 00609 00610 /* Check whether TYPE must be 16-byte aligned. */ 00611 00612 static int 00613 sparc64_16_byte_align_p (struct type *type) 00614 { 00615 if (sparc64_floating_p (type) && TYPE_LENGTH (type) == 16) 00616 return 1; 00617 00618 if (sparc64_structure_or_union_p (type)) 00619 { 00620 int i; 00621 00622 for (i = 0; i < TYPE_NFIELDS (type); i++) 00623 { 00624 struct type *subtype = check_typedef (TYPE_FIELD_TYPE (type, i)); 00625 00626 if (sparc64_16_byte_align_p (subtype)) 00627 return 1; 00628 } 00629 } 00630 00631 return 0; 00632 } 00633 00634 /* Store floating fields of element ELEMENT of an "parameter array" 00635 that has type TYPE and is stored at BITPOS in VALBUF in the 00636 apropriate registers of REGCACHE. This function can be called 00637 recursively and therefore handles floating types in addition to 00638 structures. */ 00639 00640 static void 00641 sparc64_store_floating_fields (struct regcache *regcache, struct type *type, 00642 const gdb_byte *valbuf, int element, int bitpos) 00643 { 00644 int len = TYPE_LENGTH (type); 00645 00646 gdb_assert (element < 16); 00647 00648 if (sparc64_floating_p (type) 00649 || (sparc64_complex_floating_p (type) && len <= 16)) 00650 { 00651 int regnum; 00652 00653 if (len == 16) 00654 { 00655 gdb_assert (bitpos == 0); 00656 gdb_assert ((element % 2) == 0); 00657 00658 regnum = SPARC64_Q0_REGNUM + element / 2; 00659 regcache_cooked_write (regcache, regnum, valbuf); 00660 } 00661 else if (len == 8) 00662 { 00663 gdb_assert (bitpos == 0 || bitpos == 64); 00664 00665 regnum = SPARC64_D0_REGNUM + element + bitpos / 64; 00666 regcache_cooked_write (regcache, regnum, valbuf + (bitpos / 8)); 00667 } 00668 else 00669 { 00670 gdb_assert (len == 4); 00671 gdb_assert (bitpos % 32 == 0 && bitpos >= 0 && bitpos < 128); 00672 00673 regnum = SPARC_F0_REGNUM + element * 2 + bitpos / 32; 00674 regcache_cooked_write (regcache, regnum, valbuf + (bitpos / 8)); 00675 } 00676 } 00677 else if (sparc64_structure_or_union_p (type)) 00678 { 00679 int i; 00680 00681 for (i = 0; i < TYPE_NFIELDS (type); i++) 00682 { 00683 struct type *subtype = check_typedef (TYPE_FIELD_TYPE (type, i)); 00684 int subpos = bitpos + TYPE_FIELD_BITPOS (type, i); 00685 00686 sparc64_store_floating_fields (regcache, subtype, valbuf, 00687 element, subpos); 00688 } 00689 00690 /* GCC has an interesting bug. If TYPE is a structure that has 00691 a single `float' member, GCC doesn't treat it as a structure 00692 at all, but rather as an ordinary `float' argument. This 00693 argument will be stored in %f1, as required by the psABI. 00694 However, as a member of a structure the psABI requires it to 00695 be stored in %f0. This bug is present in GCC 3.3.2, but 00696 probably in older releases to. To appease GCC, if a 00697 structure has only a single `float' member, we store its 00698 value in %f1 too (we already have stored in %f0). */ 00699 if (TYPE_NFIELDS (type) == 1) 00700 { 00701 struct type *subtype = check_typedef (TYPE_FIELD_TYPE (type, 0)); 00702 00703 if (sparc64_floating_p (subtype) && TYPE_LENGTH (subtype) == 4) 00704 regcache_cooked_write (regcache, SPARC_F1_REGNUM, valbuf); 00705 } 00706 } 00707 } 00708 00709 /* Fetch floating fields from a variable of type TYPE from the 00710 appropriate registers for BITPOS in REGCACHE and store it at BITPOS 00711 in VALBUF. This function can be called recursively and therefore 00712 handles floating types in addition to structures. */ 00713 00714 static void 00715 sparc64_extract_floating_fields (struct regcache *regcache, struct type *type, 00716 gdb_byte *valbuf, int bitpos) 00717 { 00718 if (sparc64_floating_p (type)) 00719 { 00720 int len = TYPE_LENGTH (type); 00721 int regnum; 00722 00723 if (len == 16) 00724 { 00725 gdb_assert (bitpos == 0 || bitpos == 128); 00726 00727 regnum = SPARC64_Q0_REGNUM + bitpos / 128; 00728 regcache_cooked_read (regcache, regnum, valbuf + (bitpos / 8)); 00729 } 00730 else if (len == 8) 00731 { 00732 gdb_assert (bitpos % 64 == 0 && bitpos >= 0 && bitpos < 256); 00733 00734 regnum = SPARC64_D0_REGNUM + bitpos / 64; 00735 regcache_cooked_read (regcache, regnum, valbuf + (bitpos / 8)); 00736 } 00737 else 00738 { 00739 gdb_assert (len == 4); 00740 gdb_assert (bitpos % 32 == 0 && bitpos >= 0 && bitpos < 256); 00741 00742 regnum = SPARC_F0_REGNUM + bitpos / 32; 00743 regcache_cooked_read (regcache, regnum, valbuf + (bitpos / 8)); 00744 } 00745 } 00746 else if (sparc64_structure_or_union_p (type)) 00747 { 00748 int i; 00749 00750 for (i = 0; i < TYPE_NFIELDS (type); i++) 00751 { 00752 struct type *subtype = check_typedef (TYPE_FIELD_TYPE (type, i)); 00753 int subpos = bitpos + TYPE_FIELD_BITPOS (type, i); 00754 00755 sparc64_extract_floating_fields (regcache, subtype, valbuf, subpos); 00756 } 00757 } 00758 } 00759 00760 /* Store the NARGS arguments ARGS and STRUCT_ADDR (if STRUCT_RETURN is 00761 non-zero) in REGCACHE and on the stack (starting from address SP). */ 00762 00763 static CORE_ADDR 00764 sparc64_store_arguments (struct regcache *regcache, int nargs, 00765 struct value **args, CORE_ADDR sp, 00766 int struct_return, CORE_ADDR struct_addr) 00767 { 00768 struct gdbarch *gdbarch = get_regcache_arch (regcache); 00769 /* Number of extended words in the "parameter array". */ 00770 int num_elements = 0; 00771 int element = 0; 00772 int i; 00773 00774 /* Take BIAS into account. */ 00775 sp += BIAS; 00776 00777 /* First we calculate the number of extended words in the "parameter 00778 array". While doing so we also convert some of the arguments. */ 00779 00780 if (struct_return) 00781 num_elements++; 00782 00783 for (i = 0; i < nargs; i++) 00784 { 00785 struct type *type = value_type (args[i]); 00786 int len = TYPE_LENGTH (type); 00787 00788 if (sparc64_structure_or_union_p (type) 00789 || (sparc64_complex_floating_p (type) && len == 32)) 00790 { 00791 /* Structure or Union arguments. */ 00792 if (len <= 16) 00793 { 00794 if (num_elements % 2 && sparc64_16_byte_align_p (type)) 00795 num_elements++; 00796 num_elements += ((len + 7) / 8); 00797 } 00798 else 00799 { 00800 /* The psABI says that "Structures or unions larger than 00801 sixteen bytes are copied by the caller and passed 00802 indirectly; the caller will pass the address of a 00803 correctly aligned structure value. This sixty-four 00804 bit address will occupy one word in the parameter 00805 array, and may be promoted to an %o register like any 00806 other pointer value." Allocate memory for these 00807 values on the stack. */ 00808 sp -= len; 00809 00810 /* Use 16-byte alignment for these values. That's 00811 always correct, and wasting a few bytes shouldn't be 00812 a problem. */ 00813 sp &= ~0xf; 00814 00815 write_memory (sp, value_contents (args[i]), len); 00816 args[i] = value_from_pointer (lookup_pointer_type (type), sp); 00817 num_elements++; 00818 } 00819 } 00820 else if (sparc64_floating_p (type) || sparc64_complex_floating_p (type)) 00821 { 00822 /* Floating arguments. */ 00823 if (len == 16) 00824 { 00825 /* The psABI says that "Each quad-precision parameter 00826 value will be assigned to two extended words in the 00827 parameter array. */ 00828 num_elements += 2; 00829 00830 /* The psABI says that "Long doubles must be 00831 quad-aligned, and thus a hole might be introduced 00832 into the parameter array to force alignment." Skip 00833 an element if necessary. */ 00834 if (num_elements % 2) 00835 num_elements++; 00836 } 00837 else 00838 num_elements++; 00839 } 00840 else 00841 { 00842 /* Integral and pointer arguments. */ 00843 gdb_assert (sparc64_integral_or_pointer_p (type)); 00844 00845 /* The psABI says that "Each argument value of integral type 00846 smaller than an extended word will be widened by the 00847 caller to an extended word according to the signed-ness 00848 of the argument type." */ 00849 if (len < 8) 00850 args[i] = value_cast (builtin_type (gdbarch)->builtin_int64, 00851 args[i]); 00852 num_elements++; 00853 } 00854 } 00855 00856 /* Allocate the "parameter array". */ 00857 sp -= num_elements * 8; 00858 00859 /* The psABI says that "Every stack frame must be 16-byte aligned." */ 00860 sp &= ~0xf; 00861 00862 /* Now we store the arguments in to the "paramater array". Some 00863 Integer or Pointer arguments and Structure or Union arguments 00864 will be passed in %o registers. Some Floating arguments and 00865 floating members of structures are passed in floating-point 00866 registers. However, for functions with variable arguments, 00867 floating arguments are stored in an %0 register, and for 00868 functions without a prototype floating arguments are stored in 00869 both a floating-point and an %o registers, or a floating-point 00870 register and memory. To simplify the logic here we always pass 00871 arguments in memory, an %o register, and a floating-point 00872 register if appropriate. This should be no problem since the 00873 contents of any unused memory or registers in the "parameter 00874 array" are undefined. */ 00875 00876 if (struct_return) 00877 { 00878 regcache_cooked_write_unsigned (regcache, SPARC_O0_REGNUM, struct_addr); 00879 element++; 00880 } 00881 00882 for (i = 0; i < nargs; i++) 00883 { 00884 const gdb_byte *valbuf = value_contents (args[i]); 00885 struct type *type = value_type (args[i]); 00886 int len = TYPE_LENGTH (type); 00887 int regnum = -1; 00888 gdb_byte buf[16]; 00889 00890 if (sparc64_structure_or_union_p (type) 00891 || (sparc64_complex_floating_p (type) && len == 32)) 00892 { 00893 /* Structure or Union arguments. */ 00894 gdb_assert (len <= 16); 00895 memset (buf, 0, sizeof (buf)); 00896 valbuf = memcpy (buf, valbuf, len); 00897 00898 if (element % 2 && sparc64_16_byte_align_p (type)) 00899 element++; 00900 00901 if (element < 6) 00902 { 00903 regnum = SPARC_O0_REGNUM + element; 00904 if (len > 8 && element < 5) 00905 regcache_cooked_write (regcache, regnum + 1, valbuf + 8); 00906 } 00907 00908 if (element < 16) 00909 sparc64_store_floating_fields (regcache, type, valbuf, element, 0); 00910 } 00911 else if (sparc64_floating_p (type) || sparc64_complex_floating_p (type)) 00912 { 00913 /* Floating arguments. */ 00914 if (len == 16) 00915 { 00916 if (element % 2) 00917 element++; 00918 if (element < 16) 00919 regnum = SPARC64_Q0_REGNUM + element / 2; 00920 } 00921 else if (len == 8) 00922 { 00923 if (element < 16) 00924 regnum = SPARC64_D0_REGNUM + element; 00925 } 00926 else if (len == 4) 00927 { 00928 /* The psABI says "Each single-precision parameter value 00929 will be assigned to one extended word in the 00930 parameter array, and right-justified within that 00931 word; the left half (even float register) is 00932 undefined." Even though the psABI says that "the 00933 left half is undefined", set it to zero here. */ 00934 memset (buf, 0, 4); 00935 memcpy (buf + 4, valbuf, 4); 00936 valbuf = buf; 00937 len = 8; 00938 if (element < 16) 00939 regnum = SPARC64_D0_REGNUM + element; 00940 } 00941 } 00942 else 00943 { 00944 /* Integral and pointer arguments. */ 00945 gdb_assert (len == 8); 00946 if (element < 6) 00947 regnum = SPARC_O0_REGNUM + element; 00948 } 00949 00950 if (regnum != -1) 00951 { 00952 regcache_cooked_write (regcache, regnum, valbuf); 00953 00954 /* If we're storing the value in a floating-point register, 00955 also store it in the corresponding %0 register(s). */ 00956 if (regnum >= SPARC64_D0_REGNUM && regnum <= SPARC64_D10_REGNUM) 00957 { 00958 gdb_assert (element < 6); 00959 regnum = SPARC_O0_REGNUM + element; 00960 regcache_cooked_write (regcache, regnum, valbuf); 00961 } 00962 else if (regnum >= SPARC64_Q0_REGNUM && regnum <= SPARC64_Q8_REGNUM) 00963 { 00964 gdb_assert (element < 5); 00965 regnum = SPARC_O0_REGNUM + element; 00966 regcache_cooked_write (regcache, regnum, valbuf); 00967 regcache_cooked_write (regcache, regnum + 1, valbuf + 8); 00968 } 00969 } 00970 00971 /* Always store the argument in memory. */ 00972 write_memory (sp + element * 8, valbuf, len); 00973 element += ((len + 7) / 8); 00974 } 00975 00976 gdb_assert (element == num_elements); 00977 00978 /* Take BIAS into account. */ 00979 sp -= BIAS; 00980 return sp; 00981 } 00982 00983 static CORE_ADDR 00984 sparc64_frame_align (struct gdbarch *gdbarch, CORE_ADDR address) 00985 { 00986 /* The ABI requires 16-byte alignment. */ 00987 return address & ~0xf; 00988 } 00989 00990 static CORE_ADDR 00991 sparc64_push_dummy_call (struct gdbarch *gdbarch, struct value *function, 00992 struct regcache *regcache, CORE_ADDR bp_addr, 00993 int nargs, struct value **args, CORE_ADDR sp, 00994 int struct_return, CORE_ADDR struct_addr) 00995 { 00996 /* Set return address. */ 00997 regcache_cooked_write_unsigned (regcache, SPARC_O7_REGNUM, bp_addr - 8); 00998 00999 /* Set up function arguments. */ 01000 sp = sparc64_store_arguments (regcache, nargs, args, sp, 01001 struct_return, struct_addr); 01002 01003 /* Allocate the register save area. */ 01004 sp -= 16 * 8; 01005 01006 /* Stack should be 16-byte aligned at this point. */ 01007 gdb_assert ((sp + BIAS) % 16 == 0); 01008 01009 /* Finally, update the stack pointer. */ 01010 regcache_cooked_write_unsigned (regcache, SPARC_SP_REGNUM, sp); 01011 01012 return sp + BIAS; 01013 } 01014 01015 01016 /* Extract from an array REGBUF containing the (raw) register state, a 01017 function return value of TYPE, and copy that into VALBUF. */ 01018 01019 static void 01020 sparc64_extract_return_value (struct type *type, struct regcache *regcache, 01021 gdb_byte *valbuf) 01022 { 01023 int len = TYPE_LENGTH (type); 01024 gdb_byte buf[32]; 01025 int i; 01026 01027 if (sparc64_structure_or_union_p (type)) 01028 { 01029 /* Structure or Union return values. */ 01030 gdb_assert (len <= 32); 01031 01032 for (i = 0; i < ((len + 7) / 8); i++) 01033 regcache_cooked_read (regcache, SPARC_O0_REGNUM + i, buf + i * 8); 01034 if (TYPE_CODE (type) != TYPE_CODE_UNION) 01035 sparc64_extract_floating_fields (regcache, type, buf, 0); 01036 memcpy (valbuf, buf, len); 01037 } 01038 else if (sparc64_floating_p (type) || sparc64_complex_floating_p (type)) 01039 { 01040 /* Floating return values. */ 01041 for (i = 0; i < len / 4; i++) 01042 regcache_cooked_read (regcache, SPARC_F0_REGNUM + i, buf + i * 4); 01043 memcpy (valbuf, buf, len); 01044 } 01045 else if (TYPE_CODE (type) == TYPE_CODE_ARRAY) 01046 { 01047 /* Small arrays are returned the same way as small structures. */ 01048 gdb_assert (len <= 32); 01049 01050 for (i = 0; i < ((len + 7) / 8); i++) 01051 regcache_cooked_read (regcache, SPARC_O0_REGNUM + i, buf + i * 8); 01052 memcpy (valbuf, buf, len); 01053 } 01054 else 01055 { 01056 /* Integral and pointer return values. */ 01057 gdb_assert (sparc64_integral_or_pointer_p (type)); 01058 01059 /* Just stripping off any unused bytes should preserve the 01060 signed-ness just fine. */ 01061 regcache_cooked_read (regcache, SPARC_O0_REGNUM, buf); 01062 memcpy (valbuf, buf + 8 - len, len); 01063 } 01064 } 01065 01066 /* Write into the appropriate registers a function return value stored 01067 in VALBUF of type TYPE. */ 01068 01069 static void 01070 sparc64_store_return_value (struct type *type, struct regcache *regcache, 01071 const gdb_byte *valbuf) 01072 { 01073 int len = TYPE_LENGTH (type); 01074 gdb_byte buf[16]; 01075 int i; 01076 01077 if (sparc64_structure_or_union_p (type)) 01078 { 01079 /* Structure or Union return values. */ 01080 gdb_assert (len <= 32); 01081 01082 /* Simplify matters by storing the complete value (including 01083 floating members) into %o0 and %o1. Floating members are 01084 also store in the appropriate floating-point registers. */ 01085 memset (buf, 0, sizeof (buf)); 01086 memcpy (buf, valbuf, len); 01087 for (i = 0; i < ((len + 7) / 8); i++) 01088 regcache_cooked_write (regcache, SPARC_O0_REGNUM + i, buf + i * 8); 01089 if (TYPE_CODE (type) != TYPE_CODE_UNION) 01090 sparc64_store_floating_fields (regcache, type, buf, 0, 0); 01091 } 01092 else if (sparc64_floating_p (type) || sparc64_complex_floating_p (type)) 01093 { 01094 /* Floating return values. */ 01095 memcpy (buf, valbuf, len); 01096 for (i = 0; i < len / 4; i++) 01097 regcache_cooked_write (regcache, SPARC_F0_REGNUM + i, buf + i * 4); 01098 } 01099 else if (TYPE_CODE (type) == TYPE_CODE_ARRAY) 01100 { 01101 /* Small arrays are returned the same way as small structures. */ 01102 gdb_assert (len <= 32); 01103 01104 memset (buf, 0, sizeof (buf)); 01105 memcpy (buf, valbuf, len); 01106 for (i = 0; i < ((len + 7) / 8); i++) 01107 regcache_cooked_write (regcache, SPARC_O0_REGNUM + i, buf + i * 8); 01108 } 01109 else 01110 { 01111 /* Integral and pointer return values. */ 01112 gdb_assert (sparc64_integral_or_pointer_p (type)); 01113 01114 /* ??? Do we need to do any sign-extension here? */ 01115 memset (buf, 0, 8); 01116 memcpy (buf + 8 - len, valbuf, len); 01117 regcache_cooked_write (regcache, SPARC_O0_REGNUM, buf); 01118 } 01119 } 01120 01121 static enum return_value_convention 01122 sparc64_return_value (struct gdbarch *gdbarch, struct value *function, 01123 struct type *type, struct regcache *regcache, 01124 gdb_byte *readbuf, const gdb_byte *writebuf) 01125 { 01126 if (TYPE_LENGTH (type) > 32) 01127 return RETURN_VALUE_STRUCT_CONVENTION; 01128 01129 if (readbuf) 01130 sparc64_extract_return_value (type, regcache, readbuf); 01131 if (writebuf) 01132 sparc64_store_return_value (type, regcache, writebuf); 01133 01134 return RETURN_VALUE_REGISTER_CONVENTION; 01135 } 01136 01137 01138 static void 01139 sparc64_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum, 01140 struct dwarf2_frame_state_reg *reg, 01141 struct frame_info *this_frame) 01142 { 01143 switch (regnum) 01144 { 01145 case SPARC_G0_REGNUM: 01146 /* Since %g0 is always zero, there is no point in saving it, and 01147 people will be inclined omit it from the CFI. Make sure we 01148 don't warn about that. */ 01149 reg->how = DWARF2_FRAME_REG_SAME_VALUE; 01150 break; 01151 case SPARC_SP_REGNUM: 01152 reg->how = DWARF2_FRAME_REG_CFA; 01153 break; 01154 case SPARC64_PC_REGNUM: 01155 reg->how = DWARF2_FRAME_REG_RA_OFFSET; 01156 reg->loc.offset = 8; 01157 break; 01158 case SPARC64_NPC_REGNUM: 01159 reg->how = DWARF2_FRAME_REG_RA_OFFSET; 01160 reg->loc.offset = 12; 01161 break; 01162 } 01163 } 01164 01165 void 01166 sparc64_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) 01167 { 01168 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); 01169 01170 tdep->pc_regnum = SPARC64_PC_REGNUM; 01171 tdep->npc_regnum = SPARC64_NPC_REGNUM; 01172 01173 /* This is what all the fuss is about. */ 01174 set_gdbarch_long_bit (gdbarch, 64); 01175 set_gdbarch_long_long_bit (gdbarch, 64); 01176 set_gdbarch_ptr_bit (gdbarch, 64); 01177 01178 set_gdbarch_num_regs (gdbarch, SPARC64_NUM_REGS); 01179 set_gdbarch_register_name (gdbarch, sparc64_register_name); 01180 set_gdbarch_register_type (gdbarch, sparc64_register_type); 01181 set_gdbarch_num_pseudo_regs (gdbarch, SPARC64_NUM_PSEUDO_REGS); 01182 set_gdbarch_pseudo_register_read (gdbarch, sparc64_pseudo_register_read); 01183 set_gdbarch_pseudo_register_write (gdbarch, sparc64_pseudo_register_write); 01184 01185 /* Register numbers of various important registers. */ 01186 set_gdbarch_pc_regnum (gdbarch, SPARC64_PC_REGNUM); /* %pc */ 01187 01188 /* Call dummy code. */ 01189 set_gdbarch_frame_align (gdbarch, sparc64_frame_align); 01190 set_gdbarch_call_dummy_location (gdbarch, AT_ENTRY_POINT); 01191 set_gdbarch_push_dummy_code (gdbarch, NULL); 01192 set_gdbarch_push_dummy_call (gdbarch, sparc64_push_dummy_call); 01193 01194 set_gdbarch_return_value (gdbarch, sparc64_return_value); 01195 set_gdbarch_stabs_argument_has_addr 01196 (gdbarch, default_stabs_argument_has_addr); 01197 01198 set_gdbarch_skip_prologue (gdbarch, sparc64_skip_prologue); 01199 01200 /* Hook in the DWARF CFI frame unwinder. */ 01201 dwarf2_frame_set_init_reg (gdbarch, sparc64_dwarf2_frame_init_reg); 01202 /* FIXME: kettenis/20050423: Don't enable the unwinder until the 01203 StackGhost issues have been resolved. */ 01204 01205 frame_unwind_append_unwinder (gdbarch, &sparc64_frame_unwind); 01206 frame_base_set_default (gdbarch, &sparc64_frame_base); 01207 } 01208 01209 01210 /* Helper functions for dealing with register sets. */ 01211 01212 #define TSTATE_CWP 0x000000000000001fULL 01213 #define TSTATE_ICC 0x0000000f00000000ULL 01214 #define TSTATE_XCC 0x000000f000000000ULL 01215 01216 #define PSR_S 0x00000080 01217 #define PSR_ICC 0x00f00000 01218 #define PSR_VERS 0x0f000000 01219 #define PSR_IMPL 0xf0000000 01220 #define PSR_V8PLUS 0xff000000 01221 #define PSR_XCC 0x000f0000 01222 01223 void 01224 sparc64_supply_gregset (const struct sparc_gregset *gregset, 01225 struct regcache *regcache, 01226 int regnum, const void *gregs) 01227 { 01228 struct gdbarch *gdbarch = get_regcache_arch (regcache); 01229 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 01230 int sparc32 = (gdbarch_ptr_bit (gdbarch) == 32); 01231 const gdb_byte *regs = gregs; 01232 gdb_byte zero[8] = { 0 }; 01233 int i; 01234 01235 if (sparc32) 01236 { 01237 if (regnum == SPARC32_PSR_REGNUM || regnum == -1) 01238 { 01239 int offset = gregset->r_tstate_offset; 01240 ULONGEST tstate, psr; 01241 gdb_byte buf[4]; 01242 01243 tstate = extract_unsigned_integer (regs + offset, 8, byte_order); 01244 psr = ((tstate & TSTATE_CWP) | PSR_S | ((tstate & TSTATE_ICC) >> 12) 01245 | ((tstate & TSTATE_XCC) >> 20) | PSR_V8PLUS); 01246 store_unsigned_integer (buf, 4, byte_order, psr); 01247 regcache_raw_supply (regcache, SPARC32_PSR_REGNUM, buf); 01248 } 01249 01250 if (regnum == SPARC32_PC_REGNUM || regnum == -1) 01251 regcache_raw_supply (regcache, SPARC32_PC_REGNUM, 01252 regs + gregset->r_pc_offset + 4); 01253 01254 if (regnum == SPARC32_NPC_REGNUM || regnum == -1) 01255 regcache_raw_supply (regcache, SPARC32_NPC_REGNUM, 01256 regs + gregset->r_npc_offset + 4); 01257 01258 if (regnum == SPARC32_Y_REGNUM || regnum == -1) 01259 { 01260 int offset = gregset->r_y_offset + 8 - gregset->r_y_size; 01261 regcache_raw_supply (regcache, SPARC32_Y_REGNUM, regs + offset); 01262 } 01263 } 01264 else 01265 { 01266 if (regnum == SPARC64_STATE_REGNUM || regnum == -1) 01267 regcache_raw_supply (regcache, SPARC64_STATE_REGNUM, 01268 regs + gregset->r_tstate_offset); 01269 01270 if (regnum == SPARC64_PC_REGNUM || regnum == -1) 01271 regcache_raw_supply (regcache, SPARC64_PC_REGNUM, 01272 regs + gregset->r_pc_offset); 01273 01274 if (regnum == SPARC64_NPC_REGNUM || regnum == -1) 01275 regcache_raw_supply (regcache, SPARC64_NPC_REGNUM, 01276 regs + gregset->r_npc_offset); 01277 01278 if (regnum == SPARC64_Y_REGNUM || regnum == -1) 01279 { 01280 gdb_byte buf[8]; 01281 01282 memset (buf, 0, 8); 01283 memcpy (buf + 8 - gregset->r_y_size, 01284 regs + gregset->r_y_offset, gregset->r_y_size); 01285 regcache_raw_supply (regcache, SPARC64_Y_REGNUM, buf); 01286 } 01287 01288 if ((regnum == SPARC64_FPRS_REGNUM || regnum == -1) 01289 && gregset->r_fprs_offset != -1) 01290 regcache_raw_supply (regcache, SPARC64_FPRS_REGNUM, 01291 regs + gregset->r_fprs_offset); 01292 } 01293 01294 if (regnum == SPARC_G0_REGNUM || regnum == -1) 01295 regcache_raw_supply (regcache, SPARC_G0_REGNUM, &zero); 01296 01297 if ((regnum >= SPARC_G1_REGNUM && regnum <= SPARC_O7_REGNUM) || regnum == -1) 01298 { 01299 int offset = gregset->r_g1_offset; 01300 01301 if (sparc32) 01302 offset += 4; 01303 01304 for (i = SPARC_G1_REGNUM; i <= SPARC_O7_REGNUM; i++) 01305 { 01306 if (regnum == i || regnum == -1) 01307 regcache_raw_supply (regcache, i, regs + offset); 01308 offset += 8; 01309 } 01310 } 01311 01312 if ((regnum >= SPARC_L0_REGNUM && regnum <= SPARC_I7_REGNUM) || regnum == -1) 01313 { 01314 /* Not all of the register set variants include Locals and 01315 Inputs. For those that don't, we read them off the stack. */ 01316 if (gregset->r_l0_offset == -1) 01317 { 01318 ULONGEST sp; 01319 01320 regcache_cooked_read_unsigned (regcache, SPARC_SP_REGNUM, &sp); 01321 sparc_supply_rwindow (regcache, sp, regnum); 01322 } 01323 else 01324 { 01325 int offset = gregset->r_l0_offset; 01326 01327 if (sparc32) 01328 offset += 4; 01329 01330 for (i = SPARC_L0_REGNUM; i <= SPARC_I7_REGNUM; i++) 01331 { 01332 if (regnum == i || regnum == -1) 01333 regcache_raw_supply (regcache, i, regs + offset); 01334 offset += 8; 01335 } 01336 } 01337 } 01338 } 01339 01340 void 01341 sparc64_collect_gregset (const struct sparc_gregset *gregset, 01342 const struct regcache *regcache, 01343 int regnum, void *gregs) 01344 { 01345 struct gdbarch *gdbarch = get_regcache_arch (regcache); 01346 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 01347 int sparc32 = (gdbarch_ptr_bit (gdbarch) == 32); 01348 gdb_byte *regs = gregs; 01349 int i; 01350 01351 if (sparc32) 01352 { 01353 if (regnum == SPARC32_PSR_REGNUM || regnum == -1) 01354 { 01355 int offset = gregset->r_tstate_offset; 01356 ULONGEST tstate, psr; 01357 gdb_byte buf[8]; 01358 01359 tstate = extract_unsigned_integer (regs + offset, 8, byte_order); 01360 regcache_raw_collect (regcache, SPARC32_PSR_REGNUM, buf); 01361 psr = extract_unsigned_integer (buf, 4, byte_order); 01362 tstate |= (psr & PSR_ICC) << 12; 01363 if ((psr & (PSR_VERS | PSR_IMPL)) == PSR_V8PLUS) 01364 tstate |= (psr & PSR_XCC) << 20; 01365 store_unsigned_integer (buf, 8, byte_order, tstate); 01366 memcpy (regs + offset, buf, 8); 01367 } 01368 01369 if (regnum == SPARC32_PC_REGNUM || regnum == -1) 01370 regcache_raw_collect (regcache, SPARC32_PC_REGNUM, 01371 regs + gregset->r_pc_offset + 4); 01372 01373 if (regnum == SPARC32_NPC_REGNUM || regnum == -1) 01374 regcache_raw_collect (regcache, SPARC32_NPC_REGNUM, 01375 regs + gregset->r_npc_offset + 4); 01376 01377 if (regnum == SPARC32_Y_REGNUM || regnum == -1) 01378 { 01379 int offset = gregset->r_y_offset + 8 - gregset->r_y_size; 01380 regcache_raw_collect (regcache, SPARC32_Y_REGNUM, regs + offset); 01381 } 01382 } 01383 else 01384 { 01385 if (regnum == SPARC64_STATE_REGNUM || regnum == -1) 01386 regcache_raw_collect (regcache, SPARC64_STATE_REGNUM, 01387 regs + gregset->r_tstate_offset); 01388 01389 if (regnum == SPARC64_PC_REGNUM || regnum == -1) 01390 regcache_raw_collect (regcache, SPARC64_PC_REGNUM, 01391 regs + gregset->r_pc_offset); 01392 01393 if (regnum == SPARC64_NPC_REGNUM || regnum == -1) 01394 regcache_raw_collect (regcache, SPARC64_NPC_REGNUM, 01395 regs + gregset->r_npc_offset); 01396 01397 if (regnum == SPARC64_Y_REGNUM || regnum == -1) 01398 { 01399 gdb_byte buf[8]; 01400 01401 regcache_raw_collect (regcache, SPARC64_Y_REGNUM, buf); 01402 memcpy (regs + gregset->r_y_offset, 01403 buf + 8 - gregset->r_y_size, gregset->r_y_size); 01404 } 01405 01406 if ((regnum == SPARC64_FPRS_REGNUM || regnum == -1) 01407 && gregset->r_fprs_offset != -1) 01408 regcache_raw_collect (regcache, SPARC64_FPRS_REGNUM, 01409 regs + gregset->r_fprs_offset); 01410 01411 } 01412 01413 if ((regnum >= SPARC_G1_REGNUM && regnum <= SPARC_O7_REGNUM) || regnum == -1) 01414 { 01415 int offset = gregset->r_g1_offset; 01416 01417 if (sparc32) 01418 offset += 4; 01419 01420 /* %g0 is always zero. */ 01421 for (i = SPARC_G1_REGNUM; i <= SPARC_O7_REGNUM; i++) 01422 { 01423 if (regnum == i || regnum == -1) 01424 regcache_raw_collect (regcache, i, regs + offset); 01425 offset += 8; 01426 } 01427 } 01428 01429 if ((regnum >= SPARC_L0_REGNUM && regnum <= SPARC_I7_REGNUM) || regnum == -1) 01430 { 01431 /* Not all of the register set variants include Locals and 01432 Inputs. For those that don't, we read them off the stack. */ 01433 if (gregset->r_l0_offset != -1) 01434 { 01435 int offset = gregset->r_l0_offset; 01436 01437 if (sparc32) 01438 offset += 4; 01439 01440 for (i = SPARC_L0_REGNUM; i <= SPARC_I7_REGNUM; i++) 01441 { 01442 if (regnum == i || regnum == -1) 01443 regcache_raw_collect (regcache, i, regs + offset); 01444 offset += 8; 01445 } 01446 } 01447 } 01448 } 01449 01450 void 01451 sparc64_supply_fpregset (const struct sparc_fpregset *fpregset, 01452 struct regcache *regcache, 01453 int regnum, const void *fpregs) 01454 { 01455 int sparc32 = (gdbarch_ptr_bit (get_regcache_arch (regcache)) == 32); 01456 const gdb_byte *regs = fpregs; 01457 int i; 01458 01459 for (i = 0; i < 32; i++) 01460 { 01461 if (regnum == (SPARC_F0_REGNUM + i) || regnum == -1) 01462 regcache_raw_supply (regcache, SPARC_F0_REGNUM + i, 01463 regs + fpregset->r_f0_offset + (i * 4)); 01464 } 01465 01466 if (sparc32) 01467 { 01468 if (regnum == SPARC32_FSR_REGNUM || regnum == -1) 01469 regcache_raw_supply (regcache, SPARC32_FSR_REGNUM, 01470 regs + fpregset->r_fsr_offset); 01471 } 01472 else 01473 { 01474 for (i = 0; i < 16; i++) 01475 { 01476 if (regnum == (SPARC64_F32_REGNUM + i) || regnum == -1) 01477 regcache_raw_supply (regcache, SPARC64_F32_REGNUM + i, 01478 (regs + fpregset->r_f0_offset 01479 + (32 * 4) + (i * 8))); 01480 } 01481 01482 if (regnum == SPARC64_FSR_REGNUM || regnum == -1) 01483 regcache_raw_supply (regcache, SPARC64_FSR_REGNUM, 01484 regs + fpregset->r_fsr_offset); 01485 } 01486 } 01487 01488 void 01489 sparc64_collect_fpregset (const struct sparc_fpregset *fpregset, 01490 const struct regcache *regcache, 01491 int regnum, void *fpregs) 01492 { 01493 int sparc32 = (gdbarch_ptr_bit (get_regcache_arch (regcache)) == 32); 01494 gdb_byte *regs = fpregs; 01495 int i; 01496 01497 for (i = 0; i < 32; i++) 01498 { 01499 if (regnum == (SPARC_F0_REGNUM + i) || regnum == -1) 01500 regcache_raw_collect (regcache, SPARC_F0_REGNUM + i, 01501 regs + fpregset->r_f0_offset + (i * 4)); 01502 } 01503 01504 if (sparc32) 01505 { 01506 if (regnum == SPARC32_FSR_REGNUM || regnum == -1) 01507 regcache_raw_collect (regcache, SPARC32_FSR_REGNUM, 01508 regs + fpregset->r_fsr_offset); 01509 } 01510 else 01511 { 01512 for (i = 0; i < 16; i++) 01513 { 01514 if (regnum == (SPARC64_F32_REGNUM + i) || regnum == -1) 01515 regcache_raw_collect (regcache, SPARC64_F32_REGNUM + i, 01516 (regs + fpregset->r_f0_offset 01517 + (32 * 4) + (i * 8))); 01518 } 01519 01520 if (regnum == SPARC64_FSR_REGNUM || regnum == -1) 01521 regcache_raw_collect (regcache, SPARC64_FSR_REGNUM, 01522 regs + fpregset->r_fsr_offset); 01523 } 01524 } 01525 01526 const struct sparc_fpregset sparc64_bsd_fpregset = 01527 { 01528 0 * 8, /* %f0 */ 01529 32 * 8, /* %fsr */ 01530 };