blob: 855bc64f770153fa0839cac7a4e50b5a83f88c2e [file] [log] [blame]
sewardjac9af022004-07-05 01:15:34 +00001
2/*---------------------------------------------------------------*/
sewardj752f9062010-05-03 21:38:49 +00003/*--- begin libvex.h ---*/
sewardjac9af022004-07-05 01:15:34 +00004/*---------------------------------------------------------------*/
5
sewardjf8ed9d82004-11-12 17:40:23 +00006/*
sewardj752f9062010-05-03 21:38:49 +00007 This file is part of Valgrind, a dynamic binary instrumentation
8 framework.
sewardjf8ed9d82004-11-12 17:40:23 +00009
sewardj785952d2015-08-21 11:29:16 +000010 Copyright (C) 2004-2015 OpenWorks LLP
sewardj752f9062010-05-03 21:38:49 +000011 info@open-works.net
sewardjf8ed9d82004-11-12 17:40:23 +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.
sewardjf8ed9d82004-11-12 17:40:23 +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.
sewardjf8ed9d82004-11-12 17:40:23 +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.
sewardjf8ed9d82004-11-12 17:40:23 +000034*/
35
sewardj887a11a2004-07-05 17:26:47 +000036#ifndef __LIBVEX_H
37#define __LIBVEX_H
sewardjac9af022004-07-05 01:15:34 +000038
39
sewardj887a11a2004-07-05 17:26:47 +000040#include "libvex_basictypes.h"
41#include "libvex_ir.h"
sewardjac9af022004-07-05 01:15:34 +000042
43
44/*---------------------------------------------------------------*/
sewardjd887b862005-01-17 18:34:34 +000045/*--- This file defines the top-level interface to LibVEX. ---*/
sewardjac9af022004-07-05 01:15:34 +000046/*---------------------------------------------------------------*/
47
sewardjd887b862005-01-17 18:34:34 +000048/*-------------------------------------------------------*/
sewardj27e1dd62005-06-30 11:49:14 +000049/*--- Architectures, variants, and other arch info ---*/
sewardjd887b862005-01-17 18:34:34 +000050/*-------------------------------------------------------*/
sewardjbef170b2004-12-21 01:23:00 +000051
52typedef
53 enum {
sewardj9b769162014-07-24 12:42:03 +000054 VexArch_INVALID=0x400,
sewardjbef170b2004-12-21 01:23:00 +000055 VexArchX86,
56 VexArchAMD64,
cerion896a1372005-01-25 12:24:25 +000057 VexArchARM,
sewardjbbcf1882014-01-12 12:49:10 +000058 VexArchARM64,
ceriond953ebb2005-11-29 13:27:20 +000059 VexArchPPC32,
sewardj2019a972011-03-07 16:04:07 +000060 VexArchPPC64,
sewardjd0e5fe72012-06-07 08:51:02 +000061 VexArchS390X,
petarjb92a9542013-02-27 22:57:17 +000062 VexArchMIPS32,
sewardj0de80192015-04-10 12:27:40 +000063 VexArchMIPS64,
64 VexArchTILEGX
sewardjbef170b2004-12-21 01:23:00 +000065 }
66 VexArch;
67
sewardj5117ce12006-01-27 21:20:15 +000068
sewardj9b769162014-07-24 12:42:03 +000069/* Information about endianness. */
70typedef
71 enum {
72 VexEndness_INVALID=0x600, /* unknown endianness */
73 VexEndnessLE, /* little endian */
74 VexEndnessBE /* big endian */
75 }
76 VexEndness;
77
78
sewardj5117ce12006-01-27 21:20:15 +000079/* For a given architecture, these specify extra capabilities beyond
80 the minimum supported (baseline) capabilities. They may be OR'd
81 together, although some combinations don't make sense. (eg, SSE2
82 but not SSE1). LibVEX_Translate will check for nonsensical
83 combinations. */
84
sewardje9d8a262009-07-01 08:06:34 +000085/* x86: baseline capability is Pentium-1 (FPU, MMX, but no SSE), with
mjw6c65c122013-08-27 10:19:03 +000086 cmpxchg8b. MMXEXT is a special AMD only subset of SSE1 (Integer SSE). */
87#define VEX_HWCAPS_X86_MMXEXT (1<<1) /* A subset of SSE1 on early AMD */
88#define VEX_HWCAPS_X86_SSE1 (1<<2) /* SSE1 support (Pentium III) */
89#define VEX_HWCAPS_X86_SSE2 (1<<3) /* SSE2 support (Pentium 4) */
90#define VEX_HWCAPS_X86_SSE3 (1<<4) /* SSE3 support (>= Prescott) */
91#define VEX_HWCAPS_X86_LZCNT (1<<5) /* SSE4a LZCNT insn */
sewardj5117ce12006-01-27 21:20:15 +000092
sewardje9d8a262009-07-01 08:06:34 +000093/* amd64: baseline capability is SSE2, with cmpxchg8b but not
94 cmpxchg16b. */
sewardjcc3d2192013-03-27 11:37:33 +000095#define VEX_HWCAPS_AMD64_SSE3 (1<<5) /* SSE3 support */
96#define VEX_HWCAPS_AMD64_CX16 (1<<6) /* cmpxchg16b support */
97#define VEX_HWCAPS_AMD64_LZCNT (1<<7) /* SSE4a LZCNT insn */
98#define VEX_HWCAPS_AMD64_AVX (1<<8) /* AVX instructions */
99#define VEX_HWCAPS_AMD64_RDTSCP (1<<9) /* RDTSCP instruction */
100#define VEX_HWCAPS_AMD64_BMI (1<<10) /* BMI1 instructions */
101#define VEX_HWCAPS_AMD64_AVX2 (1<<11) /* AVX2 instructions */
sewardj5117ce12006-01-27 21:20:15 +0000102
103/* ppc32: baseline capability is integer only */
sewardj536fbab2010-07-29 15:39:05 +0000104#define VEX_HWCAPS_PPC32_F (1<<8) /* basic (non-optional) FP */
105#define VEX_HWCAPS_PPC32_V (1<<9) /* Altivec (VMX) */
106#define VEX_HWCAPS_PPC32_FX (1<<10) /* FP extns (fsqrt, fsqrts) */
107#define VEX_HWCAPS_PPC32_GX (1<<11) /* Graphics extns
108 (fres,frsqrte,fsel,stfiwx) */
sewardj66d5ef22011-04-15 11:55:00 +0000109#define VEX_HWCAPS_PPC32_VX (1<<12) /* Vector-scalar floating-point (VSX); implies ISA 2.06 or higher */
sewardja0fb1192012-06-03 23:11:49 +0000110#define VEX_HWCAPS_PPC32_DFP (1<<17) /* Decimal Floating Point (DFP) -- e.g., dadd */
carll0c74bb52013-08-12 18:01:40 +0000111#define VEX_HWCAPS_PPC32_ISA2_07 (1<<19) /* ISA 2.07 -- e.g., mtvsrd */
Elliott Hughesa0664b92017-04-18 17:46:52 -0700112#define VEX_HWCAPS_PPC32_ISA3_0 (1<<21) /* ISA 3.0 -- e.g., cnttzw */
sewardj5117ce12006-01-27 21:20:15 +0000113
114/* ppc64: baseline capability is integer and basic FP insns */
sewardj66d5ef22011-04-15 11:55:00 +0000115#define VEX_HWCAPS_PPC64_V (1<<13) /* Altivec (VMX) */
116#define VEX_HWCAPS_PPC64_FX (1<<14) /* FP extns (fsqrt, fsqrts) */
117#define VEX_HWCAPS_PPC64_GX (1<<15) /* Graphics extns
sewardj536fbab2010-07-29 15:39:05 +0000118 (fres,frsqrte,fsel,stfiwx) */
sewardj66d5ef22011-04-15 11:55:00 +0000119#define VEX_HWCAPS_PPC64_VX (1<<16) /* Vector-scalar floating-point (VSX); implies ISA 2.06 or higher */
sewardjc66d6fa2012-04-02 21:24:12 +0000120#define VEX_HWCAPS_PPC64_DFP (1<<18) /* Decimal Floating Point (DFP) -- e.g., dadd */
carll0c74bb52013-08-12 18:01:40 +0000121#define VEX_HWCAPS_PPC64_ISA2_07 (1<<20) /* ISA 2.07 -- e.g., mtvsrd */
Elliott Hughesa0664b92017-04-18 17:46:52 -0700122#define VEX_HWCAPS_PPC64_ISA3_0 (1<<22) /* ISA 3.0 -- e.g., cnttzw */
sewardjc66d6fa2012-04-02 21:24:12 +0000123
sewardj652b56a2011-04-13 15:38:17 +0000124/* s390x: Hardware capability encoding
125
florianbeef61a2012-05-27 16:59:56 +0000126 Bits [26:31] encode the machine model (see VEX_S390X_MODEL... below)
127 Bits [0:20] encode specific hardware capabilities
128 (see VEX_HWAPS_S390X_... below)
sewardj652b56a2011-04-13 15:38:17 +0000129*/
130
131/* Model numbers must be assigned in chronological order.
132 They are used as array index. */
133#define VEX_S390X_MODEL_Z900 0
134#define VEX_S390X_MODEL_Z800 1
135#define VEX_S390X_MODEL_Z990 2
136#define VEX_S390X_MODEL_Z890 3
137#define VEX_S390X_MODEL_Z9_EC 4
138#define VEX_S390X_MODEL_Z9_BC 5
139#define VEX_S390X_MODEL_Z10_EC 6
140#define VEX_S390X_MODEL_Z10_BC 7
141#define VEX_S390X_MODEL_Z196 8
florian87b48b62011-09-02 22:19:47 +0000142#define VEX_S390X_MODEL_Z114 9
florianc9e43b12012-08-28 13:31:31 +0000143#define VEX_S390X_MODEL_ZEC12 10
florian1bdaac52013-07-28 15:28:57 +0000144#define VEX_S390X_MODEL_ZBC12 11
floriandee60ed2015-03-17 13:44:14 +0000145#define VEX_S390X_MODEL_Z13 12
Elliott Hughesa0664b92017-04-18 17:46:52 -0700146#define VEX_S390X_MODEL_Z13S 13
147#define VEX_S390X_MODEL_UNKNOWN 14 /* always last in list */
sewardj652b56a2011-04-13 15:38:17 +0000148#define VEX_S390X_MODEL_MASK 0x3F
149
sewardjd07b8562011-04-27 11:58:22 +0000150#define VEX_HWCAPS_S390X_LDISP (1<<6) /* Long-displacement facility */
151#define VEX_HWCAPS_S390X_EIMM (1<<7) /* Extended-immediate facility */
152#define VEX_HWCAPS_S390X_GIE (1<<8) /* General-instruction-extension facility */
153#define VEX_HWCAPS_S390X_DFP (1<<9) /* Decimal floating point facility */
154#define VEX_HWCAPS_S390X_FGX (1<<10) /* FPR-GR transfer facility */
florian9af37692012-01-15 21:01:16 +0000155#define VEX_HWCAPS_S390X_ETF2 (1<<11) /* ETF2-enhancement facility */
florian90ece042012-04-21 15:41:51 +0000156#define VEX_HWCAPS_S390X_STFLE (1<<12) /* STFLE facility */
florian79bee4b2012-05-03 01:30:48 +0000157#define VEX_HWCAPS_S390X_ETF3 (1<<13) /* ETF3-enhancement facility */
floriana4c36692012-08-26 04:22:33 +0000158#define VEX_HWCAPS_S390X_STCKF (1<<14) /* STCKF facility */
florian60b665b2012-08-30 20:28:00 +0000159#define VEX_HWCAPS_S390X_FPEXT (1<<15) /* Floating point extension facility */
florianaec8e052012-12-09 17:26:32 +0000160#define VEX_HWCAPS_S390X_LSC (1<<16) /* Conditional load/store facility */
florian78d5ef72013-05-11 15:02:58 +0000161#define VEX_HWCAPS_S390X_PFPO (1<<17) /* Perform floating point ops facility */
sewardj652b56a2011-04-13 15:38:17 +0000162
sewardj2019a972011-03-07 16:04:07 +0000163/* Special value representing all available s390x hwcaps */
164#define VEX_HWCAPS_S390X_ALL (VEX_HWCAPS_S390X_LDISP | \
165 VEX_HWCAPS_S390X_EIMM | \
166 VEX_HWCAPS_S390X_GIE | \
sewardjd07b8562011-04-27 11:58:22 +0000167 VEX_HWCAPS_S390X_DFP | \
florian9af37692012-01-15 21:01:16 +0000168 VEX_HWCAPS_S390X_FGX | \
florian90ece042012-04-21 15:41:51 +0000169 VEX_HWCAPS_S390X_STFLE | \
floriana4c36692012-08-26 04:22:33 +0000170 VEX_HWCAPS_S390X_STCKF | \
florian60b665b2012-08-30 20:28:00 +0000171 VEX_HWCAPS_S390X_FPEXT | \
florianaec8e052012-12-09 17:26:32 +0000172 VEX_HWCAPS_S390X_LSC | \
florian79bee4b2012-05-03 01:30:48 +0000173 VEX_HWCAPS_S390X_ETF3 | \
florian78d5ef72013-05-11 15:02:58 +0000174 VEX_HWCAPS_S390X_ETF2 | \
175 VEX_HWCAPS_S390X_PFPO)
sewardj2019a972011-03-07 16:04:07 +0000176
sewardj652b56a2011-04-13 15:38:17 +0000177#define VEX_HWCAPS_S390X(x) ((x) & ~VEX_S390X_MODEL_MASK)
178#define VEX_S390X_MODEL(x) ((x) & VEX_S390X_MODEL_MASK)
179
sewardj0de80192015-04-10 12:27:40 +0000180/* Tilegx: baseline capability is TILEGX36 */
181#define VEX_HWCAPS_TILEGX_BASE (1<<16) /* TILEGX Baseline */
182
sewardj5117ce12006-01-27 21:20:15 +0000183/* arm: baseline capability is ARMv4 */
sewardjec0d9a02010-08-22 12:54:56 +0000184/* Bits 5:0 - architecture level (e.g. 5 for v5, 6 for v6 etc) */
185#define VEX_HWCAPS_ARM_VFP (1<<6) /* VFP extension */
186#define VEX_HWCAPS_ARM_VFP2 (1<<7) /* VFPv2 */
187#define VEX_HWCAPS_ARM_VFP3 (1<<8) /* VFPv3 */
188/* Bits 15:10 reserved for (possible) future VFP revisions */
189#define VEX_HWCAPS_ARM_NEON (1<<16) /* Advanced SIMD also known as NEON */
sewardj5117ce12006-01-27 21:20:15 +0000190
sewardjec0d9a02010-08-22 12:54:56 +0000191/* Get an ARM architecure level from HWCAPS */
192#define VEX_ARM_ARCHLEVEL(x) ((x) & 0x3f)
sewardjbef170b2004-12-21 01:23:00 +0000193
sewardjbbcf1882014-01-12 12:49:10 +0000194/* ARM64: baseline capability is AArch64 v8. */
195/* (no definitions since no variants so far) */
196
sewardjd0e5fe72012-06-07 08:51:02 +0000197/* MIPS baseline capability */
198/* Assigned Company values for bits 23:16 of the PRId Register
199 (CP0 register 15, select 0). As of the MIPS32 and MIPS64 specs from
200 MTI, the PRId register is defined in this (backwards compatible)
201 way:
202
203 +----------------+----------------+----------------+----------------+
204 | Company Options| Company ID | Processor ID | Revision |
205 +----------------+----------------+----------------+----------------+
206 31 24 23 16 15 8 7
207
208*/
209
Elliott Hughesa0664b92017-04-18 17:46:52 -0700210#define VEX_PRID_COMP_LEGACY 0x00000000
211#define VEX_PRID_COMP_MIPS 0x00010000
212#define VEX_PRID_COMP_BROADCOM 0x00020000
213#define VEX_PRID_COMP_NETLOGIC 0x000C0000
214#define VEX_PRID_COMP_CAVIUM 0x000D0000
215#define VEX_PRID_COMP_INGENIC_E1 0x00E10000 /* JZ4780 */
216
217/*
218 * These are valid when 23:16 == PRID_COMP_LEGACY
219 */
220#define VEX_PRID_IMP_LOONGSON_64 0x6300 /* Loongson-2/3 */
sewardjd0e5fe72012-06-07 08:51:02 +0000221
petarjbc7d6f42013-09-16 18:11:59 +0000222/*
223 * These are the PRID's for when 23:16 == PRID_COMP_MIPS
224 */
Elliott Hughesa0664b92017-04-18 17:46:52 -0700225#define VEX_PRID_IMP_34K 0x9500
226#define VEX_PRID_IMP_74K 0x9700
petarjbc7d6f42013-09-16 18:11:59 +0000227
Elliott Hughesa0664b92017-04-18 17:46:52 -0700228/*
229 * Instead of Company Options values, bits 31:24 will be packed with
230 * additional information, such as isa level and FP mode.
231 */
232#define VEX_MIPS_CPU_ISA_M32R1 0x01000000
233#define VEX_MIPS_CPU_ISA_M32R2 0x02000000
234#define VEX_MIPS_CPU_ISA_M64R1 0x04000000
235#define VEX_MIPS_CPU_ISA_M64R2 0x08000000
236#define VEX_MIPS_CPU_ISA_M32R6 0x10000000
237#define VEX_MIPS_CPU_ISA_M64R6 0x20000000
238/* FP mode is FR = 1 (32 dbl. prec. FP registers) */
239#define VEX_MIPS_HOST_FR 0x40000000
240/* Get MIPS Extended Information */
241#define VEX_MIPS_EX_INFO(x) ((x) & 0xFF000000)
petarjbc7d6f42013-09-16 18:11:59 +0000242/* Get MIPS Company ID from HWCAPS */
243#define VEX_MIPS_COMP_ID(x) ((x) & 0x00FF0000)
244/* Get MIPS Processor ID from HWCAPS */
dejanj0e006f22014-02-19 11:56:29 +0000245#define VEX_MIPS_PROC_ID(x) ((x) & 0x0000FF00)
246/* Get MIPS Revision from HWCAPS */
247#define VEX_MIPS_REV(x) ((x) & 0x000000FF)
Elliott Hughesa0664b92017-04-18 17:46:52 -0700248/* Get host FP mode */
249#define VEX_MIPS_HOST_FP_MODE(x) (!!(VEX_MIPS_EX_INFO(x) & VEX_MIPS_HOST_FR))
250/* Check if the processor supports MIPS32R2. */
251#define VEX_MIPS_CPU_HAS_MIPS32R2(x) (VEX_MIPS_EX_INFO(x) & \
252 VEX_MIPS_CPU_ISA_M32R2)
petarjbc7d6f42013-09-16 18:11:59 +0000253/* Check if the processor supports DSP ASE Rev 2. */
254#define VEX_MIPS_PROC_DSP2(x) ((VEX_MIPS_COMP_ID(x) == VEX_PRID_COMP_MIPS) && \
255 (VEX_MIPS_PROC_ID(x) == VEX_PRID_IMP_74K))
256/* Check if the processor supports DSP ASE Rev 1. */
257#define VEX_MIPS_PROC_DSP(x) (VEX_MIPS_PROC_DSP2(x) || \
258 ((VEX_MIPS_COMP_ID(x) == VEX_PRID_COMP_MIPS) && \
259 (VEX_MIPS_PROC_ID(x) == VEX_PRID_IMP_34K)))
dejanjc3fee0d2013-07-25 09:08:03 +0000260
sewardjbef170b2004-12-21 01:23:00 +0000261/* These return statically allocated strings. */
262
263extern const HChar* LibVEX_ppVexArch ( VexArch );
sewardj9b769162014-07-24 12:42:03 +0000264extern const HChar* LibVEX_ppVexEndness ( VexEndness endness );
sewardj5117ce12006-01-27 21:20:15 +0000265extern const HChar* LibVEX_ppVexHwCaps ( VexArch, UInt );
sewardjbef170b2004-12-21 01:23:00 +0000266
sewardjbbcf1882014-01-12 12:49:10 +0000267
florianf192a392012-10-07 19:44:40 +0000268/* The various kinds of caches */
269typedef enum {
sewardj9b769162014-07-24 12:42:03 +0000270 DATA_CACHE=0x500,
florianf192a392012-10-07 19:44:40 +0000271 INSN_CACHE,
272 UNIFIED_CACHE
273} VexCacheKind;
274
275/* Information about a particular cache */
276typedef struct {
277 VexCacheKind kind;
278 UInt level; /* level this cache is at, e.g. 1 for L1 cache */
279 UInt sizeB; /* size of this cache in bytes */
280 UInt line_sizeB; /* cache line size in bytes */
281 UInt assoc; /* set associativity */
florian80ab2652012-10-18 03:11:39 +0000282 Bool is_trace_cache; /* False, except for certain Pentium 4 models */
florianf192a392012-10-07 19:44:40 +0000283} VexCache;
284
285/* Convenience macro to initialise a VexCache */
286#define VEX_CACHE_INIT(_kind, _level, _size, _line_size, _assoc) \
287 ({ (VexCache) { .kind = _kind, .level = _level, .sizeB = _size, \
florian80ab2652012-10-18 03:11:39 +0000288 .line_sizeB = _line_size, .assoc = _assoc, \
289 .is_trace_cache = False }; })
florianf192a392012-10-07 19:44:40 +0000290
291/* Information about the cache system as a whole */
292typedef struct {
293 UInt num_levels;
294 UInt num_caches;
295 /* Unordered array of caches for this host. NULL if there are
florian80ab2652012-10-18 03:11:39 +0000296 no caches. The following can always be assumed:
297 (1) There is at most one cache of a given kind per cache level.
298 (2) If there exists a unified cache at a particular level then
299 no other cache exists at that level.
300 (3) The existence of a cache at level N > 1 implies the existence of
301 at least one cache at level N-1. */
florianf192a392012-10-07 19:44:40 +0000302 VexCache *caches;
303 Bool icaches_maintain_coherence;
304} VexCacheInfo;
305
sewardjac9af022004-07-05 01:15:34 +0000306
sewardj27e1dd62005-06-30 11:49:14 +0000307/* This struct is a bit of a hack, but is needed to carry misc
sewardjaca070a2006-10-17 00:28:22 +0000308 important bits of info about an arch. Fields which are meaningless
florianf192a392012-10-07 19:44:40 +0000309 or ignored for the platform in question should be set to zero.
310 Nb: if you add fields to the struct make sure to update function
311 LibVEX_default_VexArchInfo. */
sewardj27e1dd62005-06-30 11:49:14 +0000312
313typedef
314 struct {
sewardj9b769162014-07-24 12:42:03 +0000315 /* The following three fields are mandatory. */
316 UInt hwcaps;
317 VexEndness endness;
florianf192a392012-10-07 19:44:40 +0000318 VexCacheInfo hwcache_info;
florian9138b172013-08-03 19:36:55 +0000319 /* PPC32/PPC64 only: size of instruction cache line */
320 Int ppc_icache_line_szB;
sewardje971c6a2010-09-03 15:49:57 +0000321 /* PPC32/PPC64 only: sizes zeroed by the dcbz/dcbzl instructions
sewardj65902992014-05-03 21:20:56 +0000322 (bug#135264) */
sewardje971c6a2010-09-03 15:49:57 +0000323 UInt ppc_dcbz_szB;
324 UInt ppc_dcbzl_szB; /* 0 means unsupported (SIGILL) */
sewardj65902992014-05-03 21:20:56 +0000325 /* ARM64: I- and D- minimum line sizes in log2(bytes), as
326 obtained from ctr_el0.DminLine and .IminLine. For example, a
327 line size of 64 bytes would be encoded here as 6. */
328 UInt arm64_dMinLine_lg2_szB;
329 UInt arm64_iMinLine_lg2_szB;
sewardj27e1dd62005-06-30 11:49:14 +0000330 }
331 VexArchInfo;
332
333/* Write default settings info *vai. */
334extern
335void LibVEX_default_VexArchInfo ( /*OUT*/VexArchInfo* vai );
336
337
sewardjaca070a2006-10-17 00:28:22 +0000338/* This struct carries guest and host ABI variant information that may
339 be needed. Fields which are meaningless or ignored for the
340 platform in question should be set to zero.
341
342 Settings which are believed to be correct are:
343
344 guest_stack_redzone_size
345 guest is ppc32-linux ==> 0
346 guest is ppc64-linux ==> 288
sewardjaca070a2006-10-17 00:28:22 +0000347 guest is amd64-linux ==> 128
348 guest is other ==> inapplicable
349
philippee2cc4de2014-12-16 23:57:51 +0000350 guest_amd64_assume_fs_is_const
sewardj2e28ac42008-12-04 00:05:12 +0000351 guest is amd64-linux ==> True
352 guest is amd64-darwin ==> False
sewardj3e5d82d2015-07-21 14:43:23 +0000353 guest is amd64-solaris ==> True
sewardj2e28ac42008-12-04 00:05:12 +0000354 guest is other ==> inapplicable
355
philippee2cc4de2014-12-16 23:57:51 +0000356 guest_amd64_assume_gs_is_const
sewardj2e28ac42008-12-04 00:05:12 +0000357 guest is amd64-darwin ==> True
philippee2cc4de2014-12-16 23:57:51 +0000358 guest is amd64-linux ==> True
sewardj3e5d82d2015-07-21 14:43:23 +0000359 guest is amd64-solaris ==> False
sewardj2e28ac42008-12-04 00:05:12 +0000360 guest is other ==> inapplicable
361
sewardjaca070a2006-10-17 00:28:22 +0000362 guest_ppc_zap_RZ_at_blr
363 guest is ppc64-linux ==> True
364 guest is ppc32-linux ==> False
sewardjaca070a2006-10-17 00:28:22 +0000365 guest is other ==> inapplicable
366
367 guest_ppc_zap_RZ_at_bl
368 guest is ppc64-linux ==> const True
369 guest is ppc32-linux ==> const False
sewardjaca070a2006-10-17 00:28:22 +0000370 guest is other ==> inapplicable
371
372 host_ppc_calls_use_fndescrs:
373 host is ppc32-linux ==> False
374 host is ppc64-linux ==> True
sewardjaca070a2006-10-17 00:28:22 +0000375 host is other ==> inapplicable
376*/
377
378typedef
379 struct {
380 /* PPC and AMD64 GUESTS only: how many bytes below the
381 stack pointer are validly addressible? */
382 Int guest_stack_redzone_size;
383
sewardj2e28ac42008-12-04 00:05:12 +0000384 /* AMD64 GUESTS only: should we translate %fs-prefixed
385 instructions using the assumption that %fs always contains
sewardj3e5d82d2015-07-21 14:43:23 +0000386 the same value? (typically zero on linux and solaris) */
philippee2cc4de2014-12-16 23:57:51 +0000387 Bool guest_amd64_assume_fs_is_const;
sewardj2e28ac42008-12-04 00:05:12 +0000388
389 /* AMD64 GUESTS only: should we translate %gs-prefixed
390 instructions using the assumption that %gs always contains
philippee2cc4de2014-12-16 23:57:51 +0000391 the same value? (typically 0x60 on darwin)? */
392 Bool guest_amd64_assume_gs_is_const;
sewardj2e28ac42008-12-04 00:05:12 +0000393
sewardjaca070a2006-10-17 00:28:22 +0000394 /* PPC GUESTS only: should we zap the stack red zone at a 'blr'
395 (function return) ? */
396 Bool guest_ppc_zap_RZ_at_blr;
397
398 /* PPC GUESTS only: should we zap the stack red zone at a 'bl'
399 (function call) ? Is supplied with the guest address of the
400 target of the call since that may be significant. If NULL,
401 is assumed equivalent to a fn which always returns False. */
florianbdf99f02015-01-04 17:20:19 +0000402 Bool (*guest_ppc_zap_RZ_at_bl)(Addr);
sewardjaca070a2006-10-17 00:28:22 +0000403
sewardjaca070a2006-10-17 00:28:22 +0000404 /* PPC32/PPC64 HOSTS only: does '&f' give us a pointer to a
405 function descriptor on the host, or to the function code
406 itself? True => descriptor, False => code. */
407 Bool host_ppc_calls_use_fndescrs;
Elliott Hughesa0664b92017-04-18 17:46:52 -0700408
409 Bool guest_mips_fp_mode64;
sewardjaca070a2006-10-17 00:28:22 +0000410 }
sewardjdd40fdf2006-12-24 02:20:24 +0000411 VexAbiInfo;
sewardjaca070a2006-10-17 00:28:22 +0000412
sewardjdd40fdf2006-12-24 02:20:24 +0000413/* Write default settings info *vbi. */
sewardjaca070a2006-10-17 00:28:22 +0000414extern
sewardjdd40fdf2006-12-24 02:20:24 +0000415void LibVEX_default_VexAbiInfo ( /*OUT*/VexAbiInfo* vbi );
sewardjaca070a2006-10-17 00:28:22 +0000416
417
sewardjd887b862005-01-17 18:34:34 +0000418/*-------------------------------------------------------*/
419/*--- Control of Vex's optimiser (iropt). ---*/
420/*-------------------------------------------------------*/
421
philippec8e2f982012-08-01 22:04:13 +0000422
423/* VexRegisterUpdates specifies when to ensure that the guest state is
sewardjca2c3c72015-02-05 12:53:20 +0000424 up to date, in order of increasing accuracy but increasing expense.
philippec8e2f982012-08-01 22:04:13 +0000425
sewardjca2c3c72015-02-05 12:53:20 +0000426 VexRegUpdSpAtMemAccess: all registers are updated at superblock
427 exits, and SP is also up to date at memory exception points. The
428 SP is described by the arch specific functions
429 guest_<arch>_state_requires_precise_mem_exns.
philippe6c46bef2012-08-14 22:29:01 +0000430
sewardjca2c3c72015-02-05 12:53:20 +0000431 VexRegUpdUnwindregsAtMemAccess: registers needed to make a stack
432 trace are up to date at memory exception points. Typically,
433 these are PC/SP/FP. The minimal registers are described by the
434 arch specific functions guest_<arch>_state_requires_precise_mem_exns.
435 This is what Valgrind sets as the default.
philippec8e2f982012-08-01 22:04:13 +0000436
sewardjca2c3c72015-02-05 12:53:20 +0000437 VexRegUpdAllregsAtMemAccess: all registers up to date at memory
438 exception points. This is what normally might be considered as
439 providing "precise exceptions for memory", but does not
440 necessarily provide precise register values at any other kind of
441 exception.
philippec8e2f982012-08-01 22:04:13 +0000442
sewardjca2c3c72015-02-05 12:53:20 +0000443 VexRegUpdAllregsAtEachInsn: all registers up to date at each
444 instruction.
445*/
446typedef
447 enum {
448 VexRegUpd_INVALID=0x700,
449 VexRegUpdSpAtMemAccess,
450 VexRegUpdUnwindregsAtMemAccess,
451 VexRegUpdAllregsAtMemAccess,
452 VexRegUpdAllregsAtEachInsn
453 }
454 VexRegisterUpdates;
philippec8e2f982012-08-01 22:04:13 +0000455
sewardj08613742004-10-25 13:01:45 +0000456/* Control of Vex's optimiser. */
457
458typedef
459 struct {
460 /* Controls verbosity of iropt. 0 = no output. */
461 Int iropt_verbosity;
462 /* Control aggressiveness of iropt. 0 = no opt, 1 = simple
463 opts, 2 (default) = max optimisation. */
464 Int iropt_level;
sewardjca2c3c72015-02-05 12:53:20 +0000465 /* Controls when registers are updated in guest state. Note
466 that this is the default value. The VEX client can override
467 this on a per-IRSB basis if it wants. bb_to_IR() will query
468 the client to ask if it wants a different setting for the
469 block under construction, and that new setting is transported
470 back to LibVEX_Translate, which feeds it to iropt via the
471 various do_iropt_BB calls. */
472 VexRegisterUpdates iropt_register_updates_default;
sewardj08613742004-10-25 13:01:45 +0000473 /* How aggressive should iropt be in unrolling loops? Higher
474 numbers make it more enthusiastic about loop unrolling.
475 Default=120. A setting of zero disables unrolling. */
476 Int iropt_unroll_thresh;
477 /* What's the maximum basic block length the front end(s) allow?
478 BBs longer than this are split up. Default=50 (guest
479 insns). */
480 Int guest_max_insns;
481 /* How aggressive should front ends be in following
482 unconditional branches to known destinations? Default=10,
483 meaning that if a block contains less than 10 guest insns so
484 far, the front end(s) will attempt to chase into its
485 successor. A setting of zero disables chasing. */
486 Int guest_chase_thresh;
sewardj984d9b12010-01-15 10:53:21 +0000487 /* EXPERIMENTAL: chase across conditional branches? Not all
488 front ends honour this. Default: NO. */
489 Bool guest_chase_cond;
sewardj08613742004-10-25 13:01:45 +0000490 }
491 VexControl;
492
493
494/* Write the default settings into *vcon. */
sewardjbef170b2004-12-21 01:23:00 +0000495
sewardjd887b862005-01-17 18:34:34 +0000496extern
497void LibVEX_default_VexControl ( /*OUT*/ VexControl* vcon );
sewardj08613742004-10-25 13:01:45 +0000498
499
sewardjd887b862005-01-17 18:34:34 +0000500/*-------------------------------------------------------*/
sewardjd887b862005-01-17 18:34:34 +0000501/*--- Storage management control ---*/
502/*-------------------------------------------------------*/
sewardjac9af022004-07-05 01:15:34 +0000503
sewardjd887b862005-01-17 18:34:34 +0000504/* Allocate in Vex's temporary allocation area. Be careful with this.
505 You can only call it inside an instrumentation or optimisation
506 callback that you have previously specified in a call to
507 LibVEX_Translate. The storage allocated will only stay alive until
florianbde34062014-10-11 14:48:38 +0000508 translation of the current basic block is complete. */
florian04fc6b12014-12-29 20:22:26 +0000509extern void* LibVEX_Alloc ( SizeT nbytes );
sewardjac9af022004-07-05 01:15:34 +0000510
sewardjd887b862005-01-17 18:34:34 +0000511/* Show Vex allocation statistics. */
512extern void LibVEX_ShowAllocStats ( void );
513
514
515/*-------------------------------------------------------*/
516/*--- Describing guest state layout ---*/
517/*-------------------------------------------------------*/
sewardjac9af022004-07-05 01:15:34 +0000518
sewardj49651f42004-10-28 22:11:04 +0000519/* Describe the guest state enough that the instrumentation
520 functions can work. */
521
sewardjeeac8412004-11-02 00:26:55 +0000522/* The max number of guest state chunks which we can describe as
523 always defined (for the benefit of Memcheck). */
sewardje86310f2009-03-19 22:21:40 +0000524#define VEXGLO_N_ALWAYSDEFD 24
sewardjeeac8412004-11-02 00:26:55 +0000525
sewardj49651f42004-10-28 22:11:04 +0000526typedef
527 struct {
sewardjcf787902004-11-03 09:08:33 +0000528 /* Total size of the guest state, in bytes. Must be
florian95a487b2014-02-14 08:55:32 +0000529 16-aligned. */
sewardjeeac8412004-11-02 00:26:55 +0000530 Int total_sizeB;
sewardj49651f42004-10-28 22:11:04 +0000531 /* Whereabouts is the stack pointer? */
532 Int offset_SP;
533 Int sizeof_SP; /* 4 or 8 */
sewardja2033302008-08-19 11:15:10 +0000534 /* Whereabouts is the frame pointer? */
535 Int offset_FP;
536 Int sizeof_FP; /* 4 or 8 */
sewardjcf787902004-11-03 09:08:33 +0000537 /* Whereabouts is the instruction pointer? */
538 Int offset_IP;
539 Int sizeof_IP; /* 4 or 8 */
sewardjeeac8412004-11-02 00:26:55 +0000540 /* Describe parts of the guest state regarded as 'always
541 defined'. */
542 Int n_alwaysDefd;
543 struct {
544 Int offset;
545 Int size;
546 } alwaysDefd[VEXGLO_N_ALWAYSDEFD];
sewardj49651f42004-10-28 22:11:04 +0000547 }
sewardjeeac8412004-11-02 00:26:55 +0000548 VexGuestLayout;
sewardj49651f42004-10-28 22:11:04 +0000549
sewardjd887b862005-01-17 18:34:34 +0000550/* A note about guest state layout.
sewardj49651f42004-10-28 22:11:04 +0000551
sewardjd887b862005-01-17 18:34:34 +0000552 LibVEX defines the layout for the guest state, in the file
sewardj478646f2008-05-01 20:13:04 +0000553 pub/libvex_guest_<arch>.h. The struct will have an 16-aligned
554 size. Each translated bb is assumed to be entered with a specified
555 register pointing at such a struct. Beyond that is two copies of
556 the shadow state area with the same size as the struct. Beyond
557 that is a spill area that LibVEX may spill into. It must have size
sewardjd887b862005-01-17 18:34:34 +0000558 LibVEX_N_SPILL_BYTES, and this must be a 16-aligned number.
559
sewardj478646f2008-05-01 20:13:04 +0000560 On entry, the baseblock pointer register must be 16-aligned.
561
562 There must be no holes in between the primary guest state, its two
563 copies, and the spill area. In short, all 4 areas must have a
564 16-aligned size and be 16-aligned, and placed back-to-back.
sewardjd887b862005-01-17 18:34:34 +0000565*/
566
sewardjd6520122009-07-01 08:45:02 +0000567#define LibVEX_N_SPILL_BYTES 4096
sewardjd887b862005-01-17 18:34:34 +0000568
florian5074b492015-02-13 16:25:41 +0000569/* The size of the guest state must be a multiple of this number. */
570#define LibVEX_GUEST_STATE_ALIGN 16
sewardjd887b862005-01-17 18:34:34 +0000571
572/*-------------------------------------------------------*/
573/*--- Initialisation of the library ---*/
574/*-------------------------------------------------------*/
575
576/* Initialise the library. You must call this first. */
577
578extern void LibVEX_Init (
sewardj6312e802011-03-15 08:05:12 +0000579
sewardjd887b862005-01-17 18:34:34 +0000580 /* failure exit function */
sewardj6312e802011-03-15 08:05:12 +0000581# if __cplusplus == 1 && __GNUC__ && __GNUC__ <= 3
582 /* g++ 3.x doesn't understand attributes on function parameters.
583 See #265762. */
584# else
sewardjd887b862005-01-17 18:34:34 +0000585 __attribute__ ((noreturn))
sewardj6312e802011-03-15 08:05:12 +0000586# endif
sewardjd887b862005-01-17 18:34:34 +0000587 void (*failure_exit) ( void ),
sewardj6312e802011-03-15 08:05:12 +0000588
sewardjd887b862005-01-17 18:34:34 +0000589 /* logging output function */
florian04fc6b12014-12-29 20:22:26 +0000590 void (*log_bytes) ( const HChar*, SizeT nbytes ),
sewardj6312e802011-03-15 08:05:12 +0000591
sewardjd887b862005-01-17 18:34:34 +0000592 /* debug paranoia level */
593 Int debuglevel,
sewardj6312e802011-03-15 08:05:12 +0000594
sewardjd887b862005-01-17 18:34:34 +0000595 /* Control ... */
florianf72c2c12014-09-05 21:52:29 +0000596 const VexControl* vcon
sewardjd887b862005-01-17 18:34:34 +0000597);
598
599
600/*-------------------------------------------------------*/
601/*--- Make a translation ---*/
602/*-------------------------------------------------------*/
sewardjac9af022004-07-05 01:15:34 +0000603
sewardj72c72812005-01-19 11:49:45 +0000604/* Describes the outcome of a translation attempt. */
sewardjac9af022004-07-05 01:15:34 +0000605typedef
sewardjbc161a42011-06-07 21:28:38 +0000606 struct {
607 /* overall status */
sewardj9b769162014-07-24 12:42:03 +0000608 enum { VexTransOK=0x800,
sewardjbc161a42011-06-07 21:28:38 +0000609 VexTransAccessFail, VexTransOutputFull } status;
610 /* The number of extents that have a self-check (0 to 3) */
611 UInt n_sc_extents;
sewardjc6f970f2012-04-02 21:54:49 +0000612 /* Offset in generated code of the profile inc, or -1 if
613 none. Needed for later patching. */
614 Int offs_profInc;
sewardjfadbbe22012-04-24 11:49:03 +0000615 /* Stats only: the number of guest insns included in the
616 translation. It may be zero (!). */
617 UInt n_guest_instrs;
sewardjd887b862005-01-17 18:34:34 +0000618 }
619 VexTranslateResult;
sewardjac9af022004-07-05 01:15:34 +0000620
sewardj72c72812005-01-19 11:49:45 +0000621
622/* Describes precisely the pieces of guest code that a translation
623 covers. Now that Vex can chase across BB boundaries, the old
624 scheme of describing a chunk of guest code merely by its start
625 address and length is inadequate.
626
florianbdf99f02015-01-04 17:20:19 +0000627 This struct uses 20 bytes on a 32-bit archtecture and 32 bytes on a
628 64-bit architecture. Space is important as clients will have to store
629 one of these for each translation made.
sewardj72c72812005-01-19 11:49:45 +0000630*/
631typedef
632 struct {
florianbdf99f02015-01-04 17:20:19 +0000633 Addr base[3];
sewardj72c72812005-01-19 11:49:45 +0000634 UShort len[3];
635 UShort n_used;
636 }
637 VexGuestExtents;
638
639
sewardj17c7f952005-12-15 14:02:34 +0000640/* A structure to carry arguments for LibVEX_Translate. There are so
641 many of them, it seems better to have a structure. */
642typedef
643 struct {
sewardjaca070a2006-10-17 00:28:22 +0000644 /* IN: The instruction sets we are translating from and to. And
645 guest/host misc info. */
sewardj17c7f952005-12-15 14:02:34 +0000646 VexArch arch_guest;
647 VexArchInfo archinfo_guest;
648 VexArch arch_host;
649 VexArchInfo archinfo_host;
sewardjdd40fdf2006-12-24 02:20:24 +0000650 VexAbiInfo abiinfo_both;
sewardjf4611492005-10-18 12:01:48 +0000651
sewardjc716aea2006-01-17 01:48:46 +0000652 /* IN: an opaque value which is passed as the first arg to all
653 callback functions supplied in this struct. Vex has no idea
654 what's at the other end of this pointer. */
655 void* callback_opaque;
656
sewardj17c7f952005-12-15 14:02:34 +0000657 /* IN: the block to translate, and its guest address. */
658 /* where are the actual bytes in the host's address space? */
florian8462d112014-09-24 15:18:09 +0000659 const UChar* guest_bytes;
sewardj17c7f952005-12-15 14:02:34 +0000660 /* where do the bytes really come from in the guest's aspace?
sewardjc716aea2006-01-17 01:48:46 +0000661 This is the post-redirection guest address. Not that Vex
662 understands anything about redirection; that is all done on
663 the Valgrind side. */
floriand4cc0de2015-01-02 11:44:12 +0000664 Addr guest_bytes_addr;
sewardj17c7f952005-12-15 14:02:34 +0000665
666 /* Is it OK to chase into this guest address? May not be
667 NULL. */
florianbeac5302014-12-31 12:09:38 +0000668 Bool (*chase_into_ok) ( /*callback_opaque*/void*, Addr );
sewardj17c7f952005-12-15 14:02:34 +0000669
670 /* OUT: which bits of guest code actually got translated */
671 VexGuestExtents* guest_extents;
672
673 /* IN: a place to put the resulting code, and its size */
674 UChar* host_bytes;
675 Int host_bytes_size;
676 /* OUT: how much of the output area is used. */
677 Int* host_bytes_used;
678
679 /* IN: optionally, two instrumentation functions. May be
680 NULL. */
sewardjdd40fdf2006-12-24 02:20:24 +0000681 IRSB* (*instrument1) ( /*callback_opaque*/void*,
682 IRSB*,
florian0a5494e2014-09-24 12:00:49 +0000683 const VexGuestLayout*,
684 const VexGuestExtents*,
685 const VexArchInfo*,
sewardj17c7f952005-12-15 14:02:34 +0000686 IRType gWordTy, IRType hWordTy );
sewardjdd40fdf2006-12-24 02:20:24 +0000687 IRSB* (*instrument2) ( /*callback_opaque*/void*,
688 IRSB*,
florian0a5494e2014-09-24 12:00:49 +0000689 const VexGuestLayout*,
690 const VexGuestExtents*,
691 const VexArchInfo*,
sewardj17c7f952005-12-15 14:02:34 +0000692 IRType gWordTy, IRType hWordTy );
693
sewardjbe1b6ff2007-08-28 06:06:27 +0000694 IRSB* (*finaltidy) ( IRSB* );
695
sewardjbc161a42011-06-07 21:28:38 +0000696 /* IN: a callback used to ask the caller which of the extents,
florian2eeeb9b2011-09-23 18:03:21 +0000697 if any, a self check is required for. Must not be NULL.
698 The returned value is a bitmask with a 1 in position i indicating
699 that the i'th extent needs a check. Since there can be at most
sewardjca2c3c72015-02-05 12:53:20 +0000700 3 extents, the returned values must be between 0 and 7.
701
702 This call also gives the VEX client the opportunity to change
703 the precision of register update preservation as performed by
704 the IR optimiser. Before the call, VEX will set *pxControl
705 to hold the default register-update status value as specified
706 by VexControl::iropt_register_updates_default as passed to
707 LibVEX_Init at library initialisation time. The client (in
708 this callback) can if it wants, inspect the value and change
709 it to something different, and that value will be used for
710 subsequent IR optimisation of the block. */
sewardjbc161a42011-06-07 21:28:38 +0000711 UInt (*needs_self_check)( /*callback_opaque*/void*,
sewardjca2c3c72015-02-05 12:53:20 +0000712 /*MAYBE_MOD*/VexRegisterUpdates* pxControl,
florian0a5494e2014-09-24 12:00:49 +0000713 const VexGuestExtents* );
sewardjc716aea2006-01-17 01:48:46 +0000714
715 /* IN: optionally, a callback which allows the caller to add its
716 own IR preamble following the self-check and any other
717 VEX-generated preamble, if any. May be NULL. If non-NULL,
sewardjf6c8ebf2007-02-06 01:52:52 +0000718 the IRSB under construction is handed to this function, which
sewardjc716aea2006-01-17 01:48:46 +0000719 presumably adds IR statements to it. The callback may
720 optionally complete the block and direct bb_to_IR not to
721 disassemble any instructions into it; this is indicated by
722 the callback returning True.
723 */
sewardjdd40fdf2006-12-24 02:20:24 +0000724 Bool (*preamble_function)(/*callback_opaque*/void*, IRSB*);
sewardjce02aa72006-01-12 12:27:58 +0000725
sewardj17c7f952005-12-15 14:02:34 +0000726 /* IN: debug: trace vex activity at various points */
727 Int traceflags;
728
sewardj442e51a2012-12-06 18:08:04 +0000729 /* IN: debug: print diagnostics when an illegal instr is detected */
730 Bool sigill_diag;
731
sewardjc6f970f2012-04-02 21:54:49 +0000732 /* IN: profiling: add a 64 bit profiler counter increment to the
733 translation? */
734 Bool addProfInc;
735
sewardj010ac542011-05-29 09:29:18 +0000736 /* IN: address of the dispatcher entry points. Describes the
737 places where generated code should jump to at the end of each
sewardj17c7f952005-12-15 14:02:34 +0000738 bb.
739
740 At the end of each translation, the next guest address is
741 placed in the host's standard return register (x86: %eax,
742 amd64: %rax, ppc32: %r3, ppc64: %r3). Optionally, the guest
743 state pointer register (on host x86: %ebp; amd64: %rbp;
744 ppc32/64: r31) may be set to a VEX_TRC_ value to indicate any
745 special action required before the next block is run.
746
747 Control is then passed back to the dispatcher (beyond Vex's
748 control; caller supplies this) in the following way:
749
750 - On host archs which lack a link register (x86, amd64), by a
sewardj010ac542011-05-29 09:29:18 +0000751 jump to the host address specified in
752 'dispatcher_assisted', if the guest state pointer has been
753 changed so as to request some action before the next block
754 is run, or 'dispatcher_unassisted' (the fast path), in
755 which it is assumed that the guest state pointer is
756 unchanged and we wish to continue directly with the next
757 translation. Both of these must be non-NULL.
sewardj17c7f952005-12-15 14:02:34 +0000758
759 - On host archs which have a link register (ppc32, ppc64), by
760 a branch to the link register (which is guaranteed to be
761 unchanged from whatever it was at entry to the
sewardj010ac542011-05-29 09:29:18 +0000762 translation). 'dispatch_assisted' and
763 'dispatch_unassisted' must be NULL.
sewardj17c7f952005-12-15 14:02:34 +0000764
765 The aim is to get back and forth between translations and the
766 dispatcher without creating memory traffic to store return
767 addresses.
sewardjc6f970f2012-04-02 21:54:49 +0000768
769 FIXME: update this comment
sewardj17c7f952005-12-15 14:02:34 +0000770 */
florian8462d112014-09-24 15:18:09 +0000771 const void* disp_cp_chain_me_to_slowEP;
772 const void* disp_cp_chain_me_to_fastEP;
773 const void* disp_cp_xindir;
774 const void* disp_cp_xassisted;
sewardj17c7f952005-12-15 14:02:34 +0000775 }
776 VexTranslateArgs;
777
778
779extern
780VexTranslateResult LibVEX_Translate ( VexTranslateArgs* );
781
sewardjc24824a2005-07-07 13:52:03 +0000782/* A subtlety re interaction between self-checking translations and
783 bb-chasing. The supplied chase_into_ok function should say NO
784 (False) when presented with any address for which you might want to
785 make a self-checking translation.
786
787 If it doesn't do that, you may end up with Vex chasing from BB #1
788 to BB #2 (fine); but if you wanted checking for #2 and not #1, that
789 would not be the result. Therefore chase_into_ok should disallow
790 following into #2. That will force the caller to eventually
791 request a new translation starting at #2, at which point Vex will
sewardjc6f970f2012-04-02 21:54:49 +0000792 correctly observe the make-a-self-check flag.
793
794 FIXME: is this still up to date? */
795
796
797/*-------------------------------------------------------*/
798/*--- Patch existing translations ---*/
799/*-------------------------------------------------------*/
800
florian5ea257b2012-09-29 17:05:46 +0000801/* A host address range that was modified by the functions below.
802 Callers must request I-cache syncing after the call as appropriate. */
sewardjc6f970f2012-04-02 21:54:49 +0000803typedef
804 struct {
805 HWord start;
florian5ea257b2012-09-29 17:05:46 +0000806 HWord len; /* always > 0 */
sewardjc6f970f2012-04-02 21:54:49 +0000807 }
808 VexInvalRange;
809
810/* Chain an XDirect jump located at place_to_chain so it jumps to
811 place_to_jump_to. It is expected (and checked) that this site
812 currently contains a call to the dispatcher specified by
813 disp_cp_chain_me_EXPECTED. */
814extern
florian7d6f81d2014-09-22 21:43:37 +0000815VexInvalRange LibVEX_Chain ( VexArch arch_host,
816 VexEndness endhess_host,
817 void* place_to_chain,
818 const void* disp_cp_chain_me_EXPECTED,
819 const void* place_to_jump_to );
sewardjc6f970f2012-04-02 21:54:49 +0000820
821/* Undo an XDirect jump located at place_to_unchain, so it is
822 converted back into a call to disp_cp_chain_me. It is expected
823 (and checked) that this site currently contains a jump directly to
824 the address specified by place_to_jump_to_EXPECTED. */
825extern
florian7d6f81d2014-09-22 21:43:37 +0000826VexInvalRange LibVEX_UnChain ( VexArch arch_host,
827 VexEndness endness_host,
828 void* place_to_unchain,
829 const void* place_to_jump_to_EXPECTED,
830 const void* disp_cp_chain_me );
sewardjc6f970f2012-04-02 21:54:49 +0000831
832/* Returns a constant -- the size of the event check that is put at
833 the start of every translation. This makes it possible to
834 calculate the fast entry point address if the slow entry point
835 address is known (the usual case), or vice versa. */
836extern
florian7ce2cc82015-01-10 16:10:58 +0000837Int LibVEX_evCheckSzB ( VexArch arch_host );
sewardjc6f970f2012-04-02 21:54:49 +0000838
839
840/* Patch the counter location into an existing ProfInc point. The
841 specified point is checked to make sure it is plausible. */
842extern
florian7d6f81d2014-09-22 21:43:37 +0000843VexInvalRange LibVEX_PatchProfInc ( VexArch arch_host,
844 VexEndness endness_host,
845 void* place_to_patch,
846 const ULong* location_of_counter );
sewardjc24824a2005-07-07 13:52:03 +0000847
sewardjac9af022004-07-05 01:15:34 +0000848
sewardjd887b862005-01-17 18:34:34 +0000849/*-------------------------------------------------------*/
850/*--- Show accumulated statistics ---*/
851/*-------------------------------------------------------*/
sewardjac9af022004-07-05 01:15:34 +0000852
sewardj887a11a2004-07-05 17:26:47 +0000853extern void LibVEX_ShowStats ( void );
sewardjac9af022004-07-05 01:15:34 +0000854
florian2245ce92012-08-28 16:49:30 +0000855/*-------------------------------------------------------*/
856/*-- IR injection --*/
857/*-------------------------------------------------------*/
858
859/* IR Injection Control Block */
860
861#define NO_ROUNDING_MODE (~0u)
862
863typedef
864 struct {
865 IROp op; // the operation to perform
866 HWord result; // address of the result
867 HWord opnd1; // address of 1st operand
868 HWord opnd2; // address of 2nd operand
869 HWord opnd3; // address of 3rd operand
870 HWord opnd4; // address of 4th operand
871 IRType t_result; // type of result
872 IRType t_opnd1; // type of 1st operand
873 IRType t_opnd2; // type of 2nd operand
874 IRType t_opnd3; // type of 3rd operand
875 IRType t_opnd4; // type of 4th operand
876 UInt rounding_mode;
877 UInt num_operands; // excluding rounding mode, if any
Elliott Hughesa0664b92017-04-18 17:46:52 -0700878 /* The following two members describe if this operand has immediate
879 * operands. There are a few restrictions:
880 * (1) An operator can have at most one immediate operand.
881 * (2) If there is an immediate operand, it is the right-most operand
882 * An immediate_index of 0 means there is no immediate operand.
883 */
884 UInt immediate_type; // size of immediate Ity_I8, Ity_16
885 UInt immediate_index; // operand number: 1, 2
florian2245ce92012-08-28 16:49:30 +0000886 }
887 IRICB;
888
889extern void LibVEX_InitIRI ( const IRICB * );
sewardjac9af022004-07-05 01:15:34 +0000890
sewardjd887b862005-01-17 18:34:34 +0000891/*-------------------------------------------------------*/
892/*--- Notes ---*/
893/*-------------------------------------------------------*/
sewardj812a8582005-01-13 16:33:19 +0000894
895/* Code generation conventions that need to be recorded somewhere.
896 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
897
898 x86
899 ~~~
sewardj17c7f952005-12-15 14:02:34 +0000900 Generated code should be entered using a JMP instruction. On
sewardj812a8582005-01-13 16:33:19 +0000901 entry, %ebp should point to the guest state, and %esp should be a
902 valid stack pointer. The generated code may change %eax, %ebx,
903 %ecx, %edx, %esi, %edi, all the FP registers and control state, and
904 all the XMM registers.
905
sewardj6915b972005-01-13 16:36:42 +0000906 On entry, the FPU control word should be set to 0x027F, and the SSE
sewardj812a8582005-01-13 16:33:19 +0000907 control word (%mxcsr) should be set to 0x1F80. On exit, they
908 should still have those values (after masking off the lowest 6 bits
909 of %mxcsr). If they don't, there is a bug in VEX-generated code.
910
sewardj17c7f952005-12-15 14:02:34 +0000911 Generated code returns to the scheduler using a JMP instruction, to
912 the address specified in the .dispatch field of VexTranslateArgs.
sewardj812a8582005-01-13 16:33:19 +0000913 %eax (or %eax:%edx, if simulating a 64-bit target) will contain the
sewardj17c7f952005-12-15 14:02:34 +0000914 guest address of the next block to execute. %ebp may be changed
915 to a VEX_TRC_ value, otherwise it should be as it was at entry.
sewardj812a8582005-01-13 16:33:19 +0000916
917 CRITICAL ISSUES in x86 code generation. The only known critical
918 issue is that the host FPU and SSE state is not properly saved
919 across calls to helper functions. If any helper references any
920 such state, it is likely (1) to misbehave itself, since the FP
921 stack tags will not be as expected, and (2) after returning to
922 generated code, the generated code is likely to go wrong. This
923 really should be fixed.
sewardjdb4738a2005-07-07 01:32:16 +0000924
sewardj17c7f952005-12-15 14:02:34 +0000925 amd64
926 ~~~~~
927 Analogous to x86.
928
929 ppc32
930 ~~~~~
931 On entry, guest state pointer is r31. .dispatch must be NULL.
932 Control is returned with a branch to the link register. Generated
933 code will not change lr. At return, r3 holds the next guest addr
934 (or r3:r4 ?). r31 may be may be changed to a VEX_TRC_ value,
935 otherwise it should be as it was at entry.
936
937 ppc64
938 ~~~~~
cerion5b2325f2005-12-23 00:55:09 +0000939 Same as ppc32.
sewardj17c7f952005-12-15 14:02:34 +0000940
sewardjbbcf1882014-01-12 12:49:10 +0000941 arm32
942 ~~~~~
943 r8 is GSP.
944
945 arm64
946 ~~~~~
947 r21 is GSP.
948
sewardjdb4738a2005-07-07 01:32:16 +0000949 ALL GUEST ARCHITECTURES
950 ~~~~~~~~~~~~~~~~~~~~~~~
sewardj05f5e012014-05-04 10:52:11 +0000951 The guest state must contain two pseudo-registers, guest_CMSTART
952 and guest_CMLEN. These are used to specify guest address ranges,
953 either of code to be invalidated, when used in conjunction with
954 Ijk_InvalICache, or of d-cache ranges to be flushed, when used in
955 conjunction with Ijk_FlushDCache. In such cases, the two _CM
956 pseudo-regs should be filled in by the IR, and then an exit with
957 one of the two abovementioned Ijk_ kinds should happen, so that the
958 dispatcher can action them. Both pseudo-regs must have size equal
959 to the guest word size.
sewardjce02aa72006-01-12 12:27:58 +0000960
961 The architecture must a third pseudo-register, guest_NRADDR, also
962 guest-word-sized. This is used to record the unredirected guest
963 address at the start of a translation whose start has been
964 redirected. By reading this pseudo-register shortly afterwards,
965 the translation can find out what the corresponding no-redirection
966 address was. Note, this is only set for wrap-style redirects, not
967 for replace-style ones.
sewardj812a8582005-01-13 16:33:19 +0000968*/
sewardj887a11a2004-07-05 17:26:47 +0000969#endif /* ndef __LIBVEX_H */
sewardjac9af022004-07-05 01:15:34 +0000970
971/*---------------------------------------------------------------*/
sewardj887a11a2004-07-05 17:26:47 +0000972/*--- libvex.h ---*/
sewardjac9af022004-07-05 01:15:34 +0000973/*---------------------------------------------------------------*/