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
;
22 /* FUNCTIONS *****************************************************************/
25 EFI_SYSTEM_TABLE
* g_SystemTable
;
28 EarlyPrint(_In_ PWCHAR Format
, ...)
33 va_start(args
, Format
);
35 vswprintf(buffer
, Format
, args
);
37 g_SystemTable
->ConOut
->OutputString(g_SystemTable
->ConOut
, L
"\r");
38 g_SystemTable
->ConOut
->OutputString(g_SystemTable
->ConOut
, buffer
);
40 g_SystemTable
->BootServices
->Stall(1000000);
47 * @name InitializeLibrary
49 * The InitializeLibrary function initializes the Boot Library.
51 * @param BootParameters
52 * Pointer to the Boot Application Parameter Block.
54 * @param LibraryParameters
55 * Pointer to the Boot Library Parameters.
57 * @return NT_SUCCESS if the boot library was loaded correctly, relevant error
63 _In_ PBOOT_APPLICATION_PARAMETER_BLOCK BootAppParameters
,
64 _In_ PBL_LIBRARY_PARAMETERS LibraryParameters
68 PBL_MEMORY_DATA MemoryData
;
69 PBL_APPLICATION_ENTRY AppEntry
;
70 PBL_FIRMWARE_DESCRIPTOR FirmwareDescriptor
;
71 ULONG_PTR ParamPointer
= (ULONG_PTR
)BootAppParameters
;
73 /* Validate correct Boot Application data */
74 if (!(BootAppParameters
) ||
75 (BootAppParameters
->Signature
[0] != BOOT_APPLICATION_SIGNATURE_1
) ||
76 (BootAppParameters
->Signature
[1] != BOOT_APPLICATION_SIGNATURE_2
) ||
77 (BootAppParameters
->Size
< sizeof(*BootAppParameters
)))
79 Status
= STATUS_INVALID_PARAMETER
;
83 /* Get sub-structures */
84 MemoryData
= (PBL_MEMORY_DATA
)(ParamPointer
+ BootAppParameters
->MemoryDataOffset
);
85 FirmwareDescriptor
= (PBL_FIRMWARE_DESCRIPTOR
)(ParamPointer
+ BootAppParameters
->FirmwareParametersOffset
);
86 AppEntry
= (PBL_APPLICATION_ENTRY
)(ParamPointer
+ BootAppParameters
->AppEntryOffset
);
87 BlpBootDevice
= (PBL_DEVICE_DESCRIPTOR
)(ParamPointer
+ BootAppParameters
->BootDeviceOffset
);
88 BlpApplicationBaseDirectory
= LibraryParameters
->ApplicationBaseDirectory
;
90 /* Initialize the firmware table */
91 Status
= BlpFwInitialize(0, FirmwareDescriptor
);
92 if (!NT_SUCCESS(Status
))
97 /* Find boot application entry */
98 if (strncmp(AppEntry
->Signature
, BL_APP_ENTRY_SIGNATURE
, 7))
100 Status
= STATUS_INVALID_PARAMETER_9
;
104 /* Read parameters */
105 BlpApplicationParameters
= BootAppParameters
;
106 BlpLibraryParameters
= *LibraryParameters
;
108 /* Save the application entry */
109 if (AppEntry
->Flags
& 2)
111 AppEntry
->Flags
= (AppEntry
->Flags
& ~0x2) | 0x80;
113 BlpApplicationEntry
= *AppEntry
;
115 /* Everything has been captured */
116 BlpLibraryParametersInitialized
= TRUE
;
118 /* Initialize the architecture (PM or RM) switching */
119 Status
= BlpArchInitialize(0);
120 if (!NT_SUCCESS(Status
))
125 /* Initialize the memory manager */
126 Status
= BlpMmInitialize(MemoryData
,
127 BootAppParameters
->MemoryTranslationType
,
129 if (!NT_SUCCESS(Status
))
131 EarlyPrint(L
"MM init failed!\n");
135 EarlyPrint(L
"TODO!\n");
136 Status
= STATUS_NOT_IMPLEMENTED
;
139 EarlyPrint(L
"Exiting init: %lx\n", Status
);
144 * @name BlInitializeLibrary
146 * The BlInitializeLibrary function initializes, or re-initializes, the
149 * @param BootParameters
150 * Pointer to the Boot Application Parameter Block.
152 * @param LibraryParameters
153 * Pointer to the Boot Library Parameters.
155 * @return NT_SUCCESS if the boot library was loaded correctly, relevant error
161 _In_ PBOOT_APPLICATION_PARAMETER_BLOCK BootAppParameters
,
162 _In_ PBL_LIBRARY_PARAMETERS LibraryParameters
167 /* Are we re-initializing the library? */
168 if (LibraryParameters
->LibraryFlags
& 2)
171 BlpLibraryParameters
= *LibraryParameters
;
172 if (LibraryParameters
->LibraryFlags
& 4)
175 /* Initialize all the core modules again */
178 BlMmRemoveBadMemory();
179 BlpMmInitializeConstraints();
181 /* Redraw the graphics console as needed */
182 BlpDisplayInitialize(LibraryParameters
->LibraryFlags
);
183 BlpResourceInitialize();
187 /* Nothing to do, we're done */
188 Status
= STATUS_SUCCESS
;
192 /* Nope, this is first time initialization */
193 Status
= InitializeLibrary(BootAppParameters
, LibraryParameters
);
196 /* Return initialization status */