X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=ArmVirtPkg%2FPrePi%2FAArch64%2FModuleEntryPoint.S;h=3296aedfe9aac671cc304e94a3f0aa087c111f5c;hp=7a9c0c3787cc2b4512e48df31c3cbd2a9fff7df2;hb=832709565e76a3f068848964a9c1dac4fa5d21f2;hpb=888559acf98ae954af0418c1f72bc603aa9b9e88 diff --git a/ArmVirtPkg/PrePi/AArch64/ModuleEntryPoint.S b/ArmVirtPkg/PrePi/AArch64/ModuleEntryPoint.S index 7a9c0c3787..3296aedfe9 100644 --- a/ArmVirtPkg/PrePi/AArch64/ModuleEntryPoint.S +++ b/ArmVirtPkg/PrePi/AArch64/ModuleEntryPoint.S @@ -49,8 +49,7 @@ ASM_FUNC(_ModuleEntryPoint) b .Lreloc_loop .Lreloc_done: - // Do early platform specific actions - bl ASM_PFX(ArmPlatformPeiBootAction) + bl ASM_PFX(DiscoverDramFromDt) // Get ID of this CPU in Multicore system bl ASM_PFX(ArmReadMpidr) @@ -140,3 +139,77 @@ _GetStackBase: _NeverReturn: b _NeverReturn + +// VOID +// DiscoverDramFromDt ( +// VOID *DeviceTreeBaseAddress, // passed by loader in x0 +// VOID *ImageBase // passed by FDF trampoline in x1 +// ); +ASM_PFX(DiscoverDramFromDt): + // + // If we are booting from RAM using the Linux kernel boot protocol, x0 will + // point to the DTB image in memory. Otherwise, use the default value defined + // by the platform. + // + cbnz x0, 0f + ldr x0, PcdGet64 (PcdDeviceTreeInitialBaseAddress) + +0:mov x29, x30 // preserve LR + mov x28, x0 // preserve DTB pointer + mov x27, x1 // preserve base of image pointer + + // + // The base of the runtime image has been preserved in x1. Check whether + // the expected magic number can be found in the header. + // + ldr w8, .LArm64LinuxMagic + ldr w9, [x1, #0x38] + cmp w8, w9 + bne .Lout + + // + // + // OK, so far so good. We have confirmed that we likely have a DTB and are + // booting via the arm64 Linux boot protocol. Update the base-of-image PCD + // to the actual relocated value, and add the shift of PcdFdBaseAddress to + // PcdFvBaseAddress as well + // + adr x8, PcdGet64 (PcdFdBaseAddress) + adr x9, PcdGet64 (PcdFvBaseAddress) + ldr x6, [x8] + ldr x7, [x9] + sub x7, x7, x6 + add x7, x7, x1 + str x1, [x8] + str x7, [x9] + + // + // Discover the memory size and offset from the DTB, and record in the + // respective PCDs. This will also return false if a corrupt DTB is + // encountered. Since we are calling a C function, use the window at the + // beginning of the FD image as a temp stack. + // + adr x1, PcdGet64 (PcdSystemMemoryBase) + adr x2, PcdGet64 (PcdSystemMemorySize) + mov sp, x7 + bl FindMemnode + cbz x0, .Lout + + // + // Copy the DTB to the slack space right after the 64 byte arm64/Linux style + // image header at the base of this image (defined in the FDF), and record the + // pointer in PcdDeviceTreeInitialBaseAddress. + // + adr x8, PcdGet64 (PcdDeviceTreeInitialBaseAddress) + add x27, x27, #0x40 + str x27, [x8] + + mov x0, x27 + mov x1, x28 + bl CopyFdt + +.Lout: + ret x29 + +.LArm64LinuxMagic: + .byte 0x41, 0x52, 0x4d, 0x64