]>
Commit | Line | Data |
---|---|---|
1 | //\r | |
2 | // Copyright (c) 2011, ARM Limited. All rights reserved.\r | |
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 <AsmMacroIoLib.h>\r | |
15 | #include <Base.h>\r | |
16 | #include <Library/PcdLib.h>\r | |
17 | #include <AutoGen.h>\r | |
18 | \r | |
19 | .text\r | |
20 | .align 3\r | |
21 | \r | |
22 | # Global symbols referenced by this module\r | |
23 | GCC_ASM_IMPORT(CEntryPoint)\r | |
24 | GCC_ASM_EXPORT(_ModuleEntryPoint)\r | |
25 | \r | |
26 | StartupAddr: .word CEntryPoint\r | |
27 | \r | |
28 | \r | |
29 | ASM_PFX(_ModuleEntryPoint):\r | |
30 | // Identify CPU ID\r | |
31 | mrc p15, 0, r0, c0, c0, 5\r | |
32 | and r0, #0xf\r | |
33 | \r | |
34 | _SetSVCMode:\r | |
35 | // Enter SVC mode\r | |
36 | mov r1, #0x13|0x80|0x40\r | |
37 | msr CPSR_c, r1\r | |
38 | \r | |
39 | // Check if we can install the size at the top of the System Memory or if we need\r | |
40 | // to install the stacks at the bottom of the Firmware Device (case the FD is located\r | |
41 | // at the top of the DRAM)\r | |
42 | _SetupStackPosition:\r | |
43 | // Compute Top of System Memory\r | |
44 | LoadConstantToReg (FixedPcdGet32(PcdSystemMemoryBase), r1)\r | |
45 | LoadConstantToReg (FixedPcdGet32(PcdSystemMemorySize), r2)\r | |
46 | add r1, r1, r2 // r1 = SystemMemoryTop = PcdSystemMemoryBase + PcdSystemMemorySize\r | |
47 | \r | |
48 | // Calculate Top of the Firmware Device\r | |
49 | LoadConstantToReg (FixedPcdGet32(PcdNormalFdBaseAddress), r2)\r | |
50 | LoadConstantToReg (FixedPcdGet32(PcdNormalFdSize), r3)\r | |
51 | add r3, r3, r2 // r4 = FdTop = PcdNormalFdBaseAddress + PcdNormalFdSize\r | |
52 | \r | |
53 | // UEFI Memory Size (stacks are allocated in this region)\r | |
54 | LoadConstantToReg (FixedPcdGet32(PcdSystemMemoryUefiRegionSize), r4)\r | |
55 | \r | |
56 | //\r | |
57 | // Reserve the memory for the UEFI region (contain stacks on its top)\r | |
58 | //\r | |
59 | \r | |
60 | // Calculate how much space there is between the top of the Firmware and the Top of the System Memory\r | |
61 | subs r5, r1, r3 // r5 = SystemMemoryTop - FdTop\r | |
62 | bmi _SetupStack // Jump if negative (FdTop > SystemMemoryTop)\r | |
63 | cmp r5, r4\r | |
64 | bge _SetupStack\r | |
65 | \r | |
66 | // Case the top of stacks is the FdBaseAddress\r | |
67 | mov r1, r2\r | |
68 | \r | |
69 | _SetupStack:\r | |
70 | // Compute Base of Normal stacks for CPU Cores\r | |
71 | LoadConstantToReg (FixedPcdGet32(PcdCPUCoresNonSecStackSize), r5)\r | |
72 | mul r3, r0, r5 // r3 = core_id * stack_size = offset from the stack base\r | |
73 | sub sp, r1, r3 // r3 = (SystemMemoryTop|FdBaseAddress) - StackOffset = TopOfStack\r | |
74 | \r | |
75 | // Calculate the Base of the UEFI Memory\r | |
76 | sub r1, r1, r4\r | |
77 | \r | |
78 | // Only allocate memory for global variables at top of the primary core stack\r | |
79 | cmp r0, #0\r | |
80 | bne _PrepareArguments\r | |
81 | \r | |
82 | _AllocateGlobalPrePiVariables:\r | |
83 | // Reserve top of the stack for Global PEI Variables (eg: PeiServicesTablePointer)\r | |
84 | LoadConstantToReg (FixedPcdGet32(PcdPeiGlobalVariableSize), r4)\r | |
85 | // The reserved place must be 8-bytes aligned for pushing 64-bit variable on the stack\r | |
86 | and r5, r4, #7\r | |
87 | rsb r5, r5, #8\r | |
88 | add r4, r4, r5\r | |
89 | sub sp, sp, r4\r | |
90 | \r | |
91 | _PrepareArguments:\r | |
92 | // Move sec startup address into a data register\r | |
93 | // Ensure we're jumping to FV version of the code (not boot remapped alias)\r | |
94 | ldr r2, StartupAddr\r | |
95 | \r | |
96 | // Jump to PrePiCore C code\r | |
97 | // r0 = core_id\r | |
98 | // r1 = UefiMemoryBase\r | |
99 | blx r2\r | |
100 | \r |