VGA Emulation is a software or hardware reproduction of the behavior of the original IBM VGA video adapter. It allows modern graphics systems to run legacy code by intercepting and converting its calls into commands understood by current hardware.
VGA is used in the BIOS of modern video cards (UEFI GOP Legacy Mode), in hypervisors (QEMU, VirtualBox), and in industrial systems. It is necessary for booting legacy operating systems (DOS, Windows 9x), for text output during the early boot stage (POST), and for running classic applications that use VGA modes.
Typical Problems
Emulation does not always provide accurate timing for register cycles, leading to failures in time-critical demoscene productions or games. Conflicts with memory protection and synchronization errors can also occur when attempting direct access to video memory via hardware ports, causing visual artifacts or system hangs.
How It Works
Unlike full software emulation (e.g., DOSBox which emulates an entire PC), hardware VGA Emulation works by intercepting accesses to I/O ports (0x3B0–0x3DF, 0x3C0) and the memory region A0000–BFFFF. A modern GPU or hypervisor driver uses a VGA shadow register table. When a write to a legacy CRT register is attempted, the emulator computes the logical state of rows and columns, then converts it into parameters for the current video mode through an intermediate layer, such as saving a text buffer. Unlike built-in Legacy VGA support (physically present circuits), emulation does not generate analog sync signals or actually control the sweep frequency; it only simulates register behavior. Compared to KVM passthrough of a physical graphics card, emulation completely isolates the guest system from the physical GPU, adding flexibility but reducing performance and accuracy for low-level code that directly accesses ports.
VGA Functionality
- Framebuffer mechanism. The driver allocates a linear region in the guest OS’s RAM for the primary framebuffer. The hypervisor, through shared memory or I/O channels, copies the contents of this buffer to the virtual display. This approach eliminates the need for hardware emulation of video memory on the host side, reducing overhead.
- Operating modes and resolutions. QXL supports dynamic display resolution changes at the request of the guest OS via ACPI events or driver extensions. The maximum resolution is limited by the size of the allocated buffer (typically up to
2560x1600). Color depth is fixed at 32 bits per pixel, ensuring compatibility with modern window managers. - QXL (Fast quantization and deblocking filtering)
- 2D graphics acceleration. Unlike purely software VGA emulations, QXL hardware-accelerates rectangle copying operations (BitBLT), area fills, and window scrolling. Rendering commands are formed by the driver as descriptors that are placed into a ring buffer. The hypervisor asynchronously fetches the commands and executes them on the host CPU.
- Interaction with SPICE. Full QXL functionality is only realized when using the SPICE protocol. The driver passes lists of rendering commands directly to the host, where the SPICE server renders them into a video stream. This reduces traffic volume: instead of transmitting bitmaps, high-level operations are sent. The driver also supports on-the-fly compression of screen regions.
- Memory management. The driver uses the concept of surfaces, separate regions of video memory for windows or cursors. Each surface has its own identifier and can be marked as primary (onscreen) or secondary (offscreen). The hypervisor may unload unused surfaces to the host disk at its discretion.
- Command ring buffers. For data transfer between guest and host, QXL uses two shared ring buffers: command and response. The guest writes pointers to
QXLCommandstructures into the command buffer, and the host, after execution, places statuses into the response buffer. The buffers operate in a wait-free mode when using atomic operations. - Synchronization and interrupts. By default, the driver operates in polling mode to minimize latency. When necessary, QXL generates a virtual INTA interrupt to notify the guest of operation completion. The guest driver can switch to interrupt mode via the PCI device status register. This is important for interactive workloads.
- Multiple monitor support. QXL emulates a graphics card with up to 4 independent outputs. Each output has its own framebuffer located in shared memory. The guest driver switches the primary surface via a separate I/O port, and the hypervisor exports each surface as a separate virtual monitor for SPICE or VNC.
- Cursor handling. The driver allocates a hardware cursor with a separate small surface (up to
64x64pixels). The guest changes the cursor shape by writing a bitmap to a special register and sending aQXL_CMD_CURSORcommand. The hypervisor renders the cursor software-over the video stream, avoiding redrawing the entire frame for simple pointer movement. - Image compression algorithm. When SPICE is activated, the QXL driver sends not only commands to the host but also raw bitmaps for non-standard operations. The LZ4 or Quic (an RLE variant) algorithm is used for compression. The method is chosen dynamically based on rectangle size: RLE for small rectangles, LZ4 with a compression threshold check for larger ones.
- Bandwidth management. The driver includes a throttling mechanism to limit the rate of update transmission. When the command-per-second limit is exceeded, QXL pauses writing to the ring buffer, returning an
EBUSYerror. The guest video manager must retry after an interval specified in the registry (default 10 ms). - Command tracing. For debugging and profiling, QXL provides tracepoints inside the hypervisor kernel. The guest driver can enable logging mode, where each command is timestamped. This helps identify bottlenecks: oversize BitBLTs occurring too frequently, or improper surface ordering.
- Compatibility with legacy VGA. The driver implements full emulation of the standard VGA register set via ports
0x3C0–0x3DF. This allows the guest OS to boot in fallback mode if the QXL driver is not installed. However, when QXL is active, access to VGA ports is redirected to shadow registers that preserve the state of the emulated graphics card. - Windows-specific behavior. The QXL driver for Windows uses the Windows Display Driver Model (WDDM) version 1.3. It supports hardware acceleration for GDI, Direct2D, and some Direct3D functions via primitive emulation. Limitation: no hardware video acceleration (DXVA) support, so decoding is done by the guest CPU.
- WDDM (Windows video subsystem management)
- Linux-specific behavior. For Linux kernels 5.x and later, the QXL driver is built into the Direct Rendering Manager (DRM) subsystem. It exports an fbdev interface for the console and a DRM interface for X11/Wayland. Modesetting via KMS is supported, but there is no hardware OpenGL acceleration: all 3D commands are translated into 2D operations.
- FBDev (Outputting graphics via frame buffer device)KMS (Kernel-Level video mode switching)DRM (GPU access coordination)
- CPU load balancing. QXL minimizes the number of host interrupts by accumulating commands in the buffer until a threshold of 64 commands or a timeout of 2 ms is reached. The guest driver can force a buffer flush by writing to the
QXL_IO_FLUSHport. This reduces hypervisor context-switching frequency during intensive graphics. - Error recovery handling. In the event of a ring buffer failure (full or corrupt), the driver falls back to software mode: all rendering is done through the framebuffer without acceleration. Recovery is possible after resetting the graphics card state via PCI configuration space. The guest OS does not reboot, but unsent commands are lost.
- Performance tuning. The hypervisor administrator can set the
ram_size_mbparameter to allocate video memory from 64 to 512 MB. Themax_surfacessetting (up to 2048) is also available to increase the number of simultaneously stored surfaces. Increasing these parameters linearly raises host RAM consumption but accelerates complex scenes. - Non-volatile states. QXL does not support preserving video memory during live virtual machine migration. All surface contents are lost, and after migration, the guest must redraw the screen from scratch. This architectural limitation stems from avoiding copying large memory regions to maintain migration performance.
Comparison of VGA Emulation with alternatives
- VGA vs HDMI. VGA transmits an analog video signal at resolutions up to
1920x1080(often with interference), while HDMI is a digital interface supporting video up to 4K, audio, and HDCP. Over equal cable lengths, HDMI maintains lossless quality, whereas VGA is susceptible to noise and requires separate audio channels, a critical drawback for modern multimedia. - VGA vs DVI. DVI can operate in either analog mode (DVI-A, compatible with VGA via an adapter) or digital mode (DVI-D). VGA is limited to analog transmission, while DVI-D provides better sharpness on LCD panels and higher refresh rates. However, DVI does not carry audio, unlike HDMI, making VGA obsolete for high-resolution video.
- VGA vs DisplayPort. DisplayPort is a fully digital packet-based protocol supporting up to 8K, high color depth, and multi-channel audio. VGA requires dual DAC signal conversion and is limited by a pixel clock of about 400 MHz, causing blurring on large screens. DisplayPort also supports adapters for VGA, but reverse conversion is impossible without active converters.
- VGA vs RCA (Composite). Composite RCA transmits analog video over a single cable with interlaced scanning and low resolution (up to
576i). VGA uses separate RGB lines and synchronization (HSync/VSync), providing progressive scanning and clarity up to1080p, making VGA noticeably superior for monitors, but without audio or color difference correction. - VGA vs Thunderbolt. Thunderbolt (including versions 3–4) combines PCIe and DisplayPort on a single cable, transmitting digital 8K video, audio, and up to 100W of power. VGA is an analog unidirectional interface with no power or data transmission. Connecting a VGA display to Thunderbolt requires an active digital-to-analog converter with added latency, reducing practicality in professional scenarios.
OS and driver support
VGA Emulation emulates registers, video memory, and CRT controller sequences (6845) at the I/O port level (0x3B0–0x3DF) and linear buffer in shadow RAM, allowing legacy real-mode DOS drivers, Windows 9x drivers, and bootloaders (GRUB, LILO) to run unmodified on top of modern GPUs via I/O port trapping and MMIO-based emulation of mapped memory pages.
Security
VGA emulation isolates guest access to hardware ports within a virtualization container or hypervisor, filtering dangerous operations (direct writes to CRTC sequence registers or the DAC palette) through address range verification and blocking non-canonical modes (e.g., reprogramming the scan timing to corrupt adjacent RAM areas). It also applies a whitelist of allowed command sequences to prevent VGART poisoning attacks via DMA.
Logging
The logging system records all VGA I/O port operations with timestamps, values, and execution context (IN/OUT instruction, VBLANK interrupt), separately saving write attempts to non-standard SR01/SR04 registers (line frequency and memory protection). This helps debug driver conflicts and detect suspicious activity (attempts to switch into unmanaged Mode X with bank chaining unlocked).
Limitations
Key limitations include the inability to emulate 2D blitter hardware acceleration and VBE/Core registers (VESA BIOS Extensions) above version 1.2 without a Software Rendering Bridge, lack of analog sync signal output (HSync/VSync) for legacy monitors, and reduced emulation performance during intensive updates of 16-color modes due to costly translation of the planar frame buffer to a linear RGB format over the virtual display bus.
History and development
Starting with MDA/CGA chip emulation in IBM PC emulators in the 1980s, VGA Emulation evolved to fully replace QEMU’s stdvga and Xen’s Cirrus Logic mechanisms, then transitioned to component decomposition (registers, palette, timings) in Linux kernel modules (vgacon, fbdev), and reached its modern state in VirtualBox and VMware, where VGA emulation is gradually replaced by hardware accelerated shaders but remains as a fallback mode for OS installation without WDDM driver support.