int.isa revision 2632:1bb2f91485ea
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                ss << ",";
68            }
69
70            // just print the first two source regs... if there's
71            // a third one, it's a read-modify-write dest (Rc),
72            // e.g. for CMOVxx
73            if (_numSrcRegs > 0) {
74                printReg(ss, _srcRegIdx[0]);
75            }
76
77            if (_numSrcRegs > 1) {
78                ss << ",";
79                printReg(ss, _srcRegIdx[1]);
80            }
81
82            return ss.str();
83        }
84
85        std::string IntImmOp::generateDisassembly(Addr pc, const SymbolTable *symtab) const
86        {
87            std::stringstream ss;
88
89            ccprintf(ss, "%-10s ", mnemonic);
90
91            if (_numDestRegs > 0) {
92                printReg(ss, _destRegIdx[0]);
93            }
94
95            ss << ",";
96
97            if (_numSrcRegs > 0) {
98                printReg(ss, _srcRegIdx[0]);
99                ss << ",";
100            }
101
102            if( mnemonic == "lui")
103                ccprintf(ss, "%08p ", sextImm);
104            else
105                ss << (int) sextImm;
106
107            return ss.str();
108        }
109
110}};
111
112//Used by decoder.isa
113def format IntOp(code, *opt_flags) {{
114        orig_code = code
115        cblk = CodeBlock(code)
116
117        # Figure out if we are creating a IntImmOp or a IntOp
118        # by looking at the instruction name
119        iop = InstObjParams(name, Name, 'IntOp', cblk, opt_flags)
120        strlen = len(name)
121        if name[strlen-1] == 'i' or name[strlen-2:] == 'iu':
122            iop = InstObjParams(name, Name, 'IntImmOp', cblk, opt_flags)
123
124        header_output = BasicDeclare.subst(iop)
125        decoder_output = BasicConstructor.subst(iop)
126        decode_block = OperateNopCheckDecode.subst(iop)
127        exec_output = BasicExecute.subst(iop)
128}};
129
130
131
132