xref: /linux/arch/riscv/include/asm/asm-extable.h (revision 20802d8d477d5771368fdac8d476285adc713af0)
16dd10d91SJisheng Zhang /* SPDX-License-Identifier: GPL-2.0-only */
26dd10d91SJisheng Zhang #ifndef __ASM_ASM_EXTABLE_H
36dd10d91SJisheng Zhang #define __ASM_ASM_EXTABLE_H
46dd10d91SJisheng Zhang 
52bf847dbSJisheng Zhang #define EX_TYPE_NONE			0
62bf847dbSJisheng Zhang #define EX_TYPE_FIXUP			1
72bf847dbSJisheng Zhang #define EX_TYPE_BPF			2
8*20802d8dSJisheng Zhang #define EX_TYPE_UACCESS_ERR_ZERO	3
92bf847dbSJisheng Zhang 
106dd10d91SJisheng Zhang #ifdef __ASSEMBLY__
116dd10d91SJisheng Zhang 
122bf847dbSJisheng Zhang #define __ASM_EXTABLE_RAW(insn, fixup, type, data)	\
136dd10d91SJisheng Zhang 	.pushsection	__ex_table, "a";		\
146dd10d91SJisheng Zhang 	.balign		4;				\
156dd10d91SJisheng Zhang 	.long		((insn) - .);			\
166dd10d91SJisheng Zhang 	.long		((fixup) - .);			\
172bf847dbSJisheng Zhang 	.short		(type);				\
182bf847dbSJisheng Zhang 	.short		(data);				\
196dd10d91SJisheng Zhang 	.popsection;
206dd10d91SJisheng Zhang 
216dd10d91SJisheng Zhang 	.macro		_asm_extable, insn, fixup
222bf847dbSJisheng Zhang 	__ASM_EXTABLE_RAW(\insn, \fixup, EX_TYPE_FIXUP, 0)
236dd10d91SJisheng Zhang 	.endm
246dd10d91SJisheng Zhang 
256dd10d91SJisheng Zhang #else /* __ASSEMBLY__ */
266dd10d91SJisheng Zhang 
27*20802d8dSJisheng Zhang #include <linux/bits.h>
286dd10d91SJisheng Zhang #include <linux/stringify.h>
29*20802d8dSJisheng Zhang #include <asm/gpr-num.h>
306dd10d91SJisheng Zhang 
312bf847dbSJisheng Zhang #define __ASM_EXTABLE_RAW(insn, fixup, type, data)	\
326dd10d91SJisheng Zhang 	".pushsection	__ex_table, \"a\"\n"		\
336dd10d91SJisheng Zhang 	".balign	4\n"				\
346dd10d91SJisheng Zhang 	".long		((" insn ") - .)\n"		\
356dd10d91SJisheng Zhang 	".long		((" fixup ") - .)\n"		\
362bf847dbSJisheng Zhang 	".short		(" type ")\n"			\
372bf847dbSJisheng Zhang 	".short		(" data ")\n"			\
386dd10d91SJisheng Zhang 	".popsection\n"
396dd10d91SJisheng Zhang 
402bf847dbSJisheng Zhang #define _ASM_EXTABLE(insn, fixup)	\
412bf847dbSJisheng Zhang 	__ASM_EXTABLE_RAW(#insn, #fixup, __stringify(EX_TYPE_FIXUP), "0")
426dd10d91SJisheng Zhang 
43*20802d8dSJisheng Zhang #define EX_DATA_REG_ERR_SHIFT	0
44*20802d8dSJisheng Zhang #define EX_DATA_REG_ERR		GENMASK(4, 0)
45*20802d8dSJisheng Zhang #define EX_DATA_REG_ZERO_SHIFT	5
46*20802d8dSJisheng Zhang #define EX_DATA_REG_ZERO	GENMASK(9, 5)
47*20802d8dSJisheng Zhang 
48*20802d8dSJisheng Zhang #define EX_DATA_REG(reg, gpr)						\
49*20802d8dSJisheng Zhang 	"((.L__gpr_num_" #gpr ") << " __stringify(EX_DATA_REG_##reg##_SHIFT) ")"
50*20802d8dSJisheng Zhang 
51*20802d8dSJisheng Zhang #define _ASM_EXTABLE_UACCESS_ERR_ZERO(insn, fixup, err, zero)		\
52*20802d8dSJisheng Zhang 	__DEFINE_ASM_GPR_NUMS						\
53*20802d8dSJisheng Zhang 	__ASM_EXTABLE_RAW(#insn, #fixup, 				\
54*20802d8dSJisheng Zhang 			  __stringify(EX_TYPE_UACCESS_ERR_ZERO),	\
55*20802d8dSJisheng Zhang 			  "("						\
56*20802d8dSJisheng Zhang 			    EX_DATA_REG(ERR, err) " | "			\
57*20802d8dSJisheng Zhang 			    EX_DATA_REG(ZERO, zero)			\
58*20802d8dSJisheng Zhang 			  ")")
59*20802d8dSJisheng Zhang 
60*20802d8dSJisheng Zhang #define _ASM_EXTABLE_UACCESS_ERR(insn, fixup, err)			\
61*20802d8dSJisheng Zhang 	_ASM_EXTABLE_UACCESS_ERR_ZERO(insn, fixup, err, zero)
62*20802d8dSJisheng Zhang 
636dd10d91SJisheng Zhang #endif /* __ASSEMBLY__ */
646dd10d91SJisheng Zhang 
656dd10d91SJisheng Zhang #endif /* __ASM_ASM_EXTABLE_H */
66