--- trunk/src/cpus/cpu_x86.c 2007/10/08 16:19:37 22 +++ trunk/src/cpus/cpu_x86.c 2007/10/08 16:19:56 24 @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005 Anders Gavare. All rights reserved. + * Copyright (C) 2005-2006 Anders Gavare. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -25,7 +25,7 @@ * SUCH DAMAGE. * * - * $Id: cpu_x86.c,v 1.7 2006/02/17 18:38:30 debug Exp $ + * $Id: cpu_x86.c,v 1.15 2006/06/16 18:31:26 debug Exp $ * * x86 (and amd64) CPU emulation. * @@ -142,6 +142,8 @@ debug("%s", cpu->name); } + x86_init_64bit_dummy_tables(cpu); + return 1; } @@ -189,59 +191,65 @@ uint64_t offset; int i, x = cpu->cpu_id; - if (REAL_MODE) { - /* Real-mode: */ - debug("cpu%i: cs:ip = 0x%04x:0x%04x\n", x, - cpu->cd.x86.s[X86_S_CS], (int)cpu->pc); - - debug("cpu%i: ax = 0x%04x bx = 0x%04x cx = 0x%04x dx = " - "0x%04x\n", x, - (int)cpu->cd.x86.r[X86_R_AX], (int)cpu->cd.x86.r[X86_R_BX], - (int)cpu->cd.x86.r[X86_R_CX], (int)cpu->cd.x86.r[X86_R_DX]); - debug("cpu%i: si = 0x%04x di = 0x%04x bp = 0x%04x sp = " - "0x%04x\n", x, - (int)cpu->cd.x86.r[X86_R_SI], (int)cpu->cd.x86.r[X86_R_DI], - (int)cpu->cd.x86.r[X86_R_BP], (int)cpu->cd.x86.r[X86_R_SP]); - - debug("cpu%i: ds = 0x%04x es = 0x%04x ss = 0x%04x flags " - "= 0x%04x\n", x, - (int)cpu->cd.x86.s[X86_S_DS], (int)cpu->cd.x86.s[X86_S_ES], - (int)cpu->cd.x86.s[X86_S_SS], (int)cpu->cd.x86.rflags); - } else { - symbol = get_symbol_name(&cpu->machine->symbol_context, - cpu->pc, &offset); - - debug("cpu%i: eip=0x", x); - debug("%08x", (int)cpu->pc); - debug(" <%s>\n", symbol != NULL? symbol : " no symbol "); - - debug("cpu%i: eax=0x%08x ebx=0x%08x ecx=0x%08x edx=" - "0x%08x\n", x, - (int)cpu->cd.x86.r[X86_R_AX], (int)cpu->cd.x86.r[X86_R_BX], - (int)cpu->cd.x86.r[X86_R_CX], (int)cpu->cd.x86.r[X86_R_DX]); - debug("cpu%i: esi=0x%08x edi=0x%08x ebp=0x%08x esp=" - "0x%08x\n", x, - (int)cpu->cd.x86.r[X86_R_SI], (int)cpu->cd.x86.r[X86_R_DI], - (int)cpu->cd.x86.r[X86_R_BP], (int)cpu->cd.x86.r[X86_R_SP]); -#if 0 - } else { - /* 64-bit */ + if (LONG_MODE) { + /* 64-bit long mode: */ symbol = get_symbol_name(&cpu->machine->symbol_context, cpu->pc, &offset); - debug("cpu%i: rip = 0x", x); - debug("%016llx", (long long)cpu->pc); + debug("cpu%i: rip = 0x%016"PRIx64, x, cpu->pc); debug(" <%s>\n", symbol != NULL? symbol : " no symbol "); for (i=0; icd.x86.r[i]); + debug(" r%s = 0x%016"PRIx64, reg_names[i], + (uint64_t)cpu->cd.x86.r[i]); if ((i & 1) == 1) debug("\n"); } -#endif + } else if (REAL_MODE) { + /* 16-bit real-mode: */ + debug("cpu%i: cs:ip = 0x%04"PRIx16":0x%04"PRIx16"\n", x, + cpu->cd.x86.s[X86_S_CS], (uint16_t)cpu->pc); + + debug("cpu%i: ax = 0x%04"PRIx16" bx = 0x%04"PRIx16 + " cx = 0x%04"PRIx16" dx = 0x%04"PRIx16"\n", x, + (uint16_t)cpu->cd.x86.r[X86_R_AX], + (uint16_t)cpu->cd.x86.r[X86_R_BX], + (uint16_t)cpu->cd.x86.r[X86_R_CX], + (uint16_t)cpu->cd.x86.r[X86_R_DX]); + debug("cpu%i: si = 0x%04"PRIx16" di = 0x%04"PRIx16 + " bp = 0x%04"PRIx16" sp = 0x%04"PRIx16"\n", x, + (uint16_t)cpu->cd.x86.r[X86_R_SI], + (uint16_t)cpu->cd.x86.r[X86_R_DI], + (uint16_t)cpu->cd.x86.r[X86_R_BP], + (uint16_t)cpu->cd.x86.r[X86_R_SP]); + debug("cpu%i: ds = 0x%04"PRIx16" es = 0x%04"PRIx16 + " ss = 0x%04"PRIx16" flags = 0x%04"PRIx16"\n", x, + (uint16_t)cpu->cd.x86.s[X86_S_DS], + (uint16_t)cpu->cd.x86.s[X86_S_ES], + (uint16_t)cpu->cd.x86.s[X86_S_SS], + (uint16_t)cpu->cd.x86.rflags); + } else { + /* 32-bit protected mode: */ + symbol = get_symbol_name(&cpu->machine->symbol_context, + cpu->pc, &offset); + + debug("cpu%i: eip=0x%08"PRIx32, x, (uint32_t)cpu->pc); + debug(" <%s>\n", symbol != NULL? symbol : " no symbol "); + + debug("cpu%i: eax=0x%08"PRIx32" ebx=0x%08"PRIx32 + " ecx=0x%08"PRIx32" edx=0x%08"PRIx32"\n", x, + (uint32_t)cpu->cd.x86.r[X86_R_AX], + (uint32_t)cpu->cd.x86.r[X86_R_BX], + (uint32_t)cpu->cd.x86.r[X86_R_CX], + (uint32_t)cpu->cd.x86.r[X86_R_DX]); + debug("cpu%i: esi=0x%08"PRIx32" edi=0x%08"PRIx32 + " ebp=0x%08"PRIx32" esp=0x%08"PRIx32"\n", x, + (uint32_t)cpu->cd.x86.r[X86_R_SI], + (uint32_t)cpu->cd.x86.r[X86_R_DI], + (uint32_t)cpu->cd.x86.r[X86_R_BP], + (uint32_t)cpu->cd.x86.r[X86_R_SP]); } if (coprocs != 0) { @@ -280,22 +288,25 @@ cpu->machine->isa_pic_data.pic2->irq_base); } else if (PROTECTED_MODE) { /* Protected mode: */ - debug("cpu%i: cs=0x%04x ds=0x%04x es=0x%04x " - "fs=0x%04x gs=0x%04x ss=0x%04x\n", x, - (int)cpu->cd.x86.s[X86_S_CS], (int)cpu->cd.x86.s[X86_S_DS], - (int)cpu->cd.x86.s[X86_S_ES], (int)cpu->cd.x86.s[X86_S_FS], - (int)cpu->cd.x86.s[X86_S_GS], (int)cpu->cd.x86.s[X86_S_SS]); + debug("cpu%i: cs=0x%04"PRIx16" ds=0x%04"PRIx16" es=0x%04" + PRIx16" fs=0x%04"PRIx16" gs=0x%04"PRIx16" ss=0x%04" + PRIx16"\n", x, (uint16_t)cpu->cd.x86.s[X86_S_CS], + (uint16_t)cpu->cd.x86.s[X86_S_DS], + (uint16_t)cpu->cd.x86.s[X86_S_ES], + (uint16_t)cpu->cd.x86.s[X86_S_FS], + (uint16_t)cpu->cd.x86.s[X86_S_GS], + (uint16_t)cpu->cd.x86.s[X86_S_SS]); } if (PROTECTED_MODE) { /* Protected mode: */ - debug("cpu%i: cr0=0x%08x cr2=0x%08x cr3=0x%08x eflags=" - "0x%08x\n", x, (int)cpu->cd.x86.cr[0], - (int)cpu->cd.x86.cr[2], (int)cpu->cd.x86.cr[3], - (int)cpu->cd.x86.rflags); - debug("cpu%i: tr = 0x%04x (base=0x%llx, limit=0x%x)\n", - x, (int)cpu->cd.x86.tr, (long long)cpu->cd.x86.tr_base, - (int)cpu->cd.x86.tr_limit); + debug("cpu%i: cr0=0x%08"PRIx32" cr2=0x%08"PRIx32" cr3=0x%08" + PRIx32" eflags=0x%08"PRIx32"\n", x, + (uint32_t)cpu->cd.x86.cr[0], (uint32_t)cpu->cd.x86.cr[2], + (uint32_t)cpu->cd.x86.cr[3], (uint32_t)cpu->cd.x86.rflags); + debug("cpu%i: tr = 0x%04"PRIx16" (base=0x%"PRIx64", limit=0x" + PRIx32")\n", x, (uint16_t)cpu->cd.x86.tr, (uint64_t) + cpu->cd.x86.tr_base, (uint32_t)cpu->cd.x86.tr_limit); } } @@ -526,6 +537,33 @@ /* + * x86_cpu_tlbdump(): + * + * Called from the debugger to dump the TLB in a readable format. + * x is the cpu number to dump, or -1 to dump all CPUs. + * + * If rawflag is nonzero, then the TLB contents isn't formated nicely, + * just dumped. + */ +void x86_cpu_tlbdump(struct machine *m, int x, int rawflag) +{ +} + + +/* + * x86_cpu_gdb_stub(): + * + * Execute a "remote GDB" command. Returns a newly allocated response string + * on success, NULL on failure. + */ +char *x86_cpu_gdb_stub(struct cpu *cpu, char *cmd) +{ + fatal("x86_cpu_gdb_stub(): TODO\n"); + return NULL; +} + + +/* * x86_cpu_interrupt(): * * NOTE: Interacting with the 8259 PIC is done in src/machine.c. @@ -655,8 +693,8 @@ reload_segment_descriptor(cpu, RELOAD_TR, new_tr, NULL); if (cpu->cd.x86.tr_limit < 0x67) - fatal("WARNING: tr_limit = 0x%x, must be at least 0x67!\n", - (int)cpu->cd.x86.tr_limit); + fatal("WARNING: tr_limit = 0x%"PRIx16", must be at least " + "0x67!\n", (uint16_t)cpu->cd.x86.tr_limit); /* Read new registers: */ #define READ_VALUE { cpu->memory_rw(cpu, cpu->mem, cpu->cd.x86.tr_base + \ @@ -1493,7 +1531,7 @@ * The rest of running tells us the default (code) operand size. */ int x86_cpu_disassemble_instr(struct cpu *cpu, unsigned char *instr, - int running, uint64_t dumpaddr, int bintrans) + int running, uint64_t dumpaddr) { int op, rep = 0, lock = 0, n_prefix_bytes = 0; uint64_t ilen = 0, offset;