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,@arg)=@_;
29 my($suffix,$dst,$src);
34 { s/^(\*?)(e?[a-dsixphl]{2})$/$1%$2/o; # gp registers
35 s/^([xy]?mm[0-7])$/%$1/o; # xmm/mmx registers
36 s/^(\-?[0-9]+)$/\$$1/o; # constants
37 s/^(\-?0x[0-9a-f]+)$/\$$1/o; # constants
40 $dst = $arg[$#arg] if ($#arg>=0);
41 $src = $arg[$#arg-1] if ($#arg>=1);
42 if ($dst =~ m/^%/o) { $suffix=&opsize
($dst); }
43 elsif ($src =~ m/^%/o) { $suffix=&opsize
($src); }
45 undef $suffix if ($dst =~ m/^%[xm]/o || $src =~ m/^%[xm]/o);
47 if ($#_==0) { &::emit
($opcode); }
48 elsif ($opcode =~ m/^j/o && $#_==1) { &::emit
($opcode,@arg); }
49 elsif ($opcode eq "call" && $#_==1) { &::emit
($opcode,@arg); }
50 elsif ($opcode eq "clflush" && $#_==1){ &::emit
($opcode,@arg); }
51 elsif ($opcode =~ m/^set/&& $#_==1) { &::emit
($opcode,@arg); }
52 else { &::emit
($opcode.$suffix,@arg);}
57 # opcodes not covered by ::generic above, mostly inconsistent namings...
59 sub ::movzx
{ &::movzb
(@_); }
60 sub ::pushfd
{ &::pushfl
; }
61 sub ::popfd
{ &::popfl
; }
62 sub ::cpuid
{ &::emit
(".byte\t0x0f,0xa2"); }
63 sub ::rdtsc
{ &::emit
(".byte\t0x0f,0x31"); }
65 sub ::call
{ &::emit
("call",(&::islabel
($_[0]) or "$nmdecor$_[0]")); }
66 sub ::call_ptr
{ &::generic
("call","*$_[0]"); }
67 sub ::jmp_ptr
{ &::generic
("jmp","*$_[0]"); }
69 *::bswap
= sub { &::emit
("bswap","%$_[0]"); } if (!$::i386
);
72 { my($addr,$reg1,$reg2,$idx)=@_;
76 # prepend global references with optional underscore
77 $addr =~ s/^([^\+\-0-9][^\+\-]*)/&::islabel($1) or "$nmdecor$1"/ige;
79 $reg1 = "%$reg1" if ($reg1);
80 $reg2 = "%$reg2" if ($reg2);
82 $ret .= $addr if (($addr ne "") && ($addr ne 0));
86 $ret .= "($reg1,$reg2,$idx)";
89 { $ret .= "($reg1)"; }
93 sub ::QWP
{ &::DWP
(@_); }
94 sub ::BP
{ &::DWP
(@_); }
95 sub ::WP
{ &::DWP
(@_); }
100 { push(@out,".file\t\"$_[0].s\"\n.text\n"); }
102 sub ::function_begin_B
104 my $global=($func !~ /^_/);
105 my $begin="${::lbdecor}_${func}_begin";
107 &::LABEL
($func,$global?
"$begin":"$nmdecor$func");
108 $func=$nmdecor.$func;
110 push(@out,".globl\t$func\n") if ($global);
112 { push(@out,".def\t$func;\t.scl\t".(3-$global).";\t.type\t32;\t.endef\n"); }
113 elsif (($::aout
and !$::pic
) or $::macosx
)
116 { push(@out,".type $func,\@function\n"); }
117 push(@out,".align\t$align\n");
118 push(@out,"$func:\n");
119 push(@out,"$begin:\n") if ($global);
125 push(@out,".size\t$nmdecor$func,.-".&::LABEL
($func)."\n") if ($::elf
);
132 if (!defined($com_start) or $::elf
)
133 { # Regarding $::elf above...
134 # GNU and SVR4 as'es use different comment delimiters,
135 push(@out,"\n"); # so we just skip ELF comments...
143 { push(@out,"\t$com_start $_ $com_end\n"); }
148 { foreach(@_) { &::LABEL
($_,$nmdecor.$_); } }
151 { push(@out,".globl\t".&::LABEL
($_[0],$nmdecor.$_[0])."\n"); }
156 { push(@out,".section __IMPORT,__pointers,non_lazy_symbol_pointers\n");
157 foreach $i (keys %non_lazy_ptr)
158 { push(@out,"$non_lazy_ptr{$i}:\n.indirect_symbol\t$i\n.long\t0\n"); }
161 if (grep {/\b${nmdecor}OPENSSL_ia32cap_P\b/i} @out) {
162 my $tmp=".comm\t${nmdecor}OPENSSL_ia32cap_P,8";
163 if ($::macosx
) { push (@out,"$tmp,2\n"); }
164 elsif ($::elf
) { push (@out,"$tmp,4\n"); }
165 else { push (@out,"$tmp\n"); }
167 push(@out,$initseg) if ($initseg);
170 sub ::data_byte
{ push(@out,".byte\t".join(',',@_)."\n"); }
171 sub ::data_short
{ push(@out,".value\t".join(',',@_)."\n"); }
172 sub ::data_word
{ push(@out,".long\t".join(',',@_)."\n"); }
175 { my $val=$_[0],$p2,$i;
177 { for ($p2=0;$val!=0;$val>>=1) { $p2++; }
181 push(@out,".align\t$val\n");
185 { my($dst,$sym,$base,$reflabel)=@_;
187 if (($::pic
&& ($::elf
|| $::aout
)) || $::macosx
)
188 { if (!defined($base))
189 { &::call
(&::label
("PIC_me_up"));
190 &::set_label
("PIC_me_up");
193 $reflabel=&::label
("PIC_me_up");
196 { my $indirect=&::static_label
("$nmdecor$sym\$non_lazy_ptr");
197 &::mov
($dst,&::DWP
("$indirect-$reflabel",$base));
198 $non_lazy_ptr{"$nmdecor$sym"}=$indirect;
201 { &::lea
($dst,&::DWP
("_GLOBAL_OFFSET_TABLE_+[.-$reflabel]",
203 &::mov
($dst,&::DWP
("$sym\@GOT",$dst));
207 { &::lea
($dst,&::DWP
($sym)); }
211 { my $f=$nmdecor.shift;
227 { $initseg.=<<___
; # applies to both Cygwin and Mingw
240 { my $ctor="${nmdecor}_GLOBAL_\$I\$$f";
242 $initseg.=".type $ctor,\@function\n" if ($::pic
);
243 $initseg.=<<___
; # OpenBSD way...
253 { push(@out,".data\n"); }