blob: 04af2eb4af134f339cfdbd197291920541856f06 [file] [log] [blame]
sewardj9e6491a2005-07-02 19:24:10 +00001
2/*--------------------------------------------------------------------*/
3/*--- ---*/
4/*--- This file (guest-generic/bb_to_IR.h) is ---*/
sewardjdbcfae72005-08-02 11:14:04 +00005/*--- Copyright (C) OpenWorks LLP. All rights reserved. ---*/
sewardj9e6491a2005-07-02 19:24:10 +00006/*--- ---*/
7/*--------------------------------------------------------------------*/
8
9/*
10 This file is part of LibVEX, a library for dynamic binary
11 instrumentation and translation.
12
sewardj7bd6ffe2005-08-03 16:07:36 +000013 Copyright (C) 2004-2005 OpenWorks LLP. All rights reserved.
sewardj9e6491a2005-07-02 19:24:10 +000014
sewardj7bd6ffe2005-08-03 16:07:36 +000015 This library is made available under a dual licensing scheme.
sewardj9e6491a2005-07-02 19:24:10 +000016
sewardj7bd6ffe2005-08-03 16:07:36 +000017 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.
sewardj9e6491a2005-07-02 19:24:10 +000040
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.
sewardj9e6491a2005-07-02 19:24:10 +000045*/
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
cerion75949202005-12-24 13:14:11 +000053 - the guest-specific toIR.c files (guest-{x86,amd64,ppc,arm}/toIR.c)
sewardj9e6491a2005-07-02 19:24:10 +000054 - 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
71typedef
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
115typedef
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 */
sewardjc716aea2006-01-17 01:48:46 +0000127 /*IN*/ Bool (*resteerOkFn) ( /*opaque*/void*, Addr64 ),
128
129 /* Vex-opaque data passed to all caller (valgrind) supplied
130 callbacks. */
131 /*IN*/ void* callback_opaque,
sewardj9e6491a2005-07-02 19:24:10 +0000132
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. */
156extern
157IRBB* bb_to_IR ( /*OUT*/VexGuestExtents* vge,
sewardjc716aea2006-01-17 01:48:46 +0000158 /*IN*/ void* closure_opaque,
sewardj9e6491a2005-07-02 19:24:10 +0000159 /*IN*/ DisOneInstrFn dis_instr_fn,
160 /*IN*/ UChar* guest_code,
161 /*IN*/ Addr64 guest_IP_bbstart,
sewardjc716aea2006-01-17 01:48:46 +0000162 /*IN*/ Bool (*chase_into_ok)(void*,Addr64),
sewardj9e6491a2005-07-02 19:24:10 +0000163 /*IN*/ Bool host_bigendian,
164 /*IN*/ VexArchInfo* archinfo_guest,
sewardjdb4738a2005-07-07 01:32:16 +0000165 /*IN*/ IRType guest_word_type,
166 /*IN*/ Bool do_self_check,
sewardjc716aea2006-01-17 01:48:46 +0000167 /*IN*/ Bool (*preamble_function)(void*,IRBB*),
sewardjdb4738a2005-07-07 01:32:16 +0000168 /*IN*/ Int offB_TISTART,
sewardjc716aea2006-01-17 01:48:46 +0000169 /*IN*/ Int offB_TILEN );
sewardj9e6491a2005-07-02 19:24:10 +0000170
171
172#endif /* ndef GENERIC_BB_TO_IR_H */
173
174/*--------------------------------------------------------------------*/
175/*--- end guest-generic/bb_to_IR.h ---*/
176/*--------------------------------------------------------------------*/