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