public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [edk2-devel][PATCH v1] IntelFsp2Pkg: Adding FspHelperLib
@ 2022-11-07  8:43 Kuo, Ted
  2022-11-07  9:31 ` Ashraf Ali S
  0 siblings, 1 reply; 2+ messages in thread
From: Kuo, Ted @ 2022-11-07  8:43 UTC (permalink / raw)
  To: devel
  Cc: Chasel Chiu, Nate DeSimone, Star Zeng, Ashraf Ali S,
	Chinni B Duggapu, Amy Chan

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=4128
Adding FspHelperLib for platform code to consume. There will be
another patch raised later for FspSecCore to consume FspHelperLib.

Cc: Chasel Chiu <chasel.chiu@intel.com>
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Ashraf Ali S <ashraf.ali.s@intel.com>
Cc: Chinni B Duggapu <chinni.b.duggapu@intel.com>
Cc: Amy Chan <amy.chan@intel.com>
Signed-off-by: Ted Kuo <ted.kuo@intel.com>
---
 IntelFsp2Pkg/FspSecCore/SecFsp.h              | 25 +---------
 IntelFsp2Pkg/Include/Library/FspHelperLib.h   | 35 +++++++++++++
 IntelFsp2Pkg/IntelFsp2Pkg.dsc                 |  2 +
 .../BaseFspHelperLib/BaseFspHelperLib.inf     | 50 +++++++++++++++++++
 .../BaseFspHelperLib/Ia32/FspHelper.nasm      | 35 +++++++++++++
 .../BaseFspHelperLib/X64/FspHelper.nasm       | 34 +++++++++++++
 6 files changed, 157 insertions(+), 24 deletions(-)
 create mode 100644 IntelFsp2Pkg/Include/Library/FspHelperLib.h
 create mode 100644 IntelFsp2Pkg/Library/BaseFspHelperLib/BaseFspHelperLib.inf
 create mode 100644 IntelFsp2Pkg/Library/BaseFspHelperLib/Ia32/FspHelper.nasm
 create mode 100644 IntelFsp2Pkg/Library/BaseFspHelperLib/X64/FspHelper.nasm

diff --git a/IntelFsp2Pkg/FspSecCore/SecFsp.h b/IntelFsp2Pkg/FspSecCore/SecFsp.h
index d7a5976c12..f12769890f 100644
--- a/IntelFsp2Pkg/FspSecCore/SecFsp.h
+++ b/IntelFsp2Pkg/FspSecCore/SecFsp.h
@@ -17,6 +17,7 @@
 #include <Library/BaseMemoryLib.h>
 #include <Library/FspCommonLib.h>
 #include <Library/FspSecPlatformLib.h>
+#include <Library/FspHelperLib.h>
 
 #define FSP_MCUD_SIGNATURE  SIGNATURE_32 ('M', 'C', 'U', 'D')
 #define FSP_PER0_SIGNATURE  SIGNATURE_32 ('P', 'E', 'R', '0')
@@ -64,28 +65,4 @@ FspDataPointerFixUp (
   IN UINTN  OffsetGap
   );
 
-/**
-  This interface returns the base address of FSP binary.
-
-  @return   FSP binary base address.
-
-**/
-UINTN
-EFIAPI
-AsmGetFspBaseAddress (
-  VOID
-  );
-
-/**
-  This interface gets FspInfoHeader pointer
-
-  @return   FSP binary base address.
-
-**/
-UINTN
-EFIAPI
-AsmGetFspInfoHeader (
-  VOID
-  );
-
 #endif
diff --git a/IntelFsp2Pkg/Include/Library/FspHelperLib.h b/IntelFsp2Pkg/Include/Library/FspHelperLib.h
new file mode 100644
index 0000000000..84b74fa7aa
--- /dev/null
+++ b/IntelFsp2Pkg/Include/Library/FspHelperLib.h
@@ -0,0 +1,35 @@
+/** @file
+  Header file for FSP Helper Library.
+
+  Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef _FSP_HELPER_LIB_H_
+#define _FSP_HELPER_LIB_H_
+
+/**
+  This interface returns the base address of FSP binary.
+
+  @return   FSP binary base address.
+
+**/
+UINTN
+EFIAPI
+AsmGetFspBaseAddress (
+  VOID
+  );
+
+/**
+  This interface gets FspInfoHeader pointer
+
+  @return   FSP info header.
+**/
+UINTN
+EFIAPI
+AsmGetFspInfoHeader (
+  VOID
+  );
+
+#endif // _FSP_HELPER_LIB_H_
diff --git a/IntelFsp2Pkg/IntelFsp2Pkg.dsc b/IntelFsp2Pkg/IntelFsp2Pkg.dsc
index 0713f0028d..09893d70e8 100644
--- a/IntelFsp2Pkg/IntelFsp2Pkg.dsc
+++ b/IntelFsp2Pkg/IntelFsp2Pkg.dsc
@@ -46,6 +46,7 @@
   FspSwitchStackLib|IntelFsp2Pkg/Library/BaseFspSwitchStackLib/BaseFspSwitchStackLib.inf
   FspSecPlatformLib|IntelFsp2Pkg/Library/SecFspSecPlatformLibNull/SecFspSecPlatformLibNull.inf
   FspMultiPhaseLib|IntelFsp2Pkg/Library/BaseFspMultiPhaseLib/BaseFspMultiPhaseLib.inf
+  FspHelperLib|IntelFsp2Pkg/Library/BaseFspHelperLib/BaseFspHelperLib.inf
 
 [LibraryClasses.common.PEIM]
   PeimEntryPoint|MdePkg/Library/PeimEntryPoint/PeimEntryPoint.inf
@@ -66,6 +67,7 @@
   IntelFsp2Pkg/Library/BaseDebugDeviceLibNull/BaseDebugDeviceLibNull.inf
   IntelFsp2Pkg/Library/SecFspSecPlatformLibNull/SecFspSecPlatformLibNull.inf
   IntelFsp2Pkg/Library/BaseFspMultiPhaseLib/BaseFspMultiPhaseLib.inf
+  IntelFsp2Pkg/Library/BaseFspHelperLib/BaseFspHelperLib.inf
 
   IntelFsp2Pkg/FspSecCore/FspSecCoreT.inf
   IntelFsp2Pkg/FspSecCore/FspSecCoreM.inf
diff --git a/IntelFsp2Pkg/Library/BaseFspHelperLib/BaseFspHelperLib.inf b/IntelFsp2Pkg/Library/BaseFspHelperLib/BaseFspHelperLib.inf
new file mode 100644
index 0000000000..318ad65330
--- /dev/null
+++ b/IntelFsp2Pkg/Library/BaseFspHelperLib/BaseFspHelperLib.inf
@@ -0,0 +1,50 @@
+## @file
+#  FSP Helper Library.
+#
+#  Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
+#
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+################################################################################
+#
+# Defines Section - statements that will be processed to create a Makefile.
+#
+################################################################################
+
+[Defines]
+  INF_VERSION                    = 0x00010005
+  BASE_NAME                      = FspHelperLib
+  FILE_GUID                      = 65746991-8a41-4b89-b0f4-eb4e24b5b471
+  MODULE_TYPE                    = BASE
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = FspHelperLib
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+#  VALID_ARCHITECTURES           = IA32 X64
+#
+
+################################################################################
+#
+# Sources Section - list of files that are required for the build to succeed.
+#
+################################################################################
+
+[Sources.IA32]
+  Ia32/FspHelper.nasm
+
+[Sources.X64]
+  X64/FspHelper.nasm
+
+################################################################################
+#
+# Package Dependency Section - list of Package files that are required for
+#                              this module.
+#
+################################################################################
+
+[Packages]
+  MdePkg/MdePkg.dec
diff --git a/IntelFsp2Pkg/Library/BaseFspHelperLib/Ia32/FspHelper.nasm b/IntelFsp2Pkg/Library/BaseFspHelperLib/Ia32/FspHelper.nasm
new file mode 100644
index 0000000000..e3e1945473
--- /dev/null
+++ b/IntelFsp2Pkg/Library/BaseFspHelperLib/Ia32/FspHelper.nasm
@@ -0,0 +1,35 @@
+;; @file
+;  Provide FSP helper function.
+;
+; Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>
+; SPDX-License-Identifier: BSD-2-Clause-Patent
+;;
+
+    SECTION .text
+
+global ASM_PFX(FspInfoHeaderRelativeOff)
+ASM_PFX(FspInfoHeaderRelativeOff):
+   DD    0x12345678               ; This value must be patched by the build script
+
+global ASM_PFX(AsmGetFspBaseAddress)
+ASM_PFX(AsmGetFspBaseAddress):
+   call  ASM_PFX(AsmGetFspInfoHeader)
+   add   eax, 0x1C
+   mov   eax, dword [eax]
+   ret
+
+global ASM_PFX(AsmGetFspInfoHeader)
+ASM_PFX(AsmGetFspInfoHeader):
+   call  ASM_PFX(NextInstruction)
+ASM_PFX(NextInstruction):
+   pop   eax
+   sub   eax, ASM_PFX(NextInstruction)
+   add   eax, ASM_PFX(AsmGetFspInfoHeader)
+   sub   eax, dword [eax - ASM_PFX(AsmGetFspInfoHeader) + ASM_PFX(FspInfoHeaderRelativeOff)]
+   ret
+
+global ASM_PFX(AsmGetFspInfoHeaderNoStack)
+ASM_PFX(AsmGetFspInfoHeaderNoStack):
+   mov   eax, ASM_PFX(AsmGetFspInfoHeader)
+   sub   eax, dword [ASM_PFX(FspInfoHeaderRelativeOff)]
+   jmp   edi
diff --git a/IntelFsp2Pkg/Library/BaseFspHelperLib/X64/FspHelper.nasm b/IntelFsp2Pkg/Library/BaseFspHelperLib/X64/FspHelper.nasm
new file mode 100644
index 0000000000..122fa1d174
--- /dev/null
+++ b/IntelFsp2Pkg/Library/BaseFspHelperLib/X64/FspHelper.nasm
@@ -0,0 +1,34 @@
+;; @file
+;  Provide FSP helper function.
+;
+; Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
+; SPDX-License-Identifier: BSD-2-Clause-Patent
+;;
+    DEFAULT  REL
+    SECTION .text
+
+global ASM_PFX(AsmGetFspBaseAddress)
+ASM_PFX(AsmGetFspBaseAddress):
+   call  ASM_PFX(AsmGetFspInfoHeader)
+   add   rax, 0x1C
+   mov   eax, [rax]
+   ret
+
+global ASM_PFX(AsmGetFspInfoHeader)
+ASM_PFX(AsmGetFspInfoHeader):
+   lea   rax, [ASM_PFX(AsmGetFspInfoHeader)]
+   DB    0x48, 0x2d               ; sub rax, 0x????????
+global ASM_PFX(FspInfoHeaderRelativeOff)
+ASM_PFX(FspInfoHeaderRelativeOff):
+   DD    0x12345678               ; This value must be patched by the build script
+   and   rax, 0xffffffff
+   ret
+
+global ASM_PFX(AsmGetFspInfoHeaderNoStack)
+ASM_PFX(AsmGetFspInfoHeaderNoStack):
+   lea   rax, [ASM_PFX(AsmGetFspInfoHeader)]
+   lea   rcx, [ASM_PFX(FspInfoHeaderRelativeOff)]
+   mov   ecx, [rcx]
+   sub   rax, rcx
+   and   rax, 0xffffffff
+   jmp   rdi
-- 
2.35.3.windows.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-11-07  9:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-07  8:43 [edk2-devel][PATCH v1] IntelFsp2Pkg: Adding FspHelperLib Kuo, Ted
2022-11-07  9:31 ` Ashraf Ali S

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox