sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 1 | |
| 2 | /*--------------------------------------------------------------------*/ |
sewardj | 752f906 | 2010-05-03 21:38:49 +0000 | [diff] [blame] | 3 | /*--- begin guest_generic_bb_to_IR.h ---*/ |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 4 | /*--------------------------------------------------------------------*/ |
| 5 | |
| 6 | /* |
sewardj | 752f906 | 2010-05-03 21:38:49 +0000 | [diff] [blame] | 7 | This file is part of Valgrind, a dynamic binary instrumentation |
| 8 | framework. |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 9 | |
Elliott Hughes | ed39800 | 2017-06-21 14:41:24 -0700 | [diff] [blame] | 10 | Copyright (C) 2004-2017 OpenWorks LLP |
sewardj | 752f906 | 2010-05-03 21:38:49 +0000 | [diff] [blame] | 11 | info@open-works.net |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 12 | |
sewardj | 752f906 | 2010-05-03 21:38:49 +0000 | [diff] [blame] | 13 | 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. |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 17 | |
sewardj | 752f906 | 2010-05-03 21:38:49 +0000 | [diff] [blame] | 18 | 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 |
sewardj | 7bd6ffe | 2005-08-03 16:07:36 +0000 | [diff] [blame] | 26 | 02110-1301, USA. |
| 27 | |
sewardj | 752f906 | 2010-05-03 21:38:49 +0000 | [diff] [blame] | 28 | The GNU General Public License is contained in the file COPYING. |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 29 | |
| 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. |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 34 | */ |
| 35 | |
sewardj | cef7d3e | 2009-07-02 12:21:59 +0000 | [diff] [blame] | 36 | #ifndef __VEX_GUEST_GENERIC_BB_TO_IR_H |
| 37 | #define __VEX_GUEST_GENERIC_BB_TO_IR_H |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 38 | |
florian | 58a637b | 2012-09-30 20:30:17 +0000 | [diff] [blame] | 39 | #include "libvex_basictypes.h" |
| 40 | #include "libvex_ir.h" // IRJumpKind |
| 41 | #include "libvex.h" // VexArch |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 42 | |
| 43 | /* This defines stuff needed by the guest insn disassemblers. |
| 44 | It's a bit circular; is imported by |
cerion | 7594920 | 2005-12-24 13:14:11 +0000 | [diff] [blame] | 45 | - the guest-specific toIR.c files (guest-{x86,amd64,ppc,arm}/toIR.c) |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 46 | - the generic disassembly driver (bb_to_IR.c) |
| 47 | - vex_main.c |
| 48 | */ |
| 49 | |
| 50 | |
| 51 | /* --------------------------------------------------------------- |
| 52 | Result of disassembling an instruction |
| 53 | --------------------------------------------------------------- */ |
| 54 | |
| 55 | /* The results of disassembling an instruction. There are three |
| 56 | possible outcomes. For Dis_Resteer, the disassembler _must_ |
| 57 | continue at the specified address. For Dis_StopHere, the |
| 58 | disassembler _must_ terminate the BB. For Dis_Continue, we may at |
| 59 | our option either disassemble the next insn, or terminate the BB; |
| 60 | but in the latter case we must set the bb's ->next field to point |
| 61 | to the next instruction. */ |
| 62 | |
| 63 | typedef |
| 64 | |
| 65 | struct { |
| 66 | |
| 67 | /* The disassembled insn has this length. Must always be |
| 68 | set. */ |
florian | 8e2d971 | 2015-01-02 14:40:59 +0000 | [diff] [blame] | 69 | UInt len; |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 70 | |
| 71 | /* What happens next? |
| 72 | Dis_StopHere: this insn terminates the BB; we must stop. |
| 73 | Dis_Continue: we can optionally continue into the next insn |
sewardj | 984d9b1 | 2010-01-15 10:53:21 +0000 | [diff] [blame] | 74 | Dis_ResteerU: followed an unconditional branch; continue at |
| 75 | 'continueAt' |
| 76 | Dis_ResteerC: (speculatively, of course) followed a |
| 77 | conditional branch; continue at 'continueAt' |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 78 | */ |
Elliott Hughes | ed39800 | 2017-06-21 14:41:24 -0700 | [diff] [blame] | 79 | enum { Dis_StopHere=0x10, Dis_Continue, |
sewardj | 984d9b1 | 2010-01-15 10:53:21 +0000 | [diff] [blame] | 80 | Dis_ResteerU, Dis_ResteerC } whatNext; |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 81 | |
Elliott Hughes | ed39800 | 2017-06-21 14:41:24 -0700 | [diff] [blame] | 82 | /* Any other hints that we should feed back to the disassembler? |
| 83 | Dis_HintNone: no hint |
| 84 | Dis_HintVerbose: this insn potentially generates a lot of code |
| 85 | */ |
| 86 | enum { Dis_HintNone=0x20, Dis_HintVerbose } hint; |
| 87 | |
| 88 | /* For whatNext==Dis_StopHere, we need to end the block and create a |
sewardj | c6f970f | 2012-04-02 21:54:49 +0000 | [diff] [blame] | 89 | transfer to whatever the NIA is. That will have presumably |
| 90 | been set by the IR generated for this insn. So we need to |
| 91 | know the jump kind to use. Should Ijk_INVALID in other Dis_ |
| 92 | cases. */ |
| 93 | IRJumpKind jk_StopHere; |
| 94 | |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 95 | /* For Dis_Resteer, this is the guest address we should continue |
| 96 | at. Otherwise ignored (should be zero). */ |
florian | 0eaa35f | 2015-01-02 13:34:15 +0000 | [diff] [blame] | 97 | Addr continueAt; |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | DisResult; |
| 101 | |
| 102 | |
| 103 | /* --------------------------------------------------------------- |
| 104 | The type of a function which disassembles one instruction. |
| 105 | C's function-type syntax is really astonishing bizarre. |
| 106 | --------------------------------------------------------------- */ |
| 107 | |
| 108 | /* A function of this type (DisOneInstrFn) disassembles an instruction |
| 109 | located at host address &guest_code[delta], whose guest IP is |
| 110 | guest_IP (this may be entirely unrelated to where the insn is |
| 111 | actually located in the host's address space.). The returned |
| 112 | DisResult.len field carries its size. If the returned |
| 113 | DisResult.whatNext field is Dis_Resteer then DisResult.continueAt |
| 114 | should hold the guest IP of the next insn to disassemble. |
| 115 | |
| 116 | disInstr is not permitted to return Dis_Resteer if resteerOkFn, |
| 117 | when applied to the address which it wishes to resteer into, |
| 118 | returns False. |
| 119 | |
| 120 | The resulting IR is added to the end of irbb. |
| 121 | */ |
| 122 | |
| 123 | typedef |
| 124 | |
| 125 | DisResult (*DisOneInstrFn) ( |
| 126 | |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 127 | /* This is the IRSB to which the resulting IR is to be appended. */ |
| 128 | /*OUT*/ IRSB* irbb, |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 129 | |
sewardj | 984d9b1 | 2010-01-15 10:53:21 +0000 | [diff] [blame] | 130 | /* Return True iff resteering to the given addr is allowed (for |
| 131 | branches/calls to destinations that are known at JIT-time) */ |
florian | beac530 | 2014-12-31 12:09:38 +0000 | [diff] [blame] | 132 | /*IN*/ Bool (*resteerOkFn) ( /*opaque*/void*, Addr ), |
sewardj | c716aea | 2006-01-17 01:48:46 +0000 | [diff] [blame] | 133 | |
sewardj | 984d9b1 | 2010-01-15 10:53:21 +0000 | [diff] [blame] | 134 | /* Should we speculatively resteer across conditional branches? |
| 135 | (Experimental and not enabled by default). The strategy is |
| 136 | to assume that backward branches are taken and forward |
| 137 | branches are not taken. */ |
| 138 | /*IN*/ Bool resteerCisOk, |
| 139 | |
sewardj | c716aea | 2006-01-17 01:48:46 +0000 | [diff] [blame] | 140 | /* Vex-opaque data passed to all caller (valgrind) supplied |
| 141 | callbacks. */ |
| 142 | /*IN*/ void* callback_opaque, |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 143 | |
| 144 | /* Where is the guest code? */ |
florian | 8462d11 | 2014-09-24 15:18:09 +0000 | [diff] [blame] | 145 | /*IN*/ const UChar* guest_code, |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 146 | |
| 147 | /* Where is the actual insn? Note: it's at &guest_code[delta] */ |
| 148 | /*IN*/ Long delta, |
| 149 | |
| 150 | /* What is the guest IP of the insn? */ |
florian | d4cc0de | 2015-01-02 11:44:12 +0000 | [diff] [blame] | 151 | /*IN*/ Addr guest_IP, |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 152 | |
| 153 | /* Info about the guest architecture */ |
sewardj | a5f55da | 2006-04-30 23:37:32 +0000 | [diff] [blame] | 154 | /*IN*/ VexArch guest_arch, |
florian | cacba8e | 2014-12-15 18:58:07 +0000 | [diff] [blame] | 155 | /*IN*/ const VexArchInfo* archinfo, |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 156 | |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 157 | /* ABI info for both guest and host */ |
florian | cacba8e | 2014-12-15 18:58:07 +0000 | [diff] [blame] | 158 | /*IN*/ const VexAbiInfo* abiinfo, |
sewardj | aca070a | 2006-10-17 00:28:22 +0000 | [diff] [blame] | 159 | |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 160 | /* The endianness of the host */ |
| 161 | /*IN*/ VexEndness host_endness, |
sewardj | 442e51a | 2012-12-06 18:08:04 +0000 | [diff] [blame] | 162 | |
| 163 | /* Should diagnostics be printed for illegal instructions? */ |
| 164 | /*IN*/ Bool sigill_diag |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 165 | |
| 166 | ); |
| 167 | |
| 168 | |
| 169 | /* --------------------------------------------------------------- |
| 170 | Top-level BB to IR conversion fn. |
| 171 | --------------------------------------------------------------- */ |
| 172 | |
sewardj | ca2c3c7 | 2015-02-05 12:53:20 +0000 | [diff] [blame] | 173 | /* See detailed comment in guest_generic_bb_to_IR.c. */ |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 174 | extern |
sewardj | bc161a4 | 2011-06-07 21:28:38 +0000 | [diff] [blame] | 175 | IRSB* bb_to_IR ( |
| 176 | /*OUT*/VexGuestExtents* vge, |
| 177 | /*OUT*/UInt* n_sc_extents, |
sewardj | fadbbe2 | 2012-04-24 11:49:03 +0000 | [diff] [blame] | 178 | /*OUT*/UInt* n_guest_instrs, /* stats only */ |
sewardj | ca2c3c7 | 2015-02-05 12:53:20 +0000 | [diff] [blame] | 179 | /*MOD*/VexRegisterUpdates* pxControl, |
sewardj | bc161a4 | 2011-06-07 21:28:38 +0000 | [diff] [blame] | 180 | /*IN*/ void* callback_opaque, |
| 181 | /*IN*/ DisOneInstrFn dis_instr_fn, |
florian | 8462d11 | 2014-09-24 15:18:09 +0000 | [diff] [blame] | 182 | /*IN*/ const UChar* guest_code, |
florian | d4cc0de | 2015-01-02 11:44:12 +0000 | [diff] [blame] | 183 | /*IN*/ Addr guest_IP_bbstart, |
florian | beac530 | 2014-12-31 12:09:38 +0000 | [diff] [blame] | 184 | /*IN*/ Bool (*chase_into_ok)(void*,Addr), |
sewardj | 9b76916 | 2014-07-24 12:42:03 +0000 | [diff] [blame] | 185 | /*IN*/ VexEndness host_endness, |
sewardj | 442e51a | 2012-12-06 18:08:04 +0000 | [diff] [blame] | 186 | /*IN*/ Bool sigill_diag, |
sewardj | bc161a4 | 2011-06-07 21:28:38 +0000 | [diff] [blame] | 187 | /*IN*/ VexArch arch_guest, |
florian | cacba8e | 2014-12-15 18:58:07 +0000 | [diff] [blame] | 188 | /*IN*/ const VexArchInfo* archinfo_guest, |
| 189 | /*IN*/ const VexAbiInfo* abiinfo_both, |
sewardj | bc161a4 | 2011-06-07 21:28:38 +0000 | [diff] [blame] | 190 | /*IN*/ IRType guest_word_type, |
sewardj | ca2c3c7 | 2015-02-05 12:53:20 +0000 | [diff] [blame] | 191 | /*IN*/ UInt (*needs_self_check) |
| 192 | (void*, /*MB_MOD*/VexRegisterUpdates*, |
| 193 | const VexGuestExtents*), |
sewardj | bc161a4 | 2011-06-07 21:28:38 +0000 | [diff] [blame] | 194 | /*IN*/ Bool (*preamble_function)(void*,IRSB*), |
sewardj | 05f5e01 | 2014-05-04 10:52:11 +0000 | [diff] [blame] | 195 | /*IN*/ Int offB_GUEST_CMSTART, |
| 196 | /*IN*/ Int offB_GUEST_CMLEN, |
sewardj | c6f970f | 2012-04-02 21:54:49 +0000 | [diff] [blame] | 197 | /*IN*/ Int offB_GUEST_IP, |
| 198 | /*IN*/ Int szB_GUEST_IP |
sewardj | bc161a4 | 2011-06-07 21:28:38 +0000 | [diff] [blame] | 199 | ); |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 200 | |
| 201 | |
sewardj | cef7d3e | 2009-07-02 12:21:59 +0000 | [diff] [blame] | 202 | #endif /* ndef __VEX_GUEST_GENERIC_BB_TO_IR_H */ |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 203 | |
| 204 | /*--------------------------------------------------------------------*/ |
sewardj | cef7d3e | 2009-07-02 12:21:59 +0000 | [diff] [blame] | 205 | /*--- end guest_generic_bb_to_IR.h ---*/ |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 206 | /*--------------------------------------------------------------------*/ |