Kernel: Make get_bootboot return a reference to avoid continuously copying data
This commit is contained in:
parent
75219763da
commit
6a41c4fc4e
@ -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]);
|
||||
}
|
@ -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) }
|
||||
}
|
@ -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)
|
||||
}
|
Loading…
Reference in New Issue
Block a user