filo: rework some code so we can use it nicely as a boot block loader
authorAlan Cox <alan@linux.intel.com>
Sat, 5 Jan 2019 22:41:51 +0000 (22:41 +0000)
committerAlan Cox <alan@linux.intel.com>
Sat, 5 Jan 2019 22:41:51 +0000 (22:41 +0000)
Kernel/filo/README
Kernel/filo/filo.s
Kernel/platform-sc114/loader.s

index 6a5a128..1bb4679 100644 (file)
@@ -2,3 +2,14 @@ FILO
 
 Initial draft of a loader that is designed to be a portable Z80 loading tool
 that can load Fuzix images out of a Fuzix file system.
+
+Commands
+
+*xxx           anything beginning * is handed to the platform specific code
+               so may be relevant or not.
+
+[A-P]:         capital required - select drive to load from
+               (will also allow A0-P3 once we do partitions)
+
+any other string is taken as a filename to search for in / of the current
+volume and boot as a kernel image.
index a4c1a93..1b61871 100644 (file)
@@ -88,21 +88,6 @@ filo:
        .ascii 'Fuzix Intermediate Loader v0.01.\n'
        .asciz '(C)2019 Alan Cox\n\n'
 
-       .area _DATA
-
-loadname:
-       .ds 31
-ibuf:
-       .ds 64
-dbuf:
-       .ds 512
-partbase_l:
-       .dw 0
-partbase_h:
-       .dw 0
-
-       .area _CODE
-
 partitions:
        ; No partitions found (hack for now)
        ld hl,#0
@@ -363,7 +348,7 @@ reader_loop:
 bread:
        ld a,d
        or e
-       jr nz, bread_disk
+       jp nz, bread_disk
        ld d,h
        ld e,l
        ld bc,#511
@@ -394,4 +379,16 @@ cmploop:
        djnz cmploop
        ret                     ; Z 
 
+       .area _DATA
+
+loadname:
+       .ds 31
+ibuf:
+       .ds 64
+dbuf:
+       .ds 512
+partbase_l:
+       .dw 0
+partbase_h:
+       .dw 0
 
index d6002cc..8709a3a 100644 (file)
@@ -4,19 +4,50 @@
 ;
 ;      Currently this and the glue driver code is well under 2 disk blocks.
 ;      Adding partitions should still fit 2 blocks nicely.
+;
+;      Our SCM command 'BOOT' loads the MBR of the media and then runs it
+;      if appropriate. We are loaded at 0xF000 and hold all of CODE
+;
+;
+;      Section ordering
 ;
        .area _CODE
+       .area _STACK
+       .area _CODE2
+       .area _DATA
 
 ;
+;      _CODE and _STACK goes in the boot sector.
+;      _CODE2 and _DATA are split across them or beyond (as data is
+;      uninitialized
+;
+       .area _CODE
+
+;
+;      So we can check set up
+;
+       .globl start
+       .globl stack
+;
 ;      Magic for the loader
 ;
        .byte 'Z'
        .byte 80
 
 ;
-;      Loader core
+;      We have 446 bytes of space in the boot sector before the
+;      partitions that is loaded (and the partition table), but we
+;      need to load the second sector holding the core of FILO
 ;
-       .include '../filo/filo.s'
+
+start:
+       ld sp, #stack
+       ld bc, #0xF200          ; Straight after us
+       ld hl, #0x0001          ; Sector 1
+       ld de, #0x0000
+       call bread_raw
+       jp boot_begin           ; Run FILO
+
 ;
 ; ****************************************************************************
 ;
@@ -104,6 +135,14 @@ nocarry_lba:
        xor a
        ret
 ;
+;      Private helper
+;
+bread_raw:
+       push hl
+       ld h,b
+       ld l,c
+       jr nocarry_lba
+;
 ;      Timeout might be a good idea
 ;
 ide_ready:
@@ -254,3 +293,15 @@ delay10ms:
        ld c,#0x0a
        ld de,#0x10
        jr mcall
+
+       .area _STACK
+
+       .ds 16
+stack:
+
+       .area _CODE2
+
+;
+;      Loader core loaded from sector 1
+;
+       .include '../filo/filo.s'