base.isa revision 2131
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     * Base class for all MIPS static instructions.
12     */
13    class MipsStaticInst : public StaticInst
14    {
15      protected:
16
17        /// Make MipsISA register dependence tags directly visible in
18        /// this class and derived classes.  Maybe these should really
19        /// live here and not in the MipsISA namespace.
20        enum DependenceTags {
21            FP_Base_DepTag = MipsISA::FP_Base_DepTag,
22            Fpcr_DepTag = MipsISA::Fpcr_DepTag,
23            Uniq_DepTag = MipsISA::Uniq_DepTag,
24            IPR_Base_DepTag = MipsISA::IPR_Base_DepTag
25        };
26
27        // Constructor
28        MipsStaticInst(const char *mnem, MachInst _machInst, OpClass __opClass)
29            : StaticInst(mnem, _machInst, __opClass)
30        {
31        }
32
33        /// Print a register name for disassembly given the unique
34        /// dependence tag number (FP or int).
35        void printReg(std::ostream &os, int reg) const;
36
37        std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const;
38    };
39
40}};
41
42//Ouputs to decoder.cc
43output decoder {{
44
45    void MipsStaticInst::printReg(std::ostream &os, int reg) const
46    {
47        if (reg < FP_Base_DepTag) {
48            ccprintf(os, "r%d", reg);
49        }
50        else {
51            ccprintf(os, "f%d", reg - FP_Base_DepTag);
52        }
53    }
54
55    std::string MipsStaticInst::generateDisassembly(Addr pc, const SymbolTable *symtab) const
56    {
57        std::stringstream ss;
58
59        ccprintf(ss, "%-10s ", mnemonic);
60
61        // just print the first two source regs... if there's
62        // a third one, it's a read-modify-write dest (Rc),
63        // e.g. for CMOVxx
64        if(_numSrcRegs > 0)
65        {
66            printReg(ss, _srcRegIdx[0]);
67        }
68        if(_numSrcRegs > 1)
69        {
70            ss << ",";
71            printReg(ss, _srcRegIdx[1]);
72        }
73
74        // just print the first dest... if there's a second one,
75        // it's generally implicit
76        if(_numDestRegs > 0)
77        {
78            if(_numSrcRegs > 0)
79                ss << ",";
80            printReg(ss, _destRegIdx[0]);
81        }
82
83        return ss.str();
84    }
85
86}};
87
88