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