Fix EVP CCM decrypt. Add decrypt support to algorithm test program.
[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
33 .globl  .OPENSSL_altivec_probe
34 .align  4
35 .OPENSSL_altivec_probe:
36         .long   0x10000484      # vor   v0,v0,v0
37         blr
38
39 .globl  .OPENSSL_wipe_cpu
40 .align  4
41 .OPENSSL_wipe_cpu:
42         xor     r0,r0,r0
43         fmr     f0,f31
44         fmr     f1,f31
45         fmr     f2,f31
46         mr      r3,r1
47         fmr     f3,f31
48         xor     r4,r4,r4
49         fmr     f4,f31
50         xor     r5,r5,r5
51         fmr     f5,f31
52         xor     r6,r6,r6
53         fmr     f6,f31
54         xor     r7,r7,r7
55         fmr     f7,f31
56         xor     r8,r8,r8
57         fmr     f8,f31
58         xor     r9,r9,r9
59         fmr     f9,f31
60         xor     r10,r10,r10
61         fmr     f10,f31
62         xor     r11,r11,r11
63         fmr     f11,f31
64         xor     r12,r12,r12
65         fmr     f12,f31
66         fmr     f13,f31
67         blr
68
69 .globl  .OPENSSL_atomic_add
70 .align  4
71 .OPENSSL_atomic_add:
72 Ladd:   lwarx   r5,0,r3
73         add     r0,r4,r5
74         stwcx.  r0,0,r3
75         bne-    Ladd
76         $SIGNX  r3,r0
77         blr
78
79 .globl  .OPENSSL_rdtsc
80 .align  4
81 .OPENSSL_rdtsc:
82         mftb    r3
83         mftbu   r4
84         blr
85
86 .globl  .OPENSSL_cleanse
87 .align  4
88 .OPENSSL_cleanse:
89         $CMPLI  r4,7
90         li      r0,0
91         bge     Lot
92         $CMPLI  r4,0
93         beqlr-
94 Little: mtctr   r4
95         stb     r0,0(r3)
96         addi    r3,r3,1
97         bdnz-   \$-8
98         blr
99 Lot:    andi.   r5,r3,3
100         beq     Laligned
101         stb     r0,0(r3)
102         subi    r4,r4,1
103         addi    r3,r3,1
104         b       Lot
105 Laligned:
106         $SHRLI  r5,r4,2
107         mtctr   r5
108         stw     r0,0(r3)
109         addi    r3,r3,4
110         bdnz-   \$-8
111         andi.   r4,r4,3
112         bne     Little
113         blr
114 ___
115 {
116 my ($out,$cnt,$max)=("r3","r4","r5");
117 my ($tick,$lasttick)=("r6","r7");
118 my ($diff,$lastdiff)=("r8","r9");
119
120 $code.=<<___;
121 .globl  .OPENSSL_instrument_bus
122 .align  4
123 .OPENSSL_instrument_bus:
124         mtctr   $cnt
125
126         mftb    $lasttick               # collect 1st tick
127         li      $diff,0
128
129         dcbf    0,$out                  # flush cache line
130         lwarx   $tick,0,$out            # load and lock
131         add     $tick,$tick,$diff
132         stwcx.  $tick,0,$out
133         stwx    $tick,0,$out
134
135 Loop:   mftb    $tick
136         sub     $diff,$tick,$lasttick
137         mr      $lasttick,$tick
138         dcbf    0,$out                  # flush cache line
139         lwarx   $tick,0,$out            # load and lock
140         add     $tick,$tick,$diff
141         stwcx.  $tick,0,$out
142         stwx    $tick,0,$out
143         addi    $out,$out,4             # ++$out
144         bdnz    Loop
145
146         mr      r3,$cnt
147         blr
148
149 .globl  .OPENSSL_instrument_bus2
150 .align  4
151 .OPENSSL_instrument_bus2:
152         mr      r0,$cnt
153         slwi    $cnt,$cnt,2
154
155         mftb    $lasttick               # collect 1st tick
156         li      $diff,0
157
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
164         mftb    $tick                   # collect 1st diff
165         sub     $diff,$tick,$lasttick
166         mr      $lasttick,$tick
167         mr      $lastdiff,$diff
168 Loop2:
169         dcbf    0,$out                  # flush cache line
170         lwarx   $tick,0,$out            # load and lock
171         add     $tick,$tick,$diff
172         stwcx.  $tick,0,$out
173         stwx    $tick,0,$out
174
175         addic.  $max,$max,-1
176         beq     Ldone2
177
178         mftb    $tick
179         sub     $diff,$tick,$lasttick
180         mr      $lasttick,$tick
181         cmplw   7,$diff,$lastdiff
182         mr      $lastdiff,$diff
183
184         mfcr    $tick                   # pull cr
185         not     $tick,$tick             # flip bits
186         rlwinm  $tick,$tick,1,29,29     # isolate flipped eq bit and scale
187
188         sub.    $cnt,$cnt,$tick         # conditional --$cnt
189         add     $out,$out,$tick         # conditional ++$out
190         bne     Loop2
191
192 Ldone2:
193         srwi    $cnt,$cnt,2
194         sub     r3,r0,$cnt
195         blr
196 ___
197 }
198
199 $code =~ s/\`([^\`]*)\`/eval $1/gem;
200 print $code;
201 close STDOUT;