2 # Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved.
4 # Licensed under the OpenSSL license (the "License"). You may not use
5 # this file except in compliance with the License. You can obtain a copy
6 # in the file LICENSE in the source distribution or at
7 # https://www.openssl.org/source/license.html
14 $::lbdecor="L\$"; # local label decoration
15 $nmdecor=$::netware?"":"_"; # external name decoration
16 $drdecor=$::mwerks?".":""; # directive decoration
25 { if ($opcode =~ m/^j/o && $#_==0) # optimize jumps
26 { $_[0] = "NEAR $_[0]"; }
27 elsif ($opcode eq "lea" && $#_==1) # wipe storage qualifier from lea
28 { $_[1] =~ s/^[^\[]*\[/\[/o; }
29 elsif ($opcode eq "clflush" && $#_==0)
30 { $_[0] =~ s/^[^\[]*\[/\[/o; }
36 # opcodes not covered by ::generic above, mostly inconsistent namings...
38 sub ::call { &::emit("call",(&::islabel($_[0]) or "$nmdecor$_[0]")); }
39 sub ::call_ptr { &::emit("call",@_); }
40 sub ::jmp_ptr { &::emit("jmp",@_); }
43 { my($size,$addr,$reg1,$reg2,$idx)=@_;
46 if (!defined($idx) && 1*$reg2) { $idx=$reg2; $reg2=$reg1; undef $reg1; }
50 $ret .= " PTR" if ($::mwerks);
56 # prepend global references with optional underscore
57 $addr =~ s/^([^\+\-0-9][^\+\-]*)/::islabel($1) or "$nmdecor$1"/ige;
58 # put address arithmetic expression in parenthesis
59 $addr="($addr)" if ($addr =~ /^.+[\-\+].+$/);
61 if (($addr ne "") && ($addr ne 0))
62 { if ($addr !~ /^-/) { $ret .= "$addr+"; }
69 $ret .= "+$reg1" if ($reg1 ne "");
75 $ret =~ s/\+\]/]/; # in case $addr was the only argument
79 sub ::BP { &get_mem("BYTE",@_); }
80 sub ::DWP { &get_mem("DWORD",@_); }
81 sub ::WP { &get_mem("WORD",@_); }
82 sub ::QWP { &get_mem("",@_); }
83 sub ::BC { (($::mwerks)?"":"BYTE ")."@_"; }
84 sub ::DWC { (($::mwerks)?"":"DWORD ")."@_"; }
87 { if ($::mwerks) { push(@out,".section\t.text,64\n"); }
90 %ifidn __OUTPUT_FORMAT__,obj
91 section code use32 class=code align=64
92 %elifidn __OUTPUT_FORMAT__,win32
94 section .text code align=64
103 sub ::function_begin_B
105 my $global=($func !~ /^_/);
106 my $begin="${::lbdecor}_${func}_begin";
108 $begin =~ s/^\@/./ if ($::mwerks); # the torture never stops
110 &::LABEL($func,$global?"$begin":"$nmdecor$func");
111 $func=$nmdecor.$func;
113 push(@out,"${drdecor}global $func\n") if ($global);
114 push(@out,"${drdecor}align 16\n");
115 push(@out,"$func:\n");
116 push(@out,"$begin:\n") if ($global);
126 { if (grep {/\b${nmdecor}OPENSSL_ia32cap_P\b/i} @out)
128 ${drdecor}segment .bss
129 ${drdecor}common ${nmdecor}OPENSSL_ia32cap_P 16
131 # comment out OPENSSL_ia32cap_P declarations
132 grep {s/(^extern\s+${nmdecor}OPENSSL_ia32cap_P)/\;$1/} @out;
135 push (@out,$initseg) if ($initseg);
138 sub ::comment { foreach (@_) { push(@out,"\t; $_\n"); } }
142 { push(@out,"${drdecor}extern\t".&::LABEL($_,$nmdecor.$_)."\n"); }
146 { push(@out,"${drdecor}global\t".&::LABEL($_[0],$nmdecor.$_[0])."\n"); }
149 { push(@out,(($::mwerks)?".byte\t":"db\t").join(',',@_)."\n"); }
151 { push(@out,(($::mwerks)?".word\t":"dw\t").join(',',@_)."\n"); }
153 { push(@out,(($::mwerks)?".long\t":"dd\t").join(',',@_)."\n"); }
156 { push(@out,"${drdecor}align\t$_[0]\n"); }
160 &::lea($dst,&::DWP($sym));
164 { my $f=$nmdecor.shift;
167 segment .CRT\$XCU data align=4
175 { if ($mwerks) { push(@out,".section\t.data,4\n"); }
176 else { push(@out,"section\t.data align=4\n"); }
181 push(@out,"%if __NASM_VERSION_ID__ >= 0x02030000\n");
182 push(@out,"safeseh ".&::LABEL($nm,$nmdecor.$nm)."\n");
183 push(@out,"%endif\n");