summaryrefslogtreecommitdiff
path: root/arch/sparc/isa/formats/priv.isa
blob: f9fea01f26ed2a004ca8a52bcbfadfba88bb4d09 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
////////////////////////////////////////////////////////////////////
//
// Privilege mode instructions
//

output header {{
        /**
         * Base class for privelege mode operations.
         */
        class Priv : public SparcStaticInst
        {
          protected:
            // Constructor
            Priv(const char *mnem, ExtMachInst _machInst, OpClass __opClass) :
                SparcStaticInst(mnem, _machInst, __opClass)
            {
            }

            std::string generateDisassembly(Addr pc,
                    const SymbolTable *symtab) const;
        };

        /**
         * Base class for user mode "tick" access.
         */
        class PrivTick : public SparcStaticInst
        {
          protected:
            // Constructor
            PrivTick(const char *mnem, ExtMachInst _machInst,
                    OpClass __opClass) :
                SparcStaticInst(mnem, _machInst, __opClass)
            {
            }

            std::string generateDisassembly(Addr pc,
                    const SymbolTable *symtab) const;
        };

        /**
         * Base class for privelege mode operations with immediates.
         */
        class PrivImm : public Priv
        {
          protected:
            // Constructor
            PrivImm(const char *mnem, ExtMachInst _machInst,
                    OpClass __opClass) :
                Priv(mnem, _machInst, __opClass), imm(SIMM13)
            {
            }

            int32_t imm;
        };

        /**
         * Base class for user mode "tick" access with immediates.
         */
        class PrivTickImm : public PrivTick
        {
          protected:
            // Constructor
            PrivTickImm(const char *mnem, ExtMachInst _machInst,
                    OpClass __opClass) :
                PrivTick(mnem, _machInst, __opClass), imm(SIMM13)
            {
            }

            int32_t imm;
        };
}};

output decoder {{
        std::string Priv::generateDisassembly(Addr pc,
                const SymbolTable *symtab) const
        {
                return "Privileged Instruction";
        }

        std::string PrivTick::generateDisassembly(Addr pc,
                const SymbolTable *symtab) const
        {
                return "Regular access to Tick";
        }
}};

def template PrivExecute {{
    Fault %(class_name)s::execute(%(CPU_exec_context)s *xc,
            Trace::InstRecord *traceData) const
    {
        %(op_decl)s;
        %(op_rd)s;

        //If the processor isn't in privileged mode, fault out right away
        if(%(check)s)
            return new PrivilegedAction;

        %(code)s;
        %(op_wb)s;
        return NoFault;
    }
}};

let {{
    def doPrivFormat(code, checkCode, name, Name, opt_flags):
        (usesImm, code, immCode,
         rString, iString) = splitOutImm(code)
        iop = InstObjParams(name, Name, 'Priv', code,
                opt_flags, ("check", checkCode))
        header_output = BasicDeclare.subst(iop)
        decoder_output = BasicConstructor.subst(iop)
        exec_output = PrivExecute.subst(iop)
        if usesImm:
            imm_iop = InstObjParams(name, Name + 'Imm', 'PrivImm',
                    immCode, opt_flags, ("check", checkCode))
            header_output += BasicDeclare.subst(imm_iop)
            decoder_output += BasicConstructor.subst(imm_iop)
            exec_output += PrivExecute.subst(imm_iop)
            decode_block = ROrImmDecode.subst(iop)
        else:
            decode_block = BasicDecode.subst(iop)
        return (header_output, decoder_output, exec_output, decode_block)
}};

// Primary format for integer operate instructions:
def format Priv(code, *opt_flags) {{
        checkCode = "(!PstatePriv)"
        (header_output, decoder_output,
         exec_output, decode_block) = doPrivFormat(code,
             checkCode, name, Name, opt_flags)
}};

// Primary format for integer operate instructions:
def format PrivTick(code, *opt_flags) {{
        checkCode = "(!PstatePriv && TickNpt)"
        (header_output, decoder_output,
         exec_output, decode_block) = doPrivFormat(code,
             checkCode, name, Name, opt_flags)
}};