summaryrefslogtreecommitdiff
path: root/src/arch/amd64/acpi.c
diff options
context:
space:
mode:
authorFreya Murphy <freya@freyacat.org>2024-01-31 12:49:06 -0500
committerFreya Murphy <freya@freyacat.org>2024-01-31 12:49:06 -0500
commit50fee8495e9329081067e9eb91f7e0ad9adc4025 (patch)
tree351790da66d5a795462618e768f077e071e4d444 /src/arch/amd64/acpi.c
parentdisable wip code (diff)
downloadcorn-50fee8495e9329081067e9eb91f7e0ad9adc4025.tar.gz
corn-50fee8495e9329081067e9eb91f7e0ad9adc4025.tar.bz2
corn-50fee8495e9329081067e9eb91f7e0ad9adc4025.zip
better mboot and kalloc
Diffstat (limited to 'src/arch/amd64/acpi.c')
-rw-r--r--src/arch/amd64/acpi.c27
1 files changed, 24 insertions, 3 deletions
diff --git a/src/arch/amd64/acpi.c b/src/arch/amd64/acpi.c
index 61083f4..732add7 100644
--- a/src/arch/amd64/acpi.c
+++ b/src/arch/amd64/acpi.c
@@ -5,6 +5,7 @@
#include <stddef.h>
#include "bindings.h"
+#include "memory.h"
#include "serial.h"
/* global state, idk a better way rn */
@@ -51,7 +52,7 @@ struct xsdp {
// ACPI 1.0
struct rsdt {
struct acpi_header h;
- uint64_t sdt_pointers[];
+ uint32_t sdt_pointers[];
};
// eXtended system descriptor table
@@ -140,6 +141,11 @@ struct fadt {
};
struct acpi_state {
+ union {
+ struct xsdt *xsdt;
+ struct rsdt *rsdt;
+ } dst;
+ uint8_t version;
struct fadt fadt;
uint16_t SLP_TYPa;
uint16_t SLP_TYPb;
@@ -196,10 +202,15 @@ static int read_s5_addr(struct acpi_state *state) {
}
static void *acpi_find_table_rsdt(struct rsdt *rsdt, const char *identifier, int ident_len) {
- int entries = (rsdt->h.length - sizeof(rsdt->h)) / 8;
+ int entries = (rsdt->h.length - sizeof(rsdt->h)) / 4;
for (int i = 0; i < entries; i++) {
struct acpi_header *h = (struct acpi_header *) (uintptr_t) rsdt->sdt_pointers[i];
+ char buf[6];
+ memcpy(buf, h->signature, 4);
+ buf[4] = '\n';
+ buf[5] = '\0';
+ serial_out_str(buf);
if (!strncmp(h->signature, identifier, ident_len))
return (void *)h;
}
@@ -222,6 +233,11 @@ static void *acpi_find_table_xsdt(struct xsdt *xsdt, const char *identifier, int
}
int acpi_init_rsdt(struct rsdt *rsdt) {
+ rsdt = mmap(rsdt, sizeof(struct rsdt));
+
+ state.dst.rsdt = rsdt;
+ state.version = 0;
+
if (!checksum((uint8_t *) &rsdt->h, rsdt->h.length))
return -1;
@@ -238,6 +254,11 @@ int acpi_init_rsdt(struct rsdt *rsdt) {
}
int acpi_init_xsdt(struct xsdt *xsdt) {
+
+ xsdt = mmap(xsdt, sizeof(struct xsdt));
+ state.dst.xsdt = xsdt;
+ state.version = 2;
+
if (!checksum((uint8_t *) &xsdt->h, xsdt->h.length))
return -1;
@@ -256,7 +277,7 @@ int acpi_init_xsdt(struct xsdt *xsdt) {
int acpi_init(void *rootsdp) {
struct rsdp *rsdp = (struct rsdp *) rootsdp;
- if (!checksum((uint8_t *)rsdp, sizeof(struct xsdp)))
+ if (!checksum((uint8_t *)rsdp, sizeof(struct rsdp)))
return -1;
int res;