2008-03-11 02:45:13 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS Kernel
|
2008-06-29 02:58:05 +00:00
|
|
|
* LICENSE: BSD - See COPYING.ARM in the top level directory
|
2008-03-11 02:45:13 +00:00
|
|
|
* FILE: ntoskrnl/ke/arm/trapc.c
|
|
|
|
* PURPOSE: Implements the various trap handlers for ARM exceptions
|
|
|
|
* PROGRAMMERS: ReactOS Portable Systems Group
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES *******************************************************************/
|
|
|
|
|
|
|
|
#include <ntoskrnl.h>
|
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
/* FUNCTIONS ******************************************************************/
|
|
|
|
|
2010-11-24 15:21:45 +00:00
|
|
|
#if 0
|
2020-09-09 01:46:56 +00:00
|
|
|
DECLSPEC_NORETURN
|
2008-06-14 22:48:30 +00:00
|
|
|
VOID
|
|
|
|
KiIdleLoop(VOID)
|
|
|
|
{
|
|
|
|
PKPCR Pcr = (PKPCR)KeGetPcr();
|
|
|
|
PKPRCB Prcb = Pcr->Prcb;
|
|
|
|
PKTHREAD OldThread, NewThread;
|
2015-05-14 22:31:58 +00:00
|
|
|
|
2008-06-14 22:48:30 +00:00
|
|
|
//
|
|
|
|
// Loop forever... that's why this is an idle loop
|
|
|
|
//
|
2010-02-09 02:09:34 +00:00
|
|
|
DPRINT1("[IDLE LOOP]\n");
|
|
|
|
while (TRUE);
|
2015-05-14 22:31:58 +00:00
|
|
|
|
2008-06-14 22:48:30 +00:00
|
|
|
while (TRUE)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// Cycle interrupts
|
|
|
|
//
|
|
|
|
_disable();
|
|
|
|
_enable();
|
2015-05-14 22:31:58 +00:00
|
|
|
|
2008-06-14 22:48:30 +00:00
|
|
|
//
|
|
|
|
// Check if there's DPC work to do
|
|
|
|
//
|
|
|
|
if ((Prcb->DpcData[0].DpcQueueDepth) ||
|
|
|
|
(Prcb->TimerRequest) ||
|
|
|
|
(Prcb->DeferredReadyListHead.Next))
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// Clear the pending interrupt
|
|
|
|
//
|
|
|
|
HalClearSoftwareInterrupt(DISPATCH_LEVEL);
|
2015-05-14 22:31:58 +00:00
|
|
|
|
2008-06-14 22:48:30 +00:00
|
|
|
//
|
2008-06-26 06:38:42 +00:00
|
|
|
// Retire DPCs
|
2008-06-14 22:48:30 +00:00
|
|
|
//
|
2008-06-26 06:38:42 +00:00
|
|
|
KiRetireDpcList(Prcb);
|
2008-06-14 22:48:30 +00:00
|
|
|
}
|
2015-05-14 22:31:58 +00:00
|
|
|
|
2008-06-14 22:48:30 +00:00
|
|
|
//
|
|
|
|
// Check if there's a thread to schedule
|
|
|
|
//
|
|
|
|
if (Prcb->NextThread)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// Out with the old, in with the new...
|
|
|
|
//
|
|
|
|
OldThread = Prcb->CurrentThread;
|
2015-05-14 22:31:58 +00:00
|
|
|
NewThread = Prcb->NextThread;
|
2008-06-14 22:48:30 +00:00
|
|
|
Prcb->CurrentThread = NewThread;
|
|
|
|
Prcb->NextThread = NULL;
|
2015-05-14 22:31:58 +00:00
|
|
|
|
2008-06-14 22:48:30 +00:00
|
|
|
//
|
|
|
|
// Update thread state
|
|
|
|
//
|
|
|
|
NewThread->State = Running;
|
2015-05-14 22:31:58 +00:00
|
|
|
|
2008-06-14 22:48:30 +00:00
|
|
|
//
|
|
|
|
// Swap to the new thread
|
|
|
|
// On ARM we call KiSwapContext instead of KiSwapContextInternal,
|
|
|
|
// because we're calling this from C code and not assembly.
|
|
|
|
// This is similar to how it gets called for unwaiting, on x86
|
|
|
|
//
|
|
|
|
KiSwapContext(OldThread, NewThread);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//
|
2008-07-19 06:53:03 +00:00
|
|
|
// Go into WFI (sleep more)
|
2008-06-14 22:48:30 +00:00
|
|
|
//
|
2008-07-19 06:53:03 +00:00
|
|
|
KeArmWaitForInterrupt();
|
2008-06-14 22:48:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-11-24 15:21:45 +00:00
|
|
|
#endif
|
2008-06-14 22:48:30 +00:00
|
|
|
|
2008-07-31 07:06:19 +00:00
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
KiSwapProcess(IN PKPROCESS NewProcess,
|
|
|
|
IN PKPROCESS OldProcess)
|
|
|
|
{
|
|
|
|
ARM_TTB_REGISTER TtbRegister;
|
|
|
|
DPRINT1("Swapping from: %p (%16s) to %p (%16s)\n",
|
|
|
|
OldProcess, ((PEPROCESS)OldProcess)->ImageFileName,
|
|
|
|
NewProcess, ((PEPROCESS)NewProcess)->ImageFileName);
|
2015-05-14 22:31:58 +00:00
|
|
|
|
2008-07-31 07:06:19 +00:00
|
|
|
//
|
|
|
|
// Update the page directory base
|
|
|
|
//
|
2009-07-12 10:47:45 +00:00
|
|
|
TtbRegister.AsUlong = NewProcess->DirectoryTableBase[0];
|
2008-07-31 07:06:19 +00:00
|
|
|
ASSERT(TtbRegister.Reserved == 0);
|
|
|
|
KeArmTranslationTableRegisterSet(TtbRegister);
|
2015-05-14 22:31:58 +00:00
|
|
|
|
2008-07-31 07:06:19 +00:00
|
|
|
//
|
|
|
|
// FIXME: Flush the TLB
|
|
|
|
//
|
2015-05-14 22:31:58 +00:00
|
|
|
|
|
|
|
|
2008-07-31 07:06:19 +00:00
|
|
|
DPRINT1("Survived!\n");
|
|
|
|
while (TRUE);
|
|
|
|
}
|
|
|
|
|
2010-11-24 15:21:45 +00:00
|
|
|
#if 0
|
2008-06-12 04:32:45 +00:00
|
|
|
BOOLEAN
|
2008-06-11 19:13:25 +00:00
|
|
|
KiSwapContextInternal(IN PKTHREAD OldThread,
|
|
|
|
IN PKTHREAD NewThread)
|
|
|
|
{
|
2010-02-09 02:09:34 +00:00
|
|
|
PKIPCR Pcr = (PKIPCR)KeGetPcr();
|
2008-06-12 04:32:45 +00:00
|
|
|
PKPRCB Prcb = Pcr->Prcb;
|
|
|
|
PKPROCESS OldProcess, NewProcess;
|
2015-05-14 22:31:58 +00:00
|
|
|
|
2010-02-09 02:09:34 +00:00
|
|
|
DPRINT1("SWAP\n");
|
|
|
|
while (TRUE);
|
2015-05-14 22:31:58 +00:00
|
|
|
|
2008-06-12 00:40:53 +00:00
|
|
|
//
|
2008-06-12 04:32:45 +00:00
|
|
|
// Increase context switch count
|
2008-06-12 00:40:53 +00:00
|
|
|
//
|
2008-06-12 04:32:45 +00:00
|
|
|
Pcr->ContextSwitches++;
|
2015-05-14 22:31:58 +00:00
|
|
|
|
2008-06-12 04:32:45 +00:00
|
|
|
//
|
|
|
|
// Check if WMI tracing is enabled
|
|
|
|
//
|
|
|
|
if (Pcr->PerfGlobalGroupMask)
|
|
|
|
{
|
|
|
|
//
|
2008-07-19 06:13:10 +00:00
|
|
|
// We don't support this yet on x86 either
|
2008-06-12 04:32:45 +00:00
|
|
|
//
|
|
|
|
DPRINT1("WMI Tracing not supported\n");
|
2008-06-27 04:19:50 +00:00
|
|
|
ASSERT(FALSE);
|
2008-06-12 04:32:45 +00:00
|
|
|
}
|
2015-05-14 22:31:58 +00:00
|
|
|
|
2008-06-12 04:32:45 +00:00
|
|
|
//
|
|
|
|
// Check if the processes are also different
|
|
|
|
//
|
|
|
|
OldProcess = OldThread->ApcState.Process;
|
|
|
|
NewProcess = NewThread->ApcState.Process;
|
|
|
|
if (OldProcess != NewProcess)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// Check if address space switch is needed
|
|
|
|
//
|
2009-07-12 10:47:45 +00:00
|
|
|
if (OldProcess->DirectoryTableBase[0] !=
|
|
|
|
NewProcess->DirectoryTableBase[0])
|
2008-06-12 04:32:45 +00:00
|
|
|
{
|
|
|
|
//
|
2008-07-19 06:13:10 +00:00
|
|
|
// FIXME-USER: Support address space switch
|
2008-06-12 04:32:45 +00:00
|
|
|
//
|
|
|
|
DPRINT1("Address space switch not implemented\n");
|
2008-06-27 04:19:50 +00:00
|
|
|
ASSERT(FALSE);
|
2008-06-12 04:32:45 +00:00
|
|
|
}
|
|
|
|
}
|
2015-05-14 22:31:58 +00:00
|
|
|
|
2008-06-12 04:32:45 +00:00
|
|
|
//
|
|
|
|
// Increase thread context switches
|
|
|
|
//
|
|
|
|
NewThread->ContextSwitches++;
|
2010-02-09 02:09:34 +00:00
|
|
|
#if 0 // I don't buy this
|
2008-06-12 04:32:45 +00:00
|
|
|
//
|
|
|
|
// Set us as the current thread
|
|
|
|
// NOTE: On RISC Platforms, there is both a KPCR CurrentThread, and a
|
|
|
|
// KPRCB CurrentThread.
|
|
|
|
// The latter is set just like on x86-based builds, the former is only set
|
|
|
|
// when actually doing the context switch (here).
|
|
|
|
// Recall that the reason for the latter is due to the fact that the KPCR
|
|
|
|
// is shared with user-mode (read-only), so that information is exposed
|
|
|
|
// there as well.
|
|
|
|
//
|
|
|
|
Pcr->CurrentThread = NewThread;
|
2010-02-09 02:09:34 +00:00
|
|
|
#endif
|
2008-06-12 04:32:45 +00:00
|
|
|
//
|
|
|
|
// DPCs shouldn't be active
|
|
|
|
//
|
|
|
|
if (Prcb->DpcRoutineActive)
|
|
|
|
{
|
|
|
|
//
|
2008-07-19 06:53:03 +00:00
|
|
|
// Crash the machine
|
2008-06-12 04:32:45 +00:00
|
|
|
//
|
2008-07-19 06:53:03 +00:00
|
|
|
KeBugCheckEx(ATTEMPTED_SWITCH_FROM_DPC,
|
|
|
|
(ULONG_PTR)OldThread,
|
|
|
|
(ULONG_PTR)NewThread,
|
|
|
|
(ULONG_PTR)OldThread->InitialStack,
|
|
|
|
0);
|
2008-06-12 04:32:45 +00:00
|
|
|
}
|
2015-05-14 22:31:58 +00:00
|
|
|
|
2008-06-12 04:32:45 +00:00
|
|
|
//
|
|
|
|
// Kernel APCs may be pending
|
|
|
|
//
|
|
|
|
if (NewThread->ApcState.KernelApcPending)
|
|
|
|
{
|
|
|
|
//
|
2008-07-19 06:53:03 +00:00
|
|
|
// Are APCs enabled?
|
2008-06-12 04:32:45 +00:00
|
|
|
//
|
2008-07-19 06:53:03 +00:00
|
|
|
if (NewThread->SpecialApcDisable == 0)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// Request APC delivery
|
|
|
|
//
|
|
|
|
HalRequestSoftwareInterrupt(APC_LEVEL);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2008-06-12 04:32:45 +00:00
|
|
|
}
|
2015-05-14 22:31:58 +00:00
|
|
|
|
2008-06-12 04:32:45 +00:00
|
|
|
//
|
|
|
|
// Return
|
|
|
|
//
|
|
|
|
return FALSE;
|
2008-06-11 19:13:25 +00:00
|
|
|
}
|
2010-11-24 15:21:45 +00:00
|
|
|
#endif
|
2008-06-11 19:13:25 +00:00
|
|
|
|
2008-06-27 04:19:50 +00:00
|
|
|
VOID
|
|
|
|
KiApcInterrupt(VOID)
|
|
|
|
{
|
|
|
|
KPROCESSOR_MODE PreviousMode;
|
|
|
|
KEXCEPTION_FRAME ExceptionFrame;
|
|
|
|
PKTRAP_FRAME TrapFrame = KeGetCurrentThread()->TrapFrame;
|
2015-05-14 22:31:58 +00:00
|
|
|
|
2010-02-09 02:09:34 +00:00
|
|
|
DPRINT1("[APC TRAP]\n");
|
|
|
|
while (TRUE);
|
2015-05-14 22:31:58 +00:00
|
|
|
|
2008-06-27 04:19:50 +00:00
|
|
|
//
|
|
|
|
// Isolate previous mode
|
|
|
|
//
|
|
|
|
PreviousMode = KiGetPreviousMode(TrapFrame);
|
2015-05-14 22:31:58 +00:00
|
|
|
|
2008-06-27 04:19:50 +00:00
|
|
|
//
|
2008-07-19 06:13:10 +00:00
|
|
|
// FIXME-USER: Handle APC interrupt while in user-mode
|
2008-06-27 04:19:50 +00:00
|
|
|
//
|
|
|
|
if (PreviousMode == UserMode) ASSERT(FALSE);
|
2015-05-14 22:31:58 +00:00
|
|
|
|
2008-06-27 04:19:50 +00:00
|
|
|
//
|
|
|
|
// Disable interrupts
|
|
|
|
//
|
|
|
|
_disable();
|
|
|
|
|
|
|
|
//
|
|
|
|
// Clear APC interrupt
|
|
|
|
//
|
|
|
|
HalClearSoftwareInterrupt(APC_LEVEL);
|
2015-05-14 22:31:58 +00:00
|
|
|
|
2008-06-27 04:19:50 +00:00
|
|
|
//
|
|
|
|
// Re-enable interrupts
|
|
|
|
//
|
|
|
|
_enable();
|
2015-05-14 22:31:58 +00:00
|
|
|
|
2008-06-27 04:19:50 +00:00
|
|
|
//
|
|
|
|
// Deliver APCs
|
|
|
|
//
|
|
|
|
KiDeliverApc(PreviousMode, &ExceptionFrame, TrapFrame);
|
|
|
|
}
|
|
|
|
|
2010-11-24 15:21:45 +00:00
|
|
|
#if 0
|
2008-06-11 16:48:07 +00:00
|
|
|
VOID
|
|
|
|
KiDispatchInterrupt(VOID)
|
|
|
|
{
|
2010-02-09 02:09:34 +00:00
|
|
|
PKIPCR Pcr;
|
2008-06-14 22:48:30 +00:00
|
|
|
PKPRCB Prcb;
|
2008-06-11 16:48:07 +00:00
|
|
|
PKTHREAD NewThread, OldThread;
|
2015-05-14 22:31:58 +00:00
|
|
|
|
2010-02-09 02:09:34 +00:00
|
|
|
DPRINT1("[DPC TRAP]\n");
|
|
|
|
while (TRUE);
|
2015-05-14 22:31:58 +00:00
|
|
|
|
2008-06-11 16:48:07 +00:00
|
|
|
//
|
|
|
|
// Get the PCR and disable interrupts
|
|
|
|
//
|
2010-02-09 02:09:34 +00:00
|
|
|
Pcr = (PKIPCR)KeGetPcr();
|
2008-06-14 22:48:30 +00:00
|
|
|
Prcb = Pcr->Prcb;
|
2008-06-11 16:48:07 +00:00
|
|
|
_disable();
|
2015-05-14 22:31:58 +00:00
|
|
|
|
2008-06-11 16:48:07 +00:00
|
|
|
//
|
|
|
|
//Check if we have to deliver DPCs, timers, or deferred threads
|
|
|
|
//
|
2008-06-14 22:48:30 +00:00
|
|
|
if ((Prcb->DpcData[0].DpcQueueDepth) ||
|
|
|
|
(Prcb->TimerRequest) ||
|
|
|
|
(Prcb->DeferredReadyListHead.Next))
|
2008-06-11 16:48:07 +00:00
|
|
|
{
|
|
|
|
//
|
2008-06-26 06:38:42 +00:00
|
|
|
// Retire DPCs
|
2008-06-11 16:48:07 +00:00
|
|
|
//
|
2008-06-26 06:38:42 +00:00
|
|
|
KiRetireDpcList(Prcb);
|
2008-06-11 16:48:07 +00:00
|
|
|
}
|
2015-05-14 22:31:58 +00:00
|
|
|
|
2008-06-11 16:48:07 +00:00
|
|
|
//
|
|
|
|
// Re-enable interrupts
|
|
|
|
//
|
|
|
|
_enable();
|
2015-05-14 22:31:58 +00:00
|
|
|
|
2008-06-11 16:48:07 +00:00
|
|
|
//
|
|
|
|
// Check for quantum end
|
|
|
|
//
|
2008-06-14 22:48:30 +00:00
|
|
|
if (Prcb->QuantumEnd)
|
2008-06-11 16:48:07 +00:00
|
|
|
{
|
|
|
|
//
|
2008-06-26 06:38:42 +00:00
|
|
|
// Handle quantum end
|
2008-06-11 16:48:07 +00:00
|
|
|
//
|
2008-06-26 06:38:42 +00:00
|
|
|
Prcb->QuantumEnd = FALSE;
|
|
|
|
KiQuantumEnd();
|
2008-06-11 16:48:07 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-05-14 22:31:58 +00:00
|
|
|
|
2008-06-11 16:48:07 +00:00
|
|
|
//
|
|
|
|
// Check if we have a thread to swap to
|
|
|
|
//
|
2008-06-14 22:48:30 +00:00
|
|
|
if (Prcb->NextThread)
|
2015-05-14 22:31:58 +00:00
|
|
|
{
|
2008-06-11 16:48:07 +00:00
|
|
|
//
|
|
|
|
// Next is now current
|
|
|
|
//
|
2008-06-14 22:48:30 +00:00
|
|
|
OldThread = Prcb->CurrentThread;
|
|
|
|
NewThread = Prcb->NextThread;
|
|
|
|
Prcb->CurrentThread = NewThread;
|
|
|
|
Prcb->NextThread = NULL;
|
2015-05-14 22:31:58 +00:00
|
|
|
|
2008-06-11 16:48:07 +00:00
|
|
|
//
|
|
|
|
// Update thread states
|
|
|
|
//
|
|
|
|
NewThread->State = Running;
|
|
|
|
OldThread->WaitReason = WrDispatchInt;
|
2015-05-14 22:31:58 +00:00
|
|
|
|
2008-06-11 16:48:07 +00:00
|
|
|
//
|
|
|
|
// Make the old thread ready
|
|
|
|
//
|
2008-06-14 22:48:30 +00:00
|
|
|
KxQueueReadyThread(OldThread, Prcb);
|
2015-05-14 22:31:58 +00:00
|
|
|
|
2008-06-11 16:48:07 +00:00
|
|
|
//
|
|
|
|
// Swap to the new thread
|
2008-06-11 19:13:25 +00:00
|
|
|
// On ARM we call KiSwapContext instead of KiSwapContextInternal,
|
|
|
|
// because we're calling this from C code and not assembly.
|
|
|
|
// This is similar to how it gets called for unwaiting, on x86
|
2008-06-11 16:48:07 +00:00
|
|
|
//
|
2008-06-11 19:13:25 +00:00
|
|
|
KiSwapContext(OldThread, NewThread);
|
2008-06-11 16:48:07 +00:00
|
|
|
}
|
|
|
|
}
|
2010-11-24 15:21:45 +00:00
|
|
|
#endif
|
2008-06-11 16:48:07 +00:00
|
|
|
|
|
|
|
VOID
|
|
|
|
KiInterruptHandler(IN PKTRAP_FRAME TrapFrame,
|
|
|
|
IN ULONG Reserved)
|
|
|
|
{
|
|
|
|
KIRQL OldIrql, Irql;
|
2015-05-14 22:31:58 +00:00
|
|
|
ULONG InterruptCause;//, InterruptMask;
|
2010-02-09 02:09:34 +00:00
|
|
|
PKIPCR Pcr;
|
2008-06-26 05:56:35 +00:00
|
|
|
PKTRAP_FRAME OldTrapFrame;
|
2015-05-14 22:31:58 +00:00
|
|
|
ASSERT(TrapFrame->Reserved == 0xBADB0D00);
|
2008-06-14 22:02:50 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Increment interrupt count
|
|
|
|
//
|
2010-02-09 02:09:34 +00:00
|
|
|
Pcr = (PKIPCR)KeGetPcr();
|
2015-05-14 22:31:58 +00:00
|
|
|
Pcr->Prcb.InterruptCount++;
|
|
|
|
|
2008-06-11 16:48:07 +00:00
|
|
|
//
|
|
|
|
// Get the old IRQL
|
|
|
|
//
|
2008-06-11 18:39:44 +00:00
|
|
|
OldIrql = KeGetCurrentIrql();
|
2015-05-14 22:31:58 +00:00
|
|
|
TrapFrame->PreviousIrql = OldIrql;
|
|
|
|
|
2008-06-11 16:48:07 +00:00
|
|
|
//
|
|
|
|
// Get the interrupt source
|
|
|
|
//
|
|
|
|
InterruptCause = HalGetInterruptSource();
|
2010-02-09 02:09:34 +00:00
|
|
|
//DPRINT1("[INT] (%x) @ %p %p\n", InterruptCause, TrapFrame->SvcLr, TrapFrame->Pc);
|
2008-06-11 16:48:07 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Get the new IRQL and Interrupt Mask
|
|
|
|
//
|
2015-05-14 22:31:58 +00:00
|
|
|
/// FIXME: use a global table in ntoskrnl instead of HAL?
|
|
|
|
//Irql = Pcr->IrqlMask[InterruptCause];
|
|
|
|
//InterruptMask = Pcr->IrqlTable[Irql];
|
|
|
|
Irql = 0;
|
|
|
|
__debugbreak();
|
|
|
|
|
2008-06-11 16:48:07 +00:00
|
|
|
//
|
2008-06-14 22:02:50 +00:00
|
|
|
// Raise to the new IRQL
|
2008-06-11 16:48:07 +00:00
|
|
|
//
|
2008-06-14 22:02:50 +00:00
|
|
|
KfRaiseIrql(Irql);
|
2015-05-14 22:31:58 +00:00
|
|
|
|
2008-06-26 05:56:35 +00:00
|
|
|
//
|
|
|
|
// The clock ISR wants the trap frame as a parameter
|
|
|
|
//
|
|
|
|
OldTrapFrame = KeGetCurrentThread()->TrapFrame;
|
|
|
|
KeGetCurrentThread()->TrapFrame = TrapFrame;
|
2008-06-14 22:02:50 +00:00
|
|
|
|
2008-06-11 16:48:07 +00:00
|
|
|
//
|
|
|
|
// Check if this interrupt is at DISPATCH or higher
|
|
|
|
//
|
|
|
|
if (Irql > DISPATCH_LEVEL)
|
2015-05-14 22:31:58 +00:00
|
|
|
{
|
2008-06-14 22:02:50 +00:00
|
|
|
//
|
2008-07-19 06:13:10 +00:00
|
|
|
// FIXME-TODO: Switch to interrupt stack
|
2008-06-14 22:02:50 +00:00
|
|
|
//
|
2008-06-14 23:19:03 +00:00
|
|
|
//DPRINT1("[ISR]\n");
|
2008-06-14 22:02:50 +00:00
|
|
|
}
|
|
|
|
else
|
2008-06-11 16:48:07 +00:00
|
|
|
{
|
|
|
|
//
|
2008-06-14 22:02:50 +00:00
|
|
|
// We know this is APC or DPC.
|
2008-06-11 16:48:07 +00:00
|
|
|
//
|
2008-06-14 23:19:03 +00:00
|
|
|
//DPRINT1("[DPC/APC]\n");
|
2008-06-14 22:02:50 +00:00
|
|
|
HalClearSoftwareInterrupt(Irql);
|
2008-06-11 16:48:07 +00:00
|
|
|
}
|
2008-06-26 05:56:35 +00:00
|
|
|
|
2008-06-11 16:48:07 +00:00
|
|
|
//
|
2008-06-14 22:02:50 +00:00
|
|
|
// Call the registered interrupt routine
|
2008-06-11 16:48:07 +00:00
|
|
|
//
|
2015-05-14 22:31:58 +00:00
|
|
|
/// FIXME: this should probably go into a table in ntoskrnl
|
|
|
|
//Pcr->InterruptRoutine[Irql]();
|
|
|
|
__debugbreak();
|
2008-06-26 05:56:35 +00:00
|
|
|
ASSERT(KeGetCurrentThread()->TrapFrame == TrapFrame);
|
|
|
|
KeGetCurrentThread()->TrapFrame = OldTrapFrame;
|
2008-06-14 23:19:03 +00:00
|
|
|
// DPRINT1("[ISR RETURN]\n");
|
2015-05-14 22:31:58 +00:00
|
|
|
|
2008-06-11 16:48:07 +00:00
|
|
|
//
|
- Rewrite the low-level trap/exception/system call code from the ground up:
- Do not corrupt the stack anymore
- Use a consistent trap frame layout (enable OldIrql and PreviousMode, and set the 0xBADB0D00 debug mark)
- Use slower but more correct trap prolog/epilog code for now.
- Generalize all prolog/epilog code into macros just like on x86. As a result, traps are now 6 lines of code.
- Rewrite the system call interface from the ground up:
- System calls didn't actually work: a debug print made the stack layout magical enough so that they didn't normally crush, but only slowly ate the stack.
- Copying arguments from caller to system call was, as the comment on the original code so aptly put it, "total shit".
- Due to ABI concerns, and to provide an actual template on how you're -supposed- to implement something like system calls on RISC processors, we now use
a model similar to BSD, but about ten times better (with that much less code too). We'll document it later on the RosPSG Wiki.
- This code probably contains some of the most vile-yet-elegant macro magic ever written for such low-level code as system call dispatching.
- The result of all this is that we're at the same place as before (RamdiskAddDevice needs to be implemented by the Ramdisk guys) but with a sane low-level
backend that isn't slowly eating away the stack, corrupting data, and basically working through random chance.
- Move timebase code from stubs.c to its own file, time.c.
- Silence multiple debug prints and fix a corrupted debug print in KiSystemStartup.
svn path=/trunk/; revision=34366
2008-07-08 09:11:44 +00:00
|
|
|
// Restore IRQL and interrupts
|
2008-06-11 16:48:07 +00:00
|
|
|
//
|
2008-06-14 22:02:50 +00:00
|
|
|
KeLowerIrql(OldIrql);
|
|
|
|
_enable();
|
2008-06-11 16:48:07 +00:00
|
|
|
}
|
|
|
|
|
2008-07-13 22:40:36 +00:00
|
|
|
NTSTATUS
|
|
|
|
KiPrefetchAbortHandler(IN PKTRAP_FRAME TrapFrame)
|
|
|
|
{
|
2008-07-13 23:34:44 +00:00
|
|
|
PVOID Address = (PVOID)KeArmFaultAddressRegisterGet();
|
2015-05-14 22:31:58 +00:00
|
|
|
ASSERT(TrapFrame->Reserved == 0xBADB0D00);
|
2008-07-13 23:34:44 +00:00
|
|
|
ULONG Instruction = *(PULONG)TrapFrame->Pc;
|
|
|
|
ULONG DebugType, Parameter0;
|
|
|
|
EXCEPTION_RECORD ExceptionRecord;
|
2015-05-14 22:31:58 +00:00
|
|
|
|
2010-02-09 02:09:34 +00:00
|
|
|
DPRINT1("[PREFETCH ABORT] (%x) @ %p/%p/%p\n",
|
2015-05-14 22:31:58 +00:00
|
|
|
KeArmInstructionFaultStatusRegisterGet(), Address, TrapFrame->Lr, TrapFrame->Pc);
|
2010-02-09 02:09:34 +00:00
|
|
|
while (TRUE);
|
2015-05-14 22:31:58 +00:00
|
|
|
|
2008-07-13 23:34:44 +00:00
|
|
|
//
|
|
|
|
// What we *SHOULD* do is look at the instruction fault status register
|
|
|
|
// and see if it's equal to 2 (debug trap). Unfortunately QEMU doesn't seem
|
|
|
|
// to emulate this behaviour properly, so we use a workaround.
|
|
|
|
//
|
|
|
|
//if (KeArmInstructionFaultStatusRegisterGet() == 2)
|
|
|
|
if (Instruction & 0xE1200070) // BKPT
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// Okay, we know this is a breakpoint, extract the index
|
|
|
|
//
|
|
|
|
DebugType = Instruction & 0xF;
|
|
|
|
if (DebugType == BREAKPOINT_PRINT)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// Debug Service
|
|
|
|
//
|
|
|
|
Parameter0 = TrapFrame->R0;
|
2008-07-14 00:26:18 +00:00
|
|
|
TrapFrame->Pc += sizeof(ULONG);
|
2008-07-13 23:34:44 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// Standard INT3 (emulate x86 behavior)
|
|
|
|
//
|
|
|
|
Parameter0 = STATUS_SUCCESS;
|
|
|
|
}
|
2015-05-14 22:31:58 +00:00
|
|
|
|
2008-07-13 23:34:44 +00:00
|
|
|
//
|
|
|
|
// Build the exception record
|
|
|
|
//
|
|
|
|
ExceptionRecord.ExceptionCode = STATUS_BREAKPOINT;
|
|
|
|
ExceptionRecord.ExceptionFlags = 0;
|
|
|
|
ExceptionRecord.ExceptionRecord = NULL;
|
|
|
|
ExceptionRecord.ExceptionAddress = (PVOID)TrapFrame->Pc;
|
|
|
|
ExceptionRecord.NumberParameters = 3;
|
2015-05-14 22:31:58 +00:00
|
|
|
|
2008-07-13 23:34:44 +00:00
|
|
|
//
|
|
|
|
// Build the parameters
|
|
|
|
//
|
|
|
|
ExceptionRecord.ExceptionInformation[0] = Parameter0;
|
|
|
|
ExceptionRecord.ExceptionInformation[1] = TrapFrame->R1;
|
|
|
|
ExceptionRecord.ExceptionInformation[2] = TrapFrame->R2;
|
2015-05-14 22:31:58 +00:00
|
|
|
|
2008-07-13 23:34:44 +00:00
|
|
|
//
|
|
|
|
// Dispatch the exception
|
|
|
|
//
|
|
|
|
KiDispatchException(&ExceptionRecord,
|
|
|
|
NULL,
|
|
|
|
TrapFrame,
|
|
|
|
KiGetPreviousMode(TrapFrame),
|
|
|
|
TRUE);
|
2008-07-14 00:26:18 +00:00
|
|
|
|
2008-07-13 23:34:44 +00:00
|
|
|
//
|
2008-07-14 00:26:18 +00:00
|
|
|
// We're done
|
2008-07-13 23:34:44 +00:00
|
|
|
//
|
2008-07-14 00:26:18 +00:00
|
|
|
return STATUS_SUCCESS;
|
2008-07-13 23:34:44 +00:00
|
|
|
}
|
2015-05-14 22:31:58 +00:00
|
|
|
|
2008-07-13 23:34:44 +00:00
|
|
|
//
|
|
|
|
// Unhandled
|
|
|
|
//
|
|
|
|
UNIMPLEMENTED;
|
|
|
|
ASSERT(FALSE);
|
2008-07-13 22:40:36 +00:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2008-03-11 02:45:13 +00:00
|
|
|
NTSTATUS
|
|
|
|
KiDataAbortHandler(IN PKTRAP_FRAME TrapFrame)
|
|
|
|
{
|
2008-03-11 16:13:43 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
PVOID Address = (PVOID)KeArmFaultAddressRegisterGet();
|
2015-05-14 22:31:58 +00:00
|
|
|
ASSERT(TrapFrame->Reserved == 0xBADB0D00);
|
|
|
|
|
2010-02-09 02:09:34 +00:00
|
|
|
DPRINT1("[ABORT] (%x) @ %p/%p/%p\n",
|
2015-05-14 22:31:58 +00:00
|
|
|
KeArmFaultStatusRegisterGet(), Address, TrapFrame->Lr, TrapFrame->Pc);
|
2010-02-09 02:09:34 +00:00
|
|
|
while (TRUE);
|
2015-05-14 22:31:58 +00:00
|
|
|
|
2008-03-11 16:13:43 +00:00
|
|
|
//
|
|
|
|
// Check if this is a page fault
|
|
|
|
//
|
2008-06-27 04:19:50 +00:00
|
|
|
if (KeArmFaultStatusRegisterGet() == 21 || KeArmFaultStatusRegisterGet() == 23)
|
2008-03-11 16:13:43 +00:00
|
|
|
{
|
2018-01-01 14:25:45 +00:00
|
|
|
Status = MmAccessFault(KeArmFaultStatusRegisterGet(),
|
2008-06-27 04:19:50 +00:00
|
|
|
Address,
|
2008-07-13 23:34:44 +00:00
|
|
|
KiGetPreviousMode(TrapFrame),
|
2008-06-27 04:19:50 +00:00
|
|
|
TrapFrame);
|
2010-11-24 18:53:47 +00:00
|
|
|
if (NT_SUCCESS(Status)) return Status;
|
2008-03-11 16:13:43 +00:00
|
|
|
}
|
2008-07-13 01:58:23 +00:00
|
|
|
|
2008-07-13 23:34:44 +00:00
|
|
|
//
|
|
|
|
// Unhandled
|
|
|
|
//
|
2008-06-14 22:02:50 +00:00
|
|
|
UNIMPLEMENTED;
|
2008-06-27 04:19:50 +00:00
|
|
|
ASSERT(FALSE);
|
2008-03-11 02:45:13 +00:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2008-03-12 22:06:42 +00:00
|
|
|
VOID
|
2008-03-12 18:17:55 +00:00
|
|
|
KiSoftwareInterruptHandler(IN PKTRAP_FRAME TrapFrame)
|
|
|
|
{
|
|
|
|
PKTHREAD Thread;
|
|
|
|
KPROCESSOR_MODE PreviousMode;
|
|
|
|
ULONG Instruction;
|
2015-05-14 22:31:58 +00:00
|
|
|
ASSERT(TrapFrame->Reserved == 0xBADB0D00);
|
|
|
|
|
|
|
|
DPRINT1("[SWI] @ %p/%p\n", TrapFrame->Lr, TrapFrame->Pc);
|
2010-02-09 02:09:34 +00:00
|
|
|
while (TRUE);
|
2015-05-14 22:31:58 +00:00
|
|
|
|
2008-03-12 18:17:55 +00:00
|
|
|
//
|
|
|
|
// Get the current thread
|
|
|
|
//
|
|
|
|
Thread = KeGetCurrentThread();
|
2015-05-14 22:31:58 +00:00
|
|
|
|
2008-03-12 18:17:55 +00:00
|
|
|
//
|
|
|
|
// Isolate previous mode
|
|
|
|
//
|
|
|
|
PreviousMode = KiGetPreviousMode(TrapFrame);
|
2015-05-14 22:31:58 +00:00
|
|
|
|
2008-03-12 22:06:42 +00:00
|
|
|
//
|
- Rewrite the low-level trap/exception/system call code from the ground up:
- Do not corrupt the stack anymore
- Use a consistent trap frame layout (enable OldIrql and PreviousMode, and set the 0xBADB0D00 debug mark)
- Use slower but more correct trap prolog/epilog code for now.
- Generalize all prolog/epilog code into macros just like on x86. As a result, traps are now 6 lines of code.
- Rewrite the system call interface from the ground up:
- System calls didn't actually work: a debug print made the stack layout magical enough so that they didn't normally crush, but only slowly ate the stack.
- Copying arguments from caller to system call was, as the comment on the original code so aptly put it, "total shit".
- Due to ABI concerns, and to provide an actual template on how you're -supposed- to implement something like system calls on RISC processors, we now use
a model similar to BSD, but about ten times better (with that much less code too). We'll document it later on the RosPSG Wiki.
- This code probably contains some of the most vile-yet-elegant macro magic ever written for such low-level code as system call dispatching.
- The result of all this is that we're at the same place as before (RamdiskAddDevice needs to be implemented by the Ramdisk guys) but with a sane low-level
backend that isn't slowly eating away the stack, corrupting data, and basically working through random chance.
- Move timebase code from stubs.c to its own file, time.c.
- Silence multiple debug prints and fix a corrupted debug print in KiSystemStartup.
svn path=/trunk/; revision=34366
2008-07-08 09:11:44 +00:00
|
|
|
// Save old previous mode
|
2008-03-12 22:06:42 +00:00
|
|
|
//
|
- Rewrite the low-level trap/exception/system call code from the ground up:
- Do not corrupt the stack anymore
- Use a consistent trap frame layout (enable OldIrql and PreviousMode, and set the 0xBADB0D00 debug mark)
- Use slower but more correct trap prolog/epilog code for now.
- Generalize all prolog/epilog code into macros just like on x86. As a result, traps are now 6 lines of code.
- Rewrite the system call interface from the ground up:
- System calls didn't actually work: a debug print made the stack layout magical enough so that they didn't normally crush, but only slowly ate the stack.
- Copying arguments from caller to system call was, as the comment on the original code so aptly put it, "total shit".
- Due to ABI concerns, and to provide an actual template on how you're -supposed- to implement something like system calls on RISC processors, we now use
a model similar to BSD, but about ten times better (with that much less code too). We'll document it later on the RosPSG Wiki.
- This code probably contains some of the most vile-yet-elegant macro magic ever written for such low-level code as system call dispatching.
- The result of all this is that we're at the same place as before (RamdiskAddDevice needs to be implemented by the Ramdisk guys) but with a sane low-level
backend that isn't slowly eating away the stack, corrupting data, and basically working through random chance.
- Move timebase code from stubs.c to its own file, time.c.
- Silence multiple debug prints and fix a corrupted debug print in KiSystemStartup.
svn path=/trunk/; revision=34366
2008-07-08 09:11:44 +00:00
|
|
|
TrapFrame->PreviousMode = PreviousMode;
|
2015-05-14 22:31:58 +00:00
|
|
|
TrapFrame->TrapFrame = (ULONG_PTR)Thread->TrapFrame;
|
|
|
|
|
2008-03-12 18:17:55 +00:00
|
|
|
//
|
|
|
|
// Save previous mode and trap frame
|
|
|
|
//
|
|
|
|
Thread->TrapFrame = TrapFrame;
|
|
|
|
Thread->PreviousMode = PreviousMode;
|
2015-05-14 22:31:58 +00:00
|
|
|
|
2008-03-12 18:17:55 +00:00
|
|
|
//
|
|
|
|
// Read the opcode
|
|
|
|
//
|
|
|
|
Instruction = *(PULONG)(TrapFrame->Pc - sizeof(ULONG));
|
2008-07-19 06:53:03 +00:00
|
|
|
|
2008-03-12 22:06:42 +00:00
|
|
|
//
|
2008-07-19 06:53:03 +00:00
|
|
|
// Call the service call dispatcher
|
2008-03-12 22:06:42 +00:00
|
|
|
//
|
2008-07-19 06:53:03 +00:00
|
|
|
KiSystemService(Thread, TrapFrame, Instruction);
|
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
KiUndefinedExceptionHandler(IN PKTRAP_FRAME TrapFrame)
|
|
|
|
{
|
2015-05-14 22:31:58 +00:00
|
|
|
ASSERT(TrapFrame->Reserved == 0xBADB0D00);
|
|
|
|
|
2008-03-12 18:17:55 +00:00
|
|
|
//
|
2008-07-19 06:53:03 +00:00
|
|
|
// This should never happen
|
2008-03-12 18:17:55 +00:00
|
|
|
//
|
2015-05-14 22:31:58 +00:00
|
|
|
DPRINT1("[UNDEF] @ %p/%p\n", TrapFrame->Lr, TrapFrame->Pc);
|
2008-07-19 06:53:03 +00:00
|
|
|
UNIMPLEMENTED;
|
|
|
|
ASSERT(FALSE);
|
|
|
|
return STATUS_SUCCESS;
|
2008-03-12 18:17:55 +00:00
|
|
|
}
|