38 |
* 'F' filename |
* 'F' filename |
39 |
* 'B' block device name |
* 'B' block device name |
40 |
* 's' string (accept optional quote) |
* 's' string (accept optional quote) |
41 |
* 'i' integer |
* 'i' 32 bit integer |
42 |
|
* 'l' target long (32 or 64 bit) |
43 |
* '/' optional gdb-like print format (like "/10x") |
* '/' optional gdb-like print format (like "/10x") |
44 |
* |
* |
45 |
* '?' optional type (for 'F', 's' and 'i') |
* '?' optional type (for 'F', 's' and 'i') |
464 |
v = lduw_raw(buf + i); |
v = lduw_raw(buf + i); |
465 |
break; |
break; |
466 |
case 4: |
case 4: |
467 |
v = ldl_raw(buf + i); |
v = (uint32_t)ldl_raw(buf + i); |
468 |
break; |
break; |
469 |
case 8: |
case 8: |
470 |
v = ldq_raw(buf + i); |
v = ldq_raw(buf + i); |
496 |
} |
} |
497 |
} |
} |
498 |
|
|
499 |
static void do_memory_dump(int count, int format, int size, int addr) |
#if TARGET_LONG_BITS == 64 |
500 |
|
#define GET_TLONG(h, l) (((uint64_t)(h) << 32) | (l)) |
501 |
|
#else |
502 |
|
#define GET_TLONG(h, l) (l) |
503 |
|
#endif |
504 |
|
|
505 |
|
static void do_memory_dump(int count, int format, int size, |
506 |
|
uint32_t addrh, uint32_t addrl) |
507 |
{ |
{ |
508 |
|
target_long addr = GET_TLONG(addrh, addrl); |
509 |
memory_dump(count, format, size, addr, 0); |
memory_dump(count, format, size, addr, 0); |
510 |
} |
} |
511 |
|
|
512 |
static void do_physical_memory_dump(int count, int format, int size, int addr) |
static void do_physical_memory_dump(int count, int format, int size, |
513 |
|
uint32_t addrh, uint32_t addrl) |
514 |
|
|
515 |
{ |
{ |
516 |
|
target_long addr = GET_TLONG(addrh, addrl); |
517 |
memory_dump(count, format, size, addr, 1); |
memory_dump(count, format, size, addr, 1); |
518 |
} |
} |
519 |
|
|
520 |
static void do_print(int count, int format, int size, int val) |
static void do_print(int count, int format, int size, unsigned int valh, unsigned int vall) |
521 |
{ |
{ |
522 |
|
target_long val = GET_TLONG(valh, vall); |
523 |
|
#if TARGET_LONG_BITS == 32 |
524 |
switch(format) { |
switch(format) { |
525 |
case 'o': |
case 'o': |
526 |
term_printf("%#o", val); |
term_printf("%#o", val); |
539 |
term_printc(val); |
term_printc(val); |
540 |
break; |
break; |
541 |
} |
} |
542 |
|
#else |
543 |
|
switch(format) { |
544 |
|
case 'o': |
545 |
|
term_printf("%#llo", val); |
546 |
|
break; |
547 |
|
case 'x': |
548 |
|
term_printf("%#llx", val); |
549 |
|
break; |
550 |
|
case 'u': |
551 |
|
term_printf("%llu", val); |
552 |
|
break; |
553 |
|
default: |
554 |
|
case 'd': |
555 |
|
term_printf("%lld", val); |
556 |
|
break; |
557 |
|
case 'c': |
558 |
|
term_printc(val); |
559 |
|
break; |
560 |
|
} |
561 |
|
#endif |
562 |
term_printf("\n"); |
term_printf("\n"); |
563 |
} |
} |
564 |
|
|
893 |
{ "gdbserver", "i?", do_gdbserver, |
{ "gdbserver", "i?", do_gdbserver, |
894 |
"[port]", "start gdbserver session (default port=1234)", }, |
"[port]", "start gdbserver session (default port=1234)", }, |
895 |
#endif |
#endif |
896 |
{ "x", "/i", do_memory_dump, |
{ "x", "/l", do_memory_dump, |
897 |
"/fmt addr", "virtual memory dump starting at 'addr'", }, |
"/fmt addr", "virtual memory dump starting at 'addr'", }, |
898 |
{ "xp", "/i", do_physical_memory_dump, |
{ "xp", "/l", do_physical_memory_dump, |
899 |
"/fmt addr", "physical memory dump starting at 'addr'", }, |
"/fmt addr", "physical memory dump starting at 'addr'", }, |
900 |
{ "p|print", "/i", do_print, |
{ "p|print", "/l", do_print, |
901 |
"/fmt expr", "print expression value (use $reg for CPU register access)", }, |
"/fmt expr", "print expression value (use $reg for CPU register access)", }, |
902 |
{ "i", "/ii.", do_ioport_read, |
{ "i", "/ii.", do_ioport_read, |
903 |
"/fmt addr", "I/O port read" }, |
"/fmt addr", "I/O port read" }, |
942 |
static const char *pch; |
static const char *pch; |
943 |
static jmp_buf expr_env; |
static jmp_buf expr_env; |
944 |
|
|
945 |
|
#define MD_TLONG 0 |
946 |
|
#define MD_I32 1 |
947 |
|
|
948 |
typedef struct MonitorDef { |
typedef struct MonitorDef { |
949 |
const char *name; |
const char *name; |
950 |
int offset; |
int offset; |
951 |
int (*get_value)(struct MonitorDef *md, int val); |
target_long (*get_value)(struct MonitorDef *md, int val); |
952 |
|
int type; |
953 |
} MonitorDef; |
} MonitorDef; |
954 |
|
|
955 |
#if defined(TARGET_I386) |
#if defined(TARGET_I386) |
956 |
static int monitor_get_pc (struct MonitorDef *md, int val) |
static target_long monitor_get_pc (struct MonitorDef *md, int val) |
957 |
{ |
{ |
958 |
return cpu_single_env->eip + (long)cpu_single_env->segs[R_CS].base; |
return cpu_single_env->eip + cpu_single_env->segs[R_CS].base; |
959 |
} |
} |
960 |
#endif |
#endif |
961 |
|
|
962 |
#if defined(TARGET_PPC) |
#if defined(TARGET_PPC) |
963 |
static int monitor_get_ccr (struct MonitorDef *md, int val) |
static target_long monitor_get_ccr (struct MonitorDef *md, int val) |
964 |
{ |
{ |
965 |
unsigned int u; |
unsigned int u; |
966 |
int i; |
int i; |
972 |
return u; |
return u; |
973 |
} |
} |
974 |
|
|
975 |
static int monitor_get_msr (struct MonitorDef *md, int val) |
static target_long monitor_get_msr (struct MonitorDef *md, int val) |
976 |
{ |
{ |
977 |
return (cpu_single_env->msr[MSR_POW] << MSR_POW) | |
return (cpu_single_env->msr[MSR_POW] << MSR_POW) | |
978 |
(cpu_single_env->msr[MSR_ILE] << MSR_ILE) | |
(cpu_single_env->msr[MSR_ILE] << MSR_ILE) | |
991 |
(cpu_single_env->msr[MSR_LE] << MSR_LE); |
(cpu_single_env->msr[MSR_LE] << MSR_LE); |
992 |
} |
} |
993 |
|
|
994 |
static int monitor_get_xer (struct MonitorDef *md, int val) |
static target_long monitor_get_xer (struct MonitorDef *md, int val) |
995 |
{ |
{ |
996 |
return (cpu_single_env->xer[XER_SO] << XER_SO) | |
return (cpu_single_env->xer[XER_SO] << XER_SO) | |
997 |
(cpu_single_env->xer[XER_OV] << XER_OV) | |
(cpu_single_env->xer[XER_OV] << XER_OV) | |
999 |
(cpu_single_env->xer[XER_BC] << XER_BC); |
(cpu_single_env->xer[XER_BC] << XER_BC); |
1000 |
} |
} |
1001 |
|
|
1002 |
static int monitor_get_decr (struct MonitorDef *md, int val) |
static target_long monitor_get_decr (struct MonitorDef *md, int val) |
1003 |
{ |
{ |
1004 |
return cpu_ppc_load_decr(cpu_single_env); |
return cpu_ppc_load_decr(cpu_single_env); |
1005 |
} |
} |
1006 |
|
|
1007 |
static int monitor_get_tbu (struct MonitorDef *md, int val) |
static target_long monitor_get_tbu (struct MonitorDef *md, int val) |
1008 |
{ |
{ |
1009 |
return cpu_ppc_load_tbu(cpu_single_env); |
return cpu_ppc_load_tbu(cpu_single_env); |
1010 |
} |
} |
1011 |
|
|
1012 |
static int monitor_get_tbl (struct MonitorDef *md, int val) |
static target_long monitor_get_tbl (struct MonitorDef *md, int val) |
1013 |
{ |
{ |
1014 |
return cpu_ppc_load_tbl(cpu_single_env); |
return cpu_ppc_load_tbl(cpu_single_env); |
1015 |
} |
} |
1016 |
#endif |
#endif |
1017 |
|
|
1018 |
#if defined(TARGET_SPARC) |
#if defined(TARGET_SPARC) |
1019 |
static int monitor_get_psr (struct MonitorDef *md, int val) |
static target_long monitor_get_psr (struct MonitorDef *md, int val) |
1020 |
{ |
{ |
1021 |
return GET_PSR(cpu_single_env); |
return GET_PSR(cpu_single_env); |
1022 |
} |
} |
1023 |
|
|
1024 |
static int monitor_get_reg(struct MonitorDef *md, int val) |
static target_long monitor_get_reg(struct MonitorDef *md, int val) |
1025 |
{ |
{ |
1026 |
return cpu_single_env->regwptr[val]; |
return cpu_single_env->regwptr[val]; |
1027 |
} |
} |
1031 |
#ifdef TARGET_I386 |
#ifdef TARGET_I386 |
1032 |
|
|
1033 |
#define SEG(name, seg) \ |
#define SEG(name, seg) \ |
1034 |
{ name, offsetof(CPUState, segs[seg].selector) },\ |
{ name, offsetof(CPUState, segs[seg].selector), NULL, MD_I32 },\ |
1035 |
{ name ".base", offsetof(CPUState, segs[seg].base) },\ |
{ name ".base", offsetof(CPUState, segs[seg].base) },\ |
1036 |
{ name ".limit", offsetof(CPUState, segs[seg].limit) }, |
{ name ".limit", offsetof(CPUState, segs[seg].limit), NULL, MD_I32 }, |
1037 |
|
|
1038 |
{ "eax", offsetof(CPUState, regs[0]) }, |
{ "eax", offsetof(CPUState, regs[0]) }, |
1039 |
{ "ecx", offsetof(CPUState, regs[1]) }, |
{ "ecx", offsetof(CPUState, regs[1]) }, |
1043 |
{ "ebp|fp", offsetof(CPUState, regs[5]) }, |
{ "ebp|fp", offsetof(CPUState, regs[5]) }, |
1044 |
{ "esi", offsetof(CPUState, regs[6]) }, |
{ "esi", offsetof(CPUState, regs[6]) }, |
1045 |
{ "edi", offsetof(CPUState, regs[7]) }, |
{ "edi", offsetof(CPUState, regs[7]) }, |
1046 |
|
#ifdef TARGET_X86_64 |
1047 |
|
{ "r8", offsetof(CPUState, regs[8]) }, |
1048 |
|
{ "r9", offsetof(CPUState, regs[9]) }, |
1049 |
|
{ "r10", offsetof(CPUState, regs[10]) }, |
1050 |
|
{ "r11", offsetof(CPUState, regs[11]) }, |
1051 |
|
{ "r12", offsetof(CPUState, regs[12]) }, |
1052 |
|
{ "r13", offsetof(CPUState, regs[13]) }, |
1053 |
|
{ "r14", offsetof(CPUState, regs[14]) }, |
1054 |
|
{ "r15", offsetof(CPUState, regs[15]) }, |
1055 |
|
#endif |
1056 |
{ "eflags", offsetof(CPUState, eflags) }, |
{ "eflags", offsetof(CPUState, eflags) }, |
1057 |
{ "eip", offsetof(CPUState, eip) }, |
{ "eip", offsetof(CPUState, eip) }, |
1058 |
SEG("cs", R_CS) |
SEG("cs", R_CS) |
1205 |
longjmp(expr_env, 1); |
longjmp(expr_env, 1); |
1206 |
} |
} |
1207 |
|
|
1208 |
static int get_monitor_def(int *pval, const char *name) |
static int get_monitor_def(target_long *pval, const char *name) |
1209 |
{ |
{ |
1210 |
MonitorDef *md; |
MonitorDef *md; |
1211 |
|
void *ptr; |
1212 |
|
|
1213 |
for(md = monitor_defs; md->name != NULL; md++) { |
for(md = monitor_defs; md->name != NULL; md++) { |
1214 |
if (compare_cmd(name, md->name)) { |
if (compare_cmd(name, md->name)) { |
1215 |
if (md->get_value) { |
if (md->get_value) { |
1216 |
*pval = md->get_value(md, md->offset); |
*pval = md->get_value(md, md->offset); |
1217 |
} else { |
} else { |
1218 |
*pval = *(uint32_t *)((uint8_t *)cpu_single_env + md->offset); |
ptr = (uint8_t *)cpu_single_env + md->offset; |
1219 |
|
switch(md->type) { |
1220 |
|
case MD_I32: |
1221 |
|
*pval = *(int32_t *)ptr; |
1222 |
|
break; |
1223 |
|
case MD_TLONG: |
1224 |
|
*pval = *(target_long *)ptr; |
1225 |
|
break; |
1226 |
|
default: |
1227 |
|
*pval = 0; |
1228 |
|
break; |
1229 |
|
} |
1230 |
} |
} |
1231 |
return 0; |
return 0; |
1232 |
} |
} |
1243 |
} |
} |
1244 |
} |
} |
1245 |
|
|
1246 |
static int expr_sum(void); |
static target_long expr_sum(void); |
1247 |
|
|
1248 |
static int expr_unary(void) |
static target_long expr_unary(void) |
1249 |
{ |
{ |
1250 |
int n; |
target_long n; |
1251 |
char *p; |
char *p; |
1252 |
|
|
1253 |
switch(*pch) { |
switch(*pch) { |
1320 |
} |
} |
1321 |
|
|
1322 |
|
|
1323 |
static int expr_prod(void) |
static target_long expr_prod(void) |
1324 |
{ |
{ |
1325 |
int val, val2, op; |
target_long val, val2; |
1326 |
|
int op; |
1327 |
|
|
1328 |
val = expr_unary(); |
val = expr_unary(); |
1329 |
for(;;) { |
for(;;) { |
1330 |
op = *pch; |
op = *pch; |
1351 |
return val; |
return val; |
1352 |
} |
} |
1353 |
|
|
1354 |
static int expr_logic(void) |
static target_long expr_logic(void) |
1355 |
{ |
{ |
1356 |
int val, val2, op; |
target_long val, val2; |
1357 |
|
int op; |
1358 |
|
|
1359 |
val = expr_prod(); |
val = expr_prod(); |
1360 |
for(;;) { |
for(;;) { |
1379 |
return val; |
return val; |
1380 |
} |
} |
1381 |
|
|
1382 |
static int expr_sum(void) |
static target_long expr_sum(void) |
1383 |
{ |
{ |
1384 |
int val, val2, op; |
target_long val, val2; |
1385 |
|
int op; |
1386 |
|
|
1387 |
val = expr_logic(); |
val = expr_logic(); |
1388 |
for(;;) { |
for(;;) { |
1399 |
return val; |
return val; |
1400 |
} |
} |
1401 |
|
|
1402 |
static int get_expr(int *pval, const char **pp) |
static int get_expr(target_long *pval, const char **pp) |
1403 |
{ |
{ |
1404 |
pch = *pp; |
pch = *pp; |
1405 |
if (setjmp(expr_env)) { |
if (setjmp(expr_env)) { |
1660 |
} |
} |
1661 |
break; |
break; |
1662 |
case 'i': |
case 'i': |
1663 |
|
case 'l': |
1664 |
{ |
{ |
1665 |
int val; |
target_long val; |
1666 |
while (isspace(*p)) |
while (isspace(*p)) |
1667 |
p++; |
p++; |
1668 |
if (*typestr == '?' || *typestr == '.') { |
if (*typestr == '?' || *typestr == '.') { |
1695 |
if (get_expr(&val, &p)) |
if (get_expr(&val, &p)) |
1696 |
goto fail; |
goto fail; |
1697 |
add_num: |
add_num: |
1698 |
if (nb_args >= MAX_ARGS) |
if (c == 'i') { |
1699 |
goto error_args; |
if (nb_args >= MAX_ARGS) |
1700 |
args[nb_args++] = (void *)val; |
goto error_args; |
1701 |
|
args[nb_args++] = (void *)(int)val; |
1702 |
|
} else { |
1703 |
|
if ((nb_args + 1) >= MAX_ARGS) |
1704 |
|
goto error_args; |
1705 |
|
#if TARGET_LONG_BITS == 64 |
1706 |
|
args[nb_args++] = (void *)(int)((val >> 32) & 0xffffffff); |
1707 |
|
#else |
1708 |
|
args[nb_args++] = (void *)0; |
1709 |
|
#endif |
1710 |
|
args[nb_args++] = (void *)(int)(val & 0xffffffff); |
1711 |
|
} |
1712 |
} |
} |
1713 |
break; |
break; |
1714 |
case '-': |
case '-': |