properly sign-extend instructions in spike-dasm
authorAndrew Waterman <waterman@cs.berkeley.edu>
Thu, 29 Jan 2015 20:49:30 +0000 (12:49 -0800)
committerAndrew Waterman <waterman@cs.berkeley.edu>
Thu, 29 Jan 2015 20:49:57 +0000 (12:49 -0800)
spike_main/spike-dasm.cc

index d0af451f737c309d901ef1b253074f6c51b513ef..7f15db0bb168be15967d1b14572cba92f75087bb 100644 (file)
@@ -31,8 +31,13 @@ int main(int argc, char** argv)
       if (end == string::npos)
         break;
 
+      char* endp;
       size_t numstart = start + strlen("DASM(");
-      insn_bits_t bits = strtoull(&s[numstart], NULL, 16);
+      int64_t bits = strtoull(&s[numstart], &endp, 16);
+      size_t nbits = 4 * (endp - &s[numstart]);
+      if (nbits < 64)
+        bits = bits << (64 - nbits) >> (64 - nbits);
+
       string dis = d.disassemble(bits);
       s = s.substr(0, start) + dis + s.substr(end+1);
       start += dis.length();