From f1aa2a0abda6cdba69864f6cfaa325f018d508cf Mon Sep 17 00:00:00 2001 From: Will Sowerbutts Date: Fri, 6 Jan 2017 19:02:15 +0000 Subject: [PATCH] Kernel: n8vem-mark4: Change to dynamic bufpool --- Kernel/platform-n8vem-mark4/config.h | 6 +++--- Kernel/platform-n8vem-mark4/crt0.s | 1 + Kernel/platform-n8vem-mark4/discard.c | 2 ++ Kernel/platform-n8vem-mark4/main.c | 14 ++++++++++++++ Kernel/platform-n8vem-mark4/mark4.s | 8 ++++++++ 5 files changed, 28 insertions(+), 3 deletions(-) diff --git a/Kernel/platform-n8vem-mark4/config.h b/Kernel/platform-n8vem-mark4/config.h index 4017d22f..8ab6bea5 100644 --- a/Kernel/platform-n8vem-mark4/config.h +++ b/Kernel/platform-n8vem-mark4/config.h @@ -25,13 +25,15 @@ #define PROGBASE 0x0000 /* also data base */ #define PROGLOAD 0x0100 /* also data base */ #define PROGTOP 0xF800 /* Top of program, base of U_DATA copy */ +#define KERNTOP 0xF000 /* Kernel has lower 60KB */ #define PROC_SIZE 64 /* Memory needed per process */ /* We need a tidier way to do this from the loader */ #define CMDLINE (0x0081) /* Location of root dev name */ #define BOOTDEVICENAMES "hd#,,,rd" -#define NBUFS 10 /* Number of block buffers */ +#define CONFIG_DYNAMIC_BUFPOOL /* we expand bufpool to overwrite the _DISCARD segment at boot */ +#define NBUFS 4 /* Number of block buffers, keep in line with space reserved in mark4.s */ #define NMOUNTS 4 /* Number of mounts at a time */ /* Hardware parameters */ @@ -80,5 +82,3 @@ /* ASCI0 as the console */ #define TTYDEV (512+1) /* System console (used by kernel, init) */ #endif - -#define platform_discard() diff --git a/Kernel/platform-n8vem-mark4/crt0.s b/Kernel/platform-n8vem-mark4/crt0.s index e77a5473..28c4b1ce 100644 --- a/Kernel/platform-n8vem-mark4/crt0.s +++ b/Kernel/platform-n8vem-mark4/crt0.s @@ -17,6 +17,7 @@ .area _HEAP ; note that areas below here may be overwritten by the heap at runtime, so ; put initialisation stuff in here + .area _BUFFERS ; _BUFFERS grows to consume all before it (up to KERNTOP) .area _INITIALIZER .area _GSINIT .area _GSFINAL diff --git a/Kernel/platform-n8vem-mark4/discard.c b/Kernel/platform-n8vem-mark4/discard.c index 49ab4d34..94aadff1 100644 --- a/Kernel/platform-n8vem-mark4/discard.c +++ b/Kernel/platform-n8vem-mark4/discard.c @@ -9,6 +9,8 @@ void init_hardware_c(void) { ramsize = 512; procmem = 512 - 64 - (DEV_RD_RAM_PAGES<<2); + /* zero out the initial bufpool */ + memset(bufpool, 0, (char*)bufpool_end - (char*)bufpool); } void pagemap_init(void) diff --git a/Kernel/platform-n8vem-mark4/main.c b/Kernel/platform-n8vem-mark4/main.c index e91bd394..05d4568c 100644 --- a/Kernel/platform-n8vem-mark4/main.c +++ b/Kernel/platform-n8vem-mark4/main.c @@ -8,6 +8,20 @@ uint16_t ramtop = PROGTOP; extern unsigned char irqvector; +struct blkbuf *bufpool_end = bufpool + NBUFS; /* minimal for boot -- expanded after we're done with _DISCARD */ + +void platform_discard(void) +{ + while(bufpool_end < (struct blkbuf*)(KERNTOP - sizeof(struct blkbuf))){ + memset(bufpool_end, 0, sizeof(struct blkbuf)); +#if BF_FREE != 0 + bufpool_end->bf_busy = BF_FREE; /* redundant when BF_FREE == 0 */ +#endif + bufpool_end->bf_dev = NO_DEVICE; + bufpool_end++; + } +} + void z180_timer_interrupt(void) { unsigned char a; diff --git a/Kernel/platform-n8vem-mark4/mark4.s b/Kernel/platform-n8vem-mark4/mark4.s index 1b7d0d52..98da09f1 100644 --- a/Kernel/platform-n8vem-mark4/mark4.s +++ b/Kernel/platform-n8vem-mark4/mark4.s @@ -10,6 +10,7 @@ .globl inchar .globl outchar .globl platform_interrupt_all + .globl _bufpool ; imported symbols .globl z180_init_hardware @@ -21,6 +22,13 @@ .include "../cpu-z180/z180.def" .include "../kernel.def" +; ----------------------------------------------------------------------------- +; Buffers +; ----------------------------------------------------------------------------- + .area _BUFFERS +_bufpool: + .ds (BUFSIZE * 4) ; adjust NBUFS in config.h in line with this + ; ----------------------------------------------------------------------------- ; Initialisation code ; ----------------------------------------------------------------------------- -- 2.34.1