forked from koniifer/ableos
Public accessors
This commit is contained in:
parent
57f30109c8
commit
9ee3e9cb5f
|
@ -13,7 +13,10 @@
|
|||
#![no_std]
|
||||
#![cfg_attr(feature = "nightly", feature(fn_align))]
|
||||
|
||||
use mem::{Address, Memory};
|
||||
use {
|
||||
mem::{Address, Memory},
|
||||
value::ValueVariant,
|
||||
};
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
extern crate alloc;
|
||||
|
@ -66,6 +69,27 @@ where
|
|||
copier: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Read register
|
||||
#[inline(always)]
|
||||
pub fn read_reg(&self, n: u8) -> Value {
|
||||
unsafe { *self.registers.get_unchecked(n as usize) }
|
||||
}
|
||||
|
||||
/// Write a register.
|
||||
/// Writing to register 0 is no-op.
|
||||
#[inline(always)]
|
||||
pub fn write_reg<T: ValueVariant>(&mut self, n: u8, value: T) {
|
||||
if n != 0 {
|
||||
unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
(&value as *const T).cast::<u8>(),
|
||||
self.registers.as_mut_ptr().add(n.into()).cast::<u8>(),
|
||||
core::mem::size_of::<T>(),
|
||||
);
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Virtual machine halt error
|
||||
|
|
|
@ -3,12 +3,7 @@
|
|||
//! Have fun
|
||||
|
||||
use {
|
||||
super::{
|
||||
bmc::BlockCopier,
|
||||
mem::Memory,
|
||||
value::{Value, ValueVariant},
|
||||
Vm, VmRunError, VmRunOk,
|
||||
},
|
||||
super::{bmc::BlockCopier, mem::Memory, value::ValueVariant, Vm, VmRunError, VmRunOk},
|
||||
crate::{
|
||||
mem::{addr::AddressOp, Address},
|
||||
value::CheckedDivRem,
|
||||
|
@ -534,27 +529,6 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
/// Read register
|
||||
#[inline(always)]
|
||||
fn read_reg(&self, n: u8) -> Value {
|
||||
unsafe { *self.registers.get_unchecked(n as usize) }
|
||||
}
|
||||
|
||||
/// Write a register.
|
||||
/// Writing to register 0 is no-op.
|
||||
#[inline(always)]
|
||||
fn write_reg<T: ValueVariant>(&mut self, n: u8, value: T) {
|
||||
if n != 0 {
|
||||
unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
(&value as *const T).cast::<u8>(),
|
||||
self.registers.as_mut_ptr().add(n.into()).cast::<u8>(),
|
||||
core::mem::size_of::<T>(),
|
||||
);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// Load / Store Address check-computation überfunction
|
||||
#[inline(always)]
|
||||
unsafe fn ldst_addr_uber(
|
||||
|
|
Loading…
Reference in a new issue