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.296 2007/03/31 15:11:26 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 |
|
#ifdef TEST_NATIVE_X86 |
50 |
|
#include "native_x86.h" |
51 |
|
#endif |
52 |
|
|
53 |
|
|
54 |
extern volatile int single_step; |
extern volatile int single_step; |
63 |
char **extra_argv; |
char **extra_argv; |
64 |
char *progname; |
char *progname; |
65 |
|
|
66 |
int fully_deterministic = 0; |
size_t dyntrans_cache_size = DEFAULT_DYNTRANS_CACHE_SIZE; |
67 |
|
int native_code_translation_enabled = 0; |
68 |
|
int skip_srandom_call = 0; |
69 |
|
|
70 |
|
|
71 |
/***************************************************************************** |
/***************************************************************************** |
202 |
{ |
{ |
203 |
printf("GXemul"); |
printf("GXemul"); |
204 |
#ifdef VERSION |
#ifdef VERSION |
205 |
printf("-" VERSION); |
printf(" " VERSION); |
206 |
#endif |
#endif |
207 |
printf(" Copyright (C) 2003-2006 Anders Gavare\n"); |
printf(" Copyright (C) 2003-2007 Anders Gavare\n"); |
208 |
printf("Read the source code and/or documentation for " |
printf("Read the source code and/or documentation for " |
209 |
"other Copyright messages.\n"); |
"other Copyright messages.\n"); |
210 |
|
|
229 |
"with -E.)\n"); |
"with -E.)\n"); |
230 |
|
|
231 |
printf("\nOther options:\n"); |
printf("\nOther options:\n"); |
|
printf(" -A disable alignment checks in some cases (for higher" |
|
|
" speed)\n"); |
|
232 |
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 " |
233 |
"list of types.)\n"); |
"list of types.)\n"); |
234 |
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:\"" |
242 |
printf(" gH;S; set geometry to H heads and S" |
printf(" gH;S; set geometry to H heads and S" |
243 |
" sectors-per-track\n"); |
" sectors-per-track\n"); |
244 |
printf(" i IDE\n"); |
printf(" i IDE\n"); |
245 |
|
printf(" oOFS; set base offset to OFS (for ISO9660" |
246 |
|
" filesystems)\n"); |
247 |
printf(" r read-only (don't allow changes to the" |
printf(" r read-only (don't allow changes to the" |
248 |
" file)\n"); |
" file)\n"); |
249 |
printf(" s SCSI\n"); |
printf(" s SCSI\n"); |
250 |
printf(" t tape\n"); |
printf(" t tape\n"); |
251 |
|
printf(" V add an overlay\n"); |
252 |
printf(" 0-7 force a specific ID\n"); |
printf(" 0-7 force a specific ID\n"); |
253 |
printf(" -G port listen to gdb remote connections on this port\n"); |
printf(" -I hz set the main cpu frequency to hz (not used by " |
254 |
printf(" -I x emulate clock interrupts at x Hz (affects" |
"all combinations\n of machines and guest OSes)\n"); |
|
" rtc devices only, not\n"); |
|
|
printf(" actual runtime speed) (this disables automatic" |
|
|
" clock adjustments)\n"); |
|
255 |
printf(" -i display each instruction as it is executed\n"); |
printf(" -i display each instruction as it is executed\n"); |
256 |
printf(" -J disable some speed tricks\n"); |
printf(" -J disable dyntrans instruction combinations\n"); |
257 |
printf(" -j name set the name of the kernel; for DECstation " |
printf(" -j name set the name of the kernel; for DECstation " |
258 |
"emulation, this passes\n the name to the bootloader," |
"emulation, this passes\n the name to the bootloader," |
259 |
" for example:\n"); |
" for example:\n"); |
282 |
printf(" -r register dumps before every instruction\n"); |
printf(" -r register dumps before every instruction\n"); |
283 |
printf(" -S initialize emulated RAM to random bytes, " |
printf(" -S initialize emulated RAM to random bytes, " |
284 |
"instead of zeroes\n"); |
"instead of zeroes\n"); |
285 |
|
printf(" -s f:name write statistics to file 'name', " |
286 |
|
"f is one or more of the following:\n"); |
287 |
|
printf(" v virtual program counter\n"); |
288 |
|
printf(" p physical equivalent of program counter\n"); |
289 |
|
printf(" i internal ic->f representation of " |
290 |
|
"the program counter\n"); |
291 |
|
printf(" and optionally:\n"); |
292 |
|
printf(" d disable statistics gathering at " |
293 |
|
"startup\n"); |
294 |
|
printf(" o overwrite instead of append\n"); |
295 |
|
printf(" -T halt on non-existant memory accesses\n"); |
296 |
printf(" -t show function trace tree\n"); |
printf(" -t show function trace tree\n"); |
297 |
printf(" -U enable slow_serial_interrupts_hack_for_linux\n"); |
printf(" -U enable slow_serial_interrupts_hack_for_linux\n"); |
298 |
#ifdef WITH_X11 |
#ifdef WITH_X11 |
315 |
#endif |
#endif |
316 |
|
|
317 |
printf("\nGeneral options:\n"); |
printf("\nGeneral options:\n"); |
318 |
|
#ifdef UNSTABLE_DEVEL |
319 |
|
printf(" -b enable native code generation\n"); |
320 |
|
printf(" -B disable native code generation\n"); |
321 |
|
#endif |
322 |
printf(" -c cmd add cmd as a command to run before starting " |
printf(" -c cmd add cmd as a command to run before starting " |
323 |
"the simulation\n"); |
"the simulation\n"); |
324 |
printf(" -D guarantee (almost) fully deterministic " |
printf(" -D skip the srandom call at startup\n"); |
|
"behaviour\n"); |
|
325 |
printf(" -H display a list of possible CPU and " |
printf(" -H display a list of possible CPU and " |
326 |
"machine types\n"); |
"machine types\n"); |
327 |
printf(" -h display this help message\n"); |
printf(" -h display this help message\n"); |
328 |
|
printf(" -k n set dyntrans translation caches to n MB (default" |
329 |
|
" size is %i MB)\n", DEFAULT_DYNTRANS_CACHE_SIZE / 1048576); |
330 |
printf(" -K force the debugger to be entered at the end " |
printf(" -K force the debugger to be entered at the end " |
331 |
"of a simulation\n"); |
"of a simulation\n"); |
332 |
printf(" -q quiet mode (don't print startup messages)\n"); |
printf(" -q quiet mode (don't print startup messages)\n"); |
367 |
struct machine *m = emul_add_machine(emul, "default"); |
struct machine *m = emul_add_machine(emul, "default"); |
368 |
|
|
369 |
char *opts = |
char *opts = |
370 |
"A" |
#ifdef UNSTABLE_DEVEL |
371 |
"C:c:Dd:E:e:G:HhI:iJj:KM:Nn:Oo:p:QqRrStU" |
"bB" |
372 |
|
#endif |
373 |
|
"C:c:Dd:E:e:HhI:iJj:k:KM:Nn:Oo:p:QqRrSs:TtU" |
374 |
#ifdef UNSTABLE_DEVEL |
#ifdef UNSTABLE_DEVEL |
375 |
"u:" |
"u:" |
376 |
#endif |
#endif |
382 |
|
|
383 |
while ((ch = getopt(argc, argv, opts)) != -1) { |
while ((ch = getopt(argc, argv, opts)) != -1) { |
384 |
switch (ch) { |
switch (ch) { |
385 |
case 'A': |
#ifdef UNSTABLE_DEVEL |
386 |
fprintf(stderr, "NOTE: The -A command line option" |
case 'b': |
387 |
" is DEPRECATED and will be removed soon.\n"); |
#ifndef NATIVE_CODE_GENERATION |
388 |
m->dyntrans_alignment_check = 0; |
printf("-b is not available on this host arch.\n"); |
389 |
msopts = 1; |
exit(1); |
390 |
|
#else |
391 |
|
native_code_translation_enabled = 1; |
392 |
|
break; |
393 |
|
#endif |
394 |
|
case 'B': |
395 |
|
native_code_translation_enabled = 0; |
396 |
break; |
break; |
397 |
|
#endif /* UNSTABLE_DEVEL */ |
398 |
case 'C': |
case 'C': |
399 |
m->cpu_name = strdup(optarg); |
m->cpu_name = strdup(optarg); |
400 |
msopts = 1; |
msopts = 1; |
411 |
strdup(optarg); |
strdup(optarg); |
412 |
break; |
break; |
413 |
case 'D': |
case 'D': |
414 |
fully_deterministic = 1; |
skip_srandom_call = 1; |
415 |
break; |
break; |
416 |
case 'd': |
case 'd': |
417 |
/* diskimage_add() is called further down */ |
/* diskimage_add() is called further down */ |
442 |
subtype = optarg; |
subtype = optarg; |
443 |
msopts = 1; |
msopts = 1; |
444 |
break; |
break; |
|
case 'G': |
|
|
m->gdb.port = atoi(optarg); |
|
|
if (m->gdb.port < 1 || m->gdb.port > 65535) { |
|
|
fprintf(stderr, "Invalid debugger port %i.\n", |
|
|
m->gdb.port); |
|
|
exit(1); |
|
|
} |
|
|
/* Note: implicit -V */ |
|
|
single_step = ENTER_SINGLE_STEPPING; |
|
|
msopts = 1; |
|
|
break; |
|
445 |
case 'H': |
case 'H': |
446 |
machine_list_available_types_and_cpus(); |
machine_list_available_types_and_cpus(); |
447 |
exit(1); |
exit(1); |
450 |
exit(1); |
exit(1); |
451 |
case 'I': |
case 'I': |
452 |
m->emulated_hz = atoi(optarg); |
m->emulated_hz = atoi(optarg); |
|
m->automatic_clock_adjustment = 0; |
|
453 |
msopts = 1; |
msopts = 1; |
454 |
break; |
break; |
455 |
case 'i': |
case 'i': |
457 |
msopts = 1; |
msopts = 1; |
458 |
break; |
break; |
459 |
case 'J': |
case 'J': |
460 |
m->speed_tricks = 0; |
m->allow_instruction_combinations = 0; |
461 |
msopts = 1; |
msopts = 1; |
462 |
break; |
break; |
463 |
case 'j': |
case 'j': |
468 |
} |
} |
469 |
msopts = 1; |
msopts = 1; |
470 |
break; |
break; |
471 |
|
case 'k': |
472 |
|
dyntrans_cache_size = atoi(optarg) * 1048576; |
473 |
|
if (dyntrans_cache_size < 1) { |
474 |
|
fprintf(stderr, "The dyntrans cache size must" |
475 |
|
" be at least 1 MB.\n"); |
476 |
|
exit(1); |
477 |
|
} |
478 |
|
break; |
479 |
case 'K': |
case 'K': |
480 |
force_debugger_at_exit = 1; |
force_debugger_at_exit = 1; |
481 |
break; |
break; |
537 |
m->random_mem_contents = 1; |
m->random_mem_contents = 1; |
538 |
msopts = 1; |
msopts = 1; |
539 |
break; |
break; |
540 |
|
case 's': |
541 |
|
machine_statistics_init(m, optarg); |
542 |
|
native_code_translation_enabled = 0; |
543 |
|
msopts = 1; |
544 |
|
break; |
545 |
|
case 'T': |
546 |
|
m->halt_on_nonexistant_memaccess = 1; |
547 |
|
msopts = 1; |
548 |
|
break; |
549 |
case 't': |
case 't': |
550 |
m->show_trace_tree = 1; |
m->show_trace_tree = 1; |
551 |
msopts = 1; |
msopts = 1; |
727 |
*/ |
*/ |
728 |
int main(int argc, char *argv[]) |
int main(int argc, char *argv[]) |
729 |
{ |
{ |
730 |
|
/* Setting constants: */ |
731 |
|
const int constant_yes = 1; |
732 |
|
const int constant_true = 1; |
733 |
|
const int constant_no = 0; |
734 |
|
const int constant_false = 0; |
735 |
|
|
736 |
struct emul **emuls; |
struct emul **emuls; |
737 |
char **diskimages = NULL; |
char **diskimages = NULL; |
738 |
int n_diskimages = 0; |
int n_diskimages = 0; |
739 |
int n_emuls; |
int n_emuls; |
740 |
int i; |
int i; |
741 |
|
|
742 |
|
|
743 |
|
/* |
744 |
|
* Experimental profil() code, which works on my laptop. |
745 |
|
* Don't use it for anything else. |
746 |
|
*/ |
747 |
|
#ifdef USE_PROFIL |
748 |
|
uint16_t samples[0x100000]; |
749 |
|
memset(samples, 0, sizeof(samples)); |
750 |
|
profil((char *)samples, sizeof(samples), (vm_offset_t) 0x400000, 8192); |
751 |
|
#endif |
752 |
|
|
753 |
|
#ifndef NATIVE_CODE_GENERATION |
754 |
|
native_code_translation_enabled = 0; |
755 |
|
#endif |
756 |
|
|
757 |
|
|
758 |
|
/* Experimental test code: */ |
759 |
|
#ifdef TEST_NATIVE_X86 |
760 |
|
test_native_x86(); |
761 |
|
#endif |
762 |
|
|
763 |
|
|
764 |
|
|
765 |
progname = argv[0]; |
progname = argv[0]; |
766 |
|
|
767 |
/* Create the settings object, and add global settings to it: */ |
|
768 |
|
/* |
769 |
|
* Create the settings object, and add global settings to it: |
770 |
|
* |
771 |
|
* Read-only "constants": yes, no, true, false. |
772 |
|
* Global emulator settings: verbose, single_step, ... |
773 |
|
*/ |
774 |
global_settings = settings_new(); |
global_settings = settings_new(); |
775 |
|
|
776 |
|
settings_add(global_settings, "yes", 0, SETTINGS_TYPE_INT, |
777 |
|
SETTINGS_FORMAT_YESNO, (void *)&constant_yes); |
778 |
|
settings_add(global_settings, "no", 0, SETTINGS_TYPE_INT, |
779 |
|
SETTINGS_FORMAT_YESNO, (void *)&constant_no); |
780 |
|
settings_add(global_settings, "true", 0, SETTINGS_TYPE_INT, |
781 |
|
SETTINGS_FORMAT_BOOL, (void *)&constant_true); |
782 |
|
settings_add(global_settings, "false", 0, SETTINGS_TYPE_INT, |
783 |
|
SETTINGS_FORMAT_BOOL, (void *)&constant_false); |
784 |
|
|
785 |
|
/* Read-only settings: */ |
786 |
|
settings_add(global_settings, "native_code_translation_enabled", 0, |
787 |
|
SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, |
788 |
|
(void *)&native_code_translation_enabled); |
789 |
settings_add(global_settings, "single_step", 0, |
settings_add(global_settings, "single_step", 0, |
790 |
SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, (void *)&single_step); |
SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, (void *)&single_step); |
791 |
|
|
792 |
|
/* Read/write settings: */ |
793 |
settings_add(global_settings, "force_debugger_at_exit", 1, |
settings_add(global_settings, "force_debugger_at_exit", 1, |
794 |
SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, |
SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, |
795 |
(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); |
|
796 |
settings_add(global_settings, "verbose", 1, |
settings_add(global_settings, "verbose", 1, |
797 |
SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, (void *)&verbose); |
SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, (void *)&verbose); |
798 |
settings_add(global_settings, "quiet_mode", 1, |
settings_add(global_settings, "quiet_mode", 1, |
803 |
cpu_init(); |
cpu_init(); |
804 |
device_init(); |
device_init(); |
805 |
machine_init(); |
machine_init(); |
806 |
|
timer_init(); |
807 |
useremul_init(); |
useremul_init(); |
808 |
|
|
809 |
emuls = malloc(sizeof(struct emul *)); |
emuls = malloc(sizeof(struct emul *)); |
814 |
|
|
815 |
/* Allocate space for a simple emul setup: */ |
/* Allocate space for a simple emul setup: */ |
816 |
n_emuls = 1; |
n_emuls = 1; |
817 |
emuls[0] = emul_new(NULL); |
emuls[0] = emul_new(NULL, 0); |
818 |
if (emuls[0] == NULL) { |
if (emuls[0] == NULL) { |
819 |
fprintf(stderr, "out of memory\n"); |
fprintf(stderr, "out of memory\n"); |
820 |
exit(1); |
exit(1); |
821 |
} |
} |
822 |
|
settings_add(global_settings, "emul[0]", 1, |
823 |
|
SETTINGS_TYPE_SUBSETTINGS, 0, emuls[0]->settings); |
824 |
|
|
825 |
get_cmd_args(argc, argv, emuls[0], &diskimages, &n_diskimages); |
get_cmd_args(argc, argv, emuls[0], &diskimages, &n_diskimages); |
826 |
|
|
827 |
if (!fully_deterministic) { |
if (!skip_srandom_call) { |
828 |
/* TODO: More than just time(). Use gettimeofday(). */ |
struct timeval tv; |
829 |
srandom(time(NULL) ^ (getpid() << 12)); |
gettimeofday(&tv, NULL); |
830 |
} 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); |
|
|
} |
|
831 |
} |
} |
832 |
|
|
833 |
/* Print startup message: */ |
/* Print startup message: */ |
834 |
debug("GXemul"); |
debug("GXemul"); |
835 |
#ifdef VERSION |
#ifdef VERSION |
836 |
debug("-" VERSION); |
debug(" " VERSION); |
837 |
#endif |
#endif |
838 |
debug(" Copyright (C) 2003-2006 Anders Gavare\n"); |
debug(" Copyright (C) 2003-2007 Anders Gavare\n"); |
839 |
debug("Read the source code and/or documentation for " |
debug("Read the source code and/or documentation for " |
840 |
"other Copyright messages.\n\n"); |
"other Copyright messages.\n\n"); |
841 |
|
|
842 |
if (emuls[0]->machines[0]->machine_type == MACHINE_NONE) |
if (emuls[0]->machines[0]->machine_type == MACHINE_NONE) { |
843 |
n_emuls --; |
n_emuls --; |
844 |
else { |
} else { |
845 |
for (i=0; i<n_diskimages; i++) |
for (i=0; i<n_diskimages; i++) |
846 |
diskimage_add(emuls[0]->machines[0], diskimages[i]); |
diskimage_add(emuls[0]->machines[0], diskimages[i]); |
847 |
} |
} |
866 |
/* Initialize emulations from config files: */ |
/* Initialize emulations from config files: */ |
867 |
for (i=1; i<argc; i++) { |
for (i=1; i<argc; i++) { |
868 |
if (argv[i][0] == '@') { |
if (argv[i][0] == '@') { |
869 |
|
char tmpstr[50]; |
870 |
char *s = argv[i] + 1; |
char *s = argv[i] + 1; |
871 |
if (strlen(s) == 0 && i+1 < argc && |
if (strlen(s) == 0 && i+1 < argc && |
872 |
argv[i+1][0] != '@') { |
argv[i+1][0] != '@') { |
884 |
emulations: */ |
emulations: */ |
885 |
console_allow_slaves(1); |
console_allow_slaves(1); |
886 |
|
|
887 |
|
/* Destroy the temporary emuls[0], since it will |
888 |
|
be overwritten: */ |
889 |
|
if (n_emuls == 1) { |
890 |
|
emul_destroy(emuls[0]); |
891 |
|
settings_remove(global_settings, "emul[0]"); |
892 |
|
} |
893 |
|
|
894 |
emuls[n_emuls - 1] = |
emuls[n_emuls - 1] = |
895 |
emul_create_from_configfile(s); |
emul_create_from_configfile(s, n_emuls - 1); |
896 |
|
|
897 |
|
snprintf(tmpstr, sizeof(tmpstr), "emul[%i]", n_emuls-1); |
898 |
|
settings_add(global_settings, tmpstr, 1, |
899 |
|
SETTINGS_TYPE_SUBSETTINGS, 0, |
900 |
|
emuls[n_emuls-1]->settings); |
901 |
} |
} |
902 |
} |
} |
903 |
|
|
913 |
device_set_exit_on_error(0); |
device_set_exit_on_error(0); |
914 |
console_warn_if_slaves_are_needed(1); |
console_warn_if_slaves_are_needed(1); |
915 |
|
|
916 |
|
|
917 |
/* Run all emulations: */ |
/* Run all emulations: */ |
918 |
emul_run(emuls, n_emuls); |
emul_run(emuls, n_emuls); |
919 |
|
|
920 |
|
|
921 |
|
/* |
922 |
|
* Deinitialize everything: |
923 |
|
*/ |
924 |
|
|
925 |
|
console_deinit(); |
926 |
|
|
927 |
|
for (i=0; i<n_emuls; i++) |
928 |
|
emul_destroy(emuls[i]); |
929 |
|
|
930 |
|
settings_remove_all(global_settings); |
931 |
settings_destroy(global_settings); |
settings_destroy(global_settings); |
932 |
|
|
933 |
|
#ifdef USE_PROFIL |
934 |
|
{ |
935 |
|
int i; |
936 |
|
FILE *f = fopen("output.txt", "w"); |
937 |
|
for (i=0; i<sizeof(samples) / sizeof(uint16_t); ++i) { |
938 |
|
if (samples[i] != 0) |
939 |
|
fprintf(f, "%i %p\n", samples[i], |
940 |
|
(void *) (size_t) (0x400000 + i * 16)); |
941 |
|
} |
942 |
|
} |
943 |
|
#endif |
944 |
|
|
945 |
return 0; |
return 0; |
946 |
} |
} |
947 |
|
|