scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit 593b85cfb9dea5ad66244a7293885a0f1fb190a8
parent 09b76524552578f790b8252c9a85bd6128b06953
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed, 27 Sep 2017 15:03:37 +0100

[as] Add basic support for z80

Diffstat:
Mas/target/amd64/ins.c | 1-
Das/target/amd64/ins.h | 0
Mas/target/amd64/target.mk | 11+++++------
Mas/target/gen.awk | 5++---
Mas/target/i386/ins.c | 1-
Das/target/i386/ins.h | 0
Mas/target/i386/target.mk | 12+++++-------
Aas/target/x80/proc.h | 38++++++++++++++++++++++++++++++++++++++
Aas/target/x80/x80.dat | 18++++++++++++++++++
Aas/target/z80/ins.c | 7+++++++
Aas/target/z80/proc.c | 72++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aas/target/z80/target.mk | 14++++++++++++++
Mconfig.mk.def | 1+
Mlib/Makefile | 2+-
14 files changed, 163 insertions(+), 19 deletions(-)

diff --git a/as/target/amd64/ins.c b/as/target/amd64/ins.c @@ -2,7 +2,6 @@ static char sccsid[] = "@(#) ./as/target/amd64/ins.c"; #include "../../../inc/scc.h" #include "../../as.h" -#include "ins.h" TUINT maxaddr = 0xFFFFFFFFFFFFFFFF; int endian = LITTLE_ENDIAN; diff --git a/as/target/amd64/ins.h b/as/target/amd64/ins.h diff --git a/as/target/amd64/target.mk b/as/target/amd64/target.mk @@ -1,15 +1,14 @@ -target/amd64/instbl.o: target/amd64/ins.h +AMD64_LST = target/amd64/instbl.o target/amd64/ins.o target/amd64/proc.o + +$(AMD64_LST): target/x86/proc.h target/amd64/instbl.c: target/gen.awk target/x86/x86.dat set -e ;\ rm -f $@;\ trap "rm -f $$$$.c" 0 2 3; \ - awk -v bits=BITS32 -v proc=x86 \ + awk -v cpu=BITS64 -v family=x86 \ -f target/gen.awk \ < target/x86/x86.dat > $$$$.c && mv $$$$.c $@ -OBJ-amd64 = $(OBJ) \ - target/amd64/instbl.o \ - target/i386/ins.o \ - target/amd64/proc.o +OBJ-amd64 = $(OBJ) $(AMD64_LST) diff --git a/as/target/gen.awk b/as/target/gen.awk @@ -3,13 +3,12 @@ BEGIN { FS = "\t" printf "#include \"../../../inc/scc.h\"\n"\ "#include \"../../as.h\"\n"\ - "#include \"../" proc "/proc.h\"\n"\ - "#include \"ins.h\"\n\n" + "#include \"../" family "/proc.h\"\n" nop = 0; nvar = 0 } {sub(/#.*/,"")} -$6 !~ bits {next} +$6 !~ cpu {next} /^$/ {next} diff --git a/as/target/i386/ins.c b/as/target/i386/ins.c @@ -2,7 +2,6 @@ static char sccsid[] = "@(#) ./as/target/i386/ins.c"; #include "../../../inc/scc.h" #include "../../as.h" -#include "ins.h" TUINT maxaddr = 0xFFFFFFFF; int endian = LITTLE_ENDIAN; diff --git a/as/target/i386/ins.h b/as/target/i386/ins.h diff --git a/as/target/i386/target.mk b/as/target/i386/target.mk @@ -1,16 +1,14 @@ -target/i386/ins.o: target/i386/ins.h -target/i386/instbl.o: target/i386/ins.h +I386_LST = target/i386/instbl.o target/i386/ins.o target/i386/proc.o + +$(I386_LST): target/x86/proc.h target/i386/instbl.c: target/gen.awk target/x86/x86.dat set -e ;\ rm -f $@;\ trap "rm -f $$$$.c" 0 2 3; \ - awk -v bits=BITS32 -v proc=x86 \ + awk -v cpu=BITS32 -v family=x86 \ -f target/gen.awk \ < target/x86/x86.dat > $$$$.c && mv $$$$.c $@ -OBJ-i386 = $(OBJ) \ - target/i386/instbl.o \ - target/i386/ins.o \ - target/i386/proc.o +OBJ-i386 = $(OBJ) $(I386_LST) diff --git a/as/target/x80/proc.h b/as/target/x80/proc.h @@ -0,0 +1,38 @@ + +enum args { + AIMM = 1, + + AIMM8, + AIMM16, + AIMM32, + AIMM64, + + AREG_AF, + AREG_A, + AREG_F, + + AREG_BC, + AREG_B, + AREG_C, + + AREG_HL, + AREG_H, + AREG_L, + + AREG_DE, + AREG_D, + AREG_E, + + AREG_IX, + AREG_IXL, + AREG_IXH, + + AREG_IY, + AREG_IYL, + AREG_IYH, + + AREG_R, + AREG_AF_, + + AREP, +}; diff --git a/as/target/x80/x80.dat b/as/target/x80/x80.dat @@ -0,0 +1,18 @@ +# Tab 16, tabs 16, :set ts=16 +# op args size bytes format cpu +.DB imm8+ 0 none defb Z80,R800,GB80 +.DEFB imm8+ 0 none defb Z80,R800,GB80 +.BYTE imm8+ 0 none defb Z80,R800,GB80 +.DW imm16+ 0 none defw Z80,R800,GB80 +.DEFW imm16+ 0 none defw Z80,R800,GB80 +.SHORT imm16+ 0 none defw Z80,R800,GB80 +.WORD imm16+ 0 none defw Z80,R800,GB80 +.DD imm32+ 0 none defd Z80,R800,GB80 +.DEFD imm32+ 0 none defd Z80,R800,GB80 +.LONG imm32+ 0 none defd Z80,R800,GB80 +.INT imm16+ 0 none defd Z80,R800,GB80 +.DQ imm64+ 0 none defq Z80,R800,GB80 +.DEFQ imm64+ 0 none defq Z80,R800,GB80 +.EQU imm16 0 none equ Z80,R800,GB80 +NOP none 1 0x00 direct Z80,R800,GB80 +RET none 1 0xc9 direct Z80,R800,GB80 diff --git a/as/target/z80/ins.c b/as/target/z80/ins.c @@ -0,0 +1,7 @@ +static char sccsid[] = "@(#) ./as/target/i386/ins.c"; + +#include "../../../inc/scc.h" +#include "../../as.h" + +TUINT maxaddr = 0xFFFFFFFF; +int endian = LITTLE_ENDIAN; diff --git a/as/target/z80/proc.c b/as/target/z80/proc.c @@ -0,0 +1,72 @@ +static char sccsid[] = "@(#) ./as/target/i386/proc.c"; + +#include <stdlib.h> + +#include "../../../inc/scc.h" +#include "../../as.h" +#include "../x80/proc.h" + +void +iarch(void) +{ + static struct { + char *name; + char type; + } regs[] = { + "AF", AREG_AF, + "A", AREG_A, + "F", AREG_F, + + "BC", AREG_BC, + "B", AREG_B, + "C", AREG_C, + + "HL", AREG_HL, + "H", AREG_H, + "L", AREG_L, + + "DE", AREG_DE, + "D", AREG_D, + "E", AREG_E, + + "IX", AREG_IX, + "IXL", AREG_IXL, + "IXH", AREG_IXH, + + "IY", AREG_IY, + "IYL", AREG_IYL, + "IYH", AREG_IYH, + + "R", AREG_R, + "AF_", AREG_AF_, + + NULL, + }; +} + +int +match(Op *op, Node **args) +{ + char *p; + int a, olda; + + if (!op->args) + return args == NULL; + + for (p = op->args; *p; ++p) { + if (*p != AREP) + a = *p; + else + --p; + + switch (a) { + case AIMM8: + case AIMM16: + case AIMM32: + case AIMM64: + default: + abort(); + } + } + return 1; +} diff --git a/as/target/z80/target.mk b/as/target/z80/target.mk @@ -0,0 +1,14 @@ + +Z80_LST = target/z80/instbl.o target/z80/ins.o target/z80/proc.o + +$(Z80_LST): target/x80/proc.h + +target/z80/instbl.c: target/gen.awk target/x80/x80.dat + set -e ;\ + rm -f $@;\ + trap "rm -f $$$$.c" 0 2 3; \ + awk -v cpu=Z80 -v family=x80 \ + -f target/gen.awk \ + < target/x80/x80.dat > $$$$.c && mv $$$$.c $@ + +OBJ-z80 = $(OBJ) $(Z80_LST) diff --git a/config.mk.def b/config.mk.def @@ -6,6 +6,7 @@ VERSION = 0.1 # element of the list becomes the default target TARGETS = amd64-sysv-linux-elf \ + z80-scc-none-none \ i386-sysv-linux-elf \ amd64-sysv-openbsd-elf diff --git a/lib/Makefile b/lib/Makefile @@ -2,7 +2,7 @@ include ../config.mk -DIRS = scc crt +DIRS = scc all dep clean distclean: @pwd=$$PWD; \