OSDN Git Service

jitCompPutImm32等をdefine化
[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 #define IA32_REG0_EAX                   0\r
43 #define IA32_REG1_ECX                   1\r
44 #define IA32_REG2_EDX                   2\r
45 #define IA32_REG3_EBX                   3\r
46 #define IA32_REG4_ESP                   4\r
47 #define IA32_REG5_EBP                   5\r
48 #define IA32_REG6_ESI                   6\r
49 #define IA32_REG7_EDI                   7\r
50 //\r
51 #define envOffset_DBGINFO0              (2304 + 0)\r
52 #define envOffset_DBGINFO1              (2304 + 4)\r
53 //\r
54 #define jitCompPutImm32(p, i)                                   jitCompPutByte4(p, ((i) & 0xff), (((i) >> 8) & 0xff), (((i) >> 16) & 0xff), (((i) >> 24) & 0xff))\r
55 #define jitCompPutOp_PUSHAD(p)                                  jitCompPutByte1(p, 0x60);\r
56 #define jitCompPutOp_POPAD(p)                                   jitCompPutByte1(p, 0x61);\r
57 #define jitCompPutOp_PUSH_GReg(p, reg)                  jitCompPutByte1(p, 0x50 | (reg));\r
58 #define jitCompPutOp_POP_GReg(p, reg)                   jitCompPutByte1(p, 0x58 | (reg));\r
59 #define jitCompPutOp_CALL_Relative(p, diff)             jitCompPutByte1(w.dst, 0xe8); jitCompPutImm32(&w, j);\r
60 \r
61 \r
62 // Optimization settings\r
63 // 他のCPUへ移植する人へ:\r
64 // 以下の定数は最適化のためのものなので、すべて0として簡単に移植しても問題ありません\r
65 #define jitCompA0001_USE_R3F_CMPJMP             1*1\r
66 #define jitCompA0001_USE_R3F_IMM32              1*1\r
67 #define jitCompA0001_USE_R3F_IMM8               1*1\r
68 #define jitCompA0001_USE_R3F_INCDEC             1*1\r
69 #define jitCompA0001_OPTIMIZE_JMP               1*1\r
70 #define jitCompA0001_OPTIMIZE_MOV               1*1     /* 1にすると速度低下する? */\r
71 #define jitCompA0001_OPTIMIZE_CMP               1*1\r
72 #define jitCompA0001_OPTIMIZE_ALIGN             4*1     /* 0-8を想定 */\r
73 #define jitCompA0001_EBP128                             128*1\r
74 \r
75 struct JitCompWork {\r
76         unsigned char *dst, *dst0;\r
77         int err, maxLabels;\r
78 #if (jitCompA0001_USE_R3F_IMM32 != 0)\r
79         int r3f;\r
80 #endif\r
81         char prefix;    //CND命令の値を記録(初期値=0)\r
82 };\r
83 \r
84 int jitCompGetImm32(const unsigned char *src);\r
85 int jitCompGetLabelNum(struct JitCompWork *w, const unsigned char *src);\r
86 void jitCompA0001_85DispN(struct JitCompWork *w, int disp, int n);\r
87 void jitCompA0001_movEbpDispReg32(struct JitCompWork *w, int disp, int reg32);\r
88 void jitCompA0001_movReg32EbpDisp(struct JitCompWork *w, int reg32, int disp);\r
89 void jitCompA0001_movEaxRxx(struct JitCompWork *w, int rxx);\r
90 void jitCompA0001_movRxxEax(struct JitCompWork *w, int rxx);\r
91 void jitCompA0001_fixPrefix(struct JitCompWork *w);\r
92 void jitCompA0001_checkCompPtr(struct JitCompWork *w, int p0, int p1);\r
93 void jitCompA000_loadRegCacheAll(struct JitCompWork *w);\r
94 void jitCompA000_storeRegCacheAll(struct JitCompWork *w);\r
95 void jitCompA000_loadRegCacheEcx(struct JitCompWork *w);\r
96 void jitCompA000_storeRegCacheEcx(struct JitCompWork *w);\r
97 void jitCompA000_loadRegCacheEdx(struct JitCompWork *w);\r
98 void jitCompA000_storeRegCacheEdx(struct JitCompWork *w);\r
99 int jitCompA000_selectRegCache(int rxx, int reg);\r
100 void jitCompA000_loadPRegCacheAll(struct JitCompWork *w);\r
101 void jitCompA000_storePRegCacheAll(struct JitCompWork *w);\r
102 int jitCompA000_selectPRegCache(int pxx, int reg);\r
103 int jitCompA000_convTyp(int t);\r
104 int jitCompA000_dataWidth(int t);\r
105 void jitCompA0001_checkType0(struct JitCompWork *w, int pxx, int typ, int ac);\r
106 void jitCompA0001_checkType(struct JitCompWork *w, int pxx, int typ, int ac);\r
107 void jitCompA0001_checkLimit(struct JitCompWork *w, int reg, int pxx);\r
108 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
109 unsigned char *jitCompCallFunc(unsigned char *dst, void *func);\r
110 unsigned char *jitCompInit(unsigned char *dst);\r
111 void func3c(char *ebp, int opt, int r1, int p1, int lenR, int lenP, int r0, int p0);\r
112 void func3d(char *ebp, int opt, int r1, int p1, int lenR, int lenP, int r0, int p0);\r
113 void funcf4(char *ebp, int pxx, int typ, int len);\r
114 void funcf5(char *ebp, int pxx, int typ, int len);\r
115 void funcf6(char *ebp, int pxx, int typ, int len);\r
116 void funcf7(char *ebp, int pxx, int typ, int len);\r
117 void errHndl(HOSECPU_RuntimeEnvironment *r);\r
118 int jitc0(unsigned char **qq, unsigned char *q1, const unsigned char *p0, const unsigned char *p1, int level, HOSECPU_LabelListTag *label);\r
119 #if (USE_DEBUGGER != 0)\r
120 int dbgrGetRegNum(const char *p);\r
121 void dbgrMain(HOSECPU_RuntimeEnvironment *r);\r
122 #endif\r
123 \r
124 \r
125 \r
126 \r
127 \r
128 \r
129 \r
130 \r
131 \r
132 \r
133 \r
134 \r
135 #endif\r
136 \r
137 #endif\r