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

index 4017d22..8ab6bea 100644 (file)
 #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()
index e77a547..28c4b1c 100644 (file)
@@ -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
index 49ab4d3..94aadff 100644 (file)
@@ -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)
index e91bd39..05d4568 100644 (file)
@@ -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;
index 1b7d0d5..98da09f 100644 (file)
@@ -10,6 +10,7 @@
         .globl inchar
         .globl outchar
         .globl platform_interrupt_all
+        .globl _bufpool
 
         ; imported symbols
         .globl z180_init_hardware
         .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
 ; -----------------------------------------------------------------------------