unsigned int op0, psw;
int temp;
- temp = (State.regs[OP[0]] << 23) >> 23;
- op0 = temp;
+ op0 = ((signed)OP[0] << 23) >> 23;
psw = State.sregs[5];
if ((psw & PSW_OV) != 0)
unsigned int op0, psw;
int temp;
- temp = (State.regs[OP[0]] << 23) >> 23;
- op0 = temp;
+ op0 = ((signed)OP[0] << 23) >> 23;
psw = State.sregs[5];
if ((psw & PSW_CY) != 0)
unsigned int op0, psw;
int temp;
- temp = (State.regs[OP[0]] << 23) >> 23;
- op0 = temp;
+ op0 = ((signed)OP[0] << 23) >> 23;
psw = State.sregs[5];
if ((psw & PSW_Z) != 0)
unsigned int op0, psw;
int temp;
- temp = (State.regs[OP[0]] << 23) >> 23;
- op0 = temp;
+ op0 = ((signed)OP[0] << 23) >> 23;
psw = State.sregs[5];
if ((((psw & PSW_CY) != 0) | ((psw & PSW_Z) != 0)) != 0)
unsigned int op0, psw;
int temp;
- temp = (State.regs[OP[0]] << 23) >> 23;
- op0 = temp;
+ op0 = ((signed)OP[0] << 23) >> 23;
psw = State.sregs[5];
if ((psw & PSW_S) != 0)
unsigned int op0;
int temp;
- temp = (State.regs[OP[0]] << 23) >> 23;
- op0 = temp;
+ op0 = ((signed)OP[0] << 23) >> 23;
State.pc += op0;
}
unsigned int op0, psw;
int temp;
- temp = (State.regs[OP[0]] << 23) >> 23;
- op0 = temp;
+ op0 = ((signed)OP[0] << 23) >> 23;
psw = State.sregs[5];
if ((((psw & PSW_S) != 0) ^ ((psw & PSW_OV) != 0)) != 0)
unsigned int op0, psw;
int temp;
- temp = (State.regs[OP[0]] << 23) >> 23;
- op0 = temp;
+ op0 = ((signed)OP[0] << 23) >> 23;
psw = State.sregs[5];
if ((((psw & PSW_Z) != 0)
unsigned int op0, psw;
int temp;
- temp = (State.regs[OP[0]] << 23) >> 23;
- op0 = temp;
+ op0 = ((signed)OP[0] << 23) >> 23;
psw = State.sregs[5];
if ((psw & PSW_OV) == 0)
unsigned int op0, psw;
int temp;
- temp = (State.regs[OP[0]] << 23) >> 23;
- op0 = temp;
+ op0 = ((signed)OP[0] << 23) >> 23;
psw = State.sregs[5];
if ((psw & PSW_CY) == 0)
unsigned int op0, psw;
int temp;
- temp = (State.regs[OP[0]] << 23) >> 23;
- op0 = temp;
+ op0 = ((signed)OP[0] << 23) >> 23;
psw = State.sregs[5];
if ((psw & PSW_Z) == 0)
unsigned int op0, psw;
int temp;
- temp = (State.regs[OP[0]] << 23) >> 23;
- op0 = temp;
+ op0 = ((signed)OP[0] << 23) >> 23;
psw = State.sregs[5];
if ((((psw & PSW_CY) != 0) | ((psw & PSW_Z) != 0)) == 0)
unsigned int op0, psw;
int temp;
- temp = (State.regs[OP[0]] << 23) >> 23;
- op0 = temp;
+ op0 = ((signed)OP[0] << 23) >> 23;
psw = State.sregs[5];
if ((psw & PSW_S) == 0)
unsigned int op0, psw;
int temp;
- temp = (State.regs[OP[0]] << 23) >> 23;
- op0 = temp;
+ op0 = ((signed)OP[0] << 23) >> 23;
psw = State.sregs[5];
if ((psw & PSW_SAT) != 0)
unsigned int op0, psw;
int temp;
- temp = (State.regs[OP[0]] << 23) >> 23;
- op0 = temp;
+ op0 = ((signed)OP[0] << 23) >> 23;
psw = State.sregs[5];
if ((((psw & PSW_S) != 0) ^ ((psw & PSW_OV) != 0)) == 0)
unsigned int op0, psw;
int temp;
- temp = (State.regs[OP[0]] << 23) >> 23;
- op0 = temp;
+ op0 = ((signed)OP[0] << 23) >> 23;
psw = State.sregs[5];
if ((((psw & PSW_Z) != 0)
ov = ((op0 & 0x80000000) == (op1 & 0x80000000)
&& (op0 & 0x80000000) != (result & 0x80000000));
+ /* According to the manual, 's' is inverted if 'ov'
+ is set. */
+ s = ov ? !s : s;
+
/* Store the result and condition codes. */
State.regs[OP[1]] = result;
State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
ov = ((op0 & 0x80000000) == (op1 & 0x80000000)
&& (op0 & 0x80000000) != (result & 0x80000000));
+ /* According to the manual, 's' is inverted if 'ov'
+ is set. */
+ s = ov ? !s : s;
+
/* Store the result and condition codes. */
State.regs[OP[1]] = result;
State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
ov = ((op0 & 0x80000000) == (op1 & 0x80000000)
&& (op0 & 0x80000000) != (result & 0x80000000));
+ /* According to the manual, 's' is inverted if 'ov'
+ is set. */
+ s = ov ? !s : s;
+
/* Store the result and condition codes. */
State.regs[OP[2]] = result;
State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
/* Compute the condition codes. */
z = (result == 0);
s = (result & 0x80000000);
- cy = (result < -op0);
+ cy = (op1 < op0);
ov = ((op1 & 0x80000000) != (op0 & 0x80000000)
&& (op1 & 0x80000000) != (result & 0x80000000));
+ /* According to the manual, 's' is inverted if 'ov'
+ is set. */
+ s = ov ? !s : s;
+
/* Store the result and condition codes. */
State.regs[OP[1]] = result;
State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
/* Compute the condition codes. */
z = (result == 0);
s = (result & 0x80000000);
- cy = (result < -op1);
+ cy = (op0 < op1);
ov = ((op0 & 0x80000000) != (op1 & 0x80000000)
&& (op0 & 0x80000000) != (result & 0x80000000));
+ /* According to the manual, 's' is inverted if 'ov'
+ is set. */
+ s = ov ? !s : s;
+
/* Store the result and condition codes. */
State.regs[OP[1]] = result;
State.sregs[5] &= ~(PSW_Z | PSW_S | PSW_CY | PSW_OV);
/* Compute the condition codes. */
z = (result == 0);
s = (result & 0x80000000);
- cy = (result < -op0);
+ cy = (op1 < op0);
ov = ((op1 & 0x80000000) != (op0 & 0x80000000)
&& (op1 & 0x80000000) != (result & 0x80000000));
/* Compute the condition codes. */
z = (result == 0);
s = (result & 0x80000000);
- cy = (result < -op0);
+ cy = (op1 < op0);
ov = ((op1 & 0x80000000) != (op0 & 0x80000000)
&& (op1 & 0x80000000) != (result & 0x80000000));
/* Compute the condition codes. */
z = (result == 0);
s = (result & 0x80000000);
- cy = (result < -op0);
+ cy = (op1 < op0);
ov = ((op1 & 0x80000000) != (op0 & 0x80000000)
&& (op1 & 0x80000000) != (result & 0x80000000));
sat = ov;
/* Compute the condition codes. */
z = (result == 0);
s = (result & 0x80000000);
- cy = (result < -op0);
+ cy = (op1 < op0);
ov = ((op1 & 0x80000000) != (op0 & 0x80000000)
&& (op1 & 0x80000000) != (result & 0x80000000));
sat = ov;
/* Compute the condition codes. */
z = (result == 0);
s = (result & 0x80000000);
- cy = (result < -op0);
+ cy = (result < op0);
ov = ((op1 & 0x80000000) != (op0 & 0x80000000)
&& (op1 & 0x80000000) != (result & 0x80000000));
sat = ov;
void
OP_12007E0 ()
{
- abort ();
+ State.exception = SIGQUIT;
}
/* reti, not supported */
void
OP_10007E0 ()
{
- abort ();
+ extern int errno;
+
+ /* Trap 0 is used for simulating low-level I/O */
+
+ if (OP[0] == 0)
+ {
+#if 0
+ char *fstr = State.regs[2] + State.imem;
+ printf (fstr,State.regs[3],State.regs[4],State.regs[5]);
+#else
+ int save_errno = errno;
+ errno = 0;
+
+/* Registers passed to trap 0 */
+
+#define FUNC State.regs[6] /* function number, return value */
+#define PARM1 State.regs[7] /* optional parm 1 */
+#define PARM2 State.regs[8] /* optional parm 2 */
+#define PARM3 State.regs[9] /* optional parm 3 */
+
+/* Registers set by trap 0 */
+
+#define RETVAL State.regs[10] /* return value */
+#define RETERR State.regs[11] /* return error code */
+
+/* Turn a pointer in a register into a pointer into real memory. */
+
+#define MEMPTR(x) ((char *)((x) + State.mem))
+
+
+ switch (FUNC)
+ {
+#if 0
+#if !defined(__GO32__) && !defined(_WIN32)
+ case SYS_fork:
+ RETVAL = fork ();
+ break;
+ case SYS_execve:
+ RETVAL = execve (MEMPTR (PARM1), (char **) MEMPTR (PARM2),
+ (char **)MEMPTR (PARM3));
+ break;
+ case SYS_execv:
+ RETVAL = execve (MEMPTR (PARM1), (char **) MEMPTR (PARM2), NULL);
+ break;
+ case SYS_pipe:
+ {
+ reg_t buf;
+ int host_fd[2];
+
+ buf = PARM1;
+ RETVAL = pipe (host_fd);
+ SW (buf, host_fd[0]);
+ buf += sizeof(uint16);
+ SW (buf, host_fd[1]);
+ }
+ break;
+
+ case SYS_wait:
+ {
+ int status;
+
+ RETVAL = wait (&status);
+ SW (PARM1, status);
+ }
+ break;
+#endif
+
+ case SYS_read:
+ RETVAL = v850_callback->read (v850_callback, PARM1, MEMPTR (PARM2),
+ PARM3);
+ break;
+#endif
+ case SYS_write:
+ if (PARM1 == 1)
+ RETVAL = (int)v850_callback->write_stdout (v850_callback,
+ MEMPTR (PARM2), PARM3);
+ else
+ RETVAL = (int)v850_callback->write (v850_callback, PARM1,
+ MEMPTR (PARM2), PARM3);
+ break;
+#if 0
+ case SYS_lseek:
+ RETVAL = v850_callback->lseek (v850_callback, PARM1, PARM2, PARM3);
+ break;
+ case SYS_close:
+ RETVAL = v850_callback->close (v850_callback, PARM1);
+ break;
+ case SYS_open:
+ RETVAL = v850_callback->open (v850_callback, MEMPTR (PARM1), PARM2);
+ break;
+#endif
+ 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;
+ break;
+
+#if 0
+ case SYS_stat: /* added at hmsi */
+ /* stat system call */
+ {
+ struct stat host_stat;
+ reg_t buf;
+
+ RETVAL = stat (MEMPTR (PARM1), &host_stat);
+
+ buf = PARM2;
+
+ /* The hard-coded offsets and sizes were determined by using
+ * the D10V compiler on a test program that used struct stat.
+ */
+ SW (buf, host_stat.st_dev);
+ SW (buf+2, host_stat.st_ino);
+ SW (buf+4, host_stat.st_mode);
+ SW (buf+6, host_stat.st_nlink);
+ SW (buf+8, host_stat.st_uid);
+ SW (buf+10, host_stat.st_gid);
+ SW (buf+12, host_stat.st_rdev);
+ SLW (buf+16, host_stat.st_size);
+ SLW (buf+20, host_stat.st_atime);
+ SLW (buf+28, host_stat.st_mtime);
+ SLW (buf+36, host_stat.st_ctime);
+ }
+ break;
+
+ case SYS_chown:
+ RETVAL = chown (MEMPTR (PARM1), PARM2, PARM3);
+ break;
+ case SYS_chmod:
+ RETVAL = chmod (MEMPTR (PARM1), PARM2);
+ break;
+ case SYS_utime:
+ /* Cast the second argument to void *, to avoid type mismatch
+ if a prototype is present. */
+ RETVAL = utime (MEMPTR (PARM1), (void *) MEMPTR (PARM2));
+ break;
+#endif
+ default:
+ abort ();
+ }
+ RETERR = errno;
+ errno = save_errno;
+#endif
+ }
+ else if (OP[0] == 1 )
+ {
+ char *fstr = State.regs[2] + State.mem;
+ puts (fstr);
+ }
}
/* ldsr, reg,reg */
#include <stdio.h>
#include <ctype.h>
#include "ansidecl.h"
+#include "callback.h"
#include "opcode/v850.h"
+extern host_callback *v850_callback;
+
/* FIXME: host defines */
typedef unsigned char uint8;
typedef unsigned short uint16;
reg_t regs[32]; /* general-purpose registers */
reg_t sregs[32]; /* system regsiters, including psw */
reg_t pc;
- uint8 *imem;
- uint8 *dmem;
+ uint8 *mem;
int exception;
} State;
-extern uint16 OP[4];
+extern uint32 OP[4];
extern struct simops Simops[];
#define PC (State.pc)
#define INC_ADDR(x,i) x = ((State.MD && x == MOD_E) ? MOD_S : (x)+(i))
-#define RB(x) (*((uint8 *)((x)+State.imem)))
+#define RB(x) (*((uint8 *)((x)+State.mem)))
#define SB(addr,data) ( RB(addr) = (data & 0xff))
#ifdef WORDS_BIGENDIAN
-#define RW(x) (*((uint16 *)((x)+State.imem)))
-#define RLW(x) (*((uint32 *)((x)+State.imem)))
-#define SW(addr,data) RW(addr)=data
-#define READ_16(x) (*((int16 *)(x)))
-#define WRITE_16(addr,data) (*(int16 *)(addr)=data)
-#define READ_64(x) (*((int64 *)(x)))
-#define WRITE_64(addr,data) (*(int64 *)(addr)=data)
+uint32 get_word PARAMS ((uint8 *));
+uint16 get_half PARAMS ((uint8 *));
+uint8 get_byte PARAMS ((uint8 *));
+#define RLW(x) (*((uint32 *)((x)+State.mem)))
#else
-uint32 get_longword PARAMS ((uint8 *));
-uint16 get_word PARAMS ((uint8 *));
-int64 get_longlong PARAMS ((uint8 *));
-void write_word PARAMS ((uint8 *addr, uint16 data));
-void write_longlong PARAMS ((uint8 *addr, int64 data));
-
-#define SW(addr,data) write_word((long)(addr)+State.imem,data)
-#define RW(x) get_word((long)(x)+State.imem)
-#define RLW(x) get_longword((long)(x)+State.imem)
-#define READ_16(x) get_word(x)
-#define WRITE_16(addr,data) write_word(addr,data)
-#define READ_64(x) get_longlong(x)
-#define WRITE_64(addr,data) write_longlong(addr,data)
+uint32 get_word PARAMS ((uint8 *));
+uint16 get_half PARAMS ((uint8 *));
+uint8 get_byte PARAMS ((uint8 *));
+
+#define RLW(x) get_word((long)(x)+State.mem)
#endif /* not WORDS_BIGENDIAN */