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
);
69 /* Disable further interrupts. */
71 /* Indicate that we're doing interrupt not exception processing. */
73 if (inttype
== int_reset
)
78 /* (Might be useful to init other regs with random values.) */
80 else if (inttype
== int_nmi
)
84 /* We're already working on an NMI, so this one must wait
85 around until the previous one is done. The processor
86 ignores subsequent NMIs, so we don't need to count them. */
87 State
.pending_nmi
= 1;
93 /* Set the FECC part of the ECR. */
104 /* Clear the EICC part of the ECR, will set below. */
133 /* Should never be possible. */
140 /* These default values correspond to expected usage for the chip. */
146 static long hash
PARAMS ((long));
148 static void do_format_1_2
PARAMS ((uint32
));
149 static void do_format_3
PARAMS ((uint32
));
150 static void do_format_4
PARAMS ((uint32
));
151 static void do_format_5
PARAMS ((uint32
));
152 static void do_format_6
PARAMS ((uint32
));
153 static void do_format_7
PARAMS ((uint32
));
154 static void do_format_8
PARAMS ((uint32
));
155 static void do_format_9_10
PARAMS ((uint32
));
162 struct hash_entry
*next
;
163 unsigned long opcode
;
168 struct hash_entry hash_table
[MAX_HASH
+1];
175 if ( (insn
& 0x0600) == 0
176 || (insn
& 0x0700) == 0x0200
177 || (insn
& 0x0700) == 0x0600
178 || (insn
& 0x0780) == 0x0700)
179 return (insn
& 0x07e0) >> 5;
181 if ((insn
& 0x0700) == 0x0300
182 || (insn
& 0x0700) == 0x0400
183 || (insn
& 0x0700) == 0x0500)
184 return (insn
& 0x0780) >> 7;
186 if ((insn
& 0x07c0) == 0x0780)
187 return (insn
& 0x07c0) >> 6;
189 return (insn
& 0x07e0) >> 5;
193 static struct hash_entry
*
194 lookup_hash (sd
, ins
)
198 struct hash_entry
*h
;
200 h
= &hash_table
[hash(ins
)];
202 while ((ins
& h
->mask
) != h
->opcode
)
206 sim_io_error (sd
, "ERROR looking up hash for 0x%lx, PC=0x%lx",
207 (long) ins
, (long) PC
);
216 sim_open (kind
, cb
, abfd
, argv
)
222 SIM_DESC sd
= sim_state_alloc (kind
, cb
);
225 /* for compatibility */
228 /* FIXME: should be better way of setting up interrupts */
229 STATE_WATCHPOINTS (sd
)->pc
= &(PC
);
230 STATE_WATCHPOINTS (sd
)->sizeof_pc
= sizeof (PC
);
231 STATE_WATCHPOINTS (sd
)->interrupt_handler
= do_interrupt
;
232 STATE_WATCHPOINTS (sd
)->interrupt_names
= interrupt_names
;
234 if (sim_pre_argv_init (sd
, argv
[0]) != SIM_RC_OK
)
237 /* Allocate core managed memory */
239 /* "Mirror" the ROM addresses below 1MB. */
240 sim_do_commandf (sd
, "memory region 0,0x100000,0x%lx", V850_ROM_SIZE
);
241 /* Chunk of ram adjacent to rom */
242 sim_do_commandf (sd
, "memory region 0x100000,0x%lx", V850_LOW_END
-0x100000);
243 /* peripheral I/O region - mirror 1K across 4k (0x1000) */
244 sim_do_command (sd
, "memory region 0xfff000,0x1000,1024");
245 /* similarly if in the internal RAM region */
246 sim_do_command (sd
, "memory region 0xffe000,0x1000,1024");
248 /* getopt will print the error message so we just have to exit if this fails.
249 FIXME: Hmmm... in the case of gdb we need getopt to call
251 if (sim_parse_args (sd
, argv
) != SIM_RC_OK
)
253 /* Uninstall the modules to avoid memory leaks,
254 file descriptor leaks, etc. */
255 sim_module_uninstall (sd
);
259 /* check for/establish the a reference program image */
260 if (sim_analyze_program (sd
,
261 (STATE_PROG_ARGV (sd
) != NULL
262 ? *STATE_PROG_ARGV (sd
)
266 sim_module_uninstall (sd
);
270 /* establish any remaining configuration options */
271 if (sim_config (sd
) != SIM_RC_OK
)
273 sim_module_uninstall (sd
);
277 if (sim_post_argv_init (sd
) != SIM_RC_OK
)
279 /* Uninstall the modules to avoid memory leaks,
280 file descriptor leaks, etc. */
281 sim_module_uninstall (sd
);
286 /* determine the machine type */
287 if (STATE_ARCHITECTURE (sd
) != NULL
288 && STATE_ARCHITECTURE (sd
)->arch
== bfd_arch_v850
)
289 mach
= STATE_ARCHITECTURE (sd
)->mach
;
291 mach
= bfd_mach_v850
; /* default */
293 /* set machine specific configuration */
297 /* start-sanitize-v850e */
299 /* end-sanitize-v850e */
300 STATE_CPU (sd
, 0)->psw_mask
= (PSW_NP
| PSW_EP
| PSW_ID
| PSW_SAT
301 | PSW_CY
| PSW_OV
| PSW_S
| PSW_Z
);
303 /* start-sanitize-v850eq */
304 case bfd_mach_v850eq
:
306 STATE_CPU (sd
, 0)->psw_mask
= (PSW_US
307 | PSW_NP
| PSW_EP
| PSW_ID
| PSW_SAT
308 | PSW_CY
| PSW_OV
| PSW_S
| PSW_Z
);
310 /* end-sanitize-v850eq */
318 sim_close (sd
, quitting
)
322 sim_module_uninstall (sd
);
334 sim_engine_run (sd
, next_cpu_nr
, siggnal
)
344 struct hash_entry
* h
;
345 /* Fetch the current instruction. */
349 h
= lookup_hash (sd
, inst
);
351 OP
[1] = (inst
>> 11) & 0x1f;
352 OP
[2] = (inst
>> 16) & 0xffff;
355 /* fprintf (stderr, "PC = %x, SP = %x\n", PC, SP ); */
359 fprintf (stderr
, "NOP encountered!\n");
363 PC
+= h
->ops
->func ();
367 sim_io_eprintf (sd
, "simulator loop at %lx\n", (long) PC
);
371 if (sim_events_tick (sd
))
373 sim_events_process (sd
);
387 sim_resume (sd
, 0, 0);
393 sim_info (sd
, verbose
)
397 profile_print (sd
, STATE_VERBOSE_P (sd
), NULL
, NULL
);
401 sim_create_inferior (sd
, prog_bfd
, argv
, env
)
403 struct _bfd
*prog_bfd
;
407 memset (&State
, 0, sizeof (State
));
408 if (prog_bfd
!= NULL
)
409 PC
= bfd_get_start_address (prog_bfd
);
410 /* start-sanitize-v850eq */
411 /* For v850eq, set PSW[US] by default */
412 if (STATE_ARCHITECTURE (sd
) != NULL
413 && STATE_ARCHITECTURE (sd
)->arch
== bfd_arch_v850
414 && STATE_ARCHITECTURE (sd
)->mach
== bfd_mach_v850eq
)
416 /* end-sanitize-v850eq */
421 sim_fetch_register (sd
, rn
, memory
)
424 unsigned char *memory
;
426 *(unsigned32
*)memory
= H2T_4 (State
.regs
[rn
]);
430 sim_store_register (sd
, rn
, memory
)
433 unsigned char *memory
;
435 State
.regs
[rn
] = T2H_4 (*(unsigned32
*)memory
);
439 sim_do_command (sd
, cmd
)
443 char *mm_cmd
= "memory-map";
444 char *int_cmd
= "interrupt";
446 if (sim_args_command (sd
, cmd
) != SIM_RC_OK
)
448 if (strncmp (cmd
, mm_cmd
, strlen (mm_cmd
) == 0))
449 sim_io_eprintf (sd
, "`memory-map' command replaced by `sim memory'\n");
450 else if (strncmp (cmd
, int_cmd
, strlen (int_cmd
)) == 0)
451 sim_io_eprintf (sd
, "`interrupt' command replaced by `sim watch'\n");
453 sim_io_eprintf (sd
, "Unknown command `%s'\n", cmd
);