From 3f602129f439a4c577ce9aeb4ecaebdb928afe0f Mon Sep 17 00:00:00 2001 From: MerryMage Date: Thu, 19 Jul 2018 01:40:51 +0100 Subject: [PATCH] system: Ensure value of CNTPCT_EL0 is accurate Since we currently only update the host's tick count at the end of a block, we force an end-of-block before executing a MRS %, CNTPCT_ELO instruction. --- src/frontend/A64/translate/impl/system.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/frontend/A64/translate/impl/system.cpp b/src/frontend/A64/translate/impl/system.cpp index 6b4a7ed0..8d6db346 100644 --- a/src/frontend/A64/translate/impl/system.cpp +++ b/src/frontend/A64/translate/impl/system.cpp @@ -105,6 +105,11 @@ bool TranslatorVisitor::MRS(Imm<1> o0, Imm<3> op1, Imm<4> CRn, Imm<4> CRm, Imm<3 X(32, Rt, ir.GetCTR()); return true; case SystemRegisterEncoding::CNTPCT_EL0: + // HACK: Ensure that this is the first instruction in the block it's emitted in, so the cycle count is most up-to-date. + if (!ir.block.empty()) { + ir.SetTerm(IR::Term::LinkBlock{*ir.current_location}); + return false; + } X(64, Rt, ir.GetCNTPCT()); return true; case SystemRegisterEncoding::FPCR: