Skip to content

Latest commit

 

History

History
131 lines (86 loc) · 4.05 KB

README.md

File metadata and controls

131 lines (86 loc) · 4.05 KB

uefi_hv

Barevisor as a UEFI driver for Intel and AMD processors.

Why UEFI driver-based hypervisor

Barevisor can be compiled into both the UEFI driver and Windows kernel driver. Those interested in virtualizing UEFI, boot loaders, and early OS initialization phases should study UEFI driver-based hypervisors. It is also suitable for having a better picture of how Intel VT-x and AMD SVM work, as well as OS-agnostic designs.

Building

  1. Navigate to the barevisor\src\uefi directory.

    > cd C:\Users\tanda\Desktop\RnD\GitHub\barevisor\src\uefi
    
  2. Build Barevisor with the xtask command.

    > cargo xtask build
    

    If successful, target\x86_64-unknown-uefi\debug\uefi_hv.efi should exist.

    Along with that, check_hv_vendor.efi is built. This is useful for confirming that Barevisor is loaded into the system (more in the below section).

Testing with Bochs

Barevisor can be partially tested with Bochs, a cross-platform open-source x86_64 PC emulator. Bochs is extremely helpful in the early phase of hypervisor development as it can be used to debug the types of errors that are difficult to diagnose on VMware. Failure of the VMX instructions is the primal example.

Setting up a VM

Set up a Bochs VM with the following instructions:

  • On Ubuntu and Windows (WSL)
    $ sudo apt install build-essential p7zip-full mtools genisoimage
    $ git clone -b barevisor /~https://github.com/tandasat/Bochs.git
    $ cd Bochs/bochs
    $ sh .conf.linux
    $ make
    $ sudo make install
    
  • On macOS
    $ brew install p7zip
    $ brew install mtools
    $ brew install cdrtools
    $ git clone -b barevisor /~https://github.com/tandasat/Bochs.git
    $ cd Bochs/bochs
    $ sh .conf.macosx
    $ make
    $ sudo make install
    

Loading on and virtualizing UEFI

In the uefi directory, run either cargo xtask bochs-amd or cargo xtask bochs-intel to test on AMD and Intel processors respectively.

You may test code on the UEFI shell but not booting an OS. The author was unable to install an OS on Bochs when UEFI is used instead of traditional BIOS. Please let me know if you made it work.

Testing with VMware

You can use VMware Workstation Pro or Fusion Pro to test the hypervisor with a VM comes with this repo.

Loading on and virtualizing UEFI

  1. Install the necessary dependencies:

    • On Ubuntu and Windows (WSL)

      $ sudo apt install build-essential p7zip-full mtools genisoimage
      
    • On macOS

      $ brew install p7zip
      $ brew install mtools
      $ brew install cdrtools
      
  2. In the uefi directory, run cargo xtask vmware. It will automatically boot a VM, enter the UEFI shell and load uefi_hv.efi as below:

    startup.nsh> echo -off
    Loading uefi_hv.efi
    Image base: 0xe5ce000..0xe627000
    Loaded uefi_hv.efi
    load: Image fs1:\uefi_hv.efi loaded at E5CE000 - Success
    Executing CPUID(0x40000000) on all logical processors
    CPU 0: Barevisor!
    fs1:\>
    

    ✅ If successful, serial output should appear. Additionally, you may confirm that Barevisor is active by executing check_hv_vendor.efi.

    fs1:\> check_hv_vendor.efi
    Executing CPUID(0x40000000) on all logical processors
    CPU 0: Barevisor!
    

You will want to boot an OS after installing Barevisor. Install your choice of a Windows version in the provided VM image for further testing.