[chore] Use gnu-efi as a part of project

This commit is contained in:
2026-05-29 19:06:37 +08:00
Unverified
parent 990c2a6295
commit d31cd01771
94 changed files with 22988 additions and 33 deletions
+203
View File
@@ -0,0 +1,203 @@
/*++
Copyright (c) 1999 Intel Corporation
Module Name:
EfiRtLib.h
Abstract:
EFI Runtime library functions
Revision History
--*/
#include "efi.h"
#include "efilib.h"
#include "efirtlib.h"
#ifndef __GNUC__
#pragma RUNTIME_CODE(RtZeroMem)
#endif
VOID
RUNTIMEFUNCTION
RtZeroMem (
IN VOID *Buffer,
IN UINTN Size
)
{
UINT8 *pt;
pt = Buffer;
while (Size--) {
*(pt++) = 0;
}
}
#ifndef __GNUC__
#pragma RUNTIME_CODE(RtSetMem)
#endif
VOID
EFIAPI
RUNTIMEFUNCTION
RtSetMem (
IN VOID *Buffer,
IN UINTN Size,
IN UINT8 Value
)
{
UINT8 *pt;
pt = Buffer;
while (Size--) {
*(pt++) = Value;
}
}
#ifndef __GNUC__
#pragma RUNTIME_CODE(RtCopyMem)
#endif
VOID
EFIAPI
RUNTIMEFUNCTION
RtCopyMem (
IN VOID *Dest,
IN VOID *Src,
IN UINTN len
)
{
UINT8 *d, *s;
d = Dest;
s = Src;
if (d == NULL || s == NULL || s == d)
return;
// If the beginning of the destination range overlaps with the end of
// the source range, make sure to start the copy from the end so that
// we don't end up overwriting source data that we need for the copy.
if ((d > s) && (d < s + len)) {
for (d += len, s += len; len--; )
*--d = *--s;
} else {
while (len--)
*d++ = *s++;
}
}
#ifndef __GNUC__
#pragma RUNTIME_CODE(RtCopyMemC)
#endif
VOID
EFIAPI
RUNTIMEFUNCTION
RtCopyMemC (
IN VOID *Dest,
IN CONST VOID *Src,
IN UINTN len
)
{
/* CopyMem matches ISO C apart from the change to NON-CONST Src
Overwriting Src is an intended outcome if overlapping occurs (per memmove)
This function is useful to avoid GCC dying in changing pointer setup
*/
RtCopyMem(Dest, (VOID*)Src, len);
}
#ifndef __GNUC__
#pragma RUNTIME_CODE(RtCompareMem)
#endif
INTN
RUNTIMEFUNCTION
RtCompareMem (
IN CONST VOID *Dest,
IN CONST VOID *Src,
IN UINTN len
)
{
CONST UINT8 *d, *s;
d = Dest;
s = Src;
while (len--) {
if (*d != *s) {
return *d - *s;
}
d += 1;
s += 1;
}
return 0;
}
typedef UINT32 QUAD_UINT32[4]; /* EFI_GUID is 128 bits so 32 x 4 */
#ifndef __GNUC__
#pragma RUNTIME_CODE(RtCompareGuid)
#endif
BOOLEAN
EFIAPI
RUNTIMEFUNCTION
RtCompareGuid (
IN CONST EFI_GUID *Guid1,
IN CONST EFI_GUID *Guid2
)
/*++
Routine Description:
Compares two GUIDs
Arguments:
Guid1 - guid to compare
Guid2 - guid to compare
Returns:
= 1 if Guid1 == Guid2
--*/
{
CONST QUAD_UINT32 *g1, *g2;
UINT32 r;
//
// Compare 32 bits at a time
//
g1 = (CONST QUAD_UINT32*)Guid1;
g2 = (CONST QUAD_UINT32*)Guid2;
r = (*g1)[0] - (*g2)[0];
r |= (*g1)[1] - (*g2)[1];
r |= (*g1)[2] - (*g2)[2];
r |= (*g1)[3] - (*g2)[3];
if (r==0) {
return 1;
} else {
return 0;
}
}
#ifndef __GNUC__
#pragma RUNTIME_CODE(RtIsZeroGuid)
#endif
BOOLEAN
EFIAPI
RUNTIMEFUNCTION
RtIsZeroGuid (
IN CONST EFI_GUID *Guid1
)
{
return RtCompareGuid(Guid1, &gZeroGuid);
}
+65
View File
@@ -0,0 +1,65 @@
/*++
Copyright (c) 1998 Intel Corporation
Module Name:
data.c
Abstract:
EFI library global data
Revision History
--*/
#include "lib.h"
//
// These globals are runtime globals
//
// N.B. The Microsoft C compiler will only put the data in the
// right data section if it is explicitly initialized..
//
#ifndef __GNUC__
#pragma BEGIN_RUNTIME_DATA()
#endif
//
// RT - pointer to the runtime table
//
EFI_RUNTIME_SERVICES *RT;
//
// LibStandalone - TRUE if lib is linked in as part of the firmware.
// N.B. The EFI fw sets this value directly
//
BOOLEAN LibFwInstance;
//
// EFIDebug - Debug mask
//
UINTN EFIDebug = EFI_DBUG_MASK;
//
// LibRuntimeDebugOut - Runtime Debug Output device
//
SIMPLE_TEXT_OUTPUT_INTERFACE *LibRuntimeDebugOut;
//
// LibRuntimeRaiseTPL, LibRuntimeRestoreTPL - pointers to Runtime functions from the
// Boot Services Table
//
EFI_RAISE_TPL LibRuntimeRaiseTPL = NULL;
EFI_RESTORE_TPL LibRuntimeRestoreTPL = NULL;
+102
View File
@@ -0,0 +1,102 @@
/*++
Copyright (c) 1998 Intel Corporation
Module Name:
lock.c
Abstract:
Implements FLOCK
Revision History
--*/
#include "lib.h"
#ifndef __GNUC__
#pragma RUNTIME_CODE(RtAcquireLock)
#endif
VOID
RtAcquireLock (
IN FLOCK *Lock
)
/*++
Routine Description:
Raising to the task priority level of the mutual exclusion
lock, and then acquires ownership of the lock.
Arguments:
Lock - The lock to acquire
Returns:
Lock owned
--*/
{
if (BS) {
if (BS->RaiseTPL != NULL) {
Lock->OwnerTpl = uefi_call_wrapper(BS->RaiseTPL, 1, Lock->Tpl);
}
}
else {
if (LibRuntimeRaiseTPL != NULL) {
Lock->OwnerTpl = LibRuntimeRaiseTPL(Lock->Tpl);
}
}
Lock->Lock += 1;
ASSERT (Lock->Lock == 1);
}
#ifndef __GNUC__
#pragma RUNTIME_CODE(RtAcquireLock)
#endif
VOID
RtReleaseLock (
IN FLOCK *Lock
)
/*++
Routine Description:
Releases ownership of the mutual exclusion lock, and
restores the previous task priority level.
Arguments:
Lock - The lock to release
Returns:
Lock unowned
--*/
{
EFI_TPL Tpl;
Tpl = Lock->OwnerTpl;
ASSERT(Lock->Lock == 1);
Lock->Lock -= 1;
if (BS) {
if (BS->RestoreTPL != NULL) {
uefi_call_wrapper(BS->RestoreTPL, 1, Tpl);
}
}
else {
if (LibRuntimeRestoreTPL != NULL) {
LibRuntimeRestoreTPL(Tpl);
}
}
}
+233
View File
@@ -0,0 +1,233 @@
/*++
Copyright (c) 1998 Intel Corporation
Module Name:
str.c
Abstract:
String runtime functions
Revision History
--*/
#include "lib.h"
#ifndef __GNUC__
#pragma RUNTIME_CODE(RtStrCmp)
#endif
INTN
RUNTIMEFUNCTION
RtStrCmp (
IN CONST CHAR16 *s1,
IN CONST CHAR16 *s2
)
// compare strings
{
while (*s1) {
if (*s1 != *s2) {
break;
}
s1 += 1;
s2 += 1;
}
return *s1 - *s2;
}
#ifndef __GNUC__
#pragma RUNTIME_CODE(RtStrCpy)
#endif
VOID
RUNTIMEFUNCTION
RtStrCpy (
IN CHAR16 *Dest,
IN CONST CHAR16 *Src
)
// copy strings
{
while (*Src) {
*(Dest++) = *(Src++);
}
*Dest = 0;
}
#ifndef __GNUC__
#pragma RUNTIME_CODE(RtStrnCpy)
#endif
VOID
RUNTIMEFUNCTION
RtStrnCpy (
IN CHAR16 *Dest,
IN CONST CHAR16 *Src,
IN UINTN Len
)
// copy strings
{
UINTN Size = RtStrnLen(Src, Len);
if (Size != Len)
RtSetMem(Dest + Size, (Len - Size) * sizeof(CHAR16), '\0');
RtCopyMemC(Dest, Src, Size * sizeof(CHAR16));
}
#ifndef __GNUC__
#pragma RUNTIME_CODE(RtStpCpy)
#endif
CHAR16 *
RUNTIMEFUNCTION
RtStpCpy (
IN CHAR16 *Dest,
IN CONST CHAR16 *Src
)
// copy strings
{
while (*Src) {
*(Dest++) = *(Src++);
}
*Dest = 0;
return Dest;
}
#ifndef __GNUC__
#pragma RUNTIME_CODE(RtStpnCpy)
#endif
CHAR16 *
RUNTIMEFUNCTION
RtStpnCpy (
IN CHAR16 *Dest,
IN CONST CHAR16 *Src,
IN UINTN Len
)
// copy strings
{
UINTN Size = RtStrnLen(Src, Len);
if (Size != Len)
RtSetMem(Dest + Size, (Len - Size) * sizeof(CHAR16), '\0');
RtCopyMemC(Dest, Src, Size * sizeof(CHAR16));
return Dest + Size;
}
#ifndef __GNUC__
#pragma RUNTIME_CODE(RtStrCat)
#endif
VOID
RUNTIMEFUNCTION
RtStrCat (
IN CHAR16 *Dest,
IN CONST CHAR16 *Src
)
{
RtStrCpy(Dest+RtStrLen(Dest), Src);
}
#ifndef __GNUC__
#pragma RUNTIME_CODE(RtStrnCat)
#endif
VOID
RUNTIMEFUNCTION
RtStrnCat (
IN CHAR16 *Dest,
IN CONST CHAR16 *Src,
IN UINTN Len
)
{
UINTN DestSize, Size;
DestSize = RtStrLen(Dest);
Size = RtStrnLen(Src, Len);
RtCopyMemC(Dest + DestSize, Src, Size * sizeof(CHAR16));
Dest[DestSize + Size] = '\0';
}
#ifndef __GNUC__
#pragma RUNTIME_CODE(RtStrLen)
#endif
UINTN
RUNTIMEFUNCTION
RtStrLen (
IN CONST CHAR16 *s1
)
// string length
{
UINTN len;
for (len=0; *s1; s1+=1, len+=1) ;
return len;
}
#ifndef __GNUC__
#pragma RUNTIME_CODE(RtStrnLen)
#endif
UINTN
RUNTIMEFUNCTION
RtStrnLen (
IN CONST CHAR16 *s1,
IN UINTN Len
)
// string length
{
UINTN i;
for (i = 0; *s1 && i < Len; i++)
s1++;
return i;
}
#ifndef __GNUC__
#pragma RUNTIME_CODE(RtStrSize)
#endif
UINTN
RUNTIMEFUNCTION
RtStrSize (
IN CONST CHAR16 *s1
)
// string size
{
UINTN len;
for (len=0; *s1; s1+=1, len+=1) ;
return (len + 1) * sizeof(CHAR16);
}
#ifndef __GNUC__
#pragma RUNTIME_CODE(RtBCDtoDecimal)
#endif
UINT8
RUNTIMEFUNCTION
RtBCDtoDecimal(
IN UINT8 BcdValue
)
{
UINTN High, Low;
High = BcdValue >> 4;
Low = BcdValue - (High << 4);
return ((UINT8)(Low + (High * 10)));
}
#ifndef __GNUC__
#pragma RUNTIME_CODE(RtDecimaltoBCD)
#endif
UINT8
RUNTIMEFUNCTION
RtDecimaltoBCD (
IN UINT8 DecValue
)
{
UINTN High, Low;
High = DecValue / 10;
Low = DecValue - (High * 10);
return ((UINT8)(Low + (High << 4)));
}
+105
View File
@@ -0,0 +1,105 @@
/*++
Copyright (c) 1998 Intel Corporation
Module Name:
vm.c
Abstract:
EFI Hell to remap runtime address into the new virual address space
that was registered by the OS for RT calls.
So the code image needs to be relocated. All pointers need to be
manually fixed up since the address map changes.
GOOD LUCK NOT HAVING BUGS IN YOUR CODE! PLEASE TEST A LOT. MAKE SURE
EXIT BOOTSERVICES OVER WRITES ALL BOOTSERVICE MEMORY & DATA SPACES WHEN
YOU TEST.
Revision History
--*/
#include "lib.h"
#ifndef __GNUC__
#pragma RUNTIME_CODE(RtLibEnableVirtualMappings)
#endif
VOID
RUNTIMEFUNCTION
RtLibEnableVirtualMappings (
VOID
)
{
EFI_CONVERT_POINTER ConvertPointer;
//
// If this copy of the lib is linked into the firmware, then
// do not update the pointers yet.
//
if (!LibFwInstance) {
//
// Different components are updating to the new virtual
// mappings at differnt times. The only function that
// is safe to call at this notification is ConvertAddress
//
ConvertPointer = RT->ConvertPointer;
//
// Fix any pointers that the lib created, that may be needed
// during runtime.
//
ConvertPointer (EFI_INTERNAL_PTR, (VOID **)&RT);
ConvertPointer (EFI_OPTIONAL_PTR, (VOID **)&LibRuntimeDebugOut);
ConvertPointer (EFI_INTERNAL_PTR, (VOID **)&LibRuntimeRaiseTPL);
ConvertPointer (EFI_INTERNAL_PTR, (VOID **)&LibRuntimeRestoreTPL);
// that was it :^)
}
}
#ifndef __GNUC__
#pragma RUNTIME_CODE(RtConvertList)
#endif
VOID
RUNTIMEFUNCTION
RtConvertList (
IN UINTN DebugDisposition,
IN OUT LIST_ENTRY *ListHead
)
{
LIST_ENTRY *Link;
LIST_ENTRY *NextLink;
EFI_CONVERT_POINTER ConvertPointer;
ConvertPointer = RT->ConvertPointer;
//
// Convert all the Flink & Blink pointers in the list
//
Link = ListHead;
do {
NextLink = Link->Flink;
ConvertPointer (
Link->Flink == ListHead ? DebugDisposition : 0,
(VOID **)&Link->Flink
);
ConvertPointer (
Link->Blink == ListHead ? DebugDisposition : 0,
(VOID **)&Link->Blink
);
Link = NextLink;
} while (Link != ListHead);
}