zxdiv: turn on SWAP
authorAlan Cox <alan@linux.intel.com>
Thu, 22 Nov 2018 14:48:51 +0000 (14:48 +0000)
committerAlan Cox <alan@linux.intel.com>
Thu, 22 Nov 2018 14:48:51 +0000 (14:48 +0000)
We now fork and blow up on the second fork trying to do swapping. Progress
of sorts

Kernel/platform-zxdiv/README
Kernel/platform-zxdiv/bank128.c
Kernel/platform-zxdiv/config.h
Kernel/platform-zxdiv/discard.c
Kernel/platform-zxdiv/main.c
Kernel/platform-zxdiv/tricks.s

index 3e792be..ac71070 100644 (file)
@@ -63,8 +63,9 @@ around we exchange it with bank 6 as we go.
 
 To Do:
 
--      Check the swap hooks are ok
--      Turn on swap so we can make progress
+DONE   -       Check the swap hooks are ok
+DONE   -       Turn on swap so we can make progress
+       -       Debug crash on swapping
 -      Set video space in CODE3 bank to 0 not 0xFF for neatness
 -      Look at what is needed for other suitable interfaces. DIVMMC would
        in particular be good to support but that means another harder
@@ -78,6 +79,8 @@ To Do:
 -      Later DivIDE and DivMMC support both a 16K page mode and a lot more
        RAM (up to 512K). That at the very least would make a kick ass
        ramdisc/swap device even if the unit lacks the allram switch
+       (May also make sense to hae a build 'the other way up' where we
+       page apps out of 0000-3FFF copying 4000-7FFF. 
 -      Speccyboot (ENC28J60)
 -      SpectraNet (W5100)
 
index 6685402..d04a051 100644 (file)
@@ -102,8 +102,8 @@ int swapout(ptptr p)
        kprintf("Swapping out %x (%d)\n", p, p->p_page);
 #endif
 
-       /* We mever swap the live process so the second page is always
-          page 6 */
+       /* We never swap the live process so the second page is always
+          page 6 (FIXME: this will not be true once we go past 128K) */
         if (low_bank == p)
                panic("swapout");
 
index 6b059a1..13a39bc 100644 (file)
@@ -22,6 +22,8 @@
 #define CONFIG_FONT8X8
 #define CONFIG_FONT8X8SMALL
 
+#define CONFIG_DYNAMIC_SWAP
+
 /* Custom banking */
 
 /* We have two mappings from our 128K of memory */
@@ -53,7 +55,6 @@
 #define NUM_DEV_TTY 1
 
 #define TTYDEV   BOOT_TTY /* Device used by kernel for messages, panics */
-/* #define SWAPDEV  2051 */ /* Microdrive 3 : FIXME - configure and probe */
 #define NBUFS    9       /* Number of block buffers */
 #define NMOUNTS         4        /* Number of mounts at a time */
 #define MAX_BLKDEV 2       /* 2 IDE drives, 1 SD drive */
@@ -61,7 +62,8 @@
 #define SWAPBASE 0x8000
 #define SWAPTOP  0x10000UL
 #define SWAP_SIZE 0x40
-#define MAX_SWAPS 3            /* For now */
+#define MAX_SWAPS      16
+#define SWAPDEV  (swap_dev)  /* Device for swapping (dynamic). */
 
 /* All our pages get mapped into the top 16K bank for swapping use */
 #define swap_map(x)            ((uint8_t *)(x|0xC000))
index 1944d62..a3f3099 100644 (file)
@@ -3,15 +3,10 @@
 #include <kdata.h>
 #include <printf.h>
 #include <devtty.h>
+#include <blkdev.h>
 
 void pagemap_init(void)
 {
-#ifdef SWAPDEV
-  /* Swap */
-  swapmap_init(0);
-  swapmap_init(1);
-  swapmap_init(2);
-#endif
 }
 
 uint8_t platform_param(char *p)
@@ -29,3 +24,25 @@ void platform_copyright(void)
 {
 }
 
+/*
+ *     This function is called for partitioned devices if a partition is found
+ *     and marked as swap type. The first one found will be used as swap. We
+ *     only support one swap device.
+ */
+void platform_swap_found(uint8_t letter, uint8_t m)
+{
+       blkdev_t *blk = blk_op.blkdev;
+       uint16_t n;
+       if (swap_dev != 0xFFFF)
+               return;
+       letter -= 'a';
+       kputs("(swap) ");
+       swap_dev = letter << 4 | m;
+       n = blk->lba_count[m - 1] / SWAP_SIZE;
+       if (n > MAX_SWAPS)
+               n = MAX_SWAPS;
+#ifdef SWAPDEV
+       while (n)
+               swapmap_add(n--);
+#endif
+}
index 762df54..f2e374f 100644 (file)
@@ -5,6 +5,7 @@
 #include <devtty.h>
 
 uint16_t ramtop = PROGTOP;
+uint16_t swap_dev = 0xFFFF;
 
 /* On idle we spin checking for the terminals. Gives us more responsiveness
    for the polled ports */
index eafffc6..5eb7d39 100644 (file)
@@ -246,16 +246,17 @@ switchinfail:
 
 ; Interrupts should be off when this is called
 _dup_low_page:
-       ld a, #0x06 + 0x18              ;       low page alternate
+       di                              ; FIXME: check callers properly
+       ld a, #0x06 + 0x18              ; low page alternate
        ld bc, #0x7ffd
        out (c), a
 
-       ld hl, #0x8000                  ;       Fixed
-       ld de, #0xC000                  ;       Page we just mapped in
+       ld hl, #0x8000                  ; fixed
+       ld de, #0xC000                  ; page we just mapped in
        ld bc, #16384
        ldir
 
-       ld a, (current_map)             ;       restore mapping
+       ld a, (current_map)             ; restore mapping
        or #0x18                        ; ROM bits
        ld bc, #0x7ffd
        out (c), a