]> git.proxmox.com Git - mirror_edk2.git/blobdiff - UefiCpuPkg/CpuDxe/CpuGdt.c
UefiCpuPkg/CpuDxe: Guarantee GDT is below 4GB
[mirror_edk2.git] / UefiCpuPkg / CpuDxe / CpuGdt.c
index 8847bc4819ca0f31cee9be69fbfc3203cbdd5e1c..692402c55df4aaa77bebfde7a422989ff8936fec 100644 (file)
@@ -124,15 +124,26 @@ InitGlobalDescriptorTable (
   VOID\r
   )\r
 {\r
+  EFI_STATUS            Status;\r
   GDT_ENTRIES           *Gdt;\r
   IA32_DESCRIPTOR       Gdtr;\r
+  EFI_PHYSICAL_ADDRESS  Memory;\r
 \r
   //\r
-  // Allocate Runtime Data for the GDT\r
-  //\r
-  Gdt = AllocateRuntimePool (sizeof (mGdtTemplate) + 8);\r
-  ASSERT (Gdt != NULL);\r
-  Gdt = ALIGN_POINTER (Gdt, 8);\r
+  // Allocate Runtime Data below 4GB for the GDT\r
+  // AP uses the same GDT when it's waken up from real mode so\r
+  // the GDT needs to be below 4GB.\r
+  //\r
+  Memory = SIZE_4GB - 1;\r
+  Status = gBS->AllocatePages (\r
+                  AllocateMaxAddress,\r
+                  EfiRuntimeServicesData,\r
+                  EFI_SIZE_TO_PAGES (sizeof (mGdtTemplate)),\r
+                  &Memory\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+  ASSERT ((Memory != 0) && (Memory < SIZE_4GB));\r
+  Gdt = (GDT_ENTRIES *) (UINTN) Memory;\r
 \r
   //\r
   // Initialize all GDT entries\r