summaryrefslogtreecommitdiff
path: root/lib/simulator.c
diff options
context:
space:
mode:
authorbiouman <>2001-04-16 14:08:26 +0000
committerbiouman <>2001-04-16 14:08:26 +0000
commit27f796ab6a9f455bbd2a1c85088db5304cece75a (patch)
tree6b24b5ae3e9873ecf623045083f06890a1f74201 /lib/simulator.c
parentc3fd2994a3efec4aacf62fd7b0d092eec0c12236 (diff)
*** empty log message ***
Diffstat (limited to 'lib/simulator.c')
-rw-r--r--lib/simulator.c300
1 files changed, 180 insertions, 120 deletions
diff --git a/lib/simulator.c b/lib/simulator.c
index d1e5c7f..4373d0d 100644
--- a/lib/simulator.c
+++ b/lib/simulator.c
@@ -17,7 +17,6 @@
-// a modifier : Adresse switch 0 c faux
// CALL RET ???
// verifier le reste
@@ -37,32 +36,39 @@ void IncrementeCompteurOrdinal(void)
Uint32 Adresse(Uint32 u, Uint32 instruction)
{
+ Uint32 tmp;
+
switch (champ(u, 2)) {
case 0:
- return (LireRegistre(Champ3(instruction))); /* directement registre A CORRIGER */
+ exception(1, _("Adresse: Call With Invalid r/m Field State ( r/m=00 )"));
+ return(0);
case 1:
+ tmp = LireInstruction();
IncrementeCompteurOrdinal();
- return (LireInstruction());
+ return (tmp);
case 2:
return (LireRegistre(Champ3(instruction))); /* Adresse dans registre */
case 3:
+ tmp = LireRegistre(Champ3(instruction)) + LireInstruction(); /* Adresse dans registre + decalage de nouvelle instruction */
IncrementeCompteurOrdinal();
- return (LireRegistre(Champ3(instruction)) + LireInstruction()); /* Adresse dans registre + decalage de nouvelle instruction */
+ return (tmp);
default:
exception(1, _("Adresse: Unmatched Addr Field"));
+ return(0);
}
}
+
void Initialisation(void)
{
int i;
for (i = 0; i < TAILLE_MEMOIRE; i++)
Reset(&memoire_principale[i]);
- EcrireRegistrePP(ADD_PP);
+ EcrireRegistreSP(ADD_SP);
}
-void Decode(Uint32 instruction)
+void DecodeExec(Uint32 instruction, Uint32 entrypoint)
{
Uint32 champ_registre_resultat, val1, val2, resultat;
@@ -77,8 +83,8 @@ void Decode(Uint32 instruction)
if (ValeurBit(Extension(instruction), 0) == 0)
val2 = LireRegistre(Champ3(instruction)); /* Deuxième entier, stocké dans un registre, qui va etre utilisé dans l'opération */
else {
- IncrementeCompteurOrdinal();
val2 = LireInstruction(); /* Deuxième entier, stocké après l'instruction, qui va etre utilisé dans l'opération */
+ IncrementeCompteurOrdinal();
}
if (ValeurBit(Extension(instruction), 1) == 0) /* Teste si l'opération est signée ou pas */
switch (Opcode(instruction)) {
@@ -152,7 +158,7 @@ void Decode(Uint32 instruction)
case 3:
if (Parity() == 1)
goto fin;
- }
+ }
} else { /* Negation du test */
switch (champ(Extension(instruction) >> 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();
+}