ARM: Show more information when disassembling data processing intstructions.
authorGabe Black <gblack@eecs.umich.edu>
Sat, 27 Jun 2009 07:30:23 +0000 (00:30 -0700)
committerGabe Black <gblack@eecs.umich.edu>
Sat, 27 Jun 2009 07:30:23 +0000 (00:30 -0700)
This will need more work, but it should be a lot closer.

src/arch/arm/insts/pred_inst.cc
src/arch/arm/insts/pred_inst.hh
src/arch/arm/insts/static_inst.cc
src/arch/arm/insts/static_inst.hh

index 7fd891b194d49573965df42dbe9d3a96dbf9de96..539cfc2d2212cf61eb42eef8ecb12e6f5acf7699 100644 (file)
@@ -35,60 +35,7 @@ std::string
 PredOp::generateDisassembly(Addr pc, const SymbolTable *symtab) const
 {
     std::stringstream ss;
-    printMnemonic(ss);
-    if (_numDestRegs > 0) {
-        printReg(ss, _destRegIdx[0]);
-    }
-
-    ss << ", ";
-
-    if (_numSrcRegs > 0) {
-        printReg(ss, _srcRegIdx[0]);
-        ss << ", ";
-    }
-
-    return ss.str();
-}
-
-std::string
-PredImmOp::generateDisassembly(Addr pc, const SymbolTable *symtab) const
-{
-    std::stringstream ss;
-
-    ccprintf(ss, "%-10s ", mnemonic);
-
-    if (_numDestRegs > 0) {
-        printReg(ss, _destRegIdx[0]);
-    }
-
-    ss << ", ";
-
-    if (_numSrcRegs > 0) {
-        printReg(ss, _srcRegIdx[0]);
-        ss << ", ";
-    }
-
-    return ss.str();
-}
-
-std::string
-PredIntOp::generateDisassembly(Addr pc, const SymbolTable *symtab) const
-{
-    std::stringstream ss;
-
-    ccprintf(ss, "%-10s ", mnemonic);
-
-    if (_numDestRegs > 0) {
-        printReg(ss, _destRegIdx[0]);
-    }
-
-    ss << ", ";
-
-    if (_numSrcRegs > 0) {
-        printReg(ss, _srcRegIdx[0]);
-        ss << ", ";
-    }
-
+    printDataInst(ss);
     return ss.str();
 }
 
index 65661efddf98c10ae565e602a80058aea788fa1c..38ac69358231947ff3688a715e6ef4f629d7a2a7 100644 (file)
@@ -82,8 +82,6 @@ class PredImmOp : public PredOp
             if (rotate != 0)
                 rotated_carry = (rotated_imm >> 31) & 1;
         }
-
-        std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const;
 };
 
 /**
@@ -102,8 +100,6 @@ class PredIntOp : public PredOp
                   shift_size(machInst.shiftSize), shift(machInst.shift)
         {
         }
-
-        std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const;
 };
 
 /**
index a76dbd69cbf7ab19ef3dddedf703a810957f4fda..011604d351e46b16909b98dbabcf554fe0d7f421 100644 (file)
@@ -327,6 +327,91 @@ ArmStaticInst::printMemSymbol(std::ostream &os,
     }
 }
 
+void
+ArmStaticInst::printShiftOperand(std::ostream &os) const
+{
+    // Shifter operand
+    if (bits((uint32_t)machInst, 25)) {
+        // Immediate form
+        unsigned rotate = machInst.rotate * 2;
+        uint32_t imm = machInst.imm;
+        ccprintf(os, "#%#x", (imm << (32 - rotate)) | (imm >> rotate));
+    } else {
+        // Register form
+        printReg(os, machInst.rm);
+
+        bool immShift = (machInst.opcode4 == 0);
+        bool done = false;
+        unsigned shiftAmt = (machInst.shiftSize);
+        ArmShiftType type = (ArmShiftType)(uint32_t)machInst.shift;
+
+        if ((type == LSR || type == ASR) && immShift && shiftAmt == 0)
+            shiftAmt = 32;
+
+        switch (type) {
+          case LSL:
+            if (immShift && shiftAmt == 0) {
+                done = true;
+                break;
+            }
+            os << ", LSL";
+            break;
+          case LSR:
+            os << ", LSR";
+            break;
+          case ASR:
+            os << ", ASR";
+            break;
+          case ROR:
+            if (immShift && shiftAmt == 0) {
+                os << ", RRX";
+                done = true;
+                break;
+            }
+            os << ", ROR";
+            break;
+          default:
+            panic("Tried to disassemble unrecognized shift type.\n");
+        }
+        if (!done) {
+            os << " ";
+            if (immShift)
+                os << "#" << shiftAmt;
+            else
+                printReg(os, machInst.rs);
+        }
+    }
+}
+
+void
+ArmStaticInst::printDataInst(std::ostream &os) const
+{
+    printMnemonic(os, machInst.sField ? "s" : "");
+    //XXX It would be nice if the decoder figured this all out for us.
+    unsigned opcode = machInst.opcode24_21;
+    bool firstOp = true;
+
+    // Destination
+    // Cmp, cmn, teq, and tst don't have one.
+    if (opcode < 8 || opcode > 0xb) {
+        firstOp = false;
+        printReg(os, machInst.rd);
+    }
+
+    // Source 1.
+    // Mov and Movn don't have one of these.
+    if (opcode != 0xd && opcode != 0xf) {
+        if (!firstOp)
+            os << ", ";
+        firstOp = false;
+        printReg(os, machInst.rn);
+    }
+
+    if (!firstOp)
+        os << ", ";
+    printShiftOperand(os);
+}
+
 std::string
 ArmStaticInst::generateDisassembly(Addr pc,
                                    const SymbolTable *symtab) const
index 6b745352edb50f79764c0d3e9600d71ea43f451b..22b59791ce8a19a6e809ce0e5a4322aada05fc9c 100644 (file)
@@ -68,8 +68,11 @@ class ArmStaticInst : public StaticInst
     void printMemSymbol(std::ostream &os, const SymbolTable *symtab,
                         const std::string &prefix, const Addr addr,
                         const std::string &suffix) const;
+    void printShiftOperand(std::ostream &os) const;
 
 
+    void printDataInst(std::ostream &os) const;
+
     std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const;
 };
 }