Initial implementation of C-source-level &&-idiom recovery
[valgrind.git] / VEX / priv / guest_generic_bb_to_IR.h
blob08d33ad3a674384a47226c5443e1e34e04212319
2 /*--------------------------------------------------------------------*/
3 /*--- begin guest_generic_bb_to_IR.h ---*/
4 /*--------------------------------------------------------------------*/
6 /*
7 This file is part of Valgrind, a dynamic binary instrumentation
8 framework.
10 Copyright (C) 2004-2017 OpenWorks LLP
11 info@open-works.net
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.
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.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, see <http://www.gnu.org/licenses/>.
26 The GNU General Public License is contained in the file COPYING.
28 Neither the names of the U.S. Department of Energy nor the
29 University of California nor the names of its contributors may be
30 used to endorse or promote products derived from this software
31 without prior written permission.
34 #ifndef __VEX_GUEST_GENERIC_BB_TO_IR_H
35 #define __VEX_GUEST_GENERIC_BB_TO_IR_H
37 #include "libvex_basictypes.h"
38 #include "libvex_ir.h" // IRJumpKind
39 #include "libvex.h" // VexArch
41 /* This defines stuff needed by the guest insn disassemblers.
42 It's a bit circular; is imported by
43 - the guest-specific toIR.c files (guest-{x86,amd64,ppc,arm}/toIR.c)
44 - the generic disassembly driver (bb_to_IR.c)
45 - vex_main.c
49 /* ---------------------------------------------------------------
50 Result of disassembling an instruction
51 --------------------------------------------------------------- */
53 /* The results of disassembling an instruction. There are three possible
54 outcomes. For Dis_StopHere, the disassembler _must_ terminate the BB. For
55 Dis_Continue, we may at our option either disassemble the next insn, or
56 terminate the BB; but in the latter case we must set the bb's ->next field
57 to point to the next instruction. */
59 typedef
61 struct {
63 /* The disassembled insn has this length. Must always be
64 set. */
65 UInt len;
67 /* What happens next?
68 Dis_StopHere: this insn terminates the BB; we must stop.
69 Dis_Continue: we can optionally continue into the next insn
71 enum { Dis_StopHere=0x10, Dis_Continue } whatNext;
73 /* Any other hints that we should feed back to the disassembler?
74 Dis_HintNone: no hint
75 Dis_HintVerbose: this insn potentially generates a lot of code
77 enum { Dis_HintNone=0x20, Dis_HintVerbose } hint;
79 /* For whatNext==Dis_StopHere, we need to end the block and create a
80 transfer to whatever the NIA is. That will have presumably
81 been set by the IR generated for this insn. So we need to
82 know the jump kind to use. Should Ijk_INVALID in other Dis_
83 cases. */
84 IRJumpKind jk_StopHere;
88 DisResult;
91 /* ---------------------------------------------------------------
92 The type of a function which disassembles one instruction.
93 --------------------------------------------------------------- */
95 /* A function of this type (DisOneInstrFn) disassembles an instruction
96 located at host address &guest_code[delta], whose guest IP is
97 guest_IP (this may be entirely unrelated to where the insn is
98 actually located in the host's address space.). The returned
99 DisResult.len field carries its size.
101 The resulting IR is added to the end of irsb.
104 typedef
106 DisResult (*DisOneInstrFn) (
108 /* This is the IRSB to which the resulting IR is to be appended. */
109 /*OUT*/ IRSB* irsb,
111 /* Where is the guest code? */
112 /*IN*/ const UChar* guest_code,
114 /* Where is the actual insn? Note: it's at &guest_code[delta] */
115 /*IN*/ Long delta,
117 /* What is the guest IP of the insn? */
118 /*IN*/ Addr guest_IP,
120 /* Info about the guest architecture */
121 /*IN*/ VexArch guest_arch,
122 /*IN*/ const VexArchInfo* archinfo,
124 /* ABI info for both guest and host */
125 /*IN*/ const VexAbiInfo* abiinfo,
127 /* The endianness of the host */
128 /*IN*/ VexEndness host_endness,
130 /* Should diagnostics be printed for illegal instructions? */
131 /*IN*/ Bool sigill_diag
136 /* ---------------------------------------------------------------
137 Top-level BB to IR conversion fn.
138 --------------------------------------------------------------- */
140 /* See detailed comment in guest_generic_bb_to_IR.c. */
141 extern
142 IRSB* bb_to_IR (
143 /*OUT*/VexGuestExtents* vge,
144 /*OUT*/UInt* n_sc_extents,
145 /*OUT*/UInt* n_guest_instrs, /* stats only */
146 /*MOD*/VexRegisterUpdates* pxControl,
147 /*IN*/ void* callback_opaque,
148 /*IN*/ DisOneInstrFn dis_instr_fn,
149 /*IN*/ const UChar* guest_code,
150 /*IN*/ Addr guest_IP_bbstart,
151 /*IN*/ Bool (*chase_into_ok)(void*,Addr),
152 /*IN*/ VexEndness host_endness,
153 /*IN*/ Bool sigill_diag,
154 /*IN*/ VexArch arch_guest,
155 /*IN*/ const VexArchInfo* archinfo_guest,
156 /*IN*/ const VexAbiInfo* abiinfo_both,
157 /*IN*/ IRType guest_word_type,
158 /*IN*/ UInt (*needs_self_check)
159 (void*, /*MB_MOD*/VexRegisterUpdates*,
160 const VexGuestExtents*),
161 /*IN*/ Bool (*preamble_function)(void*,IRSB*),
162 /*IN*/ Int offB_GUEST_CMSTART,
163 /*IN*/ Int offB_GUEST_CMLEN,
164 /*IN*/ Int offB_GUEST_IP,
165 /*IN*/ Int szB_GUEST_IP
169 #endif /* ndef __VEX_GUEST_GENERIC_BB_TO_IR_H */
171 /*--------------------------------------------------------------------*/
172 /*--- end guest_generic_bb_to_IR.h ---*/
173 /*--------------------------------------------------------------------*/