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.277 2006/06/30 20:22:53 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; |
195 |
{ |
{ |
196 |
printf("GXemul"); |
printf("GXemul"); |
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", |
222 |
"with -E.)\n"); |
"with -E.)\n"); |
223 |
|
|
224 |
printf("\nOther options:\n"); |
printf("\nOther options:\n"); |
|
printf(" -A disable alignment checks in some cases (for higher" |
|
|
" speed)\n"); |
|
|
#ifdef BINTRANS |
|
|
printf(" -B disable dynamic binary translation. (translation" |
|
|
" is turned on\n by default, if the host " |
|
|
"supports it)\n"); |
|
|
#endif |
|
225 |
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 " |
226 |
"list of types.)\n"); |
"list of types.)\n"); |
227 |
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:\"" |
240 |
printf(" s SCSI\n"); |
printf(" s SCSI\n"); |
241 |
printf(" t tape\n"); |
printf(" t tape\n"); |
242 |
printf(" 0-7 force a specific ID\n"); |
printf(" 0-7 force a specific ID\n"); |
243 |
|
printf(" -G port listen to gdb remote connections on this port\n"); |
244 |
printf(" -I x emulate clock interrupts at x Hz (affects" |
printf(" -I x emulate clock interrupts at x Hz (affects" |
245 |
" rtc devices only, not\n"); |
" rtc devices only, not\n"); |
246 |
printf(" actual runtime speed) (this disables automatic" |
printf(" actual runtime speed) (this disables automatic" |
247 |
" clock adjustments)\n"); |
" clock adjustments)\n"); |
248 |
printf(" -i display each instruction as it is executed\n"); |
printf(" -i display each instruction as it is executed\n"); |
249 |
printf(" -J disable some speed tricks\n"); |
printf(" -J disable dyntrans instruction combinations\n"); |
250 |
printf(" -j name set the name of the kernel, for example:\n"); |
printf(" -j name set the name of the kernel; for DECstation " |
251 |
printf(" -j netbsd for NetBSD/pmax\n"); |
"emulation, this passes\n the name to the bootloader," |
252 |
printf(" -j bsd for OpenBSD/pmax\n"); |
" for example:\n"); |
253 |
printf(" -j vmunix for Ultrix/RISC\n"); |
printf(" -j netbsd (NetBSD/pmax) " |
254 |
|
"-j bsd (OpenBSD/pmax)\n"); |
255 |
|
printf(" -j vmsprite (Sprite/pmax) " |
256 |
|
"-j vmunix (Ultrix/RISC)\n"); |
257 |
|
printf(" For other emulation modes, if the boot disk is an" |
258 |
|
" ISO9660\n filesystem, -j sets the name of the" |
259 |
|
" kernel to load.\n"); |
260 |
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"); |
|
261 |
printf(" -N display nr of instructions/second average, at" |
printf(" -N display nr of instructions/second average, at" |
262 |
" regular intervals\n"); |
" regular intervals\n"); |
263 |
printf(" -n nr set nr of CPUs (for SMP experiments)\n"); |
printf(" -n nr set nr of CPUs (for SMP experiments)\n"); |
264 |
printf(" -O force netboot (tftp instead of disk), even when" |
printf(" -O force netboot (tftp instead of disk), even when" |
265 |
" a disk image is\n" |
" a disk image is\n" |
266 |
" present (for DECstation, SGI, and ARC emulation)\n"); |
" present (for DECstation, SGI, and ARC emulation)\n"); |
267 |
printf(" -o arg set the boot argument (for DEC, ARC, or SGI" |
printf(" -o arg set the boot argument, for DEC, ARC, or SGI" |
268 |
" emulation).\n"); |
" emulation\n"); |
269 |
printf(" Default arg for DEC is '-a', for ARC '-aN'.\n"); |
printf(" (default arg for DEC is -a, for ARC/SGI -aN)\n"); |
270 |
printf(" -p pc add a breakpoint (remember to use the '0x' " |
printf(" -p pc add a breakpoint (remember to use the '0x' " |
271 |
"prefix for hex!)\n"); |
"prefix for hex!)\n"); |
272 |
printf(" -Q no built-in PROM emulation (use this for " |
printf(" -Q no built-in PROM emulation (use this for " |
275 |
printf(" -r register dumps before every instruction\n"); |
printf(" -r register dumps before every instruction\n"); |
276 |
printf(" -S initialize emulated RAM to random bytes, " |
printf(" -S initialize emulated RAM to random bytes, " |
277 |
"instead of zeroes\n"); |
"instead of zeroes\n"); |
278 |
printf(" -T enter the single-step debugger on " |
printf(" -s f:name write statistics to file 'name', " |
279 |
"unimplemented memory accesses\n"); |
"f is one or more of the following:\n"); |
280 |
|
printf(" v virtual program counter\n"); |
281 |
|
printf(" p physical equivalent of program counter\n"); |
282 |
|
printf(" i internal ic->f representation of " |
283 |
|
"the program counter\n"); |
284 |
|
printf(" and optionally:\n"); |
285 |
|
printf(" d disable statistics gathering at " |
286 |
|
"startup\n"); |
287 |
|
printf(" o overwrite instead of append\n"); |
288 |
printf(" -t show function trace tree\n"); |
printf(" -t show function trace tree\n"); |
289 |
printf(" -U enable slow_serial_interrupts_hack_for_linux\n"); |
printf(" -U enable slow_serial_interrupts_hack_for_linux\n"); |
290 |
#ifdef WITH_X11 |
#ifdef WITH_X11 |
291 |
printf(" -X use X11\n"); |
printf(" -X use X11\n"); |
|
#endif /* WITH_X11 */ |
|
292 |
printf(" -x open up new xterms for emulated serial ports " |
printf(" -x open up new xterms for emulated serial ports " |
293 |
"(default is on when\n using configuration files, off" |
"(default is on when\n using configuration files or" |
294 |
" otherwise)\n"); |
" when X11 is used, off otherwise)\n"); |
|
#ifdef WITH_X11 |
|
295 |
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"); |
296 |
#endif /* WITH_X11 */ |
#endif /* WITH_X11 */ |
|
printf(" -y x set max_random_cycles_per_chunk to x" |
|
|
" (experimental)\n"); |
|
297 |
printf(" -Z n set nr of graphics cards, for emulating a " |
printf(" -Z n set nr of graphics cards, for emulating a " |
298 |
"dual-head or tripple-head\n" |
"dual-head or tripple-head\n" |
299 |
" environment (only for DECstation emulation)\n"); |
" environment (only for DECstation emulation)\n"); |
300 |
printf(" -z disp add disp as an X11 display to use for " |
printf(" -z disp add disp as an X11 display to use for " |
301 |
"framebuffers\n"); |
"framebuffers\n"); |
302 |
|
|
303 |
|
#ifdef UNSTABLE_DEVEL |
304 |
printf("\nUserland options:\n"); |
printf("\nUserland options:\n"); |
305 |
printf(" -u emul userland-only (syscall) emulation (use -H to" |
printf(" -u emul userland-only (syscall) emulation (use -H to" |
306 |
" get a list of\n available emulation modes)\n"); |
" get a list of\n available emulation modes)\n"); |
307 |
|
#endif |
308 |
|
|
309 |
printf("\nGeneral options:\n"); |
printf("\nGeneral options:\n"); |
310 |
printf(" -D guarantee fully deterministic behaviour\n"); |
printf(" -c cmd add cmd as a command to run before starting " |
311 |
|
"the simulation\n"); |
312 |
|
printf(" -D guarantee (almost) fully deterministic " |
313 |
|
"behaviour\n"); |
314 |
printf(" -H display a list of possible CPU and " |
printf(" -H display a list of possible CPU and " |
315 |
"machine types\n"); |
"machine types\n"); |
316 |
printf(" -h display this help message\n"); |
printf(" -h display this help message\n"); |
317 |
printf(" -K force the debugger to be entered at the end " |
printf(" -K force the debugger to be entered at the end " |
318 |
"of a simulation\n"); |
"of a simulation\n"); |
319 |
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"); |
|
320 |
printf(" -V start up in the single-step debugger, paused\n"); |
printf(" -V start up in the single-step debugger, paused\n"); |
321 |
printf(" -v verbose debug messages\n"); |
printf(" -v verbose debug messages\n"); |
322 |
printf("\n"); |
printf("\n"); |
347 |
char ***diskimagesp, int *n_diskimagesp) |
char ***diskimagesp, int *n_diskimagesp) |
348 |
{ |
{ |
349 |
int ch, res, using_switch_d = 0, using_switch_Z = 0; |
int ch, res, using_switch_d = 0, using_switch_Z = 0; |
350 |
|
int using_switch_e = 0, using_switch_E = 0; |
351 |
char *type = NULL, *subtype = NULL; |
char *type = NULL, *subtype = NULL; |
352 |
int n_cpus_set = 0; |
int n_cpus_set = 0; |
353 |
int msopts = 0; /* Machine-specific options used */ |
int msopts = 0; /* Machine-specific options used */ |
354 |
struct machine *m = emul_add_machine(emul, "default"); |
struct machine *m = emul_add_machine(emul, "default"); |
355 |
|
|
356 |
while ((ch = getopt(argc, argv, "ABC:Dd:E:e:HhI:iJj:KM:m:" |
char *opts = |
357 |
"Nn:Oo:p:QqRrSsTtUu:VvW:XxY:y:Z:z:")) != -1) { |
"C:c:Dd:E:e:G:HhI:iJj:KM:Nn:Oo:p:QqRrSs:tU" |
358 |
|
#ifdef UNSTABLE_DEVEL |
359 |
|
"u:" |
360 |
|
#endif |
361 |
|
"VvW:" |
362 |
|
#ifdef WITH_X11 |
363 |
|
"XxY:" |
364 |
|
#endif |
365 |
|
"Z:z:"; |
366 |
|
|
367 |
|
while ((ch = getopt(argc, argv, opts)) != -1) { |
368 |
switch (ch) { |
switch (ch) { |
|
case 'A': |
|
|
m->dyntrans_alignment_check = 0; |
|
|
msopts = 1; |
|
|
break; |
|
|
case 'B': |
|
|
m->bintrans_enable = 0; |
|
|
msopts = 1; |
|
|
break; |
|
369 |
case 'C': |
case 'C': |
370 |
m->cpu_name = strdup(optarg); |
m->cpu_name = strdup(optarg); |
371 |
msopts = 1; |
msopts = 1; |
372 |
break; |
break; |
373 |
|
case 'c': |
374 |
|
emul->n_debugger_cmds ++; |
375 |
|
emul->debugger_cmds = realloc(emul->debugger_cmds, |
376 |
|
emul->n_debugger_cmds * sizeof(char *)); |
377 |
|
if (emul->debugger_cmds == NULL) { |
378 |
|
fatal("out of memory\n"); |
379 |
|
exit(1); |
380 |
|
} |
381 |
|
emul->debugger_cmds[emul->n_debugger_cmds-1] = |
382 |
|
strdup(optarg); |
383 |
|
break; |
384 |
case 'D': |
case 'D': |
385 |
fully_deterministic = 1; |
fully_deterministic = 1; |
386 |
break; |
break; |
398 |
msopts = 1; |
msopts = 1; |
399 |
break; |
break; |
400 |
case 'E': |
case 'E': |
401 |
|
if (using_switch_E ++ > 0) { |
402 |
|
fprintf(stderr, "-E already used.\n"); |
403 |
|
exit(1); |
404 |
|
} |
405 |
type = optarg; |
type = optarg; |
406 |
msopts = 1; |
msopts = 1; |
407 |
break; |
break; |
408 |
case 'e': |
case 'e': |
409 |
|
if (using_switch_e ++ > 0) { |
410 |
|
fprintf(stderr, "-e already used.\n"); |
411 |
|
exit(1); |
412 |
|
} |
413 |
subtype = optarg; |
subtype = optarg; |
414 |
msopts = 1; |
msopts = 1; |
415 |
break; |
break; |
416 |
|
case 'G': |
417 |
|
m->gdb.port = atoi(optarg); |
418 |
|
if (m->gdb.port < 1 || m->gdb.port > 65535) { |
419 |
|
fprintf(stderr, "Invalid debugger port %i.\n", |
420 |
|
m->gdb.port); |
421 |
|
exit(1); |
422 |
|
} |
423 |
|
/* Note: implicit -V */ |
424 |
|
single_step = ENTER_SINGLE_STEPPING; |
425 |
|
msopts = 1; |
426 |
|
break; |
427 |
case 'H': |
case 'H': |
428 |
machine_list_available_types_and_cpus(); |
machine_list_available_types_and_cpus(); |
429 |
exit(1); |
exit(1); |
440 |
msopts = 1; |
msopts = 1; |
441 |
break; |
break; |
442 |
case 'J': |
case 'J': |
443 |
m->speed_tricks = 0; |
m->allow_instruction_combinations = 0; |
444 |
msopts = 1; |
msopts = 1; |
445 |
break; |
break; |
446 |
case 'j': |
case 'j': |
458 |
m->physical_ram_in_mb = atoi(optarg); |
m->physical_ram_in_mb = atoi(optarg); |
459 |
msopts = 1; |
msopts = 1; |
460 |
break; |
break; |
|
case 'm': |
|
|
m->max_instructions = atoi(optarg); |
|
|
msopts = 1; |
|
|
break; |
|
461 |
case 'N': |
case 'N': |
462 |
m->show_nr_of_instructions = 1; |
m->show_nr_of_instructions = 1; |
463 |
msopts = 1; |
msopts = 1; |
513 |
msopts = 1; |
msopts = 1; |
514 |
break; |
break; |
515 |
case 's': |
case 's': |
516 |
show_opcode_statistics = 1; |
machine_statistics_init(m, optarg); |
|
break; |
|
|
case 'T': |
|
|
m->single_step_on_bad_addr = 1; |
|
517 |
msopts = 1; |
msopts = 1; |
518 |
break; |
break; |
519 |
case 't': |
case 't': |
534 |
msopts = 1; |
msopts = 1; |
535 |
break; |
break; |
536 |
case 'V': |
case 'V': |
537 |
single_step = 1; |
single_step = ENTER_SINGLE_STEPPING; |
538 |
break; |
break; |
539 |
case 'v': |
case 'v': |
540 |
verbose ++; |
verbose ++; |
545 |
case 'X': |
case 'X': |
546 |
m->use_x11 = 1; |
m->use_x11 = 1; |
547 |
msopts = 1; |
msopts = 1; |
548 |
break; |
/* FALL-THROUGH */ |
549 |
case 'x': |
case 'x': |
550 |
console_allow_slaves(1); |
console_allow_slaves(1); |
551 |
break; |
break; |
561 |
} |
} |
562 |
msopts = 1; |
msopts = 1; |
563 |
break; |
break; |
|
case 'y': |
|
|
m->max_random_cycles_per_chunk = atoi(optarg); |
|
|
msopts = 1; |
|
|
break; |
|
564 |
case 'Z': |
case 'Z': |
565 |
m->n_gfx_cards = atoi(optarg); |
m->n_gfx_cards = atoi(optarg); |
566 |
using_switch_Z = 1; |
using_switch_Z = 1; |
632 |
quiet_mode = 0; |
quiet_mode = 0; |
633 |
} |
} |
634 |
|
|
|
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; |
|
|
} |
|
|
|
|
635 |
|
|
636 |
/* |
/* |
637 |
* Usually, an executable filename must be supplied. |
* Usually, an executable filename must be supplied. |
678 |
exit(1); |
exit(1); |
679 |
} |
} |
680 |
|
|
|
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 |
|
|
|
|
681 |
if (!using_switch_Z && !m->use_x11) |
if (!using_switch_Z && !m->use_x11) |
682 |
m->n_gfx_cards = 0; |
m->n_gfx_cards = 0; |
683 |
|
|
|
m->bintrans_enabled_from_start = m->bintrans_enable; |
|
|
|
|
684 |
return 0; |
return 0; |
685 |
} |
} |
686 |
|
|
705 |
|
|
706 |
progname = argv[0]; |
progname = argv[0]; |
707 |
|
|
708 |
|
/* Create the settings object, and add global settings to it: */ |
709 |
|
global_settings = settings_new(); |
710 |
|
|
711 |
|
settings_add(global_settings, "single_step", 0, |
712 |
|
SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, (void *)&single_step); |
713 |
|
settings_add(global_settings, "force_debugger_at_exit", 1, |
714 |
|
SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, |
715 |
|
(void *)&force_debugger_at_exit); |
716 |
|
settings_add(global_settings, "fully_deterministic", 0, |
717 |
|
SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, |
718 |
|
(void *)&fully_deterministic); |
719 |
|
settings_add(global_settings, "verbose", 1, |
720 |
|
SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, (void *)&verbose); |
721 |
|
settings_add(global_settings, "quiet_mode", 1, |
722 |
|
SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, (void *)&quiet_mode); |
723 |
|
|
724 |
|
/* Initialize all emulator subsystems: */ |
725 |
console_init(); |
console_init(); |
726 |
cpu_init(); |
cpu_init(); |
727 |
device_init(); |
device_init(); |
758 |
/* Print startup message: */ |
/* Print startup message: */ |
759 |
debug("GXemul"); |
debug("GXemul"); |
760 |
#ifdef VERSION |
#ifdef VERSION |
761 |
debug("-" VERSION); |
debug(" " VERSION); |
762 |
#endif |
#endif |
763 |
debug(" Copyright (C) 2003-2005 Anders Gavare\n"); |
debug(" Copyright (C) 2003-2006 Anders Gavare\n"); |
764 |
debug("Read the source code and/or documentation for " |
debug("Read the source code and/or documentation for " |
765 |
"other Copyright messages.\n\n"); |
"other Copyright messages.\n\n"); |
766 |
|
|
803 |
fprintf(stderr, "out of memory\n"); |
fprintf(stderr, "out of memory\n"); |
804 |
exit(1); |
exit(1); |
805 |
} |
} |
|
emuls[n_emuls - 1] = |
|
|
emul_create_from_configfile(s); |
|
806 |
|
|
807 |
/* Always allow slave xterms when using multiple |
/* Always allow slave xterms when using multiple |
808 |
emulations: */ |
emulations: */ |
809 |
console_allow_slaves(1); |
console_allow_slaves(1); |
810 |
|
|
811 |
|
emuls[n_emuls - 1] = |
812 |
|
emul_create_from_configfile(s); |
813 |
} |
} |
814 |
} |
} |
815 |
|
|
823 |
} |
} |
824 |
|
|
825 |
device_set_exit_on_error(0); |
device_set_exit_on_error(0); |
826 |
console_warn_if_slaves_are_needed(); |
console_warn_if_slaves_are_needed(1); |
827 |
|
|
828 |
/* Run all emulations: */ |
/* Run all emulations: */ |
829 |
emul_run(emuls, n_emuls); |
emul_run(emuls, n_emuls); |
830 |
|
|
831 |
|
settings_destroy(global_settings); |
832 |
|
|
833 |
return 0; |
return 0; |
834 |
} |
} |
835 |
|
|