From fc70ab53e4868c84cb56a5353c3ec2cc5cf827eb Mon Sep 17 00:00:00 2001 From: Danny Holman Date: Mon, 27 May 2024 13:59:41 -0500 Subject: arch: i386: pass entry page directory to entry func Add a third argument to i386_entry. This argument is the bootstrap page directory. Pages can be temporarily mapped in during the initialization of the paging system. Signed-off-by: Danny Holman --- arch/i386/boot/boot.s | 5 ++-- arch/i386/include/kernel/multiboot.h | 2 -- arch/i386/kernel/multiboot.c | 44 ++++++++++++++++++++---------------- 3 files changed, 27 insertions(+), 24 deletions(-) (limited to 'arch/i386') diff --git a/arch/i386/boot/boot.s b/arch/i386/boot/boot.s index e443b08..6d6da7d 100644 --- a/arch/i386/boot/boot.s +++ b/arch/i386/boot/boot.s @@ -64,14 +64,13 @@ _start: .section .text -4: movl $0, boot_page_directory + 0 - - movl %cr3, %ecx +4: movl %cr3, %ecx movl %ecx, %cr3 movl $stack_top, %esp and $-16, %esp + pushl $boot_page_directory pushl %ebx pushl %eax call i386_entry diff --git a/arch/i386/include/kernel/multiboot.h b/arch/i386/include/kernel/multiboot.h index 5825816..abbd8a9 100644 --- a/arch/i386/include/kernel/multiboot.h +++ b/arch/i386/include/kernel/multiboot.h @@ -99,6 +99,4 @@ struct mboot_mmap_entry { uint32_t type; } __attribute__((packed)); -void i386_entry(uint32_t mboot_magic, struct mboot_info *header); - #endif diff --git a/arch/i386/kernel/multiboot.c b/arch/i386/kernel/multiboot.c index 720866b..87b5e32 100644 --- a/arch/i386/kernel/multiboot.c +++ b/arch/i386/kernel/multiboot.c @@ -5,40 +5,46 @@ #include #include #include -#include -#include #include #include -#include +#include +#include +#include extern void kernel_main(char *cmdline); +extern uintptr_t *kpgdir; -void i386_entry(uint32_t mboot_magic, struct mboot_info *header) { - paging_init(); - fb_init(); - gdt_install(); - idt_install(); - pic_remap(); - timer_init(); - - register_irq_handler(1, keyboard_handler); +void i386_entry(uint32_t mboot_magic, struct mboot_info *header, uintptr_t *entry_pd) { + kpgdir = entry_pd; + fb_init(); if (mboot_magic != MBOOT_LOADER_MAGIC) { - fb_write("NOT BOOTED WITH MULTIBOOT BOOTLOADER\n", 37); - fb_write("RESET PC!\n", 10); + kprintf("NOT BOOTED WITH MULTIBOOT BOOTLOADER\n"); + kprintf("RESET PC!\n"); disable_ints(); while (1); } - map_page(NULL, (uintptr_t)header, (uintptr_t)header, PD_PRES); + map_page(NULL, (uintptr_t)header, (uintptr_t)GET_VADDR(header), PD_PRES); if (!(header->flags >> 6 & 0x1)) { - fb_write("NO MEMORY MAP FROM BOOTLOADER\n", 30); - fb_write("RESET PC!\n", 10); + kprintf("NO MEMORY MAP FROM BOOTLOADER\n"); + kprintf("RESET PC!\n"); disable_ints(); while (1); } - pfa_init(header); - enable_ints(); + struct mboot_info hcopy; + memcpy(&hcopy, header, sizeof(struct mboot_info)); + unmap_page(NULL, (uintptr_t)header); + + pfa_init(&hcopy); + paging_init(); + kmalloc_init(); + gdt_install(); + idt_install(); + pic_remap(); + timer_init(); + + //enable_ints(); kernel_main((char*)header->cmdline); while (1); -- cgit v1.2.3