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