Directly read the bootstrap entry point from the initfs header

This commit is contained in:
bjorn3
2024-03-11 12:31:18 +01:00
parent fb66a8628f
commit ecbc2b7e8d
5 changed files with 13 additions and 15 deletions
+2 -4
View File
@@ -48,8 +48,8 @@ pub struct KernelArgs {
bootstrap_base: usize,
/// Size of contiguous bootstrap/initfs physical region, not necessarily page aligned.
bootstrap_size: usize,
/// Entry point the kernel will jump to.
bootstrap_entry: usize,
/// Entry point the kernel will jump to. (deprecated)
_bootstrap_entry: usize,
}
/// The entry to Rust, all things must be initialized
@@ -125,7 +125,6 @@ pub unsafe extern "C" fn kstart(args_ptr: *const KernelArgs) -> ! {
{ args.bootstrap_base },
args.bootstrap_base + args.bootstrap_size
);
info!("Bootstrap entry point: {:X}", { args.bootstrap_entry });
// Setup interrupt handlers
core::arch::asm!(
@@ -202,7 +201,6 @@ pub unsafe extern "C" fn kstart(args_ptr: *const KernelArgs) -> ! {
args.bootstrap_base,
)),
page_count: args.bootstrap_size / crate::memory::PAGE_SIZE,
entry: args.bootstrap_entry,
env,
}
};
+2 -4
View File
@@ -60,8 +60,8 @@ pub struct KernelArgs {
bootstrap_base: u64,
/// Size of contiguous bootstrap/initfs physical region, not necessarily page aligned.
bootstrap_size: u64,
/// Entry point the kernel will jump to.
bootstrap_entry: u64,
/// Entry point the kernel will jump to. (deprecated)
_bootstrap_entry: u64,
}
/// The entry to Rust, all things must be initialized
@@ -135,7 +135,6 @@ pub unsafe extern "C" fn kstart(args_ptr: *const KernelArgs) -> ! {
{ args.bootstrap_base },
{ args.bootstrap_base } + { args.bootstrap_size }
);
info!("Bootstrap entry point: {:X}", { args.bootstrap_entry });
// Set up GDT before paging
gdt::init();
@@ -224,7 +223,6 @@ pub unsafe extern "C" fn kstart(args_ptr: *const KernelArgs) -> ! {
args.bootstrap_base as usize,
)),
page_count: (args.bootstrap_size as usize) / crate::memory::PAGE_SIZE,
entry: args.bootstrap_entry as usize,
env,
}
};
+2 -4
View File
@@ -60,8 +60,8 @@ pub struct KernelArgs {
bootstrap_base: u64,
/// Size of contiguous bootstrap/initfs physical region, not necessarily page aligned.
bootstrap_size: u64,
/// Entry point the kernel will jump to.
bootstrap_entry: u64,
/// Entry point the kernel will jump to. (deprecated)
_bootstrap_entry: u64,
}
/// The entry to Rust, all things must be initialized
@@ -135,7 +135,6 @@ pub unsafe extern "C" fn kstart(args_ptr: *const KernelArgs) -> ! {
{ args.bootstrap_base },
{ args.bootstrap_base } + { args.bootstrap_size }
);
info!("Bootstrap entry point: {:X}", { args.bootstrap_entry });
// Set up GDT before paging
gdt::init();
@@ -233,7 +232,6 @@ pub unsafe extern "C" fn kstart(args_ptr: *const KernelArgs) -> ! {
args.bootstrap_base as usize,
)),
page_count: (args.bootstrap_size as usize) / crate::memory::PAGE_SIZE,
entry: args.bootstrap_entry as usize,
env,
}
};
-1
View File
@@ -172,7 +172,6 @@ extern "C" fn userspace_init() {
struct Bootstrap {
base: crate::memory::Frame,
page_count: usize,
entry: usize,
env: &'static [u8],
}
static BOOTSTRAP: spin::Once<Bootstrap> = spin::Once::new();
+7 -2
View File
@@ -594,13 +594,18 @@ pub unsafe fn usermode_bootstrap(bootstrap: &Bootstrap) -> ! {
}
// TODO: Not all arches do linear mapping
let bootstrap_slice = unsafe { bootstrap_mem(bootstrap) };
UserSliceWo::new(PAGE_SIZE, bootstrap.page_count * PAGE_SIZE)
.expect("failed to create bootstrap user slice")
.copy_from_slice(unsafe { bootstrap_mem(bootstrap) })
.copy_from_slice(bootstrap_slice)
.expect("failed to copy memory to bootstrap");
let bootstrap_entry = u64::from_le_bytes(bootstrap_slice[0x1a..0x22].try_into().unwrap());
log::info!("Bootstrap entry point: {:X}", bootstrap_entry);
assert_ne!(bootstrap_entry, 0);
// Start in a minimal environment without any stack.
usermode(bootstrap.entry, 0, 0, 0);
usermode(bootstrap_entry.try_into().unwrap(), 0, 0, 0);
}
pub unsafe fn bootstrap_mem(bootstrap: &crate::Bootstrap) -> &'static [u8] {