]>
git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - sim/v850/interp.c
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 struct hash_entry
*h
;
228 /* for compatibility */
231 /* FIXME: should be better way of setting up interrupts */
232 STATE_WATCHPOINTS (sd
)->pc
= &(PC
);
233 STATE_WATCHPOINTS (sd
)->sizeof_pc
= sizeof (PC
);
234 STATE_WATCHPOINTS (sd
)->interrupt_handler
= do_interrupt
;
235 STATE_WATCHPOINTS (sd
)->interrupt_names
= interrupt_names
;
236 /* start-sanitize-v850e */
237 STATE_ARCHITECTURE (sd
) = bfd_lookup_arch (bfd_arch_v850
, bfd_mach_v850e
);
238 /* end-sanitize-v850e */
239 /* start-sanitize-v850eq */
240 STATE_ARCHITECTURE (sd
) = bfd_lookup_arch (bfd_arch_v850
, bfd_mach_v850eq
);
241 /* end-sanitize-v850eq */
243 if (sim_pre_argv_init (sd
, argv
[0]) != SIM_RC_OK
)
246 /* Allocate core managed memory */
248 /* "Mirror" the ROM addresses below 1MB. */
249 sim_do_commandf (sd
, "memory region 0,0x100000,0x%lx", V850_ROM_SIZE
);
250 /* Chunk of ram adjacent to rom */
251 sim_do_commandf (sd
, "memory region 0x100000,0x%lx", V850_LOW_END
-0x100000);
252 /* peripheral I/O region - mirror 1K across 4k (0x1000) */
253 sim_do_command (sd
, "memory region 0xfff000,0x1000,1024");
254 /* similarly if in the internal RAM region */
255 sim_do_command (sd
, "memory region 0xffe000,0x1000,1024");
257 /* getopt will print the error message so we just have to exit if this fails.
258 FIXME: Hmmm... in the case of gdb we need getopt to call
260 if (sim_parse_args (sd
, argv
) != SIM_RC_OK
)
262 /* Uninstall the modules to avoid memory leaks,
263 file descriptor leaks, etc. */
264 sim_module_uninstall (sd
);
268 /* check for/establish the a reference program image */
269 if (sim_analyze_program (sd
,
270 (STATE_PROG_ARGV (sd
) != NULL
271 ? *STATE_PROG_ARGV (sd
)
275 sim_module_uninstall (sd
);
279 /* establish any remaining configuration options */
280 if (sim_config (sd
) != SIM_RC_OK
)
282 sim_module_uninstall (sd
);
286 if (sim_post_argv_init (sd
) != SIM_RC_OK
)
288 /* Uninstall the modules to avoid memory leaks,
289 file descriptor leaks, etc. */
290 sim_module_uninstall (sd
);
295 /* put all the opcodes in the hash table */
296 for (s
= Simops
; s
->func
; s
++)
298 h
= &hash_table
[hash(s
->opcode
)];
300 /* go to the last entry in the chain */
306 h
->next
= (struct hash_entry
*) calloc(1,sizeof(struct hash_entry
));
311 h
->opcode
= s
->opcode
;
320 sim_close (sd
, quitting
)
324 sim_module_uninstall (sd
);
336 sim_engine_run (sd
, next_cpu_nr
, siggnal
)
346 struct hash_entry
* h
;
347 /* Fetch the current instruction. */
351 h
= lookup_hash (sd
, inst
);
353 OP
[1] = (inst
>> 11) & 0x1f;
354 OP
[2] = (inst
>> 16) & 0xffff;
357 /* fprintf (stderr, "PC = %x, SP = %x\n", PC, SP ); */
361 fprintf (stderr
, "NOP encountered!\n");
365 PC
+= h
->ops
->func ();
369 sim_io_eprintf (sd
, "simulator loop at %lx\n", (long) PC
);
373 if (sim_events_tick (sd
))
375 sim_events_process (sd
);
389 sim_resume (sd
, 0, 0);
395 sim_info (sd
, verbose
)
399 profile_print (sd
, STATE_VERBOSE_P (sd
), NULL
, NULL
);
403 sim_create_inferior (sd
, prog_bfd
, argv
, env
)
405 struct _bfd
*prog_bfd
;
409 memset (&State
, 0, sizeof (State
));
410 if (prog_bfd
!= NULL
)
411 PC
= bfd_get_start_address (prog_bfd
);
416 sim_fetch_register (sd
, rn
, memory
)
419 unsigned char *memory
;
421 *(unsigned32
*)memory
= H2T_4 (State
.regs
[rn
]);
425 sim_store_register (sd
, rn
, memory
)
428 unsigned char *memory
;
430 State
.regs
[rn
] = T2H_4 (*(unsigned32
*)memory
);
434 sim_do_command (sd
, cmd
)
438 char *mm_cmd
= "memory-map";
439 char *int_cmd
= "interrupt";
441 if (sim_args_command (sd
, cmd
) != SIM_RC_OK
)
443 if (strncmp (cmd
, mm_cmd
, strlen (mm_cmd
) == 0))
444 sim_io_eprintf (sd
, "`memory-map' command replaced by `sim memory'\n");
445 else if (strncmp (cmd
, int_cmd
, strlen (int_cmd
)) == 0)
446 sim_io_eprintf (sd
, "`interrupt' command replaced by `sim watch'\n");
448 sim_io_eprintf (sd
, "Unknown command `%s'\n", cmd
);