QEMU - Machine Platform Emulation
Machine Platform Emulation
Purpose and Scope
This document provides an overview of QEMU's machine platform emulation, which defines the virtual hardware architectures that QEMU can emulate. Machine models specify the CPU architecture, memory layout, device configuration, buses, and firmware interfaces available to guest operating systems. Understanding machine models is essential for both QEMU users who need to select the right virtual hardware platform and developers who want to extend QEMU with new or enhanced machine types.
Each machine class defines the following key elements:
- CPU architecture and default CPU model
- Supported RAM configurations
- Available devices and buses
- Firmware interfaces (BIOS, UEFI, etc.)
- Boot methods
- Architecture-specific features
Initialization Process
When QEMU starts, it initializes the selected machine model through a multi-stage process:
Different machine models implement these steps differently based on their architecture requirements, but all follow this general flow. The machine initialization is typically handled by an init
function in the machine class, which is called during QEMU startup.
Sources: hw/core/machine.c604-795 hw/i386/pc_piix.c104-648 hw/ppc/spapr.c632-684 hw/arm/virt.c128-413
Key Machine Models
ARM Machine Models
Virt Machine
The ARM virt machine is a generic virtual platform that doesn't correspond to any real hardware:
Key features:
- Support for both ARMv7 and ARMv8 (AArch64) CPUs
- Generic Interrupt Controller (GIC)
- Standard ARM peripherals (PL011 UART, PL031 RTC)
- Optional PCIe support
- Device tree or ACPI firmware interface
- Highly configurable memory layout
The ARM virt machine is defined with a memory map that includes regions for flash, CPU peripherals, GIC components, UART, RTC, and other devices. The memory map is defined in the base_memmap
array in the virt.c file.
Sources: hw/arm/virt.c165-199 hw/arm/virt.c276-350 hw/arm/virt-acpi-build.c1-50
x86 Machine Models
QEMU provides two primary x86 machine types:
PC (i440FX-based)
The traditional PC machine is based on the Intel i440FX chipset:
Key features:
- ISA and PCI buses
- Legacy I/O devices
- IDE storage controller
- SeaBIOS firmware
- ACPI support
The initialization of the i440FX PC machine is handled by the pc_init1
function, which sets up the memory regions, creates the PCI host bridge, initializes the CPUs, and sets up the various devices.
Sources: hw/i386/pc_piix.c104-648 hw/i386/pc.c276-287 hw/i386/acpi-build.c88-112
Q35 (Modern PC)
The more modern Q35 machine is based on the Intel Q35/ICH9 chipset:
Key features:
- PCIe bus architecture
- AHCI/SATA storage controller
- Enhanced USB support
- UEFI firmware support
- More modern ACPI implementation
The Q35 machine is initialized by the pc_q35_init
function, which sets up the memory regions, creates the Q35 host bridge, initializes the CPUs, and sets up the ICH9 southbridge and associated devices.
Sources: hw/i386/pc_q35.c128-413 hw/i386/acpi-build.c88-112 hw/i386/acpi-build.c326-434
Machine Model Configuration
QEMU machine models can be configured through various mechanisms:
Command-line Options
The primary way to select and configure a machine model is through command-line options:
qemu-system-x86_64 -M q35,accel=kvm -m 4G -smp 4
This specifies:
- The Q35 machine model
- KVM acceleration
- 4GB of RAM
- 4 CPU cores
Machine Properties
Each machine model exposes specific properties that can be configured:
Property | Description | Example |
---|---|---|
accel |
Acceleration method (tcg, kvm, etc.) | -M q35,accel=kvm |
smm |
System Management Mode | -M pc,smm=on |
firmware |
Firmware type | -M virt,firmware=uefi |
secure |
Secure boot/mode | -M virt,secure=on |
smp-threads |
SMT/hyperthreading support | -M spapr,smp-threads=2 |
Architecture-specific machine models provide additional properties for fine-tuning the virtual hardware. For example, the PC machine models expose properties like vmport
, smbus
, sata
, and i8042
to control the presence of specific devices.
Sources: hw/core/machine.c604-795 hw/i386/pc.h63-71 include/hw/i386/pc.h63-71 hw/arm/virt.h44-233
Creating New Machine Types
Developers can extend QEMU by creating new machine types. The typical approach is:
- Define a new machine type that inherits from an existing type
- Implement class and instance initialization functions
- Register the new machine type
Example of machine type registration:
static void mynewpc_class_init(ObjectClass *oc, void *data)
{
MachineClass *mc = MACHINE_CLASS(oc);
mc->desc = "My New PC Machine";
mc->init = mynewpc_init;
/* Set other machine class properties */
}
static const TypeInfo mynewpc_info = {
.name = MACHINE_TYPE_NAME("mynewpc"),
.parent = TYPE_PC_MACHINE,
.class_init = mynewpc_class_init,
};
static void mynewpc_register_types(void)
{
type_register_static(&mynewpc_info);
}
type_init(mynewpc_register_types);
QEMU handles machine type versioning through naming conventions (e.g., pc-i440fx-9.2
for the PC machine as it was in QEMU 9.2), ensuring backward compatibility for older VM configurations. This is particularly evident in the ARM virt machine, which uses macros like DEFINE_VIRT_MACHINE_AS_LATEST
to create versioned machine types.
Sources: hw/arm/virt.c111-141 hw/i386/pc.h301-344 hw/core/machine.c40-62
Relationship with Other QEMU Components
Machine models integrate with other QEMU systems to provide a complete emulation environment:
This integration allows QEMU to provide a complete and coherent emulation environment tailored to specific hardware architectures. The machine model serves as the central coordinator that brings together all these components to create a functional virtual system.
Sources: hw/i386/pc.c276-287 hw/ppc/spapr.c632-684 hw/arm/virt.c128-413 hw/s390x/s390-virtio-ccw.c105-127
Conclusion
Machine models form the foundation of QEMU's system emulation capabilities, providing the virtual hardware environment that guest operating systems interact with. Understanding the different machine models and their capabilities is essential for effectively using QEMU in various scenarios, from simple development environments to complex enterprise virtualization.
Each architecture's machine models reflect the unique characteristics and requirements of that architecture, while still providing a consistent interface to the rest of QEMU. This architecture-specific approach allows QEMU to accurately emulate a wide range of hardware platforms while maintaining good performance and compatibility.
posted on 2025-10-16 13:50 ENGINEER-F 阅读(4) 评论(0) 收藏 举报