mini-shell for 3 cmd. we have to implemente it now
This commit is contained in:
parent
e72afcd086
commit
0e7b73e2fa
4 changed files with 82 additions and 25 deletions
|
|
@ -4,13 +4,13 @@ extern kmain
|
||||||
section .text
|
section .text
|
||||||
bits 32
|
bits 32
|
||||||
x86_start:
|
x86_start:
|
||||||
; we should clear register but it does not work
|
; we should clear register but it does not work, it's okay with 0x10 instead of 0
|
||||||
; mov ax, 0
|
mov ax, 0x10
|
||||||
; mov ss, ax
|
mov ss, ax
|
||||||
; mov ds, ax
|
mov ds, ax
|
||||||
; mov es, ax
|
mov es, ax
|
||||||
; mov fs, ax
|
mov fs, ax
|
||||||
; mov gs, ax
|
mov gs, ax
|
||||||
|
|
||||||
; PRINT OK
|
; PRINT OK
|
||||||
; mov dword [0xb8000], 0x2f4b2f4f
|
; mov dword [0xb8000], 0x2f4b2f4f
|
||||||
|
|
|
||||||
|
|
@ -91,24 +91,18 @@ pub fn kbd_callback() {
|
||||||
Some(b"\0\0") => {
|
Some(b"\0\0") => {
|
||||||
match scancode {
|
match scancode {
|
||||||
0x2A | 0x36 => {SHIFT = !is_release},
|
0x2A | 0x36 => {SHIFT = !is_release},
|
||||||
0x38 => {ALT = !is_release; println!("atl")},
|
0x38 => {ALT = !is_release},
|
||||||
0x1D => {CTRL = !is_release; println!("ctrl")},
|
0x1D => {CTRL = !is_release},
|
||||||
0x0F if !is_release => {
|
0x0F if !is_release => {
|
||||||
CONTEXT.switch_term();
|
CONTEXT.switch_term();
|
||||||
CONTEXT.current_term().flush();
|
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 => {
|
Some(ascii) if !is_release => {
|
||||||
let mut terminal = CONTEXT.current_term();
|
let mut terminal = CONTEXT.current_term();
|
||||||
if SHIFT {
|
if SHIFT {
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,6 @@ mod cpuio;
|
||||||
///
|
///
|
||||||
/// If reboot failed, will loop on a halt cmd
|
/// If reboot failed, will loop on a halt cmd
|
||||||
///
|
///
|
||||||
#[allow(dead_code)]
|
|
||||||
fn reboot() {
|
fn reboot() {
|
||||||
//TODO disable interrupt here something like : asm volatile ("cli");
|
//TODO disable interrupt here something like : asm volatile ("cli");
|
||||||
|
|
||||||
|
|
@ -47,13 +46,19 @@ fn reboot() {
|
||||||
///
|
///
|
||||||
/// If shutdown failed, will loop on a halt cmd
|
/// If shutdown failed, will loop on a halt cmd
|
||||||
///
|
///
|
||||||
#[allow(dead_code)]
|
|
||||||
fn shutdown() -> ! {
|
fn shutdown() -> ! {
|
||||||
cpuio::outb(0xf4, 0x00);//TODO doesn't work :(
|
cpuio::outb(0xf4, 0x00);//TODO doesn't work :(
|
||||||
println!("Reicv shutdown command. System cannot shutdown properly yet, he is now halt\n");
|
println!("Reicv shutdown command. System cannot shutdown properly yet, he is now halt\n");
|
||||||
cpuio::halt();
|
cpuio::halt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Print the kernel stack
|
||||||
|
///
|
||||||
|
fn print_kernel_stack() {
|
||||||
|
println!("It's a stack print");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern fn kmain() -> ! {
|
pub extern fn kmain() -> ! {
|
||||||
unsafe { CONTEXT.current_term().color_code = ColorCode::new(Color::White, Color::Cyan); }
|
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#" ' ,/ ; | .' "#),
|
||||||
format_args!("{: ^80}", r#" '--' `---' "#));
|
format_args!("{: ^80}", r#" '--' `---' "#));
|
||||||
unsafe { CONTEXT.current_term().color_code = ColorCode::new(Color::White, Color::Black); }
|
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 {
|
loop {
|
||||||
keyboard::kbd_callback();
|
keyboard::kbd_callback();
|
||||||
|
|
|
||||||
|
|
@ -44,32 +44,75 @@ pub struct Writer {
|
||||||
pub buffer_pos: usize,
|
pub buffer_pos: usize,
|
||||||
pub color_code: ColorCode,
|
pub color_code: ColorCode,
|
||||||
buffer: [u8; BUFFER_ROWS * BUFFER_COLS],
|
buffer: [u8; BUFFER_ROWS * BUFFER_COLS],
|
||||||
command: [u8; 10],
|
command: [char; 10],
|
||||||
command_len: usize,
|
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 {
|
impl Writer {
|
||||||
pub const fn new() -> Writer {
|
pub const fn new() -> Writer {
|
||||||
Writer {
|
Writer {
|
||||||
buffer_pos: 0,
|
buffer_pos: 0,
|
||||||
color_code: ColorCode::new(Color::White, Color::Black),
|
color_code: ColorCode::new(Color::White, Color::Black),
|
||||||
buffer: [0; BUFFER_ROWS * BUFFER_COLS],
|
buffer: [0; BUFFER_ROWS * BUFFER_COLS],
|
||||||
command: [0; 10],
|
command: NULL,
|
||||||
command_len: 0,
|
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) {
|
pub fn keypress(&mut self, ascii: u8) {
|
||||||
match ascii {
|
match ascii {
|
||||||
b'\n' => {
|
b'\n' => {
|
||||||
self.command_len = 0;
|
self.command_len = 0;
|
||||||
self.write_byte(b'\n');
|
self.write_byte(b'\n');
|
||||||
println!("{:?}", self.command.iter());
|
// println!("{:?}", self.command.iter());
|
||||||
self.write_byte(b'>');
|
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 => {
|
byte => {
|
||||||
if self.command_len >= 10 { return };
|
if self.command_len >= 10 { return };
|
||||||
|
|
||||||
|
self.command[self.command_len] = byte as char;
|
||||||
self.write_byte(byte);
|
self.write_byte(byte);
|
||||||
self.command_len += 1;
|
self.command_len += 1;
|
||||||
}
|
}
|
||||||
|
|
@ -77,6 +120,14 @@ impl Writer {
|
||||||
self.flush();
|
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) {
|
pub fn write_byte(&mut self, byte: u8) {
|
||||||
let i = self.buffer_pos;
|
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)
|
fn flush_cursor(&self)
|
||||||
{
|
{
|
||||||
let cursor_position = self.buffer_pos / 2;
|
let cursor_position = self.buffer_pos / 2;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue