blockmem.isa revision 3274
12SN/A//////////////////////////////////////////////////////////////////// 29448SAndreas.Sandberg@ARM.com// 39920Syasuko.eckert@amd.com// Block Memory instructions 48733Sgeoffrey.blake@arm.com// 58733Sgeoffrey.blake@arm.com 68733Sgeoffrey.blake@arm.comoutput header {{ 78733Sgeoffrey.blake@arm.com 88733Sgeoffrey.blake@arm.com class BlockMem : public SparcMacroInst 98733Sgeoffrey.blake@arm.com { 108733Sgeoffrey.blake@arm.com protected: 118733Sgeoffrey.blake@arm.com 128733Sgeoffrey.blake@arm.com // Constructor 138733Sgeoffrey.blake@arm.com // We make the assumption that all block memory operations 148733Sgeoffrey.blake@arm.com // Will take 8 instructions to execute 151762SN/A BlockMem(const char *mnem, 162SN/A ExtMachInst _machInst, OpClass __opClass) : 172SN/A SparcMacroInst(mnem, _machInst, __opClass, 8) 182SN/A {} 192SN/A 202SN/A std::string generateDisassembly(Addr pc, 212SN/A const SymbolTable *symtab) const; 222SN/A }; 232SN/A 242SN/A class BlockMemImm : public BlockMem 252SN/A { 262SN/A protected: 272SN/A 282SN/A // Constructor 292SN/A BlockMemImm(const char *mnem, 302SN/A ExtMachInst _machInst, OpClass __opClass) : 312SN/A BlockMem(mnem, _machInst, __opClass), 322SN/A imm(sext<13>(SIMM13)) 332SN/A {} 342SN/A 352SN/A std::string generateDisassembly(Addr pc, 362SN/A const SymbolTable *symtab) const; 372SN/A 382SN/A const int32_t imm; 392SN/A }; 402665Ssaidi@eecs.umich.edu 412665Ssaidi@eecs.umich.edu class BlockMemMicro : public SparcDelayedMicroInst 422665Ssaidi@eecs.umich.edu { 432665Ssaidi@eecs.umich.edu protected: 442SN/A 452SN/A // Constructor 462623SN/A BlockMemMicro(const char *mnem, ExtMachInst _machInst, 472623SN/A OpClass __opClass, int8_t _offset) : 482SN/A SparcDelayedMicroInst(mnem, _machInst, __opClass), 491354SN/A offset(_offset) 506658Snate@binkert.org {} 511717SN/A 528887Sgeoffrey.blake@arm.com std::string generateDisassembly(Addr pc, 538229Snate@binkert.org const SymbolTable *symtab) const; 542683Sktlim@umich.edu 551354SN/A const int8_t offset; 562387SN/A }; 572387SN/A 582387SN/A class BlockMemImmMicro : public BlockMemMicro 5956SN/A { 608779Sgblack@eecs.umich.edu protected: 615348Ssaidi@eecs.umich.edu 622SN/A // Constructor 632SN/A BlockMemImmMicro(const char *mnem, ExtMachInst _machInst, 648779Sgblack@eecs.umich.edu OpClass __opClass, int8_t _offset) : 658779Sgblack@eecs.umich.edu BlockMemMicro(mnem, _machInst, __opClass, _offset), 662SN/A imm(sext<13>(SIMM13)) 678779Sgblack@eecs.umich.edu {} 682SN/A 694182Sgblack@eecs.umich.edu std::string generateDisassembly(Addr pc, 704182Sgblack@eecs.umich.edu const SymbolTable *symtab) const; 718779Sgblack@eecs.umich.edu 728779Sgblack@eecs.umich.edu const int32_t imm; 734182Sgblack@eecs.umich.edu }; 742SN/A}}; 752SN/A 762SN/Aoutput decoder {{ 772SN/A std::string BlockMem::generateDisassembly(Addr pc, 782SN/A const SymbolTable *symtab) const 798737Skoansin.tan@gmail.com { 8010061Sandreas@sandberg.pp.se std::stringstream response; 812420SN/A bool load = flags[IsLoad]; 822623SN/A bool save = flags[IsStore]; 832SN/A 842107SN/A printMnemonic(response, mnemonic); 852159SN/A if(save) 862455SN/A { 872455SN/A printReg(response, _srcRegIdx[0]); 889920Syasuko.eckert@amd.com ccprintf(response, ", "); 892386SN/A } 9010061Sandreas@sandberg.pp.se ccprintf(response, "[ "); 9110061Sandreas@sandberg.pp.se printReg(response, _srcRegIdx[!save ? 0 : 1]); 922623SN/A ccprintf(response, " + "); 932SN/A printReg(response, _srcRegIdx[!save ? 1 : 2]); 941371SN/A ccprintf(response, " ]"); 955348Ssaidi@eecs.umich.edu if(load) 967720Sgblack@eecs.umich.edu { 975348Ssaidi@eecs.umich.edu ccprintf(response, ", "); 987720Sgblack@eecs.umich.edu printReg(response, _destRegIdx[0]); 995348Ssaidi@eecs.umich.edu } 1007720Sgblack@eecs.umich.edu 1017720Sgblack@eecs.umich.edu return response.str(); 1025348Ssaidi@eecs.umich.edu } 1035348Ssaidi@eecs.umich.edu 1042SN/A std::string BlockMemImm::generateDisassembly(Addr pc, 1055807Snate@binkert.org const SymbolTable *symtab) const 1062SN/A { 1072SN/A std::stringstream response; 1082SN/A bool load = flags[IsLoad]; 1092SN/A bool save = flags[IsStore]; 1102SN/A 1112SN/A printMnemonic(response, mnemonic); 1122SN/A if(save) 1132SN/A { 1142SN/A printReg(response, _srcRegIdx[0]); 1151400SN/A ccprintf(response, ", "); 1165529Snate@binkert.org } 1172623SN/A ccprintf(response, "[ "); 1182SN/A printReg(response, _srcRegIdx[!save ? 0 : 1]); 1191400SN/A if(imm >= 0) 1202683Sktlim@umich.edu ccprintf(response, " + 0x%x ]", imm); 1212683Sktlim@umich.edu else 1222190SN/A ccprintf(response, " + -0x%x ]", -imm); 1232683Sktlim@umich.edu if(load) 1242683Sktlim@umich.edu { 1252683Sktlim@umich.edu ccprintf(response, ", "); 1262680Sktlim@umich.edu printReg(response, _destRegIdx[0]); 1278733Sgeoffrey.blake@arm.com } 1288733Sgeoffrey.blake@arm.com 1298887Sgeoffrey.blake@arm.com return response.str(); 1305169Ssaidi@eecs.umich.edu } 1315169Ssaidi@eecs.umich.edu 1325496Ssaidi@eecs.umich.edu}}; 1335496Ssaidi@eecs.umich.edu 1345496Ssaidi@eecs.umich.edudef template LoadStoreExecute {{ 1358276SAli.Saidi@ARM.com Fault %(class_name)s::execute(%(CPU_exec_context)s *xc, 1365894Sgblack@eecs.umich.edu Trace::InstRecord *traceData) const 1375496Ssaidi@eecs.umich.edu { 1385496Ssaidi@eecs.umich.edu Fault fault = NoFault; 1395496Ssaidi@eecs.umich.edu uint64_t write_result = 0; 1405894Sgblack@eecs.umich.edu Addr EA; 1415496Ssaidi@eecs.umich.edu %(op_decl)s; 1425496Ssaidi@eecs.umich.edu %(op_rd)s; 1435496Ssaidi@eecs.umich.edu %(priv_check)s; 1445496Ssaidi@eecs.umich.edu %(ea_code)s; 1455496Ssaidi@eecs.umich.edu DPRINTF(Sparc, "The address is 0x%x\n", EA); 1465496Ssaidi@eecs.umich.edu xc->read(EA, (uint%(mem_acc_size)s_t&)Mem, 0); 1475496Ssaidi@eecs.umich.edu %(code)s; 1485169Ssaidi@eecs.umich.edu 1492SN/A if(fault == NoFault) 1502SN/A { 1512SN/A xc->write((uint%(mem_acc_size)s_t)Mem, EA, 0, &write_result); 1522SN/A //Write the resulting state to the execution context 1532SN/A %(op_wb)s; 1542SN/A } 1554181Sgblack@eecs.umich.edu 1564181Sgblack@eecs.umich.edu return fault; 1572107SN/A } 1583276Sgblack@eecs.umich.edu}}; 1591469SN/A 1604377Sgblack@eecs.umich.edudef template BlockMemDeclare {{ 1614377Sgblack@eecs.umich.edu /** 1624377Sgblack@eecs.umich.edu * Static instruction class for a block memory operation 1634377Sgblack@eecs.umich.edu */ 1644377Sgblack@eecs.umich.edu class %(class_name)s : public %(base_class)s 1654377Sgblack@eecs.umich.edu { 1662623SN/A public: 1675894Sgblack@eecs.umich.edu //Constructor 1682623SN/A %(class_name)s(MachInst machInst); 1692623SN/A 1702623SN/A protected: 171180SN/A class %(class_name)s_0 : public %(base_class)sMicro 1728737Skoansin.tan@gmail.com { 1738737Skoansin.tan@gmail.com public: 1742SN/A //Constructor 1752SN/A %(class_name)s_0(MachInst machInst) : 176334SN/A %(base_class)sMicro("%(mnemonic)s[0]", 177334SN/A machInst, %(op_class)s, 0*8) 1782SN/A {;} 1799461Snilay@cs.wisc.edu %(BasicExecDeclare)s 1809461Snilay@cs.wisc.edu }; 1812SN/A 1822SN/A class %(class_name)s_1 : public %(base_class)sMicro 183334SN/A { 1845999Snate@binkert.org public: 1858834Satgutier@umich.edu //Constructor 1868834Satgutier@umich.edu %(class_name)s_1(MachInst machInst) : 1878834Satgutier@umich.edu %(base_class)sMicro("%(mnemonic)s[1]", 188707SN/A machInst, %(op_class)s, 1*8) 1894998Sgblack@eecs.umich.edu {;} 1904998Sgblack@eecs.umich.edu %(BasicExecDeclare)s 1918834Satgutier@umich.edu }; 1928834Satgutier@umich.edu 1938834Satgutier@umich.edu class %(class_name)s_2 : public %(base_class)sMicro 1948834Satgutier@umich.edu { 1958834Satgutier@umich.edu public: 1968834Satgutier@umich.edu //Constructor 1978834Satgutier@umich.edu %(class_name)s_2(MachInst machInst) : 1987897Shestness@cs.utexas.edu %(base_class)sMicro("%(mnemonic)s[2]", 1994998Sgblack@eecs.umich.edu machInst, %(op_class)s, 2*8) 2004998Sgblack@eecs.umich.edu {;} 2014998Sgblack@eecs.umich.edu %(BasicExecDeclare)s 2028834Satgutier@umich.edu }; 203707SN/A 204707SN/A class %(class_name)s_3 : public %(base_class)sMicro 205707SN/A { 2062SN/A public: 2078834Satgutier@umich.edu //Constructor 2088834Satgutier@umich.edu %(class_name)s_3(MachInst machInst) : 2098834Satgutier@umich.edu %(base_class)sMicro("%(mnemonic)s[3]", 2108834Satgutier@umich.edu machInst, %(op_class)s, 3*8) 2118834Satgutier@umich.edu {;} 2127897Shestness@cs.utexas.edu %(BasicExecDeclare)s 2137897Shestness@cs.utexas.edu }; 2147897Shestness@cs.utexas.edu 2157897Shestness@cs.utexas.edu class %(class_name)s_4 : public %(base_class)sMicro 2167897Shestness@cs.utexas.edu { 2177897Shestness@cs.utexas.edu public: 2187897Shestness@cs.utexas.edu //Constructor 2197897Shestness@cs.utexas.edu %(class_name)s_4(MachInst machInst) : 2207897Shestness@cs.utexas.edu %(base_class)sMicro("%(mnemonic)s[4]", 2217897Shestness@cs.utexas.edu machInst, %(op_class)s, 4*8) 2227897Shestness@cs.utexas.edu {;} 2237897Shestness@cs.utexas.edu %(BasicExecDeclare)s 2247897Shestness@cs.utexas.edu }; 2257897Shestness@cs.utexas.edu 2267897Shestness@cs.utexas.edu class %(class_name)s_5 : public %(base_class)sMicro 2277897Shestness@cs.utexas.edu { 2287897Shestness@cs.utexas.edu public: 2297897Shestness@cs.utexas.edu //Constructor 2307897Shestness@cs.utexas.edu %(class_name)s_5(MachInst machInst) : 2317897Shestness@cs.utexas.edu %(base_class)sMicro("%(mnemonic)s[5]", 2327897Shestness@cs.utexas.edu machInst, %(op_class)s, 5*8) 2337897Shestness@cs.utexas.edu {;} 2347897Shestness@cs.utexas.edu %(BasicExecDeclare)s 2357897Shestness@cs.utexas.edu }; 2367897Shestness@cs.utexas.edu 2377897Shestness@cs.utexas.edu class %(class_name)s_6 : public %(base_class)sMicro 2389920Syasuko.eckert@amd.com { 2399920Syasuko.eckert@amd.com public: 2409920Syasuko.eckert@amd.com //Constructor 2419920Syasuko.eckert@amd.com %(class_name)s_6(MachInst machInst) : 2422SN/A %(base_class)sMicro("%(mnemonic)s[6]", 2435999Snate@binkert.org machInst, %(op_class)s, 6*8) 2447897Shestness@cs.utexas.edu {;} 2457897Shestness@cs.utexas.edu %(BasicExecDeclare)s 2467897Shestness@cs.utexas.edu }; 2477897Shestness@cs.utexas.edu 2487897Shestness@cs.utexas.edu class %(class_name)s_7 : public %(base_class)sMicro 2497897Shestness@cs.utexas.edu { 2507897Shestness@cs.utexas.edu public: 2517897Shestness@cs.utexas.edu //Constructor 2522SN/A %(class_name)s_7(MachInst machInst) : 253124SN/A %(base_class)sMicro("%(mnemonic)s[7]", 254124SN/A machInst, %(op_class)s, 7*8) 255334SN/A { 256124SN/A flags[IsLastMicroOp] = true; 2572SN/A } 2585999Snate@binkert.org %(BasicExecDeclare)s 259729SN/A }; 2602SN/A }; 2612390SN/A}}; 2625999Snate@binkert.org 2632SN/A// Basic instruction class constructor template. 2642SN/Adef template BlockMemConstructor {{ 2652390SN/A inline %(class_name)s::%(class_name)s(MachInst machInst) 2665999Snate@binkert.org : %(base_class)s("%(mnemonic)s", machInst, %(op_class)s) 2672390SN/A { 2682390SN/A %(constructor)s; 2692390SN/A microOps[0] = new %(class_name)s_0(machInst); 2705999Snate@binkert.org microOps[1] = new %(class_name)s_1(machInst); 2712SN/A microOps[2] = new %(class_name)s_2(machInst); 2722SN/A microOps[3] = new %(class_name)s_3(machInst); 2732390SN/A microOps[4] = new %(class_name)s_4(machInst); 2745999Snate@binkert.org microOps[5] = new %(class_name)s_5(machInst); 2752390SN/A microOps[6] = new %(class_name)s_6(machInst); 2762390SN/A microOps[7] = new %(class_name)s_7(machInst); 27710061Sandreas@sandberg.pp.se } 27810061Sandreas@sandberg.pp.se}}; 27910061Sandreas@sandberg.pp.se 28010061Sandreas@sandberg.pp.sedef template MicroLoadExecute {{ 28110061Sandreas@sandberg.pp.se Fault %(class_name)s_%(micro_pc)s::execute(%(CPU_exec_context)s *xc, 28210061Sandreas@sandberg.pp.se Trace::InstRecord *traceData) const 28310061Sandreas@sandberg.pp.se { 28410061Sandreas@sandberg.pp.se Fault fault = NoFault; 28510061Sandreas@sandberg.pp.se Addr EA; 28610193SCurtis.Dunham@arm.com %(op_decl)s; 28710193SCurtis.Dunham@arm.com %(op_rd)s; 28810193SCurtis.Dunham@arm.com %(fault_check)s; 2899448SAndreas.Sandberg@ARM.com %(ea_code)s; 2909448SAndreas.Sandberg@ARM.com DPRINTF(Sparc, "The address is 0x%x\n", EA); 2919448SAndreas.Sandberg@ARM.com xc->read(EA, (uint%(mem_acc_size)s_t&)Mem, 0); 2922SN/A %(code)s; 2931371SN/A 2941371SN/A if(fault == NoFault) 2952623SN/A { 2965543Ssaidi@eecs.umich.edu //Write the resulting state to the execution context 2973918Ssaidi@eecs.umich.edu %(op_wb)s; 2981371SN/A } 299726SN/A 300726SN/A return fault; 301726SN/A } 302726SN/A}}; 303726SN/A 304726SN/Adef template MicroStoreExecute {{ 305726SN/A Fault %(class_name)s_%(micro_pc)s::execute(%(CPU_exec_context)s *xc, 306726SN/A Trace::InstRecord *traceData) const 307726SN/A { 308726SN/A Fault fault = NoFault; 309705SN/A uint64_t write_result = 0; 3103735Sstever@eecs.umich.edu Addr EA; 311726SN/A %(op_decl)s; 3127897Shestness@cs.utexas.edu %(op_rd)s; 3132683Sktlim@umich.edu %(fault_check)s; 314726SN/A %(ea_code)s; 315705SN/A DPRINTF(Sparc, "The address is 0x%x\n", EA); 3163735Sstever@eecs.umich.edu %(code)s; 317726SN/A 3187897Shestness@cs.utexas.edu if(fault == NoFault) 3199918Ssteve.reinhardt@amd.com { 3202683Sktlim@umich.edu xc->write((uint%(mem_acc_size)s_t)Mem, EA, 0, &write_result); 321726SN/A //Write the resulting state to the execution context 322705SN/A %(op_wb)s; 3233735Sstever@eecs.umich.edu } 3242455SN/A 3257897Shestness@cs.utexas.edu return fault; 3269918Ssteve.reinhardt@amd.com } 3272683Sktlim@umich.edu}}; 328726SN/A 329705SN/Alet {{ 3309920Syasuko.eckert@amd.com 3319920Syasuko.eckert@amd.com def doBlockMemFormat(code, execute, name, Name, opt_flags): 3329920Syasuko.eckert@amd.com # XXX Need to take care of pstate.hpriv as well. The lower ASIs 3339920Syasuko.eckert@amd.com # are split into ones that are available in priv and hpriv, and 3349920Syasuko.eckert@amd.com # those that are only available in hpriv 3359920Syasuko.eckert@amd.com faultCheck = '''if(bits(Pstate,2,2) == 0 && (EXT_ASI & 0x80) == 0) 3369920Syasuko.eckert@amd.com return new PrivilegedAction; 3373735Sstever@eecs.umich.edu if(AsiIsAsIfUser(EXT_ASI) && !bits(Pstate,2,2)) 338726SN/A return new PrivilegedAction; 3397897Shestness@cs.utexas.edu if(RD & 0xf) 3402683Sktlim@umich.edu return new IllegalInstruction; 341726SN/A if(EA & 0x3f) 342705SN/A return new MemAddressNotAligned;''' 3433735Sstever@eecs.umich.edu addrCalcReg = 'EA = Rs1 + Rs2 + offset;' 344726SN/A addrCalcImm = 'EA = Rs1 + imm + offset;' 3457897Shestness@cs.utexas.edu iop = InstObjParams(name, Name, 'BlockMem', code, opt_flags) 3469918Ssteve.reinhardt@amd.com iop_imm = InstObjParams(name, Name + 'Imm', 'BlockMemImm', code, opt_flags) 3472683Sktlim@umich.edu header_output = BlockMemDeclare.subst(iop) + BlockMemDeclare.subst(iop_imm) 348726SN/A decoder_output = BlockMemConstructor.subst(iop) + BlockMemConstructor.subst(iop_imm) 349726SN/A decode_block = ROrImmDecode.subst(iop) 3503735Sstever@eecs.umich.edu matcher = re.compile(r'Frd_N') 3513735Sstever@eecs.umich.edu exec_output = '' 3522455SN/A for microPC in range(8): 3537897Shestness@cs.utexas.edu pcedCode = matcher.sub("Frd_%d" % microPC, code) 3549918Ssteve.reinhardt@amd.com iop = InstObjParams(name, Name, 'BlockMem', pcedCode, 3552683Sktlim@umich.edu opt_flags, {"ea_code": addrCalcReg, 356726SN/A "fault_check": faultCheck, "micro_pc": microPC}) 357705SN/A iop_imm = InstObjParams(name, Name + 'Imm', 'BlockMemImm', pcedCode, 3589920Syasuko.eckert@amd.com opt_flags, {"ea_code": addrCalcImm, 3599920Syasuko.eckert@amd.com "fault_check": faultCheck, "micro_pc": microPC}) 3609920Syasuko.eckert@amd.com exec_output += execute.subst(iop) 3619920Syasuko.eckert@amd.com exec_output += execute.subst(iop_imm) 3629920Syasuko.eckert@amd.com faultCheck = '' 3639920Syasuko.eckert@amd.com return (header_output, decoder_output, exec_output, decode_block) 3649920Syasuko.eckert@amd.com}}; 3657597Sminkyu.jeong@arm.com 3667597Sminkyu.jeong@arm.comdef format BlockLoad(code, *opt_flags) {{ 3677600Sminkyu.jeong@arm.com (header_output, 3687600Sminkyu.jeong@arm.com decoder_output, 3697600Sminkyu.jeong@arm.com exec_output, 3707600Sminkyu.jeong@arm.com decode_block) = doBlockMemFormat(code, MicroLoadExecute, 3717600Sminkyu.jeong@arm.com name, Name, opt_flags) 3727600Sminkyu.jeong@arm.com}}; 3737720Sgblack@eecs.umich.edu 3747720Sgblack@eecs.umich.edudef format BlockStore(code, *opt_flags) {{ 3757720Sgblack@eecs.umich.edu (header_output, 3767720Sgblack@eecs.umich.edu decoder_output, 3777720Sgblack@eecs.umich.edu exec_output, 378705SN/A decode_block) = doBlockMemFormat(code, MicroStoreExecute, 3794172Ssaidi@eecs.umich.edu name, Name, opt_flags) 3804172Ssaidi@eecs.umich.edu}}; 3814172Ssaidi@eecs.umich.edu