diff --git a/kernel/assemble.sh b/kernel/assemble.sh old mode 100644 new mode 100755 diff --git a/kernel/bin/riscv32i-unknown-none-elf.a b/kernel/bin/riscv32i-unknown-none-elf.a index 97fefeff0..14a3be90c 100644 Binary files a/kernel/bin/riscv32i-unknown-none-elf.a and b/kernel/bin/riscv32i-unknown-none-elf.a differ diff --git a/kernel/bin/riscv32imac-unknown-none-elf.a b/kernel/bin/riscv32imac-unknown-none-elf.a index f134e50ef..728ee5afb 100644 Binary files a/kernel/bin/riscv32imac-unknown-none-elf.a and b/kernel/bin/riscv32imac-unknown-none-elf.a differ diff --git a/kernel/bin/riscv32imc-unknown-none-elf.a b/kernel/bin/riscv32imc-unknown-none-elf.a index f134e50ef..728ee5afb 100644 Binary files a/kernel/bin/riscv32imc-unknown-none-elf.a and b/kernel/bin/riscv32imc-unknown-none-elf.a differ diff --git a/kernel/bin/riscv64gc-unknown-none-elf.a b/kernel/bin/riscv64gc-unknown-none-elf.a index c26f36718..5e0a0454f 100644 Binary files a/kernel/bin/riscv64gc-unknown-none-elf.a and b/kernel/bin/riscv64gc-unknown-none-elf.a differ diff --git a/kernel/bin/riscv64imac-unknown-none-elf.a b/kernel/bin/riscv64imac-unknown-none-elf.a index c26f36718..5e0a0454f 100644 Binary files a/kernel/bin/riscv64imac-unknown-none-elf.a and b/kernel/bin/riscv64imac-unknown-none-elf.a differ diff --git a/kernel/src/arch/riscv/exception.rs b/kernel/src/arch/riscv/exception.rs index 8cf156569..c74949787 100644 --- a/kernel/src/arch/riscv/exception.rs +++ b/kernel/src/arch/riscv/exception.rs @@ -3,7 +3,7 @@ use core::fmt; -#[derive(PartialEq)] +#[derive(PartialEq, Debug)] pub enum RiscvException { /// When things are all 0 NoException, diff --git a/kernel/src/arch/riscv/irq.rs b/kernel/src/arch/riscv/irq.rs index 0dd7970da..ae07ce1a9 100644 --- a/kernel/src/arch/riscv/irq.rs +++ b/kernel/src/arch/riscv/irq.rs @@ -27,7 +27,8 @@ pub fn disable_all_irqs() { } /// Enable external interrupts -pub fn enable_all_irqs() { +#[export_name = "_enable_all_irqs"] +pub extern "C" fn enable_all_irqs() { sim::write(unsafe{SIM_BACKING}); } @@ -122,6 +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); if sc.is_exception() { // If the CPU tries to store, look for a "reserved page" and provide // it with one if necessary. @@ -201,10 +203,10 @@ pub extern "C" fn trap_handler( .take() .expect("got an instruction page fault with no previous PID") }; - // println!( - // "ISR: Resuming previous pair of ({}, {})", - // previous_pid, previous_context - // ); + println!( + "ISR: Resuming previous pair of ({}, {})", + previous_pid, previous_context + ); // Switch to the previous process' address space. SystemServices::with_mut(|ss| { ss.finish_callback_and_resume(previous_pid, previous_context) @@ -229,6 +231,8 @@ pub extern "C" fn trap_handler( loop {} } else { let irqs_pending = sip::read(); + println!("irqs: {:x}", irqs_pending); + // Safe to access globals since interrupts are disabled // when this function runs. unsafe { diff --git a/kernel/src/asm.S b/kernel/src/asm.S index 35ac39835..628eeff65 100644 --- a/kernel/src/asm.S +++ b/kernel/src/asm.S @@ -28,6 +28,28 @@ _start: la t0, _start_trap csrw stvec, t0 + /////// resume prep code + // if resume flag is false (0), skip this section + beq a3, zero, coldboot + + // Restore a default stack pointer + li sp, 0xfffefffc + + // setup sie ssoft, sext: bits 1 and 9 0b10_0000_0010 + li t0, 0x202 + csrw sie, t0 + + // restore the SIM with the previously socked away value + jal ra, _enable_all_irqs + + // set scause to simulate an interrupt's occurence + li t0, 0x80000000 + csrw scause, t0 + + // Note that registers $a0-$a7 still contain the arguments + j _start_trap_rust + +coldboot: // Jump to a program to initialize global variables. // Note that at this point, the .data section should // have already been set up by the loader. diff --git a/kernel/src/irq.rs b/kernel/src/irq.rs index 056e6456f..dec50ba4d 100644 --- a/kernel/src/irq.rs +++ b/kernel/src/irq.rs @@ -22,7 +22,7 @@ pub fn handle(irqs_pending: usize) -> Result { // #[cfg(feature = "debug-print")] // klog!("switching to pid {}", pid); + println!("switching to pid {}", pid); xous_kernel::rsyscall(xous_kernel::SysCall::SwitchTo(pid, 0)) .expect("couldn't switch to pid"); } diff --git a/kernel/src/services.rs b/kernel/src/services.rs index 4900be416..28d03a6c5 100644 --- a/kernel/src/services.rs +++ b/kernel/src/services.rs @@ -532,6 +532,7 @@ impl SystemServices { // Activate the current context arch_process.set_thread(arch::process::IRQ_TID).unwrap(); + // println!("Invoking..."); // Construct the new frame arch::syscall::invoke( arch_process.current_thread_mut(), diff --git a/loader/src/main.rs b/loader/src/main.rs index dff0e4687..0f0418575 100644 --- a/loader/src/main.rs +++ b/loader/src/main.rs @@ -1100,6 +1100,9 @@ fn boot_sequence(args: KernelArguments, _signature: u32) -> ! { resume_csr.wfo(utra::susres::CONTROL_PAUSE, 1); // ensure that the ticktimer is paused before resuming resume_csr.wfo(utra::susres::EV_ENABLE_SOFT_INT, 1); // ensure that the soft interrupt is enabled for the kernel to kick println!("clean suspend marker found, doing a resume!"); + + // trigger the interrupt; it's not immediately handled, but rather checked later on by the kernel on clean resume + resume_csr.wfo(utra::susres::INTERRUPT_INTERRUPT, 1); // SATP restore is handled by the `start_kernel` assembly pre-amble } @@ -1160,11 +1163,21 @@ fn boot_sequence(args: KernelArguments, _signature: u32) -> ! { for i in 0..7 { println!("0x{:08x}", (*backup_args)[i]); } + let satp = ((*backup_args)[3] as usize) & 0x803F_FFFF | (10 << 22); + //let satp = (*backup_args)[3]; + println!("Adjusting SATP was: 0x{:08x} now: 0x{:08x}", (*backup_args)[3], satp); + + if true { + use utralib::generated::*; + let mut gpio_csr = CSR::new(utra::gpio::HW_GPIO_BASE as *mut u32); + gpio_csr.wfo(utra::gpio::UARTSEL_UARTSEL, 1); // patch us over to a different UART for debug (1=LOG 2=APP, 0=KERENL(default)) + } + start_kernel( (*backup_args)[0] as usize, (*backup_args)[1] as usize, (*backup_args)[2] as usize, - (*backup_args)[3] as usize, + satp as usize, (*backup_args)[4] as usize, (*backup_args)[5] as usize, if (*backup_args)[6] == 0 {false} else {true}, diff --git a/services/rkyv-test-client/src/main.rs b/services/rkyv-test-client/src/main.rs index 6175bdaf0..bfc7c4539 100644 --- a/services/rkyv-test-client/src/main.rs +++ b/services/rkyv-test-client/src/main.rs @@ -76,7 +76,7 @@ fn rkyv_test_client() -> ! { com.req_batt_stats().unwrap(); // let the loop run a bit, then try a suspend - if idx == 2 { + if idx == 0 { // TODO: add a self-wakeup RTC alarm once we're beyond the touch-and-go phase susres.initiate_suspend().unwrap(); } diff --git a/services/susres/Cargo.toml b/services/susres/Cargo.toml index fda9665a0..57d2e7f83 100644 --- a/services/susres/Cargo.toml +++ b/services/susres/Cargo.toml @@ -22,4 +22,4 @@ utralib = { path = "../../utralib"} [features] debugprint = [] -default = [] +default = ["debugprint"] diff --git a/services/susres/src/main.rs b/services/susres/src/main.rs index f5b667d70..1cfdae21e 100644 --- a/services/susres/src/main.rs +++ b/services/susres/src/main.rs @@ -59,6 +59,7 @@ mod implementation { // on a clean suspend then resume, the loader will queue up this interrupt to be the first thing to // run on Xous resume, with a bit in the RESUME register set. fn susres_handler(_irq_no: usize, arg: *mut usize) { + println!("susres handler"); let sr = unsafe{ &mut *(arg as *mut SusResHw) }; // clear the pending interrupt sr.csr.wfo(utra::susres::EV_PENDING_SOFT_INT, 1); @@ -70,7 +71,8 @@ mod implementation { } if sr.csr.rf(utra::susres::STATE_RESUME) == 0 { - { // this is just for testing + println!("going into suspend"); + if false { // this is just for testing let mut reboot_csr = CSR::new(REBOOT_CSR.load(Ordering::Relaxed) as *mut u32); reboot_csr.wfo(utra::reboot::SOC_RESET_SOC_RESET, 0xAC); } @@ -80,6 +82,7 @@ mod implementation { loop {} // block forever here } else { + println!("going into resume"); // this unblocks the threads waiting on the resume SHOULD_RESUME.store(true, Ordering::Relaxed); } @@ -498,7 +501,7 @@ pub fn execution_gate() { match FromPrimitive::from_usize(msg.body.id()) { // the entire purpose of SupendingNow is to block the thread that sent the message, until we're ready to resume. Some(ExecGateOpcode::SuspendingNow) => msg_blocking_scalar_unpack!(msg, _, _, _, _, { - println!("execution gated!"); + println!("checking exec gate:"); while !RESUME_EXEC.load(Ordering::Relaxed) { println!("execution gate active"); xous::yield_slice(); diff --git a/services/ticktimer-server/src/main.rs b/services/ticktimer-server/src/main.rs index 4ea77ae18..c7fa383f8 100644 --- a/services/ticktimer-server/src/main.rs +++ b/services/ticktimer-server/src/main.rs @@ -223,8 +223,7 @@ mod implementation { pub fn schedule_response(&mut self, request: SleepRequest) { let irq_target = request.msec; - #[cfg(feature = "debug-print")] - log::info!( + log::trace!( "setting a response at {} ms (current time: {} ms)", irq_target, self.elapsed_ms() @@ -287,6 +286,16 @@ mod implementation { self.wdt_sr_manager.resume(); self.ticktimer_sr_manager.resume(); + + #[cfg(feature = "watchdog")] + { // do a watchdog reset right away + self.wdt.wfo(utra::wdt::EV_PENDING_SOFT_INT, 1); + self.wdt.wfo(utra::wdt::EV_ENABLE_SOFT_INT, 1); + self.wdt.wfo(utra::wdt::INTERRUPT_INTERRUPT, 1); + } + + log::trace!("ticktimer enable: {}", self.csr.r(utra::ticktimer::EV_ENABLE)); + log::trace!("ticktimer target: {}", self.csr.r(utra::ticktimer::MSLEEP_TARGET0)); } } } @@ -511,6 +520,7 @@ fn xmain() -> ! { //ticktimer.check_wdt(); let msg = xous::receive_message(ticktimer_server).unwrap(); + log::trace!("msg: {:?}", msg); match num_traits::FromPrimitive::from_usize(msg.body.id()) { Some(api::Opcode::ElapsedMs) => { let time = ticktimer.elapsed_ms() as i64;