summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPixel <>2001-04-17 00:46:47 +0000
committerPixel <>2001-04-17 00:46:47 +0000
commit4f2aa7d436bb50cef3f9a551f79fa03ea275ab77 (patch)
tree51984db4e75ce1ac8e1bfe6f079938a54e056bad
parentd3050fa05ca0bc9231eca96bcbf62d1ec60c9f90 (diff)
POUEEEEEEEEEEEEEET
-rw-r--r--lib/alu.c68
-rw-r--r--lib/assembler.c56
-rw-r--r--lib/linker.c25
-rw-r--r--lib/memoire.c22
-rw-r--r--lib/meta.c12
-rw-r--r--lib/simulator.c34
-rw-r--r--lib/terminal.c9
-rw-r--r--src/simul.c1
8 files changed, 145 insertions, 82 deletions
diff --git a/lib/alu.c b/lib/alu.c
index e90b0cc..4047b72 100644
--- a/lib/alu.c
+++ b/lib/alu.c
@@ -211,11 +211,13 @@ Uint32 NSHRi(Uint32 x, int i)
return (x >> i);
}
-Uint32 NSHL(Uint32 x) {
+Uint32 NSHL(Uint32 x)
+{
return NSHLi(x, 1);
}
-Uint32 NSHR(Uint32 x) {
+Uint32 NSHR(Uint32 x)
+{
return NSHRi(x, 1);
}
@@ -638,37 +640,63 @@ couple MultipliSig(Uint32 x, Uint32 y)
return (z);
}
-Uint32 NMultiplactionNonSigne(Uint32 a, Uint32 b) {
+Uint32 NMultiplactionNonSigne(Uint32 a, Uint32 b)
+{
couple z;
-
+
z = MultipliNonSig(a, b);
-
+
SecondResult = z.deb;
return z.fin;
}
-Uint32 NMultiplactionSigne(Uint32 a, Uint32 b) {
+Uint32 NMultiplactionSigne(Uint32 a, Uint32 b)
+{
couple z;
-
+
z = MultipliNonSig(a, b);
-
+
SecondResult = z.deb;
return z.fin;
}
#else
-Uint32 NAdditionNonSigne(Uint32 a, Uint32 b) {}
-Uint32 NAdditionSigne(Uint32 a, Uint32 b) {}
-Uint32 NSoustractionNonSigne(Uint32 a, Uint32 b) {}
-Uint32 NSoustractionSigne(Uint32 a, Uint32 b) {}
-Uint32 NMultiplicationNonSigne(Uint32 a, Uint32 b) {}
-Uint32 NMultiplicationSigne(Uint32 a, Uint32 b) {}
-Uint32 NDivisionNonSigne(Uint32 a, Uint32 b) {}
-Uint32 NDivisionSigne(Uint32 a, Uint32 b) {}
-Uint32 NAND(Uint32 a, Uint32 b) {}
-Uint32 NOR(Uint32 a, Uint32 b) {}
-Uint32 NSHR(Uint32 a) {}
-Uint32 NSHL(Uint32 a) {}
+Uint32 NAdditionNonSigne(Uint32 a, Uint32 b)
+{
+}
+Uint32 NAdditionSigne(Uint32 a, Uint32 b)
+{
+}
+Uint32 NSoustractionNonSigne(Uint32 a, Uint32 b)
+{
+}
+Uint32 NSoustractionSigne(Uint32 a, Uint32 b)
+{
+}
+Uint32 NMultiplicationNonSigne(Uint32 a, Uint32 b)
+{
+}
+Uint32 NMultiplicationSigne(Uint32 a, Uint32 b)
+{
+}
+Uint32 NDivisionNonSigne(Uint32 a, Uint32 b)
+{
+}
+Uint32 NDivisionSigne(Uint32 a, Uint32 b)
+{
+}
+Uint32 NAND(Uint32 a, Uint32 b)
+{
+}
+Uint32 NOR(Uint32 a, Uint32 b)
+{
+}
+Uint32 NSHR(Uint32 a)
+{
+}
+Uint32 NSHL(Uint32 a)
+{
+}
#endif
Uint32 AdditionNonSigne(Uint32 a, Uint32 b)
diff --git a/lib/assembler.c b/lib/assembler.c
index 8e9452e..043b28f 100644
--- a/lib/assembler.c
+++ b/lib/assembler.c
@@ -1235,9 +1235,10 @@ static instruct_t *e_match_i(phon_t * phons, instruct_t * instructs, expression_
break;
}
}
-
- debug_print_expression(e);
+#ifdef DEBUG
+ debug_print_expression(e);
+#endif
for (instructs = instructs->next; instructs; instructs = instructs->next) {
t = e;
go_out = 0;
@@ -1264,13 +1265,13 @@ static instruct_t *e_match_i(phon_t * phons, instruct_t * instructs, expression_
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))) {
+ && (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;
}
@@ -1293,7 +1294,7 @@ static instruct_t *e_match_i(phon_t * phons, instruct_t * instructs, expression_
break;
}
}
-
+#ifdef DEBUG
if (instructs) {
fprintf(stderr, " o Instruction contenant %i champs explicites et %i champs implicites.\n",
instructs->nbexplicit, instructs->nbimplicit);
@@ -1322,6 +1323,7 @@ static instruct_t *e_match_i(phon_t * phons, instruct_t * instructs, expression_
}
}
}
+#endif
return instructs;
}
@@ -1650,7 +1652,10 @@ void asm_eol(void)
t->pattern = NULL;
t->symbol = NULL;
InsererVarDansTab(&it, CreerElement(instr->names[i], t));
- fprintf(stderr, "On a %s qui vaut %i\n", instr->names[i], e_current->index);
+#ifdef DEBUG
+ fprintf(stderr, "On a %s qui vaut %i\n", instr->names[i],
+ e_current->index);
+#endif
evaluate_pattern(&it, e_current);
break;
default:
@@ -1676,7 +1681,9 @@ void asm_eol(void)
t->pattern = NULL;
t->symbol = NULL;
}
- fprintf(stderr, "On a %s qui vaut %i\n", instr->implicits[i], t->avalue);
+#ifdef DEBUG
+ fprintf(stderr, "On a %s qui vaut %i\n", instr->implicits[i], t->avalue);
+#endif
InsererVarDansTab(&it, CreerElement(instr->implicits[i], t));
break;
case 1: /* type prédéfinit */
@@ -1689,7 +1696,9 @@ void asm_eol(void)
t->child = t->next = NULL;
t->pattern = NULL;
t->symbol = NULL;
- fprintf(stderr, "On a %s qui vaut %i\n", instr->implicits[i], t->avalue);
+#ifdef DEBUG
+ fprintf(stderr, "On a %s qui vaut %i\n", instr->implicits[i], t->avalue);
+#endif
InsererVarDansTab(&it, CreerElement(instr->implicits[i], t));
break;
case 2: /* type valeur */
@@ -1699,7 +1708,9 @@ void asm_eol(void)
t->child = t->next = NULL;
t->pattern = NULL;
t->symbol = NULL;
- fprintf(stderr, "On a %s qui vaut %i\n", instr->implicits[i], t->avalue);
+#ifdef DEBUG
+ fprintf(stderr, "On a %s qui vaut %i\n", instr->implicits[i], t->avalue);
+#endif
InsererVarDansTab(&it, CreerElement(instr->implicits[i], t));
break;
}
@@ -1727,8 +1738,9 @@ static void writeword(unsigned long int a, FILE * f, int n)
{
int i;
+#ifdef DEBUG
fprintf(stderr, "ÉCriture de %08lX sur %i\n", a, fileno(f));
-
+#endif
if (fwrite(&a, sizeof(unsigned long int), 1, f) != 1) {
if (ferror(f)) {
pushcontext(strerror(errno));
@@ -1821,7 +1833,9 @@ 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);
+#ifdef DEBUG
fprintf(stderr, "%s\n", errctx);
+#endif
pushcontext(errctx);
a = 0;
@@ -1832,7 +1846,9 @@ void asm_eof(FILE * f)
a = ttext->Expr->avalue;
break;
case E_LABEL:
+#ifdef DEBUG
fprintf(stderr, "Symbole externe %s\n", ttext->Expr->symbol);
+#endif
a = ttext->Expr->avalue;
nbsymbols++;
writeword(1, f2, 1);
@@ -1851,7 +1867,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)) {
+#ifdef DEBUG
fprintf(stderr, "Symbole externe %s\n", ttext->Expr->child->symbol);
+#endif
a = ttext->Expr->child->next->avalue;
nbsymbols++;
writeword(1, f2, 1);
@@ -1868,8 +1886,10 @@ void asm_eof(FILE * f)
|| ((ttext->Expr->child->e_subtype == E_VALUE)
&& (ttext->Expr->child->next->e_subtype == E_LABEL))) {
if (ttext->Expr->child->e_subtype == E_LABEL) {
+#ifdef DEBUG
fprintf(stderr, "Symbole externe %s\n",
ttext->Expr->child->symbol);
+#endif
a = ttext->Expr->child->next->avalue;
nbsymbols++;
writeword(1, f2, 1);
@@ -1878,8 +1898,10 @@ void asm_eof(FILE * f)
writestring(ttext->Expr->child->symbol, f2);
nbe++;
} else {
+#ifdef DEBUG
fprintf(stderr, "Symbole externe %s\n",
ttext->Expr->child->next->symbol);
+#endif
a = ttext->Expr->child->avalue;
nbsymbols++;
writeword(1, f2, 1);
@@ -1930,7 +1952,9 @@ void asm_eof(FILE * f)
} else {
if (ttext->Label) {
nbsymbols++;
+#ifdef DEBUG
fprintf(stderr, "Symbole interne %s\n", ttext->Label);
+#endif
writeword(0, f2, 1);
writeword(ttext->offset, f2, 1);
if (ttext->Label[strlen(ttext->Label) - 1] == ':') {
@@ -1951,7 +1975,9 @@ 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);
+#ifdef DEBUG
fprintf(stderr, "%s\n", errctx);
+#endif
pushcontext(errctx);
a = 0;
@@ -1963,7 +1989,9 @@ void asm_eof(FILE * f)
break;
case E_LABEL:
a = tdata->Expr->avalue;
+#ifdef DEBUG
fprintf(stderr, "Symbole externe %s\n", tdata->Expr->child->symbol);
+#endif
nbsymbols++;
writeword(3, f2, 1);
writeword(tdata->offset, f2, 1);
@@ -2011,7 +2039,9 @@ void asm_eof(FILE * f)
} else {
if (tdata->Label) {
nbsymbols++;
+#ifdef DEBUG
fprintf(stderr, "Symbole interne %s\n", tdata->Label);
+#endif
writeword(2, f2, 1);
writeword(tdata->offset, f2, 1);
writeword(strlen(tdata->Label), f2, 1);
@@ -2037,7 +2067,9 @@ void asm_eof(FILE * f)
if (tbss->Label) {
nbsymbols++;
writeword(4, f2, 1);
+#ifdef DEBUG
fprintf(stderr, "Symbole interne %s\n", tbss->Label);
+#endif
writeword(tbss->offset, f2, 1);
writeword(strlen(tbss->Label), f2, 1);
writestring(tbss->Label, f2);
diff --git a/lib/linker.c b/lib/linker.c
index 81fc507..0460d41 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;
@@ -223,38 +223,35 @@ static void dumprelog(FILE * f)
case 1: /* text */
switch (t->type) {
case 0:
- decal =
- objects[t->objindex]->textstart + t->offset;
+ decal = objects[t->objindex]->textstart + t->offset;
break;
case 2:
- decal =
- textsize + objects[t->objindex]->datastart + t->offset;
+ decal = textsize + objects[t->objindex]->datastart + t->offset;
break;
case 4:
- decal =
- textsize + datasize + objects[t->objindex]->bssstart + t->offset;
+ decal = textsize + datasize + objects[t->objindex]->bssstart + t->offset;
break;
default:
exception(1, _("Internal error"));
break;
}
- fprintf(stderr, "Relogement effectué sur %i, de %i octets pour le symbole %s\n", s->offset, decal, s->name);
+#ifdef DEBUG
+ fprintf(stderr, "Relogement effectué sur %i, de %i octets pour le symbole %s\n",
+ s->offset, decal, s->name);
+#endif
objects[s->objindex]->text[s->offset] += decal;
writeword(objects[s->objindex]->textstart + s->offset, f);
break;
case 3: /* data */
switch (t->type) {
case 0:
- decal =
- objects[t->objindex]->textstart + t->offset;
+ decal = objects[t->objindex]->textstart + t->offset;
break;
case 2:
- decal =
- textsize + objects[t->objindex]->datastart + t->offset;
+ decal = textsize + objects[t->objindex]->datastart + t->offset;
break;
case 4:
- decal =
- textsize + datasize + objects[t->objindex]->bssstart + t->offset;
+ decal = textsize + datasize + objects[t->objindex]->bssstart + t->offset;
break;
default:
exception(1, _("Internal error"));
diff --git a/lib/memoire.c b/lib/memoire.c
index 264009c..ae79d18 100644
--- a/lib/memoire.c
+++ b/lib/memoire.c
@@ -13,7 +13,7 @@
char temp[BUFSIZ];
-Uint32 * memoire_principale;
+Uint32 *memoire_principale;
/*****************************************/
@@ -23,11 +23,13 @@ Uint32 * memoire_principale;
/*****************************************/
-void InitMemoire(void) {
+void InitMemoire(void)
+{
memoire_principale = (Uint32 *) Emalloc(TAILLE_MEMOIRE * sizeof(Uint32));
}
-void FreeMemoire(void) {
+void FreeMemoire(void)
+{
free(memoire_principale);
}
@@ -35,7 +37,7 @@ void FreeMemoire(void) {
Uint32 LD(Uint32 offset)
{
Uint32 i;
-
+
switch (offset) {
case 0xffffff00:
initterm();
@@ -61,25 +63,29 @@ Uint32 LD(Uint32 offset)
return i;
}
-static void copychaine(Uint32 * t, char * s) {
+static void copychaine(Uint32 * t, char *s)
+{
while (*s) {
*(t++) = *(s++);
}
}
-static void litchaine(char * s, Uint32 * t) {
+static void litchaine(char *s, Uint32 * t)
+{
while (*t) {
*(s++) = *(t++);
}
}
-static void Affiche(Uint32 * t) {
+static void Affiche(Uint32 * t)
+{
while (*t) {
fprintf(stdout, "%c", (*t++));
}
}
-static void AfficheBinaire(Uint32 valeur) {
+static void AfficheBinaire(Uint32 valeur)
+{
if (valeur) {
AfficheBinaire(valeur >> 1);
fprintf(stdout, "%i", valeur & 1);
diff --git a/lib/meta.c b/lib/meta.c
index be13434..6a50ecf 100644
--- a/lib/meta.c
+++ b/lib/meta.c
@@ -579,20 +579,20 @@ void main(void)
fprintf(stderr, " + %s (%s) type: %s\n",
pattern->expr[i]->name ? pattern->expr[i]->name : "Opérateur [",
pattern->expr[i]->string ? pattern->expr[i]->string : "Aucune chaîne associée",
- pattern->expr[i]->type ? "Constante prédéfinie" : pattern->expr[i]->
- left ? "Binaire" : pattern->expr[i]->right ? "Unaire" : "Feuille");
+ pattern->expr[i]->type ? "Constante prédéfinie" : pattern->
+ expr[i]->left ? "Binaire" : pattern->expr[i]->right ? "Unaire" : "Feuille");
if (pattern->expr[i]->left) {
fprintf(stderr, " - gauche: %s (%s) type: %s\n",
pattern->expr[i]->left->name ? pattern->expr[i]->left->name : "Opérateur [",
- pattern->expr[i]->left->string ? pattern->expr[i]->left->
- string : "Aucune chaîne associée",
+ pattern->expr[i]->left->string ? pattern->expr[i]->
+ left->string : "Aucune chaîne associée",
pattern->expr[i]->left->type ? "Constante prédéfinie" : "Feuille");
}
if (pattern->expr[i]->right) {
fprintf(stderr, " - droite: %s (%s) type: %s\n",
pattern->expr[i]->right->name ? pattern->expr[i]->right->name : "Opérateur [",
- pattern->expr[i]->right->string ? pattern->expr[i]->right->
- string : "Aucune chaîne associée",
+ pattern->expr[i]->right->string ? pattern->expr[i]->
+ right->string : "Aucune chaîne associée",
pattern->expr[i]->right->type ? "Constante prédéfinie" : "Feuille");
}
}
diff --git a/lib/simulator.c b/lib/simulator.c
index 16cc2ef..61c96d5 100644
--- a/lib/simulator.c
+++ b/lib/simulator.c
@@ -57,7 +57,7 @@ static Uint32 readword(FILE * f)
Uint32 Adresse(Uint32 u, Uint32 instruction)
{
Uint32 tmp;
-
+
switch (champ(u, 4)) {
case 0:
exception(1, _("Adresse: Call With Invalid r/m Field State ( r/m=00 )"));
@@ -82,12 +82,12 @@ Uint32 Adresse(Uint32 u, Uint32 instruction)
void Initialisation(void)
{
int i;
-
+
InitMemoire();
for (i = 0; i < TAILLE_MEMOIRE; i++)
Reset(&memoire_principale[i]);
-
+
EcrireRegistre(0, 0);
EcrireRegistreSP(ADD_SP); /* initialisation du stack pointer */
@@ -98,8 +98,8 @@ 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) {
fpu(Opcode(instruction));
} else {
@@ -238,7 +238,7 @@ void DecodeExec(Uint32 instruction)
IncrementeCompteurOrdinal();
}
}
- } else { /* mov arg2, arg1 */
+ } else { /* mov arg2, arg1 */
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)));
@@ -389,20 +389,22 @@ void AfficheReg(void) // affiche reg
fprintf(stderr, "\n");
}
fprintf(stderr, "Rg: %08lX | Rd: %08lX | Flag: %08lX | PC: %08lX\n", LireRegistreRG(), LireRegistreRD(),
- LireRegistreFLAG(), LireRegistrePC());
+ LireRegistreFLAG(), LireRegistrePC());
}
void Debogueur(void)
{
int out = 0;
-
+
Uint32 instruction = LireInstruction();
while (!out) {
AfficheReg();
- 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, "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':
case 'g':
@@ -431,8 +433,6 @@ void Debogueur(void)
void Traitement(Uint32 entrypoint)
{ /* ******************** FIXMI ************************* */
Uint32 instruction;
-
- fprintf(stderr, "Entrypoint: %08lX\n", entrypoint);
while (HasToRun) {
EcrireRegistrePC(entrypoint);
@@ -462,14 +462,13 @@ void ChargeBinaire(char *filename)
if (readword(file) != 0x58454e4e) { /* verification de la signature */
exception(1, _("Invalid Signature"));
}
-
+
sprintf(message, _("Loading file %s"), filename);
pushcontext(message);
-
+
readword(file);
- entrypoint = readword(file); /* point d'entrée */
- fprintf(stderr, "Loaded entrypoint: %08lX", entrypoint);
+ entrypoint = readword(file); /* point d'entrée */
nb = readword(file); /* taille du segment text */
ns = readword(file); /* taille des donnes statiques */
nbss = readword(file); /* taille des donnees non init */
@@ -491,7 +490,7 @@ void ChargeBinaire(char *filename)
free(relocation_table);
entrypoint += base_addr;
-
+
EcrireRegistre(28, base_addr + nb);
EcrireRegistre(30, base_addr + nb + ns + nbss);
@@ -504,4 +503,3 @@ void ChargeBinaire(char *filename)
popcontext();
base_addr -= nb + ns + nbss;
}
-
diff --git a/lib/terminal.c b/lib/terminal.c
index ace1302..adc2a49 100644
--- a/lib/terminal.c
+++ b/lib/terminal.c
@@ -9,7 +9,8 @@
FILE *input;
struct termios initial_settings, new_settings;
-void initterm(void) {
+void initterm(void)
+{
tcgetattr(fileno(input), &initial_settings);
new_settings = initial_settings;
new_settings.c_lflag &= ~ICANON;
@@ -24,11 +25,13 @@ void initterm(void) {
}
-void clearterm(void) {
+void clearterm(void)
+{
tcsetattr(fileno(input), TCSANOW, &initial_settings);
}
-void openterm(void) {
+void openterm(void)
+{
if (!(input = fopen("/dev/tty", "r"))) {
exception(1, _("could not open terminal"));
}
diff --git a/src/simul.c b/src/simul.c
index 799a3b7..1ae3d55 100644
--- a/src/simul.c
+++ b/src/simul.c
@@ -20,4 +20,3 @@ int main(void)
clearterm();
return (0);
}
-