arm: Support pac_key_* register operand for MRS/MSR in Armv8.1-M Mainline
[binutils-gdb.git] / sim / common / cgen.sh
bloba7479ec8d4ca4a26c94866b8bd0f29e297172a3e
1 #! /bin/sh
2 # Generate CGEN simulator files.
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
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.
12 # We want to behave like make, any error forces us to stop.
13 set -e
15 action=$1
16 srcdir=$2
17 cgen="$3"
18 cgendir=$4
19 cgenflags=$5
20 arch=$6
21 archflags=$7
22 cpu=$8
23 isa=$9
24 # portably bring parameters beyond $9 into view
25 shift ; mach=$9
26 shift ; suffix=$9
27 shift ; archfile=$9
28 shift ; extrafiles=$9
29 shift ; opcfile=$9
31 rootdir=${srcdir}/../..
33 test -z "${opcfile}" && opcfile=/dev/null
35 if test -z "$isa" ; then
36 isa=all
37 prefix=$cpu
38 else
39 prefix=${cpu}_$isa
42 lowercase='abcdefghijklmnopqrstuvwxyz'
43 uppercase='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
44 ARCH=`echo ${arch} | tr "${lowercase}" "${uppercase}"`
45 CPU=`echo ${cpu} | tr "${lowercase}" "${uppercase}"`
46 PREFIX=`echo ${prefix} | tr "${lowercase}" "${uppercase}"`
48 sedscript="\
49 -e s/@ARCH@/${ARCH}/g -e s/@arch@/${arch}/g \
50 -e s/@CPU@/${CPU}/g -e s/@cpu@/${cpu}/g \
51 -e s/@PREFIX@/${PREFIX}/g -e s/@prefix@/${prefix}/g"
53 # avoid collisions in parallel makes
54 tmp=tmp-$$
56 case $action in
57 arch)
58 rm -f ${tmp}-arch.h1 ${tmp}-arch.h
59 rm -f ${tmp}-arch.c1 ${tmp}-arch.c
60 rm -f ${tmp}-all.h1 ${tmp}-all.h
62 ${cgen} ${cgendir}/cgen-sim.scm \
63 ${cgenflags} \
64 -f "${archflags}" \
65 -m ${mach} \
66 -a ${archfile} \
67 -i ${isa} \
68 -A ${tmp}-arch.h1 \
69 -B ${tmp}-arch.c1 \
70 -N ${tmp}-all.h1
71 sed $sedscript < ${tmp}-arch.h1 > ${tmp}-arch.h
72 ${rootdir}/move-if-change ${tmp}-arch.h ${srcdir}/arch.h
73 sed $sedscript < ${tmp}-arch.c1 > ${tmp}-arch.c
74 ${rootdir}/move-if-change ${tmp}-arch.c ${srcdir}/arch.c
75 sed $sedscript < ${tmp}-all.h1 > ${tmp}-all.h
76 ${rootdir}/move-if-change ${tmp}-all.h ${srcdir}/cpuall.h
78 rm -f ${tmp}-arch.h1 ${tmp}-arch.c1 ${tmp}-all.h1
81 cpu | decode | cpu-decode)
83 fileopts=""
85 case $action in
86 *cpu*)
87 rm -f ${tmp}-cpu.h1 ${tmp}-cpu.c1
88 rm -f ${tmp}-ext.c1 ${tmp}-read.c1 ${tmp}-write.c1
89 rm -f ${tmp}-sem.c1 ${tmp}-semsw.c1
90 rm -f ${tmp}-mod.c1
91 rm -f ${tmp}-cpu.h ${tmp}-cpu.c
92 rm -f ${tmp}-ext.c ${tmp}-read.c ${tmp}-write.c
93 rm -f ${tmp}-sem.c ${tmp}-semsw.c ${tmp}-mod.c
94 fileopts="$fileopts \
95 -C ${tmp}-cpu.h1 \
96 -U ${tmp}-cpu.c1 \
97 -M ${tmp}-mod.c1"
99 esac
101 case $action in
102 *decode*)
103 rm -f ${tmp}-dec.h1 ${tmp}-dec.h ${tmp}-dec.c1 ${tmp}-dec.c
104 fileopts="$fileopts \
105 -T ${tmp}-dec.h1 \
106 -D ${tmp}-dec.c1"
108 esac
110 case "$extrafiles" in
111 */extr/*) fileopts="${fileopts} -E ${tmp}-ext.c1" ;;
112 esac
113 case "$extrafiles" in
114 */read/*) fileopts="${fileopts} -R ${tmp}-read.c1" ;;
115 esac
116 case "$extrafiles" in
117 */write/*) fileopts="${fileopts} -W ${tmp}-write.c1" ;;
118 esac
119 case "$extrafiles" in
120 */sem/*) fileopts="${fileopts} -S ${tmp}-sem.c1" ;;
121 esac
122 case "$extrafiles" in
123 */semsw/*) fileopts="${fileopts} -X ${tmp}-semsw.c1" ;;
124 esac
126 ${cgen} ${cgendir}/cgen-sim.scm \
127 ${cgenflags} \
128 -f "${archflags}" \
129 -m ${mach} \
130 -a ${archfile} \
131 -i ${isa} \
132 ${fileopts}
134 case $action in
135 *cpu*)
136 sed $sedscript < ${tmp}-cpu.h1 > ${tmp}-cpu.h
137 ${rootdir}/move-if-change ${tmp}-cpu.h ${srcdir}/cpu${suffix}.h
138 sed $sedscript < ${tmp}-cpu.c1 > ${tmp}-cpu.c
139 ${rootdir}/move-if-change ${tmp}-cpu.c ${srcdir}/cpu${suffix}.c
140 sed $sedscript < ${tmp}-mod.c1 > ${tmp}-mod.c
141 ${rootdir}/move-if-change ${tmp}-mod.c ${srcdir}/model${suffix}.c
142 rm -f ${tmp}-cpu.h1 ${tmp}-cpu.c1 ${tmp}-mod.c1
144 esac
146 case $action in
147 *decode*)
148 sed $sedscript < ${tmp}-dec.h1 > ${tmp}-dec.h
149 ${rootdir}/move-if-change ${tmp}-dec.h ${srcdir}/decode${suffix}.h
150 sed $sedscript < ${tmp}-dec.c1 > ${tmp}-dec.c
151 ${rootdir}/move-if-change ${tmp}-dec.c ${srcdir}/decode${suffix}.c
152 rm -f ${tmp}-dec.h1 ${tmp}-dec.c1
154 esac
156 if test -f ${tmp}-ext.c1 ; then \
157 sed $sedscript < ${tmp}-ext.c1 > ${tmp}-ext.c ; \
158 ${rootdir}/move-if-change ${tmp}-ext.c ${srcdir}/extract${suffix}.c ; \
159 rm -f ${tmp}-ext.c1
161 if test -f ${tmp}-read.c1 ; then \
162 sed $sedscript < ${tmp}-read.c1 > ${tmp}-read.c ; \
163 ${rootdir}/move-if-change ${tmp}-read.c ${srcdir}/read${suffix}.c ; \
164 rm -f ${tmp}-read.c1
166 if test -f ${tmp}-write.c1 ; then \
167 sed $sedscript < ${tmp}-write.c1 > ${tmp}-write.c ; \
168 ${rootdir}/move-if-change ${tmp}-write.c ${srcdir}/write${suffix}.c ; \
169 rm -f ${tmp}-write.c1
171 if test -f ${tmp}-sem.c1 ; then \
172 sed $sedscript < ${tmp}-sem.c1 > ${tmp}-sem.c ; \
173 ${rootdir}/move-if-change ${tmp}-sem.c ${srcdir}/sem${suffix}.c ; \
174 rm -f ${tmp}-sem.c1
176 if test -f ${tmp}-semsw.c1 ; then \
177 sed $sedscript < ${tmp}-semsw.c1 > ${tmp}-semsw.c ; \
178 ${rootdir}/move-if-change ${tmp}-semsw.c ${srcdir}/sem${suffix}-switch.c ; \
179 rm -f ${tmp}-semsw.c1
184 defs)
185 rm -f ${tmp}-defs.h1 ${tmp}-defs.h
187 ${cgen} ${cgendir}/cgen-sim.scm \
188 ${cgenflags} \
189 -f "${archflags}" \
190 -m ${mach} \
191 -a ${archfile} \
192 -i ${isa} \
193 -G ${tmp}-defs.h1
194 sed $sedscript < ${tmp}-defs.h1 > ${tmp}-defs.h
195 ${rootdir}/move-if-change ${tmp}-defs.h ${srcdir}/defs${suffix}.h
196 rm -f ${tmp}-defs.h1
199 desc)
200 rm -f ${tmp}-desc.h1 ${tmp}-desc.h
201 rm -f ${tmp}-desc.c1 ${tmp}-desc.c
202 rm -f ${tmp}-opc.h1 ${tmp}-opc.h
204 ${cgen} ${cgendir}/cgen-opc.scm \
205 ${cgenflags} \
206 -OPC ${opcfile} \
207 -f "${archflags}" \
208 -m ${mach} \
209 -a ${archfile} \
210 -i ${isa} \
211 -H ${tmp}-desc.h1 \
212 -C ${tmp}-desc.c1 \
213 -O ${tmp}-opc.h1
214 sed $sedscript < ${tmp}-desc.h1 > ${tmp}-desc.h
215 ${rootdir}/move-if-change ${tmp}-desc.h ${srcdir}/${arch}-desc.h
216 sed $sedscript < ${tmp}-desc.c1 > ${tmp}-desc.c
217 ${rootdir}/move-if-change ${tmp}-desc.c ${srcdir}/${arch}-desc.c
218 sed $sedscript < ${tmp}-opc.h1 > ${tmp}-opc.h
219 ${rootdir}/move-if-change ${tmp}-opc.h ${srcdir}/${arch}-opc.h
221 rm -f ${tmp}-desc.h1 ${tmp}-desc.c1 ${tmp}-opc.h1
225 echo "`basename $0`: unknown action: ${action}" >&2
226 exit 1
229 esac
231 exit 0