priv.isa revision 2632
110259SAndrew.Bardsley@arm.com// Copyright (c) 2006 The Regents of The University of Michigan
210259SAndrew.Bardsley@arm.com// All rights reserved.
310259SAndrew.Bardsley@arm.com//
410259SAndrew.Bardsley@arm.com// Redistribution and use in source and binary forms, with or without
510259SAndrew.Bardsley@arm.com// modification, are permitted provided that the following conditions are
610259SAndrew.Bardsley@arm.com// met: redistributions of source code must retain the above copyright
710259SAndrew.Bardsley@arm.com// notice, this list of conditions and the following disclaimer;
810259SAndrew.Bardsley@arm.com// redistributions in binary form must reproduce the above copyright
910259SAndrew.Bardsley@arm.com// notice, this list of conditions and the following disclaimer in the
1010259SAndrew.Bardsley@arm.com// documentation and/or other materials provided with the distribution;
1110259SAndrew.Bardsley@arm.com// neither the name of the copyright holders nor the names of its
1210259SAndrew.Bardsley@arm.com// contributors may be used to endorse or promote products derived from
1310259SAndrew.Bardsley@arm.com// this software without specific prior written permission.
1410259SAndrew.Bardsley@arm.com//
1510259SAndrew.Bardsley@arm.com// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1610259SAndrew.Bardsley@arm.com// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1710259SAndrew.Bardsley@arm.com// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1810259SAndrew.Bardsley@arm.com// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1910259SAndrew.Bardsley@arm.com// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2010259SAndrew.Bardsley@arm.com// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2110259SAndrew.Bardsley@arm.com// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2210259SAndrew.Bardsley@arm.com// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2310259SAndrew.Bardsley@arm.com// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2410259SAndrew.Bardsley@arm.com// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2510259SAndrew.Bardsley@arm.com// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2610259SAndrew.Bardsley@arm.com//
2710259SAndrew.Bardsley@arm.com// Authors: Ali Saidi
2810259SAndrew.Bardsley@arm.com//          Gabe Black
2910259SAndrew.Bardsley@arm.com//          Steve Reinhardt
3010259SAndrew.Bardsley@arm.com
3110259SAndrew.Bardsley@arm.com////////////////////////////////////////////////////////////////////
3210259SAndrew.Bardsley@arm.com//
3310259SAndrew.Bardsley@arm.com// Privilege mode instructions
3410259SAndrew.Bardsley@arm.com//
3510259SAndrew.Bardsley@arm.com
3610259SAndrew.Bardsley@arm.comoutput header {{
3710259SAndrew.Bardsley@arm.com        /**
3810259SAndrew.Bardsley@arm.com         * Base class for privelege mode operations.
3910259SAndrew.Bardsley@arm.com         */
4010259SAndrew.Bardsley@arm.com        class Priv : public SparcStaticInst
4110259SAndrew.Bardsley@arm.com        {
4210259SAndrew.Bardsley@arm.com          protected:
4310259SAndrew.Bardsley@arm.com            // Constructor
4410259SAndrew.Bardsley@arm.com            Priv(const char *mnem, ExtMachInst _machInst, OpClass __opClass) :
4510259SAndrew.Bardsley@arm.com                SparcStaticInst(mnem, _machInst, __opClass)
4610259SAndrew.Bardsley@arm.com            {
4710259SAndrew.Bardsley@arm.com            }
4810259SAndrew.Bardsley@arm.com
4910259SAndrew.Bardsley@arm.com            std::string generateDisassembly(Addr pc,
5010259SAndrew.Bardsley@arm.com                    const SymbolTable *symtab) const;
5110259SAndrew.Bardsley@arm.com        };
5210259SAndrew.Bardsley@arm.com
5310259SAndrew.Bardsley@arm.com        /**
5410259SAndrew.Bardsley@arm.com         * Base class for user mode "tick" access.
5510259SAndrew.Bardsley@arm.com         */
5610259SAndrew.Bardsley@arm.com        class PrivTick : public SparcStaticInst
5710259SAndrew.Bardsley@arm.com        {
5810259SAndrew.Bardsley@arm.com          protected:
5910259SAndrew.Bardsley@arm.com            // Constructor
6010259SAndrew.Bardsley@arm.com            PrivTick(const char *mnem, ExtMachInst _machInst,
6110259SAndrew.Bardsley@arm.com                    OpClass __opClass) :
6210259SAndrew.Bardsley@arm.com                SparcStaticInst(mnem, _machInst, __opClass)
6310259SAndrew.Bardsley@arm.com            {
6410259SAndrew.Bardsley@arm.com            }
6510259SAndrew.Bardsley@arm.com
6610259SAndrew.Bardsley@arm.com            std::string generateDisassembly(Addr pc,
6710259SAndrew.Bardsley@arm.com                    const SymbolTable *symtab) const;
6810259SAndrew.Bardsley@arm.com        };
6910259SAndrew.Bardsley@arm.com
7010259SAndrew.Bardsley@arm.com        /**
7110259SAndrew.Bardsley@arm.com         * Base class for privelege mode operations with immediates.
7210259SAndrew.Bardsley@arm.com         */
7310259SAndrew.Bardsley@arm.com        class PrivImm : public Priv
7410259SAndrew.Bardsley@arm.com        {
7510259SAndrew.Bardsley@arm.com          protected:
7610259SAndrew.Bardsley@arm.com            // Constructor
7710259SAndrew.Bardsley@arm.com            PrivImm(const char *mnem, ExtMachInst _machInst,
7810259SAndrew.Bardsley@arm.com                    OpClass __opClass) :
7910259SAndrew.Bardsley@arm.com                Priv(mnem, _machInst, __opClass), imm(SIMM13)
8010259SAndrew.Bardsley@arm.com            {
8110259SAndrew.Bardsley@arm.com            }
8210259SAndrew.Bardsley@arm.com
8310259SAndrew.Bardsley@arm.com            int32_t imm;
8410259SAndrew.Bardsley@arm.com        };
8510259SAndrew.Bardsley@arm.com
8610259SAndrew.Bardsley@arm.com        /**
8710259SAndrew.Bardsley@arm.com         * Base class for user mode "tick" access with immediates.
8810259SAndrew.Bardsley@arm.com         */
8910259SAndrew.Bardsley@arm.com        class PrivTickImm : public PrivTick
9010259SAndrew.Bardsley@arm.com        {
9110259SAndrew.Bardsley@arm.com          protected:
9210259SAndrew.Bardsley@arm.com            // Constructor
9310259SAndrew.Bardsley@arm.com            PrivTickImm(const char *mnem, ExtMachInst _machInst,
9410259SAndrew.Bardsley@arm.com                    OpClass __opClass) :
9510259SAndrew.Bardsley@arm.com                PrivTick(mnem, _machInst, __opClass), imm(SIMM13)
9610259SAndrew.Bardsley@arm.com            {
9710259SAndrew.Bardsley@arm.com            }
9810259SAndrew.Bardsley@arm.com
9910259SAndrew.Bardsley@arm.com            int32_t imm;
10010259SAndrew.Bardsley@arm.com        };
10110259SAndrew.Bardsley@arm.com}};
10210259SAndrew.Bardsley@arm.com
10310259SAndrew.Bardsley@arm.comoutput decoder {{
10410259SAndrew.Bardsley@arm.com        std::string Priv::generateDisassembly(Addr pc,
10510259SAndrew.Bardsley@arm.com                const SymbolTable *symtab) const
10610259SAndrew.Bardsley@arm.com        {
10710259SAndrew.Bardsley@arm.com                return "Privileged Instruction";
10810259SAndrew.Bardsley@arm.com        }
10910259SAndrew.Bardsley@arm.com
11010259SAndrew.Bardsley@arm.com        std::string PrivTick::generateDisassembly(Addr pc,
11110259SAndrew.Bardsley@arm.com                const SymbolTable *symtab) const
11210259SAndrew.Bardsley@arm.com        {
11310259SAndrew.Bardsley@arm.com                return "Regular access to Tick";
11410259SAndrew.Bardsley@arm.com        }
11510259SAndrew.Bardsley@arm.com}};
11610259SAndrew.Bardsley@arm.com
11710259SAndrew.Bardsley@arm.comdef template PrivExecute {{
11810259SAndrew.Bardsley@arm.com    Fault %(class_name)s::execute(%(CPU_exec_context)s *xc,
11910259SAndrew.Bardsley@arm.com            Trace::InstRecord *traceData) const
12010259SAndrew.Bardsley@arm.com    {
12110259SAndrew.Bardsley@arm.com        %(op_decl)s;
12210259SAndrew.Bardsley@arm.com        %(op_rd)s;
12310259SAndrew.Bardsley@arm.com
12410259SAndrew.Bardsley@arm.com        //If the processor isn't in privileged mode, fault out right away
12510259SAndrew.Bardsley@arm.com        if(%(check)s)
12610259SAndrew.Bardsley@arm.com            return new PrivilegedAction;
12710259SAndrew.Bardsley@arm.com
12810259SAndrew.Bardsley@arm.com        %(code)s;
12910259SAndrew.Bardsley@arm.com        %(op_wb)s;
13010259SAndrew.Bardsley@arm.com        return NoFault;
13110259SAndrew.Bardsley@arm.com    }
13210259SAndrew.Bardsley@arm.com}};
13310259SAndrew.Bardsley@arm.com
13410259SAndrew.Bardsley@arm.comlet {{
13510259SAndrew.Bardsley@arm.com    def doPrivFormat(code, checkCode, name, Name, opt_flags):
13610259SAndrew.Bardsley@arm.com        (usesImm, code, immCode,
13710259SAndrew.Bardsley@arm.com         rString, iString) = splitOutImm(code)
13810259SAndrew.Bardsley@arm.com        iop = InstObjParams(name, Name, 'Priv', code,
13910259SAndrew.Bardsley@arm.com                opt_flags, ("check", checkCode))
14010259SAndrew.Bardsley@arm.com        header_output = BasicDeclare.subst(iop)
14110259SAndrew.Bardsley@arm.com        decoder_output = BasicConstructor.subst(iop)
14210259SAndrew.Bardsley@arm.com        exec_output = PrivExecute.subst(iop)
14310259SAndrew.Bardsley@arm.com        if usesImm:
14410259SAndrew.Bardsley@arm.com            imm_iop = InstObjParams(name, Name + 'Imm', 'PrivImm',
14510259SAndrew.Bardsley@arm.com                    immCode, opt_flags, ("check", checkCode))
14610259SAndrew.Bardsley@arm.com            header_output += BasicDeclare.subst(imm_iop)
14710259SAndrew.Bardsley@arm.com            decoder_output += BasicConstructor.subst(imm_iop)
14810259SAndrew.Bardsley@arm.com            exec_output += PrivExecute.subst(imm_iop)
14910259SAndrew.Bardsley@arm.com            decode_block = ROrImmDecode.subst(iop)
15010259SAndrew.Bardsley@arm.com        else:
15110259SAndrew.Bardsley@arm.com            decode_block = BasicDecode.subst(iop)
15210259SAndrew.Bardsley@arm.com        return (header_output, decoder_output, exec_output, decode_block)
15310259SAndrew.Bardsley@arm.com}};
15410259SAndrew.Bardsley@arm.com
15510259SAndrew.Bardsley@arm.com// Primary format for integer operate instructions:
15610259SAndrew.Bardsley@arm.comdef format Priv(code, *opt_flags) {{
15710259SAndrew.Bardsley@arm.com        checkCode = "(!PstatePriv)"
15810259SAndrew.Bardsley@arm.com        (header_output, decoder_output,
15910259SAndrew.Bardsley@arm.com         exec_output, decode_block) = doPrivFormat(code,
16010259SAndrew.Bardsley@arm.com             checkCode, name, Name, opt_flags)
16110259SAndrew.Bardsley@arm.com}};
16210259SAndrew.Bardsley@arm.com
16310259SAndrew.Bardsley@arm.com// Primary format for integer operate instructions:
16410259SAndrew.Bardsley@arm.comdef format PrivTick(code, *opt_flags) {{
16510259SAndrew.Bardsley@arm.com        checkCode = "(!PstatePriv && TickNpt)"
16610259SAndrew.Bardsley@arm.com        (header_output, decoder_output,
16710259SAndrew.Bardsley@arm.com         exec_output, decode_block) = doPrivFormat(code,
16810259SAndrew.Bardsley@arm.com             checkCode, name, Name, opt_flags)
16910259SAndrew.Bardsley@arm.com}};
17010259SAndrew.Bardsley@arm.com