diff options
Diffstat (limited to 'lib/simulator.c')
-rw-r--r-- | lib/simulator.c | 85 |
1 files changed, 65 insertions, 20 deletions
diff --git a/lib/simulator.c b/lib/simulator.c index d542a07..9a859f4 100644 --- a/lib/simulator.c +++ b/lib/simulator.c @@ -1,4 +1,7 @@ #include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> #ifdef HAVE_CONFIG_H #include "config.h" @@ -30,6 +33,27 @@ void IncrementeCompteurOrdinal(void) EcrireRegistrePC(AdditionNonSigne(LireRegistrePC(), 1)); } +static FILE *openfilereading(char *name) +{ + FILE *f; + + if (!(f = fopen(name, "rb"))) { + pushcontext(strerror(errno)); + exception(1, _("Error reading file")); + } + return f; +} + +static Uint32 readword(FILE * f) +{ + Uint32 a; + + if (fread(&a, sizeof(a), 1, f) != 1) { + exception(1, _("premature end of file")); + } + return a; +} + Uint32 Adresse(Uint32 u, Uint32 instruction) { Uint32 tmp; @@ -58,6 +82,8 @@ Uint32 Adresse(Uint32 u, Uint32 instruction) void Initialisation(void) { int i; + + InitMemoire(); for (i = 0; i < TAILLE_MEMOIRE; i++) Reset(&memoire_principale[i]); @@ -67,7 +93,7 @@ void Initialisation(void) EcrireRegistreSP(ADD_SP); /* initialisation du stack pointer */ } -void DecodeExec(Uint32 instruction, Uint32 entrypoint) +void DecodeExec(Uint32 instruction) { Uint32 champ_registre_resultat, val1, val2, resultat; int test1, test2; @@ -344,21 +370,6 @@ void DecodeExec(Uint32 instruction, Uint32 entrypoint) } } } -void Traitement(Uint32 entrypoint) -{ /* ******************** FIXMI ************************* */ - Uint32 instruction; - - while (HasToRun) { - EcrireRegistrePC(entrypoint); - HasToRun = 1; - HasToReset = 0; - while ((HasToRun) && (!HasToReset)) { - instruction = LireInstruction(); - IncrementeCompteurOrdinal(); - DecodeExec(instruction, entrypoint); - } - } -} void AfficheReg(void) // affiche reg { @@ -375,7 +386,7 @@ void AfficheReg(void) // affiche reg fprintf(stderr, "\n"); } fprintf(stderr, "Rg: %08lX | Rd: %08lX | Flag: %08lX | PC: %08lX\n\n", LireRegistreRG(), LireRegistreRD(), - LireRegistreFLAG(), registre[REG_PC]); + LireRegistreFLAG(), LireRegistrePC()); } void Debogueur(void) @@ -384,12 +395,12 @@ void Debogueur(void) while (!out) { AfficheReg(); - printf("%08lX:%08lX > ", LireRegistrePC(), LD(LireRegistrePC())); + fprintf(stderr, "%08lX:%08lX > ", LireRegistrePC(), LD(LireRegistrePC())); switch (fgetc(input)) { case 'G': case 'g': - fprintf(stderr, "Go\n") + fprintf(stderr, "Go\n"); debug = 0; out = 1; break; @@ -401,8 +412,38 @@ void Debogueur(void) case 'R': case 'r': break; + case 'Q': + case 'q': + clearterm(); + exception(1, _("Shutdown requested")); default: - fprintf(stderr, _("Help:\nG: go\nP: Proceed\nR: display registers\n\n"); + fprintf(stderr, _("Help:\nG: go\nP: Proceed\nR: display registers\nQ: quit\n")); + } + } +} + +void Traitement(Uint32 entrypoint) +{ /* ******************** FIXMI ************************* */ + Uint32 instruction; + + fprintf(stderr, "Entrypoint: %08lX\n", entrypoint); + + while (HasToRun) { + EcrireRegistrePC(entrypoint); + HasToRun = 1; + HasToReset = 0; + while ((HasToRun) && (!HasToReset)) { + if (debug) { + initterm(); + Debogueur(); + clearterm(); + } + fprintf(stderr, "Kapoue1\n"); + instruction = LireInstruction(); + fprintf(stderr, "Kapoue2\n"); + IncrementeCompteurOrdinal(); + fprintf(stderr, "Kapoue3\n"); + DecodeExec(instruction); } } } @@ -421,8 +462,11 @@ void ChargeBinaire(char *filename) sprintf(message, _("Loading file %s"), filename); pushcontext(message); + + readword(file); entrypoint = readword(file); /* point d'entrée */ + fprintf(stderr, "Loaded entrypoint: %08lX", entrypoint); nb = readword(file); /* taille du segment text */ ns = readword(file); /* taille des donnes statiques */ nbss = readword(file); /* taille des donnees non init */ @@ -457,3 +501,4 @@ void ChargeBinaire(char *filename) popcontext(); base_addr -= nb + ns + nbss; } + |