diff --git a/moon/src/init.rs b/moon/src/init.rs index dea50760..d222ef88 100644 --- a/moon/src/init.rs +++ b/moon/src/init.rs @@ -4,13 +4,13 @@ use crate::util::get_bootboot; use crate::arch::cpu; pub fn halt_other_cores() -> () { - let boot: BOOTBOOT = get_bootboot(); + let boot: &BOOTBOOT = get_bootboot(); if cpu::get_processor_id() != boot.bspid as u32 { cpu::halt(); } } pub fn check_magic() -> () { - let boot: BOOTBOOT = get_bootboot(); + let boot: &BOOTBOOT = get_bootboot(); assert_eq!(boot.magic, BOOTBOOT_MAGIC[..4]); } \ No newline at end of file diff --git a/moon/src/util.rs b/moon/src/util.rs index 0757e313..23b520d5 100644 --- a/moon/src/util.rs +++ b/moon/src/util.rs @@ -1,5 +1,5 @@ use crate::bootboot::{BOOTBOOT, BOOTBOOT_INFO}; -pub fn get_bootboot() -> BOOTBOOT { - return unsafe { *(BOOTBOOT_INFO as *const BOOTBOOT) } +pub fn get_bootboot() -> &'static BOOTBOOT { + return unsafe { & *(BOOTBOOT_INFO as *const BOOTBOOT) } } \ No newline at end of file diff --git a/moon/src/video.rs b/moon/src/video.rs index 2570416e..8648b1ec 100644 --- a/moon/src/video.rs +++ b/moon/src/video.rs @@ -39,7 +39,7 @@ impl Color { bswap(self as u32) } - fn to_layout(self, layout: u32) -> u32 { + fn to_data_layout(self, layout: u32) -> u32 { match layout { FB_ARGB => self.to_argb(), FB_BGRA => self.to_bgra(), @@ -49,24 +49,25 @@ impl Color { } pub fn put_pixel(x: u32, y: u32, color: Color) -> () { - let boot: BOOTBOOT = get_bootboot(); + let boot: &BOOTBOOT = get_bootboot(); let ptr: u64 = FB + (boot.fb_scanline * y) as u64 + (x * 4) as u64; - unsafe { *(ptr as *mut u32) = color.to_layout(boot.fb_type as u32) }; + unsafe { *(ptr as *mut u32) = color.to_data_layout(boot.fb_type as u32) }; } pub fn draw_rect(x: u32, y: u32, width: u32, height: u32, color: Color) -> () { - let boot: BOOTBOOT = get_bootboot(); + let boot: &BOOTBOOT = get_bootboot(); + let col: u32 = color.to_data_layout(boot.fb_type as u32); for i in y..(y + height) { let addr: u64 = FB + (boot.fb_scanline * i) as u64 + (x * 4) as u64; for ptr in (addr..(addr + (width*4) as u64)).step_by(4) { - unsafe { *(ptr as *mut u32) = color.to_layout(boot.fb_type as u32) }; + unsafe { *(ptr as *mut u32) = col }; } } } pub fn clear(color: Color) -> () { - let boot: BOOTBOOT = get_bootboot(); + let boot: &BOOTBOOT = get_bootboot(); draw_rect(0, 0, boot.fb_width, boot.fb_height, color) } \ No newline at end of file