#include "simops.h"
#include "sys/syscall.h"
#include "bfd.h"
+#include <errno.h>
enum op_types {
OP_UNKNOWN,
case OP_IMM_REG:
case OP_IMM_REG_CMP:
case OP_IMM_REG_MOVE:
- sprintf (buf, "%d,r%d", OP[1], OP[0]);
+ sprintf (buf, "%d,r%d", OP[0], OP[1]);
break;
case OP_COND_BR:
break;
case OP_LOAD32:
- sprintf (buf, "%d[r%d],r%d", SEXT16 (OP[2]), OP[0], OP[1]);
+ sprintf (buf, "%d[r%d],r%d", SEXT16 (OP[2]) & ~0x1, OP[0], OP[1]);
break;
case OP_STORE32:
- sprintf (buf, "r%d,%d[r%d]", OP[1], SEXT16 (OP[2]), OP[0]);
+ sprintf (buf, "r%d,%d[r%d]", OP[1], SEXT16 (OP[2] & ~0x1), OP[0]);
break;
case OP_JUMP:
temp = OP[1];
temp = SEXT7 (temp);
op2 = temp;
- result = get_byte (State.mem + State.regs[30] + op2);
+ result = load_mem (State.regs[30] + op2, 1);
State.regs[OP[0]] = SEXT8 (result);
trace_output (OP_LOAD16);
}
temp = OP[1];
temp = SEXT7 (temp);
op2 = temp << 1;
- result = get_half (State.mem + State.regs[30] + op2);
+ result = load_mem (State.regs[30] + op2, 2);
State.regs[OP[0]] = SEXT16 (result);
trace_output (OP_LOAD16);
}
temp = OP[1];
temp = SEXT7 (temp);
op2 = temp << 2;
- result = get_word (State.mem + State.regs[30] + op2);
+ result = load_mem (State.regs[30] + op2, 4);
State.regs[OP[0]] = result;
trace_output (OP_LOAD16);
}
temp = OP[1];
temp = SEXT7 (temp);
op1 = temp;
- put_byte (State.mem + State.regs[30] + op1, op0);
+ store_mem (State.regs[30] + op1, 1, op0);
trace_output (OP_STORE16);
}
temp = OP[1];
temp = SEXT7 (temp);
op1 = temp << 1;
- put_half (State.mem + State.regs[30] + op1, op0);
+ store_mem (State.regs[30] + op1, 2, op0);
trace_output (OP_STORE16);
}
temp = OP[1];
temp = SEXT7 (temp);
op1 = temp << 2;
- put_word (State.mem + State.regs[30] + op1, op0);
+ store_mem (State.regs[30] + op1, 4, op0);
trace_output (OP_STORE16);
}
op0 = State.regs[OP[0]];
temp = SEXT16 (OP[2]);
op2 = temp;
- result = get_byte (State.mem + op0 + op2);
+ result = load_mem (op0 + op2, 1);
State.regs[OP[1]] = SEXT8 (result);
trace_output (OP_LOAD32);
}
temp = SEXT16 (OP[2]);
temp &= ~0x1;
op2 = temp;
- result = get_half (State.mem + op0 + op2);
+ result = load_mem (op0 + op2, 2);
State.regs[OP[1]] = SEXT16 (result);
trace_output (OP_LOAD32);
}
temp = SEXT16 (OP[2]);
temp &= ~0x1;
op2 = temp;
- result = get_word (State.mem + op0 + op2);
+ result = load_mem (op0 + op2, 4);
State.regs[OP[1]] = result;
trace_output (OP_LOAD32);
}
op1 = State.regs[OP[1]];
temp = SEXT16 (OP[2]);
op2 = temp;
- put_byte (State.mem + op0 + op2, op1);
+ store_mem (op0 + op2, 1, op1);
trace_output (OP_STORE32);
}
op1 = State.regs[OP[1]];
temp = SEXT16 (OP[2] & ~0x1);
op2 = temp;
- put_half (State.mem + op0 + op2, op1);
+ store_mem (op0 + op2, 2, op1);
trace_output (OP_STORE32);
}
op1 = State.regs[OP[1]];
temp = SEXT16 (OP[2] & ~0x1);
op2 = temp;
- put_word (State.mem + op0 + op2, op1);
+ store_mem (op0 + op2, 4, op1);
trace_output (OP_STORE32);
}
op1 = OP[1] & 0x7;
temp = SEXT16 (OP[2]);
op2 = temp;
- temp = get_byte (State.mem + op0 + op2);
+ temp = load_mem (op0 + op2, 1);
State.sregs[5] &= ~PSW_Z;
if ((temp & (1 << op1)) == 0)
State.sregs[5] |= PSW_Z;
temp |= (1 << op1);
- put_byte (State.mem + op0 + op2, temp);
+ store_mem (op0 + op2, 1, temp);
trace_output (OP_BIT);
}
op1 = OP[1] & 0x7;
temp = SEXT16 (OP[2]);
op2 = temp;
- temp = get_byte (State.mem + op0 + op2);
+ temp = load_mem (op0 + op2, 1);
State.sregs[5] &= ~PSW_Z;
if ((temp & (1 << op1)) == 0)
State.sregs[5] |= PSW_Z;
temp ^= (1 << op1);
- put_byte (State.mem + op0 + op2, temp);
+ store_mem (op0 + op2, 1, temp);
trace_output (OP_BIT);
}
op1 = OP[1] & 0x7;
temp = SEXT16 (OP[2]);
op2 = temp;
- temp = get_byte (State.mem + op0 + op2);
+ temp = load_mem (op0 + op2, 1);
State.sregs[5] &= ~PSW_Z;
if ((temp & (1 << op1)) == 0)
State.sregs[5] |= PSW_Z;
temp &= ~(1 << op1);
- put_byte (State.mem + op0 + op2, temp);
+ store_mem (op0 + op2, 1, temp);
trace_output (OP_BIT);
}
op1 = OP[1] & 0x7;
temp = SEXT16 (OP[2]);
op2 = temp;
- temp = get_byte (State.mem + op0 + op2);
+ temp = load_mem (op0 + op2, 1);
State.sregs[5] &= ~PSW_Z;
if ((temp & (1 << op1)) == 0)
State.sregs[5] |= PSW_Z;
{
trace_input ("reti", OP_NONE, 0);
trace_output (OP_NONE);
- abort ();
+
+ 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 */
+ }
+ else
+ {
+ PC = State.sregs[0] - 4; /* EIPC */
+ State.sregs[5] = State.sregs[1]; /* EIPSW */
+ }
}
/* trap, not supportd */
trace_input ("trap", OP_TRAP, 0);
trace_output (OP_TRAP);
- /* Trap 0 is used for simulating low-level I/O */
+ /* Trap 31 is used for simulating OS I/O functions */
- if (OP[0] == 0)
+ if (OP[0] == 31)
{
int save_errno = errno;
errno = 0;
/* Turn a pointer in a register into a pointer into real memory. */
-#define MEMPTR(x) ((char *)((x) + State.mem))
-
+#define MEMPTR(x) (map (x))
switch (FUNC)
{
SLW (buf+28, host_stat.st_mtime);
SLW (buf+36, host_stat.st_ctime);
}
-#endif
break;
case SYS_chown:
RETVAL = chown (MEMPTR (PARM1), PARM2, PARM3);
break;
+#endif
case SYS_chmod:
RETVAL = chmod (MEMPTR (PARM1), PARM2);
break;
RETERR = errno;
errno = save_errno;
}
- else if (OP[0] == 1 )
- {
- char *fstr = State.regs[2] + State.mem;
- puts (fstr);
+ 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 */
+ PC = ((OP[0] < 0x10) ? 0x40 : 0x50) - 4;
}
}
#include "ansidecl.h"
#include "callback.h"
#include "opcode/v850.h"
+#include <limits.h>
+#include "remote-sim.h"
extern host_callback *v850_callback;
-/* FIXME: host defines */
+#define DEBUG_TRACE 0x00000001
+#define DEBUG_VALUES 0x00000002
+
+extern int v850_debug;
+
+#if UCHAR_MAX == 255
typedef unsigned char uint8;
-typedef unsigned short uint16;
-typedef unsigned int uint32;
typedef signed char int8;
+#else
+#error "Char is not an 8-bit type"
+#endif
+
+#if SHRT_MAX == 32767
+typedef unsigned short uint16;
typedef signed short int16;
+#else
+#error "Short is not a 16-bit type"
+#endif
+
+#if INT_MAX == 2147483647
+
+typedef unsigned int uint32;
typedef signed int int32;
-typedef signed long long int64;
+
+#else
+# if LONG_MAX == 2147483647
+
+typedef unsigned long uint32;
+typedef signed long int32;
+
+# else
+# error "Neither int nor long is a 32-bit type"
+# endif
+#endif
/* FIXME: V850 defines */
typedef uint32 reg_t;
long mask;
void (*func)();
int numops;
- int operands[9];
+ int operands[6];
};
struct _state
#define PSW_S 0x2
#define PSW_Z 0x1
-#define SEXT3(x) ((((x)&0x7)^(~3))+4)
+#define SEXT3(x) ((((x)&0x7)^(~0x3))+0x4)
/* sign-extend a 4-bit number */
-#define SEXT4(x) ((((x)&0xf)^(~7))+8)
+#define SEXT4(x) ((((x)&0xf)^(~0x7))+0x8)
+
+/* sign-extend a 5-bit number */
+#define SEXT5(x) ((((x)&0x1f)^(~0xf))+0x10)
+
+/* sign-extend a 7-bit number */
+#define SEXT7(x) ((((x)&0x7f)^(~0x4f))+0x40)
/* sign-extend an 8-bit number */
#define SEXT8(x) ((((x)&0xff)^(~0x7f))+0x80)
+/* sign-extend a 9-bit number */
+#define SEXT9(x) ((((x)&0x1ff)^(~0xff))+0x100)
+
/* sign-extend a 16-bit number */
#define SEXT16(x) ((((x)&0xffff)^(~0x7fff))+0x8000)
+/* sign-extend a 22-bit number */
+#define SEXT22(x) ((((x)&0x3fffff)^(~0x1fffff))+0x200000)
+
/* sign-extend a 32-bit number */
#define SEXT32(x) ((((x)&0xffffffffLL)^(~0x7fffffffLL))+0x80000000LL)
#define INC_ADDR(x,i) x = ((State.MD && x == MOD_E) ? MOD_S : (x)+(i))
-#define RB(x) (*((uint8 *)((x)+State.mem)))
-#define SB(addr,data) ( RB(addr) = (data & 0xff))
-
-#ifdef WORDS_BIGENDIAN
+/*#define RB(x) (*((uint8 *)((x)+State.mem)))*/
+/*#define SB(addr,data) ( RB(addr) = (data & 0xff))*/
uint32 get_word PARAMS ((uint8 *));
uint16 get_half PARAMS ((uint8 *));
uint8 get_byte PARAMS ((uint8 *));
-#define RLW(x) (*((uint32 *)((x)+State.mem)))
+void put_word PARAMS ((uint8 *, uint32));
+void put_half PARAMS ((uint8 *, uint16));
+void put_byte PARAMS ((uint8 *, uint8));
-#else
+uint32 load_mem PARAMS ((SIM_ADDR addr, int len));
+void store_mem PARAMS ((SIM_ADDR addr, int len, uint32 data));
-uint32 get_word PARAMS ((uint8 *));
-uint16 get_half PARAMS ((uint8 *));
-uint8 get_byte PARAMS ((uint8 *));
+uint8 *map PARAMS ((SIM_ADDR addr));
-#define RLW(x) get_word((long)(x)+State.mem)
+#define RLW(x) load_mem (x, 4)
-#endif /* not WORDS_BIGENDIAN */
+#ifdef _WIN32
+#define SIGTRAP 5
+#define SIGQUIT 3
+#endif