2 /*---------------------------------------------------------------*/
3 /*--- begin libvex_guest_amd64.h ---*/
4 /*---------------------------------------------------------------*/
7 This file is part of Valgrind, a dynamic binary instrumentation
10 Copyright (C) 2004-2010 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, write to the Free Software
25 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
28 The GNU General Public License is contained in the file COPYING.
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.
36 #ifndef __LIBVEX_PUB_GUEST_AMD64_H
37 #define __LIBVEX_PUB_GUEST_AMD64_H
39 #include "libvex_basictypes.h"
40 #include "libvex_emwarn.h"
43 /*---------------------------------------------------------------*/
44 /*--- Vex's representation of the AMD64 CPU state. ---*/
45 /*---------------------------------------------------------------*/
47 /* See detailed comments at the top of libvex_guest_x86.h for
48 further info. This representation closely follows the
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 /* Probably a lot more stuff too.
81 16 128-bit SSE registers
82 all the old x87 FPU gunk
86 /* Bit 21 (ID) of eflags stored here, as either 0 or 1. */
87 /* 176 */ ULong guest_IDFLAG;
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;
95 /* 192 */ULong guest_SSEROUND;
96 /* 200 */U128 guest_XMM0;
114 /* Note. Setting guest_FTOP to be ULong messes up the
115 delicately-balanced PutI/GetI optimisation machinery.
116 Therefore best to leave it as a UInt. */
117 /* 456 */UInt guest_FTOP;
118 ULong guest_FPREG[8];
119 /* 528 */ UChar guest_FPTAG[8];
120 /* 536 */ ULong guest_FPROUND;
121 /* 544 */ ULong guest_FC3210;
123 /* Emulation warnings */
124 /* 552 */ UInt guest_EMWARN;
126 /* Translation-invalidation area description. Not used on amd64
127 (there is no invalidate-icache insn), but needed so as to
128 allow users of the library to uniformly assume that the guest
129 state contains these two fields -- otherwise there is
130 compilation breakage. On amd64, these two fields are set to
131 zero by LibVEX_GuestAMD64_initialise and then should be
132 ignored forever thereafter. */
136 /* Used to record the unredirected guest address at the start of
137 a translation whose start has been redirected. By reading
138 this pseudo-register shortly afterwards, the translation can
139 find out what the corresponding no-redirection address was.
140 Note, this is only set for wrap-style redirects, not for
141 replace-style ones. */
144 /* Used for Darwin syscall dispatching. */
145 ULong guest_SC_CLASS;
147 /* HACK to make tls on darwin work. %gs only ever seems to
148 hold 0x60, and so guest_GS_0x60 holds the 64-bit offset
149 associated with a %gs value of 0x60. (A direct analogue
150 of the %fs-zero hack for amd64-linux). */
153 /* Needed for Darwin (but mandated for all guest architectures):
154 RIP at the last syscall insn (int 0x80/81/82, sysenter,
155 syscall). Used when backing up to restart a syscall that has
156 been interrupted by a signal. */
157 ULong guest_IP_AT_SYSCALL;
159 /* Padding to make it have an 16-aligned size */
166 /*---------------------------------------------------------------*/
167 /*--- Utility functions for amd64 guest stuff. ---*/
168 /*---------------------------------------------------------------*/
170 /* ALL THE FOLLOWING ARE VISIBLE TO LIBRARY CLIENT */
172 /* Initialise all guest amd64 state. The FPU is put in default
175 void LibVEX_GuestAMD64_initialise ( /*OUT*/VexGuestAMD64State* vex_state );
178 /* Extract from the supplied VexGuestAMD64State structure the
179 corresponding native %rflags value. */
181 ULong LibVEX_GuestAMD64_get_rflags ( /*IN*/VexGuestAMD64State* vex_state );
183 /* Set the carry flag in the given state to 'new_carry_flag', which
184 should be zero or one. */
187 LibVEX_GuestAMD64_put_rflag_c ( ULong new_carry_flag,
188 /*MOD*/VexGuestAMD64State* vex_state );
192 /* Convert a saved x87 FPU image (as created by fsave) and write it
193 into the supplied VexGuestX86State structure. The non-FP parts of
194 said structure are left unchanged.
197 void LibVEX_GuestX86_put_x87 ( /*IN*/UChar* x87_state,
198 /*OUT*/VexGuestX86State* vex_state );
200 /* Extract from the supplied VexGuestX86State structure, an x87 FPU
203 void LibVEX_GuestX86_get_x87 ( /*IN*/VexGuestX86State* vex_state,
204 /*OUT*/UChar* x87_state );
207 /* Given a 32-bit word containing native x86 %eflags values, set the
208 eflag-related fields in the supplied VexGuestX86State accordingly.
209 All other fields are left unchanged. */
212 void LibVEX_GuestX86_put_eflags ( UInt eflags_native,
213 /*OUT*/VexGuestX86State* vex_state );
217 #endif /* ndef __LIBVEX_PUB_GUEST_AMD64_H */
219 /*---------------------------------------------------------------*/
220 /*--- libvex_guest_amd64.h ---*/
221 /*---------------------------------------------------------------*/