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