2022-03-11 17:13:41 -06:00
|
|
|
#[cfg(target_arch = "riscv64")]
|
|
|
|
pub fn shell() {}
|
|
|
|
|
|
|
|
#[cfg(target_arch = "x86_64")]
|
|
|
|
pub fn shell() {
|
2022-02-19 09:07:33 -06:00
|
|
|
let engine = engine_construction();
|
2022-02-19 08:46:11 -06:00
|
|
|
let mut scope = rhai::Scope::new();
|
|
|
|
|
|
|
|
let mut buf = String::new();
|
|
|
|
print!("> ");
|
|
|
|
|
|
|
|
loop {
|
|
|
|
match x86_64::instructions::interrupts::without_interrupts(|| KEYBUFF.lock().pop()) {
|
|
|
|
Some('\n') => {
|
|
|
|
match engine.eval_with_scope::<rhai::Dynamic>(&mut scope, &buf) {
|
|
|
|
Ok(o) => println!("{o}"),
|
|
|
|
Err(e) => println!("Eval error: {e}"),
|
|
|
|
};
|
|
|
|
|
|
|
|
buf.clear();
|
|
|
|
print!("> ");
|
|
|
|
}
|
|
|
|
Some('\u{0008}') => {
|
|
|
|
buf.pop();
|
|
|
|
}
|
|
|
|
Some(chr) => buf.push(chr),
|
|
|
|
None => (),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lazy_static::lazy_static!(
|
|
|
|
pub static ref KEYBUFF: spin::Mutex<Vec<char>> = spin::Mutex::new(
|
|
|
|
Vec::new())
|
|
|
|
;
|
|
|
|
);
|
|
|
|
|
2022-02-19 09:07:33 -06:00
|
|
|
use rhai::Engine;
|
2022-03-16 05:39:01 -05:00
|
|
|
use x86_64::instructions::interrupts::{disable, enable};
|
2022-02-19 08:46:11 -06:00
|
|
|
|
2022-03-16 05:39:01 -05:00
|
|
|
use crate::info::master;
|
2022-03-11 17:13:41 -06:00
|
|
|
use crate::time::fetch_time;
|
2022-02-26 07:35:36 -06:00
|
|
|
use crate::wasm_jumploader::interp;
|
2022-03-16 05:39:01 -05:00
|
|
|
use crate::{allocator, ALLOCATOR};
|
2022-02-19 08:46:11 -06:00
|
|
|
use crate::{
|
|
|
|
arch::{shutdown, sloop},
|
|
|
|
systeminfo::{KERNEL_VERSION, RELEASE_TYPE},
|
|
|
|
KERNEL_STATE,
|
|
|
|
};
|
|
|
|
|
|
|
|
pub fn afetch() {
|
|
|
|
let kstate = KERNEL_STATE.lock();
|
|
|
|
|
2022-03-11 17:13:41 -06:00
|
|
|
let tick_time = fetch_time();
|
2022-02-19 08:46:11 -06:00
|
|
|
|
2022-03-16 05:39:01 -05:00
|
|
|
disable();
|
|
|
|
let allocator = ALLOCATOR.lock();
|
|
|
|
let size = allocator.size();
|
|
|
|
let used = allocator.used();
|
|
|
|
enable();
|
|
|
|
|
|
|
|
// let mem = format!("{}/{}", used, size);
|
2022-02-23 10:06:27 -06:00
|
|
|
println!(
|
2022-03-16 05:39:01 -05:00
|
|
|
include_str!("balloon.txt"),
|
|
|
|
kstate.hostname,
|
|
|
|
RELEASE_TYPE,
|
|
|
|
KERNEL_VERSION,
|
|
|
|
tick_time,
|
|
|
|
master().unwrap().brand_string().unwrap(),
|
|
|
|
// mem
|
|
|
|
used,
|
|
|
|
size
|
2022-02-23 10:06:27 -06:00
|
|
|
);
|
2022-02-19 08:46:11 -06:00
|
|
|
drop(kstate);
|
|
|
|
}
|
|
|
|
pub fn set_hostname(name: String) {
|
|
|
|
let mut kstate = KERNEL_STATE.lock();
|
|
|
|
kstate.hostname = name;
|
|
|
|
}
|
2022-02-19 09:07:33 -06:00
|
|
|
|
|
|
|
fn engine_construction() -> Engine {
|
|
|
|
let mut engine = rhai::Engine::new();
|
|
|
|
|
|
|
|
engine.on_print(|x| println!("{}", x));
|
|
|
|
|
|
|
|
engine.on_debug(|x, src, pos| {
|
|
|
|
let src = src.unwrap_or("unknown");
|
|
|
|
println!("DEBUG: {} at {:?}: {}", src, pos, x);
|
|
|
|
debug!("{} at {:?}: {}", src, pos, x);
|
|
|
|
});
|
|
|
|
|
|
|
|
engine.register_fn("afetch", afetch);
|
|
|
|
engine.register_fn("set_hostname", set_hostname);
|
|
|
|
engine.register_fn("shutdown", shutdown);
|
2022-02-23 10:06:27 -06:00
|
|
|
engine.register_fn("peek", peek_memory);
|
|
|
|
engine.register_fn("poke", poke_memory);
|
2022-02-26 07:35:36 -06:00
|
|
|
engine.register_fn("sloop", sloop);
|
|
|
|
engine.register_fn("wasm", interp);
|
2022-03-11 13:51:47 -06:00
|
|
|
engine.register_fn("log_dump", log_dump);
|
|
|
|
|
2022-02-19 09:07:33 -06:00
|
|
|
engine
|
|
|
|
}
|
2022-02-23 10:06:27 -06:00
|
|
|
|
|
|
|
/// Examine a memory pointer
|
|
|
|
pub fn peek_memory(ptr: i64) -> u8 {
|
|
|
|
let ptr: usize = ptr as usize;
|
2022-03-11 13:51:47 -06:00
|
|
|
println!(">:(");
|
2022-02-23 10:06:27 -06:00
|
|
|
unsafe { *(ptr as *const u8) }
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn poke_memory(ptr: i64, val: u8) {
|
|
|
|
let ptr: usize = ptr as usize;
|
|
|
|
unsafe { *(ptr as *mut u8) = val }
|
|
|
|
}
|
2022-03-11 13:51:47 -06:00
|
|
|
|
|
|
|
pub fn log_dump() {
|
|
|
|
use crate::network::socket::SimpleSock;
|
|
|
|
use crate::relib::network::socket::Socket;
|
|
|
|
let log_socket_id = SimpleSock::grab_socket("Logger".to_string());
|
|
|
|
match log_socket_id {
|
|
|
|
Some(mut log_socket_id) => {
|
|
|
|
let log = log_socket_id.peek();
|
|
|
|
|
|
|
|
match log {
|
|
|
|
crate::network::socket::SocketReturns::ReadOk(ok) => {
|
|
|
|
for x in ok.iter() {
|
|
|
|
print!("{}", *x as char);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
crate::network::socket::SocketReturns::ReadIndexOutOfBounds => todo!(),
|
|
|
|
crate::network::socket::SocketReturns::WriteOk => todo!(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
None => warn!("No socket found for Logger"),
|
|
|
|
}
|
|
|
|
}
|