1 #ifndef _ASM_X86_ALTERNATIVE_H
2 #define _ASM_X86_ALTERNATIVE_H
4 #include <linux/types.h>
5 #include <linux/stddef.h>
31 #define LOCK_PREFIX_HERE \
32 ".pushsection .smp_locks,\"a\"\n" \
38 #define LOCK_PREFIX LOCK_PREFIX_HERE "\n\tlock; "
41 #define LOCK_PREFIX_HERE ""
42 #define LOCK_PREFIX ""
59 extern void alternatives_smp_module_add(
struct module *
mod,
char *
name,
60 void *locks,
void *locks_end,
61 void *
text,
void *text_end);
62 extern void alternatives_smp_module_del(
struct module *
mod);
63 extern void alternatives_enable_smp(
void);
64 extern int alternatives_text_reserved(
void *
start,
void *
end);
65 extern bool skip_smp_alternatives;
67 static inline void alternatives_smp_module_add(
struct module *
mod,
char *
name,
68 void *locks,
void *locks_end,
69 void *
text,
void *text_end) {}
70 static inline void alternatives_smp_module_del(
struct module *
mod) {}
71 static inline void alternatives_enable_smp(
void) {}
72 static inline int alternatives_text_reserved(
void *
start,
void *
end)
78 #define OLDINSTR(oldinstr) "661:\n\t" oldinstr "\n662:\n"
80 #define b_replacement(number) "663"#number
81 #define e_replacement(number) "664"#number
83 #define alt_slen "662b-661b"
84 #define alt_rlen(number) e_replacement(number)"f-"b_replacement(number)"f"
86 #define ALTINSTR_ENTRY(feature, number) \
88 " .long " b_replacement(number)"f - .\n" \
89 " .word " __stringify(feature) "\n" \
90 " .byte " alt_slen "\n" \
91 " .byte " alt_rlen(number) "\n"
93 #define DISCARD_ENTRY(number) \
94 " .byte 0xff + (" alt_rlen(number) ") - (" alt_slen ")\n"
96 #define ALTINSTR_REPLACEMENT(newinstr, feature, number) \
97 b_replacement(number)":\n\t" newinstr "\n" e_replacement(number) ":\n\t"
100 #define ALTERNATIVE(oldinstr, newinstr, feature) \
102 ".pushsection .altinstructions,\"a\"\n" \
103 ALTINSTR_ENTRY(feature, 1) \
105 ".pushsection .discard,\"aw\",@progbits\n" \
108 ".pushsection .altinstr_replacement, \"ax\"\n" \
109 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
112 #define ALTERNATIVE_2(oldinstr, newinstr1, feature1, newinstr2, feature2)\
114 ".pushsection .altinstructions,\"a\"\n" \
115 ALTINSTR_ENTRY(feature1, 1) \
116 ALTINSTR_ENTRY(feature2, 2) \
118 ".pushsection .discard,\"aw\",@progbits\n" \
122 ".pushsection .altinstr_replacement, \"ax\"\n" \
123 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
124 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
131 #include <asm/cpufeature.h>
145 #define alternative(oldinstr, newinstr, feature) \
146 asm volatile (ALTERNATIVE(oldinstr, newinstr, feature) : : : "memory")
159 #define alternative_input(oldinstr, newinstr, feature, input...) \
160 asm volatile (ALTERNATIVE(oldinstr, newinstr, feature) \
161 : : "i" (0), ## input)
164 #define alternative_io(oldinstr, newinstr, feature, output, input...) \
165 asm volatile (ALTERNATIVE(oldinstr, newinstr, feature) \
166 : output : "i" (0), ## input)
169 #define alternative_call(oldfunc, newfunc, feature, output, input...) \
170 asm volatile (ALTERNATIVE("call %P[old]", "call %P[new]", feature) \
171 : output : [old] "i" (oldfunc), [new] "i" (newfunc), ## input)
179 #define alternative_call_2(oldfunc, newfunc1, feature1, newfunc2, feature2, \
181 asm volatile (ALTERNATIVE_2("call %P[old]", "call %P[new1]", feature1,\
182 "call %P[new2]", feature2) \
183 : output : [old] "i" (oldfunc), [new1] "i" (newfunc1), \
184 [new2] "i" (newfunc2), ## input)
190 #define ASM_OUTPUT2(a...) a
196 #define ASM_NO_INPUT_CLOBBER(clbr...) "i" (0) : clbr
199 #ifdef CONFIG_PARAVIRT
206 #define __parainstructions NULL
207 #define __parainstructions_end NULL