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.


Merge branch 'Release-1.2' of ssh://palacios@newskysaw.cs.northwestern.edu//home...
[palacios.git] / palacios / src / palacios / vmm_decoder.c
index e859ee5..4b88e67 100644 (file)
-/* Northwestern University */
-/* (c) 2008, Jack Lange <jarusl@cs.northwestern.edu> */
+/* 
+ * This file is part of the Palacios Virtual Machine Monitor developed
+ * by the V3VEE Project with funding from the United States National 
+ * Science Foundation and the Department of Energy.  
+ *
+ * The V3VEE Project is a joint project between Northwestern University
+ * and the University of New Mexico.  You can find out more at 
+ * http://www.v3vee.org
+ *
+ * Copyright (c) 2008, Jack Lange <jarusl@cs.northwestern.edu> 
+ * Copyright (c) 2008, The V3VEE Project <http://www.v3vee.org> 
+ * All rights reserved.
+ *
+ * Author: Jack Lange <jarusl@cs.northwestern.edu>
+ *
+ * This is free software.  You are permitted to use,
+ * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
+ */
+
 
 #include <palacios/vmm_decoder.h>
 
 
-int opcode_cmp(const uchar_t * op1, const uchar_t * op2) {
-  if (op1[0] != op2[0]) {
-    return op1[0] - op2[0];;
-  } else {
-    return memcmp(op1 + 1, op2 + 1, op1[0]);
-  }
+int v3_opcode_cmp(const uchar_t * op1, const uchar_t * op2) {
+    if (op1[0] != op2[0]) {
+       return op1[0] - op2[0];;
+    } else {
+       return memcmp(op1 + 1, op2 + 1, op1[0]);
+    }
 }
 
 
-void strip_rep_prefix(uchar_t * instr, int length) {
-  int read_ctr = 0;
-  int write_ctr = 0;
-  int found = 0;
+void v3_get_prefixes(uchar_t * instr, struct x86_prefixes * prefixes) {
+    while (1) {
+       switch (*instr) {
+           case 0xF0:      // lock
+               prefixes->lock = 1;
+               break;
 
-  while (read_ctr < length) {
-    if ((!found) && 
-       ( (instr[read_ctr] == 0xF2) ||
-         (instr[read_ctr] == 0xF3))) {
-      read_ctr++;
-      found = 1;
-    } else {
-      instr[write_ctr] = instr[read_ctr];
-      write_ctr++;
-      read_ctr++;
+           case 0xF2:      // REPNE/REPNZ
+               prefixes->repnz = 1;
+               prefixes->repne = 1;
+               break;
+
+           case 0xF3:      // REP or REPE/REPZ
+               prefixes->rep = 1;
+               prefixes->repe = 1;
+               prefixes->repz = 1; 
+               break;
+
+           case 0x2E:      // CS override or Branch hint not taken (with Jcc instrs)
+               prefixes->cs_override = 1;
+               prefixes->br_not_taken = 1;
+               break;
+
+           case 0x36:      // SS override
+               prefixes->ss_override = 1;
+               break;
+
+           case 0x3E:      // DS override or Branch hint taken (with Jcc instrs)
+               prefixes->ds_override = 1;
+               prefixes->br_taken = 1;
+               break;
+
+           case 0x26:      // ES override
+               prefixes->es_override = 1;
+               break;
+
+           case 0x64:      // FS override
+               prefixes->fs_override = 1;
+               break;
+      
+           case 0x65:      // GS override
+               prefixes->gs_override = 1;
+               break;
+
+           case 0x66:      // operand size override
+               prefixes->op_size = 1;
+               break;
+
+           case 0x67:    // address size override
+               prefixes->addr_size = 1;
+               break;
+
+           default:
+               return;
+       }
+
+       instr++;
+    }
+
+}
+
+void v3_strip_rep_prefix(uchar_t * instr, int length) {
+    int read_ctr = 0;
+    int write_ctr = 0;
+    int found = 0;
+
+    while (read_ctr < length) {
+       if ((!found) && 
+           ( (instr[read_ctr] == 0xF2) ||
+             (instr[read_ctr] == 0xF3))) {
+           read_ctr++;
+           found = 1;
+       } else {
+           instr[write_ctr] = instr[read_ctr];
+           write_ctr++;
+           read_ctr++;
+       }
     }
-  }
 }