OSDN Git Service

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