OSDN Git Service

読みやすく
[heavyosecpu/HeavyOSECPU.git] / jitc.h
1 
2 #ifndef HeavyOSECPU_jitc_h
3 #define HeavyOSECPU_jitc_h
4
5 // Error flags
6 #define JITC_ERR_MASK                   255
7 #define JITC_ERR_PHASE0ONLY             256
8 #define JITC_ERR_REGNUM                 (1 | JITC_ERR_PHASE0ONLY)
9 #define JITC_ERR_DST1                   (2 | JITC_ERR_PHASE0ONLY)
10 #define JITC_ERR_OPECODE                (3 | JITC_ERR_PHASE0ONLY)
11 #define JITC_ERR_LABELNUM               (4 | JITC_ERR_PHASE0ONLY)
12 #define JITC_ERR_LABELREDEF             (5 | JITC_ERR_PHASE0ONLY)
13 #define JITC_ERR_PREFIX                 (6 | JITC_ERR_PHASE0ONLY)
14 #define JITC_ERR_LABELNODEF             7
15 #define JITC_ERR_LABELTYP               8
16 #define JITC_ERR_IDIOM                  9
17 #define JITC_ERR_PREGNUM                (10 | JITC_ERR_PHASE0ONLY)
18 #define JITC_ERR_SRC1                   (11 | JITC_ERR_PHASE0ONLY)
19 #define JITC_ERR_BADTYPE                (12 | JITC_ERR_PHASE0ONLY)
20 #define JITC_ERR_PREFIXFAR              (13 | JITC_ERR_PHASE0ONLY)
21 #define JITC_ERR_INTERNAL               99
22
23 // Byte operations
24 #define jitCompPutByte1(p, c0)                          *p++ = c0
25 #define jitCompPutByte2(p, c0, c1)                      *p++ = c0; *p++ = c1
26 #define jitCompPutByte3(p, c0, c1, c2)          *p++ = c0; *p++ = c1; *p++ = c2
27 #define jitCompPutByte4(p, c0, c1, c2, c3)      *p++ = c0; *p++ = c1; *p++ = c2; *p++ = c3
28
29 //
30 // functions (jitc internal)
31 //
32
33 // @jitc.c
34 void errorHandler(HOSECPU_RuntimeEnvironment *r);
35 int jitCompCmdLen(const unsigned char *src);
36
37 // @jitcx86.c
38 #if (JITC_ARCNUM == 0x0001)
39 //
40 // for x86-32bit
41 //
42
43 // 他のCPUへ移植する人へ:
44 // 以下の定数は最適化のためのものなので、すべて0として簡単に移植しても問題ありません
45 #define jitCompA0001_USE_R3F_CMPJMP             1*1
46 #define jitCompA0001_USE_R3F_IMM32              1*1
47 #define jitCompA0001_USE_R3F_IMM8               1*1
48 #define jitCompA0001_USE_R3F_INCDEC             1*1
49 #define jitCompA0001_OPTIMIZE_JMP               1*1
50 #define jitCompA0001_OPTIMIZE_MOV               1*1     /* 1にすると速度低下する? */
51 #define jitCompA0001_OPTIMIZE_CMP               1*1
52 #define jitCompA0001_OPTIMIZE_ALIGN             4*1     /* 0-8を想定 */
53 #define jitCompA0001_EBP128                             128*1
54
55 struct JitCompWork {
56         unsigned char *dst, *dst0;
57         int err, maxLabels;
58 #if (jitCompA0001_USE_R3F_IMM32 != 0)
59         int r3f;
60 #endif
61         char prefix;    //CND命令の値を記録(初期値=0)
62 };
63
64 void jitCompPutImm32(struct JitCompWork *w, int i);
65 int jitCompGetImm32(const unsigned char *src);
66 int jitCompGetLabelNum(struct JitCompWork *w, const unsigned char *src);
67 void jitCompA0001_85DispN(struct JitCompWork *w, int disp, int n);
68 void jitCompA0001_movEbpDispReg32(struct JitCompWork *w, int disp, int reg32);
69 void jitCompA0001_movReg32EbpDisp(struct JitCompWork *w, int reg32, int disp);
70 void jitCompA0001_movEaxRxx(struct JitCompWork *w, int rxx);
71 void jitCompA0001_movRxxEax(struct JitCompWork *w, int rxx);
72 void jitCompA0001_fixPrefix(struct JitCompWork *w);
73 void jitCompA0001_checkCompPtr(struct JitCompWork *w, int p0, int p1);
74 void jitCompA000_loadRegCacheAll(struct JitCompWork *w);
75 void jitCompA000_storeRegCacheAll(struct JitCompWork *w);
76 void jitCompA000_loadRegCacheEcx(struct JitCompWork *w);
77 void jitCompA000_storeRegCacheEcx(struct JitCompWork *w);
78 void jitCompA000_loadRegCacheEdx(struct JitCompWork *w);
79 void jitCompA000_storeRegCacheEdx(struct JitCompWork *w);
80 int jitCompA000_selectRegCache(int rxx, int reg);
81 void jitCompA000_loadPRegCacheAll(struct JitCompWork *w);
82 void jitCompA000_storePRegCacheAll(struct JitCompWork *w);
83 int jitCompA000_selectPRegCache(int pxx, int reg);
84 int jitCompA000_convTyp(int t);
85 int jitCompA000_dataWidth(int t);
86 void jitCompA0001_checkType0(struct JitCompWork *w, int pxx, int typ, int ac);
87 void jitCompA0001_checkType(struct JitCompWork *w, int pxx, int typ, int ac);
88 void jitCompA0001_checkLimit(struct JitCompWork *w, int reg, int pxx);
89 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);
90 unsigned char *jitCompCallFunc(unsigned char *dst, void *func);
91 unsigned char *jitCompInit(unsigned char *dst);
92 void func3c(char *ebp, int opt, int r1, int p1, int lenR, int lenP, int r0, int p0);
93 void func3d(char *ebp, int opt, int r1, int p1, int lenR, int lenP, int r0, int p0);
94 void funcf4(char *ebp, int pxx, int typ, int len);
95 void funcf5(char *ebp, int pxx, int typ, int len);
96 void funcf6(char *ebp, int pxx, int typ, int len);
97 void funcf7(char *ebp, int pxx, int typ, int len);
98 void errHndl(HOSECPU_RuntimeEnvironment *r);
99 int jitc0(unsigned char **qq, unsigned char *q1, const unsigned char *p0, const unsigned char *p1, int level, HOSECPU_LabelListTag *label);
100 #if (USE_DEBUGGER != 0)
101 int dbgrGetRegNum(const char *p);
102 void dbgrMain(HOSECPU_RuntimeEnvironment *r);
103 #endif
104
105
106
107
108
109
110
111
112
113
114
115
116 #endif
117
118 #endif