3 // Copyright (c) 2007 MIPS Technologies, Inc.
4 // All rights reserved.
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are
8 // met: redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer;
10 // redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution;
13 // neither the name of the copyright holders nor the names of its
14 // contributors may be used to endorse or promote products derived from
15 // this software without specific prior written permission.
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 // Authors: Korey Sewell
31 ////////////////////////////////////////////////////////////////////
33 // Integer operate instructions
39 * Base class for integer operations.
41 class IntOp : public MipsStaticInst
46 IntOp(const char *mnem, MachInst _machInst, OpClass __opClass) :
47 MipsStaticInst(mnem, _machInst, __opClass)
51 std::string generateDisassembly(
52 Addr pc, const SymbolTable *symtab) const override;
56 class HiLoOp: public IntOp
61 HiLoOp(const char *mnem, MachInst _machInst, OpClass __opClass) :
62 IntOp(mnem, _machInst, __opClass)
66 std::string generateDisassembly(
67 Addr pc, const SymbolTable *symtab) const override;
70 class HiLoRsSelOp: public HiLoOp
75 HiLoRsSelOp(const char *mnem, MachInst _machInst, OpClass __opClass) :
76 HiLoOp(mnem, _machInst, __opClass)
80 std::string generateDisassembly(
81 Addr pc, const SymbolTable *symtab) const override;
84 class HiLoRdSelOp: public HiLoOp
89 HiLoRdSelOp(const char *mnem, MachInst _machInst, OpClass __opClass) :
90 HiLoOp(mnem, _machInst, __opClass)
94 std::string generateDisassembly(
95 Addr pc, const SymbolTable *symtab) const override;
98 class HiLoRdSelValOp: public HiLoOp
103 HiLoRdSelValOp(const char *mnem, MachInst _machInst, OpClass __opClass) :
104 HiLoOp(mnem, _machInst, __opClass)
108 std::string generateDisassembly(
109 Addr pc, const SymbolTable *symtab) const override;
112 class IntImmOp : public MipsStaticInst
121 IntImmOp(const char *mnem, MachInst _machInst, OpClass __opClass) :
122 MipsStaticInst(mnem, _machInst, __opClass),imm(INTIMM),
123 sextImm(INTIMM),zextImm(0x0000FFFF & INTIMM)
125 //If Bit 15 is 1 then Sign Extend
126 int32_t temp = sextImm & 0x00008000;
127 if (temp > 0 && strcmp(mnemonic,"lui") != 0) {
128 sextImm |= 0xFFFF0000;
132 std::string generateDisassembly(
133 Addr pc, const SymbolTable *symtab) const override;
138 // HiLo instruction class execute method template.
139 def template HiLoExecute {{
140 Fault %(class_name)s::execute(
141 ExecContext *xc, Trace::InstRecord *traceData) const
143 Fault fault = NoFault;
158 // HiLoRsSel instruction class execute method template.
159 def template HiLoRsSelExecute {{
160 Fault %(class_name)s::execute(
161 ExecContext *xc, Trace::InstRecord *traceData) const
163 Fault fault = NoFault;
167 if( ACSRC > 0 && !isDspEnabled(xc) )
169 fault = std::make_shared<DspStateDisabledFault>();
185 // HiLoRdSel instruction class execute method template.
186 def template HiLoRdSelExecute {{
187 Fault %(class_name)s::execute(
188 ExecContext *xc, Trace::InstRecord *traceData) const
190 Fault fault = NoFault;
194 if( ACDST > 0 && !isDspEnabled(xc) )
196 fault = std::make_shared<DspStateDisabledFault>();
212 //Outputs to decoder.cc
214 std::string IntOp::generateDisassembly(Addr pc, const SymbolTable *symtab) const
216 std::stringstream ss;
218 ccprintf(ss, "%-10s ", mnemonic);
220 // just print the first dest... if there's a second one,
221 // it's generally implicit
222 if (_numDestRegs > 0) {
223 printReg(ss, _destRegIdx[0]);
227 // just print the first two source regs... if there's
228 // a third one, it's a read-modify-write dest (Rc),
230 if (_numSrcRegs > 0) {
231 printReg(ss, _srcRegIdx[0]);
234 if (_numSrcRegs > 1) {
236 printReg(ss, _srcRegIdx[1]);
242 std::string HiLoOp::generateDisassembly(Addr pc, const SymbolTable *symtab) const
244 std::stringstream ss;
246 ccprintf(ss, "%-10s ", mnemonic);
248 //Destination Registers are implicit for HI/LO ops
249 if (_numSrcRegs > 0) {
250 printReg(ss, _srcRegIdx[0]);
253 if (_numSrcRegs > 1) {
255 printReg(ss, _srcRegIdx[1]);
261 std::string HiLoRsSelOp::generateDisassembly(Addr pc, const SymbolTable *symtab) const
263 std::stringstream ss;
265 ccprintf(ss, "%-10s ", mnemonic);
267 if (_numDestRegs > 0 && _destRegIdx[0].index() < 32) {
268 printReg(ss, _destRegIdx[0]);
269 } else if (_numSrcRegs > 0 && _srcRegIdx[0].index() < 32) {
270 printReg(ss, _srcRegIdx[0]);
276 std::string HiLoRdSelOp::generateDisassembly(Addr pc, const SymbolTable *symtab) const
278 std::stringstream ss;
280 ccprintf(ss, "%-10s ", mnemonic);
282 if (_numDestRegs > 0 && _destRegIdx[0].index() < 32) {
283 printReg(ss, _destRegIdx[0]);
284 } else if (_numSrcRegs > 0 && _srcRegIdx[0].index() < 32) {
285 printReg(ss, _srcRegIdx[0]);
291 std::string HiLoRdSelValOp::generateDisassembly(Addr pc, const SymbolTable *symtab) const
293 std::stringstream ss;
295 ccprintf(ss, "%-10s ", mnemonic);
297 if (_numDestRegs > 0 && _destRegIdx[0].index() < 32) {
298 printReg(ss, _destRegIdx[0]);
299 } else if (_numSrcRegs > 0 && _srcRegIdx[0].index() < 32) {
300 printReg(ss, _srcRegIdx[0]);
306 std::string IntImmOp::generateDisassembly(Addr pc, const SymbolTable *symtab) const
308 std::stringstream ss;
310 ccprintf(ss, "%-10s ", mnemonic);
312 if (_numDestRegs > 0) {
313 printReg(ss, _destRegIdx[0]);
318 if (_numSrcRegs > 0) {
319 printReg(ss, _srcRegIdx[0]);
323 if(strcmp(mnemonic,"lui") == 0)
324 ccprintf(ss, "0x%x ", sextImm);
333 def format IntOp(code, *opt_flags) {{
334 iop = InstObjParams(name, Name, 'IntOp', code, opt_flags)
335 header_output = BasicDeclare.subst(iop)
336 decoder_output = BasicConstructor.subst(iop)
337 decode_block = RegNopCheckDecode.subst(iop)
338 exec_output = BasicExecute.subst(iop)
341 def format IntImmOp(code, *opt_flags) {{
342 iop = InstObjParams(name, Name, 'IntImmOp', code, opt_flags)
343 header_output = BasicDeclare.subst(iop)
344 decoder_output = BasicConstructor.subst(iop)
345 decode_block = ImmNopCheckDecode.subst(iop)
346 exec_output = BasicExecute.subst(iop)
349 def format HiLoRsSelOp(code, *opt_flags) {{
350 iop = InstObjParams(name, Name, 'HiLoRsSelOp', code, opt_flags)
351 header_output = BasicDeclare.subst(iop)
352 decoder_output = BasicConstructor.subst(iop)
353 decode_block = BasicDecode.subst(iop)
354 exec_output = HiLoRsSelExecute.subst(iop)
357 def format HiLoRdSelOp(code, *opt_flags) {{
358 iop = InstObjParams(name, Name, 'HiLoRdSelOp', code, opt_flags)
359 header_output = BasicDeclare.subst(iop)
360 decoder_output = BasicConstructor.subst(iop)
361 decode_block = BasicDecode.subst(iop)
362 exec_output = HiLoRdSelExecute.subst(iop)
365 def format HiLoRdSelValOp(code, *opt_flags) {{
368 code = 'int64_t ' + code
370 code = 'uint64_t ' + code
372 code += 'HI_RD_SEL = val<63:32>;\n'
373 code += 'LO_RD_SEL = val<31:0>;\n'
375 iop = InstObjParams(name, Name, 'HiLoRdSelOp', code, opt_flags)
376 header_output = BasicDeclare.subst(iop)
377 decoder_output = BasicConstructor.subst(iop)
378 decode_block = BasicDecode.subst(iop)
379 exec_output = HiLoRdSelExecute.subst(iop)
382 def format HiLoOp(code, *opt_flags) {{
383 iop = InstObjParams(name, Name, 'HiLoOp', code, opt_flags)
384 header_output = BasicDeclare.subst(iop)
385 decoder_output = BasicConstructor.subst(iop)
386 decode_block = BasicDecode.subst(iop)
387 exec_output = HiLoExecute.subst(iop)