📄 monitor.c
字号:
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]) }, { "r25", offsetof(CPUState, gpr[25]) }, { "r26", offsetof(CPUState, gpr[26]) }, { "r27", offsetof(CPUState, gpr[27]) }, { "r28", offsetof(CPUState, gpr[28]) }, { "r29", offsetof(CPUState, gpr[29]) }, { "r30", offsetof(CPUState, gpr[30]) }, { "r31", offsetof(CPUState, gpr[31]) }, { "nip|pc", offsetof(CPUState, nip) }, { "lr", offsetof(CPUState, lr) }, { "ctr", offsetof(CPUState, ctr) }, { "decr", 0, &monitor_get_decr, }, { "ccr", 0, &monitor_get_ccr, }, { "msr", 0, &monitor_get_msr, }, { "xer", 0, &monitor_get_xer, }, { "tbu", 0, &monitor_get_tbu, }, { "tbl", 0, &monitor_get_tbl, }, { "sdr1", offsetof(CPUState, sdr1) }, { "sr0", offsetof(CPUState, sr[0]) }, { "sr1", offsetof(CPUState, sr[1]) }, { "sr2", offsetof(CPUState, sr[2]) }, { "sr3", offsetof(CPUState, sr[3]) }, { "sr4", offsetof(CPUState, sr[4]) }, { "sr5", offsetof(CPUState, sr[5]) }, { "sr6", offsetof(CPUState, sr[6]) }, { "sr7", offsetof(CPUState, sr[7]) }, { "sr8", offsetof(CPUState, sr[8]) }, { "sr9", offsetof(CPUState, sr[9]) }, { "sr10", offsetof(CPUState, sr[10]) }, { "sr11", offsetof(CPUState, sr[11]) }, { "sr12", offsetof(CPUState, sr[12]) }, { "sr13", offsetof(CPUState, sr[13]) }, { "sr14", offsetof(CPUState, sr[14]) }, { "sr15", offsetof(CPUState, sr[15]) }, /* Too lazy to put BATs and SPRs ... */#elif defined(TARGET_SPARC) { "g0", offsetof(CPUState, gregs[0]) }, { "g1", offsetof(CPUState, gregs[1]) }, { "g2", offsetof(CPUState, gregs[2]) }, { "g3", offsetof(CPUState, gregs[3]) }, { "g4", offsetof(CPUState, gregs[4]) }, { "g5", offsetof(CPUState, gregs[5]) }, { "g6", offsetof(CPUState, gregs[6]) }, { "g7", offsetof(CPUState, gregs[7]) }, { "o0", 0, monitor_get_reg }, { "o1", 1, monitor_get_reg }, { "o2", 2, monitor_get_reg }, { "o3", 3, monitor_get_reg }, { "o4", 4, monitor_get_reg }, { "o5", 5, monitor_get_reg }, { "o6", 6, monitor_get_reg }, { "o7", 7, monitor_get_reg }, { "l0", 8, monitor_get_reg }, { "l1", 9, monitor_get_reg }, { "l2", 10, monitor_get_reg }, { "l3", 11, monitor_get_reg }, { "l4", 12, monitor_get_reg }, { "l5", 13, monitor_get_reg }, { "l6", 14, monitor_get_reg }, { "l7", 15, monitor_get_reg }, { "i0", 16, monitor_get_reg }, { "i1", 17, monitor_get_reg }, { "i2", 18, monitor_get_reg }, { "i3", 19, monitor_get_reg }, { "i4", 20, monitor_get_reg }, { "i5", 21, monitor_get_reg }, { "i6", 22, monitor_get_reg }, { "i7", 23, monitor_get_reg }, { "pc", offsetof(CPUState, pc) }, { "npc", offsetof(CPUState, npc) }, { "y", offsetof(CPUState, y) },#ifndef TARGET_SPARC64 { "psr", 0, &monitor_get_psr, }, { "wim", offsetof(CPUState, wim) },#endif { "tbr", offsetof(CPUState, tbr) }, { "fsr", offsetof(CPUState, fsr) }, { "f0", offsetof(CPUState, fpr[0]) }, { "f1", offsetof(CPUState, fpr[1]) }, { "f2", offsetof(CPUState, fpr[2]) }, { "f3", offsetof(CPUState, fpr[3]) }, { "f4", offsetof(CPUState, fpr[4]) }, { "f5", offsetof(CPUState, fpr[5]) }, { "f6", offsetof(CPUState, fpr[6]) }, { "f7", offsetof(CPUState, fpr[7]) }, { "f8", offsetof(CPUState, fpr[8]) }, { "f9", offsetof(CPUState, fpr[9]) }, { "f10", offsetof(CPUState, fpr[10]) }, { "f11", offsetof(CPUState, fpr[11]) }, { "f12", offsetof(CPUState, fpr[12]) }, { "f13", offsetof(CPUState, fpr[13]) }, { "f14", offsetof(CPUState, fpr[14]) }, { "f15", offsetof(CPUState, fpr[15]) }, { "f16", offsetof(CPUState, fpr[16]) }, { "f17", offsetof(CPUState, fpr[17]) }, { "f18", offsetof(CPUState, fpr[18]) }, { "f19", offsetof(CPUState, fpr[19]) }, { "f20", offsetof(CPUState, fpr[20]) }, { "f21", offsetof(CPUState, fpr[21]) }, { "f22", offsetof(CPUState, fpr[22]) }, { "f23", offsetof(CPUState, fpr[23]) }, { "f24", offsetof(CPUState, fpr[24]) }, { "f25", offsetof(CPUState, fpr[25]) }, { "f26", offsetof(CPUState, fpr[26]) }, { "f27", offsetof(CPUState, fpr[27]) }, { "f28", offsetof(CPUState, fpr[28]) }, { "f29", offsetof(CPUState, fpr[29]) }, { "f30", offsetof(CPUState, fpr[30]) }, { "f31", offsetof(CPUState, fpr[31]) },#ifdef TARGET_SPARC64 { "f32", offsetof(CPUState, fpr[32]) }, { "f34", offsetof(CPUState, fpr[34]) }, { "f36", offsetof(CPUState, fpr[36]) }, { "f38", offsetof(CPUState, fpr[38]) }, { "f40", offsetof(CPUState, fpr[40]) }, { "f42", offsetof(CPUState, fpr[42]) }, { "f44", offsetof(CPUState, fpr[44]) }, { "f46", offsetof(CPUState, fpr[46]) }, { "f48", offsetof(CPUState, fpr[48]) }, { "f50", offsetof(CPUState, fpr[50]) }, { "f52", offsetof(CPUState, fpr[52]) }, { "f54", offsetof(CPUState, fpr[54]) }, { "f56", offsetof(CPUState, fpr[56]) }, { "f58", offsetof(CPUState, fpr[58]) }, { "f60", offsetof(CPUState, fpr[60]) }, { "f62", offsetof(CPUState, fpr[62]) }, { "asi", offsetof(CPUState, asi) }, { "pstate", offsetof(CPUState, pstate) }, { "cansave", offsetof(CPUState, cansave) }, { "canrestore", offsetof(CPUState, canrestore) }, { "otherwin", offsetof(CPUState, otherwin) }, { "wstate", offsetof(CPUState, wstate) }, { "cleanwin", offsetof(CPUState, cleanwin) }, { "fprs", offsetof(CPUState, fprs) },#endif#endif { NULL },};static void expr_error(const char *fmt) { term_printf(fmt); term_printf("\n"); longjmp(expr_env, 1);}/* return 0 if OK, -1 if not found, -2 if no CPU defined */static int get_monitor_def(target_long *pval, const char *name){ MonitorDef *md; void *ptr; for(md = monitor_defs; md->name != NULL; md++) { if (compare_cmd(name, md->name)) { if (md->get_value) { *pval = md->get_value(md, md->offset); } else { CPUState *env = mon_get_cpu(); if (!env) return -2; ptr = (uint8_t *)env + md->offset; switch(md->type) { case MD_I32: *pval = *(int32_t *)ptr; break; case MD_TLONG: *pval = *(target_long *)ptr; break; default: *pval = 0; break; } } return 0; } } return -1;}static void next(void){ if (pch != '\0') { pch++; while (isspace(*pch)) pch++; }}static target_long expr_sum(void);static target_long expr_unary(void){ target_long n; char *p; int ret; switch(*pch) { case '+': next(); n = expr_unary(); break; case '-': next(); n = -expr_unary(); break; case '~': next(); n = ~expr_unary(); break; case '(': next(); n = expr_sum(); if (*pch != ')') { expr_error("')' expected"); } next(); break; case '\'': pch++; if (*pch == '\0') expr_error("character constant expected"); n = *pch; pch++; if (*pch != '\'') expr_error("missing terminating \' character"); next(); break; case '$': { char buf[128], *q; pch++; q = buf; while ((*pch >= 'a' && *pch <= 'z') || (*pch >= 'A' && *pch <= 'Z') || (*pch >= '0' && *pch <= '9') || *pch == '_' || *pch == '.') { if ((q - buf) < sizeof(buf) - 1) *q++ = *pch; pch++; } while (isspace(*pch)) pch++; *q = 0; ret = get_monitor_def(&n, buf); if (ret == -1) expr_error("unknown register"); else if (ret == -2) expr_error("no cpu defined"); } break; case '\0': expr_error("unexpected end of expression"); n = 0; break; default: /* XXX: 64 bit version */ n = strtoul(pch, &p, 0); if (pch == p) { expr_error("invalid char in expression"); } pch = p; while (isspace(*pch)) pch++; break; } return n;}static target_long expr_prod(void){ target_long val, val2; int op; val = expr_unary(); for(;;) { op = *pch; if (op != '*' && op != '/' && op != '%') break; next(); val2 = expr_unary(); switch(op) { default: case '*': val *= val2; break; case '/': case '%': if (val2 == 0) expr_error("division by zero"); if (op == '/') val /= val2; else val %= val2; break; } } return val;}static target_long expr_logic(void){ target_long val, val2; int op; val = expr_prod(); for(;;) { op = *pch; if (op != '&' && op != '|' && op != '^') break; next(); val2 = expr_prod(); switch(op) { default: case '&': val &= val2; break; case '|': val |= val2; break; case '^': val ^= val2; break; } } return val;}static target_long expr_sum(void){ target_long val, val2; int op; val = expr_logic(); for(;;) { op = *pch; if (op != '+' && op != '-') break; next(); val2 = expr_logic(); if (op == '+') val += val2; else val -= val2; } return val;}static int get_expr(target_long *pval, const char **pp){ pch = *pp; if (setjmp(expr_env)) { *pp = pch; return -1; } while (isspace(*pch)) pch++; *pval = expr_sum(); *pp = pch; return 0;}static int get_str(char *buf, int buf_size, const char **pp){ const char *p; char *q; int c; q = buf; p = *pp; while (isspace(*p)) p++; if (*p == '\0') { fail: *q = '\0'; *pp = p; return -1; } if (*p == '\"') { p++; while (*p != '\0' && *p != '\"') { if (*p == '\\') { p++; c = *p++; switch(c) { case 'n': c = '\n'; break; case 'r': c = '\r'; break; case '\\': case '\'': case '\"': break; default: qemu_printf("unsupported escape code: '\\%c'\n", c); goto fail; } if ((q - buf) < buf_size - 1) { *q++ = c; } } else { if ((q - buf) < buf_size - 1) { *q++ = *p; } p++; } } if (*p != '\"') { qemu_printf("unterminated string\n"); goto fail;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -