* enough information for the alternatives patching code to patch an
* instruction. See apply_alternatives().
*/
-.macro altinstruction_entry orig alt feature orig_len alt_len
+.macro altinstruction_entry orig repl feature orig_len repl_len
.long \orig - .
- .long \alt - .
+ .long \repl - .
.word \feature
.byte \orig_len
- .byte \alt_len
+ .byte \repl_len
.endm
+#define decl_orig(insn) .L\@_orig_s: insn; .L\@_orig_e:
+#define orig_len (.L\@_orig_e - .L\@_orig_s)
+
+#define decl_repl(insn, nr) .L\@_repl_s\()nr: insn; .L\@_repl_e\()nr:
+#define repl_len(nr) (.L\@_repl_e\()nr - .L\@_repl_s\()nr)
+
.macro ALTERNATIVE oldinstr, newinstr, feature
-.Lold_start_\@:
- \oldinstr
-.Lold_end_\@:
+ decl_orig(\oldinstr)
.pushsection .altinstructions, "a", @progbits
- altinstruction_entry .Lold_start_\@, .Lnew_start_\@, \feature, \
- (.Lold_end_\@ - .Lold_start_\@), (.Lnew_end_\@ - .Lnew_start_\@)
+ altinstruction_entry .L\@_orig_s, .L\@_repl_s1, \feature, \
+ orig_len, repl_len(1)
.section .discard, "a", @progbits
/* Assembler-time check that \newinstr isn't longer than \oldinstr. */
- .byte 0xff + (.Lnew_end_\@ - .Lnew_start_\@) - (.Lold_end_\@ - .Lold_start_\@)
+ .byte 0xff + repl_len(1) - orig_len
.section .altinstr_replacement, "ax", @progbits
-.Lnew_start_\@:
- \newinstr
-.Lnew_end_\@:
+
+ decl_repl(\newinstr, 1)
+
.popsection
.endm
.macro ALTERNATIVE_2 oldinstr, newinstr1, feature1, newinstr2, feature2
-.Lold_start_\@:
- \oldinstr
-.Lold_end_\@:
+ decl_orig(\oldinstr)
.pushsection .altinstructions, "a", @progbits
- altinstruction_entry .Lold_start_\@, .Lnew1_start_\@, \feature1, \
- (.Lold_end_\@ - .Lold_start_\@), (.Lnew1_end_\@ - .Lnew1_start_\@)
- altinstruction_entry .Lold_start_\@, .Lnew2_start_\@, \feature2, \
- (.Lold_end_\@ - .Lold_start_\@), (.Lnew2_end_\@ - .Lnew2_start_\@)
+
+ altinstruction_entry .L\@_orig_s, .L\@_repl_s1, \feature1, \
+ orig_len, repl_len(1)
+ altinstruction_entry .L\@_orig_s, .L\@_repl_s2, \feature2, \
+ orig_len, repl_len(2)
.section .discard, "a", @progbits
/* Assembler-time check that \newinstr{1,2} aren't longer than \oldinstr. */
- .byte 0xff + (.Lnew1_end_\@ - .Lnew1_start_\@) - (.Lold_end_\@ - .Lold_start_\@)
- .byte 0xff + (.Lnew2_end_\@ - .Lnew2_start_\@) - (.Lold_end_\@ - .Lold_start_\@)
+ .byte 0xff + repl_len(1) - orig_len
+ .byte 0xff + repl_len(2) - orig_len
.section .altinstr_replacement, "ax", @progbits
-.Lnew1_start_\@:
- \newinstr1
-.Lnew1_end_\@:
-.Lnew2_start_\@:
- \newinstr2
-.Lnew2_end_\@:
+
+ decl_repl(\newinstr1, 1)
+ decl_repl(\newinstr2, 2)
+
.popsection
.endm
+#undef repl_len
+#undef decl_repl
+#undef orig_len
+#undef decl_orig
+
#endif /* __ASSEMBLY__ */
#endif /* _ASM_X86_ALTERNATIVE_ASM_H_ */
const struct alt_instr *end);
extern void alternative_instructions(void);
-#define OLDINSTR(oldinstr) "661:\n\t" oldinstr "\n662:\n"
+#define OLDINSTR(oldinstr) ".LXEN%=_orig_s:\n\t" oldinstr "\n.LXEN%=_orig_e:\n"
-#define b_replacement(number) "663"#number
-#define e_replacement(number) "664"#number
+#define alt_orig_len "(.LXEN%=_orig_e - .LXEN%=_orig_s)"
+#define alt_repl_s(num) ".LXEN%=_repl_s"#num
+#define alt_repl_e(num) ".LXEN%=_repl_e"#num
+#define alt_repl_len(num) "(" alt_repl_e(num) " - " alt_repl_s(num) ")"
-#define alt_slen "662b-661b"
-#define alt_rlen(number) e_replacement(number)"f-"b_replacement(number)"f"
+#define ALTINSTR_ENTRY(feature, num) \
+ " .long .LXEN%=_orig_s - .\n" /* label */ \
+ " .long " alt_repl_s(num)" - .\n" /* new instruction */ \
+ " .word " __stringify(feature) "\n" /* feature bit */ \
+ " .byte " alt_orig_len "\n" /* source len */ \
+ " .byte " alt_repl_len(num) "\n" /* replacement len */
-#define ALTINSTR_ENTRY(feature, number) \
- " .long 661b - .\n" /* label */ \
- " .long " b_replacement(number)"f - .\n" /* new instruction */ \
- " .word " __stringify(feature) "\n" /* feature bit */ \
- " .byte " alt_slen "\n" /* source len */ \
- " .byte " alt_rlen(number) "\n" /* replacement len */
+#define DISCARD_ENTRY(num) /* repl <= orig */ \
+ " .byte 0xff + (" alt_repl_len(num) ") - (" alt_orig_len ")\n"
-#define DISCARD_ENTRY(number) /* rlen <= slen */ \
- " .byte 0xff + (" alt_rlen(number) ") - (" alt_slen ")\n"
-
-#define ALTINSTR_REPLACEMENT(newinstr, feature, number) /* replacement */ \
- b_replacement(number)":\n\t" newinstr "\n" e_replacement(number) ":\n\t"
-
-#define ALTERNATIVE_N(newinstr, feature, number) \
- ".pushsection .altinstructions,\"a\"\n" \
- ALTINSTR_ENTRY(feature, number) \
- ".section .discard,\"a\",@progbits\n" \
- DISCARD_ENTRY(number) \
- ".section .altinstr_replacement, \"ax\"\n" \
- ALTINSTR_REPLACEMENT(newinstr, feature, number) \
- ".popsection\n"
+#define ALTINSTR_REPLACEMENT(newinstr, num) /* replacement */ \
+ alt_repl_s(num)":\n\t" newinstr "\n" alt_repl_e(num) ":\n\t"
/* alternative assembly primitive: */
-#define ALTERNATIVE(oldinstr, newinstr, feature) \
- OLDINSTR(oldinstr) \
- ALTERNATIVE_N(newinstr, feature, 1)
+#define ALTERNATIVE(oldinstr, newinstr, feature) \
+ OLDINSTR(oldinstr) \
+ ".pushsection .altinstructions, \"a\", @progbits\n" \
+ ALTINSTR_ENTRY(feature, 1) \
+ ".section .discard, \"a\", @progbits\n" \
+ DISCARD_ENTRY(1) \
+ ".section .altinstr_replacement, \"ax\", @progbits\n" \
+ ALTINSTR_REPLACEMENT(newinstr, 1) \
+ ".popsection\n"
#define ALTERNATIVE_2(oldinstr, newinstr1, feature1, newinstr2, feature2) \
- ALTERNATIVE(oldinstr, newinstr1, feature1) \
- ALTERNATIVE_N(newinstr2, feature2, 2)
+ OLDINSTR(oldinstr) \
+ ".pushsection .altinstructions, \"a\", @progbits\n" \
+ ALTINSTR_ENTRY(feature1, 1) \
+ ALTINSTR_ENTRY(feature2, 2) \
+ ".section .discard, \"a\", @progbits\n" \
+ DISCARD_ENTRY(1) \
+ DISCARD_ENTRY(2) \
+ ".section .altinstr_replacement, \"ax\", @progbits\n" \
+ ALTINSTR_REPLACEMENT(newinstr1, 1) \
+ ALTINSTR_REPLACEMENT(newinstr2, 2) \
+ ".popsection\n"
/*
* Alternative instructions for different CPU types or capabilities.