Doing sus stuff

This commit is contained in:
Erin 2023-08-17 03:37:14 +02:00 committed by ondra05
parent 04da28ce44
commit f6726ad9a6
3 changed files with 22 additions and 29 deletions

View file

@ -134,34 +134,29 @@ constmod!(pub opcode(u8) {
#[repr(packed)] #[repr(packed)]
pub struct ParamBBBB(pub u8, pub u8, pub u8, pub u8); pub struct ParamBBBB(pub u8, pub u8, pub u8, pub u8);
#[repr(packed)] #[repr(packed)]
pub struct ParamBBB(pub u8, pub u8, pub u8); pub struct ParamBBB(pub u8, pub u8, pub u8);
#[repr(packed)] #[repr(packed)]
pub struct ParamBBDH(pub u8, pub u8, pub u64, pub u16); pub struct ParamBBDH(pub u8, pub u8, pub u64, pub u16);
#[repr(packed)] #[repr(packed)]
pub struct ParamBBD(pub u8, pub u8, pub u64); pub struct ParamBBD(pub u8, pub u8, pub u64);
#[repr(packed)] #[repr(packed)]
pub struct ParamBBW(pub u8, pub u8, pub u32); pub struct ParamBBW(pub u8, pub u8, pub u32);
#[repr(packed)] #[repr(packed)]
pub struct ParamBB(pub u8, pub u8); pub struct ParamBB(pub u8, pub u8);
#[repr(packed)] #[repr(packed)]
pub struct ParamBD(pub u8, pub u64); pub struct ParamBD(pub u8, pub u64);
/// # Safety /// # Safety
/// Has to be valid to be decoded from bytecode. /// Has to be valid to be decoded from bytecode.
pub unsafe trait OpParam {} pub unsafe trait ProgramVal {}
unsafe impl OpParam for ParamBBBB {} unsafe impl ProgramVal for ParamBBBB {}
unsafe impl OpParam for ParamBBB {} unsafe impl ProgramVal for ParamBBB {}
unsafe impl OpParam for ParamBBDH {} unsafe impl ProgramVal for ParamBBDH {}
unsafe impl OpParam for ParamBBD {} unsafe impl ProgramVal for ParamBBD {}
unsafe impl OpParam for ParamBBW {} unsafe impl ProgramVal for ParamBBW {}
unsafe impl OpParam for ParamBB {} unsafe impl ProgramVal for ParamBB {}
unsafe impl OpParam for ParamBD {} unsafe impl ProgramVal for ParamBD {}
unsafe impl OpParam for u64 {} unsafe impl ProgramVal for u64 {}
unsafe impl OpParam for () {} unsafe impl ProgramVal for u8 {} // Opcode
unsafe impl ProgramVal for () {}

View file

@ -26,7 +26,9 @@ use {
bmc::BlockCopier, bmc::BlockCopier,
core::{cmp::Ordering, mem::size_of, ops}, core::{cmp::Ordering, mem::size_of, ops},
derive_more::Display, derive_more::Display,
hbbytecode::{OpParam, ParamBB, ParamBBB, ParamBBBB, ParamBBD, ParamBBDH, ParamBBW, ParamBD}, hbbytecode::{
ParamBB, ParamBBB, ParamBBBB, ParamBBD, ParamBBDH, ParamBBW, ParamBD, ProgramVal,
},
value::{Value, ValueVariant}, value::{Value, ValueVariant},
}; };
@ -366,7 +368,7 @@ where
/// Decode instruction operands /// Decode instruction operands
#[inline(always)] #[inline(always)]
unsafe fn decode<T: OpParam>(&mut self) -> T { unsafe fn decode<T: ProgramVal>(&mut self) -> T {
let pc1 = self.pc + 1; let pc1 = self.pc + 1;
let data = self.memory.prog_read_unchecked::<T>(pc1 as _); let data = self.memory.prog_read_unchecked::<T>(pc1 as _);
self.pc += 1 + size_of::<T>(); self.pc += 1 + size_of::<T>();
@ -515,13 +517,13 @@ pub trait Memory {
/// ///
/// # Safety /// # Safety
/// - Data read have to be valid /// - Data read have to be valid
unsafe fn prog_read<T>(&mut self, addr: u64) -> Option<T>; unsafe fn prog_read<T: ProgramVal>(&mut self, addr: u64) -> Option<T>;
/// Read from program memory to exectue /// Read from program memory to exectue
/// ///
/// # Safety /// # Safety
/// - You have to be really sure that these bytes are there, understand? /// - You have to be really sure that these bytes are there, understand?
unsafe fn prog_read_unchecked<T>(&mut self, addr: u64) -> T; unsafe fn prog_read_unchecked<T: ProgramVal>(&mut self, addr: u64) -> T;
} }
/// Unhandled load access trap /// Unhandled load access trap

View file

@ -1,7 +1,7 @@
//! Program instruction cache //! Program instruction cache
use { use {
super::{lookup::AddrPageLookuper, paging::PageTable, HandlePageFault, PageSize}, super::{lookup::AddrPageLookuper, paging::PageTable, PageSize},
core::{ core::{
mem::{size_of, MaybeUninit}, mem::{size_of, MaybeUninit},
ptr::{copy_nonoverlapping, NonNull}, ptr::{copy_nonoverlapping, NonNull},
@ -37,11 +37,7 @@ impl ICache {
/// ///
/// # Safety /// # Safety
/// `T` should be valid to read from instruction memory /// `T` should be valid to read from instruction memory
pub(super) unsafe fn fetch<T>( pub(super) unsafe fn fetch<T>(&mut self, addr: u64, root_pt: *const PageTable) -> Option<T> {
&mut self,
addr: u64,
root_pt: *const PageTable,
) -> Option<T> {
let mut ret = MaybeUninit::<T>::uninit(); let mut ret = MaybeUninit::<T>::uninit();
let pbase = self let pbase = self