asm2gas revision 1.1
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.1 1994/07/05 17:57:04 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 37cat $1 | sed -e ' 38 /[ ]IDNT[ ]/{s/^/|/;p;d;} 39 /^\*/{p;d;} 40 s/;/|/ 41 /[ ]equ[ ]/{ 42 s/\([A-Za-z_][A-Za-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0-9_]*\)(sp,\([ad].[^)]*\))/sp@(\1,\2)/g 113 114 s/-(pc)/pc@-/g 115 s/(pc)+/pc@+/g 116 s/\([-+A-Za-z0-9_]*\)(pc)/pc@(\1)/g 117 s/\([-+A-Za-z0-9_]*\)(pc,\([ad].[^)]*\))/pc@(\1,\2)/g 118 119 s/\.\([bBwWlL])\)/:\1/g 120 s/\.\([bBwWlL]\)\*\([0-9][0-9]*)\)/:\1:\2/g 121 s/\*\([0-9][0-9]*\))/:l:\1)/g 122 s/{\([0-9][0-9]*\):\([0-9][0-9]*\)}/{#\1:#\2}/g 123 s/{\(d[0-7]\):\([0-9][0-9]*\)}/{\1:#\2}/g 124 125 s/@()/@/g;s/@(0)/@/g 126 s/(,/(/g;s/:)/)/g 127 128 s/^ section 7/ .text/ 129 s/^ section 8/ .text/ 130 s/^ section 15/ .data/ 131 /^ include/{s/include[ ]/.include "/;s/\.h[ ]*$/.defs"/;p;d;} 132 s/^ xref/| xref/ 133 s/^ end/| end/ 134 s/^ xdef/ .global/ 135 136 s/^ lea\.l / lea / 137 s/^ swap\.w / swap / 138 s/^ adda\.l / addal / 139 s/^ suba\.l / subal / 140 s/^ movea\.l / moveal / 141 s/^ btst\.[bl] / btst / 142 s/^ bclr\.[bl] / bclr / 143 s/^ bset\.[bl] / bset / 144 s/^ bchg\.[bl] / bchg / 145 s/^ clr\.\([lbw]\) / clr\1 / 146 s/^ tst\.\([lbw]\) / tst\1 / 147 s/^ neg\.\([lbw]\) / neg\1 / 148 s/^ or\(i*\)\.\([lbw]\) / or\1\2 / 149 s/^ eor\(i*\)\.\([lbw]\) / eor\1\2 / 150 s/^ and\(i*\)\.\([lbw]\) / and\1\2 / 151 s/^ mul\([su]\)\.\([lw]\) / mul\1\2 / 152 s/^ div\([sul]*\)\.\([lw]\) / div\1\2 / 153 s/^ cmp\([i2]*\)\.\([lbw]\) / cmp\1\2 / 154 s/^ ro\([xlr]*\)\.\([lbw]\) / ro\1\2 / 155 s/^ \([al]\)s\([lr]\)\.\([lbw]\) / \1s\2\3 / 156 s/^ add\([xiq]*\)\.\([lbw]\) / add\1\2 / 157 s/^ sub\([xiq]*\)\.\([lbw]\) / sub\1\2 / 158 s/^ move\([scmq]*\)\.\([lbw]\) / move\1\2 / 159 s/^ fabs\.\([sdx]\) / fabs\1 / 160 s/^ fneg\.\([sdx]\) / fneg\1 / 161 s/^ ftst\.\([sdx]\) / ftst\1 / 162 s/^ fmul\.\([sdx]\) / fmul\1 / 163 s/^ fdiv\.\([sdx]\) / fdiv\1 / 164 s/^ fsqrt\.\([sdx]\) / fsqrt\1 / 165 s/^ fadd\.\([sdxbwl]\) / fadd\1 / 166 s/^ fsub\.\([sdxbwl]\) / fsub\1 / 167 s/^ fcmp\.\([sdxbwl]\) / fcmp\1 / 168 s/^ fmove\([mx]*\)\.\([sdxbwl]\) / fmove\1\2 / 169 170 # fix an odd instruction 171 s/^ bhs\.w / bcc / 172 173 # set and branch instructions; questionable 174 s/^ s\([a-z][a-z]*\)\.b / s\1 / 175 s/^ db\([a-z][a-z]*\)\.w / db\1 / 176 s/^ b\([a-eg-z][a-z]*\)\.b / b\1s / 177 s/^ b\([a-eg-z][a-z]*\)\.w / b\1 / 178 s/^ b\([a-eg-z][a-z]*\)\.l / b\1l / 179 s/^ fb\([a-eg-z][a-z]*\)\.w / fb\1 / 180 s/^ fb\([a-eg-z][a-z]*\)\.l / fb\1l / 181 182 # make up for a gas bug 183 /^ fmovemx /{ 184 s/ fp\([0-7]\),/ fp\1-fp\1,/ 185 s/,fp\([0-7]\) /,fp\1-fp\1 / 186 s/,fp\([0-7]\)$/,fp\1-fp\1/ 187 } 188' 189