1 /* libunwind - a platform-independent unwind library 2 Copyright (C) 2004 Hewlett-Packard Co 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 PROTECTED int 31 unw_get_save_loc (unw_cursor_t *cursor, int reg, unw_save_loc_t *sloc) 32 { 33 struct cursor *c = (struct cursor *) cursor; 34 dwarf_loc_t loc; 35 36 loc = DWARF_NULL_LOC; /* default to "not saved" */ 37 38 switch (reg) 39 { 40 case UNW_X86_64_RBX: loc = c->dwarf.loc[RBX]; break; 41 case UNW_X86_64_RSP: loc = c->dwarf.loc[RSP]; break; 42 case UNW_X86_64_RBP: loc = c->dwarf.loc[RBP]; break; 43 case UNW_X86_64_R12: loc = c->dwarf.loc[R12]; break; 44 case UNW_X86_64_R13: loc = c->dwarf.loc[R13]; break; 45 case UNW_X86_64_R14: loc = c->dwarf.loc[R14]; break; 46 case UNW_X86_64_R15: loc = c->dwarf.loc[R15]; break; 47 48 default: 49 break; 50 } 51 52 memset (sloc, 0, sizeof (*sloc)); 53 54 if (DWARF_IS_NULL_LOC (loc)) 55 { 56 sloc->type = UNW_SLT_NONE; 57 return 0; 58 } 59 60 #if !defined(UNW_LOCAL_ONLY) 61 if (DWARF_IS_REG_LOC (loc)) 62 { 63 sloc->type = UNW_SLT_REG; 64 sloc->u.regnum = DWARF_GET_LOC (loc); 65 } 66 else 67 #endif 68 { 69 sloc->type = UNW_SLT_MEMORY; 70 sloc->u.addr = DWARF_GET_LOC (loc); 71 } 72 return 0; 73 } 74