1 From foo@baz Wed May 23 19:42:20 CEST 2018
2 From: Martin Schwidefsky <schwidefsky@de.ibm.com>
3 Date: Wed, 23 May 2018 18:21:28 +0200
4 Subject: s390: add assembler macros for CPU alternatives
5 To: stable@vger.kernel.org
6 Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
7 Message-ID: <1527092496-24207-2-git-send-email-schwidefsky@de.ibm.com>
9 From: Martin Schwidefsky <schwidefsky@de.ibm.com>
11 [ Upstream commit fba9eb7946251d6e420df3bdf7bc45195be7be9a ]
13 Add a header with macros usable in assembler files to emit alternative
14 code sequences. It works analog to the alternatives for inline assmeblies
15 in C files, with the same restrictions and capabilities.
18 ALTERNATIVE "<default instructions sequence>", \
19 "<alternative instructions sequence>", \
23 ALTERNATIVE_2 "<default instructions sequence>", \
24 "<alternative instructions sqeuence #1>", \
26 "<alternative instructions sqeuence #2>", \
29 Reviewed-by: Vasily Gorbik <gor@linux.vnet.ibm.com>
30 Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
31 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
33 arch/s390/include/asm/alternative-asm.h | 108 ++++++++++++++++++++++++++++++++
34 1 file changed, 108 insertions(+)
35 create mode 100644 arch/s390/include/asm/alternative-asm.h
38 +++ b/arch/s390/include/asm/alternative-asm.h
40 +/* SPDX-License-Identifier: GPL-2.0 */
41 +#ifndef _ASM_S390_ALTERNATIVE_ASM_H
42 +#define _ASM_S390_ALTERNATIVE_ASM_H
47 + * Check the length of an instruction sequence. The length may not be larger
48 + * than 254 bytes and it has to be divisible by 2.
50 +.macro alt_len_check start,end
51 + .if ( \end - \start ) > 254
52 + .error "cpu alternatives does not support instructions blocks > 254 bytes\n"
54 + .if ( \end - \start ) % 2
55 + .error "cpu alternatives instructions length is odd\n"
60 + * Issue one struct alt_instr descriptor entry (need to put it into
61 + * the section .altinstructions, see below). This entry contains
62 + * enough information for the alternatives patching code to patch an
63 + * instruction. See apply_alternatives().
65 +.macro alt_entry orig_start, orig_end, alt_start, alt_end, feature
66 + .long \orig_start - .
67 + .long \alt_start - .
69 + .byte \orig_end - \orig_start
70 + .byte \alt_end - \alt_start
74 + * Fill up @bytes with nops. The macro emits 6-byte nop instructions
75 + * for the bulk of the area, possibly followed by a 4-byte and/or
76 + * a 2-byte nop if the size of the area is not divisible by 6.
78 +.macro alt_pad_fill bytes
79 + .fill ( \bytes ) / 6, 6, 0xc0040000
80 + .fill ( \bytes ) % 6 / 4, 4, 0x47000000
81 + .fill ( \bytes ) % 6 % 4 / 2, 2, 0x0700
85 + * Fill up @bytes with nops. If the number of bytes is larger
86 + * than 6, emit a jg instruction to branch over all nops, then
87 + * fill an area of size (@bytes - 6) with nop instructions.
93 + alt_pad_fill \bytes - 6
101 + * Define an alternative between two instructions. If @feature is
102 + * present, early code in apply_alternatives() replaces @oldinstr with
103 + * @newinstr. ".skip" directive takes care of proper instruction padding
104 + * in case @newinstr is longer than @oldinstr.
106 +.macro ALTERNATIVE oldinstr, newinstr, feature
107 + .pushsection .altinstr_replacement,"ax"
111 +773: alt_len_check 770b, 771b
112 + alt_len_check 772b, 773b
113 + alt_pad ( ( 771b - 770b ) - ( 773b - 772b ) )
114 +774: .pushsection .altinstructions,"a"
115 + alt_entry 772b, 774b, 770b, 771b, \feature
120 + * Define an alternative between two instructions. If @feature is
121 + * present, early code in apply_alternatives() replaces @oldinstr with
122 + * @newinstr. ".skip" directive takes care of proper instruction padding
123 + * in case @newinstr is longer than @oldinstr.
125 +.macro ALTERNATIVE_2 oldinstr, newinstr1, feature1, newinstr2, feature2
126 + .pushsection .altinstr_replacement,"ax"
131 +774: alt_len_check 770b, 771b
132 + alt_len_check 771b, 772b
133 + alt_len_check 773b, 774b
134 + .if ( 771b - 770b > 772b - 771b )
135 + alt_pad ( ( 771b - 770b ) - ( 774b - 773b ) )
137 + alt_pad ( ( 772b - 771b ) - ( 774b - 773b ) )
139 +775: .pushsection .altinstructions,"a"
140 + alt_entry 773b, 775b, 770b, 771b,\feature1
141 + alt_entry 773b, 775b, 771b, 772b,\feature2
145 +#endif /* __ASSEMBLY__ */
147 +#endif /* _ASM_S390_ALTERNATIVE_ASM_H */