sewardj | ac9af02 | 2004-07-05 01:15:34 +0000 | [diff] [blame] | 1 | |
| 2 | /*---------------------------------------------------------------*/ |
| 3 | /*--- ---*/ |
sewardj | 887a11a | 2004-07-05 17:26:47 +0000 | [diff] [blame] | 4 | /*--- This file (libvex.h) is ---*/ |
sewardj | ac9af02 | 2004-07-05 01:15:34 +0000 | [diff] [blame] | 5 | /*--- Copyright (c) 2004 OpenWorks LLP. All rights reserved. ---*/ |
| 6 | /*--- ---*/ |
| 7 | /*---------------------------------------------------------------*/ |
| 8 | |
sewardj | 887a11a | 2004-07-05 17:26:47 +0000 | [diff] [blame] | 9 | #ifndef __LIBVEX_H |
| 10 | #define __LIBVEX_H |
sewardj | ac9af02 | 2004-07-05 01:15:34 +0000 | [diff] [blame] | 11 | |
| 12 | |
sewardj | 887a11a | 2004-07-05 17:26:47 +0000 | [diff] [blame] | 13 | #include "libvex_basictypes.h" |
| 14 | #include "libvex_ir.h" |
sewardj | ac9af02 | 2004-07-05 01:15:34 +0000 | [diff] [blame] | 15 | |
| 16 | |
| 17 | /*---------------------------------------------------------------*/ |
| 18 | /*--- Top-level interface to the library. ---*/ |
| 19 | /*---------------------------------------------------------------*/ |
| 20 | |
| 21 | |
sewardj | 0861374 | 2004-10-25 13:01:45 +0000 | [diff] [blame^] | 22 | /* Control of Vex's optimiser. */ |
| 23 | |
| 24 | typedef |
| 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. */ |
| 54 | extern void LibVEX_default_VexControl ( /*OUT*/ VexControl* vcon ); |
| 55 | |
| 56 | |
sewardj | ac9af02 | 2004-07-05 01:15:34 +0000 | [diff] [blame] | 57 | /* Initialise the translator. */ |
| 58 | |
sewardj | 887a11a | 2004-07-05 17:26:47 +0000 | [diff] [blame] | 59 | extern void LibVEX_Init ( |
sewardj | ac9af02 | 2004-07-05 01:15:34 +0000 | [diff] [blame] | 60 | /* failure exit function */ |
sewardj | 2b51587 | 2004-07-05 20:50:45 +0000 | [diff] [blame] | 61 | __attribute__ ((noreturn)) |
sewardj | ac9af02 | 2004-07-05 01:15:34 +0000 | [diff] [blame] | 62 | 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, |
sewardj | 0861374 | 2004-10-25 13:01:45 +0000 | [diff] [blame^] | 71 | /* Control ... */ |
| 72 | /*READONLY*/VexControl* vcon |
sewardj | ac9af02 | 2004-07-05 01:15:34 +0000 | [diff] [blame] | 73 | ); |
| 74 | |
| 75 | |
| 76 | /* Storage management: clear the area, and allocate from it. */ |
| 77 | |
sewardj | 443cd9d | 2004-07-18 23:06:45 +0000 | [diff] [blame] | 78 | /* 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 | |
| 82 | typedef |
| 83 | enum { AllocModeTEMPORARY, AllocModePERMANENT } |
| 84 | AllocMode; |
| 85 | |
| 86 | extern void LibVEX_SetAllocMode ( AllocMode ); |
| 87 | extern AllocMode LibVEX_GetAllocMode ( void ); |
| 88 | |
| 89 | extern void LibVEX_ClearTemporary ( Bool show_stats ); |
sewardj | ac9af02 | 2004-07-05 01:15:34 +0000 | [diff] [blame] | 90 | |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 91 | extern void* LibVEX_Alloc ( Int nbytes ); |
sewardj | ac9af02 | 2004-07-05 01:15:34 +0000 | [diff] [blame] | 92 | |
| 93 | |
| 94 | /* Translate a basic block. */ |
| 95 | |
| 96 | typedef |
| 97 | enum { InsnSetX86, InsnSetARM } |
| 98 | InsnSet; |
| 99 | |
| 100 | typedef |
| 101 | enum { TransOK, TransAccessFail, TransOutputFull } |
| 102 | TranslateResult; |
| 103 | |
| 104 | extern |
sewardj | 887a11a | 2004-07-05 17:26:47 +0000 | [diff] [blame] | 105 | TranslateResult LibVEX_Translate ( |
sewardj | ac9af02 | 2004-07-05 01:15:34 +0000 | [diff] [blame] | 106 | /* 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. */ |
sewardj | 81bd550 | 2004-07-21 18:49:27 +0000 | [diff] [blame] | 110 | UChar* guest_bytes, |
sewardj | ac9af02 | 2004-07-05 01:15:34 +0000 | [diff] [blame] | 111 | 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 */ |
sewardj | 81bd550 | 2004-07-21 18:49:27 +0000 | [diff] [blame] | 115 | UChar* host_bytes, |
| 116 | Int host_bytes_size, |
sewardj | ac9af02 | 2004-07-05 01:15:34 +0000 | [diff] [blame] | 117 | /* OUT: how much of the output area is used. */ |
| 118 | Int* host_bytes_used, |
| 119 | /* IN: optionally, an instrumentation function. */ |
sewardj | f13a16a | 2004-07-05 17:10:14 +0000 | [diff] [blame] | 120 | IRBB* (*instrument) ( IRBB* ), |
sewardj | ac9af02 | 2004-07-05 01:15:34 +0000 | [diff] [blame] | 121 | /* IN: optionally, an access check function for guest code. */ |
sewardj | 58800ff | 2004-07-28 01:51:10 +0000 | [diff] [blame] | 122 | Bool (*byte_accessible) ( Addr64 ), |
| 123 | /* IN: if > 0, use this verbosity for this bb */ |
| 124 | Int bb_verbosity |
sewardj | ac9af02 | 2004-07-05 01:15:34 +0000 | [diff] [blame] | 125 | ); |
| 126 | |
| 127 | |
| 128 | /* Show accumulated statistics. */ |
| 129 | |
sewardj | 887a11a | 2004-07-05 17:26:47 +0000 | [diff] [blame] | 130 | extern void LibVEX_ShowStats ( void ); |
sewardj | ac9af02 | 2004-07-05 01:15:34 +0000 | [diff] [blame] | 131 | |
| 132 | |
sewardj | 887a11a | 2004-07-05 17:26:47 +0000 | [diff] [blame] | 133 | #endif /* ndef __LIBVEX_H */ |
sewardj | ac9af02 | 2004-07-05 01:15:34 +0000 | [diff] [blame] | 134 | |
| 135 | /*---------------------------------------------------------------*/ |
sewardj | 887a11a | 2004-07-05 17:26:47 +0000 | [diff] [blame] | 136 | /*--- libvex.h ---*/ |
sewardj | ac9af02 | 2004-07-05 01:15:34 +0000 | [diff] [blame] | 137 | /*---------------------------------------------------------------*/ |