diff --git a/src/lib/acpi.c b/src/lib/acpi.c new file mode 100644 index 00000000..b6e771cd --- /dev/null +++ b/src/lib/acpi.c @@ -0,0 +1,20 @@ +#include +#include +#include +#include + +void *get_rsdp(void) { + for (size_t i = 0x80000; i < 0x100000; i += 16) { + if (i == 0xa0000) { + /* skip video mem and mapped hardware */ + i = 0xe0000 - 16; + continue; + } + if (!strncmp((char *)i, "RSD PTR ", 8)) { + print("acpi: Found RSDP at %x\n", i); + return (void *)i; + } + } + + return NULL; +} diff --git a/src/lib/acpi.h b/src/lib/acpi.h new file mode 100644 index 00000000..4f45423c --- /dev/null +++ b/src/lib/acpi.h @@ -0,0 +1,6 @@ +#ifndef __LIB__ACPI_H__ +#define __LIB__ACPI_H__ + +void *get_rsdp(void); + +#endif diff --git a/src/protos/stivale.c b/src/protos/stivale.c index a4e19410..e11baaeb 100644 --- a/src/protos/stivale.c +++ b/src/protos/stivale.c @@ -3,6 +3,7 @@ #include #include #include +#include struct stivale_header { uint64_t stack; @@ -24,6 +25,7 @@ struct stivale_struct { uint16_t framebuffer_width; uint16_t framebuffer_height; uint16_t framebuffer_bpp; + uint64_t rsdp; uint64_t module_count; struct stivale_module modules[]; } __attribute__((packed)); @@ -54,6 +56,9 @@ void stivale_load(struct echfs_file_handle *fd) { elf_load(fd, &entry_point); + stivale_struct.rsdp = (uint64_t)(size_t)get_rsdp(); + print("stivale: RSDP at %X\n", stivale_struct.rsdp); + volatile struct { uint64_t pml4[512]; uint64_t pml3_lo[512]; @@ -103,9 +108,11 @@ void stivale_load(struct echfs_file_handle *fd) { "mov fs, ax\n\t" "mov gs, ax\n\t" "mov ss, ax\n\t" + "mov rsp, [rsi]\n\t" "jmp [rbx]\n\t" ".code32\n\t" : - : "a" (pagemap), "b" (&entry_point), "S" (&stivale_struct) + : "a" (pagemap), "b" (&entry_point), + "D" (&stivale_struct), "S" (&stivale_hdr.stack) ); } diff --git a/test/linker.ld b/test/linker.ld index a1f8fbd3..14f6027d 100644 --- a/test/linker.ld +++ b/test/linker.ld @@ -3,19 +3,23 @@ ENTRY(_start) SECTIONS { . = 0xffffffff80100000; - .text : { + .stivalehdr : ALIGN(4K) { + *(.stivalehdr) + } + + .text : ALIGN(4K) { *(.text*) } - .rodata : { + .rodata : ALIGN(4K) { *(.rodata*) } - .data : { + .data : ALIGN(4K) { *(.data*) } - .bss : { + .bss : ALIGN(4K) { *(.bss*) *(COMMON) }