base.isa revision 2686:f0d591379ac3
1// -*- mode:c++ -*-
2
3////////////////////////////////////////////////////////////////////
4//
5// Base class for MIPS instructions, and some support functions
6//
7
8//Outputs to decoder.hh
9output header {{
10
11    using namespace MipsISA;
12
13
14    /**
15     * Base class for all MIPS static instructions.
16     */
17    class MipsStaticInst : public StaticInst
18    {
19      protected:
20
21        // Constructor
22        MipsStaticInst(const char *mnem, MachInst _machInst, OpClass __opClass)
23            : StaticInst(mnem, _machInst, __opClass)
24        {
25        }
26
27        /// Print a register name for disassembly given the unique
28        /// dependence tag number (FP or int).
29        void printReg(std::ostream &os, int reg) const;
30
31        std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const;
32    };
33
34}};
35
36//Ouputs to decoder.cc
37output decoder {{
38
39    void MipsStaticInst::printReg(std::ostream &os, int reg) const
40    {
41        if (reg < FP_Base_DepTag) {
42            ccprintf(os, "r%d", reg);
43        }
44        else {
45            ccprintf(os, "f%d", reg - FP_Base_DepTag);
46        }
47    }
48
49    std::string MipsStaticInst::generateDisassembly(Addr pc, const SymbolTable *symtab) const
50    {
51        std::stringstream ss;
52
53        ccprintf(ss, "%-10s ", mnemonic);
54
55        if(_numDestRegs > 0){
56            printReg(ss, _destRegIdx[0]);
57        }
58
59        if(_numSrcRegs > 0) {
60            ss << ", ";
61            printReg(ss, _srcRegIdx[0]);
62        }
63
64        if(_numSrcRegs > 1) {
65            ss << ", ";
66            printReg(ss, _srcRegIdx[1]);
67        }
68
69
70        if(mnemonic == "sll" || mnemonic == "sra"){
71            ccprintf(ss,", %d",SA);
72        }
73
74        return ss.str();
75    }
76
77}};
78
79