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