armv4cpuid.pl 4.9 KB
Newer Older
R
Rich Salz 已提交
1 2 3 4 5 6 7 8
#! /usr/bin/env perl
# Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
#
# Licensed under the OpenSSL license (the "License").  You may not use
# this file except in compliance with the License.  You can obtain a copy
# in the file LICENSE in the source distribution or at
# https://www.openssl.org/source/license.html

9 10 11 12 13 14 15 16 17 18 19 20 21

$flavour = shift;
$output  = shift;

$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
( $xlate="${dir}arm-xlate.pl" and -f $xlate ) or
( $xlate="${dir}perlasm/arm-xlate.pl" and -f $xlate) or
die "can't locate arm-xlate.pl";

open OUT,"| \"$^X\" $xlate $flavour $output";
*STDOUT=*OUT;

$code.=<<___;
22 23 24
#include "arm_arch.h"

.text
25 26 27 28
#if defined(__thumb2__) && !defined(__APPLE__)
.syntax	unified
.thumb
#else
29
.code	32
30
#endif
31

32
.align	5
33 34 35 36 37 38 39 40 41 42
.global	OPENSSL_atomic_add
.type	OPENSSL_atomic_add,%function
OPENSSL_atomic_add:
#if __ARM_ARCH__>=6
.Ladd:	ldrex	r2,[r0]
	add	r3,r2,r1
	strex	r2,r3,[r0]
	cmp	r2,#0
	bne	.Ladd
	mov	r0,r3
43
	bx	lr
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
#else
	stmdb	sp!,{r4-r6,lr}
	ldr	r2,.Lspinlock
	adr	r3,.Lspinlock
	mov	r4,r0
	mov	r5,r1
	add	r6,r3,r2	@ &spinlock
	b	.+8
.Lspin:	bl	sched_yield
	mov	r0,#-1
	swp	r0,r0,[r6]
	cmp	r0,#0
	bne	.Lspin

	ldr	r2,[r4]
59
	add	r2,r2,r5
60 61 62 63 64 65 66 67 68 69 70 71 72 73
	str	r2,[r4]
	str	r0,[r6]		@ release spinlock
	ldmia	sp!,{r4-r6,lr}
	tst	lr,#1
	moveq	pc,lr
	.word	0xe12fff1e	@ bx	lr
#endif
.size	OPENSSL_atomic_add,.-OPENSSL_atomic_add

.global	OPENSSL_cleanse
.type	OPENSSL_cleanse,%function
OPENSSL_cleanse:
	eor	ip,ip,ip
	cmp	r1,#7
74 75 76
#ifdef	__thumb2__
	itt	hs
#endif
77
	subhs	r1,r1,#4
78 79 80 81 82
	bhs	.Lot
	cmp	r1,#0
	beq	.Lcleanse_done
.Little:
	strb	ip,[r0],#1
83
	subs	r1,r1,#1
84 85 86 87 88 89
	bhi	.Little
	b	.Lcleanse_done

.Lot:	tst	r0,#3
	beq	.Laligned
	strb	ip,[r0],#1
90
	sub	r1,r1,#1
91 92 93
	b	.Lot
.Laligned:
	str	ip,[r0],#4
94
	subs	r1,r1,#4
95
	bhs	.Laligned
96
	adds	r1,r1,#4
97 98
	bne	.Little
.Lcleanse_done:
99 100 101
#if __ARM_ARCH__>=5
	bx	lr
#else
102 103 104
	tst	lr,#1
	moveq	pc,lr
	.word	0xe12fff1e	@ bx	lr
105
#endif
106 107
.size	OPENSSL_cleanse,.-OPENSSL_cleanse

108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
#if __ARM_MAX_ARCH__>=7
.arch	armv7-a
.fpu	neon

.align	5
.global	_armv7_neon_probe
.type	_armv7_neon_probe,%function
_armv7_neon_probe:
	vorr	q0,q0,q0
	bx	lr
.size	_armv7_neon_probe,.-_armv7_neon_probe

.global	_armv7_tick
.type	_armv7_tick,%function
_armv7_tick:
123 124 125
#ifdef	__APPLE__
	mrrc	p15,0,r0,r1,c14		@ CNTPCT
#else
126
	mrrc	p15,1,r0,r1,c14		@ CNTVCT
127
#endif
128 129 130 131 132 133
	bx	lr
.size	_armv7_tick,.-_armv7_tick

.global	_armv8_aes_probe
.type	_armv8_aes_probe,%function
_armv8_aes_probe:
134 135 136
#if defined(__thumb2__) && !defined(__APPLE__)
	.byte	0xb0,0xff,0x00,0x03	@ aese.8	q0,q0
#else
137
	.byte	0x00,0x03,0xb0,0xf3	@ aese.8	q0,q0
138
#endif
139 140 141 142 143 144
	bx	lr
.size	_armv8_aes_probe,.-_armv8_aes_probe

.global	_armv8_sha1_probe
.type	_armv8_sha1_probe,%function
_armv8_sha1_probe:
145 146 147
#if defined(__thumb2__) && !defined(__APPLE__)
	.byte	0x00,0xef,0x40,0x0c	@ sha1c.32	q0,q0,q0
#else
148
	.byte	0x40,0x0c,0x00,0xf2	@ sha1c.32	q0,q0,q0
149
#endif
150 151 152 153 154 155
	bx	lr
.size	_armv8_sha1_probe,.-_armv8_sha1_probe

.global	_armv8_sha256_probe
.type	_armv8_sha256_probe,%function
_armv8_sha256_probe:
156 157 158
#if defined(__thumb2__) && !defined(__APPLE__)
	.byte	0x00,0xff,0x40,0x0c	@ sha256h.32	q0,q0,q0
#else
159
	.byte	0x40,0x0c,0x00,0xf3	@ sha256h.32	q0,q0,q0
160
#endif
161 162 163 164 165
	bx	lr
.size	_armv8_sha256_probe,.-_armv8_sha256_probe
.global	_armv8_pmull_probe
.type	_armv8_pmull_probe,%function
_armv8_pmull_probe:
166 167 168
#if defined(__thumb2__) && !defined(__APPLE__)
	.byte	0xa0,0xef,0x00,0x0e	@ vmull.p64	q0,d0,d0
#else
169
	.byte	0x00,0x0e,0xa0,0xf2	@ vmull.p64	q0,d0,d0
170
#endif
171 172 173 174
	bx	lr
.size	_armv8_pmull_probe,.-_armv8_pmull_probe
#endif

175 176 177
.global	OPENSSL_wipe_cpu
.type	OPENSSL_wipe_cpu,%function
OPENSSL_wipe_cpu:
178
#if __ARM_MAX_ARCH__>=7
179 180 181
	ldr	r0,.LOPENSSL_armcap
	adr	r1,.LOPENSSL_armcap
	ldr	r0,[r1,r0]
182 183 184
#ifdef	__APPLE__
	ldr	r0,[r0]
#endif
185
#endif
186 187 188
	eor	r2,r2,r2
	eor	r3,r3,r3
	eor	ip,ip,ip
189
#if __ARM_MAX_ARCH__>=7
190 191
	tst	r0,#1
	beq	.Lwipe_done
192 193 194 195 196 197 198 199 200 201 202 203
	veor	q0, q0, q0
	veor	q1, q1, q1
	veor	q2, q2, q2
	veor	q3, q3, q3
	veor	q8, q8, q8
	veor	q9, q9, q9
	veor	q10, q10, q10
	veor	q11, q11, q11
	veor	q12, q12, q12
	veor	q13, q13, q13
	veor	q14, q14, q14
	veor	q15, q15, q15
204
.Lwipe_done:
205
#endif
206
	mov	r0,sp
207 208 209
#if __ARM_ARCH__>=5
	bx	lr
#else
210 211 212
	tst	lr,#1
	moveq	pc,lr
	.word	0xe12fff1e	@ bx	lr
213
#endif
214 215 216 217 218 219
.size	OPENSSL_wipe_cpu,.-OPENSSL_wipe_cpu

.global	OPENSSL_instrument_bus
.type	OPENSSL_instrument_bus,%function
OPENSSL_instrument_bus:
	eor	r0,r0,r0
220 221 222
#if __ARM_ARCH__>=5
	bx	lr
#else
223 224 225
	tst	lr,#1
	moveq	pc,lr
	.word	0xe12fff1e	@ bx	lr
226
#endif
227 228 229 230 231 232
.size	OPENSSL_instrument_bus,.-OPENSSL_instrument_bus

.global	OPENSSL_instrument_bus2
.type	OPENSSL_instrument_bus2,%function
OPENSSL_instrument_bus2:
	eor	r0,r0,r0
233 234 235
#if __ARM_ARCH__>=5
	bx	lr
#else
236 237 238
	tst	lr,#1
	moveq	pc,lr
	.word	0xe12fff1e	@ bx	lr
239
#endif
240 241 242
.size	OPENSSL_instrument_bus2,.-OPENSSL_instrument_bus2

.align	5
243
#if __ARM_MAX_ARCH__>=7
244
.LOPENSSL_armcap:
245
.word	OPENSSL_armcap_P-.
246
#endif
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261
#if __ARM_ARCH__>=6
.align	5
#else
.Lspinlock:
.word	atomic_add_spinlock-.Lspinlock
.align	5

.data
.align	2
atomic_add_spinlock:
.word	0
#endif

.comm	OPENSSL_armcap_P,4,4
.hidden	OPENSSL_armcap_P
262 263 264 265
___

print $code;
close STDOUT;