diff --git a/src/cpu/CMakeLists.txt b/src/cpu/CMakeLists.txt index b79ebde8..0eaf3556 100644 --- a/src/cpu/CMakeLists.txt +++ b/src/cpu/CMakeLists.txt @@ -21,6 +21,7 @@ i486fidelity.h i486runinstruction.h i486templatefunctions.h i486debugVxD.cpp +i486garbage.cpp ) target_link_libraries(cpu device ramrom inout cpputil) target_include_directories(cpu PUBLIC .) diff --git a/src/cpu/i486.h b/src/cpu/i486.h index 19c8b646..f412b749 100644 --- a/src/cpu/i486.h +++ b/src/cpu/i486.h @@ -66,6 +66,8 @@ Therefore, the CPU class now is divided into three parts. The base class, i486C class i486DXCommon : public CPU { +public: + void ConsumeVariable(uint32_t); // See comments. public: enum { diff --git a/src/cpu/i486garbage.cpp b/src/cpu/i486garbage.cpp new file mode 100644 index 00000000..3e57603d --- /dev/null +++ b/src/cpu/i486garbage.cpp @@ -0,0 +1,4 @@ +#include "i486.h" +void i486DXCommon::ConsumeVariable(unsigned int variable) +{ +} \ No newline at end of file diff --git a/src/cpu/i486runinstruction.h b/src/cpu/i486runinstruction.h index 994d1f01..c2266b7f 100644 --- a/src/cpu/i486runinstruction.h +++ b/src/cpu/i486runinstruction.h @@ -7407,6 +7407,18 @@ unsigned int i486DXFidelityLayer::RunOneInstruction(Memory &mem,InOut SetFLAGSorEFLAGS(inst.operandSize,eflags); FIDELITY::RestoreIOPLBits(*this,ioplBits); FIDELITY::RestoreIF(*this,ioplBits); + + // If I print state.EFLAGS here, it is updated correctly. + // If I do not print state.EFLAGS, it is not updated from time to time. + // Looks like I stepped on a bug of clang. I need to be careful to declare it as a clang bug, + // but it happens only in Linux using clang 6.0.0-1ubuntu2. + // It does not seem to happen with my clang on macOS. + // I need to let state.EFLAGS consumed by outside of this function, outside of this object file, + // to make it run correctly. Otherwise, the compiler seems to ignore above SetFLAGSorEFLAGS. + #ifdef __linux__ + ConsumeVariable(state.EFLAGS); + #endif + state.EFLAGS&=EFLAGS_MASK; state.EFLAGS|=EFLAGS_ALWAYS_ON; @@ -7446,6 +7458,9 @@ unsigned int i486DXFidelityLayer::RunOneInstruction(Memory &mem,InOut typename FIDELITY::EFLAGS ioplBits; FIDELITY::SaveEFLAGS(ioplBits,*this); SetFLAGSorEFLAGS(inst.operandSize,eflags); + #ifdef __linux__ + ConsumeVariable(state.EFLAGS); + #endif FIDELITY::RestoreIOPLBits(*this,ioplBits); FIDELITY::RestoreIF(*this,ioplBits);