diff options
Diffstat (limited to 'src/lib/libcrypto/perlasm')
| -rwxr-xr-x | src/lib/libcrypto/perlasm/x86_64-xlate.pl | 221 | ||||
| -rw-r--r-- | src/lib/libcrypto/perlasm/x86asm.pl | 55 | ||||
| -rw-r--r-- | src/lib/libcrypto/perlasm/x86gas.pl | 31 | ||||
| -rw-r--r-- | src/lib/libcrypto/perlasm/x86nasm.pl | 15 |
4 files changed, 277 insertions, 45 deletions
diff --git a/src/lib/libcrypto/perlasm/x86_64-xlate.pl b/src/lib/libcrypto/perlasm/x86_64-xlate.pl index 68b4c1ca80..50ff91e2f0 100755 --- a/src/lib/libcrypto/perlasm/x86_64-xlate.pl +++ b/src/lib/libcrypto/perlasm/x86_64-xlate.pl | |||
| @@ -62,12 +62,8 @@ my $flavour = shift; | |||
| 62 | my $output = shift; | 62 | my $output = shift; |
| 63 | if ($flavour =~ /\./) { $output = $flavour; undef $flavour; } | 63 | if ($flavour =~ /\./) { $output = $flavour; undef $flavour; } |
| 64 | 64 | ||
| 65 | { my ($stddev,$stdino,@junk)=stat(STDOUT); | 65 | open STDOUT,">$output" || die "can't open $output: $!" |
| 66 | my ($outdev,$outino,@junk)=stat($output); | 66 | if (defined($output)); |
| 67 | |||
| 68 | open STDOUT,">$output" || die "can't open $output: $!" | ||
| 69 | if (1 || $stddev!=$outdev || $stdino!=$outino); | ||
| 70 | } | ||
| 71 | 67 | ||
| 72 | my $gas=1; $gas=0 if ($output =~ /\.asm$/); | 68 | my $gas=1; $gas=0 if ($output =~ /\.asm$/); |
| 73 | my $elf=1; $elf=0 if (!$gas); | 69 | my $elf=1; $elf=0 if (!$gas); |
| @@ -116,12 +112,16 @@ my %globals; | |||
| 116 | $line = substr($line,@+[0]); $line =~ s/^\s+//; | 112 | $line = substr($line,@+[0]); $line =~ s/^\s+//; |
| 117 | 113 | ||
| 118 | undef $self->{sz}; | 114 | undef $self->{sz}; |
| 119 | if ($self->{op} =~ /^(movz)b.*/) { # movz is pain... | 115 | if ($self->{op} =~ /^(movz)x?([bw]).*/) { # movz is pain... |
| 120 | $self->{op} = $1; | 116 | $self->{op} = $1; |
| 121 | $self->{sz} = "b"; | 117 | $self->{sz} = $2; |
| 122 | } elsif ($self->{op} =~ /call|jmp/) { | 118 | } elsif ($self->{op} =~ /call|jmp/) { |
| 123 | $self->{sz} = ""; | 119 | $self->{sz} = ""; |
| 124 | } elsif ($self->{op} =~ /^p/ && $' !~ /^(ush|op)/) { # SSEn | 120 | } elsif ($self->{op} =~ /^p/ && $' !~ /^(ush|op|insrw)/) { # SSEn |
| 121 | $self->{sz} = ""; | ||
| 122 | } elsif ($self->{op} =~ /^v/) { # VEX | ||
| 123 | $self->{sz} = ""; | ||
| 124 | } elsif ($self->{op} =~ /movq/ && $line =~ /%xmm/) { | ||
| 125 | $self->{sz} = ""; | 125 | $self->{sz} = ""; |
| 126 | } elsif ($self->{op} =~ /([a-z]{3,})([qlwb])$/) { | 126 | } elsif ($self->{op} =~ /([a-z]{3,})([qlwb])$/) { |
| 127 | $self->{op} = $1; | 127 | $self->{op} = $1; |
| @@ -247,35 +247,39 @@ my %globals; | |||
| 247 | $self->{index} =~ s/^[er](.?[0-9xpi])[d]?$/r\1/; | 247 | $self->{index} =~ s/^[er](.?[0-9xpi])[d]?$/r\1/; |
| 248 | $self->{base} =~ s/^[er](.?[0-9xpi])[d]?$/r\1/; | 248 | $self->{base} =~ s/^[er](.?[0-9xpi])[d]?$/r\1/; |
| 249 | 249 | ||
| 250 | # Solaris /usr/ccs/bin/as can't handle multiplications | ||
| 251 | # in $self->{label}, new gas requires sign extension... | ||
| 252 | use integer; | ||
| 253 | $self->{label} =~ s/(?<![\w\$\.])(0x?[0-9a-f]+)/oct($1)/egi; | ||
| 254 | $self->{label} =~ s/([0-9]+\s*[\*\/\%]\s*[0-9]+)/eval($1)/eg; | ||
| 255 | $self->{label} =~ s/([0-9]+)/$1<<32>>32/eg; | ||
| 256 | |||
| 250 | if ($gas) { | 257 | if ($gas) { |
| 251 | # Solaris /usr/ccs/bin/as can't handle multiplications | ||
| 252 | # in $self->{label}, new gas requires sign extension... | ||
| 253 | use integer; | ||
| 254 | $self->{label} =~ s/(?<![\w\$\.])(0x?[0-9a-f]+)/oct($1)/egi; | ||
| 255 | $self->{label} =~ s/([0-9]+\s*[\*\/\%]\s*[0-9]+)/eval($1)/eg; | ||
| 256 | $self->{label} =~ s/([0-9]+)/$1<<32>>32/eg; | ||
| 257 | $self->{label} =~ s/^___imp_/__imp__/ if ($flavour eq "mingw64"); | 258 | $self->{label} =~ s/^___imp_/__imp__/ if ($flavour eq "mingw64"); |
| 258 | 259 | ||
| 259 | if (defined($self->{index})) { | 260 | if (defined($self->{index})) { |
| 260 | sprintf "%s%s(%%%s,%%%s,%d)",$self->{asterisk}, | 261 | sprintf "%s%s(%s,%%%s,%d)",$self->{asterisk}, |
| 261 | $self->{label},$self->{base}, | 262 | $self->{label}, |
| 263 | $self->{base}?"%$self->{base}":"", | ||
| 262 | $self->{index},$self->{scale}; | 264 | $self->{index},$self->{scale}; |
| 263 | } else { | 265 | } else { |
| 264 | sprintf "%s%s(%%%s)", $self->{asterisk},$self->{label},$self->{base}; | 266 | sprintf "%s%s(%%%s)", $self->{asterisk},$self->{label},$self->{base}; |
| 265 | } | 267 | } |
| 266 | } else { | 268 | } else { |
| 267 | %szmap = ( b=>"BYTE$PTR", w=>"WORD$PTR", l=>"DWORD$PTR", q=>"QWORD$PTR" ); | 269 | %szmap = ( b=>"BYTE$PTR", w=>"WORD$PTR", l=>"DWORD$PTR", |
| 270 | q=>"QWORD$PTR",o=>"OWORD$PTR",x=>"XMMWORD$PTR" ); | ||
| 268 | 271 | ||
| 269 | $self->{label} =~ s/\./\$/g; | 272 | $self->{label} =~ s/\./\$/g; |
| 270 | $self->{label} =~ s/(?<![\w\$\.])0x([0-9a-f]+)/0$1h/ig; | 273 | $self->{label} =~ s/(?<![\w\$\.])0x([0-9a-f]+)/0$1h/ig; |
| 271 | $self->{label} = "($self->{label})" if ($self->{label} =~ /[\*\+\-\/]/); | 274 | $self->{label} = "($self->{label})" if ($self->{label} =~ /[\*\+\-\/]/); |
| 272 | $sz="q" if ($self->{asterisk}); | 275 | $sz="q" if ($self->{asterisk} || opcode->mnemonic() eq "movq"); |
| 276 | $sz="l" if (opcode->mnemonic() eq "movd"); | ||
| 273 | 277 | ||
| 274 | if (defined($self->{index})) { | 278 | if (defined($self->{index})) { |
| 275 | sprintf "%s[%s%s*%d+%s]",$szmap{$sz}, | 279 | sprintf "%s[%s%s*%d%s]",$szmap{$sz}, |
| 276 | $self->{label}?"$self->{label}+":"", | 280 | $self->{label}?"$self->{label}+":"", |
| 277 | $self->{index},$self->{scale}, | 281 | $self->{index},$self->{scale}, |
| 278 | $self->{base}; | 282 | $self->{base}?"+$self->{base}":""; |
| 279 | } elsif ($self->{base} eq "rip") { | 283 | } elsif ($self->{base} eq "rip") { |
| 280 | sprintf "%s[%s]",$szmap{$sz},$self->{label}; | 284 | sprintf "%s[%s]",$szmap{$sz},$self->{label}; |
| 281 | } else { | 285 | } else { |
| @@ -507,6 +511,12 @@ my %globals; | |||
| 507 | } | 511 | } |
| 508 | } elsif ($dir =~ /\.(text|data)/) { | 512 | } elsif ($dir =~ /\.(text|data)/) { |
| 509 | $current_segment=".$1"; | 513 | $current_segment=".$1"; |
| 514 | } elsif ($dir =~ /\.hidden/) { | ||
| 515 | if ($flavour eq "macosx") { $self->{value} = ".private_extern\t$prefix$line"; } | ||
| 516 | elsif ($flavour eq "mingw64") { $self->{value} = ""; } | ||
| 517 | } elsif ($dir =~ /\.comm/) { | ||
| 518 | $self->{value} = "$dir\t$prefix$line"; | ||
| 519 | $self->{value} =~ s|,([0-9]+),([0-9]+)$|",$1,".log($2)/log(2)|e if ($flavour eq "macosx"); | ||
| 510 | } | 520 | } |
| 511 | $line = ""; | 521 | $line = ""; |
| 512 | return $self; | 522 | return $self; |
| @@ -556,7 +566,8 @@ my %globals; | |||
| 556 | $v.=" READONLY"; | 566 | $v.=" READONLY"; |
| 557 | $v.=" ALIGN(".($1 eq "p" ? 4 : 8).")" if ($masm>=$masmref); | 567 | $v.=" ALIGN(".($1 eq "p" ? 4 : 8).")" if ($masm>=$masmref); |
| 558 | } elsif ($line=~/\.CRT\$/i) { | 568 | } elsif ($line=~/\.CRT\$/i) { |
| 559 | $v.=" READONLY DWORD"; | 569 | $v.=" READONLY "; |
| 570 | $v.=$masm>=$masmref ? "ALIGN(8)" : "DWORD"; | ||
| 560 | } | 571 | } |
| 561 | } | 572 | } |
| 562 | $current_segment = $line; | 573 | $current_segment = $line; |
| @@ -578,7 +589,7 @@ my %globals; | |||
| 578 | $self->{value}="${decor}SEH_end_$current_function->{name}:"; | 589 | $self->{value}="${decor}SEH_end_$current_function->{name}:"; |
| 579 | $self->{value}.=":\n" if($masm); | 590 | $self->{value}.=":\n" if($masm); |
| 580 | } | 591 | } |
| 581 | $self->{value}.="$current_function->{name}\tENDP" if($masm); | 592 | $self->{value}.="$current_function->{name}\tENDP" if($masm && $current_function->{name}); |
| 582 | undef $current_function; | 593 | undef $current_function; |
| 583 | } | 594 | } |
| 584 | last; | 595 | last; |
| @@ -614,6 +625,19 @@ my %globals; | |||
| 614 | .join(",",@str) if (@str); | 625 | .join(",",@str) if (@str); |
| 615 | last; | 626 | last; |
| 616 | }; | 627 | }; |
| 628 | /\.comm/ && do { my @str=split(/,\s*/,$line); | ||
| 629 | my $v=undef; | ||
| 630 | if ($nasm) { | ||
| 631 | $v.="common $prefix@str[0] @str[1]"; | ||
| 632 | } else { | ||
| 633 | $v="$current_segment\tENDS\n" if ($current_segment); | ||
| 634 | $current_segment = "_DATA"; | ||
| 635 | $v.="$current_segment\tSEGMENT\n"; | ||
| 636 | $v.="COMM @str[0]:DWORD:".@str[1]/4; | ||
| 637 | } | ||
| 638 | $self->{value} = $v; | ||
| 639 | last; | ||
| 640 | }; | ||
| 617 | } | 641 | } |
| 618 | $line = ""; | 642 | $line = ""; |
| 619 | } | 643 | } |
| @@ -626,11 +650,135 @@ my %globals; | |||
| 626 | } | 650 | } |
| 627 | } | 651 | } |
| 628 | 652 | ||
| 653 | sub rex { | ||
| 654 | local *opcode=shift; | ||
| 655 | my ($dst,$src,$rex)=@_; | ||
| 656 | |||
| 657 | $rex|=0x04 if($dst>=8); | ||
| 658 | $rex|=0x01 if($src>=8); | ||
| 659 | push @opcode,($rex|0x40) if ($rex); | ||
| 660 | } | ||
| 661 | |||
| 662 | # older gas and ml64 don't handle SSE>2 instructions | ||
| 663 | my %regrm = ( "%eax"=>0, "%ecx"=>1, "%edx"=>2, "%ebx"=>3, | ||
| 664 | "%esp"=>4, "%ebp"=>5, "%esi"=>6, "%edi"=>7 ); | ||
| 665 | |||
| 666 | my $movq = sub { # elderly gas can't handle inter-register movq | ||
| 667 | my $arg = shift; | ||
| 668 | my @opcode=(0x66); | ||
| 669 | if ($arg =~ /%xmm([0-9]+),\s*%r(\w+)/) { | ||
| 670 | my ($src,$dst)=($1,$2); | ||
| 671 | if ($dst !~ /[0-9]+/) { $dst = $regrm{"%e$dst"}; } | ||
| 672 | rex(\@opcode,$src,$dst,0x8); | ||
| 673 | push @opcode,0x0f,0x7e; | ||
| 674 | push @opcode,0xc0|(($src&7)<<3)|($dst&7); # ModR/M | ||
| 675 | @opcode; | ||
| 676 | } elsif ($arg =~ /%r(\w+),\s*%xmm([0-9]+)/) { | ||
| 677 | my ($src,$dst)=($2,$1); | ||
| 678 | if ($dst !~ /[0-9]+/) { $dst = $regrm{"%e$dst"}; } | ||
| 679 | rex(\@opcode,$src,$dst,0x8); | ||
| 680 | push @opcode,0x0f,0x6e; | ||
| 681 | push @opcode,0xc0|(($src&7)<<3)|($dst&7); # ModR/M | ||
| 682 | @opcode; | ||
| 683 | } else { | ||
| 684 | (); | ||
| 685 | } | ||
| 686 | }; | ||
| 687 | |||
| 688 | my $pextrd = sub { | ||
| 689 | if (shift =~ /\$([0-9]+),\s*%xmm([0-9]+),\s*(%\w+)/) { | ||
| 690 | my @opcode=(0x66); | ||
| 691 | $imm=$1; | ||
| 692 | $src=$2; | ||
| 693 | $dst=$3; | ||
| 694 | if ($dst =~ /%r([0-9]+)d/) { $dst = $1; } | ||
| 695 | elsif ($dst =~ /%e/) { $dst = $regrm{$dst}; } | ||
| 696 | rex(\@opcode,$src,$dst); | ||
| 697 | push @opcode,0x0f,0x3a,0x16; | ||
| 698 | push @opcode,0xc0|(($src&7)<<3)|($dst&7); # ModR/M | ||
| 699 | push @opcode,$imm; | ||
| 700 | @opcode; | ||
| 701 | } else { | ||
| 702 | (); | ||
| 703 | } | ||
| 704 | }; | ||
| 705 | |||
| 706 | my $pinsrd = sub { | ||
| 707 | if (shift =~ /\$([0-9]+),\s*(%\w+),\s*%xmm([0-9]+)/) { | ||
| 708 | my @opcode=(0x66); | ||
| 709 | $imm=$1; | ||
| 710 | $src=$2; | ||
| 711 | $dst=$3; | ||
| 712 | if ($src =~ /%r([0-9]+)/) { $src = $1; } | ||
| 713 | elsif ($src =~ /%e/) { $src = $regrm{$src}; } | ||
| 714 | rex(\@opcode,$dst,$src); | ||
| 715 | push @opcode,0x0f,0x3a,0x22; | ||
| 716 | push @opcode,0xc0|(($dst&7)<<3)|($src&7); # ModR/M | ||
| 717 | push @opcode,$imm; | ||
| 718 | @opcode; | ||
| 719 | } else { | ||
| 720 | (); | ||
| 721 | } | ||
| 722 | }; | ||
| 723 | |||
| 724 | my $pshufb = sub { | ||
| 725 | if (shift =~ /%xmm([0-9]+),\s*%xmm([0-9]+)/) { | ||
| 726 | my @opcode=(0x66); | ||
| 727 | rex(\@opcode,$2,$1); | ||
| 728 | push @opcode,0x0f,0x38,0x00; | ||
| 729 | push @opcode,0xc0|($1&7)|(($2&7)<<3); # ModR/M | ||
| 730 | @opcode; | ||
| 731 | } else { | ||
| 732 | (); | ||
| 733 | } | ||
| 734 | }; | ||
| 735 | |||
| 736 | my $palignr = sub { | ||
| 737 | if (shift =~ /\$([0-9]+),\s*%xmm([0-9]+),\s*%xmm([0-9]+)/) { | ||
| 738 | my @opcode=(0x66); | ||
| 739 | rex(\@opcode,$3,$2); | ||
| 740 | push @opcode,0x0f,0x3a,0x0f; | ||
| 741 | push @opcode,0xc0|($2&7)|(($3&7)<<3); # ModR/M | ||
| 742 | push @opcode,$1; | ||
| 743 | @opcode; | ||
| 744 | } else { | ||
| 745 | (); | ||
| 746 | } | ||
| 747 | }; | ||
| 748 | |||
| 749 | my $pclmulqdq = sub { | ||
| 750 | if (shift =~ /\$([x0-9a-f]+),\s*%xmm([0-9]+),\s*%xmm([0-9]+)/) { | ||
| 751 | my @opcode=(0x66); | ||
| 752 | rex(\@opcode,$3,$2); | ||
| 753 | push @opcode,0x0f,0x3a,0x44; | ||
| 754 | push @opcode,0xc0|($2&7)|(($3&7)<<3); # ModR/M | ||
| 755 | my $c=$1; | ||
| 756 | push @opcode,$c=~/^0/?oct($c):$c; | ||
| 757 | @opcode; | ||
| 758 | } else { | ||
| 759 | (); | ||
| 760 | } | ||
| 761 | }; | ||
| 762 | |||
| 763 | my $rdrand = sub { | ||
| 764 | if (shift =~ /%[er](\w+)/) { | ||
| 765 | my @opcode=(); | ||
| 766 | my $dst=$1; | ||
| 767 | if ($dst !~ /[0-9]+/) { $dst = $regrm{"%e$dst"}; } | ||
| 768 | rex(\@opcode,0,$1,8); | ||
| 769 | push @opcode,0x0f,0xc7,0xf0|($dst&7); | ||
| 770 | @opcode; | ||
| 771 | } else { | ||
| 772 | (); | ||
| 773 | } | ||
| 774 | }; | ||
| 775 | |||
| 629 | print "#include <machine/asm.h>\n"; | 776 | print "#include <machine/asm.h>\n"; |
| 630 | 777 | ||
| 631 | if ($nasm) { | 778 | if ($nasm) { |
| 632 | print <<___; | 779 | print <<___; |
| 633 | default rel | 780 | default rel |
| 781 | %define XMMWORD | ||
| 634 | ___ | 782 | ___ |
| 635 | } elsif ($masm) { | 783 | } elsif ($masm) { |
| 636 | print <<___; | 784 | print <<___; |
| @@ -647,14 +795,22 @@ while($line=<>) { | |||
| 647 | 795 | ||
| 648 | undef $label; | 796 | undef $label; |
| 649 | undef $opcode; | 797 | undef $opcode; |
| 650 | undef $sz; | ||
| 651 | undef @args; | 798 | undef @args; |
| 652 | 799 | ||
| 653 | if ($label=label->re(\$line)) { print $label->out(); } | 800 | if ($label=label->re(\$line)) { print $label->out(); } |
| 654 | 801 | ||
| 655 | if (directive->re(\$line)) { | 802 | if (directive->re(\$line)) { |
| 656 | printf "%s",directive->out(); | 803 | printf "%s",directive->out(); |
| 657 | } elsif ($opcode=opcode->re(\$line)) { ARGUMENT: while (1) { | 804 | } elsif ($opcode=opcode->re(\$line)) { |
| 805 | my $asm = eval("\$".$opcode->mnemonic()); | ||
| 806 | undef @bytes; | ||
| 807 | |||
| 808 | if ((ref($asm) eq 'CODE') && scalar(@bytes=&$asm($line))) { | ||
| 809 | print $gas?".byte\t":"DB\t",join(',',@bytes),"\n"; | ||
| 810 | next; | ||
| 811 | } | ||
| 812 | |||
| 813 | ARGUMENT: while (1) { | ||
| 658 | my $arg; | 814 | my $arg; |
| 659 | 815 | ||
| 660 | if ($arg=register->re(\$line)) { opcode->size($arg->size()); } | 816 | if ($arg=register->re(\$line)) { opcode->size($arg->size()); } |
| @@ -670,19 +826,26 @@ while($line=<>) { | |||
| 670 | $line =~ s/^,\s*//; | 826 | $line =~ s/^,\s*//; |
| 671 | } # ARGUMENT: | 827 | } # ARGUMENT: |
| 672 | 828 | ||
| 673 | $sz=opcode->size(); | ||
| 674 | |||
| 675 | if ($#args>=0) { | 829 | if ($#args>=0) { |
| 676 | my $insn; | 830 | my $insn; |
| 831 | my $sz=opcode->size(); | ||
| 832 | |||
| 677 | if ($gas) { | 833 | if ($gas) { |
| 678 | $insn = $opcode->out($#args>=1?$args[$#args]->size():$sz); | 834 | $insn = $opcode->out($#args>=1?$args[$#args]->size():$sz); |
| 835 | @args = map($_->out($sz),@args); | ||
| 836 | printf "\t%s\t%s",$insn,join(",",@args); | ||
| 679 | } else { | 837 | } else { |
| 680 | $insn = $opcode->out(); | 838 | $insn = $opcode->out(); |
| 681 | $insn .= $sz if (map($_->out() =~ /x?mm/,@args)); | 839 | foreach (@args) { |
| 840 | my $arg = $_->out(); | ||
| 841 | # $insn.=$sz compensates for movq, pinsrw, ... | ||
| 842 | if ($arg =~ /^xmm[0-9]+$/) { $insn.=$sz; $sz="x" if(!$sz); last; } | ||
| 843 | if ($arg =~ /^mm[0-9]+$/) { $insn.=$sz; $sz="q" if(!$sz); last; } | ||
| 844 | } | ||
| 682 | @args = reverse(@args); | 845 | @args = reverse(@args); |
| 683 | undef $sz if ($nasm && $opcode->mnemonic() eq "lea"); | 846 | undef $sz if ($nasm && $opcode->mnemonic() eq "lea"); |
| 847 | printf "\t%s\t%s",$insn,join(",",map($_->out($sz),@args)); | ||
| 684 | } | 848 | } |
| 685 | printf "\t%s\t%s",$insn,join(",",map($_->out($sz),@args)); | ||
| 686 | } else { | 849 | } else { |
| 687 | printf "\t%s",$opcode->out(); | 850 | printf "\t%s",$opcode->out(); |
| 688 | } | 851 | } |
diff --git a/src/lib/libcrypto/perlasm/x86asm.pl b/src/lib/libcrypto/perlasm/x86asm.pl index 4756a28e59..bf783cff26 100644 --- a/src/lib/libcrypto/perlasm/x86asm.pl +++ b/src/lib/libcrypto/perlasm/x86asm.pl | |||
| @@ -87,6 +87,57 @@ sub ::movq | |||
| 87 | { &::generic("movq",@_); } | 87 | { &::generic("movq",@_); } |
| 88 | } | 88 | } |
| 89 | 89 | ||
| 90 | # SSE>2 instructions | ||
| 91 | my %regrm = ( "eax"=>0, "ecx"=>1, "edx"=>2, "ebx"=>3, | ||
| 92 | "esp"=>4, "ebp"=>5, "esi"=>6, "edi"=>7 ); | ||
| 93 | sub ::pextrd | ||
| 94 | { my($dst,$src,$imm)=@_; | ||
| 95 | if ("$dst:$src" =~ /(e[a-dsd][ixp]):xmm([0-7])/) | ||
| 96 | { &::data_byte(0x66,0x0f,0x3a,0x16,0xc0|($2<<3)|$regrm{$1},$imm); } | ||
| 97 | else | ||
| 98 | { &::generic("pextrd",@_); } | ||
| 99 | } | ||
| 100 | |||
| 101 | sub ::pinsrd | ||
| 102 | { my($dst,$src,$imm)=@_; | ||
| 103 | if ("$dst:$src" =~ /xmm([0-7]):(e[a-dsd][ixp])/) | ||
| 104 | { &::data_byte(0x66,0x0f,0x3a,0x22,0xc0|($1<<3)|$regrm{$2},$imm); } | ||
| 105 | else | ||
| 106 | { &::generic("pinsrd",@_); } | ||
| 107 | } | ||
| 108 | |||
| 109 | sub ::pshufb | ||
| 110 | { my($dst,$src)=@_; | ||
| 111 | if ("$dst:$src" =~ /xmm([0-7]):xmm([0-7])/) | ||
| 112 | { &data_byte(0x66,0x0f,0x38,0x00,0xc0|($1<<3)|$2); } | ||
| 113 | else | ||
| 114 | { &::generic("pshufb",@_); } | ||
| 115 | } | ||
| 116 | |||
| 117 | sub ::palignr | ||
| 118 | { my($dst,$src,$imm)=@_; | ||
| 119 | if ("$dst:$src" =~ /xmm([0-7]):xmm([0-7])/) | ||
| 120 | { &::data_byte(0x66,0x0f,0x3a,0x0f,0xc0|($1<<3)|$2,$imm); } | ||
| 121 | else | ||
| 122 | { &::generic("palignr",@_); } | ||
| 123 | } | ||
| 124 | |||
| 125 | sub ::pclmulqdq | ||
| 126 | { my($dst,$src,$imm)=@_; | ||
| 127 | if ("$dst:$src" =~ /xmm([0-7]):xmm([0-7])/) | ||
| 128 | { &::data_byte(0x66,0x0f,0x3a,0x44,0xc0|($1<<3)|$2,$imm); } | ||
| 129 | else | ||
| 130 | { &::generic("pclmulqdq",@_); } | ||
| 131 | } | ||
| 132 | |||
| 133 | sub ::rdrand | ||
| 134 | { my ($dst)=@_; | ||
| 135 | if ($dst =~ /(e[a-dsd][ixp])/) | ||
| 136 | { &::data_byte(0x0f,0xc7,0xf0|$regrm{$dst}); } | ||
| 137 | else | ||
| 138 | { &::generic("rdrand",@_); } | ||
| 139 | } | ||
| 140 | |||
| 90 | # label management | 141 | # label management |
| 91 | $lbdecor="L"; # local label decoration, set by package | 142 | $lbdecor="L"; # local label decoration, set by package |
| 92 | $label="000"; | 143 | $label="000"; |
| @@ -174,7 +225,7 @@ sub ::asm_init | |||
| 174 | $filename=$fn; | 225 | $filename=$fn; |
| 175 | $i386=$cpu; | 226 | $i386=$cpu; |
| 176 | 227 | ||
| 177 | $elf=$cpp=$coff=$aout=$macosx=$win32=$netware=$mwerks=$openbsd=0; | 228 | $elf=$cpp=$coff=$aout=$macosx=$win32=$netware=$mwerks=$openbsd=$android=0; |
| 178 | if (($type eq "elf")) | 229 | if (($type eq "elf")) |
| 179 | { $elf=1; require "x86gas.pl"; } | 230 | { $elf=1; require "x86gas.pl"; } |
| 180 | elsif (($type eq "a\.out")) | 231 | elsif (($type eq "a\.out")) |
| @@ -195,6 +246,8 @@ sub ::asm_init | |||
| 195 | { $openbsd=$elf=1; require "x86gas.pl"; } | 246 | { $openbsd=$elf=1; require "x86gas.pl"; } |
| 196 | elsif (($type eq "openbsd-a.out")) | 247 | elsif (($type eq "openbsd-a.out")) |
| 197 | { $openbsd=1; require "x86gas.pl"; } | 248 | { $openbsd=1; require "x86gas.pl"; } |
| 249 | elsif (($type eq "android")) | ||
| 250 | { $elf=1; $android=1; require "x86gas.pl"; } | ||
| 198 | else | 251 | else |
| 199 | { print STDERR <<"EOF"; | 252 | { print STDERR <<"EOF"; |
| 200 | Pick one target type from | 253 | Pick one target type from |
diff --git a/src/lib/libcrypto/perlasm/x86gas.pl b/src/lib/libcrypto/perlasm/x86gas.pl index 9a1cce026e..d4baea514b 100644 --- a/src/lib/libcrypto/perlasm/x86gas.pl +++ b/src/lib/libcrypto/perlasm/x86gas.pl | |||
| @@ -45,9 +45,8 @@ sub ::generic | |||
| 45 | undef $suffix if ($dst =~ m/^%[xm]/o || $src =~ m/^%[xm]/o); | 45 | undef $suffix if ($dst =~ m/^%[xm]/o || $src =~ m/^%[xm]/o); |
| 46 | 46 | ||
| 47 | if ($#_==0) { &::emit($opcode); } | 47 | if ($#_==0) { &::emit($opcode); } |
| 48 | elsif ($opcode =~ m/^j/o && $#_==1) { &::emit($opcode,@arg); } | 48 | elsif ($#_==1 && $opcode =~ m/^(call|clflush|j|loop|set)/o) |
| 49 | elsif ($opcode eq "call" && $#_==1) { &::emit($opcode,@arg); } | 49 | { &::emit($opcode,@arg); } |
| 50 | elsif ($opcode =~ m/^set/&& $#_==1) { &::emit($opcode,@arg); } | ||
| 51 | else { &::emit($opcode.$suffix,@arg);} | 50 | else { &::emit($opcode.$suffix,@arg);} |
| 52 | 51 | ||
| 53 | 1; | 52 | 1; |
| @@ -91,6 +90,7 @@ sub ::DWP | |||
| 91 | } | 90 | } |
| 92 | sub ::QWP { &::DWP(@_); } | 91 | sub ::QWP { &::DWP(@_); } |
| 93 | sub ::BP { &::DWP(@_); } | 92 | sub ::BP { &::DWP(@_); } |
| 93 | sub ::WP { &::DWP(@_); } | ||
| 94 | sub ::BC { @_; } | 94 | sub ::BC { @_; } |
| 95 | sub ::DWC { @_; } | 95 | sub ::DWC { @_; } |
| 96 | 96 | ||
| @@ -149,22 +149,24 @@ sub ::public_label | |||
| 149 | { push(@out,".globl\t".&::LABEL($_[0],$nmdecor.$_[0])."\n"); } | 149 | { push(@out,".globl\t".&::LABEL($_[0],$nmdecor.$_[0])."\n"); } |
| 150 | 150 | ||
| 151 | sub ::file_end | 151 | sub ::file_end |
| 152 | { if (grep {/\b${nmdecor}OPENSSL_ia32cap_P\b/i} @out) { | 152 | { if ($::macosx) |
| 153 | my $tmp=".comm\t${nmdecor}OPENSSL_ia32cap_P,4"; | ||
| 154 | if ($::elf) { push (@out,"$tmp,4\n"); } | ||
| 155 | else { push (@out,"$tmp\n"); } | ||
| 156 | } | ||
| 157 | if ($::macosx) | ||
| 158 | { if (%non_lazy_ptr) | 153 | { if (%non_lazy_ptr) |
| 159 | { push(@out,".section __IMPORT,__pointers,non_lazy_symbol_pointers\n"); | 154 | { push(@out,".section __IMPORT,__pointers,non_lazy_symbol_pointers\n"); |
| 160 | foreach $i (keys %non_lazy_ptr) | 155 | foreach $i (keys %non_lazy_ptr) |
| 161 | { push(@out,"$non_lazy_ptr{$i}:\n.indirect_symbol\t$i\n.long\t0\n"); } | 156 | { push(@out,"$non_lazy_ptr{$i}:\n.indirect_symbol\t$i\n.long\t0\n"); } |
| 162 | } | 157 | } |
| 163 | } | 158 | } |
| 159 | if (grep {/\b${nmdecor}OPENSSL_ia32cap_P\b/i} @out) { | ||
| 160 | my $tmp=".comm\t${nmdecor}OPENSSL_ia32cap_P,8"; | ||
| 161 | if ($::macosx) { push (@out,"$tmp,2\n"); } | ||
| 162 | elsif ($::elf) { push (@out,"$tmp,4\n"); } | ||
| 163 | else { push (@out,"$tmp\n"); } | ||
| 164 | } | ||
| 164 | push(@out,$initseg) if ($initseg); | 165 | push(@out,$initseg) if ($initseg); |
| 165 | } | 166 | } |
| 166 | 167 | ||
| 167 | sub ::data_byte { push(@out,".byte\t".join(',',@_)."\n"); } | 168 | sub ::data_byte { push(@out,".byte\t".join(',',@_)."\n"); } |
| 169 | sub ::data_short{ push(@out,".value\t".join(',',@_)."\n"); } | ||
| 168 | sub ::data_word { push(@out,".long\t".join(',',@_)."\n"); } | 170 | sub ::data_word { push(@out,".long\t".join(',',@_)."\n"); } |
| 169 | 171 | ||
| 170 | sub ::align | 172 | sub ::align |
| @@ -189,7 +191,7 @@ sub ::picmeup | |||
| 189 | &::lea($dst,&::DWP($sym)); | 191 | &::lea($dst,&::DWP($sym)); |
| 190 | &::emitraw("#endif /* PIC */"); | 192 | &::emitraw("#endif /* PIC */"); |
| 191 | } | 193 | } |
| 192 | elsif ($::pic && ($::elf || $::aout)) | 194 | if (($::pic && ($::elf || $::aout)) || $::macosx) |
| 193 | { if (!defined($base)) | 195 | { if (!defined($base)) |
| 194 | { &::call(&::label("PIC_me_up")); | 196 | { &::call(&::label("PIC_me_up")); |
| 195 | &::set_label("PIC_me_up"); | 197 | &::set_label("PIC_me_up"); |
| @@ -225,14 +227,17 @@ PIC_EPILOGUE | |||
| 225 | .align $align | 227 | .align $align |
| 226 | .Linitalign: | 228 | .Linitalign: |
| 227 | ___ | 229 | ___ |
| 230 | } elsif ($::android) | ||
| 231 | { $initseg.=<<___; | ||
| 232 | .section .init_array | ||
| 233 | .align 4 | ||
| 234 | .long $f | ||
| 235 | ___ | ||
| 228 | } | 236 | } |
| 229 | elsif ($::elf) | 237 | elsif ($::elf) |
| 230 | { $initseg.=<<___; | 238 | { $initseg.=<<___; |
| 231 | .section .init | 239 | .section .init |
| 232 | call $f | 240 | call $f |
| 233 | jmp .Linitalign | ||
| 234 | .align $align | ||
| 235 | .Linitalign: | ||
| 236 | ___ | 241 | ___ |
| 237 | } | 242 | } |
| 238 | elsif ($::coff) | 243 | elsif ($::coff) |
diff --git a/src/lib/libcrypto/perlasm/x86nasm.pl b/src/lib/libcrypto/perlasm/x86nasm.pl index ce2bed9bb2..ca2511c9eb 100644 --- a/src/lib/libcrypto/perlasm/x86nasm.pl +++ b/src/lib/libcrypto/perlasm/x86nasm.pl | |||
| @@ -19,6 +19,8 @@ sub ::generic | |||
| 19 | { $_[0] = "NEAR $_[0]"; } | 19 | { $_[0] = "NEAR $_[0]"; } |
| 20 | elsif ($opcode eq "lea" && $#_==1) # wipe storage qualifier from lea | 20 | elsif ($opcode eq "lea" && $#_==1) # wipe storage qualifier from lea |
| 21 | { $_[1] =~ s/^[^\[]*\[/\[/o; } | 21 | { $_[1] =~ s/^[^\[]*\[/\[/o; } |
| 22 | elsif ($opcode eq "clflush" && $#_==0) | ||
| 23 | { $_[0] =~ s/^[^\[]*\[/\[/o; } | ||
| 22 | } | 24 | } |
| 23 | &::emit($opcode,@_); | 25 | &::emit($opcode,@_); |
| 24 | 1; | 26 | 1; |
| @@ -67,6 +69,7 @@ sub get_mem | |||
| 67 | } | 69 | } |
| 68 | sub ::BP { &get_mem("BYTE",@_); } | 70 | sub ::BP { &get_mem("BYTE",@_); } |
| 69 | sub ::DWP { &get_mem("DWORD",@_); } | 71 | sub ::DWP { &get_mem("DWORD",@_); } |
| 72 | sub ::WP { &get_mem("WORD",@_); } | ||
| 70 | sub ::QWP { &get_mem("",@_); } | 73 | sub ::QWP { &get_mem("",@_); } |
| 71 | sub ::BC { (($::mwerks)?"":"BYTE ")."@_"; } | 74 | sub ::BC { (($::mwerks)?"":"BYTE ")."@_"; } |
| 72 | sub ::DWC { (($::mwerks)?"":"DWORD ")."@_"; } | 75 | sub ::DWC { (($::mwerks)?"":"DWORD ")."@_"; } |
| @@ -114,7 +117,7 @@ sub ::file_end | |||
| 114 | { if (grep {/\b${nmdecor}OPENSSL_ia32cap_P\b/i} @out) | 117 | { if (grep {/\b${nmdecor}OPENSSL_ia32cap_P\b/i} @out) |
| 115 | { my $comm=<<___; | 118 | { my $comm=<<___; |
| 116 | ${drdecor}segment .bss | 119 | ${drdecor}segment .bss |
| 117 | ${drdecor}common ${nmdecor}OPENSSL_ia32cap_P 4 | 120 | ${drdecor}common ${nmdecor}OPENSSL_ia32cap_P 8 |
| 118 | ___ | 121 | ___ |
| 119 | # comment out OPENSSL_ia32cap_P declarations | 122 | # comment out OPENSSL_ia32cap_P declarations |
| 120 | grep {s/(^extern\s+${nmdecor}OPENSSL_ia32cap_P)/\;$1/} @out; | 123 | grep {s/(^extern\s+${nmdecor}OPENSSL_ia32cap_P)/\;$1/} @out; |
| @@ -135,7 +138,8 @@ sub ::public_label | |||
| 135 | 138 | ||
| 136 | sub ::data_byte | 139 | sub ::data_byte |
| 137 | { push(@out,(($::mwerks)?".byte\t":"db\t").join(',',@_)."\n"); } | 140 | { push(@out,(($::mwerks)?".byte\t":"db\t").join(',',@_)."\n"); } |
| 138 | 141 | sub ::data_short | |
| 142 | { push(@out,(($::mwerks)?".word\t":"dw\t").join(',',@_)."\n"); } | ||
| 139 | sub ::data_word | 143 | sub ::data_word |
| 140 | { push(@out,(($::mwerks)?".long\t":"dd\t").join(',',@_)."\n"); } | 144 | { push(@out,(($::mwerks)?".long\t":"dd\t").join(',',@_)."\n"); } |
| 141 | 145 | ||
| @@ -163,4 +167,11 @@ sub ::dataseg | |||
| 163 | else { push(@out,"section\t.data align=4\n"); } | 167 | else { push(@out,"section\t.data align=4\n"); } |
| 164 | } | 168 | } |
| 165 | 169 | ||
| 170 | sub ::safeseh | ||
| 171 | { my $nm=shift; | ||
| 172 | push(@out,"%if __NASM_VERSION_ID__ >= 0x02030000\n"); | ||
| 173 | push(@out,"safeseh ".&::LABEL($nm,$nmdecor.$nm)."\n"); | ||
| 174 | push(@out,"%endif\n"); | ||
| 175 | } | ||
| 176 | |||
| 166 | 1; | 177 | 1; |
