Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/arch/aarch64/link.ld
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ PHDRS
SECTIONS
{
. = phys;
loader_start = .;
__executable_start = .;
.text : {
*(.text)
*(.text.*)
Expand Down Expand Up @@ -45,5 +45,5 @@ SECTIONS
. += 16K; /* | growth */
/* | direction */
__boot_core_stack_end_exclusive = .; /* | */
loader_end = .;
_end = .;
}
6 changes: 3 additions & 3 deletions src/arch/aarch64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::arch::paging::*;
use crate::os::CONSOLE;

unsafe extern "C" {
static mut loader_end: u8;
static mut _end: u8;
static mut l0_pgtable: u64;
static mut l1_pgtable: u64;
static mut l2_pgtable: u64;
Expand All @@ -48,7 +48,7 @@ const PT_MEM_CD: u64 = 0x70F;
const PT_SELF: u64 = 1 << 55;

pub unsafe fn get_memory(_memory_size: u64) -> u64 {
(ptr::addr_of_mut!(loader_end).expose_provenance() as u64).align_up(LargePageSize::SIZE as u64)
(ptr::addr_of_mut!(_end).expose_provenance() as u64).align_up(LargePageSize::SIZE as u64)
}

pub fn find_kernel() -> &'static [u8] {
Expand Down Expand Up @@ -148,7 +148,7 @@ pub unsafe fn boot_kernel(kernel_info: LoadedKernel) -> ! {
}
pgt_slice[1] = uart_address as u64 + PT_MEM_CD;

// map kernel to loader_start and stack below the kernel
// map kernel to __executable_start and stack below the kernel
let pgt_slice = unsafe { core::slice::from_raw_parts_mut(ptr::addr_of_mut!(l2k_pgtable), 512) };
for i in pgt_slice.iter_mut() {
*i = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/arch/riscv64/link.ld
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
SECTIONS {
loader_start = ADDR (.text.start);
__executable_start = ADDR (.text.start);

.text.start 0x80200000 : { *(.text._start) }
.text : { *(.text.*) }
.rodata : { *(.rodata.*) }
.data : { *(.data.*) }
.bss : { *(.bss.*) }

loader_end = .;
_end = .;
}
4 changes: 2 additions & 2 deletions src/arch/x86_64/platform/linux/entry.s
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

.code64

.extern loader_start # defined in linker script
.extern loader_end
.extern __executable_start # defined in linker script
.extern _end

# Move entry point at the beginning of the elf file
.section .mboot, "a"
Expand Down
4 changes: 2 additions & 2 deletions src/arch/x86_64/platform/linux/link.ld
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ phys = 0x000000100000;

SECTIONS
{
loader_start = phys;
__executable_start = phys;
.mboot phys : AT(ADDR(.mboot)) {
*(.mboot)
}
Expand All @@ -24,5 +24,5 @@ SECTIONS
*(.bss)
*(.bss.*)
}
loader_end = .;
_end = .;
}
12 changes: 5 additions & 7 deletions src/arch/x86_64/platform/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::arch::x86_64::{KERNEL_STACK_SIZE, SERIAL_IO_PORT, page_tables};
use crate::fdt::Fdt;

unsafe extern "C" {
static mut loader_end: u8;
static mut _end: u8;
}

mod entry {
Expand All @@ -41,9 +41,7 @@ unsafe extern "C" fn rust_start(boot_params: *mut BootParams) -> ! {
crate::log::init();
BOOT_PARAMS.store(boot_params, Ordering::Relaxed);

let free_addr = ptr::addr_of!(loader_end)
.addr()
.align_up(Size2MiB::SIZE as usize);
let free_addr = ptr::addr_of!(_end).addr().align_up(Size2MiB::SIZE as usize);
// Memory after the highest end address is unused and available for the physical memory manager.
info!("Intializing PhysAlloc with {free_addr:#x}");
PhysAlloc::init(free_addr);
Expand Down Expand Up @@ -85,9 +83,9 @@ pub unsafe fn boot_kernel(kernel_info: LoadedKernel) -> ! {
let boot_params_ref = unsafe { BootParams::get() };

// determine boot stack address
let stack = (ptr::addr_of!(loader_end).addr() + Size4KiB::SIZE as usize)
.align_up(Size4KiB::SIZE as usize);
let stack = ptr::addr_of_mut!(loader_end).with_addr(stack);
let stack =
(ptr::addr_of!(_end).addr() + Size4KiB::SIZE as usize).align_up(Size4KiB::SIZE as usize);
let stack = ptr::addr_of_mut!(_end).with_addr(stack);
// clear stack
unsafe {
write_bytes(stack, 0, KERNEL_STACK_SIZE.try_into().unwrap());
Expand Down
4 changes: 2 additions & 2 deletions src/arch/x86_64/platform/multiboot/entry.s
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

.code32

.extern loader_start # defined in linker script
.extern loader_end
.extern __executable_start # defined in linker script
.extern _end

# We use a special name to map this section at the begin of our kernel
# => Multiboot expects its magic number at the beginning of the kernel.
Expand Down
4 changes: 2 additions & 2 deletions src/arch/x86_64/platform/multiboot/link.ld
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ phys = 0x000000100000;

SECTIONS
{
loader_start = phys;
__executable_start = phys;
.mboot phys : AT(ADDR(.mboot)) {
KEEP(*(.mboot))
}
Expand All @@ -25,5 +25,5 @@ SECTIONS
*(.bss)
*(.bss.*)
}
loader_end = .;
_end = .;
}
8 changes: 3 additions & 5 deletions src/arch/x86_64/platform/multiboot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::arch::x86_64::{KERNEL_STACK_SIZE, SERIAL_IO_PORT, page_tables};
use crate::fdt::Fdt;

unsafe extern "C" {
static mut loader_end: u8;
static mut _end: u8;
}

#[allow(bad_asm_style)]
Expand Down Expand Up @@ -148,9 +148,7 @@ pub unsafe fn boot_kernel(kernel_info: LoadedKernel) -> ! {
let multiboot = unsafe { Multiboot::from_ptr(mb_info as u64, &mut mem).unwrap() };

// determine boot stack address
let mut new_stack = ptr::addr_of!(loader_end)
.addr()
.align_up(Size4KiB::SIZE as usize);
let mut new_stack = ptr::addr_of!(_end).addr().align_up(Size4KiB::SIZE as usize);

if new_stack + KERNEL_STACK_SIZE as usize > mb_info.addr() {
new_stack = (mb_info.addr() + mem::size_of::<Multiboot<'_, '_>>())
Expand All @@ -166,7 +164,7 @@ pub unsafe fn boot_kernel(kernel_info: LoadedKernel) -> ! {
}
}

let stack = ptr::addr_of_mut!(loader_end).with_addr(new_stack);
let stack = ptr::addr_of_mut!(_end).with_addr(new_stack);

// clear stack
unsafe {
Expand Down
6 changes: 3 additions & 3 deletions src/os/none/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ pub use self::console::CONSOLE;
use crate::arch;

unsafe extern "C" {
static loader_end: u8;
static loader_start: u8;
static _end: u8;
static __executable_start: u8;
}

/// Entry Point of the BIOS Loader
/// (called from entry.asm or entry.rs)
pub(crate) unsafe extern "C" fn loader_main() -> ! {
unsafe {
info!("Loader: [{:p} - {:p}]", &loader_start, &loader_end);
info!("Loader: [{:p} - {:p}]", &__executable_start, &_end);
}

let kernel = arch::find_kernel();
Expand Down