sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 1 | |
| 2 | /*--------------------------------------------------------------------*/ |
| 3 | /*--- ---*/ |
| 4 | /*--- This file (guest-generic/bb_to_IR.h) is ---*/ |
sewardj | dbcfae7 | 2005-08-02 11:14:04 +0000 | [diff] [blame] | 5 | /*--- Copyright (C) OpenWorks LLP. All rights reserved. ---*/ |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 6 | /*--- ---*/ |
| 7 | /*--------------------------------------------------------------------*/ |
| 8 | |
| 9 | /* |
| 10 | This file is part of LibVEX, a library for dynamic binary |
| 11 | instrumentation and translation. |
| 12 | |
sewardj | 7bd6ffe | 2005-08-03 16:07:36 +0000 | [diff] [blame] | 13 | Copyright (C) 2004-2005 OpenWorks LLP. All rights reserved. |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 14 | |
sewardj | 7bd6ffe | 2005-08-03 16:07:36 +0000 | [diff] [blame] | 15 | This library is made available under a dual licensing scheme. |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 16 | |
sewardj | 7bd6ffe | 2005-08-03 16:07:36 +0000 | [diff] [blame] | 17 | If you link LibVEX against other code all of which is itself |
| 18 | licensed under the GNU General Public License, version 2 dated June |
| 19 | 1991 ("GPL v2"), then you may use LibVEX under the terms of the GPL |
| 20 | v2, as appearing in the file LICENSE.GPL. If the file LICENSE.GPL |
| 21 | is missing, you can obtain a copy of the GPL v2 from the Free |
| 22 | Software Foundation Inc., 51 Franklin St, Fifth Floor, Boston, MA |
| 23 | 02110-1301, USA. |
| 24 | |
| 25 | For any other uses of LibVEX, you must first obtain a commercial |
| 26 | license from OpenWorks LLP. Please contact info@open-works.co.uk |
| 27 | for information about commercial licensing. |
| 28 | |
| 29 | This software is provided by OpenWorks LLP "as is" and any express |
| 30 | or implied warranties, including, but not limited to, the implied |
| 31 | warranties of merchantability and fitness for a particular purpose |
| 32 | are disclaimed. In no event shall OpenWorks LLP be liable for any |
| 33 | direct, indirect, incidental, special, exemplary, or consequential |
| 34 | damages (including, but not limited to, procurement of substitute |
| 35 | goods or services; loss of use, data, or profits; or business |
| 36 | interruption) however caused and on any theory of liability, |
| 37 | whether in contract, strict liability, or tort (including |
| 38 | negligence or otherwise) arising in any way out of the use of this |
| 39 | software, even if advised of the possibility of such damage. |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 40 | |
| 41 | Neither the names of the U.S. Department of Energy nor the |
| 42 | University of California nor the names of its contributors may be |
| 43 | used to endorse or promote products derived from this software |
| 44 | without prior written permission. |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 45 | */ |
| 46 | |
| 47 | #ifndef __LIBVEX_GENERIC_BB_TO_IR_H |
| 48 | #define __LIBVEX_GENERIC_BB_TO_IR_H |
| 49 | |
| 50 | |
| 51 | /* This defines stuff needed by the guest insn disassemblers. |
| 52 | It's a bit circular; is imported by |
cerion | 7594920 | 2005-12-24 13:14:11 +0000 | [diff] [blame] | 53 | - the guest-specific toIR.c files (guest-{x86,amd64,ppc,arm}/toIR.c) |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 54 | - the generic disassembly driver (bb_to_IR.c) |
| 55 | - vex_main.c |
| 56 | */ |
| 57 | |
| 58 | |
| 59 | /* --------------------------------------------------------------- |
| 60 | Result of disassembling an instruction |
| 61 | --------------------------------------------------------------- */ |
| 62 | |
| 63 | /* The results of disassembling an instruction. There are three |
| 64 | possible outcomes. For Dis_Resteer, the disassembler _must_ |
| 65 | continue at the specified address. For Dis_StopHere, the |
| 66 | disassembler _must_ terminate the BB. For Dis_Continue, we may at |
| 67 | our option either disassemble the next insn, or terminate the BB; |
| 68 | but in the latter case we must set the bb's ->next field to point |
| 69 | to the next instruction. */ |
| 70 | |
| 71 | typedef |
| 72 | |
| 73 | struct { |
| 74 | |
| 75 | /* The disassembled insn has this length. Must always be |
| 76 | set. */ |
| 77 | Int len; |
| 78 | |
| 79 | /* What happens next? |
| 80 | Dis_StopHere: this insn terminates the BB; we must stop. |
| 81 | Dis_Continue: we can optionally continue into the next insn |
| 82 | Dis_Resteer: followed a branch; continue at the spec'd addr |
| 83 | */ |
| 84 | enum { Dis_StopHere, Dis_Continue, Dis_Resteer } whatNext; |
| 85 | |
| 86 | /* For Dis_Resteer, this is the guest address we should continue |
| 87 | at. Otherwise ignored (should be zero). */ |
| 88 | Addr64 continueAt; |
| 89 | |
| 90 | } |
| 91 | |
| 92 | DisResult; |
| 93 | |
| 94 | |
| 95 | /* --------------------------------------------------------------- |
| 96 | The type of a function which disassembles one instruction. |
| 97 | C's function-type syntax is really astonishing bizarre. |
| 98 | --------------------------------------------------------------- */ |
| 99 | |
| 100 | /* A function of this type (DisOneInstrFn) disassembles an instruction |
| 101 | located at host address &guest_code[delta], whose guest IP is |
| 102 | guest_IP (this may be entirely unrelated to where the insn is |
| 103 | actually located in the host's address space.). The returned |
| 104 | DisResult.len field carries its size. If the returned |
| 105 | DisResult.whatNext field is Dis_Resteer then DisResult.continueAt |
| 106 | should hold the guest IP of the next insn to disassemble. |
| 107 | |
| 108 | disInstr is not permitted to return Dis_Resteer if resteerOkFn, |
| 109 | when applied to the address which it wishes to resteer into, |
| 110 | returns False. |
| 111 | |
| 112 | The resulting IR is added to the end of irbb. |
| 113 | */ |
| 114 | |
| 115 | typedef |
| 116 | |
| 117 | DisResult (*DisOneInstrFn) ( |
| 118 | |
| 119 | /* This is the IRBB to which the resulting IR is to be appended. */ |
| 120 | /*OUT*/ IRBB* irbb, |
| 121 | |
| 122 | /* Do we need to generate IR to set the guest IP for this insn, |
| 123 | or not? */ |
| 124 | /*IN*/ Bool put_IP, |
| 125 | |
| 126 | /* Return True iff resteering to the given addr is allowed */ |
sewardj | c716aea | 2006-01-17 01:48:46 +0000 | [diff] [blame^] | 127 | /*IN*/ Bool (*resteerOkFn) ( /*opaque*/void*, Addr64 ), |
| 128 | |
| 129 | /* Vex-opaque data passed to all caller (valgrind) supplied |
| 130 | callbacks. */ |
| 131 | /*IN*/ void* callback_opaque, |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 132 | |
| 133 | /* Where is the guest code? */ |
| 134 | /*IN*/ UChar* guest_code, |
| 135 | |
| 136 | /* Where is the actual insn? Note: it's at &guest_code[delta] */ |
| 137 | /*IN*/ Long delta, |
| 138 | |
| 139 | /* What is the guest IP of the insn? */ |
| 140 | /*IN*/ Addr64 guest_IP, |
| 141 | |
| 142 | /* Info about the guest architecture */ |
| 143 | /*IN*/ VexArchInfo* archinfo, |
| 144 | |
| 145 | /* Is the host bigendian? */ |
| 146 | /*IN*/ Bool host_bigendian |
| 147 | |
| 148 | ); |
| 149 | |
| 150 | |
| 151 | /* --------------------------------------------------------------- |
| 152 | Top-level BB to IR conversion fn. |
| 153 | --------------------------------------------------------------- */ |
| 154 | |
| 155 | /* See detailed comment in bb_to_IR.c. */ |
| 156 | extern |
| 157 | IRBB* bb_to_IR ( /*OUT*/VexGuestExtents* vge, |
sewardj | c716aea | 2006-01-17 01:48:46 +0000 | [diff] [blame^] | 158 | /*IN*/ void* closure_opaque, |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 159 | /*IN*/ DisOneInstrFn dis_instr_fn, |
| 160 | /*IN*/ UChar* guest_code, |
| 161 | /*IN*/ Addr64 guest_IP_bbstart, |
sewardj | c716aea | 2006-01-17 01:48:46 +0000 | [diff] [blame^] | 162 | /*IN*/ Bool (*chase_into_ok)(void*,Addr64), |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 163 | /*IN*/ Bool host_bigendian, |
| 164 | /*IN*/ VexArchInfo* archinfo_guest, |
sewardj | db4738a | 2005-07-07 01:32:16 +0000 | [diff] [blame] | 165 | /*IN*/ IRType guest_word_type, |
| 166 | /*IN*/ Bool do_self_check, |
sewardj | c716aea | 2006-01-17 01:48:46 +0000 | [diff] [blame^] | 167 | /*IN*/ Bool (*preamble_function)(void*,IRBB*), |
sewardj | db4738a | 2005-07-07 01:32:16 +0000 | [diff] [blame] | 168 | /*IN*/ Int offB_TISTART, |
sewardj | c716aea | 2006-01-17 01:48:46 +0000 | [diff] [blame^] | 169 | /*IN*/ Int offB_TILEN ); |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 170 | |
| 171 | |
| 172 | #endif /* ndef GENERIC_BB_TO_IR_H */ |
| 173 | |
| 174 | /*--------------------------------------------------------------------*/ |
| 175 | /*--- end guest-generic/bb_to_IR.h ---*/ |
| 176 | /*--------------------------------------------------------------------*/ |