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