[BOOTMGFW]:
[reactos.git] / reactos / boot / environ / lib / bootlib.c
1 /*
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)
7 */
8
9 /* INCLUDES ******************************************************************/
10
11 #include "bl.h"
12
13 /* DATA VARIABLES ************************************************************/
14
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;
21
22 /* temp */
23 BL_TRANSLATION_TYPE MmTranslationType;
24
25 /* FUNCTIONS *****************************************************************/
26
27 /*++
28 * @name InitializeLibrary
29 *
30 * The InitializeLibrary function initializes the Boot Library.
31 *
32 * @param BootParameters
33 * Pointer to the Boot Application Parameter Block.
34 *
35 * @param LibraryParameters
36 * Pointer to the Boot Library Parameters.
37 *
38 * @return NT_SUCCESS if the boot library was loaded correctly, relevant error
39 * otherwise.
40 *
41 *--*/
42 NTSTATUS
43 InitializeLibrary (
44 _In_ PBOOT_APPLICATION_PARAMETER_BLOCK BootAppParameters,
45 _In_ PBL_LIBRARY_PARAMETERS LibraryParameters
46 )
47 {
48 NTSTATUS Status;
49 //PBL_MEMORY_DATA MemoryData;
50 PBL_APPLICATION_ENTRY AppEntry;
51 PBL_FIRMWARE_DESCRIPTOR FirmwareDescriptor;
52 ULONG_PTR ParamPointer = (ULONG_PTR)BootAppParameters;
53
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)))
59 {
60 return STATUS_INVALID_PARAMETER;
61 }
62
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;
69
70 /* Initialize the firmware table */
71 Status = BlpFwInitialize(0, FirmwareDescriptor);
72 if (!NT_SUCCESS(Status))
73 {
74 goto Quickie;
75 }
76
77 /* Find boot application entry */
78 if (strncmp(AppEntry->Signature, BL_APP_ENTRY_SIGNATURE, 7))
79 {
80 Status = STATUS_INVALID_PARAMETER_9;
81 }
82
83 /* Read parameters */
84 BlpApplicationParameters = BootAppParameters;
85 BlpLibraryParameters = *LibraryParameters;
86
87 /* Save the application entry */
88 if (AppEntry->Flags & 2)
89 {
90 AppEntry->Flags = (AppEntry->Flags & ~0x2) | 0x80;
91 }
92 BlpApplicationEntry = *AppEntry;
93
94 /* Everything has been captured */
95 BlpLibraryParametersInitialized = TRUE;
96
97 /* Initialize the architecture (PM or RM) switching */
98 Status = BlpArchInitialize(0);
99 if (!NT_SUCCESS(Status))
100 {
101 goto Quickie;
102 }
103
104 Status = STATUS_NOT_IMPLEMENTED;
105
106 Quickie:
107 return Status;
108 }
109
110 /*++
111 * @name BlInitializeLibrary
112 *
113 * The BlInitializeLibrary function initializes, or re-initializes, the
114 * Boot Library.
115 *
116 * @param BootParameters
117 * Pointer to the Boot Application Parameter Block.
118 *
119 * @param LibraryParameters
120 * Pointer to the Boot Library Parameters.
121 *
122 * @return NT_SUCCESS if the boot library was loaded correctly, relevant error
123 * otherwise.
124 *
125 *--*/
126 NTSTATUS
127 BlInitializeLibrary(
128 _In_ PBOOT_APPLICATION_PARAMETER_BLOCK BootAppParameters,
129 _In_ PBL_LIBRARY_PARAMETERS LibraryParameters
130 )
131 {
132 NTSTATUS Status;
133
134 /* Are we re-initializing the library? */
135 if (LibraryParameters->LibraryFlags & 2)
136 {
137 /* From scratch? */
138 BlpLibraryParameters = *LibraryParameters;
139 if (LibraryParameters->LibraryFlags & 4)
140 {
141 #if 0
142 /* Initialize all the core modules again */
143 BlpSiInitialize(1);
144 BlBdInitialize();
145 BlMmRemoveBadMemory();
146 BlpMmInitializeConstraints();
147
148 /* Redraw the graphics console as needed */
149 BlpDisplayInitialize(LibraryParameters->LibraryFlags);
150 BlpResourceInitialize();
151 #endif
152 }
153
154 /* Nothing to do, we're done */
155 Status = STATUS_SUCCESS;
156 }
157 else
158 {
159 /* Nope, this is first time initialization */
160 Status = InitializeLibrary(BootAppParameters, LibraryParameters);
161 }
162
163 /* Return initialization status */
164 return Status;
165 }
166