OSDN Git Service

comment added
[heavyosecpu/HeavyOSECPU.git] / jitc.c
1 #include "osecpu.h"
2
3 #define JITC_ERR_MASK                   255
4 #define JITC_ERR_PHASE0ONLY             256
5 #define JITC_ERR_REGNUM                 (1 | JITC_ERR_PHASE0ONLY)
6 #define JITC_ERR_DST1                   (2 | JITC_ERR_PHASE0ONLY)
7 #define JITC_ERR_OPECODE                (3 | JITC_ERR_PHASE0ONLY)
8 #define JITC_ERR_LABELNUM               (4 | JITC_ERR_PHASE0ONLY)
9 #define JITC_ERR_LABELREDEF             (5 | JITC_ERR_PHASE0ONLY)
10 #define JITC_ERR_PREFIX                 (6 | JITC_ERR_PHASE0ONLY)
11 #define JITC_ERR_LABELNODEF             7
12 #define JITC_ERR_LABELTYP               8
13 #define JITC_ERR_IDIOM                  9
14 #define JITC_ERR_PREGNUM                (10 | JITC_ERR_PHASE0ONLY)
15 #define JITC_ERR_SRC1                   (11 | JITC_ERR_PHASE0ONLY)
16 #define JITC_ERR_BADTYPE                (12 | JITC_ERR_PHASE0ONLY)
17 #define JITC_ERR_PREFIXFAR              (13 | JITC_ERR_PHASE0ONLY)
18 #define JITC_ERR_INTERNAL               99
19
20 void errorHandler(struct Regs *r)
21 {
22         puts("security error! abort...");
23         printf("debugInfo0=%d, debugInfo1=%d¥n", r->debugInfo0, r->debugInfo1);
24 #if (USE_DEBUGGER != 0)
25         dbgrMain(r);
26 #endif
27         exit(1);
28 }
29
30 int jitCompCmdLen(const unsigned char *src)
31 {
32         int i = 1;
33         if (0x01 <= *src && *src < 0x04) i = 6;
34         if (*src == 0x04) i = 2;
35         if (0x08 <= *src && *src < 0x0d) i = 8 + src[7] * 4;
36         if (0x0e <= *src && *src < 0x10) i = 8;
37         if (0x10 <= *src && *src < 0x2e) i = 4;
38         if (0x1c <= *src && *src < 0x1f) i = 3;
39         if (*src == 0x1f) i = 11;
40         if (*src == 0x2f) i = 4 + src[1];
41         if (0x30 <= *src && *src <= 0x33) i = 4;
42         if (0x3c <= *src && *src <= 0x3d) i = 7;
43         if (*src == 0xfe) i = 2 + src[1];
44         return i;
45 }
46 #if (JITC_ARCNUM == 0x0001)     /* x86-32bit */
47
48 /* 他のCPUへ移植する人へ:
49 以下は最適化のためのものなので、すべて0として簡単に移植しても問題ありません */
50 #define jitCompA0001_USE_R3F_CMPJMP             1*1
51 #define jitCompA0001_USE_R3F_IMM32              1*1
52 #define jitCompA0001_USE_R3F_IMM8               1*1
53 #define jitCompA0001_USE_R3F_INCDEC             1*1
54 #define jitCompA0001_OPTIMIZE_JMP               1*1
55 #define jitCompA0001_OPTIMIZE_MOV               1*1     /* 1にすると速度低下する? */
56 #define jitCompA0001_OPTIMIZE_CMP               1*1
57 #define jitCompA0001_OPTIMIZE_ALIGN             4*1     /* 0-8を想定 */
58 #define jitCompA0001_EBP128                             128*1
59
60 struct JitCompWork {
61         unsigned char *dst, *dst0;
62         int err, maxLabels;
63 #if (jitCompA0001_USE_R3F_IMM32 != 0)
64         int r3f;
65 #endif
66         char prefix;    //CND命令の値を記録(初期値=0)
67 };
68
69 #define jitCompPutByte1(p, c0)                          *p++ = c0
70 #define jitCompPutByte2(p, c0, c1)                      *p++ = c0; *p++ = c1
71 #define jitCompPutByte3(p, c0, c1, c2)          *p++ = c0; *p++ = c1; *p++ = c2
72 #define jitCompPutByte4(p, c0, c1, c2, c3)      *p++ = c0; *p++ = c1; *p++ = c2; *p++ = c3
73
74 static void jitCompPutImm32(struct JitCompWork *w, int i)
75 {
76         jitCompPutByte1(w->dst, i & 0xff);
77         jitCompPutByte1(w->dst, (i >> 8) & 0xff);
78         jitCompPutByte1(w->dst, (i >> 16) & 0xff);
79         jitCompPutByte1(w->dst, (i >> 24) & 0xff);
80         return;
81 }
82
83 int jitCompGetImm32(const unsigned char *src)
84 {
85         return (src[0] << 24) | (src[1] << 16) | (src[2] << 8) | src[3];
86 }
87
88 int jitCompGetLabelNum(struct JitCompWork *w, const unsigned char *src)
89 {
90         int i = jitCompGetImm32(src);
91         if (i < 0 || i >= w->maxLabels) {
92                 w->err = JITC_ERR_LABELNUM;
93                 i = 0;
94         }
95         return i;
96 }
97
98 void jitCompA0001_85DispN(struct JitCompWork *w, int disp, int n)
99 {
100         disp -= jitCompA0001_EBP128;
101         if (-128 <= disp && disp <= 127) {
102                 jitCompPutByte2(w->dst, 0x45 | (n << 3), disp & 0xff);
103         }
104         else {
105                 jitCompPutByte1(w->dst, 0x85 | (n << 3));
106                 jitCompPutImm32(w, disp);
107         }
108         return;
109 }
110
111 void jitCompA0001_movEbpDispReg32(struct JitCompWork *w, int disp, int reg32)
112 {
113         jitCompPutByte1(w->dst, 0x89); /* MOV(mem, reg32); */
114         jitCompA0001_85DispN(w, disp, reg32);
115         return;
116 }
117
118 void jitCompA0001_movReg32EbpDisp(struct JitCompWork *w, int reg32, int disp)
119 {
120         jitCompPutByte1(w->dst, 0x8b); /* MOV(reg32, mem); */
121         jitCompA0001_85DispN(w, disp, reg32);
122         return;
123 }
124
125 void jitCompA0001_movEaxRxx(struct JitCompWork *w, int rxx)
126 {
127 #if (jitCompA0001_USE_R3F_IMM32 != 0)
128         if (rxx == 0x3f) {
129                 jitCompPutByte1(w->dst, 0xb8); /* MOV(EAX, ?); */
130                 jitCompPutImm32(w, w->r3f);
131                 return;
132         }
133 #endif
134         if (rxx >= 0x40 || rxx < 0) w->err = JITC_ERR_REGNUM;
135         jitCompA0001_movReg32EbpDisp(w, 0 /* EAX */, rxx * 4); /* MOV(EAX, [EBP+?]); */
136         return;
137 }
138
139 void jitCompA0001_movRxxEax(struct JitCompWork *w, int rxx)
140 {
141         if (rxx >= 0x40 || rxx < 0) w->err = JITC_ERR_REGNUM;
142         jitCompA0001_movEbpDispReg32(w, rxx * 4, 0 /* EAX */); /* MOV([EBP+?], EAX); */
143         return;
144 }
145
146 void jitCompA0001_fixPrefix(struct JitCompWork *w)
147 {
148         if (w->prefix != 0) {
149                 if (w->dst - w->dst0 > 127) w->err = JITC_ERR_REGNUM;
150                 w->dst0[-1] = (unsigned char)((w->dst - w->dst0) & 0xff);
151         }
152         return;
153 }
154
155 void jitCompA0001_checkCompPtr(struct JitCompWork *w, int p0, int p1)
156 {
157         if (p0 >= 0x3f || p0 < 0) w->err = JITC_ERR_PREGNUM;
158         if (p1 >= 0x3f || p1 < 0) w->err = JITC_ERR_PREGNUM;
159         /* 比較可能可能なのかのチェックのコードを出力 */   /* 未完成 */
160         return;
161 }
162
163 void jitCompA000_loadRegCacheAll(struct JitCompWork *w)
164 {
165         jitCompA0001_movReg32EbpDisp(w, 3 /* EBX */, 0 * 4); /* EBX = R00; */
166         jitCompA0001_movReg32EbpDisp(w, 1 /* ECX */, 1 * 4); /* ECX = R01; */
167         jitCompA0001_movReg32EbpDisp(w, 2 /* EDX */, 2 * 4); /* EDX = R02; */
168         return;
169 }
170
171 void jitCompA000_storeRegCacheAll(struct JitCompWork *w)
172 {
173         jitCompA0001_movEbpDispReg32(w, 0 * 4, 3 /* EBX */); /* R00 = EBX; */
174         jitCompA0001_movEbpDispReg32(w, 1 * 4, 1 /* ECX */); /* R01 = ECX; */
175         jitCompA0001_movEbpDispReg32(w, 2 * 4, 2 /* EDX */); /* R02 = EDX; */
176         return;
177 }
178
179 void jitCompA000_loadRegCacheEcx(struct JitCompWork *w)
180 {
181         jitCompA0001_movReg32EbpDisp(w, 1 /* ECX */, 1 * 4); /* ECX = R01; */
182         return;
183 }
184
185 void jitCompA000_storeRegCacheEcx(struct JitCompWork *w)
186 {
187         jitCompA0001_movEbpDispReg32(w, 1 * 4, 1 /* ECX */); /* R01 = ECX; */
188         return;
189 }
190
191 void jitCompA000_loadRegCacheEdx(struct JitCompWork *w)
192 {
193         jitCompA0001_movReg32EbpDisp(w, 2 /* EDX */, 2 * 4); /* EDX = R02; */
194         return;
195 }
196
197 void jitCompA000_storeRegCacheEdx(struct JitCompWork *w)
198 {
199         jitCompA0001_movEbpDispReg32(w, 2 * 4, 2 /* EDX */); /* R02 = EDX; */
200         return;
201 }
202
203 int jitCompA000_selectRegCache(int rxx, int reg)
204 {
205         if (rxx == 0) reg = 3; /* EBX */
206         if (rxx == 1) reg = 1; /* ECX */
207         if (rxx == 2) reg = 2; /* EDX */
208         return reg;
209 }
210
211 void jitCompA000_loadPRegCacheAll(struct JitCompWork *w)
212 {
213         //      jitCompA0001_movReg32EbpDisp(w, 5 /* EBP */, 256 + 0 * 32 + 0); /* EBP = P00; */
214         jitCompA0001_movReg32EbpDisp(w, 6 /* ESI */, 256 + 1 * 32 + 0); /* ESI = P01; */
215         jitCompA0001_movReg32EbpDisp(w, 7 /* EDI */, 256 + 2 * 32 + 0); /* EDI = P02; */
216         return;
217 }
218
219 void jitCompA000_storePRegCacheAll(struct JitCompWork *w)
220 {
221         //      jitCompA0001_movEbpDispReg32(w, 256 + 0 * 32 + 0, 5 /* EBP */); /* P00 = EBP; */
222         jitCompA0001_movEbpDispReg32(w, 256 + 1 * 32 + 0, 6 /* ESI */); /* P01 = ESI; */
223         jitCompA0001_movEbpDispReg32(w, 256 + 2 * 32 + 0, 7 /* EDI */); /* P02 = EDI; */
224         return;
225 }
226
227 int jitCompA000_selectPRegCache(int pxx, int reg)
228 {
229         //      if (pxx == 0) reg = 5; /* EBP */
230         if (pxx == 1) reg = 6; /* ESI */
231         if (pxx == 2) reg = 7; /* EDI */
232         return reg;
233 }
234
235 int jitCompA000_convTyp(int t)
236 {
237         int r = -1;
238         if (1 <= t && t <= 7) r = t;
239         if (8 <= t && t <= 13) r = 2 | (t & 1);
240         if (14 <= t && t <= 15) r = 4 | (t & 1);
241         if (16 <= t && t <= 21) r = 6 | (t & 1);
242         return r;
243 }
244
245 int jitCompA000_dataWidth(int t)
246 {
247         int r = -1;
248         if (t == 0x0001) r = 256;
249         t >>= 1;
250         if (t == 0x0002 / 2) r = 8;
251         if (t == 0x0004 / 2) r = 16;
252         if (t == 0x0006 / 2) r = 32;
253         if (t == 0x0008 / 2) r = 4;
254         if (t == 0x000a / 2) r = 2;
255         if (t == 0x000c / 2) r = 1;
256         if (t == 0x000e / 2) r = 12;
257         if (t == 0x0010 / 2) r = 20;
258         if (t == 0x0012 / 2) r = 24;
259         if (t == 0x0014 / 2) r = 28;
260         return r;
261 }
262
263 static unsigned char *errfnc;
264
265 void jitCompA0001_checkType0(struct JitCompWork *w, int pxx, int typ, int ac)
266 {
267         if (typ <= 0) { w->err = JITC_ERR_BADTYPE; }
268         if (typ > 0x7f) { w->err = JITC_ERR_INTERNAL; }
269         jitCompA0001_movReg32EbpDisp(w, 0 /* EAX */, 256 + pxx * 32 + 4); /* MOV(EAX, [EBP+?]); */      /* typ */
270         jitCompPutByte3(w->dst, 0x83, 0xf8, typ & 0x7f);        /* CMP(EAX, ?); */
271         jitCompPutByte2(w->dst, 0x0f, 0x85); /* JNE */
272         jitCompPutImm32(w, errfnc - (w->dst + 4));
273         return;
274 }
275
276 void jitCompA0001_checkType(struct JitCompWork *w, int pxx, int typ, int ac)
277 // data用.
278 // 将来的にはaliveやアクセス権チェックも入れる
279 {
280         jitCompA0001_checkType0(w, pxx, typ, ac);
281         return;
282 }
283
284 void jitCompA0001_checkLimit(struct JitCompWork *w, int reg, int pxx)
285 {
286         jitCompPutByte1(w->dst, 0x3b);  /* CMP(reg, [EBP+?]); */
287         jitCompA0001_85DispN(w, 256 + pxx * 32 + 8, reg);       /* p0 */
288         jitCompPutByte2(w->dst, 0x0f, 0x82); /* JB */
289         jitCompPutImm32(w, errfnc - (w->dst + 4));
290         jitCompPutByte1(w->dst, 0x3b);  /* CMP(reg, [EBP+?]); */
291         jitCompA0001_85DispN(w, 256 + pxx * 32 + 12, reg);      /* p1 */
292         jitCompPutByte2(w->dst, 0x0f, 0x83); /* JAE */
293         jitCompPutImm32(w, errfnc - (w->dst + 4));
294         return;
295 }
296
297 void func3c(char *ebp, int opt, int r1, int p1, int lenR, int lenP, int r0, int p0);
298 void func3d(char *ebp, int opt, int r1, int p1, int lenR, int lenP, int r0, int p0);
299 void funcf4(char *ebp, int pxx, int typ, int len);
300 void funcf5(char *ebp, int pxx, int typ, int len); // pxxはダミーで参照されない.
301 void funcf6(char *ebp, int pxx, int typ, int len);
302 void funcf7(char *ebp, int pxx, int typ, int len); // typとlenはダミーで参照されない.
303 // F5の場合、decoderが対応するalloc-freeを結びつけるのが簡単で、typやlenを指定必須にしてもフロントエンドコードに影響はない.
304
305 void errHndl(struct Regs *r);
306
307 /*
308  * dst : 現在の書き込みアドレス。
309  * dst1 : 書き込みアドレスの最大値
310  * src : 現在の読み込みアドレス(ヘッダ部は飛ばしてある
311  * src1 : 読み込みアドレスの最大値
312  * src0 : 読み込みバイナリのアドレス
313  */
314 int jitCompiler(unsigned char *dst, unsigned char *dst1, const unsigned char *src, const unsigned char *src1, const unsigned char *src0, struct LabelTable *label, int maxLabels, int level, int debugInfo1, int flags)
315 /* IA-32用 */
316 /* 本来ならこのレイヤでは文法チェックしない */
317 {
318         struct JitCompWork w;
319         unsigned char *dst00 = dst, *errmsg = "", *enter0 = NULL, *tmp_ucp;
320         const unsigned char *oldsrc;
321         int timecount = 0, i, j = 0, lastlabel = -1, debugInfo0 = -1;
322         int reg0, reg1, reg2, cmp0reg = -1, cmp0lev = 0;
323         w.dst = w.dst0 = dst;
324         w.err = 0;
325         w.maxLabels = maxLabels;
326
327         if ((flags & JITC_NOSTARTUP) == 0) {
328                 jitCompPutByte1(w.dst, 0x60); /* PUSHAD(); */
329                 jitCompA000_loadRegCacheAll(&w); /* start-up */
330                 jitCompA000_loadPRegCacheAll(&w);
331         }
332         if (level <= JITC_LV_SLOWER) {
333                 jitCompPutByte2(w.dst, 0x31, 0xc0);     /* XOR(EAX, EAX); */
334                 jitCompA0001_movEbpDispReg32(&w, 2304 + 0, 0 /* EAX */); /* MOV(debugInfo0, EAX); */
335                 jitCompPutByte1(w.dst, 0xb8);   /* MOV(EAX, ?); */
336                 jitCompPutImm32(&w, debugInfo1);
337                 jitCompA0001_movEbpDispReg32(&w, 2304 + 4, 0 /* EAX */); /* MOV(debugInfo1, EAX); */
338         }
339         while (src < src1) {
340                 w.prefix = 0;   //0x04 CND 命令で変更される
341                 if (w.dst + 256 > dst1) { w.err = JITC_ERR_DST1; goto err_w; }  // 書き込み領域が残り256バイト未満ならエラー
342                 timecount++;
343                 if (timecount >= 64) {
344                         timecount -= 64;
345                         /* 未完成(timeoutチェックコードを入れる) */
346                 }
347         prefix_continue:        // CND命令実行後ここに戻る
348                 switch (*src) {
349
350                 case 0x00:      /* NOP */
351                         if (w.prefix != 0) { w.err = JITC_ERR_PREFIX; goto err_w; }     // 「条件付きでNOPを実行」するなんて、矛盾している!
352                         break;
353
354                 case 0x01:      /* LB */
355                         
356                         /*
357                          * LB : ラベル設置命令。(6byte)
358                          * ・prefex = 1にする
359                          * ・timecount++し、timecountのチェックをする。
360                          * ・ラベル位置を登録する。
361                          * ・割り込みがある場合、このタイミングで割り込みを発生させる。
362                          *
363                          *  1   2       3       456
364                          *      LB      01      opt     imm32
365                          *
366                          */
367                         
368                         if (enter0 == NULL && (src[6] == 0x3c /* 多数のレジスタをスタックに退避 */ || (src[6] == 0xfe/* REMARK */ && src[7] == 0x01 && src[9] == 0x3c))) {       //beginFunc()中のLB
369                                 // LB命令の後に0x3C命令・・・beginFunc()
370                                 jitCompPutByte1(w.dst, 0xe9);   // (x86) JMP rel32 : 次の命令との相対オフセットだけ相対ニアジャンプする
371                                 enter0 = w.dst;
372                                 jitCompPutImm32(&w, 0); // 飛び相対座標が0 ・・・パイプラインのフラッシュ??
373                         }
374                         if (src[6] == 0x34) {   // LBの次の命令がDATA ・・・DAT_SA0(label, typ32, length) ・・・メモリ確保命令
375                                 tmp_ucp = w.dst;
376                                 jitCompPutByte1(w.dst, 0xe9);   // (x86) JMP rel32 : 次の命令との相対オフセットだけ相対ニアジャンプする
377                                 i = jitCompGetImm32(&src[7]);   // type32 を取得
378                                 j = 32;
379                                 if (i != 1) {
380                                         i = jitCompA000_convTyp(i);
381                                         j = 0;
382                                         if (i == 2 || i == 3) { j = 1; }
383                                         if (i == 4 || i == 5) { j = 2; }
384                                         if (i == 6 || i == 7) { j = 4; }
385                                 }
386                                 j *= jitCompGetImm32(&src[11]);
387                                 if (j <= 0) w.err = JITC_ERR_BADTYPE;
388                                 jitCompPutImm32(&w, j);
389 #if (jitCompA0001_OPTIMIZE_JMP != 0)
390                                 if (j <= 127 - jitCompA0001_OPTIMIZE_ALIGN) {
391                                         w.dst -= 5;
392                                         jitCompPutByte2(w.dst, 0xeb, j);
393                                 }
394 #endif
395                         }
396 #if (jitCompA0001_OPTIMIZE_ALIGN != 0)
397                         for (;;) {
398                                 i = ((int)w.dst) & (jitCompA0001_OPTIMIZE_ALIGN - 1); /* ALIGNで割ったあまりを計算 */
399                                 if (i == 0) break;
400                                 i = jitCompA0001_OPTIMIZE_ALIGN - i;
401                                 if (i == 1) { jitCompPutByte1(w.dst, 0x90); j += i; } /* NOP(); */
402                                 if (i == 2) { jitCompPutByte2(w.dst, 0x89, 0xc0); j += i; } /* MOV(EAX, EAX); */
403                                 if (i == 3) { jitCompPutByte3(w.dst, 0x8d, 0x76, 0x00); j += i; } /* LEA(ESI, [ESI+0]); */
404                                 if (i == 4) { jitCompPutByte4(w.dst, 0x8d, 0x74, 0x26, 0x00); j += i; } /* LEA(ESI, [ESI*1+0]); */
405                                 if (i == 5) { jitCompPutByte1(w.dst, 0x0d); jitCompPutImm32(&w, 0); j += i; } /* OR(EAX, 0); */
406                                 if (i == 6) { jitCompPutByte2(w.dst, 0x8d, 0xb6); jitCompPutImm32(&w, 0); j += i; } /* LEA(ESI, [ESI+0]); */
407                                 if (i >= 7) { jitCompPutByte3(w.dst, 0x8d, 0xb4, 0x26); jitCompPutImm32(&w, 0); j += 7; } /* LEA(ESI, [ESI*1+0]); */
408                         }
409 #endif
410                         if (src[6] == 0x34) {
411                                 tmp_ucp[1] = j & 0xff;
412                                 if (*tmp_ucp == 0xe9) {
413                                         tmp_ucp[2] = (j >> 8) & 0xff;
414                                         tmp_ucp[3] = (j >> 16) & 0xff;
415                                         tmp_ucp[4] = (j >> 24) & 0xff;
416                                 }
417                         }
418                         if ((flags & JITC_PHASE1) == 0) {
419                                 i = jitCompGetLabelNum(&w, src + 2);
420                                 //printf("i=%06X %06X¥n", i, src-src0);
421                                 if (label[i].opt != 0 && w.err == 0) { w.err = JITC_ERR_LABELREDEF; goto err_w; }
422                                 if (w.prefix != 0) { w.err = JITC_ERR_PREFIX; goto err_w; }
423                                 label[i].opt = src[1] + 1;
424                                 label[i].typ = 0; /* TYP_CODE */
425                                 label[i].p = w.dst;
426                                 label[i].p1 = w.dst + 1;
427                                 lastlabel = i;
428                         }
429                         cmp0reg = -1;
430                         timecount = 0;
431                         /* 未完成(timeoutチェックコードを入れる) */
432                         break;
433
434                 case 0x02:      /* LIMM */      
435                         
436                         /*
437                          * LIMM : 定数即値代入命令(6byte)
438                          * 
439                          *      1       2               3456
440                          *      02      reg0R   imm32
441                          *
442                          * ・reg3F は条件比較慣用句指定用&演算命令即値慣用句指定用。よってCND命令の直後では使用できない。
443                          */
444                         
445                         if (src[1] == 0x3f && w.prefix != 0) w.err = JITC_ERR_PREFIX;   // CND命令の直後でR3Fを書き換えるなんて変だよね
446
447 #if (jitCompA0001_USE_R3F_IMM32 != 0)
448                         if (src[1] == 0x3f) {           // R3Fへの代入は例外敵に、 w.r3f を使用
449                                 w.r3f = jitCompGetImm32(src + 2);
450                                 break;
451                         }
452 #endif
453                         i = jitCompGetImm32(src + 2);   // 与えられた即値(第二引数)を取得
454
455                         /* R00-R02 なら EBX, ECX, EDX 、それ以外なら EAX のレジスタIDを reg0 に代入 */
456                         reg0 = jitCompA000_selectRegCache(src[1], 0 /* EAX */);
457
458 #if (jitCompA0001_OPTIMIZE_MOV != 0)
459                         if (i == 0) {
460                                 jitCompPutByte2(w.dst, 0x31, 0xc0 | reg0 << 3 | reg0);  /* XOR(reg0, reg0); */
461                                 jitCompA0001_movRxxEax(&w, src[1]);
462                                 break;
463                         }
464 #endif
465                         
466                         /* reg0 のレジスタに対応したMOV命令を発行 */
467                         jitCompPutByte1(w.dst, 0xb8 | reg0);    /* MOV(reg0, ?);  == 10111000b+wr imm32 */
468                         jitCompPutImm32(&w, i);
469
470                         if (reg0 == 0)  // R03以降の、レジスタの内容をメモリ上に格納してエミュレートする場合
471                                 
472                                 jitCompA0001_movRxxEax(&w, src[1]);
473                         break;
474
475                 case 0x03:      /* PLIMM */     /* 未完成(plsまで対応) */
476
477                         /*
478                         * PLIMM : ラベル番号代入命令(6byte)
479                         *
480                         *       1       2       3456
481                         *       03      PXX     imm32
482                         *
483                         * ・P28 はAPI用
484                         * ・P3F はプログラムカウンタ
485                         */
486
487                         i = jitCompGetLabelNum(&w, src + 2);    // Pxxに代入するラベルの番号(第二引数)
488                         if ((flags & JITC_PHASE1) != 0 && w.err == 0) { // Phase 1であるならば
489                                 if (label[i].opt == 0) { w.err = JITC_ERR_LABELNODEF; goto err_w; }             // 指定されたラベル番号は存在しない
490                                 if (src[1] != 0x3f && label[i].opt != 2) { w.err = JITC_ERR_LABELTYP; goto err_w; }     // 
491                                 if (src[1] == 0x3f && label[i].typ != 0) { w.err = JITC_ERR_LABELTYP; goto err_w; } // プログラムカウンタに TYP_CODEでない値は代入できない
492                         }
493                         if (src[1] == 0x3f) {   // プログラムカウンタへの代入なら
494                                 if (w.prefix == 0) {    // CND命令による条件付きでなければ、即座に移動
495                                         jitCompPutByte1(w.dst, 0xe9); /* JMP(?); */
496                                 }
497                                 else {  // 直前はCND命令。
498                                         
499                                         /*
500                                          * CND命令
501                                          *      1       2       
502                                          *      04      reg0R
503                                          *
504                                          * いま、dstの末端はJZ命令になっている。 0x0F 0x84 cd
505                                          */
506
507                                          // JZのとび先アドレスの書き換え?
508                                         w.dst[-1] = w.dst[-2] ^ 0xf1; /* 74->85, 75->84 */
509                                         w.dst[-2] = 0x0f;
510
511                                         w.prefix = 0;
512                                 }
513                                 j = 0;
514                                 if ((flags & JITC_PHASE1) != 0 || ((flags & JITC_PHASE1) == 0) && label[i].opt != 0)    // label番号iが確保されていれば (このif文は意味をなさない)
515                                         j = label[i].p - (w.dst + 4);   // j はとび先の相対番地 
516                                 jitCompPutImm32(&w, j); // JMP もしくは JZ 命令のアドレス部を記述
517 #if (jitCompA0001_OPTIMIZE_JMP != 0)
518                                 if (-128 - 3 <= j && j < 0) {
519                                         if (w.dst[-5] == 0xe9) {
520                                                 j += 3;
521                                                 w.dst -= 5;
522                                                 jitCompPutByte1(w.dst, 0xeb); /* JMP(?); */
523                                         }
524                                         else {
525                                                 j += 4;
526                                                 w.dst -= 6;
527                                                 jitCompPutByte1(w.dst, w.dst[1] ^ 0xf0);
528                                         }
529                                         jitCompPutByte1(w.dst, j & 0xff);
530                                 }
531 #endif
532                         }
533                         else {  // プログラムカウンタ以外への代入
534                                 
535                                 // 代入先が P01, P02なら ESI, EDI,それ以外ならEAXを指定
536                                 reg0 = jitCompA000_selectPRegCache(src[1], 0 /* EAX */);
537                                 jitCompPutByte1(w.dst, 0xb8 | reg0);    /* MOV(reg0, ?); */
538                                 jitCompPutImm32(&w, (int)label[i].p);   // ラベルのパスを各レジスタに代入
539
540                                 // レジスタへの代入をメモリでエミュレーションする場合は、スタックに積む。
541                                 if (reg0 == 0)
542                                         jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32, 0); /* MOV([EBP+?], EAX); */
543
544                                 if (level < JITC_LV_FASTEST) {
545                                         jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + 8, reg0); /* MOV([EBP+?], reg0); */ /* p0 */
546                                         jitCompPutByte1(w.dst, 0xb8); /* MOV(EAX, ?); */
547                                         jitCompPutImm32(&w, label[i].typ);
548                                         jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + 4, 0); /* MOV([EBP+?], EAX); */ /* typ */
549                                         jitCompPutByte1(w.dst, 0xb8); /* MOV(EAX, ?); */
550                                         jitCompPutImm32(&w, (int)label[i].p1);
551                                         jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + 12, 0); /* MOV([EBP+?], EAX); */ /* p1 */
552                                         jitCompPutByte2(w.dst, 0x31, 0xc0);     /* XOR(EAX, EAX); */
553                                         jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + 16, 0); /* MOV([EBP+?], EAX); */ /* liveSign */
554                                         jitCompA0001_movReg32EbpDisp(&w, 0, 2320); /* MOV(EAX, ptrCtrl); */
555                                         jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + 20, 0); /* MOV([EBP+?], EAX); */ /* pls */
556                                 }
557                         }
558                         break;
559
560                 case 0x04:      /* CND (prefix) */
561                         if (src[1] >= 0x40) w.err = JITC_ERR_REGNUM;    // R00-R3F 以外のレジスタは比較対象にできない
562
563                         // 比較対象のレジスタがメモリ上にあれば-1, それ以外なら適切なレジスタ番号を返す
564                         reg0 = jitCompA000_selectRegCache(src[1], -1 /* mem */);
565
566                         /* TEST命令を発行 */
567                         if (reg0 < 0) { //比較対象のレジスタはメモリ上にある
568                                 jitCompPutByte1(w.dst, 0xf7); /* TEST([EBP+?],1); */
569                                 jitCompA0001_85DispN(&w, src[1] * 4, 0);
570                         }
571                         else {
572                                 jitCompPutByte2(w.dst, 0xf7, 0xc0 | reg0); /* TEST(reg0,1); */
573                         }
574                         jitCompPutImm32(&w, 1);
575
576                         /* JZ命令を発行 */
577                         jitCompPutByte2(w.dst, 0x74, 0x00);     /* JZ($+2) */
578                         cmp0reg = -1;
579                         if (w.err != 0) goto err_w;
580                         src += 2;
581                         w.prefix = 1;   // プリフィックスをセット
582                         w.dst0 = w.dst; 
583                         goto prefix_continue;
584
585                 case 0x08: /* LMEM */   /* 完成 */
586                         i = jitCompGetImm32(src + 2);
587                         if (i == 0x0001) w.err = JITC_ERR_BADTYPE;
588                         if (level < JITC_LV_FASTER) {
589                                 jitCompA0001_checkType(&w, src[6], i, 0); // read
590                                 cmp0reg = -1;
591                         }
592                         reg0 = jitCompA000_selectRegCache(src[1], 0 /* EAX */);
593                         reg1 = jitCompA000_selectPRegCache(src[6], 2 /* EDX */);
594                         if (reg0 != 0 /* EAX */ && reg1 == 2 /* EDX */)
595                                 reg1 = 0; /* EAX */
596                         if (reg1 == 2 /* EDX */)
597                                 jitCompA000_storeRegCacheEdx(&w);
598                         if (reg1 <= 3 /* EAX, EDX */)
599                                 jitCompA0001_movReg32EbpDisp(&w, reg1, 256 + src[6] * 32 + 0); /* MOV(reg1, [EBP+?]); */
600                         if (level < JITC_LV_FASTER)
601                                 jitCompA0001_checkLimit(&w, reg1, src[6]);
602                         i = jitCompA000_convTyp(jitCompGetImm32(src + 2));
603                         switch (i) {
604                         case 0x0002:
605                                 jitCompPutByte3(w.dst, 0x0f, 0xbe, reg0 << 3 | reg1);   /* MOVSX(reg0,BYTE [reg1]); */
606                                 break;
607                         case 0x0003:
608                                 jitCompPutByte3(w.dst, 0x0f, 0xb6, reg0 << 3 | reg1);   /* MOVZX(reg0,BYTE [reg1]); */
609                                 break;
610                         case 0x0004:
611                                 jitCompPutByte3(w.dst, 0x0f, 0xbf, reg0 << 3 | reg1);   /* MOVSX(reg0,WORD [reg1]); */
612                                 break;
613                         case 0x0005:
614                                 jitCompPutByte3(w.dst, 0x0f, 0xb7, reg0 << 3 | reg1);   /* MOVZX(reg0,WORD [reg1]); */
615                                 break;
616                         case 0x0006:
617                         case 0x0007:
618                                 jitCompPutByte2(w.dst, 0x8b, reg0 << 3 | reg1); /* MOV(reg0, [reg1]); */
619                                 break;
620                         default:
621                                 w.err = JITC_ERR_BADTYPE;
622                         }
623                         if (reg0 == 0 /* EAX */)
624                                 jitCompA0001_movRxxEax(&w, src[1]);
625                         if (reg1 == 2 /* EDX */)
626                                 jitCompA000_loadRegCacheEdx(&w);
627                         break;
628
629                 case 0x09: /* SMEM */   /* 完成 */
630                         i = jitCompGetImm32(src + 2);
631                         if (i == 0x0001) w.err = JITC_ERR_BADTYPE;
632                         if (level < JITC_LV_FASTER) {
633                                 jitCompA0001_checkType(&w, src[6], i, 1); // write
634                                 cmp0reg = -1;
635                         }
636                         reg0 = jitCompA000_selectRegCache(src[1], 0 /* EAX */);
637                         reg1 = jitCompA000_selectPRegCache(src[6], 2 /* EDX */);
638                         if (reg0 != 0 /* EAX */ && reg1 == 2 /* EDX */)
639                                 reg1 = 0; /* EAX */
640                         if (reg1 == 2 /* EDX */)
641                                 jitCompA000_storeRegCacheEdx(&w);
642                         if (reg1 <= 3 /* EAX, EDX */)
643                                 jitCompA0001_movReg32EbpDisp(&w, reg1, 256 + src[6] * 32 + 0); /* MOV(reg1, [EBP+?]); */
644                         if (level < JITC_LV_FASTER)
645                                 jitCompA0001_checkLimit(&w, reg1, src[6]);
646                         if (reg0 == 0 /* EAX */)
647                                 jitCompA0001_movEaxRxx(&w, src[1]);
648                         /* 値の範囲チェック */
649                         i = jitCompA000_convTyp(jitCompGetImm32(src + 2));
650                         switch (i) {
651                         case 0x0002:
652                         case 0x0003:
653                                 jitCompPutByte2(w.dst, 0x88, reg0 << 3 | reg1); /* MOV([reg1], BYTE(reg0)); */
654                                 break;
655                         case 0x0004:
656                         case 0x0005:
657                                 jitCompPutByte3(w.dst, 0x66, 0x89, reg0 << 3 | reg1);   /* MOV([reg1], WORD(reg0)); */
658                                 break;
659                         case 0x0006:
660                         case 0x0007:
661                                 jitCompPutByte2(w.dst, 0x89, reg0 << 3 | reg1); /* MOV([reg1], reg0); */
662                                 break;
663                         default:
664                                 w.err = JITC_ERR_BADTYPE;
665                         }
666                         if (reg1 == 2 /* EDX */)
667                                 jitCompA000_loadRegCacheEdx(&w);
668                         break;
669
670                 case 0x0a: /* PLMEM */  /* 完成 */
671                         i = jitCompGetImm32(src + 2);
672                         if (i != 0x0001) w.err = JITC_ERR_BADTYPE;
673                         if (level < JITC_LV_FASTER) {
674                                 jitCompA0001_checkType(&w, src[6], i, 0); // read
675                                 cmp0reg = -1;
676                         }
677                         reg0 = jitCompA000_selectPRegCache(src[1], 0 /* EAX */);
678                         reg1 = jitCompA000_selectPRegCache(src[6], 2 /* EDX */);
679                         //      if (reg0 != 0 /* EAX */ && reg1 == 2 /* EDX */) /* これをやってはいけない!(by K, 2013.08.02) */
680                         //              reg1 = 0; /* EAX */
681                         if (reg0 == reg1 && reg0 != 0) {        // bugfix: hinted by yao, 2013.09.14. thanks!
682                                 jitCompA000_storePRegCacheAll(&w);
683                                 reg1 = 2; /* EDX */
684                         }
685                         if (reg1 == 2 /* EDX */)
686                                 jitCompA000_storeRegCacheEdx(&w);
687                         if (reg1 <= 3 /* EAX, EDX */)
688                                 jitCompA0001_movReg32EbpDisp(&w, reg1, 256 + src[6] * 32 + 0); /* MOV(reg1, [EBP+?]); */
689                         if (level < JITC_LV_FASTER)
690                                 jitCompA0001_checkLimit(&w, reg1, src[6]);
691                         jitCompPutByte2(w.dst, 0x8b, reg0 << 3 | reg1); /* MOV(reg0, [reg1]); */
692                         if (reg0 == 0 /* EAX */)
693                                 jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + 0, 0); /* MOV([EBP+?], EAX); */
694                         for (i = 4; i < 32; i += 4) {
695                                 jitCompPutByte3(w.dst, 0x8b, 0x40 | reg1, i);   /* MOV(EAX, [reg1+?]); */
696                                 jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + i, 0 /* EAX */); /* MOV([EBP+?], EAX); */
697                         }
698                         if (reg1 == 2 /* EDX */)
699                                 jitCompA000_loadRegCacheEdx(&w);
700                         break;
701
702                 case 0x0b: /* PSMEM */  /* 完成 */
703                         i = jitCompGetImm32(src + 2);
704                         if (i != 0x0001) w.err = JITC_ERR_BADTYPE;
705                         if (level < JITC_LV_FASTER) {
706                                 jitCompA0001_checkType(&w, src[6], i, 1); // write
707                                 cmp0reg = -1;
708                         }
709                         reg0 = jitCompA000_selectPRegCache(src[1], 0 /* EAX */);
710                         reg1 = jitCompA000_selectPRegCache(src[6], 2 /* EDX */);
711                         //      if (reg0 != 0 /* EAX */ && reg1 == 2 /* EDX */) /* これをやってはいけない!(by K, 2013.08.02) */
712                         //              reg1 = 0; /* EAX */
713                         if (reg1 == 2 /* EDX */)
714                                 jitCompA000_storeRegCacheEdx(&w);
715                         if (reg1 <= 3 /* EAX, EDX */)
716                                 jitCompA0001_movReg32EbpDisp(&w, reg1, 256 + src[6] * 32 + 0); /* MOV(reg1, [EBP+?]); */
717                         if (level < JITC_LV_FASTER)
718                                 jitCompA0001_checkLimit(&w, reg1, src[6]);
719                         if (reg0 == 0 /* EAX */)
720                                 jitCompA0001_movReg32EbpDisp(&w, reg0, 256 + src[1] * 32 + 0); /* MOV(reg0, [EBP+?]); */
721                         jitCompPutByte2(w.dst, 0x89, reg0 << 3 | reg1); /* MOV([reg1], reg0); */
722                         for (i = 4; i < 32; i += 4) {
723                                 jitCompA0001_movReg32EbpDisp(&w, 0 /* EAX */, 256 + src[1] * 32 + i); /* MOV(EAX, [EBP+?]); */
724                                 jitCompPutByte3(w.dst, 0x89, 0x40 | reg1, i);   /* MOV([reg1+?], EAX); */
725                         }
726                         if (reg1 == 2 /* EDX */)
727                                 jitCompA000_loadRegCacheEdx(&w);
728                         break;
729
730                 case 0x0e: /* PADD */           /* 完成 */
731                         if (level < JITC_LV_FASTER) {
732                                 jitCompA0001_checkType0(&w, src[6], jitCompGetImm32(src + 2), 2); // other, aliveテストはとりあえずしない.
733                                 cmp0reg = -1;
734                         }
735                         reg0 = jitCompA000_selectPRegCache(src[1], 0 /* EAX */);
736                         reg1 = jitCompA000_selectPRegCache(src[6], -1 /* mem */);
737                         if (reg1 < 0 /* mem */)
738                                 jitCompA0001_movReg32EbpDisp(&w, reg0, 256 + src[6] * 32 + 0); /* MOV(reg0, [EBP+?]); */
739                         if (reg1 >= 0 && reg0 != reg1) {
740                                 jitCompPutByte2(w.dst, 0x89, 0xc0 | reg1 << 3 | reg0); /* MOV(reg0, reg1); */
741                         }
742                         i = jitCompGetImm32(src + 2);
743                         j = -1;
744                         if (i == 1)
745                                 j = 5; /* 32 */
746                         else {
747                                 i = jitCompA000_convTyp(i);
748                                 if (0x0002 <= i && i <= 0x0007)
749                                         j = (i - 0x0002) >> 1;
750                         }
751                         if (j < 0) { w.err = JITC_ERR_BADTYPE; goto err_w; }
752 #if (jitCompA0001_USE_R3F_IMM32 != 0)
753                         if (src[7] == 0x3f) {
754                                 j = w.r3f << j;
755 #if (jitCompA0001_USE_R3F_IMM8 != 0)
756                                 if (-0x80 <= j && j <= 0x7f) {
757 #if (jitCompA0001_USE_R3F_INCDEC != 0)
758                                         if (j == 1) { jitCompPutByte1(w.dst, 0x40 | reg0); goto padd1; } /* INC */
759                                         if (j == -1) { jitCompPutByte1(w.dst, 0x48 | reg0); goto padd1; } /* DEC */
760 #endif
761                                         jitCompPutByte3(w.dst, 0x83, 0xc0 | reg0, j & 0xff);    /* ADD(reg0, im8); */
762                                         goto padd1;
763                                 }
764 #endif
765                                 if (reg0 == 0) {
766                                         jitCompPutByte1(w.dst, 0x05);   /* ADD(reg0, ?); */
767                                 }
768                                 else {
769                                         jitCompPutByte2(w.dst, 0x81, 0xc0 | reg0);      /* ADD(reg0, ?); */
770                                 }
771                                 jitCompPutImm32(&w, j);
772                                 goto padd1;
773                         }
774 #endif
775                         if (src[7] >= 0x40) w.err = JITC_ERR_REGNUM;
776                         if (j == 0) {
777                                 reg1 = jitCompA000_selectRegCache(src[7], -1 /* mem */);
778                                 if (reg1 >= 0) {
779                                         jitCompPutByte2(w.dst, 0x01, 0xc0 | reg1 << 3 | reg0);  /* ADD(reg0, reg1); */
780                                 }
781                                 else {
782                                         jitCompPutByte1(w.dst, 0x03);   /* ADD(reg0, [EBP+?]); */
783                                         jitCompA0001_85DispN(&w, src[7] * 4, reg0);
784                                 }
785                         }
786                         else {
787                                 reg1 = jitCompA000_selectRegCache(src[7], -1 /* mem */);
788                                 reg2 = 2; /* EDX */
789                                 jitCompA000_storeRegCacheEdx(&w);
790                                 if (reg1 < 0)
791                                         jitCompA0001_movReg32EbpDisp(&w, reg2, src[7] * 4); /* MOV(reg2, [EBP+?]); */
792                                 if (reg1 >= 0 && reg1 != reg2) {
793                                         jitCompPutByte2(w.dst, 0x89, 0xc0 | reg1 << 3 | reg2); /* MOV(reg2, reg1); */
794                                 }
795                                 jitCompPutByte3(w.dst, 0xc1, 0xe0 | reg2, j);   /* SHL(reg2, ?); */
796                                 jitCompPutByte2(w.dst, 0x01, 0xc0 | reg2 << 3 | reg0);  /* ADD(reg0, reg2); */
797                                 jitCompA000_loadRegCacheEdx(&w);
798                         }
799 #if (jitCompA0001_USE_R3F_IMM32 != 0)
800                 padd1:
801 #endif
802                         if (reg0 == 0 /* EAX */)
803                                 jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + 0, reg0); /* MOV([EBP+?], reg0); */
804                         if (src[1] != src[6]) {
805                                 for (i = 4; i < 32; i += 4) {
806                                         jitCompA0001_movReg32EbpDisp(&w, 0 /* EAX */, 256 + src[6] * 32 + i); /* MOV(EAX, [EBP+?]); */
807                                         jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + i, 0 /* EAX */); /* MOV([EBP+?], EAX); */
808                                 }
809                         }
810                         cmp0reg = -1;
811                         break;
812
813                 case 0x0f: /* PDIF */   /* 未完成 */
814                         reg0 = jitCompA000_selectRegCache(src[1], 0 /* EAX */);
815                         jitCompA000_storePRegCacheAll(&w); // 手抜き.
816                         jitCompA0001_checkCompPtr(&w, src[6], src[7]);
817                         jitCompA0001_movReg32EbpDisp(&w, reg0, 256 + src[6] * 32 + 0); /* MOV(reg0, [EBP+?]); */
818                         jitCompPutByte1(w.dst, 0x2b);   /* SUB(EAX, [EBP+?]); */
819                         jitCompA0001_85DispN(&w, 256 + src[7] * 32 + 0, reg0);
820                         i = jitCompA000_convTyp(jitCompGetImm32(src + 2));
821                         j = -1;
822                         if (0x0002 <= i && i <= 0x0007)
823                                 j = (i - 0x0002) >> 1;
824                         if (j < 0) { w.err = JITC_ERR_BADTYPE; goto err_w; }
825                         if (j > 0) {
826                                 jitCompPutByte3(w.dst, 0xc1, 0xf8 | reg0, j);   /* SAR(reg0,?); */
827                         }
828                         if (reg0 == 0 /* EAX */)
829                                 jitCompA0001_movRxxEax(&w, src[1]);
830                         cmp0reg = src[1]; cmp0lev = 1;
831                         break;
832
833                 case 0x10:      /* OR */
834                 case 0x11:      /* XOR */
835                 case 0x12:      /* AND */
836                 case 0x14:      /* ADD */
837                 case 0x15:      /* SUB */
838                 case 0x16:      /* MUL */
839                         if (src[1] >= 0x3f) w.err = JITC_ERR_REGNUM;
840                         reg0 = jitCompA000_selectRegCache(src[1], 0 /* EAX */);
841                         reg1 = jitCompA000_selectRegCache(src[2], -1 /* mem */);
842 #if (jitCompA0001_USE_R3F_IMM32 != 0)
843                         if (src[2] == 0x3f) {   // SUBのみ該当.
844                                 if (*src != 0x15) w.err = JITC_ERR_REGNUM;
845                                 reg2 = jitCompA000_selectRegCache(src[3], -1 /* mem */);
846                                 if (reg2 >= 0)
847                                         jitCompA000_storeRegCacheAll(&w);
848                                 jitCompPutByte1(w.dst, 0xb8 | reg0);    /* MOV(reg0, ?); */
849                                 jitCompPutImm32(&w, w.r3f);
850                                 jitCompPutByte1(w.dst, 0x2b);
851                                 jitCompA0001_85DispN(&w, src[3] * 4, reg0);
852                                 if (reg0 == 0)
853                                         jitCompA0001_movRxxEax(&w, src[1]);
854                                 break;
855                         }
856 #endif
857                         if (reg1 < 0) {
858                                 jitCompA0001_movReg32EbpDisp(&w, reg0, src[2] * 4); /* MOV(reg0, [EBP+?]); */
859                         }
860                         if (reg1 >= 0 && reg0 != reg1) {
861                                 jitCompPutByte2(w.dst, 0x89, 0xc0 | reg1 << 3 | reg0); /* MOV(reg0, reg1); */
862                         }
863                         if (!(src[0] == 0x10 && src[3] == 0xff)) {  // bugfix: hinted by Iris, 2013.06.26. thanks!
864                                 cmp0reg = src[1];
865                                 cmp0lev = 1;
866                                 if (src[0] < 0x14)
867                                         cmp0lev = 2;
868                                 if (src[0] == 0x16)
869                                         cmp0reg = -1;
870                         }
871                         if (!(src[0] == 0x10 && src[3] == 0xff)) {
872 #if (jitCompA0001_USE_R3F_IMM32 != 0)
873                                 if (src[3] == 0x3f) {
874                                         if (*src == 0x16 && w.r3f == -1) {
875                                                 jitCompPutByte2(w.dst, 0xf7, 0xd8 | reg0); /* NEG(reg0); */
876                                                 if (reg0 == 0)
877                                                         jitCompA0001_movRxxEax(&w, src[1]);
878                                                 break;
879                                         }
880 #if (jitCompA0001_USE_R3F_INCDEC != 0)
881                                         if ((*src == 0x14 && w.r3f == 1) || (*src == 0x15 && w.r3f == -1)) {
882                                                 jitCompPutByte1(w.dst, 0x40 | reg0);    /* INC(reg0); */
883                                                 if (reg0 == 0)
884                                                         jitCompA0001_movRxxEax(&w, src[1]);
885                                                 break;
886                                         }
887                                         if ((*src == 0x15 && w.r3f == 1) || (*src == 0x14 && w.r3f == -1)) {
888                                                 jitCompPutByte1(w.dst, 0x48 | reg0);    /* DEC(reg0); */
889                                                 if (reg0 == 0)
890                                                         jitCompA0001_movRxxEax(&w, src[1]);
891                                                 break;
892                                         }
893 #endif
894 #if (jitCompA0001_USE_R3F_IMM8 != 0)
895                                         if (-0x80 <= w.r3f && w.r3f <= 0x7f) {
896                                                 if (*src != 0x16) {
897                                                         static unsigned char basic_op_table_im8[] = { 0xc8, 0xf0, 0xe0, 0, 0xc0, 0xe8 };
898                                                         jitCompPutByte3(w.dst, 0x83, basic_op_table_im8[*src - 0x10] | reg0, w.r3f & 0xff);
899                                                 }
900                                                 else {
901                                                         jitCompPutByte3(w.dst, 0x6b, 0xc0 | reg0 << 3 | reg0, w.r3f & 0xff);
902                                                 }
903                                                 if (reg0 == 0)
904                                                         jitCompA0001_movRxxEax(&w, src[1]);
905                                                 break;
906                                         }
907 #endif
908                                         if (reg0 == 0 /* EAX */) {
909                                                 static unsigned char basic_op_table_im32_eax[] = { 0x0d, 0x35, 0x25, 0, 0x05, 0x2d, 0xc0 };
910                                                 if (*src == 0x16) { jitCompPutByte1(w.dst, 0x69); }
911                                                 jitCompPutByte1(w.dst, basic_op_table_im32_eax[*src - 0x10]);
912                                         }
913                                         else {
914                                                 if (*src != 0x16) {
915                                                         static unsigned char basic_op_table_im32_reg[] = { 0xc8, 0xf0, 0xe0, 0, 0xc0, 0xe8 };
916                                                         jitCompPutByte2(w.dst, 0x81, basic_op_table_im32_reg[*src - 0x10] | reg0);
917                                                 }
918                                                 else {
919                                                         jitCompPutByte2(w.dst, 0x69, 0xc0 | reg0 << 3 | reg0);
920                                                 }
921                                         }
922                                         jitCompPutImm32(&w, w.r3f);
923                                         if (reg0 == 0)
924                                                 jitCompA0001_movRxxEax(&w, src[1]);
925                                         break;
926                                 }
927 #endif
928                                 reg1 = jitCompA000_selectRegCache(src[3], -1 /* mem */);
929                                 if (src[3] >= 0x40) w.err = JITC_ERR_REGNUM;
930                                 if (*src != 0x16) {
931                                         if (reg1 >= 0) {
932                                                 static unsigned char basic_op_table_rr[] = { 0x09, 0x31, 0x21, 0, 0x01, 0x29 }; /* op(reg,reg); */
933                                                 jitCompPutByte2(w.dst, basic_op_table_rr[*src - 0x10], 0xc0 | reg1 << 3 | reg0);
934                                         }
935                                         else {
936                                                 static unsigned char basic_op_table_rm[] = { 0x0b, 0x33, 0x23, 0, 0x03, 0x2b, 0xaf }; /* op(reg,mem); */
937                                                 jitCompPutByte1(w.dst, basic_op_table_rm[*src - 0x10]);
938                                                 jitCompA0001_85DispN(&w, src[3] * 4, reg0);
939                                         }
940                                 }
941                                 else {
942                                         if (reg1 >= 0) {
943                                                 jitCompPutByte3(w.dst, 0x0f, 0xaf, 0xc0 | reg0 << 3 | reg1);
944                                         }
945                                         else {
946                                                 jitCompPutByte2(w.dst, 0x0f, 0xaf);
947                                                 jitCompA0001_85DispN(&w, src[3] * 4, reg0);
948                                         }
949                                 }
950                         }
951                         if (reg0 == 0)
952                                 jitCompA0001_movRxxEax(&w, src[1]);
953                         break;
954
955                 case 0x18:      /* SHL */
956                 case 0x19:      /* SAR */
957                         if (src[1] >= 0x3f) w.err = JITC_ERR_REGNUM;
958                         if (src[3] >= 0x40) w.err = JITC_ERR_REGNUM;
959 #if (jitCompA0001_USE_R3F_IMM32 != 0)
960                         if (src[3] == 0x3f) {
961                                 reg0 = jitCompA000_selectRegCache(src[1], 0 /* EAX */);
962                                 reg1 = jitCompA000_selectRegCache(src[2], -1 /* mem */);
963                                 if (src[1] >= 0x3f) w.err = JITC_ERR_REGNUM;
964                                 if (reg1 == -1)
965                                         jitCompA0001_movReg32EbpDisp(&w, reg0, src[2] * 4); /* MOV(reg1, [EBP+?]); */
966                                 else {
967                                         if (reg0 != reg1) {
968                                                 jitCompPutByte2(w.dst, 0x89, 0xc0 | reg1 << 3 | reg0); /* MOV(reg0, reg1); */
969                                         }
970                                 }
971                                 if (*src == 0x18) { jitCompPutByte3(w.dst, 0xc1, 0xe0 | reg0, w.r3f); } /* SHL(reg0, im8); */
972                                 if (*src == 0x19) { jitCompPutByte3(w.dst, 0xc1, 0xf8 | reg0, w.r3f); } /* SAR(reg0, im8); */
973                                 if (reg0 == 0 /* EAX */)
974                                         jitCompA0001_movRxxEax(&w, src[1]);
975                                 cmp0reg = src[1];
976                                 cmp0lev = 1;
977                                 break;
978                         }
979 #endif
980                         jitCompA000_storeRegCacheAll(&w); // 手抜き.
981                         jitCompA0001_movReg32EbpDisp(&w, 1 /* ECX */, src[3] * 4); /* MOV(ECX, [EBP+?]); */
982 #if (jitCompA0001_USE_R3F_IMM32 != 0)
983                         if (src[2] == 0x3f) {
984                                 jitCompPutByte1(w.dst, 0xb8);   /* MOV(EAX, ?); */
985                                 jitCompPutImm32(&w, w.r3f);
986                         }
987                         else {
988                                 jitCompA0001_movEaxRxx(&w, src[2]);
989                         }
990 #else
991                         jitCompA0001_movEaxRxx(&w, src[2]);
992 #endif
993                         if (*src == 0x18) { jitCompPutByte2(w.dst, 0xd3, 0xe0); } /* SHL(EAX, CL); */
994                         if (*src == 0x19) { jitCompPutByte2(w.dst, 0xd3, 0xf8); } /* SAR(EAX, CL); */
995                         jitCompA0001_movRxxEax(&w, src[1]);
996                         jitCompA000_loadRegCacheAll(&w); // 手抜き.
997                         cmp0reg = src[1];
998                         cmp0lev = 1;
999                         break;
1000
1001                 case 0x1a:      /* DIV */
1002                 case 0x1b:      /* MOD */
1003                         if (src[1] >= 0x3f) w.err = JITC_ERR_REGNUM;
1004                         if (src[2] >= 0x40) w.err = JITC_ERR_REGNUM;
1005                         if (src[3] >= 0x40) w.err = JITC_ERR_REGNUM;
1006                         jitCompA000_storeRegCacheAll(&w); // 手抜き.
1007 #if (jitCompA0001_USE_R3F_IMM32 != 0)
1008                         if (src[3] == 0x3f) {
1009                                 jitCompPutByte1(w.dst, 0xb8 | 1);       /* MOV(ECX, ?); */
1010                                 jitCompPutImm32(&w, w.r3f);
1011                         }
1012                         else {
1013                                 jitCompA0001_movReg32EbpDisp(&w, 1 /* ECX */, src[3] * 4); /* MOV(ECX, [EBP+?]); */
1014                         }
1015                         if (src[2] == 0x3f) {
1016                                 jitCompPutByte1(w.dst, 0xb8 | 0);       /* MOV(EAX, ?); */
1017                                 jitCompPutImm32(&w, w.r3f);
1018                         }
1019                         else {
1020                                 jitCompA0001_movReg32EbpDisp(&w, 0 /* EAX */, src[2] * 4); /* MOV(EAX, [EBP+?]); */
1021                         }
1022 #else
1023                         jitCompA0001_movReg32EbpDisp(&w, 1 /* ECX */, src[3] * 4); /* MOV(ECX, [EBP+?]); */
1024                         jitCompA0001_movReg32EbpDisp(&w, 0 /* EAX */, src[2] * 4); /* MOV(EAX, [EBP+?]); */
1025 #endif
1026                         jitCompPutByte1(w.dst, 0x99);   /* CDQ(); */
1027                         /* ECXがゼロではないことを確認すべき */
1028                         jitCompPutByte2(w.dst, 0xf7, 0xf9);     /* IDIV(ECX); */
1029                         if (*src == 0x1a) { jitCompA0001_movEbpDispReg32(&w, src[1] * 4, 0 /* EAX */); }
1030                         if (*src == 0x1b) { jitCompA0001_movEbpDispReg32(&w, src[1] * 4, 2 /* EDX */); }
1031                         jitCompA000_loadRegCacheAll(&w); // 手抜き.
1032                         cmp0reg = -1;
1033                         break;
1034
1035                 case 0x1c:      /* PLMT0 */
1036                 case 0x1d:      /* PLMT1 */
1037                         if (src[1] >= 0x40 || src[2] >= 0x40) w.err = JITC_ERR_PREGNUM;
1038                         if (level < JITC_LV_FASTEST) {
1039                                 cmp0reg = -1;
1040                                 if (level < JITC_LV_FASTER) {
1041                                         // typ が一致していることを確認.
1042                                         // plsとliveSignが一致していることを確認.
1043
1044                                         // preg1はp0 <= p <= p1 を満たしているか?.
1045                                         // 新しいp0/p1は古いp0〜p1に適合しているか?.
1046
1047                                 }
1048                         }
1049
1050                 case 0x1e: /* PCP */            /* 未完成(p1まで完成) */
1051                         if (src[1] >= 0x40 || src[2] >= 0x40) w.err = JITC_ERR_PREGNUM;
1052                         if (src[2] == 0x3f) w.err = JITC_ERR_PREGNUM;
1053                         if (src[1] != 0x3f) {
1054                                 /* src[2] == 0xff の場合に対応できてない */
1055                                 jitCompA000_storePRegCacheAll(&w); // 手抜き.
1056                                 for (i = 0; i < 32; i += 4) {
1057                                         jitCompA0001_movReg32EbpDisp(&w, 0 /* EAX */, 256 + src[2] * 32 + i); /* MOV(EAX, [EBP+?]); */
1058                                         jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + i, 0 /* EAX */); /* MOV([EBP+?], EAX); */
1059                                 }
1060                                 jitCompA000_loadPRegCacheAll(&w); // 手抜き.
1061                         }
1062                         else {
1063                                 if (level < JITC_LV_FASTER) {
1064                                         jitCompA0001_movReg32EbpDisp(&w, 0 /* EAX */, 256 + src[2] * 32 + 4); /* MOV(EAX, [EBP+?]); */  /* typ */
1065                                         jitCompPutByte3(w.dst, 0x83, 0xf8, 0);  /* CMP(EAX, 0); */
1066                                         jitCompPutByte2(w.dst, 0x0f, 0x85); /* JNE */
1067                                         jitCompPutImm32(&w, errfnc - (w.dst + 4));
1068                                         /* セキュリティチェックが足りてない!(aliveとか) */
1069                                 }
1070                                 reg0 = 0; /* EAX */
1071                                 jitCompA000_storePRegCacheAll(&w); // 手抜き.
1072                                 jitCompA0001_movReg32EbpDisp(&w, reg0, 256 + src[2] * 32 + 0); /* MOV(EAX, [EBP+?]); */
1073                                 if (level < JITC_LV_FASTER) {
1074                                         jitCompPutByte1(w.dst, 0x3b);   /* CMP(reg0, [EBP+?]); */
1075                                         jitCompA0001_85DispN(&w, 256 + src[2] * 32 + 8, reg0);  /* p0 */
1076                                         jitCompPutByte2(w.dst, 0x0f, 0x85); /* JNE */
1077                                         jitCompPutImm32(&w, errfnc - (w.dst + 4));
1078                                 }
1079                                 jitCompPutByte2(w.dst, 0xff, 0xe0);     /* JMP(EAX); */
1080                         }
1081                         break;
1082
1083                 case 0x1f: /* PCST */
1084                         if (jitCompGetImm32(src + 2) == 0) {
1085                                 if (level < JITC_LV_FASTER)
1086                                         jitCompA0001_checkType0(&w, src[6], jitCompGetImm32(src + 7), 2);
1087                                 jitCompA000_storePRegCacheAll(&w); // 手抜き.
1088                                 for (i = 0; i < 32 - 4; i += 4) {
1089                                         jitCompA0001_movReg32EbpDisp(&w, 0 /* EAX */, 256 + src[6] * 32 + i); /* MOV(EAX, [EBP+?]); */
1090                                         if (i == 4) {
1091                                                 jitCompPutByte1(w.dst, 0x0d); /* OR(EAX, ?); */
1092                                                 jitCompPutImm32(&w, 0x80000000);
1093                                         }
1094                                         jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + i, 0 /* EAX */); /* MOV([EBP+?], EAX); */
1095                                 }
1096                                 jitCompPutByte1(w.dst, 0xb8);   /* MOV(EAX, ?); */
1097                                 jitCompPutImm32(&w, debugInfo1);
1098                                 jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + 28, 0 /* EAX */); /* MOV([EBP+?], EAX); */
1099                                 jitCompA000_loadPRegCacheAll(&w); // 手抜き.
1100                                 cmp0reg = -1;
1101                                 break;
1102                         }
1103                         if (jitCompGetImm32(src + 7) == 0) {
1104                                 jitCompA000_storePRegCacheAll(&w); // 手抜き.
1105                                 for (i = 0; i < 32 - 4; i += 4) {
1106                                         jitCompA0001_movReg32EbpDisp(&w, 0 /* EAX */, 256 + src[6] * 32 + i); /* MOV(EAX, [EBP+?]); */
1107                                         if (i == 4) {
1108                                                 jitCompPutByte1(w.dst, 0x25); /* AND(EAX, ?); */
1109                                                 jitCompPutImm32(&w, 0x7fffffff);
1110                                         }
1111                                         jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + i, 0 /* EAX */); /* MOV([EBP+?], EAX); */
1112                                 }
1113                                 if (level < JITC_LV_FASTER) {
1114                                         jitCompA0001_movReg32EbpDisp(&w, 0 /* EAX */, 256 + src[6] * 32 + 28); /* MOV(EAX, [EBP+?]); */
1115                                         jitCompPutByte1(w.dst, 0x3d);   /* CMP(EAX, ?); */
1116                                         jitCompPutImm32(&w, debugInfo1);
1117                                         jitCompPutByte2(w.dst, 0x74, 8); /* JE */
1118                                         jitCompPutByte2(w.dst, 0x31, 0xc0);     /* XOR(EAX, EAX); (2) */
1119                                         jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + 0, 0 /* EAX */); /* MOV([EBP+?], EAX); (1+1+4) */
1120                                 }
1121                                 jitCompA000_loadPRegCacheAll(&w); // 手抜き.
1122                                 cmp0reg = -1;
1123                                 break;
1124                         }
1125                         w.err = JITC_ERR_OPECODE;
1126                         goto err_w;
1127
1128                 case 0x20:      /* CMPE */
1129                 case 0x21:      /* CMPNE */
1130                 case 0x22:      /* CMPL */
1131                 case 0x23:      /* CMPGE */
1132                 case 0x24:      /* CMPLE */
1133                 case 0x25:      /* CMPG */
1134                 case 0x26:      /* TSTZ */
1135                 case 0x27:      /* TSTNZ */
1136                         reg0 = jitCompA000_selectRegCache(src[2], 0 /* EAX */);
1137                         reg1 = jitCompA000_selectRegCache(src[3], -1 /* mem */);
1138                         if (src[1] == 0x3f) {
1139                                 /* 特殊構文チェック */
1140                                 if (w.prefix != 0) { w.err = JITC_ERR_PREFIX; goto err_w; }
1141                                 if (src[4] != 0x04 || src[5] != 0x3f || src[6] != 0x03 || src[7] != 0x3f) {
1142                                         w.err = JITC_ERR_IDIOM; goto err_w;
1143                                 }
1144                         }
1145                         if (reg0 == 0)
1146                                 jitCompA0001_movEaxRxx(&w, src[2]);
1147 #if (jitCompA0001_USE_R3F_IMM32 != 0)
1148                         if (src[3] == 0x3f) {
1149 #if (jitCompA0001_OPTIMIZE_CMP != 0)
1150                                 if ((*src <= 0x25 && w.r3f == 0) || (*src >= 0x26 && w.r3f == -1)) {
1151                                         i = 0;
1152                                         if (cmp0reg == src[2]) {
1153                                                 if (cmp0lev >= 1 && (src[0] == 0x20 || src[0] == 0x21 || src[0] == 0x26 || src[0] == 0x27))
1154                                                         i = 1;
1155                                                 if (cmp0lev >= 2 && (src[0] == 0x22 || src[0] == 0x23 || src[0] == 0x24 || src[0] == 0x25))
1156                                                         i = 1;
1157                                         }
1158                                         if (i == 0) {
1159                                                 jitCompPutByte2(w.dst, 0x85, 0xc0 | reg0 << 3 | reg0);  /* TEST(reg0, reg0); */
1160                                         }
1161                                         cmp0reg = src[2];
1162                                         cmp0lev = 2;
1163                                         goto cmpcc1;
1164                                 }
1165 #endif
1166 #if (jitCompA0001_USE_R3F_IMM8 != 0)
1167                                 if (-0x80 <= w.r3f && w.r3f <= 0x7f && *src <= 0x25) {
1168                                         jitCompPutByte3(w.dst, 0x83, 0xf8 | reg0, w.r3f);
1169                                         goto cmpcc1;
1170                                 }
1171 #endif
1172                                 if (reg0 == 0) {
1173                                         if (*src <= 0x25) { jitCompPutByte1(w.dst, 0x3d); }
1174                                         if (*src >= 0x26) { jitCompPutByte1(w.dst, 0xa9); }
1175                                 }
1176                                 else {
1177                                         if (*src <= 0x25) { jitCompPutByte2(w.dst, 0x81, 0xf8 | reg0); }
1178                                         if (*src >= 0x26) { jitCompPutByte2(w.dst, 0xf7, 0xc0 | reg0); }
1179                                 }
1180                                 jitCompPutImm32(&w, w.r3f);
1181                                 goto cmpcc1;
1182                         }
1183 #endif
1184                         if (src[3] >= 0x40) w.err = JITC_ERR_PREGNUM;
1185                         if (reg1 >= 0) {
1186                                 if (*src <= 0x25) { jitCompPutByte2(w.dst, 0x39, 0xc0 | reg1 << 3 | reg0); }
1187                                 if (*src >= 0x26) { jitCompPutByte2(w.dst, 0x85, 0xc0 | reg1 << 3 | reg0); }
1188                         }
1189                         else {
1190                                 if (*src <= 0x25) { jitCompPutByte1(w.dst, 0x3b); }
1191                                 if (*src >= 0x26) { jitCompPutByte1(w.dst, 0x85); }
1192                                 jitCompA0001_85DispN(&w, src[3] * 4, reg0);
1193                         }
1194                 cmpcc1:
1195                         if (w.err != 0) goto err_w;
1196                         static unsigned char cmpcc_table0[] = {
1197                                 0x04, 0x05, 0x0c, 0x0d, 0x0e, 0x0f, 0x04, 0x05, /* CMPcc, TSTcc */
1198                                 0x04, 0x05, 0x02, 0x03, 0x06, 0x07                              /* PCMPcc */
1199                         };
1200 #if (jitCompA0001_USE_R3F_CMPJMP != 0)
1201                         if (src[1] == 0x3f) {
1202                                 /* 特殊構文を利用した最適化 */
1203                                 jitCompPutByte2(w.dst, 0x0f, 0x80 | cmpcc_table0[*src - 0x20]);
1204                                 src += 6;
1205                                 i = jitCompGetLabelNum(&w, src + 2);
1206                                 if ((flags & JITC_PHASE1) != 0 && w.err != 0) {
1207                                         if (label[i].opt == 0) { w.err = JITC_ERR_LABELNODEF; goto err_w; }
1208                                         //      if (label[i].typ != 1) { w.err = JITC_ERR_LABELTYP; goto err_w; }
1209                                 }
1210                                 j = 0;
1211                                 if ((flags & JITC_PHASE1) != 0 || ((flags & JITC_PHASE1) == 0) && label[i].opt != 0)
1212                                         j = label[i].p - (w.dst + 4);
1213                                 jitCompPutImm32(&w, j);
1214 #if (jitCompA0001_OPTIMIZE_JMP != 0)
1215                                 if (-128 - 4 <= j && j < 0) {
1216                                         j += 4;
1217                                         w.dst -= 6;
1218                                         jitCompPutByte2(w.dst, w.dst[1] ^ 0xf0, j & 0xff);
1219                                 }
1220 #endif
1221                                 src += 6;
1222                                 if (w.err != 0) goto err_w;
1223                                 continue;
1224                         }
1225 #endif
1226                         /* 一般的なJITC */
1227                         reg0 = jitCompA000_selectRegCache(src[1], 0 /* EAX */);
1228                         jitCompPutByte3(w.dst, 0x0f, 0x90 | cmpcc_table0[*src - 0x20], 0xc0 | reg0);    /* SETcc(BYTE(reg0)); */
1229                         jitCompPutByte3(w.dst, 0x0f, 0xb6, 0xc0 | reg0 << 3 | reg0);    /* MOVZX(reg0, BYTE(reg0)); */
1230                         jitCompPutByte2(w.dst, 0xf7, 0xd8 | reg0);      /* NEG(reg0); */
1231                         if (reg0 == 0)
1232                                 jitCompA0001_movRxxEax(&w, src[1]);
1233                         cmp0reg = src[2];
1234                         cmp0lev = 1;
1235                         break;
1236
1237                 case 0x28:      /* PCMPE */
1238                 case 0x29:      /* PCMPNE */
1239                 case 0x2a:      /* PCMPL */
1240                 case 0x2b:      /* PCMPGE */
1241                 case 0x2c:      /* PCMPLE */
1242                 case 0x2d:      /* PCMPG */
1243                         if (src[1] == 0x3f) {
1244                                 /* 特殊構文チェック */
1245                                 if (w.prefix != 0) { w.err = JITC_ERR_PREFIX; goto err_w; }
1246                                 if (src[4] != 0x04 || src[5] != 0x3f || src[6] != 0x03 || src[7] != 0x3f) {
1247                                         w.err = JITC_ERR_IDIOM; goto err_w;
1248                                 }
1249                         }
1250                         if (src[2] >= 0x40) w.err = JITC_ERR_PREGNUM;
1251                         jitCompA000_storePRegCacheAll(&w); // 手抜き.
1252                         if (src[3] != 0xff)
1253                                 jitCompA0001_checkCompPtr(&w, src[2], src[3]);
1254                         jitCompA0001_movReg32EbpDisp(&w, 0 /* EAX */, 256 + src[2] * 32 + 0); /* MOV(EAX, [EBP+?]); */
1255                         if (src[3] != 0xff) {
1256                                 jitCompPutByte1(w.dst, 0x3b);   /* CMP(EAX, [EBP+?]); */
1257                                 jitCompA0001_85DispN(&w, 256 + src[3] * 32 + 0, 0);
1258                         }
1259                         else {
1260                                 /* ヌルポインタとの比較はこれでいいのか?たぶんよくない */
1261                                 jitCompPutByte3(w.dst, 0x83, 0xf8, 0x00);       /* CMP(EAX, 0); */
1262                         }
1263                         cmp0reg = -1;
1264                         goto cmpcc1;
1265
1266                 case 0x30:      /* talloc(old:F4) */
1267                 case 0x31:      /* tfree(old:F5) */
1268                 case 0x32:      /* malloc(old:F6) */
1269                 case 0x33:      /* mfree(old:F7) */
1270                         jitCompA000_storeRegCacheAll(&w); // 手抜き.
1271                         jitCompA000_storePRegCacheAll(&w); // 手抜き.
1272                         jitCompPutByte2(w.dst, 0x6a, src[3]);   /* PUSH(?); */
1273                         jitCompPutByte2(w.dst, 0x6a, src[2]);   /* PUSH(?); */
1274                         jitCompPutByte2(w.dst, 0x6a, src[1]);   /* PUSH(?); */
1275                         jitCompPutByte1(w.dst, 0x55);   /* PUSH(EBP); */
1276                         jitCompPutByte1(w.dst, 0xe8);
1277                         if (*src == 0x30) j = ((unsigned char *)&funcf4) - (w.dst + 4);
1278                         if (*src == 0x31) j = ((unsigned char *)&funcf5) - (w.dst + 4);
1279                         if (*src == 0x32) j = ((unsigned char *)&funcf6) - (w.dst + 4);
1280                         if (*src == 0x33) j = ((unsigned char *)&funcf7) - (w.dst + 4);
1281                         jitCompPutImm32(&w, j);
1282                         jitCompPutByte3(w.dst, 0x83, 0xc4, 0x10);       /* ADD(ESP,16); */
1283                         jitCompA000_loadRegCacheAll(&w); // 手抜き.
1284                         jitCompA000_loadPRegCacheAll(&w); // 手抜き.
1285                         cmp0reg = -1;
1286                         break;
1287
1288                 case 0x34:      /* data (暫定) */
1289                         cmp0reg = -1;
1290                         if (w.prefix != 0) { w.err = JITC_ERR_PREFIX; goto err_w; }
1291                         int k = jitCompGetImm32(&src[1]), tmpData, bitCount, dataWidth = jitCompA000_dataWidth(k);
1292                         if (lastlabel >= 0 && label[lastlabel].typ == 0)
1293                                 label[lastlabel].typ = k;
1294                         if (k != 1) {
1295                                 i = jitCompA000_convTyp(k);
1296                                 if (i < 2 || i > 7) { w.err = JITC_ERR_BADTYPE; goto err_w; }
1297                         }
1298                         j = jitCompGetImm32(&src[5]);
1299                         oldsrc = src;
1300                         src += 9;
1301                         if (k != 1) {
1302                                 bitCount = 7;
1303                                 while (j > 0) {
1304                                         if (src >= src1) { w.err = JITC_ERR_SRC1; src = oldsrc; goto err_w; }
1305                                         if (w.dst + 256 > dst1) { w.err = JITC_ERR_DST1; src = oldsrc; goto err_w; }
1306                                         tmpData = 0;
1307                                         for (k = 0; k < dataWidth; k++) {
1308                                                 tmpData = tmpData << 1 | ((*src >> bitCount) & 1);
1309                                                 bitCount--;
1310                                                 if (bitCount < 0) {
1311                                                         bitCount = 7;
1312                                                         src++;
1313                                                 }
1314                                         }
1315                                         if ((i & 1) == 0 && dataWidth <= 31 && (tmpData >> (dataWidth - 1)) != 0) {
1316                                                 tmpData -= 1 << dataWidth;
1317                                         }
1318                                         if (i == 2 || i == 3) { jitCompPutByte1(w.dst, tmpData & 0xff); }
1319                                         if (i == 4 || i == 5) { jitCompPutByte2(w.dst, tmpData & 0xff, (tmpData >> 8) & 0xff); }
1320                                         if (i == 6 || i == 7) { jitCompPutByte4(w.dst, tmpData & 0xff, (tmpData >> 8) & 0xff, (tmpData >> 16) & 0xff, (tmpData >> 24) & 0xff); }
1321                                         j--;
1322                                 }
1323                         }
1324                         else {
1325                                 while (j > 0) {
1326                                         if (src >= src1) { w.err = JITC_ERR_SRC1; src = oldsrc; goto err_w; }
1327                                         if (w.dst + 256 > dst1) { w.err = JITC_ERR_DST1; src = oldsrc; goto err_w; }
1328                                         i = jitCompGetImm32(src);
1329                                         src += 4;
1330                                         if ((flags & JITC_PHASE1) != 0 && w.err == 0) {
1331                                                 if (label[i].opt == 0) { w.err = JITC_ERR_LABELNODEF; goto err_w; }
1332                                         }
1333                                         jitCompPutImm32(&w, (int)label[i].p);
1334                                         jitCompPutImm32(&w, label[i].typ);
1335                                         jitCompPutImm32(&w, (int)label[i].p);
1336                                         jitCompPutImm32(&w, (int)label[i].p1);
1337                                         jitCompPutImm32(&w, 0); /* liveSign */
1338                                         jitCompPutImm32(&w, 2320); /* pls */
1339                                         jitCompPutImm32(&w, 0);
1340                                         jitCompPutImm32(&w, 0);
1341                                         j--;
1342                                 }
1343                         }
1344                         if (lastlabel >= 0 && label[lastlabel].p1 < w.dst)
1345                                 label[lastlabel].p1 = w.dst;
1346                         continue;
1347
1348                 case 0x3c:      /* ENTER */
1349                         jitCompA000_storeRegCacheAll(&w); // 手抜き.
1350                         jitCompA000_storePRegCacheAll(&w); // 手抜き.
1351                         jitCompPutByte2(w.dst, 0x6a, src[6]);   /* PUSH(?); */
1352                         jitCompPutByte2(w.dst, 0x6a, src[5]);   /* PUSH(?); */
1353                         jitCompPutByte2(w.dst, 0x6a, src[4] & 0x0f);    /* PUSH(?); */
1354                         jitCompPutByte2(w.dst, 0x6a, (src[4] >> 4) & 0x0f);     /* PUSH(?); */
1355                         jitCompPutByte2(w.dst, 0x6a, src[3]);   /* PUSH(?); */
1356                         jitCompPutByte2(w.dst, 0x6a, src[2]);   /* PUSH(?); */
1357                         jitCompPutByte2(w.dst, 0x6a, src[1]);   /* PUSH(?); */
1358                         jitCompPutByte1(w.dst, 0x55);   /* PUSH(EBP); */
1359                         jitCompPutByte1(w.dst, 0xe8);
1360                         j = ((unsigned char *)&func3c) - (w.dst + 4);
1361                         jitCompPutImm32(&w, j);
1362                         jitCompPutByte3(w.dst, 0x83, 0xc4, 0x20);       /* ADD(ESP,32); */
1363                         jitCompA000_loadRegCacheAll(&w); // 手抜き.
1364                         jitCompA000_loadPRegCacheAll(&w); // 手抜き.
1365                         cmp0reg = -1;
1366                         break;
1367
1368                 case 0x3d:      /* LEAVE */
1369                         jitCompA000_storeRegCacheAll(&w); // 手抜き.
1370                         jitCompA000_storePRegCacheAll(&w); // 手抜き.
1371                         jitCompPutByte2(w.dst, 0x6a, src[6]);   /* PUSH(?); */
1372                         jitCompPutByte2(w.dst, 0x6a, src[5]);   /* PUSH(?); */
1373                         jitCompPutByte2(w.dst, 0x6a, src[4] & 0x0f);    /* PUSH(?); */
1374                         jitCompPutByte2(w.dst, 0x6a, (src[4] >> 4) & 0x0f);     /* PUSH(?); */
1375                         jitCompPutByte2(w.dst, 0x6a, src[3]);   /* PUSH(?); */
1376                         jitCompPutByte2(w.dst, 0x6a, src[2]);   /* PUSH(?); */
1377                         jitCompPutByte2(w.dst, 0x6a, src[1]);   /* PUSH(?); */
1378                         jitCompPutByte1(w.dst, 0x55);   /* PUSH(EBP); */
1379                         jitCompPutByte1(w.dst, 0xe8);
1380                         j = ((unsigned char *)&func3d) - (w.dst + 4);
1381                         jitCompPutImm32(&w, j);
1382                         jitCompPutByte3(w.dst, 0x83, 0xc4, 0x20);       /* ADD(ESP,32); */
1383                         jitCompA000_loadRegCacheAll(&w); // 手抜き.
1384                         jitCompA000_loadPRegCacheAll(&w); // 手抜き.
1385                         cmp0reg = -1;
1386                         break;
1387
1388                 case 0xfe:      /* remark */
1389                         if (src[1] == 0x01 && src[2] == 0x00) { // DBGINFO1
1390                                 if (level <= JITC_LV_SLOWER) {
1391                                         jitCompPutByte1(w.dst, 0xb8);   /* MOV(EAX, ?); */
1392                                         jitCompPutImm32(&w, debugInfo1);
1393                                         jitCompA0001_movEbpDispReg32(&w, 2304 + 4, 0 /* EAX */); /* MOV(debugInfo1, EAX); */
1394                                 }
1395                         }
1396                         if (src[1] == 0x01 && src[2] == 0x03) { // DBGINFO1CLR
1397                                 if (level <= JITC_LV_SLOWER) {
1398                                         jitCompPutByte1(w.dst, 0xb8);   /* MOV(EAX, ?); */
1399                                         jitCompPutImm32(&w, -1);
1400                                         jitCompA0001_movEbpDispReg32(&w, 2304 + 4, 0 /* EAX */); /* MOV(debugInfo1, EAX); */
1401                                 }
1402                         }
1403                         if (src[1] == 0x05 && src[2] == 0x00) { // DBGINFO0
1404                                 if (level <= JITC_LV_SLOWEST) {
1405                                         debugInfo0 = jitCompGetImm32(src + 3);
1406                                         //      jitCompPutByte1(w.dst, 0xbf);   /* MOV(EDI, ?); */
1407                                         //      jitCompPutImm32(&w, debugInfo0);
1408                                         jitCompPutByte1(w.dst, 0xb8);   /* MOV(EAX, ?); */
1409                                         jitCompPutImm32(&w, debugInfo0);
1410                                         jitCompA0001_movEbpDispReg32(&w, 2304 + 0, 0 /* EAX */); /* MOV(debugInfo0, EAX); */
1411                                 }
1412                         }
1413                         break;
1414
1415                 default:
1416                         w.err = JITC_ERR_OPECODE;
1417                         goto err_w;
1418                 }
1419                 if (w.err != 0) goto err_w;
1420                 jitCompA0001_fixPrefix(&w);
1421                 if (w.err != 0) goto err_w;
1422                 src += jitCompCmdLen(src);
1423         }
1424         if (enter0 != NULL) {
1425                 j = w.dst - (enter0 + 4);
1426                 enter0[0] = j & 0xff;
1427                 enter0[1] = (j >> 8) & 0xff;
1428                 enter0[2] = (j >> 16) & 0xff;
1429                 enter0[3] = (j >> 24) & 0xff;
1430         }
1431         if ((flags & JITC_NOSTARTUP) == 0) {
1432                 jitCompA000_storeRegCacheAll(&w);
1433                 jitCompA000_storePRegCacheAll(&w);
1434                 jitCompPutByte1(w.dst, 0x61); /* POPAD(); */
1435         }
1436         if ((flags & JITC_PHASE1) != 0)
1437                 return w.dst - dst00;
1438         return 0;
1439
1440 err_w:
1441         if ((w.err & JITC_ERR_PHASE0ONLY) != 0) {
1442                 if ((flags & JITC_PHASE1) == 0)
1443                         w.err &= ~JITC_ERR_PHASE0ONLY;
1444         }
1445         if (w.err == (JITC_ERR_MASK & JITC_ERR_REGNUM))                 errmsg = "reg-number error";
1446         if (w.err == (JITC_ERR_MASK & JITC_ERR_DST1))                   errmsg = "dst1 error";
1447         if (w.err == (JITC_ERR_MASK & JITC_ERR_OPECODE))                errmsg = "opecode error";
1448         if (w.err == (JITC_ERR_MASK & JITC_ERR_LABELNUM))               errmsg = "label number too large";
1449         if (w.err == (JITC_ERR_MASK & JITC_ERR_LABELREDEF))             errmsg = "label redefine";
1450         if (w.err == (JITC_ERR_MASK & JITC_ERR_PREFIX))                 { errmsg = "prefix redefine"; w.dst -= 2; }
1451         if (w.err == (JITC_ERR_MASK & JITC_ERR_LABELNODEF))             errmsg = "label not defined";
1452         if (w.err == (JITC_ERR_MASK & JITC_ERR_LABELTYP))               errmsg = "label type error";
1453         if (w.err == (JITC_ERR_MASK & JITC_ERR_IDIOM))                  errmsg = "idiom error";
1454         if (w.err == (JITC_ERR_MASK & JITC_ERR_PREGNUM))                errmsg = "preg-number error";
1455         if (w.err == (JITC_ERR_MASK & JITC_ERR_SRC1))                   errmsg = "src1 error";
1456         if (w.err == (JITC_ERR_MASK & JITC_ERR_BADTYPE))                errmsg = "bad type code";
1457         if (w.err == (JITC_ERR_MASK & JITC_ERR_PREFIXFAR))              errmsg = "prefix internal error";
1458         if (w.err == (JITC_ERR_MASK & JITC_ERR_INTERNAL))               errmsg = "general internal error";
1459         if (*errmsg != '¥0') {
1460                 fprintf(stderr, "JITC: %s at %06X (debugInfo0=%d)¥n    ", errmsg, src - src0, debugInfo0);
1461                 for (i = 0; i < 16; i++)
1462                         fprintf(stderr, "%02X ", src[i]);
1463                 static char *table[0x30] = {
1464                         "NOP", "LB", "LIMM", "PLIMM", "CND", "??", "??", "??",
1465                         "LMEM", "SMEM", "PLMEM", "PSMEM", "LEA", "??", "PADD", "PDIF",
1466                         "CP/OR", "XOR", "AND", "??", "ADD", "SUB", "MUL", "??",
1467                         "SHL", "SAR", "DIV", "MOD", "PLMT0", "PLMT1", "PCP", "PCST",
1468                         "CMPE", "CMPNE", "CMPL", "CMPGE", "CMPLE", "CMPG", "TSTZ", "TSTNZ",
1469                         "PCMPE", "PCMPNE", "PCMPL", "PCMPGE", "PCMPLE", "PCMPG", "??", "EXT" };
1470                 errmsg = "??";
1471                 if (*src < 0x30) errmsg = table[*src];
1472                 fprintf(stderr, "(%s)¥n", errmsg);
1473         }
1474         return -1;
1475 }
1476
1477 unsigned char *jitCompCallFunc(unsigned char *dst, void *func)
1478 {
1479         struct JitCompWork w;
1480         w.dst = dst;
1481         jitCompA000_storeRegCacheAll(&w);
1482         jitCompA000_storePRegCacheAll(&w);
1483         jitCompPutByte1(w.dst, 0x60);   /* PUSHAD(); */
1484         jitCompPutByte1(w.dst, 0x50);   /* PUSH(EAX); */        /* for 16byte-align(win32では不要なのだけど、MacOSには必要らしい) */
1485         jitCompPutByte1(w.dst, 0x55);   /* PUSH(EBP); */
1486         jitCompPutByte1(w.dst, 0xe8);   /* CALL(func); */
1487         int j = ((unsigned char *)func) - (w.dst + 4);
1488
1489         //この関数の中では結局w->dstしか参照していない
1490         jitCompPutImm32(&w, j);
1491
1492         jitCompPutByte1(w.dst, 0x58);   /* POP(EAX); */         /* (win32では不要なのだけど、MacOSには必要らしい) */
1493         jitCompPutByte1(w.dst, 0x58);   /* POP(EAX); */
1494         jitCompPutByte1(w.dst, 0x61);   /* POPAD(); */
1495         jitCompA000_loadRegCacheAll(&w);
1496         jitCompA000_loadPRegCacheAll(&w);
1497         jitCompA0001_movReg32EbpDisp(&w, 0 /* EAX */, 256 + 0x30 * 32 + 0); /* MOV(EAX, [EBP+?]); */
1498         jitCompPutByte2(w.dst, 0xff, 0xe0);     /* JMP(EAX); */
1499         return w.dst;
1500 }
1501
1502 unsigned char *jitCompInit(unsigned char *dst)
1503 {
1504         errfnc = dst;
1505         return jitCompCallFunc(dst, &errHndl);
1506 }
1507
1508 void func3c(char *ebp, int opt, int r1, int p1, int lenR, int lenP, int r0, int p0)
1509 {
1510         struct Regs *r = (struct Regs *) (ebp - jitCompA0001_EBP128);
1511         int i, *pi;
1512         struct Ptr *pp;
1513         if (r->junkStack + 2048 > r->junkStack1) (*(r->errHndl))(r);
1514         pi = (void *)r->junkStack; r->junkStack += r1 * 4;
1515         for (i = 0; i < r1; i++)
1516                 pi[i] = r->ireg[i];
1517         pp = (void *)r->junkStack; r->junkStack += p1 * 32;
1518         for (i = 0; i < p1; i++)
1519                 pp[i] = r->preg[i];
1520         pp = (void *)r->junkStack; r->junkStack += 32;
1521         *pp = r->preg[0x30];
1522         pi = (void *)r->junkStack; r->junkStack += 4;
1523         *pi = opt << 16 | r1 << 8 | p1;
1524         for (i = 0; i < lenR; i++)
1525                 r->ireg[r0 + i] = r->ireg[0x30 + i];
1526         for (i = 0; i < lenP; i++)
1527                 r->preg[p0 + i] = r->preg[0x31 + i];
1528         return;
1529 }
1530
1531 void func3d(char *ebp, int opt, int r1, int p1, int lenR, int lenP, int r0, int p0)
1532 {
1533         struct Regs *r = (struct Regs *) (ebp - jitCompA0001_EBP128);
1534         int i;
1535         r->junkStack -= 4;
1536         r->junkStack -= 32; struct Ptr *pp = (void *)r->junkStack;
1537         r->preg[0x30] = *pp;
1538         r->junkStack -= p1 * 32; pp = (void *)r->junkStack;
1539         for (i = 0; i < p1; i++)
1540                 r->preg[i] = pp[i];
1541         r->junkStack -= r1 * 4; int *pi = (void *)r->junkStack;
1542         for (i = 0; i < r1; i++)
1543                 r->ireg[i] = pi[i];
1544         return;
1545 }
1546
1547 void funcf4(char *ebp, int pxx, int typ, int len)
1548 {
1549         struct Regs *r = (struct Regs *) (ebp - jitCompA0001_EBP128);
1550         int width = jitCompA000_dataWidth(jitCompA000_convTyp(r->ireg[typ])) >> 3;
1551         if (width < 0 || r->ireg[len] < 0)
1552                 (*(r->errHndl))(r);
1553         void *p = r->junkStack;
1554         if (r->junkStack + width * r->ireg[len] + 256 > r->junkStack1) (*(r->errHndl))(r);
1555         r->junkStack += width * r->ireg[len];
1556         r->preg[pxx].p = p;
1557         r->preg[pxx].typ = r->ireg[typ];
1558         r->preg[pxx].p0 = p;
1559         r->preg[pxx].p1 = (void *)r->junkStack;
1560         int *pi = (int *)r->junkStack;
1561         *pi = width * r->ireg[len];
1562         r->junkStack += sizeof (int);
1563         if (r->ireg[typ] == 1) {
1564                 int i, i1 = (width * r->ireg[len]) >> 2;
1565                 pi = p;
1566                 for (i = 0; i < i1; i++)
1567                         pi[i] = 0;
1568         }
1569         return;
1570 }
1571
1572 void funcf5(char *ebp, int pxx, int typ, int len)
1573 {
1574         struct Regs *r = (struct Regs *) (ebp - jitCompA0001_EBP128);
1575         r->junkStack -= sizeof (int);
1576         int *pi = (int *)r->junkStack;
1577         r->junkStack -= *pi;
1578 #if 0
1579         int width = jitCompA000_dataWidth(r->ireg[typ]);
1580         void *p = r->junkStack;
1581         r->junkStack -= width * r->ireg[len];
1582 #endif
1583         return;
1584 }
1585
1586 void funcf6(char *ebp, int pxx, int typ, int len)
1587 {
1588         struct Regs *r = (struct Regs *) (ebp - jitCompA0001_EBP128);
1589         int width = jitCompA000_dataWidth(jitCompA000_convTyp(r->ireg[typ])) >> 3;
1590         if (width < 0 || r->ireg[len] < 0)
1591                 (*(r->errHndl))(r);
1592         void *p = malloc(width * r->ireg[len]);
1593         r->preg[pxx].p = p;
1594         r->preg[pxx].typ = r->ireg[typ];
1595         r->preg[pxx].p0 = p;
1596         r->preg[pxx].p1 = (unsigned char *)p + width * r->ireg[len];
1597         if (r->ireg[typ] == 1) {
1598                 int i, i1 = (width * r->ireg[len]) >> 2, *pi;
1599                 pi = p;
1600                 for (i = 0; i < i1; i++)
1601                         pi[i] = 0;
1602                 for (i = 1; i < i1; i += 8)
1603                         pi[i] |= -1;
1604         }
1605         return;
1606 }
1607
1608 void funcf7(char *ebp, int pxx, int typ, int len)
1609 {
1610         struct Regs *r = (struct Regs *) (ebp - jitCompA0001_EBP128);
1611         free(r->preg[pxx].p);
1612         return;
1613 }
1614
1615 void errHndl(struct Regs *r)
1616 {
1617         r = (struct Regs *) (((char *)r) - jitCompA0001_EBP128);
1618         (*(r->errHndl))(r);
1619         // ここに帰ってきてはいけない.
1620 }
1621
1622 /*
1623  * jitcの出力コードをひとまとめにする関数を作成しその中身をjitCompile()で生成
1624  *
1625  * qq : 出力バイナリの書き込み位置のアドレスへの参照(書き込み位置を呼び出しに反映させるため参照渡しにする)
1626  * q1 : 出力バイナリの書き込み位置のアドレスの最大値
1627  * p0 : (*.ose)バイナリの読み込み位置のアドレス(ヘッダ部除去済)
1628  * p1 : (*.ose)バイナリの読み込み位置の取りうる最大値
1629  *      (ただし、「確保したメモリ」の最大値なのでこれより手前にゴミデータが入っているかもしれない)
1630  * ret=1 : ヘッダのエラー
1631  * ret=2 : jitコンパイルエラー
1632  */
1633 int jitc0(unsigned char **qq, unsigned char *q1, const unsigned char *p0, const unsigned char *p1, int level, struct LabelTable *label)
1634 {
1635         unsigned char *q = *qq;
1636         if (p0[0] != 0x05 || p0[1] != SIGN1)
1637                 return 1;
1638
1639         *q++ = 0x55; /* PUSH(EBP); */
1640         *q++ = 0x8b; *q++ = 0x6c; *q++ = 0x24; *q++ = 0x08; /* MOV(EBP,[ESP+8]); */
1641
1642         int i;
1643         for (i = 0; i < JITC_MAXLABELS; i++)
1644                 label[i].opt = 0;
1645
1646         // 以下のjitCompile()呼び出しでは第二引数をq1-2にした方がよいのではないか?
1647         i = jitCompiler(q, q1, p0 + 2, p1, p0, label, JITC_MAXLABELS, level, di1_serial, 0);
1648         if (i != 0) return 2;
1649         i = jitCompiler(q, q1, p0 + 2, p1, p0, label, JITC_MAXLABELS, level, di1_serial, JITC_PHASE1 + 0);
1650         if (i < 0) return 2;
1651         q += i;
1652
1653         *q++ = 0x5d; /* POP(EBP); */
1654         *q++ = 0xc3; /* RET(); */
1655
1656         *qq = q;
1657         return 0;
1658 }
1659
1660 #if (USE_DEBUGGER != 0)
1661
1662 int dbgrGetRegNum(const unsigned char *p)
1663 {
1664         int i, j, r = -1;
1665         if (p[2] <= ' ') {
1666                 i = p[0] - '0';
1667                 j = p[1] - '0';
1668                 if (i > 9) i -= 'A' - '0' - 10;
1669                 if (j > 9) j -= 'A' - '0' - 10;
1670                 if (0 <= i && i <= 15 && 0 <= j && j <= 15)
1671                         r = i << 4 | j;
1672         }
1673         return r;
1674 }
1675
1676 void dbgrMain(struct Regs *r)
1677 {
1678         if (r->dbgr == 0) return;
1679         for (;;) {
1680                 unsigned char cmd[64], *p;
1681                 int i, j, k;
1682                 printf("¥ndbgr>");
1683                 p = fgets(cmd, 64, stdin);
1684                 if (p == NULL) break;
1685                 if (cmd[0] == '¥0') continue;
1686                 if (cmd[0] == 'q' && cmd[1] <= ' ') break;
1687                 if (cmd[0] == 'p' && cmd[1] <= ' ' && cmd[1] != '¥0') {
1688                         p = &cmd[2];
1689                         while (*p <= ' ' && *p != '¥0') p++;
1690                         if (*p == 'R') {
1691                                 i = dbgrGetRegNum(p + 1);
1692                                 if (0 <= i && i <= 0x3f) {
1693                                         printf("R%02X = 0x%08X = %d¥n", i, r->ireg[i], r->ireg[i]);
1694                                 }
1695                                 else
1696                                         puts("register name error");
1697                                 continue;
1698                         }
1699                         if (*p == 'P') {
1700                                 i = dbgrGetRegNum(p + 1);
1701                                 if (0 <= i && i <= 0x3f) {
1702                                         p = "invalid";
1703                                         if (0 <= r->preg[i].typ && r->preg[i].typ <= 0x15) {
1704                                                 static unsigned char *typName[] = {
1705                                                         "T_CODE", "T_VPTR", "T_SINT8", "T_UINT8",
1706                                                         "T_SINT16", "T_UINT16", "T_SINT32", "T_UINT32",
1707                                                         "T_SINT4", "T_UINT4", "T_SINT2", "T_UINT2",
1708                                                         "T_SINT1", "T_UINT1", "T_SINT12", "T_UINT12",
1709                                                         "T_SINT20", "T_UINT20", "T_SINT24", "T_UINT24",
1710                                                         "T_SINT28", "T_UINT28"
1711                                                 };
1712                                                 p = typName[r->preg[i].typ];
1713                                         }
1714                                         printf("P%02X:¥n  type = %s(%04X),  (origin-ptr) = 0x%08X¥n", i, p, r->preg[i].typ, r->preg[i].p0);
1715                                         if (r->preg[i].p != NULL && r->preg[i].p0 != NULL) {
1716                                                 j = jitCompA000_dataWidth(jitCompA000_convTyp(r->preg[i].typ)) >> 3;
1717                                                 if (j <= 0) j = 1;
1718                                                 k = (r->preg[i].p1 - r->preg[i].p0) / j;
1719                                                 printf("  size = 0x%08X = %d¥n", k, k);
1720                                                 k = (r->preg[i].p - r->preg[i].p0) / j;
1721                                                 printf("  pos  = 0x%08X = %d¥n", k, k);
1722                                         }
1723                                         else {
1724                                                 puts("  null pointer");
1725                                         }
1726                                 }
1727                                 else
1728                                         puts("register name error");
1729                                 continue;
1730                         }
1731                 }
1732                 puts("command error");
1733         }
1734         return;
1735 }
1736
1737 #endif
1738
1739
1740 #endif
1741
1742
1743