25 |
* SUCH DAMAGE. |
* SUCH DAMAGE. |
26 |
* |
* |
27 |
* |
* |
28 |
* $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 $ |
29 |
*/ |
*/ |
30 |
|
|
31 |
#include <stdio.h> |
#include <stdio.h> |
44 |
#include "machine.h" |
#include "machine.h" |
45 |
#include "misc.h" |
#include "misc.h" |
46 |
#include "settings.h" |
#include "settings.h" |
47 |
|
#include "timer.h" |
48 |
|
|
49 |
|
|
50 |
extern volatile int single_step; |
extern volatile int single_step; |
59 |
char **extra_argv; |
char **extra_argv; |
60 |
char *progname; |
char *progname; |
61 |
|
|
62 |
int fully_deterministic = 0; |
int skip_srandom_call = 0; |
63 |
|
|
64 |
|
|
65 |
/***************************************************************************** |
/***************************************************************************** |
242 |
printf(" t tape\n"); |
printf(" t tape\n"); |
243 |
printf(" 0-7 force a specific ID\n"); |
printf(" 0-7 force a specific ID\n"); |
244 |
printf(" -G port listen to gdb remote connections on this port\n"); |
printf(" -G port listen to gdb remote connections on this port\n"); |
245 |
printf(" -I x emulate clock interrupts at x Hz (affects" |
printf(" -I hz set the main cpu frequency to hz (not used by " |
246 |
" rtc devices only, not\n"); |
"all combinations\n of machines and guest OSes)"); |
|
printf(" actual runtime speed) (this disables automatic" |
|
|
" clock adjustments)\n"); |
|
247 |
printf(" -i display each instruction as it is executed\n"); |
printf(" -i display each instruction as it is executed\n"); |
248 |
printf(" -J disable dyntrans instruction combinations\n"); |
printf(" -J disable dyntrans instruction combinations\n"); |
249 |
printf(" -j name set the name of the kernel; for DECstation " |
printf(" -j name set the name of the kernel; for DECstation " |
308 |
printf("\nGeneral options:\n"); |
printf("\nGeneral options:\n"); |
309 |
printf(" -c cmd add cmd as a command to run before starting " |
printf(" -c cmd add cmd as a command to run before starting " |
310 |
"the simulation\n"); |
"the simulation\n"); |
311 |
printf(" -D guarantee (almost) fully deterministic " |
printf(" -D skip the srandom call at startup\n"); |
|
"behaviour\n"); |
|
312 |
printf(" -H display a list of possible CPU and " |
printf(" -H display a list of possible CPU and " |
313 |
"machine types\n"); |
"machine types\n"); |
314 |
printf(" -h display this help message\n"); |
printf(" -h display this help message\n"); |
380 |
strdup(optarg); |
strdup(optarg); |
381 |
break; |
break; |
382 |
case 'D': |
case 'D': |
383 |
fully_deterministic = 1; |
skip_srandom_call = 1; |
384 |
break; |
break; |
385 |
case 'd': |
case 'd': |
386 |
/* diskimage_add() is called further down */ |
/* diskimage_add() is called further down */ |
430 |
exit(1); |
exit(1); |
431 |
case 'I': |
case 'I': |
432 |
m->emulated_hz = atoi(optarg); |
m->emulated_hz = atoi(optarg); |
|
m->automatic_clock_adjustment = 0; |
|
433 |
msopts = 1; |
msopts = 1; |
434 |
break; |
break; |
435 |
case 'i': |
case 'i': |
694 |
*/ |
*/ |
695 |
int main(int argc, char *argv[]) |
int main(int argc, char *argv[]) |
696 |
{ |
{ |
697 |
|
/* Setting constants: */ |
698 |
|
const int constant_yes = 1; |
699 |
|
const int constant_true = 1; |
700 |
|
const int constant_no = 0; |
701 |
|
const int constant_false = 0; |
702 |
|
|
703 |
struct emul **emuls; |
struct emul **emuls; |
704 |
char **diskimages = NULL; |
char **diskimages = NULL; |
705 |
int n_diskimages = 0; |
int n_diskimages = 0; |
706 |
int n_emuls; |
int n_emuls; |
707 |
int i; |
int i; |
708 |
|
|
709 |
|
|
710 |
progname = argv[0]; |
progname = argv[0]; |
711 |
|
|
712 |
/* Create the settings object, and add global settings to it: */ |
|
713 |
|
/* |
714 |
|
* Create the settings object, and add global settings to it: |
715 |
|
* |
716 |
|
* Read-only "constants": yes, no, true, false. |
717 |
|
* Global emulator settings: verbose, single_step, ... |
718 |
|
*/ |
719 |
global_settings = settings_new(); |
global_settings = settings_new(); |
720 |
|
|
721 |
|
settings_add(global_settings, "yes", 0, SETTINGS_TYPE_INT, |
722 |
|
SETTINGS_FORMAT_YESNO, (void *)&constant_yes); |
723 |
|
settings_add(global_settings, "no", 0, SETTINGS_TYPE_INT, |
724 |
|
SETTINGS_FORMAT_YESNO, (void *)&constant_no); |
725 |
|
settings_add(global_settings, "true", 0, SETTINGS_TYPE_INT, |
726 |
|
SETTINGS_FORMAT_BOOL, (void *)&constant_true); |
727 |
|
settings_add(global_settings, "false", 0, SETTINGS_TYPE_INT, |
728 |
|
SETTINGS_FORMAT_BOOL, (void *)&constant_false); |
729 |
|
|
730 |
settings_add(global_settings, "single_step", 0, |
settings_add(global_settings, "single_step", 0, |
731 |
SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, (void *)&single_step); |
SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, (void *)&single_step); |
732 |
settings_add(global_settings, "force_debugger_at_exit", 1, |
settings_add(global_settings, "force_debugger_at_exit", 1, |
733 |
SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, |
SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, |
734 |
(void *)&force_debugger_at_exit); |
(void *)&force_debugger_at_exit); |
|
settings_add(global_settings, "fully_deterministic", 0, |
|
|
SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, |
|
|
(void *)&fully_deterministic); |
|
735 |
settings_add(global_settings, "verbose", 1, |
settings_add(global_settings, "verbose", 1, |
736 |
SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, (void *)&verbose); |
SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, (void *)&verbose); |
737 |
settings_add(global_settings, "quiet_mode", 1, |
settings_add(global_settings, "quiet_mode", 1, |
742 |
cpu_init(); |
cpu_init(); |
743 |
device_init(); |
device_init(); |
744 |
machine_init(); |
machine_init(); |
745 |
|
timer_init(); |
746 |
useremul_init(); |
useremul_init(); |
747 |
|
|
748 |
emuls = malloc(sizeof(struct emul *)); |
emuls = malloc(sizeof(struct emul *)); |
758 |
fprintf(stderr, "out of memory\n"); |
fprintf(stderr, "out of memory\n"); |
759 |
exit(1); |
exit(1); |
760 |
} |
} |
761 |
|
settings_add(global_settings, "emul[0]", 1, |
762 |
|
SETTINGS_TYPE_SUBSETTINGS, 0, emuls[0]->settings); |
763 |
|
|
764 |
get_cmd_args(argc, argv, emuls[0], &diskimages, &n_diskimages); |
get_cmd_args(argc, argv, emuls[0], &diskimages, &n_diskimages); |
765 |
|
|
766 |
if (!fully_deterministic) { |
if (!skip_srandom_call) { |
767 |
/* TODO: More than just time(). Use gettimeofday(). */ |
struct timeval tv; |
768 |
srandom(time(NULL) ^ (getpid() << 12)); |
gettimeofday(&tv, NULL); |
769 |
} else { |
srandom(tv.tv_sec ^ getpid() ^ tv.tv_usec); |
|
/* Fully deterministic. -I must have been supplied. */ |
|
|
if (emuls[0]->machines[0]->automatic_clock_adjustment) { |
|
|
fatal("Cannot have -D without -I.\n"); |
|
|
exit(1); |
|
|
} |
|
770 |
} |
} |
771 |
|
|
772 |
/* Print startup message: */ |
/* Print startup message: */ |
778 |
debug("Read the source code and/or documentation for " |
debug("Read the source code and/or documentation for " |
779 |
"other Copyright messages.\n\n"); |
"other Copyright messages.\n\n"); |
780 |
|
|
781 |
if (emuls[0]->machines[0]->machine_type == MACHINE_NONE) |
if (emuls[0]->machines[0]->machine_type == MACHINE_NONE) { |
782 |
n_emuls --; |
n_emuls --; |
783 |
else { |
} else { |
784 |
for (i=0; i<n_diskimages; i++) |
for (i=0; i<n_diskimages; i++) |
785 |
diskimage_add(emuls[0]->machines[0], diskimages[i]); |
diskimage_add(emuls[0]->machines[0], diskimages[i]); |
786 |
} |
} |
805 |
/* Initialize emulations from config files: */ |
/* Initialize emulations from config files: */ |
806 |
for (i=1; i<argc; i++) { |
for (i=1; i<argc; i++) { |
807 |
if (argv[i][0] == '@') { |
if (argv[i][0] == '@') { |
808 |
|
char tmpstr[50]; |
809 |
char *s = argv[i] + 1; |
char *s = argv[i] + 1; |
810 |
if (strlen(s) == 0 && i+1 < argc && |
if (strlen(s) == 0 && i+1 < argc && |
811 |
argv[i+1][0] != '@') { |
argv[i+1][0] != '@') { |
823 |
emulations: */ |
emulations: */ |
824 |
console_allow_slaves(1); |
console_allow_slaves(1); |
825 |
|
|
826 |
|
/* Destroy the temporary emuls[0], since it will |
827 |
|
be overwritten: */ |
828 |
|
if (n_emuls == 1) { |
829 |
|
emul_destroy(emuls[0]); |
830 |
|
settings_remove(global_settings, "emul[0]"); |
831 |
|
} |
832 |
|
|
833 |
emuls[n_emuls - 1] = |
emuls[n_emuls - 1] = |
834 |
emul_create_from_configfile(s); |
emul_create_from_configfile(s); |
835 |
|
|
836 |
|
snprintf(tmpstr, sizeof(tmpstr), "emul[%i]", n_emuls-1); |
837 |
|
settings_add(global_settings, tmpstr, 1, |
838 |
|
SETTINGS_TYPE_SUBSETTINGS, 0, |
839 |
|
emuls[n_emuls-1]->settings); |
840 |
} |
} |
841 |
} |
} |
842 |
|
|
852 |
device_set_exit_on_error(0); |
device_set_exit_on_error(0); |
853 |
console_warn_if_slaves_are_needed(1); |
console_warn_if_slaves_are_needed(1); |
854 |
|
|
855 |
|
|
856 |
/* Run all emulations: */ |
/* Run all emulations: */ |
857 |
emul_run(emuls, n_emuls); |
emul_run(emuls, n_emuls); |
858 |
|
|
859 |
|
|
860 |
|
/* |
861 |
|
* Deinitialize everything: |
862 |
|
*/ |
863 |
|
|
864 |
|
console_deinit(); |
865 |
|
|
866 |
|
for (i=0; i<n_emuls; i++) |
867 |
|
emul_destroy(emuls[i]); |
868 |
|
|
869 |
|
settings_remove_all(global_settings); |
870 |
settings_destroy(global_settings); |
settings_destroy(global_settings); |
871 |
|
|
872 |
return 0; |
return 0; |