simple gui app can run now!
This commit is contained in:
parent
944f114cf8
commit
beaef1f304
11 changed files with 119 additions and 3 deletions
|
@ -27,6 +27,10 @@ impl Graphics {
|
|||
let fb = self.drv.get_framebuffer();
|
||||
fb.fill(0u8);
|
||||
}
|
||||
|
||||
pub fn get_framebuffer(&self)-> &mut [u8] {
|
||||
self.drv.get_framebuffer()
|
||||
}
|
||||
}
|
||||
|
||||
impl OriginDimensions for Graphics {
|
||||
|
|
|
@ -260,3 +260,4 @@ where
|
|||
}
|
||||
}
|
||||
pub type VPNRange = SimpleRange<VirtPageNum>;
|
||||
pub type PPNRange = SimpleRange<PhysPageNum>;
|
||||
|
|
|
@ -18,6 +18,9 @@ impl FrameTracker {
|
|||
}
|
||||
Self { ppn }
|
||||
}
|
||||
pub fn new_nowrite(ppn: PhysPageNum) -> Self {
|
||||
Self { ppn }
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for FrameTracker {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use super::{frame_alloc, FrameTracker};
|
||||
use super::{PTEFlags, PageTable, PageTableEntry};
|
||||
use super::{PhysAddr, PhysPageNum, VirtAddr, VirtPageNum};
|
||||
use super::{StepByOne, VPNRange};
|
||||
use super::{StepByOne, VPNRange, PPNRange};
|
||||
use crate::config::{MEMORY_END, MMIO, PAGE_SIZE, TRAMPOLINE};
|
||||
use crate::sync::UPIntrFreeCell;
|
||||
use alloc::collections::BTreeMap;
|
||||
|
@ -78,6 +78,10 @@ impl MemorySet {
|
|||
}
|
||||
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.
|
||||
fn map_trampoline(&mut self) {
|
||||
self.page_table.map(
|
||||
|
@ -301,6 +305,14 @@ impl MapArea {
|
|||
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_nowrite(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) {
|
||||
for vpn in self.vpn_range {
|
||||
self.unmap_one(page_table, vpn);
|
||||
|
|
|
@ -4,11 +4,11 @@ mod heap_allocator;
|
|||
mod memory_set;
|
||||
mod page_table;
|
||||
|
||||
use address::VPNRange;
|
||||
pub use address::{VPNRange, PPNRange};
|
||||
pub use address::{PhysAddr, PhysPageNum, StepByOne, VirtAddr, VirtPageNum};
|
||||
pub use frame_allocator::{frame_alloc, frame_dealloc, FrameTracker};
|
||||
pub use memory_set::remap_test;
|
||||
pub use memory_set::{kernel_token, MapPermission, MemorySet, KERNEL_SPACE};
|
||||
pub use memory_set::{kernel_token, MapPermission, MemorySet, MapArea, MapType, KERNEL_SPACE};
|
||||
use page_table::PTEFlags;
|
||||
pub use page_table::{
|
||||
translated_byte_buffer, translated_ref, translated_refmut, translated_str, PageTable,
|
||||
|
|
37
os/src/syscall/gui.rs
Normal file
37
os/src/syscall/gui.rs
Normal file
|
@ -0,0 +1,37 @@
|
|||
use crate::mm::{MapArea, MapPermission, MapType, PPNRange, PhysAddr};
|
||||
use crate::task::current_process;
|
||||
|
||||
//use crate::gui::*;
|
||||
use crate::drivers::GPU_DEVICE;
|
||||
|
||||
const FB_VADDR: usize = 0x10000000;
|
||||
|
||||
pub fn sys_framebuffer() -> isize {
|
||||
let gpu = GPU_DEVICE.clone();
|
||||
let fb = gpu.get_framebuffer();
|
||||
let len = fb.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_end_ppn = PhysAddr::from(fb.as_ptr() as usize + len).ceil();
|
||||
|
||||
let current_process = current_process();
|
||||
let mut inner = current_process.inner_exclusive_access();
|
||||
let mem_set = &mut inner.memory_set;
|
||||
|
||||
mem_set.push_noalloc(
|
||||
MapArea::new(
|
||||
(FB_VADDR as usize).into(),
|
||||
(FB_VADDR + len as usize).into(),
|
||||
MapType::Framed,
|
||||
MapPermission::R | MapPermission::W | MapPermission::U,
|
||||
),
|
||||
PPNRange::new(fb_ppn, fb_end_ppn),
|
||||
);
|
||||
FB_VADDR as isize
|
||||
}
|
||||
|
||||
pub fn sys_framebuffer_flush() -> isize {
|
||||
let gpu = GPU_DEVICE.clone();
|
||||
gpu.flush();
|
||||
0
|
||||
}
|
|
@ -25,16 +25,20 @@ const SYSCALL_SEMAPHORE_DOWN: usize = 1022;
|
|||
const SYSCALL_CONDVAR_CREATE: usize = 1030;
|
||||
const SYSCALL_CONDVAR_SIGNAL: usize = 1031;
|
||||
const SYSCALL_CONDVAR_WAIT: usize = 1032;
|
||||
const SYSCALL_FRAMEBUFFER: usize = 2000;
|
||||
const SYSCALL_FRAMEBUFFER_FLUSH: usize = 2001;
|
||||
|
||||
mod fs;
|
||||
mod process;
|
||||
mod sync;
|
||||
mod thread;
|
||||
mod gui;
|
||||
|
||||
use fs::*;
|
||||
use process::*;
|
||||
use sync::*;
|
||||
use thread::*;
|
||||
use gui::*;
|
||||
|
||||
pub fn syscall(syscall_id: usize, args: [usize; 3]) -> isize {
|
||||
match syscall_id {
|
||||
|
@ -65,6 +69,8 @@ pub fn syscall(syscall_id: usize, args: [usize; 3]) -> isize {
|
|||
SYSCALL_CONDVAR_CREATE => sys_condvar_create(args[0]),
|
||||
SYSCALL_CONDVAR_SIGNAL => sys_condvar_signal(args[0]),
|
||||
SYSCALL_CONDVAR_WAIT => sys_condvar_wait(args[0], args[1]),
|
||||
SYSCALL_FRAMEBUFFER => sys_framebuffer(),
|
||||
SYSCALL_FRAMEBUFFER_FLUSH => sys_framebuffer_flush(),
|
||||
_ => panic!("Unsupported syscall_id: {}", syscall_id),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue