1
0
Fork 0
forked from koniifer/ableos

tried to shove the timer back in

This commit is contained in:
MunirG05 2023-07-11 14:03:25 +05:30
parent bde00c13f2
commit 6759fbd2ab
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 {
core::{
fmt::Debug, fmt::Debug,
mem::MaybeUninit, mem::MaybeUninit,
ops::{Index, IndexMut}, ops::{Index, IndexMut},
slice::SliceIndex, 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)]
@ -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))]

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,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 /// Read register
#[inline] #[inline]