]>
git.ipfire.org Git - thirdparty/openssl.git/blob - crypto/perlasm/x86gas.pl
2 # Copyright 2007-2020 The OpenSSL Project Authors. All Rights Reserved.
4 # Licensed under the Apache License 2.0 (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
=$::aout?
"L":".L"; # local label decoration
15 $nmdecor=($::aout
or $::coff
)?
"_":""; # external name decoration
20 $align=log($align)/log(2) if ($::aout
);
21 $com_start="#" if ($::aout
or $::coff
);
25 if ($reg =~ m/^%e/o) { "l"; }
26 elsif ($reg =~ m/^%[a-d][hl]$/o) { "b"; }
27 elsif ($reg =~ m/^%[yxm]/o) { undef; }
32 # expand opcode with size suffix;
33 # prefix numeric constants with $;
35 { my($opcode,@arg)=@_;
36 my($suffix,$dst,$src);
41 { s/^(\*?)(e?[a-dsixphl]{2})$/$1%$2/o; # gp registers
42 s/^([xy]?mm[0-7])$/%$1/o; # xmm/mmx registers
43 s/^(\-?[0-9]+)$/\$$1/o; # constants
44 s/^(\-?0x[0-9a-f]+)$/\$$1/o; # constants
47 $dst = $arg[$#arg] if ($#arg>=0);
48 $src = $arg[$#arg-1] if ($#arg>=1);
49 if ($dst =~ m/^%/o) { $suffix=&opsize
($dst); }
50 elsif ($src =~ m/^%/o) { $suffix=&opsize
($src); }
52 undef $suffix if ($dst =~ m/^%[xm]/o || $src =~ m/^%[xm]/o);
54 if ($#_==0) { &::emit
($opcode); }
55 elsif ($#_==1 && $opcode =~ m/^(call|clflush|j|loop|set)/o)
56 { &::emit
($opcode,@arg); }
57 else { &::emit
($opcode.$suffix,@arg);}
62 # opcodes not covered by ::generic above, mostly inconsistent namings...
64 sub ::movzx
{ &::movzb
(@_); }
65 sub ::pushfd
{ &::pushfl
; }
66 sub ::popfd
{ &::popfl
; }
67 sub ::cpuid
{ &::emit
(".byte\t0x0f,0xa2"); }
68 sub ::rdtsc
{ &::emit
(".byte\t0x0f,0x31"); }
70 sub ::call
{ &::emit
("call",(&::islabel
($_[0]) or "$nmdecor$_[0]")); }
71 sub ::call_ptr
{ &::generic
("call","*$_[0]"); }
72 sub ::jmp_ptr
{ &::generic
("jmp","*$_[0]"); }
74 *::bswap
= sub { &::emit
("bswap","%$_[0]"); } if (!$::i386
);
77 { my($addr,$reg1,$reg2,$idx)=@_;
80 if (!defined($idx) && 1*$reg2) { $idx=$reg2; $reg2=$reg1; undef $reg1; }
83 # prepend global references with optional underscore
84 $addr =~ s/^([^\+\-0-9][^\+\-]*)/&::islabel($1) or "$nmdecor$1"/ige;
86 $reg1 = "%$reg1" if ($reg1);
87 $reg2 = "%$reg2" if ($reg2);
89 $ret .= $addr if (($addr ne "") && ($addr ne 0));
93 $ret .= "($reg1,$reg2,$idx)";
96 { $ret .= "($reg1)"; }
100 sub ::QWP
{ &::DWP
(@_); }
101 sub ::BP
{ &::DWP
(@_); }
102 sub ::WP
{ &::DWP
(@_); }
107 { push(@out,".text\n"); }
109 sub ::function_begin_B
111 my $global=($func !~ /^_/);
112 my $begin="${::lbdecor}_${func}_begin";
114 &::LABEL
($func,$global?
"$begin":"$nmdecor$func");
115 $func=$nmdecor.$func;
117 push(@out,".globl\t$func\n") if ($global);
119 { push(@out,".def\t$func;\t.scl\t".(3-$global).";\t.type\t32;\t.endef\n"); }
120 elsif (($::aout
and !$::pic
) or $::macosx
)
123 { push(@out,".type $func,\@function\n"); }
124 push(@out,".align\t$align\n");
125 push(@out,"$func:\n");
126 push(@out,"$begin:\n") if ($global);
133 push(@out,".size\t$nmdecor$func,.-".&::LABEL
($func)."\n") if ($::elf
);
140 if (!defined($com_start) or $::elf
)
141 { # Regarding $::elf above...
142 # GNU and SVR4 as'es use different comment delimiters,
143 push(@out,"\n"); # so we just skip ELF comments...
151 { push(@out,"\t$com_start $_ $com_end\n"); }
156 { foreach(@_) { &::LABEL
($_,$nmdecor.$_); } }
159 { push(@out,".globl\t".&::LABEL
($_[0],$nmdecor.$_[0])."\n"); }
164 { push(@out,".section __IMPORT,__pointers,non_lazy_symbol_pointers\n");
165 foreach $i (keys %non_lazy_ptr)
166 { push(@out,"$non_lazy_ptr{$i}:\n.indirect_symbol\t$i\n.long\t0\n"); }
169 if (grep {/\b${nmdecor}OPENSSL_ia32cap_P\b/i} @out) {
170 my $tmp=".comm\t${nmdecor}OPENSSL_ia32cap_P,16";
171 if ($::macosx
) { push (@out,"$tmp,2\n"); }
172 elsif ($::elf
) { push (@out,"$tmp,4\n"); }
173 else { push (@out,"$tmp\n"); }
175 push(@out,$initseg) if ($initseg);
178 .section \".note.gnu.property\", \"a\"
198 sub ::data_byte
{ push(@out,".byte\t".join(',',@_)."\n"); }
199 sub ::data_short
{ push(@out,".value\t".join(',',@_)."\n"); }
200 sub ::data_word
{ push(@out,".long\t".join(',',@_)."\n"); }
205 { $val=int(log($val)/log(2));
208 push(@out,".align\t$val\n");
212 { my($dst,$sym,$base,$reflabel)=@_;
214 if (($::pic
&& ($::elf
|| $::aout
)) || $::macosx
)
215 { if (!defined($base))
216 { &::call
(&::label
("PIC_me_up"));
217 &::set_label
("PIC_me_up");
220 $reflabel=&::label
("PIC_me_up");
223 { my $indirect=&::static_label
("$nmdecor$sym\$non_lazy_ptr");
224 &::mov
($dst,&::DWP
("$indirect-$reflabel",$base));
225 $non_lazy_ptr{"$nmdecor$sym"}=$indirect;
227 elsif ($sym eq "OPENSSL_ia32cap_P" && $::elf
>0)
228 { &::lea
($dst,&::DWP
("$sym-$reflabel",$base)); }
230 { &::lea
($dst,&::DWP
("_GLOBAL_OFFSET_TABLE_+[.-$reflabel]",
232 &::mov
($dst,&::DWP
("$sym\@GOT",$dst));
236 { &::lea
($dst,&::DWP
($sym)); }
240 { my $f=$nmdecor.shift;
256 { $initseg.=<<___
; # applies to both Cygwin and Mingw
269 { my $ctor="${nmdecor}_GLOBAL_\$I\$$f";
271 $initseg.=".type $ctor,\@function\n" if ($::pic
);
272 $initseg.=<<___
; # OpenBSD way...
282 { push(@out,".data\n"); }
284 *::hidden
= sub { push(@out,".hidden\t$nmdecor$_[0]\n"); } if ($::elf
);