diff options
Diffstat (limited to 'lib/simulator.c')
-rw-r--r-- | lib/simulator.c | 39 |
1 files changed, 14 insertions, 25 deletions
diff --git a/lib/simulator.c b/lib/simulator.c index 802587b..16cc2ef 100644 --- a/lib/simulator.c +++ b/lib/simulator.c @@ -57,8 +57,8 @@ static Uint32 readword(FILE * f) Uint32 Adresse(Uint32 u, Uint32 instruction) { Uint32 tmp; - - switch (champ(u, 2)) { + + switch (champ(u, 4)) { case 0: exception(1, _("Adresse: Call With Invalid r/m Field State ( r/m=00 )")); return (0); @@ -101,7 +101,6 @@ void DecodeExec(Uint32 instruction) if (Opcode(instruction) & 0x80) { - fprintf(stderr, "Opcode FPU\n"); fpu(Opcode(instruction)); } else { switch (Opcode(instruction)) { @@ -113,7 +112,6 @@ void DecodeExec(Uint32 instruction) case 5: case 6: case 7: - fprintf(stderr, "Opcode ALU\n"); /* ALU */ champ_registre_resultat = Champ1(instruction); /* Champ du registre dans lequel va etre stocké le résultat */ val1 = LireRegistre(Champ2(instruction)); /* Premier entier qui va etre utilisé dans l'opération */ @@ -188,7 +186,6 @@ void DecodeExec(Uint32 instruction) } break; case 8: /* MOV */ - fprintf(stderr, "Opcode MOV\n"); if (ValeurBit(Extension(instruction), 4) == 1) { /* MOV conditionnel */ if (ValeurBit(Extension(instruction), 5) == 0) { /* Test normal */ switch (champ(Extension(instruction) >> 2, 4)) { /* teste les bits 2 et 3 */ @@ -224,38 +221,28 @@ void DecodeExec(Uint32 instruction) } /* Pas de MOV conditionnel */ if (ValeurBit(Extension(instruction), 1) == 0) { /* Mov arg1 arg2 */ - fprintf(stderr, "MOV arg1, arg2\n"); if (ValeurBit(Extension(instruction), 0) == 0) { /* arg2 = reg */ - fprintf(stderr, "arg2 = reg (%i)\n", Champ2(instruction)); if (champ(Champ1(instruction), 2) == 0) { /* r/m de arg1 = 0 */ - fprintf(stderr, "arg1 = reg (%i)\n", Champ3(instruction)); EcrireRegistre(Champ3(instruction), LireRegistre(Champ2(instruction))); } else { - fprintf(stderr, "arg1 = adresse\n"); ST(Adresse(Champ1(instruction), instruction), LireRegistre(Champ2(instruction))); } } else { /* arg2 = imm32 */ - fprintf(stderr, "arg2 = imm (%i)\n", LireInstruction()); if (champ(Champ1(instruction), 2) == 0) { /* r/m de arg1 = 0 */ - fprintf(stderr, "arg1 = reg (%i)\n", Champ3(instruction)); EcrireRegistre(Champ3(instruction), LireInstruction()); IncrementeCompteurOrdinal(); } else { - fprintf(stderr, "arg1 = adresse\n"); - ST(Adresse(Champ1(instruction), instruction), LireInstruction()); + val = Adresse(Champ1(instruction), instruction); + ST(val, LireInstruction()); IncrementeCompteurOrdinal(); } } - } else { - fprintf(stderr, "MOV arg2, arg1\n"); + } else { /* mov arg2, arg1 */ if (ValeurBit(Extension(instruction), 0) == 0) { /* arg2 = reg */ - fprintf(stderr, "arg2 = reg (%i)\n", Champ2(instruction)); if (champ(Champ1(instruction), 2) == 0) { /* r/m de arg1 = 0 */ - fprintf(stderr, "arg1 = reg (%i)\n", Champ3(instruction)); EcrireRegistre(Champ2(instruction), LireRegistre(Champ3(instruction))); } else { - fprintf(stderr, "arg1 = addresse\n"); EcrireRegistre(Champ2(instruction), LD(Adresse(Champ1(instruction), instruction))); } @@ -328,6 +315,8 @@ void DecodeExec(Uint32 instruction) tmp += LireRegistrePC(); } EcrireRegistrePC(tmp); + } else { + IncrementeCompteurOrdinal(); } break; @@ -372,7 +361,7 @@ void DecodeExec(Uint32 instruction) break; case 127: /* HALT-RESET */ - if (ValeurBit(Extension(instruction), 0)) { + if (ValeurBit(Extension(instruction), 0) == 0) { HasToRun = 0; /* Halt */ } else { HasToReset = 1; /* Reset */ @@ -390,16 +379,16 @@ void AfficheReg(void) // affiche reg int i, j; for (i = 0; i <= 3; i++) { - for (j = 1; j <= 8; j++) { + for (j = 0; j < 8; j++) { fprintf(stderr, " R%02d ", (i * 8 + j)); } fprintf(stderr, "\n"); - for (j = 1; j <= 8; j++) { - fprintf(stderr, "%08lX ", (registre[i * 8 + j - 1])); + for (j = 0; j < 8; j++) { + fprintf(stderr, "%08lX ", (registre[i * 8 + j])); } fprintf(stderr, "\n"); } - fprintf(stderr, "Rg: %08lX | Rd: %08lX | Flag: %08lX | PC: %08lX\n\n", LireRegistreRG(), LireRegistreRD(), + fprintf(stderr, "Rg: %08lX | Rd: %08lX | Flag: %08lX | PC: %08lX\n", LireRegistreRG(), LireRegistreRD(), LireRegistreFLAG(), LireRegistrePC()); } @@ -417,13 +406,13 @@ void Debogueur(void) switch (fgetc(input)) { case 'G': case 'g': - fprintf(stderr, "Go\n"); + fprintf(stderr, "Go\n\n"); debug = 0; out = 1; break; case 'p': case 'P': - fprintf(stderr, "Proceed\n"); + fprintf(stderr, "Proceed\n\n"); out = 1; break; case 'R': |