1 |
/* |
/* |
2 |
* Copyright (C) 2003-2006 Anders Gavare. All rights reserved. |
* Copyright (C) 2003-2007 Anders Gavare. All rights reserved. |
3 |
* |
* |
4 |
* Redistribution and use in source and binary forms, with or without |
* Redistribution and use in source and binary forms, with or without |
5 |
* modification, are permitted provided that the following conditions are met: |
* modification, are permitted provided that the following conditions are met: |
25 |
* SUCH DAMAGE. |
* SUCH DAMAGE. |
26 |
* |
* |
27 |
* |
* |
28 |
* $Id: main.c,v 1.275 2006/06/24 19:52:28 debug Exp $ |
* $Id: main.c,v 1.293 2007/02/05 16:49:05 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; |
size_t dyntrans_cache_size = DEFAULT_DYNTRANS_CACHE_SIZE; |
63 |
|
int native_code_translation_enabled = 0; |
64 |
|
int skip_srandom_call = 0; |
65 |
|
|
66 |
|
|
67 |
/***************************************************************************** |
/***************************************************************************** |
198 |
{ |
{ |
199 |
printf("GXemul"); |
printf("GXemul"); |
200 |
#ifdef VERSION |
#ifdef VERSION |
201 |
printf("-" VERSION); |
printf(" " VERSION); |
202 |
#endif |
#endif |
203 |
printf(" Copyright (C) 2003-2006 Anders Gavare\n"); |
printf(" Copyright (C) 2003-2007 Anders Gavare\n"); |
204 |
printf("Read the source code and/or documentation for " |
printf("Read the source code and/or documentation for " |
205 |
"other Copyright messages.\n"); |
"other Copyright messages.\n"); |
206 |
|
|
225 |
"with -E.)\n"); |
"with -E.)\n"); |
226 |
|
|
227 |
printf("\nOther options:\n"); |
printf("\nOther options:\n"); |
|
printf(" -A disable alignment checks in some cases (for higher" |
|
|
" speed)\n"); |
|
228 |
printf(" -C x try to emulate a specific CPU. (Use -H to get a " |
printf(" -C x try to emulate a specific CPU. (Use -H to get a " |
229 |
"list of types.)\n"); |
"list of types.)\n"); |
230 |
printf(" -d fname add fname as a disk image. You can add \"xxx:\"" |
printf(" -d fname add fname as a disk image. You can add \"xxx:\"" |
238 |
printf(" gH;S; set geometry to H heads and S" |
printf(" gH;S; set geometry to H heads and S" |
239 |
" sectors-per-track\n"); |
" sectors-per-track\n"); |
240 |
printf(" i IDE\n"); |
printf(" i IDE\n"); |
241 |
|
printf(" oOFS; set base offset to OFS (for ISO9660" |
242 |
|
" filesystems)\n"); |
243 |
printf(" r read-only (don't allow changes to the" |
printf(" r read-only (don't allow changes to the" |
244 |
" file)\n"); |
" file)\n"); |
245 |
printf(" s SCSI\n"); |
printf(" s SCSI\n"); |
246 |
printf(" t tape\n"); |
printf(" t tape\n"); |
247 |
printf(" 0-7 force a specific ID\n"); |
printf(" 0-7 force a specific ID\n"); |
248 |
printf(" -G port listen to gdb remote connections on this port\n"); |
printf(" -G port listen to gdb remote connections on this port\n"); |
249 |
printf(" -I x emulate clock interrupts at x Hz (affects" |
printf(" -I hz set the main cpu frequency to hz (not used by " |
250 |
" rtc devices only, not\n"); |
"all combinations\n of machines and guest OSes)\n"); |
|
printf(" actual runtime speed) (this disables automatic" |
|
|
" clock adjustments)\n"); |
|
251 |
printf(" -i display each instruction as it is executed\n"); |
printf(" -i display each instruction as it is executed\n"); |
252 |
printf(" -J disable some speed tricks\n"); |
printf(" -J disable dyntrans instruction combinations\n"); |
253 |
printf(" -j name set the name of the kernel; for DECstation " |
printf(" -j name set the name of the kernel; for DECstation " |
254 |
"emulation, this passes\n the name to the bootloader," |
"emulation, this passes\n the name to the bootloader," |
255 |
" for example:\n"); |
" for example:\n"); |
278 |
printf(" -r register dumps before every instruction\n"); |
printf(" -r register dumps before every instruction\n"); |
279 |
printf(" -S initialize emulated RAM to random bytes, " |
printf(" -S initialize emulated RAM to random bytes, " |
280 |
"instead of zeroes\n"); |
"instead of zeroes\n"); |
281 |
|
printf(" -s f:name write statistics to file 'name', " |
282 |
|
"f is one or more of the following:\n"); |
283 |
|
printf(" v virtual program counter\n"); |
284 |
|
printf(" p physical equivalent of program counter\n"); |
285 |
|
printf(" i internal ic->f representation of " |
286 |
|
"the program counter\n"); |
287 |
|
printf(" and optionally:\n"); |
288 |
|
printf(" d disable statistics gathering at " |
289 |
|
"startup\n"); |
290 |
|
printf(" o overwrite instead of append\n"); |
291 |
|
printf(" -T halt on non-existant memory accesses\n"); |
292 |
printf(" -t show function trace tree\n"); |
printf(" -t show function trace tree\n"); |
293 |
printf(" -U enable slow_serial_interrupts_hack_for_linux\n"); |
printf(" -U enable slow_serial_interrupts_hack_for_linux\n"); |
294 |
#ifdef WITH_X11 |
#ifdef WITH_X11 |
311 |
#endif |
#endif |
312 |
|
|
313 |
printf("\nGeneral options:\n"); |
printf("\nGeneral options:\n"); |
314 |
|
#ifdef UNSTABLE_DEVEL |
315 |
|
printf(" -b enable native code generation\n"); |
316 |
|
printf(" -B disable native code generation\n"); |
317 |
|
#endif |
318 |
printf(" -c cmd add cmd as a command to run before starting " |
printf(" -c cmd add cmd as a command to run before starting " |
319 |
"the simulation\n"); |
"the simulation\n"); |
320 |
printf(" -D guarantee (almost) fully deterministic " |
printf(" -D skip the srandom call at startup\n"); |
|
"behaviour\n"); |
|
321 |
printf(" -H display a list of possible CPU and " |
printf(" -H display a list of possible CPU and " |
322 |
"machine types\n"); |
"machine types\n"); |
323 |
printf(" -h display this help message\n"); |
printf(" -h display this help message\n"); |
324 |
|
printf(" -k n set dyntrans translation caches to n MB (default" |
325 |
|
" size is %i MB)\n", DEFAULT_DYNTRANS_CACHE_SIZE / 1048576); |
326 |
printf(" -K force the debugger to be entered at the end " |
printf(" -K force the debugger to be entered at the end " |
327 |
"of a simulation\n"); |
"of a simulation\n"); |
328 |
printf(" -q quiet mode (don't print startup messages)\n"); |
printf(" -q quiet mode (don't print startup messages)\n"); |
363 |
struct machine *m = emul_add_machine(emul, "default"); |
struct machine *m = emul_add_machine(emul, "default"); |
364 |
|
|
365 |
char *opts = |
char *opts = |
366 |
"A" |
#ifdef UNSTABLE_DEVEL |
367 |
"C:c:Dd:E:e:G:HhI:iJj:KM:Nn:Oo:p:QqRrStU" |
"bB" |
368 |
|
#endif |
369 |
|
"C:c:Dd:E:e:G:HhI:iJj:k:KM:Nn:Oo:p:QqRrSs:TtU" |
370 |
#ifdef UNSTABLE_DEVEL |
#ifdef UNSTABLE_DEVEL |
371 |
"u:" |
"u:" |
372 |
#endif |
#endif |
378 |
|
|
379 |
while ((ch = getopt(argc, argv, opts)) != -1) { |
while ((ch = getopt(argc, argv, opts)) != -1) { |
380 |
switch (ch) { |
switch (ch) { |
381 |
case 'A': |
#ifdef UNSTABLE_DEVEL |
382 |
fprintf(stderr, "NOTE: The -A command line option" |
case 'b': |
383 |
" is DEPRECATED and will be removed soon.\n"); |
#ifndef NATIVE_CODE_GENERATION |
384 |
m->dyntrans_alignment_check = 0; |
printf("-b is not available on this host arch.\n"); |
385 |
msopts = 1; |
exit(1); |
386 |
|
#else |
387 |
|
native_code_translation_enabled = 1; |
388 |
break; |
break; |
389 |
|
#endif |
390 |
|
case 'B': |
391 |
|
native_code_translation_enabled = 0; |
392 |
|
break; |
393 |
|
#endif /* UNSTABLE_DEVEL */ |
394 |
case 'C': |
case 'C': |
395 |
m->cpu_name = strdup(optarg); |
m->cpu_name = strdup(optarg); |
396 |
msopts = 1; |
msopts = 1; |
407 |
strdup(optarg); |
strdup(optarg); |
408 |
break; |
break; |
409 |
case 'D': |
case 'D': |
410 |
fully_deterministic = 1; |
skip_srandom_call = 1; |
411 |
break; |
break; |
412 |
case 'd': |
case 'd': |
413 |
/* diskimage_add() is called further down */ |
/* diskimage_add() is called further down */ |
457 |
exit(1); |
exit(1); |
458 |
case 'I': |
case 'I': |
459 |
m->emulated_hz = atoi(optarg); |
m->emulated_hz = atoi(optarg); |
|
m->automatic_clock_adjustment = 0; |
|
460 |
msopts = 1; |
msopts = 1; |
461 |
break; |
break; |
462 |
case 'i': |
case 'i': |
464 |
msopts = 1; |
msopts = 1; |
465 |
break; |
break; |
466 |
case 'J': |
case 'J': |
467 |
m->speed_tricks = 0; |
m->allow_instruction_combinations = 0; |
468 |
msopts = 1; |
msopts = 1; |
469 |
break; |
break; |
470 |
case 'j': |
case 'j': |
475 |
} |
} |
476 |
msopts = 1; |
msopts = 1; |
477 |
break; |
break; |
478 |
|
case 'k': |
479 |
|
dyntrans_cache_size = atoi(optarg) * 1048576; |
480 |
|
if (dyntrans_cache_size < 1) { |
481 |
|
fprintf(stderr, "The dyntrans cache size must" |
482 |
|
" be at least 1 MB.\n"); |
483 |
|
exit(1); |
484 |
|
} |
485 |
|
break; |
486 |
case 'K': |
case 'K': |
487 |
force_debugger_at_exit = 1; |
force_debugger_at_exit = 1; |
488 |
break; |
break; |
544 |
m->random_mem_contents = 1; |
m->random_mem_contents = 1; |
545 |
msopts = 1; |
msopts = 1; |
546 |
break; |
break; |
547 |
|
case 's': |
548 |
|
machine_statistics_init(m, optarg); |
549 |
|
native_code_translation_enabled = 0; |
550 |
|
msopts = 1; |
551 |
|
break; |
552 |
|
case 'T': |
553 |
|
m->halt_on_nonexistant_memaccess = 1; |
554 |
|
msopts = 1; |
555 |
|
break; |
556 |
case 't': |
case 't': |
557 |
m->show_trace_tree = 1; |
m->show_trace_tree = 1; |
558 |
msopts = 1; |
msopts = 1; |
734 |
*/ |
*/ |
735 |
int main(int argc, char *argv[]) |
int main(int argc, char *argv[]) |
736 |
{ |
{ |
737 |
|
/* Setting constants: */ |
738 |
|
const int constant_yes = 1; |
739 |
|
const int constant_true = 1; |
740 |
|
const int constant_no = 0; |
741 |
|
const int constant_false = 0; |
742 |
|
|
743 |
struct emul **emuls; |
struct emul **emuls; |
744 |
char **diskimages = NULL; |
char **diskimages = NULL; |
745 |
int n_diskimages = 0; |
int n_diskimages = 0; |
746 |
int n_emuls; |
int n_emuls; |
747 |
int i; |
int i; |
748 |
|
|
749 |
|
|
750 |
|
#ifdef USE_PROFIL |
751 |
|
uint16_t samples[0x100000]; |
752 |
|
memset(samples, 0, sizeof(samples)); |
753 |
|
profil((char *)samples, sizeof(samples), (vm_offset_t) 0x400000, 8192); |
754 |
|
#endif |
755 |
|
|
756 |
|
#ifndef NATIVE_CODE_GENERATION |
757 |
|
native_code_translation_enabled = 0; |
758 |
|
#endif |
759 |
|
|
760 |
|
|
761 |
progname = argv[0]; |
progname = argv[0]; |
762 |
|
|
763 |
/* Create the settings object, and add global settings to it: */ |
|
764 |
|
/* |
765 |
|
* Create the settings object, and add global settings to it: |
766 |
|
* |
767 |
|
* Read-only "constants": yes, no, true, false. |
768 |
|
* Global emulator settings: verbose, single_step, ... |
769 |
|
*/ |
770 |
global_settings = settings_new(); |
global_settings = settings_new(); |
771 |
|
|
772 |
|
settings_add(global_settings, "yes", 0, SETTINGS_TYPE_INT, |
773 |
|
SETTINGS_FORMAT_YESNO, (void *)&constant_yes); |
774 |
|
settings_add(global_settings, "no", 0, SETTINGS_TYPE_INT, |
775 |
|
SETTINGS_FORMAT_YESNO, (void *)&constant_no); |
776 |
|
settings_add(global_settings, "true", 0, SETTINGS_TYPE_INT, |
777 |
|
SETTINGS_FORMAT_BOOL, (void *)&constant_true); |
778 |
|
settings_add(global_settings, "false", 0, SETTINGS_TYPE_INT, |
779 |
|
SETTINGS_FORMAT_BOOL, (void *)&constant_false); |
780 |
|
|
781 |
|
/* Read-only settings: */ |
782 |
|
settings_add(global_settings, "native_code_translation_enabled", 0, |
783 |
|
SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, |
784 |
|
(void *)&native_code_translation_enabled); |
785 |
settings_add(global_settings, "single_step", 0, |
settings_add(global_settings, "single_step", 0, |
786 |
SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, (void *)&single_step); |
SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, (void *)&single_step); |
787 |
|
|
788 |
|
/* Read/write settings: */ |
789 |
settings_add(global_settings, "force_debugger_at_exit", 1, |
settings_add(global_settings, "force_debugger_at_exit", 1, |
790 |
SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, |
SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, |
791 |
(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); |
|
792 |
settings_add(global_settings, "verbose", 1, |
settings_add(global_settings, "verbose", 1, |
793 |
SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, (void *)&verbose); |
SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, (void *)&verbose); |
794 |
settings_add(global_settings, "quiet_mode", 1, |
settings_add(global_settings, "quiet_mode", 1, |
799 |
cpu_init(); |
cpu_init(); |
800 |
device_init(); |
device_init(); |
801 |
machine_init(); |
machine_init(); |
802 |
|
timer_init(); |
803 |
useremul_init(); |
useremul_init(); |
804 |
|
|
805 |
emuls = malloc(sizeof(struct emul *)); |
emuls = malloc(sizeof(struct emul *)); |
810 |
|
|
811 |
/* Allocate space for a simple emul setup: */ |
/* Allocate space for a simple emul setup: */ |
812 |
n_emuls = 1; |
n_emuls = 1; |
813 |
emuls[0] = emul_new(NULL); |
emuls[0] = emul_new(NULL, 0); |
814 |
if (emuls[0] == NULL) { |
if (emuls[0] == NULL) { |
815 |
fprintf(stderr, "out of memory\n"); |
fprintf(stderr, "out of memory\n"); |
816 |
exit(1); |
exit(1); |
817 |
} |
} |
818 |
|
settings_add(global_settings, "emul[0]", 1, |
819 |
|
SETTINGS_TYPE_SUBSETTINGS, 0, emuls[0]->settings); |
820 |
|
|
821 |
get_cmd_args(argc, argv, emuls[0], &diskimages, &n_diskimages); |
get_cmd_args(argc, argv, emuls[0], &diskimages, &n_diskimages); |
822 |
|
|
823 |
if (!fully_deterministic) { |
if (!skip_srandom_call) { |
824 |
/* TODO: More than just time(). Use gettimeofday(). */ |
struct timeval tv; |
825 |
srandom(time(NULL) ^ (getpid() << 12)); |
gettimeofday(&tv, NULL); |
826 |
} 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); |
|
|
} |
|
827 |
} |
} |
828 |
|
|
829 |
/* Print startup message: */ |
/* Print startup message: */ |
830 |
debug("GXemul"); |
debug("GXemul"); |
831 |
#ifdef VERSION |
#ifdef VERSION |
832 |
debug("-" VERSION); |
debug(" " VERSION); |
833 |
#endif |
#endif |
834 |
debug(" Copyright (C) 2003-2006 Anders Gavare\n"); |
debug(" Copyright (C) 2003-2007 Anders Gavare\n"); |
835 |
debug("Read the source code and/or documentation for " |
debug("Read the source code and/or documentation for " |
836 |
"other Copyright messages.\n\n"); |
"other Copyright messages.\n\n"); |
837 |
|
|
838 |
if (emuls[0]->machines[0]->machine_type == MACHINE_NONE) |
if (emuls[0]->machines[0]->machine_type == MACHINE_NONE) { |
839 |
n_emuls --; |
n_emuls --; |
840 |
else { |
} else { |
841 |
for (i=0; i<n_diskimages; i++) |
for (i=0; i<n_diskimages; i++) |
842 |
diskimage_add(emuls[0]->machines[0], diskimages[i]); |
diskimage_add(emuls[0]->machines[0], diskimages[i]); |
843 |
} |
} |
862 |
/* Initialize emulations from config files: */ |
/* Initialize emulations from config files: */ |
863 |
for (i=1; i<argc; i++) { |
for (i=1; i<argc; i++) { |
864 |
if (argv[i][0] == '@') { |
if (argv[i][0] == '@') { |
865 |
|
char tmpstr[50]; |
866 |
char *s = argv[i] + 1; |
char *s = argv[i] + 1; |
867 |
if (strlen(s) == 0 && i+1 < argc && |
if (strlen(s) == 0 && i+1 < argc && |
868 |
argv[i+1][0] != '@') { |
argv[i+1][0] != '@') { |
880 |
emulations: */ |
emulations: */ |
881 |
console_allow_slaves(1); |
console_allow_slaves(1); |
882 |
|
|
883 |
|
/* Destroy the temporary emuls[0], since it will |
884 |
|
be overwritten: */ |
885 |
|
if (n_emuls == 1) { |
886 |
|
emul_destroy(emuls[0]); |
887 |
|
settings_remove(global_settings, "emul[0]"); |
888 |
|
} |
889 |
|
|
890 |
emuls[n_emuls - 1] = |
emuls[n_emuls - 1] = |
891 |
emul_create_from_configfile(s); |
emul_create_from_configfile(s, n_emuls - 1); |
892 |
|
|
893 |
|
snprintf(tmpstr, sizeof(tmpstr), "emul[%i]", n_emuls-1); |
894 |
|
settings_add(global_settings, tmpstr, 1, |
895 |
|
SETTINGS_TYPE_SUBSETTINGS, 0, |
896 |
|
emuls[n_emuls-1]->settings); |
897 |
} |
} |
898 |
} |
} |
899 |
|
|
909 |
device_set_exit_on_error(0); |
device_set_exit_on_error(0); |
910 |
console_warn_if_slaves_are_needed(1); |
console_warn_if_slaves_are_needed(1); |
911 |
|
|
912 |
|
|
913 |
/* Run all emulations: */ |
/* Run all emulations: */ |
914 |
emul_run(emuls, n_emuls); |
emul_run(emuls, n_emuls); |
915 |
|
|
916 |
|
|
917 |
|
/* |
918 |
|
* Deinitialize everything: |
919 |
|
*/ |
920 |
|
|
921 |
|
console_deinit(); |
922 |
|
|
923 |
|
for (i=0; i<n_emuls; i++) |
924 |
|
emul_destroy(emuls[i]); |
925 |
|
|
926 |
|
settings_remove_all(global_settings); |
927 |
settings_destroy(global_settings); |
settings_destroy(global_settings); |
928 |
|
|
929 |
|
#ifdef USE_PROFIL |
930 |
|
{ |
931 |
|
int i; |
932 |
|
FILE *f = fopen("output.txt", "w"); |
933 |
|
for (i=0; i<sizeof(samples) / sizeof(uint16_t); ++i) { |
934 |
|
if (samples[i] != 0) |
935 |
|
fprintf(f, "%i %p\n", samples[i], |
936 |
|
(void *) (size_t) (0x400000 + i * 16)); |
937 |
|
} |
938 |
|
} |
939 |
|
#endif |
940 |
|
|
941 |
return 0; |
return 0; |
942 |
} |
} |
943 |
|
|