forked from AbleOS/holey-bytes
bye stuff
This commit is contained in:
parent
006dcca309
commit
26105bab70
55
Cargo.lock
generated
55
Cargo.lock
generated
|
@ -47,25 +47,6 @@ version = "1.0.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "convert_case"
|
|
||||||
version = "0.4.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "derive_more"
|
|
||||||
version = "0.99.17"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321"
|
|
||||||
dependencies = [
|
|
||||||
"convert_case",
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"rustc_version",
|
|
||||||
"syn 1.0.109",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fnv"
|
name = "fnv"
|
||||||
version = "1.0.7"
|
version = "1.0.7"
|
||||||
|
@ -113,9 +94,7 @@ version = "0.1.0"
|
||||||
name = "hbvm"
|
name = "hbvm"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"derive_more",
|
|
||||||
"hbbytecode",
|
"hbbytecode",
|
||||||
"static_assertions",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -168,7 +147,7 @@ dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"regex-syntax",
|
"regex-syntax",
|
||||||
"syn 2.0.29",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -216,38 +195,6 @@ version = "0.6.29"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1"
|
checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "rustc_version"
|
|
||||||
version = "0.4.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366"
|
|
||||||
dependencies = [
|
|
||||||
"semver",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "semver"
|
|
||||||
version = "1.0.18"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "static_assertions"
|
|
||||||
version = "1.1.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "syn"
|
|
||||||
version = "1.0.109"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"unicode-ident",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "2.0.29"
|
version = "2.0.29"
|
||||||
|
|
|
@ -12,6 +12,4 @@ alloc = []
|
||||||
nightly = []
|
nightly = []
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
derive_more = "0.99"
|
hbbytecode.path = "../hbbytecode"
|
||||||
hbbytecode.path = "../hbbytecode"
|
|
||||||
static_assertions = "1.0"
|
|
||||||
|
|
|
@ -24,6 +24,7 @@ pub mod value;
|
||||||
|
|
||||||
mod bmc;
|
mod bmc;
|
||||||
mod vmrun;
|
mod vmrun;
|
||||||
|
mod utils;
|
||||||
|
|
||||||
use {bmc::BlockCopier, value::Value};
|
use {bmc::BlockCopier, value::Value};
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
//! Virtual(?) memory address
|
//! Virtual(?) memory address
|
||||||
|
|
||||||
use {
|
use core::{fmt::Debug, ops};
|
||||||
core::{fmt::Debug, ops},
|
|
||||||
derive_more::Display,
|
use crate::utils::impl_display;
|
||||||
};
|
|
||||||
|
|
||||||
/// Memory address
|
/// Memory address
|
||||||
#[derive(Clone, Copy, Display, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
#[display(fmt = "{_0:x}")]
|
|
||||||
pub struct Address(u64);
|
pub struct Address(u64);
|
||||||
impl Address {
|
impl Address {
|
||||||
/// A null address
|
/// A null address
|
||||||
|
@ -49,6 +47,10 @@ impl Address {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl_display!(for Address =>
|
||||||
|
|Address(a)| "{a:0x}"
|
||||||
|
);
|
||||||
|
|
||||||
impl<T: AddressOp> ops::Add<T> for Address {
|
impl<T: AddressOp> ops::Add<T> for Address {
|
||||||
type Output = Self;
|
type Output = Self;
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,8 @@ pub mod softpaging;
|
||||||
mod addr;
|
mod addr;
|
||||||
|
|
||||||
pub use addr::Address;
|
pub use addr::Address;
|
||||||
use {derive_more::Display, hbbytecode::ProgramVal};
|
|
||||||
|
use {crate::utils::impl_display, hbbytecode::ProgramVal};
|
||||||
|
|
||||||
/// Load-store memory access
|
/// Load-store memory access
|
||||||
pub trait Memory {
|
pub trait Memory {
|
||||||
|
@ -45,17 +46,21 @@ pub trait Memory {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Unhandled load access trap
|
/// Unhandled load access trap
|
||||||
#[derive(Clone, Copy, Display, Debug, PartialEq, Eq)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||||
#[display(fmt = "Load access error at address {_0}")]
|
|
||||||
pub struct LoadError(pub Address);
|
pub struct LoadError(pub Address);
|
||||||
|
impl_display!(for LoadError =>
|
||||||
|
|LoadError(a)| "Load access error at address {a}",
|
||||||
|
);
|
||||||
|
|
||||||
/// Unhandled store access trap
|
/// Unhandled store access trap
|
||||||
#[derive(Clone, Copy, Display, Debug, PartialEq, Eq)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||||
#[display(fmt = "Store access error at address {_0}")]
|
|
||||||
pub struct StoreError(pub Address);
|
pub struct StoreError(pub Address);
|
||||||
|
impl_display!(for StoreError =>
|
||||||
|
|StoreError(a)| "Load access error at address {a}",
|
||||||
|
);
|
||||||
|
|
||||||
/// Reason to access memory
|
/// Reason to access memory
|
||||||
#[derive(Clone, Copy, Display, Debug, PartialEq, Eq)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||||
pub enum MemoryAccessReason {
|
pub enum MemoryAccessReason {
|
||||||
/// Memory was accessed for load (read)
|
/// Memory was accessed for load (read)
|
||||||
Load,
|
Load,
|
||||||
|
@ -63,6 +68,11 @@ pub enum MemoryAccessReason {
|
||||||
Store,
|
Store,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl_display!(for MemoryAccessReason => match {
|
||||||
|
Self::Load => "Load";
|
||||||
|
Self::Store => "Store";
|
||||||
|
});
|
||||||
|
|
||||||
impl From<LoadError> for crate::VmRunError {
|
impl From<LoadError> for crate::VmRunError {
|
||||||
fn from(value: LoadError) -> Self {
|
fn from(value: LoadError) -> Self {
|
||||||
Self::LoadAccessEx(value.0)
|
Self::LoadAccessEx(value.0)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
//! Automatic memory mapping
|
//! Automatic memory mapping
|
||||||
|
|
||||||
use crate::mem::addr::Address;
|
use crate::{mem::addr::Address, utils::impl_display};
|
||||||
|
|
||||||
use {
|
use {
|
||||||
super::{
|
super::{
|
||||||
|
@ -9,7 +9,6 @@ use {
|
||||||
PageSize, SoftPagedMem,
|
PageSize, SoftPagedMem,
|
||||||
},
|
},
|
||||||
alloc::boxed::Box,
|
alloc::boxed::Box,
|
||||||
derive_more::Display,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
impl<'p, A, const OUT_PROG_EXEC: bool> SoftPagedMem<'p, A, OUT_PROG_EXEC> {
|
impl<'p, A, const OUT_PROG_EXEC: bool> SoftPagedMem<'p, A, OUT_PROG_EXEC> {
|
||||||
|
@ -143,22 +142,25 @@ impl<'p, A, const OUT_PROG_EXEC: bool> SoftPagedMem<'p, A, OUT_PROG_EXEC> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Error mapping
|
/// Error mapping
|
||||||
#[derive(Clone, Copy, Display, Debug, PartialEq, Eq)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||||
pub enum MapError {
|
pub enum MapError {
|
||||||
/// Entry was already mapped
|
/// Entry was already mapped
|
||||||
#[display(fmt = "There is already a page mapped on specified address")]
|
|
||||||
AlreadyMapped,
|
AlreadyMapped,
|
||||||
/// When walking a page entry was
|
/// When walking a page entry was
|
||||||
/// encounterd.
|
/// encounterd.
|
||||||
#[display(fmt = "There was a page mapped on the way instead of node")]
|
|
||||||
PageOnNode,
|
PageOnNode,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl_display!(for MapError => match {
|
||||||
|
Self::AlreadyMapped => "There is already a page mapped on specified address";
|
||||||
|
Self::PageOnNode => "There was a page mapped on the way instead of node";
|
||||||
|
});
|
||||||
|
|
||||||
/// There was no entry in page table to unmap
|
/// There was no entry in page table to unmap
|
||||||
///
|
///
|
||||||
/// No worry, don't panic, nothing bad has happened,
|
/// No worry, don't panic, nothing bad has happened,
|
||||||
/// but if you are 120% sure there should be something,
|
/// but if you are 120% sure there should be something,
|
||||||
/// double-check your addresses.
|
/// double-check your addresses.
|
||||||
#[derive(Clone, Copy, Display, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
#[display(fmt = "There was no entry to unmap")]
|
|
||||||
pub struct NothingToUnmap;
|
pub struct NothingToUnmap;
|
||||||
|
impl_display!(for NothingToUnmap => "There is no entry to unmap");
|
||||||
|
|
38
hbvm/src/utils.rs
Normal file
38
hbvm/src/utils.rs
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
macro_rules! impl_display {
|
||||||
|
(for $ty:ty => $(|$selfty:pat_param|)? $fmt:literal $(, $($param:expr),+)? $(,)?) => {
|
||||||
|
impl ::core::fmt::Display for $ty {
|
||||||
|
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
|
||||||
|
$(let $selfty = self;)?
|
||||||
|
write!(f, $fmt, $($param),*)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
(for $ty:ty => $str:literal) => {
|
||||||
|
impl ::core::fmt::Display for $ty {
|
||||||
|
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
|
||||||
|
f.write_str($str)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
(for $ty:ty => match {$(
|
||||||
|
$bind:pat => $fmt:literal $(,$($param:expr),* $(,)?)?;
|
||||||
|
)*}) => {
|
||||||
|
impl ::core::fmt::Display for $ty {
|
||||||
|
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
|
||||||
|
match self {
|
||||||
|
$(
|
||||||
|
$bind => write!(f, $fmt, $($($param),*)?)
|
||||||
|
),*
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
macro_rules! static_assert_eq(($l:expr, $r:expr $(,)?) => {
|
||||||
|
const _: [(); ($l != $r) as usize] = [];
|
||||||
|
});
|
||||||
|
|
||||||
|
pub(crate) use {impl_display, static_assert_eq};
|
|
@ -26,7 +26,7 @@ macro_rules! value_def {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static_assertions::const_assert_eq!(
|
crate::utils::static_assert_eq!(
|
||||||
core::mem::size_of::<$ty>(),
|
core::mem::size_of::<$ty>(),
|
||||||
core::mem::size_of::<Value>(),
|
core::mem::size_of::<Value>(),
|
||||||
);
|
);
|
||||||
|
@ -70,7 +70,7 @@ mod private {
|
||||||
}
|
}
|
||||||
|
|
||||||
value_def!(u64, i64, f64);
|
value_def!(u64, i64, f64);
|
||||||
static_assertions::const_assert_eq!(core::mem::size_of::<Value>(), 8);
|
crate::utils::static_assert_eq!(core::mem::size_of::<Value>(), 8);
|
||||||
|
|
||||||
impl core::fmt::Debug for Value {
|
impl core::fmt::Debug for Value {
|
||||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||||
|
|
Loading…
Reference in a new issue