efi.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /* Minimal UEFI definitions for the NebOS x86-64 loader.
  2. *
  3. * Only the tables and protocols the loader uses are declared, but the fields
  4. * before them are in their exact UEFI order so the offsets match the
  5. * firmware's structures. x86_64-w64-mingw32 uses the Microsoft x64 calling
  6. * convention, which is the UEFI ABI, so no ms_abi attributes are needed.
  7. */
  8. #ifndef NEBOS_EFI_H
  9. #define NEBOS_EFI_H
  10. typedef unsigned char UINT8;
  11. typedef unsigned short UINT16;
  12. typedef unsigned int UINT32;
  13. typedef unsigned long long UINT64;
  14. typedef unsigned long long UINTN;
  15. typedef UINTN EFI_STATUS;
  16. typedef void *EFI_HANDLE;
  17. typedef UINT64 EFI_PHYSICAL_ADDRESS;
  18. typedef UINT64 EFI_VIRTUAL_ADDRESS;
  19. typedef UINT16 CHAR16;
  20. typedef UINT8 BOOLEAN;
  21. #define EFI_SUCCESS 0
  22. typedef struct {
  23. UINT32 Data1;
  24. UINT16 Data2;
  25. UINT16 Data3;
  26. UINT8 Data4[8];
  27. } __attribute__((packed)) EFI_GUID;
  28. typedef struct {
  29. UINT64 Signature;
  30. UINT32 Revision;
  31. UINT32 HeaderSize;
  32. UINT32 CRC32;
  33. UINT32 Reserved;
  34. } EFI_TABLE_HEADER;
  35. typedef struct {
  36. UINT32 Type;
  37. UINT32 Pad;
  38. EFI_PHYSICAL_ADDRESS PhysicalStart;
  39. EFI_VIRTUAL_ADDRESS VirtualStart;
  40. UINT64 NumberOfPages;
  41. UINT64 Attribute;
  42. } __attribute__((packed)) EFI_MEMORY_DESCRIPTOR;
  43. typedef struct {
  44. EFI_GUID VendorGuid;
  45. void *VendorTable;
  46. } EFI_CONFIGURATION_TABLE;
  47. typedef struct {
  48. void *Reset;
  49. EFI_STATUS (*OutputString)(void *This, CHAR16 *String);
  50. void *TestString;
  51. void *QueryMode;
  52. void *SetMode;
  53. void *SetAttribute;
  54. void *ClearScreen;
  55. void *SetCursorPosition;
  56. void *EnableCursor;
  57. void *Mode;
  58. } EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL;
  59. /* Field order matches EFI_BOOT_SERVICES; only the used entries have typed
  60. * signatures, the rest are void * but must still be present in order. */
  61. typedef struct {
  62. EFI_TABLE_HEADER Hdr;
  63. void *RaiseTPL;
  64. void *RestoreTPL;
  65. EFI_STATUS (*AllocatePages)(UINT32 Type, UINT32 MemoryType,
  66. UINTN Pages, EFI_PHYSICAL_ADDRESS *Memory);
  67. void *FreePages;
  68. EFI_STATUS (*GetMemoryMap)(UINTN *MemoryMapSize,
  69. EFI_MEMORY_DESCRIPTOR *MemoryMap,
  70. UINTN *MapKey, UINTN *DescriptorSize,
  71. UINT32 *DescriptorVersion);
  72. void *AllocatePool;
  73. void *FreePool;
  74. void *CreateEvent;
  75. void *SetTimer;
  76. void *WaitForEvent;
  77. void *SignalEvent;
  78. void *CloseEvent;
  79. void *CheckEvent;
  80. void *InstallProtocolInterface;
  81. void *ReinstallProtocolInterface;
  82. void *UninstallProtocolInterface;
  83. void *HandleProtocol;
  84. void *Reserved;
  85. void *RegisterProtocolNotify;
  86. void *LocateHandle;
  87. void *LocateDevicePath;
  88. void *InstallConfigurationTable;
  89. void *LoadImage;
  90. void *StartImage;
  91. void *Exit;
  92. void *UnloadImage;
  93. EFI_STATUS (*ExitBootServices)(EFI_HANDLE ImageHandle, UINTN MapKey);
  94. void *GetNextMonotonicCount;
  95. void *Stall;
  96. EFI_STATUS (*SetWatchdogTimer)(UINTN Timeout, UINT64 WatchdogCode,
  97. UINTN DataSize, CHAR16 *WatchdogData);
  98. void *ConnectController;
  99. void *DisconnectController;
  100. void *OpenProtocol;
  101. void *CloseProtocol;
  102. void *OpenProtocolInformation;
  103. void *ProtocolsPerHandle;
  104. void *LocateHandleBuffer;
  105. EFI_STATUS (*LocateProtocol)(EFI_GUID *Protocol, void *Registration,
  106. void **Interface);
  107. } EFI_BOOT_SERVICES;
  108. typedef struct {
  109. EFI_TABLE_HEADER Hdr;
  110. CHAR16 *FirmwareVendor;
  111. UINT32 FirmwareRevision;
  112. UINT32 Pad;
  113. EFI_HANDLE ConsoleInHandle;
  114. void *ConIn;
  115. EFI_HANDLE ConsoleOutHandle;
  116. EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *ConOut;
  117. EFI_HANDLE StandardErrorHandle;
  118. EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *StdErr;
  119. void *RuntimeServices;
  120. EFI_BOOT_SERVICES *BootServices;
  121. UINTN NumberOfTableEntries;
  122. EFI_CONFIGURATION_TABLE *ConfigurationTable;
  123. } EFI_SYSTEM_TABLE;
  124. typedef struct {
  125. UINT32 RedMask;
  126. UINT32 GreenMask;
  127. UINT32 BlueMask;
  128. UINT32 ReservedMask;
  129. } EFI_PIXEL_BITMASK;
  130. typedef struct {
  131. UINT32 Version;
  132. UINT32 HorizontalResolution;
  133. UINT32 VerticalResolution;
  134. UINT32 PixelFormat;
  135. EFI_PIXEL_BITMASK PixelInformation;
  136. UINT32 PixelsPerScanLine;
  137. } EFI_GRAPHICS_OUTPUT_MODE_INFORMATION;
  138. typedef struct {
  139. UINT32 MaxMode;
  140. UINT32 Mode;
  141. EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;
  142. UINTN SizeOfInfo;
  143. EFI_PHYSICAL_ADDRESS FrameBufferBase;
  144. UINTN FrameBufferSize;
  145. } EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE;
  146. typedef struct {
  147. EFI_STATUS (*QueryMode)(void *This, UINT32 ModeNumber,
  148. UINTN *SizeOfInfo,
  149. EFI_GRAPHICS_OUTPUT_MODE_INFORMATION **Info);
  150. EFI_STATUS (*SetMode)(void *This, UINT32 ModeNumber);
  151. void *Blt;
  152. EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE *Mode;
  153. } EFI_GRAPHICS_OUTPUT_PROTOCOL;
  154. #define EFI_PIXEL_RGBX 0
  155. #define EFI_PIXEL_BGRX 1
  156. #define EFI_PIXEL_BITMASK 2
  157. #define EFI_PIXEL_BLTONLY 3
  158. #define EFI_ALLOCATE_ANY_PAGES 0
  159. #define EFI_ALLOCATE_MAX_ADDRESS 1
  160. #define EFI_ALLOCATE_ADDRESS 2
  161. #define EFI_LOADER_DATA 2
  162. #define EFI_BOOT_SERVICES_CODE 3
  163. #define EFI_BOOT_SERVICES_DATA 4
  164. #define EFI_CONVENTIONAL_MEMORY 7
  165. static const EFI_GUID efi_gop_guid = {
  166. 0x9042A9DEu, 0x23DC, 0x4A38,
  167. { 0x96, 0xFB, 0x7A, 0xDE, 0xD0, 0x80, 0x51, 0x6A }
  168. };
  169. static const EFI_GUID efi_acpi20_guid = {
  170. 0x8868E871u, 0xE4F1, 0x11D3,
  171. { 0xBC, 0x22, 0x00, 0x80, 0xC7, 0x3C, 0x88, 0x81 }
  172. };
  173. static const EFI_GUID efi_acpi10_guid = {
  174. 0xEB9D2D30u, 0x2D88, 0x11D3,
  175. { 0x9A, 0x16, 0x00, 0x90, 0x27, 0x3F, 0xC1, 0x4D }
  176. };
  177. #endif