#define X(op, size) op*4+size
-#define SP (HMODE ? SL:SW)
+#define SP (h8300hmode ? SL:SW)
#define SB 0
#define SW 1
#define SL 2
static cpu_state_type cpu;
-int HMODE = 0;
+int h8300hmode = 0;
static int
get_now ()
{
struct tms b;
+
+return time(0);
+#if 0
times (&b);
return b.tms_utime + b.tms_stime;
+#endif
}
static int
now_persec ()
{
- return 50;
+ return 1;
}
case L_32:
return SL;
case L_P:
- return HMODE ? SL : SW;
+ return h8300hmode ? SL : SW;
}
}
#define V (v != 0)
#define N (n != 0)
+static int
+mop(code, bsize, sign)
+ decoded_inst *code;
+ int bsize;
+ int sign;
+{
+ int multiplier;
+ int multiplicand;
+ int result;
+int n,nz;
+ if (sign)
+ {
+ multiplicand =
+ bsize ? SEXTCHAR(GET_W_REG(code->dst.reg)):
+ SEXTSHORT(GET_W_REG(code->dst.reg));
+ multiplier =
+ bsize ? SEXTCHAR(GET_B_REG(code->src.reg)):
+ SEXTSHORT(GET_W_REG(code->src.reg));
+ }
+ else
+ {
+ multiplicand = bsize ? UEXTCHAR(GET_W_REG(code->dst.reg)):
+ UEXTSHORT(GET_W_REG(code->dst.reg));
+ multiplier =
+ bsize ? UEXTCHAR(GET_B_REG(code->src.reg)):
+ UEXTSHORT(GET_W_REG(code->src.reg));
+
+ }
+ result = multiplier * multiplicand;
+
+ if (sign)
+ {
+ n = result & (bsize ? 0x8000: 0x80000000);
+ nz = result & (bsize ? 0xffff: 0xffffffff);
+ }
+ if (bsize)
+ {
+ SET_W_REG(code->dst.reg, result);
+ }
+ else
+ {
+ SET_L_REG(code->dst.reg, result);
+ }
+/* return ((n==1) << 1) | (nz==1);*/
+
+}
+
int
sim_resume (step)
{
call:
tmp = cpu.regs[7];
- if (HMODE)
+ if (h8300hmode)
{
tmp -= 4;
SET_MEMORY_L (tmp, code->next_pc);
tmp = cpu.regs[7];
- if (HMODE)
+ if (h8300hmode)
{
pc = GET_MEMORY_L (tmp);
tmp += 4;
OBITOP(O_BSET,1,1, ea |= m); /*FIXME: m can come from reg*/
-#define MOP(bsize, signed) \
- { \
- int multiplier; \
- int multiplicand; \
- int result; \
- \
- if (signed) \
- { \
- multiplicand = \
- bsize ? SEXTCHAR(GET_W_REG(code->dst.reg)): \
- SEXTSHORT(GET_W_REG(code->dst.reg)); \
- multiplier = \
- bsize ? SEXTCHAR(GET_B_REG(code->src.reg)): \
- SEXTSHORT(GET_B_REG(code->src.reg)); \
- } \
- else \
- { \
- multiplicand = bsize ? UEXTCHAR(GET_W_REG(code->dst.reg)): \
- UEXTSHORT(GET_W_REG(code->dst.reg)); \
- multiplier = \
- bsize ? UEXTCHAR(GET_B_REG(code->src.reg)): \
- UEXTSHORT(GET_B_REG(code->src.reg)); \
- \
- } \
- result = multiplier * multiplicand; \
- \
- if (signed) \
- { \
- n = result & (bsize ? 0x8000: 0x80000000); \
- nz = result & (bsize ? 0xffff: 0xffffffff); \
- } \
- if (bsize) \
- { \
- SET_W_REG(code->dst.reg, result); \
- } \
- else \
- { \
- SET_L_REG(code->dst.reg, result); \
- } \
- goto next; \
- } \
+#define MOP(bsize, signed) mop(code, bsize,signed); goto next;
case O(O_MULS, SB): MOP(1,1);break;
case O(O_MULS, SW): MOP(0,1); break;
res = rd + ea;
goto log32;
+ case O (O_NOP, SB):
+ goto next;
+
default:
cpu.exception = 123;
goto end;
-void
+int
sim_write (addr, buffer, size)
long int addr;
unsigned char *buffer;
cpu.memory[addr + i] = buffer[i];
cpu.cache_idx[addr + i] = 0;
}
+return size;
}
-void
+int
sim_read (addr, buffer, size)
long int addr;
char *buffer;
if (addr < 0 || addr + size > MSIZE)
return;
memcpy (buffer, cpu.memory + addr, size);
+ return size;
}
void
sim_store_register (rn, value)
int rn;
- int value;
+ unsigned char *value;
{
+ int longval;
+ int shortval;
+ int intval;
+ longval = (value[0] << 24 ) | (value[1] << 16) | (value[2] << 8) | value[3];
+ shortval= (value[0] << 8 ) | (value[1]);
+ intval = h8300hmode ? longval : shortval;
init_pointers ();
switch (rn)
{
case PC_REGNUM:
- cpu.pc = value;
+ cpu.pc = intval;
break;
default:
abort ();
case R5_REGNUM:
case R6_REGNUM:
case R7_REGNUM:
- cpu.regs[rn] = value;
+ cpu.regs[rn] = intval;
break;
case CCR_REGNUM:
- cpu.ccr = value;
+ cpu.ccr = intval;
break;
case CYCLE_REGNUM:
- cpu.cycles = value;
+ cpu.cycles = longval;
break;
case INST_REGNUM:
- cpu.insts = value;
+ cpu.insts = longval;
break;
case TICK_REGNUM:
- cpu.ticks = value;
+ cpu.ticks = longval;
break;
}
}
break;
}
- if (HMODE || longreg)
+ if (h8300hmode || longreg)
{
buf[0] = v >> 24;
buf[1] = v >> 16;
sim_set_pc (n)
{
- sim_store_register (PC_REGNUM, n);
+ cpu.pc = n;
}
void
set_h8300h ()
{
- HMODE = 1;
+ h8300hmode = 1;
}
+