]>
Commit | Line | Data |
---|---|---|
90d6a1bb | 1 | //\r |
1377db63 | 2 | // Copyright (c) 2011-2012, ARM Limited. All rights reserved.\r |
90d6a1bb | 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 | |
13 | \r | |
14 | #include <AutoGen.h>\r | |
15 | #include <AsmMacroIoLib.h>\r | |
16 | #include "SecInternal.h"\r | |
17 | \r | |
18 | INCLUDE AsmMacroIoLib.inc\r | |
19 | \r | |
20 | IMPORT CEntryPoint\r | |
21 | IMPORT ArmPlatformSecBootAction\r | |
e314d564 | 22 | IMPORT ArmPlatformSecBootMemoryInit\r |
90d6a1bb | 23 | IMPORT ArmDisableInterrupts\r |
24 | IMPORT ArmDisableCachesAndMmu\r | |
25 | IMPORT ArmWriteVBar\r | |
26 | IMPORT ArmReadMpidr\r | |
b1d41be7 | 27 | IMPORT ArmCallWFE\r |
90d6a1bb | 28 | IMPORT SecVectorTable\r |
90d6a1bb | 29 | EXPORT _ModuleEntryPoint\r |
30 | \r | |
31 | PRESERVE8\r | |
32 | AREA SecEntryPoint, CODE, READONLY\r | |
33 | \r | |
34 | StartupAddr DCD CEntryPoint\r | |
35 | \r | |
a75568e9 | 36 | _ModuleEntryPoint FUNCTION\r |
90d6a1bb | 37 | // First ensure all interrupts are disabled\r |
38 | blx ArmDisableInterrupts\r | |
39 | \r | |
40 | // Ensure that the MMU and caches are off\r | |
41 | blx ArmDisableCachesAndMmu\r | |
42 | \r | |
a75568e9 | 43 | // By default, we are doing a cold boot\r |
44 | mov r10, #ARM_SEC_COLD_BOOT\r | |
45 | \r | |
90d6a1bb | 46 | // Jump to Platform Specific Boot Action function\r |
47 | blx ArmPlatformSecBootAction\r | |
48 | \r | |
49 | // Set VBAR to the start of the exception vectors in Secure Mode\r | |
50 | ldr r0, =SecVectorTable\r | |
51 | blx ArmWriteVBar\r | |
52 | \r | |
53 | _IdentifyCpu \r | |
54 | // Identify CPU ID\r | |
55 | bl ArmReadMpidr\r | |
56 | // Get ID of this CPU in Multicore system\r | |
57 | LoadConstantToReg (FixedPcdGet32(PcdArmPrimaryCoreMask), r1)\r | |
58 | and r5, r0, r1\r | |
59 | \r | |
60 | // Is it the Primary Core ?\r | |
1377db63 | 61 | LoadConstantToReg (FixedPcdGet32(PcdArmPrimaryCore), r3)\r |
62 | cmp r5, r3\r | |
90d6a1bb | 63 | // Only the primary core initialize the memory (SMC)\r |
64 | beq _InitMem\r | |
65 | \r | |
66 | _WaitInitMem\r | |
a75568e9 | 67 | // If we are not doing a cold boot in this case we should assume the Initial Memory to be already initialized\r |
68 | // Otherwise we have to wait the Primary Core to finish the initialization\r | |
69 | cmp r10, #ARM_SEC_COLD_BOOT\r | |
70 | bne _SetupSecondaryCoreStack\r | |
71 | \r | |
b1d41be7 | 72 | // Wait for the primary core to initialize the initial memory (event: BOOT_MEM_INIT)\r |
73 | bl ArmCallWFE\r | |
90d6a1bb | 74 | // Now the Init Mem is initialized, we setup the secondary core stacks\r |
75 | b _SetupSecondaryCoreStack\r | |
76 | \r | |
77 | _InitMem\r | |
78 | // Initialize Init Boot Memory\r | |
e314d564 | 79 | bl ArmPlatformSecBootMemoryInit\r |
90d6a1bb | 80 | \r |
81 | // Only Primary CPU could run this line (the secondary cores have jumped from _IdentifyCpu to _SetupStack)\r | |
82 | LoadConstantToReg (FixedPcdGet32(PcdArmPrimaryCore), r5)\r | |
83 | \r | |
84 | _SetupPrimaryCoreStack\r | |
1377db63 | 85 | // Get the top of the primary stacks (and the base of the secondary stacks)\r |
86 | LoadConstantToReg (FixedPcdGet32(PcdCPUCoresSecStackBase), r1)\r | |
87 | LoadConstantToReg (FixedPcdGet32(PcdCPUCoreSecPrimaryStackSize), r2)\r | |
88 | add r1, r1, r2\r | |
89 | \r | |
90 | LoadConstantToReg (FixedPcdGet32(PcdSecGlobalVariableSize), r2)\r | |
90d6a1bb | 91 | \r |
92 | // The reserved space for global variable must be 8-bytes aligned for pushing\r | |
93 | // 64-bit variable on the stack\r | |
1377db63 | 94 | SetPrimaryStack (r1, r2, r3)\r |
95 | b _PrepareArguments\r | |
90d6a1bb | 96 | \r |
97 | _SetupSecondaryCoreStack\r | |
1377db63 | 98 | // Get the top of the primary stacks (and the base of the secondary stacks)\r |
99 | LoadConstantToReg (FixedPcdGet32(PcdCPUCoresSecStackBase), r1)\r | |
100 | LoadConstantToReg (FixedPcdGet32(PcdCPUCoreSecPrimaryStackSize), r2)\r | |
101 | add r1, r1, r2\r | |
102 | \r | |
90d6a1bb | 103 | // Get the Core Position (ClusterId * 4) + CoreId\r |
1377db63 | 104 | GetCorePositionInStack(r0, r5, r2)\r |
90d6a1bb | 105 | // The stack starts at the top of the stack region. Add '1' to the Core Position to get the top of the stack\r |
106 | add r0, r0, #1\r | |
107 | \r | |
90d6a1bb | 108 | // StackOffset = CorePos * StackSize\r |
1377db63 | 109 | LoadConstantToReg (FixedPcdGet32(PcdCPUCoreSecSecondaryStackSize), r2)\r |
90d6a1bb | 110 | mul r0, r0, r2\r |
111 | // SP = StackBase + StackOffset\r | |
112 | add sp, r1, r0\r | |
113 | \r | |
90d6a1bb | 114 | _PrepareArguments\r |
115 | // Move sec startup address into a data register\r | |
116 | // Ensure we're jumping to FV version of the code (not boot remapped alias)\r | |
117 | ldr r3, StartupAddr\r | |
118 | \r | |
119 | // Jump to SEC C code\r | |
120 | // r0 = mp_id\r | |
a75568e9 | 121 | // r1 = Boot Mode\r |
90d6a1bb | 122 | mov r0, r5\r |
a75568e9 | 123 | mov r1, r10\r |
90d6a1bb | 124 | blx r3\r |
a75568e9 | 125 | ENDFUNC\r |
90d6a1bb | 126 | \r |
127 | _NeverReturn\r | |
128 | b _NeverReturn\r | |
129 | END\r |