2 Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
3 Contributed by Cygnus Support.
5 This file is part of GDB, the GNU debugger.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License along
18 with this program; if not, write to the Free Software Foundation, Inc.,
19 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22 #include "libiberty.h"
23 #include "sim-options.h"
25 #include "sim-assert.h"
28 static void model_set (sim_cpu
*, const MODEL
*);
30 static DECLARE_OPTION_HANDLER (model_option_handler
);
32 static MODULE_INIT_FN sim_model_init
;
34 #define OPTION_MODEL (OPTION_START + 0)
36 static const OPTION model_options
[] = {
37 { {"model", required_argument
, NULL
, OPTION_MODEL
},
38 '\0', "MODEL", "Specify model to simulate",
39 model_option_handler
},
40 { {NULL
, no_argument
, NULL
, 0}, '\0', NULL
, NULL
, NULL
}
44 model_option_handler (SIM_DESC sd
, sim_cpu
*cpu
, int opt
,
45 char *arg
, int is_command
)
51 const MODEL
*model
= sim_model_lookup (arg
);
54 sim_io_eprintf (sd
, "unknown model `%s'\n", arg
);
57 sim_model_set (sd
, cpu
, model
);
66 sim_model_install (SIM_DESC sd
)
68 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
70 sim_add_option_table (sd
, NULL
, model_options
);
71 sim_module_add_init_fn (sd
, sim_model_init
);
76 /* Subroutine of sim_model_set to set the model for one cpu. */
79 model_set (sim_cpu
*cpu
, const MODEL
*model
)
81 CPU_MACH (cpu
) = MODEL_MACH (model
);
82 CPU_MODEL (cpu
) = model
;
83 (* MACH_INIT_CPU (MODEL_MACH (model
))) (cpu
);
84 (* MODEL_INIT (model
)) (cpu
);
87 /* Set the current model of CPU to MODEL.
88 If CPU is NULL, all cpus are set to MODEL. */
91 sim_model_set (SIM_DESC sd
, sim_cpu
*cpu
, const MODEL
*model
)
97 for (c
= 0; c
< MAX_NR_PROCESSORS
; ++c
)
98 if (STATE_CPU (sd
, c
))
99 model_set (STATE_CPU (sd
, c
), model
);
103 model_set (cpu
, model
);
107 /* Look up model named NAME.
108 Result is pointer to MODEL entry or NULL if not found. */
111 sim_model_lookup (const char *name
)
116 for (machp
= & sim_machs
[0]; *machp
!= NULL
; ++machp
)
118 for (model
= MACH_MODELS (*machp
); MODEL_NAME (model
) != NULL
; ++model
)
120 if (strcmp (MODEL_NAME (model
), name
) == 0)
127 /* Look up machine named NAME.
128 Result is pointer to MACH entry or NULL if not found. */
131 sim_mach_lookup (const char *name
)
135 for (machp
= & sim_machs
[0]; *machp
!= NULL
; ++machp
)
137 if (strcmp (MACH_NAME (*machp
), name
) == 0)
143 /* Look up a machine via its bfd name.
144 Result is pointer to MACH entry or NULL if not found. */
147 sim_mach_lookup_bfd_name (const char *name
)
151 for (machp
= & sim_machs
[0]; *machp
!= NULL
; ++machp
)
153 if (strcmp (MACH_BFD_NAME (*machp
), name
) == 0)
159 /* Initialize model support. */
162 sim_model_init (SIM_DESC sd
)
166 /* If both cpu model and state architecture are set, ensure they're
167 compatible. If only one is set, set the other. If neither are set,
168 use the default model. STATE_ARCHITECTURE is the bfd_arch_info data
169 for the selected "mach" (bfd terminology). */
171 /* Only check cpu 0. STATE_ARCHITECTURE is for that one only. */
172 /* ??? At present this only supports homogeneous multiprocessors. */
173 cpu
= STATE_CPU (sd
, 0);
175 if (! STATE_ARCHITECTURE (sd
)
178 /* Set the default model. */
179 const MODEL
*model
= sim_model_lookup (WITH_DEFAULT_MODEL
);
180 sim_model_set (sd
, NULL
, model
);
183 if (STATE_ARCHITECTURE (sd
)
186 if (strcmp (STATE_ARCHITECTURE (sd
)->printable_name
,
187 MACH_BFD_NAME (CPU_MACH (cpu
))) != 0)
189 sim_io_eprintf (sd
, "invalid model `%s' for `%s'\n",
190 MODEL_NAME (CPU_MODEL (cpu
)),
191 STATE_ARCHITECTURE (sd
)->printable_name
);
195 else if (STATE_ARCHITECTURE (sd
))
197 /* Use the default model for the selected machine.
198 The default model is the first one in the list. */
199 const MACH
*mach
= sim_mach_lookup_bfd_name (STATE_ARCHITECTURE (sd
)->printable_name
);
203 sim_io_eprintf (sd
, "unsupported machine `%s'\n",
204 STATE_ARCHITECTURE (sd
)->printable_name
);
207 sim_model_set (sd
, NULL
, MACH_MODELS (mach
));
211 STATE_ARCHITECTURE (sd
) = bfd_scan_arch (MACH_BFD_NAME (CPU_MACH (cpu
)));