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