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