/* Model support.
- Copyright (C) 1996-2017 Free Software Foundation, Inc.
+ Copyright (C) 1996-2021 Free Software Foundation, Inc.
Contributed by Cygnus Support.
This file is part of GDB, the GNU debugger.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
+/* This must come before any other includes. */
+#include "defs.h"
+
#include "sim-main.h"
#include "sim-model.h"
#include "libiberty.h"
{
case OPTION_MODEL :
{
- const SIM_MODEL *model = sim_model_lookup (arg);
+ const SIM_MODEL *model = sim_model_lookup (sd, arg);
if (! model)
{
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;
}
case OPTION_MODEL_INFO :
{
- const SIM_MACH **machp;
+ const SIM_MACH * const *machp;
const SIM_MODEL *model;
- for (machp = & sim_machs[0]; *machp != NULL; ++machp)
+
+ if (STATE_MACHS (sd) == NULL)
+ {
+ sim_io_printf (sd, "This target does not support any models\n");
+ return SIM_RC_FAIL;
+ }
+
+ for (machp = STATE_MACHS(sd); *machp != NULL; ++machp)
{
sim_io_printf (sd, "Models for architecture `%s':\n",
MACH_NAME (*machp));
Result is pointer to MODEL entry or NULL if not found. */
const SIM_MODEL *
-sim_model_lookup (const char *name)
+sim_model_lookup (SIM_DESC sd, const char *name)
{
- const SIM_MACH **machp;
+ const SIM_MACH * const *machp;
const SIM_MODEL *model;
- for (machp = & sim_machs[0]; *machp != NULL; ++machp)
+ if (STATE_MACHS (sd) == NULL)
+ return NULL;
+
+ for (machp = STATE_MACHS (sd); *machp != NULL; ++machp)
{
for (model = MACH_MODELS (*machp); MODEL_NAME (model) != NULL; ++model)
{
Result is pointer to MACH entry or NULL if not found. */
const SIM_MACH *
-sim_mach_lookup (const char *name)
+sim_mach_lookup (SIM_DESC sd, const char *name)
{
- const SIM_MACH **machp;
+ const SIM_MACH * const *machp;
- for (machp = & sim_machs[0]; *machp != NULL; ++machp)
+ if (STATE_MACHS (sd) == NULL)
+ return NULL;
+
+ for (machp = STATE_MACHS (sd); *machp != NULL; ++machp)
{
if (strcmp (MACH_NAME (*machp), name) == 0)
return *machp;
Result is pointer to MACH entry or NULL if not found. */
const SIM_MACH *
-sim_mach_lookup_bfd_name (const char *name)
+sim_mach_lookup_bfd_name (SIM_DESC sd, const char *name)
{
- const SIM_MACH **machp;
+ const SIM_MACH * const *machp;
+
+ if (STATE_MACHS (sd) == NULL)
+ return NULL;
- for (machp = & sim_machs[0]; *machp != NULL; ++machp)
+ for (machp = STATE_MACHS (sd); *machp != NULL; ++machp)
{
if (strcmp (MACH_BFD_NAME (*machp), name) == 0)
return *machp;
{
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
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 (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);
}
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. */
- const SIM_MACH *mach = sim_mach_lookup_bfd_name (STATE_ARCHITECTURE (sd)->printable_name);
+ const SIM_MACH *mach =
+ sim_mach_lookup_bfd_name (sd, STATE_ARCHITECTURE (sd)->printable_name);
if (mach == NULL)
{
}
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)));
}
return SIM_RC_OK;
}
-\f
-#if !WITH_MODEL_P
-/* Set up basic model support. This is a stub for ports that do not define
- models. See sim-model.h for more details. */
-const SIM_MACH *sim_machs[] =
-{
- NULL
-};
-#endif