forked from AbleOS/ableos
most recent HBVM works
This commit is contained in:
parent
432af37737
commit
36f2a8336f
120
Cargo.lock
generated
120
Cargo.lock
generated
|
@ -43,6 +43,12 @@ dependencies = [
|
||||||
"memchr",
|
"memchr",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "allocator-api2"
|
||||||
|
version = "0.2.15"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "56fc6cf8dc8c4158eed8649f9b8b0ea1518eb62b544fe9490d66fa0b349eafe9"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "android_system_properties"
|
name = "android_system_properties"
|
||||||
version = "0.1.5"
|
version = "0.1.5"
|
||||||
|
@ -81,6 +87,12 @@ version = "1.2.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7b7e4c2464d97fe331d41de9d5db0def0a96f4d823b8b32a2efd503578988973"
|
checksum = "7b7e4c2464d97fe331d41de9d5db0def0a96f4d823b8b32a2efd503578988973"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "beef"
|
||||||
|
version = "0.5.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3a8241f3ebb85c056b509d4327ad0358fbbba6ffb340bf388f26350aeda225b1"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bit"
|
name = "bit"
|
||||||
version = "0.1.1"
|
version = "0.1.1"
|
||||||
|
@ -158,6 +170,12 @@ dependencies = [
|
||||||
"unicode-width",
|
"unicode-width",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "convert_case"
|
||||||
|
version = "0.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "core-foundation-sys"
|
name = "core-foundation-sys"
|
||||||
version = "0.8.4"
|
version = "0.8.4"
|
||||||
|
@ -227,14 +245,27 @@ dependencies = [
|
||||||
"syn 2.0.13",
|
"syn 2.0.13",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "delegate"
|
||||||
|
version = "0.9.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d358e0ec5c59a5e1603b933def447096886121660fc680dc1e64a0753981fe3c"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 1.0.109",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "derive_more"
|
name = "derive_more"
|
||||||
version = "0.99.17"
|
version = "0.99.17"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321"
|
checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"convert_case",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
|
"rustc_version",
|
||||||
"syn 1.0.109",
|
"syn 1.0.109",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -336,6 +367,12 @@ dependencies = [
|
||||||
"num-traits",
|
"num-traits",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "fnv"
|
||||||
|
version = "1.0.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "getrandom"
|
name = "getrandom"
|
||||||
version = "0.2.8"
|
version = "0.2.8"
|
||||||
|
@ -365,13 +402,45 @@ dependencies = [
|
||||||
"ahash 0.8.3",
|
"ahash 0.8.3",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hashbrown"
|
||||||
|
version = "0.14.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a"
|
||||||
|
dependencies = [
|
||||||
|
"ahash 0.8.3",
|
||||||
|
"allocator-api2",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hbasm"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "git+https://git.ablecorp.us/ableos/holey-bytes#b7c34775e4514c05bf0927bd2bd2f6de90715f0d"
|
||||||
|
dependencies = [
|
||||||
|
"hashbrown 0.14.0",
|
||||||
|
"hbbytecode",
|
||||||
|
"lasso",
|
||||||
|
"logos",
|
||||||
|
"paste",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hbbytecode"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "git+https://git.ablecorp.us/ableos/holey-bytes#b7c34775e4514c05bf0927bd2bd2f6de90715f0d"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hbvm"
|
name = "hbvm"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://git.ablecorp.us/ableos/holey-bytes#76302b4ca8aeda6597ee51cb1cf5f59a5d385c4f"
|
source = "git+https://git.ablecorp.us/ableos/holey-bytes#b7c34775e4514c05bf0927bd2bd2f6de90715f0d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"delegate",
|
||||||
|
"derive_more",
|
||||||
"hashbrown 0.13.2",
|
"hashbrown 0.13.2",
|
||||||
|
"hbbytecode",
|
||||||
"log",
|
"log",
|
||||||
|
"paste",
|
||||||
|
"static_assertions",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -468,6 +537,7 @@ dependencies = [
|
||||||
"embedded-graphics",
|
"embedded-graphics",
|
||||||
"error-stack 0.3.1",
|
"error-stack 0.3.1",
|
||||||
"hashbrown 0.12.3",
|
"hashbrown 0.12.3",
|
||||||
|
"hbasm",
|
||||||
"hbvm",
|
"hbvm",
|
||||||
"limine",
|
"limine",
|
||||||
"log",
|
"log",
|
||||||
|
@ -483,6 +553,16 @@ dependencies = [
|
||||||
"xml",
|
"xml",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "lasso"
|
||||||
|
version = "0.7.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4644821e1c3d7a560fe13d842d13f587c07348a1a05d3a797152d41c90c56df2"
|
||||||
|
dependencies = [
|
||||||
|
"ahash 0.8.3",
|
||||||
|
"hashbrown 0.13.2",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
version = "0.2.141"
|
version = "0.2.141"
|
||||||
|
@ -528,6 +608,38 @@ dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "logos"
|
||||||
|
version = "0.13.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c000ca4d908ff18ac99b93a062cb8958d331c3220719c52e77cb19cc6ac5d2c1"
|
||||||
|
dependencies = [
|
||||||
|
"logos-derive",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "logos-codegen"
|
||||||
|
version = "0.13.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "dc487311295e0002e452025d6b580b77bb17286de87b57138f3b5db711cded68"
|
||||||
|
dependencies = [
|
||||||
|
"beef",
|
||||||
|
"fnv",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"regex-syntax",
|
||||||
|
"syn 2.0.13",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "logos-derive"
|
||||||
|
version = "0.13.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "dbfc0d229f1f42d790440136d941afd806bc9e949e2bcb8faa813b0f00d1267e"
|
||||||
|
dependencies = [
|
||||||
|
"logos-codegen",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "memchr"
|
name = "memchr"
|
||||||
version = "2.5.0"
|
version = "2.5.0"
|
||||||
|
@ -740,6 +852,12 @@ dependencies = [
|
||||||
"lock_api",
|
"lock_api",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "static_assertions"
|
||||||
|
version = "1.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "supports-color"
|
name = "supports-color"
|
||||||
version = "1.3.1"
|
version = "1.3.1"
|
||||||
|
|
|
@ -7,6 +7,8 @@ version = "0.2.0"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
||||||
hbvm = { git = "https://git.ablecorp.us/ableos/holey-bytes" }
|
hbvm = { git = "https://git.ablecorp.us/ableos/holey-bytes" }
|
||||||
|
hbasm = { git = "https://git.ablecorp.us/ableos/holey-bytes" }
|
||||||
|
|
||||||
embedded-graphics = "0.7.1"
|
embedded-graphics = "0.7.1"
|
||||||
|
|
||||||
|
|
||||||
|
|
101
kernel/src/host.rs
Normal file
101
kernel/src/host.rs
Normal file
|
@ -0,0 +1,101 @@
|
||||||
|
//! the system interface
|
||||||
|
|
||||||
|
// use {
|
||||||
|
// crate::ipc::message::Message,
|
||||||
|
// alloc::vec::Vec,
|
||||||
|
// crossbeam_queue::{ArrayQueue, SegQueue},
|
||||||
|
// // hbvm::engine::Engine,
|
||||||
|
// log::trace,
|
||||||
|
// HostError::MemoryError,
|
||||||
|
// };
|
||||||
|
/// Host errors
|
||||||
|
pub enum HostError {
|
||||||
|
/// A host memory error
|
||||||
|
MemoryError,
|
||||||
|
}
|
||||||
|
|
||||||
|
// / Check f0 register for the handle
|
||||||
|
// / check f1 for the message ptr
|
||||||
|
// / check f2 for the message length
|
||||||
|
// pub fn ipc_send(engine: &mut Engine) -> Result<(), HostError> {
|
||||||
|
// let _handle = engine.registers.f0;
|
||||||
|
// let message_start = engine.registers.f1;
|
||||||
|
// let message_length = engine.registers.f2;
|
||||||
|
|
||||||
|
// let mut ipc_msg: Vec<u8> = alloc::vec![];
|
||||||
|
|
||||||
|
// for x in message_start..message_start + message_length {
|
||||||
|
// let byte = engine.read_mem_addr_8(x);
|
||||||
|
// match byte {
|
||||||
|
// Ok(byte) => ipc_msg.push(byte),
|
||||||
|
// Err(_) => return Err(MemoryError),
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// log::trace!("Message bytes {:?}", ipc_msg);
|
||||||
|
// Ok(())
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // pub fn ipc_recv(_engine: &mut Engine) {}
|
||||||
|
|
||||||
|
// /// Check f0 for the buffer type
|
||||||
|
// /// 0 means an unbound buffer
|
||||||
|
// /// 1 means a bound buffer
|
||||||
|
// /// Check f1 if the buffer is bound
|
||||||
|
// ///
|
||||||
|
// /// f2 Return a handle to the sender
|
||||||
|
// /// f3 returns a handle the the reciever
|
||||||
|
// pub fn ipc_mkbuf(engine: &mut Engine) {
|
||||||
|
// match engine.registers.f0 as usize {
|
||||||
|
// 0 => {
|
||||||
|
// trace!("Making a new ipc unbound buffer");
|
||||||
|
// let _buf: SegQueue<Message> = SegQueue::new();
|
||||||
|
// }
|
||||||
|
// 1 => {
|
||||||
|
// let buf_len = engine.registers.f1 as usize;
|
||||||
|
// trace!("Making a new ipc buffer with capacity {}", buf_len);
|
||||||
|
// let _buf: ArrayQueue<Message> = ArrayQueue::new(buf_len);
|
||||||
|
// }
|
||||||
|
// _ => {}
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // pub fn rpc_discover(_engine: &mut Engine) {}
|
||||||
|
// // pub fn rpc_register(_engine: &mut Engine) {}
|
||||||
|
// // pub fn rpc_call(_engine: &mut Engine) {}
|
||||||
|
|
||||||
|
use hbvm::vm::{
|
||||||
|
mem::{Memory, MemoryAccessReason, PageSize},
|
||||||
|
trap::HandleTrap,
|
||||||
|
value::Value,
|
||||||
|
};
|
||||||
|
|
||||||
|
/// AbleOS HBVM traphandler
|
||||||
|
pub struct TrapHandler;
|
||||||
|
impl HandleTrap for TrapHandler {
|
||||||
|
fn page_fault(
|
||||||
|
&mut self,
|
||||||
|
_: MemoryAccessReason,
|
||||||
|
_: &mut Memory,
|
||||||
|
_: u64,
|
||||||
|
_: PageSize,
|
||||||
|
_: *mut u8,
|
||||||
|
) -> bool {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
|
fn invalid_op(&mut self, _: &mut [Value; 256], _: &mut usize, _: &mut Memory, _: u8) -> bool
|
||||||
|
where
|
||||||
|
Self: Sized,
|
||||||
|
{
|
||||||
|
log::trace!("Invalid opcode");
|
||||||
|
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
|
fn ecall(&mut self, _: &mut [Value; 256], _: &mut usize, _: &mut Memory)
|
||||||
|
where
|
||||||
|
Self: Sized,
|
||||||
|
{
|
||||||
|
log::trace!("ableOS system call made");
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,64 +0,0 @@
|
||||||
//! the system interface
|
|
||||||
|
|
||||||
use {
|
|
||||||
crate::ipc::message::Message,
|
|
||||||
alloc::vec::Vec,
|
|
||||||
crossbeam_queue::{ArrayQueue, SegQueue},
|
|
||||||
hbvm::engine::Engine,
|
|
||||||
log::trace,
|
|
||||||
HostError::MemoryError,
|
|
||||||
};
|
|
||||||
/// Host errors
|
|
||||||
pub enum HostError {
|
|
||||||
/// A host memory error
|
|
||||||
MemoryError,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Check f0 register for the handle
|
|
||||||
/// check f1 for the message ptr
|
|
||||||
/// check f2 for the message length
|
|
||||||
pub fn ipc_send(engine: &mut Engine) -> Result<(), HostError> {
|
|
||||||
let _handle = engine.registers.f0;
|
|
||||||
let message_start = engine.registers.f1;
|
|
||||||
let message_length = engine.registers.f2;
|
|
||||||
|
|
||||||
let mut ipc_msg: Vec<u8> = alloc::vec![];
|
|
||||||
|
|
||||||
for x in message_start..message_start + message_length {
|
|
||||||
let byte = engine.read_mem_addr_8(x);
|
|
||||||
match byte {
|
|
||||||
Ok(byte) => ipc_msg.push(byte),
|
|
||||||
Err(_) => return Err(MemoryError),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
log::trace!("Message bytes {:?}", ipc_msg);
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
// pub fn ipc_recv(_engine: &mut Engine) {}
|
|
||||||
|
|
||||||
/// Check f0 for the buffer type
|
|
||||||
/// 0 means an unbound buffer
|
|
||||||
/// 1 means a bound buffer
|
|
||||||
/// Check f1 if the buffer is bound
|
|
||||||
///
|
|
||||||
/// f2 Return a handle to the sender
|
|
||||||
/// f3 returns a handle the the reciever
|
|
||||||
pub fn ipc_mkbuf(engine: &mut Engine) {
|
|
||||||
match engine.registers.f0 as usize {
|
|
||||||
0 => {
|
|
||||||
trace!("Making a new ipc unbound buffer");
|
|
||||||
let _buf: SegQueue<Message> = SegQueue::new();
|
|
||||||
}
|
|
||||||
1 => {
|
|
||||||
let buf_len = engine.registers.f1 as usize;
|
|
||||||
trace!("Making a new ipc buffer with capacity {}", buf_len);
|
|
||||||
let _buf: ArrayQueue<Message> = ArrayQueue::new(buf_len);
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// pub fn rpc_discover(_engine: &mut Engine) {}
|
|
||||||
// pub fn rpc_register(_engine: &mut Engine) {}
|
|
||||||
// pub fn rpc_call(_engine: &mut Engine) {}
|
|
|
@ -3,7 +3,6 @@
|
||||||
use {
|
use {
|
||||||
crate::{alloc::string::ToString, arch::logging::SERIAL_CONSOLE, device_tree::DeviceTree},
|
crate::{alloc::string::ToString, arch::logging::SERIAL_CONSOLE, device_tree::DeviceTree},
|
||||||
clparse::Arguments,
|
clparse::Arguments,
|
||||||
hbvm::engine::Engine,
|
|
||||||
log::{debug, trace},
|
log::{debug, trace},
|
||||||
spin::{Lazy, Mutex},
|
spin::{Lazy, Mutex},
|
||||||
xml::XMLElement,
|
xml::XMLElement,
|
||||||
|
@ -42,12 +41,40 @@ pub fn kmain(cmdline: &str, bootstrap: Option<&'static [u8]>) -> ! {
|
||||||
// TODO: schedule the disk driver from the initramfs
|
// TODO: schedule the disk driver from the initramfs
|
||||||
// TODO: schedule the filesystem driver from the initramfs
|
// TODO: schedule the filesystem driver from the initramfs
|
||||||
// TODO: schedule the init system from the initramfs
|
// TODO: schedule the init system from the initramfs
|
||||||
|
let code = "li r1, 8
|
||||||
|
li r2, 10
|
||||||
|
add r1, r1, r2
|
||||||
|
|
||||||
let bytes = alloc::vec![0];
|
|
||||||
let mut prog = Engine::new(bytes);
|
ecall"
|
||||||
// prog.enviroment_call_table[0] = read_device_tree;
|
.to_string();
|
||||||
let _ = prog.run();
|
|
||||||
prog.dump();
|
let mut prog = alloc::vec![];
|
||||||
|
// TODO: Port hbasm to be fully nostd
|
||||||
|
if let Err(e) = hbasm::assembly(&code, &mut prog) {
|
||||||
|
log::error!(
|
||||||
|
"Error {:?} at {:?} (`{}`)",
|
||||||
|
e.kind,
|
||||||
|
e.span.clone(),
|
||||||
|
&code[e.span],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
use hbvm::validate::validate;
|
||||||
|
|
||||||
|
#[allow(clippy::redundant_else)]
|
||||||
|
if let Err(e) = validate(&prog) {
|
||||||
|
log::error!("Program validation error: {e:?}");
|
||||||
|
} else {
|
||||||
|
log::info!("valid program");
|
||||||
|
unsafe {
|
||||||
|
use {crate::host::TrapHandler, hbvm::vm::Vm};
|
||||||
|
let mut vm = Vm::new_unchecked(&prog, TrapHandler);
|
||||||
|
vm.memory.insert_test_page();
|
||||||
|
log::info!("Program interrupt: {:?}", vm.run());
|
||||||
|
log::info!("{:?}", vm.registers);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: change this to a driver
|
// TODO: change this to a driver
|
||||||
{
|
{
|
||||||
|
|
|
@ -23,7 +23,7 @@ mod allocator;
|
||||||
mod arch;
|
mod arch;
|
||||||
pub mod device_tree;
|
pub mod device_tree;
|
||||||
pub mod handle;
|
pub mod handle;
|
||||||
pub mod host_functions;
|
pub mod host;
|
||||||
pub mod ipc;
|
pub mod ipc;
|
||||||
mod kmain;
|
mod kmain;
|
||||||
mod logger;
|
mod logger;
|
||||||
|
|
Loading…
Reference in a new issue