1 2 /*---------------------------------------------------------------*/ 3 /*--- begin libvex_guest_amd64.h ---*/ 4 /*---------------------------------------------------------------*/ 5 6 /* 7 This file is part of Valgrind, a dynamic binary instrumentation 8 framework. 9 10 Copyright (C) 2004-2012 OpenWorks LLP 11 info (at) open-works.net 12 13 This program is free software; you can redistribute it and/or 14 modify it under the terms of the GNU General Public License as 15 published by the Free Software Foundation; either version 2 of the 16 License, or (at your option) any later version. 17 18 This program is distributed in the hope that it will be useful, but 19 WITHOUT ANY WARRANTY; without even the implied warranty of 20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 21 General Public License for more details. 22 23 You should have received a copy of the GNU General Public License 24 along with this program; if not, write to the Free Software 25 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 26 02110-1301, USA. 27 28 The GNU General Public License is contained in the file COPYING. 29 30 Neither the names of the U.S. Department of Energy nor the 31 University of California nor the names of its contributors may be 32 used to endorse or promote products derived from this software 33 without prior written permission. 34 */ 35 36 #ifndef __LIBVEX_PUB_GUEST_AMD64_H 37 #define __LIBVEX_PUB_GUEST_AMD64_H 38 39 #include "libvex_basictypes.h" 40 #include "libvex_emwarn.h" 41 42 43 /*---------------------------------------------------------------*/ 44 /*--- Vex's representation of the AMD64 CPU state. ---*/ 45 /*---------------------------------------------------------------*/ 46 47 /* See detailed comments at the top of libvex_guest_x86.h for 48 further info. This representation closely follows the 49 x86 representation. 50 */ 51 52 53 typedef 54 struct { 55 /* Event check fail addr, counter, and padding to make RAX 16 56 aligned. */ 57 /* 0 */ ULong host_EvC_FAILADDR; 58 /* 8 */ UInt host_EvC_COUNTER; 59 /* 12 */ UInt pad0; 60 /* 16 */ ULong guest_RAX; 61 /* 24 */ ULong guest_RCX; 62 /* 32 */ ULong guest_RDX; 63 /* 40 */ ULong guest_RBX; 64 /* 48 */ ULong guest_RSP; 65 /* 56 */ ULong guest_RBP; 66 /* 64 */ ULong guest_RSI; 67 /* 72 */ ULong guest_RDI; 68 /* 80 */ ULong guest_R8; 69 /* 88 */ ULong guest_R9; 70 /* 96 */ ULong guest_R10; 71 /* 104 */ ULong guest_R11; 72 /* 112 */ ULong guest_R12; 73 /* 120 */ ULong guest_R13; 74 /* 128 */ ULong guest_R14; 75 /* 136 */ ULong guest_R15; 76 /* 4-word thunk used to calculate O S Z A C P flags. */ 77 /* 144 */ ULong guest_CC_OP; 78 /* 152 */ ULong guest_CC_DEP1; 79 /* 160 */ ULong guest_CC_DEP2; 80 /* 168 */ ULong guest_CC_NDEP; 81 /* The D flag is stored here, encoded as either -1 or +1 */ 82 /* 176 */ ULong guest_DFLAG; 83 /* 184 */ ULong guest_RIP; 84 /* Bit 18 (AC) of eflags stored here, as either 0 or 1. */ 85 /* ... */ ULong guest_ACFLAG; 86 /* Bit 21 (ID) of eflags stored here, as either 0 or 1. */ 87 /* 192 */ ULong guest_IDFLAG; 88 /* Probably a lot more stuff too. 89 D,ID flags 90 16 128-bit SSE registers 91 all the old x87 FPU gunk 92 segment registers */ 93 94 /* HACK to make tls on amd64-linux work. %fs only ever seems to 95 hold zero, and so guest_FS_ZERO holds the 64-bit offset 96 associated with a %fs value of zero. */ 97 /* 200 */ ULong guest_FS_ZERO; 98 99 /* YMM registers. Note that these must be allocated 100 consecutively in order that the SSE4.2 PCMP{E,I}STR{I,M} 101 helpers can treat them as an array. YMM16 is a fake reg used 102 as an intermediary in handling aforementioned insns. */ 103 /* 208 */ULong guest_SSEROUND; 104 /* 216 */U256 guest_YMM0; 105 U256 guest_YMM1; 106 U256 guest_YMM2; 107 U256 guest_YMM3; 108 U256 guest_YMM4; 109 U256 guest_YMM5; 110 U256 guest_YMM6; 111 U256 guest_YMM7; 112 U256 guest_YMM8; 113 U256 guest_YMM9; 114 U256 guest_YMM10; 115 U256 guest_YMM11; 116 U256 guest_YMM12; 117 U256 guest_YMM13; 118 U256 guest_YMM14; 119 U256 guest_YMM15; 120 U256 guest_YMM16; 121 122 /* FPU */ 123 /* Note. Setting guest_FTOP to be ULong messes up the 124 delicately-balanced PutI/GetI optimisation machinery. 125 Therefore best to leave it as a UInt. */ 126 UInt guest_FTOP; 127 ULong guest_FPREG[8]; 128 UChar guest_FPTAG[8]; 129 ULong guest_FPROUND; 130 ULong guest_FC3210; 131 132 /* Emulation warnings */ 133 UInt guest_EMWARN; 134 135 /* Translation-invalidation area description. Not used on amd64 136 (there is no invalidate-icache insn), but needed so as to 137 allow users of the library to uniformly assume that the guest 138 state contains these two fields -- otherwise there is 139 compilation breakage. On amd64, these two fields are set to 140 zero by LibVEX_GuestAMD64_initialise and then should be 141 ignored forever thereafter. */ 142 ULong guest_TISTART; 143 ULong guest_TILEN; 144 145 /* Used to record the unredirected guest address at the start of 146 a translation whose start has been redirected. By reading 147 this pseudo-register shortly afterwards, the translation can 148 find out what the corresponding no-redirection address was. 149 Note, this is only set for wrap-style redirects, not for 150 replace-style ones. */ 151 ULong guest_NRADDR; 152 153 /* Used for Darwin syscall dispatching. */ 154 ULong guest_SC_CLASS; 155 156 /* HACK to make tls on darwin work. %gs only ever seems to 157 hold 0x60, and so guest_GS_0x60 holds the 64-bit offset 158 associated with a %gs value of 0x60. (A direct analogue 159 of the %fs-zero hack for amd64-linux). */ 160 ULong guest_GS_0x60; 161 162 /* Needed for Darwin (but mandated for all guest architectures): 163 RIP at the last syscall insn (int 0x80/81/82, sysenter, 164 syscall). Used when backing up to restart a syscall that has 165 been interrupted by a signal. */ 166 ULong guest_IP_AT_SYSCALL; 167 168 /* Padding to make it have an 16-aligned size */ 169 ULong pad1; 170 } 171 VexGuestAMD64State; 172 173 174 175 /*---------------------------------------------------------------*/ 176 /*--- Utility functions for amd64 guest stuff. ---*/ 177 /*---------------------------------------------------------------*/ 178 179 /* ALL THE FOLLOWING ARE VISIBLE TO LIBRARY CLIENT */ 180 181 /* Initialise all guest amd64 state. The FPU is put in default 182 mode. */ 183 extern 184 void LibVEX_GuestAMD64_initialise ( /*OUT*/VexGuestAMD64State* vex_state ); 185 186 187 /* Extract from the supplied VexGuestAMD64State structure the 188 corresponding native %rflags value. */ 189 extern 190 ULong LibVEX_GuestAMD64_get_rflags ( /*IN*/VexGuestAMD64State* vex_state ); 191 192 /* Set the carry flag in the given state to 'new_carry_flag', which 193 should be zero or one. */ 194 extern 195 void 196 LibVEX_GuestAMD64_put_rflag_c ( ULong new_carry_flag, 197 /*MOD*/VexGuestAMD64State* vex_state ); 198 199 200 #if 0 201 /* Convert a saved x87 FPU image (as created by fsave) and write it 202 into the supplied VexGuestX86State structure. The non-FP parts of 203 said structure are left unchanged. 204 */ 205 extern 206 void LibVEX_GuestX86_put_x87 ( /*IN*/UChar* x87_state, 207 /*OUT*/VexGuestX86State* vex_state ); 208 209 /* Extract from the supplied VexGuestX86State structure, an x87 FPU 210 image. */ 211 extern 212 void LibVEX_GuestX86_get_x87 ( /*IN*/VexGuestX86State* vex_state, 213 /*OUT*/UChar* x87_state ); 214 215 216 /* Given a 32-bit word containing native x86 %eflags values, set the 217 eflag-related fields in the supplied VexGuestX86State accordingly. 218 All other fields are left unchanged. */ 219 220 extern 221 void LibVEX_GuestX86_put_eflags ( UInt eflags_native, 222 /*OUT*/VexGuestX86State* vex_state ); 223 224 #endif /* 0 */ 225 226 #endif /* ndef __LIBVEX_PUB_GUEST_AMD64_H */ 227 228 /*---------------------------------------------------------------*/ 229 /*--- libvex_guest_amd64.h ---*/ 230 /*---------------------------------------------------------------*/ 231