From: Will Sowerbutts Date: Fri, 6 Jan 2017 19:14:31 +0000 (+0000) Subject: Kernel: Add "fuzix-loader" boot mechansim X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=3d282a73eba84609c3662bf55e81aeaa476da8d4;p=FUZIX.git Kernel: Add "fuzix-loader" boot mechansim This provides a way to build a Fuzix application that loads and boots a different Fuzix kernel version. This is very useful for testing new kernels -- just load the file onto a running Fuzix system and run it. It will sync the disks, steal control from the running kernel, and set the new kernel booting. This mechanism requires the kernel to support booting from arbitrary locations in memory. This is analagous to the existing "cpm-loader" mechanism and re-uses the same tools. Tested and confirmed working on p112, n8vem-mark4 and zeta-v2. --- diff --git a/Kernel/cpm-loader/.gitignore b/Kernel/cpm-loader/.gitignore index e3eb0d4d..8e99cca9 100644 --- a/Kernel/cpm-loader/.gitignore +++ b/Kernel/cpm-loader/.gitignore @@ -1,3 +1,5 @@ +fuzixload.bin +fuzixload.ihx cpmload.bin cpmload.ihx makecpmloader diff --git a/Kernel/cpm-loader/Makefile b/Kernel/cpm-loader/Makefile index 6138e478..ddc7b562 100644 --- a/Kernel/cpm-loader/Makefile +++ b/Kernel/cpm-loader/Makefile @@ -1,4 +1,4 @@ -all: makecpmloader cpmload.bin +all: makecpmloader cpmload.bin fuzixload.bin makecpmloader: makecpmloader.c @@ -7,5 +7,10 @@ cpmload.bin: cpmload.s sdldz80 -nmi cpmload.rel makebin -p cpmload.ihx > cpmload.bin +fuzixload.bin: fuzixload.s + $(CROSS_AS) $(ASOPTS) fuzixload.s + sdldz80 -nmi fuzixload.rel + makebin -p fuzixload.ihx > fuzixload.bin + clean: rm -f *~ *.rst *.lst *.asm *.bin *.sym *.rel *.map *.ihx makecpmloader diff --git a/Kernel/cpm-loader/fuzixload.s b/Kernel/cpm-loader/fuzixload.s new file mode 100644 index 00000000..63d63acc --- /dev/null +++ b/Kernel/cpm-loader/fuzixload.s @@ -0,0 +1,74 @@ + .module fuzixload + + .area _LOADER (ABS) + .org 0x100 + +start: ; jump to start of code + jp start2 + + ; fuzix executable header -------------------------- + .db 'F' + .db 'Z' + .db 'X' + .db '1' + + .db 0x01 ; page to load at + .dw 0 ; chmem ("0 - 'all'") + .dw 0 ; gives us code size info + .dw 0 ; gives us data size info + .dw 0 ; bss size info + .dw 0 ; spare + ; -------------------------------------------------- + +msg: .ascii 'booting ...\r\n' +endmsg: + +start2: + ; sync() + ld hl, #11 ; syscall # + push hl + rst #0x30 ; execute + + ; write(0, msg, strlen(msg)); + ld hl, #(endmsg-msg) ; count + push hl + ld hl, #msg ; buffer + push hl + ld hl, #0 ; fd + push hl + ld hl, #8 ; syscall # + push hl + rst #0x30 ; execute + + ; sync() + ld hl, #11 ; syscall # + push hl + rst #0x30 ; execute + + di ; now we steal control of the machine from the old kernel! + + ld de, #0 ; copy ourselves to bottom of RAM + ld hl, #(doload) ; start of loader code + ld bc, #(endloader-doload) ; length of our loader + ldir ; copy copy copy! + ld hl, (load_address) + ld sp, hl ; stash copy of entry vector in SP for now + ex de, hl ; load_address to de + ld hl, #payload_start + ld bc, (load_length) + jp 0 ; jump and perform copy in low memory + + ; this code gets copied to .org 0 +doload: + ldir ; copy image into correct place + ld hl, #0 + add hl, sp ; recover entry vector + jp (hl) ; run image +endloader: ; end of code to copy + + ; the data is in a trailer, with a 4-byte header: +load_address: + .ds 2 +load_length: + .ds 2 +payload_start: diff --git a/Kernel/cpu-z180/image.mk b/Kernel/cpu-z180/image.mk index b38c6092..9beccfac 100644 --- a/Kernel/cpu-z180/image.mk +++ b/Kernel/cpu-z180/image.mk @@ -14,7 +14,7 @@ tools/bintomdv: tools/bintomdv.c tools/bankld/sdldz80: +(cd tools/bankld; make) -cpm-loader/cpmload.bin: cpm-loader/cpmload.s cpm-loader/makecpmloader.c +cpm-loader/cpmload.bin: cpm-loader/cpmload.s cpm-loader/fuzixload.s cpm-loader/makecpmloader.c +make -C cpm-loader tools/makejv3: tools/makejv3.c diff --git a/Kernel/cpu-z80/image.mk b/Kernel/cpu-z80/image.mk index bc530ffe..58a6eefe 100644 --- a/Kernel/cpu-z80/image.mk +++ b/Kernel/cpu-z80/image.mk @@ -18,7 +18,7 @@ tools/bin2z80: tools/bin2z80.c tools/bankld/sdldz80: +(cd tools/bankld; make) -cpm-loader/cpmload.bin: cpm-loader/cpmload.s cpm-loader/makecpmloader.c +cpm-loader/cpmload.bin: cpm-loader/cpmload.s cpm-loader/fuzixload.s cpm-loader/makecpmloader.c +make -C cpm-loader tools/makejv3: tools/makejv3.c diff --git a/Kernel/platform-n8vem-mark4/Makefile b/Kernel/platform-n8vem-mark4/Makefile index bc0a82e5..ca94870a 100644 --- a/Kernel/platform-n8vem-mark4/Makefile +++ b/Kernel/platform-n8vem-mark4/Makefile @@ -50,3 +50,4 @@ diskboot.bin: diskboot.s image: ../cpm-loader/makecpmloader ../cpm-loader/cpmload.bin ../fuzix.bin 0x88 fuzix.com + ../cpm-loader/makecpmloader ../cpm-loader/fuzixload.bin ../fuzix.bin 0x88 fuzix diff --git a/Kernel/platform-p112/Makefile b/Kernel/platform-p112/Makefile index 305629a8..f79c206a 100644 --- a/Kernel/platform-p112/Makefile +++ b/Kernel/platform-p112/Makefile @@ -52,4 +52,5 @@ flopboot.bin: flopboot.s image: ../cpm-loader/makecpmloader ../cpm-loader/cpmload.bin ../fuzix.bin 0x88 fuzix.com + ../cpm-loader/makecpmloader ../cpm-loader/fuzixload.bin ../fuzix.bin 0x88 fuzix ./flopboot-mkimage flopboot.bin ../fuzix.bin fuzix-boot.fdd diff --git a/Kernel/platform-zeta-v2/Makefile b/Kernel/platform-zeta-v2/Makefile index 20526e10..e6333ad0 100644 --- a/Kernel/platform-zeta-v2/Makefile +++ b/Kernel/platform-zeta-v2/Makefile @@ -54,3 +54,4 @@ image: makebin -s 136 bootrom.ihx > bootrom.bin cat bootrom.bin ../fuzix.bin | dd conv=sync bs=65536 count=1 of=fuzix.rom ../cpm-loader/makecpmloader ../cpm-loader/cpmload.bin ../fuzix.bin 0x88 fuzix.com + ../cpm-loader/makecpmloader ../cpm-loader/fuzixload.bin ../fuzix.bin 0x88 fuzix