[PATCH] sim: move default model to the runtime sim state

Mike Frysinger vapier@gentoo.org
Wed Jun 30 03:23:37 GMT 2021


This kills off another compile-time option by moving the setting to
the individual arch runtimes.  This will allow dynamic selection by
the arch when doing a single build with multiple arches.

The sim_model_init rework is a little funky.  In the past it was
disabled entirely if no default model was set.  We maintain the
spirit of the logic by gating the fallback logic on whether the
port has defined any models.
---
 sim/Makefile.in                       |  1 -
 sim/bfin/aclocal.m4                   |  1 -
 sim/bfin/configure                    | 29 +------------------------
 sim/bfin/configure.ac                 |  2 --
 sim/bfin/interp.c                     |  1 +
 sim/bpf/aclocal.m4                    |  1 -
 sim/bpf/configure                     | 21 ------------------
 sim/bpf/configure.ac                  |  1 -
 sim/bpf/sim-if.c                      |  1 +
 sim/common/Make-common.in             |  2 --
 sim/common/sim-base.h                 |  4 ++++
 sim/common/sim-model.c                | 13 ++++++-----
 sim/common/sim-model.h                |  7 ------
 sim/configure                         |  6 ++----
 sim/configure.ac                      |  1 -
 sim/cris/aclocal.m4                   |  1 -
 sim/cris/configure                    | 25 +--------------------
 sim/cris/configure.ac                 |  3 ---
 sim/cris/sim-if.c                     |  1 +
 sim/frv/aclocal.m4                    |  1 -
 sim/frv/configure                     | 23 +-------------------
 sim/frv/configure.ac                  |  1 -
 sim/frv/sim-if.c                      |  1 +
 sim/iq2000/aclocal.m4                 |  1 -
 sim/iq2000/configure                  | 23 +-------------------
 sim/iq2000/configure.ac               |  1 -
 sim/iq2000/sim-if.c                   |  1 +
 sim/lm32/aclocal.m4                   |  1 -
 sim/lm32/configure                    | 23 +-------------------
 sim/lm32/configure.ac                 |  1 -
 sim/lm32/sim-if.c                     |  1 +
 sim/m32r/aclocal.m4                   |  1 -
 sim/m32r/configure                    | 23 +-------------------
 sim/m32r/configure.ac                 |  1 -
 sim/m32r/sim-if.c                     |  1 +
 sim/m4/sim_ac_option_default_model.m4 | 31 ---------------------------
 sim/m4/sim_ac_output.m4               |  1 -
 sim/mips/configure                    |  2 --
 sim/mn10300/configure                 |  2 --
 sim/or1k/aclocal.m4                   |  1 -
 sim/or1k/configure                    | 21 ------------------
 sim/or1k/configure.ac                 |  1 -
 sim/or1k/sim-if.c                     |  1 +
 sim/riscv/aclocal.m4                  |  1 -
 sim/riscv/configure                   | 28 ------------------------
 sim/riscv/configure.ac                |  8 -------
 sim/riscv/interp.c                    |  1 +
 sim/v850/configure                    |  2 --
 48 files changed, 27 insertions(+), 298 deletions(-)
 delete mode 100644 sim/m4/sim_ac_option_default_model.m4

diff --git a/sim/bfin/configure.ac b/sim/bfin/configure.ac
index 6cf5c4879584..99370b3a5770 100644
--- a/sim/bfin/configure.ac
+++ b/sim/bfin/configure.ac
@@ -2,6 +2,4 @@ dnl Process this file with autoconf to produce a configure script.
 AC_INIT(Makefile.in)
 AC_CONFIG_MACRO_DIRS([../m4 ../.. ../../config])
 
-SIM_AC_OPTION_DEFAULT_MODEL(bf537)
-
 SIM_AC_OUTPUT
diff --git a/sim/bfin/interp.c b/sim/bfin/interp.c
index dcc7a132d765..b99f20d91696 100644
--- a/sim/bfin/interp.c
+++ b/sim/bfin/interp.c
@@ -704,6 +704,7 @@ sim_open (SIM_OPEN_KIND kind, host_callback *callback,
 
   /* Set default options before parsing user options.  */
   STATE_MACHS (sd) = bfin_sim_machs;
+  STATE_MODEL_NAME (sd) = "bf537";
   current_alignment = STRICT_ALIGNMENT;
   current_target_byte_order = BFD_ENDIAN_LITTLE;
 
diff --git a/sim/bpf/configure.ac b/sim/bpf/configure.ac
index 32729370b5aa..9cbd202d590d 100644
--- a/sim/bpf/configure.ac
+++ b/sim/bpf/configure.ac
@@ -4,6 +4,5 @@ AC_CONFIG_MACRO_DIRS([../m4 ../.. ../../config])
 
 SIM_AC_OPTION_BITSIZE([64])
 SIM_AC_OPTION_SCACHE(16384)
-SIM_AC_OPTION_DEFAULT_MODEL([bpf-def])
 
 SIM_AC_OUTPUT
diff --git a/sim/bpf/sim-if.c b/sim/bpf/sim-if.c
index 150f5cd67861..aba191df7ec4 100644
--- a/sim/bpf/sim-if.c
+++ b/sim/bpf/sim-if.c
@@ -129,6 +129,7 @@ sim_open (SIM_OPEN_KIND kind,
 
   /* Set default options before parsing user options.  */
   STATE_MACHS (sd) = bpf_sim_machs;
+  STATE_MODEL_NAME (sd) = "bpf-def";
 
   if (sim_cpu_alloc_all (sd, 1) != SIM_RC_OK)
     goto error;
diff --git a/sim/common/Make-common.in b/sim/common/Make-common.in
index 723bda589c9b..992fd7f8a6ef 100644
--- a/sim/common/Make-common.in
+++ b/sim/common/Make-common.in
@@ -73,7 +73,6 @@ top_builddir = ..
 SHELL = @SHELL@
 
 SIM_BITSIZE = @sim_bitsize@
-SIM_DEFAULT_MODEL = @sim_default_model@
 SIM_FLOAT = @sim_float@
 SIM_RESERVED_BITS = @sim_reserved_bits@
 SIM_SCACHE = @sim_scache@
@@ -195,7 +194,6 @@ CGEN_INCLUDE_DEPS = \
 
 CONFIG_CFLAGS = \
 	-DHAVE_CONFIG_H \
-	$(SIM_DEFAULT_MODEL) \
 	$(SIM_BITSIZE) \
 	$(SIM_FLOAT) \
 	$(SIM_HW_CFLAGS) \
diff --git a/sim/common/sim-base.h b/sim/common/sim-base.h
index c32a200b36aa..47abbe1ee86b 100644
--- a/sim/common/sim-base.h
+++ b/sim/common/sim-base.h
@@ -147,6 +147,10 @@ struct sim_state {
   const SIM_MACH * const *machs;
 #define STATE_MACHS(sd) ((sd)->machs)
 
+  /* If non-NULL, the model to select for CPUs.  */
+  const char *model_name;
+#define STATE_MODEL_NAME(sd) ((sd)->model_name)
+
   /* In standalone simulator, this is the program's arguments passed
      on the command line.  */
   char **prog_argv;
diff --git a/sim/common/sim-model.c b/sim/common/sim-model.c
index 4c5e463f1a07..98dcbeae6cc1 100644
--- a/sim/common/sim-model.c
+++ b/sim/common/sim-model.c
@@ -68,6 +68,7 @@ model_option_handler (SIM_DESC sd, sim_cpu *cpu, int opt,
 	    sim_io_eprintf (sd, "unknown model `%s'\n", arg);
 	    return SIM_RC_FAIL;
 	  }
+	STATE_MODEL_NAME (sd) = arg;
 	sim_model_set (sd, cpu, model);
 	break;
       }
@@ -209,9 +210,6 @@ sim_model_init (SIM_DESC sd)
 {
   SIM_CPU *cpu;
 
-  if (!WITH_MODEL_P)
-    return SIM_RC_OK;
-
   /* If both cpu model and state architecture are set, ensure they're
      compatible.  If only one is set, set the other.  If neither are set,
      use the default model.  STATE_ARCHITECTURE is the bfd_arch_info data
@@ -222,10 +220,11 @@ sim_model_init (SIM_DESC sd)
   cpu = STATE_CPU (sd, 0);
 
   if (! STATE_ARCHITECTURE (sd)
-      && ! CPU_MACH (cpu))
+      && ! CPU_MACH (cpu)
+      && STATE_MODEL_NAME (sd))
     {
       /* Set the default model.  */
-      const SIM_MODEL *model = sim_model_lookup (sd, WITH_DEFAULT_MODEL);
+      const SIM_MODEL *model = sim_model_lookup (sd, STATE_MODEL_NAME (sd));
       SIM_ASSERT (model != NULL);
       sim_model_set (sd, NULL, model);
     }
@@ -242,7 +241,7 @@ sim_model_init (SIM_DESC sd)
 	  return SIM_RC_FAIL;
 	}
     }
-  else if (STATE_ARCHITECTURE (sd))
+  else if (STATE_ARCHITECTURE (sd) && STATE_MACHS (sd))
     {
       /* Use the default model for the selected machine.
 	 The default model is the first one in the list.  */
@@ -257,7 +256,7 @@ sim_model_init (SIM_DESC sd)
 	}
       sim_model_set (sd, NULL, MACH_MODELS (mach));
     }
-  else
+  else if (CPU_MACH (cpu))
     {
       STATE_ARCHITECTURE (sd) = bfd_scan_arch (MACH_BFD_NAME (CPU_MACH (cpu)));
     }
diff --git a/sim/common/sim-model.h b/sim/common/sim-model.h
index e735feb4b9ad..ecef2571766e 100644
--- a/sim/common/sim-model.h
+++ b/sim/common/sim-model.h
@@ -47,13 +47,6 @@ typedef struct {
 #define MAX_UNITS 1
 #endif
 
-#ifndef WITH_DEFAULT_MODEL
-# define WITH_DEFAULT_MODEL NULL
-# define WITH_MODEL_P 0
-#else
-# define WITH_MODEL_P 1
-#endif
-
 typedef int (MODEL_FN) (sim_cpu *, void *);
 
 typedef struct {
diff --git a/sim/configure.ac b/sim/configure.ac
index 15b2b65c87e8..0b31d2c5eefa 100644
--- a/sim/configure.ac
+++ b/sim/configure.ac
@@ -172,7 +172,6 @@ dnl respective SIM_AC_OPTION_xxx call above, we can drop these.
 AC_SUBST(sim_bitsize)
 AC_SUBST(sim_float)
 AC_SUBST(sim_scache)
-AC_SUBST(sim_default_model)
 AC_SUBST(sim_reserved_bits)
 
 dnl Some arches have unique configure flags.
diff --git a/sim/cris/configure.ac b/sim/cris/configure.ac
index 57a2d5fe3d7a..d2037221bfee 100644
--- a/sim/cris/configure.ac
+++ b/sim/cris/configure.ac
@@ -4,7 +4,4 @@ AC_CONFIG_MACRO_DIRS([../m4 ../.. ../../config])
 
 SIM_AC_OPTION_SCACHE(16384)
 
-# The default model shouldn't matter as long as there's a BFD.
-SIM_AC_OPTION_DEFAULT_MODEL(crisv32)
-
 SIM_AC_OUTPUT
diff --git a/sim/cris/sim-if.c b/sim/cris/sim-if.c
index 37a1d5b558a0..2d7e9221505a 100644
--- a/sim/cris/sim-if.c
+++ b/sim/cris/sim-if.c
@@ -659,6 +659,7 @@ sim_open (SIM_OPEN_KIND kind, host_callback *callback, struct bfd *abfd,
 
   /* Set default options before parsing user options.  */
   STATE_MACHS (sd) = cris_sim_machs;
+  STATE_MODEL_NAME (sd) = "crisv32";
   current_target_byte_order = BFD_ENDIAN_LITTLE;
 
   /* The cpu data is kept in a separately allocated chunk of memory.  */
diff --git a/sim/frv/configure.ac b/sim/frv/configure.ac
index 83ad0112844d..785a3bc1cc23 100644
--- a/sim/frv/configure.ac
+++ b/sim/frv/configure.ac
@@ -3,7 +3,6 @@ AC_INIT(Makefile.in)
 AC_CONFIG_MACRO_DIRS([../m4 ../.. ../../config])
 
 SIM_AC_OPTION_SCACHE(16384)
-SIM_AC_OPTION_DEFAULT_MODEL(fr500)
 
 #
 # Enable making unknown traps dump out registers
diff --git a/sim/frv/sim-if.c b/sim/frv/sim-if.c
index 82f4bd845f5d..6d22aaddc090 100644
--- a/sim/frv/sim-if.c
+++ b/sim/frv/sim-if.c
@@ -57,6 +57,7 @@ sim_open (SIM_OPEN_KIND kind, host_callback *callback, bfd *abfd,
 
   /* Set default options before parsing user options.  */
   STATE_MACHS (sd) = frv_sim_machs;
+  STATE_MODEL_NAME (sd) = "fr500";
   current_alignment = STRICT_ALIGNMENT;
   current_target_byte_order = BFD_ENDIAN_BIG;
 
diff --git a/sim/iq2000/configure.ac b/sim/iq2000/configure.ac
index e35068f31f8c..d2037221bfee 100644
--- a/sim/iq2000/configure.ac
+++ b/sim/iq2000/configure.ac
@@ -3,6 +3,5 @@ AC_INIT(Makefile.in)
 AC_CONFIG_MACRO_DIRS([../m4 ../.. ../../config])
 
 SIM_AC_OPTION_SCACHE(16384)
-SIM_AC_OPTION_DEFAULT_MODEL(iq2000)
 
 SIM_AC_OUTPUT
diff --git a/sim/iq2000/sim-if.c b/sim/iq2000/sim-if.c
index 6df4b944300e..9728882dac51 100644
--- a/sim/iq2000/sim-if.c
+++ b/sim/iq2000/sim-if.c
@@ -64,6 +64,7 @@ sim_open (SIM_OPEN_KIND kind, host_callback *callback, struct bfd *abfd,
 
   /* Set default options before parsing user options.  */
   STATE_MACHS (sd) = iq2000_sim_machs;
+  STATE_MODEL_NAME (sd) = "iq2000";
   current_alignment = STRICT_ALIGNMENT;
   current_target_byte_order = BFD_ENDIAN_BIG;
 
diff --git a/sim/lm32/configure.ac b/sim/lm32/configure.ac
index 96b6f0e98e25..d2037221bfee 100644
--- a/sim/lm32/configure.ac
+++ b/sim/lm32/configure.ac
@@ -3,6 +3,5 @@ AC_INIT(Makefile.in)
 AC_CONFIG_MACRO_DIRS([../m4 ../.. ../../config])
 
 SIM_AC_OPTION_SCACHE(16384)
-SIM_AC_OPTION_DEFAULT_MODEL(lm32)
 
 SIM_AC_OUTPUT
diff --git a/sim/lm32/sim-if.c b/sim/lm32/sim-if.c
index abb9ad7b042c..f9143ea00375 100644
--- a/sim/lm32/sim-if.c
+++ b/sim/lm32/sim-if.c
@@ -95,6 +95,7 @@ sim_open (SIM_OPEN_KIND kind, host_callback *callback, struct bfd *abfd,
 
   /* Set default options before parsing user options.  */
   STATE_MACHS (sd) = lm32_sim_machs;
+  STATE_MODEL_NAME (sd) = "lm32";
   current_alignment = STRICT_ALIGNMENT;
   current_target_byte_order = BFD_ENDIAN_BIG;
 
diff --git a/sim/m32r/configure.ac b/sim/m32r/configure.ac
index f98adb26c46d..eed2e91c87a7 100644
--- a/sim/m32r/configure.ac
+++ b/sim/m32r/configure.ac
@@ -3,7 +3,6 @@ AC_INIT(Makefile.in)
 AC_CONFIG_MACRO_DIRS([../m4 ../.. ../../config])
 
 SIM_AC_OPTION_SCACHE(16384)
-SIM_AC_OPTION_DEFAULT_MODEL(m32r/d)
 
   case "${target_alias}" in
   m32r*-linux*)
diff --git a/sim/m32r/sim-if.c b/sim/m32r/sim-if.c
index 33ae7c106e39..8957e83bf334 100644
--- a/sim/m32r/sim-if.c
+++ b/sim/m32r/sim-if.c
@@ -58,6 +58,7 @@ sim_open (SIM_OPEN_KIND kind, host_callback *callback, struct bfd *abfd,
 
   /* Set default options before parsing user options.  */
   STATE_MACHS (sd) = m32r_sim_machs;
+  STATE_MODEL_NAME (sd) = "m32r/d";
   current_alignment = STRICT_ALIGNMENT;
   current_target_byte_order = BFD_ENDIAN_BIG;
 
diff --git a/sim/m4/sim_ac_option_default_model.m4 b/sim/m4/sim_ac_option_default_model.m4
deleted file mode 100644
index 115093734bc6..000000000000
--- a/sim/m4/sim_ac_option_default_model.m4
+++ /dev/null
@@ -1,31 +0,0 @@
-dnl   Copyright (C) 1997-2021 Free Software Foundation, Inc.
-dnl
-dnl This program is free software; you can redistribute it and/or modify
-dnl it under the terms of the GNU General Public License as published by
-dnl the Free Software Foundation; either version 3 of the License, or
-dnl (at your option) any later version.
-dnl
-dnl This program is distributed in the hope that it will be useful,
-dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
-dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-dnl GNU General Public License for more details.
-dnl
-dnl You should have received a copy of the GNU General Public License
-dnl along with this program.  If not, see <http://www.gnu.org/licenses/>.
-dnl
-dnl The argument is the default model if none is specified.
-AC_DEFUN([SIM_AC_OPTION_DEFAULT_MODEL],
-[
-default_sim_default_model="ifelse([$1],,0,[$1])"
-AC_ARG_ENABLE(sim-default-model,
-[AS_HELP_STRING([--enable-sim-default-model=model],
-		[Specify default model to simulate])],
-[case "${enableval}" in
-  yes|no) AC_MSG_ERROR("Missing argument to --enable-sim-default-model");;
-  *)	sim_default_model="-DWITH_DEFAULT_MODEL='\"${enableval}\"'";;
-esac
-if test x"$silent" != x"yes" && test x"$sim_default_model" != x""; then
-  echo "Setting default model = $sim_default_model" 6>&1
-fi],[sim_default_model="-DWITH_DEFAULT_MODEL='\"${default_sim_default_model}\"'"])
-])
-AC_SUBST(sim_default_model)
diff --git a/sim/m4/sim_ac_output.m4 b/sim/m4/sim_ac_output.m4
index f9f70167e59c..100e2f9b4024 100644
--- a/sim/m4/sim_ac_output.m4
+++ b/sim/m4/sim_ac_output.m4
@@ -48,7 +48,6 @@ dnl when the rest of the code is in the respective macros.
 AC_SUBST(sim_bitsize)
 AC_SUBST(sim_float)
 AC_SUBST(sim_scache)
-AC_SUBST(sim_default_model)
 AC_SUBST(sim_reserved_bits)
 
 dnl Used by common/Make-common.in to see which configure script created it.
diff --git a/sim/or1k/configure.ac b/sim/or1k/configure.ac
index c72c80c5f47a..aaeb12135654 100644
--- a/sim/or1k/configure.ac
+++ b/sim/or1k/configure.ac
@@ -4,6 +4,5 @@ AC_CONFIG_MACRO_DIRS([../m4 ../.. ../../config])
 
 SIM_AC_OPTION_BITSIZE([32], [31], [32])
 SIM_AC_OPTION_SCACHE(16384)
-SIM_AC_OPTION_DEFAULT_MODEL([or1200])
 
 SIM_AC_OUTPUT
diff --git a/sim/or1k/sim-if.c b/sim/or1k/sim-if.c
index e8353887c828..3f47ce5e41b6 100644
--- a/sim/or1k/sim-if.c
+++ b/sim/or1k/sim-if.c
@@ -164,6 +164,7 @@ sim_open (SIM_OPEN_KIND kind, host_callback *callback, struct bfd *abfd,
 
   /* Set default options before parsing user options.  */
   STATE_MACHS (sd) = or1k_sim_machs;
+  STATE_MODEL_NAME (sd) = "or1200";
   current_target_byte_order = BFD_ENDIAN_BIG;
 
   /* The cpu data is kept in a separately allocated chunk of memory.  */
diff --git a/sim/riscv/configure.ac b/sim/riscv/configure.ac
index 01afe511ca8e..6edb28c863ed 100644
--- a/sim/riscv/configure.ac
+++ b/sim/riscv/configure.ac
@@ -2,14 +2,6 @@ dnl Process this file with autoconf to produce a configure script.
 AC_INIT(Makefile.in)
 AC_CONFIG_MACRO_DIRS([../m4 ../.. ../../config])
 
-# Select the default model for the target.
-riscv_model=
-case "${target}" in
-riscv32*) riscv_model="RV32G" ;;
-riscv*) riscv_model="RV64G" ;;
-esac
-SIM_AC_OPTION_DEFAULT_MODEL(${riscv_model})
-
 # Select the bitsize of the target.
 riscv_addr_bitsize=
 case "${target}" in
diff --git a/sim/riscv/interp.c b/sim/riscv/interp.c
index 8908ed12ae87..202412ab8ca0 100644
--- a/sim/riscv/interp.c
+++ b/sim/riscv/interp.c
@@ -66,6 +66,7 @@ sim_open (SIM_OPEN_KIND kind, host_callback *callback,
 
   /* Set default options before parsing user options.  */
   STATE_MACHS (sd) = riscv_sim_machs;
+  STATE_MODEL_NAME (sd) = WITH_TARGET_WORD_BITSIZE == 32 ? "RV32G" : "RV64G";
   current_target_byte_order = BFD_ENDIAN_LITTLE;
 
   /* The cpu data is kept in a separately allocated chunk of memory.  */
-- 
2.31.1



More information about the Gdb-patches mailing list