1#ifndef _COFF_AOUTHDR_H
2#define _COFF_AOUTHDR_H
3/*
4 * These data structures are discribed in the pecoff_v8.doc in section
5 * "3.4. Optional Header (Image Only)"
6 */
7#include <stdint.h>
8
9/*
10 * Every image file has an optional header that provides information to the
11 * loader. This header is optional in the sense that some files (specifically,
12 * object files) do not have it. For image files, this header is required.
13 *
14 * Since definitions for this header were based from the GNU binutils files
15 * coff/external.h, coff/internal.h and other files the copyright info is below.
16 */
17
18/* Copyright 2001 Free Software Foundation, Inc.
19
20   This program is free software; you can redistribute it and/or modify
21   it under the terms of the GNU General Public License as published by
22   the Free Software Foundation; either version 2 of the License, or
23   (at your option) any later version.
24
25   This program is distributed in the hope that it will be useful,
26   but WITHOUT ANY WARRANTY; without even the implied warranty of
27   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28   GNU General Public License for more details.
29
30   You should have received a copy of the GNU General Public License
31   along with this program; if not, write to the Free Software
32   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
33
34struct aouthdr
35{
36	uint16_t magic;		/* type of file				*/
37	uint16_t vstamp;	/* version stamp			*/
38	uint32_t tsize;		/* text size in bytes, padded to FW bdry*/
39	uint32_t dsize;		/* initialized data "  "		*/
40	uint32_t bsize;		/* uninitialized data "   "		*/
41	uint32_t entry;		/* entry pt.				*/
42	uint32_t text_start;	/* base of text used for this file 	*/
43	uint32_t data_start;	/* base of data used for this file 	*/
44
45	uint32_t ImageBase;
46	uint32_t SectionAlignment;
47	uint32_t FileAlignment;
48	uint16_t MajorOperatingSystemVersion;
49	uint16_t MinorOperatingSystemVersion;
50	uint16_t MajorImageVersion;
51	uint16_t MinorImageVersion;
52	uint16_t MajorSubsystemVersion;
53	uint16_t MinorSubsystemVersion;
54	uint32_t Win32VersionValue;	/* Reserved, must be zero. */
55	uint32_t SizeOfImage;
56	uint32_t SizeOfHeaders;
57	uint32_t CheckSum;
58	uint16_t Subsystem;
59	uint16_t DllCharacteristics;
60	uint32_t SizeOfStackReserve;
61	uint32_t SizeOfStackCommit;
62	uint32_t SizeOfHeapReserve;
63	uint32_t SizeOfHeapCommit;
64	uint32_t LoaderFlags;
65	uint32_t NumberOfRvaAndSizes;
66	uint32_t DataDirectory[16][2]; /* 16 entries, 2 elements/entry, */
67};
68
69struct aouthdr_64
70{
71	uint16_t magic;		/* type of file				*/
72	uint16_t vstamp;	/* version stamp			*/
73	uint32_t tsize;		/* text size in bytes, padded to FW bdry*/
74	uint32_t dsize;		/* initialized data "  "		*/
75	uint32_t bsize;		/* uninitialized data "   "		*/
76	uint32_t entry;		/* entry pt.				*/
77	uint32_t text_start;	/* base of text used for this file 	*/
78	/* note no base of data field in the 64-bit optional header */
79
80	uint64_t ImageBase;
81	uint32_t SectionAlignment;
82	uint32_t FileAlignment;
83	uint16_t MajorOperatingSystemVersion;
84	uint16_t MinorOperatingSystemVersion;
85	uint16_t MajorImageVersion;
86	uint16_t MinorImageVersion;
87	uint16_t MajorSubsystemVersion;
88	uint16_t MinorSubsystemVersion;
89	uint32_t Win32VersionValue;	/* Reserved, must be zero. */
90	uint32_t SizeOfImage;
91	uint32_t SizeOfHeaders;
92	uint32_t CheckSum;
93	uint16_t Subsystem;
94	uint16_t DllCharacteristics;
95	uint64_t SizeOfStackReserve;
96	uint64_t SizeOfStackCommit;
97	uint64_t SizeOfHeapReserve;
98	uint64_t SizeOfHeapCommit;
99	uint32_t LoaderFlags;
100	uint32_t NumberOfRvaAndSizes;
101	uint32_t DataDirectory[16][2]; /* 16 entries, 2 elements/entry, */
102};
103
104/* for the magic field */
105#define PE32MAGIC       0x10b   /* 32-bit image */
106#define PE32PMAGIC	0x20b	/* 32-bit image inside 64-bit address space */
107
108/* for the FileAlignment field */
109#define FILEALIGNMENT	0x200	/* The alignment factor (in bytes) that is used
110				   to align the raw data of sections in the
111				   image file. The value should be a power of 2
112				   between 512 and 64 K, inclusive. The default
113				   is 512. If the SectionAlignment is less than
114				   the architecture's page size, then
115				   FileAlignment must match SectionAlignment. */
116
117/* for the SectionAlignment field */
118#define SECTIONALIGNMENT 0x1000 /* The alignment (in bytes) of sections when
119				   they are loaded into memory. It must be
120				   greater than or equal to FileAlignment.
121				   The default is the page size for the
122				   architecture. */
123
124/* for the vstamp field */
125#define LINKER_VERSION 256 /* That is, 2.56 */
126/* This piece of magic sets the "linker version" field to LINKER_VERSION.  */
127#define VSTAMP (LINKER_VERSION / 100 + (LINKER_VERSION % 100) * 256)
128
129/* for the Subsystem field */
130#define IMAGE_SUBSYSTEM_EFI_APPLICATION		10
131#define IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER	11
132#define IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER	12
133
134#endif /* _COFF_AOUTHDR_H */
135