Guest User

Untitled

a guest
Jun 25th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. A VMM is just an abstraction. If you consider a virtual machine as a physical machine (running, for example, an os), then of course you need a software, running in root mode (at the most privileged level), with which you can abstract the underlying hardware.
  2. Via this software (and its interactions with control registers) you can create VMs and control transitions between the virtual machine monitor (so the name) and the vms.
  3.  
  4. The VMM, using VM entries (based on the transiction mechanism) can enter guests into a virtual machine. Using VM exit it transfer control into the VMM itself.
  5.  
  6. Before go into the details of the transiction mechanism, we should enter in VMX operation, to enable the communication betwen the virtualized cpu and the host software. We can do it using VMXON instruction. Some warinesses:
  7. first of all software has to check the VT-x technology support for VMX using CPUID instruction.
  8. with CPUID, with 01 as input value (in EAX register) that specifies the featurs informations as output in ECX register.
  9. Simply we should check if CPUID.1:ECX.VMX[bit 5] = 1.
  10.  
  11. mov eax, 1
  12. cpuid
  13. and ecx, 0x20
  14. mov supported, ecx
  15. if (!supported) return STATUS_VMX_UNSUPPORTED;
  16.  
  17. Now we have to create the VMXON region, as support for the processor using VMX operation. This memory must be 4kb aligned of unpageable memory.
  18.  
  19. VMXONregion.pVMXONva = MmAllocateNonCachedMemory(VMXONregion.size);
  20. VmxSetMem(VMXONregion.pVMXONva, 0, 4096);
  21.  
  22. A basic VMM software supports only a paged-protected operating mode, so we have to check, via cr0 register the PE and PG bits.
  23.  
  24. mov eax, cr0
  25. and eax, 0x80000000
  26. mov pgMode, eax
  27. mov eax, cr0
  28. and eax, 1
  29. mov ppMode, eax
  30. if (!(pgMode && ppMode)) return STATUS_VMX_UNSUPPORTED;
  31.  
  32. Then software should check if the lock bit of IA32_FEATURE_CONTROL MSR (code 0x3a) is set, otherwise a general protection exception occurs.
  33.  
  34. GetMSR64(0x3A, &msrStruct);
  35. if ((msrStruct.low && 1) == 0) return STATUS_VMX_UNSUPPORTED;
  36.  
  37. Finally we can lunch the vmxon ensuring that the VMX operation is enabled in cr4 register otherwise an invalid opcode exception occurs.
  38.  
  39. or cr4, 0x2000
  40. Vmxon(*VMXONregion.physicalAdd);
Add Comment
Please, Sign In to add comment