tried to shove the timer back in
This commit is contained in:
parent
bde00c13f2
commit
6759fbd2ab
|
@ -66,7 +66,6 @@ macro_rules! impl_asm {
|
|||
};
|
||||
}
|
||||
|
||||
|
||||
pub(super) use {impl_asm, impl_asm_opcodes};
|
||||
|
||||
#[allow(clippy::single_component_path_imports)]
|
||||
|
|
|
@ -2,11 +2,13 @@
|
|||
|
||||
pub mod paging;
|
||||
|
||||
use self::paging::{PageTable, Permission, PtEntry};
|
||||
use super::{trap::HandleTrap, VmRunError};
|
||||
use alloc::boxed::Box;
|
||||
use core::mem::MaybeUninit;
|
||||
use derive_more::Display;
|
||||
use {
|
||||
self::paging::{PageTable, Permission, PtEntry},
|
||||
super::{trap::HandleTrap, VmRunError},
|
||||
alloc::boxed::Box,
|
||||
core::mem::MaybeUninit,
|
||||
derive_more::Display,
|
||||
};
|
||||
|
||||
/// HoleyBytes virtual memory
|
||||
#[derive(Clone, Debug)]
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
//! Page table and associated structures implementation
|
||||
|
||||
use core::{
|
||||
use {
|
||||
core::{
|
||||
fmt::Debug,
|
||||
mem::MaybeUninit,
|
||||
ops::{Index, IndexMut},
|
||||
slice::SliceIndex,
|
||||
},
|
||||
delegate::delegate,
|
||||
};
|
||||
use delegate::delegate;
|
||||
|
||||
/// Page entry permission
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||
|
@ -61,7 +63,6 @@ impl Debug for PtEntry {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/// Page table
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
#[repr(align(4096))]
|
||||
|
|
|
@ -97,6 +97,10 @@ pub struct Vm<'a, T> {
|
|||
|
||||
/// Program
|
||||
program: &'a [u8],
|
||||
|
||||
pub last_tick_count: u32,
|
||||
pub tick_callback: Option<fn() -> u32>,
|
||||
pub tick_limit: u32,
|
||||
}
|
||||
|
||||
impl<'a, T: HandleTrap> Vm<'a, T> {
|
||||
|
@ -111,6 +115,9 @@ impl<'a, T: HandleTrap> Vm<'a, T> {
|
|||
traph,
|
||||
pc: 0,
|
||||
program,
|
||||
last_tick_count: 0,
|
||||
tick_callback: None,
|
||||
tick_limit: 32,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -123,12 +130,12 @@ impl<'a, T: HandleTrap> Vm<'a, T> {
|
|||
/// Execute program
|
||||
///
|
||||
/// Program can return [`VmRunError`] if a trap handling failed
|
||||
pub fn run(&mut self) -> Result<(), VmRunError> {
|
||||
pub fn run(&mut self) -> Result<u32, VmRunError> {
|
||||
use hbbytecode::opcode::*;
|
||||
loop {
|
||||
// Fetch instruction
|
||||
let Some(&opcode) = self.program.get(self.pc)
|
||||
else { return Ok(()) };
|
||||
else { return Ok(2) };
|
||||
|
||||
// Big match
|
||||
unsafe {
|
||||
|
@ -318,8 +325,16 @@ impl<'a, T: HandleTrap> Vm<'a, T> {
|
|||
}
|
||||
}
|
||||
}
|
||||
if self.tick_callback.is_some() {
|
||||
let ret = self.tick_callback.unwrap()();
|
||||
if (ret - self.last_tick_count) >= self.tick_limit {
|
||||
return Ok(0);
|
||||
}
|
||||
}
|
||||
return Ok(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// Read register
|
||||
#[inline]
|
||||
|
|
Loading…
Reference in a new issue