visor/src/efi.c

49 lines
1,002 B
C

#include <stdbool.h>
#include <efi.h>
#include <efilib.h>
#include "virt.h"
#include "bootstrap.h"
#include "procvisor.h"
struct virt_vtable *virt = &virt_vtable_intel;
static char virt_err[100];
void *
bs_alloc(size_t size)
{
size_t npages = (size + (4096 - 1)) / 4096;
void *ptr;
uefi_call_wrapper(BS->AllocatePages, 4, AllocateAnyPages, EfiRuntimeServicesData, npages, &ptr);
return ptr;
}
EFIAPI
EFI_STATUS
efi_main(EFI_HANDLE imageHandle, EFI_SYSTEM_TABLE *systemTable)
{
InitializeLib(imageHandle, systemTable);
AsciiPrint("Pointer Size: %d\n", (int)sizeof(void *));
AsciiPrint("efi_main: %p\n", (void *)efi_main);
AsciiPrint("* Setting up processor structures\n");
struct procvisor *pv = proc_setup();
(void)pv;
AsciiPrint("* Checking for VT-x Support\n");
if (!virt->has_support(virt_err, sizeof virt_err)) {
AsciiPrint(virt_err);
} else {
AsciiPrint("* Enabling VT-x\n");
virt->enable();
AsciiPrint("* VT-x enabled!\n");
}
for (;;) {}
return EFI_SUCCESS;
}