From 27f796ab6a9f455bbd2a1c85088db5304cece75a Mon Sep 17 00:00:00 2001 From: biouman <> Date: Mon, 16 Apr 2001 14:08:26 +0000 Subject: *** empty log message *** --- lib/registre.c | 16 ++- lib/simulator.c | 300 +++++++++++++++++++++++++++++++++----------------------- 2 files changed, 192 insertions(+), 124 deletions(-) (limited to 'lib') diff --git a/lib/registre.c b/lib/registre.c index e77e9c1..4edb885 100644 --- a/lib/registre.c +++ b/lib/registre.c @@ -35,9 +35,9 @@ Uint32 LireRegistreFLAG(void) return (registre[REG_FLAG]); } -Uint32 LireRegistrePP(void) +Uint32 LireRegistreSP(void) { - return (registre[REG_PUSHPOP]); + return (registre[REG_STACKPTR]); } void EcrireRegistreRG(Uint32 val) @@ -60,9 +60,9 @@ void EcrireRegistreFLAG(Uint32 val) registre[REG_FLAG] = val; } -void EcrireRegistrePP(Uint32 val) +void EcrireRegistreSP(Uint32 val) { - registre[REG_PUSHPOP] = val; + registre[REG_STACKPTR] = val; } /* Lit le mot qui se trouve dans le registre 'numero_registre' */ @@ -171,3 +171,11 @@ void ResetParity(void) { registre[REG_FLAG] &= (VAL_MAX - 8); } + + +void ResetRegistres(void) +{ int i; + + for (i=0; i> 2, 4)) { /* teste les bits 2 et 3 */ case 0: @@ -171,16 +177,14 @@ void Decode(Uint32 instruction) } } /* Pas de MOV conditionnel */ - if (ValeurBit(Extension(instruction), 1) == 0) {/* Mov arg1 arg2 */ - if (ValeurBit(Extension(instruction), 0) == 0) {/* arg2 = reg */ - if (champ(Champ1(instruction), 2) == 0) {/* r/m de arg1 = 0 */ - EcrireRegistre(Champ3(instruction), - LireRegistre(Champ2(instruction))); + if (ValeurBit(Extension(instruction), 1) == 0) { /* Mov arg1 arg2 */ + if (ValeurBit(Extension(instruction), 0) == 0) { /* arg2 = reg */ + if (champ(Champ1(instruction), 2) == 0) { /* r/m de arg1 = 0 */ + EcrireRegistre(Champ3(instruction), LireRegistre(Champ2(instruction))); } else { - ST(Adresse(Champ1(instruction), instruction), - LireRegistre(Champ2(instruction))); - } - } else {/* arg2 = imm32 */ + ST(Adresse(Champ1(instruction), instruction), LireRegistre(Champ2(instruction))); + } + } else { /* arg2 = imm32 */ if (champ(Champ1(instruction), 2) == 0) { /* r/m de arg1 = 0 */ EcrireRegistre(Champ3(instruction), LireInstruction()); IncrementeCompteurOrdinal(); @@ -188,114 +192,170 @@ void Decode(Uint32 instruction) ST(Adresse(Champ1(instruction), instruction), LireInstruction()); IncrementeCompteurOrdinal(); } - } - } else { - if (ValeurBit(Extension(instruction), 0) == 0) {/* arg2 = reg */ - if (champ(Champ1(instruction), 2) == 0) {/* r/m de arg1 = 0 */ + } + } else { + if (ValeurBit(Extension(instruction), 0) == 0) { /* arg2 = reg */ + if (champ(Champ1(instruction), 2) == 0) { /* r/m de arg1 = 0 */ EcrireRegistre(Champ2(instruction), LireRegistre(Champ3(instruction))); - + } else { - EcrireRegistre(Champ2(instruction), - LD(Adresse(Champ1(instruction), instruction))); - } - } else {/* arg2 = imm32 */ - exception(1,_("MOV: Memory to Memory Forbidden On This Type Of Processor")); - } + EcrireRegistre(Champ2(instruction), LD(Adresse(Champ1(instruction), instruction))); + } + } else { /* arg2 = imm32 */ + exception(1, _("MOV: Memory to Memory Forbidden On This Type Of Processor")); + } } fin: - break; - } - case 9: { /* NOP */ - /* Instruction nulle */ - break; - } - case 10: /* J */ - case 11: { - int test1, test2; + break; + } + case 9:{ /* NOP */ + /* Instruction nulle */ + break; + } + case 10: /* J[cond] */ + case 11:{ + int test1, test2; - switch (champ(Extension(instruction), 4)) { - case 0: - test1 = - LireRegistre(Champ1(instruction)) == - LireRegistre(Champ2(instruction)); break; case 1: - test1 = - LireRegistre(Champ1(instruction)) != - LireRegistre(Champ2(instruction)); break; case 2: - test1 = - LireRegistre(Champ1(instruction)) < - LireRegistre(Champ2(instruction)); break; case 3: - test1 = - LireRegistre(Champ1(instruction)) <= - LireRegistre(Champ2(instruction)); break;} - switch (champ(Extension(instruction) >> 2, 4)) { - case 0: - test2 = Overflow(); break; case 1: - test2 = Zero(); break; case 2: - test2 = Sign(); break; case 3: - test2 = Parity(); break;} - switch (champ(Extension(instruction) >> 4, 4)) { - case 0: - test1 = test1; break; case 1: - test1 = test1 || test2; break; case 2: - test1 = test1 && !test2; break; case 3: - test1 = test1 || !test2; break;} - if (test1) { - IncrementeCompteurOrdinal(); - if (Opcode(instruction) == - 10) EcrireRegistrePC(LireInstruction()); - else - EcrireRegistrePC(AdditionNonSigne - (LireRegistrePC(), LireInstruction()));} - break;} - case (12): /* JMP *//* Kris Kross */ + switch (champ(Extension(instruction), 4)) { + case 0: + if (Champ1(instruction) == Champ2(instruction)) { + test1 = 1; + } else { + test1 = LireRegistre(Champ1(instruction)) == LireRegistre(Champ2(instruction)); + } + break; + case 1: + test1 = LireRegistre(Champ1(instruction)) != LireRegistre(Champ2(instruction)); + break; + case 2: + test1 = LireRegistre(Champ1(instruction)) < LireRegistre(Champ2(instruction)); + break; + case 3: + test1 = LireRegistre(Champ1(instruction)) <= LireRegistre(Champ2(instruction)); + break; + } + switch (champ(Extension(instruction) >> 2, 4)) { + case 0: + test2 = Overflow(); + break; + case 1: + test2 = Zero(); + break; + case 2: + test2 = Sign(); + break; + case 3: + test2 = Parity(); + break; + } + switch (champ(Extension(instruction) >> 4, 4)) { + case 0: + test1 = test1; + break; + case 1: + test1 = test1 || test2; + break; + case 2: + test1 = test1 && !test2; + break; + case 3: + test1 = test1 || !test2; + break; + } + if (test1) { Uint32 tmp; + tmp=LireInstruction(); + EcrireRegistrePC(tmp); + } + break; + } + case (12): /* JMP */ case (13): - if (ValeurBit(Extension(instruction), 0) == 0) { - ; /* RET */ - } - else - if (ValeurBit(Extension(instruction), 1) == 0); /* JMP */ - else; /* CALL */ - break; case 14: { /* PUSH */ - Uint32 val; /* valeur qui va etre stockée */ - EcrireRegistrePP(SoustractionNonSigne(LireRegistrePP(), 1)); /* On pointe sur un emplacement vide */ - if (ValeurBit(Extension(instruction), 0) == 0) - val = LireRegistre(Champ1(instruction)); - else { - IncrementeCompteurOrdinal(); val = LireInstruction();} - ST(LireRegistrePP(), val); break;} - case 15: { /* POP */ - EcrireRegistre(Champ1(instruction), LireRegistrePP()); - EcrireRegistrePP(AdditionNonSigne(LireRegistrePP(), 1)); - break;} - case 127: { /* HALT-RESET */ - if (ValeurBit(Extension(instruction), 0)) - getc(stdin); /* Halt */ - else - Initialisation(); /* Reset */ - break;} - default: { - printf("soja");} - } - } - } - void Traitement(void) { - Uint32 instruction; while (!0) { - instruction = LireInstruction(); - Decode(instruction); IncrementeCompteurOrdinal();} - } + if (ValeurBit(Extension(instruction), 0) == 0) { + /* RET */ + EcrireRegistreSP(AdditionNonSigne(LireRegistreSP(),Champ1(instruction))); + EcrireRegistreSP(AdditionNonSigne(LireRegistreSP(), 1)); + EcrireRegistrePC(LD(LireRegistreSP())); + + } else if (ValeurBit(Extension(instruction), 1) == 0) { /* JMP */ + if (ValeurBit(Extension(instruction), 2) == 0) { + EcrireRegistrePC(LireRegistre(Champ1(instruction))); + } else { + EcrireRegistrePC(LireInstruction()); + } + } else { /* CALL */ + ST(LireRegistreSP(),LireRegistrePC()); + EcrireRegistreSP(SoustractionNonSigne(LireRegistreSP(),1)); + if (ValeurBit(Extension(instruction), 2) == 0) { + EcrireRegistrePC(LireRegistre(Champ1(instruction))); + } else { + EcrireRegistrePC(LireInstruction()); + } + } + break; + case 14:{ /* PUSH */ + Uint32 val; /* valeur qui va etre stockée */ - void AfficheReg(void) // affiche reg - { - int i, j; for (i = 0; i <= 3; i++) { - for (j = 1; j <= 8; j++) { - printf(" R%02d ", (i * 8 + j));} - printf("\n"); for (j = 1; j <= 8; j++) { - printf("%08lX ", (registre[i * 8 + j - 1]));} - printf("\n");} - printf - ("Rg: %08lX | Rd: %08lX | Flag: %08lX | PC: %08lX\n", - LireRegistreRG(), LireRegistreRD(), LireRegistreFLAG(), - registre[REG_PC]); printf("\n");} + if (ValeurBit(Extension(instruction), 0) == 0) + val = LireRegistre(Champ1(instruction)); + else { + val = LireInstruction(); + IncrementeCompteurOrdinal(); + } + ST(LireRegistreSP(), val); + EcrireRegistreSP(SoustractionNonSigne(LireRegistreSP(), 1)); + break; + } + case 15:{ /* POP */ + EcrireRegistreSP(AdditionNonSigne(LireRegistreSP(), 1)); + EcrireRegistre(Champ1(instruction), LD(LireRegistreSP())); + + break; + } + case 127:{ /* HALT-RESET */ + if (ValeurBit(Extension(instruction), 0)) + exit(0); /* Halt *//* *******************FIXMI********************* */ + else + ResetRegistres(); + Traitement(entrypoint); /* Reset *//* ************FIXMI************** */ + break; + } + default:{ + exception(1, _("DecodeExec: Invalid Opcode")); + } + } + } +} +void Traitement(Uint32 entrypoint) +{ /* ******************** FIXMI ************************* */ + Uint32 instruction; + + EcrireRegistrePC(entrypoint); + while (!0) { + instruction = LireInstruction(); + IncrementeCompteurOrdinal(); + DecodeExec(instruction, entrypoint); + } +} + +void AfficheReg(void) // affiche reg +{ + int i, j; + + for (i = 0; i <= 3; i++) { + for (j = 1; j <= 8; j++) { + printf(" R%02d ", (i * 8 + j)); + } + printf("\n"); + for (j = 1; j <= 8; j++) { + printf("%08lX ", (registre[i * 8 + j - 1])); + } + printf("\n"); + } + printf("Rg: %08lX | Rd: %08lX | Flag: %08lX | PC: %08lX\n", LireRegistreRG(), LireRegistreRD(), LireRegistreFLAG(), registre[REG_PC]); + printf("\n"); +} - void Debogueur(void) { - AfficheReg();} +void Debogueur(void) +{ + AfficheReg(); +} -- cgit v1.2.3