Add ApicRegisters structure

This commit is contained in:
Josh Holtrop 2022-10-18 20:48:46 -04:00
parent 747e824dae
commit edbe33bcfa

View File

@ -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());
}
}