[efi] Replace gnu-efi with a new UEFI lib
Change-Id: I31596603f884a9a373779f0f22ad53b4ce65353f
diff --git a/Makefile b/Makefile
index a4fcf0c..bf81490 100644
--- a/Makefile
+++ b/Makefile
@@ -11,8 +11,7 @@
EFI_AR := $(EFI_TOOLCHAIN)ar
EFI_PATH := third_party/gnu-efi
-EFI_LIB_PATHS := $(EFI_PATH)/$(ARCH)/lib $(EFI_PATH)/$(ARCH)/gnuefi out
-EFI_INC_PATHS := $(EFI_PATH)/inc $(EFI_PATH)/inc/$(ARCH) $(EFI_PATH)/inc/protocol
+EFI_LIB_PATHS := $(EFI_PATH)/$(ARCH)/gnuefi out
EFI_CRT0 := $(EFI_PATH)/$(ARCH)/gnuefi/crt0-efi-$(ARCH).o
EFI_LINKSCRIPT := $(EFI_PATH)/gnuefi/elf_$(ARCH)_efi.lds
@@ -20,16 +19,15 @@
EFI_CFLAGS := -fpic -fshort-wchar -fno-stack-protector -mno-red-zone
EFI_CFLAGS += -Wall
EFI_CFLAGS += -std=c99
-EFI_CFLAGS += -ffreestanding -nostdinc -Iinclude -Isrc -Ithird_party/edk2 -Ithird_party/lk/include
+EFI_CFLAGS += -ffreestanding -nostdinc -Iinclude -Isrc -Ithird_party/lk/include
EFI_CFLAGS += $(patsubst %,-I%,$(EFI_INC_PATHS))
-EFI_CFLAGS += -DHAVE_USE_MS_ABI=1
EFI_CFLAGS += -ggdb
EFI_LDFLAGS := -nostdlib -znocombreloc -T $(EFI_LINKSCRIPT)
EFI_LDFLAGS += -shared -Bsymbolic
EFI_LDFLAGS += $(patsubst %,-L%,$(EFI_LIB_PATHS))
-EFI_LIBS := -lutils -lefi -lgnuefi
+EFI_LIBS := -lutils -lgnuefi
what_to_build:: all
@@ -58,6 +56,7 @@
endif
LIB_SRCS := \
+ lib/efi/guids.c \
lib/utils.c \
lib/loadfile.c \
lib/console-printf.c \
diff --git a/include/efi/boot-services.h b/include/efi/boot-services.h
new file mode 100644
index 0000000..3ee9ec5
--- /dev/null
+++ b/include/efi/boot-services.h
@@ -0,0 +1,204 @@
+// Copyright 2016 The Fuchsia Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#pragma once
+
+#include <efi/types.h>
+#include <efi/protocol/device-path.h>
+
+#define EFI_BOOT_SERVICES_SIGNATURE 0x56524553544f4f42
+#define EFI_BOOT_SERVICES_REVISION EFI_SPECIFICATION_VERSION
+
+typedef size_t efi_tpl;
+
+#define TPL_APPLICATION 4
+#define TPL_CALLBACK 8
+#define TPL_NOTIFY 16
+#define TPL_HIGH_LEVEL 31
+
+typedef enum {
+ AllocateAnyPages,
+ AllocateMaxAddress,
+ AllocateAddress,
+ MaxAllocateType
+} efi_allocate_type;
+
+typedef struct {
+ uint32_t Type;
+ efi_physical_addr PhysicalStart;
+ efi_virtual_addr VirtualStart;
+ uint64_t NumberOfPages;
+ uint64_t Attribute;
+} efi_memory_descriptor;
+
+#define EFI_MEMORY_UC 0x0000000000000001
+#define EFI_MEMORY_WC 0x0000000000000002
+#define EFI_MEMORY_WT 0x0000000000000004
+#define EFI_MEMORY_WB 0x0000000000000008
+#define EFI_MEMORY_UCE 0x0000000000000010
+#define EFI_MEMORY_WP 0x0000000000001000
+#define EFI_MEMORY_RP 0x0000000000002000
+#define EFI_MEMORY_XP 0x0000000000004000
+#define EFI_MEMORY_NV 0x0000000000008000
+#define EFI_MEMORY_MORE_RELIABLE 0x0000000000010000
+#define EFI_MEMORY_RO 0x0000000000020000
+#define EFI_MEMORY_RUNTIME 0x8000000000000000
+
+#define EFI_MEMORY_DESCRIPTOR_VERSION 1
+
+typedef enum {
+ EFI_NATIVE_INTERFACE
+} efi_interface_type;
+
+typedef enum {
+ AllHandles,
+ ByRegisterNotify,
+ ByProtocol
+} efi_locate_search_type;
+
+#define EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL 0x00000001
+#define EFI_OPEN_PROTOCOL_GET_PROTOCOL 0x00000002
+#define EFI_OPEN_PROTOCOL_TEST_PROTOCOL 0x00000004
+#define EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER 0x00000008
+#define EFI_OPEN_PROTOCOL_BY_DRIVER 0x00000010
+#define EFI_OPEN_PROTOCOL_EXCLUSIVE 0x00000020
+
+typedef struct {
+ efi_handle agent_handle;
+ efi_handle controller_handle;
+ uint32_t attributes;
+ uint32_t open_count;
+} efi_open_protocol_information_entry;
+
+#define EFI_HII_PACKAGE_LIST_PROTOCOL_GUID \
+ {0x6a1ee763, 0xd47a, 0x43b4, {0xaa, 0xbe, 0xef, 0x1d, 0xe2, 0xab, 0x56, 0xfc}}
+
+typedef struct efi_hii_package_list_header efi_hii_package_list_header;
+typedef efi_hii_package_list_header* efi_hii_package_list_protocol;
+
+// fwd declare efi_system_table to break circular dependencies
+typedef struct efi_system_table efi_system_table;
+typedef efi_status (*efi_image_entry_point) (efi_handle img, efi_system_table* sys) EFIAPI;
+
+typedef struct {
+ efi_table_header Hdr;
+
+ efi_tpl (*RaiseTPL) (efi_tpl new_tpl) EFIAPI;
+
+ void (*RestoreTPL) (efi_tpl old_tpl) EFIAPI;
+
+ efi_status (*AllocatePages) (efi_allocate_type type, efi_memory_type memory_type,
+ size_t pages, efi_physical_addr* memory) EFIAPI;
+
+ efi_status (*FreePages) (efi_physical_addr memory, size_t pages) EFIAPI;
+
+ efi_status (*GetMemoryMap) (size_t* memory_map_size, efi_memory_descriptor* memory_map,
+ size_t* map_key, size_t* desc_size, uint32_t* desc_version) EFIAPI;
+
+ efi_status (*AllocatePool) (efi_memory_type pool_type, size_t size, void** buf) EFIAPI;
+
+ efi_status (*FreePool) (void* buf) EFIAPI;
+
+ efi_status (*CreateEvent) (uint32_t type, efi_tpl notify_tpl,
+ efi_event_notify notify_fn, void* notify_ctx,
+ efi_event* event) EFIAPI;
+
+ efi_status (*SetTimer) (efi_event event, efi_timer_delay type, uint64_t trigger_time) EFIAPI;
+
+ efi_status (*WaitForEvent) (size_t num_events, efi_event* event, size_t* index) EFIAPI;
+
+ efi_status (*SignalEvent) (efi_event event) EFIAPI;
+
+ efi_status (*CloseEvent) (efi_event event) EFIAPI;
+
+ efi_status (*CheckEvent) (efi_event event) EFIAPI;
+
+ efi_status (*InstallProtocolInterface) (efi_handle* handle, efi_guid* protocol,
+ efi_interface_type intf_type, void* intf) EFIAPI;
+
+ efi_status (*ReinstallProtocolInterface) (efi_handle hadle, efi_guid* protocol,
+ void* old_intf, void* new_intf) EFIAPI;
+
+ efi_status (*UninstallProtocolInterface) (efi_handle handle, efi_guid* protocol,
+ void* intf) EFIAPI;
+
+ efi_status (*HandleProtocol) (efi_handle handle, efi_guid* protocol, void** intf) EFIAPI;
+
+ void* Reserved;
+
+ efi_status (*RegisterProtocolNotify) (efi_guid* protocol, efi_event event,
+ void** registration) EFIAPI;
+
+ efi_status (*LocateHandle) (efi_locate_search_type search_type, efi_guid* protocol,
+ void* search_key, size_t* buf_size, efi_handle* buf) EFIAPI;
+
+ efi_status (*LocateDevicePath) (efi_guid* protocol, efi_device_path_protocol** path,
+ efi_handle* device) EFIAPI;
+
+ efi_status (*InstallConfigurationTable) (efi_guid* guid, void* table) EFIAPI;
+
+ efi_status (*LoadImage) (bool boot_policy, efi_handle parent_image_handle,
+ efi_device_path_protocol* path, void* src, size_t src_size,
+ efi_handle* image_handle) EFIAPI;
+
+ efi_status (*StartImage) (efi_handle image_handle, size_t* exit_data_size,
+ char16_t** exit_data) EFIAPI;
+
+ efi_status (*Exit) (efi_handle image_handle, efi_status exit_status,
+ size_t exit_data_size, char16_t* exit_data) EFIAPI;
+
+ efi_status (*UnloadImage) (efi_handle image_handle) EFIAPI;
+
+ efi_status (*ExitBootServices) (efi_handle image_handle, size_t map_key) EFIAPI;
+
+ efi_status (*GetNextMonotonicCount) (uint64_t* count) EFIAPI;
+
+ efi_status (*Stall) (size_t microseconds) EFIAPI;
+
+ efi_status (*SetWatchdogTimer) (size_t timeout, uint64_t watchdog_code,
+ size_t data_size, char16_t* watchdog_data) EFIAPI;
+
+ efi_status (*ConnectController) (efi_handle controller_handle,
+ efi_handle* driver_image_handle,
+ efi_device_path_protocol* remaining_path,
+ bool recursive) EFIAPI;
+
+ efi_status (*DisconnectController) (efi_handle controller_handle,
+ efi_handle driver_image_handle,
+ efi_handle child_handle) EFIAPI;
+
+ efi_status (*OpenProtocol) (efi_handle handle, efi_guid* protocol, void** intf,
+ efi_handle agent_handle, efi_handle controller_handle,
+ uint32_t attributes) EFIAPI;
+
+ efi_status (*CloseProtocol) (efi_handle handle, efi_guid* protocol,
+ efi_handle agent_handle, efi_handle controller_handle) EFIAPI;
+
+ efi_status (*OpenProtocolInformation) (efi_handle handle, efi_guid* protocol,
+ efi_open_protocol_information_entry** entry_buf,
+ size_t* entry_count) EFIAPI;
+
+ efi_status (*ProtocolsPerHandle) (efi_handle handle, efi_guid*** protocol_buf,
+ size_t* protocol_buf_count) EFIAPI;
+
+ efi_status (*LocateHandleBuffer) (efi_locate_search_type search_type,
+ efi_guid* protocol, void* search_key,
+ size_t* num_handles, efi_handle** buf) EFIAPI;
+
+ efi_status (*LocateProtocol) (efi_guid* protocol, void* registration, void** intf) EFIAPI;
+
+ efi_status (*InstallMultipleProtocolInterfaces) (efi_handle* handle, ...) EFIAPI;
+
+ efi_status (*UninstallMultipleProtocolInterfaces) (efi_handle handle, ...) EFIAPI;
+
+ efi_status (*CalculateCrc32) (void* data, size_t len, uint32_t* crc32) EFIAPI;
+
+ void (*CopyMem) (void* dest, void* src, size_t len) EFIAPI;
+
+ void (*SetMem) (void* buf, size_t len, uint8_t val) EFIAPI;
+
+ efi_status (*CreateEventEx) (uint32_t type, efi_tpl notify_tpl,
+ efi_event_notify notify_fn, const void* notify_ctx,
+ const efi_guid* event_group, efi_event* event) EFIAPI;
+} efi_boot_services;
diff --git a/include/efi/protocol/device-path-to-text.h b/include/efi/protocol/device-path-to-text.h
new file mode 100644
index 0000000..a19e2ab
--- /dev/null
+++ b/include/efi/protocol/device-path-to-text.h
@@ -0,0 +1,20 @@
+// Copyright 2016 The Fuchsia Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#pragma once
+
+#include <efi/types.h>
+#include <efi/protocol/device-path.h>
+
+#define EFI_DEVICE_PATH_TO_TEXT_PROTOCOL_GUID \
+ {0x8b843e20, 0x8132, 0x4852, {0x90, 0xcc, 0x55, 0x1a, 0x4e, 0x4a, 0x7f, 0x1c}}
+extern efi_guid DevicePathToTextProtocol;
+
+typedef struct efi_device_path_to_text_protocol {
+ char16_t* (*ConvertDeviceNodeToText) (const efi_device_path_protocol* dev_node,
+ bool display_only, bool allow_shortcuts) EFIAPI;
+
+ char16_t* (*ConvertDevicePathToText) (const efi_device_path_protocol* dev_path,
+ bool display_only, bool allow_shortcuts) EFIAPI;
+} efi_device_path_to_text_protocol;
diff --git a/include/efi/protocol/device-path.h b/include/efi/protocol/device-path.h
new file mode 100644
index 0000000..8356c28
--- /dev/null
+++ b/include/efi/protocol/device-path.h
@@ -0,0 +1,45 @@
+// Copyright 2016 The Fuchsia Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#pragma once
+
+#include <efi/types.h>
+
+#define EFI_DEVICE_PATH_PROTOCOL_GUID \
+ {0x09576e91, 0x6d3f, 0x11d2, {0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b}}
+extern efi_guid DevicePathProtocol;
+
+typedef struct efi_device_path_protocol {
+ uint8_t Type;
+ uint8_t SubType;
+ uint8_t Length[2];
+} efi_device_path_protocol;
+
+#define DEVICE_PATH_HARDWARE 0x01
+#define DEVICE_PATH_ACPI 0x02
+#define DEVICE_PATH_MESSAGING 0x03
+#define DEVICE_PATH_MEDIA 0x04
+#define DEVICE_PATH_BIOS_BOOT_SPEC 0x05
+#define DEVICE_PATH_END 0x7f
+
+#define DEVICE_PATH_INSTANCE_END 0x01
+#define DEVICE_PATH_ENTIRE_END 0xff
+
+#define DEVICE_PATH_HW_PCI 0x01
+#define DEVICE_PATH_HW_PCCARD 0x02
+#define DEVICE_PATH_HW_MEMMAP 0x03
+#define DEVICE_PATH_HW_VENDOR 0x04
+#define DEVICE_PATH_HW_CONTROLLER 0x05
+#define DEVICE_PATH_HW_BMC 0x06
+
+// TODO: sub-types for other types (ACPI, etc)
+
+// TODO: move this to another header? would break circular dependencies between
+// boot-services.h and this header, for efi_memory_type
+typedef struct {
+ efi_device_path_protocol Header;
+ efi_memory_type MemoryType;
+ efi_physical_addr StartAddress;
+ efi_physical_addr EndAddress;
+} efi_device_path_hw_memmap;
diff --git a/include/efi/protocol/driver-binding.h b/include/efi/protocol/driver-binding.h
new file mode 100644
index 0000000..bd928ac
--- /dev/null
+++ b/include/efi/protocol/driver-binding.h
@@ -0,0 +1,30 @@
+// Copyright 2016 The Fuchsia Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#pragma once
+
+#include <efi/types.h>
+#include <efi/protocol/device-path.h>
+
+#define EFI_DRIVER_BINDING_PROTOCOL_GUID \
+ {0x18a031ab, 0xb443, 0x4d1a, {0xa5, 0xc0, 0x0c, 0x09, 0x26, 0x1e, 0x9f, 0x71}}
+extern efi_guid DriverBindingProtocol;
+
+typedef struct efi_driver_binding_protocol {
+ efi_status (*Supported) (struct efi_driver_binding_protocol* self,
+ efi_handle controller_handle,
+ efi_device_path_protocol* remaining_path) EFIAPI;
+
+ efi_status (*Start) (struct efi_driver_binding_protocol* self,
+ efi_handle controller_handle,
+ efi_device_path_protocol* remaining_path) EFIAPI;
+
+ efi_status (*Stop) (struct efi_driver_binding_protocol* self,
+ efi_handle controller_handle,
+ size_t num_children, efi_handle* child_handle_buf) EFIAPI;
+
+ uint32_t Version;
+ efi_handle ImageHandle;
+ efi_handle DriverBindingHandle;
+} efi_driver_binding_protocol;
diff --git a/include/efi/protocol/file.h b/include/efi/protocol/file.h
new file mode 100644
index 0000000..5477bc6
--- /dev/null
+++ b/include/efi/protocol/file.h
@@ -0,0 +1,97 @@
+// Copyright 2016 The Fuchsia Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#pragma once
+
+#include <efi/types.h>
+#include <efi/boot-services.h>
+#include <efi/runtime-services.h>
+
+#define EFI_FILE_PROTOCOL_REVISION 0x00010000
+#define EFI_FILE_PROTOCOL_REVISION2 0x00020000
+#define EFI_FILE_PROTOCOL_LATEST_REVISION EFI_FILE_PROTOCOL_REVISION2
+
+#define EFI_FILE_MODE_READ 0x0000000000000001
+#define EFI_FILE_MODE_WRITE 0x0000000000000002
+#define EFI_FILE_MODE_CREATE 0x8000000000000000
+
+#define EFI_FILE_READ_ONLY 0x0000000000000001
+#define EFI_FILE_HIDDEN 0x0000000000000002
+#define EFI_FILE_SYSTEM 0x0000000000000004
+#define EFI_FILE_RESERVED 0x0000000000000008
+#define EFI_FILE_DIRECTORY 0x0000000000000010
+#define EFI_FILE_ARCHIVE 0x0000000000000020
+#define EFI_FILE_VALID_ATTR 0x0000000000000037
+
+typedef struct {
+ efi_event Event;
+ efi_status Status;
+ size_t BufferSize;
+ void* Buffer;
+} efi_file_io_token;
+
+#define EFI_FILE_INFO_GUID \
+ {0x09576e92, 0x6d3f, 0x11d2, {0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b}}
+extern efi_guid FileInfoGuid;
+
+typedef struct {
+ uint64_t Size;
+ uint64_t FileSize;
+ uint64_t PhysicalSize;
+ efi_time CreateTime;
+ efi_time LastAccessTime;
+ efi_time ModificationTime;
+ uint64_t Attribute;
+ char16_t FileName[];
+} efi_file_info;
+
+#define EFI_FILE_SYSTEM_INFO_GUID \
+ {0x09576e93, 0x6d3f, 0x11d2, {0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b}}
+extern efi_guid FileSystemInfoGuid;
+
+typedef struct {
+ uint64_t Size;
+ bool ReadOnly;
+ uint64_t VolumeSize;
+ uint64_t FreeSpace;
+ uint32_t BlockSize;
+ char16_t* VolumeLabel[];
+} efi_file_system_info;
+
+typedef struct efi_file_protocol {
+ uint64_t Revision;
+
+ efi_status (*Open) (struct efi_file_protocol* self, struct efi_file_protocol** new_handle,
+ char16_t* filename, uint64_t open_mode, uint64_t attributes) EFIAPI;
+
+ efi_status (*Close) (struct efi_file_protocol* self) EFIAPI;
+
+ efi_status (*Delete) (struct efi_file_protocol* self) EFIAPI;
+
+ efi_status (*Read) (struct efi_file_protocol* self, size_t* len, void* buf) EFIAPI;
+
+ efi_status (*Write) (struct efi_file_protocol* self, size_t* len, void* buf) EFIAPI;
+
+ efi_status (*GetPosition) (struct efi_file_protocol* self, uint64_t* position) EFIAPI;
+
+ efi_status (*SetPosition) (struct efi_file_protocol* self, uint64_t position) EFIAPI;
+
+ efi_status (*GetInfo) (struct efi_file_protocol* self, efi_guid* info_type,
+ size_t* buf_size, void* buf) EFIAPI;
+
+ efi_status (*SetInfo) (struct efi_file_protocol* self, efi_guid* info_type,
+ size_t buf_size, void* buf) EFIAPI;
+
+ efi_status (*Flush) (struct efi_file_protocol* self) EFIAPI;
+
+ efi_status (*OpenEx) (struct efi_file_protocol* self, struct efi_file_protocol* new_handle,
+ char16_t* filename, uint64_t open_mode, uint64_t attributes,
+ efi_file_io_token* token) EFIAPI;
+
+ efi_status (*ReadEx) (struct efi_file_protocol* self, efi_file_io_token* token) EFIAPI;
+
+ efi_status (*WriteEx) (struct efi_file_protocol* self, efi_file_io_token* token) EFIAPI;
+
+ efi_status (*FlushEx) (struct efi_file_protocol* self, efi_file_io_token* token) EFIAPI;
+} efi_file_protocol;
diff --git a/include/efi/protocol/graphics-output.h b/include/efi/protocol/graphics-output.h
new file mode 100644
index 0000000..772cf06
--- /dev/null
+++ b/include/efi/protocol/graphics-output.h
@@ -0,0 +1,76 @@
+// Copyright 2016 The Fuchsia Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#pragma once
+
+#include <efi/types.h>
+
+#define EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID \
+ {0x9042a9de, 0x23dc, 0x4a38, {0x96, 0xfb, 0x7a, 0xde, 0xd0, 0x80, 0x51, 0x6a}}
+extern efi_guid GraphicsOutputProtocol;
+
+typedef struct {
+ uint32_t RedMask;
+ uint32_t GreenMask;
+ uint32_t BlueMask;
+ uint32_t ReservedMask;
+} efi_pixel_bitmask;
+
+typedef enum {
+ PixelRedGreenBlueReserved8BitPerColor,
+ PixelBlueGreenRedReserved8BitPerColor,
+ PixelBitMask,
+ PixelBltOnly,
+ PixelFormatMax
+} efi_graphics_pixel_format;
+
+typedef struct {
+ uint32_t Version;
+ uint32_t HorizontalResolution;
+ uint32_t VerticalResolution;
+ efi_graphics_pixel_format PixelFormat;
+ efi_pixel_bitmask PixelInformation;
+ uint32_t PixelsPerScanLine;
+} efi_graphics_output_mode_information;
+
+typedef struct {
+ uint32_t MaxMode;
+ uint32_t Mode;
+ efi_graphics_output_mode_information* Info;
+ size_t SizeOfInfo;
+ efi_physical_addr FrameBufferBase;
+ size_t FrameBufferSize;
+} efi_graphics_output_mode;
+
+typedef struct {
+ uint8_t Blue;
+ uint8_t Green;
+ uint8_t Red;
+ uint8_t Reserved;
+} efi_graphics_output_blt_pixel;
+
+typedef enum {
+ EfiBltVideoFill,
+ EfiBltVideoToBltBuffer,
+ EfiBltBufferToVideo,
+ EfiBltVideoToVideo,
+ EfiGraphicsOutputBltOperationMax
+} efi_graphics_output_blt_operation;
+
+typedef struct efi_graphics_output_protocol {
+ efi_status (*QueryMode) (struct efi_graphics_output_protocol* self,
+ uint32_t mode_num, size_t* info_len,
+ efi_graphics_output_mode_information** info) EFIAPI;
+
+ efi_status (*SetMode) (struct efi_graphics_output_protocol* self,
+ uint32_t mode_num) EFIAPI;
+
+ efi_status (*Blt) (struct efi_graphics_output_protocol* self,
+ efi_graphics_output_blt_pixel* blt_buf,
+ efi_graphics_output_blt_operation blt_operation,
+ size_t src_x, size_t src_y, size_t dest_x, size_t dest_y,
+ size_t width, size_t height, size_t delta) EFIAPI;
+
+ efi_graphics_output_mode* Mode;
+} efi_graphics_output_protocol;
diff --git a/include/efi/protocol/loaded-image.h b/include/efi/protocol/loaded-image.h
new file mode 100644
index 0000000..800d269
--- /dev/null
+++ b/include/efi/protocol/loaded-image.h
@@ -0,0 +1,32 @@
+// Copyright 2016 The Fuchsia Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#pragma once
+
+#include <efi/types.h>
+#include <efi/system-table.h>
+#include <efi/protocol/device-path.h>
+
+#define EFI_LOADED_IMAGE_PROTOCOL_GUID \
+ {0x5b1b31a1, 0x9562, 0x11d2, {0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b}}
+extern efi_guid LoadedImageProtocol;
+
+#define EFI_LOADED_IMAGE_PROTOCOL_REVISION 0x1000
+
+typedef struct {
+ uint32_t Revision;
+ efi_handle ParentHandle;
+ efi_system_table* SystemTable;
+ efi_handle DeviceHandle;
+ efi_device_path_protocol* FilePath;
+ void* Reserved;
+ uint32_t LoadOptionsSize;
+ void* LoadOptions;
+ void* ImageBase;
+ uint64_t ImageSize;
+ efi_memory_type ImageCodeType;
+ efi_memory_type ImageDataType;
+
+ efi_status (*Unload) (efi_handle img) EFIAPI;
+} efi_loaded_image_protocol;
diff --git a/include/efi/protocol/managed-network.h b/include/efi/protocol/managed-network.h
index e9aafc3..2147054 100644
--- a/include/efi/protocol/managed-network.h
+++ b/include/efi/protocol/managed-network.h
@@ -4,106 +4,89 @@
#pragma once
-#include <efi.h>
+#include <efi/types.h>
+#include <efi/protocol/simple-network.h>
#define EFI_MANAGED_NETWORK_PROTOCOL_GUID \
{0x7ab33a91, 0xace5, 0x4326,{0xb5, 0x72, 0xe7, 0xee, 0x33, 0xd3, 0x9f, 0x16}}
-
-EFI_GUID ManagedNetworkProtocol = EFI_MANAGED_NETWORK_PROTOCOL_GUID;
-
-struct _EFI_MANAGED_NETWORK_PROTOCOL;
+extern efi_guid ManagedNetworkProtocol;
typedef struct {
- EFI_TIME Timestamp;
- EFI_EVENT RecycleEvent;
- UINT32 PacketLength;
- UINT32 HeaderLength;
- UINT32 AddressLength;
- UINT32 DataLength;
- BOOLEAN BroadcastFlag;
- BOOLEAN MulticastFlag;
- BOOLEAN PromiscuousFlag;
- UINT16 ProtocolType;
- VOID *DestinationAddress;
- VOID *SourceAddress;
- VOID *MediaHeader;
- VOID *PacketData;
-} EFI_MANAGED_NETWORK_RECEIVE_DATA;
+ efi_time Timestamp;
+ efi_event RecycleEvent;
+ uint32_t PacketLength;
+ uint32_t HeaderLength;
+ uint32_t AddressLength;
+ uint32_t DataLength;
+ bool BroadcastFlag;
+ bool MulticastFlag;
+ bool PromiscuousFlag;
+ uint16_t ProtocolType;
+ void* DestinationAddress;
+ void* SourceAddress;
+ void* MediaHeader;
+ void* PacketData;
+} efi_managed_network_receive_data;
typedef struct {
- UINT32 FragmentLength;
- VOID *FragmentBuffer;
-} EFI_MANAGED_NETWORK_FRAGMENT_DATA;
+ uint32_t FragmentLength;
+ void* FragmentBuffer;
+} efi_managed_network_fragment_data;
typedef struct {
- EFI_MAC_ADDRESS *DestinationAddress;
- EFI_MAC_ADDRESS *SourceAddress;
- UINT16 ProtocolType;
- UINT32 DataLength;
- UINT16 HeaderLength;
- UINT16 FragmentCount;
- EFI_MANAGED_NETWORK_FRAGMENT_DATA FragmentTable[1];
-} EFI_MANAGED_NETWORK_TRANSMIT_DATA;
+ efi_mac_addr* DestinationAddress;
+ efi_mac_addr* SourceAddress;
+ uint16_t ProtocolType;
+ uint32_t DataLength;
+ uint16_t HeaderLength;
+ uint16_t FragmentCount;
+ efi_managed_network_fragment_data FragmentTable[1];
+} efi_managed_network_transmit_data;
typedef struct {
- EFI_EVENT Event;
- EFI_STATUS Status;
+ uint32_t ReceivedQueueTimeoutValue;
+ uint32_t TransmitQueueTimeoutValue;
+ uint16_t ProtocolTypeFilter;
+ bool EnableUnicastReceive;
+ bool EnableMulticastReceive;
+ bool EnableBroadcastReceive;
+ bool EnablePromiscuousReceive;
+ bool FlushQueuesOnReset;
+ bool EnableReceiveTimestamps;
+ bool DisableBackgroundPolling;
+} efi_managed_network_config_data;
+
+typedef struct {
+ efi_event Event;
+ efi_status Status;
union {
- EFI_MANAGED_NETWORK_RECEIVE_DATA *RxData;
- EFI_MANAGED_NETWORK_TRANSMIT_DATA *TxData;
+ efi_managed_network_receive_data* RxData;
+ efi_managed_network_transmit_data* TxData;
} Packet;
-} EFI_MANAGED_NETWORK_COMPLETION_TOKEN;
+} efi_managed_network_completion_token;
-typedef EFI_STATUS (EFIAPI *EFI_MANAGED_NETWORK_GET_MODE_DATA) (
- IN struct _EFI_MANAGED_NETWORK_PROTOCOL *This,
- OUT EFI_MANAGED_NETWORK_CONFIG_DATA *MnpConfigData OPTIONAL,
- OUT EFI_SIMPLE_NETWORK_MODE *SnpModeData OPTIONAL
-);
+typedef struct efi_managed_network_protocol {
+ efi_status (*GetModeData) (struct efi_managed_network_protocol* self,
+ efi_managed_network_config_data* mnp_config_data,
+ efi_simple_network_mode* snp_mode_data) EFIAPI;
-typedef EFI_STATUS (EFIAPI *EFI_MANAGED_NETWORK_CONFIGURE) (
- IN struct _EFI_MANAGED_NETWORK_PROTOCOL *This,
- IN EFI_MANAGED_NETWORK_CONFIG_DATA *MnpConfigData OPTIONAL
-);
+ efi_status (*Configure) (struct efi_managed_network_protocol* self,
+ efi_managed_network_config_data* mnp_config_data) EFIAPI;
-typedef EFI_STATUS (EFIAPI *EFI_MANAGED_NETWORK_MCAST_IP_TO_MAC) (
- IN struct _EFI_MANAGED_NETWORK_PROTOCOL *This,
- IN BOOLEAN Ipv6Flag,
- IN EFI_IP_ADDRESS *IpAddress,
- OUT EFI_MAC_ADDRESS *MacAddress
-);
+ efi_status (*McastIpToMac) (struct efi_managed_network_protocol* self,
+ bool ipv6_flag, efi_ip_addr* ip_addr, efi_mac_addr* mac_addr) EFIAPI;
-typedef EFI_STATUS (EFIAPI *EFI_MANAGED_NETWORK_GROUPS) (
- IN struct _EFI_MANAGED_NETWORK_PROTOCOL *This,
- IN BOOLEAN JoinFlag,
- IN EFI_MAC_ADDRESS *MacAddress OPTIONAL
-);
+ efi_status (*Groups) (struct efi_managed_network_protocol* self, bool join_flag,
+ efi_mac_addr* mac_addr) EFIAPI;
-typedef EFI_STATUS (EFIAPI *EFI_MANAGED_NETWORK_TRANSMIT) (
- IN struct _EFI_MANAGED_NETWORK_PROTOCOL *This,
- IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token
-);
+ efi_status (*Transmit) (struct efi_managed_network_protocol* self,
+ efi_managed_network_completion_token* token) EFIAPI;
-typedef EFI_STATUS (EFIAPI *EFI_MANAGED_NETWORK_RECEIVE) (
- IN struct _EFI_MANAGED_NETWORK_PROTOCOL *This,
- IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token
-);
+ efi_status (*Receive) (struct efi_managed_network_protocol* self,
+ efi_managed_network_completion_token* token) EFIAPI;
-typedef EFI_STATUS (EFIAPI *EFI_MANAGED_NETWORK_CANCEL)(
- IN struct _EFI_MANAGED_NETWORK_PROTOCOL *This,
- IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token OPTIONAL
-);
+ efi_status (*Cancel) (struct efi_managed_network_protocol* self,
+ efi_managed_network_completion_token* token) EFIAPI;
-typedef EFI_STATUS (EFIAPI *EFI_MANAGED_NETWORK_POLL) (
- IN struct _EFI_MANAGED_NETWORK_PROTOCOL *This
-);
-
-typedef struct _EFI_MANAGED_NETWORK {
- EFI_MANAGED_NETWORK_GET_MODE_DATA GetModeData;
- EFI_MANAGED_NETWORK_CONFIGURE Configure;
- EFI_MANAGED_NETWORK_MCAST_IP_TO_MAC McastIpToMac;
- EFI_MANAGED_NETWORK_GROUPS Groups;
- EFI_MANAGED_NETWORK_TRANSMIT Transmit;
- EFI_MANAGED_NETWORK_RECEIVE Receive;
- EFI_MANAGED_NETWORK_CANCEL Cancel;
- EFI_MANAGED_NETWORK_POLL Poll;
-} EFI_MANAGED_NETWORK;
+ efi_status (*Poll) (struct efi_managed_network_protocol* self) EFIAPI;
+} efi_managed_network_protocol;
diff --git a/include/efi/protocol/pci-root-bridge-io.h b/include/efi/protocol/pci-root-bridge-io.h
index 3e66ce2..1e54f89 100644
--- a/include/efi/protocol/pci-root-bridge-io.h
+++ b/include/efi/protocol/pci-root-bridge-io.h
@@ -4,14 +4,12 @@
#pragma once
-#include <efi.h>
+#include <efi/boot-services.h>
+#include <efi/types.h>
#define EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_GUID \
{0x2f707ebb, 0x4a1a, 0x11D4, {0x9a, 0x38, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d}}
-
-EFI_GUID PciRootBridgeIoProtocol = EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_GUID;
-
-struct _EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL;
+extern efi_guid PciRootBridgeIoProtocol;
typedef enum {
EfiPciWidthUint8,
@@ -27,30 +25,18 @@
EfiPciWidthFillUint32,
EfiPciWidthFillUint64,
EfiPciWidthMaximum,
-} EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH;
+} efi_pci_root_bridge_io_width;
-typedef EFI_STATUS (EFIAPI *EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_POLL_IO_MEM) (
- IN struct _EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
- IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,
- IN UINT64 Address,
- IN UINT64 Mask,
- IN UINT64 Value,
- IN UINT64 Delay,
- OUT UINT64 *Result
-);
-
-typedef EFI_STATUS (EFIAPI *EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_IO_MEM) (
- IN struct _EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
- IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,
- IN UINT64 Address,
- IN UINTN Count,
- IN OUT VOID *Buffer
-);
+struct efi_pci_root_bridge_io_protocol;
typedef struct {
- EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_IO_MEM Read;
- EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_IO_MEM Write;
-} EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_ACCESS;
+ efi_status (*Read) (struct efi_pci_root_bridge_io_protocol* self,
+ efi_pci_root_bridge_io_width width,
+ uint64_t addr, size_t count, void* buffer) EFIAPI;
+ efi_status (*Write) (struct efi_pci_root_bridge_io_protocol* self,
+ efi_pci_root_bridge_io_width width,
+ uint64_t addr, size_t count, void* buffer) EFIAPI;
+} efi_pci_root_bridge_io_access;
#define EFI_PCI_ATTRIBUTE_ISA_MOTHERBOARD_IO 0x0001
#define EFI_PCI_ATTRIBUTE_ISA_IO 0x0002
@@ -75,82 +61,55 @@
EfiPciOperationBusMasterWrite64,
EfiPciOperationBusMasterCommonBuffer64,
EfiPciOperationMaximum,
-} EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_OPERATION;
+} efi_pci_root_bridge_io_operation;
-typedef EFI_STATUS (EFIAPI *EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_COPY_MEM) (
- IN struct _EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
- IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,
- IN UINT64 DestAddress,
- IN UINT64 SrcAddress,
- IN UINTN Count
-);
+typedef struct efi_pci_root_bridge_io_protocol {
+ efi_handle ParentHandle;
-typedef EFI_STATUS (EFIAPI *EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_MAP) (
- IN struct _EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
- IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_OPERATION Operation,
- IN VOID *HostAddress,
- IN OUT UINTN *NumberOfBytes,
- OUT EFI_PHYSICAL_ADDRESS *DeviceAddress,
- OUT VOID **Mapping
-);
+ efi_status (*PollMem) (struct efi_pci_root_bridge_io_protocol *self,
+ efi_pci_root_bridge_io_width width,
+ uint64_t addr, uint64_t mask, uint64_t value, uint64_t delay,
+ uint64_t* result) EFIAPI;
-typedef EFI_STATUS (EFIAPI *EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_UNMAP) (
- IN struct _EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
- IN VOID *Mapping
-);
+ efi_status (*PollIo) (struct efi_pci_root_bridge_io_protocol *self,
+ efi_pci_root_bridge_io_width width,
+ uint64_t addr, uint64_t mask, uint64_t value, uint64_t delay,
+ uint64_t* result) EFIAPI;
-typedef EFI_STATUS (EFIAPI *EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_ALLOCATE_BUFFER) (
- IN struct _EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
- IN EFI_ALLOCATE_TYPE Type,
- IN EFI_MEMORY_TYPE MemoryType,
- IN UINTN Pages,
- OUT VOID **HostAddress,
- IN UINT64 Attributes
-);
+ efi_pci_root_bridge_io_access Mem;
+ efi_pci_root_bridge_io_access Io;
+ efi_pci_root_bridge_io_access Pci;
-typedef EFI_STATUS (EFIAPI *EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_FREE_BUFFER) (
- IN struct _EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
- IN UINTN Pages,
- IN VOID *HostAddress
-);
+ efi_status (*CopyMem) (struct efi_pci_root_bridge_io_protocol* self,
+ efi_pci_root_bridge_io_width width,
+ uint64_t dest_addr, uint64_t src_addr, size_t count) EFIAPI;
-typedef EFI_STATUS (EFIAPI *EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_FLUSH) (
- IN struct _EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This
-);
+ efi_status (*Map) (struct efi_pci_root_bridge_io_protocol* self,
+ efi_pci_root_bridge_io_operation operation,
+ void* host_addr, size_t* num_bytes,
+ efi_physical_addr* device_addr, void** mapping) EFIAPI;
-typedef EFI_STATUS (EFIAPI *EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_GET_ATTRIBUTES) (
- IN struct _EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
- OUT UINT64 *Supports OPTIONAL,
- OUT UINT64 *Attributes OPTIONAL
-);
+ efi_status (*Unmap) (struct efi_pci_root_bridge_io_protocol* self,
+ void* mapping) EFIAPI;
-typedef EFI_STATUS (EFIAPI *EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_SET_ATTRIBUTES) (
- IN struct _EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
- IN UINT64 Attributes,
- IN OUT UINT64 *ResourceBase OPTIONAL,
- IN OUT UINT64 *ResourceLength OPTIONAL
-);
+ efi_status (*AllocateBuffer) (struct efi_pci_root_bridge_io_protocol* self,
+ efi_allocate_type type, efi_memory_type memory_type,
+ size_t pages, void** host_addr, uint64_t attributes) EFIAPI;
-typedef EFI_STATUS (EFIAPI *EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_CONFIGURATION) (
- IN struct _EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
- OUT VOID **Resources
-);
+ efi_status (*FreeBuffer) (struct efi_pci_root_bridge_io_protocol* self,
+ size_t pages, void* host_addr) EFIAPI;
-typedef struct _EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL {
- EFI_HANDLE ParentHandle;
- EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_POLL_IO_MEM PollMem;
- EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_POLL_IO_MEM PollIo;
- EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_ACCESS Mem;
- EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_ACCESS Io;
- EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_ACCESS Pci;
- EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_COPY_MEM CopyMem;
- EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_MAP Map;
- EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_UNMAP Unmap;
- EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_ALLOCATE_BUFFER AllocateBuffer;
- EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_FREE_BUFFER FreeBuffer;
- EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_FLUSH Flush;
- EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_GET_ATTRIBUTES GetAttributes;
- EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_SET_ATTRIBUTES SetAttributes;
- EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_CONFIGURATION Configuration;
- UINT32 SegmentNumber;
-} EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL;
+ efi_status (*Flush) (struct efi_pci_root_bridge_io_protocol* self) EFIAPI;
+
+ efi_status (*GetAttributes) (struct efi_pci_root_bridge_io_protocol* self,
+ uint64_t* supports, uint64_t* attributes) EFIAPI;
+
+ efi_status (*SetAttributes) (struct efi_pci_root_bridge_io_protocol* self,
+ uint64_t attributes, uint64_t* resource_base,
+ uint64_t* resource_len) EFIAPI;
+
+ efi_status (*Configuration) (struct efi_pci_root_bridge_io_protocol* self,
+ void** resources) EFIAPI;
+
+ uint32_t SegmentNumber;
+} efi_pci_root_bridge_io_protocol;
diff --git a/include/efi/protocol/simple-file-system.h b/include/efi/protocol/simple-file-system.h
new file mode 100644
index 0000000..ad7c42a
--- /dev/null
+++ b/include/efi/protocol/simple-file-system.h
@@ -0,0 +1,21 @@
+// Copyright 2016 The Fuchsia Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#pragma once
+
+#include <efi/types.h>
+#include <efi/protocol/file.h>
+
+#define EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID \
+ {0x0964e5b22, 0x6459, 0x11d2, {0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b}}
+extern efi_guid SimpleFileSystemProtocol;
+
+#define EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION 0x00010000
+
+typedef struct efi_simple_file_system_protocol {
+ uint64_t Revision;
+
+ efi_status (*OpenVolume) (struct efi_simple_file_system_protocol* self,
+ efi_file_protocol** root) EFIAPI;
+} efi_simple_file_system_protocol;
diff --git a/include/efi/protocol/simple-network.h b/include/efi/protocol/simple-network.h
new file mode 100644
index 0000000..b4e3489
--- /dev/null
+++ b/include/efi/protocol/simple-network.h
@@ -0,0 +1,131 @@
+// Copyright 2016 The Fuchsia Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#pragma once
+
+#include <efi/types.h>
+
+#define EFI_SIMPLE_NETWORK_PROTOCOL_GUID \
+ {0xa19832b9, 0xac25, 0x11d3, {0x9a, 0x2d, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d}}
+extern efi_guid SimpleNetworkProtocol;
+
+#define EFI_SIMPLE_NETWORK_PROTOCOL_REVISION 0x00010000
+
+#define MAX_MCAST_FILTER_CNT 16
+typedef struct {
+ uint32_t State;
+ uint32_t HwAddressSize;
+ uint32_t MediaHeaderSize;
+ uint32_t MaxPacketSize;
+ uint32_t NvRamSize;
+ uint32_t NvRamAccessSize;
+ uint32_t ReceiveFilterMask;
+ uint32_t ReceiveFilterSetting;
+ uint32_t MaxMCastFilterCount;
+ uint32_t MCastFilterCount;
+ efi_mac_addr MCastFilter[MAX_MCAST_FILTER_CNT];
+ efi_mac_addr CurrentAddress;
+ efi_mac_addr BroadcastAddress;
+ efi_mac_addr PermanentAddress;
+ uint8_t IfType;
+ bool MacAddressChangeable;
+ bool MultipleTxSupported;
+ bool MediaPresentSupported;
+ bool MediaPresent;
+} efi_simple_network_mode;
+
+typedef enum {
+ EfiSimpleNetworkStopped,
+ EfiSimpleNetworkStarted,
+ EfiSimpleNetworkInitialized,
+ EfiSimpleNetworkMaxState
+} efi_simple_network_state;
+
+#define EFI_SIMPLE_NETWORK_RECEIVE_UNICAST 0x01
+#define EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST 0x02
+#define EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST 0x04
+#define EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS 0x08
+#define EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST 0x10
+
+typedef struct {
+ uint64_t RxTotalFrames;
+ uint64_t RxGoodFrames;
+ uint64_t RxUndersizeFrames;
+ uint64_t RxOversizeFrames;
+ uint64_t RxDroppedFrames;
+ uint64_t RxUnicastFrames;
+ uint64_t RxBroadcastFrames;
+ uint64_t RxMulticastFrames;
+ uint64_t RxCrcErrorFrames;
+ uint64_t RxTotalBytes;
+ uint64_t TxTotalFrames;
+ uint64_t TxGoodFrames;
+ uint64_t TxUndersizeFrames;
+ uint64_t TxOversizeFrames;
+ uint64_t TxDroppedFrames;
+ uint64_t TxUnicastFrames;
+ uint64_t TxBroadcastFrames;
+ uint64_t TxMulticastFrames;
+ uint64_t TxCrcErrorFrames;
+ uint64_t TxTotalBytes;
+ uint64_t Collisions;
+ uint64_t UnsupportedProtocol;
+ uint64_t RxDuplicatedFrames;
+ uint64_t RxDecryptErrorFrames;
+ uint64_t TxErrorFrames;
+ uint64_t TxRetryFrames;
+} efi_network_statistics;
+
+#define EFI_SIMPLE_NETWORK_RECEIVE_INTERRUPT 0x01
+#define EFI_SIMPLE_NETWORK_TRANSMIT_INTERRUPT 0x02
+#define EFI_SIMPLE_NETWORK_COMMAND_INTERRUPT 0x04
+#define EFI_SIMPLE_NETWORK_SOFTWARE_INTERRUPT 0x08
+
+typedef struct efi_simple_network_protocol {
+ uint64_t Revision;
+
+ efi_status (*Start) (struct efi_simple_network_protocol* self) EFIAPI;
+
+ efi_status (*Stop) (struct efi_simple_network_protocol* self) EFIAPI;
+
+ efi_status (*Initialize) (struct efi_simple_network_protocol* self,
+ size_t extra_rx_buf_size, size_t extra_tx_buf_size) EFIAPI;
+
+ efi_status (*Reset) (struct efi_simple_network_protocol* self,
+ bool extended_verification) EFIAPI;
+
+ efi_status (*Shutdown) (struct efi_simple_network_protocol* self) EFIAPI;
+
+ efi_status (*ReceiveFilters) (struct efi_simple_network_protocol* self,
+ uint32_t enable, uint32_t disable,
+ bool reset_mcast_filter, size_t mcast_filter_count,
+ efi_mac_addr* mcast_filter) EFIAPI;
+
+ efi_status (*StationAddress) (struct efi_simple_network_protocol* self,
+ bool reset, efi_mac_addr* new_addr) EFIAPI;
+
+ efi_status (*Statistics) (struct efi_simple_network_protocol* self,
+ bool reset, size_t* stats_size,
+ efi_network_statistics* stats_table) EFIAPI;
+
+ efi_status (*MCastIpToMac) (struct efi_simple_network_protocol* self,
+ bool ipv6, efi_ip_addr* ip, efi_mac_addr* mac) EFIAPI;
+
+ efi_status (*NvData) (struct efi_simple_network_protocol* self,
+ bool read_write, size_t offset, size_t buf_size, void* buf) EFIAPI;
+
+ efi_status (*GetStatus) (struct efi_simple_network_protocol* self,
+ uint32_t* interrupt_status, void** tx_buf) EFIAPI;
+
+ efi_status (*Transmit) (struct efi_simple_network_protocol* self,
+ size_t header_size, size_t buf_size, void* buf,
+ efi_mac_addr* src, efi_mac_addr* dest, uint16_t* protocol) EFIAPI;
+
+ efi_status (*Receive) (struct efi_simple_network_protocol* self,
+ size_t* header_size, size_t* buf_size, void* buf,
+ efi_mac_addr* src, efi_mac_addr* dest, uint16_t* protocol) EFIAPI;
+
+ efi_event WaitForPacket;
+ efi_simple_network_mode* Mode;
+} efi_simple_network_protocol;
diff --git a/include/efi/protocol/simple-text-input.h b/include/efi/protocol/simple-text-input.h
new file mode 100644
index 0000000..ee6bf68
--- /dev/null
+++ b/include/efi/protocol/simple-text-input.h
@@ -0,0 +1,26 @@
+// Copyright 2016 The Fuchsia Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#pragma once
+
+#include <efi/types.h>
+
+#define EFI_SIMPLE_TEXT_INPUT_PROTOCOL_GUID \
+ {0x387477c1, 0x69c7, 0x11d2, {0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b}}
+extern efi_guid SimpleTextInputProtocol;
+
+typedef struct {
+ uint16_t ScanCode;
+ char16_t UnicodeChar;
+} efi_input_key;
+
+typedef struct efi_simple_text_input_protocol {
+ efi_status (*Reset) (struct efi_simple_text_input_protocol* self,
+ bool extendend_verification) EFIAPI;
+
+ efi_status (*ReadKeyStroke) (struct efi_simple_text_input_protocol* self,
+ efi_input_key* key) EFIAPI;
+
+ efi_event WaitForKey;
+} efi_simple_text_input_protocol;
diff --git a/include/efi/protocol/simple-text-output.h b/include/efi/protocol/simple-text-output.h
new file mode 100644
index 0000000..ac93167
--- /dev/null
+++ b/include/efi/protocol/simple-text-output.h
@@ -0,0 +1,143 @@
+// Copyright 2016 The Fuchsia Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#pragma once
+
+#include <efi/types.h>
+
+#define EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL_GUID \
+ {0x387477c2, 0x69c7, 0x11d2, {0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b}}
+extern efi_guid SimpleTextOutputProtocol;
+
+typedef struct {
+ int32_t MaxMode;
+ int32_t Mode;
+ int32_t Attribute;
+ int32_t CursorColumn;
+ int32_t CursorRow;
+ bool CursorVisible;
+} simple_text_output_mode;
+
+//*******************************************************
+// UNICODE DRAWING CHARACTERS
+//*******************************************************
+#define BOXDRAW_HORIZONTAL 0x2500
+#define BOXDRAW_VERTICAL 0x2502
+#define BOXDRAW_DOWN_RIGHT 0x250c
+#define BOXDRAW_DOWN_LEFT 0x2510
+#define BOXDRAW_UP_RIGHT 0x2514
+#define BOXDRAW_UP_LEFT 0x2518
+#define BOXDRAW_VERTICAL_RIGHT 0x251c
+#define BOXDRAW_VERTICAL_LEFT 0x2524
+#define BOXDRAW_DOWN_HORIZONTAL 0x252c
+#define BOXDRAW_UP_HORIZONTAL 0x2534
+#define BOXDRAW_VERTICAL_HORIZONTAL 0x253c
+#define BOXDRAW_DOUBLE_HORIZONTAL 0x2550
+#define BOXDRAW_DOUBLE_VERTICAL 0x2551
+#define BOXDRAW_DOWN_RIGHT_DOUBLE 0x2552
+#define BOXDRAW_DOWN_DOUBLE_RIGHT 0x2553
+#define BOXDRAW_DOUBLE_DOWN_RIGHT 0x2554
+#define BOXDRAW_DOWN_LEFT_DOUBLE 0x2555
+#define BOXDRAW_DOWN_DOUBLE_LEFT 0x2556
+#define BOXDRAW_DOUBLE_DOWN_LEFT 0x2557
+#define BOXDRAW_UP_RIGHT_DOUBLE 0x2558
+#define BOXDRAW_UP_DOUBLE_RIGHT 0x2559
+#define BOXDRAW_DOUBLE_UP_RIGHT 0x255a
+#define BOXDRAW_UP_LEFT_DOUBLE 0x255b
+#define BOXDRAW_UP_DOUBLE_LEFT 0x255c
+#define BOXDRAW_DOUBLE_UP_LEFT 0x255d
+#define BOXDRAW_VERTICAL_RIGHT_DOUBLE 0x255e
+#define BOXDRAW_VERTICAL_DOUBLE_RIGHT 0x255f
+#define BOXDRAW_DOUBLE_VERTICAL_RIGHT 0x2560
+#define BOXDRAW_VERTICAL_LEFT_DOUBLE 0x2561
+#define BOXDRAW_VERTICAL_DOUBLE_LEFT 0x2562
+#define BOXDRAW_DOUBLE_VERTICAL_LEFT 0x2563
+#define BOXDRAW_DOWN_HORIZONTAL_DOUBLE 0x2564
+#define BOXDRAW_DOWN_DOUBLE_HORIZONTAL 0x2565
+#define BOXDRAW_DOUBLE_DOWN_HORIZONTAL 0x2566
+#define BOXDRAW_UP_HORIZONTAL_DOUBLE 0x2567
+#define BOXDRAW_UP_DOUBLE_HORIZONTAL 0x2568
+#define BOXDRAW_DOUBLE_UP_HORIZONTAL 0x2569
+#define BOXDRAW_VERTICAL_HORIZONTAL_DOUBLE 0x256a
+#define BOXDRAW_VERTICAL_DOUBLE_HORIZONTAL 0x256b
+#define BOXDRAW_DOUBLE_VERTICAL_HORIZONTAL 0x256c
+
+//*******************************************************
+// EFI Required Block Elements Code Chart
+//*******************************************************
+#define BLOCKELEMENT_FULL_BLOCK 0x2588
+#define BLOCKELEMENT_LIGHT_SHADE 0x2591
+
+//*******************************************************
+// EFI Required Geometric Shapes Code Chart
+//*******************************************************
+#define GEOMETRICSHAPE_UP_TRIANGLE 0x25b2
+#define GEOMETRICSHAPE_RIGHT_TRIANGLE 0x25ba
+#define GEOMETRICSHAPE_DOWN_TRIANGLE 0x25bc
+#define GEOMETRICSHAPE_LEFT_TRIANGLE 0x25c4
+
+//*******************************************************
+// EFI Required Arrow shapes
+//*******************************************************
+#define ARROW_UP 0x2191
+#define ARROW_DOWN 0x2193
+
+//*******************************************************
+// Attributes
+//*******************************************************
+#define EFI_BLACK 0x00
+#define EFI_BLUE 0x01
+#define EFI_GREEN 0x02
+#define EFI_CYAN 0x03
+#define EFI_RED 0x04
+#define EFI_MAGENTA 0x05
+#define EFI_BROWN 0x06
+#define EFI_LIGHTGRAY 0x07
+#define EFI_BRIGHT 0x08
+#define EFI_DARKGRAY 0x08
+#define EFI_LIGHTBLUE 0x09
+#define EFI_LIGHTGREEN 0x0A
+#define EFI_LIGHTCYAN 0x0B
+#define EFI_LIGHTRED 0x0C
+#define EFI_LIGHTMAGENTA 0x0D
+#define EFI_YELLOW 0x0E
+#define EFI_WHITE 0x0F
+#define EFI_BACKGROUND_BLACK 0x00
+#define EFI_BACKGROUND_BLUE 0x10
+#define EFI_BACKGROUND_GREEN 0x20
+#define EFI_BACKGROUND_CYAN 0x30
+#define EFI_BACKGROUND_RED 0x40
+#define EFI_BACKGROUND_MAGENTA 0x50
+#define EFI_BACKGROUND_BROWN 0x60
+#define EFI_BACKGROUND_LIGHTGRAY 0x70
+
+typedef struct efi_simple_text_output_protocol {
+ efi_status (*Reset) (struct efi_simple_text_output_protocol* self,
+ bool extended_verification) EFIAPI;
+
+ efi_status (*OutputString) (struct efi_simple_text_output_protocol* self,
+ char16_t* string) EFIAPI;
+
+ efi_status (*TestString) (struct efi_simple_text_output_protocol* self,
+ char16_t* string) EFIAPI;
+
+ efi_status (*QueryMode) (struct efi_simple_text_output_protocol* self,
+ size_t mode_num, size_t* cols, size_t* rows) EFIAPI;
+
+ efi_status (*SetMode) (struct efi_simple_text_output_protocol* self,
+ size_t mode_num) EFIAPI;
+
+ efi_status (*SetAttribute) (struct efi_simple_text_output_protocol* self,
+ size_t attribute) EFIAPI;
+
+ efi_status (*ClearScreen) (struct efi_simple_text_output_protocol* self) EFIAPI;
+
+ efi_status (*SetCursorPosition) (struct efi_simple_text_output_protocol* self,
+ size_t col, size_t row) EFIAPI;
+
+ efi_status (*EnableCursor) (struct efi_simple_text_output_protocol* self,
+ bool visible) EFIAPI;
+
+ simple_text_output_mode* Mode;
+} efi_simple_text_output_protocol;
diff --git a/include/efi/protocol/usb-io.h b/include/efi/protocol/usb-io.h
new file mode 100644
index 0000000..721ce92
--- /dev/null
+++ b/include/efi/protocol/usb-io.h
@@ -0,0 +1,147 @@
+// Copyright 2016 The Fuchsia Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#pragma once
+
+#include <efi/types.h>
+
+#define EFI_USB_IO_PROTOCOL_GUID \
+ {0x2b2f68d6, 0x0cd2, 0x44cf, {0x8e, 0x8b, 0xbb, 0xa2, 0x0b, 0x1b, 0x5b, 0x75}}
+extern efi_guid UsbIoProtocol;
+
+typedef enum {
+ EfiUsbDataIn,
+ EfiUsbDataOut,
+ EfiUsbNoData
+} efi_usb_data_direction;
+
+#define EFI_USB_NOERROR 0x0000
+#define EFI_USB_ERR_NOTEXECUTE 0x0001
+#define EFI_USB_ERR_STALL 0x0002
+#define EFI_USB_ERR_BUFFER 0x0004
+#define EFI_USB_ERR_BABBLE 0x0008
+#define EFI_USB_ERR_NAK 0x0010
+#define EFI_USB_ERR_CRC 0x0020
+#define EFI_USB_ERR_TIMEOUT 0x0040
+#define EFI_USB_ERR_BITSTUFF 0x0080
+#define EFI_USB_ERR_SYSTEM 0x0100
+
+typedef struct {
+ uint8_t RequestType;
+ uint8_t Request;
+ uint16_t Value;
+ uint16_t Index;
+ uint16_t Length;
+} efi_usb_device_request;
+
+typedef efi_status (*efi_async_usb_transfer_callback) (
+ void* Data, size_t DataLength, void* Context, uint32_t Status) EFIAPI;
+
+typedef struct {
+ uint8_t Length;
+ uint8_t DescriptorType;
+ uint16_t BcdUSB;
+ uint8_t DeviceClass;
+ uint8_t DeviceSubClass;
+ uint8_t DeviceProtocol;
+ uint8_t MaxPacketSize0;
+ uint16_t IdVendor;
+ uint16_t IdProduct;
+ uint16_t BcdDevice;
+ uint8_t StrManufacturer;
+ uint8_t StrProduct;
+ uint8_t StrSerialNumber;
+ uint8_t NumConfigurations;
+} efi_usb_device_descriptor;
+
+typedef struct {
+ uint8_t Length;
+ uint8_t DescriptorType;
+ uint16_t TotalLength;
+ uint8_t NumInterfaces;
+ uint8_t ConfigurationValue;
+ uint8_t Configuration;
+ uint8_t Attributes;
+ uint8_t MaxPower;
+} efi_usb_config_descriptor;
+
+typedef struct {
+ uint8_t Length;
+ uint8_t DescriptorType;
+ uint8_t InterfaceNumber;
+ uint8_t AlternateSetting;
+ uint8_t NumEndpoints;
+ uint8_t InterfaceClass;
+ uint8_t InterfaceSubClass;
+ uint8_t InterfaceProtocol;
+ uint8_t Interface;
+} efi_usb_interface_descriptor;
+
+typedef struct {
+ uint8_t Length;
+ uint8_t DescriptorType;
+ uint8_t EndpointAddress;
+ uint8_t Attributes;
+ uint16_t MaxPacketSize;
+ uint8_t Interval;
+} efi_usb_endpoint_descriptor;
+
+typedef struct efi_usb_io_protocol {
+ efi_status (*UsbControlTransfer) (struct efi_usb_io_protocol* self,
+ efi_usb_device_request* request,
+ efi_usb_data_direction direction,
+ uint32_t timeout, void* data,
+ size_t data_len, uint32_t* status) EFIAPI;
+
+ efi_status (*UsbBulkTransfer) (struct efi_usb_io_protocol* self,
+ uint8_t endpoint, void* data,
+ size_t data_len, size_t timeout,
+ uint32_t* status) EFIAPI;
+
+ efi_status (*UsbAsyncInterruptTransfer) (struct efi_usb_io_protocol* self,
+ uint8_t endpoint, bool is_new_transfer,
+ size_t polling_interval,
+ size_t data_len,
+ efi_async_usb_transfer_callback interrupt_cb,
+ void* context) EFIAPI;
+
+ efi_status (*UsbSyncInterruptTransfer) (struct efi_usb_io_protocol* self,
+ uint8_t endpoint, void* data,
+ size_t* data_len, size_t timeout,
+ uint32_t* status) EFIAPI;
+
+ efi_status (*UsbIsochronousTransfer) (struct efi_usb_io_protocol* self,
+ uint8_t endpoint,
+ void* data, size_t data_len,
+ uint32_t* status) EFIAPI;
+
+ efi_status (*UsbAsyncIsochronousTransfer) (struct efi_usb_io_protocol* self,
+ uint8_t endpoint,
+ void* data, size_t data_len,
+ efi_async_usb_transfer_callback isoc_cb,
+ void* context) EFIAPI;
+
+ efi_status (*UsbGetDeviceDescriptor) (struct efi_usb_io_protocol* self,
+ efi_usb_device_descriptor* descriptor) EFIAPI;
+
+ efi_status (*UsbGetConfigDescriptor) (struct efi_usb_io_protocol* self,
+ efi_usb_config_descriptor* descriptor) EFIAPI;
+
+ efi_status (*UsbGetInterfaceDescriptor) (struct efi_usb_io_protocol* self,
+ efi_usb_interface_descriptor* descriptor) EFIAPI;
+
+ efi_status (*UsbGetEndpointDescriptor) (struct efi_usb_io_protocol* self,
+ uint8_t endpt_index,
+ efi_usb_endpoint_descriptor* descriptor) EFIAPI;
+
+ efi_status (*UsbGetStringDescriptor) (struct efi_usb_io_protocol* self,
+ uint16_t langid, uint8_t stringid,
+ char16_t** str) EFIAPI;
+
+ efi_status (*UsbGetSupportedLanguages) (struct efi_usb_io_protocol* self,
+ uint16_t** langid_table,
+ uint16_t* table_size) EFIAPI;
+
+ efi_status (*UsbPortReset) (struct efi_usb_io_protocol* self) EFIAPI;
+} efi_usb_io_protocol;
diff --git a/include/efi/runtime-services.h b/include/efi/runtime-services.h
new file mode 100644
index 0000000..613b34f
--- /dev/null
+++ b/include/efi/runtime-services.h
@@ -0,0 +1,151 @@
+// Copyright 2016 The Fuchsia Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#pragma once
+
+#include <efi/types.h>
+#include <efi/boot-services.h>
+
+#define EFI_RUNTIME_SERVICES_SIGNATURE 0x56524553544e5552
+#define EFI_RUNTIME_SERVICES_REVISION EFI_SPECIFICATION_VERSION
+
+#define EFI_VARIABLE_NON_VOLATILE 0x00000001
+#define EFI_VARIABLE_BOOTSERVICE_ACCESS 0x00000002
+#define EFI_VARIABLE_RUNTIME_ACCESS 0x00000004
+#define EFI_VARIABLE_HARDWARE_ERROR_RECORD 0x00000008
+#define EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS 0x00000010
+#define EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS 0x00000020
+#define EFI_VARIABLE_APPEND_WRITE 0x00000040
+
+// TODO: implement the win_certificate structs if we need them
+//typedef struct {
+// uint64_t MonotonicCount;
+// win_certificate_uefi_guid AuthInfo;
+//} efi_variable_authentication;
+//
+//typedef struct {
+// efi_time TimeStamp;
+// win_certificate_uefi_guid AuthInfo;
+//} efi_variable_authentication_2;
+
+#define EFI_HARDWARE_ERROR_VARIABLE \
+ {0x414e6bdd, 0xe47b, 0x47cc, {0xb2, 0x44, 0xbb, 0x61, 0x02, 0x0c, 0xf5, 0x16}}
+
+typedef struct {
+ uint16_t Year;
+ uint8_t Month;
+ uint8_t Day;
+ uint8_t Hour;
+ uint8_t Minute;
+ uint8_t Second;
+ uint8_t Pad1;
+ uint32_t Nanosecond;
+ int16_t TimeZone;
+ uint8_t Daylight;
+ uint8_t Pad2;
+} efi_time;
+
+#define EFI_TIME_ADJUST_DAYLIGHT 0x01
+#define EFI_TIME_IN_DAYLIGHT 0x02
+
+#define EFI_UNSPECIFIED_TIMEZONE 0x07FF
+
+typedef struct {
+ uint32_t Resolution;
+ uint32_t Accuracy;
+ bool SetsToZero;
+} efi_time_capabilities;
+
+#define EFI_OPTIONAL_PTR 0x00000001
+
+typedef enum {
+ EfiResetCold,
+ EfiResetWarm,
+ EfiResetShutdown,
+ EfiResetPlatformSpecific
+} efi_reset_type;
+
+typedef struct {
+ uint64_t Length;
+ union {
+ efi_physical_addr DataBlock;
+ efi_physical_addr ContinuationPointer;
+ } Union;
+} efi_capsule_block_descriptor;
+
+typedef struct {
+ efi_guid CapsuleGuid;
+ uint32_t HeaderSize;
+ uint32_t Flags;
+ uint32_t CapsuleImageSize;
+} efi_capsule_header;
+
+#define CAPSULE_FLAGS_PERSIST_ACROSS_RESET 0x00010000
+#define CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE 0x00020000
+#define CAPSULE_FLAGS_INITIATE_RESET 0x00040000
+
+#define EFI_OS_INDICATIONS_BOOT_TO_FW_UI 0x0000000000000001
+#define EFI_OS_INDICATIONS_TIMESTAMP_REVOCATION 0x0000000000000002
+#define EFI_OS_INDICATIONS_FILE_CAPSULE_DELIVERY_SUPPORTED 0x0000000000000004
+#define EFI_OS_INDICATIONS_FMP_CAPSULE_SUPPORTED 0x0000000000000008
+#define EFI_OS_INDICATIONS_CAPSULE_RESULT_VAR_SUPPORTED 0x0000000000000010
+#define EFI_OS_INDICATIONS_START_OS_RECOVERY 0x0000000000000020
+#define EFI_OS_INDICATIONS_START_PLATFORM_RECOVERY 0x0000000000000040
+
+#define EFI_CAPSULE_REPORT_GUID \
+ {0x39b68c46, 0xf7fb, 0x441b, {0xb6, 0xec, 0x16, 0xb0, 0xf6, 0x98, 0x21, 0xf3}}
+
+typedef struct {
+ uint32_t VariableTotalSize;
+ uint32_t Reserved;
+ efi_guid CapsuleGuid;
+ efi_time CapsuleProcessed;
+ efi_status CapsuleStatus;
+} efi_capsule_result_variable_header;
+
+typedef struct {
+ efi_table_header Hdr;
+
+ efi_status (*GetTime) (efi_time* time, efi_time_capabilities* capabilities) EFIAPI;
+
+ efi_status (*SetTime) (efi_time* time) EFIAPI;
+
+ efi_status (*GetWakeupTime) (bool* enabled, bool* pending, efi_time* time) EFIAPI;
+
+ efi_status (*SetWakeupTime) (bool enable, efi_time* time) EFIAPI;
+
+ efi_status (*SetVirtualAddressMap) (size_t memory_map_size, size_t desc_size,
+ uint32_t desc_version,
+ efi_memory_descriptor* virtual_map) EFIAPI;
+
+ efi_status (*ConvertPointer) (size_t debug_disposition, void** addr) EFIAPI;
+
+ efi_status (*GetVariable) (char16_t* var_name, efi_guid* vendor_guid,
+ uint32_t* attributes, size_t* data_size, void* data) EFIAPI;
+
+ efi_status (*GetNextVariableName) (size_t* var_name_size, char16_t* var_name,
+ efi_guid* vendor_guid) EFIAPI;
+
+ efi_status (*SetVariable) (char16_t* var_name, efi_guid* vendor_guid,
+ uint32_t attributes, size_t data_size, void* data) EFIAPI;
+
+ efi_status (*GetNextHighMonotonicCount) (uint32_t* high_count) EFIAPI;
+
+ efi_status (*ResetSystem) (efi_reset_type reset_type, efi_status reset_status,
+ size_t data_size, void* reset_data) EFIAPI;
+
+ efi_status (*UpdateCapsule) (efi_capsule_header** capsule_header_array,
+ size_t capsule_count,
+ efi_physical_addr scatter_gather_list) EFIAPI;
+
+ efi_status (*QueryCapsuleCapabilities) (efi_capsule_header** capsule_header_array,
+ size_t capsule_count,
+ uint64_t* max_capsule_size,
+ efi_reset_type* reset_type) EFIAPI;
+
+ efi_status (*QueryVariableInfo) (uint32_t attributes,
+ uint64_t* max_var_storage_size,
+ uint64_t* remaining_var_storage_size,
+ uint64_t* max_var_size) EFIAPI;
+} efi_runtime_services;
diff --git a/include/efi/system-table.h b/include/efi/system-table.h
new file mode 100644
index 0000000..3f145af
--- /dev/null
+++ b/include/efi/system-table.h
@@ -0,0 +1,48 @@
+// Copyright 2016 The Fuchsia Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#pragma once
+
+#include <stdint.h>
+
+#include <efi/types.h>
+#include <efi/boot-services.h>
+#include <efi/runtime-services.h>
+#include <efi/protocol/simple-text-input.h>
+#include <efi/protocol/simple-text-output.h>
+
+#define EFI_SYSTEM_TABLE_SIGNATURE 0x5453595320494249
+#define EFI_2_60_SYSTEM_TABLE_REVISION ((2<<16) | (60))
+#define EFI_2_50_SYSTEM_TABLE_REVISION ((2<<16) | (50))
+#define EFI_2_40_SYSTEM_TABLE_REVISION ((2<<16) | (40))
+#define EFI_2_31_SYSTEM_TABLE_REVISION ((2<<16) | (31))
+#define EFI_2_30_SYSTEM_TABLE_REVISION ((2<<16) | (30))
+#define EFI_2_20_SYSTEM_TABLE_REVISION ((2<<16) | (20))
+#define EFI_2_10_SYSTEM_TABLE_REVISION ((2<<16) | (10))
+#define EFI_2_00_SYSTEM_TABLE_REVISION ((2<<16) | (00))
+#define EFI_1_10_SYSTEM_TABLE_REVISION ((1<<16) | (10))
+#define EFI_1_02_SYSTEM_TABLE_REVISION ((1<<16) | (02))
+#define EFI_SPECIFICATION_VERSION EFI_SYSTEM_TABLE_REVISION
+#define EFI_SYSTEM_TABLE_REVISION EFI_2_60_SYSTEM_TABLE_REVISION
+
+typedef struct {
+ efi_guid VendorGuid;
+ void* VendorTable;
+} efi_configuration_table;
+
+typedef struct efi_system_table {
+ efi_table_header Hdr;
+ char16_t* FirmwareVendor;
+ uint32_t FirmwareRevision;
+ efi_handle ConsoleInHandle;
+ efi_simple_text_input_protocol* ConIn;
+ efi_handle ConsoleOutHandle;
+ efi_simple_text_output_protocol* ConOut;
+ efi_handle StandardErrorHandle;
+ efi_simple_text_output_protocol* StdErr;
+ efi_runtime_services *RuntimeServices;
+ efi_boot_services* BootServices;
+ size_t NumberOfTableEntries;
+ efi_configuration_table *ConfigurationTable;
+} efi_system_table;
diff --git a/include/efi/types.h b/include/efi/types.h
new file mode 100644
index 0000000..2aa6408
--- /dev/null
+++ b/include/efi/types.h
@@ -0,0 +1,141 @@
+// Copyright 2016 The Fuchsia Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#pragma once
+
+#include <stdint.h>
+
+#define EFIAPI __attribute__((ms_abi))
+
+#define EFI_ERROR_MASK 0x8000000000000000
+#define EFI_ERR(x) (EFI_ERROR_MASK | x)
+#define EFI_ERROR(x) (((int64_t)x) < 0)
+
+#define EFI_SUCCESS 0
+#define EFI_LOAD_ERROR EFI_ERR(1)
+#define EFI_INVALID_PARAMETER EFI_ERR(2)
+#define EFI_UNSUPPORTED EFI_ERR(3)
+#define EFI_BAD_BUFFER_SIZE EFI_ERR(4)
+#define EFI_BUFFER_TOO_SMALL EFI_ERR(5)
+#define EFI_NOT_READY EFI_ERR(6)
+#define EFI_DEVICE_ERROR EFI_ERR(7)
+#define EFI_WRITE_PROTECTED EFI_ERR(8)
+#define EFI_OUT_OF_RESOURCES EFI_ERR(9)
+#define EFI_VOLUME_CORRUPTED EFI_ERR(10)
+#define EFI_VOLUME_FULL EFI_ERR(11)
+#define EFI_NO_MEDIA EFI_ERR(12)
+#define EFI_MEDIA_CHANGED EFI_ERR(13)
+#define EFI_NOT_FOUND EFI_ERR(14)
+#define EFI_ACCESS_DENIED EFI_ERR(15)
+#define EFI_NO_RESPONSE EFI_ERR(16)
+#define EFI_NO_MAPPING EFI_ERR(17)
+#define EFI_TIMEOUT EFI_ERR(18)
+#define EFI_NOT_STARTED EFI_ERR(19)
+#define EFI_ALREADY_STARTED EFI_ERR(20)
+#define EFI_ABORTED EFI_ERR(21)
+#define EFI_ICMP_ERROR EFI_ERR(22)
+#define EFI_TFTP_ERROR EFI_ERR(23)
+#define EFI_PROTOCOL_ERROR EFI_ERR(24)
+#define EFI_INCOMPATIBLE_VERSION EFI_ERR(25)
+#define EFI_SECURITY_VIOLATION EFI_ERR(26)
+#define EFI_CRC_ERROR EFI_ERR(27)
+#define EFI_END_OF_MEDIA EFI_ERR(28)
+#define EFI_END_OF_FILE EFI_ERR(31)
+#define EFI_INVALID_LANGUAGE EFI_ERR(32)
+#define EFI_COMPROMISED_DATA EFI_ERR(33)
+#define EFI_IP_ADDRESS_CONFLICT EFI_ERR(34)
+#define EFI_HTTP_ERROR EFI_ERR(35)
+
+// TODO: figure out where to put these. They're just mentioned in passing in the
+// spec as some of many industry standard GUIDs but not part of the spec itself.
+#define ACPI_TABLE_GUID \
+ {0xeb9d2d30, 0x2d88, 0x11d3, {0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d}}
+#define ACPI_20_TABLE_GUID \
+ {0x8868e871, 0xe4f1, 0x11d3, {0xbc, 0x22, 0x00, 0x80, 0xc7, 0x3c, 0x88, 0x81}}
+
+typedef struct {
+ uint64_t Signature;
+ uint32_t Revision;
+ uint32_t HeaderSize;
+ uint32_t CRC32;
+ uint32_t Reserved;
+} efi_table_header;
+
+typedef struct efi_guid {
+ uint32_t data1;
+ uint16_t data2;
+ uint16_t data3;
+ uint8_t data4[8];
+} efi_guid;
+
+typedef void* efi_handle;
+
+typedef size_t efi_status;
+
+typedef struct {
+ uint8_t addr[32];
+} efi_mac_addr;
+
+typedef struct {
+ uint8_t addr[4];
+} efi_ipv4_addr;
+
+typedef struct {
+ uint8_t addr[16];
+} efi_ipv6_addr;
+
+typedef union {
+ efi_ipv4_addr v4;
+ efi_ipv6_addr v6;
+} efi_ip_addr;
+
+// This really belongs in boot-services.h, but causes circular dependencies with
+// device-path.h.
+typedef enum {
+ EfiReservedMemoryType,
+ EfiLoaderCode,
+ EfiLoaderData,
+ EfiBootServicesCode,
+ EfiBootServicesData,
+ EfiRuntimeServicesCode,
+ EfiRuntimeServicesData,
+ EfiConventionalMemory,
+ EfiUnusableMemory,
+ EfiACPIReclaimMemory,
+ EfiACPIMemoryNVS,
+ EfiMemoryMappedIO,
+ EfiMemoryMappedIOPortSpace,
+ EfiPalCode,
+ EfiPersistentMemory,
+ EfiMaxMemoryType
+} efi_memory_type;
+
+typedef uint64_t efi_physical_addr;
+typedef uint64_t efi_virtual_addr;
+
+typedef void* efi_event;
+
+#define EVT_TIMER 0x80000000
+#define EVT_RUNTIME 0x40000000
+#define EVT_NOTIFY_WAIT 0x00000100
+#define EVT_NOTIFY_SIGNAL 0x00000200
+#define EVT_SIGNAL_EXIT_BOOT_SERVICES 0x00000201
+#define EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE 0x60000202
+
+#define EFI_EVENT_GROUP_EXIT_BOOT_SERVICES \
+ {0x27abf055, 0xb1b8, 0x4c26, {0x80, 0x48, 0x74, 0x8f, 0x37, 0xba, 0xa2, 0xdf}}
+#define EFI_EVENT_GROUP_VIRTUAL_ADDRESS_CHANGE \
+ {0x13fa7698, 0xc831, 0x49c7, {0x87, 0xea, 0x8f, 0x43, 0xfc, 0xc2, 0x51, 0x96}}
+#define EFI_EVENT_GROUP_MEMORY_MAP_CHANGE \
+ {0x78bee926, 0x692f, 0x48fd, {0x9e, 0xdb, 0x01, 0x42, 0x2e, 0xf0, 0xd7, 0xab}}
+#define EFI_EVENT_GROUP_READY_TO_BOOT \
+ {0x7ce88fb3, 0x4bd7, 0x4679, {0x87, 0xa8, 0xa8, 0xd8, 0xde, 0xe5, 0x0d, 0x2b}}
+
+typedef void (*efi_event_notify) (efi_event event, void* ctx) EFIAPI;
+
+typedef enum {
+ TimerCancel,
+ TimerPeriodic,
+ TimerRelative
+} efi_timer_delay;
diff --git a/include/stdint.h b/include/stdint.h
index 6dd18fd..a7e4d5a 100644
--- a/include/stdint.h
+++ b/include/stdint.h
@@ -29,4 +29,4 @@
#define INT_MAX (__INT_MAX__)
typedef int ssize_t;
-
+typedef __CHAR16_TYPE__ char16_t;
diff --git a/include/utils.h b/include/utils.h
index 3a7b225..76f96ff 100644
--- a/include/utils.h
+++ b/include/utils.h
@@ -4,30 +4,40 @@
#pragma once
-void InitGoodies(EFI_HANDLE img, EFI_SYSTEM_TABLE* sys);
+#include <efi/boot-services.h>
+#include <efi/system-table.h>
+#include <efi/types.h>
+#include <efi/protocol/device-path.h>
+#include <efi/protocol/simple-text-output.h>
+
+void InitGoodies(efi_handle img, efi_system_table* sys);
void WaitAnyKey(void);
-void Fatal(const char* msg, EFI_STATUS status);
-CHAR16* HandleToString(EFI_HANDLE handle);
-const char *efi_strerror(EFI_STATUS status);
-const CHAR16 *efi_wstrerror(EFI_STATUS status);
-size_t strlen_16(CHAR16 *str);
+void Fatal(const char* msg, efi_status status);
+char16_t* HandleToString(efi_handle handle);
+const char *efi_strerror(efi_status status);
+const char16_t* efi_wstrerror(efi_status status);
+size_t strlen_16(char16_t* str);
+
+char16_t* DevicePathToStr(efi_device_path_protocol* path);
+
+int CompareGuid(efi_guid* guid1, efi_guid* guid2);
// Convenience wrappers for Open/Close protocol for use by
// UEFI app code that's not a driver model participant
-EFI_STATUS OpenProtocol(EFI_HANDLE h, EFI_GUID* guid, void** ifc);
-EFI_STATUS CloseProtocol(EFI_HANDLE h, EFI_GUID* guid);
+efi_status OpenProtocol(efi_handle h, efi_guid* guid, void** ifc);
+efi_status CloseProtocol(efi_handle h, efi_guid* guid);
-void* LoadFile(CHAR16* filename, UINTN* size_out);
+void* LoadFile(char16_t* filename, size_t* size_out);
-EFI_STATUS FindPCIMMIO(EFI_BOOT_SERVICES* bs, uint8_t cls, uint8_t sub, uint8_t ifc, uint64_t* mmio);
+efi_status FindPCIMMIO(efi_boot_services* bs, uint8_t cls, uint8_t sub, uint8_t ifc, uint64_t* mmio);
// GUIDs
-extern EFI_GUID SimpleFileSystemProtocol;
-extern EFI_GUID FileInfoGUID;
+extern efi_guid SimpleFileSystemProtocol;
+extern efi_guid FileInfoGUID;
// Global Context
-extern EFI_HANDLE gImg;
-extern EFI_SYSTEM_TABLE* gSys;
-extern EFI_BOOT_SERVICES* gBS;
-extern SIMPLE_TEXT_OUTPUT_INTERFACE* gConOut;
+extern efi_handle gImg;
+extern efi_system_table* gSys;
+extern efi_boot_services* gBS;
+extern efi_simple_text_output_protocol* gConOut;
diff --git a/lib/console-printf.c b/lib/console-printf.c
index 3a07f67..e599cae 100644
--- a/lib/console-printf.c
+++ b/lib/console-printf.c
@@ -3,9 +3,6 @@
// found in the LICENSE file.
#include <printf.h>
-
-#include <efi.h>
-#include <efilib.h>
#include <utils.h>
#define PCBUFMAX 126
@@ -14,12 +11,12 @@
typedef struct {
int off;
- CHAR16 buf[PCBUFMAX + 2];
+ char16_t buf[PCBUFMAX + 2];
} _pcstate;
static int _printf_console_out(const char* str, size_t len, void* _state) {
_pcstate* state = _state;
- CHAR16* buf = state->buf;
+ char16_t* buf = state->buf;
int i = state->off;
int n = len;
while (n > 0) {
diff --git a/lib/efi/guids.c b/lib/efi/guids.c
new file mode 100644
index 0000000..20fd51a
--- /dev/null
+++ b/lib/efi/guids.c
@@ -0,0 +1,32 @@
+// Copyright 2016 The Fuchsia Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <efi/protocol/device-path.h>
+#include <efi/protocol/device-path-to-text.h>
+#include <efi/protocol/driver-binding.h>
+#include <efi/protocol/file.h>
+#include <efi/protocol/graphics-output.h>
+#include <efi/protocol/loaded-image.h>
+#include <efi/protocol/managed-network.h>
+#include <efi/protocol/pci-root-bridge-io.h>
+#include <efi/protocol/simple-file-system.h>
+#include <efi/protocol/simple-network.h>
+#include <efi/protocol/simple-text-input.h>
+#include <efi/protocol/simple-text-output.h>
+#include <efi/protocol/usb-io.h>
+
+efi_guid DevicePathProtocol = EFI_DEVICE_PATH_PROTOCOL_GUID;
+efi_guid DevicePathToTextProtocol = EFI_DEVICE_PATH_TO_TEXT_PROTOCOL_GUID;
+efi_guid DriverBindingProtocol = EFI_DRIVER_BINDING_PROTOCOL_GUID;
+efi_guid FileInfoGuid = EFI_FILE_INFO_GUID;
+efi_guid FileSystemInfoGuid = EFI_FILE_SYSTEM_INFO_GUID;
+efi_guid GraphicsOutputProtocol = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
+efi_guid LoadedImageProtocol = EFI_LOADED_IMAGE_PROTOCOL_GUID;
+efi_guid ManagedNetworkProtocol = EFI_MANAGED_NETWORK_PROTOCOL_GUID;
+efi_guid PciRootBridgeIoProtocol = EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_GUID;
+efi_guid SimpleFileSystemProtocol = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID;
+efi_guid SimpleNetworkProtocol = EFI_SIMPLE_NETWORK_PROTOCOL_GUID;
+efi_guid SimpleTextInputProtocol = EFI_SIMPLE_TEXT_INPUT_PROTOCOL_GUID;
+efi_guid SimpleTextOutputProtocol = EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL_GUID;
+efi_guid UsbIoProtocol = EFI_USB_IO_PROTOCOL_GUID;
diff --git a/lib/loadfile.c b/lib/loadfile.c
index aad14ea..bbe5410 100644
--- a/lib/loadfile.c
+++ b/lib/loadfile.c
@@ -2,16 +2,17 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include <efi.h>
-#include <efilib.h>
+#include <efi/protocol/loaded-image.h>
+#include <efi/protocol/simple-file-system.h>
+
#include <utils.h>
#include <stdio.h>
-void* LoadFile(CHAR16* filename, UINTN* _sz) {
- EFI_LOADED_IMAGE* loaded;
- EFI_STATUS r;
+void* LoadFile(char16_t* filename, size_t* _sz) {
+ efi_loaded_image_protocol* loaded;
+ efi_status r;
void* data = NULL;
- UINTN pages = 0;
+ size_t pages = 0;
r = OpenProtocol(gImg, &LoadedImageProtocol, (void**)&loaded);
if (r) {
@@ -25,21 +26,21 @@
printf("Img Base=%lx Size=%lx\n", loaded->ImageBase, loaded->ImageSize);
#endif
- EFI_FILE_IO_INTERFACE* fioi;
- r = OpenProtocol(loaded->DeviceHandle, &SimpleFileSystemProtocol, (void**)&fioi);
+ efi_simple_file_system_protocol* sfs;
+ r = OpenProtocol(loaded->DeviceHandle, &SimpleFileSystemProtocol, (void**)&sfs);
if (r) {
printf("LoadFile: Cannot open SimpleFileSystemProtocol (%s)\n", efi_strerror(r));
goto exit1;
}
- EFI_FILE_HANDLE root;
- r = fioi->OpenVolume(fioi, &root);
+ efi_file_protocol* root;
+ r = sfs->OpenVolume(sfs, &root);
if (r) {
printf("LoadFile: Cannot open root volume (%s)\n", efi_strerror(r));
goto exit2;
}
- EFI_FILE_HANDLE file;
+ efi_file_protocol* file;
r = root->Open(root, &file, filename, EFI_FILE_MODE_READ, 0);
if (r) {
printf("LoadFile: Cannot open file (%s)\n", efi_strerror(r));
@@ -47,16 +48,16 @@
}
char buf[512];
- UINTN sz = sizeof(buf);
- EFI_FILE_INFO* finfo = (void*)buf;
- r = file->GetInfo(file, &FileInfoGUID, &sz, finfo);
+ size_t sz = sizeof(buf);
+ efi_file_info* finfo = (void*)buf;
+ r = file->GetInfo(file, &FileInfoGuid, &sz, finfo);
if (r) {
printf("LoadFile: Cannot get FileInfo (%s)\n", efi_strerror(r));
goto exit3;
}
pages = (finfo->FileSize + 4095) / 4096;
- r = gBS->AllocatePages(AllocateAnyPages, EfiLoaderData, pages, (EFI_PHYSICAL_ADDRESS *)&data);
+ r = gBS->AllocatePages(AllocateAnyPages, EfiLoaderData, pages, (efi_physical_addr *)&data);
if (r) {
printf("LoadFile: Cannot allocate buffer (%s)\n", efi_strerror(r));
data = NULL;
@@ -67,13 +68,13 @@
r = file->Read(file, &sz, data);
if (r) {
printf("LoadFile: Error reading file (%s)\n", efi_strerror(r));
- gBS->FreePages((EFI_PHYSICAL_ADDRESS)data, pages);
+ gBS->FreePages((efi_physical_addr)data, pages);
data = NULL;
goto exit4;
}
if (sz != finfo->FileSize) {
printf("LoadFile: Short read\n");
- gBS->FreePages((EFI_PHYSICAL_ADDRESS)data, pages);
+ gBS->FreePages((efi_physical_addr)data, pages);
data = NULL;
goto exit4;
}
diff --git a/lib/utils.c b/lib/utils.c
index 67107cb..4dc2cd8 100644
--- a/lib/utils.c
+++ b/lib/utils.c
@@ -2,16 +2,20 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include <efi.h>
-#include <efilib.h>
+#include <efi/types.h>
+#include <efi/protocol/device-path-to-text.h>
+#include <efi/protocol/file.h>
+#include <efi/protocol/simple-file-system.h>
-#include <utils.h>
+#include <stdlib.h>
+#include <string.h>
#include <printf.h>
+#include <utils.h>
#define ERR_ENTRY(x) { #x, L"" #x }
typedef struct {
- const char *str;
- const CHAR16 *w_str;
+ const char* str;
+ const char16_t* w_str;
} err_entry_t;
err_entry_t efi_error_labels[] = {
@@ -49,18 +53,12 @@
ERR_ENTRY(EFI_COMPROMISED_DATA),
};
-// Useful GUID Constants Not Defined by -lefi
-EFI_GUID SimpleFileSystemProtocol = SIMPLE_FILE_SYSTEM_PROTOCOL;
-EFI_GUID FileInfoGUID = EFI_FILE_INFO_ID;
+efi_system_table* gSys;
+efi_handle gImg;
+efi_boot_services* gBS;
+efi_simple_text_output_protocol* gConOut;
-// -lefi has its own globals, but this may end up not
-// depending on that, so let's not depend on those
-EFI_SYSTEM_TABLE* gSys;
-EFI_HANDLE gImg;
-EFI_BOOT_SERVICES* gBS;
-SIMPLE_TEXT_OUTPUT_INTERFACE* gConOut;
-
-void InitGoodies(EFI_HANDLE img, EFI_SYSTEM_TABLE* sys) {
+void InitGoodies(efi_handle img, efi_system_table* sys) {
gSys = sys;
gImg = img;
gBS = sys->BootServices;
@@ -68,38 +66,66 @@
}
void WaitAnyKey(void) {
- SIMPLE_INPUT_INTERFACE* sii = gSys->ConIn;
- EFI_INPUT_KEY key;
+ efi_simple_text_input_protocol* sii = gSys->ConIn;
+ efi_input_key key;
while (sii->ReadKeyStroke(sii, &key) != EFI_SUCCESS)
;
}
-void Fatal(const char* msg, EFI_STATUS status) {
+void Fatal(const char* msg, efi_status status) {
printf("\nERROR: %s (%s)\n", msg, efi_strerror(status));
WaitAnyKey();
gBS->Exit(gImg, 1, 0, NULL);
}
-CHAR16* HandleToString(EFI_HANDLE h) {
- EFI_DEVICE_PATH* path = DevicePathFromHandle(h);
- if (path == NULL)
- return L"<NoPath>";
- CHAR16* str = DevicePathToStr(path);
- if (str == NULL)
- return L"<NoString>";
+char16_t* DevicePathToStr(efi_device_path_protocol* path) {
+ efi_device_path_to_text_protocol* prot;
+ efi_status status = gBS->LocateProtocol(&DevicePathToTextProtocol, NULL, (void**)&prot);
+ if (EFI_ERROR(status)) {
+ return NULL;
+ }
+ return prot->ConvertDevicePathToText(path, false, false);
+}
+
+int CompareGuid(efi_guid* guid1, efi_guid* guid2) {
+ return memcmp(guid1, guid2, sizeof(efi_guid));
+}
+
+char16_t* HandleToString(efi_handle h) {
+ efi_device_path_protocol* path;
+ efi_status status = gBS->HandleProtocol(h, &DevicePathProtocol, (void*)&path);
+ if (EFI_ERROR(status)) {
+ char16_t* err;
+ status = gBS->AllocatePool(EfiLoaderData, sizeof(L"<NoPath>"), (void**)&err);
+ if (EFI_ERROR(status)) {
+ return NULL;
+ }
+ gBS->CopyMem(err, L"<NoPath>", sizeof(L"<NoPath>"));
+ return err;
+ }
+ char16_t* str = DevicePathToStr(path);
+ if (str == NULL) {
+ char16_t* err;
+ status = gBS->AllocatePool(EfiLoaderData, sizeof(L"<NoString>"), (void**)&err);
+ if (EFI_ERROR(status)) {
+ return NULL;
+ }
+ gBS->CopyMem(err, L"<NoString>", sizeof(L"<NoString>"));
+ return err;
+ }
return str;
}
-EFI_STATUS OpenProtocol(EFI_HANDLE h, EFI_GUID* guid, void** ifc) {
+efi_status OpenProtocol(efi_handle h, efi_guid* guid, void** ifc) {
return gBS->OpenProtocol(h, guid, ifc, gImg, NULL,
EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL);
}
-EFI_STATUS CloseProtocol(EFI_HANDLE h, EFI_GUID* guid) {
+efi_status CloseProtocol(efi_handle h, efi_guid* guid) {
return gBS->CloseProtocol(h, guid, gImg, NULL);
}
-const char *efi_strerror(EFI_STATUS status)
+const char *efi_strerror(efi_status status)
{
size_t i = (~EFI_ERROR_MASK & status);
if (i < sizeof(efi_error_labels)/sizeof(efi_error_labels[0])) {
@@ -109,7 +135,7 @@
return "<Unknown error>";
}
-const CHAR16 *efi_wstrerror(EFI_STATUS status)
+const char16_t* efi_wstrerror(efi_status status)
{
size_t i = (~EFI_ERROR_MASK & status);
if (i < sizeof(efi_error_labels)/sizeof(efi_error_labels[0])) {
@@ -119,7 +145,7 @@
return L"<Unknown error>";
}
-size_t strlen_16(CHAR16 *str)
+size_t strlen_16(char16_t* str)
{
size_t len = 0;
while (*(str + len) != '\0') {
diff --git a/src/fileio.c b/src/fileio.c
index 2cad9da..3e39970 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -2,48 +2,51 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include <efi.h>
-#include <efilib.h>
+#include <efi/system-table.h>
+#include <efi/types.h>
+#include <efi/protocol/loaded-image.h>
+#include <efi/protocol/simple-file-system.h>
+
+#include <stdio.h>
#include <utils.h>
-EFI_STATUS efi_main(EFI_HANDLE img, EFI_SYSTEM_TABLE* sys) {
- EFI_LOADED_IMAGE* loaded;
- EFI_STATUS r;
+efi_status efi_main(efi_handle img, efi_system_table* sys) {
+ efi_loaded_image_protocol* loaded;
+ efi_status r;
- InitializeLib(img, sys);
InitGoodies(img, sys);
- Print(L"Hello, EFI World\n");
+ printf("Hello, EFI World\n");
r = OpenProtocol(img, &LoadedImageProtocol, (void**)&loaded);
if (r)
Fatal("LoadedImageProtocol", r);
- Print(L"Img DeviceHandle='%s'\n", HandleToString(loaded->DeviceHandle));
- Print(L"Img FilePath='%s'\n", DevicePathToStr(loaded->FilePath));
- Print(L"Img Base=%lx Size=%lx\n", loaded->ImageBase, loaded->ImageSize);
+ printf("Img DeviceHandle='%ls'\n", HandleToString(loaded->DeviceHandle));
+ printf("Img FilePath='%ls'\n", DevicePathToStr(loaded->FilePath));
+ printf("Img Base=%p Size=%lx\n", loaded->ImageBase, loaded->ImageSize);
- EFI_FILE_IO_INTERFACE* fioi;
- r = OpenProtocol(loaded->DeviceHandle, &SimpleFileSystemProtocol, (void**)&fioi);
+ efi_simple_file_system_protocol* sfs;
+ r = OpenProtocol(loaded->DeviceHandle, &SimpleFileSystemProtocol, (void**)&sfs);
if (r)
Fatal("SimpleFileSystemProtocol", r);
- EFI_FILE_HANDLE root;
- r = fioi->OpenVolume(fioi, &root);
+ efi_file_protocol* root;
+ r = sfs->OpenVolume(sfs, &root);
if (r)
Fatal("OpenVolume", r);
- EFI_FILE_HANDLE file;
+ efi_file_protocol* file;
r = root->Open(root, &file, L"README.txt", EFI_FILE_MODE_READ, 0);
if (r == EFI_SUCCESS) {
char buf[512];
- UINTN sz = sizeof(buf);
- EFI_FILE_INFO* finfo = (void*)buf;
- r = file->GetInfo(file, &FileInfoGUID, &sz, finfo);
+ size_t sz = sizeof(buf);
+ efi_file_info* finfo = (void*)buf;
+ r = file->GetInfo(file, &FileInfoGuid, &sz, finfo);
if (r)
Fatal("GetInfo", r);
- Print(L"FileSize %ld\n", finfo->FileSize);
+ printf("FileSize %ld\n", finfo->FileSize);
sz = sizeof(buf) - 1;
r = file->Read(file, &sz, buf);
@@ -52,7 +55,7 @@
char* x = buf;
while (sz-- > 0)
- Print(L"%c", (CHAR16)*x++);
+ printf("%c", *x++);
file->Close(file);
}
diff --git a/src/hello.c b/src/hello.c
index 551e354..45c62bb 100644
--- a/src/hello.c
+++ b/src/hello.c
@@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include <efi.h>
+#include <efi/types.h>
-EFI_STATUS efi_main(EFI_HANDLE img, EFI_SYSTEM_TABLE* sys) {
- SIMPLE_TEXT_OUTPUT_INTERFACE* ConOut = sys->ConOut;
+efi_status efi_main(efi_handle img, efi_system_table* sys) {
+ efi_simple_text_output_protocol* ConOut = sys->ConOut;
ConOut->OutputString(ConOut, L"Hello, EFI World!\r\n");
return EFI_SUCCESS;
}
diff --git a/src/magenta.c b/src/magenta.c
index 5d7dfa4..e4e1b0a 100644
--- a/src/magenta.c
+++ b/src/magenta.c
@@ -4,18 +4,18 @@
#include <magenta.h>
-#include <efilib.h>
+#include <efi/protocol/graphics-output.h>
+
#include <stdio.h>
#include <string.h>
#include <utils.h>
-static EFI_GUID GraphicsOutputProtocol = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
-static EFI_GUID AcpiTableGUID = ACPI_TABLE_GUID;
-static EFI_GUID Acpi2TableGUID = ACPI_20_TABLE_GUID;
-static UINT8 ACPI_RSD_PTR[8] = "RSD PTR ";
+static efi_guid AcpiTableGUID = ACPI_TABLE_GUID;
+static efi_guid Acpi2TableGUID = ACPI_20_TABLE_GUID;
+static uint8_t ACPI_RSD_PTR[8] = "RSD PTR ";
-uint32_t find_acpi_root(EFI_HANDLE img, EFI_SYSTEM_TABLE* sys) {
- EFI_CONFIGURATION_TABLE* cfgtab = sys->ConfigurationTable;
+uint32_t find_acpi_root(efi_handle img, efi_system_table* sys) {
+ efi_configuration_table* cfgtab = sys->ConfigurationTable;
int i;
for (i = 0; i < sys->NumberOfTableEntries; i++) {
@@ -24,7 +24,7 @@
// not an ACPI table
continue;
}
- if (CompareMem(cfgtab[i].VendorTable, ACPI_RSD_PTR, 8)) {
+ if (memcmp(cfgtab[i].VendorTable, ACPI_RSD_PTR, 8)) {
// not the Root Description Pointer
continue;
}
@@ -50,9 +50,9 @@
};
struct e820entry {
- UINT64 addr;
- UINT64 size;
- UINT32 type;
+ uint64_t addr;
+ uint64_t size;
+ uint32_t type;
} __attribute__((packed));
static unsigned e820type(unsigned uefi_mem_type) {
@@ -91,17 +91,17 @@
static unsigned char scratch[32768];
static struct e820entry e820table[128];
-static int process_memory_map(EFI_SYSTEM_TABLE* sys, UINTN* _key, int silent) {
- EFI_MEMORY_DESCRIPTOR* mmap;
+static int process_memory_map(efi_system_table* sys, size_t* _key, int silent) {
+ efi_memory_descriptor* mmap;
struct e820entry* entry = e820table;
- UINTN msize, off;
- UINTN mkey, dsize;
- UINT32 dversion;
+ size_t msize, off;
+ size_t mkey, dsize;
+ uint32_t dversion;
unsigned n, type;
- EFI_STATUS r;
+ efi_status r;
msize = sizeof(scratch);
- mmap = (EFI_MEMORY_DESCRIPTOR*)scratch;
+ mmap = (efi_memory_descriptor*)scratch;
mkey = dsize = dversion = 0;
r = sys->BootServices->GetMemoryMap(&msize, mmap, &mkey, &dsize, &dversion);
if (!silent)
@@ -115,7 +115,7 @@
return -1;
}
for (off = 0, n = 0; off < msize; off += dsize) {
- mmap = (EFI_MEMORY_DESCRIPTOR*)(scratch + off);
+ mmap = (efi_memory_descriptor*)(scratch + off);
type = e820type(mmap->Type);
if (type == E820_IGNORE) {
continue;
@@ -166,9 +166,9 @@
#define ZP_MAGIC_VALUE 0xDBC64323
-#define ZP8(p, off) (*((UINT8*)((p) + (off))))
-#define ZP16(p, off) (*((UINT16*)((p) + (off))))
-#define ZP32(p, off) (*((UINT32*)((p) + (off))))
+#define ZP8(p, off) (*((uint8_t*)((p) + (off))))
+#define ZP16(p, off) (*((uint16_t*)((p) + (off))))
+#define ZP32(p, off) (*((uint32_t*)((p) + (off))))
static void install_memmap(kernel_t* k, struct e820entry* memmap, unsigned count) {
memcpy(k->zeropage + ZP_E820_TABLE, memmap, sizeof(*memmap) * count);
@@ -177,7 +177,7 @@
static void start_kernel(kernel_t* k) {
// 64bit entry is at offset 0x200
- UINT64 entry = (UINT64)(k->image + 0x200);
+ uint64_t entry = (uint64_t)(k->image + 0x200);
// ebx = 0, ebp = 0, edi = 0, esi = zeropage
__asm__ __volatile__(
@@ -190,11 +190,11 @@
;
}
-static int load_kernel(EFI_BOOT_SERVICES* bs, uint8_t* image, size_t sz, kernel_t* k) {
- UINT32 setup_sz;
- UINT32 image_sz;
- UINT32 setup_end;
- EFI_PHYSICAL_ADDRESS mem;
+static int load_kernel(efi_boot_services* bs, uint8_t* image, size_t sz, kernel_t* k) {
+ uint32_t setup_sz;
+ uint32_t image_sz;
+ uint32_t setup_end;
+ efi_physical_addr mem;
k->zeropage = NULL;
k->cmdline = NULL;
@@ -248,10 +248,10 @@
k->image = (void*)mem;
// setup zero page, copy setup header from kernel binary
- ZeroMem(k->zeropage, 4096);
- CopyMem(k->zeropage + ZP_SETUP, image + ZP_SETUP, setup_end - ZP_SETUP);
+ memset(k->zeropage, 0, 4096);
+ memcpy(k->zeropage + ZP_SETUP, image + ZP_SETUP, setup_end - ZP_SETUP);
- CopyMem(k->image, image + setup_sz, image_sz);
+ memcpy(k->image, image + setup_sz, image_sz);
// empty commandline for now
ZP32(k->zeropage, ZP_CMDLINE) = (uint64_t)k->cmdline;
@@ -270,28 +270,28 @@
return 0;
fail:
if (k->image) {
- bs->FreePages((EFI_PHYSICAL_ADDRESS)k->image, k->pages);
+ bs->FreePages((efi_physical_addr)k->image, k->pages);
}
if (k->cmdline) {
- bs->FreePages((EFI_PHYSICAL_ADDRESS)k->cmdline, 1);
+ bs->FreePages((efi_physical_addr)k->cmdline, 1);
}
if (k->zeropage) {
- bs->FreePages((EFI_PHYSICAL_ADDRESS)k->zeropage, 1);
+ bs->FreePages((efi_physical_addr)k->zeropage, 1);
}
return -1;
}
-int boot_kernel(EFI_HANDLE img, EFI_SYSTEM_TABLE* sys,
+int boot_kernel(efi_handle img, efi_system_table* sys,
void* image, size_t sz, void* ramdisk, size_t rsz,
void* cmdline, size_t csz, void* cmdline2, size_t csz2) {
- EFI_BOOT_SERVICES* bs = sys->BootServices;
+ efi_boot_services* bs = sys->BootServices;
kernel_t kernel;
- EFI_STATUS r;
- UINTN key;
+ efi_status r;
+ size_t key;
int n, i;
- EFI_GRAPHICS_OUTPUT_PROTOCOL* gop;
+ efi_graphics_output_protocol* gop;
bs->LocateProtocol(&GraphicsOutputProtocol, NULL, (void**)&gop);
printf("boot_kernel() from %p (%ld bytes)\n", image, sz);
@@ -307,10 +307,10 @@
ZP32(kernel.zeropage, ZP_EXTRA_MAGIC) = ZP_MAGIC_VALUE;
ZP32(kernel.zeropage, ZP_ACPI_RSD) = find_acpi_root(img, sys);
- ZP32(kernel.zeropage, ZP_FB_BASE) = (UINT32)gop->Mode->FrameBufferBase;
- ZP32(kernel.zeropage, ZP_FB_WIDTH) = (UINT32)gop->Mode->Info->HorizontalResolution;
- ZP32(kernel.zeropage, ZP_FB_HEIGHT) = (UINT32)gop->Mode->Info->VerticalResolution;
- ZP32(kernel.zeropage, ZP_FB_STRIDE) = (UINT32)gop->Mode->Info->PixelsPerScanLine;
+ ZP32(kernel.zeropage, ZP_FB_BASE) = (uint32_t)gop->Mode->FrameBufferBase;
+ ZP32(kernel.zeropage, ZP_FB_WIDTH) = (uint32_t)gop->Mode->Info->HorizontalResolution;
+ ZP32(kernel.zeropage, ZP_FB_HEIGHT) = (uint32_t)gop->Mode->Info->VerticalResolution;
+ ZP32(kernel.zeropage, ZP_FB_STRIDE) = (uint32_t)gop->Mode->Info->PixelsPerScanLine;
ZP32(kernel.zeropage, ZP_FB_FORMAT) = 5; // XRGB32
ZP32(kernel.zeropage, ZP_FB_REGBASE) = 0;
ZP32(kernel.zeropage, ZP_FB_SIZE) = 256 * 1024 * 1024;
diff --git a/src/magenta.h b/src/magenta.h
index c3ae7db..1c92213 100644
--- a/src/magenta.h
+++ b/src/magenta.h
@@ -2,15 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include <efi.h>
+#include <efi/types.h>
+#include <efi/system-table.h>
typedef struct {
- UINT8* zeropage;
- UINT8* cmdline;
+ uint8_t* zeropage;
+ uint8_t* cmdline;
void* image;
- UINT32 pages;
+ uint32_t pages;
} kernel_t;
-int boot_kernel(EFI_HANDLE img, EFI_SYSTEM_TABLE* sys,
+int boot_kernel(efi_handle img, efi_system_table* sys,
void* image, size_t sz, void* ramdisk, size_t rsz,
void* cmdline, size_t csz, void* cmdline2, size_t csz2);
diff --git a/src/netifc.c b/src/netifc.c
index d5a4797..749682c 100644
--- a/src/netifc.c
+++ b/src/netifc.c
@@ -2,8 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include <efi.h>
-#include <efilib.h>
+#include <efi/protocol/simple-network.h>
#include <stdio.h>
#include <string.h>
@@ -12,10 +11,10 @@
#include <inet6.h>
#include <netifc.h>
-static EFI_SIMPLE_NETWORK* snp;
+static efi_simple_network_protocol* snp;
#define MAX_FILTER 8
-static EFI_MAC_ADDRESS mcast_filters[MAX_FILTER];
+static efi_mac_addr mcast_filters[MAX_FILTER];
static unsigned mcast_filter_count = 0;
#define NUM_BUFFER_PAGES 8
@@ -30,7 +29,7 @@
uint8_t data[0];
};
-static EFI_PHYSICAL_ADDRESS eth_buffers_base = 0;
+static efi_physical_addr eth_buffers_base = 0;
static eth_buffer* eth_buffers = NULL;
void* eth_get_buffer(size_t sz) {
@@ -60,7 +59,7 @@
}
int eth_send(void* data, size_t len) {
- EFI_STATUS r;
+ efi_status r;
if ((r = snp->Transmit(snp, 0, len, (void*)data, NULL, NULL, NULL))) {
eth_put_buffer(data);
@@ -77,7 +76,7 @@
printf("RcvMask/RcvCfg/MaxMcast/NumMcast %d %d %d %d\n",
snp->Mode->ReceiveFilterMask, snp->Mode->ReceiveFilterSetting,
snp->Mode->MaxMCastFilterCount, snp->Mode->MCastFilterCount);
- UINT8* x = snp->Mode->CurrentAddress.Addr;
+ uint8_t* x = snp->Mode->CurrentAddress.addr;
printf("MacAddr %02x:%02x:%02x:%02x:%02x:%02x\n",
x[0], x[1], x[2], x[3], x[4], x[5]);
printf("SetMac/MultiTx/LinkDetect/Link %d %d %d %d\n",
@@ -95,7 +94,7 @@
return 0;
}
-static EFI_EVENT net_timer = NULL;
+static efi_event net_timer = NULL;
#define TIMER_MS(n) (((uint64_t)(n)) * 10000UL)
@@ -118,12 +117,12 @@
/* Search the available network interfaces via SimpleNetworkProtocol handles
* and find the first valid one with a Link detected */
-EFI_SIMPLE_NETWORK *netifc_find_available(void) {
- EFI_BOOT_SERVICES* bs = gSys->BootServices;
- EFI_STATUS ret;
- EFI_SIMPLE_NETWORK *cur_snp = NULL;
- EFI_HANDLE handles[32];
- CHAR16 *paths[32];
+efi_simple_network_protocol* netifc_find_available(void) {
+ efi_boot_services* bs = gSys->BootServices;
+ efi_status ret;
+ efi_simple_network_protocol* cur_snp = NULL;
+ efi_handle handles[32];
+ char16_t *paths[32];
size_t nic_cnt = 0;
size_t sz = sizeof(handles);
uint32_t last_parent = 0;
@@ -137,7 +136,7 @@
return NULL;
}
- nic_cnt = sz / sizeof(EFI_HANDLE);
+ nic_cnt = sz / sizeof(efi_handle);
for (size_t i = 0; i < nic_cnt; i++) {
paths[i] = HandleToString(handles[i]);
}
@@ -155,7 +154,7 @@
}
}
- Print(L"%s: ", paths[i]);
+ printf("%ls: ", paths[i]);
ret = bs->HandleProtocol(handles[i], &SimpleNetworkProtocol, (void**)&cur_snp);
if (ret) {
printf("Failed to open (%s)\n", efi_strerror(ret));
@@ -205,8 +204,8 @@
}
int netifc_open(void) {
- EFI_BOOT_SERVICES* bs = gSys->BootServices;
- EFI_STATUS ret;
+ efi_boot_services* bs = gSys->BootServices;
+ efi_status ret;
int j;
bs->CreateEvent(EVT_TIMER, TPL_CALLBACK, NULL, NULL, &net_timer);
@@ -230,7 +229,7 @@
ptr += 2048;
}
- ip6_init(snp->Mode->CurrentAddress.Addr);
+ ip6_init(snp->Mode->CurrentAddress.addr);
ret = snp->ReceiveFilters(snp,
EFI_SIMPLE_NETWORK_RECEIVE_UNICAST |
@@ -290,11 +289,11 @@
}
void netifc_poll(void) {
- UINT8 data[1514];
- EFI_STATUS r;
- UINTN hsz, bsz;
- UINT32 irq;
- VOID* txdone;
+ uint8_t data[1514];
+ efi_status r;
+ size_t hsz, bsz;
+ uint32_t irq;
+ void* txdone;
if ((r = snp->GetStatus(snp, &irq, &txdone))) {
return;
diff --git a/src/osboot.c b/src/osboot.c
index 193c5ee..5811276 100644
--- a/src/osboot.c
+++ b/src/osboot.c
@@ -2,19 +2,21 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include <efi.h>
-#include <efilib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <efi/boot-services.h>
+#include <efi/system-table.h>
+#include <efi/protocol/device-path.h>
+#include <efi/protocol/graphics-output.h>
+#include <efi/protocol/simple-text-input.h>
+
#include <cmdline.h>
#include <magenta.h>
#include <netboot.h>
#include <utils.h>
-static EFI_GUID GraphicsOutputProtocol = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
-
#define DEFAULT_TIMEOUT 3
#define KBUFSIZE (32*1024*1024)
@@ -49,15 +51,15 @@
BOOT_DEVICE_LOCAL,
};
-int boot_prompt(EFI_SYSTEM_TABLE* sys, int timeout_s) {
- EFI_BOOT_SERVICES* bs = sys->BootServices;
+int boot_prompt(efi_system_table* sys, int timeout_s) {
+ efi_boot_services* bs = sys->BootServices;
- EFI_EVENT TimerEvent;
- EFI_EVENT WaitList[2];
+ efi_event TimerEvent;
+ efi_event WaitList[2];
- EFI_STATUS status;
- UINTN Index;
- EFI_INPUT_KEY key;
+ efi_status status;
+ size_t Index;
+ efi_input_key key;
memset(&key, 0, sizeof(key));
status = bs->CreateEvent(EVT_TIMER, 0, NULL, NULL, &TimerEvent);
@@ -117,7 +119,7 @@
return BOOT_DEVICE_NETBOOT;
}
-void set_graphics_mode(EFI_SYSTEM_TABLE* sys, EFI_GRAPHICS_OUTPUT_PROTOCOL* gop, char* cmdline) {
+void set_graphics_mode(efi_system_table* sys, efi_graphics_output_protocol* gop, char* cmdline) {
if (!gop || !cmdline) return;
char res[11];
@@ -134,12 +136,12 @@
vres = atol(x);
if (!hres || !vres) return;
- UINT32 max_mode = gop->Mode->MaxMode;
+ uint32_t max_mode = gop->Mode->MaxMode;
for (int i = 0; i < max_mode; i++) {
- EFI_GRAPHICS_OUTPUT_MODE_INFORMATION* mode_info;
- UINTN info_size = 0;
- EFI_STATUS status = gop->QueryMode(gop, i, &info_size, &mode_info);
+ efi_graphics_output_mode_information* mode_info;
+ size_t info_size = 0;
+ efi_status status = gop->QueryMode(gop, i, &info_size, &mode_info);
if (EFI_ERROR(status)) {
printf("Could not retrieve mode %d: %s\n", i, efi_strerror(status));
continue;
@@ -158,17 +160,17 @@
sys->BootServices->Stall(5000000);
}
-void draw_logo(EFI_GRAPHICS_OUTPUT_PROTOCOL* gop) {
+void draw_logo(efi_graphics_output_protocol* gop) {
if (!gop) return;
const uint32_t h_res = gop->Mode->Info->HorizontalResolution;
const uint32_t v_res = gop->Mode->Info->VerticalResolution;
- EFI_GRAPHICS_OUTPUT_BLT_PIXEL fuchsia = {
+ efi_graphics_output_blt_pixel fuchsia = {
.Red = 0xFF,
.Green = 0x0,
.Blue = 0xFF,
};
- EFI_GRAPHICS_OUTPUT_BLT_PIXEL black = {
+ efi_graphics_output_blt_pixel black = {
.Red = 0x0,
.Green = 0x0,
.Blue = 0x0
@@ -181,10 +183,10 @@
gop->Blt(gop, &fuchsia, EfiBltVideoFill, 0, 0, 0, v_res - (v_res/100), h_res, v_res/100, 0);
}
-void do_netboot(EFI_HANDLE img, EFI_SYSTEM_TABLE* sys) {
- EFI_BOOT_SERVICES* bs = sys->BootServices;
+void do_netboot(efi_handle img, efi_system_table* sys) {
+ efi_boot_services* bs = sys->BootServices;
- EFI_PHYSICAL_ADDRESS mem = 0xFFFFFFFF;
+ efi_physical_addr mem = 0xFFFFFFFF;
if (bs->AllocatePages(AllocateMaxAddress, EfiLoaderData, KBUFSIZE / 4096, &mem)) {
printf("Failed to allocate network io buffer\n");
return;
@@ -206,7 +208,7 @@
cmdline[0] = 0;
printf("\nNetBoot Server Started...\n\n");
- EFI_TPL prev_tpl = bs->RaiseTPL(TPL_NOTIFY);
+ efi_tpl prev_tpl = bs->RaiseTPL(TPL_NOTIFY);
for (;;) {
int n = netboot_poll();
if (n < 1) {
@@ -218,34 +220,34 @@
}
uint8_t* x = nbkernel.data;
if ((x[0] == 'M') && (x[1] == 'Z') && (x[0x80] == 'P') && (x[0x81] == 'E')) {
- UINTN exitdatasize;
- EFI_STATUS r;
- EFI_HANDLE h;
+ size_t exitdatasize;
+ efi_status r;
+ efi_handle h;
- MEMMAP_DEVICE_PATH mempath[2] = {
+ efi_device_path_hw_memmap mempath[2] = {
{
.Header = {
- .Type = HARDWARE_DEVICE_PATH,
- .SubType = HW_MEMMAP_DP,
- .Length = { (UINT8)(sizeof(MEMMAP_DEVICE_PATH) & 0xff),
- (UINT8)((sizeof(MEMMAP_DEVICE_PATH) >> 8) & 0xff), },
+ .Type = DEVICE_PATH_HARDWARE,
+ .SubType = DEVICE_PATH_HW_MEMMAP,
+ .Length = { (uint8_t)(sizeof(efi_device_path_hw_memmap) & 0xff),
+ (uint8_t)((sizeof(efi_device_path_hw_memmap) >> 8) & 0xff), },
},
.MemoryType = EfiLoaderData,
- .StartingAddress = (EFI_PHYSICAL_ADDRESS)nbkernel.data,
- .EndingAddress = (EFI_PHYSICAL_ADDRESS)(nbkernel.data + nbkernel.offset),
+ .StartAddress = (efi_physical_addr)nbkernel.data,
+ .EndAddress = (efi_physical_addr)(nbkernel.data + nbkernel.offset),
},
{
.Header = {
- .Type = END_DEVICE_PATH_TYPE,
- .SubType = END_ENTIRE_DEVICE_PATH_SUBTYPE,
- .Length = { (UINT8)(sizeof(EFI_DEVICE_PATH) & 0xff),
- (UINT8)((sizeof(EFI_DEVICE_PATH) >> 8) & 0xff), },
+ .Type = DEVICE_PATH_END,
+ .SubType = DEVICE_PATH_ENTIRE_END,
+ .Length = { (uint8_t)(sizeof(efi_device_path_protocol) & 0xff),
+ (uint8_t)((sizeof(efi_device_path_protocol) >> 8) & 0xff), },
},
},
};
printf("Attempting to run EFI binary...\n");
- r = bs->LoadImage(FALSE, img, (EFI_DEVICE_PATH*)mempath, (void*)nbkernel.data, nbkernel.offset, &h);
+ r = bs->LoadImage(false, img, (efi_device_path_protocol*)mempath, (void*)nbkernel.data, nbkernel.offset, &h);
if (EFI_ERROR(r)) {
printf("LoadImage Failed (%s)\n", efi_strerror(r));
continue;
@@ -269,7 +271,7 @@
cmdline[nbcmdline.offset] = 0;
// maybe it's a kernel image?
- EFI_GRAPHICS_OUTPUT_PROTOCOL* gop;
+ efi_graphics_output_protocol* gop;
bs->LocateProtocol(&GraphicsOutputProtocol, NULL, (void**)&gop);
set_graphics_mode(sys, gop, cmdline);
@@ -280,10 +282,9 @@
}
}
-EFI_STATUS efi_main(EFI_HANDLE img, EFI_SYSTEM_TABLE* sys) {
- EFI_BOOT_SERVICES* bs = sys->BootServices;
+efi_status efi_main(efi_handle img, efi_system_table* sys) {
+ efi_boot_services* bs = sys->BootServices;
- InitializeLib(img, sys);
InitGoodies(img, sys);
uint64_t mmio;
@@ -294,14 +295,14 @@
}
// Load the cmdline
- UINTN csz = 0;
+ size_t csz = 0;
char* cmdline = LoadFile(L"cmdline", &csz);
if (cmdline) {
cmdline[csz] = '\0';
printf("cmdline: %s\n", cmdline);
}
- EFI_GRAPHICS_OUTPUT_PROTOCOL* gop;
+ efi_graphics_output_protocol* gop;
bs->LocateProtocol(&GraphicsOutputProtocol, NULL, (void**)&gop);
set_graphics_mode(sys, gop, cmdline);
draw_logo(gop);
@@ -314,7 +315,7 @@
// Look for a kernel image on disk
// TODO: use the filesystem protocol
- UINTN ksz = 0;
+ size_t ksz = 0;
void* kernel = LoadFile(L"magenta.bin", &ksz);
if (!have_network && kernel == NULL) {
@@ -339,7 +340,7 @@
do_netboot(img, sys);
break;
case BOOT_DEVICE_LOCAL: {
- UINTN rsz = 0;
+ size_t rsz = 0;
void* ramdisk = LoadFile(L"ramdisk.bin", &rsz);
boot_kernel(img, sys, kernel, ksz, ramdisk, rsz,
cmdline, csz, cmdextra, strlen(cmdextra));
diff --git a/src/pci.c b/src/pci.c
index 6bf0dfa..2aa0fd9 100644
--- a/src/pci.c
+++ b/src/pci.c
@@ -2,8 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include <efi.h>
-#include <efilib.h>
+#include <efi/types.h>
#include <efi/protocol/pci-root-bridge-io.h>
#include <stdio.h>
@@ -54,10 +53,10 @@
#define PCI_MAX_DEVICES 32
#define PCI_MAX_FUNCS 8
-EFI_STATUS FindPCIMMIO(EFI_BOOT_SERVICES* bs, uint8_t cls, uint8_t sub, uint8_t ifc, uint64_t* mmio) {
- UINTN num_handles;
- EFI_HANDLE* handles;
- EFI_STATUS status = bs->LocateHandleBuffer(ByProtocol, &PciRootBridgeIoProtocol,
+efi_status FindPCIMMIO(efi_boot_services* bs, uint8_t cls, uint8_t sub, uint8_t ifc, uint64_t* mmio) {
+ size_t num_handles;
+ efi_handle* handles;
+ efi_status status = bs->LocateHandleBuffer(ByProtocol, &PciRootBridgeIoProtocol,
NULL, &num_handles, &handles);
if (EFI_ERROR(status)) {
printf("Could not find PCI root bridge IO protocol: %s\n", efi_strerror(status));
@@ -66,7 +65,7 @@
for (int i = 0; i < num_handles; i++) {
printf("handle %d\n", i);
- EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL* iodev;
+ efi_pci_root_bridge_io_protocol* iodev;
status = bs->HandleProtocol(handles[i], &PciRootBridgeIoProtocol, (void**)&iodev);
if (EFI_ERROR(status)) {
printf("Could not get protocol for handle %d: %s\n", i, efi_strerror(status));
@@ -79,10 +78,10 @@
continue;
}
- UINT16 min_bus, max_bus;
+ uint16_t min_bus, max_bus;
while (descriptors->descriptor != ACPI_END_TAG_DESCRIPTOR) {
- min_bus = (UINT16)descriptors->addrrange_minimum;
- max_bus = (UINT16)descriptors->addrrange_maximum;
+ min_bus = (uint16_t)descriptors->addrrange_minimum;
+ max_bus = (uint16_t)descriptors->addrrange_maximum;
if (descriptors->res_type != ACPI_ADDRESS_SPACE_TYPE_BUS) {
descriptors++;
@@ -94,7 +93,7 @@
for (int func = 0; func < PCI_MAX_FUNCS; func++) {
pci_common_header_t pci_hdr;
bs->SetMem(&pci_hdr, sizeof(pci_hdr), 0);
- UINT64 address = (UINT64)((bus << 24) + (dev << 16) + (func << 8));
+ uint64_t address = (uint64_t)((bus << 24) + (dev << 16) + (func << 8));
status = iodev->Pci.Read(iodev, EfiPciWidthUint16, address, sizeof(pci_hdr) / 2, &pci_hdr);
if (EFI_ERROR(status)) {
printf("could not read pci configuration for bus %d dev %d func %d: %s\n",
diff --git a/src/showmem.c b/src/showmem.c
index e8f7e16..d260ad8 100644
--- a/src/showmem.c
+++ b/src/showmem.c
@@ -2,12 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include <efi.h>
-#include <efilib.h>
+#include <efi/types.h>
+#include <efi/system-table.h>
#include <printf.h>
-static const char* MemTypeName(UINT32 type, char* buf) {
+static const char* MemTypeName(uint32_t type, char* buf) {
switch (type) {
case EfiReservedMemoryType:
return "Reserved";
@@ -45,16 +45,16 @@
static unsigned char scratch[4096];
-static void dump_memmap(EFI_SYSTEM_TABLE* systab) {
- EFI_STATUS r;
- UINTN msize, off;
- EFI_MEMORY_DESCRIPTOR* mmap;
- UINTN mkey, dsize;
- UINT32 dversion;
+static void dump_memmap(efi_system_table* systab) {
+ efi_status r;
+ size_t msize, off;
+ efi_memory_descriptor* mmap;
+ size_t mkey, dsize;
+ uint32_t dversion;
char tmp[32];
msize = sizeof(scratch);
- mmap = (EFI_MEMORY_DESCRIPTOR*)scratch;
+ mmap = (efi_memory_descriptor*)scratch;
mkey = dsize = dversion;
r = systab->BootServices->GetMemoryMap(&msize, mmap, &mkey, &dsize, &dversion);
printf("r=%lx msz=%lx key=%lx dsz=%lx dvn=%x\n",
@@ -63,7 +63,7 @@
return;
}
for (off = 0; off < msize; off += dsize) {
- mmap = (EFI_MEMORY_DESCRIPTOR*)(scratch + off);
+ mmap = (efi_memory_descriptor*)(scratch + off);
printf("%016lx %016lx %08lx %c %04lx %s\n",
mmap->PhysicalStart, mmap->VirtualStart,
mmap->NumberOfPages,
@@ -75,8 +75,7 @@
#include <utils.h>
-EFI_STATUS efi_main(EFI_HANDLE img, EFI_SYSTEM_TABLE* sys) {
- InitializeLib(img, sys);
+efi_status efi_main(efi_handle img, efi_system_table* sys) {
InitGoodies(img, sys);
dump_memmap(sys);
WaitAnyKey();
diff --git a/src/usbtest.c b/src/usbtest.c
index cd6cff9..fddd734 100644
--- a/src/usbtest.c
+++ b/src/usbtest.c
@@ -2,23 +2,21 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include <efi.h>
-#include <efilib.h>
+#include <efi/types.h>
+#include <efi/protocol/device-path.h>
+#include <efi/protocol/driver-binding.h>
+#include <efi/protocol/usb-io.h>
#include <utils.h>
#include <stdio.h>
-#include <Protocol/UsbIo.h>
+EFIAPI efi_status MyDriverSupported(
+ efi_driver_binding_protocol* self, efi_handle ctlr,
+ efi_device_path_protocol* path) {
-EFI_GUID UsbIoProtocol = EFI_USB_IO_PROTOCOL_GUID;
-
-EFIAPI EFI_STATUS MyDriverSupported(
- EFI_DRIVER_BINDING* self, EFI_HANDLE ctlr,
- EFI_DEVICE_PATH* path) {
-
- EFI_USB_DEVICE_DESCRIPTOR dev;
- EFI_USB_IO_PROTOCOL* usbio;
- EFI_STATUS r;
+ efi_usb_device_descriptor dev;
+ efi_usb_io_protocol* usbio;
+ efi_status r;
r = gBS->OpenProtocol(ctlr, &UsbIoProtocol,
(void**)&usbio, self->DriverBindingHandle,
@@ -37,12 +35,12 @@
return EFI_UNSUPPORTED;
}
-EFIAPI EFI_STATUS MyDriverStart(
- EFI_DRIVER_BINDING* self, EFI_HANDLE ctlr,
- EFI_DEVICE_PATH* path) {
- EFI_STATUS r;
+EFIAPI efi_status MyDriverStart(
+ efi_driver_binding_protocol* self, efi_handle ctlr,
+ efi_device_path_protocol* path) {
+ efi_status r;
- EFI_USB_IO_PROTOCOL* usbio;
+ efi_usb_io_protocol* usbio;
printf("Start! ctlr=%p\n", ctlr);
@@ -60,9 +58,9 @@
return EFI_SUCCESS;
}
-EFIAPI EFI_STATUS MyDriverStop(
- EFI_DRIVER_BINDING* self, EFI_HANDLE ctlr,
- UINTN count, EFI_HANDLE* children) {
+EFIAPI efi_status MyDriverStop(
+ efi_driver_binding_protocol* self, efi_handle ctlr,
+ size_t count, efi_handle* children) {
printf("Stop! ctlr=%p\n", ctlr);
@@ -73,7 +71,7 @@
return EFI_SUCCESS;
}
-static EFI_DRIVER_BINDING MyDriver = {
+static efi_driver_binding_protocol MyDriver = {
.Supported = MyDriverSupported,
.Start = MyDriverStart,
.Stop = MyDriverStop,
@@ -82,18 +80,18 @@
.DriverBindingHandle = NULL,
};
-void InstallMyDriver(EFI_HANDLE img, EFI_SYSTEM_TABLE* sys) {
- EFI_BOOT_SERVICES* bs = sys->BootServices;
- EFI_HANDLE* list;
- UINTN count, i;
- EFI_STATUS r;
+void InstallMyDriver(efi_handle img, efi_system_table* sys) {
+ efi_boot_services* bs = sys->BootServices;
+ efi_handle* list;
+ size_t count, i;
+ efi_status r;
MyDriver.ImageHandle = img;
MyDriver.DriverBindingHandle = img;
r = bs->InstallProtocolInterface(&img, &DriverBindingProtocol,
EFI_NATIVE_INTERFACE, &MyDriver);
if (r) {
- Print(L"DriverBinding failed %lx\n", r);
+ printf("DriverBinding failed %lx\n", r);
return;
}
@@ -101,17 +99,17 @@
r = bs->LocateHandleBuffer(ByProtocol, &UsbIoProtocol, NULL, &count, &list);
if (r == 0) {
for (i = 0; i < count; i++) {
- r = bs->ConnectController(list[i], NULL, NULL, FALSE);
+ r = bs->ConnectController(list[i], NULL, NULL, false);
}
bs->FreePool(list);
}
}
-void RemoveMyDriver(EFI_HANDLE img, EFI_SYSTEM_TABLE* sys) {
- EFI_BOOT_SERVICES* bs = sys->BootServices;
- EFI_HANDLE* list;
- UINTN count, i;
- EFI_STATUS r;
+void RemoveMyDriver(efi_handle img, efi_system_table* sys) {
+ efi_boot_services* bs = sys->BootServices;
+ efi_handle* list;
+ size_t count, i;
+ efi_status r;
// Disconnect the driver
r = bs->LocateHandleBuffer(ByProtocol, &UsbIoProtocol, NULL, &count, &list);
@@ -128,11 +126,10 @@
printf("UninstallProtocol failed %lx\n", r);
}
-EFI_STATUS efi_main(EFI_HANDLE img, EFI_SYSTEM_TABLE* sys) {
- InitializeLib(img, sys);
+efi_status efi_main(efi_handle img, efi_system_table* sys) {
InitGoodies(img, sys);
- Print(L"Hello, EFI World\n");
+ printf("Hello, EFI World\n");
InstallMyDriver(img, sys);
diff --git a/third_party/gnu-efi/Makefile b/third_party/gnu-efi/Makefile
index 3d4275c..0f754bc 100644
--- a/third_party/gnu-efi/Makefile
+++ b/third_party/gnu-efi/Makefile
@@ -42,8 +42,7 @@
include $(SRCDIR)/Make.defaults
-SUBDIRS = lib gnuefi inc apps
-gnuefi: lib
+SUBDIRS = gnuefi
all: check_gcc $(SUBDIRS)