Print this page
libdisasm: fully decode DPI immediate
The immediate value can be rotated.  Instead of dumping the 8-bit immediate
and 4-bit rotate field, we should dump the effective immediate value (both
in decimal and hex) to ease reading the disassembly.  This matches GNU
objdump behavior.

@@ -806,15 +806,21 @@
 
         /*
          * Print the shifter as appropriate
          */
         switch (dpi_inst.dpii_stype) {
-        case ARM_DPI_SHIFTER_IMM32:
-                len = snprintf(buf, buflen, ", #%d, %d",
-                    dpi_inst.dpii_un.dpii_im.dpisi_imm,
-                    dpi_inst.dpii_un.dpii_im.dpisi_rot);
+        case ARM_DPI_SHIFTER_IMM32: {
+                uint32_t imm = dpi_inst.dpii_un.dpii_im.dpisi_imm;
+                int rot = dpi_inst.dpii_un.dpii_im.dpisi_rot * 2;
+                if (rot != 0)
+                        imm = (imm << (32 - rot)) | (imm >> rot);
+                if (imm < 10)
+                        len = snprintf(buf, buflen, ", #%d", imm);
+                else
+                        len = snprintf(buf, buflen, ", #%d  ; %#x", imm, imm);
                 break;
+        }
         case ARM_DPI_SHIFTER_SIMM:
                 if (dpi_inst.dpii_un.dpii_si.dpiss_code == DPI_S_NONE) {
                         len = snprintf(buf, buflen, ", %s",
                             arm_reg_names[dpi_inst.dpii_un.dpii_si.dpiss_targ]);
                         break;