Skip to content

Commit

Permalink
Fix CPU instruction pointer
Browse files Browse the repository at this point in the history
Closes #20
  • Loading branch information
barotto committed Oct 8, 2018
1 parent e09782a commit edd02d2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/hardware/cpu/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ void CPUCore::reset()
m_cr[2] = 0x0;
m_cr[3] = 0x0;
m_eip = 0x0000FFF0;
m_prev_eip = m_eip;

load_segment_defaults(REG_CS, 0xF000);
load_segment_defaults(REG_DS, 0x0000);
Expand Down
8 changes: 8 additions & 0 deletions src/hardware/cpu/executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ void CPUExecutor::execute(Instruction * _instr)
}

(this->*exec_fn)();

if(m_instr && !m_instr->rep) {
COMMIT_EIP();
}
}

void CPUExecutor::rep_16()
Expand Down Expand Up @@ -206,6 +210,7 @@ void CPUExecutor::rep_16()
REG_CX -= 1;
if(REG_CX == 0) {
// REP finished and IP points to the next instr.
COMMIT_EIP();
return;
}

Expand All @@ -219,6 +224,7 @@ void CPUExecutor::rep_16()
if((m_instr->rep_equal && !FLAG_ZF) || (!m_instr->rep_equal && FLAG_ZF))
{
// REP finished and IP points to the next instr.
COMMIT_EIP();
return;
}
}
Expand All @@ -244,11 +250,13 @@ void CPUExecutor::rep_32()

REG_ECX -= 1;
if(REG_ECX == 0) {
COMMIT_EIP();
return;
}

if(m_instr->rep_zf) {
if((m_instr->rep_equal && !FLAG_ZF) || (!m_instr->rep_equal && FLAG_ZF)) {
COMMIT_EIP();
return;
}
}
Expand Down

0 comments on commit edd02d2

Please sign in to comment.