--- trunk/src/cpus/cpu_alpha.c 2007/10/08 16:18:51 14 +++ trunk/src/cpus/cpu_alpha.c 2007/10/08 16:20:26 28 @@ -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_alpha.c,v 1.1 2005/08/29 14:36:41 debug Exp $ + * $Id: cpu_alpha.c,v 1.19 2006/07/20 21:52:59 debug Exp $ * * Alpha CPU emulation. * @@ -64,15 +64,25 @@ 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->run_instr = alpha_run_instr; + cpu->translate_v2p = alpha_translate_v2p; cpu->update_translation_table = alpha_update_translation_table; - cpu->invalidate_translation_caches_paddr = - alpha_invalidate_translation_caches_paddr; + cpu->invalidate_translation_caches = + alpha_invalidate_translation_caches; cpu->invalidate_code_translation = alpha_invalidate_code_translation; cpu->is_32bit = 0; @@ -81,18 +91,6 @@ 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; return 1; @@ -116,9 +114,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=13 - strlen(tdefs[i].name); j>0; j--) + debug(" "); + i++; + if ((i % 4) == 0 || tdefs[i].name == NULL) + debug("\n"); + } } @@ -172,15 +179,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,17 +195,6 @@ /* - * alpha_cpu_show_full_statistics(): - * - * Show detailed statistics on opcode usage on each cpu. - */ -void alpha_cpu_show_full_statistics(struct machine *m) -{ - fatal("alpha_cpu_show_full_statistics(): TODO\n"); -} - - -/* * alpha_cpu_tlbdump(): * * Called from the debugger to dump the TLB in a readable format. @@ -209,7 +205,88 @@ */ void alpha_cpu_tlbdump(struct machine *m, int x, int rawflag) { - fatal("alpha_cpu_tlbdump(): TODO\n"); +} + + +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; } @@ -268,7 +345,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; @@ -287,7 +364,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); @@ -513,14 +590,18 @@ break; case 0x16: switch (func & 0x7ff) { + case 0x02f: mnem = "cvttq/c"; rbrc = 1; break; case 0x080: mnem = "adds"; break; case 0x081: mnem = "subs"; break; case 0x082: mnem = "muls"; break; - case 0x083: mnem = "mult"; break; + case 0x083: mnem = "XXXx083"; break; case 0x0a0: mnem = "addt"; break; case 0x0a1: mnem = "subt"; break; case 0x0a2: mnem = "mult"; break; case 0x0a3: mnem = "divt"; break; + case 0x0a5: mnem = "cmpteq"; break; + case 0x0a6: mnem = "cmptlt"; break; + case 0x0a7: mnem = "cmptle"; break; case 0x0be: mnem = "cvtqt"; rbrc = 1; break; default:debug("UNIMPLEMENTED opcode 0x%x func 0x%x\n", opcode, func); @@ -535,6 +616,7 @@ case 0x17: switch (func & 0x7ff) { case 0x020: mnem = "fabs"; rbrc = 1; break; + case 0x021: mnem = "fneg"; rbrc = 1; break; default:debug("UNIMPLEMENTED opcode 0x%x func 0x%x\n", opcode, func); } @@ -589,7 +671,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) @@ -611,13 +693,15 @@ 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) debug("\t<%s>", symbol); debug("\n"); break; + case 0x31: + case 0x35: case 0x38: case 0x39: case 0x3a: @@ -626,7 +710,10 @@ case 0x3d: case 0x3e: case 0x3f: + floating = 0; switch (opcode) { + case 0x31: mnem = "fbeq"; floating = 1; break; + case 0x35: mnem = "fbne"; floating = 1; break; case 0x38: mnem = "blbc"; break; case 0x39: mnem = "beq"; break; case 0x3a: mnem = "blt"; break; @@ -641,8 +728,12 @@ tmp |= 0xffffffffffe00000ULL; tmp <<= 2; tmp += dumpaddr + sizeof(uint32_t); - debug("%s\t%s,", mnem, alpha_regname[ra]); - debug("0x%llx", (long long)tmp); + debug("%s\t", mnem); + if (floating) + debug("f%i,", ra); + else + debug("%s,", alpha_regname[ra]); + debug("0x%"PRIx64, (uint64_t) tmp); symbol = get_symbol_name(&cpu->machine->symbol_context, tmp, &offset); if (symbol != NULL)