2022-07-28 03:39:20 -05:00
|
|
|
use core::fmt::Error;
|
|
|
|
|
2022-06-22 13:59:24 -05:00
|
|
|
// use crate::aalloc::aalloc;
|
2022-04-25 13:39:39 -05:00
|
|
|
use crate::arch::interrupts::{reset_pit_for_cpu, set_pit_2};
|
2022-07-28 05:02:43 -05:00
|
|
|
use crate::arch::{generate_process_pass, shutdown};
|
2022-07-28 03:39:20 -05:00
|
|
|
use crate::channels::{Channel, ChannelPermission};
|
2022-05-12 22:39:13 -05:00
|
|
|
use crate::devices::pci;
|
2022-04-25 15:40:13 -05:00
|
|
|
use crate::filesystem::FILE_SYSTEM;
|
2022-07-28 03:39:20 -05:00
|
|
|
use crate::handle::Handle;
|
2022-07-28 20:15:02 -05:00
|
|
|
use crate::ipc::IPC;
|
2022-04-19 02:15:45 -05:00
|
|
|
use crate::rhai_shell::shell;
|
2022-04-25 15:40:13 -05:00
|
|
|
use crate::rhai_shell::KEYBUFF;
|
2022-07-31 05:22:39 -05:00
|
|
|
use crate::unicode_utils::LAMBDA;
|
2022-07-31 01:54:01 -05:00
|
|
|
use crate::vterm::Term;
|
2022-04-25 04:56:01 -05:00
|
|
|
use crate::wasm_jumploader::run_program;
|
2022-07-31 01:54:01 -05:00
|
|
|
use crate::{vgai, SCREEN_BUFFER};
|
2022-04-19 02:15:45 -05:00
|
|
|
use acpi::{AcpiTables, PlatformInfo};
|
2022-07-28 03:39:20 -05:00
|
|
|
use alloc::collections::{vec_deque, VecDeque};
|
2022-04-25 15:40:13 -05:00
|
|
|
use cpuio::inb;
|
2022-04-25 13:39:39 -05:00
|
|
|
use cpuio::outb;
|
2022-07-28 05:02:43 -05:00
|
|
|
use ext2::fs::sync::{DirectoryEntry, Synced};
|
|
|
|
use ext2::fs::Ext2;
|
|
|
|
use ext2::sector::Size1024;
|
|
|
|
use ext2::sys::inode;
|
2022-04-25 15:40:13 -05:00
|
|
|
use genfs::OpenOptions;
|
2022-07-28 05:02:43 -05:00
|
|
|
use genfs::{DirEntry, Fs};
|
2022-07-27 19:51:13 -05:00
|
|
|
use kernel::proccess::PID;
|
2022-07-29 11:51:54 -05:00
|
|
|
use kernel::software_int;
|
2022-07-31 01:54:01 -05:00
|
|
|
use spin::Lazy;
|
2022-06-02 06:00:26 -05:00
|
|
|
use vga::writers::GraphicsWriter;
|
2022-04-25 15:40:13 -05:00
|
|
|
|
|
|
|
// TODO: move to a better place
|
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
|
|
|
pub struct AcpiStruct {}
|
|
|
|
impl acpi::AcpiHandler for AcpiStruct {
|
|
|
|
unsafe fn map_physical_region<T>(
|
|
|
|
&self,
|
|
|
|
physical_address: usize,
|
|
|
|
size: usize,
|
|
|
|
) -> acpi::PhysicalMapping<Self, T> {
|
|
|
|
info!("PHYS ADDR: {:?}", physical_address);
|
|
|
|
info!("Size: {:?}", size);
|
|
|
|
todo!("map_physical_region");
|
|
|
|
}
|
|
|
|
fn unmap_physical_region<T>(_region: &acpi::PhysicalMapping<Self, T>) {
|
|
|
|
todo!("unmap_physical_region");
|
|
|
|
}
|
|
|
|
}
|
2022-07-31 01:54:01 -05:00
|
|
|
|
|
|
|
pub static TERM: Lazy<spin::Mutex<Term>> = Lazy::new(|| spin::Mutex::new(Term::new()));
|
2022-07-28 03:39:20 -05:00
|
|
|
#[derive(Debug)]
|
2022-04-25 15:40:13 -05:00
|
|
|
|
|
|
|
pub struct Path {
|
|
|
|
pub path: Vec<String>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Path {
|
|
|
|
pub fn new(path: String) -> Self {
|
|
|
|
let mut path_vec_string = vec![];
|
|
|
|
|
|
|
|
for part in path.split(&['\\', '/'][..]) {
|
|
|
|
path_vec_string.push(part.to_string());
|
|
|
|
}
|
|
|
|
|
|
|
|
Path {
|
|
|
|
path: path_vec_string,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-02-08 03:01:29 -06:00
|
|
|
|
|
|
|
/// Experimental scratchpad for testing.
|
|
|
|
pub fn scratchpad() {
|
2022-04-25 04:56:01 -05:00
|
|
|
real_shell();
|
2022-02-08 04:13:53 -06:00
|
|
|
}
|
2022-02-12 03:25:02 -06:00
|
|
|
|
2022-03-11 13:51:47 -06:00
|
|
|
pub fn acpi() {
|
|
|
|
let acpi_handler = AcpiStruct {};
|
|
|
|
let _table;
|
|
|
|
unsafe {
|
|
|
|
_table = AcpiTables::search_for_rsdp_bios(acpi_handler);
|
2022-02-12 03:25:02 -06:00
|
|
|
}
|
2022-04-19 02:15:45 -05:00
|
|
|
match _table.unwrap().platform_info().unwrap() {
|
|
|
|
PlatformInfo {
|
|
|
|
power_profile,
|
|
|
|
interrupt_model,
|
2022-04-25 15:40:13 -05:00
|
|
|
..
|
2022-04-19 02:15:45 -05:00
|
|
|
} => {
|
|
|
|
info!("{:?}", power_profile);
|
|
|
|
info!("{:?}", interrupt_model);
|
|
|
|
// info!("{:?}", processor_info.unwrap());
|
|
|
|
// info!("{:?}", pm_timer.unwrap());
|
|
|
|
}
|
|
|
|
}
|
2022-02-12 03:25:02 -06:00
|
|
|
}
|
2022-04-25 04:56:01 -05:00
|
|
|
|
|
|
|
pub fn real_shell() {
|
2022-07-31 05:22:39 -05:00
|
|
|
let prompt = "-> ";
|
|
|
|
|
2022-04-25 04:56:01 -05:00
|
|
|
let _current_dir = "/".to_string();
|
|
|
|
let current_user = "able".to_string();
|
|
|
|
|
|
|
|
let mut buf = String::new();
|
2022-07-31 05:22:39 -05:00
|
|
|
print!("{}", prompt);
|
2022-04-25 04:56:01 -05:00
|
|
|
|
|
|
|
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}"),
|
|
|
|
// };
|
|
|
|
if !buf.is_empty() {
|
|
|
|
command_parser(current_user.clone(), buf.clone());
|
|
|
|
}
|
|
|
|
|
|
|
|
buf.clear();
|
2022-07-31 05:22:39 -05:00
|
|
|
print!("{}", prompt);
|
2022-04-25 04:56:01 -05:00
|
|
|
}
|
|
|
|
Some('\u{0008}') => {
|
|
|
|
buf.pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
Some('\u{0009}') => {
|
|
|
|
buf.push(' ');
|
|
|
|
buf.push(' ');
|
|
|
|
buf.push(' ');
|
|
|
|
buf.push(' ');
|
|
|
|
}
|
|
|
|
|
|
|
|
Some(chr) => buf.push(chr),
|
|
|
|
None => (),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn command_parser(user: String, command: String) {
|
|
|
|
let fs = &*FILE_SYSTEM.lock();
|
|
|
|
let mut iter = command.split_whitespace();
|
|
|
|
|
2022-07-28 05:02:43 -05:00
|
|
|
// TODO: update the open() function to take either a ableOS path or a b"/" type path
|
|
|
|
let current_path = Path::new("/home/able".to_string());
|
|
|
|
trace!("Current path: {:?}", current_path);
|
|
|
|
let current_path = b"/home/able/";
|
|
|
|
|
2022-04-25 04:56:01 -05:00
|
|
|
let bin_name = iter.next().unwrap();
|
|
|
|
|
2022-07-28 05:02:43 -05:00
|
|
|
match bin_name {
|
|
|
|
"rhai" => {
|
|
|
|
drop(fs);
|
|
|
|
shell();
|
|
|
|
}
|
|
|
|
"list" | "ls" => {
|
|
|
|
for dir_entry in list_files_in_dir(fs, current_path) {
|
|
|
|
println!("{}", dir_entry.file_name_string());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"quit" => shutdown(),
|
2022-04-25 04:56:01 -05:00
|
|
|
|
2022-07-28 05:02:43 -05:00
|
|
|
_ => {
|
|
|
|
let home_exec_path = format!("/home/{}/bins/{}.wasm", user, bin_name);
|
|
|
|
let shared_exec_path = format!("/shared/bins/{}.wasm", bin_name);
|
|
|
|
let system_exec_path = format!("/system/bins/{}.wasm", bin_name);
|
2022-04-25 04:56:01 -05:00
|
|
|
|
2022-07-28 05:02:43 -05:00
|
|
|
let home_exec_file = fs.open(&home_exec_path.as_bytes(), OpenOptions::new().read(true));
|
|
|
|
let shared_exec_file =
|
|
|
|
fs.open(&shared_exec_path.as_bytes(), OpenOptions::new().read(true));
|
|
|
|
let system_exec_file =
|
|
|
|
fs.open(&system_exec_path.as_bytes(), OpenOptions::new().read(true));
|
2022-04-25 04:56:01 -05:00
|
|
|
|
2022-07-28 05:02:43 -05:00
|
|
|
let mut in_home = false;
|
|
|
|
let mut in_shared = false;
|
|
|
|
let mut in_system = false;
|
2022-04-25 04:56:01 -05:00
|
|
|
|
2022-07-28 05:02:43 -05:00
|
|
|
let mut binary_prog: Vec<u8> = vec![];
|
2022-04-25 04:56:01 -05:00
|
|
|
|
2022-07-28 05:02:43 -05:00
|
|
|
match home_exec_file {
|
|
|
|
Ok(file) => {
|
|
|
|
let ret = file.read_to_end(&mut binary_prog).unwrap();
|
|
|
|
in_home = true;
|
|
|
|
}
|
2022-04-25 04:56:01 -05:00
|
|
|
|
2022-07-28 05:02:43 -05:00
|
|
|
Err(error) => {
|
|
|
|
trace!("{:?}", error);
|
|
|
|
in_home = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
match shared_exec_file {
|
|
|
|
Ok(file) => {
|
|
|
|
let ret = file.read_to_end(&mut binary_prog).unwrap();
|
|
|
|
in_shared = true;
|
|
|
|
}
|
|
|
|
Err(error) => {
|
|
|
|
trace!("{:?}", error);
|
|
|
|
in_shared = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
match system_exec_file {
|
|
|
|
Ok(file) => {
|
|
|
|
let ret = file.read_to_end(&mut binary_prog).unwrap();
|
|
|
|
in_system = true;
|
|
|
|
}
|
2022-04-25 04:56:01 -05:00
|
|
|
|
2022-07-28 05:02:43 -05:00
|
|
|
Err(error) => {
|
|
|
|
trace!("{:?}", error);
|
|
|
|
in_system = false;
|
|
|
|
}
|
|
|
|
}
|
2022-04-25 04:56:01 -05:00
|
|
|
|
2022-07-28 05:02:43 -05:00
|
|
|
let args = iter.collect::<Vec<&str>>();
|
|
|
|
println!("{:?}", args);
|
|
|
|
if in_home || in_shared || in_system {
|
|
|
|
run_program(&binary_prog);
|
|
|
|
} else {
|
|
|
|
println!("No such binary: {}", bin_name);
|
|
|
|
error!("No such binary: {}", bin_name);
|
|
|
|
}
|
|
|
|
}
|
2022-04-25 04:56:01 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-25 13:39:39 -05:00
|
|
|
pub fn sound(n_frequency: u32) {
|
|
|
|
let div: u32;
|
|
|
|
let tmp: u8;
|
|
|
|
|
|
|
|
div = 1193180 / n_frequency;
|
|
|
|
unsafe {
|
|
|
|
outb(0xb6, 0x43);
|
|
|
|
|
|
|
|
set_pit_2(div);
|
|
|
|
|
|
|
|
//And play the sound using the PC speaker
|
|
|
|
tmp = inb(0x61);
|
|
|
|
if tmp != (tmp | 3) {
|
|
|
|
outb(tmp | 3, 0x61);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn sound_off() {
|
|
|
|
unsafe {
|
|
|
|
let tmp = inb(0x61) & 0xFC;
|
|
|
|
outb(tmp, 0x61)
|
|
|
|
};
|
|
|
|
reset_pit_for_cpu();
|
|
|
|
}
|
2022-07-28 05:02:43 -05:00
|
|
|
|
|
|
|
pub fn list_files_in_dir(fs: &Synced<Ext2<Size1024, Vec<u8>>>, path: &[u8]) -> Vec<DirectoryEntry> {
|
|
|
|
let mut entry_list = vec![];
|
|
|
|
|
|
|
|
let dirr = fs.read_dir(b"/").unwrap();
|
|
|
|
for dir_entry in dirr {
|
|
|
|
entry_list.push(dir_entry.unwrap());
|
|
|
|
}
|
|
|
|
|
|
|
|
entry_list
|
|
|
|
}
|