提交 932cc129 编写于 作者: A Andy Polyakov

x86_64 assembler updates.

上级 1a42839b
...@@ -57,7 +57,13 @@ ...@@ -57,7 +57,13 @@
# lea .Label-.Lpic_point(%rcx),%rbp # lea .Label-.Lpic_point(%rcx),%rbp
my $output = shift; my $output = shift;
open STDOUT,">$output" || die "can't open $output: $!";
{ 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 $masm=1 if ($output =~ /\.asm/); my $masm=1 if ($output =~ /\.asm/);
...@@ -70,7 +76,7 @@ my $current_function; ...@@ -70,7 +76,7 @@ my $current_function;
local *line = shift; local *line = shift;
undef $ret; undef $ret;
if ($line =~ /^([a-z]+)/i) { if ($line =~ /^([a-z][a-z0-9]*)/i) {
$self->{op} = $1; $self->{op} = $1;
$ret = $self; $ret = $self;
$line = substr($line,@+[0]); $line =~ s/^\s+//; $line = substr($line,@+[0]); $line =~ s/^\s+//;
...@@ -95,8 +101,10 @@ my $current_function; ...@@ -95,8 +101,10 @@ my $current_function;
sub out { sub out {
my $self = shift; my $self = shift;
if (!$masm) { 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; sprintf "%s%s%s",$self->{op},$self->{sz},shift;
} elsif ($self->{op} =~ /^set/) {
"$self->{op}";
} elsif ($self->{op} eq "ret") { } elsif ($self->{op} eq "ret") {
".byte 0xf3,0xc3"; ".byte 0xf3,0xc3";
} else { } else {
...@@ -198,6 +206,8 @@ my $current_function; ...@@ -198,6 +206,8 @@ my $current_function;
$self->{label}, $self->{label},
$self->{index},$self->{scale}, $self->{index},$self->{scale},
$self->{base}; $self->{base};
} elsif ($self->{base} eq "rip") {
sprintf "%s PTR %s",$szmap{$sz},$self->{label};
} else { } else {
sprintf "%s PTR %s[%s]",$szmap{$sz}, sprintf "%s PTR %s[%s]",$szmap{$sz},
$self->{label},$self->{base}; $self->{label},$self->{base};
...@@ -325,6 +335,8 @@ my $current_function; ...@@ -325,6 +335,8 @@ my $current_function;
$self->{value} = sprintf "\t.long\t0x%x,0x90000000",$opcode{$1}; $self->{value} = sprintf "\t.long\t0x%x,0x90000000",$opcode{$1};
} elsif ($line =~ /\.asciz\s+"(.*)"$/) { } elsif ($line =~ /\.asciz\s+"(.*)"$/) {
$self->{value} = ".byte\t".join(",",unpack("C*",$1),0); $self->{value} = ".byte\t".join(",",unpack("C*",$1),0);
} elsif ($line =~ /\.extern/) {
$self->{value} = ""; # swallow extern
} else { } else {
$self->{value} = $line; $self->{value} = $line;
} }
...@@ -346,6 +358,7 @@ my $current_function; ...@@ -346,6 +358,7 @@ my $current_function;
$self->{value} = $v; $self->{value} = $v;
last; last;
}; };
/\.extern/ && do { $self->{value} = "EXTRN\t".$line; last; };
/\.globl/ && do { $self->{value} = "PUBLIC\t".$line; last; }; /\.globl/ && do { $self->{value} = "PUBLIC\t".$line; last; };
/\.type/ && do { ($sym,$type,$narg) = split(',',$line); /\.type/ && do { ($sym,$type,$narg) = split(',',$line);
if ($type eq "\@function") { if ($type eq "\@function") {
......
#!/usr/bin/env perl #!/usr/bin/env perl
$output=shift; $output=shift;
$win64a=1 if ($output =~ /win64a\.[s|asm]/); $masm=1 if ($output =~ /\.asm/);
open STDOUT,">$output" || die "can't open $output: $!"; open STDOUT,">$output" || die "can't open $output: $!";
print<<___ if(defined($win64a)); print<<___ if(defined($masm));
_TEXT SEGMENT _TEXT SEGMENT
PUBLIC OPENSSL_rdtsc PUBLIC OPENSSL_rdtsc
ALIGN 16
OPENSSL_rdtsc PROC
rdtsc
shl rdx,32
or rax,rdx
ret
OPENSSL_rdtsc ENDP
PUBLIC OPENSSL_atomic_add PUBLIC OPENSSL_atomic_add
ALIGN 16 ALIGN 16
...@@ -45,64 +38,16 @@ OPENSSL_wipe_cpu PROC ...@@ -45,64 +38,16 @@ OPENSSL_wipe_cpu PROC
lea rax,QWORD PTR[rsp+8] lea rax,QWORD PTR[rsp+8]
ret ret
OPENSSL_wipe_cpu ENDP OPENSSL_wipe_cpu ENDP
OPENSSL_ia32_cpuid PROC
mov r8,rbx
xor eax,eax
cpuid
xor eax,eax
cmp ebx,0756e6547h
setne al
mov r9d,eax
cmp edx,049656e69h
setne al
or r9d,eax
cmp ecx,06c65746eh
setne al
or r9d,eax
mov eax,1
cpuid
bt edx,28
jnc \$Ldone
cmp r9,0
jne \$Lnotintel
or edx,000100000h
and ah,15
cmp ah,15
je \$Lnotintel
or edx,040000000h
\$Lnotintel:
shr ebx,16
cmp bl,1
ja \$Ldone
and edx,0efffffffh
\$Ldone:
shl rcx,32
mov eax,edx
mov rbx,r8
or rax,rcx
ret
OPENSSL_ia32_cpuid ENDP
_TEXT ENDS _TEXT ENDS
CRT\$XIU SEGMENT CRT\$XIU SEGMENT
EXTRN OPENSSL_cpuid_setup:PROC EXTRN OPENSSL_cpuid_setup:PROC
DQ OPENSSL_cpuid_setup DQ OPENSSL_cpuid_setup
CRT\$XIU ENDS CRT\$XIU ENDS
END
___ ___
print<<___ if(!defined($win64a)); print<<___ if(!defined($masm));
.text .text
.globl OPENSSL_rdtsc
.align 16
OPENSSL_rdtsc:
rdtsc
shlq \$32,%rdx
orq %rdx,%rax
ret
.size OPENSSL_rdtsc,.-OPENSSL_rdtsc
.globl OPENSSL_atomic_add .globl OPENSSL_atomic_add
.type OPENSSL_atomic_add,\@function .type OPENSSL_atomic_add,\@function
...@@ -149,10 +94,30 @@ OPENSSL_wipe_cpu: ...@@ -149,10 +94,30 @@ OPENSSL_wipe_cpu:
ret ret
.size OPENSSL_wipe_cpu,.-OPENSSL_wipe_cpu .size OPENSSL_wipe_cpu,.-OPENSSL_wipe_cpu
.section .init
call OPENSSL_cpuid_setup
___
open STDOUT,"| $^X perlasm/x86_64-xlate.pl $output";
print<<___;
.text
.globl OPENSSL_rdtsc
.type OPENSSL_rdtsc,\@abi-omnipotent
.align 16
OPENSSL_rdtsc:
rdtsc
shl \$32,%rdx
or %rdx,%rax
ret
.size OPENSSL_rdtsc,.-OPENSSL_rdtsc
.globl OPENSSL_ia32_cpuid .globl OPENSSL_ia32_cpuid
.type OPENSSL_ia32_cpuid,\@abi-omnipotent
.align 16 .align 16
OPENSSL_ia32_cpuid: OPENSSL_ia32_cpuid:
movq %rbx,%r8 mov %rbx,%r8
xor %eax,%eax xor %eax,%eax
cpuid cpuid
...@@ -167,11 +132,11 @@ OPENSSL_ia32_cpuid: ...@@ -167,11 +132,11 @@ OPENSSL_ia32_cpuid:
setne %al setne %al
or %eax,%r9d or %eax,%r9d
movl \$1,%eax mov \$1,%eax
cpuid cpuid
bt \$28,%edx # test hyper-threading bit bt \$28,%edx # test hyper-threading bit
jnc .Ldone jnc .Ldone
cmp \$0,%r9 cmp \$0,%r9d
jne .Lnotintel jne .Lnotintel
or \$1<<20,%edx # use reserved bit to engage RC4_CHAR or \$1<<20,%edx # use reserved bit to engage RC4_CHAR
and \$15,%ah and \$15,%ah
...@@ -182,15 +147,12 @@ OPENSSL_ia32_cpuid: ...@@ -182,15 +147,12 @@ OPENSSL_ia32_cpuid:
shr \$16,%ebx shr \$16,%ebx
cmp \$1,%bl # see if cache is shared cmp \$1,%bl # see if cache is shared
ja .Ldone ja .Ldone
and \$~(1<<28),%edx and \$0xefffffff,%edx # ~(1<<28)
.Ldone: .Ldone:
shlq \$32,%rcx shl \$32,%rcx
movl %edx,%eax mov %edx,%eax
movq %r8,%rbx mov %r8,%rbx
orq %rcx,%rax or %rcx,%rax
ret ret
.size OPENSSL_ia32_cpuid,.-OPENSSL_ia32_cpuid .size OPENSSL_ia32_cpuid,.-OPENSSL_ia32_cpuid
.section .init
call OPENSSL_cpuid_setup
___ ___
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册