blob: 60a889570a972229d74be8b7d7c38d39bde5ec30 [file] [log] [blame]
sewardjac9af022004-07-05 01:15:34 +00001
2/*---------------------------------------------------------------*/
3/*--- ---*/
sewardj887a11a2004-07-05 17:26:47 +00004/*--- This file (libvex.h) is ---*/
sewardjac9af022004-07-05 01:15:34 +00005/*--- Copyright (c) 2004 OpenWorks LLP. All rights reserved. ---*/
6/*--- ---*/
7/*---------------------------------------------------------------*/
8
sewardj887a11a2004-07-05 17:26:47 +00009#ifndef __LIBVEX_H
10#define __LIBVEX_H
sewardjac9af022004-07-05 01:15:34 +000011
12
sewardj887a11a2004-07-05 17:26:47 +000013#include "libvex_basictypes.h"
14#include "libvex_ir.h"
sewardjac9af022004-07-05 01:15:34 +000015
16
17/*---------------------------------------------------------------*/
18/*--- Top-level interface to the library. ---*/
19/*---------------------------------------------------------------*/
20
21
sewardj08613742004-10-25 13:01:45 +000022/* Control of Vex's optimiser. */
23
24typedef
25 struct {
26 /* Controls verbosity of iropt. 0 = no output. */
27 Int iropt_verbosity;
28 /* Control aggressiveness of iropt. 0 = no opt, 1 = simple
29 opts, 2 (default) = max optimisation. */
30 Int iropt_level;
31 /* Ensure all integer registers are up to date at potential
32 memory exception points? True(default)=yes, False=no, only
33 the guest's stack pointer. */
34 Bool iropt_precise_memory_exns;
35 /* How aggressive should iropt be in unrolling loops? Higher
36 numbers make it more enthusiastic about loop unrolling.
37 Default=120. A setting of zero disables unrolling. */
38 Int iropt_unroll_thresh;
39 /* What's the maximum basic block length the front end(s) allow?
40 BBs longer than this are split up. Default=50 (guest
41 insns). */
42 Int guest_max_insns;
43 /* How aggressive should front ends be in following
44 unconditional branches to known destinations? Default=10,
45 meaning that if a block contains less than 10 guest insns so
46 far, the front end(s) will attempt to chase into its
47 successor. A setting of zero disables chasing. */
48 Int guest_chase_thresh;
49 }
50 VexControl;
51
52
53/* Write the default settings into *vcon. */
54extern void LibVEX_default_VexControl ( /*OUT*/ VexControl* vcon );
55
56
sewardjac9af022004-07-05 01:15:34 +000057/* Initialise the translator. */
58
sewardj887a11a2004-07-05 17:26:47 +000059extern void LibVEX_Init (
sewardjac9af022004-07-05 01:15:34 +000060 /* failure exit function */
sewardj2b515872004-07-05 20:50:45 +000061 __attribute__ ((noreturn))
sewardjac9af022004-07-05 01:15:34 +000062 void (*failure_exit) ( void ),
63 /* logging output function */
64 void (*log_bytes) ( Char*, Int nbytes ),
65 /* debug paranoia level */
66 Int debuglevel,
67 /* verbosity level */
68 Int verbosity,
69 /* Are we supporting valgrind checking? */
70 Bool valgrind_support,
sewardj08613742004-10-25 13:01:45 +000071 /* Control ... */
72 /*READONLY*/VexControl* vcon
sewardjac9af022004-07-05 01:15:34 +000073);
74
75
76/* Storage management: clear the area, and allocate from it. */
77
sewardj443cd9d2004-07-18 23:06:45 +000078/* By default allocation occurs in the temporary area. However, it is
79 possible to switch to permanent area allocation if that's what you
80 want. Permanent area allocation is very limited, tho. */
81
82typedef
83 enum { AllocModeTEMPORARY, AllocModePERMANENT }
84 AllocMode;
85
86extern void LibVEX_SetAllocMode ( AllocMode );
87extern AllocMode LibVEX_GetAllocMode ( void );
88
89extern void LibVEX_ClearTemporary ( Bool show_stats );
sewardjac9af022004-07-05 01:15:34 +000090
sewardj35421a32004-07-05 13:12:34 +000091extern void* LibVEX_Alloc ( Int nbytes );
sewardjac9af022004-07-05 01:15:34 +000092
93
94/* Translate a basic block. */
95
96typedef
97 enum { InsnSetX86, InsnSetARM }
98 InsnSet;
99
100typedef
101 enum { TransOK, TransAccessFail, TransOutputFull }
102 TranslateResult;
103
104extern
sewardj887a11a2004-07-05 17:26:47 +0000105TranslateResult LibVEX_Translate (
sewardjac9af022004-07-05 01:15:34 +0000106 /* The instruction sets we are translating from and to. */
107 InsnSet iset_guest,
108 InsnSet iset_host,
109 /* IN: the block to translate, and its guest address. */
sewardj81bd5502004-07-21 18:49:27 +0000110 UChar* guest_bytes,
sewardjac9af022004-07-05 01:15:34 +0000111 Addr64 guest_bytes_addr,
112 /* OUT: the number of bytes actually read */
113 Int* guest_bytes_read,
114 /* IN: a place to put the resulting code, and its size */
sewardj81bd5502004-07-21 18:49:27 +0000115 UChar* host_bytes,
116 Int host_bytes_size,
sewardjac9af022004-07-05 01:15:34 +0000117 /* OUT: how much of the output area is used. */
118 Int* host_bytes_used,
119 /* IN: optionally, an instrumentation function. */
sewardjf13a16a2004-07-05 17:10:14 +0000120 IRBB* (*instrument) ( IRBB* ),
sewardjac9af022004-07-05 01:15:34 +0000121 /* IN: optionally, an access check function for guest code. */
sewardj58800ff2004-07-28 01:51:10 +0000122 Bool (*byte_accessible) ( Addr64 ),
123 /* IN: if > 0, use this verbosity for this bb */
124 Int bb_verbosity
sewardjac9af022004-07-05 01:15:34 +0000125);
126
127
128/* Show accumulated statistics. */
129
sewardj887a11a2004-07-05 17:26:47 +0000130extern void LibVEX_ShowStats ( void );
sewardjac9af022004-07-05 01:15:34 +0000131
132
sewardj887a11a2004-07-05 17:26:47 +0000133#endif /* ndef __LIBVEX_H */
sewardjac9af022004-07-05 01:15:34 +0000134
135/*---------------------------------------------------------------*/
sewardj887a11a2004-07-05 17:26:47 +0000136/*--- libvex.h ---*/
sewardjac9af022004-07-05 01:15:34 +0000137/*---------------------------------------------------------------*/