From: Jack Lange Date: Wed, 25 Feb 2009 23:15:43 +0000 (-0600) Subject: added address width calculations X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?p=palacios.git;a=commitdiff_plain;h=97cd5fe64c098b917e5519d30fd54c4b4e338b1c added address width calculations --- diff --git a/palacios/include/palacios/vm_guest.h b/palacios/include/palacios/vm_guest.h index d7fcdeb..8b2104e 100644 --- a/palacios/include/palacios/vm_guest.h +++ b/palacios/include/palacios/vm_guest.h @@ -149,6 +149,7 @@ struct guest_info { v3_vm_cpu_mode_t cpu_mode; v3_vm_mem_mode_t mem_mode; + uint_t addr_width; struct v3_gprs vm_regs; @@ -183,6 +184,7 @@ struct guest_info { }; +uint_t v3_get_addr_width(struct guest_info * info); v3_vm_cpu_mode_t v3_get_cpu_mode(struct guest_info * info); v3_vm_mem_mode_t v3_get_mem_mode(struct guest_info * info); diff --git a/palacios/src/palacios/vm_guest.c b/palacios/src/palacios/vm_guest.c index a0a0889..5406e7a 100644 --- a/palacios/src/palacios/vm_guest.c +++ b/palacios/src/palacios/vm_guest.c @@ -56,6 +56,37 @@ v3_vm_cpu_mode_t v3_get_cpu_mode(struct guest_info * info) { } } +// Get address width in bytes +uint_t v3_get_addr_width(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->guest_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 2; + } else if ((cr4->pae == 0) && (efer->lme == 0)) { + return 4; + } else if (efer->lme == 0) { + return 4; + } else if ((efer->lme == 1) && (cs->long_mode == 1)) { + return 8; + } else { + // What about LONG_16_COMPAT??? + return 4; + } +} + static const uchar_t REAL_STR[] = "Real"; static const uchar_t PROTECTED_STR[] = "Protected";