diff options
author | Ralf S. Engelschall <rse@openssl.org> | 1998-12-21 10:56:39 +0000 |
---|---|---|
committer | Ralf S. Engelschall <rse@openssl.org> | 1998-12-21 10:56:39 +0000 |
commit | 58964a492275ca9a59a0cd9c8155cb2491b4b909 (patch) | |
tree | c7b16876a5789463bbbb468ef4829c8129b3d718 /crypto/perlasm/x86ms.pl | |
parent | d02b48c63a58ea4367a0e905979f140b7d090f86 (diff) | |
download | openssl-58964a492275ca9a59a0cd9c8155cb2491b4b909.tar.gz |
Import of old SSLeay release: SSLeay 0.9.0b
Diffstat (limited to 'crypto/perlasm/x86ms.pl')
-rw-r--r-- | crypto/perlasm/x86ms.pl | 189 |
1 files changed, 144 insertions, 45 deletions
diff --git a/crypto/perlasm/x86ms.pl b/crypto/perlasm/x86ms.pl index 558112e082..b8b1909567 100644 --- a/crypto/perlasm/x86ms.pl +++ b/crypto/perlasm/x86ms.pl @@ -24,6 +24,11 @@ $label="L000"; 'dx', 'dh', ); +sub main'asm_init_output { @out=(); } +sub main'asm_get_output { return(@out); } +sub main'get_labels { return(@labels); } +sub main'external_label { push(@labels,@_); } + sub main'LB { (defined($lb{$_[0]})) || die "$_[0] does not have a 'low byte'\n"; @@ -36,11 +41,35 @@ sub main'HB return($hb{$_[0]}); } +sub main'BP + { + &get_mem("BYTE",@_); + } + sub main'DWP { - local($addr,$reg1,$reg2,$idx)=@_; - local($t); - local($ret)="DWORD PTR "; + &get_mem("DWORD",@_); + } + +sub main'stack_push + { + local($num)=@_; + $stack+=$num*4; + &main'sub("esp",$num*4); + } + +sub main'stack_pop + { + local($num)=@_; + $stack-=$num*4; + &main'add("esp",$num*4); + } + +sub get_mem + { + local($size,$addr,$reg1,$reg2,$idx)=@_; + local($t,$post); + local($ret)="$size PTR "; $addr =~ s/^\s+//; if ($addr =~ /^(.+)\+(.+)$/) @@ -55,16 +84,22 @@ sub main'DWP $reg1="$regs{$reg1}" if defined($regs{$reg1}); $reg2="$regs{$reg2}" if defined($regs{$reg2}); - $ret.=$addr if ($addr ne "") && ($addr ne 0); + if (($addr ne "") && ($addr ne 0)) + { + if ($addr !~ /^-/) + { $ret.=$addr; } + else { $post=$addr; } + } if ($reg2 ne "") { $t=""; $t="*$idx" if ($idx != 0); - $ret.="[$reg2$t+$reg1]"; + $reg1="+".$reg1 if ("$reg1$post" ne ""); + $ret.="[$reg2$t$reg1$post]"; } else { - $ret.="[$reg1]" + $ret.="[$reg1$post]" } return($ret); } @@ -76,34 +111,60 @@ sub main'or { &out2("or",@_); } sub main'shl { &out2("shl",@_); } sub main'shr { &out2("shr",@_); } sub main'xor { &out2("xor",@_); } +sub main'xorb { &out2("xor",@_); } sub main'add { &out2("add",@_); } +sub main'adc { &out2("adc",@_); } sub main'sub { &out2("sub",@_); } sub main'rotl { &out2("rol",@_); } sub main'rotr { &out2("ror",@_); } sub main'exch { &out2("xchg",@_); } sub main'cmp { &out2("cmp",@_); } +sub main'lea { &out2("lea",@_); } +sub main'mul { &out1("mul",@_); } +sub main'div { &out1("div",@_); } sub main'dec { &out1("dec",@_); } +sub main'inc { &out1("inc",@_); } sub main'jmp { &out1("jmp",@_); } +sub main'jmp_ptr { &out1p("jmp",@_); } sub main'je { &out1("je",@_); } +sub main'jle { &out1("jle",@_); } sub main'jz { &out1("jz",@_); } +sub main'jge { &out1("jge",@_); } +sub main'jl { &out1("jl",@_); } +sub main'jb { &out1("jb",@_); } +sub main'jc { &out1("jc",@_); } +sub main'jnc { &out1("jnc",@_); } sub main'jnz { &out1("jnz",@_); } -sub main'push { &out1("push",@_); } +sub main'jne { &out1("jne",@_); } +sub main'jno { &out1("jno",@_); } +sub main'push { &out1("push",@_); $stack+=4; } +sub main'pop { &out1("pop",@_); $stack-=4; } +sub main'bswap { &out1("bswap",@_); &using486(); } +sub main'not { &out1("not",@_); } sub main'call { &out1("call",'_'.$_[0]); } - +sub main'ret { &out0("ret"); } +sub main'nop { &out0("nop"); } sub out2 { local($name,$p1,$p2)=@_; local($l,$t); - print "\t$name\t"; + push(@out,"\t$name\t"); $t=&conv($p1).","; $l=length($t); - print $t; + push(@out,$t); $l=4-($l+9)/8; - print "\t" x $l; - print &conv($p2); - print "\n"; + push(@out,"\t" x $l); + push(@out,&conv($p2)); + push(@out,"\n"); + } + +sub out0 + { + local($name)=@_; + + push(@out,"\t$name\n"); } sub out1 @@ -111,9 +172,7 @@ sub out1 local($name,$p1)=@_; local($l,$t); - print "\t$name\t"; - print &conv($p1); - print "\n"; + push(@out,"\t$name\t".&conv($p1)."\n"); } sub conv @@ -124,24 +183,32 @@ sub conv return $p; } +sub using486 + { + return if $using486; + $using486++; + grep(s/\.386/\.486/,@out); + } + sub main'file { local($file)=@_; - print <<"EOF"; + local($tmp)=<<"EOF"; TITLE $file.asm .386 .model FLAT EOF + push(@out,$tmp); } sub main'function_begin { - local($func,$num,$extra)=@_; + local($func,$extra)=@_; - $params=$num*4; + push(@labels,$func); - print <<"EOF"; + local($tmp)=<<"EOF"; _TEXT SEGMENT PUBLIC _$func $extra @@ -151,14 +218,29 @@ _$func PROC NEAR push esi push edi EOF + push(@out,$tmp); $stack=20; } +sub main'function_begin_B + { + local($func,$extra)=@_; + + local($tmp)=<<"EOF"; +_TEXT SEGMENT +PUBLIC _$func +$extra +_$func PROC NEAR +EOF + push(@out,$tmp); + $stack=4; + } + sub main'function_end { local($func)=@_; - print <<"EOF"; + local($tmp)=<<"EOF"; pop edi pop esi pop ebx @@ -167,38 +249,41 @@ sub main'function_end _$func ENDP _TEXT ENDS EOF + push(@out,$tmp); $stack=0; %label=(); } -sub main'function_end_A +sub main'function_end_B { local($func)=@_; - print <<"EOF"; - pop edi - pop esi - pop ebx - pop ebp - ret + local($tmp)=<<"EOF"; +_$func ENDP +_TEXT ENDS EOF + push(@out,$tmp); + $stack=0; + %label=(); } -sub main'function_end_B +sub main'function_end_A { local($func)=@_; - print <<"EOF"; -_$func ENDP -_TEXT ENDS + local($tmp)=<<"EOF"; + pop edi + pop esi + pop ebx + pop ebp + ret EOF - $stack=0; - %label=(); + push(@out,$tmp); } sub main'file_end { - print "END\n" + push(@out,"END\n"); } sub main'wparam @@ -208,18 +293,24 @@ sub main'wparam return(&main'DWP($stack+$num*4,"esp","",0)); } -sub main'wtmp +sub main'swtmp { - local($num)=@_; - - return(&main'DWP($stack+$params+$num*4,"esp","",0)); + return(&main'DWP($_[0]*4,"esp","",0)); } +# Should use swtmp, which is above esp. Linix can trash the stack above esp +#sub main'wtmp +# { +# local($num)=@_; +# +# return(&main'DWP(-(($num+1)*4),"esp","",0)); +# } + sub main'comment { foreach (@_) { - print "\t; $_\n"; + push(@out,"\t; $_\n"); } } @@ -240,10 +331,18 @@ sub main'set_label $label{$_[0]}="${label}${_[0]}"; $label++; } - print "$label{$_[0]}:\n"; + push(@out,"$label{$_[0]}:\n"); } -sub main'file_end - { - print "END\n"; - } +sub main'data_word + { + push(@out,"\tDD\t$_[0]\n"); + } + +sub out1p + { + local($name,$p1)=@_; + local($l,$t); + + push(@out,"\t$name\t ".&conv($p1)."\n"); + } |