From 673e2fd5fd9f56a8beb78b47864910319a69a5a6 Mon Sep 17 00:00:00 2001 From: ReactOS Portable Systems Group Date: Sun, 13 Jul 2008 23:46:50 +0000 Subject: [PATCH] - Okay so we've got a basic KiDispatchException, we now need KiTrapFrameToContext and KiContextToTrapFrame. - 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 | 145 +++++++++++++++++++++++++++- reactos/ntoskrnl/ke/arm/stubs_asm.s | 1 - 2 files changed, 144 insertions(+), 2 deletions(-) diff --git a/reactos/ntoskrnl/ke/arm/exp.c b/reactos/ntoskrnl/ke/arm/exp.c index 5fdd93e5752..7e57f397d99 100644 --- a/reactos/ntoskrnl/ke/arm/exp.c +++ b/reactos/ntoskrnl/ke/arm/exp.c @@ -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); +} diff --git a/reactos/ntoskrnl/ke/arm/stubs_asm.s b/reactos/ntoskrnl/ke/arm/stubs_asm.s index 59e5a27a72c..a7907e4b126 100644 --- a/reactos/ntoskrnl/ke/arm/stubs_asm.s +++ b/reactos/ntoskrnl/ke/arm/stubs_asm.s @@ -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