1 #include <palacios/vm_guest.h>
2 #include <palacios/vmm_ctrl_regs.h>
3 #include <palacios/vmm.h>
6 vm_cpu_mode_t get_cpu_mode(struct guest_info * info) {
8 struct cr4_32 * cr4 = (struct cr4_32 *)&(info->ctrl_regs.cr4);
9 struct efer_64 * efer = (struct efer_64 *)&(info->ctrl_regs.efer);
10 struct v3_segment * cs = &(info->segments.cs);
12 if (info->shdw_pg_mode == SHADOW_PAGING) {
13 cr0 = (struct cr0_32 *)&(info->shdw_pg_state.guest_cr0);
14 } else if (info->shdw_pg_mode == NESTED_PAGING) {
15 cr0 = (struct cr0_32 *)&(info->ctrl_regs.cr0);
17 PrintError("Invalid Paging Mode...\n");
24 } else if ((cr4->pae == 0) && (efer->lma == 0)) {
26 } else if (efer->lma == 0) {
28 } else if ((efer->lma == 1) && (cs->long_mode == 1)) {
31 return LONG_32_COMPAT;
35 vm_mem_mode_t get_mem_mode(struct guest_info * info) {
38 if (info->shdw_pg_mode == SHADOW_PAGING) {
39 cr0 = (struct cr0_32 *)&(info->shdw_pg_state.guest_cr0);
40 } else if (info->shdw_pg_mode == NESTED_PAGING) {
41 cr0 = (struct cr0_32 *)&(info->ctrl_regs.cr0);
43 PrintError("Invalid Paging Mode...\n");
58 void PrintV3Segments(struct guest_info * info) {
59 struct v3_segments * segs = &(info->segments);
61 struct v3_segment * seg_ptr;
63 seg_ptr=(struct v3_segment *)segs;
65 char *seg_names[] = {"CS", "DS" , "ES", "FS", "GS", "SS" , "LDTR", "GDTR", "IDTR", "TR", NULL};
66 PrintDebug("Segments\n");
68 for (i = 0; seg_names[i] != NULL; i++) {
70 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);
77 void PrintV3CtrlRegs(struct guest_info * info) {
78 struct v3_ctrl_regs * regs = &(info->ctrl_regs);
81 char * reg_names[] = {"CR0", "CR2", "CR3", "CR4", "CR8", "FLAGS", NULL};
83 reg_ptr= (v3_reg_t *)regs;
85 PrintDebug("32 bit Ctrl Regs:\n");
87 for (i = 0; reg_names[i] != NULL; i++) {
88 PrintDebug("\t%s=0x%x\n", reg_names[i], reg_ptr[i]);
93 void PrintV3GPRs(struct guest_info * info) {
94 struct v3_gprs * regs = &(info->vm_regs);
97 char * reg_names[] = { "RDI", "RSI", "RBP", "RSP", "RBX", "RDX", "RCX", "RAX", NULL};
99 reg_ptr= (v3_reg_t *)regs;
101 PrintDebug("32 bit GPRs:\n");
103 for (i = 0; reg_names[i] != NULL; i++) {
104 PrintDebug("\t%s=0x%x\n", reg_names[i], reg_ptr[i]);