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-2010 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 /* 0 */ ULong guest_RAX; 56 /* 8 */ ULong guest_RCX; 57 /* 16 */ ULong guest_RDX; 58 /* 24 */ ULong guest_RBX; 59 /* 32 */ ULong guest_RSP; 60 /* 40 */ ULong guest_RBP; 61 /* 48 */ ULong guest_RSI; 62 /* 56 */ ULong guest_RDI; 63 /* 64 */ ULong guest_R8; 64 /* 72 */ ULong guest_R9; 65 /* 80 */ ULong guest_R10; 66 /* 88 */ ULong guest_R11; 67 /* 96 */ ULong guest_R12; 68 /* 104 */ ULong guest_R13; 69 /* 112 */ ULong guest_R14; 70 /* 120 */ ULong guest_R15; 71 /* 4-word thunk used to calculate O S Z A C P flags. */ 72 /* 128 */ ULong guest_CC_OP; 73 /* 136 */ ULong guest_CC_DEP1; 74 /* 144 */ ULong guest_CC_DEP2; 75 /* 152 */ ULong guest_CC_NDEP; 76 /* The D flag is stored here, encoded as either -1 or +1 */ 77 /* 160 */ ULong guest_DFLAG; 78 /* 168 */ ULong guest_RIP; 79 /* Bit 18 (AC) of eflags stored here, as either 0 or 1. */ 80 /* ... */ ULong guest_ACFLAG; 81 /* Bit 21 (ID) of eflags stored here, as either 0 or 1. */ 82 /* 176 */ ULong guest_IDFLAG; 83 /* Probably a lot more stuff too. 84 D,ID flags 85 16 128-bit SSE registers 86 all the old x87 FPU gunk 87 segment registers */ 88 89 /* HACK to make tls on amd64-linux work. %fs only ever seems to 90 hold zero, and so guest_FS_ZERO holds the 64-bit offset 91 associated with a %fs value of zero. */ 92 /* 184 */ ULong guest_FS_ZERO; 93 94 /* XMM registers. Note that these must be allocated 95 consecutively in order that the SSE4.2 PCMP{E,I}STR{I,M} 96 helpers can treat them as an array. XMM16 is a fake reg used 97 as an intermediary in handling aforementioned insns. */ 98 /* 192 */ULong guest_SSEROUND; 99 /* 200 */U128 guest_XMM0; 100 U128 guest_XMM1; 101 U128 guest_XMM2; 102 U128 guest_XMM3; 103 U128 guest_XMM4; 104 U128 guest_XMM5; 105 U128 guest_XMM6; 106 U128 guest_XMM7; 107 U128 guest_XMM8; 108 U128 guest_XMM9; 109 U128 guest_XMM10; 110 U128 guest_XMM11; 111 U128 guest_XMM12; 112 U128 guest_XMM13; 113 U128 guest_XMM14; 114 U128 guest_XMM15; 115 U128 guest_XMM16; 116 117 /* FPU */ 118 /* Note. Setting guest_FTOP to be ULong messes up the 119 delicately-balanced PutI/GetI optimisation machinery. 120 Therefore best to leave it as a UInt. */ 121 /* 456 */UInt guest_FTOP; 122 ULong guest_FPREG[8]; 123 /* 528 */ UChar guest_FPTAG[8]; 124 /* 536 */ ULong guest_FPROUND; 125 /* 544 */ ULong guest_FC3210; 126 127 /* Emulation warnings */ 128 /* 552 */ UInt guest_EMWARN; 129 130 /* Translation-invalidation area description. Not used on amd64 131 (there is no invalidate-icache insn), but needed so as to 132 allow users of the library to uniformly assume that the guest 133 state contains these two fields -- otherwise there is 134 compilation breakage. On amd64, these two fields are set to 135 zero by LibVEX_GuestAMD64_initialise and then should be 136 ignored forever thereafter. */ 137 ULong guest_TISTART; 138 ULong guest_TILEN; 139 140 /* Used to record the unredirected guest address at the start of 141 a translation whose start has been redirected. By reading 142 this pseudo-register shortly afterwards, the translation can 143 find out what the corresponding no-redirection address was. 144 Note, this is only set for wrap-style redirects, not for 145 replace-style ones. */ 146 ULong guest_NRADDR; 147 148 /* Used for Darwin syscall dispatching. */ 149 ULong guest_SC_CLASS; 150 151 /* HACK to make tls on darwin work. %gs only ever seems to 152 hold 0x60, and so guest_GS_0x60 holds the 64-bit offset 153 associated with a %gs value of 0x60. (A direct analogue 154 of the %fs-zero hack for amd64-linux). */ 155 ULong guest_GS_0x60; 156 157 /* Needed for Darwin (but mandated for all guest architectures): 158 RIP at the last syscall insn (int 0x80/81/82, sysenter, 159 syscall). Used when backing up to restart a syscall that has 160 been interrupted by a signal. */ 161 ULong guest_IP_AT_SYSCALL; 162 163 /* Padding to make it have an 16-aligned size */ 164 ULong padding; 165 } 166 VexGuestAMD64State; 167 168 169 170 /*---------------------------------------------------------------*/ 171 /*--- Utility functions for amd64 guest stuff. ---*/ 172 /*---------------------------------------------------------------*/ 173 174 /* ALL THE FOLLOWING ARE VISIBLE TO LIBRARY CLIENT */ 175 176 /* Initialise all guest amd64 state. The FPU is put in default 177 mode. */ 178 extern 179 void LibVEX_GuestAMD64_initialise ( /*OUT*/VexGuestAMD64State* vex_state ); 180 181 182 /* Extract from the supplied VexGuestAMD64State structure the 183 corresponding native %rflags value. */ 184 extern 185 ULong LibVEX_GuestAMD64_get_rflags ( /*IN*/VexGuestAMD64State* vex_state ); 186 187 /* Set the carry flag in the given state to 'new_carry_flag', which 188 should be zero or one. */ 189 extern 190 void 191 LibVEX_GuestAMD64_put_rflag_c ( ULong new_carry_flag, 192 /*MOD*/VexGuestAMD64State* vex_state ); 193 194 195 #if 0 196 /* Convert a saved x87 FPU image (as created by fsave) and write it 197 into the supplied VexGuestX86State structure. The non-FP parts of 198 said structure are left unchanged. 199 */ 200 extern 201 void LibVEX_GuestX86_put_x87 ( /*IN*/UChar* x87_state, 202 /*OUT*/VexGuestX86State* vex_state ); 203 204 /* Extract from the supplied VexGuestX86State structure, an x87 FPU 205 image. */ 206 extern 207 void LibVEX_GuestX86_get_x87 ( /*IN*/VexGuestX86State* vex_state, 208 /*OUT*/UChar* x87_state ); 209 210 211 /* Given a 32-bit word containing native x86 %eflags values, set the 212 eflag-related fields in the supplied VexGuestX86State accordingly. 213 All other fields are left unchanged. */ 214 215 extern 216 void LibVEX_GuestX86_put_eflags ( UInt eflags_native, 217 /*OUT*/VexGuestX86State* vex_state ); 218 219 #endif /* 0 */ 220 221 #endif /* ndef __LIBVEX_PUB_GUEST_AMD64_H */ 222 223 /*---------------------------------------------------------------*/ 224 /*--- libvex_guest_amd64.h ---*/ 225 /*---------------------------------------------------------------*/ 226