2011-07-01 13:09:00 +02:00
|
|
|
//
|
2013-01-25 13:05:17 +01:00
|
|
|
// Copyright (c) 2011-2013, ARM Limited. All rights reserved.
|
2011-07-01 13:09:00 +02:00
|
|
|
//
|
|
|
|
// This program and the accompanying materials
|
|
|
|
// are licensed and made available under the terms and conditions of the BSD License
|
|
|
|
// which accompanies this distribution. The full text of the license may be found at
|
|
|
|
// http://opensource.org/licenses/bsd-license.php
|
|
|
|
//
|
|
|
|
// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|
|
|
//
|
|
|
|
//
|
|
|
|
|
|
|
|
#include <AsmMacroIoLib.h>
|
|
|
|
#include <Base.h>
|
|
|
|
#include <Library/PcdLib.h>
|
|
|
|
#include <AutoGen.h>
|
|
|
|
|
2013-01-25 13:05:17 +01:00
|
|
|
#include <Chipset/ArmV7.h>
|
|
|
|
|
2011-07-01 13:09:00 +02:00
|
|
|
INCLUDE AsmMacroIoLib.inc
|
|
|
|
|
|
|
|
IMPORT CEntryPoint
|
2011-09-23 01:01:13 +02:00
|
|
|
IMPORT ArmReadMpidr
|
2012-09-28 12:43:28 +02:00
|
|
|
IMPORT ArmPlatformStackSet
|
|
|
|
|
2011-07-01 13:09:00 +02:00
|
|
|
EXPORT _ModuleEntryPoint
|
|
|
|
|
|
|
|
PRESERVE8
|
|
|
|
AREA PrePiCoreEntryPoint, CODE, READONLY
|
|
|
|
|
|
|
|
StartupAddr DCD CEntryPoint
|
|
|
|
|
|
|
|
_ModuleEntryPoint
|
2011-09-23 01:01:13 +02:00
|
|
|
// Get ID of this CPU in Multicore system
|
|
|
|
bl ArmReadMpidr
|
|
|
|
LoadConstantToReg (FixedPcdGet32(PcdArmPrimaryCoreMask), r1)
|
2012-09-28 13:01:36 +02:00
|
|
|
and r6, r0, r1
|
2011-07-01 13:09:00 +02:00
|
|
|
|
2011-07-06 18:27:21 +02:00
|
|
|
_SetSVCMode
|
2011-11-02 00:41:52 +01:00
|
|
|
// Enter SVC mode, Disable FIQ and IRQ
|
2013-01-25 13:05:17 +01:00
|
|
|
mov r1, #(CPSR_MODE_SVC :OR: CPSR_IRQ :OR: CPSR_FIQ)
|
2011-07-06 18:27:21 +02:00
|
|
|
msr CPSR_c, r1
|
|
|
|
|
2011-09-23 01:05:20 +02:00
|
|
|
// Check if we can install the stack at the top of the System Memory or if we need
|
2011-07-06 18:27:21 +02:00
|
|
|
// to install the stacks at the bottom of the Firmware Device (case the FD is located
|
|
|
|
// at the top of the DRAM)
|
|
|
|
_SetupStackPosition
|
2011-07-01 13:09:00 +02:00
|
|
|
// Compute Top of System Memory
|
|
|
|
LoadConstantToReg (FixedPcdGet32(PcdSystemMemoryBase), r1)
|
|
|
|
LoadConstantToReg (FixedPcdGet32(PcdSystemMemorySize), r2)
|
2012-02-28 18:22:13 +01:00
|
|
|
sub r2, r2, #1
|
2011-07-01 13:09:00 +02:00
|
|
|
add r1, r1, r2 // r1 = SystemMemoryTop = PcdSystemMemoryBase + PcdSystemMemorySize
|
|
|
|
|
2011-07-06 18:27:21 +02:00
|
|
|
// Calculate Top of the Firmware Device
|
2011-09-23 01:06:31 +02:00
|
|
|
LoadConstantToReg (FixedPcdGet32(PcdFdBaseAddress), r2)
|
|
|
|
LoadConstantToReg (FixedPcdGet32(PcdFdSize), r3)
|
2012-02-28 18:22:13 +01:00
|
|
|
sub r3, r3, #1
|
2012-03-26 12:48:45 +02:00
|
|
|
add r3, r3, r2 // r3 = FdTop = PcdFdBaseAddress + PcdFdSize
|
2011-07-06 18:27:21 +02:00
|
|
|
|
|
|
|
// UEFI Memory Size (stacks are allocated in this region)
|
|
|
|
LoadConstantToReg (FixedPcdGet32(PcdSystemMemoryUefiRegionSize), r4)
|
|
|
|
|
|
|
|
//
|
|
|
|
// Reserve the memory for the UEFI region (contain stacks on its top)
|
|
|
|
//
|
|
|
|
|
|
|
|
// Calculate how much space there is between the top of the Firmware and the Top of the System Memory
|
2011-09-23 01:05:20 +02:00
|
|
|
subs r0, r1, r3 // r0 = SystemMemoryTop - FdTop
|
|
|
|
bmi _SetupStack // Jump if negative (FdTop > SystemMemoryTop). Case when the PrePi is in XIP memory outside of the DRAM
|
|
|
|
cmp r0, r4
|
2011-07-06 18:27:21 +02:00
|
|
|
bge _SetupStack
|
|
|
|
|
|
|
|
// Case the top of stacks is the FdBaseAddress
|
|
|
|
mov r1, r2
|
2011-07-01 13:09:00 +02:00
|
|
|
|
|
|
|
_SetupStack
|
2011-09-23 01:05:20 +02:00
|
|
|
// r1 contains the top of the stack (and the UEFI Memory)
|
2011-07-06 18:27:21 +02:00
|
|
|
|
2012-02-28 18:22:13 +01:00
|
|
|
// Because the 'push' instruction is equivalent to 'stmdb' (decrement before), we need to increment
|
|
|
|
// one to the top of the stack. We check if incrementing one does not overflow (case of DRAM at the
|
|
|
|
// top of the memory space)
|
2012-09-28 13:01:36 +02:00
|
|
|
adds r7, r1, #1
|
2012-02-28 18:22:13 +01:00
|
|
|
bcs _SetupOverflowStack
|
|
|
|
|
|
|
|
_SetupAlignedStack
|
2012-09-28 13:01:36 +02:00
|
|
|
mov r1, r7
|
2012-02-28 18:22:13 +01:00
|
|
|
b _GetBaseUefiMemory
|
|
|
|
|
|
|
|
_SetupOverflowStack
|
|
|
|
// Case memory at the top of the address space. Ensure the top of the stack is EFI_PAGE_SIZE
|
|
|
|
// aligned (4KB)
|
2012-09-28 13:01:36 +02:00
|
|
|
LoadConstantToReg (EFI_PAGE_MASK, r7)
|
|
|
|
and r7, r7, r1
|
|
|
|
sub r1, r1, r7
|
2012-02-28 18:22:13 +01:00
|
|
|
|
|
|
|
_GetBaseUefiMemory
|
2011-07-06 18:27:21 +02:00
|
|
|
// Calculate the Base of the UEFI Memory
|
2012-09-28 13:01:36 +02:00
|
|
|
sub r7, r1, r4
|
2011-07-01 13:09:00 +02:00
|
|
|
|
2011-09-23 01:05:20 +02:00
|
|
|
_GetStackBase
|
2012-02-28 18:23:53 +01:00
|
|
|
// r1 = The top of the Mpcore Stacks
|
2011-09-23 01:05:20 +02:00
|
|
|
// Stack for the primary core = PrimaryCoreStack
|
|
|
|
LoadConstantToReg (FixedPcdGet32(PcdCPUCorePrimaryStackSize), r2)
|
2012-09-28 12:43:28 +02:00
|
|
|
sub r8, r1, r2
|
|
|
|
|
|
|
|
// Stack for the secondary core = Number of Cores - 1
|
|
|
|
LoadConstantToReg (FixedPcdGet32(PcdCoreCount), r0)
|
|
|
|
sub r0, r0, #1
|
|
|
|
LoadConstantToReg (FixedPcdGet32(PcdCPUCoreSecondaryStackSize), r1)
|
|
|
|
mul r1, r1, r0
|
|
|
|
sub r8, r8, r1
|
|
|
|
|
|
|
|
// r8 = The base of the MpCore Stacks (primary stack & secondary stacks)
|
|
|
|
mov r0, r8
|
|
|
|
mov r1, r6
|
|
|
|
//ArmPlatformStackSet(StackBase, MpId, PrimaryStackSize, SecondaryStackSize)
|
|
|
|
LoadConstantToReg (FixedPcdGet32(PcdCPUCorePrimaryStackSize), r2)
|
2011-09-23 01:05:20 +02:00
|
|
|
LoadConstantToReg (FixedPcdGet32(PcdCPUCoreSecondaryStackSize), r3)
|
2012-09-28 13:01:36 +02:00
|
|
|
bl ArmPlatformStackSet
|
2011-09-23 01:05:20 +02:00
|
|
|
|
|
|
|
// Is it the Primary Core ?
|
|
|
|
LoadConstantToReg (FixedPcdGet32(PcdArmPrimaryCore), r4)
|
2012-09-28 13:01:36 +02:00
|
|
|
cmp r6, r4
|
2011-07-01 13:09:00 +02:00
|
|
|
bne _PrepareArguments
|
|
|
|
|
2012-09-28 13:01:36 +02:00
|
|
|
_ReserveGlobalVariable
|
|
|
|
LoadConstantToReg (FixedPcdGet32(PcdPeiGlobalVariableSize), r0)
|
|
|
|
// InitializePrimaryStack($GlobalVariableSize, $Tmp1)
|
|
|
|
InitializePrimaryStack r0, r1
|
2011-09-23 01:05:20 +02:00
|
|
|
|
2011-07-01 13:09:00 +02:00
|
|
|
_PrepareArguments
|
2012-09-28 13:01:36 +02:00
|
|
|
mov r0, r6
|
|
|
|
mov r1, r7
|
|
|
|
mov r2, r8
|
2011-09-23 01:07:55 +02:00
|
|
|
mov r3, sp
|
|
|
|
|
2011-07-01 13:09:00 +02:00
|
|
|
// Move sec startup address into a data register
|
|
|
|
// Ensure we're jumping to FV version of the code (not boot remapped alias)
|
2011-09-23 01:07:55 +02:00
|
|
|
ldr r4, StartupAddr
|
2011-07-01 13:09:00 +02:00
|
|
|
|
2011-07-06 18:27:21 +02:00
|
|
|
// Jump to PrePiCore C code
|
2011-09-23 01:01:13 +02:00
|
|
|
// r0 = MpId
|
2011-07-01 13:09:00 +02:00
|
|
|
// r1 = UefiMemoryBase
|
2011-09-23 01:07:55 +02:00
|
|
|
// r2 = StacksBase
|
|
|
|
// r3 = GlobalVariableBase
|
|
|
|
blx r4
|
2011-07-01 13:09:00 +02:00
|
|
|
|
2011-09-23 01:05:20 +02:00
|
|
|
_NeverReturn
|
|
|
|
b _NeverReturn
|
|
|
|
|
2011-07-01 13:09:00 +02:00
|
|
|
END
|