X-Git-Url: https://git.openssl.org/gitweb/?p=openssl.git;a=blobdiff_plain;f=crypto%2Fperlasm%2Fx86gas.pl;h=2c8fce077939f4ad57ca99209a5a64b6909984bc;hp=fa789a78b95acb7d4b76905ce5f578836a9c6002;hb=abeae4d3251181f1cedd15e4433e79406b766155;hpb=43d8f27dca609666350512bb17a76d39e0c28e70 diff --git a/crypto/perlasm/x86gas.pl b/crypto/perlasm/x86gas.pl index fa789a78b9..2c8fce0779 100644 --- a/crypto/perlasm/x86gas.pl +++ b/crypto/perlasm/x86gas.pl @@ -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 OpenSSL license (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 + package x86gas; @@ -17,7 +24,7 @@ sub opsize() { my $reg=shift; if ($reg =~ m/^%e/o) { "l"; } elsif ($reg =~ m/^%[a-d][hl]$/o) { "b"; } - elsif ($reg =~ m/^%[xm]/o) { undef; } + elsif ($reg =~ m/^%[yxm]/o) { undef; } else { "w"; } } @@ -25,33 +32,28 @@ sub opsize() # expand opcode with size suffix; # prefix numeric constants with $; sub ::generic -{ my($opcode,$dst,$src)=@_; - my($tmp,$suffix,@arg); - - if (defined($src)) - { $src =~ s/^(e?[a-dsixphl]{2})$/%$1/o; - $src =~ s/^(x?mm[0-7])$/%$1/o; - $src =~ s/^(\-?[0-9]+)$/\$$1/o; - $src =~ s/^(\-?0x[0-9a-f]+)$/\$$1/o; - push(@arg,$src); - } - if (defined($dst)) - { $dst =~ s/^(\*?)(e?[a-dsixphl]{2})$/$1%$2/o; - $dst =~ s/^(x?mm[0-7])$/%$1/o; - $dst =~ s/^(\-?[0-9]+)$/\$$1/o if(!defined($src)); - $dst =~ s/^(\-?0x[0-9a-f]+)$/\$$1/o if(!defined($src)); - push(@arg,$dst); +{ my($opcode,@arg)=@_; + my($suffix,$dst,$src); + + @arg=reverse(@arg); + + for (@arg) + { s/^(\*?)(e?[a-dsixphl]{2})$/$1%$2/o; # gp registers + s/^([xy]?mm[0-7])$/%$1/o; # xmm/mmx registers + s/^(\-?[0-9]+)$/\$$1/o; # constants + s/^(\-?0x[0-9a-f]+)$/\$$1/o; # constants } + $dst = $arg[$#arg] if ($#arg>=0); + $src = $arg[$#arg-1] if ($#arg>=1); if ($dst =~ m/^%/o) { $suffix=&opsize($dst); } elsif ($src =~ m/^%/o) { $suffix=&opsize($src); } else { $suffix="l"; } undef $suffix if ($dst =~ m/^%[xm]/o || $src =~ m/^%[xm]/o); if ($#_==0) { &::emit($opcode); } - elsif ($opcode =~ m/^j/o && $#_==1) { &::emit($opcode,@arg); } - elsif ($opcode eq "call" && $#_==1) { &::emit($opcode,@arg); } - elsif ($opcode =~ m/^set/&& $#_==1) { &::emit($opcode,@arg); } + elsif ($#_==1 && $opcode =~ m/^(call|clflush|j|loop|set)/o) + { &::emit($opcode,@arg); } else { &::emit($opcode.$suffix,@arg);} 1; @@ -71,23 +73,12 @@ sub ::jmp_ptr { &::generic("jmp","*$_[0]"); } *::bswap = sub { &::emit("bswap","%$_[0]"); } if (!$::i386); -*::pshufw = sub -{ my($dst,$src,$magic)=@_; - &::emit("pshufw","\$$magic","%$src","%$dst"); -}; -*::shld = sub -{ my($dst,$src,$bits)=@_; - &::emit("shldl",$bit eq "cl"?"%cl":"\$$bits","%$src","%$dst"); -}; -*::shrd = sub -{ my($dst,$src,$bits)=@_; - &::emit("shrdl",$bit eq "cl"?"%cl":"\$$bits","%$src","%$dst"); -}; - sub ::DWP { my($addr,$reg1,$reg2,$idx)=@_; my $ret=""; + if (!defined($idx) && 1*$reg2) { $idx=$reg2; $reg2=$reg1; undef $reg1; } + $addr =~ s/^\s+//; # prepend global references with optional underscore $addr =~ s/^([^\+\-0-9][^\+\-]*)/&::islabel($1) or "$nmdecor$1"/ige; @@ -108,6 +99,7 @@ sub ::DWP } sub ::QWP { &::DWP(@_); } sub ::BP { &::DWP(@_); } +sub ::WP { &::DWP(@_); } sub ::BC { @_; } sub ::DWC { @_; } @@ -124,8 +116,8 @@ sub ::function_begin_B push(@out,".globl\t$func\n") if ($global); if ($::coff) - { push(@out,".def\t$func;\t.scl\t2;\t.type\t32;\t.endef\n"); } - elsif ($::aout and !$::pic) + { push(@out,".def\t$func;\t.scl\t".(3-$global).";\t.type\t32;\t.endef\n"); } + elsif (($::aout and !$::pic) or $::macosx) { } else { push(@out,".type $func,\@function\n"); } @@ -160,28 +152,36 @@ sub ::comment } sub ::external_label -{ push(@out,".extern\t".&::LABEL($_[0],$nmdecor.$_[0])."\n"); } +{ foreach(@_) { &::LABEL($_,$nmdecor.$_); } } sub ::public_label { push(@out,".globl\t".&::LABEL($_[0],$nmdecor.$_[0])."\n"); } sub ::file_end -{ if (grep {/\b${nmdecor}OPENSSL_ia32cap_P\b/i} @out) { - my $tmp=".comm\t${nmdecor}OPENSSL_ia32cap_P,4"; - if ($::elf) { push (@out,"$tmp,4\n"); } +{ if ($::macosx) + { if (%non_lazy_ptr) + { push(@out,".section __IMPORT,__pointers,non_lazy_symbol_pointers\n"); + foreach $i (keys %non_lazy_ptr) + { push(@out,"$non_lazy_ptr{$i}:\n.indirect_symbol\t$i\n.long\t0\n"); } + } + } + if (grep {/\b${nmdecor}OPENSSL_ia32cap_P\b/i} @out) { + my $tmp=".comm\t${nmdecor}OPENSSL_ia32cap_P,16"; + if ($::macosx) { push (@out,"$tmp,2\n"); } + elsif ($::elf) { push (@out,"$tmp,4\n"); } else { push (@out,"$tmp\n"); } } push(@out,$initseg) if ($initseg); } sub ::data_byte { push(@out,".byte\t".join(',',@_)."\n"); } +sub ::data_short{ push(@out,".value\t".join(',',@_)."\n"); } sub ::data_word { push(@out,".long\t".join(',',@_)."\n"); } sub ::align -{ my $val=$_[0],$p2,$i; +{ my $val=$_[0]; if ($::aout) - { for ($p2=0;$val!=0;$val>>=1) { $p2++; } - $val=$p2-1; + { $val=int(log($val)/log(2)); $val.=",0x90"; } push(@out,".align\t$val\n"); @@ -190,19 +190,26 @@ sub ::align sub ::picmeup { my($dst,$sym,$base,$reflabel)=@_; - if ($::pic && ($::elf || $::aout)) + if (($::pic && ($::elf || $::aout)) || $::macosx) { if (!defined($base)) { &::call(&::label("PIC_me_up")); &::set_label("PIC_me_up"); &::blindpop($dst); - &::add($dst,"\$${nmdecor}_GLOBAL_OFFSET_TABLE_+[.-". - &::label("PIC_me_up") . "]"); + $base=$dst; + $reflabel=&::label("PIC_me_up"); + } + if ($::macosx) + { my $indirect=&::static_label("$nmdecor$sym\$non_lazy_ptr"); + &::mov($dst,&::DWP("$indirect-$reflabel",$base)); + $non_lazy_ptr{"$nmdecor$sym"}=$indirect; } + elsif ($sym eq "OPENSSL_ia32cap_P" && $::elf>0) + { &::lea($dst,&::DWP("$sym-$reflabel",$base)); } else - { &::lea($dst,&::DWP("${nmdecor}_GLOBAL_OFFSET_TABLE_+[.-$reflabel]", + { &::lea($dst,&::DWP("_GLOBAL_OFFSET_TABLE_+[.-$reflabel]", $base)); + &::mov($dst,&::DWP("$sym\@GOT",$dst)); } - &::mov($dst,&::DWP("$nmdecor$sym\@GOT",$dst)); } else { &::lea($dst,&::DWP($sym)); } @@ -211,19 +218,30 @@ sub ::picmeup sub ::initseg { my $f=$nmdecor.shift; - if ($::elf) + if ($::android) + { $initseg.=<<___; +.section .init_array +.align 4 +.long $f +___ + } + elsif ($::elf) { $initseg.=<<___; .section .init call $f - jmp .Linitalign -.align $align -.Linitalign: ___ } elsif ($::coff) { $initseg.=<<___; # applies to both Cygwin and Mingw .section .ctors .long $f +___ + } + elsif ($::macosx) + { $initseg.=<<___; +.mod_init_func +.align 2 +.long $f ___ } elsif ($::aout) @@ -239,4 +257,9 @@ ___ } } +sub ::dataseg +{ push(@out,".data\n"); } + +*::hidden = sub { push(@out,".hidden\t$nmdecor$_[0]\n"); } if ($::elf); + 1;