]>
Commit | Line | Data |
---|---|---|
2dbcb8f0 | 1 | //\r |
1377db63 | 2 | // Copyright (c) 2011-2012, ARM Limited. All rights reserved.\r |
2dbcb8f0 | 3 | // \r |
4 | // This program and the accompanying materials \r | |
5 | // are licensed and made available under the terms and conditions of the BSD License \r | |
6 | // which accompanies this distribution. The full text of the license may be found at \r | |
7 | // http://opensource.org/licenses/bsd-license.php \r | |
8 | //\r | |
9 | // THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r | |
10 | // WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r | |
11 | //\r | |
12 | //\r | |
11c20f4e | 13 | \r |
2dbcb8f0 | 14 | #include <AutoGen.h>\r |
11c20f4e | 15 | #include <AsmMacroIoLib.h>\r |
90d6a1bb | 16 | #include "SecInternal.h"\r |
11c20f4e | 17 | \r |
11c20f4e | 18 | .text\r |
19 | .align 3\r | |
20 | \r | |
11c20f4e | 21 | GCC_ASM_IMPORT(CEntryPoint)\r |
44e272fd | 22 | GCC_ASM_IMPORT(ArmPlatformSecBootAction)\r |
e314d564 | 23 | GCC_ASM_IMPORT(ArmPlatformSecBootMemoryInit)\r |
11c20f4e | 24 | GCC_ASM_IMPORT(ArmDisableInterrupts)\r |
25 | GCC_ASM_IMPORT(ArmDisableCachesAndMmu)\r | |
0787bc61 | 26 | GCC_ASM_IMPORT(ArmReadMpidr)\r |
b1d41be7 | 27 | GCC_ASM_IMPORT(ArmCallWFE)\r |
90d6a1bb | 28 | GCC_ASM_EXPORT(_ModuleEntryPoint)\r |
11c20f4e | 29 | \r |
2dbcb8f0 | 30 | StartupAddr: .word ASM_PFX(CEntryPoint)\r |
11c20f4e | 31 | \r |
32 | ASM_PFX(_ModuleEntryPoint):\r | |
2dbcb8f0 | 33 | // First ensure all interrupts are disabled\r |
34 | bl ASM_PFX(ArmDisableInterrupts)\r | |
11c20f4e | 35 | \r |
2dbcb8f0 | 36 | // Ensure that the MMU and caches are off\r |
37 | bl ASM_PFX(ArmDisableCachesAndMmu)\r | |
11c20f4e | 38 | \r |
a75568e9 | 39 | // By default, we are doing a cold boot\r |
40 | mov r10, #ARM_SEC_COLD_BOOT\r | |
41 | \r | |
2dbcb8f0 | 42 | // Jump to Platform Specific Boot Action function\r |
44e272fd | 43 | blx ASM_PFX(ArmPlatformSecBootAction)\r |
44 | \r | |
2dbcb8f0 | 45 | _IdentifyCpu:\r |
46 | // Identify CPU ID\r | |
11c20f4e | 47 | bl ASM_PFX(ArmReadMpidr)\r |
0787bc61 | 48 | // Get ID of this CPU in Multicore system\r |
49 | LoadConstantToReg (FixedPcdGet32(PcdArmPrimaryCoreMask), r1)\r | |
50 | and r5, r0, r1\r | |
11c20f4e | 51 | \r |
2dbcb8f0 | 52 | // Is it the Primary Core ?\r |
1377db63 | 53 | LoadConstantToReg (FixedPcdGet32(PcdArmPrimaryCore), r3)\r |
54 | cmp r5, r3\r | |
2dbcb8f0 | 55 | // Only the primary core initialize the memory (SMC)\r |
11c20f4e | 56 | beq _InitMem\r |
57 | \r | |
90d6a1bb | 58 | _WaitInitMem:\r |
a75568e9 | 59 | // If we are not doing a cold boot in this case we should assume the Initial Memory to be already initialized\r |
60 | // Otherwise we have to wait the Primary Core to finish the initialization\r | |
61 | cmp r10, #ARM_SEC_COLD_BOOT\r | |
62 | bne _SetupSecondaryCoreStack\r | |
63 | \r | |
b1d41be7 | 64 | // Wait for the primary core to initialize the initial memory (event: BOOT_MEM_INIT)\r |
65 | bl ASM_PFX(ArmCallWFE)\r | |
90d6a1bb | 66 | // Now the Init Mem is initialized, we setup the secondary core stacks\r |
2dbcb8f0 | 67 | b _SetupSecondaryCoreStack\r |
11c20f4e | 68 | \r |
69 | _InitMem:\r | |
8cfd2e24 | 70 | // If we are not doing a cold boot in this case we should assume the Initial Memory to be already initialized\r |
71 | cmp r10, #ARM_SEC_COLD_BOOT\r | |
72 | bne _SetupPrimaryCoreStack\r | |
73 | \r | |
f156d5b4 | 74 | // Initialize Init Boot Memory\r |
e314d564 | 75 | bl ASM_PFX(ArmPlatformSecBootMemoryInit)\r |
2dbcb8f0 | 76 | \r |
77 | // Only Primary CPU could run this line (the secondary cores have jumped from _IdentifyCpu to _SetupStack)\r | |
78 | LoadConstantToReg (FixedPcdGet32(PcdArmPrimaryCore), r5)\r | |
79 | \r | |
80 | _SetupPrimaryCoreStack:\r | |
1377db63 | 81 | // Get the top of the primary stacks (and the base of the secondary stacks)\r |
82 | LoadConstantToReg (FixedPcdGet32(PcdCPUCoresSecStackBase), r1)\r | |
83 | LoadConstantToReg (FixedPcdGet32(PcdCPUCoreSecPrimaryStackSize), r2)\r | |
84 | add r1, r1, r2\r | |
85 | \r | |
86 | LoadConstantToReg (FixedPcdGet32(PcdSecGlobalVariableSize), r2)\r | |
2dbcb8f0 | 87 | \r |
88 | // The reserved space for global variable must be 8-bytes aligned for pushing\r | |
89 | // 64-bit variable on the stack\r | |
1377db63 | 90 | SetPrimaryStack (r1, r2, r3)\r |
91 | b _PrepareArguments\r | |
2dbcb8f0 | 92 | \r |
93 | _SetupSecondaryCoreStack:\r | |
1377db63 | 94 | // Get the top of the primary stacks (and the base of the secondary stacks)\r |
95 | LoadConstantToReg (FixedPcdGet32(PcdCPUCoresSecStackBase), r1)\r | |
96 | LoadConstantToReg (FixedPcdGet32(PcdCPUCoreSecPrimaryStackSize), r2)\r | |
97 | add r1, r1, r2\r | |
98 | \r | |
2dbcb8f0 | 99 | // Get the Core Position (ClusterId * 4) + CoreId\r |
a32dae48 | 100 | GetCorePositionFromMpId(r0, r5, r2)\r |
2dbcb8f0 | 101 | // The stack starts at the top of the stack region. Add '1' to the Core Position to get the top of the stack\r |
102 | add r0, r0, #1\r | |
103 | \r | |
2dbcb8f0 | 104 | // StackOffset = CorePos * StackSize\r |
1377db63 | 105 | LoadConstantToReg (FixedPcdGet32(PcdCPUCoreSecSecondaryStackSize), r2)\r |
2dbcb8f0 | 106 | mul r0, r0, r2\r |
107 | // SP = StackBase + StackOffset\r | |
108 | add sp, r1, r0\r | |
11c20f4e | 109 | \r |
2dbcb8f0 | 110 | _PrepareArguments:\r |
111 | // Move sec startup address into a data register\r | |
112 | // Ensure we're jumping to FV version of the code (not boot remapped alias)\r | |
11c20f4e | 113 | ldr r3, StartupAddr\r |
114 | \r | |
2dbcb8f0 | 115 | // Jump to SEC C code\r |
116 | // r0 = mp_id\r | |
a75568e9 | 117 | // r1 = Boot Mode\r |
11c20f4e | 118 | mov r0, r5\r |
a75568e9 | 119 | mov r1, r10\r |
2dbcb8f0 | 120 | blx r3\r |
121 | \r | |
122 | _NeverReturn:\r | |
123 | b _NeverReturn\r |