changeset 0:8d0e5be5d742

test exit boot services
author taiki
date Tue, 19 Mar 2013 14:06:26 +0900
parents
children 259b5f0e03ba
files Makefile bootx64.c bootx64.c.0
diffstat 3 files changed, 178 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Makefile	Tue Mar 19 14:06:26 2013 +0900
@@ -0,0 +1,33 @@
+ARCH            = $(shell uname -m | sed s,i[3456789]86,ia32,)
+EFI_INCLUDE     = /usr/include/efi
+EFI_INCLUDES    = -I$(EFI_INCLUDE) -I$(EFI_INCLUDE)/$(ARCH) -I$(EFI_INCLUDE)/protocol
+EFI_PATH        = /usr/lib64/gnuefi
+EFI_LIB_PATH    = /usr/lib64
+LIB_GCC         = $(shell $(CC) -print-libgcc-file-name)
+EFI_LIBS        = -lefi -lgnuefi $(LIB_GCC)
+EFI_CRT_OBJS    = $(EFI_PATH)/crt0-efi-$(ARCH).o
+EFI_LDS         = $(EFI_PATH)/elf_$(ARCH)_efi.lds
+CFLAGS          = -O2 -g -mno-red-zone -fno-stack-protector -fno-strict-aliasing -fpic -fshort-wchar -fno-merge-constants -Wall -Werror $(EFI_INCLUDES)
+
+ifeq ($(ARCH),x86_64)
+	CFLAGS  += -DEFI_FUNCTION_WRAPPER
+endif
+
+LDFLAGS         = -nostdlib -znocombreloc -T $(EFI_LDS) -shared -Bsymbolic -L$(EFI_LIB_PATH) $(EFI_CRT_OBJS)
+TARGET          = bootx64.efi
+OBJS            = bootx64.o
+
+all: $(TARGET)
+
+bootx64.efi: $(OBJS)
+
+%.efi: %.o 
+	$(LD) $(LDFLAGS) $^ -o $@ $(EFI_LIBS)
+	objcopy -j .text -j .sdata -j .data \
+	-j .dynamic -j .dynsym  -j .rel \
+	-j .rela -j .reloc \
+	--target=efi-app-$(ARCH) $@ 
+	strip $@
+
+clean:
+	rm -f $(TARGET) $(OBJS)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bootx64.c	Tue Mar 19 14:06:26 2013 +0900
@@ -0,0 +1,85 @@
+#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;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bootx64.c.0	Tue Mar 19 14:06:26 2013 +0900
@@ -0,0 +1,60 @@
+#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");
+
+    EFI_STATUS status = EFI_SUCCESS;
+    UINTN size = 0;
+
+    status = uefi_call_wrapper(BS->LocateHandle, 5, ByProtocol, &FileSystemProtocol, NULL, &size, NULL);
+    if (size == 0) return EFI_UNSUPPORTED;
+
+    VOID *tmp = 0;
+    size = 10 * sizeof(EFI_HANDLE);
+    status = uefi_call_wrapper(BS->AllocatePool, 3, EfiLoaderData, size, &tmp);
+
+    if (EFI_SUCCESS != status) {
+        Print(L"can not allocate. %r\n", status);
+        return status;
+    }
+    Print(L"===success allocate.\n");
+
+    EFI_HANDLE *buffer = tmp;
+
+    Print(L"size is %d\n", size);
+    Print(L"ByProtocol %d\n", ByProtocol);
+    Print(L"size %d\n", size);
+    Print(L"buffer %d\n", buffer);
+
+
+    status = uefi_call_wrapper(BS->LocateHandle, 5, ByProtocol, &FileSystemProtocol, NULL, &size, buffer);
+    if (status != EFI_SUCCESS) {
+        Print(L"can not get handler %r\n", status);
+    }
+    /*
+    status = LibLocateHandle(ByProtocol, &FileSystemProtocol, NULL, &size, buffer);
+    if (status != EFI_SUCCESS) {
+        Print(L"can not get handler %r\n", status);
+        return status;
+    }
+    */
+
+    EFI_FILE_IO_INTERFACE *volume;
+    status = uefi_call_wrapper(BS->HandleProtocol, 3, *buffer, &FileSystemProtocol, (VOID **)&volume);
+    if (EFI_ERROR(status)) {
+        Print(L"can not get handle protocol");
+        return EFI_INVALID_PARAMETER;
+    }
+
+
+    while(1) {
+    }
+
+
+    return EFI_SUCCESS;
+}