From cb8365abbd11f6c6d48e07aa1dc6d23eac806fd9 Mon Sep 17 00:00:00 2001 From: Able Date: Fri, 4 Feb 2022 23:23:59 -0600 Subject: [PATCH] various changes --- ableos/src/arch/uefi_86/mod.rs | 1 + ableos/src/experiments/mod.rs | 3 + ableos/src/experiments/vterm.rs | 39 ++++++ ableos/src/graphics/mod.rs | 1 + ableos/src/kmain.rs | 213 ++++++++++++++++++++++++++------ facepalm/src/lib.rs | 8 +- 6 files changed, 224 insertions(+), 41 deletions(-) create mode 100644 ableos/src/arch/uefi_86/mod.rs create mode 100644 ableos/src/experiments/vterm.rs diff --git a/ableos/src/arch/uefi_86/mod.rs b/ableos/src/arch/uefi_86/mod.rs new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/ableos/src/arch/uefi_86/mod.rs @@ -0,0 +1 @@ + diff --git a/ableos/src/experiments/mod.rs b/ableos/src/experiments/mod.rs index a5d7fec..7b0d8ea 100644 --- a/ableos/src/experiments/mod.rs +++ b/ableos/src/experiments/mod.rs @@ -10,4 +10,7 @@ pub mod server; pub mod systeminfo; pub mod virtual_memory; pub mod y_compositor; + +pub mod vterm; + pub const BANNER: &str = include_str!("banner.txt"); diff --git a/ableos/src/experiments/vterm.rs b/ableos/src/experiments/vterm.rs new file mode 100644 index 0000000..9f7efd2 --- /dev/null +++ b/ableos/src/experiments/vterm.rs @@ -0,0 +1,39 @@ +use shadeable::pixel_format::Rgba64; + +pub const VTERM_HEIGHT: u32 = 40; +pub const VTERM_WIDTH: u32 = 100; +/// Fg and bg colors for vterm +pub type ColorCharacter = (Rgba64, Rgba64); + +pub struct VtermCharacter { + pub character: char, + // + pub fg: Rgba64, + pub bg: Rgba64, + // + pub style: Style, +} + +pub struct Vterm { + pub characters: [[VtermCharacter; VTERM_WIDTH as usize]; VTERM_HEIGHT as usize], + pub cursor_x: u32, + pub cursor_y: u32, + pub cursor_visible: bool, +} + +pub struct Style { + pub bold: bool, + pub underline: bool, + pub italic: bool, + pub blink: bool, + pub reverse: bool, + pub strike: bool, +} + +pub struct StylePacked(u8); + +impl StylePacked { + pub fn new() -> Self { + StylePacked(0) + } +} diff --git a/ableos/src/graphics/mod.rs b/ableos/src/graphics/mod.rs index 59fd69d..0b978c9 100644 --- a/ableos/src/graphics/mod.rs +++ b/ableos/src/graphics/mod.rs @@ -29,6 +29,7 @@ impl ScreenSize { pub enum GraphicsReturn { Ok, ImproperScreenSize, + GenericError, } pub struct ScreenBuffer { diff --git a/ableos/src/kmain.rs b/ableos/src/kmain.rs index 1ffe9ec..9d19f06 100644 --- a/ableos/src/kmain.rs +++ b/ableos/src/kmain.rs @@ -38,45 +38,53 @@ lazy_static! { /// The main entry point of the kernel #[no_mangle] pub fn kernel_main() -> ! { - /* init::init(); - log::set_max_level(BOOT_CONF.log_level()); + log::set_max_level(BOOT_CONF.log_level()); + // init::init(); + if (|| true)() || (|| false)() { + () + } else { + ((), ()); + } + + /* + + { { - { - let mut scheduler = SCHEDULER.lock(); + let mut scheduler = SCHEDULER.lock(); - use crate::scheduler::Priority::*; - let mut process_1 = scheduler.new_process(High); - process_1.capabilities.files = FileAccess::Some(vec![PathRep { - location: FileLocations::Home, - file_name: "test".to_string(), - }]); - scheduler.add_process(process_1); - for ref_process in &scheduler.list { - trace!("{:?}", ref_process); - } - drop(scheduler); - } - - use crate::proto_filetable::file::FileLocations; - - { - let mut sock_print_id = SimpleSock::new(); - sock_print_id.register_protocol("Screen Printer".to_string()); - sock_print_id.write(format!("🐑").into()); - - let mut mode = SCREEN_BUFFER.lock(); - - mode.force_redraw(); - for current in (*String::from_utf8_lossy(&sock_print_id.peek().unwrap())).chars() { - mode.draw_char(0, 0, current, from_vga_16(Color16::Red)); - } - mode.copy_to_buffer(); + use crate::scheduler::Priority::*; + let mut process_1 = scheduler.new_process(High); + process_1.capabilities.files = FileAccess::Some(vec![PathRep { + location: FileLocations::Home, + file_name: "test".to_string(), + }]); + scheduler.add_process(process_1); + for ref_process in &scheduler.list { + trace!("{:?}", ref_process); } + drop(scheduler); } - start_facepalm(); + use crate::proto_filetable::file::FileLocations; + + { + let mut sock_print_id = SimpleSock::new(); + sock_print_id.register_protocol("Screen Printer".to_string()); + sock_print_id.write(format!("🐑").into()); + + let mut mode = SCREEN_BUFFER.lock(); + + mode.force_redraw(); + for current in (*String::from_utf8_lossy(&sock_print_id.peek().unwrap())).chars() { + mode.draw_char(0, 0, current, from_vga_16(Color16::Red)); + } + mode.copy_to_buffer(); + } + } + */ + start_facepalm(); sloop() } @@ -118,16 +126,147 @@ pub fn generate_process_pass() -> u128 { // #![no_main] // #![no_std] -use uefi::prelude::*; -use uefi::ResultExt; +use uefi::{ + prelude::*, + proto::{ + console::gop::{GraphicsOutput, PixelFormat}, + media::{ + file::{File, FileAttribute, FileMode}, + fs::SimpleFileSystem, + }, + }, +}; +use uefi::{proto::console::gop::FrameBuffer, ResultExt}; + +use crate::{GraphicsReturn, ScreenBuffer}; #[entry] fn main(_handle: Handle, mut system_table: SystemTable) -> Status { + system_table + .stdout() + .reset(false) + .expect_success("Failed to reset output buffer"); uefi_services::init(&mut system_table).unwrap_success(); + // Print out UEFI revision number + { + let rev = system_table.uefi_revision(); + let (major, minor) = (rev.major(), rev.minor()); + + info!("UEFI {}.{}", major, minor); + } + log_version_data(); - kernel_main(); + info!("Running graphics output protocol test"); + 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 mode = gop + .modes() + .map(|mode| mode.expect("Warnings encountered while querying mode")) + .find(|mode| { + let info = mode.info(); + info.resolution() == (1440, 900) + }) + .unwrap(); - loop {} - // Status::SUCCESS + gop.set_mode(&mode) + .expect_success("Failed to set graphics mode"); + + //crate::check_screenshot(bt, "gop_test"); + + draw_fb(gop); + } else { + // No tests can be run. + warn!("UEFI Graphics Output Protocol is not supported"); + } + + kernel_main(); } + +pub fn draw_fb(gop: &mut GraphicsOutput) { + let mi = gop.current_mode_info(); + let stride = mi.stride(); + let (width, height) = mi.resolution(); + + let mut fb = gop.frame_buffer(); + + type PixelWriter = unsafe fn(&mut FrameBuffer, usize, [u8; 3]); + unsafe fn write_pixel_rgb(fb: &mut FrameBuffer, pixel_base: usize, rgb: [u8; 3]) { + fb.write_value(pixel_base, rgb); + } + unsafe fn write_pixel_bgr(fb: &mut FrameBuffer, pixel_base: usize, rgb: [u8; 3]) { + fb.write_value(pixel_base, [rgb[2], rgb[1], rgb[0]]); + } + + 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), [123, 123, 123]); + fill_rectangle((400, 120), (750, 450), [16, 0, 255]); + fill_rectangle((80, 50), (200, 120), [0, 255, 0]); +} + +pub trait GopBuffer { + fn copy_to_buffer(&self) -> GraphicsReturn; +} + +impl GopBuffer for ScreenBuffer { + fn copy_to_buffer(&self) -> GraphicsReturn { + GraphicsReturn::GenericError + } +} +/* +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"); + } +} + +*/ diff --git a/facepalm/src/lib.rs b/facepalm/src/lib.rs index db88bc3..5b925ca 100644 --- a/facepalm/src/lib.rs +++ b/facepalm/src/lib.rs @@ -13,9 +13,9 @@ pub const RELEASE_TYPE: &str = "debug"; pub const RELEASE_TYPE: &str = "release"; pub fn start_facepalm() { - info!("facepalm 🤦 launched!"); - info!("facepalm 🤦 version: {}", VERSION); - info!("facepalm 🤦 {} mode", RELEASE_TYPE); - + // info!("facepalm 🤦 launched!"); + // info!("facepalm 🤦 version: {}", VERSION); + // info!("facepalm 🤦 {} mode", RELEASE_TYPE); + info!("Latin 1 (ISO-8859-1)"); // Drop into a debug shell }