mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:17:36 +00:00
Kernel/riscv64: Don't use the memory before .text as the initial stack
This new stack has the same size as the x86_64 prekernel stack (32K).
This commit is contained in:
parent
3b6a300ed7
commit
227818de9b
3 changed files with 8 additions and 10 deletions
|
@ -150,20 +150,12 @@ static UNMAP_AFTER_INIT void build_mappings(PageBumpAllocator& allocator, u64* r
|
||||||
auto start_of_kernel_range = VirtualAddress { bit_cast<FlatPtr>(+start_of_kernel_image) };
|
auto start_of_kernel_range = VirtualAddress { bit_cast<FlatPtr>(+start_of_kernel_image) };
|
||||||
auto end_of_kernel_range = VirtualAddress { bit_cast<FlatPtr>(+end_of_kernel_image) };
|
auto end_of_kernel_range = VirtualAddress { bit_cast<FlatPtr>(+end_of_kernel_image) };
|
||||||
|
|
||||||
// FIXME: don't use the memory before `start` as the stack
|
|
||||||
auto start_of_stack_range = VirtualAddress { bit_cast<FlatPtr>(+start_of_kernel_image) }.offset(-64 * KiB);
|
|
||||||
auto end_of_stack_range = VirtualAddress { bit_cast<FlatPtr>(+start_of_kernel_image) };
|
|
||||||
|
|
||||||
auto start_of_physical_kernel_range = PhysicalAddress { start_of_kernel_range.get() }.offset(-calculate_physical_to_link_time_address_offset());
|
auto start_of_physical_kernel_range = PhysicalAddress { start_of_kernel_range.get() }.offset(-calculate_physical_to_link_time_address_offset());
|
||||||
auto start_of_physical_stack_range = PhysicalAddress { start_of_stack_range.get() }.offset(-calculate_physical_to_link_time_address_offset());
|
|
||||||
|
|
||||||
// FIXME: dont map everything RWX
|
// FIXME: dont map everything RWX
|
||||||
|
|
||||||
// Map kernel into high virtual memory
|
// Map kernel into high virtual memory
|
||||||
insert_entries_for_memory_range(allocator, root_table, start_of_kernel_range, end_of_kernel_range, start_of_physical_kernel_range, PageTableEntryBits::Readable | PageTableEntryBits::Writeable | PageTableEntryBits::Executable);
|
insert_entries_for_memory_range(allocator, root_table, start_of_kernel_range, end_of_kernel_range, start_of_physical_kernel_range, PageTableEntryBits::Readable | PageTableEntryBits::Writeable | PageTableEntryBits::Executable);
|
||||||
|
|
||||||
// Map the stack
|
|
||||||
insert_entries_for_memory_range(allocator, root_table, start_of_stack_range, end_of_stack_range, start_of_physical_stack_range, PageTableEntryBits::Readable | PageTableEntryBits::Writeable);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static UNMAP_AFTER_INIT void setup_kernel_page_directory(u64* root_table)
|
static UNMAP_AFTER_INIT void setup_kernel_page_directory(u64* root_table)
|
||||||
|
|
|
@ -35,8 +35,8 @@ Lclear_bss_loop:
|
||||||
bltu t0, t1, Lclear_bss_loop
|
bltu t0, t1, Lclear_bss_loop
|
||||||
Lclear_bss_done:
|
Lclear_bss_done:
|
||||||
|
|
||||||
// Let the stack start before .text for now.
|
// Set the stack pointer register to the location defined in the linker script.
|
||||||
lla sp, start
|
lla sp, end_of_initial_stack
|
||||||
|
|
||||||
// Zero all registers except sp, a0 and a1.
|
// Zero all registers except sp, a0 and a1.
|
||||||
li ra, 0
|
li ra, 0
|
||||||
|
|
|
@ -98,6 +98,12 @@ SECTIONS
|
||||||
*(.heap)
|
*(.heap)
|
||||||
} :bss
|
} :bss
|
||||||
|
|
||||||
|
. = ALIGN(4K);
|
||||||
|
start_of_initial_stack = .;
|
||||||
|
|
||||||
|
. += 32K;
|
||||||
|
end_of_initial_stack = .;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
FIXME: 8MB is enough space for all of the tables required to identity map
|
FIXME: 8MB is enough space for all of the tables required to identity map
|
||||||
physical memory. 8M is wasteful, so this should be properly calculated.
|
physical memory. 8M is wasteful, so this should be properly calculated.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue