1#ifndef _ASM_X86_ALTERNATIVE_ASM_H
2#define _ASM_X86_ALTERNATIVE_ASM_H
3
4#ifdef __ASSEMBLY__
5
6#include <asm/asm.h>
7
8#ifdef CONFIG_SMP
9	.macro LOCK_PREFIX
10672:	lock
11	.pushsection .smp_locks,"a"
12	.balign 4
13	.long 672b - .
14	.popsection
15	.endm
16#else
17	.macro LOCK_PREFIX
18	.endm
19#endif
20
21.macro altinstruction_entry orig alt feature orig_len alt_len pad_len
22	.long \orig - .
23	.long \alt - .
24	.word \feature
25	.byte \orig_len
26	.byte \alt_len
27	.byte \pad_len
28.endm
29
30.macro ALTERNATIVE oldinstr, newinstr, feature
31140:
32	\oldinstr
33141:
34	.skip -(((144f-143f)-(141b-140b)) > 0) * ((144f-143f)-(141b-140b)),0x90
35142:
36
37	.pushsection .altinstructions,"a"
38	altinstruction_entry 140b,143f,\feature,142b-140b,144f-143f,142b-141b
39	.popsection
40
41	.pushsection .altinstr_replacement,"ax"
42143:
43	\newinstr
44144:
45	.popsection
46.endm
47
48#define old_len			141b-140b
49#define new_len1		144f-143f
50#define new_len2		145f-144f
51
52/*
53 * max without conditionals. Idea adapted from:
54 * http://graphics.stanford.edu/~seander/bithacks.html#IntegerMinOrMax
55 */
56#define alt_max_short(a, b)	((a) ^ (((a) ^ (b)) & -(-((a) < (b)))))
57
58.macro ALTERNATIVE_2 oldinstr, newinstr1, feature1, newinstr2, feature2
59140:
60	\oldinstr
61141:
62	.skip -((alt_max_short(new_len1, new_len2) - (old_len)) > 0) * \
63		(alt_max_short(new_len1, new_len2) - (old_len)),0x90
64142:
65
66	.pushsection .altinstructions,"a"
67	altinstruction_entry 140b,143f,\feature1,142b-140b,144f-143f,142b-141b
68	altinstruction_entry 140b,144f,\feature2,142b-140b,145f-144f,142b-141b
69	.popsection
70
71	.pushsection .altinstr_replacement,"ax"
72143:
73	\newinstr1
74144:
75	\newinstr2
76145:
77	.popsection
78.endm
79
80#endif  /*  __ASSEMBLY__  */
81
82#endif /* _ASM_X86_ALTERNATIVE_ASM_H */
83