1 #ifndef _I386_ALTERNATIVE_H
2 #define _I386_ALTERNATIVE_H
9 u8
*instr
; /* original instruction */
11 u8 cpuid
; /* cpuid bit set for replacement */
12 u8 instrlen
; /* length of original instruction */
13 u8 replacementlen
; /* length of new instruction, <= instrlen */
17 extern void apply_alternatives(struct alt_instr
*start
, struct alt_instr
*end
);
20 extern void alternatives_smp_module_add(struct module
*mod
, char *name
,
21 void *locks
, void *locks_end
,
22 void *text
, void *text_end
);
23 extern void alternatives_smp_module_del(struct module
*mod
);
24 extern void alternatives_smp_switch(int smp
);
29 * Alternative instructions for different CPU types or capabilities.
31 * This allows to use optimized instructions even on generic binary
34 * length of oldinstr must be longer or equal the length of newinstr
35 * It can be padded with nops as needed.
37 * For non barrier like inlines please define new variants
38 * without volatile and memory clobber.
40 #define alternative(oldinstr, newinstr, feature) \
41 asm volatile ("661:\n\t" oldinstr "\n662:\n" \
42 ".section .altinstructions,\"a\"\n" \
44 " .long 661b\n" /* label */ \
45 " .long 663f\n" /* new instruction */ \
46 " .byte %c0\n" /* feature bit */ \
47 " .byte 662b-661b\n" /* sourcelen */ \
48 " .byte 664f-663f\n" /* replacementlen */ \
50 ".section .altinstr_replacement,\"ax\"\n" \
51 "663:\n\t" newinstr "\n664:\n" /* replacement */\
52 ".previous" :: "i" (feature) : "memory")
55 * Alternative inline assembly with input.
58 * No memory clobber here.
59 * Argument numbers start with 1.
60 * Best is to use constraints that are fixed size (like (%1) ... "r")
61 * If you use variable sized constraints like "m" or "g" in the
62 * replacement maake sure to pad to the worst case length.
64 #define alternative_input(oldinstr, newinstr, feature, input...) \
65 asm volatile ("661:\n\t" oldinstr "\n662:\n" \
66 ".section .altinstructions,\"a\"\n" \
68 " .long 661b\n" /* label */ \
69 " .long 663f\n" /* new instruction */ \
70 " .byte %c0\n" /* feature bit */ \
71 " .byte 662b-661b\n" /* sourcelen */ \
72 " .byte 664f-663f\n" /* replacementlen */ \
74 ".section .altinstr_replacement,\"ax\"\n" \
75 "663:\n\t" newinstr "\n664:\n" /* replacement */\
76 ".previous" :: "i" (feature), ##input)
79 * Alternative inline assembly for SMP.
81 * alternative_smp() takes two versions (SMP first, UP second) and is
82 * for more complex stuff such as spinlocks.
84 * The LOCK_PREFIX macro defined here replaces the LOCK and
85 * LOCK_PREFIX macros used everywhere in the source tree.
87 * SMP alternatives use the same data structures as the other
88 * alternatives and the X86_FEATURE_UP flag to indicate the case of a
89 * UP system running a SMP kernel. The existing apply_alternatives()
90 * works fine for patching a SMP kernel for UP.
92 * The SMP alternative tables can be kept after boot and contain both
93 * UP and SMP versions of the instructions to allow switching back to
94 * SMP at runtime, when hotplugging in a new CPU, which is especially
95 * useful in virtualized environments.
97 * The very common lock prefix is handled as special case in a
98 * separate table which is a pure address list without replacement ptr
99 * and size information. That keeps the table sizes small.
103 #define alternative_smp(smpinstr, upinstr, args...) \
104 asm volatile ("661:\n\t" smpinstr "\n662:\n" \
105 ".section .smp_altinstructions,\"a\"\n" \
107 " .long 661b\n" /* label */ \
108 " .long 663f\n" /* new instruction */ \
109 " .byte 0x68\n" /* X86_FEATURE_UP */ \
110 " .byte 662b-661b\n" /* sourcelen */ \
111 " .byte 664f-663f\n" /* replacementlen */ \
113 ".section .smp_altinstr_replacement,\"awx\"\n" \
114 "663:\n\t" upinstr "\n" /* replacement */ \
115 "664:\n\t.fill 662b-661b,1,0x42\n" /* space for original */ \
118 #define LOCK_PREFIX \
119 ".section .smp_locks,\"a\"\n" \
121 " .long 661f\n" /* address */ \
125 #else /* ! CONFIG_SMP */
126 #define alternative_smp(smpinstr, upinstr, args...) \
127 asm volatile (upinstr : args)
128 #define LOCK_PREFIX ""
131 #endif /* _I386_ALTERNATIVE_H */