Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:13:29

0001 
0002 /*---------------------------------------------------------------*/
0003 /*--- begin                              libvex_guest_amd64.h ---*/
0004 /*---------------------------------------------------------------*/
0005 
0006 /*
0007    This file is part of Valgrind, a dynamic binary instrumentation
0008    framework.
0009 
0010    Copyright (C) 2004-2017 OpenWorks LLP
0011       info@open-works.net
0012 
0013    This program is free software; you can redistribute it and/or
0014    modify it under the terms of the GNU General Public License as
0015    published by the Free Software Foundation; either version 2 of the
0016    License, or (at your option) any later version.
0017 
0018    This program is distributed in the hope that it will be useful, but
0019    WITHOUT ANY WARRANTY; without even the implied warranty of
0020    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0021    General Public License for more details.
0022 
0023    You should have received a copy of the GNU General Public License
0024    along with this program; if not, see <http://www.gnu.org/licenses/>.
0025 
0026    The GNU General Public License is contained in the file COPYING.
0027 
0028    Neither the names of the U.S. Department of Energy nor the
0029    University of California nor the names of its contributors may be
0030    used to endorse or promote products derived from this software
0031    without prior written permission.
0032 */
0033 
0034 #ifndef __LIBVEX_PUB_GUEST_AMD64_H
0035 #define __LIBVEX_PUB_GUEST_AMD64_H
0036 
0037 #include "libvex_basictypes.h"
0038 #include "libvex_emnote.h"
0039 
0040 
0041 /*---------------------------------------------------------------*/
0042 /*--- Vex's representation of the AMD64 CPU state.            ---*/
0043 /*---------------------------------------------------------------*/
0044 
0045 /* See detailed comments at the top of libvex_guest_x86.h for
0046    further info.  This representation closely follows the
0047    x86 representation.
0048 */
0049 
0050 
0051 typedef
0052    struct {
0053       /* Event check fail addr, counter, and padding to make RAX 16
0054          aligned. */
0055       /*   0 */ ULong  host_EvC_FAILADDR;
0056       /*   8 */ UInt   host_EvC_COUNTER;
0057       /*  12 */ UInt   pad0;
0058       /*  16 */ ULong  guest_RAX;
0059       /*  24 */ ULong  guest_RCX;
0060       /*  32 */ ULong  guest_RDX;
0061       /*  40 */ ULong  guest_RBX;
0062       /*  48 */ ULong  guest_RSP;
0063       /*  56 */ ULong  guest_RBP;
0064       /*  64 */ ULong  guest_RSI;
0065       /*  72 */ ULong  guest_RDI;
0066       /*  80 */ ULong  guest_R8;
0067       /*  88 */ ULong  guest_R9;
0068       /*  96 */ ULong  guest_R10;
0069       /* 104 */ ULong  guest_R11;
0070       /* 112 */ ULong  guest_R12;
0071       /* 120 */ ULong  guest_R13;
0072       /* 128 */ ULong  guest_R14;
0073       /* 136 */ ULong  guest_R15;
0074       /* 4-word thunk used to calculate O S Z A C P flags. */
0075       /* 144 */ ULong  guest_CC_OP;
0076       /* 152 */ ULong  guest_CC_DEP1;
0077       /* 160 */ ULong  guest_CC_DEP2;
0078       /* 168 */ ULong  guest_CC_NDEP;
0079       /* The D flag is stored here, encoded as either -1 or +1 */
0080       /* 176 */ ULong  guest_DFLAG;
0081       /* 184 */ ULong  guest_RIP;
0082       /* Bit 18 (AC) of eflags stored here, as either 0 or 1. */
0083       /* ... */ ULong  guest_ACFLAG;
0084       /* Bit 21 (ID) of eflags stored here, as either 0 or 1. */
0085       /* 192 */ ULong guest_IDFLAG;
0086       /* Probably a lot more stuff too. 
0087          D,ID flags
0088          16  128-bit SSE registers
0089          all the old x87 FPU gunk
0090          segment registers */
0091 
0092       /* HACK to e.g. make tls on amd64-linux/solaris work.  %fs only ever seems
0093          to hold a constant value (zero on linux main thread, 0x63 in other
0094          threads), and so guest_FS_CONST holds
0095          the 64-bit offset associated with this constant %fs value. */
0096       /* 200 */ ULong guest_FS_CONST;
0097 
0098       /* YMM registers.  Note that these must be allocated
0099          consecutively in order that the SSE4.2 PCMP{E,I}STR{I,M}
0100          helpers can treat them as an array.  YMM16 is a fake reg used
0101          as an intermediary in handling aforementioned insns. */
0102       /* 208 */ULong guest_SSEROUND;
0103       /* 216 */U256  guest_YMM0;
0104       U256  guest_YMM1;
0105       U256  guest_YMM2;
0106       U256  guest_YMM3;
0107       U256  guest_YMM4;
0108       U256  guest_YMM5;
0109       U256  guest_YMM6;
0110       U256  guest_YMM7;
0111       U256  guest_YMM8;
0112       U256  guest_YMM9;
0113       U256  guest_YMM10;
0114       U256  guest_YMM11;
0115       U256  guest_YMM12;
0116       U256  guest_YMM13;
0117       U256  guest_YMM14;
0118       U256  guest_YMM15;
0119       U256  guest_YMM16;
0120 
0121       /* FPU */
0122       /* Note.  Setting guest_FTOP to be ULong messes up the
0123          delicately-balanced PutI/GetI optimisation machinery.
0124          Therefore best to leave it as a UInt. */
0125       UInt  guest_FTOP;
0126       UInt  pad1;
0127       ULong guest_FPREG[8];
0128       UChar guest_FPTAG[8];
0129       ULong guest_FPROUND;
0130       ULong guest_FC3210;
0131 
0132       /* Emulation notes */
0133       UInt  guest_EMNOTE;
0134       UInt  pad2;
0135 
0136       /* Translation-invalidation area description.  Not used on amd64
0137          (there is no invalidate-icache insn), but needed so as to
0138          allow users of the library to uniformly assume that the guest
0139          state contains these two fields -- otherwise there is
0140          compilation breakage.  On amd64, these two fields are set to
0141          zero by LibVEX_GuestAMD64_initialise and then should be
0142          ignored forever thereafter. */
0143       ULong guest_CMSTART;
0144       ULong guest_CMLEN;
0145 
0146       /* Used to record the unredirected guest address at the start of
0147          a translation whose start has been redirected.  By reading
0148          this pseudo-register shortly afterwards, the translation can
0149          find out what the corresponding no-redirection address was.
0150          Note, this is only set for wrap-style redirects, not for
0151          replace-style ones. */
0152       ULong guest_NRADDR;
0153 
0154       /* Used for Darwin syscall dispatching. */
0155       ULong guest_SC_CLASS;
0156 
0157       /* HACK to make e.g. tls on darwin work, wine on linux work, ...
0158          %gs only ever seems to hold a constant value (e.g. 0x60 on darwin,
0159          0x6b on linux), and so guest_GS_CONST holds the 64-bit offset
0160          associated with this constant %gs value.  (A direct analogue
0161          of the %fs-const hack for amd64-linux/solaris). */
0162       ULong guest_GS_CONST;
0163 
0164       /* Needed for Darwin (but mandated for all guest architectures):
0165          RIP at the last syscall insn (int 0x80/81/82, sysenter,
0166          syscall).  Used when backing up to restart a syscall that has
0167          been interrupted by a signal. */
0168       ULong guest_IP_AT_SYSCALL;
0169 
0170       /* Padding to make it have an 16-aligned size */
0171       ULong pad3;
0172    }
0173    VexGuestAMD64State;
0174 
0175 
0176 
0177 /*---------------------------------------------------------------*/
0178 /*--- Utility functions for amd64 guest stuff.                ---*/
0179 /*---------------------------------------------------------------*/
0180 
0181 /* ALL THE FOLLOWING ARE VISIBLE TO LIBRARY CLIENT */
0182 
0183 /* Initialise all guest amd64 state.  The FPU is put in default
0184    mode. */
0185 extern
0186 void LibVEX_GuestAMD64_initialise ( /*OUT*/VexGuestAMD64State* vex_state );
0187 
0188 
0189 /* Extract from the supplied VexGuestAMD64State structure the
0190    corresponding native %rflags value. */
0191 extern 
0192 ULong LibVEX_GuestAMD64_get_rflags ( /*IN*/const VexGuestAMD64State* vex_state );
0193 
0194 /* Put rflags into the given state. */
0195 extern
0196 void LibVEX_GuestAMD64_put_rflags ( ULong rflags,
0197                                     /*MOD*/VexGuestAMD64State* vex_state );
0198 
0199 /* Set the carry flag in the given state to 'new_carry_flag', which
0200    should be zero or one. */
0201 extern
0202 void
0203 LibVEX_GuestAMD64_put_rflag_c ( ULong new_carry_flag,
0204                                 /*MOD*/VexGuestAMD64State* vex_state );
0205 
0206 #if defined(VGO_freebsd) || defined(VGO_darwin)
0207 void _______VVVVVVVV_after_GuestAMD64_put_rflag_c_VVVVVVVV_______ (void);
0208 extern Addr addr_amd64g_calculate_rflags_all_WRK;
0209 extern Addr addr________VVVVVVVV_amd64g_calculate_rflags_all_WRK_VVVVVVVV_______;
0210 #endif
0211 
0212 
0213 /* Do FXSAVE from the supplied VexGuestAMD64tate structure and store the
0214    result at the given address which represents a buffer of at least 416
0215    bytes. */
0216 extern
0217 void LibVEX_GuestAMD64_fxsave ( /*IN*/VexGuestAMD64State* gst,
0218                                 /*OUT*/HWord fp_state );
0219 
0220 /* Do FXRSTOR from the supplied address and store read values to the given
0221    VexGuestAMD64State structure. */
0222 extern
0223 VexEmNote LibVEX_GuestAMD64_fxrstor ( /*IN*/HWord fp_state,
0224                                       /*MOD*/VexGuestAMD64State* gst );
0225 
0226 #endif /* ndef __LIBVEX_PUB_GUEST_AMD64_H */
0227 
0228 /*---------------------------------------------------------------*/
0229 /*---                                    libvex_guest_amd64.h ---*/
0230 /*---------------------------------------------------------------*/