Skip to content

Commit

Permalink
v20 functionally complete and passing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dbalsom committed Jun 1, 2024
1 parent 17d23b9 commit 83695df
Show file tree
Hide file tree
Showing 25 changed files with 1,388 additions and 542 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ icon.png
/install/output/screenshots/*
/install/output/traces/*
/install/output/dumps/*
/install/output/tests/test_summary.csv

# Dev machines not completed or functional
/install/configs/machines/acid88.toml
Expand Down Expand Up @@ -78,3 +79,4 @@ icon.png
/tree.txt

/test-gen/

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

72 changes: 36 additions & 36 deletions core/src/arduino8088_client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub enum ServerCommand {
}

#[derive(Debug, PartialEq)]
pub enum ProgramState {
pub enum ValidatorState {
Reset = 0,
JumpVector,
Load,
Expand Down Expand Up @@ -499,23 +499,23 @@ impl CpuClient {
self.read_result_code()
}

pub fn get_program_state(&mut self) -> Result<ProgramState, CpuClientError> {
pub fn get_program_state(&mut self) -> Result<ValidatorState, CpuClientError> {
let mut buf: [u8; 1] = [0; 1];
self.send_command_byte(ServerCommand::CmdGetProgramState)?;
self.recv_buf(&mut buf)?;
self.read_result_code()?;

match buf[0] {
0x00 => Ok(ProgramState::Reset),
0x01 => Ok(ProgramState::JumpVector),
0x02 => Ok(ProgramState::Load),
0x03 => Ok(ProgramState::LoadDone),
0x04 => Ok(ProgramState::Execute),
0x05 => Ok(ProgramState::ExecuteFinalize),
0x06 => Ok(ProgramState::ExecuteDone),
0x07 => Ok(ProgramState::Store),
0x08 => Ok(ProgramState::StoreDone),
0x09 => Ok(ProgramState::Done),
0x00 => Ok(ValidatorState::Reset),
0x01 => Ok(ValidatorState::JumpVector),
0x02 => Ok(ValidatorState::Load),
0x03 => Ok(ValidatorState::LoadDone),
0x04 => Ok(ValidatorState::Execute),
0x05 => Ok(ValidatorState::ExecuteFinalize),
0x06 => Ok(ValidatorState::ExecuteDone),
0x07 => Ok(ValidatorState::Store),
0x08 => Ok(ValidatorState::StoreDone),
0x09 => Ok(ValidatorState::Done),
_ => Err(CpuClientError::BadValue),
}
}
Expand All @@ -530,24 +530,24 @@ impl CpuClient {
Ok(err_string.to_string())
}

pub fn get_cycle_state(&mut self) -> Result<(ProgramState, u8, u8, u8, u8), CpuClientError> {
pub fn get_cycle_state(&mut self) -> Result<(ValidatorState, u8, u8, u8, u8), CpuClientError> {
let mut buf: [u8; 4] = [0; 4];
self.send_command_byte(ServerCommand::CmdGetCycleState)?;
self.recv_buf(&mut buf)?;
self.read_result_code()?;

let state_bits: u8 = buf[0] >> 4;
let state: ProgramState = match state_bits {
0x00 => ProgramState::Reset,
0x01 => ProgramState::JumpVector,
0x02 => ProgramState::Load,
0x03 => ProgramState::LoadDone,
0x04 => ProgramState::Execute,
0x05 => ProgramState::ExecuteFinalize,
0x06 => ProgramState::ExecuteDone,
0x07 => ProgramState::Store,
0x08 => ProgramState::StoreDone,
0x09 => ProgramState::Done,
let state: ValidatorState = match state_bits {
0x00 => ValidatorState::Reset,
0x01 => ValidatorState::JumpVector,
0x02 => ValidatorState::Load,
0x03 => ValidatorState::LoadDone,
0x04 => ValidatorState::Execute,
0x05 => ValidatorState::ExecuteFinalize,
0x06 => ValidatorState::ExecuteDone,
0x07 => ValidatorState::Store,
0x08 => ValidatorState::StoreDone,
0x09 => ValidatorState::Done,
_ => {
return Err(CpuClientError::BadValue);
}
Expand All @@ -558,24 +558,24 @@ impl CpuClient {
Ok((state, control_bits, buf[1], buf[2], buf[3]))
}

pub fn cycle_get_cycle_state(&mut self) -> Result<(ProgramState, u8, u8, u8, u8), CpuClientError> {
pub fn cycle_get_cycle_state(&mut self) -> Result<(ValidatorState, u8, u8, u8, u8), CpuClientError> {
let mut buf: [u8; 4] = [0; 4];
self.send_command_byte(ServerCommand::CmdCGetCycleState)?;
self.recv_buf(&mut buf)?;
self.read_result_code()?;

let state_bits: u8 = buf[0] >> 4;
let state: ProgramState = match state_bits {
0x00 => ProgramState::Reset,
0x01 => ProgramState::JumpVector,
0x02 => ProgramState::Load,
0x03 => ProgramState::LoadDone,
0x04 => ProgramState::Execute,
0x05 => ProgramState::ExecuteFinalize,
0x06 => ProgramState::ExecuteDone,
0x07 => ProgramState::Store,
0x08 => ProgramState::StoreDone,
0x09 => ProgramState::Done,
let state: ValidatorState = match state_bits {
0x00 => ValidatorState::Reset,
0x01 => ValidatorState::JumpVector,
0x02 => ValidatorState::Load,
0x03 => ValidatorState::LoadDone,
0x04 => ValidatorState::Execute,
0x05 => ValidatorState::ExecuteFinalize,
0x06 => ValidatorState::ExecuteDone,
0x07 => ValidatorState::Store,
0x08 => ValidatorState::StoreDone,
0x09 => ValidatorState::Done,
_ => {
return Err(CpuClientError::BadValue);
}
Expand Down
85 changes: 45 additions & 40 deletions core/src/arduino8088_validator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,6 @@ macro_rules! trace_error {
}};
}

#[derive(PartialEq, Debug)]
pub enum ValidatorState {
Setup,
Execute,
Readback,
Finished,
}

#[derive(Copy, Clone, Debug, PartialEq)]
pub enum RegisterValidationResult {
Ok,
Expand Down Expand Up @@ -153,8 +145,8 @@ pub struct ArduinoValidator {
cpu_type: CpuType,

current_instr: InstructionContext,
state: ValidatorState,

//state: ValidatorState,
cycle_count: u64,
do_cycle_trace: bool,

Expand Down Expand Up @@ -188,9 +180,10 @@ pub struct ArduinoValidator {
log_prefix: String,
trace_logger: TraceLogger,

opt_validate_regs: bool,
opt_validate_flags: bool,
opt_validate_mem: bool,
opt_ignore_underflow: bool,
opt_validate_regs: bool,
opt_validate_flags: bool,
opt_validate_mem: bool,
opt_validate_cycles: bool,
}

Expand All @@ -213,8 +206,7 @@ impl ArduinoValidator {
cpu_type,

current_instr: InstructionContext::new(),
state: ValidatorState::Setup,

//state: ValidatorState::Setup,
cycle_count: 0,
do_cycle_trace: false,
rd_signal: false,
Expand Down Expand Up @@ -244,6 +236,7 @@ impl ArduinoValidator {

trace_logger,

opt_ignore_underflow: false,
opt_validate_cycles: true,
opt_validate_regs: true,
opt_validate_flags: true,
Expand Down Expand Up @@ -698,23 +691,6 @@ impl CpuValidator for ArduinoValidator {
self.trigger_addr = V_INVALID_POINTER;
}

// If we are prefetching the next instruction, we need to adjust IP by the size of the
// prefetch program.
if self.current_instr.prefetch {
let pgm_len = self.cpu.get_preload_pgm().len();
self.current_instr.regs[0].ip = self.current_instr.regs[0].ip.wrapping_sub(pgm_len as u16);
trace_debug!(
self,
"Adjusting IP by prefetch program length: {} new_ip: {:04X} new_addr: {:05X}",
pgm_len,
self.current_instr.regs[0].ip,
RemoteCpu::calc_linear_address(self.current_instr.regs[0].cs, self.current_instr.regs[0].ip)
);
}
else {
trace_debug!(self, "begin_instruction(): Not prefetching.");
}

/*
if (self.trigger_addr != V_INVALID_POINTER)
|| (self.visit_once && ip_addr >= UPPER_MEMORY && self.visited[ip_addr as usize]) {
Expand Down Expand Up @@ -748,29 +724,57 @@ impl CpuValidator for ArduinoValidator {
self.cpu.reset();

let mut reg_buf: [u8; 28] = [0; 28];
ArduinoValidator::regs_to_buf(&mut reg_buf, &self.current_instr.regs[0]);

//trace_debug!(self, "\n{}", &self.current_instr.regs[0]);
//trace_debug!(self, "Flags: {}", RemoteCpu::flags_string(self.current_instr.regs[0].flags));
let mut adjusted_regs = self.current_instr.regs[0].clone();

// If prefetching, restore the original IP state
// If we are prefetching the next instruction, we need to adjust IP by the size of the
// prefetch program.
if self.current_instr.prefetch {
let pgm_len = self.cpu.get_preload_pgm().len();
self.current_instr.regs[0].ip = self.current_instr.regs[0].ip.wrapping_add(pgm_len as u16);
adjusted_regs.ip = adjusted_regs.ip.wrapping_sub(pgm_len as u16);
trace_debug!(
self,
"set_regs(): Restoring original IP: new_ip: {:04X} new_addr: {:05X}",
self.current_instr.regs[0].ip,
RemoteCpu::calc_linear_address(self.current_instr.regs[0].cs, self.current_instr.regs[0].ip)
"Adjusting IP by prefetch program length: {} new_ip: {:04X} new_addr: {:05X}",
pgm_len,
adjusted_regs.ip,
RemoteCpu::calc_linear_address(adjusted_regs.cs, adjusted_regs.ip)
);

// On 8088/8086, we need to adjust DI by 4 depending on flag direction.
if let CpuType::Intel8088 | CpuType::Intel8086 = self.cpu_type {
// Adjust DI. This depends on the state of the Direction flag.
if adjusted_regs.flags & CPU_FLAG_DIRECTION == 0 {
// Direction forward. Decrement DI.
trace_debug!(self, "Adjusting DI for 8088 prefetch, -= 4... ");
adjusted_regs.di = adjusted_regs.di.wrapping_sub(4);
}
else {
// Direction backwards. Increment DI.
trace_debug!(self, "Adjusting DI for 8088 prefetch, += 4... ");
adjusted_regs.di = adjusted_regs.di.wrapping_add(4);
}
}
}
else {
trace_debug!(self, "begin_instruction(): Not prefetching.");
}

ArduinoValidator::regs_to_buf(&mut reg_buf, &adjusted_regs);

self.cpu
.load(&reg_buf)
.expect("validate() error: Load registers failed.");
}

fn set_opts(&mut self, validate_cycles: bool, validate_regs: bool, validate_flags: bool, validate_mem: bool) {
fn set_opts(
&mut self,
ignore_underflow: bool,
validate_cycles: bool,
validate_regs: bool,
validate_flags: bool,
validate_mem: bool,
) {
self.opt_ignore_underflow = ignore_underflow;
self.opt_validate_cycles = validate_cycles;
self.opt_validate_regs = validate_regs;
self.opt_validate_flags = validate_flags;
Expand Down Expand Up @@ -901,6 +905,7 @@ impl CpuValidator for ArduinoValidator {
&mut self.current_instr.cpu_fetches,
&mut self.current_instr.cpu_ops,
&mut self.current_instr.initial_queue,
self.opt_ignore_underflow,
&mut self.trace_logger,
) {
Ok(stepresult) => stepresult,
Expand Down
Loading

0 comments on commit 83695df

Please sign in to comment.