Index: /trunk/src/VBox/Devices/EFI/DevEFI.cpp
===================================================================
--- /trunk/src/VBox/Devices/EFI/DevEFI.cpp	(revision 67917)
+++ /trunk/src/VBox/Devices/EFI/DevEFI.cpp	(revision 67918)
@@ -222,10 +222,10 @@
     /** Virtual machine CPU frequency. */
     uint64_t                u64CpuFrequency;
-    /** GOP mode. */
-    uint32_t                u32GopMode;
-    /** Uga mode horizontal resolution. */
-    uint32_t                cxUgaResolution;
-    /** Uga mode vertical resolution. */
-    uint32_t                cyUgaResolution;
+    /** EFI Graphics mode (used as fallback if resolution is not known). */
+    uint32_t                u32GraphicsMode;
+    /** EFI Graphics (GOP or UGA) horizontal resolution. */
+    uint32_t                u32HorizontalResolution;
+    /** EFI Graphics (GOP or UGA) vertical resolution. */
+    uint32_t                u32VerticalResolution;
     /** Physical address of PCI config space MMIO region */
     uint64_t                u64McfgBase;
@@ -1105,7 +1105,7 @@
         case EFI_INFO_INDEX_STACK_BASE:
         case EFI_INFO_INDEX_STACK_SIZE:
-        case EFI_INFO_INDEX_GOP_MODE:
-        case EFI_INFO_INDEX_UGA_VERTICAL_RESOLUTION:
-        case EFI_INFO_INDEX_UGA_HORIZONTAL_RESOLUTION:
+        case EFI_INFO_INDEX_GRAPHICS_MODE:
+        case EFI_INFO_INDEX_VERTICAL_RESOLUTION:
+        case EFI_INFO_INDEX_HORIZONTAL_RESOLUTION:
             return 4;
         case EFI_INFO_INDEX_BOOT_ARGS:
@@ -1190,7 +1190,7 @@
         case EFI_INFO_INDEX_BOOT_ARGS:          return efiInfoNextByteBuf(pThis, pThis->szBootArgs, sizeof(pThis->szBootArgs));
         case EFI_INFO_INDEX_DEVICE_PROPS:       return efiInfoNextByteBuf(pThis, pThis->pbDeviceProps, pThis->cbDeviceProps);
-        case EFI_INFO_INDEX_GOP_MODE:           return efiInfoNextByteU32(pThis, pThis->u32GopMode);
-        case EFI_INFO_INDEX_UGA_HORIZONTAL_RESOLUTION:  return efiInfoNextByteU32(pThis, pThis->cxUgaResolution);
-        case EFI_INFO_INDEX_UGA_VERTICAL_RESOLUTION:    return efiInfoNextByteU32(pThis, pThis->cyUgaResolution);
+        case EFI_INFO_INDEX_GRAPHICS_MODE:      return efiInfoNextByteU32(pThis, pThis->u32GraphicsMode);
+        case EFI_INFO_INDEX_HORIZONTAL_RESOLUTION:  return efiInfoNextByteU32(pThis, pThis->u32HorizontalResolution);
+        case EFI_INFO_INDEX_VERTICAL_RESOLUTION:    return efiInfoNextByteU32(pThis, pThis->u32VerticalResolution);
 
         /* Keep in sync with value in EfiThunk.asm */
@@ -1467,5 +1467,5 @@
                 pThis->szMsg[pThis->iMsg] = '\0';
                 if (pThis->iMsg)
-                    Log(("efi: %s\n", pThis->szMsg));
+                    LogRel(("efi: %s\n", pThis->szMsg));
                 pThis->iMsg = 0;
             }
@@ -1475,5 +1475,5 @@
                 {
                     pThis->szMsg[pThis->iMsg] = '\0';
-                    Log(("efi: %s\n", pThis->szMsg));
+                    LogRel(("efi: %s\n", pThis->szMsg));
                     pThis->iMsg = 0;
                 }
@@ -2189,7 +2189,10 @@
                               "BootArgs\0"
                               "DeviceProps\0"
-                              "GopMode\0"
-                              "UgaHorizontalResolution\0"
-                              "UgaVerticalResolution\0"))
+                              "GopMode\0"                   // legacy
+                              "GraphicsMode\0"
+                              "UgaHorizontalResolution\0"   // legacy
+                              "UgaVerticalResolution\0"     // legacy
+                              "HorizontalResolution\0"
+                              "VerticalResolution\0"))
         return PDMDEV_SET_ERROR(pDevIns, VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES,
                                 N_("Configuration error: Invalid config value(s) for the EFI device"));
@@ -2319,24 +2322,42 @@
 
     /*
-     * GOP graphics.
-     */
-    rc = CFGMR3QueryU32Def(pCfg, "GopMode", &pThis->u32GopMode, 2 /* 1024x768 */);
+     * EFI graphics mode (with new EFI VGA code used only as a fallback, for
+     * old EFI VGA code the only way to select the GOP mode).
+     */
+    rc = CFGMR3QueryU32Def(pCfg, "GraphicsMode", &pThis->u32GraphicsMode, UINT32_MAX);
     if (RT_FAILURE(rc))
         return PDMDevHlpVMSetError(pDevIns, rc, RT_SRC_POS,
-                                   N_("Configuration error: Querying \"GopMode\" as a 32-bit int failed"));
-    if (pThis->u32GopMode == UINT32_MAX)
-        pThis->u32GopMode = 2; /* 1024x768 */
-
-    /*
-     * Uga graphics, default to 1024x768.
-     */
-    rc = CFGMR3QueryU32Def(pCfg, "UgaHorizontalResolution", &pThis->cxUgaResolution, 0);
+                                   N_("Configuration error: Querying \"GraphicsMode\" as a 32-bit int failed"));
+    if (pThis->u32GraphicsMode == UINT32_MAX)
+    {
+        /* get the legacy value if nothing else was specified */
+        rc = CFGMR3QueryU32Def(pCfg, "GopMode", &pThis->u32GraphicsMode, UINT32_MAX);
+        if (RT_FAILURE(rc))
+            return PDMDevHlpVMSetError(pDevIns, rc, RT_SRC_POS,
+                                       N_("Configuration error: Querying \"GopMode\" as a 32-bit int failed"));
+    }
+    if (pThis->u32GraphicsMode == UINT32_MAX)
+        pThis->u32GraphicsMode = 2; /* 1024x768 */
+
+    /*
+     * EFI graphics resolution, defaults to 1024x768 (used to be UGA only, now
+     * is the main config setting as the mode number is so hard to predict).
+     */
+    rc = CFGMR3QueryU32Def(pCfg, "HorizontalResolution", &pThis->u32HorizontalResolution, 0);
     AssertRCReturn(rc, rc);
-    rc = CFGMR3QueryU32Def(pCfg, "UgaVerticalResolution", &pThis->cyUgaResolution, 0);
+    rc = CFGMR3QueryU32Def(pCfg, "VerticalResolution", &pThis->u32VerticalResolution, 0);
     AssertRCReturn(rc, rc);
-    if (pThis->cxUgaResolution == 0 || pThis->cyUgaResolution == 0)
-    {
-        pThis->cxUgaResolution = 1024;
-        pThis->cyUgaResolution = 768;
+    if (pThis->u32HorizontalResolution == 0 || pThis->u32VerticalResolution == 0)
+    {
+        /* get the legacy values if nothing else was specified */
+        rc = CFGMR3QueryU32Def(pCfg, "UgaHorizontalResolution", &pThis->u32HorizontalResolution, 0);
+        AssertRCReturn(rc, rc);
+        rc = CFGMR3QueryU32Def(pCfg, "UgaVerticalResolution", &pThis->u32VerticalResolution, 0);
+        AssertRCReturn(rc, rc);
+    }
+    if (pThis->u32HorizontalResolution == 0 || pThis->u32VerticalResolution == 0)
+    {
+        pThis->u32HorizontalResolution = 1024;
+        pThis->u32VerticalResolution = 768;
     }
 
Index: /trunk/src/VBox/Devices/EFI/DevEFI.h
===================================================================
--- /trunk/src/VBox/Devices/EFI/DevEFI.h	(revision 67917)
+++ /trunk/src/VBox/Devices/EFI/DevEFI.h	(revision 67918)
@@ -66,7 +66,7 @@
     EFI_INFO_INDEX_CPU_FREQUENCY,
     EFI_INFO_INDEX_TSC_FREQUENCY,
-    EFI_INFO_INDEX_GOP_MODE,
-    EFI_INFO_INDEX_UGA_HORIZONTAL_RESOLUTION,
-    EFI_INFO_INDEX_UGA_VERTICAL_RESOLUTION,
+    EFI_INFO_INDEX_GRAPHICS_MODE,
+    EFI_INFO_INDEX_HORIZONTAL_RESOLUTION,
+    EFI_INFO_INDEX_VERTICAL_RESOLUTION,
     EFI_INFO_INDEX_MCFG_BASE,
     EFI_INFO_INDEX_MCFG_SIZE,
Index: /trunk/src/VBox/Devices/EFI/Firmware/VBoxPkg/VBoxVgaDxe/VBoxVgaGraphicsOutput.c
===================================================================
--- /trunk/src/VBox/Devices/EFI/Firmware/VBoxPkg/VBoxVgaDxe/VBoxVgaGraphicsOutput.c	(revision 67917)
+++ /trunk/src/VBox/Devices/EFI/Firmware/VBoxPkg/VBoxVgaDxe/VBoxVgaGraphicsOutput.c	(revision 67918)
@@ -426,7 +426,12 @@
   )
 {
-  EFI_STATUS                   Status;
-  EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
-  UINT32                        GopMode = 2;
+  EFI_STATUS                    Status;
+  EFI_GRAPHICS_OUTPUT_PROTOCOL  *GraphicsOutput;
+  UINT32                        Index;
+  UINT32                        HorizontalResolution = 1024;
+  UINT32                        VerticalResolution = 768;
+  UINT32                        ColorDepth = 32;
+
+  DEBUG((DEBUG_INFO, "%a:%d construct\n", __FILE__, __LINE__));
 
   GraphicsOutput            = &Private->GraphicsOutput;
@@ -461,7 +466,32 @@
   // Initialize the hardware
   //
-  VBoxVgaGetVmVariable(EFI_INFO_INDEX_GOP_MODE, (CHAR8 *)&GopMode, sizeof(GopMode));
-
-  GraphicsOutput->SetMode (GraphicsOutput, GopMode);
+  VBoxVgaGetVmVariable(EFI_INFO_INDEX_HORIZONTAL_RESOLUTION, (CHAR8 *)&HorizontalResolution,
+                       sizeof(HorizontalResolution));
+  VBoxVgaGetVmVariable(EFI_INFO_INDEX_VERTICAL_RESOLUTION, (CHAR8 *)&VerticalResolution,
+                       sizeof(VerticalResolution));
+  for (Index = 0; Index < Private->MaxMode; Index++)
+  {
+    if (   HorizontalResolution == Private->ModeData[Index].HorizontalResolution
+        && VerticalResolution == Private->ModeData[Index].VerticalResolution
+        && ColorDepth == Private->ModeData[Index].ColorDepth)
+      break;
+  }
+  // not found? try mode number
+  if (Index >= Private->MaxMode)
+  {
+    VBoxVgaGetVmVariable(EFI_INFO_INDEX_GRAPHICS_MODE, (CHAR8 *)&Index, sizeof(Index));
+    // try with mode 2 (usually 1024x768) as a fallback
+    if (Index >= Private->MaxMode)
+      Index = 2;
+    // try with mode 0 (usually 640x480) as a fallback
+    if (Index >= Private->MaxMode)
+      Index = 0;
+  }
+
+  // skip mode setting completely if there is no valid mode
+  if (Index >= Private->MaxMode)
+    return EFI_UNSUPPORTED;
+
+  GraphicsOutput->SetMode (GraphicsOutput, Index);
 
   DrawLogo (
Index: /trunk/src/VBox/Devices/EFI/Firmware/VBoxPkg/VBoxVgaDxe/VBoxVgaUgaDraw.c
===================================================================
--- /trunk/src/VBox/Devices/EFI/Firmware/VBoxPkg/VBoxVgaDxe/VBoxVgaUgaDraw.c	(revision 67917)
+++ /trunk/src/VBox/Devices/EFI/Firmware/VBoxPkg/VBoxVgaDxe/VBoxVgaUgaDraw.c	(revision 67918)
@@ -90,6 +90,6 @@
   )
 {
-  VBOX_VGA_PRIVATE_DATA  *Private;
-  UINTN                           Index;
+  VBOX_VGA_PRIVATE_DATA *Private;
+  UINTN                 Index;
 
   DEBUG((DEBUG_INFO, "%a:%d VIDEO: %dx%d %d bpp\n", __FILE__, __LINE__, HorizontalResolution, VerticalResolution, ColorDepth));
@@ -328,6 +328,8 @@
 {
   EFI_UGA_DRAW_PROTOCOL *UgaDraw;
+  UINT32                Index;
   UINT32                HorizontalResolution = 1024;
   UINT32                VerticalResolution = 768;
+  UINT32                ColorDepth = 32;
 
   //
@@ -349,8 +351,38 @@
   // Initialize the hardware
   //
-  VBoxVgaGetVmVariable(EFI_INFO_INDEX_UGA_HORIZONTAL_RESOLUTION, (CHAR8 *)&HorizontalResolution,
+  VBoxVgaGetVmVariable(EFI_INFO_INDEX_HORIZONTAL_RESOLUTION, (CHAR8 *)&HorizontalResolution,
                        sizeof(HorizontalResolution));
-  VBoxVgaGetVmVariable(EFI_INFO_INDEX_UGA_VERTICAL_RESOLUTION, (CHAR8 *)&VerticalResolution,
+  VBoxVgaGetVmVariable(EFI_INFO_INDEX_VERTICAL_RESOLUTION, (CHAR8 *)&VerticalResolution,
                        sizeof(VerticalResolution));
+  for (Index = 0; Index < Private->MaxMode; Index++)
+  {
+    if (   HorizontalResolution == Private->ModeData[Index].HorizontalResolution
+        && VerticalResolution == Private->ModeData[Index].VerticalResolution
+        && ColorDepth == Private->ModeData[Index].ColorDepth)
+      break;
+  }
+  // not found? try mode number
+  if (Index >= Private->MaxMode)
+  {
+    VBoxVgaGetVmVariable(EFI_INFO_INDEX_GRAPHICS_MODE, (CHAR8 *)&Index, sizeof(Index));
+    // try with mode 2 (usually 1024x768) as a fallback
+    if (Index >= Private->MaxMode)
+      Index = 2;
+    // try with mode 0 (usually 640x480) as a fallback
+    if (Index >= Private->MaxMode)
+      Index = 0;
+
+    // get the resolution from the mode if valid
+    if (Index < Private->MaxMode)
+    {
+      HorizontalResolution = Private->ModeData[Index].HorizontalResolution;
+      VerticalResolution = Private->ModeData[Index].VerticalResolution;
+      ColorDepth = Private->ModeData[Index].ColorDepth;
+    }
+  }
+
+  // skip mode setting completely if there is no valid mode
+  if (Index >= Private->MaxMode)
+    return EFI_UNSUPPORTED;
 
   UgaDraw->SetMode (
@@ -358,5 +390,5 @@
             HorizontalResolution,
             VerticalResolution,
-            32,
+            ColorDepth,
             60
             );
Index: /trunk/src/VBox/Main/src-client/ConsoleImpl2.cpp
===================================================================
--- /trunk/src/VBox/Main/src-client/ConsoleImpl2.cpp	(revision 67917)
+++ /trunk/src/VBox/Main/src-client/ConsoleImpl2.cpp	(revision 67918)
@@ -1778,20 +1778,26 @@
             GetExtraDataBoth(virtualBox, pMachine, "VBoxInternal2/EfiDeviceProps", &deviceProps);
 
-            /* Get GOP mode settings */
-            uint32_t u32GopMode = UINT32_MAX;
-            GetExtraDataBoth(virtualBox, pMachine, "VBoxInternal2/EfiGopMode", &strTmp);
+            /* Get graphics mode settings */
+            uint32_t u32GraphicsMode = UINT32_MAX;
+            GetExtraDataBoth(virtualBox, pMachine, "VBoxInternal2/EfiGraphicsMode", &strTmp);
+            if (strTmp.isEmpty())
+                GetExtraDataBoth(virtualBox, pMachine, "VBoxInternal2/EfiGopMode", &strTmp);
             if (!strTmp.isEmpty())
-                u32GopMode = strTmp.toUInt32();
-
-            /* UGA mode settings */
-            uint32_t u32UgaHorizontal = 0;
-            GetExtraDataBoth(virtualBox, pMachine, "VBoxInternal2/EfiUgaHorizontalResolution", &strTmp);
+                u32GraphicsMode = strTmp.toUInt32();
+
+            /* Get graphics resolution settings */
+            uint32_t u32HorizontalResolution = 0;
+            GetExtraDataBoth(virtualBox, pMachine, "VBoxInternal2/EfiHorizontalResolution", &strTmp);
+            if (strTmp.isEmpty())
+                GetExtraDataBoth(virtualBox, pMachine, "VBoxInternal2/EfiUgaHorizontalResolution", &strTmp);
             if (!strTmp.isEmpty())
-                u32UgaHorizontal = strTmp.toUInt32();
-
-            uint32_t u32UgaVertical = 0;
-            GetExtraDataBoth(virtualBox, pMachine, "VBoxInternal2/EfiUgaVerticalResolution", &strTmp);
+                u32HorizontalResolution = strTmp.toUInt32();
+
+            uint32_t u32VerticalResolution = 0;
+            GetExtraDataBoth(virtualBox, pMachine, "VBoxInternal2/EfiVerticalResolution", &strTmp);
+            if (strTmp.isEmpty())
+                GetExtraDataBoth(virtualBox, pMachine, "VBoxInternal2/EfiUgaVerticalResolution", &strTmp);
             if (!strTmp.isEmpty())
-                u32UgaVertical = strTmp.toUInt32();
+                u32VerticalResolution = strTmp.toUInt32();
 
             /*
@@ -1812,7 +1818,7 @@
             InsertConfigBytes(pCfg,    "UUID", &HardwareUuid,sizeof(HardwareUuid));
             InsertConfigInteger(pCfg,  "64BitEntry",  f64BitEntry); /* boolean */
-            InsertConfigInteger(pCfg,  "GopMode",     u32GopMode);
-            InsertConfigInteger(pCfg,  "UgaHorizontalResolution", u32UgaHorizontal);
-            InsertConfigInteger(pCfg,  "UgaVerticalResolution", u32UgaVertical);
+            InsertConfigInteger(pCfg,  "GraphicsMode",  u32GraphicsMode);
+            InsertConfigInteger(pCfg,  "HorizontalResolution", u32HorizontalResolution);
+            InsertConfigInteger(pCfg,  "VerticalResolution", u32VerticalResolution);
 
             /* For OS X guests we'll force passing host's DMI info to the guest */
