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