public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [edk2-devel][PATCH] IntelFsp2Pkg: BaseFspCommonLib Support for X64
@ 2022-03-14  4:22 Kuo, Ted
  2022-03-22  7:43 ` Chiu, Chasel
  2022-03-22  8:18 ` Chiu, Chasel
  0 siblings, 2 replies; 3+ messages in thread
From: Kuo, Ted @ 2022-03-14  4:22 UTC (permalink / raw)
  To: devel; +Cc: Chasel Chiu, Nate DeSimone, Star Zeng, Ashraf Ali S

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3867
Add BaseFspCommonLib Support for X64.

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>
Signed-off-by: Ted Kuo <ted.kuo@intel.com>
---
 IntelFsp2Pkg/FspSecCore/SecFsp.c                   |  2 +-
 IntelFsp2Pkg/FspSecCore/SecFsp.h                   |  2 +-
 IntelFsp2Pkg/Include/FspGlobalData.h               |  2 +-
 IntelFsp2Pkg/Include/Library/FspCommonLib.h        |  6 +-
 .../Library/BaseFspCommonLib/FspCommonLib.c        | 65 +++++++++++++---------
 5 files changed, 45 insertions(+), 32 deletions(-)

diff --git a/IntelFsp2Pkg/FspSecCore/SecFsp.c b/IntelFsp2Pkg/FspSecCore/SecFsp.c
index f79d45900e..68e588dd41 100644
--- a/IntelFsp2Pkg/FspSecCore/SecFsp.c
+++ b/IntelFsp2Pkg/FspSecCore/SecFsp.c
@@ -217,7 +217,7 @@ FspGlobalDataInit (
 **/
 VOID
 FspDataPointerFixUp (
-  IN UINT32  OffsetGap
+  IN UINTN  OffsetGap
   )
 {
   FSP_GLOBAL_DATA  *NewFspData;
diff --git a/IntelFsp2Pkg/FspSecCore/SecFsp.h b/IntelFsp2Pkg/FspSecCore/SecFsp.h
index aacd32f7f7..7c9be85fe0 100644
--- a/IntelFsp2Pkg/FspSecCore/SecFsp.h
+++ b/IntelFsp2Pkg/FspSecCore/SecFsp.h
@@ -61,7 +61,7 @@ FspGlobalDataInit (
 **/
 VOID
 FspDataPointerFixUp (
-  IN UINT32  OffsetGap
+  IN UINTN  OffsetGap
   );
 
 /**
diff --git a/IntelFsp2Pkg/Include/FspGlobalData.h b/IntelFsp2Pkg/Include/FspGlobalData.h
index 71033121c4..2b534075ae 100644
--- a/IntelFsp2Pkg/Include/FspGlobalData.h
+++ b/IntelFsp2Pkg/Include/FspGlobalData.h
@@ -42,7 +42,7 @@ typedef struct  {
   UINT32             Signature;
   UINT8              Version;
   UINT8              Reserved1[3];
-  UINT32             CoreStack;
+  UINTN              CoreStack;
   UINT32             StatusCode;
   UINT32             Reserved2[8];
   FSP_PLAT_DATA      PlatformData;
diff --git a/IntelFsp2Pkg/Include/Library/FspCommonLib.h b/IntelFsp2Pkg/Include/Library/FspCommonLib.h
index c70039d9e8..b5e38568e2 100644
--- a/IntelFsp2Pkg/Include/Library/FspCommonLib.h
+++ b/IntelFsp2Pkg/Include/Library/FspCommonLib.h
@@ -38,7 +38,7 @@ GetFspGlobalDataPointer (
 
   @retval ApiParameter FSP API first parameter passed by the bootloader.
 **/
-UINT32
+UINTN
 EFIAPI
 GetFspApiParameter (
   VOID
@@ -49,7 +49,7 @@ GetFspApiParameter (
 
   @retval ApiParameter FSP API second parameter passed by the bootloader.
 **/
-UINT32
+UINTN
 EFIAPI
 GetFspApiParameter2 (
   VOID
@@ -87,7 +87,7 @@ SetFspApiParameter (
 VOID
 EFIAPI
 SetFspApiReturnStatus (
-  IN UINT32  ReturnStatus
+  IN UINTN  ReturnStatus
   );
 
 /**
diff --git a/IntelFsp2Pkg/Library/BaseFspCommonLib/FspCommonLib.c b/IntelFsp2Pkg/Library/BaseFspCommonLib/FspCommonLib.c
index 8f8453915e..cd10b63c95 100644
--- a/IntelFsp2Pkg/Library/BaseFspCommonLib/FspCommonLib.c
+++ b/IntelFsp2Pkg/Library/BaseFspCommonLib/FspCommonLib.c
@@ -30,21 +30,34 @@ typedef struct {
   UINT16    IdtrLimit;
   UINT32    IdtrBase;
   UINT16    Reserved;
-  UINT32    Edi;
-  UINT32    Esi;
-  UINT32    Ebp;
-  UINT32    Esp;
-  UINT32    Ebx;
-  UINT32    Edx;
-  UINT32    Ecx;
-  UINT32    Eax;
+  UINT32    Registers[8];   // General Purpose Registers: Edi, Esi, Ebp, Esp, Ebx, Edx, Ecx and Eax
   UINT16    Flags[2];
   UINT32    FspInfoHeader;
   UINT32    ApiRet;
   UINT32    ApiParam[2];
 } CONTEXT_STACK;
 
-#define CONTEXT_STACK_OFFSET(x)  (UINT32)&((CONTEXT_STACK *)(UINTN)0)->x
+//
+//   API return address           +0xB0
+//   push    API Parameter2       +0xA8
+//   push    API Parameter1       +0xA0
+//   push    FspInfoHeader        +0x98
+//   pushfq                       +0x90
+//   cli
+//   PUSHA_64                     +0x10
+//   sub     rsp, 16              +0x00
+//   sidt    [rsp]
+//
+typedef struct {
+  UINT64    Idtr[2];        // IDTR Limit - bit0:bi15, IDTR Base - bit16:bit79
+  UINT64    Registers[16];  // General Purpose Registers: RDI, RSI, RBP, RSP, RBX, RDX, RCX, RAX, and R15 to R8
+  UINT32    Flags[2];
+  UINT64    FspInfoHeader;
+  UINT64    ApiParam[2];
+  UINT64    ApiRet;         // 64bit stack format is different from the 32bit one due to x64 calling convention
+} CONTEXT_STACK_64;
+
+#define CONTEXT_STACK_OFFSET(x)  (sizeof(UINTN) == sizeof (UINT32) ? (UINTN)&((CONTEXT_STACK *)(UINTN)0)->x : (UINTN)&((CONTEXT_STACK_64 *)(UINTN)0)->x)
 
 #pragma pack()
 
@@ -85,7 +98,7 @@ GetFspGlobalDataPointer (
 
   @retval ApiParameter FSP API first parameter passed by the bootloader.
 **/
-UINT32
+UINTN
 EFIAPI
 GetFspApiParameter (
   VOID
@@ -94,7 +107,7 @@ GetFspApiParameter (
   FSP_GLOBAL_DATA  *FspData;
 
   FspData = GetFspGlobalDataPointer ();
-  return *(UINT32 *)(UINTN)(FspData->CoreStack + CONTEXT_STACK_OFFSET (ApiParam[0]));
+  return *(UINTN *)(FspData->CoreStack + CONTEXT_STACK_OFFSET (ApiParam[0]));
 }
 
 /**
@@ -119,7 +132,7 @@ GetFspEntryStack (
 
   @retval ApiParameter FSP API second parameter passed by the bootloader.
 **/
-UINT32
+UINTN
 EFIAPI
 GetFspApiParameter2 (
   VOID
@@ -128,7 +141,7 @@ GetFspApiParameter2 (
   FSP_GLOBAL_DATA  *FspData;
 
   FspData = GetFspGlobalDataPointer ();
-  return *(UINT32 *)(UINTN)(FspData->CoreStack + CONTEXT_STACK_OFFSET (ApiParam[1]));
+  return *(UINTN *)(FspData->CoreStack + CONTEXT_STACK_OFFSET (ApiParam[1]));
 }
 
 /**
@@ -145,8 +158,8 @@ SetFspApiParameter (
 {
   FSP_GLOBAL_DATA  *FspData;
 
-  FspData                                                                  = GetFspGlobalDataPointer ();
-  *(UINT32 *)(UINTN)(FspData->CoreStack + CONTEXT_STACK_OFFSET (ApiParam)) = Value;
+  FspData                                                          = GetFspGlobalDataPointer ();
+  *(UINTN *)(FspData->CoreStack + CONTEXT_STACK_OFFSET (ApiParam)) = Value;
 }
 
 /**
@@ -158,13 +171,13 @@ SetFspApiParameter (
 VOID
 EFIAPI
 SetFspApiReturnStatus (
-  IN UINT32  ReturnStatus
+  IN UINTN  ReturnStatus
   )
 {
   FSP_GLOBAL_DATA  *FspData;
 
-  FspData                                                             = GetFspGlobalDataPointer ();
-  *(UINT32 *)(UINTN)(FspData->CoreStack + CONTEXT_STACK_OFFSET (Eax)) = ReturnStatus;
+  FspData                                                              = GetFspGlobalDataPointer ();
+  *(UINTN *)(FspData->CoreStack + CONTEXT_STACK_OFFSET (Registers[7])) = ReturnStatus;
 }
 
 /**
@@ -180,19 +193,19 @@ SetFspCoreStackPointer (
   )
 {
   FSP_GLOBAL_DATA  *FspData;
-  UINT32           *OldStack;
-  UINT32           *NewStack;
+  UINTN            *OldStack;
+  UINTN            *NewStack;
   UINT32           StackContextLen;
 
   FspData         = GetFspGlobalDataPointer ();
-  StackContextLen = sizeof (CONTEXT_STACK) / sizeof (UINT32);
+  StackContextLen = sizeof(CONTEXT_STACK) / sizeof(UINTN);
 
   //
   // Reserve space for the ContinuationFunc two parameters
   //
-  OldStack           = (UINT32 *)FspData->CoreStack;
-  NewStack           = (UINT32 *)NewStackTop - StackContextLen - 2;
-  FspData->CoreStack = (UINT32)NewStack;
+  OldStack = (UINTN *)FspData->CoreStack;
+  NewStack = (UINTN *)NewStackTop - StackContextLen - 2;
+  FspData->CoreStack = (UINTN)NewStack;
   while (StackContextLen-- != 0) {
     *NewStack++ = *OldStack++;
   }
@@ -427,7 +440,7 @@ GetFspInfoHeaderFromApiContext (
   FSP_GLOBAL_DATA  *FspData;
 
   FspData = GetFspGlobalDataPointer ();
-  return (FSP_INFO_HEADER *)(*(UINT32 *)(UINTN)(FspData->CoreStack + CONTEXT_STACK_OFFSET (FspInfoHeader)));
+  return (FSP_INFO_HEADER *)(*(UINTN *)(FspData->CoreStack + CONTEXT_STACK_OFFSET (FspInfoHeader)));
 }
 
 /**
@@ -444,7 +457,7 @@ GetFspCfgRegionDataPointer (
   FSP_INFO_HEADER  *FspInfoHeader;
 
   FspInfoHeader = GetFspInfoHeader ();
-  return (VOID *)(FspInfoHeader->ImageBase + FspInfoHeader->CfgRegionOffset);
+  return (VOID *)(UINTN)(FspInfoHeader->ImageBase + FspInfoHeader->CfgRegionOffset);
 }
 
 /**
-- 
2.16.2.windows.1


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

* Re: [edk2-devel][PATCH] IntelFsp2Pkg: BaseFspCommonLib Support for X64
  2022-03-14  4:22 [edk2-devel][PATCH] IntelFsp2Pkg: BaseFspCommonLib Support for X64 Kuo, Ted
@ 2022-03-22  7:43 ` Chiu, Chasel
  2022-03-22  8:18 ` Chiu, Chasel
  1 sibling, 0 replies; 3+ messages in thread
From: Chiu, Chasel @ 2022-03-22  7:43 UTC (permalink / raw)
  To: Kuo, Ted, devel@edk2.groups.io
  Cc: Desimone, Nathaniel L, Zeng, Star, S, Ashraf Ali


Thanks Ted!
Reviewed-by: Chasel Chiu <chasel.chiu@intel.com>


> -----Original Message-----
> From: Kuo, Ted <ted.kuo@intel.com>
> Sent: Monday, March 14, 2022 12:23 PM
> To: devel@edk2.groups.io
> Cc: Chiu, Chasel <chasel.chiu@intel.com>; Desimone, Nathaniel L
> <nathaniel.l.desimone@intel.com>; Zeng, Star <star.zeng@intel.com>; S,
> Ashraf Ali <ashraf.ali.s@intel.com>
> Subject: [edk2-devel][PATCH] IntelFsp2Pkg: BaseFspCommonLib Support for
> X64
> 
> REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3867
> Add BaseFspCommonLib Support for X64.
> 
> 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>
> Signed-off-by: Ted Kuo <ted.kuo@intel.com>
> ---
>  IntelFsp2Pkg/FspSecCore/SecFsp.c                   |  2 +-
>  IntelFsp2Pkg/FspSecCore/SecFsp.h                   |  2 +-
>  IntelFsp2Pkg/Include/FspGlobalData.h               |  2 +-
>  IntelFsp2Pkg/Include/Library/FspCommonLib.h        |  6 +-
>  .../Library/BaseFspCommonLib/FspCommonLib.c        | 65
> +++++++++++++---------
>  5 files changed, 45 insertions(+), 32 deletions(-)
> 
> diff --git a/IntelFsp2Pkg/FspSecCore/SecFsp.c
> b/IntelFsp2Pkg/FspSecCore/SecFsp.c
> index f79d45900e..68e588dd41 100644
> --- a/IntelFsp2Pkg/FspSecCore/SecFsp.c
> +++ b/IntelFsp2Pkg/FspSecCore/SecFsp.c
> @@ -217,7 +217,7 @@ FspGlobalDataInit (
>  **/
>  VOID
>  FspDataPointerFixUp (
> -  IN UINT32  OffsetGap
> +  IN UINTN  OffsetGap
>    )
>  {
>    FSP_GLOBAL_DATA  *NewFspData;
> diff --git a/IntelFsp2Pkg/FspSecCore/SecFsp.h
> b/IntelFsp2Pkg/FspSecCore/SecFsp.h
> index aacd32f7f7..7c9be85fe0 100644
> --- a/IntelFsp2Pkg/FspSecCore/SecFsp.h
> +++ b/IntelFsp2Pkg/FspSecCore/SecFsp.h
> @@ -61,7 +61,7 @@ FspGlobalDataInit (
>  **/
>  VOID
>  FspDataPointerFixUp (
> -  IN UINT32  OffsetGap
> +  IN UINTN  OffsetGap
>    );
> 
>  /**
> diff --git a/IntelFsp2Pkg/Include/FspGlobalData.h
> b/IntelFsp2Pkg/Include/FspGlobalData.h
> index 71033121c4..2b534075ae 100644
> --- a/IntelFsp2Pkg/Include/FspGlobalData.h
> +++ b/IntelFsp2Pkg/Include/FspGlobalData.h
> @@ -42,7 +42,7 @@ typedef struct  {
>    UINT32             Signature;
>    UINT8              Version;
>    UINT8              Reserved1[3];
> -  UINT32             CoreStack;
> +  UINTN              CoreStack;
>    UINT32             StatusCode;
>    UINT32             Reserved2[8];
>    FSP_PLAT_DATA      PlatformData;
> diff --git a/IntelFsp2Pkg/Include/Library/FspCommonLib.h
> b/IntelFsp2Pkg/Include/Library/FspCommonLib.h
> index c70039d9e8..b5e38568e2 100644
> --- a/IntelFsp2Pkg/Include/Library/FspCommonLib.h
> +++ b/IntelFsp2Pkg/Include/Library/FspCommonLib.h
> @@ -38,7 +38,7 @@ GetFspGlobalDataPointer (
> 
>    @retval ApiParameter FSP API first parameter passed by the bootloader.
>  **/
> -UINT32
> +UINTN
>  EFIAPI
>  GetFspApiParameter (
>    VOID
> @@ -49,7 +49,7 @@ GetFspApiParameter (
> 
>    @retval ApiParameter FSP API second parameter passed by the
> bootloader.
>  **/
> -UINT32
> +UINTN
>  EFIAPI
>  GetFspApiParameter2 (
>    VOID
> @@ -87,7 +87,7 @@ SetFspApiParameter (
>  VOID
>  EFIAPI
>  SetFspApiReturnStatus (
> -  IN UINT32  ReturnStatus
> +  IN UINTN  ReturnStatus
>    );
> 
>  /**
> diff --git a/IntelFsp2Pkg/Library/BaseFspCommonLib/FspCommonLib.c
> b/IntelFsp2Pkg/Library/BaseFspCommonLib/FspCommonLib.c
> index 8f8453915e..cd10b63c95 100644
> --- a/IntelFsp2Pkg/Library/BaseFspCommonLib/FspCommonLib.c
> +++ b/IntelFsp2Pkg/Library/BaseFspCommonLib/FspCommonLib.c
> @@ -30,21 +30,34 @@ typedef struct {
>    UINT16    IdtrLimit;
>    UINT32    IdtrBase;
>    UINT16    Reserved;
> -  UINT32    Edi;
> -  UINT32    Esi;
> -  UINT32    Ebp;
> -  UINT32    Esp;
> -  UINT32    Ebx;
> -  UINT32    Edx;
> -  UINT32    Ecx;
> -  UINT32    Eax;
> +  UINT32    Registers[8];   // General Purpose Registers: Edi, Esi, Ebp, Esp,
> Ebx, Edx, Ecx and Eax
>    UINT16    Flags[2];
>    UINT32    FspInfoHeader;
>    UINT32    ApiRet;
>    UINT32    ApiParam[2];
>  } CONTEXT_STACK;
> 
> -#define CONTEXT_STACK_OFFSET(x)  (UINT32)&((CONTEXT_STACK
> *)(UINTN)0)->x
> +//
> +//   API return address           +0xB0
> +//   push    API Parameter2       +0xA8
> +//   push    API Parameter1       +0xA0
> +//   push    FspInfoHeader        +0x98
> +//   pushfq                       +0x90
> +//   cli
> +//   PUSHA_64                     +0x10
> +//   sub     rsp, 16              +0x00
> +//   sidt    [rsp]
> +//
> +typedef struct {
> +  UINT64    Idtr[2];        // IDTR Limit - bit0:bi15, IDTR Base - bit16:bit79
> +  UINT64    Registers[16];  // General Purpose Registers: RDI, RSI, RBP, RSP,
> RBX, RDX, RCX, RAX, and R15 to R8
> +  UINT32    Flags[2];
> +  UINT64    FspInfoHeader;
> +  UINT64    ApiParam[2];
> +  UINT64    ApiRet;         // 64bit stack format is different from the 32bit
> one due to x64 calling convention
> +} CONTEXT_STACK_64;
> +
> +#define CONTEXT_STACK_OFFSET(x)  (sizeof(UINTN) == sizeof (UINT32) ?
> +(UINTN)&((CONTEXT_STACK *)(UINTN)0)->x :
> (UINTN)&((CONTEXT_STACK_64
> +*)(UINTN)0)->x)
> 
>  #pragma pack()
> 
> @@ -85,7 +98,7 @@ GetFspGlobalDataPointer (
> 
>    @retval ApiParameter FSP API first parameter passed by the bootloader.
>  **/
> -UINT32
> +UINTN
>  EFIAPI
>  GetFspApiParameter (
>    VOID
> @@ -94,7 +107,7 @@ GetFspApiParameter (
>    FSP_GLOBAL_DATA  *FspData;
> 
>    FspData = GetFspGlobalDataPointer ();
> -  return *(UINT32 *)(UINTN)(FspData->CoreStack +
> CONTEXT_STACK_OFFSET (ApiParam[0]));
> +  return *(UINTN *)(FspData->CoreStack + CONTEXT_STACK_OFFSET
> + (ApiParam[0]));
>  }
> 
>  /**
> @@ -119,7 +132,7 @@ GetFspEntryStack (
> 
>    @retval ApiParameter FSP API second parameter passed by the
> bootloader.
>  **/
> -UINT32
> +UINTN
>  EFIAPI
>  GetFspApiParameter2 (
>    VOID
> @@ -128,7 +141,7 @@ GetFspApiParameter2 (
>    FSP_GLOBAL_DATA  *FspData;
> 
>    FspData = GetFspGlobalDataPointer ();
> -  return *(UINT32 *)(UINTN)(FspData->CoreStack +
> CONTEXT_STACK_OFFSET (ApiParam[1]));
> +  return *(UINTN *)(FspData->CoreStack + CONTEXT_STACK_OFFSET
> + (ApiParam[1]));
>  }
> 
>  /**
> @@ -145,8 +158,8 @@ SetFspApiParameter (  {
>    FSP_GLOBAL_DATA  *FspData;
> 
> -  FspData                                                                  = GetFspGlobalDataPointer
> ();
> -  *(UINT32 *)(UINTN)(FspData->CoreStack + CONTEXT_STACK_OFFSET
> (ApiParam)) = Value;
> +  FspData                                                          = GetFspGlobalDataPointer ();
> +  *(UINTN *)(FspData->CoreStack + CONTEXT_STACK_OFFSET (ApiParam))
> =
> + Value;
>  }
> 
>  /**
> @@ -158,13 +171,13 @@ SetFspApiParameter (  VOID  EFIAPI
> SetFspApiReturnStatus (
> -  IN UINT32  ReturnStatus
> +  IN UINTN  ReturnStatus
>    )
>  {
>    FSP_GLOBAL_DATA  *FspData;
> 
> -  FspData                                                             = GetFspGlobalDataPointer ();
> -  *(UINT32 *)(UINTN)(FspData->CoreStack + CONTEXT_STACK_OFFSET (Eax))
> = ReturnStatus;
> +  FspData                                                              = GetFspGlobalDataPointer ();
> +  *(UINTN *)(FspData->CoreStack + CONTEXT_STACK_OFFSET (Registers[7]))
> + = ReturnStatus;
>  }
> 
>  /**
> @@ -180,19 +193,19 @@ SetFspCoreStackPointer (
>    )
>  {
>    FSP_GLOBAL_DATA  *FspData;
> -  UINT32           *OldStack;
> -  UINT32           *NewStack;
> +  UINTN            *OldStack;
> +  UINTN            *NewStack;
>    UINT32           StackContextLen;
> 
>    FspData         = GetFspGlobalDataPointer ();
> -  StackContextLen = sizeof (CONTEXT_STACK) / sizeof (UINT32);
> +  StackContextLen = sizeof(CONTEXT_STACK) / sizeof(UINTN);
> 
>    //
>    // Reserve space for the ContinuationFunc two parameters
>    //
> -  OldStack           = (UINT32 *)FspData->CoreStack;
> -  NewStack           = (UINT32 *)NewStackTop - StackContextLen - 2;
> -  FspData->CoreStack = (UINT32)NewStack;
> +  OldStack = (UINTN *)FspData->CoreStack;  NewStack = (UINTN
> + *)NewStackTop - StackContextLen - 2;  FspData->CoreStack =
> + (UINTN)NewStack;
>    while (StackContextLen-- != 0) {
>      *NewStack++ = *OldStack++;
>    }
> @@ -427,7 +440,7 @@ GetFspInfoHeaderFromApiContext (
>    FSP_GLOBAL_DATA  *FspData;
> 
>    FspData = GetFspGlobalDataPointer ();
> -  return (FSP_INFO_HEADER *)(*(UINT32 *)(UINTN)(FspData->CoreStack +
> CONTEXT_STACK_OFFSET (FspInfoHeader)));
> +  return (FSP_INFO_HEADER *)(*(UINTN *)(FspData->CoreStack +
> + CONTEXT_STACK_OFFSET (FspInfoHeader)));
>  }
> 
>  /**
> @@ -444,7 +457,7 @@ GetFspCfgRegionDataPointer (
>    FSP_INFO_HEADER  *FspInfoHeader;
> 
>    FspInfoHeader = GetFspInfoHeader ();
> -  return (VOID *)(FspInfoHeader->ImageBase + FspInfoHeader-
> >CfgRegionOffset);
> +  return (VOID *)(UINTN)(FspInfoHeader->ImageBase +
> + FspInfoHeader->CfgRegionOffset);
>  }
> 
>  /**
> --
> 2.16.2.windows.1


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

* Re: [edk2-devel][PATCH] IntelFsp2Pkg: BaseFspCommonLib Support for X64
  2022-03-14  4:22 [edk2-devel][PATCH] IntelFsp2Pkg: BaseFspCommonLib Support for X64 Kuo, Ted
  2022-03-22  7:43 ` Chiu, Chasel
@ 2022-03-22  8:18 ` Chiu, Chasel
  1 sibling, 0 replies; 3+ messages in thread
From: Chiu, Chasel @ 2022-03-22  8:18 UTC (permalink / raw)
  To: Kuo, Ted, devel@edk2.groups.io
  Cc: Desimone, Nathaniel L, Zeng, Star, S, Ashraf Ali


Patch pushed: https://github.com/tianocore/edk2/commit/ec0b54849b23efa25caf0055b0eef8bf9b4dec98

Thanks,
Chasel


> -----Original Message-----
> From: Kuo, Ted <ted.kuo@intel.com>
> Sent: Monday, March 14, 2022 12:23 PM
> To: devel@edk2.groups.io
> Cc: Chiu, Chasel <chasel.chiu@intel.com>; Desimone, Nathaniel L
> <nathaniel.l.desimone@intel.com>; Zeng, Star <star.zeng@intel.com>; S,
> Ashraf Ali <ashraf.ali.s@intel.com>
> Subject: [edk2-devel][PATCH] IntelFsp2Pkg: BaseFspCommonLib Support for
> X64
> 
> REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3867
> Add BaseFspCommonLib Support for X64.
> 
> 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>
> Signed-off-by: Ted Kuo <ted.kuo@intel.com>
> ---
>  IntelFsp2Pkg/FspSecCore/SecFsp.c                   |  2 +-
>  IntelFsp2Pkg/FspSecCore/SecFsp.h                   |  2 +-
>  IntelFsp2Pkg/Include/FspGlobalData.h               |  2 +-
>  IntelFsp2Pkg/Include/Library/FspCommonLib.h        |  6 +-
>  .../Library/BaseFspCommonLib/FspCommonLib.c        | 65
> +++++++++++++---------
>  5 files changed, 45 insertions(+), 32 deletions(-)
> 
> diff --git a/IntelFsp2Pkg/FspSecCore/SecFsp.c
> b/IntelFsp2Pkg/FspSecCore/SecFsp.c
> index f79d45900e..68e588dd41 100644
> --- a/IntelFsp2Pkg/FspSecCore/SecFsp.c
> +++ b/IntelFsp2Pkg/FspSecCore/SecFsp.c
> @@ -217,7 +217,7 @@ FspGlobalDataInit (
>  **/
>  VOID
>  FspDataPointerFixUp (
> -  IN UINT32  OffsetGap
> +  IN UINTN  OffsetGap
>    )
>  {
>    FSP_GLOBAL_DATA  *NewFspData;
> diff --git a/IntelFsp2Pkg/FspSecCore/SecFsp.h
> b/IntelFsp2Pkg/FspSecCore/SecFsp.h
> index aacd32f7f7..7c9be85fe0 100644
> --- a/IntelFsp2Pkg/FspSecCore/SecFsp.h
> +++ b/IntelFsp2Pkg/FspSecCore/SecFsp.h
> @@ -61,7 +61,7 @@ FspGlobalDataInit (
>  **/
>  VOID
>  FspDataPointerFixUp (
> -  IN UINT32  OffsetGap
> +  IN UINTN  OffsetGap
>    );
> 
>  /**
> diff --git a/IntelFsp2Pkg/Include/FspGlobalData.h
> b/IntelFsp2Pkg/Include/FspGlobalData.h
> index 71033121c4..2b534075ae 100644
> --- a/IntelFsp2Pkg/Include/FspGlobalData.h
> +++ b/IntelFsp2Pkg/Include/FspGlobalData.h
> @@ -42,7 +42,7 @@ typedef struct  {
>    UINT32             Signature;
>    UINT8              Version;
>    UINT8              Reserved1[3];
> -  UINT32             CoreStack;
> +  UINTN              CoreStack;
>    UINT32             StatusCode;
>    UINT32             Reserved2[8];
>    FSP_PLAT_DATA      PlatformData;
> diff --git a/IntelFsp2Pkg/Include/Library/FspCommonLib.h
> b/IntelFsp2Pkg/Include/Library/FspCommonLib.h
> index c70039d9e8..b5e38568e2 100644
> --- a/IntelFsp2Pkg/Include/Library/FspCommonLib.h
> +++ b/IntelFsp2Pkg/Include/Library/FspCommonLib.h
> @@ -38,7 +38,7 @@ GetFspGlobalDataPointer (
> 
>    @retval ApiParameter FSP API first parameter passed by the bootloader.
>  **/
> -UINT32
> +UINTN
>  EFIAPI
>  GetFspApiParameter (
>    VOID
> @@ -49,7 +49,7 @@ GetFspApiParameter (
> 
>    @retval ApiParameter FSP API second parameter passed by the
> bootloader.
>  **/
> -UINT32
> +UINTN
>  EFIAPI
>  GetFspApiParameter2 (
>    VOID
> @@ -87,7 +87,7 @@ SetFspApiParameter (
>  VOID
>  EFIAPI
>  SetFspApiReturnStatus (
> -  IN UINT32  ReturnStatus
> +  IN UINTN  ReturnStatus
>    );
> 
>  /**
> diff --git a/IntelFsp2Pkg/Library/BaseFspCommonLib/FspCommonLib.c
> b/IntelFsp2Pkg/Library/BaseFspCommonLib/FspCommonLib.c
> index 8f8453915e..cd10b63c95 100644
> --- a/IntelFsp2Pkg/Library/BaseFspCommonLib/FspCommonLib.c
> +++ b/IntelFsp2Pkg/Library/BaseFspCommonLib/FspCommonLib.c
> @@ -30,21 +30,34 @@ typedef struct {
>    UINT16    IdtrLimit;
>    UINT32    IdtrBase;
>    UINT16    Reserved;
> -  UINT32    Edi;
> -  UINT32    Esi;
> -  UINT32    Ebp;
> -  UINT32    Esp;
> -  UINT32    Ebx;
> -  UINT32    Edx;
> -  UINT32    Ecx;
> -  UINT32    Eax;
> +  UINT32    Registers[8];   // General Purpose Registers: Edi, Esi, Ebp, Esp,
> Ebx, Edx, Ecx and Eax
>    UINT16    Flags[2];
>    UINT32    FspInfoHeader;
>    UINT32    ApiRet;
>    UINT32    ApiParam[2];
>  } CONTEXT_STACK;
> 
> -#define CONTEXT_STACK_OFFSET(x)  (UINT32)&((CONTEXT_STACK
> *)(UINTN)0)->x
> +//
> +//   API return address           +0xB0
> +//   push    API Parameter2       +0xA8
> +//   push    API Parameter1       +0xA0
> +//   push    FspInfoHeader        +0x98
> +//   pushfq                       +0x90
> +//   cli
> +//   PUSHA_64                     +0x10
> +//   sub     rsp, 16              +0x00
> +//   sidt    [rsp]
> +//
> +typedef struct {
> +  UINT64    Idtr[2];        // IDTR Limit - bit0:bi15, IDTR Base - bit16:bit79
> +  UINT64    Registers[16];  // General Purpose Registers: RDI, RSI, RBP, RSP,
> RBX, RDX, RCX, RAX, and R15 to R8
> +  UINT32    Flags[2];
> +  UINT64    FspInfoHeader;
> +  UINT64    ApiParam[2];
> +  UINT64    ApiRet;         // 64bit stack format is different from the 32bit
> one due to x64 calling convention
> +} CONTEXT_STACK_64;
> +
> +#define CONTEXT_STACK_OFFSET(x)  (sizeof(UINTN) == sizeof (UINT32) ?
> +(UINTN)&((CONTEXT_STACK *)(UINTN)0)->x :
> (UINTN)&((CONTEXT_STACK_64
> +*)(UINTN)0)->x)
> 
>  #pragma pack()
> 
> @@ -85,7 +98,7 @@ GetFspGlobalDataPointer (
> 
>    @retval ApiParameter FSP API first parameter passed by the bootloader.
>  **/
> -UINT32
> +UINTN
>  EFIAPI
>  GetFspApiParameter (
>    VOID
> @@ -94,7 +107,7 @@ GetFspApiParameter (
>    FSP_GLOBAL_DATA  *FspData;
> 
>    FspData = GetFspGlobalDataPointer ();
> -  return *(UINT32 *)(UINTN)(FspData->CoreStack +
> CONTEXT_STACK_OFFSET (ApiParam[0]));
> +  return *(UINTN *)(FspData->CoreStack + CONTEXT_STACK_OFFSET
> + (ApiParam[0]));
>  }
> 
>  /**
> @@ -119,7 +132,7 @@ GetFspEntryStack (
> 
>    @retval ApiParameter FSP API second parameter passed by the
> bootloader.
>  **/
> -UINT32
> +UINTN
>  EFIAPI
>  GetFspApiParameter2 (
>    VOID
> @@ -128,7 +141,7 @@ GetFspApiParameter2 (
>    FSP_GLOBAL_DATA  *FspData;
> 
>    FspData = GetFspGlobalDataPointer ();
> -  return *(UINT32 *)(UINTN)(FspData->CoreStack +
> CONTEXT_STACK_OFFSET (ApiParam[1]));
> +  return *(UINTN *)(FspData->CoreStack + CONTEXT_STACK_OFFSET
> + (ApiParam[1]));
>  }
> 
>  /**
> @@ -145,8 +158,8 @@ SetFspApiParameter (  {
>    FSP_GLOBAL_DATA  *FspData;
> 
> -  FspData                                                                  = GetFspGlobalDataPointer
> ();
> -  *(UINT32 *)(UINTN)(FspData->CoreStack + CONTEXT_STACK_OFFSET
> (ApiParam)) = Value;
> +  FspData                                                          = GetFspGlobalDataPointer ();
> +  *(UINTN *)(FspData->CoreStack + CONTEXT_STACK_OFFSET (ApiParam))
> =
> + Value;
>  }
> 
>  /**
> @@ -158,13 +171,13 @@ SetFspApiParameter (  VOID  EFIAPI
> SetFspApiReturnStatus (
> -  IN UINT32  ReturnStatus
> +  IN UINTN  ReturnStatus
>    )
>  {
>    FSP_GLOBAL_DATA  *FspData;
> 
> -  FspData                                                             = GetFspGlobalDataPointer ();
> -  *(UINT32 *)(UINTN)(FspData->CoreStack + CONTEXT_STACK_OFFSET (Eax))
> = ReturnStatus;
> +  FspData                                                              = GetFspGlobalDataPointer ();
> +  *(UINTN *)(FspData->CoreStack + CONTEXT_STACK_OFFSET (Registers[7]))
> + = ReturnStatus;
>  }
> 
>  /**
> @@ -180,19 +193,19 @@ SetFspCoreStackPointer (
>    )
>  {
>    FSP_GLOBAL_DATA  *FspData;
> -  UINT32           *OldStack;
> -  UINT32           *NewStack;
> +  UINTN            *OldStack;
> +  UINTN            *NewStack;
>    UINT32           StackContextLen;
> 
>    FspData         = GetFspGlobalDataPointer ();
> -  StackContextLen = sizeof (CONTEXT_STACK) / sizeof (UINT32);
> +  StackContextLen = sizeof(CONTEXT_STACK) / sizeof(UINTN);
> 
>    //
>    // Reserve space for the ContinuationFunc two parameters
>    //
> -  OldStack           = (UINT32 *)FspData->CoreStack;
> -  NewStack           = (UINT32 *)NewStackTop - StackContextLen - 2;
> -  FspData->CoreStack = (UINT32)NewStack;
> +  OldStack = (UINTN *)FspData->CoreStack;  NewStack = (UINTN
> + *)NewStackTop - StackContextLen - 2;  FspData->CoreStack =
> + (UINTN)NewStack;
>    while (StackContextLen-- != 0) {
>      *NewStack++ = *OldStack++;
>    }
> @@ -427,7 +440,7 @@ GetFspInfoHeaderFromApiContext (
>    FSP_GLOBAL_DATA  *FspData;
> 
>    FspData = GetFspGlobalDataPointer ();
> -  return (FSP_INFO_HEADER *)(*(UINT32 *)(UINTN)(FspData->CoreStack +
> CONTEXT_STACK_OFFSET (FspInfoHeader)));
> +  return (FSP_INFO_HEADER *)(*(UINTN *)(FspData->CoreStack +
> + CONTEXT_STACK_OFFSET (FspInfoHeader)));
>  }
> 
>  /**
> @@ -444,7 +457,7 @@ GetFspCfgRegionDataPointer (
>    FSP_INFO_HEADER  *FspInfoHeader;
> 
>    FspInfoHeader = GetFspInfoHeader ();
> -  return (VOID *)(FspInfoHeader->ImageBase + FspInfoHeader-
> >CfgRegionOffset);
> +  return (VOID *)(UINTN)(FspInfoHeader->ImageBase +
> + FspInfoHeader->CfgRegionOffset);
>  }
> 
>  /**
> --
> 2.16.2.windows.1


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

end of thread, other threads:[~2022-03-22  8:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-03-14  4:22 [edk2-devel][PATCH] IntelFsp2Pkg: BaseFspCommonLib Support for X64 Kuo, Ted
2022-03-22  7:43 ` Chiu, Chasel
2022-03-22  8:18 ` Chiu, Chasel

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