minor changes

master
Able 2022-02-12 03:25:02 -06:00
parent d62790586a
commit a0f220d597
Signed by untrusted user: able
GPG Key ID: D164AF5F5700BE51
29 changed files with 220 additions and 199 deletions

View File

@ -1,6 +1,3 @@
[build]
target = "./json_targets/x86_64-ableos.json"
@ -8,7 +5,6 @@ target = "./json_targets/x86_64-ableos.json"
build-std = ["core", "compiler_builtins", "alloc"]
build-std-features = ["compiler-builtins-mem"]
[target.'cfg(target_arch = "x86_64")']
rustflags = ["-C", "target-feature=+rdrnd"]
runner = "bootimage runner"

21
ableos/Cargo.lock generated
View File

@ -36,10 +36,12 @@ dependencies = [
"genfs",
"hashbrown",
"lazy_static",
"libwasm",
"linked_list_allocator",
"lliw",
"log",
"pc-beeper",
"pci",
"pic8259",
"picorand",
"pretty-hex",
@ -50,7 +52,6 @@ dependencies = [
"shadeable",
"smoltcp",
"spin 0.5.2",
"tinypci",
"uart_16550",
"unicode-width",
"vga",
@ -276,6 +277,11 @@ version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33a33a362ce288760ec6a508b94caaec573ae7d3bbbd91b87aa0bad4456839db"
[[package]]
name = "libwasm"
version = "0.1.0"
source = "git+https://git.ablecorp.us/able/libwasm.git#a89b8fc701ba0196cc9cca9989d9beb93d02a317"
[[package]]
name = "linked_list_allocator"
version = "0.9.1"
@ -387,6 +393,14 @@ dependencies = [
"x86_64",
]
[[package]]
name = "pci"
version = "0.0.1"
source = "git+https://gitlab.com/robigalia/pci#4e2fddc61825568b1d14d09fdc669389e6c43f02"
dependencies = [
"bitflags",
]
[[package]]
name = "pic8259"
version = "0.10.2"
@ -669,11 +683,6 @@ dependencies = [
"crunchy",
]
[[package]]
name = "tinypci"
version = "0.1.0"
source = "git+https://github.com/trashbyte/tinypci.git#5e1bc4cf7ae4edb8d524a5e7e71a1ace9c4850fc"
[[package]]
name = "ttf-parser"
version = "0.14.0"

View File

@ -12,16 +12,20 @@ run-args = [
"-cpu",
"Broadwell-v3",
"-serial",
"stdio",
"-smp",
"cores=2",
"-vga",
"qxl",
# An example gpu used with ableOS
# "-device",
# "virtio-gpu",
"-device",
"virtio-gpu",
# An example disk used with ableOS
"-device",
@ -49,9 +53,6 @@ lliw = "0.2.0"
spin = "0.5.2"
vga = "*"
log = "*"
# tinypci = "0.1.0"
tinypci = { git = "https://github.com/trashbyte/tinypci.git", default-features = false }
pretty-hex = "0.2.1"
unicode-width = "0.1.7"
@ -63,10 +64,17 @@ genfs = "0.1.0"
pc-beeper = {git = "https://github.com/AbleOS/pc-beeper"}
pci = {git="https://gitlab.com/robigalia/pci"}
libwasm = {git="https://git.ablecorp.us:443/able/libwasm.git"}
acpi = "4.1.0"
# [dependencies.ockam]
# version = "0.46.0"
# no-default-features = false
# features = ["alloc"]
[dependencies.rdrand]
version = "0.8.1"
default-features = false

View File

@ -1,3 +0,0 @@
wgpu
write using wgpu and compiles to native/web

View File

@ -1,9 +0,0 @@
Don't keep piling on API shit
Good docs are a must!!!!!!!!!!!!
No Bloat
One thing One Way
Bloat makes M!nt sad
Have rust-like strings only
# Don't
memory gun

View File

@ -1 +0,0 @@
start custom unicode at E100

View File

@ -1,3 +0,0 @@
user
> execute
> file system

View File

View File

@ -1,17 +0,0 @@
VGA
pcie
gpu
amd
ati
set_red
ssd

View File

@ -2,6 +2,8 @@ use alloc::string::String;
use crate::character_device::CharacterDevice;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct DevNull;
impl CharacterDevice for DevNull {

View File

@ -1,5 +1,6 @@
use crate::character_device::CharacterDevice;
#[derive(Debug)]
pub struct DevUnicode {
pub next_write_char: char,
pub next_read_char: char,

View File

@ -1,5 +1,6 @@
use crate::character_device::CharacterDevice;
#[derive(Debug)]
pub struct DevZero;
impl CharacterDevice for DevZero {

View File

@ -0,0 +1,3 @@
pub mod dev_null;
pub mod dev_unicode;
pub mod dev_zero;

View File

@ -1,19 +1,20 @@
pub mod character_devs;
pub mod pci_inner;
use alloc::{
boxed::Box,
string::{String, ToString},
};
use hashbrown::HashMap;
use pci::PCIDevice;
use crate::character_device::CharacterDevice;
pub mod dev_null;
pub mod dev_unicode;
pub mod dev_zero;
// FIXME: This is a hack to hold a device.
// #[derive(Debug)]
pub enum Device {
CharacterDevice(Box<dyn CharacterDevice>),
// BlockDevice,
Character(Box<dyn CharacterDevice>),
Pci(PCIDevice),
}
unsafe impl Sync for Device {}
unsafe impl Send for Device {}
@ -21,16 +22,25 @@ unsafe impl Send for Device {}
pub struct DeviceTable {
pub devices: HashMap<String, Device>,
}
use self::dev_null::DevNull;
use self::character_devs::{dev_null::DevNull, dev_unicode::DevUnicode, dev_zero::DevZero};
pub use self::Device::*;
impl DeviceTable {
pub fn new() -> Self {
let mut table: HashMap<String, Device> = HashMap::new();
table.insert("null".to_string(), CharacterDevice(Box::new(DevNull)));
table.insert("null".to_string(), Character(Box::new(DevNull)));
table.insert("zero".to_string(), Character(Box::new(DevZero)));
table.insert(
"unicode".to_string(),
Character(Box::new(DevUnicode {
next_write_char: 0x00 as char,
next_read_char: 0x00 as char,
})),
);
DeviceTable { devices: table }
}
}
lazy_static::lazy_static!(
static ref DEVICE_TABLE: DeviceTable = DeviceTable::new();
pub static ref DEVICE_TABLE: spin::Mutex<DeviceTable> =
spin::Mutex::new(DeviceTable::new());
);

View File

@ -0,0 +1,56 @@
//! map the DeviceClass via <https://pci-ids.ucw.cz/read/PD>
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum DeviceClass {
UnclassifiedDevice = 0,
MassStorageController = 0x01,
NetworkController = 0x02,
DisplayController = 0x03,
MultimediaController = 0x04,
MemoryController = 0x05,
BridgeDevice = 0x06,
CommunicationController = 0x07,
GenericSystemPeripheral = 0x08,
InputDevice = 0x09,
DockingStation = 0x0a,
Processor = 0x0b,
SerialBusController = 0x0c,
WirelessController = 0x0d,
IntelligentController = 0x0e,
SatelliteCommunicationController = 0x0f,
EncryptionController = 0x10,
SignalProcessingController = 0x11,
// 14
// 15
// 16
Coprocessor = 40,
// 64
}
impl DeviceClass {
pub fn from_u8(val: u8) -> DeviceClass {
match val {
0x00 => DeviceClass::UnclassifiedDevice,
0x01 => DeviceClass::MassStorageController,
0x02 => DeviceClass::NetworkController,
0x03 => DeviceClass::DisplayController,
0x04 => DeviceClass::MultimediaController,
0x05 => DeviceClass::MemoryController,
0x06 => DeviceClass::BridgeDevice,
0x07 => DeviceClass::CommunicationController,
0x08 => DeviceClass::GenericSystemPeripheral,
0x09 => DeviceClass::InputDevice,
0x0a => DeviceClass::DockingStation,
0x0b => DeviceClass::Processor,
0x0c => DeviceClass::SerialBusController,
0x0d => DeviceClass::WirelessController,
0x0e => DeviceClass::IntelligentController,
0x0f => DeviceClass::SatelliteCommunicationController,
0x10 => DeviceClass::EncryptionController,
0x11 => DeviceClass::SignalProcessingController,
0x40 => DeviceClass::Coprocessor,
_ => DeviceClass::UnclassifiedDevice,
}
}
}

View File

@ -32,6 +32,7 @@ pub mod arch;
#[macro_use]
pub mod print;
pub mod devices;
pub mod wasm_jumploader;
#[macro_use]
@ -89,9 +90,9 @@ pub use alias_table::*;
pub mod tests;
pub use tests::*;
pub mod syscalls;
/*pub mod syscalls;
pub use syscalls::*;
*/
pub mod scratchpad;
pub use scratchpad::*;
pub mod filesystem;

View File

@ -6,7 +6,7 @@
//! The scheduler is also responsible for choosing the priority of a process.
//! The scheduler is responsible for choosing which process to execute next.
use alloc::vec::Vec;
use alloc::{string::ToString, vec::Vec};
pub mod capabilities;
pub mod proc;
@ -120,6 +120,7 @@ impl Scheduler {
password: generate_process_pass(),
capabilities: Capabilities::empty(),
priority,
working_dir: "todo!()".to_string(),
};
// self.free_pid.0 += 1;
// self.list.push(process);

View File

@ -1,4 +1,4 @@
use alloc::vec::Vec;
use alloc::{string::ToString, vec::Vec};
use crate::{
capabilities::Capabilities,
@ -70,6 +70,7 @@ impl Scheduler {
password: generate_process_pass(),
priority,
capabilities: Capabilities::empty(),
working_dir: "todo!()".to_string(),
};
self.free_pid.0 += 1;
process

View File

@ -1,5 +1,7 @@
//! Process definition and general utilities surrounding them
use alloc::string::String;
use super::{capabilities::Capabilities, Priority};
/// Process Identification
@ -15,11 +17,13 @@ pub struct Process {
/// Process password
pub password: u128,
///
pub capabilities: Capabilities,
/// A process's priority
pub priority: Priority,
///
pub working_dir: String,
}
impl Process {}

View File

@ -1,27 +1,88 @@
use alloc::{string::String, vec::Vec};
use genfs::{Fs, OpenOptions};
use crate::{filesystem::FILE_SYSTEM, wasm_jumploader::interp};
use {
crate::{
devices::{pci_inner::DeviceClass, Device, DEVICE_TABLE},
proc::PID,
wasm_jumploader::interp,
},
alloc::{format, vec::Vec},
pci::PortOps,
};
/// Experimental scratchpad for testing.
pub fn scratchpad() {
let fs = &*FILE_SYSTEM.lock();
let file = fs
.open(b"/home/able/kernel.md", OpenOptions::new().read(true))
.unwrap();
let mut dev_list = Vec::new();
let bus_scan;
unsafe {
bus_scan = pci::scan_bus(&PciIO {}, pci::CSpaceAccessMethod::IO);
}
for dev in bus_scan {
dev_list.push(dev);
}
let mut file_bytes = Vec::new();
file.read_to_end(&mut file_bytes).unwrap();
let device_table = &mut *DEVICE_TABLE.lock();
let string = String::from_utf8_lossy(&file_bytes);
for x in dev_list {
let device_name = format!("{:?}-{}", DeviceClass::from_u8(x.id.class), x.id.device_id);
print!("{}", string);
device_table.devices.insert(device_name, Device::Pci(x));
}
let pci_list = tinypci::brute_force_scan();
for pci in pci_list {
info!("{}", pci);
for (key, _value) in device_table.devices.iter() {
debug!("{}", key);
}
interp();
}
pub struct PciIO {}
impl PortOps for PciIO {
unsafe fn read8(&self, port: u16) -> u8 {
cpuio::inb(port as u16)
}
unsafe fn read16(&self, port: u16) -> u16 {
cpuio::inw(port as u16)
}
unsafe fn read32(&self, port: u16) -> u32 {
cpuio::inl(port as u16)
}
unsafe fn write8(&self, port: u16, val: u8) {
cpuio::outb(val, port as u16);
}
unsafe fn write16(&self, port: u16, val: u16) {
cpuio::outw(val, port as u16);
}
unsafe fn write32(&self, port: u16, val: u32) {
cpuio::outl(val, port as u16);
}
}
/// An experimental process message format
pub struct ProcessMessage {
pub to_pid: PID,
pub from_pid: PID,
pub message: [u8; 2048],
pub sender_time: SecondsTime,
}
//
use libwasm::syscalls::time_calls::SecondsTime;
impl ProcessMessage {
pub fn new(to_pid: PID, from_pid: PID, message: [u8; 2048]) -> Self {
ProcessMessage {
to_pid,
from_pid,
message,
sender_time: SecondsTime {
seconds: 0,
milliseconds: 0,
},
}
}
}

View File

@ -1,43 +0,0 @@
//! File system related system calls.
/// Temporary representation of a file path
pub type Path = *const u8;
/// Remove a Directory from the filesystem
///
/// # Arguments
/// * `full_path` - The full path of the directory to remove
/// * `force` - Whether to remove the directory even if it is not empty
#[no_mangle]
pub extern "C" fn remove_directory(path: Path, force_delete: bool) {
unimplemented!();
}
/// Create a new directory at the given path
///
/// # Arguments
/// * `full_path` - The full path of the directory to create
#[no_mangle]
pub extern "C" fn create_directory(path: Path) -> FSReturns {
unimplemented!();
}
#[repr(C)]
/// A return used by the file related system calls
pub enum FSReturns {
/// The system call was successful
Ok,
/// The directory can not be created
DirectoryCouldNotBeCreated,
/// The directory could not be removed
DirectoryCouldNotBeRemoved,
///
FileCouldNotBeCreated,
///
FileCouldNotBeRemoved,
/// The file could not be opened
FileCouldNotBeOpened,
///
FileCouldNotBeClosed,
}

View File

@ -1,27 +0,0 @@
#![deny(missing_docs)]
//! The module of syscalls.
use crate::proc::PID;
pub mod file_calls;
pub mod time_calls;
#[repr(C)]
/// Signals that can be sent to a process
pub enum Signals {
/// Terminate the process
Terminate,
/// Shutdown the process and allow it to shutdown cleanly
Quit,
}
/// Send a signal to a process
///
/// # Arguments
///
/// * `pid` - The PID of the process to send the signal to
/// * `signal` - The signal to send
#[no_mangle]
pub extern "C" fn send_signal(pid: PID, signal: Signals) {
unimplemented!("send_signal");
}

View File

@ -1,28 +0,0 @@
//! Time related system calls.
use core::panic;
/// Seconds and milliseconds since the Unix epoch.
#[repr(C)]
pub struct SecondsTime {
seconds: u64,
milliseconds: u64,
}
/// Sleep the calling process for the given number of milliseconds
#[no_mangle]
pub extern "C" fn sleep(time: SecondsTime) {
panic!("sleep is not implemented yet");
}
#[no_mangle]
/// Get the current time in seconds, milliseconds
pub extern "C" fn get_time() -> SecondsTime {
panic!("get_time not implemented");
}
#[no_mangle]
/// Set the current time in seconds, milliseconds
pub extern "C" fn set_time(time: SecondsTime) {
panic!("set_time not implemented");
}

View File

@ -4,9 +4,7 @@ use wasmi::{
Signature, Trap, ValueType,
};
pub struct HostExternals {
// counter: usize,
}
pub struct HostExternals {}
const ADD_FUNC_INDEX: usize = 0;
@ -21,7 +19,7 @@ impl Externals for HostExternals {
let a: u32 = args.nth_checked(0)?;
let b: u32 = args.nth_checked(1)?;
let result = a + b;
println!("SYSCALL: {} + {} = {}", a, b, result);
Ok(Some(RuntimeValue::I32(result as i32)))
}
_ => panic!("Unimplemented function at {}", index),

View File

@ -5,21 +5,22 @@ extern crate wasmi;
use alloc::vec::Vec;
use genfs::{Fs, OpenOptions};
use wasmi::{ImportsBuilder, ModuleInstance, NopExternals};
use wasmi::{ImportsBuilder, ModuleInstance};
use crate::{filesystem::FILE_SYSTEM, wasm_jumploader::host_functions::HostExternals};
pub fn interp() {
info!("Interpreting...");
let fs = &*FILE_SYSTEM.lock();
info!("Got filesystem");
let file = fs
.open(b"/home/able/test.wasm", OpenOptions::new().read(true))
.open(b"/home/able/bins/test.wasm", OpenOptions::new().read(true))
.unwrap();
let mut wasm_binary = Vec::new();
let ret = file.read_to_end(&mut wasm_binary).unwrap();
info!("Binary size {}", ret);
// Load wasm binary and prepare it for instantiation.
let module = wasmi::Module::from_buffer(&wasm_binary).expect("failed to load wasm");
@ -35,5 +36,5 @@ pub fn interp() {
.invoke_export("start", &[], &mut HostExternals {})
.expect("failed to execute export");
info!("collected wasm return value: {:?}", ret);
println!("collected wasm return value: {:?}", ret);
}

View File

@ -5,3 +5,11 @@ version = 3
[[package]]
name = "aos_wasm_stress_test"
version = "0.1.0"
dependencies = [
"libwasm",
]
[[package]]
name = "libwasm"
version = "0.1.0"
source = "git+https://git.ablecorp.us/able/libwasm.git#502187e8734b54df3c6cae2baf2315539a3ec49b"

View File

@ -6,3 +6,4 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
libwasm = {git="https://git.ablecorp.us:443/able/libwasm.git"}

View File

@ -2,21 +2,11 @@
#![no_main]
#![deny(improper_ctypes)]
#[macro_use]
mod libwasm;
#[no_mangle]
fn start() -> i32 {
let ret = unsafe { add(1, 2) };
info!(b"hello");
ret as i32
}
use core::panic::PanicInfo;
#[panic_handler]
fn panic(_info: &PanicInfo) -> ! {
loop {}
}
use libwasm::syscalls::add;

Binary file not shown.