summaryrefslogtreecommitdiff
path: root/OvmfPkg/Library/MemDebugLogLib/MemDebugLogRt.c
blob: 456bb70a8575ef1b05ba21ee34ae4e96b558735a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/** @file
 *
  Memory Debug Log Library - Runtime

  Copyright (C) 2025, Oracle and/or its affiliates.

  SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#include <PiDxe.h>
#include <Library/MemDebugLogLib.h>
#include <Library/UefiRuntimeLib.h>

EFI_PHYSICAL_ADDRESS  mMemDebugLogBufAddr;
BOOLEAN               mMemDebugLogBufAddrInit;

EFI_STATUS
EFIAPI
MemDebugLogWrite (
  IN  CHAR8  *Buffer,
  IN  UINTN  Length
  )
{
  EFI_STATUS  Status;

  //
  // Stop logging after we have switched to virtual mode
  // to avoid potential problems (such as crashes accessing
  // physical pointers).
  //
  if (EfiGoneVirtual ()) {
    return EFI_SUCCESS;
  }

  if (!mMemDebugLogBufAddrInit) {
    //
    // Obtain the Memory Debug Log buffer addr from HOB
    //
    Status = MemDebugLogAddrFromHOB (&mMemDebugLogBufAddr);
    if (EFI_ERROR (Status)) {
      mMemDebugLogBufAddr = 0;
    }

    mMemDebugLogBufAddrInit = TRUE;
  }

  if (mMemDebugLogBufAddr) {
    Status = MemDebugLogWriteBuffer (mMemDebugLogBufAddr, Buffer, Length);
  } else {
    Status = EFI_NOT_FOUND;
  }

  return Status;
}