diff options
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libcrypto/perlasm/x86unix.pl | 141 |
1 files changed, 128 insertions, 13 deletions
diff --git a/src/lib/libcrypto/perlasm/x86unix.pl b/src/lib/libcrypto/perlasm/x86unix.pl index 6ee4dd3245..9ceabf0705 100644 --- a/src/lib/libcrypto/perlasm/x86unix.pl +++ b/src/lib/libcrypto/perlasm/x86unix.pl | |||
| @@ -1,14 +1,10 @@ | |||
| 1 | #!/usr/bin/perl | 1 | #!/usr/local/bin/perl |
| 2 | |||
| 3 | # Because the bswapl instruction is not supported for old assembers | ||
| 4 | # (it was a new instruction for the 486), I've added .byte xxxx code | ||
| 5 | # to put it in. | ||
| 6 | # eric 24-Apr-1998 | ||
| 7 | # | ||
| 8 | 2 | ||
| 9 | package x86unix; | 3 | package x86unix; |
| 10 | 4 | ||
| 11 | $label="L000"; | 5 | $label="L000"; |
| 6 | $const=""; | ||
| 7 | $constl=0; | ||
| 12 | 8 | ||
| 13 | $align=($main'aout)?"4":"16"; | 9 | $align=($main'aout)?"4":"16"; |
| 14 | $under=($main'aout)?"_":""; | 10 | $under=($main'aout)?"_":""; |
| @@ -85,12 +81,17 @@ sub main'DWP | |||
| 85 | local($addr,$reg1,$reg2,$idx)=@_; | 81 | local($addr,$reg1,$reg2,$idx)=@_; |
| 86 | 82 | ||
| 87 | $ret=""; | 83 | $ret=""; |
| 88 | $addr =~ s/(^|[+ \t])([A-Za-z_]+)($|[+ \t])/$1$under$2$3/; | 84 | $addr =~ s/(^|[+ \t])([A-Za-z_]+[A-Za-z0-9_]+)($|[+ \t])/$1$under$2$3/; |
| 89 | $reg1="$regs{$reg1}" if defined($regs{$reg1}); | 85 | $reg1="$regs{$reg1}" if defined($regs{$reg1}); |
| 90 | $reg2="$regs{$reg2}" if defined($regs{$reg2}); | 86 | $reg2="$regs{$reg2}" if defined($regs{$reg2}); |
| 91 | $ret.=$addr if ($addr ne "") && ($addr ne 0); | 87 | $ret.=$addr if ($addr ne "") && ($addr ne 0); |
| 92 | if ($reg2 ne "") | 88 | if ($reg2 ne "") |
| 93 | { $ret.="($reg1,$reg2,$idx)"; } | 89 | { |
| 90 | if($idx ne "") | ||
| 91 | { $ret.="($reg1,$reg2,$idx)"; } | ||
| 92 | else | ||
| 93 | { $ret.="($reg1,$reg2)"; } | ||
| 94 | } | ||
| 94 | else | 95 | else |
| 95 | { $ret.="($reg1)" } | 96 | { $ret.="($reg1)" } |
| 96 | return($ret); | 97 | return($ret); |
| @@ -101,6 +102,16 @@ sub main'BP | |||
| 101 | return(&main'DWP(@_)); | 102 | return(&main'DWP(@_)); |
| 102 | } | 103 | } |
| 103 | 104 | ||
| 105 | sub main'BC | ||
| 106 | { | ||
| 107 | return @_; | ||
| 108 | } | ||
| 109 | |||
| 110 | sub main'DWC | ||
| 111 | { | ||
| 112 | return @_; | ||
| 113 | } | ||
| 114 | |||
| 104 | #sub main'BP | 115 | #sub main'BP |
| 105 | # { | 116 | # { |
| 106 | # local($addr,$reg1,$reg2,$idx)=@_; | 117 | # local($addr,$reg1,$reg2,$idx)=@_; |
| @@ -153,12 +164,29 @@ sub main'dec { &out1("decl",@_); } | |||
| 153 | sub main'inc { &out1("incl",@_); } | 164 | sub main'inc { &out1("incl",@_); } |
| 154 | sub main'push { &out1("pushl",@_); $stack+=4; } | 165 | sub main'push { &out1("pushl",@_); $stack+=4; } |
| 155 | sub main'pop { &out1("popl",@_); $stack-=4; } | 166 | sub main'pop { &out1("popl",@_); $stack-=4; } |
| 156 | sub main'bswap { &out1("bswapl",@_); } | 167 | sub main'pushf { &out0("pushf"); $stack+=4; } |
| 168 | sub main'popf { &out0("popf"); $stack-=4; } | ||
| 157 | sub main'not { &out1("notl",@_); } | 169 | sub main'not { &out1("notl",@_); } |
| 158 | sub main'call { &out1("call",$under.$_[0]); } | 170 | sub main'call { &out1("call",$under.$_[0]); } |
| 159 | sub main'ret { &out0("ret"); } | 171 | sub main'ret { &out0("ret"); } |
| 160 | sub main'nop { &out0("nop"); } | 172 | sub main'nop { &out0("nop"); } |
| 161 | 173 | ||
| 174 | # The bswapl instruction is new for the 486. Emulate if i386. | ||
| 175 | sub main'bswap | ||
| 176 | { | ||
| 177 | if ($main'i386) | ||
| 178 | { | ||
| 179 | &main'comment("bswapl @_"); | ||
| 180 | &main'exch(main'HB(@_),main'LB(@_)); | ||
| 181 | &main'rotr(@_,16); | ||
| 182 | &main'exch(main'HB(@_),main'LB(@_)); | ||
| 183 | } | ||
| 184 | else | ||
| 185 | { | ||
| 186 | &out1("bswapl",@_); | ||
| 187 | } | ||
| 188 | } | ||
| 189 | |||
| 162 | sub out2 | 190 | sub out2 |
| 163 | { | 191 | { |
| 164 | local($name,$p1,$p2)=@_; | 192 | local($name,$p1,$p2)=@_; |
| @@ -268,6 +296,8 @@ EOF | |||
| 268 | push(@out,$tmp); | 296 | push(@out,$tmp); |
| 269 | if ($main'cpp) | 297 | if ($main'cpp) |
| 270 | { $tmp=push(@out,"\tTYPE($func,\@function)\n"); } | 298 | { $tmp=push(@out,"\tTYPE($func,\@function)\n"); } |
| 299 | elsif ($main'gaswin) | ||
| 300 | { $tmp=push(@out,"\t.def\t$func;\t.scl\t2;\t.type\t32;\t.endef\n"); } | ||
| 271 | else { $tmp=push(@out,"\t.type\t$func,\@function\n"); } | 301 | else { $tmp=push(@out,"\t.type\t$func,\@function\n"); } |
| 272 | push(@out,"$func:\n"); | 302 | push(@out,"$func:\n"); |
| 273 | $tmp=<<"EOF"; | 303 | $tmp=<<"EOF"; |
| @@ -296,6 +326,8 @@ EOF | |||
| 296 | push(@out,$tmp); | 326 | push(@out,$tmp); |
| 297 | if ($main'cpp) | 327 | if ($main'cpp) |
| 298 | { push(@out,"\tTYPE($func,\@function)\n"); } | 328 | { push(@out,"\tTYPE($func,\@function)\n"); } |
| 329 | elsif ($main'gaswin) | ||
| 330 | { $tmp=push(@out,"\t.def\t$func;\t.scl\t2;\t.type\t32;\t.endef\n"); } | ||
| 299 | else { push(@out,"\t.type $func,\@function\n"); } | 331 | else { push(@out,"\t.type $func,\@function\n"); } |
| 300 | push(@out,"$func:\n"); | 332 | push(@out,"$func:\n"); |
| 301 | $stack=4; | 333 | $stack=4; |
| @@ -316,8 +348,11 @@ sub main'function_end | |||
| 316 | .${func}_end: | 348 | .${func}_end: |
| 317 | EOF | 349 | EOF |
| 318 | push(@out,$tmp); | 350 | push(@out,$tmp); |
| 351 | |||
| 319 | if ($main'cpp) | 352 | if ($main'cpp) |
| 320 | { push(@out,"\tSIZE($func,.${func}_end-$func)\n"); } | 353 | { push(@out,"\tSIZE($func,.${func}_end-$func)\n"); } |
| 354 | elsif ($main'gaswin) | ||
| 355 | { $tmp=push(@out,"\t.align 4\n"); } | ||
| 321 | else { push(@out,"\t.size\t$func,.${func}_end-$func\n"); } | 356 | else { push(@out,"\t.size\t$func,.${func}_end-$func\n"); } |
| 322 | push(@out,".ident \"$func\"\n"); | 357 | push(@out,".ident \"$func\"\n"); |
| 323 | $stack=0; | 358 | $stack=0; |
| @@ -344,10 +379,12 @@ sub main'function_end_B | |||
| 344 | 379 | ||
| 345 | $func=$under.$func; | 380 | $func=$under.$func; |
| 346 | 381 | ||
| 347 | push(@out,".${func}_end:\n"); | 382 | push(@out,".L_${func}_end:\n"); |
| 348 | if ($main'cpp) | 383 | if ($main'cpp) |
| 349 | { push(@out,"\tSIZE($func,.${func}_end-$func)\n"); } | 384 | { push(@out,"\tSIZE($func,.L_${func}_end-$func)\n"); } |
| 350 | else { push(@out,"\t.size\t$func,.${func}_end-$func\n"); } | 385 | elsif ($main'gaswin) |
| 386 | { push(@out,"\t.align 4\n"); } | ||
| 387 | else { push(@out,"\t.size\t$func,.L_${func}_end-$func\n"); } | ||
| 351 | push(@out,".ident \"desasm.pl\"\n"); | 388 | push(@out,".ident \"desasm.pl\"\n"); |
| 352 | $stack=0; | 389 | $stack=0; |
| 353 | %label=(); | 390 | %label=(); |
| @@ -421,9 +458,87 @@ sub main'set_label | |||
| 421 | 458 | ||
| 422 | sub main'file_end | 459 | sub main'file_end |
| 423 | { | 460 | { |
| 461 | if ($const ne "") | ||
| 462 | { | ||
| 463 | push(@out,".section .rodata\n"); | ||
| 464 | push(@out,$const); | ||
| 465 | $const=""; | ||
| 466 | } | ||
| 424 | } | 467 | } |
| 425 | 468 | ||
| 426 | sub main'data_word | 469 | sub main'data_word |
| 427 | { | 470 | { |
| 428 | push(@out,"\t.long $_[0]\n"); | 471 | push(@out,"\t.long $_[0]\n"); |
| 429 | } | 472 | } |
| 473 | |||
| 474 | # debug output functions: puts, putx, printf | ||
| 475 | |||
| 476 | sub main'puts | ||
| 477 | { | ||
| 478 | &pushvars(); | ||
| 479 | &main'push('$Lstring' . ++$constl); | ||
| 480 | &main'call('puts'); | ||
| 481 | $stack-=4; | ||
| 482 | &main'add("esp",4); | ||
| 483 | &popvars(); | ||
| 484 | |||
| 485 | $const .= "Lstring$constl:\n\t.string \"@_[0]\"\n"; | ||
| 486 | } | ||
| 487 | |||
| 488 | sub main'putx | ||
| 489 | { | ||
| 490 | &pushvars(); | ||
| 491 | &main'push($_[0]); | ||
| 492 | &main'push('$Lstring' . ++$constl); | ||
| 493 | &main'call('printf'); | ||
| 494 | &main'add("esp",8); | ||
| 495 | $stack-=8; | ||
| 496 | &popvars(); | ||
| 497 | |||
| 498 | $const .= "Lstring$constl:\n\t.string \"\%X\"\n"; | ||
| 499 | } | ||
| 500 | |||
| 501 | sub main'printf | ||
| 502 | { | ||
| 503 | $ostack = $stack; | ||
| 504 | &pushvars(); | ||
| 505 | for ($i = @_ - 1; $i >= 0; $i--) | ||
| 506 | { | ||
| 507 | if ($i == 0) # change this to support %s format strings | ||
| 508 | { | ||
| 509 | &main'push('$Lstring' . ++$constl); | ||
| 510 | $const .= "Lstring$constl:\n\t.string \"@_[$i]\"\n"; | ||
| 511 | } | ||
| 512 | else | ||
| 513 | { | ||
| 514 | if ($_[$i] =~ /([0-9]*)\(%esp\)/) | ||
| 515 | { | ||
| 516 | &main'push(($1 + $stack - $ostack) . '(%esp)'); | ||
| 517 | } | ||
| 518 | else | ||
| 519 | { | ||
| 520 | &main'push($_[$i]); | ||
| 521 | } | ||
| 522 | } | ||
| 523 | } | ||
| 524 | &main'call('printf'); | ||
| 525 | $stack-=4*@_; | ||
| 526 | &main'add("esp",4*@_); | ||
| 527 | &popvars(); | ||
| 528 | } | ||
| 529 | |||
| 530 | sub pushvars | ||
| 531 | { | ||
| 532 | &main'pushf(); | ||
| 533 | &main'push("edx"); | ||
| 534 | &main'push("ecx"); | ||
| 535 | &main'push("eax"); | ||
| 536 | } | ||
| 537 | |||
| 538 | sub popvars | ||
| 539 | { | ||
| 540 | &main'pop("eax"); | ||
| 541 | &main'pop("ecx"); | ||
| 542 | &main'pop("edx"); | ||
| 543 | &main'popf(); | ||
| 544 | } | ||
