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/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use crate::arch::paging::*;
use crate::os::CONSOLE;

unsafe extern "C" {
static mut _end: u8;
static mut l0_pgtable: u64;
static mut l1_pgtable: u64;
static mut l2_pgtable: u64;
Expand All @@ -48,7 +47,8 @@ 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!(_end).expose_provenance() as u64).align_up(LargePageSize::SIZE as u64)
let loader_end = crate::os::executable_end().as_ptr();
(loader_end.expose_provenance() as u64).align_up(LargePageSize::SIZE as u64)
}

pub fn find_kernel() -> &'static [u8] {
Expand Down
3 changes: 0 additions & 3 deletions src/arch/x86_64/platform/linux/entry.s
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@

.code64

.extern __executable_start # defined in linker script
.extern _end

# Move entry point at the beginning of the elf file
.section .mboot, "a"
.align 8
Expand Down
13 changes: 5 additions & 8 deletions src/arch/x86_64/platform/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ use crate::arch::x86_64::physicalmem::PhysAlloc;
use crate::arch::x86_64::{KERNEL_STACK_SIZE, SERIAL_IO_PORT, page_tables};
use crate::fdt::Fdt;

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

mod entry {
core::arch::global_asm!(
include_str!("entry.s"),
Expand All @@ -41,7 +37,8 @@ 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!(_end).addr().align_up(Size2MiB::SIZE as usize);
let loader_end = crate::os::executable_end().as_ptr();
let free_addr = loader_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 @@ -83,9 +80,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!(_end).addr() + Size4KiB::SIZE as usize).align_up(Size4KiB::SIZE as usize);
let stack = ptr::addr_of_mut!(_end).with_addr(stack);
let loader_end = crate::os::executable_end().as_ptr();
let stack = (loader_end.addr() + Size4KiB::SIZE as usize).align_up(Size4KiB::SIZE as usize);
let stack = loader_end.with_addr(stack).cast::<u8>();
// clear stack
unsafe {
write_bytes(stack, 0, KERNEL_STACK_SIZE.try_into().unwrap());
Expand Down
3 changes: 0 additions & 3 deletions src/arch/x86_64/platform/multiboot/entry.s
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@

.code32

.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.
.section .mboot, "a"
Expand Down
10 changes: 4 additions & 6 deletions src/arch/x86_64/platform/multiboot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ use crate::BootInfoExt;
use crate::arch::x86_64::physicalmem::PhysAlloc;
use crate::arch::x86_64::{KERNEL_STACK_SIZE, SERIAL_IO_PORT, page_tables};
use crate::fdt::Fdt;

unsafe extern "C" {
static mut _end: u8;
}
use crate::os::executable_end;

#[allow(bad_asm_style)]
mod entry {
Expand Down Expand Up @@ -148,7 +145,8 @@ 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!(_end).addr().align_up(Size4KiB::SIZE as usize);
let loader_end = executable_end().as_ptr();
let mut new_stack = loader_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 @@ -164,7 +162,7 @@ pub unsafe fn boot_kernel(kernel_info: LoadedKernel) -> ! {
}
}

let stack = ptr::addr_of_mut!(_end).with_addr(new_stack);
let stack = loader_end.with_addr(new_stack).cast::<u8>();

// clear stack
unsafe {
Expand Down
28 changes: 22 additions & 6 deletions src/os/none/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mod console;

use core::fmt::Write;
use core::mem::MaybeUninit;
use core::ptr::NonNull;
use core::{ptr, slice};

use hermit_entry::elf::KernelObject;
Expand All @@ -11,17 +12,32 @@ use log::info;
pub use self::console::CONSOLE;
use crate::arch;

unsafe extern "C" {
static _end: u8;
static __executable_start: u8;
pub fn executable_start() -> NonNull<()> {
unsafe extern "C" {
static mut __executable_start: u8;
}

let ptr = &raw mut __executable_start;
let ptr = ptr.cast::<()>();
NonNull::new(ptr).unwrap()
}

pub fn executable_end() -> NonNull<()> {
unsafe extern "C" {
static mut _end: u8;
}

let ptr = &raw mut _end;
let ptr = ptr.cast::<()>();
NonNull::new(ptr).unwrap()
}

/// 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}]", &__executable_start, &_end);
}
let loader_start = executable_start();
let loader_end = executable_end();
info!("Loader: [{loader_start:p} - {loader_end:p}]");

let kernel = arch::find_kernel();
let kernel = KernelObject::parse(kernel).unwrap();
Expand Down