zx128: Move buffers to 0x6000 and dynamically reclaim space
authorAlan Cox <alan@linux.intel.com>
Sun, 25 Nov 2018 16:10:59 +0000 (16:10 +0000)
committerAlan Cox <alan@linux.intel.com>
Sun, 25 Nov 2018 16:10:59 +0000 (16:10 +0000)
This gets us dynamic buffers as we want and also frees up the space between
0x4000 and 0x5FFF so that we can use the ZX Spectrum classic screen mapping
and leaves a bit of space in case we need to use any ROM hooks that want to
use system variables and BASIC hooks.

We are a bit tight between 0x2000 and 0x3FFF but have enough space for now.

Freeing up the space means we can next move the screen down. That makes the
screen potentially directly addressible from user space which is a huge win.

It also means we'll have a load of free space in CODE3 which is what we want
as well as probably room to migrate the font about a bit

Kernel/platform-zxdiv/config.h
Kernel/platform-zxdiv/crt0.s
Kernel/platform-zxdiv/fuzix.lnk
Kernel/platform-zxdiv/kernel.def
Kernel/platform-zxdiv/main.c

index b690195..590155e 100644 (file)
 
 /* Video terminal, not a serial tty */
 #define CONFIG_VT
-/* Keyboard contains noascii symbols */
+/* Keyboard contains non-ascii symbols */
 #define CONFIG_UNIKEY
 #define CONFIG_FONT8X8
 #define CONFIG_FONT8X8SMALL
 
+#define CONFIG_DYNAMIC_BUFPOOL
 #define CONFIG_DYNAMIC_SWAP
 
 /* Custom banking */
@@ -56,9 +57,9 @@
 #define NUM_DEV_TTY 1
 
 #define TTYDEV   BOOT_TTY /* Device used by kernel for messages, panics */
-#define NBUFS    9       /* Number of block buffers */
+#define NBUFS    5       /* Number of block buffers */
 #define NMOUNTS         4        /* Number of mounts at a time */
-#define MAX_BLKDEV 2       /* 2 IDE drives, 1 SD drive */
+#define MAX_BLKDEV 4       /* 2 IDE drives, 2 SD drive */
 
 #define SWAPBASE 0x8000
 #define SWAPTOP  0x10000UL
@@ -68,5 +69,3 @@
 
 /* All our pages get mapped into the top 16K bank for swapping use */
 #define swap_map(x)            ((uint8_t *)(x|0xC000))
-
-#define platform_discard()
index 4920a32..8801dde 100644 (file)
@@ -14,9 +14,7 @@
        .area _COMMONDATA
         .area _INITIALIZED
        ;
-       ;       We move INITIALIZER into INITIALIZED at preparation time
-       ;       then pack COMMONMEM.. end of INITIALIZED after DISCARD
-       ;       in the load image. Beyond that point we just zero.
+       ;       Beyond this point we just zero.
        ;
         .area _DATA
         .area _BSEG
         .area _HEAP
         .area _GSINIT
         .area _GSFINAL
+       ;       We moved our font elsewhere
        .area _FONT
        ;
+       ;       Finally the buffers so they can expand
+       ;
+       .area _BUFFERS
+       ;
        ;       All our code is banked at 0xC000
        ;
         .area _CODE1
        .area _CODE2
        ;
-       ; Code3 sits above the display area along with the font and video
+       ; Code3 sits above the display area along with the video
        ; code so that they can access the display easily. It lives at
        ; 0xDB00 therefore
        ;
        .area _CODE3
         .area _VIDEO
 
-       ; FIXME: We should switch to the ROM font and an ascii remap ?
-        .area _FONT
        ; Discard is dumped in at 0x8000 and will be blown away later.
         .area _DISCARD
 
@@ -47,6 +48,8 @@
         .globl _fuzix_main
         .globl init_early
         .globl init_hardware
+       .globl l__BUFFERS
+       .globl s__BUFFERS
        .globl l__DATA
        .globl s__DATA
         .globl kstack_top
@@ -55,6 +58,7 @@
         .globl nmi_handler
         .globl interrupt_handler
 
+       .include "../kernel.def"
        .include "kernel.def"
 
         ; startup code
@@ -84,6 +88,11 @@ _go:
        ld bc, #l__DATA-1
        ld (hl), #0
        ldir
+       ld hl, #s__BUFFERS
+       ld de, #s__BUFFERS+1
+       ld bc, #l__BUFFERS-1
+       ld (hl), #0
+       ldir
 
         ld sp, #kstack_top
 
@@ -119,3 +128,15 @@ _marker:
        .area _STUBS
 stubs:
        .ds 768
+
+       .area _BUFFERS
+;
+; Buffers (we use asm to set this up as we need them in a special segment
+; so we can recover the discard memory into the buffer pool
+;
+
+       .globl _bufpool
+       .area _BUFFERS
+
+_bufpool:
+       .ds BUFSIZE * NBUFS
index b94babc..34eab0e 100644 (file)
@@ -3,6 +3,7 @@
 -i fuzix.ihx
 -b _CONST=0x400
 -b _COMMONDATA=0x2200
+-b _BUFFERS=0x6000
 -b _CODE1=0xC000
 -b _CODE2=0xC000
 -b _CODE3=0xDB00
index 2a1125f..e6c34ca 100644 (file)
@@ -11,3 +11,4 @@ Z80_TYPE                  .equ 1
 PROGBASE                   .equ 0x8000
 PROGLOAD                   .equ 0x8000
 
+NBUFS                      .equ 5
index 85e6711..20a2cce 100644 (file)
@@ -36,6 +36,37 @@ int strlen(const char *p)
   return len;
 }
 
+/* This points to the last buffer in the disk buffers. There must be at least
+   four buffers to avoid deadlocks. */
+struct blkbuf *bufpool_end = bufpool + NBUFS;
+
+/*
+ *     We pack discard into the memory image is if it were just normal
+ *     code but place it at the end after the buffers. When we finish up
+ *     booting we turn everything from the buffer pool to the start of
+ *     user space into buffers.
+ *
+ *     We don't touch discard. Discard is just turned into user space.
+ */
+void platform_discard(void)
+{
+       uint16_t discard_size = PROGBASE - (uint16_t)bufpool_end;
+       bufptr bp = bufpool_end;
+
+       discard_size /= sizeof(struct blkbuf);
+
+       kprintf("%d buffers added\n", discard_size);
+
+       bufpool_end += discard_size;
+
+       memset( bp, 0, discard_size * sizeof(struct blkbuf) );
+
+       for( bp = bufpool + NBUFS; bp < bufpool_end; ++bp ){
+               bp->bf_dev = NO_DEVICE;
+               bp->bf_busy = BF_FREE;
+       }
+}
+
 #ifndef SWAPDEV
 /* Adding dummy swapper since it is referenced by tricks.s */
 void swapper(ptptr p)