setos

拙OS
Log | Files | Refs | LICENSE

uefi.h (9758B)


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