Files
slimbootloader/BootloaderCommonPkg/Library/DebugLogBufferLib/DebugLogBufferLib.c
T
Aiden Park 3ec0361920 Fix pointer type cast errors from Visual Studio (#617)
Visual Studio reports more pointer type cast errors with 64-bit build.
This will cover the issue on the existing targets.

Signed-off-by: Aiden Park <aiden.park@intel.com>
2020-03-27 11:03:28 -07:00

62 lines
1.8 KiB
C

/** @file
Provide Log Buffer Library functions.
Copyright (c) 2018, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include <PiPei.h>
#include <Library/BaseMemoryLib.h>
#include <Library/BootloaderCommonLib.h>
#include <Library/DebugLogBufferLib.h>
#include <Guid/LoaderPlatformDataGuid.h>
/**
Write data from buffer to console buffer.
Writes NumberOfBytes data bytes from Buffer to the serial device.
The number of bytes actually written to the serial device is returned.
If the return value is less than NumberOfBytes, then the write operation failed.
If Buffer is NULL, then ASSERT().
If NumberOfBytes is zero, then return 0.
@param Buffer Pointer to the data buffer to be written.
@param NumberOfBytes Number of bytes to written to the serial device.
@retval 0 NumberOfBytes is 0.
@retval >0 The number of bytes written to the serial device.
If this value is less than NumberOfBytes, then the write operation failed.
**/
UINTN
EFIAPI
DebugLogBufferWrite (
IN UINT8 *Buffer,
IN UINTN NumberOfBytes
)
{
DEBUG_LOG_BUFFER_HEADER *LogBufHdr;
// This function will be called by DEBUG or ASSERT macro.
// So please DON'T use DEBUG/ASSERT macro inside this function,
// to avoid recursion.
LogBufHdr = (DEBUG_LOG_BUFFER_HEADER *) GetDebugLogBufferPtr ();
if (LogBufHdr == NULL) {
return 0;
}
if (LogBufHdr->UsedLength + NumberOfBytes > LogBufHdr->TotalLength) {
NumberOfBytes = LogBufHdr->TotalLength - LogBufHdr->UsedLength;
}
if (NumberOfBytes > 0) {
CopyMem ((UINT8 *)LogBufHdr + LogBufHdr->UsedLength, Buffer, NumberOfBytes);
LogBufHdr->UsedLength += (UINT32)NumberOfBytes;
}
return NumberOfBytes;
}