Skip to content

Commit

Permalink
Dump RSDP
Browse files Browse the repository at this point in the history
  • Loading branch information
phaubertin committed Nov 23, 2024
1 parent 1679f13 commit 6440ead
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 14 deletions.
4 changes: 2 additions & 2 deletions header.mk
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,12 @@ endif
#
# These flags are used when preprocessing C and assembly language files.
CPPFLAGS.includes = -I$(includes)
CPPFLAGS.arch = -m32 -march=i686
CPPFLAGS.arch = -m32 -march=i686
CPPFLAGS.others = -nostdinc
CPPFLAGS = $(CPPFLAGS.arch) $(CPPFLAGS.includes) $(CPPFLAGS.debug) $(CPPFLAGS.others) $(CPPFLAGS.extra)

# C compiler flags
CFLAGS.warnings = -std=c99 -pedantic -Wall -Werror=implicit -Werror=uninitialized -Werror=return-type
CFLAGS.warnings = -std=c99 -pedantic -Wall -Wno-array-bounds -Werror=implicit -Werror=uninitialized -Werror=return-type
CFLAGS.arch = -m32 -march=i686
CFLAGS.optimization = -O3
CFLAGS.others = -ffreestanding -fno-pie -fno-common -fno-omit-frame-pointer -fno-delete-null-pointer-checks
Expand Down
10 changes: 1 addition & 9 deletions include/kernel/infrastructure/i686/drivers/acpi.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,6 @@
#include <kernel/infrastructure/i686/drivers/asm/acpi.h>
#include <stdint.h>

typedef struct {
char signature[8];
uint8_t checksum;
char oemid[6];
uint8_t revision;
uint32_t rsdt_address;
} acpiv1_rsdp_t;

typedef struct {
char signature[8];
uint8_t checksum;
Expand All @@ -55,6 +47,6 @@ typedef struct {
uint8_t reserved[3];
} acpi_rsdp_t;

const acpi_rsdp_t *acpi_find_rsdp(void);
void acpi_init(void);

#endif
2 changes: 2 additions & 0 deletions include/kernel/infrastructure/i686/drivers/asm/acpi.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,6 @@

#define ACPI_V2_REVISION 2

#define ACPI_V1_RSDP_SIZE 20

#endif
27 changes: 24 additions & 3 deletions kernel/infrastructure/i686/drivers/acpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include <kernel/domain/services/logging.h>
#include <kernel/infrastructure/i686/drivers/acpi.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
Expand All @@ -51,7 +53,7 @@ static bool check_rsdp(const acpi_rsdp_t *rsdp) {
return false;
}

uint8_t checksum = compute_checksum(rsdp, sizeof(acpiv1_rsdp_t));
uint8_t checksum = compute_checksum(rsdp, ACPI_V1_RSDP_SIZE);

if(checksum != 0) {
return false;
Expand All @@ -68,8 +70,7 @@ static bool check_rsdp(const acpi_rsdp_t *rsdp) {
return compute_checksum(rsdp, sizeof(acpi_rsdp_t)) == 0;
}

const acpi_rsdp_t *acpi_find_rsdp(void) {

static const acpi_rsdp_t *find_rsdp(void) {
const char *ebda = (const char *)(16 * (*(uint16_t *)ACPI_BDA_EBDA));

for(const char *addr = ebda; addr < ebda + 1024; addr += 16) {
Expand All @@ -93,3 +94,23 @@ const acpi_rsdp_t *acpi_find_rsdp(void) {

return NULL;
}

void acpi_init(void) {
const acpi_rsdp_t *rsdp = find_rsdp();

if(rsdp == NULL) {
warning("ACPI RSDP not found");
return;
}

info("ACPI:");
info(" RSDP: %#08p", rsdp);
info(" Version: %s", rsdp->revision == ACPI_V1_REVISION ? "1.0" : "2.x");
info(" RSDT addr: 0x%08" PRIx32, rsdp->rsdt_address);

if(rsdp->revision == ACPI_V1_REVISION) {
return;
}

info(" XSDT addr: %#" PRIx64, rsdp->xsdt_address);
}
3 changes: 3 additions & 0 deletions kernel/infrastructure/i686/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <kernel/domain/services/logging.h>
#include <kernel/domain/services/panic.h>
#include <kernel/infrastructure/i686/asm/msr.h>
#include <kernel/infrastructure/i686/drivers/acpi.h>
#include <kernel/infrastructure/i686/drivers/pic8259.h>
#include <kernel/infrastructure/i686/drivers/pit8253.h>
#include <kernel/infrastructure/i686/drivers/uart16550a.h>
Expand Down Expand Up @@ -373,6 +374,8 @@ void machine_init(const config_t *config) {
pit8253_init();
pic8259_unmask(IRQ_TIMER);

acpi_init();

exec_file_t kernel;
get_kernel_exec_file(&kernel, bootinfo);

Expand Down

0 comments on commit 6440ead

Please sign in to comment.