import insight-2000-02-04 snapshot (2nd try)
[external/binutils.git] / sim / common / sim-model.c
index 47be996..3cfdc15 100644 (file)
@@ -25,7 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "sim-assert.h"
 #include "bfd.h"
 
-static void model_set (SIM_DESC, sim_cpu *, const MODEL *);
+static void model_set (sim_cpu *, const MODEL *);
 
 static DECLARE_OPTION_HANDLER (model_option_handler);
 
@@ -51,7 +51,7 @@ model_option_handler (SIM_DESC sd, sim_cpu *cpu, int opt,
        const MODEL *model = sim_model_lookup (arg);
        if (! model)
          {
-           sim_io_eprintf (sd, "unknown model `%s'", arg);
+           sim_io_eprintf (sd, "unknown model `%s'\n", arg);
            return SIM_RC_FAIL;
          }
        sim_model_set (sd, cpu, model);
@@ -76,7 +76,7 @@ sim_model_install (SIM_DESC sd)
 /* Subroutine of sim_model_set to set the model for one cpu.  */
 
 static void
-model_set (SIM_DESC sd, sim_cpu *cpu, const MODEL *model)
+model_set (sim_cpu *cpu, const MODEL *model)
 {
   CPU_MACH (cpu) = MODEL_MACH (model);
   CPU_MODEL (cpu) = model;
@@ -96,11 +96,11 @@ sim_model_set (SIM_DESC sd, sim_cpu *cpu, const MODEL *model)
 
       for (c = 0; c < MAX_NR_PROCESSORS; ++c)
        if (STATE_CPU (sd, c))
-         model_set (sd, STATE_CPU (sd, c), model);
+         model_set (STATE_CPU (sd, c), model);
     }
   else
     {
-      model_set (sd, cpu, model);
+      model_set (cpu, model);
     }
 }
 
@@ -140,6 +140,22 @@ sim_mach_lookup (const char *name)
   return NULL;
 }
 
+/* Look up a machine via its bfd name.
+   Result is pointer to MACH entry or NULL if not found.  */
+
+const MACH *
+sim_mach_lookup_bfd_name (const char *name)
+{
+  const MACH **machp;
+
+  for (machp = & sim_machs[0]; *machp != NULL; ++machp)
+    {
+      if (strcmp (MACH_BFD_NAME (*machp), name) == 0)
+       return *machp;
+    }
+  return NULL;
+}
+
 /* Initialize model support.  */
 
 static SIM_RC
@@ -180,7 +196,14 @@ sim_model_init (SIM_DESC sd)
     {
       /* Use the default model for the selected machine.
         The default model is the first one in the list.  */
-      const MACH *mach = sim_mach_lookup (STATE_ARCHITECTURE (sd)->printable_name);
+      const MACH *mach = sim_mach_lookup_bfd_name (STATE_ARCHITECTURE (sd)->printable_name);
+
+      if (mach == NULL)
+       {
+         sim_io_eprintf (sd, "unsupported machine `%s'\n",
+                         STATE_ARCHITECTURE (sd)->printable_name);
+         return SIM_RC_FAIL;
+       }
       sim_model_set (sd, NULL, MACH_MODELS (mach));
     }
   else