| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259 |
- /* Minimal UEFI definitions for the NebOS x86-64 loader.
- *
- * Only the tables and protocols the loader uses are declared, but the fields
- * before them are in their exact UEFI order so the offsets match the
- * firmware's structures. x86_64-w64-mingw32 uses the Microsoft x64 calling
- * convention, which is the UEFI ABI, so no ms_abi attributes are needed.
- */
- #ifndef NEBOS_EFI_H
- #define NEBOS_EFI_H
- typedef unsigned char UINT8;
- typedef unsigned short UINT16;
- typedef unsigned int UINT32;
- typedef unsigned long long UINT64;
- typedef unsigned long long UINTN;
- typedef UINTN EFI_STATUS;
- typedef void *EFI_HANDLE;
- typedef UINT64 EFI_PHYSICAL_ADDRESS;
- typedef UINT64 EFI_VIRTUAL_ADDRESS;
- typedef UINT16 CHAR16;
- typedef UINT8 BOOLEAN;
- #define EFI_SUCCESS 0
- typedef struct {
- UINT32 Data1;
- UINT16 Data2;
- UINT16 Data3;
- UINT8 Data4[8];
- } __attribute__((packed)) EFI_GUID;
- typedef struct {
- UINT64 Signature;
- UINT32 Revision;
- UINT32 HeaderSize;
- UINT32 CRC32;
- UINT32 Reserved;
- } EFI_TABLE_HEADER;
- typedef struct {
- UINT32 Type;
- UINT32 Pad;
- EFI_PHYSICAL_ADDRESS PhysicalStart;
- EFI_VIRTUAL_ADDRESS VirtualStart;
- UINT64 NumberOfPages;
- UINT64 Attribute;
- } __attribute__((packed)) EFI_MEMORY_DESCRIPTOR;
- typedef struct {
- EFI_GUID VendorGuid;
- void *VendorTable;
- } EFI_CONFIGURATION_TABLE;
- /* EFI_DEVICE_PATH_PROTOCOL: type/subtype/2-byte little-endian length. */
- typedef struct {
- UINT8 Type;
- UINT8 SubType;
- UINT8 Length[2];
- } __attribute__((packed)) EFI_DEVICE_PATH_PROTOCOL;
- typedef UINT64 EFI_LBA;
- typedef struct {
- UINT32 MediaId;
- BOOLEAN RemovableMedia;
- BOOLEAN MediaPresent;
- BOOLEAN LogicalPartition;
- BOOLEAN ReadOnly;
- BOOLEAN WriteCaching;
- UINT32 BlockSize;
- UINT32 IoAlign;
- EFI_LBA LastBlock;
- } EFI_BLOCK_IO_MEDIA;
- typedef struct {
- UINT64 Revision;
- EFI_BLOCK_IO_MEDIA *Media;
- EFI_STATUS (*Reset)(void *This, BOOLEAN ExtendedVerification);
- EFI_STATUS (*ReadBlocks)(void *This, UINT32 MediaId, EFI_LBA Lba,
- UINTN BufferSize, void *Buffer);
- void *WriteBlocks;
- void *FlushBlocks;
- } EFI_BLOCK_IO_PROTOCOL;
- typedef struct {
- UINT32 Revision;
- EFI_HANDLE ParentHandle;
- void *SystemTable;
- EFI_HANDLE DeviceHandle;
- EFI_DEVICE_PATH_PROTOCOL *FilePath;
- void *Reserved;
- UINT32 LoadOptionsSize;
- void *LoadOptions;
- void *ImageBase;
- UINT64 ImageSize;
- UINT32 ImageCodeType;
- UINT32 ImageDataType;
- void *Unload;
- } EFI_LOADED_IMAGE_PROTOCOL;
- typedef struct {
- void *Reset;
- EFI_STATUS (*OutputString)(void *This, CHAR16 *String);
- void *TestString;
- void *QueryMode;
- void *SetMode;
- void *SetAttribute;
- void *ClearScreen;
- void *SetCursorPosition;
- void *EnableCursor;
- void *Mode;
- } EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL;
- /* Field order matches EFI_BOOT_SERVICES; only the used entries have typed
- * signatures, the rest are void * but must still be present in order. */
- typedef struct {
- EFI_TABLE_HEADER Hdr;
- void *RaiseTPL;
- void *RestoreTPL;
- EFI_STATUS (*AllocatePages)(UINT32 Type, UINT32 MemoryType,
- UINTN Pages, EFI_PHYSICAL_ADDRESS *Memory);
- void *FreePages;
- EFI_STATUS (*GetMemoryMap)(UINTN *MemoryMapSize,
- EFI_MEMORY_DESCRIPTOR *MemoryMap,
- UINTN *MapKey, UINTN *DescriptorSize,
- UINT32 *DescriptorVersion);
- void *AllocatePool;
- void *FreePool;
- void *CreateEvent;
- void *SetTimer;
- void *WaitForEvent;
- void *SignalEvent;
- void *CloseEvent;
- void *CheckEvent;
- void *InstallProtocolInterface;
- void *ReinstallProtocolInterface;
- void *UninstallProtocolInterface;
- EFI_STATUS (*HandleProtocol)(EFI_HANDLE Handle, EFI_GUID *Protocol,
- void **Interface);
- void *Reserved;
- void *RegisterProtocolNotify;
- EFI_STATUS (*LocateHandle)(UINT32 SearchType, EFI_GUID *Protocol,
- void *SearchKey, UINTN *BufferSize,
- EFI_HANDLE *Buffer);
- EFI_STATUS (*LocateDevicePath)(EFI_GUID *Protocol,
- EFI_DEVICE_PATH_PROTOCOL **DevicePath,
- EFI_HANDLE *Device);
- void *InstallConfigurationTable;
- void *LoadImage;
- void *StartImage;
- void *Exit;
- void *UnloadImage;
- EFI_STATUS (*ExitBootServices)(EFI_HANDLE ImageHandle, UINTN MapKey);
- void *GetNextMonotonicCount;
- void *Stall;
- EFI_STATUS (*SetWatchdogTimer)(UINTN Timeout, UINT64 WatchdogCode,
- UINTN DataSize, CHAR16 *WatchdogData);
- void *ConnectController;
- void *DisconnectController;
- void *OpenProtocol;
- void *CloseProtocol;
- void *OpenProtocolInformation;
- void *ProtocolsPerHandle;
- void *LocateHandleBuffer;
- EFI_STATUS (*LocateProtocol)(EFI_GUID *Protocol, void *Registration,
- void **Interface);
- } EFI_BOOT_SERVICES;
- typedef struct {
- EFI_TABLE_HEADER Hdr;
- CHAR16 *FirmwareVendor;
- UINT32 FirmwareRevision;
- UINT32 Pad;
- EFI_HANDLE ConsoleInHandle;
- void *ConIn;
- EFI_HANDLE ConsoleOutHandle;
- EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *ConOut;
- EFI_HANDLE StandardErrorHandle;
- EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *StdErr;
- void *RuntimeServices;
- EFI_BOOT_SERVICES *BootServices;
- UINTN NumberOfTableEntries;
- EFI_CONFIGURATION_TABLE *ConfigurationTable;
- } EFI_SYSTEM_TABLE;
- typedef struct {
- UINT32 RedMask;
- UINT32 GreenMask;
- UINT32 BlueMask;
- UINT32 ReservedMask;
- } EFI_PIXEL_BITMASK;
- typedef struct {
- UINT32 Version;
- UINT32 HorizontalResolution;
- UINT32 VerticalResolution;
- UINT32 PixelFormat;
- EFI_PIXEL_BITMASK PixelInformation;
- UINT32 PixelsPerScanLine;
- } EFI_GRAPHICS_OUTPUT_MODE_INFORMATION;
- typedef struct {
- UINT32 MaxMode;
- UINT32 Mode;
- EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;
- UINTN SizeOfInfo;
- EFI_PHYSICAL_ADDRESS FrameBufferBase;
- UINTN FrameBufferSize;
- } EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE;
- typedef struct {
- EFI_STATUS (*QueryMode)(void *This, UINT32 ModeNumber,
- UINTN *SizeOfInfo,
- EFI_GRAPHICS_OUTPUT_MODE_INFORMATION **Info);
- EFI_STATUS (*SetMode)(void *This, UINT32 ModeNumber);
- void *Blt;
- EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE *Mode;
- } EFI_GRAPHICS_OUTPUT_PROTOCOL;
- #define EFI_PIXEL_RGBX 0
- #define EFI_PIXEL_BGRX 1
- #define EFI_PIXEL_BITMASK 2
- #define EFI_PIXEL_BLTONLY 3
- #define EFI_ALLOCATE_ANY_PAGES 0
- #define EFI_ALLOCATE_MAX_ADDRESS 1
- #define EFI_ALLOCATE_ADDRESS 2
- #define EFI_LOADER_DATA 2
- #define EFI_BOOT_SERVICES_CODE 3
- #define EFI_BOOT_SERVICES_DATA 4
- #define EFI_CONVENTIONAL_MEMORY 7
- static const EFI_GUID efi_gop_guid = {
- 0x9042A9DEu, 0x23DC, 0x4A38,
- { 0x96, 0xFB, 0x7A, 0xDE, 0xD0, 0x80, 0x51, 0x6A }
- };
- static const EFI_GUID efi_acpi20_guid = {
- 0x8868E871u, 0xE4F1, 0x11D3,
- { 0xBC, 0x22, 0x00, 0x80, 0xC7, 0x3C, 0x88, 0x81 }
- };
- static const EFI_GUID efi_acpi10_guid = {
- 0xEB9D2D30u, 0x2D88, 0x11D3,
- { 0x9A, 0x16, 0x00, 0x90, 0x27, 0x3F, 0xC1, 0x4D }
- };
- static const EFI_GUID efi_loaded_image_guid = {
- 0x5B1B31A1u, 0x9562, 0x11D2,
- { 0x8E, 0x3F, 0x00, 0xA0, 0xC9, 0x69, 0x72, 0x3B }
- };
- static const EFI_GUID efi_device_path_guid = {
- 0x09576E91u, 0x6D3F, 0x11D2,
- { 0x8E, 0x39, 0x00, 0xA0, 0xC9, 0x69, 0x72, 0x3B }
- };
- static const EFI_GUID efi_block_io_guid = {
- 0x964E5B21u, 0x6459, 0x11D2,
- { 0x8E, 0x39, 0x00, 0xA0, 0xC9, 0x69, 0x72, 0x3B }
- };
- #endif
|