progress: new assembler works, instruction set fully implemented with call/ret and push/pop, bf.dsa works which means the dsa assembly language works reliably. still a few bugs to fix. might be able to squeeze out a tiny bit more performance
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
use crate::memory::{
|
||||
PhysAddr, RandomAccessMemory,
|
||||
ram::{NUM_PAGES, Page},
|
||||
};
|
||||
|
||||
pub struct PreAllocStore {
|
||||
heap: Box<[u8; NUM_PAGES * 4096]>,
|
||||
}
|
||||
|
||||
unsafe impl Send for PreAllocStore {}
|
||||
impl PreAllocStore {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
heap: unsafe { Box::new_zeroed().assume_init() },
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl RandomAccessMemory for PreAllocStore {
|
||||
#[inline(always)]
|
||||
fn read_word(&self, addr: PhysAddr) -> u32 {
|
||||
unsafe { (self.heap.as_ptr().add(addr as usize) as *const u32).read() }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn read_byte(&self, addr: PhysAddr) -> u8 {
|
||||
self.heap[addr as usize]
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn read_page(&self, addr: PhysAddr) -> &Page {
|
||||
debug_assert_eq!(addr % 4096, 0);
|
||||
unsafe { (self.heap.as_ptr().add(addr as usize) as *const Page).as_ref_unchecked() }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn write_byte(&mut self, addr: PhysAddr, value: u8) {
|
||||
self.heap[addr as usize] = value;
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn write_word(&mut self, addr: PhysAddr, value: u32) {
|
||||
unsafe { (self.heap.as_ptr().add(addr as usize) as *mut u32).write(value) };
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn write_page(&mut self, addr: PhysAddr, value: &Page) {
|
||||
self.heap[addr as usize..addr as usize + 4096].copy_from_slice(value);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user