Fix virtio_phys_to_virt. Now we can load app from disk on qemu/k210!

This commit is contained in:
Yifan Wu 2020-12-20 08:46:27 +08:00
parent ae9eecf97b
commit 1bafe9615f
3 changed files with 10 additions and 7 deletions

View File

@ -7,6 +7,8 @@ use crate::mm::{
PhysPageNum,
FrameTracker,
StepByOne,
PageTable,
kernel_token,
};
use super::BlockDevice;
use spin::Mutex;
@ -23,12 +25,9 @@ lazy_static! {
impl BlockDevice for VirtIOBlock {
fn read_block(&self, block_id: usize, buf: &mut [u8]) {
//println!("read block {}", block_id);
self.0.lock().read_block(block_id, buf).expect("Error when reading VirtIOBlk");
//println!("read block OK!");
}
fn write_block(&self, block_id: usize, buf: &[u8]) {
//println!("write block {}", block_id);
self.0.lock().write_block(block_id, buf).expect("Error when writing VirtIOBlk");
}
}
@ -47,7 +46,6 @@ pub extern "C" fn virtio_dma_alloc(pages: usize) -> PhysAddr {
for i in 0..pages {
let frame = frame_alloc().unwrap();
if i == 0 { ppn_base = frame.ppn; }
println!("virtio_dma_alloc {:?}", frame.ppn);
assert_eq!(frame.ppn.0, ppn_base.0 + i);
QUEUE_FRAMES.lock().push(frame);
}
@ -71,5 +69,5 @@ pub extern "C" fn virtio_phys_to_virt(paddr: PhysAddr) -> VirtAddr {
#[no_mangle]
pub extern "C" fn virtio_virt_to_phys(vaddr: VirtAddr) -> PhysAddr {
PhysAddr(vaddr.0)
PageTable::from_token(kernel_token()).translate_va(vaddr).unwrap()
}

View File

@ -36,6 +36,10 @@ lazy_static! {
));
}
pub fn kernel_token() -> usize {
KERNEL_SPACE.lock().token()
}
pub struct MemorySet {
page_table: PageTable,
areas: Vec<MapArea>,

View File

@ -4,11 +4,12 @@ mod frame_allocator;
mod page_table;
mod memory_set;
use page_table::{PageTable, PTEFlags};
use page_table::PTEFlags;
use address::VPNRange;
pub use address::{PhysAddr, VirtAddr, PhysPageNum, VirtPageNum, StepByOne};
pub use frame_allocator::{FrameTracker, frame_alloc, frame_dealloc,};
pub use page_table::{
PageTable,
PageTableEntry,
translated_byte_buffer,
translated_str,
@ -16,7 +17,7 @@ pub use page_table::{
UserBuffer,
UserBufferIterator,
};
pub use memory_set::{MemorySet, KERNEL_SPACE, MapPermission};
pub use memory_set::{MemorySet, KERNEL_SPACE, MapPermission, kernel_token};
pub use memory_set::remap_test;
pub fn init() {