Subversion Repositories HelenOS

Rev

Rev 2726 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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