ref: ea7be436724a770dc5e3f43ac32dd7393c0b0057
parent: 7df2442d7a009b63be92736140b7d0323eb0953c
parent: b96020ecf7d028aca4079de9d484d3fecd0b93e9
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Wed Dec 13 02:38:44 EST 2017
Merge branch 'master' of ssh://simple-cc.org:/var/gitrepos/scc
--- a/as/as.h
+++ b/as/as.h
@@ -119,7 +119,7 @@
/* symbol.c */
extern void isections(void);
-extern void emit(Section *sec, char *bytes, int nbytes);
+extern void emit(char *bytes, int nbytes);
extern Section *section(char *name);
extern Symbol *tmpsym(TUINT val);
extern void killtmp(void);
--- a/as/ins.c
+++ b/as/ins.c
@@ -24,7 +24,7 @@
void
noargs(Op *op, Node **args)
{
- emit(cursec, op->bytes, op->size);
+ emit(op->bytes, op->size);
}
void
@@ -37,7 +37,7 @@
if (sym->flags & FUNDEF)
reloc(sym, 0, siz, siz * 8, 0);
- emit(cursec, tobytes(sym->value, siz, endian), siz);
+ emit(tobytes(sym->value, siz, endian), siz);
}
}
--- a/as/symbol.c
+++ b/as/symbol.c
@@ -135,7 +135,8 @@
sym = lookup(name, FUNDEF);
if (pass == 1 && (sym->flags & FUNDEF) == 0)
error("redefinition of label '%s'", name);
- sym->flags &= ~FUNDEF;
+ if (cursec->flags & SABS)
+ sym->flags &= ~FUNDEF;
sym->value = cursec->curpc;
if (*name != '.')
@@ -222,10 +223,12 @@
}
void
-emit(Section *sec, char *bytes, int n)
+emit(char *bytes, int n)
{
- if (sec->mem)
- memcpy(&sec->mem[sec->pc - sec->base], bytes, n);
+ if (cursec->mem) {
+ size_t len = cursec->pc - cursec->base;
+ memcpy(&cursec->mem[len], bytes, n);
+ }
incpc(n);
}
--- a/as/target/gen.awk
+++ b/as/target/gen.awk
@@ -85,8 +85,10 @@
out = out "AREG_A"
} else if (match(a, /^indir_HL/)) {
out = out "AINDER_HL"
+ } else if (match(a, /^HL/)) {
+ out = out "AREG_HL"
} else {
- print "wrong arg", a
+ print "wrong arg", a > "/dev/stderr"
exit 1
}
a = substr(a, RLENGTH+1)
--- a/as/target/x80/ins.c
+++ b/as/target/x80/ins.c
@@ -90,7 +90,7 @@
memcpy(buf, op->bytes, n-1);
buf[n-1] = par2->sym->value;
buf[n-2] |= reg2int(par1->sym->argtype) << 3;
- emit(cursec, buf, n);
+ emit(buf, n);
}
void
@@ -104,10 +104,27 @@
memcpy(buf, op->bytes, n-1);
buf[n-1] = par2->sym->value;
- emit(cursec, buf, n);
+ emit(buf, n);
}
void
+r_imm16(Op *op, Node **args)
+{
+ Node *par1, *par2;
+ unsigned char buf[3];
+ unsigned val;
+ int n = op->size;
+
+ par2 = args[1];
+
+ memcpy(buf, op->bytes, n-2);
+ val = par2->sym->value;
+ buf[n-1] = val >> 8;
+ buf[n-2] = val;
+ emit(buf, n);
+}
+
+void
r8_r8(Op *op, Node **args)
{
Node *par1, *par2;
@@ -119,7 +136,7 @@
memcpy(buf, op->bytes, n);
buf[n-1] |= reg2int(par1->sym->argtype) << 3 |
reg2int(par2->sym->argtype);
- emit(cursec, buf, n);
+ emit(buf, n);
}
void
@@ -134,7 +151,7 @@
memcpy(buf, op->bytes, n);
buf[n-1] |= reg2int(par2->sym->argtype);
- emit(cursec, buf, n);
+ emit(buf, n);
}
void
@@ -149,7 +166,7 @@
memcpy(buf, op->bytes, n);
buf[n-1] |= reg2int(par2->sym->argtype) << 3;
- emit(cursec, buf, n);
+ emit(buf, n);
}
void
@@ -164,5 +181,5 @@
memcpy(buf, op->bytes, n);
buf[n-1] |= reg2int(par1->sym->argtype) << 3;
- emit(cursec, buf, n);
+ emit(buf, n);
}
--- a/as/target/x80/x80.dat
+++ b/as/target/x80/x80.dat
@@ -67,6 +67,8 @@
LD indir_HL,reg_r 1 0x70 xx_r8_2 Z80,R800,GB80
LD reg_r,indir_HL 1 0x46 r8_xx_1 Z80,R800,GB80
+LD HL,imm16 3 0x21 r_imm16 Z80,R800,GB80
+
ADD regA,reg_r 1 0x80 xx_r8_2 Z80,R800,GB80
ADD regA,reg_p 2 0xdd,0x80 xx_r8_2 Z80,R800
ADD regA,reg_q 2 0xfd,0x80 xx_r8_2 Z80,R800
--- a/as/target/z80/proc.c
+++ b/as/target/z80/proc.c
@@ -93,6 +93,10 @@
if (!qclass(np->sym->argtype))
return 0;
break;
+ case AREG_HL:
+ if (np->op != AREG && np->sym->argtype != AREG_HL)
+ return 0;
+ return 1;
case AIMM8:
case AIMM16:
case AIMM32: