2007-06-22 05:21:45 +02:00
|
|
|
/** @file
|
|
|
|
Implementation of the EfiSetMem routine. This function is broken
|
|
|
|
out into its own source file so that it can be excluded from a
|
|
|
|
build for a particular platform easily if an optimized version
|
|
|
|
is desired.
|
|
|
|
|
2010-04-23 18:04:26 +02:00
|
|
|
Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
|
2016-09-02 09:26:23 +02:00
|
|
|
Copyright (c) 2012 - 2013, ARM Ltd. All rights reserved.<BR>
|
|
|
|
Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR>
|
|
|
|
|
2010-04-23 18:04:26 +02:00
|
|
|
This program and the accompanying materials
|
2007-06-22 05:21:45 +02:00
|
|
|
are licensed and made available under the terms and conditions of the BSD License
|
|
|
|
which accompanies this distribution. The full text of the license may be found at
|
2010-06-24 22:11:34 +02:00
|
|
|
http://opensource.org/licenses/bsd-license.php.
|
2007-06-22 05:21:45 +02:00
|
|
|
|
|
|
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|
|
|
|
|
|
|
**/
|
|
|
|
|
2008-09-17 09:46:17 +02:00
|
|
|
|
2007-06-30 01:22:13 +02:00
|
|
|
|
2007-06-22 05:21:45 +02:00
|
|
|
|
|
|
|
#include "MemLibInternals.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
Set Buffer to Value for Size bytes.
|
|
|
|
|
2010-06-24 22:11:34 +02:00
|
|
|
@param Buffer The memory to set.
|
|
|
|
@param Length The number of bytes to set.
|
|
|
|
@param Value The value of the set operation.
|
2007-06-22 05:21:45 +02:00
|
|
|
|
|
|
|
@return Buffer
|
|
|
|
|
|
|
|
**/
|
|
|
|
VOID *
|
|
|
|
EFIAPI
|
|
|
|
InternalMemSetMem (
|
2010-01-27 04:25:28 +01:00
|
|
|
OUT VOID *Buffer,
|
2008-10-21 08:55:38 +02:00
|
|
|
IN UINTN Length,
|
2007-06-22 05:21:45 +02:00
|
|
|
IN UINT8 Value
|
|
|
|
)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// Declare the local variables that actually move the data elements as
|
|
|
|
// volatile to prevent the optimizer from replacing this function with
|
|
|
|
// the intrinsic memset()
|
|
|
|
//
|
2016-09-02 09:26:23 +02:00
|
|
|
volatile UINT8 *Pointer8;
|
|
|
|
volatile UINT32 *Pointer32;
|
|
|
|
volatile UINT64 *Pointer64;
|
|
|
|
UINT32 Value32;
|
|
|
|
UINT64 Value64;
|
|
|
|
|
|
|
|
if ((((UINTN)Buffer & 0x7) == 0) && (Length >= 8)) {
|
|
|
|
// Generate the 64bit value
|
|
|
|
Value32 = (Value << 24) | (Value << 16) | (Value << 8) | Value;
|
|
|
|
Value64 = LShiftU64 (Value32, 32) | Value32;
|
|
|
|
|
|
|
|
Pointer64 = (UINT64*)Buffer;
|
|
|
|
while (Length >= 8) {
|
|
|
|
*(Pointer64++) = Value64;
|
|
|
|
Length -= 8;
|
|
|
|
}
|
2007-06-22 05:21:45 +02:00
|
|
|
|
2016-09-02 09:26:23 +02:00
|
|
|
// Finish with bytes if needed
|
|
|
|
Pointer8 = (UINT8*)Pointer64;
|
|
|
|
} else if ((((UINTN)Buffer & 0x3) == 0) && (Length >= 4)) {
|
|
|
|
// Generate the 32bit value
|
|
|
|
Value32 = (Value << 24) | (Value << 16) | (Value << 8) | Value;
|
|
|
|
|
|
|
|
Pointer32 = (UINT32*)Buffer;
|
|
|
|
while (Length >= 4) {
|
|
|
|
*(Pointer32++) = Value32;
|
|
|
|
Length -= 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Finish with bytes if needed
|
|
|
|
Pointer8 = (UINT8*)Pointer32;
|
|
|
|
} else {
|
|
|
|
Pointer8 = (UINT8*)Buffer;
|
|
|
|
}
|
2009-01-21 04:17:15 +01:00
|
|
|
while (Length-- > 0) {
|
2016-09-02 09:26:23 +02:00
|
|
|
*(Pointer8++) = Value;
|
2007-06-22 05:21:45 +02:00
|
|
|
}
|
|
|
|
return Buffer;
|
|
|
|
}
|