1 /* (c) 2008, Jack Lange <jarusl@cs.northwestern.edu> */
2 /* (c) 2008, The V3VEE Project <http://www.v3vee.org> */
4 #include <palacios/vm_guest.h>
5 #include <palacios/vmm_ctrl_regs.h>
6 #include <palacios/vmm.h>
9 vm_cpu_mode_t get_cpu_mode(struct guest_info * info) {
11 struct cr4_32 * cr4 = (struct cr4_32 *)&(info->ctrl_regs.cr4);
12 struct efer_64 * efer = (struct efer_64 *)&(info->ctrl_regs.efer);
13 struct v3_segment * cs = &(info->segments.cs);
15 if (info->shdw_pg_mode == SHADOW_PAGING) {
16 cr0 = (struct cr0_32 *)&(info->shdw_pg_state.guest_cr0);
17 } else if (info->shdw_pg_mode == NESTED_PAGING) {
18 cr0 = (struct cr0_32 *)&(info->ctrl_regs.cr0);
20 PrintError("Invalid Paging Mode...\n");
27 } else if ((cr4->pae == 0) && (efer->lma == 0)) {
29 } else if (efer->lma == 0) {
31 } else if ((efer->lma == 1) && (cs->long_mode == 1)) {
34 return LONG_32_COMPAT;
38 vm_mem_mode_t get_mem_mode(struct guest_info * info) {
41 if (info->shdw_pg_mode == SHADOW_PAGING) {
42 cr0 = (struct cr0_32 *)&(info->shdw_pg_state.guest_cr0);
43 } else if (info->shdw_pg_mode == NESTED_PAGING) {
44 cr0 = (struct cr0_32 *)&(info->ctrl_regs.cr0);
46 PrintError("Invalid Paging Mode...\n");
61 void PrintV3Segments(struct guest_info * info) {
62 struct v3_segments * segs = &(info->segments);
64 struct v3_segment * seg_ptr;
66 seg_ptr=(struct v3_segment *)segs;
68 char *seg_names[] = {"CS", "DS" , "ES", "FS", "GS", "SS" , "LDTR", "GDTR", "IDTR", "TR", NULL};
69 PrintDebug("Segments\n");
71 for (i = 0; seg_names[i] != NULL; i++) {
73 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);
80 void PrintV3CtrlRegs(struct guest_info * info) {
81 struct v3_ctrl_regs * regs = &(info->ctrl_regs);
84 char * reg_names[] = {"CR0", "CR2", "CR3", "CR4", "CR8", "FLAGS", NULL};
86 reg_ptr= (v3_reg_t *)regs;
88 PrintDebug("32 bit Ctrl Regs:\n");
90 for (i = 0; reg_names[i] != NULL; i++) {
91 PrintDebug("\t%s=0x%x\n", reg_names[i], reg_ptr[i]);
96 void PrintV3GPRs(struct guest_info * info) {
97 struct v3_gprs * regs = &(info->vm_regs);
100 char * reg_names[] = { "RDI", "RSI", "RBP", "RSP", "RBX", "RDX", "RCX", "RAX", NULL};
102 reg_ptr= (v3_reg_t *)regs;
104 PrintDebug("32 bit GPRs:\n");
106 for (i = 0; reg_names[i] != NULL; i++) {
107 PrintDebug("\t%s=0x%x\n", reg_names[i], reg_ptr[i]);