//\r
// Copyright (c) 2011-2013, ARM Limited. All rights reserved.\r
-// Copyright (c) 2015, Linaro Limited. All rights reserved.\r
+// Copyright (c) 2015-2016, Linaro Limited. All rights reserved.\r
//\r
// This program and the accompanying materials\r
// are licensed and made available under the terms and conditions of the BSD License\r
//\r
\r
#include <AsmMacroIoLib.h>\r
-#include <Base.h>\r
-#include <Library/PcdLib.h>\r
-#include <AutoGen.h>\r
\r
-.text\r
-.align 3\r
-\r
-GCC_ASM_IMPORT(ArmPlatformIsPrimaryCore)\r
-GCC_ASM_IMPORT(ArmReadMpidr)\r
-GCC_ASM_IMPORT(ArmPlatformPeiBootAction)\r
-GCC_ASM_IMPORT(ArmPlatformStackSet)\r
-GCC_ASM_EXPORT(_ModuleEntryPoint)\r
-ASM_GLOBAL ASM_PFX(mSystemMemoryEnd)\r
-\r
-ASM_PFX(mSystemMemoryEnd): .quad 0\r
-\r
-__relocs:\r
- .long __reloc_base - __relocs\r
- .long __reloc_start - __relocs\r
- .long __reloc_end - __relocs\r
-\r
-ASM_PFX(_ModuleEntryPoint):\r
+ASM_FUNC(_ModuleEntryPoint)\r
//\r
// We are built as a ET_DYN PIE executable, so we need to process all\r
// relative relocations if we are executing from a different offset than we\r
// were linked at. This is only possible if we are running from RAM.\r
//\r
-\r
- adr r12, __relocs\r
- ldrd r4, r5, [r12]\r
- ldr r6, [r12, #8]\r
-\r
- add r4, r4, r12\r
- add r5, r5, r12\r
- add r6, r6, r12\r
+ ADRL (r4, __reloc_base)\r
+ ADRL (r5, __reloc_start)\r
+ ADRL (r6, __reloc_end)\r
\r
.Lreloc_loop:\r
cmp r5, r6\r
// at the top of the DRAM)\r
_SetupStackPosition:\r
// Compute Top of System Memory\r
- ldr r12, =PcdGet64 (PcdSystemMemoryBase)\r
- ldr r1, [r12]\r
- ldr r12, =PcdGet64 (PcdSystemMemorySize)\r
+ LDRL (r1, PcdGet64 (PcdSystemMemoryBase))\r
+ ADRL (r12, PcdGet64 (PcdSystemMemorySize))\r
ldrd r2, r3, [r12]\r
\r
- // calculate the top of memory, and record it in mSystemMemoryEnd\r
+ // calculate the top of memory\r
adds r2, r2, r1\r
sub r2, r2, #1\r
addcs r3, r3, #1\r
- adr r12, mSystemMemoryEnd\r
- strd r2, r3, [r12]\r
\r
// truncate the memory used by UEFI to 4 GB range\r
teq r3, #0\r
moveq r1, r2\r
\r
// Calculate Top of the Firmware Device\r
- ldr r12, =PcdGet64 (PcdFdBaseAddress)\r
- ldr r2, [r12]\r
- ldr r3, =FixedPcdGet32 (PcdFdSize)\r
- sub r3, r3, #1\r
+ LDRL (r2, PcdGet64 (PcdFdBaseAddress))\r
+ MOV32 (r3, FixedPcdGet32 (PcdFdSize) - 1)\r
add r3, r3, r2 // r3 = FdTop = PcdFdBaseAddress + PcdFdSize\r
\r
// UEFI Memory Size (stacks are allocated in this region)\r
- LoadConstantToReg (FixedPcdGet32(PcdSystemMemoryUefiRegionSize), r4)\r
+ MOV32 (r4, FixedPcdGet32(PcdSystemMemoryUefiRegionSize))\r
\r
//\r
// Reserve the memory for the UEFI region (contain stacks on its top)\r
_SetupOverflowStack:\r
// Case memory at the top of the address space. Ensure the top of the stack is EFI_PAGE_SIZE\r
// aligned (4KB)\r
- LoadConstantToReg (EFI_PAGE_MASK, r11)\r
- and r11, r11, r1\r
- sub r1, r1, r11\r
+ MOV32 (r11, (~EFI_PAGE_MASK) & 0xffffffff)\r
+ and r1, r1, r11\r
\r
_GetBaseUefiMemory:\r
// Calculate the Base of the UEFI Memory\r
\r
_GetStackBase:\r
// r1 = The top of the Mpcore Stacks\r
+ mov sp, r1\r
+\r
// Stack for the primary core = PrimaryCoreStack\r
- LoadConstantToReg (FixedPcdGet32(PcdCPUCorePrimaryStackSize), r2)\r
+ MOV32 (r2, FixedPcdGet32(PcdCPUCorePrimaryStackSize))\r
sub r9, r1, r2\r
\r
- // Stack for the secondary core = Number of Cores - 1\r
- LoadConstantToReg (FixedPcdGet32(PcdCoreCount), r0)\r
- sub r0, r0, #1\r
- LoadConstantToReg (FixedPcdGet32(PcdCPUCoreSecondaryStackSize), r1)\r
- mul r1, r1, r0\r
- sub r9, r9, r1\r
-\r
- // r9 = The base of the MpCore Stacks (primary stack & secondary stacks)\r
- mov r0, r9\r
- mov r1, r10\r
- //ArmPlatformStackSet(StackBase, MpId, PrimaryStackSize, SecondaryStackSize)\r
- LoadConstantToReg (FixedPcdGet32(PcdCPUCorePrimaryStackSize), r2)\r
- LoadConstantToReg (FixedPcdGet32(PcdCPUCoreSecondaryStackSize), r3)\r
- bl ASM_PFX(ArmPlatformStackSet)\r
-\r
- // Is it the Primary Core ?\r
- mov r0, r10\r
- bl ASM_PFX(ArmPlatformIsPrimaryCore)\r
- cmp r0, #1\r
- bne _PrepareArguments\r
-\r
-_PrepareArguments:\r
mov r0, r10\r
mov r1, r11\r
mov r2, r9\r
\r
_NeverReturn:\r
b _NeverReturn\r
+\r
+ASM_PFX(ArmPlatformPeiBootAction):\r
+ //\r
+ // If we are booting from RAM using the Linux kernel boot protocol, r0 will\r
+ // point to the DTB image in memory. Otherwise, use the default value defined\r
+ // by the platform.\r
+ //\r
+ teq r0, #0\r
+ bne 0f\r
+ LDRL (r0, PcdGet64 (PcdDeviceTreeInitialBaseAddress))\r
+\r
+0:mov r11, r14 // preserve LR\r
+ mov r10, r0 // preserve DTB pointer\r
+ mov r9, r1 // preserve base of image pointer\r
+\r
+ //\r
+ // The base of the runtime image has been preserved in r1. Check whether\r
+ // the expected magic number can be found in the header.\r
+ //\r
+ ldr r8, .LArm32LinuxMagic\r
+ ldr r7, [r1, #0x24]\r
+ cmp r7, r8\r
+ bne .Lout\r
+\r
+ //\r
+ //\r
+ // OK, so far so good. We have confirmed that we likely have a DTB and are\r
+ // booting via the ARM Linux boot protocol. Update the base-of-image PCD\r
+ // to the actual relocated value, and add the shift of PcdFdBaseAddress to\r
+ // PcdFvBaseAddress as well\r
+ //\r
+ ADRL (r8, PcdGet64 (PcdFdBaseAddress))\r
+ ADRL (r7, PcdGet64 (PcdFvBaseAddress))\r
+ ldr r6, [r8]\r
+ ldr r5, [r7]\r
+ sub r5, r5, r6\r
+ add r5, r5, r1\r
+ str r1, [r8]\r
+ str r5, [r7]\r
+\r
+ //\r
+ // Discover the memory size and offset from the DTB, and record in the\r
+ // respective PCDs. This will also return false if a corrupt DTB is\r
+ // encountered. Since we are calling a C function, use the window at the\r
+ // beginning of the FD image as a temp stack.\r
+ //\r
+ ADRL (r1, PcdGet64 (PcdSystemMemoryBase))\r
+ ADRL (r2, PcdGet64 (PcdSystemMemorySize))\r
+ mov sp, r5\r
+ bl FindMemnode\r
+ teq r0, #0\r
+ beq .Lout\r
+\r
+ //\r
+ // Copy the DTB to the slack space right after the 64 byte arm64/Linux style\r
+ // image header at the base of this image (defined in the FDF), and record the\r
+ // pointer in PcdDeviceTreeInitialBaseAddress.\r
+ //\r
+ ADRL (r8, PcdGet64 (PcdDeviceTreeInitialBaseAddress))\r
+ add r9, r9, #0x40\r
+ str r9, [r8]\r
+\r
+ mov r0, r9\r
+ mov r1, r10\r
+ bl CopyFdt\r
+\r
+.Lout:\r
+ bx r11\r
+\r
+.LArm32LinuxMagic:\r
+ .byte 0x18, 0x28, 0x6f, 0x01\r