Skip to content

Commit 75820d7

Browse files
author
Matthew
committed
added echo command, and framework for commands
1 parent 3ea0177 commit 75820d7

26 files changed

+546
-53
lines changed

Cargo.lock

+47
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ volatile = "0.2.6"
1414
spin = "0.7.0"
1515
x86_64 = "0.12.2"
1616
uart_16550 = "0.2.10"
17+
linked_list_allocator = "0.8.6"
1718
ksh = { path = "./crates/ksh"}
1819
kopy_keyboard = { path = "./crates/kopy_keyboard"}
1920
kopy_core = { path = "./crates/kopy_core" }

crates/kopy_asm/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ extern "C" {
1010
}
1111

1212
pub fn add() -> u64 {
13-
let sum = unsafe { _my_adder(5, 10) };
13+
let sum = unsafe { _my_adder(12, 23) };
1414
sum
1515
}

crates/kopy_core/src/vga_buffer.rs

+19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
extern crate alloc;
2+
3+
use alloc::string::{String, ToString};
14
use core::fmt;
25
use core::fmt::Write;
6+
use core::ops::Add;
37
use lazy_static::lazy_static;
48
use spin::Mutex;
59
use volatile::Volatile;
@@ -118,6 +122,15 @@ impl Writer {
118122
}
119123
}
120124

125+
pub fn read_line(&mut self) -> String {
126+
let mut line: String = " ".to_string();
127+
for char in 0..BUFFER_WIDTH {
128+
let screen_char = self.buffer.chars[BUFFER_HEIGHT - 1][char].read();
129+
line.push(char::from(screen_char.ascii_character));
130+
}
131+
line.trim().to_string()
132+
}
133+
121134
pub fn delete_last_character(&mut self) {
122135
let blank = ScreenChar {
123136
ascii_character: b' ',
@@ -152,6 +165,12 @@ macro_rules! println {
152165
($($arg:tt)*) => ($crate::print!("{}\n", format_args!($($arg)*)));
153166
}
154167

168+
#[macro_export]
169+
macro_rules! eprintln {
170+
() => ($crate::print!("ERROR: \n"));
171+
($($arg:tt)*) => ($crate::print!("ERROR: {}\n", format_args!($($arg)*)));
172+
}
173+
155174
#[doc(hidden)]
156175
pub fn _print(args: fmt::Arguments) {
157176
interrupts::without_interrupts(|| {

crates/kopy_events/Cargo.lock

+60-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/kopy_events/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ edition = "2018"
88

99
[dependencies]
1010
spin = "0.7.0"
11-
lazy_static = "1.4.0"
11+
lazy_static = "1.4.0"
12+
kopy_core = { path = "./../kopy_core" }
+4-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
use crate::Notifier;
2+
use kopy_core::vga_buffer::Buffer;
23
use lazy_static::lazy_static;
34
use spin::Mutex;
45

56
lazy_static! {
67
pub static ref KEYBOARD_NOTIFIER: Mutex<Notifier<KeyboardEvent>> = Mutex::new(Notifier::new());
78
}
89

9-
pub struct KeyboardEvent {}
10+
pub struct KeyboardEvent {
11+
pub key: char,
12+
}

crates/kopy_events/src/lib.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
pub mod events;
55

6+
extern crate alloc;
7+
68
use alloc::boxed::Box;
79
use alloc::vec::Vec;
810
use lazy_static::lazy_static;
@@ -31,8 +33,4 @@ impl<E> Notifier<E> {
3133
callback(&event);
3234
}
3335
}
34-
35-
pub fn dispatch(&self, event: E) {
36-
self.notify(E)
37-
}
3836
}

crates/kopy_keyboard/Cargo.lock

+13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/kopy_keyboard/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ pc-keyboard = "0.5.0"
1111
spin = "0.7.0"
1212
x86_64 = "0.12.2"
1313
kopy_core = {path = "./../kopy_core"}
14+
kopy_events = { path = "./../kopy_events" }
1415
ksh = {path = "./../ksh"}
1516
lazy_static = "1.4.0"

crates/kopy_keyboard/src/lib.rs

+13-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![no_std]
22

33
use kopy_core::{print, vga_buffer::WRITER};
4+
use kopy_events::events::keyboard::{KeyboardEvent, KEYBOARD_NOTIFIER};
45
use lazy_static::lazy_static;
56
use pc_keyboard::{layouts, DecodedKey, HandleControl, Keyboard, ScancodeSet1};
67
use spin::Mutex;
@@ -24,11 +25,18 @@ pub fn handle_key_event(mut port: Port<u8>) {
2425
'\u{8}' => interrupts::without_interrupts(|| {
2526
WRITER.lock().delete_last_character();
2627
}),
27-
'\n' => interrupts::without_interrupts(|| {
28-
ksh::handle_line(WRITER.lock().buffer);
29-
ksh::new_line();
30-
}),
31-
_ => print!("{}", character),
28+
// '\n' => interrupts::without_interrupts(|| {
29+
// KEYBOARD_NOTIFIER.lock().notify(KeyboardEvent {
30+
// ksh::handle_line(WRITER.lock().buffer);
31+
// ksh::new_line();})
32+
// }),
33+
_ => {
34+
interrupts::without_interrupts(|| {
35+
KEYBOARD_NOTIFIER
36+
.lock()
37+
.notify(KeyboardEvent { key: character })
38+
});
39+
}
3240
},
3341
DecodedKey::RawKey(key) => match key {
3442
_ => print!("{:?}", key),

crates/ksh/Cargo.lock

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/ksh/Cargo.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@ edition = "2018"
88

99
[dependencies]
1010
kopy_core = { path = "./../kopy_core" }
11-
kopy_asm = { path = "./../kopy_asm" }
11+
kopy_asm = { path = "./../kopy_asm" }
12+
kopy_events = { path = "./../kopy_events" }
13+
x86_64 = "0.12.2"
14+
lazy_static = "1.4.0"

0 commit comments

Comments
 (0)