/[gxemul]/trunk/src/main.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/src/main.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 22 by dpavlin, Mon Oct 8 16:19:37 2007 UTC revision 26 by dpavlin, Mon Oct 8 16:20:10 2007 UTC
# Line 25  Line 25 
25   *  SUCH DAMAGE.   *  SUCH DAMAGE.
26   *   *
27   *   *
28   *  $Id: main.c,v 1.256 2006/02/04 11:10:58 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>
# Line 37  Line 37 
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;
60    
61  int fully_deterministic = 0;  int fully_deterministic = 0;
 int dyntrans_backend_enable = 1;  
62    
63    
64  /*****************************************************************************  /*****************************************************************************
# Line 202  static void usage(int longusage) Line 204  static void usage(int longusage)
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",
# Line 220  static void usage(int longusage) Line 224  static void usage(int longusage)
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");
 #if defined(BINTRANS) || defined(DYNTRANS_BACKEND)  
         printf("  -B        disable native translation backends. (translation"  
             " is turned on\n            by default, if it is supposed for "  
             "the particular host)\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:\""
# Line 243  static void usage(int longusage) Line 242  static void usage(int longusage)
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 "
# Line 272  static void usage(int longusage) Line 277  static void usage(int longusage)
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 or"              "(default is on when\n            using configuration files or"
286              " when X11 is used, off 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("  -c cmd    add cmd as a command to run before starting "          printf("  -c cmd    add cmd as a command to run before starting "
303              "the simulation\n");              "the simulation\n");
304          printf("  -D        guarantee fully deterministic behaviour\n");          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");
# Line 338  int get_cmd_args(int argc, char *argv[], Line 339  int get_cmd_args(int argc, char *argv[],
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:c: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':  
                         /*  Turns off both bintrans and dyntrans.  */  
                         m->bintrans_enable = 0;  
                         dyntrans_backend_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;
# Line 388  int get_cmd_args(int argc, char *argv[], Line 397  int get_cmd_args(int argc, char *argv[],
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);
# Line 429  int get_cmd_args(int argc, char *argv[], Line 457  int get_cmd_args(int argc, char *argv[],
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;
# Line 487  int get_cmd_args(int argc, char *argv[], Line 511  int get_cmd_args(int argc, char *argv[],
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;
# Line 512  int get_cmd_args(int argc, char *argv[], Line 529  int get_cmd_args(int argc, char *argv[],
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 ++;
# Line 539  int get_cmd_args(int argc, char *argv[], Line 556  int get_cmd_args(int argc, char *argv[],
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;
# Line 614  int get_cmd_args(int argc, char *argv[], Line 627  int get_cmd_args(int argc, char *argv[],
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.
# Line 667  int get_cmd_args(int argc, char *argv[], Line 673  int get_cmd_args(int argc, char *argv[],
673                  exit(1);                  exit(1);
674          }          }
675    
 #ifndef EXPERIMENTAL_NEWMIPS  
         if (m->bintrans_enable && m->arch == ARCH_MIPS) {  
                 m->speed_tricks = 0;  
                 /*  TODO: Print a warning about this?  */  
         }  
 #endif  
   
         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    
# Line 726  int main(int argc, char *argv[]) Line 700  int main(int argc, char *argv[])
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();
# Line 832  int main(int argc, char *argv[]) Line 823  int main(int argc, char *argv[])
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    

Legend:
Removed from v.22  
changed lines
  Added in v.26

  ViewVC Help
Powered by ViewVC 1.1.26