|
@@ -5,6 +5,8 @@
|
|
#include <asm/cpucaps.h>
|
|
#include <asm/cpucaps.h>
|
|
#include <asm/insn.h>
|
|
#include <asm/insn.h>
|
|
|
|
|
|
|
|
+#define ARM64_CB_PATCH ARM64_NCAPS
|
|
|
|
+
|
|
#ifndef __ASSEMBLY__
|
|
#ifndef __ASSEMBLY__
|
|
|
|
|
|
#include <linux/init.h>
|
|
#include <linux/init.h>
|
|
@@ -22,12 +24,19 @@ struct alt_instr {
|
|
u8 alt_len; /* size of new instruction(s), <= orig_len */
|
|
u8 alt_len; /* size of new instruction(s), <= orig_len */
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+typedef void (*alternative_cb_t)(struct alt_instr *alt,
|
|
|
|
+ __le32 *origptr, __le32 *updptr, int nr_inst);
|
|
|
|
+
|
|
void __init apply_alternatives_all(void);
|
|
void __init apply_alternatives_all(void);
|
|
void apply_alternatives(void *start, size_t length);
|
|
void apply_alternatives(void *start, size_t length);
|
|
|
|
|
|
-#define ALTINSTR_ENTRY(feature) \
|
|
|
|
|
|
+#define ALTINSTR_ENTRY(feature,cb) \
|
|
" .word 661b - .\n" /* label */ \
|
|
" .word 661b - .\n" /* label */ \
|
|
|
|
+ " .if " __stringify(cb) " == 0\n" \
|
|
" .word 663f - .\n" /* new instruction */ \
|
|
" .word 663f - .\n" /* new instruction */ \
|
|
|
|
+ " .else\n" \
|
|
|
|
+ " .word " __stringify(cb) "- .\n" /* callback */ \
|
|
|
|
+ " .endif\n" \
|
|
" .hword " __stringify(feature) "\n" /* feature bit */ \
|
|
" .hword " __stringify(feature) "\n" /* feature bit */ \
|
|
" .byte 662b-661b\n" /* source len */ \
|
|
" .byte 662b-661b\n" /* source len */ \
|
|
" .byte 664f-663f\n" /* replacement len */
|
|
" .byte 664f-663f\n" /* replacement len */
|
|
@@ -45,15 +54,18 @@ void apply_alternatives(void *start, size_t length);
|
|
* but most assemblers die if insn1 or insn2 have a .inst. This should
|
|
* but most assemblers die if insn1 or insn2 have a .inst. This should
|
|
* be fixed in a binutils release posterior to 2.25.51.0.2 (anything
|
|
* be fixed in a binutils release posterior to 2.25.51.0.2 (anything
|
|
* containing commit 4e4d08cf7399b606 or c1baaddf8861).
|
|
* containing commit 4e4d08cf7399b606 or c1baaddf8861).
|
|
|
|
+ *
|
|
|
|
+ * Alternatives with callbacks do not generate replacement instructions.
|
|
*/
|
|
*/
|
|
-#define __ALTERNATIVE_CFG(oldinstr, newinstr, feature, cfg_enabled) \
|
|
|
|
|
|
+#define __ALTERNATIVE_CFG(oldinstr, newinstr, feature, cfg_enabled, cb) \
|
|
".if "__stringify(cfg_enabled)" == 1\n" \
|
|
".if "__stringify(cfg_enabled)" == 1\n" \
|
|
"661:\n\t" \
|
|
"661:\n\t" \
|
|
oldinstr "\n" \
|
|
oldinstr "\n" \
|
|
"662:\n" \
|
|
"662:\n" \
|
|
".pushsection .altinstructions,\"a\"\n" \
|
|
".pushsection .altinstructions,\"a\"\n" \
|
|
- ALTINSTR_ENTRY(feature) \
|
|
|
|
|
|
+ ALTINSTR_ENTRY(feature,cb) \
|
|
".popsection\n" \
|
|
".popsection\n" \
|
|
|
|
+ " .if " __stringify(cb) " == 0\n" \
|
|
".pushsection .altinstr_replacement, \"a\"\n" \
|
|
".pushsection .altinstr_replacement, \"a\"\n" \
|
|
"663:\n\t" \
|
|
"663:\n\t" \
|
|
newinstr "\n" \
|
|
newinstr "\n" \
|
|
@@ -61,11 +73,17 @@ void apply_alternatives(void *start, size_t length);
|
|
".popsection\n\t" \
|
|
".popsection\n\t" \
|
|
".org . - (664b-663b) + (662b-661b)\n\t" \
|
|
".org . - (664b-663b) + (662b-661b)\n\t" \
|
|
".org . - (662b-661b) + (664b-663b)\n" \
|
|
".org . - (662b-661b) + (664b-663b)\n" \
|
|
|
|
+ ".else\n\t" \
|
|
|
|
+ "663:\n\t" \
|
|
|
|
+ "664:\n\t" \
|
|
|
|
+ ".endif\n" \
|
|
".endif\n"
|
|
".endif\n"
|
|
|
|
|
|
#define _ALTERNATIVE_CFG(oldinstr, newinstr, feature, cfg, ...) \
|
|
#define _ALTERNATIVE_CFG(oldinstr, newinstr, feature, cfg, ...) \
|
|
- __ALTERNATIVE_CFG(oldinstr, newinstr, feature, IS_ENABLED(cfg))
|
|
|
|
|
|
+ __ALTERNATIVE_CFG(oldinstr, newinstr, feature, IS_ENABLED(cfg), 0)
|
|
|
|
|
|
|
|
+#define ALTERNATIVE_CB(oldinstr, cb) \
|
|
|
|
+ __ALTERNATIVE_CFG(oldinstr, "NOT_AN_INSTRUCTION", ARM64_CB_PATCH, 1, cb)
|
|
#else
|
|
#else
|
|
|
|
|
|
#include <asm/assembler.h>
|
|
#include <asm/assembler.h>
|
|
@@ -132,6 +150,14 @@ void apply_alternatives(void *start, size_t length);
|
|
661:
|
|
661:
|
|
.endm
|
|
.endm
|
|
|
|
|
|
|
|
+.macro alternative_cb cb
|
|
|
|
+ .set .Lasm_alt_mode, 0
|
|
|
|
+ .pushsection .altinstructions, "a"
|
|
|
|
+ altinstruction_entry 661f, \cb, ARM64_CB_PATCH, 662f-661f, 0
|
|
|
|
+ .popsection
|
|
|
|
+661:
|
|
|
|
+.endm
|
|
|
|
+
|
|
/*
|
|
/*
|
|
* Provide the other half of the alternative code sequence.
|
|
* Provide the other half of the alternative code sequence.
|
|
*/
|
|
*/
|
|
@@ -157,6 +183,13 @@ void apply_alternatives(void *start, size_t length);
|
|
.org . - (662b-661b) + (664b-663b)
|
|
.org . - (662b-661b) + (664b-663b)
|
|
.endm
|
|
.endm
|
|
|
|
|
|
|
|
+/*
|
|
|
|
+ * Callback-based alternative epilogue
|
|
|
|
+ */
|
|
|
|
+.macro alternative_cb_end
|
|
|
|
+662:
|
|
|
|
+.endm
|
|
|
|
+
|
|
/*
|
|
/*
|
|
* Provides a trivial alternative or default sequence consisting solely
|
|
* Provides a trivial alternative or default sequence consisting solely
|
|
* of NOPs. The number of NOPs is chosen automatically to match the
|
|
* of NOPs. The number of NOPs is chosen automatically to match the
|