blob: 651200dc4b6cc5ce9c840e0ae82f28606dfbaf85 [file] [log] [blame]
Joel Stanley42d9dac2017-06-22 13:31:58 +09301From 3e9a825d1a217ab02a24d14e80cad993a864079e Mon Sep 17 00:00:00 2001
2From: Joel Stanley <joel@jms.id.au>
3Date: Thu, 22 Jun 2017 13:43:47 +0930
4Subject: [PATCH] Convert cmpi to cmpwi to fix build for modern binutils
5
6From Linux 80f23935cadb ("powerpc: Convert cmp to cmpd in idle enter sequence"):
7
8 PowerPC's "cmp" instruction has four operands. Normally people write
9 "cmpw" or "cmpd" for the second cmp operand 0 or 1. But, frequently
10 people forget, and write "cmp" with just three operands.
11
12 With older binutils this is silently accepted as if this was "cmpw",
13 while often "cmpd" is wanted. With newer binutils GAS will complain
14 about this for 64-bit code. For 32-bit code it still silently assumes
15 "cmpw" is what is meant.
16
17 In this instance the code comes directly from ISA v2.07, including the
18 cmp, but cmpd is correct. Backport to stable so that new toolchains can
19 build old kernels.
20
21This is change is a noop with the existing toolchain. We change from
22implicitly generating the cmpwi to explicitly stating in for
23compatibility with newer toolchains.
24
25With gcc 4.9.3, binutils 2.25.2:
26
27 $ cat asm-test.S
28 .text
29
30 .global test
31 cmpi 0, 8, 1
32 $ powerpc64-linux-gcc -c asm-test.S
33 $ objdump -d asm-test.o
34 0000000000000000 <.text>:
35 2c 08 00 01 cmpwi r8,1
36
37Old compiler, updated instruction:
38
39 $ cat asm-test.S
40 .text
41
42 .global test
43 cmpwi 0, 8, 1
44 $ powerpc64-linux-gcc -c asm-test.S
45 $ objdump -d asm-test.o
46 0000000000000000 <.text>:
47 2c 08 00 01 cmpwi r8,1
48
49And then the new toolchain (gcc 6.3.0, binutils 2.28) with the updated
50asm:
51
52 $ cat asm-test.S
53 .text
54
55 .global test
56 cmpwi 0, 8, 1
57 $ powerpc64-linux-gnu-gcc -c asm-test.S
58 $ objdump -d asm-test.o
59 0000000000000000 <.text>:
60 2c 08 00 01 cmpwi r8,1
61
62Change-Id: I878ab3596f54c221879945944f2dfbf053427026
63Signed-off-by: Joel Stanley <joel@jms.id.au>
64Signed-off-by: Joel Stanley <joel.stanley@au1.ibm.com>
65---
66 src/kernel/start.S | 34 +++++++++++++++++-----------------
67 src/runtime/rt_start.S | 2 +-
68 2 files changed, 18 insertions(+), 18 deletions(-)
69
70diff --git a/src/kernel/start.S b/src/kernel/start.S
71index 6474a2ced794..5015b652e407 100644
72--- a/src/kernel/start.S
73+++ b/src/kernel/start.S
74@@ -199,7 +199,7 @@ UNIMPL_INTERRUPT(hype_decrementer, 0x980)
75 ;//
76 .org _start + 0xC00
77 intvect_system_call_fast:
78- cmpi cr0, r3, 0x0800
79+ cmpwi cr0, r3, 0x0800
80 bge cr0, system_call_fast_path
81 STD_INTERRUPT(system_call, 0xC08)
82
83@@ -292,7 +292,7 @@ _other_thread_spinlock:
84 1:
85 ld r3, 0(r2)
86 ;// Loop until value is 1...
87- cmpi cr0, r3, 1
88+ cmpwi cr0, r3, 1
89 beq _other_thread_spinlock_complete
90 or 1,1,1 ;// Lower thread priority.
91 b 1b
92@@ -307,12 +307,12 @@ _other_thread_spinlock_complete:
93 extrwi r1, r1, 3, 19
94 sldi r1, r1, 3
95 ldx r2, r1, r2 ;// Dereference to get on-node CPUs array.
96- cmpi cr0, r2, 0 ;// Check for NULL node array.
97+ cmpwi cr0, r2, 0 ;// Check for NULL node array.
98 beq- 1f
99 mfspr r1, PIR ;// Extract on-node CPU id.
100 clrlslwi r1, r1, 22, 3
101 ldx r3, r1, r2 ;// Load CPU object.
102- cmpi cr0, r3, 0 ;// Check for NULL CPU object.
103+ cmpwi cr0, r3, 0 ;// Check for NULL CPU object.
104 beq- 1f
105 ld r1, CPU_KERNEL_STACK(r3) ;// Load initial stack.
106
107@@ -388,7 +388,7 @@ kernel_save_task:
108 std r31, TASK_GPR_31(r1) ;// Save GPR31
109
110 ld r2, TASK_FP_CONTEXT(r1) ;// Load FP Context pointer.
111- cmpi cr0, r2, 0
112+ cmpwi cr0, r2, 0
113 bne- cr0, 1f ;// Jump to FP-save if != NULL.
114 2:
115
116@@ -470,7 +470,7 @@ kernel_dispatch_task:
117
118 ;// Check if FP enabled, load context.
119 ld r2, TASK_FP_CONTEXT(r1)
120- cmpi cr0, r2, 0
121+ cmpwi cr0, r2, 0
122 bne- 1f
123 2:
124 ;// Restore GPRs from context.
125@@ -587,7 +587,7 @@ intvect_system_reset:
126 lis r2, kernel_other_thread_spinlock@h
127 ori r2, r2, kernel_other_thread_spinlock@l
128 ld r2, 0(r2)
129- cmpi cr0, r2, 0
130+ cmpwi cr0, r2, 0
131 beq- _start
132
133 ;// Get CPU object from thread ID, check for NULL which implies not
134@@ -598,12 +598,12 @@ intvect_system_reset:
135 extrwi r1, r1, 3, 19
136 sldi r1, r1, 3
137 ldx r2, r1, r2 ;// Dereference to get on-node CPUs array.
138- cmpi cr0, r2, 0 ;// Check for NULL node array.
139+ cmpwi cr0, r2, 0 ;// Check for NULL node array.
140 beq- _start
141 mfspr r1, PIR ;// Extract on-node CPU id.
142 clrlslwi r1, r1, 22, 3
143 ldx r2, r1, r2 ;// Load CPU object.
144- cmpi cr0, r2, 0 ;// Check for NULL CPU object.
145+ cmpwi cr0, r2, 0 ;// Check for NULL CPU object.
146 beq- _start
147
148 ;// Check for inactive CPU.
149@@ -617,13 +617,13 @@ intvect_system_reset:
150 mfsrr1 r2
151 extrdi r2, r2, 3, 42
152 ;// Check for decrementer (bits = 011).
153- cmpi cr0, r2, 0x3
154+ cmpwi cr0, r2, 0x3
155 beq+ intvect_system_reset_decrementer
156 ;// Check for external interrupt (bits = 010).
157- cmpi cr0, r2, 0x4
158+ cmpwi cr0, r2, 0x4
159 beq+ intvect_system_reset_external
160 ;// Check for HMI (bits = 101).
161- cmpi cr0, r2, 0x5
162+ cmpwi cr0, r2, 0x5
163 beq+ 1f ;// Unable to handle HMI, jump to 'unknown reason'.
164
165 1: ;// Unknown reason, call as unhandled_exception.
166@@ -721,14 +721,14 @@ system_call_fast_path:
167 b 1f ;// Jump to exit point.
168 ;// Check if this is HMER write (0x801).
169 2:
170- cmpi cr0, r3, 0x801
171+ cmpwi cr0, r3, 0x801
172 bne cr0, 3f
173 mtspr HMER, r4
174 li r3, 0
175 b 1f ;// Jump to exit point.
176 ;// Check if this is SCRATCH read (0x802).
177 3:
178- cmpi cr0, r3, 0x802
179+ cmpwi cr0, r3, 0x802
180 bne cr0, 4f
181 ;// Check for being on master processor.
182 mfsprg3 r6 ;// Get task structure.
183@@ -755,7 +755,7 @@ system_call_fast_path:
184 b intvect_system_call
185 ;// Check if this is SCRATCH write (0x803).
186 4:
187- cmpi cr0, r3, 0x803
188+ cmpwi cr0, r3, 0x803
189 bne cr0, 5f
190 ;// Check for master processor.
191 mfsprg3 r6 ;// Get task structure.
192@@ -770,7 +770,7 @@ system_call_fast_path:
193 b 1f ;// Jump to exit point.
194 ;// Check if this is PVR read (0x804).
195 5:
196- cmpi cr0, r3, 0x804
197+ cmpwi cr0, r3, 0x804
198 bne cr0, 6f
199 mfspr r3, PVR
200 b 1f ;// Jump to exit point.
201@@ -800,7 +800,7 @@ system_call_fast_path:
202 .global userspace_task_entry
203 userspace_task_entry:
204 ;// Skip stack frame if GPR1 == NULL.
205- cmpi cr0, r1, 0
206+ cmpwi cr0, r1, 0
207 beq- 1f
208 ;// Create frame.
209 ;// NULL back-chain + 48 bytes + quad-word alignment. See ABI.
210diff --git a/src/runtime/rt_start.S b/src/runtime/rt_start.S
211index d69184aef29f..821e9f956b8e 100644
212--- a/src/runtime/rt_start.S
213+++ b/src/runtime/rt_start.S
214@@ -47,7 +47,7 @@ _init:
215
216 ld r8, 0(r10) # Get count of relocations.
217
218- cmpi cr0, r8, 0 # Perform relocations (if any).
219+ cmpwi cr0, r8, 0 # Perform relocations (if any).
220 beq 2f
221 mtctr r8
222 1:
223--
2242.13.1
225