scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit bc6f6e23f1c47c8fd53633522174ad7e4fc8c82d
parent 12495aa767d04446770e1a3133306c7c7195ffba
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Fri,  4 Jan 2019 15:27:03 +0000

Remove myro files

We also remove the pack/unpack functions because they had a dependency
with the myro files. It also meant to disable the output in ld.

Diffstat:
Ddoc/myro.txt | 177-------------------------------------------------------------------------------
Dinclude/scc/scc/myro.h | 79-------------------------------------------------------------------------------
Msrc/ld/Makefile | 5++---
Msrc/ld/main.c | 15+++++++++++++++
Msrc/libscc/Makefile | 6------
Dsrc/libscc/bunpack.c | 71-----------------------------------------------------------------------
Msrc/libscc/deps.mk | 6------
Dsrc/libscc/lunpack.c | 71-----------------------------------------------------------------------
Dsrc/libscc/rmyro.c | 94-------------------------------------------------------------------------------
Dsrc/libscc/wmyro.c | 86-------------------------------------------------------------------------------
10 files changed, 17 insertions(+), 593 deletions(-)

diff --git a/doc/myro.txt b/doc/myro.txt @@ -1,177 +0,0 @@ -Object File Format ------------------- - -The object file format is designed to be the simplest format that covers -all the needs of many modern programming languages, with sufficient support -for hand written assembly. All the types are little endian. - -File Format ------------ - - +== Header ======+ - | signature | 32 bits - +----------------+ - | format str | MyroN bit - | | - +----------------+ - | entrypoint | MyroN bit - | | - +----------------+ - | stringtab size | MyroN bit - | | - +----------------+ - | section size | MyroN bit - | | - +----------------+ - | symtab size | MyroN bit - | | - +----------------+ - | reloctab size | MyroN bit - | | - +== Metadata ====+ - | strings... | - | .... | - +----------------+ - | sections... | - | ... | - |----------------+ - | symbols.... | - | ... | - +----------------+ - | relocations... | - | ... | - +== Data ========+ - | data... | - | ... | - +================+ - -The file is composed of three components: The header, the metadata, and -the data. The header begins with a signature, containing the four bytes -"uobj", identifying this file as a unified object. It is followed by -a string offste with a format description (it may be used to indicate -file format version, architecture, abi, ...) .This is followed by the -size of the string table, the size of the section table, the size of -the symbol table, and the size of the relocation table. - -Metadata: Strings ------------------ - -The string table directly follows the header. It contains an array -of strings. Each string is a sequence of bytes terminated by a zero -byte. A string may contain any characters other than the zero byte. Any -reference to a string is done using an offset into the string table. If -it is needed to indicate a "no string" then the value -1 may be used. - -Metadata: Sections ------------------- - -The section table follows the string table. The section table defines where -data in a program goes. - - +== Sect ========+ - | str | 32 bit - +----------------+ - | flags | 16 bit - +----------------+ - | fill value | 8 bit - +----------------+ - | aligment | 8 bit - +----------------+ - | offset | MyroN bit - +----------------+ - | len | MyroN bit - +----------------+ - -All the files must defined at least 5 sections, numbered 1 through 5, -which are implcitly included in every binary: - - .text SprotRread | SprotWrite | Sload | Sfile | SprotExec - .data SprotRread | SprotWrite | Sload | Sfile - .bss SprotRread | SprotWrite | Sload - .rodata SprotRread | Sload | Sfile - .blob Sblod | Sfile - -A program may have at most 65,535 sections. Sections have the followign flags; - - SprotRead = 1 << 0 - SprotWrite = 1 << 1 - SprotExec = 1 << 2 - Sload = 1 << 3 - Sfile = 1 << 4 - Sabsolute = 1 << 5 - Sblob = 1 << 6 - -Blob section. This is not loaded into the program memory. It may be used -for debug info, tagging the binary, and other similar uses. - -Metadata: Symbols ------------------ - -The symbol table follows the string table. The symbol table contains an array -of symbol defs. Each symbol has the following structure: - - - +== Sym =========+ - | str name | 32 bits - +----------------+ - | str type | 32 bits - +----------------+ - | section id | 8 bits - +----------------+ - | flags | 8 bits - +----------------+ - | offset | MyroN bits - | | - +----------------+ - | len | MyroN bits - | | - +----------------+ - -The string is an offset into the string table, pointing to the start -of the string. The kind describes where in the output the data goes -and what its role is. The offset describes where, relative to the start -of the data, the symbol begins. The length describes how many bytes it is. - -Currently, there's one flag supported: - - 1 << 1: Deduplicate the symbol. - 1 << 2: Common storage for the symbol. - 1 << 3: external symbol - 1 << 4: undefined symbol - -Metadata: Relocations ----------------------- - -The relocations follow the symbol table. Each relocation has the -following structure: - - - +== Reloc =======+ - | 0 | symbol id | 32 bits - | 1 | section id | - +----------------+ - | flags | 8 bits - +----------------+ - | rel size | 8 bits - +----------------+ - | mask size | 8 bits - +----------------+ - | mask shift | 8 bits - +----------------+ - | offset | MyroN bits - | | - +----------------+ - -Relocations write the appropriate value into the offset requested. -The offset is relative to the base of the section where the symbol -is defined. - -The flags may be: - - Rabsolute = 1 << 0 - Roverflow = 1 << 1 - -Data ----- - -It's just data. What do you want? diff --git a/include/scc/scc/myro.h b/include/scc/scc/myro.h @@ -1,79 +0,0 @@ -#define MYROHDR_SIZ 48 -#define MYROSECT_SIZ 24 -#define MYROSYM_SIZ 26 -#define MYROREL_SIZ 16 - -#define MYROMAGIC_SIZ 4 -#define MYROMAGIC "uobj" - -#define MYROMAXSEC 254 - -struct myrohdr { - char magic[4]; - 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; -}; - -enum myrosecflg { - MYROSEC_READ = 1 << 0, - MYROSEC_WRITE = 1 << 1, - MYROSEC_EXEC = 1 << 2, - MYROSEC_LOAD = 1 << 3, - MYROSEC_FILE = 1 << 4, - MYROSEC_ABS = 1 << 5, -}; - -enum myrosymflg { - MYROSYM_COMMON = 1 << 0, - MYROSYM_EXTERN = 1 << 1, - MYROSYM_GLOBAL = 1 << 2, - MYROSYM_UNDEF = 1 << 3, - MYROSYM_ABS = 1 << 4, -}; - -enum myrosectnames { - MYRO_TEXT = 0, - MYRO_DATA = 1, - MYRO_BSS = 2, - MYRO_ABS = 3, -}; - -extern int wrmyrohdr(FILE *fp, struct myrohdr *hdr); -extern int wrmyrosec(FILE *fp, struct myrosect *sect); -extern int wrmyrosym(FILE *fp, struct myrosym *sym); -extern int wrmyrorel(FILE *fp, struct myrorel *rel); -extern int rdmyrohdr(FILE *fp, struct myrohdr *hdr); -extern int rdmyrosec(FILE *fp, struct myrosect *sect); -extern int rdmyrosym(FILE *fp, struct myrosym *sym); -extern int rdmyrorel(FILE *fp, struct myrorel *rel); diff --git a/src/ld/Makefile b/src/ld/Makefile @@ -4,17 +4,16 @@ PROJECTDIR = ../.. include $(PROJECTDIR)/scripts/rules.mk OBJS = main.o \ - coff32.o \ obj.o \ TARGET = $(BINDIR)/ld all: $(TARGET) -$(TARGET): $(LIBDIR)/libcoff32.a $(LIBDIR)/libscc.a +$(TARGET): $(LIBDIR)/libscc.a $(TARGET): $(OBJS) - $(CC) $(SCC_LDFLAGS) $(OBJS) -lcoff32 -lscc -o $@ + $(CC) $(SCC_LDFLAGS) $(OBJS) -lscc -o $@ dep: inc-dep diff --git a/src/ld/main.c b/src/ld/main.c @@ -23,6 +23,21 @@ int gflag; /* preserve debug symbols */ static int done; +Obj * +probe(char *fname, char *member, FILE *fp) +{ +} + +Obj * +load(Obj *obj) +{ +} + +void +writeout(FILE *fp) +{ +} + void redefined(Obj *obj, Symbol *sym) { diff --git a/src/libscc/Makefile b/src/libscc/Makefile @@ -12,12 +12,6 @@ OBJS = debug.o \ xstrdup.o \ alloc.o \ casecmp.o \ - lunpack.o \ - lpack.o \ - bunpack.o \ - bpack.o \ - wmyro.o \ - rmyro.o \ TARGET = $(LIBDIR)/libscc.a diff --git a/src/libscc/bunpack.c b/src/libscc/bunpack.c @@ -1,71 +0,0 @@ -static char sccsid[] = "@(#) ./lib/scc/bunpack.c"; - -#include <ctype.h> -#include <stdarg.h> - -#include <scc/scc.h> - -int -bunpack(unsigned char *src, char *fmt, ...) -{ - unsigned char *bp, *cp; - unsigned short *sp; - unsigned s; - unsigned long *lp, l; - unsigned long long *qp, q; - va_list va; - size_t n; - int d; - - bp = src; - va_start(va, fmt); - while (*fmt) { - switch (*fmt++) { - case '\'': - for (n = 0; isdigit(*fmt); n += d) { - n *= 10; - d = *fmt++ - '0'; - } - cp = va_arg(va, unsigned char *); - while (n--) - *cp++ = *bp++; - break; - case 'c': - cp = va_arg(va, unsigned char *); - *cp = *bp++; - break; - case 's': - sp = va_arg(va, unsigned short *); - s = (unsigned) *bp++ << 8; - s |= (unsigned) *bp++; - *sp = s; - break; - case 'l': - lp = va_arg(va, unsigned long *); - l = (unsigned long) *bp++ << 24; - l |= (unsigned long) *bp++ << 16; - l |= (unsigned long) *bp++ << 8; - l |= (unsigned long) *bp++; - *lp = l; - break; - case 'q': - qp = va_arg(va, unsigned long long *); - q = (unsigned long long) *bp++ << 56; - q |= (unsigned long long) *bp++ << 48; - q |= (unsigned long long) *bp++ << 40; - q |= (unsigned long long) *bp++ << 32; - q |= (unsigned long long) *bp++ << 24; - q |= (unsigned long long) *bp++ << 16; - q |= (unsigned long long) *bp++ << 8; - q |= (unsigned long long) *bp++; - *qp = q; - break; - default: - va_end(va); - return -1; - } - } - va_end(va); - - return bp - src; -} diff --git a/src/libscc/deps.mk b/src/libscc/deps.mk @@ -1,17 +1,11 @@ #deps alloc.o: $(INCDIR)/scc/scc/scc.h bpack.o: $(INCDIR)/scc/scc/scc.h -bunpack.o: $(INCDIR)/scc/scc/scc.h casecmp.o: $(INCDIR)/scc/scc/scc.h debug.o: $(INCDIR)/scc/scc/scc.h die.o: $(INCDIR)/scc/scc/scc.h lpack.o: $(INCDIR)/scc/scc/scc.h -lunpack.o: $(INCDIR)/scc/scc/scc.h newitem.o: $(INCDIR)/scc/scc/scc.h -rmyro.o: $(INCDIR)/scc/scc/myro.h -rmyro.o: $(INCDIR)/scc/scc/scc.h -wmyro.o: $(INCDIR)/scc/scc/myro.h -wmyro.o: $(INCDIR)/scc/scc/scc.h xcalloc.o: $(INCDIR)/scc/scc/scc.h xmalloc.o: $(INCDIR)/scc/scc/scc.h xrealloc.o: $(INCDIR)/scc/scc/scc.h diff --git a/src/libscc/lunpack.c b/src/libscc/lunpack.c @@ -1,71 +0,0 @@ -static char sccsid[] = "@(#) ./lib/scc/lunpack.c"; - -#include <ctype.h> -#include <stdarg.h> - -#include <scc/scc.h> - -int -lunpack(unsigned char *src, char *fmt, ...) -{ - unsigned char *bp, *cp; - unsigned short *sp; - unsigned s; - unsigned long *lp, l; - unsigned long long *qp, q; - va_list va; - size_t n; - int d; - - bp = src; - va_start(va, fmt); - while (*fmt) { - switch (*fmt++) { - case '\'': - for (n = 0; isdigit(*fmt); n += d) { - n *= 10; - d = *fmt++ - '0'; - } - cp = va_arg(va, unsigned char *); - while (n--) - *cp++ = *bp++; - break; - case 'c': - cp = va_arg(va, unsigned char *); - *cp = *bp++; - break; - case 's': - sp = va_arg(va, unsigned short *); - s = (unsigned) *bp++; - s |= (unsigned) *bp++ << 8; - *sp = s; - break; - case 'l': - lp = va_arg(va, unsigned long *); - l = (unsigned long) *bp++; - l |= (unsigned long) *bp++ << 8; - l |= (unsigned long) *bp++ << 16; - l |= (unsigned long) *bp++ << 24; - *lp = l; - break; - case 'q': - qp = va_arg(va, unsigned long long *); - q = (unsigned long long) *bp++; - q |= (unsigned long long) *bp++ << 8; - q |= (unsigned long long) *bp++ << 16; - q |= (unsigned long long) *bp++ << 24; - q |= (unsigned long long) *bp++ << 32; - q |= (unsigned long long) *bp++ << 40; - q |= (unsigned long long) *bp++ << 48; - q |= (unsigned long long) *bp++ << 56; - *qp = q; - break; - default: - va_end(va); - return -1; - } - } - va_end(va); - - return bp - src; -} diff --git a/src/libscc/rmyro.c b/src/libscc/rmyro.c @@ -1,94 +0,0 @@ -static char sccsid[] = "@(#) ./lib/scc/rmyro.c"; - -#include <assert.h> -#include <stdio.h> -#include <string.h> - -#include <scc/scc.h> -#include <scc/myro.h> - -int -rdmyrohdr(FILE *fp, struct myrohdr *hdr) -{ - unsigned char buf[MYROHDR_SIZ]; - int len; - - fread(buf, sizeof(buf), 1, fp); - if (ferror(fp)) - return EOF; - len = lunpack(buf, "cccclqqqqq", - hdr->magic+0, hdr->magic+1, - hdr->magic+2, hdr->magic+3, - &hdr->format, - &hdr->entry, - &hdr->strsize, - &hdr->secsize, - &hdr->symsize, - &hdr->relsize); - assert(len == MYROHDR_SIZ); - - return len; -} - -int -rdmyrosec(FILE *fp, struct myrosect *sect) -{ - unsigned char buf[MYROSECT_SIZ]; - int len; - - fread(buf, sizeof(buf), 1, fp); - if (ferror(fp)) - return EOF; - len = lunpack(buf, "lsccqq", - &sect->name, - &sect->flags, - &sect->fill, - &sect->aligment, - &sect->offset, - &sect->len); - assert(len == MYROSECT_SIZ); - - return len; -} - -int -rdmyrosym(FILE *fp, struct myrosym *sym) -{ - unsigned char buf[MYROSYM_SIZ]; - int len; - - fread(buf, sizeof(buf), 1, fp); - if (ferror(fp)) - return EOF; - len = lunpack(buf, "llccqq", - &sym->name, - &sym->type, - &sym->section, - &sym->flags, - &sym->offset, - &sym->len); - assert(len == MYROSYM_SIZ); - - return len; -} - -int -rdmyrorel(FILE *fp, struct myrorel *rel) -{ - unsigned char buf[MYROREL_SIZ]; - int len; - - fread(buf, sizeof(buf), 1, fp); - if (ferror(fp)) - return EOF; - len = lunpack(buf, "lccccq", - &rel->id, - &rel->flags, - &rel->size, - &rel->nbits, - &rel->shift, - &rel->offset); - assert(len == MYROREL_SIZ); - - return len; -} diff --git a/src/libscc/wmyro.c b/src/libscc/wmyro.c @@ -1,86 +0,0 @@ -static char sccsid[] = "@(#) ./lib/scc/wmyro.c"; - -#include <assert.h> -#include <stdio.h> -#include <string.h> - -#include <scc/scc.h> -#include <scc/myro.h> - -int -wrmyrohdr(FILE *fp, struct myrohdr *hdr) -{ - unsigned char buf[MYROHDR_SIZ]; - int len; - - len = lpack(buf, "cccclqqqqq", - hdr->magic[0], hdr->magic[1], - hdr->magic[2], hdr->magic[3], - hdr->format, - hdr->entry, - hdr->strsize, - hdr->secsize, - hdr->symsize, - hdr->relsize); - assert(MYROHDR_SIZ == len); - fwrite(buf, len, 1, fp); - - return (ferror(fp)) ? EOF : len; -} - -int -wrmyrosec(FILE *fp, struct myrosect *sect) -{ - unsigned char buf[MYROSECT_SIZ]; - int len; - - len = lpack(buf, "lsccqq", - sect->name, - sect->flags, - sect->fill, - sect->aligment, - sect->offset, - sect->len); - assert(MYROSECT_SIZ == len); - fwrite(buf, len, 1, fp); - - return (ferror(fp)) ? EOF : len; -} - -int -wrmyrosym(FILE *fp, struct myrosym *sym) -{ - unsigned char buf[MYROSYM_SIZ]; - int len; - - len = lpack(buf, "llccqq", - sym->name, - sym->type, - sym->section, - sym->flags, - sym->offset, - sym->len); - assert(MYROSYM_SIZ == len); - fwrite(buf, len, 1, fp); - - return (ferror(fp)) ? EOF : len; -} - -int -wrmyrorel(FILE *fp, struct myrorel *rel) -{ - unsigned char buf[MYROREL_SIZ]; - int len; - - len = lpack(buf, "lccccq", - rel->id, - rel->flags, - rel->size, - rel->nbits, - rel->shift, - rel->offset); - assert(MYROREL_SIZ == len); - fwrite(buf, len, 1, fp); - - return (ferror(fp)) ? EOF : len; -}