summaryrefslogtreecommitdiff
path: root/PcsxSrc/ix86
diff options
context:
space:
mode:
Diffstat (limited to 'PcsxSrc/ix86')
-rw-r--r--PcsxSrc/ix86/iR3000A.c1236
-rw-r--r--PcsxSrc/ix86/ix86.c966
-rw-r--r--PcsxSrc/ix86/ix86.h397
3 files changed, 2599 insertions, 0 deletions
diff --git a/PcsxSrc/ix86/iR3000A.c b/PcsxSrc/ix86/iR3000A.c
new file mode 100644
index 0000000..c6ff128
--- /dev/null
+++ b/PcsxSrc/ix86/iR3000A.c
@@ -0,0 +1,1236 @@
+/* Pcsx - Pc Psx Emulator
+ * Copyright (C) 1999-2002 Pcsx Team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifdef __WIN32__
+#pragma warning(disable:4244)
+#pragma warning(disable:4761)
+#endif
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+
+#include "PsxCommon.h"
+#include "ix86.h"
+
+static u32 *recLUT;
+
+#define PC_REC(x) (recLUT[x >> 16] + (x & 0xffff))
+#define PC_REC8(x) (*(u8 *)PC_REC(x))
+#define PC_REC16(x) (*(u16*)PC_REC(x))
+#define PC_REC32(x) (*(u32*)PC_REC(x))
+
+#define RECMEM_SIZE (8*1024*1024)
+
+static char *recMem; /* the recompiled blocks will be here */
+static char *recRAM; /* and the ptr to the blocks here */
+static char *recROM; /* and here */
+
+static u32 pc; /* recompiler pc */
+static int count; /* recompiler intruction count */
+static int branch; /* set for branch */
+static u32 target; /* branch target */
+
+static void (*recBSC[64])();
+static void (*recSPC[64])();
+static void (*recREG[32])();
+static void (*recCP0[32])();
+static void (*recCP2[64])();
+static void (*recCP2BSC[32])();
+
+/* set a pending branch */
+#define SetBranch() { \
+ branch = 1; \
+ psxRegs.code = PSXMu32(pc); \
+ pc+=4; count++; \
+ recBSC[psxRegs.code>>26](); \
+ \
+ MOV32MtoR(EAX, (u32)&target); \
+ MOV32RtoM((u32)&psxRegs.pc, EAX); \
+ CALLFunc((u32)psxBranchTest); \
+}
+
+#define REC_FUNC(f) \
+void psx##f(); \
+static void rec##f() { \
+ MOV32ItoM((u32)&psxRegs.code, (u32)psxRegs.code); \
+ MOV32ItoM((u32)&psxRegs.pc, (u32)pc); \
+ CALLFunc((u32)psx##f); \
+/* branch = 2; */\
+}
+
+#define REC_SYS(f) \
+void psx##f(); \
+static void rec##f() { \
+ MOV32ItoM((u32)&psxRegs.code, (u32)psxRegs.code); \
+ MOV32ItoM((u32)&psxRegs.pc, (u32)pc); \
+ CALLFunc((u32)psx##f); \
+ branch = 2; \
+}
+
+#define REC_BRANCH(f) \
+void psx##f(); \
+static void rec##f() { \
+ MOV32ItoM((u32)&psxRegs.code, (u32)psxRegs.code); \
+ MOV32ItoM((u32)&psxRegs.pc, (u32)pc); \
+ CALLFunc((u32)psx##f); \
+ branch = 2; \
+ count++; \
+}
+
+static void recRecompile();
+
+static int recInit() {
+ int i;
+
+ recLUT = (u32*) malloc(0x010000 * 4);
+
+ recMem = (char*) malloc(RECMEM_SIZE);
+ recRAM = (char*) malloc(0x200000);
+ recROM = (char*) malloc(0x080000);
+ if (recRAM == NULL || recROM == NULL || recMem == NULL || recLUT == NULL) {
+ SysMessage("Error allocating memory"); return -1;
+ }
+
+ for (i=0; i<0x80; i++) recLUT[i + 0x0000] = (u32)&recRAM[(i & 0x1f) << 16];
+ memcpy(recLUT + 0x8000, recLUT, 0x80 * 4);
+ memcpy(recLUT + 0xa000, recLUT, 0x80 * 4);
+
+ for (i=0; i<0x08; i++) recLUT[i + 0xbfc0] = (u32)&recROM[i << 16];
+
+ return 0;
+}
+
+static void recReset() {
+ memset(recRAM, 0, 0x200000);
+ memset(recROM, 0, 0x080000);
+
+ x86Init(recMem);
+ branch = 0;
+}
+
+static void recShutdown() {
+ if (recMem == NULL) return;
+ free(recLUT);
+ free(recMem);
+ free(recRAM);
+ free(recROM);
+}
+
+static void recError() {
+ SysReset();
+ ClosePlugins();
+ SysMessage("Unrecoverable error while running recompiler\n");
+ SysRunGui();
+}
+
+#define execute() { \
+ void (**recFunc)(); \
+ char *p; \
+ \
+ p = (char*)PC_REC(psxRegs.pc); \
+ if (p != NULL) recFunc = (void (**)()) (u32)p; \
+ else { recError(); return; } \
+ \
+ if (*recFunc == 0) { \
+ recRecompile(); \
+ } \
+ (*recFunc)(); \
+}
+
+static void DumpRegs() {
+ int i, j;
+
+ printf("%lx %lx\n", psxRegs.pc, psxRegs.cycle);
+ for (i=0; i<4; i++) {
+ for (j=0; j<8; j++)
+ printf("%lx ", psxRegs.GPR.r[j*i]);
+ printf("\n");
+ }
+}
+
+static void recExecuteBios() {
+ while (psxRegs.pc != 0x80030000) {
+ execute();
+ }
+}
+
+static void recExecute() {
+ for (;;) execute();
+}
+
+static void recExecuteBlock() {
+ execute();
+}
+
+static void recClear(u32 Addr, u32 Size) {
+ memset((void*)PC_REC(Addr), 0, Size * 4);
+}
+
+static void recNULL() {
+// SysMessage("recUNK: %8.8x\n", psxRegs.code);
+}
+
+/*********************************************************
+* goes to opcodes tables... *
+* Format: table[something....] *
+*********************************************************/
+
+//REC_SYS(SPECIAL);
+static void recSPECIAL() {
+ recSPC[_Funct_]();
+}
+
+static void recREGIMM() {
+ recREG[_Rt_]();
+}
+
+static void recCOP0() {
+ recCP0[_Rs_]();
+}
+
+//REC_SYS(COP2);
+static void recCOP2() {
+ recCP2[_Funct_]();
+}
+
+static void recBASIC() {
+ recCP2BSC[_Rs_]();
+}
+
+//end of Tables opcodes...
+
+/*********************************************************
+* Arithmetic with immediate operand *
+* Format: OP rt, rs, immediate *
+*********************************************************/
+/*
+REC_FUNC(ADDI);
+REC_FUNC(ADDIU);
+REC_FUNC(ANDI);
+REC_FUNC(ORI);
+REC_FUNC(XORI);
+REC_FUNC(SLTI);
+REC_FUNC(SLTIU);
+#if 0*/
+static void recADDIU() {
+// Rt = Rs + Im
+ if (!_Rt_) return;
+
+ if (_Rs_) {
+ if (_Rs_ == _Rt_) {
+ ADD32ItoM((u32)&psxRegs.GPR.r[_Rt_], _Imm_);
+ } else {
+ MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]);
+ if (_Imm_) ADD32ItoR(EAX, _Imm_);
+ MOV32RtoM((u32)&psxRegs.GPR.r[_Rt_], EAX);
+ }
+ } else {
+ MOV32ItoM((u32)&psxRegs.GPR.r[_Rt_], _Imm_);
+ }
+}
+
+static void recADDI() {
+// Rt = Rs + Im
+ recADDIU();
+}
+
+static void recSLTI() {
+// Rt = Rs < Im (signed)
+ if (!_Rt_) return;
+
+ MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]);
+ CMP32ItoR(EAX, _Imm_);
+ SETL8R (EAX);
+ AND32ItoR(EAX, 0xff);
+ MOV32RtoM((u32)&psxRegs.GPR.r[_Rt_], EAX);
+}
+
+static void recSLTIU() {
+// Rt = Rs < Im (unsigned)
+ if (!_Rt_) return;
+
+ MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]);
+ CMP32ItoR(EAX, _Imm_);
+ SETB8R (EAX);
+ AND32ItoR(EAX, 0xff);
+ MOV32RtoM((u32)&psxRegs.GPR.r[_Rt_], EAX);
+}
+
+static void recANDI() {
+// Rt = Rs And Im
+ if (!_Rt_) return;
+
+ if (_Rs_ && _ImmU_) {
+ if (_Rs_ == _Rt_) {
+ AND32ItoM((u32)&psxRegs.GPR.r[_Rt_], _ImmU_);
+ } else {
+ MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]);
+ AND32ItoR(EAX, _ImmU_);
+ MOV32RtoM((u32)&psxRegs.GPR.r[_Rt_], EAX);
+ }
+ } else {
+ XOR32RtoR(EAX, EAX);
+ MOV32RtoM((u32)&psxRegs.GPR.r[_Rt_], EAX);
+ }
+}
+
+static void recORI() {
+// Rt = Rs Or Im
+ if (!_Rt_) return;
+
+ if (_Rs_) {
+ if (_Rs_ == _Rt_) {
+ OR32ItoM((u32)&psxRegs.GPR.r[_Rt_], _ImmU_);
+ } else {
+ MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]);
+ if (_ImmU_) OR32ItoR (EAX, _ImmU_);
+ MOV32RtoM((u32)&psxRegs.GPR.r[_Rt_], EAX);
+ }
+ } else {
+ MOV32ItoM((u32)&psxRegs.GPR.r[_Rt_], _ImmU_);
+ }
+}
+
+static void recXORI() {
+// Rt = Rs Xor Im
+ if (!_Rt_) return;
+
+ if (_Rs_) {
+ if (_Rs_ == _Rt_) {
+ XOR32ItoM((u32)&psxRegs.GPR.r[_Rt_], _ImmU_);
+ } else {
+ MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]);
+ XOR32ItoR(EAX, _ImmU_);
+ MOV32RtoM((u32)&psxRegs.GPR.r[_Rt_], EAX);
+ }
+ } else {
+ MOV32ItoR(EAX, _ImmU_ ^ 0);
+ MOV32RtoM((u32)&psxRegs.GPR.r[_Rt_], EAX);
+ }
+}
+//#endif
+//end of * Arithmetic with immediate operand
+
+/*********************************************************
+* Load higher 16 bits of the first word in GPR with imm *
+* Format: OP rt, immediate *
+*********************************************************/
+/*REC_FUNC(LUI);
+#if 0*/
+static void recLUI() {
+// Rt = Imm << 16
+ if (!_Rt_) return;
+
+ MOV32ItoM((u32)&psxRegs.GPR.r[_Rt_], psxRegs.code << 16);
+}
+//#endif
+//End of Load Higher .....
+
+
+/*********************************************************
+* Register arithmetic *
+* Format: OP rd, rs, rt *
+*********************************************************/
+/*
+REC_FUNC(ADD);
+REC_FUNC(ADDU);
+REC_FUNC(SUB);
+REC_FUNC(SUBU);
+REC_FUNC(AND);
+REC_FUNC(OR);
+REC_FUNC(XOR);
+REC_FUNC(NOR);
+REC_FUNC(SLT);
+REC_FUNC(SLTU);
+
+#if 0*/
+static void recADDU() {
+// Rd = Rs + Rt
+ if (!_Rd_) return;
+
+ if (_Rs_ && _Rt_) {
+ MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]);
+ ADD32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]);
+ } else if (_Rs_) {
+ MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]);
+ } else if (_Rt_) {
+ MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]);
+ } else {
+ XOR32RtoR(EAX, EAX);
+ }
+ MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX);
+}
+
+static void recADD() {
+// Rd = Rs + Rt
+ recADDU();
+}
+
+static void recSUBU() {
+// Rd = Rs - Rt
+ if (!_Rd_) return;
+
+ if (_Rs_ || _Rt_) {
+ MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]);
+ SUB32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]);
+ } else {
+ XOR32RtoR(EAX, EAX);
+ }
+ MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX);
+}
+
+static void recSUB() {
+// Rd = Rs - Rt
+ recSUBU();
+}
+
+static void recAND() {
+// Rd = Rs And Rt
+ if (!_Rd_) return;
+
+ if (_Rs_ && _Rt_) {
+ MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]);
+ AND32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]);
+ } else {
+ XOR32RtoR(EAX, EAX);
+ }
+ MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX);
+}
+
+static void recOR() {
+// Rd = Rs Or Rt
+ if (!_Rd_) return;
+
+ if (_Rs_ && _Rt_) {
+ MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]);
+ OR32MtoR (EAX, (u32)&psxRegs.GPR.r[_Rt_]);
+ } else if (_Rs_) {
+ MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]);
+ } else if (_Rt_) {
+ MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]);
+ } else {
+ XOR32RtoR(EAX, EAX);
+ }
+ MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX);
+}
+
+static void recXOR() {
+// Rd = Rs Xor Rt
+ if (!_Rd_) return;
+
+ if (_Rs_ && _Rt_) {
+ MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]);
+ XOR32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]);
+ } else if (_Rs_) {
+ MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]);
+ XOR32ItoR(EAX, 0);
+ } else if (_Rt_) {
+ XOR32RtoR(EAX, EAX);
+ XOR32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]);
+ } else {
+ XOR32RtoR(EAX, EAX);
+ }
+ MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX);
+}
+
+static void recNOR() {
+// Rd = Rs Nor Rt
+ if (!_Rd_) return;
+
+ if (_Rs_ && _Rt_) {
+ MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]);
+ OR32MtoR (EAX, (u32)&psxRegs.GPR.r[_Rt_]);
+ NOT32R (EAX);
+ } else if (_Rs_) {
+ MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]);
+ NOT32R (EAX);
+ } else if (_Rt_) {
+ MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]);
+ NOT32R (EAX);
+ } else {
+ MOV32ItoR(EAX, ~0);
+ }
+ MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX);
+}
+
+static void recSLT() {
+// Rd = Rs < Rt (signed)
+ if (!_Rd_) return;
+
+ MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]);
+ CMP32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]);
+ SETL8R (EAX);
+ AND32ItoR(EAX, 0xff);
+ MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX);
+}
+
+static void recSLTU() {
+// Rd = Rs < Rt (unsigned)
+ if (!_Rd_) return;
+
+ MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]);
+ CMP32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]);
+ SBB32RtoR(EAX, EAX);
+ NEG32R (EAX);
+ MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX);
+}
+//#endif
+//End of * Register arithmetic
+
+/*********************************************************
+* Register mult/div & Register trap logic *
+* Format: OP rs, rt *
+*********************************************************/
+
+/*REC_FUNC(MULT);
+REC_FUNC(MULTU);
+REC_FUNC(DIV);
+REC_FUNC(DIVU);
+#if 0*/
+static void recMULT() {
+// Lo/Hi = Rs * Rt (signed)
+
+ MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]);
+ IMUL32M ((u32)&psxRegs.GPR.r[_Rt_]);
+ MOV32RtoM((u32)&psxRegs.GPR.n.lo, EAX);
+ MOV32RtoM((u32)&psxRegs.GPR.n.hi, EDX);
+}
+
+static void recMULTU() {
+// Lo/Hi = Rs * Rt (unsigned)
+
+ MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]);
+ MUL32M ((u32)&psxRegs.GPR.r[_Rt_]);
+ MOV32RtoM((u32)&psxRegs.GPR.n.lo, EAX);
+ MOV32RtoM((u32)&psxRegs.GPR.n.hi, EDX);
+}
+
+static void recDIV() {
+// Lo/Hi = Rs / Rt (signed)
+
+ MOV32MtoR(ECX, (u32)&psxRegs.GPR.r[_Rt_]);
+ CMP32ItoR(ECX, 0);
+ j8Ptr[0] = JE8(0);
+ MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]);
+ CDQ();
+ IDIV32R (ECX);
+ MOV32RtoM((u32)&psxRegs.GPR.n.lo, EAX);
+ MOV32RtoM((u32)&psxRegs.GPR.n.hi, EDX);
+ x86SetJ8(j8Ptr[0]);
+}
+
+static void recDIVU() {
+// Lo/Hi = Rs / Rt (unsigned)
+
+ MOV32MtoR(ECX, (u32)&psxRegs.GPR.r[_Rt_]);
+ CMP32ItoR(ECX, 0);
+ j8Ptr[0] = JE8(0);
+ MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]);
+ XOR32RtoR(EDX, EDX);
+ DIV32R (ECX);
+ MOV32RtoM((u32)&psxRegs.GPR.n.lo, EAX);
+ MOV32RtoM((u32)&psxRegs.GPR.n.hi, EDX);
+ x86SetJ8(j8Ptr[0]);
+}
+//#endif
+//End of * Register mult/div & Register trap logic
+
+/*REC_FUNC(LB);
+REC_FUNC(LBU);
+REC_FUNC(LH);
+REC_FUNC(LHU);
+REC_FUNC(LW);
+
+REC_FUNC(SB);
+REC_FUNC(SH);
+REC_FUNC(SW);*/
+
+REC_FUNC(LWL);
+REC_FUNC(LWR);
+REC_FUNC(SWL);
+REC_FUNC(SWR);
+//#if 0
+static void recLB() {
+// Rt = mem[Rs + Im] (signed)
+
+ MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]);
+ if (_Imm_) ADD32ItoR(EAX, _Imm_);
+ PUSH32R (EAX);
+ CALLFunc((u32)psxMemRead8);
+ if (_Rt_) {
+ MOVSX32R8toR(EAX, EAX);
+ MOV32RtoM((u32)&psxRegs.GPR.r[_Rt_], EAX);
+ }
+ ADD32ItoR(ESP, 4);
+}
+
+static void recLBU() {
+// Rt = mem[Rs + Im] (unsigned)
+
+ MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]);
+ if (_Imm_) ADD32ItoR(EAX, _Imm_);
+ PUSH32R (EAX);
+ CALLFunc((u32)psxMemRead8);
+ if (_Rt_) {
+ MOVZX32R8toR(EAX, EAX);
+ MOV32RtoM((u32)&psxRegs.GPR.r[_Rt_], EAX);
+ }
+ ADD32ItoR(ESP, 4);
+}
+
+static void recLH() {
+// Rt = mem[Rs + Im] (signed)
+
+ MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]);
+ if (_Imm_) ADD32ItoR(EAX, _Imm_);
+ PUSH32R (EAX);
+ CALLFunc((u32)psxMemRead16);
+ if (_Rt_) {
+ MOVSX32R16toR(EAX, EAX);
+ MOV32RtoM((u32)&psxRegs.GPR.r[_Rt_], EAX);
+ }
+ ADD32ItoR(ESP, 4);
+}
+
+static void recLHU() {
+// Rt = mem[Rs + Im] (unsigned)
+
+ MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]);
+ if (_Imm_) ADD32ItoR(EAX, _Imm_);
+ PUSH32R (EAX);
+ CALLFunc((u32)psxMemRead16);
+ if (_Rt_) {
+ MOVZX32R16toR(EAX, EAX);
+ MOV32RtoM((u32)&psxRegs.GPR.r[_Rt_], EAX);
+ }
+ ADD32ItoR(ESP, 4);
+}
+
+static void recLW() {
+// Rt = mem[Rs + Im] (unsigned)
+
+ MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]);
+ if (_Imm_) ADD32ItoR(EAX, _Imm_);
+ PUSH32R (EAX);
+ CALLFunc((u32)psxMemRead32);
+ if (_Rt_) {
+ MOV32RtoM((u32)&psxRegs.GPR.r[_Rt_], EAX);
+ }
+ ADD32ItoR(ESP, 4);
+}
+/*
+void recLWL() {
+}
+
+void recLWR() {
+}
+*/
+static void recSB() {
+// mem[Rs + Im] = Rt
+
+ PUSH32M ((u32)&psxRegs.GPR.r[_Rt_]);
+ MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]);
+ if (_Imm_) ADD32ItoR(EAX, _Imm_);
+ PUSH32R (EAX);
+ CALLFunc((u32)psxMemWrite8);
+ ADD32ItoR(ESP, 8);
+}
+
+static void recSH() {
+// mem[Rs + Im] = Rt
+
+ PUSH32M ((u32)&psxRegs.GPR.r[_Rt_]);
+ MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]);
+ if (_Imm_) ADD32ItoR(EAX, _Imm_);
+ PUSH32R (EAX);
+ CALLFunc((u32)psxMemWrite16);
+ ADD32ItoR(ESP, 8);
+}
+
+static void recSW() {
+// mem[Rs + Im] = Rt
+
+ PUSH32M ((u32)&psxRegs.GPR.r[_Rt_]);
+ MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]);
+ if (_Imm_) ADD32ItoR(EAX, _Imm_);
+ PUSH32R (EAX);
+ CALLFunc((u32)psxMemWrite32);
+ ADD32ItoR(ESP, 8);
+}
+//#endif
+/*
+void recSWL() {
+}
+
+void recSWR() {
+}
+*/
+/*REC_FUNC(SLL);
+REC_FUNC(SRL);
+REC_FUNC(SRA);
+#if 0*/
+static void recSLL() {
+// Rd = Rt << Sa
+ if (!_Rd_) return;
+
+ if (_Rt_) {
+ MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]);
+ if (_Sa_) SHL32ItoR(EAX, _Sa_);
+ MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX);
+ } else {
+ XOR32RtoR(EAX, EAX);
+ MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX);
+ }
+}
+
+static void recSRL() {
+// Rd = Rt >> Sa
+ if (!_Rd_) return;
+
+ if (_Rt_) {
+ MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]);
+ if (_Sa_) SHR32ItoR(EAX, _Sa_);
+ MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX);
+ } else {
+ XOR32RtoR(EAX, EAX);
+ MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX);
+ }
+}
+
+static void recSRA() {
+// Rd = Rt >> Sa
+ if (!_Rd_) return;
+
+ if (_Rt_) {
+ MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]);
+ if (_Sa_) SAR32ItoR(EAX, _Sa_);
+ MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX);
+ } else {
+ XOR32RtoR(EAX, EAX);
+ MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX);
+ }
+}
+//#endif
+
+/*REC_FUNC(SLLV);
+REC_FUNC(SRLV);
+REC_FUNC(SRAV);
+#if 0*/
+static void recSLLV() {
+// Rd = Rt << Rs
+ if (!_Rd_) return;
+
+ if (_Rt_) {
+ MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]);
+ if (_Rs_) {
+ MOV32MtoR(ECX, (u32)&psxRegs.GPR.r[_Rs_]);
+ SHL32CLtoR(EAX);
+ }
+ }
+ MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX);
+}
+
+static void recSRLV() {
+// Rd = Rt >> Rs
+ if (!_Rd_) return;
+
+ if (_Rt_) {
+ MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]);
+ if (_Rs_) {
+ MOV32MtoR(ECX, (u32)&psxRegs.GPR.r[_Rs_]);
+ SHR32CLtoR(EAX);
+ }
+ }
+ MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX);
+}
+
+static void recSRAV() {
+// Rd = Rt >> Rs
+ if (!_Rd_) return;
+
+ if (_Rt_) {
+ MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]);
+ if (_Rs_) {
+ MOV32MtoR(ECX, (u32)&psxRegs.GPR.r[_Rs_]);
+ SAR32CLtoR(EAX);
+ }
+ }
+ MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX);
+}
+//#endif
+
+/*REC_SYS(SYSCALL);
+REC_SYS(BREAK);
+
+#if 0*/
+static void recSYSCALL() {
+ MOV32ItoR(EAX, pc - 4);
+ MOV32RtoM((u32)&psxRegs.pc, EAX);
+ PUSH32I (branch == 1 ? 1 : 0);
+ PUSH32I (0x20);
+ CALLFunc ((u32)psxException);
+ ADD32ItoR(ESP, 8);
+
+ if (!branch) branch = 2;
+}
+
+static void recBREAK() {
+}
+//#endif
+/*
+REC_FUNC(MFHI);
+REC_FUNC(MTHI);
+REC_FUNC(MFLO);
+REC_FUNC(MTLO);
+#if 0*/
+static void recMFHI() {
+// Rd = Hi
+ if (!_Rd_) return;
+
+ MOV32MtoR(EAX, (u32)&psxRegs.GPR.n.hi);
+ MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX);
+}
+
+static void recMTHI() {
+// Hi = Rs
+
+ MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]);
+ MOV32RtoM((u32)&psxRegs.GPR.n.hi, EAX);
+}
+
+static void recMFLO() {
+// Rd = Lo
+ if (!_Rd_) return;
+
+ MOV32MtoR(EAX, (u32)&psxRegs.GPR.n.lo);
+ MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX);
+}
+
+static void recMTLO() {
+// Lo = Rs
+
+ MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]);
+ MOV32RtoM((u32)&psxRegs.GPR.n.lo, EAX);
+}
+//#endif
+
+/*REC_BRANCH(J);
+REC_BRANCH(JR);
+REC_BRANCH(JAL);
+REC_BRANCH(JALR);
+REC_BRANCH(BLTZ);
+REC_BRANCH(BGTZ);
+REC_BRANCH(BLTZAL);
+REC_BRANCH(BGEZAL);
+REC_BRANCH(BNE);
+REC_BRANCH(BEQ);
+REC_BRANCH(BLEZ);
+REC_BRANCH(BGEZ);
+
+#if 0*/
+static void recBLTZ() {
+// Branch if Rs < 0
+
+ CMP32ItoM((u32)&psxRegs.GPR.r[_Rs_], 0);
+ j8Ptr[0] = JL8(0);
+
+ MOV32ItoM((u32)&target, pc+4);
+ j8Ptr[1] = JMP8(0);
+
+ x86SetJ8(j8Ptr[0]);
+
+ MOV32ItoM((u32)&target, _Imm_ * 4 + pc);
+
+ x86SetJ8(j8Ptr[1]);
+
+ SetBranch();
+}
+
+static void recBGEZ() {
+// Branch if Rs >= 0
+
+ CMP32ItoM((u32)&psxRegs.GPR.r[_Rs_], 0);
+ j8Ptr[0] = JGE8(0);
+
+ MOV32ItoM((u32)&target, pc+4);
+ j8Ptr[1] = JMP8(0);
+
+ x86SetJ8(j8Ptr[0]);
+
+ MOV32ItoM((u32)&target, _Imm_ * 4 + pc);
+
+ x86SetJ8(j8Ptr[1]);
+
+ SetBranch();
+}
+
+static void recBLTZAL() {
+// Branch if Rs < 0
+
+ CMP32ItoM((u32)&psxRegs.GPR.r[_Rs_], 0);
+ j8Ptr[0] = JL8(0);
+
+ MOV32ItoM((u32)&target, pc+4);
+ j8Ptr[1] = JMP8(0);
+
+ x86SetJ8(j8Ptr[0]);
+
+ MOV32ItoM((u32)&target, _Imm_ * 4 + pc);
+ MOV32ItoM((u32)&psxRegs.GPR.r[31], pc + 4);
+
+ x86SetJ8(j8Ptr[1]);
+
+ SetBranch();
+}
+
+static void recBGEZAL() {
+// Branch if Rs >= 0
+
+ CMP32ItoM((u32)&psxRegs.GPR.r[_Rs_], 0);
+ j8Ptr[0] = JGE8(0);
+
+ MOV32ItoM((u32)&target, pc+4);
+ j8Ptr[1] = JMP8(0);
+
+ x86SetJ8(j8Ptr[0]);
+
+ MOV32ItoM((u32)&target, _Imm_ * 4 + pc);
+ MOV32ItoM((u32)&psxRegs.GPR.r[31], pc + 4);
+
+ x86SetJ8(j8Ptr[1]);
+
+ SetBranch();
+}
+
+static void recJ() {
+// j target
+ MOV32ItoM((u32)&target, _Target_ * 4 + (pc & 0xf0000000));
+
+ SetBranch();
+}
+
+static void recJAL() {
+// jal target
+
+ MOV32ItoM((u32)&target, _Target_ * 4 + (pc & 0xf0000000));
+ MOV32ItoM((u32)&psxRegs.GPR.r[31], pc + 4);
+
+ SetBranch();
+}
+
+static void recJR() {
+// jr Rs
+
+ MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]);
+ MOV32RtoM((u32)&target, EAX);
+
+ SetBranch();
+}
+
+static void recJALR() {
+// jalr Rs
+
+ MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]);
+ MOV32RtoM((u32)&target, EAX);
+
+ if (_Rd_) {
+ MOV32ItoM((u32)&psxRegs.GPR.r[_Rd_], pc + 4);
+ }
+
+ SetBranch();
+}
+
+static void recBEQ() {
+// Branch if Rs == Rt
+
+ if (_Rs_ == _Rt_) {
+ MOV32ItoM((u32)&target, _Imm_ * 4 + pc);
+ } else {
+ if (_Rs_) {
+ MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]);
+ } else {
+ XOR32RtoR(EAX, EAX);
+ }
+ CMP32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]);
+ j8Ptr[0] = JE8(0);
+
+ MOV32ItoM((u32)&target, pc+4);
+ j8Ptr[1] = JMP8(0);
+
+ x86SetJ8(j8Ptr[0]);
+
+ MOV32ItoM((u32)&target, _Imm_ * 4 + pc);
+
+ x86SetJ8(j8Ptr[1]);
+ }
+
+ SetBranch();
+}
+
+static void recBNE() {
+// Branch if Rs != Rt
+
+ if (_Rs_) {
+ MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]);
+ } else {
+ XOR32RtoR(EAX, EAX);
+ }
+ CMP32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]);
+ j8Ptr[0] = JNE8(0);
+
+ MOV32ItoM((u32)&target, pc+4);
+ j8Ptr[1] = JMP8(0);
+
+ x86SetJ8(j8Ptr[0]);
+
+ MOV32ItoM((u32)&target, _Imm_ * 4 + pc);
+
+ x86SetJ8(j8Ptr[1]);
+
+ SetBranch();
+}
+
+static void recBLEZ() {
+// Branch if Rs <= 0
+
+ CMP32ItoM((u32)&psxRegs.GPR.r[_Rs_], 0);
+ j8Ptr[0] = JLE8(0);
+
+ MOV32ItoM((u32)&target, pc+4);
+ j8Ptr[1] = JMP8(0);
+
+ x86SetJ8(j8Ptr[0]);
+
+ MOV32ItoM((u32)&target, _Imm_ * 4 + pc);
+
+ x86SetJ8(j8Ptr[1]);
+
+ SetBranch();
+}
+
+static void recBGTZ() {
+// Branch if Rs > 0
+
+ CMP32ItoM((u32)&psxRegs.GPR.r[_Rs_], 0);
+ j8Ptr[0] = JG8(0);
+
+ MOV32ItoM((u32)&target, pc+4);
+ j8Ptr[1] = JMP8(0);
+
+ x86SetJ8(j8Ptr[0]);
+
+ MOV32ItoM((u32)&target, _Imm_ * 4 + pc);
+
+ x86SetJ8(j8Ptr[1]);
+
+ SetBranch();
+}
+//#endif
+
+/*REC_FUNC(MFC0);
+REC_FUNC(MTC0);
+REC_FUNC(CFC0);
+REC_FUNC(CTC0);
+REC_FUNC(RFE);
+#if 0*/
+static void recMFC0() {
+// Rt = Cop0->Rd
+ if (!_Rt_) return;
+
+ MOV32MtoR(EAX, (u32)&psxRegs.CP0.r[_Rd_]);
+ MOV32RtoM((u32)&psxRegs.GPR.r[_Rt_], EAX);
+}
+
+static void recCFC0() {
+// Rt = Cop0->Rd
+ if (!_Rt_) return;
+
+ MOV32MtoR(EAX, (u32)&psxRegs.CP0.r[_Rd_]);
+ MOV32RtoM((u32)&psxRegs.GPR.r[_Rt_], EAX);
+}
+
+static void recMTC0() {
+// Cop0->Rd = Rt
+
+ MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]);
+ MOV32RtoM((u32)&psxRegs.CP0.r[_Rd_], EAX);
+}
+
+static void recCTC0() {
+// Cop0->Rd = Rt
+
+ MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]);
+ MOV32RtoM((u32)&psxRegs.CP0.r[_Rd_], EAX);
+}
+
+static void recRFE() {
+ MOV32MtoR(EAX, (u32)&psxRegs.CP0.n.Status);
+ MOV32RtoR(ECX, EAX);
+ AND32ItoR(EAX, 0xfffffff0);
+ AND32ItoR(ECX, 0x3c);
+ SHR32ItoR(ECX, 2);
+ OR32RtoR (EAX, ECX);
+ MOV32RtoM((u32)&psxRegs.CP0.n.Status, EAX);
+}
+//#endif
+
+#define CP2_FUNC(f) \
+void gte##f(); \
+static void rec##f() { \
+ MOV32ItoM((u32)&psxRegs.code, (u32)psxRegs.code); \
+ MOV32ItoM((u32)&psxRegs.pc, (u32)pc); \
+ CALLFunc ((u32)gte##f); \
+/* branch = 2; */\
+}
+
+CP2_FUNC(MFC2);
+CP2_FUNC(MTC2);
+CP2_FUNC(CFC2);
+CP2_FUNC(CTC2);
+CP2_FUNC(LWC2);
+CP2_FUNC(SWC2);
+
+CP2_FUNC(RTPS);
+CP2_FUNC(OP);
+CP2_FUNC(NCLIP);
+CP2_FUNC(DPCS);
+CP2_FUNC(INTPL);
+CP2_FUNC(MVMVA);
+CP2_FUNC(NCDS);
+CP2_FUNC(NCDT);
+CP2_FUNC(CDP);
+CP2_FUNC(NCCS);
+CP2_FUNC(CC);
+CP2_FUNC(NCS);
+CP2_FUNC(NCT);
+CP2_FUNC(SQR);
+CP2_FUNC(DCPL);
+CP2_FUNC(DPCT);
+CP2_FUNC(AVSZ3);
+CP2_FUNC(AVSZ4);
+CP2_FUNC(RTPT);
+CP2_FUNC(GPF);
+CP2_FUNC(GPL);
+CP2_FUNC(NCCT);
+
+static void recHLE() {
+ MOV32ItoR(EAX, (u32)psxHLEt[psxRegs.code & 0xff]);
+ CALL32R(EAX);
+ branch = 2;
+}
+
+//
+
+static void (*recBSC[64])() = {
+ recSPECIAL, recREGIMM, recJ , recJAL , recBEQ , recBNE , recBLEZ, recBGTZ,
+ recADDI , recADDIU , recSLTI, recSLTIU, recANDI, recORI , recXORI, recLUI ,
+ recCOP0 , recNULL , recCOP2, recNULL , recNULL, recNULL, recNULL, recNULL,
+ recNULL , recNULL , recNULL, recNULL , recNULL, recNULL, recNULL, recNULL,
+ recLB , recLH , recLWL , recLW , recLBU , recLHU , recLWR , recNULL,
+ recSB , recSH , recSWL , recSW , recNULL, recNULL, recSWR , recNULL,
+ recNULL , recNULL , recLWC2, recNULL , recNULL, recNULL, recNULL, recNULL,
+ recNULL , recNULL , recSWC2, recHLE , recNULL, recNULL, recNULL, recNULL
+};
+
+static void (*recSPC[64])() = {
+ recSLL , recNULL, recSRL , recSRA , recSLLV , recNULL , recSRLV, recSRAV,
+ recJR , recJALR, recNULL, recNULL, recSYSCALL, recBREAK, recNULL, recNULL,
+ recMFHI, recMTHI, recMFLO, recMTLO, recNULL , recNULL , recNULL, recNULL,
+ recMULT, recMULTU, recDIV, recDIVU, recNULL , recNULL , recNULL, recNULL,
+ recADD , recADDU, recSUB , recSUBU, recAND , recOR , recXOR , recNOR ,
+ recNULL, recNULL, recSLT , recSLTU, recNULL , recNULL , recNULL, recNULL,
+ recNULL, recNULL, recNULL, recNULL, recNULL , recNULL , recNULL, recNULL,
+ recNULL, recNULL, recNULL, recNULL, recNULL , recNULL , recNULL, recNULL
+};
+
+static void (*recREG[32])() = {
+ recBLTZ , recBGEZ , recNULL, recNULL, recNULL, recNULL, recNULL, recNULL,
+ recNULL , recNULL , recNULL, recNULL, recNULL, recNULL, recNULL, recNULL,
+ recBLTZAL, recBGEZAL, recNULL, recNULL, recNULL, recNULL, recNULL, recNULL,
+ recNULL , recNULL , recNULL, recNULL, recNULL, recNULL, recNULL, recNULL
+};
+
+static void (*recCP0[32])() = {
+ recMFC0, recNULL, recCFC0, recNULL, recMTC0, recNULL, recCTC0, recNULL,
+ recNULL, recNULL, recNULL, recNULL, recNULL, recNULL, recNULL, recNULL,
+ recRFE , recNULL, recNULL, recNULL, recNULL, recNULL, recNULL, recNULL,
+ recNULL, recNULL, recNULL, recNULL, recNULL, recNULL, recNULL, recNULL
+};
+
+static void (*recCP2[64])() = {
+ recBASIC, recRTPS , recNULL , recNULL, recNULL, recNULL , recNCLIP, recNULL, // 00
+ recNULL , recNULL , recNULL , recNULL, recOP , recNULL , recNULL , recNULL, // 08
+ recDPCS , recINTPL, recMVMVA, recNCDS, recCDP , recNULL , recNCDT , recNULL, // 10
+ recNULL , recNULL , recNULL , recNCCS, recCC , recNULL , recNCS , recNULL, // 18
+ recNCT , recNULL , recNULL , recNULL, recNULL, recNULL , recNULL , recNULL, // 20
+ recSQR , recDCPL , recDPCT , recNULL, recNULL, recAVSZ3, recAVSZ4, recNULL, // 28
+ recRTPT , recNULL , recNULL , recNULL, recNULL, recNULL , recNULL , recNULL, // 30
+ recNULL , recNULL , recNULL , recNULL, recNULL, recGPF , recGPL , recNCCT // 38
+};
+
+static void (*recCP2BSC[32])() = {
+ recMFC2, recNULL, recCFC2, recNULL, recMTC2, recNULL, recCTC2, recNULL,
+ recNULL, recNULL, recNULL, recNULL, recNULL, recNULL, recNULL, recNULL,
+ recNULL, recNULL, recNULL, recNULL, recNULL, recNULL, recNULL, recNULL,
+ recNULL, recNULL, recNULL, recNULL, recNULL, recNULL, recNULL, recNULL
+};
+
+static void recRecompile() {
+ /* if x86Ptr reached the mem limit reset whole mem */
+ if (((u32)x86Ptr - (u32)recMem) >= (RECMEM_SIZE - 0x10000))
+ recReset();
+
+ PC_REC32(psxRegs.pc) = (u32)x86Ptr;
+ pc = psxRegs.pc;
+
+ for (count=0; count<500;) {
+ char *p;
+
+ p = (char *)PSXM(pc);
+ if (p == NULL) recError();
+ psxRegs.code = *(u32 *)p;
+
+ pc+=4; count++;
+ recBSC[psxRegs.code>>26]();
+
+ if (branch) {
+ break;
+ }
+ }
+
+ if (!branch) {
+ MOV32ItoM((u32)&psxRegs.pc, pc);
+ }
+
+ /* store cycle */
+ ADD32ItoM((u32)&psxRegs.cycle, count);
+
+ branch = 0;
+
+ RET();
+}
+
+
+R3000Acpu psxRec = {
+ recInit,
+ recReset,
+ recExecute,
+ recExecuteBlock,
+ recClear,
+ recShutdown
+};
diff --git a/PcsxSrc/ix86/ix86.c b/PcsxSrc/ix86/ix86.c
new file mode 100644
index 0000000..d0775e4
--- /dev/null
+++ b/PcsxSrc/ix86/ix86.c
@@ -0,0 +1,966 @@
+/*
+ * ix86 core.
+ * Author: linuzappz <linuzappz@pcsx.net>
+ */
+
+#include <stdio.h>
+
+#include "ix86.h"
+
+void x86Init(char *ptr) {
+ x86Ptr = ptr;
+}
+
+void x86Shutdown() {
+}
+
+void x86SetJ8(u8 *j8) {
+ *j8 = ((u8*)x86Ptr - j8) - 1;
+}
+
+void x86SetJ32(u32 *j32) {
+ *j32 = ((u32*)x86Ptr - j32) - 4;
+}
+
+#define SIB 4
+#define DISP32 5
+
+#define write8(val) *(unsigned char *)x86Ptr = val; x86Ptr++;
+#define write16(val) *(unsigned short*)x86Ptr = val; x86Ptr+=2;
+#define write32(val) *(u32 *)x86Ptr = val; x86Ptr+=4;
+
+/* macros helpers */
+
+#define ModRM(mod, rm, reg) \
+ write8((mod << 6) | (rm << 3) | (reg));
+
+#define SibSB(ss, rm, index) \
+ write8((ss << 6) | (rm << 3) | (index));
+
+#define SET8R(cc, to) { \
+ write8(0x0F); write8(cc); \
+ write8((0xC0) | (to)); }
+
+#define J8Rel(cc, to) { \
+ write8(cc); write8(to); return x86Ptr - 1; }
+
+#define CMOV32RtoR(cc, to, from) { \
+ write8(0x0F); write8(cc); \
+ ModRM(3, to, from); }
+
+#define CMOV32MtoR(cc, to, from) { \
+ write8(0x0F); write8(cc); \
+ ModRM(0, to, DISP32); \
+ write32(from); }
+
+/********************/
+/* IX86 intructions */
+/********************/
+
+// mov instructions
+
+/* mov r32 to r32 */
+void MOV32RtoR(int to, int from) {
+ write8(0x89);
+ ModRM(3, from, to);
+}
+
+/* mov r32 to m32 */
+void MOV32RtoM(u32 to, int from) {
+ write8(0x89);
+ ModRM(0, from, DISP32);
+ write32(to);
+}
+
+/* mov m32 to r32 */
+void MOV32MtoR(int to, u32 from) {
+ write8(0x8B);
+ ModRM(0, to, DISP32);
+ write32(from);
+}
+
+/* mov [r32] to r32 */
+void MOV32RmtoR(int to, int from) {
+ write8(0x8B);
+ ModRM(0, to, from);
+}
+
+/* mov [r32][r32*scale] to r32 */
+void MOV32RmStoR(int to, int from, int from2, int scale) {
+ write8(0x8B);
+ ModRM(0, to, 0x4);
+ SibSB(scale, from2, from);
+}
+
+/* mov r32 to [r32] */
+void MOV32RtoRm(int to, int from) {
+ write8(0x89);
+ ModRM(0, from, to);
+}
+
+/* mov imm32 to r32 */
+void MOV32ItoR(int to, u32 from) {
+ write8(0xB8 | to);
+ write32(from);
+}
+
+/* mov imm32 to m32 */
+void MOV32ItoM(u32 to, u32 from) {
+ write8(0xC7);
+ ModRM(0, 0, DISP32);
+ write32(to);
+ write32(from);
+}
+
+/* movsx r8 to r32 */
+void MOVSX32R8toR(int to, int from) {
+ write16(0xBE0F);
+ ModRM(3, to, from);
+}
+
+/* movsx r16 to r32 */
+void MOVSX32R16toR(int to, int from) {
+ write16(0xBF0F);
+ ModRM(3, to, from);
+}
+
+/* movzx r8 to r32 */
+void MOVZX32R8toR(int to, int from) {
+ write16(0xB60F);
+ ModRM(3, to, from);
+}
+
+/* movzx r16 to r32 */
+void MOVZX32R16toR(int to, int from) {
+ write16(0xB70F);
+ ModRM(3, to, from);
+}
+
+/* cmovne r32 to r32 */
+void CMOVNE32RtoR(int to, int from) {
+ CMOV32RtoR(0x45, to, from);
+}
+
+/* cmovne m32 to r32*/
+void CMOVNE32MtoR(int to, u32 from) {
+ CMOV32MtoR(0x45, to, from);
+}
+
+/* cmove r32 to r32*/
+void CMOVE32RtoR(int to, int from) {
+ CMOV32RtoR(0x44, to, from);
+}
+
+/* cmove m32 to r32*/
+void CMOVE32MtoR(int to, u32 from) {
+ CMOV32MtoR(0x44, to, from);
+}
+
+/* cmovg r32 to r32*/
+void CMOVG32RtoR(int to, int from) {
+ CMOV32RtoR(0x4F, to, from);
+}
+
+/* cmovg m32 to r32*/
+void CMOVG32MtoR(int to, u32 from) {
+ CMOV32MtoR(0x4F, to, from);
+}
+
+/* cmovge r32 to r32*/
+void CMOVGE32RtoR(int to, int from) {
+ CMOV32RtoR(0x4D, to, from);
+}
+
+/* cmovge m32 to r32*/
+void CMOVGE32MtoR(int to, u32 from) {
+ CMOV32MtoR(0x4D, to, from);
+}
+
+/* cmovl r32 to r32*/
+void CMOVL32RtoR(int to, int from) {
+ CMOV32RtoR(0x4C, to, from);
+}
+
+/* cmovl m32 to r32*/
+void CMOVL32MtoR(int to, u32 from) {
+ CMOV32MtoR(0x4C, to, from);
+}
+
+/* cmovle r32 to r32*/
+void CMOVLE32RtoR(int to, int from) {
+ CMOV32RtoR(0x4E, to, from);
+}
+
+/* cmovle m32 to r32*/
+void CMOVLE32MtoR(int to, u32 from) {
+ CMOV32MtoR(0x4E, to, from);
+}
+
+// arithmic instructions
+
+/* add imm32 to r32 */
+void ADD32ItoR(int to, u32 from) {
+ if (to == EAX) {
+ write8(0x05);
+ } else {
+ write8(0x81);
+ ModRM(3, 0, to);
+ }
+ write32(from);
+}
+
+/* add imm32 to m32 */
+void ADD32ItoM(u32 to, u32 from) {
+ write8(0x81);
+ ModRM(0, 0, DISP32);
+ write32(to);
+ write32(from);
+}
+
+/* add r32 to r32 */
+void ADD32RtoR(int to, int from) {
+ write8(0x01);
+ ModRM(3, from, to);
+}
+
+/* add m32 to r32 */
+void ADD32MtoR(int to, u32 from) {
+ write8(0x03);
+ ModRM(0, to, DISP32);
+ write32(from);
+}
+
+/* adc imm32 to r32 */
+void ADC32ItoR(int to, u32 from) {
+ if (to == EAX) {
+ write8(0x15);
+ } else {
+ write8(0x81);
+ ModRM(3, 2, to);
+ }
+ write32(from);
+}
+
+/* adc r32 to r32 */
+void ADC32RtoR(int to, int from) {
+ write8(0x11);
+ ModRM(3, from, to);
+}
+
+/* adc m32 to r32 */
+void ADC32MtoR(int to, u32 from) {
+ write8(0x13);
+ ModRM(0, to, DISP32);
+ write32(from);
+}
+
+/* sub imm32 to r32 */
+void SUB32ItoR(int to, u32 from) {
+ if (to == EAX) {
+ write8(0x2D);
+ } else {
+ write8(0x81);
+ ModRM(3, 5, to);
+ }
+ write32(from);
+}
+
+/* sub r32 to r32 */
+void SUB32RtoR(int to, int from) {
+ write8(0x29);
+ ModRM(3, from, to);
+}
+
+/* sub m32 to r32 */
+void SUB32MtoR(int to, u32 from) {
+ write8(0x2B);
+ ModRM(0, to, DISP32);
+ write32(from);
+}
+
+/* sbb imm32 to r32 */
+void SBB32ItoR(int to, u32 from) {
+ if (to == EAX) {
+ write8(0x1D);
+ } else {
+ write8(0x81);
+ ModRM(3, 3, to);
+ }
+ write32(from);
+}
+
+/* sbb r32 to r32 */
+void SBB32RtoR(int to, int from) {
+ write8(0x19);
+ ModRM(3, from, to);
+}
+
+/* sbb m32 to r32 */
+void SBB32MtoR(int to, u32 from) {
+ write8(0x1B);
+ ModRM(0, to, DISP32);
+ write32(from);
+}
+
+/* mul eax by r32 to edx:eax */
+void MUL32R(int from) {
+ write8(0xF7);
+ ModRM(3, 4, from);
+}
+
+/* imul eax by r32 to edx:eax */
+void IMUL32R(int from) {
+ write8(0xF7);
+ ModRM(3, 5, from);
+}
+
+/* mul eax by m32 to edx:eax */
+void MUL32M(u32 from) {
+ write8(0xF7);
+ ModRM(0, 4, DISP32);
+ write32(from);
+}
+
+/* imul eax by m32 to edx:eax */
+void IMUL32M(u32 from) {
+ write8(0xF7);
+ ModRM(0, 5, DISP32);
+ write32(from);
+}
+
+/* div eax by r32 to edx:eax */
+void DIV32R(int from) {
+ write8(0xF7);
+ ModRM(3, 6, from);
+}
+
+/* idiv eax by r32 to edx:eax */
+void IDIV32R(int from) {
+ write8(0xF7);
+ ModRM(3, 7, from);
+}
+
+/* div eax by m32 to edx:eax */
+void DIV32M(u32 from) {
+ write8(0xF7);
+ ModRM(0, 6, DISP32);
+ write32(from);
+}
+
+/* idiv eax by m32 to edx:eax */
+void IDIV32M(u32 from) {
+ write8(0xF7);
+ ModRM(0, 7, DISP32);
+ write32(from);
+}
+
+// shifting instructions
+
+/* shl imm8 to r32 */
+void SHL32ItoR(int to, unsigned char from) {
+ write8(0xC1);
+ ModRM(3, 4, to);
+ write8(from);
+}
+
+/* shl cl to r32 */
+void SHL32CLtoR(int to) {
+ write8(0xD3);
+ ModRM(3, 4, to);
+}
+
+/* shr imm8 to r32 */
+void SHR32ItoR(int to, unsigned char from) {
+ write8(0xC1);
+ ModRM(3, 5, to);
+ write8(from);
+}
+
+/* shr cl to r32 */
+void SHR32CLtoR(int to) {
+ write8(0xD3);
+ ModRM(3, 5, to);
+}
+
+/* sar imm8 to r32 */
+void SAR32ItoR(int to, unsigned char from) {
+ write8(0xC1);
+ ModRM(3, 7, to);
+ write8(from);
+}
+
+/* sar cl to r32 */
+void SAR32CLtoR(int to) {
+ write8(0xD3);
+ ModRM(3, 7, to);
+}
+
+
+// logical instructions
+
+/* or imm32 to r32 */
+void OR32ItoR(int to, u32 from) {
+ if (to == EAX) {
+ write8(0x0D);
+ } else {
+ write8(0x81);
+ ModRM(3, 1, to);
+ }
+ write32(from);
+}
+
+/* or imm32 to m32 */
+void OR32ItoM(u32 to, u32 from) {
+ write8(0x81);
+ ModRM(0, 1, DISP32);
+ write32(to);
+ write32(from);
+}
+
+/* or r32 to r32 */
+void OR32RtoR(int to, int from) {
+ write8(0x09);
+ ModRM(3, from, to);
+}
+
+/* or m32 to r32 */
+void OR32MtoR(int to, u32 from) {
+ write8(0x0B);
+ ModRM(0, to, DISP32);
+ write32(from);
+}
+
+/* xor imm32 to r32 */
+void XOR32ItoR(int to, u32 from) {
+ if (to == EAX) {
+ write8(0x35);
+ } else {
+ write8(0x81);
+ ModRM(3, 6, to);
+ }
+ write32(from);
+}
+
+/* xor imm32 to m32 */
+void XOR32ItoM(u32 to, u32 from) {
+ write8(0x81);
+ ModRM(0, 6, DISP32);
+ write32(to);
+ write32(from);
+}
+
+/* xor r32 to r32 */
+void XOR32RtoR(int to, int from) {
+ write8(0x31);
+ ModRM(3, from, to);
+}
+
+/* xor m32 to r32 */
+void XOR32MtoR(int to, u32 from) {
+ write8(0x33);
+ ModRM(0, to, DISP32);
+ write32(from);
+}
+
+/* and imm32 to r32 */
+void AND32ItoR(int to, u32 from) {
+ if (to == EAX) {
+ write8(0x25);
+ } else {
+ write8(0x81);
+ ModRM(3, 0x4, to);
+ }
+ write32(from);
+}
+
+/* and imm32 to m32 */
+void AND32ItoM(u32 to, u32 from) {
+ write8(0x81);
+ ModRM(0, 0x4, DISP32);
+ write32(to);
+ write32(from);
+}
+
+/* and r32 to r32 */
+void AND32RtoR(int to, int from) {
+ write8(0x21);
+ ModRM(3, from, to);
+}
+
+/* and m32 to r32 */
+void AND32MtoR(int to, u32 from) {
+ write8(0x23);
+ ModRM(0, to, DISP32);
+ write32(from);
+}
+
+/* not r32 */
+void NOT32R(int from) {
+ write8(0xF7);
+ ModRM(3, 2, from);
+}
+
+/* neg r32 */
+void NEG32R(int from) {
+ write8(0xF7);
+ ModRM(3, 3, from);
+}
+
+// jump instructions
+
+/* jmp rel8 */
+u8* JMP8(unsigned char to) {
+ write8(0xEB);
+ write8(to);
+ return x86Ptr - 1;
+}
+
+/* jmp rel32 */
+u32* JMP32(u32 to) {
+ write8(0xE9);
+ write32(to);
+ return (u32*)(x86Ptr - 4);
+}
+
+/* jmp r32 */
+void JMP32R(int to) {
+ write8(0xFF);
+ ModRM(3, 4, to);
+}
+
+/* je rel8 */
+u8* JE8(unsigned char to) {
+ J8Rel(0x74, to);
+}
+
+/* jz rel8 */
+u8* JZ8(unsigned char to) {
+ J8Rel(0x74, to);
+}
+
+/* jg rel8 */
+u8* JG8(unsigned char to) {
+ J8Rel(0x7F, to); }
+
+/* jge rel8 */
+u8* JGE8(unsigned char to) {
+ J8Rel(0x7D, to);
+}
+
+/* jl rel8 */
+u8* JL8(unsigned char to) {
+ J8Rel(0x7C, to);
+}
+
+/* jle rel8 */
+u8* JLE8(unsigned char to) {
+ J8Rel(0x7E, to);
+}
+
+/* jne rel8 */
+u8* JNE8(unsigned char to) {
+ J8Rel(0x75, to);
+}
+
+/* jnz rel8 */
+u8* JNZ8(unsigned char to) {
+ J8Rel(0x75, to);
+}
+
+/* jng rel8 */
+u8* JNG8(unsigned char to) {
+ J8Rel(0x7E, to);
+}
+
+/* jnge rel8 */
+u8* JNGE8(unsigned char to) {
+ J8Rel(0x7C, to);
+}
+
+/* jnl rel8 */
+u8* JNL8(unsigned char to) {
+ J8Rel(0x7D, to);
+}
+
+/* jnle rel8 */
+u8* JNLE8(unsigned char to) {
+ J8Rel(0x7F, to);
+}
+
+/* call func */
+void CALLFunc(u32 func) {
+ CALL32(func - ((u32)x86Ptr + 5));
+}
+
+/* call rel32 */
+void CALL32(u32 to) {
+ write8(0xE8);
+ write32(to);
+}
+
+/* call r32 */
+void CALL32R(int to) {
+ write8(0xFF);
+ ModRM(3, 2, to);
+}
+
+// misc instructions
+
+/* cmp imm32 to r32 */
+void CMP32ItoR(int to, u32 from) {
+ if (to == EAX) {
+ write8(0x3D);
+ } else {
+ write8(0x81);
+ ModRM(3, 7, to);
+ }
+ write32(from);
+}
+
+/* cmp imm32 to m32 */
+void CMP32ItoM(u32 to, u32 from) {
+ write8(0x81);
+ ModRM(0, 7, DISP32);
+ write32(to);
+ write32(from);
+}
+
+/* cmp r32 to r32 */
+void CMP32RtoR(int to, int from) {
+ write8(0x39);
+ ModRM(3, from, to);
+}
+
+/* cmp m32 to r32 */
+void CMP32MtoR(int to, u32 from) {
+ write8(0x3B);
+ ModRM(0, to, DISP32);
+ write32(from);
+}
+
+/* test imm32 to r32 */
+void TEST32ItoR(int to, u32 from) {
+ if (to == EAX) {
+ write8(0xA9);
+ } else {
+ write8(0xF7);
+ ModRM(3, 0, to);
+ }
+ write32(from);
+}
+
+/* test r32 to r32 */
+void TEST32RtoR(int to, int from) {
+ write8(0x85);
+ ModRM(3, from, to);
+}
+
+/* setl r8 */
+void SETL8R(int to) {
+ SET8R(0x9C, to);
+}
+
+/* setb r8 */
+void SETB8R(int to) {
+ SET8R(0x92, to);
+}
+
+/* cbw */
+void CBW() {
+ write16(0x9866);
+}
+
+/* cwd */
+void CWD() {
+ write8(0x98);
+}
+
+/* cdq */
+void CDQ() {
+ write8(0x99);
+}
+
+/* push r32 */
+void PUSH32R(int from) {
+ write8(0x50 | from);
+}
+
+/* push m32 */
+void PUSH32M(u32 from) {
+ write8(0xFF);
+ ModRM(0, 6, DISP32);
+ write32(from);
+}
+
+/* push imm32 */
+void PUSH32I(u32 from) {
+ write8(0x68); write32(from);
+}
+
+/* pop r32 */
+void POP32R(int from) {
+ write8(0x58 | from);
+}
+
+/* pushad */
+void PUSHA32() {
+ write8(0x60);
+}
+
+/* popad */
+void POPA32() {
+ write8(0x61);
+}
+
+/* ret */
+void RET() {
+ write8(0xC3);
+}
+
+/********************/
+/* FPU instructions */
+/********************/
+
+/* fild m32 to fpu reg stack */
+void FILD32(u32 from) {
+ write8(0xDB);
+ ModRM(0, 0x0, DISP32);
+ write32(from);
+}
+
+/* fistp m32 from fpu reg stack */
+void FISTP32(u32 from) {
+ write8(0xDB);
+ ModRM(0, 0x3, DISP32);
+ write32(from);
+}
+
+/* fld m32 to fpu reg stack */
+void FLD32(u32 from) {
+ write8(0xD9);
+ ModRM(0, 0x0, DISP32);
+ write32(from);
+}
+
+/* fstp m32 from fpu reg stack */
+void FSTP32(u32 to) {
+ write8(0xD9);
+ ModRM(0, 0x3, DISP32);
+ write32(to);
+}
+
+//
+
+/* fldcw fpu control word from m16 */
+void FLDCW(u32 from) {
+ write8(0xD9);
+ ModRM(0, 0x5, DISP32);
+ write32(from);
+}
+
+/* fnstcw fpu control word to m16 */
+void FNSTCW(u32 to) {
+ write8(0xD9);
+ ModRM(0, 0x7, DISP32);
+ write32(to);
+}
+
+//
+
+/* fadd m32 to fpu reg stack */
+void FADD32(u32 from) {
+ write8(0xD8);
+ ModRM(0, 0x0, DISP32);
+ write32(from);
+}
+
+/* fsub m32 to fpu reg stack */
+void FSUB32(u32 from) {
+ write8(0xD8);
+ ModRM(0, 0x4, DISP32);
+ write32(from);
+}
+
+/* fmul m32 to fpu reg stack */
+void FMUL32(u32 from) {
+ write8(0xD8);
+ ModRM(0, 0x1, DISP32);
+ write32(from);
+}
+
+/* fdiv m32 to fpu reg stack */
+void FDIV32(u32 from) {
+ write8(0xD8);
+ ModRM(0, 0x6, DISP32);
+ write32(from);
+}
+
+/* fabs fpu reg stack */
+void FABS() {
+ write16(0xE1D9);
+}
+
+/* fsqrt fpu reg stack */
+void FSQRT() {
+ write16(0xFAD9);
+}
+
+/* fchs fpu reg stack */
+void FCHS() {
+ write16(0xE0D9);
+}
+
+/********************/
+/* MMX instructions */
+/********************/
+
+// r64 = mm
+
+/* movq m64 to r64 */
+void MOVQMtoR(int to, u32 from) {
+ write16(0x6F0F);
+ ModRM(0, to, DISP32);
+ write32(from);
+}
+
+/* movq r64 to m64 */
+void MOVQRtoM(u32 to, int from) {
+ write16(0x7F0F);
+ ModRM(0, from, DISP32);
+ write32(to);
+}
+
+/* pand r64 to r64 */
+void PANDRtoR(int to, int from) {
+ write16(0xDB0F);
+ ModRM(3, to, from);
+}
+
+/* por r64 to r64 */
+void PORRtoR(int to, int from) {
+ write16(0xEB0F);
+ ModRM(3, to, from);
+}
+
+/* por m64 to r64 */
+void PORMtoR(int to, u32 from) {
+ write16(0xEB0F);
+ ModRM(0, to, DISP32);
+ write32(from);
+}
+
+/* pxor r64 to r64 */
+void PXORRtoR(int to, int from) {
+ write16(0xEF0F);
+ ModRM(3, to, from);
+}
+
+/* psllq r64 to r64 */
+void PSLLQRtoR(int to, int from) {
+ write16(0xF30F);
+ ModRM(3, to, from);
+}
+
+/* psllq m64 to r64 */
+void PSLLQMtoR(int to, u32 from) {
+ write16(0xF30F);
+ ModRM(0, to, DISP32);
+ write32(from);
+}
+
+/* psllq imm8 to r64 */
+void PSLLQItoR(int to, unsigned char from) {
+ write16(0x730F);
+ ModRM(3, 6, to);
+ write8(from);
+}
+
+/* psrlq r64 to r64 */
+void PSRLQRtoR(int to, int from) {
+ write16(0xD30F);
+ ModRM(3, to, from);
+}
+
+/* psrlq m64 to r64 */
+void PSRLQMtoR(int to, u32 from) {
+ write16(0xD30F);
+ ModRM(0, to, DISP32);
+ write32(from);
+}
+
+/* psrlq imm8 to r64 */
+void PSRLQItoR(int to, unsigned char from) {
+ write16(0x730F);
+ ModRM(3, 2, to);
+ write8(from);
+}
+
+/* paddusb r64 to r64 */
+void PADDUSBRtoR(int to, int from) {
+ write16(0xDC0F);
+ ModRM(3, to, from);
+}
+
+/* paddusb m64 to r64 */
+void PADDUSBMtoR(int to, u32 from) {
+ write16(0xDC0F);
+ ModRM(0, to, DISP32);
+ write32(from);
+}
+
+/* paddusw r64 to r64 */
+void PADDUSWRtoR(int to, int from) {
+ write16(0xDD0F);
+ ModRM(3, to, from);
+}
+
+/* paddusw m64 to r64 */
+void PADDUSWMtoR(int to, u32 from) {
+ write16(0xDD0F);
+ ModRM(0, to, DISP32);
+ write32(from);
+}
+
+/* paddb r64 to r64 */
+void PADDBRtoR(int to, int from) {
+ write16(0xFC0F);
+ ModRM(3, to, from);
+}
+
+/* paddb m64 to r64 */
+void PADDBMtoR(int to, u32 from) {
+ write16(0xFC0F);
+ ModRM(0, to, DISP32);
+ write32(from);
+}
+
+/* paddw r64 to r64 */
+void PADDWRtoR(int to, int from) {
+ write16(0xFD0F);
+ ModRM(3, to, from);
+}
+
+/* paddw m64 to r64 */
+void PADDWMtoR(int to, u32 from) {
+ write16(0xFD0F);
+ ModRM(0, to, DISP32);
+ write32(from);
+}
+
+/* paddd r64 to r64 */
+void PADDDRtoR(int to, int from) {
+ write16(0xFE0F);
+ ModRM(3, to, from);
+}
+
+/* paddd m64 to r64 */
+void PADDDMtoR(int to, u32 from) {
+ write16(0xFE0F);
+ ModRM(0, to, DISP32);
+ write32(from);
+}
+
+/* emms */
+void EMMS() {
+ write16(0x770F);
+}
diff --git a/PcsxSrc/ix86/ix86.h b/PcsxSrc/ix86/ix86.h
new file mode 100644
index 0000000..3f3d6cd
--- /dev/null
+++ b/PcsxSrc/ix86/ix86.h
@@ -0,0 +1,397 @@
+/*
+ * ix86 definitions.
+ * Author: linuzappz <linuzappz@pcsx.net>
+ */
+
+#ifndef __IX86_H__
+#define __IX86_H__
+
+// include basic types
+#include "PsxCommon.h"
+
+/* general defines */
+
+#define EAX 0
+#define EBX 3
+#define ECX 1
+#define EDX 2
+#define ESI 6
+#define EDI 7
+#define EBP 5
+#define ESP 4
+
+#define MM0 0
+#define MM1 1
+#define MM2 2
+#define MM3 3
+#define MM4 4
+#define MM5 5
+#define MM6 6
+#define MM7 7
+
+s8 *x86Ptr;
+u8 *j8Ptr[32];
+u32 *j32Ptr[32];
+
+void x86Init(char *ptr);
+void x86SetJ8(u8 *j8);
+void x86SetJ32(u32 *j32);
+void x86Shutdown();
+
+
+/********************/
+/* IX86 intructions */
+/********************/
+
+/*
+ * scale values:
+ * 0 - *1
+ * 1 - *2
+ * 2 - *4
+ * 3 - *8
+ */
+
+// mov instructions
+
+/* mov r32 to r32 */
+void MOV32RtoR(int to, int from);
+/* mov r32 to m32 */
+void MOV32RtoM(u32 to, int from);
+/* mov m32 to r32 */
+void MOV32MtoR(int to, u32 from);
+/* mov [r32] to r32 */
+void MOV32RmtoR(int to, int from);
+/* mov [r32][r32*scale] to r32 */
+void MOV32RmStoR(int to, int from, int from2, int scale);
+/* mov r32 to [r32] */
+void MOV32RtoRm(int to, int from);
+/* mov imm32 to r32 */
+void MOV32ItoR(int to, u32 from);
+/* mov imm32 to m32 */
+void MOV32ItoM(u32 to, u32 from);
+
+/* movsx r8 to r32 */
+void MOVSX32R8toR(int to, int from);
+/* movsx r16 to r32 */
+void MOVSX32R16toR(int to, int from);
+/* movzx r8 to r32 */
+void MOVZX32R8toR(int to, int from);
+/* movzx r16 to r32 */
+void MOVZX32R16toR(int to, int from);
+
+/* cmovne r32 to r32 */
+void CMOVNE32RtoR(int to, int from);
+/* cmovne m32 to r32*/
+void CMOVNE32MtoR(int to, u32 from);
+/* cmove r32 to r32*/
+void CMOVE32RtoR(int to, int from);
+/* cmove m32 to r32*/
+void CMOVE32MtoR(int to, u32 from);
+/* cmovg r32 to r32*/
+void CMOVG32RtoR(int to, int from);
+/* cmovg m32 to r32*/
+void CMOVG32MtoR(int to, u32 from);
+/* cmovge r32 to r32*/
+void CMOVGE32RtoR(int to, int from);
+/* cmovge m32 to r32*/
+void CMOVGE32MtoR(int to, u32 from);
+/* cmovl r32 to r32*/
+void CMOVL32RtoR(int to, int from);
+/* cmovl m32 to r32*/
+void CMOVL32MtoR(int to, u32 from);
+/* cmovle r32 to r32*/
+void CMOVLE32RtoR(int to, int from);
+/* cmovle m32 to r32*/
+void CMOVLE32MtoR(int to, u32 from);
+
+// arithmic instructions
+
+/* add imm32 to r32 */
+void ADD32ItoR(int to, u32 from);
+/* add imm32 to m32 */
+void ADD32ItoM(u32 to, u32 from);
+/* add r32 to r32 */
+void ADD32RtoR(int to, int from);
+/* add m32 to r32 */
+void ADD32MtoR(int to, u32 from);
+
+/* adc imm32 to r32 */
+void ADC32ItoR(int to, u32 from);
+/* adc r32 to r32 */
+void ADC32RtoR(int to, int from);
+/* adc m32 to r32 */
+void ADC32MtoR(int to, u32 from);
+
+/* sub imm32 to r32 */
+void SUB32ItoR(int to, u32 from);
+/* sub r32 to r32 */
+void SUB32RtoR(int to, int from);
+/* sub m32 to r32 */
+void SUB32MtoR(int to, u32 from);
+
+/* sbb imm32 to r32 */
+void SBB32ItoR(int to, u32 from);
+/* sbb r32 to r32 */
+void SBB32RtoR(int to, int from);
+/* sbb m32 to r32 */
+void SBB32MtoR(int to, u32 from);
+
+/* mul eax by r32 to edx:eax */
+void MUL32R(int from);
+/* mul eax by m32 to edx:eax */
+void MUL32M(u32 from);
+
+/* imul eax by r32 to edx:eax */
+void IMUL32R(int from);
+/* imul eax by m32 to edx:eax */
+void IMUL32M(u32 from);
+
+/* div eax by r32 to edx:eax */
+void DIV32R(int from);
+/* div eax by m32 to edx:eax */
+void DIV32M(u32 from);
+
+/* idiv eax by r32 to edx:eax */
+void IDIV32R(int from);
+/* idiv eax by m32 to edx:eax */
+void IDIV32M(u32 from);
+
+// shifting instructions
+
+/* shl imm8 to r32 */
+void SHL32ItoR(int to, unsigned char from);
+/* shl cl to r32 */
+void SHL32CLtoR(int to);
+
+/* shr imm8 to r32 */
+void SHR32ItoR(int to, unsigned char from);
+/* shr cl to r32 */
+void SHR32CLtoR(int to);
+
+/* sar imm8 to r32 */
+void SAR32ItoR(int to, unsigned char from);
+/* sar cl to r32 */
+void SAR32CLtoR(int to);
+
+/* sal imm8 to r32 */
+#define SAL32ItoR SHL32ItoR
+/* sal cl to r32 */
+#define SAL32CLtoR SHL32CLtoR
+
+// logical instructions
+
+/* or imm32 to r32 */
+void OR32ItoR(int to, u32 from);
+/* or imm32 to m32 */
+void OR32ItoM(u32 to, u32 from);
+/* or r32 to r32 */
+void OR32RtoR(int to, int from);
+/* or m32 to r32 */
+void OR32MtoR(int to, u32 from);
+
+/* xor imm32 to r32 */
+void XOR32ItoR(int to, u32 from);
+/* xor imm32 to m32 */
+void XOR32ItoM(u32 to, u32 from);
+/* xor r32 to r32 */
+void XOR32RtoR(int to, int from);
+/* xor m32 to r32 */
+void XOR32MtoR(int to, u32 from);
+
+/* and imm32 to r32 */
+void AND32ItoR(int to, u32 from);
+/* and imm32 to m32 */
+void AND32ItoM(u32 to, u32 from);
+/* and r32 to r32 */
+void AND32RtoR(int to, int from);
+/* and m32 to r32 */
+void AND32MtoR(int to, u32 from);
+
+/* not r32 */
+void NOT32R(int from);
+/* neg r32 */
+void NEG32R(int from);
+
+// jump instructions
+
+/* jmp rel8 */
+u8* JMP8(unsigned char to);
+/* jmp rel32 */
+u32* JMP32(u32 to);
+/* jmp r32 */
+void JMP32R(int to);
+
+/* je rel8 */
+u8* JE8(unsigned char to);
+/* jz rel8 */
+u8* JZ8(unsigned char to);
+/* jg rel8 */
+u8* JG8(unsigned char to);
+/* jge rel8 */
+u8* JGE8(unsigned char to);
+/* jl rel8 */
+u8* JL8(unsigned char to);
+/* jle rel8 */
+u8* JLE8(unsigned char to);
+/* jne rel8 */
+u8* JNE8(unsigned char to);
+/* jnz rel8 */
+u8* JNZ8(unsigned char to);
+/* jng rel8 */
+u8* JNG8(unsigned char to);
+/* jnge rel8 */
+u8* JNGE8(unsigned char to);
+/* jnl rel8 */
+u8* JNL8(unsigned char to);
+/* jnle rel8 */
+u8* JNLE8(unsigned char to);
+
+/* call func */
+void CALLFunc(u32 func); // based on CALL32
+/* call rel32 */
+void CALL32(u32 to);
+/* call r32 */
+void CALL32R(int to);
+
+// misc instructions
+
+/* cmp imm32 to r32 */
+void CMP32ItoR(int to, u32 from);
+/* cmp imm32 to m32 */
+void CMP32ItoM(u32 to, u32 from);
+/* cmp r32 to r32 */
+void CMP32RtoR(int to, int from);
+/* cmp m32 to r32 */
+void CMP32MtoR(int to, u32 from);
+
+/* test imm32 to r32 */
+void TEST32ItoR(int to, u32 from);
+/* test r32 to r32 */
+void TEST32RtoR(int to, int from);
+
+/* setl r8 */
+void SETL8R(int to);
+/* setb r8 */
+void SETB8R(int to);
+
+/* cbw */
+void CBW();
+/* cwd */
+void CWD();
+/* cdq */
+void CDQ();
+
+/* push r32 */
+void PUSH32R(int from);
+/* push m32 */
+void PUSH32M(u32 from);
+/* push imm32 */
+void PUSH32I(u32 from);
+
+/* pop r32 */
+void POP32R(int from);
+
+/* pushad */
+void PUSHA32();
+/* popad */
+void POPA32();
+
+/* ret */
+void RET();
+
+/********************/
+/* FPU instructions */
+/********************/
+
+/* fild m32 to fpu reg stack */
+void FILD32(u32 from);
+/* fistp m32 from fpu reg stack */
+void FISTP32(u32 from);
+/* fld m32 to fpu reg stack */
+void FLD32(u32 from);
+/* fstp m32 from fpu reg stack */
+void FSTP32(u32 to);
+
+/* fldcw fpu control word from m16 */
+void FLDCW(u32 from);
+/* fstcw fpu control word to m16 */
+void FNSTCW(u32 to);
+
+/* fadd m32 to fpu reg stack */
+void FADD32(u32 from);
+/* fsub m32 to fpu reg stack */
+void FSUB32(u32 from);
+/* fmul m32 to fpu reg stack */
+void FMUL32(u32 from);
+/* fdiv m32 to fpu reg stack */
+void FDIV32(u32 from);
+/* fabs fpu reg stack */
+void FABS();
+/* fsqrt fpu reg stack */
+void FSQRT();
+/* fchs fpu reg stack */
+void FCHS();
+
+/********************/
+/* MMX instructions */
+/********************/
+
+// r64 = mm
+
+/* movq m64 to r64 */
+void MOVQMtoR(int to, u32 from);
+/* movq r64 to m64 */
+void MOVQRtoM(u32 to, int from);
+
+/* pand r64 to r64 */
+void PANDRtoR(int to, int from);
+
+/* por r64 to r64 */
+void PORRtoR(int to, int from);
+/* por m64 to r64 */
+void PORMtoR(int to, u32 from);
+
+/* pxor r64 to r64 */
+void PXORRtoR(int to, int from);
+
+/* psllq r64 to r64 */
+void PSLLQRtoR(int to, int from);
+/* psllq m64 to r64 */
+void PSLLQMtoR(int to, u32 from);
+/* psllq imm8 to r64 */
+void PSLLQItoR(int to, unsigned char from);
+
+/* psrlq r64 to r64 */
+void PSRLQRtoR(int to, int from);
+/* psrlq m64 to r64 */
+void PSRLQMtoR(int to, u32 from);
+/* psrlq imm8 to r64 */
+void PSRLQItoR(int to, unsigned char from);
+
+/* paddusb r64 to r64 */
+void PADDUSBRtoR(int to, int from);
+/* paddusb m64 to r64 */
+void PADDUSBMtoR(int to, u32 from);
+/* paddusw r64 to r64 */
+void PADDUSWRtoR(int to, int from);
+/* paddusw m64 to r64 */
+void PADDUSWMtoR(int to, u32 from);
+
+/* paddb r64 to r64 */
+void PADDBRtoR(int to, int from);
+/* paddb m64 to r64 */
+void PADDBMtoR(int to, u32 from);
+/* paddw r64 to r64 */
+void PADDWRtoR(int to, int from);
+/* paddw m64 to r64 */
+void PADDWMtoR(int to, u32 from);
+/* paddd r64 to r64 */
+void PADDDRtoR(int to, int from);
+/* paddd m64 to r64 */
+void PADDDMtoR(int to, u32 from);
+
+/* emms */
+void EMMS();
+
+
+#endif /* __IX86_H__ */