Compare commits

...

3 Commits

4 changed files with 29 additions and 4 deletions

View File

@ -3,7 +3,6 @@
*/
module hulk.acpi;
import hulk.klog;
import hulk.hurl;
import hulk.klog;
import hos.memory;
@ -54,7 +53,7 @@ struct acpi
ubyte length;
}
private static ulong apic_address;
public static __gshared ulong apic_address;
public static void initialize(ulong acpi_xsdt_phys)
{
@ -86,6 +85,7 @@ struct acpi
const(MadtHeader) * madt_header = cast(const(MadtHeader) *)address;
Hurl.map_range(address, madt_header.length, 0u);
apic_address = madt_header.local_apic_address;
klog.writefln("Found 32-bit APIC address: 0x%x", apic_address);
const(void) * madt_end = cast(const(void) *)(address + madt_header.length);
const(MadtEntry) * madt_entry = cast(const(MadtEntry) *)(address + 0x2Cu);
while (madt_entry < madt_end)
@ -95,6 +95,7 @@ struct acpi
{
/* Found a 64-bit Local APIC Address Override entry. */
memcpy(cast(void *)&apic_address, cast(const(void) *)madt_entry + 4u, 8u);
klog.writefln("Found 64-bit APIC address: 0x%x", apic_address);
}
}
}

22
src/hulk/apic.d Normal file
View File

@ -0,0 +1,22 @@
/**
* APIC (Advanced Programmable Interrupt Controller) functionality.
*/
module hulk.apic;
import hulk.klog;
import hulk.hurl;
import hulk.acpi;
struct apic
{
public enum uint * local_apic_registers = cast(uint *)0xFEE0_0000u;
public static void initialize()
{
Hurl.map(cast(ulong)local_apic_registers,
cast(ulong)local_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]);
}
}

View File

@ -19,6 +19,7 @@ import hos.cpu;
import ldc.llvmasm;
import hulk.pic;
import hulk.acpi;
import hulk.apic;
extern extern(C) __gshared ubyte _hulk_total_size;
@ -52,6 +53,7 @@ void hulk_start()
pci.initialize();
pic.initialize();
acpi.initialize(hulk_header.bootinfo.acpi_xsdt_phys);
apic.initialize();
sti();
for (;;)

View File

@ -83,7 +83,7 @@ struct Hurl
return opIndexAssign(pte, cast(ulong)address, level);
}
private ulong pt_index(ulong address, ulong level)
public ulong pt_index(ulong address, ulong level)
{
return (address >> (39u - (9u * level))) & 0x1FFu;
}
@ -140,7 +140,7 @@ struct Hurl
for (size_t level = 0; level < 4u; level++)
{
PageTableEntry entry = (*pt)[address, level];
klog.writefln("Level %u, entry = 0x%x", level, entry);
klog.writefln("Level %u, index %u, entry = 0x%x", level, pt.pt_index(cast(ulong)address, level), entry);
if (entry.present)
{
pt = entry.follow();