1#! /bin/sh 2# Generate CGEN simulator files. 3# 4# Usage: /bin/sh cgen.sh {"arch"|"cpu"|"decode"|"defs"|"cpu-decode"} \ 5# srcdir cgen cgendir cgenflags \ 6# arch archflags cpu mach suffix archfile extrafiles opcfile 7# 8# We store the generated files in the source directory until we decide to 9# ship a Scheme interpreter (or other implementation) with gdb/binutils. 10# Maybe we never will. 11 12# We want to behave like make, any error forces us to stop. 13set -e 14 15action=$1 16srcdir=$2 17cgen="$3" 18cgendir=$4 19cgenflags=$5 20arch=$6 21archflags=$7 22cpu=$8 23isa=$9 24# portably bring parameters beyond $9 into view 25shift ; mach=$9 26shift ; suffix=$9 27shift ; archfile=$9 28shift ; extrafiles=$9 29shift ; opcfile=$9 30 31rootdir=${srcdir}/../.. 32move_if_change="${CONFIG_SHELL:-/bin/sh} ${rootdir}/move-if-change" 33 34test -z "${opcfile}" && opcfile=/dev/null 35 36if test -z "$isa" ; then 37 isa=all 38 prefix=$cpu 39else 40 prefix=${cpu}_$isa 41fi 42 43lowercase='abcdefghijklmnopqrstuvwxyz' 44uppercase='ABCDEFGHIJKLMNOPQRSTUVWXYZ' 45ARCH=`echo ${arch} | tr "${lowercase}" "${uppercase}"` 46CPU=`echo ${cpu} | tr "${lowercase}" "${uppercase}"` 47PREFIX=`echo ${prefix} | tr "${lowercase}" "${uppercase}"` 48 49sedscript="\ 50-e s/@ARCH@/${ARCH}/g -e s/@arch@/${arch}/g \ 51-e s/@CPU@/${CPU}/g -e s/@cpu@/${cpu}/g \ 52-e s/@PREFIX@/${PREFIX}/g -e s/@prefix@/${prefix}/g" 53 54# avoid collisions in parallel makes 55tmp=tmp-$$ 56 57case $action in 58arch) 59 rm -f ${tmp}-arch.h1 ${tmp}-arch.h 60 rm -f ${tmp}-arch.c1 ${tmp}-arch.c 61 rm -f ${tmp}-all.h1 ${tmp}-all.h 62 63 ${cgen} ${cgendir}/cgen-sim.scm \ 64 ${cgenflags} \ 65 -f "${archflags}" \ 66 -m ${mach} \ 67 -a ${archfile} \ 68 -i ${isa} \ 69 -A ${tmp}-arch.h1 \ 70 -B ${tmp}-arch.c1 \ 71 -N ${tmp}-all.h1 72 sed $sedscript < ${tmp}-arch.h1 > ${tmp}-arch.h 73 ${move_if_change} ${tmp}-arch.h ${srcdir}/arch.h 74 sed $sedscript < ${tmp}-arch.c1 > ${tmp}-arch.c 75 ${move_if_change} ${tmp}-arch.c ${srcdir}/arch.c 76 sed $sedscript < ${tmp}-all.h1 > ${tmp}-all.h 77 ${move_if_change} ${tmp}-all.h ${srcdir}/cpuall.h 78 79 rm -f ${tmp}-arch.h1 ${tmp}-arch.c1 ${tmp}-all.h1 80 ;; 81 82cpu | decode | cpu-decode) 83 84 fileopts="" 85 86 case $action in 87 *cpu*) 88 rm -f ${tmp}-cpu.h1 ${tmp}-cpu.c1 89 rm -f ${tmp}-ext.c1 ${tmp}-read.c1 ${tmp}-write.c1 90 rm -f ${tmp}-sem.c1 ${tmp}-semsw.c1 91 rm -f ${tmp}-mod.c1 92 rm -f ${tmp}-cpu.h ${tmp}-cpu.c 93 rm -f ${tmp}-ext.c ${tmp}-read.c ${tmp}-write.c 94 rm -f ${tmp}-sem.c ${tmp}-semsw.c ${tmp}-mod.c 95 fileopts="$fileopts \ 96 -C ${tmp}-cpu.h1 \ 97 -U ${tmp}-cpu.c1 \ 98 -M ${tmp}-mod.c1" 99 ;; 100 esac 101 102 case $action in 103 *decode*) 104 rm -f ${tmp}-dec.h1 ${tmp}-dec.h ${tmp}-dec.c1 ${tmp}-dec.c 105 fileopts="$fileopts \ 106 -T ${tmp}-dec.h1 \ 107 -D ${tmp}-dec.c1" 108 ;; 109 esac 110 111 case "$extrafiles" in 112 */extr/*) fileopts="${fileopts} -E ${tmp}-ext.c1" ;; 113 esac 114 case "$extrafiles" in 115 */read/*) fileopts="${fileopts} -R ${tmp}-read.c1" ;; 116 esac 117 case "$extrafiles" in 118 */write/*) fileopts="${fileopts} -W ${tmp}-write.c1" ;; 119 esac 120 case "$extrafiles" in 121 */sem/*) fileopts="${fileopts} -S ${tmp}-sem.c1" ;; 122 esac 123 case "$extrafiles" in 124 */semsw/*) fileopts="${fileopts} -X ${tmp}-semsw.c1" ;; 125 esac 126 127 ${cgen} ${cgendir}/cgen-sim.scm \ 128 ${cgenflags} \ 129 -f "${archflags}" \ 130 -m ${mach} \ 131 -a ${archfile} \ 132 -i ${isa} \ 133 ${fileopts} 134 135 case $action in 136 *cpu*) 137 sed $sedscript < ${tmp}-cpu.h1 > ${tmp}-cpu.h 138 ${move_if_change} ${tmp}-cpu.h ${srcdir}/cpu${suffix}.h 139 sed $sedscript < ${tmp}-cpu.c1 > ${tmp}-cpu.c 140 ${move_if_change} ${tmp}-cpu.c ${srcdir}/cpu${suffix}.c 141 sed $sedscript < ${tmp}-mod.c1 > ${tmp}-mod.c 142 ${move_if_change} ${tmp}-mod.c ${srcdir}/model${suffix}.c 143 rm -f ${tmp}-cpu.h1 ${tmp}-cpu.c1 ${tmp}-mod.c1 144 ;; 145 esac 146 147 case $action in 148 *decode*) 149 sed $sedscript < ${tmp}-dec.h1 > ${tmp}-dec.h 150 ${move_if_change} ${tmp}-dec.h ${srcdir}/decode${suffix}.h 151 sed $sedscript < ${tmp}-dec.c1 > ${tmp}-dec.c 152 ${move_if_change} ${tmp}-dec.c ${srcdir}/decode${suffix}.c 153 rm -f ${tmp}-dec.h1 ${tmp}-dec.c1 154 ;; 155 esac 156 157 if test -f ${tmp}-ext.c1 ; then \ 158 sed $sedscript < ${tmp}-ext.c1 > ${tmp}-ext.c ; \ 159 ${move_if_change} ${tmp}-ext.c ${srcdir}/extract${suffix}.c ; \ 160 rm -f ${tmp}-ext.c1 161 fi 162 if test -f ${tmp}-read.c1 ; then \ 163 sed $sedscript < ${tmp}-read.c1 > ${tmp}-read.c ; \ 164 ${move_if_change} ${tmp}-read.c ${srcdir}/read${suffix}.c ; \ 165 rm -f ${tmp}-read.c1 166 fi 167 if test -f ${tmp}-write.c1 ; then \ 168 sed $sedscript < ${tmp}-write.c1 > ${tmp}-write.c ; \ 169 ${move_if_change} ${tmp}-write.c ${srcdir}/write${suffix}.c ; \ 170 rm -f ${tmp}-write.c1 171 fi 172 if test -f ${tmp}-sem.c1 ; then \ 173 sed $sedscript < ${tmp}-sem.c1 > ${tmp}-sem.c ; \ 174 ${move_if_change} ${tmp}-sem.c ${srcdir}/sem${suffix}.c ; \ 175 rm -f ${tmp}-sem.c1 176 fi 177 if test -f ${tmp}-semsw.c1 ; then \ 178 sed $sedscript < ${tmp}-semsw.c1 > ${tmp}-semsw.c ; \ 179 ${move_if_change} ${tmp}-semsw.c ${srcdir}/sem${suffix}-switch.c ; \ 180 rm -f ${tmp}-semsw.c1 181 fi 182 183 ;; 184 185defs) 186 rm -f ${tmp}-defs.h1 ${tmp}-defs.h 187 188 ${cgen} ${cgendir}/cgen-sim.scm \ 189 ${cgenflags} \ 190 -f "${archflags}" \ 191 -m ${mach} \ 192 -a ${archfile} \ 193 -i ${isa} \ 194 -G ${tmp}-defs.h1 195 sed $sedscript < ${tmp}-defs.h1 > ${tmp}-defs.h 196 ${move_if_change} ${tmp}-defs.h ${srcdir}/defs${suffix}.h 197 rm -f ${tmp}-defs.h1 198 ;; 199 200desc) 201 rm -f ${tmp}-desc.h1 ${tmp}-desc.h 202 rm -f ${tmp}-desc.c1 ${tmp}-desc.c 203 rm -f ${tmp}-opc.h1 ${tmp}-opc.h 204 205 ${cgen} ${cgendir}/cgen-opc.scm \ 206 ${cgenflags} \ 207 -OPC ${opcfile} \ 208 -f "${archflags}" \ 209 -m ${mach} \ 210 -a ${archfile} \ 211 -i ${isa} \ 212 -H ${tmp}-desc.h1 \ 213 -C ${tmp}-desc.c1 \ 214 -O ${tmp}-opc.h1 215 sed $sedscript < ${tmp}-desc.h1 > ${tmp}-desc.h 216 ${move_if_change} ${tmp}-desc.h ${srcdir}/${arch}-desc.h 217 sed $sedscript < ${tmp}-desc.c1 > ${tmp}-desc.c 218 ${move_if_change} ${tmp}-desc.c ${srcdir}/${arch}-desc.c 219 sed $sedscript < ${tmp}-opc.h1 > ${tmp}-opc.h 220 ${move_if_change} ${tmp}-opc.h ${srcdir}/${arch}-opc.h 221 222 rm -f ${tmp}-desc.h1 ${tmp}-desc.c1 ${tmp}-opc.h1 223 ;; 224 225*) 226 echo "`basename $0`: unknown action: ${action}" >&2 227 exit 1 228 ;; 229 230esac 231 232exit 0 233