shithub: scc

Download patch

ref: 91bbc191c7da87926dae3557cc57cd5bd75d0975
parent: 528d5a761438016ceeb6785fda0ce643a2aa85e0
author: Roberto E. Vargas Caballero <[email protected]>
date: Wed Sep 27 11:03:37 EDT 2017

[as] Add basic support for z80

--- a/as/target/amd64/ins.c
+++ b/as/target/amd64/ins.c
@@ -2,7 +2,6 @@
 
 #include "../../../inc/scc.h"
 #include "../../as.h"
-#include "ins.h"
 
 TUINT maxaddr = 0xFFFFFFFFFFFFFFFF;
 int endian = LITTLE_ENDIAN;
--- 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)
--- a/as/target/gen.awk
+++ b/as/target/gen.awk
@@ -3,13 +3,12 @@
 		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}
 
--- a/as/target/i386/ins.c
+++ b/as/target/i386/ins.c
@@ -2,7 +2,6 @@
 
 #include "../../../inc/scc.h"
 #include "../../as.h"
-#include "ins.h"
 
 TUINT maxaddr = 0xFFFFFFFF;
 int endian = LITTLE_ENDIAN;
--- 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)
--- /dev/null
+++ b/as/target/x80/proc.h
@@ -1,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,
+};
--- /dev/null
+++ b/as/target/x80/x80.dat
@@ -1,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
--- /dev/null
+++ b/as/target/z80/ins.c
@@ -1,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;
--- /dev/null
+++ b/as/target/z80/proc.c
@@ -1,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;
+}
--- /dev/null
+++ b/as/target/z80/target.mk
@@ -1,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)
--- a/config.mk.def
+++ b/config.mk.def
@@ -6,6 +6,7 @@
 # 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
 
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -2,7 +2,7 @@
 
 include ../config.mk
 
-DIRS = scc crt
+DIRS = scc
 
 all dep clean distclean:
 	@pwd=$$PWD; \