diff --git a/arch/x86/init.c b/arch/x86/init.c index 422b812..01a3fc0 100644 --- a/arch/x86/init.c +++ b/arch/x86/init.c @@ -1,49 +1,32 @@ -#include "multiboot.h" +#include "console.h" +#include "panic.h" +#include "pfa.h" +#include "protected.h" #include "paging.h" #include #include - -// Defined in linker script -extern char _kernel_offset; -extern char _kernel_size; -extern char _kernel_phys_base; -extern char _kernel_virt_base; -extern char _kernel_stack_top; +#include static struct KernelMQ_Info kinfo; -const struct KernelMQ_Info *init(unsigned long multiboot_magic, unsigned long multiboot_info_base) +void init(const struct KernelMQ_Info *const kinfo_ptr) { - if (multiboot_magic != MULTIBOOT_MAGIC) { - return 0; - } + console_initialize(); kmemset(&kinfo, 0, sizeof(struct KernelMQ_Info)); - if (!multiboot_parse(&kinfo, multiboot_info_base)) { - return 0; - } + assert(kernelmq_info_validate_and_copy(&kinfo, kinfo_ptr), "Invalid kernel information."); - kinfo.kernel_offset = (unsigned long)&_kernel_offset; - kinfo.kernel_size = (unsigned long)&_kernel_size; + pfa_initialize(&kinfo); - kinfo.kernel_phys_base = (unsigned long)&_kernel_phys_base; - kinfo.kernel_virt_base = (unsigned long)&_kernel_virt_base; - - kinfo.kernel_phys_limit = kinfo.kernel_phys_base + kinfo.kernel_size - 1; - kinfo.kernel_virt_limit = kinfo.kernel_virt_base + kinfo.kernel_size - 1; - - kinfo.kernel_and_modules_total_size = kinfo.kernel_size + kinfo.modules_total_size; - - kinfo.kernel_stack_top = (unsigned long)&_kernel_stack_top; + protected_initialize(&kinfo); + // Set up a new post-relocate bootstrap pagetable so that + // we can map in VM, and we no longer rely on pre-relocated + // data. paging_clear(); - paging_identity(); - /* kinfo.freepde_start = */ paging_mapkernel(&kinfo); + paging_identity(); // Still need 1:1 for lapic and video mem and such. + paging_mapkernel(&kinfo); paging_load(); - - paging_enable(); - - return &kinfo; } diff --git a/arch/x86/main.c b/arch/x86/main.c index 9dbb7ba..94910a9 100644 --- a/arch/x86/main.c +++ b/arch/x86/main.c @@ -1,32 +1,49 @@ -#include "console.h" -#include "panic.h" -#include "pfa.h" -#include "protected.h" +#include "multiboot.h" #include "paging.h" #include #include -#include + +// Defined in linker script +extern char _kernel_offset; +extern char _kernel_size; +extern char _kernel_phys_base; +extern char _kernel_virt_base; +extern char _kernel_stack_top; static struct KernelMQ_Info kinfo; -void main(const struct KernelMQ_Info *const kinfo_ptr) +const struct KernelMQ_Info *main(unsigned long multiboot_magic, unsigned long multiboot_info_base) { - console_initialize(); + if (multiboot_magic != MULTIBOOT_MAGIC) { + return 0; + } kmemset(&kinfo, 0, sizeof(struct KernelMQ_Info)); - assert(kernelmq_info_validate_and_copy(&kinfo, kinfo_ptr), "Invalid kernel information."); + if (!multiboot_parse(&kinfo, multiboot_info_base)) { + return 0; + } - pfa_initialize(&kinfo); + kinfo.kernel_offset = (unsigned long)&_kernel_offset; + kinfo.kernel_size = (unsigned long)&_kernel_size; - protected_initialize(&kinfo); + kinfo.kernel_phys_base = (unsigned long)&_kernel_phys_base; + kinfo.kernel_virt_base = (unsigned long)&_kernel_virt_base; + + kinfo.kernel_phys_limit = kinfo.kernel_phys_base + kinfo.kernel_size - 1; + kinfo.kernel_virt_limit = kinfo.kernel_virt_base + kinfo.kernel_size - 1; + + kinfo.kernel_and_modules_total_size = kinfo.kernel_size + kinfo.modules_total_size; + + kinfo.kernel_stack_top = (unsigned long)&_kernel_stack_top; - // Set up a new post-relocate bootstrap pagetable so that - // we can map in VM, and we no longer rely on pre-relocated - // data. paging_clear(); - paging_identity(); // Still need 1:1 for lapic and video mem and such. - paging_mapkernel(&kinfo); + paging_identity(); + /* kinfo.freepde_start = */ paging_mapkernel(&kinfo); paging_load(); + + paging_enable(); + + return &kinfo; } diff --git a/arch/x86/start.s b/arch/x86/start.s index 3e668e0..462f12c 100644 --- a/arch/x86/start.s +++ b/arch/x86/start.s @@ -31,12 +31,12 @@ _start: push %ebx // Multiboot information pointer push %eax // Multiboot magic number - call init + call main mov $_kernel_stack_top, %esp // Initialize stack push %eax // Kernel information pointer - call main + call init call halt