forked from able/aos_userland
initialize
This commit is contained in:
parent
5b315488dd
commit
0ffd50df94
5
Cargo.toml
Normal file
5
Cargo.toml
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
[workspace]
|
||||||
|
|
||||||
|
members = [
|
||||||
|
"libwasm",
|
||||||
|
]
|
8
libwasm/Cargo.toml
Normal file
8
libwasm/Cargo.toml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
[package]
|
||||||
|
name = "libwasm"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
4
libwasm/src/driver.rs
Normal file
4
libwasm/src/driver.rs
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
pub enum DriverExitCode {
|
||||||
|
Success = 0,
|
||||||
|
Failure = 1,
|
||||||
|
}
|
13
libwasm/src/lib.rs
Normal file
13
libwasm/src/lib.rs
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
#![no_std]
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
pub mod logger;
|
||||||
|
pub mod driver;
|
||||||
|
pub mod process;
|
||||||
|
pub mod syscalls;
|
||||||
|
|
||||||
|
pub use core::*;
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
pub fn get_random() -> u32;
|
||||||
|
}
|
68
libwasm/src/logger/mod.rs
Normal file
68
libwasm/src/logger/mod.rs
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
#![allow(unused_macros)]
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
|
pub enum LogLevel {
|
||||||
|
Error,
|
||||||
|
Warn,
|
||||||
|
Info,
|
||||||
|
Debug,
|
||||||
|
Trace,
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
pub fn host_log(log_level: LogLevel, log_message: *const u8, log_message_len: u32);
|
||||||
|
}
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! log {
|
||||||
|
($a:expr, $b:expr) => {{
|
||||||
|
let log_level: LogLevel = $a;
|
||||||
|
let log_message: &[u8] = $b;
|
||||||
|
|
||||||
|
let pointer = log_message.as_ptr();
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
$crate::logger::host_log(log_level, pointer, log_message.len() as u32);
|
||||||
|
}
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
#[macro_export]
|
||||||
|
|
||||||
|
macro_rules! debug {
|
||||||
|
($a:expr) => {
|
||||||
|
use crate::logger::{LogLevel::*, *};
|
||||||
|
|
||||||
|
log!(Debug, $a);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! error {
|
||||||
|
($a:expr) => {
|
||||||
|
use crate::logger::{LogLevel::*, *};
|
||||||
|
|
||||||
|
log!(Error, $a);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! trace {
|
||||||
|
($a:expr) => {
|
||||||
|
use crate::logger::*;
|
||||||
|
|
||||||
|
log!(Trace, $a);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! warn {
|
||||||
|
($a:expr) => {
|
||||||
|
use crate::logger::{LogLevel::*, *};
|
||||||
|
|
||||||
|
log!(Warn, $a);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! info {
|
||||||
|
($a:expr) => {
|
||||||
|
use crate::logger::{LogLevel::*, *};
|
||||||
|
|
||||||
|
log!(Info, $a);
|
||||||
|
};
|
||||||
|
}
|
6
libwasm/src/process/mod.rs
Normal file
6
libwasm/src/process/mod.rs
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
pub mod signals;
|
||||||
|
|
||||||
|
/// Process Identification
|
||||||
|
#[derive(Clone, Copy, PartialEq, Debug)]
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct PID(pub usize);
|
8
libwasm/src/process/signals.rs
Normal file
8
libwasm/src/process/signals.rs
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
#[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,
|
||||||
|
}
|
43
libwasm/src/syscalls/file_calls.rs
Normal file
43
libwasm/src/syscalls/file_calls.rs
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
//! 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,
|
||||||
|
}
|
24
libwasm/src/syscalls/mod.rs
Normal file
24
libwasm/src/syscalls/mod.rs
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
#![deny(missing_docs)]
|
||||||
|
//! The module of syscalls.
|
||||||
|
|
||||||
|
use crate::process::{signals::Signals, PID};
|
||||||
|
|
||||||
|
pub mod file_calls;
|
||||||
|
pub mod time_calls;
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
/// All system calls are defined here.
|
||||||
|
extern "C" {
|
||||||
|
|
||||||
|
/// Send a signal to a process
|
||||||
|
///
|
||||||
|
/// # Arguments
|
||||||
|
///
|
||||||
|
/// * `pid` - The PID of the process to send the signal to
|
||||||
|
/// * `signal` - The signal to send
|
||||||
|
pub fn send_signal(pid: PID, signal: Signals) -> bool;
|
||||||
|
|
||||||
|
/// A temporary function to test the syscall interface
|
||||||
|
pub fn add(a: u32, b: u32) -> u32;
|
||||||
|
|
||||||
|
}
|
24
libwasm/src/syscalls/time_calls.rs
Normal file
24
libwasm/src/syscalls/time_calls.rs
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
//! Time related system calls.
|
||||||
|
|
||||||
|
/// Seconds and milliseconds since the Unix epoch.
|
||||||
|
#[repr(C)]
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct SecondsTime {
|
||||||
|
/// Seconds
|
||||||
|
pub seconds: u64,
|
||||||
|
/// Milliseconds
|
||||||
|
pub milliseconds: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
/// Sleep the calling process for the given number of milliseconds
|
||||||
|
pub fn sleep(time: SecondsTime);
|
||||||
|
|
||||||
|
/// Get the current time in seconds, milliseconds
|
||||||
|
///
|
||||||
|
/// Temporarily returns an i32 instead of a SecondsTime
|
||||||
|
pub fn get_time() -> i32;
|
||||||
|
|
||||||
|
/// Set the current time in seconds, milliseconds
|
||||||
|
pub fn set_time(time: SecondsTime);
|
||||||
|
}
|
Loading…
Reference in a new issue