Mercurial > hg > Members > taiki > EFIKernel
changeset 19:2fbe46f63d4c
separate source file.
author | taiki |
---|---|
date | Fri, 08 Feb 2013 19:12:05 +0900 |
parents | bd4c99e700e8 |
children | 5e184d4c01b8 |
files | boot/Makefile boot/bootx64.c boot/bootx64.efi boot/config.c |
diffstat | 4 files changed, 153 insertions(+), 157 deletions(-) [+] |
line wrap: on
line diff
--- a/boot/Makefile Thu Feb 07 06:11:26 2013 +0900 +++ b/boot/Makefile Fri Feb 08 19:12:05 2013 +0900 @@ -15,8 +15,7 @@ LDFLAGS = -nostdlib -znocombreloc -T $(EFI_LDS) -shared -Bsymbolic -L$(EFI_LIB_PATH) $(EFI_CRT_OBJS) TARGET = bootx64.efi -OBJS = bootx64.o - +OBJS = bootx64.o config.o all: $(TARGET)
--- a/boot/bootx64.c Thu Feb 07 06:11:26 2013 +0900 +++ b/boot/bootx64.c Fri Feb 08 19:12:05 2013 +0900 @@ -8,160 +8,6 @@ #include "bootx64.h" #include "mach-o/mach_o.h" -INTN -efi_error(CHAR16* error_massage, EFI_STATUS status) -{ - Print(L"%s", error_massage); - if (status < 0) return ERROR; - return SUCCESS; -} - -EFI_STATUS -open(CHAR16 *name, EFI_FILE_HANDLE *fd, fs_t *fs) -{ - EFI_STATUS status; - - if (name == NULL || fd == NULL) return EFI_INVALID_PARAMETER; - - status = uefi_call_wrapper(fs->volume->Open, 5, fs->volume, &fd, name, EFI_FILE_MODE_READ, (UINT64)0); - - return status; -} - -EFI_STATUS -close(fs_t *fs, EFI_FILE_HANDLE *fd) -{ - if (fs == NULL || fd == NULL) return EFI_INVALID_PARAMETER; - - return uefi_call_wrapper(fs->volume->Close, 1, fd); -} - -EFI_STATUS -read(fs_t *fs, EFI_FILE_HANDLE *fd, VOID *buf, UINTN *size) -{ - if (buf == NULL || fd == NULL || size == NULL) return EFI_INVALID_PARAMETER; - return uefi_call_wrapper(fs->volume->Read, 3, fd, size, buf); -} - -EFI_STATUS -seek(fs_t *fs, EFI_FILE_HANDLE fd, UINTN newpos) -{ - if (newpos <= 0 || fd == NULL || fs == NULL) return EFI_INVALID_PARAMETER; - return uefi_call_wrapper(fs->volume->SetPosition, 2, fd, newpos); -} - -EFI_STATUS -config_fs_one(EFI_HANDLE dev, VOID *fs) -{ - EFI_STATUS status; - EFI_FILE_IO_INTERFACE *volume; - EFI_FILE_HANDLE volume_fh; - EFI_GUID LocalFsProtocol = LOCALFS_PROTOCOL; - - status = uefi_call_wrapper(BS->HandleProtocol, 3, dev, &FileSystemProtocol, (VOID **)&volume); - if (EFI_ERROR(status)) return EFI_INVALID_PARAMETER; - - /* alloc */ - - status = uefi_call_wrapper(volume->OpenVolume, 2, volume, &volume_fh); - if (EFI_ERROR(status)) { - Print(L"Can not open volume.\n"); - return status; - } - Print(L"Open volume.\n"); - - fs_t *fs_tmp = (fs_t *)fs; - - SetMem(fs, sizeof(fs_t), 0); - - fs_tmp->dev = dev; - fs_tmp->volume = volume_fh; - - status = LibInstallProtocolInterfaces(&dev, &LocalFsProtocol, fs, NULL); - if (EFI_ERROR(status)) return status; - /* free */ - - return EFI_SUCCESS; -} - -EFI_STATUS -config_fs(EFI_HANDLE boot_handle, fs_t *fs, dev_tab_t *boot_dev) -{ - UINTN size = 0; - UINTN i; - EFI_GUID *proto = NULL; - - Print(L"configure filesystems for all volume. \n"); - - uefi_call_wrapper(BS->LocateHandle, 5, ByProtocol, &FileSystemProtocol, NULL, &size, NULL); - if (size == 0) return EFI_UNSUPPORTED; - - /* alloc */ - - dev_tab_t *dev_tab = NULL; // all devices - EFI_STATUS status = uefi_call_wrapper(BS->LocateHandle, 5, ByProtocol, &FileSystemProtocol, NULL, &size, (VOID **)dev_tab); - if (status != EFI_SUCCESS) { - efi_error(L"can't get handler.\n", status); - /* free */ - return status; - } - - UINTN ndev = size / sizeof(EFI_HANDLE); - - for (i = 0; i < ndev; i++) { - VOID *fs = NULL; - config_fs_one(dev_tab[i].dev, &fs); - dev_tab[i].fs = fs; - } - - status = uefi_call_wrapper(BS->LocateHandle, 5, ByProtocol, proto, NULL, &size, NULL); - if (EFI_ERROR(status)) { - Print(L"No useable filesystem found.\n"); - return status; - } - - /* alloc */ - - SetMem(proto, sizeof(EFI_HANDLE), 0); - - uefi_call_wrapper(BS->LocateHandle, 5, ByProtocol, &proto, NULL, &size, NULL); - - EFI_HANDLE *tab = NULL; - - SetMem(tab, size, 0); - - status = uefi_call_wrapper(BS->LocateHandle, 5, ByProtocol, proto, NULL, &size, tab); - if (status != EFI_SUCCESS) { - Print(L"faild to get handles\n"); - } - - size /= sizeof(EFI_HANDLE); - - UINTN idx = 0; - - for (i=0; i<size; i++) { - dev_tab[idx].dev = tab[i]; - if (tab[i] == boot_handle) boot_dev = dev_tab + idx; - idx++; - } - - return EFI_SUCCESS; -} - -EFI_STATUS -load(fs_t *fs, EFI_FILE_HANDLE *fd, CHAR16 *kname) -{ - VOID *buf = NULL; - UINTN size; - read(fs ,fd, buf, &size); - //seek(fs ,fd); - - - - return EFI_SUCCESS; -} - - static inline void start_kernel() { @@ -192,13 +38,14 @@ status = config_fs(info->DeviceHandle, &fs, &boot_dev); EFI_FILE_HANDLE fd; - open(kname, &fd, &fs); + open(&fs, &fd, kname); load(&fs, &fd, kname); close(&fs, &fd); UINTN cookie = 0; + uefi_call_wrapper(BS->ExitBootServices, 2, image, cookie); start_kernel();
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/boot/config.c Fri Feb 08 19:12:05 2013 +0900 @@ -0,0 +1,150 @@ +#include "bootx64.h" + + +EFI_STATUS +open(fs_t *fs, EFI_FILE_HANDLE *fd, CHAR16 *name) +{ + EFI_STATUS status; + + if (name == NULL || fd == NULL) return EFI_INVALID_PARAMETER; + + status = uefi_call_wrapper(fs->volume->Open, 5, fs->volume, &fd, name, EFI_FILE_MODE_READ, (UINT64)0); + + return status; +} + +EFI_STATUS +close(fs_t *fs, EFI_FILE_HANDLE *fd) +{ + if (fs == NULL || fd == NULL) return EFI_INVALID_PARAMETER; + + return uefi_call_wrapper(fs->volume->Close, 1, fd); +} + +EFI_STATUS +read(fs_t *fs, EFI_FILE_HANDLE *fd, VOID *buf, UINTN *size) +{ + if (buf == NULL || fd == NULL || size == NULL) return EFI_INVALID_PARAMETER; + return uefi_call_wrapper(fs->volume->Read, 3, fd, size, buf); +} + +EFI_STATUS +seek(fs_t *fs, EFI_FILE_HANDLE *fd, UINTN newpos) +{ + if (newpos <= 0 || fd == NULL || fs == NULL) return EFI_INVALID_PARAMETER; + return uefi_call_wrapper(fs->volume->SetPosition, 2, *fd, newpos); +} + + +EFI_STATUS +load(fs_t *fs, EFI_FILE_HANDLE *fd, CHAR16 *kname) +{ + VOID *buf = NULL; + UINTN size; + UINTN newpos = 0; + + + + + read(fs ,fd, buf, &size); + seek(fs ,fd, newpos); + + return EFI_SUCCESS; +} + +EFI_STATUS +config_fs_one(EFI_HANDLE dev, VOID *fs) +{ + EFI_STATUS status; + EFI_FILE_IO_INTERFACE *volume; + EFI_FILE_HANDLE volume_fh; + EFI_GUID LocalFsProtocol = LOCALFS_PROTOCOL; + + status = uefi_call_wrapper(BS->HandleProtocol, 3, dev, &FileSystemProtocol, (VOID **)&volume); + if (EFI_ERROR(status)) return EFI_INVALID_PARAMETER; + + /* alloc */ + + status = uefi_call_wrapper(volume->OpenVolume, 2, volume, &volume_fh); + if (EFI_ERROR(status)) { + Print(L"Can not open volume.\n"); + return status; + } + Print(L"Open volume.\n"); + + fs_t *fs_tmp = (fs_t *)fs; + + SetMem(fs, sizeof(fs_t), 0); + + fs_tmp->dev = dev; + fs_tmp->volume = volume_fh; + + status = LibInstallProtocolInterfaces(&dev, &LocalFsProtocol, fs, NULL); + if (EFI_ERROR(status)) return status; + /* free */ + + return EFI_SUCCESS; +} + +EFI_STATUS +config_fs(fs_t *fs, EFI_HANDLE boot_handle, dev_tab_t *boot_dev) +{ + UINTN i; + EFI_GUID *proto = NULL; + + Print(L"configure filesystems for all volume. \n"); + + UINTN size = 0; + uefi_call_wrapper(BS->LocateHandle, 5, ByProtocol, &FileSystemProtocol, NULL, &size, NULL); + if (size == 0) return EFI_UNSUPPORTED; + + Print(L"find device, size=%d\n", size); + + dev_tab_t *dev_tab = NULL; + + /* alloc */ + EFI_STATUS status = uefi_call_wrapper(BS->AllocatePool, 3, EfiLoaderData, size, (VOID **)dev_tab); + if (EFI_ERROR(status)) { + Print(L"can not allocate.\n"); + return status; + } + + UINTN ndev = size / sizeof(EFI_HANDLE); + + for (i = 0; i < ndev; i++) { + VOID *fs = NULL; + config_fs_one(dev_tab[i].dev, fs); + dev_tab[i].fs = fs; + } + + status = uefi_call_wrapper(BS->LocateHandle, 5, ByProtocol, proto, NULL, &size, NULL); + if (EFI_ERROR(status)) { + Print(L"No useable filesystem found.\n"); + return status; + } + + SetMem(proto, sizeof(EFI_HANDLE), 0); + + uefi_call_wrapper(BS->LocateHandle, 5, ByProtocol, &proto, NULL, &size, NULL); + + EFI_HANDLE *tab = NULL; + + SetMem(tab, size, 0); + + status = uefi_call_wrapper(BS->LocateHandle, 5, ByProtocol, proto, NULL, &size, tab); + if (status != EFI_SUCCESS) { + Print(L"faild to get handles\n"); + } + + size /= sizeof(EFI_HANDLE); + + UINTN idx = 0; + + for (i=0; i<size; i++) { + dev_tab[idx].dev = tab[i]; + if (tab[i] == boot_handle) boot_dev = dev_tab + idx; + idx++; + } + + return EFI_SUCCESS; +}