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
1 /* 
2  * This file is part of the Palacios Virtual Machine Monitor developed
3  * by the V3VEE Project with funding from the United States National 
4  * Science Foundation and the Department of Energy.  
5  *
6  * The V3VEE Project is a joint project between Northwestern University
7  * and the University of New Mexico.  You can find out more at 
8  * http://www.v3vee.org
9  *
10  * Copyright (c) 2008, Jack Lange <jarusl@cs.northwestern.edu> 
11  * Copyright (c) 2008, The V3VEE Project <http://www.v3vee.org> 
12  * All rights reserved.
13  *
14  * Author: Jack Lange <jarusl@cs.northwestern.edu>
15  *
16  * This is free software.  You are permitted to use,
17  * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
18  */
19
20
21 #include <palacios/vmm_decoder.h>
22
23
24 int v3_opcode_cmp(const uchar_t * op1, const uchar_t * op2) {
25     if (op1[0] != op2[0]) {
26         return op1[0] - op2[0];;
27     } else {
28         return memcmp(op1 + 1, op2 + 1, op1[0]);
29     }
30 }
31
32
33 void v3_get_prefixes(uchar_t * instr, struct x86_prefixes * prefixes) {
34     while (1) {
35         switch (*instr) {
36             case 0xF0:      // lock
37                 prefixes->lock = 1;
38                 break;
39
40             case 0xF2:      // REPNE/REPNZ
41                 prefixes->repnz = 1;
42                 prefixes->repne = 1;
43                 break;
44
45             case 0xF3:      // REP or REPE/REPZ
46                 prefixes->rep = 1;
47                 prefixes->repe = 1;
48                 prefixes->repz = 1; 
49                 break;
50
51             case 0x2E:      // CS override or Branch hint not taken (with Jcc instrs)
52                 prefixes->cs_override = 1;
53                 prefixes->br_not_taken = 1;
54                 break;
55
56             case 0x36:      // SS override
57                 prefixes->ss_override = 1;
58                 break;
59
60             case 0x3E:      // DS override or Branch hint taken (with Jcc instrs)
61                 prefixes->ds_override = 1;
62                 prefixes->br_taken = 1;
63                 break;
64
65             case 0x26:      // ES override
66                 prefixes->es_override = 1;
67                 break;
68
69             case 0x64:      // FS override
70                 prefixes->fs_override = 1;
71                 break;
72       
73             case 0x65:      // GS override
74                 prefixes->gs_override = 1;
75                 break;
76
77             case 0x66:      // operand size override
78                 prefixes->op_size = 1;
79                 break;
80
81             case 0x67:    // address size override
82                 prefixes->addr_size = 1;
83                 break;
84
85             default:
86                 return;
87         }
88
89         instr++;
90     }
91
92 }
93
94 void v3_strip_rep_prefix(uchar_t * instr, int length) {
95     int read_ctr = 0;
96     int write_ctr = 0;
97     int found = 0;
98
99     while (read_ctr < length) {
100         if ((!found) && 
101             ( (instr[read_ctr] == 0xF2) ||
102               (instr[read_ctr] == 0xF3))) {
103             read_ctr++;
104             found = 1;
105         } else {
106             instr[write_ctr] = instr[read_ctr];
107             write_ctr++;
108             read_ctr++;
109         }
110     }
111 }