diff options
Diffstat (limited to 'src/lib/libcrypto/perlasm')
| -rw-r--r-- | src/lib/libcrypto/perlasm/cbc.pl | 2 | ||||
| -rwxr-xr-x | src/lib/libcrypto/perlasm/x86_64-xlate.pl | 13 | ||||
| -rw-r--r-- | src/lib/libcrypto/perlasm/x86asm.pl | 16 | ||||
| -rw-r--r-- | src/lib/libcrypto/perlasm/x86gas.pl | 24 | ||||
| -rw-r--r-- | src/lib/libcrypto/perlasm/x86masm.pl | 184 | ||||
| -rw-r--r-- | src/lib/libcrypto/perlasm/x86nasm.pl | 166 |
6 files changed, 395 insertions, 10 deletions
diff --git a/src/lib/libcrypto/perlasm/cbc.pl b/src/lib/libcrypto/perlasm/cbc.pl index 6fc2510905..e43dc9ae15 100644 --- a/src/lib/libcrypto/perlasm/cbc.pl +++ b/src/lib/libcrypto/perlasm/cbc.pl | |||
| @@ -158,6 +158,7 @@ sub cbc | |||
| 158 | &jmp_ptr($count); | 158 | &jmp_ptr($count); |
| 159 | 159 | ||
| 160 | &set_label("ej7"); | 160 | &set_label("ej7"); |
| 161 | &xor("edx", "edx") if $ppro; # ppro friendly | ||
| 161 | &movb(&HB("edx"), &BP(6,$in,"",0)); | 162 | &movb(&HB("edx"), &BP(6,$in,"",0)); |
| 162 | &shl("edx",8); | 163 | &shl("edx",8); |
| 163 | &set_label("ej6"); | 164 | &set_label("ej6"); |
| @@ -169,6 +170,7 @@ sub cbc | |||
| 169 | &jmp(&label("ejend")); | 170 | &jmp(&label("ejend")); |
| 170 | &set_label("ej3"); | 171 | &set_label("ej3"); |
| 171 | &movb(&HB("ecx"), &BP(2,$in,"",0)); | 172 | &movb(&HB("ecx"), &BP(2,$in,"",0)); |
| 173 | &xor("ecx", "ecx") if $ppro; # ppro friendly | ||
| 172 | &shl("ecx",8); | 174 | &shl("ecx",8); |
| 173 | &set_label("ej2"); | 175 | &set_label("ej2"); |
| 174 | &movb(&HB("ecx"), &BP(1,$in,"",0)); | 176 | &movb(&HB("ecx"), &BP(1,$in,"",0)); |
diff --git a/src/lib/libcrypto/perlasm/x86_64-xlate.pl b/src/lib/libcrypto/perlasm/x86_64-xlate.pl index e47116b74b..d66ad24095 100755 --- a/src/lib/libcrypto/perlasm/x86_64-xlate.pl +++ b/src/lib/libcrypto/perlasm/x86_64-xlate.pl | |||
| @@ -66,7 +66,7 @@ if ($flavour =~ /\./) { $output = $flavour; undef $flavour; } | |||
| 66 | my ($outdev,$outino,@junk)=stat($output); | 66 | my ($outdev,$outino,@junk)=stat($output); |
| 67 | 67 | ||
| 68 | open STDOUT,">$output" || die "can't open $output: $!" | 68 | open STDOUT,">$output" || die "can't open $output: $!" |
| 69 | if ($stddev!=$outdev || $stdino!=$outino); | 69 | if (1 || $stddev!=$outdev || $stdino!=$outino); |
| 70 | } | 70 | } |
| 71 | 71 | ||
| 72 | my $gas=1; $gas=0 if ($output =~ /\.asm$/); | 72 | my $gas=1; $gas=0 if ($output =~ /\.asm$/); |
| @@ -167,7 +167,7 @@ my %globals; | |||
| 167 | } elsif ($self->{op} =~ /^(pop|push)f/) { | 167 | } elsif ($self->{op} =~ /^(pop|push)f/) { |
| 168 | $self->{op} .= $self->{sz}; | 168 | $self->{op} .= $self->{sz}; |
| 169 | } elsif ($self->{op} eq "call" && $current_segment eq ".CRT\$XCU") { | 169 | } elsif ($self->{op} eq "call" && $current_segment eq ".CRT\$XCU") { |
| 170 | $self->{op} = "\tDQ"; | 170 | $self->{op} = "ALIGN\t8\n\tDQ"; |
| 171 | } | 171 | } |
| 172 | $self->{op}; | 172 | $self->{op}; |
| 173 | } | 173 | } |
| @@ -215,7 +215,8 @@ my %globals; | |||
| 215 | undef $ret; | 215 | undef $ret; |
| 216 | 216 | ||
| 217 | # optional * ---vvv--- appears in indirect jmp/call | 217 | # optional * ---vvv--- appears in indirect jmp/call |
| 218 | if ($line =~ /^(\*?)([^\(,]*)\(([%\w,]+)\)/) { | 218 | if ($line =~ /^(\*?)([^\(,]*)\(([%\w,]+)\)/ && |
| 219 | !($line =~ /^PIC_(GOT|PLT)/)) { | ||
| 219 | $self->{asterisk} = $1; | 220 | $self->{asterisk} = $1; |
| 220 | $self->{label} = $2; | 221 | $self->{label} = $2; |
| 221 | ($self->{base},$self->{index},$self->{scale})=split(/,/,$3); | 222 | ($self->{base},$self->{index},$self->{scale})=split(/,/,$3); |
| @@ -545,8 +546,6 @@ my %globals; | |||
| 545 | if ($line=~/\.([px])data/) { | 546 | if ($line=~/\.([px])data/) { |
| 546 | $v.=" rdata align="; | 547 | $v.=" rdata align="; |
| 547 | $v.=$1 eq "p"? 4 : 8; | 548 | $v.=$1 eq "p"? 4 : 8; |
| 548 | } elsif ($line=~/\.CRT\$/i) { | ||
| 549 | $v.=" rdata align=8"; | ||
| 550 | } | 549 | } |
| 551 | } else { | 550 | } else { |
| 552 | $v="$current_segment\tENDS\n" if ($current_segment); | 551 | $v="$current_segment\tENDS\n" if ($current_segment); |
| @@ -554,8 +553,6 @@ my %globals; | |||
| 554 | if ($line=~/\.([px])data/) { | 553 | if ($line=~/\.([px])data/) { |
| 555 | $v.=" READONLY"; | 554 | $v.=" READONLY"; |
| 556 | $v.=" ALIGN(".($1 eq "p" ? 4 : 8).")" if ($masm>=$masmref); | 555 | $v.=" ALIGN(".($1 eq "p" ? 4 : 8).")" if ($masm>=$masmref); |
| 557 | } elsif ($line=~/\.CRT\$/i) { | ||
| 558 | $v.=" READONLY DWORD"; | ||
| 559 | } | 556 | } |
| 560 | } | 557 | } |
| 561 | $current_segment = $line; | 558 | $current_segment = $line; |
| @@ -625,6 +622,8 @@ my %globals; | |||
| 625 | } | 622 | } |
| 626 | } | 623 | } |
| 627 | 624 | ||
| 625 | print "#include <machine/asm.h>\n"; | ||
| 626 | |||
| 628 | if ($nasm) { | 627 | if ($nasm) { |
| 629 | print <<___; | 628 | print <<___; |
| 630 | default rel | 629 | default rel |
diff --git a/src/lib/libcrypto/perlasm/x86asm.pl b/src/lib/libcrypto/perlasm/x86asm.pl index 28080caaa6..4756a28e59 100644 --- a/src/lib/libcrypto/perlasm/x86asm.pl +++ b/src/lib/libcrypto/perlasm/x86asm.pl | |||
| @@ -33,6 +33,13 @@ sub ::emit | |||
| 33 | else { push(@out,"\t$opcode\t".join(',',@_)."\n"); } | 33 | else { push(@out,"\t$opcode\t".join(',',@_)."\n"); } |
| 34 | } | 34 | } |
| 35 | 35 | ||
| 36 | sub ::emitraw | ||
| 37 | { my $opcode=shift; | ||
| 38 | |||
| 39 | if ($#_==-1) { push(@out,"$opcode\n"); } | ||
| 40 | else { push(@out,"$opcode\t".join(',',@_)."\n"); } | ||
| 41 | } | ||
| 42 | |||
| 36 | sub ::LB | 43 | sub ::LB |
| 37 | { $_[0] =~ m/^e?([a-d])x$/o or die "$_[0] does not have a 'low byte'"; | 44 | { $_[0] =~ m/^e?([a-d])x$/o or die "$_[0] does not have a 'low byte'"; |
| 38 | $1."l"; | 45 | $1."l"; |
| @@ -167,7 +174,7 @@ sub ::asm_init | |||
| 167 | $filename=$fn; | 174 | $filename=$fn; |
| 168 | $i386=$cpu; | 175 | $i386=$cpu; |
| 169 | 176 | ||
| 170 | $elf=$cpp=$coff=$aout=$macosx=$win32=$netware=$mwerks=0; | 177 | $elf=$cpp=$coff=$aout=$macosx=$win32=$netware=$mwerks=$openbsd=0; |
| 171 | if (($type eq "elf")) | 178 | if (($type eq "elf")) |
| 172 | { $elf=1; require "x86gas.pl"; } | 179 | { $elf=1; require "x86gas.pl"; } |
| 173 | elsif (($type eq "a\.out")) | 180 | elsif (($type eq "a\.out")) |
| @@ -184,6 +191,10 @@ sub ::asm_init | |||
| 184 | { $win32=1; require "x86masm.pl"; } | 191 | { $win32=1; require "x86masm.pl"; } |
| 185 | elsif (($type eq "macosx")) | 192 | elsif (($type eq "macosx")) |
| 186 | { $aout=1; $macosx=1; require "x86gas.pl"; } | 193 | { $aout=1; $macosx=1; require "x86gas.pl"; } |
| 194 | elsif (($type eq "openbsd-elf")) | ||
| 195 | { $openbsd=$elf=1; require "x86gas.pl"; } | ||
| 196 | elsif (($type eq "openbsd-a.out")) | ||
| 197 | { $openbsd=1; require "x86gas.pl"; } | ||
| 187 | else | 198 | else |
| 188 | { print STDERR <<"EOF"; | 199 | { print STDERR <<"EOF"; |
| 189 | Pick one target type from | 200 | Pick one target type from |
| @@ -191,6 +202,8 @@ Pick one target type from | |||
| 191 | a.out - DJGPP, elder OpenBSD, etc. | 202 | a.out - DJGPP, elder OpenBSD, etc. |
| 192 | coff - GAS/COFF such as Win32 targets | 203 | coff - GAS/COFF such as Win32 targets |
| 193 | win32n - Windows 95/Windows NT NASM format | 204 | win32n - Windows 95/Windows NT NASM format |
| 205 | openbsd-elf - OpenBSD elf | ||
| 206 | openbsd-a.out - OpenBSD a.out | ||
| 194 | nw-nasm - NetWare NASM format | 207 | nw-nasm - NetWare NASM format |
| 195 | macosx - Mac OS X | 208 | macosx - Mac OS X |
| 196 | EOF | 209 | EOF |
| @@ -200,6 +213,7 @@ EOF | |||
| 200 | $pic=0; | 213 | $pic=0; |
| 201 | for (@ARGV) { $pic=1 if (/\-[fK]PIC/i); } | 214 | for (@ARGV) { $pic=1 if (/\-[fK]PIC/i); } |
| 202 | 215 | ||
| 216 | ::emitraw("#include <machine/asm.h>\n") if $openbsd; | ||
| 203 | $filename =~ s/\.pl$//; | 217 | $filename =~ s/\.pl$//; |
| 204 | &file($filename); | 218 | &file($filename); |
| 205 | } | 219 | } |
diff --git a/src/lib/libcrypto/perlasm/x86gas.pl b/src/lib/libcrypto/perlasm/x86gas.pl index 6eab727fd4..15e17f25d0 100644 --- a/src/lib/libcrypto/perlasm/x86gas.pl +++ b/src/lib/libcrypto/perlasm/x86gas.pl | |||
| @@ -180,7 +180,16 @@ sub ::align | |||
| 180 | sub ::picmeup | 180 | sub ::picmeup |
| 181 | { my($dst,$sym,$base,$reflabel)=@_; | 181 | { my($dst,$sym,$base,$reflabel)=@_; |
| 182 | 182 | ||
| 183 | if ($::pic && ($::elf || $::aout)) | 183 | if ($::openbsd) |
| 184 | { &::emitraw("#ifdef PIC"); | ||
| 185 | &::emitraw("PIC_PROLOGUE"); | ||
| 186 | &::mov($dst, &::DWP("PIC_GOT($sym)")); | ||
| 187 | &::emitraw("PIC_EPILOGUE"); | ||
| 188 | &::emitraw("#else /* PIC */"); | ||
| 189 | &::lea($dst,&::DWP($sym)); | ||
| 190 | &::emitraw("#endif /* PIC */"); | ||
| 191 | } | ||
| 192 | elsif ($::pic && ($::elf || $::aout)) | ||
| 184 | { if (!defined($base)) | 193 | { if (!defined($base)) |
| 185 | { &::call(&::label("PIC_me_up")); | 194 | { &::call(&::label("PIC_me_up")); |
| 186 | &::set_label("PIC_me_up"); | 195 | &::set_label("PIC_me_up"); |
| @@ -206,7 +215,18 @@ sub ::picmeup | |||
| 206 | sub ::initseg | 215 | sub ::initseg |
| 207 | { my $f=$nmdecor.shift; | 216 | { my $f=$nmdecor.shift; |
| 208 | 217 | ||
| 209 | if ($::elf) | 218 | if ($::openbsd) |
| 219 | { $initseg.=<<___; | ||
| 220 | .section .init | ||
| 221 | PIC_PROLOGUE | ||
| 222 | call PIC_PLT($f) | ||
| 223 | PIC_EPILOGUE | ||
| 224 | jmp .Linitalign | ||
| 225 | .align $align | ||
| 226 | .Linitalign: | ||
| 227 | ___ | ||
| 228 | } | ||
| 229 | elsif ($::elf) | ||
| 210 | { $initseg.=<<___; | 230 | { $initseg.=<<___; |
| 211 | .section .init | 231 | .section .init |
| 212 | call $f | 232 | call $f |
diff --git a/src/lib/libcrypto/perlasm/x86masm.pl b/src/lib/libcrypto/perlasm/x86masm.pl new file mode 100644 index 0000000000..3d50e4a786 --- /dev/null +++ b/src/lib/libcrypto/perlasm/x86masm.pl | |||
| @@ -0,0 +1,184 @@ | |||
| 1 | #!/usr/bin/env perl | ||
| 2 | |||
| 3 | package x86masm; | ||
| 4 | |||
| 5 | *out=\@::out; | ||
| 6 | |||
| 7 | $::lbdecor="\$L"; # local label decoration | ||
| 8 | $nmdecor="_"; # external name decoration | ||
| 9 | |||
| 10 | $initseg=""; | ||
| 11 | $segment=""; | ||
| 12 | |||
| 13 | sub ::generic | ||
| 14 | { my ($opcode,@arg)=@_; | ||
| 15 | |||
| 16 | # fix hexadecimal constants | ||
| 17 | for (@arg) { s/0x([0-9a-f]+)/0$1h/oi; } | ||
| 18 | |||
| 19 | if ($opcode !~ /movq/) | ||
| 20 | { # fix xmm references | ||
| 21 | $arg[0] =~ s/\b[A-Z]+WORD\s+PTR/XMMWORD PTR/i if ($arg[1]=~/\bxmm[0-7]\b/i); | ||
| 22 | $arg[1] =~ s/\b[A-Z]+WORD\s+PTR/XMMWORD PTR/i if ($arg[0]=~/\bxmm[0-7]\b/i); | ||
| 23 | } | ||
| 24 | |||
| 25 | &::emit($opcode,@arg); | ||
| 26 | 1; | ||
| 27 | } | ||
| 28 | # | ||
| 29 | # opcodes not covered by ::generic above, mostly inconsistent namings... | ||
| 30 | # | ||
| 31 | sub ::call { &::emit("call",(&::islabel($_[0]) or "$nmdecor$_[0]")); } | ||
| 32 | sub ::call_ptr { &::emit("call",@_); } | ||
| 33 | sub ::jmp_ptr { &::emit("jmp",@_); } | ||
| 34 | |||
| 35 | sub get_mem | ||
| 36 | { my($size,$addr,$reg1,$reg2,$idx)=@_; | ||
| 37 | my($post,$ret); | ||
| 38 | |||
| 39 | $ret .= "$size PTR " if ($size ne ""); | ||
| 40 | |||
| 41 | $addr =~ s/^\s+//; | ||
| 42 | # prepend global references with optional underscore | ||
| 43 | $addr =~ s/^([^\+\-0-9][^\+\-]*)/&::islabel($1) or "$nmdecor$1"/ige; | ||
| 44 | # put address arithmetic expression in parenthesis | ||
| 45 | $addr="($addr)" if ($addr =~ /^.+[\-\+].+$/); | ||
| 46 | |||
| 47 | if (($addr ne "") && ($addr ne 0)) | ||
| 48 | { if ($addr !~ /^-/) { $ret .= "$addr"; } | ||
| 49 | else { $post=$addr; } | ||
| 50 | } | ||
| 51 | $ret .= "["; | ||
| 52 | |||
| 53 | if ($reg2 ne "") | ||
| 54 | { $idx!=0 or $idx=1; | ||
| 55 | $ret .= "$reg2*$idx"; | ||
| 56 | $ret .= "+$reg1" if ($reg1 ne ""); | ||
| 57 | } | ||
| 58 | else | ||
| 59 | { $ret .= "$reg1"; } | ||
| 60 | |||
| 61 | $ret .= "$post]"; | ||
| 62 | $ret =~ s/\+\]/]/; # in case $addr was the only argument | ||
| 63 | $ret =~ s/\[\s*\]//; | ||
| 64 | |||
| 65 | $ret; | ||
| 66 | } | ||
| 67 | sub ::BP { &get_mem("BYTE",@_); } | ||
| 68 | sub ::DWP { &get_mem("DWORD",@_); } | ||
| 69 | sub ::QWP { &get_mem("QWORD",@_); } | ||
| 70 | sub ::BC { "@_"; } | ||
| 71 | sub ::DWC { "@_"; } | ||
| 72 | |||
| 73 | sub ::file | ||
| 74 | { my $tmp=<<___; | ||
| 75 | TITLE $_[0].asm | ||
| 76 | IF \@Version LT 800 | ||
| 77 | ECHO MASM version 8.00 or later is strongly recommended. | ||
| 78 | ENDIF | ||
| 79 | .486 | ||
| 80 | .MODEL FLAT | ||
| 81 | OPTION DOTNAME | ||
| 82 | IF \@Version LT 800 | ||
| 83 | .text\$ SEGMENT PAGE 'CODE' | ||
| 84 | ELSE | ||
| 85 | .text\$ SEGMENT ALIGN(64) 'CODE' | ||
| 86 | ENDIF | ||
| 87 | ___ | ||
| 88 | push(@out,$tmp); | ||
| 89 | $segment = ".text\$"; | ||
| 90 | } | ||
| 91 | |||
| 92 | sub ::function_begin_B | ||
| 93 | { my $func=shift; | ||
| 94 | my $global=($func !~ /^_/); | ||
| 95 | my $begin="${::lbdecor}_${func}_begin"; | ||
| 96 | |||
| 97 | &::LABEL($func,$global?"$begin":"$nmdecor$func"); | ||
| 98 | $func="ALIGN\t16\n".$nmdecor.$func."\tPROC"; | ||
| 99 | |||
| 100 | if ($global) { $func.=" PUBLIC\n${begin}::\n"; } | ||
| 101 | else { $func.=" PRIVATE\n"; } | ||
| 102 | push(@out,$func); | ||
| 103 | $::stack=4; | ||
| 104 | } | ||
| 105 | sub ::function_end_B | ||
| 106 | { my $func=shift; | ||
| 107 | |||
| 108 | push(@out,"$nmdecor$func ENDP\n"); | ||
| 109 | $::stack=0; | ||
| 110 | &::wipe_labels(); | ||
| 111 | } | ||
| 112 | |||
| 113 | sub ::file_end | ||
| 114 | { my $xmmheader=<<___; | ||
| 115 | .686 | ||
| 116 | .XMM | ||
| 117 | IF \@Version LT 800 | ||
| 118 | XMMWORD STRUCT 16 | ||
| 119 | DQ 2 dup (?) | ||
| 120 | XMMWORD ENDS | ||
| 121 | ENDIF | ||
| 122 | ___ | ||
| 123 | if (grep {/\b[x]?mm[0-7]\b/i} @out) { | ||
| 124 | grep {s/\.[3-7]86/$xmmheader/} @out; | ||
| 125 | } | ||
| 126 | |||
| 127 | push(@out,"$segment ENDS\n"); | ||
| 128 | |||
| 129 | if (grep {/\b${nmdecor}OPENSSL_ia32cap_P\b/i} @out) | ||
| 130 | { my $comm=<<___; | ||
| 131 | .bss SEGMENT 'BSS' | ||
| 132 | COMM ${nmdecor}OPENSSL_ia32cap_P:DWORD | ||
| 133 | .bss ENDS | ||
| 134 | ___ | ||
| 135 | # comment out OPENSSL_ia32cap_P declarations | ||
| 136 | grep {s/(^EXTERN\s+${nmdecor}OPENSSL_ia32cap_P)/\;$1/} @out; | ||
| 137 | push (@out,$comm); | ||
| 138 | } | ||
| 139 | push (@out,$initseg) if ($initseg); | ||
| 140 | push (@out,"END\n"); | ||
| 141 | } | ||
| 142 | |||
| 143 | sub ::comment { foreach (@_) { push(@out,"\t; $_\n"); } } | ||
| 144 | |||
| 145 | *::set_label_B = sub | ||
| 146 | { my $l=shift; push(@out,$l.($l=~/^\Q${::lbdecor}\E[0-9]{3}/?":\n":"::\n")); }; | ||
| 147 | |||
| 148 | sub ::external_label | ||
| 149 | { foreach(@_) | ||
| 150 | { push(@out, "EXTERN\t".&::LABEL($_,$nmdecor.$_).":NEAR\n"); } | ||
| 151 | } | ||
| 152 | |||
| 153 | sub ::public_label | ||
| 154 | { push(@out,"PUBLIC\t".&::LABEL($_[0],$nmdecor.$_[0])."\n"); } | ||
| 155 | |||
| 156 | sub ::data_byte | ||
| 157 | { push(@out,("DB\t").join(',',@_)."\n"); } | ||
| 158 | |||
| 159 | sub ::data_word | ||
| 160 | { push(@out,("DD\t").join(',',@_)."\n"); } | ||
| 161 | |||
| 162 | sub ::align | ||
| 163 | { push(@out,"ALIGN\t$_[0]\n"); } | ||
| 164 | |||
| 165 | sub ::picmeup | ||
| 166 | { my($dst,$sym)=@_; | ||
| 167 | &::lea($dst,&::DWP($sym)); | ||
| 168 | } | ||
| 169 | |||
| 170 | sub ::initseg | ||
| 171 | { my $f=$nmdecor.shift; | ||
| 172 | |||
| 173 | $initseg.=<<___; | ||
| 174 | .CRT\$XCU SEGMENT DWORD PUBLIC 'DATA' | ||
| 175 | EXTERN $f:NEAR | ||
| 176 | DD $f | ||
| 177 | .CRT\$XCU ENDS | ||
| 178 | ___ | ||
| 179 | } | ||
| 180 | |||
| 181 | sub ::dataseg | ||
| 182 | { push(@out,"$segment\tENDS\n_DATA\tSEGMENT\n"); $segment="_DATA"; } | ||
| 183 | |||
| 184 | 1; | ||
diff --git a/src/lib/libcrypto/perlasm/x86nasm.pl b/src/lib/libcrypto/perlasm/x86nasm.pl new file mode 100644 index 0000000000..ce2bed9bb2 --- /dev/null +++ b/src/lib/libcrypto/perlasm/x86nasm.pl | |||
| @@ -0,0 +1,166 @@ | |||
| 1 | #!/usr/bin/env perl | ||
| 2 | |||
| 3 | package x86nasm; | ||
| 4 | |||
| 5 | *out=\@::out; | ||
| 6 | |||
| 7 | $::lbdecor="L\$"; # local label decoration | ||
| 8 | $nmdecor=$::netware?"":"_"; # external name decoration | ||
| 9 | $drdecor=$::mwerks?".":""; # directive decoration | ||
| 10 | |||
| 11 | $initseg=""; | ||
| 12 | |||
| 13 | sub ::generic | ||
| 14 | { my $opcode=shift; | ||
| 15 | my $tmp; | ||
| 16 | |||
| 17 | if (!$::mwerks) | ||
| 18 | { if ($opcode =~ m/^j/o && $#_==0) # optimize jumps | ||
| 19 | { $_[0] = "NEAR $_[0]"; } | ||
| 20 | elsif ($opcode eq "lea" && $#_==1) # wipe storage qualifier from lea | ||
| 21 | { $_[1] =~ s/^[^\[]*\[/\[/o; } | ||
| 22 | } | ||
| 23 | &::emit($opcode,@_); | ||
| 24 | 1; | ||
| 25 | } | ||
| 26 | # | ||
| 27 | # opcodes not covered by ::generic above, mostly inconsistent namings... | ||
| 28 | # | ||
| 29 | sub ::call { &::emit("call",(&::islabel($_[0]) or "$nmdecor$_[0]")); } | ||
| 30 | sub ::call_ptr { &::emit("call",@_); } | ||
| 31 | sub ::jmp_ptr { &::emit("jmp",@_); } | ||
| 32 | |||
| 33 | sub get_mem | ||
| 34 | { my($size,$addr,$reg1,$reg2,$idx)=@_; | ||
| 35 | my($post,$ret); | ||
| 36 | |||
| 37 | if ($size ne "") | ||
| 38 | { $ret .= "$size"; | ||
| 39 | $ret .= " PTR" if ($::mwerks); | ||
| 40 | $ret .= " "; | ||
| 41 | } | ||
| 42 | $ret .= "["; | ||
| 43 | |||
| 44 | $addr =~ s/^\s+//; | ||
| 45 | # prepend global references with optional underscore | ||
| 46 | $addr =~ s/^([^\+\-0-9][^\+\-]*)/::islabel($1) or "$nmdecor$1"/ige; | ||
| 47 | # put address arithmetic expression in parenthesis | ||
| 48 | $addr="($addr)" if ($addr =~ /^.+[\-\+].+$/); | ||
| 49 | |||
| 50 | if (($addr ne "") && ($addr ne 0)) | ||
| 51 | { if ($addr !~ /^-/) { $ret .= "$addr+"; } | ||
| 52 | else { $post=$addr; } | ||
| 53 | } | ||
| 54 | |||
| 55 | if ($reg2 ne "") | ||
| 56 | { $idx!=0 or $idx=1; | ||
| 57 | $ret .= "$reg2*$idx"; | ||
| 58 | $ret .= "+$reg1" if ($reg1 ne ""); | ||
| 59 | } | ||
| 60 | else | ||
| 61 | { $ret .= "$reg1"; } | ||
| 62 | |||
| 63 | $ret .= "$post]"; | ||
| 64 | $ret =~ s/\+\]/]/; # in case $addr was the only argument | ||
| 65 | |||
| 66 | $ret; | ||
| 67 | } | ||
| 68 | sub ::BP { &get_mem("BYTE",@_); } | ||
| 69 | sub ::DWP { &get_mem("DWORD",@_); } | ||
| 70 | sub ::QWP { &get_mem("",@_); } | ||
| 71 | sub ::BC { (($::mwerks)?"":"BYTE ")."@_"; } | ||
| 72 | sub ::DWC { (($::mwerks)?"":"DWORD ")."@_"; } | ||
| 73 | |||
| 74 | sub ::file | ||
| 75 | { if ($::mwerks) { push(@out,".section\t.text,64\n"); } | ||
| 76 | else | ||
| 77 | { my $tmp=<<___; | ||
| 78 | %ifidn __OUTPUT_FORMAT__,obj | ||
| 79 | section code use32 class=code align=64 | ||
| 80 | %elifidn __OUTPUT_FORMAT__,win32 | ||
| 81 | \$\@feat.00 equ 1 | ||
| 82 | section .text code align=64 | ||
| 83 | %else | ||
| 84 | section .text code | ||
| 85 | %endif | ||
| 86 | ___ | ||
| 87 | push(@out,$tmp); | ||
| 88 | } | ||
| 89 | } | ||
| 90 | |||
| 91 | sub ::function_begin_B | ||
| 92 | { my $func=shift; | ||
| 93 | my $global=($func !~ /^_/); | ||
| 94 | my $begin="${::lbdecor}_${func}_begin"; | ||
| 95 | |||
| 96 | $begin =~ s/^\@/./ if ($::mwerks); # the torture never stops | ||
| 97 | |||
| 98 | &::LABEL($func,$global?"$begin":"$nmdecor$func"); | ||
| 99 | $func=$nmdecor.$func; | ||
| 100 | |||
| 101 | push(@out,"${drdecor}global $func\n") if ($global); | ||
| 102 | push(@out,"${drdecor}align 16\n"); | ||
| 103 | push(@out,"$func:\n"); | ||
| 104 | push(@out,"$begin:\n") if ($global); | ||
| 105 | $::stack=4; | ||
| 106 | } | ||
| 107 | |||
| 108 | sub ::function_end_B | ||
| 109 | { $::stack=0; | ||
| 110 | &::wipe_labels(); | ||
| 111 | } | ||
| 112 | |||
| 113 | sub ::file_end | ||
| 114 | { if (grep {/\b${nmdecor}OPENSSL_ia32cap_P\b/i} @out) | ||
| 115 | { my $comm=<<___; | ||
| 116 | ${drdecor}segment .bss | ||
| 117 | ${drdecor}common ${nmdecor}OPENSSL_ia32cap_P 4 | ||
| 118 | ___ | ||
| 119 | # comment out OPENSSL_ia32cap_P declarations | ||
| 120 | grep {s/(^extern\s+${nmdecor}OPENSSL_ia32cap_P)/\;$1/} @out; | ||
| 121 | push (@out,$comm) | ||
| 122 | } | ||
| 123 | push (@out,$initseg) if ($initseg); | ||
| 124 | } | ||
| 125 | |||
| 126 | sub ::comment { foreach (@_) { push(@out,"\t; $_\n"); } } | ||
| 127 | |||
| 128 | sub ::external_label | ||
| 129 | { foreach(@_) | ||
| 130 | { push(@out,"${drdecor}extern\t".&::LABEL($_,$nmdecor.$_)."\n"); } | ||
| 131 | } | ||
| 132 | |||
| 133 | sub ::public_label | ||
| 134 | { push(@out,"${drdecor}global\t".&::LABEL($_[0],$nmdecor.$_[0])."\n"); } | ||
| 135 | |||
| 136 | sub ::data_byte | ||
| 137 | { push(@out,(($::mwerks)?".byte\t":"db\t").join(',',@_)."\n"); } | ||
| 138 | |||
| 139 | sub ::data_word | ||
| 140 | { push(@out,(($::mwerks)?".long\t":"dd\t").join(',',@_)."\n"); } | ||
| 141 | |||
| 142 | sub ::align | ||
| 143 | { push(@out,"${drdecor}align\t$_[0]\n"); } | ||
| 144 | |||
| 145 | sub ::picmeup | ||
| 146 | { my($dst,$sym)=@_; | ||
| 147 | &::lea($dst,&::DWP($sym)); | ||
| 148 | } | ||
| 149 | |||
| 150 | sub ::initseg | ||
| 151 | { my $f=$nmdecor.shift; | ||
| 152 | if ($::win32) | ||
| 153 | { $initseg=<<___; | ||
| 154 | segment .CRT\$XCU data align=4 | ||
| 155 | extern $f | ||
| 156 | dd $f | ||
| 157 | ___ | ||
| 158 | } | ||
| 159 | } | ||
| 160 | |||
| 161 | sub ::dataseg | ||
| 162 | { if ($mwerks) { push(@out,".section\t.data,4\n"); } | ||
| 163 | else { push(@out,"section\t.data align=4\n"); } | ||
| 164 | } | ||
| 165 | |||
| 166 | 1; | ||
