diff options
author | Jon Santmyer <jon@jonsantmyer.com> | 2025-09-02 11:35:38 -0400 |
---|---|---|
committer | Jon Santmyer <jon@jonsantmyer.com> | 2025-09-02 11:35:38 -0400 |
commit | d26eb8b54969e79d933a8e20f2725343cd42deab (patch) | |
tree | 9b6aaf6e84ed965d146c129028e32e00ef846adc | |
parent | 8f0ba2fd31408d04175513b8826bf9418ad8b087 (diff) | |
download | jove-kernel-d26eb8b54969e79d933a8e20f2725343cd42deab.tar.gz jove-kernel-d26eb8b54969e79d933a8e20f2725343cd42deab.tar.bz2 jove-kernel-d26eb8b54969e79d933a8e20f2725343cd42deab.zip |
move limine to arch-specific directory.
untie boot code from non-boot code
-rw-r--r-- | arch/x86_64/boot/limine/limine.c (renamed from boot/limine/limine.c) | 43 | ||||
-rw-r--r-- | arch/x86_64/boot/limine/limine.h (renamed from boot/limine/limine.h) | 0 | ||||
-rw-r--r-- | arch/x86_64/boot/limine/memorymap.c (renamed from arch/x86_64/memory/untyped_memory.c) | 19 | ||||
-rw-r--r-- | arch/x86_64/memory/page_directory.c | 20 | ||||
-rw-r--r-- | device/initrd.c | 30 | ||||
-rw-r--r-- | include/boot.h | 10 | ||||
-rw-r--r-- | include/memory.h | 1 | ||||
-rw-r--r-- | main.c | 3 |
8 files changed, 66 insertions, 60 deletions
diff --git a/boot/limine/limine.c b/arch/x86_64/boot/limine/limine.c index 6a1bb43..4f42491 100644 --- a/boot/limine/limine.c +++ b/arch/x86_64/boot/limine/limine.c @@ -7,10 +7,38 @@ char s_kernel_stack_initial[8192]; char *jove_bootargs; int jove_bootargs_len; +void *_boot_initrd_base; +size_t _boot_initrd_size; + +uintptr_t _boot_kernel_phys_base; + struct limine_kernel_file_request s_kernel_file_req = { .id = LIMINE_KERNEL_FILE_REQUEST }; +static struct limine_kernel_address_request s_kaddr_req = { + .id = LIMINE_KERNEL_ADDRESS_REQUEST +}; + +#ifdef ENABLE_INITRD +static struct limine_module_request s_module_request = { + .id = LIMINE_MODULE_REQUEST +}; + +#endif + +static void +e9_putc(char c) +{ + __asm__ volatile("outb %0, %1":: "a"(c), "Nd"(0xe9): "memory"); +} + +static void +e9_puts(char *s) +{ + for(; *s; s++) e9_putc(*s); +} + void _start(void) { @@ -20,6 +48,21 @@ _start(void) jove_bootargs = kernel_file_response->kernel_file->cmdline; jove_bootargs_len = strlen(jove_bootargs); +#ifdef ENABLE_INITRD + struct limine_module_response *initrd_module_response = s_module_request.response; + if(initrd_module_response->module_count == 0) { + e9_puts("Missing kernel modules\n"); + for(;;); + } + + _boot_initrd_base = initrd_module_response->modules[0]->address; + _boot_initrd_size = initrd_module_response->modules[0]->size; +#endif + + _boot_kernel_phys_base = s_kaddr_req.response->physical_base; + + + //Zero all spaces in bootargs not enclosed with quotes. for(char *c = jove_bootargs; *c; c++) { if(*c == '"') { diff --git a/boot/limine/limine.h b/arch/x86_64/boot/limine/limine.h index b7baa79..b7baa79 100644 --- a/boot/limine/limine.h +++ b/arch/x86_64/boot/limine/limine.h diff --git a/arch/x86_64/memory/untyped_memory.c b/arch/x86_64/boot/limine/memorymap.c index bd3bc6d..ec0f545 100644 --- a/arch/x86_64/memory/untyped_memory.c +++ b/arch/x86_64/boot/limine/memorymap.c @@ -1,26 +1,20 @@ -#include "memory.h" -#include "jove.h" +#include "boot.h" +#include "limine.h" +#include "object.h" #include "print.h" -#include "arch/x86_64/object.h" +#include "jove.h" #include "arch/x86_64/page.h" -#include <stddef.h> static struct jove_ObjectDirectory s_untyped_dir = { .self = { .type = KO_OBJECT_DIRECTORY, .data = 1 }, }; -static void s_populate_tables(); - -#if defined(__limine__) - -#include "boot/limine/limine.h" static volatile struct limine_memmap_request s_memmap_req = { - .id = LIMINE_MEMMAP_REQUEST, - .response = NULL + .id = LIMINE_MEMMAP_REQUEST }; void -pmem_setup(void) +boot_populate_untyped(void) { _initDirectory.entries[INIT_OBJECT_UNTYPED_DIR] = (objdir_entry_t) { .type = KO_OBJECT_DIRECTORY, @@ -49,4 +43,3 @@ pmem_setup(void) } } -#endif diff --git a/arch/x86_64/memory/page_directory.c b/arch/x86_64/memory/page_directory.c index 7030b05..11e4861 100644 --- a/arch/x86_64/memory/page_directory.c +++ b/arch/x86_64/memory/page_directory.c @@ -1,30 +1,16 @@ #include "arch/x86_64/page.h" -#include "arch/x86_64/object.h" #include "device/processor.h" -#include "print.h" #include "memory.h" +#include "boot.h" #include "object.h" #include "string.h" #include "jove.h" #include <stdint.h> -physptr_t s_kpbase(void); - -#if defined(__limine__) - -#include "boot/limine/limine.h" -static struct limine_kernel_address_request s_kaddr_req = { - .id = LIMINE_KERNEL_ADDRESS_REQUEST -}; - -physptr_t s_kpbase(void) { return s_kaddr_req.response->physical_base; } - -#endif - physptr_t vmem_tophys_koff(virtptr_t v) { - return v - (physptr_t)&_kernel_start + s_kpbase(); + return v - (physptr_t)&_kernel_start + _boot_kernel_phys_base; } #define IDENTITY_BASE 0xFFFF800000000000 @@ -106,7 +92,7 @@ vmem_setup(void) s_kernel_pml3[kernel_pml3_i].value = kernel_pml2_base | 2 | 1; s_kernel_pml2[kernel_pml2_i].value = kernel_pml1_base | 2 | 1; for(pmli_t i = kernel_pml1_ib; i < kernel_pml1_ie; i++) { - s_kernel_pml1[i].value = ((i * 0x1000) + s_kpbase()) | 3; + s_kernel_pml1[i].value = ((i * 0x1000) + _boot_kernel_phys_base) | 3; } __asm__ volatile("mov %0, %%cr3":: "r"(kernel_pml4_base)); diff --git a/device/initrd.c b/device/initrd.c index b2e615e..58f38c9 100644 --- a/device/initrd.c +++ b/device/initrd.c @@ -3,7 +3,7 @@ #include <stddef.h> #include "device/initrd.h" -#include "device/processor.h" +#include "boot.h" #include "object.h" #include "jove.h" #include "bootargs.h" @@ -20,30 +20,6 @@ struct jove_ObjectDirectory s_initrd_dir = { } }; -static uintptr_t s_initrd_getaddr(char *path); - -#if defined(__limine__) - -#include "boot/limine/limine.h" -static struct limine_module_request s_module_request = { - .id = LIMINE_MODULE_REQUEST -}; - -static uintptr_t -s_initrd_getaddr(char *path) -{ - struct limine_module_response *response = s_module_request.response; - for(size_t i = 0; i < response->module_count; i++) { - struct limine_file *module = response->modules[i]; - if(strcmp(path, module->path) == 0) - return (uintptr_t)module->address; - } - kpanic("Failed to load module at path %s\n", path); -} - - -#endif - static size_t s_tar_oct_dec(const char *oct) { @@ -83,9 +59,7 @@ initrd_setup(void) kpanic("Missing kernel commandline argument for initrd."); } - uintptr_t initrd_addr = s_initrd_getaddr(initrd_path); - klogf("Initrd found at %p\n", initrd_addr); - tar_parse((tar_block_t*)initrd_addr); + tar_parse(_boot_initrd_base); _initDirectory.entries[INIT_OBJECT_INITRD_DIR] = (objdir_entry_t) { .type = KO_OBJECT_DIRECTORY, diff --git a/include/boot.h b/include/boot.h index 989b4b9..9ff89f7 100644 --- a/include/boot.h +++ b/include/boot.h @@ -1,7 +1,17 @@ #ifndef _JOVE_BOOT_H #define _JOVE_BOOT_H 1 +#include <stddef.h> +#include <stdint.h> + extern char *jove_bootargs; extern int jove_bootargs_len; +extern void *_boot_initrd_base; +extern size_t _boot_initrd_size; + +extern uintptr_t _boot_kernel_phys_base; + +void boot_populate_untyped(void); + #endif diff --git a/include/memory.h b/include/memory.h index 7e668ae..2f75b60 100644 --- a/include/memory.h +++ b/include/memory.h @@ -9,7 +9,6 @@ typedef uintptr_t virtptr_t; #define KERNEL_STACK_SIZE 0x1000 -void pmem_setup(void); void vmem_setup(void); int untyped_retype_kernel_stack(objdir_entry_t *untyped_entry, objdir_entry_t *dest_entry); @@ -3,6 +3,7 @@ #include "memory.h" #include "print.h" #include "init.h" +#include "boot.h" #include "device/portio_uart.h" #include "device/processor.h" #include "device/initrd.h" @@ -25,7 +26,7 @@ _jove_main(void) #endif bsp_setup(); - pmem_setup(); + boot_populate_untyped(); vmem_setup(); #ifdef ENABLE_INITRD initrd_setup(); |