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}; pub(super) use {impl_asm, impl_asm_opcodes};
#[allow(clippy::single_component_path_imports)] #[allow(clippy::single_component_path_imports)]

View file

@ -2,11 +2,13 @@
pub mod paging; pub mod paging;
use self::paging::{PageTable, Permission, PtEntry}; use {
use super::{trap::HandleTrap, VmRunError}; self::paging::{PageTable, Permission, PtEntry},
use alloc::boxed::Box; super::{trap::HandleTrap, VmRunError},
use core::mem::MaybeUninit; alloc::boxed::Box,
use derive_more::Display; core::mem::MaybeUninit,
derive_more::Display,
};
/// HoleyBytes virtual memory /// HoleyBytes virtual memory
#[derive(Clone, Debug)] #[derive(Clone, Debug)]

View file

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

View file

@ -97,6 +97,10 @@ pub struct Vm<'a, T> {
/// Program /// Program
program: &'a [u8], 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> { impl<'a, T: HandleTrap> Vm<'a, T> {
@ -111,6 +115,9 @@ impl<'a, T: HandleTrap> Vm<'a, T> {
traph, traph,
pc: 0, pc: 0,
program, program,
last_tick_count: 0,
tick_callback: None,
tick_limit: 32,
} }
} }
@ -123,12 +130,12 @@ impl<'a, T: HandleTrap> Vm<'a, T> {
/// Execute program /// Execute program
/// ///
/// Program can return [`VmRunError`] if a trap handling failed /// 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::*; use hbbytecode::opcode::*;
loop { loop {
// Fetch instruction // Fetch instruction
let Some(&opcode) = self.program.get(self.pc) let Some(&opcode) = self.program.get(self.pc)
else { return Ok(()) }; else { return Ok(2) };
// Big match // Big match
unsafe { 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 /// Read register