Permalink
Browse files

Kernel: Avoid race in OS_ReadC.

Previously if a key was pressed just before the call
to Portable_Idle the key would not be processes until
the following interrupt.
  • Loading branch information...
TimothyEBaldwin committed Feb 10, 2017
1 parent 6788423 commit 4bf1f543ba329274a692dd7bd97abfbf6bf8673e
Showing with 16 additions and 10 deletions.
  1. +16 −10 castle/RiscOS/Sources/Kernel/s/PMF/key
@@ -971,7 +971,7 @@ RdchInkey Entry
; Enable interrupts so that keyboard can work properly
WritePSRc SVC_mode, r1
CLI SVC32_mode
LDR r1, =ZeroPage
LDRB r1, [r1, #RedirectInHandle]
@@ -1024,15 +1024,8 @@ RdchInkey Entry
LDRB R5, [R5, #PortableFlags] ; 0 if not a portable, else Portable_Features result
RdchLoop
LDR R0, =ZeroPage
LDRB R0, [R0, #ESC_Status]
MOVS R0, R0, LSL #(32-6) ; shift relevant bit into carry
MOVCS R0, #27 ; escape detected
BCS ReturnChar2
LDROSB R1, InputStream ; 0 => keyboard, 1 => RS423
BL RDCHG
BCC ReturnChar2
; Enable interrupts so that keyboard can work properly
CLI SVC32_mode
; Sam's hack to call the callback vector if appropriate
@@ -1043,6 +1036,19 @@ RdchLoop
; here endeth the hack
; Disable interrupts to prevent a race with Portable_Idle
SEI SVC32_mode
LDR R0, =ZeroPage
LDRB R0, [R0, #ESC_Status]
MOVS R0, R0, LSL #(32-6) ; shift relevant bit into carry
MOVCS R0, #27 ; escape detected
BCS ReturnChar2
LDROSB R1, InputStream ; 0 => keyboard, 1 => RS423
BL RDCHG
BCC ReturnChar2
TEQ R4, #0 ; EQ => inkey, NE => rdch
LDREQ R0, InkeyCounter ; if inkey
TEQEQ R0, #0 ; and count expired

0 comments on commit 4bf1f54

Please sign in to comment.