hazel/kernel/acpi.c

41 lines
978 B
C
Raw Normal View History

2024-08-01 12:33:24 -04:00
#include <kernel/acpi.h>
#include <kernel/kernel.h>
rsdp_t *acpi_find_rsdp() {
char *ptr = (char *)(KERNEL_VMA + BIOS_START);
const char sig[RSDP_SIG_LEN] = RSDP_SIG;
for (; (uint32_t)ptr - KERNEL_VMA <= BIOS_END; ptr += 16) {
int i = 0;
for (; i < RSDP_SIG_LEN; i++)
if (ptr[i] != sig[i]) break;
if (i == RSDP_SIG_LEN) return (rsdp_t *)ptr;
}
return 0;
}
uint32_t acpi_checksum(void *s, int size) {
uint32_t sum = 0;
for (int i = 0; i < size; i++) {
sum += ((uint8_t *)s)[i];
}
return sum;
}
void *acpi_find_sdt(rsdt_t *rsdt, const char sig[6]) {
int entries = (rsdt->hdr.Length - sizeof(sdt_hdr_t)) / 4;
for (int i = 0; i < entries; i++) {
const char *ptr = (const char *)rsdt->other_tables[i];
int j = 0;
for (; j < RSDP_SIG_LEN; j++)
if (ptr[j] != sig[j]) break;
if (j == RSDP_SIG_LEN) return (void *)ptr;
}
return 0;
}