#include "acpi.h" #include "../types.h" #include "../lnxboot.h" #include "../util.h" #include "../efi/memmap.h" #include "../efi/guid.h" #include "../efi/efi.h" bool AcpiIsPresent = false; struct AcpiRSDP* AcpiTheRSDP = 0; void AcpiInitialize() { // Check boot params if (BootBootParams->acpi_rsdp_addr) { AcpiTheRSDP = BootBootParams->acpi_rsdp_addr; goto found; } // Check firmware if (EfiPresent()) { const struct EfiSystemTable* SystemTable = EfiGetSystemTable(); const struct EfiConfigurationTable* ConfigurationTable = EfiTranslatePointer(SystemTable->ConfigurationTable); for (int i = 0; i < SystemTable->NumberOfTableEntries; i++) { // this used to break because the cckernel decided to give me one last fuck you // and corrupt random portions of code, i really really hate DEFLATE. if (CompareMemory(&ConfigurationTable[i].VendorGuid, &EFI_ACPI_20_TABLE_GUID, sizeof(EfiGuid))) { AcpiTheRSDP = ConfigurationTable[i].VendorTable; goto found; } } } goto fail; found: // Is this a valid ACPI table? if (!CompareMemory(AcpiTheRSDP->Signature, "RSD PTR ", 8)) goto fail; // Check the sum u8 Sum = 0; for (int i = 0; i < sizeof(struct AcpiRSDP); i++) Sum += ((u8*)AcpiTheRSDP)[i]; if (Sum != 0) goto fail; AcpiIsPresent = true; return; fail: AcpiIsPresent = false; return; } bool AcpiPresent() { return AcpiIsPresent; } struct AcpiRSDP* AcpiGetRSDP() { return AcpiTheRSDP; }