blob: 7d5d354ed92608118eadeae4813280e59a791d58 [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
sewardje6c53e02011-10-23 07:33:43 +000010 Copyright (C) 2004-2011 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#include "libvex_emwarn.h"
41
sewardj9a7b75d2004-11-23 14:07:46 +000042
43/*---------------------------------------------------------------*/
44/*--- Vex's representation of the AMD64 CPU state. ---*/
45/*---------------------------------------------------------------*/
46
sewardjcb6091d2005-02-21 08:23:39 +000047/* See detailed comments at the top of libvex_guest_x86.h for
sewardj8d965312005-02-25 02:48:47 +000048 further info. This representation closely follows the
sewardjcb6091d2005-02-21 08:23:39 +000049 x86 representation.
sewardjcb6091d2005-02-21 08:23:39 +000050*/
51
52
sewardj9a7b75d2004-11-23 14:07:46 +000053typedef
54 struct {
sewardjc6f970f2012-04-02 21:54:49 +000055 /* 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;
sewardj9a7b75d2004-11-23 14:07:46 +000076 /* 4-word thunk used to calculate O S Z A C P flags. */
sewardjc6f970f2012-04-02 21:54:49 +000077 /* 144 */ ULong guest_CC_OP;
78 /* 152 */ ULong guest_CC_DEP1;
79 /* 160 */ ULong guest_CC_DEP2;
80 /* 168 */ ULong guest_CC_NDEP;
sewardjd0a12df2005-02-10 02:07:43 +000081 /* The D flag is stored here, encoded as either -1 or +1 */
sewardjc6f970f2012-04-02 21:54:49 +000082 /* 176 */ ULong guest_DFLAG;
83 /* 184 */ ULong guest_RIP;
sewardj5e120aa2010-09-28 15:59:04 +000084 /* 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. */
sewardjc6f970f2012-04-02 21:54:49 +000087 /* 192 */ ULong guest_IDFLAG;
sewardj9a7b75d2004-11-23 14:07:46 +000088 /* Probably a lot more stuff too.
njn95f73862004-11-28 16:05:46 +000089 D,ID flags
sewardj9a7b75d2004-11-23 14:07:46 +000090 16 128-bit SSE registers
91 all the old x87 FPU gunk
sewardj5e120aa2010-09-28 15:59:04 +000092 segment registers */
sewardj85520e42005-02-19 15:22:38 +000093
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. */
sewardjc6f970f2012-04-02 21:54:49 +000097 /* 200 */ ULong guest_FS_ZERO;
sewardja6b93d12005-02-17 09:28:28 +000098
sewardj0b2d3fe2010-08-06 07:59:38 +000099 /* 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. */
sewardjc6f970f2012-04-02 21:54:49 +0000103 /* 208 */ULong guest_SSEROUND;
104 /* 216 */U128 guest_XMM0;
sewardjcb6091d2005-02-21 08:23:39 +0000105 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;
sewardj0b2d3fe2010-08-06 07:59:38 +0000120 U128 guest_XMM16;
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;
sewardj8d965312005-02-25 02:48:47 +0000127 ULong guest_FPREG[8];
sewardjc6f970f2012-04-02 21:54:49 +0000128 UChar guest_FPTAG[8];
129 ULong guest_FPROUND;
130 ULong guest_FC3210;
sewardj8d965312005-02-25 02:48:47 +0000131
sewardj893aada2004-11-29 19:57:54 +0000132 /* Emulation warnings */
sewardjc6f970f2012-04-02 21:54:49 +0000133 UInt guest_EMWARN;
sewardj1f126c52005-03-16 13:57:58 +0000134
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
sewardjce02aa72006-01-12 12:27:58 +0000145 /* 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
sewardjd660d412008-12-03 21:29:59 +0000153 /* 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
sewardje86310f2009-03-19 22:21:40 +0000162 /* 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
sewardj478646f2008-05-01 20:13:04 +0000168 /* Padding to make it have an 16-aligned size */
sewardjc6f970f2012-04-02 21:54:49 +0000169 ULong pad1;
sewardj9a7b75d2004-11-23 14:07:46 +0000170 }
171 VexGuestAMD64State;
172
173
174
175/*---------------------------------------------------------------*/
176/*--- Utility functions for amd64 guest stuff. ---*/
177/*---------------------------------------------------------------*/
178
sewardj9a7b75d2004-11-23 14:07:46 +0000179/* ALL THE FOLLOWING ARE VISIBLE TO LIBRARY CLIENT */
180
sewardj65526c22005-01-20 19:43:56 +0000181/* Initialise all guest amd64 state. The FPU is put in default
182 mode. */
sewardj9a7b75d2004-11-23 14:07:46 +0000183extern
njn9c6acb02004-11-30 15:56:47 +0000184void LibVEX_GuestAMD64_initialise ( /*OUT*/VexGuestAMD64State* vex_state );
sewardj9a7b75d2004-11-23 14:07:46 +0000185
186
sewardj7de0d3c2005-02-13 02:26:41 +0000187/* Extract from the supplied VexGuestAMD64State structure the
188 corresponding native %rflags value. */
189extern
190ULong LibVEX_GuestAMD64_get_rflags ( /*IN*/VexGuestAMD64State* vex_state );
191
sewardjd660d412008-12-03 21:29:59 +0000192/* Set the carry flag in the given state to 'new_carry_flag', which
193 should be zero or one. */
194extern
195void
196LibVEX_GuestAMD64_put_rflag_c ( ULong new_carry_flag,
197 /*MOD*/VexGuestAMD64State* vex_state );
198
sewardj7de0d3c2005-02-13 02:26:41 +0000199
njn9c6acb02004-11-30 15:56:47 +0000200#if 0
sewardj9a7b75d2004-11-23 14:07:46 +0000201/* 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*/
205extern
206void 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. */
211extern
212void 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
220extern
221void LibVEX_GuestX86_put_eflags ( UInt eflags_native,
222 /*OUT*/VexGuestX86State* vex_state );
223
sewardj9a7b75d2004-11-23 14:07:46 +0000224#endif /* 0 */
225
226#endif /* ndef __LIBVEX_PUB_GUEST_AMD64_H */
227
228/*---------------------------------------------------------------*/
229/*--- libvex_guest_amd64.h ---*/
230/*---------------------------------------------------------------*/