// Atomic memory operation instructions
//
output header {{
+ class LoadReserved : public RiscvStaticInst
+ {
+ protected:
+ Request::Flags memAccessFlags;
+
+ LoadReserved(const char *mnem, ExtMachInst _machInst,
+ OpClass __opClass)
+ : RiscvStaticInst(mnem, _machInst, __opClass)
+ {}
+
+ std::string
+ generateDisassembly(Addr pc, const SymbolTable *symtab) const;
+ };
+
+ class StoreCond : public RiscvStaticInst
+ {
+ protected:
+ Request::Flags memAccessFlags;
+
+ StoreCond(const char* mnem, ExtMachInst _machInst, OpClass __opClass)
+ : RiscvStaticInst(mnem, _machInst, __opClass)
+ {}
+
+ std::string
+ generateDisassembly(Addr pc, const SymbolTable *symtab) const;
+ };
+
class AtomicMemOp : public RiscvMacroInst
{
protected:
}};
output decoder {{
+ std::string LoadReserved::generateDisassembly(Addr pc,
+ const SymbolTable *symtab) const
+ {
+ std::stringstream ss;
+ ss << mnemonic << ' ' << regName(_destRegIdx[0]) << ", ("
+ << regName(_srcRegIdx[0]) << ')';
+ return ss.str();
+ }
+
+ std::string StoreCond::generateDisassembly(Addr pc,
+ const SymbolTable *symtab) const
+ {
+ std::stringstream ss;
+ ss << mnemonic << ' ' << regName(_destRegIdx[0]) << ", "
+ << regName(_srcRegIdx[1]) << ", ("
+ << regName(_srcRegIdx[0]) << ')';
+ return ss.str();
+ }
+
std::string AtomicMemOp::generateDisassembly(Addr pc,
const SymbolTable *symtab) const
{
std::stringstream ss;
- ss << csprintf("0x%08x", machInst) << ' ';
ss << mnemonic << ' ' << regName(_destRegIdx[0]) << ", "
<< regName(_srcRegIdx[1]) << ", ("
<< regName(_srcRegIdx[0]) << ')';
}
}};
+def template LRSCDeclare {{
+ class %(class_name)s : public %(base_class)s
+ {
+ public:
+ %(class_name)s(ExtMachInst machInst);
+
+ %(BasicExecDeclare)s
+
+ %(EACompDeclare)s
+
+ %(InitiateAccDeclare)s
+
+ %(CompleteAccDeclare)s
+ };
+}};
+
def template AtomicMemOpDeclare {{
/**
* Static instruction class for an AtomicMemOp operation
};
}};
+def template LRSCConstructor {{
+ %(class_name)s::%(class_name)s(ExtMachInst machInst):
+ %(base_class)s("%(mnemonic)s", machInst, %(op_class)s)
+ {
+ %(constructor)s;
+ if (AQ)
+ memAccessFlags = memAccessFlags | Request::ACQUIRE;
+ if (RL)
+ memAccessFlags = memAccessFlags | Request::RELEASE;
+ }
+}};
+
def template AtomicMemOpMacroConstructor {{
%(class_name)s::%(class_name)s(ExtMachInst machInst)
: %(base_class)s("%(mnemonic)s", machInst, %(op_class)s)
return new %(class_name)s(machInst);
}};
+def template LoadReservedExecute {{
+ Fault
+ %(class_name)s::execute(CPU_EXEC_CONTEXT *xc,
+ Trace::InstRecord *traceData) const
+ {
+ Addr EA;
+ Fault fault = NoFault;
+
+ %(op_decl)s;
+ %(op_rd)s;
+ %(ea_code)s;
+
+ if (fault == NoFault) {
+ fault = readMemAtomic(xc, traceData, EA, Mem, memAccessFlags);
+ %(memacc_code)s;
+ }
+
+ if (fault == NoFault) {
+ %(op_wb)s;
+ }
+
+ return fault;
+ }
+}};
+
+def template StoreCondExecute {{
+ Fault %(class_name)s::execute(CPU_EXEC_CONTEXT *xc,
+ Trace::InstRecord *traceData) const
+ {
+ Addr EA;
+ Fault fault = NoFault;
+ uint64_t result;
+
+ %(op_decl)s;
+ %(op_rd)s;
+ %(ea_code)s;
+
+ if (fault == NoFault) {
+ %(memacc_code)s;
+ }
+
+ if (fault == NoFault) {
+ fault = writeMemAtomic(xc, traceData, Mem, EA, memAccessFlags,
+ &result);
+ // RISC-V has the opposite convention gem5 has for success flags,
+ // so we invert the result here.
+ result = !result;
+ }
+
+ if (fault == NoFault) {
+ %(postacc_code)s;
+ }
+
+ if (fault == NoFault) {
+ %(op_wb)s;
+ }
+
+ return fault;
+ }
+}};
+
def template AtomicMemOpLoadExecute {{
Fault %(class_name)s::%(class_name)sLoad::execute(CPU_EXEC_CONTEXT *xc,
Trace::InstRecord *traceData) const
}
}};
+def template LRSCEACompExecute {{
+ Fault
+ %(class_name)s::eaComp(CPU_EXEC_CONTEXT *xc,
+ Trace::InstRecord *traceData) const
+ {
+ Addr EA;
+ Fault fault = NoFault;
+
+ %(op_decl)s;
+ %(op_rd)s;
+ %(ea_code)s;
+
+ if (fault == NoFault) {
+ %(op_wb)s;
+ xc->setEA(EA);
+ }
+
+ return fault;
+ }
+}};
+
def template AtomicMemOpLoadEACompExecute {{
Fault %(class_name)s::%(class_name)sLoad::eaComp(CPU_EXEC_CONTEXT *xc,
Trace::InstRecord *traceData) const
}
}};
+def template LoadReservedInitiateAcc {{
+ Fault
+ %(class_name)s::initiateAcc(CPU_EXEC_CONTEXT *xc,
+ Trace::InstRecord *traceData) const
+ {
+ Addr EA;
+ Fault fault = NoFault;
+
+ %(op_src_decl)s;
+ %(op_rd)s;
+ %(ea_code)s;
+
+ if (fault == NoFault) {
+ fault = initiateMemRead(xc, traceData, EA, Mem, memAccessFlags);
+ }
+
+ return fault;
+ }
+}};
+
+def template StoreCondInitiateAcc {{
+ Fault
+ %(class_name)s::initiateAcc(CPU_EXEC_CONTEXT *xc,
+ Trace::InstRecord *traceData) const
+ {
+ Addr EA;
+ Fault fault = NoFault;
+
+ %(op_decl)s;
+ %(op_rd)s;
+ %(ea_code)s;
+
+ if (fault == NoFault) {
+ %(memacc_code)s;
+ }
+
+ if (fault == NoFault) {
+ fault = writeMemTiming(xc, traceData, Mem, EA,
+ memAccessFlags, nullptr);
+ }
+
+ if (fault == NoFault) {
+ %(op_wb)s;
+ }
+
+ return fault;
+ }
+}};
+
def template AtomicMemOpLoadInitiateAcc {{
Fault %(class_name)s::%(class_name)sLoad::initiateAcc(CPU_EXEC_CONTEXT *xc,
Trace::InstRecord *traceData) const
}
}};
+def template LoadReservedCompleteAcc {{
+ Fault
+ %(class_name)s::completeAcc(PacketPtr pkt, CPU_EXEC_CONTEXT *xc,
+ Trace::InstRecord *traceData) const
+ {
+ Fault fault = NoFault;
+
+ %(op_decl)s;
+ %(op_rd)s;
+
+ getMem(pkt, Mem, traceData);
+
+ if (fault == NoFault) {
+ %(memacc_code)s;
+ }
+
+ if (fault == NoFault) {
+ %(op_wb)s;
+ }
+
+ return fault;
+ }
+}};
+
+def template StoreCondCompleteAcc {{
+ Fault %(class_name)s::completeAcc(Packet *pkt, CPU_EXEC_CONTEXT *xc,
+ Trace::InstRecord *traceData) const
+ {
+ Fault fault = NoFault;
+
+ %(op_dest_decl)s;
+
+ // RISC-V has the opposite convention gem5 has for success flags,
+ // so we invert the result here.
+ uint64_t result = !pkt->req->getExtraData();
+
+ if (fault == NoFault) {
+ %(postacc_code)s;
+ }
+
+ if (fault == NoFault) {
+ %(op_wb)s;
+ }
+
+ return fault;
+ }
+}};
+
def template AtomicMemOpLoadCompleteAcc {{
Fault %(class_name)s::%(class_name)sLoad::completeAcc(PacketPtr pkt,
CPU_EXEC_CONTEXT *xc, Trace::InstRecord *traceData) const
}
}};
+def format LoadReserved(memacc_code, postacc_code={{ }}, ea_code={{EA = Rs1;}},
+ mem_flags=[], inst_flags=[]) {{
+ mem_flags = makeList(mem_flags)
+ inst_flags = makeList(inst_flags)
+ iop = InstObjParams(name, Name, 'LoadReserved',
+ {'ea_code': ea_code, 'memacc_code': memacc_code,
+ 'postacc_code': postacc_code}, inst_flags)
+ iop.constructor += '\n\tmemAccessFlags = memAccessFlags | ' + \
+ '|'.join(['Request::%s' % flag for flag in mem_flags]) + ';'
+
+ header_output = LRSCDeclare.subst(iop)
+ decoder_output = LRSCConstructor.subst(iop)
+ decode_block = BasicDecode.subst(iop)
+ exec_output = LoadReservedExecute.subst(iop) \
+ + LRSCEACompExecute.subst(iop) \
+ + LoadReservedInitiateAcc.subst(iop) \
+ + LoadReservedCompleteAcc.subst(iop)
+}};
+
+def format StoreCond(memacc_code, postacc_code={{ }}, ea_code={{EA = Rs1;}},
+ mem_flags=[], inst_flags=[]) {{
+ mem_flags = makeList(mem_flags)
+ inst_flags = makeList(inst_flags)
+ iop = InstObjParams(name, Name, 'StoreCond',
+ {'ea_code': ea_code, 'memacc_code': memacc_code,
+ 'postacc_code': postacc_code}, inst_flags)
+ iop.constructor += '\n\tmemAccessFlags = memAccessFlags | ' + \
+ '|'.join(['Request::%s' % flag for flag in mem_flags]) + ';'
+
+ header_output = LRSCDeclare.subst(iop)
+ decoder_output = LRSCConstructor.subst(iop)
+ decode_block = BasicDecode.subst(iop)
+ exec_output = StoreCondExecute.subst(iop) \
+ + LRSCEACompExecute.subst(iop) \
+ + StoreCondInitiateAcc.subst(iop) \
+ + StoreCondCompleteAcc.subst(iop)
+}};
+
def format AtomicMemOp(load_code, store_code, ea_code, load_flags=[],
store_flags=[], inst_flags=[]) {{
macro_iop = InstObjParams(name, Name, 'AtomicMemOp', ea_code, inst_flags)
# select templates
- # The InitiateAcc template is the same for StoreCond templates as the
- # corresponding Store template..
- StoreCondInitiateAcc = StoreInitiateAcc
-
fullExecTemplate = eval(exec_template_base + 'Execute')
initiateAccTemplate = eval(exec_template_base + 'InitiateAcc')
completeAccTemplate = eval(exec_template_base + 'CompleteAcc')
}
}};
-def template StoreCondExecute {{
- Fault %(class_name)s::execute(CPU_EXEC_CONTEXT *xc,
- Trace::InstRecord *traceData) const
- {
- Addr EA;
- Fault fault = NoFault;
- uint64_t result;
-
- %(op_decl)s;
- %(op_rd)s;
- %(ea_code)s;
-
- if (fault == NoFault) {
- %(memacc_code)s;
- }
-
- if (fault == NoFault) {
- fault = writeMemAtomic(xc, traceData, Mem, EA, memAccessFlags,
- &result);
- // RISC-V has the opposite convention gem5 has for success flags,
- // so we invert the result here.
- result = !result;
- }
-
- if (fault == NoFault) {
- %(postacc_code)s;
- }
-
- if (fault == NoFault) {
- %(op_wb)s;
- }
-
- return fault;
- }
-}};
-
-def template StoreCondCompleteAcc {{
- Fault %(class_name)s::completeAcc(Packet *pkt, CPU_EXEC_CONTEXT *xc,
- Trace::InstRecord *traceData) const
- {
- Fault fault = NoFault;
-
- %(op_dest_decl)s;
-
- // RISC-V has the opposite convention gem5 has for success flags,
- // so we invert the result here.
- uint64_t result = !pkt->req->getExtraData();
-
- if (fault == NoFault) {
- %(postacc_code)s;
- }
-
- if (fault == NoFault) {
- %(op_wb)s;
- }
-
- return fault;
- }
-}};
-
def format Load(memacc_code, ea_code = {{EA = Rs1 + ldisp;}}, mem_flags=[],
inst_flags=[]) {{
(header_output, decoder_output, decode_block, exec_output) = \
LoadStoreBase(name, Name, ea_code, memacc_code, mem_flags, inst_flags,
'Store', exec_template_base='Store')
}};
-
-def format StoreCond(memacc_code, postacc_code, ea_code={{EA = Rs1;}},
- mem_flags=[], inst_flags=[], aq=0, rl=0) {{
- if aq:
- mem_flags = makeList(mem_flags) + ["ACQUIRE"]
- if rl:
- mem_flags = makeList(mem_flags) + ["RELEASE"]
- (header_output, decoder_output, decode_block, exec_output) = LoadStoreBase(
- name, Name, ea_code, memacc_code, mem_flags, inst_flags, 'Store',
- postacc_code, exec_template_base='StoreCond')
-}};
-
-def format LoadReserved(memacc_code, ea_code={{EA = Rs1;}}, mem_flags=[],
- inst_flags=[], aq=0, rl=0) {{
- if aq:
- mem_flags = makeList(mem_flags) + ["ACQUIRE"]
- if rl:
- mem_flags = makeList(mem_flags) + ["RELEASE"]
- (header_output, decoder_output, decode_block, exec_output) = LoadStoreBase(
- name, Name, ea_code, memacc_code, mem_flags, inst_flags, 'Load',
- exec_template_base='Load')
-}};
using namespace insttest;
// Memory (LR.W, SC.W)
- expect<pair<int64_t, uint64_t>>({-1, 0}, []{
+ expect<pair<int64_t, int64_t>>({-1, 256}, []{
int32_t mem = -1;
int64_t rs2 = 256;
- int64_t rd = A::lr_w(mem);
- pair<int64_t, uint64_t> result = A::sc_w(rs2, mem);
- return pair<int64_t, uint64_t>(rd, result.second);
+ int64_t rd;
+ pair<int64_t, uint64_t> result;
+ do {
+ rd = A::lr_w(mem);
+ result = A::sc_w(rs2, mem);
+ } while (result.second == 1);
+ return pair<int64_t, uint64_t>(rd, result.first);
}, "lr.w/sc.w");
expect<pair<bool, int64_t>>({true, 200}, []{
int32_t mem = 200;
"amomaxu.w, sign extend");
// Memory (LR.D, SC.D)
- expect<pair<int64_t, uint64_t>>({-1, 0}, []{
+ expect<pair<int64_t, int64_t>>({-1, 256}, []{
int64_t mem = -1;
int64_t rs2 = 256;
- int64_t rd = A::lr_d(mem);
- pair<int64_t, uint64_t> result = A::sc_d(rs2, mem);
- return pair<int64_t, uint64_t>(rd, result.second);
+ int64_t rd;
+ pair<int64_t, uint64_t> result;
+ do {
+ rd = A::lr_d(mem);
+ result = A::sc_d(rs2, mem);
+ } while (result.second == 1);
+ return pair<int64_t, uint64_t>(rd, result.first);
}, "lr.d/sc.d");
expect<pair<bool, int64_t>>({true, 200}, []{
int64_t mem = 200;