2006-01-29 23:25:54 +01:00
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Mem instructions
|
|
|
|
//
|
|
|
|
|
|
|
|
output header {{
|
|
|
|
/**
|
2006-04-01 03:31:53 +02:00
|
|
|
* Base class for memory operations.
|
2006-01-29 23:25:54 +01:00
|
|
|
*/
|
|
|
|
class Mem : public SparcStaticInst
|
|
|
|
{
|
2006-03-07 10:33:10 +01:00
|
|
|
protected:
|
2006-01-29 23:25:54 +01:00
|
|
|
|
2006-03-07 10:33:10 +01:00
|
|
|
// Constructor
|
2006-03-16 19:58:50 +01:00
|
|
|
Mem(const char *mnem, ExtMachInst _machInst, OpClass __opClass) :
|
2006-03-07 10:33:10 +01:00
|
|
|
SparcStaticInst(mnem, _machInst, __opClass)
|
|
|
|
{
|
|
|
|
}
|
2006-01-29 23:25:54 +01:00
|
|
|
|
2006-03-07 10:33:10 +01:00
|
|
|
std::string generateDisassembly(Addr pc,
|
|
|
|
const SymbolTable *symtab) const;
|
2006-01-29 23:25:54 +01:00
|
|
|
};
|
2006-04-01 03:31:53 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class for memory operations which use an immediate offset.
|
|
|
|
*/
|
|
|
|
class MemImm : public Mem
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
|
|
|
|
// Constructor
|
|
|
|
MemImm(const char *mnem, ExtMachInst _machInst, OpClass __opClass) :
|
|
|
|
Mem(mnem, _machInst, __opClass), imm(SIMM13)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string generateDisassembly(Addr pc,
|
|
|
|
const SymbolTable *symtab) const;
|
|
|
|
|
2006-04-06 20:52:44 +02:00
|
|
|
int32_t imm;
|
2006-04-01 03:31:53 +02:00
|
|
|
};
|
2006-01-29 23:25:54 +01:00
|
|
|
}};
|
|
|
|
|
|
|
|
output decoder {{
|
2006-04-01 03:31:53 +02:00
|
|
|
std::string Mem::generateDisassembly(Addr pc,
|
|
|
|
const SymbolTable *symtab) const
|
2006-01-29 23:25:54 +01:00
|
|
|
{
|
2006-04-01 03:31:53 +02:00
|
|
|
std::stringstream response;
|
2006-04-06 20:52:44 +02:00
|
|
|
bool load = flags[IsLoad];
|
2006-04-01 03:31:53 +02:00
|
|
|
|
|
|
|
printMnemonic(response, mnemonic);
|
|
|
|
if(!load)
|
|
|
|
{
|
|
|
|
printReg(response, _srcRegIdx[0]);
|
|
|
|
ccprintf(response, ", ");
|
|
|
|
}
|
|
|
|
ccprintf(response, "[ ");
|
|
|
|
printReg(response, _srcRegIdx[load ? 0 : 1]);
|
|
|
|
ccprintf(response, " + ");
|
|
|
|
printReg(response, _srcRegIdx[load ? 1 : 2]);
|
|
|
|
ccprintf(response, " ]");
|
|
|
|
if(load)
|
|
|
|
{
|
|
|
|
ccprintf(response, ", ");
|
|
|
|
printReg(response, _destRegIdx[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return response.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string MemImm::generateDisassembly(Addr pc,
|
|
|
|
const SymbolTable *symtab) const
|
|
|
|
{
|
|
|
|
std::stringstream response;
|
2006-04-06 20:52:44 +02:00
|
|
|
bool load = flags[IsLoad];
|
2006-04-01 03:31:53 +02:00
|
|
|
|
|
|
|
printMnemonic(response, mnemonic);
|
|
|
|
if(!load)
|
|
|
|
{
|
|
|
|
printReg(response, _srcRegIdx[0]);
|
|
|
|
ccprintf(response, ", ");
|
|
|
|
}
|
|
|
|
ccprintf(response, "[ ");
|
|
|
|
printReg(response, _srcRegIdx[load ? 0 : 1]);
|
|
|
|
ccprintf(response, " + 0x%x ]", imm);
|
|
|
|
if(load)
|
|
|
|
{
|
|
|
|
ccprintf(response, ", ");
|
|
|
|
printReg(response, _destRegIdx[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return response.str();
|
2006-01-29 23:25:54 +01:00
|
|
|
}
|
|
|
|
}};
|
|
|
|
|
|
|
|
def template MemExecute {{
|
2006-03-07 10:33:10 +01:00
|
|
|
Fault %(class_name)s::execute(%(CPU_exec_context)s *xc,
|
|
|
|
Trace::InstRecord *traceData) const
|
2006-01-29 23:25:54 +01:00
|
|
|
{
|
2006-03-07 10:33:10 +01:00
|
|
|
Fault fault = NoFault;
|
2006-03-28 22:13:57 +02:00
|
|
|
Addr EA;
|
2006-03-07 10:33:10 +01:00
|
|
|
%(op_decl)s;
|
|
|
|
%(op_rd)s;
|
2006-03-28 22:13:57 +02:00
|
|
|
%(ea_code)s;
|
2006-04-06 20:52:44 +02:00
|
|
|
%(load)s;
|
2006-03-07 10:33:10 +01:00
|
|
|
%(code)s;
|
2006-04-06 20:52:44 +02:00
|
|
|
%(store)s;
|
2006-01-29 23:25:54 +01:00
|
|
|
|
2006-03-07 10:33:10 +01:00
|
|
|
if(fault == NoFault)
|
|
|
|
{
|
2006-01-29 23:25:54 +01:00
|
|
|
//Write the resulting state to the execution context
|
|
|
|
%(op_wb)s;
|
2006-03-07 10:33:10 +01:00
|
|
|
}
|
2006-01-29 23:25:54 +01:00
|
|
|
|
2006-03-07 10:33:10 +01:00
|
|
|
return fault;
|
2006-01-29 23:25:54 +01:00
|
|
|
}
|
|
|
|
}};
|
|
|
|
|
2006-04-06 20:52:44 +02:00
|
|
|
let {{
|
|
|
|
# Leave memAccessFlags at 0 for now
|
|
|
|
loadString = "xc->read(EA, (uint%(width)s_t&)Mem, 0);"
|
|
|
|
storeString = "uint64_t write_result = 0; \
|
|
|
|
xc->write((uint%(width)s_t)Mem, EA, 0, &write_result);"
|
|
|
|
|
|
|
|
def doMemFormat(code, load, store, name, Name, opt_flags):
|
2006-04-01 03:31:53 +02:00
|
|
|
addrCalcReg = 'EA = Rs1 + Rs2;'
|
|
|
|
addrCalcImm = 'EA = Rs1 + SIMM13;'
|
2006-04-06 20:52:44 +02:00
|
|
|
iop = InstObjParams(name, Name, 'Mem', code,
|
|
|
|
opt_flags, ("ea_code", addrCalcReg),
|
|
|
|
("load", load), ("store", store))
|
|
|
|
iop_imm = InstObjParams(name, Name + 'Imm', 'MemImm', code,
|
|
|
|
opt_flags, ("ea_code", addrCalcImm),
|
|
|
|
("load", load), ("store", store))
|
2006-04-01 03:31:53 +02:00
|
|
|
header_output = BasicDeclare.subst(iop) + BasicDeclare.subst(iop_imm)
|
|
|
|
decoder_output = BasicConstructor.subst(iop) + BasicConstructor.subst(iop_imm)
|
|
|
|
decode_block = ROrImmDecode.subst(iop)
|
|
|
|
exec_output = MemExecute.subst(iop) + MemExecute.subst(iop_imm)
|
2006-04-06 20:52:44 +02:00
|
|
|
return (header_output, decoder_output, exec_output, decode_block)
|
|
|
|
}};
|
|
|
|
|
|
|
|
def format Load(code, width, *opt_flags) {{
|
|
|
|
(header_output,
|
|
|
|
decoder_output,
|
|
|
|
exec_output,
|
|
|
|
decode_block) = doMemFormat(code,
|
|
|
|
loadString % {"width":width}, '', name, Name, opt_flags)
|
|
|
|
}};
|
|
|
|
|
|
|
|
def format Store(code, width, *opt_flags) {{
|
|
|
|
(header_output,
|
|
|
|
decoder_output,
|
|
|
|
exec_output,
|
|
|
|
decode_block) = doMemFormat(code, '',
|
|
|
|
storeString % {"width":width}, name, Name, opt_flags)
|
|
|
|
}};
|
|
|
|
|
|
|
|
def format LoadStore(code, width, *opt_flags) {{
|
|
|
|
(header_output,
|
|
|
|
decoder_output,
|
|
|
|
exec_output,
|
|
|
|
decode_block) = doMemFormat(code,
|
|
|
|
loadString % {"width":width}, storeString % {"width":width},
|
|
|
|
name, Name, opt_flags)
|
2006-01-29 23:25:54 +01:00
|
|
|
}};
|