• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revisiónfe519622fb41bc1d1d04ca609f26d416bc6f6bde (tree)
Tiempo2014-07-07 23:06:45
Autorhikarupsp <hikarupsp@user...>
Commiterhikarupsp

Log Message

コードの整理。
wikiドキュメント生成機能は削除された。

Cambiar Resumen

Diferencia incremental

--- a/chncpu.xcodeproj/project.pbxproj
+++ b/chncpu.xcodeproj/project.pbxproj
@@ -14,6 +14,7 @@
1414 1786B0941956C18800FD4F7B /* label.c in Sources */ = {isa = PBXBuildFile; fileRef = 1786B0931956C18800FD4F7B /* label.c */; };
1515 17DD55BB1967992200DA7D82 /* args.c in Sources */ = {isa = PBXBuildFile; fileRef = 17DD55BA1967992200DA7D82 /* args.c */; };
1616 17E5092A1967F7B00091A22A /* src.txt in CopyFiles */ = {isa = PBXBuildFile; fileRef = 17E509291967F7770091A22A /* src.txt */; };
17+ 17E50932196AD91D0091A22A /* debug.c in Sources */ = {isa = PBXBuildFile; fileRef = 17E50931196AD91D0091A22A /* debug.c */; };
1718 17F95C01194C8DA70064E1B6 /* bios.c in Sources */ = {isa = PBXBuildFile; fileRef = 17F95C00194C8DA70064E1B6 /* bios.c */; };
1819 /* End PBXBuildFile section */
1920
@@ -42,6 +43,8 @@
4243 1786B0931956C18800FD4F7B /* label.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = label.c; sourceTree = "<group>"; };
4344 17DD55BA1967992200DA7D82 /* args.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = args.c; sourceTree = "<group>"; };
4445 17E509291967F7770091A22A /* src.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = src.txt; sourceTree = "<group>"; };
46+ 17E50930196AD6BF0091A22A /* opcache.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = opcache.h; sourceTree = "<group>"; };
47+ 17E50931196AD91D0091A22A /* debug.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = debug.c; path = ../debug.c; sourceTree = "<group>"; };
4548 17F95C00194C8DA70064E1B6 /* bios.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bios.c; sourceTree = "<group>"; };
4649 /* End PBXFileReference section */
4750
@@ -76,15 +79,17 @@
7679 17478CF2193E2A4900293791 /* chncpu */ = {
7780 isa = PBXGroup;
7881 children = (
82+ 17478CFC193E2A7800293791 /* chncpu.h */,
7983 17478CF3193E2A4900293791 /* chncpu.c */,
84+ 17E50931196AD91D0091A22A /* debug.c */,
8085 17DD55BA1967992200DA7D82 /* args.c */,
81- 17478CFC193E2A7800293791 /* chncpu.h */,
8286 17478D00193F3D0000293791 /* ch4.c */,
8387 17478D02193F586100293791 /* ch4.h */,
84- 17478CFD193E2ADA00293791 /* test.hex */,
88+ 17E50930196AD6BF0091A22A /* opcache.h */,
8589 17478D031940B66700293791 /* opcode.c */,
8690 17F95C00194C8DA70064E1B6 /* bios.c */,
8791 1786B0931956C18800FD4F7B /* label.c */,
92+ 17478CFD193E2ADA00293791 /* test.hex */,
8893 17E509291967F7770091A22A /* src.txt */,
8994 );
9095 path = chncpu;
@@ -142,6 +147,7 @@
142147 buildActionMask = 2147483647;
143148 files = (
144149 1786B0941956C18800FD4F7B /* label.c in Sources */,
150+ 17E50932196AD91D0091A22A /* debug.c in Sources */,
145151 17F95C01194C8DA70064E1B6 /* bios.c in Sources */,
146152 17DD55BB1967992200DA7D82 /* args.c in Sources */,
147153 17478D041940B66700293791 /* opcode.c in Sources */,
--- a/chncpu/args.c
+++ b/chncpu/args.c
@@ -31,7 +31,7 @@ CHNCPU_VMArgs *bindVMArgs(int argc, const char *argv[])
3131 s = CHNCPU_VMArgs_GetNextAsString(argc, argv, &nextIndex);
3232 for(;*s != '\0'; s++){
3333 if(*s == 'i'){
34- args->VMFlags |= CHNCPU_VM_FLAG_PRINT_OPLIST;
34+ args->VMFlags |= CHNCPU_VM_FLAG_PRINT_INFO;
3535 } else{
3636 printf("bindVMArgs: unknown flag %c.\n", *s);
3737 argc = 0;
--- a/chncpu/chncpu.c
+++ b/chncpu/chncpu.c
@@ -16,8 +16,8 @@ int main(int argc, const char *argv[])
1616 vmArgs = bindVMArgs(argc, argv);
1717 env = CHNCPU_CreateRuntimeEnvironment(CHNCPU_CreateOpTableSet(), CHNCPU_CreateBIOS());
1818
19- if(vmArgs->VMFlags & CHNCPU_VM_FLAG_PRINT_OPLIST){
20- printOpTableWikiDoc(env);
19+ if(vmArgs->VMFlags & CHNCPU_VM_FLAG_PRINT_INFO){
20+ printf("chncpu, inspired by OSECPU-VM. \nCompiled at %s, %s.\n", __TIME__, __DATE__);
2121 return 0;
2222 }
2323
@@ -34,18 +34,6 @@ int main(int argc, const char *argv[])
3434 return 0;
3535 }
3636
37-void printOpTableWikiDoc(CHNCPU_RuntimeEnvironment *env)
38-{
39- int i;
40-
41- puts(", mnemonic, OpCode(Hex), OpCode(ch4_uint Hex), +!, +2, +3, +4, +5, +6, +7, code, type");
42- for(i = 0; i <= CHNCPU_OPECODE_MAX; i++){
43- if(env->opSet->docFuncTable[i]){
44- env->opSet->docFuncTable[i](i, stdout);
45- }
46- }
47-}
48-
4937 int decodeHexString(char *src0, char *src1, unsigned char *dst0, unsigned char *dst1)
5038 {
5139 // ASCII文字のみ対応
@@ -380,61 +368,6 @@ int CHNCPU_Execute(CHNCPU_RuntimeEnvironment *env)
380368 return count;
381369 }
382370
383-void CHNCPU_DumpAppBin(CHNCPU_RuntimeEnvironment *env)
384-{
385- int i;
386-
387- for(i = 0; i < env->appbinsize; i++){
388- printf("%02X ", env->appbin0[i]);
389- if((i & 0xf) == 0xf){
390- putchar('\n');
391- }
392- }
393- if(((i - 1) & 0xf) != 0xf){
394- putchar('\n');
395- }
396-}
397-
398-void CHNCPU_DumpIReg(CHNCPU_RuntimeEnvironment *env)
399-{
400- int i, regs = 0;
401-
402- puts(">>> Integer registers");
403-
404- for(i = 0; i < CHNCPU_NUMBER_OF_IREG; i++){
405- if(env->iRegBits[i]){
406- printf("R%02X = %10d = 0x%08X(%2d) ", i, env->iReg[i], env->iReg[i], env->iRegBits[i]);
407- putchar('\n');
408- regs++;
409- }
410- }
411- if(((regs - 1) & 0xF) != 0xF){
412- putchar('\n');
413- }
414-}
415-
416-void CHNCPU_DumpPReg(CHNCPU_RuntimeEnvironment *env)
417-{
418- int i, regs = 0;
419-
420- puts(">>> Pointer registers");
421-
422- for(i = 0; i < CHNCPU_NUMBER_OF_PREG; i++){
423- if(env->pReg[i].type != CHNCPU_PType_Undefined){
424- if(env->pReg[i].mindex != CHNCPU_MemoryIndex_INVALID){
425- printf("P%02X: Type:%2X mem[%d][%d]", i, env->pReg[i].type, env->pReg[i].mindex, env->pReg[i].pindex);
426- } else{
427- printf("P%02X: Type:%2X %s[%d]", i, env->pReg[i].type, CHNCPU_Op_DATA_GetFilePath(env->pReg[i].opTag), env->pReg[i].pindex);
428- }
429- putchar('\n');
430- regs++;
431- }
432- }
433- if(((regs - 1) & 0xF) != 0xF){
434- putchar('\n');
435- }
436-}
437-
438371 int CHNCPU_CHK_IsAvailableBits(CHNCPU_RuntimeEnvironment *env, ch4_uint bits)
439372 {
440373 if(bits > 32){
--- a/chncpu/chncpu.h
+++ b/chncpu/chncpu.h
@@ -22,7 +22,7 @@
2222 #define DEBUG_PRINT_OP_EXECUTING 0
2323
2424 // VM flags
25-#define CHNCPU_VM_FLAG_PRINT_OPLIST 0x01
25+#define CHNCPU_VM_FLAG_PRINT_INFO 0x01
2626
2727
2828 // Settings
@@ -110,7 +110,6 @@ struct _CHNCPU_OP_TABLE_SET {
110110 int (*bindFuncTable[CHNCPU_OPECODE_MAX + 1])(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, unsigned int prefix);
111111 int (*execFuncTable[CHNCPU_OPECODE_MAX + 1])(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op);
112112 int (*printFuncTable[CHNCPU_OPECODE_MAX + 1])(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, FILE *file);
113- int (*docFuncTable[CHNCPU_OPECODE_MAX + 1])(int opCode, FILE *file);
114113 };
115114
116115 struct _CHNCPU_LABEL_TAG {
@@ -166,15 +165,11 @@ struct _CHNCPU_VM_ARGS {
166165
167166
168167 // @chncpu.c
169-void printOpTableWikiDoc(CHNCPU_RuntimeEnvironment *env);
170168 int decodeHexString(char *src0, char *src1, unsigned char *dst0, unsigned char *dst1);
171169 CHNCPU_RuntimeEnvironment *CHNCPU_CreateRuntimeEnvironment(CHNCPU_OpTableSet *opSet, CHNCPU_BIOS *bios);
172170 int CHNCPU_LoadBinaryFromHexStringFilePath(CHNCPU_RuntimeEnvironment *env, const char *path);
173171 int CHNCPU_PrepareBinaryForExecution(CHNCPU_RuntimeEnvironment *env);
174172 int CHNCPU_Execute(CHNCPU_RuntimeEnvironment *env);
175-void CHNCPU_DumpAppBin(CHNCPU_RuntimeEnvironment *env);
176-void CHNCPU_DumpIReg(CHNCPU_RuntimeEnvironment *env);
177-void CHNCPU_DumpPReg(CHNCPU_RuntimeEnvironment *env);
178173 int CHNCPU_CHK_IsAvailableBits(CHNCPU_RuntimeEnvironment *env, ch4_uint bits);
179174 int CHNCPU_AdjustValueForBit(CHNCPU_RuntimeEnvironment *env, int *value, ch4_uint bit, int prefix);
180175
@@ -192,53 +187,42 @@ int CHNCPU_VMArgs_GetNextAsSignedHexValue(int argc, const char *argv[], int *nex
192187 CHNCPU_OpTableSet *CHNCPU_CreateOpTableSet(void);
193188 int CHNCPU_Op_Init(CHNCPU_OpTableSet *env);
194189 //
195-int CHNCPU_Op_NOP_PrintWikiDoc(int opCode, FILE *file);
196-//
197190 int CHNCPU_Op_LB_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, unsigned int prefix);
198191 int CHNCPU_Op_LB_Execute(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op);
199192 int CHNCPU_Op_LB_PrintCode(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, FILE *file);
200-int CHNCPU_Op_LB_PrintWikiDoc(int opCode, FILE *file);
201193 //
202194 int CHNCPU_Op_LIMM_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, unsigned int prefix);
203195 int CHNCPU_Op_LIMM_Execute(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op);
204196 int CHNCPU_Op_LIMM_PrintCode(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, FILE *file);
205-int CHNCPU_Op_LIMM_PrintWikiDoc(int opCode, FILE *file);
206197 //
207198 int CHNCPU_Op_PLIMM_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, unsigned int prefix);
208199 int CHNCPU_Op_PLIMM_Execute(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op);
209200 int CHNCPU_Op_PLIMM_PrintCode(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, FILE *file);
210-int CHNCPU_Op_PLIMM_PrintWikiDoc(int opCode, FILE *file);
211201 //
212202 int CHNCPU_Op_CND_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, unsigned int prefix);
213203 int CHNCPU_Op_CND_Execute(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op);
214204 int CHNCPU_Op_CND_PrintCode(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, FILE *file);
215-int CHNCPU_Op_CND_PrintWikiDoc(int opCode, FILE *file);
216205 //
217206 int CHNCPU_Op_CALLBIOS_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, unsigned int prefix);
218207 int CHNCPU_Op_CALLBIOS_Execute(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op);
219208 int CHNCPU_Op_CALLBIOS_PrintCode(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, FILE *file);
220-int CHNCPU_Op_CALLBIOS_PrintWikiDoc(int opCode, FILE *file);
221209 //
222210 int CHNCPU_Op_LMEM_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, unsigned int prefix);
223211 int CHNCPU_Op_LMEM_Execute(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op);
224212 int CHNCPU_Op_LMEM_PrintCode(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, FILE *file);
225-int CHNCPU_Op_LMEM_PrintWikiDoc(int opCode, FILE *file);
226213 //
227214 int CHNCPU_Op_TernaryReg_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, unsigned int prefix);
228215 int CHNCPU_Op_TernaryRegBitwise_Execute(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op);
229216 int CHNCPU_Op_TernaryRegArithmetic_Execute(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op);
230217 int CHNCPU_Op_TernaryReg_PrintCode(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, FILE *file);
231-int CHNCPU_Op_TernaryReg_PrintWikiDoc(int opCode, FILE *file);
232218 //
233219 int CHNCPU_Op_CompareIReg_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, unsigned int prefix);
234220 int CHNCPU_Op_CompareIReg_Execute(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op);
235221 int CHNCPU_Op_CompareIReg_PrintCode(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, FILE *file);
236-int CHNCPU_Op_CompareIReg_PrintWikiDoc(int opCode, FILE *file);
237222 //
238223 int CHNCPU_Op_DATA_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, unsigned int prefix);
239224 int CHNCPU_Op_DATA_Execute(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op);
240225 int CHNCPU_Op_DATA_PrintCode(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, FILE *file);
241-int CHNCPU_Op_DATA_PrintWikiDoc(int opCode, FILE *file);
242226 CHNCPU_OpTag *CHNCPU_Op_DATA_CreateDataFromFileAsPType(const char dataPath[], ch4_sint pType);
243227 int CHNCPU_Op_DATA_WriteRawDataToFile(CHNCPU_OpTag *op, const char dataPath[], int dataCount, int dataType);
244228 int CHNCPU_Op_DATA_ReadAtIndex(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, int index);
@@ -260,4 +244,9 @@ CHNCPU_LabelSet *CHNCPU_CreateLabelSet(void);
260244 int CHNCPU_Label_Add(CHNCPU_LabelSet *lbSet, int mindex, ch4_uint labelID, ch4_uint opt, ch4_sint pType);
261245 CHNCPU_LabelTag *CHNCPU_Label_GetTagFromLabelID(CHNCPU_LabelSet *lbSet, int labelID);
262246
247+// @debug.c
248+void CHNCPU_DumpAppBin(CHNCPU_RuntimeEnvironment *env);
249+void CHNCPU_DumpIReg(CHNCPU_RuntimeEnvironment *env);
250+void CHNCPU_DumpPReg(CHNCPU_RuntimeEnvironment *env);
251+
263252 #endif
--- /dev/null
+++ b/chncpu/opcache.h
@@ -0,0 +1,164 @@
1+//
2+// opcache.h
3+// chncpu
4+//
5+// Created by 西田 耀 on 2014/07/07.
6+// Copyright (c) 2014年 CHNOSProject. All rights reserved.
7+//
8+
9+#ifndef chncpu_opcache_h
10+#define chncpu_opcache_h
11+
12+#include "chncpu.h"
13+
14+//
15+// 00 NOP (not cached)
16+//
17+// 00
18+//
19+
20+
21+//
22+// 01 LB
23+//
24+// 01 labelID opt
25+//
26+typedef struct _CHNCPU_OP_CACHE_LB CHNCPU_OpCache_LB;
27+struct _CHNCPU_OP_CACHE_LB {
28+ ch4_uint labelID;
29+ ch4_uint opt;
30+};
31+
32+//
33+// 02 LIMM
34+//
35+// 02 (sint)imm r bit
36+//
37+typedef struct _CHNCPU_OP_CACHE_LIMM CHNCPU_OpCache_LIMM;
38+struct _CHNCPU_OP_CACHE_LIMM {
39+ ch4_sint imm;
40+ ch4_uint r;
41+ ch4_uint bit;
42+};
43+
44+//
45+// 03 PLIMM
46+//
47+// 03 labelID p
48+//
49+typedef struct _CHNCPU_OP_CACHE_PLIMM CHNCPU_OpCache_PLIMM;
50+struct _CHNCPU_OP_CACHE_PLIMM {
51+ ch4_uint labelID;
52+ ch4_uint r;
53+};
54+
55+//
56+// 04 CND
57+//
58+// 04 r
59+//
60+typedef struct _CHNCPU_OP_CACHE_CND CHNCPU_OpCache_CND;
61+struct _CHNCPU_OP_CACHE_CND {
62+ ch4_uint r;
63+};
64+
65+//
66+// 05 CALLBIOS
67+//
68+// 05 fid ...
69+//
70+
71+//
72+// 08 LMEM
73+//
74+// p (sint)pType (sint)pDiff rDst bitDst
75+//
76+typedef struct _CHNCPU_OP_CACHE_LMEM CHNCPU_OpCache_LMEM;
77+struct _CHNCPU_OP_CACHE_LMEM {
78+ ch4_uint p;
79+ ch4_sint pType;
80+ ch4_sint pDiff;
81+ ch4_uint r;
82+ ch4_uint bitDst;
83+};
84+
85+//
86+// 10-12, 14-16, 18-1B Ternary Register Operation
87+//
88+// opCode r1 r2 r0 bit
89+//
90+// Bitwise
91+// 10 CP/OR r0 = r1 | r2; (CP: r0 = r1)
92+// 11 XOR r0 = r1 ^ r2;
93+// 12 AND r0 = r1 & r2;
94+//
95+// Arithmetic
96+// 14 ADD r0 = r1 + r2;
97+// 15 SUB r0 = r1 - r2;
98+// 16 MUL r0 = r1 * r2;
99+// 18 SHL r0 = r1 << r2;
100+// 19 SAR r0 = r1 >> r2;
101+// 1A DIV r0 = r1 / r2;
102+// 1B MOD r0 = r1 % r2;
103+//
104+typedef struct _CHNCPU_OP_CACHE_TERNARY_REG CHNCPU_OpCache_TernaryReg;
105+struct _CHNCPU_OP_CACHE_TERNARY_REG {
106+ ch4_uint r0;
107+ ch4_uint r1;
108+ ch4_uint r2;
109+ ch4_uint bit;
110+ unsigned int prefix;
111+};
112+
113+//
114+// 20-27 Compare Integer Register Operation
115+//
116+// opCode r1 r2 bitCmp r0 bitDst
117+//
118+// 20 CMPE r0 = (r1 == r2) ? -1 : 0;
119+// 21 CMPNE r0 = (r1 != r2) ? -1 : 0;
120+// 22 CMPL r0 = (r1 < r2) ? -1 : 0;
121+// 23 CMPGE r0 = (r1 >= r2) ? -1 : 0;
122+// 24 CMPLE r0 = (r1 <= r2) ? -1 : 0;
123+// 25 CMPG r0 = (r1 > r2) ? -1 : 0;
124+// 26 TSTZ ((r1 & r2) == 0) ? -1 : 0;
125+// 27 TSTNZ ((r1 & r2) != 0) ? -1 : 0;
126+//
127+
128+typedef struct _CHNCPU_OP_CACHE_COMPARE_IREG CHNCPU_OpCache_CompareIReg;
129+struct _CHNCPU_OP_CACHE_COMPARE_IREG {
130+ ch4_uint rSrc1;
131+ ch4_uint rSrc2;
132+ ch4_uint bitDiff;
133+ ch4_uint rDst;
134+ ch4_uint bitDst;
135+ unsigned int prefix;
136+};
137+
138+
139+//
140+// 2E DATA
141+//
142+// 2E labelID labelOpt (sint)dType dCount (rawData...)
143+//
144+typedef struct _CHNCPU_OP_CACHE_DATA CHNCPU_OpCache_DATA;
145+struct _CHNCPU_OP_CACHE_DATA {
146+ ch4_uint labelID;
147+ ch4_uint labelOpt;
148+ ch4_sint dataType;
149+ ch4_uint dataCount;
150+ void *rawData;
151+ //
152+ int rawDataByteSize;
153+ const char *filePath;
154+};
155+
156+//
157+// 2F Prefix (not cached)
158+//
159+// 2F n
160+//
161+
162+
163+
164+#endif
--- a/chncpu/opcode.c
+++ b/chncpu/opcode.c
@@ -7,6 +7,7 @@
77 //
88
99 #include "chncpu.h"
10+#include "opcache.h"
1011
1112 CHNCPU_OpTableSet *CHNCPU_CreateOpTableSet(void)
1213 {
@@ -32,107 +33,72 @@ int CHNCPU_Op_Init(CHNCPU_OpTableSet *opSet)
3233 opSet->bindFuncTable[i] = NULL;
3334 opSet->execFuncTable[i] = NULL;
3435 opSet->printFuncTable[i] = NULL;
35- opSet->docFuncTable[i] = NULL;
3636 }
37-
38- // NOP
39- opSet->docFuncTable[0x00] = CHNCPU_Op_NOP_PrintWikiDoc;
40-
37+
4138 // LB
4239 opSet->bindFuncTable[0x01] = CHNCPU_Op_LB_BindOperand;
4340 opSet->execFuncTable[0x01] = CHNCPU_Op_LB_Execute;
4441 opSet->printFuncTable[0x01] = CHNCPU_Op_LB_PrintCode;
45- opSet->docFuncTable[0x01] = CHNCPU_Op_LB_PrintWikiDoc;
4642
4743 // LIMM
4844 opSet->bindFuncTable[0x02] = CHNCPU_Op_LIMM_BindOperand;
4945 opSet->execFuncTable[0x02] = CHNCPU_Op_LIMM_Execute;
5046 opSet->printFuncTable[0x02] = CHNCPU_Op_LIMM_PrintCode;
51- opSet->docFuncTable[0x02] = CHNCPU_Op_LIMM_PrintWikiDoc;
5247
5348 // PLIMM
5449 opSet->bindFuncTable[0x03] = CHNCPU_Op_PLIMM_BindOperand;
5550 opSet->execFuncTable[0x03] = CHNCPU_Op_PLIMM_Execute;
5651 opSet->printFuncTable[0x03] = CHNCPU_Op_PLIMM_PrintCode;
57- opSet->docFuncTable[0x03] = CHNCPU_Op_PLIMM_PrintWikiDoc;
5852
5953 // CND
6054 opSet->bindFuncTable[0x04] = CHNCPU_Op_CND_BindOperand;
6155 opSet->execFuncTable[0x04] = CHNCPU_Op_CND_Execute;
6256 opSet->printFuncTable[0x04] = CHNCPU_Op_CND_PrintCode;
63- opSet->docFuncTable[0x04] = CHNCPU_Op_CND_PrintWikiDoc;
6457
6558 // CALLBIOS
6659 opSet->bindFuncTable[0x05] = CHNCPU_Op_CALLBIOS_BindOperand;
6760 opSet->execFuncTable[0x05] = CHNCPU_Op_CALLBIOS_Execute;
6861 opSet->printFuncTable[0x05] = CHNCPU_Op_CALLBIOS_PrintCode;
69- opSet->docFuncTable[0x05] = CHNCPU_Op_CALLBIOS_PrintWikiDoc;
7062
7163 // LMEM
7264 opSet->bindFuncTable[0x08] = CHNCPU_Op_LMEM_BindOperand;
7365 opSet->execFuncTable[0x08] = CHNCPU_Op_LMEM_Execute;
7466 opSet->printFuncTable[0x08] = CHNCPU_Op_LMEM_PrintCode;
75- opSet->docFuncTable[0x08] = CHNCPU_Op_LMEM_PrintWikiDoc;
7667
7768 // TernaryRegBitwise
7869 for(i = 0x10; i <= 0x12; i++){
7970 opSet->bindFuncTable[i] = CHNCPU_Op_TernaryReg_BindOperand;
8071 opSet->execFuncTable[i] = CHNCPU_Op_TernaryRegBitwise_Execute;
8172 opSet->printFuncTable[i] = CHNCPU_Op_TernaryReg_PrintCode;
82- opSet->docFuncTable[i] = CHNCPU_Op_TernaryReg_PrintWikiDoc;
8373 }
8474 // TernaryRegArithmetic
8575 for(i = 0x14; i <= 0x16; i++){
8676 opSet->bindFuncTable[i] = CHNCPU_Op_TernaryReg_BindOperand;
8777 opSet->execFuncTable[i] = CHNCPU_Op_TernaryRegArithmetic_Execute;
8878 opSet->printFuncTable[i] = CHNCPU_Op_TernaryReg_PrintCode;
89- opSet->docFuncTable[i] = CHNCPU_Op_TernaryReg_PrintWikiDoc;
9079 }
9180 for(i = 0x18; i <= 0x1B; i++){
9281 opSet->bindFuncTable[i] = CHNCPU_Op_TernaryReg_BindOperand;
9382 opSet->execFuncTable[i] = CHNCPU_Op_TernaryRegArithmetic_Execute;
9483 opSet->printFuncTable[i] = CHNCPU_Op_TernaryReg_PrintCode;
95- opSet->docFuncTable[i] = CHNCPU_Op_TernaryReg_PrintWikiDoc;
9684 }
9785 // CompareIReg
9886 for(i = 0x20; i <= 0x27; i++){
9987 opSet->bindFuncTable[i] = CHNCPU_Op_CompareIReg_BindOperand;
10088 opSet->execFuncTable[i] = CHNCPU_Op_CompareIReg_Execute;
10189 opSet->printFuncTable[i] = CHNCPU_Op_CompareIReg_PrintCode;
102- opSet->docFuncTable[i] = CHNCPU_Op_CompareIReg_PrintWikiDoc;
10390 }
10491 // DATA
10592 opSet->bindFuncTable[0x2E] = CHNCPU_Op_DATA_BindOperand;
10693 opSet->execFuncTable[0x2E] = CHNCPU_Op_DATA_Execute;
10794 opSet->printFuncTable[0x2E] = CHNCPU_Op_DATA_PrintCode;
108- opSet->docFuncTable[0x2E] = CHNCPU_Op_DATA_PrintWikiDoc;
109- // Prefix2F
110- opSet->docFuncTable[0x2f] = CHNCPU_Op_Prefix2F_PrintWikiDoc;
11195 return 0;
11296 }
11397
11498 //
115-// 00 NOP
116-//
117-int CHNCPU_Op_NOP_PrintWikiDoc(int opCode, FILE *file)
118-{
119- fprintf(file, ", %s, %02X, %X, %s, %s, %s, %s, %s, %s, %s, %s, %s\n",
120- "NOP",
121- 0x00, 0x00,
122- "", "", "", "", "", "", "",
123- "No operation", "");
124-
125- return 0;
126-}
127-
128-//
12999 // 01 LB
130100 //
131-typedef struct _CHNCPU_OP_CACHE_LB CHNCPU_OpCache_LB;
132-struct _CHNCPU_OP_CACHE_LB {
133- ch4_uint labelID;
134- ch4_uint opt;
135-};
101+
136102 int CHNCPU_Op_LB_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, unsigned int prefix)
137103 {
138104 CHNCPU_OpCache_LB *opCache;
@@ -175,27 +141,10 @@ int CHNCPU_Op_LB_PrintCode(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, FIL
175141 return 0;
176142 }
177143
178-int CHNCPU_Op_LB_PrintWikiDoc(int opCode, FILE *file)
179-{
180- fprintf(file, ", %s, %02X, %X, %s, %s, %s, %s, %s, %s, %s, %s, %s\n",
181- "LB",
182- 0x01, 0x01,
183- "labelID", "opt", "", "", "", "", "",
184- "#labelID;", "");
185-
186- return 0;
187-}
188-
189144 //
190145 // 02 LIMM
191146 //
192147
193-typedef struct _CHNCPU_OP_CACHE_LIMM CHNCPU_OpCache_LIMM;
194-struct _CHNCPU_OP_CACHE_LIMM {
195- ch4_sint imm;
196- ch4_uint r;
197- ch4_uint bit;
198-};
199148 int CHNCPU_Op_LIMM_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, unsigned int prefix)
200149 {
201150 CHNCPU_OpCache_LIMM *opCache;
@@ -251,26 +200,9 @@ int CHNCPU_Op_LIMM_PrintCode(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, F
251200 return 0;
252201 }
253202
254-int CHNCPU_Op_LIMM_PrintWikiDoc(int opCode, FILE *file)
255-{
256- fprintf(file, ", %s, %02X, %X, %s, %s, %s, %s, %s, %s, %s, %s, %s\n",
257- "LIMM",
258- 0x02, 0x02,
259- "(sint)imm", "r", "bit", "", "", "", "",
260- "reg = imm;", "");
261-
262- return 0;
263-}
264-
265203 //
266204 // 03 PLIMM
267205 //
268-
269-typedef struct _CHNCPU_OP_CACHE_PLIMM CHNCPU_OpCache_PLIMM;
270-struct _CHNCPU_OP_CACHE_PLIMM {
271- ch4_uint labelID;
272- ch4_uint r;
273-};
274206 int CHNCPU_Op_PLIMM_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, unsigned int prefix)
275207 {
276208 CHNCPU_OpCache_PLIMM *opCache;
@@ -331,25 +263,9 @@ int CHNCPU_Op_PLIMM_PrintCode(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op,
331263 return 0;
332264 }
333265
334-int CHNCPU_Op_PLIMM_PrintWikiDoc(int opCode, FILE *file)
335-{
336- fprintf(file, ", %s, %02X, %X, %s, %s, %s, %s, %s, %s, %s, %s, %s\n",
337- "PLIMM",
338- 0x03, 0x03,
339- "labelID", "p", "", "", "", "", "",
340- "p = #labelID;", "");
341-
342- return 0;
343-}
344-
345266 //
346267 // 04 CND
347268 //
348-
349-typedef struct _CHNCPU_OP_CACHE_CND CHNCPU_OpCache_CND;
350-struct _CHNCPU_OP_CACHE_CND {
351- ch4_uint r;
352-};
353269 int CHNCPU_Op_CND_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, unsigned int prefix)
354270 {
355271 CHNCPU_OpCache_CND *opCache;
@@ -392,17 +308,6 @@ int CHNCPU_Op_CND_PrintCode(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, FI
392308 return 0;
393309 }
394310
395-int CHNCPU_Op_CND_PrintWikiDoc(int opCode, FILE *file)
396-{
397- fprintf(file, ", %s, %02X, %X, %s, %s, %s, %s, %s, %s, %s, %s, %s\n",
398- "CND",
399- 0x04, 0x04,
400- "r", "", "", "", "", "", "",
401- "if((reg0R & 1) == 0){ skip nextOp; }", "Prefix");
402-
403- return 0;
404-}
405-
406311 //
407312 // 05 CALLBIOS
408313 //
@@ -464,29 +369,9 @@ int CHNCPU_Op_CALLBIOS_PrintCode(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *o
464369 return 0;
465370 }
466371
467-int CHNCPU_Op_CALLBIOS_PrintWikiDoc(int opCode, FILE *file)
468-{
469- fprintf(file, ", %s, %02X, %X, %s, %s, %s, %s, %s, %s, %s, %s, %s\n",
470- "CALLBIOS",
471- 0x05, 0x05,
472- "fid", "...", "", "", "", "", "",
473- "", "");
474-
475- return 0;
476-}
477-
478372 //
479373 // 08 LMEM
480374 //
481-
482-typedef struct _CHNCPU_OP_CACHE_LMEM CHNCPU_OpCache_LMEM;
483-struct _CHNCPU_OP_CACHE_LMEM {
484- ch4_uint p;
485- ch4_sint pType;
486- ch4_sint pDiff;
487- ch4_uint r;
488- ch4_uint bitDst;
489-};
490375 int CHNCPU_Op_LMEM_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, unsigned int prefix)
491376 {
492377 CHNCPU_OpCache_LMEM *opCache;
@@ -553,43 +438,10 @@ int CHNCPU_Op_LMEM_PrintCode(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, F
553438
554439 return 0;
555440 }
556-int CHNCPU_Op_LMEM_PrintWikiDoc(int opCode, FILE *file)
557-{
558- fprintf(file, ", %s, %02X, %X, %s, %s, %s, %s, %s, %s, %s, %s, %s\n",
559- "LMEM",
560- 0x08, 0x08 + 0x80,
561- "p", "(sint)pType", "(sint)pDiff", "r", "bitDst", "", "",
562- "", "");
563-
564- return 0;
565-}
566441
567442 //
568443 // Ternary Register Operation
569444 //
570-
571-// Bitwise
572-// 10 CP/OR
573-// 11 XOR
574-// 12 AND
575-//
576-// Arithmetic
577-// 14 ADD
578-// 15 SUB
579-// 16 MUL
580-// 18 SHL
581-// 19 SAR
582-// 1A DIV
583-// 1B MOD
584-
585-typedef struct _CHNCPU_OP_CACHE_TERNARY_REG CHNCPU_OpCache_TernaryReg;
586-struct _CHNCPU_OP_CACHE_TERNARY_REG {
587- ch4_uint r0;
588- ch4_uint r1;
589- ch4_uint r2;
590- ch4_uint bit;
591- unsigned int prefix;
592-};
593445 int CHNCPU_Op_TernaryReg_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, unsigned int prefix)
594446 {
595447 CHNCPU_OpCache_TernaryReg *opCache;
@@ -714,22 +566,6 @@ char *CHNCPU_Op_TernaryReg_MnemonicList0[12] = {
714566 "MOD"
715567 };
716568
717-char *CHNCPU_Op_TernaryReg_CodeList0[12] = {
718- // 10 - 1B
719- "r0 = r1 | r2;",
720- "r0 = r1 ^ r2;",
721- "r0 = r1 & r2;",
722- "",
723- "r0 = r1 + r2;",
724- "r0 = r1 - r2;",
725- "r0 = r1 * r2;",
726- "",
727- "r0 = r1 << r2;",
728- "r0 = r1 >> r2;",
729- "r0 = r1 / r2;",
730- "r0 = r1 % r2;"
731-};
732-
733569 int CHNCPU_Op_TernaryReg_PrintCode(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, FILE *file)
734570 {
735571 CHNCPU_OpCache_TernaryReg *opCache;
@@ -750,47 +586,9 @@ int CHNCPU_Op_TernaryReg_PrintCode(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag
750586 return 0;
751587 }
752588
753-int CHNCPU_Op_TernaryReg_PrintWikiDoc(int opCode, FILE *file)
754-{
755- fprintf(file, ", %s, %02X, %X, %s, %s, %s, %s, %s, %s, %s, %s, %s\n",
756- CHNCPU_Op_TernaryReg_MnemonicList0[opCode - 0x10],
757- opCode, opCode + 0x80,
758- "r1", "r2", "r0", "bit", "", "", "",
759- CHNCPU_Op_TernaryReg_CodeList0[opCode - 0x10], "");
760-
761- if(opCode == 0x10){
762- fprintf(file, ", %s, %02X, %X, %s, %s, %s, %s, %s, %s, %s, %s, %s\n",
763- "CP",
764- opCode, opCode + 0x80,
765- "r1", "r1", "r0", "bit", "", "", "",
766- "r0 = r1", "");
767- }
768-
769- return 0;
770-}
771-
772589 //
773590 // Compare Integer Register Operation
774591 //
775-
776-// 20 CMPE
777-// 21 CMPNE
778-// 22 CMPL
779-// 23 CMPGE
780-// 24 CMPLE
781-// 25 CMPG
782-// 26 TSTZ
783-// 27 TSTNZ
784-
785-typedef struct _CHNCPU_OP_CACHE_COMPARE_IREG CHNCPU_OpCache_CompareIReg;
786-struct _CHNCPU_OP_CACHE_COMPARE_IREG {
787- ch4_uint rSrc1;
788- ch4_uint rSrc2;
789- ch4_uint bitDiff;
790- ch4_uint rDst;
791- ch4_uint bitDst;
792- unsigned int prefix;
793-};
794592 int CHNCPU_Op_CompareIReg_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, unsigned int prefix)
795593 {
796594 CHNCPU_OpCache_CompareIReg *opCache;
@@ -890,19 +688,6 @@ char *CHNCPU_Op_CompareIReg_MnemonicList0[8] = {
890688 "TSTNZ",
891689 };
892690
893-char *CHNCPU_Op_CompareIReg_CodeList0[8] = {
894- // 20-27
895- "r0 = (r1 == r2) ? -1 : 0;",
896- "r0 = (r1 != r2) ? -1 : 0;",
897- "r0 = (r1 < r2) ? -1 : 0;",
898- "r0 = (r1 >= r2) ? -1 : 0;",
899- "r0 = (r1 <= r2) ? -1 : 0;",
900- "r0 = (r1 > r2) ? -1 : 0;",
901- "r0 = ((r1 & r2) == 0) ? -1 : 0;",
902- "r0 = ((r1 & r2) != 0) ? -1 : 0;",
903-};
904-
905-
906691 int CHNCPU_Op_CompareIReg_PrintCode(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, FILE *file)
907692 {
908693 CHNCPU_OpCache_CompareIReg *opCache;
@@ -920,31 +705,9 @@ int CHNCPU_Op_CompareIReg_PrintCode(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag
920705 return 0;
921706 }
922707
923-int CHNCPU_Op_CompareIReg_PrintWikiDoc(int opCode, FILE *file)
924-{
925- fprintf(file, ", %s, %02X, %X, %s, %s, %s, %s, %s, %s, %s, %s, %s\n",
926- CHNCPU_Op_CompareIReg_MnemonicList0[opCode - 0x20],
927- opCode, opCode + 0x80,
928- "r1", "r2", "bitDiff", "r0", "bitDst", "", "",
929- CHNCPU_Op_CompareIReg_CodeList0[opCode - 0x20], "");
930-
931- return 0;
932-}
933-
934708 //
935709 // 2E DATA
936710 //
937-typedef struct _CHNCPU_OP_CACHE_DATA CHNCPU_OpCache_DATA;
938-struct _CHNCPU_OP_CACHE_DATA {
939- ch4_uint labelID;
940- ch4_uint labelOpt;
941- ch4_sint dataType;
942- ch4_uint dataCount;
943- void *rawData;
944- //
945- int rawDataByteSize;
946- const char *filePath;
947-};
948711 int CHNCPU_Op_DATA_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, unsigned int prefix)
949712 {
950713 CHNCPU_OpCache_DATA *opCache;
@@ -1020,16 +783,6 @@ int CHNCPU_Op_DATA_PrintCode(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, F
1020783
1021784 return 0;
1022785 }
1023-int CHNCPU_Op_DATA_PrintWikiDoc(int opCode, FILE *file)
1024-{
1025- fprintf(file, ", %s, %02X, %X, %s, %s, %s, %s, %s, %s, %s, %s, %s\n",
1026- "DATA",
1027- 0x2E, 0x2E + 0x80,
1028- "labelID", "labelOpt", "(sint)dataType", "dataCount", "(rawData)...", "", "",
1029- "", "");
1030-
1031- return 0;
1032-}
1033786 CHNCPU_OpTag *CHNCPU_Op_DATA_CreateDataFromFileAsPType(const char dataPath[], ch4_sint pType)
1034787 {
1035788 FILE *fp;
@@ -1174,19 +927,3 @@ const char *CHNCPU_Op_DATA_GetFilePath(CHNCPU_OpTag *op)
1174927 return ((CHNCPU_OpCache_DATA *)op->opCache)->filePath;
1175928 }
1176929
1177-//
1178-// Prefix2F
1179-//
1180-
1181-int CHNCPU_Op_Prefix2F_PrintWikiDoc(int opCode, FILE *file)
1182-{
1183- fprintf(file, ", %s, %02X, %X, %s, %s, %s, %s, %s, %s, %s, %s, %s\n",
1184- "Prefix2F-0",
1185- 0x2F, 0x2F + 0x80,
1186- "0", "", "", "", "", "", "",
1187- "DISABLE_BOUND_CHECK;", "");
1188-
1189- return 0;
1190-}
1191-
1192-
--- /dev/null
+++ b/debug.c
@@ -0,0 +1,64 @@
1+//
2+// debug.c
3+// chncpu
4+//
5+// Created by 西田 耀 on 2014/07/07.
6+// Copyright (c) 2014年 CHNOSProject. All rights reserved.
7+//
8+
9+#include "chncpu.h"
10+
11+void CHNCPU_DumpAppBin(CHNCPU_RuntimeEnvironment *env)
12+{
13+ int i;
14+
15+ for(i = 0; i < env->appbinsize; i++){
16+ printf("%02X ", env->appbin0[i]);
17+ if((i & 0xf) == 0xf){
18+ putchar('\n');
19+ }
20+ }
21+ if(((i - 1) & 0xf) != 0xf){
22+ putchar('\n');
23+ }
24+}
25+
26+void CHNCPU_DumpIReg(CHNCPU_RuntimeEnvironment *env)
27+{
28+ int i, regs = 0;
29+
30+ puts(">>> Integer registers");
31+
32+ for(i = 0; i < CHNCPU_NUMBER_OF_IREG; i++){
33+ if(env->iRegBits[i]){
34+ printf("R%02X = %10d = 0x%08X(%2d) ", i, env->iReg[i], env->iReg[i], env->iRegBits[i]);
35+ putchar('\n');
36+ regs++;
37+ }
38+ }
39+ if(((regs - 1) & 0xF) != 0xF){
40+ putchar('\n');
41+ }
42+}
43+
44+void CHNCPU_DumpPReg(CHNCPU_RuntimeEnvironment *env)
45+{
46+ int i, regs = 0;
47+
48+ puts(">>> Pointer registers");
49+
50+ for(i = 0; i < CHNCPU_NUMBER_OF_PREG; i++){
51+ if(env->pReg[i].type != CHNCPU_PType_Undefined){
52+ if(env->pReg[i].mindex != CHNCPU_MemoryIndex_INVALID){
53+ printf("P%02X: Type:%2X mem[%d][%d]", i, env->pReg[i].type, env->pReg[i].mindex, env->pReg[i].pindex);
54+ } else{
55+ printf("P%02X: Type:%2X %s[%d]", i, env->pReg[i].type, CHNCPU_Op_DATA_GetFilePath(env->pReg[i].opTag), env->pReg[i].pindex);
56+ }
57+ putchar('\n');
58+ regs++;
59+ }
60+ }
61+ if(((regs - 1) & 0xF) != 0xF){
62+ putchar('\n');
63+ }
64+}