⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vl.c

📁 qemu性能直逼VMware的仿真器QEMU 的模擬速度約為實機的 25%;約為 Bochs 的 60 倍。Plex86、User-Mode-Linux、VMware 和 Virtual PC 則比
💻 C
📖 第 1 页 / 共 5 页
字号:
/* * QEMU System Emulator *  * Copyright (c) 2003-2007 Fabrice Bellard *  * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */#include "vl.h"#include <unistd.h>#include <fcntl.h>#include <signal.h>#include <time.h>#include <errno.h>#include <sys/time.h>#include <zlib.h>#ifndef _WIN32#include <sys/times.h>#include <sys/wait.h>#include <termios.h>#include <sys/poll.h>#include <sys/mman.h>#include <sys/ioctl.h>#include <sys/socket.h>#include <netinet/in.h>#include <dirent.h>#include <netdb.h>#ifdef _BSD#include <sys/stat.h>#ifndef __APPLE__#include <libutil.h>#endif#else#ifndef __sun__#include <linux/if.h>#include <linux/if_tun.h>#include <pty.h>#include <malloc.h>#include <linux/rtc.h>#include <linux/ppdev.h>#endif#endif#endif#if defined(CONFIG_SLIRP)#include "libslirp.h"#endif#ifdef _WIN32#include <malloc.h>#include <sys/timeb.h>#include <windows.h>#define getopt_long_only getopt_long#define memalign(align, size) malloc(size)#endif#include "qemu_socket.h"#ifdef CONFIG_SDL#ifdef __APPLE__#include <SDL/SDL.h>#endif#endif /* CONFIG_SDL */#ifdef CONFIG_COCOA#undef main#define main qemu_main#endif /* CONFIG_COCOA */#include "disas.h"#include "exec-all.h"#define DEFAULT_NETWORK_SCRIPT "/etc/qemu-ifup"#ifdef __sun__#define SMBD_COMMAND "/usr/sfw/sbin/smbd"#else#define SMBD_COMMAND "/usr/sbin/smbd"#endif//#define DEBUG_UNUSED_IOPORT//#define DEBUG_IOPORT#define PHYS_RAM_MAX_SIZE (2047 * 1024 * 1024)#ifdef TARGET_PPC#define DEFAULT_RAM_SIZE 144#else#define DEFAULT_RAM_SIZE 128#endif/* in ms */#define GUI_REFRESH_INTERVAL 30/* Max number of USB devices that can be specified on the commandline.  */#define MAX_USB_CMDLINE 8/* XXX: use a two level table to limit memory usage */#define MAX_IOPORTS 65536const char *bios_dir = CONFIG_QEMU_SHAREDIR;char phys_ram_file[1024];void *ioport_opaque[MAX_IOPORTS];IOPortReadFunc *ioport_read_table[3][MAX_IOPORTS];IOPortWriteFunc *ioport_write_table[3][MAX_IOPORTS];/* Note: bs_table[MAX_DISKS] is a dummy block driver if none available   to store the VM snapshots */BlockDriverState *bs_table[MAX_DISKS + 1], *fd_table[MAX_FD];/* point to the block driver where the snapshots are managed */BlockDriverState *bs_snapshots;int vga_ram_size;int bios_size;static DisplayState display_state;int nographic;const char* keyboard_layout = NULL;int64_t ticks_per_sec;int boot_device = 'c';int ram_size;int pit_min_timer_count = 0;int nb_nics;NICInfo nd_table[MAX_NICS];QEMUTimer *gui_timer;int vm_running;int rtc_utc = 1;int cirrus_vga_enabled = 1;#ifdef TARGET_SPARCint graphic_width = 1024;int graphic_height = 768;#elseint graphic_width = 800;int graphic_height = 600;#endifint graphic_depth = 15;int full_screen = 0;int no_quit = 0;CharDriverState *serial_hds[MAX_SERIAL_PORTS];CharDriverState *parallel_hds[MAX_PARALLEL_PORTS];#ifdef TARGET_I386int win2k_install_hack = 0;#endifint usb_enabled = 0;static VLANState *first_vlan;int smp_cpus = 1;const char *vnc_display;#if defined(TARGET_SPARC)#define MAX_CPUS 16#elif defined(TARGET_I386)#define MAX_CPUS 255#else#define MAX_CPUS 1#endifint acpi_enabled = 1;int fd_bootchk = 1;int no_reboot = 0;int daemonize = 0;const char *option_rom[MAX_OPTION_ROMS];int nb_option_roms;int semihosting_enabled = 0;int autostart = 1;/***********************************************************//* x86 ISA bus support */target_phys_addr_t isa_mem_base = 0;PicState2 *isa_pic;uint32_t default_ioport_readb(void *opaque, uint32_t address){#ifdef DEBUG_UNUSED_IOPORT    fprintf(stderr, "inb: port=0x%04x\n", address);#endif    return 0xff;}void default_ioport_writeb(void *opaque, uint32_t address, uint32_t data){#ifdef DEBUG_UNUSED_IOPORT    fprintf(stderr, "outb: port=0x%04x data=0x%02x\n", address, data);#endif}/* default is to make two byte accesses */uint32_t default_ioport_readw(void *opaque, uint32_t address){    uint32_t data;    data = ioport_read_table[0][address](ioport_opaque[address], address);    address = (address + 1) & (MAX_IOPORTS - 1);    data |= ioport_read_table[0][address](ioport_opaque[address], address) << 8;    return data;}void default_ioport_writew(void *opaque, uint32_t address, uint32_t data){    ioport_write_table[0][address](ioport_opaque[address], address, data & 0xff);    address = (address + 1) & (MAX_IOPORTS - 1);    ioport_write_table[0][address](ioport_opaque[address], address, (data >> 8) & 0xff);}uint32_t default_ioport_readl(void *opaque, uint32_t address){#ifdef DEBUG_UNUSED_IOPORT    fprintf(stderr, "inl: port=0x%04x\n", address);#endif    return 0xffffffff;}void default_ioport_writel(void *opaque, uint32_t address, uint32_t data){#ifdef DEBUG_UNUSED_IOPORT    fprintf(stderr, "outl: port=0x%04x data=0x%02x\n", address, data);#endif}void init_ioports(void){    int i;    for(i = 0; i < MAX_IOPORTS; i++) {        ioport_read_table[0][i] = default_ioport_readb;        ioport_write_table[0][i] = default_ioport_writeb;        ioport_read_table[1][i] = default_ioport_readw;        ioport_write_table[1][i] = default_ioport_writew;        ioport_read_table[2][i] = default_ioport_readl;        ioport_write_table[2][i] = default_ioport_writel;    }}/* size is the word size in byte */int register_ioport_read(int start, int length, int size,                          IOPortReadFunc *func, void *opaque){    int i, bsize;    if (size == 1) {        bsize = 0;    } else if (size == 2) {        bsize = 1;    } else if (size == 4) {        bsize = 2;    } else {        hw_error("register_ioport_read: invalid size");        return -1;    }    for(i = start; i < start + length; i += size) {        ioport_read_table[bsize][i] = func;        if (ioport_opaque[i] != NULL && ioport_opaque[i] != opaque)            hw_error("register_ioport_read: invalid opaque");        ioport_opaque[i] = opaque;    }    return 0;}/* size is the word size in byte */int register_ioport_write(int start, int length, int size,                           IOPortWriteFunc *func, void *opaque){    int i, bsize;    if (size == 1) {        bsize = 0;    } else if (size == 2) {        bsize = 1;    } else if (size == 4) {        bsize = 2;    } else {        hw_error("register_ioport_write: invalid size");        return -1;    }    for(i = start; i < start + length; i += size) {        ioport_write_table[bsize][i] = func;        if (ioport_opaque[i] != NULL && ioport_opaque[i] != opaque)            hw_error("register_ioport_write: invalid opaque");        ioport_opaque[i] = opaque;    }    return 0;}void isa_unassign_ioport(int start, int length){    int i;    for(i = start; i < start + length; i++) {        ioport_read_table[0][i] = default_ioport_readb;        ioport_read_table[1][i] = default_ioport_readw;        ioport_read_table[2][i] = default_ioport_readl;        ioport_write_table[0][i] = default_ioport_writeb;        ioport_write_table[1][i] = default_ioport_writew;        ioport_write_table[2][i] = default_ioport_writel;    }}/***********************************************************/void cpu_outb(CPUState *env, int addr, int val){#ifdef DEBUG_IOPORT    if (loglevel & CPU_LOG_IOPORT)        fprintf(logfile, "outb: %04x %02x\n", addr, val);#endif        ioport_write_table[0][addr](ioport_opaque[addr], addr, val);#ifdef USE_KQEMU    if (env)        env->last_io_time = cpu_get_time_fast();#endif}void cpu_outw(CPUState *env, int addr, int val){#ifdef DEBUG_IOPORT    if (loglevel & CPU_LOG_IOPORT)        fprintf(logfile, "outw: %04x %04x\n", addr, val);#endif        ioport_write_table[1][addr](ioport_opaque[addr], addr, val);#ifdef USE_KQEMU    if (env)        env->last_io_time = cpu_get_time_fast();#endif}void cpu_outl(CPUState *env, int addr, int val){#ifdef DEBUG_IOPORT    if (loglevel & CPU_LOG_IOPORT)        fprintf(logfile, "outl: %04x %08x\n", addr, val);#endif    ioport_write_table[2][addr](ioport_opaque[addr], addr, val);#ifdef USE_KQEMU    if (env)        env->last_io_time = cpu_get_time_fast();#endif}int cpu_inb(CPUState *env, int addr){    int val;    val = ioport_read_table[0][addr](ioport_opaque[addr], addr);#ifdef DEBUG_IOPORT    if (loglevel & CPU_LOG_IOPORT)        fprintf(logfile, "inb : %04x %02x\n", addr, val);#endif#ifdef USE_KQEMU    if (env)        env->last_io_time = cpu_get_time_fast();#endif    return val;}int cpu_inw(CPUState *env, int addr){    int val;    val = ioport_read_table[1][addr](ioport_opaque[addr], addr);#ifdef DEBUG_IOPORT    if (loglevel & CPU_LOG_IOPORT)        fprintf(logfile, "inw : %04x %04x\n", addr, val);#endif#ifdef USE_KQEMU    if (env)        env->last_io_time = cpu_get_time_fast();#endif    return val;}int cpu_inl(CPUState *env, int addr){    int val;    val = ioport_read_table[2][addr](ioport_opaque[addr], addr);#ifdef DEBUG_IOPORT    if (loglevel & CPU_LOG_IOPORT)        fprintf(logfile, "inl : %04x %08x\n", addr, val);#endif#ifdef USE_KQEMU    if (env)        env->last_io_time = cpu_get_time_fast();#endif    return val;}/***********************************************************/void hw_error(const char *fmt, ...){    va_list ap;    CPUState *env;    va_start(ap, fmt);    fprintf(stderr, "qemu: hardware error: ");    vfprintf(stderr, fmt, ap);    fprintf(stderr, "\n");    for(env = first_cpu; env != NULL; env = env->next_cpu) {        fprintf(stderr, "CPU #%d:\n", env->cpu_index);#ifdef TARGET_I386        cpu_dump_state(env, stderr, fprintf, X86_DUMP_FPU);#else        cpu_dump_state(env, stderr, fprintf, 0);#endif    }    va_end(ap);    abort();}/***********************************************************//* keyboard/mouse */static QEMUPutKBDEvent *qemu_put_kbd_event;static void *qemu_put_kbd_event_opaque;static QEMUPutMouseEntry *qemu_put_mouse_event_head;static QEMUPutMouseEntry *qemu_put_mouse_event_current;void qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque){    qemu_put_kbd_event_opaque = opaque;    qemu_put_kbd_event = func;}QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,                                                void *opaque, int absolute,                                                const char *name){    QEMUPutMouseEntry *s, *cursor;    s = qemu_mallocz(sizeof(QEMUPutMouseEntry));    if (!s)        return NULL;    s->qemu_put_mouse_event = func;    s->qemu_put_mouse_event_opaque = opaque;    s->qemu_put_mouse_event_absolute = absolute;    s->qemu_put_mouse_event_name = qemu_strdup(name);    s->next = NULL;    if (!qemu_put_mouse_event_head) {        qemu_put_mouse_event_head = qemu_put_mouse_event_current = s;        return s;    }    cursor = qemu_put_mouse_event_head;    while (cursor->next != NULL)        cursor = cursor->next;    cursor->next = s;    qemu_put_mouse_event_current = s;    return s;}void qemu_remove_mouse_event_handler(QEMUPutMouseEntry *entry){    QEMUPutMouseEntry *prev = NULL, *cursor;    if (!qemu_put_mouse_event_head || entry == NULL)        return;    cursor = qemu_put_mouse_event_head;    while (cursor != NULL && cursor != entry) {        prev = cursor;        cursor = cursor->next;    }    if (cursor == NULL) // does not exist or list empty        return;    else if (prev == NULL) { // entry is head        qemu_put_mouse_event_head = cursor->next;        if (qemu_put_mouse_event_current == entry)            qemu_put_mouse_event_current = cursor->next;        qemu_free(entry->qemu_put_mouse_event_name);        qemu_free(entry);        return;    }    prev->next = entry->next;    if (qemu_put_mouse_event_current == entry)        qemu_put_mouse_event_current = prev;    qemu_free(entry->qemu_put_mouse_event_name);    qemu_free(entry);}void kbd_put_keycode(int keycode){    if (qemu_put_kbd_event) {        qemu_put_kbd_event(qemu_put_kbd_event_opaque, keycode);    }}void kbd_mouse_event(int dx, int dy, int dz, int buttons_state){    QEMUPutMouseEvent *mouse_event;    void *mouse_event_opaque;    if (!qemu_put_mouse_event_current) {        return;    }    mouse_event =        qemu_put_mouse_event_current->qemu_put_mouse_event;    mouse_event_opaque =        qemu_put_mouse_event_current->qemu_put_mouse_event_opaque;    if (mouse_event) {        mouse_event(mouse_event_opaque, dx, dy, dz, buttons_state);    }}int kbd_mouse_is_absolute(void){    if (!qemu_put_mouse_event_current)        return 0;    return qemu_put_mouse_event_current->qemu_put_mouse_event_absolute;}void do_info_mice(void){    QEMUPutMouseEntry *cursor;    int index = 0;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -