From 3e614f69b83f7fe5d503fc5ab4a08f96b2d7b474 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Thu, 22 Nov 2018 00:19:16 +0000 Subject: [PATCH] zxdiv: Fix various things Map the code low Mark code as code1 so it banks right Fix the writable code references Sort out the udata mapping Fix the __memcpy calls to call our bank code not invalid sdcc lib code Remove strlcpy we don't use Fix minor fork bugs With this we get to the point of init running and forking. No further but we really need swap on to make any real progress. --- Kernel/platform-zxdiv/Makefile | 3 +++ Kernel/platform-zxdiv/README | 16 +++++++++++----- Kernel/platform-zxdiv/config.h | 4 +--- Kernel/platform-zxdiv/crt0.s | 7 ++++--- Kernel/platform-zxdiv/fuzix.lnk | 8 +++++--- Kernel/platform-zxdiv/kernel.def | 8 ++++---- Kernel/platform-zxdiv/main.c | 14 +++++++++----- Kernel/platform-zxdiv/rules.mk | 11 ++++++----- Kernel/platform-zxdiv/tricks.s | 5 +++-- Kernel/platform-zxdiv/zx128.s | 2 +- 10 files changed, 47 insertions(+), 31 deletions(-) diff --git a/Kernel/platform-zxdiv/Makefile b/Kernel/platform-zxdiv/Makefile index 2d79c7a0..0bbb5739 100644 --- a/Kernel/platform-zxdiv/Makefile +++ b/Kernel/platform-zxdiv/Makefile @@ -38,6 +38,9 @@ clean: # Re-order the image and snapshop it image: + # Merge the first code bank into common + dd if=../bank1.bin bs=16384 skip=3 seek=3 count=1 \ + of=../common.bin conv=notrunc # The bootstrap to con Fatware dd if=../common.bin of=BOOT.BIN bs=8192 count=1 # Rest of the base image, starts at 0x2200, pad it diff --git a/Kernel/platform-zxdiv/README b/Kernel/platform-zxdiv/README index 578db85e..3e792be0 100644 --- a/Kernel/platform-zxdiv/README +++ b/Kernel/platform-zxdiv/README @@ -40,7 +40,9 @@ We run with the following mapping 4000-7FFF Kernel data continued (lots of space) -8000-BFFF _DISCARD area - blown away when we exec init +8000-83FF Needed to create the exec of init +8400-BFFF _DISCARD area - blown away when we exec init + (tons of room in this space) C000-FFFF 0: Kernel CODE (fairly full) @@ -61,11 +63,8 @@ around we exchange it with bank 6 as we go. To Do: -- Get the DivIDE interface working -- Review DivIDE writes - is the port aliasing safe with a full - otir or do we need to avoid port aliasing ? - Check the swap hooks are ok -- See what we can get below 0x2000 +- Turn on swap so we can make progress - 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 @@ -155,3 +154,10 @@ hassle. Could we jump up and down on it enough to get user to be a bit bigger than 32K and if so where and how do we handle the extra + + +DONE - Get the DivIDE interface working +DONE - See what we can get below 0x2000 +DONE - Review DivIDE writes - is the port aliasing safe with a full + otir or do we need to avoid port aliasing ? - safe +DONE - Crash when we fork() or switch ? diff --git a/Kernel/platform-zxdiv/config.h b/Kernel/platform-zxdiv/config.h index dd050eee..6b059a1f 100644 --- a/Kernel/platform-zxdiv/config.h +++ b/Kernel/platform-zxdiv/config.h @@ -1,5 +1,3 @@ -#define CONFIG_LEVEL_0 - #define CONFIG_IDE #define CONFIG_SD #define SD_DRIVE_COUNT 1 /* For the moment */ @@ -42,7 +40,7 @@ #define TICKSPERSEC 50 /* Ticks per second */ #define PROGBASE 0x8000 /* also data base */ #define PROGLOAD 0x8000 /* also data base */ -#define PROGTOP 0xFC00 /* Top of program, base of U_DATA copy */ +#define PROGTOP 0xFE00 /* Top of program, base of U_DATA copy */ #define PROC_SIZE 32 /* Memory needed per process */ #define BOOT_TTY (513) /* Set this to default device for stdio, stderr */ diff --git a/Kernel/platform-zxdiv/crt0.s b/Kernel/platform-zxdiv/crt0.s index 77f2d985..0b9d0367 100644 --- a/Kernel/platform-zxdiv/crt0.s +++ b/Kernel/platform-zxdiv/crt0.s @@ -2,6 +2,7 @@ ; ; Our common lives low ; + .area _CODE .area _COMMONMEM .area _STUBS .area _CONST @@ -28,7 +29,7 @@ ; ; All our code is banked at 0xC000 ; - .area _CODE + .area _CODE1 .area _CODE2 ; ; Code3 sits above the display area along with the font and video @@ -69,7 +70,7 @@ ; the kernel image for us from blocks 1+ and all is good. ; - .area _CODE + .area _CODE1 .globl _go @@ -109,7 +110,7 @@ stop: halt ; Boot marker at 0x2200 - .area _COMMONMEM + .area _COMMONDATA .globl _marker _marker: .byte 'Z' ; marker diff --git a/Kernel/platform-zxdiv/fuzix.lnk b/Kernel/platform-zxdiv/fuzix.lnk index d379a3be..26efb812 100644 --- a/Kernel/platform-zxdiv/fuzix.lnk +++ b/Kernel/platform-zxdiv/fuzix.lnk @@ -1,11 +1,13 @@ -mwxuy -r -i fuzix.ihx --b _COMMONMEM=0x2200 --b _CODE=0xC000 +-b _CODE=0x0200 +-b _COMMONMEM=0x400 +-b _COMMONDATA=0x2200 +-b _CODE1=0xC000 -b _CODE2=0xC000 -b _CODE3=0xDB00 --b _DISCARD=0x8000 +-b _DISCARD=0x8400 -b BOOT1FEC=0x1FEC -b BOOT1FF7=0x1FF7 -b BOOT1FFE=0x1FFE diff --git a/Kernel/platform-zxdiv/kernel.def b/Kernel/platform-zxdiv/kernel.def index 24abedce..2a1125f6 100644 --- a/Kernel/platform-zxdiv/kernel.def +++ b/Kernel/platform-zxdiv/kernel.def @@ -1,10 +1,10 @@ ; UZI mnemonics for memory addresses etc -; FIXME: THIS IS WRONG - NEED TO SORT OUT MAPPINGS AND DEAL WITH THIS -U_DATA .equ 0x4000 ; (this is struct u_data from kernel.h) -U_DATA__TOTALSIZE .equ 0x300 ; 256+256+256 bytes. +; We stick it straight after the tag +U_DATA .equ 0x2204 ; (this is struct u_data from kernel.h) +U_DATA__TOTALSIZE .equ 0x200 ; 256+256+256 bytes. -U_DATA_STASH .equ 0xFC00 ; FC00-FEFF +U_DATA_STASH .equ 0xFE00 ; FE00-FFFF Z80_TYPE .equ 1 diff --git a/Kernel/platform-zxdiv/main.c b/Kernel/platform-zxdiv/main.c index afdacd9e..762df544 100644 --- a/Kernel/platform-zxdiv/main.c +++ b/Kernel/platform-zxdiv/main.c @@ -22,12 +22,16 @@ void platform_interrupt(void) timer_interrupt(); } -size_t strlcpy(char *dst, const char *src, size_t dstsize) +/* + * So that we don't suck in a library routine we can't use from + * the runtime + */ + +int strlen(const char *p) { - size_t len = strlen(src); - size_t cp = len >= dstsize ? dstsize - 1 : len; - memcpy(dst, src, cp); - dst[cp] = 0; + int len = 0; + while(*p++) + len++; return len; } diff --git a/Kernel/platform-zxdiv/rules.mk b/Kernel/platform-zxdiv/rules.mk index a6a61151..9266fa42 100644 --- a/Kernel/platform-zxdiv/rules.mk +++ b/Kernel/platform-zxdiv/rules.mk @@ -8,11 +8,12 @@ CROSS_CCOPTS += --external-banker export BANKED=-banked # export CROSS_CC_SEG1=--codeseg CODE2 -export CROSS_CC_SEG3=--codeseg CODE -export CROSS_CC_SYS1=--codeseg CODE -export CROSS_CC_SYS2=--codeseg CODE -export CROSS_CC_SYS3=--codeseg CODE -export CROSS_CC_SYS4=--codeseg CODE +export CROSS_CC_SEG3=--codeseg CODE1 +export CROSS_CC_SEG4=--codeseg CODE1 +export CROSS_CC_SYS1=--codeseg CODE1 +export CROSS_CC_SYS2=--codeseg CODE1 +export CROSS_CC_SYS3=--codeseg CODE1 +export CROSS_CC_SYS4=--codeseg CODE3 export CROSS_CC_SYS5=--codeseg CODE3 # The banking default is to put fonts in bank3. We don't want this so build # our font as CONST so it lands where we want it diff --git a/Kernel/platform-zxdiv/tricks.s b/Kernel/platform-zxdiv/tricks.s index dc8b380b..eafffc64 100644 --- a/Kernel/platform-zxdiv/tricks.s +++ b/Kernel/platform-zxdiv/tricks.s @@ -261,7 +261,6 @@ _dup_low_page: out (c), a ret -fork_proc_ptr: .dw 0 ; (C type is struct p_tab *) -- address of child process p_tab entry ; ; Called from _fork. We are in a syscall, the uarea is live as the @@ -397,7 +396,7 @@ _dofork: ; bankfork: or #0x18 ; ROM bits for the bank - ld b, #0x3C ; 40 x 256 minus 4 sets for the uarea stash/irqs + ld b, #0x3E ; 64 x 256 minus 2 sets for the uarea stash/irqs ld hl, #0xC000 ; base of memory to fork (vectors included) bankfork_1: push bc ; Save our counter and also child offset @@ -440,3 +439,5 @@ _swapstack: _low_bank: .dw _ptab ; Init starts owning this +fork_proc_ptr: + .dw 0 ; (C type is struct p_tab *) -- address of child process p_tab entry diff --git a/Kernel/platform-zxdiv/zx128.s b/Kernel/platform-zxdiv/zx128.s index dd58cf31..11e2b024 100644 --- a/Kernel/platform-zxdiv/zx128.s +++ b/Kernel/platform-zxdiv/zx128.s @@ -104,7 +104,7 @@ _int_disabled: ; ----------------------------------------------------------------------------- ; KERNEL MEMORY BANK (above 0xC000, only accessible when the kernel is mapped) ; ----------------------------------------------------------------------------- - .area _CODE + .area _CODE1 ; ; The memory banker will deal with the map setting -- 2.34.1