diff --git a/emulation/renode.svd b/emulation/renode.svd index 939835df1..8f67283ac 100644 --- a/emulation/renode.svd +++ b/emulation/renode.svd @@ -3,7 +3,7 @@ litex SOC - + 8 32 @@ -1070,10 +1070,10 @@ register to disable individual events.]]> GIT_GITREV 0x0014 - 0xd738663a + 0x79550678 32 @@ -1090,7 +1090,7 @@ the exact git version used to build this firmware.]]> is ``1``, then the repository this was built from has one additional commit beyond the tag indicated in `MAJOR`, `MINOR`, and `REVISION`.]]> 0x0018 - 0x02 + 0x03 32 @@ -2376,51 +2376,9 @@ register to disable individual events.]]> 9 - - RESUMEKICKER - 0xF0013000 - RESUMEKICKER - - - KICKER - 0x0000 - 0x00 - 32 - - - kick - 0 - [0:0] - 0 - - - - - - STATE - 0x0004 - 0x00 - 32 - - - resume - 0 - [0:0] - 0 - - - - - - - 0 - 0x8 - registers - - POWER - 0xF0014000 + 0xF0013000 POWER @@ -2569,7 +2527,7 @@ reset fashion]]> SPINOR - 0xF0015000 + 0xF0014000 SPINOR @@ -2850,7 +2808,7 @@ checked]]> KEYBOARD - 0xF0016000 + 0xF0015000 KEYBOARD @@ -3108,7 +3066,7 @@ again until the interrupt is serviced.]]> KEYINJECT - 0xF0017000 + 0xF0016000 KEYINJECT @@ -3144,14 +3102,14 @@ inject too fast.]]> SEED - 0xF0018000 + 0xF0017000 SEED SEED1 0x0000 - 0x676324b6 + 0x1cbd6891 32 @@ -3166,7 +3124,7 @@ inject too fast.]]> SEED0 0x0004 - 0x57ada412 + 0x3d2e31ed 32 @@ -3186,7 +3144,7 @@ inject too fast.]]> KEYROM - 0xF0019000 + 0xF0018000 KEYROM @@ -3228,7 +3186,7 @@ inject too fast.]]> AUDIO - 0xF001A000 + 0xF0019000 AUDIO @@ -3600,7 +3558,7 @@ I2S_FORMAT.I2S_STANDARD is I2S standard]]> TRNG_KERNEL - 0xF001B000 + 0xF001A000 TRNG_KERNEL @@ -3736,7 +3694,7 @@ I2S_FORMAT.I2S_STANDARD is I2S standard]]> TRNG_SERVER - 0xF001C000 + 0xF001B000 TRNG_SERVER @@ -4068,7 +4026,7 @@ to max field size]]> TRNG - 0xF001D000 + 0xF001C000 TRNG @@ -4381,7 +4339,7 @@ VCCBRAM (V) = ``Value`` x 3 / 4096.]]> SHA512 - 0xF001E000 + 0xF001D000 SHA512 @@ -4876,7 +4834,7 @@ in bits]]> ENGINE - 0xF001F000 + 0xF001E000 ENGINE @@ -5105,7 +5063,7 @@ exactly reflects the binary layout of an Engine instruction.]]> JTAG - 0xF0020000 + 0xF001F000 JTAG @@ -5163,7 +5121,7 @@ exactly reflects the binary layout of an Engine instruction.]]> WDT - 0xF0021000 + 0xF0020000 WDT @@ -5323,7 +5281,7 @@ register to disable individual events.]]> D11CTIME - 0xF0022000 + 0xF0021000 D11CTIME @@ -5365,7 +5323,7 @@ register to disable individual events.]]> IDENTIFIER_MEM - 0xF0023000 + 0xF0022000 IDENTIFIER_MEM @@ -5392,7 +5350,7 @@ register to disable individual events.]]> TIMER0 - 0xF0024000 + 0xF0023000 TIMER0 diff --git a/kernel/src/arch/riscv/irq.rs b/kernel/src/arch/riscv/irq.rs index 3769e6d82..b392b4802 100644 --- a/kernel/src/arch/riscv/irq.rs +++ b/kernel/src/arch/riscv/irq.rs @@ -123,7 +123,7 @@ pub extern "C" fn trap_handler( use crate::arch::exception::RiscvException; let ex = RiscvException::from_regs(sc.bits(), sepc::read(), stval::read()); - println!("ex: {:?}", ex); + // println!("ex: {:?}", ex); if sc.is_exception() { // If the CPU tries to store, look for a "reserved page" and provide // it with one if necessary. diff --git a/kernel/src/asm.S b/kernel/src/asm.S index 6ebe062a7..2a78b87c7 100644 --- a/kernel/src/asm.S +++ b/kernel/src/asm.S @@ -39,7 +39,7 @@ _start: allows a Xous interrupt context to run, which allows the Xous return-from-interrupt handler to set up the remainder of the resume tasks. */ - // Restore a default stack pointer + // Restore a default stack pointer - used by interrupt handlers and considered temporary/smashable li sp, 0xfffefffc // setup sie [ssoft, sext]. This corresponds to bits 1 and 9, or 0b10_0000_0010 diff --git a/loader/src/main.rs b/loader/src/main.rs index 9852454bf..0bc2a048e 100644 --- a/loader/src/main.rs +++ b/loader/src/main.rs @@ -1079,7 +1079,7 @@ fn boot_sequence(args: KernelArguments, _signature: u32) -> ! { read_initial_config(&mut cfg); // check to see if we are recovering from a clean suspend or not - let (clean, was_forced_suspend) = check_resume(&mut cfg); + let (clean, was_forced_suspend, susres_pid) = check_resume(&mut cfg); if !clean { // cold boot path @@ -1188,7 +1188,7 @@ fn boot_sequence(args: KernelArguments, _signature: u32) -> ! { println!("0x{:08x}", (*backup_args)[i]); } } - let satp = ((*backup_args)[3] as usize) & 0x803F_FFFF | (10 << 22); + let satp = ((*backup_args)[3] as usize) & 0x803F_FFFF | (((susres_pid as usize) & 0x1FF) << 22); //let satp = (*backup_args)[3]; println!("Adjusting SATP to the sures process. Was: 0x{:08x} now: 0x{:08x}", (*backup_args)[3], satp); @@ -1212,7 +1212,7 @@ fn boot_sequence(args: KernelArguments, _signature: u32) -> ! { } } -fn check_resume(cfg: &mut BootConfig) -> (bool, bool) { +fn check_resume(cfg: &mut BootConfig) -> (bool, bool, u32) { use utralib::generated::*; const WORDS_PER_SECTOR: usize = 128; const NUM_SECTORS: usize = 8; @@ -1229,14 +1229,17 @@ fn check_resume(cfg: &mut BootConfig) -> (bool, bool) { let mut clean = true; let mut hashbuf: [u32; WORDS_PER_SECTOR - 1] = [0; WORDS_PER_SECTOR - 1]; let mut index: usize = 0; + let mut pid: u32 = 0; for sector in 0..NUM_SECTORS { for i in 0..hashbuf.len() { hashbuf[i] = unsafe{(*marker)[index * WORDS_PER_SECTOR + i]}; } // sector 0 contains the boot seeds, which we replace with our own as read out from our FPGA before computing the hash + // it also contains the PID of the suspend/resume process manager, which we need to inject into the SATP if sector == 0 { hashbuf[1] = seed0; hashbuf[2] = seed1; + pid = hashbuf[3]; } let hash = crate::murmur3::murmur3_32(&hashbuf, 0); if hash != unsafe{(*marker)[(index+1) * WORDS_PER_SECTOR - 1]} { @@ -1252,7 +1255,7 @@ fn check_resume(cfg: &mut BootConfig) -> (bool, bool) { unsafe{(*marker)[i] = 0;} } - (clean, was_forced_suspend) + (clean, was_forced_suspend, pid) } fn phase_1(cfg: &mut BootConfig) { @@ -1382,6 +1385,6 @@ pub fn phase_2(cfg: &mut BootConfig) { cfg.runtime_page_tracker.len() ); // mark pages used by suspend/resume according to their needs - cfg.runtime_page_tracker[cfg.sram_size / PAGE_SIZE - 1] = 1; // loader stack -- do not touch as it contains kerner args - cfg.runtime_page_tracker[cfg.sram_size / PAGE_SIZE - 2] = 0; // clean suspend page + cfg.runtime_page_tracker[cfg.sram_size / PAGE_SIZE - 1] = 1; // claim the loader stack -- do not allow tampering, as it contains backup kernel args + cfg.runtime_page_tracker[cfg.sram_size / PAGE_SIZE - 2] = 0; // allow clean suspend page to be mapped in Xous } diff --git a/precursors/soc.svd b/precursors/soc.svd index 939835df1..8f67283ac 100644 --- a/precursors/soc.svd +++ b/precursors/soc.svd @@ -3,7 +3,7 @@ litex SOC - + 8 32 @@ -1070,10 +1070,10 @@ register to disable individual events.]]> GIT_GITREV 0x0014 - 0xd738663a + 0x79550678 32 @@ -1090,7 +1090,7 @@ the exact git version used to build this firmware.]]> is ``1``, then the repository this was built from has one additional commit beyond the tag indicated in `MAJOR`, `MINOR`, and `REVISION`.]]> 0x0018 - 0x02 + 0x03 32 @@ -2376,51 +2376,9 @@ register to disable individual events.]]> 9 - - RESUMEKICKER - 0xF0013000 - RESUMEKICKER - - - KICKER - 0x0000 - 0x00 - 32 - - - kick - 0 - [0:0] - 0 - - - - - - STATE - 0x0004 - 0x00 - 32 - - - resume - 0 - [0:0] - 0 - - - - - - - 0 - 0x8 - registers - - POWER - 0xF0014000 + 0xF0013000 POWER @@ -2569,7 +2527,7 @@ reset fashion]]> SPINOR - 0xF0015000 + 0xF0014000 SPINOR @@ -2850,7 +2808,7 @@ checked]]> KEYBOARD - 0xF0016000 + 0xF0015000 KEYBOARD @@ -3108,7 +3066,7 @@ again until the interrupt is serviced.]]> KEYINJECT - 0xF0017000 + 0xF0016000 KEYINJECT @@ -3144,14 +3102,14 @@ inject too fast.]]> SEED - 0xF0018000 + 0xF0017000 SEED SEED1 0x0000 - 0x676324b6 + 0x1cbd6891 32 @@ -3166,7 +3124,7 @@ inject too fast.]]> SEED0 0x0004 - 0x57ada412 + 0x3d2e31ed 32 @@ -3186,7 +3144,7 @@ inject too fast.]]> KEYROM - 0xF0019000 + 0xF0018000 KEYROM @@ -3228,7 +3186,7 @@ inject too fast.]]> AUDIO - 0xF001A000 + 0xF0019000 AUDIO @@ -3600,7 +3558,7 @@ I2S_FORMAT.I2S_STANDARD is I2S standard]]> TRNG_KERNEL - 0xF001B000 + 0xF001A000 TRNG_KERNEL @@ -3736,7 +3694,7 @@ I2S_FORMAT.I2S_STANDARD is I2S standard]]> TRNG_SERVER - 0xF001C000 + 0xF001B000 TRNG_SERVER @@ -4068,7 +4026,7 @@ to max field size]]> TRNG - 0xF001D000 + 0xF001C000 TRNG @@ -4381,7 +4339,7 @@ VCCBRAM (V) = ``Value`` x 3 / 4096.]]> SHA512 - 0xF001E000 + 0xF001D000 SHA512 @@ -4876,7 +4834,7 @@ in bits]]> ENGINE - 0xF001F000 + 0xF001E000 ENGINE @@ -5105,7 +5063,7 @@ exactly reflects the binary layout of an Engine instruction.]]> JTAG - 0xF0020000 + 0xF001F000 JTAG @@ -5163,7 +5121,7 @@ exactly reflects the binary layout of an Engine instruction.]]> WDT - 0xF0021000 + 0xF0020000 WDT @@ -5323,7 +5281,7 @@ register to disable individual events.]]> D11CTIME - 0xF0022000 + 0xF0021000 D11CTIME @@ -5365,7 +5323,7 @@ register to disable individual events.]]> IDENTIFIER_MEM - 0xF0023000 + 0xF0022000 IDENTIFIER_MEM @@ -5392,7 +5350,7 @@ register to disable individual events.]]> TIMER0 - 0xF0024000 + 0xF0023000 TIMER0 diff --git a/precursors/soc_csr.bin b/precursors/soc_csr.bin index 77b1dec39..feeb98f90 100644 Binary files a/precursors/soc_csr.bin and b/precursors/soc_csr.bin differ diff --git a/services/susres/src/main.rs b/services/susres/src/main.rs index 3ec5d4668..79c1446a7 100644 --- a/services/susres/src/main.rs +++ b/services/susres/src/main.rs @@ -95,8 +95,6 @@ mod implementation { os_timer: 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 stored_time: Option, /// so we can access the build seed and detect if the FPGA image was changed on us @@ -135,12 +133,6 @@ 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 seed_csr = xous::syscall::map_memory( xous::MemoryAddress::new(utra::seed::HW_SEED_BASE), None, @@ -161,7 +153,6 @@ mod implementation { os_timer: CSR::new(ostimer_csr.as_mut_ptr() as *mut u32), stored_time: None, marker, - //loader_stack, seed_csr: CSR::new(seed_csr.as_mut_ptr() as *mut u32), reboot_csr: CSR::new(reboot_csr.as_mut_ptr() as *mut u32), }; @@ -184,12 +175,6 @@ mod implementation { // note to self: don't use log:: here because we're upstream of logging being initialized assert!(unsafe{(*check_marker)[words]} == 0, "marker had non-zero entry!"); } - /* - // clear the loader stack, mostly to get rid of unused code warnings - let stack = loader_stack.as_ptr() as *mut [u32; 1024]; - for words in 0..1024 { - unsafe{(*stack)[words] = 0;} - }*/ xous::claim_interrupt( utra::susres::SUSRES_IRQ, @@ -284,6 +269,7 @@ mod implementation { */ let seed0 = self.seed_csr.r(utra::seed::SEED0); let seed1 = self.seed_csr.r(utra::seed::SEED1); + let pid = xous::process::id() as u32; let range = WORDS_PER_PAGE / RANGES; let mut index: usize = 0; for &e in entropy.iter() { @@ -305,6 +291,7 @@ mod implementation { } unsafe{(*marker)[index + 1] = seed0}; unsafe{(*marker)[index + 2] = seed1}; + unsafe{(*marker)[index + 3] = pid}; } let mut hashbuf: [u32; WORDS_PER_PAGE / RANGES - 1] = [0; WORDS_PER_PAGE / RANGES - 1]; for i in 0..hashbuf.len() { @@ -316,13 +303,6 @@ mod implementation { index += range; } - - // clear the loader stack, for no particular reason other than to be vengeful. - /*let stack = self.loader_stack.as_ptr() as *mut [u32; 1024]; - for words in 0..1024 { - unsafe{(*stack)[words] = 0;} - }*/ - println!("Triggering suspend interrupt"); // trigger an interrupt to process the final suspend bits self.csr.wfo(utra::susres::INTERRUPT_INTERRUPT, 1); @@ -371,11 +351,6 @@ mod implementation { self.csr.wo(utra::susres::CONTROL, 0); println!("Ticktimer and OS timer now running"); - // clear the loader stack, for no other reason other than to be vengeful - /*let stack = self.loader_stack.as_ptr() as *mut [u32; 1024]; - for words in 0..1024 { - unsafe{(*stack)[words] = 0;} - }*/ } else { panic!("Can't resume because the ticktimer value was not saved properly before suspend!") }; diff --git a/services/ticktimer-server/src/main.rs b/services/ticktimer-server/src/main.rs index c7fa383f8..6254af793 100644 --- a/services/ticktimer-server/src/main.rs +++ b/services/ticktimer-server/src/main.rs @@ -493,7 +493,7 @@ fn xmain() -> ! { let mut sleep_heap: BinaryHeap = BinaryHeap::new(); log_server::init_wait().unwrap(); - log::set_max_level(log::LevelFilter::Trace); + log::set_max_level(log::LevelFilter::Info); info!("my PID is {}", xous::process::id()); let ticktimer_server = xous::create_server_with_address(b"ticktimer-server") diff --git a/svd2utra/examples/soc.svd b/svd2utra/examples/soc.svd index 939835df1..8f67283ac 100644 --- a/svd2utra/examples/soc.svd +++ b/svd2utra/examples/soc.svd @@ -3,7 +3,7 @@ litex SOC - + 8 32 @@ -1070,10 +1070,10 @@ register to disable individual events.]]> GIT_GITREV 0x0014 - 0xd738663a + 0x79550678 32 @@ -1090,7 +1090,7 @@ the exact git version used to build this firmware.]]> is ``1``, then the repository this was built from has one additional commit beyond the tag indicated in `MAJOR`, `MINOR`, and `REVISION`.]]> 0x0018 - 0x02 + 0x03 32 @@ -2376,51 +2376,9 @@ register to disable individual events.]]> 9 - - RESUMEKICKER - 0xF0013000 - RESUMEKICKER - - - KICKER - 0x0000 - 0x00 - 32 - - - kick - 0 - [0:0] - 0 - - - - - - STATE - 0x0004 - 0x00 - 32 - - - resume - 0 - [0:0] - 0 - - - - - - - 0 - 0x8 - registers - - POWER - 0xF0014000 + 0xF0013000 POWER @@ -2569,7 +2527,7 @@ reset fashion]]> SPINOR - 0xF0015000 + 0xF0014000 SPINOR @@ -2850,7 +2808,7 @@ checked]]> KEYBOARD - 0xF0016000 + 0xF0015000 KEYBOARD @@ -3108,7 +3066,7 @@ again until the interrupt is serviced.]]> KEYINJECT - 0xF0017000 + 0xF0016000 KEYINJECT @@ -3144,14 +3102,14 @@ inject too fast.]]> SEED - 0xF0018000 + 0xF0017000 SEED SEED1 0x0000 - 0x676324b6 + 0x1cbd6891 32 @@ -3166,7 +3124,7 @@ inject too fast.]]> SEED0 0x0004 - 0x57ada412 + 0x3d2e31ed 32 @@ -3186,7 +3144,7 @@ inject too fast.]]> KEYROM - 0xF0019000 + 0xF0018000 KEYROM @@ -3228,7 +3186,7 @@ inject too fast.]]> AUDIO - 0xF001A000 + 0xF0019000 AUDIO @@ -3600,7 +3558,7 @@ I2S_FORMAT.I2S_STANDARD is I2S standard]]> TRNG_KERNEL - 0xF001B000 + 0xF001A000 TRNG_KERNEL @@ -3736,7 +3694,7 @@ I2S_FORMAT.I2S_STANDARD is I2S standard]]> TRNG_SERVER - 0xF001C000 + 0xF001B000 TRNG_SERVER @@ -4068,7 +4026,7 @@ to max field size]]> TRNG - 0xF001D000 + 0xF001C000 TRNG @@ -4381,7 +4339,7 @@ VCCBRAM (V) = ``Value`` x 3 / 4096.]]> SHA512 - 0xF001E000 + 0xF001D000 SHA512 @@ -4876,7 +4834,7 @@ in bits]]> ENGINE - 0xF001F000 + 0xF001E000 ENGINE @@ -5105,7 +5063,7 @@ exactly reflects the binary layout of an Engine instruction.]]> JTAG - 0xF0020000 + 0xF001F000 JTAG @@ -5163,7 +5121,7 @@ exactly reflects the binary layout of an Engine instruction.]]> WDT - 0xF0021000 + 0xF0020000 WDT @@ -5323,7 +5281,7 @@ register to disable individual events.]]> D11CTIME - 0xF0022000 + 0xF0021000 D11CTIME @@ -5365,7 +5323,7 @@ register to disable individual events.]]> IDENTIFIER_MEM - 0xF0023000 + 0xF0022000 IDENTIFIER_MEM @@ -5392,7 +5350,7 @@ register to disable individual events.]]> TIMER0 - 0xF0024000 + 0xF0023000 TIMER0