From: Tormod Volden Date: Sun, 12 Apr 2015 20:26:30 +0000 (+0200) Subject: Library: Generate 6809 syscall glue X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=0269e7be771e9d6564fd4d7a8aba086a70003d8e;p=FUZIX.git Library: Generate 6809 syscall glue Signed-off-by: Tormod Volden --- diff --git a/Library/Makefile b/Library/Makefile index 0158ee97..4e45b6ca 100644 --- a/Library/Makefile +++ b/Library/Makefile @@ -10,4 +10,5 @@ clean: tools/syscall: tools/syscall.c ../Kernel/include/syscall_name.h tools/syscall-z88dk: tools/syscall-z88dk.c ../Kernel/include/syscall_name.h tools/syscall_6502: tools/syscall_6502.c ../Kernel/include/syscall_name.h +tools/syscall_6809: tools/syscall_6809.c ../Kernel/include/syscall_name.h tools/binman: tools/binman.c diff --git a/Library/libs/fuzix6809/syscall.s b/Library/libs/fuzix6809/syscall.s new file mode 100644 index 00000000..8e586d99 --- /dev/null +++ b/Library/libs/fuzix6809/syscall.s @@ -0,0 +1,15 @@ + .globl __syscall + .globl _errno + + .area .text + +__syscall: + swi2 + bne error + rts +error: + sta _errno + ldx #0 + stx _errno+1 + leax -1,x ; Return $FFFF (-1) + rts diff --git a/Library/tools/syscall_6809.c b/Library/tools/syscall_6809.c new file mode 100644 index 00000000..64a05774 --- /dev/null +++ b/Library/tools/syscall_6809.c @@ -0,0 +1,68 @@ +/* + * Generate the syscall functions + */ + +#include +#include +#include +#include "syscall_name.h" + +static char namebuf[128]; + +static void write_call(int n) +{ + FILE *fp; + snprintf(namebuf, 128, "fuzix6809/syscall_%s.s", syscall_name[n]); + fp = fopen(namebuf, "w"); + if (fp == NULL) { + perror(namebuf); + exit(1); + } + fprintf(fp, "\t.area .text\n\n"); + fprintf(fp, "\t.globl __syscall\n"); + fprintf(fp, "\t.globl _%s\n\n", syscall_name[n]); + fprintf(fp, "_%s:\n\tldx #%d\n", syscall_name[n], n); + fprintf(fp, "\tjmp __syscall\n"); + fclose(fp); +} + +static void write_call_table(void) +{ + int i; + for (i = 0; i < NR_SYSCALL; i++) + write_call(i); +} + +static void write_makefile(void) +{ + int i; + FILE *fp = fopen("fuzix6809/Makefile", "w"); + if (fp == NULL) { + perror("Makefile"); + exit(1); + } + fprintf(fp, "# Autogenerated by tools/syscall_6809\n"); + fprintf(fp, "CROSS_AS=m6809-unknown-as\nCROSS_LD=m6809-unknown-ld\nCROSS_AR=m6809-unknown-ar\n"); + fprintf(fp, "ASOPTS=\n\n"); + fprintf(fp, "ASYS=syscall$(PLATFORM).s\n"); + fprintf(fp, "ASRCS = syscall_%s.s\n", syscall_name[0]); + for (i = 1; i < NR_SYSCALL; i++) + fprintf(fp, "ASRCS += syscall_%s.s\n", syscall_name[i]); + fprintf(fp, "\n\nASRCALL = $(ASRCS) $(ASYS)\n"); + fprintf(fp, "\nAOBJS = $(ASRCALL:.s=.o)\n\n"); + fprintf(fp, "syslib.lib: $(AOBJS)\n"); + fprintf(fp, "\techo $(AOBJS) >syslib.l\n"); + fprintf(fp, "\t$(CROSS_AR) rc syslib.lib $(AOBJS)\n\n"); + fprintf(fp, "$(AOBJS): %%.o: %%.s\n"); + fprintf(fp, "\t$(CROSS_AS) $(ASOPTS) -o $*.o $<\n\n"); + fprintf(fp, "clean:\n"); + fprintf(fp, "\trm -f $(AOBJS) $(ASRCS) syslib.lib syslib.l *~\n\n"); + fclose(fp); +} + +int main(int argc, char *argv[]) +{ + write_makefile(); + write_call_table(); + exit(0); +}