tried to shove the timer back in

This commit is contained in:
MunirG05 2023-07-11 14:03:25 +05:30
parent 7ca0b1d4eb
commit 63b2dc7514
4 changed files with 34 additions and 17 deletions

View file

@ -66,7 +66,6 @@ macro_rules! impl_asm {
};
}
pub(super) use {impl_asm, impl_asm_opcodes};
#[allow(clippy::single_component_path_imports)]

View file

@ -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)]

View file

@ -1,12 +1,14 @@
//! Page table and associated structures implementation
use core::{
fmt::Debug,
mem::MaybeUninit,
ops::{Index, IndexMut},
slice::SliceIndex,
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)]
@ -30,7 +32,7 @@ pub enum Permission {
pub struct PtEntry(u64);
impl PtEntry {
/// Create new
///
///
/// # Safety
/// - `ptr` has to point to valid data and shall not be deallocated
/// troughout the entry lifetime
@ -61,7 +63,6 @@ impl Debug for PtEntry {
}
}
/// Page table
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[repr(align(4096))]
@ -145,7 +146,7 @@ impl Default for PageTable {
#[repr(C, align(4096))]
pub union PtPointedData {
/// Node - next page table
pub pt: PageTable,
pub pt: PageTable,
/// Leaf
pub page: u8,
}

View file

@ -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,7 +325,15 @@ 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