1 /* libunwind - a platform-independent unwind library 2 Copyright (C) 2002-2004 Hewlett-Packard Co 3 Contributed by David Mosberger-Tang <davidm@hpl.hp.com> 4 5 This file is part of libunwind. 6 7 Permission is hereby granted, free of charge, to any person obtaining 8 a copy of this software and associated documentation files (the 9 "Software"), to deal in the Software without restriction, including 10 without limitation the rights to use, copy, modify, merge, publish, 11 distribute, sublicense, and/or sell copies of the Software, and to 12 permit persons to whom the Software is furnished to do so, subject to 13 the following conditions: 14 15 The above copyright notice and this permission notice shall be 16 included in all copies or substantial portions of the Software. 17 18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 22 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 24 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 25 26 #ifndef LIBUNWIND_H 27 #define LIBUNWIND_H 28 29 #if defined(__cplusplus) || defined(c_plusplus) 30 extern "C" { 31 #endif 32 33 #include <sys/types.h> 34 #include <inttypes.h> 35 #include <ucontext.h> 36 37 #ifndef UNW_EMPTY_STRUCT 38 # define UNW_EMPTY_STRUCT uint8_t unused; 39 #endif 40 41 #define UNW_TARGET x86 42 #define UNW_TARGET_X86 1 43 44 #define _U_TDEP_QP_TRUE 0 /* see libunwind-dynamic.h */ 45 46 /* This needs to be big enough to accommodate "struct cursor", while 47 leaving some slack for future expansion. Changing this value will 48 require recompiling all users of this library. Stack allocation is 49 relatively cheap and unwind-state copying is relatively rare, so we 50 want to err on making it rather too big than too small. */ 51 #define UNW_TDEP_CURSOR_LEN 127 52 53 typedef uint32_t unw_word_t; 54 typedef int32_t unw_sword_t; 55 56 typedef union { 57 struct { uint8_t b[4]; } val32; 58 struct { uint8_t b[10]; } val80; 59 struct { uint8_t b[16]; } val128; 60 } unw_tdep_fpreg_t; 61 62 typedef enum 63 { 64 /* Note: general registers are expected to start with index 0. 65 This convention facilitates architecture-independent 66 implementation of the C++ exception handling ABI. See 67 _Unwind_SetGR() and _Unwind_GetGR() for details. 68 69 The described register usage convention is based on "System V 70 Application Binary Interface, Intel386 Architecture Processor 71 Supplement, Fourth Edition" at 72 73 http://www.linuxbase.org/spec/refspecs/elf/abi386-4.pdf 74 75 It would have been nice to use the same register numbering as 76 DWARF, but that doesn't work because the libunwind requires 77 that the exception argument registers be consecutive, which the 78 wouldn't be with the DWARF numbering. */ 79 UNW_X86_EAX, /* scratch (exception argument 1) */ 80 UNW_X86_EDX, /* scratch (exception argument 2) */ 81 UNW_X86_ECX, /* scratch */ 82 UNW_X86_EBX, /* preserved */ 83 UNW_X86_ESI, /* preserved */ 84 UNW_X86_EDI, /* preserved */ 85 UNW_X86_EBP, /* (optional) frame-register */ 86 UNW_X86_ESP, /* (optional) frame-register */ 87 UNW_X86_EIP, /* frame-register */ 88 UNW_X86_EFLAGS, /* scratch (except for "direction", which is fixed */ 89 UNW_X86_TRAPNO, /* scratch */ 90 91 /* MMX/stacked-fp registers */ 92 UNW_X86_ST0, /* fp return value */ 93 UNW_X86_ST1, /* scratch */ 94 UNW_X86_ST2, /* scratch */ 95 UNW_X86_ST3, /* scratch */ 96 UNW_X86_ST4, /* scratch */ 97 UNW_X86_ST5, /* scratch */ 98 UNW_X86_ST6, /* scratch */ 99 UNW_X86_ST7, /* scratch */ 100 101 UNW_X86_FCW, /* scratch */ 102 UNW_X86_FSW, /* scratch */ 103 UNW_X86_FTW, /* scratch */ 104 UNW_X86_FOP, /* scratch */ 105 UNW_X86_FCS, /* scratch */ 106 UNW_X86_FIP, /* scratch */ 107 UNW_X86_FEA, /* scratch */ 108 UNW_X86_FDS, /* scratch */ 109 110 /* SSE registers */ 111 UNW_X86_XMM0_lo, /* scratch */ 112 UNW_X86_XMM0_hi, /* scratch */ 113 UNW_X86_XMM1_lo, /* scratch */ 114 UNW_X86_XMM1_hi, /* scratch */ 115 UNW_X86_XMM2_lo, /* scratch */ 116 UNW_X86_XMM2_hi, /* scratch */ 117 UNW_X86_XMM3_lo, /* scratch */ 118 UNW_X86_XMM3_hi, /* scratch */ 119 UNW_X86_XMM4_lo, /* scratch */ 120 UNW_X86_XMM4_hi, /* scratch */ 121 UNW_X86_XMM5_lo, /* scratch */ 122 UNW_X86_XMM5_hi, /* scratch */ 123 UNW_X86_XMM6_lo, /* scratch */ 124 UNW_X86_XMM6_hi, /* scratch */ 125 UNW_X86_XMM7_lo, /* scratch */ 126 UNW_X86_XMM7_hi, /* scratch */ 127 128 UNW_X86_MXCSR, /* scratch */ 129 130 /* segment registers */ 131 UNW_X86_GS, /* special */ 132 UNW_X86_FS, /* special */ 133 UNW_X86_ES, /* special */ 134 UNW_X86_DS, /* special */ 135 UNW_X86_SS, /* special */ 136 UNW_X86_CS, /* special */ 137 UNW_X86_TSS, /* special */ 138 UNW_X86_LDT, /* special */ 139 140 /* frame info (read-only) */ 141 UNW_X86_CFA, 142 143 UNW_X86_XMM0, /* scratch */ 144 UNW_X86_XMM1, /* scratch */ 145 UNW_X86_XMM2, /* scratch */ 146 UNW_X86_XMM3, /* scratch */ 147 UNW_X86_XMM4, /* scratch */ 148 UNW_X86_XMM5, /* scratch */ 149 UNW_X86_XMM6, /* scratch */ 150 UNW_X86_XMM7, /* scratch */ 151 152 UNW_TDEP_LAST_REG = UNW_X86_XMM7, 153 154 UNW_TDEP_IP = UNW_X86_EIP, 155 UNW_TDEP_SP = UNW_X86_ESP, 156 UNW_TDEP_EH = UNW_X86_EAX 157 } 158 x86_regnum_t; 159 160 #define UNW_TDEP_NUM_EH_REGS 2 /* eax and edx are exception args */ 161 162 typedef struct unw_tdep_save_loc 163 { 164 /* Additional target-dependent info on a save location. */ 165 UNW_EMPTY_STRUCT 166 } 167 unw_tdep_save_loc_t; 168 169 /* On x86, we can directly use ucontext_t as the unwind context. */ 170 typedef ucontext_t unw_tdep_context_t; 171 172 #include "libunwind-dynamic.h" 173 174 typedef struct 175 { 176 /* no x86-specific auxiliary proc-info */ 177 UNW_EMPTY_STRUCT 178 } 179 unw_tdep_proc_info_t; 180 181 #include "libunwind-common.h" 182 183 #define unw_tdep_getcontext UNW_ARCH_OBJ(getcontext) 184 extern int unw_tdep_getcontext (unw_tdep_context_t *); 185 186 #define unw_tdep_is_fpreg UNW_ARCH_OBJ(is_fpreg) 187 extern int unw_tdep_is_fpreg (int); 188 189 #if defined(__cplusplus) || defined(c_plusplus) 190 } 191 #endif 192 193 #endif /* LIBUNWIND_H */ 194