feat(loader, kernel): impl part of loader and initialize kernel structure

This commit is contained in:
2026-04-11 09:42:09 +08:00
parent 1233ae9e9b
commit 34ccf69569
53 changed files with 1743 additions and 777 deletions

23
arch/x86_64/boot/idt.zig Normal file
View File

@@ -0,0 +1,23 @@
const desc = @import("arch").desc;
const mem = @import("arch").mem;
const TrapType = @import("arch").trap.TrapType;
extern const __KERNEL_CS: u8;
var idt_table: [256]desc.IdtEntry align(mem.PAGE_SIZE) = .{.{}} ** 256;
extern const boot_page_fault: u8;
extern const boot_nmi: u8;
fn setIdtEntry(vec: usize, handler: anytype) void {
var entry = desc.IdtEntry{};
entry.setOffset(@intFromPtr(handler));
entry.selector = @intFromPtr(&__KERNEL_CS);
entry.gate_type = .trap;
entry.present = 1;
idt_table[vec] = entry;
}
export fn loadLoaderIdt() void {
setIdtEntry(TrapType.PF, &boot_page_fault);
setIdtEntry(TrapType.NMI, &boot_nmi);
desc.loadIdt(&idt_table);
}