mirror of
https://github.com/Fennix-Project/Kernel.git
synced 2025-05-28 15:34:33 +00:00
Refactor interrupt handling code
This commit is contained in:
parent
2d5bb5193d
commit
7d1041a3bd
@ -31,6 +31,9 @@
|
|||||||
extern "C" void MainInterruptHandler(void *Data);
|
extern "C" void MainInterruptHandler(void *Data);
|
||||||
extern "C" void ExceptionHandler(void *Data);
|
extern "C" void ExceptionHandler(void *Data);
|
||||||
|
|
||||||
|
#define __stub_handler \
|
||||||
|
__naked __used __no_stack_protector __aligned(16)
|
||||||
|
|
||||||
namespace InterruptDescriptorTable
|
namespace InterruptDescriptorTable
|
||||||
{
|
{
|
||||||
__aligned(8) static IDTGateDescriptor Entries[0x100];
|
__aligned(8) static IDTGateDescriptor Entries[0x100];
|
||||||
@ -40,13 +43,10 @@ namespace InterruptDescriptorTable
|
|||||||
.BaseAddress = Entries,
|
.BaseAddress = Entries,
|
||||||
};
|
};
|
||||||
|
|
||||||
void SetEntry(uint8_t Index,
|
void SetEntry(uint8_t Index, void (*Base)(),
|
||||||
void (*Base)(),
|
|
||||||
InterruptStackTableType InterruptStackTable,
|
InterruptStackTableType InterruptStackTable,
|
||||||
GateType Gate,
|
GateType Gate, PrivilegeLevelType Ring,
|
||||||
PrivilegeLevelType Ring,
|
bool Present, uint16_t SegmentSelector)
|
||||||
bool Present,
|
|
||||||
uint16_t SegmentSelector)
|
|
||||||
{
|
{
|
||||||
switch (Gate)
|
switch (Gate)
|
||||||
{
|
{
|
||||||
@ -110,13 +110,13 @@ namespace InterruptDescriptorTable
|
|||||||
case BUSY_64BIT_TSS:
|
case BUSY_64BIT_TSS:
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
assert(false);
|
assert(!"Unsupported gate type");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" __naked __used __no_stack_protector __aligned(16) void ExceptionHandlerStub()
|
extern "C" __stub_handler void ExceptionHandlerStub()
|
||||||
{
|
{
|
||||||
asm("cld\n"
|
asm("cld\n"
|
||||||
"cli\n"
|
"cli\n"
|
||||||
@ -199,7 +199,7 @@ namespace InterruptDescriptorTable
|
|||||||
"iretq"); // pop CS RIP RFLAGS SS RSP
|
"iretq"); // pop CS RIP RFLAGS SS RSP
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" __naked __used __no_stack_protector __aligned(16) void InterruptHandlerStub()
|
extern "C" __stub_handler void InterruptHandlerStub()
|
||||||
{
|
{
|
||||||
asm("cld\n"
|
asm("cld\n"
|
||||||
"cli\n"
|
"cli\n"
|
||||||
@ -247,27 +247,29 @@ namespace InterruptDescriptorTable
|
|||||||
"iretq"); // pop CS RIP RFLAGS SS RSP
|
"iretq"); // pop CS RIP RFLAGS SS RSP
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma region Exceptions
|
#pragma region Interrupt Macros
|
||||||
|
|
||||||
#define EXCEPTION_HANDLER(num) \
|
#define EXCEPTION_HANDLER(num) \
|
||||||
__naked __used __no_stack_protector __aligned(16) static void InterruptHandler_##num() \
|
__stub_handler static void InterruptHandler_##num() \
|
||||||
{ \
|
{ \
|
||||||
asm("pushq $0\npushq $" #num "\n" \
|
asm("pushq $0\n" \
|
||||||
"jmp ExceptionHandlerStub"); \
|
"pushq $" #num "\n" \
|
||||||
|
"jmp ExceptionHandlerStub"); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define EXCEPTION_ERROR_HANDLER(num) \
|
#define EXCEPTION_ERROR_HANDLER(num) \
|
||||||
__naked __used __no_stack_protector __aligned(16) static void InterruptHandler_##num() \
|
__stub_handler static void InterruptHandler_##num() \
|
||||||
{ \
|
{ \
|
||||||
asm("pushq $" #num "\n" \
|
asm("pushq $" #num "\n" \
|
||||||
"jmp ExceptionHandlerStub"); \
|
"jmp ExceptionHandlerStub"); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define INTERRUPT_HANDLER(num) \
|
#define INTERRUPT_HANDLER(num) \
|
||||||
__naked __used __no_stack_protector __aligned(16) void InterruptHandler_##num() \
|
__stub_handler void InterruptHandler_##num() \
|
||||||
{ \
|
{ \
|
||||||
asm("pushq $0\npushq $" #num "\n" \
|
asm("pushq $0\n" \
|
||||||
"jmp InterruptHandlerStub\n"); \
|
"pushq $" #num "\n" \
|
||||||
|
"jmp InterruptHandlerStub\n"); \
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ISR */
|
/* ISR */
|
||||||
@ -538,7 +540,7 @@ namespace InterruptDescriptorTable
|
|||||||
INTERRUPT_HANDLER(0xfe)
|
INTERRUPT_HANDLER(0xfe)
|
||||||
INTERRUPT_HANDLER(0xff)
|
INTERRUPT_HANDLER(0xff)
|
||||||
|
|
||||||
#pragma endregion Exceptions
|
#pragma endregion Interrupt Macros
|
||||||
|
|
||||||
void Init(int Core)
|
void Init(int Core)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user