summaryrefslogtreecommitdiffstats
path: root/IntelFsp2Pkg
diff options
context:
space:
mode:
authorKuo, Ted <ted.kuo@intel.com>2022-03-14 12:22:38 +0800
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2022-03-22 07:56:09 +0000
commitec0b54849b23efa25caf0055b0eef8bf9b4dec98 (patch)
treed9972d9671d3aedda9e9c7901eed20df2e0fde8c /IntelFsp2Pkg
parent267a92fef3b705e6a3ecbeaa4d4b58f7bfac9734 (diff)
downloadedk2-ec0b54849b23efa25caf0055b0eef8bf9b4dec98.tar.gz
edk2-ec0b54849b23efa25caf0055b0eef8bf9b4dec98.tar.bz2
edk2-ec0b54849b23efa25caf0055b0eef8bf9b4dec98.zip
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> Reviewed-by: Chasel Chiu <chasel.chiu@intel.com>
Diffstat (limited to 'IntelFsp2Pkg')
-rw-r--r--IntelFsp2Pkg/FspSecCore/SecFsp.c2
-rw-r--r--IntelFsp2Pkg/FspSecCore/SecFsp.h2
-rw-r--r--IntelFsp2Pkg/Include/FspGlobalData.h2
-rw-r--r--IntelFsp2Pkg/Include/Library/FspCommonLib.h6
-rw-r--r--IntelFsp2Pkg/Library/BaseFspCommonLib/FspCommonLib.c65
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);
}
/**