bizare page unmapped error
This commit is contained in:
parent
7d8b0bae78
commit
46eb4c17a0
|
@ -20,6 +20,13 @@ use self::call_stack::CallStack;
|
|||
pub struct Page {
|
||||
pub data: [u8; 4096 * 2],
|
||||
}
|
||||
impl Page {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
data: [0; 4096 * 2],
|
||||
}
|
||||
}
|
||||
}
|
||||
pub type EnviromentCall = fn(Registers) -> Result<Registers, u64>;
|
||||
|
||||
pub fn empty_enviroment_call(reg: Registers) -> Result<Registers, u64> {
|
||||
|
@ -42,9 +49,9 @@ pub struct Engine {
|
|||
}
|
||||
|
||||
impl Engine {
|
||||
pub fn read_mem_addr(&mut self, address: u64) -> u8 {
|
||||
pub fn read_mem_addr_8(&mut self, address: u64) -> Result<u8, RuntimeErrors> {
|
||||
// println!("{}", address);
|
||||
255
|
||||
self.memory.read_addr8(address)
|
||||
}
|
||||
pub fn set_timer_callback(&mut self, func: fn() -> u32) {
|
||||
self.timer_callback = Some(func);
|
||||
|
@ -53,6 +60,13 @@ impl Engine {
|
|||
|
||||
impl Engine {
|
||||
pub fn new(program: Vec<u8>) -> Self {
|
||||
let mut mem = memory::Memory::new();
|
||||
for (addr, byte) in program.clone().into_iter().enumerate() {
|
||||
let ret = mem.set_addr8(addr as u64, byte);
|
||||
println!("{:?}", ret);
|
||||
}
|
||||
println!("{:?}", mem.read_addr8(0));
|
||||
|
||||
Self {
|
||||
index: 0,
|
||||
program,
|
||||
|
@ -321,7 +335,7 @@ F5-F9 {:016X} {:016X} {:016X} {:016X} {:016X}",
|
|||
|
||||
trace!("addr {}", addr);
|
||||
|
||||
let ret = self.read_mem_addr(addr);
|
||||
let ret = self.read_mem_addr_8(addr)?;
|
||||
let reg = self.program[self.index + 10];
|
||||
trace!("reg {}", reg);
|
||||
self.set_register_8(reg, ret);
|
||||
|
|
|
@ -14,6 +14,7 @@ pub enum RuntimeErrors {
|
|||
InvalidOpcode(u8),
|
||||
RegisterTooSmall,
|
||||
HostError(u64),
|
||||
PageUnmapped(u64),
|
||||
}
|
||||
|
||||
// If you solve the halting problem feel free to remove this
|
||||
|
|
10
src/main.rs
10
src/main.rs
|
@ -7,7 +7,7 @@ use holey_bytes::{
|
|||
fn main() -> Result<(), RuntimeErrors> {
|
||||
#[rustfmt::skip]
|
||||
let prog: Vec<u8> = vec![
|
||||
// NOP as u8, NOP as u8,
|
||||
NOP as u8, NOP as u8,
|
||||
// 10, 10,
|
||||
|
||||
ADD as u8, EightBit as u8, 100, 20, 0xA7,
|
||||
|
@ -26,11 +26,11 @@ fn main() -> Result<(), RuntimeErrors> {
|
|||
];
|
||||
|
||||
let mut eng = Engine::new(prog);
|
||||
|
||||
println!("{:?}", eng.read_mem_addr_8(4));
|
||||
// eng.set_timer_callback(time);
|
||||
eng.enviroment_call_table[10] = print_fn;
|
||||
eng.run()?;
|
||||
eng.dump();
|
||||
// eng.enviroment_call_table[10] = print_fn;
|
||||
// eng.run()?;
|
||||
// eng.dump();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -21,16 +21,35 @@ impl Memory {
|
|||
impl Memory {
|
||||
pub fn read_addr8(&mut self, address: u64) -> Result<u8, RuntimeErrors> {
|
||||
let (page, offset) = addr_to_page(address);
|
||||
let val: u8 = self.inner.get(&page).unwrap().data[offset as usize];
|
||||
trace!("Value read {} from page {} offset {}", val, page, offset);
|
||||
Ok(val)
|
||||
println!("page {} offset {}", page, offset);
|
||||
match self.inner.get(&page) {
|
||||
Some(page) => {
|
||||
let val = page.data[offset as usize];
|
||||
Ok(val)
|
||||
}
|
||||
None => Err(RuntimeErrors::PageUnmapped(page)),
|
||||
}
|
||||
// trace!("Value read {} from page {} offset {}", val, page, offset);
|
||||
}
|
||||
pub fn read_addr64(&mut self, address: u64) -> u64 {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn set_addr8(&self, address: u64, value: u8) -> Result<(), RuntimeErrors> {
|
||||
unimplemented!()
|
||||
pub fn set_addr8(&mut self, address: u64, value: u8) -> Result<(), RuntimeErrors> {
|
||||
let (page, offset) = addr_to_page(address);
|
||||
let ret: Option<(&u64, &mut Page)> = self.inner.get_key_value_mut(&page);
|
||||
match ret {
|
||||
Some((_, page)) => {
|
||||
page.data[offset as usize] = value;
|
||||
}
|
||||
None => {
|
||||
let mut pg = Page::new();
|
||||
pg.data[offset as usize] = value;
|
||||
self.inner.insert(page, pg);
|
||||
println!("Mapped page {}", page);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
pub fn set_addr64(&mut self, address: u64, value: u64) -> u64 {
|
||||
unimplemented!()
|
||||
|
|
Loading…
Reference in a new issue