blob: 1043b20c0d81c296fcd5896526d0399c6ea86f1f [file] [log] [blame]
sewardj9a7b75d2004-11-23 14:07:46 +00001
2/*---------------------------------------------------------------*/
sewardj752f9062010-05-03 21:38:49 +00003/*--- begin libvex_guest_amd64.h ---*/
sewardj9a7b75d2004-11-23 14:07:46 +00004/*---------------------------------------------------------------*/
5
6/*
sewardj752f9062010-05-03 21:38:49 +00007 This file is part of Valgrind, a dynamic binary instrumentation
8 framework.
sewardj9a7b75d2004-11-23 14:07:46 +00009
sewardj89ae8472013-10-18 14:12:58 +000010 Copyright (C) 2004-2013 OpenWorks LLP
sewardj752f9062010-05-03 21:38:49 +000011 info@open-works.net
sewardj9a7b75d2004-11-23 14:07:46 +000012
sewardj752f9062010-05-03 21:38:49 +000013 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.
sewardj9a7b75d2004-11-23 14:07:46 +000017
sewardj752f9062010-05-03 21:38:49 +000018 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
sewardj7bd6ffe2005-08-03 16:07:36 +000026 02110-1301, USA.
27
sewardj752f9062010-05-03 21:38:49 +000028 The GNU General Public License is contained in the file COPYING.
sewardj9a7b75d2004-11-23 14:07:46 +000029
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.
sewardj9a7b75d2004-11-23 14:07:46 +000034*/
35
36#ifndef __LIBVEX_PUB_GUEST_AMD64_H
37#define __LIBVEX_PUB_GUEST_AMD64_H
38
39#include "libvex_basictypes.h"
njnd93ee4c2004-11-30 11:37:48 +000040
sewardj9a7b75d2004-11-23 14:07:46 +000041
42/*---------------------------------------------------------------*/
43/*--- Vex's representation of the AMD64 CPU state. ---*/
44/*---------------------------------------------------------------*/
45
sewardjcb6091d2005-02-21 08:23:39 +000046/* See detailed comments at the top of libvex_guest_x86.h for
sewardj8d965312005-02-25 02:48:47 +000047 further info. This representation closely follows the
sewardjcb6091d2005-02-21 08:23:39 +000048 x86 representation.
sewardjcb6091d2005-02-21 08:23:39 +000049*/
50
51
sewardj9a7b75d2004-11-23 14:07:46 +000052typedef
53 struct {
sewardjc6f970f2012-04-02 21:54:49 +000054 /* 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;
sewardj9a7b75d2004-11-23 14:07:46 +000075 /* 4-word thunk used to calculate O S Z A C P flags. */
sewardjc6f970f2012-04-02 21:54:49 +000076 /* 144 */ ULong guest_CC_OP;
77 /* 152 */ ULong guest_CC_DEP1;
78 /* 160 */ ULong guest_CC_DEP2;
79 /* 168 */ ULong guest_CC_NDEP;
sewardjd0a12df2005-02-10 02:07:43 +000080 /* The D flag is stored here, encoded as either -1 or +1 */
sewardjc6f970f2012-04-02 21:54:49 +000081 /* 176 */ ULong guest_DFLAG;
82 /* 184 */ ULong guest_RIP;
sewardj5e120aa2010-09-28 15:59:04 +000083 /* 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. */
sewardjc6f970f2012-04-02 21:54:49 +000086 /* 192 */ ULong guest_IDFLAG;
sewardj9a7b75d2004-11-23 14:07:46 +000087 /* Probably a lot more stuff too.
njn95f73862004-11-28 16:05:46 +000088 D,ID flags
sewardj9a7b75d2004-11-23 14:07:46 +000089 16 128-bit SSE registers
90 all the old x87 FPU gunk
sewardj5e120aa2010-09-28 15:59:04 +000091 segment registers */
sewardj85520e42005-02-19 15:22:38 +000092
philippee2cc4de2014-12-16 23:57:51 +000093 /* HACK to e.g. make tls on amd64-linux work. %fs only ever seems to
94 hold a constant value (zero on linux main thread, 0x63 in other
95 threads), and so guest_FS_CONST holds
96 the 64-bit offset associated with this constant %fs value. */
97 /* 200 */ ULong guest_FS_CONST;
sewardja6b93d12005-02-17 09:28:28 +000098
sewardjc4530ae2012-05-21 10:18:49 +000099 /* YMM registers. Note that these must be allocated
sewardj0b2d3fe2010-08-06 07:59:38 +0000100 consecutively in order that the SSE4.2 PCMP{E,I}STR{I,M}
sewardjc4530ae2012-05-21 10:18:49 +0000101 helpers can treat them as an array. YMM16 is a fake reg used
sewardj0b2d3fe2010-08-06 07:59:38 +0000102 as an intermediary in handling aforementioned insns. */
sewardjc6f970f2012-04-02 21:54:49 +0000103 /* 208 */ULong guest_SSEROUND;
sewardjc4530ae2012-05-21 10:18:49 +0000104 /* 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;
sewardjcb6091d2005-02-21 08:23:39 +0000121
sewardj8d965312005-02-25 02:48:47 +0000122 /* 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. */
sewardjc6f970f2012-04-02 21:54:49 +0000126 UInt guest_FTOP;
philippe7e5aa0d2015-04-11 14:32:53 +0000127 UInt pad1;
sewardj8d965312005-02-25 02:48:47 +0000128 ULong guest_FPREG[8];
sewardjc6f970f2012-04-02 21:54:49 +0000129 UChar guest_FPTAG[8];
130 ULong guest_FPROUND;
131 ULong guest_FC3210;
sewardj8d965312005-02-25 02:48:47 +0000132
florian6ef84be2012-08-26 03:20:07 +0000133 /* Emulation notes */
134 UInt guest_EMNOTE;
philippe7e5aa0d2015-04-11 14:32:53 +0000135 UInt pad2;
sewardj1f126c52005-03-16 13:57:58 +0000136
137 /* Translation-invalidation area description. Not used on amd64
138 (there is no invalidate-icache insn), but needed so as to
139 allow users of the library to uniformly assume that the guest
140 state contains these two fields -- otherwise there is
141 compilation breakage. On amd64, these two fields are set to
142 zero by LibVEX_GuestAMD64_initialise and then should be
143 ignored forever thereafter. */
sewardj05f5e012014-05-04 10:52:11 +0000144 ULong guest_CMSTART;
145 ULong guest_CMLEN;
sewardj1f126c52005-03-16 13:57:58 +0000146
sewardjce02aa72006-01-12 12:27:58 +0000147 /* Used to record the unredirected guest address at the start of
148 a translation whose start has been redirected. By reading
149 this pseudo-register shortly afterwards, the translation can
150 find out what the corresponding no-redirection address was.
151 Note, this is only set for wrap-style redirects, not for
152 replace-style ones. */
153 ULong guest_NRADDR;
154
sewardjd660d412008-12-03 21:29:59 +0000155 /* Used for Darwin syscall dispatching. */
156 ULong guest_SC_CLASS;
157
philippee2cc4de2014-12-16 23:57:51 +0000158 /* HACK to make e.g. tls on darwin work, wine on linux work, ...
159 %gs only ever seems to hold a constant value (e.g. 0x60 on darwin,
160 0x6b on linux), and so guest_GS_CONST holds the 64-bit offset
161 associated with this constant %gs value. (A direct analogue
162 of the %fs-const hack for amd64-linux). */
163 ULong guest_GS_CONST;
sewardjd660d412008-12-03 21:29:59 +0000164
sewardje86310f2009-03-19 22:21:40 +0000165 /* Needed for Darwin (but mandated for all guest architectures):
166 RIP at the last syscall insn (int 0x80/81/82, sysenter,
167 syscall). Used when backing up to restart a syscall that has
168 been interrupted by a signal. */
169 ULong guest_IP_AT_SYSCALL;
170
sewardj478646f2008-05-01 20:13:04 +0000171 /* Padding to make it have an 16-aligned size */
philippe7e5aa0d2015-04-11 14:32:53 +0000172 ULong pad3;
sewardj9a7b75d2004-11-23 14:07:46 +0000173 }
174 VexGuestAMD64State;
175
176
177
178/*---------------------------------------------------------------*/
179/*--- Utility functions for amd64 guest stuff. ---*/
180/*---------------------------------------------------------------*/
181
sewardj9a7b75d2004-11-23 14:07:46 +0000182/* ALL THE FOLLOWING ARE VISIBLE TO LIBRARY CLIENT */
183
sewardj65526c22005-01-20 19:43:56 +0000184/* Initialise all guest amd64 state. The FPU is put in default
185 mode. */
sewardj9a7b75d2004-11-23 14:07:46 +0000186extern
njn9c6acb02004-11-30 15:56:47 +0000187void LibVEX_GuestAMD64_initialise ( /*OUT*/VexGuestAMD64State* vex_state );
sewardj9a7b75d2004-11-23 14:07:46 +0000188
189
sewardj7de0d3c2005-02-13 02:26:41 +0000190/* Extract from the supplied VexGuestAMD64State structure the
191 corresponding native %rflags value. */
192extern
florianefa834a2012-11-24 21:07:14 +0000193ULong LibVEX_GuestAMD64_get_rflags ( /*IN*/const VexGuestAMD64State* vex_state );
sewardj7de0d3c2005-02-13 02:26:41 +0000194
sewardjd660d412008-12-03 21:29:59 +0000195/* Set the carry flag in the given state to 'new_carry_flag', which
196 should be zero or one. */
197extern
198void
199LibVEX_GuestAMD64_put_rflag_c ( ULong new_carry_flag,
200 /*MOD*/VexGuestAMD64State* vex_state );
201
sewardj7de0d3c2005-02-13 02:26:41 +0000202
sewardj9a7b75d2004-11-23 14:07:46 +0000203#endif /* ndef __LIBVEX_PUB_GUEST_AMD64_H */
204
205/*---------------------------------------------------------------*/
206/*--- libvex_guest_amd64.h ---*/
207/*---------------------------------------------------------------*/