ref: cc37574232c7a540c101aa91bd3ecdf89cb90627
parent: ee9d0c10154747c291ff77815127698de118b502
parent: b81141894f3c7f562bde8c125087cb51f00ae53a
author: Roberto E. Vargas Caballero <[email protected]>
date: Mon Feb 5 02:48:40 EST 2018
Merge branch 'master' of ssh://simple-cc.org:/var/gitrepos/scc
--- a/as/Makefile
+++ b/as/Makefile
@@ -24,10 +24,10 @@
./gendep.sh $(TARGETS)
clean:
- rm -f *.o
- rm -f target/*/*.o
+ rm -f *.o target/*/*.o
rm -f target/*/*tbl.c
rm -f as-*
+ rm -f *.log
distclean: clean
rm -f makefile
--- a/as/as.h
+++ b/as/as.h
@@ -3,17 +3,13 @@
* type of segment
*/
enum symflags {
- FTMASK = 0x3,
- FNTYPE = 0,
- FREG = 1,
- FSECT = 2,
- FSYM = 3,
-
- FCOMMON = 1 << 2,
- FEXTERN = 1 << 3,
- FUNDEF = 1 << 4,
- FGLOBAL = 1 << 5,
- FRELOC = 1 << 6,
+ FREG = 1 << 0,
+ FSECT = 1 << 1,
+ FSYM = 1 << 2,
+ FCOMMON = 1 << 3,
+ FEXTERN = 1 << 4,
+ FDEF = 1 << 5,
+ FGLOBAL = 1 << 6,
FABS = 1 << 7,
};
@@ -176,6 +172,8 @@
extern void regctx(int mode);
extern Node *getreg(void);
extern Node *operand(char **s);
+extern void addinput(char *fname);
+extern int delinput(void);
/* expr.c */
extern Node *expr(void);
--- a/as/expr.c
+++ b/as/expr.c
@@ -164,20 +164,14 @@
static Node *
primary(void)
{
- int addr, op;
Node *np;
switch (yytoken) {
case IDEN:
case NUMBER:
- addr = ANUMBER;
- goto basic_atom;
- case STRING:
- addr = ASTR;
- basic_atom:
np = node(yytoken, NULL, NULL);
np->sym = yylval.sym;
- np->addr = addr;
+ np->addr = ANUMBER;
next();
break;
case '(':
--- a/as/ins.c
+++ b/as/ins.c
@@ -75,7 +75,7 @@
while (np = *args++) {
Symbol *sym = np->sym;
- if (sym->flags & FRELOC)
+ if ((sym->flags & FABS) == 0)
reloc(sym, 0, siz, siz * 8, 0);
emit(tobytes(sym->value, siz, endian), siz);
}
@@ -131,10 +131,10 @@
switch (which) {
case EQU:
- if (pass == 1 && (sym->flags & FUNDEF) == 0)
+ if (pass == 1 && (sym->flags & FDEF))
error("redefinition of symbol '%s'", sym->name.buf);
sym->value = exp->value;
- sym->flags &= ~FUNDEF;
+ sym->flags |= FDEF;
break;
case COMMON:
sym->flags |= FCOMMON;
@@ -240,6 +240,12 @@
end(Op *op, Node **args)
{
endpass = 1;
+}
+
+void
+include(Op *op, Node **args)
+{
+ addinput(args[0]->sym->name.buf);
}
void
--- a/as/main.c
+++ b/as/main.c
@@ -74,9 +74,7 @@
extern int nerrors;
extern jmp_buf recover;
- /* TODO: reset line number */
- if ((fp = fopen(fname, "r")) == NULL)
- die("as: error opening '%s'", fname);
+ addinput(fname);
cleansecs();
endpass = 0;
@@ -93,8 +91,6 @@
error("arguments without an opcode");
}
- if (fclose(fp))
- die("as: error reading from input file '%s'", fname);
return nerrors == 0;
}
--- a/as/myro.c
+++ b/as/myro.c
@@ -27,7 +27,7 @@
off = sizeof(FORMAT);
for (sym = symlist; sym; sym = sym->next) {
- if ((sym->flags & FTMASK) == FREG)
+ if (sym->flags & FREG)
continue;
str = &sym->name;
len = strlen(str->buf) + 1;
@@ -92,7 +92,7 @@
flags |= MYROSYM_COMMON;
if (sym->flags & FEXTERN)
flags |= MYROSYM_EXTERN;
- if (sym->flags & FUNDEF)
+ if (!(sym->flags & FDEF))
flags |= MYROSYM_UNDEF;
return flags;
}
@@ -100,14 +100,12 @@
static size_t
writesymbols(FILE *fp)
{
- int type;
Symbol *sym;
size_t off = 0;
struct myrosym symbol;
for (sym = symlist; sym; sym = sym->next) {
- type = sym->flags & FTMASK;
- if (type == FREG || type == FSECT)
+ if (sym->flags & (FREG|FSECT))
continue;
symbol.name = sym->name.offset;
symbol.type = -1;
--- a/as/parser.c
+++ b/as/parser.c
@@ -1,4 +1,5 @@
static char sccsid[] = "@(#) ./as/parser.c";
+#include <assert.h>
#include <ctype.h>
#include <limits.h>
#include <setjmp.h>
@@ -12,8 +13,15 @@
#include "as.h"
#define NARGS 20
+#define NR_INPUTS 10
#define MAXLINE 100
+struct input {
+ char *fname;
+ unsigned lineno;
+ FILE *fp;
+};
+
int nerrors;
jmp_buf recover;
char yytext[INTIDENTSIZ+1];
@@ -24,6 +32,7 @@
static char *textp, *endp;
static int regmode;
static unsigned lineno;
+static struct input inputs[NR_INPUTS], *isp = inputs;
static int
follow(int expect1, int expect2, int ifyes1, int ifyes2, int ifno)
@@ -75,7 +84,7 @@
tok2str();
yylval.sym = lookup(yytext);
- return ((yylval.sym->flags & FTMASK) == FREG) ? REG : IDEN;
+ return (yylval.sym->flags & FREG) ? REG : IDEN;
}
static int
@@ -121,15 +130,20 @@
string(void)
{
int c;
- char *p;
+ size_t l;
+ char *s;
+ Symbol *sym = tmpsym(0);
for (++endp; *endp != '"'; ++endp)
;
++endp;
tok2str();
- yylval.sym = tmpsym(0);
+ yylval.sym = sym;
/* FIXME: this memory is not freed ever */
- yylval.sym->name.buf = xstrdup(yytext);
+ l = yylen-2;
+ s = memcpy(xmalloc(l+1), yytext+1, l);
+ s[l] = '\0';
+ sym->name.buf = s;
return STRING;
}
@@ -207,9 +221,13 @@
error(char *msg, ...)
{
va_list va;
+ struct input *ip;
+ assert(isp > inputs);
+ ip = &isp[-1];
+
va_start(va, msg);
- fprintf(stderr, "as:%s:%u: ", infile, lineno);
+ fprintf(stderr, "as:%s:%u: ", ip->fname, ip->lineno);
vfprintf(stderr, msg, va);
putc('\n', stderr);
nerrors++;
@@ -253,6 +271,12 @@
case REG:
np = getreg();
break;
+ case STRING:
+ np = node(yytoken, NULL, NULL);
+ np->sym = yylval.sym;
+ np->addr = ASTR;
+ next();
+ break;
case '$':
next();
imm = 1;
@@ -309,7 +333,7 @@
for (s = begin; isspace(*s) && *s != '\t'; ++s)
;
if (*s == '\0' || *s == '/' || *s == ';') {
- *t = '\0';
+ *s = '\0';
return *oldp = NULL;
}
@@ -416,17 +440,52 @@
int
nextline(FILE *fp, struct line *lp)
{
+ struct input *ip;
size_t n;
static char buff[MAXLINE];
+ assert(isp > inputs);
repeat:
- if (feof(fp))
+ if (isp == inputs)
return 0;
- if ((n = getline(fp, buff)) == 0)
+ ip = &isp[-1];
+ if (feof(ip->fp)) {
+ delinput();
goto repeat;
- if (++lineno == 0)
+ }
+ n = getline(ip->fp, buff);
+ if (++ip->lineno == 0)
die("as: file too long");
+ if (n == 0)
+ goto repeat;
if (extract(buff, n, lp) == 0)
goto repeat;
return 1;
+}
+
+void
+addinput(char *fname)
+{
+ FILE *fp;
+
+ if (isp == &inputs[NR_INPUTS])
+ die("too many included files");
+ if ((fp = fopen(fname, "r")) == NULL)
+ die("error opening input file '%s'", fname);
+ isp->fname = xstrdup(fname);
+ isp->fp = fp;
+ isp->lineno = 0;
+ ++isp;
+}
+
+int
+delinput(void)
+{
+ if (isp == inputs)
+ return EOF;
+ --isp;
+ if (fclose(isp->fp) == EOF)
+ die("error closing file '%s'", isp->fname);
+ free(isp->fname);
+ return 0;
}
--- a/as/symbol.c
+++ b/as/symbol.c
@@ -64,7 +64,7 @@
sym = xmalloc(sizeof(*sym));
sym->name = newstring(name);
- sym->flags = FRELOC | FUNDEF | FNTYPE;
+ sym->flags = 0;
sym->size = sym->value = 0;
sym->section = cursec;
sym->hash = *list;
@@ -106,13 +106,11 @@
}
sym = lookup(name);
- if (pass == 1 && (sym->flags & FUNDEF) == 0)
+ if (pass == 1 && (sym->flags & FDEF))
error("redefinition of label '%s'", name);
- if (cursec->flags & SABS) {
- sym->flags &= ~FRELOC;
+ if (cursec->flags & SABS)
sym->flags |= FABS;
- }
- sym->flags &= ~FUNDEF;
+ sym->flags |= FDEF;
sym->value = cursec->curpc;
sym->section = cursec;
@@ -192,12 +190,10 @@
{
Section *sec;
Symbol *sym;
- int flags, type;
cursec = NULL;
sym = lookup(name);
- type = sym->flags & FTMASK;
- if (type != FNTYPE && type != FSECT)
+ if (sym->flags & ~FSECT)
error("invalid section name '%s'", name);
if ((sec = sym->section) == NULL) {
--- a/as/target/x80/x80.dat
+++ b/as/target/x80/x80.dat
@@ -27,12 +27,15 @@
.TYPE sym,imm16 0 none type Z80,R800,GB80
.TYPE imm16 0 none type Z80,R800,GB80
.GLOBL sym+ 0 none global Z80,R800,GB80
+.PUBLIC sym+ 0 none global Z80,R800,GB80
.EXTERN sym+ 0 none extrn Z80,R800,GB80
+.EXTRN sym+ 0 none extrn Z80,R800,GB80
.STRING string+ 0 none string Z80,R800,GB80
.ASCII string+ 0 none ascii Z80,R800,GB80
.ALIGN imm16+ 0 none align Z80,R800,GB80
.ATT imm8 0 none att Z80,R800,GB80
.END none 0 none end Z80,R800,GB80
+.INCLUDE string 0 none include Z80,R800,GB80
--- a/as/target/x80/z80-test.s
+++ b/as/target/x80/z80-test.s
@@ -40,7 +40,7 @@
DAA / 27
L4: JR Z,$L4 / 28 02
ADD HL,HL / 29
- LD HL, (16384) / 2A 00 40
+ LD HL,(16384) / 2A 00 40
DEC HL / 2B
INC L / 2C
DEC L / 2D
@@ -1134,3 +1134,455 @@
LD SP,IY / FD F9
CP A,$32 / FE 20
RST $56 / FF
+
+/ and now, we are going to test at&t syntax in z80
+ INC 32(IX) / DD 34 20
+ DEC 16(IX) / DD 35 10
+ LD 64(IX),$128 / DD 36 40 80
+ LD B,32(IX) / DD 46 20
+ LD C,48(IX) / DD 4E 30
+ LD D,32(IX) / DD 56 20
+ LD E,64(IX) / DD 5E 40
+ LD H,16(IX) / DD 66 10
+ LD L,48(IX) / DD 6E 30
+ LD 64(IX),B / DD 70 40
+ LD 16(IX),C / DD 71 10
+ LD 32(IX),D / DD 72 20
+ LD 48(IX),E / DD 73 30
+ LD 16(IX),H / DD 74 10
+ LD 32(IX),L / DD 75 20
+ LD 48(IX),A / DD 77 30
+ LD A,16(IX) / DD 7E 10
+ ADD A,32(IX) / DD 86 20
+ ADC A,48(IX) / DD 8E 30
+ SUB A,16(IX) / DD 96 10
+ SBC A,32(IX) / DD 9E 20
+ AND A,48(IX) / DD A6 30
+ XOR A,16(IX) / DD AE 10
+ OR A,32(IX) / DD B6 20
+ CP A,48(IX) / DD BE 30
+ RLC 16(IX),B / DD CB 10 00
+ RLC 32(IX),C / DD CB 20 01
+ RLC 48(IX),D / DD CB 30 02
+ RLC 64(IX),E / DD CB 40 03
+ RLC 16(IX),H / DD CB 10 04
+ RLC 32(IX),L / DD CB 20 05
+ RLC 64(IX) / DD CB 40 06
+ RLC 16(IX),A / DD CB 10 07
+ RRC 32(IX),B / DD CB 20 08
+ RRC 48(IX),C / DD CB 30 09
+ RRC 64(IX),D / DD CB 40 0A
+ RRC 16(IX),E / DD CB 10 0B
+ RRC 32(IX),H / DD CB 20 0C
+ RRC 48(IX),L / DD CB 30 0D
+ RRC 16(IX) / DD CB 10 0E
+ RRC 16(IX),A / DD CB 10 0F
+ RL 32(IX),B / DD CB 20 10
+ RL 48(IX),C / DD CB 30 11
+ RL 64(IX),D / DD CB 40 12
+ RL 16(IX),E / DD CB 10 13
+ RL 32(IX),H / DD CB 20 14
+ RL 48(IX),L / DD CB 30 15
+ RL 32(IX) / DD CB 20 16
+ RL 16(IX),A / DD CB 10 17
+ RR 32(IX),B / DD CB 20 18
+ RR 48(IX),C / DD CB 30 19
+ RR 64(IX),D / DD CB 40 1A
+ RR 16(IX),E / DD CB 10 1B
+ RR 32(IX),H / DD CB 20 1C
+ RR 48(IX),L / DD CB 30 1D
+ RR 48(IX) / DD CB 30 1E
+ RR 16(IX),A / DD CB 10 1F
+ SLA 32(IX),B / DD CB 20 20
+ SLA 48(IX),C / DD CB 30 21
+ SLA 64(IX),D / DD CB 40 22
+ SLA 16(IX),E / DD CB 10 23
+ SLA 32(IX),H / DD CB 20 24
+ SLA 48(IX),L / DD CB 30 25
+ SLA 64(IX) / DD CB 40 26
+ SLA 16(IX),A / DD CB 10 27
+ SRA 32(IX),B / DD CB 20 28
+ SRA 48(IX),C / DD CB 30 29
+ SRA 64(IX),D / DD CB 40 2A
+ SRA 16(IX),E / DD CB 10 2B
+ SRA 32(IX),H / DD CB 20 2C
+ SRA 48(IX),L / DD CB 30 2D
+ SRA 16(IX) / DD CB 10 2E
+ SRA 16(IX),A / DD CB 10 2F
+ SLL 32(IX),B / DD CB 20 30
+ SLL 48(IX),C / DD CB 30 31
+ SLL 64(IX),D / DD CB 40 32
+ SLL 16(IX),E / DD CB 10 33
+ SLL 32(IX),H / DD CB 20 34
+ SLL 48(IX),L / DD CB 30 35
+ SLL 32(IX) / DD CB 20 36
+ SLL 16(IX),A / DD CB 10 37
+ SRL 32(IX),B / DD CB 20 38
+ SRL 48(IX),C / DD CB 30 39
+ SRL 64(IX),D / DD CB 40 3A
+ SRL 16(IX),E / DD CB 10 3B
+ SRL 32(IX),H / DD CB 20 3C
+ SRL 48(IX),L / DD CB 30 3D
+ SRL 48(IX) / DD CB 30 3E
+ SRL 64(IX),A / DD CB 40 3F
+ BIT $0,16(IX) / DD CB 10 46
+ BIT $1,32(IX) / DD CB 20 4E
+ BIT $2,48(IX) / DD CB 30 56
+ BIT $3,64(IX) / DD CB 40 5E
+ BIT $4,16(IX) / DD CB 10 66
+ BIT $5,32(IX) / DD CB 20 6E
+ BIT $6,48(IX) / DD CB 30 76
+ BIT $7,64(IX) / DD CB 40 7E
+ RES $0,16(IX),B / DD CB 10 80
+ RES $0,32(IX),C / DD CB 20 81
+ RES $0,48(IX),D / DD CB 30 82
+ RES $0,64(IX),E / DD CB 40 83
+ RES $0,16(IX),H / DD CB 10 84
+ RES $0,32(IX),L / DD CB 20 85
+ RES $0,48(IX) / DD CB 30 86
+ RES $0,64(IX),A / DD CB 40 87
+ RES $1,16(IX),B / DD CB 10 88
+ RES $1,32(IX),C / DD CB 20 89
+ RES $1,48(IX),D / DD CB 30 8A
+ RES $1,64(IX),E / DD CB 40 8B
+ RES $1,16(IX),H / DD CB 10 8C
+ RES $1,32(IX),L / DD CB 20 8D
+ RES $1,48(IX) / DD CB 30 8E
+ RES $1,64(IX),A / DD CB 40 8F
+ RES $2,16(IX),B / DD CB 10 90
+ RES $2,32(IX),C / DD CB 20 91
+ RES $2,48(IX),D / DD CB 30 92
+ RES $2,64(IX),E / DD CB 40 93
+ RES $2,16(IX),H / DD CB 10 94
+ RES $2,32(IX),L / DD CB 20 95
+ RES $2,48(IX) / DD CB 30 96
+ RES $2,64(IX),A / DD CB 40 97
+ RES $3,16(IX),B / DD CB 10 98
+ RES $3,32(IX),C / DD CB 20 99
+ RES $3,48(IX),D / DD CB 30 9A
+ RES $3,64(IX),E / DD CB 40 9B
+ RES $3,16(IX),H / DD CB 10 9C
+ RES $3,32(IX),L / DD CB 20 9D
+ RES $3,48(IX) / DD CB 30 9E
+ RES $3,64(IX),A / DD CB 40 9F
+ RES $4,16(IX),B / DD CB 10 A0
+ RES $4,32(IX),C / DD CB 20 A1
+ RES $4,48(IX),D / DD CB 30 A2
+ RES $4,64(IX),E / DD CB 40 A3
+ RES $4,16(IX),H / DD CB 10 A4
+ RES $4,32(IX),L / DD CB 20 A5
+ RES $4,48(IX) / DD CB 30 A6
+ RES $4,64(IX),A / DD CB 40 A7
+ RES $5,16(IX),B / DD CB 10 A8
+ RES $5,32(IX),C / DD CB 20 A9
+ RES $5,48(IX),D / DD CB 30 AA
+ RES $5,64(IX),E / DD CB 40 AB
+ RES $5,16(IX),H / DD CB 10 AC
+ RES $5,32(IX),L / DD CB 20 AD
+ RES $5,48(IX) / DD CB 30 AE
+ RES $5,64(IX),A / DD CB 40 AF
+ RES $6,16(IX),B / DD CB 10 B0
+ RES $6,32(IX),C / DD CB 20 B1
+ RES $6,48(IX),D / DD CB 30 B2
+ RES $6,64(IX),E / DD CB 40 B3
+ RES $6,16(IX),H / DD CB 10 B4
+ RES $6,32(IX),L / DD CB 20 B5
+ RES $6,48(IX) / DD CB 30 B6
+ RES $6,64(IX),A / DD CB 40 B7
+ RES $7,16(IX),B / DD CB 10 B8
+ RES $7,32(IX),C / DD CB 20 B9
+ RES $7,48(IX),D / DD CB 30 BA
+ RES $7,64(IX),E / DD CB 40 BB
+ RES $7,16(IX),H / DD CB 10 BC
+ RES $7,32(IX),L / DD CB 20 BD
+ RES $7,48(IX) / DD CB 30 BE
+ RES $7,64(IX),A / DD CB 40 BF
+ SET $0,16(IX),B / DD CB 10 C0
+ SET $0,32(IX),C / DD CB 20 C1
+ SET $0,48(IX),D / DD CB 30 C2
+ SET $0,64(IX),E / DD CB 40 C3
+ SET $0,16(IX),H / DD CB 10 C4
+ SET $0,32(IX),L / DD CB 20 C5
+ SET $0,48(IX) / DD CB 30 C6
+ SET $0,64(IX),A / DD CB 40 C7
+ SET $1,16(IX),B / DD CB 10 C8
+ SET $1,32(IX),C / DD CB 20 C9
+ SET $1,48(IX),D / DD CB 30 CA
+ SET $1,64(IX),E / DD CB 40 CB
+ SET $1,16(IX),H / DD CB 10 CC
+ SET $1,32(IX),L / DD CB 20 CD
+ SET $1,48(IX) / DD CB 30 CE
+ SET $1,64(IX),A / DD CB 40 CF
+ SET $2,16(IX),B / DD CB 10 D0
+ SET $2,32(IX),C / DD CB 20 D1
+ SET $2,48(IX),D / DD CB 30 D2
+ SET $2,64(IX),E / DD CB 40 D3
+ SET $2,16(IX),H / DD CB 10 D4
+ SET $2,32(IX),L / DD CB 20 D5
+ SET $2,48(IX) / DD CB 30 D6
+ SET $2,64(IX),A / DD CB 40 D7
+ SET $3,16(IX),B / DD CB 10 D8
+ SET $3,32(IX),C / DD CB 20 D9
+ SET $3,48(IX),D / DD CB 30 DA
+ SET $3,64(IX),E / DD CB 40 DB
+ SET $3,16(IX),H / DD CB 10 DC
+ SET $3,32(IX),L / DD CB 20 DD
+ SET $3,48(IX) / DD CB 30 DE
+ SET $3,64(IX),A / DD CB 40 DF
+ SET $4,16(IX),B / DD CB 10 E0
+ SET $4,32(IX),C / DD CB 20 E1
+ SET $4,48(IX),D / DD CB 30 E2
+ SET $4,64(IX),E / DD CB 40 E3
+ SET $4,16(IX),H / DD CB 10 E4
+ SET $4,32(IX),L / DD CB 20 E5
+ SET $4,48(IX) / DD CB 30 E6
+ SET $4,64(IX),A / DD CB 40 E7
+ SET $5,16(IX),B / DD CB 10 E8
+ SET $5,32(IX),C / DD CB 20 E9
+ SET $5,48(IX),D / DD CB 30 EA
+ SET $5,64(IX),E / DD CB 40 EB
+ SET $5,16(IX),H / DD CB 10 EC
+ SET $5,32(IX),L / DD CB 20 ED
+ SET $5,48(IX) / DD CB 30 EE
+ SET $5,64(IX),A / DD CB 40 EF
+ SET $6,16(IX),B / DD CB 10 F0
+ SET $6,32(IX),C / DD CB 20 F1
+ SET $6,48(IX),D / DD CB 30 F2
+ SET $6,64(IX),E / DD CB 40 F3
+ SET $6,16(IX),H / DD CB 10 F4
+ SET $6,32(IX),L / DD CB 20 F5
+ SET $6,48(IX) / DD CB 30 F6
+ SET $6,64(IX),A / DD CB 40 F7
+ SET $7,16(IX),B / DD CB 10 F8
+ SET $7,32(IX),C / DD CB 20 F9
+ SET $7,48(IX),D / DD CB 30 FA
+ SET $7,64(IX),E / DD CB 40 FB
+ SET $7,16(IX),H / DD CB 10 FC
+ SET $7,32(IX),L / DD CB 20 FD
+ SET $7,48(IX) / DD CB 30 FE
+ SET $7,64(IX),A / DD CB 40 FF
+ INC 32(IY) / FD 34 20
+ DEC 48(IY) / FD 35 30
+ LD 64(IY),$16 / FD 36 40 10
+ LD B,32(IY) / FD 46 20
+ LD C,48(IY) / FD 4E 30
+ LD D,64(IY) / FD 56 40
+ LD E,16(IY) / FD 5E 10
+ LD H,32(IY) / FD 66 20
+ LD L,48(IY) / FD 6E 30
+ LD 64(IY),B / FD 70 40
+ LD 16(IY),C / FD 71 10
+ LD 32(IY),D / FD 72 20
+ LD 48(IY),E / FD 73 30
+ LD 64(IY),H / FD 74 40
+ LD 16(IY),L / FD 75 10
+ LD 32(IY),A / FD 77 20
+ LD A,48(IY) / FD 7E 30
+ ADD A,64(IY) / FD 86 40
+ ADC A,16(IY) / FD 8E 10
+ SUB A,32(IY) / FD 96 20
+ SBC A,48(IY) / FD 9E 30
+ AND A,64(IY) / FD A6 40
+ XOR A,16(IY) / FD AE 10
+ OR A,32(IY) / FD B6 20
+ CP A,48(IY) / FD BE 30
+ RLC 16(IY),B / FD CB 10 00
+ RLC 32(IY),C / FD CB 20 01
+ RLC 48(IY),D / FD CB 30 02
+ RLC 64(IY),E / FD CB 40 03
+ RLC 16(IY),H / FD CB 10 04
+ RLC 32(IY),L / FD CB 20 05
+ RLC 16(IY) / FD CB 10 06
+ RLC 32(IY),A / FD CB 20 07
+ RRC 48(IY),B / FD CB 30 08
+ RRC 64(IY),C / FD CB 40 09
+ RRC 16(IY),D / FD CB 10 0A
+ RRC 32(IY),E / FD CB 20 0B
+ RRC 48(IY),H / FD CB 30 0C
+ RRC 64(IY),L / FD CB 40 0D
+ RRC 32(IY) / FD CB 20 0E
+ RRC 16(IY),A / FD CB 10 0F
+ RL 32(IY),B / FD CB 20 10
+ RL 48(IY),C / FD CB 30 11
+ RL 64(IY),D / FD CB 40 12
+ RL 16(IY),E / FD CB 10 13
+ RL 32(IY),H / FD CB 20 14
+ RL 48(IY),L / FD CB 30 15
+ RL 48(IY) / FD CB 30 16
+ RL 16(IY),A / FD CB 10 17
+ RR 32(IY),B / FD CB 20 18
+ RR 48(IY),C / FD CB 30 19
+ RR 64(IY),D / FD CB 40 1A
+ RR 16(IY),E / FD CB 10 1B
+ RR 32(IY),H / FD CB 20 1C
+ RR 48(IY),L / FD CB 30 1D
+ RR 64(IY) / FD CB 40 1E
+ RR 16(IY),A / FD CB 10 1F
+ SLA 32(IY),B / FD CB 20 20
+ SLA 48(IY),C / FD CB 30 21
+ SLA 64(IY),D / FD CB 40 22
+ SLA 16(IY),E / FD CB 10 23
+ SLA 32(IY),H / FD CB 20 24
+ SLA 48(IY),L / FD CB 30 25
+ SLA 16(IY) / FD CB 10 26
+ SLA 16(IY),A / FD CB 10 27
+ SRA 32(IY),B / FD CB 20 28
+ SRA 48(IY),C / FD CB 30 29
+ SRA 64(IY),D / FD CB 40 2A
+ SRA 16(IY),E / FD CB 10 2B
+ SRA 32(IY),H / FD CB 20 2C
+ SRA 48(IY),L / FD CB 30 2D
+ SRA 32(IY) / FD CB 20 2E
+ SRA 48(IY),A / FD CB 30 2F
+ SLL 16(IY),B / FD CB 10 30
+ SLL 32(IY),C / FD CB 20 31
+ SLL 48(IY),D / FD CB 30 32
+ SLL 64(IY),E / FD CB 40 33
+ SLL 16(IY),H / FD CB 10 34
+ SLL 32(IY),L / FD CB 20 35
+ SLL 48(IY) / FD CB 30 36
+ SLL 16(IY),A / FD CB 10 37
+ SRL 32(IY),B / FD CB 20 38
+ SRL 48(IY),C / FD CB 30 39
+ SRL 64(IY),D / FD CB 40 3A
+ SRL 16(IY),E / FD CB 10 3B
+ SRL 32(IY),H / FD CB 20 3C
+ SRL 48(IY),L / FD CB 30 3D
+ SRL 64(IY) / FD CB 40 3E
+ SRL 16(IY),A / FD CB 10 3F
+ BIT $0,16(IY) / FD CB 10 46
+ BIT $1,32(IY) / FD CB 20 4E
+ BIT $2,48(IY) / FD CB 30 56
+ BIT $3,64(IY) / FD CB 40 5E
+ BIT $4,16(IY) / FD CB 10 66
+ BIT $5,32(IY) / FD CB 20 6E
+ BIT $6,48(IY) / FD CB 30 76
+ BIT $7,64(IY) / FD CB 40 7E
+ RES $0,16(IY),B / FD CB 10 80
+ RES $0,32(IY),C / FD CB 20 81
+ RES $0,48(IY),D / FD CB 30 82
+ RES $0,64(IY),E / FD CB 40 83
+ RES $0,16(IY),H / FD CB 10 84
+ RES $0,32(IY),L / FD CB 20 85
+ RES $0,48(IY) / FD CB 30 86
+ RES $0,64(IY),A / FD CB 40 87
+ RES $1,16(IY),B / FD CB 10 88
+ RES $1,32(IY),C / FD CB 20 89
+ RES $1,48(IY),D / FD CB 30 8A
+ RES $1,64(IY),E / FD CB 40 8B
+ RES $1,16(IY),H / FD CB 10 8C
+ RES $1,32(IY),L / FD CB 20 8D
+ RES $1,48(IY) / FD CB 30 8E
+ RES $1,64(IY),A / FD CB 40 8F
+ RES $2,16(IY),B / FD CB 10 90
+ RES $2,32(IY),C / FD CB 20 91
+ RES $2,48(IY),D / FD CB 30 92
+ RES $2,64(IY),E / FD CB 40 93
+ RES $2,16(IY),H / FD CB 10 94
+ RES $2,32(IY),L / FD CB 20 95
+ RES $2,48(IY) / FD CB 30 96
+ RES $2,64(IY),A / FD CB 40 97
+ RES $3,16(IY),B / FD CB 10 98
+ RES $3,32(IY),C / FD CB 20 99
+ RES $3,48(IY),D / FD CB 30 9A
+ RES $3,64(IY),E / FD CB 40 9B
+ RES $3,16(IY),H / FD CB 10 9C
+ RES $3,32(IY),L / FD CB 20 9D
+ RES $3,48(IY) / FD CB 30 9E
+ RES $3,64(IY),A / FD CB 40 9F
+ RES $4,16(IY),B / FD CB 10 A0
+ RES $4,32(IY),C / FD CB 20 A1
+ RES $4,48(IY),D / FD CB 30 A2
+ RES $4,64(IY),E / FD CB 40 A3
+ RES $4,16(IY),H / FD CB 10 A4
+ RES $4,32(IY),L / FD CB 20 A5
+ RES $4,48(IY) / FD CB 30 A6
+ RES $4,64(IY),A / FD CB 40 A7
+ RES $5,16(IY),B / FD CB 10 A8
+ RES $5,32(IY),C / FD CB 20 A9
+ RES $5,48(IY),D / FD CB 30 AA
+ RES $5,64(IY),E / FD CB 40 AB
+ RES $5,16(IY),H / FD CB 10 AC
+ RES $5,32(IY),L / FD CB 20 AD
+ RES $5,48(IY) / FD CB 30 AE
+ RES $5,64(IY),A / FD CB 40 AF
+ RES $6,16(IY),B / FD CB 10 B0
+ RES $6,32(IY),C / FD CB 20 B1
+ RES $6,48(IY),D / FD CB 30 B2
+ RES $6,64(IY),E / FD CB 40 B3
+ RES $6,16(IY),H / FD CB 10 B4
+ RES $6,32(IY),L / FD CB 20 B5
+ RES $6,48(IY) / FD CB 30 B6
+ RES $6,64(IY),A / FD CB 40 B7
+ RES $7,16(IY),B / FD CB 10 B8
+ RES $7,32(IY),C / FD CB 20 B9
+ RES $7,48(IY),D / FD CB 30 BA
+ RES $7,64(IY),E / FD CB 40 BB
+ RES $7,16(IY),H / FD CB 10 BC
+ RES $7,32(IY),L / FD CB 20 BD
+ RES $7,48(IY) / FD CB 30 BE
+ RES $7,64(IY),A / FD CB 40 BF
+ SET $0,16(IY),B / FD CB 10 C0
+ SET $0,32(IY),C / FD CB 20 C1
+ SET $0,48(IY),D / FD CB 30 C2
+ SET $0,64(IY),E / FD CB 40 C3
+ SET $0,16(IY),H / FD CB 10 C4
+ SET $0,32(IY),L / FD CB 20 C5
+ SET $0,48(IY) / FD CB 30 C6
+ SET $0,64(IY),A / FD CB 40 C7
+ SET $1,16(IY),B / FD CB 10 C8
+ SET $1,32(IY),C / FD CB 20 C9
+ SET $1,48(IY),D / FD CB 30 CA
+ SET $1,64(IY),E / FD CB 40 CB
+ SET $1,16(IY),H / FD CB 10 CC
+ SET $1,32(IY),L / FD CB 20 CD
+ SET $1,48(IY) / FD CB 30 CE
+ SET $1,64(IY),A / FD CB 40 CF
+ SET $2,16(IY),B / FD CB 10 D0
+ SET $2,32(IY),C / FD CB 20 D1
+ SET $2,48(IY),D / FD CB 30 D2
+ SET $2,64(IY),E / FD CB 40 D3
+ SET $2,16(IY),H / FD CB 10 D4
+ SET $2,32(IY),L / FD CB 20 D5
+ SET $2,48(IY) / FD CB 30 D6
+ SET $2,64(IY),A / FD CB 40 D7
+ SET $3,16(IY),B / FD CB 10 D8
+ SET $3,32(IY),C / FD CB 20 D9
+ SET $3,48(IY),D / FD CB 30 DA
+ SET $3,64(IY),E / FD CB 40 DB
+ SET $3,16(IY),H / FD CB 10 DC
+ SET $3,32(IY),L / FD CB 20 DD
+ SET $3,48(IY) / FD CB 30 DE
+ SET $3,64(IY),A / FD CB 40 DF
+ SET $4,16(IY),B / FD CB 10 E0
+ SET $4,32(IY),C / FD CB 20 E1
+ SET $4,48(IY),D / FD CB 30 E2
+ SET $4,64(IY),E / FD CB 40 E3
+ SET $4,16(IY),H / FD CB 10 E4
+ SET $4,32(IY),L / FD CB 20 E5
+ SET $4,48(IY) / FD CB 30 E6
+ SET $4,64(IY),A / FD CB 40 E7
+ SET $5,16(IY),B / FD CB 10 E8
+ SET $5,32(IY),C / FD CB 20 E9
+ SET $5,48(IY),D / FD CB 30 EA
+ SET $5,64(IY),E / FD CB 40 EB
+ SET $5,16(IY),H / FD CB 10 EC
+ SET $5,32(IY),L / FD CB 20 ED
+ SET $5,48(IY) / FD CB 30 EE
+ SET $5,64(IY),A / FD CB 40 EF
+ SET $6,16(IY),B / FD CB 10 F0
+ SET $6,32(IY),C / FD CB 20 F1
+ SET $6,48(IY),D / FD CB 30 F2
+ SET $6,64(IY),E / FD CB 40 F3
+ SET $6,16(IY),H / FD CB 10 F4
+ SET $6,32(IY),L / FD CB 20 F5
+ SET $6,48(IY) / FD CB 30 F6
+ SET $6,64(IY),A / FD CB 40 F7
+ SET $7,16(IY),B / FD CB 10 F8
+ SET $7,32(IY),C / FD CB 20 F9
+ SET $7,48(IY),D / FD CB 30 FA
+ SET $7,64(IY),E / FD CB 40 FB
+ SET $7,16(IY),H / FD CB 10 FC
+ SET $7,32(IY),L / FD CB 20 FD
+ SET $7,48(IY) / FD CB 30 FE
+ SET $7,64(IY),A / FD CB 40 FF
--- /dev/null
+++ b/doc/myro.txt
@@ -1,0 +1,177 @@
+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?
--- a/inc/myro.h
+++ b/inc/myro.h
@@ -63,6 +63,13 @@
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);
--- a/nm/main.c
+++ b/nm/main.c
@@ -1,5 +1,6 @@
static char sccsid[] = "@(#) ./nm/main.c";
+#include <ctype.h>
#include <errno.h>
#include <limits.h>
#include <stdint.h>
@@ -30,12 +31,10 @@
fgetpos(fp, &pos);
fread(magic, sizeof(magic), 1, fp);
- if (!ferror(fp)) {
- if (!strncmp(magic, MYROMAGIC, MYROMAGIC_SIZ))
- return 1;
- }
-
fsetpos(fp, &pos);
+
+ if (!ferror(fp) && !strncmp(magic, MYROMAGIC, MYROMAGIC_SIZ))
+ return 1;
return 0;
}
@@ -47,13 +46,10 @@
fgetpos(fp, &pos);
fread(magic, sizeof(magic), 1, fp);
-
- if (!ferror(fp)) {
- if (!strncmp(magic, ARMAGIC, ARMAGIC_SIZ))
- return 1;
- }
-
fsetpos(fp, &pos);
+
+ if (!ferror(fp) && !strncmp(magic, ARMAGIC, ARMAGIC_SIZ))
+ return 1;
return 0;
}
@@ -71,11 +67,34 @@
static int
typeof(struct myrosym *sym)
{
- return 'U';
+ int t, flags = sym->flags;
+
+ switch (sym->section) {
+ case MYRO_TEXT:
+ t = 't';
+ break;
+ case MYRO_DATA:
+ t = 'd';
+ break;
+ case MYRO_BSS:
+ t = (flags & MYROSYM_COMMON) ? 'c' : 'b';
+ break;
+ case MYRO_ABS:
+ t = 'a';
+ break;
+ default:
+ t = (flags & MYROSYM_UNDEF) ? 'u' : '?';
+ break;
+ }
+ if (flags & MYROSYM_ABS)
+ t = 'a';
+ if (flags & MYROSYM_EXTERN)
+ t = tolower(t);
+ return t;
}
static void
-print(char *file, char *member, struct myrosym *sym, FILE *fp)
+print(char *file, char *member, struct myrosym *sym)
{
char *fmt, *name = strings + sym->name;
int type = typeof(sym);
@@ -86,9 +105,9 @@
return;
if (Aflag)
- fprintf(fp, (archflag) ? "%s[%s]: " : "%s: ", file, member);
+ printf((archflag) ? "%s[%s]: " : "%s: ", file, member);
if (Pflag) {
- fprintf(fp, "%s %c", name, type);
+ printf("%s %c", name, type);
if (type != 'U') {
if (radix == 8)
fmt = "%llo %llo";
@@ -96,7 +115,7 @@
fmt = "%llu %llu";
else
fmt = "%llx %llx";
- fprintf(fp, fmt, sym->offset, sym->len);
+ printf(fmt, sym->offset, sym->len);
}
} else {
if (type == 'U')
@@ -107,10 +126,10 @@
fmt = "%016.16lld";
else
fmt = "%016.16llx";
- fprintf(fp, fmt, sym->offset);
- fprintf(fp, " %c %s", type, name);
+ printf(fmt, sym->offset);
+ printf(" %c %s", type, name);
}
- putc('\n', fp);
+ putchar('\n');
}
static void
@@ -154,13 +173,13 @@
for (i = 0; i < n; ++i) {
if (rdmyrosym(fp, &syms[i]) < 0)
- goto free_arrays;
+ goto symbol_error;
if (syms[i].name >= hdr.strsize)
goto offset_overflow;
}
qsort(syms, n, sizeof(*syms), cmp);
for (i = 0; i < n; ++i)
- print(fname, member, &syms[i], fp);
+ print(fname, member, &syms[i]);
free_arrays:
@@ -168,6 +187,10 @@
free(strings);
return;
+symbol_error:
+ fprintf(stderr, "nm: %s: error reading symbols\n", fname);
+ goto free_arrays;
+
offset_overflow:
fprintf(stderr, "nm: %s: overflow in headers of archive\n",
fname);
@@ -273,8 +296,8 @@
if (argc == 0) {
doit("a.out");
} else {
- while (argc-- > 0)
- doit(*++argv);
+ for ( ; *argv; ++argv)
+ doit(*argv);
}
return 0;
--- a/objdump/main.c
+++ b/objdump/main.c
@@ -222,7 +222,7 @@
for (off = 0; ; off += 32) {
printf(" %016llX:", off);
for (i = 0; i < 2; i++) {
- for (j = 0; j < 16; j++) {
+ for (j = 0; j < 8; j++) {
if ((c = getc(obj->fp)) == EOF)
goto exit_loop;
printf(" %02X", c);