1 /* This must come before any other includes. */
5 #include "sim-options.h"
7 #include "sim-assert.h"
15 #include "target-newlib-syscall.h"
17 static const char * get_insn_name (sim_cpu
*, int);
19 /* For compatibility. */
22 /* V850 interrupt model. */
37 const char *interrupt_names
[] =
51 do_interrupt (SIM_DESC sd
, void *data
)
53 sim_cpu
*cpu
= STATE_CPU (sd
, 0);
54 struct v850_sim_cpu
*v850_cpu
= V850_SIM_CPU (cpu
);
55 const char **interrupt_name
= (const char**)data
;
56 enum interrupt_type inttype
;
57 inttype
= (interrupt_name
- STATE_WATCHPOINTS (sd
)->interrupt_names
);
59 /* For a hardware reset, drop everything and jump to the start
61 if (inttype
== int_reset
)
66 sim_engine_restart (sd
, NULL
, NULL
, NULL_CIA
);
69 /* Deliver an NMI when allowed */
70 if (inttype
== int_nmi
)
74 /* We're already working on an NMI, so this one must wait
75 around until the previous one is done. The processor
76 ignores subsequent NMIs, so we don't need to count them.
77 Just keep re-scheduling a single NMI until it manages to
79 if (v850_cpu
->pending_nmi
!= NULL
)
80 sim_events_deschedule (sd
, v850_cpu
->pending_nmi
);
81 v850_cpu
->pending_nmi
=
82 sim_events_schedule (sd
, 1, do_interrupt
, data
);
87 /* NMI can be delivered. Do not deschedule pending_nmi as
88 that, if still in the event queue, is a second NMI that
89 needs to be delivered later. */
92 /* Set the FECC part of the ECR. */
99 sim_engine_restart (sd
, NULL
, NULL
, NULL_CIA
);
103 /* deliver maskable interrupt when allowed */
104 if (inttype
> int_nmi
&& inttype
< num_int_types
)
106 if ((PSW
& PSW_NP
) || (PSW
& PSW_ID
))
108 /* Can't deliver this interrupt, reschedule it for later */
109 sim_events_schedule (sd
, 1, do_interrupt
, data
);
117 /* Disable further interrupts. */
119 /* Indicate that we're doing interrupt not exception processing. */
121 /* Clear the EICC part of the ECR, will set below. */
150 /* Should never be possible. */
151 sim_engine_abort (sd
, NULL
, NULL_CIA
,
152 "do_interrupt - internal error - bad switch");
156 sim_engine_restart (sd
, NULL
, NULL
, NULL_CIA
);
159 /* some other interrupt? */
160 sim_engine_abort (sd
, NULL
, NULL_CIA
,
161 "do_interrupt - internal error - interrupt %d unknown",
165 /* Return name of an insn, used by insn profiling. */
168 get_insn_name (sim_cpu
*cpu
, int i
)
170 return itable
[i
].name
;
173 /* These default values correspond to expected usage for the chip. */
178 v850_pc_get (sim_cpu
*cpu
)
184 v850_pc_set (sim_cpu
*cpu
, sim_cia pc
)
189 static int v850_reg_fetch (SIM_CPU
*, int, void *, int);
190 static int v850_reg_store (SIM_CPU
*, int, const void *, int);
193 sim_open (SIM_OPEN_KIND kind
,
199 SIM_DESC sd
= sim_state_alloc (kind
, cb
);
202 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
204 /* Set default options before parsing user options. */
205 current_target_byte_order
= BFD_ENDIAN_LITTLE
;
206 cb
->syscall_map
= cb_v850_syscall_map
;
208 /* The cpu data is kept in a separately allocated chunk of memory. */
209 if (sim_cpu_alloc_all_extra (sd
, 0, sizeof (struct v850_sim_cpu
))
213 /* for compatibility */
216 /* FIXME: should be better way of setting up interrupts */
217 STATE_WATCHPOINTS (sd
)->interrupt_handler
= do_interrupt
;
218 STATE_WATCHPOINTS (sd
)->interrupt_names
= interrupt_names
;
220 /* Initialize the mechanism for doing insn profiling. */
221 CPU_INSN_NAME (STATE_CPU (sd
, 0)) = get_insn_name
;
222 CPU_MAX_INSNS (STATE_CPU (sd
, 0)) = nr_itable_entries
;
224 if (sim_pre_argv_init (sd
, argv
[0]) != SIM_RC_OK
)
227 /* Allocate core managed memory */
229 /* "Mirror" the ROM addresses below 1MB. */
230 sim_do_commandf (sd
, "memory region 0,0x100000,0x%x", V850_ROM_SIZE
);
231 /* Chunk of ram adjacent to rom */
232 sim_do_commandf (sd
, "memory region 0x100000,0x%x", V850_LOW_END
-0x100000);
233 /* peripheral I/O region - mirror 1K across 4k (0x1000) */
234 sim_do_command (sd
, "memory region 0xfff000,0x1000,1024");
235 /* similarly if in the internal RAM region */
236 sim_do_command (sd
, "memory region 0xffe000,0x1000,1024");
238 /* The parser will print an error message for us, so we silently return. */
239 if (sim_parse_args (sd
, argv
) != SIM_RC_OK
)
241 /* Uninstall the modules to avoid memory leaks,
242 file descriptor leaks, etc. */
243 sim_module_uninstall (sd
);
247 /* check for/establish the a reference program image */
248 if (sim_analyze_program (sd
, STATE_PROG_FILE (sd
), abfd
) != SIM_RC_OK
)
250 sim_module_uninstall (sd
);
254 /* establish any remaining configuration options */
255 if (sim_config (sd
) != SIM_RC_OK
)
257 sim_module_uninstall (sd
);
261 if (sim_post_argv_init (sd
) != SIM_RC_OK
)
263 /* Uninstall the modules to avoid memory leaks,
264 file descriptor leaks, etc. */
265 sim_module_uninstall (sd
);
270 /* determine the machine type */
271 if (STATE_ARCHITECTURE (sd
) != NULL
272 && (STATE_ARCHITECTURE (sd
)->arch
== bfd_arch_v850
273 || STATE_ARCHITECTURE (sd
)->arch
== bfd_arch_v850_rh850
))
274 mach
= STATE_ARCHITECTURE (sd
)->mach
;
276 mach
= bfd_mach_v850
; /* default */
278 /* set machine specific configuration */
283 case bfd_mach_v850e1
:
284 case bfd_mach_v850e2
:
285 case bfd_mach_v850e2v3
:
286 case bfd_mach_v850e3v5
:
287 V850_SIM_CPU (STATE_CPU (sd
, 0))->psw_mask
=
288 (PSW_NP
| PSW_EP
| PSW_ID
| PSW_SAT
| PSW_CY
| PSW_OV
| PSW_S
| PSW_Z
);
292 /* CPU specific initialization. */
293 for (i
= 0; i
< MAX_NR_PROCESSORS
; ++i
)
295 SIM_CPU
*cpu
= STATE_CPU (sd
, i
);
297 CPU_REG_FETCH (cpu
) = v850_reg_fetch
;
298 CPU_REG_STORE (cpu
) = v850_reg_store
;
299 CPU_PC_FETCH (cpu
) = v850_pc_get
;
300 CPU_PC_STORE (cpu
) = v850_pc_set
;
307 sim_create_inferior (SIM_DESC sd
,
308 struct bfd
* prog_bfd
,
312 memset (&State
, 0, sizeof (State
));
313 if (prog_bfd
!= NULL
)
314 PC
= bfd_get_start_address (prog_bfd
);
319 v850_reg_fetch (SIM_CPU
*cpu
, int rn
, void *memory
, int length
)
321 *(uint32_t*)memory
= H2T_4 (State
.regs
[rn
]);
326 v850_reg_store (SIM_CPU
*cpu
, int rn
, const void *memory
, int length
)
328 State
.regs
[rn
] = T2H_4 (*(uint32_t *) memory
);