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