1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_S390_NOSPEC_ASM_H
3 #define _ASM_S390_NOSPEC_ASM_H
4 
5 #include <asm/alternative-asm.h>
6 #include <asm/asm-offsets.h>
7 #include <asm/dwarf.h>
8 
9 #ifdef __ASSEMBLY__
10 
11 #ifdef CC_USING_EXPOLINE
12 
13 /*
14  * The expoline macros are used to create thunks in the same format
15  * as gcc generates them. The 'comdat' section flag makes sure that
16  * the various thunks are merged into a single copy.
17  */
18 	.macro __THUNK_PROLOG_NAME name
19 #ifdef CONFIG_EXPOLINE_EXTERN
20 	.pushsection .text,"ax",@progbits
21 	.align 16,0x07
22 #else
23 	.pushsection .text.\name,"axG",@progbits,\name,comdat
24 #endif
25 	.globl \name
26 	.hidden \name
27 	.type \name,@function
28 \name:
29 	CFI_STARTPROC
30 	.endm
31 
32 	.macro __THUNK_EPILOG_NAME name
33 	CFI_ENDPROC
34 #ifdef CONFIG_EXPOLINE_EXTERN
35 	.size \name, .-\name
36 #endif
37 	.popsection
38 	.endm
39 
40 	.macro __THUNK_PROLOG_BR r1
41 	__THUNK_PROLOG_NAME __s390_indirect_jump_r\r1
42 	.endm
43 
44 	.macro __THUNK_EPILOG_BR r1
45 	__THUNK_EPILOG_NAME __s390_indirect_jump_r\r1
46 	.endm
47 
48 	.macro __THUNK_BR r1
49 	jg	__s390_indirect_jump_r\r1
50 	.endm
51 
52 	.macro __THUNK_BRASL r1,r2
53 	brasl	\r1,__s390_indirect_jump_r\r2
54 	.endm
55 
56 	.macro	__DECODE_R expand,reg
57 	.set __decode_fail,1
58 	.irp r1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
59 	.ifc \reg,%r\r1
60 	\expand \r1
61 	.set __decode_fail,0
62 	.endif
63 	.endr
64 	.if __decode_fail == 1
65 	.error "__DECODE_R failed"
66 	.endif
67 	.endm
68 
69 	.macro	__DECODE_RR expand,rsave,rtarget
70 	.set __decode_fail,1
71 	.irp r1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
72 	.ifc \rsave,%r\r1
73 	.irp r2,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
74 	.ifc \rtarget,%r\r2
75 	\expand \r1,\r2
76 	.set __decode_fail,0
77 	.endif
78 	.endr
79 	.endif
80 	.endr
81 	.if __decode_fail == 1
82 	.error "__DECODE_RR failed"
83 	.endif
84 	.endm
85 
86 	.macro __THUNK_EX_BR reg
87 	exrl	0,555f
88 	j	.
89 555:	br	\reg
90 	.endm
91 
92 #ifdef CONFIG_EXPOLINE_EXTERN
93 	.macro GEN_BR_THUNK reg
94 	.endm
95 	.macro GEN_BR_THUNK_EXTERN reg
96 #else
97 	.macro GEN_BR_THUNK reg
98 #endif
99 	__DECODE_R __THUNK_PROLOG_BR,\reg
100 	__THUNK_EX_BR \reg
101 	__DECODE_R __THUNK_EPILOG_BR,\reg
102 	.endm
103 
104 	.macro BR_EX reg
105 557:	__DECODE_R __THUNK_BR,\reg
106 	.pushsection .s390_indirect_branches,"a",@progbits
107 	.long	557b-.
108 	.popsection
109 	.endm
110 
111 	.macro BASR_EX rsave,rtarget
112 559:	__DECODE_RR __THUNK_BRASL,\rsave,\rtarget
113 	.pushsection .s390_indirect_branches,"a",@progbits
114 	.long	559b-.
115 	.popsection
116 	.endm
117 
118 #else
119 	.macro GEN_BR_THUNK reg
120 	.endm
121 
122 	 .macro BR_EX reg
123 	br	\reg
124 	.endm
125 
126 	.macro BASR_EX rsave,rtarget
127 	basr	\rsave,\rtarget
128 	.endm
129 #endif /* CC_USING_EXPOLINE */
130 
131 #endif /* __ASSEMBLY__ */
132 
133 #endif /* _ASM_S390_NOSPEC_ASM_H */
134