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