mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-19 09:00:54 +00:00
ensure that the kernel is loaded last, even after argument extension
The kernel is supposed to be loaded last, but, when we append arguments that isn't true anymore. This fix makes sure the kernel is loaded last.
This commit is contained in:
parent
dbacbb609b
commit
62f1ad09f0
1 changed files with 33 additions and 21 deletions
|
|
@ -1,4 +1,6 @@
|
||||||
use crate::{swap::SWAP_PT_VADDR, *};
|
#[cfg(feature = "swap")]
|
||||||
|
use crate::swap::SWAP_PT_VADDR;
|
||||||
|
use crate::*;
|
||||||
|
|
||||||
/// Phase 2 bootloader
|
/// Phase 2 bootloader
|
||||||
///
|
///
|
||||||
|
|
@ -76,6 +78,7 @@ pub fn phase_2(cfg: &mut BootConfig, fs_prehash: &[u8; 64]) {
|
||||||
let mut kernel_exception_sp = 0;
|
let mut kernel_exception_sp = 0;
|
||||||
#[cfg(feature = "atsama5d27")]
|
#[cfg(feature = "atsama5d27")]
|
||||||
let mut kernel_irq_sp = 0;
|
let mut kernel_irq_sp = 0;
|
||||||
|
let mut xkrn: Option<&ProgramDescription> = None;
|
||||||
for tag in args.iter() {
|
for tag in args.iter() {
|
||||||
if tag.name == u32::from_le_bytes(*b"IniE") {
|
if tag.name == u32::from_le_bytes(*b"IniE") {
|
||||||
let inie = MiniElf::new(&tag);
|
let inie = MiniElf::new(&tag);
|
||||||
|
|
@ -102,8 +105,13 @@ pub fn phase_2(cfg: &mut BootConfig, fs_prehash: &[u8; 64]) {
|
||||||
pid += 1;
|
pid += 1;
|
||||||
}
|
}
|
||||||
} else if tag.name == u32::from_le_bytes(*b"XKrn") {
|
} else if tag.name == u32::from_le_bytes(*b"XKrn") {
|
||||||
|
xkrn = Some(unsafe { &*(tag.data.as_ptr() as *const ProgramDescription) });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Ensure that the kernel is loaded last, even if the arguments are out of order.
|
||||||
|
// This is necessary due to the swap-append arguments.
|
||||||
|
if let Some(xkrn) = xkrn {
|
||||||
println!("\n\nCopying kernel into memory");
|
println!("\n\nCopying kernel into memory");
|
||||||
let xkrn = unsafe { &*(tag.data.as_ptr() as *const ProgramDescription) };
|
|
||||||
let load_size_rounded = ((xkrn.text_size as usize + PAGE_SIZE - 1) & !(PAGE_SIZE - 1))
|
let load_size_rounded = ((xkrn.text_size as usize + PAGE_SIZE - 1) & !(PAGE_SIZE - 1))
|
||||||
+ (((xkrn.data_size + xkrn.bss_size) as usize + PAGE_SIZE - 1) & !(PAGE_SIZE - 1));
|
+ (((xkrn.data_size + xkrn.bss_size) as usize + PAGE_SIZE - 1) & !(PAGE_SIZE - 1));
|
||||||
#[cfg(not(feature = "atsama5d27"))]
|
#[cfg(not(feature = "atsama5d27"))]
|
||||||
|
|
@ -121,8 +129,9 @@ pub fn phase_2(cfg: &mut BootConfig, fs_prehash: &[u8; 64]) {
|
||||||
xkrn.data_offset as usize,
|
xkrn.data_offset as usize,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
process_offset -= load_size_rounded;
|
// process_offset -= load_size_rounded;
|
||||||
}
|
} else {
|
||||||
|
panic!("No kernel in arguments, can't boot.");
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("Done loading.");
|
println!("Done loading.");
|
||||||
|
|
@ -322,6 +331,9 @@ impl ProgramDescription {
|
||||||
|
|
||||||
// Turn the satp address into a pointer
|
// Turn the satp address into a pointer
|
||||||
let satp = unsafe { &mut *(satp_address as *mut PageTable) };
|
let satp = unsafe { &mut *(satp_address as *mut PageTable) };
|
||||||
|
if SDBG {
|
||||||
|
println!("Kernel root PT address: {:x}", satp_address);
|
||||||
|
}
|
||||||
allocator.map_page(
|
allocator.map_page(
|
||||||
satp,
|
satp,
|
||||||
satp_address,
|
satp_address,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue