From 21c47901ec5626510f2199f1c392209612b1c5c6 Mon Sep 17 00:00:00 2001 From: Alexander Tsidaev Date: Mon, 24 Nov 2014 02:51:05 +0500 Subject: [PATCH] zx128: custom banking added --- Kernel/platform-zx128/Makefile | 9 ++++-- Kernel/platform-zx128/bankzx128.c | 53 +++++++++++++++++++++++++++++++ Kernel/platform-zx128/config.h | 9 +++--- Kernel/platform-zx128/uzi.lnk | 3 +- 4 files changed, 66 insertions(+), 8 deletions(-) create mode 100644 Kernel/platform-zx128/bankzx128.c diff --git a/Kernel/platform-zx128/Makefile b/Kernel/platform-zx128/Makefile index c6c92919..f0038508 100644 --- a/Kernel/platform-zx128/Makefile +++ b/Kernel/platform-zx128/Makefile @@ -1,13 +1,15 @@ - CSRCS = devtty.c CSRCS += devices.c main.c +CSRCS2 = bankzx128.c + ASRCS = crt0.s zx128.s zxvideo.s ASRCS += tricks.s commonmem.s COBJS = $(CSRCS:.c=.rel) +COBJS2 = $(CSRCS2:.c=.rel) AOBJS = $(ASRCS:.s=.rel) -OBJS = $(COBJS) $(AOBJS) +OBJS = $(COBJS) $(COBJS2) $(AOBJS) JUNK = $(CSRCS:.c=.lst) $(CSRCS:.c=.asm) $(CSRCS:.c=.sym) $(ASRCS:.s=.lst) $(ASRCS:.s=.sym) $(CSRCS:.c=.rst) $(ASRCS:.s=.rst) @@ -16,6 +18,9 @@ all: $(OBJS) $(COBJS): %.rel: %.c $(CROSS_CC) $(CROSS_CCOPTS) -c $< +$(COBJS2): %.rel: %.c + $(CROSS_CC) $(CROSS_CCOPTS) $(CROSS_CC_SEG2) -c $< + $(AOBJS): %.rel: %.s $(CROSS_AS) $(ASOPTS) $< diff --git a/Kernel/platform-zx128/bankzx128.c b/Kernel/platform-zx128/bankzx128.c new file mode 100644 index 00000000..d31b6b8e --- /dev/null +++ b/Kernel/platform-zx128/bankzx128.c @@ -0,0 +1,53 @@ +#include +#include +#include +#include + +/* This is copied version of bankfixed.c + The only difference is pagemap_realloc function. + Since we have PROGBASE at 0xC000, pagemap_realloc + returned ENOMEM even when 0 bytes were requested */ + +/* Kernel is 0, apps 1,2,3 etc */ +static unsigned char pfree[MAX_MAPS]; +static unsigned char pfptr = 0; +static unsigned char pfmax; + +void pagemap_add(uint8_t page) +{ + pfree[pfptr++] = page; + pfmax = pfptr; +} + +void pagemap_free(ptptr p) +{ + if (p->p_page == 0) + panic("free0"); + pfree[pfptr++] = p->p_page; +} + +int pagemap_alloc(ptptr p) +{ +#ifdef SWAP_DEV + if (pfptr == 0) { + swapneeded(p, 1); + } +#endif + if (pfptr == 0) + return ENOMEM; + p->p_page = pfree[--pfptr]; + return 0; +} + +/* Realloc is trivial - we can't do anything useful */ +int pagemap_realloc(uint16_t size) +{ + if (size - PROGBASE >= MAP_SIZE) + return ENOMEM; + return 0; +} + +uint16_t pagemap_mem_used(void) +{ + return (pfmax - pfptr) * (MAP_SIZE >> 10); +} diff --git a/Kernel/platform-zx128/config.h b/Kernel/platform-zx128/config.h index b31f3b59..cfd0cbfd 100644 --- a/Kernel/platform-zx128/config.h +++ b/Kernel/platform-zx128/config.h @@ -17,11 +17,12 @@ #define CONFIG_FONT8X8 #define CONFIG_FONT8X8SMALL -/* We have 1 bank at C000 with 6 possible pages to map, but I'm not sure - if CONFIG_BANK_FIXED is our choice. */ +/* We have 1 bank at C000 with 6 possible pages to map. + Our choise should be CONFIG_BANK_FIXED, but we are. + using custom implementation of it */ + +#undef CONFIG_BANK_FIXED -/* Fixed banking */ -#define CONFIG_BANK_FIXED /* 6 16K banks, 1 is for kernel needs */ #define MAX_MAPS 5 #define MAP_SIZE 0x4000U diff --git a/Kernel/platform-zx128/uzi.lnk b/Kernel/platform-zx128/uzi.lnk index fb55a5e9..7085013f 100644 --- a/Kernel/platform-zx128/uzi.lnk +++ b/Kernel/platform-zx128/uzi.lnk @@ -8,7 +8,6 @@ platform-zx128/commonmem.rel platform-zx128/zx128.rel platform-zx128/zxvideo.rel platform-zx128/main.rel -platform-zx128/devfd.rel start.rel version.rel lowlevel-z80.rel @@ -31,7 +30,7 @@ tty.rel vt.rel font8x8.rel mm.rel -bankfixed.rel +platform-zx128/bankzx128.rel swap.rel devsys.rel platform-zx128/devtty.rel -- 2.34.1