3 #include "sim-options.h"
29 /* For compatibility */
34 /* v850 interrupt model */
49 char *interrupt_names[] = {
62 do_interrupt (sd, data)
66 char **interrupt_name = (char**)data;
67 enum interrupt_type inttype;
68 inttype = (interrupt_name - STATE_WATCHPOINTS (sd)->interrupt_names);
70 /* For a hardware reset, drop everything and jump to the start
72 if (inttype == int_reset)
77 sim_engine_restart (sd, NULL, NULL, NULL_CIA);
80 /* Deliver an NMI when allowed */
81 if (inttype == int_nmi)
85 /* We're already working on an NMI, so this one must wait
86 around until the previous one is done. The processor
87 ignores subsequent NMIs, so we don't need to count them.
88 Just keep re-scheduling a single NMI until it manages to
90 if (STATE_CPU (sd, 0)->pending_nmi != NULL)
91 sim_events_deschedule (sd, STATE_CPU (sd, 0)->pending_nmi);
92 STATE_CPU (sd, 0)->pending_nmi =
93 sim_events_schedule (sd, 1, do_interrupt, data);
98 /* NMI can be delivered. Do not deschedule pending_nmi as
99 that, if still in the event queue, is a second NMI that
100 needs to be delivered later. */
103 /* Set the FECC part of the ECR. */
110 sim_engine_restart (sd, NULL, NULL, NULL_CIA);
114 /* deliver maskable interrupt when allowed */
115 if (inttype > int_nmi && inttype < num_int_types)
117 if ((PSW & PSW_NP) || (PSW & PSW_ID))
119 /* Can't deliver this interrupt, reschedule it for later */
120 sim_events_schedule (sd, 1, do_interrupt, data);
128 /* Disable further interrupts. */
130 /* Indicate that we're doing interrupt not exception processing. */
132 /* Clear the EICC part of the ECR, will set below. */
161 /* Should never be possible. */
162 sim_engine_abort (sd, NULL, NULL_CIA,
163 "do_interrupt - internal error - bad switch");
167 sim_engine_restart (sd, NULL, NULL, NULL_CIA);
170 /* some other interrupt? */
171 sim_engine_abort (sd, NULL, NULL_CIA,
172 "do_interrupt - internal error - interrupt %d unknown",
176 /* These default values correspond to expected usage for the chip. */
182 sim_open (kind, cb, abfd, argv)
188 SIM_DESC sd = sim_state_alloc (kind, cb);
191 /* for compatibility */
194 /* FIXME: should be better way of setting up interrupts */
195 STATE_WATCHPOINTS (sd)->pc = &(PC);
196 STATE_WATCHPOINTS (sd)->sizeof_pc = sizeof (PC);
197 STATE_WATCHPOINTS (sd)->interrupt_handler = do_interrupt;
198 STATE_WATCHPOINTS (sd)->interrupt_names = interrupt_names;
200 if (sim_pre_argv_init (sd, argv[0]) != SIM_RC_OK)
203 /* Allocate core managed memory */
205 /* "Mirror" the ROM addresses below 1MB. */
206 sim_do_commandf (sd, "memory region 0,0x100000,0x%lx", V850_ROM_SIZE);
207 /* Chunk of ram adjacent to rom */
208 sim_do_commandf (sd, "memory region 0x100000,0x%lx", V850_LOW_END-0x100000);
209 /* peripheral I/O region - mirror 1K across 4k (0x1000) */
210 sim_do_command (sd, "memory region 0xfff000,0x1000,1024");
211 /* similarly if in the internal RAM region */
212 sim_do_command (sd, "memory region 0xffe000,0x1000,1024");
214 /* getopt will print the error message so we just have to exit if this fails.
215 FIXME: Hmmm... in the case of gdb we need getopt to call
217 if (sim_parse_args (sd, argv) != SIM_RC_OK)
219 /* Uninstall the modules to avoid memory leaks,
220 file descriptor leaks, etc. */
221 sim_module_uninstall (sd);
225 /* check for/establish the a reference program image */
226 if (sim_analyze_program (sd,
227 (STATE_PROG_ARGV (sd) != NULL
228 ? *STATE_PROG_ARGV (sd)
232 sim_module_uninstall (sd);
236 /* establish any remaining configuration options */
237 if (sim_config (sd) != SIM_RC_OK)
239 sim_module_uninstall (sd);
243 if (sim_post_argv_init (sd) != SIM_RC_OK)
245 /* Uninstall the modules to avoid memory leaks,
246 file descriptor leaks, etc. */
247 sim_module_uninstall (sd);
252 /* determine the machine type */
253 if (STATE_ARCHITECTURE (sd) != NULL
254 && STATE_ARCHITECTURE (sd)->arch == bfd_arch_v850)
255 mach = STATE_ARCHITECTURE (sd)->mach;
257 mach = bfd_mach_v850; /* default */
259 /* set machine specific configuration */
263 /* start-sanitize-v850e */
265 /* end-sanitize-v850e */
266 STATE_CPU (sd, 0)->psw_mask = (PSW_NP | PSW_EP | PSW_ID | PSW_SAT
267 | PSW_CY | PSW_OV | PSW_S | PSW_Z);
269 /* start-sanitize-v850eq */
270 case bfd_mach_v850eq:
272 STATE_CPU (sd, 0)->psw_mask = (PSW_US
273 | PSW_NP | PSW_EP | PSW_ID | PSW_SAT
274 | PSW_CY | PSW_OV | PSW_S | PSW_Z);
276 /* end-sanitize-v850eq */
284 sim_close (sd, quitting)
288 sim_module_uninstall (sd);
299 sim_info (sd, verbose)
303 profile_print (sd, STATE_VERBOSE_P (sd), NULL, NULL);
307 sim_create_inferior (sd, prog_bfd, argv, env)
309 struct _bfd *prog_bfd;
313 memset (&State, 0, sizeof (State));
314 if (prog_bfd != NULL)
315 PC = bfd_get_start_address (prog_bfd);
316 /* start-sanitize-v850eq */
317 /* For v850eq, set PSW[US] by default */
318 if (STATE_ARCHITECTURE (sd) != NULL
319 && STATE_ARCHITECTURE (sd)->arch == bfd_arch_v850
320 && STATE_ARCHITECTURE (sd)->mach == bfd_mach_v850eq)
322 /* end-sanitize-v850eq */
327 sim_fetch_register (sd, rn, memory)
330 unsigned char *memory;
332 *(unsigned32*)memory = H2T_4 (State.regs[rn]);
336 sim_store_register (sd, rn, memory)
339 unsigned char *memory;
341 State.regs[rn] = T2H_4 (*(unsigned32*)memory);
345 sim_do_command (sd, cmd)
349 char *mm_cmd = "memory-map";
350 char *int_cmd = "interrupt";
352 if (sim_args_command (sd, cmd) != SIM_RC_OK)
354 if (strncmp (cmd, mm_cmd, strlen (mm_cmd) == 0))
355 sim_io_eprintf (sd, "`memory-map' command replaced by `sim memory'\n");
356 else if (strncmp (cmd, int_cmd, strlen (int_cmd)) == 0)
357 sim_io_eprintf (sd, "`interrupt' command replaced by `sim watch'\n");
359 sim_io_eprintf (sd, "Unknown command `%s'\n", cmd);