summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/assembler.c11
-rw-r--r--lib/linker.c3
-rw-r--r--lib/memoire.c28
-rw-r--r--lib/registre.c1
-rw-r--r--lib/simulator.c85
-rw-r--r--lib/terminal.c7
6 files changed, 102 insertions, 33 deletions
diff --git a/lib/assembler.c b/lib/assembler.c
index 3fda135..edf6aed 100644
--- a/lib/assembler.c
+++ b/lib/assembler.c
@@ -1456,6 +1456,7 @@ void asm_eol(void)
int i;
char trouve;
_TableauVariable it;
+ bytestream_t * pi;
switch (special) {
case 2: /* Cas de #define */
@@ -1576,6 +1577,8 @@ void asm_eol(void)
/* Operation cruciale: nous avons l'instruction qui correspond le mieux à notre
expression, on va tenter de l'évaluer */
+
+ pi = pushuninit(1);
Initialise(&it);
for (i = 0; i < instr->nbexplicit; i++) {
@@ -1669,8 +1672,8 @@ void asm_eol(void)
break;
}
}
-
- pushdword(evaluate_field(it, "FI", fields), NULL);
+
+ pi->Encoded = evaluate_field(it, "FI", fields);
DetruitTab(&it);
break;
default:
@@ -1691,6 +1694,8 @@ void asm_eol(void)
static void writeword(unsigned long int a, FILE * f, int n)
{
int i;
+
+ fprintf(stderr, "ÉCriture de %08lX sur %i\n", a, fileno(f));
if (fwrite(&a, sizeof(unsigned long int), 1, f) != 1) {
if (ferror(f)) {
@@ -1787,6 +1792,7 @@ void asm_eof(FILE * f)
for (ttext = ttext->next; ttext; ttext = ttext->next) {
sprintf(errctx, _("Processing word number %i coming from line %i of the file %s."), ttext->offset,
ttext->line, ttext->filename);
+ fprintf(stderr, "%s\n", errctx);
pushcontext(errctx);
a = 0;
@@ -1905,6 +1911,7 @@ void asm_eof(FILE * f)
for (tdata = tdata->next; tdata; tdata = tdata->next) {
sprintf(errctx, _("Processing word number %i coming from line %i of the file %s."), tdata->offset,
tdata->line, tdata->filename);
+ fprintf(stderr, "%s\n", errctx);
pushcontext(errctx);
a = 0;
diff --git a/lib/linker.c b/lib/linker.c
index b6930e3..0228a9f 100644
--- a/lib/linker.c
+++ b/lib/linker.c
@@ -138,7 +138,7 @@ void addfile(char *nom)
if ((startpoint != -1) && (start != -1)) {
exception(1, _("Startpoint already defined."));
}
- startpoint = start;
+ startpoint = start + textsize;
objects[objindex]->s_text = readword(f);
objects[objindex]->s_data = readword(f);
@@ -284,6 +284,7 @@ void dumpfile(char *nom)
pushcontext(_("Writing headers"));
writeword(0x58454e4e, f);
writeword(nbrsymbs + textsize + datasize + 7, f);
+ writeword(startpoint, f);
writeword(textsize, f);
writeword(datasize, f);
writeword(bsssize, f);
diff --git a/lib/memoire.c b/lib/memoire.c
index 48daf0e..eb6dadc 100644
--- a/lib/memoire.c
+++ b/lib/memoire.c
@@ -1,3 +1,5 @@
+#include <stdio.h>
+#include <stdlib.h>
#include "memoire.h"
#include "interne.h"
#include "simulator.h"
@@ -20,6 +22,15 @@ Uint32 * memoire_principale;
/** **/
/*****************************************/
+
+void InitMemoire(void) {
+ memoire_principale = (Uint32 *) Emalloc(TAILLE_MEMOIRE * sizeof(Uint32));
+}
+
+void FreeMemoire(void) {
+ free(memoire_principale);
+}
+
/* Lit le mot qui se trouve à l'offset 'offset' en mémoire */
Uint32 LD(Uint32 offset)
{
@@ -27,24 +38,27 @@ Uint32 LD(Uint32 offset)
switch (offset) {
case 0xffffff00:
- return (!feof(stdin));
+ initterm();
+ i = !feof(input);
+ clearterm();
+ return (i);
case 0xffffff01:
- return (fgetc(stdin));
- case 0xffffff05:
+ initterm();
+ i = fgetc(input);
clearterm();
+ break;
+ case 0xffffff05:
fscanf(input, "%i", &i);
- initterm();
- return i;
+ break;
default:
if (offset >= TAILLE_MEMOIRE) {
exception(1, _("Invalid Memory Adress"));
- return (i);
} else {
i = memoire_principale[offset];
- return (i);
}
break;
}
+ return i;
}
static void copychaine(Uint32 * t, char * s) {
diff --git a/lib/registre.c b/lib/registre.c
index 2d88d45..a11a88c 100644
--- a/lib/registre.c
+++ b/lib/registre.c
@@ -8,6 +8,7 @@
#define _(x) x
#endif
+Uint32 registre[64];
/*****************************************/
/** **/
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;
}
+
diff --git a/lib/terminal.c b/lib/terminal.c
index df3e61d..ace1302 100644
--- a/lib/terminal.c
+++ b/lib/terminal.c
@@ -4,11 +4,12 @@
#include <termios.h>
#include <string.h>
#include "config.h"
+#include "exceptions.h"
FILE *input;
struct termios initial_settings, new_settings;
-void initterm() {
+void initterm(void) {
tcgetattr(fileno(input), &initial_settings);
new_settings = initial_settings;
new_settings.c_lflag &= ~ICANON;
@@ -23,11 +24,11 @@ void initterm() {
}
-void clearterm() {
+void clearterm(void) {
tcsetattr(fileno(input), TCSANOW, &initial_settings);
}
-void openterm() {
+void openterm(void) {
if (!(input = fopen("/dev/tty", "r"))) {
exception(1, _("could not open terminal"));
}