priv.isa revision 2482
12SN/A////////////////////////////////////////////////////////////////////
21762SN/A//
32SN/A// Privilege mode instructions
42SN/A//
52SN/A
62SN/Aoutput header {{
72SN/A        /**
82SN/A         * Base class for privelege mode operations.
92SN/A         */
102SN/A        class Priv : public SparcStaticInst
112SN/A        {
122SN/A          protected:
132SN/A            // Constructor
142SN/A            Priv(const char *mnem, ExtMachInst _machInst, OpClass __opClass) :
152SN/A                SparcStaticInst(mnem, _machInst, __opClass)
162SN/A            {
172SN/A            }
182SN/A
192SN/A            std::string generateDisassembly(Addr pc,
202SN/A                    const SymbolTable *symtab) const;
212SN/A        };
222SN/A
232SN/A        /**
242SN/A         * Base class for user mode "tick" access.
252SN/A         */
262SN/A        class PrivTick : public SparcStaticInst
272665Ssaidi@eecs.umich.edu        {
282665Ssaidi@eecs.umich.edu          protected:
292665Ssaidi@eecs.umich.edu            // Constructor
302665Ssaidi@eecs.umich.edu            PrivTick(const char *mnem, ExtMachInst _machInst,
312665Ssaidi@eecs.umich.edu                    OpClass __opClass) :
322SN/A                SparcStaticInst(mnem, _machInst, __opClass)
332SN/A            {
342SN/A            }
352SN/A
363506Ssaidi@eecs.umich.edu            std::string generateDisassembly(Addr pc,
373506Ssaidi@eecs.umich.edu                    const SymbolTable *symtab) const;
382SN/A        };
392973Sgblack@eecs.umich.edu
4056SN/A        /**
411717SN/A         * Base class for privelege mode operations with immediates.
422518SN/A         */
4356SN/A        class PrivImm : public Priv
442518SN/A        {
452518SN/A          protected:
462SN/A            // Constructor
473065Sgblack@eecs.umich.edu            PrivImm(const char *mnem, ExtMachInst _machInst,
483065Sgblack@eecs.umich.edu                    OpClass __opClass) :
493506Ssaidi@eecs.umich.edu                Priv(mnem, _machInst, __opClass), imm(SIMM13)
503065Sgblack@eecs.umich.edu            {
512SN/A            }
522973Sgblack@eecs.umich.edu
532SN/A            uint32_t imm;
543506Ssaidi@eecs.umich.edu        };
553506Ssaidi@eecs.umich.edu
563506Ssaidi@eecs.umich.edu        /**
573506Ssaidi@eecs.umich.edu         * Base class for user mode "tick" access with immediates.
582SN/A         */
592SN/A        class PrivTickImm : public PrivTick
602SN/A        {
612SN/A          protected:
622SN/A            // Constructor
632SN/A            PrivTickImm(const char *mnem, ExtMachInst _machInst,
642SN/A                    OpClass __opClass) :
652SN/A                PrivTick(mnem, _machInst, __opClass), imm(SIMM13)
662SN/A            {
672973Sgblack@eecs.umich.edu            }
682973Sgblack@eecs.umich.edu
693065Sgblack@eecs.umich.edu            uint32_t imm;
703506Ssaidi@eecs.umich.edu        };
713380Sgblack@eecs.umich.edu}};
723380Sgblack@eecs.umich.edu
733380Sgblack@eecs.umich.eduoutput decoder {{
743380Sgblack@eecs.umich.edu        std::string Priv::generateDisassembly(Addr pc,
753380Sgblack@eecs.umich.edu                const SymbolTable *symtab) const
763380Sgblack@eecs.umich.edu        {
773380Sgblack@eecs.umich.edu                return "Privileged Instruction";
783380Sgblack@eecs.umich.edu        }
793380Sgblack@eecs.umich.edu
803380Sgblack@eecs.umich.edu        std::string PrivTick::generateDisassembly(Addr pc,
813380Sgblack@eecs.umich.edu                const SymbolTable *symtab) const
823380Sgblack@eecs.umich.edu        {
833380Sgblack@eecs.umich.edu                return "Regular access to Tick";
843380Sgblack@eecs.umich.edu        }
853065Sgblack@eecs.umich.edu}};
863380Sgblack@eecs.umich.edu
873380Sgblack@eecs.umich.edudef template PrivExecute {{
883059Sgblack@eecs.umich.edu    Fault %(class_name)s::execute(%(CPU_exec_context)s *xc,
893380Sgblack@eecs.umich.edu            Trace::InstRecord *traceData) const
903059Sgblack@eecs.umich.edu    {
913380Sgblack@eecs.umich.edu        %(op_decl)s;
923380Sgblack@eecs.umich.edu        %(op_rd)s;
933059Sgblack@eecs.umich.edu
943380Sgblack@eecs.umich.edu        //If the processor isn't in privileged mode, fault out right away
953380Sgblack@eecs.umich.edu        if(!PstatePriv)
963380Sgblack@eecs.umich.edu            return new PrivilegedOpcode
973380Sgblack@eecs.umich.edu
983380Sgblack@eecs.umich.edu        %(code)s;
993380Sgblack@eecs.umich.edu        %(op_wb)s;
1003380Sgblack@eecs.umich.edu    }
1013380Sgblack@eecs.umich.edu}};
1023380Sgblack@eecs.umich.edu
1033380Sgblack@eecs.umich.edudef template PrivTickExecute {{
1043380Sgblack@eecs.umich.edu    Fault %(class_name)s::execute(%(CPU_exec_context)s *xc,
1053380Sgblack@eecs.umich.edu            Trace::InstRecord *traceData) const
1063380Sgblack@eecs.umich.edu    {
1073380Sgblack@eecs.umich.edu        %(op_decl)s;
1083059Sgblack@eecs.umich.edu        %(op_rd)s;
1093380Sgblack@eecs.umich.edu
1103380Sgblack@eecs.umich.edu        //If the processor isn't in privileged mode, fault out right away
1113380Sgblack@eecs.umich.edu        if(!PstatePriv && TickNpt)
1123380Sgblack@eecs.umich.edu            return new PrivilegedAction
1133380Sgblack@eecs.umich.edu
1143380Sgblack@eecs.umich.edu        %(code)s;
1153380Sgblack@eecs.umich.edu        %(op_wb)s;
1163380Sgblack@eecs.umich.edu    }
1173059Sgblack@eecs.umich.edu}};
1183059Sgblack@eecs.umich.edu
1193380Sgblack@eecs.umich.edu// Primary format for integer operate instructions:
1203380Sgblack@eecs.umich.edudef format Priv(code, *opt_flags) {{
1213380Sgblack@eecs.umich.edu        uses_imm = (code.find('Rs2_or_imm13') != -1)
1223380Sgblack@eecs.umich.edu        if uses_imm:
1233380Sgblack@eecs.umich.edu            orig_code = code
1243380Sgblack@eecs.umich.edu            code = re.sub(r'Rs2_or_imm13', 'Rs2', orig_code)
1253380Sgblack@eecs.umich.edu            imm_code = re.sub(r'Rs2_or_imm13(\.\w+)?', 'imm', orig_code)
1263380Sgblack@eecs.umich.edu        cblk = CodeBlock(code)
1273380Sgblack@eecs.umich.edu        iop = InstObjParams(name, Name, 'Priv', cblk, opt_flags)
1283380Sgblack@eecs.umich.edu        header_output = BasicDeclare.subst(iop)
1293380Sgblack@eecs.umich.edu        decoder_output = BasicConstructor.subst(iop)
1303059Sgblack@eecs.umich.edu        exec_output = PrivExecute.subst(iop)
1313065Sgblack@eecs.umich.edu        if uses_imm:
1323506Ssaidi@eecs.umich.edu            imm_cblk = CodeBlock(imm_code)
1332973Sgblack@eecs.umich.edu            imm_iop = InstObjParams(name, Name + 'Imm', 'PrivImm', imm_cblk,
1342973Sgblack@eecs.umich.edu                                    opt_flags)
1351968SN/A            header_output += BasicDeclare.subst(imm_iop)
1363064Sgblack@eecs.umich.edu            decoder_output += BasicConstructor.subst(imm_iop)
1371968SN/A            exec_output += PrivExecute.subst(imm_iop)
1381968SN/A            decode_block = ROrImmDecode.subst(iop)
1391968SN/A        else:
1401968SN/A            decode_block = BasicDecode.subst(iop)
1411967SN/A}};
1421967SN/A
1431967SN/A// Primary format for integer operate instructions:
1441967SN/Adef format PrivTick(code, *opt_flags) {{
1451967SN/A        uses_imm = (code.find('Rs2_or_imm13') != -1)
1461967SN/A        if uses_imm:
1471967SN/A            orig_code = code
1481967SN/A            code = re.sub(r'Rs2_or_imm13', 'Rs2', orig_code)
1491967SN/A            imm_code = re.sub(r'Rs2_or_imm13(\.\w+)?', 'imm', orig_code)
1501967SN/A        cblk = CodeBlock(code)
1511904SN/A        iop = InstObjParams(name, Name, 'PrivTick', cblk, opt_flags)
1521904SN/A        header_output = BasicDeclare.subst(iop)
1531904SN/A        decoder_output = BasicConstructor.subst(iop)
1541904SN/A        exec_output = PrivTickExecute.subst(iop)
155452SN/A        if uses_imm:
1563064Sgblack@eecs.umich.edu            imm_cblk = CodeBlock(imm_code)
1572SN/A            imm_iop = InstObjParams(name, Name + 'Imm', 'PrivTickImm', imm_cblk,
1581904SN/A                                    opt_flags)
1591904SN/A            header_output += BasicDeclare.subst(imm_iop)
1602SN/A            decoder_output += BasicConstructor.subst(imm_iop)
1611904SN/A            exec_output += PrivTickExecute.subst(imm_iop)
1623064Sgblack@eecs.umich.edu            decode_block = Rb2OrImmDecode.subst(iop)
1632SN/A        else:
1642SN/A            decode_block = BasicDecode.subst(iop)
1651904SN/A}};
1661904SN/A