Also check for errors in x86_64-xlate.pl.
[openssl.git] / crypto / sha / asm / sha1-armv4-large.pl
index e1bb92bad764dd26c9ca9a60819d2804f152a034..d82a38bb93883d97f0ecb9359a71772215488f92 100644 (file)
@@ -1,4 +1,11 @@
-#!/usr/bin/env perl
+#! /usr/bin/env perl
+# Copyright 2007-2016 The OpenSSL Project Authors. All Rights Reserved.
+#
+# Licensed under the Apache License 2.0 (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
+
 
 # ====================================================================
 # Written by Andy Polyakov <appro@openssl.org> for the OpenSSL
 #
 # Add ARMv8 code path performing at 2.35 cpb on Apple A7.
 
-$flavour = shift;
-if ($flavour=~/^\w[\w\-]*\.\w+$/) { $output=$flavour; undef $flavour; }
-else { while (($output=shift) && ($output!~/^\w[\w\-]*\.\w+$/)) {} }
+# $output is the last argument if it looks like a file (it has an extension)
+# $flavour is the first argument if it doesn't look like a file
+$output = $#ARGV >= 0 && $ARGV[$#ARGV] =~ m|\.\w+$| ? pop : undef;
+$flavour = $#ARGV >= 0 && $ARGV[0] !~ m|\.| ? shift : undef;
 
 if ($flavour && $flavour ne "void") {
     $0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
@@ -78,9 +86,10 @@ if ($flavour && $flavour ne "void") {
     ( $xlate="${dir}../../perlasm/arm-xlate.pl" and -f $xlate) or
     die "can't locate arm-xlate.pl";
 
-    open STDOUT,"| \"$^X\" $xlate $flavour $output";
+    open STDOUT,"| \"$^X\" $xlate $flavour \"$output\""
+        or die "can't call $xlate: $!";
 } else {
-    open STDOUT,">$output";
+    $output and open STDOUT,">$output";
 }
 
 $ctx="r0";
@@ -180,7 +189,6 @@ ___
 $code=<<___;
 #include "arm_arch.h"
 
-.text
 #if defined(__thumb2__)
 .syntax        unified
 .thumb
@@ -188,6 +196,8 @@ $code=<<___;
 .code  32
 #endif
 
+.text
+
 .global        sha1_block_data_order
 .type  sha1_block_data_order,%function
 
@@ -195,12 +205,14 @@ $code=<<___;
 sha1_block_data_order:
 #if __ARM_MAX_ARCH__>=7
 .Lsha1_block:
-       adr     r3,.Lsha1_block
        ldr     r12,.LOPENSSL_armcap
+# if !defined(_WIN32)
+       adr     r3,.Lsha1_block
        ldr     r12,[r3,r12]            @ OPENSSL_armcap_P
-#ifdef __APPLE__
+# endif
+# if defined(__APPLE__) || defined(_WIN32)
        ldr     r12,[r12]
-#endif
+# endif
        tst     r12,#ARMV8_SHA1
        bne     .LARMv8
        tst     r12,#ARMV7_NEON
@@ -304,7 +316,11 @@ $code.=<<___;
 .LK_60_79:     .word   0xca62c1d6
 #if __ARM_MAX_ARCH__>=7
 .LOPENSSL_armcap:
+# ifdef        _WIN32
+.word  OPENSSL_armcap_P
+# else
 .word  OPENSSL_armcap_P-.Lsha1_block
+# endif
 #endif
 .asciz "SHA1 block transform for ARMv4/NEON/ARMv8, CRYPTOGAMS by <appro\@openssl.org>"
 .align 5
@@ -606,14 +622,15 @@ my ($ABCD,$E,$E0,$E1)=map("q$_",(0..3));
 my @MSG=map("q$_",(4..7));
 my @Kxx=map("q$_",(8..11));
 my ($W0,$W1,$ABCD_SAVE)=map("q$_",(12..14));
+my $_byte = ($flavour =~ /win/ ? "DCB" : ".byte");
 
 $code.=<<___;
 #if __ARM_MAX_ARCH__>=7
 
 # if defined(__thumb2__)
-#  define INST(a,b,c,d)        .byte   c,d|0xf,a,b
+#  define INST(a,b,c,d)        $_byte  c,d|0xf,a,b
 # else
-#  define INST(a,b,c,d)        .byte   a,b,c,d|0x10
+#  define INST(a,b,c,d)        $_byte  a,b,c,d|0x10
 # endif
 
 .type  sha1_block_data_order_armv8,%function
@@ -732,4 +749,4 @@ foreach (split($/,$code)) {
        print $_,$/;
 }
 
-close STDOUT; # enforce flush
+close STDOUT or die "error closing STDOUT: $!"; # enforce flush