From 914085fdf5e94f64ce34909e479c2e0bf305e0af Mon Sep 17 00:00:00 2001 From: Able Date: Fri, 24 Dec 2021 13:00:20 -0600 Subject: [PATCH] colorify function added --- ableos/src/arch/x86_64/.runners/debug.sh | 2 - ableos/src/arch/x86_64/.runners/run-debug.sh | 2 - ableos/src/arch/x86_64/.runners/run-test.sh | 2 - ableos/src/arch/x86_64/.runners/run.sh | 2 - ableos/src/arch/x86_64/drivers/mod.rs | 2 +- ableos/src/arch/x86_64/drivers/vga.rs | 181 ++++++++++--------- ableos/src/arch/x86_64/mod.rs | 4 +- ableos/src/experiments/absi.rs | 63 +++++++ ableos/src/experiments/mail.rs | 1 + ableos/src/experiments/mod.rs | 1 + ableos/src/kmain.rs | 5 +- ableos/src/lib.rs | 1 - ableos/src/wasm/mod.rs | 2 +- ableos/src/wasm/wasm_sys.rs | 23 ++- ableos/src/wasm/zig.wasm | Bin 0 -> 402 bytes 15 files changed, 182 insertions(+), 109 deletions(-) delete mode 100644 ableos/src/arch/x86_64/.runners/debug.sh delete mode 100644 ableos/src/arch/x86_64/.runners/run-debug.sh delete mode 100644 ableos/src/arch/x86_64/.runners/run-test.sh delete mode 100644 ableos/src/arch/x86_64/.runners/run.sh create mode 100644 ableos/src/experiments/absi.rs create mode 100644 ableos/src/wasm/zig.wasm diff --git a/ableos/src/arch/x86_64/.runners/debug.sh b/ableos/src/arch/x86_64/.runners/debug.sh deleted file mode 100644 index caac0240..00000000 --- a/ableos/src/arch/x86_64/.runners/debug.sh +++ /dev/null @@ -1,2 +0,0 @@ -cargo bootimage --target json_targets/x86_64-ableos.json && \ -qemu-system-x86_64 -S -gdb tcp::9000 -drive format=raw,file=target/x86_64-ableos/debug/bootimage-ableos.bin diff --git a/ableos/src/arch/x86_64/.runners/run-debug.sh b/ableos/src/arch/x86_64/.runners/run-debug.sh deleted file mode 100644 index 448bf8c8..00000000 --- a/ableos/src/arch/x86_64/.runners/run-debug.sh +++ /dev/null @@ -1,2 +0,0 @@ -cargo bootimage --target json_targets/x86_64-ableos.json && \ -qemu-system-x86_64 -drive format=raw,file=target/x86_64-ableos/debug/bootimage-ableos.bin diff --git a/ableos/src/arch/x86_64/.runners/run-test.sh b/ableos/src/arch/x86_64/.runners/run-test.sh deleted file mode 100644 index 448bf8c8..00000000 --- a/ableos/src/arch/x86_64/.runners/run-test.sh +++ /dev/null @@ -1,2 +0,0 @@ -cargo bootimage --target json_targets/x86_64-ableos.json && \ -qemu-system-x86_64 -drive format=raw,file=target/x86_64-ableos/debug/bootimage-ableos.bin diff --git a/ableos/src/arch/x86_64/.runners/run.sh b/ableos/src/arch/x86_64/.runners/run.sh deleted file mode 100644 index afd3b549..00000000 --- a/ableos/src/arch/x86_64/.runners/run.sh +++ /dev/null @@ -1,2 +0,0 @@ -cargo bootimage --release --target json_targets/x86_64-ableos.json && \ -qemu-system-x86_64 -drive format=raw,file=target/x86_64-ableos/release/bootimage-ableos.bin diff --git a/ableos/src/arch/x86_64/drivers/mod.rs b/ableos/src/arch/x86_64/drivers/mod.rs index 9267fd2a..8ac1cbc8 100644 --- a/ableos/src/arch/x86_64/drivers/mod.rs +++ b/ableos/src/arch/x86_64/drivers/mod.rs @@ -1,5 +1,5 @@ pub mod allocator; pub mod graphics; pub mod serial; -#[deprecated(note = "The use of hardware specific drivers for VGA is discouraged")] +// #[deprecated(note = "The use of hardware specific drivers for VGA is discouraged")] pub mod vga; diff --git a/ableos/src/arch/x86_64/drivers/vga.rs b/ableos/src/arch/x86_64/drivers/vga.rs index c7746f96..91264c7f 100644 --- a/ableos/src/arch/x86_64/drivers/vga.rs +++ b/ableos/src/arch/x86_64/drivers/vga.rs @@ -2,114 +2,111 @@ #[derive(Debug, Clone, Copy, PartialEq, Eq)] #[repr(u8)] pub enum Color { - Black = 0, - Blue = 1, - Green = 2, - Cyan = 3, - Red = 4, - Magenta = 5, - Brown = 6, - LightGray = 7, - DarkGray = 8, - LightBlue = 9, - LightGreen = 10, - LightCyan = 11, - LightRed = 12, - Pink = 13, - Yellow = 14, - White = 15, + Black = 0, + Blue = 1, + Green = 2, + Cyan = 3, + Red = 4, + Magenta = 5, + Brown = 6, + LightGray = 7, + DarkGray = 8, + LightBlue = 9, + LightGreen = 10, + LightCyan = 11, + LightRed = 12, + Pink = 13, + Yellow = 14, + White = 15, } #[derive(Debug, Clone, Copy, PartialEq, Eq)] #[repr(transparent)] struct ColorCode(u8); impl ColorCode { - fn new(foreground: Color, background: Color) -> ColorCode { - ColorCode((background as u8) << 4 | (foreground as u8)) - } + fn new(foreground: Color, background: Color) -> ColorCode { + ColorCode((background as u8) << 4 | (foreground as u8)) + } } #[derive(Debug, Clone, Copy, PartialEq, Eq)] #[repr(C)] struct ScreenChar { - ascii_character: u8, - color_code: ColorCode, + ascii_character: u8, + color_code: ColorCode, } const BUFFER_HEIGHT: usize = 25; const BUFFER_WIDTH: usize = 80; #[repr(transparent)] struct Buffer { - chars: [[Volatile; BUFFER_WIDTH]; BUFFER_HEIGHT], + chars: [[Volatile; BUFFER_WIDTH]; BUFFER_HEIGHT], } pub struct Writer { - column_position: usize, - color_code: ColorCode, - buffer: &'static mut Buffer, + column_position: usize, + color_code: ColorCode, + buffer: &'static mut Buffer, } impl Writer { - pub fn write_byte(&mut self, byte: u8) { - match byte { - b'\n' => self.new_line(), - byte => { - if self.column_position >= BUFFER_WIDTH { - self.new_line(); - } - let row = BUFFER_HEIGHT - 1; - let col = self.column_position; - let color_code = self.color_code; - self.buffer.chars[row][col].write(ScreenChar { - ascii_character: byte, - color_code, - }); - self.column_position += 1; - } - } - } - pub fn write_string(&mut self, s: &str) { - for byte in s.bytes() { - match byte { - // printable ASCII byte or newline - 0x20..=0x7e | b'\n' => self.write_byte(byte), - // not part of printable ASCII range - _ => self.write_byte(0xfe), - } - } - } - fn new_line(&mut self) { - for row in 1..BUFFER_HEIGHT { - for col in 0..BUFFER_WIDTH { - let character = self.buffer.chars[row][col].read(); - self.buffer.chars[row - 1][col].write(character); - } - } - self.clear_row(BUFFER_HEIGHT - 1); - self.column_position = 0; - } - fn clear_row(&mut self, row: usize) { - let blank = ScreenChar { - ascii_character: b' ', - color_code: self.color_code, - }; - for col in 0..BUFFER_WIDTH { - self.buffer.chars[row][col].write(blank); - } - } + pub fn write_byte(&mut self, byte: u8) { + match byte { + b'\n' => self.new_line(), + byte => { + if self.column_position >= BUFFER_WIDTH { + self.new_line(); + } + let row = BUFFER_HEIGHT - 1; + let col = self.column_position; + let color_code = self.color_code; + self.buffer.chars[row][col].write(ScreenChar { + ascii_character: byte, + color_code, + }); + self.column_position += 1; + } + } + } + pub fn write_string(&mut self, s: &str) { + for byte in s.bytes() { + match byte { + // printable ASCII byte or newline + 0x20..=0x7e | b'\n' => self.write_byte(byte), + // not part of printable ASCII range + _ => self.write_byte(0xfe), + } + } + } + fn new_line(&mut self) { + for row in 1..BUFFER_HEIGHT { + for col in 0..BUFFER_WIDTH { + let character = self.buffer.chars[row][col].read(); + self.buffer.chars[row - 1][col].write(character); + } + } + self.clear_row(BUFFER_HEIGHT - 1); + self.column_position = 0; + } + fn clear_row(&mut self, row: usize) { + let blank = ScreenChar { + ascii_character: b' ', + color_code: self.color_code, + }; + for col in 0..BUFFER_WIDTH { + self.buffer.chars[row][col].write(blank); + } + } } impl fmt::Write for Writer { - fn write_str(&mut self, s: &str) -> fmt::Result { - self.write_string(s); - Ok(()) - } + fn write_str(&mut self, s: &str) -> fmt::Result { + self.write_string(s); + Ok(()) + } } lazy_static! { - pub static ref WRITER: Mutex = Mutex::new(Writer { - column_position: 0, - color_code: ColorCode::new(Color::Green, Color::Black), - buffer: unsafe { &mut *(0xb8000 as *mut Buffer) }, - }); -} -#[allow(dead_code)] -pub fn set_vga_color() { - WRITER.lock().color_code = ColorCode::new(Color::White, Color::Yellow); + pub static ref WRITER: Mutex = Mutex::new(Writer { + column_position: 0, + color_code: ColorCode::new(Color::Green, Color::Black), + buffer: unsafe { &mut *(0xb8000 as *mut Buffer) }, + }); } + use core::fmt; use lazy_static::lazy_static; use spin::Mutex; @@ -125,9 +122,13 @@ macro_rules! kprintln { } #[doc(hidden)] pub fn _kprint(args: fmt::Arguments) { - use core::fmt::Write; - use x86_64::instructions::interrupts; - interrupts::without_interrupts(|| { - WRITER.lock().write_fmt(args).unwrap(); - }); + use core::fmt::Write; + use x86_64::instructions::interrupts; + interrupts::without_interrupts(|| { + WRITER.lock().write_fmt(args).unwrap(); + }); +} + +pub fn set_vga_color(fg: Color, bg: Color) { + WRITER.lock().color_code = ColorCode::new(fg, bg); } diff --git a/ableos/src/arch/x86_64/mod.rs b/ableos/src/arch/x86_64/mod.rs index eb0dea8c..03a95cb0 100644 --- a/ableos/src/arch/x86_64/mod.rs +++ b/ableos/src/arch/x86_64/mod.rs @@ -23,8 +23,8 @@ pub fn start(boot_info: &'static BootInfo) -> ! { let page = Page::containing_address(VirtAddr::new(0xdeadbeaf000)); memory::create_example_mapping(page, &mut mapper, &mut frame_allocator); - let page_ptr: *mut u64 = page.start_address().as_mut_ptr(); - unsafe { page_ptr.offset(400).write_volatile(0xf021_f077_f065_804e) }; + // let page_ptr: *mut u64 = page.start_address().as_mut_ptr(); + // unsafe { page_ptr.offset(400).write_volatile(0xf021_f077_f065_804e) }; allocator::init_heap(&mut mapper, &mut frame_allocator).expect("heap initialization failed"); diff --git a/ableos/src/experiments/absi.rs b/ableos/src/experiments/absi.rs new file mode 100644 index 00000000..74972400 --- /dev/null +++ b/ableos/src/experiments/absi.rs @@ -0,0 +1,63 @@ +use crate::arch::drivers::vga::{set_vga_color, Color}; + +pub fn colorify(eval: &str) { + let y = eval.split("$"); + for z in y { + match z { + "BLACK" => { + set_vga_color(Color::Black, Color::Black); + } + "RED" => { + set_vga_color(Color::Red, Color::Black); + } + "GREEN" => { + set_vga_color(Color::Green, Color::Black); + } + "BLUE" => { + set_vga_color(Color::Blue, Color::Black); + } + "CYAN" => { + set_vga_color(Color::Cyan, Color::Black); + } + "MAGENTA" => { + set_vga_color(Color::Magenta, Color::Black); + } + "BROWN" => { + set_vga_color(Color::Brown, Color::Black); + } + "LIGHTGRAY" => { + set_vga_color(Color::LightGray, Color::Black); + } + "DARKGRAY" => { + set_vga_color(Color::DarkGray, Color::Black); + } + "LIGHTBLUE" => { + set_vga_color(Color::LightBlue, Color::Black); + } + "LIGHTGREEN" => { + set_vga_color(Color::LightGreen, Color::Black); + } + "LIGHTCYAN" => { + set_vga_color(Color::LightCyan, Color::Black); + } + "LIGHTRED" => { + set_vga_color(Color::LightRed, Color::Black); + } + "PINK" => { + set_vga_color(Color::Pink, Color::Black); + } + "YELLOW" => { + set_vga_color(Color::Yellow, Color::Black); + } + "WHITE" => { + set_vga_color(Color::White, Color::Black); + } + "RESET" => { + set_vga_color(Color::White, Color::Black); + } + elk => { + print!("{}", elk); + } + } + } +} diff --git a/ableos/src/experiments/mail.rs b/ableos/src/experiments/mail.rs index 43f486eb..3778b6be 100644 --- a/ableos/src/experiments/mail.rs +++ b/ableos/src/experiments/mail.rs @@ -1,5 +1,6 @@ #![allow(dead_code)] use crate::trace; +// TODO: Evaluate variable sized mailboxes pub struct MailBoxes { flags: u8, diff --git a/ableos/src/experiments/mod.rs b/ableos/src/experiments/mod.rs index 75686028..2e5f4f15 100644 --- a/ableos/src/experiments/mod.rs +++ b/ableos/src/experiments/mod.rs @@ -1,5 +1,6 @@ #![allow(dead_code)] +pub mod absi; pub mod clip; pub mod server; pub mod systeminfo; diff --git a/ableos/src/kmain.rs b/ableos/src/kmain.rs index ed8297b0..9ad76b5a 100644 --- a/ableos/src/kmain.rs +++ b/ableos/src/kmain.rs @@ -1,5 +1,6 @@ #![allow(clippy::empty_loop)] +use crate::experiments::absi::colorify; use { crate::{ arch::{drivers::graphics::GraphicsBuffer, init, sloop}, @@ -12,7 +13,6 @@ use { alloc::vec, lazy_static::lazy_static, }; - #[no_mangle] #[allow(unconditional_recursion)] pub extern "C" fn stack_overflow() -> u8 { @@ -31,6 +31,7 @@ lazy_static! { #[no_mangle] pub fn kernel_main() -> ! { init::init(); + let mut a_thread = Thread::new(); a_thread.new_task(test_fn); @@ -46,6 +47,8 @@ pub fn kernel_main() -> ! { println!("{} v{}", RELEASE_TYPE, KERNEL_VERSION); info!("{} v{}", RELEASE_TYPE, KERNEL_VERSION); + colorify("$PINK$Hi$RED$ from$GREEN$ able"); + // stack_overflow(); // crate::arch::shutdown(); sloop() diff --git a/ableos/src/lib.rs b/ableos/src/lib.rs index bbf413c2..d3e9b44d 100644 --- a/ableos/src/lib.rs +++ b/ableos/src/lib.rs @@ -39,7 +39,6 @@ pub mod kmain; pub mod panic; pub mod relib; pub mod scheduler; -pub mod test; pub mod wasm; extern crate alloc; diff --git a/ableos/src/wasm/mod.rs b/ableos/src/wasm/mod.rs index a4113723..d2777dcd 100644 --- a/ableos/src/wasm/mod.rs +++ b/ableos/src/wasm/mod.rs @@ -72,7 +72,7 @@ impl ModuleImportResolver for HostFunctions { } pub fn evaluate() { - let wasm_binary = include_bytes!("rust.wasm"); + let wasm_binary = include_bytes!("zig.wasm"); // Load wasm binary and prepare it for instantiation. let module = wasmi::Module::from_buffer(&wasm_binary).expect("failed to load wasm"); diff --git a/ableos/src/wasm/wasm_sys.rs b/ableos/src/wasm/wasm_sys.rs index def69e05..7ee8b458 100644 --- a/ableos/src/wasm/wasm_sys.rs +++ b/ableos/src/wasm/wasm_sys.rs @@ -37,11 +37,22 @@ syscall_enum! { GET_PID=6, // Get the proccess ID PROCESS_INFO=7, // Get information about the process //scheduler Related Syscals - GET_PRIORITY=10, // Get scheduler priority - SET_PRIORITY=11, // Set scheduler priority + GET_PRIORITY=8, // Get scheduler priority + SET_PRIORITY=9, // Set scheduler priority // - GET_HOSTNAME=12, - SET_HOSTNAME=13, + GET_HOSTNAME=10, + SET_HOSTNAME=11, + + + NEW_THREAD=12, + NEW_TASK=13, + KILL_THREAD=14, + KILL_TASK=15, + GET_THREAD=16, + GET_TASK=17, + SEND= 18, + RECEIVE = 19, + RESPOND = 20, //File Related syscalls // @@ -65,7 +76,6 @@ syscall_enum! { GET_TIME=36, // Gets the system time (some derivitive of seconds) SET_TIME=37, // Sets the system time (some derivitive of seconds) - // Socket SysCall SOCKET_BIND=39, // Used by servers to lock a port SOCKET_CONNECT=40, @@ -73,6 +83,9 @@ syscall_enum! { SOCKET_SEND=42, SOCKET_RECEIVE=43, + + + EXIT=50, EMPTY=0xFFFF, } diff --git a/ableos/src/wasm/zig.wasm b/ableos/src/wasm/zig.wasm new file mode 100644 index 0000000000000000000000000000000000000000..72a2519ad086066f6414443d70dea65caf7beac9 GIT binary patch literal 402 zcmZvXKTpFj5XJB8{3%IMfepmq2nHl}P{*hP3*X`DCMFGa?8tG2n9`9C!H30d*x-hf ze(#;$>46+N1OS||HNYBhuZdbyw@y`_-u9;Qtu^H3Mk|ClQ9W4NN>gjaF$*ZY zBxP#O&WRdrH&W9^4vO=fXscvDQ54+i`^0fbI%Q6nWUq`t{(|XvcL)OolotgG5V$Lt zVD~4n#DWVZ_!FB8_Q2*v6prGc#P3BSlIci9iyWRKBRhq+|5e4`rs);Jf{v}L9rd;~ aUOBiq>z%Flm2v~lv^33LHVXM_xr84;lxENX literal 0 HcmV?d00001