--- trunk/src/cpus/cpu_alpha.c 2007/10/08 16:19:37 22 +++ trunk/src/cpus/cpu_alpha.c 2007/10/08 16:19:56 24 @@ -25,7 +25,7 @@ * SUCH DAMAGE. * * - * $Id: cpu_alpha.c,v 1.5 2006/01/01 16:08:25 debug Exp $ + * $Id: cpu_alpha.c,v 1.16 2006/06/16 18:31:25 debug Exp $ * * Alpha CPU emulation. * @@ -64,12 +64,21 @@ int alpha_cpu_new(struct cpu *cpu, struct memory *mem, struct machine *machine, int cpu_id, char *cpu_type_name) { - int i; + int i = 0; + struct alpha_cpu_type_def cpu_type_defs[] = ALPHA_CPU_TYPE_DEFS; - if (strcasecmp(cpu_type_name, "Alpha") != 0) + /* Scan the cpu_type_defs list for this cpu type: */ + while (cpu_type_defs[i].name != NULL) { + if (strcasecmp(cpu_type_defs[i].name, cpu_type_name) == 0) { + break; + } + i++; + } + if (cpu_type_defs[i].name == NULL) return 0; cpu->memory_rw = alpha_memory_rw; + cpu->translate_address = alpha_translate_address; cpu->update_translation_table = alpha_update_translation_table; cpu->invalidate_translation_caches = alpha_invalidate_translation_caches; @@ -81,20 +90,10 @@ debug("%s", cpu->name); } - /* Create the default virtual->physical->host translation: */ - cpu->cd.alpha.vph_default_page = malloc(sizeof(struct alpha_vph_page)); - if (cpu->cd.alpha.vph_default_page == NULL) { - fprintf(stderr, "out of memory in alpha_cpu_new()\n"); - exit(1); - } - memset(cpu->cd.alpha.vph_default_page, 0, - sizeof(struct alpha_vph_page)); - for (i=0; icd.alpha.vph_table0[i] = cpu->cd.alpha.vph_table0_kernel[i] - = cpu->cd.alpha.vph_default_page; - cpu->cd.alpha.r[ALPHA_SP] = 0xfffffc000000ff00ULL; + alpha_init_64bit_dummy_tables(cpu); + return 1; } @@ -116,9 +115,18 @@ */ void alpha_cpu_list_available_types(void) { - /* TODO */ + int i, j; + struct alpha_cpu_type_def tdefs[] = ALPHA_CPU_TYPE_DEFS; - debug("Alpha\n"); + i = 0; + while (tdefs[i].name != NULL) { + debug("%s", tdefs[i].name); + for (j=16 - strlen(tdefs[i].name); j>0; j--) + debug(" "); + i++; + if ((i % 4) == 0 || tdefs[i].name == NULL) + debug("\n"); + } } @@ -172,15 +180,15 @@ if (gprs) { symbol = get_symbol_name(&cpu->machine->symbol_context, cpu->pc, &offset); - debug("cpu%i:\t pc = 0x%016llx", x, (long long)cpu->pc); + debug("cpu%i:\t pc = 0x%016"PRIx64, x, (uint64_t) cpu->pc); debug(" <%s>\n", symbol != NULL? symbol : " no symbol "); for (i=0; i> 1) + ((i & 1) << 4); if ((i % 2) == 0) debug("cpu%i:\t", x); if (r != ALPHA_ZERO) - debug("%3s = 0x%016llx", alpha_regname[r], - (long long)cpu->cd.alpha.r[r]); + debug("%3s = 0x%016"PRIx64, alpha_regname[r], + (uint64_t) cpu->cd.alpha.r[r]); debug((i % 2) == 1? "\n" : " "); } } @@ -188,6 +196,102 @@ /* + * alpha_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 alpha_cpu_tlbdump(struct machine *m, int x, int rawflag) +{ +} + + +static void add_response_word(struct cpu *cpu, char *r, uint64_t value, + size_t maxlen, int len) +{ + char *format = (len == 4)? "%08"PRIx64 : "%016"PRIx64; + if (len == 4) + value &= 0xffffffffULL; + if (cpu->byte_order == EMUL_LITTLE_ENDIAN) { + if (len == 4) { + value = ((value & 0xff) << 24) + + ((value & 0xff00) << 8) + + ((value & 0xff0000) >> 8) + + ((value & 0xff000000) >> 24); + } else { + value = ((value & 0xff) << 56) + + ((value & 0xff00) << 40) + + ((value & 0xff0000) << 24) + + ((value & 0xff000000ULL) << 8) + + ((value & 0xff00000000ULL) >> 8) + + ((value & 0xff0000000000ULL) >> 24) + + ((value & 0xff000000000000ULL) >> 40) + + ((value & 0xff00000000000000ULL) >> 56); + } + } + snprintf(r + strlen(r), maxlen - strlen(r), format, (uint64_t)value); +} + + +/* + * alpha_cpu_gdb_stub(): + * + * Execute a "remote GDB" command. Returns a newly allocated response string + * on success, NULL on failure. + */ +char *alpha_cpu_gdb_stub(struct cpu *cpu, char *cmd) +{ + if (strcmp(cmd, "g") == 0) { + int i; + char *r; + size_t wlen = cpu->is_32bit? + sizeof(uint32_t) : sizeof(uint64_t); + size_t len = 1 + 76 * wlen; + r = malloc(len); + if (r == NULL) { + fprintf(stderr, "out of memory\n"); + exit(1); + } + r[0] = '\0'; + for (i=0; i<128; i++) + add_response_word(cpu, r, i, len, wlen); + return r; + } + + if (cmd[0] == 'p') { + int regnr = strtol(cmd + 1, NULL, 16); + size_t wlen = cpu->is_32bit? + sizeof(uint32_t) : sizeof(uint64_t); + size_t len = 2 * wlen + 1; + char *r = malloc(len); + r[0] = '\0'; + if (regnr >= 0 && regnr <= 31) { + add_response_word(cpu, r, + cpu->cd.alpha.r[regnr], len, wlen); + } else if (regnr >= 32 && regnr <= 62) { + add_response_word(cpu, r, + cpu->cd.alpha.f[regnr - 32], len, wlen); + } else if (regnr == 0x3f) { + add_response_word(cpu, r, cpu->cd.alpha.fpcr, + len, wlen); + } else if (regnr == 0x40) { + add_response_word(cpu, r, cpu->pc, len, wlen); + } else { + /* Unimplemented: */ + add_response_word(cpu, r, 0xcc000 + regnr, len, wlen); + } + return r; + } + + fatal("alpha_cpu_gdb_stub(): TODO\n"); + return NULL; +} + + +/* * alpha_cpu_interrupt(): */ int alpha_cpu_interrupt(struct cpu *cpu, uint64_t irq_nr) @@ -242,7 +346,7 @@ * cpu->pc for relative addresses. */ int alpha_cpu_disassemble_instr(struct cpu *cpu, unsigned char *ib, - int running, uint64_t dumpaddr, int bintrans) + int running, uint64_t dumpaddr) { uint32_t iw; uint64_t offset, tmp; @@ -261,7 +365,7 @@ if (cpu->machine->ncpus > 1 && running) debug("cpu%i:\t", cpu->cpu_id); - debug("%016llx: ", (long long)dumpaddr); + debug("%016"PRIx64": ", (uint64_t) dumpaddr); iw = ib[0] + (ib[1]<<8) + (ib[2]<<16) + (ib[3]<<24); debug("%08x\t", (int)iw); @@ -568,7 +672,7 @@ debug("jsr"); debug("\t%s,", alpha_regname[ra]); debug("(%s),", alpha_regname[rb]); - debug("0x%llx", (long long)tmp); + debug("0x%"PRIx64, (uint64_t) tmp); symbol = get_symbol_name(&cpu->machine->symbol_context, tmp, &offset); if (symbol != NULL) @@ -590,7 +694,7 @@ debug("%s\t", opcode==0x30? "br" : "bsr"); if (ra != ALPHA_ZERO) debug("%s,", alpha_regname[ra]); - debug("0x%llx", (long long)tmp); + debug("0x%"PRIx64, (uint64_t) tmp); symbol = get_symbol_name(&cpu->machine->symbol_context, tmp, &offset); if (symbol != NULL) @@ -630,7 +734,7 @@ debug("f%i,", ra); else debug("%s,", alpha_regname[ra]); - debug("0x%llx", (long long)tmp); + debug("0x%"PRIx64, (uint64_t) tmp); symbol = get_symbol_name(&cpu->machine->symbol_context, tmp, &offset); if (symbol != NULL)