]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmVirtPkg/PrePi/AArch64/ModuleEntryPoint.S
ArmVirtPkg/PrePi: clear frame pointer in startup code
[mirror_edk2.git] / ArmVirtPkg / PrePi / AArch64 / ModuleEntryPoint.S
index d6be3454183411e2d0ad4c92ea79e659412c5915..99658b9abc7b2cc45fc85539b5edd893cd4ac15d 100644 (file)
@@ -1,6 +1,6 @@
 //\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 <AsmMacroIoLibV8.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
-StartupAddr:                  .8byte ASM_PFX(CEntryPoint)\r
-ASM_PFX(mSystemMemoryEnd):    .8byte 0\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 regardless of whether or not we are executing from\r
@@ -65,8 +49,7 @@ ASM_PFX(_ModuleEntryPoint):
   b     .Lreloc_loop\r
 .Lreloc_done:\r
 \r
-  // Do early platform specific actions\r
-  bl    ASM_PFX(ArmPlatformPeiBootAction)\r
+  bl    ASM_PFX(DiscoverDramFromDt)\r
 \r
   // Get ID of this CPU in Multicore system\r
   bl    ASM_PFX(ArmReadMpidr)\r
@@ -82,17 +65,14 @@ _SetupStackPosition:
   ldr   x2, PcdGet64 (PcdSystemMemorySize)\r
   sub   x2, x2, #1\r
   add   x1, x1, x2      // x1 = SystemMemoryTop = PcdSystemMemoryBase + PcdSystemMemorySize\r
-  adr   x2, mSystemMemoryEnd\r
-  str   x1, [x2]\r
 \r
   // Calculate Top of the Firmware Device\r
   ldr   x2, PcdGet64 (PcdFdBaseAddress)\r
-  ldr   w3, PcdGet32 (PcdFdSize)\r
-  sub   x3, x3, #1\r
+  MOV32 (w3, FixedPcdGet32 (PcdFdSize) - 1)\r
   add   x3, x3, x2      // x3 = FdTop = PcdFdBaseAddress + PcdFdSize\r
 \r
   // UEFI Memory Size (stacks are allocated in this region)\r
-  LoadConstantToReg (FixedPcdGet32(PcdSystemMemoryUefiRegionSize), x4)\r
+  MOV32 (x4, FixedPcdGet32(PcdSystemMemoryUefiRegionSize))\r
 \r
   //\r
   // Reserve the memory for the UEFI region (contain stacks on its top)\r
@@ -123,9 +103,7 @@ _SetupAlignedStack:
 _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, x21)\r
-  and   x21, x21, x1\r
-  sub   x1, x1, x21\r
+  and   x1, x1, ~EFI_PAGE_MASK\r
 \r
 _GetBaseUefiMemory:\r
   // Calculate the Base of the UEFI Memory\r
@@ -133,45 +111,98 @@ _GetBaseUefiMemory:
 \r
 _GetStackBase:\r
   // r1 = The top of the Mpcore Stacks\r
+  mov   sp, x1\r
+\r
   // Stack for the primary core = PrimaryCoreStack\r
-  LoadConstantToReg (FixedPcdGet32(PcdCPUCorePrimaryStackSize), x2)\r
+  MOV32 (x2, FixedPcdGet32(PcdCPUCorePrimaryStackSize))\r
   sub   x22, x1, x2\r
 \r
-  // Stack for the secondary core = Number of Cores - 1\r
-  LoadConstantToReg (FixedPcdGet32(PcdCoreCount), x0)\r
-  sub   x0, x0, #1\r
-  LoadConstantToReg (FixedPcdGet32(PcdCPUCoreSecondaryStackSize), x1)\r
-  mul   x1, x1, x0\r
-  sub   x22, x22, x1\r
-\r
-  // x22 = The base of the MpCore Stacks (primary stack & secondary stacks)\r
-  mov   x0, x22\r
-  mov   x1, x20\r
-  //ArmPlatformStackSet(StackBase, MpId, PrimaryStackSize, SecondaryStackSize)\r
-  LoadConstantToReg (FixedPcdGet32(PcdCPUCorePrimaryStackSize), x2)\r
-  LoadConstantToReg (FixedPcdGet32(PcdCPUCoreSecondaryStackSize), x3)\r
-  bl    ASM_PFX(ArmPlatformStackSet)\r
-\r
-  // Is it the Primary Core ?\r
-  mov   x0, x10\r
-  bl    ASM_PFX(ArmPlatformIsPrimaryCore)\r
-  cmp   x0, #1\r
-  bne   _PrepareArguments\r
-\r
-_PrepareArguments:\r
   mov   x0, x20\r
   mov   x1, x21\r
   mov   x2, x22\r
 \r
-  // Move sec startup address into a data register\r
-  // Ensure we're jumping to FV version of the code (not boot remapped alias)\r
-  ldr   x4, StartupAddr\r
+  // Set the frame pointer to NULL so any backtraces terminate here\r
+  mov   x29, xzr\r
 \r
   // Jump to PrePiCore C code\r
   //    x0 = MpId\r
   //    x1 = UefiMemoryBase\r
   //    x2 = StacksBase\r
-  blr   x4\r
+  bl    ASM_PFX(CEntryPoint)\r
 \r
 _NeverReturn:\r
   b _NeverReturn\r
+\r
+// VOID\r
+// DiscoverDramFromDt (\r
+//   VOID   *DeviceTreeBaseAddress,   // passed by loader in x0\r
+//   VOID   *ImageBase                // passed by FDF trampoline in x1\r
+//   );\r
+ASM_PFX(DiscoverDramFromDt):\r
+  //\r
+  // If we are booting from RAM using the Linux kernel boot protocol, x0 will\r
+  // point to the DTB image in memory. Otherwise, use the default value defined\r
+  // by the platform.\r
+  //\r
+  cbnz  x0, 0f\r
+  ldr   x0, PcdGet64 (PcdDeviceTreeInitialBaseAddress)\r
+\r
+0:mov   x29, x30            // preserve LR\r
+  mov   x28, x0             // preserve DTB pointer\r
+  mov   x27, x1             // preserve base of image pointer\r
+\r
+  //\r
+  // The base of the runtime image has been preserved in x1. Check whether\r
+  // the expected magic number can be found in the header.\r
+  //\r
+  ldr   w8, .LArm64LinuxMagic\r
+  ldr   w9, [x1, #0x38]\r
+  cmp   w8, w9\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 arm64 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
+  adr   x8, PcdGet64 (PcdFdBaseAddress)\r
+  adr   x9, PcdGet64 (PcdFvBaseAddress)\r
+  ldr   x6, [x8]\r
+  ldr   x7, [x9]\r
+  sub   x7, x7, x6\r
+  add   x7, x7, x1\r
+  str   x1, [x8]\r
+  str   x7, [x9]\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
+  adr   x1, PcdGet64 (PcdSystemMemoryBase)\r
+  adr   x2, PcdGet64 (PcdSystemMemorySize)\r
+  mov   sp, x7\r
+  bl    FindMemnode\r
+  cbz   x0, .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
+  adr   x8, PcdGet64 (PcdDeviceTreeInitialBaseAddress)\r
+  add   x27, x27, #0x40\r
+  str   x27, [x8]\r
+\r
+  mov   x0, x27\r
+  mov   x1, x28\r
+  bl    CopyFdt\r
+\r
+.Lout:\r
+  ret    x29\r
+\r
+.LArm64LinuxMagic:\r
+  .byte   0x41, 0x52, 0x4d, 0x64\r