summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/assembler.c114
-rw-r--r--lib/linker.c10
-rw-r--r--lib/simulator.c26
3 files changed, 102 insertions, 48 deletions
diff --git a/lib/assembler.c b/lib/assembler.c
index edf6aed..64eafb9 100644
--- a/lib/assembler.c
+++ b/lib/assembler.c
@@ -1235,6 +1235,8 @@ static instruct_t *e_match_i(phon_t * phons, instruct_t * instructs, expression_
break;
}
}
+
+ debug_print_expression(e);
for (instructs = instructs->next; instructs; instructs = instructs->next) {
t = e;
@@ -1255,22 +1257,22 @@ static instruct_t *e_match_i(phon_t * phons, instruct_t * instructs, expression_
}
break;
case 'C':
- if ((t->e_subtype != E_VALUE) && (t->e_subtype != E_LABEL)
- && (t->e_subtype != E_OPERATION)) {
+ if ((t->e_subtype != E_VALUE) && (t->e_subtype != E_LABEL)) {
go_out = 1;
- if (t->e_subtype == E_OPERATION) {
- if (t->op == OP_FUNC_CALL)
- go_out = 0;
- }
}
- if ((t->e_subtype == E_OPERATION) && (!(((t->child->e_subtype == E_LABEL)
- && (t->child->next->e_subtype ==
- E_VALUE))
- || ((t->child->e_subtype == E_VALUE)
- && (t->child->next->e_subtype ==
- E_LABEL))))) {
- go_out = 1;
+ if ((t->e_subtype == E_OPERATION)
+ && ((t->op == OP_PLUS) || (t->op == OP_MOINS))) {
+ if (((t->child->e_subtype == E_LABEL)
+ && (t->child->next->e_subtype == E_VALUE))
+ || ((t->child->e_subtype == E_VALUE)
+ && (t->child->next->e_subtype == E_LABEL))) {
+ go_out = 0;
+ }
+ }
+
+ if ((t->e_subtype == E_OPERATION) && (t->op == OP_FUNC_CALL)) {
+ go_out = 0;
}
break;
@@ -1292,6 +1294,34 @@ static instruct_t *e_match_i(phon_t * phons, instruct_t * instructs, expression_
}
}
+ if (instructs) {
+ fprintf(stderr, " o Instruction contenant %i champs explicites et %i champs implicites.\n",
+ instructs->nbexplicit, instructs->nbimplicit);
+ fprintf(stderr, " => Champs explicites.\n");
+ for (i = 0; i < instructs->nbexplicit; i++) {
+ fprintf(stderr, " + %s <= %s (type %s)\n",
+ instructs->names[i],
+ instructs->strings[i] ? instructs->strings[i] : "Pas de chaîne associée",
+ instructs->etypes[i] ? "prédéfinit" : "direct");
+ }
+ fprintf(stderr, " => Champs implicites.\n");
+ for (i = 0; i < instructs->nbimplicit; i++) {
+ switch (instructs->itypes[i]) {
+ case 0:
+ fprintf(stderr, " + %s <= %s (type direct)\n", instructs->implicits[i],
+ instructs->istrings[i]);
+ break;
+ case 1:
+ fprintf(stderr, " + %s <= %s (type prédéfinit)\n", instructs->implicits[i],
+ instructs->istrings[i]);
+ break;
+ case 2:
+ fprintf(stderr, " + %s <= %i (type valeur)\n", instructs->implicits[i],
+ instructs->ivalues[i]);
+ break;
+ }
+ }
+ }
return instructs;
}
@@ -1421,7 +1451,6 @@ static int evaluate_field(_TableauVariable it, char *field, field_t * fields)
break;
}
}
-
if (!(fields)) {
exception(1, _("Unknow field in metalanguage"));
}
@@ -1456,7 +1485,7 @@ void asm_eol(void)
int i;
char trouve;
_TableauVariable it;
- bytestream_t * pi;
+ bytestream_t *pi;
switch (special) {
case 2: /* Cas de #define */
@@ -1470,7 +1499,6 @@ void asm_eol(void)
break;
case 0: /* Cas normal */
/* C'est ici la bonne histoire... Il faut reconnaitre l'instruction */
-
e_current = e_line;
if (!(e_current))
break;
@@ -1577,7 +1605,7 @@ 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);
@@ -1672,7 +1700,7 @@ void asm_eol(void)
break;
}
}
-
+
pi->Encoded = evaluate_field(it, "FI", fields);
DetruitTab(&it);
break;
@@ -1694,7 +1722,7 @@ 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) {
@@ -1735,10 +1763,7 @@ static void writestring(char *string, FILE * f)
| | | .| | |
| +---+--+---+ |
| |
-\****************/
-
-/* Cette fonction ajoute un fichier à un autre */
-
+\****************//* Cette fonction ajoute un fichier à un autre */
void appendfile(FILE * f, char *name)
{
unsigned long int a;
@@ -1790,8 +1815,8 @@ void asm_eof(FILE * f)
pushcontext(_("Dumping text segment"));
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);
+ 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);
@@ -1803,6 +1828,7 @@ void asm_eof(FILE * f)
a = ttext->Expr->avalue;
break;
case E_LABEL:
+ fprintf(stderr, "Symbole externe %s\n", ttext->Expr->symbol);
a = ttext->Expr->avalue;
nbsymbols++;
writeword(1, f2, 1);
@@ -1819,7 +1845,9 @@ void asm_eof(FILE * f)
}
}
if (ttext->Expr->op == OP_DECAL) {
- if ((ttext->Expr->child->e_subtype == E_LABEL) && (ttext->Expr->child->next->e_subtype == E_VALUE)) {
+ if ((ttext->Expr->child->e_subtype == E_LABEL)
+ && (ttext->Expr->child->next->e_subtype == E_VALUE)) {
+ fprintf(stderr, "Symbole externe %s\n", ttext->Expr->child->symbol);
a = ttext->Expr->child->next->avalue;
nbsymbols++;
writeword(1, f2, 1);
@@ -1831,8 +1859,13 @@ void asm_eof(FILE * f)
}
}
if (ttext->Expr->op == OP_PLUS) {
- if (((ttext->Expr->child->e_subtype == E_LABEL) && (ttext->Expr->child->next->e_subtype == E_VALUE)) || ((ttext->Expr->child->e_subtype == E_VALUE) && (ttext->Expr->child->next->e_subtype == E_LABEL))) {
+ if (((ttext->Expr->child->e_subtype == E_LABEL)
+ && (ttext->Expr->child->next->e_subtype == E_VALUE))
+ || ((ttext->Expr->child->e_subtype == E_VALUE)
+ && (ttext->Expr->child->next->e_subtype == E_LABEL))) {
if (ttext->Expr->child->e_subtype == E_LABEL) {
+ fprintf(stderr, "Symbole externe %s\n",
+ ttext->Expr->child->symbol);
a = ttext->Expr->child->next->avalue;
nbsymbols++;
writeword(1, f2, 1);
@@ -1841,6 +1874,8 @@ void asm_eof(FILE * f)
writestring(ttext->Expr->child->symbol, f2);
nbe++;
} else {
+ fprintf(stderr, "Symbole externe %s\n",
+ ttext->Expr->child->next->symbol);
a = ttext->Expr->child->avalue;
nbsymbols++;
writeword(1, f2, 1);
@@ -1891,6 +1926,7 @@ void asm_eof(FILE * f)
} else {
if (ttext->Label) {
nbsymbols++;
+ fprintf(stderr, "Symbole interne %s\n", ttext->Label);
writeword(0, f2, 1);
writeword(ttext->offset, f2, 1);
if (ttext->Label[strlen(ttext->Label) - 1] == ':') {
@@ -1909,8 +1945,8 @@ void asm_eof(FILE * f)
pushcontext(_("Dumping data segment"));
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);
+ 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);
@@ -1923,9 +1959,10 @@ void asm_eof(FILE * f)
break;
case E_LABEL:
a = tdata->Expr->avalue;
+ fprintf(stderr, "Symbole externe %s\n", tdata->Expr->child->symbol);
nbsymbols++;
writeword(3, f2, 1);
- writeword(tdata->offset + s_text, f2, 1);
+ writeword(tdata->offset, f2, 1);
writeword(strlen(tdata->Expr->symbol), f2, 1);
writestring(tdata->Expr->symbol, f2);
nbe++;
@@ -1970,8 +2007,9 @@ void asm_eof(FILE * f)
} else {
if (tdata->Label) {
nbsymbols++;
+ fprintf(stderr, "Symbole interne %s\n", tdata->Label);
writeword(2, f2, 1);
- writeword(tdata->offset + s_text, f2, 1);
+ writeword(tdata->offset, f2, 1);
writeword(strlen(tdata->Label), f2, 1);
writestring(tdata->Label, f2);
nbi++;
@@ -1987,15 +2025,16 @@ void asm_eof(FILE * f)
pushcontext(_("Dumping bss segment"));
for (tbss = tbss->next; tbss; tbss = tbss->next) {
- sprintf(errctx, _("Processing word number %i coming from line %i of the file %s."), tbss->offset,
- tbss->line, tbss->filename);
+ sprintf(errctx, _("Processing word number %i coming from line %i of the file %s."),
+ tbss->offset, tbss->line, tbss->filename);
pushcontext(errctx);
if (!tbss->size) {
if (tbss->Label) {
nbsymbols++;
writeword(4, f2, 1);
- writeword(tbss->offset + s_text + s_data, f2, 1);
+ fprintf(stderr, "Symbole interne %s\n", tbss->Label);
+ writeword(tbss->offset, f2, 1);
writeword(strlen(tbss->Label), f2, 1);
writestring(tbss->Label, f2);
nbi++;
@@ -2054,10 +2093,7 @@ void assembler_flush(void)
delete_bytestream(data);
delete_bytestream(bss);
}
-
-/* Fonction générique qui va traiter un fichier entier */
-
-static int process_file(char *name)
+/* Fonction générique qui va traiter un fichier entier */ static int process_file(char *name)
{
FILE *f;
char buf[BUFSIZ], errctx[BUFSIZ], *p;
@@ -2072,6 +2108,7 @@ static int process_file(char *name)
return 1;
}
popcontext();
+
pushcontext(_("Reading file"));
while (fgets(buf, BUFSIZ, f)) {
sprintf(errctx, _("Reading line %i"), line = ++i);
@@ -2109,6 +2146,7 @@ void assemble_file(char *iname, char *oname)
exception(1, _("Error writing output file"));
}
popcontext();
+
if (process_file(iname)) {
exception(1, _("Error reading file"));
}
diff --git a/lib/linker.c b/lib/linker.c
index 0228a9f..0be4cfc 100644
--- a/lib/linker.c
+++ b/lib/linker.c
@@ -98,7 +98,7 @@ static char *readstring(FILE * f)
static void addsymbol(char *name, int offset, int type)
{
symbol_t *newsymbol;
-
+
newsymbol = (symbol_t *) Emalloc(sizeof(symbol_t));
newsymbol->next = NULL;
newsymbol->type = type;
@@ -210,6 +210,7 @@ static void dumprelog(FILE * f)
{
symbol_t *s = symbols, *t;
char trouve, err[BUFSIZ];
+ Uint32 decal;
for (s = s->next; s; s = s->next) {
if (s->type & 1) {
@@ -222,21 +223,22 @@ static void dumprelog(FILE * f)
case 1: /* text */
switch (t->type) {
case 0:
- objects[s->objindex]->text[s->offset] +=
+ decal =
objects[t->objindex]->textstart + t->offset;
break;
case 2:
- objects[s->objindex]->text[s->offset] +=
+ decal =
textsize + objects[t->objindex]->datastart + t->offset;
break;
case 4:
- objects[s->objindex]->text[s->offset] +=
+ decal =
textsize + datasize + objects[t->objindex]->bssstart + t->offset;
break;
default:
exception(1, _("Internal error"));
break;
}
+ objects[s->objindex]->text[s->offset] += decal;
writeword(objects[s->objindex]->textstart + s->offset, f);
break;
case 3: /* data */
diff --git a/lib/simulator.c b/lib/simulator.c
index 9a859f4..802587b 100644
--- a/lib/simulator.c
+++ b/lib/simulator.c
@@ -98,8 +98,10 @@ void DecodeExec(Uint32 instruction)
Uint32 champ_registre_resultat, val1, val2, resultat;
int test1, test2;
Uint32 val; /* valeur qui va etre stockée */
-
+
+
if (Opcode(instruction) & 0x80) {
+ fprintf(stderr, "Opcode FPU\n");
fpu(Opcode(instruction));
} else {
switch (Opcode(instruction)) {
@@ -111,6 +113,7 @@ 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 */
@@ -185,6 +188,7 @@ 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 */
@@ -220,28 +224,38 @@ 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());
IncrementeCompteurOrdinal();
}
}
} else {
+ fprintf(stderr, "MOV arg2, arg1\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(Champ2(instruction), LireRegistre(Champ3(instruction)));
-
} else {
+ fprintf(stderr, "arg1 = addresse\n");
EcrireRegistre(Champ2(instruction),
LD(Adresse(Champ1(instruction), instruction)));
}
@@ -392,10 +406,13 @@ void AfficheReg(void) // affiche reg
void Debogueur(void)
{
int out = 0;
+
+ Uint32 instruction = LireInstruction();
while (!out) {
AfficheReg();
- fprintf(stderr, "%08lX:%08lX > ", LireRegistrePC(), LD(LireRegistrePC()));
+ fprintf(stderr, "Opcode: %02X, extension: %02X, champ1: %02X, champ2: %02X, champ3: %02X\n", Opcode(instruction), Extension(instruction), Champ1(instruction), Champ2(instruction), Champ3(instruction));
+ fprintf(stderr, "%08lX:%08lX > ", LireRegistrePC(), instruction);
switch (fgetc(input)) {
case 'G':
@@ -438,11 +455,8 @@ void Traitement(Uint32 entrypoint)
Debogueur();
clearterm();
}
- fprintf(stderr, "Kapoue1\n");
instruction = LireInstruction();
- fprintf(stderr, "Kapoue2\n");
IncrementeCompteurOrdinal();
- fprintf(stderr, "Kapoue3\n");
DecodeExec(instruction);
}
}