1 /* Main simulator entry points specific to the M32R.
2 Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
3 Contributed by Cygnus Support.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
23 #include "sim-options.h"
24 #include "libiberty.h"
27 static void free_state (SIM_DESC);
28 static void print_m32r_misc_cpu (SIM_CPU *cpu, int verbose);
30 /* Records simulator descriptor so utilities like m32r_dump_regs can be
32 SIM_DESC current_state;
34 /* Cover function of sim_state_free to free the cpu buffers as well. */
37 free_state (SIM_DESC sd)
39 if (STATE_MODULES (sd) != NULL)
40 sim_module_uninstall (sd);
41 sim_cpu_free_all (sd);
45 /* Create an instance of the simulator. */
48 sim_open (kind, callback, abfd, argv)
50 host_callback *callback;
55 SIM_DESC sd = sim_state_alloc (kind, callback);
57 /* The cpu data is kept in a separately allocated chunk of memory. */
58 if (sim_cpu_alloc_all (sd, 1, cgen_cpu_max_extra_bytes ()) != SIM_RC_OK)
64 #if 0 /* FIXME: pc is in mach-specific struct */
65 /* FIXME: watchpoints code shouldn't need this */
67 SIM_CPU *current_cpu = STATE_CPU (sd, 0);
68 STATE_WATCHPOINTS (sd)->pc = &(PC);
69 STATE_WATCHPOINTS (sd)->sizeof_pc = sizeof (PC);
73 if (sim_pre_argv_init (sd, argv[0]) != SIM_RC_OK)
79 #if 0 /* FIXME: 'twould be nice if we could do this */
80 /* These options override any module options.
81 Obviously ambiguity should be avoided, however the caller may wish to
82 augment the meaning of an option. */
83 if (extra_options != NULL)
84 sim_add_option_table (sd, extra_options);
87 /* getopt will print the error message so we just have to exit if this fails.
88 FIXME: Hmmm... in the case of gdb we need getopt to call
90 if (sim_parse_args (sd, argv) != SIM_RC_OK)
96 /* Allocate a handler for the control registers and other devices
97 if no memory for that range has been allocated by the user.
98 All are allocated in one chunk to keep things from being
99 unnecessarily complicated. */
100 if (sim_core_read_buffer (sd, NULL, read_map, &c, M32R_DEVICE_ADDR, 1) == 0)
101 sim_core_attach (sd, NULL,
105 M32R_DEVICE_ADDR, M32R_DEVICE_LEN /*nr_bytes*/,
110 /* Allocate core managed memory if none specified by user.
111 Use address 4 here in case the user wanted address 0 unmapped. */
112 if (sim_core_read_buffer (sd, NULL, read_map, &c, 4, 1) == 0)
113 sim_do_commandf (sd, "memory region 0,0x%lx", M32R_DEFAULT_MEM_SIZE);
115 /* check for/establish the reference program image */
116 if (sim_analyze_program (sd,
117 (STATE_PROG_ARGV (sd) != NULL
118 ? *STATE_PROG_ARGV (sd)
126 /* If both cpu model and state architecture are set, ensure they're
127 compatible. If only one is set, set the other. If neither are set,
128 use the default model. STATE_ARCHITECTURE is the bfd_arch_info data
129 for the selected "mach" (bfd terminology). */
131 SIM_CPU *cpu = STATE_CPU (sd, 0);
133 if (! STATE_ARCHITECTURE (sd)
134 /* Only check cpu 0. STATE_ARCHITECTURE is for that one only. */
137 /* Set the default model. */
138 const MODEL *model = sim_model_lookup (WITH_DEFAULT_MODEL);
139 sim_model_set (sd, NULL, model);
141 if (STATE_ARCHITECTURE (sd)
144 if (strcmp (STATE_ARCHITECTURE (sd)->printable_name,
145 MACH_NAME (CPU_MACH (cpu))) != 0)
147 sim_io_eprintf (sd, "invalid model `%s' for `%s'\n",
148 MODEL_NAME (CPU_MODEL (cpu)),
149 STATE_ARCHITECTURE (sd)->printable_name);
154 else if (STATE_ARCHITECTURE (sd))
156 /* Use the default model for the selected machine.
157 The default model is the first one in the list. */
158 const MACH *mach = sim_mach_lookup (STATE_ARCHITECTURE (sd)->printable_name);
159 sim_model_set (sd, NULL, MACH_MODELS (mach));
163 STATE_ARCHITECTURE (sd) = bfd_scan_arch (MACH_NAME (CPU_MACH (cpu)));
167 /* Establish any remaining configuration options. */
168 if (sim_config (sd) != SIM_RC_OK)
174 if (sim_post_argv_init (sd) != SIM_RC_OK)
180 /* Initialize various cgen things not done by common framework. */
183 /* Open a copy of the opcode table. */
184 STATE_OPCODE_TABLE (sd) = m32r_cgen_opcode_open (STATE_ARCHITECTURE (sd)->mach,
186 m32r_cgen_init_dis (STATE_OPCODE_TABLE (sd));
191 for (c = 0; c < MAX_NR_PROCESSORS; ++c)
193 /* Only needed for profiling, but the structure member is small. */
194 memset (CPU_M32R_MISC_PROFILE (STATE_CPU (sd, c)), 0,
195 sizeof (* CPU_M32R_MISC_PROFILE (STATE_CPU (sd, c))));
196 /* Hook in callback for reporting these stats */
197 PROFILE_INFO_CPU_CALLBACK (CPU_PROFILE_DATA (STATE_CPU (sd, c)))
198 = print_m32r_misc_cpu;
202 /* Store in a global so things like sparc32_dump_regs can be invoked
203 from the gdb command line. */
210 sim_close (sd, quitting)
214 m32r_cgen_opcode_close (STATE_OPCODE_TABLE (sd));
215 sim_module_uninstall (sd);
219 sim_create_inferior (sd, abfd, argv, envp)
225 SIM_CPU *current_cpu = STATE_CPU (sd, 0);
229 addr = bfd_get_start_address (abfd);
232 sim_pc_set (current_cpu, addr);
235 STATE_ARGV (sd) = sim_copy_argv (argv);
236 STATE_ENVP (sd) = sim_copy_argv (envp);
242 /* PROFILE_CPU_CALLBACK */
245 print_m32r_misc_cpu (SIM_CPU *cpu, int verbose)
247 SIM_DESC sd = CPU_STATE (cpu);
250 if (CPU_PROFILE_FLAGS (cpu) [PROFILE_INSN_IDX])
252 sim_io_printf (sd, "Miscellaneous Statistics\n\n");
253 sim_io_printf (sd, " %-*s %s\n\n",
254 PROFILE_LABEL_WIDTH, "Fill nops:",
255 sim_add_commas (buf, sizeof (buf),
256 CPU_M32R_MISC_PROFILE (cpu)->fillnop_count));
257 if (STATE_ARCHITECTURE (sd)->mach == bfd_mach_m32rx)
258 sim_io_printf (sd, " %-*s %s\n\n",
259 PROFILE_LABEL_WIDTH, "Parallel insns:",
260 sim_add_commas (buf, sizeof (buf),
261 CPU_M32R_MISC_PROFILE (cpu)->parallel_count));
266 sim_do_command (sd, cmd)
275 argv = buildargv (cmd);
278 && strcasecmp (argv[0], "info") == 0
280 && strncasecmp (argv[1], "reg", 3) == 0)
284 /* We only support printing bbpsw,bbpc here as there is no equivalent
285 functionality in gdb. */
287 sim_io_eprintf (sd, "Missing register in `%s'\n", cmd);
288 else if (argv[3] != NULL)
289 sim_io_eprintf (sd, "Too many arguments in `%s'\n", cmd);
290 else if (strcasecmp (argv[2], "bbpsw") == 0)
292 val = a_m32r_h_cr_get (STATE_CPU (sd, 0), H_CR_BBPSW);
293 sim_io_printf (sd, "bbpsw 0x%x %d\n", val, val);
295 else if (strcasecmp (argv[2], "bbpc") == 0)
297 val = a_m32r_h_cr_get (STATE_CPU (sd, 0), H_CR_BBPC);
298 sim_io_printf (sd, "bbpc 0x%x %d\n", val, val);
301 sim_io_eprintf (sd, "Printing of register `%s' not supported with `sim info'\n",
306 if (sim_args_command (sd, cmd) != SIM_RC_OK)
307 sim_io_eprintf (sd, "Unknown sim command `%s'\n", cmd);