Kernel: zeta-v2: Change to dynamic bufpool
authorWill Sowerbutts <will@sowerbutts.com>
Fri, 6 Jan 2017 19:02:52 +0000 (19:02 +0000)
committerWill Sowerbutts <will@sowerbutts.com>
Sun, 8 Jan 2017 23:05:11 +0000 (23:05 +0000)
Kernel/platform-zeta-v2/config.h
Kernel/platform-zeta-v2/crt0.s
Kernel/platform-zeta-v2/discard.c
Kernel/platform-zeta-v2/main.c
Kernel/platform-zeta-v2/zeta-v2.s

index 0e7cbeb..76b1155 100644 (file)
@@ -24,6 +24,7 @@
 #define PROGBASE    0x0000  /* also data base */
 #define PROGLOAD    0x0100  /* also data base */
 #define PROGTOP     0xF000  /* Top of program, base of U_DATA copy */
+#define KERNTOP     0xF000  /* Top of kernel (first 3 banks), base of shared bank */
 #define PROC_SIZE   64   /* Memory needed per process */
 
 /* WRS: this is probably wrong -- we want to swap the full 64K minus the common code */
@@ -38,7 +39,8 @@
 #define BOOTDEVICENAMES "hd#,fd,,rd"
 
 //#define SWAPDEV  (256 + 1)  /* Device for swapping */
-#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 zeta-v2.s */
 #define NMOUNTS         4        /* Number of mounts at a time */
 
 #define MAX_BLKDEV 4       /* 1 ROM disk, 1 RAM disk, 1 floppy, 1 PPIDE */
@@ -85,5 +87,3 @@
 #endif
 
 #define TTYDEV   BOOT_TTY /* Device used by kernel for messages, panics */
-
-#define platform_discard()
index dc1cf1c..285a8c4 100644 (file)
         .area _HEAP
         ; note that areas below here may be overwritten by the heap at runtime, so
         ; put initialisation stuff in here
-        .area _INITIALIZER
-        .area _GSINIT
-        .area _GSFINAL
+        .area _BUFFERS     ; _BUFFERS grows to consume all before it (up to KERNTOP)
+        .area _INITIALIZER ; binman copies this to the right place for us
+        .area _GSINIT      ; unused
+        .area _GSFINAL     ; unused
         .area _DISCARD
         .area _COMMONMEM
 
index ce78eff..dbf7caa 100644 (file)
@@ -17,6 +17,8 @@ void init_hardware_c(void)
 {
     ramsize = 512;
     procmem = 512 - 64 - (DEV_RD_RAM_PAGES<<4);
+    /* zero out the initial bufpool */
+    memset(bufpool, 0, (char*)bufpool_end - (char*)bufpool);
 }
 
 void pagemap_init(void)
index 66aa345..3832bd1 100644 (file)
@@ -8,6 +8,21 @@
 #endif
 
 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++;
+    }
+
+    kprintf("platform_discard: bufpool=%x, bufpool_end=%x\n", bufpool, bufpool_end);
+}
 
 void platform_idle(void)
 {
index 03ba17f..2a64dee 100644 (file)
@@ -17,6 +17,7 @@
        .globl mpgsel_cache
        .globl _kernel_pages
        .globl _trap_reboot
+       .globl _bufpool
 
         ; imported symbols
         .globl _ramsize
@@ -44,6 +45,13 @@ CONSOLE_DIVISOR              .equ    (1843200 / (16 * CONSOLE_RATE))
 CONSOLE_DIVISOR_HIGH   .equ    (CONSOLE_DIVISOR >> 8)
 CONSOLE_DIVISOR_LOW    .equ    (CONSOLE_DIVISOR & 0xFF)
 
+;=========================================================================
+; Buffers
+;=========================================================================
+        .area _BUFFERS
+_bufpool:
+        .ds (BUFSIZE * 4) ; adjust NBUFS in config.h in line with this
+
 ;=========================================================================
 ; Initialization code
 ;=========================================================================