From: Sandipan Das Date: Sat, 6 Feb 2021 11:47:34 +0000 (+0530) Subject: arch-power: Fix disassembly for arithmetic instructions X-Git-Tag: develop-gem5-snapshot~51 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=f53de369885467e26282d3e14b3d185dc41a3bcf;p=gem5.git arch-power: Fix disassembly for arithmetic instructions This fixes disassembly generated for integer add and subtract arithmetic instructions based on the type of operands and the special use cases for which the Power ISA provides extended mnemonics. Change-Id: I89b8271994e4d4b7b16efad170af5eeb5ee1aa10 Signed-off-by: Sandipan Das --- diff --git a/src/arch/power/insts/integer.cc b/src/arch/power/insts/integer.cc index 5ecb8ccd8..015ed723d 100644 --- a/src/arch/power/insts/integer.cc +++ b/src/arch/power/insts/integer.cc @@ -91,15 +91,112 @@ IntImmOp::generateDisassembly(Addr pc, const Loader::SymbolTable *symtab) const { std::stringstream ss; + ccprintf(ss, "%-10s ", mnemonic); + + // Print the first destination only + if (_numDestRegs > 0) { + printReg(ss, destRegIdx(0)); + } + + // Print the source register + if (_numSrcRegs > 0) { + if (_numDestRegs > 0) { + ss << ", "; + } + printReg(ss, srcRegIdx(0)); + } + + // Print the immediate value last + ss << ", " << (int32_t)imm; + + return ss.str(); +} + + +std::string +IntArithOp::generateDisassembly( + Addr pc, const Loader::SymbolTable *symtab) const +{ + std::stringstream ss; + bool printSecondSrc = true; + // Generate the correct mnemonic std::string myMnemonic(mnemonic); // Special cases - if (!myMnemonic.compare("addi") && _numSrcRegs == 0) { - myMnemonic = "li"; - } else if (!myMnemonic.compare("addis") && _numSrcRegs == 0) { - myMnemonic = "lis"; + if (!myMnemonic.compare("addme") || + !myMnemonic.compare("addze") || + !myMnemonic.compare("subfme") || + !myMnemonic.compare("subfze") || + !myMnemonic.compare("neg")){ + printSecondSrc = false; } + + // Additional characters depending on isa bits being set + if (oeSet) myMnemonic = myMnemonic + "o"; + if (rcSet) myMnemonic = myMnemonic + "."; + ccprintf(ss, "%-10s ", myMnemonic); + + // Print the first destination only + if (_numDestRegs > 0) { + printReg(ss, destRegIdx(0)); + } + + // Print the first source register + if (_numSrcRegs > 0) { + if (_numDestRegs > 0) { + ss << ", "; + } + printReg(ss, srcRegIdx(0)); + + // Print the second source register + if (_numSrcRegs > 1 && printSecondSrc) { + ss << ", "; + printReg(ss, srcRegIdx(1)); + } + } + + return ss.str(); +} + + +std::string +IntImmArithOp::generateDisassembly( + Addr pc, const Loader::SymbolTable *symtab) const +{ + std::stringstream ss; + bool negateSimm = false; + + // Generate the correct mnemonic + std::string myMnemonic(mnemonic); + + // Special cases + if (!myMnemonic.compare("addi")) { + if (_numSrcRegs == 0) { + myMnemonic = "li"; + } else if (simm < 0) { + myMnemonic = "subi"; + negateSimm = true; + } + } else if (!myMnemonic.compare("addis")) { + if (_numSrcRegs == 0) { + myMnemonic = "lis"; + } else if (simm < 0) { + myMnemonic = "subis"; + negateSimm = true; + } + } else if (!myMnemonic.compare("addic") && simm < 0) { + myMnemonic = "subic"; + negateSimm = true; + } else if (!myMnemonic.compare("addic_")) { + if (simm < 0) { + myMnemonic = "subic."; + negateSimm = true; + } else { + myMnemonic = "addic."; + } + } + ccprintf(ss, "%-10s ", myMnemonic); // Print the first destination only @@ -115,8 +212,12 @@ IntImmOp::generateDisassembly(Addr pc, const Loader::SymbolTable *symtab) const printReg(ss, srcRegIdx(0)); } - // Print the immediate value last - ss << ", " << (int32_t)imm; + // Print the immediate value + if (negateSimm) { + ss << ", " << -simm; + } else { + ss << ", " << simm; + } return ss.str(); } diff --git a/src/arch/power/insts/integer.hh b/src/arch/power/insts/integer.hh index 9efda4337..32c1ccd37 100644 --- a/src/arch/power/insts/integer.hh +++ b/src/arch/power/insts/integer.hh @@ -153,6 +153,9 @@ class IntArithOp : public IntOp : IntOp(mnem, _machInst, __opClass) { } + + std::string generateDisassembly( + Addr pc, const Loader::SymbolTable *symtab) const override; }; @@ -171,6 +174,9 @@ class IntImmArithOp : public IntArithOp simm((int16_t)machInst.si) { } + + std::string generateDisassembly( + Addr pc, const Loader::SymbolTable *symtab) const override; };