sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame^] | 1 | |
| 2 | /*--------------------------------------------------------------------*/ |
| 3 | /*--- ---*/ |
| 4 | /*--- This file (guest-generic/bb_to_IR.h) is ---*/ |
| 5 | /*--- Copyright (c) OpenWorks LLP. All rights reserved. ---*/ |
| 6 | /*--- ---*/ |
| 7 | /*--------------------------------------------------------------------*/ |
| 8 | |
| 9 | /* |
| 10 | This file is part of LibVEX, a library for dynamic binary |
| 11 | instrumentation and translation. |
| 12 | |
| 13 | Copyright (C) 2004-2005 OpenWorks LLP. |
| 14 | |
| 15 | This program is free software; you can redistribute it and/or modify |
| 16 | it under the terms of the GNU General Public License as published by |
| 17 | the Free Software Foundation; Version 2 dated June 1991 of the |
| 18 | license. |
| 19 | |
| 20 | This program is distributed in the hope that it will be useful, |
| 21 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or liability |
| 23 | for damages. See the GNU General Public License for more details. |
| 24 | |
| 25 | Neither the names of the U.S. Department of Energy nor the |
| 26 | University of California nor the names of its contributors may be |
| 27 | used to endorse or promote products derived from this software |
| 28 | without prior written permission. |
| 29 | |
| 30 | You should have received a copy of the GNU General Public License |
| 31 | along with this program; if not, write to the Free Software |
| 32 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
| 33 | USA. |
| 34 | */ |
| 35 | |
| 36 | #ifndef __LIBVEX_GENERIC_BB_TO_IR_H |
| 37 | #define __LIBVEX_GENERIC_BB_TO_IR_H |
| 38 | |
| 39 | |
| 40 | /* This defines stuff needed by the guest insn disassemblers. |
| 41 | It's a bit circular; is imported by |
| 42 | - the guest-specific toIR.c files (guest-{x86,amd64,ppc32,arm}/toIR.c) |
| 43 | - the generic disassembly driver (bb_to_IR.c) |
| 44 | - vex_main.c |
| 45 | */ |
| 46 | |
| 47 | |
| 48 | /* --------------------------------------------------------------- |
| 49 | Result of disassembling an instruction |
| 50 | --------------------------------------------------------------- */ |
| 51 | |
| 52 | /* The results of disassembling an instruction. There are three |
| 53 | possible outcomes. For Dis_Resteer, the disassembler _must_ |
| 54 | continue at the specified address. For Dis_StopHere, the |
| 55 | disassembler _must_ terminate the BB. For Dis_Continue, we may at |
| 56 | our option either disassemble the next insn, or terminate the BB; |
| 57 | but in the latter case we must set the bb's ->next field to point |
| 58 | to the next instruction. */ |
| 59 | |
| 60 | typedef |
| 61 | |
| 62 | struct { |
| 63 | |
| 64 | /* The disassembled insn has this length. Must always be |
| 65 | set. */ |
| 66 | Int len; |
| 67 | |
| 68 | /* What happens next? |
| 69 | Dis_StopHere: this insn terminates the BB; we must stop. |
| 70 | Dis_Continue: we can optionally continue into the next insn |
| 71 | Dis_Resteer: followed a branch; continue at the spec'd addr |
| 72 | */ |
| 73 | enum { Dis_StopHere, Dis_Continue, Dis_Resteer } whatNext; |
| 74 | |
| 75 | /* For Dis_Resteer, this is the guest address we should continue |
| 76 | at. Otherwise ignored (should be zero). */ |
| 77 | Addr64 continueAt; |
| 78 | |
| 79 | } |
| 80 | |
| 81 | DisResult; |
| 82 | |
| 83 | |
| 84 | /* --------------------------------------------------------------- |
| 85 | The type of a function which disassembles one instruction. |
| 86 | C's function-type syntax is really astonishing bizarre. |
| 87 | --------------------------------------------------------------- */ |
| 88 | |
| 89 | /* A function of this type (DisOneInstrFn) disassembles an instruction |
| 90 | located at host address &guest_code[delta], whose guest IP is |
| 91 | guest_IP (this may be entirely unrelated to where the insn is |
| 92 | actually located in the host's address space.). The returned |
| 93 | DisResult.len field carries its size. If the returned |
| 94 | DisResult.whatNext field is Dis_Resteer then DisResult.continueAt |
| 95 | should hold the guest IP of the next insn to disassemble. |
| 96 | |
| 97 | disInstr is not permitted to return Dis_Resteer if resteerOkFn, |
| 98 | when applied to the address which it wishes to resteer into, |
| 99 | returns False. |
| 100 | |
| 101 | The resulting IR is added to the end of irbb. |
| 102 | */ |
| 103 | |
| 104 | typedef |
| 105 | |
| 106 | DisResult (*DisOneInstrFn) ( |
| 107 | |
| 108 | /* This is the IRBB to which the resulting IR is to be appended. */ |
| 109 | /*OUT*/ IRBB* irbb, |
| 110 | |
| 111 | /* Do we need to generate IR to set the guest IP for this insn, |
| 112 | or not? */ |
| 113 | /*IN*/ Bool put_IP, |
| 114 | |
| 115 | /* Return True iff resteering to the given addr is allowed */ |
| 116 | /*IN*/ Bool (*resteerOkFn) ( Addr64 ), |
| 117 | |
| 118 | /* Where is the guest code? */ |
| 119 | /*IN*/ UChar* guest_code, |
| 120 | |
| 121 | /* Where is the actual insn? Note: it's at &guest_code[delta] */ |
| 122 | /*IN*/ Long delta, |
| 123 | |
| 124 | /* What is the guest IP of the insn? */ |
| 125 | /*IN*/ Addr64 guest_IP, |
| 126 | |
| 127 | /* Info about the guest architecture */ |
| 128 | /*IN*/ VexArchInfo* archinfo, |
| 129 | |
| 130 | /* Is the host bigendian? */ |
| 131 | /*IN*/ Bool host_bigendian |
| 132 | |
| 133 | ); |
| 134 | |
| 135 | |
| 136 | /* --------------------------------------------------------------- |
| 137 | Top-level BB to IR conversion fn. |
| 138 | --------------------------------------------------------------- */ |
| 139 | |
| 140 | /* See detailed comment in bb_to_IR.c. */ |
| 141 | extern |
| 142 | IRBB* bb_to_IR ( /*OUT*/VexGuestExtents* vge, |
| 143 | /*IN*/ DisOneInstrFn dis_instr_fn, |
| 144 | /*IN*/ UChar* guest_code, |
| 145 | /*IN*/ Addr64 guest_IP_bbstart, |
| 146 | /*IN*/ Bool (*chase_into_ok)(Addr64), |
| 147 | /*IN*/ Bool host_bigendian, |
| 148 | /*IN*/ VexArchInfo* archinfo_guest, |
| 149 | /*IN*/ IRType guest_word_type ); |
| 150 | |
| 151 | |
| 152 | #endif /* ndef GENERIC_BB_TO_IR_H */ |
| 153 | |
| 154 | /*--------------------------------------------------------------------*/ |
| 155 | /*--- end guest-generic/bb_to_IR.h ---*/ |
| 156 | /*--------------------------------------------------------------------*/ |