media/libtheora/lib/arm/arm2gnu.pl

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 #!/usr/bin/perl
michael@0 2
michael@0 3 my $bigend; # little/big endian
michael@0 4 my $nxstack;
michael@0 5
michael@0 6 $nxstack = 0;
michael@0 7
michael@0 8 eval 'exec /usr/local/bin/perl -S $0 ${1+"$@"}'
michael@0 9 if $running_under_some_shell;
michael@0 10
michael@0 11 while ($ARGV[0] =~ /^-/) {
michael@0 12 $_ = shift;
michael@0 13 last if /^--/;
michael@0 14 if (/^-n/) {
michael@0 15 $nflag++;
michael@0 16 next;
michael@0 17 }
michael@0 18 die "I don't recognize this switch: $_\\n";
michael@0 19 }
michael@0 20 $printit++ unless $nflag;
michael@0 21
michael@0 22 $\ = "\n"; # automatically add newline on print
michael@0 23 $n=0;
michael@0 24
michael@0 25 $thumb = 0; # ARM mode by default, not Thumb.
michael@0 26
michael@0 27 LINE:
michael@0 28 while (<>) {
michael@0 29
michael@0 30 # For ADRLs we need to add a new line after the substituted one.
michael@0 31 $addPadding = 0;
michael@0 32
michael@0 33 # First, we do not dare to touch *anything* inside double quotes, do we?
michael@0 34 # Second, if you want a dollar character in the string,
michael@0 35 # insert two of them -- that's how ARM C and assembler treat strings.
michael@0 36 s/^([A-Za-z_]\w*)[ \t]+DCB[ \t]*\"/$1: .ascii \"/ && do { s/\$\$/\$/g; next };
michael@0 37 s/\bDCB\b[ \t]*\"/.ascii \"/ && do { s/\$\$/\$/g; next };
michael@0 38 s/^(\S+)\s+RN\s+(\S+)/$1 .req r$2/ && do { s/\$\$/\$/g; next };
michael@0 39 # If there's nothing on a line but a comment, don't try to apply any further
michael@0 40 # substitutions (this is a cheap hack to avoid mucking up the license header)
michael@0 41 s/^([ \t]*);/$1@/ && do { s/\$\$/\$/g; next };
michael@0 42 # If substituted -- leave immediately !
michael@0 43
michael@0 44 s/@/,:/;
michael@0 45 s/;/@/;
michael@0 46 while ( /@.*'/ ) {
michael@0 47 s/(@.*)'/$1/g;
michael@0 48 }
michael@0 49 s/\{FALSE\}/0/g;
michael@0 50 s/\{TRUE\}/1/g;
michael@0 51 s/\{(\w\w\w\w+)\}/$1/g;
michael@0 52 s/\bINCLUDE[ \t]*([^ \t\n]+)/.include \"$1\"/;
michael@0 53 s/\bGET[ \t]*([^ \t\n]+)/.include \"${ my $x=$1; $x =~ s|\.s|-gnu.S|; \$x }\"/;
michael@0 54 s/\bIMPORT\b/.extern/;
michael@0 55 s/\bEXPORT\b/.global/;
michael@0 56 s/^(\s+)\[/$1IF/;
michael@0 57 s/^(\s+)\|/$1ELSE/;
michael@0 58 s/^(\s+)\]/$1ENDIF/;
michael@0 59 s/IF *:DEF:/ .ifdef/;
michael@0 60 s/IF *:LNOT: *:DEF:/ .ifndef/;
michael@0 61 s/ELSE/ .else/;
michael@0 62 s/ENDIF/ .endif/;
michael@0 63
michael@0 64 if( /\bIF\b/ ) {
michael@0 65 s/\bIF\b/ .if/;
michael@0 66 s/=/==/;
michael@0 67 }
michael@0 68 if ( $n == 2) {
michael@0 69 s/\$/\\/g;
michael@0 70 }
michael@0 71 if ($n == 1) {
michael@0 72 s/\$//g;
michael@0 73 s/label//g;
michael@0 74 $n = 2;
michael@0 75 }
michael@0 76 if ( /MACRO/ ) {
michael@0 77 s/MACRO *\n/.macro/;
michael@0 78 $n=1;
michael@0 79 }
michael@0 80 if ( /\bMEND\b/ ) {
michael@0 81 s/\bMEND\b/.endm/;
michael@0 82 $n=0;
michael@0 83 }
michael@0 84
michael@0 85 # ".rdata" doesn't work in 'as' version 2.13.2, as it is ".rodata" there.
michael@0 86 #
michael@0 87 if ( /\bAREA\b/ ) {
michael@0 88 if ( /CODE/ ) {
michael@0 89 $nxstack = 1;
michael@0 90 }
michael@0 91 s/^(.+)CODE(.+)READONLY(.*)/ .text/;
michael@0 92 s/^(.+)DATA(.+)READONLY(.*)/ .section .rdata\n .align 2/;
michael@0 93 s/^(.+)\|\|\.data\|\|(.+)/ .data\n .align 2/;
michael@0 94 s/^(.+)\|\|\.bss\|\|(.+)/ .bss/;
michael@0 95 }
michael@0 96
michael@0 97 s/\|\|\.constdata\$(\d+)\|\|/.L_CONST$1/; # ||.constdata$3||
michael@0 98 s/\|\|\.bss\$(\d+)\|\|/.L_BSS$1/; # ||.bss$2||
michael@0 99 s/\|\|\.data\$(\d+)\|\|/.L_DATA$1/; # ||.data$2||
michael@0 100 s/\|\|([a-zA-Z0-9_]+)\@([a-zA-Z0-9_]+)\|\|/@ $&/;
michael@0 101 s/^(\s+)\%(\s)/ .space $1/;
michael@0 102
michael@0 103 s/\|(.+)\.(\d+)\|/\.$1_$2/; # |L80.123| -> .L80_123
michael@0 104 s/\bCODE32\b/.code 32/ && do {$thumb = 0};
michael@0 105 s/\bCODE16\b/.code 16/ && do {$thumb = 1};
michael@0 106 if (/\bPROC\b/)
michael@0 107 {
michael@0 108 print " .thumb_func" if ($thumb);
michael@0 109 s/\bPROC\b/@ $&/;
michael@0 110 }
michael@0 111 s/^(\s*)(S|Q|SH|U|UQ|UH)ASX\b/$1$2ADDSUBX/;
michael@0 112 s/^(\s*)(S|Q|SH|U|UQ|UH)SAX\b/$1$2SUBADDX/;
michael@0 113 s/\bENDP\b/@ $&/;
michael@0 114 s/\bSUBT\b/@ $&/;
michael@0 115 s/\bDATA\b/@ $&/; # DATA directive is deprecated -- Asm guide, p.7-25
michael@0 116 s/\bKEEP\b/@ $&/;
michael@0 117 s/\bEXPORTAS\b/@ $&/;
michael@0 118 s/\|\|(.)+\bEQU\b/@ $&/;
michael@0 119 s/\|\|([\w\$]+)\|\|/$1/;
michael@0 120 s/\bENTRY\b/@ $&/;
michael@0 121 s/\bASSERT\b/@ $&/;
michael@0 122 s/\bGBLL\b/@ $&/;
michael@0 123 s/\bGBLA\b/@ $&/;
michael@0 124 s/^\W+OPT\b/@ $&/;
michael@0 125 s/:OR:/|/g;
michael@0 126 s/:SHL:/<</g;
michael@0 127 s/:SHR:/>>/g;
michael@0 128 s/:AND:/&/g;
michael@0 129 s/:LAND:/&&/g;
michael@0 130 s/CPSR/cpsr/;
michael@0 131 s/SPSR/spsr/;
michael@0 132 s/ALIGN$/.balign 4/;
michael@0 133 s/ALIGN\s+([0-9x]+)$/.balign $1/;
michael@0 134 s/psr_cxsf/psr_all/;
michael@0 135 s/LTORG/.ltorg/;
michael@0 136 s/^([A-Za-z_]\w*)[ \t]+EQU/ .set $1,/;
michael@0 137 s/^([A-Za-z_]\w*)[ \t]+SETL/ .set $1,/;
michael@0 138 s/^([A-Za-z_]\w*)[ \t]+SETA/ .set $1,/;
michael@0 139 s/^([A-Za-z_]\w*)[ \t]+\*/ .set $1,/;
michael@0 140
michael@0 141 # {PC} + 0xdeadfeed --> . + 0xdeadfeed
michael@0 142 s/\{PC\} \+/ \. +/;
michael@0 143
michael@0 144 # Single hex constant on the line !
michael@0 145 #
michael@0 146 # >>> NOTE <<<
michael@0 147 # Double-precision floats in gcc are always mixed-endian, which means
michael@0 148 # bytes in two words are little-endian, but words are big-endian.
michael@0 149 # So, 0x0000deadfeed0000 would be stored as 0x0000dead at low address
michael@0 150 # and 0xfeed0000 at high address.
michael@0 151 #
michael@0 152 s/\bDCFD\b[ \t]+0x([a-fA-F0-9]{8})([a-fA-F0-9]{8})/.long 0x$1, 0x$2/;
michael@0 153 # Only decimal constants on the line, no hex !
michael@0 154 s/\bDCFD\b[ \t]+([0-9\.\-]+)/.double $1/;
michael@0 155
michael@0 156 # Single hex constant on the line !
michael@0 157 # s/\bDCFS\b[ \t]+0x([a-f0-9]{8})([a-f0-9]{8})/.long 0x$1, 0x$2/;
michael@0 158 # Only decimal constants on the line, no hex !
michael@0 159 # s/\bDCFS\b[ \t]+([0-9\.\-]+)/.double $1/;
michael@0 160 s/\bDCFS[ \t]+0x/.word 0x/;
michael@0 161 s/\bDCFS\b/.float/;
michael@0 162
michael@0 163 s/^([A-Za-z_]\w*)[ \t]+DCD/$1 .word/;
michael@0 164 s/\bDCD\b/.word/;
michael@0 165 s/^([A-Za-z_]\w*)[ \t]+DCW/$1 .short/;
michael@0 166 s/\bDCW\b/.short/;
michael@0 167 s/^([A-Za-z_]\w*)[ \t]+DCB/$1 .byte/;
michael@0 168 s/\bDCB\b/.byte/;
michael@0 169 s/^([A-Za-z_]\w*)[ \t]+\%/.comm $1,/;
michael@0 170 s/^[A-Za-z_\.]\w+/$&:/;
michael@0 171 s/^(\d+)/$1:/;
michael@0 172 s/\%(\d+)/$1b_or_f/;
michael@0 173 s/\%[Bb](\d+)/$1b/;
michael@0 174 s/\%[Ff](\d+)/$1f/;
michael@0 175 s/\%[Ff][Tt](\d+)/$1f/;
michael@0 176 s/&([\dA-Fa-f]+)/0x$1/;
michael@0 177 if ( /\b2_[01]+\b/ ) {
michael@0 178 s/\b2_([01]+)\b/conv$1&&&&/g;
michael@0 179 while ( /[01][01][01][01]&&&&/ ) {
michael@0 180 s/0000&&&&/&&&&0/g;
michael@0 181 s/0001&&&&/&&&&1/g;
michael@0 182 s/0010&&&&/&&&&2/g;
michael@0 183 s/0011&&&&/&&&&3/g;
michael@0 184 s/0100&&&&/&&&&4/g;
michael@0 185 s/0101&&&&/&&&&5/g;
michael@0 186 s/0110&&&&/&&&&6/g;
michael@0 187 s/0111&&&&/&&&&7/g;
michael@0 188 s/1000&&&&/&&&&8/g;
michael@0 189 s/1001&&&&/&&&&9/g;
michael@0 190 s/1010&&&&/&&&&A/g;
michael@0 191 s/1011&&&&/&&&&B/g;
michael@0 192 s/1100&&&&/&&&&C/g;
michael@0 193 s/1101&&&&/&&&&D/g;
michael@0 194 s/1110&&&&/&&&&E/g;
michael@0 195 s/1111&&&&/&&&&F/g;
michael@0 196 }
michael@0 197 s/000&&&&/&&&&0/g;
michael@0 198 s/001&&&&/&&&&1/g;
michael@0 199 s/010&&&&/&&&&2/g;
michael@0 200 s/011&&&&/&&&&3/g;
michael@0 201 s/100&&&&/&&&&4/g;
michael@0 202 s/101&&&&/&&&&5/g;
michael@0 203 s/110&&&&/&&&&6/g;
michael@0 204 s/111&&&&/&&&&7/g;
michael@0 205 s/00&&&&/&&&&0/g;
michael@0 206 s/01&&&&/&&&&1/g;
michael@0 207 s/10&&&&/&&&&2/g;
michael@0 208 s/11&&&&/&&&&3/g;
michael@0 209 s/0&&&&/&&&&0/g;
michael@0 210 s/1&&&&/&&&&1/g;
michael@0 211 s/conv&&&&/0x/g;
michael@0 212 }
michael@0 213
michael@0 214 if ( /commandline/)
michael@0 215 {
michael@0 216 if( /-bigend/)
michael@0 217 {
michael@0 218 $bigend=1;
michael@0 219 }
michael@0 220 }
michael@0 221
michael@0 222 if ( /\bDCDU\b/ )
michael@0 223 {
michael@0 224 my $cmd=$_;
michael@0 225 my $value;
michael@0 226 my $w1;
michael@0 227 my $w2;
michael@0 228 my $w3;
michael@0 229 my $w4;
michael@0 230
michael@0 231 s/\s+DCDU\b/@ $&/;
michael@0 232
michael@0 233 $cmd =~ /\bDCDU\b\s+0x(\d+)/;
michael@0 234 $value = $1;
michael@0 235 $value =~ /(\w\w)(\w\w)(\w\w)(\w\w)/;
michael@0 236 $w1 = $1;
michael@0 237 $w2 = $2;
michael@0 238 $w3 = $3;
michael@0 239 $w4 = $4;
michael@0 240
michael@0 241 if( $bigend ne "")
michael@0 242 {
michael@0 243 # big endian
michael@0 244
michael@0 245 print " .byte 0x".$w1;
michael@0 246 print " .byte 0x".$w2;
michael@0 247 print " .byte 0x".$w3;
michael@0 248 print " .byte 0x".$w4;
michael@0 249 }
michael@0 250 else
michael@0 251 {
michael@0 252 # little endian
michael@0 253
michael@0 254 print " .byte 0x".$w4;
michael@0 255 print " .byte 0x".$w3;
michael@0 256 print " .byte 0x".$w2;
michael@0 257 print " .byte 0x".$w1;
michael@0 258 }
michael@0 259
michael@0 260 }
michael@0 261
michael@0 262
michael@0 263 if ( /\badrl\b/i )
michael@0 264 {
michael@0 265 s/\badrl\s+(\w+)\s*,\s*(\w+)/ldr $1,=$2/i;
michael@0 266 $addPadding = 1;
michael@0 267 }
michael@0 268 s/\bEND\b/@ END/;
michael@0 269 } continue {
michael@0 270 printf ("%s", $_) if $printit;
michael@0 271 if ($addPadding != 0)
michael@0 272 {
michael@0 273 printf (" mov r0,r0\n");
michael@0 274 $addPadding = 0;
michael@0 275 }
michael@0 276 }
michael@0 277 #If we had a code section, mark that this object doesn't need an executable
michael@0 278 # stack.
michael@0 279 if ($nxstack) {
michael@0 280 printf (" .section\t.note.GNU-stack,\"\",\%\%progbits\n");
michael@0 281 }

mercurial