2 * COPYRIGHT: See COPYING.ARM in the top level directory
3 * PROJECT: ReactOS UEFI Boot Library
4 * FILE: boot/environ/lib/bootlib.c
5 * PURPOSE: Boot Library Initialization
6 * PROGRAMMER: Alex Ionescu (alex.ionescu@reactos.org)
9 /* INCLUDES ******************************************************************/
13 /* DATA VARIABLES ************************************************************/
15 BL_LIBRARY_PARAMETERS BlpLibraryParameters
;
16 PBL_DEVICE_DESCRIPTOR BlpBootDevice
;
17 PWCHAR BlpApplicationBaseDirectory
;
18 PBOOT_APPLICATION_PARAMETER_BLOCK BlpApplicationParameters
;
19 BL_APPLICATION_ENTRY BlpApplicationEntry
;
20 BOOLEAN BlpLibraryParametersInitialized
;
23 BL_TRANSLATION_TYPE MmTranslationType
;
25 /* FUNCTIONS *****************************************************************/
28 * @name InitializeLibrary
30 * The InitializeLibrary function initializes the Boot Library.
32 * @param BootParameters
33 * Pointer to the Boot Application Parameter Block.
35 * @param LibraryParameters
36 * Pointer to the Boot Library Parameters.
38 * @return NT_SUCCESS if the boot library was loaded correctly, relevant error
44 _In_ PBOOT_APPLICATION_PARAMETER_BLOCK BootAppParameters
,
45 _In_ PBL_LIBRARY_PARAMETERS LibraryParameters
49 //PBL_MEMORY_DATA MemoryData;
50 PBL_APPLICATION_ENTRY AppEntry
;
51 PBL_FIRMWARE_DESCRIPTOR FirmwareDescriptor
;
52 ULONG_PTR ParamPointer
= (ULONG_PTR
)BootAppParameters
;
54 /* Validate correct Boot Application data */
55 if (!(BootAppParameters
) ||
56 (BootAppParameters
->Signature
[0] != BOOT_APPLICATION_SIGNATURE_1
) ||
57 (BootAppParameters
->Signature
[1] != BOOT_APPLICATION_SIGNATURE_2
) ||
58 (BootAppParameters
->Size
< sizeof(*BootAppParameters
)))
60 return STATUS_INVALID_PARAMETER
;
63 /* Get sub-structures */
64 //MemoryData = (PBL_MEMORY_DATA)(ParamPointer + BootAppParameters->MemoryDataOffset);
65 FirmwareDescriptor
= (PBL_FIRMWARE_DESCRIPTOR
)(ParamPointer
+ BootAppParameters
->FirmwareParametersOffset
);
66 AppEntry
= (PBL_APPLICATION_ENTRY
)(ParamPointer
+ BootAppParameters
->AppEntryOffset
);
67 BlpBootDevice
= (PBL_DEVICE_DESCRIPTOR
)(ParamPointer
+ BootAppParameters
->BootDeviceOffset
);
68 BlpApplicationBaseDirectory
= LibraryParameters
->ApplicationBaseDirectory
;
70 /* Initialize the firmware table */
71 Status
= BlpFwInitialize(0, FirmwareDescriptor
);
72 if (!NT_SUCCESS(Status
))
77 /* Find boot application entry */
78 if (strncmp(AppEntry
->Signature
, BL_APP_ENTRY_SIGNATURE
, 7))
80 Status
= STATUS_INVALID_PARAMETER_9
;
84 BlpApplicationParameters
= BootAppParameters
;
85 BlpLibraryParameters
= *LibraryParameters
;
87 /* Save the application entry */
88 if (AppEntry
->Flags
& 2)
90 AppEntry
->Flags
= (AppEntry
->Flags
& ~0x2) | 0x80;
92 BlpApplicationEntry
= *AppEntry
;
94 /* Everything has been captured */
95 BlpLibraryParametersInitialized
= TRUE
;
97 /* Initialize the architecture (PM or RM) switching */
98 Status
= BlpArchInitialize(0);
99 if (!NT_SUCCESS(Status
))
104 Status
= STATUS_NOT_IMPLEMENTED
;
111 * @name BlInitializeLibrary
113 * The BlInitializeLibrary function initializes, or re-initializes, the
116 * @param BootParameters
117 * Pointer to the Boot Application Parameter Block.
119 * @param LibraryParameters
120 * Pointer to the Boot Library Parameters.
122 * @return NT_SUCCESS if the boot library was loaded correctly, relevant error
128 _In_ PBOOT_APPLICATION_PARAMETER_BLOCK BootAppParameters
,
129 _In_ PBL_LIBRARY_PARAMETERS LibraryParameters
134 /* Are we re-initializing the library? */
135 if (LibraryParameters
->LibraryFlags
& 2)
138 BlpLibraryParameters
= *LibraryParameters
;
139 if (LibraryParameters
->LibraryFlags
& 4)
142 /* Initialize all the core modules again */
145 BlMmRemoveBadMemory();
146 BlpMmInitializeConstraints();
148 /* Redraw the graphics console as needed */
149 BlpDisplayInitialize(LibraryParameters
->LibraryFlags
);
150 BlpResourceInitialize();
154 /* Nothing to do, we're done */
155 Status
= STATUS_SUCCESS
;
159 /* Nope, this is first time initialization */
160 Status
= InitializeLibrary(BootAppParameters
, LibraryParameters
);
163 /* Return initialization status */