1#! /usr/bin/env perl 2# Copyright 2015-2023 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 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; 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 18die "can't locate arm-xlate.pl"; 19 20open OUT,"| \"$^X\" $xlate $flavour \"$output\"" 21 or die "can't call $xlate: $!"; 22*STDOUT=*OUT; 23 24$code.=<<___; 25#include "arm_arch.h" 26 27#if defined(__thumb2__) && !defined(__APPLE__) 28.syntax unified 29.thumb 30#else 31.code 32 32#undef __thumb2__ 33#endif 34 35.text 36 37.align 5 38.global OPENSSL_atomic_add 39.type OPENSSL_atomic_add,%function 40OPENSSL_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 48 bx lr 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] 64 add r2,r2,r5 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 76OPENSSL_cleanse: 77 eor ip,ip,ip 78 cmp r1,#7 79#ifdef __thumb2__ 80 itt hs 81#endif 82 subhs r1,r1,#4 83 bhs .Lot 84 cmp r1,#0 85 beq .Lcleanse_done 86.Little: 87 strb ip,[r0],#1 88 subs r1,r1,#1 89 bhi .Little 90 b .Lcleanse_done 91 92.Lot: tst r0,#3 93 beq .Laligned 94 strb ip,[r0],#1 95 sub r1,r1,#1 96 b .Lot 97.Laligned: 98 str ip,[r0],#4 99 subs r1,r1,#4 100 bhs .Laligned 101 adds r1,r1,#4 102 bne .Little 103.Lcleanse_done: 104#if __ARM_ARCH__>=5 105 bx lr 106#else 107 tst lr,#1 108 moveq pc,lr 109 .word 0xe12fff1e @ bx lr 110#endif 111.size OPENSSL_cleanse,.-OPENSSL_cleanse 112 113.global CRYPTO_memcmp 114.type CRYPTO_memcmp,%function 115.align 4 116CRYPTO_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: 132 rsb r0,ip,#0 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 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: 158#ifdef __APPLE__ 159 mrrc p15,0,r0,r1,c14 @ CNTPCT 160#else 161 mrrc p15,1,r0,r1,c14 @ CNTVCT 162#endif 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: 169#if defined(__thumb2__) && !defined(__APPLE__) 170 .byte 0xb0,0xff,0x00,0x03 @ aese.8 q0,q0 171#else 172 .byte 0x00,0x03,0xb0,0xf3 @ aese.8 q0,q0 173#endif 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: 180#if defined(__thumb2__) && !defined(__APPLE__) 181 .byte 0x00,0xef,0x40,0x0c @ sha1c.32 q0,q0,q0 182#else 183 .byte 0x40,0x0c,0x00,0xf2 @ sha1c.32 q0,q0,q0 184#endif 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: 191#if defined(__thumb2__) && !defined(__APPLE__) 192 .byte 0x00,0xff,0x40,0x0c @ sha256h.32 q0,q0,q0 193#else 194 .byte 0x40,0x0c,0x00,0xf3 @ sha256h.32 q0,q0,q0 195#endif 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: 201#if defined(__thumb2__) && !defined(__APPLE__) 202 .byte 0xa0,0xef,0x00,0x0e @ vmull.p64 q0,d0,d0 203#else 204 .byte 0x00,0x0e,0xa0,0xf2 @ vmull.p64 q0,d0,d0 205#endif 206 bx lr 207.size _armv8_pmull_probe,.-_armv8_pmull_probe 208#endif 209 210.global OPENSSL_wipe_cpu 211.type OPENSSL_wipe_cpu,%function 212OPENSSL_wipe_cpu: 213#if __ARM_MAX_ARCH__>=7 214 ldr r0,.LOPENSSL_armcap 215 adr r1,.LOPENSSL_armcap 216 ldr r0,[r1,r0] 217#ifdef __APPLE__ 218 ldr r0,[r0] 219#endif 220#endif 221 eor r2,r2,r2 222 eor r3,r3,r3 223 eor ip,ip,ip 224#if __ARM_MAX_ARCH__>=7 225 tst r0,#1 226 beq .Lwipe_done 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 239.Lwipe_done: 240#endif 241 mov r0,sp 242#if __ARM_ARCH__>=5 243 bx lr 244#else 245 tst lr,#1 246 moveq pc,lr 247 .word 0xe12fff1e @ bx lr 248#endif 249.size OPENSSL_wipe_cpu,.-OPENSSL_wipe_cpu 250 251.global OPENSSL_instrument_bus 252.type OPENSSL_instrument_bus,%function 253OPENSSL_instrument_bus: 254 eor r0,r0,r0 255#if __ARM_ARCH__>=5 256 bx lr 257#else 258 tst lr,#1 259 moveq pc,lr 260 .word 0xe12fff1e @ bx lr 261#endif 262.size OPENSSL_instrument_bus,.-OPENSSL_instrument_bus 263 264.global OPENSSL_instrument_bus2 265.type OPENSSL_instrument_bus2,%function 266OPENSSL_instrument_bus2: 267 eor r0,r0,r0 268#if __ARM_ARCH__>=5 269 bx lr 270#else 271 tst lr,#1 272 moveq pc,lr 273 .word 0xe12fff1e @ bx lr 274#endif 275.size OPENSSL_instrument_bus2,.-OPENSSL_instrument_bus2 276 277.align 5 278#if __ARM_MAX_ARCH__>=7 279.LOPENSSL_armcap: 280.word OPENSSL_armcap_P-. 281#endif 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 291atomic_add_spinlock: 292.word 0 293#endif 294 295.extern OPENSSL_armcap_P 296___ 297 298print $code; 299close STDOUT or die "error closing STDOUT: $!"; 300