]>
Commit | Line | Data |
---|---|---|
878ddf1f | 1 | /*++\r |
2 | \r | |
ce8bd86e | 3 | Copyright (c) 2006, Intel Corporation\r |
4 | All rights reserved. This program and the accompanying materials\r | |
5 | are licensed and made available under the terms and conditions of the BSD License\r | |
6 | which accompanies this distribution. The full text of the license may be found at\r | |
7 | http://opensource.org/licenses/bsd-license.php\r | |
8 | \r | |
9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
878ddf1f | 11 | \r |
12 | Module Name:\r | |
13 | \r | |
14 | Runtime.c\r | |
15 | \r | |
16 | Abstract:\r | |
17 | \r | |
18 | Runtime Architectural Protocol as defined in the DXE CIS\r | |
19 | \r | |
20 | This code is used to produce the EFI runtime virtual switch over\r | |
21 | \r | |
22 | THIS IS VERY DANGEROUS CODE BE VERY CAREFUL IF YOU CHANGE IT\r | |
23 | \r | |
24 | The transition for calling EFI Runtime functions in physical mode to calling\r | |
ce8bd86e | 25 | them in virtual mode is very very complex. Every pointer in needs to be\r |
878ddf1f | 26 | converted from physical mode to virtual mode. Be very careful walking linked\r |
27 | lists! Then to make it really hard the code it's self needs be relocated into\r | |
28 | the new virtual address space.\r | |
29 | \r | |
30 | So here is the concept. The code in this module will never ever be called in\r | |
31 | virtual mode. This is the code that collects the information needed to convert\r | |
ce8bd86e | 32 | to virtual mode (DXE core registers runtime stuff with this code). Since this\r |
878ddf1f | 33 | code is used to fixup all runtime images, it CAN NOT fix it's self up. So some\r |
34 | code has to stay behind and that is us.\r | |
35 | \r | |
ce8bd86e | 36 | Also you need to be careful about when you allocate memory, as once we are in\r |
37 | runtime (including our EVT_SIGNAL_EXIT_BOOT_SERVICES event) you can no longer\r | |
878ddf1f | 38 | allocate memory.\r |
39 | \r | |
ce8bd86e | 40 | Any runtime driver that gets loaded before us will not be callable in virtual\r |
41 | mode. This is due to the fact that the DXE core can not register the info\r | |
42 | needed with us. This is good, since it keeps the code in this file from\r | |
878ddf1f | 43 | getting registered.\r |
44 | \r | |
45 | \r | |
46 | Revision History:\r | |
47 | \r | |
48 | - Move the CalculateCrc32 function from Runtime Arch Protocol to Boot Service.\r | |
49 | Runtime Arch Protocol definition no longer contains CalculateCrc32. Boot Service\r | |
50 | Table now contains an item named CalculateCrc32.\r | |
51 | \r | |
52 | --*/\r | |
53 | \r | |
54 | \r | |
55 | #include "Runtime.h"\r | |
56 | \r | |
57 | //\r | |
3ec2611d | 58 | // Global Variables\r |
878ddf1f | 59 | //\r |
3ec2611d LG |
60 | EFI_MEMORY_DESCRIPTOR *mVirtualMap = NULL;\r |
61 | UINTN mVirtualMapDescriptorSize;\r | |
62 | UINTN mVirtualMapMaxIndex;\r | |
63 | VOID *mMyImageBase;\r | |
878ddf1f | 64 | \r |
65 | //\r | |
66 | // The handle onto which the Runtime Architectural Protocol instance is installed\r | |
67 | //\r | |
68 | EFI_HANDLE mRuntimeHandle = NULL;\r | |
69 | \r | |
70 | //\r | |
71 | // The Runtime Architectural Protocol instance produced by this driver\r | |
72 | //\r | |
73 | EFI_RUNTIME_ARCH_PROTOCOL mRuntime = {\r | |
3ec2611d LG |
74 | INITIALIZE_LIST_HEAD_VARIABLE (mRuntime.ImageHead),\r |
75 | INITIALIZE_LIST_HEAD_VARIABLE (mRuntime.EventHead),\r | |
878ddf1f | 76 | \r |
3ec2611d LG |
77 | //\r |
78 | // Make sure Size != sizeof (EFI_MEMORY_DESCRIPTOR). This will\r | |
79 | // prevent people from having pointer math bugs in their code.\r | |
80 | // now you have to use *DescriptorSize to make things work.\r | |
81 | //\r | |
ce8bd86e | 82 | sizeof (EFI_MEMORY_DESCRIPTOR) + sizeof (UINT64) - (sizeof (EFI_MEMORY_DESCRIPTOR) % sizeof (UINT64)),\r |
83 | EFI_MEMORY_DESCRIPTOR_VERSION,\r | |
3ec2611d LG |
84 | 0,\r |
85 | NULL,\r | |
86 | NULL,\r | |
87 | FALSE,\r | |
88 | FALSE\r | |
89 | };\r | |
878ddf1f | 90 | \r |
91 | //\r | |
92 | // Worker Functions\r | |
93 | //\r | |
1cc8ee78 | 94 | STATIC\r |
878ddf1f | 95 | VOID\r |
96 | RuntimeDriverCalculateEfiHdrCrc (\r | |
97 | IN OUT EFI_TABLE_HEADER *Hdr\r | |
98 | )\r | |
99 | /*++\r | |
100 | \r | |
101 | Routine Description:\r | |
102 | \r | |
103 | Calcualte the 32-bit CRC in a EFI table using the Runtime Drivers\r | |
104 | internal function. The EFI Boot Services Table can not be used because\r | |
105 | the EFI Boot Services Table was destroyed at ExitBootServices()\r | |
106 | \r | |
107 | Arguments:\r | |
108 | \r | |
109 | Hdr - Pointer to an EFI standard header\r | |
110 | \r | |
111 | Returns:\r | |
112 | \r | |
113 | None\r | |
114 | \r | |
115 | --*/\r | |
116 | {\r | |
117 | UINT32 Crc;\r | |
118 | \r | |
119 | Hdr->CRC32 = 0;\r | |
120 | \r | |
121 | Crc = 0;\r | |
122 | RuntimeDriverCalculateCrc32 ((UINT8 *) Hdr, Hdr->HeaderSize, &Crc);\r | |
123 | Hdr->CRC32 = Crc;\r | |
124 | }\r | |
125 | \r | |
126 | EFI_STATUS\r | |
127 | EFIAPI\r | |
3ec2611d LG |
128 | RuntimeDriverConvertPointer (\r |
129 | IN UINTN DebugDisposition,\r | |
130 | IN OUT VOID **ConvertAddress\r | |
878ddf1f | 131 | )\r |
132 | /*++\r | |
133 | \r | |
134 | Routine Description:\r | |
135 | \r | |
3ec2611d | 136 | Determines the new virtual address that is to be used on subsequent memory accesses.\r |
878ddf1f | 137 | \r |
138 | Arguments:\r | |
ce8bd86e | 139 | \r |
3ec2611d LG |
140 | DebugDisposition - Supplies type information for the pointer being converted.\r |
141 | ConvertAddress - A pointer to a pointer that is to be fixed to be the value needed\r | |
142 | for the new virtual address mappings being applied.\r | |
878ddf1f | 143 | \r |
3ec2611d | 144 | Returns:\r |
878ddf1f | 145 | \r |
3ec2611d LG |
146 | EFI_SUCCESS - The pointer pointed to by Address was modified.\r |
147 | EFI_NOT_FOUND - The pointer pointed to by Address was not found to be part\r | |
148 | of the current memory map. This is normally fatal.\r | |
149 | EFI_INVALID_PARAMETER - One of the parameters has an invalid value.\r | |
878ddf1f | 150 | \r |
151 | --*/\r | |
878ddf1f | 152 | {\r |
153 | UINTN Address;\r | |
154 | VOID *PlabelConvertAddress;\r | |
155 | UINT64 VirtEndOfRange;\r | |
156 | EFI_MEMORY_DESCRIPTOR *VirtEntry;\r | |
157 | UINTN Index;\r | |
158 | \r | |
159 | //\r | |
160 | // Make sure ConvertAddress is a valid pointer\r | |
161 | //\r | |
162 | if (ConvertAddress == NULL) {\r | |
163 | return EFI_INVALID_PARAMETER;\r | |
164 | }\r | |
165 | //\r | |
166 | // Get the address to convert\r | |
167 | //\r | |
168 | Address = (UINTN) *ConvertAddress;\r | |
169 | \r | |
170 | //\r | |
171 | // If this is a null pointer, return if it's allowed\r | |
172 | //\r | |
173 | if (Address == 0) {\r | |
174 | if (DebugDisposition & EFI_OPTIONAL_POINTER) {\r | |
175 | return EFI_SUCCESS;\r | |
176 | }\r | |
177 | \r | |
178 | return EFI_INVALID_PARAMETER;\r | |
179 | }\r | |
180 | \r | |
181 | PlabelConvertAddress = NULL;\r | |
182 | VirtEntry = mVirtualMap;\r | |
183 | for (Index = 0; Index < mVirtualMapMaxIndex; Index++) {\r | |
184 | //\r | |
185 | // To prevent the inclusion of 64-bit math functions a UINTN was placed in\r | |
186 | // front of VirtEntry->NumberOfPages to cast it to a 32-bit thing on IA-32\r | |
187 | // platforms. If you get this ASSERT remove the UINTN and do a 64-bit\r | |
188 | // multiply.\r | |
189 | //\r | |
3ec2611d | 190 | ASSERT (((UINTN) VirtEntry->NumberOfPages < 0xffffffff) || (sizeof (UINTN) > 4));\r |
878ddf1f | 191 | \r |
192 | if ((VirtEntry->Attribute & EFI_MEMORY_RUNTIME) == EFI_MEMORY_RUNTIME) {\r | |
193 | if (Address >= VirtEntry->PhysicalStart) {\r | |
194 | VirtEndOfRange = VirtEntry->PhysicalStart + (((UINTN) VirtEntry->NumberOfPages) * EFI_PAGE_SIZE);\r | |
195 | if (Address < VirtEndOfRange) {\r | |
196 | //\r | |
197 | // Compute new address\r | |
198 | //\r | |
199 | *ConvertAddress = (VOID *) (Address - (UINTN) VirtEntry->PhysicalStart + (UINTN) VirtEntry->VirtualStart);\r | |
200 | return EFI_SUCCESS;\r | |
201 | } else if (Address < (VirtEndOfRange + 0x200000)) {\r | |
202 | //\r | |
203 | // On Itanium GP defines a window +/- 2 MB inside an image.\r | |
204 | // The compiler may asign a GP value outside of the image. Thus\r | |
205 | // it could fall out side of any of our valid regions\r | |
206 | //\r | |
207 | PlabelConvertAddress = (VOID *) (Address - (UINTN) VirtEntry->PhysicalStart + (UINTN) VirtEntry->VirtualStart);\r | |
208 | }\r | |
209 | }\r | |
210 | }\r | |
211 | \r | |
212 | VirtEntry = NextMemoryDescriptor (VirtEntry, mVirtualMapDescriptorSize);\r | |
213 | }\r | |
214 | \r | |
215 | if (DebugDisposition & EFI_IPF_GP_POINTER) {\r | |
216 | //\r | |
217 | // If it's an IPF GP and the GP was outside the image handle that case.\r | |
218 | //\r | |
219 | if (PlabelConvertAddress != NULL) {\r | |
220 | *ConvertAddress = PlabelConvertAddress;\r | |
221 | return EFI_SUCCESS;\r | |
222 | }\r | |
223 | }\r | |
224 | \r | |
225 | return EFI_NOT_FOUND;\r | |
226 | }\r | |
227 | \r | |
1cc8ee78 | 228 | STATIC\r |
878ddf1f | 229 | EFI_STATUS\r |
230 | RuntimeDriverConvertInternalPointer (\r | |
231 | IN OUT VOID **ConvertAddress\r | |
232 | )\r | |
3ec2611d LG |
233 | /*++\r |
234 | \r | |
235 | Routine Description:\r | |
236 | \r | |
ce8bd86e | 237 | Determines the new virtual address that is to be used on subsequent memory accesses\r |
3ec2611d LG |
238 | for internal pointers.\r |
239 | \r | |
240 | Arguments:\r | |
ce8bd86e | 241 | \r |
3ec2611d LG |
242 | ConvertAddress - A pointer to a pointer that is to be fixed to be the value needed\r |
243 | for the new virtual address mappings being applied.\r | |
244 | \r | |
245 | Returns:\r | |
246 | \r | |
247 | EFI_SUCCESS - The pointer pointed to by Address was modified.\r | |
248 | EFI_NOT_FOUND - The pointer pointed to by Address was not found to be part\r | |
249 | of the current memory map. This is normally fatal.\r | |
250 | EFI_INVALID_PARAMETER - One of the parameters has an invalid value.\r | |
251 | \r | |
252 | --*/\r | |
878ddf1f | 253 | {\r |
254 | return RuntimeDriverConvertPointer (0x0, ConvertAddress);\r | |
255 | }\r | |
256 | \r | |
257 | EFI_STATUS\r | |
258 | EFIAPI\r | |
259 | RuntimeDriverSetVirtualAddressMap (\r | |
260 | IN UINTN MemoryMapSize,\r | |
261 | IN UINTN DescriptorSize,\r | |
262 | IN UINT32 DescriptorVersion,\r | |
263 | IN EFI_MEMORY_DESCRIPTOR *VirtualMap\r | |
264 | )\r | |
3ec2611d LG |
265 | /*++\r |
266 | \r | |
267 | Routine Description:\r | |
268 | \r | |
269 | Changes the runtime addressing mode of EFI firmware from physical to virtual.\r | |
270 | \r | |
271 | Arguments:\r | |
ce8bd86e | 272 | \r |
3ec2611d LG |
273 | MemoryMapSize - The size in bytes of VirtualMap.\r |
274 | DescriptorSize - The size in bytes of an entry in the VirtualMap.\r | |
275 | DescriptorVersion - The version of the structure entries in VirtualMap.\r | |
276 | VirtualMap - An array of memory descriptors which contain new virtual\r | |
277 | address mapping information for all runtime ranges.\r | |
278 | \r | |
279 | Returns:\r | |
280 | \r | |
281 | EFI_SUCCESS - The virtual address map has been applied.\r | |
282 | EFI_UNSUPPORTED - EFI firmware is not at runtime, or the EFI firmware is already in\r | |
283 | virtual address mapped mode.\r | |
284 | EFI_INVALID_PARAMETER - DescriptorSize or DescriptorVersion is invalid.\r | |
285 | EFI_NO_MAPPING - A virtual address was not supplied for a range in the memory\r | |
286 | map that requires a mapping.\r | |
287 | EFI_NOT_FOUND - A virtual address was supplied for an address that is not found\r | |
288 | in the memory map.\r | |
289 | \r | |
ce8bd86e | 290 | --*/\r |
878ddf1f | 291 | {\r |
2ce31132 | 292 | EFI_STATUS Status;\r |
3ec2611d LG |
293 | EFI_RUNTIME_EVENT_ENTRY *RuntimeEvent;\r |
294 | EFI_RUNTIME_IMAGE_ENTRY *RuntimeImage;\r | |
878ddf1f | 295 | LIST_ENTRY *Link;\r |
296 | UINTN Index;\r | |
297 | UINTN Index1;\r | |
298 | EFI_DRIVER_OS_HANDOFF_HEADER *DriverOsHandoffHeader;\r | |
299 | EFI_DRIVER_OS_HANDOFF *DriverOsHandoff;\r | |
2ce31132 | 300 | EFI_PHYSICAL_ADDRESS VirtImageBase;\r |
ce8bd86e | 301 | EFI_CAPSULE_TABLE *CapsuleTable;\r |
878ddf1f | 302 | \r |
303 | //\r | |
304 | // Can only switch to virtual addresses once the memory map is locked down,\r | |
305 | // and can only set it once\r | |
306 | //\r | |
3ec2611d | 307 | if (!mRuntime.AtRuntime || mRuntime.VirtualMode) {\r |
878ddf1f | 308 | return EFI_UNSUPPORTED;\r |
309 | }\r | |
310 | //\r | |
311 | // Only understand the original descriptor format\r | |
312 | //\r | |
313 | if (DescriptorVersion != EFI_MEMORY_DESCRIPTOR_VERSION || DescriptorSize < sizeof (EFI_MEMORY_DESCRIPTOR)) {\r | |
314 | return EFI_INVALID_PARAMETER;\r | |
315 | }\r | |
316 | //\r | |
878ddf1f | 317 | // We are now committed to go to virtual mode, so lets get to it!\r |
318 | //\r | |
3ec2611d | 319 | mRuntime.VirtualMode = TRUE;\r |
878ddf1f | 320 | \r |
321 | //\r | |
322 | // ConvertPointer() needs this mVirtualMap to do the conversion. So set up\r | |
323 | // globals we need to parse the virtual address map.\r | |
324 | //\r | |
325 | mVirtualMapDescriptorSize = DescriptorSize;\r | |
3ec2611d | 326 | mVirtualMapMaxIndex = MemoryMapSize / DescriptorSize;\r |
878ddf1f | 327 | mVirtualMap = VirtualMap;\r |
328 | \r | |
878ddf1f | 329 | //\r |
330 | // Currently the bug in StatusCode/RuntimeLib has been fixed, it will\r | |
331 | // check whether in Runtime or not (this is judged by looking at\r | |
332 | // mEfiAtRuntime global So this ReportStatusCode will work\r | |
333 | //\r | |
334 | REPORT_STATUS_CODE (\r | |
335 | EFI_PROGRESS_CODE,\r | |
336 | (EFI_SOFTWARE_EFI_BOOT_SERVICE | EFI_SW_RS_PC_SET_VIRTUAL_ADDRESS_MAP)\r | |
337 | );\r | |
338 | \r | |
339 | //\r | |
3ec2611d LG |
340 | // Signal all the EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE events.\r |
341 | // All runtime events are stored in a list in Runtime AP.\r | |
878ddf1f | 342 | //\r |
3ec2611d LG |
343 | for (Link = mRuntime.EventHead.ForwardLink; Link != &mRuntime.EventHead; Link = Link->ForwardLink) {\r |
344 | RuntimeEvent = _CR (Link, EFI_RUNTIME_EVENT_ENTRY, Link);\r | |
93b0fbc8 | 345 | if ((RuntimeEvent->Type & EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE) == EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE) {\r |
878ddf1f | 346 | RuntimeEvent->NotifyFunction (\r |
347 | RuntimeEvent->Event,\r | |
348 | RuntimeEvent->NotifyContext\r | |
349 | );\r | |
350 | }\r | |
351 | }\r | |
3ec2611d | 352 | \r |
878ddf1f | 353 | //\r |
3ec2611d | 354 | // Relocate runtime images. All runtime images are stored in a list in Runtime AP.\r |
878ddf1f | 355 | //\r |
3ec2611d LG |
356 | for (Link = mRuntime.ImageHead.ForwardLink; Link != &mRuntime.ImageHead; Link = Link->ForwardLink) {\r |
357 | RuntimeImage = _CR (Link, EFI_RUNTIME_IMAGE_ENTRY, Link);\r | |
358 | //\r | |
359 | // We don't want to relocate our selves, as we only run in physical mode.\r | |
360 | //\r | |
361 | if (mMyImageBase != RuntimeImage->ImageBase) {\r | |
2ce31132 | 362 | \r |
3ec2611d | 363 | VirtImageBase = (EFI_PHYSICAL_ADDRESS) (UINTN) RuntimeImage->ImageBase;\r |
2ce31132 | 364 | Status = RuntimeDriverConvertPointer (0, (VOID **) &VirtImageBase);\r |
365 | ASSERT_EFI_ERROR (Status);\r | |
366 | \r | |
367 | PeCoffLoaderRelocateImageForRuntime (\r | |
3ec2611d | 368 | (EFI_PHYSICAL_ADDRESS) (UINTN) RuntimeImage->ImageBase,\r |
2ce31132 | 369 | VirtImageBase,\r |
3ec2611d | 370 | (UINTN) RuntimeImage->ImageSize,\r |
2ce31132 | 371 | RuntimeImage->RelocationData\r |
372 | );\r | |
ce8bd86e | 373 | \r |
3ec2611d | 374 | InvalidateInstructionCacheRange (RuntimeImage->ImageBase, (UINTN)RuntimeImage->ImageSize);\r |
878ddf1f | 375 | }\r |
376 | }\r | |
3ec2611d | 377 | \r |
878ddf1f | 378 | //\r |
379 | // Convert all the Runtime Services except ConvertPointer() and SetVirtualAddressMap()\r | |
380 | // and recompute the CRC-32\r | |
381 | //\r | |
382 | RuntimeDriverConvertInternalPointer ((VOID **) &gRT->GetTime);\r | |
383 | RuntimeDriverConvertInternalPointer ((VOID **) &gRT->SetTime);\r | |
384 | RuntimeDriverConvertInternalPointer ((VOID **) &gRT->GetWakeupTime);\r | |
385 | RuntimeDriverConvertInternalPointer ((VOID **) &gRT->SetWakeupTime);\r | |
386 | RuntimeDriverConvertInternalPointer ((VOID **) &gRT->ResetSystem);\r | |
387 | RuntimeDriverConvertInternalPointer ((VOID **) &gRT->GetNextHighMonotonicCount);\r | |
388 | RuntimeDriverConvertInternalPointer ((VOID **) &gRT->GetVariable);\r | |
389 | RuntimeDriverConvertInternalPointer ((VOID **) &gRT->SetVariable);\r | |
390 | RuntimeDriverConvertInternalPointer ((VOID **) &gRT->GetNextVariableName);\r | |
045f4521 | 391 | RuntimeDriverConvertInternalPointer ((VOID **) &gRT->QueryVariableInfo);\r |
392 | RuntimeDriverConvertInternalPointer ((VOID **) &gRT->UpdateCapsule);\r | |
393 | RuntimeDriverConvertInternalPointer ((VOID **) &gRT->QueryCapsuleCapabilities);\r | |
878ddf1f | 394 | RuntimeDriverCalculateEfiHdrCrc (&gRT->Hdr);\r |
395 | \r | |
396 | //\r | |
397 | // Convert the UGA OS Handoff Table if it is present in the Configuration Table\r | |
398 | //\r | |
399 | for (Index = 0; Index < gST->NumberOfTableEntries; Index++) {\r | |
3ec2611d | 400 | if (CompareGuid (&gEfiUgaIoProtocolGuid, &(gST->ConfigurationTable[Index].VendorGuid))) {\r |
878ddf1f | 401 | DriverOsHandoffHeader = gST->ConfigurationTable[Index].VendorTable;\r |
402 | for (Index1 = 0; Index1 < DriverOsHandoffHeader->NumberOfEntries; Index1++) {\r | |
403 | DriverOsHandoff = (EFI_DRIVER_OS_HANDOFF *)\r | |
404 | (\r | |
405 | (UINTN) DriverOsHandoffHeader +\r | |
406 | DriverOsHandoffHeader->HeaderSize +\r | |
407 | Index1 *\r | |
408 | DriverOsHandoffHeader->SizeOfEntries\r | |
409 | );\r | |
410 | RuntimeDriverConvertPointer (EFI_OPTIONAL_POINTER, (VOID **) &DriverOsHandoff->DevicePath);\r | |
411 | RuntimeDriverConvertPointer (EFI_OPTIONAL_POINTER, (VOID **) &DriverOsHandoff->PciRomImage);\r | |
412 | }\r | |
413 | \r | |
414 | RuntimeDriverConvertPointer (EFI_OPTIONAL_POINTER, (VOID **) &(gST->ConfigurationTable[Index].VendorTable));\r | |
415 | }\r | |
3ec2611d | 416 | \r |
3ec2611d | 417 | if (CompareGuid (&gEfiCapsuleGuid, &(gST->ConfigurationTable[Index].VendorGuid))) {\r |
045f4521 | 418 | CapsuleTable = gST->ConfigurationTable[Index].VendorTable;\r |
419 | for (Index1 = 0; Index1 < CapsuleTable->CapsuleArrayNumber; Index1++) {\r | |
420 | RuntimeDriverConvertPointer (EFI_OPTIONAL_POINTER, (VOID **) &CapsuleTable->CapsulePtr[Index1]);\r | |
ce8bd86e | 421 | }\r |
045f4521 | 422 | RuntimeDriverConvertPointer (EFI_OPTIONAL_POINTER, (VOID **) &(gST->ConfigurationTable[Index].VendorTable));\r |
423 | }\r | |
878ddf1f | 424 | }\r |
425 | //\r | |
426 | // Convert the runtime fields of the EFI System Table and recompute the CRC-32\r | |
427 | //\r | |
428 | RuntimeDriverConvertInternalPointer ((VOID **) &gST->FirmwareVendor);\r | |
429 | RuntimeDriverConvertInternalPointer ((VOID **) &gST->ConfigurationTable);\r | |
430 | RuntimeDriverConvertInternalPointer ((VOID **) &gST->RuntimeServices);\r | |
431 | RuntimeDriverCalculateEfiHdrCrc (&gST->Hdr);\r | |
432 | \r | |
433 | //\r | |
434 | // At this point, gRT and gST are physical pointers, but the contents of these tables\r | |
435 | // have been converted to runtime.\r | |
436 | //\r | |
437 | //\r | |
438 | // mVirtualMap is only valid during SetVirtualAddressMap() call\r | |
439 | //\r | |
440 | mVirtualMap = NULL;\r | |
441 | \r | |
442 | return EFI_SUCCESS;\r | |
443 | }\r | |
444 | \r | |
445 | EFI_STATUS\r | |
446 | EFIAPI\r | |
447 | RuntimeDriverInitialize (\r | |
448 | IN EFI_HANDLE ImageHandle,\r | |
449 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
450 | )\r | |
451 | /*++\r | |
452 | \r | |
453 | Routine Description:\r | |
454 | Install Runtime AP. This code includes the EfiDriverLib, but it functions at\r | |
455 | RT in physical mode. The only Lib services are gBS, gRT, and the DEBUG and\r | |
456 | ASSERT macros (they do ReportStatusCode).\r | |
457 | \r | |
458 | Arguments:\r | |
459 | (Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT)\r | |
460 | \r | |
461 | Returns:\r | |
462 | \r | |
463 | EFI_SUCEESS - Runtime Driver Architectural Protocol Installed\r | |
464 | \r | |
465 | Other - Return value from gBS->InstallMultipleProtocolInterfaces\r | |
466 | \r | |
467 | --*/\r | |
468 | {\r | |
3ec2611d LG |
469 | EFI_STATUS Status;\r |
470 | EFI_LOADED_IMAGE_PROTOCOL *MyLoadedImage;\r | |
878ddf1f | 471 | \r |
472 | //\r | |
473 | // This image needs to be exclued from relocation for virtual mode, so cache\r | |
474 | // a copy of the Loaded Image protocol to test later.\r | |
475 | //\r | |
476 | Status = gBS->HandleProtocol (\r | |
477 | ImageHandle,\r | |
478 | &gEfiLoadedImageProtocolGuid,\r | |
ddb3d91c | 479 | (VOID**)&MyLoadedImage\r |
878ddf1f | 480 | );\r |
481 | ASSERT_EFI_ERROR (Status);\r | |
3ec2611d | 482 | mMyImageBase = MyLoadedImage->ImageBase;\r |
878ddf1f | 483 | \r |
484 | //\r | |
485 | // Initialize the table used to compute 32-bit CRCs\r | |
486 | //\r | |
487 | RuntimeDriverInitializeCrc32Table ();\r | |
488 | \r | |
489 | //\r | |
490 | // Fill in the entries of the EFI Boot Services and EFI Runtime Services Tables\r | |
491 | //\r | |
3ec2611d | 492 | gBS->CalculateCrc32 = RuntimeDriverCalculateCrc32;\r |
878ddf1f | 493 | gRT->SetVirtualAddressMap = RuntimeDriverSetVirtualAddressMap;\r |
494 | gRT->ConvertPointer = RuntimeDriverConvertPointer;\r | |
495 | \r | |
496 | //\r | |
497 | // Install the Runtime Architectural Protocol onto a new handle\r | |
498 | //\r | |
499 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
500 | &mRuntimeHandle,\r | |
501 | &gEfiRuntimeArchProtocolGuid,\r | |
502 | &mRuntime,\r | |
503 | NULL\r | |
504 | );\r | |
505 | ASSERT_EFI_ERROR (Status);\r | |
ce8bd86e | 506 | \r |
3ec2611d | 507 | return EFI_SUCCESS;\r |
878ddf1f | 508 | }\r |