fix bug in impl Drop for FrameTracker, for the correctly mapping/unmapping display buffer in app
This commit is contained in:
parent
2cbd237260
commit
73fcb72cbb
6 changed files with 16 additions and 5 deletions
|
@ -7,6 +7,7 @@ use lazy_static::*;
|
||||||
|
|
||||||
pub struct FrameTracker {
|
pub struct FrameTracker {
|
||||||
pub ppn: PhysPageNum,
|
pub ppn: PhysPageNum,
|
||||||
|
pub nodrop: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FrameTracker {
|
impl FrameTracker {
|
||||||
|
@ -16,10 +17,10 @@ impl FrameTracker {
|
||||||
for i in bytes_array {
|
for i in bytes_array {
|
||||||
*i = 0;
|
*i = 0;
|
||||||
}
|
}
|
||||||
Self { ppn }
|
Self { ppn, nodrop: false }
|
||||||
}
|
}
|
||||||
pub fn new_nowrite(ppn: PhysPageNum) -> Self {
|
pub fn new_noalloc(ppn: PhysPageNum) -> Self {
|
||||||
Self { ppn }
|
Self { ppn, nodrop: true }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,6 +32,9 @@ 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -290,6 +290,9 @@ impl MapArea {
|
||||||
ppn = frame.ppn;
|
ppn = frame.ppn;
|
||||||
self.data_frames.insert(vpn, frame);
|
self.data_frames.insert(vpn, frame);
|
||||||
}
|
}
|
||||||
|
MapType::Noalloc => {
|
||||||
|
panic!("Noalloc should not be mapped");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
let pte_flags = PTEFlags::from_bits(self.map_perm.bits).unwrap();
|
let pte_flags = PTEFlags::from_bits(self.map_perm.bits).unwrap();
|
||||||
page_table.map(vpn, ppn, pte_flags);
|
page_table.map(vpn, ppn, pte_flags);
|
||||||
|
@ -307,7 +310,7 @@ impl MapArea {
|
||||||
}
|
}
|
||||||
pub fn map_noalloc(&mut self, page_table: &mut PageTable,ppn_range:PPNRange) {
|
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) {
|
for (vpn,ppn) in core::iter::zip(self.vpn_range,ppn_range) {
|
||||||
self.data_frames.insert(vpn, FrameTracker::new_nowrite(ppn));
|
self.data_frames.insert(vpn, FrameTracker::new_noalloc(ppn));
|
||||||
let pte_flags = PTEFlags::from_bits(self.map_perm.bits).unwrap();
|
let pte_flags = PTEFlags::from_bits(self.map_perm.bits).unwrap();
|
||||||
page_table.map(vpn, ppn, pte_flags);
|
page_table.map(vpn, ppn, pte_flags);
|
||||||
}
|
}
|
||||||
|
@ -346,6 +349,7 @@ impl MapArea {
|
||||||
pub enum MapType {
|
pub enum MapType {
|
||||||
Identical,
|
Identical,
|
||||||
Framed,
|
Framed,
|
||||||
|
Noalloc,
|
||||||
}
|
}
|
||||||
|
|
||||||
bitflags! {
|
bitflags! {
|
||||||
|
|
|
@ -22,7 +22,7 @@ pub fn sys_framebuffer() -> isize {
|
||||||
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::Framed,
|
MapType::Noalloc,
|
||||||
MapPermission::R | MapPermission::W | MapPermission::U,
|
MapPermission::R | MapPermission::W | MapPermission::U,
|
||||||
),
|
),
|
||||||
PPNRange::new(fb_ppn, fb_end_ppn),
|
PPNRange::new(fb_ppn, fb_end_ppn),
|
||||||
|
|
|
@ -108,6 +108,7 @@ impl DrawingBoard {
|
||||||
pub fn main() -> i32 {
|
pub fn main() -> i32 {
|
||||||
// let fb_ptr = framebuffer() as *mut u8;
|
// let fb_ptr = framebuffer() as *mut u8;
|
||||||
let mut board = DrawingBoard::new();
|
let mut board = DrawingBoard::new();
|
||||||
|
let _ = board.disp.clear(Rgb888::BLACK).unwrap();
|
||||||
for i in 0..20 {
|
for i in 0..20 {
|
||||||
board.latest_pos.x += i;
|
board.latest_pos.x += i;
|
||||||
board.latest_pos.y += i;
|
board.latest_pos.y += i;
|
||||||
|
|
|
@ -382,6 +382,7 @@ const CR: u8 = 0x0du8;
|
||||||
pub fn main() -> i32 {
|
pub fn main() -> i32 {
|
||||||
let mut disp = Display::new(Size::new(1280, 800), Point::new(0, 0));
|
let mut disp = Display::new(Size::new(1280, 800), Point::new(0, 0));
|
||||||
let mut game = SnakeGame::<20, Rgb888>::new(1280, 800, 20, 20, Rgb888::RED, Rgb888::YELLOW, 50);
|
let mut game = SnakeGame::<20, Rgb888>::new(1280, 800, 20, 20, Rgb888::RED, Rgb888::YELLOW, 50);
|
||||||
|
let _ = disp.clear(Rgb888::BLACK).unwrap();
|
||||||
loop {
|
loop {
|
||||||
if key_pressed() {
|
if key_pressed() {
|
||||||
let c = getchar();
|
let c = getchar();
|
||||||
|
|
|
@ -111,6 +111,7 @@ const CR: u8 = 0x0du8;
|
||||||
pub fn main() -> i32 {
|
pub fn main() -> i32 {
|
||||||
// let fb_ptr = framebuffer() as *mut u8;
|
// let fb_ptr = framebuffer() as *mut u8;
|
||||||
let mut board = DrawingBoard::new();
|
let mut board = DrawingBoard::new();
|
||||||
|
let _ = board.disp.clear(Rgb888::BLACK).unwrap();
|
||||||
for i in 0..20 {
|
for i in 0..20 {
|
||||||
let c=getchar();
|
let c=getchar();
|
||||||
if c == LF || c == CR {
|
if c == LF || c == CR {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue