2 # Copyright 2006-2016 The OpenSSL Project Authors. All Rights Reserved.
4 # Licensed under the OpenSSL license (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
11 open STDOUT,">$output" || die "can't open $output: $!";
15 my $dotinlocallabels=($flavour=~/linux/)?1:0;
17 ################################################################
18 # directives which need special treatment on different platforms
19 ################################################################
21 my ($dir,$name,$type) = @_;
23 $TYPES{$name} = $type;
24 if ($flavour =~ /linux/) {
34 my $global = \$GLOBALS{$name};
35 my $type = \$TYPES{$name};
40 SWITCH: for ($flavour) {
41 /aix/ && do { if (!$$type) {
42 $$type = "\@function";
44 if ($$type =~ /function/) {
49 /osx/ && do { $name = "_$name";
53 && do { $ret .= ".globl $name";
55 $ret .= "\n.type $name,\@function";
56 $$type = "\@function";
60 /linux.*64/ && do { $ret .= ".globl $name";
62 $ret .= "\n.type $name,\@function";
63 $$type = "\@function";
65 if ($$type =~ /function/) {
66 $ret .= "\n.section \".opd\",\"aw\"";
69 $ret .= "\n.quad .$name,.TOC.\@tocbase,0";
70 $ret .= "\n.previous";
77 $ret = ".globl $name" if (!$ret);
82 my $ret = ($flavour =~ /aix/) ? ".csect\t.text[PR],7" : ".text";
83 $ret = ".abiversion 2\n".$ret if ($flavour =~ /linux.*64le/);
89 if ($flavour =~ /osx/)
91 $arch = ($flavour=~/64/) ? "ppc970-64" : "ppc970" if ($arch eq "any");
96 if ($flavour =~ /linux/)
99 my $real = $GLOBALS{$name} ? \$GLOBALS{$name} : \$name;
100 my $ret = ".size $$real,.-$$real";
102 if ($$real ne $name) {
103 $ret .= "\n.size $name,.-$$real";
112 my $line = join(",",@_);
113 if ($line =~ /^"(.*)"$/)
114 { ".byte " . join(",",unpack("C*",$1),0) . "\n.align 2"; }
123 if (/^0x([0-9a-f]*?)([0-9a-f]{1,8})$/io)
124 { $hi=$1?"0x$1":"0"; $lo="0x$2"; }
125 elsif (/^([0-9]+)$/o)
126 { $hi=$1>>32; $lo=$1&0xffffffff; } # error-prone with 32-bit perl
128 { $hi=undef; $lo=$_; }
131 { push(@ret,$flavour=~/le$/o?".long\t$lo,$hi":".long\t$hi,$lo"); }
133 { push(@ret,".quad $lo"); }
138 ################################################################
139 # simplified mnemonics not handled by at least one assembler
140 ################################################################
143 my $cr = 0; $cr = shift if ($#_>1);
144 # Some out-of-date 32-bit GNU assembler just can't handle cmplw...
145 ($flavour =~ /linux.*32/) ?
146 " .long ".sprintf "0x%x",31<<26|$cr<<23|$_[0]<<16|$_[1]<<11|64 :
147 " cmplw ".join(',',$cr,@_);
151 my $bo = $f=~/[\+\-]/ ? 16+9 : 16; # optional "to be taken" hint
153 } if ($flavour!~/linux/);
156 my $bo = $f=~/\-/ ? 12+2 : 12; # optional "not to be taken" hint
157 ($flavour =~ /linux/) ? # GNU as doesn't allow most recent hints
158 " .long ".sprintf "0x%x",19<<26|$bo<<21|16<<1 :
163 my $bo = $f=~/\-/ ? 4+2 : 4; # optional "not to be taken" hint
164 ($flavour =~ /linux/) ? # GNU as doesn't allow most recent hints
165 " .long ".sprintf "0x%x",19<<26|$bo<<21|2<<16|16<<1 :
170 my $bo = $f=~/-/ ? 12+2 : 12; # optional "not to be taken" hint
171 ($flavour =~ /linux/) ? # GNU as doesn't allow most recent hints
172 " .long ".sprintf "0x%X",19<<26|$bo<<21|2<<16|16<<1 :
175 # GNU assembler can't handle extrdi rA,rS,16,48, or when sum of last two
176 # arguments is 64, with "operand out of range" error.
178 my ($f,$ra,$rs,$n,$b) = @_;
179 $b = ($b+$n)&63; $n = 64-$n;
180 " rldicl $ra,$rs,$b,$n";
183 my ($f,$vx,$vy) = @_;
187 # Some ABIs specify vrsave, special-purpose register #256, as reserved
189 my $no_vrsave = ($flavour =~ /aix|linux64le/);
191 my ($f,$idx,$ra) = @_;
192 if ($idx == 256 && $no_vrsave) {
199 my ($f,$rd,$idx) = @_;
200 if ($idx == 256 && $no_vrsave) {
207 # PowerISA 2.06 stuff
209 my ($f, $vrt, $ra, $rb, $op) = @_;
210 " .long ".sprintf "0x%X",(31<<26)|($vrt<<21)|($ra<<16)|($rb<<11)|($op*2+1);
212 # made-up unaligned memory reference AltiVec/VMX instructions
213 my $lvx_u = sub { vsxmem_op(@_, 844); }; # lxvd2x
214 my $stvx_u = sub { vsxmem_op(@_, 972); }; # stxvd2x
215 my $lvdx_u = sub { vsxmem_op(@_, 588); }; # lxsdx
216 my $stvdx_u = sub { vsxmem_op(@_, 716); }; # stxsdx
217 my $lvx_4w = sub { vsxmem_op(@_, 780); }; # lxvw4x
218 my $stvx_4w = sub { vsxmem_op(@_, 908); }; # stxvw4x
220 # PowerISA 2.07 stuff
222 my ($f, $vrt, $vra, $vrb, $op) = @_;
223 " .long ".sprintf "0x%X",(4<<26)|($vrt<<21)|($vra<<16)|($vrb<<11)|$op;
225 my $vcipher = sub { vcrypto_op(@_, 1288); };
226 my $vcipherlast = sub { vcrypto_op(@_, 1289); };
227 my $vncipher = sub { vcrypto_op(@_, 1352); };
228 my $vncipherlast= sub { vcrypto_op(@_, 1353); };
229 my $vsbox = sub { vcrypto_op(@_, 0, 1480); };
230 my $vshasigmad = sub { my ($st,$six)=splice(@_,-2); vcrypto_op(@_, $st<<4|$six, 1730); };
231 my $vshasigmaw = sub { my ($st,$six)=splice(@_,-2); vcrypto_op(@_, $st<<4|$six, 1666); };
232 my $vpmsumb = sub { vcrypto_op(@_, 1032); };
233 my $vpmsumd = sub { vcrypto_op(@_, 1224); };
234 my $vpmsubh = sub { vcrypto_op(@_, 1096); };
235 my $vpmsumw = sub { vcrypto_op(@_, 1160); };
236 my $vaddudm = sub { vcrypto_op(@_, 192); };
240 " .long ".sprintf "0x%X",(31<<26)|($arg<<21)|(147*2);
245 my ($f, $rt, $ra, $rb, $rc) = @_;
246 " .long ".sprintf "0x%X",(4<<26)|($rt<<21)|($ra<<16)|($rb<<11)|($rc<<6)|49;
249 my ($f, $rt, $ra, $rb, $rc) = @_;
250 " .long ".sprintf "0x%X",(4<<26)|($rt<<21)|($ra<<16)|($rb<<11)|($rc<<6)|51;
254 my ($f, $rt, $l) = @_;
255 " .long ".sprintf "0x%X",(31<<26)|($rt<<21)|($l<<16)|(755<<1);
260 $line =~ s|[#!;].*$||; # get rid of asm-style comments...
261 $line =~ s|/\*.*\*/||; # ... and C-style comments...
262 $line =~ s|^\s+||; # ... and skip white spaces in beginning...
263 $line =~ s|\s+$||; # ... and at the end
266 $line =~ s|\.L(\w+)|L$1|g; # common denominator for Locallabel
267 $line =~ s|\bL(\w+)|\.L$1|g if ($dotinlocallabels);
271 $line =~ s|(^[\.\w]+)\:\s*||;
274 my $xlated = ($GLOBALS{$label} or $label);
276 if ($flavour =~ /linux.*64le/) {
277 if ($TYPES{$label} =~ /function/) {
278 printf "\n.localentry %s,0\n",$xlated;
285 $line =~ s|^\s*(\.?)(\w+)([\.\+\-]?)\s*||;
286 my $c = $1; $c = "\t" if ($c eq "");
289 my $opcode = eval("\$$mnemonic");
290 $line =~ s/\b(c?[rf]|v|vs)([0-9]+)\b/$2/g if ($c ne "." and $flavour !~ /osx/);
291 if (ref($opcode) eq 'CODE') { $line = &$opcode($f,split(',',$line)); }
292 elsif ($mnemonic) { $line = $c.$mnemonic.$f."\t".$line; }
295 print $line if ($line);