sewardj | 9a7b75d | 2004-11-23 14:07:46 +0000 | [diff] [blame] | 1 | |
| 2 | /*---------------------------------------------------------------*/ |
sewardj | 752f906 | 2010-05-03 21:38:49 +0000 | [diff] [blame] | 3 | /*--- begin libvex_guest_amd64.h ---*/ |
sewardj | 9a7b75d | 2004-11-23 14:07:46 +0000 | [diff] [blame] | 4 | /*---------------------------------------------------------------*/ |
| 5 | |
| 6 | /* |
sewardj | 752f906 | 2010-05-03 21:38:49 +0000 | [diff] [blame] | 7 | This file is part of Valgrind, a dynamic binary instrumentation |
| 8 | framework. |
sewardj | 9a7b75d | 2004-11-23 14:07:46 +0000 | [diff] [blame] | 9 | |
sewardj | e6c53e0 | 2011-10-23 07:33:43 +0000 | [diff] [blame] | 10 | Copyright (C) 2004-2011 OpenWorks LLP |
sewardj | 752f906 | 2010-05-03 21:38:49 +0000 | [diff] [blame] | 11 | info@open-works.net |
sewardj | 9a7b75d | 2004-11-23 14:07:46 +0000 | [diff] [blame] | 12 | |
sewardj | 752f906 | 2010-05-03 21:38:49 +0000 | [diff] [blame] | 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. |
sewardj | 9a7b75d | 2004-11-23 14:07:46 +0000 | [diff] [blame] | 17 | |
sewardj | 752f906 | 2010-05-03 21:38:49 +0000 | [diff] [blame] | 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 |
sewardj | 7bd6ffe | 2005-08-03 16:07:36 +0000 | [diff] [blame] | 26 | 02110-1301, USA. |
| 27 | |
sewardj | 752f906 | 2010-05-03 21:38:49 +0000 | [diff] [blame] | 28 | The GNU General Public License is contained in the file COPYING. |
sewardj | 9a7b75d | 2004-11-23 14:07:46 +0000 | [diff] [blame] | 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. |
sewardj | 9a7b75d | 2004-11-23 14:07:46 +0000 | [diff] [blame] | 34 | */ |
| 35 | |
| 36 | #ifndef __LIBVEX_PUB_GUEST_AMD64_H |
| 37 | #define __LIBVEX_PUB_GUEST_AMD64_H |
| 38 | |
| 39 | #include "libvex_basictypes.h" |
njn | d93ee4c | 2004-11-30 11:37:48 +0000 | [diff] [blame] | 40 | #include "libvex_emwarn.h" |
| 41 | |
sewardj | 9a7b75d | 2004-11-23 14:07:46 +0000 | [diff] [blame] | 42 | |
| 43 | /*---------------------------------------------------------------*/ |
| 44 | /*--- Vex's representation of the AMD64 CPU state. ---*/ |
| 45 | /*---------------------------------------------------------------*/ |
| 46 | |
sewardj | cb6091d | 2005-02-21 08:23:39 +0000 | [diff] [blame] | 47 | /* See detailed comments at the top of libvex_guest_x86.h for |
sewardj | 8d96531 | 2005-02-25 02:48:47 +0000 | [diff] [blame] | 48 | further info. This representation closely follows the |
sewardj | cb6091d | 2005-02-21 08:23:39 +0000 | [diff] [blame] | 49 | x86 representation. |
sewardj | cb6091d | 2005-02-21 08:23:39 +0000 | [diff] [blame] | 50 | */ |
| 51 | |
| 52 | |
sewardj | 9a7b75d | 2004-11-23 14:07:46 +0000 | [diff] [blame] | 53 | typedef |
| 54 | struct { |
sewardj | c6f970f | 2012-04-02 21:54:49 +0000 | [diff] [blame^] | 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; |
sewardj | 9a7b75d | 2004-11-23 14:07:46 +0000 | [diff] [blame] | 76 | /* 4-word thunk used to calculate O S Z A C P flags. */ |
sewardj | c6f970f | 2012-04-02 21:54:49 +0000 | [diff] [blame^] | 77 | /* 144 */ ULong guest_CC_OP; |
| 78 | /* 152 */ ULong guest_CC_DEP1; |
| 79 | /* 160 */ ULong guest_CC_DEP2; |
| 80 | /* 168 */ ULong guest_CC_NDEP; |
sewardj | d0a12df | 2005-02-10 02:07:43 +0000 | [diff] [blame] | 81 | /* The D flag is stored here, encoded as either -1 or +1 */ |
sewardj | c6f970f | 2012-04-02 21:54:49 +0000 | [diff] [blame^] | 82 | /* 176 */ ULong guest_DFLAG; |
| 83 | /* 184 */ ULong guest_RIP; |
sewardj | 5e120aa | 2010-09-28 15:59:04 +0000 | [diff] [blame] | 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. */ |
sewardj | c6f970f | 2012-04-02 21:54:49 +0000 | [diff] [blame^] | 87 | /* 192 */ ULong guest_IDFLAG; |
sewardj | 9a7b75d | 2004-11-23 14:07:46 +0000 | [diff] [blame] | 88 | /* Probably a lot more stuff too. |
njn | 95f7386 | 2004-11-28 16:05:46 +0000 | [diff] [blame] | 89 | D,ID flags |
sewardj | 9a7b75d | 2004-11-23 14:07:46 +0000 | [diff] [blame] | 90 | 16 128-bit SSE registers |
| 91 | all the old x87 FPU gunk |
sewardj | 5e120aa | 2010-09-28 15:59:04 +0000 | [diff] [blame] | 92 | segment registers */ |
sewardj | 85520e4 | 2005-02-19 15:22:38 +0000 | [diff] [blame] | 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. */ |
sewardj | c6f970f | 2012-04-02 21:54:49 +0000 | [diff] [blame^] | 97 | /* 200 */ ULong guest_FS_ZERO; |
sewardj | a6b93d1 | 2005-02-17 09:28:28 +0000 | [diff] [blame] | 98 | |
sewardj | 0b2d3fe | 2010-08-06 07:59:38 +0000 | [diff] [blame] | 99 | /* XMM 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. XMM16 is a fake reg used |
| 102 | as an intermediary in handling aforementioned insns. */ |
sewardj | c6f970f | 2012-04-02 21:54:49 +0000 | [diff] [blame^] | 103 | /* 208 */ULong guest_SSEROUND; |
| 104 | /* 216 */U128 guest_XMM0; |
sewardj | cb6091d | 2005-02-21 08:23:39 +0000 | [diff] [blame] | 105 | U128 guest_XMM1; |
| 106 | U128 guest_XMM2; |
| 107 | U128 guest_XMM3; |
| 108 | U128 guest_XMM4; |
| 109 | U128 guest_XMM5; |
| 110 | U128 guest_XMM6; |
| 111 | U128 guest_XMM7; |
| 112 | U128 guest_XMM8; |
| 113 | U128 guest_XMM9; |
| 114 | U128 guest_XMM10; |
| 115 | U128 guest_XMM11; |
| 116 | U128 guest_XMM12; |
| 117 | U128 guest_XMM13; |
| 118 | U128 guest_XMM14; |
| 119 | U128 guest_XMM15; |
sewardj | 0b2d3fe | 2010-08-06 07:59:38 +0000 | [diff] [blame] | 120 | U128 guest_XMM16; |
sewardj | cb6091d | 2005-02-21 08:23:39 +0000 | [diff] [blame] | 121 | |
sewardj | 8d96531 | 2005-02-25 02:48:47 +0000 | [diff] [blame] | 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. */ |
sewardj | c6f970f | 2012-04-02 21:54:49 +0000 | [diff] [blame^] | 126 | UInt guest_FTOP; |
sewardj | 8d96531 | 2005-02-25 02:48:47 +0000 | [diff] [blame] | 127 | ULong guest_FPREG[8]; |
sewardj | c6f970f | 2012-04-02 21:54:49 +0000 | [diff] [blame^] | 128 | UChar guest_FPTAG[8]; |
| 129 | ULong guest_FPROUND; |
| 130 | ULong guest_FC3210; |
sewardj | 8d96531 | 2005-02-25 02:48:47 +0000 | [diff] [blame] | 131 | |
sewardj | 893aada | 2004-11-29 19:57:54 +0000 | [diff] [blame] | 132 | /* Emulation warnings */ |
sewardj | c6f970f | 2012-04-02 21:54:49 +0000 | [diff] [blame^] | 133 | UInt guest_EMWARN; |
sewardj | 1f126c5 | 2005-03-16 13:57:58 +0000 | [diff] [blame] | 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 | |
sewardj | ce02aa7 | 2006-01-12 12:27:58 +0000 | [diff] [blame] | 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 | |
sewardj | d660d41 | 2008-12-03 21:29:59 +0000 | [diff] [blame] | 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 | |
sewardj | e86310f | 2009-03-19 22:21:40 +0000 | [diff] [blame] | 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 | |
sewardj | 478646f | 2008-05-01 20:13:04 +0000 | [diff] [blame] | 168 | /* Padding to make it have an 16-aligned size */ |
sewardj | c6f970f | 2012-04-02 21:54:49 +0000 | [diff] [blame^] | 169 | ULong pad1; |
sewardj | 9a7b75d | 2004-11-23 14:07:46 +0000 | [diff] [blame] | 170 | } |
| 171 | VexGuestAMD64State; |
| 172 | |
| 173 | |
| 174 | |
| 175 | /*---------------------------------------------------------------*/ |
| 176 | /*--- Utility functions for amd64 guest stuff. ---*/ |
| 177 | /*---------------------------------------------------------------*/ |
| 178 | |
sewardj | 9a7b75d | 2004-11-23 14:07:46 +0000 | [diff] [blame] | 179 | /* ALL THE FOLLOWING ARE VISIBLE TO LIBRARY CLIENT */ |
| 180 | |
sewardj | 65526c2 | 2005-01-20 19:43:56 +0000 | [diff] [blame] | 181 | /* Initialise all guest amd64 state. The FPU is put in default |
| 182 | mode. */ |
sewardj | 9a7b75d | 2004-11-23 14:07:46 +0000 | [diff] [blame] | 183 | extern |
njn | 9c6acb0 | 2004-11-30 15:56:47 +0000 | [diff] [blame] | 184 | void LibVEX_GuestAMD64_initialise ( /*OUT*/VexGuestAMD64State* vex_state ); |
sewardj | 9a7b75d | 2004-11-23 14:07:46 +0000 | [diff] [blame] | 185 | |
| 186 | |
sewardj | 7de0d3c | 2005-02-13 02:26:41 +0000 | [diff] [blame] | 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 | |
sewardj | d660d41 | 2008-12-03 21:29:59 +0000 | [diff] [blame] | 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 | |
sewardj | 7de0d3c | 2005-02-13 02:26:41 +0000 | [diff] [blame] | 199 | |
njn | 9c6acb0 | 2004-11-30 15:56:47 +0000 | [diff] [blame] | 200 | #if 0 |
sewardj | 9a7b75d | 2004-11-23 14:07:46 +0000 | [diff] [blame] | 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 | |
sewardj | 9a7b75d | 2004-11-23 14:07:46 +0000 | [diff] [blame] | 224 | #endif /* 0 */ |
| 225 | |
| 226 | #endif /* ndef __LIBVEX_PUB_GUEST_AMD64_H */ |
| 227 | |
| 228 | /*---------------------------------------------------------------*/ |
| 229 | /*--- libvex_guest_amd64.h ---*/ |
| 230 | /*---------------------------------------------------------------*/ |