Index: /trunk/src/VBox/Additions/x11/vboxvideo/undefined
===================================================================
--- /trunk/src/VBox/Additions/x11/vboxvideo/undefined	(revision 35948)
+++ /trunk/src/VBox/Additions/x11/vboxvideo/undefined	(revision 35949)
@@ -16,8 +16,4 @@
 RRChangeOutputProperty
 ShadowFBInit2
-VBEExtendedInit
-VBEGetVBEMode
-VBESaveRestore
-VBESetVBEMode
 XNFcalloc
 XNFstrdup
@@ -127,6 +123,8 @@
 vgaHWFreeHWRec
 vgaHWGetHWRec
-vgaHWRestoreFonts
-vgaHWSaveFonts
+vgaHWGetIndex
+vgaHWGetIOBase
+vgaHWRestore
+vgaHWSave
 write
 xf86AddDriver
Index: /trunk/src/VBox/Additions/x11/vboxvideo/vboxvideo.c
===================================================================
--- /trunk/src/VBox/Additions/x11/vboxvideo/vboxvideo.c	(revision 35948)
+++ /trunk/src/VBox/Additions/x11/vboxvideo/vboxvideo.c	(revision 35949)
@@ -104,5 +104,4 @@
 static void VBOXAdjustFrame(int scrnIndex, int x, int y, int flags);
 static void VBOXFreeScreen(int scrnIndex, int flags);
-static void VBOXFreeRec(ScrnInfoPtr pScrn);
 static void VBOXDisplayPowerManagementSet(ScrnInfoPtr pScrn, int mode,
                                           int flags);
@@ -111,6 +110,6 @@
 static Bool VBOXMapVidMem(ScrnInfoPtr pScrn);
 static void VBOXUnmapVidMem(ScrnInfoPtr pScrn);
-static Bool VBOXSaveRestore(ScrnInfoPtr pScrn,
-                            vbeSaveRestoreFunction function);
+static void VBOXSaveMode(ScrnInfoPtr pScrn);
+static void VBOXRestoreMode(ScrnInfoPtr pScrn);
 static Bool VBOXAdjustScreenPixmap(ScrnInfoPtr pScrn, int width, int height);
 
@@ -200,12 +199,4 @@
 };
 
-static const char *vbeSymbols[] = {
-    "VBEExtendedInit",
-    "VBEGetVBEMode",
-    "VBESaveRestore",
-    "VBESetVBEMode",
-    NULL
-};
-
 static const char *ramdacSymbols[] = {
     "xf86InitCursor",
@@ -215,8 +206,10 @@
 
 static const char *vgahwSymbols[] = {
+    "vgaHWFreeHWRec",
     "vgaHWGetHWRec",
-    "vgaHWFreeHWRec",
-    "vgaHWSaveFonts",
-    "vgaHWRestoreFonts",
+    "vgaHWGetIOBase",
+    "vgaHWGetIndex",
+    "vgaHWRestore",
+    "vgaHWSave",
     NULL
 };
@@ -232,14 +225,4 @@
 
     return ((VBOXPtr)pScrn->driverPrivate);
-}
-
-static void
-VBOXFreeRec(ScrnInfoPtr pScrn)
-{
-    VBOXPtr pVBox = VBOXGetRec(pScrn);
-    free(pVBox->savedPal);
-    free(pVBox->fonts);
-    free(pScrn->driverPrivate);
-    pScrn->driverPrivate = NULL;
 }
 
@@ -569,5 +552,4 @@
         LoaderRefSymLists(fbSymbols,
                           shadowfbSymbols,
-                          vbeSymbols,
                           ramdacSymbols,
                           vgahwSymbols,
@@ -795,9 +777,4 @@
         return FALSE;
 
-    /* We need the vbe module because we use VBE code to save and restore
-       text mode, in order to keep our code simple. */
-    if (!xf86LoadSubModule(pScrn, "vbe"))
-        return (FALSE);
-
     /* The framebuffer module. */
     if (!xf86LoadSubModule(pScrn, "fb"))
@@ -911,4 +888,10 @@
     xf86PrintModes(pScrn);
 
+    /* VGA hardware initialisation */
+    if (!vgaHWGetHWRec(pScrn))
+        return FALSE;
+    /* Must be called before any VGA registers are saved or restored */
+    vgaHWGetIOBase(VGAHWPTR(pScrn));
+
     /* Colour weight - we always call this, since we are always in
        truecolour. */
@@ -974,20 +957,9 @@
     TRACE_ENTRY();
 
-    /* VGA hardware initialisation */
-    if (!vgaHWGetHWRec(pScrn))
-        return FALSE;
-
-    /* We make use of the X11 VBE code to save and restore text mode, in
-       order to keep our code simple. */
-    if ((pVBox->pVbe = VBEExtendedInit(NULL, pVBox->pEnt->index,
-                                       SET_BIOS_SCRATCH
-                                       | RESTORE_BIOS_SCRATCH)) == NULL)
-        return (FALSE);
-
     if (!VBOXMapVidMem(pScrn))
         return (FALSE);
 
     /* save current video state */
-    VBOXSaveRestore(pScrn, MODE_SAVE);
+    VBOXSaveMode(pScrn);
 
     /* mi layer - reset the visual list (?)*/
@@ -1219,5 +1191,5 @@
         vboxDisableVbva(pScrn);
     vboxClearVRAM(pScrn, 0, 0);
-    VBOXSaveRestore(pScrn, MODE_RESTORE);
+    VBOXRestoreMode(pScrn);
     vboxDisableGraphicsCap(pVBox);
 #ifdef VBOX_DRI
@@ -1245,13 +1217,10 @@
 
     if (pScrn->vtSema) {
-        VBOXSaveRestore(xf86Screens[scrnIndex], MODE_RESTORE);
+        VBOXRestoreMode(xf86Screens[scrnIndex]);
         VBOXUnmapVidMem(pScrn);
     }
     pScrn->vtSema = FALSE;
 
-    /* Destroy the VGA hardware record */
-    vgaHWFreeHWRec(pScrn);
-
-    /* And do additional bits which are separate for historical reasons */
+    /* Do additional bits which are separate for historical reasons */
     vbox_close(pScrn, pVBox);
 
@@ -1420,5 +1389,11 @@
 VBOXFreeScreen(int scrnIndex, int flags)
 {
-    VBOXFreeRec(xf86Screens[scrnIndex]);
+    ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
+
+    /* Destroy the VGA hardware record */
+    vgaHWFreeHWRec(pScrn);
+    /* And our private record */
+    free(pScrn->driverPrivate);
+    pScrn->driverPrivate = NULL;
 }
 
@@ -1479,65 +1454,35 @@
 }
 
-Bool
-VBOXSaveRestore(ScrnInfoPtr pScrn, vbeSaveRestoreFunction function)
-{
-    VBOXPtr pVBox;
-    Bool rc = TRUE;
+void
+VBOXSaveMode(ScrnInfoPtr pScrn)
+{
+    VBOXPtr pVBox = VBOXGetRec(pScrn);
+    vgaRegPtr vgaReg;
 
     TRACE_ENTRY();
-    if (MODE_QUERY < 0 || function > MODE_RESTORE)
-	rc = FALSE;
-
-    if (rc)
-    {
-        pVBox = VBOXGetRec(pScrn);
-
-        /* Query amount of memory to save state */
-        if (function == MODE_QUERY ||
-    	    (function == MODE_SAVE && pVBox->state == NULL))
-        {
-
-	    /* Make sure we save at least this information in case of failure */
-            (void)VBEGetVBEMode(pVBox->pVbe, &pVBox->stateMode);
-            vgaHWSaveFonts(pScrn, &pVBox->vgaRegs);
-
-            if (!VBESaveRestore(pVBox->pVbe,function,(pointer)&pVBox->state,
-                                &pVBox->stateSize,&pVBox->statePage)
-               )
-                rc = FALSE;
-        }
-    }
-    if (rc)
-    {
-        /* Save/Restore Super VGA state */
-        if (function != MODE_QUERY) {
-
-            if (function == MODE_RESTORE)
-                memcpy(pVBox->state, pVBox->pstate,
-                       (unsigned) pVBox->stateSize);
-
-            if (   (rc = VBESaveRestore(pVBox->pVbe,function,
-                                        (pointer)&pVBox->state,
-                                        &pVBox->stateSize,&pVBox->statePage)
-                   )
-                && (function == MODE_SAVE)
-               )
-            {
-                /* don't rely on the memory not being touched */
-                if (pVBox->pstate == NULL)
-                    pVBox->pstate = malloc(pVBox->stateSize);
-                memcpy(pVBox->pstate, pVBox->state,
-                       (unsigned) pVBox->stateSize);
-            }
-
-            if (function == MODE_RESTORE)
-            {
-                VBESetVBEMode(pVBox->pVbe, pVBox->stateMode, NULL);
-                vgaHWRestoreFonts(pScrn, &pVBox->vgaRegs);
-            }
-        }
-    }
-    TRACE_LOG("returning %s\n", rc ? "TRUE" : "FALSE");
-    return rc;
+    vgaReg = &VGAHWPTR(pScrn)->SavedReg;
+    vgaHWSave(pScrn, vgaReg, VGA_SR_ALL);
+    pVBox->fSavedVBEMode = VBoxVideoGetModeRegisters(&pVBox->cSavedWidth,
+                                                     &pVBox->cSavedHeight,
+                                                     &pVBox->cSavedPitch,
+                                                     &pVBox->cSavedBPP,
+                                                     &pVBox->fSavedFlags);
+}
+
+void
+VBOXRestoreMode(ScrnInfoPtr pScrn)
+{
+    VBOXPtr pVBox = VBOXGetRec(pScrn);
+    vgaRegPtr vgaReg;
+
+    TRACE_ENTRY();
+    vgaReg = &VGAHWPTR(pScrn)->SavedReg;
+    vgaHWRestore(pScrn, vgaReg, VGA_SR_ALL);
+    if (pVBox->fSavedVBEMode)
+        VBoxVideoSetModeRegisters(pVBox->cSavedWidth, pVBox->cSavedHeight,
+                                  pVBox->cSavedPitch, pVBox->cSavedBPP,
+                                  pVBox->fSavedFlags, 0, 0);
+    else
+        VBoxVideoDisableVBE();
 }
 
Index: /trunk/src/VBox/Additions/x11/vboxvideo/vboxvideo.h
===================================================================
--- /trunk/src/VBox/Additions/x11/vboxvideo/vboxvideo.h	(revision 35948)
+++ /trunk/src/VBox/Additions/x11/vboxvideo/vboxvideo.h	(revision 35949)
@@ -117,9 +117,4 @@
 #endif
 
-#include "vgaHW.h"
-
-/* VBE/DDC support */
-#include "vbe.h"
-
 /* ShadowFB support */
 #include "shadowfb.h"
@@ -169,5 +164,4 @@
 typedef struct VBOXRec
 {
-    vbeInfoPtr pVbe;  /** @todo do the VBE bits ourselves? */
     EntityInfoPtr pEnt;
 #ifdef PCIACCESS
@@ -185,9 +179,9 @@
     /** The current line size in bytes */
     uint32_t cbLine;
-    CARD8 *state, *pstate;	/* SVGA state */
-    int statePage, stateSize, stateMode;
-    CARD32 *savedPal;
-    CARD8 *fonts;
-    vgaRegRec vgaRegs;  /* Space for saving VGA information */
+    /** Whether the pre-X-server mode was a VBE mode */
+    bool fSavedVBEMode;
+    /** Paramters of the saved pre-X-server VBE mode, invalid if there is none
+     */
+    uint16_t cSavedWidth, cSavedHeight, cSavedPitch, cSavedBPP, fSavedFlags;
     CloseScreenProcPtr CloseScreen;
     /** Default X server procedure for enabling and disabling framebuffer access */
