注册 登录  
 加关注
查看详情
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

天道酬勤 玩物丧志

用勇气去改变可以改变的事情,用胸怀去包容无法改变的事情,用智慧去判断两者的区别

 
 
 

日志

 
 

【转载】qemu源码分析-添加默认虚拟设备(以串口为例)  

2016-06-25 20:45:54|  分类: 嵌入式系统 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
在vl.c中的main函数:

 if (display_type == DT_NOGRAPHIC) {
        if (default_parallel)
            add_device_config(DEV_PARALLEL, "null");
        if (default_serial && default_monitor) {
            add_device_config(DEV_SERIAL, "mon:stdio");//没有
        } else if (default_virtcon && default_monitor) {
            add_device_config(DEV_VIRTCON, "mon:stdio");
        } else {
            if (default_serial)
                add_device_config(DEV_SERIAL, "stdio");
            if (default_virtcon)
                add_device_config(DEV_VIRTCON, "stdio");
            if (default_monitor)
                monitor_parse("stdio", "readline");
        }
    } else {
        if (default_serial)//default serial
            add_device_config(DEV_SERIAL, "vc:80Cx24C");
        if (default_parallel)//default parallel
            add_device_config(DEV_PARALLEL, "vc:80Cx24C");
        if (default_monitor)
            monitor_parse("vc:80Cx24C", "readline");
        if (default_virtcon)
            add_device_config(DEV_VIRTCON, "vc:80Cx24C");
    }



  if (foreach_device_config(DEV_SERIAL, serial_parse) < 0)
        exit(1);
  if (foreach_device_config(DEV_PARALLEL, parallel_parse) < 0)
        exit(1);
函数原型:static int foreach_device_config(int type, int (*func)(const char *cmdline))
struct device_config {
    enum {
        DEV_USB,       /* -usbdevice     */
        DEV_BT,        /* -bt            */
        DEV_SERIAL,    /* -serial        */
        DEV_PARALLEL,  /* -parallel      */
        DEV_VIRTCON,   /* -virtioconsole */
        DEV_DEBUGCON,  /* -debugcon */
        DEV_GDB,       /* -gdb, -s */
    } type;
    const char *cmdline;
    Location loc;
    QTAILQ_ENTRY(device_config) next;
};
QTAILQ_HEAD(, device_config) device_configs = QTAILQ_HEAD_INITIALIZER(device_configs);

相关定义:
static int default_serial = 1;
static int default_parallel = 1;

默认设备列表:
static struct {
    const char *driver;
    int *flag;
} default_list[] = {
    { .driver = "isa-serial",           .flag = &default_serial    },
    { .driver = "isa-parallel",         .flag = &default_parallel  },
    { .driver = "isa-fdc",              .flag = &default_floppy    },
    { .driver = "ide-cd",               .flag = &default_cdrom     },
    { .driver = "ide-hd",               .flag = &default_cdrom     },
    { .driver = "ide-drive",            .flag = &default_cdrom     },
    { .driver = "scsi-cd",              .flag = &default_cdrom     },
    { .driver = "virtio-serial-pci",    .flag = &default_virtcon   },
    { .driver = "virtio-serial-s390",   .flag = &default_virtcon   },
    { .driver = "virtio-serial",        .flag = &default_virtcon   },
    { .driver = "VGA",                  .flag = &default_vga       },
    { .driver = "isa-vga",              .flag = &default_vga       },
    { .driver = "cirrus-vga",           .flag = &default_vga       },
    { .driver = "isa-cirrus-vga",       .flag = &default_vga       },
    { .driver = "vmware-svga",          .flag = &default_vga       },
    { .driver = "qxl-vga",              .flag = &default_vga       },
};

/*串口数最大限制*/
#define MAX_SERIAL_PORTS 4
CharDriverState *serial_hds[MAX_SERIAL_PORTS];
/*并口数最大限制*/
#define MAX_PARALLEL_PORTS 3

CharDriverState *parallel_hds[MAX_PARALLEL_PORTS];


将串口重定向到TCP端口:

vl.c中的main函数 ->foreach_device_config(DEV_SERIAL,serial_parse)->serial_parse()->qemu_chr_new()->qemu_chr_parse_compat->qemu_chr_parse_compat->opts_do_parse


serial_parse()->qemu_chr_new_from_opts()->chr = backend_table[i].open(opts);初始化socket->qemu_chr_open_socket()对socket进 行处理。

P.S:打印信息
serial---/root/work/qemu/qemu-1.2.0/vl.c:main:2957---command-parameters="tcp::3333,server,nowait"-----commond parameters parse and add to device list
serial------/root/work/qemu/qemu-1.2.0/vl.c:main:3592----start to call" foreach_device_config(DEV_SERIAL, serial_parse)  "
serial------/root/work/qemu/qemu-1.2.0/vl.c:foreach_device_config:2048---conf-cmdline="tcp::3333,server,nowait" call the callback-fun:serial_parse
serial-----/root/work/qemu/qemu-1.2.0/vl.c:serial_parse:2069----label = serial0, devname = tcp::3333,server,nowait
serial-----qemu-char.c:qemu_chr_new:2821----
serial-----qemu-char.c:qemu_chr_parse_compat:2601----to create device
serial------qemu-char.c:qemu_chr_new_from_opts:2766---to init serial & socket
serial-----qemu-char.c:qemu_chr_open_socket:2439---set socket
  评论这张
 
阅读(31)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018