summaryrefslogtreecommitdiffstats
path: root/crypto/perlasm
diff options
context:
space:
mode:
authorsimon <simon@FreeBSD.org>2008-09-21 14:56:30 +0000
committersimon <simon@FreeBSD.org>2008-09-21 14:56:30 +0000
commit859b6dcfcc8295a0eac4afbc70e4d42aa512674a (patch)
treea136b5b2317abe8eb83b021afe5e088230fd67e2 /crypto/perlasm
parentfe745806aa8bec66ca79fe8f032ad472261ba789 (diff)
downloadFreeBSD-src-859b6dcfcc8295a0eac4afbc70e4d42aa512674a.zip
FreeBSD-src-859b6dcfcc8295a0eac4afbc70e4d42aa512674a.tar.gz
Vendor import of OpenSSL 0.9.8i.
Diffstat (limited to 'crypto/perlasm')
-rwxr-xr-xcrypto/perlasm/x86_64-xlate.pl80
-rw-r--r--crypto/perlasm/x86ms.pl30
-rw-r--r--crypto/perlasm/x86nasm.pl4
-rw-r--r--crypto/perlasm/x86unix.pl42
4 files changed, 90 insertions, 66 deletions
diff --git a/crypto/perlasm/x86_64-xlate.pl b/crypto/perlasm/x86_64-xlate.pl
index ef1a4ce..a4af769 100755
--- a/crypto/perlasm/x86_64-xlate.pl
+++ b/crypto/perlasm/x86_64-xlate.pl
@@ -57,9 +57,18 @@
# lea .Label-.Lpic_point(%rcx),%rbp
my $output = shift;
-open STDOUT,">$output" || die "can't open $output: $!";
-my $masm=1 if ($output =~ /\.asm/);
+{ my ($stddev,$stdino,@junk)=stat(STDOUT);
+ my ($outdev,$outino,@junk)=stat($output);
+
+ open STDOUT,">$output" || die "can't open $output: $!"
+ if ($stddev!=$outdev || $stdino!=$outino);
+}
+
+my $masmref=8 + 50727*2**-32; # 8.00.50727 shipped with VS2005
+my $masm=$masmref if ($output =~ /\.asm/);
+if ($masm && `ml64 2>&1` =~ m/Version ([0-9]+)\.([0-9]+)(\.([0-9]+))?/)
+{ $masm=$1 + $2*2**-16 + $4*2**-32; }
my $current_segment;
my $current_function;
@@ -70,16 +79,18 @@ my $current_function;
local *line = shift;
undef $ret;
- if ($line =~ /^([a-z]+)/i) {
+ if ($line =~ /^([a-z][a-z0-9]*)/i) {
$self->{op} = $1;
$ret = $self;
$line = substr($line,@+[0]); $line =~ s/^\s+//;
undef $self->{sz};
- if ($self->{op} =~ /(movz)b.*/) { # movz is pain...
+ if ($self->{op} =~ /^(movz)b.*/) { # movz is pain...
$self->{op} = $1;
$self->{sz} = "b";
- } elsif ($self->{op} =~ /([a-z]{3,})([qlwb])/) {
+ } elsif ($self->{op} =~ /call/) {
+ $self->{sz} = ""
+ } elsif ($self->{op} =~ /([a-z]{3,})([qlwb])$/) {
$self->{op} = $1;
$self->{sz} = $2;
}
@@ -95,15 +106,17 @@ my $current_function;
sub out {
my $self = shift;
if (!$masm) {
- if ($self->{op} eq "movz") { # movz in pain...
+ if ($self->{op} eq "movz") { # movz is pain...
sprintf "%s%s%s",$self->{op},$self->{sz},shift;
+ } elsif ($self->{op} =~ /^set/) {
+ "$self->{op}";
} elsif ($self->{op} eq "ret") {
".byte 0xf3,0xc3";
} else {
"$self->{op}$self->{sz}";
}
} else {
- $self->{op} =~ s/movz/movzx/;
+ $self->{op} =~ s/^movz/movzx/;
if ($self->{op} eq "ret") {
$self->{op} = "";
if ($current_function->{abi} eq "svr4") {
@@ -133,6 +146,10 @@ my $current_function;
my $self = shift;
if (!$masm) {
+ # Solaris /usr/ccs/bin/as can't handle multiplications
+ # in $self->{value}
+ $self->{value} =~ s/(?<![0-9a-f])(0[x0-9a-f]+)/oct($1)/egi;
+ $self->{value} =~ s/([0-9]+\s*[\*\/\%]\s*[0-9]+)/eval($1)/eg;
sprintf "\$%s",$self->{value};
} else {
$self->{value} =~ s/0x([0-9a-f]+)/0$1h/ig;
@@ -163,14 +180,16 @@ my $current_function;
my $self = shift;
my $sz = shift;
+ # Silently convert all EAs to 64-bit. This is required for
+ # elder GNU assembler and results in more compact code,
+ # *but* most importantly AES module depends on this feature!
+ $self->{index} =~ s/^[er](.?[0-9xpi])[d]?$/r\1/;
+ $self->{base} =~ s/^[er](.?[0-9xpi])[d]?$/r\1/;
+
if (!$masm) {
- # elder GNU assembler insists on 64-bit EAs:-(
- # on pros side, this results in more compact code:-)
- $self->{index} =~ s/^[er](.?[0-9xp])[d]?$/r\1/;
- $self->{base} =~ s/^[er](.?[0-9xp])[d]?$/r\1/;
# Solaris /usr/ccs/bin/as can't handle multiplications
# in $self->{label}
- $self->{label} =~ s/(?<![0-9a-f])(0[x0-9a-f]+)/oct($1)/eg;
+ $self->{label} =~ s/(?<![0-9a-f])(0[x0-9a-f]+)/oct($1)/egi;
$self->{label} =~ s/([0-9]+\s*[\*\/\%]\s*[0-9]+)/eval($1)/eg;
if (defined($self->{index})) {
@@ -192,6 +211,8 @@ my $current_function;
$self->{label},
$self->{index},$self->{scale},
$self->{base};
+ } elsif ($self->{base} eq "rip") {
+ sprintf "%s PTR %s",$szmap{$sz},$self->{label};
} else {
sprintf "%s PTR %s[%s]",$szmap{$sz},
$self->{label},$self->{base};
@@ -317,6 +338,10 @@ my $current_function;
$line =~ s/\@function.*/\@function/;
if ($line =~ /\.picmeup\s+(%r[\w]+)/i) {
$self->{value} = sprintf "\t.long\t0x%x,0x90000000",$opcode{$1};
+ } elsif ($line =~ /\.asciz\s+"(.*)"$/) {
+ $self->{value} = ".byte\t".join(",",unpack("C*",$1),0);
+ } elsif ($line =~ /\.extern/) {
+ $self->{value} = ""; # swallow extern
} else {
$self->{value} = $line;
}
@@ -334,10 +359,13 @@ my $current_function;
$v="$current_segment\tENDS\n" if ($current_segment);
$current_segment = "_$1\$";
$current_segment =~ tr/[a-z]/[A-Z]/;
- $v.="$current_segment\tSEGMENT ALIGN(64) 'CODE'";
+ $v.="$current_segment\tSEGMENT ";
+ $v.=$masm>=$masmref ? "ALIGN(64)" : "PAGE";
+ $v.=" 'CODE'";
$self->{value} = $v;
last;
};
+ /\.extern/ && do { $self->{value} = "EXTRN\t".$line.":BYTE"; last; };
/\.globl/ && do { $self->{value} = "PUBLIC\t".$line; last; };
/\.type/ && do { ($sym,$type,$narg) = split(',',$line);
if ($type eq "\@function") {
@@ -362,16 +390,33 @@ my $current_function;
&& do { my @arr = split(',',$line);
my $sz = substr($1,0,1);
my $last = pop(@arr);
+ my $conv = sub { my $var=shift;
+ if ($var=~s/0x([0-9a-f]+)/0$1h/i) { $var; }
+ else { sprintf"0%Xh",$var; }
+ };
$sz =~ tr/bvlq/BWDQ/;
$self->{value} = "\tD$sz\t";
- for (@arr) { $self->{value} .= sprintf"0%Xh,",oct; }
- $self->{value} .= sprintf"0%Xh",oct($last);
+ for (@arr) { $self->{value} .= &$conv($_).","; }
+ $self->{value} .= &$conv($last);
last;
};
/\.picmeup/ && do { $self->{value} = sprintf"\tDD\t 0%Xh,090000000h",$opcode{$line};
last;
};
+ /\.asciz/ && do { if ($line =~ /^"(.*)"$/) {
+ my @str=unpack("C*",$1);
+ push @str,0;
+ while ($#str>15) {
+ $self->{value}.="DB\t"
+ .join(",",@str[0..15])."\n";
+ foreach (0..15) { shift @str; }
+ }
+ $self->{value}.="DB\t"
+ .join(",",@str) if (@str);
+ }
+ last;
+ };
}
$line = "";
}
@@ -480,7 +525,10 @@ close STDOUT;
# arguments passed to callee, *but* not less than 4! This means that
# upon function entry point 5th argument resides at 40(%rsp), as well
# as that 32 bytes from 8(%rsp) can always be used as temporal
-# storage [without allocating a frame].
+# storage [without allocating a frame]. One can actually argue that
+# one can assume a "red zone" above stack pointer under Win64 as well.
+# Point is that at apparently no occasion Windows kernel would alter
+# the area above user stack pointer in true asynchronous manner...
#
# All the above means that if assembler programmer adheres to Unix
# register and stack layout, but disregards the "red zone" existense,
diff --git a/crypto/perlasm/x86ms.pl b/crypto/perlasm/x86ms.pl
index 82538a9..a0be293 100644
--- a/crypto/perlasm/x86ms.pl
+++ b/crypto/perlasm/x86ms.pl
@@ -146,6 +146,7 @@ sub main'exch { &out2("xchg",@_); }
sub main'cmp { &out2("cmp",@_); }
sub main'lea { &out2("lea",@_); }
sub main'mul { &out1("mul",@_); }
+sub main'imul { &out2("imul",@_); }
sub main'div { &out1("div",@_); }
sub main'dec { &out1("dec",@_); }
sub main'inc { &out1("inc",@_); }
@@ -204,16 +205,17 @@ sub main'pand { &out2("pand",@_); }
sub out2
{
local($name,$p1,$p2)=@_;
- local($l,$t);
+ local($l,$t,$line);
- push(@out,"\t$name\t");
+ $line="\t$name\t";
$t=&conv($p1).",";
$l=length($t);
- push(@out,$t);
+ $line.="$t";
$l=4-($l+9)/8;
- push(@out,"\t" x $l);
- push(@out,&conv($p2));
- push(@out,"\n");
+ $line.="\t" x $l;
+ $line.=&conv($p2);
+ if ($line=~/\bxmm[0-7]\b/i) { $line=~s/\b[A-Z]+WORD\s+PTR/XMMWORD PTR/i; }
+ push(@out,$line."\n");
}
sub out0
@@ -338,11 +340,17 @@ EOF
sub main'file_end
{
# try to detect if SSE2 or MMX extensions were used...
- if (grep {/xmm[0-7]\s*,/i} @out) {
- grep {s/\.[3-7]86/\.686\n\t\.XMM/} @out;
- }
- elsif (grep {/mm[0-7]\s*,/i} @out) {
- grep {s/\.[3-7]86/\.686\n\t\.MMX/} @out;
+ my $xmmheader=<<___;
+.686
+.XMM
+IF \@Version LT 800
+XMMWORD STRUCT 16
+ DQ 2 dup (?)
+XMMWORD ENDS
+ENDIF
+___
+ if (grep {/\b[x]?mm[0-7]\b/i} @out) {
+ grep {s/\.[3-7]86/$xmmheader/} @out;
}
push(@out,"_TEXT\$ ENDS\n");
push(@out,"END\n");
diff --git a/crypto/perlasm/x86nasm.pl b/crypto/perlasm/x86nasm.pl
index b6dfcbd..fa38f89 100644
--- a/crypto/perlasm/x86nasm.pl
+++ b/crypto/perlasm/x86nasm.pl
@@ -154,6 +154,7 @@ sub main'exch { &out2("xchg",@_); }
sub main'cmp { &out2("cmp",@_); }
sub main'lea { &out2("lea",@_); }
sub main'mul { &out1("mul",@_); }
+sub main'imul { &out2("imul",@_); }
sub main'div { &out1("div",@_); }
sub main'dec { &out1("dec",@_); }
sub main'inc { &out1("inc",@_); }
@@ -281,6 +282,7 @@ sub main'function_begin
my($func,$extra)=@_;
push(@labels,$func);
+ push(@out,".") if ($main'mwerks);
my($tmp)=<<"EOF";
global $under$func
$under$func:
@@ -296,6 +298,7 @@ EOF
sub main'function_begin_B
{
my($func,$extra)=@_;
+ push(@out,".") if ($main'mwerks);
my($tmp)=<<"EOF";
global $under$func
$under$func:
@@ -375,6 +378,7 @@ sub main'comment
sub main'public_label
{
$label{$_[0]}="${under}${_[0]}" if (!defined($label{$_[0]}));
+ push(@out,".") if ($main'mwerks);
push(@out,"global\t$label{$_[0]}\n");
}
diff --git a/crypto/perlasm/x86unix.pl b/crypto/perlasm/x86unix.pl
index e71050b..a4c9471 100644
--- a/crypto/perlasm/x86unix.pl
+++ b/crypto/perlasm/x86unix.pl
@@ -171,6 +171,7 @@ sub main'exch { &out2($_[0]=~/%[a-d][lh]/?"xchgb":"xchgl",@_); }
sub main'cmp { &out2("cmpl",@_); }
sub main'lea { &out2("leal",@_); }
sub main'mul { &out1("mull",@_); }
+sub main'imul { &out2("imull",@_); }
sub main'div { &out1("divl",@_); }
sub main'jmp { &out1("jmp",@_); }
sub main'jmp_ptr { &out1p("jmp",@_); }
@@ -541,50 +542,13 @@ sub main'set_label
sub main'file_end
{
# try to detect if SSE2 or MMX extensions were used on ELF platform...
- if ($main'elf && grep {/%[x]*mm[0-7]/i} @out) {
+ if ($main'elf && grep {/\b%[x]*mm[0-7]\b|OPENSSL_ia32cap_P\b/i} @out) {
local($tmp);
push (@out,"\n.section\t.bss\n");
push (@out,".comm\t${under}OPENSSL_ia32cap_P,4,4\n");
- push (@out,".section\t.init\n");
- # One can argue that it's wasteful to craft every
- # SSE/MMX module with this snippet... Well, it's 72
- # bytes long and for the moment we have two modules.
- # Let's argue when we have 7 modules or so...
- #
- # $1<<10 sets a reserved bit to signal that variable
- # was initialized already...
- &main'picmeup("edx","OPENSSL_ia32cap_P");
- $tmp=<<___;
- cmpl \$0,(%edx)
- jne 1f
- movl \$1<<10,(%edx)
- pushf
- popl %eax
- movl %eax,%ecx
- xorl \$1<<21,%eax
- pushl %eax
- popf
- pushf
- popl %eax
- xorl %ecx,%eax
- btl \$21,%eax
- jnc 1f
- pushl %edi
- pushl %ebx
- movl %edx,%edi
- movl \$1,%eax
- .byte 0x0f,0xa2
- orl \$1<<10,%edx
- movl %edx,0(%edi)
- popl %ebx
- popl %edi
- jmp 1f
- .align $align
- 1:
-___
- push (@out,$tmp);
+ return;
}
if ($const ne "")
OpenPOWER on IntegriCloud