--- trunk/src/main.c 2007/10/08 16:18:11 6 +++ trunk/src/main.c 2007/10/08 16:20:10 26 @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2005 Anders Gavare. All rights reserved. + * Copyright (C) 2003-2006 Anders Gavare. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -25,7 +25,7 @@ * SUCH DAMAGE. * * - * $Id: main.c,v 1.236 2005/05/25 06:40:18 debug Exp $ + * $Id: main.c,v 1.275 2006/06/24 19:52:28 debug Exp $ */ #include @@ -37,20 +37,23 @@ #include "console.h" #include "cpu.h" +#include "debugger.h" #include "device.h" #include "diskimage.h" #include "emul.h" #include "machine.h" #include "misc.h" +#include "settings.h" extern volatile int single_step; extern int force_debugger_at_exit; -extern int show_opcode_statistics; extern int optind; extern char *optarg; +struct settings *global_settings; + int extra_argc; char **extra_argv; char *progname; @@ -194,15 +197,17 @@ #ifdef VERSION printf("-" VERSION); #endif - printf(" Copyright (C) 2003-2005 Anders Gavare\n"); + printf(" Copyright (C) 2003-2006 Anders Gavare\n"); printf("Read the source code and/or documentation for " "other Copyright messages.\n"); printf("\nusage: %s [machine, other, and general options] [file " "[...]]\n", progname); - printf(" or %s [general options] @configfile [...]\n", progname); + printf(" or %s [general options] @configfile\n", progname); +#ifdef UNSTABLE_DEVEL printf(" or %s [userland, other, and general options] file " "[args ...]\n", progname); +#endif if (!longusage) { printf("\nRun %s -h for help on command line options.\n", @@ -217,10 +222,8 @@ "with -E.)\n"); printf("\nOther options:\n"); -#ifdef BINTRANS - printf(" -B disable dynamic binary translation completely\n"); - printf(" -b use the OLD binary translation subsystem\n"); -#endif + printf(" -A disable alignment checks in some cases (for higher" + " speed)\n"); printf(" -C x try to emulate a specific CPU. (Use -H to get a " "list of types.)\n"); printf(" -d fname add fname as a disk image. You can add \"xxx:\"" @@ -239,27 +242,33 @@ printf(" s SCSI\n"); printf(" t tape\n"); printf(" 0-7 force a specific ID\n"); + printf(" -G port listen to gdb remote connections on this port\n"); printf(" -I x emulate clock interrupts at x Hz (affects" " rtc devices only, not\n"); printf(" actual runtime speed) (this disables automatic" " clock adjustments)\n"); printf(" -i display each instruction as it is executed\n"); printf(" -J disable some speed tricks\n"); - printf(" -j name set the name of the kernel, for example:\n"); - printf(" -j netbsd for NetBSD/pmax\n"); - printf(" -j bsd for OpenBSD/pmax\n"); - printf(" -j vmunix for Ultrix/RISC\n"); + printf(" -j name set the name of the kernel; for DECstation " + "emulation, this passes\n the name to the bootloader," + " for example:\n"); + printf(" -j netbsd (NetBSD/pmax) " + "-j bsd (OpenBSD/pmax)\n"); + printf(" -j vmsprite (Sprite/pmax) " + "-j vmunix (Ultrix/RISC)\n"); + printf(" For other emulation modes, if the boot disk is an" + " ISO9660\n filesystem, -j sets the name of the" + " kernel to load.\n"); printf(" -M m emulate m MBs of physical RAM\n"); - printf(" -m nr run at most nr instructions (on any cpu)\n"); printf(" -N display nr of instructions/second average, at" " regular intervals\n"); printf(" -n nr set nr of CPUs (for SMP experiments)\n"); printf(" -O force netboot (tftp instead of disk), even when" " a disk image is\n" " present (for DECstation, SGI, and ARC emulation)\n"); - printf(" -o arg set the boot argument (for DEC, ARC, or SGI" - " emulation).\n"); - printf(" Default arg for DEC is '-a', for ARC '-aN'.\n"); + printf(" -o arg set the boot argument, for DEC, ARC, or SGI" + " emulation\n"); + printf(" (default arg for DEC is -a, for ARC/SGI -aN)\n"); printf(" -p pc add a breakpoint (remember to use the '0x' " "prefix for hex!)\n"); printf(" -Q no built-in PROM emulation (use this for " @@ -268,40 +277,38 @@ printf(" -r register dumps before every instruction\n"); printf(" -S initialize emulated RAM to random bytes, " "instead of zeroes\n"); - printf(" -T enter the single-step debugger on " - "unimplemented memory accesses\n"); printf(" -t show function trace tree\n"); printf(" -U enable slow_serial_interrupts_hack_for_linux\n"); #ifdef WITH_X11 printf(" -X use X11\n"); -#endif /* WITH_X11 */ printf(" -x open up new xterms for emulated serial ports " - "(default is on when\n using configuration files, off" - " otherwise)\n"); -#ifdef WITH_X11 + "(default is on when\n using configuration files or" + " when X11 is used, off otherwise)\n"); printf(" -Y n scale down framebuffer windows by n x n times\n"); #endif /* WITH_X11 */ - printf(" -y x set max_random_cycles_per_chunk to x" - " (experimental)\n"); printf(" -Z n set nr of graphics cards, for emulating a " "dual-head or tripple-head\n" " environment (only for DECstation emulation)\n"); printf(" -z disp add disp as an X11 display to use for " "framebuffers\n"); +#ifdef UNSTABLE_DEVEL printf("\nUserland options:\n"); printf(" -u emul userland-only (syscall) emulation (use -H to" " get a list of\n available emulation modes)\n"); +#endif printf("\nGeneral options:\n"); - printf(" -D guarantee fully deterministic behaviour\n"); + printf(" -c cmd add cmd as a command to run before starting " + "the simulation\n"); + printf(" -D guarantee (almost) fully deterministic " + "behaviour\n"); printf(" -H display a list of possible CPU and " "machine types\n"); printf(" -h display this help message\n"); printf(" -K force the debugger to be entered at the end " "of a simulation\n"); printf(" -q quiet mode (don't print startup messages)\n"); - printf(" -s show opcode usage statistics after simulation\n"); printf(" -V start up in the single-step debugger, paused\n"); printf(" -v verbose debug messages\n"); printf("\n"); @@ -332,26 +339,47 @@ char ***diskimagesp, int *n_diskimagesp) { int ch, res, using_switch_d = 0, using_switch_Z = 0; + int using_switch_e = 0, using_switch_E = 0; char *type = NULL, *subtype = NULL; int n_cpus_set = 0; int msopts = 0; /* Machine-specific options used */ struct machine *m = emul_add_machine(emul, "default"); - while ((ch = getopt(argc, argv, "BbC:Dd:E:e:HhI:iJj:KM:m:" - "Nn:Oo:p:QqRrSsTtUu:VvW:XxY:y:Z:z:")) != -1) { + char *opts = + "A" + "C:c:Dd:E:e:G:HhI:iJj:KM:Nn:Oo:p:QqRrStU" +#ifdef UNSTABLE_DEVEL + "u:" +#endif + "VvW:" +#ifdef WITH_X11 + "XxY:" +#endif + "Z:z:"; + + while ((ch = getopt(argc, argv, opts)) != -1) { switch (ch) { - case 'B': - m->bintrans_enable = 0; - msopts = 1; - break; - case 'b': - m->old_bintrans_enable = 1; + case 'A': + fprintf(stderr, "NOTE: The -A command line option" + " is DEPRECATED and will be removed soon.\n"); + m->dyntrans_alignment_check = 0; msopts = 1; break; case 'C': m->cpu_name = strdup(optarg); msopts = 1; break; + case 'c': + emul->n_debugger_cmds ++; + emul->debugger_cmds = realloc(emul->debugger_cmds, + emul->n_debugger_cmds * sizeof(char *)); + if (emul->debugger_cmds == NULL) { + fatal("out of memory\n"); + exit(1); + } + emul->debugger_cmds[emul->n_debugger_cmds-1] = + strdup(optarg); + break; case 'D': fully_deterministic = 1; break; @@ -369,13 +397,32 @@ msopts = 1; break; case 'E': + if (using_switch_E ++ > 0) { + fprintf(stderr, "-E already used.\n"); + exit(1); + } type = optarg; msopts = 1; break; case 'e': + if (using_switch_e ++ > 0) { + fprintf(stderr, "-e already used.\n"); + exit(1); + } subtype = optarg; msopts = 1; 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; case 'H': machine_list_available_types_and_cpus(); exit(1); @@ -410,10 +457,6 @@ m->physical_ram_in_mb = atoi(optarg); msopts = 1; break; - case 'm': - m->max_instructions = atoi(optarg); - msopts = 1; - break; case 'N': m->show_nr_of_instructions = 1; msopts = 1; @@ -468,13 +511,6 @@ m->random_mem_contents = 1; msopts = 1; break; - case 's': - show_opcode_statistics = 1; - break; - case 'T': - m->single_step_on_bad_addr = 1; - msopts = 1; - break; case 't': m->show_trace_tree = 1; msopts = 1; @@ -493,7 +529,7 @@ msopts = 1; break; case 'V': - single_step = 1; + single_step = ENTER_SINGLE_STEPPING; break; case 'v': verbose ++; @@ -504,22 +540,22 @@ case 'X': m->use_x11 = 1; msopts = 1; - break; + /* FALL-THROUGH */ case 'x': console_allow_slaves(1); break; case 'Y': m->x11_scaledown = atoi(optarg); + if (m->x11_scaledown < -1) { + m->x11_scaleup = - m->x11_scaledown; + m->x11_scaledown = 1; + } if (m->x11_scaledown < 1) { fprintf(stderr, "Invalid scaledown value.\n"); exit(1); } msopts = 1; break; - case 'y': - m->max_random_cycles_per_chunk = atoi(optarg); - msopts = 1; - break; case 'Z': m->n_gfx_cards = atoi(optarg); using_switch_Z = 1; @@ -544,13 +580,15 @@ msopts = 1; break; default: - fprintf(stderr, "Invalid option.\n"); - usage(0); + fprintf(stderr, "Run %s -h for help on command " + "line options.\n", progname); exit(1); } } - if (type != NULL) { + if (type != NULL || subtype != NULL) { + if (type == NULL) + type = ""; if (subtype == NULL) subtype = ""; res = machine_name_to_type(type, subtype, @@ -566,17 +604,6 @@ extra_argv = argv; - if (!m->bintrans_enable && m->old_bintrans_enable) { - fprintf(stderr, "You cannot both select old bintrans and" - " disable bintrans at the same time.\n"); - exit(1); - } - - /* TODO: Remove this once there is a new bintrans system. */ - if (m->bintrans_enable && !m->old_bintrans_enable) { - m->bintrans_enable = 0; - } - if (m->machine_type == MACHINE_NONE && msopts) { fprintf(stderr, "Machine specific options used directly on " "the command line, but no machine\nemulation specified?\n"); @@ -584,7 +611,7 @@ } - /* -i, -r, -t are pretty verbose: */ + /* -i and -r are pretty verbose: */ if (m->instruction_trace && !verbose) { fprintf(stderr, "Implicitly %sturning on -v, because" @@ -600,13 +627,6 @@ quiet_mode = 0; } - if (m->show_trace_tree && !verbose) { - fprintf(stderr, "Implicitly %sturning on -v, because" - " of -t\n", quiet_mode? "turning off -q and " : ""); - verbose = 1; - quiet_mode = 0; - } - /* * Usually, an executable filename must be supplied. @@ -653,38 +673,9 @@ exit(1); } - if (m->bintrans_enable) { - m->speed_tricks = 0; - /* TODO: Print a warning about this? */ - } - - if (m->n_breakpoints > 0 && m->bintrans_enable) { - fprintf(stderr, "Breakpoints and dynamic 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 - if (!using_switch_Z && !m->use_x11) m->n_gfx_cards = 0; - m->bintrans_enabled_from_start = m->bintrans_enable; - return 0; } @@ -709,6 +700,23 @@ progname = argv[0]; + /* Create the settings object, and add global settings to it: */ + global_settings = settings_new(); + + settings_add(global_settings, "single_step", 0, + SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, (void *)&single_step); + settings_add(global_settings, "force_debugger_at_exit", 1, + SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, + (void *)&force_debugger_at_exit); + settings_add(global_settings, "fully_deterministic", 0, + SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, + (void *)&fully_deterministic); + settings_add(global_settings, "verbose", 1, + SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, (void *)&verbose); + settings_add(global_settings, "quiet_mode", 1, + SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, (void *)&quiet_mode); + + /* Initialize all emulator subsystems: */ console_init(); cpu_init(); device_init(); @@ -747,7 +755,7 @@ #ifdef VERSION debug("-" VERSION); #endif - debug(" Copyright (C) 2003-2005 Anders Gavare\n"); + debug(" Copyright (C) 2003-2006 Anders Gavare\n"); debug("Read the source code and/or documentation for " "other Copyright messages.\n\n"); @@ -790,29 +798,33 @@ fprintf(stderr, "out of memory\n"); exit(1); } - emuls[n_emuls - 1] = - emul_create_from_configfile(s); /* Always allow slave xterms when using multiple emulations: */ console_allow_slaves(1); + + emuls[n_emuls - 1] = + emul_create_from_configfile(s); } } if (n_emuls == 0) { fprintf(stderr, "No emulations defined. Maybe you forgot to " - "use -E xx (and -e yy), to specify\nthe machine type)." - " For example:\n\n %s -E dec -e 3max -d disk.img\n\n" + "use -E xx and/or -e yy, to specify\nthe machine type." + " For example:\n\n %s -e 3max -d disk.img\n\n" "to boot an emulated DECstation 5000/200 with a disk " "image.\n", progname); exit(1); } device_set_exit_on_error(0); + console_warn_if_slaves_are_needed(1); /* Run all emulations: */ emul_run(emuls, n_emuls); + settings_destroy(global_settings); + return 0; }