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.


boot process to serial initialization
[palacios.git] / palacios / src / palacios / vmm_ctrl_regs.c
1 #include <palacios/vmm_mem.h>
2 #include <palacios/vmm.h>
3 #include <palacios/vmcb.h>
4 #include <palacios/vmm_decoder.h>
5 #include <palacios/vm_guest_mem.h>
6 #include <palacios/vmm_ctrl_regs.h>
7
8
9
10 extern void SerialMemDump(unsigned char *start, int n);
11
12 /* Segmentation is a problem here...
13  *
14  * When we get a memory operand, presumably we use the default segment (which is?) 
15  * unless an alternate segment was specfied in the prefix...
16  */
17
18
19 int handle_cr0_write(struct guest_info * info) {
20   char instr[15];
21   
22   
23   switch (info->cpu_mode) { 
24   case REAL: 
25     {
26       int index = 0;
27       int ret;
28       
29       PrintDebug("Real Mode write to CR0 at linear guest pa 0x%x\n",get_addr_linear(info,info->rip,&(info->segments.cs)));
30
31       // The real rip address is actually a combination of the rip + CS base 
32       ret = read_guest_pa_memory(info, get_addr_linear(info, info->rip, &(info->segments.cs)), 15, instr);
33       if (ret != 15) {
34         // I think we should inject a GPF into the guest
35         PrintDebug("Could not read instruction (ret=%d)\n", ret);
36         return -1;
37       }
38
39       while (is_prefix_byte(instr[index])) {
40         index++; 
41       }
42
43       if ((instr[index] == cr_access_byte) && 
44           (instr[index + 1] == lmsw_byte) && 
45           (MODRM_REG(instr[index + 2]) == lmsw_reg_byte)) {
46  
47         addr_t first_operand;
48         addr_t second_operand;
49         struct cr0_real *real_cr0;
50         struct cr0_real *new_cr0;
51         operand_type_t addr_type;
52         char new_cr0_val = 0;
53         // LMSW
54         // decode mod/RM
55         index += 2;
56  
57         real_cr0 = (struct cr0_real*)&(info->ctrl_regs.cr0);
58
59         addr_type = decode_operands16(&(info->vm_regs), instr + index, &index, &first_operand, &second_operand, REG16);
60
61
62         if (addr_type == REG_OPERAND) {
63           new_cr0 = (struct cr0_real *)first_operand;
64         } else if (addr_type == MEM_OPERAND) {
65           addr_t host_addr;
66
67           if (guest_pa_to_host_va(info, first_operand + (info->segments.ds.base << 4), &host_addr) == -1) {
68             // gpf the guest
69             return -1;
70           }
71
72           new_cr0 = (struct cr0_real *)host_addr;
73         } else {
74           PrintDebug("Memory operand in real mode write to CR0 is UNIMPLEMENTED\n");
75           // error... don't know what to do
76           return -1;
77         }
78                  
79         if ((new_cr0->pe == 1) && (real_cr0->pe == 0)) {
80           info->cpu_mode = PROTECTED;
81         } else if ((new_cr0->pe == 0) && (real_cr0->pe == 1)) {
82           info->cpu_mode = REAL;
83         }
84       
85         new_cr0_val = *(char*)(new_cr0) & 0x0f;
86
87
88         if (info->shdw_pg_mode == SHADOW_PAGING) {
89           struct cr0_real * shadow_cr0 = (struct cr0_real*)&(info->shdw_pg_state.guest_cr0);
90
91           PrintDebug("Old CR0=%x, Old Shadow CR0=%x\n", *real_cr0, *shadow_cr0);        
92           /* struct cr0_real is only 4 bits wide, 
93            * so we can overwrite the real_cr0 without worrying about the shadow fields
94            */
95           *(char*)real_cr0 &= 0xf0;
96           *(char*)real_cr0 |= new_cr0_val;
97         
98           *(char*)shadow_cr0 &= 0xf0;
99           *(char*)shadow_cr0 |= new_cr0_val;
100
101           PrintDebug("New CR0=%x, New Shadow CR0=%x\n", *real_cr0, *shadow_cr0);        
102         } else {
103           PrintDebug("Old CR0=%x\n", *real_cr0);        
104           // for now we just pass through....
105           *(char*)real_cr0 &= 0xf0;
106           *(char*)real_cr0 |= new_cr0_val;
107
108           PrintDebug("New CR0=%x\n", *real_cr0);        
109         }
110
111
112         info->rip += index;
113
114       } else if ((instr[index] == cr_access_byte) && 
115                  (instr[index + 1] == clts_byte)) {
116         // CLTS
117         PrintDebug("CLTS unhandled in CR0 write\n");
118         return -1;
119
120       } else if ((instr[index] == cr_access_byte) && 
121                  (instr[index + 1] = mov_to_cr_byte)) {
122         addr_t first_operand;
123         addr_t second_operand;
124         struct cr0_32 *real_cr0;
125         struct cr0_32 *new_cr0;
126         operand_type_t addr_type;
127      
128       
129         index += 2;
130  
131         real_cr0 = (struct cr0_32*)&(info->ctrl_regs.cr0);
132
133         addr_type = decode_operands16(&(info->vm_regs), instr + index, &index, &first_operand, &second_operand, REG32);
134
135         if (addr_type != REG_OPERAND) {
136           PrintDebug("Moving to CR0 from non-register operand in CR0 write\n");
137           /* Mov to CR0 Can only be a 32 bit register */
138           // FIX ME
139           return -1;
140         }
141
142         new_cr0 = (struct cr0_32 *)first_operand;
143
144         if (new_cr0->pe == 1) {
145           PrintDebug("Entering Protected Mode\n");
146           info->cpu_mode = PROTECTED;
147         }
148
149         if (new_cr0->pe == 0) { 
150           PrintDebug("Entering Real Mode\n");
151           info->cpu_mode = REAL;
152         }
153           
154
155         if (new_cr0->pg == 1) {
156           PrintDebug("Paging is already turned on in switch to protected mode in CR0 write\n");
157
158           // GPF the guest??
159           return -1;
160         }
161
162         if (info->shdw_pg_mode == SHADOW_PAGING) {
163           struct cr0_32 * shadow_cr0 = (struct cr0_32 *)&(info->shdw_pg_state.guest_cr0);
164         
165           PrintDebug("Old CR0=%x, Old Shadow CR0=%x\n", *real_cr0, *shadow_cr0);        
166           *real_cr0 = *new_cr0;
167           real_cr0->pg = 1;
168
169           *shadow_cr0 = *new_cr0;
170
171           PrintDebug("New CR0=%x, New Shadow CR0=%x\n", *real_cr0, *shadow_cr0);        
172         } else {
173           PrintDebug("Old CR0=%x\n", *real_cr0);        
174           *real_cr0 = *new_cr0;
175           PrintDebug("New CR0=%x\n", *real_cr0);        
176         }
177
178         info->rip += index;
179
180       } else {
181         PrintDebug("Unsupported Instruction\n");
182         // unsupported instruction, UD the guest
183         return -1;
184       }
185
186     } 
187     break;
188  
189   case PROTECTED: 
190     {
191
192       int index = 0;
193       int ret;
194
195       PrintDebug("Protected %s Mode write to CR0 at guest %s linear rip 0x%x\n", 
196                  info->mem_mode == VIRTUAL_MEM ? "Paged" : "",
197                  info->mem_mode == VIRTUAL_MEM ? "virtual" : "",
198                  get_addr_linear(info, info->rip, &(info->segments.cs)));
199
200       // OK, now we will read the instruction
201       // The only difference between PROTECTED and PROTECTED_PG is whether we read
202       // from guest_pa or guest_va
203       if (info->mem_mode == PHYSICAL_MEM) { 
204         // The real rip address is actually a combination of the rip + CS base 
205         ret = read_guest_pa_memory(info, get_addr_linear(info, info->rip, &(info->segments.cs)), 15, instr);
206       } else { 
207         ret = read_guest_va_memory(info, get_addr_linear(info, info->rip, &(info->segments.cs)), 15, instr);
208       }
209         
210
211       if (ret != 15) {
212         // I think we should inject a GPF into the guest
213         PrintDebug("Could not read instruction (ret=%d)\n", ret);
214         return -1;
215       }
216
217       while (is_prefix_byte(instr[index])) {
218         index++; 
219       }
220
221       struct cr0_32 * shadow_cr0 = (struct cr0_32 *)&(info->shdw_pg_state.guest_cr0);
222
223       struct cr0_32 * real_cr0 = (struct cr0_32*)&(info->ctrl_regs.cr0);
224
225       if ((instr[index] == cr_access_byte) && 
226           (instr[index + 1] == mov_to_cr_byte)) {
227
228         // MOV to CR0
229     
230         addr_t first_operand;
231         addr_t second_operand;
232         struct cr0_32 *new_cr0;
233         operand_type_t addr_type;
234
235         index += 2;
236  
237
238         addr_type = decode_operands32(&(info->vm_regs), instr + index, &index, &first_operand, &second_operand, REG32);
239
240         if (addr_type != REG_OPERAND) {
241           PrintDebug("Non-register operand in write to CR0\n");
242           return -1;
243         }
244
245         new_cr0 = (struct cr0_32 *)first_operand;
246
247
248
249         if (info->shdw_pg_mode == SHADOW_PAGING) {
250           struct cr0_32 * shadow_cr0 = (struct cr0_32 *)&(info->shdw_pg_state.guest_cr0);
251
252           if (new_cr0->pg == 1){
253             // This should be new_cr0->pg && !(old_cr->pg), right?
254             // and then a case for turning paging off?
255
256             struct cr3_32 * shadow_cr3 = (struct cr3_32 *)&(info->shdw_pg_state.shadow_cr3);
257
258             info->mem_mode = VIRTUAL_MEM;
259           
260             *shadow_cr0 = *new_cr0;
261             *real_cr0 = *new_cr0;
262
263             //
264             // Activate Shadow Paging
265             //
266             PrintDebug("Turning on paging in the guest\n");
267
268             info->ctrl_regs.cr3 = *(addr_t*)shadow_cr3;
269           
270
271           } else if (new_cr0->pe == 0) {
272             info->cpu_mode = REAL;
273
274             *shadow_cr0 = *new_cr0;
275             *real_cr0 = *new_cr0;
276             real_cr0->pg = 1;
277           }
278
279
280         } else {
281           *real_cr0 = *new_cr0;
282         }
283
284         info->rip += index;
285
286       } else if ((instr[index] == 0x0f) &&
287                  (instr[index + 1] == 0x06)) { 
288         // CLTS instruction
289         PrintDebug("CLTS instruction - clearing TS flag of real and shadow CR0\n");
290         shadow_cr0->ts = 0;
291         real_cr0->ts = 0;
292         
293         index+=2;
294         
295         info->rip+=index;
296
297       } else {
298         PrintDebug("Unkown instruction: \n");
299         SerialMemDump(instr,15);
300         return -1;
301       }
302     }
303     break;
304     
305   case PROTECTED_PAE:
306     PrintDebug("Protected PAE Mode write to CR0 is UNIMPLEMENTED\n");
307     return -1;
308
309   case LONG:
310     PrintDebug("Protected Long Mode write to CR0 is UNIMPLEMENTED\n");
311     return -1;
312
313   default: 
314     {
315       PrintDebug("Unknown Mode write to CR0 (info->cpu_mode=0x%x\n)",info->cpu_mode);
316       return -1;
317     }
318     break;
319
320   }
321
322   return 0;
323 }
324
325
326 int handle_cr0_read(struct guest_info * info) {
327   char instr[15];
328
329   switch (info->cpu_mode) { 
330
331   case REAL: 
332     {
333
334       int index = 0;
335       int ret;
336
337       PrintDebug("Real Mode read from CR0 at linear guest pa 0x%x\n",get_addr_linear(info,info->rip,&(info->segments.cs)));
338
339       // The real rip address is actually a combination of the rip + CS base 
340       ret = read_guest_pa_memory(info, get_addr_linear(info, info->rip, &(info->segments.cs)), 15, instr);
341       if (ret != 15) {
342         // I think we should inject a GPF into the guest
343         PrintDebug("Could not read Real Mode instruction (ret=%d)\n", ret);
344         return -1;
345       }
346
347
348       while (is_prefix_byte(instr[index])) {
349         index++; 
350       }
351
352       if ((instr[index] == cr_access_byte) && 
353           (instr[index + 1] == smsw_byte) && 
354           (MODRM_REG(instr[index + 2]) == smsw_reg_byte)) {
355
356         // SMSW (store machine status word)
357
358         addr_t first_operand;
359         addr_t second_operand;
360         struct cr0_real *cr0;
361         operand_type_t addr_type;
362         char cr0_val = 0;
363
364         index += 2;
365       
366         cr0 = (struct cr0_real*)&(info->ctrl_regs.cr0);
367       
368       
369         addr_type = decode_operands16(&(info->vm_regs), instr + index, &index, &first_operand, &second_operand, REG16);
370       
371         if (addr_type == MEM_OPERAND) {
372           addr_t host_addr;
373         
374           if (guest_pa_to_host_va(info, first_operand + (info->segments.ds.base << 4), &host_addr) == -1) {
375             // gpf the guest
376             PrintDebug("Could not convert guest physical address to host virtual address\n");
377             return -1;
378           }
379         
380           first_operand = host_addr;
381         } else {
382           // Register operand
383           // Should be ok??
384         }
385
386         cr0_val = *(char*)cr0 & 0x0f;
387
388         *(char *)first_operand &= 0xf0;
389         *(char *)first_operand |= cr0_val;
390
391         PrintDebug("index = %d, rip = %x\n", index, (ulong_t)(info->rip));
392         info->rip += index;
393         PrintDebug("new_rip = %x\n", (ulong_t)(info->rip));
394         // success
395
396       } else if ((instr[index] == cr_access_byte) &&
397                  (instr[index+1] == mov_from_cr_byte)) {
398         /* Mov from CR0
399          * This can only take a 32 bit register argument in anything less than 64 bit mode.
400          */
401         addr_t first_operand;
402         addr_t second_operand;
403         operand_type_t addr_type;
404
405         struct cr0_32 * real_cr0 = (struct cr0_32 *)&(info->ctrl_regs.cr0);
406
407         index += 2;
408
409         addr_type = decode_operands16(&(info->vm_regs), instr + index, &index, &first_operand, &second_operand, REG32);
410      
411         struct cr0_32 * virt_cr0 = (struct cr0_32 *)first_operand;
412   
413         if (addr_type != REG_OPERAND) {
414           // invalid opcode to guest
415           PrintDebug("Invalid operand type in mov from CR0\n");
416           return -1;
417         }
418
419         if (info->shdw_pg_mode == SHADOW_PAGING) {
420           *virt_cr0 = *(struct cr0_32 *)&(info->shdw_pg_state.guest_cr0);
421         } else {
422           *virt_cr0 = *real_cr0;
423         }
424
425         info->rip += index;
426
427       } else {
428         PrintDebug("Unknown read instr from CR0\n");
429         return -1;
430       }
431
432     } 
433
434     break;
435
436   case PROTECTED:
437     {
438     
439       int index = 0;
440       int ret;
441
442       PrintDebug("Protected %s Mode read from CR0 at guest %s linear rip 0x%x\n", 
443                  info->mem_mode == VIRTUAL_MEM ? "Paged" : "",
444                  info->mem_mode == VIRTUAL_MEM ? "virtual" : "",
445                  get_addr_linear(info, info->rip, &(info->segments.cs)));
446
447       // We need to read the instruction, which is at CS:IP, but that 
448       // linear address is guest physical without PG and guest virtual with PG
449       if (info->cpu_mode == PHYSICAL_MEM) { 
450         // The real rip address is actually a combination of the rip + CS base 
451         ret = read_guest_pa_memory(info, get_addr_linear(info, info->rip, &(info->segments.cs)), 15, instr);
452       } else { 
453         // The real rip address is actually a combination of the rip + CS base 
454         ret = read_guest_va_memory(info, get_addr_linear(info, info->rip, &(info->segments.cs)), 15, instr);
455       }
456
457       if (ret != 15) {
458         // I think we should inject a GPF into the guest
459         PrintDebug("Could not read Protected %s mode instruction (ret=%d)\n", 
460                    info->cpu_mode == VIRTUAL_MEM ? "Paged" : "", ret);
461         return -1;
462       }
463
464       while (is_prefix_byte(instr[index])) {
465         index++; 
466       }
467
468
469       if ((instr[index] == cr_access_byte) &&
470           (instr[index+1] == mov_from_cr_byte)) {
471         
472         // MOV from CR0 to register
473
474         addr_t first_operand;
475         addr_t second_operand;
476         operand_type_t addr_type;
477         struct cr0_32 * virt_cr0;
478         struct cr0_32 * real_cr0 = (struct cr0_32 *)&(info->ctrl_regs.cr0);
479
480         index += 2;
481
482         addr_type = decode_operands32(&(info->vm_regs), instr + index, &index, &first_operand, &second_operand, REG32);
483
484         if (addr_type != REG_OPERAND) {
485           PrintDebug("Invalid operand type in mov from CR0\n");
486           return -1;
487         }
488       
489         virt_cr0 = (struct cr0_32 *)first_operand;
490
491         if (info->shdw_pg_mode == SHADOW_PAGING) {
492           *virt_cr0 = *(struct cr0_32 *)&(info->shdw_pg_state.guest_cr0);
493           
494           if (info->mem_mode == PHYSICAL_MEM) {
495             virt_cr0->pg = 0; // clear the pg bit because guest doesn't think it's on
496           }
497           
498         } else {
499           *virt_cr0 = *real_cr0;
500         }
501       
502         info->rip += index;
503
504       } else { 
505         PrintDebug("Unknown read instruction from CR0\n");
506         return -1;
507       }
508     }
509     break;
510
511   case PROTECTED_PAE:
512     PrintDebug("Protected PAE Mode read to CR0 is UNIMPLEMENTED\n");
513     return -1;
514
515   case LONG:
516     PrintDebug("Protected Long Mode read to CR0 is UNIMPLEMENTED\n");
517     return -1;
518
519
520   default:
521     {
522       PrintDebug("Unknown Mode read from CR0 (info->cpu_mode=0x%x)\n",info->cpu_mode);
523       return -1;
524     }
525     break;
526   }
527
528
529   return 0;
530 }
531
532
533
534
535 int handle_cr3_write(struct guest_info * info) {
536   if (info->cpu_mode == PROTECTED) {
537     int index = 0;
538     int ret;
539     char instr[15];
540
541     PrintDebug("Protected %s mode write to CR3 at %s 0x%x\n",
542                info->cpu_mode==PROTECTED ? "" : "Paged", 
543                info->cpu_mode==PROTECTED ? "guest physical" : "guest virtual",
544                get_addr_linear(info,info->rip,&(info->segments.cs)));
545
546     // We need to read the instruction, which is at CS:IP, but that 
547     // linear address is guest physical without PG and guest virtual with PG
548     if (info->mem_mode == PHYSICAL_MEM) { 
549       // The real rip address is actually a combination of the rip + CS base 
550       PrintDebug("Writing Guest CR3 Write (Physical Address)\n");
551       ret = read_guest_pa_memory(info, get_addr_linear(info, info->rip, &(info->segments.cs)), 15, instr);
552     } else { 
553       PrintDebug("Writing Guest CR3 Write (Virtual Address)\n");
554       // The real rip address is actually a combination of the rip + CS base 
555       ret = read_guest_va_memory(info, get_addr_linear(info, info->rip, &(info->segments.cs)), 15, instr);
556     }
557
558     if (ret != 15) {
559       PrintDebug("Could not read instruction (ret=%d)\n", ret);
560       return -1;
561     }
562     
563     while (is_prefix_byte(instr[index])) {
564       index++;
565     }
566
567     if ((instr[index] == cr_access_byte) && 
568         (instr[index + 1] == mov_to_cr_byte)) {
569
570       addr_t first_operand;
571       addr_t second_operand;
572       struct cr3_32 * new_cr3;
573       //      struct cr3_32 * real_cr3;
574       operand_type_t addr_type;
575
576       index += 2;
577
578       addr_type = decode_operands32(&(info->vm_regs), instr + index, &index, &first_operand, &second_operand, REG32);
579
580       if (addr_type != REG_OPERAND) {
581         /* Mov to CR3 can only be a 32 bit register */
582         return -1;
583       }
584
585       new_cr3 = (struct cr3_32 *)first_operand;
586
587       if (info->shdw_pg_mode == SHADOW_PAGING) {
588         addr_t shadow_pt;
589         struct cr3_32 * shadow_cr3 = (struct cr3_32 *)&(info->shdw_pg_state.shadow_cr3);
590         struct cr3_32 * guest_cr3 = (struct cr3_32 *)&(info->shdw_pg_state.guest_cr3);
591
592
593           if (CR3_TO_PDE32(*(uint_t*)shadow_cr3) != 0) {
594             PrintDebug("Shadow Page Table\n");
595             PrintDebugPageTables((pde32_t *)CR3_TO_PDE32(*(uint_t*)shadow_cr3));
596           }
597
598         /* Delete the current Page Tables */
599         delete_page_tables_pde32((pde32_t *)CR3_TO_PDE32(*(uint_t*)shadow_cr3));
600
601         PrintDebug("Old Shadow CR3=%x; Old Guest CR3=%x\n", 
602                    *(uint_t*)shadow_cr3, *(uint_t*)guest_cr3);
603
604
605         *guest_cr3 = *new_cr3;
606
607
608
609         // Something like this
610         shadow_pt =  create_new_shadow_pt32(info);
611         //shadow_pt = setup_shadow_pt32(info, CR3_TO_PDE32(*(addr_t *)new_cr3));
612
613         /* Copy Various flags */
614         *shadow_cr3 = *new_cr3;
615
616         {
617           addr_t tmp_addr;
618           guest_pa_to_host_va(info, ((*(uint_t*)guest_cr3) & 0xfffff000), &tmp_addr);
619           PrintDebug("Guest PD\n");
620           PrintPD32((pde32_t *)tmp_addr);
621
622         }
623         
624
625         
626         shadow_cr3->pdt_base_addr = PD32_BASE_ADDR(shadow_pt);
627
628         PrintDebug("New Shadow CR3=%x; New Guest CR3=%x\n", 
629                    *(uint_t*)shadow_cr3, *(uint_t*)guest_cr3);
630
631
632
633         if (info->mem_mode == VIRTUAL_MEM) {
634           // If we aren't in paged mode then we have to preserve the identity mapped CR3
635           info->ctrl_regs.cr3 = *(addr_t*)shadow_cr3;
636         }
637       }
638
639       info->rip += index;
640
641     } else {
642       PrintDebug("Unknown Instruction\n");
643       SerialMemDump(instr,15);
644       return -1;
645     }
646   } else {
647     PrintDebug("Invalid operating Mode (0x%x)\n", info->cpu_mode);
648     return -1;
649   }
650
651   return 0;
652 }
653
654
655
656
657 int handle_cr3_read(struct guest_info * info) {
658   if (info->cpu_mode == PROTECTED) {
659     int index = 0;
660     int ret;
661     char instr[15];
662
663    
664     // We need to read the instruction, which is at CS:IP, but that 
665     // linear address is guest physical without PG and guest virtual with PG
666     if (info->cpu_mode == PHYSICAL_MEM) { 
667       // The real rip address is actually a combination of the rip + CS base 
668       ret = read_guest_pa_memory(info, get_addr_linear(info, info->rip, &(info->segments.cs)), 15, instr);
669     } else { 
670       // The real rip address is actually a combination of the rip + CS base 
671       ret = read_guest_va_memory(info, get_addr_linear(info, info->rip, &(info->segments.cs)), 15, instr);
672     }
673
674     if (ret != 15) {
675       PrintDebug("Could not read instruction (ret=%d)\n", ret);
676       return -1;
677     }
678     
679     while (is_prefix_byte(instr[index])) {
680       index++;
681     }
682
683     if ((instr[index] == cr_access_byte) && 
684         (instr[index + 1] == mov_from_cr_byte)) {
685       addr_t first_operand;
686       addr_t second_operand;
687       struct cr3_32 * virt_cr3;
688       struct cr3_32 * real_cr3 = (struct cr3_32 *)&(info->ctrl_regs.cr3);
689       operand_type_t addr_type;
690
691       index += 2;
692
693       addr_type = decode_operands32(&(info->vm_regs), instr + index, &index, &first_operand, &second_operand, REG32);
694
695       if (addr_type != REG_OPERAND) {
696         /* Mov to CR3 can only be a 32 bit register */
697         return -1;
698       }
699
700       virt_cr3 = (struct cr3_32 *)first_operand;
701
702       if (info->shdw_pg_mode == SHADOW_PAGING) {
703         *virt_cr3 = *(struct cr3_32 *)&(info->shdw_pg_state.guest_cr3);
704       } else {
705         *virt_cr3 = *real_cr3;
706       }
707       
708       info->rip += index;
709     } else {
710       PrintDebug("Unknown Instruction\n");
711       SerialMemDump(instr,15);
712       return -1;
713     }
714   } else {
715     PrintDebug("Invalid operating Mode (0x%x)\n", info->cpu_mode);
716     return -1;
717   }
718
719   return 0;
720 }