//\r
// for x86-32bit\r
//\r
-\r
-void jitCompPutImm32(struct JitCompWork *w, int i)\r
-{\r
- jitCompPutByte1(w->dst, i & 0xff);\r
- jitCompPutByte1(w->dst, (i >> 8) & 0xff);\r
- jitCompPutByte1(w->dst, (i >> 16) & 0xff);\r
- jitCompPutByte1(w->dst, (i >> 24) & 0xff);\r
- return;\r
-}\r
-\r
int jitCompGetImm32(const unsigned char *src)\r
{\r
return (src[0] << 24) | (src[1] << 16) | (src[2] << 8) | src[3];\r
} else {\r
// 10 + reg + 101 + disp\r
jitCompPutByte1(w->dst, 0x85 | (n << 3));\r
- jitCompPutImm32(w, disp);\r
+ jitCompPutImm32(w->dst, disp);\r
}\r
return;\r
}\r
#if (jitCompA0001_USE_R3F_IMM32 != 0)\r
if (rxx == 0x3f) {\r
jitCompPutByte1(w->dst, 0xb8); /* MOV(EAX, ?); */\r
- jitCompPutImm32(w, w->r3f);\r
+ jitCompPutImm32(w->dst, w->r3f);\r
return;\r
}\r
#endif\r
jitCompA0001_movReg32EbpDisp(w, 0 /* EAX */, 256 + pxx * 32 + 4); /* MOV(EAX, [EBP+?]); */ /* typ */\r
jitCompPutByte3(w->dst, 0x83, 0xf8, typ & 0x7f); /* CMP(EAX, ?); */\r
jitCompPutByte2(w->dst, 0x0f, 0x85); /* JNE */\r
- jitCompPutImm32(w, errfnc - (w->dst + 4));\r
+ jitCompPutImm32(w->dst, errfnc - (w->dst + 4));\r
return;\r
}\r
\r
jitCompPutByte1(w->dst, 0x3b); /* CMP(reg, [EBP+?]); */\r
jitCompA0001_85DispN(w, 256 + pxx * 32 + 8, reg); /* p0 */\r
jitCompPutByte2(w->dst, 0x0f, 0x82); /* JB */\r
- jitCompPutImm32(w, errfnc - (w->dst + 4));\r
+ jitCompPutImm32(w->dst, errfnc - (w->dst + 4));\r
jitCompPutByte1(w->dst, 0x3b); /* CMP(reg, [EBP+?]); */\r
jitCompA0001_85DispN(w, 256 + pxx * 32 + 12, reg); /* p1 */\r
jitCompPutByte2(w->dst, 0x0f, 0x83); /* JAE */\r
- jitCompPutImm32(w, errfnc - (w->dst + 4));\r
+ jitCompPutImm32(w->dst, errfnc - (w->dst + 4));\r
return;\r
}\r
\r
jitCompA0001_movEbpDispReg32(&w, envOffset_DBGINFO0, IA32_REG0_EAX);\r
// MOV(EAX, ?);\r
jitCompPutByte1(w.dst, 0xb8); /* MOV(EAX, imm32); */\r
- jitCompPutImm32(&w, debugInfo1);\r
+ jitCompPutImm32(w.dst, debugInfo1);\r
jitCompA0001_movEbpDispReg32(&w, envOffset_DBGINFO1, IA32_REG0_EAX); /* MOV(debugInfo1, EAX); */\r
}\r
while (src < src1) {\r
// LB命令の後に0x3C命令・・・beginFunc()\r
jitCompPutByte1(w.dst, 0xe9); // (x86) JMP rel32 : 次の命令との相対オフセットだけ相対ニアジャンプする\r
enter0 = w.dst;\r
- jitCompPutImm32(&w, 0); // 飛び相対座標が0 ・・・パイプラインのフラッシュ??\r
+ jitCompPutImm32(w.dst, 0); // 飛び相対座標が0 ・・・パイプラインのフラッシュ??\r
}\r
if (src[6] == 0x34) { // LBの次の命令がDATA ・・・DAT_SA0(label, typ32, length) ・・・メモリ確保命令\r
tmp_ucp = w.dst;\r
}\r
j *= jitCompGetImm32(&src[11]);\r
if (j <= 0) w.err = JITC_ERR_BADTYPE;\r
- jitCompPutImm32(&w, j);\r
+ jitCompPutImm32(w.dst, j);\r
#if (jitCompA0001_OPTIMIZE_JMP != 0)\r
if (j <= 127 - jitCompA0001_OPTIMIZE_ALIGN) {\r
w.dst -= 5;\r
if (i == 2) { jitCompPutByte2(w.dst, 0x89, 0xc0); j += i; } /* MOV(EAX, EAX); */\r
if (i == 3) { jitCompPutByte3(w.dst, 0x8d, 0x76, 0x00); j += i; } /* LEA(ESI, [ESI+0]); */\r
if (i == 4) { jitCompPutByte4(w.dst, 0x8d, 0x74, 0x26, 0x00); j += i; } /* LEA(ESI, [ESI*1+0]); */\r
- if (i == 5) { jitCompPutByte1(w.dst, 0x0d); jitCompPutImm32(&w, 0); j += i; } /* OR(EAX, 0); */\r
- if (i == 6) { jitCompPutByte2(w.dst, 0x8d, 0xb6); jitCompPutImm32(&w, 0); j += i; } /* LEA(ESI, [ESI+0]); */\r
- if (i >= 7) { jitCompPutByte3(w.dst, 0x8d, 0xb4, 0x26); jitCompPutImm32(&w, 0); j += 7; } /* LEA(ESI, [ESI*1+0]); */\r
+ if (i == 5) { jitCompPutByte1(w.dst, 0x0d); jitCompPutImm32(w.dst, 0); j += i; } /* OR(EAX, 0); */\r
+ if (i == 6) { jitCompPutByte2(w.dst, 0x8d, 0xb6); jitCompPutImm32(w.dst, 0); j += i; } /* LEA(ESI, [ESI+0]); */\r
+ if (i >= 7) { jitCompPutByte3(w.dst, 0x8d, 0xb4, 0x26); jitCompPutImm32(w.dst, 0); j += 7; } /* LEA(ESI, [ESI*1+0]); */\r
}\r
#endif\r
if (src[6] == 0x34) {\r
\r
/* reg0 のレジスタに対応したMOV命令を発行 */\r
jitCompPutByte1(w.dst, 0xb8 | reg0); /* MOV(reg0, ?); == 10111000b+wr imm32 */\r
- jitCompPutImm32(&w, i);\r
+ jitCompPutImm32(w.dst, i);\r
\r
if (reg0 == 0) // R03以降の、レジスタの内容をメモリ上に格納してエミュレートする場合\r
\r
j = 0;\r
if ((flags & JITC_PHASE1) != 0 || (((flags & JITC_PHASE1) == 0) && label[i].opt != 0)) // label番号iが確保されていれば (このif文は意味をなさない)\r
j = label[i].p - (w.dst + 4); // j はとび先の相対番地\r
- jitCompPutImm32(&w, j); // JMP もしくは JZ 命令のアドレス部を記述\r
+ jitCompPutImm32(w.dst, j); // JMP もしくは JZ 命令のアドレス部を記述\r
#if (jitCompA0001_OPTIMIZE_JMP != 0)\r
if (-128 - 3 <= j && j < 0) {\r
if (w.dst[-5] == 0xe9) {\r
// 代入先が P01, P02なら ESI, EDI,それ以外ならEAXを指定\r
reg0 = jitCompA000_selectPRegCache(src[1], IA32_REG0_EAX);\r
jitCompPutByte1(w.dst, 0xb8 | reg0); /* MOV(reg0, ?); */\r
- jitCompPutImm32(&w, (int)label[i].p); // ラベルのパスを各レジスタに代入\r
+ jitCompPutImm32(w.dst, (int)label[i].p); // ラベルのパスを各レジスタに代入\r
\r
// レジスタへの代入をメモリでエミュレーションする場合は、スタックに積む。\r
if (reg0 == 0)\r
if (level < JITC_LV_FASTEST) {\r
jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + 8, reg0); /* MOV([EBP+?], reg0); */ /* p0 */\r
jitCompPutByte1(w.dst, 0xb8); /* MOV(EAX, ?); */\r
- jitCompPutImm32(&w, label[i].typ);\r
+ jitCompPutImm32(w.dst, label[i].typ);\r
jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + 4, IA32_REG0_EAX); /* MOV([EBP+?], EAX); */ /* typ */\r
jitCompPutByte1(w.dst, 0xb8); /* MOV(EAX, ?); */\r
- jitCompPutImm32(&w, (int)label[i].p1);\r
+ jitCompPutImm32(w.dst, (int)label[i].p1);\r
jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + 12, IA32_REG0_EAX); /* MOV([EBP+?], EAX); */ /* p1 */\r
jitCompPutByte2(w.dst, 0x31, 0xc0); /* XOR(EAX, EAX); */\r
jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + 16, IA32_REG0_EAX); /* MOV([EBP+?], EAX); */ /* liveSign */\r
else {\r
jitCompPutByte2(w.dst, 0xf7, 0xc0 | reg0); /* TEST(reg0,1); */\r
}\r
- jitCompPutImm32(&w, 1);\r
+ jitCompPutImm32(w.dst, 1);\r
\r
/* JZ命令を発行 */\r
jitCompPutByte2(w.dst, 0x74, 0x00); /* JZ($+2) */\r
else {\r
jitCompPutByte2(w.dst, 0x81, 0xc0 | reg0); /* ADD(reg0, ?); */\r
}\r
- jitCompPutImm32(&w, j);\r
+ jitCompPutImm32(w.dst, j);\r
goto padd1;\r
}\r
#endif\r
if (reg2 >= 0)\r
jitCompA000_storeRegCacheAll(&w);\r
jitCompPutByte1(w.dst, 0xb8 | reg0); /* MOV(reg0, ?); */\r
- jitCompPutImm32(&w, w.r3f);\r
+ jitCompPutImm32(w.dst, w.r3f);\r
jitCompPutByte1(w.dst, 0x2b);\r
jitCompA0001_85DispN(&w, src[3] * 4, reg0);\r
if (reg0 == 0)\r
jitCompPutByte2(w.dst, 0x69, 0xc0 | reg0 << 3 | reg0);\r
}\r
}\r
- jitCompPutImm32(&w, w.r3f);\r
+ jitCompPutImm32(w.dst, w.r3f);\r
if (reg0 == 0)\r
jitCompA0001_movRxxEax(&w, src[1]);\r
break;\r
#if (jitCompA0001_USE_R3F_IMM32 != 0)\r
if (src[2] == 0x3f) {\r
jitCompPutByte1(w.dst, 0xb8); /* MOV(EAX, ?); */\r
- jitCompPutImm32(&w, w.r3f);\r
+ jitCompPutImm32(w.dst, w.r3f);\r
}\r
else {\r
jitCompA0001_movEaxRxx(&w, src[2]);\r
#if (jitCompA0001_USE_R3F_IMM32 != 0)\r
if (src[3] == 0x3f) {\r
jitCompPutByte1(w.dst, 0xb8 | 1); /* MOV(ECX, ?); */\r
- jitCompPutImm32(&w, w.r3f);\r
+ jitCompPutImm32(w.dst, w.r3f);\r
}\r
else {\r
jitCompA0001_movReg32EbpDisp(&w, IA32_REG1_ECX, src[3] * 4); /* MOV(ECX, [EBP+?]); */\r
}\r
if (src[2] == 0x3f) {\r
jitCompPutByte1(w.dst, 0xb8 | 0); /* MOV(EAX, ?); */\r
- jitCompPutImm32(&w, w.r3f);\r
+ jitCompPutImm32(w.dst, w.r3f);\r
}\r
else {\r
jitCompA0001_movReg32EbpDisp(&w, IA32_REG0_EAX, src[2] * 4); /* MOV(EAX, [EBP+?]); */\r
jitCompA0001_movReg32EbpDisp(&w, 0 /* EAX */, 256 + src[2] * 32 + 4); /* MOV(EAX, [EBP+?]); */ /* typ */\r
jitCompPutByte3(w.dst, 0x83, 0xf8, 0); /* CMP(EAX, 0); */\r
jitCompPutByte2(w.dst, 0x0f, 0x85); /* JNE */\r
- jitCompPutImm32(&w, errfnc - (w.dst + 4));\r
+ jitCompPutImm32(w.dst, errfnc - (w.dst + 4));\r
/* セキュリティチェックが足りてない!(aliveとか) */\r
}\r
reg0 = IA32_REG0_EAX;\r
jitCompPutByte1(w.dst, 0x3b); /* CMP(reg0, [EBP+?]); */\r
jitCompA0001_85DispN(&w, 256 + src[2] * 32 + 8, reg0); /* p0 */\r
jitCompPutByte2(w.dst, 0x0f, 0x85); /* JNE */\r
- jitCompPutImm32(&w, errfnc - (w.dst + 4));\r
+ jitCompPutImm32(w.dst, errfnc - (w.dst + 4));\r
}\r
jitCompPutByte2(w.dst, 0xff, 0xe0); /* JMP(EAX); */\r
}\r
jitCompA0001_movReg32EbpDisp(&w, IA32_REG0_EAX, 256 + src[6] * 32 + i); /* MOV(EAX, [EBP+?]); */\r
if (i == 4) {\r
jitCompPutByte1(w.dst, 0x0d); /* OR(EAX, ?); */\r
- jitCompPutImm32(&w, 0x80000000);\r
+ jitCompPutImm32(w.dst, 0x80000000);\r
}\r
jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + i, IA32_REG0_EAX); /* MOV([EBP+?], EAX); */\r
}\r
jitCompPutByte1(w.dst, 0xb8); /* MOV(EAX, ?); */\r
- jitCompPutImm32(&w, debugInfo1);\r
+ jitCompPutImm32(w.dst, debugInfo1);\r
jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + 28, IA32_REG0_EAX); /* MOV([EBP+?], EAX); */\r
jitCompA000_loadPRegCacheAll(&w); // 手抜き.\r
cmp0reg = -1;\r
jitCompA0001_movReg32EbpDisp(&w, 0 /* EAX */, 256 + src[6] * 32 + i); /* MOV(EAX, [EBP+?]); */\r
if (i == 4) {\r
jitCompPutByte1(w.dst, 0x25); /* AND(EAX, ?); */\r
- jitCompPutImm32(&w, 0x7fffffff);\r
+ jitCompPutImm32(w.dst, 0x7fffffff);\r
}\r
jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + i, IA32_REG0_EAX); /* MOV([EBP+?], EAX); */\r
}\r
if (level < JITC_LV_FASTER) {\r
jitCompA0001_movReg32EbpDisp(&w, IA32_REG0_EAX, 256 + src[6] * 32 + 28); /* MOV(EAX, [EBP+?]); */\r
jitCompPutByte1(w.dst, 0x3d); /* CMP(EAX, ?); */\r
- jitCompPutImm32(&w, debugInfo1);\r
+ jitCompPutImm32(w.dst, debugInfo1);\r
jitCompPutByte2(w.dst, 0x74, 8); /* JE */\r
jitCompPutByte2(w.dst, 0x31, 0xc0); /* XOR(EAX, EAX); (2) */\r
jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + 0, IA32_REG0_EAX); /* MOV([EBP+?], EAX); (1+1+4) */\r
if (*src <= 0x25) { jitCompPutByte2(w.dst, 0x81, 0xf8 | reg0); }\r
if (*src >= 0x26) { jitCompPutByte2(w.dst, 0xf7, 0xc0 | reg0); }\r
}\r
- jitCompPutImm32(&w, w.r3f);\r
+ jitCompPutImm32(w.dst, w.r3f);\r
goto cmpcc1;\r
}\r
#endif\r
j = 0;\r
if ((flags & JITC_PHASE1) != 0 || (((flags & JITC_PHASE1) == 0) && label[i].opt != 0))\r
j = label[i].p - (w.dst + 4);\r
- jitCompPutImm32(&w, j);\r
+ jitCompPutImm32(w.dst, j);\r
#if (jitCompA0001_OPTIMIZE_JMP != 0)\r
if (-128 - 4 <= j && j < 0) {\r
j += 4;\r
if (*src == 0x31) j = ((unsigned char *)&funcf5) - (w.dst + 4);\r
if (*src == 0x32) j = ((unsigned char *)&funcf6) - (w.dst + 4);\r
if (*src == 0x33) j = ((unsigned char *)&funcf7) - (w.dst + 4);\r
- jitCompPutImm32(&w, j);\r
+ jitCompPutImm32(w.dst, j);\r
jitCompPutByte3(w.dst, 0x83, 0xc4, 0x10); /* ADD(ESP,16); */\r
jitCompA000_loadRegCacheAll(&w); // 手抜き.\r
jitCompA000_loadPRegCacheAll(&w); // 手抜き.\r
if ((flags & JITC_PHASE1) != 0 && w.err == 0) {\r
if (label[i].opt == 0) { w.err = JITC_ERR_LABELNODEF; goto err_w; }\r
}\r
- jitCompPutImm32(&w, (int)label[i].p);\r
- jitCompPutImm32(&w, label[i].typ);\r
- jitCompPutImm32(&w, (int)label[i].p);\r
- jitCompPutImm32(&w, (int)label[i].p1);\r
- jitCompPutImm32(&w, 0); /* liveSign */\r
- jitCompPutImm32(&w, 2320); /* pls */\r
- jitCompPutImm32(&w, 0);\r
- jitCompPutImm32(&w, 0);\r
+ jitCompPutImm32(w.dst, (int)label[i].p);\r
+ jitCompPutImm32(w.dst, label[i].typ);\r
+ jitCompPutImm32(w.dst, (int)label[i].p);\r
+ jitCompPutImm32(w.dst, (int)label[i].p1);\r
+ jitCompPutImm32(w.dst, 0); /* liveSign */\r
+ jitCompPutImm32(w.dst, 2320); /* pls */\r
+ jitCompPutImm32(w.dst, 0);\r
+ jitCompPutImm32(w.dst, 0);\r
j--;\r
}\r
}\r
jitCompPutByte1(w.dst, 0x55); /* PUSH(EBP); */\r
jitCompPutByte1(w.dst, 0xe8);\r
j = ((unsigned char *)&func3c) - (w.dst + 4);\r
- jitCompPutImm32(&w, j);\r
+ jitCompPutImm32(w.dst, j);\r
jitCompPutByte3(w.dst, 0x83, 0xc4, 0x20); /* ADD(ESP,32); */\r
jitCompA000_loadRegCacheAll(&w); // 手抜き.\r
jitCompA000_loadPRegCacheAll(&w); // 手抜き.\r
jitCompPutByte1(w.dst, 0x55); /* PUSH(EBP); */\r
jitCompPutByte1(w.dst, 0xe8);\r
j = ((unsigned char *)&func3d) - (w.dst + 4);\r
- jitCompPutImm32(&w, j);\r
+ jitCompPutImm32(w.dst, j);\r
jitCompPutByte3(w.dst, 0x83, 0xc4, 0x20); /* ADD(ESP,32); */\r
jitCompA000_loadRegCacheAll(&w); // 手抜き.\r
jitCompA000_loadPRegCacheAll(&w); // 手抜き.\r
if (src[1] == 0x01 && src[2] == 0x00) { // DBGINFO1\r
if (level <= JITC_LV_SLOWER) {\r
jitCompPutByte1(w.dst, 0xb8); /* MOV(EAX, ?); */\r
- jitCompPutImm32(&w, debugInfo1);\r
+ jitCompPutImm32(w.dst, debugInfo1);\r
jitCompA0001_movEbpDispReg32(&w, 2304 + 4, IA32_REG0_EAX); /* MOV(debugInfo1, EAX); */\r
}\r
}\r
if (src[1] == 0x01 && src[2] == 0x03) { // DBGINFO1CLR\r
if (level <= JITC_LV_SLOWER) {\r
jitCompPutByte1(w.dst, 0xb8); /* MOV(EAX, ?); */\r
- jitCompPutImm32(&w, -1);\r
+ jitCompPutImm32(w.dst, -1);\r
jitCompA0001_movEbpDispReg32(&w, 2304 + 4, IA32_REG0_EAX); /* MOV(debugInfo1, EAX); */\r
}\r
}\r
// jitCompPutByte1(w.dst, 0xbf); /* MOV(EDI, ?); */\r
// jitCompPutImm32(&w, debugInfo0);\r
jitCompPutByte1(w.dst, 0xb8); /* MOV(EAX, ?); */\r
- jitCompPutImm32(&w, debugInfo0);\r
+ jitCompPutImm32(w.dst, debugInfo0);\r
jitCompA0001_movEbpDispReg32(&w, 2304 + 0, IA32_REG0_EAX); /* MOV(debugInfo0, EAX); */\r
}\r
}\r
w.dst = dst;\r
jitCompA000_storeRegCacheAll(&w);\r
jitCompA000_storePRegCacheAll(&w);\r
- jitCompPutByte1(w.dst, 0x60); /* PUSHAD(); */\r
- jitCompPutByte1(w.dst, 0x50); /* PUSH(EAX); */ /* for 16byte-align(win32では不要なのだけど、MacOSには必要らしい) */\r
- jitCompPutByte1(w.dst, 0x55); /* PUSH(EBP); */\r
+ jitCompPutOp_PUSHAD(w.dst);\r
+ jitCompPutOp_PUSH_GReg(w.dst, IA32_REG0_EAX); /* for 16Byte-align(Mac OSX) */\r
+ jitCompPutOp_PUSH_GReg(w.dst, IA32_REG5_EBP); /* PUSH(EBP); */\r
jitCompPutByte1(w.dst, 0xe8); /* CALL(func); */\r
int j = ((unsigned char *)func) - (w.dst + 4);\r
\r
//この関数の中では結局w->dstしか参照していない\r
- jitCompPutImm32(&w, j);\r
+ jitCompPutImm32(w.dst, j);\r
\r
- jitCompPutByte1(w.dst, 0x58); /* POP(EAX); */ /* (win32では不要なのだけど、MacOSには必要らしい) */\r
- jitCompPutByte1(w.dst, 0x58); /* POP(EAX); */\r
- jitCompPutByte1(w.dst, 0x61); /* POPAD(); */\r
+ jitCompPutOp_POP_GReg(w.dst, IA32_REG0_EAX); /* for 16Byte-align (Mac OSX) */\r
+ jitCompPutOp_POP_GReg(w.dst, IA32_REG0_EAX);\r
+ jitCompPutOp_POPAD(w.dst);\r
jitCompA000_loadRegCacheAll(&w);\r
jitCompA000_loadPRegCacheAll(&w);\r
jitCompA0001_movReg32EbpDisp(&w, IA32_REG0_EAX, 256 + 0x30 * 32 + 0); /* MOV(EAX, [EBP+?]); */\r