- Okay so we've got a basic KiDispatchException, we now need KiTrapFrameToContext...
authorReactOS Portable Systems Group <ros-arm-bringup@svn.reactos.org>
Sun, 13 Jul 2008 23:46:50 +0000 (23:46 +0000)
committerReactOS Portable Systems Group <ros-arm-bringup@svn.reactos.org>
Sun, 13 Jul 2008 23:46:50 +0000 (23:46 +0000)
- We aren't really sure where the hell we are since we can't printf anything otherwise we'll trap again and end up in an infinite loop.
- So we're debugging with while (TRUE).

svn path=/trunk/; revision=34481

reactos/ntoskrnl/ke/arm/exp.c
reactos/ntoskrnl/ke/arm/stubs_asm.s

index 5fdd93e..7e57f39 100644 (file)
@@ -25,6 +25,149 @@ KeContextToTrapFrame(IN PCONTEXT Context,
                      IN ULONG ContextFlags,
                      IN KPROCESSOR_MODE PreviousMode)
 {
-    UNIMPLEMENTED;
+    while (TRUE);
     return;
 }
+
+VOID
+NTAPI
+KeTrapFrameToContext(IN PKTRAP_FRAME TrapFrame,
+                     IN PKEXCEPTION_FRAME ExceptionFrame,
+                     IN OUT PCONTEXT Context)
+{
+    while (TRUE);
+    return; 
+}
+
+VOID
+NTAPI
+KiDispatchException(IN PEXCEPTION_RECORD ExceptionRecord,
+                    IN PKEXCEPTION_FRAME ExceptionFrame,
+                    IN PKTRAP_FRAME TrapFrame,
+                    IN KPROCESSOR_MODE PreviousMode,
+                    IN BOOLEAN FirstChance)
+{
+    CONTEXT Context;
+    
+    //
+    // Increase number of Exception Dispatches
+    //
+    KeGetCurrentPrcb()->KeExceptionDispatchCount++;
+    
+    //
+    // Set the context flags
+    //
+    Context.ContextFlags = CONTEXT_FULL;
+    
+    //
+    // FIXME: Fuck floating point
+    //
+    
+    //
+    // Get a Context
+    //
+    KeTrapFrameToContext(TrapFrame, ExceptionFrame, &Context);
+    
+    //
+    // Look at our exception code
+    //
+    switch (ExceptionRecord->ExceptionCode)
+    {
+        //
+        // Breakpoint
+        //
+        case STATUS_BREAKPOINT:
+            
+            //
+            // Decrement PC by one
+            //
+            Context.Pc--;
+            break;
+            
+        //
+        // Internal exception
+        //
+        case KI_EXCEPTION_ACCESS_VIOLATION:
+            
+            //
+            // Set correct code
+            //
+            ExceptionRecord->ExceptionCode = STATUS_ACCESS_VIOLATION;
+            break;
+    }
+       
+    //
+    // Handle kernel-mode first, it's simpler
+    //
+    if (PreviousMode == KernelMode)
+    {
+        //
+        // Check if this is a first-chance exception
+        //
+        if (FirstChance == TRUE)
+        {
+            //
+            // Break into the debugger for the first time
+            //
+            if (KiDebugRoutine(TrapFrame,
+                               ExceptionFrame,
+                               ExceptionRecord,
+                               &Context,
+                               PreviousMode,
+                               FALSE))
+            {
+                //
+                // Exception was handled
+                //
+                goto Handled;
+            }
+            
+            //
+            // If the Debugger couldn't handle it, dispatch the exception
+            //
+            if (RtlDispatchException(ExceptionRecord, &Context)) goto Handled;
+        }
+        
+        //
+        // This is a second-chance exception, only for the debugger
+        //
+        if (KiDebugRoutine(TrapFrame,
+                           ExceptionFrame,
+                           ExceptionRecord,
+                           &Context,
+                           PreviousMode,
+                           TRUE))
+        {
+            //
+            // Exception was handled
+            //
+            goto Handled;
+        }
+        
+        //
+        // Third strike; you're out
+        //
+        KeBugCheckEx(KMODE_EXCEPTION_NOT_HANDLED,
+                     ExceptionRecord->ExceptionCode,
+                     (ULONG_PTR)ExceptionRecord->ExceptionAddress,
+                     (ULONG_PTR)TrapFrame,
+                     0);
+    }
+    else
+    {
+        //
+        // FIXME: User mode
+        //
+        ASSERT(FALSE);
+    }
+    
+Handled:
+    //
+    // Convert the context back into Trap/Exception Frames
+    //
+    KeContextToTrapFrame(&Context,
+                         ExceptionFrame,
+                         TrapFrame,
+                         Context.ContextFlags,
+                         PreviousMode);
+}
index 59e5a27..a7907e4 100644 (file)
@@ -39,7 +39,6 @@ GENERATE_ARM_STUB RtlInitializeContext
 //
 GENERATE_ARM_STUB KiInitializeUserApc
 GENERATE_ARM_STUB KeDisableInterrupts
-GENERATE_ARM_STUB KiDispatchException
 GENERATE_ARM_STUB KiSwapProcess
 GENERATE_ARM_STUB KeSwitchKernelStack