work on moving the uefi into its own subcrate

This commit is contained in:
Able 2022-02-05 01:32:58 -06:00
parent 7785de8fd9
commit 04374aa905
8 changed files with 189 additions and 184 deletions

View file

@ -0,0 +1 @@
pub fn init() {}

View file

@ -1 +1,9 @@
pub mod init;
pub fn shutdown() {
loop {}
}
pub fn sloop() -> ! {
loop {}
}

View file

@ -1,6 +1,6 @@
#![allow(dead_code)] #![allow(dead_code)]
pub mod absi; // pub mod absi;
pub mod clip; pub mod clip;
pub mod futex; pub mod futex;
pub mod info; pub mod info;

View file

@ -10,157 +10,163 @@ pub type ColorCharacter = (Rgba64, Rgba64);
/// A vterm representation of a character /// A vterm representation of a character
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
pub struct VtermCharacter { pub struct VtermCharacter {
pub character: char, pub character: char,
// //
pub style: Style, pub style: Style,
// //
pub char_color: ColorCharacter, pub char_color: ColorCharacter,
} }
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
pub struct Style { pub struct Style {
pub bold: bool, pub bold: bool,
pub underline: bool, pub underline: bool,
pub italic: bool, pub italic: bool,
pub blink: bool, pub blink: bool,
pub reverse: bool, pub reverse: bool,
pub strike: bool, pub strike: bool,
} }
#[derive(Default)] #[derive(Default)]
pub struct StylePacked(pub u8); pub struct StylePacked(pub u8);
impl StylePacked { impl StylePacked {
pub fn bold(&self) -> bool { pub fn bold(&self) -> bool {
(self.0 & 0x01) > 0 (self.0 & 0x01) > 0
} }
pub fn underlined(&self) -> bool { pub fn underlined(&self) -> bool {
(self.0 & 0x02) > 0 (self.0 & 0x02) > 0
} }
pub fn italic(&self) -> bool { pub fn italic(&self) -> bool {
(self.0 & 0x04) > 0 (self.0 & 0x04) > 0
} }
pub fn blinking(&self) -> bool { pub fn blinking(&self) -> bool {
(self.0 & 0x08) > 0 (self.0 & 0x08) > 0
} }
pub fn reversed(&self) -> bool { pub fn reversed(&self) -> bool {
(self.0 & 0x10) > 0 (self.0 & 0x10) > 0
} }
pub fn struck(&self) -> bool { pub fn struck(&self) -> bool {
(self.0 & 0x20) > 0 (self.0 & 0x20) > 0
} }
#[must_use] #[must_use]
pub fn set_bold(mut self, v: bool) -> Self { pub fn set_bold(mut self, v: bool) -> Self {
if v { if v {
self.0 |= 0x01; self.0 |= 0x01;
} else { } else {
self.0 &= 0x01u8.not(); self.0 &= 0x01u8.not();
} }
self self
} }
#[must_use] #[must_use]
pub fn set_underlined(mut self, v: bool) -> Self { pub fn set_underlined(mut self, v: bool) -> Self {
if v { if v {
self.0 |= 0x02; self.0 |= 0x02;
} else { } else {
self.0 &= 0x02u8.not(); self.0 &= 0x02u8.not();
} }
self self
} }
#[must_use] #[must_use]
pub fn set_italic(mut self, v: bool) -> Self { pub fn set_italic(mut self, v: bool) -> Self {
if v { if v {
self.0 |= 0x04; self.0 |= 0x04;
} else { } else {
self.0 &= 0x04u8.not(); self.0 &= 0x04u8.not();
} }
self self
} }
#[must_use] #[must_use]
pub fn set_blinking(mut self, v: bool) -> Self { pub fn set_blinking(mut self, v: bool) -> Self {
if v { if v {
self.0 |= 0x08; self.0 |= 0x08;
} else { } else {
self.0 &= 0x08u8.not(); self.0 &= 0x08u8.not();
} }
self self
} }
#[must_use] #[must_use]
pub fn set_reversed(mut self, v: bool) -> Self { pub fn set_reversed(mut self, v: bool) -> Self {
if v { if v {
self.0 |= 0x10; self.0 |= 0x10;
} else { } else {
self.0 &= 0x10u8.not(); self.0 &= 0x10u8.not();
} }
self self
} }
#[must_use] #[must_use]
pub fn set_struck(mut self, v: bool) -> Self { pub fn set_struck(mut self, v: bool) -> Self {
if v { if v {
self.0 |= 0x20; self.0 |= 0x20;
} else { } else {
self.0 &= 0x20u8.not(); self.0 &= 0x20u8.not();
} }
self self
} }
} }
pub struct Vterm { pub struct Vterm {
pub characters: [[VtermCharacter; VTERM_WIDTH as usize]; VTERM_HEIGHT as usize], pub characters: [[VtermCharacter; VTERM_WIDTH as usize]; VTERM_HEIGHT as usize],
/// The internal representation of the vterm /// The internal representation of the vterm
style: Style, style: Style,
/// The cursor position in layout x,y /// The cursor position in layout x,y
cursor_position: (u32, u32), cursor_position: (u32, u32),
pub cursor_visible: bool, pub cursor_visible: bool,
} }
impl Default for Vterm { impl Default for Vterm {
fn default() -> Self { fn default() -> Self {
Vterm { Vterm {
characters: [[VtermCharacter { characters: [[VtermCharacter {
character: ' ', character: ' ',
char_color: (0xff_ff_ff_ff, 0x00_00_00_00), 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 { style: Style {
bold: false, bold: false,
underline: false, underline: false,
italic: false, italic: false,
blink: false, blink: false,
reverse: false, reverse: false,
strike: 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 { impl Vterm {
/// Set the vterm cursor to the given position pub fn new() -> Self {
pub fn set_cursor_position(&mut self, x: u32, y: u32) { Vterm::default()
if x > VTERM_WIDTH { }
self.cursor_position.0 = VTERM_WIDTH; /// Set the vterm cursor to the given position
} else { pub fn set_cursor_position(&mut self, x: u32, y: u32) {
self.cursor_position.0 = x; if x > VTERM_WIDTH {
} self.cursor_position.0 = VTERM_WIDTH;
if y > VTERM_HEIGHT { error!("Cursor x position out of bounds");
self.cursor_position.1 = VTERM_HEIGHT; } else {
} else { self.cursor_position.0 = x;
self.cursor_position.1 = y; }
} if y > VTERM_HEIGHT {
} error!("Cursor y position out of bounds");
/// Set the vterm style self.cursor_position.1 = VTERM_HEIGHT;
pub fn set_vterm_style(&mut self, style: Style) { } else {
self.style = style; self.cursor_position.1 = y;
} }
}
/// Set the vterm style
pub fn set_vterm_style(&mut self, style: Style) {
self.style = style;
}
} }

View file

@ -15,7 +15,8 @@ use {
file::PathRep, file::PathRep,
relib::network::socket::{SimpleSock, Socket}, relib::network::socket::{SimpleSock, Socket},
scheduler::SCHEDULER, scheduler::SCHEDULER,
VgaBuffer, SCREEN_BUFFER, // VgaBuffer,
SCREEN_BUFFER,
}, },
alloc::{ alloc::{
format, format,
@ -26,8 +27,6 @@ use {
facepalm::start_facepalm, facepalm::start_facepalm,
lazy_static::lazy_static, lazy_static::lazy_static,
log::*, log::*,
shadeable::pixel_format::from_vga_16,
vga::colors::Color16,
}; };
lazy_static! { lazy_static! {
@ -39,51 +38,19 @@ lazy_static! {
#[no_mangle] #[no_mangle]
pub fn kernel_main() -> ! { pub fn kernel_main() -> ! {
log::set_max_level(BOOT_CONF.log_level()); 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(); 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(); let mut vterm0 = Vterm::new();
vterm0.set_cursor_position(123, 123); vterm0.set_cursor_position(60, 40);
start_facepalm(); vterm0.characters[0][0].character = 'a';
// start_facepalm();
sloop() sloop()
} }
@ -134,10 +101,11 @@ use uefi::{
fs::SimpleFileSystem, fs::SimpleFileSystem,
}, },
}, },
CStr16,
}; };
use uefi::{proto::console::gop::FrameBuffer, ResultExt}; use uefi::{proto::console::gop::FrameBuffer, ResultExt};
use crate::{vterm::Vterm, GraphicsReturn, ScreenBuffer}; use crate::{file::FileLocations, logger, vterm::Vterm, GraphicsReturn, ScreenBuffer};
#[entry] #[entry]
fn main(_handle: Handle, mut system_table: SystemTable<Boot>) -> Status { fn main(_handle: Handle, mut system_table: SystemTable<Boot>) -> Status {
@ -147,6 +115,7 @@ fn main(_handle: Handle, mut system_table: SystemTable<Boot>) -> Status {
.expect_success("Failed to reset output buffer"); .expect_success("Failed to reset output buffer");
uefi_services::init(&mut system_table).unwrap_success(); uefi_services::init(&mut system_table).unwrap_success();
// Print out UEFI revision number // Print out UEFI revision number
{ {
let rev = system_table.uefi_revision(); let rev = system_table.uefi_revision();
let (major, minor) = (rev.major(), rev.minor()); let (major, minor) = (rev.major(), rev.minor());
@ -155,6 +124,15 @@ fn main(_handle: Handle, mut system_table: SystemTable<Boot>) -> Status {
} }
info!("Running graphics output protocol test"); 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 if let Ok(gop) = system_table
.boot_services() .boot_services()
.locate_protocol::<GraphicsOutput>() .locate_protocol::<GraphicsOutput>()
@ -182,7 +160,14 @@ fn main(_handle: Handle, mut system_table: SystemTable<Boot>) -> Status {
warn!("UEFI Graphics Output Protocol is not supported"); warn!("UEFI Graphics Output Protocol is not supported");
} }
*/
// exit boot services
kernel_main(); kernel_main();
Status::SUCCESS
} }
pub fn draw_fb(gop: &mut GraphicsOutput) { pub fn draw_fb(gop: &mut GraphicsOutput) {

View file

@ -22,10 +22,14 @@
pub mod arch; pub mod arch;
/// Contains architecture specific code for x86_64. /// 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"] #[path = "arch/x86_64/mod.rs"]
pub mod arch; 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. /// Contains architecture specific code for riscv64.
#[cfg(target_arch = "riscv64")] #[cfg(target_arch = "riscv64")]
#[path = "arch/riscv/mod.rs"] #[path = "arch/riscv/mod.rs"]

View file

@ -1,12 +1,12 @@
use core::sync::atomic::Ordering; use core::sync::atomic::Ordering;
use crate::kmain::TICK; use crate::kmain::TICK;
use crate::serial_println; // use crate::serial_println;
use lliw::{Fg, Reset}; use lliw::{Fg, Reset};
pub use log::{debug, info, trace, warn}; pub use log::{debug, info, trace, warn};
use log::{Level, Metadata, Record}; use log::{Level, Metadata, Record};
use crate::arch::drivers::timer::TIMER_INTERRUPT_HERTZ; // use crate::arch::drivers::timer::TIMER_INTERRUPT_HERTZ;
struct SimpleLogger; struct SimpleLogger;
@ -20,7 +20,7 @@ impl log::Log for SimpleLogger {
let color; let color;
let time = TICK.load(Ordering::Relaxed) as f64; 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() { match record.level() {
log::Level::Error => color = (Fg::Red, "$RED$"), 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::Debug => color = (Fg::Blue, "$BLUE$"),
log::Level::Trace => color = (Fg::Yellow, "$YELLOW$"), log::Level::Trace => color = (Fg::Yellow, "$YELLOW$"),
} }
/*
serial_println!( serial_println!(
"[{}{}{}][{}{}{}] {}", "[{}{}{}][{}{}{}] {}",
color.0, color.0,
@ -40,6 +40,7 @@ impl log::Log for SimpleLogger {
Reset, Reset,
record.args(), record.args(),
); );
*/
} }
} }
/// Clear the log buffer /// Clear the log buffer

View file

@ -16,8 +16,8 @@ impl core::fmt::Write for Stdout {
} }
#[cfg(target_arch = "x86_64")] #[cfg(target_arch = "x86_64")]
fn write_str(&mut self, s: &str) -> Result<(), Error> { fn write_str(&mut self, s: &str) -> Result<(), Error> {
use crate::experiments::absi::colorify; // use crate::experiments::absi::colorify;
colorify(s); // colorify(s);
// kprint!("{}", s); // kprint!("{}", s);
Ok(()) Ok(())
} }