]>
Commit | Line | Data |
---|---|---|
e0a65194 | 1 | #! /usr/bin/env perl |
33388b44 | 2 | # Copyright 2015-2020 The OpenSSL Project Authors. All Rights Reserved. |
e0a65194 | 3 | # |
0e9725bc | 4 | # Licensed under the Apache License 2.0 (the "License"). You may not use |
e0a65194 RS |
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 | ||
313e6ec1 | 9 | |
1aa89a7a RL |
10 | # $output is the last argument if it looks like a file (it has an extension) |
11 | # $flavour is the first argument if it doesn't look like a file | |
12 | $output = $#ARGV >= 0 && $ARGV[$#ARGV] =~ m|\.\w+$| ? pop : undef; | |
13 | $flavour = $#ARGV >= 0 && $ARGV[0] !~ m|\.| ? shift : undef; | |
313e6ec1 AP |
14 | |
15 | $0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1; | |
16 | ( $xlate="${dir}arm-xlate.pl" and -f $xlate ) or | |
17 | ( $xlate="${dir}perlasm/arm-xlate.pl" and -f $xlate) or | |
18 | die "can't locate arm-xlate.pl"; | |
19 | ||
1aa89a7a RL |
20 | open OUT,"| \"$^X\" $xlate $flavour \"$output\"" |
21 | or die "can't call $xlate: $!"; | |
313e6ec1 AP |
22 | *STDOUT=*OUT; |
23 | ||
24 | $code.=<<___; | |
87873f43 AP |
25 | #include "arm_arch.h" |
26 | ||
11208dcf AP |
27 | #if defined(__thumb2__) && !defined(__APPLE__) |
28 | .syntax unified | |
29 | .thumb | |
30 | #else | |
87873f43 | 31 | .code 32 |
c93f06c1 | 32 | #undef __thumb2__ |
11208dcf | 33 | #endif |
87873f43 | 34 | |
3405db97 AP |
35 | .text |
36 | ||
4afa9f03 | 37 | .align 5 |
87873f43 AP |
38 | .global OPENSSL_atomic_add |
39 | .type OPENSSL_atomic_add,%function | |
40 | OPENSSL_atomic_add: | |
41 | #if __ARM_ARCH__>=6 | |
42 | .Ladd: ldrex r2,[r0] | |
43 | add r3,r2,r1 | |
44 | strex r2,r3,[r0] | |
45 | cmp r2,#0 | |
46 | bne .Ladd | |
47 | mov r0,r3 | |
5dcf70a1 | 48 | bx lr |
87873f43 AP |
49 | #else |
50 | stmdb sp!,{r4-r6,lr} | |
51 | ldr r2,.Lspinlock | |
52 | adr r3,.Lspinlock | |
53 | mov r4,r0 | |
54 | mov r5,r1 | |
55 | add r6,r3,r2 @ &spinlock | |
56 | b .+8 | |
57 | .Lspin: bl sched_yield | |
58 | mov r0,#-1 | |
59 | swp r0,r0,[r6] | |
60 | cmp r0,#0 | |
61 | bne .Lspin | |
62 | ||
63 | ldr r2,[r4] | |
29fd6746 | 64 | add r2,r2,r5 |
87873f43 AP |
65 | str r2,[r4] |
66 | str r0,[r6] @ release spinlock | |
67 | ldmia sp!,{r4-r6,lr} | |
68 | tst lr,#1 | |
69 | moveq pc,lr | |
70 | .word 0xe12fff1e @ bx lr | |
71 | #endif | |
72 | .size OPENSSL_atomic_add,.-OPENSSL_atomic_add | |
73 | ||
74 | .global OPENSSL_cleanse | |
75 | .type OPENSSL_cleanse,%function | |
76 | OPENSSL_cleanse: | |
77 | eor ip,ip,ip | |
78 | cmp r1,#7 | |
11208dcf AP |
79 | #ifdef __thumb2__ |
80 | itt hs | |
81 | #endif | |
29fd6746 | 82 | subhs r1,r1,#4 |
87873f43 AP |
83 | bhs .Lot |
84 | cmp r1,#0 | |
85 | beq .Lcleanse_done | |
86 | .Little: | |
87 | strb ip,[r0],#1 | |
29fd6746 | 88 | subs r1,r1,#1 |
87873f43 AP |
89 | bhi .Little |
90 | b .Lcleanse_done | |
91 | ||
92 | .Lot: tst r0,#3 | |
93 | beq .Laligned | |
94 | strb ip,[r0],#1 | |
29fd6746 | 95 | sub r1,r1,#1 |
87873f43 AP |
96 | b .Lot |
97 | .Laligned: | |
98 | str ip,[r0],#4 | |
29fd6746 | 99 | subs r1,r1,#4 |
87873f43 | 100 | bhs .Laligned |
29fd6746 | 101 | adds r1,r1,#4 |
87873f43 AP |
102 | bne .Little |
103 | .Lcleanse_done: | |
5dcf70a1 AP |
104 | #if __ARM_ARCH__>=5 |
105 | bx lr | |
106 | #else | |
87873f43 AP |
107 | tst lr,#1 |
108 | moveq pc,lr | |
109 | .word 0xe12fff1e @ bx lr | |
5dcf70a1 | 110 | #endif |
87873f43 AP |
111 | .size OPENSSL_cleanse,.-OPENSSL_cleanse |
112 | ||
e33826f0 AP |
113 | .global CRYPTO_memcmp |
114 | .type CRYPTO_memcmp,%function | |
115 | .align 4 | |
116 | CRYPTO_memcmp: | |
117 | eor ip,ip,ip | |
118 | cmp r2,#0 | |
119 | beq .Lno_data | |
120 | stmdb sp!,{r4,r5} | |
121 | ||
122 | .Loop_cmp: | |
123 | ldrb r4,[r0],#1 | |
124 | ldrb r5,[r1],#1 | |
125 | eor r4,r4,r5 | |
126 | orr ip,ip,r4 | |
127 | subs r2,r2,#1 | |
128 | bne .Loop_cmp | |
129 | ||
130 | ldmia sp!,{r4,r5} | |
131 | .Lno_data: | |
198a2ed7 | 132 | rsb r0,ip,#0 |
e33826f0 AP |
133 | mov r0,r0,lsr#31 |
134 | #if __ARM_ARCH__>=5 | |
135 | bx lr | |
136 | #else | |
137 | tst lr,#1 | |
138 | moveq pc,lr | |
139 | .word 0xe12fff1e @ bx lr | |
140 | #endif | |
141 | .size CRYPTO_memcmp,.-CRYPTO_memcmp | |
142 | ||
c1669e1c AP |
143 | #if __ARM_MAX_ARCH__>=7 |
144 | .arch armv7-a | |
145 | .fpu neon | |
146 | ||
147 | .align 5 | |
148 | .global _armv7_neon_probe | |
149 | .type _armv7_neon_probe,%function | |
150 | _armv7_neon_probe: | |
151 | vorr q0,q0,q0 | |
152 | bx lr | |
153 | .size _armv7_neon_probe,.-_armv7_neon_probe | |
154 | ||
155 | .global _armv7_tick | |
156 | .type _armv7_tick,%function | |
157 | _armv7_tick: | |
313e6ec1 AP |
158 | #ifdef __APPLE__ |
159 | mrrc p15,0,r0,r1,c14 @ CNTPCT | |
160 | #else | |
c1669e1c | 161 | mrrc p15,1,r0,r1,c14 @ CNTVCT |
313e6ec1 | 162 | #endif |
c1669e1c AP |
163 | bx lr |
164 | .size _armv7_tick,.-_armv7_tick | |
165 | ||
166 | .global _armv8_aes_probe | |
167 | .type _armv8_aes_probe,%function | |
168 | _armv8_aes_probe: | |
11208dcf AP |
169 | #if defined(__thumb2__) && !defined(__APPLE__) |
170 | .byte 0xb0,0xff,0x00,0x03 @ aese.8 q0,q0 | |
171 | #else | |
c1669e1c | 172 | .byte 0x00,0x03,0xb0,0xf3 @ aese.8 q0,q0 |
11208dcf | 173 | #endif |
c1669e1c AP |
174 | bx lr |
175 | .size _armv8_aes_probe,.-_armv8_aes_probe | |
176 | ||
177 | .global _armv8_sha1_probe | |
178 | .type _armv8_sha1_probe,%function | |
179 | _armv8_sha1_probe: | |
11208dcf AP |
180 | #if defined(__thumb2__) && !defined(__APPLE__) |
181 | .byte 0x00,0xef,0x40,0x0c @ sha1c.32 q0,q0,q0 | |
182 | #else | |
c1669e1c | 183 | .byte 0x40,0x0c,0x00,0xf2 @ sha1c.32 q0,q0,q0 |
11208dcf | 184 | #endif |
c1669e1c AP |
185 | bx lr |
186 | .size _armv8_sha1_probe,.-_armv8_sha1_probe | |
187 | ||
188 | .global _armv8_sha256_probe | |
189 | .type _armv8_sha256_probe,%function | |
190 | _armv8_sha256_probe: | |
11208dcf AP |
191 | #if defined(__thumb2__) && !defined(__APPLE__) |
192 | .byte 0x00,0xff,0x40,0x0c @ sha256h.32 q0,q0,q0 | |
193 | #else | |
c1669e1c | 194 | .byte 0x40,0x0c,0x00,0xf3 @ sha256h.32 q0,q0,q0 |
11208dcf | 195 | #endif |
c1669e1c AP |
196 | bx lr |
197 | .size _armv8_sha256_probe,.-_armv8_sha256_probe | |
198 | .global _armv8_pmull_probe | |
199 | .type _armv8_pmull_probe,%function | |
200 | _armv8_pmull_probe: | |
11208dcf AP |
201 | #if defined(__thumb2__) && !defined(__APPLE__) |
202 | .byte 0xa0,0xef,0x00,0x0e @ vmull.p64 q0,d0,d0 | |
203 | #else | |
c1669e1c | 204 | .byte 0x00,0x0e,0xa0,0xf2 @ vmull.p64 q0,d0,d0 |
11208dcf | 205 | #endif |
c1669e1c AP |
206 | bx lr |
207 | .size _armv8_pmull_probe,.-_armv8_pmull_probe | |
208 | #endif | |
209 | ||
87873f43 AP |
210 | .global OPENSSL_wipe_cpu |
211 | .type OPENSSL_wipe_cpu,%function | |
212 | OPENSSL_wipe_cpu: | |
c1669e1c | 213 | #if __ARM_MAX_ARCH__>=7 |
87873f43 AP |
214 | ldr r0,.LOPENSSL_armcap |
215 | adr r1,.LOPENSSL_armcap | |
216 | ldr r0,[r1,r0] | |
313e6ec1 AP |
217 | #ifdef __APPLE__ |
218 | ldr r0,[r0] | |
219 | #endif | |
c1669e1c | 220 | #endif |
87873f43 AP |
221 | eor r2,r2,r2 |
222 | eor r3,r3,r3 | |
223 | eor ip,ip,ip | |
c1669e1c | 224 | #if __ARM_MAX_ARCH__>=7 |
87873f43 AP |
225 | tst r0,#1 |
226 | beq .Lwipe_done | |
c1669e1c AP |
227 | veor q0, q0, q0 |
228 | veor q1, q1, q1 | |
229 | veor q2, q2, q2 | |
230 | veor q3, q3, q3 | |
231 | veor q8, q8, q8 | |
232 | veor q9, q9, q9 | |
233 | veor q10, q10, q10 | |
234 | veor q11, q11, q11 | |
235 | veor q12, q12, q12 | |
236 | veor q13, q13, q13 | |
237 | veor q14, q14, q14 | |
238 | veor q15, q15, q15 | |
87873f43 | 239 | .Lwipe_done: |
c1669e1c | 240 | #endif |
87873f43 | 241 | mov r0,sp |
5dcf70a1 AP |
242 | #if __ARM_ARCH__>=5 |
243 | bx lr | |
244 | #else | |
87873f43 AP |
245 | tst lr,#1 |
246 | moveq pc,lr | |
247 | .word 0xe12fff1e @ bx lr | |
5dcf70a1 | 248 | #endif |
87873f43 AP |
249 | .size OPENSSL_wipe_cpu,.-OPENSSL_wipe_cpu |
250 | ||
251 | .global OPENSSL_instrument_bus | |
252 | .type OPENSSL_instrument_bus,%function | |
253 | OPENSSL_instrument_bus: | |
254 | eor r0,r0,r0 | |
5dcf70a1 AP |
255 | #if __ARM_ARCH__>=5 |
256 | bx lr | |
257 | #else | |
87873f43 AP |
258 | tst lr,#1 |
259 | moveq pc,lr | |
260 | .word 0xe12fff1e @ bx lr | |
5dcf70a1 | 261 | #endif |
87873f43 AP |
262 | .size OPENSSL_instrument_bus,.-OPENSSL_instrument_bus |
263 | ||
264 | .global OPENSSL_instrument_bus2 | |
265 | .type OPENSSL_instrument_bus2,%function | |
266 | OPENSSL_instrument_bus2: | |
267 | eor r0,r0,r0 | |
5dcf70a1 AP |
268 | #if __ARM_ARCH__>=5 |
269 | bx lr | |
270 | #else | |
87873f43 AP |
271 | tst lr,#1 |
272 | moveq pc,lr | |
273 | .word 0xe12fff1e @ bx lr | |
5dcf70a1 | 274 | #endif |
87873f43 AP |
275 | .size OPENSSL_instrument_bus2,.-OPENSSL_instrument_bus2 |
276 | ||
277 | .align 5 | |
c1669e1c | 278 | #if __ARM_MAX_ARCH__>=7 |
87873f43 | 279 | .LOPENSSL_armcap: |
313e6ec1 | 280 | .word OPENSSL_armcap_P-. |
c1669e1c | 281 | #endif |
87873f43 AP |
282 | #if __ARM_ARCH__>=6 |
283 | .align 5 | |
284 | #else | |
285 | .Lspinlock: | |
286 | .word atomic_add_spinlock-.Lspinlock | |
287 | .align 5 | |
288 | ||
289 | .data | |
290 | .align 2 | |
291 | atomic_add_spinlock: | |
292 | .word 0 | |
293 | #endif | |
294 | ||
295 | .comm OPENSSL_armcap_P,4,4 | |
296 | .hidden OPENSSL_armcap_P | |
313e6ec1 AP |
297 | ___ |
298 | ||
299 | print $code; | |
a21314db | 300 | close STDOUT or die "error closing STDOUT: $!"; |