asm2gas revision 1.6
11.1Smycroft#!/bin/sh 21.6Sis# $NetBSD: asm2gas,v 1.6 2000/12/06 21:31:05 is Exp $ 31.1Smycroft 41.1Smycroft# 51.5Smycroft# Copyright (c) 1998 The NetBSD Foundation, Inc. 61.5Smycroft# All rights reserved. 71.5Smycroft# 81.5Smycroft# This code is derived from software contributed to The NetBSD Foundation 91.5Smycroft# by Charles M. Hannum. 101.1Smycroft# 111.1Smycroft# Redistribution and use in source and binary forms, with or without 121.1Smycroft# modification, are permitted provided that the following conditions 131.1Smycroft# are met: 141.1Smycroft# 1. Redistributions of source code must retain the above copyright 151.1Smycroft# notice, this list of conditions and the following disclaimer. 161.1Smycroft# 2. Redistributions in binary form must reproduce the above copyright 171.1Smycroft# notice, this list of conditions and the following disclaimer in the 181.1Smycroft# documentation and/or other materials provided with the distribution. 191.1Smycroft# 3. All advertising materials mentioning features or use of this software 201.1Smycroft# must display the following acknowledgement: 211.5Smycroft# This product includes software developed by the NetBSD 221.5Smycroft# Foundation, Inc. and its contributors. 231.5Smycroft# 4. Neither the name of The NetBSD Foundation nor the names of its 241.5Smycroft# contributors may be used to endorse or promote products derived 251.5Smycroft# from this software without specific prior written permission. 261.1Smycroft# 271.5Smycroft# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 281.5Smycroft# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 291.5Smycroft# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 301.5Smycroft# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 311.5Smycroft# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 321.5Smycroft# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 331.5Smycroft# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 341.5Smycroft# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 351.5Smycroft# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 361.5Smycroft# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 371.5Smycroft# POSSIBILITY OF SUCH DAMAGE. 381.1Smycroft# 391.1Smycroft 401.1Smycroft# This ugly script converts assembler code from Motorola's format to a 411.1Smycroft# form that gas (MIT syntax) can digest. 421.1Smycroft 431.1Smycroftcat $1 | sed -e ' 441.2Smycroft # format canonicalization 451.2Smycroft 461.1Smycroft /[ ]IDNT[ ]/{s/^/|/;p;d;} 471.2Smycroft /^\*/{s//|/;p;d;} 481.1Smycroft s/;/|/ 491.1Smycroft /[ ]equ[ ]/{ 501.1Smycroft s/\([A-Za-z_][A-Za-z0-9_]*\)[ ]*equ[ ]*/\1,/ 511.1Smycroft s/[ ][ ]*\(.*\)$/ |\1/ 521.1Smycroft s/ ||/ |/ 531.1Smycroft s/^/ .set / 541.1Smycroft p;d 551.1Smycroft } 561.1Smycroft s/^\([A-Za-z_][A-Za-z0-9_]*\)[ ][ ]*/\1: / 571.1Smycroft s/^\([A-Za-z_][A-Za-z0-9_]*\)$/\1:/ 581.1Smycroft /^[A-Za-z_][A-Za-z0-9_]*:/{ 591.1Smycroft h 601.1Smycroft s/:.*$/:/ 611.1Smycroft p 621.1Smycroft g 631.1Smycroft s/^.*:[ ]*/ / 641.1Smycroft /^ $/d 651.1Smycroft } 661.2Smycroft /^[ ][ ]*\([.a-zA-Z][.a-zA-Z0-9]*\)/{ 671.1Smycroft h 681.2Smycroft s/// 691.2Smycroft s/^[ ][ ]*// 701.1Smycroft s/[ ][ ]*\(.*\)$/ |\1/ 711.1Smycroft s/ ||/ |/ 721.1Smycroft x 731.2Smycroft s/^[ ][ ]*// 741.1Smycroft s/[ ][ ]*.*$/ / 751.1Smycroft y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ 761.1Smycroft s/^/ / 771.1Smycroft G 781.1Smycroft s/\n// 791.1Smycroft } 801.1Smycroft' | sed -e ' 811.2Smycroft # operator conversion 821.2Smycroft 831.2Smycroft s/^ section 7/ .text/ 841.2Smycroft s/^ section 8/ .text/ 851.2Smycroft s/^ section 15/ .data/ 861.2Smycroft /^ include/{s/include[ ]/.include "/;s/\.h[ ]*$/.defs"/;p;d;} 871.2Smycroft s/^ xref/| xref/ 881.2Smycroft s/^ end/| end/ 891.2Smycroft s/^ xdef/ .global/ 901.2Smycroft 911.2Smycroft s/^ dc\.l/ .long/ 921.2Smycroft s/^ dc\.w/ .short/ 931.2Smycroft s/^ dc\.b/ .byte/ 941.2Smycroft 951.2Smycroft /^ [aceg-z]/{ 961.2Smycroft /^ add[aiqx]*\.[bwl] /{s/\.//;p;d;} 971.2Smycroft /^ andi*\.[bwl] /{s/\.//;p;d;} 981.2Smycroft /^ as[lr]\.[bwl] /{s/\.//;p;d;} 991.2Smycroft /^ clr\.[bwl] /{s/\.//;p;d;} 1001.2Smycroft /^ cmp[i2]*\.[bwl] /{s/\.//;p;d;} 1011.2Smycroft /^ eori*\.[bwl] /{s/\.//;p;d;} 1021.2Smycroft /^ lea\.l /{s/\..//;p;d;} 1031.2Smycroft /^ ls[lr]\.[bwl] /{s/\.//;p;d;} 1041.2Smycroft /^ move[acmqs]*\.[bwl] /{s/\.//;p;d;} 1051.2Smycroft /^ mul[su]\.[wl] /{s/\.//;p;d;} 1061.2Smycroft /^ neg\.[bwl] /{s/\.//;p;d;} 1071.2Smycroft /^ ori*\.[bwl] /{s/\.//;p;d;} 1081.2Smycroft /^ ro[lrx]*\.[bwl] /{s/\.//;p;d;} 1091.2Smycroft /^ sub[aiqx]*\.[bwl] /{s/\.//;p;d;} 1101.2Smycroft /^ swap\.w /{s/\..//;p;d;} 1111.2Smycroft /^ s\([a-tv-z][a-z]*\)\.b /{s/\..//;p;d;} 1121.2Smycroft /^ tst\.[bwl] /{s/\.//;p;d;} 1131.2Smycroft p;d 1141.2Smycroft } 1151.2Smycroft 1161.2Smycroft /^ bchg\.[bl] /{s/\..//;p;d;} 1171.2Smycroft /^ bclr\.[bl] /{s/\..//;p;d;} 1181.2Smycroft /^ bset\.[bl] /{s/\..//;p;d;} 1191.2Smycroft /^ btst\.[bl] /{s/\..//;p;d;} 1201.2Smycroft /^ div[sul]*\.[wl] /{s/\.//;p;d;} 1211.2Smycroft /^ fabs\.[sdx] /{s/\.//;p;d;} 1221.2Smycroft /^ fadd\.[sdxbwl] /{s/\.//;p;d;} 1231.2Smycroft /^ fcmp\.[sdxbwl] /{s/\.//;p;d;} 1241.2Smycroft /^ fdiv\.[sdx] /{s/\.//;p;d;} 1251.2Smycroft /^ fmove[mx]*\.[sdxbwl] /{s/\.//;p;d;} 1261.2Smycroft /^ fmul\.[sdx] /{s/\.//;p;d;} 1271.2Smycroft /^ fneg\.[sdx] /{s/\.//;p;d;} 1281.2Smycroft /^ fsqrt\.[sdx] /{s/\.//;p;d;} 1291.2Smycroft /^ fsub\.[sdxbwl] /{s/\.//;p;d;} 1301.2Smycroft /^ ftst\.[sdx] /{s/\.//;p;d;} 1311.2Smycroft 1321.2Smycroft /^ b[a-eg-z][a-z]*\.b /{s/\.b/s/;p;d;} 1331.2Smycroft /^ b[a-eg-z][a-z]*\.w /{s/\.w//;p;d;} 1341.2Smycroft /^ b[a-eg-z][a-z]*\.l /{s/\.l/l/;p;d;} 1351.2Smycroft /^ db[a-z][a-z]*\.w /{s/\.w//;p;d;} 1361.2Smycroft /^ fb[a-eg-z][a-z]*\.w /{s/\.w//;p;d;} 1371.2Smycroft /^ fb[a-eg-z][a-z]*\.l /{s/\.l/l/;p;d;} 1381.1Smycroft' | sed -e ' 1391.2Smycroft # operand conversion 1401.2Smycroft 1411.6Sis s/\([^_a-zA-Z0-9]\)FPIAR\([^_a-zA-Z0-9]\)/\1%FPI\2/g 1421.6Sis s/\([^_a-zA-Z0-9]\)FPIAR$/\1%FPI/g 1431.6Sis s/\([^_a-zA-Z0-9]\)fpiar\([^_a-zA-Z0-9]\)/\1%fpi\2/g 1441.6Sis s/\([^_a-zA-Z0-9]\)fpiar$/\1%fpi/g 1451.6Sis s/\([^_a-zA-Z0-9]\)FPCR\([^_a-zA-Z0-9]\)/\1%FPCR\2/g 1461.6Sis s/\([^_a-zA-Z0-9]\)FPCR$/\1%FPCR/g 1471.6Sis s/\([^_a-zA-Z0-9]\)fpcr\([^_a-zA-Z0-9]\)/\1%fpcr\2/g 1481.6Sis s/\([^_a-zA-Z0-9]\)fpcr$/\1%fpcr/g 1491.6Sis s/\([^_a-zA-Z0-9]\)FPSR\([^_a-zA-Z0-9]\)/\1%FPSR\2/g 1501.6Sis s/\([^_a-zA-Z0-9]\)FPSR$/\1%FPSR/g 1511.6Sis s/\([^_a-zA-Z0-9]\)fpsr\([^_a-zA-Z0-9]\)/\1%fpsr\2/g 1521.6Sis s/\([^_a-zA-Z0-9]\)fpsr$/\1%fpsr/g 1531.2Smycroft 1541.2Smycroft s/\$/0x/g 1551.2Smycroft s/#:/#:0x/g 1561.2Smycroft 1571.6Sis s/\([^[:alnum:]_]\)\([dDaA][0-7]\)\([^[:alnum:]_]\)/\1%\2\3/g 1581.6Sis s/\([^[:alnum:]_]\)\([fF][pP][0-7]\)\([^[:alnum:]_]\)/\1%\2\3/g 1591.6Sis s/\([^[:alnum:]_]\)\(sp\)\([^[:alnum:]_]\)/\1%\2\3/g 1601.6Sis s/\([^[:alnum:]_]\)\(pc\)\([^[:alnum:]_]\)/\1%\2\3/g 1611.6Sis 1621.6Sis s/\([^[:alnum:]_]\)\([dDaA][0-7]\)$/\1%\2/g 1631.6Sis s/\([^[:alnum:]_]\)\([fF][pP][0-7]\)$/\1%\2/g 1641.6Sis s/\([^[:alnum:]_]\)\(sp\)$/\1%\2/g 1651.6Sis 1661.6Sis s/\(,\)\([dDaA][0-7]\)/\1%\2/g 1671.6Sis s/\(,\)\([fF][pP][0-7]\)/\1%\2/g 1681.6Sis 1691.6Sis s/-(\(%[sSpPaA][pPcC0-7]\))/\1@-/g 1701.6Sis s/(\(%[sSpPaA][pPcC0-7]\))+/\1@+/g 1711.6Sis s/\([-+A-Za-z0-9_]*\)(\(%[sSpPaA][pPcC0-7]\)\([),]\)/\2@(\1\3/g 1721.1Smycroft 1731.1Smycroft s/\.\([bBwWlL])\)/:\1/g 1741.1Smycroft s/\.\([bBwWlL]\)\*\([0-9][0-9]*)\)/:\1:\2/g 1751.1Smycroft s/\*\([0-9][0-9]*\))/:l:\1)/g 1761.1Smycroft s/{\([0-9][0-9]*\):\([0-9][0-9]*\)}/{#\1:#\2}/g 1771.6Sis s/{\(%[dD][0-7]\):\([0-9][0-9]*\)}/{\1:#\2}/g 1781.6Sis s/{\([dD][0-7]\):\([0-9][0-9]*\)}/{%\1:#\2}/g 1791.6Sis s/{\([dD][0-7]\):\(%[dD][0-9]*\)}/{%\1:\2}/g 1801.6Sis 1811.6Sis s/\(-\)\([dDaA][0-7]\)\([^_a-zA-Z0-9]\)/\1%\2\3/g 1821.6Sis s/\(-\)\([fF][pP][0-7]\)\([^_a-zA-Z0-9]\)/\1%\2\3/g 1831.6Sis 1841.6Sis s/\(\/\)\([dDaA][0-7]\)\([^_a-zA-Z0-9]\)/\1%\2\3/g 1851.6Sis s/\(\/\)\([fF][pP][0-7]\)\([^_a-zA-Z0-9]\)/\1%\2\3/g 1861.1Smycroft 1871.2Smycroft s/@(0*)/@/g 1881.1Smycroft s/(,/(/g;s/:)/)/g 1891.1Smycroft 1901.1Smycroft # make up for a gas bug 1911.1Smycroft /^ fmovemx /{ 1921.6Sis s/ \(%[fF][pP][0-7]\),/ \1-\1,/ 1931.6Sis s/,\(%[fF][pP][0-7]\) /,\1-\1 / 1941.6Sis s/,\(%[fF][pP][0-7]\)$/,\1-\1/ 1951.1Smycroft } 1961.6Sis' | sed -e ' 1971.6Sis # Floating point literal conversion 1981.6Sis 1991.6Sis s/:0x41dfffffffc00000/0r2147483647.0/g 2001.6Sis s/:0xc1e0000000000000/0r-2147483648.0/g 2011.6Sis s/:0x41dfffffffe00000/0r2147483647.5/g 2021.6Sis s/:0xc1e0000000100000/0r-2147483648.5/g 2031.6Sis s/:0x46fffe00/0r32767.0/g 2041.6Sis s/:0xc7000000/0r-32768.0/g 2051.6Sis s/:0x46ffff00/0r32767.5/g 2061.6Sis s/:0xc7000080/0r-32768.5/g 2071.6Sis s/:0x42fe0000/0r127.0/g 2081.6Sis s/:0xc3000000/0r-128.0/g 2091.6Sis s/:0x42ff0000/0r127.5/g 2101.6Sis s/:0xc3008000/0r-128.5/g 2111.6Sis s/:0x3F800000/0r1.0/g 2121.6Sis s/:0x00000000/0r0.0/g 2131.6Sis s/:0xBF800000/0r-1.0/g 2141.6Sis s/:0x3F000000/0r0.5/g 2151.6Sis s/:0x3E800000/0r0.25/g 2161.6Sis s/:0x42B8AA3B/0r92.332481384277343750/g 2171.6Sis s/:0xBC317218/0r-0.0108304247260093688964843750/g 2181.6Sis s/:0x3AB60B70/0r0.001388890668749809265136718750/g 2191.6Sis s/:0x3C088895/0r0.0083333449438214302062988281250/g 2201.6Sis s/:0x42B8AA3B/0r92.332481384277343750/g 2211.6Sis s/:0x3950097B/0r0.0001983995753107592463493347167968750/g 2221.6Sis s/:0x3AB60B6A/0r0.001388889970257878303527832031250/g 2231.6Sis s/:0x2F30CAA8/0r1.60791047143504783889511600136756896972656250e-10/g 2241.6Sis s/:0x310F8290/0r2.0883454965314740547910332679748535156250e-09/g 2251.6Sis s/:0x32D73220/0r2.5052088403754169121384620666503906250e-08/g 2261.6Sis s/:0x3493F281/0r2.755732850800995947793126106262207031250e-07/g 2271.6Sis s/:0x40000000/0r2.0/g 2281.6Sis s/:0x42800000/0r6.40e+01/g 2291.6Sis s/:0x3C800000/0r1.56250e-02/g 2301.6Sis s/fadds #:0x00800000,%[fF][pP]0/ .long 0xf23c4422,0x00800000/ 2311.6Sis s/fsubs #:0x00800000,%[fF][pP]0/ .long 0xf23c4428,0x00800000/ 2321.6Sis s/fsubs #:0x00800000,%[fF][pP]1/ .long 0xf23c44a8,0x00800000/ 2331.6Sis s/fmoves #:0x80000000,%[fF][pP]0/ .long 0xf23c4400,0x80000000/ 2341.6Sis s/fmoves #:0x00000000,%[fF][pP]0/ .long 0xf23c4400,0x00000000/ 2351.6Sis 2361.1Smycroft' 237