]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmVirtPkg/PrePi/AArch64/ModuleEntryPoint.S
ArmVirtPkg/PrePi: remove ArmPlatformStackLib dependency
[mirror_edk2.git] / ArmVirtPkg / PrePi / AArch64 / ModuleEntryPoint.S
index 9c040b17f253b7f9ef4951c1bdb932b80102bb98..891cf1fcab400c0842035be6a2fb003bafd63040 100644 (file)
@@ -14,8 +14,6 @@
 \r
 #include <AsmMacroIoLibV8.h>\r
 \r
-ASM_GLOBAL ASM_PFX(mSystemMemoryEnd)\r
-\r
 ASM_FUNC(_ModuleEntryPoint)\r
   //\r
   // We are built as a ET_DYN PIE executable, so we need to process all\r
@@ -51,8 +49,7 @@ ASM_FUNC(_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
@@ -68,8 +65,6 @@ _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
@@ -116,29 +111,12 @@ _GetBaseUefiMemory:
 \r
 _GetStackBase:\r
   // r1 = The top of the Mpcore Stacks\r
+  mov   sp, x1\r
+\r
   // Stack for the primary core = PrimaryCoreStack\r
   MOV32 (x2, FixedPcdGet32(PcdCPUCorePrimaryStackSize))\r
   sub   x22, x1, x2\r
 \r
-  // Stack for the secondary core = Number of Cores - 1\r
-  MOV32 (x1, (FixedPcdGet32(PcdCoreCount) - 1) * FixedPcdGet32(PcdCPUCoreSecondaryStackSize))\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
-  MOV32 (x2, FixedPcdGet32(PcdCPUCorePrimaryStackSize))\r
-  MOV32 (x3, FixedPcdGet32(PcdCPUCoreSecondaryStackSize))\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
@@ -152,4 +130,76 @@ _PrepareArguments:
 _NeverReturn:\r
   b _NeverReturn\r
 \r
-ASM_PFX(mSystemMemoryEnd):    .8byte 0\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