1 /* $NetBSD: vm.c,v 1.1.1.1 2014/04/01 16:16:07 jakllsch Exp $ */ 2 3 /*++ 4 5 Copyright (c) 1998 Intel Corporation 6 7 Module Name: 8 9 vm.c 10 11 Abstract: 12 13 EFI Hell to remap runtime address into the new virual address space 14 that was registered by the OS for RT calls. 15 16 So the code image needs to be relocated. All pointers need to be 17 manually fixed up since the address map changes. 18 19 GOOD LUCK NOT HAVING BUGS IN YOUR CODE! PLEASE TEST A LOT. MAKE SURE 20 EXIT BOOTSERVICES OVER WRITES ALL BOOTSERVICE MEMORY & DATA SPACES WHEN 21 YOU TEST. 22 23 Revision History 24 25 --*/ 26 27 #include "lib.h" 28 29 #ifndef __GNUC__ 30 #pragma RUNTIME_CODE(RtLibEnableVirtualMappings) 31 #endif 32 VOID 33 RUNTIMEFUNCTION 34 RtLibEnableVirtualMappings ( 35 VOID 36 ) 37 { 38 EFI_CONVERT_POINTER ConvertPointer; 39 40 // 41 // If this copy of the lib is linked into the firmware, then 42 // do not update the pointers yet. 43 // 44 45 if (!LibFwInstance) { 46 47 // 48 // Different components are updating to the new virtual 49 // mappings at differnt times. The only function that 50 // is safe to call at this notification is ConvertAddress 51 // 52 53 ConvertPointer = RT->ConvertPointer; 54 55 // 56 // Fix any pointers that the lib created, that may be needed 57 // during runtime. 58 // 59 60 ConvertPointer (EFI_INTERNAL_PTR, (VOID **)&RT); 61 ConvertPointer (EFI_OPTIONAL_PTR, (VOID **)&LibRuntimeDebugOut); 62 63 ConvertPointer (EFI_INTERNAL_PTR, (VOID **)&LibRuntimeRaiseTPL); 64 ConvertPointer (EFI_INTERNAL_PTR, (VOID **)&LibRuntimeRestoreTPL); 65 66 // that was it :^) 67 } 68 } 69 70 71 #ifndef __GNUC__ 72 #pragma RUNTIME_CODE(RtConvertList) 73 #endif 74 VOID 75 RUNTIMEFUNCTION 76 RtConvertList ( 77 IN UINTN DebugDisposition, 78 IN OUT LIST_ENTRY *ListHead 79 ) 80 { 81 LIST_ENTRY *Link; 82 LIST_ENTRY *NextLink; 83 EFI_CONVERT_POINTER ConvertPointer; 84 85 ConvertPointer = RT->ConvertPointer; 86 87 // 88 // Convert all the Flink & Blink pointers in the list 89 // 90 91 Link = ListHead; 92 do { 93 NextLink = Link->Flink; 94 95 ConvertPointer ( 96 Link->Flink == ListHead ? DebugDisposition : 0, 97 (VOID **)&Link->Flink 98 ); 99 100 ConvertPointer ( 101 Link->Blink == ListHead ? DebugDisposition : 0, 102 (VOID **)&Link->Blink 103 ); 104 105 Link = NextLink; 106 } while (Link != ListHead); 107 } 108