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

📄 monitor.c

📁 qemu性能直逼VMware的仿真器QEMU 的模擬速度約為實機的 25%;約為 Bochs 的 60 倍。Plex86、User-Mode-Linux、VMware 和 Virtual PC 則比
💻 C
📖 第 1 页 / 共 5 页
字号:
    if (prot != prot1) {        if (*pstart != -1) {            term_printf("%08x-%08x %08x %c%c%c\n",                        *pstart, end, end - *pstart,                         prot1 & PG_USER_MASK ? 'u' : '-',                        'r',                        prot1 & PG_RW_MASK ? 'w' : '-');        }        if (prot != 0)            *pstart = end;        else            *pstart = -1;        *plast_prot = prot;    }}static void mem_info(void){    CPUState *env;    int l1, l2, prot, last_prot;    uint32_t pgd, pde, pte, start, end;    env = mon_get_cpu();    if (!env)        return;    if (!(env->cr[0] & CR0_PG_MASK)) {        term_printf("PG disabled\n");        return;    }    pgd = env->cr[3] & ~0xfff;    last_prot = 0;    start = -1;    for(l1 = 0; l1 < 1024; l1++) {        cpu_physical_memory_read(pgd + l1 * 4, (uint8_t *)&pde, 4);        pde = le32_to_cpu(pde);        end = l1 << 22;        if (pde & PG_PRESENT_MASK) {            if ((pde & PG_PSE_MASK) && (env->cr[4] & CR4_PSE_MASK)) {                prot = pde & (PG_USER_MASK | PG_RW_MASK | PG_PRESENT_MASK);                mem_print(&start, &last_prot, end, prot);            } else {                for(l2 = 0; l2 < 1024; l2++) {                    cpu_physical_memory_read((pde & ~0xfff) + l2 * 4,                                              (uint8_t *)&pte, 4);                    pte = le32_to_cpu(pte);                    end = (l1 << 22) + (l2 << 12);                    if (pte & PG_PRESENT_MASK) {                        prot = pte & (PG_USER_MASK | PG_RW_MASK | PG_PRESENT_MASK);                    } else {                        prot = 0;                    }                    mem_print(&start, &last_prot, end, prot);                }            }        } else {            prot = 0;            mem_print(&start, &last_prot, end, prot);        }    }}#endifstatic void do_info_kqemu(void){#ifdef USE_KQEMU    CPUState *env;    int val;    val = 0;    env = mon_get_cpu();    if (!env) {        term_printf("No cpu initialized yet");        return;    }    val = env->kqemu_enabled;    term_printf("kqemu support: ");    switch(val) {    default:    case 0:        term_printf("disabled\n");        break;    case 1:        term_printf("enabled for user code\n");        break;    case 2:        term_printf("enabled for user and kernel code\n");        break;    }#else    term_printf("kqemu support: not compiled\n");#endif} #ifdef CONFIG_PROFILERint64_t kqemu_time;int64_t qemu_time;int64_t kqemu_exec_count;int64_t dev_time;int64_t kqemu_ret_int_count;int64_t kqemu_ret_excp_count;int64_t kqemu_ret_intr_count;static void do_info_profile(void){    int64_t total;    total = qemu_time;    if (total == 0)        total = 1;    term_printf("async time  %" PRId64 " (%0.3f)\n",                dev_time, dev_time / (double)ticks_per_sec);    term_printf("qemu time   %" PRId64 " (%0.3f)\n",                qemu_time, qemu_time / (double)ticks_per_sec);    term_printf("kqemu time  %" PRId64 " (%0.3f %0.1f%%) count=%" PRId64 " int=%" PRId64 " excp=%" PRId64 " intr=%" PRId64 "\n",                kqemu_time, kqemu_time / (double)ticks_per_sec,                kqemu_time / (double)total * 100.0,                kqemu_exec_count,                kqemu_ret_int_count,                kqemu_ret_excp_count,                kqemu_ret_intr_count);    qemu_time = 0;    kqemu_time = 0;    kqemu_exec_count = 0;    dev_time = 0;    kqemu_ret_int_count = 0;    kqemu_ret_excp_count = 0;    kqemu_ret_intr_count = 0;#ifdef USE_KQEMU    kqemu_record_dump();#endif}#elsestatic void do_info_profile(void){    term_printf("Internal profiler not compiled\n");}#endif/* Capture support */static LIST_HEAD (capture_list_head, CaptureState) capture_head;static void do_info_capture (void){    int i;    CaptureState *s;    for (s = capture_head.lh_first, i = 0; s; s = s->entries.le_next, ++i) {        term_printf ("[%d]: ", i);        s->ops.info (s->opaque);    }}static void do_stop_capture (int n){    int i;    CaptureState *s;    for (s = capture_head.lh_first, i = 0; s; s = s->entries.le_next, ++i) {        if (i == n) {            s->ops.destroy (s->opaque);            LIST_REMOVE (s, entries);            qemu_free (s);            return;        }    }}#ifdef HAS_AUDIOint wav_start_capture (CaptureState *s, const char *path, int freq,                       int bits, int nchannels);static void do_wav_capture (const char *path,                            int has_freq, int freq,                            int has_bits, int bits,                            int has_channels, int nchannels){    CaptureState *s;    s = qemu_mallocz (sizeof (*s));    if (!s) {        term_printf ("Not enough memory to add wave capture\n");        return;    }    freq = has_freq ? freq : 44100;    bits = has_bits ? bits : 16;    nchannels = has_channels ? nchannels : 2;    if (wav_start_capture (s, path, freq, bits, nchannels)) {        term_printf ("Faied to add wave capture\n");        qemu_free (s);    }    LIST_INSERT_HEAD (&capture_head, s, entries);}#endifstatic term_cmd_t term_cmds[] = {    { "help|?", "s?", do_help,       "[cmd]", "show the help" },    { "commit", "s", do_commit,       "device|all", "commit changes to the disk images (if -snapshot is used) or backing files" },    { "info", "s?", do_info,      "subcommand", "show various information about the system state" },    { "q|quit", "", do_quit,      "", "quit the emulator" },    { "eject", "-fB", do_eject,      "[-f] device", "eject a removable media (use -f to force it)" },    { "change", "BF", do_change,      "device filename", "change a removable media" },    { "screendump", "F", do_screen_dump,       "filename", "save screen into PPM image 'filename'" },    { "log", "s", do_log,      "item1[,...]", "activate logging of the specified items to '/tmp/qemu.log'" },     { "savevm", "s?", do_savevm,      "tag|id", "save a VM snapshot. If no tag or id are provided, a new snapshot is created" },     { "loadvm", "s", do_loadvm,      "tag|id", "restore a VM snapshot from its tag or id" },     { "delvm", "s", do_delvm,      "tag|id", "delete a VM snapshot from its tag or id" },     { "stop", "", do_stop,       "", "stop emulation", },    { "c|cont", "", do_cont,       "", "resume emulation", },#ifdef CONFIG_GDBSTUB    { "gdbserver", "i?", do_gdbserver,       "[port]", "start gdbserver session (default port=1234)", },#endif    { "x", "/l", do_memory_dump,       "/fmt addr", "virtual memory dump starting at 'addr'", },    { "xp", "/l", do_physical_memory_dump,       "/fmt addr", "physical memory dump starting at 'addr'", },    { "p|print", "/l", do_print,       "/fmt expr", "print expression value (use $reg for CPU register access)", },    { "i", "/ii.", do_ioport_read,       "/fmt addr", "I/O port read" },    { "sendkey", "s", do_send_key,       "keys", "send keys to the VM (e.g. 'sendkey ctrl-alt-f1')" },    { "system_reset", "", do_system_reset,       "", "reset the system" },    { "system_powerdown", "", do_system_powerdown,       "", "send system power down event" },    { "sum", "ii", do_sum,       "addr size", "compute the checksum of a memory region" },    { "usb_add", "s", do_usb_add,      "device", "add USB device (e.g. 'host:bus.addr' or 'host:vendor_id:product_id')" },    { "usb_del", "s", do_usb_del,      "device", "remove USB device 'bus.addr'" },    { "cpu", "i", do_cpu_set,       "index", "set the default CPU" },    { "mouse_move", "sss?", do_mouse_move,       "dx dy [dz]", "send mouse move events" },    { "mouse_button", "i", do_mouse_button,       "state", "change mouse button state (1=L, 2=M, 4=R)" },    { "mouse_set", "i", do_mouse_set,      "index", "set which mouse device receives events" },#ifdef HAS_AUDIO    { "wavcapture", "si?i?i?", do_wav_capture,      "path [frequency bits channels]",      "capture audio to a wave file (default frequency=44100 bits=16 channels=2)" },#endif     { "stopcapture", "i", do_stop_capture,       "capture index", "stop capture" },    { "memsave", "lis", do_memory_save,       "addr size file", "save to disk virtual memory dump starting at 'addr' of size 'size'", },    { NULL, NULL, }, };static term_cmd_t info_cmds[] = {    { "version", "", do_info_version,      "", "show the version of qemu" },    { "network", "", do_info_network,      "", "show the network state" },    { "block", "", do_info_block,      "", "show the block devices" },    { "registers", "", do_info_registers,      "", "show the cpu registers" },    { "cpus", "", do_info_cpus,      "", "show infos for each CPU" },    { "history", "", do_info_history,      "", "show the command line history", },    { "irq", "", irq_info,      "", "show the interrupts statistics (if available)", },    { "pic", "", pic_info,      "", "show i8259 (PIC) state", },    { "pci", "", pci_info,      "", "show PCI info", },#if defined(TARGET_I386)    { "tlb", "", tlb_info,      "", "show virtual to physical memory mappings", },    { "mem", "", mem_info,      "", "show the active virtual memory mappings", },#endif    { "jit", "", do_info_jit,      "", "show dynamic compiler info", },    { "kqemu", "", do_info_kqemu,      "", "show kqemu information", },    { "usb", "", usb_info,      "", "show guest USB devices", },    { "usbhost", "", usb_host_info,      "", "show host USB devices", },    { "profile", "", do_info_profile,      "", "show profiling information", },    { "capture", "", do_info_capture,      "", "show capture information" },    { "snapshots", "", do_info_snapshots,      "", "show the currently saved VM snapshots" },    { "mice", "", do_info_mice,      "", "show which guest mouse is receiving events" },    { "vnc", "", do_info_vnc,      "", "show the vnc server status"},    { NULL, NULL, },};/*******************************************************************/static const char *pch;static jmp_buf expr_env;#define MD_TLONG 0#define MD_I32   1typedef struct MonitorDef {    const char *name;    int offset;    target_long (*get_value)(struct MonitorDef *md, int val);    int type;} MonitorDef;#if defined(TARGET_I386)static target_long monitor_get_pc (struct MonitorDef *md, int val){    CPUState *env = mon_get_cpu();    if (!env)        return 0;    return env->eip + env->segs[R_CS].base;}#endif#if defined(TARGET_PPC)static target_long monitor_get_ccr (struct MonitorDef *md, int val){    CPUState *env = mon_get_cpu();    unsigned int u;    int i;    if (!env)        return 0;    u = 0;    for (i = 0; i < 8; i++)	u |= env->crf[i] << (32 - (4 * i));    return u;}static target_long monitor_get_msr (struct MonitorDef *md, int val){    CPUState *env = mon_get_cpu();    if (!env)        return 0;    return (env->msr[MSR_POW] << MSR_POW) |        (env->msr[MSR_ILE] << MSR_ILE) |        (env->msr[MSR_EE] << MSR_EE) |        (env->msr[MSR_PR] << MSR_PR) |        (env->msr[MSR_FP] << MSR_FP) |        (env->msr[MSR_ME] << MSR_ME) |        (env->msr[MSR_FE0] << MSR_FE0) |        (env->msr[MSR_SE] << MSR_SE) |        (env->msr[MSR_BE] << MSR_BE) |        (env->msr[MSR_FE1] << MSR_FE1) |        (env->msr[MSR_IP] << MSR_IP) |        (env->msr[MSR_IR] << MSR_IR) |        (env->msr[MSR_DR] << MSR_DR) |        (env->msr[MSR_RI] << MSR_RI) |        (env->msr[MSR_LE] << MSR_LE);}static target_long monitor_get_xer (struct MonitorDef *md, int val){    CPUState *env = mon_get_cpu();    if (!env)        return 0;    return (env->xer[XER_SO] << XER_SO) |        (env->xer[XER_OV] << XER_OV) |        (env->xer[XER_CA] << XER_CA) |        (env->xer[XER_BC] << XER_BC);}static target_long monitor_get_decr (struct MonitorDef *md, int val){    CPUState *env = mon_get_cpu();    if (!env)        return 0;    return cpu_ppc_load_decr(env);}static target_long monitor_get_tbu (struct MonitorDef *md, int val){    CPUState *env = mon_get_cpu();    if (!env)        return 0;    return cpu_ppc_load_tbu(env);}static target_long monitor_get_tbl (struct MonitorDef *md, int val){    CPUState *env = mon_get_cpu();    if (!env)        return 0;    return cpu_ppc_load_tbl(env);}#endif#if defined(TARGET_SPARC)#ifndef TARGET_SPARC64static target_long monitor_get_psr (struct MonitorDef *md, int val){    CPUState *env = mon_get_cpu();    if (!env)        return 0;    return GET_PSR(env);}#endifstatic target_long monitor_get_reg(struct MonitorDef *md, int val){    CPUState *env = mon_get_cpu();    if (!env)        return 0;    return env->regwptr[val];}#endifstatic MonitorDef monitor_defs[] = {#ifdef TARGET_I386#define SEG(name, seg) \    { name, offsetof(CPUState, segs[seg].selector), NULL, MD_I32 },\    { name ".base", offsetof(CPUState, segs[seg].base) },\    { name ".limit", offsetof(CPUState, segs[seg].limit), NULL, MD_I32 },    { "eax", offsetof(CPUState, regs[0]) },    { "ecx", offsetof(CPUState, regs[1]) },    { "edx", offsetof(CPUState, regs[2]) },    { "ebx", offsetof(CPUState, regs[3]) },    { "esp|sp", offsetof(CPUState, regs[4]) },    { "ebp|fp", offsetof(CPUState, regs[5]) },    { "esi", offsetof(CPUState, regs[6]) },    { "edi", offsetof(CPUState, regs[7]) },#ifdef TARGET_X86_64    { "r8", offsetof(CPUState, regs[8]) },    { "r9", offsetof(CPUState, regs[9]) },    { "r10", offsetof(CPUState, regs[10]) },    { "r11", offsetof(CPUState, regs[11]) },    { "r12", offsetof(CPUState, regs[12]) },    { "r13", offsetof(CPUState, regs[13]) },    { "r14", offsetof(CPUState, regs[14]) },    { "r15", offsetof(CPUState, regs[15]) },#endif    { "eflags", offsetof(CPUState, eflags) },    { "eip", offsetof(CPUState, eip) },    SEG("cs", R_CS)    SEG("ds", R_DS)    SEG("es", R_ES)    SEG("ss", R_SS)    SEG("fs", R_FS)    SEG("gs", R_GS)    { "pc", 0, monitor_get_pc, },#elif defined(TARGET_PPC)    { "r0", offsetof(CPUState, gpr[0]) },    { "r1", offsetof(CPUState, gpr[1]) },    { "r2", offsetof(CPUState, gpr[2]) },    { "r3", offsetof(CPUState, gpr[3]) },    { "r4", offsetof(CPUState, gpr[4]) },    { "r5", offsetof(CPUState, gpr[5]) },    { "r6", offsetof(CPUState, gpr[6]) },    { "r7", offsetof(CPUState, gpr[7]) },    { "r8", offsetof(CPUState, gpr[8]) },    { "r9", offsetof(CPUState, gpr[9]) },    { "r10", offsetof(CPUState, gpr[10]) },    { "r11", offsetof(CPUState, gpr[11]) },    { "r12", offsetof(CPUState, gpr[12]) },    { "r13", offsetof(CPUState, gpr[13]) },    { "r14", offsetof(CPUState, gpr[14]) },    { "r15", offsetof(CPUState, gpr[15]) },    { "r16", offsetof(CPUState, gpr[16]) },    { "r17", offsetof(CPUState, gpr[17]) },    { "r18", offsetof(CPUState, gpr[18]) },    { "r19", offsetof(CPUState, gpr[19]) },    { "r20", offsetof(CPUState, gpr[20]) },    { "r21", offsetof(CPUState, gpr[21]) },    { "r22", offsetof(CPUState, gpr[22]) },    { "r23", offsetof(CPUState, gpr[23]) },    { "r24", offsetof(CPUState, gpr[24]) },

⌨️ 快捷键说明

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