xref: /linux/arch/riscv/include/asm/asm-extable.h (revision de658bcf03339561572e5dad3ec8ecedd1256747)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 #ifndef __ASM_ASM_EXTABLE_H
3 #define __ASM_ASM_EXTABLE_H
4 
5 #define EX_TYPE_NONE			0
6 #define EX_TYPE_FIXUP			1
7 #define EX_TYPE_BPF			2
8 #define EX_TYPE_UACCESS_ERR_ZERO	3
9 
10 #ifdef CONFIG_MMU
11 
12 #ifdef __ASSEMBLY__
13 
14 #define __ASM_EXTABLE_RAW(insn, fixup, type, data)	\
15 	.pushsection	__ex_table, "a";		\
16 	.balign		4;				\
17 	.long		((insn) - .);			\
18 	.long		((fixup) - .);			\
19 	.short		(type);				\
20 	.short		(data);				\
21 	.popsection;
22 
23 	.macro		_asm_extable, insn, fixup
24 	__ASM_EXTABLE_RAW(\insn, \fixup, EX_TYPE_FIXUP, 0)
25 	.endm
26 
27 #else /* __ASSEMBLY__ */
28 
29 #include <linux/bits.h>
30 #include <linux/stringify.h>
31 #include <asm/gpr-num.h>
32 
33 #define __ASM_EXTABLE_RAW(insn, fixup, type, data)	\
34 	".pushsection	__ex_table, \"a\"\n"		\
35 	".balign	4\n"				\
36 	".long		((" insn ") - .)\n"		\
37 	".long		((" fixup ") - .)\n"		\
38 	".short		(" type ")\n"			\
39 	".short		(" data ")\n"			\
40 	".popsection\n"
41 
42 #define _ASM_EXTABLE(insn, fixup)	\
43 	__ASM_EXTABLE_RAW(#insn, #fixup, __stringify(EX_TYPE_FIXUP), "0")
44 
45 #define EX_DATA_REG_ERR_SHIFT	0
46 #define EX_DATA_REG_ERR		GENMASK(4, 0)
47 #define EX_DATA_REG_ZERO_SHIFT	5
48 #define EX_DATA_REG_ZERO	GENMASK(9, 5)
49 
50 #define EX_DATA_REG(reg, gpr)						\
51 	"((.L__gpr_num_" #gpr ") << " __stringify(EX_DATA_REG_##reg##_SHIFT) ")"
52 
53 #define _ASM_EXTABLE_UACCESS_ERR_ZERO(insn, fixup, err, zero)		\
54 	__DEFINE_ASM_GPR_NUMS						\
55 	__ASM_EXTABLE_RAW(#insn, #fixup, 				\
56 			  __stringify(EX_TYPE_UACCESS_ERR_ZERO),	\
57 			  "("						\
58 			    EX_DATA_REG(ERR, err) " | "			\
59 			    EX_DATA_REG(ZERO, zero)			\
60 			  ")")
61 
62 #define _ASM_EXTABLE_UACCESS_ERR(insn, fixup, err)			\
63 	_ASM_EXTABLE_UACCESS_ERR_ZERO(insn, fixup, err, zero)
64 
65 #endif /* __ASSEMBLY__ */
66 
67 #else /* CONFIG_MMU */
68 	#define _ASM_EXTABLE_UACCESS_ERR(insn, fixup, err)
69 #endif /* CONFIG_MMU */
70 
71 #endif /* __ASM_ASM_EXTABLE_H */
72