From: Alan Cox Date: Tue, 27 Oct 2015 19:25:26 +0000 (+0000) Subject: micropack: further work on banked syscalls X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=a219ead9fecaef0a78b09d0adb30df9b163eb46b;p=FUZIX.git micropack: further work on banked syscalls Move swap on a slot, assume swap bank 0 is preloaded with 4K x n images by bank number (bank 0 is free and means "any"). --- diff --git a/Kernel/platform-micropack/Makefile b/Kernel/platform-micropack/Makefile index 00709586..f79403a4 100644 --- a/Kernel/platform-micropack/Makefile +++ b/Kernel/platform-micropack/Makefile @@ -1,15 +1,17 @@ DSRCS = ../dev/z80pack/devlpr.c ../dev/z80pack/devfd.c -CSRCS = devices.c main.c devtty.c syscall_bank.c +CSRCS = devices.c main.c devtty.c +CBSRCS = syscall_bank.c ASRCS = crt0.s z80pack.s ASRCS += tricks.s commonmem.s AOBJS = $(ASRCS:.s=.rel) COBJS = $(CSRCS:.c=.rel) +CBOBJS = $(CBSRCS:.c=.rel) DOBJS = $(patsubst ../dev/z80pack/%.c,%.rel, $(DSRCS)) -OBJS = $(AOBJS) $(COBJS) $(DOBJS) +OBJS = $(AOBJS) $(COBJS) $(DOBJS) $(CBOBJS) CROSS_CCOPTS += -I../dev/z80pack/ @@ -28,6 +30,9 @@ $(AOBJS): %.rel: %.s $(COBJS): %.rel: %.c $(CROSS_CC) $(CROSS_CCOPTS) -c $< +$(CBOBJS): %.rel: %.c + $(CROSS_CC) $(CROSS_CCOPTS) --constseg DATAAL -c $< + $(DOBJS): %.rel: ../dev/z80pack/%.c $(CROSS_CC) $(CROSS_CCOPTS) -c $< diff --git a/Kernel/platform-micropack/devices.c b/Kernel/platform-micropack/devices.c index c60640f7..c16f2080 100644 --- a/Kernel/platform-micropack/devices.c +++ b/Kernel/platform-micropack/devices.c @@ -37,7 +37,8 @@ bool validdev(uint16_t dev) void device_init(void) { int i; - /* Add 64 swaps (4MB) to use the entire J drive */ - for (i = 0; i < MAX_SWAPS; i++) + /* The first swap area is reserved for the banked syscall blocks */ + /* Add a max of 63 swaps (4MB) to use the entire J drive */ + for (i = 1; i <= MAX_SWAPS; i++) swapmap_add(i); } diff --git a/Kernel/platform-micropack/fuzix.lnk b/Kernel/platform-micropack/fuzix.lnk index 9bfe055c..80babec6 100644 --- a/Kernel/platform-micropack/fuzix.lnk +++ b/Kernel/platform-micropack/fuzix.lnk @@ -1,6 +1,8 @@ -mwxuy +-r -i fuzix.ihx --b _CODE=0xC000 +-b _DATAAL=0xC000 +-b _CODE=0xC040 -b _DISCARD=0x5000 -b _UDATA=0x7E00 -b _CODE6=0x8000 @@ -39,4 +41,5 @@ swap.rel devsys.rel platform-micropack/devlpr.rel platform-micropack/devtty.rel +platform-micropack/syscall_bank.rel -e diff --git a/Kernel/platform-micropack/tricks.s b/Kernel/platform-micropack/tricks.s index ae4d5f74..b789c992 100644 --- a/Kernel/platform-micropack/tricks.s +++ b/Kernel/platform-micropack/tricks.s @@ -17,6 +17,8 @@ .globl interrupt_handler .globl _swapper .globl _swapout + .globl _curbank + .globl bank_switch_a ; imported debug symbols .globl outstring, outde, outhl, outbc, outnewline, outchar, outcharhex @@ -83,6 +85,8 @@ _switchin: ; We are still on the departing processes stack, which is ; fine for now. ; + ld a, (_curbank) + ld (U_DATA__U_PAGE2), a ld sp, #_swapstack push hl ; We will always swap out the current process @@ -104,6 +108,19 @@ not_swapped: sbc hl, de ; subtract, result will be zero if DE==IX jr nz, switchinfail + ld a, (U_DATA__U_INSYS) + or a + jr z, not_sys + ld l, a + ; Bank rigt ? + ld a, (U_DATA__U_PAGE2) + ; Any bank + or a + jr z, not_sys + ; Need to switch bank + ld l, a + call bank_switch_a +not_sys: ; wants optimising up a bit ld ix, (U_DATA__U_PTAB) ; next_process->p_status = P_RUNNING diff --git a/Kernel/platform-micropack/z80pack.s b/Kernel/platform-micropack/z80pack.s index d1a294a9..12020974 100644 --- a/Kernel/platform-micropack/z80pack.s +++ b/Kernel/platform-micropack/z80pack.s @@ -24,6 +24,8 @@ .globl map_save .globl map_restore .globl platform_interrupt_all + .globl bank_switch_a + .globl _curbank ; exported debugging tools .globl _trap_monitor @@ -40,6 +42,8 @@ .globl null_handler .globl nmi_handler .globl interrupt_handler + .globl _syscall_bank + .globl _hd_read .globl outcharhex .globl outhl, outde, outbc @@ -65,9 +69,6 @@ _trap_reboot: ld a, #1 out (29), a -; ----------------------------------------------------------------------------- -; KERNEL MEMORY BANK (below 0xC000, only accessible when the kernel is mapped) -; ----------------------------------------------------------------------------- .area _CODE init_early: @@ -125,7 +126,7 @@ _program_vectors: ; set restart vector for UZI system calls ld (0x0030), a ; (rst 30h is unix function call vector) - ld hl, #unix_syscall_entry + ld hl, #overlay_syscall_entry ld (0x0031), hl ; Set vector for jump to NULL @@ -158,5 +159,51 @@ outchar: out (0x01), a ret +overlay_syscall_entry: + ld hl, #18 + add hl, sp + ld hl, #_syscall_bank ; FIXME load both as sdasz80 sulks + ld l, (hl) + ld a, (hl) + or a + jp z, unix_syscall_entry + ld a, (_curbank) + cp (hl) + call nz, bank_switch_hl + jp unix_syscall_entry + ; + ; Flip bank + ; +bank_switch_hl: + ld a, (hl) +bank_switch_a: + push bc + push de + push iy + ld (_curbank), a + add a, a ; 8 * 512 blocks per instance + add a, a + add a, a + ld h, #0 + ld l, a + ld (U_DATA__U_OFFSET), hl + ld hl, #0x8000 + ld (U_DATA__U_BASE), hl + ld hl, #0xE00 + ld (U_DATA__U_COUNT), hl + ld hl, #0x0101 + push hl + xor a + push af + inc sp + call _hd_read + inc sp + pop af + pop iy + pop de + pop bc + _need_resched: - .db 0 + .db 0 +_curbank: + .db 0