blob: f0b9f760daae9b6f0b58ffa49af1da771808f880 [file] [log] [blame]
sewardj9e6491a2005-07-02 19:24:10 +00001
2/*--------------------------------------------------------------------*/
sewardj752f9062010-05-03 21:38:49 +00003/*--- begin guest_generic_bb_to_IR.h ---*/
sewardj9e6491a2005-07-02 19:24:10 +00004/*--------------------------------------------------------------------*/
5
6/*
sewardj752f9062010-05-03 21:38:49 +00007 This file is part of Valgrind, a dynamic binary instrumentation
8 framework.
sewardj9e6491a2005-07-02 19:24:10 +00009
sewardj89ae8472013-10-18 14:12:58 +000010 Copyright (C) 2004-2013 OpenWorks LLP
sewardj752f9062010-05-03 21:38:49 +000011 info@open-works.net
sewardj9e6491a2005-07-02 19:24:10 +000012
sewardj752f9062010-05-03 21:38:49 +000013 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.
sewardj9e6491a2005-07-02 19:24:10 +000017
sewardj752f9062010-05-03 21:38:49 +000018 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
sewardj7bd6ffe2005-08-03 16:07:36 +000026 02110-1301, USA.
27
sewardj752f9062010-05-03 21:38:49 +000028 The GNU General Public License is contained in the file COPYING.
sewardj9e6491a2005-07-02 19:24:10 +000029
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.
sewardj9e6491a2005-07-02 19:24:10 +000034*/
35
sewardjcef7d3e2009-07-02 12:21:59 +000036#ifndef __VEX_GUEST_GENERIC_BB_TO_IR_H
37#define __VEX_GUEST_GENERIC_BB_TO_IR_H
sewardj9e6491a2005-07-02 19:24:10 +000038
florian58a637b2012-09-30 20:30:17 +000039#include "libvex_basictypes.h"
40#include "libvex_ir.h" // IRJumpKind
41#include "libvex.h" // VexArch
sewardj9e6491a2005-07-02 19:24:10 +000042
43/* This defines stuff needed by the guest insn disassemblers.
44 It's a bit circular; is imported by
cerion75949202005-12-24 13:14:11 +000045 - the guest-specific toIR.c files (guest-{x86,amd64,ppc,arm}/toIR.c)
sewardj9e6491a2005-07-02 19:24:10 +000046 - 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
63typedef
64
65 struct {
66
67 /* The disassembled insn has this length. Must always be
68 set. */
69 Int len;
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
sewardj984d9b12010-01-15 10:53:21 +000074 Dis_ResteerU: followed an unconditional branch; continue at
75 'continueAt'
76 Dis_ResteerC: (speculatively, of course) followed a
77 conditional branch; continue at 'continueAt'
sewardj9e6491a2005-07-02 19:24:10 +000078 */
sewardj984d9b12010-01-15 10:53:21 +000079 enum { Dis_StopHere, Dis_Continue,
80 Dis_ResteerU, Dis_ResteerC } whatNext;
sewardj9e6491a2005-07-02 19:24:10 +000081
sewardjc6f970f2012-04-02 21:54:49 +000082 /* For Dis_StopHere, we need to end the block and create a
83 transfer to whatever the NIA is. That will have presumably
84 been set by the IR generated for this insn. So we need to
85 know the jump kind to use. Should Ijk_INVALID in other Dis_
86 cases. */
87 IRJumpKind jk_StopHere;
88
sewardj9e6491a2005-07-02 19:24:10 +000089 /* For Dis_Resteer, this is the guest address we should continue
90 at. Otherwise ignored (should be zero). */
91 Addr64 continueAt;
92
93 }
94
95 DisResult;
96
97
98/* ---------------------------------------------------------------
99 The type of a function which disassembles one instruction.
100 C's function-type syntax is really astonishing bizarre.
101 --------------------------------------------------------------- */
102
103/* A function of this type (DisOneInstrFn) disassembles an instruction
104 located at host address &guest_code[delta], whose guest IP is
105 guest_IP (this may be entirely unrelated to where the insn is
106 actually located in the host's address space.). The returned
107 DisResult.len field carries its size. If the returned
108 DisResult.whatNext field is Dis_Resteer then DisResult.continueAt
109 should hold the guest IP of the next insn to disassemble.
110
111 disInstr is not permitted to return Dis_Resteer if resteerOkFn,
112 when applied to the address which it wishes to resteer into,
113 returns False.
114
115 The resulting IR is added to the end of irbb.
116*/
117
118typedef
119
120 DisResult (*DisOneInstrFn) (
121
sewardjdd40fdf2006-12-24 02:20:24 +0000122 /* This is the IRSB to which the resulting IR is to be appended. */
123 /*OUT*/ IRSB* irbb,
sewardj9e6491a2005-07-02 19:24:10 +0000124
sewardj984d9b12010-01-15 10:53:21 +0000125 /* Return True iff resteering to the given addr is allowed (for
126 branches/calls to destinations that are known at JIT-time) */
sewardjc716aea2006-01-17 01:48:46 +0000127 /*IN*/ Bool (*resteerOkFn) ( /*opaque*/void*, Addr64 ),
128
sewardj984d9b12010-01-15 10:53:21 +0000129 /* Should we speculatively resteer across conditional branches?
130 (Experimental and not enabled by default). The strategy is
131 to assume that backward branches are taken and forward
132 branches are not taken. */
133 /*IN*/ Bool resteerCisOk,
134
sewardjc716aea2006-01-17 01:48:46 +0000135 /* Vex-opaque data passed to all caller (valgrind) supplied
136 callbacks. */
137 /*IN*/ void* callback_opaque,
sewardj9e6491a2005-07-02 19:24:10 +0000138
139 /* Where is the guest code? */
florian8462d112014-09-24 15:18:09 +0000140 /*IN*/ const UChar* guest_code,
sewardj9e6491a2005-07-02 19:24:10 +0000141
142 /* Where is the actual insn? Note: it's at &guest_code[delta] */
143 /*IN*/ Long delta,
144
145 /* What is the guest IP of the insn? */
146 /*IN*/ Addr64 guest_IP,
147
148 /* Info about the guest architecture */
sewardja5f55da2006-04-30 23:37:32 +0000149 /*IN*/ VexArch guest_arch,
sewardj9e6491a2005-07-02 19:24:10 +0000150 /*IN*/ VexArchInfo* archinfo,
151
sewardjdd40fdf2006-12-24 02:20:24 +0000152 /* ABI info for both guest and host */
153 /*IN*/ VexAbiInfo* abiinfo,
sewardjaca070a2006-10-17 00:28:22 +0000154
sewardj9b769162014-07-24 12:42:03 +0000155 /* The endianness of the host */
156 /*IN*/ VexEndness host_endness,
sewardj442e51a2012-12-06 18:08:04 +0000157
158 /* Should diagnostics be printed for illegal instructions? */
159 /*IN*/ Bool sigill_diag
sewardj9e6491a2005-07-02 19:24:10 +0000160
161 );
162
163
164/* ---------------------------------------------------------------
165 Top-level BB to IR conversion fn.
166 --------------------------------------------------------------- */
167
168/* See detailed comment in bb_to_IR.c. */
169extern
sewardjbc161a42011-06-07 21:28:38 +0000170IRSB* bb_to_IR (
171 /*OUT*/VexGuestExtents* vge,
172 /*OUT*/UInt* n_sc_extents,
sewardjfadbbe22012-04-24 11:49:03 +0000173 /*OUT*/UInt* n_guest_instrs, /* stats only */
sewardjbc161a42011-06-07 21:28:38 +0000174 /*IN*/ void* callback_opaque,
175 /*IN*/ DisOneInstrFn dis_instr_fn,
florian8462d112014-09-24 15:18:09 +0000176 /*IN*/ const UChar* guest_code,
sewardjbc161a42011-06-07 21:28:38 +0000177 /*IN*/ Addr64 guest_IP_bbstart,
178 /*IN*/ Bool (*chase_into_ok)(void*,Addr64),
sewardj9b769162014-07-24 12:42:03 +0000179 /*IN*/ VexEndness host_endness,
sewardj442e51a2012-12-06 18:08:04 +0000180 /*IN*/ Bool sigill_diag,
sewardjbc161a42011-06-07 21:28:38 +0000181 /*IN*/ VexArch arch_guest,
182 /*IN*/ VexArchInfo* archinfo_guest,
183 /*IN*/ VexAbiInfo* abiinfo_both,
184 /*IN*/ IRType guest_word_type,
florian0a5494e2014-09-24 12:00:49 +0000185 /*IN*/ UInt (*needs_self_check)(void*,const VexGuestExtents*),
sewardjbc161a42011-06-07 21:28:38 +0000186 /*IN*/ Bool (*preamble_function)(void*,IRSB*),
sewardj05f5e012014-05-04 10:52:11 +0000187 /*IN*/ Int offB_GUEST_CMSTART,
188 /*IN*/ Int offB_GUEST_CMLEN,
sewardjc6f970f2012-04-02 21:54:49 +0000189 /*IN*/ Int offB_GUEST_IP,
190 /*IN*/ Int szB_GUEST_IP
sewardjbc161a42011-06-07 21:28:38 +0000191 );
sewardj9e6491a2005-07-02 19:24:10 +0000192
193
sewardjcef7d3e2009-07-02 12:21:59 +0000194#endif /* ndef __VEX_GUEST_GENERIC_BB_TO_IR_H */
sewardj9e6491a2005-07-02 19:24:10 +0000195
196/*--------------------------------------------------------------------*/
sewardjcef7d3e2009-07-02 12:21:59 +0000197/*--- end guest_generic_bb_to_IR.h ---*/
sewardj9e6491a2005-07-02 19:24:10 +0000198/*--------------------------------------------------------------------*/