ModuleEntryPoint.asm 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. //
  2. // Copyright (c) 2011 - 2020, Arm Limited. All rights reserved.<BR>
  3. //
  4. // SPDX-License-Identifier: BSD-2-Clause-Patent
  5. //
  6. //
  7. #include <AutoGen.h>
  8. #include <Chipset/ArmV7.h>
  9. INCLUDE AsmMacroIoLib.inc
  10. IMPORT CEntryPoint
  11. IMPORT ArmPlatformIsPrimaryCore
  12. IMPORT ArmReadMpidr
  13. IMPORT ArmPlatformPeiBootAction
  14. IMPORT ArmPlatformStackSet
  15. IMPORT mSystemMemoryEnd
  16. EXPORT _ModuleEntryPoint
  17. PRESERVE8
  18. AREA PrePiCoreEntryPoint, CODE, READONLY
  19. StartupAddr DCD CEntryPoint
  20. _ModuleEntryPoint
  21. // Do early platform specific actions
  22. bl ArmPlatformPeiBootAction
  23. // Get ID of this CPU in multi-core system
  24. bl ArmReadMpidr
  25. // Keep a copy of the MpId register value
  26. mov r8, r0
  27. _SetSVCMode
  28. // Enter SVC mode, Disable FIQ and IRQ
  29. mov r1, #(CPSR_MODE_SVC :OR: CPSR_IRQ :OR: CPSR_FIQ)
  30. msr CPSR_c, r1
  31. // Check if we can install the stack at the top of the System Memory or if we need
  32. // to install the stacks at the bottom of the Firmware Device (case the FD is located
  33. // at the top of the DRAM)
  34. _SystemMemoryEndInit
  35. adrll r1, mSystemMemoryEnd
  36. ldrd r2, r3, [r1]
  37. teq r3, #0
  38. moveq r1, r2
  39. mvnne r1, #0
  40. _SetupStackPosition
  41. // r1 = SystemMemoryTop
  42. // Calculate Top of the Firmware Device
  43. mov32 r2, FixedPcdGet32(PcdFdBaseAddress)
  44. mov32 r3, FixedPcdGet32(PcdFdSize)
  45. sub r3, r3, #1
  46. add r3, r3, r2 // r3 = FdTop = PcdFdBaseAddress + PcdFdSize
  47. // UEFI Memory Size (stacks are allocated in this region)
  48. mov32 r4, FixedPcdGet32(PcdSystemMemoryUefiRegionSize)
  49. //
  50. // Reserve the memory for the UEFI region (contain stacks on its top)
  51. //
  52. // Calculate how much space there is between the top of the Firmware and the Top of the System Memory
  53. subs r0, r1, r3 // r0 = SystemMemoryTop - FdTop
  54. bmi _SetupStack // Jump if negative (FdTop > SystemMemoryTop). Case when the PrePi is in XIP memory outside of the DRAM
  55. cmp r0, r4
  56. bge _SetupStack
  57. // Case the top of stacks is the FdBaseAddress
  58. mov r1, r2
  59. _SetupStack
  60. // r1 contains the top of the stack (and the UEFI Memory)
  61. // Because the 'push' instruction is equivalent to 'stmdb' (decrement before), we need to increment
  62. // one to the top of the stack. We check if incrementing one does not overflow (case of DRAM at the
  63. // top of the memory space)
  64. adds r9, r1, #1
  65. bcs _SetupOverflowStack
  66. _SetupAlignedStack
  67. mov r1, r9
  68. b _GetBaseUefiMemory
  69. _SetupOverflowStack
  70. // Case memory at the top of the address space. Ensure the top of the stack is EFI_PAGE_SIZE
  71. // aligned (4KB)
  72. mov32 r9, EFI_PAGE_MASK
  73. and r9, r9, r1
  74. sub r1, r1, r9
  75. _GetBaseUefiMemory
  76. // Calculate the Base of the UEFI Memory
  77. sub r9, r1, r4
  78. _GetStackBase
  79. // r1 = The top of the Mpcore Stacks
  80. // Stack for the primary core = PrimaryCoreStack
  81. mov32 r2, FixedPcdGet32(PcdCPUCorePrimaryStackSize)
  82. sub r10, r1, r2
  83. // Stack for the secondary core = Number of Cores - 1
  84. mov32 r1, (FixedPcdGet32(PcdCoreCount) - 1) * FixedPcdGet32(PcdCPUCoreSecondaryStackSize)
  85. sub r10, r10, r1
  86. // r10 = The base of the MpCore Stacks (primary stack & secondary stacks)
  87. mov r0, r10
  88. mov r1, r8
  89. //ArmPlatformStackSet(StackBase, MpId, PrimaryStackSize, SecondaryStackSize)
  90. mov32 r2, FixedPcdGet32(PcdCPUCorePrimaryStackSize)
  91. mov32 r3, FixedPcdGet32(PcdCPUCoreSecondaryStackSize)
  92. bl ArmPlatformStackSet
  93. // Is it the Primary Core ?
  94. mov r0, r8
  95. bl ArmPlatformIsPrimaryCore
  96. cmp r0, #1
  97. bne _PrepareArguments
  98. _PrepareArguments
  99. mov r0, r8
  100. mov r1, r9
  101. mov r2, r10
  102. // Move sec startup address into a data register
  103. // Ensure we're jumping to FV version of the code (not boot remapped alias)
  104. ldr r4, StartupAddr
  105. // Jump to PrePiCore C code
  106. // r0 = MpId
  107. // r1 = UefiMemoryBase
  108. // r2 = StacksBase
  109. blx r4
  110. _NeverReturn
  111. b _NeverReturn
  112. END