view bootx64.c @ 0:8d0e5be5d742

test exit boot services
author taiki
date Tue, 19 Mar 2013 14:06:26 +0900
parents
children 259b5f0e03ba
line wrap: on
line source

#include <efi.h>
#include <efilib.h>

EFI_STATUS
efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *systab)
{
    InitializeLib(image, systab);

    Print(L"test start.\n");

    UINTN map_size, cookie, size, version;
    map_size = EFI_PAGE_SIZE * 2;
    EFI_MEMORY_DESCRIPTOR *md;

    EFI_STATUS status = uefi_call_wrapper(BS->AllocatePool, 3, EfiLoaderData, map_size, &md);

    if (EFI_ERROR(status)) {
        Print(L"error 'allocate pool' %r \n", status);
    }

    status = uefi_call_wrapper(BS->GetMemoryMap, 5, &map_size, md, &cookie, &size, &version);
    if (EFI_ERROR(status)) {
        Print(L"error 'get memory map' %r \n", status);
    }

    /*
    UINTN nr_map = map_size/size;

    UINTN i;
    for (i=0; i <nr_map ;i++) {
        EFI_MEMORY_DESCRIPTOR p = md[i];
        switch (p.Type) {
            case EfiReservedMemoryType:
                Print(L"| reserved memory.");
                break;
            case EfiLoaderCode:
                Print(L"| loader code.");
                break;
            case EfiLoaderData:
                Print(L"| loader data.");
                break;
            case EfiBootServicesCode:
                Print(L"| boot services code.");
                break;
            case EfiBootServicesData:
                Print(L"| boot services data.");
                break;
            case EfiConventionalMemory:
                Print(L"| conventional memory.");
                break;
            case EfiUnusableMemory:
                Print(L"| unusable memory.");
                break;
            case EfiACPIReclaimMemory:
                Print(L"| ACPI reclaim memory.");
                break;
            case EfiACPIMemoryNVS:
                Print(L"| ACPI memory NVS.");
                break;
            case EfiMemoryMappedIO:
                Print(L"| memory mapped IO.");
                break;
            case EfiMemoryMappedIOPortSpace:
                Print(L"| memory mapped IO port space.");
                break;
            case EfiPalCode:
                Print(L"| pal code. ");
                break;
            case EfiMaxMemoryType:
                Print(L"| max memory type.");
                break;
        }
    }
    */

    status = uefi_call_wrapper(BS->ExitBootServices, 2, image, cookie);

    if (EFI_ERROR(status)) {
        Print(L"error 'exit boot services' %r \n", status);
    }

    while(1) { }

    return EFI_SUCCESS;
}