From a73126bd246e8f3bba800c2926567a2b47341bc0 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Thu, 7 Mar 2019 14:32:23 +0000 Subject: [PATCH] pentagon: more work in progress for fixed 16K ROM systems --- Kernel/platform-pentagon/README | 28 +---- Kernel/platform-pentagon/crt0.s | 4 +- Kernel/platform-pentagon/fuzix.lnk | 5 +- Kernel/platform-pentagon/pentagon.s | 183 +++++++++++++++++++++------- Kernel/platform-pentagon/rules.mk | 4 +- 5 files changed, 153 insertions(+), 71 deletions(-) diff --git a/Kernel/platform-pentagon/README b/Kernel/platform-pentagon/README index f2646bc0..f14a3713 100644 --- a/Kernel/platform-pentagon/README +++ b/Kernel/platform-pentagon/README @@ -1,5 +1,5 @@ -Experimental porting work for Pentagon and similar systems that have the ability -to somehow get the low 16K mapped into page 0 and have at least 256K of RAM. +Experimental porting work for Pentagon and similar systems that have no ability +to map RAM low. For now we hardcode 256K and Pentagon style rules (although it seems they vary even by pentagon type). As far as I can make out the basic rules for @@ -11,23 +11,7 @@ Then it gets more complicated (and the partial decode ports make it worse) Pentagon uses bits 7/6 to allow for 512K RAM -Some pentagon designs use 1FFD bit 0 to put RAM 0 into the low 16K, and -use 1FFD bits 4 and 7 instead of 7FFD bits 7/6 - -Pentagon 1MB uses EFF7 bit 3 to turn on the RAM mapping - -Scorpion 256/Kay 256 uses 1FFD bit 0 to put RAM 0 into the low 16K and then -uses 1FFD bit 4 for the 256K select. Scoripon uses 4/6/7 if 1MB -Kay 1MB uses 1FFD 4 and 7 for 256/512 and 7FFD bit 7 for 1MB bank (why!!!) - -ZX Profi uses DFFD bits 0-2 to select the upper page bits. Those that -support it (Profi 1024 ?) bit 4 maps RAM0. There are other weird mappings -too. - -ATM us FDFD bits 0-2 but early ones can't map over ROM. Late ATM goes up to -4MB and can - -What a mess 8) +ATM us FDFD bits 0-2 ---- These machines all have the same basic problem, there is a 16K window at @@ -55,10 +39,8 @@ User processes live in 3/4 and 8+. We have copy stuff back and forth to page 2 due to the memory manager liits. To Do: -- Debug the rest -- Write SMUC driver code -- Work out what we need to do for Pentagon v Scorpion etc -- Floppy driver +- Update the loader +- Debug the code - Optimizations for switching (runticks expiry on non-preempt case should we clear runticks - pro it gets us better perf, anti it reduces responsiveness. diff --git a/Kernel/platform-pentagon/crt0.s b/Kernel/platform-pentagon/crt0.s index 33caf7b0..092eb071 100644 --- a/Kernel/platform-pentagon/crt0.s +++ b/Kernel/platform-pentagon/crt0.s @@ -27,8 +27,10 @@ .area _CODE2 ; We start this bank with FONT so that we have it aligned .area _FONT - .area _CODE3 .area _VIDEO + .area _CODE3 + + .area _CODE4 ; Discard is dumped in at 0x8000 and will be blown away later. .area _DISCARD diff --git a/Kernel/platform-pentagon/fuzix.lnk b/Kernel/platform-pentagon/fuzix.lnk index 195c964e..ae4674ff 100644 --- a/Kernel/platform-pentagon/fuzix.lnk +++ b/Kernel/platform-pentagon/fuzix.lnk @@ -1,10 +1,11 @@ -mwxuy -r -i fuzix.ihx --b _COMMONDATA=0x0100 +-b _COMMONDATA=0x4000 -b _CODE1=0xC000 -b _CODE2=0xC000 --b _FONT=0xC000 +-b _FONT=0xDB00 +-b _CODE4=0xC000 -b _DISCARD=0x8400 -l z80 platform-pentagon/crt0.rel diff --git a/Kernel/platform-pentagon/pentagon.s b/Kernel/platform-pentagon/pentagon.s index da2c05e1..7d1ff0fa 100644 --- a/Kernel/platform-pentagon/pentagon.s +++ b/Kernel/platform-pentagon/pentagon.s @@ -1,5 +1,18 @@ ; -; Pentagon hardware support +; Pentagon 256K+ hardware support +; A 128K machine needs something to put RAM low (eg DivIDE) and can thus +; use the zxdiv tree, although we might want to add printer support for +; it somehow (autodetect question) +; +; Kernel is banked into +; 0 CODE 1 +; 1 CODE 2 + BUFFERS +; 3 CODE 4 +; 7 CODE 3 + VIDEO + FONTS +; 2/5 4000-BFFF (common and user low buffer) +; +; 4 Free +; 8+ Free ; .module pentagon @@ -57,22 +70,36 @@ .globl __bank_0_1 .globl __bank_0_2 .globl __bank_0_3 + .globl __bank_0_4 .globl __bank_1_2 .globl __bank_1_3 + .globl __bank_1_4 .globl __bank_2_1 .globl __bank_2_3 + .globl __bank_2_4 .globl __bank_3_1 .globl __bank_3_2 + .globl __bank_3_4 + .globl __bank_4_1 + .globl __bank_4_2 + .globl __bank_4_3 .globl __stub_0_1 .globl __stub_0_2 .globl __stub_0_3 + .globl __stub_0_4 .globl __stub_1_2 .globl __stub_1_3 + .globl __stub_1_4 .globl __stub_2_1 .globl __stub_2_3 + .globl __stub_2_4 .globl __stub_3_1 .globl __stub_3_2 + .globl __stub_3_4 + .globl __stub_4_1 + .globl __stub_4_2 + .globl __stub_4_3 .include "kernel.def" .include "../kernel-z80.def" @@ -94,9 +121,6 @@ _platform_monitor: _platform_reboot: di im 1 - ld bc, #0xeff7 - xor a - out (c),a ; turn off RAM in low 16K ld bc, #0x7ffd xor a ; 128K ROM, initial banks, low screen out (c), a @@ -132,38 +156,38 @@ init_hardware: ld hl, #256 ld (_ramsize), hl ; We lose the following to the system - ; 0: low 16K of kernel - ; 1: first kernel bank at C000 + ; 0: first kernel bank at C000 + ; 1: second kernel bank at C000 ; 2: 4000-7FFF (screen and buffers) + ; 3: fourth kernel bank at C000 ; 5: 8000-BFFF (working 16K copy) ; 6: second kernel bank at C000 ; 7: third kernel bank at C000 ; - ; We might be able to squash things up and get 6 or 7 back - ; but as we work in pairs it's not actually that interesting. OTOH - ; getting 6000-7FFF back might be for program sizes. - ; ld hl, #(256 - 96) ld (_procmem), hl + ; + ; No low RAM so need IM2 and custom syscall interface + ; (will need to tackle that nicely in libc too) + ; + ld a,#0xC3 - ld (0x00),a - ld (0x30),a - ld (0x38),a - ld (0x66),a - ld hl,#null_handler - ld (0x01),hl + ld (0xFFFD),a + ld (0xFFF4),a ld hl,#unix_syscall_entry - ld (0x31),hl + ld (0xFFFE),hl ld hl,#interrupt_handler - ld (0x39),hl - ld hl,#nmi_handler - ld (0x67),hl + ld (0xFFF5),hl ; screen initialization push af call _vtinit pop af + ld a,#0x39 + ld i,a + im 2 ; Everything ends up at FFF4 + ret ;------------------------------------------------------------------------------ @@ -309,10 +333,11 @@ _need_resched: ; 1 0 ; 2 1 ; 3 7 +; 4 3 ; ; __bank_0_1: - ld a,#1 ; switch to physical bank 1 (logical 1) + xor a ; switch to physical bank 1 (logical 1) bankina0: ; ; Get the target address first, otherwise we will change @@ -328,23 +353,28 @@ bankina0: call switch_bank ; Move to new bank ; figure out which bank to map on the return path ld a, c - dec a + or a jr z, __retmap1 - cp #5 + dec a jr z, __retmap2 + cp #1 ; 3 phys = logical 4 + jr z, __retmap4 jr __retmap3 callhl: jp (hl) __bank_0_2: - ld a, #6 ; logical 2 -> physical 6 + ld a, #1 ; logical 2 -> physical 1 jr bankina0 __bank_0_3: ld a, #7 ; logical 3 -> physical 7 jr bankina0 +__bank_0_4: + ld a, #3 ; logical 4 -> physical 3 + jr bankina0 __bank_1_2: - ld a, #6 + ld a, #1 bankina1: pop hl ; Return address (points to true function address) ld e, (hl) ; DE = function to call @@ -356,14 +386,17 @@ bankina1: __retmap1: ex de, hl call callhl ; call the function - ld a,#1 ; return to bank 1 (physical 1) + xor a ; return to bank 1 (physical 1) jp switch_bank __bank_1_3: ld a, #7 jr bankina1 +__bank_1_4: + ld a, #3 + jr bankina1 __bank_2_1: - ld a,#1 + xor a bankina2: pop hl ; Return address (points to true function address) ld e, (hl) ; DE = function to call @@ -375,14 +408,17 @@ bankina2: __retmap2: ex de, hl call callhl ; call the function - ld a, #6 ; return to bank 2 + ld a, #1 ; return to bank 2 jp switch_bank __bank_2_3: ld a, #7 jr bankina2 +__bank_2_4: + ld a, #3 + jr bankina2 __bank_3_1: - ld a, #1 + xor a bankina3: pop hl ; Return address (points to true function address) ld e, (hl) ; DE = function to call @@ -394,39 +430,69 @@ bankina3: __retmap3: ex de, hl call callhl ; call the function - ld a, #7 ; return to bank 0 + ld a, #7 ; return to bank 3 jp switch_bank - __bank_3_2: - ld a, #6 + ld a, #1 + jr bankina3 +__bank_3_4: + ld a, #3 jr bankina3 +__bank_4_1: + xor a +bankina4: + pop hl ; Return address (points to true function address) + ld e, (hl) ; DE = function to call + inc hl + ld d, (hl) + inc hl + push hl ; Restore corrected return pointer + call switch_bank ; Move to new bank +__retmap4: + ex de, hl + call callhl ; call the function + ld a, #3 ; return to bank 4 + jp switch_bank +__bank_4_2: + ld a, #1 + jr bankina3 +__bank_4_3: + ld a, #7 + jr bankina3 + + ; ; Stubs need some stack munging and use DE ; __stub_0_1: - ld a,#1 + xor a __stub_0_a: pop hl ; the return ex (sp), hl ; write it over the discard ld bc, (current_map) call switch_bank ld a, c - dec a + or a ; bank 0 (logical 1) jr z, __stub_1_ret - cp #5 ; bank 6 + dec a ; bank 1 (logical 2) jr z, __stub_2_ret - jr __stub_3_ret ; bank 7 + cp #1 ; bank 3 (logical 4) + jr z, __stub_4_ret + jr __stub_3_ret ; bank 7 (logical 3) __stub_0_2: - ld a, #6 + ld a, #1 jr __stub_0_a __stub_0_3: ld a, #7 jr __stub_0_a +__stub_0_4: + ld a, #3 + jr __stub_0_a __stub_1_2: - ld a, #6 + ld a, #1 __stub_1_a: pop hl ; the return ex (sp), hl ; write it over the discard @@ -434,7 +500,7 @@ __stub_1_a: __stub_1_ret: ex de, hl call callhl - ld a,#1 + xor a call switch_bank pop de push de ; dummy the caller will discard @@ -443,9 +509,12 @@ __stub_1_ret: __stub_1_3: ld a, #7 jr __stub_1_a +__stub_1_4: + ld a, #3 + jr __stub_1_a __stub_2_1: - ld a,#1 + xor a __stub_2_a: pop hl ; the return ex (sp), hl ; write it over the discad @@ -453,7 +522,7 @@ __stub_2_a: __stub_2_ret: ex de, hl ; DE is our target call callhl - ld a,#6 + ld a,#1 call switch_bank pop de push de ; dummy the caller will discard @@ -462,9 +531,12 @@ __stub_2_ret: __stub_2_3: ld a, #7 jr __stub_2_a +__stub_2_4: + ld a, #3 + jr __stub_2_a __stub_3_1: - ld a,#1 + xor a __stub_3_a: pop hl ; the return ex (sp), hl ; write it over the discad @@ -479,5 +551,30 @@ __stub_3_ret: push de ret __stub_3_2: - ld a, #6 + ld a, #1 + jr __stub_3_a +__stub_3_4: + ld a, #3 jr __stub_3_a + +__stub_4_1: + xor a +__stub_4_a: + pop hl ; the return + ex (sp), hl ; write it over the discad + call switch_bank +__stub_4_ret: + ex de, hl + call callhl + ld a,#2 + call switch_bank + pop de + push de ; dummy the caller will discard + push de + ret +__stub_4_2: + ld a, #1 + jr __stub_4_a +__stub_4_3: + ld a, #7 + jr __stub_4_a diff --git a/Kernel/platform-pentagon/rules.mk b/Kernel/platform-pentagon/rules.mk index c0539a62..1e4d3020 100644 --- a/Kernel/platform-pentagon/rules.mk +++ b/Kernel/platform-pentagon/rules.mk @@ -15,5 +15,5 @@ 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 +export CROSS_CC_SYS4=--codeseg CODE4 +export CROSS_CC_SYS5=--codeseg CODE4 -- 2.34.1