\r
#include <AsmMacroIoLib.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
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
MOV32 (r3, FixedPcdGet32(PcdCPUCoreSecondaryStackSize))\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
_NeverReturn:\r
b _NeverReturn\r
\r
-ASM_PFX(mSystemMemoryEnd): .quad 0\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