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