]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPkg/Library/BaseMemoryLibVstm/CopyMem.c
Sync up ArmPkg with patch from mailing list. Changed name of BdsLib.h to BdsUnixLib...
[mirror_edk2.git] / ArmPkg / Library / BaseMemoryLibVstm / CopyMem.c
CommitLineData
d39eb83c 1/** @file\r
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
5\r
d6ebcab7
HT
6 Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>\r
7 This program and the accompanying materials\r
d39eb83c 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
10 http://opensource.org/licenses/bsd-license.php\r
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
15**/\r
16\r
17\r
18\r
19\r
20#include "MemLibInternals.h"\r
21\r
22/**\r
23 Copy Length bytes from Source to Destination.\r
24\r
25 @param DestinationBuffer Target of copy\r
26 @param SourceBuffer Place to copy from\r
27 @param Length Number of bytes to copy\r
28\r
29 @return Destination\r
30\r
31**/\r
32VOID *\r
33EFIAPI\r
34InternalMemCopyMem (\r
35 OUT VOID *DestinationBuffer,\r
36 IN CONST VOID *SourceBuffer,\r
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
48 if (SourceBuffer > DestinationBuffer) {\r
49 Destination8 = (UINT8*)DestinationBuffer;\r
50 Source8 = (CONST UINT8*)SourceBuffer;\r
51 while (Length-- != 0) {\r
52 *(Destination8++) = *(Source8++);\r
53 }\r
54 } else if (SourceBuffer < DestinationBuffer) {\r
55 Destination8 = (UINT8*)DestinationBuffer + Length;\r
56 Source8 = (CONST UINT8*)SourceBuffer + Length;\r
57 while (Length-- != 0) {\r
58 *(--Destination8) = *(--Source8);\r
59 }\r
60 }\r
61 return DestinationBuffer;\r
62}\r