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.


initial checking of internal decoder
[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
25
26
27 void v3_get_prefixes(uchar_t * instr, struct x86_prefixes * prefixes) {
28     while (1) {
29         switch (*instr) {
30             case 0xF0:      // lock
31                 prefixes->lock = 1;
32                 break;
33
34             case 0xF2:      // REPNE/REPNZ
35                 prefixes->repnz = 1;
36                 prefixes->repne = 1;
37                 break;
38
39             case 0xF3:      // REP or REPE/REPZ
40                 prefixes->rep = 1;
41                 prefixes->repe = 1;
42                 prefixes->repz = 1; 
43                 break;
44
45             case 0x2E:      // CS override or Branch hint not taken (with Jcc instrs)
46                 prefixes->cs_override = 1;
47                 prefixes->br_not_taken = 1;
48                 break;
49
50             case 0x36:      // SS override
51                 prefixes->ss_override = 1;
52                 break;
53
54             case 0x3E:      // DS override or Branch hint taken (with Jcc instrs)
55                 prefixes->ds_override = 1;
56                 prefixes->br_taken = 1;
57                 break;
58
59             case 0x26:      // ES override
60                 prefixes->es_override = 1;
61                 break;
62
63             case 0x64:      // FS override
64                 prefixes->fs_override = 1;
65                 break;
66       
67             case 0x65:      // GS override
68                 prefixes->gs_override = 1;
69                 break;
70
71             case 0x66:      // operand size override
72                 prefixes->op_size = 1;
73                 break;
74
75             case 0x67:    // address size override
76                 prefixes->addr_size = 1;
77                 break;
78
79             default:
80                 return;
81         }
82
83         instr++;
84     }
85
86 }
87
88 void v3_strip_rep_prefix(uchar_t * instr, int length) {
89     int read_ctr = 0;
90     int write_ctr = 0;
91     int found = 0;
92
93     while (read_ctr < length) {
94         if ((!found) && 
95             ( (instr[read_ctr] == 0xF2) ||
96               (instr[read_ctr] == 0xF3))) {
97             read_ctr++;
98             found = 1;
99         } else {
100             instr[write_ctr] = instr[read_ctr];
101             write_ctr++;
102             read_ctr++;
103         }
104     }
105 }