#pragma once typedef unsigned char uint8_t; typedef unsigned short uint16_t; typedef unsigned int uint32_t; typedef unsigned long long uint64_t; typedef int int32_t; typedef long long int64_t; typedef uint64_t uintptr_t; typedef int64_t intn_t; typedef uint64_t uintn_t; typedef uint8_t boolean_t; typedef uint64_t efi_status_t; typedef uint64_t efi_tpl_t; typedef uint64_t efi_physical_address_t; typedef uint64_t efi_virtual_address_t; typedef void* efi_handle_t; typedef void* efi_event_t; #ifndef NULL #define NULL ((void*)0) #endif #ifndef __cplusplus typedef uint16_t wchar_t; #endif #ifndef EFIAPI #define EFIAPI #endif #define EFIERR(value) (0x8000000000000000ULL | (uint32_t)(value)) #define EFI_ERROR(status) (((intn_t)(status)) < 0) #define EFI_SUCCESS 0 #define EFI_LOAD_ERROR EFIERR(1) #define EFI_UNSUPPORTED EFIERR(3) #define EFI_BUFFER_TOO_SMALL EFIERR(5) #define EFI_OUT_OF_RESOURCES EFIERR(9) #define EFI_NOT_FOUND EFIERR(14) #define EFI_ABORTED EFIERR(21) #define EFI_OPEN_PROTOCOL_GET_PROTOCOL 0x00000002 #define EFI_FILE_MODE_READ 0x0000000000000001ULL #define EFI_LOADED_IMAGE_PROTOCOL_GUID \ {0x5B1B31A1, 0x9562, 0x11d2, {0x8E, 0x3F, 0x00, 0xA0, 0xC9, 0x69, 0x72, 0x3B}} #define EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID \ {0x964e5b22, 0x6459, 0x11d2, {0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b}} #define EFI_FILE_INFO_GUID \ {0x09576e92, 0x6d3f, 0x11d2, {0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b}} #define EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID \ {0x9042a9de, 0x23dc, 0x4a38, {0x96, 0xfb, 0x7a, 0xde, 0xd0, 0x80, 0x51, 0x6a}} #define FILENAME_MAX 262 typedef enum { AllocateAnyPages, AllocateMaxAddress, AllocateAddress, MaxAllocateType } efi_allocate_type_t; typedef enum { EfiReservedMemoryType, EfiLoaderCode, EfiLoaderData, EfiBootServicesCode, EfiBootServicesData, EfiRuntimeServicesCode, EfiRuntimeServicesData, EfiConventionalMemory, EfiUnusableMemory, EfiACPIReclaimMemory, EfiACPIMemoryNVS, EfiMemoryMappedIO, EfiMemoryMappedIOPortSpace, EfiPalCode, EfiPersistentMemory, EfiUnacceptedMemoryType, EfiMaxMemoryType } efi_memory_type_t; typedef enum { AllHandles, ByRegisterNotify, ByProtocol } efi_locate_search_type_t; typedef enum { PixelRedGreenBlueReserved8BitPerColor, PixelBlueGreenRedReserved8BitPerColor, PixelBitMask, PixelBltOnly, PixelFormatMax } efi_gop_pixel_format_t; typedef struct { uint32_t Data1; uint16_t Data2; uint16_t Data3; uint8_t Data4[8]; } efi_guid_t; typedef struct { uint8_t Type; uint8_t SubType; uint8_t Length[2]; } efi_device_path_t; typedef struct { uint32_t Type; uint32_t Pad; efi_physical_address_t PhysicalStart; efi_virtual_address_t VirtualStart; uint64_t NumberOfPages; uint64_t Attribute; } efi_memory_descriptor_t; typedef struct { uint64_t Signature; uint32_t Revision; uint32_t HeaderSize; uint32_t CRC32; uint32_t Reserved; } efi_table_header_t; 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; short TimeZone; uint8_t Daylight; uint8_t Pad2; } efi_time_t; typedef struct { uint16_t ScanCode; wchar_t UnicodeChar; } efi_input_key_t; typedef struct { int32_t MaxMode; int32_t Mode; int32_t Attribute; int32_t CursorColumn; int32_t CursorRow; boolean_t CursorVisible; } simple_text_output_mode_t; typedef efi_status_t (EFIAPI *efi_input_reset_t)(void* this_ptr, boolean_t extended_verification); typedef efi_status_t (EFIAPI *efi_input_read_key_t)(void* this_ptr, efi_input_key_t* key); typedef efi_status_t (EFIAPI *efi_text_reset_t)(void* this_ptr, boolean_t extended_verification); typedef efi_status_t (EFIAPI *efi_text_output_string_t)(void* this_ptr, wchar_t* string); typedef efi_status_t (EFIAPI *efi_text_test_string_t)(void* this_ptr, wchar_t* string); typedef efi_status_t (EFIAPI *efi_text_query_mode_t)(void* this_ptr, uintn_t mode_number, uintn_t* column, uintn_t* row); typedef efi_status_t (EFIAPI *efi_text_set_mode_t)(void* this_ptr, uintn_t mode_number); typedef efi_status_t (EFIAPI *efi_text_set_attribute_t)(void* this_ptr, uintn_t attribute); typedef efi_status_t (EFIAPI *efi_text_clear_screen_t)(void* this_ptr); typedef efi_status_t (EFIAPI *efi_text_set_cursor_t)(void* this_ptr, uintn_t column, uintn_t row); typedef efi_status_t (EFIAPI *efi_text_enable_cursor_t)(void* this_ptr, boolean_t enable); typedef struct { efi_input_reset_t Reset; efi_input_read_key_t ReadKeyStroke; efi_event_t WaitForKey; } simple_input_interface_t; typedef struct { efi_text_reset_t Reset; efi_text_output_string_t OutputString; efi_text_test_string_t TestString; efi_text_query_mode_t QueryMode; efi_text_set_mode_t SetMode; efi_text_set_attribute_t SetAttribute; efi_text_clear_screen_t ClearScreen; efi_text_set_cursor_t SetCursorPosition; efi_text_enable_cursor_t EnableCursor; simple_text_output_mode_t* Mode; } simple_text_output_interface_t; typedef struct efi_runtime_services_t { efi_table_header_t Hdr; } efi_runtime_services_t; typedef struct { efi_handle_t AgentHandle; efi_handle_t ControllerHandle; uint32_t Attributes; uint32_t OpenCount; } efi_open_protocol_information_entry_t; typedef efi_tpl_t (EFIAPI *efi_raise_tpl_t)(efi_tpl_t new_tpl); typedef efi_tpl_t (EFIAPI *efi_restore_tpl_t)(efi_tpl_t old_tpl); typedef efi_status_t (EFIAPI *efi_allocate_pages_t)(efi_allocate_type_t type, efi_memory_type_t memory_type, uintn_t pages, efi_physical_address_t* memory); typedef efi_status_t (EFIAPI *efi_free_pages_t)(efi_physical_address_t memory, uintn_t pages); typedef efi_status_t (EFIAPI *efi_get_memory_map_t)(uintn_t* memory_map_size, efi_memory_descriptor_t* memory_map, uintn_t* map_key, uintn_t* descriptor_size, uint32_t* descriptor_version); typedef efi_status_t (EFIAPI *efi_allocate_pool_t)(efi_memory_type_t pool_type, uintn_t size, void** buffer); typedef efi_status_t (EFIAPI *efi_free_pool_t)(void* buffer); typedef void (EFIAPI *efi_event_notify_t)(efi_event_t event, void* context); typedef efi_status_t (EFIAPI *efi_create_event_t)(uint32_t type, efi_tpl_t notify_tpl, efi_event_notify_t notify_function, void* context, efi_event_t* event); typedef efi_status_t (EFIAPI *efi_set_timer_t)(efi_event_t event, uint32_t type, uint64_t trigger_time); typedef efi_status_t (EFIAPI *efi_wait_for_event_t)(uintn_t number_of_events, efi_event_t* event, uintn_t* index); typedef efi_status_t (EFIAPI *efi_signal_event_t)(efi_event_t event); typedef efi_status_t (EFIAPI *efi_close_event_t)(efi_event_t event); typedef efi_status_t (EFIAPI *efi_check_event_t)(efi_event_t event); typedef efi_status_t (EFIAPI *efi_handle_protocol_t)(efi_handle_t handle, efi_guid_t* protocol, void** interface); typedef efi_status_t (EFIAPI *efi_register_protocol_notify_t)(efi_guid_t* protocol, efi_event_t event, void** registration); typedef efi_status_t (EFIAPI *efi_locate_handle_t)(efi_locate_search_type_t search_type, efi_guid_t* protocol, void* search_key, uintn_t* buffer_size, efi_handle_t* buffer); typedef efi_status_t (EFIAPI *efi_locate_device_path_t)(efi_guid_t* protocol, efi_device_path_t** device_path, efi_handle_t* device); typedef efi_status_t (EFIAPI *efi_install_configuration_table_t)(efi_guid_t* guid, void* table); typedef efi_status_t (EFIAPI *efi_image_load_t)(boolean_t boot_policy, efi_handle_t parent_image_handle, efi_device_path_t* file_path, void* source_buffer, uintn_t source_size, efi_handle_t* image_handle); typedef efi_status_t (EFIAPI *efi_image_start_t)(efi_handle_t image_handle, uintn_t* exit_data_size, wchar_t** exit_data); typedef efi_status_t (EFIAPI *efi_exit_t)(efi_handle_t image_handle, efi_status_t exit_status, uintn_t exit_data_size, wchar_t* exit_data); typedef efi_status_t (EFIAPI *efi_exit_boot_services_t)(efi_handle_t image_handle, uintn_t map_key); typedef efi_status_t (EFIAPI *efi_get_next_monotonic_t)(uint64_t* count); typedef efi_status_t (EFIAPI *efi_stall_t)(uintn_t microseconds); typedef efi_status_t (EFIAPI *efi_set_watchdog_timer_t)(uintn_t timeout, uint64_t watchdog_code, uintn_t data_size, wchar_t* watchdog_data); typedef efi_status_t (EFIAPI *efi_connect_controller_t)(efi_handle_t controller_handle, efi_handle_t* driver_image_handle, efi_device_path_t* remaining_device_path, boolean_t recursive); typedef efi_status_t (EFIAPI *efi_disconnect_controller_t)(efi_handle_t controller_handle, efi_handle_t driver_image_handle, efi_handle_t child_handle); typedef efi_status_t (EFIAPI *efi_open_protocol_t)(efi_handle_t handle, efi_guid_t* protocol, void** interface, efi_handle_t agent_handle, efi_handle_t controller_handle, uint32_t attributes); typedef efi_status_t (EFIAPI *efi_close_protocol_t)(efi_handle_t handle, efi_guid_t* protocol, efi_handle_t agent_handle, efi_handle_t controller_handle); typedef efi_status_t (EFIAPI *efi_open_protocol_information_t)(efi_handle_t handle, efi_guid_t* protocol, efi_open_protocol_information_entry_t** entry_buffer, uintn_t* entry_count); typedef efi_status_t (EFIAPI *efi_protocols_per_handle_t)(efi_handle_t handle, efi_guid_t*** protocol_buffer, uintn_t* protocol_buffer_count); typedef efi_status_t (EFIAPI *efi_locate_handle_buffer_t)(efi_locate_search_type_t search_type, efi_guid_t* protocol, void* search_key, uintn_t* handle_count, efi_handle_t** handles); typedef efi_status_t (EFIAPI *efi_locate_protocol_t)(efi_guid_t* protocol, void* registration, void** interface); typedef efi_status_t (EFIAPI *efi_calculate_crc32_t)(void* data, uintn_t data_size, uint32_t* crc32); typedef struct { efi_table_header_t Hdr; efi_raise_tpl_t RaiseTPL; efi_restore_tpl_t RestoreTPL; efi_allocate_pages_t AllocatePages; efi_free_pages_t FreePages; efi_get_memory_map_t GetMemoryMap; efi_allocate_pool_t AllocatePool; efi_free_pool_t FreePool; efi_create_event_t CreateEvent; efi_set_timer_t SetTimer; efi_wait_for_event_t WaitForEvent; efi_signal_event_t SignalEvent; efi_close_event_t CloseEvent; efi_check_event_t CheckEvent; void* InstallProtocolInterface; void* ReinstallProtocolInterface; void* UninstallProtocolInterface; efi_handle_protocol_t HandleProtocol; efi_handle_protocol_t PCHandleProtocol; efi_register_protocol_notify_t RegisterProtocolNotify; efi_locate_handle_t LocateHandle; efi_locate_device_path_t LocateDevicePath; efi_install_configuration_table_t InstallConfigurationTable; efi_image_load_t LoadImage; efi_image_start_t StartImage; efi_exit_t Exit; void* UnloadImage; efi_exit_boot_services_t ExitBootServices; efi_get_next_monotonic_t GetNextHighMonotonicCount; efi_stall_t Stall; efi_set_watchdog_timer_t SetWatchdogTimer; efi_connect_controller_t ConnectController; efi_disconnect_controller_t DisconnectController; efi_open_protocol_t OpenProtocol; efi_close_protocol_t CloseProtocol; efi_open_protocol_information_t OpenProtocolInformation; efi_protocols_per_handle_t ProtocolsPerHandle; efi_locate_handle_buffer_t LocateHandleBuffer; efi_locate_protocol_t LocateProtocol; void* InstallMultipleProtocolInterfaces; void* UninstallMultipleProtocolInterfaces; efi_calculate_crc32_t CalculateCrc32; } efi_boot_services_t; typedef struct { uint32_t Revision; efi_handle_t ParentHandle; void* SystemTable; efi_handle_t DeviceHandle; efi_device_path_t* FilePath; void* Reserved; uint32_t LoadOptionsSize; void* LoadOptions; void* ImageBase; uint64_t ImageSize; efi_memory_type_t ImageCodeType; efi_memory_type_t ImageDataType; } efi_loaded_image_protocol_t; typedef struct { efi_guid_t VendorGuid; void* VendorTable; } efi_configuration_table_t; typedef struct { efi_table_header_t Hdr; wchar_t* FirmwareVendor; uint32_t FirmwareRevision; efi_handle_t ConsoleInHandle; simple_input_interface_t* ConIn; efi_handle_t ConsoleOutHandle; simple_text_output_interface_t* ConOut; efi_handle_t ConsoleErrorHandle; simple_text_output_interface_t* StdErr; efi_runtime_services_t* RuntimeServices; efi_boot_services_t* BootServices; uintn_t NumberOfTableEntries; efi_configuration_table_t* ConfigurationTable; } efi_system_table_t; typedef struct efi_file_handle_s efi_file_handle_t; typedef efi_status_t (EFIAPI *efi_volume_open_t)(void* this_ptr, efi_file_handle_t** root); typedef struct { uint64_t Revision; efi_volume_open_t OpenVolume; } efi_simple_file_system_protocol_t; typedef struct { uint64_t Size; uint64_t FileSize; uint64_t PhysicalSize; efi_time_t CreateTime; efi_time_t LastAccessTime; efi_time_t ModificationTime; uint64_t Attribute; wchar_t FileName[FILENAME_MAX]; } efi_file_info_t; typedef efi_status_t (EFIAPI *efi_file_open_t)(efi_file_handle_t* file, efi_file_handle_t** new_handle, wchar_t* file_name, uint64_t open_mode, uint64_t attributes); typedef efi_status_t (EFIAPI *efi_file_close_t)(efi_file_handle_t* file); typedef efi_status_t (EFIAPI *efi_file_delete_t)(efi_file_handle_t* file); typedef efi_status_t (EFIAPI *efi_file_read_t)(efi_file_handle_t* file, uintn_t* buffer_size, void* buffer); typedef efi_status_t (EFIAPI *efi_file_write_t)(efi_file_handle_t* file, uintn_t* buffer_size, void* buffer); typedef efi_status_t (EFIAPI *efi_file_get_pos_t)(efi_file_handle_t* file, uint64_t* position); typedef efi_status_t (EFIAPI *efi_file_set_pos_t)(efi_file_handle_t* file, uint64_t position); typedef efi_status_t (EFIAPI *efi_file_get_info_t)(efi_file_handle_t* file, efi_guid_t* information_type, uintn_t* buffer_size, void* buffer); typedef efi_status_t (EFIAPI *efi_file_set_info_t)(efi_file_handle_t* file, efi_guid_t* information_type, uintn_t buffer_size, void* buffer); typedef efi_status_t (EFIAPI *efi_file_flush_t)(efi_file_handle_t* file); struct efi_file_handle_s { uint64_t Revision; efi_file_open_t Open; efi_file_close_t Close; efi_file_delete_t Delete; efi_file_read_t Read; efi_file_write_t Write; efi_file_get_pos_t GetPosition; efi_file_set_pos_t SetPosition; efi_file_get_info_t GetInfo; efi_file_set_info_t SetInfo; efi_file_flush_t Flush; }; typedef struct { uint32_t RedMask; uint32_t GreenMask; uint32_t BlueMask; uint32_t ReservedMask; } efi_gop_pixel_bitmask_t; typedef struct { uint32_t Version; uint32_t HorizontalResolution; uint32_t VerticalResolution; efi_gop_pixel_format_t PixelFormat; efi_gop_pixel_bitmask_t PixelInformation; uint32_t PixelsPerScanLine; } efi_gop_mode_info_t; typedef struct { uint32_t MaxMode; uint32_t Mode; efi_gop_mode_info_t* Information; uintn_t SizeOfInfo; efi_physical_address_t FrameBufferBase; uintn_t FrameBufferSize; } efi_gop_mode_t; typedef efi_status_t (EFIAPI *efi_gop_query_mode_t)(void* this_ptr, uint32_t mode_number, uintn_t* size_of_info, efi_gop_mode_info_t** info); typedef efi_status_t (EFIAPI *efi_gop_set_mode_t)(void* this_ptr, uint32_t mode_number); typedef efi_status_t (EFIAPI *efi_gop_blt_t)(void* this_ptr, uint32_t* blt_buffer, uint32_t blt_operation, uintn_t source_x, uintn_t source_y, uintn_t destination_x, uintn_t destination_y, uintn_t width, uintn_t height, uintn_t delta); typedef struct { efi_gop_query_mode_t QueryMode; efi_gop_set_mode_t SetMode; efi_gop_blt_t Blt; efi_gop_mode_t* Mode; } efi_gop_t; extern efi_handle_t IM; extern efi_system_table_t* ST; extern efi_boot_services_t* BS; extern efi_runtime_services_t* RT; #define gBS BS