42 lines
1.1 KiB
C
42 lines
1.1 KiB
C
#include "common.h"
|
|
#include "print.h"
|
|
|
|
#include "../include/limine.h"
|
|
|
|
// credit to dreamportdev's OSDev-Notes and the OSDev Wiki for table layouts
|
|
|
|
#include "acpi.h"
|
|
#define RSDT_SIGNATURE "RSDT"
|
|
#define XSDT_SIGNATURE "XSDT"
|
|
|
|
bool rsdp_validate(const u8* data) {
|
|
if(memcmp(data, (const u8*)RSDP_SIGNATURE, 8) != 0) {
|
|
/* to debug in memcmp is broken somehow */
|
|
if(data[0] == 'R' && data[1] == 'S' && data[2] == 'D' && data[3] == 'T' && data[4] == ' ') {
|
|
printn((const char*)data, 8);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
struct acpi_rsdp_header* head = (struct acpi_rsdp_header*)data;
|
|
size_t len = sizeof(struct acpi_rsdp_header);
|
|
len -= (head->revision == 2) * sizeof(u32) + sizeof(u64) + sizeof(u8) + sizeof(u8[3]);
|
|
u32 sum_to_zero = 0;
|
|
for(size_t i = 0; i < len; i++) {
|
|
sum_to_zero += data[i];
|
|
}
|
|
|
|
return (sum_to_zero & 0xFF) == 0;
|
|
}
|
|
|
|
static bool use_xsdt = false;
|
|
|
|
static struct acpi_rsdt* rsdt;
|
|
static struct acpi_xsdt* xsdt;
|
|
|
|
struct acpi_sdt_header* acpi_get_header(size_t n) {
|
|
return (struct acpi_sdt_header*) (use_xsdt? xsdt->addrs[n] : (u64)rsdt->addrs[n]);
|
|
}
|
|
|
|
struct acpi_rsdp_header* rsdp;
|