diff --git a/kernel-rs/src/arch/x86/start.asm b/kernel-rs/src/arch/x86/start.asm index 53125fab..0ac7dd3d 100644 --- a/kernel-rs/src/arch/x86/start.asm +++ b/kernel-rs/src/arch/x86/start.asm @@ -4,13 +4,13 @@ extern kmain section .text bits 32 x86_start: -; we should clear register but it does not work -; mov ax, 0 -; mov ss, ax -; mov ds, ax -; mov es, ax -; mov fs, ax -; mov gs, ax +; we should clear register but it does not work, it's okay with 0x10 instead of 0 +mov ax, 0x10 +mov ss, ax +mov ds, ax +mov es, ax +mov fs, ax +mov gs, ax ; PRINT OK ; mov dword [0xb8000], 0x2f4b2f4f diff --git a/kernel-rs/src/keyboard.rs b/kernel-rs/src/keyboard.rs index f874aa8c..acc65937 100644 --- a/kernel-rs/src/keyboard.rs +++ b/kernel-rs/src/keyboard.rs @@ -91,24 +91,18 @@ pub fn kbd_callback() { Some(b"\0\0") => { match scancode { 0x2A | 0x36 => {SHIFT = !is_release}, - 0x38 => {ALT = !is_release; println!("atl")}, - 0x1D => {CTRL = !is_release; println!("ctrl")}, + 0x38 => {ALT = !is_release}, + 0x1D => {CTRL = !is_release}, 0x0F if !is_release => { CONTEXT.switch_term(); CONTEXT.current_term().flush(); }, + 0x0E if !is_release => { + CONTEXT.current_term().backspace(); + } _ => {} } }, - // Some(b"2@") if ALT => { - // CONTEXT.switch_term(); - // CONTEXT.current_term().flush(); - // }, - // Some(b"1!") if CTRL && !is_release => { - // CONTEXT.switch_term(); - // CONTEXT.current_term().keypress('>' as u8); - // CONTEXT.current_term().flush(); - // }, Some(ascii) if !is_release => { let mut terminal = CONTEXT.current_term(); if SHIFT { diff --git a/kernel-rs/src/lib.rs b/kernel-rs/src/lib.rs index 8fcdaedc..d9bbf662 100644 --- a/kernel-rs/src/lib.rs +++ b/kernel-rs/src/lib.rs @@ -25,7 +25,6 @@ mod cpuio; /// /// If reboot failed, will loop on a halt cmd /// -#[allow(dead_code)] fn reboot() { //TODO disable interrupt here something like : asm volatile ("cli"); @@ -47,13 +46,19 @@ fn reboot() { /// /// If shutdown failed, will loop on a halt cmd /// -#[allow(dead_code)] fn shutdown() -> ! { cpuio::outb(0xf4, 0x00);//TODO doesn't work :( println!("Reicv shutdown command. System cannot shutdown properly yet, he is now halt\n"); cpuio::halt(); } +/// Print the kernel stack +/// +fn print_kernel_stack() { + println!("It's a stack print"); + +} + #[no_mangle] pub extern fn kmain() -> ! { unsafe { CONTEXT.current_term().color_code = ColorCode::new(Color::White, Color::Cyan); } @@ -73,7 +78,8 @@ pub extern fn kmain() -> ! { format_args!("{: ^80}", r#" ' ,/ ; | .' "#), format_args!("{: ^80}", r#" '--' `---' "#)); unsafe { CONTEXT.current_term().color_code = ColorCode::new(Color::White, Color::Black); } - print!(">"); + unsafe { CONTEXT.vga1.prompt();CONTEXT.vga1.flush(); } + unsafe { CONTEXT.vga2.prompt(); } loop { keyboard::kbd_callback(); diff --git a/kernel-rs/src/vga/buffer.rs b/kernel-rs/src/vga/buffer.rs index c8aa0643..b454fc1d 100644 --- a/kernel-rs/src/vga/buffer.rs +++ b/kernel-rs/src/vga/buffer.rs @@ -44,32 +44,75 @@ pub struct Writer { pub buffer_pos: usize, pub color_code: ColorCode, buffer: [u8; BUFFER_ROWS * BUFFER_COLS], - command: [u8; 10], + command: [char; 10], command_len: usize, } +// enum shell_command { +// "reboot" => super::reboot(); +// } + +const NULL: [char; 10] = ['\0'; 10]; +const REBOOT: [char; 10] = ['r', 'e', 'b', 'o', 'o', 't', '\0', '\0', '\0', '\0']; +const HALT: [char; 10] = ['h', 'a', 'l', 't', '\0', '\0', '\0', '\0', '\0', '\0']; +const SHUTDOWN: [char; 10] = ['s', 'h', 'u', 't', 'd', 'o', 'w', 'n', '\0', '\0']; +const STACK: [char; 10] = ['s', 't', 'a', 'c', 'k', '\0', '\0', '\0', '\0', '\0']; impl Writer { pub const fn new() -> Writer { Writer { buffer_pos: 0, color_code: ColorCode::new(Color::White, Color::Black), buffer: [0; BUFFER_ROWS * BUFFER_COLS], - command: [0; 10], + command: NULL, command_len: 0, } } + pub fn prompt(&mut self) { + let color_code_save = self.color_code; + self.color_code = ColorCode::new(Color::Blue, Color::Black); + self.write_str("> "); + self.color_code = color_code_save; + } + + pub fn backspace(&mut self) { + if self.command_len > 0 { + self.command_len -= 1; + self.command[self.command_len] = '\0'; + self.erase_byte(); + } + } + pub fn keypress(&mut self, ascii: u8) { match ascii { b'\n' => { self.command_len = 0; self.write_byte(b'\n'); - println!("{:?}", self.command.iter()); - self.write_byte(b'>'); + // println!("{:?}", self.command.iter()); + match self.command { + SHUTDOWN | HALT => { + super::super::shutdown(); + } + REBOOT => { + super::super::reboot(); + } + STACK => { + super::super::print_kernel_stack(); + } + _ => { + let color_code_save = self.color_code; + self.color_code = ColorCode::new(Color::Red, Color::Black); + println!("Command unknown !"); + self.color_code = color_code_save; + } + } + self.command = NULL; + self.prompt(); } byte => { if self.command_len >= 10 { return }; + self.command[self.command_len] = byte as char; self.write_byte(byte); self.command_len += 1; } @@ -77,6 +120,14 @@ impl Writer { self.flush(); } + pub fn erase_byte(&mut self) { + self.buffer_pos -= 2; + let i = self.buffer_pos; + self.buffer[i] = b' '; + self.buffer[i + 1] = 0; + self.flush(); + } + pub fn write_byte(&mut self, byte: u8) { let i = self.buffer_pos; @@ -98,6 +149,12 @@ impl Writer { } } + fn write_str(&mut self, s: &str) { + for byte in s.bytes() { + self.write_byte(byte) + } + } + fn flush_cursor(&self) { let cursor_position = self.buffer_pos / 2;