--- trunk/src/emul.c 2007/10/08 16:19:28 21 +++ trunk/src/emul.c 2007/10/08 16:19:37 22 @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2005 Anders Gavare. All rights reserved. + * Copyright (C) 2003-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: emul.c,v 1.238 2005/11/19 18:53:06 debug Exp $ + * $Id: emul.c,v 1.247 2006/02/04 12:27:12 debug Exp $ * * Emulation startup and misc. routines. */ @@ -70,6 +70,15 @@ static char *diskimage_types[] = DISKIMAGE_TYPES; +static void print_separator(void) +{ + int i = 79; + while (i-- > 0) + debug("-"); + debug("\n"); +} + + /* * add_dump_points(): * @@ -152,7 +161,7 @@ int *n_loadp, char ***load_namesp) { char str[35]; - int filenr, i, ofs, dirlen, res = 0, res2, iadd = 4; + int filenr, i, ofs, dirlen, res = 0, res2, iadd = DEBUG_INDENTATION; int found_dir; uint64_t dirofs; uint64_t fileofs, filelen; @@ -161,7 +170,7 @@ char *p, *filename_orig; char *filename = strdup(cpu->machine->boot_kernel_filename); unsigned char *filebuf = NULL; - char *tmpfilename = NULL; + char *tmpfname = NULL; char **new_array; int tmpfile_handle; @@ -207,7 +216,7 @@ fatal("WARNING: Root directory length mismatch?\n"); dirofs = (int64_t)(buf[0x8c] + (buf[0x8d] << 8) + (buf[0x8e] << 16) + - (buf[0x8f] << 24)) * 2048; + ((uint64_t)buf[0x8f] << 24)) * 2048; /* debug("root = %i bytes at 0x%llx\n", dirlen, (long long)dirofs); */ @@ -228,8 +237,9 @@ dp = dirbuf; filenr = 1; p = NULL; while (dp < dirbuf + dirlen) { - int i, nlen = dp[0]; - int x = dp[2] + (dp[3] << 8) + (dp[4] << 16) + (dp[5] << 24); + size_t i, nlen = dp[0]; + int x = dp[2] + (dp[3] << 8) + (dp[4] << 16) + + ((uint64_t)dp[5] << 24); int y = dp[6] + (dp[7] << 8); char direntry[65]; @@ -299,7 +309,7 @@ } for (;;) { - int len, i; + size_t len, i; /* Too close to another sector? Then realign. */ if ((dirofs & 2047) + 70 > 2047) { @@ -364,9 +374,9 @@ } fileofs = match_entry[2] + (match_entry[3] << 8) + - (match_entry[4] << 16) + (match_entry[5] << 24); + (match_entry[4] << 16) + ((uint64_t)match_entry[5] << 24); filelen = match_entry[10] + (match_entry[11] << 8) + - (match_entry[12] << 16) + (match_entry[13] << 24); + (match_entry[12] << 16) + ((uint64_t)match_entry[13] << 24); fileofs *= 2048; /* debug("filelen=%llx fileofs=%llx\n", (long long)filelen, @@ -379,10 +389,7 @@ goto ret; } - tmpfilename = strdup("/tmp/gxemul.XXXXXXXXXXXX"); - - debug("extracting %lli bytes into %s\n", - (long long)filelen, tmpfilename); + tmpfname = strdup("/tmp/gxemul.XXXXXXXXXXXX"); res2 = diskimage_access(m, disk_id, disk_type, 0, fileofs, filebuf, filelen); @@ -391,14 +398,16 @@ goto ret; } - tmpfile_handle = mkstemp(tmpfilename); + tmpfile_handle = mkstemp(tmpfname); if (tmpfile_handle < 0) { - fatal("could not create %s\n", tmpfilename); + fatal("could not create %s\n", tmpfname); exit(1); } write(tmpfile_handle, filebuf, filelen); close(tmpfile_handle); + debug("extracted %lli bytes into %s\n", (long long)filelen, tmpfname); + /* Add the temporary filename to the load_namesp array: */ (*n_loadp)++; new_array = malloc(sizeof(char *) * (*n_loadp)); @@ -412,11 +421,11 @@ /* This adds a Backspace char in front of the filename; this is a special hack which causes the file to be removed once it has been loaded. */ - tmpfilename = realloc(tmpfilename, strlen(tmpfilename) + 2); - memmove(tmpfilename + 1, tmpfilename, strlen(tmpfilename) + 1); - tmpfilename[0] = 8; + tmpfname = realloc(tmpfname, strlen(tmpfname) + 2); + memmove(tmpfname + 1, tmpfname, strlen(tmpfname) + 1); + tmpfname[0] = 8; - (*load_namesp)[*n_loadp - 1] = tmpfilename; + (*load_namesp)[*n_loadp - 1] = tmpfname; res = 1; @@ -469,9 +478,9 @@ int ofs = 0x200 * (partnr + 1); if (partnr == 0) n_partitions = buf[ofs + 7]; - start = (buf[ofs + 8] << 24) + (buf[ofs + 9] << 16) + + start = ((uint64_t)buf[ofs + 8] << 24) + (buf[ofs + 9] << 16) + (buf[ofs + 10] << 8) + buf[ofs + 11]; - length = (buf[ofs + 12] << 24) + (buf[ofs + 13] << 16) + + length = ((uint64_t)buf[ofs+12] << 24) + (buf[ofs + 13] << 16) + (buf[ofs + 14] << 8) + buf[ofs + 15]; debug("partition %i: '%s', type '%s', start %i, length %i\n", @@ -526,7 +535,7 @@ return 0; switch (m->machine_type) { - case MACHINE_DEC: + case MACHINE_PMAX: /* * The first few bytes of a disk contains information about * where the bootblock(s) are located. (These are all 32-bit @@ -547,7 +556,7 @@ minibuf, sizeof(minibuf)); bootblock_loadaddr = minibuf[0x10] + (minibuf[0x11] << 8) - + (minibuf[0x12] << 16) + (minibuf[0x13] << 24); + + (minibuf[0x12] << 16) + ((uint64_t)minibuf[0x13] << 24); /* Convert loadaddr to uncached: */ if ((bootblock_loadaddr & 0xf0000000ULL) != 0x80000000 && @@ -558,7 +567,7 @@ bootblock_loadaddr |= 0xffffffffa0000000ULL; bootblock_pc = minibuf[0x14] + (minibuf[0x15] << 8) - + (minibuf[0x16] << 16) + (minibuf[0x17] << 24); + + (minibuf[0x16] << 16) + ((uint64_t)minibuf[0x17] << 24); bootblock_pc &= 0x0fffffffULL; bootblock_pc |= 0xffffffffa0000000ULL; @@ -579,10 +588,10 @@ } n_blocks = minibuf[0] + (minibuf[1] << 8) - + (minibuf[2] << 16) + (minibuf[3] << 24); + + (minibuf[2] << 16) + ((uint64_t)minibuf[3] << 24); - bootblock_offset = (minibuf[4] + (minibuf[5] << 8) - + (minibuf[6] << 16) + (minibuf[7] << 24)) * 512; + bootblock_offset = (minibuf[4] + (minibuf[5] << 8) + + (minibuf[6]<<16) + ((uint64_t)minibuf[7]<<24)) * 512; if (n_blocks < 1) break; @@ -903,14 +912,11 @@ void emul_machine_setup(struct machine *m, int n_load, char **load_names, int n_devices, char **device_names) { - struct emul *emul; struct cpu *cpu; - int i, iadd=4; + int i, iadd = DEBUG_INDENTATION; uint64_t memory_amount, entrypoint = 0, gp = 0, toc = 0; int byte_order; - emul = m->emul; - debug("machine \"%s\":\n", m->name); debug_indentation(iadd); @@ -1063,6 +1069,7 @@ } diskimage_dump_info(m); + console_debug_dump(m); /* Load files (ROM code, boot code, ...) into memory: */ if (n_load == 0) { @@ -1341,7 +1348,7 @@ add_dump_points(m); /* TODO: This is MIPS-specific! */ - if (m->machine_type == MACHINE_DEC && + if (m->machine_type == MACHINE_PMAX && cpu->cd.mips.cpu_type.mmu_model == MMU3K) add_symbol_name(&m->symbol_context, 0x9fff0000, 0x10000, "r2k3k_cache", 0, 0); @@ -1357,15 +1364,6 @@ m->machine_type == MACHINE_SGI) && m->prom_emulation) add_arc_components(m); - -#if 0 -if (m->machine_type == MACHINE_IQ80321) { - store_32bit_word(cpu, 0xc0200000, 0); - store_32bit_word(cpu, 0xc0200004, 0xd0000000); -} -#endif - - debug("starting cpu%i at ", m->bootstrap_cpu); switch (m->arch) { @@ -1409,7 +1407,10 @@ break; default: - debug("0x%016llx", (long long)cpu->pc); + if (cpu->is_32bit) + debug("0x%08x", (int)cpu->pc); + else + debug("0x%016llx", (long long)cpu->pc); } debug("\n"); @@ -1424,7 +1425,7 @@ */ void emul_dumpinfo(struct emul *e) { - int j, nm, iadd = 4; + int j, nm, iadd = DEBUG_INDENTATION; if (e->net != NULL) net_dumpinfo(e->net); @@ -1453,7 +1454,7 @@ */ void emul_simple_init(struct emul *emul) { - int iadd=4; + int iadd = DEBUG_INDENTATION; struct machine *m; if (emul->n_machines != 1) { @@ -1490,7 +1491,7 @@ */ struct emul *emul_create_from_configfile(char *fname) { - int iadd = 4; + int iadd = DEBUG_INDENTATION; struct emul *e = emul_new(fname); FILE *f; char buf[128]; @@ -1544,14 +1545,28 @@ atexit(fix_console); - i = 79; - while (i-- > 0) - debug("-"); - debug("\n\n"); - /* Initialize the interactive debugger: */ debugger_init(emuls, n_emuls); + /* Run any additional debugger commands before starting: */ + for (i=0; in_debugger_cmds > 0) { + int j; + if (i == 0) + print_separator(); + for (j = 0; j < emul->n_debugger_cmds; j ++) { + debug("> %s\n", emul->debugger_cmds[j]); + debugger_execute_cmd(emul->debugger_cmds[j], + strlen(emul->debugger_cmds[j])); + } + } + } + + print_separator(); + debug("\n"); + + /* * console_init_main() makes sure that the terminal is in a * reasonable state.