From 9b52ae58e84c213f879c9fd1c7702f9bd51c498f Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Wed, 7 Dec 2022 23:13:51 -0500 Subject: [PATCH] Get local APIC timer ready to run --- src/hulk/apic.d | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/hulk/apic.d b/src/hulk/apic.d index 1fb61df..3050f77 100644 --- a/src/hulk/apic.d +++ b/src/hulk/apic.d @@ -9,6 +9,8 @@ import hulk.acpi; struct apic { + private enum uint PERIODIC_MODE = 0x2_0000u; + static struct ApicRegister { public uint value; @@ -49,10 +51,11 @@ struct apic ApicRegister divide_configuration; } + private static __gshared ApicRegisters * apic_registers; + public static void initialize() { - ApicRegisters * apic_registers = - cast(ApicRegisters *)acpi.apic_address; + apic_registers = cast(ApicRegisters *)acpi.apic_address; hurl.map(cast(ulong)apic_registers, cast(ulong)apic_registers, PT_WRITABLE | PT_WRITE_THROUGH | PT_DISABLE_CACHE | PT_NO_EXECUTE); klog.writefln("LAPIC ID: 0x%08x", apic_registers.lapic_id.value); @@ -60,8 +63,19 @@ struct apic /* Enable local APIC to receive interrupts and set spurious interrupt * vector to 0xFF. */ apic_registers.spurious_interrupt_vector.value = 0x1FFu; - apic_registers.lvt_timer.value = 0x70u; + apic_registers.lvt_timer.value = 0x70u | PERIODIC_MODE; apic_registers.lvt_lint[0].value = 0x71u; apic_registers.lvt_lint[1].value = 0x72u; + apic_registers.divide_configuration.value = 3u; + } + + private static void eoi() + { + apic_registers.eoi.value = 0u; + } + + public static void isr() + { + eoi(); } }