1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_S390_ALTERNATIVE_H
3 #define _ASM_S390_ALTERNATIVE_H
7 #include <linux/types.h>
8 #include <linux/stddef.h>
9 #include <linux/stringify.h>
12 s32 instr_offset; /* original instruction */
13 s32 repl_offset; /* offset to replacement instruction */
14 u16 facility; /* facility bit set for replacement */
15 u8 instrlen; /* length of original instruction */
18 void apply_alternative_instructions(void);
19 void apply_alternatives(struct alt_instr *start, struct alt_instr *end);
22 * +---------------------------------+
25 * +---------------------------------+
27 * .altinstr_replacement section
28 * +---------------------------------+
30 * | alternative instr 1 |
31 * +---------------------------------+
33 * | alternative instr 2 |
34 * +---------------------------------+
36 * .altinstructions section
37 * +---------------------------------+
38 * | alt_instr entries for each |
39 * | alternative instr |
40 * +---------------------------------+
43 #define b_altinstr(num) "664"#num
44 #define e_altinstr(num) "665"#num
45 #define oldinstr_len "662b-661b"
46 #define altinstr_len(num) e_altinstr(num)"b-"b_altinstr(num)"b"
48 #define OLDINSTR(oldinstr) \
49 "661:\n\t" oldinstr "\n662:\n"
51 #define ALTINSTR_ENTRY(facility, num) \
52 "\t.long 661b - .\n" /* old instruction */ \
53 "\t.long " b_altinstr(num)"b - .\n" /* alt instruction */ \
54 "\t.word " __stringify(facility) "\n" /* facility bit */ \
55 "\t.byte " oldinstr_len "\n" /* instruction len */ \
56 "\t.org . - (" oldinstr_len ") + (" altinstr_len(num) ")\n" \
57 "\t.org . - (" altinstr_len(num) ") + (" oldinstr_len ")\n"
59 #define ALTINSTR_REPLACEMENT(altinstr, num) /* replacement */ \
60 b_altinstr(num)":\n\t" altinstr "\n" e_altinstr(num) ":\n"
62 /* alternative assembly primitive: */
63 #define ALTERNATIVE(oldinstr, altinstr, facility) \
64 ".pushsection .altinstr_replacement, \"ax\"\n" \
65 ALTINSTR_REPLACEMENT(altinstr, 1) \
68 ".pushsection .altinstructions,\"a\"\n" \
69 ALTINSTR_ENTRY(facility, 1) \
72 #define ALTERNATIVE_2(oldinstr, altinstr1, facility1, altinstr2, facility2)\
73 ".pushsection .altinstr_replacement, \"ax\"\n" \
74 ALTINSTR_REPLACEMENT(altinstr1, 1) \
75 ALTINSTR_REPLACEMENT(altinstr2, 2) \
78 ".pushsection .altinstructions,\"a\"\n" \
79 ALTINSTR_ENTRY(facility1, 1) \
80 ALTINSTR_ENTRY(facility2, 2) \
84 * Alternative instructions for different CPU types or capabilities.
86 * This allows to use optimized instructions even on generic binary
89 * oldinstr is padded with jump and nops at compile time if altinstr is
90 * longer. altinstr is padded with jump and nops at run-time during patching.
92 * For non barrier like inlines please define new variants
93 * without volatile and memory clobber.
95 #define alternative(oldinstr, altinstr, facility) \
96 asm_inline volatile(ALTERNATIVE(oldinstr, altinstr, facility) : : : "memory")
98 #define alternative_2(oldinstr, altinstr1, facility1, altinstr2, facility2) \
99 asm_inline volatile(ALTERNATIVE_2(oldinstr, altinstr1, facility1, \
100 altinstr2, facility2) ::: "memory")
102 /* Alternative inline assembly with input. */
103 #define alternative_input(oldinstr, newinstr, feature, input...) \
104 asm_inline volatile (ALTERNATIVE(oldinstr, newinstr, feature) \
107 /* Like alternative_input, but with a single output argument */
108 #define alternative_io(oldinstr, altinstr, facility, output, input...) \
109 asm_inline volatile(ALTERNATIVE(oldinstr, altinstr, facility) \
112 /* Use this macro if more than one output parameter is needed. */
113 #define ASM_OUTPUT2(a...) a
115 /* Use this macro if clobbers are needed without inputs. */
116 #define ASM_NO_INPUT_CLOBBER(clobber...) : clobber
118 #endif /* __ASSEMBLY__ */
120 #endif /* _ASM_S390_ALTERNATIVE_H */