OSDN Git Service

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