view boot/bootx64.c @ 21:e3accb15b1bb default tip

add alloc and loader.
author taiki
date Mon, 11 Feb 2013 04:30:42 +0900
parents 5e184d4c01b8
children
line wrap: on
line source

/* 
 * This program is EFI boot loader.
 * load Mach-O kernel, and locate on memory, and jump kernel.
 *
 * Author: Taiki TAIRA.
 */

#include "bootx64.h"
#include "mach-o/mach_o.h"

extern EFI_STATUS open(fs_interface_t *this, EFI_FILE_HANDLE *fd, CHAR16 *name); 
extern EFI_STATUS close(fs_t *fs, EFI_FILE_HANDLE *fd);
extern EFI_STATUS read(fs_t *fs, EFI_FILE_HANDLE *fd, VOID *buf, UINTN *size);
extern EFI_STATUS seek(fs_t *fs, EFI_FILE_HANDLE *fd, UINTN newpos);
extern EFI_STATUS load(fs_t *fs, EFI_FILE_HANDLE *fd, CHAR16 *kname);
extern EFI_STATUS config_fs(fs_t *fs,EFI_HANDLE boot_handle, dev_tab_t *boot_dev);

static inline void
start_kernel()
{
}

/* start cbc kernel boot loader. */

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

    EFI_LOADED_IMAGE *info;
    CHAR16 *kname = L"kernel";
    Print(L"Boot start. %s\n", kname);

    EFI_STATUS status = uefi_call_wrapper(BS->SetWatchdogTimer, 4, 0, 0x0, 0, NULL);
    if (EFI_ERROR(status)) return status;
    Print(L"Set watchdog timer.\n");

    status = uefi_call_wrapper(BS->HandleProtocol, 3, image, &LoadedImageProtocol, (VOID **) &info);
    if (EFI_ERROR(status)) {
        Print(L"Load error.\n");
        return EFI_LOAD_ERROR;
    }

    fs_t fs;
    dev_tab_t boot_dev;
    fs_interface_t fsi;
    
    status = config_fs(&fs, info->DeviceHandle ,&boot_dev);

    EFI_FILE_HANDLE fd;
    open(&fsi, &fd, kname);

    load(&fs, &fd, kname);

    close(&fs, &fd);

    UINTN cookie = 0;

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

    start_kernel();

    status = EFI_SUCCESS;
    return status;
}