VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/Firmware/MdePkg/Library/BaseMemoryLib/SetMem.c

最後變更 在這個檔案是 99404,由 vboxsync 提交於 22 月 前

Devices/EFI/FirmwareNew: Update to edk2-stable202302 and make it build, bugref:4643

  • 屬性 svn:eol-style 設為 native
檔案大小: 2.0 KB
 
1/** @file
2 Implementation of the EfiSetMem routine. This function is broken
3 out into its own source file so that it can be excluded from a
4 build for a particular platform easily if an optimized version
5 is desired.
6
7 Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
8 Copyright (c) 2012 - 2013, ARM Ltd. All rights reserved.<BR>
9 Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR>
10
11 SPDX-License-Identifier: BSD-2-Clause-Patent
12
13**/
14
15#include "MemLibInternals.h"
16
17/**
18 Set Buffer to Value for Size bytes.
19
20 @param Buffer The memory to set.
21 @param Length The number of bytes to set.
22 @param Value The value of the set operation.
23
24 @return Buffer
25
26**/
27VOID *
28EFIAPI
29InternalMemSetMem (
30 OUT VOID *Buffer,
31 IN UINTN Length,
32 IN UINT8 Value
33 )
34{
35 //
36 // Declare the local variables that actually move the data elements as
37 // volatile to prevent the optimizer from replacing this function with
38 // the intrinsic memset()
39 //
40 volatile UINT8 *Pointer8;
41 volatile UINT32 *Pointer32;
42 volatile UINT64 *Pointer64;
43 UINT32 Value32;
44 UINT64 Value64;
45
46 if ((((UINTN)Buffer & 0x7) == 0) && (Length >= 8)) {
47 // Generate the 64bit value
48 Value32 = (Value << 24) | (Value << 16) | (Value << 8) | Value;
49 Value64 = LShiftU64 (Value32, 32) | Value32;
50
51 Pointer64 = (UINT64 *)Buffer;
52 while (Length >= 8) {
53 *(Pointer64++) = Value64;
54 Length -= 8;
55 }
56
57 // Finish with bytes if needed
58 Pointer8 = (UINT8 *)Pointer64;
59 } else if ((((UINTN)Buffer & 0x3) == 0) && (Length >= 4)) {
60 // Generate the 32bit value
61 Value32 = (Value << 24) | (Value << 16) | (Value << 8) | Value;
62
63 Pointer32 = (UINT32 *)Buffer;
64 while (Length >= 4) {
65 *(Pointer32++) = Value32;
66 Length -= 4;
67 }
68
69 // Finish with bytes if needed
70 Pointer8 = (UINT8 *)Pointer32;
71 } else {
72 Pointer8 = (UINT8 *)Buffer;
73 }
74
75 while (Length-- > 0) {
76 *(Pointer8++) = Value;
77 }
78
79 return Buffer;
80}
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette