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.
6 * The V3VEE Project is a joint project between Northwestern University
7 * and the University of New Mexico. You can find out more at
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.
14 * Author: Jack Lange <jarusl@cs.northwestern.edu>
16 * This is free software. You are permitted to use,
17 * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
23 #include <palacios/vm_guest.h>
24 #include <palacios/vmm_ctrl_regs.h>
25 #include <palacios/vmm.h>
28 v3_vm_cpu_mode_t v3_get_cpu_mode(struct guest_info * info) {
30 struct cr4_32 * cr4 = (struct cr4_32 *)&(info->ctrl_regs.cr4);
31 struct efer_64 * efer = (struct efer_64 *)&(info->ctrl_regs.efer);
32 struct v3_segment * cs = &(info->segments.cs);
34 if (info->shdw_pg_mode == SHADOW_PAGING) {
35 cr0 = (struct cr0_32 *)&(info->shdw_pg_state.guest_cr0);
36 } else if (info->shdw_pg_mode == NESTED_PAGING) {
37 cr0 = (struct cr0_32 *)&(info->ctrl_regs.cr0);
39 PrintError("Invalid Paging Mode...\n");
46 } else if ((cr4->pae == 0) && (efer->lma == 0)) {
48 } else if (efer->lma == 0) {
50 } else if ((efer->lma == 1) && (cs->long_mode == 1)) {
53 return LONG_32_COMPAT;
57 v3_vm_mem_mode_t v3_get_mem_mode(struct guest_info * info) {
60 if (info->shdw_pg_mode == SHADOW_PAGING) {
61 cr0 = (struct cr0_32 *)&(info->shdw_pg_state.guest_cr0);
62 } else if (info->shdw_pg_mode == NESTED_PAGING) {
63 cr0 = (struct cr0_32 *)&(info->ctrl_regs.cr0);
65 PrintError("Invalid Paging Mode...\n");
80 void v3_print_segments(struct guest_info * info) {
81 struct v3_segments * segs = &(info->segments);
83 struct v3_segment * seg_ptr;
85 seg_ptr=(struct v3_segment *)segs;
87 char *seg_names[] = {"CS", "DS" , "ES", "FS", "GS", "SS" , "LDTR", "GDTR", "IDTR", "TR", NULL};
88 PrintDebug("Segments\n");
90 for (i = 0; seg_names[i] != NULL; i++) {
92 PrintDebug("\t%s: Sel=%x, base=%p, limit=%x\n", seg_names[i], seg_ptr[i].selector,
93 (void *)seg_ptr[i].base, seg_ptr[i].limit);
100 void v3_print_ctrl_regs(struct guest_info * info) {
101 struct v3_ctrl_regs * regs = &(info->ctrl_regs);
104 char * reg_names[] = {"CR0", "CR2", "CR3", "CR4", "CR8", "FLAGS", NULL};
106 reg_ptr= (v3_reg_t *)regs;
108 PrintDebug("32 bit Ctrl Regs:\n");
110 for (i = 0; reg_names[i] != NULL; i++) {
111 PrintDebug("\t%s=0x%p\n", reg_names[i], (void *)reg_ptr[i]);
116 void v3_print_GPRs(struct guest_info * info) {
117 struct v3_gprs * regs = &(info->vm_regs);
120 char * reg_names[] = { "RDI", "RSI", "RBP", "RSP", "RBX", "RDX", "RCX", "RAX", NULL};
122 reg_ptr= (v3_reg_t *)regs;
124 PrintDebug("32 bit GPRs:\n");
126 for (i = 0; reg_names[i] != NULL; i++) {
127 PrintDebug("\t%s=0x%p\n", reg_names[i], (void *)reg_ptr[i]);