+#include "config.h"
+
#include <signal.h>
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
#include "v850_sim.h"
#include "simops.h"
#include "sys/syscall.h"
case OP_COND_BR:
values[0] = State.pc;
values[1] = SEXT9 (OP[0]);
- values[2] = State.sregs[5];
+ values[2] = PSW;
num_values = 3;
break;
break;
case OP_EX1:
- values[0] = State.sregs[5];
+ values[0] = PSW;
num_values = 1;
break;
trace_input ("bv", OP_COND_BR, 0);
op0 = SEXT9 (OP[0]);
- psw = State.sregs[5];
+ psw = PSW;
if ((psw & PSW_OV) != 0)
State.pc += op0;
trace_input ("bl", OP_COND_BR, 0);
op0 = SEXT9 (OP[0]);
- psw = State.sregs[5];
+ psw = PSW;
if ((psw & PSW_CY) != 0)
State.pc += op0;
trace_input ("be", OP_COND_BR, 0);
op0 = SEXT9 (OP[0]);
- psw = State.sregs[5];
+ psw = PSW;
if ((psw & PSW_Z) != 0)
State.pc += op0;
trace_input ("bnh", OP_COND_BR, 0);
op0 = SEXT9 (OP[0]);
- psw = State.sregs[5];
+ psw = PSW;
if ((((psw & PSW_CY) != 0) | ((psw & PSW_Z) != 0)) != 0)
State.pc += op0;
trace_input ("bn", OP_COND_BR, 0);
op0 = SEXT9 (OP[0]);
- psw = State.sregs[5];
+ psw = PSW;
if ((psw & PSW_S) != 0)
State.pc += op0;
trace_input ("blt", OP_COND_BR, 0);
op0 = SEXT9 (OP[0]);
- psw = State.sregs[5];
+ psw = PSW;
if ((((psw & PSW_S) != 0) ^ ((psw & PSW_OV) != 0)) != 0)
State.pc += op0;
trace_input ("ble", OP_COND_BR, 0);
op0 = SEXT9 (OP[0]);
- psw = State.sregs[5];
+ psw = PSW;
if ((((psw & PSW_Z) != 0)
|| (((psw & PSW_S) != 0) ^ ((psw & PSW_OV) != 0))) != 0)
trace_input ("bnv", OP_COND_BR, 0);
op0 = SEXT9 (OP[0]);
- psw = State.sregs[5];
+ psw = PSW;
if ((psw & PSW_OV) == 0)
State.pc += op0;
trace_input ("bnl", OP_COND_BR, 0);
op0 = SEXT9 (OP[0]);
- psw = State.sregs[5];
+ psw = PSW;
if ((psw & PSW_CY) == 0)
State.pc += op0;
trace_input ("bne", OP_COND_BR, 0);
op0 = SEXT9 (OP[0]);
- psw = State.sregs[5];
+ psw = PSW;
if ((psw & PSW_Z) == 0)
State.pc += op0;
trace_input ("bh", OP_COND_BR, 0);
op0 = SEXT9 (OP[0]);
- psw = State.sregs[5];
+ psw = PSW;
if ((((psw & PSW_CY) != 0) | ((psw & PSW_Z) != 0)) == 0)
State.pc += op0;
trace_input ("bp", OP_COND_BR, 0);
op0 = SEXT9 (OP[0]);
- psw = State.sregs[5];
+ psw = PSW;
if ((psw & PSW_S) == 0)
State.pc += op0;
trace_input ("bsa", OP_COND_BR, 0);
op0 = SEXT9 (OP[0]);
- psw = State.sregs[5];
+ psw = PSW;
if ((psw & PSW_SAT) != 0)
State.pc += op0;
trace_input ("bge", OP_COND_BR, 0);
op0 = SEXT9 (OP[0]);
- psw = State.sregs[5];
+ psw = PSW;
if ((((psw & PSW_S) != 0) ^ ((psw & PSW_OV) != 0)) == 0)
State.pc += op0;
trace_input ("bgt", OP_COND_BR, 0);
op0 = SEXT9 (OP[0]);
- psw = State.sregs[5];
+ psw = PSW;
if ((((psw & PSW_Z) != 0)
|| (((psw & PSW_S) != 0) ^ ((psw & PSW_OV) != 0))) == 0)
/* Store the result and condition codes. */
State.regs[OP[1]] = result;
- State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
- State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
+ PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
+ PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
| (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0));
trace_output (OP_REG_REG);
}
/* Store the result and condition codes. */
State.regs[OP[1]] = result;
- State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
- State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
+ PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
+ PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
| (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0));
trace_output (OP_IMM_REG);
}
/* Store the result and condition codes. */
State.regs[OP[2]] = result;
- State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
- State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
+ PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
+ PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
| (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0));
trace_output (OP_IMM_REG_REG);
}
/* Store the result and condition codes. */
State.regs[OP[1]] = result;
- State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
- State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
+ PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
+ PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
| (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0));
trace_output (OP_REG_REG);
}
/* Store the result and condition codes. */
State.regs[OP[1]] = result;
- State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
- State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
+ PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
+ PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
| (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0));
trace_output (OP_REG_REG);
}
/* Store the result and condition codes. */
State.regs[OP[1]] = result;
- State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_OV);
- State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
+ PSW &= ~(PSW_Z | PSW_S | PSW_OV);
+ PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
| (ov ? PSW_OV : 0));
trace_output (OP_REG_REG);
}
&& (op1 & 0x80000000) != (result & 0x80000000));
/* Set condition codes. */
- State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
- State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
+ PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
+ PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
| (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0));
trace_output (OP_REG_REG_CMP);
}
&& (op1 & 0x80000000) != (result & 0x80000000));
/* Set condition codes. */
- State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
- State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
+ PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
+ PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
| (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0));
trace_output (OP_IMM_REG_CMP);
}
trace_input ("setf", OP_EX1, 0);
op0 = OP[0] & 0xf;
- psw = State.sregs[5];
+ psw = PSW;
switch (op0)
{
/* Store the result and condition codes. */
State.regs[OP[1]] = result;
- State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
- State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
+ PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
+ PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
| (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0)
| (sat ? PSW_SAT : 0));
/* Store the result and condition codes. */
State.regs[OP[1]] = result;
- State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
- State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
+ PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
+ PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
| (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0)
| (sat ? PSW_SAT : 0));
/* Store the result and condition codes. */
State.regs[OP[1]] = result;
- State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
- State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
+ PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
+ PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
| (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0)
| (sat ? PSW_SAT : 0));
/* Store the result and condition codes. */
State.regs[OP[1]] = result;
- State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
- State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
+ PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
+ PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
| (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0)
| (sat ? PSW_SAT : 0));
/* Store the result and condition codes. */
State.regs[OP[1]] = result;
- State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
- State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
+ PSW &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
+ PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
| (cy ? PSW_CY : 0) | (ov ? PSW_OV : 0)
| (sat ? PSW_SAT : 0));
s = (result & 0x80000000);
/* Store the condition codes. */
- State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_OV);
- State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0));
+ PSW &= ~(PSW_Z | PSW_S | PSW_OV);
+ PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0));
trace_output (OP_REG_REG_CMP);
}
/* Store the result and condition codes. */
State.regs[OP[1]] = result;
- State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_OV | PSW_CY);
- State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
+ PSW &= ~(PSW_Z | PSW_S | PSW_OV | PSW_CY);
+ PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
| (cy ? PSW_CY : 0));
trace_output (OP_IMM_REG);
}
/* Store the result and condition codes. */
State.regs[OP[1]] = result;
- State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_OV | PSW_CY);
- State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
+ PSW &= ~(PSW_Z | PSW_S | PSW_OV | PSW_CY);
+ PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
| (cy ? PSW_CY : 0));
trace_output (OP_REG_REG);
}
/* Store the result and condition codes. */
State.regs[OP[1]] = result;
- State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_OV | PSW_CY);
- State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
+ PSW &= ~(PSW_Z | PSW_S | PSW_OV | PSW_CY);
+ PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
| (cy ? PSW_CY : 0));
trace_output (OP_IMM_REG);
}
/* Store the result and condition codes. */
State.regs[OP[1]] = result;
- State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_OV | PSW_CY);
- State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
+ PSW &= ~(PSW_Z | PSW_S | PSW_OV | PSW_CY);
+ PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
| (cy ? PSW_CY : 0));
trace_output (OP_REG_REG);
}
/* Store the result and condition codes. */
State.regs[OP[1]] = result;
- State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_OV | PSW_CY);
- State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
+ PSW &= ~(PSW_Z | PSW_S | PSW_OV | PSW_CY);
+ PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
| (cy ? PSW_CY : 0));
trace_output (OP_IMM_REG);
}
/* Store the result and condition codes. */
State.regs[OP[1]] = result;
- State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_OV | PSW_CY);
- State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
+ PSW &= ~(PSW_Z | PSW_S | PSW_OV | PSW_CY);
+ PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0)
| (cy ? PSW_CY : 0));
trace_output (OP_REG_REG);
}
/* Store the result and condition codes. */
State.regs[OP[1]] = result;
- State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_OV);
- State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0));
+ PSW &= ~(PSW_Z | PSW_S | PSW_OV);
+ PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0));
trace_output (OP_REG_REG);
}
/* Store the result and condition codes. */
State.regs[OP[2]] = result;
- State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_OV);
- State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0));
+ PSW &= ~(PSW_Z | PSW_S | PSW_OV);
+ PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0));
trace_output (OP_UIMM_REG_REG);
}
/* Store the result and condition codes. */
State.regs[OP[1]] = result;
- State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_OV);
- State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0));
+ PSW &= ~(PSW_Z | PSW_S | PSW_OV);
+ PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0));
trace_output (OP_REG_REG);
}
/* Store the result and condition codes. */
State.regs[OP[2]] = result;
- State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_OV);
- State.sregs[5] |= (z ? PSW_Z : 0);
+ PSW &= ~(PSW_Z | PSW_S | PSW_OV);
+ PSW |= (z ? PSW_Z : 0);
trace_output (OP_UIMM_REG_REG);
}
/* Store the result and condition codes. */
State.regs[OP[1]] = result;
- State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_OV);
- State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0));
+ PSW &= ~(PSW_Z | PSW_S | PSW_OV);
+ PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0));
trace_output (OP_REG_REG);
}
/* Store the result and condition codes. */
State.regs[OP[2]] = result;
- State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_OV);
- State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0));
+ PSW &= ~(PSW_Z | PSW_S | PSW_OV);
+ PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0));
trace_output (OP_UIMM_REG_REG);
}
/* Store the result and condition codes. */
State.regs[OP[1]] = result;
- State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_OV);
- State.sregs[5] |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0));
+ PSW &= ~(PSW_Z | PSW_S | PSW_OV);
+ PSW |= ((z ? PSW_Z : 0) | (s ? PSW_S : 0));
trace_output (OP_REG_REG_MOVE);
}
temp = SEXT16 (OP[2]);
op2 = temp;
temp = load_mem (op0 + op2, 1);
- State.sregs[5] &= ~PSW_Z;
+ PSW &= ~PSW_Z;
if ((temp & (1 << op1)) == 0)
- State.sregs[5] |= PSW_Z;
+ PSW |= PSW_Z;
temp |= (1 << op1);
store_mem (op0 + op2, 1, temp);
trace_output (OP_BIT);
temp = SEXT16 (OP[2]);
op2 = temp;
temp = load_mem (op0 + op2, 1);
- State.sregs[5] &= ~PSW_Z;
+ PSW &= ~PSW_Z;
if ((temp & (1 << op1)) == 0)
- State.sregs[5] |= PSW_Z;
+ PSW |= PSW_Z;
temp ^= (1 << op1);
store_mem (op0 + op2, 1, temp);
trace_output (OP_BIT);
temp = SEXT16 (OP[2]);
op2 = temp;
temp = load_mem (op0 + op2, 1);
- State.sregs[5] &= ~PSW_Z;
+ PSW &= ~PSW_Z;
if ((temp & (1 << op1)) == 0)
- State.sregs[5] |= PSW_Z;
+ PSW |= PSW_Z;
temp &= ~(1 << op1);
store_mem (op0 + op2, 1, temp);
trace_output (OP_BIT);
temp = SEXT16 (OP[2]);
op2 = temp;
temp = load_mem (op0 + op2, 1);
- State.sregs[5] &= ~PSW_Z;
+ PSW &= ~PSW_Z;
if ((temp & (1 << op1)) == 0)
- State.sregs[5] |= PSW_Z;
+ PSW |= PSW_Z;
trace_output (OP_BIT);
}
OP_16007E0 ()
{
trace_input ("di", OP_NONE, 0);
- State.sregs[5] |= PSW_ID;
+ PSW |= PSW_ID;
trace_output (OP_NONE);
}
OP_16087E0 ()
{
trace_input ("ei", OP_NONE, 0);
- State.sregs[5] &= ~PSW_ID;
+ PSW &= ~PSW_ID;
trace_output (OP_NONE);
}
-/* halt, not supported */
+/* halt */
void
OP_12007E0 ()
{
trace_input ("halt", OP_NONE, 0);
+ /* FIXME this should put processor into a mode where NMI still handled */
State.exception = SIGQUIT;
trace_output (OP_NONE);
}
-/* reti, not supported */
+/* reti */
void
OP_14007E0 ()
{
trace_input ("reti", OP_NONE, 0);
trace_output (OP_NONE);
- if ((State.sregs[5] & (PSW_NP | PSW_EP)) == PSW_NP)
- { /* Only NP is on */
- PC = State.sregs[2] - 4; /* FEPC */
- State.sregs[5] = State.sregs[3]; /* FEPSW */
+ /* Restore for NMI if only NP on, otherwise is interrupt or exception. */
+ if ((PSW & (PSW_NP | PSW_EP)) == PSW_NP)
+ {
+ PC = FEPC - 4;
+ PSW = FEPSW;
}
else
{
- PC = State.sregs[0] - 4; /* EIPC */
- State.sregs[5] = State.sregs[1]; /* EIPSW */
+ PC = EIPC - 4;
+ PSW = EIPSW;
}
}
-/* trap, not supportd */
+/* trap */
void
OP_10007E0 ()
{
case SYS_exit:
/* EXIT - caller can look in PARM1 to work out the
reason */
- if (PARM1 == 0xdead || PARM1 == 0x1)
- State.exception = SIGABRT;
- else
- State.exception = SIGQUIT;
+ State.exception = SIG_V850_EXIT;
break;
case SYS_stat: /* added at hmsi */
RETVAL = chmod (MEMPTR (PARM1), PARM2);
break;
case SYS_time:
- RETVAL = time (MEMPTR (PARM1));
+ {
+ time_t now;
+ RETVAL = time (&now);
+ store_mem (PARM1, 4, now);
+ }
break;
case SYS_times:
{
}
else
{ /* Trap 0 -> 30 */
- State.sregs[0] = PC + 4; /* EIPC */
- State.sregs[1] = State.sregs[5]; /* EIPSW */
- State.sregs[4] &= 0xffff0000; /* Mask out EICC */
- State.sregs[4] |= 0x40 + OP[0]; /* EICC */
- State.sregs[5] |= PSW_EP | PSW_ID; /* Now doing exception processing */
+ EIPC = PC + 4;
+ EIPSW = PSW;
+ /* Mask out EICC */
+ ECR &= 0xffff0000;
+ ECR |= 0x40 + OP[0];
+ /* Flag that we are now doing exception processing. */
+ PSW |= PSW_EP | PSW_ID;
PC = ((OP[0] < 0x10) ? 0x40 : 0x50) - 4;
}
}
trace_output (OP_LDSR);
}
-/* stsr, not supported */
+/* stsr */
void
OP_4007E0 ()
{