1# 2# Copyright (c) 2011-2013, ARM Limited. All rights reserved. 3# Copyright (c) 2014, Linaro Limited. All rights reserved. 4# 5# This program and the accompanying materials 6# are licensed and made available under the terms and conditions of the BSD License 7# which accompanies this distribution. The full text of the license may be found at 8# http://opensource.org/licenses/bsd-license.php 9# 10# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 11# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 12# 13# 14 15#include <AsmMacroIoLib.h> 16#include <Base.h> 17#include <Library/ArmLib.h> 18#include <Library/PcdLib.h> 19#include <AutoGen.h> 20 21.text 22.align 2 23 24GCC_ASM_EXPORT(ArmPlatformPeiBootAction) 25GCC_ASM_EXPORT(ArmPlatformIsPrimaryCore) 26GCC_ASM_EXPORT(ArmPlatformGetPrimaryCoreMpId) 27GCC_ASM_EXPORT(ArmPlatformGetCorePosition) 28GCC_ASM_EXPORT(ArmGetPhysAddrTop) 29 30GCC_ASM_IMPORT(_gPcd_FixedAtBuild_PcdArmPrimaryCore) 31GCC_ASM_IMPORT(_gPcd_FixedAtBuild_PcdArmPrimaryCoreMask) 32GCC_ASM_IMPORT(_gPcd_FixedAtBuild_PcdCoreCount) 33 34.LArm32LinuxMagic: 35 .byte 0x18, 0x28, 0x6f, 0x01 36 37ASM_PFX(ArmPlatformPeiBootAction): 38 mov r11, r14 // preserve LR 39 mov r10, r0 // preserve DTB pointer 40 mov r9, r1 // preserve base of image pointer 41 42 // 43 // If we are booting from RAM using the Linux kernel boot protocol, r0 will 44 // point to the DTB image in memory. Otherwise, we are just coming out of 45 // reset, and r0 will be 0. 46 // 47 teq r0, #0 48 beq .Lout 49 50 // 51 // The base of the runtime image has been preserved in r1. Check whether 52 // the expected magic number can be found in the header. 53 // 54 ldr r8, .LArm32LinuxMagic 55 ldr r7, [r1, #0x24] 56 cmp r7, r8 57 bne .Lout 58 59 // 60 // 61 // OK, so far so good. We have confirmed that we likely have a DTB and are 62 // booting via the ARM Linux boot protocol. Update the base-of-image PCD 63 // to the actual relocated value, and add the shift of PcdFdBaseAddress to 64 // PcdFvBaseAddress as well 65 // 66 ldr r8, =PcdGet64 (PcdFdBaseAddress) 67 ldr r7, =PcdGet64 (PcdFvBaseAddress) 68 ldr r6, [r8] 69 ldr r5, [r7] 70 sub r5, r5, r6 71 add r5, r5, r1 72 str r1, [r8] 73 str r5, [r7] 74 75 // 76 // Discover the memory size and offset from the DTB, and record in the 77 // respective PCDs. This will also return false if a corrupt DTB is 78 // encountered. Since we are calling a C function, use the window at the 79 // beginning of the FD image as a temp stack. 80 // 81 ldr r1, =PcdGet64 (PcdSystemMemorySize) 82 ldr r2, =PcdGet64 (PcdSystemMemoryBase) 83 mov sp, r5 84 bl FindMemnode 85 teq r0, #0 86 beq .Lout 87 88 // 89 // Copy the DTB to the slack space right after the 64 byte arm64/Linux style 90 // image header at the base of this image (defined in the FDF), and record the 91 // pointer in PcdDeviceTreeInitialBaseAddress. 92 // 93 ldr r8, =PcdGet64 (PcdDeviceTreeInitialBaseAddress) 94 add r9, r9, #0x40 95 str r9, [r8] 96 97 mov r0, r9 98 mov r1, r10 99 bl CopyFdt 100 101.Lout: 102 bx r11 103 104//UINTN 105//ArmPlatformGetPrimaryCoreMpId ( 106// VOID 107// ); 108ASM_PFX(ArmPlatformGetPrimaryCoreMpId): 109 LoadConstantToReg (_gPcd_FixedAtBuild_PcdArmPrimaryCore, r0) 110 ldr r0, [r0] 111 bx lr 112 113//UINTN 114//ArmPlatformIsPrimaryCore ( 115// IN UINTN MpId 116// ); 117ASM_PFX(ArmPlatformIsPrimaryCore): 118 mov r0, #1 119 bx lr 120 121//UINTN 122//ArmPlatformGetCorePosition ( 123// IN UINTN MpId 124// ); 125// With this function: CorePos = (ClusterId * 4) + CoreId 126ASM_PFX(ArmPlatformGetCorePosition): 127 and r1, r0, #ARM_CORE_MASK 128 and r0, r0, #ARM_CLUSTER_MASK 129 add r0, r1, r0, LSR #6 130 bx lr 131 132//EFI_PHYSICAL_ADDRESS 133//GetPhysAddrTop ( 134// VOID 135// ); 136ASM_PFX(ArmGetPhysAddrTop): 137 mov r0, #0x00000000 138 mov r1, #0x10000 139 bx lr 140 141