audk/IntelFsp2Pkg/Library
Ni, Ray 0b4acb88d6 IntelFsp2Pkg/SwitchStack: Reserve 32B when calling C function in 64bit
When FSP runs in API mode, it saves the IDTR in its own stack then
switches to bootloader's stack before it returns from FspMemoryInit.
Next time when the bootloader calls TempRamExit, FSP switches to
its own stack and restores IDTR from its stack saved earlier.

However, due to a bug in BaseFspSwitchStackLib, the IDTR saved on
FSP's stack might be corrupted that results the following TempRamExit
call fails inside FSP due to PeiServices pointer cannot be retrieved
from IDT.base - 8.

The bug is the assembly code doesn't reserve 32 bytes before calling
the C routine in 64bit. According to the x86-64 calling convention,
caller is responsible for allocating 32 bytes of "shadow space" on the
stack right before calling the function (regardless of the actual
number of parameters used).

When FSP is built in optimization-off mode, the C routine makes use
of the 32-byte "shadow space" which is not reserved by the assembly
caller. That causes the IDTR saved on the stack is corrupted by the
C routine.
The patch fixes so by reserving the 32 bytes before calling C routine.

Signed-off-by: Ray Ni <ray.ni@intel.com>
Cc: Chasel Chiu <chasel.chiu@intel.com>
Reviewed-by: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Duggapu Chinni B <chinni.b.duggapu@intel.com>
Cc: Ray Han Lim Ng <ray.han.lim.ng@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Reviewed-by: Ted Kuo <ted.kuo@intel.com>
Reviewed-by: Ashraf Ali S <ashraf.ali.s@intel.com>
Cc: Susovan Mohapatra <susovan.mohapatra@intel.com>
2023-11-03 19:41:25 +00:00
..
BaseCacheAsRamLibNull IntelFsp2Pkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
BaseCacheLib IntelFsp2Pkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
BaseDebugDeviceLibNull IntelFsp2Pkg: Replace BSD License with BSD+Patent License 2019-04-09 10:58:03 -07:00
BaseFspCommonLib IntelFsp2Pkg: Add get and set FspSmmInit upd data pointer functions 2023-08-28 21:25:11 +00:00
BaseFspDebugLibSerialPort IntelFsp2Pkg: Fix code formatting errors 2022-10-04 16:53:59 +00:00
BaseFspMultiPhaseLib IntelFsp2Pkg/BaseFspMultiPhaseLib: Replace duplicate GUID 2022-10-04 16:53:59 +00:00
BaseFspPlatformLib IntelFsp2Pkg: Fix GCC Compiler warning. 2023-03-10 02:04:51 +00:00
BaseFspSwitchStackLib IntelFsp2Pkg/SwitchStack: Reserve 32B when calling C function in 64bit 2023-11-03 19:41:25 +00:00
SecFspSecPlatformLibNull IntelFsp2Pkg: Add FSP 2.4 MultiPhase interface. 2022-08-31 16:48:07 +00:00