2 # SPDX-License-Identifier: GPL-2.0
4 # PowerPC assembler distiller by <appro>.
8 open STDOUT
,">$output" || die "can't open $output: $!";
11 my $dotinlocallabels=($flavour=~/linux/)?
1:0;
13 ################################################################
14 # directives which need special treatment on different platforms
15 ################################################################
19 my $global = \
$GLOBALS{$name};
24 SWITCH
: for ($flavour) {
25 /aix/ && do { $name = ".$name";
28 /osx/ && do { $name = "_$name";
32 && do { $ret = "_GLOBAL($name)";
37 $ret = ".globl $name\nalign 5\n$name:" if (!$ret);
42 my $ret = ($flavour =~ /aix/) ?
".csect\t.text[PR],7" : ".text";
43 $ret = ".abiversion 2\n".$ret if ($flavour =~ /linux.*64le/);
49 if ($flavour =~ /osx/)
51 $arch = ($flavour=~/64/) ?
"ppc970-64" : "ppc970" if ($arch eq "any");
56 if ($flavour =~ /linux/)
58 my $name = shift; $name =~ s
|^[\
.\_
]||;
59 my $ret = ".size $name,.-".($flavour=~/64$/?
".":"").$name;
60 $ret .= "\n.size .$name,.-.$name" if ($flavour=~/64$/);
68 my $line = join(",",@_);
69 if ($line =~ /^"(.*)"$/)
70 { ".byte " . join(",",unpack("C*",$1),0) . "\n.align 2"; }
79 if (/^0x([0-9a-f]*?)([0-9a-f]{1,8})$/io)
80 { $hi=$1?
"0x$1":"0"; $lo="0x$2"; }
82 { $hi=$1>>32; $lo=$1&0xffffffff; } # error-prone with 32-bit perl
84 { $hi=undef; $lo=$_; }
87 { push(@ret,$flavour=~/le$/o?
".long\t$lo,$hi":".long\t$hi,$lo"); }
89 { push(@ret,".quad $lo"); }
94 ################################################################
95 # simplified mnemonics not handled by at least one assembler
96 ################################################################
99 my $cr = 0; $cr = shift if ($#_>1);
100 # Some out-of-date 32-bit GNU assembler just can't handle cmplw...
101 ($flavour =~ /linux.*32/) ?
102 " .long ".sprintf "0x%x",31<<26|$cr<<23|$_[0]<<16|$_[1]<<11|64 :
103 " cmplw ".join(',',$cr,@_);
107 my $bo = $f=~/[\+\-]/ ?
16+9 : 16; # optional "to be taken" hint
109 } if ($flavour!~/linux/);
112 my $bo = $f=~/\-/ ?
12+2 : 12; # optional "not to be taken" hint
113 ($flavour =~ /linux/) ?
# GNU as doesn't allow most recent hints
114 " .long ".sprintf "0x%x",19<<26|$bo<<21|16<<1 :
119 my $bo = $f=~/\-/ ?
4+2 : 4; # optional "not to be taken" hint
120 ($flavour =~ /linux/) ?
# GNU as doesn't allow most recent hints
121 " .long ".sprintf "0x%x",19<<26|$bo<<21|2<<16|16<<1 :
126 my $bo = $f=~/-/ ?
12+2 : 12; # optional "not to be taken" hint
127 ($flavour =~ /linux/) ?
# GNU as doesn't allow most recent hints
128 " .long ".sprintf "0x%X",19<<26|$bo<<21|2<<16|16<<1 :
131 # GNU assembler can't handle extrdi rA,rS,16,48, or when sum of last two
132 # arguments is 64, with "operand out of range" error.
134 my ($f,$ra,$rs,$n,$b) = @_;
135 $b = ($b+$n)&63; $n = 64-$n;
136 " rldicl $ra,$rs,$b,$n";
139 my ($f,$vx,$vy) = @_;
143 # Some ABIs specify vrsave, special-purpose register #256, as reserved
145 my $no_vrsave = ($flavour =~ /linux-ppc64le/);
147 my ($f,$idx,$ra) = @_;
148 if ($idx == 256 && $no_vrsave) {
155 my ($f,$rd,$idx) = @_;
156 if ($idx == 256 && $no_vrsave) {
163 # PowerISA 2.06 stuff
165 my ($f, $vrt, $ra, $rb, $op) = @_;
166 " .long ".sprintf "0x%X",(31<<26)|($vrt<<21)|($ra<<16)|($rb<<11)|($op*2+1);
168 # made-up unaligned memory reference AltiVec/VMX instructions
169 my $lvx_u = sub { vsxmem_op
(@_, 844); }; # lxvd2x
170 my $stvx_u = sub { vsxmem_op
(@_, 972); }; # stxvd2x
171 my $lvdx_u = sub { vsxmem_op
(@_, 588); }; # lxsdx
172 my $stvdx_u = sub { vsxmem_op
(@_, 716); }; # stxsdx
173 my $lvx_4w = sub { vsxmem_op
(@_, 780); }; # lxvw4x
174 my $stvx_4w = sub { vsxmem_op
(@_, 908); }; # stxvw4x
176 # PowerISA 2.07 stuff
178 my ($f, $vrt, $vra, $vrb, $op) = @_;
179 " .long ".sprintf "0x%X",(4<<26)|($vrt<<21)|($vra<<16)|($vrb<<11)|$op;
181 my $vcipher = sub { vcrypto_op
(@_, 1288); };
182 my $vcipherlast = sub { vcrypto_op
(@_, 1289); };
183 my $vncipher = sub { vcrypto_op
(@_, 1352); };
184 my $vncipherlast= sub { vcrypto_op
(@_, 1353); };
185 my $vsbox = sub { vcrypto_op
(@_, 0, 1480); };
186 my $vshasigmad = sub { my ($st,$six)=splice(@_,-2); vcrypto_op
(@_, $st<<4|$six, 1730); };
187 my $vshasigmaw = sub { my ($st,$six)=splice(@_,-2); vcrypto_op
(@_, $st<<4|$six, 1666); };
188 my $vpmsumb = sub { vcrypto_op
(@_, 1032); };
189 my $vpmsumd = sub { vcrypto_op
(@_, 1224); };
190 my $vpmsubh = sub { vcrypto_op
(@_, 1096); };
191 my $vpmsumw = sub { vcrypto_op
(@_, 1160); };
192 my $vaddudm = sub { vcrypto_op
(@_, 192); };
193 my $vadduqm = sub { vcrypto_op
(@_, 256); };
197 " .long ".sprintf "0x%X",(31<<26)|($arg<<21)|(147*2);
200 print "#include <asm/ppc_asm.h>\n" if $flavour =~ /linux
/;
204 $line =~ s
|[#!;].*$||; # get rid of asm-style comments...
205 $line =~ s
|/\*.*\*/||; # ... and C-style comments...
206 $line =~ s
|^\s
+||; # ... and skip white spaces in beginning...
207 $line =~ s
|\s
+$||; # ... and at the end
210 $line =~ s
|\b\
.L
(\w
+)|L
$1|g
; # common denominator for Locallabel
211 $line =~ s
|\bL
(\w
+)|\
.L
$1|g
if ($dotinlocallabels);
215 $line =~ s
|^\s
*(\
.?
)(\w
+)([\
.\
+\
-]?
)\s
*||;
216 my $c = $1; $c = "\t" if ($c eq "");
219 my $opcode = eval("\$$mnemonic");
220 $line =~ s/\b(c?[rf]|v|vs)([0-9]+)\b/$2/g if ($c ne "." and $flavour !~ /osx/);
221 if (ref($opcode) eq 'CODE') { $line = &$opcode($f,split(',',$line)); }
222 elsif ($mnemonic) { $line = $c.$mnemonic.$f."\t".$line; }
225 print $line if ($line);