3 // Copyright (c) 2006 The Regents of The University of Michigan
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
38 * Base class for integer operations.
40 class IntOp : public MipsStaticInst
45 IntOp(const char *mnem, MachInst _machInst, OpClass __opClass) :
46 MipsStaticInst(mnem, _machInst, __opClass)
50 std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const;
54 class HiLoOp: public IntOp
59 HiLoOp(const char *mnem, MachInst _machInst, OpClass __opClass) :
60 IntOp(mnem, _machInst, __opClass)
64 std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const;
67 class HiLoMiscOp: public HiLoOp
72 HiLoMiscOp(const char *mnem, MachInst _machInst, OpClass __opClass) :
73 HiLoOp(mnem, _machInst, __opClass)
77 std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const;
81 class IntImmOp : public MipsStaticInst
90 IntImmOp(const char *mnem, MachInst _machInst, OpClass __opClass) :
91 MipsStaticInst(mnem, _machInst, __opClass),imm(INTIMM),
92 sextImm(INTIMM),zextImm(0x0000FFFF & INTIMM)
94 //If Bit 15 is 1 then Sign Extend
95 int32_t temp = sextImm & 0x00008000;
96 if (temp > 0 && mnemonic != "lui") {
97 sextImm |= 0xFFFF0000;
101 std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const;
108 // HiLo<Misc> instruction class execute method template.
109 // Mainly to get instruction trace data to print out
111 def template HiLoExecute {{
112 Fault %(class_name)s::execute(%(CPU_exec_context)s *xc, Trace::InstRecord *traceData) const
114 Fault fault = NoFault;
124 //If there are 2 Destination Registers then
125 //concatenate the values for the traceData
126 if(traceData && _numDestRegs == 2) {
127 uint64_t hilo_final_val = (uint64_t)HI << 32 | LO;
128 traceData->setData(hilo_final_val);
135 //Outputs to decoder.cc
137 std::string IntOp::generateDisassembly(Addr pc, const SymbolTable *symtab) const
139 std::stringstream ss;
141 ccprintf(ss, "%-10s ", mnemonic);
143 // just print the first dest... if there's a second one,
144 // it's generally implicit
145 if (_numDestRegs > 0) {
146 printReg(ss, _destRegIdx[0]);
150 // just print the first two source regs... if there's
151 // a third one, it's a read-modify-write dest (Rc),
153 if (_numSrcRegs > 0) {
154 printReg(ss, _srcRegIdx[0]);
157 if (_numSrcRegs > 1) {
159 printReg(ss, _srcRegIdx[1]);
165 std::string HiLoOp::generateDisassembly(Addr pc, const SymbolTable *symtab) const
167 std::stringstream ss;
169 ccprintf(ss, "%-10s ", mnemonic);
171 //Destination Registers are implicit for HI/LO ops
172 if (_numSrcRegs > 0) {
173 printReg(ss, _srcRegIdx[0]);
176 if (_numSrcRegs > 1) {
178 printReg(ss, _srcRegIdx[1]);
184 std::string HiLoMiscOp::generateDisassembly(Addr pc, const SymbolTable *symtab) const
186 std::stringstream ss;
188 ccprintf(ss, "%-10s ", mnemonic);
190 if (_numDestRegs > 0 && _destRegIdx[0] < 32) {
191 printReg(ss, _destRegIdx[0]);
192 } else if (_numSrcRegs > 0 && _srcRegIdx[0] < 32) {
193 printReg(ss, _srcRegIdx[0]);
199 std::string IntImmOp::generateDisassembly(Addr pc, const SymbolTable *symtab) const
201 std::stringstream ss;
203 ccprintf(ss, "%-10s ", mnemonic);
205 if (_numDestRegs > 0) {
206 printReg(ss, _destRegIdx[0]);
211 if (_numSrcRegs > 0) {
212 printReg(ss, _srcRegIdx[0]);
216 if( mnemonic == "lui")
217 ccprintf(ss, "0x%x ", sextImm);
226 def format IntOp(code, *opt_flags) {{
227 iop = InstObjParams(name, Name, 'IntOp', code, opt_flags)
228 header_output = BasicDeclare.subst(iop)
229 decoder_output = BasicConstructor.subst(iop)
230 decode_block = RegNopCheckDecode.subst(iop)
231 exec_output = BasicExecute.subst(iop)
234 def format IntImmOp(code, *opt_flags) {{
235 iop = InstObjParams(name, Name, 'IntImmOp', code, opt_flags)
236 header_output = BasicDeclare.subst(iop)
237 decoder_output = BasicConstructor.subst(iop)
238 decode_block = ImmNopCheckDecode.subst(iop)
239 exec_output = BasicExecute.subst(iop)
242 def format HiLoOp(code, *opt_flags) {{
243 code += 'HI = val<63:32>;\n'
244 code += 'LO = val<31:0>;\n'
246 iop = InstObjParams(name, Name, 'HiLoOp', code, opt_flags)
247 header_output = BasicDeclare.subst(iop)
248 decoder_output = BasicConstructor.subst(iop)
249 decode_block = BasicDecode.subst(iop)
250 exec_output = HiLoExecute.subst(iop)
253 def format HiLoMiscOp(code, *opt_flags) {{
254 iop = InstObjParams(name, Name, 'HiLoMiscOp', code, opt_flags)
255 header_output = BasicDeclare.subst(iop)
256 decoder_output = BasicConstructor.subst(iop)
257 decode_block = BasicDecode.subst(iop)
258 exec_output = BasicExecute.subst(iop)