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 const char **interrupt_name
= (const char**)data
;
54 enum interrupt_type inttype
;
55 inttype
= (interrupt_name
- STATE_WATCHPOINTS (sd
)->interrupt_names
);
57 /* For a hardware reset, drop everything and jump to the start
59 if (inttype
== int_reset
)
64 sim_engine_restart (sd
, NULL
, NULL
, NULL_CIA
);
67 /* Deliver an NMI when allowed */
68 if (inttype
== int_nmi
)
72 /* We're already working on an NMI, so this one must wait
73 around until the previous one is done. The processor
74 ignores subsequent NMIs, so we don't need to count them.
75 Just keep re-scheduling a single NMI until it manages to
77 if (STATE_CPU (sd
, 0)->pending_nmi
!= NULL
)
78 sim_events_deschedule (sd
, STATE_CPU (sd
, 0)->pending_nmi
);
79 STATE_CPU (sd
, 0)->pending_nmi
=
80 sim_events_schedule (sd
, 1, do_interrupt
, data
);
85 /* NMI can be delivered. Do not deschedule pending_nmi as
86 that, if still in the event queue, is a second NMI that
87 needs to be delivered later. */
90 /* Set the FECC part of the ECR. */
97 sim_engine_restart (sd
, NULL
, NULL
, NULL_CIA
);
101 /* deliver maskable interrupt when allowed */
102 if (inttype
> int_nmi
&& inttype
< num_int_types
)
104 if ((PSW
& PSW_NP
) || (PSW
& PSW_ID
))
106 /* Can't deliver this interrupt, reschedule it for later */
107 sim_events_schedule (sd
, 1, do_interrupt
, data
);
115 /* Disable further interrupts. */
117 /* Indicate that we're doing interrupt not exception processing. */
119 /* Clear the EICC part of the ECR, will set below. */
148 /* Should never be possible. */
149 sim_engine_abort (sd
, NULL
, NULL_CIA
,
150 "do_interrupt - internal error - bad switch");
154 sim_engine_restart (sd
, NULL
, NULL
, NULL_CIA
);
157 /* some other interrupt? */
158 sim_engine_abort (sd
, NULL
, NULL_CIA
,
159 "do_interrupt - internal error - interrupt %d unknown",
163 /* Return name of an insn, used by insn profiling. */
166 get_insn_name (sim_cpu
*cpu
, int i
)
168 return itable
[i
].name
;
171 /* These default values correspond to expected usage for the chip. */
176 v850_pc_get (sim_cpu
*cpu
)
182 v850_pc_set (sim_cpu
*cpu
, sim_cia pc
)
187 static int v850_reg_fetch (SIM_CPU
*, int, unsigned char *, int);
188 static int v850_reg_store (SIM_CPU
*, int, const unsigned char *, int);
191 sim_open (SIM_OPEN_KIND kind
,
197 SIM_DESC sd
= sim_state_alloc (kind
, cb
);
200 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
202 /* Set default options before parsing user options. */
203 current_target_byte_order
= BFD_ENDIAN_LITTLE
;
204 cb
->syscall_map
= cb_v850_syscall_map
;
206 /* The cpu data is kept in a separately allocated chunk of memory. */
207 if (sim_cpu_alloc_all (sd
, 1) != SIM_RC_OK
)
210 /* for compatibility */
213 /* FIXME: should be better way of setting up interrupts */
214 STATE_WATCHPOINTS (sd
)->interrupt_handler
= do_interrupt
;
215 STATE_WATCHPOINTS (sd
)->interrupt_names
= interrupt_names
;
217 /* Initialize the mechanism for doing insn profiling. */
218 CPU_INSN_NAME (STATE_CPU (sd
, 0)) = get_insn_name
;
219 CPU_MAX_INSNS (STATE_CPU (sd
, 0)) = nr_itable_entries
;
221 if (sim_pre_argv_init (sd
, argv
[0]) != SIM_RC_OK
)
224 /* Allocate core managed memory */
226 /* "Mirror" the ROM addresses below 1MB. */
227 sim_do_commandf (sd
, "memory region 0,0x100000,0x%x", V850_ROM_SIZE
);
228 /* Chunk of ram adjacent to rom */
229 sim_do_commandf (sd
, "memory region 0x100000,0x%x", V850_LOW_END
-0x100000);
230 /* peripheral I/O region - mirror 1K across 4k (0x1000) */
231 sim_do_command (sd
, "memory region 0xfff000,0x1000,1024");
232 /* similarly if in the internal RAM region */
233 sim_do_command (sd
, "memory region 0xffe000,0x1000,1024");
235 /* The parser will print an error message for us, so we silently return. */
236 if (sim_parse_args (sd
, argv
) != SIM_RC_OK
)
238 /* Uninstall the modules to avoid memory leaks,
239 file descriptor leaks, etc. */
240 sim_module_uninstall (sd
);
244 /* check for/establish the a reference program image */
245 if (sim_analyze_program (sd
, STATE_PROG_FILE (sd
), abfd
) != SIM_RC_OK
)
247 sim_module_uninstall (sd
);
251 /* establish any remaining configuration options */
252 if (sim_config (sd
) != SIM_RC_OK
)
254 sim_module_uninstall (sd
);
258 if (sim_post_argv_init (sd
) != SIM_RC_OK
)
260 /* Uninstall the modules to avoid memory leaks,
261 file descriptor leaks, etc. */
262 sim_module_uninstall (sd
);
267 /* determine the machine type */
268 if (STATE_ARCHITECTURE (sd
) != NULL
269 && (STATE_ARCHITECTURE (sd
)->arch
== bfd_arch_v850
270 || STATE_ARCHITECTURE (sd
)->arch
== bfd_arch_v850_rh850
))
271 mach
= STATE_ARCHITECTURE (sd
)->mach
;
273 mach
= bfd_mach_v850
; /* default */
275 /* set machine specific configuration */
280 case bfd_mach_v850e1
:
281 case bfd_mach_v850e2
:
282 case bfd_mach_v850e2v3
:
283 case bfd_mach_v850e3v5
:
284 STATE_CPU (sd
, 0)->psw_mask
= (PSW_NP
| PSW_EP
| PSW_ID
| PSW_SAT
285 | PSW_CY
| PSW_OV
| PSW_S
| PSW_Z
);
289 /* CPU specific initialization. */
290 for (i
= 0; i
< MAX_NR_PROCESSORS
; ++i
)
292 SIM_CPU
*cpu
= STATE_CPU (sd
, i
);
294 CPU_REG_FETCH (cpu
) = v850_reg_fetch
;
295 CPU_REG_STORE (cpu
) = v850_reg_store
;
296 CPU_PC_FETCH (cpu
) = v850_pc_get
;
297 CPU_PC_STORE (cpu
) = v850_pc_set
;
304 sim_create_inferior (SIM_DESC sd
,
305 struct bfd
* prog_bfd
,
309 memset (&State
, 0, sizeof (State
));
310 if (prog_bfd
!= NULL
)
311 PC
= bfd_get_start_address (prog_bfd
);
316 v850_reg_fetch (SIM_CPU
*cpu
, int rn
, unsigned char *memory
, int length
)
318 *(uint32_t*)memory
= H2T_4 (State
.regs
[rn
]);
323 v850_reg_store (SIM_CPU
*cpu
, int rn
, const unsigned char *memory
, int length
)
325 State
.regs
[rn
] = T2H_4 (*(uint32_t *) memory
);