asm2gas revision 1.1
11.1Smycroft#!/bin/sh
21.1Smycroft
31.1Smycroft#
41.1Smycroft# Copyright (c) 1994 Charles Hannum.  All rights reserved.
51.1Smycroft#
61.1Smycroft# Redistribution and use in source and binary forms, with or without
71.1Smycroft# modification, are permitted provided that the following conditions
81.1Smycroft# are met:
91.1Smycroft# 1. Redistributions of source code must retain the above copyright
101.1Smycroft#    notice, this list of conditions and the following disclaimer.
111.1Smycroft# 2. Redistributions in binary form must reproduce the above copyright
121.1Smycroft#    notice, this list of conditions and the following disclaimer in the
131.1Smycroft#    documentation and/or other materials provided with the distribution.
141.1Smycroft# 3. All advertising materials mentioning features or use of this software
151.1Smycroft#    must display the following acknowledgement:
161.1Smycroft#	This product includes software developed by Charles Hannum.
171.1Smycroft# 4. The name of the author may not be used to endorse or promote products
181.1Smycroft#    derived from this software without specific prior written permission.
191.1Smycroft#
201.1Smycroft# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
211.1Smycroft# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
221.1Smycroft# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
231.1Smycroft# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
241.1Smycroft# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
251.1Smycroft# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
261.1Smycroft# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
271.1Smycroft# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
281.1Smycroft# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
291.1Smycroft# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
301.1Smycroft#
311.1Smycroft#	$Id: asm2gas,v 1.1 1994/07/05 17:57:04 mycroft Exp $
321.1Smycroft#
331.1Smycroft
341.1Smycroft# This ugly script converts assembler code from Motorola's format to a
351.1Smycroft# form that gas (MIT syntax) can digest.
361.1Smycroft
371.1Smycroftcat $1 | sed -e '
381.1Smycroft  /[ 	]IDNT[ 	]/{s/^/|/;p;d;}
391.1Smycroft  /^\*/{p;d;}
401.1Smycroft  s/;/|/
411.1Smycroft  /[ 	]equ[ 	]/{
421.1Smycroft    s/\([A-Za-z_][A-Za-z0-9_]*\)[ 	]*equ[ 	]*/\1,/
431.1Smycroft    s/[ 	][ 	]*\(.*\)$/		|\1/
441.1Smycroft    s/		||/		|/
451.1Smycroft    s/^/	.set	/
461.1Smycroft    p;d
471.1Smycroft  }
481.1Smycroft  s/^\([A-Za-z_][A-Za-z0-9_]*\)[ 	][ 	]*/\1:	/
491.1Smycroft  s/^\([A-Za-z_][A-Za-z0-9_]*\)$/\1:/
501.1Smycroft  /^[A-Za-z_][A-Za-z0-9_]*:/{
511.1Smycroft    h
521.1Smycroft    s/:.*$/:/
531.1Smycroft    p
541.1Smycroft    g
551.1Smycroft    s/^.*:[ 	]*/	/
561.1Smycroft    /^	$/d
571.1Smycroft  }
581.1Smycroft  /^[ 	][ 	]*[.a-zA-Z][.a-zA-Z0-9]*/{
591.1Smycroft    h
601.1Smycroft    s/[ 	]*[.a-zA-Z][.a-zA-Z0-9]*[ 	]*//
611.1Smycroft    s/[ 	][ 	]*\(.*\)$/		|\1/
621.1Smycroft    s/		||/		|/
631.1Smycroft    x
641.1Smycroft    s/^[ 	]*\([.a-zA-Z][.a-zA-Z0-9]*\)/\1/
651.1Smycroft    s/[ 	][ 	]*.*$/	/
661.1Smycroft    y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/
671.1Smycroft    s/^/	/
681.1Smycroft    G
691.1Smycroft    s/\n//
701.1Smycroft  }
711.1Smycroft' | sed -e '
721.1Smycroft  s/^\*/|/
731.1Smycroft  s/\$/0x/g
741.1Smycroft  s/#:/#0x/g
751.1Smycroft  s/	dc\.l/	.long/
761.1Smycroft  s/	dc\.w/	.short/
771.1Smycroft  s/	dc\.b/	.byte/
781.1Smycroft' | sed -e '
791.1Smycroft  s/\([^_a-zA-Z0-9]\)A\([0-7]\)\([^_a-zA-Z0-9:.]\)/\1a\2\3/g
801.1Smycroft  s/\([^_a-zA-Z0-9]\)A\([0-7]\)\([^_a-zA-Z0-9:.]\)/\1a\2\3/g
811.1Smycroft  s/\([^_a-zA-Z0-9]\)A\([0-7]\)$/\1a\2/g
821.1Smycroft  s/\([^_a-zA-Z0-9]\)D\([0-7]\)\([^_a-zA-Z0-9]\)/\1d\2\3/g
831.1Smycroft  s/\([^_a-zA-Z0-9]\)D\([0-7]\)\([^_a-zA-Z0-9]\)/\1d\2\3/g
841.1Smycroft  s/\([^_a-zA-Z0-9]\)D\([0-7]\)$/\1d\2/g
851.1Smycroft  s/\([^_a-zA-Z0-9]\)FP\([0-7]\)\([^_a-zA-Z0-9]\)/\1fp\2\3/g
861.1Smycroft  s/\([^_a-zA-Z0-9]\)FP\([0-7]\)\([^_a-zA-Z0-9]\)/\1fp\2\3/g
871.1Smycroft  s/\([^_a-zA-Z0-9]\)FP\([0-7]\)$/\1fp\2/g
881.1Smycroft  s/\([^_a-zA-Z0-9]\)FPCR\([^_a-zA-Z0-9]\)/\1fpcr\2/g
891.1Smycroft  s/\([^_a-zA-Z0-9]\)FPCR\([^_a-zA-Z0-9]\)/\1fpcr\2/g
901.1Smycroft  s/\([^_a-zA-Z0-9]\)FPCR$/\1fpcr/g
911.1Smycroft  s/\([^_a-zA-Z0-9]\)FPSR\([^_a-zA-Z0-9]\)/\1fpsr\2/g
921.1Smycroft  s/\([^_a-zA-Z0-9]\)FPSR\([^_a-zA-Z0-9]\)/\1fpsr\2/g
931.1Smycroft  s/\([^_a-zA-Z0-9]\)FPSR$/\1fpsr/g
941.1Smycroft  s/\([^_a-zA-Z0-9]\)FPIAR\([^_a-zA-Z0-9]\)/\1fpi\2/g
951.1Smycroft  s/\([^_a-zA-Z0-9]\)FPIAR\([^_a-zA-Z0-9]\)/\1fpi\2/g
961.1Smycroft  s/\([^_a-zA-Z0-9]\)FPIAR$/\1fpi/g
971.1Smycroft  s/\([^_a-zA-Z0-9]\)fpiar\([^_a-zA-Z0-9]\)/\1fpi\2/g
981.1Smycroft  s/\([^_a-zA-Z0-9]\)fpiar\([^_a-zA-Z0-9]\)/\1fpi\2/g
991.1Smycroft  s/\([^_a-zA-Z0-9]\)fpiar$/\1fpi/g
1001.1Smycroft  s/\([^_a-zA-Z0-9]\)a7\([^_a-zA-Z0-9:.]\)/\1sp\2/g
1011.1Smycroft  s/\([^_a-zA-Z0-9]\)a7\([^_a-zA-Z0-9:.]\)/\1sp\2/g
1021.1Smycroft  s/\([^_a-zA-Z0-9]\)a7$/\1sp/g
1031.1Smycroft' | sed -e '
1041.1Smycroft  s/-(\(a.\))/\1@-/g
1051.1Smycroft  s/(\(a.\))+/\1@+/g
1061.1Smycroft  s/\([-+A-Za-z0-9_]*\)(\(a.\))/\2@(\1)/g
1071.1Smycroft  s/\([-+A-Za-z0-9_]*\)(\(a.\),\([ad].[^)]*\))/\2@(\1,\3)/g
1081.1Smycroft
1091.1Smycroft  s/-(sp)/sp@-/g
1101.1Smycroft  s/(sp)+/sp@+/g
1111.1Smycroft  s/\([-+A-Za-z0-9_]*\)(sp)/sp@(\1)/g
1121.1Smycroft  s/\([-+A-Za-z0-9_]*\)(sp,\([ad].[^)]*\))/sp@(\1,\2)/g
1131.1Smycroft
1141.1Smycroft  s/-(pc)/pc@-/g
1151.1Smycroft  s/(pc)+/pc@+/g
1161.1Smycroft  s/\([-+A-Za-z0-9_]*\)(pc)/pc@(\1)/g
1171.1Smycroft  s/\([-+A-Za-z0-9_]*\)(pc,\([ad].[^)]*\))/pc@(\1,\2)/g
1181.1Smycroft
1191.1Smycroft  s/\.\([bBwWlL])\)/:\1/g
1201.1Smycroft  s/\.\([bBwWlL]\)\*\([0-9][0-9]*)\)/:\1:\2/g
1211.1Smycroft  s/\*\([0-9][0-9]*\))/:l:\1)/g
1221.1Smycroft  s/{\([0-9][0-9]*\):\([0-9][0-9]*\)}/{#\1:#\2}/g
1231.1Smycroft  s/{\(d[0-7]\):\([0-9][0-9]*\)}/{\1:#\2}/g
1241.1Smycroft
1251.1Smycroft  s/@()/@/g;s/@(0)/@/g
1261.1Smycroft  s/(,/(/g;s/:)/)/g
1271.1Smycroft
1281.1Smycroft  s/^	section	7/	.text/
1291.1Smycroft  s/^	section	8/	.text/
1301.1Smycroft  s/^	section	15/	.data/
1311.1Smycroft  /^	include/{s/include[ 	]/.include "/;s/\.h[ 	]*$/.defs"/;p;d;}
1321.1Smycroft  s/^	xref/|	xref/
1331.1Smycroft  s/^	end/|	end/
1341.1Smycroft  s/^	xdef/	.global/
1351.1Smycroft
1361.1Smycroft  s/^	lea\.l	/	lea	/
1371.1Smycroft  s/^	swap\.w	/	swap	/
1381.1Smycroft  s/^	adda\.l	/	addal	/
1391.1Smycroft  s/^	suba\.l	/	subal	/
1401.1Smycroft  s/^	movea\.l	/	moveal	/
1411.1Smycroft  s/^	btst\.[bl]	/	btst	/
1421.1Smycroft  s/^	bclr\.[bl]	/	bclr	/
1431.1Smycroft  s/^	bset\.[bl]	/	bset	/
1441.1Smycroft  s/^	bchg\.[bl]	/	bchg	/
1451.1Smycroft  s/^	clr\.\([lbw]\)	/	clr\1	/
1461.1Smycroft  s/^	tst\.\([lbw]\)	/	tst\1	/
1471.1Smycroft  s/^	neg\.\([lbw]\)	/	neg\1	/
1481.1Smycroft  s/^	or\(i*\)\.\([lbw]\)	/	or\1\2	/
1491.1Smycroft  s/^	eor\(i*\)\.\([lbw]\)	/	eor\1\2	/
1501.1Smycroft  s/^	and\(i*\)\.\([lbw]\)	/	and\1\2	/
1511.1Smycroft  s/^	mul\([su]\)\.\([lw]\)	/	mul\1\2	/
1521.1Smycroft  s/^	div\([sul]*\)\.\([lw]\)	/	div\1\2	/
1531.1Smycroft  s/^	cmp\([i2]*\)\.\([lbw]\)	/	cmp\1\2	/
1541.1Smycroft  s/^	ro\([xlr]*\)\.\([lbw]\)	/	ro\1\2	/
1551.1Smycroft  s/^	\([al]\)s\([lr]\)\.\([lbw]\)	/	\1s\2\3	/
1561.1Smycroft  s/^	add\([xiq]*\)\.\([lbw]\)	/	add\1\2	/
1571.1Smycroft  s/^	sub\([xiq]*\)\.\([lbw]\)	/	sub\1\2	/
1581.1Smycroft  s/^	move\([scmq]*\)\.\([lbw]\)	/	move\1\2	/
1591.1Smycroft  s/^	fabs\.\([sdx]\)	/	fabs\1	/
1601.1Smycroft  s/^	fneg\.\([sdx]\)	/	fneg\1	/
1611.1Smycroft  s/^	ftst\.\([sdx]\)	/	ftst\1	/
1621.1Smycroft  s/^	fmul\.\([sdx]\)	/	fmul\1	/
1631.1Smycroft  s/^	fdiv\.\([sdx]\)	/	fdiv\1	/
1641.1Smycroft  s/^	fsqrt\.\([sdx]\)	/	fsqrt\1	/
1651.1Smycroft  s/^	fadd\.\([sdxbwl]\)	/	fadd\1	/
1661.1Smycroft  s/^	fsub\.\([sdxbwl]\)	/	fsub\1	/
1671.1Smycroft  s/^	fcmp\.\([sdxbwl]\)	/	fcmp\1	/
1681.1Smycroft  s/^	fmove\([mx]*\)\.\([sdxbwl]\)	/	fmove\1\2	/
1691.1Smycroft
1701.1Smycroft  # fix an odd instruction
1711.1Smycroft  s/^	bhs\.w	/	bcc	/
1721.1Smycroft
1731.1Smycroft  # set and branch instructions; questionable
1741.1Smycroft  s/^	s\([a-z][a-z]*\)\.b	/	s\1	/
1751.1Smycroft  s/^	db\([a-z][a-z]*\)\.w	/	db\1	/
1761.1Smycroft  s/^	b\([a-eg-z][a-z]*\)\.b	/	b\1s	/
1771.1Smycroft  s/^	b\([a-eg-z][a-z]*\)\.w	/	b\1	/
1781.1Smycroft  s/^	b\([a-eg-z][a-z]*\)\.l	/	b\1l	/
1791.1Smycroft  s/^	fb\([a-eg-z][a-z]*\)\.w	/	fb\1	/
1801.1Smycroft  s/^	fb\([a-eg-z][a-z]*\)\.l	/	fb\1l	/
1811.1Smycroft
1821.1Smycroft  # make up for a gas bug
1831.1Smycroft  /^	fmovemx	/{
1841.1Smycroft	s/	fp\([0-7]\),/	fp\1-fp\1,/
1851.1Smycroft	s/,fp\([0-7]\)	/,fp\1-fp\1	/
1861.1Smycroft	s/,fp\([0-7]\)$/,fp\1-fp\1/
1871.1Smycroft  }
1881.1Smycroft'
189