view bootx64.c @ 9:d6a8d676a1ac

add load kernel function, but the function don't have important process
author taiki
date Sun, 30 Mar 2014 01:41:35 +0900
parents b4db4b6c8d00
children 0c55588d01b0
line wrap: on
line source

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

#include "registers.h"

EFI_STATUS
load_kernel()
{
    Print(L"Start load kernel.\n");

    EFI_STATUS status;
    UINTN handle_count;
    EFI_HANDLE *handle_buffer;
    SIMPLE_READ_FILE read_handle = NULL;

    status = uefi_call_wrapper(BS->LocateHandleBuffer,
                5,
                ByProtocol,
                &FileSystemProtocol,
                NULL,
                &handle_count,
                &handle_buffer);

    if (EFI_ERROR(status)) {
        Print(L"LocateHandleBuffer is %r\n", status);
    }

    EFI_DEVICE_PATH *path;
    UINTN handle_idx = 0;

    for (handle_idx = 0; handle_idx < handle_count; handle_idx++) {
        EFI_HANDLE device_handle;

        //path = FileDevicePath(handle_buffer[handle_idx], kernel_image);

        if (!path) {
            status = EFI_NOT_FOUND;
            break;
        }

        status = OpenSimpleReadFile(TRUE, NULL, 0, &path, &device_handle, &read_handle);

        if (EFI_ERROR(status)) {
            FreePool(path);
            path = NULL;
        }
        break;
    }

    if (!EFI_ERROR(status)) {
        //status = LoadImage(read_handle);
    }

    if (read_handle) {
        CloseSimpleReadFile(read_handle);
    }

    if (path) {
        FreePool(path);
    }

    FreePool(handle_buffer);

    return status;
}

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

    InitializeLib(image, systab);

    uefi_call_wrapper(systab->ConOut->Reset, 2, systab->ConOut, FALSE);

    Print(L"---- start ----\n");

    EFI_STATUS status;
    
    Print(L"Open LoadedImage Protocol\n");
    status = uefi_call_wrapper(
        BS->OpenProtocol,
        6,
        image,
        &LoadedImageProtocol,
        (void **)&loaded_image,
        image,
        NULL,
        EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL);

    if (EFI_ERROR(status)) {
        Print(L"OpenProtocol is %r\n", status);
    }

    Print(L"%s\n", loaded_image->LoadOptions);

    load_kernel();


    Print(L"Close LoadedImage Protocol\n");
    status = uefi_call_wrapper(
        BS->CloseProtocol,
        4,
        image,
        &LoadedImageProtocol,
        image,
        NULL);

    if (EFI_ERROR(status)) {
        Print(L"CloseProtocol is %r\n", status);
    }

    Print(L"---- Faild start kernel ----\n");

    return EFI_SUCCESS;
}