?? monitor.c
字號:
static void term_printc(int c){ term_printf("'"); switch(c) { case '\'': term_printf("\\'"); break; case '\\': term_printf("\\\\"); break; case '\n': term_printf("\\n"); break; case '\r': term_printf("\\r"); break; default: if (c >= 32 && c <= 126) { term_printf("%c", c); } else { term_printf("\\x%02x", c); } break; } term_printf("'");}static void memory_dump(int count, int format, int wsize, target_phys_addr_t addr, int is_physical){ CPUState *env; int nb_per_line, l, line_size, i, max_digits, len; uint8_t buf[16]; uint64_t v; if (format == 'i') { int flags; flags = 0; env = mon_get_cpu(); if (!env && !is_physical) return;#ifdef TARGET_I386 if (wsize == 2) { flags = 1; } else if (wsize == 4) { flags = 0; } else { /* as default we use the current CS size */ flags = 0; if (env) {#ifdef TARGET_X86_64 if ((env->efer & MSR_EFER_LMA) && (env->segs[R_CS].flags & DESC_L_MASK)) flags = 2; else#endif if (!(env->segs[R_CS].flags & DESC_B_MASK)) flags = 1; } }#endif monitor_disas(env, addr, count, is_physical, flags); return; } len = wsize * count; if (wsize == 1) line_size = 8; else line_size = 16; nb_per_line = line_size / wsize; max_digits = 0; switch(format) { case 'o': max_digits = (wsize * 8 + 2) / 3; break; default: case 'x': max_digits = (wsize * 8) / 4; break; case 'u': case 'd': max_digits = (wsize * 8 * 10 + 32) / 33; break; case 'c': wsize = 1; break; } while (len > 0) { if (is_physical) term_printf(TARGET_FMT_plx ":", addr); else term_printf(TARGET_FMT_lx ":", (target_ulong)addr); l = len; if (l > line_size) l = line_size; if (is_physical) { cpu_physical_memory_rw(addr, buf, l, 0); } else { env = mon_get_cpu(); if (!env) break; cpu_memory_rw_debug(env, addr, buf, l, 0); } i = 0; while (i < l) { switch(wsize) { default: case 1: v = ldub_raw(buf + i); break; case 2: v = lduw_raw(buf + i); break; case 4: v = (uint32_t)ldl_raw(buf + i); break; case 8: v = ldq_raw(buf + i); break; } term_printf(" "); switch(format) { case 'o': term_printf("%#*" PRIo64, max_digits, v); break; case 'x': term_printf("0x%0*" PRIx64, max_digits, v); break; case 'u': term_printf("%*" PRIu64, max_digits, v); break; case 'd': term_printf("%*" PRId64, max_digits, v); break; case 'c': term_printc(v); break; } i += wsize; } term_printf("\n"); addr += l; len -= l; }}#if TARGET_LONG_BITS == 64#define GET_TLONG(h, l) (((uint64_t)(h) << 32) | (l))#else#define GET_TLONG(h, l) (l)#endifstatic void do_memory_dump(int count, int format, int size, uint32_t addrh, uint32_t addrl){ target_long addr = GET_TLONG(addrh, addrl); memory_dump(count, format, size, addr, 0);}#if TARGET_PHYS_ADDR_BITS > 32#define GET_TPHYSADDR(h, l) (((uint64_t)(h) << 32) | (l))#else#define GET_TPHYSADDR(h, l) (l)#endifstatic void do_physical_memory_dump(int count, int format, int size, uint32_t addrh, uint32_t addrl){ target_phys_addr_t addr = GET_TPHYSADDR(addrh, addrl); memory_dump(count, format, size, addr, 1);}static void do_print(int count, int format, int size, unsigned int valh, unsigned int vall){ target_phys_addr_t val = GET_TPHYSADDR(valh, vall);#if TARGET_PHYS_ADDR_BITS == 32 switch(format) { case 'o': term_printf("%#o", val); break; case 'x': term_printf("%#x", val); break; case 'u': term_printf("%u", val); break; default: case 'd': term_printf("%d", val); break; case 'c': term_printc(val); break; }#else switch(format) { case 'o': term_printf("%#" PRIo64, val); break; case 'x': term_printf("%#" PRIx64, val); break; case 'u': term_printf("%" PRIu64, val); break; default: case 'd': term_printf("%" PRId64, val); break; case 'c': term_printc(val); break; }#endif term_printf("\n");}static void do_memory_save(unsigned int valh, unsigned int vall, uint32_t size, const char *filename){ FILE *f; target_long addr = GET_TLONG(valh, vall); uint32_t l; CPUState *env; uint8_t buf[1024]; env = mon_get_cpu(); if (!env) return; f = fopen(filename, "wb"); if (!f) { term_printf("could not open '%s'\n", filename); return; } while (size != 0) { l = sizeof(buf); if (l > size) l = size; cpu_memory_rw_debug(env, addr, buf, l, 0); fwrite(buf, 1, l, f); addr += l; size -= l; } fclose(f);}static void do_sum(uint32_t start, uint32_t size){ uint32_t addr; uint8_t buf[1]; uint16_t sum; sum = 0; for(addr = start; addr < (start + size); addr++) { cpu_physical_memory_rw(addr, buf, 1, 0); /* BSD sum algorithm ('sum' Unix command) */ sum = (sum >> 1) | (sum << 15); sum += buf[0]; } term_printf("%05d\n", sum);}typedef struct { int keycode; const char *name;} KeyDef;static const KeyDef key_defs[] = { { 0x2a, "shift" }, { 0x36, "shift_r" }, { 0x38, "alt" }, { 0xb8, "alt_r" }, { 0x1d, "ctrl" }, { 0x9d, "ctrl_r" }, { 0xdd, "menu" }, { 0x01, "esc" }, { 0x02, "1" }, { 0x03, "2" }, { 0x04, "3" }, { 0x05, "4" }, { 0x06, "5" }, { 0x07, "6" }, { 0x08, "7" }, { 0x09, "8" }, { 0x0a, "9" }, { 0x0b, "0" }, { 0x0c, "minus" }, { 0x0d, "equal" }, { 0x0e, "backspace" }, { 0x0f, "tab" }, { 0x10, "q" }, { 0x11, "w" }, { 0x12, "e" }, { 0x13, "r" }, { 0x14, "t" }, { 0x15, "y" }, { 0x16, "u" }, { 0x17, "i" }, { 0x18, "o" }, { 0x19, "p" }, { 0x1c, "ret" }, { 0x1e, "a" }, { 0x1f, "s" }, { 0x20, "d" }, { 0x21, "f" }, { 0x22, "g" }, { 0x23, "h" }, { 0x24, "j" }, { 0x25, "k" }, { 0x26, "l" }, { 0x2c, "z" }, { 0x2d, "x" }, { 0x2e, "c" }, { 0x2f, "v" }, { 0x30, "b" }, { 0x31, "n" }, { 0x32, "m" }, { 0x39, "spc" }, { 0x3a, "caps_lock" }, { 0x3b, "f1" }, { 0x3c, "f2" }, { 0x3d, "f3" }, { 0x3e, "f4" }, { 0x3f, "f5" }, { 0x40, "f6" }, { 0x41, "f7" }, { 0x42, "f8" }, { 0x43, "f9" }, { 0x44, "f10" }, { 0x45, "num_lock" }, { 0x46, "scroll_lock" }, { 0xb5, "kp_divide" }, { 0x37, "kp_multiply" }, { 0x4a, "kp_subtract" }, { 0x4e, "kp_add" }, { 0x9c, "kp_enter" }, { 0x53, "kp_decimal" }, { 0x52, "kp_0" }, { 0x4f, "kp_1" }, { 0x50, "kp_2" }, { 0x51, "kp_3" }, { 0x4b, "kp_4" }, { 0x4c, "kp_5" }, { 0x4d, "kp_6" }, { 0x47, "kp_7" }, { 0x48, "kp_8" }, { 0x49, "kp_9" }, { 0x56, "<" }, { 0x57, "f11" }, { 0x58, "f12" }, { 0xb7, "print" }, { 0xc7, "home" }, { 0xc9, "pgup" }, { 0xd1, "pgdn" }, { 0xcf, "end" }, { 0xcb, "left" }, { 0xc8, "up" }, { 0xd0, "down" }, { 0xcd, "right" }, { 0xd2, "insert" }, { 0xd3, "delete" }, { 0, NULL },};static int get_keycode(const char *key){ const KeyDef *p; char *endp; int ret; for(p = key_defs; p->name != NULL; p++) { if (!strcmp(key, p->name)) return p->keycode; } if (strstart(key, "0x", NULL)) { ret = strtoul(key, &endp, 0); if (*endp == '\0' && ret >= 0x01 && ret <= 0xff) return ret; } return -1;}static void do_send_key(const char *string){ char keybuf[16], *q; uint8_t keycodes[16]; const char *p; int nb_keycodes, keycode, i; nb_keycodes = 0; p = string; while (*p != '\0') { q = keybuf; while (*p != '\0' && *p != '-') { if ((q - keybuf) < sizeof(keybuf) - 1) { *q++ = *p; } p++; } *q = '\0'; keycode = get_keycode(keybuf); if (keycode < 0) { term_printf("unknown key: '%s'\n", keybuf); return; } keycodes[nb_keycodes++] = keycode; if (*p == '\0') break; p++; } /* key down events */ for(i = 0; i < nb_keycodes; i++) { keycode = keycodes[i]; if (keycode & 0x80) kbd_put_keycode(0xe0); kbd_put_keycode(keycode & 0x7f); } /* key up events */ for(i = nb_keycodes - 1; i >= 0; i--) { keycode = keycodes[i]; if (keycode & 0x80) kbd_put_keycode(0xe0); kbd_put_keycode(keycode | 0x80); }}static int mouse_button_state;static void do_mouse_move(const char *dx_str, const char *dy_str, const char *dz_str){ int dx, dy, dz; dx = strtol(dx_str, NULL, 0); dy = strtol(dy_str, NULL, 0); dz = 0; if (dz_str) dz = strtol(dz_str, NULL, 0); kbd_mouse_event(dx, dy, dz, mouse_button_state);}static void do_mouse_button(int button_state){ mouse_button_state = button_state; kbd_mouse_event(0, 0, 0, mouse_button_state);}static void do_ioport_read(int count, int format, int size, int addr, int has_index, int index){ uint32_t val; int suffix; if (has_index) { cpu_outb(NULL, addr & 0xffff, index & 0xff); addr++; } addr &= 0xffff; switch(size) { default: case 1: val = cpu_inb(NULL, addr); suffix = 'b'; break; case 2: val = cpu_inw(NULL, addr); suffix = 'w'; break; case 4: val = cpu_inl(NULL, addr); suffix = 'l'; break; } term_printf("port%c[0x%04x] = %#0*x\n",
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -