1 #ifndef __ASM_ALTERNATIVE_H
2 #define __ASM_ALTERNATIVE_H
6 #include <linux/types.h>
7 #include <linux/stddef.h>
8 #include <linux/stringify.h>
11 s32 orig_offset; /* offset to original instruction */
12 s32 alt_offset; /* offset to replacement instruction */
13 u16 cpufeature; /* cpufeature bit set for replacement */
14 u8 orig_len; /* size of original instruction(s) */
15 u8 alt_len; /* size of new instruction(s), <= orig_len */
18 void apply_alternatives_all(void);
19 void apply_alternatives(void *start, size_t length);
20 void free_alternatives_memory(void);
22 #define ALTINSTR_ENTRY(feature) \
23 " .word 661b - .\n" /* label */ \
24 " .word 663f - .\n" /* new instruction */ \
25 " .hword " __stringify(feature) "\n" /* feature bit */ \
26 " .byte 662b-661b\n" /* source len */ \
27 " .byte 664f-663f\n" /* replacement len */
30 * alternative assembly primitive:
32 * If any of these .org directive fail, it means that insn1 and insn2
33 * don't have the same length. This used to be written as
35 * .if ((664b-663b) != (662b-661b))
36 * .error "Alternatives instruction length mismatch"
39 * but most assemblers die if insn1 or insn2 have a .inst. This should
40 * be fixed in a binutils release posterior to 2.25.51.0.2 (anything
41 * containing commit 4e4d08cf7399b606 or c1baaddf8861).
43 #define ALTERNATIVE(oldinstr, newinstr, feature) \
47 ".pushsection .altinstructions,\"a\"\n" \
48 ALTINSTR_ENTRY(feature) \
50 ".pushsection .altinstr_replacement, \"a\"\n" \
55 ".org . - (664b-663b) + (662b-661b)\n\t" \
56 ".org . - (662b-661b) + (664b-663b)\n"
60 .macro altinstruction_entry orig_offset alt_offset feature orig_len alt_len
61 .word \orig_offset - .
68 .macro alternative_insn insn1 insn2 cap
70 662: .pushsection .altinstructions, "a"
71 altinstruction_entry 661b, 663f, \cap, 662b-661b, 664f-663f
73 .pushsection .altinstr_replacement, "ax"
76 .org . - (664b-663b) + (662b-661b)
77 .org . - (662b-661b) + (664b-663b)
80 #endif /* __ASSEMBLY__ */
82 #endif /* __ASM_ALTERNATIVE_H */