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 __ASSEMBLY__ 11 12 #define __ASM_EXTABLE_RAW(insn, fixup, type, data) \ 13 .pushsection __ex_table, "a"; \ 14 .align 2; \ 15 .long ((insn) - .); \ 16 .long ((fixup) - .); \ 17 .short (type); \ 18 .short (data); \ 19 .popsection; 20 21 /* 22 * Create an exception table entry for `insn`, which will branch to `fixup` 23 * when an unhandled fault is taken. 24 */ 25 .macro _asm_extable, insn, fixup 26 __ASM_EXTABLE_RAW(\insn, \fixup, EX_TYPE_FIXUP, 0) 27 .endm 28 29 /* 30 * Create an exception table entry for `insn` if `fixup` is provided. Otherwise 31 * do nothing. 32 */ 33 .macro _cond_extable, insn, fixup 34 .ifnc \fixup, 35 _asm_extable \insn, \fixup 36 .endif 37 .endm 38 39 #else /* __ASSEMBLY__ */ 40 41 #include <linux/bits.h> 42 #include <linux/stringify.h> 43 44 #include <asm/gpr-num.h> 45 46 #define __ASM_EXTABLE_RAW(insn, fixup, type, data) \ 47 ".pushsection __ex_table, \"a\"\n" \ 48 ".align 2\n" \ 49 ".long ((" insn ") - .)\n" \ 50 ".long ((" fixup ") - .)\n" \ 51 ".short (" type ")\n" \ 52 ".short (" data ")\n" \ 53 ".popsection\n" 54 55 #define _ASM_EXTABLE(insn, fixup) \ 56 __ASM_EXTABLE_RAW(#insn, #fixup, __stringify(EX_TYPE_FIXUP), "0") 57 58 #define EX_DATA_REG_ERR_SHIFT 0 59 #define EX_DATA_REG_ERR GENMASK(4, 0) 60 #define EX_DATA_REG_ZERO_SHIFT 5 61 #define EX_DATA_REG_ZERO GENMASK(9, 5) 62 63 #define EX_DATA_REG(reg, gpr) \ 64 "((.L__gpr_num_" #gpr ") << " __stringify(EX_DATA_REG_##reg##_SHIFT) ")" 65 66 #define _ASM_EXTABLE_UACCESS_ERR_ZERO(insn, fixup, err, zero) \ 67 __DEFINE_ASM_GPR_NUMS \ 68 __ASM_EXTABLE_RAW(#insn, #fixup, \ 69 __stringify(EX_TYPE_UACCESS_ERR_ZERO), \ 70 "(" \ 71 EX_DATA_REG(ERR, err) " | " \ 72 EX_DATA_REG(ZERO, zero) \ 73 ")") 74 75 #define _ASM_EXTABLE_UACCESS_ERR(insn, fixup, err) \ 76 _ASM_EXTABLE_UACCESS_ERR_ZERO(insn, fixup, err, wzr) 77 78 #endif /* __ASSEMBLY__ */ 79 80 #endif /* __ASM_ASM_EXTABLE_H */ 81