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