uefi.h (9793B)
1 #define IN 2 #define OUT 3 #define OPTIONAL 4 #define CONST 5 #define EFIAPI __attribute__((ms_abi)) 6 7 #define NULL 0L 8 9 typedef unsigned short CHAR16; 10 typedef unsigned long long UINTN; 11 typedef unsigned char UINT8; 12 typedef short INT16; 13 typedef unsigned short UINT16; 14 typedef unsigned UINT32; 15 typedef unsigned long long UINT64; 16 typedef UINTN EFI_STATUS; 17 typedef void *EFI_HANDLE; 18 typedef UINT64 EFI_PHYSICAL_ADDRESS; 19 typedef UINT64 EFI_VIRTUAL_ADDRESS; 20 typedef void VOID; 21 typedef struct EFI_GUID { 22 UINT32 Data1; 23 UINT16 Data2; 24 UINT16 Data3; 25 UINT8 Data4[8]; 26 } EFI_GUID; 27 28 // TODO: endianness? 29 #define EFI_LOADED_IMAGE_PROTOCOL_GUID \ 30 {0x5b1b31a1, 0x9562, 0x11d2, \ 31 {0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b}} 32 #define EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID \ 33 {0x9042a9de, 0x23dc, 0x4a38, \ 34 {0x96, 0xfb, 0x7a, 0xde, 0xd0, 0x80, 0x51, 0x6a}} 35 #define EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID \ 36 {0x964e5b22, 0x6459, 0x11d2, \ 37 {0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b}} 38 #define EFI_FILE_INFO_ID \ 39 {0x9576e92, 0x6d3f, 0x11d2, \ 40 {0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b}} 41 42 // EFI_STATUS 43 enum { 44 EFI_SUCCESS = 0, 45 46 EFI_INVALID_PARAMETER = 0x8000000000000002, 47 EFI_BUFFER_TOO_SMALL = 0x8000000000000005, 48 }; 49 50 typedef struct _EFI_SYSTEM_TABLE EFI_SYSTEM_TABLE; 51 52 typedef struct { 53 UINT16 ScanCode; 54 CHAR16 UnicodeChar; 55 } EFI_INPUT_KEY; 56 57 typedef struct _EFI_SIMPLE_TEXT_INPUT_PROTOCOL EFI_SIMPLE_TEXT_INPUT_PROTOCOL; 58 59 typedef 60 EFI_STATUS (EFIAPI *EFI_INPUT_READ_KEY)( 61 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This, 62 OUT EFI_INPUT_KEY *Key 63 ); 64 65 typedef struct _EFI_SIMPLE_TEXT_INPUT_PROTOCOL { 66 void *dummy; 67 EFI_INPUT_READ_KEY ReadKeyStroke; 68 } EFI_SIMPLE_TEXT_INPUT_PROTOCOL; 69 70 typedef struct _EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL; 71 72 typedef 73 EFI_STATUS (EFIAPI *EFI_TEXT_STRING)( 74 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, 75 IN CHAR16 *String 76 ); 77 78 typedef 79 EFI_STATUS (EFIAPI *EFI_TEXT_CLEAR_SCREEN)( 80 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This 81 ); 82 83 struct _EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL { 84 void *dummy; 85 EFI_TEXT_STRING OutputString; 86 void *dummy1[4]; 87 EFI_TEXT_CLEAR_SCREEN ClearScreen; 88 }; 89 90 typedef enum { 91 EfiReservedMemoryType, 92 EfiLoaderCode, 93 EfiLoaderData, 94 EfiBootServicesCode, 95 EfiBootServicesData, 96 EfiRuntimeServicesCode, 97 EfiRuntimeServicesData, 98 EfiConventionalMemory, 99 EfiUnusableMemory, 100 EfiACPIReclaimMemory, 101 EfiACPIMemoryNVS, 102 EfiMemoryMappedIO, 103 EfiMemoryMappedIOPortSpace, 104 EfiPalCode, 105 EfiPersistentMemory, 106 EfiUnacceptedMemoryType, 107 EfiMaxMemoryType, 108 } EFI_MEMORY_TYPE; 109 110 typedef struct { 111 UINT32 Type; 112 EFI_PHYSICAL_ADDRESS PhysicalStart; 113 EFI_VIRTUAL_ADDRESS VirtualStart; 114 UINT64 NumberOfPages; 115 UINT64 Attribute; 116 } EFI_MEMORY_DESCRIPTOR; 117 118 typedef struct _EFI_GRAPHICS_OUTPUT_PROTOCOL EFI_GRAPHICS_OUTPUT_PROTOCOL; 119 120 typedef enum { 121 PixelRedGreenBlueReserved8BitPerColor, 122 PixelBlueGreenRedReserved8BitPerColor, 123 PixelBitMask, 124 PixelBltOnly, 125 PixelFormatMax, 126 } EFI_GRAPHICS_PIXEL_FORMAT; 127 128 typedef struct { 129 UINT32 RedMask; 130 UINT32 GreenMask; 131 UINT32 BlueMask; 132 UINT32 ReservedMask; 133 } EFI_PIXEL_BITMASK; 134 135 typedef struct { 136 UINT32 Version; 137 UINT32 HorizontalResolution; 138 UINT32 VerticalResolution; 139 EFI_GRAPHICS_PIXEL_FORMAT PixelFormat; // TODO: I think this is not fixed in size. 140 EFI_PIXEL_BITMASK PixelInformation; 141 UINT32 PixelsPerScanLine; 142 } EFI_GRAPHICS_OUTPUT_MODE_INFORMATION; 143 144 typedef struct { 145 UINT32 MaxMode; 146 UINT32 Mode; 147 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info; 148 UINTN SizeOfInfo; 149 EFI_PHYSICAL_ADDRESS FrameBufferBase; 150 UINTN FrameBufferSize; 151 } EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE; 152 153 typedef 154 EFI_STATUS (EFIAPI *EFI_GRAPHICS_OUTPUT_PROTOCOL_QUERY_MODE) ( 155 ); 156 157 typedef 158 EFI_STATUS (EFIAPI *EFI_GRAPHICS_OUTPUT_PROTOCOL_SET_MODE) ( 159 ); 160 161 typedef 162 EFI_STATUS (EFIAPI *EFI_GRAPHICS_OUTPUT_PROTOCOL_BLT) ( 163 ); 164 165 struct _EFI_GRAPHICS_OUTPUT_PROTOCOL { 166 EFI_GRAPHICS_OUTPUT_PROTOCOL_QUERY_MODE QueryMode; 167 EFI_GRAPHICS_OUTPUT_PROTOCOL_SET_MODE SetMode; 168 EFI_GRAPHICS_OUTPUT_PROTOCOL_BLT Blt; 169 EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE *Mode; 170 }; 171 172 typedef struct _EFI_FILE_PROTOCOL EFI_FILE_PROTOCOL; 173 174 typedef 175 EFI_STATUS (EFIAPI *EFI_FILE_OPEN) ( 176 IN EFI_FILE_PROTOCOL *This, 177 OUT EFI_FILE_PROTOCOL **NewHandle, 178 IN CHAR16 *FileName, 179 IN UINT64 OpenMode, 180 IN UINT64 Attributes 181 ); 182 183 #define EFI_FILE_MODE_READ 0x0000000000000001 184 #define EFI_FILE_MODE_WRITE 0x0000000000000002 185 #define EFI_FILE_MODE_CREATE 0x8000000000000000 186 187 typedef 188 EFI_STATUS (EFIAPI *EFI_FILE_CLOSE) ( 189 IN EFI_FILE_PROTOCOL *This 190 ); 191 192 typedef 193 EFI_STATUS (EFIAPI *EFI_FILE_DELETE) ( 194 IN EFI_FILE_PROTOCOL *This 195 ); 196 197 typedef 198 EFI_STATUS (EFIAPI *EFI_FILE_READ) ( 199 IN EFI_FILE_PROTOCOL *This, 200 IN OUT UINTN *BufferSize, 201 OUT VOID *Buffer 202 ); 203 204 typedef 205 EFI_STATUS (EFIAPI *EFI_FILE_WRITE) ( 206 IN EFI_FILE_PROTOCOL *This, 207 IN OUT UINTN *BufferSize, 208 IN VOID *Buffer 209 ); 210 211 typedef 212 EFI_STATUS (EFIAPI *EFI_FILE_SET_POSITION) ( 213 IN EFI_FILE_PROTOCOL *This, 214 IN UINT64 Position 215 ); 216 217 typedef 218 EFI_STATUS (EFIAPI *EFI_FILE_GET_POSITION) ( 219 IN EFI_FILE_PROTOCOL *This, 220 OUT UINT64 *Position 221 ); 222 223 typedef 224 EFI_STATUS (EFIAPI *EFI_FILE_GET_INFO) ( 225 IN EFI_FILE_PROTOCOL *This, 226 IN EFI_GUID *InformationType, 227 IN OUT UINTN *BufferSize, 228 OUT VOID *Buffer 229 ); 230 231 struct _EFI_FILE_PROTOCOL { 232 UINT64 Revision; 233 EFI_FILE_OPEN Open; 234 EFI_FILE_CLOSE Close; 235 EFI_FILE_DELETE Delete; 236 EFI_FILE_READ Read; 237 EFI_FILE_WRITE Write; 238 EFI_FILE_GET_POSITION GetPosition; 239 EFI_FILE_SET_POSITION SetPosition; 240 EFI_FILE_GET_INFO GetInfo; 241 void *dummy1[6]; 242 }; 243 244 typedef struct { 245 UINT16 Year; 246 UINT8 Month; 247 UINT8 Day; 248 UINT8 Hour; 249 UINT8 Minute; 250 UINT8 Second; 251 UINT8 Pad1; 252 UINT32 NanoSecond; 253 INT16 TimeZone; 254 UINT8 Daylight; 255 UINT8 Pad2; 256 } EFI_TIME; 257 258 typedef struct { 259 UINT64 Size; 260 UINT64 FileSize; 261 UINT64 PhysicalSize; 262 EFI_TIME CreateTime; 263 EFI_TIME LastAccessTime; 264 EFI_TIME ModificationTime; 265 UINT64 Attribute; 266 CHAR16 FileName[]; 267 } EFI_FILE_INFO; 268 269 typedef struct _EFI_LOADED_IMAGE_PROTOCOL EFI_LOADED_IMAGE_PROTOCOL; 270 271 struct _EFI_LOADED_IMAGE_PROTOCOL{ 272 UINT32 Revision; 273 EFI_HANDLE ParentHandle; 274 EFI_SYSTEM_TABLE *SystemTable; 275 276 EFI_HANDLE DeviceHandle; 277 void *dummy[2]; 278 279 UINT32 LoadOptionSize; 280 VOID *LoadOptions; 281 282 VOID *ImageBase; 283 UINT64 ImageSize; 284 char dummy1[4 + 4]; 285 void *dummy2; 286 }; 287 288 typedef struct _EFI_SIMPLE_FILE_SYSTEM_PROTOCOL EFI_SIMPLE_FILE_SYSTEM_PROTOCOL; 289 290 typedef 291 EFI_STATUS (EFIAPI *EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_OPEN_VOLUME)( 292 IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *This, 293 OUT EFI_FILE_PROTOCOL **Root 294 ); 295 296 struct _EFI_SIMPLE_FILE_SYSTEM_PROTOCOL { 297 UINT64 Revision; 298 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_OPEN_VOLUME OpenVolume; 299 }; 300 301 typedef enum { 302 AllocateAnyPages, 303 AllocateMaxAddress, 304 AllocateAddress, 305 MaxAllocateType 306 } EFI_ALLOCATE_TYPE; 307 308 typedef 309 EFI_STATUS (EFIAPI *EFI_ALLOCATE_PAGES)( 310 IN EFI_ALLOCATE_TYPE Type, 311 IN EFI_MEMORY_TYPE MemoryType, 312 IN UINTN Pages, 313 IN OUT EFI_PHYSICAL_ADDRESS *Memory 314 ); 315 316 typedef 317 EFI_STATUS (EFIAPI *EFI_GET_MEMORY_MAP)( 318 IN OUT UINTN *MemoryMapSize, 319 OUT EFI_MEMORY_DESCRIPTOR *MemoryMap, 320 OUT UINTN *MapKey, 321 OUT UINTN *DescriptorSize, 322 OUT UINT32 *DescriptorVersion 323 ); 324 325 typedef 326 EFI_STATUS (EFIAPI *EFI_EXIT_BOOT_SERVICES)( 327 IN EFI_HANDLE ImageHandle, 328 IN UINTN MapKey 329 ); 330 331 typedef 332 EFI_STATUS (EFIAPI *EFI_OPEN_PROTOCOL)( 333 IN EFI_HANDLE Handle, 334 IN EFI_GUID *Protocol, 335 OUT VOID **Interface OPTIONAL, 336 IN EFI_HANDLE AgentHandle, 337 IN EFI_HANDLE ControllerHandle, 338 IN UINT32 Attributes 339 ); 340 341 typedef enum { 342 AllHandles, 343 ByRegisterNotify, 344 ByProtocol 345 } EFI_LOCATE_SEARCH_TYPE; 346 347 typedef 348 EFI_STATUS (EFIAPI *EFI_LOCATE_HANDLE_BUFFER)( 349 IN EFI_LOCATE_SEARCH_TYPE SearchType, 350 IN EFI_GUID *Protocol OPTIONAL, 351 IN VOID *SearchKey OPTIONAL, 352 OUT UINTN *NoHandles, 353 OUT EFI_HANDLE **Buffer 354 ); 355 356 #define EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL 0x1 357 358 typedef struct { 359 } EFI_RUNTIME_SERVICES; 360 361 typedef struct { 362 UINT64 Signature; 363 UINT32 Revision; 364 UINT32 HeaderSize; 365 UINT32 CRC32; 366 UINT32 Reserved; 367 } EFI_TABLE_HEADER; 368 369 typedef struct { 370 EFI_TABLE_HEADER Hdr; 371 // task priority services 372 void *task_priority_services[2]; 373 // memory services 374 EFI_ALLOCATE_PAGES AllocatePages; 375 void *memory_services0[1]; 376 EFI_GET_MEMORY_MAP GetMemoryMap; 377 void *memory_services1[2]; 378 // event timer services 379 void *event_timer_services[6]; 380 // protocol handler services 381 void *protocol_handler_services[9]; 382 // image services 383 void *image_services0[4]; 384 EFI_EXIT_BOOT_SERVICES ExitBootServices; 385 void *miscellaneus_services[3]; 386 void *driversupport_services[2]; 387 EFI_OPEN_PROTOCOL OpenProtocol; 388 void *open_and_close_protocol_services[2]; 389 void *library_servies0[1]; 390 EFI_LOCATE_HANDLE_BUFFER LocateHandleBuffer; 391 void *library_servies1[3]; 392 void *crc_services[1]; 393 void *miscellaneus_services1[3]; 394 } EFI_BOOT_SERVICES; 395 396 struct _EFI_SYSTEM_TABLE { 397 EFI_TABLE_HEADER Hdr; 398 CHAR16 *FirmwareVendor; 399 char dummy1[4]; 400 EFI_HANDLE ConsoleInHandle; 401 EFI_SIMPLE_TEXT_INPUT_PROTOCOL *ConIn; 402 EFI_HANDLE ConsoleOutHandle; 403 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *ConOut; 404 EFI_HANDLE StandardErrorHandle; 405 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *StdErr; 406 EFI_RUNTIME_SERVICES *RuntimeServices; 407 EFI_BOOT_SERVICES *BootServices; 408 char dummy2[16]; 409 };