]>
git.ipfire.org Git - thirdparty/openssl.git/blob - crypto/perlasm/x86gas.pl
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 ($#_==1 && $opcode =~ m/^(call|clflush|j|loop|set)/o)
49 { &::emit
($opcode,@arg); }
50 else { &::emit
($opcode.$suffix,@arg);}
55 # opcodes not covered by ::generic above, mostly inconsistent namings...
57 sub ::movzx
{ &::movzb
(@_); }
58 sub ::pushfd
{ &::pushfl
; }
59 sub ::popfd
{ &::popfl
; }
60 sub ::cpuid
{ &::emit
(".byte\t0x0f,0xa2"); }
61 sub ::rdtsc
{ &::emit
(".byte\t0x0f,0x31"); }
63 sub ::call
{ &::emit
("call",(&::islabel
($_[0]) or "$nmdecor$_[0]")); }
64 sub ::call_ptr
{ &::generic
("call","*$_[0]"); }
65 sub ::jmp_ptr
{ &::generic
("jmp","*$_[0]"); }
67 *::bswap
= sub { &::emit
("bswap","%$_[0]"); } if (!$::i386
);
70 { my($addr,$reg1,$reg2,$idx)=@_;
74 # prepend global references with optional underscore
75 $addr =~ s/^([^\+\-0-9][^\+\-]*)/&::islabel($1) or "$nmdecor$1"/ige;
77 $reg1 = "%$reg1" if ($reg1);
78 $reg2 = "%$reg2" if ($reg2);
80 $ret .= $addr if (($addr ne "") && ($addr ne 0));
84 $ret .= "($reg1,$reg2,$idx)";
87 { $ret .= "($reg1)"; }
91 sub ::QWP
{ &::DWP
(@_); }
92 sub ::BP
{ &::DWP
(@_); }
93 sub ::WP
{ &::DWP
(@_); }
98 { push(@out,".file\t\"$_[0].s\"\n.text\n"); }
100 sub ::function_begin_B
102 my $global=($func !~ /^_/);
103 my $begin="${::lbdecor}_${func}_begin";
105 &::LABEL
($func,$global?
"$begin":"$nmdecor$func");
106 $func=$nmdecor.$func;
108 push(@out,".globl\t$func\n") if ($global);
110 { push(@out,".def\t$func;\t.scl\t".(3-$global).";\t.type\t32;\t.endef\n"); }
111 elsif (($::aout
and !$::pic
) or $::macosx
)
114 { push(@out,".type $func,\@function\n"); }
115 push(@out,".align\t$align\n");
116 push(@out,"$func:\n");
117 push(@out,"$begin:\n") if ($global);
123 push(@out,".size\t$nmdecor$func,.-".&::LABEL
($func)."\n") if ($::elf
);
130 if (!defined($com_start) or $::elf
)
131 { # Regarding $::elf above...
132 # GNU and SVR4 as'es use different comment delimiters,
133 push(@out,"\n"); # so we just skip ELF comments...
141 { push(@out,"\t$com_start $_ $com_end\n"); }
146 { foreach(@_) { &::LABEL
($_,$nmdecor.$_); } }
149 { push(@out,".globl\t".&::LABEL
($_[0],$nmdecor.$_[0])."\n"); }
154 { push(@out,".section __IMPORT,__pointers,non_lazy_symbol_pointers\n");
155 foreach $i (keys %non_lazy_ptr)
156 { push(@out,"$non_lazy_ptr{$i}:\n.indirect_symbol\t$i\n.long\t0\n"); }
159 if (grep {/\b${nmdecor}OPENSSL_ia32cap_P\b/i} @out) {
160 my $tmp=".comm\t${nmdecor}OPENSSL_ia32cap_P,8";
161 if ($::macosx
) { push (@out,"$tmp,2\n"); }
162 elsif ($::elf
) { push (@out,"$tmp,4\n"); }
163 else { push (@out,"$tmp\n"); }
165 push(@out,$initseg) if ($initseg);
168 sub ::data_byte
{ push(@out,".byte\t".join(',',@_)."\n"); }
169 sub ::data_short
{ push(@out,".value\t".join(',',@_)."\n"); }
170 sub ::data_word
{ push(@out,".long\t".join(',',@_)."\n"); }
175 { $val=int(log($val)/log(2));
178 push(@out,".align\t$val\n");
182 { my($dst,$sym,$base,$reflabel)=@_;
184 if (defined($base) && $sym eq "OPENSSL_ia32cap_P" && !$::macosx
)
185 { &::lea
($dst,&::DWP
("$sym-$reflabel",$base)); }
186 elsif (($::pic
&& ($::elf
|| $::aout
)) || $::macosx
)
187 { if (!defined($base))
188 { &::call
(&::label
("PIC_me_up"));
189 &::set_label
("PIC_me_up");
192 $reflabel=&::label
("PIC_me_up");
195 { my $indirect=&::static_label
("$nmdecor$sym\$non_lazy_ptr");
196 &::mov
($dst,&::DWP
("$indirect-$reflabel",$base));
197 $non_lazy_ptr{"$nmdecor$sym"}=$indirect;
200 { &::lea
($dst,&::DWP
("_GLOBAL_OFFSET_TABLE_+[.-$reflabel]",
202 &::mov
($dst,&::DWP
("$sym\@GOT",$dst));
206 { &::lea
($dst,&::DWP
($sym)); }
210 { my $f=$nmdecor.shift;
226 { $initseg.=<<___
; # applies to both Cygwin and Mingw
239 { my $ctor="${nmdecor}_GLOBAL_\$I\$$f";
241 $initseg.=".type $ctor,\@function\n" if ($::pic
);
242 $initseg.=<<___
; # OpenBSD way...
252 { push(@out,".data\n"); }
254 *::hidden
= sub { push(@out,".hidden\t$nmdecor$_[0]\n"); } if ($::elf
);