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@hpl.hp.com> 4 5 Modified for x86_64 by Max Asbock <masbock@us.ibm.com> 6 7This file is part of libunwind. 8 9Permission is hereby granted, free of charge, to any person obtaining 10a copy of this software and associated documentation files (the 11"Software"), to deal in the Software without restriction, including 12without limitation the rights to use, copy, modify, merge, publish, 13distribute, sublicense, and/or sell copies of the Software, and to 14permit persons to whom the Software is furnished to do so, subject to 15the following conditions: 16 17The above copyright notice and this permission notice shall be 18included in all copies or substantial portions of the Software. 19 20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 27 28#include "unwind_i.h" 29 30#if 0 31static inline dwarf_loc_t 32linux_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 54HIDDEN dwarf_loc_t 55x86_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 64HIDDEN int 65tdep_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 133HIDDEN int 134tdep_access_fpreg (struct cursor *c, unw_regnum_t reg, unw_fpreg_t *valp, 135 int write) 136{ 137 return -UNW_EBADREG; 138} 139