diff options
-rw-r--r-- | src/arch/generic/memhelpers.hh | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/arch/generic/memhelpers.hh b/src/arch/generic/memhelpers.hh index 35e666b92..6fe1707a0 100644 --- a/src/arch/generic/memhelpers.hh +++ b/src/arch/generic/memhelpers.hh @@ -121,4 +121,36 @@ writeMemAtomic(XC *xc, Trace::InstRecord *traceData, const MemT &mem, return fault; } +/// Do atomic read-modify-write (AMO) in atomic mode +template <class XC, class MemT> +Fault +amoMemAtomic(XC *xc, Trace::InstRecord *traceData, MemT &mem, Addr addr, + Request::Flags flags, AtomicOpFunctor *amo_op) +{ + assert(amo_op); + + // mem will hold the previous value at addr after the AMO completes + memset(&mem, 0, sizeof(mem)); + + Fault fault = xc->amoMem(addr, (uint8_t *)&mem, sizeof(MemT), flags, + amo_op); + + if (fault == NoFault) { + mem = TheISA::gtoh(mem); + if (traceData) + traceData->setData(mem); + } + return fault; +} + +/// Do atomic read-modify-wrote (AMO) in timing mode +template <class XC, class MemT> +Fault +initiateMemAMO(XC *xc, Trace::InstRecord *traceData, Addr addr, MemT& mem, + Request::Flags flags, AtomicOpFunctor *amo_op) +{ + assert(amo_op); + return xc->initiateMemAMO(addr, sizeof(MemT), flags, amo_op); +} + #endif |