]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPlatformPkg/PrePi/AArch64/ModuleEntryPoint.S
ArmPlatformPkg/PrePi: switch to ASM_FUNC() asm macro
[mirror_edk2.git] / ArmPlatformPkg / PrePi / AArch64 / ModuleEntryPoint.S
1 //
2 // Copyright (c) 2011-2015, 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 <AsmMacroIoLibV8.h>
15
16 ASM_GLOBAL ASM_PFX(mSystemMemoryEnd)
17
18 ASM_FUNC(_ModuleEntryPoint)
19 // Do early platform specific actions
20 bl ASM_PFX(ArmPlatformPeiBootAction)
21
22 // Get ID of this CPU in Multicore system
23 bl ASM_PFX(ArmReadMpidr)
24 // Keep a copy of the MpId register value
25 mov x10, x0
26
27 _SetSVCMode:
28 // Check if we can install the stack at the top of the System Memory or if we need
29 // to install the stacks at the bottom of the Firmware Device (case the FD is located
30 // at the top of the DRAM)
31 _SystemMemoryEndInit:
32 ldr x1, mSystemMemoryEnd
33
34 // Is mSystemMemoryEnd initialized?
35 cmp x1, #0
36 bne _SetupStackPosition
37
38 MOV64 (x1, FixedPcdGet64(PcdSystemMemoryBase) + FixedPcdGet64(PcdSystemMemorySize) - 1)
39
40 // Update the global variable
41 adr x2, mSystemMemoryEnd
42 str x1, [x2]
43
44 _SetupStackPosition:
45 // r1 = SystemMemoryTop
46
47 // Calculate Top of the Firmware Device
48 MOV64 (x2, FixedPcdGet64(PcdFdBaseAddress))
49 MOV32 (x3, FixedPcdGet32(PcdFdSize) - 1)
50 sub x3, x3, #1
51 add x3, x3, x2 // x3 = FdTop = PcdFdBaseAddress + PcdFdSize
52
53 // UEFI Memory Size (stacks are allocated in this region)
54 MOV32 (x4, FixedPcdGet32(PcdSystemMemoryUefiRegionSize))
55
56 //
57 // Reserve the memory for the UEFI region (contain stacks on its top)
58 //
59
60 // Calculate how much space there is between the top of the Firmware and the Top of the System Memory
61 subs x0, x1, x3 // x0 = SystemMemoryTop - FdTop
62 b.mi _SetupStack // Jump if negative (FdTop > SystemMemoryTop). Case when the PrePi is in XIP memory outside of the DRAM
63 cmp x0, x4
64 b.ge _SetupStack
65
66 // Case the top of stacks is the FdBaseAddress
67 mov x1, x2
68
69 _SetupStack:
70 // x1 contains the top of the stack (and the UEFI Memory)
71
72 // Because the 'push' instruction is equivalent to 'stmdb' (decrement before), we need to increment
73 // one to the top of the stack. We check if incrementing one does not overflow (case of DRAM at the
74 // top of the memory space)
75 adds x11, x1, #1
76 b.cs _SetupOverflowStack
77
78 _SetupAlignedStack:
79 mov x1, x11
80 b _GetBaseUefiMemory
81
82 _SetupOverflowStack:
83 // Case memory at the top of the address space. Ensure the top of the stack is EFI_PAGE_SIZE
84 // aligned (4KB)
85 and x1, x1, ~EFI_PAGE_MASK
86
87 _GetBaseUefiMemory:
88 // Calculate the Base of the UEFI Memory
89 sub x11, x1, x4
90
91 _GetStackBase:
92 // r1 = The top of the Mpcore Stacks
93 // Stack for the primary core = PrimaryCoreStack
94 MOV32 (x2, FixedPcdGet32(PcdCPUCorePrimaryStackSize))
95 sub x12, x1, x2
96
97 // Stack for the secondary core = Number of Cores - 1
98 MOV32 (x1, (FixedPcdGet32(PcdCoreCount) - 1) * FixedPcdGet32(PcdCPUCoreSecondaryStackSize))
99 sub x12, x12, x1
100
101 // x12 = The base of the MpCore Stacks (primary stack & secondary stacks)
102 mov x0, x12
103 mov x1, x10
104 //ArmPlatformStackSet(StackBase, MpId, PrimaryStackSize, SecondaryStackSize)
105 MOV32 (x2, FixedPcdGet32(PcdCPUCorePrimaryStackSize))
106 MOV32 (x3, FixedPcdGet32(PcdCPUCoreSecondaryStackSize))
107 bl ASM_PFX(ArmPlatformStackSet)
108
109 // Is it the Primary Core ?
110 mov x0, x10
111 bl ASM_PFX(ArmPlatformIsPrimaryCore)
112 cmp x0, #1
113 bne _PrepareArguments
114
115 _PrepareArguments:
116 mov x0, x10
117 mov x1, x11
118 mov x2, x12
119
120 // Move sec startup address into a data register
121 // Ensure we're jumping to FV version of the code (not boot remapped alias)
122 ldr x4, =ASM_PFX(CEntryPoint)
123
124 // Jump to PrePiCore C code
125 // x0 = MpId
126 // x1 = UefiMemoryBase
127 // x2 = StacksBase
128 blr x4
129
130 _NeverReturn:
131 b _NeverReturn
132
133 ASM_PFX(mSystemMemoryEnd): .8byte 0