Home | History | Annotate | Line # | Download | only in fpsp
asm2gas revision 1.9
      1 #!/bin/sh
      2 #	$NetBSD: asm2gas,v 1.9 2008/03/28 22:27:33 apb Exp $
      3 
      4 #
      5 # Copyright (c) 1998,2008 The NetBSD Foundation, Inc.
      6 # All rights reserved.
      7 #
      8 # This code is derived from software contributed to The NetBSD Foundation
      9 # by Charles M. Hannum.
     10 #
     11 # Redistribution and use in source and binary forms, with or without
     12 # modification, are permitted provided that the following conditions
     13 # are met:
     14 # 1. Redistributions of source code must retain the above copyright
     15 #    notice, this list of conditions and the following disclaimer.
     16 # 2. Redistributions in binary form must reproduce the above copyright
     17 #    notice, this list of conditions and the following disclaimer in the
     18 #    documentation and/or other materials provided with the distribution.
     19 # 3. All advertising materials mentioning features or use of this software
     20 #    must display the following acknowledgement:
     21 #        This product includes software developed by the NetBSD
     22 #        Foundation, Inc. and its contributors.
     23 # 4. Neither the name of The NetBSD Foundation nor the names of its
     24 #    contributors may be used to endorse or promote products derived
     25 #    from this software without specific prior written permission.
     26 #
     27 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30 # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37 # POSSIBILITY OF SUCH DAMAGE.
     38 #
     39 
     40 # This ugly script converts assembler code from Motorola's format to a
     41 # form that gas (MIT syntax) can digest.
     42 
     43 : ${SED:=sed}	# Which sed to use
     44 P='%'		# Prefix for register names, may be '%' or ''
     45 
     46 cat "$1" | "${SED}" -e '
     47   # format canonicalization
     48 
     49   # leave "#include" alone; change "#" and "*" comment lines to use "|".
     50   /^\#include/{p;d;}
     51   /^\#/{s//|#/;p;d;}
     52   /^\*/{s//|/;p;d;}
     53   /[ 	]IDNT[ 	]/{s/^/|/;p;d;}
     54   s/;/|/
     55   /[ 	]equ[ 	]/{
     56     s/\([A-Za-z_][A-Za-z0-9_]*\)[ 	]*equ[ 	]*/\1,/
     57     s/[ 	][ 	]*\(.*\)$/		|\1/
     58     s/		||/		|/
     59     s/^/	.set	/
     60     p;d
     61   }
     62   s/^\([A-Za-z_][A-Za-z0-9_]*\)[ 	][ 	]*/\1:	/
     63   s/^\([A-Za-z_][A-Za-z0-9_]*\)$/\1:/
     64   /^[A-Za-z_][A-Za-z0-9_]*:/{
     65     h
     66     s/:.*$/:/
     67     p
     68     g
     69     s/^.*:[ 	]*/	/
     70     /^	$/d
     71   }
     72   /^[ 	][ 	]*\([.a-zA-Z][.a-zA-Z0-9]*\)/{
     73     h
     74     s///
     75     s/^[ 	][ 	]*//
     76     s/[ 	][ 	]*\(.*\)$/		|\1/
     77     s/		||/		|/
     78     x
     79     s/^[ 	][ 	]*//
     80     s/[ 	][ 	]*.*$/	/
     81     y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/
     82     s/^/	/
     83     G
     84     s/\n//
     85   }
     86 ' | "${SED}" -e '
     87   # operator conversion
     88 
     89   s/^	section	7/	.text/
     90   s/^	section	8/	.text/
     91   s/^	section	15/	.data/
     92   /^	include/{s/include[ 	]/.include "/;s/\.h[ 	]*$/.defs"/;p;d;}
     93   s/^	xref/|	xref/
     94   s/^	end/|	end/
     95   s/^	xdef/	.global/
     96 
     97   s/^	dc\.l/	.long/
     98   s/^	dc\.w/	.short/
     99   s/^	dc\.b/	.byte/
    100 
    101   /^	[aceg-z]/{
    102     /^	add[aiqx]*\.[bwl]	/{s/\.//;p;d;}
    103     /^	andi*\.[bwl]	/{s/\.//;p;d;}
    104     /^	as[lr]\.[bwl]	/{s/\.//;p;d;}
    105     /^	clr\.[bwl]	/{s/\.//;p;d;}
    106     /^	cmp[i2]*\.[bwl]	/{s/\.//;p;d;}
    107     /^	eori*\.[bwl]	/{s/\.//;p;d;}
    108     /^	lea\.l	/{s/\..//;p;d;}
    109     /^	ls[lr]\.[bwl]	/{s/\.//;p;d;}
    110     /^	move[acmqs]*\.[bwl]	/{s/\.//;p;d;}
    111     /^	mul[su]\.[wl]	/{s/\.//;p;d;}
    112     /^	neg\.[bwl]	/{s/\.//;p;d;}
    113     /^	ori*\.[bwl]	/{s/\.//;p;d;}
    114     /^	ro[lrx]*\.[bwl]	/{s/\.//;p;d;}
    115     /^	sub[aiqx]*\.[bwl]	/{s/\.//;p;d;}
    116     /^	swap\.w	/{s/\..//;p;d;}
    117     /^	s\([a-tv-z][a-z]*\)\.b	/{s/\..//;p;d;}
    118     /^	tst\.[bwl]	/{s/\.//;p;d;}
    119     p;d
    120   }
    121 
    122   /^	bchg\.[bl]	/{s/\..//;p;d;}
    123   /^	bclr\.[bl]	/{s/\..//;p;d;}
    124   /^	bset\.[bl]	/{s/\..//;p;d;}
    125   /^	btst\.[bl]	/{s/\..//;p;d;}
    126   /^	div[sul]*\.[wl]	/{s/\.//;p;d;}
    127   /^	fabs\.[sdx]	/{s/\.//;p;d;}
    128   /^	fadd\.[sdxbwl]	/{s/\.//;p;d;}
    129   /^	fcmp\.[sdxbwl]	/{s/\.//;p;d;}
    130   /^	fdiv\.[sdx]	/{s/\.//;p;d;}
    131   /^	fmove[mx]*\.[sdxbwl]	/{s/\.//;p;d;}
    132   /^	fmul\.[sdx]	/{s/\.//;p;d;}
    133   /^	fneg\.[sdx]	/{s/\.//;p;d;}
    134   /^	fsqrt\.[sdx]	/{s/\.//;p;d;}
    135   /^	fsub\.[sdxbwl]	/{s/\.//;p;d;}
    136   /^	ftst\.[sdx]	/{s/\.//;p;d;}
    137 
    138   /^	b[a-eg-z][a-z]*\.b	/{s/\.b/s/;p;d;}
    139   /^	b[a-eg-z][a-z]*\.w	/{s/\.w//;p;d;}
    140   /^	b[a-eg-z][a-z]*\.l	/{s/\.l/l/;p;d;}
    141   /^	db[a-z][a-z]*\.w	/{s/\.w//;p;d;}
    142   /^	fb[a-eg-z][a-z]*\.w	/{s/\.w//;p;d;}
    143   /^	fb[a-eg-z][a-z]*\.l	/{s/\.l/l/;p;d;}
    144 ' | "${SED}" -e '
    145   # operand conversion
    146 
    147   # register names "FPIAR" -> "%FPI", etc., possibly without the "%"
    148   s/\([^_a-zA-Z0-9]\)FPIAR\([^_a-zA-Z0-9]\)/\1'"$P"'FPI\2/g
    149   s/\([^_a-zA-Z0-9]\)FPIAR$/\1'"$P"'FPI/g
    150   s/\([^_a-zA-Z0-9]\)fpiar\([^_a-zA-Z0-9]\)/\1'"$P"'fpi\2/g
    151   s/\([^_a-zA-Z0-9]\)fpiar$/\1'"$P"'fpi/g
    152   s/\([^_a-zA-Z0-9]\)FPCR\([^_a-zA-Z0-9]\)/\1'"$P"'FPCR\2/g
    153   s/\([^_a-zA-Z0-9]\)FPCR$/\1'"$P"'FPCR/g
    154   s/\([^_a-zA-Z0-9]\)fpcr\([^_a-zA-Z0-9]\)/\1'"$P"'fpcr\2/g
    155   s/\([^_a-zA-Z0-9]\)fpcr$/\1'"$P"'fpcr/g
    156   s/\([^_a-zA-Z0-9]\)FPSR\([^_a-zA-Z0-9]\)/\1'"$P"'FPSR\2/g
    157   s/\([^_a-zA-Z0-9]\)FPSR$/\1'"$P"'FPSR/g
    158   s/\([^_a-zA-Z0-9]\)fpsr\([^_a-zA-Z0-9]\)/\1'"$P"'fpsr\2/g
    159   s/\([^_a-zA-Z0-9]\)fpsr$/\1'"$P"'fpsr/g
    160 
    161   # Hexadecimal numbers
    162   s/\$\([0-9a-fA-F]\)/0x\1/g
    163   s/#:/#:0x/g
    164 
    165   # Insert "%" before more register names (only if $P = "%").
    166   # Some of the rules are repeated because of overlap between trailing
    167   # context in one match and leading context in another match; otherwise
    168   # only half the register names in "d4{d3:4},d0" would be converted.
    169   s/\([^[:alnum:]_%]\)\([dDaA][0-7]\)\([^[:alnum:]_]\)/\1'"$P"'\2\3/g
    170   s/\([^[:alnum:]_%]\)\([fF][pP][0-7]\)\([^[:alnum:]_]\)/\1'"$P"'\2\3/g
    171   s/\([^[:alnum:]_%]\)\(sp\)\([^[:alnum:]_]\)/\1'"$P"'\2\3/g
    172   s/\([^[:alnum:]_%]\)\(pc\)\([^[:alnum:]_]\)/\1'"$P"'\2\3/g
    173 
    174   s/\([^[:alnum:]_%]\)\([dDaA][0-7]\)\([^[:alnum:]_]\)/\1'"$P"'\2\3/g
    175   s/\([^[:alnum:]_%]\)\([fF][pP][0-7]\)\([^[:alnum:]_]\)/\1'"$P"'\2\3/g
    176   s/\([^[:alnum:]_%]\)\(sp\)\([^[:alnum:]_]\)/\1'"$P"'\2\3/g
    177   s/\([^[:alnum:]_%]\)\(pc\)\([^[:alnum:]_]\)/\1'"$P"'\2\3/g
    178 
    179   s/\([^[:alnum:]_%]\)\([dDaA][0-7]\)$/\1'"$P"'\2/g
    180   s/\([^[:alnum:]_%]\)\([dDaA][0-7]\)$/\1'"$P"'\2/g
    181   s/\([^[:alnum:]_%]\)\([fF][pP][0-7]\)$/\1'"$P"'\2/g
    182   s/\([^[:alnum:]_%]\)\(sp\)$/\1'"$P"'\2/g
    183 
    184   s/\(,\)\([dDaA][0-7]\)/\1'"$P"'\2/g
    185   s/\(,\)\([fF][pP][0-7]\)/\1'"$P"'\2/g
    186 
    187   # "-(%sp)" -> "%sp@-", etc. (possibly without the "%")
    188   s/-(\('"$P"'[sSpPaA][pPcC0-7]\))/\1@-/g
    189   # "(%sp)+" -> "%sp@+", etc. (possibly without the "%")
    190   s/(\('"$P"'[sSpPaA][pPcC0-7]\))+/\1@+/g
    191   # "foo(%sp,...)" -> "%sp@(foo,...)", etc. (possibly without the "%")
    192   s/\([-+A-Za-z0-9_]*\)(\('"$P"'[sSpPaA][pPcC0-7]\)\([),]\)/\2@(\1\3/g
    193 
    194   # ".w" -> ":w"; ".w*nn" -> ":w:nn"; "*nn" -> ":l:nn"; etc.
    195   s/\.\([bBwWlL])\)/:\1/g
    196   s/\.\([bBwWlL]\)\*\([0-9][0-9]*)\)/:\1:\2/g
    197   s/\*\([0-9][0-9]*\))/:l:\1)/g
    198   # "{nn:mm}" -> "{#nn:#mm}"
    199   s/{\([0-9][0-9]*\):\([0-9][0-9]*\)}/{#\1:#\2}/g
    200   # "{%d0:nn}" -> "{%d0:#nn}", etc. (possibly without the "%")
    201   s/{\('"$P"'[dD][0-7]\):\([0-9][0-9]*\)}/{\1:#\2}/g
    202 
    203   # Remove empty "()" or "(0)" after "@"
    204   s/@(0*)/@/g
    205   # Remove leading "," or trailing ":" in parentheses
    206   s/(,/(/g;s/:)/)/g
    207 
    208   # make up for a gas bug
    209   /^	fmovemx	/{
    210 	s/	\('"$P"'[fF][pP][0-7]\),/	\1-\1,/
    211 	s/,\('"$P"'[fF][pP][0-7]\)	/,\1-\1	/
    212 	s/,\('"$P"'[fF][pP][0-7]\)$/,\1-\1/
    213   }
    214 ' | "${SED}" -e '
    215   # Floating point literal conversion
    216 
    217   s/:0x41dfffffffc00000/0r2147483647.0/g
    218   s/:0xc1e0000000000000/0r-2147483648.0/g
    219   s/:0x41dfffffffe00000/0r2147483647.5/g
    220   s/:0xc1e0000000100000/0r-2147483648.5/g
    221   s/:0x46fffe00/0r32767.0/g
    222   s/:0xc7000000/0r-32768.0/g
    223   s/:0x46ffff00/0r32767.5/g
    224   s/:0xc7000080/0r-32768.5/g
    225   s/:0x42fe0000/0r127.0/g
    226   s/:0xc3000000/0r-128.0/g
    227   s/:0x42ff0000/0r127.5/g
    228   s/:0xc3008000/0r-128.5/g
    229   s/:0x3F800000/0r1.0/g
    230   s/:0x00000000/0r0.0/g
    231   s/:0xBF800000/0r-1.0/g
    232   s/:0x3F000000/0r0.5/g
    233   s/:0x3E800000/0r0.25/g
    234   s/:0x42B8AA3B/0r92.332481384277343750/g
    235   s/:0xBC317218/0r-0.0108304247260093688964843750/g
    236   s/:0x3AB60B70/0r0.001388890668749809265136718750/g
    237   s/:0x3C088895/0r0.0083333449438214302062988281250/g
    238   s/:0x42B8AA3B/0r92.332481384277343750/g
    239   s/:0x3950097B/0r0.0001983995753107592463493347167968750/g
    240   s/:0x3AB60B6A/0r0.001388889970257878303527832031250/g
    241   s/:0x2F30CAA8/0r1.60791047143504783889511600136756896972656250e-10/g
    242   s/:0x310F8290/0r2.0883454965314740547910332679748535156250e-09/g
    243   s/:0x32D73220/0r2.5052088403754169121384620666503906250e-08/g
    244   s/:0x3493F281/0r2.755732850800995947793126106262207031250e-07/g
    245   s/:0x40000000/0r2.0/g
    246   s/:0x42800000/0r6.40e+01/g
    247   s/:0x3C800000/0r1.56250e-02/g
    248   s/fadds	#:0x00800000,'"$P"'[fF][pP]0/	.long	0xf23c4422,0x00800000/
    249   s/fsubs	#:0x00800000,'"$P"'[fF][pP]0/	.long	0xf23c4428,0x00800000/
    250   s/fsubs	#:0x00800000,'"$P"'[fF][pP]1/	.long	0xf23c44a8,0x00800000/
    251   s/fmoves	#:0x80000000,'"$P"'[fF][pP]0/	.long	0xf23c4400,0x80000000/
    252   s/fmoves		#:0x00000000,'"$P"'[fF][pP]0/	.long	0xf23c4400,0x00000000/
    253 
    254 '
    255