Home IT Linux Windows Database Network Programming Server Mobile  
  Home \ Linux \ QEMU code analysis: BIOS loading process     - Advanced Search Oracle study notes (Database)

- Use XtraBackup to MySQL database online incremental backup and recovery (Database)

- MySQL root password reset under CentOS (Database)

- ELKstack log analysis platform (Server)

- Ubuntu is not in the sudoers file problem solving (Linux)

- Oracle background processes daemons (Database)

- Configuring automatic mail GAMIT under CentOS system (Linux)

- Based kubernetes Construction Docker Cluster Management Comments (Server)

- Single-node Hadoop installation notes distributed pseudo & (Server)

- Linux cron job (Linux)

- Use Oracle 11g show spparameter command (Database)

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

- Ubuntu install Liferea news subscription software (Linux)

- Ubuntu users how to install the latest Nvidia graphics drivers (Linux)

- CentOS 7 install Hadoop-cdh-2.6 (Server)

- Linux FTP setting file description (Server)

- expdp reported ORA-39181 Export Processing Method (Database)

- Linux operating system to solve a serious fault handling (Linux)

- JavaScript prototype and the prototype chain (Programming)

- Retro terminal in Linux (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.
- To create a secure network firewall with iptables Under Linux (Linux)
- RPM package management under Linux (Linux)
- About Samba certification process and permissions (Linux)
- Ubuntu install snmp packets Unlinked OID in IPATM-IPMC-MIB: marsMIB (Linux)
- Mhddfs: multiple smaller partitions into one large virtual storage (Linux)
- Git Rebase Tutorial: Using Git Rebase turn back the clock (Linux)
- Hard disk encryption to protect data security (Linux)
- MySQL5.6 based GTID master-slave replication (Database)
- How to create a cloud encrypted file system in Linux systems (Linux)
- For the FreeBSD install Adobe Flash plug-in (Linux)
- init level settings for Linux / etc / inittab file into six (restart) or does not support the level of solution (Linux)
- Docker use Dockerfile created since the launch of the service support SSH container mirror (Server)
- Python 3.5 will support Async / Await Asynchronous Programming (Programming)
- CentOS yum source configuration (Linux)
- Rman Oracle database backup and recovery plan (Database)
- Nine tips to protect the security of Linux desktop (Linux)
- Virtualization and IT cooperation (Linux)
- Linux Network Programming --epoll model Detailed principles and examples (Programming)
- FFmpeg compiled with only H264 decoding library (Programming)
- Json Applications of FastJson (Programming)
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.