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

index cdc050d..92ded8f 100644 (file)
@@ -25,6 +25,7 @@
 #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 */
@@ -35,7 +36,9 @@
 #define NUM_DEV_TTY 5
 
 #define TTYDEV   (512+1)  /* System console (used by kernel, init) */
-#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 p112.s */
 #define NMOUNTS         4        /* Number of mounts at a time */
 
 /* Hardware parameters */
@@ -62,5 +65,3 @@
 
 /* We have the P112 floppy controller */
 #define CONFIG_P112_FLOPPY
-
-#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 8551cbd..7034863 100644 (file)
@@ -15,6 +15,8 @@ void init_hardware_c(void)
 {
     ramsize = 1024;
     procmem = 1024 - 64 - (DEV_RD_RAM_PAGES<<2);
+    /* zero out the initial bufpool */
+    memset(bufpool, 0, (char*)bufpool_end - (char*)bufpool);
 }
 
 void pagemap_init(void)
index 30883a3..2d7edc9 100644 (file)
 
 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)
 {
index 68cd2ec..73d800a 100644 (file)
@@ -13,6 +13,7 @@
         .globl outcharhex
         .globl platform_interrupt_all
         .globl _trap_reboot
+        .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
 ; -----------------------------------------------------------------------------