Author: sir_richard
Date: Tue Jan 26 22:41:05 2010
New Revision: 45276

URL: http://svn.reactos.org/svn/reactos?rev=45276&view=rev
Log:
[HAL]:  Implement the profile and clock interrupt trap/handlers in C instead of 
ASM. This allows the kernel to remove the ugly hacks based on internal 
knowledge of how the assembly/stack of the HAL is supposed to look like. 
Everything is now done through a clean C interface.
[NTOS]: Remove said hacks and have a normal C implementation of 
KeUpdateSystemTime. It exits the interrupt through a soft interrupt exit.
[NTOS]: Implement 4 lines of support code needed to handle interrupts during 
V8086 mode, which were lacking since we weren't hitting this case yet.
Note that now the KeUpdateSystemTime interface is not "compatible" with Windows 
anymore. This does not matter, since the only possible caller of 
KeUpdateSystemTime is a very specific HAL routine that needs a very specific 
stack layout to actually work, so the chance of anyone calling this API is 
absolutely zero (no, not even some experimental driver. It's absolutely 
impossible).

Modified:
    trunk/reactos/hal/halx86/generic/systimer.S
    trunk/reactos/hal/halx86/generic/timer.c
    trunk/reactos/hal/halx86/include/halp.h
    trunk/reactos/include/ndk/kefuncs.h
    trunk/reactos/ntoskrnl/include/internal/trap_x.h
    trunk/reactos/ntoskrnl/ke/i386/trap.s
    trunk/reactos/ntoskrnl/ke/time.c
    trunk/reactos/ntoskrnl/ntoskrnl.pspec

Modified: trunk/reactos/hal/halx86/generic/systimer.S
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/hal/halx86/generic/systimer.S?rev=45276&r1=45275&r2=45276&view=diff
==============================================================================
--- trunk/reactos/hal/halx86/generic/systimer.S [iso-8859-1] (original)
+++ trunk/reactos/hal/halx86/generic/systimer.S [iso-8859-1] Tue Jan 26 
22:41:05 2010
@@ -520,72 +520,3 @@
     mov _HalpLastPerfCounterHigh, eax
     jmp LoopPreInt
 .endfunc
-
-.globl _halpclockinterr...@0
-.func halpclockinterr...@0
-TRAP_FIXUPS hci_a, hci_t, DoFixupV86, DoFixupAbios
-_halpclockinterr...@0:
-
-    /* Enter trap */
-    INT_PROLOG hci_a, hci_t, DoPushFakeErrorCode
-
-    /* Push vector and make stack for IRQL */
-    push 0x30
-    sub esp, 4
-
-    /* Begin the interrupt */
-    push esp
-    push 0x30
-    push CLOCK2_LEVEL
-    call _halbeginsysteminterr...@12
-
-    /* Check if it's spurious */
-    or al, al
-    jz Spurious
-
-    /* Update the performance counter */
-    xor ebx, ebx
-    mov eax, _HalpCurrentRollOver
-    add _HalpPerfCounterLow, eax
-    adc _HalpPerfCounterHigh, ebx
-
-    /* Get the time increment and check if someone changed the clock rate */
-    mov eax, _HalpCurrentTimeIncrement
-    cmp _HalpClockSetMSRate, ebx
-    jz _keupdatesystemt...@0
-
-    /* FIXME: Someone did! */
-    int 3
-
-Spurious:
-
-    /* Exit the interrupt */
-    add esp, 8
-    jmp _kei386eoihel...@0
-.endfunc
-
-.globl _halpprofileinterr...@0
-.func halpprofileinterr...@0
-TRAP_FIXUPS hpi_a, hpi_t, DoFixupV86, DoFixupAbios
-_halpprofileinterr...@0:
-
-    /* Enter trap */
-    INT_PROLOG hpi_a, hpi_t, DoPushFakeErrorCode
-
-    /* Push vector and make stack for IRQL */
-    push 0x38
-    sub esp, 4
-
-    /* Begin the interrupt */
-    push esp
-    push 0x38
-    push PROFILE_LEVEL
-    call _halbeginsysteminterr...@12
-
-    /* Check if it's spurious */
-    or al, al
-    jz Spurious
-
-    /* FIXME: We should not be getting profile interrupts yet! */
-    int 3
-.endfunc

Modified: trunk/reactos/hal/halx86/generic/timer.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/hal/halx86/generic/timer.c?rev=45276&r1=45275&r2=45276&view=diff
==============================================================================
--- trunk/reactos/hal/halx86/generic/timer.c [iso-8859-1] (original)
+++ trunk/reactos/hal/halx86/generic/timer.c [iso-8859-1] Tue Jan 26 22:41:05 
2010
@@ -109,6 +109,61 @@
     HalpCurrentRollOver = RollOver;
 }
 
+VOID
+FASTCALL
+HalpClockInterruptHandler(IN PKTRAP_FRAME TrapFrame)
+{
+    KIRQL Irql;
+    
+    /* Enter trap */
+    KiEnterInterruptTrap(TrapFrame);
+    
+    /* Start the interrupt */
+    if (HalBeginSystemInterrupt(CLOCK2_LEVEL, PRIMARY_VECTOR_BASE, &Irql))
+    {
+        /* Update the performance counter */
+        HalpPerfCounter.QuadPart += HalpCurrentRollOver;
+        
+        /* Check if someone changed the time rate */
+        if (HalpClockSetMSRate)
+        {
+            /* Not yet supported */
+            UNIMPLEMENTED;
+            while (TRUE);
+        }
+        
+        /* Update the system time -- the kernel will exit this trap  */
+        KeUpdateSystemTime(TrapFrame, HalpCurrentTimeIncrement, Irql);
+    }
+    
+    /* Spurious, just end the interrupt */
+    KiEoiHelper(TrapFrame);
+}
+
+VOID
+FASTCALL
+HalpProfileInterruptHandler(IN PKTRAP_FRAME TrapFrame)
+{
+    KIRQL Irql;
+    
+    /* Enter trap */
+    KiEnterInterruptTrap(TrapFrame);
+    
+    /* Start the interrupt */
+    if (HalBeginSystemInterrupt(PROFILE_LEVEL, PRIMARY_VECTOR_BASE + 8, &Irql))
+    {
+        /* Profiling isn't yet enabled */
+        UNIMPLEMENTED;
+        while (TRUE);
+    }
+    
+    /* Spurious, just end the interrupt */
+    KiEoiHelper(TrapFrame);
+}
+
+KiTrap(HalpClockInterrupt,   KI_PUSH_FAKE_ERROR_CODE);
+KiTrap(HalpProfileInterrupt, KI_PUSH_FAKE_ERROR_CODE);
+
 /* PUBLIC FUNCTIONS 
***********************************************************/
 
 /*

Modified: trunk/reactos/hal/halx86/include/halp.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/hal/halx86/include/halp.h?rev=45276&r1=45275&r2=45276&view=diff
==============================================================================
--- trunk/reactos/hal/halx86/include/halp.h [iso-8859-1] (original)
+++ trunk/reactos/hal/halx86/include/halp.h [iso-8859-1] Tue Jan 26 22:41:05 
2010
@@ -532,8 +532,10 @@
 VOID HalpApcInterrupt(VOID);
 VOID HalpDispatchInterrupt(VOID);
 
-/* udelay.c */
+/* timer.c */
 VOID NTAPI HalpInitializeClock(VOID);
+VOID HalpClockInterrupt(VOID);
+VOID HalpProfileInterrupt(VOID);
 
 VOID
 NTAPI
@@ -548,8 +550,6 @@
 /* Non-generic initialization */
 VOID HalpInitPhase0 (PLOADER_PARAMETER_BLOCK LoaderBlock);
 VOID HalpInitPhase1(VOID);
-VOID NTAPI HalpClockInterrupt(VOID);
-VOID NTAPI HalpProfileInterrupt(VOID);
 
 VOID
 NTAPI
@@ -755,6 +755,14 @@
 
 #endif
 
+VOID
+FASTCALL
+KeUpdateSystemTime(
+    IN PKTRAP_FRAME TrapFrame,
+    IN ULONG Increment,
+    IN KIRQL OldIrql
+);
+
 #ifdef _M_AMD64
 #define KfLowerIrql KeLowerIrql
 #ifndef CONFIG_SMP
@@ -774,4 +782,6 @@
 
 extern PADDRESS_USAGE HalpAddressUsageList;
 
+extern LARGE_INTEGER HalpPerfCounter;
+
 #endif /* __INTERNAL_HAL_HAL_H */

Modified: trunk/reactos/include/ndk/kefuncs.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/include/ndk/kefuncs.h?rev=45276&r1=45275&r2=45276&view=diff
==============================================================================
--- trunk/reactos/include/ndk/kefuncs.h [iso-8859-1] (original)
+++ trunk/reactos/include/ndk/kefuncs.h [iso-8859-1] Tue Jan 26 22:41:05 2010
@@ -237,21 +237,6 @@
 
 VOID
 NTAPI
-KeUpdateSystemTime(
-    PKTRAP_FRAME TrapFrame,
-    KIRQL Irql,
-    ULONG Increment
-);
-
-VOID
-NTAPI
-KeUpdateRunTime(
-    PKTRAP_FRAME TrapFrame,
-    KIRQL Irql
-);
-
-VOID
-NTAPI
 KeSetDmaIoCoherency(
     IN ULONG Coherency
 );

Modified: trunk/reactos/ntoskrnl/include/internal/trap_x.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/trap_x.h?rev=45276&r1=45275&r2=45276&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/include/internal/trap_x.h [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/include/internal/trap_x.h [iso-8859-1] Tue Jan 26 
22:41:05 2010
@@ -629,8 +629,11 @@
     /* Check for V86 mode */
     if (__builtin_expect(TrapFrame->EFlags & EFLAGS_V86_MASK, 0))
     {
-        DbgPrint("Need V8086 Interrupt Support!\n");
-        while (TRUE);
+        /* Restore V8086 segments into Protected Mode segments */
+        TrapFrame->SegFs = TrapFrame->V86Fs;
+        TrapFrame->SegGs = TrapFrame->V86Gs;
+        TrapFrame->SegDs = TrapFrame->V86Ds;
+        TrapFrame->SegEs = TrapFrame->V86Es;
     }
     
     /* Check if this wasn't kernel code */

Modified: trunk/reactos/ntoskrnl/ke/i386/trap.s
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/i386/trap.s?rev=45276&r1=45275&r2=45276&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/ke/i386/trap.s [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/ke/i386/trap.s [iso-8859-1] Tue Jan 26 22:41:05 2010
@@ -205,41 +205,6 @@
 
 /* INTERRUPT HANDLERS ********************************************************/
 
-.globl _keupdatesystemt...@0
-.func keupdatesystemt...@0
-_keupdatesystemt...@0:
-
-    /*
-     * When we enter here, the ASM HAL has:
-     *   - Entered here with a JMP, not a CALL
-     *   - Put increment in EAX
-     *   - Pushed OldIRQL on the stack earlier [ESP]
-     *   - Pushed Vector on the stack earlier [ESP + 4]
-     *   - The trap frame at ESP + 8
-     *
-     * When the HAL moves to C, this shit needs to die!!!
-     *
-     */
-     
-     /* Call the regparm with Increment, OldIrql, TrapFrame */
-     mov edx, [esp]
-     mov ecx, ebp
-     call _KeUpdateSystemTimeHandler
-     
-     /*
-      * The code below cannot be done in C because HalEndSystemInterrupt will
-      * fuck with your stack sideways when it decides to handle a pending APC 
or
-      * DPC!
-      */
-
-     /* Stack is back where it was, HalEndSystemInterrupt will clean it up */
-     cli
-     call _halendsysteminterr...@8
-     
-     /* Now the stack has become the trap frame */
-     jmp _kei386eoihel...@0
-.endfunc
-
 .func kidispatchinterr...@0
 _kidispatchinterr...@0:
 

Modified: trunk/reactos/ntoskrnl/ke/time.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/time.c?rev=45276&r1=45275&r2=45276&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/ke/time.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/ke/time.c [iso-8859-1] Tue Jan 26 22:41:05 2010
@@ -19,19 +19,11 @@
 
 /* FUNCTIONS 
******************************************************************/
 
-#ifndef _M_ARM
 VOID
-__attribute__((regparm(3)))
-KeUpdateSystemTimeHandler(IN ULONG Increment,
-                          IN KIRQL Irql,
-                          IN PKTRAP_FRAME TrapFrame)
-#else
-VOID
-NTAPI
+FASTCALL
 KeUpdateSystemTime(IN PKTRAP_FRAME TrapFrame,
                    IN ULONG Increment,
-                   IN KIRQL Irql)
-#endif                   
+                   IN KIRQL Irql)                   
 {
     PKPRCB Prcb = KeGetCurrentPrcb();
     ULARGE_INTEGER CurrentTime, InterruptTime;
@@ -119,6 +111,13 @@
         /* Increase interrupt count and exit */
         Prcb->InterruptCount++;
     }
+    
+    /* Disable interrupts and end the interrupt */
+    _disable();
+    HalEndSystemInterrupt(Irql, CLOCK2_LEVEL);
+    
+    /* Exit the interrupt */
+    KiEoiHelper(TrapFrame);
 }
 
 VOID

Modified: trunk/reactos/ntoskrnl/ntoskrnl.pspec
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ntoskrnl.pspec?rev=45276&r1=45275&r2=45276&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/ntoskrnl.pspec [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/ntoskrnl.pspec [iso-8859-1] Tue Jan 26 22:41:05 2010
@@ -688,11 +688,7 @@
 @ fastcall KeTryToAcquireSpinLockAtDpcLevel(ptr)
 @ stdcall KeUnstackDetachProcess(ptr)
 @ stdcall KeUpdateRunTime(ptr long)
-#ifdef _M_IX86
-@ stdcall KeUpdateSystemTime()
-#else
-@ stdcall KeUpdateSystemTime(ptr long long)
-#endif
+@ fastcall KeUpdateSystemTime(ptr long long)
 @ stdcall KeUserModeCallback(long ptr long ptr ptr)
 @ stdcall KeWaitForMultipleObjects(long ptr long long long long ptr ptr)
 @ stdcall KeWaitForMutexObject(ptr long long long ptr) KeWaitForSingleObject


Reply via email to