1 /* SPDX-License-Identifier: GPL-2.0 */
6 # define __ASM_FORM(x, ...) x,## __VA_ARGS__
7 # define __ASM_FORM_RAW(x, ...) x,## __VA_ARGS__
8 # define __ASM_FORM_COMMA(x, ...) x,## __VA_ARGS__,
9 # define __ASM_REGPFX %
11 #include <linux/stringify.h>
12 # define __ASM_FORM(x, ...) " " __stringify(x,##__VA_ARGS__) " "
13 # define __ASM_FORM_RAW(x, ...) __stringify(x,##__VA_ARGS__)
14 # define __ASM_FORM_COMMA(x, ...) " " __stringify(x,##__VA_ARGS__) ","
15 # define __ASM_REGPFX %%
18 #define _ASM_BYTES(x, ...) __ASM_FORM(.byte x,##__VA_ARGS__ ;)
22 # define __ASM_SEL(a,b) __ASM_FORM(a)
23 # define __ASM_SEL_RAW(a,b) __ASM_FORM_RAW(a)
26 # define __ASM_SEL(a,b) __ASM_FORM(b)
27 # define __ASM_SEL_RAW(a,b) __ASM_FORM_RAW(b)
30 #define __ASM_SIZE(inst, ...) __ASM_SEL(inst##l##__VA_ARGS__, \
32 #define __ASM_REG(reg) __ASM_SEL_RAW(e##reg, r##reg)
34 #define _ASM_PTR __ASM_SEL(.long, .quad)
35 #define _ASM_ALIGN __ASM_SEL(.balign 4, .balign 8)
37 #define _ASM_MOV __ASM_SIZE(mov)
38 #define _ASM_INC __ASM_SIZE(inc)
39 #define _ASM_DEC __ASM_SIZE(dec)
40 #define _ASM_ADD __ASM_SIZE(add)
41 #define _ASM_SUB __ASM_SIZE(sub)
42 #define _ASM_XADD __ASM_SIZE(xadd)
43 #define _ASM_MUL __ASM_SIZE(mul)
45 #define _ASM_AX __ASM_REG(ax)
46 #define _ASM_BX __ASM_REG(bx)
47 #define _ASM_CX __ASM_REG(cx)
48 #define _ASM_DX __ASM_REG(dx)
49 #define _ASM_SP __ASM_REG(sp)
50 #define _ASM_BP __ASM_REG(bp)
51 #define _ASM_SI __ASM_REG(si)
52 #define _ASM_DI __ASM_REG(di)
54 /* Adds a (%rip) suffix on 64 bits only; for immediate memory references */
55 #define _ASM_RIP(x) __ASM_SEL_RAW(x, x (__ASM_REGPFX rip))
60 #define _ASM_ARG1 _ASM_AX
61 #define _ASM_ARG2 _ASM_DX
62 #define _ASM_ARG3 _ASM_CX
64 #define _ASM_ARG1L eax
65 #define _ASM_ARG2L edx
66 #define _ASM_ARG3L ecx
79 #define _ASM_ARG1 _ASM_DI
80 #define _ASM_ARG2 _ASM_SI
81 #define _ASM_ARG3 _ASM_DX
82 #define _ASM_ARG4 _ASM_CX
86 #define _ASM_ARG1Q rdi
87 #define _ASM_ARG2Q rsi
88 #define _ASM_ARG3Q rdx
89 #define _ASM_ARG4Q rcx
93 #define _ASM_ARG1L edi
94 #define _ASM_ARG2L esi
95 #define _ASM_ARG3L edx
96 #define _ASM_ARG4L ecx
97 #define _ASM_ARG5L r8d
98 #define _ASM_ARG6L r9d
100 #define _ASM_ARG1W di
101 #define _ASM_ARG2W si
102 #define _ASM_ARG3W dx
103 #define _ASM_ARG4W cx
104 #define _ASM_ARG5W r8w
105 #define _ASM_ARG6W r9w
107 #define _ASM_ARG1B dil
108 #define _ASM_ARG2B sil
109 #define _ASM_ARG3B dl
110 #define _ASM_ARG4B cl
111 #define _ASM_ARG5B r8b
112 #define _ASM_ARG6B r9b
117 * Macros to generate condition code outputs from inline assembly,
118 * The output operand must be type "bool".
120 #ifdef __GCC_ASM_FLAG_OUTPUTS__
121 # define CC_SET(c) "\n\t/* output condition code " #c "*/\n"
122 # define CC_OUT(c) "=@cc" #c
124 # define CC_SET(c) "\n\tset" #c " %[_cc_" #c "]\n"
125 # define CC_OUT(c) [_cc_ ## c] "=qm"
130 # include <asm/extable_fixup_types.h>
132 /* Exception table entry */
135 # define _ASM_EXTABLE_TYPE(from, to, type) \
136 .pushsection "__ex_table","a" ; \
143 # ifdef CONFIG_KPROBES
144 # define _ASM_NOKPROBE(entry) \
145 .pushsection "_kprobe_blacklist","aw" ; \
150 # define _ASM_NOKPROBE(entry)
153 #else /* ! __ASSEMBLY__ */
155 # define DEFINE_EXTABLE_TYPE_REG \
156 ".macro extable_type_reg type:req reg:req\n" \
157 ".set .Lfound, 0\n" \
158 ".set .Lregnr, 0\n" \
159 ".irp rs,rax,rcx,rdx,rbx,rsp,rbp,rsi,rdi,r8,r9,r10,r11,r12,r13,r14,r15\n" \
160 ".ifc \\reg, %%\\rs\n" \
161 ".set .Lfound, .Lfound+1\n" \
162 ".long \\type + (.Lregnr << 8)\n" \
164 ".set .Lregnr, .Lregnr+1\n" \
166 ".set .Lregnr, 0\n" \
167 ".irp rs,eax,ecx,edx,ebx,esp,ebp,esi,edi,r8d,r9d,r10d,r11d,r12d,r13d,r14d,r15d\n" \
168 ".ifc \\reg, %%\\rs\n" \
169 ".set .Lfound, .Lfound+1\n" \
170 ".long \\type + (.Lregnr << 8)\n" \
172 ".set .Lregnr, .Lregnr+1\n" \
174 ".if (.Lfound != 1)\n" \
175 ".error \"extable_type_reg: bad register argument\"\n" \
179 # define UNDEFINE_EXTABLE_TYPE_REG \
180 ".purgem extable_type_reg\n"
182 # define _ASM_EXTABLE_TYPE(from, to, type) \
183 " .pushsection \"__ex_table\",\"a\"\n" \
185 " .long (" #from ") - .\n" \
186 " .long (" #to ") - .\n" \
187 " .long " __stringify(type) " \n" \
190 # define _ASM_EXTABLE_TYPE_REG(from, to, type, reg) \
191 " .pushsection \"__ex_table\",\"a\"\n" \
193 " .long (" #from ") - .\n" \
194 " .long (" #to ") - .\n" \
195 DEFINE_EXTABLE_TYPE_REG \
196 "extable_type_reg reg=" __stringify(reg) ", type=" __stringify(type) " \n"\
197 UNDEFINE_EXTABLE_TYPE_REG \
200 /* For C file, we already have NOKPROBE_SYMBOL macro */
203 * This output constraint should be used for any inline asm which has a "call"
204 * instruction. Otherwise the asm may be inserted before the frame pointer
205 * gets set up by the containing function. If you forget to do this, objtool
206 * may print a "call without frame pointer save/setup" warning.
208 register unsigned long current_stack_pointer asm(_ASM_SP);
209 #define ASM_CALL_CONSTRAINT "+r" (current_stack_pointer)
210 #endif /* __ASSEMBLY__ */
212 #define _ASM_EXTABLE(from, to) \
213 _ASM_EXTABLE_TYPE(from, to, EX_TYPE_DEFAULT)
215 #define _ASM_EXTABLE_UA(from, to) \
216 _ASM_EXTABLE_TYPE(from, to, EX_TYPE_UACCESS)
218 #define _ASM_EXTABLE_CPY(from, to) \
219 _ASM_EXTABLE_TYPE(from, to, EX_TYPE_COPY)
221 #define _ASM_EXTABLE_FAULT(from, to) \
222 _ASM_EXTABLE_TYPE(from, to, EX_TYPE_FAULT)
224 #endif /* __KERNEL__ */
225 #endif /* _ASM_X86_ASM_H */