perlasm/x86masm.pl: make it work.
[openssl.git] / crypto / perlasm / x86masm.pl
index 6154b079b9bb16b68e358480864173fb0b8a67fc..917d0f8b8e1982621b3a06cd8c1fe1cebd17f71f 100644 (file)
@@ -16,10 +16,12 @@ sub ::generic
     # fix hexadecimal constants
     for (@arg) { s/(?<![\w\$\.])0x([0-9a-f]+)/0$1h/oi; }
 
-    if ($opcode !~ /movq/)
+    if ($opcode =~ /lea/ && @arg[1] =~ s/.*PTR\s+(\(.*\))$/OFFSET $1/) # no []
+    {  $opcode="mov";  }
+    elsif ($opcode !~ /mov[dq]$/)
     {  # fix xmm references
-       $arg[0] =~ s/\b[A-Z]+WORD\s+PTR/XMMWORD PTR/i if ($arg[1]=~/\bxmm[0-7]\b/i);
-       $arg[1] =~ s/\b[A-Z]+WORD\s+PTR/XMMWORD PTR/i if ($arg[0]=~/\bxmm[0-7]\b/i);
+       $arg[0] =~ s/\b[A-Z]+WORD\s+PTR/XMMWORD PTR/i if ($arg[-1]=~/\bxmm[0-7]\b/i);
+       $arg[-1] =~ s/\b[A-Z]+WORD\s+PTR/XMMWORD PTR/i if ($arg[0]=~/\bxmm[0-7]\b/i);
     }
 
     &::emit($opcode,@arg);
@@ -37,6 +39,8 @@ sub get_mem
 { my($size,$addr,$reg1,$reg2,$idx)=@_;
   my($post,$ret);
 
+    if (!defined($idx) && 1*$reg2) { $idx=$reg2; $reg2=$reg1; undef $reg1; }
+
     $ret .= "$size PTR " if ($size ne "");
 
     $addr =~ s/^\s+//;
@@ -131,7 +135,7 @@ ___
     if (grep {/\b${nmdecor}OPENSSL_ia32cap_P\b/i} @out)
     {  my $comm=<<___;
 .bss   SEGMENT 'BSS'
-COMM   ${nmdecor}OPENSSL_ia32cap_P:QWORD
+COMM   ${nmdecor}OPENSSL_ia32cap_P:DWORD:4
 .bss   ENDS
 ___
        # comment out OPENSSL_ia32cap_P declarations
@@ -156,13 +160,13 @@ sub ::public_label
 {   push(@out,"PUBLIC\t".&::LABEL($_[0],$nmdecor.$_[0])."\n");   }
 
 sub ::data_byte
-{   push(@out,("DB\t").join(',',@_)."\n");     }
+{   push(@out,("DB\t").join(',',splice(@_,0,16))."\n") while(@_);      }
 
 sub ::data_short
-{   push(@out,("DW\t").join(',',@_)."\n");     }
+{   push(@out,("DW\t").join(',',splice(@_,0,8))."\n") while(@_);       }
 
 sub ::data_word
-{   push(@out,("DD\t").join(',',@_)."\n");     }
+{   push(@out,("DD\t").join(',',splice(@_,0,4))."\n") while(@_);       }
 
 sub ::align
 {   push(@out,"ALIGN\t$_[0]\n");       }
@@ -186,4 +190,11 @@ ___
 sub ::dataseg
 {   push(@out,"$segment\tENDS\n_DATA\tSEGMENT\n"); $segment="_DATA";   }
 
+sub ::safeseh
+{ my $nm=shift;
+    push(@out,"IF \@Version GE 710\n");
+    push(@out,".SAFESEH        ".&::LABEL($nm,$nmdecor.$nm)."\n");
+    push(@out,"ENDIF\n");
+}
+
 1;