Kernel: Add "fuzix-loader" boot mechansim
authorWill Sowerbutts <will@sowerbutts.com>
Fri, 6 Jan 2017 19:14:31 +0000 (19:14 +0000)
committerWill Sowerbutts <will@sowerbutts.com>
Sun, 8 Jan 2017 23:05:11 +0000 (23:05 +0000)
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.

Kernel/cpm-loader/.gitignore
Kernel/cpm-loader/Makefile
Kernel/cpm-loader/fuzixload.s [new file with mode: 0644]
Kernel/cpu-z180/image.mk
Kernel/cpu-z80/image.mk
Kernel/platform-n8vem-mark4/Makefile
Kernel/platform-p112/Makefile
Kernel/platform-zeta-v2/Makefile

index e3eb0d4..8e99cca 100644 (file)
@@ -1,3 +1,5 @@
+fuzixload.bin
+fuzixload.ihx
 cpmload.bin
 cpmload.ihx
 makecpmloader
index 6138e47..ddc7b56 100644 (file)
@@ -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 (file)
index 0000000..63d63ac
--- /dev/null
@@ -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:
index b38c609..9beccfa 100644 (file)
@@ -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
index bc530ff..58a6eef 100644 (file)
@@ -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
index bc0a82e..ca94870 100644 (file)
@@ -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
index 305629a..f79c206 100644 (file)
@@ -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
index 20526e1..e6333ad 100644 (file)
@@ -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