From Wikipedia, the free encyclopedia
QEMU is a processor emulator that relies on dynamic binary translation to achieve a reasonable speed while being easy to port on new host CPU architectures.
In conjunction with CPU emulation, it also provides a set of device models, allowing it to run a variety of unmodified guest operating systems; it can thus be viewed as a hosted virtual machine monitor. It also provides an accelerated mode for supporting a mixture of binary translation (for kernel code) and native execution (for user code), in the same fashion as VMware Workstation and Microsoft Virtual PC.
QEMU can also be used purely for CPU emulation for user level processes; in this mode of operation it is most similar to Valgrind.
One feature exclusive to QEMU is that of portability: the virtual machines can be run on any PC, even those where the user has only limited rights with no administrator access, making the "PC-on-a-USB-stick" concept very real. Similar applications exist (such as MojoPac) but they currently require administrator rights to run, making them useless in areas such as public libraries, internet cafes, and so on.
QEMU was written by Fabrice Bellard and is free software. Specifically, the QEMU virtual CPU core library is released under the GNU Lesser General Public License (GNU LGPL). Many hardware device emulation sources are released under the BSD license. When running on Windows, although by default it uses DirectSound, there is the option to use the proprietary FMOD library, which if used disqualifies it for a single, unified, Open Source software license.
QEMU has two operating modes:
- User mode emulation
- QEMU can launch Linux or Darwin/Mac OS X processes compiled for one CPU on another CPU. Target OS system calls are thunked for endianness and 32/64 bit mismatches. WINE Windows API reimplementation and DOSEMU are the main targets for QEMU in user mode emulation. This mode also eases cross-compilation and cross-debugging.
- Complete Computer System mode emulation
- QEMU emulates a full computer system, including a processor and various peripherals. It can be used to provide virtual hosting of several virtual computers on a single computer. QEMU can boot many guest operating systems, including Linux, Solaris, Microsoft Windows, DOS, and BSD ; it supports emulating several hardware platforms, including x86, x86-64 (AMD64/Intel 64), ARM, Alpha, ETRAX CRIS, MIPS, MicroBlaze and SPARC.
QEMU offers many features that are also present in other emulators. For example, it can save and restore the state of the virtual machine with all programs running. As with many emulators, guest operating systems do not need to be patched to successfully run.
QEMU supports the emulation of various architectures, including IA-32 (x86) PCs, x86-64 PCs, MIPS R4000, Sun's SPARC sun4m, Sun's SPARC sun4u, ARM development boards (Integrator/CP and Versatile/PB), SH4 SHIX board, PowerPC (PReP and Power Macintosh), ETRAX CRIS and MicroBlaze architectures. The QEMU homepage provides a complete list of supported architectures.
The virtual machine can be equipped with many types of hardware. Some of these are: hard disks, CD-ROM drives, network cards, sound chips, and USB devices. USB devices can be completely emulated (mass storage from image files, input devices), or the host's USB devices can be used (however, this requires administrator privileges and does not work with all devices).
Virtual hard disk images can be stored in a special format (qcow2) that only takes up disk space that the guest OS actually uses. This way, an emulated 120 GiB disk can still take up just several hundred megabytes on the host. The QCOW2 format also allows the creation of overlay images that record the difference to another base image file which is not modified. This can be useful to have the possibility of reverting the disk's contents to an earlier state. For example, a base image could hold a fresh install of an operating system that is known to work, and the overlay images are worked with. Should the guest system be unusable (virus attack, accidental system destruction, ...), the overlay can be deleted and recreated.
QEMU can emulate network cards (of different models) which share the host system's connectivity by doing network address translation, effectively allowing the guest to use the same network as the host. The virtual network cards can also be connected to network cards of other instances of QEMU or local TAP interfaces.
It also has some features that are not present in many emulators. QEMU integrates several services to allow the host and guest systems to communicate, for example, a SMB server and network port redirection (to allow incoming connections to the virtual machine). It can also boot Linux kernels without having to prepare a bootable image with a bootloader.
QEMU does not depend on the presence of graphical output methods on the host system. Instead, it can allow one to access the screen of the guest OS via VNC. It can also use an emulated serial line, without any screen, with applicable operating systems.
Simulating multiple CPUs that can be used like a real SMP system is possible.
Unlike some other emulators, QEMU does not require administrative rights to run, except if additional kernel modules for improving speed are used (like KQEMU).
 User mode emulation
QEMU mimics the hardware environment. This is what allows it to run code that was compiled for a different architecture. In practical terms this is how emulation differs from simulation. It is important because it allows code to be tested after it is compiled.
An operating system separates hardware access from the various layers of software (application-layer being the easiest to visualize). This gives rise to different access permissions or rights. In such an environment the ability to mimic hardware and to maintain control is difficult to achieve. QEMU has achieved this.
 Tiny Code Generator
The Tiny Code Generator (TCG) aims to remove the shortcoming of relying on a particular version of GCC or any compiler, instead incorporating the compiler (code generator) into other tasks performed by QEMU in run-time. The whole translation task thus consists of two parts: blocks of target code (TBs) being rewritten in TCG ops - a kind of machine-independent intermediate notation, and subsequently this notation being compiled for the host's architecture by TCG. Optional optimisation passes are performed between them.
TCG requires that there be dedicated code written to support every architecture it is being run on. It also requires that the target instruction translation be rewritten to take advantage of TCG ops, instead of the previously used dyngen ops.
Starting with QEMU Version 0.10.0, TCG ships with the QEMU stable release.
Virtualization of machines or operating systems comes at the cost of speed of execution. One tried and true method to reduce the effect (cost) are software-based drivers which perform specific functions that would otherwise be very costly to perform by the virtualization software. Two of those software programs, developed for QEMU, are KQEMU and QVM86.
Fabrice Bellard also wrote a Linux kernel module (with preliminary ports to FreeBSD and MS Windows) named KQEMU or QEMU Accelerator, which notably speeds up x86 emulation on x86 platforms. This is accomplished by running user mode code directly on the host computer's CPU, and using processor and peripheral emulation only for kernel mode and real mode code. KQEMU also supports a kernel emulation mode in which portions of kernel mode code run on the host's CPU.
Unlike KVM, KQEMU can execute code from many guest OSes even if the host CPU does not support hardware virtualization. KQEMU supports both x86 and x86_64 CPUs. As a future development for KQEMU there are plans to support the hardware (CPU) based virtualization extensions introduced by Intel VT-x and AMD-V families of processors.
KQEMU, was initially released free of charge but was licensed as a closed-source proprietary product. However, since version 1.3.0pre10, released on February 5, 2007, it has been available under the GNU General Public License. QEMU versions starting with 0.12.0 no longer support KQEMU.
QVM86 was a Linux kernel module to provide x86 virtualization capabilities for the QEMU emulator. Virtualization allowed "emulated" code to be run natively on the host CPU, using the CPU protection mechanisms to intercept and emulate privileged events. It was licensed under GNU GPLv2 license. It was developed as a drop-in replacement for the then closed-source KQEMU, which has since been made available under the GPL. The developer of QVM86 ceased development on January 21, 2007 as they decided that the project had been rendered obsolete by the release of VirtualBox.
 Hardware-assisted emulation
The MIPS-compatible Loongson-3 processor adds 200 new instructions to help QEMU translate x86 instructions; those new instructions lower the overhead of executing x86/CISC-style instructions in the MIPS pipeline. With additional improvements in QEMU by the Chinese Academy of Sciences, Loongson-3 achieves an average of 70% the performance of executing native binaries while running x86 binaries from nine benchmarks.
 Integration in other virtualization solutions
In January 2007, VirtualBox was released. It uses some of QEMU's virtual hardware devices and has a built-in dynamic recompiler that is based on QEMU. As with KQEMU, it runs nearly all guest code natively on the host via the VMM (Virtual Machine Manager), and uses the recompiler only for special situations as a fallback mechanism (this holds true for guest code that executes in real mode and some other rare scenarios at runtime). In addition, VirtualBox goes through a lot of code analysis and patching via a built-in disassembler to reduce usage of the recompiler to a minimum. VirtualBox is open-source software under the GPL, except for a number of enterprise features, and standard user features like USB.
As of the 3.0 release (updated 2009-07-06) VirtualBox does have support for SMP in a guest OS.
The Xen virtual machine monitor can run in HVM (hardware virtual machine) mode, using Intel VT-x or AMD-V hardware x86 virtualization extensions. This means that instead of paravirtualized devices, a real set of virtual hardware is exposed to the domU to use real device drivers to talk to.
QEMU includes several components: CPU emulators, emulated devices, generic devices, machine descriptions, user interface, and a debugger. The emulated devices and generic devices in QEMU make up its device models for I/O virtualization.
Xen-HVM has device emulation based on the QEMU project to provide I/O virtualization to the VMs. Hardware is emulated via a patched QEMU "device model" (qemu-dm) daemon running as a backend in dom0. This means that the virtualized machines see as hardware: a PIIX3 IDE (with some rudimentary PIIX4 capabilities), Cirrus Logic or vanilla VGA emulated video, RTL8139 or NE2000 network emulation, PAE, and somewhat limited ACPI and APIC support and no SCSI emulation.
 Kernel-based Virtual Machine (KVM)
KVM is a Linux kernel virtualization infrastructure. By itself, it does not perform any emulation. Instead, a user-space program uses the /dev/kvm interface to set up the guest VM's address space, feed it simulated I/O and map its video display back onto the host's. At least two programs exploit KVM: a modified version of QEMU and QEMU itself since version 0.10.0.
Darwine was originally intended to support compiling of Win32 source into Mach-O/PowerPC binaries for Macintosh computers. The project shifted objectives combining Wine's program loader with QEMU in user mode emulation, to allow running of Win32 binaries on Mac OS X for PowerPC.
 Win4Lin Pro Desktop
In early 2005, Win4Lin introduced Win4Lin Pro Desktop, based on a 'tuned' version of QEMU and KQEMU and it hosts NT-versions of Windows. In June 2006, Win4Lin released Win4Lin Virtual Desktop Server based on the same code base. Win4Lin Virtual Desktop Server serves Microsoft Windows sessions to thin clients from a Linux server.
In September 2006, Win4Lin announced a change of the company name to Virtual Bridges with the release of Win4BSD Pro Desktop, a port of the product to FreeBSD and PC-BSD. Solaris support followed in May 2007 with the release of Win4Solaris Pro Desktop and Win4Solaris Virtual Desktop Server.
- Incomplete support for Microsoft Windows and other host operating systems; this has improved with recent versions
- Incomplete support for less frequently-used architectures
- Currently only supports traditional BIOS boot model for the guest OSes, no UEFI boot model support yet on x64 systems
- Few special device drivers (graphics, sound, IO) for guests are available, thus quite large overhead for multimedia applications. For example, a Cirrus Logic graphics chip and various popular sound cards (ES1370, Sound Blaster 16, Gravis Ultrasound and AdLib) are emulated, but they do not provide hardware-accelerated performance on the host system. Also, it supports only SDL or Cocoa video output libraries although a patch for GGI support exists Virtio support for block and network is fully supported for several Linux distributions running in a VM. Virtio drivers are also now available for Windows. Recent work has added a virtual video device compatible with the VMWare video driver, however it does not support any scaled video or 3D features.
 Emulated hardware platforms
QEMU with the free operating system ReactOS
Besides the CPU the following is emulated:
The BIOS implementation used by QEMU starting from version 0.12 is SeaBIOS. The VGA BIOS implementation comes from Plex86/Bochs.
On the PowerPC target, Open Hack'Ware, an Open-Firmware-compatible BIOS, is used.
QEMU emulates the following PowerMac peripherals:
- UniNorth PCI Bridge
- PCI-VGA-compatible Graphics card which maps the VESA Bochs Extensions
- Two PMAC-IDE-Interfaces with hard disk and CD-ROM support.
- NE2000 PCI Adapter
- Non Volatile RAM
- VIA-CUDA with ADB keyboard and mouse.
QEMU emulates the following PREP peripherals:
- PCI Bridge
- PCI-VGA-compatible graphics card with VESA Bochs Extensions
- Two IDE-Interfaces with hard disk and CD-ROM support
- Floppy drive
- NE2000 network adapter
- Serial interface
- PREP Non Volatile RAM
- PC-compatible keyboard and mouse
QEMU booted into the ARM port of Fedora 8
QEMU emulates the armv5tej instruction set and all the derivative processors families like ARM7, ARM9E, ARM10E and XScale. It emulates full systems like Integrator/CP board, Versatile baseboard, RealView Emulation baseboard, XScale-based PDAs, Palm Tungsten|E PDA, Nokia N800 and Nokia N810 internet tablets etc.
Sun SPARC-Architecture = (Scalable Processor ARChitecture)
When the BIOS in the JavaStation (sun4m-Architecture) became Version 0.8.1 Proll , a PROM replacement, used, in Version 0.8.2 was replaced with OpenBIOS.
QEMU emulates the following sun4m/sun4c/sun4d peripherals:
- IOMMU or IO-UNITs
- TCX Frame buffer (graphics card)
- Lance (Am7990) Ethernet
- Non Volatile RAM M48T02/M48T08
- Slave I/O: timers, interrupt controllers, Zilog serial ports, keyboard and power/reset logic
- ESP SCSI controller with hard disk and CD-ROM support
- Floppy drive (not on SS-600MP)
- CS4231 sound device (only on SS-5, not working yet)
Emulating Sun4u (UltraSPARC PC-like machine), Sun4v (T1 PC-like machine), or generic Niagara (T1) machine with the following peripherals:
- UltraSparc IIi APB PCI Bridge
- PCI VGA compatible card with VESA Bochs Extensions
- PS/2 mouse and keyboard
- Non Volatile RAM M48T59
- PC-compatible serial ports
- 2 PCI IDE interfaces with hard disk and CD-ROM support
- Floppy disk
- Microblaze with/without MMU
 External patches
External trees exist supporting the following targets:
 See also
 External links