int.isa revision 2495
1// -*- mode:c++ -*-
2
3////////////////////////////////////////////////////////////////////
4//
5// Integer operate instructions
6//
7
8//Outputs to decoder.hh
9output header {{
10#include <iostream>
11    using namespace std;
12        /**
13         * Base class for integer operations.
14         */
15        class IntOp : public MipsStaticInst
16        {
17                protected:
18
19                /// Constructor
20                IntOp(const char *mnem, MachInst _machInst, OpClass __opClass) :
21                                MipsStaticInst(mnem, _machInst, __opClass)
22                {
23                }
24
25                std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const;
26        };
27
28        class IntImmOp : public MipsStaticInst
29        {
30                protected:
31
32                int16_t imm;
33                int32_t sextImm;
34                uint32_t zextImm;
35
36                /// Constructor
37                IntImmOp(const char *mnem, MachInst _machInst, OpClass __opClass) :
38                    MipsStaticInst(mnem, _machInst, __opClass),imm(INTIMM),
39                    sextImm(INTIMM),zextImm(0x0000FFFF & INTIMM)
40                {
41                    //If Bit 15 is 1 then Sign Extend
42                    int32_t temp = sextImm & 0x00008000;
43                    if (temp > 0 && mnemonic != "lui") {
44                        sextImm |= 0xFFFF0000;
45                    }
46                }
47
48                std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const;
49
50
51        };
52
53}};
54
55//Outputs to decoder.cc
56output decoder {{
57        std::string IntOp::generateDisassembly(Addr pc, const SymbolTable *symtab) const
58        {
59            std::stringstream ss;
60
61            ccprintf(ss, "%-10s ", mnemonic);
62
63            // just print the first dest... if there's a second one,
64            // it's generally implicit
65            if (_numDestRegs > 0) {
66                printReg(ss, _destRegIdx[0]);
67            }
68
69            ss << ",";
70
71            // just print the first two source regs... if there's
72            // a third one, it's a read-modify-write dest (Rc),
73            // e.g. for CMOVxx
74            if (_numSrcRegs > 0) {
75                printReg(ss, _srcRegIdx[0]);
76            }
77
78            if (_numSrcRegs > 1) {
79                ss << ",";
80                printReg(ss, _srcRegIdx[1]);
81            }
82
83            return ss.str();
84        }
85
86        std::string IntImmOp::generateDisassembly(Addr pc, const SymbolTable *symtab) const
87        {
88            std::stringstream ss;
89
90            ccprintf(ss, "%-10s ", mnemonic);
91
92            if (_numDestRegs > 0) {
93                printReg(ss, _destRegIdx[0]);
94            }
95
96            ss << ",";
97
98            if (_numSrcRegs > 0) {
99                printReg(ss, _srcRegIdx[0]);
100                ss << ",";
101            }
102
103            if( mnemonic == "lui")
104                ccprintf(ss, "%08p ", sextImm);
105            else
106                ss << (int) sextImm;
107
108            return ss.str();
109        }
110
111}};
112
113//Used by decoder.isa
114def format IntOp(code, *opt_flags) {{
115        orig_code = code
116        cblk = CodeBlock(code)
117
118        # Figure out if we are creating a IntImmOp or a IntOp
119        # by looking at the instruction name
120        iop = InstObjParams(name, Name, 'IntOp', cblk, opt_flags)
121        strlen = len(name)
122        if name[strlen-1] == 'i' or name[strlen-2:] == 'iu':
123            iop = InstObjParams(name, Name, 'IntImmOp', cblk, opt_flags)
124
125        header_output = BasicDeclare.subst(iop)
126        decoder_output = BasicConstructor.subst(iop)
127        decode_block = OperateNopCheckDecode.subst(iop)
128        exec_output = BasicExecute.subst(iop)
129}};
130
131
132
133