From 603800457645e2615f0ff672184cbf7a19beb148 Mon Sep 17 00:00:00 2001 From: Yuhao Zhou Date: Sat, 6 Apr 2019 11:59:22 +0800 Subject: [PATCH] Add page table lookup in pagefault. --- kernel/src/arch/mipsel/interrupt.rs | 10 +++++++++- kernel/src/fs/mod.rs | 17 ++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/kernel/src/arch/mipsel/interrupt.rs b/kernel/src/arch/mipsel/interrupt.rs index abc0373..fc59fae 100644 --- a/kernel/src/arch/mipsel/interrupt.rs +++ b/kernel/src/arch/mipsel/interrupt.rs @@ -1,6 +1,9 @@ use mips::interrupts; +use mips::tlb; use mips::registers::cp0; use crate::drivers::DRIVERS; +use mips::paging::{PageTable as MIPSPageTable, PageTableEntry, PageTableFlags as EF, TwoLevelPageTable}; +use mips::addr::*; pub use self::context::*; use log::*; @@ -141,5 +144,10 @@ fn page_fault(tf: &mut TrapFrame) { crate::trap::error(tf); } - + let virt_addr = VirtAddr::new(addr); + let root_table = unsafe { + &mut *(root_page_table_ptr as *mut MIPSPageTable) + }; + let tlb_entry = root_table.lookup(addr); + tlb::write_tlb_random(tlb_entry); } diff --git a/kernel/src/fs/mod.rs b/kernel/src/fs/mod.rs index dd5c6da..a045552 100644 --- a/kernel/src/fs/mod.rs +++ b/kernel/src/fs/mod.rs @@ -21,7 +21,7 @@ mod stdio; #[cfg(feature = "link_user")] global_asm!(concat!( r#" - .section .data + .section .data.img .global _user_img_start .global _user_img_end _user_img_start: @@ -57,7 +57,22 @@ lazy_static! { println!("Sfs start {:x}, end {:x}", _user_img_start as usize, _user_img_end as usize); Arc::new(unsafe { device::MemBuf::new(_user_img_start, _user_img_end) }) }; + + let device2 = { + extern { + fn _user_img_start(); + fn _user_img_end(); + } + Arc::new(unsafe { device::MemBuf::new(_user_img_start, _user_img_end) }) + }; + + let super_block = SimpleFileSystem::read(device2); + println!("Superblock: magic = {:x}, freemap_blocks = {:x}", super_block.magic, super_block.freemap_blocks); + println!("blocks = {:}", super_block.blocks); + println!("unused_blocks = {:}", super_block.unused_blocks); + let sfs = SimpleFileSystem::open(device).expect("failed to open SFS"); + // println!("{:}", sfs.free_map.read()); sfs.root_inode() }; }