Skip to content
Snippets Groups Projects
Commit b89b19ab authored by Eemeli's avatar Eemeli
Browse files

framebuffer initial clear

parent 8c443eb7
Branches
No related tags found
No related merge requests found
#[derive(Debug, Clone, Copy)]
pub struct FramebufferCreateInfo {
pub buf: &'static mut [u8],
pub buf: *mut [u8],
pub width: usize,
pub height: usize,
pub pitch: usize,
}
unsafe impl Sync for FramebufferCreateInfo {}
unsafe impl Send for FramebufferCreateInfo {}
impl FramebufferCreateInfo {
/// # Safety
/// this is not synchronized between copies of [`FramebufferCreateInfo`]
pub unsafe fn buf_mut(&mut self) -> &'static mut [u8] {
unsafe { &mut *self.buf }
}
}
use core::slice;
use core::ptr;
use hyperion_boot_interface::FramebufferCreateInfo;
use limine::FramebufferRequest;
use spin::Once;
//
pub fn framebuffer() -> Option<FramebufferCreateInfo> {
static FB_INFO: Once<Option<FramebufferCreateInfo>> = Once::new();
static FB_REQ: FramebufferRequest = FramebufferRequest::new(0);
*FB_INFO.call_once(|| {
FB_REQ
.get_response()
.get()
......@@ -15,8 +18,7 @@ pub fn framebuffer() -> Option<FramebufferCreateInfo> {
.flat_map(|resp| resp.framebuffers().iter())
.filter(|fb| fb.bpp == 32)
.find_map(|fb| {
let buf = unsafe { slice::from_raw_parts_mut(fb.address.as_ptr()?, fb.size()) };
let buf = ptr::slice_from_raw_parts_mut(fb.address.as_ptr()?, fb.size());
Some(FramebufferCreateInfo {
buf,
width: fb.width as _,
......@@ -24,4 +26,13 @@ pub fn framebuffer() -> Option<FramebufferCreateInfo> {
pitch: fb.pitch as _,
})
})
})
}
pub fn init_fb() {
if let Some(mut fb) = framebuffer() {
let buf = unsafe { fb.buf_mut() };
buf.fill(b'0');
}
}
......@@ -4,7 +4,7 @@
pub use addr::{hhdm_offset, phys_addr, size, virt_addr};
pub use cmdline::cmdline;
pub use framebuffer::framebuffer;
pub use framebuffer::{framebuffer, init_fb};
pub use kernel::kernel_file;
pub use mem::memmap;
pub use rsdp::rsdp;
......
......@@ -45,14 +45,14 @@ impl Framebuffer {
static FBO: Once<Option<Mutex<Framebuffer>>> = Once::new();
FBO.call_once(|| {
let FramebufferCreateInfo {
buf,
let mut fb @ FramebufferCreateInfo {
width,
height,
pitch,
..
} = hyperion_boot::framebuffer()?;
let mut fbo = Framebuffer::new(
buf,
unsafe { fb.buf_mut() },
FramebufferInfo {
width,
height,
......
......@@ -43,6 +43,8 @@ static ALLOCATOR: KernelSlabAlloc<spin::Mutex<()>> = KernelSlabAlloc::new();
#[no_mangle]
extern "C" fn _start() -> ! {
hyperion_boot::init_fb();
if sync::once!() {
// enable logging and and outputs based on the kernel args,
// any logging before won't be shown
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment