X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=sim%2Fh8300%2Fcompile.c;h=fb0e51b2e58d381c26296fae805dff3fca1bed7a;hb=d5a71b1131778cf2a023855966831eb2457d50d6;hp=cd097d68a98e00ba104591b6333263690987c5bf;hpb=d6fd015d6e56f31566d6c754a103693912abcb5c;p=binutils-gdb.git diff --git a/sim/h8300/compile.c b/sim/h8300/compile.c index cd097d68a98..fb0e51b2e58 100644 --- a/sim/h8300/compile.c +++ b/sim/h8300/compile.c @@ -17,13 +17,10 @@ * AND FITNESS FOR A PARTICULAR PURPOSE. */ +#include "config.h" #include -#ifdef HAVE_TIME_H #include -#endif -#ifdef HAVE_STDLIB_H #include -#endif #ifdef HAVE_SYS_PARAM_H #include #endif @@ -33,6 +30,7 @@ #include "gdb/sim-h8300.h" #include "sys/stat.h" #include "sys/types.h" +#include "sim-options.h" #ifndef SIGTRAP # define SIGTRAP 5 @@ -40,16 +38,7 @@ int debug; -host_callback *sim_callback; - -static SIM_OPEN_KIND sim_kind; -static char *myname; - -/* FIXME: Needs to live in header file. - This header should also include the things in remote-sim.h. - One could move this to remote-sim.h but this function isn't needed - by gdb. */ -static void set_simcache_size (SIM_DESC, int); +static int memory_size; #define X(op, size) (op * 4 + size) @@ -61,32 +50,6 @@ static void set_simcache_size (SIM_DESC, int); /* CPU data object: */ -static int -sim_state_initialize (SIM_DESC sd, sim_cpu *cpu) -{ - /* FIXME: not really necessary, since sim_cpu_alloc calls zalloc. */ - - memset (&cpu->regs, 0, sizeof(cpu->regs)); - cpu->regs[SBR_REGNUM] = 0xFFFFFF00; - cpu->pc = 0; - cpu->delayed_branch = 0; - cpu->memory = NULL; - cpu->eightbit = NULL; - cpu->mask = 0; - - /* Initialize local simulator state. */ - sd->sim_cache = NULL; - sd->sim_cache_size = 0; - sd->cache_idx = NULL; - sd->cache_top = 0; - sd->memory_size = 0; - sd->compiles = 0; -#ifdef ADEBUG - memset (&cpu->stats, 0, sizeof (cpu->stats)); -#endif - return 0; -} - static unsigned int h8_get_pc (SIM_DESC sd) { @@ -147,18 +110,6 @@ h8_set_vbr (SIM_DESC sd, int val) (STATE_CPU (sd, 0)) -> regs[VBR_REGNUM] = val; } -static int -h8_get_cache_top (SIM_DESC sd) -{ - return sd -> cache_top; -} - -static void -h8_set_cache_top (SIM_DESC sd, int val) -{ - sd -> cache_top = val; -} - static int h8_get_mask (SIM_DESC sd) { @@ -255,18 +206,6 @@ h8_set_macl (SIM_DESC sd, unsigned int val) (STATE_CPU (sd, 0)) -> regs[MACL_REGNUM] = val; } -static int -h8_get_compiles (SIM_DESC sd) -{ - return sd -> compiles; -} - -static void -h8_increment_compiles (SIM_DESC sd) -{ - sd -> compiles ++; -} - static unsigned int * h8_get_reg_buf (SIM_DESC sd) { @@ -299,32 +238,6 @@ h8_increment_stats (SIM_DESC sd, int idx) } #endif /* ADEBUG */ -static unsigned short * -h8_get_cache_idx_buf (SIM_DESC sd) -{ - return sd -> cache_idx; -} - -static void -h8_set_cache_idx_buf (SIM_DESC sd, unsigned short *ptr) -{ - sd -> cache_idx = ptr; -} - -static unsigned short -h8_get_cache_idx (SIM_DESC sd, unsigned int idx) -{ - if (idx > sd->memory_size) - return (unsigned short) -1; - return sd -> cache_idx[idx]; -} - -static void -h8_set_cache_idx (SIM_DESC sd, int idx, unsigned int val) -{ - sd -> cache_idx[idx] = (unsigned short) val; -} - static unsigned char * h8_get_memory_buf (SIM_DESC sd) { @@ -340,39 +253,17 @@ h8_set_memory_buf (SIM_DESC sd, unsigned char *ptr) static unsigned char h8_get_memory (SIM_DESC sd, int idx) { + ASSERT (idx < memory_size); return (STATE_CPU (sd, 0)) -> memory[idx]; } static void h8_set_memory (SIM_DESC sd, int idx, unsigned int val) { + ASSERT (idx < memory_size); (STATE_CPU (sd, 0)) -> memory[idx] = (unsigned char) val; } -static unsigned char * -h8_get_eightbit_buf (SIM_DESC sd) -{ - return (STATE_CPU (sd, 0)) -> eightbit; -} - -static void -h8_set_eightbit_buf (SIM_DESC sd, unsigned char *ptr) -{ - (STATE_CPU (sd, 0)) -> eightbit = ptr; -} - -static unsigned char -h8_get_eightbit (SIM_DESC sd, int idx) -{ - return (STATE_CPU (sd, 0)) -> eightbit[idx]; -} - -static void -h8_set_eightbit (SIM_DESC sd, int idx, unsigned int val) -{ - (STATE_CPU (sd, 0)) -> eightbit[idx] = (unsigned char) val; -} - static unsigned int h8_get_delayed_branch (SIM_DESC sd) { @@ -513,8 +404,6 @@ int h8300smode = 0; int h8300_normal_mode = 0; int h8300sxmode = 0; -static int memory_size; - static int get_now (void) { @@ -552,6 +441,8 @@ bitfrom (int x) static unsigned int lvalue (SIM_DESC sd, int x, int rn, unsigned int *val) { + SIM_CPU *cpu = STATE_CPU (sd, 0); + if (val == NULL) /* Paranoia. */ return -1; @@ -567,14 +458,14 @@ lvalue (SIM_DESC sd, int x, int rn, unsigned int *val) *val = X (OP_MEM, SP); break; default: - sim_engine_set_run_state (sd, sim_stopped, SIGSEGV); + sim_engine_halt (sd, cpu, NULL, NULL_CIA, sim_stopped, SIM_SIGSEGV); return -1; } return 0; } static int -cmdline_location() +cmdline_location(void) { if (h8300smode && !h8300_normal_mode) return 0xffff00L; @@ -599,7 +490,7 @@ decode (SIM_DESC sd, int addr, unsigned char *data, decoded_inst *dst) /* Find the exact opcode/arg combo. */ for (q = h8_opcodes; q->name; q++) { - op_type *nib = q->data.nib; + const op_type *nib = q->data.nib; unsigned int len = 0; if ((q->available == AV_H8SX && !h8300sxmode) || @@ -924,7 +815,7 @@ decode (SIM_DESC sd, int addr, unsigned char *data, decoded_inst *dst) #endif /* Fill in the args. */ { - op_type *args = q->args.nib; + const op_type *args = q->args.nib; int hadone = 0; int nargs; @@ -1018,7 +909,7 @@ decode (SIM_DESC sd, int addr, unsigned char *data, decoded_inst *dst) p->literal = 0; if (OP_KIND (q->how) == O_JSR || OP_KIND (q->how) == O_JMP) - if (lvalue (sd, p->type, p->reg, &p->type)) + if (lvalue (sd, p->type, p->reg, (unsigned int *)&p->type)) goto end; } else if ((x & MODE) == ABS) @@ -1050,7 +941,7 @@ decode (SIM_DESC sd, int addr, unsigned char *data, decoded_inst *dst) p->literal = cst[opnum]; if (OP_KIND (q->how) == O_JSR || OP_KIND (q->how) == O_JMP) - if (lvalue (sd, p->type, p->reg, &p->type)) + if (lvalue (sd, p->type, p->reg, (unsigned int *)&p->type)) goto end; } else if ((x & MODE) == PCREL) @@ -1224,37 +1115,8 @@ decode (SIM_DESC sd, int addr, unsigned char *data, decoded_inst *dst) dst->opcode = O (O_ILL, SB); } -static void -compile (SIM_DESC sd, int pc) -{ - int idx; - - /* Find the next cache entry to use. */ - idx = h8_get_cache_top (sd) + 1; - h8_increment_compiles (sd); - if (idx >= sd->sim_cache_size) - { - idx = 1; - } - h8_set_cache_top (sd, idx); - - /* Throw away its old meaning. */ - h8_set_cache_idx (sd, sd->sim_cache[idx].oldpc, 0); - - /* Set to new address. */ - sd->sim_cache[idx].oldpc = pc; - - /* Fill in instruction info. */ - decode (sd, pc, h8_get_memory_buf (sd) + pc, sd->sim_cache + idx); - - /* Point to new cache entry. */ - h8_set_cache_idx (sd, pc, idx); -} - - static unsigned char *breg[32]; static unsigned short *wreg[16]; -static unsigned int *lreg[18]; #define GET_B_REG(X) *(breg[X]) #define SET_B_REG(X, Y) (*(breg[X])) = (Y) @@ -1267,41 +1129,31 @@ static unsigned int *lreg[18]; ((X) < memory_size \ ? ((h8_get_memory (sd, (X)+0) << 24) | (h8_get_memory (sd, (X)+1) << 16) \ | (h8_get_memory (sd, (X)+2) << 8) | (h8_get_memory (sd, (X)+3) << 0)) \ - : ((h8_get_eightbit (sd, ((X)+0) & 0xff) << 24) \ - | (h8_get_eightbit (sd, ((X)+1) & 0xff) << 16) \ - | (h8_get_eightbit (sd, ((X)+2) & 0xff) << 8) \ - | (h8_get_eightbit (sd, ((X)+3) & 0xff) << 0))) + : 0) #define GET_MEMORY_W(X) \ ((X) < memory_size \ - ? ((h8_get_memory (sd, (X)+0) << 8) \ - | (h8_get_memory (sd, (X)+1) << 0)) \ - : ((h8_get_eightbit (sd, ((X)+0) & 0xff) << 8) \ - | (h8_get_eightbit (sd, ((X)+1) & 0xff) << 0))) - + ? ((h8_get_memory (sd, (X)+0) << 8) | (h8_get_memory (sd, (X)+1) << 0)) \ + : 0) #define GET_MEMORY_B(X) \ - ((X) < memory_size ? (h8_get_memory (sd, (X))) \ - : (h8_get_eightbit (sd, (X) & 0xff))) + ((X) < memory_size ? h8_get_memory (sd, (X)) : 0) #define SET_MEMORY_L(X, Y) \ { register unsigned char *_p; register int __y = (Y); \ - _p = ((X) < memory_size ? h8_get_memory_buf (sd) + (X) : \ - h8_get_eightbit_buf (sd) + ((X) & 0xff)); \ + _p = ((X) < memory_size ? h8_get_memory_buf (sd) + (X) : 0); \ _p[0] = __y >> 24; _p[1] = __y >> 16; \ _p[2] = __y >> 8; _p[3] = __y >> 0; \ } #define SET_MEMORY_W(X, Y) \ { register unsigned char *_p; register int __y = (Y); \ - _p = ((X) < memory_size ? h8_get_memory_buf (sd) + (X) : \ - h8_get_eightbit_buf (sd) + ((X) & 0xff)); \ + _p = ((X) < memory_size ? h8_get_memory_buf (sd) + (X) : 0); \ _p[0] = __y >> 8; _p[1] = __y; \ } #define SET_MEMORY_B(X, Y) \ - ((X) < memory_size ? (h8_set_memory (sd, (X), (Y))) \ - : (h8_set_eightbit (sd, (X) & 0xff, (Y)))) + ((X) < memory_size ? h8_set_memory (sd, (X), (Y)) : 0) /* Simulate a memory fetch. Return 0 for success, -1 for failure. @@ -1310,6 +1162,7 @@ static unsigned int *lreg[18]; static int fetch_1 (SIM_DESC sd, ea_type *arg, int *val, int twice) { + SIM_CPU *cpu = STATE_CPU (sd, 0); int rn = arg->reg; int abs = arg->literal; int r; @@ -1386,105 +1239,93 @@ fetch_1 (SIM_DESC sd, ea_type *arg, int *val, int twice) break; case X (OP_POSTINC, SB): /* Register indirect w/post-incr: byte. */ t = GET_L_REG (rn); - t &= h8_get_mask (sd); - r = GET_MEMORY_B (t); + r = GET_MEMORY_B (t & h8_get_mask (sd)); if (!twice) t += 1; - t = t & h8_get_mask (sd); SET_L_REG (rn, t); *val = r; break; case X (OP_POSTINC, SW): /* Register indirect w/post-incr: word. */ t = GET_L_REG (rn); - t &= h8_get_mask (sd); - r = GET_MEMORY_W (t); + r = GET_MEMORY_W (t & h8_get_mask (sd)); if (!twice) t += 2; - t = t & h8_get_mask (sd); SET_L_REG (rn, t); *val = r; break; case X (OP_POSTINC, SL): /* Register indirect w/post-incr: long. */ t = GET_L_REG (rn); - t &= h8_get_mask (sd); - r = GET_MEMORY_L (t); + r = GET_MEMORY_L (t & h8_get_mask (sd)); if (!twice) t += 4; - t = t & h8_get_mask (sd); SET_L_REG (rn, t); *val = r; break; case X (OP_POSTDEC, SB): /* Register indirect w/post-decr: byte. */ t = GET_L_REG (rn); - t &= h8_get_mask (sd); - r = GET_MEMORY_B (t); + r = GET_MEMORY_B (t & h8_get_mask (sd)); if (!twice) t -= 1; - t = t & h8_get_mask (sd); SET_L_REG (rn, t); *val = r; break; case X (OP_POSTDEC, SW): /* Register indirect w/post-decr: word. */ t = GET_L_REG (rn); - t &= h8_get_mask (sd); - r = GET_MEMORY_W (t); + r = GET_MEMORY_W (t & h8_get_mask (sd)); if (!twice) t -= 2; - t = t & h8_get_mask (sd); SET_L_REG (rn, t); *val = r; break; case X (OP_POSTDEC, SL): /* Register indirect w/post-decr: long. */ t = GET_L_REG (rn); - t &= h8_get_mask (sd); - r = GET_MEMORY_L (t); + r = GET_MEMORY_L (t & h8_get_mask (sd)); if (!twice) t -= 4; - t = t & h8_get_mask (sd); SET_L_REG (rn, t); *val = r; break; case X (OP_PREDEC, SB): /* Register indirect w/pre-decr: byte. */ t = GET_L_REG (rn) - 1; - t &= h8_get_mask (sd); SET_L_REG (rn, t); + t &= h8_get_mask (sd); *val = GET_MEMORY_B (t); break; case X (OP_PREDEC, SW): /* Register indirect w/pre-decr: word. */ t = GET_L_REG (rn) - 2; - t &= h8_get_mask (sd); SET_L_REG (rn, t); + t &= h8_get_mask (sd); *val = GET_MEMORY_W (t); break; case X (OP_PREDEC, SL): /* Register indirect w/pre-decr: long. */ t = GET_L_REG (rn) - 4; - t &= h8_get_mask (sd); SET_L_REG (rn, t); + t &= h8_get_mask (sd); *val = GET_MEMORY_L (t); break; case X (OP_PREINC, SB): /* Register indirect w/pre-incr: byte. */ t = GET_L_REG (rn) + 1; - t &= h8_get_mask (sd); SET_L_REG (rn, t); + t &= h8_get_mask (sd); *val = GET_MEMORY_B (t); break; case X (OP_PREINC, SW): /* Register indirect w/pre-incr: long. */ t = GET_L_REG (rn) + 2; - t &= h8_get_mask (sd); SET_L_REG (rn, t); + t &= h8_get_mask (sd); *val = GET_MEMORY_W (t); break; case X (OP_PREINC, SL): /* Register indirect w/pre-incr: long. */ t = GET_L_REG (rn) + 4; - t &= h8_get_mask (sd); SET_L_REG (rn, t); + t &= h8_get_mask (sd); *val = GET_MEMORY_L (t); break; @@ -1527,7 +1368,7 @@ fetch_1 (SIM_DESC sd, ea_type *arg, int *val, int twice) case X (OP_MEM, SB): /* Why isn't this implemented? */ default: - sim_engine_set_run_state (sd, sim_stopped, SIGSEGV); + sim_engine_halt (sd, cpu, NULL, NULL_CIA, sim_stopped, SIM_SIGSEGV); return -1; } return 0; /* Success. */ @@ -1558,6 +1399,7 @@ fetch2 (SIM_DESC sd, ea_type *arg, int *val) static int store_1 (SIM_DESC sd, ea_type *arg, int n, int twice) { + SIM_CPU *cpu = STATE_CPU (sd, 0); int rn = arg->reg; int abs = arg->literal; int t; @@ -1621,8 +1463,8 @@ store_1 (SIM_DESC sd, ea_type *arg, int n, int twice) t = GET_L_REG (rn); if (!twice) t -= 1; - t &= h8_get_mask (sd); SET_L_REG (rn, t); + t &= h8_get_mask (sd); SET_MEMORY_B (t, n); break; @@ -1630,8 +1472,8 @@ store_1 (SIM_DESC sd, ea_type *arg, int n, int twice) t = GET_L_REG (rn); if (!twice) t -= 2; - t &= h8_get_mask (sd); SET_L_REG (rn, t); + t &= h8_get_mask (sd); SET_MEMORY_W (t, n); break; @@ -1639,8 +1481,8 @@ store_1 (SIM_DESC sd, ea_type *arg, int n, int twice) t = GET_L_REG (rn); if (!twice) t -= 4; - t &= h8_get_mask (sd); SET_L_REG (rn, t); + t &= h8_get_mask (sd); SET_MEMORY_L (t, n); break; @@ -1648,8 +1490,8 @@ store_1 (SIM_DESC sd, ea_type *arg, int n, int twice) t = GET_L_REG (rn); if (!twice) t += 1; - t &= h8_get_mask (sd); SET_L_REG (rn, t); + t &= h8_get_mask (sd); SET_MEMORY_B (t, n); break; @@ -1657,8 +1499,8 @@ store_1 (SIM_DESC sd, ea_type *arg, int n, int twice) t = GET_L_REG (rn); if (!twice) t += 2; - t &= h8_get_mask (sd); SET_L_REG (rn, t); + t &= h8_get_mask (sd); SET_MEMORY_W (t, n); break; @@ -1666,45 +1508,51 @@ store_1 (SIM_DESC sd, ea_type *arg, int n, int twice) t = GET_L_REG (rn); if (!twice) t += 4; - t &= h8_get_mask (sd); SET_L_REG (rn, t); + t &= h8_get_mask (sd); SET_MEMORY_L (t, n); break; case X (OP_POSTDEC, SB): /* Register indirect w/post-decr, byte. */ - t = GET_L_REG (rn) & h8_get_mask (sd); - SET_MEMORY_B (t, n); + t = GET_L_REG (rn); SET_L_REG (rn, t - 1); + t &= h8_get_mask (sd); + SET_MEMORY_B (t, n); break; case X (OP_POSTDEC, SW): /* Register indirect w/post-decr, word. */ - t = GET_L_REG (rn) & h8_get_mask (sd); - SET_MEMORY_W (t, n); + t = GET_L_REG (rn); SET_L_REG (rn, t - 2); + t &= h8_get_mask (sd); + SET_MEMORY_W (t, n); break; case X (OP_POSTDEC, SL): /* Register indirect w/post-decr, long. */ - t = GET_L_REG (rn) & h8_get_mask (sd); - SET_MEMORY_L (t, n); + t = GET_L_REG (rn); SET_L_REG (rn, t - 4); + t &= h8_get_mask (sd); + SET_MEMORY_L (t, n); break; case X (OP_POSTINC, SB): /* Register indirect w/post-incr, byte. */ - t = GET_L_REG (rn) & h8_get_mask (sd); - SET_MEMORY_B (t, n); + t = GET_L_REG (rn); SET_L_REG (rn, t + 1); + t &= h8_get_mask (sd); + SET_MEMORY_B (t, n); break; case X (OP_POSTINC, SW): /* Register indirect w/post-incr, word. */ - t = GET_L_REG (rn) & h8_get_mask (sd); - SET_MEMORY_W (t, n); + t = GET_L_REG (rn); SET_L_REG (rn, t + 2); + t &= h8_get_mask (sd); + SET_MEMORY_W (t, n); break; case X (OP_POSTINC, SL): /* Register indirect w/post-incr, long. */ - t = GET_L_REG (rn) & h8_get_mask (sd); - SET_MEMORY_L (t, n); + t = GET_L_REG (rn); SET_L_REG (rn, t + 4); + t &= h8_get_mask (sd); + SET_MEMORY_L (t, n); break; case X (OP_DISP, SB): /* Register indirect w/displacement, byte. */ @@ -1730,7 +1578,7 @@ store_1 (SIM_DESC sd, ea_type *arg, int n, int twice) case X (OP_MEM, SW): /* Why isn't this implemented? */ case X (OP_MEM, SL): /* Why isn't this implemented? */ default: - sim_engine_set_run_state (sd, sim_stopped, SIGSEGV); + sim_engine_halt (sd, cpu, NULL, NULL_CIA, sim_stopped, SIM_SIGSEGV); return -1; } return 0; @@ -1754,17 +1602,6 @@ store2 (SIM_DESC sd, ea_type *arg, int n) return store_1 (sd, arg, n, 1); } -static union -{ - short int i; - struct - { - char low; - char high; - } - u; -} littleendian; - /* Flag to be set whenever a new SIM_DESC object is created. */ static int init_pointers_needed = 1; @@ -1775,8 +1612,6 @@ init_pointers (SIM_DESC sd) { int i; - littleendian.i = 1; - if (h8300smode && !h8300_normal_mode) memory_size = H8300S_MSIZE; else if (h8300hmode && !h8300_normal_mode) @@ -1786,25 +1621,19 @@ init_pointers (SIM_DESC sd) /* `msize' must be a power of two. */ if ((memory_size & (memory_size - 1)) != 0) { - (*sim_callback->printf_filtered) - (sim_callback, + sim_io_printf + (sd, "init_pointers: bad memory size %d, defaulting to %d.\n", - memory_size, memory_size = H8300S_MSIZE); + memory_size, H8300S_MSIZE); + memory_size = H8300S_MSIZE; } if (h8_get_memory_buf (sd)) free (h8_get_memory_buf (sd)); - if (h8_get_cache_idx_buf (sd)) - free (h8_get_cache_idx_buf (sd)); - if (h8_get_eightbit_buf (sd)) - free (h8_get_eightbit_buf (sd)); h8_set_memory_buf (sd, (unsigned char *) calloc (sizeof (char), memory_size)); - h8_set_cache_idx_buf (sd, (unsigned short *) - calloc (sizeof (short), memory_size)); sd->memory_size = memory_size; - h8_set_eightbit_buf (sd, (unsigned char *) calloc (sizeof (char), 256)); h8_set_mask (sd, memory_size - 1); @@ -1847,40 +1676,15 @@ init_pointers (SIM_DESC sd) } if (wreg[i] == 0 || wreg[i + 8] == 0) - (*sim_callback->printf_filtered) (sim_callback, - "init_pointers: internal error.\n"); + sim_io_printf (sd, "init_pointers: internal error.\n"); h8_set_reg (sd, i, 0); - lreg[i] = h8_get_reg_buf (sd) + i; } - /* Note: sim uses pseudo-register ZERO as a zero register. */ - lreg[ZERO_REGNUM] = h8_get_reg_buf (sd) + ZERO_REGNUM; init_pointers_needed = 0; - - /* Initialize the seg registers. */ - if (!sd->sim_cache) - set_simcache_size (sd, CSIZE); } } -/* Grotty global variable for use by control_c signal handler. */ -static SIM_DESC control_c_sim_desc; - -static void -control_c (int sig) -{ - sim_engine_set_run_state (control_c_sim_desc, sim_stopped, SIGINT); -} - -int -sim_stop (SIM_DESC sd) -{ - /* FIXME: use a real signal value. */ - sim_engine_set_run_state (sd, sim_stopped, SIGINT); - return 1; -} - #define OBITOP(name, f, s, op) \ case O (name, SB): \ { \ @@ -1891,7 +1695,7 @@ case O (name, SB): \ goto end; \ if (fetch (sd, &code->src, &tmp)) \ goto end; \ - m = 1 << tmp; \ + m = 1 << (tmp & 7); \ op; \ if (s) \ if (store (sd, &code->dst,ea)) \ @@ -1899,15 +1703,12 @@ case O (name, SB): \ goto next; \ } -void -sim_resume (SIM_DESC sd, int step, int siggnal) +static void +step_once (SIM_DESC sd, SIM_CPU *cpu) { - static int init1; int cycles = 0; int insts = 0; int tick_start = get_now (); - void (*prev) (); - int poll_count = 0; int res; int tmp; int rd; @@ -1917,29 +1718,16 @@ sim_resume (SIM_DESC sd, int step, int siggnal) int c, nz, v, n, u, h, ui, intMaskBit; int trace, intMask; int oldmask; - enum sim_stop reason; - int sigrc; + host_callback *sim_callback = STATE_CALLBACK (sd); init_pointers (sd); - control_c_sim_desc = sd; - prev = signal (SIGINT, control_c); - - if (step) - { - sim_engine_set_run_state (sd, sim_stopped, SIGTRAP); - } - else - { - sim_engine_set_run_state (sd, sim_running, 0); - } - pc = h8_get_pc (sd); /* The PC should never be odd. */ if (pc & 0x1) { - sim_engine_set_run_state (sd, sim_stopped, SIGBUS); + sim_engine_halt (sd, cpu, NULL, NULL_CIA, sim_stopped, SIM_SIGBUS); return; } @@ -1957,16 +1745,10 @@ sim_resume (SIM_DESC sd, int step, int siggnal) h8_set_mask (sd, 0xffff); do { - unsigned short cidx; - decoded_inst *code; - - top: - cidx = h8_get_cache_idx (sd, pc); - if (cidx == (unsigned short) -1 || - cidx >= sd->sim_cache_size) - goto illegal; - - code = sd->sim_cache + cidx; + decoded_inst _code, *code = &_code; + memset (code, 0, sizeof (*code)); + decode (sd, pc, h8_get_memory_buf (sd) + pc, code); + code->oldpc = pc; #if ADEBUG if (debug) @@ -1985,15 +1767,6 @@ sim_resume (SIM_DESC sd, int step, int siggnal) switch (code->opcode) { - case 0: - /* - * This opcode is a fake for when we get to an - * instruction which hasnt been compiled - */ - compile (sd, pc); - goto top; - break; - case O (O_MOVAB, SL): case O (O_MOVAW, SL): case O (O_MOVAL, SL): @@ -2037,7 +1810,10 @@ sim_resume (SIM_DESC sd, int step, int siggnal) code->op3.literal = 0; if (OP_KIND (code->src.type) == OP_INDEXB) - code->dst.type = X (OP_REG, SB); + { + code->dst.type = X (OP_REG, SB); + code->dst.reg = code->op3.reg + 8; + } else code->dst.type = X (OP_REG, SW); } @@ -2354,25 +2130,12 @@ sim_resume (SIM_DESC sd, int step, int siggnal) ? h8_get_reg (sd, R4_REGNUM) & 0xffff : h8_get_reg (sd, R4_REGNUM) & 0xff); - _src = (h8_get_reg (sd, R5_REGNUM) < memory_size - ? h8_get_memory_buf (sd) + h8_get_reg (sd, R5_REGNUM) - : h8_get_eightbit_buf (sd) + - (h8_get_reg (sd, R5_REGNUM) & 0xff)); + _src = h8_get_memory_buf (sd) + h8_get_reg (sd, R5_REGNUM); if ((_src + count) >= (h8_get_memory_buf (sd) + memory_size)) - { - if ((_src + count) >= (h8_get_eightbit_buf (sd) + 0x100)) - goto illegal; - } - _dst = (h8_get_reg (sd, R6_REGNUM) < memory_size - ? h8_get_memory_buf (sd) + h8_get_reg (sd, R6_REGNUM) - : h8_get_eightbit_buf (sd) + - (h8_get_reg (sd, R6_REGNUM) & 0xff)); - + goto illegal; + _dst = h8_get_memory_buf (sd) + h8_get_reg (sd, R6_REGNUM); if ((_dst + count) >= (h8_get_memory_buf (sd) + memory_size)) - { - if ((_dst + count) >= (h8_get_eightbit_buf (sd) + 0x100)) - goto illegal; - } + goto illegal; memcpy (_dst, _src, count); h8_set_reg (sd, R5_REGNUM, h8_get_reg (sd, R5_REGNUM) + count); @@ -2807,7 +2570,7 @@ sim_resume (SIM_DESC sd, int step, int siggnal) ind_arg_len = 0; /* The size of the commandline argument. */ - ind_arg_len = strlen (h8_get_cmdline_arg (sd, i) + 1); + ind_arg_len = strlen (h8_get_cmdline_arg (sd, i)) + 1; /* The total size of the command line string. */ size_cmdline += ind_arg_len; @@ -3077,7 +2840,8 @@ sim_resume (SIM_DESC sd, int step, int siggnal) stat_ptr = (h8300hmode && !h8300_normal_mode) ? GET_L_REG (1) : GET_W_REG (1); /* Callback stat and return. */ - fstat_return = sim_callback->fstat (sim_callback, fd, &stat_rec); + fstat_return = sim_callback->to_fstat (sim_callback, fd, + &stat_rec); /* Have stat_ptr point to starting of stat_rec. */ temp_stat_ptr = (char *) (&stat_rec); @@ -3151,7 +2915,7 @@ sim_resume (SIM_DESC sd, int step, int siggnal) /* Callback stat and return. */ stat_return = - sim_callback->stat (sim_callback, filename, &stat_rec); + sim_callback->to_stat (sim_callback, filename, &stat_rec); /* Have stat_ptr point to starting of stat_rec. */ temp_stat_ptr = (char *) (&stat_rec); @@ -3625,7 +3389,7 @@ sim_resume (SIM_DESC sd, int step, int siggnal) goto end; case O (O_ILL, SB): /* illegal */ - sim_engine_set_run_state (sd, sim_stopped, SIGILL); + sim_engine_halt (sd, cpu, NULL, pc, sim_stopped, SIM_SIGILL); goto end; case O (O_SLEEP, SN): /* sleep */ @@ -3635,8 +3399,8 @@ sim_resume (SIM_DESC sd, int step, int siggnal) SIM_WIFEXITED (h8_get_reg (sd, 0))) { /* This trap comes from _exit, not from gdb. */ - sim_engine_set_run_state (sd, sim_exited, - SIM_WEXITSTATUS (h8_get_reg (sd, 0))); + sim_engine_halt (sd, cpu, NULL, pc, sim_exited, + SIM_WEXITSTATUS (h8_get_reg (sd, 0))); } #if 0 /* Unfortunately this won't really work, because @@ -3645,14 +3409,14 @@ sim_resume (SIM_DESC sd, int step, int siggnal) else if (SIM_WIFSTOPPED (h8_get_reg (sd, 0))) { /* Pass the stop signal up to gdb. */ - sim_engine_set_run_state (sd, sim_stopped, - SIM_WSTOPSIG (h8_get_reg (sd, 0))); + sim_engine_halt (sd, cpu, NULL, pc, sim_stopped, + SIM_WSTOPSIG (h8_get_reg (sd, 0))); } #endif else { /* Treat it as a sigtrap. */ - sim_engine_set_run_state (sd, sim_stopped, SIGTRAP); + sim_engine_halt (sd, cpu, NULL, pc, sim_stopped, SIM_SIGTRAP); } goto end; @@ -3693,7 +3457,7 @@ sim_resume (SIM_DESC sd, int step, int siggnal) goto end; case O (O_BPT, SN): - sim_engine_set_run_state (sd, sim_stopped, SIGTRAP); + sim_engine_halt (sd, cpu, NULL, pc, sim_stopped, SIM_SIGTRAP); goto end; case O (O_BSETEQ, SB): @@ -3886,13 +3650,7 @@ sim_resume (SIM_DESC sd, int step, int siggnal) fetch (sd, &code->dst, &rd)) goto end; - /* FIXME: is this the right place to be doing sign extend? */ - if (OP_KIND (code->src.type) == OP_IMM && - (ea & 8) != 0) - ea |= 0xfff0; - else - ea = SEXTSHORT (ea); - + ea = SEXTSHORT (ea); res = SEXTSHORT (ea * SEXTSHORT (rd)); n = res & 0x8000; @@ -3907,11 +3665,6 @@ sim_resume (SIM_DESC sd, int step, int siggnal) fetch (sd, &code->dst, &rd)) goto end; - /* FIXME: is this the right place to be doing sign extend? */ - if (OP_KIND (code->src.type) == OP_IMM && - (ea & 8) != 0) - ea |= 0xfffffff0; - res = ea * rd; n = res & 0x80000000; @@ -3925,11 +3678,6 @@ sim_resume (SIM_DESC sd, int step, int siggnal) fetch (sd, &code->dst, &rd)) goto end; - /* FIXME: is this the right place to be doing sign extend? */ - if (OP_KIND (code->src.type) == OP_IMM && - (ea & 8) != 0) - ea |= 0xfffffff0; - /* Compute upper 32 bits of the 64-bit result. */ res = (((long long) ea) * ((long long) rd)) >> 32; @@ -3985,13 +3733,7 @@ sim_resume (SIM_DESC sd, int step, int siggnal) fetch (sd, &code->dst, &rd)) goto end; - /* FIXME: is this the right place to be doing sign extend? */ - if (OP_KIND (code->src.type) == OP_IMM && - (ea & 8) != 0) - ea |= 0xfffffff0; - else - ea = SEXTCHAR (ea); - + ea = SEXTCHAR (ea); res = ea * SEXTCHAR (rd); n = res & 0x8000; @@ -4006,13 +3748,7 @@ sim_resume (SIM_DESC sd, int step, int siggnal) fetch (sd, &code->dst, &rd)) goto end; - /* FIXME: is this the right place to be doing sign extend? */ - if (OP_KIND (code->src.type) == OP_IMM && - (ea & 8) != 0) - ea |= 0xfff0; - else - ea = SEXTSHORT (ea); - + ea = SEXTSHORT (ea); res = ea * SEXTSHORT (rd & 0xffff); n = res & 0x80000000; @@ -4103,11 +3839,6 @@ sim_resume (SIM_DESC sd, int step, int siggnal) fetch (sd, &code->dst, &rd)) goto end; - /* FIXME: is this the right place to be doing sign extend? */ - if (OP_KIND (code->src.type) == OP_IMM && - (ea & 8) != 0) - ea |= 0xfffffff0; - if (ea) { res = SEXTSHORT (rd) / SEXTSHORT (ea); @@ -4129,11 +3860,6 @@ sim_resume (SIM_DESC sd, int step, int siggnal) fetch (sd, &code->dst, &rd)) goto end; - /* FIXME: is this the right place to be doing sign extend? */ - if (OP_KIND (code->src.type) == OP_IMM && - (ea & 8) != 0) - ea |= 0xfffffff0; - if (ea) { res = rd / ea; @@ -4205,13 +3931,7 @@ sim_resume (SIM_DESC sd, int step, int siggnal) goto end; rd = SEXTSHORT (rd); - - /* FIXME: is this the right place to be doing sign extend? */ - if (OP_KIND (code->src.type) == OP_IMM && - (ea & 8) != 0) - ea |= 0xfffffff0; - else - ea = SEXTCHAR (ea); + ea = SEXTCHAR (ea); if (ea) { @@ -4236,12 +3956,7 @@ sim_resume (SIM_DESC sd, int step, int siggnal) fetch (sd, &code->dst, &rd)) goto end; - /* FIXME: is this the right place to be doing sign extend? */ - if (OP_KIND (code->src.type) == OP_IMM && - (ea & 8) != 0) - ea |= 0xfffffff0; - else - ea = SEXTSHORT (ea); + ea = SEXTSHORT (ea); if (ea) { @@ -4415,14 +4130,13 @@ sim_resume (SIM_DESC sd, int step, int siggnal) default: illegal: - sim_engine_set_run_state (sd, sim_stopped, SIGILL); + sim_engine_halt (sd, cpu, NULL, pc, sim_stopped, SIM_SIGILL); goto end; } - (*sim_callback->printf_filtered) (sim_callback, - "sim_resume: internal error.\n"); - sim_engine_set_run_state (sd, sim_stopped, SIGILL); + sim_io_printf (sd, "sim_resume: internal error.\n"); + sim_engine_halt (sd, cpu, NULL, pc, sim_stopped, SIM_SIGILL); goto end; setc: @@ -4633,18 +4347,9 @@ sim_resume (SIM_DESC sd, int step, int siggnal) else pc = code->next_pc; - end: - - if (--poll_count < 0) - { - poll_count = POLL_QUIT_INTERVAL; - if ((*sim_callback->poll_quit) != NULL - && (*sim_callback->poll_quit) (sim_callback)) - sim_engine_set_run_state (sd, sim_stopped, SIGINT); - } - sim_engine_get_run_state (sd, &reason, &sigrc); - } while (reason == sim_running); + } while (0); + end: h8_set_ticks (sd, h8_get_ticks (sd) + get_now () - tick_start); h8_set_cycles (sd, h8_get_cycles (sd) + cycles); h8_set_insts (sd, h8_get_insts (sd) + insts); @@ -4655,20 +4360,30 @@ sim_resume (SIM_DESC sd, int step, int siggnal) h8_set_exr (sd, (trace<<7) | intMask); h8_set_mask (sd, oldmask); - signal (SIGINT, prev); } -int -sim_trace (SIM_DESC sd) +void +sim_engine_run (SIM_DESC sd, + int next_cpu_nr, /* ignore */ + int nr_cpus, /* ignore */ + int siggnal) { - /* FIXME: Unfinished. */ - (*sim_callback->printf_filtered) (sim_callback, - "sim_trace: trace not supported.\n"); - return 1; /* Done. */ + sim_cpu *cpu; + + SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER); + + cpu = STATE_CPU (sd, 0); + + while (1) + { + step_once (sd, cpu); + if (sim_events_tick (sd)) + sim_events_process (sd); + } } int -sim_write (SIM_DESC sd, SIM_ADDR addr, unsigned char *buffer, int size) +sim_write (SIM_DESC sd, SIM_ADDR addr, const unsigned char *buffer, int size) { int i; @@ -4680,14 +4395,11 @@ sim_write (SIM_DESC sd, SIM_ADDR addr, unsigned char *buffer, int size) if (addr < memory_size) { h8_set_memory (sd, addr + i, buffer[i]); - h8_set_cache_idx (sd, addr + i, 0); } else - { - h8_set_eightbit (sd, (addr + i) & 0xff, buffer[i]); - } + break; } - return size; + return i; } int @@ -4696,16 +4408,15 @@ sim_read (SIM_DESC sd, SIM_ADDR addr, unsigned char *buffer, int size) init_pointers (sd); if (addr < 0) return 0; - if (addr < memory_size) + if (addr + size < memory_size) memcpy (buffer, h8_get_memory_buf (sd) + addr, size); else - memcpy (buffer, h8_get_eightbit_buf (sd) + (addr & 0xff), size); + return 0; return size; } - -int -sim_store_register (SIM_DESC sd, int rn, unsigned char *value, int length) +static int +h8300_reg_store (SIM_CPU *cpu, int rn, unsigned char *value, int length) { int longval; int shortval; @@ -4714,19 +4425,17 @@ sim_store_register (SIM_DESC sd, int rn, unsigned char *value, int length) shortval = (value[0] << 8) | (value[1]); intval = h8300hmode ? longval : shortval; - init_pointers (sd); + init_pointers (CPU_STATE (cpu)); switch (rn) { case PC_REGNUM: if(h8300_normal_mode) - h8_set_pc (sd, shortval); /* PC for Normal mode is 2 bytes */ + cpu->pc = shortval; /* PC for Normal mode is 2 bytes */ else - h8_set_pc (sd, intval); + cpu->pc = intval; break; default: - (*sim_callback->printf_filtered) (sim_callback, - "sim_store_register: bad regnum %d.\n", - rn); + return -1; case R0_REGNUM: case R1_REGNUM: case R2_REGNUM: @@ -4735,80 +4444,46 @@ sim_store_register (SIM_DESC sd, int rn, unsigned char *value, int length) case R5_REGNUM: case R6_REGNUM: case R7_REGNUM: - h8_set_reg (sd, rn, intval); - break; case CCR_REGNUM: - h8_set_ccr (sd, intval); - break; case EXR_REGNUM: - h8_set_exr (sd, intval); - break; case SBR_REGNUM: - h8_set_sbr (sd, intval); - break; case VBR_REGNUM: - h8_set_vbr (sd, intval); - break; case MACH_REGNUM: - h8_set_mach (sd, intval); - break; case MACL_REGNUM: - h8_set_macl (sd, intval); + cpu->regs[rn] = intval; break; case CYCLE_REGNUM: - h8_set_cycles (sd, longval); - break; - case INST_REGNUM: - h8_set_insts (sd, longval); - break; - case TICK_REGNUM: - h8_set_ticks (sd, longval); + cpu->regs[rn] = longval; break; } - return -1; + return length; } -int -sim_fetch_register (SIM_DESC sd, int rn, unsigned char *buf, int length) +static int +h8300_reg_fetch (SIM_CPU *cpu, int rn, unsigned char *buf, int length) { int v; int longreg = 0; - init_pointers (sd); + init_pointers (CPU_STATE (cpu)); if (!h8300smode && rn >= EXR_REGNUM) rn++; switch (rn) { default: - (*sim_callback->printf_filtered) (sim_callback, - "sim_fetch_register: bad regnum %d.\n", - rn); - v = 0; + return -1; + case PC_REGNUM: + v = cpu->pc; break; case CCR_REGNUM: - v = h8_get_ccr (sd); - break; case EXR_REGNUM: - v = h8_get_exr (sd); - break; - case PC_REGNUM: - v = h8_get_pc (sd); - break; case SBR_REGNUM: - v = h8_get_sbr (sd); - break; case VBR_REGNUM: - v = h8_get_vbr (sd); - break; case MACH_REGNUM: - v = h8_get_mach (sd); - break; case MACL_REGNUM: - v = h8_get_macl (sd); - break; case R0_REGNUM: case R1_REGNUM: case R2_REGNUM: @@ -4817,20 +4492,17 @@ sim_fetch_register (SIM_DESC sd, int rn, unsigned char *buf, int length) case R5_REGNUM: case R6_REGNUM: case R7_REGNUM: - v = h8_get_reg (sd, rn); + v = cpu->regs[rn]; break; case CYCLE_REGNUM: - v = h8_get_cycles (sd); - longreg = 1; - break; case TICK_REGNUM: - v = h8_get_ticks (sd); - longreg = 1; - break; case INST_REGNUM: - v = h8_get_insts (sd); + v = cpu->regs[rn]; longreg = 1; break; + case ZERO_REGNUM: + v = 0; + break; } /* In Normal mode PC is 2 byte, but other registers are 4 byte */ if ((h8300hmode || longreg) && !(rn == PC_REGNUM && h8300_normal_mode)) @@ -4839,70 +4511,28 @@ sim_fetch_register (SIM_DESC sd, int rn, unsigned char *buf, int length) buf[1] = v >> 16; buf[2] = v >> 8; buf[3] = v >> 0; + return 4; } else { buf[0] = v >> 8; buf[1] = v; + return 2; } - return -1; } -void -sim_stop_reason (SIM_DESC sd, enum sim_stop *reason, int *sigrc) -{ - sim_engine_get_run_state (sd, reason, sigrc); -} - -/* FIXME: Rename to sim_set_mem_size. */ - -void -sim_size (int n) -{ - /* Memory size is fixed. */ -} - -static void -set_simcache_size (SIM_DESC sd, int n) -{ - if (sd->sim_cache) - free (sd->sim_cache); - if (n < 2) - n = 2; - sd->sim_cache = (decoded_inst *) malloc (sizeof (decoded_inst) * n); - memset (sd->sim_cache, 0, sizeof (decoded_inst) * n); - sd->sim_cache_size = n; -} - - void sim_info (SIM_DESC sd, int verbose) { double timetaken = (double) h8_get_ticks (sd) / (double) now_persec (); double virttime = h8_get_cycles (sd) / 10.0e6; - (*sim_callback->printf_filtered) (sim_callback, - "\n\n#instructions executed %10d\n", - h8_get_insts (sd)); - (*sim_callback->printf_filtered) (sim_callback, - "#cycles (v approximate) %10d\n", - h8_get_cycles (sd)); - (*sim_callback->printf_filtered) (sim_callback, - "#real time taken %10.4f\n", - timetaken); - (*sim_callback->printf_filtered) (sim_callback, - "#virtual time taken %10.4f\n", - virttime); + sim_io_printf (sd, "\n\n#instructions executed %10d\n", h8_get_insts (sd)); + sim_io_printf (sd, "#cycles (v approximate) %10d\n", h8_get_cycles (sd)); + sim_io_printf (sd, "#real time taken %10.4f\n", timetaken); + sim_io_printf (sd, "#virtual time taken %10.4f\n", virttime); if (timetaken != 0.0) - (*sim_callback->printf_filtered) (sim_callback, - "#simulation ratio %10.4f\n", - virttime / timetaken); - (*sim_callback->printf_filtered) (sim_callback, - "#compiles %10d\n", - h8_get_compiles (sd)); - (*sim_callback->printf_filtered) (sim_callback, - "#cache size %10d\n", - sd->sim_cache_size); + sim_io_printf (sd, "#simulation ratio %10.4f\n", virttime / timetaken); #ifdef ADEBUG /* This to be conditional on `what' (aka `verbose'), @@ -4913,8 +4543,7 @@ sim_info (SIM_DESC sd, int verbose) for (i = 0; i < O_LAST; i++) { if (h8_get_stats (sd, i)) - (*sim_callback->printf_filtered) (sim_callback, "%d: %d\n", - i, h8_get_stats (sd, i)); + sim_io_printf (sd, "%d: %d\n", i, h8_get_stats (sd, i)); } } #endif @@ -4945,6 +4574,66 @@ set_h8300h (unsigned long machine) h8300_normal_mode = 1; } +/* H8300-specific options. + TODO: These really should be merged into the common model modules. */ +typedef enum { + OPTION_H8300H, + OPTION_H8300S, + OPTION_H8300SX +} H8300_OPTIONS; + +static SIM_RC +h8300_option_handler (SIM_DESC sd, sim_cpu *cpu ATTRIBUTE_UNUSED, int opt, + char *arg, int is_command ATTRIBUTE_UNUSED) +{ + switch ((H8300_OPTIONS) opt) + { + case OPTION_H8300H: + set_h8300h (bfd_mach_h8300h); + break; + case OPTION_H8300S: + set_h8300h (bfd_mach_h8300s); + break; + case OPTION_H8300SX: + set_h8300h (bfd_mach_h8300sx); + break; + + default: + /* We'll actually never get here; the caller handles the error + case. */ + sim_io_eprintf (sd, "Unknown option `%s'\n", arg); + return SIM_RC_FAIL; + } + + return SIM_RC_OK; +} + +static const OPTION h8300_options[] = +{ + { {"h8300h", no_argument, NULL, OPTION_H8300H}, + 'h', NULL, "Indicate the CPU is H8/300H", + h8300_option_handler }, + { {"h8300s", no_argument, NULL, OPTION_H8300S}, + 'S', NULL, "Indicate the CPU is H8S", + h8300_option_handler }, + { {"h8300sx", no_argument, NULL, OPTION_H8300SX}, + 'x', NULL, "Indicate the CPU is H8SX", + h8300_option_handler }, + { {NULL, no_argument, NULL, 0}, '\0', NULL, NULL, NULL, NULL } +}; + +static sim_cia +h8300_pc_get (sim_cpu *cpu) +{ + return cpu->pc; +} + +static void +h8300_pc_set (sim_cpu *cpu, sim_cia pc) +{ + cpu->pc = pc; +} + /* Cover function of sim_state_free to free the cpu buffers as well. */ static void @@ -4961,32 +4650,40 @@ SIM_DESC sim_open (SIM_OPEN_KIND kind, struct host_callback_struct *callback, struct bfd *abfd, - char **argv) + char * const *argv) { + int i; SIM_DESC sd; sim_cpu *cpu; sd = sim_state_alloc (kind, callback); - sd->cpu = sim_cpu_alloc (sd, 0); + + /* The cpu data is kept in a separately allocated chunk of memory. */ + if (sim_cpu_alloc_all (sd, 1) != SIM_RC_OK) + { + free_state (sd); + return 0; + } + cpu = STATE_CPU (sd, 0); SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER); - sim_state_initialize (sd, cpu); + cpu->regs[SBR_REGNUM] = 0xFFFFFF00; /* sim_cpu object is new, so some initialization is needed. */ init_pointers_needed = 1; - /* For compatibility (FIXME: is this right?). */ - current_alignment = NONSTRICT_ALIGNMENT; - current_target_byte_order = BIG_ENDIAN; - if (sim_pre_argv_init (sd, argv[0]) != SIM_RC_OK) { free_state (sd); return 0; } - /* getopt will print the error message so we just have to exit if - this fails. FIXME: Hmmm... in the case of gdb we need getopt - to call print_filtered. */ + if (sim_add_option_table (sd, NULL, h8300_options) != SIM_RC_OK) + { + free_state (sd); + return 0; + } + + /* The parser will print an error message for us, so we silently return. */ if (sim_parse_args (sd, argv) != SIM_RC_OK) { /* Uninstall the modules to avoid memory leaks, @@ -5020,26 +4717,28 @@ sim_open (SIM_OPEN_KIND kind, return 0; } + /* CPU specific initialization. */ + for (i = 0; i < MAX_NR_PROCESSORS; ++i) + { + SIM_CPU *cpu = STATE_CPU (sd, i); + + CPU_REG_FETCH (cpu) = h8300_reg_fetch; + CPU_REG_STORE (cpu) = h8300_reg_store; + CPU_PC_FETCH (cpu) = h8300_pc_get; + CPU_PC_STORE (cpu) = h8300_pc_set; + } + /* sim_hw_configure (sd); */ /* FIXME: Much of the code in sim_load can be moved here. */ - sim_kind = kind; - myname = argv[0]; - sim_callback = callback; return sd; } -void -sim_close (SIM_DESC sd, int quitting) -{ - /* Nothing to do. */ -} - /* Called by gdb to load a program into memory. */ SIM_RC -sim_load (SIM_DESC sd, char *prog, bfd *abfd, int from_tty) +sim_load (SIM_DESC sd, const char *prog, bfd *abfd, int from_tty) { bfd *prog_bfd; @@ -5087,28 +4786,21 @@ sim_load (SIM_DESC sd, char *prog, bfd *abfd, int from_tty) if (h8_get_memory_buf (sd)) free (h8_get_memory_buf (sd)); - if (h8_get_cache_idx_buf (sd)) - free (h8_get_cache_idx_buf (sd)); - if (h8_get_eightbit_buf (sd)) - free (h8_get_eightbit_buf (sd)); h8_set_memory_buf (sd, (unsigned char *) calloc (sizeof (char), memory_size)); - h8_set_cache_idx_buf (sd, (unsigned short *) - calloc (sizeof (short), memory_size)); - h8_set_eightbit_buf (sd, (unsigned char *) calloc (sizeof (char), 256)); + sd->memory_size = memory_size; /* `msize' must be a power of two. */ if ((memory_size & (memory_size - 1)) != 0) { - (*sim_callback->printf_filtered) (sim_callback, - "sim_load: bad memory size.\n"); + sim_io_printf (sd, "sim_load: bad memory size.\n"); return SIM_RC_FAIL; } h8_set_mask (sd, memory_size - 1); - if (sim_load_file (sd, myname, sim_callback, prog, prog_bfd, - sim_kind == SIM_OPEN_DEBUG, + if (sim_load_file (sd, STATE_MY_NAME (sd), STATE_CALLBACK (sd), prog, + prog_bfd, STATE_OPEN_KIND (sd) == SIM_OPEN_DEBUG, 0, sim_write) == NULL) { @@ -5125,7 +4817,8 @@ sim_load (SIM_DESC sd, char *prog, bfd *abfd, int from_tty) } SIM_RC -sim_create_inferior (SIM_DESC sd, struct bfd *abfd, char **argv, char **env) +sim_create_inferior (SIM_DESC sd, struct bfd *abfd, + char * const *argv, char * const *env) { int i = 0; int len_arg = 0; @@ -5157,16 +4850,3 @@ sim_create_inferior (SIM_DESC sd, struct bfd *abfd, char **argv, char **env) return SIM_RC_OK; } - -void -sim_do_command (SIM_DESC sd, char *cmd) -{ - (*sim_callback->printf_filtered) (sim_callback, - "This simulator does not accept any commands.\n"); -} - -void -sim_set_callbacks (struct host_callback_struct *ptr) -{ - sim_callback = ptr; -}