diff options
author | Angelos Mouzakitis <a.mouzakitis@virtualopensystems.com> | 2023-10-10 14:33:42 +0000 |
---|---|---|
committer | Angelos Mouzakitis <a.mouzakitis@virtualopensystems.com> | 2023-10-10 14:33:42 +0000 |
commit | af1a266670d040d2f4083ff309d732d648afba2a (patch) | |
tree | 2fc46203448ddcc6f81546d379abfaeb323575e9 /roms/edk2/ArmPlatformPkg/Library/ArmPlatformStackLib | |
parent | e02cda008591317b1625707ff8e115a4841aa889 (diff) |
Change-Id: Iaf8d18082d3991dec7c0ebbea540f092188eb4ec
Diffstat (limited to 'roms/edk2/ArmPlatformPkg/Library/ArmPlatformStackLib')
4 files changed, 349 insertions, 0 deletions
diff --git a/roms/edk2/ArmPlatformPkg/Library/ArmPlatformStackLib/AArch64/ArmPlatformStackLib.S b/roms/edk2/ArmPlatformPkg/Library/ArmPlatformStackLib/AArch64/ArmPlatformStackLib.S new file mode 100644 index 000000000..db0912c19 --- /dev/null +++ b/roms/edk2/ArmPlatformPkg/Library/ArmPlatformStackLib/AArch64/ArmPlatformStackLib.S @@ -0,0 +1,99 @@ +//
+// Copyright (c) 2012-2014, ARM Limited. All rights reserved.
+//
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+//
+//
+
+#include <AsmMacroIoLibV8.h>
+
+//VOID
+//ArmPlatformStackSet (
+// IN UINTN StackBase,
+// IN UINTN MpId,
+// IN UINTN PrimaryStackSize,
+// IN UINTN SecondaryStackSize
+// );
+ASM_FUNC(ArmPlatformStackSet)
+ // Save parameters
+ mov x26, x3
+ mov x25, x2
+ mov x24, x1
+ mov x23, x0
+
+ // Save the Link register
+ mov x27, x30
+
+ // Identify Stack
+ mov x0, x1
+ bl ASM_PFX(ArmPlatformIsPrimaryCore)
+ cmp x0, #1
+
+ // Restore parameters
+ mov x0, x23
+ mov x1, x24
+ mov x2, x25
+ mov x3, x26
+
+ // Restore the Link register
+ mov x30, x27
+
+ b.ne 0f
+
+ b ASM_PFX(ArmPlatformStackSetPrimary)
+0:b ASM_PFX(ArmPlatformStackSetSecondary)
+
+//VOID
+//ArmPlatformStackSetPrimary (
+// IN UINTN StackBase,
+// IN UINTN MpId,
+// IN UINTN PrimaryStackSize,
+// IN UINTN SecondaryStackSize
+// );
+ASM_FUNC(ArmPlatformStackSetPrimary)
+ // Add size of primary stack to StackBase
+ add x0, x0, x2
+
+ // Compute SecondaryCoresCount * SecondaryCoreStackSize
+ MOV32 (w1, FixedPcdGet32(PcdCoreCount) - 1)
+ mul x3, x3, x1
+
+ // Set Primary Stack ((StackBase + PrimaryStackSize) + (SecondaryCoresCount * SecondaryCoreStackSize))
+ add sp, x0, x3
+
+ ret
+
+//VOID
+//ArmPlatformStackSetSecondary (
+// IN UINTN StackBase,
+// IN UINTN MpId,
+// IN UINTN PrimaryStackSize,
+// IN UINTN SecondaryStackSize
+// );
+ASM_FUNC(ArmPlatformStackSetSecondary)
+ // Save the Link register
+ mov x24, x30
+ mov sp, x0
+
+ // Get Core Position
+ mov x0, x1
+ bl ASM_PFX(ArmPlatformGetCorePosition)
+ mov x25, x0
+
+ // Get Primary Core Position
+ bl ASM_PFX(ArmPlatformGetPrimaryCoreMpId)
+ bl ASM_PFX(ArmPlatformGetCorePosition)
+
+ // Get Secondary Core Position. We should get consecutive secondary stack number from 1...(CoreCount-1)
+ cmp x25, x0
+
+ // Decrement the position if after the primary core
+ cinc x25, x25, ls
+
+ // Compute top of the secondary stack
+ mul x3, x3, x25
+
+ // Set stack
+ add sp, sp, x3
+
+ ret x24
diff --git a/roms/edk2/ArmPlatformPkg/Library/ArmPlatformStackLib/Arm/ArmPlatformStackLib.S b/roms/edk2/ArmPlatformPkg/Library/ArmPlatformStackLib/Arm/ArmPlatformStackLib.S new file mode 100644 index 000000000..0e47032ed --- /dev/null +++ b/roms/edk2/ArmPlatformPkg/Library/ArmPlatformStackLib/Arm/ArmPlatformStackLib.S @@ -0,0 +1,98 @@ +//
+// Copyright (c) 2012-2013, ARM Limited. All rights reserved.
+//
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+//
+//
+
+#include <AsmMacroIoLib.h>
+
+//VOID
+//ArmPlatformStackSet (
+// IN UINTN StackBase,
+// IN UINTN MpId,
+// IN UINTN PrimaryStackSize,
+// IN UINTN SecondaryStackSize
+// );
+ASM_FUNC(ArmPlatformStackSet)
+ // Save parameters
+ mov r6, r3
+ mov r5, r2
+ mov r4, r1
+ mov r3, r0
+
+ // Save the Link register
+ mov r7, lr
+
+ // Identify Stack
+ mov r0, r1
+ bl ASM_PFX(ArmPlatformIsPrimaryCore)
+ cmp r0, #1
+
+ // Restore parameters
+ mov r0, r3
+ mov r1, r4
+ mov r2, r5
+ mov r3, r6
+
+ // Restore the Link register
+ mov lr, r7
+
+ beq ASM_PFX(ArmPlatformStackSetPrimary)
+ bne ASM_PFX(ArmPlatformStackSetSecondary)
+
+//VOID
+//ArmPlatformStackSetPrimary (
+// IN UINTN StackBase,
+// IN UINTN MpId,
+// IN UINTN PrimaryStackSize,
+// IN UINTN SecondaryStackSize
+// );
+ASM_FUNC(ArmPlatformStackSetPrimary)
+ mov r4, lr
+
+ // Add stack of primary stack to StackBase
+ add r0, r0, r2
+
+ // Compute SecondaryCoresCount * SecondaryCoreStackSize
+ MOV32 (r1, FixedPcdGet32(PcdCoreCount) - 1)
+ mul r3, r3, r1
+
+ // Set Primary Stack ((StackBase + PrimaryStackSize) + (SecondaryCoresCount * SecondaryCoreStackSize))
+ add sp, r0, r3
+
+ bx r4
+
+//VOID
+//ArmPlatformStackSetSecondary (
+// IN UINTN StackBase,
+// IN UINTN MpId,
+// IN UINTN PrimaryStackSize,
+// IN UINTN SecondaryStackSize
+// );
+ASM_FUNC(ArmPlatformStackSetSecondary)
+ mov r4, lr
+ mov sp, r0
+
+ // Get Core Position
+ mov r0, r1
+ bl ASM_PFX(ArmPlatformGetCorePosition)
+ mov r5, r0
+
+ // Get Primary Core Position
+ bl ASM_PFX(ArmPlatformGetPrimaryCoreMpId)
+ bl ASM_PFX(ArmPlatformGetCorePosition)
+
+ // Get Secondary Core Position. We should get consecutive secondary stack number from 1...(CoreCount-1)
+ cmp r5, r0
+ subhi r5, r5, #1
+ add r5, r5, #1
+
+ // Compute top of the secondary stack
+ mul r3, r3, r5
+
+ // Set stack
+ add sp, sp, r3
+
+ bx r4
+
diff --git a/roms/edk2/ArmPlatformPkg/Library/ArmPlatformStackLib/Arm/ArmPlatformStackLib.asm b/roms/edk2/ArmPlatformPkg/Library/ArmPlatformStackLib/Arm/ArmPlatformStackLib.asm new file mode 100644 index 000000000..2c346146d --- /dev/null +++ b/roms/edk2/ArmPlatformPkg/Library/ArmPlatformStackLib/Arm/ArmPlatformStackLib.asm @@ -0,0 +1,118 @@ +//
+// Copyright (c) 2012-2013, ARM Limited. All rights reserved.
+//
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+//
+//
+
+#include <AutoGen.h>
+
+ INCLUDE AsmMacroIoLib.inc
+
+ EXPORT ArmPlatformStackSet
+ EXPORT ArmPlatformStackSetPrimary
+ EXPORT ArmPlatformStackSetSecondary
+
+ IMPORT ArmPlatformIsPrimaryCore
+ IMPORT ArmPlatformGetCorePosition
+ IMPORT ArmPlatformGetPrimaryCoreMpId
+
+ IMPORT _gPcd_FixedAtBuild_PcdCoreCount
+
+ PRESERVE8
+ AREA ArmPlatformStackLib, CODE, READONLY
+
+//VOID
+//ArmPlatformStackSet (
+// IN UINTN StackBase,
+// IN UINTN MpId,
+// IN UINTN PrimaryStackSize,
+// IN UINTN SecondaryStackSize
+// );
+ArmPlatformStackSet FUNCTION
+ // Save parameters
+ mov r6, r3
+ mov r5, r2
+ mov r4, r1
+ mov r3, r0
+
+ // Save the Link register
+ mov r7, lr
+
+ // Identify Stack
+ mov r0, r1
+ bl ArmPlatformIsPrimaryCore
+ cmp r0, #1
+
+ // Restore parameters
+ mov r0, r3
+ mov r1, r4
+ mov r2, r5
+ mov r3, r6
+
+ // Restore the Link register
+ mov lr, r7
+
+ beq ArmPlatformStackSetPrimary
+ bne ArmPlatformStackSetSecondary
+ ENDFUNC
+
+//VOID
+//ArmPlatformStackSetPrimary (
+// IN UINTN StackBase,
+// IN UINTN MpId,
+// IN UINTN PrimaryStackSize,
+// IN UINTN SecondaryStackSize
+// );
+ArmPlatformStackSetPrimary FUNCTION
+ mov r4, lr
+
+ // Add stack of primary stack to StackBase
+ add r0, r0, r2
+
+ // Compute SecondaryCoresCount * SecondaryCoreStackSize
+ mov32 r1, FixedPcdGet32 (PcdCoreCount)
+ sub r1, #1
+ mul r3, r3, r1
+
+ // Set Primary Stack ((StackBase + PrimaryStackSize) + (SecondaryCoresCount * SecondaryCoreStackSize))
+ add sp, r0, r3
+
+ bx r4
+ ENDFUNC
+
+//VOID
+//ArmPlatformStackSetSecondary (
+// IN UINTN StackBase,
+// IN UINTN MpId,
+// IN UINTN PrimaryStackSize,
+// IN UINTN SecondaryStackSize
+// );
+ArmPlatformStackSetSecondary FUNCTION
+ mov r4, lr
+ mov sp, r0
+
+ // Get Core Position
+ mov r0, r1
+ bl ArmPlatformGetCorePosition
+ mov r5, r0
+
+ // Get Primary Core Position
+ bl ArmPlatformGetPrimaryCoreMpId
+ bl ArmPlatformGetCorePosition
+
+ // Get Secondary Core Position. We should get consecutive secondary stack number from 1...(CoreCount-1)
+ cmp r5, r0
+ subhi r5, r5, #1
+ add r5, r5, #1
+
+ // Compute top of the secondary stack
+ mul r3, r3, r5
+
+ // Set stack
+ add sp, sp, r3
+
+ bx r4
+ ENDFUNC
+
+ END
diff --git a/roms/edk2/ArmPlatformPkg/Library/ArmPlatformStackLib/ArmPlatformStackLib.inf b/roms/edk2/ArmPlatformPkg/Library/ArmPlatformStackLib/ArmPlatformStackLib.inf new file mode 100644 index 000000000..76f809c80 --- /dev/null +++ b/roms/edk2/ArmPlatformPkg/Library/ArmPlatformStackLib/ArmPlatformStackLib.inf @@ -0,0 +1,34 @@ +#/* @file
+#
+# Copyright (c) 2012, ARM Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+#*/
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = ArmPlatformStackLib
+ FILE_GUID = 5e2e44af-53c1-44c2-a801-9c149f3d6ba0
+ MODULE_TYPE = BASE
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = ArmPlatformStackLib
+
+[Packages]
+ MdePkg/MdePkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+ ArmPkg/ArmPkg.dec
+ ArmPlatformPkg/ArmPlatformPkg.dec
+
+[Sources.ARM]
+ Arm/ArmPlatformStackLib.asm | RVCT
+ Arm/ArmPlatformStackLib.S | GCC
+
+[Sources.AARCH64]
+ AArch64/ArmPlatformStackLib.S
+
+[LibraryClasses]
+ ArmPlatformLib
+
+[FixedPcd]
+ gArmPlatformTokenSpaceGuid.PcdCoreCount
|