From f93158645b7b9b29765fad1f719dcf216296f583 Mon Sep 17 00:00:00 2001 From: Gabriel Date: Sat, 15 Feb 2025 22:22:04 +0100 Subject: [PATCH] core/x86_64: Enable the NX bit before using it Spent an embarrassing amount of time trying to figure out why there was a page fault with "reserved bits set". Turns out, I had set the NX bit without enabling it. --- core/src/arch/x86_64/platform.zig | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/core/src/arch/x86_64/platform.zig b/core/src/arch/x86_64/platform.zig index f46d171..c535282 100644 --- a/core/src/arch/x86_64/platform.zig +++ b/core/src/arch/x86_64/platform.zig @@ -5,10 +5,21 @@ const interrupts = @import("interrupts.zig"); pub const PAGE_SIZE = 4096; +// FIXME: Check if it's supported first. +fn enableNX() void { + asm volatile ( + \\ mov $0xC0000080, %rcx + \\ rdmsr + \\ or $0x800, %eax + \\ wrmsr + ); +} + // Initialize platform-specific components. pub fn platformInit() void { gdt.setupGDT(); idt.setupIDT(); + enableNX(); } // Initialize platform-specific components just before beginning multitasking.