diff options
-rw-r--r-- | Kernel/BootInfo.h | 12 | ||||
-rw-r--r-- | Kernel/Graphics/GraphicsManagement.cpp | 10 | ||||
-rw-r--r-- | Kernel/Multiboot.h | 2 | ||||
-rw-r--r-- | Kernel/Prekernel/Prekernel.h | 12 | ||||
-rw-r--r-- | Kernel/Prekernel/init.cpp | 14 | ||||
-rw-r--r-- | Kernel/VM/MemoryManager.cpp | 6 | ||||
-rw-r--r-- | Kernel/VM/MemoryManager.h | 5 | ||||
-rw-r--r-- | Kernel/init.cpp | 31 |
8 files changed, 67 insertions, 25 deletions
diff --git a/Kernel/BootInfo.h b/Kernel/BootInfo.h index aceaa296b5..2b6399998c 100644 --- a/Kernel/BootInfo.h +++ b/Kernel/BootInfo.h @@ -7,6 +7,7 @@ #pragma once #include <Kernel/Arch/x86/PageDirectory.h> +#include <Kernel/Multiboot.h> #include <Kernel/PhysicalAddress.h> #include <Kernel/VirtualAddress.h> @@ -24,3 +25,14 @@ extern "C" PhysicalAddress boot_pd0; extern "C" PhysicalAddress boot_pd_kernel; extern "C" Kernel::PageTableEntry* boot_pd_kernel_pt1023; extern "C" const char* kernel_cmdline; +extern "C" u32 multiboot_flags; +extern "C" multiboot_memory_map_t* multiboot_memory_map; +extern "C" size_t multiboot_memory_map_count; +extern "C" multiboot_module_entry_t* multiboot_modules; +extern "C" size_t multiboot_modules_count; +extern "C" PhysicalAddress multiboot_framebuffer_addr; +extern "C" u32 multiboot_framebuffer_pitch; +extern "C" u32 multiboot_framebuffer_width; +extern "C" u32 multiboot_framebuffer_height; +extern "C" u8 multiboot_framebuffer_bpp; +extern "C" u8 multiboot_framebuffer_type; diff --git a/Kernel/Graphics/GraphicsManagement.cpp b/Kernel/Graphics/GraphicsManagement.cpp index 9a17ea96b0..3b77b17836 100644 --- a/Kernel/Graphics/GraphicsManagement.cpp +++ b/Kernel/Graphics/GraphicsManagement.cpp @@ -109,13 +109,13 @@ UNMAP_AFTER_INIT bool GraphicsManagement::determine_and_initialize_graphics_devi // support, so we want to utilize the provided framebuffer of these // devices, if possible. if (!m_vga_adapter && PCI::is_io_space_enabled(address)) { - if (multiboot_info_ptr->framebuffer_type == MULTIBOOT_FRAMEBUFFER_TYPE_RGB) { + if (multiboot_framebuffer_type == MULTIBOOT_FRAMEBUFFER_TYPE_RGB) { dmesgln("Graphics: Using a preset resolution from the bootloader"); adapter = VGACompatibleAdapter::initialize_with_preset_resolution(address, - PhysicalAddress((u32)(multiboot_info_ptr->framebuffer_addr)), - multiboot_info_ptr->framebuffer_width, - multiboot_info_ptr->framebuffer_height, - multiboot_info_ptr->framebuffer_pitch); + multiboot_framebuffer_addr, + multiboot_framebuffer_width, + multiboot_framebuffer_height, + multiboot_framebuffer_pitch); } } else { dmesgln("Graphics: Using a VGA compatible generic adapter"); diff --git a/Kernel/Multiboot.h b/Kernel/Multiboot.h index da714701e0..899e730d4b 100644 --- a/Kernel/Multiboot.h +++ b/Kernel/Multiboot.h @@ -121,5 +121,3 @@ struct multiboot_info { }; }; typedef struct multiboot_info multiboot_info_t; - -extern "C" multiboot_info_t* multiboot_info_ptr; diff --git a/Kernel/Prekernel/Prekernel.h b/Kernel/Prekernel/Prekernel.h index 945b617569..69d90faf66 100644 --- a/Kernel/Prekernel/Prekernel.h +++ b/Kernel/Prekernel/Prekernel.h @@ -22,7 +22,6 @@ struct [[gnu::packed]] BootInfo { u32 end_of_prekernel_image; u64 physical_to_virtual_offset; u64 kernel_base; - u64 multiboot_info_ptr; # if ARCH(X86_64) u32 gdt64ptr; u16 code64_sel; @@ -33,6 +32,17 @@ struct [[gnu::packed]] BootInfo { u32 boot_pd_kernel; u64 boot_pd_kernel_pt1023; u64 kernel_cmdline; + u32 multiboot_flags; + u64 multiboot_memory_map; + u32 multiboot_memory_map_count; + u64 multiboot_modules; + u32 multiboot_modules_count; + u64 multiboot_framebuffer_addr; + u32 multiboot_framebuffer_pitch; + u32 multiboot_framebuffer_width; + u32 multiboot_framebuffer_height; + u8 multiboot_framebuffer_bpp; + u8 multiboot_framebuffer_type; }; } #endif diff --git a/Kernel/Prekernel/init.cpp b/Kernel/Prekernel/init.cpp index 1743eae4f3..952461a2f4 100644 --- a/Kernel/Prekernel/init.cpp +++ b/Kernel/Prekernel/init.cpp @@ -143,7 +143,7 @@ extern "C" [[noreturn]] void init() multiboot_info_ptr->mods_count--; multiboot_info_ptr->mods_addr += sizeof(multiboot_module_entry_t); - auto adjust_by_load_base = [kernel_load_base](auto* ptr) { + auto adjust_by_load_base = [kernel_load_base](auto ptr) { return (decltype(ptr))((FlatPtr)ptr + kernel_load_base); }; @@ -152,7 +152,6 @@ extern "C" [[noreturn]] void init() info.end_of_prekernel_image = (PhysicalPtr)end_of_prekernel_image; info.physical_to_virtual_offset = kernel_load_base; info.kernel_base = kernel_load_base; - info.multiboot_info_ptr = (FlatPtr)adjust_by_load_base(multiboot_info_ptr); #if ARCH(X86_64) info.gdt64ptr = (PhysicalPtr)gdt64ptr; info.code64_sel = code64_sel; @@ -163,6 +162,17 @@ extern "C" [[noreturn]] void init() info.boot_pd_kernel = (PhysicalPtr)boot_pd_kernel; info.boot_pd_kernel_pt1023 = (FlatPtr)adjust_by_load_base(boot_pd_kernel_pt1023); info.kernel_cmdline = (FlatPtr)adjust_by_load_base(kernel_cmdline); + info.multiboot_flags = multiboot_info_ptr->flags; + info.multiboot_memory_map = adjust_by_load_base((FlatPtr)multiboot_info_ptr->mmap_addr); + info.multiboot_memory_map_count = multiboot_info_ptr->mmap_length / sizeof(multiboot_memory_map_t); + info.multiboot_modules = adjust_by_load_base((FlatPtr)multiboot_info_ptr->mods_addr); + info.multiboot_modules_count = multiboot_info_ptr->mods_count; + info.multiboot_framebuffer_addr = multiboot_info_ptr->framebuffer_addr; + info.multiboot_framebuffer_pitch = multiboot_info_ptr->framebuffer_pitch; + info.multiboot_framebuffer_width = multiboot_info_ptr->framebuffer_width; + info.multiboot_framebuffer_height = multiboot_info_ptr->framebuffer_height; + info.multiboot_framebuffer_bpp = multiboot_info_ptr->framebuffer_bpp; + info.multiboot_framebuffer_type = multiboot_info_ptr->framebuffer_type; asm( #if ARCH(I386) diff --git a/Kernel/VM/MemoryManager.cpp b/Kernel/VM/MemoryManager.cpp index 37690cd3a4..bd4eeeb974 100644 --- a/Kernel/VM/MemoryManager.cpp +++ b/Kernel/VM/MemoryManager.cpp @@ -199,7 +199,7 @@ UNMAP_AFTER_INIT void MemoryManager::parse_memory_map() m_used_memory_ranges.append(UsedMemoryRange { UsedMemoryRangeType::Prekernel, start_of_prekernel_image, end_of_prekernel_image }); m_used_memory_ranges.append(UsedMemoryRange { UsedMemoryRangeType::Kernel, PhysicalAddress(virtual_to_low_physical((FlatPtr)start_of_kernel_image)), PhysicalAddress(page_round_up(virtual_to_low_physical((FlatPtr)end_of_kernel_image))) }); - if (multiboot_info_ptr->flags & 0x4) { + if (multiboot_flags & 0x4) { auto* bootmods_start = multiboot_copy_boot_modules_array; auto* bootmods_end = bootmods_start + multiboot_copy_boot_modules_count; @@ -208,8 +208,8 @@ UNMAP_AFTER_INIT void MemoryManager::parse_memory_map() } } - auto* mmap_begin = reinterpret_cast<multiboot_memory_map_t*>(low_physical_to_virtual(multiboot_info_ptr->mmap_addr)); - auto* mmap_end = reinterpret_cast<multiboot_memory_map_t*>(low_physical_to_virtual(multiboot_info_ptr->mmap_addr) + multiboot_info_ptr->mmap_length); + auto* mmap_begin = multiboot_memory_map; + auto* mmap_end = multiboot_memory_map + multiboot_memory_map_count; struct ContiguousPhysicalRange { PhysicalAddress lower; diff --git a/Kernel/VM/MemoryManager.h b/Kernel/VM/MemoryManager.h index 854557ef48..2803b43cbe 100644 --- a/Kernel/VM/MemoryManager.h +++ b/Kernel/VM/MemoryManager.h @@ -41,11 +41,6 @@ constexpr FlatPtr page_round_down(FlatPtr x) return ((FlatPtr)(x)) & ~(PAGE_SIZE - 1); } -inline FlatPtr low_physical_to_virtual(FlatPtr physical) -{ - return physical + physical_to_virtual_offset; -} - inline FlatPtr virtual_to_low_physical(FlatPtr virtual_) { return virtual_ - physical_to_virtual_offset; diff --git a/Kernel/init.cpp b/Kernel/init.cpp index 16246fece0..6a821e9c0b 100644 --- a/Kernel/init.cpp +++ b/Kernel/init.cpp @@ -120,13 +120,23 @@ READONLY_AFTER_INIT PhysicalAddress boot_pd0; READONLY_AFTER_INIT PhysicalAddress boot_pd_kernel; READONLY_AFTER_INIT PageTableEntry* boot_pd_kernel_pt1023; READONLY_AFTER_INIT const char* kernel_cmdline; +READONLY_AFTER_INIT u32 multiboot_flags; +READONLY_AFTER_INIT multiboot_memory_map_t* multiboot_memory_map; +READONLY_AFTER_INIT size_t multiboot_memory_map_count; +READONLY_AFTER_INIT multiboot_module_entry_t* multiboot_modules; +READONLY_AFTER_INIT size_t multiboot_modules_count; +READONLY_AFTER_INIT PhysicalAddress multiboot_framebuffer_addr; +READONLY_AFTER_INIT u32 multiboot_framebuffer_pitch; +READONLY_AFTER_INIT u32 multiboot_framebuffer_width; +READONLY_AFTER_INIT u32 multiboot_framebuffer_height; +READONLY_AFTER_INIT u8 multiboot_framebuffer_bpp; +READONLY_AFTER_INIT u8 multiboot_framebuffer_type; } extern "C" [[noreturn]] UNMAP_AFTER_INIT void init(BootInfo const& boot_info) { g_in_early_boot = true; - multiboot_info_ptr = (multiboot_info_t*)boot_info.multiboot_info_ptr; start_of_prekernel_image = PhysicalAddress { boot_info.start_of_prekernel_image }; end_of_prekernel_image = PhysicalAddress { boot_info.end_of_prekernel_image }; physical_to_virtual_offset = boot_info.physical_to_virtual_offset; @@ -141,14 +151,25 @@ extern "C" [[noreturn]] UNMAP_AFTER_INIT void init(BootInfo const& boot_info) boot_pd_kernel = PhysicalAddress { boot_info.boot_pd_kernel }; boot_pd_kernel_pt1023 = (PageTableEntry*)boot_info.boot_pd_kernel_pt1023; kernel_cmdline = (char const*)boot_info.kernel_cmdline; + multiboot_flags = boot_info.multiboot_flags; + multiboot_memory_map = (multiboot_memory_map_t*)boot_info.multiboot_memory_map; + multiboot_memory_map_count = boot_info.multiboot_memory_map_count; + multiboot_modules = (multiboot_module_entry_t*)boot_info.multiboot_modules; + multiboot_modules_count = boot_info.multiboot_modules_count; + multiboot_framebuffer_addr = PhysicalAddress { boot_info.multiboot_framebuffer_addr }; + multiboot_framebuffer_pitch = boot_info.multiboot_framebuffer_pitch; + multiboot_framebuffer_width = boot_info.multiboot_framebuffer_width; + multiboot_framebuffer_height = boot_info.multiboot_framebuffer_height; + multiboot_framebuffer_bpp = boot_info.multiboot_framebuffer_bpp; + multiboot_framebuffer_type = boot_info.multiboot_framebuffer_type; setup_serial_debug(); // We need to copy the command line before kmalloc is initialized, // as it may overwrite parts of multiboot! CommandLine::early_initialize(kernel_cmdline); - memcpy(multiboot_copy_boot_modules_array, (u8*)low_physical_to_virtual(multiboot_info_ptr->mods_addr), multiboot_info_ptr->mods_count * sizeof(multiboot_module_entry_t)); - multiboot_copy_boot_modules_count = multiboot_info_ptr->mods_count; + memcpy(multiboot_copy_boot_modules_array, multiboot_modules, multiboot_modules_count * sizeof(multiboot_module_entry_t)); + multiboot_copy_boot_modules_count = multiboot_modules_count; s_bsp_processor.early_initialize(0); // Invoke the constructors needed for the kernel heap @@ -352,10 +373,6 @@ UNMAP_AFTER_INIT void setup_serial_debug() } } -extern "C" { -multiboot_info_t* multiboot_info_ptr; -} - // Define some Itanium C++ ABI methods to stop the linker from complaining. // If we actually call these something has gone horribly wrong void* __dso_handle __attribute__((visibility("hidden"))); |