another fix for the debug print
[openssl.git] / crypto / perlasm / x86unix.pl
index 60d75f5ce4b1bb31b74ca5b9b074becceba86d48..573d4f1126e95cb939832a9f2da0eb1f2b9499ec 100644 (file)
@@ -3,6 +3,8 @@
 package x86unix;
 
 $label="L000";
+$const="";
+$constl=0;
 
 $align=($main'aout)?"4":"16";
 $under=($main'aout)?"_":"";
@@ -162,6 +164,8 @@ sub main'dec        { &out1("decl",@_); }
 sub main'inc   { &out1("incl",@_); }
 sub main'push  { &out1("pushl",@_); $stack+=4; }
 sub main'pop   { &out1("popl",@_); $stack-=4; }
+sub main'pushf { &out0("pushf"); $stack+=4; }
+sub main'popf  { &out0("popf"); $stack-=4; }
 sub main'not   { &out1("notl",@_); }
 sub main'call  { &out1("call",$under.$_[0]); }
 sub main'ret   { &out0("ret"); }
@@ -292,6 +296,8 @@ EOF
        push(@out,$tmp);
        if ($main'cpp)
                { $tmp=push(@out,"\tTYPE($func,\@function)\n"); }
+       elsif ($main'gaswin)
+               { $tmp=push(@out,"\t.def\t$func;\t.scl\t2;\t.type\t32;\t.endef\n"); }
        else    { $tmp=push(@out,"\t.type\t$func,\@function\n"); }
        push(@out,"$func:\n");
        $tmp=<<"EOF";
@@ -320,6 +326,8 @@ EOF
        push(@out,$tmp);
        if ($main'cpp)
                { push(@out,"\tTYPE($func,\@function)\n"); }
+       elsif ($main'gaswin)
+               { $tmp=push(@out,"\t.def\t$func;\t.scl\t2;\t.type\t32;\t.endef\n"); }
        else    { push(@out,"\t.type    $func,\@function\n"); }
        push(@out,"$func:\n");
        $stack=4;
@@ -340,8 +348,11 @@ sub main'function_end
 .${func}_end:
 EOF
        push(@out,$tmp);
+
        if ($main'cpp)
                { push(@out,"\tSIZE($func,.${func}_end-$func)\n"); }
+       elsif ($main'gaswin)
+                { $tmp=push(@out,"\t.align 4\n"); }
        else    { push(@out,"\t.size\t$func,.${func}_end-$func\n"); }
        push(@out,".ident       \"$func\"\n");
        $stack=0;
@@ -371,6 +382,8 @@ sub main'function_end_B
        push(@out,".L_${func}_end:\n");
        if ($main'cpp)
                { push(@out,"\tSIZE($func,.L_${func}_end-$func)\n"); }
+        elsif ($main'gaswin)
+                { push(@out,"\t.align 4\n"); }
        else    { push(@out,"\t.size\t$func,.L_${func}_end-$func\n"); }
        push(@out,".ident       \"desasm.pl\"\n");
        $stack=0;
@@ -445,9 +458,87 @@ sub main'set_label
 
 sub main'file_end
        {
+       if ($const ne "")
+               {
+               push(@out,".section .rodata\n");
+               push(@out,$const);
+               $const="";
+               }
        }
 
 sub main'data_word
        {
        push(@out,"\t.long $_[0]\n");
        }
+
+# debug output functions: puts, putx, printf
+
+sub main'puts
+       {
+       &pushvars();
+       &main'push('$Lstring' . ++$constl);
+       &main'call('puts');
+       $stack-=4;
+       &main'add("esp",4);
+       &popvars();
+
+       $const .= "Lstring$constl:\n\t.string \"@_[0]\"\n";
+       }
+
+sub main'putx
+       {
+       &pushvars();
+       &main'push($_[0]);
+       &main'push('$Lstring' . ++$constl);
+       &main'call('printf');
+       &main'add("esp",8);
+       $stack-=8;
+       &popvars();
+
+       $const .= "Lstring$constl:\n\t.string \"\%X\"\n";
+       }
+
+sub main'printf
+       {
+       $ostack = $stack;
+       &pushvars();
+       for ($i = @_ - 1; $i >= 0; $i--)
+               {
+               if ($i == 0) # change this to support %s format strings
+                       {
+                       &main'push('$Lstring' . ++$constl);
+                       $const .= "Lstring$constl:\n\t.string \"@_[$i]\"\n";
+                       }
+               else
+                       {
+                       if ($_[$i] =~ /([0-9]*)\(%esp\)/)
+                               {
+                               &main'push(($1 + $stack - $ostack) . '(%esp)');
+                               }
+                       else
+                               {
+                               &main'push($_[$i]);
+                               }
+                       }
+               }
+       &main'call('printf');
+       $stack-=4*@_;
+       &main'add("esp",4*@_);
+       &popvars();
+       }
+
+sub pushvars
+       {
+       &main'pushf();
+       &main'push("edx");
+       &main'push("ecx");
+       &main'push("eax");
+       }
+
+sub popvars
+       {
+       &main'pop("eax");
+       &main'pop("ecx");
+       &main'pop("edx");
+       &main'popf();
+       }