summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPixel <>2001-04-16 01:43:54 +0000
committerPixel <>2001-04-16 01:43:54 +0000
commit9c0427e3b87d55f77fbb0176c66916c0844e0c13 (patch)
treefa4ddb422dcaa999b77d6a8f956369f919ce01f6 /lib
parent70ce40a4e0464865df5b946781a179c7d770787c (diff)
Assmbleur fini (?)
Diffstat (limited to 'lib')
-rw-r--r--lib/assembler.c49
1 files changed, 44 insertions, 5 deletions
diff --git a/lib/assembler.c b/lib/assembler.c
index bc9d5d2..646d48f 100644
--- a/lib/assembler.c
+++ b/lib/assembler.c
@@ -2,6 +2,7 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
+#include <unistd.h>
#include "config.h"
#include "meta.h"
@@ -1789,6 +1790,27 @@ static void writestring(char * string, FILE * f) {
*/
+void appendfile(FILE * f, char * name) {
+ unsigned long int a;
+ FILE * g;
+
+ if (!(g = fopen(name, "rb"))) {
+ pushcontext(strerror(errno));
+ exception(1, _("Error writing file"));
+ }
+
+ while (fread(&a, sizeof(a), 1, g) == 1) {
+ writeword(a, f, 1);
+ }
+
+ if (ferror(f)) {
+ pushcontext(strerror(errno));
+ exception(1, _("Error reading file"));
+ }
+
+ fclose(g);
+}
+
void asm_eof(FILE * f)
{
bytestream_t * t, * u;
@@ -1906,7 +1928,7 @@ void asm_eof(FILE * f)
a = tdata->Expr->avalue;
nbsymbols++;
writeword(0, f2, 1);
- writeword(tdata->offset, f2, 1);
+ writeword(tdata->offset + s_text, f2, 1);
writeword(strlen(tdata->Expr->symbol), f2, 1);
writestring(tdata->Expr->symbol, f2);
break;
@@ -1951,7 +1973,7 @@ void asm_eof(FILE * f)
if (tdata->Label) {
nbsymbols++;
writeword(0, f2, 1);
- writeword(tdata->offset, f2, 1);
+ writeword(tdata->offset + s_text, f2, 1);
writeword(strlen(tdata->Expr->symbol), f2, 1);
writestring(tdata->Expr->symbol, f2);
}
@@ -1972,7 +1994,7 @@ void asm_eof(FILE * f)
if (tbss->Label) {
nbsymbols++;
writeword(0, f2, 1);
- writeword(tbss->offset, f2, 1);
+ writeword(tbss->offset + s_text + s_data, f2, 1);
writeword(strlen(tbss->Expr->symbol), f2, 1);
writestring(tbss->Expr->symbol, f2);
}
@@ -1980,12 +2002,29 @@ void asm_eof(FILE * f)
popcontext();
}
popcontext();
-
-
popcontext();
fclose(f1);
+
+ fprintf(stderr, "------\n");
+
+ writeword(0x4f424e4e, f, 1);
+ fprintf(stderr, "Pointeur de f2: %i taille de data: %i taille de text: %i\n", ftell(f2), s_data, s_text);
+ writeword(ftell(f2) + s_data + s_text + 7, f, 1);
fclose(f2);
+ t = (bytestream_t *) NomVarToVar("__start__", labels, &trouve);
+ if (trouve) {
+ writeword(t->offset, f, 1);
+ } else {
+ writeword(-1, f, 1);
+ }
+
+ appendfile(f, "__symbols__");
+ appendfile(f, "__text__");
+ fclose(f);
+
+ unlink("__symbols__");
+ unlink("__text__");
}
static void delete_bytestream(bytestream_t * s)