From 4290c48188d4ccb377996de3c585471fb171e9d9 Mon Sep 17 00:00:00 2001 From: ttwilb Date: Wed, 12 Mar 2014 18:20:29 +0900 Subject: [PATCH] =?utf8?q?Visual=20Studio=E3=81=A7=E3=82=B3=E3=83=B3?= =?utf8?q?=E3=83=91=E3=82=A4=E3=83=AB=E3=81=8C=E9=80=9A=E3=82=8B=E3=82=88?= =?utf8?q?=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- comlib.c | 2 +- dpndenv.c | 2 +- fontdata.c | 2 +- function.c | 2 +- jitc.c | 2260 ++++++++++++++++++++++++++++++------------------------------ main.c | 2 +- osecpu.h | 2 +- randmt.c | 2 +- screen.c | 2 +- 9 files changed, 1138 insertions(+), 1138 deletions(-) diff --git a/comlib.c b/comlib.c index 4501c74..f4785b8 100644 --- a/comlib.c +++ b/comlib.c @@ -1,4 +1,4 @@ -#include "osecpu.h" +#include "osecpu.h" struct ComLib_Str { const unsigned char *p; diff --git a/dpndenv.c b/dpndenv.c index 39a50d1..168bfd1 100644 --- a/dpndenv.c +++ b/dpndenv.c @@ -1,4 +1,4 @@ -#include "osecpu.h" +#include "osecpu.h" #if (DRV_OSNUM == 0x0002) diff --git a/fontdata.c b/fontdata.c index 2a3c559..8d2c2e4 100644 --- a/fontdata.c +++ b/fontdata.c @@ -1,4 +1,4 @@ - + unsigned char fontdata[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, diff --git a/function.c b/function.c index c5ddf68..25039bd 100644 --- a/function.c +++ b/function.c @@ -1,4 +1,4 @@ -#include "osecpu.h" +#include "osecpu.h" extern unsigned char fontdata[]; // @fontdata.c diff --git a/jitc.c b/jitc.c index a3f6a35..5707143 100644 --- a/jitc.c +++ b/jitc.c @@ -29,47 +29,47 @@ void errorHandler(HOSECPU_RuntimeEnvironment *r) int jitCompCmdLen(const unsigned char *src) { - //BCode命令長を取得する + //BCode命令長を取得する int i = 1; - - if (0x01 <= *src && *src < 0x04){ - // LB, LIMM, PLIMM - i = 6; - } else if (*src == 0x04){ - // CND - i = 2; - } else if (0x08 <= *src && *src < 0x0d){ - // LMEM, SMEM, ??, ??, ?? - i = 8 + src[7] * 4; - } else if (0x0e <= *src && *src < 0x10){ - // PADD, PDIF - i = 8; - } else if (0x10 <= *src && *src < 0x1c){ - // CP/OR, XOR, AND, ADD, SUB, MUL, SHL, SAR, DIV, MOD, - i = 4; - } else if (0x1c <= *src && *src < 0x1f){ - // ??, ??, PCP - i = 3; - } else if (*src == 0x1f){ - // ?? - i = 11; - } else if(0x20 <= *src && *src < 0x2e){ - // CMPE, CMPNE, CMPL, CMPGE, CMPLE, CMPG, TSTZ, TSTNZ, - // PCMPE, PCMPNE, PCMPL, PCMPGE, PCMPLE, PCMPG, - i = 4; - } else if (*src == 0x2f){ - // ?? - i = 4 + src[1]; - } else if (0x30 <= *src && *src < 0x34){ - // ??, ??, MALLOC, ?? - i = 4; - } else if (0x3c <= *src && *src < 0x3e){ - // ??, ?? - i = 7; - } else if (*src == 0xfe){ - // REMARK - i = 2 + src[1]; - } + + if (0x01 <= *src && *src < 0x04){ + // LB, LIMM, PLIMM + i = 6; + } else if (*src == 0x04){ + // CND + i = 2; + } else if (0x08 <= *src && *src < 0x0d){ + // LMEM, SMEM, ??, ??, ?? + i = 8 + src[7] * 4; + } else if (0x0e <= *src && *src < 0x10){ + // PADD, PDIF + i = 8; + } else if (0x10 <= *src && *src < 0x1c){ + // CP/OR, XOR, AND, ADD, SUB, MUL, SHL, SAR, DIV, MOD, + i = 4; + } else if (0x1c <= *src && *src < 0x1f){ + // ??, ??, PCP + i = 3; + } else if (*src == 0x1f){ + // ?? + i = 11; + } else if(0x20 <= *src && *src < 0x2e){ + // CMPE, CMPNE, CMPL, CMPGE, CMPLE, CMPG, TSTZ, TSTNZ, + // PCMPE, PCMPNE, PCMPL, PCMPGE, PCMPLE, PCMPG, + i = 4; + } else if (*src == 0x2f){ + // ?? + i = 4 + src[1]; + } else if (0x30 <= *src && *src < 0x34){ + // ??, ??, MALLOC, ?? + i = 4; + } else if (0x3c <= *src && *src < 0x3e){ + // ??, ?? + i = 7; + } else if (*src == 0xfe){ + // REMARK + i = 2 + src[1]; + } return i; } @@ -133,7 +133,7 @@ void jitCompA0001_85DispN(struct JitCompWork *w, int disp, int n) disp -= jitCompA0001_EBP128; if (-128 <= disp && disp <= 127) { jitCompPutByte2(w->dst, 0x45 | (n << 3), disp & 0xff); - } else { + } else { jitCompPutByte1(w->dst, 0x85 | (n << 3)); jitCompPutImm32(w, disp); } @@ -164,8 +164,8 @@ void jitCompA0001_movEaxRxx(struct JitCompWork *w, int rxx) } #endif if (rxx >= 0x40 || rxx < 0){ - w->err = JITC_ERR_REGNUM; - } + w->err = JITC_ERR_REGNUM; + } jitCompA0001_movReg32EbpDisp(w, 0 /* EAX */, rxx * 4); /* MOV(EAX, [EBP+?]); */ return; } @@ -173,8 +173,8 @@ void jitCompA0001_movEaxRxx(struct JitCompWork *w, int rxx) void jitCompA0001_movRxxEax(struct JitCompWork *w, int rxx) { if (rxx >= 0x40 || rxx < 0){ - w->err = JITC_ERR_REGNUM; - } + w->err = JITC_ERR_REGNUM; + } jitCompA0001_movEbpDispReg32(w, rxx * 4, 0 /* EAX */); /* MOV([EBP+?], EAX); */ return; } @@ -183,8 +183,8 @@ void jitCompA0001_fixPrefix(struct JitCompWork *w) { if (w->prefix != 0) { if (w->dst - w->dst0 > 127){ - w->err = JITC_ERR_REGNUM; - } + w->err = JITC_ERR_REGNUM; + } w->dst0[-1] = (unsigned char)((w->dst - w->dst0) & 0xff); } return; @@ -193,11 +193,11 @@ void jitCompA0001_fixPrefix(struct JitCompWork *w) void jitCompA0001_checkCompPtr(struct JitCompWork *w, int p0, int p1) { if (p0 >= 0x3f || p0 < 0){ - w->err = JITC_ERR_PREGNUM; - } + w->err = JITC_ERR_PREGNUM; + } if (p1 >= 0x3f || p1 < 0){ - w->err = JITC_ERR_PREGNUM; - } + w->err = JITC_ERR_PREGNUM; + } /* 比較可能可能なのかのチェックのコードを出力 */ /* 未完成 */ return; } @@ -244,21 +244,21 @@ void jitCompA000_storeRegCacheEdx(struct JitCompWork *w) int jitCompA000_selectRegCache(int rxx, int reg) { - switch (rxx) { - case 0: - //EBX - reg = 3; - break; - case 1: - //ECX - reg = 1; - break; - case 2: - //EDX - reg = 2; - break; - } - return reg; + switch (rxx) { + case 0: + //EBX + reg = 3; + break; + case 1: + //ECX + reg = 1; + break; + case 2: + //EDX + reg = 2; + break; + } + return reg; } void jitCompA000_loadPRegCacheAll(struct JitCompWork *w) @@ -280,33 +280,33 @@ void jitCompA000_storePRegCacheAll(struct JitCompWork *w) int jitCompA000_selectPRegCache(int pxx, int reg) { // if (pxx == 0) reg = 5; /* EBP */ - switch (pxx) { - case 1: - //ESI - reg = 6; - break; - - case 2: - //EDI - reg = 7; - break; - } - return reg; + switch (pxx) { + case 1: + //ESI + reg = 6; + break; + + case 2: + //EDI + reg = 7; + break; + } + return reg; } int jitCompA000_convTyp(int t) { int r = -1; - + if (1 <= t && t <= 7){ - r = t; - } else if (8 <= t && t <= 13){ - r = 2 | (t & 1); - } else if (14 <= t && t <= 15){ - r = 4 | (t & 1); - } else if (16 <= t && t <= 21){ - r = 6 | (t & 1); - } + r = t; + } else if (8 <= t && t <= 13){ + r = 2 | (t & 1); + } else if (14 <= t && t <= 15){ + r = 4 | (t & 1); + } else if (16 <= t && t <= 21){ + r = 6 | (t & 1); + } return r; } @@ -385,14 +385,14 @@ int jitCompiler(unsigned char *dst, unsigned char *dst1, const unsigned char *sr { struct JitCompWork w; unsigned char *dst00 = dst, *enter0 = NULL, *tmp_ucp; - char *errmsg = ""; + char *errmsg = ""; const unsigned char *oldsrc; int timecount = 0, i, j = 0, lastlabel = -1, debugInfo0 = -1; int reg0, reg1, reg2, cmp0reg = -1, cmp0lev = 0; w.dst = w.dst0 = dst; w.err = 0; w.maxLabels = maxLabels; - + if ((flags & JITC_NOSTARTUP) == 0) { jitCompPutByte1(w.dst, 0x60); /* PUSHAD(); */ jitCompA000_loadRegCacheAll(&w); /* start-up */ @@ -415,1082 +415,1082 @@ int jitCompiler(unsigned char *dst, unsigned char *dst1, const unsigned char *sr } prefix_continue: // CND命令実行後ここに戻る switch (*src) { - - case 0x00: /* NOP */ - if (w.prefix != 0) { w.err = JITC_ERR_PREFIX; goto err_w; } // 「条件付きでNOPを実行」するなんて、矛盾している! - break; - - case 0x01: /* LB */ - - /* - * LB : ラベル設置命令。(6byte) - * ・prefex = 1にする - * ・timecount++し、timecountのチェックをする。 - * ・ラベル位置を登録する。 - * ・割り込みがある場合、このタイミングで割り込みを発生させる。 - * - * 1 2 3 456 - * LB 01 opt imm32 - * - */ - - if (enter0 == NULL && (src[6] == 0x3c /* 多数のレジスタをスタックに退避 */ || (src[6] == 0xfe/* REMARK */ && src[7] == 0x01 && src[9] == 0x3c))) { //beginFunc()中のLB - // LB命令の後に0x3C命令・・・beginFunc() - jitCompPutByte1(w.dst, 0xe9); // (x86) JMP rel32 : 次の命令との相対オフセットだけ相対ニアジャンプする - enter0 = w.dst; - jitCompPutImm32(&w, 0); // 飛び相対座標が0 ・・・パイプラインのフラッシュ?? - } - if (src[6] == 0x34) { // LBの次の命令がDATA ・・・DAT_SA0(label, typ32, length) ・・・メモリ確保命令 - tmp_ucp = w.dst; - jitCompPutByte1(w.dst, 0xe9); // (x86) JMP rel32 : 次の命令との相対オフセットだけ相対ニアジャンプする - i = jitCompGetImm32(&src[7]); // type32 を取得 - j = 32; - if (i != 1) { - i = jitCompA000_convTyp(i); - j = 0; - if (i == 2 || i == 3) { j = 1; } - if (i == 4 || i == 5) { j = 2; } - if (i == 6 || i == 7) { j = 4; } - } - j *= jitCompGetImm32(&src[11]); - if (j <= 0) w.err = JITC_ERR_BADTYPE; - jitCompPutImm32(&w, j); + + case 0x00: /* NOP */ + if (w.prefix != 0) { w.err = JITC_ERR_PREFIX; goto err_w; } // 「条件付きでNOPを実行」するなんて、矛盾している! + break; + + case 0x01: /* LB */ + + /* + * LB : ラベル設置命令。(6byte) + * ・prefex = 1にする + * ・timecount++し、timecountのチェックをする。 + * ・ラベル位置を登録する。 + * ・割り込みがある場合、このタイミングで割り込みを発生させる。 + * + * 1 2 3 456 + * LB 01 opt imm32 + * + */ + + if (enter0 == NULL && (src[6] == 0x3c /* 多数のレジスタをスタックに退避 */ || (src[6] == 0xfe/* REMARK */ && src[7] == 0x01 && src[9] == 0x3c))) { //beginFunc()中のLB + // LB命令の後に0x3C命令・・・beginFunc() + jitCompPutByte1(w.dst, 0xe9); // (x86) JMP rel32 : 次の命令との相対オフセットだけ相対ニアジャンプする + enter0 = w.dst; + jitCompPutImm32(&w, 0); // 飛び相対座標が0 ・・・パイプラインのフラッシュ?? + } + if (src[6] == 0x34) { // LBの次の命令がDATA ・・・DAT_SA0(label, typ32, length) ・・・メモリ確保命令 + tmp_ucp = w.dst; + jitCompPutByte1(w.dst, 0xe9); // (x86) JMP rel32 : 次の命令との相対オフセットだけ相対ニアジャンプする + i = jitCompGetImm32(&src[7]); // type32 を取得 + j = 32; + if (i != 1) { + i = jitCompA000_convTyp(i); + j = 0; + if (i == 2 || i == 3) { j = 1; } + if (i == 4 || i == 5) { j = 2; } + if (i == 6 || i == 7) { j = 4; } + } + j *= jitCompGetImm32(&src[11]); + if (j <= 0) w.err = JITC_ERR_BADTYPE; + jitCompPutImm32(&w, j); #if (jitCompA0001_OPTIMIZE_JMP != 0) - if (j <= 127 - jitCompA0001_OPTIMIZE_ALIGN) { - w.dst -= 5; - jitCompPutByte2(w.dst, 0xeb, j); - } + if (j <= 127 - jitCompA0001_OPTIMIZE_ALIGN) { + w.dst -= 5; + jitCompPutByte2(w.dst, 0xeb, j); + } #endif - } + } #if (jitCompA0001_OPTIMIZE_ALIGN != 0) - for (;;) { - i = ((int)w.dst) & (jitCompA0001_OPTIMIZE_ALIGN - 1); /* ALIGNで割ったあまりを計算 */ - if (i == 0) break; - i = jitCompA0001_OPTIMIZE_ALIGN - i; - if (i == 1) { jitCompPutByte1(w.dst, 0x90); j += i; } /* NOP(); */ - if (i == 2) { jitCompPutByte2(w.dst, 0x89, 0xc0); j += i; } /* MOV(EAX, EAX); */ - if (i == 3) { jitCompPutByte3(w.dst, 0x8d, 0x76, 0x00); j += i; } /* LEA(ESI, [ESI+0]); */ - if (i == 4) { jitCompPutByte4(w.dst, 0x8d, 0x74, 0x26, 0x00); j += i; } /* LEA(ESI, [ESI*1+0]); */ - if (i == 5) { jitCompPutByte1(w.dst, 0x0d); jitCompPutImm32(&w, 0); j += i; } /* OR(EAX, 0); */ - if (i == 6) { jitCompPutByte2(w.dst, 0x8d, 0xb6); jitCompPutImm32(&w, 0); j += i; } /* LEA(ESI, [ESI+0]); */ - if (i >= 7) { jitCompPutByte3(w.dst, 0x8d, 0xb4, 0x26); jitCompPutImm32(&w, 0); j += 7; } /* LEA(ESI, [ESI*1+0]); */ - } + for (;;) { + i = ((int)w.dst) & (jitCompA0001_OPTIMIZE_ALIGN - 1); /* ALIGNで割ったあまりを計算 */ + if (i == 0) break; + i = jitCompA0001_OPTIMIZE_ALIGN - i; + if (i == 1) { jitCompPutByte1(w.dst, 0x90); j += i; } /* NOP(); */ + if (i == 2) { jitCompPutByte2(w.dst, 0x89, 0xc0); j += i; } /* MOV(EAX, EAX); */ + if (i == 3) { jitCompPutByte3(w.dst, 0x8d, 0x76, 0x00); j += i; } /* LEA(ESI, [ESI+0]); */ + if (i == 4) { jitCompPutByte4(w.dst, 0x8d, 0x74, 0x26, 0x00); j += i; } /* LEA(ESI, [ESI*1+0]); */ + if (i == 5) { jitCompPutByte1(w.dst, 0x0d); jitCompPutImm32(&w, 0); j += i; } /* OR(EAX, 0); */ + if (i == 6) { jitCompPutByte2(w.dst, 0x8d, 0xb6); jitCompPutImm32(&w, 0); j += i; } /* LEA(ESI, [ESI+0]); */ + if (i >= 7) { jitCompPutByte3(w.dst, 0x8d, 0xb4, 0x26); jitCompPutImm32(&w, 0); j += 7; } /* LEA(ESI, [ESI*1+0]); */ + } #endif - if (src[6] == 0x34) { - tmp_ucp[1] = j & 0xff; - if (*tmp_ucp == 0xe9) { - tmp_ucp[2] = (j >> 8) & 0xff; - tmp_ucp[3] = (j >> 16) & 0xff; - tmp_ucp[4] = (j >> 24) & 0xff; - } - } - if ((flags & JITC_PHASE1) == 0) { - i = jitCompGetLabelNum(&w, src + 2); - //printf("i=%06X %06X\n", i, src-src0); - if (label[i].opt != 0 && w.err == 0) { w.err = JITC_ERR_LABELREDEF; goto err_w; } - if (w.prefix != 0) { w.err = JITC_ERR_PREFIX; goto err_w; } - label[i].opt = src[1] + 1; - label[i].typ = 0; /* TYP_CODE */ - label[i].p = w.dst; - label[i].p1 = w.dst + 1; - lastlabel = i; - } - cmp0reg = -1; - timecount = 0; - /* 未完成(timeoutチェックコードを入れる) */ - break; - - case 0x02: /* LIMM */ - - /* - * LIMM : 定数即値代入命令(6byte) - * - * 1 2 3456 - * 02 reg0R imm32 - * - * ・reg3F は条件比較慣用句指定用&演算命令即値慣用句指定用。よってCND命令の直後では使用できない。 - */ - - if (src[1] == 0x3f && w.prefix != 0) w.err = JITC_ERR_PREFIX; // CND命令の直後でR3Fを書き換えるなんて変だよね - + if (src[6] == 0x34) { + tmp_ucp[1] = j & 0xff; + if (*tmp_ucp == 0xe9) { + tmp_ucp[2] = (j >> 8) & 0xff; + tmp_ucp[3] = (j >> 16) & 0xff; + tmp_ucp[4] = (j >> 24) & 0xff; + } + } + if ((flags & JITC_PHASE1) == 0) { + i = jitCompGetLabelNum(&w, src + 2); + //printf("i=%06X %06X\n", i, src-src0); + if (label[i].opt != 0 && w.err == 0) { w.err = JITC_ERR_LABELREDEF; goto err_w; } + if (w.prefix != 0) { w.err = JITC_ERR_PREFIX; goto err_w; } + label[i].opt = src[1] + 1; + label[i].typ = 0; /* TYP_CODE */ + label[i].p = w.dst; + label[i].p1 = w.dst + 1; + lastlabel = i; + } + cmp0reg = -1; + timecount = 0; + /* 未完成(timeoutチェックコードを入れる) */ + break; + + case 0x02: /* LIMM */ + + /* + * LIMM : 定数即値代入命令(6byte) + * + * 1 2 3456 + * 02 reg0R imm32 + * + * ・reg3F は条件比較慣用句指定用&演算命令即値慣用句指定用。よってCND命令の直後では使用できない。 + */ + + if (src[1] == 0x3f && w.prefix != 0) w.err = JITC_ERR_PREFIX; // CND命令の直後でR3Fを書き換えるなんて変だよね + #if (jitCompA0001_USE_R3F_IMM32 != 0) - if (src[1] == 0x3f) { // R3Fへの代入は例外敵に、 w.r3f を使用 - w.r3f = jitCompGetImm32(src + 2); - break; - } + if (src[1] == 0x3f) { // R3Fへの代入は例外敵に、 w.r3f を使用 + w.r3f = jitCompGetImm32(src + 2); + break; + } #endif - i = jitCompGetImm32(src + 2); // 与えられた即値(第二引数)を取得 - - /* R00-R02 なら EBX, ECX, EDX 、それ以外なら EAX のレジスタIDを reg0 に代入 */ - reg0 = jitCompA000_selectRegCache(src[1], 0 /* EAX */); - + i = jitCompGetImm32(src + 2); // 与えられた即値(第二引数)を取得 + + /* R00-R02 なら EBX, ECX, EDX 、それ以外なら EAX のレジスタIDを reg0 に代入 */ + reg0 = jitCompA000_selectRegCache(src[1], 0 /* EAX */); + #if (jitCompA0001_OPTIMIZE_MOV != 0) - if (i == 0) { - jitCompPutByte2(w.dst, 0x31, 0xc0 | reg0 << 3 | reg0); /* XOR(reg0, reg0); */ - jitCompA0001_movRxxEax(&w, src[1]); - break; - } + if (i == 0) { + jitCompPutByte2(w.dst, 0x31, 0xc0 | reg0 << 3 | reg0); /* XOR(reg0, reg0); */ + jitCompA0001_movRxxEax(&w, src[1]); + break; + } #endif - - /* reg0 のレジスタに対応したMOV命令を発行 */ - jitCompPutByte1(w.dst, 0xb8 | reg0); /* MOV(reg0, ?); == 10111000b+wr imm32 */ - jitCompPutImm32(&w, i); - - if (reg0 == 0) // R03以降の、レジスタの内容をメモリ上に格納してエミュレートする場合 - - jitCompA0001_movRxxEax(&w, src[1]); - break; - - case 0x03: /* PLIMM */ /* 未完成(plsまで対応) */ - - /* - * PLIMM : ラベル番号代入命令(6byte) - * - * 1 2 3456 - * 03 PXX imm32 - * - * ・P28 はAPI用 - * ・P30 はリターンアドレス - * ・P3F はプログラムカウンタ - */ - - i = jitCompGetLabelNum(&w, src + 2); // Pxxに代入するラベルの番号(第二引数) - if ((flags & JITC_PHASE1) != 0 && w.err == 0) { // Phase 1であるならば - if (label[i].opt == 0) { w.err = JITC_ERR_LABELNODEF; goto err_w; } // 指定されたラベル番号は存在しない - if (src[1] != 0x3f && label[i].opt != 2) { w.err = JITC_ERR_LABELTYP; goto err_w; } // - if (src[1] == 0x3f && label[i].typ != 0) { w.err = JITC_ERR_LABELTYP; goto err_w; } // プログラムカウンタに TYP_CODEでない値は代入できない - } - if (src[1] == 0x3f) { // プログラムカウンタへの代入なら - if (w.prefix == 0) { // CND命令による条件付きでなければ、即座に移動 - jitCompPutByte1(w.dst, 0xe9); /* JMP(?); */ - } - else { // 直前はCND命令。 - - /* - * CND命令 - * 1 2 - * 04 reg0R - * - * いま、dstの末端はJZ命令になっている。 0x0F 0x84 cd - */ - - // JZのとび先アドレスの書き換え? - w.dst[-1] = w.dst[-2] ^ 0xf1; /* 74->85, 75->84 */ - w.dst[-2] = 0x0f; - - w.prefix = 0; - } - j = 0; - if ((flags & JITC_PHASE1) != 0 || (((flags & JITC_PHASE1) == 0) && label[i].opt != 0)) // label番号iが確保されていれば (このif文は意味をなさない) - j = label[i].p - (w.dst + 4); // j はとび先の相対番地 - jitCompPutImm32(&w, j); // JMP もしくは JZ 命令のアドレス部を記述 + + /* reg0 のレジスタに対応したMOV命令を発行 */ + jitCompPutByte1(w.dst, 0xb8 | reg0); /* MOV(reg0, ?); == 10111000b+wr imm32 */ + jitCompPutImm32(&w, i); + + if (reg0 == 0) // R03以降の、レジスタの内容をメモリ上に格納してエミュレートする場合 + + jitCompA0001_movRxxEax(&w, src[1]); + break; + + case 0x03: /* PLIMM */ /* 未完成(plsまで対応) */ + + /* + * PLIMM : ラベル番号代入命令(6byte) + * + * 1 2 3456 + * 03 PXX imm32 + * + * ・P28 はAPI用 + * ・P30 はリターンアドレス + * ・P3F はプログラムカウンタ + */ + + i = jitCompGetLabelNum(&w, src + 2); // Pxxに代入するラベルの番号(第二引数) + if ((flags & JITC_PHASE1) != 0 && w.err == 0) { // Phase 1であるならば + if (label[i].opt == 0) { w.err = JITC_ERR_LABELNODEF; goto err_w; } // 指定されたラベル番号は存在しない + if (src[1] != 0x3f && label[i].opt != 2) { w.err = JITC_ERR_LABELTYP; goto err_w; } // + if (src[1] == 0x3f && label[i].typ != 0) { w.err = JITC_ERR_LABELTYP; goto err_w; } // プログラムカウンタに TYP_CODEでない値は代入できない + } + if (src[1] == 0x3f) { // プログラムカウンタへの代入なら + if (w.prefix == 0) { // CND命令による条件付きでなければ、即座に移動 + jitCompPutByte1(w.dst, 0xe9); /* JMP(?); */ + } + else { // 直前はCND命令。 + + /* + * CND命令 + * 1 2 + * 04 reg0R + * + * いま、dstの末端はJZ命令になっている。 0x0F 0x84 cd + */ + + // JZのとび先アドレスの書き換え? + w.dst[-1] = w.dst[-2] ^ 0xf1; /* 74->85, 75->84 */ + w.dst[-2] = 0x0f; + + w.prefix = 0; + } + j = 0; + if ((flags & JITC_PHASE1) != 0 || (((flags & JITC_PHASE1) == 0) && label[i].opt != 0)) // label番号iが確保されていれば (このif文は意味をなさない) + j = label[i].p - (w.dst + 4); // j はとび先の相対番地 + jitCompPutImm32(&w, j); // JMP もしくは JZ 命令のアドレス部を記述 #if (jitCompA0001_OPTIMIZE_JMP != 0) - if (-128 - 3 <= j && j < 0) { - if (w.dst[-5] == 0xe9) { - j += 3; - w.dst -= 5; - jitCompPutByte1(w.dst, 0xeb); /* JMP(?); */ - } - else { - j += 4; - w.dst -= 6; - jitCompPutByte1(w.dst, w.dst[1] ^ 0xf0); - } - jitCompPutByte1(w.dst, j & 0xff); - } + if (-128 - 3 <= j && j < 0) { + if (w.dst[-5] == 0xe9) { + j += 3; + w.dst -= 5; + jitCompPutByte1(w.dst, 0xeb); /* JMP(?); */ + } + else { + j += 4; + w.dst -= 6; + jitCompPutByte1(w.dst, w.dst[1] ^ 0xf0); + } + jitCompPutByte1(w.dst, j & 0xff); + } #endif - } - else { // プログラムカウンタ以外への代入 - - // 代入先が P01, P02なら ESI, EDI,それ以外ならEAXを指定 - reg0 = jitCompA000_selectPRegCache(src[1], 0 /* EAX */); - jitCompPutByte1(w.dst, 0xb8 | reg0); /* MOV(reg0, ?); */ - jitCompPutImm32(&w, (int)label[i].p); // ラベルのパスを各レジスタに代入 - - // レジスタへの代入をメモリでエミュレーションする場合は、スタックに積む。 - if (reg0 == 0) - jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32, 0); /* MOV([EBP+?], EAX); */ - - if (level < JITC_LV_FASTEST) { - jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + 8, reg0); /* MOV([EBP+?], reg0); */ /* p0 */ - jitCompPutByte1(w.dst, 0xb8); /* MOV(EAX, ?); */ - jitCompPutImm32(&w, label[i].typ); - jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + 4, 0); /* MOV([EBP+?], EAX); */ /* typ */ - jitCompPutByte1(w.dst, 0xb8); /* MOV(EAX, ?); */ - jitCompPutImm32(&w, (int)label[i].p1); - jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + 12, 0); /* MOV([EBP+?], EAX); */ /* p1 */ - jitCompPutByte2(w.dst, 0x31, 0xc0); /* XOR(EAX, EAX); */ - jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + 16, 0); /* MOV([EBP+?], EAX); */ /* liveSign */ - jitCompA0001_movReg32EbpDisp(&w, 0, 2320); /* MOV(EAX, ptrCtrl); */ - jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + 20, 0); /* MOV([EBP+?], EAX); */ /* pls */ - } - } - break; - - case 0x04: /* CND (prefix) */ - - /* - * CND命令 - * 与えられたRxxの最下位ビットが1であれば後続の命令を実行、そうでなければ飛ばす。 - */ - - if (src[1] >= 0x40) w.err = JITC_ERR_REGNUM; // R00-R3F 以外のレジスタは比較対象にできない - - // 比較対象のレジスタがメモリ上にあれば-1, それ以外なら適切なレジスタ番号を返す - reg0 = jitCompA000_selectRegCache(src[1], -1 /* mem */); - - /* TEST命令を発行 */ - if (reg0 < 0) { //比較対象のレジスタはメモリ上にある - jitCompPutByte1(w.dst, 0xf7); /* TEST([EBP+?],1); */ - jitCompA0001_85DispN(&w, src[1] * 4, 0); - } - else { - jitCompPutByte2(w.dst, 0xf7, 0xc0 | reg0); /* TEST(reg0,1); */ - } - jitCompPutImm32(&w, 1); - - /* JZ命令を発行 */ - jitCompPutByte2(w.dst, 0x74, 0x00); /* JZ($+2) */ - cmp0reg = -1; - if (w.err != 0) goto err_w; - src += 2; - w.prefix = 1; // プリフィックスをセット - w.dst0 = w.dst; - goto prefix_continue; - - case 0x08: /* LMEM */ /* 完成 */ - i = jitCompGetImm32(src + 2); - if (i == 0x0001) w.err = JITC_ERR_BADTYPE; - if (level < JITC_LV_FASTER) { - jitCompA0001_checkType(&w, src[6], i, 0); // read - cmp0reg = -1; - } - reg0 = jitCompA000_selectRegCache(src[1], 0 /* EAX */); - reg1 = jitCompA000_selectPRegCache(src[6], 2 /* EDX */); - if (reg0 != 0 /* EAX */ && reg1 == 2 /* EDX */) - reg1 = 0; /* EAX */ - if (reg1 == 2 /* EDX */) - jitCompA000_storeRegCacheEdx(&w); - if (reg1 <= 3 /* EAX, EDX */) - jitCompA0001_movReg32EbpDisp(&w, reg1, 256 + src[6] * 32 + 0); /* MOV(reg1, [EBP+?]); */ - if (level < JITC_LV_FASTER) - jitCompA0001_checkLimit(&w, reg1, src[6]); - i = jitCompA000_convTyp(jitCompGetImm32(src + 2)); - switch (i) { - case 0x0002: - jitCompPutByte3(w.dst, 0x0f, 0xbe, reg0 << 3 | reg1); /* MOVSX(reg0,BYTE [reg1]); */ - break; - case 0x0003: - jitCompPutByte3(w.dst, 0x0f, 0xb6, reg0 << 3 | reg1); /* MOVZX(reg0,BYTE [reg1]); */ - break; - case 0x0004: - jitCompPutByte3(w.dst, 0x0f, 0xbf, reg0 << 3 | reg1); /* MOVSX(reg0,WORD [reg1]); */ - break; - case 0x0005: - jitCompPutByte3(w.dst, 0x0f, 0xb7, reg0 << 3 | reg1); /* MOVZX(reg0,WORD [reg1]); */ - break; - case 0x0006: - case 0x0007: - jitCompPutByte2(w.dst, 0x8b, reg0 << 3 | reg1); /* MOV(reg0, [reg1]); */ - break; - default: - w.err = JITC_ERR_BADTYPE; - } - if (reg0 == 0 /* EAX */) - jitCompA0001_movRxxEax(&w, src[1]); - if (reg1 == 2 /* EDX */) - jitCompA000_loadRegCacheEdx(&w); - break; - - case 0x09: /* SMEM */ /* 完成 */ - i = jitCompGetImm32(src + 2); - if (i == 0x0001) w.err = JITC_ERR_BADTYPE; - if (level < JITC_LV_FASTER) { - jitCompA0001_checkType(&w, src[6], i, 1); // write - cmp0reg = -1; - } - reg0 = jitCompA000_selectRegCache(src[1], 0 /* EAX */); - reg1 = jitCompA000_selectPRegCache(src[6], 2 /* EDX */); - if (reg0 != 0 /* EAX */ && reg1 == 2 /* EDX */) - reg1 = 0; /* EAX */ - if (reg1 == 2 /* EDX */) - jitCompA000_storeRegCacheEdx(&w); - if (reg1 <= 3 /* EAX, EDX */) - jitCompA0001_movReg32EbpDisp(&w, reg1, 256 + src[6] * 32 + 0); /* MOV(reg1, [EBP+?]); */ - if (level < JITC_LV_FASTER) - jitCompA0001_checkLimit(&w, reg1, src[6]); - if (reg0 == 0 /* EAX */) - jitCompA0001_movEaxRxx(&w, src[1]); - /* 値の範囲チェック */ - i = jitCompA000_convTyp(jitCompGetImm32(src + 2)); - switch (i) { - case 0x0002: - case 0x0003: - jitCompPutByte2(w.dst, 0x88, reg0 << 3 | reg1); /* MOV([reg1], BYTE(reg0)); */ - break; - case 0x0004: - case 0x0005: - jitCompPutByte3(w.dst, 0x66, 0x89, reg0 << 3 | reg1); /* MOV([reg1], WORD(reg0)); */ - break; - case 0x0006: - case 0x0007: - jitCompPutByte2(w.dst, 0x89, reg0 << 3 | reg1); /* MOV([reg1], reg0); */ - break; - default: - w.err = JITC_ERR_BADTYPE; - } - if (reg1 == 2 /* EDX */) - jitCompA000_loadRegCacheEdx(&w); - break; - - case 0x0a: /* PLMEM */ /* 完成 */ - i = jitCompGetImm32(src + 2); - if (i != 0x0001) w.err = JITC_ERR_BADTYPE; - if (level < JITC_LV_FASTER) { - jitCompA0001_checkType(&w, src[6], i, 0); // read - cmp0reg = -1; - } - reg0 = jitCompA000_selectPRegCache(src[1], 0 /* EAX */); - reg1 = jitCompA000_selectPRegCache(src[6], 2 /* EDX */); - // if (reg0 != 0 /* EAX */ && reg1 == 2 /* EDX */) /* これをやってはいけない!(by K, 2013.08.02) */ - // reg1 = 0; /* EAX */ - if (reg0 == reg1 && reg0 != 0) { // bugfix: hinted by yao, 2013.09.14. thanks! - jitCompA000_storePRegCacheAll(&w); - reg1 = 2; /* EDX */ - } - if (reg1 == 2 /* EDX */) - jitCompA000_storeRegCacheEdx(&w); - if (reg1 <= 3 /* EAX, EDX */) - jitCompA0001_movReg32EbpDisp(&w, reg1, 256 + src[6] * 32 + 0); /* MOV(reg1, [EBP+?]); */ - if (level < JITC_LV_FASTER) - jitCompA0001_checkLimit(&w, reg1, src[6]); - jitCompPutByte2(w.dst, 0x8b, reg0 << 3 | reg1); /* MOV(reg0, [reg1]); */ - if (reg0 == 0 /* EAX */) - jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + 0, 0); /* MOV([EBP+?], EAX); */ - for (i = 4; i < 32; i += 4) { - jitCompPutByte3(w.dst, 0x8b, 0x40 | reg1, i); /* MOV(EAX, [reg1+?]); */ - jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + i, 0 /* EAX */); /* MOV([EBP+?], EAX); */ - } - if (reg1 == 2 /* EDX */) - jitCompA000_loadRegCacheEdx(&w); - break; - - case 0x0b: /* PSMEM */ /* 完成 */ - i = jitCompGetImm32(src + 2); - if (i != 0x0001) w.err = JITC_ERR_BADTYPE; - if (level < JITC_LV_FASTER) { - jitCompA0001_checkType(&w, src[6], i, 1); // write - cmp0reg = -1; - } - reg0 = jitCompA000_selectPRegCache(src[1], 0 /* EAX */); - reg1 = jitCompA000_selectPRegCache(src[6], 2 /* EDX */); - // if (reg0 != 0 /* EAX */ && reg1 == 2 /* EDX */) /* これをやってはいけない!(by K, 2013.08.02) */ - // reg1 = 0; /* EAX */ - if (reg1 == 2 /* EDX */) - jitCompA000_storeRegCacheEdx(&w); - if (reg1 <= 3 /* EAX, EDX */) - jitCompA0001_movReg32EbpDisp(&w, reg1, 256 + src[6] * 32 + 0); /* MOV(reg1, [EBP+?]); */ - if (level < JITC_LV_FASTER) - jitCompA0001_checkLimit(&w, reg1, src[6]); - if (reg0 == 0 /* EAX */) - jitCompA0001_movReg32EbpDisp(&w, reg0, 256 + src[1] * 32 + 0); /* MOV(reg0, [EBP+?]); */ - jitCompPutByte2(w.dst, 0x89, reg0 << 3 | reg1); /* MOV([reg1], reg0); */ - for (i = 4; i < 32; i += 4) { - jitCompA0001_movReg32EbpDisp(&w, 0 /* EAX */, 256 + src[1] * 32 + i); /* MOV(EAX, [EBP+?]); */ - jitCompPutByte3(w.dst, 0x89, 0x40 | reg1, i); /* MOV([reg1+?], EAX); */ - } - if (reg1 == 2 /* EDX */) - jitCompA000_loadRegCacheEdx(&w); - break; - - case 0x0e: /* PADD */ /* 完成 */ - if (level < JITC_LV_FASTER) { - jitCompA0001_checkType0(&w, src[6], jitCompGetImm32(src + 2), 2); // other, aliveテストはとりあえずしない. - cmp0reg = -1; - } - reg0 = jitCompA000_selectPRegCache(src[1], 0 /* EAX */); - reg1 = jitCompA000_selectPRegCache(src[6], -1 /* mem */); - if (reg1 < 0 /* mem */) - jitCompA0001_movReg32EbpDisp(&w, reg0, 256 + src[6] * 32 + 0); /* MOV(reg0, [EBP+?]); */ - if (reg1 >= 0 && reg0 != reg1) { - jitCompPutByte2(w.dst, 0x89, 0xc0 | reg1 << 3 | reg0); /* MOV(reg0, reg1); */ - } - i = jitCompGetImm32(src + 2); - j = -1; - if (i == 1) - j = 5; /* 32 */ - else { - i = jitCompA000_convTyp(i); - if (0x0002 <= i && i <= 0x0007) - j = (i - 0x0002) >> 1; - } - if (j < 0) { w.err = JITC_ERR_BADTYPE; goto err_w; } + } + else { // プログラムカウンタ以外への代入 + + // 代入先が P01, P02なら ESI, EDI,それ以外ならEAXを指定 + reg0 = jitCompA000_selectPRegCache(src[1], 0 /* EAX */); + jitCompPutByte1(w.dst, 0xb8 | reg0); /* MOV(reg0, ?); */ + jitCompPutImm32(&w, (int)label[i].p); // ラベルのパスを各レジスタに代入 + + // レジスタへの代入をメモリでエミュレーションする場合は、スタックに積む。 + if (reg0 == 0) + jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32, 0); /* MOV([EBP+?], EAX); */ + + if (level < JITC_LV_FASTEST) { + jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + 8, reg0); /* MOV([EBP+?], reg0); */ /* p0 */ + jitCompPutByte1(w.dst, 0xb8); /* MOV(EAX, ?); */ + jitCompPutImm32(&w, label[i].typ); + jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + 4, 0); /* MOV([EBP+?], EAX); */ /* typ */ + jitCompPutByte1(w.dst, 0xb8); /* MOV(EAX, ?); */ + jitCompPutImm32(&w, (int)label[i].p1); + jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + 12, 0); /* MOV([EBP+?], EAX); */ /* p1 */ + jitCompPutByte2(w.dst, 0x31, 0xc0); /* XOR(EAX, EAX); */ + jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + 16, 0); /* MOV([EBP+?], EAX); */ /* liveSign */ + jitCompA0001_movReg32EbpDisp(&w, 0, 2320); /* MOV(EAX, ptrCtrl); */ + jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + 20, 0); /* MOV([EBP+?], EAX); */ /* pls */ + } + } + break; + + case 0x04: /* CND (prefix) */ + + /* + * CND命令 + * 与えられたRxxの最下位ビットが1であれば後続の命令を実行、そうでなければ飛ばす。 + */ + + if (src[1] >= 0x40) w.err = JITC_ERR_REGNUM; // R00-R3F 以外のレジスタは比較対象にできない + + // 比較対象のレジスタがメモリ上にあれば-1, それ以外なら適切なレジスタ番号を返す + reg0 = jitCompA000_selectRegCache(src[1], -1 /* mem */); + + /* TEST命令を発行 */ + if (reg0 < 0) { //比較対象のレジスタはメモリ上にある + jitCompPutByte1(w.dst, 0xf7); /* TEST([EBP+?],1); */ + jitCompA0001_85DispN(&w, src[1] * 4, 0); + } + else { + jitCompPutByte2(w.dst, 0xf7, 0xc0 | reg0); /* TEST(reg0,1); */ + } + jitCompPutImm32(&w, 1); + + /* JZ命令を発行 */ + jitCompPutByte2(w.dst, 0x74, 0x00); /* JZ($+2) */ + cmp0reg = -1; + if (w.err != 0) goto err_w; + src += 2; + w.prefix = 1; // プリフィックスをセット + w.dst0 = w.dst; + goto prefix_continue; + + case 0x08: /* LMEM */ /* 完成 */ + i = jitCompGetImm32(src + 2); + if (i == 0x0001) w.err = JITC_ERR_BADTYPE; + if (level < JITC_LV_FASTER) { + jitCompA0001_checkType(&w, src[6], i, 0); // read + cmp0reg = -1; + } + reg0 = jitCompA000_selectRegCache(src[1], 0 /* EAX */); + reg1 = jitCompA000_selectPRegCache(src[6], 2 /* EDX */); + if (reg0 != 0 /* EAX */ && reg1 == 2 /* EDX */) + reg1 = 0; /* EAX */ + if (reg1 == 2 /* EDX */) + jitCompA000_storeRegCacheEdx(&w); + if (reg1 <= 3 /* EAX, EDX */) + jitCompA0001_movReg32EbpDisp(&w, reg1, 256 + src[6] * 32 + 0); /* MOV(reg1, [EBP+?]); */ + if (level < JITC_LV_FASTER) + jitCompA0001_checkLimit(&w, reg1, src[6]); + i = jitCompA000_convTyp(jitCompGetImm32(src + 2)); + switch (i) { + case 0x0002: + jitCompPutByte3(w.dst, 0x0f, 0xbe, reg0 << 3 | reg1); /* MOVSX(reg0,BYTE [reg1]); */ + break; + case 0x0003: + jitCompPutByte3(w.dst, 0x0f, 0xb6, reg0 << 3 | reg1); /* MOVZX(reg0,BYTE [reg1]); */ + break; + case 0x0004: + jitCompPutByte3(w.dst, 0x0f, 0xbf, reg0 << 3 | reg1); /* MOVSX(reg0,WORD [reg1]); */ + break; + case 0x0005: + jitCompPutByte3(w.dst, 0x0f, 0xb7, reg0 << 3 | reg1); /* MOVZX(reg0,WORD [reg1]); */ + break; + case 0x0006: + case 0x0007: + jitCompPutByte2(w.dst, 0x8b, reg0 << 3 | reg1); /* MOV(reg0, [reg1]); */ + break; + default: + w.err = JITC_ERR_BADTYPE; + } + if (reg0 == 0 /* EAX */) + jitCompA0001_movRxxEax(&w, src[1]); + if (reg1 == 2 /* EDX */) + jitCompA000_loadRegCacheEdx(&w); + break; + + case 0x09: /* SMEM */ /* 完成 */ + i = jitCompGetImm32(src + 2); + if (i == 0x0001) w.err = JITC_ERR_BADTYPE; + if (level < JITC_LV_FASTER) { + jitCompA0001_checkType(&w, src[6], i, 1); // write + cmp0reg = -1; + } + reg0 = jitCompA000_selectRegCache(src[1], 0 /* EAX */); + reg1 = jitCompA000_selectPRegCache(src[6], 2 /* EDX */); + if (reg0 != 0 /* EAX */ && reg1 == 2 /* EDX */) + reg1 = 0; /* EAX */ + if (reg1 == 2 /* EDX */) + jitCompA000_storeRegCacheEdx(&w); + if (reg1 <= 3 /* EAX, EDX */) + jitCompA0001_movReg32EbpDisp(&w, reg1, 256 + src[6] * 32 + 0); /* MOV(reg1, [EBP+?]); */ + if (level < JITC_LV_FASTER) + jitCompA0001_checkLimit(&w, reg1, src[6]); + if (reg0 == 0 /* EAX */) + jitCompA0001_movEaxRxx(&w, src[1]); + /* 値の範囲チェック */ + i = jitCompA000_convTyp(jitCompGetImm32(src + 2)); + switch (i) { + case 0x0002: + case 0x0003: + jitCompPutByte2(w.dst, 0x88, reg0 << 3 | reg1); /* MOV([reg1], BYTE(reg0)); */ + break; + case 0x0004: + case 0x0005: + jitCompPutByte3(w.dst, 0x66, 0x89, reg0 << 3 | reg1); /* MOV([reg1], WORD(reg0)); */ + break; + case 0x0006: + case 0x0007: + jitCompPutByte2(w.dst, 0x89, reg0 << 3 | reg1); /* MOV([reg1], reg0); */ + break; + default: + w.err = JITC_ERR_BADTYPE; + } + if (reg1 == 2 /* EDX */) + jitCompA000_loadRegCacheEdx(&w); + break; + + case 0x0a: /* PLMEM */ /* 完成 */ + i = jitCompGetImm32(src + 2); + if (i != 0x0001) w.err = JITC_ERR_BADTYPE; + if (level < JITC_LV_FASTER) { + jitCompA0001_checkType(&w, src[6], i, 0); // read + cmp0reg = -1; + } + reg0 = jitCompA000_selectPRegCache(src[1], 0 /* EAX */); + reg1 = jitCompA000_selectPRegCache(src[6], 2 /* EDX */); + // if (reg0 != 0 /* EAX */ && reg1 == 2 /* EDX */) /* これをやってはいけない!(by K, 2013.08.02) */ + // reg1 = 0; /* EAX */ + if (reg0 == reg1 && reg0 != 0) { // bugfix: hinted by yao, 2013.09.14. thanks! + jitCompA000_storePRegCacheAll(&w); + reg1 = 2; /* EDX */ + } + if (reg1 == 2 /* EDX */) + jitCompA000_storeRegCacheEdx(&w); + if (reg1 <= 3 /* EAX, EDX */) + jitCompA0001_movReg32EbpDisp(&w, reg1, 256 + src[6] * 32 + 0); /* MOV(reg1, [EBP+?]); */ + if (level < JITC_LV_FASTER) + jitCompA0001_checkLimit(&w, reg1, src[6]); + jitCompPutByte2(w.dst, 0x8b, reg0 << 3 | reg1); /* MOV(reg0, [reg1]); */ + if (reg0 == 0 /* EAX */) + jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + 0, 0); /* MOV([EBP+?], EAX); */ + for (i = 4; i < 32; i += 4) { + jitCompPutByte3(w.dst, 0x8b, 0x40 | reg1, i); /* MOV(EAX, [reg1+?]); */ + jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + i, 0 /* EAX */); /* MOV([EBP+?], EAX); */ + } + if (reg1 == 2 /* EDX */) + jitCompA000_loadRegCacheEdx(&w); + break; + + case 0x0b: /* PSMEM */ /* 完成 */ + i = jitCompGetImm32(src + 2); + if (i != 0x0001) w.err = JITC_ERR_BADTYPE; + if (level < JITC_LV_FASTER) { + jitCompA0001_checkType(&w, src[6], i, 1); // write + cmp0reg = -1; + } + reg0 = jitCompA000_selectPRegCache(src[1], 0 /* EAX */); + reg1 = jitCompA000_selectPRegCache(src[6], 2 /* EDX */); + // if (reg0 != 0 /* EAX */ && reg1 == 2 /* EDX */) /* これをやってはいけない!(by K, 2013.08.02) */ + // reg1 = 0; /* EAX */ + if (reg1 == 2 /* EDX */) + jitCompA000_storeRegCacheEdx(&w); + if (reg1 <= 3 /* EAX, EDX */) + jitCompA0001_movReg32EbpDisp(&w, reg1, 256 + src[6] * 32 + 0); /* MOV(reg1, [EBP+?]); */ + if (level < JITC_LV_FASTER) + jitCompA0001_checkLimit(&w, reg1, src[6]); + if (reg0 == 0 /* EAX */) + jitCompA0001_movReg32EbpDisp(&w, reg0, 256 + src[1] * 32 + 0); /* MOV(reg0, [EBP+?]); */ + jitCompPutByte2(w.dst, 0x89, reg0 << 3 | reg1); /* MOV([reg1], reg0); */ + for (i = 4; i < 32; i += 4) { + jitCompA0001_movReg32EbpDisp(&w, 0 /* EAX */, 256 + src[1] * 32 + i); /* MOV(EAX, [EBP+?]); */ + jitCompPutByte3(w.dst, 0x89, 0x40 | reg1, i); /* MOV([reg1+?], EAX); */ + } + if (reg1 == 2 /* EDX */) + jitCompA000_loadRegCacheEdx(&w); + break; + + case 0x0e: /* PADD */ /* 完成 */ + if (level < JITC_LV_FASTER) { + jitCompA0001_checkType0(&w, src[6], jitCompGetImm32(src + 2), 2); // other, aliveテストはとりあえずしない. + cmp0reg = -1; + } + reg0 = jitCompA000_selectPRegCache(src[1], 0 /* EAX */); + reg1 = jitCompA000_selectPRegCache(src[6], -1 /* mem */); + if (reg1 < 0 /* mem */) + jitCompA0001_movReg32EbpDisp(&w, reg0, 256 + src[6] * 32 + 0); /* MOV(reg0, [EBP+?]); */ + if (reg1 >= 0 && reg0 != reg1) { + jitCompPutByte2(w.dst, 0x89, 0xc0 | reg1 << 3 | reg0); /* MOV(reg0, reg1); */ + } + i = jitCompGetImm32(src + 2); + j = -1; + if (i == 1) + j = 5; /* 32 */ + else { + i = jitCompA000_convTyp(i); + if (0x0002 <= i && i <= 0x0007) + j = (i - 0x0002) >> 1; + } + if (j < 0) { w.err = JITC_ERR_BADTYPE; goto err_w; } #if (jitCompA0001_USE_R3F_IMM32 != 0) - if (src[7] == 0x3f) { - j = w.r3f << j; + if (src[7] == 0x3f) { + j = w.r3f << j; #if (jitCompA0001_USE_R3F_IMM8 != 0) - if (-0x80 <= j && j <= 0x7f) { + if (-0x80 <= j && j <= 0x7f) { #if (jitCompA0001_USE_R3F_INCDEC != 0) - if (j == 1) { jitCompPutByte1(w.dst, 0x40 | reg0); goto padd1; } /* INC */ - if (j == -1) { jitCompPutByte1(w.dst, 0x48 | reg0); goto padd1; } /* DEC */ + if (j == 1) { jitCompPutByte1(w.dst, 0x40 | reg0); goto padd1; } /* INC */ + if (j == -1) { jitCompPutByte1(w.dst, 0x48 | reg0); goto padd1; } /* DEC */ #endif - jitCompPutByte3(w.dst, 0x83, 0xc0 | reg0, j & 0xff); /* ADD(reg0, im8); */ - goto padd1; - } + jitCompPutByte3(w.dst, 0x83, 0xc0 | reg0, j & 0xff); /* ADD(reg0, im8); */ + goto padd1; + } #endif - if (reg0 == 0) { - jitCompPutByte1(w.dst, 0x05); /* ADD(reg0, ?); */ - } - else { - jitCompPutByte2(w.dst, 0x81, 0xc0 | reg0); /* ADD(reg0, ?); */ - } - jitCompPutImm32(&w, j); - goto padd1; - } + if (reg0 == 0) { + jitCompPutByte1(w.dst, 0x05); /* ADD(reg0, ?); */ + } + else { + jitCompPutByte2(w.dst, 0x81, 0xc0 | reg0); /* ADD(reg0, ?); */ + } + jitCompPutImm32(&w, j); + goto padd1; + } #endif - if (src[7] >= 0x40) w.err = JITC_ERR_REGNUM; - if (j == 0) { - reg1 = jitCompA000_selectRegCache(src[7], -1 /* mem */); - if (reg1 >= 0) { - jitCompPutByte2(w.dst, 0x01, 0xc0 | reg1 << 3 | reg0); /* ADD(reg0, reg1); */ - } - else { - jitCompPutByte1(w.dst, 0x03); /* ADD(reg0, [EBP+?]); */ - jitCompA0001_85DispN(&w, src[7] * 4, reg0); - } - } - else { - reg1 = jitCompA000_selectRegCache(src[7], -1 /* mem */); - reg2 = 2; /* EDX */ - jitCompA000_storeRegCacheEdx(&w); - if (reg1 < 0) - jitCompA0001_movReg32EbpDisp(&w, reg2, src[7] * 4); /* MOV(reg2, [EBP+?]); */ - if (reg1 >= 0 && reg1 != reg2) { - jitCompPutByte2(w.dst, 0x89, 0xc0 | reg1 << 3 | reg2); /* MOV(reg2, reg1); */ - } - jitCompPutByte3(w.dst, 0xc1, 0xe0 | reg2, j); /* SHL(reg2, ?); */ - jitCompPutByte2(w.dst, 0x01, 0xc0 | reg2 << 3 | reg0); /* ADD(reg0, reg2); */ - jitCompA000_loadRegCacheEdx(&w); - } + if (src[7] >= 0x40) w.err = JITC_ERR_REGNUM; + if (j == 0) { + reg1 = jitCompA000_selectRegCache(src[7], -1 /* mem */); + if (reg1 >= 0) { + jitCompPutByte2(w.dst, 0x01, 0xc0 | reg1 << 3 | reg0); /* ADD(reg0, reg1); */ + } + else { + jitCompPutByte1(w.dst, 0x03); /* ADD(reg0, [EBP+?]); */ + jitCompA0001_85DispN(&w, src[7] * 4, reg0); + } + } + else { + reg1 = jitCompA000_selectRegCache(src[7], -1 /* mem */); + reg2 = 2; /* EDX */ + jitCompA000_storeRegCacheEdx(&w); + if (reg1 < 0) + jitCompA0001_movReg32EbpDisp(&w, reg2, src[7] * 4); /* MOV(reg2, [EBP+?]); */ + if (reg1 >= 0 && reg1 != reg2) { + jitCompPutByte2(w.dst, 0x89, 0xc0 | reg1 << 3 | reg2); /* MOV(reg2, reg1); */ + } + jitCompPutByte3(w.dst, 0xc1, 0xe0 | reg2, j); /* SHL(reg2, ?); */ + jitCompPutByte2(w.dst, 0x01, 0xc0 | reg2 << 3 | reg0); /* ADD(reg0, reg2); */ + jitCompA000_loadRegCacheEdx(&w); + } #if (jitCompA0001_USE_R3F_IMM32 != 0) - padd1: + padd1: #endif - if (reg0 == 0 /* EAX */) - jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + 0, reg0); /* MOV([EBP+?], reg0); */ - if (src[1] != src[6]) { - for (i = 4; i < 32; i += 4) { - jitCompA0001_movReg32EbpDisp(&w, 0 /* EAX */, 256 + src[6] * 32 + i); /* MOV(EAX, [EBP+?]); */ - jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + i, 0 /* EAX */); /* MOV([EBP+?], EAX); */ - } - } - cmp0reg = -1; - break; - - case 0x0f: /* PDIF */ /* 未完成 */ - reg0 = jitCompA000_selectRegCache(src[1], 0 /* EAX */); - jitCompA000_storePRegCacheAll(&w); // 手抜き. - jitCompA0001_checkCompPtr(&w, src[6], src[7]); - jitCompA0001_movReg32EbpDisp(&w, reg0, 256 + src[6] * 32 + 0); /* MOV(reg0, [EBP+?]); */ - jitCompPutByte1(w.dst, 0x2b); /* SUB(EAX, [EBP+?]); */ - jitCompA0001_85DispN(&w, 256 + src[7] * 32 + 0, reg0); - i = jitCompA000_convTyp(jitCompGetImm32(src + 2)); - j = -1; - if (0x0002 <= i && i <= 0x0007) - j = (i - 0x0002) >> 1; - if (j < 0) { w.err = JITC_ERR_BADTYPE; goto err_w; } - if (j > 0) { - jitCompPutByte3(w.dst, 0xc1, 0xf8 | reg0, j); /* SAR(reg0,?); */ - } - if (reg0 == 0 /* EAX */) - jitCompA0001_movRxxEax(&w, src[1]); - cmp0reg = src[1]; cmp0lev = 1; - break; - - case 0x10: /* OR */ - case 0x11: /* XOR */ - case 0x12: /* AND */ - case 0x14: /* ADD */ - case 0x15: /* SUB */ - case 0x16: /* MUL */ - if (src[1] >= 0x3f) w.err = JITC_ERR_REGNUM; - reg0 = jitCompA000_selectRegCache(src[1], 0 /* EAX */); - reg1 = jitCompA000_selectRegCache(src[2], -1 /* mem */); + if (reg0 == 0 /* EAX */) + jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + 0, reg0); /* MOV([EBP+?], reg0); */ + if (src[1] != src[6]) { + for (i = 4; i < 32; i += 4) { + jitCompA0001_movReg32EbpDisp(&w, 0 /* EAX */, 256 + src[6] * 32 + i); /* MOV(EAX, [EBP+?]); */ + jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + i, 0 /* EAX */); /* MOV([EBP+?], EAX); */ + } + } + cmp0reg = -1; + break; + + case 0x0f: /* PDIF */ /* 未完成 */ + reg0 = jitCompA000_selectRegCache(src[1], 0 /* EAX */); + jitCompA000_storePRegCacheAll(&w); // 手抜き. + jitCompA0001_checkCompPtr(&w, src[6], src[7]); + jitCompA0001_movReg32EbpDisp(&w, reg0, 256 + src[6] * 32 + 0); /* MOV(reg0, [EBP+?]); */ + jitCompPutByte1(w.dst, 0x2b); /* SUB(EAX, [EBP+?]); */ + jitCompA0001_85DispN(&w, 256 + src[7] * 32 + 0, reg0); + i = jitCompA000_convTyp(jitCompGetImm32(src + 2)); + j = -1; + if (0x0002 <= i && i <= 0x0007) + j = (i - 0x0002) >> 1; + if (j < 0) { w.err = JITC_ERR_BADTYPE; goto err_w; } + if (j > 0) { + jitCompPutByte3(w.dst, 0xc1, 0xf8 | reg0, j); /* SAR(reg0,?); */ + } + if (reg0 == 0 /* EAX */) + jitCompA0001_movRxxEax(&w, src[1]); + cmp0reg = src[1]; cmp0lev = 1; + break; + + case 0x10: /* OR */ + case 0x11: /* XOR */ + case 0x12: /* AND */ + case 0x14: /* ADD */ + case 0x15: /* SUB */ + case 0x16: /* MUL */ + if (src[1] >= 0x3f) w.err = JITC_ERR_REGNUM; + reg0 = jitCompA000_selectRegCache(src[1], 0 /* EAX */); + reg1 = jitCompA000_selectRegCache(src[2], -1 /* mem */); #if (jitCompA0001_USE_R3F_IMM32 != 0) - if (src[2] == 0x3f) { // SUBのみ該当. - if (*src != 0x15) w.err = JITC_ERR_REGNUM; - reg2 = jitCompA000_selectRegCache(src[3], -1 /* mem */); - if (reg2 >= 0) - jitCompA000_storeRegCacheAll(&w); - jitCompPutByte1(w.dst, 0xb8 | reg0); /* MOV(reg0, ?); */ - jitCompPutImm32(&w, w.r3f); - jitCompPutByte1(w.dst, 0x2b); - jitCompA0001_85DispN(&w, src[3] * 4, reg0); - if (reg0 == 0) - jitCompA0001_movRxxEax(&w, src[1]); - break; - } + if (src[2] == 0x3f) { // SUBのみ該当. + if (*src != 0x15) w.err = JITC_ERR_REGNUM; + reg2 = jitCompA000_selectRegCache(src[3], -1 /* mem */); + if (reg2 >= 0) + jitCompA000_storeRegCacheAll(&w); + jitCompPutByte1(w.dst, 0xb8 | reg0); /* MOV(reg0, ?); */ + jitCompPutImm32(&w, w.r3f); + jitCompPutByte1(w.dst, 0x2b); + jitCompA0001_85DispN(&w, src[3] * 4, reg0); + if (reg0 == 0) + jitCompA0001_movRxxEax(&w, src[1]); + break; + } #endif - if (reg1 < 0) { - jitCompA0001_movReg32EbpDisp(&w, reg0, src[2] * 4); /* MOV(reg0, [EBP+?]); */ - } - if (reg1 >= 0 && reg0 != reg1) { - jitCompPutByte2(w.dst, 0x89, 0xc0 | reg1 << 3 | reg0); /* MOV(reg0, reg1); */ - } - if (!(src[0] == 0x10 && src[3] == 0xff)) { // bugfix: hinted by Iris, 2013.06.26. thanks! - cmp0reg = src[1]; - cmp0lev = 1; - if (src[0] < 0x14) - cmp0lev = 2; - if (src[0] == 0x16) - cmp0reg = -1; - } - if (!(src[0] == 0x10 && src[3] == 0xff)) { + if (reg1 < 0) { + jitCompA0001_movReg32EbpDisp(&w, reg0, src[2] * 4); /* MOV(reg0, [EBP+?]); */ + } + if (reg1 >= 0 && reg0 != reg1) { + jitCompPutByte2(w.dst, 0x89, 0xc0 | reg1 << 3 | reg0); /* MOV(reg0, reg1); */ + } + if (!(src[0] == 0x10 && src[3] == 0xff)) { // bugfix: hinted by Iris, 2013.06.26. thanks! + cmp0reg = src[1]; + cmp0lev = 1; + if (src[0] < 0x14) + cmp0lev = 2; + if (src[0] == 0x16) + cmp0reg = -1; + } + if (!(src[0] == 0x10 && src[3] == 0xff)) { #if (jitCompA0001_USE_R3F_IMM32 != 0) - if (src[3] == 0x3f) { - if (*src == 0x16 && w.r3f == -1) { - jitCompPutByte2(w.dst, 0xf7, 0xd8 | reg0); /* NEG(reg0); */ - if (reg0 == 0) - jitCompA0001_movRxxEax(&w, src[1]); - break; - } + if (src[3] == 0x3f) { + if (*src == 0x16 && w.r3f == -1) { + jitCompPutByte2(w.dst, 0xf7, 0xd8 | reg0); /* NEG(reg0); */ + if (reg0 == 0) + jitCompA0001_movRxxEax(&w, src[1]); + break; + } #if (jitCompA0001_USE_R3F_INCDEC != 0) - if ((*src == 0x14 && w.r3f == 1) || (*src == 0x15 && w.r3f == -1)) { - jitCompPutByte1(w.dst, 0x40 | reg0); /* INC(reg0); */ - if (reg0 == 0) - jitCompA0001_movRxxEax(&w, src[1]); - break; - } - if ((*src == 0x15 && w.r3f == 1) || (*src == 0x14 && w.r3f == -1)) { - jitCompPutByte1(w.dst, 0x48 | reg0); /* DEC(reg0); */ - if (reg0 == 0) - jitCompA0001_movRxxEax(&w, src[1]); - break; - } + if ((*src == 0x14 && w.r3f == 1) || (*src == 0x15 && w.r3f == -1)) { + jitCompPutByte1(w.dst, 0x40 | reg0); /* INC(reg0); */ + if (reg0 == 0) + jitCompA0001_movRxxEax(&w, src[1]); + break; + } + if ((*src == 0x15 && w.r3f == 1) || (*src == 0x14 && w.r3f == -1)) { + jitCompPutByte1(w.dst, 0x48 | reg0); /* DEC(reg0); */ + if (reg0 == 0) + jitCompA0001_movRxxEax(&w, src[1]); + break; + } #endif #if (jitCompA0001_USE_R3F_IMM8 != 0) - if (-0x80 <= w.r3f && w.r3f <= 0x7f) { - if (*src != 0x16) { - static unsigned char basic_op_table_im8[] = { 0xc8, 0xf0, 0xe0, 0, 0xc0, 0xe8 }; - jitCompPutByte3(w.dst, 0x83, basic_op_table_im8[*src - 0x10] | reg0, w.r3f & 0xff); - } - else { - jitCompPutByte3(w.dst, 0x6b, 0xc0 | reg0 << 3 | reg0, w.r3f & 0xff); - } - if (reg0 == 0) - jitCompA0001_movRxxEax(&w, src[1]); - break; - } + if (-0x80 <= w.r3f && w.r3f <= 0x7f) { + if (*src != 0x16) { + static unsigned char basic_op_table_im8[] = { 0xc8, 0xf0, 0xe0, 0, 0xc0, 0xe8 }; + jitCompPutByte3(w.dst, 0x83, basic_op_table_im8[*src - 0x10] | reg0, w.r3f & 0xff); + } + else { + jitCompPutByte3(w.dst, 0x6b, 0xc0 | reg0 << 3 | reg0, w.r3f & 0xff); + } + if (reg0 == 0) + jitCompA0001_movRxxEax(&w, src[1]); + break; + } #endif - if (reg0 == 0 /* EAX */) { - static unsigned char basic_op_table_im32_eax[] = { 0x0d, 0x35, 0x25, 0, 0x05, 0x2d, 0xc0 }; - if (*src == 0x16) { jitCompPutByte1(w.dst, 0x69); } - jitCompPutByte1(w.dst, basic_op_table_im32_eax[*src - 0x10]); - } - else { - if (*src != 0x16) { - static unsigned char basic_op_table_im32_reg[] = { 0xc8, 0xf0, 0xe0, 0, 0xc0, 0xe8 }; - jitCompPutByte2(w.dst, 0x81, basic_op_table_im32_reg[*src - 0x10] | reg0); - } - else { - jitCompPutByte2(w.dst, 0x69, 0xc0 | reg0 << 3 | reg0); - } - } - jitCompPutImm32(&w, w.r3f); - if (reg0 == 0) - jitCompA0001_movRxxEax(&w, src[1]); - break; - } + if (reg0 == 0 /* EAX */) { + static unsigned char basic_op_table_im32_eax[] = { 0x0d, 0x35, 0x25, 0, 0x05, 0x2d, 0xc0 }; + if (*src == 0x16) { jitCompPutByte1(w.dst, 0x69); } + jitCompPutByte1(w.dst, basic_op_table_im32_eax[*src - 0x10]); + } + else { + if (*src != 0x16) { + static unsigned char basic_op_table_im32_reg[] = { 0xc8, 0xf0, 0xe0, 0, 0xc0, 0xe8 }; + jitCompPutByte2(w.dst, 0x81, basic_op_table_im32_reg[*src - 0x10] | reg0); + } + else { + jitCompPutByte2(w.dst, 0x69, 0xc0 | reg0 << 3 | reg0); + } + } + jitCompPutImm32(&w, w.r3f); + if (reg0 == 0) + jitCompA0001_movRxxEax(&w, src[1]); + break; + } #endif - reg1 = jitCompA000_selectRegCache(src[3], -1 /* mem */); - if (src[3] >= 0x40) w.err = JITC_ERR_REGNUM; - if (*src != 0x16) { - if (reg1 >= 0) { - static unsigned char basic_op_table_rr[] = { 0x09, 0x31, 0x21, 0, 0x01, 0x29 }; /* op(reg,reg); */ - jitCompPutByte2(w.dst, basic_op_table_rr[*src - 0x10], 0xc0 | reg1 << 3 | reg0); - } - else { - static unsigned char basic_op_table_rm[] = { 0x0b, 0x33, 0x23, 0, 0x03, 0x2b, 0xaf }; /* op(reg,mem); */ - jitCompPutByte1(w.dst, basic_op_table_rm[*src - 0x10]); - jitCompA0001_85DispN(&w, src[3] * 4, reg0); - } - } - else { - if (reg1 >= 0) { - jitCompPutByte3(w.dst, 0x0f, 0xaf, 0xc0 | reg0 << 3 | reg1); - } - else { - jitCompPutByte2(w.dst, 0x0f, 0xaf); - jitCompA0001_85DispN(&w, src[3] * 4, reg0); - } - } - } - if (reg0 == 0) - jitCompA0001_movRxxEax(&w, src[1]); - break; - - case 0x18: /* SHL */ - case 0x19: /* SAR */ - if (src[1] >= 0x3f) w.err = JITC_ERR_REGNUM; - if (src[3] >= 0x40) w.err = JITC_ERR_REGNUM; + reg1 = jitCompA000_selectRegCache(src[3], -1 /* mem */); + if (src[3] >= 0x40) w.err = JITC_ERR_REGNUM; + if (*src != 0x16) { + if (reg1 >= 0) { + static unsigned char basic_op_table_rr[] = { 0x09, 0x31, 0x21, 0, 0x01, 0x29 }; /* op(reg,reg); */ + jitCompPutByte2(w.dst, basic_op_table_rr[*src - 0x10], 0xc0 | reg1 << 3 | reg0); + } + else { + static unsigned char basic_op_table_rm[] = { 0x0b, 0x33, 0x23, 0, 0x03, 0x2b, 0xaf }; /* op(reg,mem); */ + jitCompPutByte1(w.dst, basic_op_table_rm[*src - 0x10]); + jitCompA0001_85DispN(&w, src[3] * 4, reg0); + } + } + else { + if (reg1 >= 0) { + jitCompPutByte3(w.dst, 0x0f, 0xaf, 0xc0 | reg0 << 3 | reg1); + } + else { + jitCompPutByte2(w.dst, 0x0f, 0xaf); + jitCompA0001_85DispN(&w, src[3] * 4, reg0); + } + } + } + if (reg0 == 0) + jitCompA0001_movRxxEax(&w, src[1]); + break; + + case 0x18: /* SHL */ + case 0x19: /* SAR */ + if (src[1] >= 0x3f) w.err = JITC_ERR_REGNUM; + if (src[3] >= 0x40) w.err = JITC_ERR_REGNUM; #if (jitCompA0001_USE_R3F_IMM32 != 0) - if (src[3] == 0x3f) { - reg0 = jitCompA000_selectRegCache(src[1], 0 /* EAX */); - reg1 = jitCompA000_selectRegCache(src[2], -1 /* mem */); - if (src[1] >= 0x3f) w.err = JITC_ERR_REGNUM; - if (reg1 == -1) - jitCompA0001_movReg32EbpDisp(&w, reg0, src[2] * 4); /* MOV(reg1, [EBP+?]); */ - else { - if (reg0 != reg1) { - jitCompPutByte2(w.dst, 0x89, 0xc0 | reg1 << 3 | reg0); /* MOV(reg0, reg1); */ - } - } - if (*src == 0x18) { jitCompPutByte3(w.dst, 0xc1, 0xe0 | reg0, w.r3f); } /* SHL(reg0, im8); */ - if (*src == 0x19) { jitCompPutByte3(w.dst, 0xc1, 0xf8 | reg0, w.r3f); } /* SAR(reg0, im8); */ - if (reg0 == 0 /* EAX */) - jitCompA0001_movRxxEax(&w, src[1]); - cmp0reg = src[1]; - cmp0lev = 1; - break; - } + if (src[3] == 0x3f) { + reg0 = jitCompA000_selectRegCache(src[1], 0 /* EAX */); + reg1 = jitCompA000_selectRegCache(src[2], -1 /* mem */); + if (src[1] >= 0x3f) w.err = JITC_ERR_REGNUM; + if (reg1 == -1) + jitCompA0001_movReg32EbpDisp(&w, reg0, src[2] * 4); /* MOV(reg1, [EBP+?]); */ + else { + if (reg0 != reg1) { + jitCompPutByte2(w.dst, 0x89, 0xc0 | reg1 << 3 | reg0); /* MOV(reg0, reg1); */ + } + } + if (*src == 0x18) { jitCompPutByte3(w.dst, 0xc1, 0xe0 | reg0, w.r3f); } /* SHL(reg0, im8); */ + if (*src == 0x19) { jitCompPutByte3(w.dst, 0xc1, 0xf8 | reg0, w.r3f); } /* SAR(reg0, im8); */ + if (reg0 == 0 /* EAX */) + jitCompA0001_movRxxEax(&w, src[1]); + cmp0reg = src[1]; + cmp0lev = 1; + break; + } #endif - jitCompA000_storeRegCacheAll(&w); // 手抜き. - jitCompA0001_movReg32EbpDisp(&w, 1 /* ECX */, src[3] * 4); /* MOV(ECX, [EBP+?]); */ + jitCompA000_storeRegCacheAll(&w); // 手抜き. + jitCompA0001_movReg32EbpDisp(&w, 1 /* ECX */, src[3] * 4); /* MOV(ECX, [EBP+?]); */ #if (jitCompA0001_USE_R3F_IMM32 != 0) - if (src[2] == 0x3f) { - jitCompPutByte1(w.dst, 0xb8); /* MOV(EAX, ?); */ - jitCompPutImm32(&w, w.r3f); - } - else { - jitCompA0001_movEaxRxx(&w, src[2]); - } + if (src[2] == 0x3f) { + jitCompPutByte1(w.dst, 0xb8); /* MOV(EAX, ?); */ + jitCompPutImm32(&w, w.r3f); + } + else { + jitCompA0001_movEaxRxx(&w, src[2]); + } #else - jitCompA0001_movEaxRxx(&w, src[2]); + jitCompA0001_movEaxRxx(&w, src[2]); #endif - if (*src == 0x18) { jitCompPutByte2(w.dst, 0xd3, 0xe0); } /* SHL(EAX, CL); */ - if (*src == 0x19) { jitCompPutByte2(w.dst, 0xd3, 0xf8); } /* SAR(EAX, CL); */ - jitCompA0001_movRxxEax(&w, src[1]); - jitCompA000_loadRegCacheAll(&w); // 手抜き. - cmp0reg = src[1]; - cmp0lev = 1; - break; - - case 0x1a: /* DIV */ - case 0x1b: /* MOD */ - if (src[1] >= 0x3f) w.err = JITC_ERR_REGNUM; - if (src[2] >= 0x40) w.err = JITC_ERR_REGNUM; - if (src[3] >= 0x40) w.err = JITC_ERR_REGNUM; - jitCompA000_storeRegCacheAll(&w); // 手抜き. + if (*src == 0x18) { jitCompPutByte2(w.dst, 0xd3, 0xe0); } /* SHL(EAX, CL); */ + if (*src == 0x19) { jitCompPutByte2(w.dst, 0xd3, 0xf8); } /* SAR(EAX, CL); */ + jitCompA0001_movRxxEax(&w, src[1]); + jitCompA000_loadRegCacheAll(&w); // 手抜き. + cmp0reg = src[1]; + cmp0lev = 1; + break; + + case 0x1a: /* DIV */ + case 0x1b: /* MOD */ + if (src[1] >= 0x3f) w.err = JITC_ERR_REGNUM; + if (src[2] >= 0x40) w.err = JITC_ERR_REGNUM; + if (src[3] >= 0x40) w.err = JITC_ERR_REGNUM; + jitCompA000_storeRegCacheAll(&w); // 手抜き. #if (jitCompA0001_USE_R3F_IMM32 != 0) - if (src[3] == 0x3f) { - jitCompPutByte1(w.dst, 0xb8 | 1); /* MOV(ECX, ?); */ - jitCompPutImm32(&w, w.r3f); - } - else { - jitCompA0001_movReg32EbpDisp(&w, 1 /* ECX */, src[3] * 4); /* MOV(ECX, [EBP+?]); */ - } - if (src[2] == 0x3f) { - jitCompPutByte1(w.dst, 0xb8 | 0); /* MOV(EAX, ?); */ - jitCompPutImm32(&w, w.r3f); - } - else { - jitCompA0001_movReg32EbpDisp(&w, 0 /* EAX */, src[2] * 4); /* MOV(EAX, [EBP+?]); */ - } + if (src[3] == 0x3f) { + jitCompPutByte1(w.dst, 0xb8 | 1); /* MOV(ECX, ?); */ + jitCompPutImm32(&w, w.r3f); + } + else { + jitCompA0001_movReg32EbpDisp(&w, 1 /* ECX */, src[3] * 4); /* MOV(ECX, [EBP+?]); */ + } + if (src[2] == 0x3f) { + jitCompPutByte1(w.dst, 0xb8 | 0); /* MOV(EAX, ?); */ + jitCompPutImm32(&w, w.r3f); + } + else { + jitCompA0001_movReg32EbpDisp(&w, 0 /* EAX */, src[2] * 4); /* MOV(EAX, [EBP+?]); */ + } #else - jitCompA0001_movReg32EbpDisp(&w, 1 /* ECX */, src[3] * 4); /* MOV(ECX, [EBP+?]); */ - jitCompA0001_movReg32EbpDisp(&w, 0 /* EAX */, src[2] * 4); /* MOV(EAX, [EBP+?]); */ + jitCompA0001_movReg32EbpDisp(&w, 1 /* ECX */, src[3] * 4); /* MOV(ECX, [EBP+?]); */ + jitCompA0001_movReg32EbpDisp(&w, 0 /* EAX */, src[2] * 4); /* MOV(EAX, [EBP+?]); */ #endif - jitCompPutByte1(w.dst, 0x99); /* CDQ(); */ - /* ECXがゼロではないことを確認すべき */ - jitCompPutByte2(w.dst, 0xf7, 0xf9); /* IDIV(ECX); */ - if (*src == 0x1a) { jitCompA0001_movEbpDispReg32(&w, src[1] * 4, 0 /* EAX */); } - if (*src == 0x1b) { jitCompA0001_movEbpDispReg32(&w, src[1] * 4, 2 /* EDX */); } - jitCompA000_loadRegCacheAll(&w); // 手抜き. - cmp0reg = -1; - break; - - case 0x1c: /* PLMT0 */ - case 0x1d: /* PLMT1 */ - if (src[1] >= 0x40 || src[2] >= 0x40) w.err = JITC_ERR_PREGNUM; - if (level < JITC_LV_FASTEST) { - cmp0reg = -1; - if (level < JITC_LV_FASTER) { - // typ が一致していることを確認. - // plsとliveSignが一致していることを確認. - - // preg1はp0 <= p <= p1 を満たしているか?. - // 新しいp0/p1は古いp0〜p1に適合しているか?. - - } - } - - case 0x1e: /* PCP */ /* 未完成(p1まで完成) */ - if (src[1] >= 0x40 || src[2] >= 0x40) w.err = JITC_ERR_PREGNUM; - if (src[2] == 0x3f) w.err = JITC_ERR_PREGNUM; - if (src[1] != 0x3f) { - /* src[2] == 0xff の場合に対応できてない */ - jitCompA000_storePRegCacheAll(&w); // 手抜き. - for (i = 0; i < 32; i += 4) { - jitCompA0001_movReg32EbpDisp(&w, 0 /* EAX */, 256 + src[2] * 32 + i); /* MOV(EAX, [EBP+?]); */ - jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + i, 0 /* EAX */); /* MOV([EBP+?], EAX); */ - } - jitCompA000_loadPRegCacheAll(&w); // 手抜き. - } - else { - if (level < JITC_LV_FASTER) { - jitCompA0001_movReg32EbpDisp(&w, 0 /* EAX */, 256 + src[2] * 32 + 4); /* MOV(EAX, [EBP+?]); */ /* typ */ - jitCompPutByte3(w.dst, 0x83, 0xf8, 0); /* CMP(EAX, 0); */ - jitCompPutByte2(w.dst, 0x0f, 0x85); /* JNE */ - jitCompPutImm32(&w, errfnc - (w.dst + 4)); - /* セキュリティチェックが足りてない!(aliveとか) */ - } - reg0 = 0; /* EAX */ - jitCompA000_storePRegCacheAll(&w); // 手抜き. - jitCompA0001_movReg32EbpDisp(&w, reg0, 256 + src[2] * 32 + 0); /* MOV(EAX, [EBP+?]); */ - if (level < JITC_LV_FASTER) { - jitCompPutByte1(w.dst, 0x3b); /* CMP(reg0, [EBP+?]); */ - jitCompA0001_85DispN(&w, 256 + src[2] * 32 + 8, reg0); /* p0 */ - jitCompPutByte2(w.dst, 0x0f, 0x85); /* JNE */ - jitCompPutImm32(&w, errfnc - (w.dst + 4)); - } - jitCompPutByte2(w.dst, 0xff, 0xe0); /* JMP(EAX); */ - } - break; - - case 0x1f: /* PCST */ - if (jitCompGetImm32(src + 2) == 0) { - if (level < JITC_LV_FASTER) - jitCompA0001_checkType0(&w, src[6], jitCompGetImm32(src + 7), 2); - jitCompA000_storePRegCacheAll(&w); // 手抜き. - for (i = 0; i < 32 - 4; i += 4) { - jitCompA0001_movReg32EbpDisp(&w, 0 /* EAX */, 256 + src[6] * 32 + i); /* MOV(EAX, [EBP+?]); */ - if (i == 4) { - jitCompPutByte1(w.dst, 0x0d); /* OR(EAX, ?); */ - jitCompPutImm32(&w, 0x80000000); - } - jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + i, 0 /* EAX */); /* MOV([EBP+?], EAX); */ - } - jitCompPutByte1(w.dst, 0xb8); /* MOV(EAX, ?); */ - jitCompPutImm32(&w, debugInfo1); - jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + 28, 0 /* EAX */); /* MOV([EBP+?], EAX); */ - jitCompA000_loadPRegCacheAll(&w); // 手抜き. - cmp0reg = -1; - break; - } - if (jitCompGetImm32(src + 7) == 0) { - jitCompA000_storePRegCacheAll(&w); // 手抜き. - for (i = 0; i < 32 - 4; i += 4) { - jitCompA0001_movReg32EbpDisp(&w, 0 /* EAX */, 256 + src[6] * 32 + i); /* MOV(EAX, [EBP+?]); */ - if (i == 4) { - jitCompPutByte1(w.dst, 0x25); /* AND(EAX, ?); */ - jitCompPutImm32(&w, 0x7fffffff); - } - jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + i, 0 /* EAX */); /* MOV([EBP+?], EAX); */ - } - if (level < JITC_LV_FASTER) { - jitCompA0001_movReg32EbpDisp(&w, 0 /* EAX */, 256 + src[6] * 32 + 28); /* MOV(EAX, [EBP+?]); */ - jitCompPutByte1(w.dst, 0x3d); /* CMP(EAX, ?); */ - jitCompPutImm32(&w, debugInfo1); - jitCompPutByte2(w.dst, 0x74, 8); /* JE */ - jitCompPutByte2(w.dst, 0x31, 0xc0); /* XOR(EAX, EAX); (2) */ - jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + 0, 0 /* EAX */); /* MOV([EBP+?], EAX); (1+1+4) */ - } - jitCompA000_loadPRegCacheAll(&w); // 手抜き. - cmp0reg = -1; - break; - } - w.err = JITC_ERR_OPECODE; - goto err_w; - - case 0x20: /* CMPE */ - case 0x21: /* CMPNE */ - case 0x22: /* CMPL */ - case 0x23: /* CMPGE */ - case 0x24: /* CMPLE */ - case 0x25: /* CMPG */ - case 0x26: /* TSTZ */ - case 0x27: /* TSTNZ */ - reg0 = jitCompA000_selectRegCache(src[2], 0 /* EAX */); - reg1 = jitCompA000_selectRegCache(src[3], -1 /* mem */); - if (src[1] == 0x3f) { - /* 特殊構文チェック */ - if (w.prefix != 0) { w.err = JITC_ERR_PREFIX; goto err_w; } - if (src[4] != 0x04 || src[5] != 0x3f || src[6] != 0x03 || src[7] != 0x3f) { - w.err = JITC_ERR_IDIOM; goto err_w; - } - } - if (reg0 == 0) - jitCompA0001_movEaxRxx(&w, src[2]); + jitCompPutByte1(w.dst, 0x99); /* CDQ(); */ + /* ECXがゼロではないことを確認すべき */ + jitCompPutByte2(w.dst, 0xf7, 0xf9); /* IDIV(ECX); */ + if (*src == 0x1a) { jitCompA0001_movEbpDispReg32(&w, src[1] * 4, 0 /* EAX */); } + if (*src == 0x1b) { jitCompA0001_movEbpDispReg32(&w, src[1] * 4, 2 /* EDX */); } + jitCompA000_loadRegCacheAll(&w); // 手抜き. + cmp0reg = -1; + break; + + case 0x1c: /* PLMT0 */ + case 0x1d: /* PLMT1 */ + if (src[1] >= 0x40 || src[2] >= 0x40) w.err = JITC_ERR_PREGNUM; + if (level < JITC_LV_FASTEST) { + cmp0reg = -1; + if (level < JITC_LV_FASTER) { + // typ が一致していることを確認. + // plsとliveSignが一致していることを確認. + + // preg1はp0 <= p <= p1 を満たしているか?. + // 新しいp0/p1は古いp0〜p1に適合しているか?. + + } + } + + case 0x1e: /* PCP */ /* 未完成(p1まで完成) */ + if (src[1] >= 0x40 || src[2] >= 0x40) w.err = JITC_ERR_PREGNUM; + if (src[2] == 0x3f) w.err = JITC_ERR_PREGNUM; + if (src[1] != 0x3f) { + /* src[2] == 0xff の場合に対応できてない */ + jitCompA000_storePRegCacheAll(&w); // 手抜き. + for (i = 0; i < 32; i += 4) { + jitCompA0001_movReg32EbpDisp(&w, 0 /* EAX */, 256 + src[2] * 32 + i); /* MOV(EAX, [EBP+?]); */ + jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + i, 0 /* EAX */); /* MOV([EBP+?], EAX); */ + } + jitCompA000_loadPRegCacheAll(&w); // 手抜き. + } + else { + if (level < JITC_LV_FASTER) { + jitCompA0001_movReg32EbpDisp(&w, 0 /* EAX */, 256 + src[2] * 32 + 4); /* MOV(EAX, [EBP+?]); */ /* typ */ + jitCompPutByte3(w.dst, 0x83, 0xf8, 0); /* CMP(EAX, 0); */ + jitCompPutByte2(w.dst, 0x0f, 0x85); /* JNE */ + jitCompPutImm32(&w, errfnc - (w.dst + 4)); + /* セキュリティチェックが足りてない!(aliveとか) */ + } + reg0 = 0; /* EAX */ + jitCompA000_storePRegCacheAll(&w); // 手抜き. + jitCompA0001_movReg32EbpDisp(&w, reg0, 256 + src[2] * 32 + 0); /* MOV(EAX, [EBP+?]); */ + if (level < JITC_LV_FASTER) { + jitCompPutByte1(w.dst, 0x3b); /* CMP(reg0, [EBP+?]); */ + jitCompA0001_85DispN(&w, 256 + src[2] * 32 + 8, reg0); /* p0 */ + jitCompPutByte2(w.dst, 0x0f, 0x85); /* JNE */ + jitCompPutImm32(&w, errfnc - (w.dst + 4)); + } + jitCompPutByte2(w.dst, 0xff, 0xe0); /* JMP(EAX); */ + } + break; + + case 0x1f: /* PCST */ + if (jitCompGetImm32(src + 2) == 0) { + if (level < JITC_LV_FASTER) + jitCompA0001_checkType0(&w, src[6], jitCompGetImm32(src + 7), 2); + jitCompA000_storePRegCacheAll(&w); // 手抜き. + for (i = 0; i < 32 - 4; i += 4) { + jitCompA0001_movReg32EbpDisp(&w, 0 /* EAX */, 256 + src[6] * 32 + i); /* MOV(EAX, [EBP+?]); */ + if (i == 4) { + jitCompPutByte1(w.dst, 0x0d); /* OR(EAX, ?); */ + jitCompPutImm32(&w, 0x80000000); + } + jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + i, 0 /* EAX */); /* MOV([EBP+?], EAX); */ + } + jitCompPutByte1(w.dst, 0xb8); /* MOV(EAX, ?); */ + jitCompPutImm32(&w, debugInfo1); + jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + 28, 0 /* EAX */); /* MOV([EBP+?], EAX); */ + jitCompA000_loadPRegCacheAll(&w); // 手抜き. + cmp0reg = -1; + break; + } + if (jitCompGetImm32(src + 7) == 0) { + jitCompA000_storePRegCacheAll(&w); // 手抜き. + for (i = 0; i < 32 - 4; i += 4) { + jitCompA0001_movReg32EbpDisp(&w, 0 /* EAX */, 256 + src[6] * 32 + i); /* MOV(EAX, [EBP+?]); */ + if (i == 4) { + jitCompPutByte1(w.dst, 0x25); /* AND(EAX, ?); */ + jitCompPutImm32(&w, 0x7fffffff); + } + jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + i, 0 /* EAX */); /* MOV([EBP+?], EAX); */ + } + if (level < JITC_LV_FASTER) { + jitCompA0001_movReg32EbpDisp(&w, 0 /* EAX */, 256 + src[6] * 32 + 28); /* MOV(EAX, [EBP+?]); */ + jitCompPutByte1(w.dst, 0x3d); /* CMP(EAX, ?); */ + jitCompPutImm32(&w, debugInfo1); + jitCompPutByte2(w.dst, 0x74, 8); /* JE */ + jitCompPutByte2(w.dst, 0x31, 0xc0); /* XOR(EAX, EAX); (2) */ + jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + 0, 0 /* EAX */); /* MOV([EBP+?], EAX); (1+1+4) */ + } + jitCompA000_loadPRegCacheAll(&w); // 手抜き. + cmp0reg = -1; + break; + } + w.err = JITC_ERR_OPECODE; + goto err_w; + + case 0x20: /* CMPE */ + case 0x21: /* CMPNE */ + case 0x22: /* CMPL */ + case 0x23: /* CMPGE */ + case 0x24: /* CMPLE */ + case 0x25: /* CMPG */ + case 0x26: /* TSTZ */ + case 0x27: /* TSTNZ */ + reg0 = jitCompA000_selectRegCache(src[2], 0 /* EAX */); + reg1 = jitCompA000_selectRegCache(src[3], -1 /* mem */); + if (src[1] == 0x3f) { + /* 特殊構文チェック */ + if (w.prefix != 0) { w.err = JITC_ERR_PREFIX; goto err_w; } + if (src[4] != 0x04 || src[5] != 0x3f || src[6] != 0x03 || src[7] != 0x3f) { + w.err = JITC_ERR_IDIOM; goto err_w; + } + } + if (reg0 == 0) + jitCompA0001_movEaxRxx(&w, src[2]); #if (jitCompA0001_USE_R3F_IMM32 != 0) - if (src[3] == 0x3f) { + if (src[3] == 0x3f) { #if (jitCompA0001_OPTIMIZE_CMP != 0) - if ((*src <= 0x25 && w.r3f == 0) || (*src >= 0x26 && w.r3f == -1)) { - i = 0; - if (cmp0reg == src[2]) { - if (cmp0lev >= 1 && (src[0] == 0x20 || src[0] == 0x21 || src[0] == 0x26 || src[0] == 0x27)) - i = 1; - if (cmp0lev >= 2 && (src[0] == 0x22 || src[0] == 0x23 || src[0] == 0x24 || src[0] == 0x25)) - i = 1; - } - if (i == 0) { - jitCompPutByte2(w.dst, 0x85, 0xc0 | reg0 << 3 | reg0); /* TEST(reg0, reg0); */ - } - cmp0reg = src[2]; - cmp0lev = 2; - goto cmpcc1; - } + if ((*src <= 0x25 && w.r3f == 0) || (*src >= 0x26 && w.r3f == -1)) { + i = 0; + if (cmp0reg == src[2]) { + if (cmp0lev >= 1 && (src[0] == 0x20 || src[0] == 0x21 || src[0] == 0x26 || src[0] == 0x27)) + i = 1; + if (cmp0lev >= 2 && (src[0] == 0x22 || src[0] == 0x23 || src[0] == 0x24 || src[0] == 0x25)) + i = 1; + } + if (i == 0) { + jitCompPutByte2(w.dst, 0x85, 0xc0 | reg0 << 3 | reg0); /* TEST(reg0, reg0); */ + } + cmp0reg = src[2]; + cmp0lev = 2; + goto cmpcc1; + } #endif #if (jitCompA0001_USE_R3F_IMM8 != 0) - if (-0x80 <= w.r3f && w.r3f <= 0x7f && *src <= 0x25) { - jitCompPutByte3(w.dst, 0x83, 0xf8 | reg0, w.r3f); - goto cmpcc1; - } + if (-0x80 <= w.r3f && w.r3f <= 0x7f && *src <= 0x25) { + jitCompPutByte3(w.dst, 0x83, 0xf8 | reg0, w.r3f); + goto cmpcc1; + } #endif - if (reg0 == 0) { - if (*src <= 0x25) { jitCompPutByte1(w.dst, 0x3d); } - if (*src >= 0x26) { jitCompPutByte1(w.dst, 0xa9); } - } - else { - if (*src <= 0x25) { jitCompPutByte2(w.dst, 0x81, 0xf8 | reg0); } - if (*src >= 0x26) { jitCompPutByte2(w.dst, 0xf7, 0xc0 | reg0); } - } - jitCompPutImm32(&w, w.r3f); - goto cmpcc1; - } + if (reg0 == 0) { + if (*src <= 0x25) { jitCompPutByte1(w.dst, 0x3d); } + if (*src >= 0x26) { jitCompPutByte1(w.dst, 0xa9); } + } + else { + if (*src <= 0x25) { jitCompPutByte2(w.dst, 0x81, 0xf8 | reg0); } + if (*src >= 0x26) { jitCompPutByte2(w.dst, 0xf7, 0xc0 | reg0); } + } + jitCompPutImm32(&w, w.r3f); + goto cmpcc1; + } #endif - if (src[3] >= 0x40) w.err = JITC_ERR_PREGNUM; - if (reg1 >= 0) { - if (*src <= 0x25) { jitCompPutByte2(w.dst, 0x39, 0xc0 | reg1 << 3 | reg0); } - if (*src >= 0x26) { jitCompPutByte2(w.dst, 0x85, 0xc0 | reg1 << 3 | reg0); } - } - else { - if (*src <= 0x25) { jitCompPutByte1(w.dst, 0x3b); } - if (*src >= 0x26) { jitCompPutByte1(w.dst, 0x85); } - jitCompA0001_85DispN(&w, src[3] * 4, reg0); - } - cmpcc1: - if (w.err != 0) goto err_w; - static unsigned char cmpcc_table0[] = { - 0x04, 0x05, 0x0c, 0x0d, 0x0e, 0x0f, 0x04, 0x05, /* CMPcc, TSTcc */ - 0x04, 0x05, 0x02, 0x03, 0x06, 0x07 /* PCMPcc */ - }; + if (src[3] >= 0x40) w.err = JITC_ERR_PREGNUM; + if (reg1 >= 0) { + if (*src <= 0x25) { jitCompPutByte2(w.dst, 0x39, 0xc0 | reg1 << 3 | reg0); } + if (*src >= 0x26) { jitCompPutByte2(w.dst, 0x85, 0xc0 | reg1 << 3 | reg0); } + } + else { + if (*src <= 0x25) { jitCompPutByte1(w.dst, 0x3b); } + if (*src >= 0x26) { jitCompPutByte1(w.dst, 0x85); } + jitCompA0001_85DispN(&w, src[3] * 4, reg0); + } + cmpcc1: + if (w.err != 0) goto err_w; + static unsigned char cmpcc_table0[] = { + 0x04, 0x05, 0x0c, 0x0d, 0x0e, 0x0f, 0x04, 0x05, /* CMPcc, TSTcc */ + 0x04, 0x05, 0x02, 0x03, 0x06, 0x07 /* PCMPcc */ + }; #if (jitCompA0001_USE_R3F_CMPJMP != 0) - if (src[1] == 0x3f) { - /* 特殊構文を利用した最適化 */ - jitCompPutByte2(w.dst, 0x0f, 0x80 | cmpcc_table0[*src - 0x20]); - src += 6; - i = jitCompGetLabelNum(&w, src + 2); - if ((flags & JITC_PHASE1) != 0 && w.err != 0) { - if (label[i].opt == 0) { w.err = JITC_ERR_LABELNODEF; goto err_w; } - // if (label[i].typ != 1) { w.err = JITC_ERR_LABELTYP; goto err_w; } - } - j = 0; - if ((flags & JITC_PHASE1) != 0 || (((flags & JITC_PHASE1) == 0) && label[i].opt != 0)) - j = label[i].p - (w.dst + 4); - jitCompPutImm32(&w, j); + if (src[1] == 0x3f) { + /* 特殊構文を利用した最適化 */ + jitCompPutByte2(w.dst, 0x0f, 0x80 | cmpcc_table0[*src - 0x20]); + src += 6; + i = jitCompGetLabelNum(&w, src + 2); + if ((flags & JITC_PHASE1) != 0 && w.err != 0) { + if (label[i].opt == 0) { w.err = JITC_ERR_LABELNODEF; goto err_w; } + // if (label[i].typ != 1) { w.err = JITC_ERR_LABELTYP; goto err_w; } + } + j = 0; + if ((flags & JITC_PHASE1) != 0 || (((flags & JITC_PHASE1) == 0) && label[i].opt != 0)) + j = label[i].p - (w.dst + 4); + jitCompPutImm32(&w, j); #if (jitCompA0001_OPTIMIZE_JMP != 0) - if (-128 - 4 <= j && j < 0) { - j += 4; - w.dst -= 6; - jitCompPutByte2(w.dst, w.dst[1] ^ 0xf0, j & 0xff); - } + if (-128 - 4 <= j && j < 0) { + j += 4; + w.dst -= 6; + jitCompPutByte2(w.dst, w.dst[1] ^ 0xf0, j & 0xff); + } #endif - src += 6; - if (w.err != 0) goto err_w; - continue; - } + src += 6; + if (w.err != 0) goto err_w; + continue; + } #endif - /* 一般的なJITC */ - reg0 = jitCompA000_selectRegCache(src[1], 0 /* EAX */); - jitCompPutByte3(w.dst, 0x0f, 0x90 | cmpcc_table0[*src - 0x20], 0xc0 | reg0); /* SETcc(BYTE(reg0)); */ - jitCompPutByte3(w.dst, 0x0f, 0xb6, 0xc0 | reg0 << 3 | reg0); /* MOVZX(reg0, BYTE(reg0)); */ - jitCompPutByte2(w.dst, 0xf7, 0xd8 | reg0); /* NEG(reg0); */ - if (reg0 == 0) - jitCompA0001_movRxxEax(&w, src[1]); - cmp0reg = src[2]; - cmp0lev = 1; - break; - - case 0x28: /* PCMPE */ - case 0x29: /* PCMPNE */ - case 0x2a: /* PCMPL */ - case 0x2b: /* PCMPGE */ - case 0x2c: /* PCMPLE */ - case 0x2d: /* PCMPG */ - if (src[1] == 0x3f) { - /* 特殊構文チェック */ - if (w.prefix != 0) { w.err = JITC_ERR_PREFIX; goto err_w; } - if (src[4] != 0x04 || src[5] != 0x3f || src[6] != 0x03 || src[7] != 0x3f) { - w.err = JITC_ERR_IDIOM; goto err_w; - } - } - if (src[2] >= 0x40) w.err = JITC_ERR_PREGNUM; - jitCompA000_storePRegCacheAll(&w); // 手抜き. - if (src[3] != 0xff) - jitCompA0001_checkCompPtr(&w, src[2], src[3]); - jitCompA0001_movReg32EbpDisp(&w, 0 /* EAX */, 256 + src[2] * 32 + 0); /* MOV(EAX, [EBP+?]); */ - if (src[3] != 0xff) { - jitCompPutByte1(w.dst, 0x3b); /* CMP(EAX, [EBP+?]); */ - jitCompA0001_85DispN(&w, 256 + src[3] * 32 + 0, 0); - } - else { - /* ヌルポインタとの比較はこれでいいのか?たぶんよくない */ - jitCompPutByte3(w.dst, 0x83, 0xf8, 0x00); /* CMP(EAX, 0); */ - } - cmp0reg = -1; - goto cmpcc1; - - case 0x30: /* talloc(old:F4) */ - case 0x31: /* tfree(old:F5) */ - case 0x32: /* malloc(old:F6) */ - case 0x33: /* mfree(old:F7) */ - jitCompA000_storeRegCacheAll(&w); // 手抜き. - jitCompA000_storePRegCacheAll(&w); // 手抜き. - jitCompPutByte2(w.dst, 0x6a, src[3]); /* PUSH(?); */ - jitCompPutByte2(w.dst, 0x6a, src[2]); /* PUSH(?); */ - jitCompPutByte2(w.dst, 0x6a, src[1]); /* PUSH(?); */ - jitCompPutByte1(w.dst, 0x55); /* PUSH(EBP); */ - jitCompPutByte1(w.dst, 0xe8); - if (*src == 0x30) j = ((unsigned char *)&funcf4) - (w.dst + 4); - if (*src == 0x31) j = ((unsigned char *)&funcf5) - (w.dst + 4); - if (*src == 0x32) j = ((unsigned char *)&funcf6) - (w.dst + 4); - if (*src == 0x33) j = ((unsigned char *)&funcf7) - (w.dst + 4); - jitCompPutImm32(&w, j); - jitCompPutByte3(w.dst, 0x83, 0xc4, 0x10); /* ADD(ESP,16); */ - jitCompA000_loadRegCacheAll(&w); // 手抜き. - jitCompA000_loadPRegCacheAll(&w); // 手抜き. - cmp0reg = -1; - break; - - case 0x34: /* data (暫定) */ - cmp0reg = -1; - if (w.prefix != 0) { w.err = JITC_ERR_PREFIX; goto err_w; } - int k = jitCompGetImm32(&src[1]), tmpData, bitCount, dataWidth = jitCompA000_dataWidth(k); - if (lastlabel >= 0 && label[lastlabel].typ == 0) - label[lastlabel].typ = k; - if (k != 1) { - i = jitCompA000_convTyp(k); - if (i < 2 || i > 7) { w.err = JITC_ERR_BADTYPE; goto err_w; } - } - j = jitCompGetImm32(&src[5]); - oldsrc = src; - src += 9; - if (k != 1) { - bitCount = 7; - while (j > 0) { - if (src >= src1) { w.err = JITC_ERR_SRC1; src = oldsrc; goto err_w; } - if (w.dst + 256 > dst1) { w.err = JITC_ERR_DST1; src = oldsrc; goto err_w; } - tmpData = 0; - for (k = 0; k < dataWidth; k++) { - tmpData = tmpData << 1 | ((*src >> bitCount) & 1); - bitCount--; - if (bitCount < 0) { - bitCount = 7; - src++; - } - } - if ((i & 1) == 0 && dataWidth <= 31 && (tmpData >> (dataWidth - 1)) != 0) { - tmpData -= 1 << dataWidth; - } - if (i == 2 || i == 3) { jitCompPutByte1(w.dst, tmpData & 0xff); } - if (i == 4 || i == 5) { jitCompPutByte2(w.dst, tmpData & 0xff, (tmpData >> 8) & 0xff); } - if (i == 6 || i == 7) { jitCompPutByte4(w.dst, tmpData & 0xff, (tmpData >> 8) & 0xff, (tmpData >> 16) & 0xff, (tmpData >> 24) & 0xff); } - j--; - } - } - else { - while (j > 0) { - if (src >= src1) { w.err = JITC_ERR_SRC1; src = oldsrc; goto err_w; } - if (w.dst + 256 > dst1) { w.err = JITC_ERR_DST1; src = oldsrc; goto err_w; } - i = jitCompGetImm32(src); - src += 4; - if ((flags & JITC_PHASE1) != 0 && w.err == 0) { - if (label[i].opt == 0) { w.err = JITC_ERR_LABELNODEF; goto err_w; } - } - jitCompPutImm32(&w, (int)label[i].p); - jitCompPutImm32(&w, label[i].typ); - jitCompPutImm32(&w, (int)label[i].p); - jitCompPutImm32(&w, (int)label[i].p1); - jitCompPutImm32(&w, 0); /* liveSign */ - jitCompPutImm32(&w, 2320); /* pls */ - jitCompPutImm32(&w, 0); - jitCompPutImm32(&w, 0); - j--; - } - } - if (lastlabel >= 0 && label[lastlabel].p1 < w.dst) - label[lastlabel].p1 = w.dst; - continue; - - case 0x3c: /* ENTER */ - jitCompA000_storeRegCacheAll(&w); // 手抜き. - jitCompA000_storePRegCacheAll(&w); // 手抜き. - jitCompPutByte2(w.dst, 0x6a, src[6]); /* PUSH(?); */ - jitCompPutByte2(w.dst, 0x6a, src[5]); /* PUSH(?); */ - jitCompPutByte2(w.dst, 0x6a, src[4] & 0x0f); /* PUSH(?); */ - jitCompPutByte2(w.dst, 0x6a, (src[4] >> 4) & 0x0f); /* PUSH(?); */ - jitCompPutByte2(w.dst, 0x6a, src[3]); /* PUSH(?); */ - jitCompPutByte2(w.dst, 0x6a, src[2]); /* PUSH(?); */ - jitCompPutByte2(w.dst, 0x6a, src[1]); /* PUSH(?); */ - jitCompPutByte1(w.dst, 0x55); /* PUSH(EBP); */ - jitCompPutByte1(w.dst, 0xe8); - j = ((unsigned char *)&func3c) - (w.dst + 4); - jitCompPutImm32(&w, j); - jitCompPutByte3(w.dst, 0x83, 0xc4, 0x20); /* ADD(ESP,32); */ - jitCompA000_loadRegCacheAll(&w); // 手抜き. - jitCompA000_loadPRegCacheAll(&w); // 手抜き. - cmp0reg = -1; - break; - - case 0x3d: /* LEAVE */ - jitCompA000_storeRegCacheAll(&w); // 手抜き. - jitCompA000_storePRegCacheAll(&w); // 手抜き. - jitCompPutByte2(w.dst, 0x6a, src[6]); /* PUSH(?); */ - jitCompPutByte2(w.dst, 0x6a, src[5]); /* PUSH(?); */ - jitCompPutByte2(w.dst, 0x6a, src[4] & 0x0f); /* PUSH(?); */ - jitCompPutByte2(w.dst, 0x6a, (src[4] >> 4) & 0x0f); /* PUSH(?); */ - jitCompPutByte2(w.dst, 0x6a, src[3]); /* PUSH(?); */ - jitCompPutByte2(w.dst, 0x6a, src[2]); /* PUSH(?); */ - jitCompPutByte2(w.dst, 0x6a, src[1]); /* PUSH(?); */ - jitCompPutByte1(w.dst, 0x55); /* PUSH(EBP); */ - jitCompPutByte1(w.dst, 0xe8); - j = ((unsigned char *)&func3d) - (w.dst + 4); - jitCompPutImm32(&w, j); - jitCompPutByte3(w.dst, 0x83, 0xc4, 0x20); /* ADD(ESP,32); */ - jitCompA000_loadRegCacheAll(&w); // 手抜き. - jitCompA000_loadPRegCacheAll(&w); // 手抜き. - cmp0reg = -1; - break; - - case 0xfe: /* remark */ - if (src[1] == 0x01 && src[2] == 0x00) { // DBGINFO1 - if (level <= JITC_LV_SLOWER) { - jitCompPutByte1(w.dst, 0xb8); /* MOV(EAX, ?); */ - jitCompPutImm32(&w, debugInfo1); - jitCompA0001_movEbpDispReg32(&w, 2304 + 4, 0 /* EAX */); /* MOV(debugInfo1, EAX); */ - } - } - if (src[1] == 0x01 && src[2] == 0x03) { // DBGINFO1CLR - if (level <= JITC_LV_SLOWER) { - jitCompPutByte1(w.dst, 0xb8); /* MOV(EAX, ?); */ - jitCompPutImm32(&w, -1); - jitCompA0001_movEbpDispReg32(&w, 2304 + 4, 0 /* EAX */); /* MOV(debugInfo1, EAX); */ - } - } - if (src[1] == 0x05 && src[2] == 0x00) { // DBGINFO0 - if (level <= JITC_LV_SLOWEST) { - debugInfo0 = jitCompGetImm32(src + 3); - // jitCompPutByte1(w.dst, 0xbf); /* MOV(EDI, ?); */ - // jitCompPutImm32(&w, debugInfo0); - jitCompPutByte1(w.dst, 0xb8); /* MOV(EAX, ?); */ - jitCompPutImm32(&w, debugInfo0); - jitCompA0001_movEbpDispReg32(&w, 2304 + 0, 0 /* EAX */); /* MOV(debugInfo0, EAX); */ - } - } - break; - - default: - w.err = JITC_ERR_OPECODE; - goto err_w; + /* 一般的なJITC */ + reg0 = jitCompA000_selectRegCache(src[1], 0 /* EAX */); + jitCompPutByte3(w.dst, 0x0f, 0x90 | cmpcc_table0[*src - 0x20], 0xc0 | reg0); /* SETcc(BYTE(reg0)); */ + jitCompPutByte3(w.dst, 0x0f, 0xb6, 0xc0 | reg0 << 3 | reg0); /* MOVZX(reg0, BYTE(reg0)); */ + jitCompPutByte2(w.dst, 0xf7, 0xd8 | reg0); /* NEG(reg0); */ + if (reg0 == 0) + jitCompA0001_movRxxEax(&w, src[1]); + cmp0reg = src[2]; + cmp0lev = 1; + break; + + case 0x28: /* PCMPE */ + case 0x29: /* PCMPNE */ + case 0x2a: /* PCMPL */ + case 0x2b: /* PCMPGE */ + case 0x2c: /* PCMPLE */ + case 0x2d: /* PCMPG */ + if (src[1] == 0x3f) { + /* 特殊構文チェック */ + if (w.prefix != 0) { w.err = JITC_ERR_PREFIX; goto err_w; } + if (src[4] != 0x04 || src[5] != 0x3f || src[6] != 0x03 || src[7] != 0x3f) { + w.err = JITC_ERR_IDIOM; goto err_w; + } + } + if (src[2] >= 0x40) w.err = JITC_ERR_PREGNUM; + jitCompA000_storePRegCacheAll(&w); // 手抜き. + if (src[3] != 0xff) + jitCompA0001_checkCompPtr(&w, src[2], src[3]); + jitCompA0001_movReg32EbpDisp(&w, 0 /* EAX */, 256 + src[2] * 32 + 0); /* MOV(EAX, [EBP+?]); */ + if (src[3] != 0xff) { + jitCompPutByte1(w.dst, 0x3b); /* CMP(EAX, [EBP+?]); */ + jitCompA0001_85DispN(&w, 256 + src[3] * 32 + 0, 0); + } + else { + /* ヌルポインタとの比較はこれでいいのか?たぶんよくない */ + jitCompPutByte3(w.dst, 0x83, 0xf8, 0x00); /* CMP(EAX, 0); */ + } + cmp0reg = -1; + goto cmpcc1; + + case 0x30: /* talloc(old:F4) */ + case 0x31: /* tfree(old:F5) */ + case 0x32: /* malloc(old:F6) */ + case 0x33: /* mfree(old:F7) */ + jitCompA000_storeRegCacheAll(&w); // 手抜き. + jitCompA000_storePRegCacheAll(&w); // 手抜き. + jitCompPutByte2(w.dst, 0x6a, src[3]); /* PUSH(?); */ + jitCompPutByte2(w.dst, 0x6a, src[2]); /* PUSH(?); */ + jitCompPutByte2(w.dst, 0x6a, src[1]); /* PUSH(?); */ + jitCompPutByte1(w.dst, 0x55); /* PUSH(EBP); */ + jitCompPutByte1(w.dst, 0xe8); + if (*src == 0x30) j = ((unsigned char *)&funcf4) - (w.dst + 4); + if (*src == 0x31) j = ((unsigned char *)&funcf5) - (w.dst + 4); + if (*src == 0x32) j = ((unsigned char *)&funcf6) - (w.dst + 4); + if (*src == 0x33) j = ((unsigned char *)&funcf7) - (w.dst + 4); + jitCompPutImm32(&w, j); + jitCompPutByte3(w.dst, 0x83, 0xc4, 0x10); /* ADD(ESP,16); */ + jitCompA000_loadRegCacheAll(&w); // 手抜き. + jitCompA000_loadPRegCacheAll(&w); // 手抜き. + cmp0reg = -1; + break; + + case 0x34: /* data (暫定) */ + cmp0reg = -1; + if (w.prefix != 0) { w.err = JITC_ERR_PREFIX; goto err_w; } + int k = jitCompGetImm32(&src[1]), tmpData, bitCount, dataWidth = jitCompA000_dataWidth(k); + if (lastlabel >= 0 && label[lastlabel].typ == 0) + label[lastlabel].typ = k; + if (k != 1) { + i = jitCompA000_convTyp(k); + if (i < 2 || i > 7) { w.err = JITC_ERR_BADTYPE; goto err_w; } + } + j = jitCompGetImm32(&src[5]); + oldsrc = src; + src += 9; + if (k != 1) { + bitCount = 7; + while (j > 0) { + if (src >= src1) { w.err = JITC_ERR_SRC1; src = oldsrc; goto err_w; } + if (w.dst + 256 > dst1) { w.err = JITC_ERR_DST1; src = oldsrc; goto err_w; } + tmpData = 0; + for (k = 0; k < dataWidth; k++) { + tmpData = tmpData << 1 | ((*src >> bitCount) & 1); + bitCount--; + if (bitCount < 0) { + bitCount = 7; + src++; + } + } + if ((i & 1) == 0 && dataWidth <= 31 && (tmpData >> (dataWidth - 1)) != 0) { + tmpData -= 1 << dataWidth; + } + if (i == 2 || i == 3) { jitCompPutByte1(w.dst, tmpData & 0xff); } + if (i == 4 || i == 5) { jitCompPutByte2(w.dst, tmpData & 0xff, (tmpData >> 8) & 0xff); } + if (i == 6 || i == 7) { jitCompPutByte4(w.dst, tmpData & 0xff, (tmpData >> 8) & 0xff, (tmpData >> 16) & 0xff, (tmpData >> 24) & 0xff); } + j--; + } + } + else { + while (j > 0) { + if (src >= src1) { w.err = JITC_ERR_SRC1; src = oldsrc; goto err_w; } + if (w.dst + 256 > dst1) { w.err = JITC_ERR_DST1; src = oldsrc; goto err_w; } + i = jitCompGetImm32(src); + src += 4; + if ((flags & JITC_PHASE1) != 0 && w.err == 0) { + if (label[i].opt == 0) { w.err = JITC_ERR_LABELNODEF; goto err_w; } + } + jitCompPutImm32(&w, (int)label[i].p); + jitCompPutImm32(&w, label[i].typ); + jitCompPutImm32(&w, (int)label[i].p); + jitCompPutImm32(&w, (int)label[i].p1); + jitCompPutImm32(&w, 0); /* liveSign */ + jitCompPutImm32(&w, 2320); /* pls */ + jitCompPutImm32(&w, 0); + jitCompPutImm32(&w, 0); + j--; + } + } + if (lastlabel >= 0 && label[lastlabel].p1 < w.dst) + label[lastlabel].p1 = w.dst; + continue; + + case 0x3c: /* ENTER */ + jitCompA000_storeRegCacheAll(&w); // 手抜き. + jitCompA000_storePRegCacheAll(&w); // 手抜き. + jitCompPutByte2(w.dst, 0x6a, src[6]); /* PUSH(?); */ + jitCompPutByte2(w.dst, 0x6a, src[5]); /* PUSH(?); */ + jitCompPutByte2(w.dst, 0x6a, src[4] & 0x0f); /* PUSH(?); */ + jitCompPutByte2(w.dst, 0x6a, (src[4] >> 4) & 0x0f); /* PUSH(?); */ + jitCompPutByte2(w.dst, 0x6a, src[3]); /* PUSH(?); */ + jitCompPutByte2(w.dst, 0x6a, src[2]); /* PUSH(?); */ + jitCompPutByte2(w.dst, 0x6a, src[1]); /* PUSH(?); */ + jitCompPutByte1(w.dst, 0x55); /* PUSH(EBP); */ + jitCompPutByte1(w.dst, 0xe8); + j = ((unsigned char *)&func3c) - (w.dst + 4); + jitCompPutImm32(&w, j); + jitCompPutByte3(w.dst, 0x83, 0xc4, 0x20); /* ADD(ESP,32); */ + jitCompA000_loadRegCacheAll(&w); // 手抜き. + jitCompA000_loadPRegCacheAll(&w); // 手抜き. + cmp0reg = -1; + break; + + case 0x3d: /* LEAVE */ + jitCompA000_storeRegCacheAll(&w); // 手抜き. + jitCompA000_storePRegCacheAll(&w); // 手抜き. + jitCompPutByte2(w.dst, 0x6a, src[6]); /* PUSH(?); */ + jitCompPutByte2(w.dst, 0x6a, src[5]); /* PUSH(?); */ + jitCompPutByte2(w.dst, 0x6a, src[4] & 0x0f); /* PUSH(?); */ + jitCompPutByte2(w.dst, 0x6a, (src[4] >> 4) & 0x0f); /* PUSH(?); */ + jitCompPutByte2(w.dst, 0x6a, src[3]); /* PUSH(?); */ + jitCompPutByte2(w.dst, 0x6a, src[2]); /* PUSH(?); */ + jitCompPutByte2(w.dst, 0x6a, src[1]); /* PUSH(?); */ + jitCompPutByte1(w.dst, 0x55); /* PUSH(EBP); */ + jitCompPutByte1(w.dst, 0xe8); + j = ((unsigned char *)&func3d) - (w.dst + 4); + jitCompPutImm32(&w, j); + jitCompPutByte3(w.dst, 0x83, 0xc4, 0x20); /* ADD(ESP,32); */ + jitCompA000_loadRegCacheAll(&w); // 手抜き. + jitCompA000_loadPRegCacheAll(&w); // 手抜き. + cmp0reg = -1; + break; + + case 0xfe: /* remark */ + if (src[1] == 0x01 && src[2] == 0x00) { // DBGINFO1 + if (level <= JITC_LV_SLOWER) { + jitCompPutByte1(w.dst, 0xb8); /* MOV(EAX, ?); */ + jitCompPutImm32(&w, debugInfo1); + jitCompA0001_movEbpDispReg32(&w, 2304 + 4, 0 /* EAX */); /* MOV(debugInfo1, EAX); */ + } + } + if (src[1] == 0x01 && src[2] == 0x03) { // DBGINFO1CLR + if (level <= JITC_LV_SLOWER) { + jitCompPutByte1(w.dst, 0xb8); /* MOV(EAX, ?); */ + jitCompPutImm32(&w, -1); + jitCompA0001_movEbpDispReg32(&w, 2304 + 4, 0 /* EAX */); /* MOV(debugInfo1, EAX); */ + } + } + if (src[1] == 0x05 && src[2] == 0x00) { // DBGINFO0 + if (level <= JITC_LV_SLOWEST) { + debugInfo0 = jitCompGetImm32(src + 3); + // jitCompPutByte1(w.dst, 0xbf); /* MOV(EDI, ?); */ + // jitCompPutImm32(&w, debugInfo0); + jitCompPutByte1(w.dst, 0xb8); /* MOV(EAX, ?); */ + jitCompPutImm32(&w, debugInfo0); + jitCompA0001_movEbpDispReg32(&w, 2304 + 0, 0 /* EAX */); /* MOV(debugInfo0, EAX); */ + } + } + break; + + default: + w.err = JITC_ERR_OPECODE; + goto err_w; } if (w.err != 0) goto err_w; jitCompA0001_fixPrefix(&w); @@ -1512,7 +1512,7 @@ int jitCompiler(unsigned char *dst, unsigned char *dst1, const unsigned char *sr if ((flags & JITC_PHASE1) != 0) return w.dst - dst00; return 0; - + err_w: if ((w.err & JITC_ERR_PHASE0ONLY) != 0) { if ((flags & JITC_PHASE1) == 0) @@ -1561,10 +1561,10 @@ unsigned char *jitCompCallFunc(unsigned char *dst, void *func) jitCompPutByte1(w.dst, 0x55); /* PUSH(EBP); */ jitCompPutByte1(w.dst, 0xe8); /* CALL(func); */ int j = ((unsigned char *)func) - (w.dst + 4); - + //この関数の中では結局w->dstしか参照していない jitCompPutImm32(&w, j); - + jitCompPutByte1(w.dst, 0x58); /* POP(EAX); */ /* (win32では不要なのだけど、MacOSには必要らしい) */ jitCompPutByte1(w.dst, 0x58); /* POP(EAX); */ jitCompPutByte1(w.dst, 0x61); /* POPAD(); */ @@ -1610,7 +1610,7 @@ void func3d(char *ebp, int opt, int r1, int p1, int lenR, int lenP, int r0, int int i; r->junkStack -= 4; r->junkStack -= 32; - HOSECPU_PointerRegisterEntry *pp = (void *)r->junkStack; + HOSECPU_PointerRegisterEntry *pp = (void *)r->junkStack; r->preg[0x30] = *pp; r->junkStack -= p1 * 32; pp = (void *)r->junkStack; for (i = 0; i < p1; i++) @@ -1712,24 +1712,24 @@ int jitc0(unsigned char **qq, unsigned char *q1, const unsigned char *p0, const unsigned char *q = *qq; if (p0[0] != 0x05 || p0[1] != SIGN1) // OSECPUのヘッダ (05E1) を確認 return 1; - + *q++ = 0x55; /* PUSH(EBP); */ *q++ = 0x8b; *q++ = 0x6c; *q++ = 0x24; *q++ = 0x08; /* MOV(EBP,[ESP+8]); */ - + int i; for (i = 0; i < JITC_MAXLABELS; i++) label[i].opt = 0; - + // 以下のjitCompile()呼び出しでは第二引数をq1-2にした方がよいのではないか? i = jitCompiler(q, q1, p0 + 2, p1, p0, label, JITC_MAXLABELS, level, di1_serial, 0); if (i != 0) return 2; i = jitCompiler(q, q1, p0 + 2, p1, p0, label, JITC_MAXLABELS, level, di1_serial, JITC_PHASE1 + 0); if (i < 0) return 2; q += i; - + *q++ = 0x5d; /* POP(EBP); */ *q++ = 0xc3; /* RET(); */ - + *qq = q; return 0; } diff --git a/main.c b/main.c index 80927f6..98591a2 100644 --- a/main.c +++ b/main.c @@ -1,4 +1,4 @@ -#include "osecpu.h" +#include "osecpu.h" int *keybuf, keybuf_r, keybuf_w, keybuf_c; HOSECPU_Device_Window mainWindow; diff --git a/osecpu.h b/osecpu.h index da20826..677802f 100644 --- a/osecpu.h +++ b/osecpu.h @@ -1,4 +1,4 @@ -#ifndef _HDLOAD_OSECPU +#ifndef _HDLOAD_OSECPU #define _HDLOAD_OSECPU 1 /* Visual Studio で fopen()やsprintf() などの古い関数を使用する時に出る警告を抑止する*/ diff --git a/randmt.c b/randmt.c index a449960..74a7d70 100644 --- a/randmt.c +++ b/randmt.c @@ -1,4 +1,4 @@ - + #include "osecpu.h" static struct { diff --git a/screen.c b/screen.c index def1db8..63f2f30 100644 --- a/screen.c +++ b/screen.c @@ -1,4 +1,4 @@ -#include "osecpu.h" +#include "osecpu.h" void putOsaskChar(int c, HOSECPU_RuntimeEnvironment *r) { -- 2.11.0