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