Skip to content

Commit

Permalink
Kernel: Rename pre_init arguments to fit the new BootInfo definition
Browse files Browse the repository at this point in the history
  • Loading branch information
spholz committed Sep 19, 2024
1 parent 3504b5e commit 9866ee2
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Kernel/Arch/aarch64/CPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void dbgln_without_mmu(StringView);

namespace Memory {

void init_page_tables(PhysicalPtr fdt_ptr);
void init_page_tables(PhysicalPtr flattened_devicetree_paddr);
void unmap_identity_map();

}
Expand Down
8 changes: 4 additions & 4 deletions Kernel/Arch/aarch64/MMU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,14 +292,14 @@ static void setup_kernel_page_directory(u64* root_table)
*adjust_by_mapping_base(&g_boot_info.boot_pdpt) = PhysicalAddress((PhysicalPtr)get_page_directory_table(root_table, VirtualAddress { *adjust_by_mapping_base(&g_boot_info.kernel_mapping_base) }));
}

void init_page_tables(PhysicalPtr fdt_ptr)
void init_page_tables(PhysicalPtr flattened_devicetree_paddr)
{
::DeviceTree::FlattenedDeviceTreeHeader* fdt_header = bit_cast<::DeviceTree::FlattenedDeviceTreeHeader*>(fdt_ptr);
::DeviceTree::FlattenedDeviceTreeHeader* fdt_header = bit_cast<::DeviceTree::FlattenedDeviceTreeHeader*>(flattened_devicetree_paddr);
if (fdt_header->magic != 0xd00dfeed)
panic_without_mmu("Invalid FDT passed"sv);

// Copy the FDT to a known location
u8* fdt_storage = bit_cast<u8*>(fdt_ptr);
u8* fdt_storage = bit_cast<u8*>(flattened_devicetree_paddr);
if (fdt_header->totalsize > DeviceTree::fdt_storage_size)
panic_without_mmu("Passed FDT is bigger than the internal storage"sv);
for (size_t o = 0; o < fdt_header->totalsize; o += 1) {
Expand All @@ -311,7 +311,7 @@ void init_page_tables(PhysicalPtr fdt_ptr)
adjust_by_mapping_base(&g_boot_info.boot_method_specific)->pre_init.~PreInitBootInfo();
new (adjust_by_mapping_base(&g_boot_info.boot_method_specific.multiboot1)) Multiboot1BootInfo;

*adjust_by_mapping_base(&g_boot_info.flattened_devicetree_paddr) = PhysicalAddress { fdt_ptr };
*adjust_by_mapping_base(&g_boot_info.flattened_devicetree_paddr) = PhysicalAddress { flattened_devicetree_paddr };
*adjust_by_mapping_base(&g_boot_info.physical_to_virtual_offset) = calculate_physical_to_link_time_address_offset();
*adjust_by_mapping_base(&g_boot_info.kernel_mapping_base) = KERNEL_MAPPING_BASE;
*adjust_by_mapping_base(&g_boot_info.kernel_load_base) = KERNEL_MAPPING_BASE;
Expand Down
6 changes: 3 additions & 3 deletions Kernel/Arch/aarch64/pre_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ namespace Kernel {

extern "C" [[noreturn]] void init();

extern "C" [[noreturn]] void pre_init(PhysicalPtr fdt_ptr);
extern "C" [[noreturn]] void pre_init(PhysicalPtr fdt_ptr)
extern "C" [[noreturn]] void pre_init(PhysicalPtr flattened_devicetree_paddr);
extern "C" [[noreturn]] void pre_init(PhysicalPtr flattened_devicetree_paddr)
{
// We want to drop to EL1 as soon as possible, because that is the
// exception level the kernel should run at.
initialize_exceptions();

// Next step is to set up page tables and enable the MMU.
Memory::init_page_tables(fdt_ptr);
Memory::init_page_tables(flattened_devicetree_paddr);

// At this point the MMU is enabled, physical memory is identity mapped,
// and the kernel is also mapped into higher virtual memory. However we are still executing
Expand Down
10 changes: 5 additions & 5 deletions Kernel/Arch/riscv64/MMU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,17 +221,17 @@ static UNMAP_AFTER_INIT void setup_kernel_page_directory(u64* root_table)
VERIFY_NOT_REACHED();
}

[[noreturn]] UNMAP_AFTER_INIT void init_page_tables_and_jump_to_init(FlatPtr mhartid, PhysicalPtr fdt_phys_addr)
[[noreturn]] UNMAP_AFTER_INIT void init_page_tables_and_jump_to_init(FlatPtr boot_hart_id, PhysicalPtr flattened_devicetree_paddr)
{
if (RISCV64::CSR::SATP::read().MODE != RISCV64::CSR::SATP::Mode::Bare)
panic_without_mmu("Kernel booted with MMU enabled"sv);

::DeviceTree::FlattenedDeviceTreeHeader* fdt_header = bit_cast<::DeviceTree::FlattenedDeviceTreeHeader*>(fdt_phys_addr);
::DeviceTree::FlattenedDeviceTreeHeader* fdt_header = bit_cast<::DeviceTree::FlattenedDeviceTreeHeader*>(flattened_devicetree_paddr);
if (fdt_header->magic != 0xd00dfeed)
panic_without_mmu("Invalid FDT passed"sv);

// Copy the FDT to a known location
u8* fdt_storage = bit_cast<u8*>(fdt_phys_addr);
u8* fdt_storage = bit_cast<u8*>(flattened_devicetree_paddr);
if (fdt_header->totalsize > DeviceTree::fdt_storage_size)
panic_without_mmu("Passed FDT is bigger than the internal storage"sv);
for (size_t o = 0; o < fdt_header->totalsize; o += 1) {
Expand All @@ -241,12 +241,12 @@ static UNMAP_AFTER_INIT void setup_kernel_page_directory(u64* root_table)

*adjust_by_mapping_base(&g_boot_info.boot_method) = BootMethod::PreInit;

*adjust_by_mapping_base(&g_boot_info.flattened_devicetree_paddr) = PhysicalAddress { fdt_phys_addr };
*adjust_by_mapping_base(&g_boot_info.flattened_devicetree_paddr) = PhysicalAddress { flattened_devicetree_paddr };
*adjust_by_mapping_base(&g_boot_info.physical_to_virtual_offset) = calculate_physical_to_link_time_address_offset();
*adjust_by_mapping_base(&g_boot_info.kernel_mapping_base) = KERNEL_MAPPING_BASE;
*adjust_by_mapping_base(&g_boot_info.kernel_load_base) = KERNEL_MAPPING_BASE;

*adjust_by_mapping_base(&g_boot_info.arch_specific.boot_hart_id) = mhartid;
*adjust_by_mapping_base(&g_boot_info.arch_specific.boot_hart_id) = boot_hart_id;

PageBumpAllocator allocator(adjust_by_mapping_base(reinterpret_cast<u64*>(page_tables_phys_start)), adjust_by_mapping_base(reinterpret_cast<u64*>(page_tables_phys_end)));
auto* root_table = allocator.take_page();
Expand Down
2 changes: 1 addition & 1 deletion Kernel/Arch/riscv64/MMU.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ VALIDATE_IS_RISCV64()

namespace Kernel::Memory {

[[noreturn]] void init_page_tables_and_jump_to_init(FlatPtr mhartid, PhysicalPtr fdt_phys_addr);
[[noreturn]] void init_page_tables_and_jump_to_init(FlatPtr boot_hart_id, PhysicalPtr flattened_devicetree_paddr);

}
5 changes: 2 additions & 3 deletions Kernel/Arch/riscv64/pre_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,12 @@ UNMAP_AFTER_INIT void dbgln_without_mmu(StringView message)
panic_without_mmu("Unexpected trap"sv);
}

extern "C" [[noreturn]] UNMAP_AFTER_INIT void pre_init(FlatPtr mhartid, PhysicalPtr fdt_phys_addr)
extern "C" [[noreturn]] UNMAP_AFTER_INIT void pre_init(FlatPtr boot_hart_id, PhysicalPtr flattened_devicetree_paddr)
{

// Catch traps in pre_init
RISCV64::CSR::write(RISCV64::CSR::Address::STVEC, bit_cast<FlatPtr>(&early_trap_handler));

Memory::init_page_tables_and_jump_to_init(mhartid, fdt_phys_addr);
Memory::init_page_tables_and_jump_to_init(boot_hart_id, flattened_devicetree_paddr);
}

}

0 comments on commit 9866ee2

Please sign in to comment.