Home | History | Annotate | Line # | Download | only in 060sp
asm2gas revision 1.1
      1  1.1  mycroft #!/bin/sh
      2  1.1  mycroft 
      3  1.1  mycroft #
      4  1.1  mycroft # Copyright (c) 1994 Charles Hannum.  All rights reserved.
      5  1.1  mycroft #
      6  1.1  mycroft # Redistribution and use in source and binary forms, with or without
      7  1.1  mycroft # modification, are permitted provided that the following conditions
      8  1.1  mycroft # are met:
      9  1.1  mycroft # 1. Redistributions of source code must retain the above copyright
     10  1.1  mycroft #    notice, this list of conditions and the following disclaimer.
     11  1.1  mycroft # 2. Redistributions in binary form must reproduce the above copyright
     12  1.1  mycroft #    notice, this list of conditions and the following disclaimer in the
     13  1.1  mycroft #    documentation and/or other materials provided with the distribution.
     14  1.1  mycroft # 3. All advertising materials mentioning features or use of this software
     15  1.1  mycroft #    must display the following acknowledgement:
     16  1.1  mycroft #	This product includes software developed by Charles Hannum.
     17  1.1  mycroft # 4. The name of the author may not be used to endorse or promote products
     18  1.1  mycroft #    derived from this software without specific prior written permission.
     19  1.1  mycroft #
     20  1.1  mycroft # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     21  1.1  mycroft # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     22  1.1  mycroft # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23  1.1  mycroft # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     24  1.1  mycroft # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     25  1.1  mycroft # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26  1.1  mycroft # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27  1.1  mycroft # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28  1.1  mycroft # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29  1.1  mycroft # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30  1.1  mycroft #
     31  1.1  mycroft #	$Id: asm2gas,v 1.1 1994/07/05 17:57:04 mycroft Exp $
     32  1.1  mycroft #
     33  1.1  mycroft 
     34  1.1  mycroft # This ugly script converts assembler code from Motorola's format to a
     35  1.1  mycroft # form that gas (MIT syntax) can digest.
     36  1.1  mycroft 
     37  1.1  mycroft cat $1 | sed -e '
     38  1.1  mycroft   /[ 	]IDNT[ 	]/{s/^/|/;p;d;}
     39  1.1  mycroft   /^\*/{p;d;}
     40  1.1  mycroft   s/;/|/
     41  1.1  mycroft   /[ 	]equ[ 	]/{
     42  1.1  mycroft     s/\([A-Za-z_][A-Za-z0-9_]*\)[ 	]*equ[ 	]*/\1,/
     43  1.1  mycroft     s/[ 	][ 	]*\(.*\)$/		|\1/
     44  1.1  mycroft     s/		||/		|/
     45  1.1  mycroft     s/^/	.set	/
     46  1.1  mycroft     p;d
     47  1.1  mycroft   }
     48  1.1  mycroft   s/^\([A-Za-z_][A-Za-z0-9_]*\)[ 	][ 	]*/\1:	/
     49  1.1  mycroft   s/^\([A-Za-z_][A-Za-z0-9_]*\)$/\1:/
     50  1.1  mycroft   /^[A-Za-z_][A-Za-z0-9_]*:/{
     51  1.1  mycroft     h
     52  1.1  mycroft     s/:.*$/:/
     53  1.1  mycroft     p
     54  1.1  mycroft     g
     55  1.1  mycroft     s/^.*:[ 	]*/	/
     56  1.1  mycroft     /^	$/d
     57  1.1  mycroft   }
     58  1.1  mycroft   /^[ 	][ 	]*[.a-zA-Z][.a-zA-Z0-9]*/{
     59  1.1  mycroft     h
     60  1.1  mycroft     s/[ 	]*[.a-zA-Z][.a-zA-Z0-9]*[ 	]*//
     61  1.1  mycroft     s/[ 	][ 	]*\(.*\)$/		|\1/
     62  1.1  mycroft     s/		||/		|/
     63  1.1  mycroft     x
     64  1.1  mycroft     s/^[ 	]*\([.a-zA-Z][.a-zA-Z0-9]*\)/\1/
     65  1.1  mycroft     s/[ 	][ 	]*.*$/	/
     66  1.1  mycroft     y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/
     67  1.1  mycroft     s/^/	/
     68  1.1  mycroft     G
     69  1.1  mycroft     s/\n//
     70  1.1  mycroft   }
     71  1.1  mycroft ' | sed -e '
     72  1.1  mycroft   s/^\*/|/
     73  1.1  mycroft   s/\$/0x/g
     74  1.1  mycroft   s/#:/#0x/g
     75  1.1  mycroft   s/	dc\.l/	.long/
     76  1.1  mycroft   s/	dc\.w/	.short/
     77  1.1  mycroft   s/	dc\.b/	.byte/
     78  1.1  mycroft ' | sed -e '
     79  1.1  mycroft   s/\([^_a-zA-Z0-9]\)A\([0-7]\)\([^_a-zA-Z0-9:.]\)/\1a\2\3/g
     80  1.1  mycroft   s/\([^_a-zA-Z0-9]\)A\([0-7]\)\([^_a-zA-Z0-9:.]\)/\1a\2\3/g
     81  1.1  mycroft   s/\([^_a-zA-Z0-9]\)A\([0-7]\)$/\1a\2/g
     82  1.1  mycroft   s/\([^_a-zA-Z0-9]\)D\([0-7]\)\([^_a-zA-Z0-9]\)/\1d\2\3/g
     83  1.1  mycroft   s/\([^_a-zA-Z0-9]\)D\([0-7]\)\([^_a-zA-Z0-9]\)/\1d\2\3/g
     84  1.1  mycroft   s/\([^_a-zA-Z0-9]\)D\([0-7]\)$/\1d\2/g
     85  1.1  mycroft   s/\([^_a-zA-Z0-9]\)FP\([0-7]\)\([^_a-zA-Z0-9]\)/\1fp\2\3/g
     86  1.1  mycroft   s/\([^_a-zA-Z0-9]\)FP\([0-7]\)\([^_a-zA-Z0-9]\)/\1fp\2\3/g
     87  1.1  mycroft   s/\([^_a-zA-Z0-9]\)FP\([0-7]\)$/\1fp\2/g
     88  1.1  mycroft   s/\([^_a-zA-Z0-9]\)FPCR\([^_a-zA-Z0-9]\)/\1fpcr\2/g
     89  1.1  mycroft   s/\([^_a-zA-Z0-9]\)FPCR\([^_a-zA-Z0-9]\)/\1fpcr\2/g
     90  1.1  mycroft   s/\([^_a-zA-Z0-9]\)FPCR$/\1fpcr/g
     91  1.1  mycroft   s/\([^_a-zA-Z0-9]\)FPSR\([^_a-zA-Z0-9]\)/\1fpsr\2/g
     92  1.1  mycroft   s/\([^_a-zA-Z0-9]\)FPSR\([^_a-zA-Z0-9]\)/\1fpsr\2/g
     93  1.1  mycroft   s/\([^_a-zA-Z0-9]\)FPSR$/\1fpsr/g
     94  1.1  mycroft   s/\([^_a-zA-Z0-9]\)FPIAR\([^_a-zA-Z0-9]\)/\1fpi\2/g
     95  1.1  mycroft   s/\([^_a-zA-Z0-9]\)FPIAR\([^_a-zA-Z0-9]\)/\1fpi\2/g
     96  1.1  mycroft   s/\([^_a-zA-Z0-9]\)FPIAR$/\1fpi/g
     97  1.1  mycroft   s/\([^_a-zA-Z0-9]\)fpiar\([^_a-zA-Z0-9]\)/\1fpi\2/g
     98  1.1  mycroft   s/\([^_a-zA-Z0-9]\)fpiar\([^_a-zA-Z0-9]\)/\1fpi\2/g
     99  1.1  mycroft   s/\([^_a-zA-Z0-9]\)fpiar$/\1fpi/g
    100  1.1  mycroft   s/\([^_a-zA-Z0-9]\)a7\([^_a-zA-Z0-9:.]\)/\1sp\2/g
    101  1.1  mycroft   s/\([^_a-zA-Z0-9]\)a7\([^_a-zA-Z0-9:.]\)/\1sp\2/g
    102  1.1  mycroft   s/\([^_a-zA-Z0-9]\)a7$/\1sp/g
    103  1.1  mycroft ' | sed -e '
    104  1.1  mycroft   s/-(\(a.\))/\1@-/g
    105  1.1  mycroft   s/(\(a.\))+/\1@+/g
    106  1.1  mycroft   s/\([-+A-Za-z0-9_]*\)(\(a.\))/\2@(\1)/g
    107  1.1  mycroft   s/\([-+A-Za-z0-9_]*\)(\(a.\),\([ad].[^)]*\))/\2@(\1,\3)/g
    108  1.1  mycroft 
    109  1.1  mycroft   s/-(sp)/sp@-/g
    110  1.1  mycroft   s/(sp)+/sp@+/g
    111  1.1  mycroft   s/\([-+A-Za-z0-9_]*\)(sp)/sp@(\1)/g
    112  1.1  mycroft   s/\([-+A-Za-z0-9_]*\)(sp,\([ad].[^)]*\))/sp@(\1,\2)/g
    113  1.1  mycroft 
    114  1.1  mycroft   s/-(pc)/pc@-/g
    115  1.1  mycroft   s/(pc)+/pc@+/g
    116  1.1  mycroft   s/\([-+A-Za-z0-9_]*\)(pc)/pc@(\1)/g
    117  1.1  mycroft   s/\([-+A-Za-z0-9_]*\)(pc,\([ad].[^)]*\))/pc@(\1,\2)/g
    118  1.1  mycroft 
    119  1.1  mycroft   s/\.\([bBwWlL])\)/:\1/g
    120  1.1  mycroft   s/\.\([bBwWlL]\)\*\([0-9][0-9]*)\)/:\1:\2/g
    121  1.1  mycroft   s/\*\([0-9][0-9]*\))/:l:\1)/g
    122  1.1  mycroft   s/{\([0-9][0-9]*\):\([0-9][0-9]*\)}/{#\1:#\2}/g
    123  1.1  mycroft   s/{\(d[0-7]\):\([0-9][0-9]*\)}/{\1:#\2}/g
    124  1.1  mycroft 
    125  1.1  mycroft   s/@()/@/g;s/@(0)/@/g
    126  1.1  mycroft   s/(,/(/g;s/:)/)/g
    127  1.1  mycroft 
    128  1.1  mycroft   s/^	section	7/	.text/
    129  1.1  mycroft   s/^	section	8/	.text/
    130  1.1  mycroft   s/^	section	15/	.data/
    131  1.1  mycroft   /^	include/{s/include[ 	]/.include "/;s/\.h[ 	]*$/.defs"/;p;d;}
    132  1.1  mycroft   s/^	xref/|	xref/
    133  1.1  mycroft   s/^	end/|	end/
    134  1.1  mycroft   s/^	xdef/	.global/
    135  1.1  mycroft 
    136  1.1  mycroft   s/^	lea\.l	/	lea	/
    137  1.1  mycroft   s/^	swap\.w	/	swap	/
    138  1.1  mycroft   s/^	adda\.l	/	addal	/
    139  1.1  mycroft   s/^	suba\.l	/	subal	/
    140  1.1  mycroft   s/^	movea\.l	/	moveal	/
    141  1.1  mycroft   s/^	btst\.[bl]	/	btst	/
    142  1.1  mycroft   s/^	bclr\.[bl]	/	bclr	/
    143  1.1  mycroft   s/^	bset\.[bl]	/	bset	/
    144  1.1  mycroft   s/^	bchg\.[bl]	/	bchg	/
    145  1.1  mycroft   s/^	clr\.\([lbw]\)	/	clr\1	/
    146  1.1  mycroft   s/^	tst\.\([lbw]\)	/	tst\1	/
    147  1.1  mycroft   s/^	neg\.\([lbw]\)	/	neg\1	/
    148  1.1  mycroft   s/^	or\(i*\)\.\([lbw]\)	/	or\1\2	/
    149  1.1  mycroft   s/^	eor\(i*\)\.\([lbw]\)	/	eor\1\2	/
    150  1.1  mycroft   s/^	and\(i*\)\.\([lbw]\)	/	and\1\2	/
    151  1.1  mycroft   s/^	mul\([su]\)\.\([lw]\)	/	mul\1\2	/
    152  1.1  mycroft   s/^	div\([sul]*\)\.\([lw]\)	/	div\1\2	/
    153  1.1  mycroft   s/^	cmp\([i2]*\)\.\([lbw]\)	/	cmp\1\2	/
    154  1.1  mycroft   s/^	ro\([xlr]*\)\.\([lbw]\)	/	ro\1\2	/
    155  1.1  mycroft   s/^	\([al]\)s\([lr]\)\.\([lbw]\)	/	\1s\2\3	/
    156  1.1  mycroft   s/^	add\([xiq]*\)\.\([lbw]\)	/	add\1\2	/
    157  1.1  mycroft   s/^	sub\([xiq]*\)\.\([lbw]\)	/	sub\1\2	/
    158  1.1  mycroft   s/^	move\([scmq]*\)\.\([lbw]\)	/	move\1\2	/
    159  1.1  mycroft   s/^	fabs\.\([sdx]\)	/	fabs\1	/
    160  1.1  mycroft   s/^	fneg\.\([sdx]\)	/	fneg\1	/
    161  1.1  mycroft   s/^	ftst\.\([sdx]\)	/	ftst\1	/
    162  1.1  mycroft   s/^	fmul\.\([sdx]\)	/	fmul\1	/
    163  1.1  mycroft   s/^	fdiv\.\([sdx]\)	/	fdiv\1	/
    164  1.1  mycroft   s/^	fsqrt\.\([sdx]\)	/	fsqrt\1	/
    165  1.1  mycroft   s/^	fadd\.\([sdxbwl]\)	/	fadd\1	/
    166  1.1  mycroft   s/^	fsub\.\([sdxbwl]\)	/	fsub\1	/
    167  1.1  mycroft   s/^	fcmp\.\([sdxbwl]\)	/	fcmp\1	/
    168  1.1  mycroft   s/^	fmove\([mx]*\)\.\([sdxbwl]\)	/	fmove\1\2	/
    169  1.1  mycroft 
    170  1.1  mycroft   # fix an odd instruction
    171  1.1  mycroft   s/^	bhs\.w	/	bcc	/
    172  1.1  mycroft 
    173  1.1  mycroft   # set and branch instructions; questionable
    174  1.1  mycroft   s/^	s\([a-z][a-z]*\)\.b	/	s\1	/
    175  1.1  mycroft   s/^	db\([a-z][a-z]*\)\.w	/	db\1	/
    176  1.1  mycroft   s/^	b\([a-eg-z][a-z]*\)\.b	/	b\1s	/
    177  1.1  mycroft   s/^	b\([a-eg-z][a-z]*\)\.w	/	b\1	/
    178  1.1  mycroft   s/^	b\([a-eg-z][a-z]*\)\.l	/	b\1l	/
    179  1.1  mycroft   s/^	fb\([a-eg-z][a-z]*\)\.w	/	fb\1	/
    180  1.1  mycroft   s/^	fb\([a-eg-z][a-z]*\)\.l	/	fb\1l	/
    181  1.1  mycroft 
    182  1.1  mycroft   # make up for a gas bug
    183  1.1  mycroft   /^	fmovemx	/{
    184  1.1  mycroft 	s/	fp\([0-7]\),/	fp\1-fp\1,/
    185  1.1  mycroft 	s/,fp\([0-7]\)	/,fp\1-fp\1	/
    186  1.1  mycroft 	s/,fp\([0-7]\)$/,fp\1-fp\1/
    187  1.1  mycroft   }
    188  1.1  mycroft '
    189