Always use TLSv1.0 for record layer version in TLSv1.3
[oweals/openssl.git] / crypto / ppccpuid.pl
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
9
10 $flavour = shift;
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
17 open STDOUT,"| $^X $xlate $flavour ".shift || die "can't call $xlate: $!";
18
19 if ($flavour=~/64/) {
20     $CMPLI="cmpldi";
21     $SHRLI="srdi";
22     $SIGNX="extsw";
23 } else {
24     $CMPLI="cmplwi";
25     $SHRLI="srwi";
26     $SIGNX="mr";
27 }
28
29 $code=<<___;
30 .machine        "any"
31 .text
32
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
41 .globl  .OPENSSL_ppc64_probe
42 .align  4
43 .OPENSSL_ppc64_probe:
44         fcfid   f1,f1
45         extrdi  r0,r0,32,0
46         blr
47         .long   0
48         .byte   0,12,0x14,0,0,0,0,0
49 .size   .OPENSSL_ppc64_probe,.-.OPENSSL_ppc64_probe
50
51 .globl  .OPENSSL_altivec_probe
52 .align  4
53 .OPENSSL_altivec_probe:
54         .long   0x10000484      # vor   v0,v0,v0
55         blr
56         .long   0
57         .byte   0,12,0x14,0,0,0,0,0
58 .size   .OPENSSL_altivec_probe,.-..OPENSSL_altivec_probe
59
60 .globl  .OPENSSL_crypto207_probe
61 .align  4
62 .OPENSSL_crypto207_probe:
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
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
80 .globl  .OPENSSL_wipe_cpu
81 .align  4
82 .OPENSSL_wipe_cpu:
83         xor     r0,r0,r0
84         fmr     f0,f31
85         fmr     f1,f31
86         fmr     f2,f31
87         mr      r3,r1
88         fmr     f3,f31
89         xor     r4,r4,r4
90         fmr     f4,f31
91         xor     r5,r5,r5
92         fmr     f5,f31
93         xor     r6,r6,r6
94         fmr     f6,f31
95         xor     r7,r7,r7
96         fmr     f7,f31
97         xor     r8,r8,r8
98         fmr     f8,f31
99         xor     r9,r9,r9
100         fmr     f9,f31
101         xor     r10,r10,r10
102         fmr     f10,f31
103         xor     r11,r11,r11
104         fmr     f11,f31
105         xor     r12,r12,r12
106         fmr     f12,f31
107         fmr     f13,f31
108         blr
109         .long   0
110         .byte   0,12,0x14,0,0,0,0,0
111 .size   .OPENSSL_wipe_cpu,.-.OPENSSL_wipe_cpu
112
113 .globl  .OPENSSL_atomic_add
114 .align  4
115 .OPENSSL_atomic_add:
116 Ladd:   lwarx   r5,0,r3
117         add     r0,r4,r5
118         stwcx.  r0,0,r3
119         bne-    Ladd
120         $SIGNX  r3,r0
121         blr
122         .long   0
123         .byte   0,12,0x14,0,0,0,2,0
124         .long   0
125 .size   .OPENSSL_atomic_add,.-.OPENSSL_atomic_add
126
127 .globl  .OPENSSL_rdtsc
128 .align  4
129 .OPENSSL_rdtsc:
130 ___
131 $code.=<<___    if ($flavour =~ /64/);
132         mftb    r3
133 ___
134 $code.=<<___    if ($flavour !~ /64/);
135 Loop_rdtsc:
136         mftbu   r5
137         mftb    r3
138         mftbu   r4
139         cmplw   r4,r5
140         bne     Loop_rdtsc
141 ___
142 $code.=<<___;
143         blr
144         .long   0
145         .byte   0,12,0x14,0,0,0,0,0
146 .size   .OPENSSL_rdtsc,.-.OPENSSL_rdtsc
147
148 .globl  .OPENSSL_cleanse
149 .align  4
150 .OPENSSL_cleanse:
151         $CMPLI  r4,7
152         li      r0,0
153         bge     Lot
154         $CMPLI  r4,0
155         beqlr-
156 Little: mtctr   r4
157         stb     r0,0(r3)
158         addi    r3,r3,1
159         bdnz    \$-8
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
172         bdnz    \$-8
173         andi.   r4,r4,3
174         bne     Little
175         blr
176         .long   0
177         .byte   0,12,0x14,0,0,0,2,0
178         .long   0
179 .size   .OPENSSL_cleanse,.-.OPENSSL_cleanse
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
206 ___
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
240         .long   0
241         .byte   0,12,0x14,0,0,0,2,0
242         .long   0
243 .size   .OPENSSL_instrument_bus,.-.OPENSSL_instrument_bus
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
292         .long   0
293         .byte   0,12,0x14,0,0,0,3,0
294         .long   0
295 .size   .OPENSSL_instrument_bus2,.-.OPENSSL_instrument_bus2
296 ___
297 }
298
299 $code =~ s/\`([^\`]*)\`/eval $1/gem;
300 print $code;
301 close STDOUT;