1 /* libunwind - a platform-independent unwind library 2 Copyright (c) 2002-2004 Hewlett-Packard Development Company, L.P. 3 Contributed by David Mosberger-Tang <davidm (at) hpl.hp.com> 4 5 Modified for x86_64 by Max Asbock <masbock (at) us.ibm.com> 6 7 This file is part of libunwind. 8 9 Permission is hereby granted, free of charge, to any person obtaining 10 a copy of this software and associated documentation files (the 11 "Software"), to deal in the Software without restriction, including 12 without limitation the rights to use, copy, modify, merge, publish, 13 distribute, sublicense, and/or sell copies of the Software, and to 14 permit persons to whom the Software is furnished to do so, subject to 15 the following conditions: 16 17 The above copyright notice and this permission notice shall be 18 included in all copies or substantial portions of the Software. 19 20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 27 28 #include "unwind_i.h" 29 30 #if 0 31 static inline dwarf_loc_t 32 linux_scratch_loc (struct cursor *c, unw_regnum_t reg) 33 { 34 unw_word_t addr = c->sigcontext_addr; 35 36 switch (c->sigcontext_format) 37 { 38 case X86_64_SCF_NONE: 39 return DWARF_REG_LOC (&c->dwarf, reg); 40 41 case X86_64_SCF_LINUX_RT_SIGFRAME: 42 addr += LINUX_UC_MCONTEXT_OFF; 43 break; 44 45 case X86_64_SCF_FREEBSD_SIGFRAME: 46 addr += FREEBSD_UC_MCONTEXT_OFF; 47 break; 48 } 49 50 return DWARF_REG_LOC (&c->dwarf, reg); 51 52 } 53 54 HIDDEN dwarf_loc_t 55 x86_64_scratch_loc (struct cursor *c, unw_regnum_t reg) 56 { 57 if (c->sigcontext_addr) 58 return linux_scratch_loc (c, reg); 59 else 60 return DWARF_REG_LOC (&c->dwarf, reg); 61 } 62 #endif 63 64 HIDDEN int 65 tdep_access_reg (struct cursor *c, unw_regnum_t reg, unw_word_t *valp, 66 int write) 67 { 68 dwarf_loc_t loc = DWARF_NULL_LOC; 69 unsigned int mask; 70 int arg_num; 71 72 switch (reg) 73 { 74 75 case UNW_X86_64_RIP: 76 if (write) 77 c->dwarf.ip = *valp; /* also update the RIP cache */ 78 loc = c->dwarf.loc[RIP]; 79 break; 80 81 case UNW_X86_64_CFA: 82 case UNW_X86_64_RSP: 83 if (write) 84 return -UNW_EREADONLYREG; 85 *valp = c->dwarf.cfa; 86 return 0; 87 88 case UNW_X86_64_RAX: 89 case UNW_X86_64_RDX: 90 arg_num = reg - UNW_X86_64_RAX; 91 mask = (1 << arg_num); 92 if (write) 93 { 94 c->dwarf.eh_args[arg_num] = *valp; 95 c->dwarf.eh_valid_mask |= mask; 96 return 0; 97 } 98 else if ((c->dwarf.eh_valid_mask & mask) != 0) 99 { 100 *valp = c->dwarf.eh_args[arg_num]; 101 return 0; 102 } 103 else 104 loc = c->dwarf.loc[(reg == UNW_X86_64_RAX) ? RAX : RDX]; 105 break; 106 107 case UNW_X86_64_RCX: loc = c->dwarf.loc[RCX]; break; 108 case UNW_X86_64_RBX: loc = c->dwarf.loc[RBX]; break; 109 110 case UNW_X86_64_RBP: loc = c->dwarf.loc[RBP]; break; 111 case UNW_X86_64_RSI: loc = c->dwarf.loc[RSI]; break; 112 case UNW_X86_64_RDI: loc = c->dwarf.loc[RDI]; break; 113 case UNW_X86_64_R8: loc = c->dwarf.loc[R8]; break; 114 case UNW_X86_64_R9: loc = c->dwarf.loc[R9]; break; 115 case UNW_X86_64_R10: loc = c->dwarf.loc[R10]; break; 116 case UNW_X86_64_R11: loc = c->dwarf.loc[R11]; break; 117 case UNW_X86_64_R12: loc = c->dwarf.loc[R12]; break; 118 case UNW_X86_64_R13: loc = c->dwarf.loc[R13]; break; 119 case UNW_X86_64_R14: loc = c->dwarf.loc[R14]; break; 120 case UNW_X86_64_R15: loc = c->dwarf.loc[R15]; break; 121 122 default: 123 Debug (1, "bad register number %u\n", reg); 124 return -UNW_EBADREG; 125 } 126 127 if (write) 128 return dwarf_put (&c->dwarf, loc, *valp); 129 else 130 return dwarf_get (&c->dwarf, loc, valp); 131 } 132 133 HIDDEN int 134 tdep_access_fpreg (struct cursor *c, unw_regnum_t reg, unw_fpreg_t *valp, 135 int write) 136 { 137 return -UNW_EBADREG; 138 } 139