]>
git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - sim/v850/interp.c
1 /* This must come before any other includes. */
5 #include "sim-options.h"
7 #include "sim-assert.h"
15 static const char * get_insn_name (sim_cpu
*, int);
17 /* For compatibility. */
20 /* V850 interrupt model. */
35 const char *interrupt_names
[] =
49 do_interrupt (SIM_DESC sd
, void *data
)
51 const char **interrupt_name
= (const char**)data
;
52 enum interrupt_type inttype
;
53 inttype
= (interrupt_name
- STATE_WATCHPOINTS (sd
)->interrupt_names
);
55 /* For a hardware reset, drop everything and jump to the start
57 if (inttype
== int_reset
)
62 sim_engine_restart (sd
, NULL
, NULL
, NULL_CIA
);
65 /* Deliver an NMI when allowed */
66 if (inttype
== int_nmi
)
70 /* We're already working on an NMI, so this one must wait
71 around until the previous one is done. The processor
72 ignores subsequent NMIs, so we don't need to count them.
73 Just keep re-scheduling a single NMI until it manages to
75 if (STATE_CPU (sd
, 0)->pending_nmi
!= NULL
)
76 sim_events_deschedule (sd
, STATE_CPU (sd
, 0)->pending_nmi
);
77 STATE_CPU (sd
, 0)->pending_nmi
=
78 sim_events_schedule (sd
, 1, do_interrupt
, data
);
83 /* NMI can be delivered. Do not deschedule pending_nmi as
84 that, if still in the event queue, is a second NMI that
85 needs to be delivered later. */
88 /* Set the FECC part of the ECR. */
95 sim_engine_restart (sd
, NULL
, NULL
, NULL_CIA
);
99 /* deliver maskable interrupt when allowed */
100 if (inttype
> int_nmi
&& inttype
< num_int_types
)
102 if ((PSW
& PSW_NP
) || (PSW
& PSW_ID
))
104 /* Can't deliver this interrupt, reschedule it for later */
105 sim_events_schedule (sd
, 1, do_interrupt
, data
);
113 /* Disable further interrupts. */
115 /* Indicate that we're doing interrupt not exception processing. */
117 /* Clear the EICC part of the ECR, will set below. */
146 /* Should never be possible. */
147 sim_engine_abort (sd
, NULL
, NULL_CIA
,
148 "do_interrupt - internal error - bad switch");
152 sim_engine_restart (sd
, NULL
, NULL
, NULL_CIA
);
155 /* some other interrupt? */
156 sim_engine_abort (sd
, NULL
, NULL_CIA
,
157 "do_interrupt - internal error - interrupt %d unknown",
161 /* Return name of an insn, used by insn profiling. */
164 get_insn_name (sim_cpu
*cpu
, int i
)
166 return itable
[i
].name
;
169 /* These default values correspond to expected usage for the chip. */
174 v850_pc_get (sim_cpu
*cpu
)
180 v850_pc_set (sim_cpu
*cpu
, sim_cia pc
)
185 static int v850_reg_fetch (SIM_CPU
*, int, unsigned char *, int);
186 static int v850_reg_store (SIM_CPU
*, int, unsigned char *, int);
189 sim_open (SIM_OPEN_KIND kind
,
195 SIM_DESC sd
= sim_state_alloc (kind
, cb
);
198 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
200 /* The cpu data is kept in a separately allocated chunk of memory. */
201 if (sim_cpu_alloc_all (sd
, 1) != SIM_RC_OK
)
204 /* for compatibility */
207 /* FIXME: should be better way of setting up interrupts */
208 STATE_WATCHPOINTS (sd
)->interrupt_handler
= do_interrupt
;
209 STATE_WATCHPOINTS (sd
)->interrupt_names
= interrupt_names
;
211 /* Initialize the mechanism for doing insn profiling. */
212 CPU_INSN_NAME (STATE_CPU (sd
, 0)) = get_insn_name
;
213 CPU_MAX_INSNS (STATE_CPU (sd
, 0)) = nr_itable_entries
;
215 if (sim_pre_argv_init (sd
, argv
[0]) != SIM_RC_OK
)
218 /* Allocate core managed memory */
220 /* "Mirror" the ROM addresses below 1MB. */
221 sim_do_commandf (sd
, "memory region 0,0x100000,0x%x", V850_ROM_SIZE
);
222 /* Chunk of ram adjacent to rom */
223 sim_do_commandf (sd
, "memory region 0x100000,0x%x", V850_LOW_END
-0x100000);
224 /* peripheral I/O region - mirror 1K across 4k (0x1000) */
225 sim_do_command (sd
, "memory region 0xfff000,0x1000,1024");
226 /* similarly if in the internal RAM region */
227 sim_do_command (sd
, "memory region 0xffe000,0x1000,1024");
229 /* The parser will print an error message for us, so we silently return. */
230 if (sim_parse_args (sd
, argv
) != SIM_RC_OK
)
232 /* Uninstall the modules to avoid memory leaks,
233 file descriptor leaks, etc. */
234 sim_module_uninstall (sd
);
238 /* check for/establish the a reference program image */
239 if (sim_analyze_program (sd
,
240 (STATE_PROG_ARGV (sd
) != NULL
241 ? *STATE_PROG_ARGV (sd
)
245 sim_module_uninstall (sd
);
249 /* establish any remaining configuration options */
250 if (sim_config (sd
) != SIM_RC_OK
)
252 sim_module_uninstall (sd
);
256 if (sim_post_argv_init (sd
) != SIM_RC_OK
)
258 /* Uninstall the modules to avoid memory leaks,
259 file descriptor leaks, etc. */
260 sim_module_uninstall (sd
);
265 /* determine the machine type */
266 if (STATE_ARCHITECTURE (sd
) != NULL
267 && (STATE_ARCHITECTURE (sd
)->arch
== bfd_arch_v850
268 || STATE_ARCHITECTURE (sd
)->arch
== bfd_arch_v850_rh850
))
269 mach
= STATE_ARCHITECTURE (sd
)->mach
;
271 mach
= bfd_mach_v850
; /* default */
273 /* set machine specific configuration */
278 case bfd_mach_v850e1
:
279 case bfd_mach_v850e2
:
280 case bfd_mach_v850e2v3
:
281 case bfd_mach_v850e3v5
:
282 STATE_CPU (sd
, 0)->psw_mask
= (PSW_NP
| PSW_EP
| PSW_ID
| PSW_SAT
283 | PSW_CY
| PSW_OV
| PSW_S
| PSW_Z
);
287 /* CPU specific initialization. */
288 for (i
= 0; i
< MAX_NR_PROCESSORS
; ++i
)
290 SIM_CPU
*cpu
= STATE_CPU (sd
, i
);
292 CPU_REG_FETCH (cpu
) = v850_reg_fetch
;
293 CPU_REG_STORE (cpu
) = v850_reg_store
;
294 CPU_PC_FETCH (cpu
) = v850_pc_get
;
295 CPU_PC_STORE (cpu
) = v850_pc_set
;
302 sim_create_inferior (SIM_DESC sd
,
303 struct bfd
* prog_bfd
,
307 memset (&State
, 0, sizeof (State
));
308 if (prog_bfd
!= NULL
)
309 PC
= bfd_get_start_address (prog_bfd
);
314 v850_reg_fetch (SIM_CPU
*cpu
, int rn
, unsigned char *memory
, int length
)
316 *(unsigned32
*)memory
= H2T_4 (State
.regs
[rn
]);
321 v850_reg_store (SIM_CPU
*cpu
, int rn
, unsigned char *memory
, int length
)
323 State
.regs
[rn
] = T2H_4 (*(unsigned32
*) memory
);