rc2014: fix up the banking code and update the bootloader
authorAlan Cox <alan@linux.intel.com>
Sat, 16 Mar 2019 00:22:26 +0000 (00:22 +0000)
committerAlan Cox <alan@linux.intel.com>
Sat, 16 Mar 2019 00:22:26 +0000 (00:22 +0000)
At this point the banked kernel appears to work. Needs a bit more testing and
to be tested on the actual board.

Kernel/platform-rc2014/Makefile
Kernel/platform-rc2014/boot-romwbw.s
Kernel/platform-rc2014/buffers.s [deleted file]
Kernel/platform-rc2014/config.h
Kernel/platform-rc2014/fuzix.lnk
Kernel/platform-rc2014/rc2014.s
Kernel/platform-rc2014/tricks.s

index 2c89259..baf972f 100644 (file)
@@ -1,4 +1,4 @@
-ASRCS = crt0.s tricks.s commonmem.s rc2014.s monitor.s vfdterm.s buffers.s
+ASRCS = crt0.s tricks.s commonmem.s rc2014.s monitor.s vfdterm.s
 CSRCS = devices.c main.c devtty.c vfd-debug.c vfd-term.c
 CSRCS += devinput.c
 DISCARD_CSRCS = discard.c
@@ -52,7 +52,11 @@ clean:
 #      Compile up the boot block
 #
 image: bootblock
-#      cat boot-romwbw.bin ../fuzix.bin >fuzix.romwbw
+       cat boot-romwbw.bin >fuzix.romwbw
+       dd if=../common.bin bs=16384 count=1 >>fuzix.romwbw
+       dd if=../bank1.bin bs=16384 skip=1 count=2 conv=sync >>fuzix.romwbw
+       dd if=../common.bin bs=16384 skip=3 count=1 conv=sync >>fuzix.romwbw
+       dd if=../bank2.bin bs=16384 skip=1 count=2 conv=sync >>fuzix.romwbw
 
 bootblock:
        sdasz80 -o boot-romwbw.s
index f1aafb1..fa69e9f 100644 (file)
@@ -69,9 +69,9 @@ bootit:
        ld e, #32               ; 32 sectors (16K)
        push bc
        rst 8                   ; Can error but if so wtf do we do ?
-       ld hl,#0x8100           ; Don't copy first 256 bytes over
-       ld de,#0x4100
-       ld bc,#0x3F00           ; We've loaded 0100-4000
+       ld hl,#0x8000           ; Don't copy first 256 bytes over
+       ld de,#0x4000
+       ld bc,#0x4000           ; We've loaded 0000-4000
        ld a,#32
        out (MPGSEL_1),a        ; Low bank at 0x4000 please
        ldir
@@ -111,9 +111,8 @@ bootit:
        ;       Final 16K
        ;
        ld hl,#0x8000           ; Now load 8000 up
-       ld e, #32               ; takes us up to F000. If that's not enough
-                               ; before unpack we have a problem as we
-                               ; will need to move the loader
+       ld e, #32
+       push bc
        rst 8
 
        ld hl,#0x8000           ; Move it into place
@@ -122,6 +121,35 @@ bootit:
        ld a,#35
        out (MPGSEL_1),a
        ldir
+       pop bc
+
+       ;
+       ;       Bank 2 first 16K
+       ;
+       ld hl,#0x8000           ; Load 4000 up
+       ld e, #32
+       push bc
+       rst 8
+       ld hl,#0x8000           ; Move it into place
+       ld de,#0x4000
+       ld bc,#0x4000
+       ld a,#36
+       out (MPGSEL_1),a
+       ldir
+       pop bc
+
+       ;
+       ;       Bank 2 second 16K
+       ;
+       ld hl,#0x8000           ; Now load 8000 up
+       ld e, #32
+       rst 8
+       ld hl,#0x8000           ; Move it into place
+       ld de,#0x4000
+       ld bc,#0x4000
+       ld a,#37
+       out (MPGSEL_1),a
+       ldir
 
        ;
        ;       Map the kernel low 16K block and jump into it
diff --git a/Kernel/platform-rc2014/buffers.s b/Kernel/platform-rc2014/buffers.s
deleted file mode 100644 (file)
index 377707b..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-;
-;      External buffer support logic
-;
-
-       .module buffers
-       .area _COMMONMEM
-
-       .include "kernel.def"
-       .include "../kernel-z80.def"
-
-       .globl _do_blkzero
-       .globl _do_blkcopyk
-       .globl _do_blkcopyul
-       .globl _do_blkcopyuh
-
-       .globl _bdest
-       .globl _blen
-
-       .globl map_kernel
-       .globl map_buffers
-       .globl map_buffers_user
-       .globl map_buffers_user_h
-
-       .globl _workbuf
-
-
-;
-;      Ugly - but we need to rework memory management and stuff to fix it
-;
-_workbuf:
-       .ds 1024
-
-_bdest:
-       .word 0
-_blen:
-       .word 0
-
-_do_blkzero:
-       call map_buffers
-       ld e,l
-       ld d,h
-       inc de
-       ld (hl),#0
-       ld bc,#511
-       ldir
-       jp map_kernel
-
-_do_blkcopyk:
-       call map_buffers
-       ld de,(_bdest)
-       ld bc,(_blen)
-       ldir
-       jp map_kernel
-
-_do_blkcopyul:
-       call map_buffers_user
-       ld de,(_bdest)
-       ld bc,(_blen)
-       ldir
-       jp map_kernel
-
-_do_blkcopyuh:
-       call map_buffers_user_h
-       ld de,(_bdest)
-       ld bc,(_blen)
-       ldir
-       jp map_kernel
index 138a408..52c0338 100644 (file)
 #define TICKSPERSEC 10      /* Ticks per second */
 #define PROGBASE    0x0000  /* also data base */
 #define PROGLOAD    0x0100  /* also data base */
-#define PROGTOP     0xD000  /* Top of program, base of U_DATA copy */
-/* FIXME: check this... for discard looks wrong */
-#define KERNTOP     0xC000  /* Top of kernel (first 3 banks), base of shared bank */
+#define PROGTOP     0xF000  /* Top of program, base of U_DATA copy */
 
 //#define SWAPDEV     (swap_dev)       /* A variable for dynamic, or a device major/minor */
 extern unsigned int swap_dev;
 #define SWAP_SIZE   0x69       /* 60.5K in blocks (prog + udata) */
 #define SWAPBASE    0x0000     /* start at the base of user mem */
-#define SWAPTOP            0xD200      /* Swap out udata and program */
+#define SWAPTOP            0xF200      /* Swap out udata and program */
 #define MAX_SWAPS   16         /* We will size if from the partition */
 /* Swap will be set up when a suitably labelled partition is seen */
 #define CONFIG_DYNAMIC_SWAP
index 7625aaf..961d1ff 100644 (file)
@@ -17,7 +17,6 @@ version.rel
 lowlevel-z80-banked.rel
 platform-rc2014/tricks.rel
 platform-rc2014/main.rel
-platform-rc2014/buffers.rel
 timer.rel
 kdata.rel
 platform-rc2014/devfd.rel
index ad55755..89dd11a 100644 (file)
@@ -11,8 +11,6 @@
        .globl map_process
        .globl map_process_save
        .globl map_buffers
-       .globl map_buffers_user
-       .globl map_buffers_user_h
        .globl map_kernel_di
        .globl map_process_di
        .globl map_process_always
@@ -83,8 +81,8 @@ ACIA_RTS_LOW_A       .EQU     0x96   ; rts low, xmit interrupt disabled
 
 MAP_BANK1      .equ    0x2221  ; 20 is low, 23 is high
 BANK1          .equ    0x21
-MAP_BANK2      .equ    0x2625  ; for now 24 is buffers - FIXME
-BANK2          .equ    0x25
+MAP_BANK2      .equ    0x2524  ; for now 24 is buffers - FIXME
+BANK2          .equ    0x24
 
 ;=========================================================================
 ; Initialization code
@@ -92,10 +90,7 @@ BANK2                .equ    0x25
         .area _DISCARD
 init_hardware:
         ; program vectors for the kernel
-        ld hl, #0
-        push hl
-        call _program_vectors
-        pop hl
+        call do_program_vectors
 
         ; Stop floppy drive motors
         ld a, #0x0C
@@ -349,6 +344,12 @@ _program_vectors:
        ; At this point the common block has already been copied
        call map_process
 
+       call do_program_vectors
+
+       jp map_kernel_restore
+
+
+do_program_vectors:
        ; write zeroes across all vectors
        ld hl,#0
        ld de,#1
@@ -374,8 +375,7 @@ _program_vectors:
        ld (0x0066),a                   ; Set vector for NMI
        ld hl,#nmi_handler
        ld (0x0067),hl
-
-       jr map_kernel
+       ret
 
 ;=========================================================================
 ; Memory management
@@ -393,40 +393,11 @@ map_process_always:
 map_process_save:
 map_process_always_di:
        push hl
-       ld hl,#_kernel_pages + 1
-       ; Save the current versions of MPGSEL 1 and 2 for map_kernel_restore
-       ; so we return to the right kernel bank
-       in a,(MPGSEL_1)
-       ld (hl),a
-       inc hl
-       in a,(MPGSEL_2)
-       ld (hl),a
+       ; We don't need to save the kernel page numbers because we
+       ; patched them on bank switches
        ld hl,#_udata + U_DATA__U_PAGE
         jr map_process_2_pophl_ret
 
-;
-;      FIXME: needs to save the old kernel mid mapping
-;
-map_buffers_user:
-       push hl
-       ld hl,(_udata + U_DATA__U_PAGE)
-       ld h,#36
-       ld (_ubuffer_pages),hl
-       ld hl,(_udata + U_DATA__U_PAGE + 2)
-       ld (_ubuffer_pages + 2),hl
-       ld hl,#_ubuffer_pages
-        jr map_process_2_pophl_ret
-
-map_buffers_user_h:
-       push hl
-       ld hl,(_udata + U_DATA__U_PAGE)
-       ld (_ubuffer_pages),hl
-       ld hl,(_udata + U_DATA__U_PAGE + 2)
-       ld l,#36
-       ld (_ubuffer_pages + 2),hl
-       ld hl,#_ubuffer_pages
-        jr map_process_2_pophl_ret
-
 ;=========================================================================
 ; map_process - map process or kernel pages
 ; Inputs: page table address in HL, map kernel if HL == 0
@@ -444,22 +415,13 @@ map_process_di:
 ; Outputs: none; all registers preserved
 ;=========================================================================
 map_kernel:
+map_buffers:
 map_kernel_restore:
 map_kernel_di:
        push hl
        ld hl,#_kernel_pages
         jr map_process_2_pophl_ret
 
-;=========================================================================
-; map_buffers - map kernel with disk buffers at 0x4000-0x7FFF
-; Inputs: none
-; Outputs: none; all registers preserved
-;=========================================================================
-map_buffers:
-       push hl
-       ld hl,#_kernelbuf_pages
-        jr map_process_2_pophl_ret
-
 ;=========================================================================
 ; map_process_2 - map process or kernel pages
 ; Inputs: page table address in HL
@@ -502,7 +464,8 @@ map_process_2_pophl_ret:
 
 ;=========================================================================
 ; map_save_kernel - save the current page mapping to map_savearea and
-; switch to kernel maps
+; switch to kernel maps. We might switch to any kernel map but that is
+; ok as we will make a thunking call from common to the C irq handler
 ; Inputs: none
 ; Outputs: none
 ;=========================================================================
@@ -554,8 +517,9 @@ bank0:
        ld d,(hl)
        inc hl
        push hl
+       ld a,(_kernel_pages + 1)        ; save old page
        ld (_kernel_pages + 1),bc
-       in a, (MPGSEL_1)                ; existing page
+       ld (mpgsel_cache + 1),bc        ; and mark as current
        ld b,a
        ld a,c                          ; set new page
        out (MPGSEL_1),a
@@ -569,12 +533,14 @@ bank0:
        ld bc,#MAP_BANK2
 banksetbc:
        ld (_kernel_pages + 1), bc
+       ld (mpgsel_cache + 1), bc
        ld a,c
        out (MPGSEL_1),a
        ld a,b
        out (MPGSEL_2),a
        ret
 retbank1:
+       call callhl
        ld bc,#MAP_BANK1
        jr banksetbc
 __bank_0_2:
@@ -593,6 +559,7 @@ __bank_1_2:
        inc hl
        push hl
        call banksetbc
+       ex de,hl
        call callhl
        ld bc,#MAP_BANK1
        jr banksetbc
@@ -606,6 +573,7 @@ __bank_2_1:
        inc hl
        push hl
        call banksetbc
+       ex de,hl
        call callhl
        ld bc,#MAP_BANK2
        jr banksetbc
@@ -618,13 +586,15 @@ __stub_0_2:
 stub_call:
        pop hl                          ; return address
        ex (sp),hl                      ; bank space now target
-       in a,(MPGSEL_1)                 ; current bank
+       ld a,(_kernel_pages+1)          ; current bank
        ld (_kernel_pages+1),bc         ; target
+       ld (mpgsel_cache + 1), bc
        ld b,a
        ld a,c
        out (MPGSEL_1),a
        inc a
        out (MPGSEL_2),a
+       ex de,hl
        ld a,b
        cp #BANK1
        jr z, stub_ret_1
@@ -632,6 +602,7 @@ stub_call:
        ld bc,#MAP_BANK2
 stub_ret:
        ld (_kernel_pages+1),bc
+       ld (mpgsel_cache + 1), bc
        ld a,c
        out (MPGSEL_1),a
        inc a
@@ -659,9 +630,9 @@ _copy_common:
        push bc
        ld a,e
        call map_for_swap
-       ld hl,#0xD300
-       ld de,#0x4300
-       ld bc,#0x2D00
+       ld hl,#0xF200
+       ld de,#0x7200
+       ld bc,#0x0E00
        ldir
        jp map_kernel
 
@@ -676,12 +647,6 @@ top_bank:  ; the shared tricks code needs this name for cache+3
 _kernel_pages:
        .db     32,33,34,35
 
-; kernel page mapping with buffer window
-_kernelbuf_pages:
-       .db     32,36,34,35
-
-_ubuffer_pages:
-       .db     0,0,0,0
 ; memory page mapping save area for map_save/map_restore
 map_savearea:
        .db     0,0,0,0
index 46414c2..eda21d9 100644 (file)
@@ -63,6 +63,7 @@ _platform_switchout:
        pop af
 
         push hl
+       push hl
         call _switchin
 
         ; we should never get here
@@ -143,10 +144,12 @@ _dofork:
         ; always disconnect the vehicle battery before performing maintenance
         di ; should already be the case ... belt and braces.
 
+       pop bc
         pop de  ; return address
         pop hl  ; new process p_tab*
         push hl
         push de
+       push bc
 
         ld (fork_proc_ptr), hl