From edbe33bcfa7e6c5d069a19253ab39f6a1f75f876 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Tue, 18 Oct 2022 20:48:46 -0400 Subject: [PATCH] Add ApicRegisters structure --- src/hulk/apic.d | 57 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 52 insertions(+), 5 deletions(-) diff --git a/src/hulk/apic.d b/src/hulk/apic.d index 213e89e..f7cfc95 100644 --- a/src/hulk/apic.d +++ b/src/hulk/apic.d @@ -9,14 +9,61 @@ import hulk.acpi; struct apic { - public enum uint * local_apic_registers = cast(uint *)0xFEE0_0000u; + static struct ApicRegister + { + private uint register; + private ubyte[12] _padding; + + public uint read() const + { + return register; + } + + public void write(uint value) + { + register = value; + } + }; + + static struct ApicRegisters + { + ApicRegister[2] _reserved0; + ApicRegister lapic_id; + ApicRegister lapic_version; + ApicRegister[4] _reserved1; + ApicRegister task_priority; + ApicRegister arbitration_priority; + ApicRegister processor_priority; + ApicRegister eoi; + ApicRegister remote_read; + ApicRegister logical_destination; + ApicRegister destination_format; + ApicRegister spurious_interrupt_vector; + ApicRegister[8] in_service; + ApicRegister[8] trigger_mode; + ApicRegister[8] interrupt_request; + ApicRegister error_status; + ApicRegister[6] _reserved2; + ApicRegister lvt_cmci; + ApicRegister[2] interrupt_command; + ApicRegister lvt_timer; + ApicRegister lvt_thermal_sensor; + ApicRegister lvt_performance_monitoring_counters; + ApicRegister[2] lvt_lint; + ApicRegister lvt_error; + ApicRegister initial_count; + ApicRegister current_count; + ApicRegister[4] _reserved3; + ApicRegister divide_configuration; + }; public static void initialize() { - Hurl.map(cast(ulong)local_apic_registers, - cast(ulong)local_apic_registers, + ApicRegisters * apic_registers = + cast(ApicRegisters *)acpi.apic_address; + Hurl.map(cast(ulong)apic_registers, cast(ulong)apic_registers, MAP_WRITABLE | MAP_WRITE_THROUGH | MAP_DISABLE_CACHE | MAP_NO_EXECUTE); - klog.writefln("LAPIC ID: 0x%08x", local_apic_registers[0x20/4]); - klog.writefln("LAPIC version: 0x%08x", local_apic_registers[0x30/4]); + klog.writefln("LAPIC ID: 0x%08x", apic_registers.lapic_id.read()); + klog.writefln("LAPIC version: 0x%08x", apic_registers.lapic_version.read()); } }