diff options
-rw-r--r-- | kernel/Makefile | 1 | ||||
-rw-r--r-- | kernel/drivers/acpi.c | 54 | ||||
-rw-r--r-- | kernel/inc/acpi.h | 42 | ||||
-rw-r--r-- | kernel/main.c | 2 |
4 files changed, 99 insertions, 0 deletions
diff --git a/kernel/Makefile b/kernel/Makefile index 98060df..c6b6d93 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -1,6 +1,7 @@ # MIT License, Copyright (c) 2020 Marvin Borner COBJS = main.o \ + drivers/acpi.o \ drivers/interrupts.o \ drivers/interrupts_asm.o \ drivers/fpu.o \ diff --git a/kernel/drivers/acpi.c b/kernel/drivers/acpi.c new file mode 100644 index 0000000..02f3718 --- /dev/null +++ b/kernel/drivers/acpi.c @@ -0,0 +1,54 @@ +// MIT License, Copyright (c) 2020 Marvin Borner + +#include <acpi.h> +#include <assert.h> +#include <cpu.h> +#include <def.h> +#include <mem.h> +#include <print.h> + +int check_sdt(struct sdt_header *header) +{ + u8 sum = 0; + + for (u32 i = 0; i < header->length; i++) + sum += ((char *)header)[i]; + + return sum == 0; +} + +int check_sdp(struct sdp_header *header) +{ + u8 sum = 0; + + for (u32 i = 0; i < sizeof(struct rsdp); i++) + sum += ((char *)header)[i]; + + return sum == 0; +} + +struct rsdp *find_rsdp() +{ + // Main BIOS area + for (int i = 0xe0000; i < 0xfffff; i++) { + if (memcmp((u32 *)i, RSDP_MAGIC, 8) == 0) + return (struct rsdp *)i; + } + + // Or first KB of EBDA? + for (int i = 0x100000; i < 0x101000; i++) { + if (memcmp((u32 *)i, RSDP_MAGIC, 8) == 0) + return (struct rsdp *)i; + } + + return NULL; +} + +void acpi_install() +{ + struct rsdp *rsdp = find_rsdp(); + assert(rsdp && rsdp->header.revision == 0 && check_sdp(&rsdp->header)); + struct rsdt *rsdt = rsdp->rsdt; + assert(rsdt && memcmp(rsdt->header.signature, RSDT_MAGIC, 4) == 0 && + check_sdt(&rsdt->header)); +} diff --git a/kernel/inc/acpi.h b/kernel/inc/acpi.h new file mode 100644 index 0000000..f620d55 --- /dev/null +++ b/kernel/inc/acpi.h @@ -0,0 +1,42 @@ +// MIT License, Copyright (c) 2020 Marvin Borner + +#ifndef ACPI_H +#define ACPI_H + +#include <def.h> + +#define RSDP_MAGIC "RSD PTR " +#define RSDT_MAGIC "RSDT" + +struct sdt_header { + char signature[4]; + u32 length; + u8 revision; + u8 checksum; + char oem_id[6]; + char oem_table_id[8]; + u32 oem_revision; + u32 creator_id; + u32 creator_revision; +}; + +struct sdp_header { + char signature[8]; + u8 checksum; + char oem_id[6]; + u8 revision; +}; + +struct rsdt { + struct sdt_header header; + u32 sdt_pointer[]; +}; + +struct rsdp { + struct sdp_header header; + struct rsdt *rsdt; +}; + +void acpi_install(); + +#endif diff --git a/kernel/main.c b/kernel/main.c index 4792d75..34332e2 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -1,5 +1,6 @@ // MIT License, Copyright (c) 2020 Marvin Borner +#include <acpi.h> #include <boot.h> #include <cpu.h> #include <fpu.h> @@ -23,6 +24,7 @@ void kernel_main(struct vid_info *vid_info) serial_print("\nConnected.\n"); // Install drivers + acpi_install(); interrupts_install(); fpu_install(); timer_install(); |