added rsdt parse functionality

this function prints out the RSDT entries present in the system
This commit is contained in:
Michael Shaw 2023-02-27 22:55:06 -05:00
commit 2146b49bb3
6 changed files with 76 additions and 9 deletions

View file

@ -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

View file

@ -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__ */

12
include/string.h Normal file
View file

@ -0,0 +1,12 @@
#ifndef _STRING_H_
#define _STRING_H_
#ifndef __ASM__
#include <kernel/common.h>
void *memcpy(void *dest, const void *src, size_t num);
char *strcpy(char *dest, const char *src);
#endif /* __ASM__ */
#endif /* _STRING_H_ */

View file

@ -2,15 +2,40 @@
#include <limine/limine.h>
#include <stdio.h>
#include <string.h>
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");
}

View file

@ -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);

18
lib/string.c Normal file
View file

@ -0,0 +1,18 @@
#include <string.h>
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;
}