1
0
mirror of https://github.com/rcore-os/rCore.git synced 2024-11-22 16:16:16 +04:00

run until ms.token()

This commit is contained in:
dzy 2018-12-26 14:56:13 +08:00
parent ccee527272
commit 21adebb203
5 changed files with 20 additions and 48 deletions

View File

@ -95,10 +95,18 @@ impl MemoryArea {
** @param name: &'static str the name of the memory area
** @retval MemoryArea the memory area created
*/
// TODO: VirtAddr and PhysAddr should not be the same `usize`, it's not type safe.
#[cfg(target_arch = "riscv32")]
pub fn new_identity(start_addr: VirtAddr, end_addr: VirtAddr, flags: MemoryAttr, name: &'static str) -> Self {
assert!(start_addr <= end_addr, "invalid memory area");
MemoryArea { start_addr, end_addr, phys_start_addr: Some(start_addr), flags, name }
}
#[cfg(target_arch = "riscv64")]
pub fn new_identity(start_addr: VirtAddr, end_addr: VirtAddr, flags: MemoryAttr, name: &'static str) -> Self {
assert!(start_addr <= end_addr, "invalid memory area");
let paddr = start_addr - 0xFFFF_FFFF_0000_0000;
MemoryArea { start_addr, end_addr, phys_start_addr: Some(paddr), flags, name }
}
/*
** @brief create a memory area from physics address
** @param start_addr: PhysAddr the physics address of beginning of the area
@ -298,16 +306,9 @@ impl<T: InactivePageTable> MemorySet<T> {
}
}
pub fn new_bare() -> Self {
info!("new bare");
// TODO
info!("Vec::new begin");
let a = Vec::<MemoryArea>::new();
info!("Vec::new finish");
let pt = T::new_bare();
info!("T::new bare finish");
MemorySet {
areas: a,
page_table: pt,
areas: Vec::<MemoryArea>::new(),
page_table: T::new_bare()
}
}
/*
@ -395,7 +396,6 @@ impl<T: InactivePageTable> Clone for MemorySet<T> {
area.map::<T>(pt);
}
});
info!("finish map in clone!");
MemorySet {
areas: self.areas.clone(),
page_table,
@ -405,7 +405,6 @@ impl<T: InactivePageTable> Clone for MemorySet<T> {
impl<T: InactivePageTable> Drop for MemorySet<T> {
fn drop(&mut self) {
info!("come into drop func for memoryset");
self.clear();
}
}

@ -1 +1 @@
Subproject commit 71d108e50cfa006464782a725621ae760f69f90f
Subproject commit f7bea54d7f254b63b5a6130285ab421c23d2f3bd

View File

@ -25,7 +25,7 @@ if [[ ${RV32} = 1 ]]; then
UCORE_USER_IMAGE="../user/img/ucore-rv32.img"
else
TARGET_ARCH=riscv64
export LOG=warn
export LOG=trace
COMPILER_RT_CFLAGS="-march=rv64ia -mabi=lp64 -O3"
SFSIMG_CFLAGS="-march=rv64ia -mabi=lp64"
RISCV_PK_CONFIGURE_FLAGS="--with-arch=rv64imac --disable-fp-emulation --host=riscv64-unknown-elf"

View File

@ -39,7 +39,6 @@ impl PageTable for ActivePageTable {
let frame = Frame::of_addr(PhysAddr::new(target));
// map the page to the frame using FrameAllocatorForRiscv
// we may need frame allocator to alloc frame for new page table(first/second)
info!("ActivePageTable: calling RecursivePageTable::map_to, va={:x}, pa={:x}, flags={:?}", page.start_address().as_usize(), frame.start_address().as_usize(), flags);
self.0.map_to(page, frame, flags, &mut FrameAllocatorForRiscv).unwrap().flush();
self.get_entry(addr).expect("fail to get entry")
}
@ -212,12 +211,9 @@ const ROOT_PAGE_TABLE: *mut RvPageTable =
impl ActivePageTable {
pub unsafe fn new() -> Self {
// TODO: delete debug code
let rv = ActivePageTable(
RecursivePageTable::new(&mut *ROOT_PAGE_TABLE).unwrap(),
::core::mem::zeroed());
info!("ROOT_PAGE_TABLE: {:x}, ActivePageTable::new.0.pagetable: {:x}",
ROOT_PAGE_TABLE as usize, unsafe { rv.0.root_table as *const _ as usize });
rv
}
@ -231,37 +227,17 @@ impl ActivePageTable {
#[cfg(target_arch = "riscv64")]
fn with_temporary_map(&mut self, frame: &Frame, f: impl FnOnce(&mut ActivePageTable, &mut RvPageTable)) {
// Create a temporary page
info!("enter with_temporary_map");
let page = Page::of_addr(VirtAddr::new(0xffffdeadcafebabe));
info!("translate page begin, self at {:x}, page: {:x} ({:o}, {:o}, {:o}, {:o})",
(self.0.root_table as *const _ as usize),
page.start_address().as_usize(),
page.p4_index(),
page.p3_index(),
page.p2_index(),
page.p1_index() );
info!("self info: recursive_index={:x}",
self.0.recursive_index);
info!("root_table[recursive_index]={:?}",
self.0.root_table[self.0.recursive_index]);
info!("root_table[recursive_index+1]={:?}",
self.0.root_table[self.0.recursive_index+1]);
assert!(self.0.translate_page(page).is_none(), "temporary page is already mapped");
info!("enter with_temporary_map check temporary mapped success");
// Map it to table
self.map(page.start_address().as_usize(), frame.start_address().as_usize());
// TODO: delete debug code
let t: usize = 0xffffdeadcafebabe;
info!("with_temporary_map: {:?}->{:?}, translate result {:?}", frame.start_address(), t, self.0.translate_page(page));
// Call f
let table = unsafe { &mut *(page.start_address().as_usize() as *mut _) };
f(self, table);
// Unmap the page
self.unmap(0xffffdeadcafebabe);
info!("leaving with_temporary_map");
}
#[cfg(target_arch = "riscv32")]
@ -351,19 +327,13 @@ impl InactivePageTable for InactivePageTable0 {
* the inactive page table
*/
fn new_bare() -> Self {
info!("InactivePageTable0:new bare begin");
let frame = Self::alloc_frame().map(|target| Frame::of_addr(PhysAddr::new(target)))
.expect("failed to allocate frame");
info!("new bare before with_temporary_map");
// TODO: delete debug code
let mut at = active_table();
info!("got active table");
at.with_temporary_map(&frame, |_, table: &mut RvPageTable| {
info!("enter closure of with_temporary_map");
table.zero();
table.set_recursive(RECURSIVE_INDEX, frame.clone());
});
info!("new bare after with_temporary_map");
InactivePageTable0 { root_frame: frame }
}
@ -398,6 +368,14 @@ impl InactivePageTable for InactivePageTable0 {
unsafe fn activate(&self) {
let old_frame = satp::read().frame();
let new_frame = self.root_frame.clone();
active_table().with_temporary_map(&new_frame, |_, table: &mut RvPageTable| {
info!("new_frame's pa: {:x}", new_frame.start_address().as_usize());
info!("entry 0o0: {:?}", table[0x0]);
info!("entry 0o774: {:?}", table[0x1fc]);
info!("entry 0o775: {:?}", table[0x1fd]);
info!("entry 0o776: {:?}", table[0x1fe]);
info!("entry 0o777: {:?}", table[0x1ff]);
});
debug!("switch table {:x?} -> {:x?}", old_frame, new_frame);
if old_frame != new_frame {
satp::set(SATP_MODE, 0, new_frame);
@ -494,7 +472,6 @@ impl InactivePageTable0 {
impl Drop for InactivePageTable0 {
fn drop(&mut self) {
info!("PageTable dropping: {:?}", self);
Self::dealloc_frame(self.root_frame.start_address().as_usize());
}
}

View File

@ -68,12 +68,8 @@ pub fn active_table_swap() -> MutexGuard<'static, SwapExt<ActivePageTable, fifo:
*/
pub fn alloc_frame() -> Option<usize> {
// get the real address of the alloc frame
// TODO: delete debug code
info!("alloc_frame");
let mut ret = FRAME_ALLOCATOR.lock();
info!("alloc_frame _2");
let ret = ret.alloc();
info!("alloc_frame _3");
let ret = ret.map(|id| id * PAGE_SIZE + MEMORY_OFFSET);
trace!("Allocate frame: {:x?}", ret);
ret