summaryrefslogtreecommitdiff
path: root/lib/simulator.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/simulator.c')
-rw-r--r--lib/simulator.c62
1 files changed, 60 insertions, 2 deletions
diff --git a/lib/simulator.c b/lib/simulator.c
index 7dde434..633085f 100644
--- a/lib/simulator.c
+++ b/lib/simulator.c
@@ -13,7 +13,7 @@
#include "memoire.h"
#include "fpu.h"
#include "exceptions.h"
-
+#include "linker.h"
/*
initialisation de la MP avec un malloc
@@ -24,6 +24,9 @@
int HasToRun = 1, HasToReset;
+Uint32 base_addr = 0;
+
+
Uint32 LireInstruction(void)
{
return (LD(LireRegistrePC()));
@@ -65,7 +68,8 @@ void Initialisation(void)
for (i = 0; i < TAILLE_MEMOIRE; i++)
Reset(&memoire_principale[i]);
- EcrireRegistreSP(ADD_SP);
+ InitRegistres(); /* initialisation des registres */
+ EcrireRegistreSP(ADD_SP); /* initialisation du stack pointer */
}
void DecodeExec(Uint32 instruction, Uint32 entrypoint)
@@ -384,3 +388,57 @@ void Debogueur(void)
{
AfficheReg();
}
+
+void ChargeBinaire(char * filename)
+{
+FILE * file;
+char message[BUFSIZ];
+Uint32 entrypoint, nb, ns, nbss, nr;
+Uint32 * relocation_table;
+i int;
+
+file = openfilereading(filename);
+if (readword(file)==0x58454e4e) { /*verification de la signature*/
+sprintf(message,_("Total Size Of The Binary File: %d"),readword(file));
+pushcontext(message);
+nb=readword(file); /* taille du segment text */
+ns=readword(file); /* taille des donnes statiques */
+nbss=readword(file); /* taille des donnees non init */
+nr=readword(file); /* taille de la table de relogement */
+
+relocation_table=Emalloc(nr);
+for (i=0;i<nr;i++) {
+ relocation_table[i]=readword(file);
+}
+
+
+for(i=base_addr;i<(base_addr+nb+ns);i++) { /*chargement en ram de .text et .data */
+ ST(i,readword(file));
+}
+
+for (i=0;i<nr;i++) { /* relogement */
+ ST(base_addr+relocation_table[i],LD(base_addr+relocation_table[i])+base_addr);
+}
+
+free(relocation_table);
+
+InitRegistres(); /* initialisation des registres */
+EcrireRegistreSP(ADD_SP); /* initialisation du stack pointer */
+
+EcrireRegistrePC(LireRegistrePC()+base_addr); /* maj de PC */
+
+
+fclose(file);
+
+
+
+
+
+
+
+}
+
+
+
+
+} \ No newline at end of file