Home IT Linux Windows Database Network Programming Server Mobile  
  Home \ Linux \ QEMU code analysis: BIOS loading process     - How to create a someone project on github (Linux)

- AFNetworking + Nginx HTTPS communication server + (Server)

- Java Network Programming Internet address lookup (Programming)

- Linux maximum number of threads and limit the number of queries the current thread (Linux)

- Zabbix API and PHP configuration (Server)

- Linux kernel compilation, the configuration of the motor drive (Programming)

- Java environment to build a number of issues (Linux)

- How to build Mono 3.4.0 / 3.4.1 on Windows (Linux)

- Java, hashcode, equals and == (Programming)

- To compile install and test Swift under Linux (Linux)

- Ubuntu: HDF5 error: HDF5 header version does not match with the HDF5 library (Linux)

- STL spatial Configurator (Programming)

- Getting Started with Linux system to learn: how to install autossh (Linux)

- Linux 64-bit porting (Programming)

- PHP CURL get cookies simulated login (Database)

- Cancel Root Command History under Linux (Linux)

- Git version rollback (Linux)

- RHEL6 install Python and other packages from source (Linux)

- DataGuard add temporary data files bug (Database)

- Workspace Go language and environment variables GOPATH (Linux)

  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.
- You must ask yourself four questions before deploying Docker (Server)
- Android custom controls create the simplest skid menu in the history (Programming)
- Initialization and starting process of Linux (Linux)
- Linux asynchronous read documents by AIO (Programming)
- Linux Mint under tty.js Installation Guide (Linux)
- Ubuntu users to install Xtreme Download Manager (Linux)
- Oracle Standby Redo Log experiment (Database)
- Ubuntu user use PPA to install Uget 2.0.5 (Linux)
- Linux security settings Notes (Linux)
- CentOS 6.5 installation VNCServer implement graphical access (Server)
- To setup CentOS LAMP environment (Server)
- SELinux security permissions HTTP + PHP service changes (Server)
- Which file system is most suitable for your Linux system (Linux)
- In addition to wget and curl, what better alternatives (Linux)
- CentOS yum source configuration (Linux)
- Lenovo Ultrabooks Ubuntu system can not open the wireless hardware switch solutions (Linux)
- CentOS 6.5 / Linux restart network card being given Determining if ip address x.x.x.x is already in use (Linux)
- Linux based serial programming (Programming)
- AngularJS application unit testing started (Programming)
- Usage of sudo (Linux)
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.