peimage.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998
  1. /*++
  2. Copyright (c) 2014 Minoca Corp. All Rights Reserved
  3. Module Name:
  4. peimage.h
  5. Abstract:
  6. This header contains definitions for PE32+ UEFI images.
  7. Author:
  8. Evan Green 6-Mar-2014
  9. --*/
  10. //
  11. // ------------------------------------------------------------------- Includes
  12. //
  13. //
  14. // ---------------------------------------------------------------- Definitions
  15. //
  16. //
  17. // PE32+ Subsystem types for EFI images
  18. //
  19. #define EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION 10
  20. #define EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER 11
  21. #define EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER 12
  22. #define EFI_IMAGE_SUBSYSTEM_SAL_RUNTIME_DRIVER 13
  23. //
  24. // PE32+ Machine type for EFI images
  25. //
  26. #define IMAGE_FILE_MACHINE_I386 0x014C
  27. #define IMAGE_FILE_MACHINE_IA64 0x0200
  28. #define IMAGE_FILE_MACHINE_EBC 0x0EBC
  29. #define IMAGE_FILE_MACHINE_X64 0x8664
  30. //
  31. // Thumb only image.
  32. //
  33. #define IMAGE_FILE_MACHINE_ARM 0x01C0
  34. //
  35. // Mixed ARM and Thumb/Thumb2 (little endian).
  36. //
  37. #define IMAGE_FILE_MACHINE_ARMT 0x01C2
  38. //
  39. // 64-bit ARM, little endian.
  40. //
  41. #define IMAGE_FILE_MACHINE_ARM64 0xAA64
  42. #define EFI_IMAGE_DOS_SIGNATURE 0x5A4D
  43. #define EFI_IMAGE_OS2_SIGNATURE 0x454E
  44. #define EFI_IMAGE_OS2_SIGNATURE_LE 0x454C
  45. #define EFI_IMAGE_NT_SIGNATURE 0x00004550
  46. #define EFI_IMAGE_EDOS_SIGNATURE 0x44454550
  47. #define EFI_IMAGE_SIZEOF_FILE_HEADER 20
  48. //
  49. // Set this if relocation information is stripped from the file.
  50. //
  51. #define EFI_IMAGE_FILE_RELOCS_STRIPPED 0x0001
  52. //
  53. // Set this if the file is executable.
  54. //
  55. #define EFI_IMAGE_FILE_EXECUTABLE_IMAGE 0x0002
  56. //
  57. // Set this if line numbers have been stripped from the file.
  58. //
  59. #define EFI_IMAGE_FILE_LINE_NUMS_STRIPPED 0x0004
  60. //
  61. // Set this if local symbols have been stripped from the file.
  62. //
  63. #define EFI_IMAGE_FILE_LOCAL_SYMS_STRIPPED 0x0008
  64. //
  65. // Set this if the image supports address > 2GB.
  66. //
  67. #define EFI_IMAGE_FILE_LARGE_ADDRESS_AWARE 0x0020
  68. //
  69. // Set this if the bytes of the machine word are reversed.
  70. //
  71. #define EFI_IMAGE_FILE_BYTES_REVERSED_LO 0x0080
  72. //
  73. // Set this if the machine is 32-bit.
  74. //
  75. #define EFI_IMAGE_FILE_32BIT_MACHINE 0x0100
  76. //
  77. // Set this if debuging information is stripped from the file.
  78. //
  79. #define EFI_IMAGE_FILE_DEBUG_STRIPPED 0x0200
  80. //
  81. // Set this if this is a system file.
  82. //
  83. #define EFI_IMAGE_FILE_SYSTEM 0x1000
  84. //
  85. // Set this if the file is a DLL.
  86. //
  87. #define EFI_IMAGE_FILE_DLL 0x2000
  88. //
  89. // Set this if the high bytes of the machine word are reversed.
  90. //
  91. #define EFI_IMAGE_FILE_BYTES_REVERSED_HI 0x8000
  92. //
  93. // Define machine types.
  94. //
  95. #define EFI_IMAGE_FILE_MACHINE_UNKNOWN 0
  96. //
  97. // Intel 386
  98. //
  99. #define EFI_IMAGE_FILE_MACHINE_I386 0x14C
  100. //
  101. // MIPS little endian, 0540 big endian
  102. //
  103. #define EFI_IMAGE_FILE_MACHINE_R3000 0x162
  104. //
  105. // MIPS little endian
  106. //
  107. #define EFI_IMAGE_FILE_MACHINE_R4000 0x166
  108. //
  109. // Alpha AXP
  110. //
  111. #define EFI_IMAGE_FILE_MACHINE_ALPHA 0x184
  112. //
  113. // IBM PowerPC little endian
  114. //
  115. #define EFI_IMAGE_FILE_MACHINE_POWERPC 0x1F0
  116. //
  117. // Intel EM machine
  118. //
  119. #define EFI_IMAGE_FILE_MACHINE_TAHOE 0x7CC
  120. #define EFI_IMAGE_NUMBER_OF_DIRECTORY_ENTRIES 16
  121. #define EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC 0x10B
  122. #define EFI_IMAGE_ROM_OPTIONAL_HDR_MAGIC 0x107
  123. #define EFI_IMAGE_SIZEOF_ROM_OPTIONAL_HEADER \
  124. sizeof(EFI_IMAGE_ROM_OPTIONAL_HEADER)
  125. #define EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC 0x20b
  126. #define EFI_IMAGE_SIZEOF_NT_OPTIONAL32_HEADER sizeof(EFI_IMAGE_NT_HEADERS32)
  127. #define EFI_IMAGE_SIZEOF_NT_OPTIONAL64_HEADER sizeof(EFI_IMAGE_NT_HEADERS64)
  128. //
  129. // Subsystem Values
  130. //
  131. #define EFI_IMAGE_SUBSYSTEM_UNKNOWN 0
  132. #define EFI_IMAGE_SUBSYSTEM_NATIVE 1
  133. #define EFI_IMAGE_SUBSYSTEM_WINDOWS_GUI 2
  134. #define EFI_IMAGE_SUBSYSTEM_WINDOWS_CUI 3
  135. #define EFI_IMAGE_SUBSYSTEM_OS2_CUI 5
  136. #define EFI_IMAGE_SUBSYSTEM_POSIX_CUI 7
  137. //
  138. // Directory Entries
  139. //
  140. #define EFI_IMAGE_DIRECTORY_ENTRY_EXPORT 0
  141. #define EFI_IMAGE_DIRECTORY_ENTRY_IMPORT 1
  142. #define EFI_IMAGE_DIRECTORY_ENTRY_RESOURCE 2
  143. #define EFI_IMAGE_DIRECTORY_ENTRY_EXCEPTION 3
  144. #define EFI_IMAGE_DIRECTORY_ENTRY_SECURITY 4
  145. #define EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC 5
  146. #define EFI_IMAGE_DIRECTORY_ENTRY_DEBUG 6
  147. #define EFI_IMAGE_DIRECTORY_ENTRY_COPYRIGHT 7
  148. #define EFI_IMAGE_DIRECTORY_ENTRY_GLOBALPTR 8
  149. #define EFI_IMAGE_DIRECTORY_ENTRY_TLS 9
  150. #define EFI_IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG 10
  151. //
  152. // Section header format.
  153. //
  154. #define EFI_IMAGE_SIZEOF_SHORT_NAME 8
  155. #define EFI_IMAGE_SIZEOF_SECTION_HEADER 40
  156. #define EFI_IMAGE_SCN_TYPE_NO_PAD 0x00000008
  157. #define EFI_IMAGE_SCN_CNT_CODE 0x00000020
  158. #define EFI_IMAGE_SCN_CNT_INITIALIZED_DATA 0x00000040
  159. #define EFI_IMAGE_SCN_CNT_UNINITIALIZED_DATA 0x00000080
  160. #define EFI_IMAGE_SCN_LNK_OTHER 0x00000100
  161. //
  162. // Set if the section contains comments or some other type of information.
  163. //
  164. #define EFI_IMAGE_SCN_LNK_INFO 0x00000200
  165. //
  166. // Set if the section contents will not become part of the image.
  167. //
  168. #define EFI_IMAGE_SCN_LNK_REMOVE 0x00000800
  169. #define EFI_IMAGE_SCN_LNK_COMDAT 0x00001000
  170. #define EFI_IMAGE_SCN_ALIGN_1BYTES 0x00100000
  171. #define EFI_IMAGE_SCN_ALIGN_2BYTES 0x00200000
  172. #define EFI_IMAGE_SCN_ALIGN_4BYTES 0x00300000
  173. #define EFI_IMAGE_SCN_ALIGN_8BYTES 0x00400000
  174. #define EFI_IMAGE_SCN_ALIGN_16BYTES 0x00500000
  175. #define EFI_IMAGE_SCN_ALIGN_32BYTES 0x00600000
  176. #define EFI_IMAGE_SCN_ALIGN_64BYTES 0x00700000
  177. #define EFI_IMAGE_SCN_MEM_DISCARDABLE 0x02000000
  178. #define EFI_IMAGE_SCN_MEM_NOT_CACHED 0x04000000
  179. #define EFI_IMAGE_SCN_MEM_NOT_PAGED 0x08000000
  180. #define EFI_IMAGE_SCN_MEM_SHARED 0x10000000
  181. #define EFI_IMAGE_SCN_MEM_EXECUTE 0x20000000
  182. #define EFI_IMAGE_SCN_MEM_READ 0x40000000
  183. #define EFI_IMAGE_SCN_MEM_WRITE 0x80000000
  184. //
  185. // Symbol format.
  186. //
  187. #define EFI_IMAGE_SIZEOF_SYMBOL 18
  188. //
  189. // Section values.
  190. //
  191. // Symbols have a section number of the section in which they are
  192. // defined. Otherwise, section numbers have the following meanings:
  193. //
  194. //
  195. // The symbol is undefined or is common.
  196. //
  197. #define EFI_IMAGE_SYM_UNDEFINED (UINT16)0
  198. //
  199. // The symbol is an absolute value.
  200. //
  201. #define EFI_IMAGE_SYM_ABSOLUTE (UINT16)-1
  202. //
  203. // The symbol is a special debug item.
  204. //
  205. #define EFI_IMAGE_SYM_DEBUG (UINT16)-2
  206. //
  207. // Type (fundamental) values.
  208. //
  209. #define EFI_IMAGE_SYM_TYPE_NULL 0
  210. #define EFI_IMAGE_SYM_TYPE_VOID 1
  211. #define EFI_IMAGE_SYM_TYPE_CHAR 2
  212. #define EFI_IMAGE_SYM_TYPE_SHORT 3
  213. #define EFI_IMAGE_SYM_TYPE_INT 4
  214. #define EFI_IMAGE_SYM_TYPE_LONG 5
  215. #define EFI_IMAGE_SYM_TYPE_FLOAT 6
  216. #define EFI_IMAGE_SYM_TYPE_DOUBLE 7
  217. #define EFI_IMAGE_SYM_TYPE_STRUCT 8
  218. #define EFI_IMAGE_SYM_TYPE_UNION 9
  219. #define EFI_IMAGE_SYM_TYPE_ENUM 10
  220. #define EFI_IMAGE_SYM_TYPE_MOE 11
  221. #define EFI_IMAGE_SYM_TYPE_BYTE 12
  222. #define EFI_IMAGE_SYM_TYPE_WORD 13
  223. #define EFI_IMAGE_SYM_TYPE_UINT 14
  224. #define EFI_IMAGE_SYM_TYPE_DWORD 15
  225. //
  226. // Type (derived) values.
  227. //
  228. #define EFI_IMAGE_SYM_DTYPE_NULL 0
  229. #define EFI_IMAGE_SYM_DTYPE_POINTER 1
  230. #define EFI_IMAGE_SYM_DTYPE_FUNCTION 2
  231. #define EFI_IMAGE_SYM_DTYPE_ARRAY 3
  232. //
  233. // Storage classes.
  234. //
  235. #define EFI_IMAGE_SYM_CLASS_END_OF_FUNCTION (UINT8)-1
  236. #define EFI_IMAGE_SYM_CLASS_NULL 0
  237. #define EFI_IMAGE_SYM_CLASS_AUTOMATIC 1
  238. #define EFI_IMAGE_SYM_CLASS_EXTERNAL 2
  239. #define EFI_IMAGE_SYM_CLASS_STATIC 3
  240. #define EFI_IMAGE_SYM_CLASS_REGISTER 4
  241. #define EFI_IMAGE_SYM_CLASS_EXTERNAL_DEF 5
  242. #define EFI_IMAGE_SYM_CLASS_LABEL 6
  243. #define EFI_IMAGE_SYM_CLASS_UNDEFINED_LABEL 7
  244. #define EFI_IMAGE_SYM_CLASS_MEMBER_OF_STRUCT 8
  245. #define EFI_IMAGE_SYM_CLASS_ARGUMENT 9
  246. #define EFI_IMAGE_SYM_CLASS_STRUCT_TAG 10
  247. #define EFI_IMAGE_SYM_CLASS_MEMBER_OF_UNION 11
  248. #define EFI_IMAGE_SYM_CLASS_UNION_TAG 12
  249. #define EFI_IMAGE_SYM_CLASS_TYPE_DEFINITION 13
  250. #define EFI_IMAGE_SYM_CLASS_UNDEFINED_STATIC 14
  251. #define EFI_IMAGE_SYM_CLASS_ENUM_TAG 15
  252. #define EFI_IMAGE_SYM_CLASS_MEMBER_OF_ENUM 16
  253. #define EFI_IMAGE_SYM_CLASS_REGISTER_PARAM 17
  254. #define EFI_IMAGE_SYM_CLASS_BIT_FIELD 18
  255. #define EFI_IMAGE_SYM_CLASS_BLOCK 100
  256. #define EFI_IMAGE_SYM_CLASS_FUNCTION 101
  257. #define EFI_IMAGE_SYM_CLASS_END_OF_STRUCT 102
  258. #define EFI_IMAGE_SYM_CLASS_FILE 103
  259. #define EFI_IMAGE_SYM_CLASS_SECTION 104
  260. #define EFI_IMAGE_SYM_CLASS_WEAK_EXTERNAL 105
  261. //
  262. // type packing constants
  263. //
  264. #define EFI_IMAGE_N_BTMASK 017
  265. #define EFI_IMAGE_N_TMASK 060
  266. #define EFI_IMAGE_N_TMASK1 0300
  267. #define EFI_IMAGE_N_TMASK2 0360
  268. #define EFI_IMAGE_N_BTSHFT 4
  269. #define EFI_IMAGE_N_TSHIFT 2
  270. //
  271. // Communal selection types.
  272. //
  273. #define EFI_IMAGE_COMDAT_SELECT_NODUPLICATES 1
  274. #define EFI_IMAGE_COMDAT_SELECT_ANY 2
  275. #define EFI_IMAGE_COMDAT_SELECT_SAME_SIZE 3
  276. #define EFI_IMAGE_COMDAT_SELECT_EXACT_MATCH 4
  277. #define EFI_IMAGE_COMDAT_SELECT_ASSOCIATIVE 5
  278. #define EFI_IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY 1
  279. #define EFI_IMAGE_WEAK_EXTERN_SEARCH_LIBRARY 2
  280. #define EFI_IMAGE_WEAK_EXTERN_SEARCH_ALIAS 3
  281. //
  282. // Relocation format definitions
  283. //
  284. #define EFI_IMAGE_SIZEOF_RELOCATION 10
  285. //
  286. // I386 relocation types.
  287. //
  288. //
  289. // The reference is absolute, no relocation is necessary.
  290. //
  291. #define EFI_IMAGE_REL_I386_ABSOLUTE 0
  292. //
  293. // This is a direct 16-bit reference to the symbol's virtual address.
  294. //
  295. #define EFI_IMAGE_REL_I386_DIR16 01
  296. //
  297. // This is a PC-relative 16-bit reference to the symbol's virtual address.
  298. //
  299. #define EFI_IMAGE_REL_I386_REL16 02
  300. //
  301. // This is a direct 32-bit reference to the symbol's virtual address.
  302. //
  303. #define EFI_IMAGE_REL_I386_DIR32 06
  304. //
  305. // This is a direct 32-bit reference to the symbol's virtual address, not
  306. // including the base.
  307. //
  308. #define EFI_IMAGE_REL_I386_DIR32NB 07
  309. //
  310. // This is a direct 16-bit reference to the segment selector bits of a 32-bit
  311. // virtual address.
  312. //
  313. #define EFI_IMAGE_REL_I386_SEG12 09
  314. #define EFI_IMAGE_REL_I386_SECTION 010
  315. #define EFI_IMAGE_REL_I386_SECREL 011
  316. //
  317. // This is a PC-relative 32-bit reference to the symbol's virtual address.
  318. //
  319. #define EFI_IMAGE_REL_I386_REL32 020
  320. //
  321. // x64 processor relocation types.
  322. //
  323. #define IMAGE_REL_AMD64_ABSOLUTE 0x0000
  324. #define IMAGE_REL_AMD64_ADDR64 0x0001
  325. #define IMAGE_REL_AMD64_ADDR32 0x0002
  326. #define IMAGE_REL_AMD64_ADDR32NB 0x0003
  327. #define IMAGE_REL_AMD64_REL32 0x0004
  328. #define IMAGE_REL_AMD64_REL32_1 0x0005
  329. #define IMAGE_REL_AMD64_REL32_2 0x0006
  330. #define IMAGE_REL_AMD64_REL32_3 0x0007
  331. #define IMAGE_REL_AMD64_REL32_4 0x0008
  332. #define IMAGE_REL_AMD64_REL32_5 0x0009
  333. #define IMAGE_REL_AMD64_SECTION 0x000A
  334. #define IMAGE_REL_AMD64_SECREL 0x000B
  335. #define IMAGE_REL_AMD64_SECREL7 0x000C
  336. #define IMAGE_REL_AMD64_TOKEN 0x000D
  337. #define IMAGE_REL_AMD64_SREL32 0x000E
  338. #define IMAGE_REL_AMD64_PAIR 0x000F
  339. #define IMAGE_REL_AMD64_SSPAN32 0x0010
  340. //
  341. // Based relocation types
  342. //
  343. #define EFI_IMAGE_SIZEOF_BASE_RELOCATION 8
  344. //
  345. // Based relocation types.
  346. //
  347. #define EFI_IMAGE_REL_BASED_ABSOLUTE 0
  348. #define EFI_IMAGE_REL_BASED_HIGH 1
  349. #define EFI_IMAGE_REL_BASED_LOW 2
  350. #define EFI_IMAGE_REL_BASED_HIGHLOW 3
  351. #define EFI_IMAGE_REL_BASED_HIGHADJ 4
  352. #define EFI_IMAGE_REL_BASED_MIPS_JMPADDR 5
  353. #define EFI_IMAGE_REL_BASED_ARM_MOV32A 5
  354. #define EFI_IMAGE_REL_BASED_ARM_MOV32T 7
  355. #define EFI_IMAGE_REL_BASED_IA64_IMM64 9
  356. #define EFI_IMAGE_REL_BASED_DIR64 10
  357. #define EFI_IMAGE_SIZEOF_LINENUMBER 6
  358. //
  359. // Archive format definitions
  360. //
  361. #define EFI_IMAGE_ARCHIVE_START_SIZE 8
  362. #define EFI_IMAGE_ARCHIVE_START "!<arch>\n"
  363. #define EFI_IMAGE_ARCHIVE_END "`\n"
  364. #define EFI_IMAGE_ARCHIVE_PAD "\n"
  365. #define EFI_IMAGE_ARCHIVE_LINKER_MEMBER "/ "
  366. #define EFI_IMAGE_ARCHIVE_LONGNAMES_MEMBER "// "
  367. #define EFI_IMAGE_SIZEOF_ARCHIVE_MEMBER_HDR 60
  368. #define EFI_IMAGE_ORDINAL_FLAG 0x80000000
  369. #define EFI_IMAGE_SNAP_BY_ORDINAL(Ordinal) \
  370. ((Ordinal & EFI_IMAGE_ORDINAL_FLAG) != 0)
  371. #define EFI_IMAGE_ORDINAL(Ordinal) (Ordinal & 0xFFFF)
  372. #define EFI_IMAGE_DEBUG_TYPE_CODEVIEW 2
  373. #define CODEVIEW_SIGNATURE_NB10 0x3031424E // 'NB10'
  374. #define CODEVIEW_SIGNATURE_RSDS 0x53445352 // 'RSDS'
  375. #define CODEVIEW_SIGNATURE_MTOC 0x434F544D // 'MTOC'
  376. #define EFI_TE_IMAGE_HEADER_SIGNATURE 0x5A56 // "VZ"
  377. //
  378. // Data directory indexes in our TE image header
  379. //
  380. #define EFI_TE_IMAGE_DIRECTORY_ENTRY_BASERELOC 0
  381. #define EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG 1
  382. //
  383. // ------------------------------------------------------ Data Type Definitions
  384. //
  385. /*++
  386. Structure Description:
  387. This structure stores information about a DOS header. PE images can start
  388. with an optional DOS header so that if an image is run under DOS it can
  389. print an error message.
  390. Members:
  391. e_magic - Stores the magic number.
  392. e_cblp - Stores the byte count on the last page of the file.
  393. e_cp - Stores the number of pages in the file.
  394. e_crlc - Stores the location of the relocations.
  395. e_cparhdr - Stores the size of the header in paragraphs.
  396. e_minalloc - Stores the minimum number of extra paragraphs needed.
  397. e_maxalloc - Stores the maximum number of extra paragraphs needed.
  398. e_ss - Stores the initial (relative) SS value.
  399. e_sp - Stores the initial SP value.
  400. e_csum - Stores the checksum.
  401. e_ip - Stores the initial IP value.
  402. e_cs - Stores the initial (relative) CS value.
  403. e_lfarlc - Stores the file address of the relocation table.
  404. e_ovno - Stores the overlay number.
  405. e_res - Stores reserved words.
  406. e_oemid - Stores the OEM identifier.
  407. e_oeminfo - Stores the OEM-specific information.
  408. e_res - Stores additional reserved words.
  409. e_lfanew - Stores the file address of the new EXE header.
  410. --*/
  411. typedef struct {
  412. UINT16 e_magic;
  413. UINT16 e_cblp;
  414. UINT16 e_cp;
  415. UINT16 e_crlc;
  416. UINT16 e_cparhdr;
  417. UINT16 e_minalloc;
  418. UINT16 e_maxalloc;
  419. UINT16 e_ss;
  420. UINT16 e_sp;
  421. UINT16 e_csum;
  422. UINT16 e_ip;
  423. UINT16 e_cs;
  424. UINT16 e_lfarlc;
  425. UINT16 e_ovno;
  426. UINT16 e_res[4];
  427. UINT16 e_oemid;
  428. UINT16 e_oeminfo;
  429. UINT16 e_res2[10];
  430. UINT32 e_lfanew;
  431. } EFI_IMAGE_DOS_HEADER;
  432. typedef struct {
  433. UINT16 Machine;
  434. UINT16 NumberOfSections;
  435. UINT32 TimeDateStamp;
  436. UINT32 PointerToSymbolTable;
  437. UINT32 NumberOfSymbols;
  438. UINT16 SizeOfOptionalHeader;
  439. UINT16 Characteristics;
  440. } EFI_IMAGE_FILE_HEADER;
  441. typedef struct {
  442. UINT32 VirtualAddress;
  443. UINT32 Size;
  444. } EFI_IMAGE_DATA_DIRECTORY;
  445. typedef struct {
  446. UINT16 Magic;
  447. UINT8 MajorLinkerVersion;
  448. UINT8 MinorLinkerVersion;
  449. UINT32 SizeOfCode;
  450. UINT32 SizeOfInitializedData;
  451. UINT32 SizeOfUninitializedData;
  452. UINT32 AddressOfEntryPoint;
  453. UINT32 BaseOfCode;
  454. UINT32 BaseOfData;
  455. UINT32 BaseOfBss;
  456. UINT32 GprMask;
  457. UINT32 CprMask[4];
  458. UINT32 GpValue;
  459. } EFI_IMAGE_ROM_OPTIONAL_HEADER;
  460. typedef struct {
  461. EFI_IMAGE_FILE_HEADER FileHeader;
  462. EFI_IMAGE_ROM_OPTIONAL_HEADER OptionalHeader;
  463. } EFI_IMAGE_ROM_HEADERS;
  464. //
  465. // These structure are for use ONLY by tools. All proper EFI code MUST use the
  466. // EFI_IMAGE_OPTIONAL_HEADER only.
  467. //
  468. typedef struct {
  469. UINT16 Magic;
  470. UINT8 MajorLinkerVersion;
  471. UINT8 MinorLinkerVersion;
  472. UINT32 SizeOfCode;
  473. UINT32 SizeOfInitializedData;
  474. UINT32 SizeOfUninitializedData;
  475. UINT32 AddressOfEntryPoint;
  476. UINT32 BaseOfCode;
  477. UINT32 BaseOfData;
  478. UINT32 ImageBase;
  479. UINT32 SectionAlignment;
  480. UINT32 FileAlignment;
  481. UINT16 MajorOperatingSystemVersion;
  482. UINT16 MinorOperatingSystemVersion;
  483. UINT16 MajorImageVersion;
  484. UINT16 MinorImageVersion;
  485. UINT16 MajorSubsystemVersion;
  486. UINT16 MinorSubsystemVersion;
  487. UINT32 Win32VersionValue;
  488. UINT32 SizeOfImage;
  489. UINT32 SizeOfHeaders;
  490. UINT32 CheckSum;
  491. UINT16 Subsystem;
  492. UINT16 DllCharacteristics;
  493. UINT32 SizeOfStackReserve;
  494. UINT32 SizeOfStackCommit;
  495. UINT32 SizeOfHeapReserve;
  496. UINT32 SizeOfHeapCommit;
  497. UINT32 LoaderFlags;
  498. UINT32 NumberOfRvaAndSizes;
  499. EFI_IMAGE_DATA_DIRECTORY
  500. DataDirectory[EFI_IMAGE_NUMBER_OF_DIRECTORY_ENTRIES];
  501. } EFI_IMAGE_OPTIONAL_HEADER32;
  502. typedef struct {
  503. UINT16 Magic;
  504. UINT8 MajorLinkerVersion;
  505. UINT8 MinorLinkerVersion;
  506. UINT32 SizeOfCode;
  507. UINT32 SizeOfInitializedData;
  508. UINT32 SizeOfUninitializedData;
  509. UINT32 AddressOfEntryPoint;
  510. UINT32 BaseOfCode;
  511. UINT64 ImageBase;
  512. UINT32 SectionAlignment;
  513. UINT32 FileAlignment;
  514. UINT16 MajorOperatingSystemVersion;
  515. UINT16 MinorOperatingSystemVersion;
  516. UINT16 MajorImageVersion;
  517. UINT16 MinorImageVersion;
  518. UINT16 MajorSubsystemVersion;
  519. UINT16 MinorSubsystemVersion;
  520. UINT32 Win32VersionValue;
  521. UINT32 SizeOfImage;
  522. UINT32 SizeOfHeaders;
  523. UINT32 CheckSum;
  524. UINT16 Subsystem;
  525. UINT16 DllCharacteristics;
  526. UINT64 SizeOfStackReserve;
  527. UINT64 SizeOfStackCommit;
  528. UINT64 SizeOfHeapReserve;
  529. UINT64 SizeOfHeapCommit;
  530. UINT32 LoaderFlags;
  531. UINT32 NumberOfRvaAndSizes;
  532. EFI_IMAGE_DATA_DIRECTORY
  533. DataDirectory[EFI_IMAGE_NUMBER_OF_DIRECTORY_ENTRIES];
  534. } EFI_IMAGE_OPTIONAL_HEADER64;
  535. typedef struct {
  536. UINT32 Signature;
  537. EFI_IMAGE_FILE_HEADER FileHeader;
  538. EFI_IMAGE_OPTIONAL_HEADER32 OptionalHeader;
  539. } EFI_IMAGE_NT_HEADERS32;
  540. typedef struct {
  541. UINT32 Signature;
  542. EFI_IMAGE_FILE_HEADER FileHeader;
  543. EFI_IMAGE_OPTIONAL_HEADER64 OptionalHeader;
  544. } EFI_IMAGE_NT_HEADERS64;
  545. typedef struct {
  546. UINT8 Name[EFI_IMAGE_SIZEOF_SHORT_NAME];
  547. union {
  548. UINT32 PhysicalAddress;
  549. UINT32 VirtualSize;
  550. } Misc;
  551. UINT32 VirtualAddress;
  552. UINT32 SizeOfRawData;
  553. UINT32 PointerToRawData;
  554. UINT32 PointerToRelocations;
  555. UINT32 PointerToLinenumbers;
  556. UINT16 NumberOfRelocations;
  557. UINT16 NumberOfLinenumbers;
  558. UINT32 Characteristics;
  559. } EFI_IMAGE_SECTION_HEADER;
  560. typedef struct {
  561. UINT32 VirtualAddress;
  562. UINT32 SymbolTableIndex;
  563. UINT16 Type;
  564. } EFI_IMAGE_RELOCATION;
  565. typedef struct {
  566. UINT32 VirtualAddress;
  567. UINT32 SizeOfBlock;
  568. } EFI_IMAGE_BASE_RELOCATION;
  569. typedef struct {
  570. union {
  571. UINT32 SymbolTableIndex;
  572. UINT32 VirtualAddress;
  573. } Type;
  574. UINT16 Linenumber;
  575. } EFI_IMAGE_LINENUMBER;
  576. /*++
  577. Structure Description:
  578. This structure defines a PE archive header member.
  579. Members:
  580. Name - Stores the file member name, / terminated.
  581. Date - Stores the file member date in decimal format.
  582. UserID - Stores the file member user ID in decimal format.
  583. GroupID - Stores the file member group ID in decimal format.
  584. Mode - Stores the file member mode in octal format.
  585. Size - Stores the file member size in decimal format.
  586. EndHeader - Stores the string to end the header.
  587. --*/
  588. typedef struct {
  589. UINT8 Name[16];
  590. UINT8 Date[12];
  591. UINT8 UserID[6];
  592. UINT8 GroupID[6];
  593. UINT8 Mode[8];
  594. UINT8 Size[10];
  595. UINT8 EndHeader[2];
  596. } EFI_IMAGE_ARCHIVE_MEMBER_HEADER;
  597. //
  598. // DLL Support
  599. //
  600. typedef struct {
  601. UINT32 Characteristics;
  602. UINT32 TimeDateStamp;
  603. UINT16 MajorVersion;
  604. UINT16 MinorVersion;
  605. UINT32 Name;
  606. UINT32 Base;
  607. UINT32 NumberOfFunctions;
  608. UINT32 NumberOfNames;
  609. UINT32 AddressOfFunctions;
  610. UINT32 AddressOfNames;
  611. UINT32 AddressOfNameOrdinals;
  612. } EFI_IMAGE_EXPORT_DIRECTORY;
  613. typedef struct {
  614. UINT16 Hint;
  615. UINT8 Name[1];
  616. } EFI_IMAGE_IMPORT_BY_NAME;
  617. typedef struct {
  618. union {
  619. UINT32 Function;
  620. UINT32 Ordinal;
  621. EFI_IMAGE_IMPORT_BY_NAME *AddressOfData;
  622. } u1;
  623. } EFI_IMAGE_THUNK_DATA;
  624. typedef struct {
  625. UINT32 Characteristics;
  626. UINT32 TimeDateStamp;
  627. UINT32 ForwarderChain;
  628. UINT32 Name;
  629. EFI_IMAGE_THUNK_DATA *FirstThunk;
  630. } EFI_IMAGE_IMPORT_DESCRIPTOR;
  631. typedef struct {
  632. UINT32 Characteristics;
  633. UINT32 TimeDateStamp;
  634. UINT16 MajorVersion;
  635. UINT16 MinorVersion;
  636. UINT32 Type;
  637. UINT32 SizeOfData;
  638. UINT32 RVA;
  639. UINT32 FileOffset;
  640. } EFI_IMAGE_DEBUG_DIRECTORY_ENTRY;
  641. typedef struct {
  642. UINT32 Signature;
  643. UINT32 Unknown;
  644. UINT32 Unknown2;
  645. UINT32 Unknown3;
  646. } EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY;
  647. typedef struct {
  648. UINT32 Signature;
  649. UINT32 Unknown;
  650. UINT32 Unknown2;
  651. UINT32 Unknown3;
  652. UINT32 Unknown4;
  653. UINT32 Unknown5;
  654. } EFI_IMAGE_DEBUG_CODEVIEW_RSDS_ENTRY;
  655. typedef struct {
  656. UINT32 Signature;
  657. EFI_GUID MachOUuid;
  658. } EFI_IMAGE_DEBUG_CODEVIEW_MTOC_ENTRY;
  659. //
  660. // .pdata entries for X64
  661. //
  662. typedef struct {
  663. UINT32 FunctionStartAddress;
  664. UINT32 FunctionEndAddress;
  665. UINT32 UnwindInfoAddress;
  666. } RUNTIME_FUNCTION;
  667. typedef struct {
  668. UINT8 Version:3;
  669. UINT8 Flags:5;
  670. UINT8 SizeOfProlog;
  671. UINT8 CountOfUnwindCodes;
  672. UINT8 FrameRegister:4;
  673. UINT8 FrameRegisterOffset:4;
  674. } UNWIND_INFO;
  675. //
  676. // Resource format.
  677. //
  678. typedef struct {
  679. UINT32 Characteristics;
  680. UINT32 TimeDateStamp;
  681. UINT16 MajorVersion;
  682. UINT16 MinorVersion;
  683. UINT16 NumberOfNamedEntries;
  684. UINT16 NumberOfIdEntries;
  685. } EFI_IMAGE_RESOURCE_DIRECTORY;
  686. //
  687. // Resource directory entry format.
  688. //
  689. typedef struct {
  690. union {
  691. struct {
  692. UINT32 NameOffset:31;
  693. UINT32 NameIsString:1;
  694. } s;
  695. UINT32 Id;
  696. } u1;
  697. union {
  698. UINT32 OffsetToData;
  699. struct {
  700. UINT32 OffsetToDirectory:31;
  701. UINT32 DataIsDirectory:1;
  702. } s;
  703. } u2;
  704. } EFI_IMAGE_RESOURCE_DIRECTORY_ENTRY;
  705. //
  706. // Resource directory entry for string.
  707. //
  708. typedef struct {
  709. UINT16 Length;
  710. CHAR16 String[1];
  711. } EFI_IMAGE_RESOURCE_DIRECTORY_STRING;
  712. //
  713. // Resource directory entry for data array.
  714. //
  715. typedef struct {
  716. UINT32 OffsetToData;
  717. UINT32 Size;
  718. UINT32 CodePage;
  719. UINT32 Reserved;
  720. } EFI_IMAGE_RESOURCE_DATA_ENTRY;
  721. //
  722. // Header format for TE images
  723. //
  724. /*++
  725. Structure Description:
  726. This structure defines the header format for TE images.
  727. Members:
  728. Signature - Stores the magic value for the TE format, "VZ".
  729. Machine - Stores the machine type.
  730. NumberOfSections - Stores the total number of file sections.
  731. Subsystem - Stores the PE subsystem.
  732. StrippedSize - Stores the count of bytes removed from the header.
  733. AddressOfEntryPoint - Stores the offset to the entry point.
  734. BaseOfCode - Stores the image base of the text section, required for ITP
  735. debugging.
  736. ImageBase - Stores the image base.
  737. DataDirectory - Stores the base relocation and debug directories.
  738. --*/
  739. typedef struct {
  740. UINT16 Signature;
  741. UINT16 Machine;
  742. UINT8 NumberOfSections;
  743. UINT8 Subsystem;
  744. UINT16 StrippedSize;
  745. UINT32 AddressOfEntryPoint;
  746. UINT32 BaseOfCode;
  747. UINT64 ImageBase;
  748. EFI_IMAGE_DATA_DIRECTORY DataDirectory[2];
  749. } EFI_TE_IMAGE_HEADER;
  750. //
  751. // Union of PE32, PE32+, and TE headers
  752. //
  753. typedef union {
  754. EFI_IMAGE_NT_HEADERS32 Pe32;
  755. EFI_IMAGE_NT_HEADERS64 Pe32Plus;
  756. EFI_TE_IMAGE_HEADER Te;
  757. } EFI_IMAGE_OPTIONAL_HEADER_UNION;
  758. typedef union {
  759. EFI_IMAGE_NT_HEADERS32 *Pe32;
  760. EFI_IMAGE_NT_HEADERS64 *Pe32Plus;
  761. EFI_TE_IMAGE_HEADER *Te;
  762. EFI_IMAGE_OPTIONAL_HEADER_UNION *Union;
  763. } EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION;
  764. //
  765. // -------------------------------------------------------------------- Globals
  766. //
  767. //
  768. // -------------------------------------------------------- Function Prototypes
  769. //