From c4421e57c5c4f2e5fd8aafbe7443e31c396413fc Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Thu, 22 Nov 2018 14:48:51 +0000 Subject: [PATCH] zxdiv: turn on SWAP We now fork and blow up on the second fork trying to do swapping. Progress of sorts --- Kernel/platform-zxdiv/README | 7 +++++-- Kernel/platform-zxdiv/bank128.c | 4 ++-- Kernel/platform-zxdiv/config.h | 6 ++++-- Kernel/platform-zxdiv/discard.c | 29 +++++++++++++++++++++++------ Kernel/platform-zxdiv/main.c | 1 + Kernel/platform-zxdiv/tricks.s | 9 +++++---- 6 files changed, 40 insertions(+), 16 deletions(-) diff --git a/Kernel/platform-zxdiv/README b/Kernel/platform-zxdiv/README index 3e792be0..ac71070f 100644 --- a/Kernel/platform-zxdiv/README +++ b/Kernel/platform-zxdiv/README @@ -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) diff --git a/Kernel/platform-zxdiv/bank128.c b/Kernel/platform-zxdiv/bank128.c index 66854024..d04a051c 100644 --- a/Kernel/platform-zxdiv/bank128.c +++ b/Kernel/platform-zxdiv/bank128.c @@ -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"); diff --git a/Kernel/platform-zxdiv/config.h b/Kernel/platform-zxdiv/config.h index 6b059a1f..13a39bc0 100644 --- a/Kernel/platform-zxdiv/config.h +++ b/Kernel/platform-zxdiv/config.h @@ -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)) diff --git a/Kernel/platform-zxdiv/discard.c b/Kernel/platform-zxdiv/discard.c index 1944d62d..a3f30999 100644 --- a/Kernel/platform-zxdiv/discard.c +++ b/Kernel/platform-zxdiv/discard.c @@ -3,15 +3,10 @@ #include #include #include +#include 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 +} diff --git a/Kernel/platform-zxdiv/main.c b/Kernel/platform-zxdiv/main.c index 762df544..f2e374f0 100644 --- a/Kernel/platform-zxdiv/main.c +++ b/Kernel/platform-zxdiv/main.c @@ -5,6 +5,7 @@ #include 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 */ diff --git a/Kernel/platform-zxdiv/tricks.s b/Kernel/platform-zxdiv/tricks.s index eafffc64..5eb7d39e 100644 --- a/Kernel/platform-zxdiv/tricks.s +++ b/Kernel/platform-zxdiv/tricks.s @@ -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 -- 2.34.1