Revisión | e60dffbbb2da2872fc46a56d18c83ad56baadbce (tree) |
---|---|
Tiempo | 2014-05-22 20:15:13 |
Autor | hikarupsp <hikarupsp@user...> |
Commiter | hikarupsp |
osecpu106a
@@ -0,0 +1,8 @@ | ||
1 | +CC = cc | |
2 | +SRCS = extend.c float.c integer.c osecpu-vm.c pointer.c test.c | |
3 | +BINNAME = osecpu-test.bin | |
4 | + | |
5 | +$(BINNAME): $(SRCS) | |
6 | + $(CC) -o $@ $(SRCS) | |
7 | + | |
8 | + |
@@ -28,3 +28,8 @@ | ||
28 | 28 | 倍精度である64bitをサポートするかは処理系依存。 |
29 | 29 | floatのサポートそのものがない場合も許す。 |
30 | 30 | |
31 | +2014.05.22木: | |
32 | + data文まではとりあえずできた。 | |
33 | + data命令でも浮動小数点を使えるようになりたいからそれは後日がんばる。 | |
34 | + 次はLMEMだなー。その次がPADD。 | |
35 | + |
@@ -6,8 +6,20 @@ typedef int Int32; // 32bit | ||
6 | 6 | |
7 | 7 | #define DEFINES_MAXLABELS 4096 |
8 | 8 | |
9 | +typedef struct _PtrCtrl { | |
10 | + int liveSign; | |
11 | + int size, typ; | |
12 | + unsigned char *p0; | |
13 | +} PtrCtrl; | |
14 | + | |
9 | 15 | typedef struct _PReg { |
10 | - void *p; | |
16 | + unsigned char *p; | |
17 | + int typ; | |
18 | + unsigned char *p0, *p1; | |
19 | + int liveSign; | |
20 | + struct PtrCtrl *pls; | |
21 | + int flags; /* read/writeなど */ | |
22 | + unsigned char *bit; | |
11 | 23 | } PReg; |
12 | 24 | |
13 | 25 | typedef struct _Label { |
@@ -1,6 +1,6 @@ | ||
1 | 1 | #include "osecpu-vm.h" |
2 | 2 | |
3 | -// ポインタ関連命令: 01, 03 | |
3 | +// ポインタ関連命令: 01, 03, 2E | |
4 | 4 | |
5 | 5 | void jitcInitPointer(OsecpuJitc *jitc) |
6 | 6 | { |
@@ -15,16 +15,21 @@ void jitcStep_checkPxx(int *pRC, int pxx) | ||
15 | 15 | } |
16 | 16 | |
17 | 17 | void getTypSize(int typ, int *typSize0, int *typSize1, int *typSign) |
18 | +// typSize0: 入力バイナリ内でのビット数. | |
19 | +// typSize1: 出力バイナリ内でのバイト数. | |
18 | 20 | { |
19 | 21 | *typSize0 = *typSize1 = -1; |
20 | 22 | if (2 <= typ && typ <= 21) { |
21 | 23 | static unsigned char table[10] = { 8, 16, 32, 4, 2, 1, 12, 20, 24, 28 }; |
24 | + int bytes; | |
22 | 25 | if ((typ & 1) == 0) |
23 | 26 | *typSign = -1; // typが偶数なら符号あり. |
24 | 27 | else |
25 | 28 | *typSign = 0; // typが奇数なら符号なし. |
26 | 29 | *typSize0 = table[(typ - 2) / 2]; |
27 | - *typSize1 = (*typSize0 + 7) / 8; | |
30 | + bytes = (*typSize0 + 7) / 8; | |
31 | + if (bytes == 3) bytes = 4; | |
32 | + *typSize1 = bytes; | |
28 | 33 | } |
29 | 34 | return; |
30 | 35 | } |
@@ -126,6 +131,9 @@ int jitcStepPointer(OsecpuJitc *jitc) | ||
126 | 131 | psi[i] = bitReaderGetNbitSigned(&br, typSize0); |
127 | 132 | } |
128 | 133 | jitc->dst += (typSize1 * len + 3) / 4; |
134 | + unsigned char *puc = (unsigned char *) jitc->dst; | |
135 | + for (i = 0; i < len; i++) | |
136 | + puc[i] = 0xff; // bits=255. | |
129 | 137 | jitc->dst += (len + 3) / 4; |
130 | 138 | } |
131 | 139 | for (j = 0; j < JITC_DSTLOG_SIZE; j++) { |
@@ -136,6 +144,8 @@ int jitcStepPointer(OsecpuJitc *jitc) | ||
136 | 144 | jitc->defines->label[i].typ = typ; |
137 | 145 | jitc->defines->label[i].dst = ip; |
138 | 146 | } |
147 | + goto fin; | |
148 | + | |
139 | 149 | } |
140 | 150 | goto fin1; |
141 | 151 | fin: |
@@ -163,14 +173,30 @@ void execStepPointer(OsecpuVm *vm) | ||
163 | 173 | i = ip[1]; p = ip[2]; |
164 | 174 | if (p == 0x3f) |
165 | 175 | ip = (const Int32 *) vm->defines->label[i].dst; |
166 | - else | |
176 | + else { | |
177 | + typ = vm->defines->label[i].typ; | |
178 | + vm->p[p].p = (unsigned char *) vm->defines->label[i].dst; | |
179 | + vm->p[p].typ = typ; | |
180 | + vm->p[p].p0 = vm->p[p].p; | |
181 | + if (typ >= 2) { | |
182 | + len = vm->defines->label[i].dst[2]; // 2e(data)のlenフィールド値. | |
183 | + getTypSize(typ, NULL, &typSize1, NULL); | |
184 | + vm->p[p].p1 = vm->p[p].p + typSize1 * len; | |
185 | + vm->p[p].bit = vm->p[p].p + ((typSize1 * len + 3) / 4) * 4; | |
186 | + } | |
187 | + if (typ == -1) { // コードラベル. | |
188 | + vm->p[p].p1 = vm->p[p].p + 1; | |
189 | + } | |
190 | + if (typ == 1) { // VPtr. | |
191 | + } | |
167 | 192 | ip += 3; |
193 | + } | |
168 | 194 | goto fin; |
169 | 195 | } |
170 | 196 | if (opecode == 0x2e) { // data |
171 | 197 | typ = ip[1]; len = ip[2]; |
172 | 198 | getTypSize(typ, &typSize0, &typSize1, &typSign); |
173 | - ip += 3 + (typSize1 * len + 3) / 4; | |
199 | + ip += 3 + (typSize1 * len + 3) / 4 + (len + 3) / 4; | |
174 | 200 | goto fin; |
175 | 201 | } |
176 | 202 | fin: |
@@ -9,6 +9,7 @@ int main(int argc, const char **argv) | ||
9 | 9 | OsecpuVm vm; |
10 | 10 | unsigned char hh4src[BUFFER_SIZE], *hh4src1; |
11 | 11 | Int32 i32buf[BUFFER_SIZE], j32buf[BUFFER_SIZE]; |
12 | + int rc; | |
12 | 13 | jitc.defines = &defs; |
13 | 14 | vm.defines = &defs; |
14 | 15 |
@@ -31,6 +32,7 @@ int main(int argc, const char **argv) | ||
31 | 32 | "4 bf" // CND(R3F); |
32 | 33 | "3 0 bf" // PLIMM(P3F, 0); |
33 | 34 | |
35 | +#if 0 | |
34 | 36 | // F03 = 4 * (1 - 1/3 + 1/5 - 1/7 + ...) |
35 | 37 | // テストなので速度とかを気にせず、極力Fxxを使ってみる. |
36 | 38 | "c40 0 0 3 c40" // FLIMM64(F03, 0); |
@@ -47,10 +49,21 @@ int main(int argc, const char **argv) | ||
47 | 49 | "c49 5 bf c40 bf a0" // FCMPNE32_64(R3F, F05, F3F); |
48 | 50 | "4 bf" // CND(R3F); |
49 | 51 | "3 1 bf" // PLIMM(P3F, 1); |
52 | +#endif | |
50 | 53 | |
54 | +#if 0 | |
51 | 55 | "2 0 3 0" // LIMM0(R03, 0); |
52 | - "90 3 3 3 a0", // CP32(R03, R03); // ここでエラーコード1になる. | |
53 | - NULL, hh4src, &hh4src[BUFFER_SIZE] | |
56 | + "90 3 3 3 a0" // CP32(R03, R03); // ここでエラーコード1になる. | |
57 | +#endif | |
58 | + | |
59 | +#if 1 | |
60 | + "1 2 1" // LB1(2); | |
61 | + "ae 2 84 01 23 45 67" // data(UINT8, 4, 0x01, 0x23, 0x45, 0x67); | |
62 | + "3 2 1" // PLIMM(P01, 2); | |
63 | + "2 1 3 a0" // LIMM32(R03, 1); | |
64 | +#endif | |
65 | + | |
66 | + , NULL, hh4src, &hh4src[BUFFER_SIZE] | |
54 | 67 | ); |
55 | 68 | |
56 | 69 | if (hh4src1 == NULL) { |
@@ -63,7 +76,9 @@ int main(int argc, const char **argv) | ||
63 | 76 | hh4ReaderInit(&jitc.hh4r, hh4src, 0, hh4src1, 0); |
64 | 77 | jitc.dst = j32buf; |
65 | 78 | jitc.dst1 = &j32buf[BUFFER_SIZE]; |
66 | - printf("jitcAll()=%d\n", jitcAll(&jitc)); // 0なら成功. | |
79 | + rc = jitcAll(&jitc); | |
80 | + printf("jitcAll()=%d\n", rc); // 0なら成功. | |
81 | + if (rc != 0) return 1; | |
67 | 82 | *jitc.dst = -1; // デバッグ用の特殊opecode. |
68 | 83 | vm.ip = j32buf; |
69 | 84 | vm.ip1 = jitc.dst; |
@@ -72,11 +87,12 @@ int main(int argc, const char **argv) | ||
72 | 87 | // execAll()を使って、j32buf[]内の中間コードを実行する. |
73 | 88 | printf("execAll()=%d\n", execAll(&vm)); // 65535なら成功(EXEC_ABORT_OPECODE_M1). |
74 | 89 | printf("R00=%d\n", vm.r[0x00]); |
90 | + printf("R01=%d\n", vm.r[0x01]); | |
91 | + printf("R02=%d\n", vm.r[0x02]); | |
92 | + printf("R03=%d\n", vm.r[0x03]); | |
75 | 93 | printf("F00=%f\n", vm.f[0x00]); |
76 | 94 | printf("F01=%.15f\n", vm.f[0x01]); |
77 | 95 | printf("F02=%.15f\n", vm.f[0x02]); |
78 | - printf("R01=%d\n", vm.r[0x01]); | |
79 | - printf("R02=%d\n", vm.r[0x02]); | |
80 | 96 | printf("F03=%f\n", vm.f[0x03]); |
81 | 97 | printf("F04=%f\n", vm.f[0x04]); |
82 | 98 |