asm-extable.h 1.7 KB
Newer Older
1 2 3 4
/* SPDX-License-Identifier: GPL-2.0-only */
#ifndef __ASM_ASM_EXTABLE_H
#define __ASM_ASM_EXTABLE_H

5 6
#define EX_TYPE_NONE			0
#define EX_TYPE_FIXUP			1
7
#define EX_TYPE_UACCESS_ERR_ZERO	2
8

9 10
#ifdef __ASSEMBLY__

11
#define __ASM_EXTABLE_RAW(insn, fixup, type, data)	\
12
	.pushsection	__ex_table, "a";		\
13 14 15
	.balign		4;				\
	.long		((insn) - .);			\
	.long		((fixup) - .);			\
16 17
	.short		(type);				\
	.short		(data);				\
18 19 20
	.popsection;

	.macro		_asm_extable, insn, fixup
21
	__ASM_EXTABLE_RAW(\insn, \fixup, EX_TYPE_FIXUP, 0)
22 23 24 25 26 27
	.endm

#else /* __ASSEMBLY__ */

#include <linux/bits.h>
#include <linux/stringify.h>
28
#include <asm/gpr-num.h>
29

30
#define __ASM_EXTABLE_RAW(insn, fixup, type, data)	\
31
	".pushsection	__ex_table, \"a\"\n"		\
32 33 34
	".balign	4\n"				\
	".long		((" insn ") - .)\n"		\
	".long		((" fixup ") - .)\n"		\
35 36
	".short		(" type ")\n"			\
	".short		(" data ")\n"			\
37 38 39
	".popsection\n"

#define _ASM_EXTABLE(insn, fixup)	\
40
	__ASM_EXTABLE_RAW(#insn, #fixup, __stringify(EX_TYPE_FIXUP), "0")
41

42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
#define EX_DATA_REG_ERR_SHIFT	0
#define EX_DATA_REG_ERR		GENMASK(4, 0)
#define EX_DATA_REG_ZERO_SHIFT	5
#define EX_DATA_REG_ZERO	GENMASK(9, 5)

#define EX_DATA_REG(reg, gpr)						\
	"((.L__gpr_num_" #gpr ") << " __stringify(EX_DATA_REG_##reg##_SHIFT) ")"

#define _ASM_EXTABLE_UACCESS_ERR_ZERO(insn, fixup, err, zero)		\
	__DEFINE_ASM_GPR_NUMS						\
	__ASM_EXTABLE_RAW(#insn, #fixup, 				\
			  __stringify(EX_TYPE_UACCESS_ERR_ZERO),	\
			  "("						\
			    EX_DATA_REG(ERR, err) " | "			\
			    EX_DATA_REG(ZERO, zero)			\
			  ")")

#define _ASM_EXTABLE_UACCESS_ERR(insn, fixup, err)			\
	_ASM_EXTABLE_UACCESS_ERR_ZERO(insn, fixup, err, zero)

62 63 64
#endif /* __ASSEMBLY__ */

#endif /* __ASM_ASM_EXTABLE_H */