X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fpalacios%2Fvmm_ctrl_regs.c;h=b31fcaabfd770c6afa8d352995122aad05abd4c9;hb=6f089682a19a99474faf05f74b44f9f71f58b30b;hp=a05957370c5d6079116915ed504fa94687dda51e;hpb=526ffdd06c1afb982d0d9831b99f337b6a094960;p=palacios.releases.git diff --git a/palacios/src/palacios/vmm_ctrl_regs.c b/palacios/src/palacios/vmm_ctrl_regs.c index a059573..b31fcaa 100644 --- a/palacios/src/palacios/vmm_ctrl_regs.c +++ b/palacios/src/palacios/vmm_ctrl_regs.c @@ -1,4 +1,4 @@ -#include + #include #include #include #include @@ -17,6 +17,11 @@ extern void SerialMemDump(unsigned char *start, int n); */ +#ifndef VMM_CTRL_REGS +#undef PrintDebug +#define PrintDebug(fmt, args...) +#endif + int handle_cr0_write(struct guest_info * info) { char instr[15]; @@ -29,7 +34,7 @@ int handle_cr0_write(struct guest_info * info) { PrintDebug("Real Mode write to CR0 at linear guest pa 0x%x\n",get_addr_linear(info,info->rip,&(info->segments.cs))); - PrintV3Segments(&(info->segments)); + //PrintV3Segments(info); // The real rip address is actually a combination of the rip + CS base ret = read_guest_pa_memory(info, get_addr_linear(info, info->rip, &(info->segments.cs)), 15, instr); @@ -38,7 +43,14 @@ int handle_cr0_write(struct guest_info * info) { PrintDebug("Could not read instruction (ret=%d)\n", ret); return -1; } + /* + { + struct x86_instr dec_instr; + v3_decode(info, (addr_t)instr, &dec_instr); + return -1; + } + */ while (is_prefix_byte(instr[index])) { switch(instr[index]) { case PREFIX_CS_OVERRIDE: @@ -289,10 +301,11 @@ int handle_cr0_write(struct guest_info * info) { index += 2; - PrintDebug("MovToCR0 instr:\n"); - PrintTraceMemDump(instr, 15); - PrintDebug("EAX=%x\n", *(uint_t*)&(info->vm_regs.rax)); - + /* + PrintDebug("MovToCR0 instr:\n"); + PrintTraceMemDump(instr, 15); + PrintDebug("EAX=%x\n", *(uint_t*)&(info->vm_regs.rax)); + */ addr_type = decode_operands32(&(info->vm_regs), instr + index, &index, &first_operand, &second_operand, REG32); if (addr_type != REG_OPERAND) { @@ -302,7 +315,7 @@ int handle_cr0_write(struct guest_info * info) { new_cr0 = (struct cr0_32 *)first_operand; - PrintDebug("first operand=%x\n", *(uint_t *)first_operand); + //PrintDebug("first operand=%x\n", *(uint_t *)first_operand); if (info->shdw_pg_mode == SHADOW_PAGING) { struct cr0_32 * shadow_cr0 = (struct cr0_32 *)&(info->shdw_pg_state.guest_cr0); @@ -333,7 +346,7 @@ int handle_cr0_write(struct guest_info * info) { info->mem_mode = PHYSICAL_MEM; PrintDebug("Entering Real Mode\n"); - PrintV3CtrlRegs(&(info->ctrl_regs)); + //PrintV3CtrlRegs(info); // reinstate the identity mapped paged tables // But keep the shadow tables around to handle TLB issues.... UGH... //info->shdw_pg_state.shadow_cr3 &= 0x00000fff; @@ -348,12 +361,19 @@ int handle_cr0_write(struct guest_info * info) { shadow_cr0->et = 1; real_cr0->et = 1; - PrintV3CtrlRegs(&(info->ctrl_regs)); + //PrintV3CtrlRegs(info); } } else { + if (new_cr0->pg == 1) { + info->mem_mode = VIRTUAL_MEM; + } else if (new_cr0->pg == 0) { + info->cpu_mode = REAL; + info->mem_mode = PHYSICAL_MEM; + } + *real_cr0 = *new_cr0; } @@ -488,7 +508,7 @@ int handle_cr0_read(struct guest_info * info) { int ret; PrintDebug("Real Mode read from CR0 at linear guest pa 0x%x\n",get_addr_linear(info,info->rip,&(info->segments.cs))); - PrintV3Segments(&(info->segments)); + //PrintV3Segments(info); // The real rip address is actually a combination of the rip + CS base ret = read_guest_pa_memory(info, get_addr_linear(info, info->rip, &(info->segments.cs)), 15, instr); @@ -628,8 +648,10 @@ int handle_cr0_read(struct guest_info * info) { } - PrintDebug("Instr (15 bytes) at %x:\n", instr); - PrintTraceMemDump((char*)instr, 15); + /* + PrintDebug("Instr (15 bytes) at %x:\n", instr); + PrintTraceMemDump((char*)instr, 15); + */ if (ret != 15) { // I think we should inject a GPF into the guest @@ -691,14 +713,13 @@ int handle_cr0_read(struct guest_info * info) { if (info->mem_mode == PHYSICAL_MEM) { virt_cr0->pg = 0; // clear the pg bit because guest doesn't think it's on } - - PrintDebug("real CR0: %x\n", *(uint_t*)real_cr0); - PrintDebug("returned CR0: %x\n", *(uint_t*)virt_cr0); - } else { *virt_cr0 = *real_cr0; } + + PrintDebug("real CR0: %x\n", *(uint_t*)real_cr0); + PrintDebug("returned CR0: %x\n", *(uint_t*)virt_cr0); info->rip += index; @@ -741,7 +762,7 @@ int handle_cr3_write(struct guest_info * info) { int ret; char instr[15]; - PrintDebug("Real Mode Write to CR3??? What the fuck???\n"); + PrintDebug("Real Mode Write to CR3.\n"); // We need to read the instruction, which is at CS:IP, but that // linear address is guest physical without PG and guest virtual with PG @@ -865,10 +886,10 @@ int handle_cr3_write(struct guest_info * info) { // linear address is guest physical without PG and guest virtual with PG if (info->mem_mode == PHYSICAL_MEM) { // The real rip address is actually a combination of the rip + CS base - PrintDebug("Writing Guest CR3 Write (Physical Address)\n"); + //PrintDebug("Writing Guest CR3 Write (Physical Address)\n"); ret = read_guest_pa_memory(info, get_addr_linear(info, info->rip, &(info->segments.cs)), 15, instr); } else { - PrintDebug("Writing Guest CR3 Write (Virtual Address)\n"); + //PrintDebug("Writing Guest CR3 Write (Virtual Address)\n"); // The real rip address is actually a combination of the rip + CS base ret = read_guest_va_memory(info, get_addr_linear(info, info->rip, &(info->segments.cs)), 15, instr); } @@ -1005,8 +1026,8 @@ int handle_cr3_read(struct guest_info * info) { linear_addr = get_addr_linear(info, info->rip, &(info->segments.cs)); - PrintDebug("RIP Linear: %x\n", linear_addr); - PrintV3Segments(&(info->segments)); + //PrintDebug("RIP Linear: %x\n", linear_addr); + //PrintV3Segments(info); ret = read_guest_pa_memory(info, linear_addr, 15, instr); @@ -1145,7 +1166,7 @@ int handle_cr3_read(struct guest_info * info) { } } else { PrintDebug("Invalid operating Mode (0x%x), control registers follow\n", info->cpu_mode); - PrintV3CtrlRegs(&(info->ctrl_regs)); + PrintV3CtrlRegs(info); return -1; }