[BOOTMGFW]
[reactos.git] / reactos / boot / environ / include / bl.h
1 /*
2 * COPYRIGHT: See COPYING.ARM in the top level directory
3 * PROJECT: ReactOS UEFI Boot Library
4 * FILE: boot/environ/include/bl.h
5 * PURPOSE: Main Boot Library Header
6 * PROGRAMMER: Alex Ionescu (alex.ionescu@reactos.org)
7 */
8
9 #ifndef _BL_H
10 #define _BL_H
11
12 /* INCLUDES ******************************************************************/
13
14 /* C Headers */
15 #include <stdlib.h>
16 #include <stdio.h>
17 #include <wchar.h>
18
19 /* NT Base Headers */
20 #include <ntifs.h>
21
22 /* UEFI Headers */
23 #include <Uefi.h>
24 #include <DevicePath.h>
25 #include <LoadedImage.h>
26
27 /* DEFINES *******************************************************************/
28
29 #define BL_APPLICATION_FLAG_CONVERTED_FROM_EFI 0x01
30
31 #define BOOT_APPLICATION_SIGNATURE_1 'TOOB'
32 #define BOOT_APPLICATION_SIGNATURE_2 ' PPA'
33
34 #define BOOT_MEMORY_TRANSLATION_TYPE_PHYSICAL 0
35 #define BOOT_MEMORY_TRANSLATION_TYPE_VIRTUAL 1
36
37 #define BOOT_APPLICATION_VERSION 2
38 #define BL_MEMORY_DATA_VERSION 1
39 #define BL_RETURN_ARGUMENTS_VERSION 1
40 #define BL_FIRMWARE_DESCRIPTOR_VERSION 2
41
42 #define BL_APPLICATION_ENTRY_FLAG_NO_GUID 0x01
43
44 /* ENUMERATIONS **************************************************************/
45
46 //
47 // Boot Device Types
48 //
49 typedef enum _BL_DEVICE_TYPE
50 {
51 LocalDevice = 0,
52 PartitionDevice = 2,
53 UdpDevice = 4,
54 HardDiskDevice = 6
55 } BL_DEVICE_TYPE;
56
57 //
58 // Local Device Types
59 //
60 typedef enum _BL_LOCAL_DEVICE_TYPE
61 {
62 FloppyDevice = 1,
63 CdRomDevice = 2,
64 RamDiskDevice = 3,
65 } BL_LOCAL_DEVICE_TYPE;
66
67 //
68 // Partition types
69 //
70 typedef enum _BL_PARTITION_TYPE
71 {
72 GptPartition,
73 MbrPartition,
74 RawPartition,
75 } BL_PARTITION_TYPE;
76
77 //
78 // File Path Types
79 //
80 typedef enum _BL_PATH_TYPE
81 {
82 EfiPath = 4
83 } BL_PATH_TYPE;
84
85 //
86 // Classes of Memory
87 //
88 typedef enum _BL_MEMORY_CLASS
89 {
90 BlLoaderClass = 0xD,
91 BlApplicationClass,
92 BlSystemClass
93 } BL_MEMORY_CLASS;
94
95 //
96 // Types of Memory
97 //
98 typedef enum _BL_MEMORY_TYPE
99 {
100 //
101 // Loader Memory
102 //
103 BlLoaderMemory = 0xD0000002,
104 BlLoaderPageDirectory = 0xD0000006,
105 BlLoaderReferencePage = 0xD0000007,
106 BlLoaderRamDisk = 0xD0000008,
107 BlLoaderData = 0xD000000A,
108 BlLoaderSelfMap = 0xD000000F,
109
110 //
111 // Application Memory
112 //
113 BlApplicationData = 0xE0000004,
114
115 //
116 // System Memory
117 //
118 BlConventionalMemory = 0xF0000001,
119 BlUnusableMemory = 0xF0000002,
120 BlReservedMemory = 0xF0000003,
121 BlEfiBootMemory = 0xF0000004,
122 BlEfiRuntimeMemory = 0xF0000006,
123 BlAcpiReclaimMemory = 0xF0000008,
124 BlAcpiNvsMemory = 0xF0000009,
125 BlDeviceIoMemory = 0xF000000A,
126 BlDevicePortMemory = 0xF000000B,
127 BlPalMemory = 0xF000000C,
128 } BL_MEMORY_TYPE;
129
130 /* DATA STRUCTURES ***********************************************************/
131
132 typedef struct _BL_LIBRARY_PARAMETERS
133 {
134 ULONG LibraryFlags;
135 ULONG TranslationType;
136 ULONG MinimumAllocationCount;
137 ULONG MinimumHeapSize;
138 ULONG HeapAllocationAttributes;
139 PWCHAR ApplicationBaseDirectory;
140 ULONG DescriptorCount;
141 } BL_LIBRARY_PARAMETERS, *PBL_LIBRARY_PARAMETERS;
142
143 /* This should eventually go into a more public header */
144 typedef struct _BOOT_APPLICATION_PARAMETER_BLOCK
145 {
146 /* This header tells the library what image we're dealing with */
147 ULONG Signature[2];
148 ULONG Version;
149 ULONG Size;
150 ULONG ImageType;
151 ULONG MemoryTranslationType;
152
153 /* Where is the image located */
154 ULONGLONG ImageBase;
155 ULONG ImageSize;
156
157 /* Offset to BL_MEMORY_DATA */
158 ULONG MemoryDataOffset;
159
160 /* Offset to BL_APPLICATION_ENTRY */
161 ULONG AppEntryOffset;
162
163 /* Offset to BL_DEVICE_DESCRPIPTOR */
164 ULONG BootDeviceOffset;
165
166 /* Offset to BL_FIRMWARE_PARAMETERS */
167 ULONG FirmwareParametersOffset;
168
169 /* Offset to BL_RETURN_ARGUMENTS */
170 ULONG ReturnArgumentsOffset;
171 } BOOT_APPLICATION_PARAMETER_BLOCK, *PBOOT_APPLICATION_PARAMETER_BLOCK;
172
173 typedef struct _BL_MEMORY_DATA
174 {
175 ULONG Version;
176 ULONG MdListOffset;
177 ULONG DescriptorCount;
178 ULONG DescriptorSize;
179 ULONG Unknown;
180 } BL_MEMORY_DATA, *PBL_MEMORY_DATA;
181
182 typedef struct _BL_FIRMWARE_DESCRIPTOR
183 {
184 ULONG Version;
185 ULONG Unknown;
186 EFI_HANDLE ImageHandle;
187 EFI_SYSTEM_TABLE *SystemTable;
188 } BL_FIRMWARE_DESCRIPTOR, *PBL_FIRMWARE_DESCRIPTOR;
189
190 typedef struct _BL_RETURN_ARGUMENTS
191 {
192 ULONG Version;
193 ULONG ReturnArgumentData[6];
194 } BL_RETURN_ARGUMENTS, *PBL_RETURN_ARGUMENTS;
195
196 typedef struct _BL_MEMORY_DESCRIPTOR
197 {
198 LIST_ENTRY ListEntry;
199 union
200 {
201 struct
202 {
203 ULONGLONG BasePage;
204 ULONGLONG VirtualPage;
205 };
206 struct
207 {
208 ULONGLONG BaseAddress;
209 ULONGLONG VirtualAddress;
210 };
211 };
212 ULONGLONG PageCount;
213 ULONG Flags;
214 BL_MEMORY_TYPE Type;
215 } BL_MEMORY_DESCRIPTOR, *PBL_MEMORY_DESCRIPTOR;
216
217 typedef struct _BL_BCD_OPTION
218 {
219 ULONG Type;
220 ULONG DataOffset;
221 ULONG DataSize;
222 ULONG ListOffset;
223 ULONG NextEntryOffset;
224 ULONG Failed;
225 } BL_BCD_OPTION, *PBL_BCD_OPTION;
226
227 typedef struct _BL_APPLICATION_ENTRY
228 {
229 CHAR Signature[8];
230 ULONG Flags;
231 GUID Guid;
232 ULONG Unknown[4];
233 BL_BCD_OPTION BcdData;
234 } BL_APPLICATION_ENTRY, *PBL_APPLICATION_ENTRY;
235
236 typedef struct _BL_HARDDISK_DEVICE
237 {
238 ULONG PartitionType;
239 union
240 {
241 struct
242 {
243 ULONG PartitionSignature;
244 } Mbr;
245
246 struct
247 {
248 GUID PartitionSignature;
249 } Gpt;
250
251 struct
252 {
253 ULONG DiskNumber;
254 } Raw;
255 };
256 } BL_HARDDISK_DEVICE;
257
258 typedef struct _BL_LOCAL_DEVICE
259 {
260 ULONG Type;
261 union
262 {
263 struct
264 {
265 ULONG DriveNumber;
266 } FloppyDisk;
267
268 BL_HARDDISK_DEVICE HardDisk;
269
270 struct
271 {
272 PHYSICAL_ADDRESS ImageBase;
273 LARGE_INTEGER ImageSize;
274 ULONG ImageOffset;
275 } RamDisk;
276 };
277 } BL_LOCAL_DEVICE;
278
279 typedef struct _BL_DEVICE_DESCRIPTOR
280 {
281 ULONG Size;
282 ULONG Flags;
283 DEVICE_TYPE DeviceType;
284 ULONG Unknown;
285 union
286 {
287 BL_LOCAL_DEVICE Local;
288
289 struct
290 {
291 ULONG Unknown;
292 } Remote;
293
294 struct
295 {
296 union
297 {
298 ULONG PartitionNumber;
299 } Mbr;
300
301 union
302 {
303 GUID PartitionGuid;
304 } Gpt;
305
306 BL_LOCAL_DEVICE Disk;
307 } Partition;
308 };
309 } BL_DEVICE_DESCRIPTOR, *PBL_DEVICE_DESCRIPTOR;
310
311 typedef struct _BL_FILE_PATH_DESCRIPTOR
312 {
313 ULONG Version;
314 ULONG Length;
315 ULONG PathType;
316 UCHAR Path[ANYSIZE_ARRAY];
317 } BL_FILE_PATH_DESCRIPTOR, *PBL_FILE_PATH_DESCRIPTOR;
318
319 typedef struct _BL_WINDOWS_LOAD_OPTIONS
320 {
321 CHAR Signature[8];
322 ULONG Version;
323 ULONG Length;
324 ULONG OsPathOffset;
325 WCHAR LoadOptions[ANYSIZE_ARRAY];
326 } BL_WINDOWS_LOAD_OPTIONS, *PBL_WINDOWS_LOAD_OPTIONS;
327
328 /* INITIALIZATION ROUTINES ***************************************************/
329
330 NTSTATUS
331 BlInitializeLibrary(
332 _In_ PBOOT_APPLICATION_PARAMETER_BLOCK BootAppParameters,
333 _In_ PBL_LIBRARY_PARAMETERS LibraryParameters
334 );
335
336 /* UTILITY ROUTINES **********************************************************/
337
338 EFI_STATUS
339 EfiGetEfiStatusCode(
340 _In_ NTSTATUS Status
341 );
342
343 /* BCD ROUTINES **************************************************************/
344
345 ULONG
346 BlGetBootOptionSize (
347 _In_ PBL_BCD_OPTION BcdOption
348 );
349
350 #endif