Option to set current cert to server certificate.
[openssl.git] / crypto / ppccpuid.pl
1 #!/usr/bin/env perl
2
3 $flavour = shift;
4
5 $0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
6 ( $xlate="${dir}ppc-xlate.pl" and -f $xlate ) or
7 ( $xlate="${dir}perlasm/ppc-xlate.pl" and -f $xlate) or
8 die "can't locate ppc-xlate.pl";
9
10 open STDOUT,"| $^X $xlate $flavour ".shift || die "can't call $xlate: $!";
11
12 if ($flavour=~/64/) {
13     $CMPLI="cmpldi";
14     $SHRLI="srdi";
15     $SIGNX="extsw";
16 } else {
17     $CMPLI="cmplwi";
18     $SHRLI="srwi";
19     $SIGNX="mr";
20 }
21
22 $code=<<___;
23 .machine        "any"
24 .text
25
26 .globl  .OPENSSL_ppc64_probe
27 .align  4
28 .OPENSSL_ppc64_probe:
29         fcfid   f1,f1
30         extrdi  r0,r0,32,0
31         blr
32         .long   0
33         .byte   0,12,0x14,0,0,0,0,0
34 .size   .OPENSSL_ppc64_probe,.-.OPENSSL_ppc64_probe
35
36 .globl  .OPENSSL_altivec_probe
37 .align  4
38 .OPENSSL_altivec_probe:
39         .long   0x10000484      # vor   v0,v0,v0
40         blr
41         .long   0
42         .byte   0,12,0x14,0,0,0,0,0
43 .size   .OPENSSL_altivec_probe,.-..OPENSSL_altivec_probe
44
45 .globl  .OPENSSL_wipe_cpu
46 .align  4
47 .OPENSSL_wipe_cpu:
48         xor     r0,r0,r0
49         fmr     f0,f31
50         fmr     f1,f31
51         fmr     f2,f31
52         mr      r3,r1
53         fmr     f3,f31
54         xor     r4,r4,r4
55         fmr     f4,f31
56         xor     r5,r5,r5
57         fmr     f5,f31
58         xor     r6,r6,r6
59         fmr     f6,f31
60         xor     r7,r7,r7
61         fmr     f7,f31
62         xor     r8,r8,r8
63         fmr     f8,f31
64         xor     r9,r9,r9
65         fmr     f9,f31
66         xor     r10,r10,r10
67         fmr     f10,f31
68         xor     r11,r11,r11
69         fmr     f11,f31
70         xor     r12,r12,r12
71         fmr     f12,f31
72         fmr     f13,f31
73         blr
74         .long   0
75         .byte   0,12,0x14,0,0,0,0,0
76 .size   .OPENSSL_wipe_cpu,.-.OPENSSL_wipe_cpu
77
78 .globl  .OPENSSL_atomic_add
79 .align  4
80 .OPENSSL_atomic_add:
81 Ladd:   lwarx   r5,0,r3
82         add     r0,r4,r5
83         stwcx.  r0,0,r3
84         bne-    Ladd
85         $SIGNX  r3,r0
86         blr
87         .long   0
88         .byte   0,12,0x14,0,0,0,2,0
89         .long   0
90 .size   .OPENSSL_atomic_add,.-.OPENSSL_atomic_add
91
92 .globl  .OPENSSL_rdtsc
93 .align  4
94 .OPENSSL_rdtsc:
95         mftb    r3
96         mftbu   r4
97         blr
98         .long   0
99         .byte   0,12,0x14,0,0,0,0,0
100 .size   .OPENSSL_rdtsc,.-.OPENSSL_rdtsc
101
102 .globl  .OPENSSL_cleanse
103 .align  4
104 .OPENSSL_cleanse:
105         $CMPLI  r4,7
106         li      r0,0
107         bge     Lot
108         $CMPLI  r4,0
109         beqlr-
110 Little: mtctr   r4
111         stb     r0,0(r3)
112         addi    r3,r3,1
113         bdnz    \$-8
114         blr
115 Lot:    andi.   r5,r3,3
116         beq     Laligned
117         stb     r0,0(r3)
118         subi    r4,r4,1
119         addi    r3,r3,1
120         b       Lot
121 Laligned:
122         $SHRLI  r5,r4,2
123         mtctr   r5
124         stw     r0,0(r3)
125         addi    r3,r3,4
126         bdnz    \$-8
127         andi.   r4,r4,3
128         bne     Little
129         blr
130         .long   0
131         .byte   0,12,0x14,0,0,0,2,0
132         .long   0
133 .size   .OPENSSL_cleanse,.-.OPENSSL_cleanse
134 ___
135 {
136 my ($out,$cnt,$max)=("r3","r4","r5");
137 my ($tick,$lasttick)=("r6","r7");
138 my ($diff,$lastdiff)=("r8","r9");
139
140 $code.=<<___;
141 .globl  .OPENSSL_instrument_bus
142 .align  4
143 .OPENSSL_instrument_bus:
144         mtctr   $cnt
145
146         mftb    $lasttick               # collect 1st tick
147         li      $diff,0
148
149         dcbf    0,$out                  # flush cache line
150         lwarx   $tick,0,$out            # load and lock
151         add     $tick,$tick,$diff
152         stwcx.  $tick,0,$out
153         stwx    $tick,0,$out
154
155 Loop:   mftb    $tick
156         sub     $diff,$tick,$lasttick
157         mr      $lasttick,$tick
158         dcbf    0,$out                  # flush cache line
159         lwarx   $tick,0,$out            # load and lock
160         add     $tick,$tick,$diff
161         stwcx.  $tick,0,$out
162         stwx    $tick,0,$out
163         addi    $out,$out,4             # ++$out
164         bdnz    Loop
165
166         mr      r3,$cnt
167         blr
168         .long   0
169         .byte   0,12,0x14,0,0,0,2,0
170         .long   0
171 .size   .OPENSSL_instrument_bus,.-.OPENSSL_instrument_bus
172
173 .globl  .OPENSSL_instrument_bus2
174 .align  4
175 .OPENSSL_instrument_bus2:
176         mr      r0,$cnt
177         slwi    $cnt,$cnt,2
178
179         mftb    $lasttick               # collect 1st tick
180         li      $diff,0
181
182         dcbf    0,$out                  # flush cache line
183         lwarx   $tick,0,$out            # load and lock
184         add     $tick,$tick,$diff
185         stwcx.  $tick,0,$out
186         stwx    $tick,0,$out
187
188         mftb    $tick                   # collect 1st diff
189         sub     $diff,$tick,$lasttick
190         mr      $lasttick,$tick
191         mr      $lastdiff,$diff
192 Loop2:
193         dcbf    0,$out                  # flush cache line
194         lwarx   $tick,0,$out            # load and lock
195         add     $tick,$tick,$diff
196         stwcx.  $tick,0,$out
197         stwx    $tick,0,$out
198
199         addic.  $max,$max,-1
200         beq     Ldone2
201
202         mftb    $tick
203         sub     $diff,$tick,$lasttick
204         mr      $lasttick,$tick
205         cmplw   7,$diff,$lastdiff
206         mr      $lastdiff,$diff
207
208         mfcr    $tick                   # pull cr
209         not     $tick,$tick             # flip bits
210         rlwinm  $tick,$tick,1,29,29     # isolate flipped eq bit and scale
211
212         sub.    $cnt,$cnt,$tick         # conditional --$cnt
213         add     $out,$out,$tick         # conditional ++$out
214         bne     Loop2
215
216 Ldone2:
217         srwi    $cnt,$cnt,2
218         sub     r3,r0,$cnt
219         blr
220         .long   0
221         .byte   0,12,0x14,0,0,0,3,0
222         .long   0
223 .size   .OPENSSL_instrument_bus2,.-.OPENSSL_instrument_bus2
224 ___
225 }
226
227 $code =~ s/\`([^\`]*)\`/eval $1/gem;
228 print $code;
229 close STDOUT;