Revisión | 5c23f39e5708c9dd8288c968957571698b98110f (tree) |
---|---|
Tiempo | 2014-06-23 23:58:37 |
Autor | hikarupsp <hikarupsp@user...> |
Commiter | hikarupsp |
どうにかcharsを実行できた!
@@ -49,7 +49,8 @@ | ||
49 | 49 | // (2F)Prefix |
50 | 50 | #define CHNCPU_PREFIX_ALLOW_TRUNCATE 0x01 |
51 | 51 | |
52 | -#define CHNCPU_PREFIX_MASK_Op_TernaryRegBitwise (CHNCPU_PREFIX_ALLOW_TRUNCATE) | |
52 | +#define CHNCPU_PREFIX_MASK_Op_TernaryReg (CHNCPU_PREFIX_ALLOW_TRUNCATE) | |
53 | +#define CHNCPU_PREFIX_MASK_Op_CompareIReg (CHNCPU_PREFIX_ALLOW_TRUNCATE) | |
53 | 54 | |
54 | 55 | // Type of Pointer |
55 | 56 | #define CHNCPU_PType_Undefined 0 |
@@ -160,6 +161,9 @@ int CHNCPU_Op_LIMM_PrintCode(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, F | ||
160 | 161 | int CHNCPU_Op_PLIMM_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, unsigned int prefix); |
161 | 162 | int CHNCPU_Op_PLIMM_Execute(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op); |
162 | 163 | int CHNCPU_Op_PLIMM_PrintCode(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, FILE *file); |
164 | +int CHNCPU_Op_CND_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, unsigned int prefix); | |
165 | +int CHNCPU_Op_CND_Execute(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op); | |
166 | +int CHNCPU_Op_CND_PrintCode(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, FILE *file); | |
163 | 167 | int CHNCPU_Op_CALLBIOS_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, unsigned int prefix); |
164 | 168 | int CHNCPU_Op_CALLBIOS_Execute(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op); |
165 | 169 | int CHNCPU_Op_CALLBIOS_PrintCode(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, FILE *file); |
@@ -167,6 +171,9 @@ int CHNCPU_Op_TernaryReg_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTa | ||
167 | 171 | int CHNCPU_Op_TernaryRegBitwise_Execute(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op); |
168 | 172 | int CHNCPU_Op_TernaryRegArithmetic_Execute(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op); |
169 | 173 | int CHNCPU_Op_TernaryReg_PrintCode(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, FILE *file); |
174 | +int CHNCPU_Op_CompareIReg_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, unsigned int prefix); | |
175 | +int CHNCPU_Op_CompareIReg_Execute(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op); | |
176 | +int CHNCPU_Op_CompareIReg_PrintCode(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, FILE *file); | |
170 | 177 | |
171 | 178 | // @bios.c |
172 | 179 | CHNCPU_BIOS *CHNCPU_CreateBIOS(void); |
@@ -49,6 +49,11 @@ int CHNCPU_Op_Init(CHNCPU_OpTableSet *opSet) | ||
49 | 49 | opSet->execFuncTable[0x03] = CHNCPU_Op_PLIMM_Execute; |
50 | 50 | opSet->printFuncTable[0x03] = CHNCPU_Op_PLIMM_PrintCode; |
51 | 51 | |
52 | + // CND | |
53 | + opSet->bindFuncTable[0x04] = CHNCPU_Op_CND_BindOperand; | |
54 | + opSet->execFuncTable[0x04] = CHNCPU_Op_CND_Execute; | |
55 | + opSet->printFuncTable[0x04] = CHNCPU_Op_CND_PrintCode; | |
56 | + | |
52 | 57 | // CALLBIOS |
53 | 58 | opSet->bindFuncTable[0x05] = CHNCPU_Op_CALLBIOS_BindOperand; |
54 | 59 | opSet->execFuncTable[0x05] = CHNCPU_Op_CALLBIOS_Execute; |
@@ -71,7 +76,12 @@ int CHNCPU_Op_Init(CHNCPU_OpTableSet *opSet) | ||
71 | 76 | opSet->execFuncTable[i] = CHNCPU_Op_TernaryRegArithmetic_Execute; |
72 | 77 | opSet->printFuncTable[i] = CHNCPU_Op_TernaryReg_PrintCode; |
73 | 78 | } |
74 | - | |
79 | + // | |
80 | + for(i = 0x20; i <= 0x27; i++){ | |
81 | + opSet->bindFuncTable[i] = CHNCPU_Op_CompareIReg_BindOperand; | |
82 | + opSet->execFuncTable[i] = CHNCPU_Op_CompareIReg_Execute; | |
83 | + opSet->printFuncTable[i] = CHNCPU_Op_CompareIReg_PrintCode; | |
84 | + } | |
75 | 85 | return 0; |
76 | 86 | } |
77 | 87 |
@@ -186,7 +196,7 @@ int CHNCPU_Op_LIMM_PrintCode(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, F | ||
186 | 196 | } |
187 | 197 | |
188 | 198 | // |
189 | -// 02 PLIMM | |
199 | +// 03 PLIMM | |
190 | 200 | // |
191 | 201 | |
192 | 202 | typedef struct _CHNCPU_OP_CACHE_PLIMM CHNCPU_OpCache_PLIMM; |
@@ -250,6 +260,56 @@ int CHNCPU_Op_PLIMM_PrintCode(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, | ||
250 | 260 | } |
251 | 261 | |
252 | 262 | // |
263 | +// 04 CND | |
264 | +// | |
265 | + | |
266 | +typedef struct _CHNCPU_OP_CACHE_CND CHNCPU_OpCache_CND; | |
267 | +struct _CHNCPU_OP_CACHE_CND { | |
268 | + ch4_uint r; | |
269 | +}; | |
270 | +int CHNCPU_Op_CND_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, unsigned int prefix) | |
271 | +{ | |
272 | + CHNCPU_OpCache_CND *opCache; | |
273 | + | |
274 | + opCache = malloc(sizeof(CHNCPU_OpCache_CND)); | |
275 | + op->opCache = opCache; | |
276 | + | |
277 | + opCache->r = CH4Reader_ReadNextAsUINT(env->appbinReader); | |
278 | + | |
279 | + if(opCache->r >= CHNCPU_NUMBER_OF_PREG){ | |
280 | + env->errFlags |= CHNCPU_ERR_C_REGNUM; | |
281 | + return -1; | |
282 | + } | |
283 | + if(prefix != 0){ | |
284 | + env->errFlags |= CHNCPU_ERR_C_PREFIX; | |
285 | + return -1; | |
286 | + } | |
287 | + return 0; | |
288 | +} | |
289 | +int CHNCPU_Op_CND_Execute(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op) | |
290 | +{ | |
291 | + CHNCPU_OpCache_CND *opCache; | |
292 | + | |
293 | + opCache = op->opCache; | |
294 | + | |
295 | + if((env->iReg[opCache->r] & 0x1) != 0x1){ | |
296 | + // 次の命令は実行しない | |
297 | + env->currentIndex++; | |
298 | + } | |
299 | + return 0; | |
300 | +} | |
301 | + | |
302 | +int CHNCPU_Op_CND_PrintCode(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, FILE *file) | |
303 | +{ | |
304 | + CHNCPU_OpCache_CND *opCache; | |
305 | + | |
306 | + opCache = op->opCache; | |
307 | + fprintf(file, "CND(r:%02X);\n", opCache->r); | |
308 | + | |
309 | + return 0; | |
310 | +} | |
311 | + | |
312 | +// | |
253 | 313 | // 05 CALLBIOS |
254 | 314 | // |
255 | 315 | int CHNCPU_Op_CALLBIOS_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, unsigned int prefix) |
@@ -360,7 +420,7 @@ int CHNCPU_Op_TernaryReg_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTa | ||
360 | 420 | if(!CHNCPU_CHK_IsAvailableBits(env, opCache->bit)){ |
361 | 421 | return -1; |
362 | 422 | } |
363 | - if((prefix | CHNCPU_PREFIX_MASK_Op_TernaryRegBitwise) != CHNCPU_PREFIX_MASK_Op_TernaryRegBitwise){ | |
423 | + if((prefix | CHNCPU_PREFIX_MASK_Op_TernaryReg) != CHNCPU_PREFIX_MASK_Op_TernaryReg){ | |
364 | 424 | env->errFlags |= CHNCPU_ERR_C_PREFIX; |
365 | 425 | return -1; |
366 | 426 | } |
@@ -408,14 +468,6 @@ int CHNCPU_Op_TernaryRegBitwise_Execute(CHNCPU_RuntimeEnvironment *env, CHNCPU_O | ||
408 | 468 | } |
409 | 469 | int CHNCPU_Op_TernaryRegArithmetic_Execute(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op) |
410 | 470 | { |
411 | - // Arithmetic | |
412 | - // 14 ADD | |
413 | - // 15 SUB | |
414 | - // 16 MUL | |
415 | - // 18 SHL | |
416 | - // 19 SAR | |
417 | - // 1A DIV | |
418 | - // 1B MOD | |
419 | 471 | CHNCPU_OpCache_TernaryReg *opCache; |
420 | 472 | int opCode; |
421 | 473 | ch4_sint result; |
@@ -484,8 +536,146 @@ int CHNCPU_Op_TernaryReg_PrintCode(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag | ||
484 | 536 | fprintf(file, "(%02X)", op->opCode); |
485 | 537 | } |
486 | 538 | |
487 | - fprintf(file, "(r0:%d, r1:%02X, r2:%02X, bit:%02X);\n", opCache->r0, opCache->r1, opCache->r2, opCache->bit); | |
539 | + fprintf(file, "(r0:%02X, r1:%02X, r2:%02X, bit:%d);\n", opCache->r0, opCache->r1, opCache->r2, opCache->bit); | |
488 | 540 | |
489 | 541 | return 0; |
490 | 542 | } |
491 | 543 | |
544 | +// | |
545 | +// Compare Integer Register Operation | |
546 | +// | |
547 | + | |
548 | +// 20 CMPE | |
549 | +// 21 CMPNE | |
550 | +// 22 CMPL | |
551 | +// 23 CMPGE | |
552 | +// 24 CMPLE | |
553 | +// 25 CMPG | |
554 | +// 26 TSTZ | |
555 | +// 27 TSTNZ | |
556 | + | |
557 | +typedef struct _CHNCPU_OP_CACHE_COMPARE_IREG CHNCPU_OpCache_CompareIReg; | |
558 | +struct _CHNCPU_OP_CACHE_COMPARE_IREG { | |
559 | + ch4_uint rSrc1; | |
560 | + ch4_uint rSrc2; | |
561 | + ch4_uint bitDiff; | |
562 | + ch4_uint rDst; | |
563 | + ch4_uint bitDst; | |
564 | + unsigned int prefix; | |
565 | +}; | |
566 | +int CHNCPU_Op_CompareIReg_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, unsigned int prefix) | |
567 | +{ | |
568 | + CHNCPU_OpCache_CompareIReg *opCache; | |
569 | + | |
570 | + opCache = malloc(sizeof(CHNCPU_OpCache_TernaryReg)); | |
571 | + op->opCache = opCache; | |
572 | + | |
573 | + opCache->rSrc1 = CH4Reader_ReadNextAsUINT(env->appbinReader); | |
574 | + opCache->rSrc2 = CH4Reader_ReadNextAsUINT(env->appbinReader); | |
575 | + opCache->bitDiff = CH4Reader_ReadNextAsUINT(env->appbinReader); | |
576 | + opCache->rDst = CH4Reader_ReadNextAsUINT(env->appbinReader); | |
577 | + opCache->bitDst = CH4Reader_ReadNextAsUINT(env->appbinReader); | |
578 | + opCache->prefix = prefix; | |
579 | + | |
580 | + if(opCache->rSrc1 >= CHNCPU_NUMBER_OF_IREG || | |
581 | + opCache->rSrc2 >= CHNCPU_NUMBER_OF_IREG || | |
582 | + opCache->rDst >= CHNCPU_NUMBER_OF_IREG){ | |
583 | + env->errFlags |= CHNCPU_ERR_C_REGNUM; | |
584 | + return -1; | |
585 | + } | |
586 | + if(!CHNCPU_CHK_IsAvailableBits(env, opCache->bitDiff) || | |
587 | + !CHNCPU_CHK_IsAvailableBits(env, opCache->bitDst)){ | |
588 | + return -1; | |
589 | + } | |
590 | + if((prefix | CHNCPU_PREFIX_MASK_Op_CompareIReg) != CHNCPU_PREFIX_MASK_Op_CompareIReg){ | |
591 | + env->errFlags |= CHNCPU_ERR_C_PREFIX; | |
592 | + return -1; | |
593 | + } | |
594 | + return 0; | |
595 | +} | |
596 | +int CHNCPU_Op_CompareIReg_Execute(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op) | |
597 | +{ | |
598 | + CHNCPU_OpCache_CompareIReg *opCache; | |
599 | + int opCode; | |
600 | + ch4_sint result; | |
601 | + //ch4_sint diff; | |
602 | + ch4_sint r1, r2; | |
603 | + | |
604 | + opCache = op->opCache; | |
605 | + opCode = op->opCode; | |
606 | + | |
607 | + // check with bitDiff | |
608 | + /* | |
609 | + // この機能は未実装 | |
610 | + diff = env->iReg[opCache->rSrc1] - env->iReg[opCache->rSrc2]; | |
611 | + CHNCPU_AdjustValueForBit(env, &diff, opCache->bitDiff, opCache->prefix); | |
612 | + if(env->errFlags){ | |
613 | + return -1; | |
614 | + } | |
615 | + */ | |
616 | + | |
617 | + r1 = env->iReg[opCache->rSrc1]; | |
618 | + r2 = env->iReg[opCache->rSrc2]; | |
619 | + | |
620 | + if(opCode == 0x20){ | |
621 | + result = (r1 == r2) ? -1 : 0; | |
622 | + } else if(opCode == 0x21){ | |
623 | + result = (r1 != r2) ? -1 : 0; | |
624 | + } else if(opCode == 0x22){ | |
625 | + result = (r1 < r2) ? -1 : 0; | |
626 | + } else if(opCode == 0x23){ | |
627 | + result = (r1 >= r2) ? -1 : 0; | |
628 | + } else if(opCode == 0x24){ | |
629 | + result = (r1 <= r2) ? -1 : 0; | |
630 | + } else if(opCode == 0x25){ | |
631 | + result = (r1 > r2) ? -1 : 0; | |
632 | + } else if(opCode == 0x26){ | |
633 | + result = ((r1 & r2) == 0) ? -1 : 0; | |
634 | + } else if(opCode == 0x27){ | |
635 | + result = ((r1 & r2) != 0) ? -1 : 0; | |
636 | + } else{ | |
637 | + env->errFlags |= CHNCPU_ERR_X_INTERNAL; | |
638 | + return -1; | |
639 | + } | |
640 | + // check with bitDst | |
641 | + if(opCache->bitDst == 0){ | |
642 | + env->errFlags |= CHNCPU_ERR_X_TRUNCATED_VALUE; | |
643 | + return -1; | |
644 | + } | |
645 | + // store | |
646 | + if(!env->errFlags){ | |
647 | + env->iReg[opCache->rDst] = result; | |
648 | + env->iRegBits[opCache->rDst] = opCache->bitDst; | |
649 | + } | |
650 | + return 0; | |
651 | +} | |
652 | + | |
653 | +char *CHNCPU_Op_CompareIReg_MnemonicList0[8] = { | |
654 | + // 20-27 | |
655 | + "CMPE", | |
656 | + "CMPNE", | |
657 | + "CMPL", | |
658 | + "CMPGE", | |
659 | + "CMPLE", | |
660 | + "CMPG", | |
661 | + "TSTZ", | |
662 | + "TSTNZ", | |
663 | +}; | |
664 | +int CHNCPU_Op_CompareIReg_PrintCode(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, FILE *file) | |
665 | +{ | |
666 | + CHNCPU_OpCache_CompareIReg *opCache; | |
667 | + | |
668 | + opCache = op->opCache; | |
669 | + | |
670 | + if(0x20 <= op->opCode && op->opCode <= 0x27){ | |
671 | + fprintf(file, "%s", CHNCPU_Op_CompareIReg_MnemonicList0[op->opCode - 0x20]); | |
672 | + } else{ | |
673 | + fprintf(file, "(%02X)", op->opCode); | |
674 | + } | |
675 | + | |
676 | + fprintf(file, "(rDst:%02X, bitDst:%d r1:%02X, r2:%02X, bitDiff:%d);\n", opCache->rDst, opCache->bitDst, opCache->rSrc1, opCache->rSrc2, opCache->bitDiff); | |
677 | + | |
678 | + return 0; | |
679 | +} | |
680 | + | |
681 | + |
@@ -1,6 +1,9 @@ | ||
1 | 1 | 2 a0 0 90 |
2 | 2 | 2 1 1 90 |
3 | +2 C7E 2 90 | |
3 | 4 | 1 1 0 |
4 | 5 | 5 0 0 |
5 | 6 | 94 0 1 0 90 |
7 | +a4 0 2 90 bf 90 | |
8 | +4 bf | |
6 | 9 | 3 1 bf |