audk/UefiCpuPkg
Laszlo Ersek f98f5ec304 UefiCpuPkg: S3Resume2Pei: align return stacks explicitly
S3RestoreConfig2() can optionally stack-switch to the SMM S3 Resume Entry
Point and ask it to transfer to S3ResumeExecuteBootScript().

Similarly, S3ResumeExecuteBootScript() stack-switches explicitly to the
boot script executor, and asks it to transfer to S3ResumeBootOs().

Currently the stack pointers specified for the SMM S3 Resume Entry Point
and the boot script executor to use for returning are derived from
addresses of the first local variables in S3RestoreConfig2() and
S3ResumeExecuteBootScript(), respectively.

Since (theoretically) the stack grows down as local variables are defined
and functions are called, the idea is presumably to allow the respective
callee to overwrite the caller's local variables. (The callees in
question can never return normally, only by explicit stack switching.)

Taking the address of "Status" is less portable than optimal however.
Compilers are free to juggle local variables at build time as they
please, including order and alignment on the stack. For example, when the
code is built for 64-bit PEI with gcc-4.8.2, the address of "Status"
trips up the alignment assertion in SwitchStack().

Let's align the address of "Status" down to CPU_STACK_ALIGNMENT
explicitly. If a compiler ensures such alignment and places "Status" at
the highest address automatically, then this change has no effect.
Otherwise, we'll prepare ReturnStackPointer values that (a) are correctly
aligned, (b) preserve the same amount or more (but never less) from the
caller's local variables than before, which should be safe.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed by: Jiewen Yao <Jiewen.Yao@intel.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14977 6f19259b-4bc3-4df7-8a09-765794883524
2013-12-13 03:22:33 +00:00
..
CpuDxe 1. Separated DxeSmmCpuExceptionHandlerLib.inf into 2 instance DxeCpuExceptionHandlerLib.inf and SmmCpuExceptionHandlerLib.inf. 2013-11-22 06:24:41 +00:00
CpuIo2Dxe Fix comparisons of enumerated types which may cause warnings for some compilers. 2012-08-28 06:48:28 +00:00
CpuIo2Smm Fix comparisons of enumerated types which may cause warnings for some compilers. 2012-08-28 06:48:28 +00:00
CpuIoPei Fix comparisons of enumerated types which may cause warnings for some compilers. 2012-08-28 06:48:28 +00:00
Include 1. Read 32bit CPU Init APIC ID from CPUID leaf B in XAPIC mode. 2013-09-16 08:42:59 +00:00
Library Correct INF file to make module pass ICC compiler. 2013-12-11 08:22:43 +00:00
ResetVector/Vtf0 UefiCpuPkg/ResetVector/Vtf0: Move Page Table/CR3 setting to a new file 2013-09-24 18:23:09 +00:00
Universal/Acpi/S3Resume2Pei UefiCpuPkg: S3Resume2Pei: align return stacks explicitly 2013-12-13 03:22:33 +00:00
Contributions.txt EDK II Packages: Add Contributions.txt and License.txt files 2012-04-11 23:19:46 +00:00
License.txt Update copyright format 2012-04-24 06:49:39 +00:00
UefiCpuPkg.dec Update package version for MdeModulePkg, UefiCpuPkg. 2011-12-14 01:42:15 +00:00
UefiCpuPkg.dsc 1. Separated DxeSmmCpuExceptionHandlerLib.inf into 2 instance DxeCpuExceptionHandlerLib.inf and SmmCpuExceptionHandlerLib.inf. 2013-11-22 06:24:41 +00:00