\r
IMPORT CEntryPoint\r
IMPORT ArmReadMpidr\r
+ IMPORT ArmIsMpCore\r
EXPORT _ModuleEntryPoint\r
\r
PRESERVE8\r
and r5, r0, r1\r
\r
_SetSVCMode\r
- // Enter SVC mode\r
+ // Enter SVC mode, Disable FIQ and IRQ\r
mov r1, #0x13|0x80|0x40\r
msr CPSR_c, r1\r
\r
-// Check if we can install the size at the top of the System Memory or if we need\r
+// Check if we can install the stack at the top of the System Memory or if we need\r
// to install the stacks at the bottom of the Firmware Device (case the FD is located\r
// at the top of the DRAM)\r
_SetupStackPosition\r
add r1, r1, r2 // r1 = SystemMemoryTop = PcdSystemMemoryBase + PcdSystemMemorySize\r
\r
// Calculate Top of the Firmware Device\r
- LoadConstantToReg (FixedPcdGet32(PcdNormalFdBaseAddress), r2)\r
- LoadConstantToReg (FixedPcdGet32(PcdNormalFdSize), r3)\r
- add r3, r3, r2 // r4 = FdTop = PcdNormalFdBaseAddress + PcdNormalFdSize\r
+ LoadConstantToReg (FixedPcdGet32(PcdFdBaseAddress), r2)\r
+ LoadConstantToReg (FixedPcdGet32(PcdFdSize), r3)\r
+ add r3, r3, r2 // r4 = FdTop = PcdFdBaseAddress + PcdFdSize\r
\r
// UEFI Memory Size (stacks are allocated in this region)\r
LoadConstantToReg (FixedPcdGet32(PcdSystemMemoryUefiRegionSize), r4)\r
//\r
\r
// Calculate how much space there is between the top of the Firmware and the Top of the System Memory\r
- subs r5, r1, r3 // r5 = SystemMemoryTop - FdTop\r
- bmi _SetupStack // Jump if negative (FdTop > SystemMemoryTop)\r
- cmp r5, r4\r
+ subs r0, r1, r3 // r0 = SystemMemoryTop - FdTop\r
+ bmi _SetupStack // Jump if negative (FdTop > SystemMemoryTop). Case when the PrePi is in XIP memory outside of the DRAM\r
+ cmp r0, r4\r
bge _SetupStack\r
\r
// Case the top of stacks is the FdBaseAddress\r
mov r1, r2\r
\r
_SetupStack\r
- // Compute Base of Normal stacks for CPU Cores\r
- LoadConstantToReg (FixedPcdGet32(PcdCPUCoresNonSecStackSize), r5)\r
- mul r3, r0, r5 // r3 = core_id * stack_size = offset from the stack base\r
- sub sp, r1, r3 // r3 = (SystemMemoryTop|FdBaseAddress) - StackOffset = TopOfStack\r
+ // r1 contains the top of the stack (and the UEFI Memory)\r
\r
// Calculate the Base of the UEFI Memory\r
- sub r1, r1, r4\r
+ sub r6, r1, r4\r
\r
- // Only allocate memory for global variables at top of the primary core stack\r
+_GetStackBase\r
+ // Compute Base of Normal stacks for CPU Cores\r
+ // Is it MpCore system\r
+ bl ArmIsMpCore\r
cmp r0, #0\r
+ // Case it is not an MP Core system. Just setup the primary core\r
+ beq _SetupUnicoreStack\r
+\r
+_GetStackBaseMpCore\r
+ // Stack for the primary core = PrimaryCoreStack\r
+ LoadConstantToReg (FixedPcdGet32(PcdCPUCorePrimaryStackSize), r2)\r
+ sub r7, r1, r2\r
+ // Stack for the secondary core = Number of Cluster * (4 Core per cluster) * SecondaryStackSize\r
+ LoadConstantToReg (FixedPcdGet32(PcdClusterCount), r2)\r
+ lsl r2, r2, #2\r
+ LoadConstantToReg (FixedPcdGet32(PcdCPUCoreSecondaryStackSize), r3)\r
+ mul r2, r2, r3\r
+ sub r7, r7, r2\r
+\r
+ // The top of the Mpcore Stacks is in r1\r
+ // The base of the MpCore Stacks is in r7\r
+\r
+ // Is it the Primary Core ?\r
+ LoadConstantToReg (FixedPcdGet32(PcdArmPrimaryCore), r4)\r
+ cmp r5, r4\r
+ beq _SetupPrimaryCoreStack\r
+\r
+_SetupSecondaryCoreStack\r
+ // Base of the stack for the secondary cores is in r7\r
+\r
+ // Get the position of the cores (ClusterId * 4) + CoreId\r
+ GetCorePositionInStack(r0, r5, r4)\r
+ // The stack starts at the top of the stack region. Add '1' to the Core Position to get the top of the stack\r
+ add r0, r0, #1\r
+ // Get the offset for the Secondary Stack\r
+ mul r0, r0, r3\r
+ add sp, r7, r0\r
+\r
bne _PrepareArguments\r
\r
-_AllocateGlobalPrePiVariables\r
- // Reserve top of the stack for Global PEI Variables (eg: PeiServicesTablePointer)\r
- LoadConstantToReg (FixedPcdGet32(PcdPeiGlobalVariableSize), r4)\r
- // The reserved place must be 8-bytes aligned for pushing 64-bit variable on the stack\r
- and r5, r4, #7\r
- rsb r5, r5, #8\r
- add r4, r4, r5\r
- sub sp, sp, r4\r
+_SetupPrimaryCoreStack\r
+ // The top of the Mpcore Stacks is in r1\r
+ LoadConstantToReg (FixedPcdGet32(PcdPeiGlobalVariableSize), r2)\r
+\r
+ // The reserved space for global variable must be 8-bytes aligned for pushing\r
+ // 64-bit variable on the stack\r
+ SetPrimaryStack (r1, r2, r3)\r
+\r
+_SetGlobals\r
+ // Set all the PrePi global variables to 0\r
+ mov r3, sp\r
+ mov r2, #0x0\r
+_InitGlobals\r
+ cmp r3, r1\r
+ beq _PrepareArguments\r
+ str r2, [r3], #4\r
+ b _InitGlobals\r
\r
_PrepareArguments\r
+ mov r0, r5\r
+ mov r1, r6\r
+ mov r2, r7\r
+ mov r3, sp\r
+\r
// Move sec startup address into a data register\r
// Ensure we're jumping to FV version of the code (not boot remapped alias)\r
- ldr r2, StartupAddr\r
+ ldr r4, StartupAddr\r
\r
// Jump to PrePiCore C code\r
// r0 = MpId\r
// r1 = UefiMemoryBase\r
- blx r2\r
+ // r2 = StacksBase\r
+ // r3 = GlobalVariableBase\r
+ blx r4\r
+\r
+_NeverReturn\r
+ b _NeverReturn\r
+\r
+_SetupUnicoreStack\r
+ // The top of the Unicore Stack is in r1\r
+ LoadConstantToReg (FixedPcdGet32(PcdPeiGlobalVariableSize), r2)\r
+ LoadConstantToReg (FixedPcdGet32(PcdCPUCorePrimaryStackSize), r3)\r
+\r
+ // Calculate the bottom of the primary stack (StackBase)\r
+ sub r7, r1, r3\r
+\r
+ // The reserved space for global variable must be 8-bytes aligned for pushing\r
+ // 64-bit variable on the stack\r
+ SetPrimaryStack (r1, r2, r3)\r
+\r
+ b _SetGlobals\r
\r
END\r