xref: /OK3568_Linux_fs/kernel/arch/arm/probes/decode.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-only */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * arch/arm/probes/decode.h
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Copyright (C) 2011 Jon Medhurst <tixy@yxit.co.uk>.
6*4882a593Smuzhiyun  *
7*4882a593Smuzhiyun  * Some contents moved here from arch/arm/include/asm/kprobes.h which is
8*4882a593Smuzhiyun  * Copyright (C) 2006, 2007 Motorola Inc.
9*4882a593Smuzhiyun  */
10*4882a593Smuzhiyun 
11*4882a593Smuzhiyun #ifndef _ARM_KERNEL_PROBES_H
12*4882a593Smuzhiyun #define  _ARM_KERNEL_PROBES_H
13*4882a593Smuzhiyun 
14*4882a593Smuzhiyun #include <linux/types.h>
15*4882a593Smuzhiyun #include <linux/stddef.h>
16*4882a593Smuzhiyun #include <asm/probes.h>
17*4882a593Smuzhiyun #include <asm/ptrace.h>
18*4882a593Smuzhiyun #include <asm/kprobes.h>
19*4882a593Smuzhiyun 
20*4882a593Smuzhiyun void __init arm_probes_decode_init(void);
21*4882a593Smuzhiyun 
22*4882a593Smuzhiyun extern probes_check_cc * const probes_condition_checks[16];
23*4882a593Smuzhiyun 
24*4882a593Smuzhiyun #if __LINUX_ARM_ARCH__ >= 7
25*4882a593Smuzhiyun 
26*4882a593Smuzhiyun /* str_pc_offset is architecturally defined from ARMv7 onwards */
27*4882a593Smuzhiyun #define str_pc_offset 8
28*4882a593Smuzhiyun #define find_str_pc_offset()
29*4882a593Smuzhiyun 
30*4882a593Smuzhiyun #else /* __LINUX_ARM_ARCH__ < 7 */
31*4882a593Smuzhiyun 
32*4882a593Smuzhiyun /* We need a run-time check to determine str_pc_offset */
33*4882a593Smuzhiyun extern int str_pc_offset;
34*4882a593Smuzhiyun void __init find_str_pc_offset(void);
35*4882a593Smuzhiyun 
36*4882a593Smuzhiyun #endif
37*4882a593Smuzhiyun 
38*4882a593Smuzhiyun 
bx_write_pc(long pcv,struct pt_regs * regs)39*4882a593Smuzhiyun static inline void __kprobes bx_write_pc(long pcv, struct pt_regs *regs)
40*4882a593Smuzhiyun {
41*4882a593Smuzhiyun 	long cpsr = regs->ARM_cpsr;
42*4882a593Smuzhiyun 	if (pcv & 0x1) {
43*4882a593Smuzhiyun 		cpsr |= PSR_T_BIT;
44*4882a593Smuzhiyun 		pcv &= ~0x1;
45*4882a593Smuzhiyun 	} else {
46*4882a593Smuzhiyun 		cpsr &= ~PSR_T_BIT;
47*4882a593Smuzhiyun 		pcv &= ~0x2;	/* Avoid UNPREDICTABLE address allignment */
48*4882a593Smuzhiyun 	}
49*4882a593Smuzhiyun 	regs->ARM_cpsr = cpsr;
50*4882a593Smuzhiyun 	regs->ARM_pc = pcv;
51*4882a593Smuzhiyun }
52*4882a593Smuzhiyun 
53*4882a593Smuzhiyun 
54*4882a593Smuzhiyun #if __LINUX_ARM_ARCH__ >= 6
55*4882a593Smuzhiyun 
56*4882a593Smuzhiyun /* Kernels built for >= ARMv6 should never run on <= ARMv5 hardware, so... */
57*4882a593Smuzhiyun #define load_write_pc_interworks true
58*4882a593Smuzhiyun #define test_load_write_pc_interworking()
59*4882a593Smuzhiyun 
60*4882a593Smuzhiyun #else /* __LINUX_ARM_ARCH__ < 6 */
61*4882a593Smuzhiyun 
62*4882a593Smuzhiyun /* We need run-time testing to determine if load_write_pc() should interwork. */
63*4882a593Smuzhiyun extern bool load_write_pc_interworks;
64*4882a593Smuzhiyun void __init test_load_write_pc_interworking(void);
65*4882a593Smuzhiyun 
66*4882a593Smuzhiyun #endif
67*4882a593Smuzhiyun 
load_write_pc(long pcv,struct pt_regs * regs)68*4882a593Smuzhiyun static inline void __kprobes load_write_pc(long pcv, struct pt_regs *regs)
69*4882a593Smuzhiyun {
70*4882a593Smuzhiyun 	if (load_write_pc_interworks)
71*4882a593Smuzhiyun 		bx_write_pc(pcv, regs);
72*4882a593Smuzhiyun 	else
73*4882a593Smuzhiyun 		regs->ARM_pc = pcv;
74*4882a593Smuzhiyun }
75*4882a593Smuzhiyun 
76*4882a593Smuzhiyun 
77*4882a593Smuzhiyun #if __LINUX_ARM_ARCH__ >= 7
78*4882a593Smuzhiyun 
79*4882a593Smuzhiyun #define alu_write_pc_interworks true
80*4882a593Smuzhiyun #define test_alu_write_pc_interworking()
81*4882a593Smuzhiyun 
82*4882a593Smuzhiyun #elif __LINUX_ARM_ARCH__ <= 5
83*4882a593Smuzhiyun 
84*4882a593Smuzhiyun /* Kernels built for <= ARMv5 should never run on >= ARMv6 hardware, so... */
85*4882a593Smuzhiyun #define alu_write_pc_interworks false
86*4882a593Smuzhiyun #define test_alu_write_pc_interworking()
87*4882a593Smuzhiyun 
88*4882a593Smuzhiyun #else /* __LINUX_ARM_ARCH__ == 6 */
89*4882a593Smuzhiyun 
90*4882a593Smuzhiyun /* We could be an ARMv6 binary on ARMv7 hardware so we need a run-time check. */
91*4882a593Smuzhiyun extern bool alu_write_pc_interworks;
92*4882a593Smuzhiyun void __init test_alu_write_pc_interworking(void);
93*4882a593Smuzhiyun 
94*4882a593Smuzhiyun #endif /* __LINUX_ARM_ARCH__ == 6 */
95*4882a593Smuzhiyun 
alu_write_pc(long pcv,struct pt_regs * regs)96*4882a593Smuzhiyun static inline void __kprobes alu_write_pc(long pcv, struct pt_regs *regs)
97*4882a593Smuzhiyun {
98*4882a593Smuzhiyun 	if (alu_write_pc_interworks)
99*4882a593Smuzhiyun 		bx_write_pc(pcv, regs);
100*4882a593Smuzhiyun 	else
101*4882a593Smuzhiyun 		regs->ARM_pc = pcv;
102*4882a593Smuzhiyun }
103*4882a593Smuzhiyun 
104*4882a593Smuzhiyun 
105*4882a593Smuzhiyun /*
106*4882a593Smuzhiyun  * Test if load/store instructions writeback the address register.
107*4882a593Smuzhiyun  * if P (bit 24) == 0 or W (bit 21) == 1
108*4882a593Smuzhiyun  */
109*4882a593Smuzhiyun #define is_writeback(insn) ((insn ^ 0x01000000) & 0x01200000)
110*4882a593Smuzhiyun 
111*4882a593Smuzhiyun /*
112*4882a593Smuzhiyun  * The following definitions and macros are used to build instruction
113*4882a593Smuzhiyun  * decoding tables for use by probes_decode_insn.
114*4882a593Smuzhiyun  *
115*4882a593Smuzhiyun  * These tables are a concatenation of entries each of which consist of one of
116*4882a593Smuzhiyun  * the decode_* structs. All of the fields in every type of decode structure
117*4882a593Smuzhiyun  * are of the union type decode_item, therefore the entire decode table can be
118*4882a593Smuzhiyun  * viewed as an array of these and declared like:
119*4882a593Smuzhiyun  *
120*4882a593Smuzhiyun  *	static const union decode_item table_name[] = {};
121*4882a593Smuzhiyun  *
122*4882a593Smuzhiyun  * In order to construct each entry in the table, macros are used to
123*4882a593Smuzhiyun  * initialise a number of sequential decode_item values in a layout which
124*4882a593Smuzhiyun  * matches the relevant struct. E.g. DECODE_SIMULATE initialise a struct
125*4882a593Smuzhiyun  * decode_simulate by initialising four decode_item objects like this...
126*4882a593Smuzhiyun  *
127*4882a593Smuzhiyun  *	{.bits = _type},
128*4882a593Smuzhiyun  *	{.bits = _mask},
129*4882a593Smuzhiyun  *	{.bits = _value},
130*4882a593Smuzhiyun  *	{.action = _handler},
131*4882a593Smuzhiyun  *
132*4882a593Smuzhiyun  * Initialising a specified member of the union means that the compiler
133*4882a593Smuzhiyun  * will produce a warning if the argument is of an incorrect type.
134*4882a593Smuzhiyun  *
135*4882a593Smuzhiyun  * Below is a list of each of the macros used to initialise entries and a
136*4882a593Smuzhiyun  * description of the action performed when that entry is matched to an
137*4882a593Smuzhiyun  * instruction. A match is found when (instruction & mask) == value.
138*4882a593Smuzhiyun  *
139*4882a593Smuzhiyun  * DECODE_TABLE(mask, value, table)
140*4882a593Smuzhiyun  *	Instruction decoding jumps to parsing the new sub-table 'table'.
141*4882a593Smuzhiyun  *
142*4882a593Smuzhiyun  * DECODE_CUSTOM(mask, value, decoder)
143*4882a593Smuzhiyun  *	The value of 'decoder' is used as an index into the array of
144*4882a593Smuzhiyun  *	action functions, and the retrieved decoder function is invoked
145*4882a593Smuzhiyun  *	to complete decoding of the instruction.
146*4882a593Smuzhiyun  *
147*4882a593Smuzhiyun  * DECODE_SIMULATE(mask, value, handler)
148*4882a593Smuzhiyun  *	The probes instruction handler is set to the value found by
149*4882a593Smuzhiyun  *	indexing into the action array using the value of 'handler'. This
150*4882a593Smuzhiyun  *	will be used to simulate the instruction when the probe is hit.
151*4882a593Smuzhiyun  *	Decoding returns with INSN_GOOD_NO_SLOT.
152*4882a593Smuzhiyun  *
153*4882a593Smuzhiyun  * DECODE_EMULATE(mask, value, handler)
154*4882a593Smuzhiyun  *	The probes instruction handler is set to the value found by
155*4882a593Smuzhiyun  *	indexing into the action array using the value of 'handler'. This
156*4882a593Smuzhiyun  *	will be used to emulate the instruction when the probe is hit. The
157*4882a593Smuzhiyun  *	modified instruction (see below) is placed in the probes instruction
158*4882a593Smuzhiyun  *	slot so it may be called by the emulation code. Decoding returns
159*4882a593Smuzhiyun  *	with INSN_GOOD.
160*4882a593Smuzhiyun  *
161*4882a593Smuzhiyun  * DECODE_REJECT(mask, value)
162*4882a593Smuzhiyun  *	Instruction decoding fails with INSN_REJECTED
163*4882a593Smuzhiyun  *
164*4882a593Smuzhiyun  * DECODE_OR(mask, value)
165*4882a593Smuzhiyun  *	This allows the mask/value test of multiple table entries to be
166*4882a593Smuzhiyun  *	logically ORed. Once an 'or' entry is matched the decoding action to
167*4882a593Smuzhiyun  *	be performed is that of the next entry which isn't an 'or'. E.g.
168*4882a593Smuzhiyun  *
169*4882a593Smuzhiyun  *		DECODE_OR	(mask1, value1)
170*4882a593Smuzhiyun  *		DECODE_OR	(mask2, value2)
171*4882a593Smuzhiyun  *		DECODE_SIMULATE	(mask3, value3, simulation_handler)
172*4882a593Smuzhiyun  *
173*4882a593Smuzhiyun  *	This means that if any of the three mask/value pairs match the
174*4882a593Smuzhiyun  *	instruction being decoded, then 'simulation_handler' will be used
175*4882a593Smuzhiyun  *	for it.
176*4882a593Smuzhiyun  *
177*4882a593Smuzhiyun  * Both the SIMULATE and EMULATE macros have a second form which take an
178*4882a593Smuzhiyun  * additional 'regs' argument.
179*4882a593Smuzhiyun  *
180*4882a593Smuzhiyun  *	DECODE_SIMULATEX(mask, value, handler, regs)
181*4882a593Smuzhiyun  *	DECODE_EMULATEX	(mask, value, handler, regs)
182*4882a593Smuzhiyun  *
183*4882a593Smuzhiyun  * These are used to specify what kind of CPU register is encoded in each of the
184*4882a593Smuzhiyun  * least significant 5 nibbles of the instruction being decoded. The regs value
185*4882a593Smuzhiyun  * is specified using the REGS macro, this takes any of the REG_TYPE_* values
186*4882a593Smuzhiyun  * from enum decode_reg_type as arguments; only the '*' part of the name is
187*4882a593Smuzhiyun  * given. E.g.
188*4882a593Smuzhiyun  *
189*4882a593Smuzhiyun  *	REGS(0, ANY, NOPC, 0, ANY)
190*4882a593Smuzhiyun  *
191*4882a593Smuzhiyun  * This indicates an instruction is encoded like:
192*4882a593Smuzhiyun  *
193*4882a593Smuzhiyun  *	bits 19..16	ignore
194*4882a593Smuzhiyun  *	bits 15..12	any register allowed here
195*4882a593Smuzhiyun  *	bits 11.. 8	any register except PC allowed here
196*4882a593Smuzhiyun  *	bits  7.. 4	ignore
197*4882a593Smuzhiyun  *	bits  3.. 0	any register allowed here
198*4882a593Smuzhiyun  *
199*4882a593Smuzhiyun  * This register specification is checked after a decode table entry is found to
200*4882a593Smuzhiyun  * match an instruction (through the mask/value test). Any invalid register then
201*4882a593Smuzhiyun  * found in the instruction will cause decoding to fail with INSN_REJECTED. In
202*4882a593Smuzhiyun  * the above example this would happen if bits 11..8 of the instruction were
203*4882a593Smuzhiyun  * 1111, indicating R15 or PC.
204*4882a593Smuzhiyun  *
205*4882a593Smuzhiyun  * As well as checking for legal combinations of registers, this data is also
206*4882a593Smuzhiyun  * used to modify the registers encoded in the instructions so that an
207*4882a593Smuzhiyun  * emulation routines can use it. (See decode_regs() and INSN_NEW_BITS.)
208*4882a593Smuzhiyun  *
209*4882a593Smuzhiyun  * Here is a real example which matches ARM instructions of the form
210*4882a593Smuzhiyun  * "AND <Rd>,<Rn>,<Rm>,<shift> <Rs>"
211*4882a593Smuzhiyun  *
212*4882a593Smuzhiyun  *	DECODE_EMULATEX	(0x0e000090, 0x00000010, PROBES_DATA_PROCESSING_REG,
213*4882a593Smuzhiyun  *						 REGS(ANY, ANY, NOPC, 0, ANY)),
214*4882a593Smuzhiyun  *						      ^    ^    ^        ^
215*4882a593Smuzhiyun  *						      Rn   Rd   Rs       Rm
216*4882a593Smuzhiyun  *
217*4882a593Smuzhiyun  * Decoding the instruction "AND R4, R5, R6, ASL R15" will be rejected because
218*4882a593Smuzhiyun  * Rs == R15
219*4882a593Smuzhiyun  *
220*4882a593Smuzhiyun  * Decoding the instruction "AND R4, R5, R6, ASL R7" will be accepted and the
221*4882a593Smuzhiyun  * instruction will be modified to "AND R0, R2, R3, ASL R1" and then placed into
222*4882a593Smuzhiyun  * the kprobes instruction slot. This can then be called later by the handler
223*4882a593Smuzhiyun  * function emulate_rd12rn16rm0rs8_rwflags (a pointer to which is retrieved from
224*4882a593Smuzhiyun  * the indicated slot in the action array), in order to simulate the instruction.
225*4882a593Smuzhiyun  */
226*4882a593Smuzhiyun 
227*4882a593Smuzhiyun enum decode_type {
228*4882a593Smuzhiyun 	DECODE_TYPE_END,
229*4882a593Smuzhiyun 	DECODE_TYPE_TABLE,
230*4882a593Smuzhiyun 	DECODE_TYPE_CUSTOM,
231*4882a593Smuzhiyun 	DECODE_TYPE_SIMULATE,
232*4882a593Smuzhiyun 	DECODE_TYPE_EMULATE,
233*4882a593Smuzhiyun 	DECODE_TYPE_OR,
234*4882a593Smuzhiyun 	DECODE_TYPE_REJECT,
235*4882a593Smuzhiyun 	NUM_DECODE_TYPES /* Must be last enum */
236*4882a593Smuzhiyun };
237*4882a593Smuzhiyun 
238*4882a593Smuzhiyun #define DECODE_TYPE_BITS	4
239*4882a593Smuzhiyun #define DECODE_TYPE_MASK	((1 << DECODE_TYPE_BITS) - 1)
240*4882a593Smuzhiyun 
241*4882a593Smuzhiyun enum decode_reg_type {
242*4882a593Smuzhiyun 	REG_TYPE_NONE = 0, /* Not a register, ignore */
243*4882a593Smuzhiyun 	REG_TYPE_ANY,	   /* Any register allowed */
244*4882a593Smuzhiyun 	REG_TYPE_SAMEAS16, /* Register should be same as that at bits 19..16 */
245*4882a593Smuzhiyun 	REG_TYPE_SP,	   /* Register must be SP */
246*4882a593Smuzhiyun 	REG_TYPE_PC,	   /* Register must be PC */
247*4882a593Smuzhiyun 	REG_TYPE_NOSP,	   /* Register must not be SP */
248*4882a593Smuzhiyun 	REG_TYPE_NOSPPC,   /* Register must not be SP or PC */
249*4882a593Smuzhiyun 	REG_TYPE_NOPC,	   /* Register must not be PC */
250*4882a593Smuzhiyun 	REG_TYPE_NOPCWB,   /* No PC if load/store write-back flag also set */
251*4882a593Smuzhiyun 
252*4882a593Smuzhiyun 	/* The following types are used when the encoding for PC indicates
253*4882a593Smuzhiyun 	 * another instruction form. This distiction only matters for test
254*4882a593Smuzhiyun 	 * case coverage checks.
255*4882a593Smuzhiyun 	 */
256*4882a593Smuzhiyun 	REG_TYPE_NOPCX,	   /* Register must not be PC */
257*4882a593Smuzhiyun 	REG_TYPE_NOSPPCX,  /* Register must not be SP or PC */
258*4882a593Smuzhiyun 
259*4882a593Smuzhiyun 	/* Alias to allow '0' arg to be used in REGS macro. */
260*4882a593Smuzhiyun 	REG_TYPE_0 = REG_TYPE_NONE
261*4882a593Smuzhiyun };
262*4882a593Smuzhiyun 
263*4882a593Smuzhiyun #define REGS(r16, r12, r8, r4, r0)	\
264*4882a593Smuzhiyun 	(((REG_TYPE_##r16) << 16) +	\
265*4882a593Smuzhiyun 	((REG_TYPE_##r12) << 12) +	\
266*4882a593Smuzhiyun 	((REG_TYPE_##r8) << 8) +	\
267*4882a593Smuzhiyun 	((REG_TYPE_##r4) << 4) +	\
268*4882a593Smuzhiyun 	(REG_TYPE_##r0))
269*4882a593Smuzhiyun 
270*4882a593Smuzhiyun union decode_item {
271*4882a593Smuzhiyun 	u32			bits;
272*4882a593Smuzhiyun 	const union decode_item	*table;
273*4882a593Smuzhiyun 	int			action;
274*4882a593Smuzhiyun };
275*4882a593Smuzhiyun 
276*4882a593Smuzhiyun struct decode_header;
277*4882a593Smuzhiyun typedef enum probes_insn (probes_custom_decode_t)(probes_opcode_t,
278*4882a593Smuzhiyun 						  struct arch_probes_insn *,
279*4882a593Smuzhiyun 						  const struct decode_header *);
280*4882a593Smuzhiyun 
281*4882a593Smuzhiyun union decode_action {
282*4882a593Smuzhiyun 	probes_insn_handler_t	*handler;
283*4882a593Smuzhiyun 	probes_custom_decode_t	*decoder;
284*4882a593Smuzhiyun };
285*4882a593Smuzhiyun 
286*4882a593Smuzhiyun typedef enum probes_insn (probes_check_t)(probes_opcode_t,
287*4882a593Smuzhiyun 					   struct arch_probes_insn *,
288*4882a593Smuzhiyun 					   const struct decode_header *);
289*4882a593Smuzhiyun 
290*4882a593Smuzhiyun struct decode_checker {
291*4882a593Smuzhiyun 	probes_check_t	*checker;
292*4882a593Smuzhiyun };
293*4882a593Smuzhiyun 
294*4882a593Smuzhiyun #define DECODE_END			\
295*4882a593Smuzhiyun 	{.bits = DECODE_TYPE_END}
296*4882a593Smuzhiyun 
297*4882a593Smuzhiyun 
298*4882a593Smuzhiyun struct decode_header {
299*4882a593Smuzhiyun 	union decode_item	type_regs;
300*4882a593Smuzhiyun 	union decode_item	mask;
301*4882a593Smuzhiyun 	union decode_item	value;
302*4882a593Smuzhiyun };
303*4882a593Smuzhiyun 
304*4882a593Smuzhiyun #define DECODE_HEADER(_type, _mask, _value, _regs)		\
305*4882a593Smuzhiyun 	{.bits = (_type) | ((_regs) << DECODE_TYPE_BITS)},	\
306*4882a593Smuzhiyun 	{.bits = (_mask)},					\
307*4882a593Smuzhiyun 	{.bits = (_value)}
308*4882a593Smuzhiyun 
309*4882a593Smuzhiyun 
310*4882a593Smuzhiyun struct decode_table {
311*4882a593Smuzhiyun 	struct decode_header	header;
312*4882a593Smuzhiyun 	union decode_item	table;
313*4882a593Smuzhiyun };
314*4882a593Smuzhiyun 
315*4882a593Smuzhiyun #define DECODE_TABLE(_mask, _value, _table)			\
316*4882a593Smuzhiyun 	DECODE_HEADER(DECODE_TYPE_TABLE, _mask, _value, 0),	\
317*4882a593Smuzhiyun 	{.table = (_table)}
318*4882a593Smuzhiyun 
319*4882a593Smuzhiyun 
320*4882a593Smuzhiyun struct decode_custom {
321*4882a593Smuzhiyun 	struct decode_header	header;
322*4882a593Smuzhiyun 	union decode_item	decoder;
323*4882a593Smuzhiyun };
324*4882a593Smuzhiyun 
325*4882a593Smuzhiyun #define DECODE_CUSTOM(_mask, _value, _decoder)			\
326*4882a593Smuzhiyun 	DECODE_HEADER(DECODE_TYPE_CUSTOM, _mask, _value, 0),	\
327*4882a593Smuzhiyun 	{.action = (_decoder)}
328*4882a593Smuzhiyun 
329*4882a593Smuzhiyun 
330*4882a593Smuzhiyun struct decode_simulate {
331*4882a593Smuzhiyun 	struct decode_header	header;
332*4882a593Smuzhiyun 	union decode_item	handler;
333*4882a593Smuzhiyun };
334*4882a593Smuzhiyun 
335*4882a593Smuzhiyun #define DECODE_SIMULATEX(_mask, _value, _handler, _regs)		\
336*4882a593Smuzhiyun 	DECODE_HEADER(DECODE_TYPE_SIMULATE, _mask, _value, _regs),	\
337*4882a593Smuzhiyun 	{.action = (_handler)}
338*4882a593Smuzhiyun 
339*4882a593Smuzhiyun #define DECODE_SIMULATE(_mask, _value, _handler)	\
340*4882a593Smuzhiyun 	DECODE_SIMULATEX(_mask, _value, _handler, 0)
341*4882a593Smuzhiyun 
342*4882a593Smuzhiyun 
343*4882a593Smuzhiyun struct decode_emulate {
344*4882a593Smuzhiyun 	struct decode_header	header;
345*4882a593Smuzhiyun 	union decode_item	handler;
346*4882a593Smuzhiyun };
347*4882a593Smuzhiyun 
348*4882a593Smuzhiyun #define DECODE_EMULATEX(_mask, _value, _handler, _regs)			\
349*4882a593Smuzhiyun 	DECODE_HEADER(DECODE_TYPE_EMULATE, _mask, _value, _regs),	\
350*4882a593Smuzhiyun 	{.action = (_handler)}
351*4882a593Smuzhiyun 
352*4882a593Smuzhiyun #define DECODE_EMULATE(_mask, _value, _handler)		\
353*4882a593Smuzhiyun 	DECODE_EMULATEX(_mask, _value, _handler, 0)
354*4882a593Smuzhiyun 
355*4882a593Smuzhiyun 
356*4882a593Smuzhiyun struct decode_or {
357*4882a593Smuzhiyun 	struct decode_header	header;
358*4882a593Smuzhiyun };
359*4882a593Smuzhiyun 
360*4882a593Smuzhiyun #define DECODE_OR(_mask, _value)				\
361*4882a593Smuzhiyun 	DECODE_HEADER(DECODE_TYPE_OR, _mask, _value, 0)
362*4882a593Smuzhiyun 
363*4882a593Smuzhiyun enum probes_insn {
364*4882a593Smuzhiyun 	INSN_REJECTED,
365*4882a593Smuzhiyun 	INSN_GOOD,
366*4882a593Smuzhiyun 	INSN_GOOD_NO_SLOT
367*4882a593Smuzhiyun };
368*4882a593Smuzhiyun 
369*4882a593Smuzhiyun struct decode_reject {
370*4882a593Smuzhiyun 	struct decode_header	header;
371*4882a593Smuzhiyun };
372*4882a593Smuzhiyun 
373*4882a593Smuzhiyun #define DECODE_REJECT(_mask, _value)				\
374*4882a593Smuzhiyun 	DECODE_HEADER(DECODE_TYPE_REJECT, _mask, _value, 0)
375*4882a593Smuzhiyun 
376*4882a593Smuzhiyun probes_insn_handler_t probes_simulate_nop;
377*4882a593Smuzhiyun probes_insn_handler_t probes_emulate_none;
378*4882a593Smuzhiyun 
379*4882a593Smuzhiyun int __kprobes
380*4882a593Smuzhiyun probes_decode_insn(probes_opcode_t insn, struct arch_probes_insn *asi,
381*4882a593Smuzhiyun 		const union decode_item *table, bool thumb, bool emulate,
382*4882a593Smuzhiyun 		const union decode_action *actions,
383*4882a593Smuzhiyun 		const struct decode_checker **checkers);
384*4882a593Smuzhiyun 
385*4882a593Smuzhiyun #endif
386