]>
git.ipfire.org Git - thirdparty/openssl.git/blob - crypto/perlasm/arm-xlate.pl
2 # Copyright 2015-2023 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
13 open STDOUT
,">$output" || die "can't open $output: $!";
15 $flavour = "linux32" if (!$flavour or $flavour eq "void");
18 my $dotinlocallabels=($flavour=~/linux/)?
1:0;
20 ################################################################
21 # directives which need special treatment on different platforms
22 ################################################################
24 if ($flavour =~ /linux/) { ".arch\t".join(',',@_); }
25 elsif ($flavour =~ /win64/) { ".arch\t".join(',',@_); }
29 if ($flavour =~ /linux/) { ".fpu\t".join(',',@_); }
33 SWITCH
: for ($flavour) {
34 /linux/ && return ".section\t.rodata";
35 /ios/ && return ".section\t__TEXT,__const";
40 if ($flavour =~ /ios/) { ".private_extern\t".join(',',@_); }
41 elsif ($flavour =~ /win64/) { ""; }
42 else { ".hidden\t".join(',',@_); }
45 my @args = split(/,\s*/,shift);
47 my $global = \
$GLOBALS{$name};
50 if ($flavour =~ /ios32/) {
51 $ret = ".comm\t_$name,@args[1]\n";
52 $ret .= ".non_lazy_symbol_pointer\n";
54 $ret .= ".indirect_symbol\t_$name\n";
57 } else { $ret = ".comm\t".join(',',@args); }
64 my $global = \
$GLOBALS{$name};
67 SWITCH
: for ($flavour) {
68 /ios/ && do { $name = "_$name";
73 $ret = ".globl $name" if (!$ret);
80 return; # return nothing
83 if ($flavour =~ /linux/) { ".type\t".join(',',@_); }
84 elsif ($flavour =~ /ios32/) { if (join(',',@_) =~ /(\w+),%function/) {
85 "#ifdef __thumb2__\n".
90 elsif ($flavour =~ /win64/) { if (join(',',@_) =~ /(\w+),%function/) {
91 # See https://sourceware.org/binutils/docs/as/Pseudo-Ops.html
92 # Per https://docs.microsoft.com/en-us/windows/win32/debug/pe-format#coff-symbol-table,
93 # the type for functions is 0x20, or 32.
102 if ($flavour =~ /linux/) { ".size\t".join(',',@_); }
106 if ($flavour =~ /linux/) { ".inst\t".join(',',@_); }
107 else { ".long\t".join(',',@_); }
110 my $line = join(",",@_);
111 if ($line =~ /^"(.*)"$/)
112 { ".byte " . join(",",unpack("C*",$1),0) . "\n.align 2"; }
118 my ($args,$comment) = split(m
|\s
*//|,shift);
119 "\tadrp\t$args\@PAGE";
120 } if ($flavour =~ /ios64/);
124 my ($r,$sfx,$start,$end) = @_;
126 join(",",map("$r$_$sfx",($start..$end)));
135 while ($line =~ m/\G[^@\/\
{\"]*/g
) {
136 if ($line =~ m/\G(@|\/\
/|$)/gc) {
139 elsif ($line =~ m/\G\{/gc) {
140 my $saved_pos = pos($line);
141 $line =~ s/\G([rdqv])([0-9]+)([^\-]*)\-\1([0-9]+)\3/range($1,$3,$2,$4)/e;
142 pos($line) = $saved_pos;
143 $line =~ m/\G[^\}]*\}/g;
145 elsif ($line =~ m/\G\"/gc) {
146 $line =~ m/\G[^\"]*\"/g;
150 $line =~ s/\b(\w+)/$GLOBALS{$1} or $1/ge;
152 if ($flavour =~ /ios64/) {
153 $line =~ s/#:lo12:(\w+)/$1\@PAGEOFF/;
161 if ($line =~ m/^\s*(#|@|\/\
/)/) { print $line; next; }
163 $line =~ s
|/\*.*\*/||; # get rid of C-style comments...
164 $line =~ s
|^\s
+||; # ... and skip whitespace in beginning...
165 $line =~ s
|\s
+$||; # ... and at the end
168 $line =~ s
|[\b\
.]L
(\w
{2,})|L
$1|g
; # common denominator for Locallabel
169 $line =~ s
|\bL
(\w
{2,})|\
.L
$1|g
if ($dotinlocallabels);
173 if ($line =~ s
|(^[\
.\w
]+)\
:\s
*||) {
175 printf "%s:",($GLOBALS{$label} or $label);
179 if ($line !~ m/^[#@]/) {
180 $line =~ s
|^\s
*(\
.?
)(\S
+)\s
*||;
181 my $c = $1; $c = "\t" if ($c eq "");
184 if ($mnemonic =~ m/([^\.]+)\.([^\.]+)/) {
185 $opcode = eval("\$$1_$2");
187 $opcode = eval("\$$mnemonic");
190 my $arg=expand_line
($line);
192 if (ref($opcode) eq 'CODE') {
193 $line = &$opcode($arg);
194 } elsif ($mnemonic) {
195 $line = $c.$mnemonic;
196 $line.= "\t$arg" if ($arg ne "");
200 # ldr REG, #VALUE psuedo-instruction - avoid clang issue with Neon registers
202 if ($line =~ /^\s*ldr\s+([qd]\d\d?)\s*,\s*=(\w+)/i) {
203 # Immediate load via literal pool into qN or DN - clang max is 2^32-1
204 my ($reg, $value) = ($1, $2);
205 # If $value is hex, 0x + 8 hex chars = 10 chars total will be okay
206 # If $value is decimal, 2^32 - 1 = 4294967295 will be okay (also 10 chars)
207 die("$line: immediate load via literal pool into $reg: value too large for clang - redo manually") if length($value) > 10;
210 print $line if ($line);
214 close STDOUT
or die "error closing STDOUT: $!";