diff --git a/drivers/acpi.cpp b/drivers/acpi.cpp index aaaedae..9bbcc3e 100644 --- a/drivers/acpi.cpp +++ b/drivers/acpi.cpp @@ -150,15 +150,21 @@ void ACPIParseTables() { bool isXSDT = false; if (acpi.rsdp) { + uint64_t sdt_address; + if (acpi.rsdp->revision == 2 && acpi.rsdp->xsdtAddress) { isXSDT = true; - sdt = (ACPIDescriptorTable *) acpi.rsdp->xsdtAddress; + sdt_address = acpi.rsdp->xsdtAddress; } else { isXSDT = false; - sdt = (ACPIDescriptorTable *) (uintptr_t) acpi.rsdp->rsdtAddress; + sdt_address = acpi.rsdp->rsdtAddress; } - sdt = (ACPIDescriptorTable *) MMMapPhysical(kernelMMSpace, (uintptr_t) sdt, 16384, ES_FLAGS_DEFAULT); + + ACPIDescriptorTable *tmp_sdt = (ACPIDescriptorTable *) MMMapPhysical(kernelMMSpace, sdt_address, sizeof(ACPIDescriptorTable), ES_FLAGS_DEFAULT); + uint32_t len_sdt = tmp_sdt->length < 16384 ? tmp_sdt->length : 16384; + MMFree(kernelMMSpace, tmp_sdt); + sdt = (ACPIDescriptorTable *) MMMapPhysical(kernelMMSpace, sdt_address, len_sdt, ES_FLAGS_DEFAULT); } else { KernelPanic("ACPIInitialise - Could not find supported root system descriptor pointer.\nACPI support is required.\n"); } diff --git a/kernel/memory.cpp b/kernel/memory.cpp index 9f842b2..0473650 100644 --- a/kernel/memory.cpp +++ b/kernel/memory.cpp @@ -1325,7 +1325,8 @@ void *MMMapPhysical(MMSpace *space, uintptr_t offset, size_t bytes, uint64_t cac uintptr_t offset2 = offset & (K_PAGE_SIZE - 1); offset -= offset2; - if (offset2) bytes += K_PAGE_SIZE; + bytes += offset2; + bytes = (bytes + K_PAGE_SIZE - 1) & ~(K_PAGE_SIZE - 1); MMRegion *region;