]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/valgrind/src/valgrind-3.6.0-svn/VEX/pub/libvex_guest_amd64.h
944f27e7645fef73ef61f82dffcabbc101c2e86b
[l4.git] / l4 / pkg / valgrind / src / valgrind-3.6.0-svn / VEX / pub / libvex_guest_amd64.h
1
2 /*---------------------------------------------------------------*/
3 /*--- begin                              libvex_guest_amd64.h ---*/
4 /*---------------------------------------------------------------*/
5
6 /*
7    This file is part of Valgrind, a dynamic binary instrumentation
8    framework.
9
10    Copyright (C) 2004-2010 OpenWorks LLP
11       info@open-works.net
12
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.
17
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
26    02110-1301, USA.
27
28    The GNU General Public License is contained in the file COPYING.
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.
34 */
35
36 #ifndef __LIBVEX_PUB_GUEST_AMD64_H
37 #define __LIBVEX_PUB_GUEST_AMD64_H
38
39 #include "libvex_basictypes.h"
40 #include "libvex_emwarn.h"
41
42
43 /*---------------------------------------------------------------*/
44 /*--- Vex's representation of the AMD64 CPU state.            ---*/
45 /*---------------------------------------------------------------*/
46
47 /* See detailed comments at the top of libvex_guest_x86.h for
48    further info.  This representation closely follows the
49    x86 representation.
50 */
51
52
53 typedef
54    struct {
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. 
80          D,ID flags
81          16  128-bit SSE registers
82          all the old x87 FPU gunk
83          segment registers
84       */
85
86       /* Bit 21 (ID) of eflags stored here, as either 0 or 1. */
87       /* 176 */ ULong guest_IDFLAG;
88
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;
93
94       /* XMM registers */
95       /* 192 */ULong guest_SSEROUND;
96       /* 200 */U128  guest_XMM0;
97       U128  guest_XMM1;
98       U128  guest_XMM2;
99       U128  guest_XMM3;
100       U128  guest_XMM4;
101       U128  guest_XMM5;
102       U128  guest_XMM6;
103       U128  guest_XMM7;
104       U128  guest_XMM8;
105       U128  guest_XMM9;
106       U128  guest_XMM10;
107       U128  guest_XMM11;
108       U128  guest_XMM12;
109       U128  guest_XMM13;
110       U128  guest_XMM14;
111       U128  guest_XMM15;
112
113       /* FPU */
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;
122
123       /* Emulation warnings */
124       /* 552 */ UInt  guest_EMWARN;
125
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. */
133       ULong guest_TISTART;
134       ULong guest_TILEN;
135
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. */
142       ULong guest_NRADDR;
143
144       /* Used for Darwin syscall dispatching. */
145       ULong guest_SC_CLASS;
146
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). */
151       ULong guest_GS_0x60;
152
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;
158
159       /* Padding to make it have an 16-aligned size */
160       /* ULong padding; */
161    }
162    VexGuestAMD64State;
163
164
165
166 /*---------------------------------------------------------------*/
167 /*--- Utility functions for amd64 guest stuff.                ---*/
168 /*---------------------------------------------------------------*/
169
170 /* ALL THE FOLLOWING ARE VISIBLE TO LIBRARY CLIENT */
171
172 /* Initialise all guest amd64 state.  The FPU is put in default
173    mode. */
174 extern
175 void LibVEX_GuestAMD64_initialise ( /*OUT*/VexGuestAMD64State* vex_state );
176
177
178 /* Extract from the supplied VexGuestAMD64State structure the
179    corresponding native %rflags value. */
180 extern 
181 ULong LibVEX_GuestAMD64_get_rflags ( /*IN*/VexGuestAMD64State* vex_state );
182
183 /* Set the carry flag in the given state to 'new_carry_flag', which
184    should be zero or one. */
185 extern
186 void
187 LibVEX_GuestAMD64_put_rflag_c ( ULong new_carry_flag,
188                                 /*MOD*/VexGuestAMD64State* vex_state );
189
190
191 #if 0
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.  
195 */
196 extern 
197 void LibVEX_GuestX86_put_x87 ( /*IN*/UChar* x87_state, 
198                                /*OUT*/VexGuestX86State* vex_state );
199
200 /* Extract from the supplied VexGuestX86State structure, an x87 FPU
201    image. */
202 extern 
203 void LibVEX_GuestX86_get_x87 ( /*IN*/VexGuestX86State* vex_state, 
204                                /*OUT*/UChar* x87_state );
205
206
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.  */
210
211 extern
212 void LibVEX_GuestX86_put_eflags ( UInt eflags_native,
213                                   /*OUT*/VexGuestX86State* vex_state );
214
215 #endif /* 0 */
216
217 #endif /* ndef __LIBVEX_PUB_GUEST_AMD64_H */
218
219 /*---------------------------------------------------------------*/
220 /*---                                    libvex_guest_amd64.h ---*/
221 /*---------------------------------------------------------------*/