z80: fix a nasty bug with the full bank switching model on swapless
authorAlan Cox <alan@linux.intel.com>
Tue, 7 Aug 2018 23:10:05 +0000 (00:10 +0100)
committerAlan Cox <alan@linux.intel.com>
Tue, 7 Aug 2018 23:10:05 +0000 (00:10 +0100)
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

index 0afc88e..6a669ef 100644 (file)
@@ -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