Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


Corrected handling of decode of memory operands that have a
Peter Dinda [Wed, 2 Mar 2011 21:36:03 +0000 (15:36 -0600)]
displacement.   This now correctly handles negative displacements
where the displacement width is <64 bits.

palacios/src/palacios/vmm_xed.c

index f4408f2..f140d1a 100644 (file)
@@ -700,13 +700,15 @@ static int get_memory_operand(struct guest_info * info,  xed_decoded_inst_t * xe
     index = MASK(mem_op.index, mem_op.index_size);
     scale = mem_op.scale;
 
-    // This is a horrendous hack...
-    // XED really screwed the pooch in calculating the displacement
-    if (cpu_mode == LONG) {
-       displacement = mem_op.displacement;
-    } else {
-       displacement = MASK(mem_op.displacement, mem_op.displacement_size);
-    }
+    // XED returns the displacement as a 2s complement signed number, but it can
+    // have different sizes, depending on the instruction encoding.
+    // we put that into a 64 bit unsigned (the unsigned doesn't matter since
+    // we only ever do 2s complement arithmetic on it.   However, this means we
+    // need to sign-extend what XED provides through 64 bits.
+    displacement = mem_op.displacement;
+    displacement <<= 64 - mem_op.displacement_size * 8;
+    displacement = ((sllong_t)displacement) >> (64 - mem_op.displacement_size * 8);
+    
 
     PrintDebug("Seg=%p, base=%p, index=%p, scale=%p, displacement=%p\n", 
               (void *)seg, (void *)base, (void *)index, (void *)scale, (void *)(addr_t)displacement);