asm2gas revision 1.5
1#!/bin/sh 2# $NetBSD: asm2gas,v 1.5 1998/08/15 03:02:40 mycroft Exp $ 3 4# 5# Copyright (c) 1994 Charles M. Hannum. All rights reserved. 6# 7# Redistribution and use in source and binary forms, with or without 8# modification, are permitted provided that the following conditions 9# are met: 10# 1. Redistributions of source code must retain the above copyright 11# notice, this list of conditions and the following disclaimer. 12# 2. Redistributions in binary form must reproduce the above copyright 13# notice, this list of conditions and the following disclaimer in the 14# documentation and/or other materials provided with the distribution. 15# 3. All advertising materials mentioning features or use of this software 16# must display the following acknowledgement: 17# This product includes software developed by Charles M. Hannum. 18# 4. The name of the author may not be used to endorse or promote products 19# derived from this software without specific prior written permission. 20# 21# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 25# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 26# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31# 32 33# This ugly script converts assembler code from Motorola's format to a 34# form that gas (MIT syntax) can digest. 35 36cat $1 | sed -e ' 37 # format canonicalization 38 39 s/^#/|#/ 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/\$\([0-9a-fA-F]\)/0x\1/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