1 dnl Copyright (C) 2005-2024 Free Software Foundation, Inc.
3 dnl This program is free software; you can redistribute it and/or modify
4 dnl it under the terms of the GNU General Public License as published by
5 dnl the Free Software Foundation; either version 3 of the License, or
6 dnl (at your option) any later version.
8 dnl This program is distributed in the hope that it will be useful,
9 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
10 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 dnl GNU General Public License for more details.
13 dnl You should have received a copy of the GNU General Public License
14 dnl along with this program. If not, see <http://www.gnu.org/licenses/>.
16 dnl NB: This file is included in sim/configure, so keep settings namespaced.
20 dnl Instead of defining a `subtarget' macro, code should be checking the value
21 dnl of {STATE,CPU}_ARCHITECTURE to identify the architecture dnl in question.
22 AC_MSG_CHECKING([mips subtarget])
25 [mips64vr*-*-*], [SIM_MIPS_SUBTARGET="-DTARGET_ENABLE_FR=1"],
26 [mips*tx39*], [SIM_MIPS_SUBTARGET="-DSUBTARGET_R3900=1"],
27 [mips*-sde-elf*], [SIM_MIPS_SUBTARGET="-DTARGET_ENABLE_FR=1"],
28 [mips*-mti-elf*], [SIM_MIPS_SUBTARGET="-DTARGET_ENABLE_FR=1"],
29 [mipsisa32*-*-*], [SIM_MIPS_SUBTARGET="-DTARGET_ENABLE_FR=1"],
30 [mipsisa64*-*-*], [SIM_MIPS_SUBTARGET="-DTARGET_ENABLE_FR=1"])
31 AC_MSG_RESULT([${SIM_MIPS_SUBTARGET:-none}])
32 AC_SUBST(SIM_MIPS_SUBTARGET)
34 dnl Select the bitsize of the target.
35 AC_MSG_CHECKING([mips bitsize])
38 [mips*-sde-elf*], [SIM_MIPS_BITSIZE=64],
39 [mips*-mti-elf*], [SIM_MIPS_BITSIZE=64],
40 [mips64*-*-*], [SIM_MIPS_BITSIZE=64],
41 [mips16*-*-*], [SIM_MIPS_BITSIZE=64],
42 [mipsisa32*-*-*], [SIM_MIPS_BITSIZE=32],
43 [mipsisa64*-*-*], [SIM_MIPS_BITSIZE=64],
44 [mips*-*-*], [SIM_MIPS_BITSIZE=32])
45 AC_MSG_RESULT([$SIM_MIPS_BITSIZE])
46 AC_SUBST(SIM_MIPS_BITSIZE)
48 dnl Select the floating hardware support of the target.
49 AC_MSG_CHECKING([mips fpu bitsize])
50 SIM_MIPS_FPU_BITSIZE=64
52 [mips*tx39*], [SIM_MIPS_FPU_BITSIZE=32],
53 [mips*-sde-elf*], [SIM_MIPS_FPU_BITSIZE=64],
54 [mips*-mti-elf*], [SIM_MIPS_FPU_BITSIZE=64],
55 [mipsisa32*-*-*], [SIM_MIPS_FPU_BITSIZE=64],
56 [mipsisa64*-*-*], [SIM_MIPS_FPU_BITSIZE=64],
57 [mips*-*-*], [SIM_MIPS_FPU_BITSIZE=32])
58 AC_MSG_RESULT([$SIM_MIPS_FPU_BITSIZE])
59 AC_SUBST(SIM_MIPS_FPU_BITSIZE)
61 dnl Select the IGEN architecture.
63 sim_mips_single_machine="-M mipsIV"
64 sim_mips_m16_machine="-M mips16,mipsIII"
65 sim_mips_single_filter="32,64,f"
66 sim_mips_m16_filter="16"
70 sim_mips_single_filter="32,f"
71 sim_mips_single_machine="-M r3900"],
74 sim_mips_single_machine="-M vr4100"
75 sim_mips_m16_machine="-M vr4100"],
78 sim_mips_multi_configs="\
79 vr4100:mipsIII,mips16,vr4100:32,64:mips4100,mips4111\
80 vr4120:mipsIII,mips16,vr4120:32,64:mips4120\
81 vr5000:mipsIV:32,64,f:mips4300,mips5000,mips8000\
82 vr5400:mipsIV,vr5400:32,64,f:mips5400\
83 vr5500:mipsIV,vr5500:32,64,f:mips5500"
84 sim_mips_multi_default=mips5000],
85 [mips*-sde-elf* | mips*-mti-elf*], [dnl
87 sim_mips_multi_configs="\
88 micromips:micromips64,micromipsdsp:32,64,f:mips_micromips\
89 mipsisa64r2:mips64r2,mips16,mips16e,mdmx,dsp,dsp2,mips3d,smartmips:32,64,f:mipsisa32r2,mipsisa64r2,mipsisa32r5,mipsisa64r5\
90 mipsisa64r6:mips64r6:32,64,f:mipsisa32r6,mipsisa64r6"
91 sim_mips_multi_default=mipsisa64r2],
96 sim_mips_multi_configs="\
97 micromips:micromips32,micromipsdsp:32,f:mips_micromips\
98 mips32r2:mips32r2,mips3d,mips16,mips16e,mdmx,dsp,dsp2,smartmips:32,f:mipsisa32r2"
99 sim_mips_multi_default=mipsisa32r2],
102 sim_mips_single_machine="-M mips32r6"
103 sim_mips_single_filter="32,f"],
106 sim_mips_single_machine="-M mips32,mips16,mips16e,smartmips"
107 sim_mips_m16_machine="-M mips16,mips16e,mips32"
108 sim_mips_single_filter="32,f"],
111 sim_mips_single_machine="-M mips64r2,mips3d,mips16,mips16e,mdmx,dsp,dsp2"
112 sim_mips_m16_machine="-M mips16,mips16e,mips64r2"],
115 sim_mips_single_machine="-M mips64r6"],
116 [mipsisa64sb1*], [dnl
118 sim_mips_single_machine="-M mips64,mips3d,sb1"],
121 sim_mips_single_machine="-M mips64,mips3d,mips16,mips16e,mdmx"
122 sim_mips_m16_machine="-M mips16,mips16e,mips64"],
125 sim_mips_single_machine="-M mipsIII,mips16"
126 sim_mips_m16_machine="-M mips16,mipsIII"
127 sim_mips_single_filter="32,f"],
130 sim_mips_single_filter="32,f"])
132 dnl The MULTI generator can combine several simulation engines into one.
133 dnl executable. A configuration which uses the MULTI should set two
134 dnl variables: ${sim_mips_multi_configs} and ${sim_mips_multi_default}.
136 dnl ${sim_mips_multi_configs} is the list of engines to build. Each
137 dnl space-separated entry has the form NAME:MACHINE:FILTER:BFDMACHS,
140 dnl - NAME is a C-compatible prefix for the engine,
141 dnl - MACHINE is a -M argument,
142 dnl - FILTER is a -F argument, and
143 dnl - BFDMACHS is a comma-separated list of bfd machines that the
144 dnl simulator can run.
146 dnl Each entry will have a separate simulation engine whose prefix is
147 dnl m32<NAME>. If the machine list includes "mips16", there will also
148 dnl be a mips16 engine, prefix m16<NAME>. The mips16 engine will be
149 dnl generated using the same machine list as the 32-bit version,
150 dnl but the filter will be "16" instead of FILTER.
152 dnl The simulator compares the bfd mach against BFDMACHS to decide
153 dnl which engine to use. Entries in BFDMACHS should be bfd_mach
154 dnl values with "bfd_mach_" removed. ${sim_mips_multi_default} says
155 dnl which entry should be the default.
156 SIM_MIPS_IGEN_ITABLE_FLAGS=
159 SIM_MIPS_MULTI_IGEN_CONFIGS=
160 AS_VAR_IF([SIM_MIPS_GEN], ["MULTI"], [dnl
161 dnl Verify the AS_CASE logic above is setup correctly.
162 AS_IF([test -z "${sim_mips_multi_configs}" || test -z "${sim_mips_multi_default}"], [dnl
163 AC_MSG_ERROR(Error in configure.ac: MULTI simulator not set up correctly)])
165 dnl Start in a known state.
167 rm -f mips/multi-include.h mips/multi-run.c
168 sim_mips_seen_default=no
170 cat << __EOF__ > mips/multi-run.c
171 /* Main entry point for MULTI simulators.
172 Copyright (C) 2003-2023 Free Software Foundation, Inc.
174 This program is free software; you can redistribute it and/or modify
175 it under the terms of the GNU General Public License as published by
176 the Free Software Foundation; either version 3 of the License, or
177 (at your option) any later version.
179 This program is distributed in the hope that it will be useful,
180 but WITHOUT ANY WARRANTY; without even the implied warranty of
181 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
182 GNU General Public License for more details.
184 You should have received a copy of the GNU General Public License
185 along with this program. If not, see <http://www.gnu.org/licenses/>.
189 This file was generated by sim/mips/configure. */
191 #include "sim-main.h"
192 #include "multi-include.h"
193 #include "bfd/elf-bfd.h"
194 #include "bfd/elfxx-mips.h"
195 #include "elf/mips.h"
201 sim_engine_run (SIM_DESC sd,
204 int signal) /* ignore */
208 if (STATE_ARCHITECTURE (sd) == NULL)
209 mach = bfd_mach_${sim_mips_multi_default};
210 else if (elf_elfheader (STATE_PROG_BFD (sd))->e_flags
211 & EF_MIPS_ARCH_ASE_MICROMIPS)
212 mach = bfd_mach_mips_micromips;
215 mach = _bfd_elf_mips_mach (elf_elfheader (STATE_PROG_BFD (sd))->e_flags);
217 mach = STATE_ARCHITECTURE (SD)->mach;
224 for fc in ${sim_mips_multi_configs}; do
226 dnl Split up the entry. ${c} contains the first three elements.
227 dnl Note: outer sqaure brackets are m4 quotes.
228 c=`echo ${fc} | sed ['s/:[^:]*$//']`
229 bfdmachs=`echo ${fc} | sed 's/.*://'`
230 name=`echo ${c} | sed 's/:.*//'`
231 machine=`echo ${c} | sed 's/.*:\(.*\):.*/\1/'`
232 filter=`echo ${c} | sed 's/.*://'`
234 dnl Build the following lists:
236 dnl SIM_MIPS_IGEN_ITABLE_FLAGS: all -M and -F flags used by the simulator
237 dnl SIM_MIPS_MULTI_SRC: all makefile-generated source files
238 dnl SIM_MIPS_MULTI_OBJ: the objects for ${SIM_MIPS_MULTI_SRC}
239 dnl SIM_MIPS_MULTI_IGEN_CONFIGS: igen configuration strings.
241 dnl Each entry in ${SIM_MIPS_MULTI_IGEN_CONFIGS} is a prefix (m32
242 dnl or m16) followed by the NAME, MACHINE and FILTER part of
243 dnl the ${sim_mips_multi_configs} entry.
244 AS_VAR_APPEND([SIM_MIPS_IGEN_ITABLE_FLAGS], [" -F ${filter} -M ${machine}"])
246 dnl Check whether special handling is needed.
249 dnl Run igen twice, once for normal mode and once for mips16.
252 dnl The top-level function for the mips16 simulator is
253 dnl in a file m16${name}_run.c, generated by the
254 dnl tmp-run-multi Makefile rule.
255 AS_VAR_APPEND([SIM_MIPS_MULTI_SRC], [" mips/m16${name}_run.c"])
256 AS_VAR_APPEND([SIM_MIPS_MULTI_OBJ], [" mips/m16${name}_run.o"])
257 AS_VAR_APPEND([SIM_MIPS_IGEN_ITABLE_FLAGS], [" -F 16"])
259 [*:*micromips32*:*], [dnl
260 dnl Run igen thrice, once for micromips32, once for micromips16,
261 dnl and once for m32.
262 ws="micromips_m32 micromips16 micromips32"
264 dnl The top-level function for the micromips simulator is
265 dnl in a file micromips${name}_run.c, generated by the
266 dnl tmp-run-multi Makefile rule.
267 AS_VAR_APPEND([SIM_MIPS_MULTI_SRC], [" mips/micromips${name}_run.c"])
268 AS_VAR_APPEND([SIM_MIPS_MULTI_OBJ], [" mips/micromips${name}_run.o"])
269 AS_VAR_APPEND([SIM_MIPS_IGEN_ITABLE_FLAGS], [" -F 16,32"])
271 [*:*micromips64*:*], [dnl
272 dnl Run igen thrice, once for micromips64, once for micromips16,
273 dnl and once for m64.
274 ws="micromips_m64 micromips16 micromips64"
276 dnl The top-level function for the micromips simulator is
277 dnl in a file micromips${name}_run.c, generated by the
278 dnl tmp-run-multi Makefile rule.
279 AS_VAR_APPEND([SIM_MIPS_MULTI_SRC], [" mips/micromips${name}_run.c"])
280 AS_VAR_APPEND([SIM_MIPS_MULTI_OBJ], [" mips/micromips${name}_run.o"])
281 AS_VAR_APPEND([SIM_MIPS_IGEN_ITABLE_FLAGS], [" -F 16,32,64"])
285 dnl Now add the list of igen-generated files to ${SIM_MIPS_MULTI_SRC}
286 dnl and ${SIM_MIPS_MULTI_OBJ}.
288 for base in engine icache idecode model semantics support; do
289 AS_VAR_APPEND([SIM_MIPS_MULTI_SRC], [" mips/${w}${name}_${base}.c"])
290 AS_VAR_APPEND([SIM_MIPS_MULTI_SRC], [" mips/${w}${name}_${base}.h"])
291 AS_VAR_APPEND([SIM_MIPS_MULTI_OBJ], [" mips/${w}${name}_${base}.o"])
293 AS_VAR_APPEND([SIM_MIPS_MULTI_IGEN_CONFIGS], [" ${w}${c}"])
296 dnl Add an include for the engine.h file. This file declares the
297 dnl top-level foo_engine_run() function.
298 echo "#include \"${w}${name}_engine.h\"" >> mips/multi-include.h
300 dnl Add case statements for this engine to sim_engine_run().
301 for mach in `echo ${bfdmachs} | sed 's/,/ /g'`; do
302 echo " case bfd_mach_${mach}:" >> mips/multi-run.c
303 AS_VAR_IF([mach], ["${sim_mips_multi_default}"], [dnl
304 echo " default:" >> mips/multi-run.c
305 sim_mips_seen_default=yes
308 echo " ${w}${name}_engine_run (sd, next_cpu_nr, nr_cpus, signal);" \
310 echo " break;" >> mips/multi-run.c
313 dnl Check whether we added a 'default:' label.
314 AS_VAR_IF([sim_mips_seen_default], [no], [dnl
315 AC_MSG_ERROR(Error in configure.ac: \${sim_mips_multi_configs} doesn't have an entry for \${sim_mips_multi_default})])
317 cat << __EOF__ >> mips/multi-run.c
322 SIM_MIPS_IGEN_ITABLE_FLAGS='$(SIM_MIPS_SINGLE_FLAGS)'
323 AS_VAR_IF([SIM_MIPS_GEN], ["M16"], [AS_VAR_APPEND([SIM_MIPS_IGEN_ITABLE_FLAGS], [' $(SIM_MIPS_M16_FLAGS)'])])
325 SIM_MIPS_SINGLE_FLAGS="-F ${sim_mips_single_filter} ${sim_mips_single_machine}"
326 SIM_MIPS_M16_FLAGS="-F ${sim_mips_m16_filter} ${sim_mips_m16_machine}"
327 AC_SUBST(SIM_MIPS_SINGLE_FLAGS)
328 AC_SUBST(SIM_MIPS_M16_FLAGS)
329 AC_SUBST(SIM_MIPS_GEN)
330 AC_SUBST(SIM_MIPS_IGEN_ITABLE_FLAGS)
331 AC_SUBST(SIM_MIPS_MULTI_IGEN_CONFIGS)
332 AC_SUBST(SIM_MIPS_MULTI_SRC)
333 AC_SUBST(SIM_MIPS_MULTI_OBJ)
334 AM_CONDITIONAL([SIM_MIPS_GEN_MODE_SINGLE], [test "$SIM_MIPS_GEN" = "SINGLE"])
335 AM_CONDITIONAL([SIM_MIPS_GEN_MODE_M16], [test "$SIM_MIPS_GEN" = "M16"])
336 AM_CONDITIONAL([SIM_MIPS_GEN_MODE_MULTI], [test "$SIM_MIPS_GEN" = "MULTI"])