Makefile for source code analysis of qemu

Source: Internet
Author: User

By analyzing qemu makefile, we can understand the organization of qemu code and the division of qemu functional modules. On the one hand, it helps to understand the design idea of qemu source code, and on the other hand, it helps to crop qemu code as needed, generate a streamlined qemu that meets the specified requirements.
To better understand the qemu makefile design, we recommend that you read the following two articles if you are not familiar with makefile syntax rules:
1. makefile Common Function Analysis
2. Write makefile with me

Bytes ----------------------------------------------------------------------------------------
/* Relationship Between qemu makefile dependency targets */
P, Li {white-space: Pre-wrap ;}

ALL: Build-All (1)

Build-ALL: $ (tools) recurse-All (2)

Recurse-ALL: $ (subdir_rules) $ (romsubdir_rules) (3)

P, Li {white-space: Pre-wrap; subdir_rules =$ (patsubst %, subdir-%, $ (target_dirs) (4)

Romsubdir_rules = $ (patsubst %, romsubdir-%, $ (roms) (5)

Subdir-%: $ (generated_headers) (6)

$ (Call quiet-command, $ (make) $ (subdir_makeflags)-C $ * V = "$ (v)" target_dir = "$ */" All ,)

Romsubdir-%: (7)

$ (Call quiet-command, $ (make) $ (subdir_makeflags)-c pc-bios/$ * V = "$ (v)" target_dir = "$ */",)

The above is the makefile of the simplified version of qemu. The following describes the meanings of the above rules in detail.
Bytes -------------------------------------------------------------------------------------------
P, Li {white-space: Pre-wrap ;}

Src_path =/home/src/qemu-0.15.1

Tools = qemu-ga qemu-NBD qemu-IMG qemu-IO/* Definition of tools in Rule (2 */

Target_dirs = Definition of target_dirs in i386-softmmu/* Rule (4 */

ROMs = optionrom/* Rule (5) romsubdir_rules definition */

Bytes --------------------------------------------------------------------------------------------

The most important rule in the preceding rule is the call of two functions: P, Li {white-space: Pre-wrap ;}

Subdir-%: $ (generated_headers)

$ (Call quiet-command, $ (make) $ (subdir_makeflags)-C $ * V = "$ (v)" target_dir = "$ */" All ,)

The above rules are equivalent:

Make -- no-print-directory-C i386-softmmu v = "" target_dir = "i386-softmmu/" All

Recall the common format of make-C:

Make-C path Parameter

The meaning of the above rule is: Execute the dependency target all in makefile under the i386-softmmu, the passed parameters are v = "" And target_dir = "i386-softmmu /"

Romsubdir-%:

$ (Call quiet-command, $ (make) $ (subdir_makeflags)-c pc-bios/$ * V = "$ (v)" target_dir = "$ */",)

Like the subdir-i386-softmmu, the above rule means to execute all the dependency targets under PC-bios/, passing the parameter V = "$ (V) "target_dir =" $ */", note that $ * indicates the name of the target file that does not contain the extension.

Since then, makefile has entered the i386-softmmu and PC-bios directory, execute the corresponding makfile

Bytes ---------------------------------------------------------------------------------------------

From the i386-softmmu/makefile can clearly find out which code completed qemu functional modules simulation.

1. Simulation of CPU function modules

  1. Libobj-y
    = Exec. O translate-all.o cpu-exec.o translate. o
  2. Libobj-y + = TCG/TCG. o
  3. Libobj-y + = FPU/softfloat. o
  4. Libobj-y + = op_helper.o helper. o
  5. Ifeq ($ (target_base_arch), i386)
  6. Libobj-y + = cpuid. o
  7. Endif
  8. Libobj-$ (config_need_mmu)
    + = MMU. o
  9. Libobj-$ (target_arm)
    + = Neon_helper.o iwmmxt_helper.o
  10. Libobj-y + = disas. o

2. Simulation of hardware devices

  1. # Hardware support
  2. Obj-i386-y
    + = VGA. o
  3. Obj-i386-y
    + = Mc146818rtc. O i8259.o PC. o
  4. Obj-i386-y
    + = Cirrus_vga.o SGA. o apic. O ioapic. O piix_pci.o
  5. Obj-i386-y
    + = Vmport. o
  6. Obj-i386-y
    + = Device-hotplug.o pci-hotplug.o smbios. o
    Wdt_ib700.o
  7. Obj-i386-y
    + = Debugcon. O multiboot. o
  8. Obj-i386-y
    + = Pc_piix.o
  9. Obj-i386-$ (maid)
    + = Kvmclock. o
  10. Obj-i386-$ (config_spice)
    + = Qxl. O qxl-logger.o qxl-render.o

3. platform-independent code in qemu (platform-shared code)

  1. Translate. O: translate. c CPU. h
  2. Translate-all.o: translate-all.c CPU. h
  3. TCG/TCG. O: CPU. h
  4. # Helper_cflags is used
    For all the Code Compiled with static register
  5. # VARIABLES
  6. Op_helper.o user-exec.o: qemu_cflags
    + =$ (Helper_cflags)
  7. # Note: This is a workaround. The real
    Fix is
    To avoid compiling
  8. # Cpu_signal_handler ()
    In user-exec.c.
  9. Signal. O: qemu_cflags
    + =$ (Helper_cflags)

4. KVM-related code

  1. OBJ-$ (config_kvm)
    + = KVM. O kvm-all.o
  2. OBJ-$ (config_no_kvm)
    + = Kvm-stub.o

According. /configure cannot be enabled by modules. This makefile also has other functional modules. The code corresponding to these functional modules is clearly displayed here, which can effectively improve the qemu code understanding and cropping efficiency.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.