Subversion Repositories HelenOS

Rev

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

Rev 2726 Rev 3386
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
    misc.c
7
    misc.c
8
 
8
 
9
Abstract:
9
Abstract:
10
 
10
 
11
 
11
 
12
 
12
 
13
 
13
 
14
Revision History
14
Revision History
15
 
15
 
16
--*/
16
--*/
17
 
17
 
18
#include "lib.h"
18
#include "lib.h"
19
 
19
 
20
 
20
 
21
//
21
//
22
//
22
//
23
//
23
//
24
 
24
 
25
VOID *
25
VOID *
26
AllocatePool (
26
AllocatePool (
27
    IN UINTN                Size
27
    IN UINTN                Size
28
    )
28
    )
29
{
29
{
30
    EFI_STATUS              Status;
30
    EFI_STATUS              Status;
31
    VOID                    *p;
31
    VOID                    *p;
32
 
32
 
33
    Status = BS->AllocatePool (PoolAllocationType, Size, &p);
33
    Status = BS->AllocatePool (PoolAllocationType, Size, &p);
34
    if (EFI_ERROR(Status)) {
34
    if (EFI_ERROR(Status)) {
35
        DEBUG((D_ERROR, "AllocatePool: out of pool  %x\n", Status));
35
        DEBUG((D_ERROR, "AllocatePool: out of pool  %x\n", Status));
36
        p = NULL;
36
        p = NULL;
37
    }
37
    }
38
    return p;
38
    return p;
39
}
39
}
40
 
40
 
41
VOID *
41
VOID *
42
AllocateZeroPool (
42
AllocateZeroPool (
43
    IN UINTN                Size
43
    IN UINTN                Size
44
    )
44
    )
45
{
45
{
46
    VOID                    *p;
46
    VOID                    *p;
47
 
47
 
48
    p = AllocatePool (Size);
48
    p = AllocatePool (Size);
49
    if (p) {
49
    if (p) {
50
        ZeroMem (p, Size);
50
        ZeroMem (p, Size);
51
    }
51
    }
52
 
52
 
53
    return p;
53
    return p;
54
}
54
}
55
 
55
 
56
VOID *
56
VOID *
57
ReallocatePool (
57
ReallocatePool (
58
    IN VOID                 *OldPool,
58
    IN VOID                 *OldPool,
59
    IN UINTN                OldSize,
59
    IN UINTN                OldSize,
60
    IN UINTN                NewSize
60
    IN UINTN                NewSize
61
    )
61
    )
62
{
62
{
63
    VOID                    *NewPool;
63
    VOID                    *NewPool;
64
 
64
 
65
    NewPool = NULL;
65
    NewPool = NULL;
66
    if (NewSize) {
66
    if (NewSize) {
67
        NewPool = AllocatePool (NewSize);
67
        NewPool = AllocatePool (NewSize);
68
    }
68
    }
69
 
69
 
70
    if (OldPool) {
70
    if (OldPool) {
71
        if (NewPool) {
71
        if (NewPool) {
72
            CopyMem (NewPool, OldPool, OldSize < NewSize ? OldSize : NewSize);
72
            CopyMem (NewPool, OldPool, OldSize < NewSize ? OldSize : NewSize);
73
        }
73
        }
74
   
74
   
75
        FreePool (OldPool);
75
        FreePool (OldPool);
76
    }
76
    }
77
   
77
   
78
    return NewPool;
78
    return NewPool;
79
}
79
}
80
 
80
 
81
 
81
 
82
VOID
82
VOID
83
FreePool (
83
FreePool (
84
    IN VOID                 *Buffer
84
    IN VOID                 *Buffer
85
    )
85
    )
86
{
86
{
87
    BS->FreePool (Buffer);
87
    BS->FreePool (Buffer);
88
}
88
}
89
 
89
 
90
 
90
 
91
 
91
 
92
VOID
92
VOID
93
ZeroMem (
93
ZeroMem (
94
    IN VOID     *Buffer,
94
    IN VOID     *Buffer,
95
    IN UINTN    Size
95
    IN UINTN    Size
96
    )
96
    )
97
{
97
{
98
    RtZeroMem (Buffer, Size);
98
    RtZeroMem (Buffer, Size);
99
}
99
}
100
 
100
 
101
VOID
101
VOID
102
SetMem (
102
SetMem (
103
    IN VOID     *Buffer,
103
    IN VOID     *Buffer,
104
    IN UINTN    Size,
104
    IN UINTN    Size,
105
    IN UINT8    Value    
105
    IN UINT8    Value    
106
    )
106
    )
107
{
107
{
108
    RtSetMem (Buffer, Size, Value);
108
    RtSetMem (Buffer, Size, Value);
109
}
109
}
110
 
110
 
111
VOID
111
VOID
112
CopyMem (
112
CopyMem (
113
    IN VOID     *Dest,
113
    IN VOID     *Dest,
114
    IN VOID     *Src,
114
    IN VOID     *Src,
115
    IN UINTN    len
115
    IN UINTN    len
116
    )
116
    )
117
{
117
{
118
    RtCopyMem (Dest, Src, len);
118
    RtCopyMem (Dest, Src, len);
119
}
119
}
120
 
120
 
121
INTN
121
INTN
122
CompareMem (
122
CompareMem (
123
    IN VOID     *Dest,
123
    IN VOID     *Dest,
124
    IN VOID     *Src,
124
    IN VOID     *Src,
125
    IN UINTN    len
125
    IN UINTN    len
126
    )
126
    )
127
{
127
{
128
    return RtCompareMem (Dest, Src, len);
128
    return RtCompareMem (Dest, Src, len);
129
}
129
}
130
 
130
 
131
BOOLEAN
131
BOOLEAN
132
GrowBuffer(
132
GrowBuffer(
133
    IN OUT EFI_STATUS   *Status,
133
    IN OUT EFI_STATUS   *Status,
134
    IN OUT VOID         **Buffer,
134
    IN OUT VOID         **Buffer,
135
    IN UINTN            BufferSize
135
    IN UINTN            BufferSize
136
    )
136
    )
137
/*++
137
/*++
138
 
138
 
139
Routine Description:
139
Routine Description:
140
 
140
 
141
    Helper function called as part of the code needed
141
    Helper function called as part of the code needed
142
    to allocate the proper sized buffer for various
142
    to allocate the proper sized buffer for various
143
    EFI interfaces.
143
    EFI interfaces.
144
 
144
 
145
Arguments:
145
Arguments:
146
 
146
 
147
    Status      - Current status
147
    Status      - Current status
148
 
148
 
149
    Buffer      - Current allocated buffer, or NULL
149
    Buffer      - Current allocated buffer, or NULL
150
 
150
 
151
    BufferSize  - Current buffer size needed
151
    BufferSize  - Current buffer size needed
152
   
152
   
153
Returns:
153
Returns:
154
   
154
   
155
    TRUE - if the buffer was reallocated and the caller
155
    TRUE - if the buffer was reallocated and the caller
156
    should try the API again.
156
    should try the API again.
157
 
157
 
158
--*/
158
--*/
159
{
159
{
160
    BOOLEAN         TryAgain;
160
    BOOLEAN         TryAgain;
161
 
161
 
162
    //
162
    //
163
    // If this is an initial request, buffer will be null with a new buffer size
163
    // If this is an initial request, buffer will be null with a new buffer size
164
    //
164
    //
165
 
165
 
166
    if (!*Buffer && BufferSize) {
166
    if (!*Buffer && BufferSize) {
167
        *Status = EFI_BUFFER_TOO_SMALL;
167
        *Status = EFI_BUFFER_TOO_SMALL;
168
    }
168
    }
169
 
169
 
170
    //
170
    //
171
    // If the status code is "buffer too small", resize the buffer
171
    // If the status code is "buffer too small", resize the buffer
172
    //
172
    //
173
       
173
       
174
    TryAgain = FALSE;
174
    TryAgain = FALSE;
175
    if (*Status == EFI_BUFFER_TOO_SMALL) {
175
    if (*Status == EFI_BUFFER_TOO_SMALL) {
176
 
176
 
177
        if (*Buffer) {
177
        if (*Buffer) {
178
            FreePool (*Buffer);
178
            FreePool (*Buffer);
179
        }
179
        }
180
 
180
 
181
        *Buffer = AllocatePool (BufferSize);
181
        *Buffer = AllocatePool (BufferSize);
182
 
182
 
183
        if (*Buffer) {
183
        if (*Buffer) {
184
            TryAgain = TRUE;
184
            TryAgain = TRUE;
185
        } else {    
185
        } else {    
186
            *Status = EFI_OUT_OF_RESOURCES;
186
            *Status = EFI_OUT_OF_RESOURCES;
187
        }
187
        }
188
    }
188
    }
189
 
189
 
190
    //
190
    //
191
    // If there's an error, free the buffer
191
    // If there's an error, free the buffer
192
    //
192
    //
193
 
193
 
194
    if (!TryAgain && EFI_ERROR(*Status) && *Buffer) {
194
    if (!TryAgain && EFI_ERROR(*Status) && *Buffer) {
195
        FreePool (*Buffer);
195
        FreePool (*Buffer);
196
        *Buffer = NULL;
196
        *Buffer = NULL;
197
    }
197
    }
198
 
198
 
199
    return TryAgain;
199
    return TryAgain;
200
}
200
}
201
 
201
 
202
 
202
 
203
EFI_MEMORY_DESCRIPTOR *
203
EFI_MEMORY_DESCRIPTOR *
204
LibMemoryMap (
204
LibMemoryMap (
205
    OUT UINTN               *NoEntries,
205
    OUT UINTN               *NoEntries,
206
    OUT UINTN               *MapKey,
206
    OUT UINTN               *MapKey,
207
    OUT UINTN               *DescriptorSize,
207
    OUT UINTN               *DescriptorSize,
208
    OUT UINT32              *DescriptorVersion
208
    OUT UINT32              *DescriptorVersion
209
    )
209
    )
210
{
210
{
211
    EFI_STATUS              Status;
211
    EFI_STATUS              Status;
212
    EFI_MEMORY_DESCRIPTOR   *Buffer;
212
    EFI_MEMORY_DESCRIPTOR   *Buffer;
213
    UINTN                   BufferSize;
213
    UINTN                   BufferSize;
214
 
214
 
215
    //
215
    //
216
    // Initialize for GrowBuffer loop
216
    // Initialize for GrowBuffer loop
217
    //
217
    //
218
 
218
 
219
    Buffer = NULL;
219
    Buffer = NULL;
220
    BufferSize = sizeof(EFI_MEMORY_DESCRIPTOR);
220
    BufferSize = sizeof(EFI_MEMORY_DESCRIPTOR);
221
 
221
 
222
    //
222
    //
223
    // Call the real function
223
    // Call the real function
224
    //
224
    //
225
 
225
 
226
    while (GrowBuffer (&Status, (VOID **) &Buffer, BufferSize)) {
226
    while (GrowBuffer (&Status, (VOID **) &Buffer, BufferSize)) {
227
        Status = BS->GetMemoryMap (&BufferSize, Buffer, MapKey, DescriptorSize, DescriptorVersion);
227
        Status = BS->GetMemoryMap (&BufferSize, Buffer, MapKey, DescriptorSize, DescriptorVersion);
228
    }
228
    }
229
 
229
 
230
    //
230
    //
231
    // Convert buffer size to NoEntries
231
    // Convert buffer size to NoEntries
232
    //
232
    //
233
 
233
 
234
    if (!EFI_ERROR(Status)) {
234
    if (!EFI_ERROR(Status)) {
235
        *NoEntries = BufferSize / *DescriptorSize;
235
        *NoEntries = BufferSize / *DescriptorSize;
236
    }
236
    }
237
 
237
 
238
    return Buffer;
238
    return Buffer;
239
}
239
}
240
 
240
 
241
VOID *
241
VOID *
242
LibGetVariableAndSize (
242
LibGetVariableAndSize (
243
    IN CHAR16               *Name,
243
    IN CHAR16               *Name,
244
    IN EFI_GUID             *VendorGuid,
244
    IN EFI_GUID             *VendorGuid,
245
    OUT UINTN               *VarSize
245
    OUT UINTN               *VarSize
246
    )
246
    )
247
{
247
{
248
    EFI_STATUS              Status;
248
    EFI_STATUS              Status;
249
    VOID                    *Buffer;
249
    VOID                    *Buffer;
250
    UINTN                   BufferSize;
250
    UINTN                   BufferSize;
251
 
251
 
252
    //
252
    //
253
    // Initialize for GrowBuffer loop
253
    // Initialize for GrowBuffer loop
254
    //
254
    //
255
 
255
 
256
    Buffer = NULL;
256
    Buffer = NULL;
257
    BufferSize = 100;
257
    BufferSize = 100;
258
 
258
 
259
    //
259
    //
260
    // Call the real function
260
    // Call the real function
261
    //
261
    //
262
 
262
 
263
    while (GrowBuffer (&Status, &Buffer, BufferSize)) {
263
    while (GrowBuffer (&Status, &Buffer, BufferSize)) {
264
        Status = RT->GetVariable (
264
        Status = RT->GetVariable (
265
                    Name,
265
                    Name,
266
                    VendorGuid,
266
                    VendorGuid,
267
                    NULL,
267
                    NULL,
268
                    &BufferSize,
268
                    &BufferSize,
269
                    Buffer
269
                    Buffer
270
                    );
270
                    );
271
    }
271
    }
272
    if (Buffer) {
272
    if (Buffer) {
273
        *VarSize = BufferSize;
273
        *VarSize = BufferSize;
274
    } else {
274
    } else {
275
        *VarSize = 0;
275
        *VarSize = 0;
276
    }
276
    }
277
    return Buffer;
277
    return Buffer;
278
}
278
}
279
   
279
   
280
VOID *
280
VOID *
281
LibGetVariable (
281
LibGetVariable (
282
    IN CHAR16               *Name,
282
    IN CHAR16               *Name,
283
    IN EFI_GUID             *VendorGuid
283
    IN EFI_GUID             *VendorGuid
284
    )
284
    )
285
{
285
{
286
    UINTN   VarSize;
286
    UINTN   VarSize;
287
 
287
 
288
    return LibGetVariableAndSize (Name, VendorGuid, &VarSize);
288
    return LibGetVariableAndSize (Name, VendorGuid, &VarSize);
289
}
289
}
290
 
290
 
291
EFI_STATUS
291
EFI_STATUS
292
LibDeleteVariable (
292
LibDeleteVariable (
293
    IN CHAR16   *VarName,
293
    IN CHAR16   *VarName,
294
    IN EFI_GUID *VarGuid
294
    IN EFI_GUID *VarGuid
295
    )
295
    )
296
{
296
{
297
    VOID        *VarBuf;
297
    VOID        *VarBuf;
298
    EFI_STATUS  Status;
298
    EFI_STATUS  Status;
299
 
299
 
300
    VarBuf = LibGetVariable(VarName,VarGuid);
300
    VarBuf = LibGetVariable(VarName,VarGuid);
301
 
301
 
302
    Status = EFI_NOT_FOUND;
302
    Status = EFI_NOT_FOUND;
303
 
303
 
304
    if (VarBuf) {
304
    if (VarBuf) {
305
        //
305
        //
306
        // Delete variable from Storage
306
        // Delete variable from Storage
307
        //
307
        //
308
        Status = RT->SetVariable (
308
        Status = RT->SetVariable (
309
                    VarName, VarGuid,
309
                    VarName, VarGuid,
310
                    EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
310
                    EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
311
                    0, NULL
311
                    0, NULL
312
                 );
312
                 );
313
        ASSERT (!EFI_ERROR(Status));
313
        ASSERT (!EFI_ERROR(Status));
314
        FreePool(VarBuf);
314
        FreePool(VarBuf);
315
    }
315
    }
316
 
316
 
317
    return (Status);
317
    return (Status);
318
}
318
}
319
 
319
 
320
EFI_STATUS
320
EFI_STATUS
321
LibInsertToTailOfBootOrder (
321
LibInsertToTailOfBootOrder (
322
    IN  UINT16  BootOption,
322
    IN  UINT16  BootOption,
323
    IN  BOOLEAN OnlyInsertIfEmpty
323
    IN  BOOLEAN OnlyInsertIfEmpty
324
    )
324
    )
325
{
325
{
326
    UINT16      *BootOptionArray;
326
    UINT16      *BootOptionArray;
327
    UINT16      *NewBootOptionArray;
327
    UINT16      *NewBootOptionArray;
328
    UINTN       VarSize;
328
    UINTN       VarSize;
329
    UINTN       Index;
329
    UINTN       Index;
330
    EFI_STATUS  Status;
330
    EFI_STATUS  Status;
331
 
331
 
332
    BootOptionArray = LibGetVariableAndSize (VarBootOrder, &EfiGlobalVariable, &VarSize);    
332
    BootOptionArray = LibGetVariableAndSize (VarBootOrder, &EfiGlobalVariable, &VarSize);    
333
    if (VarSize != 0 && OnlyInsertIfEmpty) {
333
    if (VarSize != 0 && OnlyInsertIfEmpty) {
334
        if (BootOptionArray) {
334
        if (BootOptionArray) {
335
            FreePool (BootOptionArray);
335
            FreePool (BootOptionArray);
336
        }
336
        }
337
        return EFI_UNSUPPORTED;
337
        return EFI_UNSUPPORTED;
338
    }
338
    }
339
 
339
 
340
    VarSize += sizeof(UINT16);
340
    VarSize += sizeof(UINT16);
341
    NewBootOptionArray = AllocatePool (VarSize);
341
    NewBootOptionArray = AllocatePool (VarSize);
342
   
342
   
343
    for (Index = 0; Index < ((VarSize/sizeof(UINT16)) - 1); Index++) {
343
    for (Index = 0; Index < ((VarSize/sizeof(UINT16)) - 1); Index++) {
344
        NewBootOptionArray[Index] = BootOptionArray[Index];
344
        NewBootOptionArray[Index] = BootOptionArray[Index];
345
    }
345
    }
346
    //
346
    //
347
    // Insert in the tail of the array
347
    // Insert in the tail of the array
348
    //
348
    //
349
    NewBootOptionArray[Index] = BootOption;
349
    NewBootOptionArray[Index] = BootOption;
350
 
350
 
351
    Status = RT->SetVariable (
351
    Status = RT->SetVariable (
352
                VarBootOrder, &EfiGlobalVariable,
352
                VarBootOrder, &EfiGlobalVariable,
353
                EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
353
                EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
354
                VarSize, (VOID*) NewBootOptionArray
354
                VarSize, (VOID*) NewBootOptionArray
355
                );
355
                );
356
 
356
 
357
    if (NewBootOptionArray) {
357
    if (NewBootOptionArray) {
358
        FreePool (NewBootOptionArray);
358
        FreePool (NewBootOptionArray);
359
    }
359
    }
360
    if (BootOptionArray) {
360
    if (BootOptionArray) {
361
        FreePool (BootOptionArray);
361
        FreePool (BootOptionArray);
362
    }
362
    }
363
    return Status;
363
    return Status;
364
}
364
}
365
 
365
 
366
 
366
 
367
BOOLEAN
367
BOOLEAN
368
ValidMBR(
368
ValidMBR(
369
    IN  MASTER_BOOT_RECORD  *Mbr,
369
    IN  MASTER_BOOT_RECORD  *Mbr,
370
    IN  EFI_BLOCK_IO        *BlkIo
370
    IN  EFI_BLOCK_IO        *BlkIo
371
    )
371
    )
372
{
372
{
373
    UINT32      StartingLBA, EndingLBA;
373
    UINT32      StartingLBA, EndingLBA;
374
    UINT32      NewEndingLBA;
374
    UINT32      NewEndingLBA;
375
    INTN        i, j;
375
    INTN        i, j;
376
    BOOLEAN     ValidMbr;
376
    BOOLEAN     ValidMbr;
377
 
377
 
378
    if (Mbr->Signature != MBR_SIGNATURE) {
378
    if (Mbr->Signature != MBR_SIGNATURE) {
379
        //
379
        //
380
        // The BPB also has this signature, so it can not be used alone.
380
        // The BPB also has this signature, so it can not be used alone.
381
        //
381
        //
382
        return FALSE;
382
        return FALSE;
383
    }
383
    }
384
 
384
 
385
    ValidMbr = FALSE;
385
    ValidMbr = FALSE;
386
    for (i=0; i<MAX_MBR_PARTITIONS; i++) {
386
    for (i=0; i<MAX_MBR_PARTITIONS; i++) {
387
        if ( Mbr->Partition[i].OSIndicator == 0x00 || EXTRACT_UINT32(Mbr->Partition[i].SizeInLBA) == 0 ) {
387
        if ( Mbr->Partition[i].OSIndicator == 0x00 || EXTRACT_UINT32(Mbr->Partition[i].SizeInLBA) == 0 ) {
388
            continue;
388
            continue;
389
        }
389
        }
390
        ValidMbr = TRUE;
390
        ValidMbr = TRUE;
391
        StartingLBA = EXTRACT_UINT32(Mbr->Partition[i].StartingLBA);
391
        StartingLBA = EXTRACT_UINT32(Mbr->Partition[i].StartingLBA);
392
        EndingLBA = StartingLBA + EXTRACT_UINT32(Mbr->Partition[i].SizeInLBA) - 1;
392
        EndingLBA = StartingLBA + EXTRACT_UINT32(Mbr->Partition[i].SizeInLBA) - 1;
393
        if (EndingLBA > BlkIo->Media->LastBlock) {
393
        if (EndingLBA > BlkIo->Media->LastBlock) {
394
            //
394
            //
395
            // Compatability Errata:
395
            // Compatability Errata:
396
            //  Some systems try to hide drive space with thier INT 13h driver
396
            //  Some systems try to hide drive space with thier INT 13h driver
397
            //  This does not hide space from the OS driver. This means the MBR
397
            //  This does not hide space from the OS driver. This means the MBR
398
            //  that gets created from DOS is smaller than the MBR created from 
398
            //  that gets created from DOS is smaller than the MBR created from 
399
            //  a real OS (NT & Win98). This leads to BlkIo->LastBlock being 
399
            //  a real OS (NT & Win98). This leads to BlkIo->LastBlock being 
400
            //  wrong on some systems FDISKed by the OS.
400
            //  wrong on some systems FDISKed by the OS.
401
            //
401
            //
402
            //
402
            //
403
            if (BlkIo->Media->LastBlock < MIN_MBR_DEVICE_SIZE) {
403
            if (BlkIo->Media->LastBlock < MIN_MBR_DEVICE_SIZE) {
404
                //
404
                //
405
                // If this is a very small device then trust the BlkIo->LastBlock
405
                // If this is a very small device then trust the BlkIo->LastBlock
406
                //
406
                //
407
                return FALSE;
407
                return FALSE;
408
            }
408
            }
409
 
409
 
410
            if (EndingLBA > (BlkIo->Media->LastBlock + MBR_ERRATA_PAD)) {
410
            if (EndingLBA > (BlkIo->Media->LastBlock + MBR_ERRATA_PAD)) {
411
                return FALSE;
411
                return FALSE;
412
            }
412
            }
413
 
413
 
414
        }
414
        }
415
        for (j=i+1; j<MAX_MBR_PARTITIONS; j++) {
415
        for (j=i+1; j<MAX_MBR_PARTITIONS; j++) {
416
            if (Mbr->Partition[j].OSIndicator == 0x00 || EXTRACT_UINT32(Mbr->Partition[j].SizeInLBA) == 0) {
416
            if (Mbr->Partition[j].OSIndicator == 0x00 || EXTRACT_UINT32(Mbr->Partition[j].SizeInLBA) == 0) {
417
                continue;
417
                continue;
418
            }
418
            }
419
            if (   EXTRACT_UINT32(Mbr->Partition[j].StartingLBA) >= StartingLBA &&
419
            if (   EXTRACT_UINT32(Mbr->Partition[j].StartingLBA) >= StartingLBA &&
420
                   EXTRACT_UINT32(Mbr->Partition[j].StartingLBA) <= EndingLBA       ) {
420
                   EXTRACT_UINT32(Mbr->Partition[j].StartingLBA) <= EndingLBA       ) {
421
                //
421
                //
422
                // The Start of this region overlaps with the i'th region
422
                // The Start of this region overlaps with the i'th region
423
                //
423
                //
424
                return FALSE;
424
                return FALSE;
425
            }
425
            }
426
            NewEndingLBA = EXTRACT_UINT32(Mbr->Partition[j].StartingLBA) + EXTRACT_UINT32(Mbr->Partition[j].SizeInLBA) - 1;
426
            NewEndingLBA = EXTRACT_UINT32(Mbr->Partition[j].StartingLBA) + EXTRACT_UINT32(Mbr->Partition[j].SizeInLBA) - 1;
427
            if ( NewEndingLBA >= StartingLBA && NewEndingLBA <= EndingLBA ) {
427
            if ( NewEndingLBA >= StartingLBA && NewEndingLBA <= EndingLBA ) {
428
                //
428
                //
429
                // The End of this region overlaps with the i'th region
429
                // The End of this region overlaps with the i'th region
430
                //
430
                //
431
                return FALSE;
431
                return FALSE;
432
            }
432
            }
433
        }
433
        }
434
    }
434
    }
435
    //
435
    //
436
    // Non of the regions overlapped so MBR is O.K.
436
    // Non of the regions overlapped so MBR is O.K.
437
    //
437
    //
438
    return ValidMbr;
438
    return ValidMbr;
439
}
439
}
440
   
440
   
441
 
441
 
442
UINT8
442
UINT8
443
DecimaltoBCD(
443
DecimaltoBCD(
444
    IN  UINT8 DecValue
444
    IN  UINT8 DecValue
445
    )
445
    )
446
{
446
{
447
    return RtDecimaltoBCD (DecValue);
447
    return RtDecimaltoBCD (DecValue);
448
}
448
}
449
 
449
 
450
 
450
 
451
UINT8
451
UINT8
452
BCDtoDecimal(
452
BCDtoDecimal(
453
    IN  UINT8 BcdValue
453
    IN  UINT8 BcdValue
454
    )
454
    )
455
{
455
{
456
    return RtBCDtoDecimal (BcdValue);
456
    return RtBCDtoDecimal (BcdValue);
457
}
457
}
458
 
458
 
459
EFI_STATUS
459
EFI_STATUS
460
LibGetSystemConfigurationTable(
460
LibGetSystemConfigurationTable(
461
    IN EFI_GUID *TableGuid,
461
    IN EFI_GUID *TableGuid,
462
    IN OUT VOID **Table
462
    IN OUT VOID **Table
463
    )
463
    )
464
 
464
 
465
{
465
{
466
    UINTN Index;
466
    UINTN Index;
467
 
467
 
468
    for(Index=0;Index<ST->NumberOfTableEntries;Index++) {
468
    for(Index=0;Index<ST->NumberOfTableEntries;Index++) {
469
        if (CompareGuid(TableGuid,&(ST->ConfigurationTable[Index].VendorGuid))==0) {
469
        if (CompareGuid(TableGuid,&(ST->ConfigurationTable[Index].VendorGuid))==0) {
470
            *Table = ST->ConfigurationTable[Index].VendorTable;
470
            *Table = ST->ConfigurationTable[Index].VendorTable;
471
            return EFI_SUCCESS;
471
            return EFI_SUCCESS;
472
        }
472
        }
473
    }
473
    }
474
    return EFI_NOT_FOUND;
474
    return EFI_NOT_FOUND;
475
}
475
}
476
 
476
 
477
 
477
 
478
CHAR16 *
478
CHAR16 *
479
LibGetUiString (
479
LibGetUiString (
480
    IN  EFI_HANDLE      Handle,
480
    IN  EFI_HANDLE      Handle,
481
    IN  UI_STRING_TYPE  StringType,
481
    IN  UI_STRING_TYPE  StringType,
482
    IN  ISO_639_2       *LangCode,
482
    IN  ISO_639_2       *LangCode,
483
    IN  BOOLEAN         ReturnDevicePathStrOnMismatch
483
    IN  BOOLEAN         ReturnDevicePathStrOnMismatch
484
    )
484
    )
485
{
485
{
486
    UI_INTERFACE    *Ui;
486
    UI_INTERFACE    *Ui;
487
    UI_STRING_TYPE  Index;
487
    UI_STRING_TYPE  Index;
488
    UI_STRING_ENTRY *Array;
488
    UI_STRING_ENTRY *Array;
489
    EFI_STATUS      Status;
489
    EFI_STATUS      Status;
490
   
490
   
491
    Status = BS->HandleProtocol (Handle, &UiProtocol, (VOID *)&Ui);
491
    Status = BS->HandleProtocol (Handle, &UiProtocol, (VOID *)&Ui);
492
    if (EFI_ERROR(Status)) {
492
    if (EFI_ERROR(Status)) {
493
        return (ReturnDevicePathStrOnMismatch) ? DevicePathToStr(DevicePathFromHandle(Handle)) : NULL;
493
        return (ReturnDevicePathStrOnMismatch) ? DevicePathToStr(DevicePathFromHandle(Handle)) : NULL;
494
    }
494
    }
495
 
495
 
496
    //
496
    //
497
    // Skip the first strings
497
    // Skip the first strings
498
    //
498
    //
499
    for (Index = UiDeviceString, Array = Ui->Entry; Index < StringType; Index++, Array++) {
499
    for (Index = UiDeviceString, Array = Ui->Entry; Index < StringType; Index++, Array++) {
500
        while (Array->LangCode) {
500
        while (Array->LangCode) {
501
            Array++;
501
            Array++;
502
        }
502
        }
503
    }
503
    }
504
 
504
 
505
    //
505
    //
506
    // Search for the match
506
    // Search for the match
507
    //
507
    //
508
    while (Array->LangCode) {
508
    while (Array->LangCode) {
509
        if (strcmpa (Array->LangCode, LangCode) == 0) {
509
        if (strcmpa (Array->LangCode, LangCode) == 0) {
510
            return Array->UiString;
510
            return Array->UiString;
511
        }
511
        }
512
    }
512
    }
513
    return (ReturnDevicePathStrOnMismatch) ? DevicePathToStr(DevicePathFromHandle(Handle)) : NULL;
513
    return (ReturnDevicePathStrOnMismatch) ? DevicePathToStr(DevicePathFromHandle(Handle)) : NULL;
514
}
514
}
515
 
515