X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fpalacios%2Fvm_guest.c;h=b9e49d280b2bdf66ac5ee858038eda7ed86e832b;hb=3cd1d3771e3f8e30b09f6c4995851979aaafc5ff;hp=b8319629ac0bdaf80a89e1602f71a1b4653d4d82;hpb=8a6d2dbc1b6d593cab383bb04f3fe778949376b2;p=palacios.git diff --git a/palacios/src/palacios/vm_guest.c b/palacios/src/palacios/vm_guest.c index b831962..b9e49d2 100644 --- a/palacios/src/palacios/vm_guest.c +++ b/palacios/src/palacios/vm_guest.c @@ -1,7 +1,84 @@ +/* + * 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 -void PrintV3Segments(struct v3_segments * segs) { + +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->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; + } +} + +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; + } +} + + +void v3_print_segments(struct guest_info * info) { + struct v3_segments * segs = &(info->segments); int i = 0; struct v3_segment * seg_ptr; @@ -19,7 +96,8 @@ void PrintV3Segments(struct v3_segments * segs) { } -void PrintV3CtrlRegs(struct v3_ctrl_regs * regs) { +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}; @@ -32,3 +110,19 @@ void PrintV3CtrlRegs(struct v3_ctrl_regs * regs) { PrintDebug("\t%s=0x%x\n", reg_names[i], reg_ptr[i]); } } + + +void v3_print_GPRs(struct guest_info * info) { + struct v3_gprs * regs = &(info->vm_regs); + int i = 0; + v3_reg_t * reg_ptr; + char * reg_names[] = { "RDI", "RSI", "RBP", "RSP", "RBX", "RDX", "RCX", "RAX", NULL}; + + reg_ptr= (v3_reg_t *)regs; + + 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]); + } +}