From: Alan Cox Date: Tue, 7 Aug 2018 23:10:05 +0000 (+0100) Subject: z80: fix a nasty bug with the full bank switching model on swapless X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=c9465c0d879dab35e8df7754c116a9aecac17f34;p=FUZIX.git z80: fix a nasty bug with the full bank switching model on swapless The swap case is ok as it always runs on the swap stack. The non swap case restores the process kernel stack underneath the curent sp. That in itself is fine as we have interrupts off. However we then called map_kernel which if the current sp was above the sp of the save would corrupt the stack. Instead restore sp first so that we push and pop data below the saved stack content --- diff --git a/Kernel/lib/z80fixedbank.s b/Kernel/lib/z80fixedbank.s index 0afc88e2..6a669efd 100644 --- a/Kernel/lib/z80fixedbank.s +++ b/Kernel/lib/z80fixedbank.s @@ -88,10 +88,8 @@ _switchin: call map_kernel - push de ld hl, #P_TAB__P_PAGE_OFFSET add hl, de ; process ptr - pop de .ifne CONFIG_SWAP .globl _swapper @@ -148,6 +146,9 @@ not_swapped: ldir exx + ; In the non swap case we must set so before we use the stack + ; otherwise we risk corrupting the restored stack frame + ld sp, (U_DATA__U_SP) call map_kernel ; check u_data->u_ptab matches what we wanted