1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_ALTERNATIVE_ASM_H
3 #define _ASM_ALTERNATIVE_ASM_H
10 * Issue one struct alt_instr descriptor entry (need to put it into
11 * the section .altinstructions, see below). This entry contains
12 * enough information for the alternatives patching code to patch an
13 * instruction. See apply_alternatives().
15 .macro altinstruction_entry orig alt feature orig_len alt_len
24 * Define an alternative between two instructions. If @feature is
25 * present, early code in apply_alternatives() replaces @oldinstr with
26 * @newinstr. ".fill" directive takes care of proper instruction padding
27 * in case @newinstr is longer than @oldinstr.
29 .macro ALTERNATIVE oldinstr
, newinstr
, feature
33 .fill
- (((144f
-143f
)-(141b
-140b
)) > 0) * ((144f
-143f
)-(141b
-140b
)) / 4, 4, 0x03400000
36 .pushsection
.altinstructions
, "a"
37 altinstruction_entry
140b
, 143f
, \feature
, 142b
-140b
, 144f
-143f
47 #define old_len (141b-140b)
48 #define new_len1 (144f-143f)
49 #define new_len2 (145f-144f)
51 #define alt_max_short(a, b) ((a) ^ (((a) ^ (b)) & -(-((a) < (b)))))
54 * Same as ALTERNATIVE macro above but for two alternatives. If CPU
55 * has @feature1, it replaces @oldinstr with @newinstr1. If CPU has
56 * @feature2, it replaces @oldinstr with @feature2.
58 .macro ALTERNATIVE_2 oldinstr
, newinstr1
, feature1
, newinstr2
, feature2
62 .fill
- ((alt_max_short(new_len1
, new_len2
) - (old_len
)) > 0) * \
63 (alt_max_short(new_len1
, new_len2
) - (old_len
)) / 4, 4, 0x03400000
66 .pushsection
.altinstructions
, "a"
67 altinstruction_entry
140b
, 143f
, \feature
1, 142b
-140b
, 144f
-143f
, 142b
-141b
68 altinstruction_entry
140b
, 144f
, \feature
2, 142b
-140b
, 145f
-144f
, 142b
-141b
80 #endif /* __ASSEMBLY__ */
82 #endif /* _ASM_ALTERNATIVE_ASM_H */