commit 19ec26233d17768b62e8055548523086fa6946f0
parent 4a33c80f5df444995c798cdacfba87a295b4f854
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Thu, 23 Nov 2017 19:23:55 +0100
[lib/scc] Move myro functions to libscc
Thes functions may be used in other tools, so it is a good
idea to move them to a different header.
Diffstat:
M | as/myro.c | | | 105 | +------------------------------------------------------------------------------ |
A | inc/myro.h | | | 41 | +++++++++++++++++++++++++++++++++++++++++ |
M | lib/scc/libdep.mk | | | 1 | + |
A | lib/scc/wmyro.c | | | 78 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
4 files changed, 121 insertions(+), 104 deletions(-)
diff --git a/as/myro.c b/as/myro.c
@@ -5,81 +5,12 @@ static char sccsid[] = "@(#) ./as/myro.c";
#include <string.h>
#include "../inc/scc.h"
+#include "../inc/myro.h"
#include "as.h"
-struct myrohdr {
- unsigned long format;
- unsigned long long entry;
- unsigned long long strsize;
- unsigned long long secsize;
- unsigned long long symsize;
- unsigned long long relsize;
-};
-
-struct myrosect {
- unsigned long name;
- unsigned short flags;
- unsigned char fill;
- unsigned char aligment;
- unsigned long long offset;
- unsigned long long len;
-};
-
-struct myrosym {
- unsigned long name;
- unsigned long type;
- unsigned char section;
- unsigned char flags;
- unsigned long long offset;
- unsigned long long len;
-};
-
-struct myrorel {
- unsigned long id;
- unsigned char flags;
- unsigned char size;
- unsigned char nbits;
- unsigned char shift;
- unsigned long long offset;
-};
-
static Reloc *relocs;
static size_t relcap, relsiz;
-static void
-writehdr(FILE *fp, struct myrohdr *hdr)
-{
- unsigned char buf[sizeof(*hdr)];
- size_t len;
-
- len = lpack(buf, "lqqqqq",
- hdr->format,
- hdr->entry,
- hdr->strsize,
- hdr->secsize,
- hdr->symsize,
- hdr->relsize);
- fwrite(buf, len, 1, fp);
-}
-
-static size_t
-writesec(FILE *fp, struct myrosect *sect)
-{
- unsigned char buf[sizeof(*sect)];
- size_t len;
-
- len = lpack(buf, "lsccqq",
- sect->name,
- sect->flags,
- sect->fill,
- sect->aligment,
- sect->offset,
- sect->len);
- fwrite(buf, len, 1, fp);
-
- return len;
-}
-
static size_t
writestrings(FILE *fp)
{
@@ -132,24 +63,6 @@ writesections(FILE *fp)
}
static size_t
-writesym(FILE *fp, struct myrosym *sym)
-{
- unsigned char buf[sizeof(*sym)];
- size_t len;
-
- len = lpack(buf, "llccqq",
- sym->name,
- sym->type,
- sym->section,
- sym->flags,
- sym->offset,
- sym->len);
- fwrite(buf, len, 1, fp);
-
- return len;
-}
-
-static size_t
writesymbols(FILE *fp)
{
Symbol *sym;
@@ -170,22 +83,6 @@ writesymbols(FILE *fp)
}
static size_t
-writerel(FILE *fp, struct myrorel *rel)
-{
- unsigned char buf[sizeof(*rel)];
- size_t len;
-
- len = lpack(buf, "lccccq",
- rel->id,
- rel->flags,
- rel->size,
- rel->nbits,
- rel->shift,
- rel->offset);
- return len;
-}
-
-static size_t
writerelocs(FILE *fp)
{
Reloc *bp, *lim;
diff --git a/inc/myro.h b/inc/myro.h
@@ -0,0 +1,41 @@
+
+struct myrohdr {
+ unsigned long format;
+ unsigned long long entry;
+ unsigned long long strsize;
+ unsigned long long secsize;
+ unsigned long long symsize;
+ unsigned long long relsize;
+};
+
+struct myrosect {
+ unsigned long name;
+ unsigned short flags;
+ unsigned char fill;
+ unsigned char aligment;
+ unsigned long long offset;
+ unsigned long long len;
+};
+
+struct myrosym {
+ unsigned long name;
+ unsigned long type;
+ unsigned char section;
+ unsigned char flags;
+ unsigned long long offset;
+ unsigned long long len;
+};
+
+struct myrorel {
+ unsigned long id;
+ unsigned char flags;
+ unsigned char size;
+ unsigned char nbits;
+ unsigned char shift;
+ unsigned long long offset;
+};
+
+extern size_t writehdr(FILE *fp, struct myrohdr *hdr);
+extern size_t writesec(FILE *fp, struct myrosect *sect);
+extern size_t writesym(FILE *fp, struct myrosym *sym);
+extern size_t writerel(FILE *fp, struct myrorel *rel);
diff --git a/lib/scc/libdep.mk b/lib/scc/libdep.mk
@@ -9,3 +9,4 @@ LIB-OBJ = $(LIBDIR)/debug.o \
$(LIBDIR)/casecmp.o \
$(LIBDIR)/lunpack.o \
$(LIBDIR)/lpack.o \
+ $(LIBDIR)/wmyro.o \
diff --git a/lib/scc/wmyro.c b/lib/scc/wmyro.c
@@ -0,0 +1,78 @@
+static char sccsid[] = "@(#) ./lib/scc/wmyro.c";
+
+#include <stdio.h>
+
+#include "../../inc/scc.h"
+#include "../../inc/myro.h"
+
+size_t
+writehdr(FILE *fp, struct myrohdr *hdr)
+{
+ unsigned char buf[sizeof(*hdr)];
+ size_t len;
+
+ len = lpack(buf, "lqqqqq",
+ hdr->format,
+ hdr->entry,
+ hdr->strsize,
+ hdr->secsize,
+ hdr->symsize,
+ hdr->relsize);
+ fwrite(buf, len, 1, fp);
+
+ return len;
+}
+
+size_t
+writesec(FILE *fp, struct myrosect *sect)
+{
+ unsigned char buf[sizeof(*sect)];
+ size_t len;
+
+ len = lpack(buf, "lsccqq",
+ sect->name,
+ sect->flags,
+ sect->fill,
+ sect->aligment,
+ sect->offset,
+ sect->len);
+ fwrite(buf, len, 1, fp);
+
+ return len;
+}
+
+size_t
+writesym(FILE *fp, struct myrosym *sym)
+{
+ unsigned char buf[sizeof(*sym)];
+ size_t len;
+
+ len = lpack(buf, "llccqq",
+ sym->name,
+ sym->type,
+ sym->section,
+ sym->flags,
+ sym->offset,
+ sym->len);
+ fwrite(buf, len, 1, fp);
+
+ return len;
+}
+
+size_t
+writerel(FILE *fp, struct myrorel *rel)
+{
+ unsigned char buf[sizeof(*rel)];
+ size_t len;
+
+ len = lpack(buf, "lccccq",
+ rel->id,
+ rel->flags,
+ rel->size,
+ rel->nbits,
+ rel->shift,
+ rel->offset);
+ fwrite(buf, len, 1, fp);
+
+ return len;
+}