asm2gas revision 1.2
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.2Smycroft#	$Id: asm2gas,v 1.2 1994/07/07 01:51:18 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.2Smycroft  # format canonicalization
391.2Smycroft
401.1Smycroft  /[ 	]IDNT[ 	]/{s/^/|/;p;d;}
411.2Smycroft  /^\*/{s//|/;p;d;}
421.1Smycroft  s/;/|/
431.1Smycroft  /[ 	]equ[ 	]/{
441.1Smycroft    s/\([A-Za-z_][A-Za-z0-9_]*\)[ 	]*equ[ 	]*/\1,/
451.1Smycroft    s/[ 	][ 	]*\(.*\)$/		|\1/
461.1Smycroft    s/		||/		|/
471.1Smycroft    s/^/	.set	/
481.1Smycroft    p;d
491.1Smycroft  }
501.1Smycroft  s/^\([A-Za-z_][A-Za-z0-9_]*\)[ 	][ 	]*/\1:	/
511.1Smycroft  s/^\([A-Za-z_][A-Za-z0-9_]*\)$/\1:/
521.1Smycroft  /^[A-Za-z_][A-Za-z0-9_]*:/{
531.1Smycroft    h
541.1Smycroft    s/:.*$/:/
551.1Smycroft    p
561.1Smycroft    g
571.1Smycroft    s/^.*:[ 	]*/	/
581.1Smycroft    /^	$/d
591.1Smycroft  }
601.2Smycroft  /^[ 	][ 	]*\([.a-zA-Z][.a-zA-Z0-9]*\)/{
611.1Smycroft    h
621.2Smycroft    s///
631.2Smycroft    s/^[ 	][ 	]*//
641.1Smycroft    s/[ 	][ 	]*\(.*\)$/		|\1/
651.1Smycroft    s/		||/		|/
661.1Smycroft    x
671.2Smycroft    s/^[ 	][ 	]*//
681.1Smycroft    s/[ 	][ 	]*.*$/	/
691.1Smycroft    y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/
701.1Smycroft    s/^/	/
711.1Smycroft    G
721.1Smycroft    s/\n//
731.1Smycroft  }
741.1Smycroft' | sed -e '
751.2Smycroft  # operator conversion
761.2Smycroft
771.2Smycroft  s/^	section	7/	.text/
781.2Smycroft  s/^	section	8/	.text/
791.2Smycroft  s/^	section	15/	.data/
801.2Smycroft  /^	include/{s/include[ 	]/.include "/;s/\.h[ 	]*$/.defs"/;p;d;}
811.2Smycroft  s/^	xref/|	xref/
821.2Smycroft  s/^	end/|	end/
831.2Smycroft  s/^	xdef/	.global/
841.2Smycroft
851.2Smycroft  s/^	dc\.l/	.long/
861.2Smycroft  s/^	dc\.w/	.short/
871.2Smycroft  s/^	dc\.b/	.byte/
881.2Smycroft
891.2Smycroft  /^	[aceg-z]/{
901.2Smycroft    /^	add[aiqx]*\.[bwl]	/{s/\.//;p;d;}
911.2Smycroft    /^	andi*\.[bwl]	/{s/\.//;p;d;}
921.2Smycroft    /^	as[lr]\.[bwl]	/{s/\.//;p;d;}
931.2Smycroft    /^	clr\.[bwl]	/{s/\.//;p;d;}
941.2Smycroft    /^	cmp[i2]*\.[bwl]	/{s/\.//;p;d;}
951.2Smycroft    /^	eori*\.[bwl]	/{s/\.//;p;d;}
961.2Smycroft    /^	lea\.l	/{s/\..//;p;d;}
971.2Smycroft    /^	ls[lr]\.[bwl]	/{s/\.//;p;d;}
981.2Smycroft    /^	move[acmqs]*\.[bwl]	/{s/\.//;p;d;}
991.2Smycroft    /^	mul[su]\.[wl]	/{s/\.//;p;d;}
1001.2Smycroft    /^	neg\.[bwl]	/{s/\.//;p;d;}
1011.2Smycroft    /^	ori*\.[bwl]	/{s/\.//;p;d;}
1021.2Smycroft    /^	ro[lrx]*\.[bwl]	/{s/\.//;p;d;}
1031.2Smycroft    /^	sub[aiqx]*\.[bwl]	/{s/\.//;p;d;}
1041.2Smycroft    /^	swap\.w	/{s/\..//;p;d;}
1051.2Smycroft    /^	s\([a-tv-z][a-z]*\)\.b	/{s/\..//;p;d;}
1061.2Smycroft    /^	tst\.[bwl]	/{s/\.//;p;d;}
1071.2Smycroft    p;d
1081.2Smycroft  }
1091.2Smycroft
1101.2Smycroft  /^	bchg\.[bl]	/{s/\..//;p;d;}
1111.2Smycroft  /^	bclr\.[bl]	/{s/\..//;p;d;}
1121.2Smycroft  /^	bset\.[bl]	/{s/\..//;p;d;}
1131.2Smycroft  /^	btst\.[bl]	/{s/\..//;p;d;}
1141.2Smycroft  /^	div[sul]*\.[wl]	/{s/\.//;p;d;}
1151.2Smycroft  /^	fabs\.[sdx]	/{s/\.//;p;d;}
1161.2Smycroft  /^	fadd\.[sdxbwl]	/{s/\.//;p;d;}
1171.2Smycroft  /^	fcmp\.[sdxbwl]	/{s/\.//;p;d;}
1181.2Smycroft  /^	fdiv\.[sdx]	/{s/\.//;p;d;}
1191.2Smycroft  /^	fmove[mx]*\.[sdxbwl]	/{s/\.//;p;d;}
1201.2Smycroft  /^	fmul\.[sdx]	/{s/\.//;p;d;}
1211.2Smycroft  /^	fneg\.[sdx]	/{s/\.//;p;d;}
1221.2Smycroft  /^	fsqrt\.[sdx]	/{s/\.//;p;d;}
1231.2Smycroft  /^	fsub\.[sdxbwl]	/{s/\.//;p;d;}
1241.2Smycroft  /^	ftst\.[sdx]	/{s/\.//;p;d;}
1251.2Smycroft
1261.2Smycroft  /^	b[a-eg-z][a-z]*\.b	/{s/\.b/s/;p;d;}
1271.2Smycroft  /^	b[a-eg-z][a-z]*\.w	/{s/\.w//;p;d;}
1281.2Smycroft  /^	b[a-eg-z][a-z]*\.l	/{s/\.l/l/;p;d;}
1291.2Smycroft  /^	db[a-z][a-z]*\.w	/{s/\.w//;p;d;}
1301.2Smycroft  /^	fb[a-eg-z][a-z]*\.w	/{s/\.w//;p;d;}
1311.2Smycroft  /^	fb[a-eg-z][a-z]*\.l	/{s/\.l/l/;p;d;}
1321.1Smycroft' | sed -e '
1331.2Smycroft  # operand conversion
1341.2Smycroft
1351.2Smycroft  s/\([^_a-zA-Z0-9]\)FPIAR\([^_a-zA-Z0-9]\)/\1FPI\2/g
1361.2Smycroft  s/\([^_a-zA-Z0-9]\)FPIAR\([^_a-zA-Z0-9]\)/\1FPI\2/g
1371.2Smycroft  s/\([^_a-zA-Z0-9]\)FPIAR$/\1FPI/g
1381.1Smycroft  s/\([^_a-zA-Z0-9]\)fpiar\([^_a-zA-Z0-9]\)/\1fpi\2/g
1391.1Smycroft  s/\([^_a-zA-Z0-9]\)fpiar\([^_a-zA-Z0-9]\)/\1fpi\2/g
1401.1Smycroft  s/\([^_a-zA-Z0-9]\)fpiar$/\1fpi/g
1411.2Smycroft
1421.2Smycroft  s/\$/0x/g
1431.2Smycroft  s/#:/#:0x/g
1441.2Smycroft
1451.2Smycroft  s/-(\([sSpPaA][pPcC0-7]\))/\1@-/g
1461.2Smycroft  s/(\([sSpPaA][pPcC0-7]\))+/\1@+/g
1471.2Smycroft  s/\([-+A-Za-z0-9_]*\)(\([sSpPaA][pPcC0-7]\)\([),]\)/\2@(\1\3/g
1481.1Smycroft
1491.1Smycroft  s/\.\([bBwWlL])\)/:\1/g
1501.1Smycroft  s/\.\([bBwWlL]\)\*\([0-9][0-9]*)\)/:\1:\2/g
1511.1Smycroft  s/\*\([0-9][0-9]*\))/:l:\1)/g
1521.1Smycroft  s/{\([0-9][0-9]*\):\([0-9][0-9]*\)}/{#\1:#\2}/g
1531.2Smycroft  s/{\([dD][0-7]\):\([0-9][0-9]*\)}/{\1:#\2}/g
1541.1Smycroft
1551.2Smycroft  s/@(0*)/@/g
1561.1Smycroft  s/(,/(/g;s/:)/)/g
1571.1Smycroft
1581.1Smycroft  # make up for a gas bug
1591.1Smycroft  /^	fmovemx	/{
1601.2Smycroft	s/	\([fF][pP][0-7]\),/	\1-\1,/
1611.2Smycroft	s/,\([fF][pP][0-7]\)	/,\1-\1	/
1621.2Smycroft	s/,\([fF][pP][0-7]\)$/,\1-\1/
1631.1Smycroft  }
1641.1Smycroft'
165