qemu1.4.0源码阅读笔记————vl.c阅读

 

最近在研究qemu的用法,在次做一些笔记,希望大家批评指正,多做交流。

 

vl.c main函数内容记录:

 

进入main函数:

 

2846   

         module_call_init(MODULE_INIT_QOM);——————————以MODULE_INIT_QOM类型,对各个调用的模块初始化

进入module_call_init (type=MODULE_INIT_QOM) at util/module.c:72

typedef enum {

    MODULE_INIT_BLOCK,

    MODULE_INIT_MACHINE,

    MODULE_INIT_QAPI,

    MODULE_INIT_QOM,

    MODULE_INIT_MAX

} module_init_type;

 

static ModuleTypeList *find_type(module_init_type type)

{

    ModuleTypeList *l;

    init_types();

    l = &init_type_list[type];

    return l;

}

 

2848

    qemu_add_opts(&qemu_drive_opts);——————————————获取各种需要的参数

    qemu_add_opts(&qemu_chardev_opts);

    qemu_add_opts(&qemu_device_opts);

    qemu_add_opts(&qemu_netdev_opts);

    qemu_add_opts(&qemu_net_opts);

    qemu_add_opts(&qemu_rtc_opts);

    qemu_add_opts(&qemu_global_opts);

    qemu_add_opts(&qemu_mon_opts);

    qemu_add_opts(&qemu_trace_opts);

    qemu_add_opts(&qemu_option_rom_opts);

    qemu_add_opts(&qemu_machine_opts);

    qemu_add_opts(&qemu_boot_opts);

    qemu_add_opts(&qemu_sandbox_opts);

    qemu_add_opts(&qemu_add_fd_opts);

    qemu_add_opts(&qemu_object_opts);

 

void qemu_add_opts(QemuOptsList *list)    ——————————————获取各种需要的参数

{

    int entries, i;

    entries = ARRAY_SIZE(vm_config_groups);

    entries--; /* keep list NULL terminated */

    for (i = 0; i < entries; i++) {

        if (vm_config_groups[i] == NULL) {

            vm_config_groups[i] = list;

            return;

        }

    }

    fprintf(stderr, "ran out of space in vm_config_groups");

    abort();

}

 

struct QemuOptsList {

    const char *name;

    const char *implied_opt_name;

    bool merge_lists;  /* Merge multiple uses of option into a single list? */

    QTAILQ_HEAD(, QemuOpts) head;

    QemuOptDesc desc[];

};

 

 

2864     runstate_init();————————————对运行状态进行初始化( vl.c

 522 /***********************************************************/

 523 /* QEMU state */

 524

 525 static RunState current_run_state = RUN_STATE_PRELAUNCH;

 526

 527 typedef struct {

 528     RunState from;

 529     RunState to;

 530 } RunStateTransition;

 531

 532 static const RunStateTransition runstate_transitions_def[] = {

 533     /*     from      ->     to      */

 534     { RUN_STATE_DEBUG, RUN_STATE_RUNNING },

 535

 536     { RUN_STATE_INMIGRATE, RUN_STATE_RUNNING },

 537     { RUN_STATE_INMIGRATE, RUN_STATE_PAUSED },

 538

 539     { RUN_STATE_INTERNAL_ERROR, RUN_STATE_PAUSED },

 540     { RUN_STATE_INTERNAL_ERROR, RUN_STATE_FINISH_MIGRATE },

 541

 542     { RUN_STATE_IO_ERROR, RUN_STATE_RUNNING },

 543     { RUN_STATE_IO_ERROR, RUN_STATE_FINISH_MIGRATE },

 544

 545     { RUN_STATE_PAUSED, RUN_STATE_RUNNING },

 546     { RUN_STATE_PAUSED, RUN_STATE_FINISH_MIGRATE },

 547

 548     { RUN_STATE_POSTMIGRATE, RUN_STATE_RUNNING },

 549     { RUN_STATE_POSTMIGRATE, RUN_STATE_FINISH_MIGRATE },

 550

 551     { RUN_STATE_PRELAUNCH, RUN_STATE_RUNNING },

 552     { RUN_STATE_PRELAUNCH, RUN_STATE_FINISH_MIGRATE },

 553     { RUN_STATE_PRELAUNCH, RUN_STATE_INMIGRATE },

 554

 555     { RUN_STATE_FINISH_MIGRATE, RUN_STATE_RUNNING },

 556     { RUN_STATE_FINISH_MIGRATE, RUN_STATE_POSTMIGRATE },

 557

 558     { RUN_STATE_RESTORE_VM, RUN_STATE_RUNNING },

 559

 560     { RUN_STATE_RUNNING, RUN_STATE_DEBUG },

 561     { RUN_STATE_RUNNING, RUN_STATE_INTERNAL_ERROR },

 562     { RUN_STATE_RUNNING, RUN_STATE_IO_ERROR },

 563     { RUN_STATE_RUNNING, RUN_STATE_PAUSED },

 564     { RUN_STATE_RUNNING, RUN_STATE_FINISH_MIGRATE },

 565     { RUN_STATE_RUNNING, RUN_STATE_RESTORE_VM },

 566     { RUN_STATE_RUNNING, RUN_STATE_SAVE_VM },

 567     { RUN_STATE_RUNNING, RUN_STATE_SHUTDOWN },

 568     { RUN_STATE_RUNNING, RUN_STATE_WATCHDOG },

 569

 570     { RUN_STATE_SAVE_VM, RUN_STATE_RUNNING },

 571

 572     { RUN_STATE_SHUTDOWN, RUN_STATE_PAUSED },

 573     { RUN_STATE_SHUTDOWN, RUN_STATE_FINISH_MIGRATE },

 574

 575     { RUN_STATE_DEBUG, RUN_STATE_SUSPENDED },

 576     { RUN_STATE_RUNNING, RUN_STATE_SUSPENDED },

 577     { RUN_STATE_SUSPENDED, RUN_STATE_RUNNING },

 578     { RUN_STATE_SUSPENDED, RUN_STATE_FINISH_MIGRATE },

 579

 580     { RUN_STATE_WATCHDOG, RUN_STATE_RUNNING },

 581     { RUN_STATE_WATCHDOG, RUN_STATE_FINISH_MIGRATE },

 582

 583     { RUN_STATE_MAX, RUN_STATE_MAX },

 584 };

 

 

2866                                  

    init_clocks();——————————————————初始化guest的时钟为host的时钟:

    rtc_clock = host_clock;

 

2874

    module_call_init(MODULE_INIT_MACHINE);————以MODULE_INIT_MACHINE类型进行模块调用初始化

 

2875

    machine = find_default_machine();

 

2894     while (optind < argc) {————————————第一次遍历命令行参数

 

2916

    ret = qemu_read_default_config_files(userconfig);——————————读取用户默认配置:

 qemu_read_default_config_files (userconfig=true)

    at /home/robin/workspace/qemu_workspace/debug/qemu-1.4.0/arch_init.c:150

 默认配置文件的位置定义如下两个,我发现与自己机器的不符合,是不是要添加自己的在下面呢???????

 142 default_config_files[] = {——————————————arch_init.c

 143     { CONFIG_QEMU_CONFDIR "/qemu.conf",                   true },

 144     { CONFIG_QEMU_CONFDIR "/target-" TARGET_ARCH ".conf", true },

 145     { NULL }, /* end of list */

 146 };

./config-host.h:2:#define CONFIG_QEMU_CONFDIR "/usr/local/etc/qemu"

./config-host.h-timestamp:2:#define CONFIG_QEMU_CONFDIR "/usr/local/etc/qemu"

 

158

    ret = qemu_read_config_file(f->filename);

qemu_read_config_file (filename=0x80510bbc "/usr/local/etc/qemu/qemu.conf") at util/qemu-config.c:199

 

2924    

         for(;;) {——————————————第二次遍历命令行参数

 

 3814    

         loc_set_none();

 

3854    

         cpudef_init();————————cpu的初始化

 

 3994

    socket_init();—————————初始化socket

 

初始化cpu_loop:

4055

    qemu_init_cpu_loop();

 

你可能感兴趣的:(开源项目学习,QEMU)