X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fpalacios%2Fvm_guest.c;h=64241aa5d1d611c52b25f8b75348c15c2aa33479;hb=e70e95962c26832628d586e07f9cd1a2e1852d72;hp=f920d1bc8a8b3be5ea63d90e0d69f564086f4270;hpb=8ee31494ea28d1756689574fb69791746daac3f3;p=palacios.git diff --git a/palacios/src/palacios/vm_guest.c b/palacios/src/palacios/vm_guest.c index f920d1b..64241aa 100644 --- a/palacios/src/palacios/vm_guest.c +++ b/palacios/src/palacios/vm_guest.c @@ -1,6 +1,82 @@ +/* + * 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 + * Copyright (c) 2008, The V3VEE Project + * All rights reserved. + * + * Author: Jack Lange + * + * This is free software. You are permitted to use, + * redistribute, and modify it as specified in the file "V3VEE_LICENSE". + */ + + + + #include +#include #include + +vm_cpu_mode_t get_cpu_mode(struct guest_info * info) { + struct cr0_32 * cr0; + struct cr4_32 * cr4 = (struct cr4_32 *)&(info->ctrl_regs.cr4); + struct efer_64 * efer = (struct efer_64 *)&(info->ctrl_regs.efer); + struct v3_segment * cs = &(info->segments.cs); + + if (info->shdw_pg_mode == SHADOW_PAGING) { + cr0 = (struct cr0_32 *)&(info->shdw_pg_state.guest_cr0); + } else if (info->shdw_pg_mode == NESTED_PAGING) { + cr0 = (struct cr0_32 *)&(info->ctrl_regs.cr0); + } else { + PrintError("Invalid Paging Mode...\n"); + V3_ASSERT(0); + return -1; + } + + if (cr0->pe == 0) { + return REAL; + } else if ((cr4->pae == 0) && (efer->lma == 0)) { + return PROTECTED; + } else if (efer->lma == 0) { + return PROTECTED_PAE; + } else if ((efer->lma == 1) && (cs->long_mode == 1)) { + return LONG; + } else { + return LONG_32_COMPAT; + } +} + +vm_mem_mode_t get_mem_mode(struct guest_info * info) { + struct cr0_32 * cr0; + + if (info->shdw_pg_mode == SHADOW_PAGING) { + cr0 = (struct cr0_32 *)&(info->shdw_pg_state.guest_cr0); + } else if (info->shdw_pg_mode == NESTED_PAGING) { + cr0 = (struct cr0_32 *)&(info->ctrl_regs.cr0); + } else { + PrintError("Invalid Paging Mode...\n"); + V3_ASSERT(0); + return -1; + } + + + + if (cr0->pg == 0) { + return PHYSICAL_MEM; + } else { + return VIRTUAL_MEM; + } +} + + void PrintV3Segments(struct guest_info * info) { struct v3_segments * segs = &(info->segments); int i = 0;