mirror of
https://github.com/rcore-os/rCore-Tutorial-v3.git
synced 2024-11-25 02:46:23 +04:00
Added MapType::Linear for framebuffer mapping & cargo fmt
This commit is contained in:
parent
7f04d674ca
commit
b77f2d6999
@ -143,12 +143,13 @@ impl<const BASE_ADDR: usize> NS16550a<BASE_ADDR> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn read_buffer_is_empty(&self) -> bool {
|
pub fn read_buffer_is_empty(&self) -> bool {
|
||||||
self.inner.exclusive_session(|inner| inner.read_buffer.is_empty())
|
self.inner
|
||||||
|
.exclusive_session(|inner| inner.read_buffer.is_empty())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<const BASE_ADDR: usize> CharDevice for NS16550a<BASE_ADDR> {
|
impl<const BASE_ADDR: usize> CharDevice for NS16550a<BASE_ADDR> {
|
||||||
fn init(&self){
|
fn init(&self) {
|
||||||
let mut inner = self.inner.exclusive_access();
|
let mut inner = self.inner.exclusive_access();
|
||||||
inner.ns16550a.init();
|
inner.ns16550a.init();
|
||||||
drop(inner);
|
drop(inner);
|
||||||
|
@ -18,7 +18,7 @@ struct VirtIOInputWrapper {
|
|||||||
inner: UPIntrFreeCell<VirtIOInputInner>,
|
inner: UPIntrFreeCell<VirtIOInputInner>,
|
||||||
//condvars: BTreeMap<u16, Condvar>,
|
//condvars: BTreeMap<u16, Condvar>,
|
||||||
//condvar: Arc::<Condvar> ,
|
//condvar: Arc::<Condvar> ,
|
||||||
condvar:Condvar,
|
condvar: Condvar,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait InputDevice: Send + Sync + Any {
|
pub trait InputDevice: Send + Sync + Any {
|
||||||
@ -38,7 +38,7 @@ lazy_static::lazy_static!(
|
|||||||
//const QUEUE_SIZE: u16 = 32;
|
//const QUEUE_SIZE: u16 = 32;
|
||||||
// pub fn read_input_event() -> u64 {
|
// pub fn read_input_event() -> u64 {
|
||||||
// loop {
|
// loop {
|
||||||
|
|
||||||
// //let mut inner = self.inner.exclusive_access();
|
// //let mut inner = self.inner.exclusive_access();
|
||||||
// let kb=KEYBOARD_DEVICE.clone();
|
// let kb=KEYBOARD_DEVICE.clone();
|
||||||
// let evs = kb.events();
|
// let evs = kb.events();
|
||||||
|
@ -170,4 +170,4 @@ impl File for Pipe {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,6 @@ pub fn rust_main() -> ! {
|
|||||||
timer::set_next_trigger();
|
timer::set_next_trigger();
|
||||||
board::device_init();
|
board::device_init();
|
||||||
fs::list_apps();
|
fs::list_apps();
|
||||||
//gui::init_paint();
|
|
||||||
task::add_initproc();
|
task::add_initproc();
|
||||||
*DEV_NON_BLOCKING_ACCESS.exclusive_access() = true;
|
*DEV_NON_BLOCKING_ACCESS.exclusive_access() = true;
|
||||||
task::run_tasks();
|
task::run_tasks();
|
||||||
|
@ -260,4 +260,3 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub type VPNRange = SimpleRange<VirtPageNum>;
|
pub type VPNRange = SimpleRange<VirtPageNum>;
|
||||||
pub type PPNRange = SimpleRange<PhysPageNum>;
|
|
||||||
|
@ -7,7 +7,6 @@ use lazy_static::*;
|
|||||||
|
|
||||||
pub struct FrameTracker {
|
pub struct FrameTracker {
|
||||||
pub ppn: PhysPageNum,
|
pub ppn: PhysPageNum,
|
||||||
pub nodrop: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FrameTracker {
|
impl FrameTracker {
|
||||||
@ -17,10 +16,7 @@ impl FrameTracker {
|
|||||||
for i in bytes_array {
|
for i in bytes_array {
|
||||||
*i = 0;
|
*i = 0;
|
||||||
}
|
}
|
||||||
Self { ppn, nodrop: false }
|
Self { ppn }
|
||||||
}
|
|
||||||
pub fn new_noalloc(ppn: PhysPageNum) -> Self {
|
|
||||||
Self { ppn, nodrop: true }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,9 +28,6 @@ impl Debug for FrameTracker {
|
|||||||
|
|
||||||
impl Drop for FrameTracker {
|
impl Drop for FrameTracker {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
if self.nodrop {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
frame_dealloc(self.ppn);
|
frame_dealloc(self.ppn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use super::{frame_alloc, FrameTracker};
|
use super::{frame_alloc, FrameTracker};
|
||||||
use super::{PTEFlags, PageTable, PageTableEntry};
|
use super::{PTEFlags, PageTable, PageTableEntry};
|
||||||
use super::{PhysAddr, PhysPageNum, VirtAddr, VirtPageNum};
|
use super::{PhysAddr, PhysPageNum, VirtAddr, VirtPageNum};
|
||||||
use super::{StepByOne, VPNRange, PPNRange};
|
use super::{StepByOne, VPNRange};
|
||||||
use crate::config::{MEMORY_END, MMIO, PAGE_SIZE, TRAMPOLINE};
|
use crate::config::{MEMORY_END, MMIO, PAGE_SIZE, TRAMPOLINE};
|
||||||
use crate::sync::UPIntrFreeCell;
|
use crate::sync::UPIntrFreeCell;
|
||||||
use alloc::collections::BTreeMap;
|
use alloc::collections::BTreeMap;
|
||||||
@ -71,17 +71,16 @@ impl MemorySet {
|
|||||||
self.areas.remove(idx);
|
self.areas.remove(idx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn push(&mut self, mut map_area: MapArea, data: Option<&[u8]>) {
|
/// Add a new MapArea into this MemorySet.
|
||||||
|
/// Assuming that there are no conflicts in the virtual address
|
||||||
|
/// space.
|
||||||
|
pub fn push(&mut self, mut map_area: MapArea, data: Option<&[u8]>) {
|
||||||
map_area.map(&mut self.page_table);
|
map_area.map(&mut self.page_table);
|
||||||
if let Some(data) = data {
|
if let Some(data) = data {
|
||||||
map_area.copy_data(&mut self.page_table, data);
|
map_area.copy_data(&mut self.page_table, data);
|
||||||
}
|
}
|
||||||
self.areas.push(map_area);
|
self.areas.push(map_area);
|
||||||
}
|
}
|
||||||
pub fn push_noalloc(&mut self, mut map_area: MapArea, ppn_range: PPNRange) {
|
|
||||||
map_area.map_noalloc(&mut self.page_table, ppn_range);
|
|
||||||
self.areas.push(map_area);
|
|
||||||
}
|
|
||||||
/// Mention that trampoline is not collected by areas.
|
/// Mention that trampoline is not collected by areas.
|
||||||
fn map_trampoline(&mut self) {
|
fn map_trampoline(&mut self) {
|
||||||
self.page_table.map(
|
self.page_table.map(
|
||||||
@ -290,8 +289,10 @@ impl MapArea {
|
|||||||
ppn = frame.ppn;
|
ppn = frame.ppn;
|
||||||
self.data_frames.insert(vpn, frame);
|
self.data_frames.insert(vpn, frame);
|
||||||
}
|
}
|
||||||
MapType::Noalloc => {
|
MapType::Linear(pn_offset) => {
|
||||||
panic!("Noalloc should not be mapped");
|
// check for sv39
|
||||||
|
assert!(vpn.0 < (1usize << 27));
|
||||||
|
ppn = PhysPageNum((vpn.0 as isize + pn_offset) as usize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let pte_flags = PTEFlags::from_bits(self.map_perm.bits).unwrap();
|
let pte_flags = PTEFlags::from_bits(self.map_perm.bits).unwrap();
|
||||||
@ -308,14 +309,6 @@ impl MapArea {
|
|||||||
self.map_one(page_table, vpn);
|
self.map_one(page_table, vpn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn map_noalloc(&mut self, page_table: &mut PageTable,ppn_range:PPNRange) {
|
|
||||||
for (vpn,ppn) in core::iter::zip(self.vpn_range,ppn_range) {
|
|
||||||
self.data_frames.insert(vpn, FrameTracker::new_noalloc(ppn));
|
|
||||||
let pte_flags = PTEFlags::from_bits(self.map_perm.bits).unwrap();
|
|
||||||
page_table.map(vpn, ppn, pte_flags);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn unmap(&mut self, page_table: &mut PageTable) {
|
pub fn unmap(&mut self, page_table: &mut PageTable) {
|
||||||
for vpn in self.vpn_range {
|
for vpn in self.vpn_range {
|
||||||
self.unmap_one(page_table, vpn);
|
self.unmap_one(page_table, vpn);
|
||||||
@ -349,7 +342,8 @@ impl MapArea {
|
|||||||
pub enum MapType {
|
pub enum MapType {
|
||||||
Identical,
|
Identical,
|
||||||
Framed,
|
Framed,
|
||||||
Noalloc,
|
/// offset of page num
|
||||||
|
Linear(isize),
|
||||||
}
|
}
|
||||||
|
|
||||||
bitflags! {
|
bitflags! {
|
||||||
|
@ -4,11 +4,11 @@ mod heap_allocator;
|
|||||||
mod memory_set;
|
mod memory_set;
|
||||||
mod page_table;
|
mod page_table;
|
||||||
|
|
||||||
pub use address::{VPNRange, PPNRange};
|
pub use address::VPNRange;
|
||||||
pub use address::{PhysAddr, PhysPageNum, StepByOne, VirtAddr, VirtPageNum};
|
pub use address::{PhysAddr, PhysPageNum, StepByOne, VirtAddr, VirtPageNum};
|
||||||
pub use frame_allocator::{frame_alloc, frame_dealloc, FrameTracker};
|
pub use frame_allocator::{frame_alloc, frame_dealloc, FrameTracker};
|
||||||
pub use memory_set::remap_test;
|
pub use memory_set::remap_test;
|
||||||
pub use memory_set::{kernel_token, MapPermission, MemorySet, MapArea, MapType, KERNEL_SPACE};
|
pub use memory_set::{kernel_token, MapArea, MapPermission, MapType, MemorySet, KERNEL_SPACE};
|
||||||
use page_table::PTEFlags;
|
use page_table::PTEFlags;
|
||||||
pub use page_table::{
|
pub use page_table::{
|
||||||
translated_byte_buffer, translated_ref, translated_refmut, translated_str, PageTable,
|
translated_byte_buffer, translated_ref, translated_refmut, translated_str, PageTable,
|
||||||
|
@ -96,4 +96,4 @@ pub fn sys_dup(fd: usize) -> isize {
|
|||||||
let new_fd = inner.alloc_fd();
|
let new_fd = inner.alloc_fd();
|
||||||
inner.fd_table[new_fd] = Some(Arc::clone(inner.fd_table[fd].as_ref().unwrap()));
|
inner.fd_table[new_fd] = Some(Arc::clone(inner.fd_table[fd].as_ref().unwrap()));
|
||||||
new_fd as isize
|
new_fd as isize
|
||||||
}
|
}
|
||||||
|
@ -1,37 +1,34 @@
|
|||||||
use crate::mm::{MapArea, MapPermission, MapType, PPNRange, PhysAddr};
|
|
||||||
use crate::task::current_process;
|
|
||||||
|
|
||||||
//use crate::gui::*;
|
|
||||||
use crate::drivers::GPU_DEVICE;
|
use crate::drivers::GPU_DEVICE;
|
||||||
|
use crate::mm::{MapArea, MapPermission, MapType, PhysAddr, VirtAddr};
|
||||||
|
use crate::task::current_process;
|
||||||
|
|
||||||
const FB_VADDR: usize = 0x10000000;
|
const FB_VADDR: usize = 0x10000000;
|
||||||
|
|
||||||
pub fn sys_framebuffer() -> isize {
|
pub fn sys_framebuffer() -> isize {
|
||||||
let gpu = GPU_DEVICE.clone();
|
let fb = GPU_DEVICE.get_framebuffer();
|
||||||
let fb = gpu.get_framebuffer();
|
|
||||||
let len = fb.len();
|
let len = fb.len();
|
||||||
println!("[kernel] FrameBuffer: addr 0x{:X}, len {}", fb.as_ptr() as usize , len);
|
// println!("[kernel] FrameBuffer: addr 0x{:X}, len {}", fb.as_ptr() as usize , len);
|
||||||
let fb_ppn = PhysAddr::from(fb.as_ptr() as usize).floor();
|
let fb_start_pa = PhysAddr::from(fb.as_ptr() as usize);
|
||||||
let fb_end_ppn = PhysAddr::from(fb.as_ptr() as usize + len).ceil();
|
assert!(fb_start_pa.aligned());
|
||||||
|
let fb_start_ppn = fb_start_pa.floor();
|
||||||
|
let fb_start_vpn = VirtAddr::from(FB_VADDR).floor();
|
||||||
|
let pn_offset = fb_start_ppn.0 as isize - fb_start_vpn.0 as isize;
|
||||||
|
|
||||||
let current_process = current_process();
|
let current_process = current_process();
|
||||||
let mut inner = current_process.inner_exclusive_access();
|
let mut inner = current_process.inner_exclusive_access();
|
||||||
let mem_set = &mut inner.memory_set;
|
inner.memory_set.push(
|
||||||
|
|
||||||
mem_set.push_noalloc(
|
|
||||||
MapArea::new(
|
MapArea::new(
|
||||||
(FB_VADDR as usize).into(),
|
(FB_VADDR as usize).into(),
|
||||||
(FB_VADDR + len as usize).into(),
|
(FB_VADDR + len as usize).into(),
|
||||||
MapType::Noalloc,
|
MapType::Linear(pn_offset),
|
||||||
MapPermission::R | MapPermission::W | MapPermission::U,
|
MapPermission::R | MapPermission::W | MapPermission::U,
|
||||||
),
|
),
|
||||||
PPNRange::new(fb_ppn, fb_end_ppn),
|
None,
|
||||||
);
|
);
|
||||||
FB_VADDR as isize
|
FB_VADDR as isize
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn sys_framebuffer_flush() -> isize {
|
pub fn sys_framebuffer_flush() -> isize {
|
||||||
let gpu = GPU_DEVICE.clone();
|
GPU_DEVICE.flush();
|
||||||
gpu.flush();
|
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
|
@ -1,29 +1,28 @@
|
|||||||
//use crate::drivers::{KEYBOARD_DEVICE,MOUSE_DEVICE,INPUT_CONDVAR,read_input_event};
|
//use crate::drivers::{KEYBOARD_DEVICE,MOUSE_DEVICE,INPUT_CONDVAR,read_input_event};
|
||||||
use crate::drivers::{KEYBOARD_DEVICE,MOUSE_DEVICE};
|
use crate::drivers::{KEYBOARD_DEVICE, MOUSE_DEVICE};
|
||||||
|
|
||||||
pub fn sys_event_get() ->isize {
|
pub fn sys_event_get() -> isize {
|
||||||
let kb = KEYBOARD_DEVICE.clone();
|
let kb = KEYBOARD_DEVICE.clone();
|
||||||
let mouse = MOUSE_DEVICE.clone();
|
let mouse = MOUSE_DEVICE.clone();
|
||||||
//let input=INPUT_CONDVAR.clone();
|
//let input=INPUT_CONDVAR.clone();
|
||||||
//read_input_event() as isize
|
//read_input_event() as isize
|
||||||
if !kb.is_empty(){
|
if !kb.is_empty() {
|
||||||
kb.read_event() as isize
|
kb.read_event() as isize
|
||||||
} else if !mouse.is_empty() {
|
} else if !mouse.is_empty() {
|
||||||
mouse.read_event() as isize
|
mouse.read_event() as isize
|
||||||
} else {
|
} else {
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
use crate::drivers::chardev::UART;
|
use crate::drivers::chardev::UART;
|
||||||
|
|
||||||
/// check UART's read-buffer is empty or not
|
/// check UART's read-buffer is empty or not
|
||||||
pub fn sys_key_pressed() -> isize {
|
pub fn sys_key_pressed() -> isize {
|
||||||
let res =!UART.read_buffer_is_empty();
|
let res = !UART.read_buffer_is_empty();
|
||||||
if res {
|
if res {
|
||||||
1
|
1
|
||||||
} else {
|
} else {
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,18 +31,18 @@ const SYSCALL_EVENT_GET: usize = 3000;
|
|||||||
const SYSCALL_KEY_PRESSED: usize = 3001;
|
const SYSCALL_KEY_PRESSED: usize = 3001;
|
||||||
|
|
||||||
mod fs;
|
mod fs;
|
||||||
|
mod gui;
|
||||||
|
mod input;
|
||||||
mod process;
|
mod process;
|
||||||
mod sync;
|
mod sync;
|
||||||
mod thread;
|
mod thread;
|
||||||
mod gui;
|
|
||||||
mod input;
|
|
||||||
|
|
||||||
use fs::*;
|
use fs::*;
|
||||||
|
use gui::*;
|
||||||
|
use input::*;
|
||||||
use process::*;
|
use process::*;
|
||||||
use sync::*;
|
use sync::*;
|
||||||
use thread::*;
|
use thread::*;
|
||||||
use gui::*;
|
|
||||||
use input::*;
|
|
||||||
|
|
||||||
pub fn syscall(syscall_id: usize, args: [usize; 3]) -> isize {
|
pub fn syscall(syscall_id: usize, args: [usize; 3]) -> isize {
|
||||||
match syscall_id {
|
match syscall_id {
|
||||||
|
Loading…
Reference in New Issue
Block a user