bank16k: Fixes for some of the swap issues
authorAlan Cox <alan@linux.intel.com>
Sun, 26 Jul 2015 12:38:24 +0000 (13:38 +0100)
committerAlan Cox <alan@linux.intel.com>
Sun, 26 Jul 2015 12:38:24 +0000 (13:38 +0100)
Fix up some of the problems Brett Gordon found, but in a slightly different
way. Also fix up (hopefully) handling where the swap base is not 0.

Not yet all sorted and tested

Kernel/bank16k.c
Kernel/bank16k_low.c

index decb25e..d7e8aef 100644 (file)
@@ -18,6 +18,8 @@
  *     PROGTOP         first byte above process space
  *
  *     Page numbers must not include 0 (0 is taken as swapped)
+ *
+ *     SWAPBASE must be in the low 16K bank
  */
 #include <kernel.h>
 #include <kdata.h>
@@ -189,13 +191,15 @@ int swapout(ptptr p)
                return ENOMEM;
        blk = map * SWAP_SIZE;
        /* Write the app (and possibly the uarea etc..) to disk */
-       for (i = 0; i < 4; i ++) {
+       for (i = 0; i < 4; i++) {
                swapwrite(SWAPDEV, blk, size, base, *pt++);
                base += 0x4000;
+               base &= 0xC000; /* Snap to bank alignment */
+                blk += size;
                /* Last bank is determined by SWAP SIZE. We do the maths
                   in 512's (0x60 = 0xC000) */
-               if (i == 3)
-                       size = SWAP_SIZE - 0x60;
+               if (i == 2)
+                       size = SWAP_SIZE + (SWAPBASE >> 9) - 0x60;
                else
                        size = 0x20;
        }
@@ -233,10 +237,12 @@ void swapin(ptptr p, uint16_t map)
        for (i = 0; i < 4; i ++) {
                swapread(SWAPDEV, blk, size, base, *pt++);
                base += 0x4000;
+               base &= 0xC000;
+               blk += size;
                /* Last bank is determined by SWAP SIZE. We do the maths
                   in 512's (0x60 = 0xC000) */
-               if (i == 3)
-                       size = SWAP_SIZE - 0x60;
+               if (i == 2)
+                       size = SWAP_SIZE + (SWAPBASE >> 9) - 0x60;
                else
                        size = 0x20;    /* 16 K */
        }
index 0798f88..1035a89 100644 (file)
@@ -21,6 +21,9 @@
  *     SWAPDEV         if using swap
  *
  *     Page numbers must not include 0 (0 is taken as swapped)
+ *
+ *     Swap needs debugging and fixes before it will be usable (review
+ *     bank16k.c)
  */
 
 
@@ -176,7 +179,7 @@ int swapout(ptptr p)
        uint16_t size = (0x4000 - SWAPBASE) >> 9;
        uint8_t *pt = (uint8_t *)&p->page;
 
-       if (page)
+       if (!page)
                panic("process already swapped!\n");
 #ifdef DEBUG
        kprintf("Swapping out %x (%d)\n", p, p->p_page);
@@ -199,7 +202,7 @@ int swapout(ptptr p)
                base += 0x4000;
                /* Last bank is determined by SWAP SIZE. We do the maths
                   in 512's (0x60 = 0xC000) */
-               if (i == 3)
+               if (i == 2)
                        size = SWAP_SIZE_EXCL_ZP - 0x60;
                else
                        size = 0x20;
@@ -246,7 +249,7 @@ void swapin(ptptr p, uint16_t map)
                base += 0x4000;
                /* Last bank is determined by SWAP SIZE. We do the maths
                   in 512's (0x60 = 0xC000) */
-               if (i == 3)
+               if (i == 2)
                        size = SWAP_SIZE_EXCL_ZP - 0x60;
                else
                        size = 0x20;    /* 16 K */