Qemu-system mode emulation analysis (2)

Source: Internet
Author: User

2. Machine management under System mode

QEMU sytem Mode Simulation of the entire hardware platform, the core of the hardware platform is what we often say the board, the PC is often said to be the motherboard, which includes the main elements such as CPU, ROM space, RAM space, etc., and here is said machine is the simulation of this level of machines.


2.1 Machine Data structure

QEMU provides a general-purpose qemumachine structure to describe machine, adding a machine that simply instantiates the data structure in the machine's own file. The most important thing to instantiate is to register your own initialization function in the data structure.

1) Universal Interface

Location: Hw/boards.h

typedef struct QEMUMACHINE {    const char *name;    const char *alias;    const char *DESC;            Description    Qemumachineinitfunc *init;   Machine init function,[board]_init    int use_scsi;         Use SCSI standard    int max_cpus;    unsigned int no_serial:1,        no_parallel:1,        use_virtcon:1,        no_vga:1,        no_floppy:1,        no_cdrom : 1,        no_sdcard:1;    int is_default;          Mark as default machine    Globalproperty *compat_props;    struct Qemumachine *next;  Point to the machine list in the next machine} Qemumachine;

2) instantiation of the interface

For example, one of arm's boards is instantiated as follows:

Static Qemumachine Integratorcp_machine = {    . Name = "INTEGRATORCP",    . desc = "ARM integrator/cp (arm926ej-s)", 
   .init = Integratorcp_init,    . Is_default = 1,};

2. 2 Machine related Interfaces1) interfaces that need to be implemented

Qemumachine [Board]_machine

Describe the data structure of machine

Macro Machine_init ([Board]_machine_init)

Main before registering [Board]_machine_init function

[Board]_machine_init

Machine Registration function

[Board]_init

Machine initialization function




2) Calling the common interface

int Qemu_register_machine (Qemumachine *m)

Register the current machine in the machine list

Cpu_init (const char *cpu_model)

CPU Initialization

am_addr_t Qemu_ram_alloc (devicestate *dev, const char *name, ram_addr_t size)

Request RAM Space

staticinline void Cpu_register_physical_memory (Target_phys_addr_tstart_addr, ram_addr_tsize, ram_addr_t Phys_offset

Paging to the requested memory space

Devicestate *qdev_create (busstate *bus, const char *name)

Create a Device

void Qdev_init_nofail (Devicestate *dev)

Device initialization via Hw_error () End Program

int Qdev_init (devicestate *dev)

Device initialization, called by Qdev_init_nofail

void Qdev_prop_set (Devicestate *dev, const char *name, void *src, enum PropertyType type)

Device property settings

void Sysbus_mmio_map (Sysbusdevice *dev, int n, target_phys_addr_t addr)

IO address mapping

Devicestate *sysbus_create_varargs (const char *name, target_phys_addr_t addr, ...)

Hook up the device on the bus and complete the creation, initialization, address mapping and interrupt initialization of the device.

Static inline Devicestate *sysbus_create_simple (const char *name, target_phys_addr_taddr,

QEMU_IRQ IRQ)

Sysbus_create_varargs shortcut, call this function when the device has only one corresponding interrupt number

Qemu_irq qdev_get_gpio_in (devicestate *dev, int n)


2.3 Machine Registration

It is known that in Qemu, there are two linked lists related to machine, Init_type_list[module_init_machine] and machine linked lists, respectively.

1) The linked list indicated by Init_type_list[module_init_machine] records the machine's registration function, and its data structure is as follows:

Files: module.c

Static moduletypelist init_type_list[module_init_max];typedef struct moduleentry{    module_init_type type;    Linked list type    void (*init) (void);   Machine's registration function    qtailq_entry (moduleentry) node;} moduleentry;module.h typedef enum {    Module_init_block,    module_init_device,    module_init_machine,    Module_init_max} module_init_type;

After the linked list is formed:

2) Machine chain list

As shown in the machine list structure, the node data structure is Qemumachine, where the init member records the machine's initialization function, and the next member points to the next machine.

The following describes the creation of the two linked lists, respectively.

2.3.1 Init_type_list[module_init_machine] Generation

Machine requires the implementation of the Macro interface Machine_init (func), Func is the registration function of machine. The processing flow of Machine_init (func) is as follows:



The compiler processes all machine_init and generates a linked list that is indicated by Init_type_list[module_init_machine].

2.3.2 Machine Chain list generation

The main function uses Module_call_init (module_init_machine) to invoke the initialization function for each node in init_type_list[module_init_machine] [board]_machine_ Init to register the machine data structure of each node corresponding to the machine queue. The process is as shown.

Through the process shown, the machine list is generated in QEMU and the basic information for each machine is recorded.

With the basic information of each machine, the specified machine can be initialized at run time according to the-machine parameter. When the-machine parameter is not present, the default machine is used as the Development Board to run. The initialization function of the selected machine is then called. The machine initialization process is described in the following section.


2.4 Machine Initialization

This paper introduces the initialization process of machine using ARM's INTEGRATOR/CP Development board as an example.



Both the bus and the interrupt controller can be seen as devices, the device creation process and how the device connects the bus will be introduced in the device mechanism.


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Qemu-system mode emulation analysis (2)

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.