From 2d0bb16fad4c70f5adcee3af133aae29bf5e6b49 Mon Sep 17 00:00:00 2001 From: Nigel Date: Mon, 27 Feb 2023 00:32:16 +0100 Subject: [PATCH] Fixed up ACPI Version 1.0 checksum validation code --- CoreLib/Memory.cpp | 12 +++++------- kernel/acpi/acpi.cpp | 34 +++++++++++++++++++++++++--------- kernel/acpi/acpi.h | 7 ++++--- kernel/acpi/rsdp.cpp | 9 +-------- kernel/acpi/rsdp.h | 25 ++++++++++++++++++------- 5 files changed, 53 insertions(+), 34 deletions(-) diff --git a/CoreLib/Memory.cpp b/CoreLib/Memory.cpp index 491ed38..155dba1 100644 --- a/CoreLib/Memory.cpp +++ b/CoreLib/Memory.cpp @@ -16,16 +16,14 @@ void* memset (void* ptr, int value, size_t num) int memcmp( const void* ptr1, const void* ptr2, size_t num) { - const unsigned char * cs = (const unsigned char*) ptr1; - const unsigned char * ct = (const unsigned char*) ptr2; + auto* cs = (const unsigned char*) ptr1; + auto* ct = (const unsigned char*) ptr2; for (int i = 0 ; i < num ; i++, cs++, ct++ ){ - if( *cs < *ct){ - return -1; - } else if( *cs > *ct){ - return 1; - } + if( *cs != *ct) + return *cs - *ct; + } return 0; diff --git a/kernel/acpi/acpi.cpp b/kernel/acpi/acpi.cpp index e904ae6..bc83d08 100644 --- a/kernel/acpi/acpi.cpp +++ b/kernel/acpi/acpi.cpp @@ -1,5 +1,6 @@ #include "acpi.h" RSDPDescriptor* ACPI::rsd_ptr; +RSCPDescriptor20* ACPI::rsd2_ptr; RSDT* ACPI::rsd_table; @@ -8,19 +9,34 @@ 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); - // is it valid - int sum = 0; - for (int i =0; i < 20 ; i++) { - sum += ((char*)rsd_ptr)[i]; + + if( rsd_ptr->Revision == 0 ){ + // Using veriosn 1.0 of the ACPI specifiction + int sum = rsd_ptr->Checksum; + for (int i =0; i < sizeof(RSDPDescriptor) ; i++) { + sum += ((char*)rsd_ptr)[i]; + } + + printf(" 0x%x sum\n", sum); + if(sum & 0xfff0) + printf("valid rsd!\n"); + else + printf("invalid rsd\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 + ACPI::rsd2_ptr = (RSCPDescriptor20*)rsd_ptr; } - printf(" 0x%x sum\n", sum); - return; - // Get the Root System Description Table - RSDT* rootSystemDescriptionTable = getRSDT((RSDPDescriptor *) rsd_ptr); +/* auto tableHeader = &rootSystemDescriptionTable->h; // do checksum @@ -31,5 +47,5 @@ void ACPI::initialize(){ } if( sum != 0) - printf("Table invalid!"); + printf("Table invalid!");*/ } \ No newline at end of file diff --git a/kernel/acpi/acpi.h b/kernel/acpi/acpi.h index c2293d0..97ca223 100644 --- a/kernel/acpi/acpi.h +++ b/kernel/acpi/acpi.h @@ -6,8 +6,9 @@ class ACPI { // In the future ACPI might start // doing more systems initialization - + + static RSDPDescriptor* rsd_ptr; + static RSCPDescriptor20* rsd2_ptr; + static RSDT* rsd_table; private: - static RSDPDescriptor* rsd_ptr; - static RSDT* rsd_table; }; \ No newline at end of file diff --git a/kernel/acpi/rsdp.cpp b/kernel/acpi/rsdp.cpp index f4408c2..3ed66e9 100644 --- a/kernel/acpi/rsdp.cpp +++ b/kernel/acpi/rsdp.cpp @@ -1,5 +1,6 @@ #include "rsdp.h" #include "../memory/VirtualMemoryManager.h" +#include "../../CoreLib/Memory.h" void printRSD(RSDPDescriptor* rsd){ @@ -16,7 +17,6 @@ void printRSD(RSDPDescriptor* rsd){ kterm_put('\n'); printf("Revision: %d\n", rsd->Revision); - printf("RSDT Address: 0x%x\n", rsd->RsdtAddress ); } RSDPDescriptor* FindRSD(){ @@ -31,10 +31,3 @@ RSDPDescriptor* FindRSD(){ } return (RSDPDescriptor*) memory_byte; } - - -RSDT* getRSDT(RSDPDescriptor* rsd){ - printf("rsdt Address: 0x%x\n", rsd->RsdtAddress); - return (RSDT*)rsd->RsdtAddress ; - -} \ No newline at end of file diff --git a/kernel/acpi/rsdp.h b/kernel/acpi/rsdp.h index 4ae6899..aef9445 100644 --- a/kernel/acpi/rsdp.h +++ b/kernel/acpi/rsdp.h @@ -3,13 +3,6 @@ #include #include -struct RSDPDescriptor { - char signature[8]; - uint8_t Checksum ; - char OEMID [6]; - uint8_t Revision; - uint32_t RsdtAddress; -}__attribute__((packed)); struct ACPISDTHeader{ char Signature[4]; @@ -28,6 +21,24 @@ struct RSDT{ struct ACPISDTHeader h; uint32_t PointerToSDT[]; // Length of array : (header.Length - sizeof(header))/ 4 }__attribute__((packed)); + + +struct RSDPDescriptor { + char signature[8]; + uint8_t Checksum ; + char OEMID [6]; + uint8_t Revision; + RSDT* RsdtAddress; +}__attribute__((packed)); + +struct RSCPDescriptor20{ + RSDPDescriptor base; + uint32_t Length; + uint64_t XsdtAddress; + uint8_t ExtendedChecksum; + uint8_t reserved[3]; +}__attribute__((packed)); + RSDPDescriptor* FindRSD(); void printRSD(RSDPDescriptor* rsd);