asm2gas revision 1.7
11.1Smycroft#!/bin/sh
21.7Sapb#	$NetBSD: asm2gas,v 1.7 2008/03/27 07:15:16 apb Exp $
31.1Smycroft
41.1Smycroft#
51.6Smycroft# Copyright (c) 1998 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# 3. All advertising materials mentioning features or use of this software
201.1Smycroft#    must display the following acknowledgement:
211.6Smycroft#        This product includes software developed by the NetBSD
221.6Smycroft#        Foundation, Inc. and its contributors.
231.6Smycroft# 4. Neither the name of The NetBSD Foundation nor the names of its
241.6Smycroft#    contributors may be used to endorse or promote products derived
251.6Smycroft#    from this software without specific prior written permission.
261.1Smycroft#
271.6Smycroft# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
281.6Smycroft# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
291.6Smycroft# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
301.6Smycroft# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
311.6Smycroft# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
321.6Smycroft# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
331.6Smycroft# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
341.6Smycroft# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
351.6Smycroft# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
361.6Smycroft# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
371.6Smycroft# 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.7Sapb: ${TOOL_SED:=sed}
441.7Sapb
451.7Sapbcat "$1" | "${TOOL_SED}" -e '
461.2Smycroft  # format canonicalization
471.2Smycroft
481.4Sis  s/^#/|#/
491.1Smycroft  /[ 	]IDNT[ 	]/{s/^/|/;p;d;}
501.2Smycroft  /^\*/{s//|/;p;d;}
511.1Smycroft  s/;/|/
521.1Smycroft  /[ 	]equ[ 	]/{
531.1Smycroft    s/\([A-Za-z_][A-Za-z0-9_]*\)[ 	]*equ[ 	]*/\1,/
541.1Smycroft    s/[ 	][ 	]*\(.*\)$/		|\1/
551.1Smycroft    s/		||/		|/
561.1Smycroft    s/^/	.set	/
571.1Smycroft    p;d
581.1Smycroft  }
591.1Smycroft  s/^\([A-Za-z_][A-Za-z0-9_]*\)[ 	][ 	]*/\1:	/
601.1Smycroft  s/^\([A-Za-z_][A-Za-z0-9_]*\)$/\1:/
611.1Smycroft  /^[A-Za-z_][A-Za-z0-9_]*:/{
621.1Smycroft    h
631.1Smycroft    s/:.*$/:/
641.1Smycroft    p
651.1Smycroft    g
661.1Smycroft    s/^.*:[ 	]*/	/
671.1Smycroft    /^	$/d
681.1Smycroft  }
691.2Smycroft  /^[ 	][ 	]*\([.a-zA-Z][.a-zA-Z0-9]*\)/{
701.1Smycroft    h
711.2Smycroft    s///
721.2Smycroft    s/^[ 	][ 	]*//
731.1Smycroft    s/[ 	][ 	]*\(.*\)$/		|\1/
741.1Smycroft    s/		||/		|/
751.1Smycroft    x
761.2Smycroft    s/^[ 	][ 	]*//
771.1Smycroft    s/[ 	][ 	]*.*$/	/
781.1Smycroft    y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/
791.1Smycroft    s/^/	/
801.1Smycroft    G
811.1Smycroft    s/\n//
821.1Smycroft  }
831.1Smycroft' | sed -e '
841.2Smycroft  # operator conversion
851.2Smycroft
861.2Smycroft  s/^	section	7/	.text/
871.2Smycroft  s/^	section	8/	.text/
881.2Smycroft  s/^	section	15/	.data/
891.2Smycroft  /^	include/{s/include[ 	]/.include "/;s/\.h[ 	]*$/.defs"/;p;d;}
901.2Smycroft  s/^	xref/|	xref/
911.2Smycroft  s/^	end/|	end/
921.2Smycroft  s/^	xdef/	.global/
931.2Smycroft
941.2Smycroft  s/^	dc\.l/	.long/
951.2Smycroft  s/^	dc\.w/	.short/
961.2Smycroft  s/^	dc\.b/	.byte/
971.2Smycroft
981.2Smycroft  /^	[aceg-z]/{
991.2Smycroft    /^	add[aiqx]*\.[bwl]	/{s/\.//;p;d;}
1001.2Smycroft    /^	andi*\.[bwl]	/{s/\.//;p;d;}
1011.2Smycroft    /^	as[lr]\.[bwl]	/{s/\.//;p;d;}
1021.2Smycroft    /^	clr\.[bwl]	/{s/\.//;p;d;}
1031.2Smycroft    /^	cmp[i2]*\.[bwl]	/{s/\.//;p;d;}
1041.2Smycroft    /^	eori*\.[bwl]	/{s/\.//;p;d;}
1051.2Smycroft    /^	lea\.l	/{s/\..//;p;d;}
1061.2Smycroft    /^	ls[lr]\.[bwl]	/{s/\.//;p;d;}
1071.2Smycroft    /^	move[acmqs]*\.[bwl]	/{s/\.//;p;d;}
1081.2Smycroft    /^	mul[su]\.[wl]	/{s/\.//;p;d;}
1091.2Smycroft    /^	neg\.[bwl]	/{s/\.//;p;d;}
1101.2Smycroft    /^	ori*\.[bwl]	/{s/\.//;p;d;}
1111.2Smycroft    /^	ro[lrx]*\.[bwl]	/{s/\.//;p;d;}
1121.2Smycroft    /^	sub[aiqx]*\.[bwl]	/{s/\.//;p;d;}
1131.2Smycroft    /^	swap\.w	/{s/\..//;p;d;}
1141.2Smycroft    /^	s\([a-tv-z][a-z]*\)\.b	/{s/\..//;p;d;}
1151.2Smycroft    /^	tst\.[bwl]	/{s/\.//;p;d;}
1161.2Smycroft    p;d
1171.2Smycroft  }
1181.2Smycroft
1191.2Smycroft  /^	bchg\.[bl]	/{s/\..//;p;d;}
1201.2Smycroft  /^	bclr\.[bl]	/{s/\..//;p;d;}
1211.2Smycroft  /^	bset\.[bl]	/{s/\..//;p;d;}
1221.2Smycroft  /^	btst\.[bl]	/{s/\..//;p;d;}
1231.2Smycroft  /^	div[sul]*\.[wl]	/{s/\.//;p;d;}
1241.2Smycroft  /^	fabs\.[sdx]	/{s/\.//;p;d;}
1251.2Smycroft  /^	fadd\.[sdxbwl]	/{s/\.//;p;d;}
1261.2Smycroft  /^	fcmp\.[sdxbwl]	/{s/\.//;p;d;}
1271.2Smycroft  /^	fdiv\.[sdx]	/{s/\.//;p;d;}
1281.2Smycroft  /^	fmove[mx]*\.[sdxbwl]	/{s/\.//;p;d;}
1291.2Smycroft  /^	fmul\.[sdx]	/{s/\.//;p;d;}
1301.2Smycroft  /^	fneg\.[sdx]	/{s/\.//;p;d;}
1311.2Smycroft  /^	fsqrt\.[sdx]	/{s/\.//;p;d;}
1321.2Smycroft  /^	fsub\.[sdxbwl]	/{s/\.//;p;d;}
1331.2Smycroft  /^	ftst\.[sdx]	/{s/\.//;p;d;}
1341.2Smycroft
1351.2Smycroft  /^	b[a-eg-z][a-z]*\.b	/{s/\.b/s/;p;d;}
1361.2Smycroft  /^	b[a-eg-z][a-z]*\.w	/{s/\.w//;p;d;}
1371.2Smycroft  /^	b[a-eg-z][a-z]*\.l	/{s/\.l/l/;p;d;}
1381.2Smycroft  /^	db[a-z][a-z]*\.w	/{s/\.w//;p;d;}
1391.2Smycroft  /^	fb[a-eg-z][a-z]*\.w	/{s/\.w//;p;d;}
1401.2Smycroft  /^	fb[a-eg-z][a-z]*\.l	/{s/\.l/l/;p;d;}
1411.1Smycroft' | sed -e '
1421.2Smycroft  # operand conversion
1431.2Smycroft
1441.2Smycroft  s/\([^_a-zA-Z0-9]\)FPIAR\([^_a-zA-Z0-9]\)/\1FPI\2/g
1451.2Smycroft  s/\([^_a-zA-Z0-9]\)FPIAR\([^_a-zA-Z0-9]\)/\1FPI\2/g
1461.2Smycroft  s/\([^_a-zA-Z0-9]\)FPIAR$/\1FPI/g
1471.1Smycroft  s/\([^_a-zA-Z0-9]\)fpiar\([^_a-zA-Z0-9]\)/\1fpi\2/g
1481.1Smycroft  s/\([^_a-zA-Z0-9]\)fpiar\([^_a-zA-Z0-9]\)/\1fpi\2/g
1491.1Smycroft  s/\([^_a-zA-Z0-9]\)fpiar$/\1fpi/g
1501.2Smycroft
1511.4Sis  s/\$\([0-9a-fA-F]\)/0x\1/g
1521.2Smycroft  s/#:/#:0x/g
1531.2Smycroft
1541.2Smycroft  s/-(\([sSpPaA][pPcC0-7]\))/\1@-/g
1551.2Smycroft  s/(\([sSpPaA][pPcC0-7]\))+/\1@+/g
1561.2Smycroft  s/\([-+A-Za-z0-9_]*\)(\([sSpPaA][pPcC0-7]\)\([),]\)/\2@(\1\3/g
1571.1Smycroft
1581.1Smycroft  s/\.\([bBwWlL])\)/:\1/g
1591.1Smycroft  s/\.\([bBwWlL]\)\*\([0-9][0-9]*)\)/:\1:\2/g
1601.1Smycroft  s/\*\([0-9][0-9]*\))/:l:\1)/g
1611.1Smycroft  s/{\([0-9][0-9]*\):\([0-9][0-9]*\)}/{#\1:#\2}/g
1621.2Smycroft  s/{\([dD][0-7]\):\([0-9][0-9]*\)}/{\1:#\2}/g
1631.1Smycroft
1641.2Smycroft  s/@(0*)/@/g
1651.1Smycroft  s/(,/(/g;s/:)/)/g
1661.1Smycroft
1671.1Smycroft  # make up for a gas bug
1681.1Smycroft  /^	fmovemx	/{
1691.2Smycroft	s/	\([fF][pP][0-7]\),/	\1-\1,/
1701.2Smycroft	s/,\([fF][pP][0-7]\)	/,\1-\1	/
1711.2Smycroft	s/,\([fF][pP][0-7]\)$/,\1-\1/
1721.1Smycroft  }
1731.1Smycroft'
174