diff --git a/loader/src/main.rs b/loader/src/main.rs index 26ee628cf..84b407262 100644 --- a/loader/src/main.rs +++ b/loader/src/main.rs @@ -1116,6 +1116,8 @@ fn phase_1(cfg: &mut BootConfig) { // prior to jumping to our program, so allocate one page of data for // stack. // All other allocations will be placed below the stack pointer. + // + // As of Xous 0.8, the top page is bootloader stack, and the page below that is the 'clean suspend' page. cfg.init_size += PAGE_SIZE * 2; // The first region is defined as being "main RAM", which will be used @@ -1152,8 +1154,11 @@ fn phase_1(cfg: &mut BootConfig) { // will require us to transfer ownership in `stage3`. // Note also that we skip the first index, causing the stack to be // returned to the process pool. + // We also skip the second index as that is the clean suspend page. This + // needs to be claimed by the susres server before the kernel allocates it. + // Lower numbered indices corresponding to higher address pages. println!("Marking pages as in-use"); - for i in 1..(cfg.init_size / PAGE_SIZE) { + for i in 3..(cfg.init_size / PAGE_SIZE) { cfg.runtime_page_tracker[cfg.sram_size / PAGE_SIZE - i] = 1; } } @@ -1229,5 +1234,7 @@ pub fn phase_2(cfg: &mut BootConfig) { "Runtime Page Tracker: {} bytes", cfg.runtime_page_tracker.len() ); - cfg.runtime_page_tracker[cfg.sram_size / PAGE_SIZE - 1] = 0; + // mark pages used by suspend/resume as unused for later allocation by the susres server + cfg.runtime_page_tracker[cfg.sram_size / PAGE_SIZE - 1] = 0; // loader stack + cfg.runtime_page_tracker[cfg.sram_size / PAGE_SIZE - 2] = 0; // clean suspend page } diff --git a/services/susres/src/main.rs b/services/susres/src/main.rs index 8597a46d2..293a043f5 100644 --- a/services/susres/src/main.rs +++ b/services/susres/src/main.rs @@ -22,6 +22,8 @@ mod implementation { csr: utralib::CSR, /// memory region for the "clean suspend" marker marker: xous::MemoryRange, + /// loader stack region -- this data is dirtied on every resume; claim it in this process so no others accidentally use it + loader_stack: xous::MemoryRange, /// backing store for the ticktimer value time_backing: Option<[u32; 2]>, } @@ -41,12 +43,22 @@ mod implementation { 4096, xous::MemoryFlags::R | xous::MemoryFlags::W, ).expect("couldn't map clean suspend page"); + let loader_stack = xous::syscall::map_memory( + xous::MemoryAddress::new(0x40FFF000), // this is a special, hard-coded location + None, + 4096, + xous::MemoryFlags::R | xous::MemoryFlags::W, + ).expect("couldn't map clean suspend page"); let mut sr = SusResHw { csr: CSR::new(csr.as_mut_ptr() as *mut u32), time_backing: None, marker, + loader_stack, }; + // check that the marker has been zerod by map_memory + // TODO + xous::claim_interrupt( utra::susres::SUSRES_IRQ, handle_irq,