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 |
|
---|
53 | //
|
---|
54 | // Set up global pointer to the system table, boot services table,
|
---|
55 | // and runtime services table
|
---|
56 | //
|
---|
57 |
|
---|
58 | ST = SystemTable;
|
---|
59 | BS = SystemTable->BootServices;
|
---|
60 | RT = SystemTable->RuntimeServices;
|
---|
61 | // ASSERT (CheckCrc(0, &ST->Hdr));
|
---|
62 | // ASSERT (CheckCrc(0, &BS->Hdr));
|
---|
63 | // ASSERT (CheckCrc(0, &RT->Hdr));
|
---|
64 |
|
---|
65 |
|
---|
66 | //
|
---|
67 | // Initialize pool allocation type
|
---|
68 | //
|
---|
69 |
|
---|
70 | if (ImageHandle) {
|
---|
71 | Status = BS->HandleProtocol (
|
---|
72 | ImageHandle,
|
---|
73 | &LoadedImageProtocol,
|
---|
74 | (VOID*)&LoadedImage
|
---|
75 | );
|
---|
76 |
|
---|
77 | if (!EFI_ERROR(Status)) {
|
---|
78 | PoolAllocationType = LoadedImage->ImageDataType;
|
---|
79 | }
|
---|
80 |
|
---|
81 | EFIDebugVariable ();
|
---|
82 | }
|
---|
83 |
|
---|
84 | //
|
---|
85 | // Initialize Guid table
|
---|
86 | //
|
---|
87 |
|
---|
88 | InitializeGuid();
|
---|
89 |
|
---|
90 | InitializeLibPlatform(ImageHandle,SystemTable);
|
---|
91 | }
|
---|
92 |
|
---|
93 | //
|
---|
94 | //
|
---|
95 | //
|
---|
96 |
|
---|
97 | if (ImageHandle && UnicodeInterface == &LibStubUnicodeInterface) {
|
---|
98 | LangCode = LibGetVariable (VarLanguage, &EfiGlobalVariable);
|
---|
99 | InitializeUnicodeSupport (LangCode);
|
---|
100 | if (LangCode) {
|
---|
101 | FreePool (LangCode);
|
---|
102 | }
|
---|
103 | }
|
---|
104 | }
|
---|
105 |
|
---|
106 | VOID
|
---|
107 | InitializeUnicodeSupport (
|
---|
108 | CHAR8 *LangCode
|
---|
109 | )
|
---|
110 | {
|
---|
111 | EFI_UNICODE_COLLATION_INTERFACE *Ui;
|
---|
112 | EFI_STATUS Status;
|
---|
113 | CHAR8 *Languages;
|
---|
114 | UINTN Index, Position, Length;
|
---|
115 | UINTN NoHandles;
|
---|
116 | EFI_HANDLE *Handles;
|
---|
117 |
|
---|
118 | //
|
---|
119 | // If we don't know it, lookup the current language code
|
---|
120 | //
|
---|
121 |
|
---|
122 | LibLocateHandle (ByProtocol, &UnicodeCollationProtocol, NULL, &NoHandles, &Handles);
|
---|
123 | if (!LangCode || !NoHandles) {
|
---|
124 | goto Done;
|
---|
125 | }
|
---|
126 |
|
---|
127 | //
|
---|
128 | // Check all driver's for a matching language code
|
---|
129 | //
|
---|
130 |
|
---|
131 | for (Index=0; Index < NoHandles; Index++) {
|
---|
132 | Status = BS->HandleProtocol (Handles[Index], &UnicodeCollationProtocol, (VOID*)&Ui);
|
---|
133 | if (EFI_ERROR(Status)) {
|
---|
134 | continue;
|
---|
135 | }
|
---|
136 |
|
---|
137 | //
|
---|
138 | // Check for a matching language code
|
---|
139 | //
|
---|
140 |
|
---|
141 | Languages = Ui->SupportedLanguages;
|
---|
142 | Length = strlena(Languages);
|
---|
143 | for (Position=0; Position < Length; Position += ISO_639_2_ENTRY_SIZE) {
|
---|
144 |
|
---|
145 | //
|
---|
146 | // If this code matches, use this driver
|
---|
147 | //
|
---|
148 |
|
---|
149 | if (CompareMem (Languages+Position, LangCode, ISO_639_2_ENTRY_SIZE) == 0) {
|
---|
150 | UnicodeInterface = Ui;
|
---|
151 | goto Done;
|
---|
152 | }
|
---|
153 | }
|
---|
154 | }
|
---|
155 |
|
---|
156 | Done:
|
---|
157 | //
|
---|
158 | // Cleanup
|
---|
159 | //
|
---|
160 |
|
---|
161 | if (Handles) {
|
---|
162 | FreePool (Handles);
|
---|
163 | }
|
---|
164 | }
|
---|
165 |
|
---|
166 | VOID
|
---|
167 | EFIDebugVariable (
|
---|
168 | VOID
|
---|
169 | )
|
---|
170 | {
|
---|
171 | EFI_STATUS Status;
|
---|
172 | UINT32 Attributes;
|
---|
173 | UINTN DataSize;
|
---|
174 | UINTN NewEFIDebug;
|
---|
175 |
|
---|
176 | DataSize = sizeof(EFIDebug);
|
---|
177 | Status = RT->GetVariable(L"EFIDebug", &EfiGlobalVariable, &Attributes, &DataSize, &NewEFIDebug);
|
---|
178 | if (!EFI_ERROR(Status)) {
|
---|
179 | EFIDebug = NewEFIDebug;
|
---|
180 | }
|
---|
181 | }
|
---|