From 497f9af8196fd3326a57f540e5693abe93d2f066 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Sun, 26 Jul 2015 13:38:24 +0100 Subject: [PATCH] bank16k: Fixes for some of the swap issues 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 | 16 +++++++++++----- Kernel/bank16k_low.c | 9 ++++++--- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/Kernel/bank16k.c b/Kernel/bank16k.c index decb25ee..d7e8aefb 100644 --- a/Kernel/bank16k.c +++ b/Kernel/bank16k.c @@ -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 #include @@ -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 */ } diff --git a/Kernel/bank16k_low.c b/Kernel/bank16k_low.c index 0798f889..1035a897 100644 --- a/Kernel/bank16k_low.c +++ b/Kernel/bank16k_low.c @@ -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 */ -- 2.34.1