Skip to contentSkip to conversation

disas/libvixl: Update to VIXL 1.7

PATCH New Peter Maydell 1 participant 3 messages Jan 26, 2015

lore
Share & tools
lore
#0 lore raw

cover disas/libvixl: Update to VIXL 1.7

This patchseries brings our copy of libvixl up to upstream's 1.7 release. Patch 1 is the usual straight copy of upstream's files into our tree (note that this includes a fix for the compile warnings we previously dealt with locally in commit 94cc44a9e5). Patch 2 uses a new-in-1.7 feature to correct our disassembly of target addresses for relative jumps and offsets:

    Previous disassembly:
    
    0x0000000040000000:  580000c0      ldr x0, pc+24 (addr 0x7f6cb7020434)
    0x0000000040000004:  aa1f03e1      mov x1, xzr
    0x0000000040000008:  aa1f03e2      mov x2, xzr
    0x000000004000000c:  aa1f03e3      mov x3, xzr
    0x0000000040000010:  58000084      ldr x4, pc+16 (addr 0x7f6cb702042c)
    0x0000000040000014:  d61f0080      br x4
    
    Fixed disassembly:
    0x0000000040000000:  580000c0      ldr x0, pc+24 (addr 0x40000018)
    0x0000000040000004:  aa1f03e1      mov x1, xzr
    0x0000000040000008:  aa1f03e2      mov x2, xzr
    0x000000004000000c:  aa1f03e3      mov x3, xzr
    0x0000000040000010:  58000084      ldr x4, pc+16 (addr 0x40000020)
    0x0000000040000014:  d61f0080      br x4

(previous versions of vixl assumed that the host address of the instruction was the address the ARM CPU would see, since the primary usecase was disassembly of code generated by JITs targeting AArch64.)

Peter Maydell (2):
disas/libvixl: Update to upstream VIXL 1.7 disas/arm-a64.cc: Tell libvixl correct code addresses

 disas/arm-a64.cc                      |   9 +-
 disas/libvixl/README                  |   2 +-
 disas/libvixl/a64/assembler-a64.h     | 290 +++++++++++++++++++++-------------
 disas/libvixl/a64/constants-a64.h     |  61 +++++--
 disas/libvixl/a64/decoder-a64.h       |   2 +-
 disas/libvixl/a64/disasm-a64.cc       | 142 ++++++++++++++---
 disas/libvixl/a64/disasm-a64.h        |  48 ++++--
 disas/libvixl/a64/instructions-a64.cc |  63 ++++++++
 disas/libvixl/a64/instructions-a64.h  | 110 ++++++++-----
 disas/libvixl/globals.h               |   2 +-
 disas/libvixl/utils.cc                |  13 ++
 disas/libvixl/utils.h                 |  14 +-
 12 files changed, 543 insertions(+), 213 deletions(-)
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/2 disas/libvixl: Update to upstream VIXL 1.7

Update our copy of libvixl to upstream's 1.7 release. This includes upstream's fix for the issue we had a local patch for in commit 94cc44a9e.

---
 disas/libvixl/README                  |   2 +-
 disas/libvixl/a64/assembler-a64.h     | 290 +++++++++++++++++++++-------------
 disas/libvixl/a64/constants-a64.h     |  61 +++++--
 disas/libvixl/a64/decoder-a64.h       |   2 +-
 disas/libvixl/a64/disasm-a64.cc       | 142 ++++++++++++++---
 disas/libvixl/a64/disasm-a64.h        |  48 ++++--
 disas/libvixl/a64/instructions-a64.cc |  63 ++++++++
 disas/libvixl/a64/instructions-a64.h  | 110 ++++++++-----
 disas/libvixl/globals.h               |   2 +-
 disas/libvixl/utils.cc                |  13 ++
 disas/libvixl/utils.h                 |  14 +-
 11 files changed, 537 insertions(+), 210 deletions(-)
disas/libvixl/README +1 -1
index cba31b4..58db41c 100644
@@ -2,7 +2,7 @@
 The code in this directory is a subset of libvixl:
  https://github.com/armvixl/vixl
 (specifically, it is the set of files needed for disassembly only,
-taken from libvixl 1.6).
+taken from libvixl 1.7).
 Bugfixes should preferably be sent upstream initially.
 
 The disassembler does not currently support the entire A64 instruction
disas/libvixl/a64/assembler-a64.h +177 -113

729 lines not on this page · raw message

disas/libvixl/a64/constants-a64.h +44 -17

108 lines not on this page · raw message

disas/libvixl/a64/decoder-a64.h +1 -1
index 172594c..fd08d6c 100644
@@ -108,7 +108,7 @@ class DecoderVisitor {
   }
 
  private:
-  VisitorConstness constness_;
+  const VisitorConstness constness_;
 };
 
 
disas/libvixl/a64/disasm-a64.cc +120 -22

246 lines not on this page · raw message

disas/libvixl/a64/disasm-a64.h +39 -9

101 lines not on this page · raw message

disas/libvixl/a64/instructions-a64.cc +63 -0

75 lines not on this page · raw message

disas/libvixl/a64/instructions-a64.h +70 -40

234 lines not on this page · raw message

disas/libvixl/globals.h +1 -1
index e28dc66..0c24931 100644
@@ -58,7 +58,7 @@ const int KBytes = 1024;
 const int MBytes = 1024 * KBytes;
 
 #define VIXL_ABORT() printf("in %s, line %i", __FILE__, __LINE__); abort()
-#ifdef DEBUG
+#ifdef VIXL_DEBUG
   #define VIXL_ASSERT(condition) assert(condition)
   #define VIXL_CHECK(condition) VIXL_ASSERT(condition)
   #define VIXL_UNIMPLEMENTED() printf("UNIMPLEMENTED\t"); VIXL_ABORT()
disas/libvixl/utils.cc +13 -0
index 21965d7..80b132a 100644
@@ -135,4 +135,17 @@ bool IsPowerOf2(int64_t value) {
   return (value != 0) && ((value & (value - 1)) == 0);
 }
 
+
+unsigned CountClearHalfWords(uint64_t imm, unsigned reg_size) {
+  VIXL_ASSERT((reg_size % 8) == 0);
+  int count = 0;
+  for (unsigned i = 0; i < (reg_size / 16); i++) {
+    if ((imm & 0xffff) == 0) {
+      count++;
+    }
+    imm >>= 16;
+  }
+  return count;
+}
+
 }  // namespace vixl
disas/libvixl/utils.h +8 -6
index 1540c30..b440626 100644
@@ -166,6 +166,8 @@ int CountSetBits(uint64_t value, int width);
 uint64_t LowestSetBit(uint64_t value);
 bool IsPowerOf2(int64_t value);
 
+unsigned CountClearHalfWords(uint64_t imm, unsigned reg_size);
+
 // Pointer alignment
 // TODO: rename/refactor to make it specific to instructions.
 template<typename T>
@@ -174,14 +176,14 @@ bool IsWordAligned(T pointer) {
   return ((intptr_t)(pointer) & 3) == 0;
 }
 
-// Increment a pointer until it has the specified alignment.
+// Increment a pointer (up to 64 bits) until it has the specified alignment.
 template<class T>
 T AlignUp(T pointer, size_t alignment) {
   // Use C-style casts to get static_cast behaviour for integral types (T), and
   // reinterpret_cast behaviour for other types.
 
-  uintptr_t pointer_raw = (uintptr_t)pointer;
-  VIXL_STATIC_ASSERT(sizeof(pointer) == sizeof(pointer_raw));
+  uint64_t pointer_raw = (uint64_t)pointer;
+  VIXL_STATIC_ASSERT(sizeof(pointer) <= sizeof(pointer_raw));
 
   size_t align_step = (alignment - pointer_raw) % alignment;
   VIXL_ASSERT((pointer_raw + align_step) % alignment == 0);
@@ -189,14 +191,14 @@ T AlignUp(T pointer, size_t alignment) {
   return (T)(pointer_raw + align_step);
 }
 
-// Decrement a pointer until it has the specified alignment.
+// Decrement a pointer (up to 64 bits) until it has the specified alignment.
 template<class T>
 T AlignDown(T pointer, size_t alignment) {
   // Use C-style casts to get static_cast behaviour for integral types (T), and
   // reinterpret_cast behaviour for other types.
 
-  uintptr_t pointer_raw = (uintptr_t)pointer;
-  VIXL_STATIC_ASSERT(sizeof(pointer) == sizeof(pointer_raw));
+  uint64_t pointer_raw = (uint64_t)pointer;
+  VIXL_STATIC_ASSERT(sizeof(pointer) <= sizeof(pointer_raw));
 
   size_t align_step = pointer_raw % alignment;
   VIXL_ASSERT((pointer_raw - align_step) % alignment == 0);
Signature · 1 line
1.9.1
#2 lore raw

PATCH 2/2 disas/arm-a64.cc: Tell libvixl correct code addresses

In reply to Peter Maydell
Quoted 1 line

From 1.7, libvixl supports giving correct target addresses when

disassembling relative branches in code which doesn't reside at what the guest CPU would think its execution address is. Use the new MapCodeAddress() API to tell libvixl where the code is from the guest CPU's point of view so it can get the target addresses right.

Previous disassembly:

0x0000000040000000:  580000c0      ldr x0, pc+24 (addr 0x7f6cb7020434)
0x0000000040000004:  aa1f03e1      mov x1, xzr
0x0000000040000008:  aa1f03e2      mov x2, xzr
0x000000004000000c:  aa1f03e3      mov x3, xzr
0x0000000040000010:  58000084      ldr x4, pc+16 (addr 0x7f6cb702042c)
0x0000000040000014:  d61f0080      br x4

Fixed disassembly:

0x0000000040000000:  580000c0      ldr x0, pc+24 (addr 0x40000018)
0x0000000040000004:  aa1f03e1      mov x1, xzr
0x0000000040000008:  aa1f03e2      mov x2, xzr
0x000000004000000c:  aa1f03e3      mov x3, xzr
0x0000000040000010:  58000084      ldr x4, pc+16 (addr 0x40000020)
0x0000000040000014:  d61f0080      br x4
---
 disas/arm-a64.cc | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
disas/arm-a64.cc +6 -3
index ca29f6f..e04f946 100644
@@ -67,7 +67,8 @@ static void vixl_init(FILE *f) {
 int print_insn_arm_a64(uint64_t addr, disassemble_info *info)
 {
     uint8_t bytes[INSN_SIZE];
-    uint32_t instr;
+    uint32_t instrval;
+    const Instruction *instr;
     int status;
 
     status = info->read_memory_func(addr, bytes, INSN_SIZE, info);
@@ -80,8 +81,10 @@ int print_insn_arm_a64(uint64_t addr, disassemble_info *info)
         vixl_init(info->stream);
     }
 
-    instr = bytes[0] | bytes[1] << 8 | bytes[2] << 16 | bytes[3] << 24;
-    vixl_decoder->Decode(reinterpret_cast<Instruction*>(&instr));
+    instrval = bytes[0] | bytes[1] << 8 | bytes[2] << 16 | bytes[3] << 24;
+    instr = reinterpret_cast<const Instruction *>(&instrval);
+    vixl_disasm->MapCodeAddress(addr, instr);
+    vixl_decoder->Decode(instr);
 
     return INSN_SIZE;
 }
Signature · 1 line
1.9.1