From patchwork Mon Jan 26 19:03:13 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 43784 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f69.google.com (mail-la0-f69.google.com [209.85.215.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 6F62520D5D for ; Mon, 26 Jan 2015 19:04:48 +0000 (UTC) Received: by mail-la0-f69.google.com with SMTP id gm9sf5321736lab.0 for ; Mon, 26 Jan 2015 11:04:47 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:subject:precedence:reply-to:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version :content-type:content-transfer-encoding:errors-to:x-original-sender :x-original-authentication-results:mailing-list; bh=JW/ueMvylJZVbViZjSa0HqOc+yFVyTQ3WngpRnuo3ck=; b=bHk8VVT32Q52as1NHJi6FqApGxALOHc1kLwE9QujHA6zYVy4rxxT5vtIukygYNe8Dv +1uakFAYBvJ8OJS7/dnRJoUlNrX7lC+JzGge4NFtsaQZqXO8ovY3Hu06j0EHm/Uoh2ra odnVn27y2GB/Iqd1NapsUHCMYspm8WBufALKWQlPjxEYdqLIWyVV5bmLjIOo76YTyrGb W4gkYuGOQwMsohdZf95px1qB0TsrYbPrTHgcNnDFzKxF78X+E0m2y4+WT+68zAZfyYaG x2mtY6H4tC+mJiS+XO7/ln11vxKfm6V7kldP+2KIg3dLtTLFJrmUzbvst4swaMLCRAZy 7KvQ== X-Gm-Message-State: ALoCoQkxarruAagiYqam0mJ+PYMqlFTLRsPqeMtfl6JMsuDbX1k/VwkAjXU/kxWzv9tQgPrcetbe X-Received: by 10.112.175.10 with SMTP id bw10mr1553332lbc.7.1422299087433; Mon, 26 Jan 2015 11:04:47 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.19.73 with SMTP id c9ls562459lae.74.gmail; Mon, 26 Jan 2015 11:04:47 -0800 (PST) X-Received: by 10.112.159.195 with SMTP id xe3mr22777859lbb.64.1422299087282; Mon, 26 Jan 2015 11:04:47 -0800 (PST) Received: from mail-lb0-f171.google.com (mail-lb0-f171.google.com. [209.85.217.171]) by mx.google.com with ESMTPS id l9si9850504lah.3.2015.01.26.11.04.47 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 26 Jan 2015 11:04:47 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.171 as permitted sender) client-ip=209.85.217.171; Received: by mail-lb0-f171.google.com with SMTP id u14so9237497lbd.2 for ; Mon, 26 Jan 2015 11:04:47 -0800 (PST) X-Received: by 10.112.90.170 with SMTP id bx10mr8307592lbb.69.1422299087163; Mon, 26 Jan 2015 11:04:47 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.35.133 with SMTP id h5csp870374lbj; Mon, 26 Jan 2015 11:04:46 -0800 (PST) X-Received: by 10.42.236.81 with SMTP id kj17mr22520957icb.60.1422299082090; Mon, 26 Jan 2015 11:04:42 -0800 (PST) Received: from lists.sourceforge.net (lists.sourceforge.net. [216.34.181.88]) by mx.google.com with ESMTPS id h2si8468937icu.107.2015.01.26.11.04.41 (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 26 Jan 2015 11:04:42 -0800 (PST) Received-SPF: pass (google.com: domain of edk2-devel-bounces@lists.sourceforge.net designates 216.34.181.88 as permitted sender) client-ip=216.34.181.88; Received: from localhost ([127.0.0.1] helo=sfs-ml-2.v29.ch3.sourceforge.com) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1YFoxY-00078e-04; Mon, 26 Jan 2015 19:04:28 +0000 Received: from sog-mx-2.v43.ch3.sourceforge.com ([172.29.43.192] helo=mx.sourceforge.net) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1YFoxX-00078T-1l for edk2-devel@lists.sourceforge.net; Mon, 26 Jan 2015 19:04:27 +0000 Received-SPF: pass (sog-mx-2.v43.ch3.sourceforge.com: domain of linaro.org designates 74.125.82.181 as permitted sender) client-ip=74.125.82.181; envelope-from=ard.biesheuvel@linaro.org; helo=mail-we0-f181.google.com; Received: from mail-we0-f181.google.com ([74.125.82.181]) by sog-mx-2.v43.ch3.sourceforge.com with esmtps (TLSv1:RC4-SHA:128) (Exim 4.76) id 1YFoxW-00072Y-Fc for edk2-devel@lists.sourceforge.net; Mon, 26 Jan 2015 19:04:28 +0000 Received: by mail-we0-f181.google.com with SMTP id k48so10863894wev.12 for ; Mon, 26 Jan 2015 11:04:21 -0800 (PST) X-Received: by 10.180.96.4 with SMTP id do4mr34970808wib.46.1422299061519; Mon, 26 Jan 2015 11:04:21 -0800 (PST) Received: from ards-macbook-pro.local ([197.129.8.190]) by mx.google.com with ESMTPSA id fo17sm15471007wjc.19.2015.01.26.11.04.18 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 26 Jan 2015 11:04:20 -0800 (PST) From: Ard Biesheuvel To: edk2-devel@lists.sourceforge.net, lersek@redhat.com, olivier.martin@arm.com, roy.franz@linaro.org, leif.lindholm@linaro.org, stefano.stabellini@eu.citrix.com, ian.campbell@citrix.com, anthony.perard@citrix.com, christoffer.dall@linaro.org, xen-devel@lists.xen.org, ilias.biris@linaro.org Date: Mon, 26 Jan 2015 19:03:13 +0000 Message-Id: <1422299011-2409-12-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1422299011-2409-1-git-send-email-ard.biesheuvel@linaro.org> References: <1422299011-2409-1-git-send-email-ard.biesheuvel@linaro.org> X-Spam-Score: -1.5 (-) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -1.5 SPF_CHECK_PASS SPF reports sender host as permitted sender for sender-domain -0.0 SPF_PASS SPF: sender matches SPF record -0.0 AWL AWL: Adjusted score from AWL reputation of From: address X-Headers-End: 1YFoxW-00072Y-Fc Subject: [edk2] [PATCH v2 11/29] ArmPlatformPkg/PrePi: add a relocatable version of PrePi X-BeenThere: edk2-devel@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list Reply-To: edk2-devel@lists.sourceforge.net List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.sourceforge.net X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ard.biesheuvel@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.171 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 This patch introduces a relocatable PrePi, which can execute from arbitrary offsets in RAM. This is intendend to be run from a boot loader which passes a description of the actual platform in a device tree, for instance. Signed-off-by: Ard Biesheuvel --- ArmPlatformPkg/PrePi/AArch64/ModuleEntryPoint.S | 27 +++++++++++++++++++++++ ArmPlatformPkg/PrePi/MainUniCoreRelocatable.c | 38 ++++++++++++++++++++++++++++++++ ArmPlatformPkg/PrePi/PeiUniCoreRelocatable.inf | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ArmPlatformPkg/PrePi/Scripts/PrePi-PIE.lds | 28 ++++++++++++++++++++++++ 4 files changed, 204 insertions(+) diff --git a/ArmPlatformPkg/PrePi/AArch64/ModuleEntryPoint.S b/ArmPlatformPkg/PrePi/AArch64/ModuleEntryPoint.S index 3fa6bf1f0322..54ac01c4b9c3 100644 --- a/ArmPlatformPkg/PrePi/AArch64/ModuleEntryPoint.S +++ b/ArmPlatformPkg/PrePi/AArch64/ModuleEntryPoint.S @@ -28,6 +28,33 @@ GCC_ASM_EXPORT(_ModuleEntryPoint) StartupAddr: .8byte ASM_PFX(CEntryPoint) ASM_PFX(_ModuleEntryPoint): + +#if defined (SELF_RELOCATE) + // + // If we are built as a ET_DYN PIE executable, we need to process all + // relative relocations regardless of whether or not we are executing from + // the same offset we were linked at. This is only possible if we are + // running from RAM. + // + adr x8, __reloc_base + adr x9, __reloc_start + adr x10, __reloc_end + +.Lreloc_loop: + cmp x9, x10 + bhs .Lreloc_done + + ldp x11, x12, [x9], #24 + cmp x12, #0x403 // R_AARCH64_RELATIVE + bne .Lreloc_loop + + ldr x12, [x9, #-8] + add x12, x12, x8 + str x12, [x11, x8] + b .Lreloc_loop +.Lreloc_done: +#endif + // Do early platform specific actions bl ASM_PFX(ArmPlatformPeiBootAction) diff --git a/ArmPlatformPkg/PrePi/MainUniCoreRelocatable.c b/ArmPlatformPkg/PrePi/MainUniCoreRelocatable.c new file mode 100644 index 000000000000..594579971a2d --- /dev/null +++ b/ArmPlatformPkg/PrePi/MainUniCoreRelocatable.c @@ -0,0 +1,38 @@ +/** @file +* +* Copyright (c) 2011, ARM Limited. All rights reserved. +* +* This program and the accompanying materials +* are licensed and made available under the terms and conditions of the BSD License +* which accompanies this distribution. The full text of the license may be found at +* http://opensource.org/licenses/bsd-license.php +* +* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +* +**/ + +#include "PrePi.h" + +VOID +PrimaryMain ( + IN UINTN UefiMemoryBase, + IN UINTN StacksBase, + IN UINTN GlobalVariableBase, + IN UINT64 StartTimeStamp + ) +{ + PrePiMain (UefiMemoryBase, StacksBase, GlobalVariableBase, StartTimeStamp, FALSE); + + // We must never return + ASSERT(FALSE); +} + +VOID +SecondaryMain ( + IN UINTN MpId + ) +{ + // We must never get into this function on UniCore system + ASSERT(FALSE); +} diff --git a/ArmPlatformPkg/PrePi/PeiUniCoreRelocatable.inf b/ArmPlatformPkg/PrePi/PeiUniCoreRelocatable.inf new file mode 100755 index 000000000000..155aa3288341 --- /dev/null +++ b/ArmPlatformPkg/PrePi/PeiUniCoreRelocatable.inf @@ -0,0 +1,111 @@ +#/** @file +# +# Copyright (c) 2011-2014, ARM Ltd. All rights reserved.
+# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +#**/ + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = ArmPlatformPrePiUniCoreRelocatable + FILE_GUID = f7d9fd14-9335-4389-80c5-334d6abfcced + MODULE_TYPE = SEC + VALID_ARCHITECTURES = AARCH64 + VERSION_STRING = 1.0 + +[Sources] + PrePi.c + MainUniCoreRelocatable.c + +[Sources.AArch64] + AArch64/ArchPrePi.c + AArch64/ModuleEntryPoint.S + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + EmbeddedPkg/EmbeddedPkg.dec + ArmPkg/ArmPkg.dec + ArmPlatformPkg/ArmPlatformPkg.dec + ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationPkg.dec + IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec + +[LibraryClasses] + BaseLib + DebugLib + DebugAgentLib + ArmLib + IoLib + TimerLib + SerialPortLib + ExtractGuidedSectionLib + LzmaDecompressLib + PeCoffGetEntryPointLib + DebugAgentLib + PrePiLib + ArmPlatformLib + ArmPlatformStackLib + MemoryAllocationLib + HobLib + PrePiHobListPointerLib + PlatformPeiLib + MemoryInitPeiLib + +[Ppis] + gArmMpCoreInfoPpiGuid + +[Guids] + gArmGlobalVariableGuid + gArmMpCoreInfoGuid + +[FeaturePcd] + gEmbeddedTokenSpaceGuid.PcdPrePiProduceMemoryTypeInformationHob + gArmPlatformTokenSpaceGuid.PcdSendSgiToBringUpSecondaryCores + +[FixedPcd] + gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareVersionString + + gArmTokenSpaceGuid.PcdVFPEnabled + + gArmTokenSpaceGuid.PcdFdSize + gArmTokenSpaceGuid.PcdFvSize + + gArmPlatformTokenSpaceGuid.PcdCPUCorePrimaryStackSize + gArmPlatformTokenSpaceGuid.PcdCPUCoreSecondaryStackSize + + gArmPlatformTokenSpaceGuid.PcdPeiGlobalVariableSize + + gArmPlatformTokenSpaceGuid.PcdSystemMemoryUefiRegionSize + + gArmPlatformTokenSpaceGuid.PcdCoreCount + + gEmbeddedTokenSpaceGuid.PcdPrePiCpuMemorySize + gEmbeddedTokenSpaceGuid.PcdPrePiCpuIoSize + + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIReclaimMemory + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIMemoryNVS + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiReservedMemoryType + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesData + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesCode + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesCode + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesData + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderCode + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderData + +[Pcd] + gArmTokenSpaceGuid.PcdSystemMemoryBase + gArmTokenSpaceGuid.PcdSystemMemorySize + gArmVirtualizationTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress + gArmTokenSpaceGuid.PcdFdBaseAddress + gArmTokenSpaceGuid.PcdFvBaseAddress + +[BuildOptions] + GCC:*_*_AARCH64_PP_FLAGS = -DSELF_RELOCATE + GCC:*_*_AARCH64_DLINK_FLAGS = -pie -T $(MODULE_DIR)/Scripts/PrePi-PIE.lds diff --git a/ArmPlatformPkg/PrePi/Scripts/PrePi-PIE.lds b/ArmPlatformPkg/PrePi/Scripts/PrePi-PIE.lds new file mode 100644 index 000000000000..880f9b114ddd --- /dev/null +++ b/ArmPlatformPkg/PrePi/Scripts/PrePi-PIE.lds @@ -0,0 +1,28 @@ +SECTIONS +{ + .text 0x0 : { + PROVIDE(__reloc_base = .); + + *(.text .text*) + *(.got .got*) + *(.rodata .rodata*) + *(.data .data*) + + . = ALIGN(0x20); + PROVIDE(__reloc_start = .); + *(.rela .rela*) + PROVIDE(__reloc_end = .); + } + .bss ALIGN(0x20) : { *(.bss .bss*) } + + /DISCARD/ : { + *(.note.GNU-stack) + *(.gnu_debuglink) + *(.interp) + *(.dynamic) + *(.dynsym) + *(.dynstr) + *(.hash) + *(.comment) + } +}