1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __ASM_EXTABLE_H
3 #define __ASM_EXTABLE_H
4 
5 #include <linux/stringify.h>
6 #include <linux/bits.h>
7 #include <asm/asm-const.h>
8 
9 #define EX_TYPE_NONE		0
10 #define EX_TYPE_FIXUP		1
11 #define EX_TYPE_BPF		2
12 #define EX_TYPE_UA_STORE	3
13 #define EX_TYPE_UA_LOAD_MEM	4
14 #define EX_TYPE_UA_LOAD_REG	5
15 
16 #define EX_DATA_REG_ERR_SHIFT	0
17 #define EX_DATA_REG_ERR		GENMASK(3, 0)
18 
19 #define EX_DATA_REG_ADDR_SHIFT	4
20 #define EX_DATA_REG_ADDR	GENMASK(7, 4)
21 
22 #define EX_DATA_LEN_SHIFT	8
23 #define EX_DATA_LEN		GENMASK(11, 8)
24 
25 #define __EX_TABLE(_section, _fault, _target, _type)			\
26 	stringify_in_c(.section	_section,"a";)				\
27 	stringify_in_c(.align	4;)					\
28 	stringify_in_c(.long	(_fault) - .;)				\
29 	stringify_in_c(.long	(_target) - .;)				\
30 	stringify_in_c(.short	(_type);)				\
31 	stringify_in_c(.short	0;)					\
32 	stringify_in_c(.previous)
33 
34 #define __EX_TABLE_UA(_section, _fault, _target, _type, _regerr, _regaddr, _len)\
35 	stringify_in_c(.section _section,"a";)					\
36 	stringify_in_c(.align	4;)						\
37 	stringify_in_c(.long	(_fault) - .;)					\
38 	stringify_in_c(.long	(_target) - .;)					\
39 	stringify_in_c(.short	(_type);)					\
40 	stringify_in_c(.macro	extable_reg regerr, regaddr;)			\
41 	stringify_in_c(.set	.Lfound, 0;)					\
42 	stringify_in_c(.set	.Lcurr, 0;)					\
43 	stringify_in_c(.irp	rs,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15;)	\
44 	stringify_in_c(		.ifc	"\regerr", "%%r\rs";)			\
45 	stringify_in_c(			.set	.Lfound, 1;)			\
46 	stringify_in_c(			.set	.Lregerr, .Lcurr;)		\
47 	stringify_in_c(		.endif;)					\
48 	stringify_in_c(		.set	.Lcurr, .Lcurr+1;)			\
49 	stringify_in_c(.endr;)							\
50 	stringify_in_c(.ifne	(.Lfound != 1);)				\
51 	stringify_in_c(		.error	"extable_reg: bad register argument1";)	\
52 	stringify_in_c(.endif;)							\
53 	stringify_in_c(.set	.Lfound, 0;)					\
54 	stringify_in_c(.set	.Lcurr, 0;)					\
55 	stringify_in_c(.irp	rs,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15;)	\
56 	stringify_in_c(		.ifc	"\regaddr", "%%r\rs";)			\
57 	stringify_in_c(			.set	.Lfound, 1;)			\
58 	stringify_in_c(			.set	.Lregaddr, .Lcurr;)		\
59 	stringify_in_c(		.endif;)					\
60 	stringify_in_c(		.set	.Lcurr, .Lcurr+1;)			\
61 	stringify_in_c(.endr;)							\
62 	stringify_in_c(.ifne	(.Lfound != 1);)				\
63 	stringify_in_c(		.error	"extable_reg: bad register argument2";)	\
64 	stringify_in_c(.endif;)							\
65 	stringify_in_c(.short	.Lregerr << EX_DATA_REG_ERR_SHIFT |		\
66 				.Lregaddr << EX_DATA_REG_ADDR_SHIFT |		\
67 				_len << EX_DATA_LEN_SHIFT;)			\
68 	stringify_in_c(.endm;)							\
69 	stringify_in_c(extable_reg _regerr,_regaddr;)				\
70 	stringify_in_c(.purgem	extable_reg;)					\
71 	stringify_in_c(.previous)
72 
73 #define EX_TABLE(_fault, _target)					\
74 	__EX_TABLE(__ex_table, _fault, _target, EX_TYPE_FIXUP)
75 
76 #define EX_TABLE_AMODE31(_fault, _target)				\
77 	__EX_TABLE(.amode31.ex_table, _fault, _target, EX_TYPE_FIXUP)
78 
79 #define EX_TABLE_UA_STORE(_fault, _target, _regerr)			\
80 	__EX_TABLE_UA(__ex_table, _fault, _target, EX_TYPE_UA_STORE, _regerr, _regerr, 0)
81 
82 #define EX_TABLE_UA_LOAD_MEM(_fault, _target, _regerr, _regmem, _len)	\
83 	__EX_TABLE_UA(__ex_table, _fault, _target, EX_TYPE_UA_LOAD_MEM, _regerr, _regmem, _len)
84 
85 #define EX_TABLE_UA_LOAD_REG(_fault, _target, _regerr, _regzero)	\
86 	__EX_TABLE_UA(__ex_table, _fault, _target, EX_TYPE_UA_LOAD_REG, _regerr, _regzero, 0)
87 
88 #endif /* __ASM_EXTABLE_H */
89