]>
Commit | Line | Data |
---|---|---|
e0a65194 RS |
1 | #! /usr/bin/env perl |
2 | # Copyright 2007-2016 The OpenSSL Project Authors. All Rights Reserved. | |
3 | # | |
4 | # Licensed under the OpenSSL license (the "License"). You may not use | |
5 | # this file except in compliance with the License. You can obtain a copy | |
6 | # in the file LICENSE in the source distribution or at | |
7 | # https://www.openssl.org/source/license.html | |
8 | ||
9c9c83cc | 9 | |
addd641f | 10 | $flavour = shift; |
9c9c83cc AP |
11 | |
12 | $0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1; | |
13 | ( $xlate="${dir}ppc-xlate.pl" and -f $xlate ) or | |
14 | ( $xlate="${dir}perlasm/ppc-xlate.pl" and -f $xlate) or | |
15 | die "can't locate ppc-xlate.pl"; | |
16 | ||
addd641f | 17 | open STDOUT,"| $^X $xlate $flavour ".shift || die "can't call $xlate: $!"; |
9c9c83cc | 18 | |
addd641f | 19 | if ($flavour=~/64/) { |
9c9c83cc AP |
20 | $CMPLI="cmpldi"; |
21 | $SHRLI="srdi"; | |
22 | $SIGNX="extsw"; | |
23 | } else { | |
24 | $CMPLI="cmplwi"; | |
25 | $SHRLI="srwi"; | |
26 | $SIGNX="mr"; | |
27 | } | |
28 | ||
29 | $code=<<___; | |
492279f6 | 30 | .machine "any" |
9c9c83cc AP |
31 | .text |
32 | ||
81eae077 AP |
33 | .globl .OPENSSL_fpu_probe |
34 | .align 4 | |
35 | .OPENSSL_fpu_probe: | |
36 | fmr f0,f0 | |
37 | blr | |
38 | .long 0 | |
39 | .byte 0,12,0x14,0,0,0,0,0 | |
40 | .size .OPENSSL_fpu_probe,.-.OPENSSL_fpu_probe | |
b4b48a10 | 41 | .globl .OPENSSL_ppc64_probe |
9c9c83cc | 42 | .align 4 |
b4b48a10 AP |
43 | .OPENSSL_ppc64_probe: |
44 | fcfid f1,f1 | |
45 | extrdi r0,r0,32,0 | |
9c9c83cc | 46 | blr |
67150340 AP |
47 | .long 0 |
48 | .byte 0,12,0x14,0,0,0,0,0 | |
d6019e16 | 49 | .size .OPENSSL_ppc64_probe,.-.OPENSSL_ppc64_probe |
9c9c83cc | 50 | |
6415dd7b AP |
51 | .globl .OPENSSL_altivec_probe |
52 | .align 4 | |
53 | .OPENSSL_altivec_probe: | |
54 | .long 0x10000484 # vor v0,v0,v0 | |
55 | blr | |
67150340 AP |
56 | .long 0 |
57 | .byte 0,12,0x14,0,0,0,0,0 | |
d6019e16 | 58 | .size .OPENSSL_altivec_probe,.-..OPENSSL_altivec_probe |
6415dd7b | 59 | |
de51e830 AP |
60 | .globl .OPENSSL_crypto207_probe |
61 | .align 4 | |
d86689e1 | 62 | .OPENSSL_crypto207_probe: |
de51e830 AP |
63 | lvx_u v0,0,r1 |
64 | vcipher v0,v0,v0 | |
65 | blr | |
66 | .long 0 | |
67 | .byte 0,12,0x14,0,0,0,0,0 | |
68 | .size .OPENSSL_crypto207_probe,.-.OPENSSL_crypto207_probe | |
69 | ||
e0e53282 AP |
70 | .globl .OPENSSL_madd300_probe |
71 | .align 4 | |
72 | .OPENSSL_madd300_probe: | |
73 | xor r0,r0,r0 | |
74 | maddld r3,r0,r0,r0 | |
75 | maddhdu r3,r0,r0,r0 | |
76 | blr | |
77 | .long 0 | |
78 | .byte 0,12,0x14,0,0,0,0,0 | |
79 | ||
9c9c83cc AP |
80 | .globl .OPENSSL_wipe_cpu |
81 | .align 4 | |
82 | .OPENSSL_wipe_cpu: | |
83 | xor r0,r0,r0 | |
78a533cb AP |
84 | fmr f0,f31 |
85 | fmr f1,f31 | |
86 | fmr f2,f31 | |
9c9c83cc | 87 | mr r3,r1 |
78a533cb | 88 | fmr f3,f31 |
9c9c83cc | 89 | xor r4,r4,r4 |
78a533cb | 90 | fmr f4,f31 |
9c9c83cc | 91 | xor r5,r5,r5 |
78a533cb | 92 | fmr f5,f31 |
9c9c83cc | 93 | xor r6,r6,r6 |
78a533cb | 94 | fmr f6,f31 |
9c9c83cc | 95 | xor r7,r7,r7 |
78a533cb | 96 | fmr f7,f31 |
9c9c83cc | 97 | xor r8,r8,r8 |
78a533cb | 98 | fmr f8,f31 |
9c9c83cc | 99 | xor r9,r9,r9 |
78a533cb | 100 | fmr f9,f31 |
9c9c83cc | 101 | xor r10,r10,r10 |
78a533cb | 102 | fmr f10,f31 |
9c9c83cc | 103 | xor r11,r11,r11 |
78a533cb | 104 | fmr f11,f31 |
9c9c83cc | 105 | xor r12,r12,r12 |
78a533cb AP |
106 | fmr f12,f31 |
107 | fmr f13,f31 | |
9c9c83cc | 108 | blr |
67150340 AP |
109 | .long 0 |
110 | .byte 0,12,0x14,0,0,0,0,0 | |
d6019e16 | 111 | .size .OPENSSL_wipe_cpu,.-.OPENSSL_wipe_cpu |
9c9c83cc AP |
112 | |
113 | .globl .OPENSSL_atomic_add | |
114 | .align 4 | |
115 | .OPENSSL_atomic_add: | |
5fabb88a | 116 | Ladd: lwarx r5,0,r3 |
9c9c83cc AP |
117 | add r0,r4,r5 |
118 | stwcx. r0,0,r3 | |
5fabb88a | 119 | bne- Ladd |
9c9c83cc AP |
120 | $SIGNX r3,r0 |
121 | blr | |
67150340 AP |
122 | .long 0 |
123 | .byte 0,12,0x14,0,0,0,2,0 | |
124 | .long 0 | |
d6019e16 | 125 | .size .OPENSSL_atomic_add,.-.OPENSSL_atomic_add |
9c9c83cc AP |
126 | |
127 | .globl .OPENSSL_rdtsc | |
128 | .align 4 | |
129 | .OPENSSL_rdtsc: | |
81eae077 AP |
130 | ___ |
131 | $code.=<<___ if ($flavour =~ /64/); | |
132 | mftb r3 | |
133 | ___ | |
134 | $code.=<<___ if ($flavour !~ /64/); | |
135 | Loop_rdtsc: | |
136 | mftbu r5 | |
9c9c83cc AP |
137 | mftb r3 |
138 | mftbu r4 | |
81eae077 AP |
139 | cmplw r4,r5 |
140 | bne Loop_rdtsc | |
141 | ___ | |
142 | $code.=<<___; | |
9c9c83cc | 143 | blr |
67150340 AP |
144 | .long 0 |
145 | .byte 0,12,0x14,0,0,0,0,0 | |
d6019e16 | 146 | .size .OPENSSL_rdtsc,.-.OPENSSL_rdtsc |
9c9c83cc AP |
147 | |
148 | .globl .OPENSSL_cleanse | |
149 | .align 4 | |
150 | .OPENSSL_cleanse: | |
151 | $CMPLI r4,7 | |
152 | li r0,0 | |
153 | bge Lot | |
7676eebf AP |
154 | $CMPLI r4,0 |
155 | beqlr- | |
9c9c83cc AP |
156 | Little: mtctr r4 |
157 | stb r0,0(r3) | |
158 | addi r3,r3,1 | |
9474483a | 159 | bdnz \$-8 |
9c9c83cc AP |
160 | blr |
161 | Lot: andi. r5,r3,3 | |
162 | beq Laligned | |
163 | stb r0,0(r3) | |
164 | subi r4,r4,1 | |
165 | addi r3,r3,1 | |
166 | b Lot | |
167 | Laligned: | |
168 | $SHRLI r5,r4,2 | |
169 | mtctr r5 | |
170 | stw r0,0(r3) | |
171 | addi r3,r3,4 | |
9474483a | 172 | bdnz \$-8 |
9c9c83cc AP |
173 | andi. r4,r4,3 |
174 | bne Little | |
175 | blr | |
67150340 AP |
176 | .long 0 |
177 | .byte 0,12,0x14,0,0,0,2,0 | |
178 | .long 0 | |
d6019e16 | 179 | .size .OPENSSL_cleanse,.-.OPENSSL_cleanse |
e33826f0 AP |
180 | |
181 | globl .CRYPTO_memcmp | |
182 | .align 4 | |
183 | .CRYPTO_memcmp: | |
184 | $CMPLI r5,0 | |
185 | li r0,0 | |
186 | beq Lno_data | |
187 | mtctr r5 | |
188 | Loop_cmp: | |
189 | lbz r6,0(r3) | |
190 | addi r3,r3,1 | |
191 | lbz r7,0(r4) | |
192 | addi r4,r4,1 | |
193 | xor r6,r6,r7 | |
194 | or r0,r0,r6 | |
195 | bdnz Loop_cmp | |
196 | ||
197 | Lno_data: | |
198 | li r3,0 | |
199 | sub r3,r3,r0 | |
200 | extrwi r3,r3,1,0 | |
201 | blr | |
202 | .long 0 | |
203 | .byte 0,12,0x14,0,0,0,3,0 | |
204 | .long 0 | |
205 | .size .CRYPTO_memcmp,.-.CRYPTO_memcmp | |
9c9c83cc | 206 | ___ |
5fabb88a AP |
207 | { |
208 | my ($out,$cnt,$max)=("r3","r4","r5"); | |
209 | my ($tick,$lasttick)=("r6","r7"); | |
210 | my ($diff,$lastdiff)=("r8","r9"); | |
211 | ||
212 | $code.=<<___; | |
213 | .globl .OPENSSL_instrument_bus | |
214 | .align 4 | |
215 | .OPENSSL_instrument_bus: | |
216 | mtctr $cnt | |
217 | ||
218 | mftb $lasttick # collect 1st tick | |
219 | li $diff,0 | |
220 | ||
221 | dcbf 0,$out # flush cache line | |
222 | lwarx $tick,0,$out # load and lock | |
223 | add $tick,$tick,$diff | |
224 | stwcx. $tick,0,$out | |
225 | stwx $tick,0,$out | |
226 | ||
227 | Loop: mftb $tick | |
228 | sub $diff,$tick,$lasttick | |
229 | mr $lasttick,$tick | |
230 | dcbf 0,$out # flush cache line | |
231 | lwarx $tick,0,$out # load and lock | |
232 | add $tick,$tick,$diff | |
233 | stwcx. $tick,0,$out | |
234 | stwx $tick,0,$out | |
235 | addi $out,$out,4 # ++$out | |
236 | bdnz Loop | |
237 | ||
238 | mr r3,$cnt | |
239 | blr | |
67150340 AP |
240 | .long 0 |
241 | .byte 0,12,0x14,0,0,0,2,0 | |
242 | .long 0 | |
d6019e16 | 243 | .size .OPENSSL_instrument_bus,.-.OPENSSL_instrument_bus |
5fabb88a AP |
244 | |
245 | .globl .OPENSSL_instrument_bus2 | |
246 | .align 4 | |
247 | .OPENSSL_instrument_bus2: | |
248 | mr r0,$cnt | |
249 | slwi $cnt,$cnt,2 | |
250 | ||
251 | mftb $lasttick # collect 1st tick | |
252 | li $diff,0 | |
253 | ||
254 | dcbf 0,$out # flush cache line | |
255 | lwarx $tick,0,$out # load and lock | |
256 | add $tick,$tick,$diff | |
257 | stwcx. $tick,0,$out | |
258 | stwx $tick,0,$out | |
259 | ||
260 | mftb $tick # collect 1st diff | |
261 | sub $diff,$tick,$lasttick | |
262 | mr $lasttick,$tick | |
263 | mr $lastdiff,$diff | |
264 | Loop2: | |
265 | dcbf 0,$out # flush cache line | |
266 | lwarx $tick,0,$out # load and lock | |
267 | add $tick,$tick,$diff | |
268 | stwcx. $tick,0,$out | |
269 | stwx $tick,0,$out | |
270 | ||
271 | addic. $max,$max,-1 | |
272 | beq Ldone2 | |
273 | ||
274 | mftb $tick | |
275 | sub $diff,$tick,$lasttick | |
276 | mr $lasttick,$tick | |
277 | cmplw 7,$diff,$lastdiff | |
278 | mr $lastdiff,$diff | |
279 | ||
280 | mfcr $tick # pull cr | |
281 | not $tick,$tick # flip bits | |
282 | rlwinm $tick,$tick,1,29,29 # isolate flipped eq bit and scale | |
283 | ||
284 | sub. $cnt,$cnt,$tick # conditional --$cnt | |
285 | add $out,$out,$tick # conditional ++$out | |
286 | bne Loop2 | |
287 | ||
288 | Ldone2: | |
289 | srwi $cnt,$cnt,2 | |
290 | sub r3,r0,$cnt | |
291 | blr | |
67150340 AP |
292 | .long 0 |
293 | .byte 0,12,0x14,0,0,0,3,0 | |
294 | .long 0 | |
d6019e16 | 295 | .size .OPENSSL_instrument_bus2,.-.OPENSSL_instrument_bus2 |
5fabb88a AP |
296 | ___ |
297 | } | |
9c9c83cc AP |
298 | |
299 | $code =~ s/\`([^\`]*)\`/eval $1/gem; | |
300 | print $code; | |
301 | close STDOUT; |