1 |
/* |
/* |
2 |
* Copyright (C) 2003-2005 Anders Gavare. All rights reserved. |
* Copyright (C) 2003-2006 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.248 2005/11/23 02:17:00 debug Exp $ |
* $Id: main.c,v 1.275 2006/06/24 19:52:28 debug Exp $ |
29 |
*/ |
*/ |
30 |
|
|
31 |
#include <stdio.h> |
#include <stdio.h> |
37 |
|
|
38 |
#include "console.h" |
#include "console.h" |
39 |
#include "cpu.h" |
#include "cpu.h" |
40 |
|
#include "debugger.h" |
41 |
#include "device.h" |
#include "device.h" |
42 |
#include "diskimage.h" |
#include "diskimage.h" |
43 |
#include "emul.h" |
#include "emul.h" |
44 |
#include "machine.h" |
#include "machine.h" |
45 |
#include "misc.h" |
#include "misc.h" |
46 |
|
#include "settings.h" |
47 |
|
|
48 |
|
|
49 |
extern volatile int single_step; |
extern volatile int single_step; |
50 |
extern int force_debugger_at_exit; |
extern int force_debugger_at_exit; |
|
extern int show_opcode_statistics; |
|
51 |
|
|
52 |
extern int optind; |
extern int optind; |
53 |
extern char *optarg; |
extern char *optarg; |
54 |
|
|
55 |
|
struct settings *global_settings; |
56 |
|
|
57 |
int extra_argc; |
int extra_argc; |
58 |
char **extra_argv; |
char **extra_argv; |
59 |
char *progname; |
char *progname; |
197 |
#ifdef VERSION |
#ifdef VERSION |
198 |
printf("-" VERSION); |
printf("-" VERSION); |
199 |
#endif |
#endif |
200 |
printf(" Copyright (C) 2003-2005 Anders Gavare\n"); |
printf(" Copyright (C) 2003-2006 Anders Gavare\n"); |
201 |
printf("Read the source code and/or documentation for " |
printf("Read the source code and/or documentation for " |
202 |
"other Copyright messages.\n"); |
"other Copyright messages.\n"); |
203 |
|
|
204 |
printf("\nusage: %s [machine, other, and general options] [file " |
printf("\nusage: %s [machine, other, and general options] [file " |
205 |
"[...]]\n", progname); |
"[...]]\n", progname); |
206 |
printf(" or %s [general options] @configfile\n", progname); |
printf(" or %s [general options] @configfile\n", progname); |
207 |
|
#ifdef UNSTABLE_DEVEL |
208 |
printf(" or %s [userland, other, and general options] file " |
printf(" or %s [userland, other, and general options] file " |
209 |
"[args ...]\n", progname); |
"[args ...]\n", progname); |
210 |
|
#endif |
211 |
|
|
212 |
if (!longusage) { |
if (!longusage) { |
213 |
printf("\nRun %s -h for help on command line options.\n", |
printf("\nRun %s -h for help on command line options.\n", |
224 |
printf("\nOther options:\n"); |
printf("\nOther options:\n"); |
225 |
printf(" -A disable alignment checks in some cases (for higher" |
printf(" -A disable alignment checks in some cases (for higher" |
226 |
" speed)\n"); |
" speed)\n"); |
|
#ifdef BINTRANS |
|
|
printf(" -B disable dynamic binary translation. (translation" |
|
|
" is turned on\n by default, if the host " |
|
|
"supports it)\n"); |
|
|
#endif |
|
227 |
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 " |
228 |
"list of types.)\n"); |
"list of types.)\n"); |
229 |
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(" s SCSI\n"); |
printf(" s SCSI\n"); |
243 |
printf(" t tape\n"); |
printf(" t tape\n"); |
244 |
printf(" 0-7 force a specific ID\n"); |
printf(" 0-7 force a specific ID\n"); |
245 |
|
printf(" -G port listen to gdb remote connections on this port\n"); |
246 |
printf(" -I x emulate clock interrupts at x Hz (affects" |
printf(" -I x emulate clock interrupts at x Hz (affects" |
247 |
" rtc devices only, not\n"); |
" rtc devices only, not\n"); |
248 |
printf(" actual runtime speed) (this disables automatic" |
printf(" actual runtime speed) (this disables automatic" |
249 |
" clock adjustments)\n"); |
" clock adjustments)\n"); |
250 |
printf(" -i display each instruction as it is executed\n"); |
printf(" -i display each instruction as it is executed\n"); |
251 |
printf(" -J disable some speed tricks\n"); |
printf(" -J disable some speed tricks\n"); |
252 |
printf(" -j name set the name of the kernel, for example:\n"); |
printf(" -j name set the name of the kernel; for DECstation " |
253 |
printf(" -j netbsd for NetBSD/pmax\n"); |
"emulation, this passes\n the name to the bootloader," |
254 |
printf(" -j bsd for OpenBSD/pmax\n"); |
" for example:\n"); |
255 |
printf(" -j vmunix for Ultrix/RISC\n"); |
printf(" -j netbsd (NetBSD/pmax) " |
256 |
|
"-j bsd (OpenBSD/pmax)\n"); |
257 |
|
printf(" -j vmsprite (Sprite/pmax) " |
258 |
|
"-j vmunix (Ultrix/RISC)\n"); |
259 |
|
printf(" For other emulation modes, if the boot disk is an" |
260 |
|
" ISO9660\n filesystem, -j sets the name of the" |
261 |
|
" kernel to load.\n"); |
262 |
printf(" -M m emulate m MBs of physical RAM\n"); |
printf(" -M m emulate m MBs of physical RAM\n"); |
|
printf(" -m nr run at most nr instructions (on any cpu)\n"); |
|
263 |
printf(" -N display nr of instructions/second average, at" |
printf(" -N display nr of instructions/second average, at" |
264 |
" regular intervals\n"); |
" regular intervals\n"); |
265 |
printf(" -n nr set nr of CPUs (for SMP experiments)\n"); |
printf(" -n nr set nr of CPUs (for SMP experiments)\n"); |
266 |
printf(" -O force netboot (tftp instead of disk), even when" |
printf(" -O force netboot (tftp instead of disk), even when" |
267 |
" a disk image is\n" |
" a disk image is\n" |
268 |
" present (for DECstation, SGI, and ARC emulation)\n"); |
" present (for DECstation, SGI, and ARC emulation)\n"); |
269 |
printf(" -o arg set the boot argument (for DEC, ARC, or SGI" |
printf(" -o arg set the boot argument, for DEC, ARC, or SGI" |
270 |
" emulation).\n"); |
" emulation\n"); |
271 |
printf(" Default arg for DEC is '-a', for ARC '-aN'.\n"); |
printf(" (default arg for DEC is -a, for ARC/SGI -aN)\n"); |
272 |
printf(" -p pc add a breakpoint (remember to use the '0x' " |
printf(" -p pc add a breakpoint (remember to use the '0x' " |
273 |
"prefix for hex!)\n"); |
"prefix for hex!)\n"); |
274 |
printf(" -Q no built-in PROM emulation (use this for " |
printf(" -Q no built-in PROM emulation (use this for " |
277 |
printf(" -r register dumps before every instruction\n"); |
printf(" -r register dumps before every instruction\n"); |
278 |
printf(" -S initialize emulated RAM to random bytes, " |
printf(" -S initialize emulated RAM to random bytes, " |
279 |
"instead of zeroes\n"); |
"instead of zeroes\n"); |
|
printf(" -T enter the single-step debugger on " |
|
|
"unimplemented memory accesses\n"); |
|
280 |
printf(" -t show function trace tree\n"); |
printf(" -t show function trace tree\n"); |
281 |
printf(" -U enable slow_serial_interrupts_hack_for_linux\n"); |
printf(" -U enable slow_serial_interrupts_hack_for_linux\n"); |
282 |
#ifdef WITH_X11 |
#ifdef WITH_X11 |
283 |
printf(" -X use X11\n"); |
printf(" -X use X11\n"); |
|
#endif /* WITH_X11 */ |
|
284 |
printf(" -x open up new xterms for emulated serial ports " |
printf(" -x open up new xterms for emulated serial ports " |
285 |
"(default is on when\n using configuration files, off" |
"(default is on when\n using configuration files or" |
286 |
" otherwise)\n"); |
" when X11 is used, off otherwise)\n"); |
|
#ifdef WITH_X11 |
|
287 |
printf(" -Y n scale down framebuffer windows by n x n times\n"); |
printf(" -Y n scale down framebuffer windows by n x n times\n"); |
288 |
#endif /* WITH_X11 */ |
#endif /* WITH_X11 */ |
|
printf(" -y x set max_random_cycles_per_chunk to x" |
|
|
" (experimental)\n"); |
|
289 |
printf(" -Z n set nr of graphics cards, for emulating a " |
printf(" -Z n set nr of graphics cards, for emulating a " |
290 |
"dual-head or tripple-head\n" |
"dual-head or tripple-head\n" |
291 |
" environment (only for DECstation emulation)\n"); |
" environment (only for DECstation emulation)\n"); |
292 |
printf(" -z disp add disp as an X11 display to use for " |
printf(" -z disp add disp as an X11 display to use for " |
293 |
"framebuffers\n"); |
"framebuffers\n"); |
294 |
|
|
295 |
|
#ifdef UNSTABLE_DEVEL |
296 |
printf("\nUserland options:\n"); |
printf("\nUserland options:\n"); |
297 |
printf(" -u emul userland-only (syscall) emulation (use -H to" |
printf(" -u emul userland-only (syscall) emulation (use -H to" |
298 |
" get a list of\n available emulation modes)\n"); |
" get a list of\n available emulation modes)\n"); |
299 |
|
#endif |
300 |
|
|
301 |
printf("\nGeneral options:\n"); |
printf("\nGeneral options:\n"); |
302 |
printf(" -D guarantee fully deterministic behaviour\n"); |
printf(" -c cmd add cmd as a command to run before starting " |
303 |
|
"the simulation\n"); |
304 |
|
printf(" -D guarantee (almost) fully deterministic " |
305 |
|
"behaviour\n"); |
306 |
printf(" -H display a list of possible CPU and " |
printf(" -H display a list of possible CPU and " |
307 |
"machine types\n"); |
"machine types\n"); |
308 |
printf(" -h display this help message\n"); |
printf(" -h display this help message\n"); |
309 |
printf(" -K force the debugger to be entered at the end " |
printf(" -K force the debugger to be entered at the end " |
310 |
"of a simulation\n"); |
"of a simulation\n"); |
311 |
printf(" -q quiet mode (don't print startup messages)\n"); |
printf(" -q quiet mode (don't print startup messages)\n"); |
|
printf(" -s show opcode usage statistics after simulation\n"); |
|
312 |
printf(" -V start up in the single-step debugger, paused\n"); |
printf(" -V start up in the single-step debugger, paused\n"); |
313 |
printf(" -v verbose debug messages\n"); |
printf(" -v verbose debug messages\n"); |
314 |
printf("\n"); |
printf("\n"); |
339 |
char ***diskimagesp, int *n_diskimagesp) |
char ***diskimagesp, int *n_diskimagesp) |
340 |
{ |
{ |
341 |
int ch, res, using_switch_d = 0, using_switch_Z = 0; |
int ch, res, using_switch_d = 0, using_switch_Z = 0; |
342 |
|
int using_switch_e = 0, using_switch_E = 0; |
343 |
char *type = NULL, *subtype = NULL; |
char *type = NULL, *subtype = NULL; |
344 |
int n_cpus_set = 0; |
int n_cpus_set = 0; |
345 |
int msopts = 0; /* Machine-specific options used */ |
int msopts = 0; /* Machine-specific options used */ |
346 |
struct machine *m = emul_add_machine(emul, "default"); |
struct machine *m = emul_add_machine(emul, "default"); |
347 |
|
|
348 |
while ((ch = getopt(argc, argv, "ABC:Dd:E:e:HhI:iJj:KM:m:" |
char *opts = |
349 |
"Nn:Oo:p:QqRrSsTtUu:VvW:XxY:y:Z:z:")) != -1) { |
"A" |
350 |
|
"C:c:Dd:E:e:G:HhI:iJj:KM:Nn:Oo:p:QqRrStU" |
351 |
|
#ifdef UNSTABLE_DEVEL |
352 |
|
"u:" |
353 |
|
#endif |
354 |
|
"VvW:" |
355 |
|
#ifdef WITH_X11 |
356 |
|
"XxY:" |
357 |
|
#endif |
358 |
|
"Z:z:"; |
359 |
|
|
360 |
|
while ((ch = getopt(argc, argv, opts)) != -1) { |
361 |
switch (ch) { |
switch (ch) { |
362 |
case 'A': |
case 'A': |
363 |
|
fprintf(stderr, "NOTE: The -A command line option" |
364 |
|
" is DEPRECATED and will be removed soon.\n"); |
365 |
m->dyntrans_alignment_check = 0; |
m->dyntrans_alignment_check = 0; |
366 |
msopts = 1; |
msopts = 1; |
367 |
break; |
break; |
|
case 'B': |
|
|
m->bintrans_enable = 0; |
|
|
msopts = 1; |
|
|
break; |
|
368 |
case 'C': |
case 'C': |
369 |
m->cpu_name = strdup(optarg); |
m->cpu_name = strdup(optarg); |
370 |
msopts = 1; |
msopts = 1; |
371 |
break; |
break; |
372 |
|
case 'c': |
373 |
|
emul->n_debugger_cmds ++; |
374 |
|
emul->debugger_cmds = realloc(emul->debugger_cmds, |
375 |
|
emul->n_debugger_cmds * sizeof(char *)); |
376 |
|
if (emul->debugger_cmds == NULL) { |
377 |
|
fatal("out of memory\n"); |
378 |
|
exit(1); |
379 |
|
} |
380 |
|
emul->debugger_cmds[emul->n_debugger_cmds-1] = |
381 |
|
strdup(optarg); |
382 |
|
break; |
383 |
case 'D': |
case 'D': |
384 |
fully_deterministic = 1; |
fully_deterministic = 1; |
385 |
break; |
break; |
397 |
msopts = 1; |
msopts = 1; |
398 |
break; |
break; |
399 |
case 'E': |
case 'E': |
400 |
|
if (using_switch_E ++ > 0) { |
401 |
|
fprintf(stderr, "-E already used.\n"); |
402 |
|
exit(1); |
403 |
|
} |
404 |
type = optarg; |
type = optarg; |
405 |
msopts = 1; |
msopts = 1; |
406 |
break; |
break; |
407 |
case 'e': |
case 'e': |
408 |
|
if (using_switch_e ++ > 0) { |
409 |
|
fprintf(stderr, "-e already used.\n"); |
410 |
|
exit(1); |
411 |
|
} |
412 |
subtype = optarg; |
subtype = optarg; |
413 |
msopts = 1; |
msopts = 1; |
414 |
break; |
break; |
415 |
|
case 'G': |
416 |
|
m->gdb.port = atoi(optarg); |
417 |
|
if (m->gdb.port < 1 || m->gdb.port > 65535) { |
418 |
|
fprintf(stderr, "Invalid debugger port %i.\n", |
419 |
|
m->gdb.port); |
420 |
|
exit(1); |
421 |
|
} |
422 |
|
/* Note: implicit -V */ |
423 |
|
single_step = ENTER_SINGLE_STEPPING; |
424 |
|
msopts = 1; |
425 |
|
break; |
426 |
case 'H': |
case 'H': |
427 |
machine_list_available_types_and_cpus(); |
machine_list_available_types_and_cpus(); |
428 |
exit(1); |
exit(1); |
457 |
m->physical_ram_in_mb = atoi(optarg); |
m->physical_ram_in_mb = atoi(optarg); |
458 |
msopts = 1; |
msopts = 1; |
459 |
break; |
break; |
|
case 'm': |
|
|
m->max_instructions = atoi(optarg); |
|
|
msopts = 1; |
|
|
break; |
|
460 |
case 'N': |
case 'N': |
461 |
m->show_nr_of_instructions = 1; |
m->show_nr_of_instructions = 1; |
462 |
msopts = 1; |
msopts = 1; |
511 |
m->random_mem_contents = 1; |
m->random_mem_contents = 1; |
512 |
msopts = 1; |
msopts = 1; |
513 |
break; |
break; |
|
case 's': |
|
|
show_opcode_statistics = 1; |
|
|
break; |
|
|
case 'T': |
|
|
m->single_step_on_bad_addr = 1; |
|
|
msopts = 1; |
|
|
break; |
|
514 |
case 't': |
case 't': |
515 |
m->show_trace_tree = 1; |
m->show_trace_tree = 1; |
516 |
msopts = 1; |
msopts = 1; |
529 |
msopts = 1; |
msopts = 1; |
530 |
break; |
break; |
531 |
case 'V': |
case 'V': |
532 |
single_step = 1; |
single_step = ENTER_SINGLE_STEPPING; |
533 |
break; |
break; |
534 |
case 'v': |
case 'v': |
535 |
verbose ++; |
verbose ++; |
540 |
case 'X': |
case 'X': |
541 |
m->use_x11 = 1; |
m->use_x11 = 1; |
542 |
msopts = 1; |
msopts = 1; |
543 |
break; |
/* FALL-THROUGH */ |
544 |
case 'x': |
case 'x': |
545 |
console_allow_slaves(1); |
console_allow_slaves(1); |
546 |
break; |
break; |
556 |
} |
} |
557 |
msopts = 1; |
msopts = 1; |
558 |
break; |
break; |
|
case 'y': |
|
|
m->max_random_cycles_per_chunk = atoi(optarg); |
|
|
msopts = 1; |
|
|
break; |
|
559 |
case 'Z': |
case 'Z': |
560 |
m->n_gfx_cards = atoi(optarg); |
m->n_gfx_cards = atoi(optarg); |
561 |
using_switch_Z = 1; |
using_switch_Z = 1; |
627 |
quiet_mode = 0; |
quiet_mode = 0; |
628 |
} |
} |
629 |
|
|
|
if ((m->instruction_trace || m->register_dump || m->show_trace_tree) |
|
|
&& m->bintrans_enable) { |
|
|
if (m->arch == ARCH_MIPS) |
|
|
fprintf(stderr, "Implicitly turning off bintrans.\n"); |
|
|
m->bintrans_enable = 0; |
|
|
} |
|
|
|
|
630 |
|
|
631 |
/* |
/* |
632 |
* Usually, an executable filename must be supplied. |
* Usually, an executable filename must be supplied. |
673 |
exit(1); |
exit(1); |
674 |
} |
} |
675 |
|
|
|
if (m->bintrans_enable && m->arch == ARCH_MIPS) { |
|
|
m->speed_tricks = 0; |
|
|
/* TODO: Print a warning about this? */ |
|
|
} |
|
|
|
|
|
if (m->n_breakpoints > 0 && |
|
|
m->bintrans_enable && m->arch == ARCH_MIPS) { |
|
|
fprintf(stderr, "Breakpoints and MIPS binary translation " |
|
|
"don't work too well together right now.\n"); |
|
|
exit(1); |
|
|
} |
|
|
|
|
|
#ifndef BINTRANS |
|
|
if (m->bintrans_enable) { |
|
|
fprintf(stderr, "WARNING: %s was compiled without " |
|
|
"bintrans support. Ignoring -b.\n", progname); |
|
|
m->bintrans_enable = 0; |
|
|
} |
|
|
#endif |
|
|
|
|
|
#ifndef WITH_X11 |
|
|
if (m->use_x11) { |
|
|
fprintf(stderr, "WARNING: %s was compiled without " |
|
|
"X11 support. Ignoring -X.\n", progname); |
|
|
m->use_x11 = 0; |
|
|
} |
|
|
#endif |
|
|
|
|
676 |
if (!using_switch_Z && !m->use_x11) |
if (!using_switch_Z && !m->use_x11) |
677 |
m->n_gfx_cards = 0; |
m->n_gfx_cards = 0; |
678 |
|
|
|
m->bintrans_enabled_from_start = m->bintrans_enable; |
|
|
|
|
679 |
return 0; |
return 0; |
680 |
} |
} |
681 |
|
|
700 |
|
|
701 |
progname = argv[0]; |
progname = argv[0]; |
702 |
|
|
703 |
|
/* Create the settings object, and add global settings to it: */ |
704 |
|
global_settings = settings_new(); |
705 |
|
|
706 |
|
settings_add(global_settings, "single_step", 0, |
707 |
|
SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, (void *)&single_step); |
708 |
|
settings_add(global_settings, "force_debugger_at_exit", 1, |
709 |
|
SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, |
710 |
|
(void *)&force_debugger_at_exit); |
711 |
|
settings_add(global_settings, "fully_deterministic", 0, |
712 |
|
SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, |
713 |
|
(void *)&fully_deterministic); |
714 |
|
settings_add(global_settings, "verbose", 1, |
715 |
|
SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, (void *)&verbose); |
716 |
|
settings_add(global_settings, "quiet_mode", 1, |
717 |
|
SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, (void *)&quiet_mode); |
718 |
|
|
719 |
|
/* Initialize all emulator subsystems: */ |
720 |
console_init(); |
console_init(); |
721 |
cpu_init(); |
cpu_init(); |
722 |
device_init(); |
device_init(); |
755 |
#ifdef VERSION |
#ifdef VERSION |
756 |
debug("-" VERSION); |
debug("-" VERSION); |
757 |
#endif |
#endif |
758 |
debug(" Copyright (C) 2003-2005 Anders Gavare\n"); |
debug(" Copyright (C) 2003-2006 Anders Gavare\n"); |
759 |
debug("Read the source code and/or documentation for " |
debug("Read the source code and/or documentation for " |
760 |
"other Copyright messages.\n\n"); |
"other Copyright messages.\n\n"); |
761 |
|
|
798 |
fprintf(stderr, "out of memory\n"); |
fprintf(stderr, "out of memory\n"); |
799 |
exit(1); |
exit(1); |
800 |
} |
} |
|
emuls[n_emuls - 1] = |
|
|
emul_create_from_configfile(s); |
|
801 |
|
|
802 |
/* Always allow slave xterms when using multiple |
/* Always allow slave xterms when using multiple |
803 |
emulations: */ |
emulations: */ |
804 |
console_allow_slaves(1); |
console_allow_slaves(1); |
805 |
|
|
806 |
|
emuls[n_emuls - 1] = |
807 |
|
emul_create_from_configfile(s); |
808 |
} |
} |
809 |
} |
} |
810 |
|
|
818 |
} |
} |
819 |
|
|
820 |
device_set_exit_on_error(0); |
device_set_exit_on_error(0); |
821 |
console_warn_if_slaves_are_needed(); |
console_warn_if_slaves_are_needed(1); |
822 |
|
|
823 |
/* Run all emulations: */ |
/* Run all emulations: */ |
824 |
emul_run(emuls, n_emuls); |
emul_run(emuls, n_emuls); |
825 |
|
|
826 |
|
settings_destroy(global_settings); |
827 |
|
|
828 |
return 0; |
return 0; |
829 |
} |
} |
830 |
|
|