cb11a2736fb1f15eae31b2a39ee4f8c933e61637
1 /* Main simulator entry points for 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. */
24 #include "libiberty.h"
28 static SIM_RC
alloc_cpu (SIM_DESC
, struct _bfd
*, char **);
29 static void free_state (SIM_DESC
);
31 /* Records simulator descriptor so utilities like m32r_dump_regs can be
33 SIM_DESC current_state
;
35 /* Scan the args and bfd to see what kind of cpus are in use and allocate
39 alloc_cpu (SIM_DESC sd
, struct _bfd
*abfd
, char **argv
)
41 /* Compute the size of the SIM_CPU struct.
42 For now its the max of all the possible sizes. */
46 for (mach
= &machs
[0]; MACH_NAME (mach
) != NULL
; ++mach
)
48 int mach_size
= IMP_PROPS_SIM_CPU_SIZE (MACH_IMP_PROPS (mach
));
49 size
= mach_size
> size
? mach_size
: size
;
54 /* `sizeof (SIM_CPU)' is the size of the generic part, and `size' is the
55 size of the cpu-specific part. */
56 STATE_CPU (sd
, 0) = zalloc (sizeof (SIM_CPU
) + size
);
61 /* Cover function of sim_state_free to free the cpu buffers as well. */
64 free_state (SIM_DESC sd
)
66 if (STATE_CPU (sd
, 0))
67 zfree (STATE_CPU (sd
, 0));
71 /* Create an instance of the simulator. */
74 sim_open (kind
, callback
, abfd
, argv
)
76 host_callback
*callback
;
80 SIM_DESC sd
= sim_state_alloc (kind
, callback
);
82 /* The cpu data is kept in a separately allocated chunk of memory. */
83 if (alloc_cpu (sd
, abfd
, argv
) != SIM_RC_OK
)
89 if (sim_pre_argv_init (sd
, argv
[0]) != SIM_RC_OK
)
95 #if 0 /* FIXME: 'twould be nice if we could do this */
96 /* These options override any module options.
97 Obviously ambiguity should be avoided, however the caller may wish to
98 augment the meaning of an option. */
99 if (extra_options
!= NULL
)
100 sim_add_option_table (sd
, extra_options
);
103 /* Allocate core managed memory */
104 sim_do_commandf (sd
, "memory region 0,0x%lx", M32R_DEFAULT_MEM_SIZE
);
106 /* Allocate a handler for the MSPR register. */
107 sim_core_attach (sd
, NULL
,
111 MSPR_ADDR
, 1 /*nr_bytes*/, 0 /*modulo*/,
115 /* getopt will print the error message so we just have to exit if this fails.
116 FIXME: Hmmm... in the case of gdb we need getopt to call
118 if (sim_parse_args (sd
, argv
) != SIM_RC_OK
)
120 sim_module_uninstall (sd
);
125 /* check for/establish the a reference program image */
126 if (sim_analyze_program (sd
,
127 (STATE_PROG_ARGV (sd
) != NULL
128 ? *STATE_PROG_ARGV (sd
)
132 sim_module_uninstall (sd
);
137 /* Establish any remaining configuration options. */
138 if (sim_config (sd
) != SIM_RC_OK
)
140 sim_module_uninstall (sd
);
145 if (sim_post_argv_init (sd
) != SIM_RC_OK
)
147 sim_module_uninstall (sd
);
152 /* Initialize various cgen things not done by common framework. */
158 /* Only needed for profiling, but the structure member is small. */
159 for (i
= 0; i
< MAX_NR_PROCESSORS
; ++i
)
160 memset (& CPU_M32R_MISC_PROFILE (STATE_CPU (sd
, i
)), 0,
161 sizeof (CPU_M32R_MISC_PROFILE (STATE_CPU (sd
, i
))));
164 /* Store in a global so things like sparc32_dump_regs can be invoked
165 from the gdb command line. */
172 sim_close (sd
, quitting
)
176 sim_module_uninstall (sd
);
180 sim_create_inferior (sd
, abfd
, argv
, envp
)
186 SIM_CPU
*current_cpu
= STATE_CPU (sd
, 0);
191 addr
= bfd_get_start_address (abfd
);
194 taddr
= endian_h2t_4 (addr
);
195 sim_store_register (sd
, PC_REGNUM
, (unsigned char *) &taddr
, 4);
198 STATE_ARGV (sd
) = sim_copy_argv (argv
);
199 STATE_ENVP (sd
) = sim_copy_argv (envp
);
206 sim_stop (SIM_DESC sd
)
208 switch (STATE_ARCHITECTURE (sd
)->mach
)
211 return m32r_engine_stop (sd
);
212 /* start-sanitize-m32rx */
213 #ifdef HAVE_CPU_M32RX
214 case bfd_mach_m32rx
:
215 return m32rx_engine_stop (sd
);
217 /* end-sanitize-m32rx */
224 sim_resume (sd
, step
, siggnal
)
228 switch (STATE_ARCHITECTURE (sd
)->mach
)
231 m32r_engine_run (sd
, step
, siggnal
);
233 /* start-sanitize-m32rx */
234 #ifdef HAVE_CPU_M32RX
235 case bfd_mach_m32rx
:
236 m32rx_engine_run (sd
, step
, siggnal
);
239 /* end-sanitize-m32rx */
245 /* PROFILE_CPU_CALLBACK */
248 print_m32r_misc_cpu (SIM_CPU
*cpu
, int verbose
)
250 SIM_DESC sd
= CPU_STATE (cpu
);
253 if (CPU_PROFILE_FLAGS (cpu
) [PROFILE_INSN_IDX
])
255 sim_io_printf (sd
, "Miscellaneous Statistics\n\n");
256 sim_io_printf (sd
, " %-*s %s\n\n",
257 PROFILE_LABEL_WIDTH
, "Fill nops:",
258 sim_add_commas (buf
, sizeof (buf
),
259 CPU_M32R_MISC_PROFILE (cpu
).fillnop_count
));
264 sim_info (sd
, verbose
)
268 profile_print (sd
, STATE_VERBOSE_P (sd
), NULL
, print_m32r_misc_cpu
);
271 /* The contents of BUF are in target byte order. */
274 sim_fetch_register (sd
, rn
, buf
, length
)
280 switch (STATE_ARCHITECTURE (sd
)->mach
)
283 m32r_fetch_register (sd
, rn
, buf
);
285 /* start-sanitize-m32rx */
286 #ifdef HAVE_CPU_M32RX
287 case bfd_mach_m32rx
:
288 m32rx_fetch_register (sd
, rn
, buf
);
291 /* end-sanitize-m32rx */
298 /* The contents of BUF are in target byte order. */
301 sim_store_register (sd
, rn
, buf
, length
)
307 switch (STATE_ARCHITECTURE (sd
)->mach
)
310 m32r_store_register (sd
, rn
, buf
);
312 /* start-sanitize-m32rx */
313 #ifdef HAVE_CPU_M32RX
314 case bfd_mach_m32rx
:
315 m32rx_store_register (sd
, rn
, buf
);
318 /* end-sanitize-m32rx */
326 sim_do_command (sd
, cmd
)
330 if (sim_args_command (sd
, cmd
) != SIM_RC_OK
)
331 sim_io_eprintf (sd
, "Unknown command `%s'\n", cmd
);
334 /* The semantic code invokes this for illegal (unrecognized) instructions. */
337 sim_engine_illegal_insn (current_cpu
, pc
)
338 SIM_CPU
*current_cpu
;
341 sim_engine_halt (CPU_STATE (current_cpu
), current_cpu
, NULL
, pc
,
342 sim_stopped
, SIM_SIGILL
);
This page took 0.038734 seconds and 4 git commands to generate.