util.isa

来自「M5,一个功能强大的多处理器系统模拟器.很多针对处理器架构,性能的研究都使用它作」· ISA 代码 · 共 334 行

ISA
334
字号
//////////////////////////////////////////////////////////////////////// Mem utility templates and functions//output header {{        /**         * Base class for memory operations.         */        class Mem : public SparcStaticInst        {          protected:            // Constructor            Mem(const char *mnem, ExtMachInst _machInst, OpClass __opClass) :                SparcStaticInst(mnem, _machInst, __opClass)            {            }            std::string generateDisassembly(Addr pc,                    const SymbolTable *symtab) const;        };        /**         * 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(sext<13>(SIMM13))            {}            std::string generateDisassembly(Addr pc,                    const SymbolTable *symtab) const;            const int32_t imm;        };}};output decoder {{        std::string Mem::generateDisassembly(Addr pc,                const SymbolTable *symtab) const        {            std::stringstream response;            bool load = flags[IsLoad];            bool store = flags[IsStore];            printMnemonic(response, mnemonic);            if(store)            {                printReg(response, _srcRegIdx[0]);                ccprintf(response, ", ");            }            ccprintf(response, "[");            if(_srcRegIdx[!store ? 0 : 1] != 0)            {                printSrcReg(response, !store ? 0 : 1);                ccprintf(response, " + ");            }            printSrcReg(response, !store ? 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;            bool load = flags[IsLoad];            bool save = flags[IsStore];            printMnemonic(response, mnemonic);            if(save)            {                printReg(response, _srcRegIdx[0]);                ccprintf(response, ", ");            }            ccprintf(response, "[");            if(_srcRegIdx[!save ? 0 : 1] != 0)            {                printReg(response, _srcRegIdx[!save ? 0 : 1]);                ccprintf(response, " + ");            }            if(imm >= 0)                ccprintf(response, "0x%x]", imm);            else                ccprintf(response, "-0x%x]", -imm);            if(load)            {                ccprintf(response, ", ");                printReg(response, _destRegIdx[0]);            }            return response.str();        }}};//This template provides the execute functions for a loaddef template LoadExecute {{        Fault %(class_name)s::execute(%(CPU_exec_context)s *xc,                Trace::InstRecord *traceData) const        {            Fault fault = NoFault;            Addr EA;            %(fp_enable_check)s;            %(op_decl)s;            %(op_rd)s;            %(ea_code)s;            DPRINTF(Sparc, "%s: The address is 0x%x\n", mnemonic, EA);            %(fault_check)s;            if(fault == NoFault)            {                %(EA_trunc)s                fault = xc->read(EA, (%(mem_acc_type)s%(mem_acc_size)s_t&)Mem, %(asi_val)s);            }            if(fault == NoFault)            {                %(code)s;            }            if(fault == NoFault)            {                    //Write the resulting state to the execution context                    %(op_wb)s;            }            return fault;        }}};def template LoadInitiateAcc {{        Fault %(class_name)s::initiateAcc(%(CPU_exec_context)s * xc,                Trace::InstRecord * traceData) const        {            Fault fault = NoFault;            Addr EA;            %(fp_enable_check)s;            %(op_decl)s;            %(op_rd)s;            %(ea_code)s;            DPRINTF(Sparc, "%s: The address is 0x%x\n", mnemonic, EA);            %(fault_check)s;            if(fault == NoFault)            {                %(EA_trunc)s                fault = xc->read(EA, (%(mem_acc_type)s%(mem_acc_size)s_t&)Mem, %(asi_val)s);            }            return fault;        }}};def template LoadCompleteAcc {{        Fault %(class_name)s::completeAcc(PacketPtr pkt, %(CPU_exec_context)s * xc,                Trace::InstRecord * traceData) const        {            Fault fault = NoFault;            %(op_decl)s;            %(op_rd)s;            Mem = pkt->get<typeof(Mem)>();            %(code)s;            if(fault == NoFault)            {                %(op_wb)s;            }            return fault;        }}};//This template provides the execute functions for a storedef template StoreExecute {{        Fault %(class_name)s::execute(%(CPU_exec_context)s *xc,                Trace::InstRecord *traceData) const        {            Fault fault = NoFault;            //This is to support the conditional store in cas instructions.            //It should be optomized out in all the others            bool storeCond = true;            Addr EA;            %(fp_enable_check)s;            %(op_decl)s;            %(op_rd)s;            %(ea_code)s;            DPRINTF(Sparc, "%s: The address is 0x%x\n", mnemonic, EA);            %(fault_check)s;            if(fault == NoFault)            {                %(code)s;            }            if(storeCond && fault == NoFault)            {                %(EA_trunc)s                fault = xc->write((%(mem_acc_type)s%(mem_acc_size)s_t)Mem,                        EA, %(asi_val)s, 0);            }            if(fault == NoFault)            {                    //Write the resulting state to the execution context                    %(op_wb)s;            }            return fault;        }}};def template StoreInitiateAcc {{        Fault %(class_name)s::initiateAcc(%(CPU_exec_context)s * xc,                Trace::InstRecord * traceData) const        {            Fault fault = NoFault;            bool storeCond = true;            Addr EA;            %(fp_enable_check)s;            %(op_decl)s;            %(op_rd)s;            %(ea_code)s;            DPRINTF(Sparc, "%s: The address is 0x%x\n", mnemonic, EA);            %(fault_check)s;            if(fault == NoFault)            {                %(code)s;            }            if(storeCond && fault == NoFault)            {                %(EA_trunc)s                fault = xc->write((%(mem_acc_type)s%(mem_acc_size)s_t)Mem,                        EA, %(asi_val)s, 0);            }            if(fault == NoFault)            {                    //Write the resulting state to the execution context                %(op_wb)s;            }            return fault;        }}};def template StoreCompleteAcc {{        Fault %(class_name)s::completeAcc(PacketPtr, %(CPU_exec_context)s * xc,                Trace::InstRecord * traceData) const        {            return NoFault;        }}};//This delcares the initiateAcc function in memory operationsdef template InitiateAccDeclare {{    Fault initiateAcc(%(CPU_exec_context)s *, Trace::InstRecord *) const;}};//This declares the completeAcc function in memory operationsdef template CompleteAccDeclare {{    Fault completeAcc(PacketPtr, %(CPU_exec_context)s *, Trace::InstRecord *) const;}};//Here are some code snippets which check for various fault conditionslet {{    LoadFuncs = [LoadExecute, LoadInitiateAcc, LoadCompleteAcc]    StoreFuncs = [StoreExecute, StoreInitiateAcc, StoreCompleteAcc]    # The LSB can be zero, since it's really the MSB in doubles and quads    # and we're dealing with doubles    BlockAlignmentFaultCheck = '''        if(RD & 0xe)            fault = new IllegalInstruction;        else if(EA & 0x3f)            fault = new MemAddressNotAligned;    '''    TwinAlignmentFaultCheck = '''        if(RD & 0x1)            fault = new IllegalInstruction;        else if(EA & 0xf)            fault = new MemAddressNotAligned;    '''    # XXX Need to take care of pstate.hpriv as well. The lower ASIs    # are split into ones that are available in priv and hpriv, and    # those that are only available in hpriv    AlternateASIPrivFaultCheck = '''        if(!bits(Pstate,2,2) && !bits(Hpstate,2,2) && !AsiIsUnPriv((ASI)EXT_ASI) ||                             !bits(Hpstate,2,2) && AsiIsHPriv((ASI)EXT_ASI))                fault = new PrivilegedAction;        else if(AsiIsAsIfUser((ASI)EXT_ASI) && !bits(Pstate,2,2))            fault = new PrivilegedAction;    '''    TruncateEA = '''#if !FULL_SYSTEM                EA = Pstate<3:> ? EA<31:0> : EA;#endif    '''}};//A simple function to generate the name of the macro op of a certain//instruction at a certain micropclet {{    def makeMicroName(name, microPc):            return name + "::" + name + "_" + str(microPc)}};//This function properly generates the execute functions for one of the//templates above. This is needed because in one case, ea computation,//fault checks and the actual code all occur in the same function,//and in the other they're distributed across two. Also note that for//execute functions, the name of the base class doesn't matter.let {{    def doSplitExecute(execute, name, Name, asi, opt_flags, microParam):        microParam["asi_val"] = asi;        iop = InstObjParams(name, Name, '', microParam, opt_flags)        (execf, initf, compf) = execute        return execf.subst(iop) + initf.subst(iop) + compf.subst(iop)    def doDualSplitExecute(code, postacc_code, eaRegCode, eaImmCode, execute,            faultCode, nameReg, nameImm, NameReg, NameImm, asi, opt_flags):        executeCode = ''        for (eaCode, name, Name) in (                (eaRegCode, nameReg, NameReg),                (eaImmCode, nameImm, NameImm)):            microParams = {"code": code, "postacc_code" : postacc_code,                "ea_code": eaCode, "fault_check": faultCode,                "EA_trunc" : TruncateEA}            executeCode += doSplitExecute(execute, name, Name,                    asi, opt_flags, microParams)        return executeCode}};

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?