25 |
* SUCH DAMAGE. |
* SUCH DAMAGE. |
26 |
* |
* |
27 |
* |
* |
28 |
* $Id: main.c,v 1.305 2007/06/15 17:02:38 debug Exp $ |
* $Id: main.c,v 1.311 2007/06/28 14:58:38 debug Exp $ |
29 |
*/ |
*/ |
30 |
|
|
31 |
#include <stdio.h> |
#include <stdio.h> |
61 |
char *progname; |
char *progname; |
62 |
|
|
63 |
size_t dyntrans_cache_size = DEFAULT_DYNTRANS_CACHE_SIZE; |
size_t dyntrans_cache_size = DEFAULT_DYNTRANS_CACHE_SIZE; |
64 |
int native_code_translation_enabled = 0; |
static int skip_srandom_call = 0; |
|
int skip_srandom_call = 0; |
|
65 |
|
|
66 |
|
|
67 |
/***************************************************************************** |
/***************************************************************************** |
196 |
*/ |
*/ |
197 |
static void usage(int longusage) |
static void usage(int longusage) |
198 |
{ |
{ |
199 |
printf("GXemul"); |
printf("GXemul "VERSION" Copyright (C) 2003-2007 Anders Gavare\n"); |
|
#ifdef VERSION |
|
|
printf(" " VERSION); |
|
|
#endif |
|
|
printf(" Copyright (C) 2003-2007 Anders Gavare\n"); |
|
200 |
printf("Read the source code and/or documentation for " |
printf("Read the source code and/or documentation for " |
201 |
"other Copyright messages.\n"); |
"other Copyright messages.\n"); |
202 |
|
|
303 |
" get a list of\n available emulation modes)\n"); |
" get a list of\n available emulation modes)\n"); |
304 |
|
|
305 |
printf("\nGeneral options:\n"); |
printf("\nGeneral options:\n"); |
|
printf(" -b enable native code generation, if available\n"); |
|
|
printf(" -B disable native code generation (this is " |
|
|
"the default)\n"); |
|
306 |
printf(" -c cmd add cmd as a command to run before starting " |
printf(" -c cmd add cmd as a command to run before starting " |
307 |
"the simulation\n"); |
"the simulation\n"); |
308 |
printf(" -D skip the srandom call at startup\n"); |
printf(" -D skip the srandom call at startup\n"); |
348 |
char *type = NULL, *subtype = NULL; |
char *type = NULL, *subtype = NULL; |
349 |
int n_cpus_set = 0; |
int n_cpus_set = 0; |
350 |
int msopts = 0; /* Machine-specific options used */ |
int msopts = 0; /* Machine-specific options used */ |
351 |
struct machine *m = emul_add_machine(emul, "default"); |
struct machine *m = emul_add_machine(emul, NULL); |
352 |
|
|
353 |
char *opts = |
char *opts = |
354 |
"bBC:c:Dd:E:e:HhI:iJj:k:KM:Nn:Oo:p:QqRrSs:TtUu:VvW:" |
"C:c:Dd:E:e:HhI:iJj:k:KM:Nn:Oo:p:QqRrSs:TtUu:VvW:" |
355 |
#ifdef WITH_X11 |
#ifdef WITH_X11 |
356 |
"XxY:" |
"XxY:" |
357 |
#endif |
#endif |
359 |
|
|
360 |
while ((ch = getopt(argc, argv, opts)) != -1) { |
while ((ch = getopt(argc, argv, opts)) != -1) { |
361 |
switch (ch) { |
switch (ch) { |
|
case 'b': |
|
|
native_code_translation_enabled = 1; |
|
|
break; |
|
|
case 'B': |
|
|
native_code_translation_enabled = 0; |
|
|
break; |
|
362 |
case 'C': |
case 'C': |
363 |
CHECK_ALLOCATION(m->cpu_name = strdup(optarg)); |
CHECK_ALLOCATION(m->cpu_name = strdup(optarg)); |
364 |
msopts = 1; |
msopts = 1; |
482 |
break; |
break; |
483 |
case 's': |
case 's': |
484 |
machine_statistics_init(m, optarg); |
machine_statistics_init(m, optarg); |
|
native_code_translation_enabled = 0; |
|
485 |
msopts = 1; |
msopts = 1; |
486 |
break; |
break; |
487 |
case 'T': |
case 'T': |
658 |
const int constant_no = 0; |
const int constant_no = 0; |
659 |
const int constant_false = 0; |
const int constant_false = 0; |
660 |
|
|
661 |
struct emul **emuls; |
struct emul *emul; |
662 |
|
int config_file = 0; |
663 |
|
|
664 |
char **diskimages = NULL; |
char **diskimages = NULL; |
665 |
int n_diskimages = 0; |
int n_diskimages = 0; |
|
int n_emuls; |
|
666 |
int i; |
int i; |
667 |
|
|
668 |
|
|
669 |
progname = argv[0]; |
progname = argv[0]; |
670 |
|
|
671 |
|
|
687 |
SETTINGS_FORMAT_BOOL, (void *)&constant_false); |
SETTINGS_FORMAT_BOOL, (void *)&constant_false); |
688 |
|
|
689 |
/* Read-only settings: */ |
/* Read-only settings: */ |
|
settings_add(global_settings, "native_code_translation_enabled", 0, |
|
|
SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, |
|
|
(void *)&native_code_translation_enabled); |
|
690 |
settings_add(global_settings, "single_step", 0, |
settings_add(global_settings, "single_step", 0, |
691 |
SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, (void *)&single_step); |
SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, (void *)&single_step); |
692 |
|
|
707 |
timer_init(); |
timer_init(); |
708 |
useremul_init(); |
useremul_init(); |
709 |
|
|
710 |
emuls = malloc(sizeof(struct emul *)); |
/* Create a simple emulation setup: */ |
711 |
CHECK_ALLOCATION(emuls); |
emul = emul_new(NULL); |
712 |
|
settings_add(global_settings, "emul", 1, |
713 |
|
SETTINGS_TYPE_SUBSETTINGS, 0, emul->settings); |
714 |
|
|
715 |
/* Allocate space for a simple emul setup: */ |
get_cmd_args(argc, argv, emul, &diskimages, &n_diskimages); |
|
n_emuls = 1; |
|
|
emuls[0] = emul_new(NULL, 0); |
|
|
settings_add(global_settings, "emul[0]", 1, |
|
|
SETTINGS_TYPE_SUBSETTINGS, 0, emuls[0]->settings); |
|
|
|
|
|
get_cmd_args(argc, argv, emuls[0], &diskimages, &n_diskimages); |
|
716 |
|
|
717 |
if (!skip_srandom_call) { |
if (!skip_srandom_call) { |
718 |
struct timeval tv; |
struct timeval tv; |
721 |
} |
} |
722 |
|
|
723 |
/* Print startup message: */ |
/* Print startup message: */ |
724 |
debug("GXemul"); |
debug("GXemul "VERSION" Copyright (C) 2003-2007 Anders Gavare\n" |
725 |
#ifdef VERSION |
"Read the source code and/or documentation for other Copyright " |
726 |
debug(" " VERSION); |
"messages.\n\n"); |
|
#endif |
|
|
debug(" Copyright (C) 2003-2007 Anders Gavare\n"); |
|
|
debug("Read the source code and/or documentation for " |
|
|
"other Copyright messages.\n\n"); |
|
|
|
|
|
if (emuls[0]->machines[0]->machine_type == MACHINE_NONE) { |
|
|
n_emuls --; |
|
|
} else { |
|
|
for (i=0; i<n_diskimages; i++) |
|
|
diskimage_add(emuls[0]->machines[0], diskimages[i]); |
|
|
} |
|
727 |
|
|
728 |
/* Simple initialization, from command line arguments: */ |
/* Simple initialization, from command line arguments: */ |
729 |
if (n_emuls > 0) { |
if (emul->machines[0]->machine_type != MACHINE_NONE) { |
730 |
|
for (i=0; i<n_diskimages; i++) |
731 |
|
diskimage_add(emul->machines[0], diskimages[i]); |
732 |
|
|
733 |
/* Make sure that there are no configuration files as well: */ |
/* Make sure that there are no configuration files as well: */ |
734 |
for (i=1; i<argc; i++) |
for (i=1; i<argc; i++) |
735 |
if (argv[i][0] == '@') { |
if (argv[i][0] == '@') { |
742 |
} |
} |
743 |
|
|
744 |
/* Initialize one emul: */ |
/* Initialize one emul: */ |
745 |
emul_simple_init(emuls[0]); |
emul_simple_init(emul); |
746 |
} |
} |
747 |
|
|
748 |
/* Initialize emulations from config files: */ |
/* Initialize an emulation from a config file: */ |
749 |
for (i=1; i<argc; i++) { |
for (i=1; i<argc; i++) { |
750 |
if (argv[i][0] == '@') { |
if (argv[i][0] == '@') { |
|
char tmpstr[50]; |
|
751 |
char *s = argv[i] + 1; |
char *s = argv[i] + 1; |
752 |
if (strlen(s) == 0 && i+1 < argc && |
|
753 |
argv[i+1][0] != '@') { |
if (config_file) { |
754 |
i++; |
fprintf(stderr, "More than one configuration " |
755 |
s = argv[i]; |
"file cannot be used.\n"); |
756 |
|
exit(1); |
757 |
} |
} |
|
n_emuls ++; |
|
|
CHECK_ALLOCATION(emuls = realloc(emuls, |
|
|
sizeof(struct emul *) * n_emuls)); |
|
758 |
|
|
759 |
/* Always allow slave xterms when using multiple |
if (strlen(s) == 0 && i+1 < argc && *argv[i+1] != '@') |
760 |
emulations: */ |
s = argv[++i]; |
761 |
|
|
762 |
|
/* Always allow slave xterms: */ |
763 |
console_allow_slaves(1); |
console_allow_slaves(1); |
764 |
|
|
765 |
/* Destroy the temporary emuls[0], since it will |
/* Destroy the temporary emul, since it will |
766 |
be overwritten: */ |
be overwritten: */ |
767 |
if (n_emuls == 1) { |
if (emul != NULL) { |
768 |
emul_destroy(emuls[0]); |
emul_destroy(emul); |
769 |
settings_remove(global_settings, "emul[0]"); |
settings_remove(global_settings, "emul"); |
770 |
|
emul = NULL; |
771 |
} |
} |
772 |
|
|
773 |
emuls[n_emuls - 1] = |
emul = emul_create_from_configfile(s); |
774 |
emul_create_from_configfile(s, n_emuls - 1); |
|
775 |
|
settings_add(global_settings, "emul", 1, |
776 |
|
SETTINGS_TYPE_SUBSETTINGS, 0, emul->settings); |
777 |
|
|
778 |
snprintf(tmpstr, sizeof(tmpstr), "emul[%i]", n_emuls-1); |
config_file = 1; |
|
settings_add(global_settings, tmpstr, 1, |
|
|
SETTINGS_TYPE_SUBSETTINGS, 0, |
|
|
emuls[n_emuls-1]->settings); |
|
779 |
} |
} |
780 |
} |
} |
781 |
|
|
782 |
if (n_emuls == 0) { |
if (emul->n_machines == 0) { |
783 |
fprintf(stderr, "No emulations defined. Maybe you forgot to " |
fprintf(stderr, "No emulations defined. Maybe you forgot to " |
784 |
"use -E xx and/or -e yy, to specify\nthe machine type." |
"use -E xx and/or -e yy, to specify\nthe machine type." |
785 |
" For example:\n\n %s -e 3max -d disk.img\n\n" |
" For example:\n\n %s -e 3max -d disk.img\n\n" |
792 |
console_warn_if_slaves_are_needed(1); |
console_warn_if_slaves_are_needed(1); |
793 |
|
|
794 |
|
|
795 |
/* Run all emulations: */ |
/* Run the emulation: */ |
796 |
emul_run(emuls, n_emuls); |
emul_run(emul); |
797 |
|
|
798 |
|
|
799 |
/* |
/* |
802 |
|
|
803 |
console_deinit(); |
console_deinit(); |
804 |
|
|
805 |
for (i=0; i<n_emuls; i++) |
emul_destroy(emul); |
|
emul_destroy(emuls[i]); |
|
806 |
|
|
807 |
settings_remove_all(global_settings); |
settings_remove_all(global_settings); |
808 |
settings_destroy(global_settings); |
settings_destroy(global_settings); |