uefi.h 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447
  1. /*
  2. * uefi.h
  3. * https://gitlab.com/bztsrc/posix-uefi
  4. *
  5. * Copyright (C) 2021 bzt (bztsrc@gitlab)
  6. *
  7. * Permission is hereby granted, free of charge, to any person
  8. * obtaining a copy of this software and associated documentation
  9. * files (the "Software"), to deal in the Software without
  10. * restriction, including without limitation the rights to use, copy,
  11. * modify, merge, publish, distribute, sublicense, and/or sell copies
  12. * of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be
  16. * included in all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  19. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  20. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  21. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  22. * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  23. * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  25. * DEALINGS IN THE SOFTWARE.
  26. *
  27. * This file is part of the POSIX-UEFI package.
  28. * @brief Main (and only) header file
  29. *
  30. */
  31. #ifndef _UEFI_H_
  32. #define _UEFI_H_
  33. /*** configuration ***/
  34. /* #define UEFI_NO_UTF8 */ /* use wchar_t in your application */
  35. /* #define UEFI_NO_TRACK_ALLOC */ /* do not track allocated buffers' size */
  36. /*** configuration ends ***/
  37. #ifdef __cplusplus
  38. extern "C" {
  39. #endif
  40. /* get these from the compiler or the efi headers, only define if we have neither */
  41. #if !defined(_STDINT_H) && !defined(_GCC_STDINT_H) && !defined(_EFI_INCLUDE_)
  42. #define _STDINT_H
  43. typedef char int8_t;
  44. typedef unsigned char uint8_t;
  45. typedef short int16_t;
  46. typedef unsigned short uint16_t;
  47. typedef int int32_t;
  48. typedef unsigned int uint32_t;
  49. #ifndef __clang__
  50. typedef long int int64_t;
  51. typedef unsigned long int uint64_t;
  52. typedef unsigned long int uintptr_t;
  53. #else
  54. typedef long long int64_t;
  55. typedef unsigned long long uint64_t;
  56. typedef unsigned long long uintptr_t;
  57. #endif
  58. #endif
  59. extern char c_assert1[sizeof(uint32_t) == 4 ? 1 : -1];
  60. extern char c_assert2[sizeof(uint64_t) == 8 ? 1 : -1];
  61. extern char c_assert3[sizeof(uintptr_t) == 8 ? 1 : -1];
  62. #ifndef NULL
  63. #define NULL ((void*)0)
  64. #endif
  65. /*** common defines and typedefs ***/
  66. typedef int64_t intn_t;
  67. typedef uint8_t boolean_t;
  68. #ifndef __cplusplus
  69. typedef uint16_t wchar_t;
  70. #endif
  71. typedef uint64_t uintn_t;
  72. typedef uint64_t size_t;
  73. typedef uint64_t time_t;
  74. typedef uint64_t mode_t;
  75. typedef uint64_t off_t;
  76. typedef uint64_t blkcnt_t;
  77. typedef uint64_t efi_status_t;
  78. typedef uint64_t efi_tpl_t;
  79. typedef uint64_t efi_lba_t;
  80. typedef uint64_t efi_physical_address_t;
  81. typedef uint64_t efi_virtual_address_t;
  82. typedef void *efi_handle_t;
  83. typedef void *efi_event_t;
  84. #ifndef UEFI_NO_UTF8
  85. typedef char char_t;
  86. #define CL(a) a
  87. extern char *__argvutf8;
  88. #else
  89. typedef wchar_t char_t;
  90. #define CL(a) L ## a
  91. #endif
  92. typedef struct {
  93. uint32_t Data1;
  94. uint16_t Data2;
  95. uint16_t Data3;
  96. uint8_t Data4[8];
  97. } efi_guid_t;
  98. typedef struct {
  99. uint8_t Type;
  100. uint8_t SubType;
  101. uint8_t Length[2];
  102. } efi_device_path_t;
  103. typedef struct {
  104. uint32_t Type;
  105. uint32_t Pad;
  106. efi_physical_address_t PhysicalStart;
  107. efi_virtual_address_t VirtualStart;
  108. uint64_t NumberOfPages;
  109. uint64_t Attribute;
  110. } efi_memory_descriptor_t;
  111. typedef struct {
  112. uint64_t Signature;
  113. uint32_t Revision;
  114. uint32_t HeaderSize;
  115. uint32_t CRC32;
  116. uint32_t Reserved;
  117. } efi_table_header_t;
  118. /*** definitions only needed when efi.h (either from EDK II or gnu-efi) is NOT included ***/
  119. #ifndef EFI_SPECIFICATION_MAJOR_REVISION
  120. /* efibind.h */
  121. #ifndef __WCHAR_TYPE__
  122. # define __WCHAR_TYPE__ short
  123. #endif
  124. #define EFIERR(a) (0x8000000000000000 | (unsigned int)(a))
  125. #define EFI_ERROR_MASK 0x8000000000000000
  126. #define EFIERR_OEM(a) (0xc000000000000000 | (unsigned int)(a))
  127. #define BAD_POINTER 0xFBFBFBFBFBFBFBFB
  128. #define MAX_ADDRESS 0xFFFFFFFFFFFFFFFF
  129. #define EFI_SIGNATURE_16(A,B) ((A) | (B<<8))
  130. #define EFI_SIGNATURE_32(A,B,C,D) (EFI_SIGNATURE_16(A,B) | (EFI_SIGNATURE_16(C,D) << 16))
  131. #define EFI_SIGNATURE_64(A,B,C,D,E,F,G,H) (EFI_SIGNATURE_32(A,B,C,D) | ((uint64_t)(EFI_SIGNATURE_32(E,F,G,H)) << 32))
  132. #ifndef EFIAPI
  133. # ifdef _MSC_EXTENSIONS
  134. # define EFIAPI __cdecl
  135. # elif defined(HAVE_USE_MS_ABI)
  136. # define EFIAPI __attribute__((ms_abi))
  137. # else
  138. # define EFIAPI
  139. # endif
  140. #endif
  141. /* efistdarg.h */
  142. typedef __builtin_va_list va_list;
  143. #define va_start(v,l) __builtin_va_start(v,l)
  144. #define va_end(v) __builtin_va_end(v)
  145. #define va_arg(v,l) __builtin_va_arg(v,l)
  146. #define va_copy(d,s) __builtin_va_copy(d,s)
  147. /* efierr.h */
  148. #define EFIWARN(a) (a)
  149. #define EFI_ERROR(a) (((intn_t) a) < 0)
  150. #define EFI_SUCCESS 0
  151. #define EFI_LOAD_ERROR EFIERR(1)
  152. #define EFI_INVALID_PARAMETER EFIERR(2)
  153. #define EFI_UNSUPPORTED EFIERR(3)
  154. #define EFI_BAD_BUFFER_SIZE EFIERR(4)
  155. #define EFI_BUFFER_TOO_SMALL EFIERR(5)
  156. #define EFI_NOT_READY EFIERR(6)
  157. #define EFI_DEVICE_ERROR EFIERR(7)
  158. #define EFI_WRITE_PROTECTED EFIERR(8)
  159. #define EFI_OUT_OF_RESOURCES EFIERR(9)
  160. #define EFI_VOLUME_CORRUPTED EFIERR(10)
  161. #define EFI_VOLUME_FULL EFIERR(11)
  162. #define EFI_NO_MEDIA EFIERR(12)
  163. #define EFI_MEDIA_CHANGED EFIERR(13)
  164. #define EFI_NOT_FOUND EFIERR(14)
  165. #define EFI_ACCESS_DENIED EFIERR(15)
  166. #define EFI_NO_RESPONSE EFIERR(16)
  167. #define EFI_NO_MAPPING EFIERR(17)
  168. #define EFI_TIMEOUT EFIERR(18)
  169. #define EFI_NOT_STARTED EFIERR(19)
  170. #define EFI_ALREADY_STARTED EFIERR(20)
  171. #define EFI_ABORTED EFIERR(21)
  172. #define EFI_ICMP_ERROR EFIERR(22)
  173. #define EFI_TFTP_ERROR EFIERR(23)
  174. #define EFI_PROTOCOL_ERROR EFIERR(24)
  175. #define EFI_INCOMPATIBLE_VERSION EFIERR(25)
  176. #define EFI_SECURITY_VIOLATION EFIERR(26)
  177. #define EFI_CRC_ERROR EFIERR(27)
  178. #define EFI_END_OF_MEDIA EFIERR(28)
  179. #define EFI_END_OF_FILE EFIERR(31)
  180. #define EFI_INVALID_LANGUAGE EFIERR(32)
  181. #define EFI_COMPROMISED_DATA EFIERR(33)
  182. #define EFI_WARN_UNKOWN_GLYPH EFIWARN(1)
  183. #define EFI_WARN_UNKNOWN_GLYPH EFIWARN(1)
  184. #define EFI_WARN_DELETE_FAILURE EFIWARN(2)
  185. #define EFI_WARN_WRITE_FAILURE EFIWARN(3)
  186. #define EFI_WARN_BUFFER_TOO_SMALL EFIWARN(4)
  187. /* efisetjmp.h */
  188. #ifdef __x86_64__
  189. typedef struct {
  190. uint64_t Rbx;
  191. uint64_t Rsp;
  192. uint64_t Rbp;
  193. uint64_t Rdi;
  194. uint64_t Rsi;
  195. uint64_t R12;
  196. uint64_t R13;
  197. uint64_t R14;
  198. uint64_t R15;
  199. uint64_t Rip;
  200. uint64_t MxCsr;
  201. uint8_t XmmBuffer[160];
  202. } __attribute__((aligned(8))) jmp_buf[1];
  203. #endif
  204. #ifdef __aarch64__
  205. typedef struct {
  206. uint64_t X19;
  207. uint64_t X20;
  208. uint64_t X21;
  209. uint64_t X22;
  210. uint64_t X23;
  211. uint64_t X24;
  212. uint64_t X25;
  213. uint64_t X26;
  214. uint64_t X27;
  215. uint64_t X28;
  216. uint64_t FP;
  217. uint64_t LR;
  218. uint64_t IP0;
  219. uint64_t reserved;
  220. uint64_t D8;
  221. uint64_t D9;
  222. uint64_t D10;
  223. uint64_t D11;
  224. uint64_t D12;
  225. uint64_t D13;
  226. uint64_t D14;
  227. uint64_t D15;
  228. } __attribute__((aligned(8))) jmp_buf[1];
  229. #endif
  230. #if defined(__riscv) && __riscv_xlen == 64
  231. typedef struct {
  232. uint64_t pc;
  233. uint64_t sp;
  234. uint64_t regs[12];
  235. double fp[12];
  236. } __attribute__((aligned(8))) jmp_buf[1];
  237. #endif
  238. extern uintn_t setjmp(jmp_buf env) __attribute__((returns_twice));
  239. extern void longjmp(jmp_buf env, uintn_t value) __attribute__((noreturn));
  240. /* efidevp.h */
  241. #define EFI_DEVICE_PATH_PROTOCOL_GUID { 0x9576e91, 0x6d3f, 0x11d2, {0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b} }
  242. #define EFI_DP_TYPE_MASK 0x7F
  243. #define EFI_DP_TYPE_UNPACKED 0x80
  244. #define END_DEVICE_PATH_TYPE 0x7f
  245. #define END_ENTIRE_DEVICE_PATH_SUBTYPE 0xff
  246. #define END_INSTANCE_DEVICE_PATH_SUBTYPE 0x01
  247. #define END_DEVICE_PATH_LENGTH (sizeof(efi_device_path_t))
  248. #define DP_IS_END_TYPE(a)
  249. #define DP_IS_END_SUBTYPE(a) ( ((a)->SubType == END_ENTIRE_DEVICE_PATH_SUBTYPE )
  250. #define DevicePathType(a) ( ((a)->Type) & EFI_DP_TYPE_MASK )
  251. #define DevicePathSubType(a) ( (a)->SubType )
  252. #define DevicePathNodeLength(a) ( ((a)->Length[0]) | ((a)->Length[1] << 8) )
  253. #define NextDevicePathNode(a) ( (efi_device_path_t *) ( ((uint8_t *) (a)) + DevicePathNodeLength(a)))
  254. #define IsDevicePathEndType(a) ( DevicePathType(a) == END_DEVICE_PATH_TYPE )
  255. #define IsDevicePathEndSubType(a) ( (a)->SubType == END_ENTIRE_DEVICE_PATH_SUBTYPE )
  256. #define IsDevicePathEnd(a) ( IsDevicePathEndType(a) && IsDevicePathEndSubType(a) )
  257. #define IsDevicePathUnpacked(a) ( (a)->Type & EFI_DP_TYPE_UNPACKED )
  258. #define SetDevicePathNodeLength(a,l) { \
  259. (a)->Length[0] = (uint8_t) (l); \
  260. (a)->Length[1] = (uint8_t) ((l) >> 8); \
  261. }
  262. #define SetDevicePathEndNode(a) { \
  263. (a)->Type = END_DEVICE_PATH_TYPE; \
  264. (a)->SubType = END_ENTIRE_DEVICE_PATH_SUBTYPE; \
  265. (a)->Length[0] = sizeof(efi_device_path_t); \
  266. (a)->Length[1] = 0; \
  267. }
  268. /* efiapi.h */
  269. #define EFI_SPECIFICATION_MAJOR_REVISION 1
  270. #define EFI_SPECIFICATION_MINOR_REVISION 02
  271. #define TPL_APPLICATION 4
  272. #define TPL_CALLBACK 8
  273. #define TPL_NOTIFY 16
  274. #define TPL_HIGH_LEVEL 31
  275. #define EFI_TPL_APPLICATION TPL_APPLICATION
  276. #define EFI_TPL_CALLBACK TPL_CALLBACK
  277. #define EFI_TPL_NOTIFY TPL_NOTIFY
  278. #define EFI_TPL_HIGH_LEVEL TPL_HIGH_LEVEL
  279. #define NextMemoryDescriptor(Ptr,Size) ((efi_memory_descriptor_t *) (((uint8_t *) Ptr) + Size))
  280. #define EFI_PAGE_SIZE 4096
  281. #define EFI_PAGE_MASK 0xFFF
  282. #define EFI_PAGE_SHIFT 12
  283. #define EFI_SIZE_TO_PAGES(a) ( ((a) >> EFI_PAGE_SHIFT) + ((a) & EFI_PAGE_MASK ? 1 : 0) )
  284. #define EFI_MEMORY_UC 0x0000000000000001
  285. #define EFI_MEMORY_WC 0x0000000000000002
  286. #define EFI_MEMORY_WT 0x0000000000000004
  287. #define EFI_MEMORY_WB 0x0000000000000008
  288. #define EFI_MEMORY_UCE 0x0000000000000010
  289. #define EFI_MEMORY_WP 0x0000000000001000
  290. #define EFI_MEMORY_RP 0x0000000000002000
  291. #define EFI_MEMORY_XP 0x0000000000004000
  292. #define EFI_MEMORY_RUNTIME 0x8000000000000000
  293. #define EFI_MEMORY_DESCRIPTOR_VERSION 1
  294. #define EVT_TIMER 0x80000000
  295. #define EVT_RUNTIME 0x40000000
  296. #define EVT_RUNTIME_CONTEXT 0x20000000
  297. #define EVT_NOTIFY_WAIT 0x00000100
  298. #define EVT_NOTIFY_SIGNAL 0x00000200
  299. #define EVT_SIGNAL_EXIT_BOOT_SERVICES 0x00000201
  300. #define EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE 0x60000202
  301. #define EVT_EFI_SIGNAL_MASK 0x000000FF
  302. #define EVT_EFI_SIGNAL_MAX 4
  303. #define EFI_EVENT_TIMER EVT_TIMER
  304. #define EFI_EVENT_RUNTIME EVT_RUNTIME
  305. #define EFI_EVENT_RUNTIME_CONTEXT EVT_RUNTIME_CONTEXT
  306. #define EFI_EVENT_NOTIFY_WAIT EVT_NOTIFY_WAIT
  307. #define EFI_EVENT_NOTIFY_SIGNAL EVT_NOTIFY_SIGNAL
  308. #define EFI_EVENT_SIGNAL_EXIT_BOOT_SERVICES EVT_SIGNAL_EXIT_BOOT_SERVICES
  309. #define EFI_EVENT_SIGNAL_VIRTUAL_ADDRESS_CHANGE EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE
  310. #define EFI_EVENT_EFI_SIGNAL_MASK EVT_EFI_SIGNAL_MASK
  311. #define EFI_EVENT_EFI_SIGNAL_MAX EVT_EFI_SIGNAL_MAX
  312. #define EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL 0x00000001
  313. #define EFI_OPEN_PROTOCOL_GET_PROTOCOL 0x00000002
  314. #define EFI_OPEN_PROTOCOL_TEST_PROTOCOL 0x00000004
  315. #define EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER 0x00000008
  316. #define EFI_OPEN_PROTOCOL_BY_DRIVER 0x00000010
  317. #define EFI_OPEN_PROTOCOL_EXCLUSIVE 0x00000020
  318. #define EFI_OPTIONAL_PTR 0x00000001
  319. #define EFI_INTERNAL_FNC 0x00000002
  320. #define EFI_INTERNAL_PTR 0x00000004
  321. #define EFI_GLOBAL_VARIABLE { 0x8BE4DF61, 0x93CA, 0x11d2, {0xAA, 0x0D, 0x00, 0xE0, 0x98, 0x03, 0x2B, 0x8C} }
  322. #define EFI_VARIABLE_NON_VOLATILE 0x00000001
  323. #define EFI_VARIABLE_BOOTSERVICE_ACCESS 0x00000002
  324. #define EFI_VARIABLE_RUNTIME_ACCESS 0x00000004
  325. #define EFI_VARIABLE_HARDWARE_ERROR_RECORD 0x00000008
  326. #define EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS 0x00000010
  327. #define EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS 0x00000020
  328. #define EFI_VARIABLE_APPEND_WRITE 0x00000040
  329. #define EFI_MAXIMUM_VARIABLE_SIZE 1024
  330. #define CAPSULE_FLAGS_PERSIST_ACROSS_RESET 0x00010000
  331. #define CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE 0x00020000
  332. #define CAPSULE_FLAGS_INITIATE_RESET 0x00040000
  333. #define MPS_TABLE_GUID { 0xeb9d2d2f, 0x2d88, 0x11d3, {0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d} }
  334. #define ACPI_TABLE_GUID { 0xeb9d2d30, 0x2d88, 0x11d3, {0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d} }
  335. #define ACPI_20_TABLE_GUID { 0x8868e871, 0xe4f1, 0x11d3, {0xbc, 0x22, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81} }
  336. #define SMBIOS_TABLE_GUID { 0xeb9d2d31, 0x2d88, 0x11d3, {0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d} }
  337. #define SMBIOS3_TABLE_GUID { 0xf2fd1544, 0x9794, 0x4a2c, {0x99, 0x2e,0xe5, 0xbb, 0xcf, 0x20, 0xe3, 0x94} }
  338. #define SAL_SYSTEM_TABLE_GUID { 0xeb9d2d32, 0x2d88, 0x11d3, {0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d} }
  339. #define EFI_RUNTIME_SERVICES_SIGNATURE 0x56524553544e5552
  340. #define EFI_RUNTIME_SERVICES_REVISION (EFI_SPECIFICATION_MAJOR_REVISION<<16) | (EFI_SPECIFICATION_MINOR_REVISION)
  341. #define EFI_BOOT_SERVICES_SIGNATURE 0x56524553544f4f42
  342. #define EFI_BOOT_SERVICES_REVISION (EFI_SPECIFICATION_MAJOR_REVISION<<16) | (EFI_SPECIFICATION_MINOR_REVISION)
  343. #define EFI_SYSTEM_TABLE_SIGNATURE 0x5453595320494249
  344. #define EFI_SYSTEM_TABLE_REVISION (EFI_SPECIFICATION_MAJOR_REVISION<<16) | (EFI_SPECIFICATION_MINOR_REVISION)
  345. /* eficon.h */
  346. #define EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL_GUID { 0x387477c2, 0x69c7, 0x11d2, {0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b} }
  347. #define EFI_BLACK 0x00
  348. #define EFI_BLUE 0x01
  349. #define EFI_GREEN 0x02
  350. #define EFI_CYAN (EFI_BLUE | EFI_GREEN)
  351. #define EFI_RED 0x04
  352. #define EFI_MAGENTA (EFI_BLUE | EFI_RED)
  353. #define EFI_BROWN (EFI_GREEN | EFI_RED)
  354. #define EFI_LIGHTGRAY (EFI_BLUE | EFI_GREEN | EFI_RED)
  355. #define EFI_BRIGHT 0x08
  356. #define EFI_DARKGRAY (EFI_BRIGHT)
  357. #define EFI_LIGHTBLUE (EFI_BLUE | EFI_BRIGHT)
  358. #define EFI_LIGHTGREEN (EFI_GREEN | EFI_BRIGHT)
  359. #define EFI_LIGHTCYAN (EFI_CYAN | EFI_BRIGHT)
  360. #define EFI_LIGHTRED (EFI_RED | EFI_BRIGHT)
  361. #define EFI_LIGHTMAGENTA (EFI_MAGENTA | EFI_BRIGHT)
  362. #define EFI_YELLOW (EFI_BROWN | EFI_BRIGHT)
  363. #define EFI_WHITE (EFI_BLUE | EFI_GREEN | EFI_RED | EFI_BRIGHT)
  364. #define EFI_TEXT_ATTR(f,b) ((f) | ((b) << 4))
  365. #define EFI_BACKGROUND_BLACK 0x00
  366. #define EFI_BACKGROUND_BLUE 0x10
  367. #define EFI_BACKGROUND_GREEN 0x20
  368. #define EFI_BACKGROUND_CYAN (EFI_BACKGROUND_BLUE | EFI_BACKGROUND_GREEN)
  369. #define EFI_BACKGROUND_RED 0x40
  370. #define EFI_BACKGROUND_MAGENTA (EFI_BACKGROUND_BLUE | EFI_BACKGROUND_RED)
  371. #define EFI_BACKGROUND_BROWN (EFI_BACKGROUND_GREEN | EFI_BACKGROUND_RED)
  372. #define EFI_BACKGROUND_LIGHTGRAY (EFI_BACKGROUND_BLUE | EFI_BACKGROUND_GREEN | EFI_BACKGROUND_RED)
  373. #define BOXDRAW_HORIZONTAL 0x2500
  374. #define BOXDRAW_VERTICAL 0x2502
  375. #define BOXDRAW_DOWN_RIGHT 0x250c
  376. #define BOXDRAW_DOWN_LEFT 0x2510
  377. #define BOXDRAW_UP_RIGHT 0x2514
  378. #define BOXDRAW_UP_LEFT 0x2518
  379. #define BOXDRAW_VERTICAL_RIGHT 0x251c
  380. #define BOXDRAW_VERTICAL_LEFT 0x2524
  381. #define BOXDRAW_DOWN_HORIZONTAL 0x252c
  382. #define BOXDRAW_UP_HORIZONTAL 0x2534
  383. #define BOXDRAW_VERTICAL_HORIZONTAL 0x253c
  384. #define BOXDRAW_DOUBLE_HORIZONTAL 0x2550
  385. #define BOXDRAW_DOUBLE_VERTICAL 0x2551
  386. #define BOXDRAW_DOWN_RIGHT_DOUBLE 0x2552
  387. #define BOXDRAW_DOWN_DOUBLE_RIGHT 0x2553
  388. #define BOXDRAW_DOUBLE_DOWN_RIGHT 0x2554
  389. #define BOXDRAW_DOWN_LEFT_DOUBLE 0x2555
  390. #define BOXDRAW_DOWN_DOUBLE_LEFT 0x2556
  391. #define BOXDRAW_DOUBLE_DOWN_LEFT 0x2557
  392. #define BOXDRAW_UP_RIGHT_DOUBLE 0x2558
  393. #define BOXDRAW_UP_DOUBLE_RIGHT 0x2559
  394. #define BOXDRAW_DOUBLE_UP_RIGHT 0x255a
  395. #define BOXDRAW_UP_LEFT_DOUBLE 0x255b
  396. #define BOXDRAW_UP_DOUBLE_LEFT 0x255c
  397. #define BOXDRAW_DOUBLE_UP_LEFT 0x255d
  398. #define BOXDRAW_VERTICAL_RIGHT_DOUBLE 0x255e
  399. #define BOXDRAW_VERTICAL_DOUBLE_RIGHT 0x255f
  400. #define BOXDRAW_DOUBLE_VERTICAL_RIGHT 0x2560
  401. #define BOXDRAW_VERTICAL_LEFT_DOUBLE 0x2561
  402. #define BOXDRAW_VERTICAL_DOUBLE_LEFT 0x2562
  403. #define BOXDRAW_DOUBLE_VERTICAL_LEFT 0x2563
  404. #define BOXDRAW_DOWN_HORIZONTAL_DOUBLE 0x2564
  405. #define BOXDRAW_DOWN_DOUBLE_HORIZONTAL 0x2565
  406. #define BOXDRAW_DOUBLE_DOWN_HORIZONTAL 0x2566
  407. #define BOXDRAW_UP_HORIZONTAL_DOUBLE 0x2567
  408. #define BOXDRAW_UP_DOUBLE_HORIZONTAL 0x2568
  409. #define BOXDRAW_DOUBLE_UP_HORIZONTAL 0x2569
  410. #define BOXDRAW_VERTICAL_HORIZONTAL_DOUBLE 0x256a
  411. #define BOXDRAW_VERTICAL_DOUBLE_HORIZONTAL 0x256b
  412. #define BOXDRAW_DOUBLE_VERTICAL_HORIZONTAL 0x256c
  413. #define BLOCKELEMENT_FULL_BLOCK 0x2588
  414. #define BLOCKELEMENT_LIGHT_SHADE 0x2591
  415. #define GEOMETRICSHAPE_UP_TRIANGLE 0x25b2
  416. #define GEOMETRICSHAPE_RIGHT_TRIANGLE 0x25ba
  417. #define GEOMETRICSHAPE_DOWN_TRIANGLE 0x25bc
  418. #define GEOMETRICSHAPE_LEFT_TRIANGLE 0x25c4
  419. #define ARROW_UP 0x2191
  420. #define ARROW_DOWN 0x2193
  421. #define EFI_SIMPLE_TEXT_INPUT_PROTOCOL_GUID { 0x387477c1, 0x69c7, 0x11d2, {0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b} }
  422. #define CHAR_NULL 0x0000
  423. #define CHAR_BACKSPACE 0x0008
  424. #define CHAR_TAB 0x0009
  425. #define CHAR_LINEFEED 0x000A
  426. #define CHAR_CARRIAGE_RETURN 0x000D
  427. #define SCAN_NULL 0x0000
  428. #define SCAN_UP 0x0001
  429. #define SCAN_DOWN 0x0002
  430. #define SCAN_RIGHT 0x0003
  431. #define SCAN_LEFT 0x0004
  432. #define SCAN_HOME 0x0005
  433. #define SCAN_END 0x0006
  434. #define SCAN_INSERT 0x0007
  435. #define SCAN_DELETE 0x0008
  436. #define SCAN_PAGE_UP 0x0009
  437. #define SCAN_PAGE_DOWN 0x000A
  438. #define SCAN_F1 0x000B
  439. #define SCAN_F2 0x000C
  440. #define SCAN_F3 0x000D
  441. #define SCAN_F4 0x000E
  442. #define SCAN_F5 0x000F
  443. #define SCAN_F6 0x0010
  444. #define SCAN_F7 0x0011
  445. #define SCAN_F8 0x0012
  446. #define SCAN_F9 0x0013
  447. #define SCAN_F10 0x0014
  448. #define SCAN_F11 0x0015
  449. #define SCAN_F12 0x0016
  450. #define SCAN_ESC 0x0017
  451. /* efigpt.h */
  452. #define PRIMARY_PART_HEADER_LBA 1
  453. #define EFI_PTAB_HEADER_ID "EFI PART"
  454. #define EFI_PART_USED_BY_EFI 0x0000000000000001
  455. #define EFI_PART_REQUIRED_TO_FUNCTION 0x0000000000000002
  456. #define EFI_PART_USED_BY_OS 0x0000000000000004
  457. #define EFI_PART_REQUIRED_BY_OS 0x0000000000000008
  458. #define EFI_PART_BACKUP_REQUIRED 0x0000000000000010
  459. #define EFI_PART_USER_DATA 0x0000000000000020
  460. #define EFI_PART_CRITICAL_USER_DATA 0x0000000000000040
  461. #define EFI_PART_REDUNDANT_PARTITION 0x0000000000000080
  462. #define EFI_PART_TYPE_UNUSED_GUID { 0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} }
  463. #define EFI_PART_TYPE_EFI_SYSTEM_PART_GUID { 0xc12a7328, 0xf81f, 0x11d2, {0xba, 0x4b, 0x00, 0xa0, 0xc9, 0x3e, 0xc9, 0x3b} }
  464. #define EFI_PART_TYPE_LEGACY_MBR_GUID { 0x024dee41, 0x33e7, 0x11d3, {0x9d, 0x69, 0x00, 0x08, 0xc7, 0x81, 0xf3, 0x9f} }
  465. /* Protocol GUIDs */
  466. #ifndef INTERNAL_SHELL_GUID
  467. #define INTERNAL_SHELL_GUID { 0xd65a6b8c, 0x71e5, 0x4df0, {0xa9, 0x09, 0xf0, 0xd2, 0x99, 0x2b, 0x5a, 0xa9} }
  468. #endif
  469. typedef enum {
  470. AllocateAnyPages,
  471. AllocateMaxAddress,
  472. AllocateAddress,
  473. MaxAllocateType
  474. } efi_allocate_type_t;
  475. typedef enum {
  476. EfiReservedMemoryType,
  477. EfiLoaderCode,
  478. EfiLoaderData,
  479. EfiBootServicesCode,
  480. EfiBootServicesData,
  481. EfiRuntimeServicesCode,
  482. EfiRuntimeServicesData,
  483. EfiConventionalMemory,
  484. EfiUnusableMemory,
  485. EfiACPIReclaimMemory,
  486. EfiACPIMemoryNVS,
  487. EfiMemoryMappedIO,
  488. EfiMemoryMappedIOPortSpace,
  489. EfiPalCode,
  490. EfiPersistentMemory,
  491. EfiUnacceptedMemoryType,
  492. EfiMaxMemoryType
  493. } efi_memory_type_t;
  494. typedef enum {
  495. TimerCancel,
  496. TimerPeriodic,
  497. TimerRelative,
  498. TimerTypeMax
  499. } efi_timer_delay_t;
  500. typedef enum {
  501. AllHandles,
  502. ByRegisterNotify,
  503. ByProtocol
  504. } efi_locate_search_type_t;
  505. typedef enum {
  506. EfiResetCold,
  507. EfiResetWarm,
  508. EfiResetShutdown
  509. } efi_reset_type_t;
  510. #else
  511. #define efi_allocate_type_t EFI_ALLOCATE_TYPE
  512. #define efi_memory_type_t EFI_MEMORY_TYPE
  513. #define efi_timer_delay_t EFI_TIMER_DELAY
  514. #define efi_locate_search_type_t EFI_LOCATE_SEARCH_TYPE
  515. #define efi_reset_type_t EFI_RESET_TYPE
  516. #endif
  517. /*** standard input, output and error streams via ConIn, ConOut and StdErr ***/
  518. typedef struct {
  519. uint16_t ScanCode;
  520. wchar_t UnicodeChar;
  521. } efi_input_key_t;
  522. typedef efi_status_t (EFIAPI *efi_input_reset_t)(void *This, boolean_t ExtendedVerification);
  523. typedef efi_status_t (EFIAPI *efi_input_read_key_t)(void *This, efi_input_key_t *Key);
  524. typedef struct {
  525. efi_input_reset_t Reset;
  526. efi_input_read_key_t ReadKeyStroke;
  527. efi_event_t WaitForKey;
  528. } simple_input_interface_t;
  529. typedef efi_status_t (EFIAPI *efi_text_reset_t)(void *This, boolean_t ExtendedVerification);
  530. typedef efi_status_t (EFIAPI *efi_text_output_string_t)(void *This, wchar_t *String);
  531. typedef efi_status_t (EFIAPI *efi_text_test_string_t)(void *This, wchar_t *String);
  532. typedef efi_status_t (EFIAPI *efi_text_query_mode_t)(void *This, uintn_t ModeNumber, uintn_t *Column, uintn_t *Row);
  533. typedef efi_status_t (EFIAPI *efi_text_set_mode_t)(void *This, uintn_t ModeNumber);
  534. typedef efi_status_t (EFIAPI *efi_text_set_attribute_t)(void *This, uintn_t Attribute);
  535. typedef efi_status_t (EFIAPI *efi_text_clear_screen_t)(void *This);
  536. typedef efi_status_t (EFIAPI *efi_text_set_cursor_t)(void *This, uintn_t Column, uintn_t Row);
  537. typedef efi_status_t (EFIAPI *efi_text_enable_cursor_t)(void *This, boolean_t Enable);
  538. typedef struct {
  539. int32_t MaxMode;
  540. int32_t Mode;
  541. int32_t Attribute;
  542. int32_t CursorColumn;
  543. int32_t CursorRow;
  544. boolean_t CursorVisible;
  545. } simple_text_output_mode_t;
  546. typedef struct {
  547. efi_text_reset_t Reset;
  548. efi_text_output_string_t OutputString;
  549. efi_text_test_string_t TestString;
  550. efi_text_query_mode_t QueryMode;
  551. efi_text_set_mode_t SetMode;
  552. efi_text_set_attribute_t SetAttribute;
  553. efi_text_clear_screen_t ClearScreen;
  554. efi_text_set_cursor_t SetCursorPosition;
  555. efi_text_enable_cursor_t EnableCursor;
  556. simple_text_output_mode_t *Mode;
  557. } simple_text_output_interface_t;
  558. /*** Runtime Services ***/
  559. typedef struct {
  560. uint16_t Year; /* 1998 - 2XXX */
  561. uint8_t Month; /* 1 - 12 */
  562. uint8_t Day; /* 1 - 31 */
  563. uint8_t Hour; /* 0 - 23 */
  564. uint8_t Minute; /* 0 - 59 */
  565. uint8_t Second; /* 0 - 59 */
  566. uint8_t Pad1;
  567. uint32_t Nanosecond; /* 0 - 999,999,999 */
  568. int16_t TimeZone; /* -1440 to 1440 or 2047 */
  569. uint8_t Daylight;
  570. uint8_t Pad2;
  571. } efi_time_t;
  572. typedef struct {
  573. uint32_t Resolution;
  574. uint32_t Accuracy;
  575. boolean_t SetsToZero;
  576. } efi_time_capabilities_t;
  577. typedef struct {
  578. efi_guid_t CapsuleGuid;
  579. uint32_t HeaderSize;
  580. uint32_t Flags;
  581. uint32_t CapsuleImageSize;
  582. } efi_capsule_header_t;
  583. #ifndef DataBlock
  584. #define DataBlock ContinuationPointer
  585. #endif
  586. typedef struct {
  587. uint64_t Length;
  588. efi_physical_address_t ContinuationPointer;
  589. } efi_capsule_block_descriptor_t;
  590. typedef efi_status_t (EFIAPI *efi_get_time_t)(efi_time_t *Time, efi_time_capabilities_t *Capabilities);
  591. typedef efi_status_t (EFIAPI *efi_set_time_t)(efi_time_t *Time);
  592. typedef efi_status_t (EFIAPI *efi_get_wakeup_time_t)(boolean_t *Enable, boolean_t *Pending, efi_time_t *Time);
  593. typedef efi_status_t (EFIAPI *efi_set_wakeup_time_t)(boolean_t Enable, efi_time_t *Time);
  594. typedef efi_status_t (EFIAPI *efi_set_virtual_address_map_t)(uintn_t MemoryMapSize, uintn_t DescriptorSize,
  595. uint32_t DescriptorVersion, efi_memory_descriptor_t *VirtualMap);
  596. typedef efi_status_t (EFIAPI *efi_convert_pointer_t)(uintn_t DebugDisposition, void **Address);
  597. typedef efi_status_t (EFIAPI *efi_get_variable_t)(wchar_t *VariableName, efi_guid_t *VendorGuid, uint32_t *Attributes,
  598. uintn_t *DataSize, void *Data);
  599. typedef efi_status_t (EFIAPI *efi_get_next_variable_name_t)(uintn_t *VariableNameSize, wchar_t *VariableName,
  600. efi_guid_t *VendorGuid);
  601. typedef efi_status_t (EFIAPI *efi_set_variable_t)(wchar_t *VariableName, efi_guid_t *VendorGuid, uint32_t Attributes,
  602. uintn_t DataSize, void *Data);
  603. typedef efi_status_t (EFIAPI *efi_get_next_high_mono_t)(uint64_t *Count);
  604. typedef efi_status_t (EFIAPI *efi_reset_system_t)(efi_reset_type_t ResetType, efi_status_t ResetStatus, uintn_t DataSize,
  605. wchar_t *ResetData);
  606. typedef efi_status_t (EFIAPI *efi_update_capsule_t)(efi_capsule_header_t **CapsuleHeaderArray, uintn_t CapsuleCount,
  607. efi_physical_address_t ScatterGatherList);
  608. typedef efi_status_t (EFIAPI *efi_query_capsule_capabilities_t)(efi_capsule_header_t **CapsuleHeaderArray, uintn_t CapsuleCount,
  609. uint64_t *MaximumCapsuleSize, efi_reset_type_t *ResetType);
  610. typedef efi_status_t (EFIAPI *efi_query_variable_info_t)(uint32_t Attributes, uint64_t *MaximumVariableStorageSize,
  611. uint64_t *RemainingVariableStorageSize, uint64_t *MaximumVariableSize);
  612. typedef struct {
  613. efi_table_header_t Hdr;
  614. efi_get_time_t GetTime;
  615. efi_set_time_t SetTime;
  616. efi_get_wakeup_time_t GetWakeupTime;
  617. efi_set_wakeup_time_t SetWakeupTime;
  618. efi_set_virtual_address_map_t SetVirtualAddressMap;
  619. efi_convert_pointer_t ConvertPointer;
  620. efi_get_variable_t GetVariable;
  621. efi_get_next_variable_name_t GetNextVariableName;
  622. efi_set_variable_t SetVariable;
  623. efi_get_next_high_mono_t GetNextHighMonotonicCount;
  624. efi_reset_system_t ResetSystem;
  625. efi_update_capsule_t UpdateCapsule;
  626. efi_query_capsule_capabilities_t QueryCapsuleCapabilities;
  627. efi_query_variable_info_t QueryVariableInfo;
  628. } efi_runtime_services_t;
  629. extern efi_runtime_services_t *RT;
  630. #define gRT RT
  631. /** Boot Services ***/
  632. typedef struct {
  633. efi_handle_t AgentHandle;
  634. efi_handle_t ControllerHandle;
  635. uint32_t Attributes;
  636. uint32_t OpenCount;
  637. } efi_open_protocol_information_entry_t;
  638. typedef efi_tpl_t (EFIAPI *efi_raise_tpl_t)(efi_tpl_t NewTpl);
  639. typedef efi_tpl_t (EFIAPI *efi_restore_tpl_t)(efi_tpl_t OldTpl);
  640. typedef efi_status_t (EFIAPI *efi_allocate_pages_t)(efi_allocate_type_t Type, efi_memory_type_t MemoryType,
  641. uintn_t NoPages, efi_physical_address_t *Memory);
  642. typedef efi_status_t (EFIAPI *efi_free_pages_t)(efi_physical_address_t Memory, uintn_t NoPages);
  643. typedef efi_status_t (EFIAPI *efi_get_memory_map_t)(uintn_t *MemoryMapSize, efi_memory_descriptor_t *MemoryMap,
  644. uintn_t *MapKey, uintn_t *DescriptorSize, uint32_t *DescriptorVersion);
  645. typedef efi_status_t (EFIAPI *efi_allocate_pool_t)(efi_memory_type_t PoolType, uintn_t Size, void **Buffer);
  646. typedef efi_status_t (EFIAPI *efi_free_pool_t)(void *Buffer);
  647. typedef void (EFIAPI *efi_event_notify_t)(efi_event_t Event, void *Context);
  648. typedef efi_status_t (EFIAPI *efi_create_event_t)(uint32_t Type, efi_tpl_t NotifyTpl, efi_event_notify_t NotifyFunction,
  649. void *NextContext, efi_event_t *Event);
  650. typedef efi_status_t (EFIAPI *efi_set_timer_t)(efi_event_t Event, efi_timer_delay_t Type, uint64_t TriggerTime);
  651. typedef efi_status_t (EFIAPI *efi_wait_for_event_t)(uintn_t NumberOfEvents, efi_event_t *Event, uintn_t *Index);
  652. typedef efi_status_t (EFIAPI *efi_signal_event_t)(efi_event_t Event);
  653. typedef efi_status_t (EFIAPI *efi_close_event_t)(efi_event_t Event);
  654. typedef efi_status_t (EFIAPI *efi_check_event_t)(efi_event_t Event);
  655. typedef efi_status_t (EFIAPI *efi_handle_protocol_t)(efi_handle_t Handle, efi_guid_t *Protocol, void **Interface);
  656. typedef efi_status_t (EFIAPI *efi_register_protocol_notify_t)(efi_guid_t *Protocol, efi_event_t Event, void **Registration);
  657. typedef efi_status_t (EFIAPI *efi_locate_handle_t)(efi_locate_search_type_t SearchType, efi_guid_t *Protocol,
  658. void *SearchKey, uintn_t *BufferSize, efi_handle_t *Buffer);
  659. typedef efi_status_t (EFIAPI *efi_locate_device_path_t)(efi_guid_t *Protocol, efi_device_path_t **DevicePath,
  660. efi_handle_t *Device);
  661. typedef efi_status_t (EFIAPI *efi_install_configuration_table_t)(efi_guid_t *Guid, void *Table);
  662. typedef efi_status_t (EFIAPI *efi_image_load_t)(boolean_t BootPolicy, efi_handle_t ParentImageHandle, efi_device_path_t *FilePath,
  663. void *SourceBuffer, uintn_t SourceSize, efi_handle_t *ImageHandle);
  664. typedef efi_status_t (EFIAPI *efi_image_start_t)(efi_handle_t ImageHandle, uintn_t *ExitDataSize, wchar_t **ExitData);
  665. typedef efi_status_t (EFIAPI *efi_exit_t)(efi_handle_t ImageHandle, efi_status_t ExitStatus, uintn_t ExitDataSize,
  666. wchar_t *ExitData);
  667. typedef efi_status_t (EFIAPI *efi_exit_boot_services_t)(efi_handle_t ImageHandle, uintn_t MapKey);
  668. typedef efi_status_t (EFIAPI *efi_get_next_monotonic_t)(uint64_t *Count);
  669. typedef efi_status_t (EFIAPI *efi_stall_t)(uintn_t Microseconds);
  670. typedef efi_status_t (EFIAPI *efi_set_watchdog_timer_t)(uintn_t Timeout, uint64_t WatchdogCode, uintn_t DataSize,
  671. wchar_t *WatchdogData);
  672. typedef efi_status_t (EFIAPI *efi_connect_controller_t)(efi_handle_t ControllerHandle, efi_handle_t *DriverImageHandle,
  673. efi_device_path_t *RemainingDevicePath, boolean_t Recursive);
  674. typedef efi_status_t (EFIAPI *efi_disconnect_controller_t)(efi_handle_t ControllerHandle, efi_handle_t DriverImageHandle,
  675. efi_handle_t ChildHandle);
  676. typedef efi_status_t (EFIAPI *efi_open_protocol_t)(efi_handle_t Handle, efi_guid_t *Protocol, void **Interface,
  677. efi_handle_t AgentHandle, efi_handle_t ControllerHandle, uint32_t Attributes);
  678. typedef efi_status_t (EFIAPI *efi_close_protocol_t)(efi_handle_t Handle, efi_guid_t *Protocol, efi_handle_t AgentHandle,
  679. efi_handle_t ControllerHandle);
  680. typedef efi_status_t (EFIAPI *efi_open_protocol_information_t)(efi_handle_t Handle, efi_guid_t *Protocol,
  681. efi_open_protocol_information_entry_t**EntryBuffer, uintn_t *EntryCount);
  682. typedef efi_status_t (EFIAPI *efi_protocols_per_handle_t)(efi_handle_t Handle, efi_guid_t ***ProtocolBuffer,
  683. uintn_t *ProtocolBufferCount);
  684. typedef efi_status_t (EFIAPI *efi_locate_handle_buffer_t)(efi_locate_search_type_t SearchType, efi_guid_t *Protocol,
  685. void *SearchKey, uintn_t *NoHandles, efi_handle_t **Handles);
  686. typedef efi_status_t (EFIAPI *efi_locate_protocol_t)(efi_guid_t *Protocol, void *Registration, void **Interface);
  687. typedef efi_status_t (EFIAPI *efi_calculate_crc32_t)(void *Data, uintn_t DataSize, uint32_t *Crc32);
  688. typedef struct {
  689. efi_table_header_t Hdr;
  690. efi_raise_tpl_t RaiseTPL;
  691. efi_restore_tpl_t RestoreTPL;
  692. efi_allocate_pages_t AllocatePages;
  693. efi_free_pages_t FreePages;
  694. efi_get_memory_map_t GetMemoryMap;
  695. efi_allocate_pool_t AllocatePool;
  696. efi_free_pool_t FreePool;
  697. efi_create_event_t CreateEvent;
  698. efi_set_timer_t SetTimer;
  699. efi_wait_for_event_t WaitForEvent;
  700. efi_signal_event_t SignalEvent;
  701. efi_close_event_t CloseEvent;
  702. efi_check_event_t CheckEvent;
  703. void* InstallProtocolInterface; /* not defined yet */
  704. void* ReinstallProtocolInterface;
  705. void* UninstallProtocolInterface;
  706. efi_handle_protocol_t HandleProtocol;
  707. efi_handle_protocol_t PCHandleProtocol;
  708. efi_register_protocol_notify_t RegisterProtocolNotify;
  709. efi_locate_handle_t LocateHandle;
  710. efi_locate_device_path_t LocateDevicePath;
  711. efi_install_configuration_table_t InstallConfigurationTable;
  712. efi_image_load_t LoadImage;
  713. efi_image_start_t StartImage;
  714. efi_exit_t Exit;
  715. void* UnloadImage; /* not defined in gnu-efi either */
  716. efi_exit_boot_services_t ExitBootServices;
  717. efi_get_next_monotonic_t GetNextHighMonotonicCount;
  718. efi_stall_t Stall;
  719. efi_set_watchdog_timer_t SetWatchdogTimer;
  720. efi_connect_controller_t ConnectController;
  721. efi_disconnect_controller_t DisconnectController;
  722. efi_open_protocol_t OpenProtocol;
  723. efi_close_protocol_t CloseProtocol;
  724. efi_open_protocol_information_t OpenProtocolInformation;
  725. efi_protocols_per_handle_t ProtocolsPerHandle;
  726. efi_locate_handle_buffer_t LocateHandleBuffer;
  727. efi_locate_protocol_t LocateProtocol;
  728. void* InstallMultipleProtocolInterfaces;
  729. void* UninstallMultipleProtocolInterfaces;
  730. efi_calculate_crc32_t CalculateCrc32;
  731. } efi_boot_services_t;
  732. extern efi_boot_services_t *BS;
  733. #define gBS BS
  734. /*** Loaded Image Protocol ***/
  735. #ifndef EFI_LOADED_IMAGE_PROTOCOL_GUID
  736. #define EFI_LOADED_IMAGE_PROTOCOL_GUID { 0x5B1B31A1, 0x9562, 0x11d2, {0x8E, 0x3F, 0x00, 0xA0, 0xC9, 0x69, 0x72, 0x3B} }
  737. #define LOADED_IMAGE_PROTOCOL EFI_LOADED_IMAGE_PROTOCOL_GUID
  738. #define EFI_LOADED_IMAGE_PROTOCOL_REVISION 0x1000
  739. #define EFI_IMAGE_INFORMATION_REVISION EFI_LOADED_IMAGE_PROTOCOL_REVISION
  740. #endif
  741. typedef struct {
  742. uint32_t Revision;
  743. efi_handle_t ParentHandle;
  744. void *SystemTable;
  745. efi_handle_t DeviceHandle;
  746. efi_device_path_t *FilePath;
  747. void *Reserved;
  748. uint32_t LoadOptionsSize;
  749. void *LoadOptions;
  750. void *ImageBase;
  751. uint64_t ImageSize;
  752. efi_memory_type_t ImageCodeType;
  753. efi_memory_type_t ImageDataType;
  754. } efi_loaded_image_protocol_t;
  755. extern efi_loaded_image_protocol_t *LIP;
  756. extern efi_handle_t IM;
  757. /*** System Table ***/
  758. typedef struct {
  759. efi_guid_t VendorGuid;
  760. void *VendorTable;
  761. } efi_configuration_table_t;
  762. typedef struct {
  763. efi_table_header_t Hdr;
  764. wchar_t *FirmwareVendor;
  765. uint32_t FirmwareRevision;
  766. efi_handle_t ConsoleInHandle;
  767. simple_input_interface_t *ConIn;
  768. efi_handle_t ConsoleOutHandle;
  769. simple_text_output_interface_t *ConOut;
  770. efi_handle_t ConsoleErrorHandle;
  771. simple_text_output_interface_t *StdErr;
  772. efi_runtime_services_t *RuntimeServices;
  773. efi_boot_services_t *BootServices;
  774. uintn_t NumberOfTableEntries;
  775. efi_configuration_table_t *ConfigurationTable;
  776. } efi_system_table_t;
  777. extern efi_system_table_t *ST;
  778. #define gST ST
  779. /*** Simple File System Protocol ***/
  780. #ifndef EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID
  781. #define EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID { 0x964e5b22, 0x6459, 0x11d2, {0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b} }
  782. #define EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION 0x00010000
  783. #define EFI_FILE_IO_INTERFACE_REVISION EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION
  784. #define EFI_FILE_MODE_READ 0x0000000000000001
  785. #define EFI_FILE_MODE_WRITE 0x0000000000000002
  786. #define EFI_FILE_MODE_CREATE 0x8000000000000000
  787. #define EFI_FILE_READ_ONLY 0x0000000000000001
  788. #define EFI_FILE_HIDDEN 0x0000000000000002
  789. #define EFI_FILE_SYSTEM 0x0000000000000004
  790. #define EFI_FILE_RESERVED 0x0000000000000008
  791. #define EFI_FILE_DIRECTORY 0x0000000000000010
  792. #define EFI_FILE_ARCHIVE 0x0000000000000020
  793. #define EFI_FILE_VALID_ATTR 0x0000000000000037
  794. #define EFI_FILE_PROTOCOL_REVISION 0x00010000
  795. #define EFI_FILE_HANDLE_REVISION EFI_FILE_PROTOCOL_REVISION
  796. #endif
  797. #ifndef EFI_FILE_INFO_GUID
  798. #define EFI_FILE_INFO_GUID { 0x9576e92, 0x6d3f, 0x11d2, {0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b} }
  799. #endif
  800. #ifndef FILENAME_MAX
  801. #define FILENAME_MAX 262 /* from FAT spec */
  802. #endif
  803. typedef struct {
  804. uint64_t Size;
  805. uint64_t FileSize;
  806. uint64_t PhysicalSize;
  807. efi_time_t CreateTime;
  808. efi_time_t LastAccessTime;
  809. efi_time_t ModificationTime;
  810. uint64_t Attribute;
  811. wchar_t FileName[FILENAME_MAX];
  812. } efi_file_info_t;
  813. typedef struct efi_file_handle_s efi_file_handle_t;
  814. typedef efi_status_t (EFIAPI *efi_volume_open_t)(void *This, efi_file_handle_t **Root);
  815. typedef struct {
  816. uint64_t Revision;
  817. efi_volume_open_t OpenVolume;
  818. } efi_simple_file_system_protocol_t;
  819. typedef efi_status_t (EFIAPI *efi_file_open_t)(efi_file_handle_t *File, efi_file_handle_t **NewHandle, wchar_t *FileName,
  820. uint64_t OpenMode, uint64_t Attributes);
  821. typedef efi_status_t (EFIAPI *efi_file_close_t)(efi_file_handle_t *File);
  822. typedef efi_status_t (EFIAPI *efi_file_delete_t)(efi_file_handle_t *File);
  823. typedef efi_status_t (EFIAPI *efi_file_read_t)(efi_file_handle_t *File, uintn_t *BufferSize, void *Buffer);
  824. typedef efi_status_t (EFIAPI *efi_file_write_t)(efi_file_handle_t *File, uintn_t *BufferSize, void *Buffer);
  825. typedef efi_status_t (EFIAPI *efi_file_get_pos_t)(efi_file_handle_t *File, uint64_t *Position);
  826. typedef efi_status_t (EFIAPI *efi_file_set_pos_t)(efi_file_handle_t *File, uint64_t Position);
  827. typedef efi_status_t (EFIAPI *efi_file_get_info_t)(efi_file_handle_t *File, efi_guid_t *InformationType, uintn_t *BufferSize,
  828. void *Buffer);
  829. typedef efi_status_t (EFIAPI *efi_file_set_info_t)(efi_file_handle_t *File, efi_guid_t *InformationType, uintn_t BufferSize,
  830. void *Buffer);
  831. typedef efi_status_t (EFIAPI *efi_file_flush_t)(efi_file_handle_t *File);
  832. struct efi_file_handle_s {
  833. uint64_t Revision;
  834. efi_file_open_t Open;
  835. efi_file_close_t Close;
  836. efi_file_delete_t Delete;
  837. efi_file_read_t Read;
  838. efi_file_write_t Write;
  839. efi_file_get_pos_t GetPosition;
  840. efi_file_set_pos_t SetPosition;
  841. efi_file_get_info_t GetInfo;
  842. efi_file_set_info_t SetInfo;
  843. efi_file_flush_t Flush;
  844. };
  845. /*** Shell Parameter Protocols ***/
  846. #ifndef EFI_SHELL_PARAMETERS_PROTOCOL_GUID
  847. #define EFI_SHELL_PARAMETERS_PROTOCOL_GUID { 0x752f3136, 0x4e16, 0x4fdc, {0xa2, 0x2a, 0xe5, 0xf4, 0x68, 0x12, 0xf4, 0xca} }
  848. #endif
  849. typedef struct {
  850. wchar_t **Argv;
  851. uintn_t Argc;
  852. efi_handle_t StdIn;
  853. efi_handle_t StdOut;
  854. efi_handle_t StdErr;
  855. } efi_shell_parameters_protocol_t;
  856. #ifndef SHELL_INTERFACE_PROTOCOL_GUID
  857. #define SHELL_INTERFACE_PROTOCOL_GUID { 0x47c7b223, 0xc42a, 0x11d2, {0x8e, 0x57, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b} }
  858. #endif
  859. typedef struct {
  860. efi_handle_t ImageHandle;
  861. void* *Info;
  862. wchar_t **Argv;
  863. uintn_t Argc;
  864. wchar_t **RedirArgv;
  865. uintn_t RedirArgc;
  866. efi_handle_t StdIn;
  867. efi_handle_t StdOut;
  868. efi_handle_t StdErr;
  869. } efi_shell_interface_protocol_t;
  870. /*** Random Number Generator ***/
  871. #ifndef EFI_RNG_PROTOCOL_GUID
  872. #define EFI_RNG_PROTOCOL_GUID { 0x3152bca5, 0xeade, 0x433d, {0x86, 0x2e, 0xc0, 0x1c, 0xdc, 0x29, 0x1f, 0x44} }
  873. #endif
  874. typedef efi_status_t (EFIAPI *efi_rng_get_info_t)(void *This, uintn_t *RNGAlgorithmListSize, efi_guid_t *RNGAlgorithmList);
  875. typedef efi_status_t (EFIAPI *efi_rng_get_rng_t)(void *This, efi_guid_t *RNGAlgorithm, uintn_t RNGValueLength, uint8_t *RNGValue);
  876. typedef struct {
  877. efi_rng_get_info_t GetInfo;
  878. efi_rng_get_rng_t GetRNG;
  879. } efi_rng_protocol_t;
  880. /*** Serial IO Protocol ***/
  881. #ifndef EFI_SERIAL_IO_PROTOCOL_GUID
  882. #define EFI_SERIAL_IO_PROTOCOL_GUID { 0xBB25CF6F, 0xF1D4, 0x11D2, {0x9A, 0x0C, 0x00, 0x90, 0x27, 0x3F, 0xC1, 0xFD} }
  883. #define SERIAL_IO_INTERFACE_REVISION 0x00010000
  884. #define EFI_SERIAL_CLEAR_TO_SEND 0x0010
  885. #define EFI_SERIAL_DATA_SET_READY 0x0020
  886. #define EFI_SERIAL_RING_INDICATE 0x0040
  887. #define EFI_SERIAL_CARRIER_DETECT 0x0080
  888. #define EFI_SERIAL_REQUEST_TO_SEND 0x0002
  889. #define EFI_SERIAL_DATA_TERMINAL_READY 0x0001
  890. #define EFI_SERIAL_INPUT_BUFFER_EMPTY 0x0100
  891. #define EFI_SERIAL_OUTPUT_BUFFER_EMPTY 0x0200
  892. #define EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE 0x1000
  893. #define EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE 0x2000
  894. #define EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE 0x4000
  895. typedef enum {
  896. DefaultParity,
  897. NoParity,
  898. EvenParity,
  899. OddParity,
  900. MarkParity,
  901. SpaceParity
  902. } efi_parity_type_t;
  903. typedef enum {
  904. DefaultStopBits,
  905. OneStopBit,
  906. OneFiveStopBits,
  907. TwoStopBits
  908. } efi_stop_bits_type_t;
  909. #else
  910. #define efi_parity_type_t EFI_PARITY_TYPE
  911. #define efi_stop_bits_type_t EFI_STOP_BITS_TYPE
  912. #endif
  913. typedef struct {
  914. uint32_t ControlMask;
  915. uint32_t Timeout;
  916. uint64_t BaudRate;
  917. uint32_t ReceiveFifoDepth;
  918. uint32_t DataBits;
  919. uint32_t Parity;
  920. uint32_t StopBits;
  921. } efi_serial_io_mode_t;
  922. typedef efi_status_t (EFIAPI *efi_serial_reset_t)(void *This);
  923. typedef efi_status_t (EFIAPI *efi_serial_set_attributes_t)(void *This, uint64_t BaudRate, uint32_t ReceiveFifoDepth,
  924. uint32_t Timeout, efi_parity_type_t Parity, uint8_t DataBits, efi_stop_bits_type_t StopBits);
  925. typedef efi_status_t (EFIAPI *efi_serial_set_control_bits_t)(void *This, uint32_t Control);
  926. typedef efi_status_t (EFIAPI *efi_serial_get_control_bits_t)(void *This, uint32_t *Control);
  927. typedef efi_status_t (EFIAPI *efi_serial_write_t)(void *This, uintn_t *BufferSize, void *Buffer);
  928. typedef efi_status_t (EFIAPI *efi_serial_read_t)(void *This, uintn_t *BufferSize, void *Buffer);
  929. typedef struct {
  930. uint32_t Revision;
  931. efi_serial_reset_t Reset;
  932. efi_serial_set_attributes_t SetAttributes;
  933. efi_serial_set_control_bits_t SetControl;
  934. efi_serial_get_control_bits_t GetControl;
  935. efi_serial_write_t Write;
  936. efi_serial_read_t Read;
  937. efi_serial_io_mode_t *Mode;
  938. } efi_serial_io_protocol_t;
  939. /*** Block IO Protocol ***/
  940. #ifndef EFI_BLOCK_IO_PROTOCOL_GUID
  941. #define EFI_BLOCK_IO_PROTOCOL_GUID { 0x964e5b21, 0x6459, 0x11d2, {0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b} }
  942. #define EFI_BLOCK_IO_PROTOCOL_REVISION 0x00010000
  943. #define EFI_BLOCK_IO_INTERFACE_REVISION EFI_BLOCK_IO_PROTOCOL_REVISION
  944. #endif
  945. typedef struct {
  946. uint32_t MediaId;
  947. boolean_t RemovableMedia;
  948. boolean_t MediaPresent;
  949. boolean_t LogicalPartition;
  950. boolean_t ReadOnly;
  951. boolean_t WriteCaching;
  952. uint32_t BlockSize;
  953. uint32_t IoAlign;
  954. efi_lba_t LastBlock;
  955. } efi_block_io_media_t;
  956. typedef efi_status_t (EFIAPI *efi_block_reset_t)(void *This, boolean_t ExtendedVerification);
  957. typedef efi_status_t (EFIAPI *efi_block_read_t)(void *This, uint32_t MediaId, efi_lba_t LBA, uintn_t BufferSize, void *Buffer);
  958. typedef efi_status_t (EFIAPI *efi_block_write_t)(void *This, uint32_t MediaId, efi_lba_t LBA, uintn_t BufferSize, void *Buffer);
  959. typedef efi_status_t (EFIAPI *efi_block_flush_t)(void *This);
  960. typedef struct {
  961. uint64_t Revision;
  962. efi_block_io_media_t *Media;
  963. efi_block_reset_t Reset;
  964. efi_block_read_t ReadBlocks;
  965. efi_block_write_t WriteBlocks;
  966. efi_block_flush_t FlushBlocks;
  967. } efi_block_io_t;
  968. typedef struct {
  969. off_t offset;
  970. efi_block_io_t *bio;
  971. } block_file_t;
  972. /*** Graphics Output Protocol (not used, but could be useful to have) ***/
  973. #ifndef EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID
  974. #define EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID { 0x9042a9de, 0x23dc, 0x4a38, {0x96, 0xfb, 0x7a, 0xde, 0xd0, 0x80, 0x51, 0x6a } }
  975. typedef enum {
  976. PixelRedGreenBlueReserved8BitPerColor,
  977. PixelBlueGreenRedReserved8BitPerColor,
  978. PixelBitMask,
  979. PixelBltOnly,
  980. PixelFormatMax
  981. } efi_gop_pixel_format_t;
  982. typedef enum {
  983. EfiBltVideoFill,
  984. EfiBltVideoToBltBuffer,
  985. EfiBltBufferToVideo,
  986. EfiBltVideoToVideo,
  987. EfiGraphicsOutputBltOperationMax
  988. } efi_gop_blt_operation_t;
  989. #else
  990. #define efi_gop_pixel_format_t EFI_GRAPHICS_PIXEL_FORMAT
  991. #define efi_gop_blt_operation_t EFI_GRAPHICS_OUTPUT_BLT_OPERATION
  992. #endif
  993. typedef struct {
  994. uint32_t RedMask;
  995. uint32_t GreenMask;
  996. uint32_t BlueMask;
  997. uint32_t ReservedMask;
  998. } efi_gop_pixel_bitmask_t;
  999. typedef struct {
  1000. uint32_t Version;
  1001. uint32_t HorizontalResolution;
  1002. uint32_t VerticalResolution;
  1003. efi_gop_pixel_format_t PixelFormat;
  1004. efi_gop_pixel_bitmask_t PixelInformation;
  1005. uint32_t PixelsPerScanLine;
  1006. } efi_gop_mode_info_t;
  1007. typedef struct {
  1008. uint32_t MaxMode;
  1009. uint32_t Mode;
  1010. efi_gop_mode_info_t *Information;
  1011. uintn_t SizeOfInfo;
  1012. efi_physical_address_t FrameBufferBase;
  1013. uintn_t FrameBufferSize;
  1014. } efi_gop_mode_t;
  1015. typedef efi_status_t (EFIAPI *efi_gop_query_mode_t)(void *This, uint32_t ModeNumber, uintn_t *SizeOfInfo,
  1016. efi_gop_mode_info_t **Info);
  1017. typedef efi_status_t (EFIAPI *efi_gop_set_mode_t)(void *This, uint32_t ModeNumber);
  1018. typedef efi_status_t (EFIAPI *efi_gop_blt_t)(void *This, uint32_t *BltBuffer, efi_gop_blt_operation_t BltOperation,
  1019. uintn_t SourceX, uintn_t SourceY, uintn_t DestinationX, uintn_t DestionationY, uintn_t Width, uintn_t Height, uintn_t Delta);
  1020. typedef struct {
  1021. efi_gop_query_mode_t QueryMode;
  1022. efi_gop_set_mode_t SetMode;
  1023. efi_gop_blt_t Blt;
  1024. efi_gop_mode_t *Mode;
  1025. } efi_gop_t;
  1026. /*** EDID Protocol (not used, but could be useful to have) ***/
  1027. #ifndef EFI_EDID_ACTIVE_GUID
  1028. #define EFI_EDID_ACTIVE_GUID { 0xbd8c1056, 0x9f36, 0x44ec, { 0x92, 0xa8, 0xa6, 0x33, 0x7f, 0x81, 0x79, 0x86 } }
  1029. #define EFI_EDID_DISCOVERED_GUID { 0x1c0c34f6, 0xd380, 0x41fa, { 0xa0, 0x49, 0x8a, 0xd0, 0x6c, 0x1a, 0x66, 0xaa } }
  1030. #endif
  1031. typedef struct {
  1032. uint32_t SizeOfEdid;
  1033. uint8_t *Edid;
  1034. } efi_edid_t;
  1035. /*** Simple Pointer Protocol (not used, but could be useful to have) ***/
  1036. #ifndef EFI_SIMPLE_POINTER_PROTOCOL_GUID
  1037. #define EFI_SIMPLE_POINTER_PROTOCOL_GUID { 0x31878c87, 0xb75, 0x11d5, { 0x9a, 0x4f, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d } }
  1038. #endif
  1039. typedef struct {
  1040. int32_t RelativeMovementX;
  1041. int32_t RelativeMovementY;
  1042. int32_t RelativeMovementZ;
  1043. boolean_t LeftButton;
  1044. boolean_t RightButton;
  1045. } efi_simple_pointer_state_t;
  1046. typedef struct {
  1047. uint64_t ResolutionX;
  1048. uint64_t ResolutionY;
  1049. uint64_t ResolutionZ;
  1050. boolean_t LeftButton;
  1051. boolean_t RightButton;
  1052. } efi_simple_pointer_mode_t;
  1053. typedef efi_status_t (EFIAPI *efi_simple_pointer_reset_t) (void *This, boolean_t ExtendedVerification);
  1054. typedef efi_status_t (EFIAPI *efi_simple_pointer_get_state_t) (void *This, efi_simple_pointer_state_t *State);
  1055. typedef struct {
  1056. efi_simple_pointer_reset_t Reset;
  1057. efi_simple_pointer_get_state_t GetState;
  1058. efi_event_t WaitForInput;
  1059. efi_simple_pointer_mode_t *Mode;
  1060. } efi_simple_pointer_protocol_t;
  1061. /*** Option ROM Protocol (not used, but could be useful to have) ***/
  1062. #ifndef EFI_PCI_OPTION_ROM_TABLE_GUID
  1063. #define EFI_PCI_OPTION_ROM_TABLE_GUID { 0x7462660f, 0x1cbd, 0x48da, {0xad, 0x11, 0x91, 0x71, 0x79, 0x13, 0x83, 0x1c} }
  1064. #endif
  1065. typedef struct {
  1066. efi_physical_address_t RomAddress;
  1067. efi_memory_type_t MemoryType;
  1068. uint32_t RomLength;
  1069. uint32_t Seg;
  1070. uint8_t Bus;
  1071. uint8_t Dev;
  1072. uint8_t Func;
  1073. boolean_t ExecutedLegacyBiosImage;
  1074. boolean_t DontLoadEfiRom;
  1075. } efi_pci_option_rom_descriptor_t;
  1076. typedef struct {
  1077. uint64_t PciOptionRomCount;
  1078. efi_pci_option_rom_descriptor_t *PciOptionRomDescriptors;
  1079. } efi_pci_option_rom_table_t;
  1080. /*** GPT partitioning table (not used, but could be useful to have) ***/
  1081. typedef struct {
  1082. efi_table_header_t Header;
  1083. efi_lba_t MyLBA;
  1084. efi_lba_t AlternateLBA;
  1085. efi_lba_t FirstUsableLBA;
  1086. efi_lba_t LastUsableLBA;
  1087. efi_guid_t DiskGUID;
  1088. efi_lba_t PartitionEntryLBA;
  1089. uint32_t NumberOfPartitionEntries;
  1090. uint32_t SizeOfPartitionEntry;
  1091. uint32_t PartitionEntryArrayCRC32;
  1092. } efi_partition_table_header_t;
  1093. typedef struct {
  1094. efi_guid_t PartitionTypeGUID;
  1095. efi_guid_t UniquePartitionGUID;
  1096. efi_lba_t StartingLBA;
  1097. efi_lba_t EndingLBA;
  1098. uint64_t Attributes;
  1099. wchar_t PartitionName[36];
  1100. } efi_partition_entry_t;
  1101. /*** POSIX definitions ***/
  1102. #define abs(x) ((x)<0?-(x):(x))
  1103. #define min(x,y) ((x)<(y)?(x):(y))
  1104. #define max(x,y) ((x)>(y)?(x):(y))
  1105. /* dirent.h */
  1106. #define IFTODT(mode) (((mode) & 0170000) >> 12)
  1107. #define DTTOIF(dirtype) ((dirtype) << 12)
  1108. #define DT_DIR 4
  1109. #define DT_REG 8
  1110. struct dirent {
  1111. unsigned short int d_reclen;
  1112. unsigned char d_type;
  1113. char_t d_name[FILENAME_MAX];
  1114. };
  1115. typedef struct efi_file_handle_s DIR;
  1116. extern DIR *opendir (const char_t *__name);
  1117. extern struct dirent *readdir (DIR *__dirp);
  1118. extern void rewinddir (DIR *__dirp);
  1119. extern int closedir (DIR *__dirp);
  1120. /* errno.h */
  1121. extern int errno;
  1122. #define EPERM 1 /* Operation not permitted */
  1123. #define ENOENT 2 /* No such file or directory */
  1124. #define ESRCH 3 /* No such process */
  1125. #define EINTR 4 /* Interrupted system call */
  1126. #define EIO 5 /* I/O error */
  1127. #define ENXIO 6 /* No such device or address */
  1128. #define E2BIG 7 /* Argument list too long */
  1129. #define ENOEXEC 8 /* Exec format error */
  1130. #define EBADF 9 /* Bad file number */
  1131. #define ECHILD 10 /* No child processes */
  1132. #define EAGAIN 11 /* Try again */
  1133. #define ENOMEM 12 /* Out of memory */
  1134. #define EACCES 13 /* Permission denied */
  1135. #define EFAULT 14 /* Bad address */
  1136. #define ENOTBLK 15 /* Block device required */
  1137. #define EBUSY 16 /* Device or resource busy */
  1138. #define EEXIST 17 /* File exists */
  1139. #define EXDEV 18 /* Cross-device link */
  1140. #define ENODEV 19 /* No such device */
  1141. #define ENOTDIR 20 /* Not a directory */
  1142. #define EISDIR 21 /* Is a directory */
  1143. #define EINVAL 22 /* Invalid argument */
  1144. #define ENFILE 23 /* File table overflow */
  1145. #define EMFILE 24 /* Too many open files */
  1146. #define ENOTTY 25 /* Not a typewriter */
  1147. #define ETXTBSY 26 /* Text file busy */
  1148. #define EFBIG 27 /* File too large */
  1149. #define ENOSPC 28 /* No space left on device */
  1150. #define ESPIPE 29 /* Illegal seek */
  1151. #define EROFS 30 /* Read-only file system */
  1152. #define EMLINK 31 /* Too many links */
  1153. #define EPIPE 32 /* Broken pipe */
  1154. #define EDOM 33 /* Math argument out of domain of func */
  1155. #define ERANGE 34 /* Math result not representable */
  1156. /* stdlib.h */
  1157. #define RAND_MAX 2147483647
  1158. typedef int (*__compar_fn_t) (const void *, const void *);
  1159. extern int atoi (const char_t *__nptr);
  1160. extern int64_t atol (const char_t *__nptr);
  1161. extern int64_t strtol (const char_t *__nptr, char_t **__endptr, int __base);
  1162. extern void *malloc (size_t __size);
  1163. extern void *calloc (size_t __nmemb, size_t __size);
  1164. extern void *realloc (void *__ptr, size_t __size);
  1165. extern void free (void *__ptr);
  1166. extern void abort (void);
  1167. extern void exit (int __status);
  1168. /* exit Boot Services function. Returns 0 on success. */
  1169. extern int exit_bs(void);
  1170. extern void *bsearch (const void *__key, const void *__base, size_t __nmemb, size_t __size, __compar_fn_t __compar);
  1171. extern void qsort (void *__base, size_t __nmemb, size_t __size, __compar_fn_t __compar);
  1172. extern int mblen (const char *__s, size_t __n);
  1173. extern int mbtowc (wchar_t * __pwc, const char * __s, size_t __n);
  1174. extern int wctomb (char *__s, wchar_t __wchar);
  1175. extern size_t mbstowcs (wchar_t *__pwcs, const char *__s, size_t __n);
  1176. extern size_t wcstombs (char *__s, const wchar_t *__pwcs, size_t __n);
  1177. extern void srand(unsigned int __seed);
  1178. extern int rand(void);
  1179. extern uint8_t *getenv(char_t *name, uintn_t *len);
  1180. extern int setenv(char_t *name, uintn_t len, uint8_t *data);
  1181. /* stdio.h */
  1182. #ifndef BUFSIZ
  1183. #define BUFSIZ 8192
  1184. #endif
  1185. #define SEEK_SET 0 /* Seek from beginning of file. */
  1186. #define SEEK_CUR 1 /* Seek from current position. */
  1187. #define SEEK_END 2 /* Seek from end of file. */
  1188. #define stdin (FILE*)ST->ConsoleInHandle
  1189. #define stdout (FILE*)ST->ConsoleOutHandle
  1190. #define stderr (FILE*)ST->ConsoleErrorHandle
  1191. typedef struct efi_file_handle_s FILE;
  1192. extern int fclose (FILE *__stream);
  1193. extern int fflush (FILE *__stream);
  1194. extern int remove (const char_t *__filename);
  1195. extern FILE *fopen (const char_t *__filename, const char_t *__modes);
  1196. extern size_t fread (void *__ptr, size_t __size, size_t __n, FILE *__stream);
  1197. extern size_t fwrite (const void *__ptr, size_t __size, size_t __n, FILE *__s);
  1198. extern int fseek (FILE *__stream, long int __off, int __whence);
  1199. extern long int ftell (FILE *__stream);
  1200. extern int feof (FILE *__stream);
  1201. extern int fprintf (FILE *__stream, const char_t *__format, ...);
  1202. extern int printf (const char_t *__format, ...);
  1203. extern int sprintf (char_t *__s, const char_t *__format, ...);
  1204. extern int vfprintf (FILE *__s, const char_t *__format, __builtin_va_list __arg);
  1205. extern int vprintf (const char_t *__format, __builtin_va_list __arg);
  1206. extern int vsprintf (char_t *__s, const char_t *__format, __builtin_va_list __arg);
  1207. extern int snprintf (char_t *__s, size_t __maxlen, const char_t *__format, ...);
  1208. extern int vsnprintf (char_t *__s, size_t __maxlen, const char_t *__format, __builtin_va_list __arg);
  1209. extern int getchar (void);
  1210. /* non-blocking, only returns UNICODE if there's any key pressed, 0 otherwise */
  1211. extern int getchar_ifany (void);
  1212. extern int putchar (int __c);
  1213. /* string.h */
  1214. extern void *memcpy(void *__dest, const void *__src, size_t __n);
  1215. extern void *memmove(void *__dest, const void *__src, size_t __n);
  1216. extern void *memset(void *__s, int __c, size_t __n);
  1217. extern int memcmp(const void *__s1, const void *__s2, size_t __n);
  1218. extern void *memchr(const void *__s, int __c, size_t __n);
  1219. extern void *memrchr(const void *__s, int __c, size_t __n);
  1220. void *memmem(const void *haystack, size_t hl, const void *needle, size_t nl);
  1221. void *memrmem(const void *haystack, size_t hl, const void *needle, size_t nl);
  1222. extern char_t *strcpy (char_t *__dest, const char_t *__src);
  1223. extern char_t *strncpy (char_t *__dest, const char_t *__src, size_t __n);
  1224. extern char_t *strcat (char_t *__dest, const char_t *__src);
  1225. extern char_t *strncat (char_t *__dest, const char_t *__src, size_t __n);
  1226. extern int strcmp (const char_t *__s1, const char_t *__s2);
  1227. extern int strncmp (const char_t *__s1, const char_t *__s2, size_t __n);
  1228. extern char_t *strdup (const char_t *__s);
  1229. extern char_t *strchr (const char_t *__s, int __c);
  1230. extern char_t *strrchr (const char_t *__s, int __c);
  1231. extern char_t *strstr (const char_t *__haystack, const char_t *__needle);
  1232. extern char_t *strtok (char_t *__s, const char_t *__delim);
  1233. extern char_t *strtok_r (char_t *__s, const char_t *__delim, char_t **__save_ptr);
  1234. extern size_t strlen (const char_t *__s);
  1235. /* sys/stat.h */
  1236. #define S_IREAD 0400 /* Read by owner. */
  1237. #define S_IWRITE 0200 /* Write by owner. */
  1238. #define S_IFMT 0170000 /* These bits determine file type. */
  1239. #define S_IFIFO 0010000 /* FIFO. */
  1240. #define S_IFCHR 0020000 /* Character device. */
  1241. #define S_IFDIR 0040000 /* Directory. */
  1242. #define S_IFBLK 0060000 /* Block device. */
  1243. #define S_IFREG 0100000 /* Regular file. */
  1244. #define S_ISTYPE(mode, mask) (((mode) & S_IFMT) == (mask))
  1245. #define S_ISCHR(mode) S_ISTYPE((mode), S_IFCHR)
  1246. #define S_ISDIR(mode) S_ISTYPE((mode), S_IFDIR)
  1247. #define S_ISBLK(mode) S_ISTYPE((mode), S_IFBLK)
  1248. #define S_ISREG(mode) S_ISTYPE((mode), S_IFREG)
  1249. #define S_ISFIFO(mode) S_ISTYPE((mode), S_IFIFO)
  1250. struct stat {
  1251. mode_t st_mode;
  1252. off_t st_size;
  1253. blkcnt_t st_blocks;
  1254. time_t st_atime;
  1255. time_t st_mtime;
  1256. time_t st_ctime;
  1257. };
  1258. extern int stat (const char_t *__file, struct stat *__buf);
  1259. extern int fstat (FILE *__f, struct stat *__buf);
  1260. extern int mkdir (const char_t *__path, mode_t __mode);
  1261. /* time.h */
  1262. struct tm {
  1263. int tm_sec; /* Seconds. [0-60] (1 leap second) */
  1264. int tm_min; /* Minutes. [0-59] */
  1265. int tm_hour; /* Hours. [0-23] */
  1266. int tm_mday; /* Day. [1-31] */
  1267. int tm_mon; /* Month. [0-11] */
  1268. int tm_year; /* Year - 1900. */
  1269. int tm_wday; /* Day of week. [0-6] (not set) */
  1270. int tm_yday; /* Days in year.[0-365] (not set) */
  1271. int tm_isdst; /* DST. [-1/0/1]*/
  1272. };
  1273. extern struct tm *localtime (const time_t *__timer);
  1274. extern time_t mktime(const struct tm *__tm);
  1275. extern time_t time(time_t *__timer);
  1276. /* unistd.h */
  1277. extern unsigned int sleep (unsigned int __seconds);
  1278. extern int usleep (unsigned long int __useconds);
  1279. extern int unlink (const wchar_t *__filename);
  1280. extern int rmdir (const wchar_t *__filename);
  1281. #ifdef __cplusplus
  1282. }
  1283. #endif
  1284. #endif /* _UEFI_H_ */