1dnl Process this file with autoconf to produce a configure script.
2AC_INIT(Makefile.in)
3AC_CONFIG_MACRO_DIRS([../m4 ../.. ../../config])
4
5dnl The sim shouldn't be checking $target and changing behavior.  But it is,
6dnl and until we clean that up, we need to expand --target for use below.
7AC_CANONICAL_SYSTEM
8
9# DEPRECATED
10#
11# Instead of defining a `subtarget' macro, code should be checking
12# the value of {STATE,CPU}_ARCHITECTURE to identify the architecture
13# in question.
14#
15case "${target}" in
16  mips64vr*-*-*)	SIM_SUBTARGET="-DTARGET_ENABLE_FR=1" ;;
17  mips*tx39*)           SIM_SUBTARGET="-DSUBTARGET_R3900=1";;
18  mips*-sde-elf*)       SIM_SUBTARGET="-DTARGET_ENABLE_FR=1";;
19  mips*-mti-elf*)       SIM_SUBTARGET="-DTARGET_ENABLE_FR=1";;
20  mipsisa32*-*-*)       SIM_SUBTARGET="-DTARGET_ENABLE_FR=1";;
21  mipsisa64*-*-*)       SIM_SUBTARGET="-DTARGET_ENABLE_FR=1";;
22  *)                    SIM_SUBTARGET="";;
23esac
24AC_SUBST(SIM_SUBTARGET)
25
26
27
28#
29# Select the bitsize of the target
30#
31case "${target}" in
32  mips*-sde-elf*)       mips_bitsize=64 ; mips_msb=63 ;;
33  mips*-mti-elf*)       mips_bitsize=64 ; mips_msb=63 ;;
34  mips64*-*-*)          mips_bitsize=64 ; mips_msb=63 ;;
35  mips16*-*-*)          mips_bitsize=64 ; mips_msb=63 ;;
36  mipsisa32*-*-*)       mips_bitsize=32 ; mips_msb=31 ;;
37  mipsisa64*-*-*)       mips_bitsize=64 ; mips_msb=63 ;;
38  mips*-*-*)            mips_bitsize=32 ; mips_msb=31 ;;
39  *)                    mips_bitsize=64 ; mips_msb=63 ;;
40esac
41SIM_AC_OPTION_BITSIZE($mips_bitsize,$mips_msb)
42
43
44
45#
46# Select the floating hardware support of the target
47#
48mips_fpu_bitsize=
49case "${target}" in
50  mips*tx39*)           mips_fpu_bitsize=32 ;;
51  mips*-sde-elf*)       mips_fpu_bitsize=64 ;;
52  mips*-mti-elf*)       mips_fpu_bitsize=64 ;;
53  mipsisa32*-*-*)       mips_fpu_bitsize=64 ;;
54  mipsisa64*-*-*)       mips_fpu_bitsize=64 ;;
55  mips*-*-*)            mips_fpu_bitsize=32 ;;
56esac
57SIM_AC_OPTION_FLOAT(HARD_FLOATING_POINT,$mips_fpu_bitsize)
58
59
60
61#
62# Select the IGEN architecture
63#
64sim_gen=IGEN
65sim_igen_machine="-M mipsIV"
66sim_m16_machine="-M mips16,mipsIII"
67sim_igen_filter="32,64,f"
68sim_m16_filter="16"
69sim_mach_default="mips8000"
70
71case "${target}" in
72  mips*tx39*)		sim_gen=IGEN
73			sim_igen_filter="32,f"
74			sim_igen_machine="-M r3900"
75			;;
76  mips64vr43*-*-*)	sim_gen=IGEN
77			sim_igen_machine="-M mipsIV"
78			sim_mach_default="mips8000"
79			;;
80  mips64vr5*-*-*)	sim_gen=IGEN
81			sim_igen_machine="-M vr5000"
82			sim_mach_default="mips5000"
83			;;
84  mips64vr41*)		sim_gen=M16
85			sim_igen_machine="-M vr4100"
86			sim_m16_machine="-M vr4100"
87			sim_igen_filter="32,64,f"
88			sim_m16_filter="16"
89			sim_mach_default="mips4100"
90                        ;;
91  mips64vr-*-* | mips64vrel-*-*)
92			sim_gen=MULTI
93			sim_multi_configs="\
94			  vr4100:mipsIII,mips16,vr4100:32,64:mips4100,mips4111\
95			  vr4120:mipsIII,mips16,vr4120:32,64:mips4120\
96			  vr5000:mipsIV:32,64,f:mips4300,mips5000\
97			  vr5400:mipsIV,vr5400:32,64,f:mips5400\
98			  vr5500:mipsIV,vr5500:32,64,f:mips5500"
99			sim_multi_default=mips5000
100			;;
101  mips*-sde-elf* | mips*-mti-elf*)
102			sim_gen=MULTI
103			sim_multi_configs="\
104			  micromips:micromips64,micromipsdsp:32,64,f:mips_micromips\
105			  mipsisa64r2:mips64r2,mips16,mips16e,mdmx,dsp,dsp2,mips3d,smartmips:32,64,f:mipsisa32r2,mipsisa64r2,mipsisa32r5,mipsisa64r5\
106			  mipsisa64r6:mips64r6:32,64,f:mipsisa32r6,mipsisa64r6"
107			sim_multi_default=mipsisa64r2
108			;;
109  mips64*-*-*)		sim_igen_filter="32,64,f"
110			sim_gen=IGEN
111			;;
112  mips16*-*-*)		sim_gen=M16
113			sim_igen_filter="32,64,f"
114			sim_m16_filter="16"
115			;;
116  mipsisa32r2*-*-*)	sim_gen=MULTI
117			sim_multi_configs="\
118			  micromips:micromips32,micromipsdsp:32,f:mips_micromips\
119			  mips32r2:mips32r2,mips3d,mips16,mips16e,mdmx,dsp,dsp2,smartmips:32,f:mipsisa32r2"
120			sim_multi_default=mipsisa32r2
121			;;
122  mipsisa32r6*-*-*)	sim_gen=IGEN
123			sim_igen_machine="-M mips32r6"
124			sim_igen_filter="32,f"
125			sim_mach_default="mipsisa32r6"
126			;;
127  mipsisa32*-*-*)	sim_gen=M16
128			sim_igen_machine="-M mips32,mips16,mips16e,smartmips"
129			sim_m16_machine="-M mips16,mips16e,mips32"
130			sim_igen_filter="32,f"
131			sim_mach_default="mipsisa32"
132			;;
133  mipsisa64r2*-*-*)	sim_gen=M16
134			sim_igen_machine="-M mips64r2,mips3d,mips16,mips16e,mdmx,dsp,dsp2"
135			sim_m16_machine="-M mips16,mips16e,mips64r2"
136			sim_igen_filter="32,64,f"
137			sim_mach_default="mipsisa64r2"
138			;;
139  mipsisa64r6*-*-*)	sim_gen=IGEN
140			sim_igen_machine="-M mips64r6"
141			sim_igen_filter="32,64,f"
142			sim_mach_default="mipsisa64r6"
143			;;
144  mipsisa64sb1*-*-*)	sim_gen=IGEN
145			sim_igen_machine="-M mips64,mips3d,sb1"
146			sim_igen_filter="32,64,f"
147			sim_mach_default="mips_sb1"
148			;;
149  mipsisa64*-*-*)	sim_gen=M16
150			sim_igen_machine="-M mips64,mips3d,mips16,mips16e,mdmx"
151			sim_m16_machine="-M mips16,mips16e,mips64"
152			sim_igen_filter="32,64,f"
153			sim_mach_default="mipsisa64"
154			;;
155  mips*lsi*)		sim_gen=M16
156			sim_igen_machine="-M mipsIII,mips16"
157			sim_m16_machine="-M mips16,mipsIII"
158			sim_igen_filter="32,f"
159			sim_m16_filter="16"
160			sim_mach_default="mips4000"
161			;;
162  mips*-*-*)		sim_gen=IGEN
163			sim_igen_filter="32,f"
164			;;
165esac
166
167# The MULTI generator can combine several simulation engines into one.
168# executable.  A configuration which uses the MULTI should set two
169# variables: ${sim_multi_configs} and ${sim_multi_default}.
170#
171# ${sim_multi_configs} is the list of engines to build.  Each
172# space-separated entry has the form NAME:MACHINE:FILTER:BFDMACHS,
173# where:
174#
175# - NAME is a C-compatible prefix for the engine,
176# - MACHINE is a -M argument,
177# - FILTER is a -F argument, and
178# - BFDMACHS is a comma-separated list of bfd machines that the
179#     simulator can run.
180#
181# Each entry will have a separate simulation engine whose prefix is
182# m32<NAME>.  If the machine list includes "mips16", there will also
183# be a mips16 engine, prefix m16<NAME>.  The mips16 engine will be
184# generated using the same machine list as the 32-bit version,
185# but the filter will be "16" instead of FILTER.
186#
187# The simulator compares the bfd mach against BFDMACHS to decide
188# which engine to use.  Entries in BFDMACHS should be bfd_mach
189# values with "bfd_mach_" removed.  ${sim_multi_default} says
190# which entry should be the default.
191if test ${sim_gen} = MULTI; then
192
193  # Simple sanity check.
194  if test -z "${sim_multi_configs}" || test -z "${sim_multi_default}"; then
195    AC_MSG_ERROR(Error in configure.ac: MULTI simulator not set up correctly)
196  fi
197
198  # Start in a known state.
199  rm -f multi-include.h multi-run.c
200  sim_multi_flags=
201  sim_multi_src=
202  sim_multi_obj=
203  sim_multi_igen_configs=
204  sim_seen_default=no
205
206  cat << __EOF__ > multi-run.c
207/* Main entry point for MULTI simulators.
208   Copyright (C) 2003-2023 Free Software Foundation, Inc.
209
210   This program is free software; you can redistribute it and/or modify
211   it under the terms of the GNU General Public License as published by
212   the Free Software Foundation; either version 3 of the License, or
213   (at your option) any later version.
214
215   This program is distributed in the hope that it will be useful,
216   but WITHOUT ANY WARRANTY; without even the implied warranty of
217   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
218   GNU General Public License for more details.
219
220   You should have received a copy of the GNU General Public License
221   along with this program.  If not, see <http://www.gnu.org/licenses/>.
222
223   --
224
225   This file was generated by sim/mips/configure.  */
226
227#include "sim-main.h"
228#include "multi-include.h"
229#include "elf-bfd.h"
230#include "elfxx-mips.h"
231#include "elf/mips.h"
232
233#define SD sd
234#define CPU cpu
235
236void
237sim_engine_run (SIM_DESC sd,
238		int next_cpu_nr,
239		int nr_cpus,
240		int signal) /* ignore */
241{
242  int mach;
243
244  if (STATE_ARCHITECTURE (sd) == NULL)
245    mach = bfd_mach_${sim_multi_default};
246  else if (elf_elfheader (STATE_PROG_BFD (sd))->e_flags
247	   & EF_MIPS_ARCH_ASE_MICROMIPS)
248    mach = bfd_mach_mips_micromips;
249  else
250  {
251     mach = _bfd_elf_mips_mach (elf_elfheader (STATE_PROG_BFD (sd))->e_flags);
252     if (!mach)
253       mach = STATE_ARCHITECTURE (SD)->mach;
254  }
255
256  switch (mach)
257    {
258__EOF__
259
260  for fc in ${sim_multi_configs}; do
261
262    # Split up the entry.  ${c} contains the first three elements.
263    # Note: outer sqaure brackets are m4 quotes.
264    c=`echo ${fc} | sed ['s/:[^:]*$//']`
265    bfdmachs=`echo ${fc} | sed 's/.*://'`
266    name=`echo ${c} | sed 's/:.*//'`
267    machine=`echo ${c} | sed 's/.*:\(.*\):.*/\1/'`
268    filter=`echo ${c} | sed 's/.*://'`
269
270    # Build the following lists:
271    #
272    #   sim_multi_flags: all -M and -F flags used by the simulator
273    #   sim_multi_src: all makefile-generated source files
274    #   sim_multi_obj: the objects for ${sim_multi_src}
275    #   sim_multi_igen_configs: igen configuration strings.
276    #
277    # Each entry in ${sim_multi_igen_configs} is a prefix (m32
278    # or m16) followed by the NAME, MACHINE and FILTER part of
279    # the ${sim_multi_configs} entry.
280    sim_multi_flags="${sim_multi_flags} -F ${filter} -M ${machine}"
281
282    # Check whether special handling is needed.
283    case ${c} in
284      *:*mips16*:*)
285	# Run igen twice, once for normal mode and once for mips16.
286	ws="m32 m16"
287
288	# The top-level function for the mips16 simulator is
289	# in a file m16${name}_run.c, generated by the
290	# tmp-run-multi Makefile rule.
291	sim_multi_src="${sim_multi_src} m16${name}_run.c"
292	sim_multi_obj="${sim_multi_obj} m16${name}_run.o"
293	sim_multi_flags="${sim_multi_flags} -F 16"
294	;;
295      *:*micromips32*:*)
296	# Run igen thrice, once for micromips32, once for micromips16,
297	# and once for m32.
298	ws="micromips_m32 micromips16 micromips32"
299
300	# The top-level function for the micromips simulator is
301	# in a file micromips${name}_run.c, generated by the
302	# tmp-run-multi Makefile rule.
303	sim_multi_src="${sim_multi_src} micromips${name}_run.c"
304	sim_multi_obj="${sim_multi_obj} micromips${name}_run.o"
305	sim_multi_flags="${sim_multi_flags} -F 16,32"
306	;;
307      *:*micromips64*:*)
308	# Run igen thrice, once for micromips64, once for micromips16,
309	# and once for m64.
310	ws="micromips_m64 micromips16 micromips64"
311
312	# The top-level function for the micromips simulator is
313	# in a file micromips${name}_run.c, generated by the
314	# tmp-run-multi Makefile rule.
315	sim_multi_src="${sim_multi_src} micromips${name}_run.c"
316	sim_multi_obj="${sim_multi_obj} micromips${name}_run.o"
317	sim_multi_flags="${sim_multi_flags} -F 16,32,64"
318	;;
319      *)
320	ws=m32
321	;;
322    esac
323
324    # Now add the list of igen-generated files to ${sim_multi_src}
325    # and ${sim_multi_obj}.
326    for w in ${ws}; do
327      for base in engine icache idecode model semantics support; do
328	sim_multi_src="${sim_multi_src} ${w}${name}_${base}.c"
329	sim_multi_src="${sim_multi_src} ${w}${name}_${base}.h"
330	sim_multi_obj="${sim_multi_obj} ${w}${name}_${base}.o"
331      done
332      sim_multi_igen_configs="${sim_multi_igen_configs} ${w}${c}"
333    done
334
335    # Add an include for the engine.h file.  This file declares the
336    # top-level foo_engine_run() function.
337    echo "#include \"${w}${name}_engine.h\"" >> multi-include.h
338
339    # Add case statements for this engine to sim_engine_run().
340    for mach in `echo ${bfdmachs} | sed 's/,/ /g'`; do
341      echo "    case bfd_mach_${mach}:" >> multi-run.c
342      if test ${mach} = ${sim_multi_default}; then
343	echo "    default:" >> multi-run.c
344	sim_seen_default=yes
345      fi
346    done
347    echo "      ${w}${name}_engine_run (sd, next_cpu_nr, nr_cpus, signal);" \
348      >> multi-run.c
349    echo "      break;" >> multi-run.c
350  done
351
352  # Check whether we added a 'default:' label.
353  if test ${sim_seen_default} = no; then
354    AC_MSG_ERROR(Error in configure.ac: \${sim_multi_configs} doesn't have an entry for \${sim_multi_default})
355  fi
356
357  cat << __EOF__ >> multi-run.c
358    }
359}
360
361int
362mips_mach_multi (SIM_DESC sd)
363{
364  if (STATE_ARCHITECTURE (sd) == NULL)
365    return bfd_mach_${sim_multi_default};
366
367  switch (STATE_ARCHITECTURE (SD)->mach)
368    {
369__EOF__
370
371  # Add case statements for this engine to mips_mach_multi().
372  for fc in ${sim_multi_configs}; do
373
374    # Split up the entry.  ${c} contains the first three elements.
375    # Note: outer sqaure brackets are m4 quotes.
376    c=`echo ${fc} | sed ['s/:[^:]*$//']`
377    bfdmachs=`echo ${fc} | sed 's/.*://'`
378
379    for mach in `echo ${bfdmachs} | sed 's/,/ /g'`; do
380      echo "    case bfd_mach_${mach}:" >> multi-run.c
381    done
382  done
383
384  cat << __EOF__ >> multi-run.c
385      return (STATE_ARCHITECTURE (SD)->mach);
386    default:
387      return bfd_mach_${sim_multi_default};
388    }
389}
390__EOF__
391
392  SIM_SUBTARGET="$SIM_SUBTARGET -DMIPS_MACH_MULTI"
393else
394  # For clean-extra
395  sim_multi_src=doesnt-exist.c
396
397  if test x"${sim_mach_default}" = x""; then
398    AC_MSG_ERROR(Error in configure.ac: \${sim_mach_default} not defined)
399  fi
400  SIM_SUBTARGET="$SIM_SUBTARGET -DMIPS_MACH_DEFAULT=bfd_mach_${sim_mach_default}"
401fi
402sim_igen_flags="-F ${sim_igen_filter} ${sim_igen_machine} ${sim_igen_smp}"
403sim_m16_flags=" -F ${sim_m16_filter}  ${sim_m16_machine}  ${sim_igen_smp}"
404sim_micromips16_flags=" -F ${sim_micromips16_filter}  ${sim_micromips16_machine}  ${sim_igen_smp}"
405sim_micromips_flags=" -F ${sim_micromips_filter}  ${sim_micromips_machine}  ${sim_igen_smp}"
406AC_SUBST(sim_igen_flags)
407AC_SUBST(sim_m16_flags)
408AC_SUBST(sim_micromips_flags)
409AC_SUBST(sim_micromips16_flags)
410AC_SUBST(sim_gen)
411AC_SUBST(sim_multi_flags)
412AC_SUBST(sim_multi_igen_configs)
413AC_SUBST(sim_multi_src)
414AC_SUBST(sim_multi_obj)
415
416SIM_AC_OUTPUT
417