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-2013 OpenWorks LLP 11 info@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 41 42 /*---------------------------------------------------------------*/ 43 /*--- Vex's representation of the AMD64 CPU state. ---*/ 44 /*---------------------------------------------------------------*/ 45 46 /* See detailed comments at the top of libvex_guest_x86.h for 47 further info. This representation closely follows the 48 x86 representation. 49 */ 50 51 52 typedef 53 struct { 54 /* Event check fail addr, counter, and padding to make RAX 16 55 aligned. */ 56 /* 0 */ ULong host_EvC_FAILADDR; 57 /* 8 */ UInt host_EvC_COUNTER; 58 /* 12 */ UInt pad0; 59 /* 16 */ ULong guest_RAX; 60 /* 24 */ ULong guest_RCX; 61 /* 32 */ ULong guest_RDX; 62 /* 40 */ ULong guest_RBX; 63 /* 48 */ ULong guest_RSP; 64 /* 56 */ ULong guest_RBP; 65 /* 64 */ ULong guest_RSI; 66 /* 72 */ ULong guest_RDI; 67 /* 80 */ ULong guest_R8; 68 /* 88 */ ULong guest_R9; 69 /* 96 */ ULong guest_R10; 70 /* 104 */ ULong guest_R11; 71 /* 112 */ ULong guest_R12; 72 /* 120 */ ULong guest_R13; 73 /* 128 */ ULong guest_R14; 74 /* 136 */ ULong guest_R15; 75 /* 4-word thunk used to calculate O S Z A C P flags. */ 76 /* 144 */ ULong guest_CC_OP; 77 /* 152 */ ULong guest_CC_DEP1; 78 /* 160 */ ULong guest_CC_DEP2; 79 /* 168 */ ULong guest_CC_NDEP; 80 /* The D flag is stored here, encoded as either -1 or +1 */ 81 /* 176 */ ULong guest_DFLAG; 82 /* 184 */ ULong guest_RIP; 83 /* Bit 18 (AC) of eflags stored here, as either 0 or 1. */ 84 /* ... */ ULong guest_ACFLAG; 85 /* Bit 21 (ID) of eflags stored here, as either 0 or 1. */ 86 /* 192 */ ULong guest_IDFLAG; 87 /* Probably a lot more stuff too. 88 D,ID flags 89 16 128-bit SSE registers 90 all the old x87 FPU gunk 91 segment registers */ 92 93 /* HACK to make tls on amd64-linux work. %fs only ever seems to 94 hold zero, and so guest_FS_ZERO holds the 64-bit offset 95 associated with a %fs value of zero. */ 96 /* 200 */ ULong guest_FS_ZERO; 97 98 /* YMM registers. Note that these must be allocated 99 consecutively in order that the SSE4.2 PCMP{E,I}STR{I,M} 100 helpers can treat them as an array. YMM16 is a fake reg used 101 as an intermediary in handling aforementioned insns. */ 102 /* 208 */ULong guest_SSEROUND; 103 /* 216 */U256 guest_YMM0; 104 U256 guest_YMM1; 105 U256 guest_YMM2; 106 U256 guest_YMM3; 107 U256 guest_YMM4; 108 U256 guest_YMM5; 109 U256 guest_YMM6; 110 U256 guest_YMM7; 111 U256 guest_YMM8; 112 U256 guest_YMM9; 113 U256 guest_YMM10; 114 U256 guest_YMM11; 115 U256 guest_YMM12; 116 U256 guest_YMM13; 117 U256 guest_YMM14; 118 U256 guest_YMM15; 119 U256 guest_YMM16; 120 121 /* FPU */ 122 /* Note. Setting guest_FTOP to be ULong messes up the 123 delicately-balanced PutI/GetI optimisation machinery. 124 Therefore best to leave it as a UInt. */ 125 UInt guest_FTOP; 126 ULong guest_FPREG[8]; 127 UChar guest_FPTAG[8]; 128 ULong guest_FPROUND; 129 ULong guest_FC3210; 130 131 /* Emulation notes */ 132 UInt guest_EMNOTE; 133 134 /* Translation-invalidation area description. Not used on amd64 135 (there is no invalidate-icache insn), but needed so as to 136 allow users of the library to uniformly assume that the guest 137 state contains these two fields -- otherwise there is 138 compilation breakage. On amd64, these two fields are set to 139 zero by LibVEX_GuestAMD64_initialise and then should be 140 ignored forever thereafter. */ 141 ULong guest_CMSTART; 142 ULong guest_CMLEN; 143 144 /* Used to record the unredirected guest address at the start of 145 a translation whose start has been redirected. By reading 146 this pseudo-register shortly afterwards, the translation can 147 find out what the corresponding no-redirection address was. 148 Note, this is only set for wrap-style redirects, not for 149 replace-style ones. */ 150 ULong guest_NRADDR; 151 152 /* Used for Darwin syscall dispatching. */ 153 ULong guest_SC_CLASS; 154 155 /* HACK to make tls on darwin work. %gs only ever seems to 156 hold 0x60, and so guest_GS_0x60 holds the 64-bit offset 157 associated with a %gs value of 0x60. (A direct analogue 158 of the %fs-zero hack for amd64-linux). */ 159 ULong guest_GS_0x60; 160 161 /* Needed for Darwin (but mandated for all guest architectures): 162 RIP at the last syscall insn (int 0x80/81/82, sysenter, 163 syscall). Used when backing up to restart a syscall that has 164 been interrupted by a signal. */ 165 ULong guest_IP_AT_SYSCALL; 166 167 /* Padding to make it have an 16-aligned size */ 168 ULong pad1; 169 } 170 VexGuestAMD64State; 171 172 173 174 /*---------------------------------------------------------------*/ 175 /*--- Utility functions for amd64 guest stuff. ---*/ 176 /*---------------------------------------------------------------*/ 177 178 /* ALL THE FOLLOWING ARE VISIBLE TO LIBRARY CLIENT */ 179 180 /* Initialise all guest amd64 state. The FPU is put in default 181 mode. */ 182 extern 183 void LibVEX_GuestAMD64_initialise ( /*OUT*/VexGuestAMD64State* vex_state ); 184 185 186 /* Extract from the supplied VexGuestAMD64State structure the 187 corresponding native %rflags value. */ 188 extern 189 ULong LibVEX_GuestAMD64_get_rflags ( /*IN*/const VexGuestAMD64State* vex_state ); 190 191 /* Set the carry flag in the given state to 'new_carry_flag', which 192 should be zero or one. */ 193 extern 194 void 195 LibVEX_GuestAMD64_put_rflag_c ( ULong new_carry_flag, 196 /*MOD*/VexGuestAMD64State* vex_state ); 197 198 199 #endif /* ndef __LIBVEX_PUB_GUEST_AMD64_H */ 200 201 /*---------------------------------------------------------------*/ 202 /*--- libvex_guest_amd64.h ---*/ 203 /*---------------------------------------------------------------*/ 204