]> git.proxmox.com Git - mirror_edk2.git/commitdiff
UefiCpuPkg/CpuExceptionHandlerLib: Code optimization to allow bigger stack
authorTan, Dun <dun.tan@intel.com>
Thu, 29 Sep 2022 09:06:51 +0000 (17:06 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Sat, 8 Oct 2022 05:45:22 +0000 (05:45 +0000)
This commit is a code optimization to allow bigger seperate stack size in
ArchSetupExceptionStack. In previous code logic, CPU_STACK_ALIGNMENT bytes
will be wasted if StackTop is already CPU_STACK_ALIGNMENT aligned.

Signed-off-by: Dun Tan <dun.tan@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Reviewed-by: Abner Chang <abner.chang@amd.com>
UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ArchExceptionHandler.c
UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchExceptionHandler.c

index 8c398ebc5b8ad917bd041bc0dc48966c0b466da1..c30ece1dc92becafba6ca5e8f63a48271707b230 100644 (file)
@@ -215,7 +215,10 @@ ArchSetupExceptionStack (
   // Fixup exception task descriptor and task-state segment\r
   //\r
   AsmGetTssTemplateMap (&TemplateMap);\r
-  StackTop = StackTop - CPU_STACK_ALIGNMENT;\r
+  //\r
+  // Plus 1 byte is for compact stack layout in case StackTop is already aligned.\r
+  //\r
+  StackTop = StackTop - CPU_STACK_ALIGNMENT + 1;\r
   StackTop = (UINTN)ALIGN_POINTER (StackTop, CPU_STACK_ALIGNMENT);\r
   IdtTable = (IA32_IDT_GATE_DESCRIPTOR  *)Idtr.Base;\r
   for (Index = 0; Index < CPU_STACK_SWITCH_EXCEPTION_NUMBER; ++Index) {\r
index 80e9f08e5ba0ba436f5ffac9e4eed60cb958734b..4e85880ed4e3532543458bcd31ebfdf5413a0bc1 100644 (file)
@@ -223,7 +223,10 @@ ArchSetupExceptionStack (
   // Fixup exception task descriptor and task-state segment\r
   //\r
   ZeroMem (Tss, sizeof (*Tss));\r
-  StackTop = StackTop - CPU_STACK_ALIGNMENT;\r
+  //\r
+  // Plus 1 byte is for compact stack layout in case StackTop is already aligned.\r
+  //\r
+  StackTop = StackTop - CPU_STACK_ALIGNMENT + 1;\r
   StackTop = (UINTN)ALIGN_POINTER (StackTop, CPU_STACK_ALIGNMENT);\r
   IdtTable = (IA32_IDT_GATE_DESCRIPTOR  *)Idtr.Base;\r
   for (Index = 0; Index < CPU_STACK_SWITCH_EXCEPTION_NUMBER; ++Index) {\r