From af501c4303f5dff17a7cad8827788dae6977f97c Mon Sep 17 00:00:00 2001 From: Sean Cross Date: Thu, 20 Oct 2022 11:23:44 +0800 Subject: [PATCH 1/2] loader: print process IDs as debug data Print out the current process ID when looping through values. This will make it easier to identify which process is getting loaded when reading through the tea leaves. Signed-off-by: Sean Cross --- loader/src/main.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/loader/src/main.rs b/loader/src/main.rs index 07e1cf851..e90d8ecf3 100644 --- a/loader/src/main.rs +++ b/loader/src/main.rs @@ -643,8 +643,10 @@ pub fn read_initial_config(cfg: &mut BootConfig) { /// Copy program data from the SPI flash into newly-allocated RAM /// located at the end of memory space. fn copy_processes(cfg: &mut BootConfig) { + let mut _pid = 1; for tag in cfg.args.iter() { if tag.name == u32::from_le_bytes(*b"IniE") { + _pid += 1; let mut page_addr: usize = 0; let mut previous_addr: usize = 0; let mut top = core::ptr::null_mut::(); @@ -668,7 +670,7 @@ fn copy_processes(cfg: &mut BootConfig) { // // Example: Page starts at oxf0c0 and is 128 bytes long // 1. Copy 128 bytes to page 1 - println!("IniE has {} sections", inie.sections.len()); + println!("\n\nIniE {} has {} sections", _pid, inie.sections.len()); for section in inie.sections.iter() { if (section.virt as usize) < previous_addr { panic!("init section addresses are not strictly increasing (new virt: {:08x}, last virt: {:08x})", section.virt, previous_addr); From b35d65c3e19d75327e5094f1019ff2f76e8809b1 Mon Sep 17 00:00:00 2001 From: Sean Cross Date: Thu, 20 Oct 2022 11:24:22 +0800 Subject: [PATCH 2/2] loader: skip zeroing when we hit a page boundary Previously, we would unconditionally zero out the remainder of a page when finished copying. We wrapped to PAGE_SIZE in order to avoid corrupting another process' memory. However, an issue was discovered under the following circumstances: 1. There are fewer than 4096 bytes of `.bss` 2. The `.bss` ends on a page boundary Under these conditions, the loader would load the section before the `.bss` into the page, then clear out the `.bss`, and finally clear the entire page, overwriting the previous section. Skip the remainder-of-page clearout when the `.bss` ends on a page boundary, rather than clearing the entire page. Signed-off-by: Sean Cross --- loader/src/main.rs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/loader/src/main.rs b/loader/src/main.rs index e90d8ecf3..043feb834 100644 --- a/loader/src/main.rs +++ b/loader/src/main.rs @@ -786,14 +786,19 @@ fn copy_processes(cfg: &mut BootConfig) { if VDBG {println!("Looping to the next section");} } - println!("Done with sections, zeroing out remaining data"); - // Zero-out the trailing bytes - unsafe { - bzero( - top.add(previous_addr as usize & (PAGE_SIZE - 1)), - top.add(PAGE_SIZE as usize), - ) - }; + println!("Done with sections"); + if previous_addr as usize & (PAGE_SIZE - 1) != 0 { + println!("Zeroing out remaining data"); + // Zero-out the trailing bytes + unsafe { + bzero( + top.add(previous_addr as usize & (PAGE_SIZE - 1)), + top.add(PAGE_SIZE as usize), + ) + }; + } else { + println!("Skipping zero step -- we ended on a page boundary"); + } } else if tag.name == u32::from_le_bytes(*b"XKrn") { let prog = unsafe { &*(tag.data.as_ptr() as *const ProgramDescription) };