From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 04451AC0BE2 for ; Tue, 9 Apr 2024 05:20:15 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=nKVXAyFPRoJuAiWNQ5zLLH5OJCk9pRN6wlr3MGqoCXk=; c=relaxed/simple; d=groups.io; h=From:To:CC:Subject:Thread-Topic:Thread-Index:Date:Message-ID:References:In-Reply-To:Accept-Language:msip_labels:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Resent-Date:Resent-From:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Language:Content-Type; s=20240206; t=1712640014; v=1; b=cRhzBw1Kyx//BdyH9gb9EPCAytBAzuBjOmSFKqXDMYdkXEGpTV9lgHPvYL/oSrbbQC7M0IU6 8KJyNxrzWBYMQMb1Eaa5T+7trTOsbMUKVEKeAI/Phn8preovTLgGnkAmhSQE6UlCnCqq3g7WU5F C9FClbK3/s95xJueBn1Ke62g2fOp14L7qo++5MlGq6YluqafQ/jowLgECDqG9AW94MF2XL1ZuVK MqXBJE5Gooz/A2UJ0SwrMjpmPQBLfD954ynKykoEcTr4bRL19I2mYViqu1yOWDvD//fv0Rhzdwn r9WPdhpi1PALc7woGGV29lTZS0YoccM8AQfz9MwagNLyg== X-Received: by 127.0.0.2 with SMTP id KFGDYY7687511xLwZHOCx9gU; Mon, 08 Apr 2024 22:20:14 -0700 X-Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.20]) by mx.groups.io with SMTP id smtpd.web11.129484.1712640013374328205 for ; Mon, 08 Apr 2024 22:20:13 -0700 X-CSE-ConnectionGUID: rstZV4PwR0O9p502FfOFWg== X-CSE-MsgGUID: sBGxwdlLTtm8ow4jXKYcMA== X-IronPort-AV: E=McAfee;i="6600,9927,11038"; a="7807682" X-IronPort-AV: E=Sophos;i="6.07,188,1708416000"; d="scan'208,217";a="7807682" X-Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa112.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Apr 2024 22:20:13 -0700 X-CSE-ConnectionGUID: 2A5dcpBRSkCLP0EwFRiE+Q== X-CSE-MsgGUID: 87kJYHljSoe8c0bAr0p/lg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,188,1708416000"; d="scan'208,217";a="24813978" X-Received: from orsmsx602.amr.corp.intel.com ([10.22.229.15]) by orviesa003.jf.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 08 Apr 2024 22:20:13 -0700 X-Received: from orsmsx611.amr.corp.intel.com (10.22.229.24) by ORSMSX602.amr.corp.intel.com (10.22.229.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Mon, 8 Apr 2024 22:20:12 -0700 X-Received: from orsmsx610.amr.corp.intel.com (10.22.229.23) by ORSMSX611.amr.corp.intel.com (10.22.229.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Mon, 8 Apr 2024 22:20:12 -0700 X-Received: from orsedg603.ED.cps.intel.com (10.7.248.4) by orsmsx610.amr.corp.intel.com (10.22.229.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35 via Frontend Transport; Mon, 8 Apr 2024 22:20:12 -0700 X-Received: from NAM02-SN1-obe.outbound.protection.outlook.com (104.47.57.40) by edgegateway.intel.com (134.134.137.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Mon, 8 Apr 2024 22:20:12 -0700 X-Received: from DM4PR11MB8226.namprd11.prod.outlook.com (2603:10b6:8:182::12) by DS7PR11MB6013.namprd11.prod.outlook.com (2603:10b6:8:70::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.26; Tue, 9 Apr 2024 05:20:09 +0000 X-Received: from DM4PR11MB8226.namprd11.prod.outlook.com ([fe80::4b2d:823c:e71a:541e]) by DM4PR11MB8226.namprd11.prod.outlook.com ([fe80::4b2d:823c:e71a:541e%6]) with mapi id 15.20.7430.045; Tue, 9 Apr 2024 05:20:09 +0000 From: "Ni, Ray" To: "Liu, Zhiguang" , "devel@edk2.groups.io" CC: "Chiu, Chasel" , "Desimone, Nathaniel L" , "Duggapu, Chinni B" , "Zeng, Star" , "Kuo, Ted" , "S, Ashraf Ali" , "Susovan Mohapatra" Subject: Re: [edk2-devel] [PATCH] IntelFsp2Pkg: Optional Plugin for FSP SecCore/PeiCore Rebasing Thread-Topic: [PATCH] IntelFsp2Pkg: Optional Plugin for FSP SecCore/PeiCore Rebasing Thread-Index: AQHahZ6rPFh+vZt+rEW5tdkj7+cQr7FfUTYy Date: Tue, 9 Apr 2024 05:20:09 +0000 Message-ID: References: <20240403081202.2069-1-zhiguang.liu@intel.com> In-Reply-To: <20240403081202.2069-1-zhiguang.liu@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: x-ms-publictraffictype: Email x-ms-traffictypediagnostic: DM4PR11MB8226:EE_|DS7PR11MB6013:EE_ x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam-message-info: CNvhZXLoFfo8J+jWY5HRjh4WRgh0//LxqPzeBIaJcGvXL828vmzhPUXLIm7QhKE/OaHdxCQdh0gtUsEBPki/kUAFEzZxqK1k1rkpTCM392MaUu0XaPSMkp3KqJix6wVZCahwK4qowsIipBuboN7Usa/8/8c15Yxo4iOaoFNerTt9WhNxi56IqIYw0YIFO2VgCDYiU2UlYIrffAWsZzTQdc2dX/JFET3/pGe5ZsVCo9pn+ZcSG4yxkEuWVUfUL3Y4+WieHQFaHLxJfNA2gdqYA3gIlWevHCsZwxjJ4XRzN9nNyF3lv54Oj24Z7VJQyYMKRs7iA8gdBMpkF+q02KOAcimvjkUUQv4yjeAnbdhjdH/MSmELO/BBlx/zSSurA5OiL2V1HKYODvGFhBB0039sFbXcLq1/y7a0uNNuUKsYElF+n4fZjFzbahtSRCqrWcSjZhgo8eLP8Kay6Jar712UC2ayN9BXYSPQCYJ81SI4mnt3aNvW8c1SY4giFA98B5io4HIpazybTcjF9ecBSErLTQwApviZnsCh0BdtIvI3DXTZOvZTYqChIaktfM6CdxTHdSmhJUpCJcs5kFwu/1YNAVPC0EaoX+0wZY5HIixulF1CwwfdcWOe8JlmbwYZp5lnT61AoxpIlI05+voo5eqJgY6oUx/AjiShZ+5krNyZAiw= x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?Q?F/TevqVcmxdtziDSv3trKqV77/odk+t5bXEDJkZSZsVS2iNUlsoHx7R5Pg?= =?iso-8859-1?Q?ksKKbE9ekJaV6bAbpi4J1pnHQrd3cllec6j0U1PBLwouXx8T/vugE2l7fh?= =?iso-8859-1?Q?hcdR6lj9lmnWWr+7Od3RjgAxzv4yYqno0s7YQ6YHb34jKh/0E6utGcC5JG?= =?iso-8859-1?Q?8Qzp1Zy4QlkHivVET7pzCXppr2wDcDm2XrxJY0OPSPQGdz4PM63uN8Umwo?= =?iso-8859-1?Q?btHxDXLOmkESxSY+C30+lu4DcjEaSVMUSHZjBE+TZFZuh4J7doDyb+pecw?= =?iso-8859-1?Q?mM2LbcWevSa9AbqiRBLeROZR5UzT/OQVq80+FVfNXxbFBdEm7f3PgTiwn5?= =?iso-8859-1?Q?Ezeg49y6amnJ79ArSwqTRH25qT3BwDjpBEG8aLswJkjiVf6RJ6aGSCEsR3?= =?iso-8859-1?Q?3npfBTF/zwnEw+adROOjQLLkwSyPFPkqnY2ruAzVvkZRADhbToYaplD0Y6?= =?iso-8859-1?Q?OSUykmCNb27DWPi1tq0HbnQT9Az33JW2G7c/86Bp4fBRqwvcPycfFyGxvC?= =?iso-8859-1?Q?bhs4wZNpAaYQ5cv7o4CEygD1uBsRmPeRnfWEssNW1UAeCicPqYGtCUPeF0?= =?iso-8859-1?Q?I4MOARizp+cevztAjVhvhQNYTkhosO9GBmAKALVtwekvFlio4dgTCXzmwW?= =?iso-8859-1?Q?DgQ9i8PZlk/lUXU+yvk+6t0GeMtkydho2bIBlAtCmC8fP+5+5jklhu2xnJ?= =?iso-8859-1?Q?pMbrULJ2sJSWsCv3Dn8H+S0OKv+B6ndPQ9ug8yhtpLnXE92tl+HcT6su0V?= =?iso-8859-1?Q?a4QW7gD9tYvTd1pVzHKFVgWgY3fDMyq2HdqmKC5TdbCIkz/elDR2Jo8leE?= =?iso-8859-1?Q?C61P4gyzSe4XJ1tz6C+QbUjgAF6ar9nV8s2FlBWgkxUZRNckoASNyPneL9?= =?iso-8859-1?Q?L3ih6087hNjQ92uL+4FE59+/sAbdTeG+6PIwOIOcTR5+O0H662fcoAN50f?= =?iso-8859-1?Q?F27avVWNCoU+JNqJgEdKE4N53fLn0CrJKDjmxGtcuXvVEXkSsvRcG8SE17?= =?iso-8859-1?Q?OgyI4WjXSTRcLbsTiaH20xhb6YWfB0KnwGUaE6K9zicKTbVQiZ0H3zo3il?= =?iso-8859-1?Q?xWl+OVbJUpOPpLcOWBccdaxImqBTlXsQj2fRj3SqmXiP2Kfem385ATzb57?= =?iso-8859-1?Q?nLSAET7a0dNQ1i4Ntj7BA3cTX0yL09R32fimi3rZX9UatF/D+wVo3lTAZR?= =?iso-8859-1?Q?uiUcu6NitZA2Pge0AIVjA8r4aOGXIr4sNdPYxG95+g+TbgjV5tfbFqWIYU?= =?iso-8859-1?Q?9pp54PRWIBq7tJu86B3OzuJeyQmBsXrWTyuo62cLygsgdb9yjJl9ncrrQc?= =?iso-8859-1?Q?yvSm47Uxf1u/hhXY8q8mT02LmPYg4KBLnUejeUupVP01BgRLd/MgCMecQC?= =?iso-8859-1?Q?wqBITpfoFCBp4jAZ0xldqaq43cb+4U1pDe3p9+fQ6+ePua3CufooJwgJqA?= =?iso-8859-1?Q?26qFpE1GRS+uHj+NAgPv5Bp8JftaQxxBl9hoEJtpNXCNJZnBFv1Ynbyaza?= =?iso-8859-1?Q?J/PGtzmK8JylMgv2+qCGD4QbjuiWRaqVSFKFA+E3u4XGaG/YOu9Dioh30Q?= =?iso-8859-1?Q?X5Ipfev0HoOUUqYvPsr2s4bdOefUUsxWm69p9pfjCcLHPdpSLLp7DYVCHU?= =?iso-8859-1?Q?WYbp/AHf2cD7I=3D?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DM4PR11MB8226.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 97901b3f-bf3f-4b11-0fad-08dc5854b9c8 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2024 05:20:09.6670 (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: rJKNmsbNqMusf1HjZ1qGExgunzS5qi5h0+6r9peM16DbqDVqafMdyZrs2GqzJzmmpWROzI1la0EKXOAG+Cu5Fw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR11MB6013 X-OriginatorOrg: intel.com Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Resent-Date: Mon, 08 Apr 2024 22:20:14 -0700 Resent-From: ray.ni@intel.com Reply-To: devel@edk2.groups.io,ray.ni@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: DuVGNc2YsNZ5xa6ASZqhKDVjx7686176AA= Content-Language: en-US Content-Type: multipart/alternative; boundary="_000_MN6PR11MB8244E88FA8D30AC03F2C75528C072MN6PR11MB8244namp_" X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20240206 header.b=cRhzBw1K; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=intel.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io --_000_MN6PR11MB8244E88FA8D30AC03F2C75528C072MN6PR11MB8244namp_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable This optional plugin is designed to execute before the FSP SecCore to rebase SecCore and PeiCore during runtime. If the FSP binary requires rebasing at runtime, this module should be included within the FSP binary. Additionally, specific patches must be applied to ensure proper functionality. In the absence of this module, manual patching of API offsets within the FSP header is necessary. To illustrate, let's consider a scenario within FSP-S where 'FspSiliconInitEntry' is the initial API to be executed post-rebase. Rather than directly inputting the 'FspSiliconInit' offset into the 'FspSiliconInitEntryOffset' field of the FSP header, the entry point of this module should be used. Furthermore, the 'FspSiliconInit' offset should be placed into 'AsmGetFspSecEntry', which signifies the address to which this module will jump. It is also essential to patch the image bases of SecCore and PeiCore to enable the rebasing functionality of this module. The following is an example of how to apply the necessary patches: Patch Address Patch Value PreFspSecS:_ModuleEntryPoint - [0x0000] PreFspSecS:SecCoreRelativeOff PreFspSecS:AsmGetFspSecCore - Fsp24SecCoreS:BASE PreFspSecS:PeiCoreRelativeOff PreFspSecS:AsmGetFspPeiCore - PeiCore:BASE PreFspSecS:SecEntryRelativeOff PreFspSecS:AsmGetFspSecEntry - Fsp24SecCoreS:FspSiliconInitApi [Ray.1] Can you emphasize this optional plug-in only applies to 64bit FSP? +/** + Relocate Pe/Te Image + + @param[in] ImageBaseAddress Image base address + + @retval EFI_SUCCESS Image is relocated successfully + @retval Others Image is not relocated successfully +**/ +EFI_STATUS +RelocatePeTeImage ( + UINT64 ImageBaseAddress + ) +{ + RETURN_STATUS Status; + PE_COFF_LOADER_IMAGE_CONTEXT ImageContext; + + ZeroMem (&ImageContext, sizeof (ImageContext)); + + ImageContext.Handle =3D (VOID *)ImageBaseAddress; + ImageContext.ImageRead =3D PeCoffLoaderImageReadFromMemory; + + Status =3D PeCoffLoaderGetImageInfo (&ImageContext); + if (EFI_ERROR (Status)) { + ASSERT_EFI_ERROR (Status); + return Status; + } + + ImageContext.ImageAddress =3D (EFI_PHYSICAL_ADDRESS)(UINTN)ImageBaseAddr= ess; + + // + // rebase the image + // + Status =3D PeCoffLoaderRelocateImage (&ImageContext); + + ASSERT_EFI_ERROR (Status); + return Status; +} + +/** + This function will patch the Sec Core and Pei Core in current FSP. +**/ +VOID +EFIAPI +FspPatchSecAndPeiCore ( [Ray.2] Can you rename it as "Fsp*Relocate*SecAndPeiCore"? It's to align with "RelocatePeTeImage". +; +;-------------------------------------------------------------------------= --- +global ASM_PFX(_ModuleEntryPoint) +ASM_PFX(_ModuleEntryPoint): + PUSHA_64 + call ASM_PFX(FspPatchSecAndPeiCore) + POPA_64 + call ASM_PFX(AsmGetFspSecEntry) + jmp rax + +global ASM_PFX(AsmGetFspSecCore) [Ray.3] rename as AsmGetFspSecCoreImageBase and add function header. +ASM_PFX(AsmGetFspSecCore): + lea rax, [ASM_PFX(AsmGetFspSecCore)] + mov rcx, rax + xor rdx, rdx + DB 0x48, 0x2d ; sub rax, 0x???????? +global ASM_PFX(SecCoreRelativeOff) +ASM_PFX(SecCoreRelativeOff): + DD 0 ; This value can be patched by the build= script if need to rebase SecCore [Ray.4] ; RAX =3D SecCore image base at runtime, RCX =3D AsmGetFspSecCore r= untime address + xchg rax, rcx ; After exchange, rcx is the value be su= btract by the patched value + ; rax =3D=3D rcx means patched value is = zero [Ray.5] ; RCX =3D SecCore image base at runtime, RAX =3D AsmGetFspSecCore r= untime address. ; If SecCoreRelativeOff is not patched, RCX =3D RAX =3D AsmGetFspSecCore ru= ntime address. This happens when there is no SecCore in the binary. + CMPXCHG rcx, rdx ; if (rcx =3D=3D rax) {rcx =3D rdx (0) }= else {rax =3D rcx (SecCore image base at runtime)} + mov rax, rcx + ret + +global ASM_PFX(AsmGetFspPeiCore) +ASM_PFX(AsmGetFspPeiCore): + lea rax, [ASM_PFX(AsmGetFspPeiCore)] + mov rcx, rax + xor rdx, rdx + DB 0x48, 0x2d ; sub rax, 0x???????? +global ASM_PFX(PeiCoreRelativeOff) +ASM_PFX(PeiCoreRelativeOff): + DD 0 ; This value can be patched by the build= script if need to rebase PeiCore + xchg rax, rcx ; After exchange, rcx is the value be su= btract by the patched value + ; rax =3D=3D rcx means patched value is = zero + CMPXCHG rcx, rdx ; if (rcx =3D=3D rax) {rcx =3D rdx} else= {rax =3D rcx} + mov rax, rcx + ret + [Ray.6] rename it as AsmGetFspOriginalEntry. +global ASM_PFX(AsmGetFspSecEntry) +ASM_PFX(AsmGetFspSecEntry): + lea rax, [ASM_PFX(AsmGetFspSecEntry)] + DB 0x48, 0x2d ; sub rax, 0x???????? +global ASM_PFX(SecEntryRelativeOff) +ASM_PFX(SecEntryRelativeOff): + DD 0x12345678 ; This value must be patched by the buil= d script + ret -- 2.31.1.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#117528): https://edk2.groups.io/g/devel/message/117528 Mute This Topic: https://groups.io/mt/105304660/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- --_000_MN6PR11MB8244E88FA8D30AC03F2C75528C072MN6PR11MB8244namp_ Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable

 
This optional plug= in is designed to execute before the FSP SecCore to
rebase SecCore and PeiCore during runtime. If the FSP binary requires
rebasing at runtime, this module should be included within the FSP
binary. Additionally, specific patches must be applied to ensure proper
functionality.
In the absence of this module, manual patching of API offsets within
the FSP header is necessary. To illustrate, let's consider a scenario
within FSP-S where 'FspSiliconInitEntry' is the initial API to be
executed post-rebase.
Rather than directly inputting the 'FspSiliconInit' offset into the
'FspSiliconInitEntryOffset' field of the FSP header, the entry point
of this module should be used.
Furthermore, the 'FspSiliconInit' offset should be placed into
'AsmGetFspSecEntry', which signifies the address to which this module
will jump.
It is also essential to patch the image bases of SecCore and PeiCore
to enable the rebasing functionality of this module.

The following is an example of how to apply the necessary patches:
Patch Address          &n= bsp;        Patch Value
<FspSiliconInitEntryOffset>     PreFspSecS:_Modul= eEntryPoint - [0x0000]
PreFspSecS:SecCoreRelativeOff   PreFspSecS:AsmGetFspSecCore
            &nb= sp;            =           - Fsp24SecCoreS:BASE=
PreFspSecS:PeiCoreRelativeOff   PreFspSecS:AsmGetFspPeiCore
            &nb= sp;            =           - PeiCore:BASE
PreFspSecS:SecEntryRelativeOff  PreFspSecS:AsmGetFspSecEntry
            &nb= sp;            =          - Fsp24SecCoreS:FspSilicon= InitApi


[Ray.1] Can you emphasize this optional plug-in only applies to 64bit FSP?<= br>


+/**
+  Relocate Pe/Te Image
+
+  @param[in] ImageBaseAddress   Image base address
+
+  @retval EFI_SUCCESS        =    Image is relocated successfully
+  @retval Others         = ;       Image is not relocated successfully +**/
+EFI_STATUS
+RelocatePeTeImage (
+  UINT64  ImageBaseAddress
+  )
+{
+  RETURN_STATUS         =         Status;
+  PE_COFF_LOADER_IMAGE_CONTEXT  ImageContext;
+
+  ZeroMem (&ImageContext, sizeof (ImageContext));
+
+  ImageContext.Handle    =3D (VOID *)ImageBaseAddress;=
+  ImageContext.ImageRead =3D PeCoffLoaderImageReadFromMemory;
+
+  Status =3D PeCoffLoaderGetImageInfo (&ImageContext);
+  if (EFI_ERROR (Status)) {
+    ASSERT_EFI_ERROR (Status);
+    return Status;
+  }
+
+  ImageContext.ImageAddress =3D (EFI_PHYSICAL_ADDRESS)(UINTN)ImageBas= eAddress;
+
+  //
+  // rebase the image
+  //
+  Status =3D PeCoffLoaderRelocateImage (&ImageContext);
+
+  ASSERT_EFI_ERROR (Status);
+  return Status;
+}
+
+/**
+  This function will patch the Sec Core and Pei Core in current FSP.<= br> +**/
+VOID
+EFIAPI
+FspPatchSecAndPeiCore (

[Ray.2] Can you rename it as "Fsp*Relocate*SecAndPeiCore"?
It's to align with "RelocatePeTeImage".

+;
+;-------------------------------------------------------------------------= ---
+global ASM_PFX(_ModuleEntryPoint)
+ASM_PFX(_ModuleEntryPoint):
+  PUSHA_64
+  call   ASM_PFX(FspPatchSecAndPeiCore)
+  POPA_64
+  call   ASM_PFX(AsmGetFspSecEntry)
+  jmp    rax
+
+global ASM_PFX(AsmGetFspSecCore)

[Ray.3] rename as AsmGetFspSecCoreImageBase and add function header.

+ASM_PFX(AsmGetFspSecCore):
+   lea   rax, [ASM_PFX(AsmGetFspSecCore)]
+   mov   rcx, rax
+   xor   rdx, rdx
+   DB    0x48, 0x2d     =           ; sub rax, 0x???????= ?
+global ASM_PFX(SecCoreRelativeOff)
+ASM_PFX(SecCoreRelativeOff):
+   DD    0       &n= bsp;            = ;    ; This value can be patched by the build script if need= to rebase SecCore

[Ray.4] ; RAX =3D SecCore image base at runtime, RCX =3D AsmGetFspSecCore runtime address

+   xchg=     rax, rcx        =        ; After exchange, rcx is the value be = subtract by the patched value
+            &n= bsp;            = ;         ; rax =3D=3D rcx means pa= tched value is zero
[Ray.5] ; RCX =3D SecCore image base at runtime, RAX =3D AsmGetFspSecCore runtime address.
; If SecCoreRelativeO= ff is not patched, RCX =3D RAX =3D AsmGetFspSecCore runtime address. This h= appens when there is no SecCore in the binary.


+   CMPXCHG rcx, rdx       &nb= sp;       ; if (rcx =3D=3D rax) {rcx =3D rdx = (0) } else {rax =3D rcx (SecCore image base at runtime)}
+   mov     rax, rcx
+   ret
+
+global ASM_PFX(AsmGetFspPeiCore)
+ASM_PFX(AsmGetFspPeiCore):
+   lea   rax, [ASM_PFX(AsmGetFspPeiCore)]
+   mov   rcx, rax
+   xor   rdx, rdx
+   DB    0x48, 0x2d     =           ; sub rax, 0x???????= ?
+global ASM_PFX(PeiCoreRelativeOff)
+ASM_PFX(PeiCoreRelativeOff):
+   DD    0      &nb= sp;            =      ; This value can be patched by the build script if= need to rebase PeiCore
+   xchg    rax, rcx     =           ; After exchange, rc= x is the value be subtract by the patched value
+            &n= bsp;            = ;         ; rax =3D=3D rcx means pa= tched value is zero
+   CMPXCHG rcx, rdx       &nb= sp;       ; if (rcx =3D=3D rax) {rcx =3D rdx}= else {rax =3D rcx}
+   mov     rax, rcx
+   ret
+



[Ray.6] rename it as AsmGetFspOriginalEntry.
+global ASM_PFX(AsmGetFspSecEntry)
+ASM_PFX(AsmGetFspSecEntry):
+   lea   rax, [ASM_PFX(AsmGetFspSecEntry)]
+   DB    0x48, 0x2d     =           ; sub rax, 0x???????= ?
+global ASM_PFX(SecEntryRelativeOff)
+ASM_PFX(SecEntryRelativeOff):
+   DD    0x12345678     =           ; This value must be= patched by the build script
+   ret
--
2.31.1.windows.1

_._,_._,_

Groups.io Links:

=20 You receive all messages sent to this group. =20 =20

View/Reply Online (#117528) | =20 | Mute= This Topic | New Topic
Your Subscriptio= n | Contact Group Owner | Unsubscribe [rebecca@openfw.io]

_._,_._,_
--_000_MN6PR11MB8244E88FA8D30AC03F2C75528C072MN6PR11MB8244namp_--