| 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 |
EFIDebugVariable (); |
| 85 |
} |
| 86 |
|
| 87 |
// |
| 88 |
// Initialize Guid table |
| 89 |
// |
| 90 |
|
| 91 |
InitializeGuid(); |
| 92 |
|
| 93 |
InitializeLibPlatform(ImageHandle,SystemTable); |
| 94 |
} |
| 95 |
|
| 96 |
// |
| 97 |
// |
| 98 |
// |
| 99 |
|
| 100 |
if (ImageHandle && UnicodeInterface == &LibStubUnicodeInterface) { |
| 101 |
LangCode = LibGetVariable (VarLanguage, &EfiGlobalVariable); |
| 102 |
InitializeUnicodeSupport (LangCode); |
| 103 |
if (LangCode) { |
| 104 |
FreePool (LangCode); |
| 105 |
} |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
#define strlen(s1) __builtin_strlen(s1) |
| 110 |
|
| 111 |
VOID |
| 112 |
InitializeUnicodeSupport ( |
| 113 |
CHAR8 *LangCode |
| 114 |
) |
| 115 |
{ |
| 116 |
EFI_UNICODE_COLLATION_INTERFACE *Ui; |
| 117 |
EFI_STATUS Status; |
| 118 |
CHAR8 *Languages; |
| 119 |
UINTN Index, Position, Length; |
| 120 |
UINTN NoHandles; |
| 121 |
EFI_HANDLE *Handles; |
| 122 |
|
| 123 |
// |
| 124 |
// If we don't know it, lookup the current language code |
| 125 |
// |
| 126 |
|
| 127 |
LibLocateHandle (ByProtocol, &UnicodeCollationProtocol, NULL, &NoHandles, &Handles); |
| 128 |
if (!LangCode || !NoHandles) { |
| 129 |
goto Done; |
| 130 |
} |
| 131 |
|
| 132 |
// |
| 133 |
// Check all driver's for a matching language code |
| 134 |
// |
| 135 |
|
| 136 |
for (Index=0; Index < NoHandles; Index++) { |
| 137 |
Status = uefi_call_wrapper(BS->HandleProtocol, 3, Handles[Index], &UnicodeCollationProtocol, (VOID*)&Ui); |
| 138 |
if (EFI_ERROR(Status)) { |
| 139 |
continue; |
| 140 |
} |
| 141 |
|
| 142 |
// |
| 143 |
// Check for a matching language code |
| 144 |
// |
| 145 |
|
| 146 |
Languages = Ui->SupportedLanguages; |
| 147 |
Length = strlen(Languages); |
| 148 |
for (Position=0; Position < Length; Position += ISO_639_2_ENTRY_SIZE) { |
| 149 |
|
| 150 |
// |
| 151 |
// If this code matches, use this driver |
| 152 |
// |
| 153 |
|
| 154 |
if (CompareMem (Languages+Position, LangCode, ISO_639_2_ENTRY_SIZE) == 0) { |
| 155 |
UnicodeInterface = Ui; |
| 156 |
goto Done; |
| 157 |
} |
| 158 |
} |
| 159 |
} |
| 160 |
|
| 161 |
Done: |
| 162 |
// |
| 163 |
// Cleanup |
| 164 |
// |
| 165 |
|
| 166 |
if (Handles) { |
| 167 |
FreePool (Handles); |
| 168 |
} |
| 169 |
} |
| 170 |
|
| 171 |
VOID |
| 172 |
EFIDebugVariable ( |
| 173 |
VOID |
| 174 |
) |
| 175 |
{ |
| 176 |
EFI_STATUS Status; |
| 177 |
UINT32 Attributes; |
| 178 |
UINTN DataSize; |
| 179 |
UINTN NewEFIDebug; |
| 180 |
|
| 181 |
DataSize = sizeof(EFIDebug); |
| 182 |
Status = uefi_call_wrapper(RT->GetVariable, 5, L"EFIDebug", &EfiGlobalVariable, &Attributes, &DataSize, &NewEFIDebug); |
| 183 |
if (!EFI_ERROR(Status)) { |
| 184 |
EFIDebug = NewEFIDebug; |
| 185 |
} |
| 186 |
} |
| 187 |
|
| 188 |
/* |
| 189 |
* Calls to memset/memcpy may be emitted implicitly by GCC or MSVC |
| 190 |
* even when -ffreestanding or /NODEFAULTLIB are in effect. |
| 191 |
*/ |
| 192 |
|
| 193 |
#ifndef __SIZE_TYPE__ |
| 194 |
#define __SIZE_TYPE__ UINTN |
| 195 |
#endif |
| 196 |
|
| 197 |
void *memset(void *s, int c, __SIZE_TYPE__ n) |
| 198 |
{ |
| 199 |
unsigned char *p = s; |
| 200 |
|
| 201 |
while (n--) |
| 202 |
*p++ = c; |
| 203 |
|
| 204 |
return s; |
| 205 |
} |
| 206 |
|
| 207 |
void *memcpy(void *dest, const void *src, __SIZE_TYPE__ n) |
| 208 |
{ |
| 209 |
const unsigned char *q = src; |
| 210 |
unsigned char *p = dest; |
| 211 |
|
| 212 |
while (n--) |
| 213 |
*p++ = *q++; |
| 214 |
|
| 215 |
return dest; |
| 216 |
} |