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,r2
41 	__THUNK_PROLOG_NAME __s390_indirect_jump_r\r1
42 	.endm
43 
44 	.macro __THUNK_EPILOG_BR r1,r2
45 	__THUNK_EPILOG_NAME __s390_indirect_jump_r\r1
46 	.endm
47 
48 	.macro __THUNK_BR r1,r2
49 	jg	__s390_indirect_jump_r\r1
50 	.endm
51 
52 	.macro __THUNK_BRASL r1,r2,r3
53 	brasl	\r1,__s390_indirect_jump_r\r2
54 	.endm
55 
56 	.macro	__DECODE_RR expand,reg,ruse
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 	.irp r2,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
61 	.ifc \ruse,%r\r2
62 	\expand \r1,\r2
63 	.set __decode_fail,0
64 	.endif
65 	.endr
66 	.endif
67 	.endr
68 	.if __decode_fail == 1
69 	.error "__DECODE_RR failed"
70 	.endif
71 	.endm
72 
73 	.macro	__DECODE_RRR expand,rsave,rtarget,ruse
74 	.set __decode_fail,1
75 	.irp r1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
76 	.ifc \rsave,%r\r1
77 	.irp r2,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
78 	.ifc \rtarget,%r\r2
79 	.irp r3,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
80 	.ifc \ruse,%r\r3
81 	\expand \r1,\r2,\r3
82 	.set __decode_fail,0
83 	.endif
84 	.endr
85 	.endif
86 	.endr
87 	.endif
88 	.endr
89 	.if __decode_fail == 1
90 	.error "__DECODE_RRR failed"
91 	.endif
92 	.endm
93 
94 	.macro __THUNK_EX_BR reg,ruse
95 	exrl	0,555f
96 	j	.
97 555:	br	\reg
98 	.endm
99 
100 #ifdef CONFIG_EXPOLINE_EXTERN
101 	.macro GEN_BR_THUNK reg,ruse=%r1
102 	.endm
103 	.macro GEN_BR_THUNK_EXTERN reg,ruse=%r1
104 #else
105 	.macro GEN_BR_THUNK reg,ruse=%r1
106 #endif
107 	__DECODE_RR __THUNK_PROLOG_BR,\reg,\ruse
108 	__THUNK_EX_BR \reg,\ruse
109 	__DECODE_RR __THUNK_EPILOG_BR,\reg,\ruse
110 	.endm
111 
112 	.macro BR_EX reg,ruse=%r1
113 557:	__DECODE_RR __THUNK_BR,\reg,\ruse
114 	.pushsection .s390_indirect_branches,"a",@progbits
115 	.long	557b-.
116 	.popsection
117 	.endm
118 
119 	.macro BASR_EX rsave,rtarget,ruse=%r1
120 559:	__DECODE_RRR __THUNK_BRASL,\rsave,\rtarget,\ruse
121 	.pushsection .s390_indirect_branches,"a",@progbits
122 	.long	559b-.
123 	.popsection
124 	.endm
125 
126 #else
127 	.macro GEN_BR_THUNK reg,ruse=%r1
128 	.endm
129 
130 	 .macro BR_EX reg,ruse=%r1
131 	br	\reg
132 	.endm
133 
134 	.macro BASR_EX rsave,rtarget,ruse=%r1
135 	basr	\rsave,\rtarget
136 	.endm
137 #endif /* CC_USING_EXPOLINE */
138 
139 #endif /* __ASSEMBLY__ */
140 
141 #endif /* _ASM_S390_NOSPEC_ASM_H */
142