fix(interpreter): impl fetch and decode

I parsed all instructions before executing, but this is not how
intel works.
We need to decode the instructions, pointed to by IP, on the fly.
This commit is contained in:
2025-07-01 12:04:20 +09:00
parent f3fd655908
commit a5cffa4852
5 changed files with 511 additions and 539 deletions

View File

@@ -1,9 +1,13 @@
//! Internal a.out File abstraction.
use core::fmt;
use std::ffi::{c_uchar, c_ushort};
use std::{
ffi::{c_uchar, c_ushort},
fs::File,
io::Read,
};
use crate::operands::Byte;
use crate::{Args, disasm::DisasmError, operands::Byte};
#[allow(non_camel_case_types)]
pub type c_long = i32; // we use a a.out with 32 byte
@@ -25,6 +29,20 @@ impl fmt::Display for Aout {
}
impl Aout {
pub fn new_from_args(args: &Args) -> Self {
let path = args
.path
.clone()
.ok_or(DisasmError::NoFile(args.path.clone()))
.unwrap();
let mut file = File::open(path).unwrap();
let mut buf = Vec::new();
file.read_to_end(&mut buf).unwrap();
let aout = Aout::new(buf);
log::debug!("{:?}", aout);
aout
}
pub fn new(buf: Vec<u8>) -> Self {
let hdr = Header {
magic: [buf[0], buf[1]],