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.


changes
Jack Lange [Thu, 31 Jul 2008 18:47:58 +0000 (18:47 +0000)]
misc/decoder_test/Makefile
misc/decoder_test/test.asm
misc/decoder_test/test.c
misc/decoder_test/vmm_decoder.h
misc/decoder_test/vmm_xed.c

index 9b2bc18..6643fbd 100644 (file)
@@ -10,12 +10,12 @@ TEST_OBJS =  vm_guest.o vmm_xed.o test.o
 
 
 
-CFLAGS =  -I$(INCLUDEDIR) -D__V3VEE__ -g -gstabs
+CFLAGS =  -I$(INCLUDEDIR) -D__V3VEE__ -g -gstabs -D__DECODER_TEST__
 
 
 
 #CC=../../devtools/i386/bin/i386-elf-gcc
-CC=/usr/bin/gcc
+CC=/usr/bin/gcc -m32
 
 
 #CXXFLAGS =  -DDEBUG  -g -gstabs+ -Wall  -I/usr/kerberos/include
index 3073827..34245ee 100644 (file)
@@ -15,7 +15,15 @@ popa
 pusha
 push eax
 
-
+mov eax, 100
+mov [ebx + 2*esi], word 0x4
+       
+add ebx, 200
+       
 add eax, ebx
 out 0x64, al
 
+lmsw ax
+smsw ax
+mov cr0, eax
+clts
\ No newline at end of file
index 00b219f..f92238a 100644 (file)
@@ -63,6 +63,7 @@ static void init_guest_info(struct guest_info * info) {
 }
 static const char * mem = "MEMORY";
 static const char * reg = "REGISTER";
+static const char * imm = "IMMEDIATE";
 static const char * invalid = "INVALID";
 
 static const char * get_op_type_str(operand_type_t type) {
@@ -70,6 +71,8 @@ static const char * get_op_type_str(operand_type_t type) {
     return mem;
   } else if (type == REG_OPERAND) {
     return reg;
+  } else if (type == IMM_OPERAND) {
+    return imm;
   } else {
     return invalid;
   }
@@ -88,6 +91,11 @@ static int print_op(struct x86_operand *op) {
     printf("\taddr=0x%x\n", op->operand);
     return 0;
 
+  case IMM_OPERAND:
+    printf("\tsize=%d\n", op->size);
+    printf("\tval=0x%x\n", op->operand);
+    return 0;
+
   default:
     return -1;
   }
index d7b1d8d..0c7dcf4 100644 (file)
@@ -7,7 +7,7 @@
 #include "vm_guest.h"
 
 
-typedef enum {INVALID_OPERAND, REG_OPERAND, MEM_OPERAND} operand_type_t;
+typedef enum {INVALID_OPERAND, REG_OPERAND, MEM_OPERAND, IMM_OPERAND} operand_type_t;
 
 struct x86_operand {
   addr_t operand;
index a2ee930..fc676a9 100644 (file)
@@ -1,8 +1,17 @@
+#ifdef __DECODER_TEST__
 #include "vmm_decoder.h"
 #include "vmm_xed.h"
 #include <xed/xed-interface.h>
 #include "vm_guest.h"
 #include "test.h"
+#else
+#include <palacios/vmm_decoder.h>
+#include <palacios/vmm_xed.h>
+#include <xed/xed-interface.h>
+#include <palacios/vm_guest.h>
+#include <palacios/vmm.h>
+
+#endif
 
 static xed_state_t decoder_state;
 
@@ -161,12 +170,12 @@ int v3_decode(struct guest_info * info, addr_t instr_ptr, struct x86_instr * ins
 
 
 
-  /*
+
   if (get_opcode(iform, &(instr->opcode)) == -1) {
     PrintDebug("Could not get opcode. (iform=%s)\n", xed_iform_enum_t2str(iform));
     return -1;
   }
-  */
+
 
 
 
@@ -178,56 +187,71 @@ int v3_decode(struct guest_info * info, addr_t instr_ptr, struct x86_instr * ins
     const xed_operand_t * op = xed_inst_operand(xi, 0);
     xed_operand_enum_t op_enum = xed_operand_name(op);
 
+    struct x86_operand * v3_op = NULL;
+
+    if (xed_operand_written(op)) {
+      v3_op = &(instr->dst_operand);
+    } else {
+      v3_op = &(instr->src_operand);
+    }
+
+
     if (xed_operand_is_register(op_enum)) {
       xed_reg_enum_t xed_reg =  xed_decoded_inst_get_reg(&xed_instr, op_enum);
       int v3_reg_type = xed_reg_to_v3_reg(info, 
                                          xed_reg, 
-                                         &(instr->dst_operand.operand), 
-                                         &(instr->dst_operand.size));
+                                         &(v3_op->operand), 
+                                         &(v3_op->size));
                                          
       if (v3_reg_type == -1) {
        PrintError("First operand is an Unhandled Operand: %s\n", xed_reg_enum_t2str(xed_reg));
-       instr->dst_operand.type = INVALID_OPERAND;
+       v3_op->type = INVALID_OPERAND;
        return -1;
       } else if (v3_reg_type == SEGMENT_REGISTER) {
-       struct v3_segment * seg_reg = (struct v3_segment *)(instr->dst_operand.operand);
-       instr->dst_operand.operand = (addr_t)&(seg_reg->selector);
+       struct v3_segment * seg_reg = (struct v3_segment *)(v3_op->operand);
+       v3_op->operand = (addr_t)&(seg_reg->selector);
       }
 
-      instr->dst_operand.type = REG_OPERAND;
+      v3_op->type = REG_OPERAND;
     } else {
 
       switch (op_enum) {
 
       case XED_OPERAND_MEM0:
        {
-         struct x86_operand * operand = &(instr->dst_operand);
-
-         if (xed_decoded_inst_mem_read(&xed_instr, 0)) {
+         /*
+           struct x86_operand * operand = &(instr->dst_operand);
+           
+           if (xed_decoded_inst_mem_read(&xed_instr, 0)) {
            operand = &(instr->src_operand);
-         } else if (xed_decoded_inst_mem_written(&xed_instr, 0)) {
+           } else if (xed_decoded_inst_mem_written(&xed_instr, 0)) {
            operand = &(instr->dst_operand);
-         }
-
-         if (get_memory_operand(info, &xed_instr, 0, operand) == -1) {
+           }
+         */
+         
+         if (get_memory_operand(info, &xed_instr, 0, v3_op) == -1) {
            PrintError("Could not get first memory operand\n");
            return -1;
          }
        }
        break;
-      case XED_OPERAND_AGEN:
-      case XED_OPERAND_PTR:
-      case XED_OPERAND_RELBR:
-      case XED_OPERAND_IMM0:
-       PrintError("Unhandled Operand Type\n");
-       return -1;
 
       case XED_OPERAND_MEM1:
       case XED_OPERAND_IMM1:
        // illegal
        PrintError("Illegal Operand Order\n");
        return -1;
-      
+
+
+      case XED_OPERAND_IMM0:
+      case XED_OPERAND_AGEN:
+      case XED_OPERAND_PTR:
+      case XED_OPERAND_RELBR:
+      default:
+       PrintError("Unhandled Operand Type\n");
+       return -1;
+
+
       }
     }
   }
@@ -235,25 +259,34 @@ int v3_decode(struct guest_info * info, addr_t instr_ptr, struct x86_instr * ins
   // set second operand
   if (instr->num_operands >= 2) {
     const xed_operand_t * op = xed_inst_operand(xi, 1);
-    xed_operand_type_enum_t op_type = xed_operand_type(op);
+    //   xed_operand_type_enum_t op_type = xed_operand_type(op);
     xed_operand_enum_t op_enum = xed_operand_name(op);
     
+    struct x86_operand * v3_op;
+
+    if (xed_operand_written(op)) {
+      v3_op = &(instr->dst_operand);
+    } else {
+      v3_op = &(instr->src_operand);
+    }
+
+
     if (xed_operand_is_register(op_enum)) {
       xed_reg_enum_t xed_reg =  xed_decoded_inst_get_reg(&xed_instr, op_enum);
       int v3_reg_type = xed_reg_to_v3_reg(info, 
                                          xed_reg, 
-                                         &(instr->src_operand.operand), 
-                                         &(instr->src_operand.size));
+                                         &(v3_op->operand), 
+                                         &(v3_op->size));
       if (v3_reg_type == -1) {
        PrintError("Second operand is an Unhandled Operand: %s\n", xed_reg_enum_t2str(xed_reg));
-       instr->src_operand.type = INVALID_OPERAND;
+       v3_op->type = INVALID_OPERAND;
        return -1;
       } else if (v3_reg_type == SEGMENT_REGISTER) {
-       struct v3_segment * seg_reg = (struct v3_segment *)(instr->src_operand.operand);
-       instr->src_operand.operand = (addr_t)&(seg_reg->selector);
+       struct v3_segment * seg_reg = (struct v3_segment *)(v3_op->operand);
+       v3_op->operand = (addr_t)&(seg_reg->selector);
       }
 
-      instr->src_operand.type = REG_OPERAND;
+      v3_op->type = REG_OPERAND;
     
 
     } else {
@@ -262,35 +295,50 @@ int v3_decode(struct guest_info * info, addr_t instr_ptr, struct x86_instr * ins
 
       case XED_OPERAND_MEM0:
        {
-         struct x86_operand * operand = &(instr->src_operand);
 
+         /*
          if (xed_decoded_inst_mem_read(&xed_instr, 0)) {
-           operand = &(instr->src_operand);
+           v3_op = &(instr->src_operand);
          } else if (xed_decoded_inst_mem_written(&xed_instr, 0)) {
-           operand = &(instr->dst_operand);
+           v3_op = &(instr->dst_operand);
          }
+         */
 
-         if (get_memory_operand(info, &xed_instr, 0, operand) == -1) {
+         if (get_memory_operand(info, &xed_instr, 0, v3_op) == -1) {
            PrintError("Could not get first memory operand\n");
            return -1;
          }
        }
        break;
-      case XED_OPERAND_AGEN:
-      case XED_OPERAND_PTR:
-      case XED_OPERAND_RELBR:
+
       case XED_OPERAND_IMM0:
-       PrintError("Unhandled Operand Type\n");
-       return -1;
+       {
+         instr->src_operand.size = xed_decoded_inst_get_immediate_width(&xed_instr);
+
+         if (instr->src_operand.size > 4) {
+           PrintError("Unhandled 64 bit immediates\n");
+           return -1;
+         }
+         instr->src_operand.operand = xed_decoded_inst_get_unsigned_immediate(&xed_instr);
+
+         instr->src_operand.type = IMM_OPERAND;
+
+       }
+       break;
 
       case XED_OPERAND_MEM1:
       case XED_OPERAND_IMM1:
        // illegal
        PrintError("Illegal Operand Order\n");
        return -1;
-      
+       
+      case XED_OPERAND_AGEN:
+      case XED_OPERAND_PTR:
+      case XED_OPERAND_RELBR:
+      default:
+       PrintError("Unhandled Operand Type\n");
+       return -1;
       }
-
     }
 
   }
@@ -298,7 +346,7 @@ int v3_decode(struct guest_info * info, addr_t instr_ptr, struct x86_instr * ins
   // set third operand
   if (instr->num_operands >= 3) {
     const xed_operand_t * op = xed_inst_operand(xi, 2);
-    xed_operand_type_enum_t op_type = xed_operand_type(op);
+    //  xed_operand_type_enum_t op_type = xed_operand_type(op);
     xed_operand_enum_t op_enum = xed_operand_name(op);
 
     if (xed_operand_is_register(op_enum)) {
@@ -322,7 +370,7 @@ int v3_decode(struct guest_info * info, addr_t instr_ptr, struct x86_instr * ins
 
 
     } else {
-      PrintError("Unhandled third operand type %s\n", xed_operand_type_enum_t2str(op_type));
+      //      PrintError("Unhandled third operand type %s\n", xed_operand_type_enum_t2str(op_type));
       return -1;
     }
 
@@ -352,12 +400,12 @@ static int get_memory_operand(struct guest_info * info,  xed_decoded_inst_t * xe
   addr_t scale;
   addr_t index;
   ullong_t displacement;
-  struct v3_segment * seg_reg;
+  // struct v3_segment * seg_reg;
 
 
 
 
-  memset(&mem_op, 0, sizeof(struct memory_operand));
+  memset((void*)&mem_op, '\0', sizeof(struct memory_operand));
 
   xed_reg_enum_t xed_seg = xed_decoded_inst_get_seg_reg(xed_instr, op_index);
   if (xed_seg != XED_REG_INVALID) {