From c9465c0d879dab35e8df7754c116a9aecac17f34 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Wed, 8 Aug 2018 00:10:05 +0100 Subject: [PATCH] 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 --- Kernel/lib/z80fixedbank.s | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 -- 2.34.1