]>
Commit | Line | Data |
---|---|---|
e1f414b6 | 1 | /** @file\r |
2 | Implementation of the EfiSetMem 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 | |
2fcf0abf | 7 | Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r |
01f688be AB |
8 | Copyright (c) 2012 - 2013, ARM Ltd. All rights reserved.<BR>\r |
9 | Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR>\r | |
10 | \r | |
2fcf0abf | 11 | This program and the accompanying materials\r |
e1f414b6 | 12 | are licensed and made available under the terms and conditions of the BSD License\r |
13 | which accompanies this distribution. The full text of the license may be found at\r | |
15c952e7 | 14 | http://opensource.org/licenses/bsd-license.php.\r |
e1f414b6 | 15 | \r |
16 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
17 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
18 | \r | |
e1f414b6 | 19 | **/\r |
20 | \r | |
1efcc4ae | 21 | \r |
f734a10a | 22 | \r |
e1f414b6 | 23 | \r |
24 | #include "MemLibInternals.h"\r | |
25 | \r | |
26 | /**\r | |
27 | Set Buffer to Value for Size bytes.\r | |
28 | \r | |
15c952e7 | 29 | @param Buffer The memory to set.\r |
30 | @param Length The number of bytes to set.\r | |
31 | @param Value The value of the set operation.\r | |
e1f414b6 | 32 | \r |
33 | @return Buffer\r | |
34 | \r | |
35 | **/\r | |
36 | VOID *\r | |
37 | EFIAPI\r | |
38 | InternalMemSetMem (\r | |
ea6898b9 | 39 | OUT VOID *Buffer,\r |
0827d304 | 40 | IN UINTN Length,\r |
e1f414b6 | 41 | IN UINT8 Value\r |
42 | )\r | |
43 | {\r | |
44 | //\r | |
45 | // Declare the local variables that actually move the data elements as\r | |
46 | // volatile to prevent the optimizer from replacing this function with\r | |
47 | // the intrinsic memset()\r | |
48 | //\r | |
01f688be AB |
49 | volatile UINT8 *Pointer8;\r |
50 | volatile UINT32 *Pointer32;\r | |
51 | volatile UINT64 *Pointer64;\r | |
52 | UINT32 Value32;\r | |
53 | UINT64 Value64;\r | |
54 | \r | |
55 | if ((((UINTN)Buffer & 0x7) == 0) && (Length >= 8)) {\r | |
56 | // Generate the 64bit value\r | |
57 | Value32 = (Value << 24) | (Value << 16) | (Value << 8) | Value;\r | |
58 | Value64 = LShiftU64 (Value32, 32) | Value32;\r | |
59 | \r | |
60 | Pointer64 = (UINT64*)Buffer;\r | |
61 | while (Length >= 8) {\r | |
62 | *(Pointer64++) = Value64;\r | |
63 | Length -= 8;\r | |
64 | }\r | |
e1f414b6 | 65 | \r |
01f688be AB |
66 | // Finish with bytes if needed\r |
67 | Pointer8 = (UINT8*)Pointer64;\r | |
68 | } else if ((((UINTN)Buffer & 0x3) == 0) && (Length >= 4)) {\r | |
69 | // Generate the 32bit value\r | |
70 | Value32 = (Value << 24) | (Value << 16) | (Value << 8) | Value;\r | |
71 | \r | |
72 | Pointer32 = (UINT32*)Buffer;\r | |
73 | while (Length >= 4) {\r | |
74 | *(Pointer32++) = Value32;\r | |
75 | Length -= 4;\r | |
76 | }\r | |
77 | \r | |
78 | // Finish with bytes if needed\r | |
79 | Pointer8 = (UINT8*)Pointer32;\r | |
80 | } else {\r | |
81 | Pointer8 = (UINT8*)Buffer;\r | |
82 | }\r | |
7efb1d89 | 83 | while (Length-- > 0) {\r |
01f688be | 84 | *(Pointer8++) = Value;\r |
e1f414b6 | 85 | }\r |
86 | return Buffer;\r | |
87 | }\r |