summaryrefslogtreecommitdiff
path: root/src/arch/sparc/isa/formats/mem.isa
blob: b046bdd1c86f7da145724c4bcea915bd3053edf5 (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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
////////////////////////////////////////////////////////////////////
//
// Mem instructions
//

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;

            int32_t imm;
        };
}};

output decoder {{
        std::string Mem::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, "[ ");
            printReg(response, _srcRegIdx[!save ? 0 : 1]);
            ccprintf(response, " + ");
            printReg(response, _srcRegIdx[!save ? 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, "[ ");
            printReg(response, _srcRegIdx[!save ? 0 : 1]);
            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();
        }

}};

def template LoadExecute {{
        Fault %(class_name)s::execute(%(CPU_exec_context)s *xc,
                Trace::InstRecord *traceData) const
        {
            Fault fault = NoFault;
            Addr EA;
            %(op_decl)s;
            %(op_rd)s;
            %(priv_check)s;
            %(ea_code)s;
            DPRINTF(Sparc, "The address is 0x%x\n", EA);
            xc->read(EA, (uint%(mem_acc_size)s_t&)Mem, 0);
            %(code)s;

            if(fault == NoFault)
            {
                //Write the resulting state to the execution context
                %(op_wb)s;
            }

            return fault;
        }
}};

def template StoreExecute {{
        Fault %(class_name)s::execute(%(CPU_exec_context)s *xc,
                Trace::InstRecord *traceData) const
        {
            Fault fault = NoFault;
            uint64_t write_result = 0;
            Addr EA;
            %(op_decl)s;
            %(op_rd)s;
            %(priv_check)s;
            %(ea_code)s;
            DPRINTF(Sparc, "The address is 0x%x\n", EA);
            %(code)s;

            if(fault == NoFault)
            {
                xc->write((uint%(mem_acc_size)s_t)Mem, EA, 0, &write_result);
                //Write the resulting state to the execution context
                %(op_wb)s;
            }

            return fault;
        }
}};

def template LoadStoreExecute {{
        Fault %(class_name)s::execute(%(CPU_exec_context)s *xc,
                Trace::InstRecord *traceData) const
        {
            Fault fault = NoFault;
            uint64_t write_result = 0;
            Addr EA;
            %(op_decl)s;
            %(op_rd)s;
            %(priv_check)s;
            %(ea_code)s;
            DPRINTF(Sparc, "The address is 0x%x\n", EA);
            xc->read(EA, (uint%(mem_acc_size)s_t&)Mem, 0);
            %(code)s;

            if(fault == NoFault)
            {
                xc->write((uint%(mem_acc_size)s_t)Mem, EA, 0, &write_result);
                //Write the resulting state to the execution context
                %(op_wb)s;
            }

            return fault;
        }
}};

let {{
    # 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
    privilegedString = '''if(bits(Pstate,2,2) == 0 && (EXT_ASI & 0x80) == 0)
                return new PrivilegedAction;
            if(AsiIsAsIfUser(EXT_ASI) && !bits(Pstate,2,2))
                return new PrivilegedAction;'''

    def doMemFormat(code, execute, priv, name, Name, opt_flags):
        addrCalcReg = 'EA = Rs1 + Rs2;'
        addrCalcImm = 'EA = Rs1 + imm;'
        iop = InstObjParams(name, Name, 'Mem', code,
                opt_flags, {"ea_code": addrCalcReg,
                "priv_check": priv})
        iop_imm = InstObjParams(name, Name + 'Imm', 'MemImm', code,
                opt_flags, {"ea_code": addrCalcImm,
                "priv_check": priv})
        header_output = BasicDeclare.subst(iop) + BasicDeclare.subst(iop_imm)
        decoder_output = BasicConstructor.subst(iop) + BasicConstructor.subst(iop_imm)
        decode_block = ROrImmDecode.subst(iop)
        exec_output = execute.subst(iop) + execute.subst(iop_imm)
        return (header_output, decoder_output, exec_output, decode_block)
}};

def format LoadAlt(code, *opt_flags) {{
        (header_output,
         decoder_output,
         exec_output,
         decode_block) = doMemFormat(code, LoadExecute,
            privelegedString, name, Name, opt_flags)
}};

def format StoreAlt(code, *opt_flags) {{
        (header_output,
         decoder_output,
         exec_output,
         decode_block) = doMemFormat(code, StoreExecute,
            privilegedString, name, Name, opt_flags)
}};

def format Load(code, *opt_flags) {{
        (header_output,
         decoder_output,
         exec_output,
         decode_block) = doMemFormat(code,
             LoadExecute, '', name, Name, opt_flags)
}};

def format Store(code, *opt_flags) {{
        (header_output,
         decoder_output,
         exec_output,
         decode_block) = doMemFormat(code,
             StoreExecute, '', name, Name, opt_flags)
}};

def format LoadStore(code, *opt_flags) {{
        (header_output,
         decoder_output,
         exec_output,
         decode_block) = doMemFormat(code,
             LoadStoreExecute, '', name, Name, opt_flags)
}};