From: Alan Cox Date: Tue, 20 Oct 2015 14:50:17 +0000 (+0100) Subject: trs80: recover discardable buffers X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=2569a6aa56065c5aa501e42a1a3475f6fb6a16c0;p=FUZIX.git trs80: recover discardable buffers --- diff --git a/Kernel/platform-trs80/config.h b/Kernel/platform-trs80/config.h index b7c45bd4..d10bc2a8 100644 --- a/Kernel/platform-trs80/config.h +++ b/Kernel/platform-trs80/config.h @@ -33,7 +33,7 @@ #define TICKSPERSEC 60 /* Ticks per second */ #define PROGBASE 0x0000 /* Base of user */ #define PROGLOAD 0x0100 /* Load and run here */ -#define PROGTOP 0x7D00 /* Top of program, base of U_DATA stash */ +#define PROGTOP 0x7E00 /* Top of program, base of U_DATA stash */ #define PROC_SIZE 32 /* Memory needed per process */ #define SWAP_SIZE 0x40 /* 32K in blocks */ @@ -54,7 +54,9 @@ #define NUM_DEV_TTY 3 #define TTYDEV BOOT_TTY /* Device used by kernel for messages, panics */ #define SWAPDEV (swap_dev) /* Device for swapping (dynamic). */ -#define NBUFS 10 /* Number of block buffers */ +#define NBUFS 10 /* Number of block buffers - keep in sync with asm! */ #define NMOUNTS 4 /* Number of mounts at a time */ +/* Reclaim the discard space for buffers */ +#define CONFIG_DYNAMIC_BUFPOOL -#define platform_discard() +extern void platform_discard(void); diff --git a/Kernel/platform-trs80/crt0.s b/Kernel/platform-trs80/crt0.s index 234ad1aa..4e1205b0 100644 --- a/Kernel/platform-trs80/crt0.s +++ b/Kernel/platform-trs80/crt0.s @@ -16,8 +16,11 @@ ; put initialisation stuff in here .area _GSINIT .area _GSFINAL - .area _COMMONMEM + ; Buffers must be directly before discard as they will + ; expand over it + .area _BUFFERS .area _DISCARD + .area _COMMONMEM ; imported symbols .globl _fuzix_main @@ -27,11 +30,16 @@ .globl l__DATA .globl s__DISCARD .globl l__DISCARD + .globl s__BUFFERS + .globl l__BUFFERS .globl s__COMMONMEM .globl l__COMMONMEM .globl s__INITIALIZER .globl kstack_top + ; exports + .globl _discard_size + ; startup code .area _CODE @@ -46,23 +54,29 @@ start: ld bc, #l__COMMONMEM ldir ; then the discard - ld de, #s__DISCARD - ld bc, #l__DISCARD - ldir +; Discard can just be linked in but is next to the buffers +; ld de, #s__DISCARD +; ld bc, #l__DISCARD +; ldir ; then zero the data area ld hl, #s__DATA ld de, #s__DATA + 1 ld bc, #l__DATA - 1 ld (hl), #0 ldir - -; TODO: Move the common into the other bank, pain as we may well have -; code in low bank and __COMMON packed in high. Needs to be in -; .COMMONMEM and map the other page low -; +; Zero buffers area + ld hl, #s__BUFFERS + ld de, #s__BUFFERS + 1 + ld bc, #l__BUFFERS - 1 + ld (hl), #0 + ldir call init_early call init_hardware call _fuzix_main di stop: halt jr stop + + .area _DISCARD +_discard_size: + .dw l__DISCARD diff --git a/Kernel/platform-trs80/fuzix.lnk b/Kernel/platform-trs80/fuzix.lnk index 2a6d4c13..fe00fa3a 100644 --- a/Kernel/platform-trs80/fuzix.lnk +++ b/Kernel/platform-trs80/fuzix.lnk @@ -1,7 +1,6 @@ -mwxuy -i fuzix.ihx -b _CODE=0x0100 --b _DISCARD=0xD000 -b _COMMONMEM=0xE800 -l z80 platform-trs80/crt0.rel diff --git a/Kernel/platform-trs80/kernel.def b/Kernel/platform-trs80/kernel.def index 35e6327a..919828c0 100644 --- a/Kernel/platform-trs80/kernel.def +++ b/Kernel/platform-trs80/kernel.def @@ -3,9 +3,11 @@ U_DATA .equ 0xE800 ; (this is struct u_data from kernel.h) U_DATA__TOTALSIZE .equ 0x200 ; 256+256 (we don't save istack) -U_DATA_STASH .equ 0x7D00 ; BD00-BEFF +U_DATA_STASH .equ 0x7E00 ; 7E00-7FFF PROGBASE .equ 0x0000 PROGLOAD .equ 0x0100 Z80_TYPE .equ 1 + +NBUFS .equ 10 diff --git a/Kernel/platform-trs80/main.c b/Kernel/platform-trs80/main.c index 08e8bb35..a11ca7a6 100644 --- a/Kernel/platform-trs80/main.c +++ b/Kernel/platform-trs80/main.c @@ -10,6 +10,8 @@ __sfr __at 0xEF irqack; uint8_t vtattr_cap; +struct blkbuf *bufpool_end = bufpool + NBUFS; + /* On idle we spin checking for the terminals. Gives us more responsiveness for the polled ports */ void platform_idle(void) @@ -34,6 +36,30 @@ void platform_interrupt(void) timer_interrupt(); } +/* + * Once we are about to load init we can throw the boot code away + * and convert it into disk cache. This gets us 7 or so buffer + * back which more than doubles our cache size ! + */ +void platform_discard(void) +{ + extern uint16_t discard_size; + bufptr bp = bufpool_end; + + discard_size /= sizeof(struct blkbuf); + + kprintf("%d buffers reclaimed from discard\n", discard_size); + + bufpool_end += discard_size; /* Reclaim the discard space */ + + memset(bp, 0, discard_size * sizeof(struct blkbuf)); + /* discard_size is in discard so it dies here */ + for (bp = bufpool + NBUFS; bp < bufpool_end; ++bp) { + bp->bf_dev = NO_DEVICE; + bp->bf_busy = BF_FREE; + } +} + #ifdef CONFIG_RTC __sfr __at 0xB0 rtc_secl; diff --git a/Kernel/platform-trs80/trs80.s b/Kernel/platform-trs80/trs80.s index 1719f1b3..52a9a8fa 100644 --- a/Kernel/platform-trs80/trs80.s +++ b/Kernel/platform-trs80/trs80.s @@ -49,9 +49,15 @@ .globl s__COMMONMEM .globl l__COMMONMEM + .globl _bufpool + .include "kernel.def" .include "../kernel.def" + .area _BUFFERS + +_bufpool: + .ds BUFSIZE * NBUFS ; ----------------------------------------------------------------------------- ; COMMON MEMORY BANK (0xE800 upwards) ; -----------------------------------------------------------------------------