X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fpalacios%2Fvm_guest.c;h=614c6a548138537814186890f42cbef762f76393;hb=207e3b36648e4019ad8505c75ae6ef0778464a26;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..614c6a5 100644 --- a/palacios/src/palacios/vm_guest.c +++ b/palacios/src/palacios/vm_guest.c @@ -1,7 +1,124 @@ +/* + * 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 +#include + + +v3_vm_cpu_mode_t v3_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->lme == 0)) { + return PROTECTED; + } else if (efer->lme == 0) { + return PROTECTED_PAE; + } else if ((efer->lme == 1) && (cs->long_mode == 1)) { + return LONG; + } else { + // What about LONG_16_COMPAT??? + return LONG_32_COMPAT; + } +} + + +static const uchar_t REAL_STR[] = "Real"; +static const uchar_t PROTECTED_STR[] = "Protected"; +static const uchar_t PROTECTED_PAE_STR[] = "Protected+PAE"; +static const uchar_t LONG_STR[] = "Long"; +static const uchar_t LONG_32_COMPAT_STR[] = "32bit Compat"; +static const uchar_t LONG_16_COMPAT_STR[] = "16bit Compat"; + +const uchar_t * v3_cpu_mode_to_str(v3_vm_cpu_mode_t mode) { + switch (mode) { + case REAL: + return REAL_STR; + case PROTECTED: + return PROTECTED_STR; + case PROTECTED_PAE: + return PROTECTED_PAE_STR; + case LONG: + return LONG_STR; + case LONG_32_COMPAT: + return LONG_32_COMPAT_STR; + case LONG_16_COMPAT: + return LONG_16_COMPAT_STR; + default: + return NULL; + } +} -void PrintV3Segments(struct guest_info * info) { +v3_vm_mem_mode_t v3_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; + } +} + +static const uchar_t PHYS_MEM_STR[] = "Physical Memory"; +static const uchar_t VIRT_MEM_STR[] = "Virtual Memory"; + +const uchar_t * v3_mem_mode_to_str(v3_vm_mem_mode_t mode) { + switch (mode) { + case PHYSICAL_MEM: + return PHYS_MEM_STR; + case VIRTUAL_MEM: + return VIRT_MEM_STR; + default: + return NULL; + } +} + + +void v3_print_segments(struct guest_info * info) { struct v3_segments * segs = &(info->segments); int i = 0; struct v3_segment * seg_ptr; @@ -13,30 +130,35 @@ void PrintV3Segments(struct guest_info * info) { for (i = 0; seg_names[i] != NULL; i++) { - PrintDebug("\t%s: Sel=%x, base=%x, limit=%x\n", seg_names[i], seg_ptr[i].selector, seg_ptr[i].base, seg_ptr[i].limit); + PrintDebug("\t%s: Sel=%x, base=%p, limit=%x\n", seg_names[i], seg_ptr[i].selector, + (void *)(addr_t)seg_ptr[i].base, seg_ptr[i].limit); } } -void PrintV3CtrlRegs(struct guest_info * info) { +void v3_print_ctrl_regs(struct guest_info * info) { struct v3_ctrl_regs * regs = &(info->ctrl_regs); int i = 0; v3_reg_t * reg_ptr; char * reg_names[] = {"CR0", "CR2", "CR3", "CR4", "CR8", "FLAGS", NULL}; + vmcb_saved_state_t * guest_state = GET_VMCB_SAVE_STATE_AREA(info->vmm_data); reg_ptr= (v3_reg_t *)regs; PrintDebug("32 bit Ctrl Regs:\n"); for (i = 0; reg_names[i] != NULL; i++) { - PrintDebug("\t%s=0x%x\n", reg_names[i], reg_ptr[i]); + PrintDebug("\t%s=0x%p\n", reg_names[i], (void *)(addr_t)reg_ptr[i]); } + + PrintDebug("\tEFER=0x%p\n", (void*)(addr_t)(guest_state->efer)); + } -void PrintV3GPRs(struct guest_info * info) { +void v3_print_GPRs(struct guest_info * info) { struct v3_gprs * regs = &(info->vm_regs); int i = 0; v3_reg_t * reg_ptr; @@ -47,6 +169,6 @@ void PrintV3GPRs(struct guest_info * info) { PrintDebug("32 bit GPRs:\n"); for (i = 0; reg_names[i] != NULL; i++) { - PrintDebug("\t%s=0x%x\n", reg_names[i], reg_ptr[i]); + PrintDebug("\t%s=0x%p\n", reg_names[i], (void *)(addr_t)reg_ptr[i]); } }