From 29708067059985b545d96632fc8d85471b82308b Mon Sep 17 00:00:00 2001 From: Nigel Date: Mon, 11 Sep 2023 23:23:38 +0200 Subject: [PATCH] ACPI reading memory when mapped to higher half --- kernel/acpi/acpi.cpp | 37 +++++++++++++++++++++++++++++++------ kernel/acpi/rsdp.cpp | 15 +++++++++++++-- kernel/acpi/rsdp.h | 5 ++--- 3 files changed, 46 insertions(+), 11 deletions(-) diff --git a/kernel/acpi/acpi.cpp b/kernel/acpi/acpi.cpp index bc83d08..66d4c7a 100644 --- a/kernel/acpi/acpi.cpp +++ b/kernel/acpi/acpi.cpp @@ -1,20 +1,22 @@ #include "acpi.h" +#include "../../CoreLib/Memory.h" +#include "../memory/VirtualMemoryManager.h" + RSDPDescriptor* ACPI::rsd_ptr; RSCPDescriptor20* ACPI::rsd2_ptr; RSDT* ACPI::rsd_table; - +const int KERNEL_OFFSET = 0xC0000000; void ACPI::initialize(){ - // Find the Root System Description Pointer ACPI::rsd_ptr = FindRSD(); printf("RSD address: 0x%x\n", ACPI::rsd_ptr); - //printRSD(rsd_ptr); + printRSD(rsd_ptr); if( rsd_ptr->Revision == 0 ){ - // Using veriosn 1.0 of the ACPI specifiction + // Using version 1.0 of the ACPI specification int sum = rsd_ptr->Checksum; for (int i =0; i < sizeof(RSDPDescriptor) ; i++) { sum += ((char*)rsd_ptr)[i]; @@ -26,11 +28,34 @@ void ACPI::initialize(){ else printf("invalid rsd\n"); + printf("rsdp: 0x%x\n", rsd_ptr); + + printf("0x%x address\n", (rsd_ptr->RsdtAddress)); + Immediate_Map(rsd_ptr->RsdtAddress + KERNEL_OFFSET, rsd_ptr->RsdtAddress); + + RSDT* rootSystemDescriptionTable = (RSDT*)(rsd_ptr->RsdtAddress + KERNEL_OFFSET); + //printf("0x%x Root System Descriptor address\n", rootSystemDescriptionTable); + // checksum it, but we'll ignore it for now + printf("signature "); + for (int i = 0; i < 4; i++) { + kterm_put( rootSystemDescriptionTable->h.Signature[i]); + } + kterm_put('\n'); + + + int entries = (rootSystemDescriptionTable->h.Length - sizeof (rootSystemDescriptionTable->h)) /4; + printf("%d num entries\n", entries); + for( int i = 0; i < entries; i++){ + ACPISDTHeader* h = (ACPISDTHeader*) rootSystemDescriptionTable->PointerToSDT + i ; + if(strncmp(h->Signature, "FACP", 4)){ + printf("Found FACP Entry!\n"); + } + } + - // Get the Root System Description Table NOTE: might need memory mapping - //RSDT* rootSystemDescriptionTable = (RSDT*) (rsd_ptr->RsdtAddress + 0xC0000000); } else{ // parse it as of version2.0 + printf("rsd2_ptr\n"); ACPI::rsd2_ptr = (RSCPDescriptor20*)rsd_ptr; } diff --git a/kernel/acpi/rsdp.cpp b/kernel/acpi/rsdp.cpp index 3ed66e9..8882f7f 100644 --- a/kernel/acpi/rsdp.cpp +++ b/kernel/acpi/rsdp.cpp @@ -23,11 +23,22 @@ RSDPDescriptor* FindRSD(){ char* memory_byte = (char*) 0x000f2e14; const void* string = "RSD PTR "; - for( ; (uint32_t) memory_byte < 0x00100000; memory_byte+=10){ + + for( ; (uint32_t) memory_byte < 0x0100000; memory_byte+=10){ if( memcmp(memory_byte , string , 8 ) == 0 ) { printf("RSD PTR found at 0x%x !\n", memory_byte); + return (RSDPDescriptor*) memory_byte; break; } } - return (RSDPDescriptor*) memory_byte; + + memory_byte = (char*) 0x000E0000; + for ( ;(uint32_t) memory_byte < 0x000FFFFF; memory_byte += 1) + { + if( memcmp(memory_byte , string , 8 ) == 0 ) { + printf("RSD PTR found at 0x%x !\n", memory_byte); + return (RSDPDescriptor*) memory_byte; + break; + } + } } diff --git a/kernel/acpi/rsdp.h b/kernel/acpi/rsdp.h index aef9445..77014fc 100644 --- a/kernel/acpi/rsdp.h +++ b/kernel/acpi/rsdp.h @@ -16,10 +16,9 @@ struct ACPISDTHeader{ uint32_t CreatorRevision; }; - struct RSDT{ struct ACPISDTHeader h; - uint32_t PointerToSDT[]; // Length of array : (header.Length - sizeof(header))/ 4 + uint32_t *PointerToSDT; // Length of array : (header.Length - sizeof(header))/ 4 }__attribute__((packed)); @@ -28,7 +27,7 @@ struct RSDPDescriptor { uint8_t Checksum ; char OEMID [6]; uint8_t Revision; - RSDT* RsdtAddress; + uint32_t RsdtAddress; }__attribute__((packed)); struct RSCPDescriptor20{