2016-04-20 10:10:43 +08:00
|
|
|
#! /usr/bin/env perl
|
2020-04-23 20:55:52 +08:00
|
|
|
# Copyright 2009-2020 The OpenSSL Project Authors. All Rights Reserved.
|
2016-04-20 10:10:43 +08:00
|
|
|
#
|
2018-12-06 21:03:01 +08:00
|
|
|
# Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-04-20 10:10:43 +08:00
|
|
|
# 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
|
|
|
|
|
2009-12-28 04:49:40 +08:00
|
|
|
|
Unify all assembler file generators
They now generally conform to the following argument sequence:
script.pl "$(PERLASM_SCHEME)" [ C preprocessor arguments ... ] \
$(PROCESSOR) <output file>
However, in the spirit of being able to use these scripts manually,
they also allow for no argument, or for only the flavour, or for only
the output file. This is done by only using the last argument as
output file if it's a file (it has an extension), and only using the
first argument as flavour if it isn't a file (it doesn't have an
extension).
While we're at it, we make all $xlate calls the same, i.e. the $output
argument is always quoted, and we always die on error when trying to
start $xlate.
There's a perl lesson in this, regarding operator priority...
This will always succeed, even when it fails:
open FOO, "something" || die "ERR: $!";
The reason is that '||' has higher priority than list operators (a
function is essentially a list operator and gobbles up everything
following it that isn't lower priority), and since a non-empty string
is always true, so that ends up being exactly the same as:
open FOO, "something";
This, however, will fail if "something" can't be opened:
open FOO, "something" or die "ERR: $!";
The reason is that 'or' has lower priority that list operators,
i.e. it's performed after the 'open' call.
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9884)
2019-09-13 06:06:46 +08:00
|
|
|
# $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;
|
|
|
|
|
|
|
|
$output and open STDOUT,">$output";
|
2009-12-28 04:49:40 +08:00
|
|
|
|
|
|
|
if ($flavour =~ /64/) {
|
|
|
|
$LEVEL ="2.0W";
|
|
|
|
$SIZE_T =8;
|
|
|
|
$ST ="std";
|
|
|
|
} else {
|
|
|
|
$LEVEL ="1.1";
|
|
|
|
$SIZE_T =4;
|
|
|
|
$ST ="stw";
|
|
|
|
}
|
|
|
|
|
|
|
|
$rp="%r2";
|
|
|
|
$sp="%r30";
|
|
|
|
$rv="%r28";
|
|
|
|
|
|
|
|
$code=<<___;
|
|
|
|
.LEVEL $LEVEL
|
|
|
|
.SPACE \$TEXT\$
|
|
|
|
.SUBSPA \$CODE\$,QUAD=0,ALIGN=8,ACCESS=0x2C,CODE_ONLY
|
|
|
|
|
2009-12-29 00:13:35 +08:00
|
|
|
.EXPORT OPENSSL_cpuid_setup,ENTRY
|
|
|
|
.ALIGN 8
|
|
|
|
OPENSSL_cpuid_setup
|
|
|
|
.PROC
|
|
|
|
.CALLINFO NO_CALLS
|
|
|
|
.ENTRY
|
|
|
|
bv ($rp)
|
|
|
|
.EXIT
|
|
|
|
nop
|
|
|
|
.PROCEND
|
|
|
|
|
2009-12-28 04:49:40 +08:00
|
|
|
.EXPORT OPENSSL_rdtsc,ENTRY
|
|
|
|
.ALIGN 8
|
|
|
|
OPENSSL_rdtsc
|
|
|
|
.PROC
|
|
|
|
.CALLINFO NO_CALLS
|
|
|
|
.ENTRY
|
|
|
|
mfctl %cr16,$rv
|
|
|
|
bv ($rp)
|
|
|
|
.EXIT
|
|
|
|
nop
|
|
|
|
.PROCEND
|
|
|
|
|
|
|
|
.EXPORT OPENSSL_wipe_cpu,ENTRY
|
|
|
|
.ALIGN 8
|
|
|
|
OPENSSL_wipe_cpu
|
|
|
|
.PROC
|
|
|
|
.CALLINFO NO_CALLS
|
|
|
|
.ENTRY
|
|
|
|
xor %r0,%r0,%r1
|
|
|
|
fcpy,dbl %fr0,%fr4
|
|
|
|
xor %r0,%r0,%r19
|
|
|
|
fcpy,dbl %fr0,%fr5
|
|
|
|
xor %r0,%r0,%r20
|
|
|
|
fcpy,dbl %fr0,%fr6
|
|
|
|
xor %r0,%r0,%r21
|
|
|
|
fcpy,dbl %fr0,%fr7
|
|
|
|
xor %r0,%r0,%r22
|
|
|
|
fcpy,dbl %fr0,%fr8
|
|
|
|
xor %r0,%r0,%r23
|
|
|
|
fcpy,dbl %fr0,%fr9
|
|
|
|
xor %r0,%r0,%r24
|
|
|
|
fcpy,dbl %fr0,%fr10
|
|
|
|
xor %r0,%r0,%r25
|
|
|
|
fcpy,dbl %fr0,%fr11
|
|
|
|
xor %r0,%r0,%r26
|
|
|
|
fcpy,dbl %fr0,%fr22
|
|
|
|
xor %r0,%r0,%r29
|
|
|
|
fcpy,dbl %fr0,%fr23
|
|
|
|
xor %r0,%r0,%r31
|
|
|
|
fcpy,dbl %fr0,%fr24
|
|
|
|
fcpy,dbl %fr0,%fr25
|
|
|
|
fcpy,dbl %fr0,%fr26
|
|
|
|
fcpy,dbl %fr0,%fr27
|
|
|
|
fcpy,dbl %fr0,%fr28
|
|
|
|
fcpy,dbl %fr0,%fr29
|
|
|
|
fcpy,dbl %fr0,%fr30
|
|
|
|
fcpy,dbl %fr0,%fr31
|
|
|
|
bv ($rp)
|
|
|
|
.EXIT
|
|
|
|
ldo 0($sp),$rv
|
|
|
|
.PROCEND
|
|
|
|
___
|
|
|
|
{
|
2011-04-17 20:46:00 +08:00
|
|
|
my $inp="%r26";
|
|
|
|
my $len="%r25";
|
2009-12-28 04:49:40 +08:00
|
|
|
|
|
|
|
$code.=<<___;
|
|
|
|
.EXPORT OPENSSL_cleanse,ENTRY,ARGW0=GR,ARGW1=GR
|
|
|
|
.ALIGN 8
|
|
|
|
OPENSSL_cleanse
|
|
|
|
.PROC
|
|
|
|
.CALLINFO NO_CALLS
|
|
|
|
.ENTRY
|
2013-06-18 16:37:00 +08:00
|
|
|
cmpib,*= 0,$len,L\$done
|
2010-01-24 23:04:28 +08:00
|
|
|
nop
|
2013-06-18 16:37:00 +08:00
|
|
|
cmpib,*>>= 15,$len,L\$ittle
|
2009-12-28 04:49:40 +08:00
|
|
|
ldi $SIZE_T-1,%r1
|
|
|
|
|
2013-06-18 16:37:00 +08:00
|
|
|
L\$align
|
2009-12-28 04:49:40 +08:00
|
|
|
and,*<> $inp,%r1,%r28
|
2013-06-18 16:37:00 +08:00
|
|
|
b,n L\$aligned
|
2009-12-28 04:49:40 +08:00
|
|
|
stb %r0,0($inp)
|
|
|
|
ldo -1($len),$len
|
2013-06-18 16:37:00 +08:00
|
|
|
b L\$align
|
2009-12-28 04:49:40 +08:00
|
|
|
ldo 1($inp),$inp
|
|
|
|
|
2013-06-18 16:37:00 +08:00
|
|
|
L\$aligned
|
2009-12-28 04:49:40 +08:00
|
|
|
andcm $len,%r1,%r28
|
2013-06-18 16:37:00 +08:00
|
|
|
L\$ot
|
2009-12-28 04:49:40 +08:00
|
|
|
$ST %r0,0($inp)
|
2013-06-18 16:37:00 +08:00
|
|
|
addib,*<> -$SIZE_T,%r28,L\$ot
|
2009-12-28 04:49:40 +08:00
|
|
|
ldo $SIZE_T($inp),$inp
|
|
|
|
|
|
|
|
and,*<> $len,%r1,$len
|
2013-06-18 16:37:00 +08:00
|
|
|
b,n L\$done
|
|
|
|
L\$ittle
|
2009-12-28 04:49:40 +08:00
|
|
|
stb %r0,0($inp)
|
2013-06-18 16:37:00 +08:00
|
|
|
addib,*<> -1,$len,L\$ittle
|
2009-12-28 04:49:40 +08:00
|
|
|
ldo 1($inp),$inp
|
2013-06-18 16:37:00 +08:00
|
|
|
L\$done
|
2009-12-28 04:49:40 +08:00
|
|
|
bv ($rp)
|
|
|
|
.EXIT
|
|
|
|
nop
|
|
|
|
.PROCEND
|
|
|
|
___
|
|
|
|
}
|
2011-04-17 20:46:00 +08:00
|
|
|
{
|
2016-05-15 23:01:15 +08:00
|
|
|
my ($in1,$in2,$len)=("%r26","%r25","%r24");
|
|
|
|
|
|
|
|
$code.=<<___;
|
|
|
|
.EXPORT CRYPTO_memcmp,ENTRY,ARGW0=GR,ARGW1=GR,ARGW1=GR
|
|
|
|
.ALIGN 8
|
|
|
|
CRYPTO_memcmp
|
|
|
|
.PROC
|
|
|
|
.CALLINFO NO_CALLS
|
|
|
|
.ENTRY
|
|
|
|
cmpib,*= 0,$len,L\$no_data
|
|
|
|
xor $rv,$rv,$rv
|
|
|
|
|
|
|
|
L\$oop_cmp
|
|
|
|
ldb 0($in1),%r19
|
|
|
|
ldb 0($in2),%r20
|
|
|
|
ldo 1($in1),$in1
|
|
|
|
ldo 1($in2),$in2
|
|
|
|
xor %r19,%r20,%r29
|
|
|
|
addib,*<> -1,$len,L\$oop_cmp
|
|
|
|
or %r29,$rv,$rv
|
|
|
|
|
|
|
|
sub %r0,$rv,%r29
|
2018-03-22 06:48:10 +08:00
|
|
|
extru %r29,0,1,$rv
|
2016-05-15 23:01:15 +08:00
|
|
|
L\$no_data
|
|
|
|
bv ($rp)
|
|
|
|
.EXIT
|
|
|
|
nop
|
|
|
|
.PROCEND
|
|
|
|
___
|
|
|
|
}
|
|
|
|
{
|
2011-04-17 20:46:00 +08:00
|
|
|
my ($out,$cnt,$max)=("%r26","%r25","%r24");
|
|
|
|
my ($tick,$lasttick)=("%r23","%r22");
|
|
|
|
my ($diff,$lastdiff)=("%r21","%r20");
|
|
|
|
|
|
|
|
$code.=<<___;
|
|
|
|
.EXPORT OPENSSL_instrument_bus,ENTRY,ARGW0=GR,ARGW1=GR
|
|
|
|
.ALIGN 8
|
|
|
|
OPENSSL_instrument_bus
|
|
|
|
.PROC
|
|
|
|
.CALLINFO NO_CALLS
|
|
|
|
.ENTRY
|
|
|
|
copy $cnt,$rv
|
|
|
|
mfctl %cr16,$tick
|
|
|
|
copy $tick,$lasttick
|
|
|
|
ldi 0,$diff
|
|
|
|
|
|
|
|
fdc 0($out)
|
|
|
|
ldw 0($out),$tick
|
|
|
|
add $diff,$tick,$tick
|
|
|
|
stw $tick,0($out)
|
2013-06-18 16:37:00 +08:00
|
|
|
L\$oop
|
2011-04-17 20:46:00 +08:00
|
|
|
mfctl %cr16,$tick
|
|
|
|
sub $tick,$lasttick,$diff
|
|
|
|
copy $tick,$lasttick
|
|
|
|
|
|
|
|
fdc 0($out)
|
|
|
|
ldw 0($out),$tick
|
|
|
|
add $diff,$tick,$tick
|
|
|
|
stw $tick,0($out)
|
|
|
|
|
2013-06-18 16:37:00 +08:00
|
|
|
addib,<> -1,$cnt,L\$oop
|
2011-04-17 20:46:00 +08:00
|
|
|
addi 4,$out,$out
|
|
|
|
|
|
|
|
bv ($rp)
|
|
|
|
.EXIT
|
|
|
|
sub $rv,$cnt,$rv
|
|
|
|
.PROCEND
|
2009-12-28 04:49:40 +08:00
|
|
|
|
2011-04-17 20:46:00 +08:00
|
|
|
.EXPORT OPENSSL_instrument_bus2,ENTRY,ARGW0=GR,ARGW1=GR
|
|
|
|
.ALIGN 8
|
|
|
|
OPENSSL_instrument_bus2
|
|
|
|
.PROC
|
|
|
|
.CALLINFO NO_CALLS
|
|
|
|
.ENTRY
|
|
|
|
copy $cnt,$rv
|
|
|
|
sub %r0,$cnt,$cnt
|
|
|
|
|
|
|
|
mfctl %cr16,$tick
|
|
|
|
copy $tick,$lasttick
|
|
|
|
ldi 0,$diff
|
|
|
|
|
|
|
|
fdc 0($out)
|
|
|
|
ldw 0($out),$tick
|
|
|
|
add $diff,$tick,$tick
|
|
|
|
stw $tick,0($out)
|
|
|
|
|
|
|
|
mfctl %cr16,$tick
|
|
|
|
sub $tick,$lasttick,$diff
|
|
|
|
copy $tick,$lasttick
|
2013-06-18 16:37:00 +08:00
|
|
|
L\$oop2
|
2011-04-17 20:46:00 +08:00
|
|
|
copy $diff,$lastdiff
|
|
|
|
fdc 0($out)
|
|
|
|
ldw 0($out),$tick
|
|
|
|
add $diff,$tick,$tick
|
|
|
|
stw $tick,0($out)
|
|
|
|
|
2013-06-18 16:37:00 +08:00
|
|
|
addib,= -1,$max,L\$done2
|
2011-04-17 20:46:00 +08:00
|
|
|
nop
|
|
|
|
|
|
|
|
mfctl %cr16,$tick
|
|
|
|
sub $tick,$lasttick,$diff
|
|
|
|
copy $tick,$lasttick
|
|
|
|
cmpclr,<> $lastdiff,$diff,$tick
|
|
|
|
ldi 1,$tick
|
|
|
|
|
|
|
|
ldi 1,%r1
|
|
|
|
xor %r1,$tick,$tick
|
2013-06-18 16:37:00 +08:00
|
|
|
addb,<> $tick,$cnt,L\$oop2
|
2011-04-17 20:46:00 +08:00
|
|
|
shladd,l $tick,2,$out,$out
|
2013-06-18 16:37:00 +08:00
|
|
|
L\$done2
|
2011-04-17 20:46:00 +08:00
|
|
|
bv ($rp)
|
|
|
|
.EXIT
|
|
|
|
add $rv,$cnt,$rv
|
|
|
|
.PROCEND
|
|
|
|
___
|
|
|
|
}
|
2018-06-24 19:29:29 +08:00
|
|
|
|
|
|
|
if (`$ENV{CC} -Wa,-v -c -o /dev/null -x assembler /dev/null 2>&1`
|
|
|
|
=~ /GNU assembler/) {
|
|
|
|
$gnuas = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach(split("\n",$code)) {
|
|
|
|
|
|
|
|
s/(\.LEVEL\s+2\.0)W/$1w/ if ($gnuas && $SIZE_T==8);
|
|
|
|
s/\.SPACE\s+\$TEXT\$/.text/ if ($gnuas && $SIZE_T==8);
|
|
|
|
s/\.SUBSPA.*// if ($gnuas && $SIZE_T==8);
|
|
|
|
s/cmpib,\*/comib,/ if ($SIZE_T==4);
|
|
|
|
s/,\*/,/ if ($SIZE_T==4);
|
|
|
|
s/\bbv\b/bve/ if ($SIZE_T==8);
|
|
|
|
|
|
|
|
print $_,"\n";
|
|
|
|
}
|
2020-02-17 10:17:53 +08:00
|
|
|
close STDOUT or die "error closing STDOUT: $!";
|
2009-12-28 04:49:40 +08:00
|
|
|
|