2 # Copyright 2015-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
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(',',@_); }
28 if ($flavour =~ /linux/) { ".fpu\t".join(',',@_); }
32 SWITCH: for ($flavour) {
33 /linux/ && return ".section\t.rodata";
34 /ios/ && return ".section\t__TEXT,__const";
39 if ($flavour =~ /ios/) { ".private_extern\t".join(',',@_); }
40 else { ".hidden\t".join(',',@_); }
43 my @args = split(/,\s*/,shift);
45 my $global = \$GLOBALS{$name};
48 if ($flavour =~ /ios32/) {
49 $ret = ".comm\t_$name,@args[1]\n";
50 $ret .= ".non_lazy_symbol_pointer\n";
52 $ret .= ".indirect_symbol\t_$name\n";
55 } else { $ret = ".comm\t".join(',',@args); }
62 my $global = \$GLOBALS{$name};
65 SWITCH: for ($flavour) {
66 /ios/ && do { $name = "_$name";
71 $ret = ".globl $name" if (!$ret);
78 return; # return nothing
81 if ($flavour =~ /linux/) { ".type\t".join(',',@_); }
82 elsif ($flavour =~ /ios32/) { if (join(',',@_) =~ /(\w+),%function/) {
83 "#ifdef __thumb2__\n".
91 if ($flavour =~ /linux/) { ".size\t".join(',',@_); }
95 if ($flavour =~ /linux/) { ".inst\t".join(',',@_); }
96 else { ".long\t".join(',',@_); }
99 my $line = join(",",@_);
100 if ($line =~ /^"(.*)"$/)
101 { ".byte " . join(",",unpack("C*",$1),0) . "\n.align 2"; }
107 my ($args,$comment) = split(m|\s*//|,shift);
108 "\tadrp\t$args\@PAGE";
109 } if ($flavour =~ /ios64/);
113 my ($r,$sfx,$start,$end) = @_;
115 join(",",map("$r$_$sfx",($start..$end)));
124 while ($line =~ m/\G[^@\/\{\"]*/g) {
125 if ($line =~ m/\G(@|\/\/|$)/gc) {
128 elsif ($line =~ m/\G\{/gc) {
129 my $saved_pos = pos($line);
130 $line =~ s/\G([rdqv])([0-9]+)([^\-]*)\-\1([0-9]+)\3/range($1,$3,$2,$4)/e;
131 pos($line) = $saved_pos;
132 $line =~ m/\G[^\}]*\}/g;
134 elsif ($line =~ m/\G\"/gc) {
135 $line =~ m/\G[^\"]*\"/g;
139 $line =~ s/\b(\w+)/$GLOBALS{$1} or $1/ge;
141 if ($flavour =~ /ios64/) {
142 $line =~ s/#:lo12:(\w+)/$1\@PAGEOFF/;
150 if ($line =~ m/^\s*(#|@|\/\/)/) { print $line; next; }
152 $line =~ s|/\*.*\*/||; # get rid of C-style comments...
153 $line =~ s|^\s+||; # ... and skip white spaces in beginning...
154 $line =~ s|\s+$||; # ... and at the end
157 $line =~ s|[\b\.]L(\w{2,})|L$1|g; # common denominator for Locallabel
158 $line =~ s|\bL(\w{2,})|\.L$1|g if ($dotinlocallabels);
162 $line =~ s|(^[\.\w]+)\:\s*||;
165 printf "%s:",($GLOBALS{$label} or $label);
169 if ($line !~ m/^[#@]/) {
170 $line =~ s|^\s*(\.?)(\S+)\s*||;
171 my $c = $1; $c = "\t" if ($c eq "");
174 if ($mnemonic =~ m/([^\.]+)\.([^\.]+)/) {
175 $opcode = eval("\$$1_$2");
177 $opcode = eval("\$$mnemonic");
180 my $arg=expand_line($line);
182 if (ref($opcode) eq 'CODE') {
183 $line = &$opcode($arg);
184 } elsif ($mnemonic) {
185 $line = $c.$mnemonic;
186 $line.= "\t$arg" if ($arg ne "");
190 print $line if ($line);
194 close STDOUT or die "error closing STDOUT: $!";