1
0

peimage.h 23 KB

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