2 /*---------------------------------------------------------------*/
3 /*--- begin libvex_guest_amd64.h ---*/
4 /*---------------------------------------------------------------*/
7 This file is part of Valgrind, a dynamic binary instrumentation
10 Copyright (C) 2004-2017 OpenWorks LLP
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.
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.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, see <http://www.gnu.org/licenses/>.
26 The GNU General Public License is contained in the file COPYING.
28 Neither the names of the U.S. Department of Energy nor the
29 University of California nor the names of its contributors may be
30 used to endorse or promote products derived from this software
31 without prior written permission.
34 #ifndef __LIBVEX_PUB_GUEST_AMD64_H
35 #define __LIBVEX_PUB_GUEST_AMD64_H
37 #include "libvex_basictypes.h"
38 #include "libvex_emnote.h"
41 /*---------------------------------------------------------------*/
42 /*--- Vex's representation of the AMD64 CPU state. ---*/
43 /*---------------------------------------------------------------*/
45 /* See detailed comments at the top of libvex_guest_x86.h for
46 further info. This representation closely follows the
53 /* Event check fail addr, counter, and padding to make RAX 16
55 /* 0 */ ULong host_EvC_FAILADDR
;
56 /* 8 */ UInt host_EvC_COUNTER
;
58 /* 16 */ ULong guest_RAX
;
59 /* 24 */ ULong guest_RCX
;
60 /* 32 */ ULong guest_RDX
;
61 /* 40 */ ULong guest_RBX
;
62 /* 48 */ ULong guest_RSP
;
63 /* 56 */ ULong guest_RBP
;
64 /* 64 */ ULong guest_RSI
;
65 /* 72 */ ULong guest_RDI
;
66 /* 80 */ ULong guest_R8
;
67 /* 88 */ ULong guest_R9
;
68 /* 96 */ ULong guest_R10
;
69 /* 104 */ ULong guest_R11
;
70 /* 112 */ ULong guest_R12
;
71 /* 120 */ ULong guest_R13
;
72 /* 128 */ ULong guest_R14
;
73 /* 136 */ ULong guest_R15
;
74 /* 4-word thunk used to calculate O S Z A C P flags. */
75 /* 144 */ ULong guest_CC_OP
;
76 /* 152 */ ULong guest_CC_DEP1
;
77 /* 160 */ ULong guest_CC_DEP2
;
78 /* 168 */ ULong guest_CC_NDEP
;
79 /* The D flag is stored here, encoded as either -1 or +1 */
80 /* 176 */ ULong guest_DFLAG
;
81 /* 184 */ ULong guest_RIP
;
82 /* Bit 18 (AC) of eflags stored here, as either 0 or 1. */
83 /* ... */ ULong guest_ACFLAG
;
84 /* Bit 21 (ID) of eflags stored here, as either 0 or 1. */
85 /* 192 */ ULong guest_IDFLAG
;
86 /* Probably a lot more stuff too.
88 16 128-bit SSE registers
89 all the old x87 FPU gunk
92 /* HACK to e.g. make tls on amd64-linux/solaris work. %fs only ever seems
93 to hold a constant value (zero on linux main thread, 0x63 in other
94 threads), and so guest_FS_CONST holds
95 the 64-bit offset associated with this constant %fs value. */
96 /* 200 */ ULong guest_FS_CONST
;
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
;
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. */
127 ULong guest_FPREG
[8];
128 UChar guest_FPTAG
[8];
132 /* Emulation notes */
136 /* Translation-invalidation area description. Not used on amd64
137 (there is no invalidate-icache insn), but needed so as to
138 allow users of the library to uniformly assume that the guest
139 state contains these two fields -- otherwise there is
140 compilation breakage. On amd64, these two fields are set to
141 zero by LibVEX_GuestAMD64_initialise and then should be
142 ignored forever thereafter. */
146 /* Used to record the unredirected guest address at the start of
147 a translation whose start has been redirected. By reading
148 this pseudo-register shortly afterwards, the translation can
149 find out what the corresponding no-redirection address was.
150 Note, this is only set for wrap-style redirects, not for
151 replace-style ones. */
154 /* Used for Darwin syscall dispatching. */
155 ULong guest_SC_CLASS
;
157 /* HACK to make e.g. tls on darwin work, wine on linux work, ...
158 %gs only ever seems to hold a constant value (e.g. 0x60 on darwin,
159 0x6b on linux), and so guest_GS_CONST holds the 64-bit offset
160 associated with this constant %gs value. (A direct analogue
161 of the %fs-const hack for amd64-linux/solaris). */
162 ULong guest_GS_CONST
;
164 /* Needed for Darwin (but mandated for all guest architectures):
165 RIP at the last syscall insn (int 0x80/81/82, sysenter,
166 syscall). Used when backing up to restart a syscall that has
167 been interrupted by a signal. */
168 ULong guest_IP_AT_SYSCALL
;
170 /* Padding to make it have an 16-aligned size */
177 /*---------------------------------------------------------------*/
178 /*--- Utility functions for amd64 guest stuff. ---*/
179 /*---------------------------------------------------------------*/
181 /* ALL THE FOLLOWING ARE VISIBLE TO LIBRARY CLIENT */
183 /* Initialise all guest amd64 state. The FPU is put in default
186 void LibVEX_GuestAMD64_initialise ( /*OUT*/VexGuestAMD64State
* vex_state
);
189 /* Extract from the supplied VexGuestAMD64State structure the
190 corresponding native %rflags value. */
192 ULong
LibVEX_GuestAMD64_get_rflags ( /*IN*/const VexGuestAMD64State
* vex_state
);
194 /* Put rflags into the given state. */
196 void LibVEX_GuestAMD64_put_rflags ( ULong rflags
,
197 /*MOD*/VexGuestAMD64State
* vex_state
);
199 /* Set the carry flag in the given state to 'new_carry_flag', which
200 should be zero or one. */
203 LibVEX_GuestAMD64_put_rflag_c ( ULong new_carry_flag
,
204 /*MOD*/VexGuestAMD64State
* vex_state
);
206 #if defined(VGO_freebsd) || defined(VGO_darwin)
207 void _______VVVVVVVV_after_GuestAMD64_put_rflag_c_VVVVVVVV_______ (void);
208 extern Addr addr_amd64g_calculate_rflags_all_WRK
;
209 extern Addr addr________VVVVVVVV_amd64g_calculate_rflags_all_WRK_VVVVVVVV_______
;
213 /* Do FXSAVE from the supplied VexGuestAMD64tate structure and store the
214 result at the given address which represents a buffer of at least 416
217 void LibVEX_GuestAMD64_fxsave ( /*IN*/VexGuestAMD64State
* gst
,
218 /*OUT*/HWord fp_state
);
220 /* Do FXRSTOR from the supplied address and store read values to the given
221 VexGuestAMD64State structure. */
223 VexEmNote
LibVEX_GuestAMD64_fxrstor ( /*IN*/HWord fp_state
,
224 /*MOD*/VexGuestAMD64State
* gst
);
226 #endif /* ndef __LIBVEX_PUB_GUEST_AMD64_H */
228 /*---------------------------------------------------------------*/
229 /*--- libvex_guest_amd64.h ---*/
230 /*---------------------------------------------------------------*/