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