1
0
Fork 0
forked from koniifer/ableos

workspace

This commit is contained in:
Able 2022-04-11 13:53:33 -05:00
parent 762e6a27ea
commit d78bb002f3
19 changed files with 1143 additions and 201 deletions

2
.gitignore vendored
View file

@ -7,4 +7,6 @@ qprofiler
userland/*/target userland/*/target
kernel/target kernel/target
userland/root_fs/mnt/* userland/root_fs/mnt/*
target/
!*/.gitkeep !*/.gitkeep

1065
Cargo.lock generated Normal file

File diff suppressed because it is too large Load diff

10
Cargo.toml Normal file
View file

@ -0,0 +1,10 @@
[workspace]
members = [
"ableos",
"kernel",
"facepalm",
"shadeable",
"repbuild",
]

24
ableos/Cargo.lock generated
View file

@ -117,7 +117,7 @@ dependencies = [
"hashbrown 0.7.2", "hashbrown 0.7.2",
"log", "log",
"logos", "logos",
"versioning 0.1.2 (git+https://git.ablecorp.us/able/aos_userland)", "versioning",
] ]
[[package]] [[package]]
@ -308,7 +308,7 @@ version = "0.1.2"
dependencies = [ dependencies = [
"lazy_static", "lazy_static",
"log", "log",
"versioning 0.1.2 (git+https://git.ablecorp.us/able/versioning)", "versioning",
] ]
[[package]] [[package]]
@ -571,11 +571,12 @@ checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b"
[[package]] [[package]]
name = "rhai" name = "rhai"
version = "1.5.0" version = "1.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49c94fda0280985896ed6d8bf0b43bbb5a7f0e39ccc8728ac907ddb4f06dae94" checksum = "8ef3d57e55ca044c53ced279d2d3ee9df229b247556b005a23713d5206a2ecfc"
dependencies = [ dependencies = [
"ahash 0.7.6", "ahash 0.7.6",
"bitflags",
"core-error", "core-error",
"instant", "instant",
"libm", "libm",
@ -588,9 +589,9 @@ dependencies = [
[[package]] [[package]]
name = "rhai_codegen" name = "rhai_codegen"
version = "1.3.0" version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e02d33d76a7aa8ec72ac8298d5b52134fd2dff77445ada0c65f6f8c40d8f2931" checksum = "faa0ff1c9dc19c9f8bba510a2a75d3f0449f6233570c2672c7e31c692a11a59a"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -705,11 +706,13 @@ checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83"
[[package]] [[package]]
name = "smartstring" name = "smartstring"
version = "0.2.10" version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e714dff2b33f2321fdcd475b71cec79781a692d846f37f415fb395a1d2bcd48e" checksum = "3fb72c633efbaa2dd666986505016c32c3044395ceaf881518399d2f4127ee29"
dependencies = [ dependencies = [
"autocfg",
"static_assertions", "static_assertions",
"version_check",
] ]
[[package]] [[package]]
@ -819,11 +822,6 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "versioning"
version = "0.1.2"
source = "git+https://git.ablecorp.us/able/versioning#b86e53ab8461ee4f28807bf2254d543f6d8f4727"
[[package]] [[package]]
name = "vga" name = "vga"
version = "0.2.7" version = "0.2.7"

View file

@ -50,10 +50,10 @@ spin = "0.5.2"
log = "*" log = "*"
pretty-hex = "0.2.1" pretty-hex = "0.2.1"
unicode-width = "0.1.7" unicode-width = "0.1.7"
picorand = "*" picorand = "0.1.0"
watson = "0.4" watson = "0.4"
genfs = "0.1.0" genfs = "0.1.0"
rhai = "1.5" rhai = "1.6.0"
libwasm = {git="https://git.ablecorp.us:443/able/libwasm.git"} libwasm = {git="https://git.ablecorp.us:443/able/libwasm.git"}
acpi = "4.1.0" acpi = "4.1.0"

View file

@ -56,15 +56,19 @@ lazy_static! {
idt idt
}; };
} }
extern "x86-interrupt" fn breakpoint_handler(stack_frame: InterruptStackFrame) { extern "x86-interrupt" fn breakpoint_handler(stack_frame: InterruptStackFrame) {
println!("EXCEPTION: BREAKPOINT\n{:#?}", stack_frame); println!("EXCEPTION: BREAKPOINT\n{:#?}", stack_frame);
} }
// new // new
extern "x86-interrupt" fn double_fault_handler( extern "x86-interrupt" fn double_fault_handler(
stack_frame: InterruptStackFrame, stack_frame: InterruptStackFrame,
_error_code: u64, error_code: u64,
) -> ! { ) -> ! {
panic!("EXCEPTION: DOUBLE FAULT\n{:#?}", stack_frame); panic!(
"EXCEPTION: Error code{}\nDOUBLE FAULT\n{:#?}",
error_code, stack_frame
);
} }
extern "x86-interrupt" fn timer_interrupt_handler(_stack_frame: InterruptStackFrame) { extern "x86-interrupt" fn timer_interrupt_handler(_stack_frame: InterruptStackFrame) {
kernel::tick(); kernel::tick();

View file

@ -51,7 +51,7 @@ pub fn cpu_socket_startup() {
} }
pub fn log_version_data() { pub fn log_version_data() {
info!("{} v{}", RELEASE_TYPE, KERNEL_VERSION); info!("{} v{:?}", RELEASE_TYPE, KERNEL_VERSION);
info!( info!(
"Brand String: {}", "Brand String: {}",
master().unwrap().brand_string().unwrap() master().unwrap().brand_string().unwrap()

View file

@ -58,7 +58,6 @@ pub mod kernel_state;
pub mod keyboard; pub mod keyboard;
pub mod kmain; pub mod kmain;
pub mod logger; pub mod logger;
pub mod proto_filetable;
pub mod relib; pub mod relib;
pub mod scheduler; pub mod scheduler;
mod unicode_utils; mod unicode_utils;
@ -79,7 +78,6 @@ pub use graphics::*;
pub use kernel_state::*; pub use kernel_state::*;
pub use keyboard::*; pub use keyboard::*;
pub use logger::*; pub use logger::*;
pub use proto_filetable::*;
pub use relib::*; pub use relib::*;
// pub use scheduler::*; // pub use scheduler::*;
pub use utils::*; pub use utils::*;

View file

@ -46,6 +46,5 @@ macro_rules! print {
macro_rules! println { macro_rules! println {
($($tt:tt)*) => { ($($tt:tt)*) => {
::core::writeln!($crate::print::Stdout, $($tt)*) ::core::writeln!($crate::print::Stdout, $($tt)*)
// panic![];
}; };
} }

View file

@ -1,5 +0,0 @@
use crate::ProtoFileTable;
lazy_static::lazy_static!(
pub static ref FILE_TABLE: spin::Mutex<ProtoFileTable> = spin::Mutex::new(ProtoFileTable::new());
);

View file

@ -1,82 +0,0 @@
use core::fmt;
#[derive(Debug, PartialEq, Clone)]
pub struct PathRep {
pub location: FileLocations,
pub file_name: String,
}
#[derive(Debug)]
pub struct FilePermissions {
pub read: bool,
pub write: bool,
pub execute: bool,
}
#[derive(Debug)]
pub struct FileMetadata {
pub file_type: String,
pub size: usize,
// pub permissions: FilePermissions,
}
#[derive(Debug, Clone, PartialEq)]
pub enum FileLocations {
Bin,
Config,
Home,
}
impl fmt::Display for FileLocations {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{:?}", self)
}
}
#[derive(Debug)]
pub struct File {
pub location: FileLocations,
pub file_name: String,
pub meta_data: FileMetadata,
pub data_pointer: Vec<u8>,
}
impl File {
/// Write the provided bytes to a file
pub fn write_bytes(&mut self, bytes: &[u8]) {
for byte in bytes {
self.data_pointer.push(*byte);
}
self.meta_data.size = self.data_pointer.len();
}
pub fn new(location: FileLocations, file_name: String, file_type: String) -> Self {
let bytes: Vec<u8> = vec![];
let abc123 = bytes;
Self {
location,
file_name,
meta_data: FileMetadata { file_type, size: 0 },
data_pointer: abc123,
}
}
pub fn size(&self) -> usize {
self.meta_data.size.clone()
}
pub fn read_to_string(&mut self, _string: &mut String) {
todo!();
}
pub fn read_and_return(&mut self) -> String {
String::from_utf8(self.data_pointer.clone()).expect("Found invalid UTF-8")
}
}
impl fmt::Display for File {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}://{}", self.location, self.file_name)
}
}

View file

@ -1,56 +0,0 @@
//! A file table module for AbleOS
//!
//! This module provides a file table interface for AbleOS.
//!
//! # Examples
//! ```
//! use relib::filesystem::ProtoFileTable;
//! let mut file_table = ProtoFileTable::new();
//! file_table.add_file("test.txt", "Hello, world!".as_bytes());
//! let file = file_table.get_file("test.txt");
//! assert_eq!(file.unwrap().as_slice(), "Hello, world!".as_bytes());
//! ```
//! # Notes
//! The file table is a simple in-memory hashmap.
//! The file table is not thread safe.
//! The file table is not persistent.
use hashbrown::HashMap;
pub mod contain;
pub mod file;
use file::File;
/// A prototype file table for AbleOS
///
/// This module provides a file table interface for AbleOS.
///
/// # Examples
/// ```
/// use crate::filesystem::ProtoFileTable;
/// let mut file_table = ProtoFileTable::new();
/// file_table.add_file("test.txt", "Hello, world!".as_bytes());
/// let file = file_table.get_file("test.txt");
/// assert_eq!(file.unwrap().as_slice(), "Hello, world!".as_bytes());
/// ```
pub struct ProtoFileTable {
files: HashMap<String, File>,
}
impl ProtoFileTable {
pub fn new() -> ProtoFileTable {
ProtoFileTable {
files: HashMap::new(),
}
}
pub fn add_file(&mut self, path: &str, contents: File) {
self.files.insert(path.to_string(), contents);
}
pub fn get_file(&self, path: &str) -> Option<&File> {
self.files.get(path)
}
}
#[cfg(test)]
mod tests;

View file

@ -1,16 +0,0 @@
use super::file::FileLocations;
use super::*;
// #[test]
fn test_add_file() {
let mut file_table = ProtoFileTable::new();
let file_to_add = File::new(FileLocations::Bin, "test".to_string(), "txt".to_string());
file_to_add.write_bytes(b"Hello, world!");
file_table.add_file("test", file_to_add);
let file = file_table.get_file("test.txt");
assert_eq!(
file.unwrap().data_pointer.as_slice(),
"Hello, world!".as_bytes()
);
}

View file

@ -43,6 +43,5 @@ macro_rules! serial_print {
macro_rules! serial_println { macro_rules! serial_println {
($($tt:tt)*) => { ($($tt:tt)*) => {
::core::writeln!($crate::serial_print::Serialout, $($tt)*) ::core::writeln!($crate::serial_print::Serialout, $($tt)*)
// panic![];
}; };
} }

View file

@ -14,6 +14,8 @@ const GET_RANDOM_INDEX: usize = 3;
const GET_INPUT_INDEX: usize = 4; const GET_INPUT_INDEX: usize = 4;
const PRINT_CLEVER_HACK: usize = 5;
impl Externals for HostExternals { impl Externals for HostExternals {
fn invoke_index( fn invoke_index(
&mut self, &mut self,
@ -25,21 +27,21 @@ impl Externals for HostExternals {
let a: u32 = args.nth_checked(0)?; let a: u32 = args.nth_checked(0)?;
let b: u32 = args.nth_checked(1)?; let b: u32 = args.nth_checked(1)?;
let result = a + b; let result = a + b;
println!("SYSCALL: {} + {} = {}", a, b, result); trace!("SYSCALL: {} + {} = {}", a, b, result);
Ok(Some(RuntimeValue::I32(result as i32))) Ok(Some(RuntimeValue::I32(result as i32)))
} }
SEND_SIGNAL_INDEX => { SEND_SIGNAL_INDEX => {
let pid: u32 = args.nth_checked(0)?; let pid: u32 = args.nth_checked(0)?;
let signal: u32 = args.nth_checked(1)?; let signal: u32 = args.nth_checked(1)?;
println!("SYSCALL: send signal {} to pid {}", signal, pid); trace!("SYSCALL: send signal {} to pid {}", signal, pid);
let ret = RuntimeValue::I32(0); let ret = RuntimeValue::I32(0);
Ok(Some(ret)) Ok(Some(ret))
} }
GET_TIME_INDEX => { GET_TIME_INDEX => {
use core::sync::atomic::Ordering::*; use core::sync::atomic::Ordering::*;
println!("SYSCALL: get time"); trace!("SYSCALL: get time");
x86_64::instructions::interrupts::disable(); x86_64::instructions::interrupts::disable();
let tick_time = kernel::TICK.load(Relaxed); let tick_time = kernel::TICK.load(Relaxed);
x86_64::instructions::interrupts::enable(); x86_64::instructions::interrupts::enable();
@ -48,7 +50,7 @@ impl Externals for HostExternals {
Ok(Some(ret)) Ok(Some(ret))
} }
GET_RANDOM_INDEX => { GET_RANDOM_INDEX => {
println!("SYSCALL: get random"); trace!("SYSCALL: get random");
let rand = generate_process_pass(); let rand = generate_process_pass();
let ret = RuntimeValue::I32(rand as i32); let ret = RuntimeValue::I32(rand as i32);
@ -58,11 +60,10 @@ impl Externals for HostExternals {
} }
GET_INPUT_INDEX => { GET_INPUT_INDEX => {
// println!("SYSCALL: get input");
let input = let input =
x86_64::instructions::interrupts::without_interrupts(|| KEYBUFF.lock().pop()); x86_64::instructions::interrupts::without_interrupts(|| KEYBUFF.lock().pop());
if let Some(chr) = input { if let Some(chr) = input {
println!("SYSCALL: input: {}", chr); trace!("SYSCALL: input: {}", chr);
} }
let ret = RuntimeValue::I32(input.unwrap_or(0x00 as char) as i32); let ret = RuntimeValue::I32(input.unwrap_or(0x00 as char) as i32);
@ -70,7 +71,24 @@ impl Externals for HostExternals {
Ok(Some(ret)) Ok(Some(ret))
} }
_ => panic!("Unimplemented function at {}", index), PRINT_CLEVER_HACK => {
// println!("SYSCALL: print clever hack");
let combinated = args.nth_checked::<u64>(0).unwrap().to_le_bytes();
for x in combinated.iter() {
let chr = *x as char;
print!("{}", chr);
}
println!("\n");
Ok(None)
}
_ => {
error!("Unimplemented function at {}", index);
Err(Trap::new(wasmi::TrapKind::Unreachable))
}
} }
} }
} }
@ -129,7 +147,6 @@ impl HostExternals {
} }
return true; return true;
} }
GET_RANDOM_INDEX => { GET_RANDOM_INDEX => {
let (params, ret_ty): (&[ValueType], Option<ValueType>) = let (params, ret_ty): (&[ValueType], Option<ValueType>) =
(&[], Some(ValueType::I32)); (&[], Some(ValueType::I32));
@ -162,6 +179,22 @@ impl HostExternals {
} }
return true; return true;
} }
PRINT_CLEVER_HACK => {
let (params, ret_ty): (&[ValueType], Option<ValueType>) = (&[ValueType::I64], None);
if params.len() != signature.params().len() {
return false;
}
if ret_ty != signature.return_type() {
return false;
}
for (ty, param) in params.iter().zip(signature.params()) {
if *ty != *param {
return false;
}
}
return true;
}
_ => false, _ => false,
} }
} }
@ -175,6 +208,7 @@ impl ModuleImportResolver for HostExternals {
"get_time" => GET_TIME_INDEX, "get_time" => GET_TIME_INDEX,
"get_random" => GET_RANDOM_INDEX, "get_random" => GET_RANDOM_INDEX,
"get_input" => GET_INPUT_INDEX, "get_input" => GET_INPUT_INDEX,
"print_clever_hack" => PRINT_CLEVER_HACK,
_ => { _ => {
return Err(Error::Instantiation(format!( return Err(Error::Instantiation(format!(
"Export {} not found", "Export {} not found",
@ -192,11 +226,6 @@ impl ModuleImportResolver for HostExternals {
trace!("Resolved export {} as func {}", field_name, index); trace!("Resolved export {} as func {}", field_name, index);
Ok(FuncInstance::alloc_host(signature.clone(), index)) Ok(FuncInstance::alloc_host(signature.clone(), index))
/*Ok(FuncInstance::alloc_host(
Signature::new(&[ValueType::I32, ValueType::I32][..], Some(ValueType::I32)),
index,
))*/
} }
} }
use crate::wasm_jumploader::host_functions::ValueType::I32; use crate::wasm_jumploader::host_functions::ValueType::I32;

View file

@ -32,12 +32,10 @@ pub fn interp() {
// Instantiate a module with empty imports and // Instantiate a module with empty imports and
// assert that there is no `start` function. // assert that there is no `start` function.
let instance = ModuleInstance::new(&module, &imports); // .expect("failed to instantiate wasm module") let instance = ModuleInstance::new(&module, &imports); // .expect("failed to instantiate wasm module")
// .assert_no_start();
match instance { match instance {
Ok(inst) => { Ok(inst) => {
let mut instance = inst.assert_no_start(); let mut instance = inst.assert_no_start();
// trace!("Instantiated wasm module");
let mut is_driver = false; let mut is_driver = false;
let mut is_program = false; let mut is_program = false;
@ -54,7 +52,6 @@ pub fn interp() {
has_driver_exit = true; has_driver_exit = true;
} }
// trace!("Checking for start function");
match instance.export_by_name("start") { match instance.export_by_name("start") {
Some(val) => { Some(val) => {
trace!("Program start function found"); trace!("Program start function found");

View file

@ -12,4 +12,4 @@ version = "1.4.0"
default-features = false default-features = false
[dependencies.versioning] [dependencies.versioning]
git = "https://git.ablecorp.us/able/versioning" git = "https://git.ablecorp.us/able/aos_userland"

View file

@ -2,11 +2,11 @@
use core::panic::PanicInfo; use core::panic::PanicInfo;
// #[macro_use] // #[macro_use]
// use log; use log::error;
#[panic_handler] #[panic_handler]
fn panic_handler(_info: &PanicInfo) -> ! { fn panic_handler(info: &PanicInfo) -> ! {
// error!("{}", _info); error!("{}", info);
loop {} loop {}
} }

Binary file not shown.