]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/BaseMemoryLib/CopyMem.c
ArmVirtPkg/FdtParser: avoid unaligned accesses with the MMU off
[mirror_edk2.git] / MdePkg / Library / BaseMemoryLib / CopyMem.c
CommitLineData
e1f414b6 1/** @file\r
d531bfee 2 Implementation of the InternalMemCopyMem routine. This function is broken\r
3 out into its own source file so that it can be excluded from a build for a\r
4 particular platform easily if an optimized version is desired.\r
e1f414b6 5\r
15c952e7 6 Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
2fcf0abf 7 This program and the accompanying materials\r
e1f414b6 8 are licensed and made available under the terms and conditions of the BSD License\r
9 which accompanies this distribution. The full text of the license may be found at\r
15c952e7 10 http://opensource.org/licenses/bsd-license.php.\r
e1f414b6 11\r
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
14\r
e1f414b6 15**/\r
16\r
1efcc4ae 17\r
f734a10a 18\r
e1f414b6 19\r
20#include "MemLibInternals.h"\r
21\r
22/**\r
23 Copy Length bytes from Source to Destination.\r
24\r
15c952e7 25 @param DestinationBuffer The target of the copy request.\r
26 @param SourceBuffer The place to copy from.\r
27 @param Length The number of bytes to copy.\r
e1f414b6 28\r
29 @return Destination\r
30\r
31**/\r
32VOID *\r
33EFIAPI\r
34InternalMemCopyMem (\r
efb23117 35 OUT VOID *DestinationBuffer,\r
36 IN CONST VOID *SourceBuffer,\r
e1f414b6 37 IN UINTN Length\r
38 )\r
39{\r
40 //\r
41 // Declare the local variables that actually move the data elements as\r
42 // volatile to prevent the optimizer from replacing this function with\r
43 // the intrinsic memcpy()\r
44 //\r
45 volatile UINT8 *Destination8;\r
46 CONST UINT8 *Source8;\r
47\r
efb23117 48 if (SourceBuffer > DestinationBuffer) {\r
49 Destination8 = (UINT8*)DestinationBuffer;\r
50 Source8 = (CONST UINT8*)SourceBuffer;\r
e1f414b6 51 while (Length-- != 0) {\r
52 *(Destination8++) = *(Source8++);\r
53 }\r
efb23117 54 } else if (SourceBuffer < DestinationBuffer) {\r
55 Destination8 = (UINT8*)DestinationBuffer + Length;\r
56 Source8 = (CONST UINT8*)SourceBuffer + Length;\r
e1f414b6 57 while (Length-- != 0) {\r
58 *(--Destination8) = *(--Source8);\r
59 }\r
60 }\r
efb23117 61 return DestinationBuffer;\r
e1f414b6 62}\r