7 $::lbdecor="\$L"; # local label decoration
8 $nmdecor="_"; # external name decoration
14 { my ($opcode,@arg)=@_;
16 # fix hexadecimal constants
17 for (@arg) { s/(?<![\w\$\.])0x([0-9a-f]+)/0$1h/oi; }
19 if ($opcode =~ /lea/ && @arg[1] =~ s/.*PTR\s+(\(.*\))$/OFFSET $1/) # no []
21 elsif ($opcode !~ /movq/)
22 { # fix xmm references
23 $arg[0] =~ s/\b[A-Z]+WORD\s+PTR/XMMWORD PTR/i if ($arg[1]=~/\bxmm[0-7]\b/i);
24 $arg[1] =~ s/\b[A-Z]+WORD\s+PTR/XMMWORD PTR/i if ($arg[0]=~/\bxmm[0-7]\b/i);
27 &::emit($opcode,@arg);
31 # opcodes not covered by ::generic above, mostly inconsistent namings...
33 sub ::call { &::emit("call",(&::islabel($_[0]) or "$nmdecor$_[0]")); }
34 sub ::call_ptr { &::emit("call",@_); }
35 sub ::jmp_ptr { &::emit("jmp",@_); }
36 sub ::lock { &::data_byte(0xf0); }
39 { my($size,$addr,$reg1,$reg2,$idx)=@_;
42 if (!defined($idx) && 1*$reg2) { $idx=$reg2; $reg2=$reg1; undef $reg1; }
44 $ret .= "$size PTR " if ($size ne "");
47 # prepend global references with optional underscore
48 $addr =~ s/^([^\+\-0-9][^\+\-]*)/&::islabel($1) or "$nmdecor$1"/ige;
49 # put address arithmetic expression in parenthesis
50 $addr="($addr)" if ($addr =~ /^.+[\-\+].+$/);
52 if (($addr ne "") && ($addr ne 0))
53 { if ($addr !~ /^-/) { $ret .= "$addr"; }
61 $ret .= "+$reg1" if ($reg1 ne "");
67 $ret =~ s/\+\]/]/; # in case $addr was the only argument
72 sub ::BP { &get_mem("BYTE",@_); }
73 sub ::WP { &get_mem("WORD",@_); }
74 sub ::DWP { &get_mem("DWORD",@_); }
75 sub ::QWP { &get_mem("QWORD",@_); }
83 ECHO MASM version 8.00 or later is strongly recommended.
89 .text\$ SEGMENT PAGE 'CODE'
91 .text\$ SEGMENT ALIGN(64) 'CODE'
98 sub ::function_begin_B
100 my $global=($func !~ /^_/);
101 my $begin="${::lbdecor}_${func}_begin";
103 &::LABEL($func,$global?"$begin":"$nmdecor$func");
104 $func="ALIGN\t16\n".$nmdecor.$func."\tPROC";
106 if ($global) { $func.=" PUBLIC\n${begin}::\n"; }
107 else { $func.=" PRIVATE\n"; }
114 push(@out,"$nmdecor$func ENDP\n");
120 { my $xmmheader=<<___;
129 if (grep {/\b[x]?mm[0-7]\b/i} @out) {
130 grep {s/\.[3-7]86/$xmmheader/} @out;
133 push(@out,"$segment ENDS\n");
135 if (grep {/\b${nmdecor}OPENSSL_ia32cap_P\b/i} @out)
138 COMM ${nmdecor}OPENSSL_ia32cap_P:DWORD:4
141 # comment out OPENSSL_ia32cap_P declarations
142 grep {s/(^EXTERN\s+${nmdecor}OPENSSL_ia32cap_P)/\;$1/} @out;
145 push (@out,$initseg) if ($initseg);
149 sub ::comment { foreach (@_) { push(@out,"\t; $_\n"); } }
152 { my $l=shift; push(@out,$l.($l=~/^\Q${::lbdecor}\E[0-9]{3}/?":\n":"::\n")); };
156 { push(@out, "EXTERN\t".&::LABEL($_,$nmdecor.$_).":NEAR\n"); }
160 { push(@out,"PUBLIC\t".&::LABEL($_[0],$nmdecor.$_[0])."\n"); }
163 { push(@out,("DB\t").join(',',@_)."\n"); }
166 { push(@out,("DW\t").join(',',@_)."\n"); }
169 { push(@out,("DD\t").join(',',@_)."\n"); }
172 { push(@out,"ALIGN\t$_[0]\n"); }
176 &::lea($dst,&::DWP($sym));
180 { my $f=$nmdecor.shift;
183 .CRT\$XCU SEGMENT DWORD PUBLIC 'DATA'
191 { push(@out,"$segment\tENDS\n_DATA\tSEGMENT\n"); $segment="_DATA"; }
195 push(@out,"IF \@Version GE 710\n");
196 push(@out,".SAFESEH ".&::LABEL($nm,$nmdecor.$nm)."\n");
197 push(@out,"ENDIF\n");