Home IT Linux Windows Database Network Programming Server Mobile  
           
  Home \ Linux \ QEMU code analysis: BIOS loading process     - CUDA (including GPU card driver) installation process under Ubuntu (Linux)

- Android Sets the system screen brightness (Programming)

- Shuffle Process Arrangement in MapReduce (Server)

- Ubuntu apt-mirror established local private sources (Linux)

- Ubuntu System Log Configuration / var / log / messages (Linux)

- Oracle GoldenGate tutorial Second, configure and use (Database)

- xCAT error Unable to dispatch hierarchical sub-command to NORESOLUTION: 3001 (Linux)

- grep command Series: How to Use the grep command in Linux / UNIX (Linux)

- Linux system components Detailed log (Linux)

- Sort search algorithm Java - application examples with recursive dichotomy (Programming)

- Terminal fun: 6 interesting Linux command-line tools (Linux)

- Ubuntu comes with gedit editor to add Markdown preview widget (Linux)

- How to achieve the MySQL Oracle table associated with the two operations update (Database)

- Binary Tree Traversal (Linux)

- Ubuntu installation 2.10.x version of Scala (Linux)

- Oracle 11g manually create a database (Database)

- Taught you how to install Ubuntu Linux (Linux)

- Oracle ORA-01089 failure analysis (Database)

- A list of the basics of Python, Ganso, Dictionary (Programming)

- Binder began to talk about inter-process communication mechanism from Android AIDL (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
 vgabios-vmware.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)"; \
        done
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.

summary

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.
     
         
       
         
  More:      
 
- Nginx high concurrency optimization ideas (Server)
- Linux screen commonly commands (Linux)
- Linux command execution order control and pipeline (Linux)
- PHP security Programming Advice (Programming)
- Under CentOS using yum command to install the Task Scheduler crontab (Linux)
- Build your own Web server under Ubuntu Linux system (Server)
- ntop monitoring software configuration and installation (Linux)
- After you change the GRUB boot disk partition repair (Linux)
- Bash added to the Vi mode indicator (Linux)
- Cygwin install Python MySQLdb (Linux)
- Linux System Getting Started Learning: In RedHat Linux driver compiled Ixgbe (Linux)
- UNIX file permissions in the "set user ID bit" (Linux)
- Linux firewall settings -DNS server articles (Server)
- Effective Java - lazy initialization (Programming)
- The wrong in Linux: too many open files (Linux)
- Linux Security and Optimization (Linux)
- sa weak passwords intrusion prevention (Linux)
- Udev: Device Manager for Linux Fundamentals (Linux)
- CentOS 6.5_x64 install Oracle 11g R2 (Database)
- Boot automatically remove Linux operating history records (Linux)
     
           
     
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.