2023-10-27 20:26:04 -05:00
|
|
|
//! Security? Multiple address spaces? What are you talking about
|
|
|
|
//! young adventurer. In this temple, we know no such words.
|
|
|
|
//!
|
|
|
|
//! Want your program to override other program's data or even the
|
|
|
|
//! data of the kernel itself? Sure. This right shall not be infringed.
|
|
|
|
|
|
|
|
use hbvm::mem::Address;
|
|
|
|
|
2024-03-11 09:48:56 -05:00
|
|
|
fn calc_start_of_page(ptr: u64) -> u64 {
|
|
|
|
let mut page_aligned = false;
|
|
|
|
if ptr % 4096 == 0 {
|
|
|
|
// page_aligned = true;
|
|
|
|
return ptr / 4096;
|
|
|
|
}
|
|
|
|
panic!("unaligned");
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct Memory {
|
|
|
|
// TODO: map page aligned segments of memory into a table or some sort here
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Memory {
|
|
|
|
#[cfg(target_arch = "x86_64")]
|
|
|
|
fn read_device(addr: Address) {
|
|
|
|
unsafe {
|
|
|
|
//
|
|
|
|
// x86_64::instructions::port::Port::new(addr.get()).read()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-27 20:26:04 -05:00
|
|
|
impl hbvm::mem::Memory for Memory {
|
|
|
|
#[inline]
|
|
|
|
unsafe fn load(
|
|
|
|
&mut self,
|
|
|
|
addr: Address,
|
|
|
|
target: *mut u8,
|
|
|
|
count: usize,
|
|
|
|
) -> Result<(), hbvm::mem::LoadError> {
|
2024-03-11 09:48:56 -05:00
|
|
|
use log::{error, info};
|
|
|
|
if addr.get() % 4096 == 0 {}
|
2023-10-27 20:26:04 -05:00
|
|
|
core::ptr::copy(addr.get() as *const u8, target, count);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
unsafe fn store(
|
|
|
|
&mut self,
|
|
|
|
addr: Address,
|
|
|
|
source: *const u8,
|
|
|
|
count: usize,
|
|
|
|
) -> Result<(), hbvm::mem::StoreError> {
|
|
|
|
core::ptr::copy(source, addr.get() as *mut u8, count);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
unsafe fn prog_read<T: Copy>(&mut self, addr: Address) -> T {
|
2023-11-03 03:04:22 -05:00
|
|
|
(addr.get() as *const T).read_unaligned()
|
2023-10-27 20:26:04 -05:00
|
|
|
}
|
|
|
|
}
|