--- trunk/src/cpu_urisc.c 2007/10/08 16:18:22 9 +++ trunk/src/cpu_urisc.c 2007/10/08 16:18:27 10 @@ -25,7 +25,7 @@ * SUCH DAMAGE. * * - * $Id: cpu_urisc.c,v 1.6 2005/04/04 20:08:58 debug Exp $ + * $Id: cpu_urisc.c,v 1.8 2005/06/26 22:23:42 debug Exp $ * * URISC CPU emulation. See http://en.wikipedia.org/wiki/URISC for more * information about the "instruction set". @@ -93,27 +93,14 @@ * * Create a new URISC cpu object. */ -struct cpu *urisc_cpu_new(struct memory *mem, struct machine *machine, +int urisc_cpu_new(struct cpu *cpu, struct memory *mem, struct machine *machine, int cpu_id, char *cpu_type_name) { - struct cpu *cpu; - - if (cpu_type_name == NULL || strcmp(cpu_type_name, "URISC") != 0) - return NULL; - - cpu = malloc(sizeof(struct cpu)); - if (cpu == NULL) { - fprintf(stderr, "out of memory\n"); - exit(1); - } + if (strcmp(cpu_type_name, "URISC") != 0) + return 0; - memset(cpu, 0, sizeof(struct cpu)); - cpu->memory_rw = urisc_memory_rw; - cpu->name = cpu_type_name; - cpu->mem = mem; - cpu->machine = machine; - cpu->cpu_id = cpu_id; - cpu->byte_order = EMUL_BIG_ENDIAN; + cpu->memory_rw = urisc_memory_rw; + cpu->byte_order = EMUL_BIG_ENDIAN; cpu->cd.urisc.wordlen = 32; cpu->cd.urisc.acc_in_mem = 0; @@ -130,7 +117,7 @@ debug(")"); } - return cpu; + return 1; } @@ -178,10 +165,12 @@ symbol = get_symbol_name(&cpu->machine->symbol_context, cpu->pc, &offset); - sprintf(tmps, "cpu%%i: pc = 0x%%0%illx", (cpu->cd.urisc.wordlen/4)); + snprintf(tmps, sizeof(tmps), "cpu%%i: pc = 0x%%0%illx", + (cpu->cd.urisc.wordlen/4)); debug(tmps, x, (long long)cpu->pc); debug(" <%s>\n", symbol != NULL? symbol : " no symbol "); - sprintf(tmps, "cpu%%i: acc = 0x%%0%illx\n", (cpu->cd.urisc.wordlen/4)); + snprintf(tmps, sizeof(tmps), "cpu%%i: acc = 0x%%0%illx\n", + (cpu->cd.urisc.wordlen/4)); debug(tmps, x, (long long)cpu->cd.urisc.acc); } @@ -216,7 +205,7 @@ if (cpu->machine->ncpus > 1 && running) debug("cpu%i: ", cpu->cpu_id); - sprintf(tmps, "0x%%0%illx: 0x", nbytes * 2); + snprintf(tmps, sizeof(tmps), "0x%%0%illx: 0x", nbytes * 2); debug(tmps, (long long)dumpaddr); /* TODO: Little-endian? */ @@ -350,9 +339,9 @@ } if (cpu->machine->instruction_trace) { - sprintf(tmps, "\t[mem=0x%%0%illx", nbytes * 2); + snprintf(tmps, sizeof(tmps), "\t[mem=0x%%0%illx", nbytes * 2); debug(tmps, (long long)data); - sprintf(tmps, "; acc: 0x%%0%illx", nbytes * 2); + snprintf(tmps, sizeof(tmps), "; acc: 0x%%0%illx", nbytes * 2); debug(tmps, (long long)cpu->cd.urisc.acc); } @@ -364,7 +353,7 @@ cpu->cd.urisc.acc = data; if (cpu->machine->instruction_trace) { - sprintf(tmps, " ==> 0x%%0%illx", nbytes * 2); + snprintf(tmps, sizeof(tmps), " ==> 0x%%0%illx", nbytes * 2); debug(tmps, (long long)cpu->cd.urisc.acc); if (skip) debug(", SKIP");