From 77e6f29568558a94065c41e094ba5eb62c89e6ef Mon Sep 17 00:00:00 2001 From: Able Date: Thu, 17 Feb 2022 03:26:05 -0600 Subject: [PATCH] mp work --- ableos/src/arch/uefi_86/mod.rs | 95 +++++++--------------------------- ableos/src/graphics_api/mod.rs | 4 -- ableos/src/kmain.rs | 2 +- repbuild/src/main.rs | 2 +- 4 files changed, 20 insertions(+), 83 deletions(-) diff --git a/ableos/src/arch/uefi_86/mod.rs b/ableos/src/arch/uefi_86/mod.rs index ecf919e..138bcec 100644 --- a/ableos/src/arch/uefi_86/mod.rs +++ b/ableos/src/arch/uefi_86/mod.rs @@ -7,10 +7,16 @@ pub fn shutdown() { pub fn sloop() -> ! { loop {} } +use core::{ffi::c_void, sync::atomic::AtomicUsize, time::Duration}; + use crate::kmain::kernel_main; + use uefi::{ prelude::*, - proto::console::gop::{GraphicsOutput, PixelFormat}, + proto::{ + console::gop::{GraphicsOutput, PixelFormat}, + pi::mp::MpServices, + }, }; use uefi::{proto::console::gop::FrameBuffer, ResultExt}; @@ -56,10 +62,9 @@ fn main(_handle: Handle, mut system_table: SystemTable) -> Status { .expect_success("Failed to set graphics mode"); let mut fb_1 = FrameBuffWrap::new(gop); - loop { - for x in 0..100 { - fb_1.draw_pixel(x, 400, [123, 123, 123]); - } + + for x in 0..100 { + fb_1.draw_pixel(x, 400, [123, 123, 123]); } } else { // No tests can be run. @@ -67,87 +72,23 @@ fn main(_handle: Handle, mut system_table: SystemTable) -> Status { } use uefi::proto::pi::mp::MpServices; - if let Ok(mp) = system_table.boot_services().locate_protocol::() { - let mp = mp.expect("Warnings encountered while opening GOP"); - let mp = unsafe { &mut *mp.get() }; - info!("Found MP Services"); - // info!("{:?}", mp.get_number_of_processors().unwrap_success()); - // info!("{:?}", mp.get_processor_info(0).unwrap_success()); + if let Ok(mp_support) = system_table.boot_services().locate_protocol::() { + let mp_support = mp_support + .expect("Warnings encountered while opening multi-processor services protocol"); + let mp = unsafe { &mut *mp_support.get() }; + let proc_count = mp.get_number_of_processors().unwrap().unwrap(); + info!("Number of processors: {:?}", proc_count); } - // */ // exit boot services kernel_main(); - - Status::SUCCESS } -/* -pub fn file_system() -> Result { - if let Ok(gop) = system_table - .boot_services() - .locate_protocol::() - { - let gop = gop.expect("Warnings encountered while opening GOP"); - // Maybe save this - let gop = unsafe { &mut *gop.get() }; - let mut root = gop.open_volume().unwrap().expect("Failed to open volume"); - let attr = FileAttribute::all(); - - let xyz = root.open("test", FileMode::CreateReadWrite, attr).unwrap(); - let abcd = xyz.expect("Failed to open file").into_type(); - - let abcdef = abcd.unwrap().expect("Failed to open file"); - let mut buffer = [0u8; 10]; - match abcdef { - uefi::proto::media::file::FileType::Regular(mut file) => { - info!("{:?}", file.read(&mut buffer)) - } - uefi::proto::media::file::FileType::Dir(_) => todo!(), - } - } else { - // No tests can be run. - warn!("UEFI Simple File System is not supported"); - } +extern "efiapi" fn hi(_: *mut c_void) { + info!("Hello, world!"); } - - - - -*/ - -pub fn mp_handle() {} - -/* - let write_pixel: PixelWriter = match mi.pixel_format() { - // PixelFormat::Rgb => write_pixel_rgb, - PixelFormat::Bgr => write_pixel_bgr, - _ => { - info!("This pixel format is not supported by the drawing demo"); - return; - } - }; - - let mut fill_rectangle = |(x1, y1), (x2, y2), color| { - assert!((x1 < width) && (x2 < width), "Bad X coordinate"); - assert!((y1 < height) && (y2 < height), "Bad Y coordinate"); - for row in y1..y2 { - for column in x1..x2 { - unsafe { - let pixel_index = (row * stride) + column; - let pixel_base = 4 * pixel_index; - write_pixel(&mut fb, pixel_base, color); - } - } - } - }; - - fill_rectangle((50, 30), (150, 600), [250, 128, 64]); - fill_rectangle((400, 120), (750, 450), [16, 128, 255]); -*/ - use uefi::proto::console::gop::ModeInfo; pub type PixelWriter = unsafe fn(&mut FrameBuffer, usize, [u8; 3]); diff --git a/ableos/src/graphics_api/mod.rs b/ableos/src/graphics_api/mod.rs index 8360676..b726809 100644 --- a/ableos/src/graphics_api/mod.rs +++ b/ableos/src/graphics_api/mod.rs @@ -3,7 +3,3 @@ pub mod pixel_format; pub mod positions; pub mod text; pub mod window; - -pub trait API { - fn init(); -} diff --git a/ableos/src/kmain.rs b/ableos/src/kmain.rs index 9f390f0..814703a 100644 --- a/ableos/src/kmain.rs +++ b/ableos/src/kmain.rs @@ -39,7 +39,7 @@ lazy_static! { pub fn kernel_main() -> ! { // log::set_max_level(BOOT_CONF.log_level()); init::init(); - info!("AbleOS {} {}", KERNEL_VERSION, RELEASE_TYPE); + // info!("AbleOS {} {}", KERNEL_VERSION, RELEASE_TYPE); let result = logger::init(); match result { Ok(_) => {} diff --git a/repbuild/src/main.rs b/repbuild/src/main.rs index efe131f..2fd3a5c 100644 --- a/repbuild/src/main.rs +++ b/repbuild/src/main.rs @@ -73,7 +73,7 @@ fn main() -> anyhow::Result<()> { xshell::cmd!("cargo build --release --target=x86_64-unknown-uefi").run()?; xshell::cmd!( - "uefi-run -b src/arch/uefi_86/firmware/OVMF-pure-efi.fd target/x86_64-unknown-uefi/release/ableos.efi" + "uefi-run -b src/arch/uefi_86/firmware/OVMF-pure-efi.fd target/x86_64-unknown-uefi/release/ableos.efi -- -machine q35 -smp 4" ) .run()?; }