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
\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
mov x0, x20\r
mov x1, x21\r
mov x2, x22\r
\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
\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