Allocate the three shared DRBGs on the secure heap
[openssl.git] / crypto / alphacpuid.pl
1 #! /usr/bin/env perl
2 # Copyright 2010-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 $output = pop;
11 open STDOUT,">$output";
12
13 print <<'___';
14 .text
15
16 .set    noat
17
18 .globl  OPENSSL_cpuid_setup
19 .ent    OPENSSL_cpuid_setup
20 OPENSSL_cpuid_setup:
21         .frame  $30,0,$26
22         .prologue 0
23         ret     ($26)
24 .end    OPENSSL_cpuid_setup
25
26 .globl  OPENSSL_wipe_cpu
27 .ent    OPENSSL_wipe_cpu
28 OPENSSL_wipe_cpu:
29         .frame  $30,0,$26
30         .prologue 0
31         clr     $1
32         clr     $2
33         clr     $3
34         clr     $4
35         clr     $5
36         clr     $6
37         clr     $7
38         clr     $8
39         clr     $16
40         clr     $17
41         clr     $18
42         clr     $19
43         clr     $20
44         clr     $21
45         clr     $22
46         clr     $23
47         clr     $24
48         clr     $25
49         clr     $27
50         clr     $at
51         clr     $29
52         fclr    $f0
53         fclr    $f1
54         fclr    $f10
55         fclr    $f11
56         fclr    $f12
57         fclr    $f13
58         fclr    $f14
59         fclr    $f15
60         fclr    $f16
61         fclr    $f17
62         fclr    $f18
63         fclr    $f19
64         fclr    $f20
65         fclr    $f21
66         fclr    $f22
67         fclr    $f23
68         fclr    $f24
69         fclr    $f25
70         fclr    $f26
71         fclr    $f27
72         fclr    $f28
73         fclr    $f29
74         fclr    $f30
75         mov     $sp,$0
76         ret     ($26)
77 .end    OPENSSL_wipe_cpu
78
79 .globl  OPENSSL_atomic_add
80 .ent    OPENSSL_atomic_add
81 OPENSSL_atomic_add:
82         .frame  $30,0,$26
83         .prologue 0
84 1:      ldl_l   $0,0($16)
85         addl    $0,$17,$1
86         stl_c   $1,0($16)
87         beq     $1,1b
88         addl    $0,$17,$0
89         ret     ($26)
90 .end    OPENSSL_atomic_add
91
92 .globl  OPENSSL_rdtsc
93 .ent    OPENSSL_rdtsc
94 OPENSSL_rdtsc:
95         .frame  $30,0,$26
96         .prologue 0
97         rpcc    $0
98         ret     ($26)
99 .end    OPENSSL_rdtsc
100
101 .globl  OPENSSL_cleanse
102 .ent    OPENSSL_cleanse
103 OPENSSL_cleanse:
104         .frame  $30,0,$26
105         .prologue 0
106         beq     $17,.Ldone
107         and     $16,7,$0
108         bic     $17,7,$at
109         beq     $at,.Little
110         beq     $0,.Laligned
111
112 .Little:
113         subq    $0,8,$0
114         ldq_u   $1,0($16)
115         mov     $16,$2
116 .Lalign:
117         mskbl   $1,$16,$1
118         lda     $16,1($16)
119         subq    $17,1,$17
120         addq    $0,1,$0
121         beq     $17,.Lout
122         bne     $0,.Lalign
123 .Lout:  stq_u   $1,0($2)
124         beq     $17,.Ldone
125         bic     $17,7,$at
126         beq     $at,.Little
127
128 .Laligned:
129         stq     $31,0($16)
130         subq    $17,8,$17
131         lda     $16,8($16)
132         bic     $17,7,$at
133         bne     $at,.Laligned
134         bne     $17,.Little
135 .Ldone: ret     ($26)
136 .end    OPENSSL_cleanse
137
138 .globl  CRYPTO_memcmp
139 .ent    CRYPTO_memcmp
140 CRYPTO_memcmp:
141         .frame  $30,0,$26
142         .prologue 0
143         xor     $0,$0,$0
144         beq     $18,.Lno_data
145
146         xor     $1,$1,$1
147         nop
148 .Loop_cmp:
149         ldq_u   $2,0($16)
150         subq    $18,1,$18
151         ldq_u   $3,0($17)
152         extbl   $2,$16,$2
153         lda     $16,1($16)
154         extbl   $3,$17,$3
155         lda     $17,1($17)
156         xor     $3,$2,$2
157         or      $2,$0,$0
158         bne     $18,.Loop_cmp
159
160         subq    $31,$0,$0
161         srl     $0,63,$0
162 .Lno_data:
163         ret     ($26)
164 .end    CRYPTO_memcmp
165 ___
166 {
167 my ($out,$cnt,$max)=("\$16","\$17","\$18");
168 my ($tick,$lasttick)=("\$19","\$20");
169 my ($diff,$lastdiff)=("\$21","\$22");
170 my ($v0,$ra,$sp,$zero)=("\$0","\$26","\$30","\$31");
171
172 print <<___;
173 .globl  OPENSSL_instrument_bus
174 .ent    OPENSSL_instrument_bus
175 OPENSSL_instrument_bus:
176         .frame  $sp,0,$ra
177         .prologue 0
178         mov     $cnt,$v0
179
180         rpcc    $lasttick
181         mov     0,$diff
182
183         ecb     ($out)
184         ldl_l   $tick,0($out)
185         addl    $diff,$tick,$tick
186         mov     $tick,$diff
187         stl_c   $tick,0($out)
188         stl     $diff,0($out)
189
190 .Loop:  rpcc    $tick
191         subq    $tick,$lasttick,$diff
192         mov     $tick,$lasttick
193
194         ecb     ($out)
195         ldl_l   $tick,0($out)
196         addl    $diff,$tick,$tick
197         mov     $tick,$diff
198         stl_c   $tick,0($out)
199         stl     $diff,0($out)
200
201         subl    $cnt,1,$cnt
202         lda     $out,4($out)
203         bne     $cnt,.Loop
204
205         ret     ($ra)
206 .end    OPENSSL_instrument_bus
207
208 .globl  OPENSSL_instrument_bus2
209 .ent    OPENSSL_instrument_bus2
210 OPENSSL_instrument_bus2:
211         .frame  $sp,0,$ra
212         .prologue 0
213         mov     $cnt,$v0
214
215         rpcc    $lasttick
216         mov     0,$diff
217
218         ecb     ($out)
219         ldl_l   $tick,0($out)
220         addl    $diff,$tick,$tick
221         mov     $tick,$diff
222         stl_c   $tick,0($out)
223         stl     $diff,0($out)
224
225         rpcc    $tick
226         subq    $tick,$lasttick,$diff
227         mov     $tick,$lasttick
228         mov     $diff,$lastdiff
229 .Loop2:
230         ecb     ($out)
231         ldl_l   $tick,0($out)
232         addl    $diff,$tick,$tick
233         mov     $tick,$diff
234         stl_c   $tick,0($out)
235         stl     $diff,0($out)
236
237         subl    $max,1,$max
238         beq     $max,.Ldone2
239
240         rpcc    $tick
241         subq    $tick,$lasttick,$diff
242         mov     $tick,$lasttick
243         subq    $lastdiff,$diff,$tick
244         mov     $diff,$lastdiff
245         cmovne  $tick,1,$tick
246         subl    $cnt,$tick,$cnt
247         s4addq  $tick,$out,$out
248         bne     $cnt,.Loop2
249
250 .Ldone2:
251         subl    $v0,$cnt,$v0
252         ret     ($ra)
253 .end    OPENSSL_instrument_bus2
254 ___
255 }
256
257 close STDOUT;