-struct interrupt_generator *intgen_list;
-
-/* True if a non-maskable (such as NMI or reset) interrupt generator
- is present. */
-
-static int have_nm_generator;
-
-#ifndef INLINE
-#ifdef __GNUC__
-#define INLINE inline
-#else
-#define INLINE
-#endif
-#endif
-
-/* These default values correspond to expected usage for the chip. */
-
-SIM_ADDR rom_size = 0x8000;
-SIM_ADDR low_end = 0x200000;
-SIM_ADDR high_start = 0xffe000;
-
-SIM_ADDR high_base;
-
-host_callback *v850_callback;
-
-int v850_debug;
-
-/* non-zero if we opened prog_bfd */
-static int prog_bfd_was_opened_p;
-bfd *prog_bfd;
-
-static SIM_OPEN_KIND sim_kind;
-static char *myname;
-
-uint32 OP[4];
-
-static struct hash_entry *lookup_hash PARAMS ((uint32 ins));
-static long hash PARAMS ((long));
-static void do_format_1_2 PARAMS ((uint32));
-static void do_format_3 PARAMS ((uint32));
-static void do_format_4 PARAMS ((uint32));
-static void do_format_5 PARAMS ((uint32));
-static void do_format_6 PARAMS ((uint32));
-static void do_format_7 PARAMS ((uint32));
-static void do_format_8 PARAMS ((uint32));
-static void do_format_9_10 PARAMS ((uint32));
-static void init_system PARAMS ((void));
-
-#define MAX_HASH 63
-
-struct hash_entry
-{
- struct hash_entry *next;
- long opcode;
- long mask;
- struct simops *ops;
-};
-
-struct hash_entry hash_table[MAX_HASH+1];
-
-
-static INLINE long
-hash(insn)
- long insn;
-{
- if ( (insn & 0x0600) == 0
- || (insn & 0x0700) == 0x0200
- || (insn & 0x0700) == 0x0600
- || (insn & 0x0780) == 0x0700)
- return (insn & 0x07e0) >> 5;
-
- if ((insn & 0x0700) == 0x0300
- || (insn & 0x0700) == 0x0400
- || (insn & 0x0700) == 0x0500)
- return (insn & 0x0780) >> 7;
-
- if ((insn & 0x07c0) == 0x0780)
- return (insn & 0x07c0) >> 6;
-
- return (insn & 0x07e0) >> 5;
-}
-
-static struct hash_entry *
-lookup_hash (ins)
- uint32 ins;
-{
- struct hash_entry *h;
-
- h = &hash_table[hash(ins)];
-
- while ((ins & h->mask) != h->opcode)
- {
- if (h->next == NULL)
- {
- (*v850_callback->printf_filtered) (v850_callback, "ERROR looking up hash for 0x%x, PC=0x%x\n", ins, PC);
- exit(1);
- }
- h = h->next;
- }
- return (h);
-}
-
-/* FIXME These would more efficient to use than load_mem/store_mem,
- but need to be changed to use the memory map. */
-
-uint8
-get_byte (x)
- uint8 *x;
-{
- return *x;
-}
-
-uint16
-get_half (x)
- uint8 *x;
-{
- uint8 *a = x;
- return (a[1] << 8) + (a[0]);
-}
-
-uint32
-get_word (x)
- uint8 *x;
-{
- uint8 *a = x;
- return (a[3]<<24) + (a[2]<<16) + (a[1]<<8) + (a[0]);
-}
-
-void
-put_byte (addr, data)
- uint8 *addr;
- uint8 data;
-{
- uint8 *a = addr;
- a[0] = data;
-}
-
-void
-put_half (addr, data)
- uint8 *addr;
- uint16 data;
-{
- uint8 *a = addr;
- a[0] = data & 0xff;
- a[1] = (data >> 8) & 0xff;
-}
-
-void
-put_word (addr, data)
- uint8 *addr;
- uint32 data;
-{
- uint8 *a = addr;
- a[0] = data & 0xff;
- a[1] = (data >> 8) & 0xff;
- a[2] = (data >> 16) & 0xff;
- a[3] = (data >> 24) & 0xff;
-}
-
-uint8 *
-map (addr)
- SIM_ADDR addr;
-{
- uint8 *p;
-
- /* Mask down to 24 bits. */
- addr &= 0xffffff;
-
- if (addr < low_end)
- {
- /* "Mirror" the addresses below 1MB. */
- if (addr < 0x100000)
- addr &= (rom_size - 1);
- else
- addr += (rom_size - 0x100000);
- return (uint8 *) (addr + State.mem);
- }
- else if (addr >= high_start)
- {
- /* If in the peripheral I/O region, mirror 1K region across 4K,
- and similarly if in the internal RAM region. */
- if (addr >= 0xfff000)
- addr &= 0xfff3ff;
- else if (addr >= 0xffe000)
- addr &= 0xffe3ff;
- return (uint8 *) (addr - high_start + high_base + State.mem);
- }
- else
- {
- fprintf (stderr, "segmentation fault: access address: %x not below %x or above %x [ep = %x]\n", addr, low_end, high_start, State.regs[30]);
-
- /* Signal a memory error. */
- State.exception = SIGSEGV;
- /* Point to a location not in main memory - renders invalid
- addresses harmless until we get back to main insn loop. */
- return (uint8 *) &(State.dummy_mem);
- }
-}
-
-uint32
-load_mem (addr, len)
- SIM_ADDR addr;
- int len;
-{
- uint8 *p = map (addr);
-
- switch (len)
- {
- case 1:
- return p[0];
- case 2:
- return p[1] << 8 | p[0];
- case 4:
- return p[3] << 24 | p[2] << 16 | p[1] << 8 | p[0];
- default:
- abort ();
- }
-}
-
-void
-store_mem (addr, len, data)
- SIM_ADDR addr;
- int len;
- uint32 data;
-{
- uint8 *p = map (addr);
-
- switch (len)
- {
- case 1:
- p[0] = data;
- return;
- case 2:
- p[0] = data;
- p[1] = data >> 8;
- return;
- case 4:
- p[0] = data;
- p[1] = data >> 8;
- p[2] = data >> 16;
- p[3] = data >> 24;
- return;
- default:
- abort ();
- }
-}
-
-void
-sim_size (power)
- int power;
-