diff --git a/reactos/hal/halx86/generic/amd64/systimer.S b/reactos/hal/halx86/generic/amd64/systimer.S index a0482cce014..2a7dcff56f3 100644 --- a/reactos/hal/halx86/generic/amd64/systimer.S +++ b/reactos/hal/halx86/generic/amd64/systimer.S @@ -14,9 +14,6 @@ .data -_UnhandledMsg: - .asciz "\n\x7\x7!!! Unhandled or Unexpected Code at line: %lx!!!\n" - .global _MsgUnimplemented _MsgUnimplemented: .asciz "WARNING: %s at %s:%d is UNIMPLEMENTED!\n" @@ -27,18 +24,6 @@ _MsgUnimplemented: .text .code64 -.global _HalpReleaseCmosSpinLock -.func HalpReleaseCmosSpinLock -_HalpReleaseCmosSpinLock: - -.endfunc - -.global _HalpAcquireSystemHardwareSpinLock -.func HalpAcquireSystemHardwareSpinLock -_HalpAcquireSystemHardwareSpinLock: - -.endfunc - .global _HalpCalibrateStallExecution@0 .func HalpCalibrateStallExecution@0 _HalpCalibrateStallExecution@0: diff --git a/reactos/hal/halx86/generic/cmos.c b/reactos/hal/halx86/generic/cmos.c index 754d360a543..de5c443de94 100644 --- a/reactos/hal/halx86/generic/cmos.c +++ b/reactos/hal/halx86/generic/cmos.c @@ -5,6 +5,7 @@ * PURPOSE: CMOS Access Routines (Real Time Clock and LastKnownGood) * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org) * Eric Kohl (ekohl@abo.rhein-zeitung.de) + * Timo Kreuzer (timo.kreuzer@reactos.org) */ /* INCLUDES ******************************************************************/ @@ -17,9 +18,51 @@ KSPIN_LOCK HalpSystemHardwareLock; UCHAR HalpCmosCenturyOffset; +ULONG HalpSystemHardwareFlags; /* PRIVATE FUNCTIONS *********************************************************/ +VOID +NTAPI +HalpAcquireSystemHardwareSpinLock(VOID) +{ + ULONG Flags; + + /* Get flags and disable interrupts */ + Flags = __readeflags(); + _disable(); + + /* Try to acquire the lock */ + while (InterlockedBitTestAndSet((PLONG)&HalpSystemHardwareLock, 0)) + { + /* Lock is held, short wait and try again */ + YieldProcessor(); + } + + /* We have the lock, save the flags now */ + HalpSystemHardwareFlags = Flags; +} + +VOID +NTAPI +HalpReleaseCmosSpinLock(VOID) +{ + ULONG Flags; + + /* Get the flags */ + Flags = HalpSystemHardwareFlags; + + /* Release lock and check if we owned it */ + if (!InterlockedBitTestAndReset((PLONG)&HalpSystemHardwareLock, 0)) + { + /* The spin lock was not owned! */ + KeBugCheckEx(SPIN_LOCK_NOT_OWNED, 0, 0, 0, 0); + } + + /* Restore the flags */ + __writeeflags(Flags); +} + FORCEINLINE UCHAR HalpReadCmos(IN UCHAR Reg) diff --git a/reactos/hal/halx86/generic/i386/systimer.S b/reactos/hal/halx86/generic/i386/systimer.S index 62f11c1d5d1..16c1bc1f5da 100644 --- a/reactos/hal/halx86/generic/i386/systimer.S +++ b/reactos/hal/halx86/generic/i386/systimer.S @@ -17,83 +17,12 @@ _HalpLastPerfCounterLow: .long 0 _HalpLastPerfCounterHigh: .long 0 _HalpPerfCounterLow: .long 0 _HalpPerfCounterHigh: .long 0 -_HalpSystemHardwareFlags: .long 0 _UnhandledMsg: .asciz "\n\x7\x7!!! Unhandled or Unexpected Code at line: %lx!!!\n" /* FUNCTIONS *****************************************************************/ -.global _HalpReleaseCmosSpinLock@0 -.func HalpReleaseCmosSpinLock@0 -_HalpReleaseCmosSpinLock@0: - -#ifdef CONFIG_SMP - /* Save clobbered register */ - push eax - - /* Push saved EFLAGS */ - push _HalpSystemHardwareFlags - - /* Release the lock */ - lea eax, _HalpSystemHardwareLock - RELEASE_SPINLOCK(eax) - - /* Restore EFLAGS */ - popf - - /* Return */ - pop eax - ret -#else - /* Restore EFLAGS and return */ - push _HalpSystemHardwareFlags - popf - ret -#endif - -.endfunc - -.global _HalpAcquireSystemHardwareSpinLock@0 -.func HalpAcquireSystemHardwareSpinLock@0 -_HalpAcquireSystemHardwareSpinLock@0: - -#ifdef CONFIG_SMP - /* Save clobbered register */ - push eax - -HardwareLock: - /* Save EFLAGS and disable interrupts */ - pushf - cli - - /* This is the CMOS lock, acquire it */ - lea eax, _HalpSystemHardwareLock - ACQUIRE_SPINLOCK(eax, CmosSpin) - - /* We have it, return the flags */ - pop _HalpSystemHardwareFlags - pop eax - ret - -CmosSpin: - - /* Restore EFLAGS */ - pushf _HalpSystemHardwareLock - popf - - /* Spin */ - SPIN_ON_LOCK(eax, HardwareLock) -#else - /* Save EFLAGS, disable interrupts and return */ - pushf - cli - pop _HalpSystemHardwareFlags - ret -#endif - -.endfunc - .global _HalpCalibrateStallExecution@0 .func HalpCalibrateStallExecution@0 _HalpCalibrateStallExecution@0: