From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by mx.groups.io with SMTP id smtpd.web10.8874.1591492634907673430 for ; Sat, 06 Jun 2020 18:17:15 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@intel.onmicrosoft.com header.s=selector2-intel-onmicrosoft-com header.b=fRV28h6R; spf=pass (domain: intel.com, ip: 192.55.52.115, mailfrom: jiewen.yao@intel.com) IronPort-SDR: 8lwVmYF4Nn7ogt/ksN1yx4+nZ91r2lGDNHXMnojYH9DVCeuevOlvO4dEVEfb4XpZmH5rAw6ZGv FCNDEh2LLsZA== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Jun 2020 18:17:13 -0700 IronPort-SDR: mBqKHE1T1ijHnQzmchsImcaEEsXZVgqbji3knjuKAGKrSATdXg6qmkRc+BDlkwapTMc9UgfP9Q bYTkcg37kc7Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,482,1583222400"; d="scan'208";a="305464637" Received: from orsmsx102.amr.corp.intel.com ([10.22.225.129]) by fmsmga002.fm.intel.com with ESMTP; 06 Jun 2020 18:17:13 -0700 Received: from ORSEDG002.ED.cps.intel.com (10.7.248.5) by ORSMSX102.amr.corp.intel.com (10.22.225.129) with Microsoft SMTP Server (TLS) id 14.3.439.0; Sat, 6 Jun 2020 18:17:13 -0700 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (104.47.66.41) by edgegateway.intel.com (134.134.137.101) with Microsoft SMTP Server (TLS) id 14.3.439.0; Sat, 6 Jun 2020 18:17:13 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YOtkkLcpBNtwuj2avpGrlLbb18CL+o5MTtXDsl6/rhwzJKr5ewH1vLgl+k6TLHFrBwJMAacd5xUia7E2zKHnIABgcl/xXThw7I0A1PeaFPyz+G7FCBIBQrATR6Id24F8lvRvexSrvlSjYHAw5EttLRNihSldLGjEmk2s0jUFGb48FpWT0QKWj4kEWPSOfIwxRjdomGyYJ66++I+CQ3GEqu0T5Rzb7BG3lqvBDEz+1lEPyK1/AcxmdolaQ0tI76+2ZkEpbtaZ/X7h2r5ClKDQ1rcxhW3xaUulBGRQM7V41AqMWiI2qR8ixF9VPLtGQkSKV9VKdkIyOgUt/AhPsr0FXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=nBSMg7C9H16I7ZLcFhmadwRW30CbqX6NvuyBTNRGuLg=; b=XhE3bxtsTTjb1Rn50JaWP7FWDP0V/b0UvegEdQfZ1/4mEOeucm8VnQn3b+urlFcs1Hss6C5ETnnapMC5e52GGMWM94PtIY5wpm4oeTHQqU98giC/yRnqi/n/Xuhezn6o73333D/4Qd53BgK6+6/gegZyq1CNOp+3fCaaKT4QjeRHhyMsIVccR0gYUbpospXggfVgz1wmA4xMUTouJFmbfB2qXniO7K5qX7dLdz3S5e1z4KPx+sFANryIo/fhnBPkwHDkpr59mFfS8RFlBFuwz7kI1sWrkXiQNPh2we9m8nvMM3FSUP0Y8mYMS/zPefqnVJbLr+wFfzPACOXe3mzuYw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.onmicrosoft.com; s=selector2-intel-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=nBSMg7C9H16I7ZLcFhmadwRW30CbqX6NvuyBTNRGuLg=; b=fRV28h6RCCv0WgN8/U0r9wjfZyXCXGxo2oLassisZuQWMjnpOEHaXtNylCGC0iiL6lH1cH6WehQznfSBoJBigoYbwhjDMYZmVMjLXKNc9elv7l0zbW1+wj7sgnqke10FWLi7EB8j1ikdMN5McQelADtV6M5NMIwIP/OWU2MHNu8= Received: from BL0PR11MB3412.namprd11.prod.outlook.com (2603:10b6:208:7c::32) by BL0PR11MB3315.namprd11.prod.outlook.com (2603:10b6:208:6c::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3066.20; Sun, 7 Jun 2020 01:17:11 +0000 Received: from BL0PR11MB3412.namprd11.prod.outlook.com ([fe80::a0dd:b860:2661:de87]) by BL0PR11MB3412.namprd11.prod.outlook.com ([fe80::a0dd:b860:2661:de87%6]) with mapi id 15.20.3066.023; Sun, 7 Jun 2020 01:17:11 +0000 From: "Yao, Jiewen" To: Ilias Apalodimas , "ard.biesheuvel@arm.com" , "sami.mujawar@arm.com" , "supreeth.venkatesh@arm.com" CC: "devel@edk2.groups.io" Subject: Re: [RFC edk2 v1] StandaloneMmPkg: Relocatable version for StandAloneMM Thread-Topic: [RFC edk2 v1] StandaloneMmPkg: Relocatable version for StandAloneMM Thread-Index: AQHWO9/MItd22NdrTUuVV/T7EWTsDqjMWA8Q Date: Sun, 7 Jun 2020 01:17:11 +0000 Message-ID: References: <20200606085209.1161547-1-ilias.apalodimas@linaro.org> In-Reply-To: <20200606085209.1161547-1-ilias.apalodimas@linaro.org> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiOTJmNDZiYTktOTYzNC00ZTM3LWJhYjEtYTE5MzI5NGQ3NTRjIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiXC9pRnhDcWh0dWVPMzRQSHdJWWNESFRhTiszWXN6TmhtblMwTVZKTUhxbTRTOVplMWd2azdaVzBnRmZVclwvamNDIn0= x-ctpclassification: CTP_NT dlp-version: 11.2.0.6 dlp-product: dlpe-windows dlp-reaction: no-action authentication-results: linaro.org; dkim=none (message not signed) header.d=none;linaro.org; dmarc=none action=none header.from=intel.com; x-originating-ip: [101.87.141.219] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 5a9d7708-38a9-4b22-bf84-08d80a808142 x-ms-traffictypediagnostic: BL0PR11MB3315: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:10000; x-forefront-prvs: 04270EF89C x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: VI98RJ9H5plCFz0wVlG27AEzCEN1EnR5zmmbyl+AH4pg9n1ZEVhgXaDBgq4gWEEKXZlEFB5evGLhdwXvFYzi2xzJ4ypS4nDDD/VujZdWt35FZRJkUdTTe3OEJGDvvWNmzwh3BMib7iMf1sUhqSfLaVjqlBnSslWXuxg7iXJcDvu5fqYLqsGrnWzWxjrgVkLq6OS7768lLmelRYCma0159XhGXpZCFdaBWRhaaiS4kX//Y5ena9K/rCTz23ymo36XaBdVNuHWUn874Kbg4zAT9vDw+gW/bv+sGtYDxF3S/XRn2IoMyGjD0PSAFbXDlh94afT0GqXnQL9nelfOitBNOlfEEFKmVG2IbEb21LUFm81ESYXQR9LIFPsA+3zTLGsaBIa8PVycOpwMDBD0/ky2uw== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BL0PR11MB3412.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(6029001)(396003)(136003)(39860400002)(376002)(366004)(346002)(19627235002)(478600001)(186003)(86362001)(8676002)(110136005)(6506007)(66946007)(8936002)(83380400001)(66476007)(9686003)(26005)(64756008)(55016002)(66556008)(966005)(66446008)(30864003)(33656002)(4326008)(76116006)(71200400001)(53546011)(316002)(52536014)(5660300002)(2906002)(7696005);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata: YPJ5PNkZ2OngY2BSXWFsG6wCOT+Mh0r/JOaoGlmsMm9UvWokO0YC1gojutVuIALBvZ9Ma0y1GhpRGYW7aSZzdsDrdQdevrsDShkTSEgZIkvx547qQYc1EMLly+XvbAY2001aNuKXDNCCRYmRL1V1fwE9+2ESQQPoEShOZcd+Mray9Ncd2qqIJL0uMafVQmLgfx3wx55LU5tIQGjXujIJeckVL8LtjkabWcBWJob18Tn8sigwJAA6xsGN/azBWYWUQuH1URHWUuc4Wwxhk5ZdgfSOP8voJNCskMwzHQOw9aRn4bg3m0w4R+7hnghJ/h2JoUbIEGxBNcFITK/ISRobgRHU3pd5LNBU5fgateYAEaKI8mMPE3/sH9X51NjzHbeGNOziyGxZz97P8tbTZAp4mfaBIdy0sae8aNgd7oT+ib0gZzPFOIQJ/fpTeRLdtu+/1FOKVsl8Z0kvWNExhPU5zAfH6f99CeWDeQPSZmHliiBypP8qTCv9cduvUWxNCgFL x-ms-exchange-transport-forked: True MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: 5a9d7708-38a9-4b22-bf84-08d80a808142 X-MS-Exchange-CrossTenant-originalarrivaltime: 07 Jun 2020 01:17:11.1853 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: fr9zeF0k2JjXY/OSSgzacNPkJUNZTYisbAsSuZwiPzDC6QaJZQBdJ8Xka4opm2wQ3XuGZUOdF8BohRM4FD1YZQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR11MB3315 Return-Path: jiewen.yao@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi Ilias It seems a good idea to support relocatable StMM. Thought on StandaloneMmPkg/Core/StandaloneMmCoreRelocatable.inf Usually we do not add special link option in INF and build a module to be E= LF for some special purposes. Things might be broken if X86 platform uses this INF to build Relocatable i= mage with visual studio or with GCC. Do you think if it is possible to still create a self-relocatable Standalon= eMmCore as a PE image, instead of ELF ? One example is at : https://github.com/jyao1/STM/blob/master/Stm/StmPkg/Cor= e/Init/StmInit.c#L1096 Then we may reuse the generic PeCoff library in C code before any global va= riable access. No special assembly code or link script required. And no need to add a PCD. Thank you Yao Jiewen > -----Original Message----- > From: Ilias Apalodimas > Sent: Saturday, June 6, 2020 4:52 PM > To: ard.biesheuvel@arm.com; sami.mujawar@arm.com; Yao, Jiewen > ; supreeth.venkatesh@arm.com > Cc: devel@edk2.groups.io; Ilias Apalodimas > Subject: [RFC edk2 v1] StandaloneMmPkg: Relocatable version for > StandAloneMM >=20 > With work currently being done in OP-TEE [1] and U-boot [2], we can > compile StandAloneMM as a single binary [3] and load it from OP-TEE in > an isolated partition that behahes similarly to SPM. > By doing so we reuse existing code from EDK2 for the UEFI variable > storage regardless of the firmware implementation. Another advantage is > that OP-TEE combined with U-Boot's OP-TEE supplicant can use the RPMB > partition of an eMMC and securely store EFI variables instead of solely > relying on a secure world flash [4]. >=20 > Since StMM can be compiled as a binary that runs on OP-TEE, we need to > make it self-relocatable. OP-TEE load address can be arbitrary depending > on memory layout or ASLR. > We could keep the current StandAloneMM implementation as-is and duplicate > StandaloneMmCoreEntryPoint.c. Instead add two more .inf files for the > relocatable option and the relevant linker script, move the current > entry point into asm and add a FeaturePcd for enabling/disabling the > relocatable option. >=20 > [1] https://github.com/apalos/optee_os/tree/stmm_upstream_03_clean > [2] https://github.com/u-boot/u- > boot/blob/master/lib/efi_loader/efi_variable_tee.c > [3] https://git.linaro.org/people/ilias.apalodimas/edk2- > platforms.git/tree/Platform/QemuVirt/PlatformStandaloneMm.dsc?h=3Dstmm_re= l > oc_combined > [4] https://git.linaro.org/people/ilias.apalodimas/edk2- > platforms.git/tree/Silicon/QemuVirt/Drivers/OpTeeRpmbFv/OpTeeRpmbFv.c?h= =3D > stmm_reloc_combined >=20 > Signed-off-by: Ilias Apalodimas > --- > StandaloneMmPkg/Core/Scripts/StMM-PIE.lds | 54 +++++++++ > StandaloneMmPkg/Core/StandaloneMmCore.inf | 3 + > .../Core/StandaloneMmCoreRelocatable.inf | 80 ++++++++++++++ > .../AArch64/ModuleEntryPoint.S | 103 ++++++++++++++++++ > .../AArch64/StandaloneMmCoreEntryPoint.c | 7 +- > .../StandaloneMmCoreEntryPoint.inf | 4 + > .../StandaloneMmCoreEntryPointRelocatable.inf | 54 +++++++++ > StandaloneMmPkg/StandaloneMmPkg.dec | 2 + > 8 files changed, 306 insertions(+), 1 deletion(-) > create mode 100644 StandaloneMmPkg/Core/Scripts/StMM-PIE.lds > create mode 100644 > StandaloneMmPkg/Core/StandaloneMmCoreRelocatable.inf > create mode 100644 > StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/AArch64/ModuleEntr > yPoint.S > create mode 100644 > StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCoreE > ntryPointRelocatable.inf >=20 > diff --git a/StandaloneMmPkg/Core/Scripts/StMM-PIE.lds > b/StandaloneMmPkg/Core/Scripts/StMM-PIE.lds > new file mode 100644 > index 000000000000..a1d7012c4ca3 > --- /dev/null > +++ b/StandaloneMmPkg/Core/Scripts/StMM-PIE.lds > @@ -0,0 +1,54 @@ > +/** @file >=20 > + >=20 > + Copyright (c) 2015, Linaro Ltd. All rights reserved.
>=20 > + >=20 > + SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > + >=20 > +**/ >=20 > + >=20 > +SECTIONS >=20 > +{ >=20 > + PROVIDE(__reloc_base =3D .); >=20 > + >=20 > + . =3D PECOFF_HEADER_SIZE; >=20 > + .text : ALIGN(CONSTANT(COMMONPAGESIZE)) { >=20 > + *(.text.reloc*) >=20 > + . =3D ALIGN(0x1000); >=20 > + PROVIDE(__stmm_start =3D .); >=20 > + *(.text .text*) >=20 > + . =3D ALIGN(0x20); >=20 > + PROVIDE(__reloc_start =3D .); >=20 > + *(.rel .rel.*) >=20 > + *(.rela .rela.*) >=20 > + PROVIDE(__reloc_end =3D .); >=20 > + } >=20 > + PROVIDE(__ro_start =3D .); >=20 > + .got : ALIGN(CONSTANT(COMMONPAGESIZE)) { >=20 > + *(.got .got*) >=20 > + } >=20 > + .rodata : ALIGN(CONSTANT(COMMONPAGESIZE)) { >=20 > + *(.rodata .rodata*) >=20 > + } >=20 > + PROVIDE(__ro_end =3D .); >=20 > + .data : ALIGN(CONSTANT(COMMONPAGESIZE)) { >=20 > + *(.data .data*) >=20 > + } >=20 > + .bss : ALIGN(CONSTANT(COMMONPAGESIZE)) { >=20 > + *(.bss .bss*) >=20 > + } >=20 > + PROVIDE(__stmm_end =3D .); >=20 > + >=20 > + .note (INFO) : { *(.note.gnu.build-id) } >=20 > + >=20 > + /DISCARD/ : { >=20 > + *(.note.GNU-stack) >=20 > + *(.gnu.hash) >=20 > + *(.gnu_debuglink) >=20 > + *(.interp) >=20 > + *(.dynamic) >=20 > + *(.dynsym) >=20 > + *(.dynstr) >=20 > + *(.hash) >=20 > + *(.comment) >=20 > + } >=20 > +} >=20 > diff --git a/StandaloneMmPkg/Core/StandaloneMmCore.inf > b/StandaloneMmPkg/Core/StandaloneMmCore.inf > index 7d590b49bd3f..fdd4b61b3665 100644 > --- a/StandaloneMmPkg/Core/StandaloneMmCore.inf > +++ b/StandaloneMmPkg/Core/StandaloneMmCore.inf > @@ -74,3 +74,6 @@ > gEfiEventLegacyBootGuid >=20 > gEfiEventExitBootServicesGuid >=20 > gEfiEventReadyToBootGuid >=20 > + >=20 > +[BuildOptions] >=20 > + GCC:*_*_*_DLINK_FLAGS =3D -Wl,-T,$(MODULE_DIR)/Scripts/StMM-PIE.lds >=20 > diff --git a/StandaloneMmPkg/Core/StandaloneMmCoreRelocatable.inf > b/StandaloneMmPkg/Core/StandaloneMmCoreRelocatable.inf > new file mode 100644 > index 000000000000..69049080ef78 > --- /dev/null > +++ b/StandaloneMmPkg/Core/StandaloneMmCoreRelocatable.inf > @@ -0,0 +1,80 @@ > +## @file >=20 > +# This module provide an SMM CIS compliant implementation of SMM Core. >=20 > +# >=20 > +# Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.
>=20 > +# Copyright (c) 2016 - 2018, ARM Limited. All rights reserved.
>=20 > +# Copyright (c) 2020, Linaro Limited. All rights reserved.
>=20 > +# >=20 > +# SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > +# >=20 > +## >=20 > + >=20 > +[Defines] >=20 > + INF_VERSION =3D 0x0001001A >=20 > + BASE_NAME =3D StandaloneMmCore >=20 > + FILE_GUID =3D 6E14B6FD-3600-4DD6-A17A-206B3B6DCE1= 6 >=20 > + MODULE_TYPE =3D MM_CORE_STANDALONE >=20 > + VERSION_STRING =3D 1.0 >=20 > + PI_SPECIFICATION_VERSION =3D 0x00010032 >=20 > + ENTRY_POINT =3D StandaloneMmMain >=20 > + >=20 > +# VALID_ARCHITECTURES =3D IA32 X64 AARCH64 >=20 > + >=20 > +[Sources] >=20 > + StandaloneMmCore.c >=20 > + StandaloneMmCore.h >=20 > + StandaloneMmCorePrivateData.h >=20 > + Page.c >=20 > + Pool.c >=20 > + Handle.c >=20 > + Locate.c >=20 > + Notify.c >=20 > + Dependency.c >=20 > + Dispatcher.c >=20 > + Mmi.c >=20 > + InstallConfigurationTable.c >=20 > + FwVol.c >=20 > + >=20 > +[Packages] >=20 > + MdePkg/MdePkg.dec >=20 > + MdeModulePkg/MdeModulePkg.dec >=20 > + StandaloneMmPkg/StandaloneMmPkg.dec >=20 > + >=20 > +[LibraryClasses] >=20 > + BaseLib >=20 > + BaseMemoryLib >=20 > + CacheMaintenanceLib >=20 > + DebugLib >=20 > + ExtractGuidedSectionLib >=20 > + FvLib >=20 > + HobLib >=20 > + MemoryAllocationLib >=20 > + MemLib >=20 > + PeCoffLib >=20 > + ReportStatusCodeLib >=20 > + StandaloneMmCoreEntryPoint >=20 > + >=20 > +[Protocols] >=20 > + gEfiDxeMmReadyToLockProtocolGuid ## UNDEFINED # > SmiHandlerRegister >=20 > + gEfiMmReadyToLockProtocolGuid ## PRODUCES >=20 > + gEfiMmEndOfDxeProtocolGuid ## PRODUCES >=20 > + gEfiLoadedImageProtocolGuid ## PRODUCES >=20 > + gEfiMmConfigurationProtocolGuid ## CONSUMES >=20 > + >=20 > +[Guids] >=20 > + gAprioriGuid ## SOMETIMES_CONSUMES = ## File >=20 > + gEfiEventDxeDispatchGuid ## PRODUCES = ## GUID # > SmiHandlerRegister >=20 > + gEfiEndOfDxeEventGroupGuid ## PRODUCES = ## GUID # > SmiHandlerRegister >=20 > + ## SOMETIMES_CONSUMES ## GUID # Locate protocol >=20 > + ## SOMETIMES_PRODUCES ## GUID # SmiHandlerRegister >=20 > + gEdkiiMemoryProfileGuid >=20 > + gZeroGuid ## SOMETIMES_CONSUMES = ## GUID >=20 > + gEfiHobListGuid >=20 > + gMmCoreDataHobGuid >=20 > + gMmFvDispatchGuid >=20 > + gEfiEventLegacyBootGuid >=20 > + gEfiEventExitBootServicesGuid >=20 > + gEfiEventReadyToBootGuid >=20 > + >=20 > +[BuildOptions] >=20 > + GCC:*_*_*_DLINK_FLAGS =3D -Wl,-Bsymbolic,-pie,- > T,$(MODULE_DIR)/Scripts/StMM-PIE.lds >=20 > diff --git > a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/AArch64/ModuleEn > tryPoint.S > b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/AArch64/ModuleEn > tryPoint.S > new file mode 100644 > index 000000000000..90ff4579daa6 > --- /dev/null > +++ > b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/AArch64/ModuleEn > tryPoint.S > @@ -0,0 +1,103 @@ > +// >=20 > +// Copyright (c) 2011-2013, ARM Limited. All rights reserved. >=20 > +// Copyright (c) 2015-2020, Linaro Limited. All rights reserved. >=20 > +// >=20 > +// SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > +// >=20 > +// >=20 > + >=20 > +#include >=20 > +ASM_FUNC(_ModuleEntryPoint) >=20 > + adr x8, FeaturePcdGet (PcdStMMReloc) >=20 > + ldrb w9, [x8] >=20 > + cmp x9, #0 >=20 > + // If PcdStMMReloc is set to TRUE, go ahead and fixup the relocations = here >=20 > + beq .Llaunch >=20 > + adr x8, __reloc_base >=20 > + adr x9, __reloc_start >=20 > + adr x10, __reloc_end >=20 > + bl ASM_PFX(_DoReloc) >=20 > +.Llaunch: >=20 > + b ModuleEntryPoint >=20 > + >=20 > +.section .text.reloc, "ax" >=20 > +ASM_PFX(_DoReloc): >=20 > + mov x20, x0 >=20 > + mov x21, x1 >=20 > + mov x22, x2 >=20 > + mov x23, x3 >=20 > + >=20 > + // Set all of the memory as r/w >=20 > + adr x11, __stmm_start >=20 > + adr x2, __stmm_end >=20 > + ldr x0, =3D0xC4000065 >=20 > + and x1, x11, #~0x0fff // Align to page >=20 > + sub x2, x2, x11 >=20 > + add x2, x2, #0xfff >=20 > + lsr x2, x2, #12 // nr pages >=20 > + ldr x3, =3D0x5 // Set perms to r/w >=20 > + svc #0 >=20 > + // Prevent speculative execution beyond svc instruction >=20 > + dsb nsh >=20 > + isb >=20 > + >=20 > +.Lreloc_loop: >=20 > + cmp x9, x10 >=20 > + bhs .Lreloc_done >=20 > + // >=20 > + // We are built as a ET_DYN PIE executable, so we need to process all >=20 > + // relative relocations regardless of whether or not we are executing = from >=20 > + // the same offset we were linked at. This is only possible if we are >=20 > + // running from RAM. >=20 > + // >=20 > + // AArch64 uses the ELF64 RELA format, which means each entry in the >=20 > + // relocation table consists of >=20 > + // >=20 > + // UINT64 offset : the relative offset of the value that ne= eds to >=20 > + // be relocated >=20 > + // UINT64 info : relocation type and symbol index (the la= tter is >=20 > + // not used for R_AARCH64_RELATIVE relocati= ons) >=20 > + // UINT64 addend : value to be added to the value being rel= ocated >=20 > + // >=20 > + ldp x11, x12, [x9], #24 // read offset into x11 and info into x12 >=20 > + cmp x12, #0x403 // check info =3D=3D R_AARCH64_RELATIVE? >=20 > + bne .Lreloc_loop // not a relative relocation? then skip >=20 > + ldr x12, [x9, #-8] // read addend into x12 >=20 > + add x12, x12, x8 // add reloc base to addend to get relocat= ed value >=20 > + str x12, [x11, x8] // write relocated value at offset >=20 > + b .Lreloc_loop >=20 > + >=20 > +.Lreloc_done: >=20 > + // set memory per section >=20 > + adr x11, __stmm_start >=20 > + adr x2, __reloc_end >=20 > + ldr x0, =3D0xC4000065 >=20 > + and x1, x11, #~0x0fff // Align to page >=20 > + sub x2, x2, x11 >=20 > + add x2, x2, #0xfff >=20 > + lsr x2, x2, #12 // nr pages >=20 > + ldr x3, =3D0x3 // Set perms to r/x >=20 > + svc #0 >=20 > + // Prevent speculative execution beyond svc instruction >=20 > + dsb nsh >=20 > + isb >=20 > + >=20 > + adr x11, __ro_start >=20 > + adr x2, __ro_end >=20 > + ldr x0, =3D0xC4000065 >=20 > + and x1, x11, #~0x0fff // Align to page >=20 > + sub x2, x2, x11 >=20 > + add x2, x2, #0xfff >=20 > + lsr x2, x2, #12 // nr pages >=20 > + ldr x3, =3D0x1 // Set perms to r/o >=20 > + svc #0 >=20 > + // Prevent speculative execution beyond svc instruction >=20 > + dsb nsh >=20 > + isb >=20 > + >=20 > + mov x0, x20 >=20 > + mov x1, x21 >=20 > + mov x2, x22 >=20 > + mov x3, x23 >=20 > + >=20 > + ret >=20 > diff --git > a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/AArch64/Standalon > eMmCoreEntryPoint.c > b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/AArch64/Standalon > eMmCoreEntryPoint.c > index 20723385113f..57c3162ab5d0 100644 > --- > a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/AArch64/Standalon > eMmCoreEntryPoint.c > +++ > b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/AArch64/Standalon > eMmCoreEntryPoint.c > @@ -22,6 +22,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent > #include >=20 > #include >=20 > #include >=20 > +#include >=20 > #include >=20 >=20 >=20 > #include >=20 > @@ -209,7 +210,7 @@ GetSpmVersion (VOID) > **/ >=20 > VOID >=20 > EFIAPI >=20 > -_ModuleEntryPoint ( >=20 > +ModuleEntryPoint ( >=20 > IN VOID *SharedBufAddress, >=20 > IN UINT64 SharedBufSize, >=20 > IN UINT64 cookie1, >=20 > @@ -238,6 +239,9 @@ _ModuleEntryPoint ( > goto finish; >=20 > } >=20 >=20 >=20 > + if (FeaturePcdGet (PcdStMMReloc)) { >=20 > + goto skip_remap; >=20 > + } >=20 > // Locate PE/COFF File information for the Standalone MM core module >=20 > Status =3D LocateStandaloneMmCorePeCoffData ( >=20 > (EFI_FIRMWARE_VOLUME_HEADER *) PayloadBootInfo->SpImageBase= , >=20 > @@ -276,6 +280,7 @@ _ModuleEntryPoint ( > goto finish; >=20 > } >=20 >=20 >=20 > +skip_remap: >=20 > // >=20 > // Create Hoblist based upon boot information passed by privileged sof= tware >=20 > // >=20 > diff --git > a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCor > eEntryPoint.inf > b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCor > eEntryPoint.inf > index 891c292e92f8..6659219404a5 100644 > --- > a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCor > eEntryPoint.inf > +++ > b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCor > eEntryPoint.inf > @@ -25,6 +25,7 @@ > AArch64/StandaloneMmCoreEntryPoint.c >=20 > AArch64/SetPermissions.c >=20 > AArch64/CreateHobList.c >=20 > + AArch64/ModuleEntryPoint.S >=20 >=20 >=20 > [Packages] >=20 > MdePkg/MdePkg.dec >=20 > @@ -48,3 +49,6 @@ > gEfiMmPeiMmramMemoryReserveGuid >=20 > gEfiStandaloneMmNonSecureBufferGuid >=20 > gEfiArmTfCpuDriverEpDescriptorGuid >=20 > + >=20 > +[FeaturePcd] >=20 > + gStandaloneMmPkgTokenSpaceGuid.PcdStMMReloc|FALSE >=20 > diff --git > a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCor > eEntryPointRelocatable.inf > b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCor > eEntryPointRelocatable.inf > new file mode 100644 > index 000000000000..10cdae1b4018 > --- /dev/null > +++ > b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCor > eEntryPointRelocatable.inf > @@ -0,0 +1,54 @@ > +## @file >=20 > +# Module entry point library for DXE core. >=20 > +# >=20 > +# Copyright (c) 2020, ARM Ltd. All rights reserved.
>=20 > +# >=20 > +# SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > +# >=20 > +# >=20 > +## >=20 > + >=20 > +[Defines] >=20 > + INF_VERSION =3D 0x0001001A >=20 > + BASE_NAME =3D StandaloneMmCoreEntryPoint >=20 > + FILE_GUID =3D C97AC593-109A-4C63-905C-675FDE2689E= 8 >=20 > + MODULE_TYPE =3D MM_CORE_STANDALONE >=20 > + VERSION_STRING =3D 1.0 >=20 > + PI_SPECIFICATION_VERSION =3D 0x00010032 >=20 > + LIBRARY_CLASS =3D > StandaloneMmCoreEntryPoint|MM_CORE_STANDALONE >=20 > + >=20 > +# >=20 > +# VALID_ARCHITECTURES =3D IA32 X64 IPF EBC (EBC is for build = only) >=20 > +# >=20 > + >=20 > +[Sources.AARCH64] >=20 > + AArch64/StandaloneMmCoreEntryPoint.c >=20 > + AArch64/SetPermissions.c >=20 > + AArch64/CreateHobList.c >=20 > + AArch64/ModuleEntryPoint.S >=20 > + >=20 > +[Packages] >=20 > + MdePkg/MdePkg.dec >=20 > + MdeModulePkg/MdeModulePkg.dec >=20 > + StandaloneMmPkg/StandaloneMmPkg.dec >=20 > + >=20 > +[Packages.AARCH64] >=20 > + ArmPkg/ArmPkg.dec >=20 > + ArmPlatformPkg/ArmPlatformPkg.dec >=20 > + >=20 > +[LibraryClasses] >=20 > + BaseLib >=20 > + DebugLib >=20 > + >=20 > +[LibraryClasses.AARCH64] >=20 > + StandaloneMmMmuLib >=20 > + ArmSvcLib >=20 > + >=20 > +[Guids] >=20 > + gMpInformationHobGuid >=20 > + gEfiMmPeiMmramMemoryReserveGuid >=20 > + gEfiStandaloneMmNonSecureBufferGuid >=20 > + gEfiArmTfCpuDriverEpDescriptorGuid >=20 > + >=20 > +[FeaturePcd] >=20 > + gStandaloneMmPkgTokenSpaceGuid.PcdStMMReloc|TRUE >=20 > diff --git a/StandaloneMmPkg/StandaloneMmPkg.dec > b/StandaloneMmPkg/StandaloneMmPkg.dec > index 82cb62568b53..cc572321a5b6 100644 > --- a/StandaloneMmPkg/StandaloneMmPkg.dec > +++ b/StandaloneMmPkg/StandaloneMmPkg.dec > @@ -33,3 +33,5 @@ > gEfiStandaloneMmNonSecureBufferGuid =3D { 0xf00497e3, 0xbfa2, 0x4= 1a1, > { 0x9d, 0x29, 0x54, 0xc2, 0xe9, 0x37, 0x21, 0xc5 }} >=20 > gEfiArmTfCpuDriverEpDescriptorGuid =3D { 0x6ecbd5a1, 0xc0f8, 0x4= 702, > { 0x83, 0x01, 0x4f, 0xc2, 0xc5, 0x47, 0x0a, 0x51 }} >=20 >=20 >=20 > +[PcdsFeatureFlag] >=20 > + > gStandaloneMmPkgTokenSpaceGuid.PcdStMMReloc|FALSE|BOOLEAN|0x00000 > 001 >=20 > -- > 2.27.0