3 * Copyright (c) 2011, ARM Limited. All rights reserved.
5 * This program and the accompanying materials
6 * are licensed and made available under the terms and conditions of the BSD License
7 * which accompanies this distribution. The full text of the license may be found at
8 * http://opensource.org/licenses/bsd-license.php
10 * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include <Library/ArmPlatformGlobalVariableLib.h>
17 #include <Library/BaseLib.h>
18 #include <Library/BaseMemoryLib.h>
19 #include <Library/PcdLib.h>
21 #define IS_XIP() ((PcdGet32 (PcdFdBaseAddress) > (PcdGet32 (PcdSystemMemoryBase) + PcdGet32 (PcdSystemMemorySize))) || \
22 ((PcdGet32 (PcdFdBaseAddress) + PcdGet32 (PcdFdSize)) < PcdGet32 (PcdSystemMemoryBase)))
24 // Declared by ArmPlatformPkg/PrePi Module
25 extern UINTN mGlobalVariableBase
;
28 ArmPlatformGetGlobalVariable (
29 IN UINTN VariableOffset
,
30 IN UINTN VariableSize
,
34 UINTN GlobalVariableBase
;
37 // In Case of XIP, we expect the Primary Stack at the top of the System Memory
38 GlobalVariableBase
= PcdGet32 (PcdSystemMemoryBase
) + PcdGet32 (PcdSystemMemorySize
) - PcdGet32 (PcdPeiGlobalVariableSize
);
40 GlobalVariableBase
= mGlobalVariableBase
;
43 if (VariableSize
== 4) {
44 *(UINT32
*)Variable
= ReadUnaligned32 ((CONST UINT32
*)(GlobalVariableBase
+ VariableOffset
));
45 } else if (VariableSize
== 8) {
46 *(UINT32
*)Variable
= ReadUnaligned64 ((CONST UINT64
*)(GlobalVariableBase
+ VariableOffset
));
48 CopyMem (Variable
, (VOID
*)(GlobalVariableBase
+ VariableOffset
), VariableSize
);
53 ArmPlatformSetGlobalVariable (
54 IN UINTN VariableOffset
,
55 IN UINTN VariableSize
,
59 UINTN GlobalVariableBase
;
62 // In Case of XIP, we expect the Primary Stack at the top of the System Memory
63 GlobalVariableBase
= PcdGet32 (PcdSystemMemoryBase
) + PcdGet32 (PcdSystemMemorySize
) - PcdGet32 (PcdPeiGlobalVariableSize
);
65 GlobalVariableBase
= mGlobalVariableBase
;
68 if (VariableSize
== 4) {
69 WriteUnaligned32 ((UINT32
*)(GlobalVariableBase
+ VariableOffset
), *(UINT32
*)Variable
);
70 } else if (VariableSize
== 8) {
71 WriteUnaligned64 ((UINT64
*)(GlobalVariableBase
+ VariableOffset
), *(UINT64
*)Variable
);
73 CopyMem ((VOID
*)(GlobalVariableBase
+ VariableOffset
), Variable
, VariableSize
);