--- trunk/src/main.c 2007/10/08 16:20:26 28 +++ trunk/src/main.c 2007/10/08 16:20:58 32 @@ -25,7 +25,7 @@ * SUCH DAMAGE. * * - * $Id: main.c,v 1.277 2006/06/30 20:22:53 debug Exp $ + * $Id: main.c,v 1.284 2006/09/19 10:50:08 debug Exp $ */ #include @@ -44,6 +44,7 @@ #include "machine.h" #include "misc.h" #include "settings.h" +#include "timer.h" extern volatile int single_step; @@ -58,7 +59,7 @@ char **extra_argv; char *progname; -int fully_deterministic = 0; +int skip_srandom_call = 0; /***************************************************************************** @@ -241,10 +242,8 @@ printf(" t tape\n"); printf(" 0-7 force a specific ID\n"); printf(" -G port listen to gdb remote connections on this port\n"); - printf(" -I x emulate clock interrupts at x Hz (affects" - " rtc devices only, not\n"); - printf(" actual runtime speed) (this disables automatic" - " clock adjustments)\n"); + printf(" -I hz set the main cpu frequency to hz (not used by " + "all combinations\n of machines and guest OSes)"); printf(" -i display each instruction as it is executed\n"); printf(" -J disable dyntrans instruction combinations\n"); printf(" -j name set the name of the kernel; for DECstation " @@ -309,8 +308,7 @@ printf("\nGeneral options:\n"); printf(" -c cmd add cmd as a command to run before starting " "the simulation\n"); - printf(" -D guarantee (almost) fully deterministic " - "behaviour\n"); + printf(" -D skip the srandom call at startup\n"); printf(" -H display a list of possible CPU and " "machine types\n"); printf(" -h display this help message\n"); @@ -382,7 +380,7 @@ strdup(optarg); break; case 'D': - fully_deterministic = 1; + skip_srandom_call = 1; break; case 'd': /* diskimage_add() is called further down */ @@ -432,7 +430,6 @@ exit(1); case 'I': m->emulated_hz = atoi(optarg); - m->automatic_clock_adjustment = 0; msopts = 1; break; case 'i': @@ -697,25 +694,44 @@ */ int main(int argc, char *argv[]) { + /* Setting constants: */ + const int constant_yes = 1; + const int constant_true = 1; + const int constant_no = 0; + const int constant_false = 0; + struct emul **emuls; char **diskimages = NULL; int n_diskimages = 0; int n_emuls; int i; + progname = argv[0]; - /* Create the settings object, and add global settings to it: */ + + /* + * Create the settings object, and add global settings to it: + * + * Read-only "constants": yes, no, true, false. + * Global emulator settings: verbose, single_step, ... + */ global_settings = settings_new(); + settings_add(global_settings, "yes", 0, SETTINGS_TYPE_INT, + SETTINGS_FORMAT_YESNO, (void *)&constant_yes); + settings_add(global_settings, "no", 0, SETTINGS_TYPE_INT, + SETTINGS_FORMAT_YESNO, (void *)&constant_no); + settings_add(global_settings, "true", 0, SETTINGS_TYPE_INT, + SETTINGS_FORMAT_BOOL, (void *)&constant_true); + settings_add(global_settings, "false", 0, SETTINGS_TYPE_INT, + SETTINGS_FORMAT_BOOL, (void *)&constant_false); + settings_add(global_settings, "single_step", 0, SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, (void *)&single_step); settings_add(global_settings, "force_debugger_at_exit", 1, SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, (void *)&force_debugger_at_exit); - settings_add(global_settings, "fully_deterministic", 0, - SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, - (void *)&fully_deterministic); settings_add(global_settings, "verbose", 1, SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, (void *)&verbose); settings_add(global_settings, "quiet_mode", 1, @@ -726,6 +742,7 @@ cpu_init(); device_init(); machine_init(); + timer_init(); useremul_init(); emuls = malloc(sizeof(struct emul *)); @@ -741,18 +758,15 @@ fprintf(stderr, "out of memory\n"); exit(1); } + settings_add(global_settings, "emul[0]", 1, + SETTINGS_TYPE_SUBSETTINGS, 0, emuls[0]->settings); get_cmd_args(argc, argv, emuls[0], &diskimages, &n_diskimages); - if (!fully_deterministic) { - /* TODO: More than just time(). Use gettimeofday(). */ - srandom(time(NULL) ^ (getpid() << 12)); - } else { - /* Fully deterministic. -I must have been supplied. */ - if (emuls[0]->machines[0]->automatic_clock_adjustment) { - fatal("Cannot have -D without -I.\n"); - exit(1); - } + if (!skip_srandom_call) { + struct timeval tv; + gettimeofday(&tv, NULL); + srandom(tv.tv_sec ^ getpid() ^ tv.tv_usec); } /* Print startup message: */ @@ -764,9 +778,9 @@ debug("Read the source code and/or documentation for " "other Copyright messages.\n\n"); - if (emuls[0]->machines[0]->machine_type == MACHINE_NONE) + if (emuls[0]->machines[0]->machine_type == MACHINE_NONE) { n_emuls --; - else { + } else { for (i=0; imachines[0], diskimages[i]); } @@ -791,6 +805,7 @@ /* Initialize emulations from config files: */ for (i=1; isettings); } } @@ -825,9 +852,21 @@ device_set_exit_on_error(0); console_warn_if_slaves_are_needed(1); + /* Run all emulations: */ emul_run(emuls, n_emuls); + + /* + * Deinitialize everything: + */ + + console_deinit(); + + for (i=0; i