Following the license change, modify the boilerplates in crypto/perlasm/
[openssl.git] / crypto / perlasm / x86gas.pl
index d0b7ae27ae73d091a344d68a2e10e3153a62fa08..728c1a6da515fcf4973663fb9577689cbf0938e6 100644 (file)
@@ -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 Apache License 2.0 (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"; }
 }
 
@@ -45,10 +52,8 @@ sub ::generic
     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 eq "clflush" && $#_==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;
@@ -72,6 +77,8 @@ 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;
@@ -97,7 +104,7 @@ sub ::BC     { @_;           }
 sub ::DWC      { @_;           }
 
 sub ::file
-{   push(@out,".file\t\"$_[0].s\"\n.text\n");  }
+{   push(@out,".text\n");      }
 
 sub ::function_begin_B
 { my $func=shift;
@@ -159,8 +166,9 @@ sub ::file_end
        }
     }
     if (grep {/\b${nmdecor}OPENSSL_ia32cap_P\b/i} @out) {
-       my $tmp=".comm\t${nmdecor}OPENSSL_ia32cap_P,8";
-       if ($::elf)     { push (@out,"$tmp,4\n"); }
+       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);
@@ -171,10 +179,9 @@ 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");
@@ -183,7 +190,7 @@ 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");
@@ -196,6 +203,8 @@ sub ::picmeup
            &::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("_GLOBAL_OFFSET_TABLE_+[.-$reflabel]",
                            $base));
@@ -251,4 +260,6 @@ ___
 sub ::dataseg
 {   push(@out,".data\n");   }
 
+*::hidden = sub { push(@out,".hidden\t$nmdecor$_[0]\n"); } if ($::elf);
+
 1;