Add command loop
This commit is contained in:
parent
a073ceb272
commit
f42a3879cc
|
@ -92,16 +92,25 @@ impl Console {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A command prompt. Currently does nothing.
|
/// A command prompt. Currently does nothing.
|
||||||
pub fn command_prompt(&self) -> ! {
|
pub fn command_prompt<'a>(&self, buf: &'a mut [u8]) -> &'a [u8] {
|
||||||
self.puts("\n$> ");
|
self.puts("\n$> ");
|
||||||
|
|
||||||
|
let mut i = 0;
|
||||||
let mut input;
|
let mut input;
|
||||||
loop {
|
loop {
|
||||||
input = self.getc();
|
input = self.getc();
|
||||||
|
|
||||||
if input == '\n' {
|
if input == '\n' {
|
||||||
self.puts("\n$> ")
|
self.putc('\n');
|
||||||
|
return &buf[..i];
|
||||||
} else {
|
} else {
|
||||||
|
if i < buf.len() {
|
||||||
|
buf[i] = input as u8;
|
||||||
|
i += 1;
|
||||||
|
} else {
|
||||||
|
return &buf[..i];
|
||||||
|
}
|
||||||
|
|
||||||
self.putc(input);
|
self.putc(input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
40
src/main.rs
40
src/main.rs
|
@ -7,6 +7,7 @@
|
||||||
#![feature(lang_items)]
|
#![feature(lang_items)]
|
||||||
#![feature(ptr_internals)] // until we mark with PhantomData instead?
|
#![feature(ptr_internals)] // until we mark with PhantomData instead?
|
||||||
#![feature(core_intrinsics)]
|
#![feature(core_intrinsics)]
|
||||||
|
#![feature(range_contains)]
|
||||||
#![feature(try_from)]
|
#![feature(try_from)]
|
||||||
#![doc(html_root_url = "https://docs.metta.systems/")]
|
#![doc(html_root_url = "https://docs.metta.systems/")]
|
||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
|
@ -127,6 +128,34 @@ fn kmain() -> ! {
|
||||||
display.draw_text(170, 70, "BLUE", Color::blue());
|
display.draw_text(170, 70, "BLUE", Color::blue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------------
|
||||||
|
// Start a command prompt
|
||||||
|
//------------------------------------------------------------
|
||||||
|
'cmd_loop: loop {
|
||||||
|
let mut buf = [0u8; 64];
|
||||||
|
|
||||||
|
match CONSOLE.lock(|c| c.command_prompt(&mut buf)) {
|
||||||
|
b"trap" => check_data_abort_trap(),
|
||||||
|
b"map" => arch::memory::print_layout(),
|
||||||
|
b"help" => print_help(),
|
||||||
|
b"end" => break 'cmd_loop,
|
||||||
|
x => println!("Unknown command {:?}, try 'help'", x),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// writeln!(uart, "Bye, going to sleep now");
|
||||||
|
// qemu_aarch64_exit()
|
||||||
|
endless_sleep()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn print_help() {
|
||||||
|
println!("Supported console commands:");
|
||||||
|
println!(" trap - cause and recover from a data abort exception");
|
||||||
|
println!(" map - show kernel memory layout");
|
||||||
|
println!(" end - leave console and lock up");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn check_data_abort_trap() {
|
||||||
// Cause an exception by accessing a virtual address for which no
|
// Cause an exception by accessing a virtual address for which no
|
||||||
// address translations have been set up.
|
// address translations have been set up.
|
||||||
//
|
//
|
||||||
|
@ -136,17 +165,6 @@ fn kmain() -> ! {
|
||||||
unsafe { core::ptr::read_volatile(big_addr as *mut u64) };
|
unsafe { core::ptr::read_volatile(big_addr as *mut u64) };
|
||||||
|
|
||||||
println!("[i] Whoa! We recovered from an exception.");
|
println!("[i] Whoa! We recovered from an exception.");
|
||||||
|
|
||||||
//------------------------------------------------------------
|
|
||||||
// Start a command prompt
|
|
||||||
//------------------------------------------------------------
|
|
||||||
CONSOLE.lock(|c| {
|
|
||||||
c.command_prompt();
|
|
||||||
});
|
|
||||||
|
|
||||||
// writeln!(uart, "Bye, going to sleep now");
|
|
||||||
// qemu_aarch64_exit()
|
|
||||||
endless_sleep()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
entry!(kmain);
|
entry!(kmain);
|
||||||
|
|
Loading…
Reference in New Issue