Implement software interrupt dispatch table and secondary handler lookup
Some checks failed
Builds / ExectOS (amd64, debug) (push) Successful in 30s
Builds / ExectOS (i686, release) (push) Failing after 30s
Builds / ExectOS (i686, debug) (push) Failing after 39s
Builds / ExectOS (amd64, release) (push) Successful in 42s

This commit is contained in:
2026-04-08 20:13:35 +02:00
parent 4f65773aa9
commit 9ffb03217a
16 changed files with 358 additions and 17 deletions

View File

@@ -142,7 +142,7 @@ Dispatch\Type\Vector:
call ArDispatchTrap
.else
/* Pass to the interrupt dispatcher */
call ArDispatchTrap
call ArDispatchInterrupt
.endif
/* Restore the original trap frame stack pointer */

View File

@@ -29,3 +29,6 @@ KTSS AR::ProcSup::InitialTss;
/* Initial kernel NMI stack */
UCHAR AR::ProcSup::NmiStack[KERNEL_STACK_SIZE] = {};
/* Unhandled interrupt routine */
PINTERRUPT_HANDLER AR::Traps::UnhandledInterruptRoutine = NULLPTR;

View File

@@ -9,6 +9,44 @@
#include <xtos.hh>
/**
* Dispatches the interrupt provided by common interrupt handler.
*
* @param TrapFrame
* Supplies a kernel trap frame pushed by common interrupt handler on the stack.
*
* @return This routine does not return any value.
*
* @since XT 1.0
*/
XTCDECL
VOID
AR::Traps::DispatchInterrupt(IN PKTRAP_FRAME TrapFrame)
{
PINTERRUPT_HANDLER Handler;
/* Read the handler pointer from the CPU's interrupt dispatch table */
Handler = (PINTERRUPT_HANDLER)AR::CpuFunc::ReadGSQuadWord(FIELD_OFFSET(KPROCESSOR_BLOCK, InterruptDispatchTable) +
(TrapFrame->Vector * sizeof(PINTERRUPT_HANDLER)));
/* Check if the interrupt has a handler registered */
if(Handler != NULLPTR)
{
/* Call the handler */
Handler(TrapFrame);
}
else if(UnhandledInterruptRoutine != NULLPTR)
{
/* Call the unhandled interrupt routine */
UnhandledInterruptRoutine(TrapFrame);
}
else
{
/* Dispatcher not initialized, print a debug message */
DebugPrint(L"ERROR: Caught unhandled interrupt: 0x%.2llX\n", TrapFrame->Vector);
}
}
/**
* Dispatches the trap provided by common trap handler.
*
@@ -642,3 +680,21 @@ AR::Traps::InitializeSystemCallMsrs(VOID)
/* Enable system call extensions (SCE) in EFER MSR */
CpuFunc::WriteModelSpecificRegister(X86_MSR_EFER, CpuFunc::ReadModelSpecificRegister(X86_MSR_EFER) | X86_MSR_EFER_SCE);
}
/**
* Sets the unhandled interrupt routine used for vectors that have no handler registered.
*
* @param Handler
* Supplies the pointer to the interrupt handler routine.
*
* @return This routine does not return any value.
*
* @since XT 1.0
*/
XTAPI
VOID
AR::Traps::SetUnhandledInterruptRoutine(PINTERRUPT_HANDLER Handler)
{
/* Set the unhandled interrupt routine */
UnhandledInterruptRoutine = Handler;
}

View File

@@ -136,7 +136,7 @@ Dispatch\Type\Vector:
call _ArDispatchTrap
.else
/* Pass to the interrupt dispatcher */
call _ArDispatchTrap
call _ArDispatchInterrupt
.endif
/* Clean up the stack */

View File

@@ -35,3 +35,6 @@ UCHAR AR::ProcSup::NmiStack[KERNEL_STACK_SIZE] = {};
/* NMI task gate */
UCHAR AR::ProcSup::NonMaskableInterruptTss[KTSS_IO_MAPS];
/* Unhandled interrupt routine */
PINTERRUPT_HANDLER AR::Traps::UnhandledInterruptRoutine = NULLPTR;

View File

@@ -9,6 +9,44 @@
#include <xtos.hh>
/**
* Dispatches the interrupt provided by common interrupt handler.
*
* @param TrapFrame
* Supplies a kernel trap frame pushed by common interrupt handler on the stack.
*
* @return This routine does not return any value.
*
* @since XT 1.0
*/
XTCDECL
VOID
AR::Traps::DispatchInterrupt(IN PKTRAP_FRAME TrapFrame)
{
PINTERRUPT_HANDLER Handler;
/* Read the handler pointer from the CPU's interrupt dispatch table */
Handler = (PINTERRUPT_HANDLER)AR::CpuFunc::ReadFSDualWord(FIELD_OFFSET(KPROCESSOR_BLOCK, InterruptDispatchTable) +
(TrapFrame->Vector * sizeof(PINTERRUPT_HANDLER)));
/* Check if the interrupt has a handler registered */
if(Handler != NULLPTR)
{
/* Call the handler */
Handler(TrapFrame);
}
else if(UnhandledInterruptRoutine != NULLPTR)
{
/* Call the unhandled interrupt routine */
UnhandledInterruptRoutine(TrapFrame);
}
else
{
/* Dispatcher not initialized, print a debug message */
DebugPrint(L"ERROR: Caught unhandled interrupt: 0x%.2lX\n", TrapFrame->Vector);
}
}
/**
* Dispatches the trap provided by common trap handler.
*
@@ -589,3 +627,21 @@ AR::Traps::HandleTrapFF(IN PKTRAP_FRAME TrapFrame)
DebugPrint(L"Handled Unexpected-Interrupt (0xFF)!\n");
KE::Crash::Panic(0xFF);
}
/**
* Sets the unhandled interrupt routine used for vectors that have no handler registered.
*
* @param Handler
* Supplies the pointer to the interrupt handler routine.
*
* @return This routine does not return any value.
*
* @since XT 1.0
*/
XTCDECL
VOID
AR::Traps::SetUnhandledInterruptRoutine(PINTERRUPT_HANDLER Handler)
{
/* Set the unhandled interrupt routine */
UnhandledInterruptRoutine = Handler;
}