From ae3abb6d0a53d67fcd4a62aa96c95c8a3e637547 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Sun, 25 Nov 2018 16:10:59 +0000 Subject: [PATCH] zx128: Move buffers to 0x6000 and dynamically reclaim space 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 | 9 ++++----- Kernel/platform-zxdiv/crt0.s | 33 ++++++++++++++++++++++++++------ Kernel/platform-zxdiv/fuzix.lnk | 1 + Kernel/platform-zxdiv/kernel.def | 1 + Kernel/platform-zxdiv/main.c | 31 ++++++++++++++++++++++++++++++ 5 files changed, 64 insertions(+), 11 deletions(-) diff --git a/Kernel/platform-zxdiv/config.h b/Kernel/platform-zxdiv/config.h index b6901957..590155e3 100644 --- a/Kernel/platform-zxdiv/config.h +++ b/Kernel/platform-zxdiv/config.h @@ -18,11 +18,12 @@ /* Video terminal, not a serial tty */ #define CONFIG_VT -/* Keyboard contains not ascii 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() diff --git a/Kernel/platform-zxdiv/crt0.s b/Kernel/platform-zxdiv/crt0.s index 4920a322..8801dde7 100644 --- a/Kernel/platform-zxdiv/crt0.s +++ b/Kernel/platform-zxdiv/crt0.s @@ -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 @@ -24,22 +22,25 @@ .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 diff --git a/Kernel/platform-zxdiv/fuzix.lnk b/Kernel/platform-zxdiv/fuzix.lnk index b94babcd..34eab0e7 100644 --- a/Kernel/platform-zxdiv/fuzix.lnk +++ b/Kernel/platform-zxdiv/fuzix.lnk @@ -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 diff --git a/Kernel/platform-zxdiv/kernel.def b/Kernel/platform-zxdiv/kernel.def index 2a1125f6..e6c34caa 100644 --- a/Kernel/platform-zxdiv/kernel.def +++ b/Kernel/platform-zxdiv/kernel.def @@ -11,3 +11,4 @@ Z80_TYPE .equ 1 PROGBASE .equ 0x8000 PROGLOAD .equ 0x8000 +NBUFS .equ 5 diff --git a/Kernel/platform-zxdiv/main.c b/Kernel/platform-zxdiv/main.c index 85e6711f..20a2ccee 100644 --- a/Kernel/platform-zxdiv/main.c +++ b/Kernel/platform-zxdiv/main.c @@ -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) -- 2.34.1