7 $::lbdecor=$::aout?"L":".L"; # local label decoration
8 $nmdecor=($::aout or $::coff)?"_":""; # external name decoration
13 $align=log($align)/log(2) if ($::aout);
14 $com_start="#" if ($::aout or $::coff);
18 if ($reg =~ m/^%e/o) { "l"; }
19 elsif ($reg =~ m/^%[a-d][hl]$/o) { "b"; }
20 elsif ($reg =~ m/^%[xm]/o) { undef; }
25 # expand opcode with size suffix;
26 # prefix numeric constants with $;
28 { my($opcode,$dst,$src)=@_;
29 my($tmp,$suffix,@arg);
32 { $src =~ s/^(e?[a-dsixphl]{2})$/%$1/o;
33 $src =~ s/^(x?mm[0-7])$/%$1/o;
34 $src =~ s/^(\-?[0-9]+)$/\$$1/o;
35 $src =~ s/^(\-?0x[0-9a-f]+)$/\$$1/o;
39 { $dst =~ s/^(\*?)(e?[a-dsixphl]{2})$/$1%$2/o;
40 $dst =~ s/^(x?mm[0-7])$/%$1/o;
41 $dst =~ s/^(\-?[0-9]+)$/\$$1/o if(!defined($src));
42 $dst =~ s/^(\-?0x[0-9a-f]+)$/\$$1/o if(!defined($src));
46 if ($dst =~ m/^%/o) { $suffix=&opsize($dst); }
47 elsif ($src =~ m/^%/o) { $suffix=&opsize($src); }
49 undef $suffix if ($dst =~ m/^%[xm]/o || $src =~ m/^%[xm]/o);
51 if ($#_==0) { &::emit($opcode); }
52 elsif ($opcode =~ m/^j/o && $#_==1) { &::emit($opcode,@arg); }
53 elsif ($opcode eq "call" && $#_==1) { &::emit($opcode,@arg); }
54 elsif ($opcode =~ m/^set/&& $#_==1) { &::emit($opcode,@arg); }
55 else { &::emit($opcode.$suffix,@arg);}
60 # opcodes not covered by ::generic above, mostly inconsistent namings...
62 sub ::movzx { &::movzb(@_); }
63 sub ::pushfd { &::pushfl; }
64 sub ::popfd { &::popfl; }
65 sub ::cpuid { &::emit(".byte\t0x0f,0xa2"); }
66 sub ::rdtsc { &::emit(".byte\t0x0f,0x31"); }
68 sub ::call { &::emit("call",(&::islabel($_[0]) or "$nmdecor$_[0]")); }
69 sub ::call_ptr { &::generic("call","*$_[0]"); }
70 sub ::jmp_ptr { &::generic("jmp","*$_[0]"); }
72 *::bswap = sub { &::emit("bswap","%$_[0]"); } if (!$::i386);
75 { my($dst,$src,$magic)=@_;
76 &::emit("pshufw","\$$magic","%$src","%$dst");
79 { my($dst,$src,$bits)=@_;
80 &::emit("shldl",$bit eq "cl"?"%cl":"\$$bits","%$src","%$dst");
83 { my($dst,$src,$bits)=@_;
84 &::emit("shrdl",$bit eq "cl"?"%cl":"\$$bits","%$src","%$dst");
88 { my($addr,$reg1,$reg2,$idx)=@_;
92 # prepend global references with optional underscore
93 $addr =~ s/^([^\+\-0-9][^\+\-]*)/&::islabel($1) or "$nmdecor$1"/ige;
95 $reg1 = "%$reg1" if ($reg1);
96 $reg2 = "%$reg2" if ($reg2);
98 $ret .= $addr if (($addr ne "") && ($addr ne 0));
101 { $idx!= 0 or $idx=1;
102 $ret .= "($reg1,$reg2,$idx)";
105 { $ret .= "($reg1)"; }
109 sub ::QWP { &::DWP(@_); }
110 sub ::BP { &::DWP(@_); }
115 { push(@out,".file\t\"$_[0].s\"\n.text\n"); }
117 sub ::function_begin_B
119 my $global=($func !~ /^_/);
120 my $begin="${::lbdecor}_${func}_begin";
122 &::LABEL($func,$global?"$begin":"$nmdecor$func");
123 $func=$nmdecor.$func;
125 push(@out,".globl\t$func\n") if ($global);
127 { push(@out,".def\t$func;\t.scl\t2;\t.type\t32;\t.endef\n"); }
128 elsif (($::aout and !$::pic) or $::macosx)
131 { push(@out,".type $func,\@function\n"); }
132 push(@out,".align\t$align\n");
133 push(@out,"$func:\n");
134 push(@out,"$begin:\n") if ($global);
140 push(@out,".size\t$nmdecor$func,.-".&::LABEL($func)."\n") if ($::elf);
147 if (!defined($com_start) or $::elf)
148 { # Regarding $::elf above...
149 # GNU and SVR4 as'es use different comment delimiters,
150 push(@out,"\n"); # so we just skip ELF comments...
158 { push(@out,"\t$com_start $_ $com_end\n"); }
163 { foreach(@_) { &::LABEL($_,$nmdecor.$_); } }
166 { push(@out,".globl\t".&::LABEL($_[0],$nmdecor.$_[0])."\n"); }
169 { if (grep {/\b${nmdecor}OPENSSL_ia32cap_P\b/i} @out) {
170 my $tmp=".comm\t${nmdecor}OPENSSL_ia32cap_P,4";
171 if ($::elf) { push (@out,"$tmp,4\n"); }
172 else { push (@out,"$tmp\n"); }
176 { push(@out,".section __IMPORT,__pointers,non_lazy_symbol_pointers\n");
177 foreach $i (keys %non_lazy_ptr)
178 { push(@out,"$non_lazy_ptr{$i}:\n.indirect_symbol\t$i\n.long\t0\n"); }
181 push(@out,$initseg) if ($initseg);
184 sub ::data_byte { push(@out,".byte\t".join(',',@_)."\n"); }
185 sub ::data_word { push(@out,".long\t".join(',',@_)."\n"); }
188 { my $val=$_[0],$p2,$i;
190 { for ($p2=0;$val!=0;$val>>=1) { $p2++; }
194 push(@out,".align\t$val\n");
198 { my($dst,$sym,$base,$reflabel)=@_;
200 if ($::pic && ($::elf || $::aout))
201 { if (!defined($base))
202 { &::call(&::label("PIC_me_up"));
203 &::set_label("PIC_me_up");
206 $reflabel=&::label("PIC_me_up");
209 { my $indirect=&::static_label("$nmdecor$sym\$non_lazy_ptr");
210 &::mov($dst,&::DWP("$indirect-$reflabel",$base));
211 $non_lazy_ptr{"$nmdecor$sym"}=$indirect;
214 { &::lea($dst,&::DWP("_GLOBAL_OFFSET_TABLE_+[.-$reflabel]",
216 &::mov($dst,&::DWP("$sym\@GOT",$dst));
220 { &::lea($dst,&::DWP($sym)); }
224 { my $f=$nmdecor.shift;
236 { $initseg.=<<___; # applies to both Cygwin and Mingw
249 { my $ctor="${nmdecor}_GLOBAL_\$I\$$f";
251 $initseg.=".type $ctor,\@function\n" if ($::pic);
252 $initseg.=<<___; # OpenBSD way...