trs80: recover discardable buffers
authorAlan Cox <alan@etchedpixels.co.uk>
Tue, 20 Oct 2015 14:50:17 +0000 (15:50 +0100)
committerAlan Cox <alan@etchedpixels.co.uk>
Tue, 20 Oct 2015 14:50:17 +0000 (15:50 +0100)
Kernel/platform-trs80/config.h
Kernel/platform-trs80/crt0.s
Kernel/platform-trs80/fuzix.lnk
Kernel/platform-trs80/kernel.def
Kernel/platform-trs80/main.c
Kernel/platform-trs80/trs80.s

index b7c45bd..d10bc2a 100644 (file)
@@ -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);
index 234ad1a..4e1205b 100644 (file)
                ; 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
                .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
index 2a6d4c1..fe00fa3 100644 (file)
@@ -1,7 +1,6 @@
 -mwxuy
 -i fuzix.ihx
 -b _CODE=0x0100
--b _DISCARD=0xD000
 -b _COMMONMEM=0xE800
 -l z80
 platform-trs80/crt0.rel
index 35e6327..919828c 100644 (file)
@@ -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
index 08e8bb3..a11ca7a 100644 (file)
@@ -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;
index 1719f1b..52a9a8f 100644 (file)
            .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)
 ; -----------------------------------------------------------------------------