1 /*++ 2 3 Copyright (c) 1998 Intel Corporation 4 5 Module Name: 6 7 8 Abstract: 9 10 11 12 13 Revision History 14 15 --*/ 16 17 #include "lib.h" 18 19 VOID 20 EFIDebugVariable ( 21 VOID 22 ); 23 24 VOID 25 InitializeLib ( 26 IN EFI_HANDLE ImageHandle, 27 IN EFI_SYSTEM_TABLE *SystemTable 28 ) 29 /*++ 30 31 Routine Description: 32 33 Initializes EFI library for use 34 35 Arguments: 36 37 Firmware's EFI system table 38 39 Returns: 40 41 None 42 43 --*/ 44 { 45 EFI_LOADED_IMAGE *LoadedImage; 46 EFI_STATUS Status; 47 CHAR8 *LangCode; 48 49 if (!LibInitialized) { 50 LibInitialized = TRUE; 51 LibFwInstance = FALSE; 52 LibImageHandle = ImageHandle; 53 54 55 // 56 // Set up global pointer to the system table, boot services table, 57 // and runtime services table 58 // 59 60 ST = SystemTable; 61 BS = SystemTable->BootServices; 62 RT = SystemTable->RuntimeServices; 63 // ASSERT (CheckCrc(0, &ST->Hdr)); 64 // ASSERT (CheckCrc(0, &BS->Hdr)); 65 // ASSERT (CheckCrc(0, &RT->Hdr)); 66 67 68 // 69 // Initialize pool allocation type 70 // 71 72 if (ImageHandle) { 73 Status = uefi_call_wrapper( 74 BS->HandleProtocol, 75 3, 76 ImageHandle, 77 &LoadedImageProtocol, 78 (VOID*)&LoadedImage 79 ); 80 81 if (!EFI_ERROR(Status)) { 82 PoolAllocationType = LoadedImage->ImageDataType; 83 } 84 85 EFIDebugVariable (); 86 } 87 88 // 89 // Initialize Guid table 90 // 91 92 InitializeGuid(); 93 94 InitializeLibPlatform(ImageHandle,SystemTable); 95 } 96 97 // 98 // 99 // 100 101 if (ImageHandle && UnicodeInterface == &LibStubUnicodeInterface) { 102 LangCode = LibGetVariable (VarLanguage, &EfiGlobalVariable); 103 InitializeUnicodeSupport (LangCode); 104 if (LangCode) { 105 FreePool (LangCode); 106 } 107 } 108 } 109 110 VOID 111 InitializeUnicodeSupport ( 112 CHAR8 *LangCode 113 ) 114 { 115 EFI_UNICODE_COLLATION_INTERFACE *Ui; 116 EFI_STATUS Status; 117 CHAR8 *Languages; 118 UINTN Index, Position, Length; 119 UINTN NoHandles; 120 EFI_HANDLE *Handles; 121 122 // 123 // If we don't know it, lookup the current language code 124 // 125 126 LibLocateHandle (ByProtocol, &UnicodeCollationProtocol, NULL, &NoHandles, &Handles); 127 if (!LangCode || !NoHandles) { 128 goto Done; 129 } 130 131 // 132 // Check all driver's for a matching language code 133 // 134 135 for (Index=0; Index < NoHandles; Index++) { 136 Status = uefi_call_wrapper(BS->HandleProtocol, 3, Handles[Index], &UnicodeCollationProtocol, (VOID*)&Ui); 137 if (EFI_ERROR(Status)) { 138 continue; 139 } 140 141 // 142 // Check for a matching language code 143 // 144 145 Languages = Ui->SupportedLanguages; 146 Length = strlena(Languages); 147 for (Position=0; Position < Length; Position += ISO_639_2_ENTRY_SIZE) { 148 149 // 150 // If this code matches, use this driver 151 // 152 153 if (CompareMem (Languages+Position, LangCode, ISO_639_2_ENTRY_SIZE) == 0) { 154 UnicodeInterface = Ui; 155 goto Done; 156 } 157 } 158 } 159 160 Done: 161 // 162 // Cleanup 163 // 164 165 if (Handles) { 166 FreePool (Handles); 167 } 168 } 169 170 VOID 171 EFIDebugVariable ( 172 VOID 173 ) 174 { 175 EFI_STATUS Status; 176 UINT32 Attributes; 177 UINTN DataSize; 178 UINTN NewEFIDebug; 179 180 DataSize = sizeof(EFIDebug); 181 Status = uefi_call_wrapper(RT->GetVariable, 5, L"EFIDebug", &EfiGlobalVariable, &Attributes, &DataSize, &NewEFIDebug); 182 if (!EFI_ERROR(Status)) { 183 EFIDebug = NewEFIDebug; 184 } 185 } 186