mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-16 08:38:26 +00:00
start debugging of swap in kernel
switching contexts to bringing up hardware.
This commit is contained in:
parent
c8f104326a
commit
73c834d067
3 changed files with 34 additions and 8 deletions
|
|
@ -187,6 +187,11 @@ pub extern "C" fn trap_handler(
|
|||
let epc = sepc::read();
|
||||
|
||||
let ex = RiscvException::from_regs(sc.bits(), epc, stval::read());
|
||||
{
|
||||
let pid = current_pid();
|
||||
let ex = RiscvException::from_regs(sc.bits(), sepc::read(), stval::read());
|
||||
println!("IRQ -- KERNEL({}): RISC-V fault: {}", pid, ex);
|
||||
}
|
||||
match ex {
|
||||
// Syscall
|
||||
RiscvException::CallFromSMode(_epc, _) | RiscvException::CallFromUMode(_epc, _) => {
|
||||
|
|
@ -250,7 +255,7 @@ pub extern "C" fn trap_handler(
|
|||
// and return right away.
|
||||
RiscvException::StorePageFault(_pc, addr) | RiscvException::LoadPageFault(_pc, addr) => {
|
||||
#[cfg(all(feature = "debug-print", feature = "print-panics"))]
|
||||
print!("KERNEL({}): RISC-V fault: {} @ {:08x}, addr {:08x} - ", pid, ex, _pc, addr);
|
||||
println!("KERNEL({}): RISC-V fault: {} @ {:08x}, addr {:08x} - ", pid, ex, _pc, addr);
|
||||
crate::arch::mem::ensure_page_exists_inner(addr)
|
||||
.map(|_new_page| {
|
||||
#[cfg(all(feature = "debug-print", feature = "print-panics"))]
|
||||
|
|
@ -361,6 +366,27 @@ pub extern "C" fn trap_handler(
|
|||
}
|
||||
}
|
||||
|
||||
// Handle faulted instruction pages, because we can now actually have instruction pages that are
|
||||
// swapped out.
|
||||
|
||||
// TODO: this probably needs custom handling.
|
||||
// TODO: check the bounds of the address, it should be in the expected area for code. If outside,
|
||||
// fault. This is just to reduce potential attack surface.
|
||||
#[cfg(feature = "swap")]
|
||||
RiscvException::InstructionPageFault(_pc, addr) => {
|
||||
#[cfg(all(feature = "debug-print", feature = "print-panics"))]
|
||||
println!("KERNEL({}): RISC-V fault: {} @ {:08x}, addr {:08x} - ", pid, ex, _pc, addr);
|
||||
crate::arch::mem::ensure_page_exists_inner(addr)
|
||||
.map(|_new_page| {
|
||||
#[cfg(all(feature = "debug-print", feature = "print-panics"))]
|
||||
klog!("Handing page {:08x} to process", _new_page);
|
||||
ArchProcess::with_current_mut(|process| {
|
||||
crate::arch::syscall::resume(current_pid().get() == 1, process.current_thread())
|
||||
});
|
||||
})
|
||||
.ok(); // If this fails, fall through.
|
||||
}
|
||||
|
||||
#[cfg(feature = "gdb-stub")]
|
||||
RiscvException::Breakpoint(_address) => {
|
||||
let insn_lo = crate::arch::mem::peek_memory(epc as *mut u16).unwrap_or(0xffff);
|
||||
|
|
|
|||
|
|
@ -34,11 +34,11 @@ pub fn resume(supervisor: bool, thread: &Thread) -> ! {
|
|||
// Return to the appropriate CPU mode
|
||||
set_supervisor(supervisor);
|
||||
|
||||
// println!(
|
||||
// "Switching to PID {}, SP: {:08x}, PC: {:08x}",
|
||||
// crate::arch::current_pid(),
|
||||
// Thread.registers[1],
|
||||
// Thread.sepc,
|
||||
// );
|
||||
println!(
|
||||
"Switching to PID {}, SP: {:08x}, PC: {:08x}",
|
||||
crate::arch::current_pid(),
|
||||
thread.registers[1],
|
||||
thread.sepc,
|
||||
);
|
||||
unsafe { _xous_resume_context(thread.registers.as_ptr()) };
|
||||
}
|
||||
|
|
|
|||
|
|
@ -244,7 +244,7 @@ pub fn phase_2(cfg: &mut BootConfig, fs_prehash: &[u8; 64]) {
|
|||
// TODO: patch kernel arguments with Swap values...?
|
||||
}
|
||||
|
||||
if VVDBG {
|
||||
if VVDBG || SDBG {
|
||||
println!("PID1 pagetables:");
|
||||
#[cfg(feature = "atsama5d27")]
|
||||
debug::print_pagetable(cfg.processes[0].ttbr0);
|
||||
|
|
|
|||
Loading…
Reference in a new issue