]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmVirtPkg/ArmXenRelocatablePlatformLib: add ARM support
authorArd Biesheuvel <ard.biesheuvel@linaro.org>
Thu, 17 Dec 2015 17:11:25 +0000 (17:11 +0000)
committerabiesheuvel <abiesheuvel@Edk2>
Thu, 17 Dec 2015 17:11:25 +0000 (17:11 +0000)
This is a port of the AARCH64 low level init routines to ARM. This
mainly covers the platform boot code that extracts the system base
and size from the DTB, copies it and updates the FD and FV base
addresses according to the load time offset.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Acked-by: Laszlo Ersek <lersek@redhat.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@19332 6f19259b-4bc3-4df7-8a09-765794883524

ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/ARM/RelocatableVirtHelper.S [new file with mode: 0644]
ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/ArmXenRelocatablePlatformLib.inf

diff --git a/ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/ARM/RelocatableVirtHelper.S b/ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/ARM/RelocatableVirtHelper.S
new file mode 100644 (file)
index 0000000..b69c6d6
--- /dev/null
@@ -0,0 +1,140 @@
+#\r
+#  Copyright (c) 2011-2013, ARM Limited. All rights reserved.\r
+#  Copyright (c) 2014, 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
+#  which accompanies this distribution.  The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+\r
+#include <AsmMacroIoLib.h>\r
+#include <Base.h>\r
+#include <Library/ArmLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <AutoGen.h>\r
+\r
+.text\r
+.align 2\r
+\r
+GCC_ASM_EXPORT(ArmPlatformPeiBootAction)\r
+GCC_ASM_EXPORT(ArmPlatformIsPrimaryCore)\r
+GCC_ASM_EXPORT(ArmPlatformGetPrimaryCoreMpId)\r
+GCC_ASM_EXPORT(ArmPlatformGetCorePosition)\r
+GCC_ASM_EXPORT(ArmGetPhysAddrTop)\r
+\r
+GCC_ASM_IMPORT(_gPcd_FixedAtBuild_PcdArmPrimaryCore)\r
+GCC_ASM_IMPORT(_gPcd_FixedAtBuild_PcdArmPrimaryCoreMask)\r
+GCC_ASM_IMPORT(_gPcd_FixedAtBuild_PcdCoreCount)\r
+\r
+.LArm32LinuxMagic:\r
+  .byte   0x18, 0x28, 0x6f, 0x01\r
+\r
+ASM_PFX(ArmPlatformPeiBootAction):\r
+  mov   r11, r14            // preserve LR\r
+  mov   r10, r0             // preserve DTB pointer\r
+  mov   r9, r1              // preserve base of image pointer\r
+\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, we are just coming out of\r
+  // reset, and r0 will be 0.\r
+  //\r
+  teq   r0, #0\r
+  beq   .Lout\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
+  ldr   r8, =PcdGet64 (PcdFdBaseAddress)\r
+  ldr   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
+  ldr   r1, =PcdGet64 (PcdSystemMemorySize)\r
+  ldr   r2, =PcdGet64 (PcdSystemMemoryBase)\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
+  ldr   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
+//UINTN\r
+//ArmPlatformGetPrimaryCoreMpId (\r
+//  VOID\r
+//  );\r
+ASM_PFX(ArmPlatformGetPrimaryCoreMpId):\r
+  LoadConstantToReg (_gPcd_FixedAtBuild_PcdArmPrimaryCore, r0)\r
+  ldr    r0, [r0]\r
+  bx     lr\r
+\r
+//UINTN\r
+//ArmPlatformIsPrimaryCore (\r
+//  IN UINTN MpId\r
+//  );\r
+ASM_PFX(ArmPlatformIsPrimaryCore):\r
+  mov   r0, #1\r
+  bx    lr\r
+\r
+//UINTN\r
+//ArmPlatformGetCorePosition (\r
+//  IN UINTN MpId\r
+//  );\r
+// With this function: CorePos = (ClusterId * 4) + CoreId\r
+ASM_PFX(ArmPlatformGetCorePosition):\r
+  and   r1, r0, #ARM_CORE_MASK\r
+  and   r0, r0, #ARM_CLUSTER_MASK\r
+  add   r0, r1, r0, LSR #6\r
+  bx    lr\r
+\r
+//EFI_PHYSICAL_ADDRESS\r
+//GetPhysAddrTop (\r
+//  VOID\r
+//  );\r
+ASM_PFX(ArmGetPhysAddrTop):\r
+  mov   r0, #0x00000000\r
+  mov   r1, #0x10000\r
+  bx    lr\r
+\r
index fce3e11922bcf9e83a52e2077227668ae635323f..b8cb24514d4c95d17df331f34c8ee7182e5622ce 100644 (file)
@@ -42,6 +42,9 @@
 [Sources.AARCH64]\r
   AARCH64/RelocatableVirtHelper.S\r
 \r
+[Sources.ARM]\r
+  ARM/RelocatableVirtHelper.S\r
+\r
 [FeaturePcd]\r
   gEmbeddedTokenSpaceGuid.PcdCacheEnable\r
   gArmPlatformTokenSpaceGuid.PcdSystemMemoryInitializeInSec\r