From 69063370682f5c0e0ac3e2756773347da2358718 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E4=B8=B0=E6=BA=90?= Date: Wed, 8 Jul 2020 22:07:24 +0800 Subject: [PATCH] enable interrupt --- kernel/src/arch/mipsel/interrupt/consts.rs | 7 +++-- kernel/src/arch/mipsel/interrupt/mod.rs | 36 ++++++++++++++++++---- kernel/src/process/thread.rs | 14 ++++++--- kernel/src/shell.rs | 4 +++ kernel/src/syscall/fs.rs | 8 ++--- 5 files changed, 51 insertions(+), 18 deletions(-) diff --git a/kernel/src/arch/mipsel/interrupt/consts.rs b/kernel/src/arch/mipsel/interrupt/consts.rs index f2a5cdb9..e34fc01e 100644 --- a/kernel/src/arch/mipsel/interrupt/consts.rs +++ b/kernel/src/arch/mipsel/interrupt/consts.rs @@ -4,9 +4,10 @@ pub fn is_page_fault(trap: usize) -> bool { use cp0::cause::Exception as E; let cause = cp0::cause::Cause { bits: trap as u32 }; match cause.cause() { - E::TLBModification => true, - E::TLBLoadMiss => true, - E::TLBStoreMiss => true, + E::TLBModification | E::TLBLoadMiss | E::TLBStoreMiss => { + info!("{:#?}", cause.cause()); + true + } _ => false, } } diff --git a/kernel/src/arch/mipsel/interrupt/mod.rs b/kernel/src/arch/mipsel/interrupt/mod.rs index f60c229f..c79f50fa 100644 --- a/kernel/src/arch/mipsel/interrupt/mod.rs +++ b/kernel/src/arch/mipsel/interrupt/mod.rs @@ -23,7 +23,12 @@ pub fn init() { status.enable_soft_int1(); // Enable clock interrupt status.enable_hard_int5(); - + // status.enable_hard_int4(); + // status.enable_hard_int3(); + // status.enable_hard_int2(); + // status.enable_hard_int1(); + // status.enable_hard_int0(); + // error!("{:#x?}", status); cp0::status::write(status); info!("interrupt: init end"); } @@ -79,9 +84,11 @@ pub extern "C" fn trap_handler(tf: &mut TrapFrame) { } fn interrupt_dispatcher(tf: &mut TrapFrame) { - /* - let pint = tf.cause.pending_interrupt(); - trace!(" Interrupt {:08b} ", pint); + let cause = cp0::cause::Cause { + bits: tf.cause as u32, + }; + let pint = cause.pending_interrupt(); + // trace!(" Interrupt {:08b} ", pint); if (pint & 0b100_000_00) != 0 { timer(); } else if (pint & 0b011_111_00) != 0 { @@ -89,7 +96,6 @@ fn interrupt_dispatcher(tf: &mut TrapFrame) { } else { ipi(); } - */ } fn external() { @@ -242,6 +248,22 @@ pub fn handle_user_page_fault(thread: &Arc, addr: usize) -> bool { } else { tlb_entry.entry_lo1.valid() }; + // thread.vm.lock().handle_page_fault(addr); + // if !crate::memory::handle_page_fault(addr) { + // extern "C" { + // fn _copy_user_start(); + // fn _copy_user_end(); + // } + // let mut inner = thread.inner.lock(); + // if let Some(tf) = &mut inner.context { + // let mut tf = &mut tf.user; + // if tf.epc >= _copy_user_start as usize && tf.epc < _copy_user_end as usize { + // debug!("fixup for addr {:x?}", addr); + // tf.epc = crate::memory::read_user_fixup as usize; + // return true; + // } + // } + // } if !tlb_valid { if !thread.vm.lock().handle_page_fault(addr) { @@ -261,7 +283,7 @@ pub fn handle_user_page_fault(thread: &Arc, addr: usize) -> bool { fn page_fault(tf: &mut TrapFrame) { // TODO: set access/dirty bit let addr = tf.vaddr; - trace!("\nEXCEPTION: Page Fault @ {:#x}", addr); + // info!("\nEXCEPTION: Page Fault @ {:#x}", addr); let virt_addr = VirtAddr::new(addr); let root_table = unsafe { &mut *(get_root_page_table_ptr() as *mut MIPSPageTable) }; @@ -330,3 +352,5 @@ pub fn wait_for_interrupt() { cp0::status::enable_interrupt(); cp0::status::disable_interrupt(); } + +//2ea84 diff --git a/kernel/src/process/thread.rs b/kernel/src/process/thread.rs index 0f4e1a78..8bf23347 100644 --- a/kernel/src/process/thread.rs +++ b/kernel/src/process/thread.rs @@ -55,7 +55,7 @@ use xmas_elf::{ pub type Tid = usize; pub struct ThreadContext { - user: Box, + pub user: Box, /// TODO: lazy fp fp: Box, } @@ -65,7 +65,7 @@ pub struct ThreadContext { pub struct ThreadInner { /// user context /// None when thread is running in user - context: Option, + pub context: Option, /// Kernel performs futex wake when thread exits. /// Ref: [http://man7.org/linux/man-pages/man2/set_tid_address.2.html] pub clear_child_tid: usize, @@ -311,8 +311,12 @@ impl Thread { } #[cfg(target_arch = "mips")] { - // UM | CP1 - context.status = 1 << 4 | 1 << 29; + // UM | CP1 | IE + context.status = 1 << 4 | 1 << 29 | 1; + // IM1..IM0 + context.status |= 1 << 8 | 1 << 9; + // IPL(IM5..IM2) + context.status |= 1 << 15 | 1 << 14 | 1 << 13 | 1 << 12; } let thread = Thread { @@ -511,7 +515,7 @@ pub fn spawn(thread: Arc) { _ if is_page_fault(trap_num) => { // page fault let addr = get_page_fault_addr(); - debug!("page fault from user @ {:#x}", addr); + info!("page fault from user @ {:#x}", addr); if !handle_user_page_fault(&thread, addr) { // TODO: SIGSEGV diff --git a/kernel/src/shell.rs b/kernel/src/shell.rs index 9798d32d..095895a8 100644 --- a/kernel/src/shell.rs +++ b/kernel/src/shell.rs @@ -13,6 +13,10 @@ pub fn add_user_shell() { // This one can transfer env vars! // Why??? + #[cfg(target_arch = "mips")] + let init_shell = "/rust/sh"; //from docker-library + + #[cfg(not(target_arch = "mips"))] let init_shell = "/busybox"; //from docker-library #[cfg(target_arch = "x86_64")] diff --git a/kernel/src/syscall/fs.rs b/kernel/src/syscall/fs.rs index 32e101f1..3af82786 100644 --- a/kernel/src/syscall/fs.rs +++ b/kernel/src/syscall/fs.rs @@ -664,11 +664,11 @@ impl Syscall<'_> { let flags = AtFlags::from_bits_truncate(flags); if !proc.pid.is_init() { // we trust pid 0 process - info!( - "faccessat: dirfd: {}, path: {:?}, mode: {:#o}, flags: {:?}", - dirfd as isize, path, mode, flags - ); } + info!( + "faccessat: dirfd: {}, path: {:?}, mode: {:#o}, flags: {:?}", + dirfd as isize, path, mode, flags + ); let _inode = proc.lookup_inode_at(dirfd, &path, !flags.contains(AtFlags::SYMLINK_NOFOLLOW))?; Ok(0)