ArmPlatformStackLib.S 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. //
  2. // Copyright (c) 2012-2013, ARM Limited. All rights reserved.
  3. //
  4. // SPDX-License-Identifier: BSD-2-Clause-Patent
  5. //
  6. //
  7. #include <AsmMacroIoLib.h>
  8. //VOID
  9. //ArmPlatformStackSet (
  10. // IN UINTN StackBase,
  11. // IN UINTN MpId,
  12. // IN UINTN PrimaryStackSize,
  13. // IN UINTN SecondaryStackSize
  14. // );
  15. ASM_FUNC(ArmPlatformStackSet)
  16. // Save parameters
  17. mov r6, r3
  18. mov r5, r2
  19. mov r4, r1
  20. mov r3, r0
  21. // Save the Link register
  22. mov r7, lr
  23. // Identify Stack
  24. mov r0, r1
  25. bl ASM_PFX(ArmPlatformIsPrimaryCore)
  26. cmp r0, #1
  27. // Restore parameters
  28. mov r0, r3
  29. mov r1, r4
  30. mov r2, r5
  31. mov r3, r6
  32. // Restore the Link register
  33. mov lr, r7
  34. beq ASM_PFX(ArmPlatformStackSetPrimary)
  35. bne ASM_PFX(ArmPlatformStackSetSecondary)
  36. //VOID
  37. //ArmPlatformStackSetPrimary (
  38. // IN UINTN StackBase,
  39. // IN UINTN MpId,
  40. // IN UINTN PrimaryStackSize,
  41. // IN UINTN SecondaryStackSize
  42. // );
  43. ASM_FUNC(ArmPlatformStackSetPrimary)
  44. mov r4, lr
  45. // Add stack of primary stack to StackBase
  46. add r0, r0, r2
  47. // Compute SecondaryCoresCount * SecondaryCoreStackSize
  48. MOV32 (r1, FixedPcdGet32(PcdCoreCount) - 1)
  49. mul r3, r3, r1
  50. // Set Primary Stack ((StackBase + PrimaryStackSize) + (SecondaryCoresCount * SecondaryCoreStackSize))
  51. add sp, r0, r3
  52. bx r4
  53. //VOID
  54. //ArmPlatformStackSetSecondary (
  55. // IN UINTN StackBase,
  56. // IN UINTN MpId,
  57. // IN UINTN PrimaryStackSize,
  58. // IN UINTN SecondaryStackSize
  59. // );
  60. ASM_FUNC(ArmPlatformStackSetSecondary)
  61. mov r4, lr
  62. mov sp, r0
  63. // Get Core Position
  64. mov r0, r1
  65. bl ASM_PFX(ArmPlatformGetCorePosition)
  66. mov r5, r0
  67. // Get Primary Core Position
  68. bl ASM_PFX(ArmPlatformGetPrimaryCoreMpId)
  69. bl ASM_PFX(ArmPlatformGetCorePosition)
  70. // Get Secondary Core Position. We should get consecutive secondary stack number from 1...(CoreCount-1)
  71. cmp r5, r0
  72. subhi r5, r5, #1
  73. add r5, r5, #1
  74. // Compute top of the secondary stack
  75. mul r3, r3, r5
  76. // Set stack
  77. add sp, sp, r3
  78. bx r4