X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=crypto%2Fperlasm%2Fx86unix.pl;h=573d4f1126e95cb939832a9f2da0eb1f2b9499ec;hb=7ae551fd03b447e41d3a74e803a711350383ebc4;hp=3e6ff685b7adfaa94dcaf83c2bc7f7e3bc9f9fe9;hpb=cc74659fcc7502434d9452718bd47a46e70a0962;p=oweals%2Fopenssl.git diff --git a/crypto/perlasm/x86unix.pl b/crypto/perlasm/x86unix.pl index 3e6ff685b7..573d4f1126 100644 --- a/crypto/perlasm/x86unix.pl +++ b/crypto/perlasm/x86unix.pl @@ -4,6 +4,7 @@ package x86unix; $label="L000"; $const=""; +$constl=0; $align=($main'aout)?"4":"16"; $under=($main'aout)?"_":""; @@ -163,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"); } @@ -342,13 +345,10 @@ sub main'function_end popl %ebx popl %ebp ret +.${func}_end: EOF push(@out,$tmp); - push(@out,$const); - $const=""; - push(@out,".${func}_end:\n"); - if ($main'cpp) { push(@out,"\tSIZE($func,.${func}_end-$func)\n"); } elsif ($main'gaswin) @@ -458,6 +458,12 @@ sub main'set_label sub main'file_end { + if ($const ne "") + { + push(@out,".section .rodata\n"); + push(@out,$const); + $const=""; + } } sub main'data_word @@ -465,23 +471,74 @@ sub main'data_word push(@out,"\t.long $_[0]\n"); } +# debug output functions: puts, putx, printf + sub main'puts { - $constl++; - &main'push('$Lstring' . $constl); - &main'call('puts'); - &main'add("esp",4); - - $const .= "Lstring$constl:\n\t.string \"@_[0]\"\n"; + &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 { - $constl++; - &main'push($_[0]); - &main'push('$Lstring' . $constl); - &main'call('printf'); - &main'add("esp",8); + &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(); + } - $const .= "Lstring$constl:\n\t.string \"\%X\"\n"; +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(); }