From 2146b49bb3e2898199b294d880e992366506dc04 Mon Sep 17 00:00:00 2001 From: Michael Shaw Date: Mon, 27 Feb 2023 22:55:06 -0500 Subject: [PATCH] added rsdt parse functionality this function prints out the RSDT entries present in the system --- Makefile | 6 +++--- include/kernel/acpi.h | 12 ++++++------ include/string.h | 12 ++++++++++++ init/acpi.c | 25 +++++++++++++++++++++++++ lib/printf.c | 12 ++++++++++++ lib/string.c | 18 ++++++++++++++++++ 6 files changed, 76 insertions(+), 9 deletions(-) create mode 100644 include/string.h create mode 100644 lib/string.c diff --git a/Makefile b/Makefile index 33d07ef..e094777 100644 --- a/Makefile +++ b/Makefile @@ -68,7 +68,7 @@ all: $(KERNEL) # Link rules for the final kernel executable. $(KERNEL): $(OBJ) @$(LD) $(OBJ) $(LDFLAGS) -o $@ - @echo " LD $@" + @echo " LD $@" # Include header dependencies. -include $(HEADER_DEPS) @@ -76,12 +76,12 @@ $(KERNEL): $(OBJ) # Compilation rules for *.c files. %.o: %.c @$(CC) $(CFLAGS) -c $< -o $@ - @echo " CC $@" + @echo " CC $@" # Compilation rules for *.S files. %.o: %.S @$(CC) $(CFLAGS) -c $< -o $@ - @echo " CC $@" + @echo " CC $@" # Remove object files and the final executable. .PHONY: clean diff --git a/include/kernel/acpi.h b/include/kernel/acpi.h index ea0b2ee..e21dffe 100644 --- a/include/kernel/acpi.h +++ b/include/kernel/acpi.h @@ -11,14 +11,9 @@ struct rsdp { char oemid[6]; uint8_t revision; uint32_t rsdt_addr; - - uint32_t length; - uint64_t xsdt_addr; /* the REAL address */ - uint8_t checksum_ext; - char reserved[3]; } PACKED; -struct acpi_header { +struct acpi_sdt_header { char signature[4]; uint32_t length; uint8_t revision; @@ -30,6 +25,11 @@ struct acpi_header { uint32_t creator_revision; } PACKED; +struct rsdt { + struct acpi_sdt_header h; + uint32_t sdt[]; +}; + void acpi_init(); #endif /* __ASM__ */ diff --git a/include/string.h b/include/string.h new file mode 100644 index 0000000..0d75c5b --- /dev/null +++ b/include/string.h @@ -0,0 +1,12 @@ +#ifndef _STRING_H_ +#define _STRING_H_ + +#ifndef __ASM__ + +#include + +void *memcpy(void *dest, const void *src, size_t num); +char *strcpy(char *dest, const char *src); + +#endif /* __ASM__ */ +#endif /* _STRING_H_ */ diff --git a/init/acpi.c b/init/acpi.c index 3592a90..71ba60d 100644 --- a/init/acpi.c +++ b/init/acpi.c @@ -2,15 +2,40 @@ #include #include +#include struct limine_rsdp_request rsdp_req = { .id = LIMINE_RSDP_REQUEST, .revision = 0 }; static struct rsdp *rsdp; +void rsdt_print(struct rsdt *rsdt) +{ + int num_sdt = (rsdt->h.length - sizeof(rsdt->h)) / 4; + printf("Number of RSDT entries: %d\n", num_sdt); + + for (int i = 0; i < num_sdt; i++) { + /* 2 steps silences warning */ + uint64_t sdt_addr = (uint64_t)rsdt->sdt[i]; + struct acpi_sdt_header *h = (struct acpi_sdt_header *)sdt_addr; + + char buf[9]; + memcpy(buf, h->signature, 4); + printf("[ACPI] %s %d %x \n", buf, h->revision, h->checksum); + } +} + void acpi_init() { rsdp = (struct rsdp *)rsdp_req.response->address; + /* 2 steps silences warning */ + uint64_t rsdt_addr = (uint64_t)rsdp->rsdt_addr; + struct rsdt *rsdt = (struct rsdt *)rsdt_addr; + + rsdt_print(rsdt); + + printf("ACPI version: %d\n", rsdp->revision); + printf("ACPI initialized\n"); } diff --git a/lib/printf.c b/lib/printf.c index bf12627..2081c84 100644 --- a/lib/printf.c +++ b/lib/printf.c @@ -71,6 +71,18 @@ int printf(const char *restrict fmt, ...) i = va_arg(args, int); ret++; printf_out(i); + break; + case 'x': + i = va_arg(args, int); + for (int j = sizeof(i) - 1; j >= 0; j--) { + printf_out( + convert[(i >> (j * 4)) & 0xF]); + ret++; + } + break; + default: + printf_out(c); + ret++; } } else { printf_out(c); diff --git a/lib/string.c b/lib/string.c new file mode 100644 index 0000000..111c3d1 --- /dev/null +++ b/lib/string.c @@ -0,0 +1,18 @@ +#include + +void *memcpy(void *dest, const void *src, size_t num) +{ + char *d = (char *)dest; + char *s = (char *)src; + for (size_t i = 0; i < num; i++) { + *d++ = *s++; + } + return dest; +} + +char *strcpy(char *dest, const char *src) +{ + while ((*dest++ = *src++)) + ; + return dest; +}