diff --git a/ableos/src/arch/uefi_86/init.rs b/ableos/src/arch/uefi_86/init.rs new file mode 100644 index 0000000..12cd021 --- /dev/null +++ b/ableos/src/arch/uefi_86/init.rs @@ -0,0 +1 @@ +pub fn init() {} diff --git a/ableos/src/arch/uefi_86/mod.rs b/ableos/src/arch/uefi_86/mod.rs index 8b13789..5fa7374 100644 --- a/ableos/src/arch/uefi_86/mod.rs +++ b/ableos/src/arch/uefi_86/mod.rs @@ -1 +1,9 @@ +pub mod init; +pub fn shutdown() { + loop {} +} + +pub fn sloop() -> ! { + loop {} +} diff --git a/ableos/src/experiments/mod.rs b/ableos/src/experiments/mod.rs index 7b0d8ea..e758fb4 100644 --- a/ableos/src/experiments/mod.rs +++ b/ableos/src/experiments/mod.rs @@ -1,6 +1,6 @@ #![allow(dead_code)] -pub mod absi; +// pub mod absi; pub mod clip; pub mod futex; pub mod info; diff --git a/ableos/src/experiments/vterm.rs b/ableos/src/experiments/vterm.rs index 9acb188..f039fc6 100644 --- a/ableos/src/experiments/vterm.rs +++ b/ableos/src/experiments/vterm.rs @@ -10,157 +10,163 @@ pub type ColorCharacter = (Rgba64, Rgba64); /// A vterm representation of a character #[derive(Debug, Clone, Copy)] pub struct VtermCharacter { - pub character: char, - // - pub style: Style, - // - pub char_color: ColorCharacter, + pub character: char, + // + pub style: Style, + // + pub char_color: ColorCharacter, } #[derive(Debug, Clone, Copy)] pub struct Style { - pub bold: bool, - pub underline: bool, - pub italic: bool, - pub blink: bool, - pub reverse: bool, - pub strike: bool, + pub bold: bool, + pub underline: bool, + pub italic: bool, + pub blink: bool, + pub reverse: bool, + pub strike: bool, } #[derive(Default)] pub struct StylePacked(pub u8); impl StylePacked { - pub fn bold(&self) -> bool { - (self.0 & 0x01) > 0 - } - pub fn underlined(&self) -> bool { - (self.0 & 0x02) > 0 - } - pub fn italic(&self) -> bool { - (self.0 & 0x04) > 0 - } - pub fn blinking(&self) -> bool { - (self.0 & 0x08) > 0 - } - pub fn reversed(&self) -> bool { - (self.0 & 0x10) > 0 - } - pub fn struck(&self) -> bool { - (self.0 & 0x20) > 0 - } - #[must_use] - pub fn set_bold(mut self, v: bool) -> Self { - if v { - self.0 |= 0x01; - } else { - self.0 &= 0x01u8.not(); - } - self - } - #[must_use] - pub fn set_underlined(mut self, v: bool) -> Self { - if v { - self.0 |= 0x02; - } else { - self.0 &= 0x02u8.not(); - } - self - } - #[must_use] - pub fn set_italic(mut self, v: bool) -> Self { - if v { - self.0 |= 0x04; - } else { - self.0 &= 0x04u8.not(); - } - self - } - #[must_use] - pub fn set_blinking(mut self, v: bool) -> Self { - if v { - self.0 |= 0x08; - } else { - self.0 &= 0x08u8.not(); - } - self - } - #[must_use] - pub fn set_reversed(mut self, v: bool) -> Self { - if v { - self.0 |= 0x10; - } else { - self.0 &= 0x10u8.not(); - } - self - } - #[must_use] - pub fn set_struck(mut self, v: bool) -> Self { - if v { - self.0 |= 0x20; - } else { - self.0 &= 0x20u8.not(); - } - self - } + pub fn bold(&self) -> bool { + (self.0 & 0x01) > 0 + } + pub fn underlined(&self) -> bool { + (self.0 & 0x02) > 0 + } + pub fn italic(&self) -> bool { + (self.0 & 0x04) > 0 + } + pub fn blinking(&self) -> bool { + (self.0 & 0x08) > 0 + } + pub fn reversed(&self) -> bool { + (self.0 & 0x10) > 0 + } + pub fn struck(&self) -> bool { + (self.0 & 0x20) > 0 + } + #[must_use] + pub fn set_bold(mut self, v: bool) -> Self { + if v { + self.0 |= 0x01; + } else { + self.0 &= 0x01u8.not(); + } + self + } + #[must_use] + pub fn set_underlined(mut self, v: bool) -> Self { + if v { + self.0 |= 0x02; + } else { + self.0 &= 0x02u8.not(); + } + self + } + #[must_use] + pub fn set_italic(mut self, v: bool) -> Self { + if v { + self.0 |= 0x04; + } else { + self.0 &= 0x04u8.not(); + } + self + } + #[must_use] + pub fn set_blinking(mut self, v: bool) -> Self { + if v { + self.0 |= 0x08; + } else { + self.0 &= 0x08u8.not(); + } + self + } + #[must_use] + pub fn set_reversed(mut self, v: bool) -> Self { + if v { + self.0 |= 0x10; + } else { + self.0 &= 0x10u8.not(); + } + self + } + #[must_use] + pub fn set_struck(mut self, v: bool) -> Self { + if v { + self.0 |= 0x20; + } else { + self.0 &= 0x20u8.not(); + } + self + } } pub struct Vterm { - pub characters: [[VtermCharacter; VTERM_WIDTH as usize]; VTERM_HEIGHT as usize], - /// The internal representation of the vterm - style: Style, - /// The cursor position in layout x,y - cursor_position: (u32, u32), + pub characters: [[VtermCharacter; VTERM_WIDTH as usize]; VTERM_HEIGHT as usize], + /// The internal representation of the vterm + style: Style, + /// The cursor position in layout x,y + cursor_position: (u32, u32), - pub cursor_visible: bool, + pub cursor_visible: bool, } impl Default for Vterm { - fn default() -> Self { - Vterm { - characters: [[VtermCharacter { - character: ' ', - char_color: (0xff_ff_ff_ff, 0x00_00_00_00), + fn default() -> Self { + Vterm { + characters: [[VtermCharacter { + character: ' ', + char_color: (0xff_ff_ff_ff, 0x00_00_00_00), + style: Style { + bold: false, + underline: false, + italic: false, + blink: false, + reverse: false, + strike: false, + }, + }; VTERM_WIDTH as usize]; VTERM_HEIGHT as usize], + cursor_position: (0, 0), + cursor_visible: true, style: Style { - bold: false, - underline: false, - italic: false, - blink: false, - reverse: false, - strike: false, + bold: false, + underline: false, + italic: false, + blink: false, + reverse: false, + strike: false, }, - }; VTERM_WIDTH as usize]; VTERM_HEIGHT as usize], - cursor_position: (0, 0), - cursor_visible: true, - style: Style { - bold: false, - underline: false, - italic: false, - blink: false, - reverse: false, - strike: false, - }, - } - } + } + } } impl Vterm { - /// Set the vterm cursor to the given position - pub fn set_cursor_position(&mut self, x: u32, y: u32) { - if x > VTERM_WIDTH { - self.cursor_position.0 = VTERM_WIDTH; - } else { - self.cursor_position.0 = x; - } - if y > VTERM_HEIGHT { - self.cursor_position.1 = VTERM_HEIGHT; - } else { - self.cursor_position.1 = y; - } - } + pub fn new() -> Self { + Vterm::default() + } + /// Set the vterm cursor to the given position + pub fn set_cursor_position(&mut self, x: u32, y: u32) { + if x > VTERM_WIDTH { + self.cursor_position.0 = VTERM_WIDTH; + error!("Cursor x position out of bounds"); + } else { + self.cursor_position.0 = x; + } + if y > VTERM_HEIGHT { + error!("Cursor y position out of bounds"); - /// Set the vterm style - pub fn set_vterm_style(&mut self, style: Style) { - self.style = style; - } + self.cursor_position.1 = VTERM_HEIGHT; + } else { + self.cursor_position.1 = y; + } + } + + /// Set the vterm style + pub fn set_vterm_style(&mut self, style: Style) { + self.style = style; + } } diff --git a/ableos/src/kmain.rs b/ableos/src/kmain.rs index aece4fd..7b11d50 100644 --- a/ableos/src/kmain.rs +++ b/ableos/src/kmain.rs @@ -15,7 +15,8 @@ use { file::PathRep, relib::network::socket::{SimpleSock, Socket}, scheduler::SCHEDULER, - VgaBuffer, SCREEN_BUFFER, + // VgaBuffer, + SCREEN_BUFFER, }, alloc::{ format, @@ -26,8 +27,6 @@ use { facepalm::start_facepalm, lazy_static::lazy_static, log::*, - shadeable::pixel_format::from_vga_16, - vga::colors::Color16, }; lazy_static! { @@ -39,51 +38,19 @@ lazy_static! { #[no_mangle] pub fn kernel_main() -> ! { log::set_max_level(BOOT_CONF.log_level()); - // init::init(); - + init::init(); + let result = logger::init(); + match result { + Ok(_) => {} + Err(err) => error!("{}", err), + } log_version_data(); - /* - - { - { - 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(); - } - } - - */ - let mut vterm0 = Vterm::new(); - vterm0.set_cursor_position(123, 123); - start_facepalm(); + vterm0.set_cursor_position(60, 40); + vterm0.characters[0][0].character = 'a'; + + // start_facepalm(); sloop() } @@ -134,10 +101,11 @@ use uefi::{ fs::SimpleFileSystem, }, }, + CStr16, }; use uefi::{proto::console::gop::FrameBuffer, ResultExt}; -use crate::{vterm::Vterm, GraphicsReturn, ScreenBuffer}; +use crate::{file::FileLocations, logger, vterm::Vterm, GraphicsReturn, ScreenBuffer}; #[entry] fn main(_handle: Handle, mut system_table: SystemTable) -> Status { @@ -147,6 +115,7 @@ fn main(_handle: Handle, mut system_table: SystemTable) -> Status { .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()); @@ -155,6 +124,15 @@ fn main(_handle: Handle, mut system_table: SystemTable) -> Status { } info!("Running graphics output protocol test"); + + let stdout = system_table.stdout(); + + stdout.set_cursor_position(0, 10).unwrap_success(); + info!("{:?}", stdout.cursor_position()); + + // loop {} + /* + if let Ok(gop) = system_table .boot_services() .locate_protocol::() @@ -182,7 +160,14 @@ fn main(_handle: Handle, mut system_table: SystemTable) -> Status { warn!("UEFI Graphics Output Protocol is not supported"); } + + + */ + + // exit boot services kernel_main(); + + Status::SUCCESS } pub fn draw_fb(gop: &mut GraphicsOutput) { diff --git a/ableos/src/lib.rs b/ableos/src/lib.rs index 264385d..7fe6992 100644 --- a/ableos/src/lib.rs +++ b/ableos/src/lib.rs @@ -22,10 +22,14 @@ pub mod arch; /// Contains architecture specific code for x86_64. -#[cfg(target_arch = "x86_64")] +#[cfg(all(target_arch = "x86_64", not(target_os = "uefi")))] #[path = "arch/x86_64/mod.rs"] pub mod arch; +#[cfg(all(target_arch = "x86_64", target_os = "uefi"))] +#[path = "arch/uefi_86/mod.rs"] +pub mod arch; + /// Contains architecture specific code for riscv64. #[cfg(target_arch = "riscv64")] #[path = "arch/riscv/mod.rs"] diff --git a/ableos/src/logger.rs b/ableos/src/logger.rs index 64ae5e8..0503cd4 100644 --- a/ableos/src/logger.rs +++ b/ableos/src/logger.rs @@ -1,12 +1,12 @@ use core::sync::atomic::Ordering; use crate::kmain::TICK; -use crate::serial_println; +// use crate::serial_println; use lliw::{Fg, Reset}; pub use log::{debug, info, trace, warn}; use log::{Level, Metadata, Record}; -use crate::arch::drivers::timer::TIMER_INTERRUPT_HERTZ; +// use crate::arch::drivers::timer::TIMER_INTERRUPT_HERTZ; struct SimpleLogger; @@ -20,7 +20,7 @@ impl log::Log for SimpleLogger { let color; let time = TICK.load(Ordering::Relaxed) as f64; - let time_float = time / TIMER_INTERRUPT_HERTZ; + // let time_float = time / TIMER_INTERRUPT_HERTZ; match record.level() { log::Level::Error => color = (Fg::Red, "$RED$"), @@ -29,7 +29,7 @@ impl log::Log for SimpleLogger { log::Level::Debug => color = (Fg::Blue, "$BLUE$"), log::Level::Trace => color = (Fg::Yellow, "$YELLOW$"), } - + /* serial_println!( "[{}{}{}][{}{}{}] {}", color.0, @@ -40,6 +40,7 @@ impl log::Log for SimpleLogger { Reset, record.args(), ); + */ } } /// Clear the log buffer diff --git a/ableos/src/print.rs b/ableos/src/print.rs index 59ea1fb..56c1bf5 100644 --- a/ableos/src/print.rs +++ b/ableos/src/print.rs @@ -16,8 +16,8 @@ impl core::fmt::Write for Stdout { } #[cfg(target_arch = "x86_64")] fn write_str(&mut self, s: &str) -> Result<(), Error> { - use crate::experiments::absi::colorify; - colorify(s); + // use crate::experiments::absi::colorify; + // colorify(s); // kprint!("{}", s); Ok(()) }