shithub: scc

Download patch

ref: 7bc957e955f3f89ebf7781d5e631996564c87292
parent: 0517d8a80bca67fca4c46dfdf4a8837b967eefbf
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Thu Nov 23 14:23:55 EST 2017

[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.

--- a/as/myro.c
+++ b/as/myro.c
@@ -5,82 +5,13 @@
 #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)
 {
 	size_t off = 0;
@@ -132,24 +63,6 @@
 }
 
 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;
@@ -167,22 +80,6 @@
 	}
 
 	return off;
-}
-
-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
--- /dev/null
+++ b/inc/myro.h
@@ -1,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);
--- a/lib/scc/libdep.mk
+++ b/lib/scc/libdep.mk
@@ -9,3 +9,4 @@
           $(LIBDIR)/casecmp.o \
           $(LIBDIR)/lunpack.o \
           $(LIBDIR)/lpack.o \
+          $(LIBDIR)/wmyro.o \
--- /dev/null
+++ b/lib/scc/wmyro.c
@@ -1,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;
+}