summaryrefslogtreecommitdiff
path: root/gnu-efi/lib/runtime
diff options
context:
space:
mode:
authorSteve McIntyre <steve@einval.com>2021-03-23 23:49:46 +0000
committerSteve McIntyre <steve@einval.com>2021-03-23 23:49:46 +0000
commit1251a7ba86fc40a6aad8b4fecdbca2b61808d9fa (patch)
tree2125fda549aaca55cb49a48d54be77dec7fbf3df /gnu-efi/lib/runtime
parent85b409232ce89b34626df9d72abedf5d4f5ccef6 (diff)
parent031e5cce385d3f96b1caa1d53495332a7eb03749 (diff)
downloadefi-boot-shim-debian/15.3-1.tar.gz
efi-boot-shim-debian/15.3-1.zip
Update upstream source from tag 'upstream/15.3'debian/15.3-1
Update to upstream version '15.3' with Debian dir 1b484f1c1ac270604a5a1451b34de4b0865c6211
Diffstat (limited to 'gnu-efi/lib/runtime')
-rw-r--r--gnu-efi/lib/runtime/efirtlib.c131
-rw-r--r--gnu-efi/lib/runtime/rtdata.c65
-rw-r--r--gnu-efi/lib/runtime/rtlock.c102
-rw-r--r--gnu-efi/lib/runtime/rtstr.c234
-rw-r--r--gnu-efi/lib/runtime/vm.c105
5 files changed, 637 insertions, 0 deletions
diff --git a/gnu-efi/lib/runtime/efirtlib.c b/gnu-efi/lib/runtime/efirtlib.c
new file mode 100644
index 00000000..3e330d6a
--- /dev/null
+++ b/gnu-efi/lib/runtime/efirtlib.c
@@ -0,0 +1,131 @@
+/*++
+
+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
+ )
+{
+ INT8 *pt;
+
+ pt = Buffer;
+ while (Size--) {
+ *(pt++) = 0;
+ }
+}
+
+#ifndef __GNUC__
+#pragma RUNTIME_CODE(RtSetMem)
+#endif
+VOID
+RUNTIMEFUNCTION
+RtSetMem (
+ IN VOID *Buffer,
+ IN UINTN Size,
+ IN UINT8 Value
+ )
+{
+ INT8 *pt;
+
+ pt = Buffer;
+ while (Size--) {
+ *(pt++) = Value;
+ }
+}
+
+#ifndef __GNUC__
+#pragma RUNTIME_CODE(RtCopyMem)
+#endif
+VOID
+RUNTIMEFUNCTION
+RtCopyMem (
+ IN VOID *Dest,
+ IN CONST VOID *Src,
+ IN UINTN len
+ )
+{
+ CHAR8 *d;
+ CONST CHAR8 *s = Src;
+ d = Dest;
+ while (len--) {
+ *(d++) = *(s++);
+ }
+}
+
+#ifndef __GNUC__
+#pragma RUNTIME_CODE(RtCompareMem)
+#endif
+INTN
+RUNTIMEFUNCTION
+RtCompareMem (
+ IN CONST VOID *Dest,
+ IN CONST VOID *Src,
+ IN UINTN len
+ )
+{
+ CONST unsigned char *d = Dest, *s = Src;
+ while (len--) {
+ if (*d != *s) {
+ return *d - *s;
+ }
+
+ d += 1;
+ s += 1;
+ }
+
+ return 0;
+}
+
+#ifndef __GNUC__
+#pragma RUNTIME_CODE(RtCompareGuid)
+#endif
+INTN
+RUNTIMEFUNCTION
+RtCompareGuid (
+ IN EFI_GUID *Guid1,
+ IN EFI_GUID *Guid2
+ )
+/*++
+
+Routine Description:
+
+ Compares to GUIDs
+
+Arguments:
+
+ Guid1 - guid to compare
+ Guid2 - guid to compare
+
+Returns:
+ = 0 if Guid1 == Guid2
+
+--*/
+{
+ return RtCompareMem(Guid1, Guid2, sizeof(*Guid1));
+}
+
+
diff --git a/gnu-efi/lib/runtime/rtdata.c b/gnu-efi/lib/runtime/rtdata.c
new file mode 100644
index 00000000..3efcbf3a
--- /dev/null
+++ b/gnu-efi/lib/runtime/rtdata.c
@@ -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;
+
diff --git a/gnu-efi/lib/runtime/rtlock.c b/gnu-efi/lib/runtime/rtlock.c
new file mode 100644
index 00000000..2eafdca1
--- /dev/null
+++ b/gnu-efi/lib/runtime/rtlock.c
@@ -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);
+ }
+ }
+}
diff --git a/gnu-efi/lib/runtime/rtstr.c b/gnu-efi/lib/runtime/rtstr.c
new file mode 100644
index 00000000..962bb32c
--- /dev/null
+++ b/gnu-efi/lib/runtime/rtstr.c
@@ -0,0 +1,234 @@
+/*++
+
+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 *s1p,
+ IN CONST CHAR16 *s2p
+ )
+// compare strings
+{
+ CONST UINT16 *s1 = (CONST UINT16 *)s1p;
+ CONST UINT16 *s2 = (CONST UINT16 *)s2p;
+
+ 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');
+ RtCopyMem(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');
+ RtCopyMem(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);
+ RtCopyMem(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)));
+}
+
+
diff --git a/gnu-efi/lib/runtime/vm.c b/gnu-efi/lib/runtime/vm.c
new file mode 100644
index 00000000..26e0c8e1
--- /dev/null
+++ b/gnu-efi/lib/runtime/vm.c
@@ -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);
+}