2000-08-21 17:52:39 +02:00
|
|
|
#! /bin/sh
|
|
|
|
# Generate CGEN simulator files.
|
|
|
|
#
|
2000-12-13 23:55:54 +01:00
|
|
|
# Usage: /bin/sh cgen.sh {"arch"|"cpu"|"decode"|"defs"|"cpu-decode"} \
|
|
|
|
# srcdir cgen cgendir cgenflags \
|
2004-12-01 03:29:30 +01:00
|
|
|
# arch archflags cpu mach suffix archfile extrafiles opcfile
|
2000-08-21 17:52:39 +02:00
|
|
|
#
|
|
|
|
# We store the generated files in the source directory until we decide to
|
|
|
|
# ship a Scheme interpreter (or other implementation) with gdb/binutils.
|
|
|
|
# Maybe we never will.
|
|
|
|
|
|
|
|
# We want to behave like make, any error forces us to stop.
|
|
|
|
set -e
|
|
|
|
|
|
|
|
action=$1
|
|
|
|
srcdir=$2
|
2005-02-09 23:04:04 +01:00
|
|
|
cgen="$3"
|
2000-08-21 17:52:39 +02:00
|
|
|
cgendir=$4
|
|
|
|
cgenflags=$5
|
|
|
|
arch=$6
|
|
|
|
archflags=$7
|
|
|
|
cpu=$8
|
2000-10-26 18:21:34 +02:00
|
|
|
isa=$9
|
2000-12-13 23:55:54 +01:00
|
|
|
# portably bring parameters beyond $9 into view
|
2000-10-26 18:21:34 +02:00
|
|
|
shift ; mach=$9
|
2000-08-21 17:52:39 +02:00
|
|
|
shift ; suffix=$9
|
2003-09-08 19:24:59 +02:00
|
|
|
shift ; archfile=$9
|
2000-08-21 17:52:39 +02:00
|
|
|
shift ; extrafiles=$9
|
2004-12-01 03:29:30 +01:00
|
|
|
shift ; opcfile=$9
|
2000-08-21 17:52:39 +02:00
|
|
|
|
|
|
|
rootdir=${srcdir}/../..
|
|
|
|
|
2004-12-01 03:29:30 +01:00
|
|
|
test -z "${opcfile}" && opcfile=/dev/null
|
|
|
|
|
2000-12-13 23:55:54 +01:00
|
|
|
if test -z "$isa" ; then
|
|
|
|
isa=all
|
|
|
|
prefix=$cpu
|
|
|
|
else
|
|
|
|
prefix=${cpu}_$isa
|
|
|
|
fi
|
|
|
|
|
2000-08-21 17:52:39 +02:00
|
|
|
lowercase='abcdefghijklmnopqrstuvwxyz'
|
|
|
|
uppercase='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
|
|
|
ARCH=`echo ${arch} | tr "${lowercase}" "${uppercase}"`
|
|
|
|
CPU=`echo ${cpu} | tr "${lowercase}" "${uppercase}"`
|
2000-12-13 23:55:54 +01:00
|
|
|
PREFIX=`echo ${prefix} | tr "${lowercase}" "${uppercase}"`
|
2000-08-21 17:52:39 +02:00
|
|
|
|
2000-12-13 23:55:54 +01:00
|
|
|
sedscript="\
|
|
|
|
-e s/@ARCH@/${ARCH}/g -e s/@arch@/${arch}/g \
|
|
|
|
-e s/@CPU@/${CPU}/g -e s/@cpu@/${cpu}/g \
|
|
|
|
-e s/@PREFIX@/${PREFIX}/g -e s/@prefix@/${prefix}/g"
|
2000-10-26 18:21:34 +02:00
|
|
|
|
2009-07-07 10:09:19 +02:00
|
|
|
# avoid collisions in parallel makes
|
|
|
|
tmp=tmp-$$
|
|
|
|
|
2000-08-21 17:52:39 +02:00
|
|
|
case $action in
|
|
|
|
arch)
|
2009-07-07 10:09:19 +02:00
|
|
|
rm -f ${tmp}-arch.h1 ${tmp}-arch.h
|
|
|
|
rm -f ${tmp}-arch.c1 ${tmp}-arch.c
|
|
|
|
rm -f ${tmp}-all.h1 ${tmp}-all.h
|
2000-08-21 17:52:39 +02:00
|
|
|
|
2005-02-09 23:04:04 +01:00
|
|
|
${cgen} ${cgendir}/cgen-sim.scm \
|
2000-08-21 17:52:39 +02:00
|
|
|
-s ${cgendir} \
|
|
|
|
${cgenflags} \
|
|
|
|
-f "${archflags}" \
|
|
|
|
-m ${mach} \
|
2003-09-08 19:24:59 +02:00
|
|
|
-a ${archfile} \
|
2000-10-26 18:21:34 +02:00
|
|
|
-i ${isa} \
|
2009-07-07 10:09:19 +02:00
|
|
|
-A ${tmp}-arch.h1 \
|
|
|
|
-B ${tmp}-arch.c1 \
|
|
|
|
-N ${tmp}-all.h1
|
|
|
|
sed $sedscript < ${tmp}-arch.h1 > ${tmp}-arch.h
|
|
|
|
${rootdir}/move-if-change ${tmp}-arch.h ${srcdir}/arch.h
|
|
|
|
sed $sedscript < ${tmp}-arch.c1 > ${tmp}-arch.c
|
|
|
|
${rootdir}/move-if-change ${tmp}-arch.c ${srcdir}/arch.c
|
|
|
|
sed $sedscript < ${tmp}-all.h1 > ${tmp}-all.h
|
|
|
|
${rootdir}/move-if-change ${tmp}-all.h ${srcdir}/cpuall.h
|
|
|
|
|
|
|
|
rm -f ${tmp}-arch.h1 ${tmp}-arch.c1 ${tmp}-all.h1
|
2000-08-21 17:52:39 +02:00
|
|
|
;;
|
|
|
|
|
|
|
|
cpu | decode | cpu-decode)
|
|
|
|
|
|
|
|
fileopts=""
|
2009-07-07 10:09:19 +02:00
|
|
|
|
2000-08-21 17:52:39 +02:00
|
|
|
case $action in
|
|
|
|
*cpu*)
|
2009-07-07 10:09:19 +02:00
|
|
|
rm -f ${tmp}-cpu.h1 ${tmp}-cpu.c1
|
|
|
|
rm -f ${tmp}-ext.c1 ${tmp}-read.c1 ${tmp}-write.c1
|
|
|
|
rm -f ${tmp}-sem.c1 ${tmp}-semsw.c1
|
|
|
|
rm -f ${tmp}-mod.c1
|
|
|
|
rm -f ${tmp}-cpu.h ${tmp}-cpu.c
|
|
|
|
rm -f ${tmp}-ext.c ${tmp}-read.c ${tmp}-write.c
|
|
|
|
rm -f ${tmp}-sem.c ${tmp}-semsw.c ${tmp}-mod.c
|
2000-08-21 17:52:39 +02:00
|
|
|
fileopts="$fileopts \
|
2009-07-07 10:09:19 +02:00
|
|
|
-C ${tmp}-cpu.h1 \
|
|
|
|
-U ${tmp}-cpu.c1 \
|
|
|
|
-M ${tmp}-mod.c1"
|
2000-08-21 17:52:39 +02:00
|
|
|
;;
|
|
|
|
esac
|
2009-07-07 10:09:19 +02:00
|
|
|
|
2000-08-21 17:52:39 +02:00
|
|
|
case $action in
|
|
|
|
*decode*)
|
2009-07-07 10:09:19 +02:00
|
|
|
rm -f ${tmp}-dec.h1 ${tmp}-dec.h ${tmp}-dec.c1 ${tmp}-dec.c
|
2000-08-21 17:52:39 +02:00
|
|
|
fileopts="$fileopts \
|
2009-07-07 10:09:19 +02:00
|
|
|
-T ${tmp}-dec.h1 \
|
|
|
|
-D ${tmp}-dec.c1"
|
2000-08-21 17:52:39 +02:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2009-07-07 10:09:19 +02:00
|
|
|
case "$extrafiles" in
|
|
|
|
*/extr/*) fileopts="${fileopts} -E ${tmp}-ext.c1" ;;
|
|
|
|
esac
|
|
|
|
case "$extrafiles" in
|
|
|
|
*/read/*) fileopts="${fileopts} -R ${tmp}-read.c1" ;;
|
|
|
|
esac
|
|
|
|
case "$extrafiles" in
|
|
|
|
*/write/*) fileopts="${fileopts} -W ${tmp}-write.c1" ;;
|
|
|
|
esac
|
|
|
|
case "$extrafiles" in
|
|
|
|
*/sem/*) fileopts="${fileopts} -S ${tmp}-sem.c1" ;;
|
|
|
|
esac
|
|
|
|
case "$extrafiles" in
|
|
|
|
*/semsw/*) fileopts="${fileopts} -X ${tmp}-semsw.c1" ;;
|
|
|
|
esac
|
|
|
|
|
2005-02-09 23:04:04 +01:00
|
|
|
${cgen} ${cgendir}/cgen-sim.scm \
|
2000-08-21 17:52:39 +02:00
|
|
|
-s ${cgendir} \
|
|
|
|
${cgenflags} \
|
|
|
|
-f "${archflags}" \
|
|
|
|
-m ${mach} \
|
2003-09-08 19:24:59 +02:00
|
|
|
-a ${archfile} \
|
2000-10-26 18:21:34 +02:00
|
|
|
-i ${isa} \
|
2000-08-21 17:52:39 +02:00
|
|
|
${fileopts}
|
|
|
|
|
|
|
|
case $action in
|
|
|
|
*cpu*)
|
2009-07-07 10:09:19 +02:00
|
|
|
sed $sedscript < ${tmp}-cpu.h1 > ${tmp}-cpu.h
|
|
|
|
${rootdir}/move-if-change ${tmp}-cpu.h ${srcdir}/cpu${suffix}.h
|
|
|
|
sed $sedscript < ${tmp}-cpu.c1 > ${tmp}-cpu.c
|
|
|
|
${rootdir}/move-if-change ${tmp}-cpu.c ${srcdir}/cpu${suffix}.c
|
|
|
|
sed $sedscript < ${tmp}-mod.c1 > ${tmp}-mod.c
|
|
|
|
${rootdir}/move-if-change ${tmp}-mod.c ${srcdir}/model${suffix}.c
|
|
|
|
rm -f ${tmp}-cpu.h1 ${tmp}-cpu.c1 ${tmp}-mod.c1
|
2000-08-21 17:52:39 +02:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
case $action in
|
|
|
|
*decode*)
|
2009-07-07 10:09:19 +02:00
|
|
|
sed $sedscript < ${tmp}-dec.h1 > ${tmp}-dec.h
|
|
|
|
${rootdir}/move-if-change ${tmp}-dec.h ${srcdir}/decode${suffix}.h
|
|
|
|
sed $sedscript < ${tmp}-dec.c1 > ${tmp}-dec.c
|
|
|
|
${rootdir}/move-if-change ${tmp}-dec.c ${srcdir}/decode${suffix}.c
|
|
|
|
rm -f ${tmp}-dec.h1 ${tmp}-dec.c1
|
2000-08-21 17:52:39 +02:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2009-07-07 10:09:19 +02:00
|
|
|
if test -f ${tmp}-ext.c1 ; then \
|
|
|
|
sed $sedscript < ${tmp}-ext.c1 > ${tmp}-ext.c ; \
|
|
|
|
${rootdir}/move-if-change ${tmp}-ext.c ${srcdir}/extract${suffix}.c ; \
|
|
|
|
rm -f ${tmp}-ext.c1
|
|
|
|
fi
|
|
|
|
if test -f ${tmp}-read.c1 ; then \
|
|
|
|
sed $sedscript < ${tmp}-read.c1 > ${tmp}-read.c ; \
|
|
|
|
${rootdir}/move-if-change ${tmp}-read.c ${srcdir}/read${suffix}.c ; \
|
|
|
|
rm -f ${tmp}-read.c1
|
|
|
|
fi
|
|
|
|
if test -f ${tmp}-write.c1 ; then \
|
|
|
|
sed $sedscript < ${tmp}-write.c1 > ${tmp}-write.c ; \
|
|
|
|
${rootdir}/move-if-change ${tmp}-write.c ${srcdir}/write${suffix}.c ; \
|
|
|
|
rm -f ${tmp}-write.c1
|
|
|
|
fi
|
|
|
|
if test -f ${tmp}-sem.c1 ; then \
|
|
|
|
sed $sedscript < ${tmp}-sem.c1 > ${tmp}-sem.c ; \
|
|
|
|
${rootdir}/move-if-change ${tmp}-sem.c ${srcdir}/sem${suffix}.c ; \
|
|
|
|
rm -f ${tmp}-sem.c1
|
|
|
|
fi
|
|
|
|
if test -f ${tmp}-semsw.c1 ; then \
|
|
|
|
sed $sedscript < ${tmp}-semsw.c1 > ${tmp}-semsw.c ; \
|
|
|
|
${rootdir}/move-if-change ${tmp}-semsw.c ${srcdir}/sem${suffix}-switch.c ; \
|
|
|
|
rm -f ${tmp}-semsw.c1
|
|
|
|
fi
|
|
|
|
|
2000-08-21 17:52:39 +02:00
|
|
|
;;
|
|
|
|
|
2000-12-13 23:55:54 +01:00
|
|
|
defs)
|
2009-07-07 10:09:19 +02:00
|
|
|
rm -f ${tmp}-defs.h1 ${tmp}-defs.h
|
2000-12-13 23:55:54 +01:00
|
|
|
|
2005-02-09 23:04:04 +01:00
|
|
|
${cgen} ${cgendir}/cgen-sim.scm \
|
2000-12-13 23:55:54 +01:00
|
|
|
-s ${cgendir} \
|
|
|
|
${cgenflags} \
|
|
|
|
-f "${archflags}" \
|
|
|
|
-m ${mach} \
|
2003-09-08 19:24:59 +02:00
|
|
|
-a ${archfile} \
|
2000-12-13 23:55:54 +01:00
|
|
|
-i ${isa} \
|
2009-07-07 10:09:19 +02:00
|
|
|
-G ${tmp}-defs.h1
|
|
|
|
sed $sedscript < ${tmp}-defs.h1 > ${tmp}-defs.h
|
|
|
|
${rootdir}/move-if-change ${tmp}-defs.h ${srcdir}/defs${suffix}.h
|
|
|
|
rm -f ${tmp}-defs.h1
|
2000-12-13 23:55:54 +01:00
|
|
|
;;
|
|
|
|
|
2000-08-21 17:52:39 +02:00
|
|
|
desc)
|
2009-07-07 10:09:19 +02:00
|
|
|
rm -f ${tmp}-desc.h1 ${tmp}-desc.h
|
|
|
|
rm -f ${tmp}-desc.c1 ${tmp}-desc.c
|
|
|
|
rm -f ${tmp}-opc.h1 ${tmp}-opc.h
|
2000-08-21 17:52:39 +02:00
|
|
|
|
2005-02-09 23:04:04 +01:00
|
|
|
${cgen} ${cgendir}/cgen-opc.scm \
|
2000-08-21 17:52:39 +02:00
|
|
|
-s ${cgendir} \
|
|
|
|
${cgenflags} \
|
2004-12-01 03:29:30 +01:00
|
|
|
-OPC ${opcfile} \
|
2000-08-21 17:52:39 +02:00
|
|
|
-f "${archflags}" \
|
|
|
|
-m ${mach} \
|
2003-09-08 19:24:59 +02:00
|
|
|
-a ${archfile} \
|
2000-10-26 18:21:34 +02:00
|
|
|
-i ${isa} \
|
2009-07-07 10:09:19 +02:00
|
|
|
-H ${tmp}-desc.h1 \
|
|
|
|
-C ${tmp}-desc.c1 \
|
|
|
|
-O ${tmp}-opc.h1
|
|
|
|
sed $sedscript < ${tmp}-desc.h1 > ${tmp}-desc.h
|
|
|
|
${rootdir}/move-if-change ${tmp}-desc.h ${srcdir}/${arch}-desc.h
|
|
|
|
sed $sedscript < ${tmp}-desc.c1 > ${tmp}-desc.c
|
|
|
|
${rootdir}/move-if-change ${tmp}-desc.c ${srcdir}/${arch}-desc.c
|
|
|
|
sed $sedscript < ${tmp}-opc.h1 > ${tmp}-opc.h
|
|
|
|
${rootdir}/move-if-change ${tmp}-opc.h ${srcdir}/${arch}-opc.h
|
|
|
|
|
|
|
|
rm -f ${tmp}-desc.h1 ${tmp}-desc.c1 ${tmp}-opc.h1
|
2000-08-21 17:52:39 +02:00
|
|
|
;;
|
|
|
|
|
|
|
|
*)
|
2000-12-13 23:55:54 +01:00
|
|
|
echo "`basename $0`: unknown action: ${action}" >&2
|
2000-08-21 17:52:39 +02:00
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
|
|
|
|
esac
|
|
|
|
|
|
|
|
exit 0
|