OvmfPkg/Csm/LegacyBiosDxe: Fix Legacy16GetTableAddress call for E820 data master
authorDavid Woodhouse <dwmw2@infradead.org>
Thu, 13 Jun 2019 08:40:05 +0000 (16:40 +0800)
committerHao A Wu <hao.a.wu@intel.com>
Fri, 14 Jun 2019 05:05:49 +0000 (13:05 +0800)
The DX register is supposed to contain the required alignment for the
allocation. It was zero, and SeaBIOS doesn't (well, didn't) cope well
with that. Set it appropriately.

Also set BX to indicate the regions it's OK to allocate in too. That
wasn't being initialised and was just using whatever the previous user
of the structure had left there.

Finally, actually return an error if the allocation fails. Instead of
going all the way through into the CSM and just letting it have a bogus
pointer to the E820 data.

Signed-off-by: David Woodhouse <dwmw2@infradead.org>
Reviewed-by: Hao A Wu <hao.a.wu@intel.com>
Acked-by: Laszlo Ersek <lersek@redhat.com>
OvmfPkg/Csm/LegacyBiosDxe/LegacyBootSupport.c

index 211750c..cd4cd24 100644 (file)
@@ -928,7 +928,9 @@ GenericLegacyBoot (
   if (CopySize > Private->Legacy16Table->E820Length) {\r
     ZeroMem (&Regs, sizeof (EFI_IA32_REGISTER_SET));\r
     Regs.X.AX = Legacy16GetTableAddress;\r
+    Regs.X.BX = (UINT16) 0x0; // Any region\r
     Regs.X.CX = (UINT16) CopySize;\r
+    Regs.X.DX = (UINT16) 0x4; // Alignment\r
     Private->LegacyBios.FarCall86 (\r
       &Private->LegacyBios,\r
       Private->Legacy16Table->Compatibility16CallSegment,\r
@@ -942,6 +944,7 @@ GenericLegacyBoot (
     Private->Legacy16Table->E820Length  = (UINT32) CopySize;\r
     if (Regs.X.AX != 0) {\r
       DEBUG ((EFI_D_ERROR, "Legacy16 E820 length insufficient\n"));\r
+      return EFI_OUT_OF_RESOURCES;\r
     } else {\r
       CopyMem (\r
         (VOID *)(UINTN) Private->Legacy16Table->E820Pointer,\r