ptos/amd64+hal: Add interrupt handling + P1 KPCR init
Signed-off-by: Chloe M. <chloe@mensia.org>
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2026, Chloe M.
|
||||
* Provided under the BSD-3 clause.
|
||||
*
|
||||
* Description: Kernel processor control region
|
||||
* Author: Chloe M.
|
||||
*/
|
||||
|
||||
#include <hal/kpcr.h>
|
||||
#include <machine/idt.h>
|
||||
#include <machine/trap.h>
|
||||
|
||||
/*
|
||||
* Initialize interrupts for the current processor
|
||||
*/
|
||||
static VOID
|
||||
InitInterrupts(VOID)
|
||||
{
|
||||
MdIdtSetGate(0x00, (UPTR)TrapDivError, IDT_TRAP_GATE, 0);
|
||||
MdIdtSetGate(0x01, (UPTR)TrapDebugException, IDT_TRAP_GATE, 0);
|
||||
MdIdtSetGate(0x02, (UPTR)TrapNmi, IDT_TRAP_GATE, 0);
|
||||
MdIdtSetGate(0x03, (UPTR)TrapBreakPoint, IDT_TRAP_GATE, 0);
|
||||
MdIdtSetGate(0x04, (UPTR)TrapOverflow, IDT_TRAP_GATE, 0);
|
||||
MdIdtSetGate(0x05, (UPTR)TrapBoundRange, IDT_TRAP_GATE, 0);
|
||||
MdIdtSetGate(0x06, (UPTR)TrapInvalidOpcode, IDT_TRAP_GATE, 0);
|
||||
MdIdtSetGate(0x07, (UPTR)TrapNoCoprocessor, IDT_TRAP_GATE, 0);
|
||||
MdIdtSetGate(0x08, (UPTR)TrapDoubleFault, IDT_TRAP_GATE, 0);
|
||||
MdIdtSetGate(0x09, (UPTR)TrapReserved, IDT_TRAP_GATE, 0);
|
||||
MdIdtSetGate(0x0A, (UPTR)TrapInvalidTss, IDT_TRAP_GATE, 0);
|
||||
MdIdtSetGate(0x0B, (UPTR)TrapSegNotPresent, IDT_TRAP_GATE, 0);
|
||||
MdIdtSetGate(0x0C, (UPTR)TrapStackSegmentFault, IDT_TRAP_GATE, 0);
|
||||
MdIdtSetGate(0x0D, (UPTR)TrapGeneralProtection, IDT_TRAP_GATE, 0);
|
||||
MdIdtSetGate(0x0E, (UPTR)TrapPageFault, IDT_TRAP_GATE, 0);
|
||||
MdIdtLoad();
|
||||
}
|
||||
|
||||
VOID
|
||||
HalKpcrP1Init(KPCR *Kpcr)
|
||||
{
|
||||
InitInterrupts();
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (c) 2026, Chloe M.
|
||||
* Provided under the BSD-3 clause.
|
||||
*
|
||||
* Description: Trap dispatch
|
||||
* Author: Chloe M.
|
||||
*/
|
||||
|
||||
#include <machine/trap.h>
|
||||
#include <ke/bugcheck.h>
|
||||
#include <ptdef.h>
|
||||
|
||||
#define TRAP_STR(TYPE) \
|
||||
((TYPE) >= NELEM(TrapTab)) \
|
||||
? "bad trap type" \
|
||||
: TrapTab[(TYPE)]
|
||||
|
||||
static const CHAR *TrapTab[] = {
|
||||
[TRAP_DIVERR] = "divide error",
|
||||
[TRAP_DEBUG_EXCEPTION] = "debug exception",
|
||||
[TRAP_NMI] = "non-maskable interrupt",
|
||||
[TRAP_BREAKPOINT] = "breakpoint",
|
||||
[TRAP_OVERFLOW] = "overflow",
|
||||
[TRAP_BOUND_RANGE] = "bound range exceeded",
|
||||
[TRAP_INVALID_OPCODE] = "invalid opcode",
|
||||
[TRAP_NO_COPROCESSOR] = "no math coprocessor",
|
||||
[TRAP_DOUBLE_FAULT] = "double fault",
|
||||
[TRAP_RESERVED] = "reserved exception",
|
||||
[TRAP_INVALID_TSS] = "invalid tss",
|
||||
[TRAP_SEG_NOT_PRESENT] = "segment not present",
|
||||
[TRAP_STACK_SEG_FAULT] = "stack segment fault",
|
||||
[TRAP_GENERAL_PROTECTION] = "general protection fault",
|
||||
[TRAP_PAGE_FAULT] = "page fault"
|
||||
};
|
||||
|
||||
VOID
|
||||
MdTrapDispatch(TRAP_FRAME *TrapFrame)
|
||||
{
|
||||
/* Sanity check */
|
||||
if (TrapFrame == NULL) {
|
||||
KeBugCheck(
|
||||
BUGCHECK_UNBOUND_RESRC,
|
||||
"unbound trapframe during dispatch\n"
|
||||
);
|
||||
}
|
||||
|
||||
KeBugCheck(
|
||||
BUGCHECK_EXCEPTION,
|
||||
"got fatal %s\n", TRAP_STR(TrapFrame->Vector)
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
/*
|
||||
* Copyright (c) 2026, Chloe M.
|
||||
* Provided under the BSD-3 clause.
|
||||
*
|
||||
* Description: AMD64 interrupt vectors
|
||||
* Author: Chloe M.
|
||||
*/
|
||||
|
||||
#include <machine/frameasm.h>
|
||||
|
||||
.text
|
||||
.globl TrapDivError
|
||||
TrapDivError:
|
||||
INTR_ENTRY($0x00)
|
||||
mov %rsp, %rdi
|
||||
call MdTrapDispatch
|
||||
1: cli
|
||||
hlt
|
||||
jmp 1b
|
||||
|
||||
.globl TrapDebugException
|
||||
TrapDebugException:
|
||||
INTR_ENTRY($0x01)
|
||||
mov %rsp, %rdi
|
||||
call MdTrapDispatch
|
||||
1: cli
|
||||
hlt
|
||||
jmp 1b
|
||||
|
||||
.globl TrapNmi
|
||||
TrapNmi:
|
||||
INTR_ENTRY($0x02)
|
||||
mov %rsp, %rdi
|
||||
call MdTrapDispatch
|
||||
1: cli
|
||||
hlt
|
||||
jmp 1b
|
||||
|
||||
.globl TrapBreakPoint
|
||||
TrapBreakPoint:
|
||||
INTR_ENTRY($0x03)
|
||||
mov %rsp, %rdi
|
||||
call MdTrapDispatch
|
||||
1: cli
|
||||
hlt
|
||||
jmp 1b
|
||||
|
||||
.globl TrapOverflow
|
||||
TrapOverflow:
|
||||
INTR_ENTRY($0x04)
|
||||
mov %rsp, %rdi
|
||||
call MdTrapDispatch
|
||||
1: cli
|
||||
hlt
|
||||
jmp 1b
|
||||
|
||||
.globl TrapBoundRange
|
||||
TrapBoundRange:
|
||||
INTR_ENTRY($0x05)
|
||||
mov %rsp, %rdi
|
||||
call MdTrapDispatch
|
||||
1: cli
|
||||
hlt
|
||||
jmp 1b
|
||||
|
||||
.globl TrapInvalidOpcode
|
||||
TrapInvalidOpcode:
|
||||
INTR_ENTRY($0x06)
|
||||
mov %rsp, %rdi
|
||||
call MdTrapDispatch
|
||||
1: cli
|
||||
hlt
|
||||
jmp 1b
|
||||
|
||||
.globl TrapNoCoprocessor
|
||||
TrapNoCoprocessor:
|
||||
INTR_ENTRY($0x07)
|
||||
mov %rsp, %rdi
|
||||
call MdTrapDispatch
|
||||
1: cli
|
||||
hlt
|
||||
jmp 1b
|
||||
|
||||
.globl TrapDoubleFault
|
||||
TrapDoubleFault:
|
||||
INTR_ENTRY_EC($0x08)
|
||||
mov %rsp, %rdi
|
||||
call MdTrapDispatch
|
||||
1: cli
|
||||
hlt
|
||||
jmp 1b
|
||||
|
||||
.globl TrapReserved
|
||||
TrapReserved:
|
||||
INTR_ENTRY($0x09)
|
||||
mov %rsp, %rdi
|
||||
call MdTrapDispatch
|
||||
1: cli
|
||||
hlt
|
||||
jmp 1b
|
||||
|
||||
.globl TrapInvalidTss
|
||||
TrapInvalidTss:
|
||||
INTR_ENTRY_EC($0x0A)
|
||||
mov %rsp, %rdi
|
||||
call MdTrapDispatch
|
||||
1: cli
|
||||
hlt
|
||||
jmp 1b
|
||||
|
||||
.globl TrapSegNotPresent
|
||||
TrapSegNotPresent:
|
||||
INTR_ENTRY_EC($0x0B)
|
||||
mov %rsp, %rdi
|
||||
call MdTrapDispatch
|
||||
1: cli
|
||||
hlt
|
||||
jmp 1b
|
||||
|
||||
.globl TrapStackSegmentFault
|
||||
TrapStackSegmentFault:
|
||||
INTR_ENTRY_EC($0x0C)
|
||||
mov %rsp, %rdi
|
||||
call MdTrapDispatch
|
||||
1: cli
|
||||
hlt
|
||||
jmp 1b
|
||||
|
||||
.globl TrapGeneralProtection
|
||||
TrapGeneralProtection:
|
||||
INTR_ENTRY_EC($0x0D)
|
||||
mov %rsp, %rdi
|
||||
call MdTrapDispatch
|
||||
1: cli
|
||||
hlt
|
||||
jmp 1b
|
||||
|
||||
.globl TrapPageFault
|
||||
TrapPageFault:
|
||||
INTR_ENTRY_EC($0x0E)
|
||||
mov %rsp, %rdi
|
||||
call MdTrapDispatch
|
||||
1: cli
|
||||
hlt
|
||||
jmp 1b
|
||||
Reference in New Issue
Block a user