11.1Smycroft#!/bin/sh 21.9Smartin# $NetBSD: asm2gas,v 1.9 2008/04/28 20:23:26 martin Exp $ 31.1Smycroft 41.1Smycroft# 51.8Sapb# Copyright (c) 1998,2008 The NetBSD Foundation, Inc. 61.6Smycroft# All rights reserved. 71.6Smycroft# 81.6Smycroft# This code is derived from software contributed to The NetBSD Foundation 91.6Smycroft# 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# 201.6Smycroft# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 211.6Smycroft# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 221.6Smycroft# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 231.6Smycroft# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 241.6Smycroft# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 251.6Smycroft# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 261.6Smycroft# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 271.6Smycroft# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 281.6Smycroft# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 291.6Smycroft# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 301.6Smycroft# POSSIBILITY OF SUCH DAMAGE. 311.1Smycroft# 321.1Smycroft 331.1Smycroft# This ugly script converts assembler code from Motorola's format to a 341.1Smycroft# form that gas (MIT syntax) can digest. 351.1Smycroft 361.8Sapb: ${SED:=sed} # Which sed to use 371.8SapbP='' # Prefix for register names, may be '%' or '' 381.7Sapb 391.8Sapbcat "$1" | "${SED}" -e ' 401.2Smycroft # format canonicalization 411.2Smycroft 421.8Sapb # leave "#include" alone; change "#" and "*" comment lines to use "|". 431.8Sapb /^\#include/{p;d;} 441.8Sapb /^\#/{s//|#/;p;d;} 451.8Sapb /^\*/{s//|/;p;d;} 461.1Smycroft /[ ]IDNT[ ]/{s/^/|/;p;d;} 471.1Smycroft s/;/|/ 481.1Smycroft /[ ]equ[ ]/{ 491.1Smycroft s/\([A-Za-z_][A-Za-z0-9_]*\)[ ]*equ[ ]*/\1,/ 501.1Smycroft s/[ ][ ]*\(.*\)$/ |\1/ 511.1Smycroft s/ ||/ |/ 521.1Smycroft s/^/ .set / 531.1Smycroft p;d 541.1Smycroft } 551.1Smycroft s/^\([A-Za-z_][A-Za-z0-9_]*\)[ ][ ]*/\1: / 561.1Smycroft s/^\([A-Za-z_][A-Za-z0-9_]*\)$/\1:/ 571.1Smycroft /^[A-Za-z_][A-Za-z0-9_]*:/{ 581.1Smycroft h 591.1Smycroft s/:.*$/:/ 601.1Smycroft p 611.1Smycroft g 621.1Smycroft s/^.*:[ ]*/ / 631.1Smycroft /^ $/d 641.1Smycroft } 651.2Smycroft /^[ ][ ]*\([.a-zA-Z][.a-zA-Z0-9]*\)/{ 661.1Smycroft h 671.2Smycroft s/// 681.2Smycroft s/^[ ][ ]*// 691.1Smycroft s/[ ][ ]*\(.*\)$/ |\1/ 701.1Smycroft s/ ||/ |/ 711.1Smycroft x 721.2Smycroft s/^[ ][ ]*// 731.1Smycroft s/[ ][ ]*.*$/ / 741.1Smycroft y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ 751.1Smycroft s/^/ / 761.1Smycroft G 771.1Smycroft s/\n// 781.1Smycroft } 791.8Sapb' | "${SED}" -e ' 801.2Smycroft # operator conversion 811.2Smycroft 821.2Smycroft s/^ section 7/ .text/ 831.2Smycroft s/^ section 8/ .text/ 841.2Smycroft s/^ section 15/ .data/ 851.2Smycroft /^ include/{s/include[ ]/.include "/;s/\.h[ ]*$/.defs"/;p;d;} 861.2Smycroft s/^ xref/| xref/ 871.2Smycroft s/^ end/| end/ 881.2Smycroft s/^ xdef/ .global/ 891.2Smycroft 901.2Smycroft s/^ dc\.l/ .long/ 911.2Smycroft s/^ dc\.w/ .short/ 921.2Smycroft s/^ dc\.b/ .byte/ 931.2Smycroft 941.2Smycroft /^ [aceg-z]/{ 951.2Smycroft /^ add[aiqx]*\.[bwl] /{s/\.//;p;d;} 961.2Smycroft /^ andi*\.[bwl] /{s/\.//;p;d;} 971.2Smycroft /^ as[lr]\.[bwl] /{s/\.//;p;d;} 981.2Smycroft /^ clr\.[bwl] /{s/\.//;p;d;} 991.2Smycroft /^ cmp[i2]*\.[bwl] /{s/\.//;p;d;} 1001.2Smycroft /^ eori*\.[bwl] /{s/\.//;p;d;} 1011.2Smycroft /^ lea\.l /{s/\..//;p;d;} 1021.2Smycroft /^ ls[lr]\.[bwl] /{s/\.//;p;d;} 1031.2Smycroft /^ move[acmqs]*\.[bwl] /{s/\.//;p;d;} 1041.2Smycroft /^ mul[su]\.[wl] /{s/\.//;p;d;} 1051.2Smycroft /^ neg\.[bwl] /{s/\.//;p;d;} 1061.2Smycroft /^ ori*\.[bwl] /{s/\.//;p;d;} 1071.2Smycroft /^ ro[lrx]*\.[bwl] /{s/\.//;p;d;} 1081.2Smycroft /^ sub[aiqx]*\.[bwl] /{s/\.//;p;d;} 1091.2Smycroft /^ swap\.w /{s/\..//;p;d;} 1101.2Smycroft /^ s\([a-tv-z][a-z]*\)\.b /{s/\..//;p;d;} 1111.2Smycroft /^ tst\.[bwl] /{s/\.//;p;d;} 1121.2Smycroft p;d 1131.2Smycroft } 1141.2Smycroft 1151.2Smycroft /^ bchg\.[bl] /{s/\..//;p;d;} 1161.2Smycroft /^ bclr\.[bl] /{s/\..//;p;d;} 1171.2Smycroft /^ bset\.[bl] /{s/\..//;p;d;} 1181.2Smycroft /^ btst\.[bl] /{s/\..//;p;d;} 1191.2Smycroft /^ div[sul]*\.[wl] /{s/\.//;p;d;} 1201.2Smycroft /^ fabs\.[sdx] /{s/\.//;p;d;} 1211.2Smycroft /^ fadd\.[sdxbwl] /{s/\.//;p;d;} 1221.2Smycroft /^ fcmp\.[sdxbwl] /{s/\.//;p;d;} 1231.2Smycroft /^ fdiv\.[sdx] /{s/\.//;p;d;} 1241.2Smycroft /^ fmove[mx]*\.[sdxbwl] /{s/\.//;p;d;} 1251.2Smycroft /^ fmul\.[sdx] /{s/\.//;p;d;} 1261.2Smycroft /^ fneg\.[sdx] /{s/\.//;p;d;} 1271.2Smycroft /^ fsqrt\.[sdx] /{s/\.//;p;d;} 1281.2Smycroft /^ fsub\.[sdxbwl] /{s/\.//;p;d;} 1291.2Smycroft /^ ftst\.[sdx] /{s/\.//;p;d;} 1301.2Smycroft 1311.2Smycroft /^ b[a-eg-z][a-z]*\.b /{s/\.b/s/;p;d;} 1321.2Smycroft /^ b[a-eg-z][a-z]*\.w /{s/\.w//;p;d;} 1331.2Smycroft /^ b[a-eg-z][a-z]*\.l /{s/\.l/l/;p;d;} 1341.2Smycroft /^ db[a-z][a-z]*\.w /{s/\.w//;p;d;} 1351.2Smycroft /^ fb[a-eg-z][a-z]*\.w /{s/\.w//;p;d;} 1361.2Smycroft /^ fb[a-eg-z][a-z]*\.l /{s/\.l/l/;p;d;} 1371.8Sapb' | "${SED}" -e ' 1381.2Smycroft # operand conversion 1391.2Smycroft 1401.8Sapb # register names "FPIAR" -> "%FPI", etc., possibly without the "%" 1411.8Sapb s/\([^_a-zA-Z0-9]\)FPIAR\([^_a-zA-Z0-9]\)/\1'"$P"'FPI\2/g 1421.8Sapb s/\([^_a-zA-Z0-9]\)FPIAR$/\1'"$P"'FPI/g 1431.8Sapb s/\([^_a-zA-Z0-9]\)fpiar\([^_a-zA-Z0-9]\)/\1'"$P"'fpi\2/g 1441.8Sapb s/\([^_a-zA-Z0-9]\)fpiar$/\1'"$P"'fpi/g 1451.8Sapb s/\([^_a-zA-Z0-9]\)FPCR\([^_a-zA-Z0-9]\)/\1'"$P"'FPCR\2/g 1461.8Sapb s/\([^_a-zA-Z0-9]\)FPCR$/\1'"$P"'FPCR/g 1471.8Sapb s/\([^_a-zA-Z0-9]\)fpcr\([^_a-zA-Z0-9]\)/\1'"$P"'fpcr\2/g 1481.8Sapb s/\([^_a-zA-Z0-9]\)fpcr$/\1'"$P"'fpcr/g 1491.8Sapb s/\([^_a-zA-Z0-9]\)FPSR\([^_a-zA-Z0-9]\)/\1'"$P"'FPSR\2/g 1501.8Sapb s/\([^_a-zA-Z0-9]\)FPSR$/\1'"$P"'FPSR/g 1511.8Sapb s/\([^_a-zA-Z0-9]\)fpsr\([^_a-zA-Z0-9]\)/\1'"$P"'fpsr\2/g 1521.8Sapb s/\([^_a-zA-Z0-9]\)fpsr$/\1'"$P"'fpsr/g 1531.2Smycroft 1541.8Sapb # Hexadecimal numbers 1551.4Sis s/\$\([0-9a-fA-F]\)/0x\1/g 1561.2Smycroft s/#:/#:0x/g 1571.2Smycroft 1581.8Sapb # Insert "%" before more register names (only if $P = "%"). 1591.8Sapb # Some of the rules are repeated because of overlap between trailing 1601.8Sapb # context in one match and leading context in another match; otherwise 1611.8Sapb # only half the register names in "d4{d3:4},d0" would be converted. 1621.8Sapb s/\([^[:alnum:]_%]\)\([dDaA][0-7]\)\([^[:alnum:]_]\)/\1'"$P"'\2\3/g 1631.8Sapb s/\([^[:alnum:]_%]\)\([fF][pP][0-7]\)\([^[:alnum:]_]\)/\1'"$P"'\2\3/g 1641.8Sapb s/\([^[:alnum:]_%]\)\(sp\)\([^[:alnum:]_]\)/\1'"$P"'\2\3/g 1651.8Sapb s/\([^[:alnum:]_%]\)\(pc\)\([^[:alnum:]_]\)/\1'"$P"'\2\3/g 1661.8Sapb 1671.8Sapb s/\([^[:alnum:]_%]\)\([dDaA][0-7]\)\([^[:alnum:]_]\)/\1'"$P"'\2\3/g 1681.8Sapb s/\([^[:alnum:]_%]\)\([fF][pP][0-7]\)\([^[:alnum:]_]\)/\1'"$P"'\2\3/g 1691.8Sapb s/\([^[:alnum:]_%]\)\(sp\)\([^[:alnum:]_]\)/\1'"$P"'\2\3/g 1701.8Sapb s/\([^[:alnum:]_%]\)\(pc\)\([^[:alnum:]_]\)/\1'"$P"'\2\3/g 1711.8Sapb 1721.8Sapb s/\([^[:alnum:]_%]\)\([dDaA][0-7]\)$/\1'"$P"'\2/g 1731.8Sapb s/\([^[:alnum:]_%]\)\([dDaA][0-7]\)$/\1'"$P"'\2/g 1741.8Sapb s/\([^[:alnum:]_%]\)\([fF][pP][0-7]\)$/\1'"$P"'\2/g 1751.8Sapb s/\([^[:alnum:]_%]\)\(sp\)$/\1'"$P"'\2/g 1761.8Sapb 1771.8Sapb s/\(,\)\([dDaA][0-7]\)/\1'"$P"'\2/g 1781.8Sapb s/\(,\)\([fF][pP][0-7]\)/\1'"$P"'\2/g 1791.8Sapb 1801.8Sapb # "-(%sp)" -> "%sp@-", etc. (possibly without the "%") 1811.8Sapb s/-(\('"$P"'[sSpPaA][pPcC0-7]\))/\1@-/g 1821.8Sapb # "(%sp)+" -> "%sp@+", etc. (possibly without the "%") 1831.8Sapb s/(\('"$P"'[sSpPaA][pPcC0-7]\))+/\1@+/g 1841.8Sapb # "foo(%sp,...)" -> "%sp@(foo,...)", etc. (possibly without the "%") 1851.8Sapb s/\([-+A-Za-z0-9_]*\)(\('"$P"'[sSpPaA][pPcC0-7]\)\([),]\)/\2@(\1\3/g 1861.1Smycroft 1871.8Sapb # ".w" -> ":w"; ".w*nn" -> ":w:nn"; "*nn" -> ":l:nn"; etc. 1881.1Smycroft s/\.\([bBwWlL])\)/:\1/g 1891.1Smycroft s/\.\([bBwWlL]\)\*\([0-9][0-9]*)\)/:\1:\2/g 1901.1Smycroft s/\*\([0-9][0-9]*\))/:l:\1)/g 1911.8Sapb # "{nn:mm}" -> "{#nn:#mm}" 1921.1Smycroft s/{\([0-9][0-9]*\):\([0-9][0-9]*\)}/{#\1:#\2}/g 1931.8Sapb # "{%d0:nn}" -> "{%d0:#nn}", etc. (possibly without the "%") 1941.8Sapb s/{\('"$P"'[dD][0-7]\):\([0-9][0-9]*\)}/{\1:#\2}/g 1951.1Smycroft 1961.8Sapb # Remove empty "()" or "(0)" after "@" 1971.2Smycroft s/@(0*)/@/g 1981.8Sapb # Remove leading "," or trailing ":" in parentheses 1991.1Smycroft s/(,/(/g;s/:)/)/g 2001.1Smycroft 2011.1Smycroft # make up for a gas bug 2021.1Smycroft /^ fmovemx /{ 2031.8Sapb s/ \('"$P"'[fF][pP][0-7]\),/ \1-\1,/ 2041.8Sapb s/,\('"$P"'[fF][pP][0-7]\) /,\1-\1 / 2051.8Sapb s/,\('"$P"'[fF][pP][0-7]\)$/,\1-\1/ 2061.1Smycroft } 2071.1Smycroft' 208