From 802c72dfa9f2cfea3dfbbcf67329a1255799f264 Mon Sep 17 00:00:00 2001 From: Alexander Tsidaev Date: Mon, 24 Nov 2014 12:15:12 -0500 Subject: [PATCH] apps: add binman support and produce FUZIX executables --- Applications/util/Makefile | 11 +++++++---- Library/Makefile | 6 +++++- Library/libs/crt0.s | 1 - Library/tools/binman.c | 31 ++++++++++++++++++++----------- 4 files changed, 32 insertions(+), 17 deletions(-) diff --git a/Applications/util/Makefile b/Applications/util/Makefile index 8c1ac13d..f96f5a96 100644 --- a/Applications/util/Makefile +++ b/Applications/util/Makefile @@ -3,13 +3,14 @@ ASM = sdasz80 AR = sdar LINKER = sdcc -CODELOC= 0xC000 +PROGLOAD=`(cat ../../Kernel/platform/config.h; echo PROGLOAD) | cpp -E | tail -n1` #CC_OPT = -mz80 -c --opt-code-size --std-c89 --max-allocs-per-node 2000000 -I../../Library/include CC_OPT = -mz80 --std-c99 -c --opt-code-size --max-allocs-per-node 20000 -I../../Library/include #--oldralloc ASM_OPT = -l -o -s -LINKER_OPT = -mz80 --nostdlib --no-std-crt0 --code-loc $(CODELOC) --data-loc 0 +LINKER_OPT = -mz80 --nostdlib --no-std-crt0 --code-loc $(PROGLOAD) --data-loc 0 +BINMAN = ../../Library/tools/binman .SUFFIXES: .c .rel @@ -86,10 +87,12 @@ $(OBJS): $(SRCS) %: %.rel $(LINKER) $(LINKER_OPT) ../../Library/libs/crt0.rel $< $(LIBS) -o $@.ihx - hex2bin $@.ihx + makebin -s 65536 $@.ihx $@.tmp + $(BINMAN) $(PROGLOAD) $@.tmp $@.map $@ + chmod +x $@ clean: - rm -f $(OBJS) $(APPS) core *~ *.asm *.lst *.sym *.map *.noi *.lk *.ihx *.bin + rm -f $(OBJS) $(APPS) $(SRCS:.c=) core *~ *.asm *.lst *.sym *.map *.noi *.lk *.ihx *.tmp rmbak: rm -f *~ core diff --git a/Library/Makefile b/Library/Makefile index 0025278d..8ad77aec 100644 --- a/Library/Makefile +++ b/Library/Makefile @@ -1,5 +1,9 @@ # Top level makefile for library +CFLAGS += -I../Kernel/include + +all: tools/syscall tools/binman + tools/syscall: tools/syscall.c ../Kernel/include/syscall_name.h - $(CC) $(CFLAGS) -I../Kernel/include tools/syscall.c -o tools/syscall +tools/binman: tools/binman.c diff --git a/Library/libs/crt0.s b/Library/libs/crt0.s index 74e61f45..b094e1d1 100644 --- a/Library/libs/crt0.s +++ b/Library/libs/crt0.s @@ -27,7 +27,6 @@ .area _CODE - .ds 0x100 ; start at 0x100 start: jp start2 .db 'F' diff --git a/Library/tools/binman.c b/Library/tools/binman.c index 1e4d73f1..c2cb69fa 100644 --- a/Library/tools/binman.c +++ b/Library/tools/binman.c @@ -16,6 +16,7 @@ static unsigned int l__INITIALIZER; static unsigned int s__DATA; +static unsigned int progload = 0x100; static void ProcessMap(FILE *fp) @@ -47,39 +48,47 @@ static void ProcessMap(FILE *fp) int main(int argc, char *argv[]) { FILE *map, *bin; + int argp = 1; - if (argc != 4) { - fprintf(stderr, "%s: [binary] [map] [output]\n", argv[0]); + if (argc != 4 && argc != 5) { + fprintf(stderr, "%s: [PROGLOAD address] \n", argv[0]); exit(1); } - bin = fopen(argv[1], "r"); + + if (argc == 5 && sscanf(argv[argp++], "%x", &progload) != 1) + { + fprintf(stderr, "%s: PROGLOAD parse error: %s\n", argv[0], argv[argp - 1]); + exit(1); + } + + bin = fopen(argv[argp++], "r"); if (bin == NULL) { - perror(argv[1]); + perror(argv[argp - 1]); exit(1); } if (fread(buf, 1, 65536, bin) == 0) { - fprintf(stderr, "%s: read error on %s\n", argv[0], argv[1]); + fprintf(stderr, "%s: read error on %s\n", argv[0], argv[argp - 1]); exit(1); } fclose(bin); - map = fopen(argv[2], "r"); + map = fopen(argv[argp++], "r"); if (map == NULL) { - perror(argv[2]); + perror(argv[argp - 1]); exit(1); } ProcessMap(map); fclose(map); - bin = fopen(argv[3], "w"); + bin = fopen(argv[argp++], "w"); if (bin == NULL) { - perror(argv[3]); + perror(argv[argp - 1]); exit(1); } memcpy(buf + s__INITIALIZED, buf + s__INITIALIZER, l__INITIALIZER); /* Write out everything that is data, omit everything that will be zapped */ - if (fwrite(buf + 0x100, s__DATA - 0x100, 1, bin) != 1) { - perror(argv[3]); + if (fwrite(buf + progload, s__DATA - progload, 1, bin) != 1) { + perror(argv[argp - 1]); exit(1); } fclose(bin); -- 2.34.1