feature (acpi): implemented RSDP descriptor verification

This commit is contained in:
antifallobst 2023-03-11 13:25:48 +01:00
parent a6af38bb39
commit a77b8b9b14
3 changed files with 54 additions and 1 deletions

View File

@ -21,4 +21,7 @@ typedef struct {
uint8_t reserved [3]; uint8_t reserved [3];
} __attribute__((packed)) rsdp_descriptor_v2_T; } __attribute__((packed)) rsdp_descriptor_v2_T;
bool rsdp_descriptor_v1_verify(rsdp_descriptor_v1_T* descriptor);
bool rsdp_descriptor_v2_verify(rsdp_descriptor_v2_T* descriptor);
#endif //NOX_RSDP_H #endif //NOX_RSDP_H

View File

@ -1,8 +1,30 @@
// This file is part of noxos and licensed under the MIT open source license // This file is part of noxos and licensed under the MIT open source license
#include "drivers/acpi/acpi.h" #include "drivers/acpi/acpi.h"
#include "drivers/acpi/rsdp.h"
#include "utils/logger.h" #include "utils/logger.h"
void acpi_init(boot_info_T* boot_info) { void acpi_init(boot_info_T* boot_info) {
log(LOG_DEBUG, "Initializing ACPI - RSDP: 0x%x", boot_info->rsdp); log(LOG_INFO, "Initializing ACPI - RSDP: 0x%x", boot_info->rsdp);
rsdp_descriptor_v1_T* rsdp = boot_info->rsdp;
switch (rsdp->revision) {
case 0: {
log(LOG_INFO, " Version: 1.0");
if (!rsdp_descriptor_v1_verify(boot_info->rsdp)) {
log(LOG_WARNING, "<ACPI> RSDP header verification failed");
}
break;
}
case 2: {
log(LOG_INFO, " Version: 2.0+");
if (!rsdp_descriptor_v2_verify(boot_info->rsdp)) {
log(LOG_WARNING, "<ACPI> RSDP header verification failed");
}
break;
}
default: {
log(LOG_ERROR, "<ACPI> failed to parse RSDP table (invalid revision)");
break;
}
}
} }

View File

@ -1 +1,29 @@
// This file is part of noxos and licensed under the MIT open source license // This file is part of noxos and licensed under the MIT open source license
#include "drivers/acpi/rsdp.h"
bool rsdp_descriptor_v1_verify(rsdp_descriptor_v1_T* descriptor) {
uint8_t* data = (uint8_t*)descriptor;
uint32_t num = 0;
for (uint8_t i = 0; i < sizeof(rsdp_descriptor_v1_T); i++) {
num += data[i];
}
return ((num & 0xFF) == 0);
}
bool rsdp_descriptor_v2_verify(rsdp_descriptor_v2_T* descriptor) {
if (!rsdp_descriptor_v1_verify(&descriptor->descriptor_v1)) {
return false;
}
uint8_t* data = (uint8_t*)descriptor + sizeof(rsdp_descriptor_v1_T);
uint32_t num = 0;
for (uint8_t i = 0; i < sizeof(rsdp_descriptor_v2_T) - sizeof(rsdp_descriptor_v1_T); i++) {
num += data[i];
}
return ((num & 0xFF) == 0);
}