trs80: fix a tiny race in the floppy code
authorAlan Cox <alan@linux.intel.com>
Wed, 16 May 2018 21:18:14 +0000 (22:18 +0100)
committerAlan Cox <alan@linux.intel.com>
Wed, 16 May 2018 21:18:14 +0000 (22:18 +0100)
We could otherwise take an NMI in a IRQ held over until the EI. When that
happens we mangle the wrong stack and .... splat!

Kernel/platform-trs80/floppy.s

index 2456b2d..592222c 100644 (file)
@@ -61,6 +61,9 @@ nap:  dec     bc
 ;
 ;      The motor off logic is driven from hardware
 ;
+;      fdc_active must never be set when interrupts are enabled or we may
+;      take a motor off during an interrupt...
+;
 fd_nmi_handler:
        push    af
        push    bc
@@ -185,17 +188,16 @@ rwiowt:   djnz    rwiowt
 ;      Status registers
 ;
 fdxferdone:
-       ei
-fdxferdone2:
        xor     a
        ld      (fdc_active), a
+       ei
        in      a, (FDCREG)
        and     #0x19           ; Error bits + busy
        bit     0, a            ; Wait for busy to drop, return in a
        ret     z
        ld      a, (fdcctrl)
        out     (FDCCTRL), a
-       jr      fdxferdone2
+       jr      fdxferdone
 ;
 ;      Read from the disk - HL points to the target buffer
 ;