Home IT Linux Windows Database Network Programming Server Mobile  
  Home \ Linux \ QEMU code analysis: BIOS loading process     - Ubuntu install video playback software SMPlayer (Linux)

- How to manage start-up applications in Ubuntu (Linux)

- Using C / C ++ extensions Python (Programming)

- Linux Kernel 4.2.2 compiler installation tutorial (Linux)

- PL / SQL in forall simple test (Database)

- How to configure MariaDB replication in CentOS Linux (Database)

- Scope of variables in Object-C (Programming)

- Comparison of C # and Java (Programming)

- Ubuntu 14.04, 13.10 install OpenCV 2.4.9 (Linux)

- Zabbix Agent for Linux Installation and Configuration (Server)

- Linux group account deletion, and other related operations (Linux)

- shell script: LVS start simple script (Server)

- How dependent on Fedora, CentOS, RHEL check RPM packages (Linux)

- C ++ constant definition (Programming)

- C # Future: Method Contract (Programming)

- Linux Network Programming - raw socket Example: sending a UDP packet (Programming)

- Zabbix configure DataGuard monitoring (Database)

- Simple comparison of MySQL and Oracle in a sql analytical details (Database)

- Linux process management related content (Linux)

- Regular expressions in Perl (Programming)

  QEMU code analysis: BIOS loading process
  Add Date : 2017-08-31      
  QEMU is an open source machine emulator and a widely used virtual machine, which provides a virtual machine hardware virtualization capabilities, the use of certain hardware firmware by some open source projects. This article describes QEMU code to use the BIOS, by analyzing the QEMU code, how to explain the BIOS is loaded into the physical memory of the virtual machine.

QEMU use BIOS Profile

BIOS provides the motherboard or video card firmware information and basic input and output functions, QEMU using some open source projects such as Bochs, openBIOS like. QEMU is used to form part of the BIOS and the firmware binary file stored in the source tree pc-bios directory. pc-bios directory contains QEMU to use firmware, BIOS and some form of git source code stored in the sub-module source QEMU warehouse, when compiled QEMU program, also compile these BIOS or firmware binary file. QEMU supports a variety of start-up mode, for example, efi, pxe, etc., are included in the directory, which requires specific BIOS support.

Listing 1. QEMU source tree BIOS file

$ Ls pc-bios /
acpi-dsdt.aml efi-rtl8139.rom openbios-ppc pxe-e1000.rom qemu_logo_no_text.svg slof.bin bamboo.dtb
efi-virtio.rom openbios-sparc32 pxe-eepro100.rom qemu-nsis.bmp spapr-rtas bamboo.dts keymaps
openbios-sparc64 pxe-ne2k_pci.rom qemu-nsis.ico spapr-rtas.bin bios.bin kvmvapic.bin optionrom
pxe-pcnet.rom vgabios.bin efi-e1000.rom linuxboot.bin palcode-clipper pxe-rtl8139.rom
 s390-ccwvgabios-cirrus.bin efi-eepro100.rom petalogix-ml605.dtb pxe-virtio.rom s390-ccw.img
vgabios-qxl.bin efi-ne2k_pci.rom multiboot.bin petalogix-s3adsp1800.dtb q35-acpi-dsdt.aml
s390-zipl.rom vgabios-stdvga.bin efi-pcnet.rom ohw.diff ppc_rom.bin qemu-icon.bmp sgabios.bin
Listing 2. QEMU source tree to save the sub-modules of the BIOS code

-bash-4.1 $ cat .gitmodules
[Submodule "roms / vgabios"]
        path = roms / vgabios
        url = git: //git.qemu.org/vgabios.git/
[Submodule "roms / seabios"]
        path = roms / seabios
        url = git: //git.qemu.org/seabios.git/
[Submodule "roms / SLOF"]
        path = roms / SLOF
        url = git: //git.qemu.org/SLOF.git
[Submodule "roms / ipxe"]
        path = roms / ipxe
        url = git: //git.qemu.org/ipxe.git
[Submodule "roms / openbios"]
        path = roms / openbios
        url = git: //git.qemu.org/openbios.git
[Submodule "roms / qemu-palcode"]
        path = roms / qemu-palcode
        url = git: //github.com/rth7680/qemu-palcode.git
[Submodule "roms / sgabios"]
        path = roms / sgabios
        url = git: //git.qemu.org/sgabios.git
[Submodule "pixman"]
        path = pixman
        url = git: //anongit.freedesktop.org/pixman
[Submodule "dtc"]
        path = dtc
         url = git: //git.qemu.org/dtc.git

When we compile from source QEMU time, QEMU's Makefile will QEMU binary files are copied to the data file directory.
Listing 3. QEMU's Makefile on BIOS copy operation:

ifneq ($ (BLOBS),)
        set -e; for x in $ (BLOBS); do \
                $ (INSTALL_DATA) $ (SRC_PATH) / pc-bios / $$ x "$ (DESTDIR) $ (qemu_datadir)"; \
QEMU loading BIOS process analysis

When QEMU user space process started, QEMU process based on the parameters passed and the current host platform type, automatic load the appropriate BIOS firmware. QEMU process starts the initial phase, the register will call qemu_register_machine platform supports all types of machines by module_call_init function, then calls find_default_machine select a default models are initialized. The latest QEMU Code (1.7.0) the x86_64 platform, for example, supported machine types are:

Listing 4. x86_64 QEMU 1.7.0 version of the type of support

pc-q35-1.7 pc-q35-1.6 pc-q35-1.5 pc-q35-1.4 pc-i440fx-1.7 pc-i440fx-1.6 pc-i440fx-1.5
pc-i440fx-1.4 pc-1.3 pc-1.2 pc-1.1 pc-1.0 pc-0.15 pc-0.14
pc-0.13 pc-0.12 pc-0.11 pc-0.10 isapc
The default model used in the code for the latest pc-i440fx-1.7, BIOS files used are:

pc-bios / bios.bin
Default machine name: pc-i440fx-1.7
bios_name = bios.bin
pc-i440fx-1.7 interpreted as QEMU simulates the INTEL i440fx hardware chipset for the QEMU 1.7 version number. After finding the default machine after its physical memory initialization, QEMU first apply for a memory space to simulate virtual machine physical memory space, the application intact memory, depending on the platform or start QEMU process parameters for the virtual machine's physical memory initialization.

In QEMU, the entire physical memory to a structure struct MemoryRegion said specific definition shown in Listing 5.

Listing 5. QEMU in MemoryRegion structure

struct MemoryRegion {
    / * All fields are private - violators will be prosecuted * /
    const MemoryRegionOps * ops;
    const MemoryRegionIOMMUOps * iommu_ops;
    void * opaque;
    struct Object * owner;
    MemoryRegion * parent;
    Int128 size;
    hwaddr addr;
    void (* destructor) (MemoryRegion * mr);
    ram_addr_t ram_addr;
    bool subpage;
    bool terminates;
    bool romd_mode;
    bool ram;
    bool readonly; / * For RAM regions * /
    bool enabled;
    bool rom_device;
    bool warning_printed; / * For reservations * /
    bool flush_coalesced_mmio;
    MemoryRegion * alias;
    hwaddr alias_offset;
    unsigned priority;
    bool may_overlap;
    QTAILQ_HEAD (subregions, MemoryRegion) subregions;
    QTAILQ_ENTRY (MemoryRegion) subregions_link;
    QTAILQ_HEAD (coalesced_ranges, CoalescedMemoryRange) subregions_link;
    const char * name;
    uint8_t dirty_log_mask;
    unsigned ioeventfd_nb;
    MemoryRegionIoeventfd * ioeventfds;
    NotifierList iommu_notify;
Each MemoryRegion behalf of a memory area. Careful observation MemoryRegion member functions member functions, it contains an Object is used to refer to its owner, as well as used to refer to a member of his MemoryRegion parent (somewhat similar to the list). There are also three tail queue (QTAILQ) subregions, subregions_link, subregions_link. That is, a MemoryRegion can contain multiple memory areas, depending on the parameters to distinguish between the function of the memory domain. Before using MemoryRegion first assigned memory space and call memory_region_init do the necessary initialization. BIOS is also indicated by a MemoryRegion structure. It MemoryRegion.name is set to "pc.bios", size is set to BIOS file size (an integer multiple of 65536). Then off with rom_add_file_fixed will load its BIOS rom file into a global queue.

Finally, back to old_pc_system_rom_init function in the BIOS memory-mapped at the top of the address space.

Listing 6. It will function BIOS old_pc_system_rom_init mapped to the physical memory space code:

hw / i386 / pc_sysfw.c:
    memory_region_add_subregion (rom_memory,
        (Uint32_t) (- bios_size) bios);
(Uint32_t) (- bios_size) is a 32-bit unsigned number, so -bios_size corresponding address is FFFFFFFF lose bios_size size. bios size size ./pc-bios/bios.bin = 131072 (128KB) byte, hexadecimal as 0x20000, so bios location in memory for bios position = fffe0000, bios location in memory is 0xfffdffff ~ 0xffffffff BIOS now been added to the virtual machine's physical memory address space of.

Last call QEMU CPU reset function resets VCPU register value IP = 0x0000fff0, CS = 0xf000, CS.BASE = 0xffff0000, CS.LIMIT = 0xffff. Instructions from 0xfffffff0 begin, just start position ROM program. VM BIOS to find the entrance.


OF QEMU by reading the source code of the program, detailing the QEMU to use BIOS file, QEMU in representation of physical memory, and QEMU is a step by step how the BIOS binary loaded into the virtual machine created by QEMU memory the process of.
- Java Timer (regular calling, to achieve a fixed time to perform) (Programming)
- Linux, ls command to achieve (Linux)
- MySQL 5.5 on master-slave copy filter (Database)
- Ubuntu Gnome and Fedora 22 Gnome desktop, extended to achieve global menu (Linux)
- Easily create RPM packages using the FPM (Linux)
- How to use the command line ftp upload and download files (Linux)
- Firewall types and instructions (Linux)
- Ubuntu 14.04 install Nmap 6.46.1 (Linux)
- The most common and most effective security settings under linux (Linux)
- Ubuntu 14.04 modify environment variables (Linux)
- PostgreSQL transaction model introduction (Database)
- Spacewalk Linux system configuration and installation (Linux)
- DataGuard add temporary data files bug (Database)
- Zabbix API and PHP configuration (Server)
- Linux Log (Linux)
- Summary Linux bond of multi-interface load balancing (Linux)
- Configuring Haproxy log support (syslog logging support) (Server)
- Linux find command usage summary (Linux)
- Efficient Linux Shell - Shell special characters Summary (Linux)
- How to disable IPv6 in the CentOS 7 (Linux)
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.