diff --git a/kernel/src/drivers/gpu/fb.rs b/kernel/src/drivers/gpu/fb.rs index 1939b901..de278afd 100644 --- a/kernel/src/drivers/gpu/fb.rs +++ b/kernel/src/drivers/gpu/fb.rs @@ -173,6 +173,11 @@ impl Framebuffer { unsafe { self.buf.base_addr } } + #[inline] + pub fn framebuffer_size(&self) -> usize { + self.fb_info.screen_size as usize + } + #[inline] pub fn bus_addr(&self) -> usize { self.fb_info.bus_addr as usize diff --git a/kernel/src/fs/file.rs b/kernel/src/fs/file.rs index b5429e63..db4f84e8 100644 --- a/kernel/src/fs/file.rs +++ b/kernel/src/fs/file.rs @@ -1,8 +1,8 @@ //! File handle for process +use crate::thread; use alloc::{string::String, sync::Arc}; use core::fmt; -use crate::thread; use rcore_fs::vfs::{FsError, INode, Metadata, PollStatus, Result}; diff --git a/kernel/src/fs/vga.rs b/kernel/src/fs/vga.rs index 3f34116f..95b03859 100755 --- a/kernel/src/fs/vga.rs +++ b/kernel/src/fs/vga.rs @@ -31,15 +31,20 @@ impl INode for Vga { } fn write_at(&self, _offset: usize, _buf: &[u8]) -> Result { info!("the _offset is {} {}", _offset, _buf[0]); - use core::slice; - let frame_buffer_data = unsafe { - slice::from_raw_parts_mut( - phys_to_virt(0xfd00_0000) as *mut u8, - (1024 * 768 * 3) as usize, - ) - }; - frame_buffer_data.copy_from_slice(&_buf); - return Ok(1024 * 768 * 3); + let lock = FRAME_BUFFER.lock(); + if let Some(ref frame_buffer) = *lock { + use core::slice; + let frame_buffer_data = unsafe { + slice::from_raw_parts_mut( + frame_buffer.base_addr() as *mut u8, + frame_buffer.framebuffer_size(), + ) + }; + frame_buffer_data.copy_from_slice(&_buf); + Ok(frame_buffer.framebuffer_size()) + } else { + Err(FsError::EntryNotFound) + } } fn poll(&self) -> Result { Ok(PollStatus {