/[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 23 by dpavlin, Mon Oct 8 16:19:37 2007 UTC revision 24 by dpavlin, Mon Oct 8 16:19:56 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.274 2006/06/22 13:22:41 debug Exp $
29   */   */
30    
31  #include <stdio.h>  #include <stdio.h>
# Line 42  Line 42 
42  #include "emul.h"  #include "emul.h"
43  #include "machine.h"  #include "machine.h"
44  #include "misc.h"  #include "misc.h"
45    #include "settings.h"
46    
47    
48  extern volatile int single_step;  extern volatile int single_step;
49  extern int force_debugger_at_exit;  extern int force_debugger_at_exit;
 extern int show_opcode_statistics;  
50    
51  extern int optind;  extern int optind;
52  extern char *optarg;  extern char *optarg;
53    
54    struct settings *global_settings;
55    
56  int extra_argc;  int extra_argc;
57  char **extra_argv;  char **extra_argv;
58  char *progname;  char *progname;
59    
60  int fully_deterministic = 0;  int fully_deterministic = 0;
 int dyntrans_backend_enable = 1;  
61    
62    
63  /*****************************************************************************  /*****************************************************************************
# Line 202  static void usage(int longusage) Line 203  static void usage(int longusage)
203          printf("\nusage: %s [machine, other, and general options] [file "          printf("\nusage: %s [machine, other, and general options] [file "
204              "[...]]\n", progname);              "[...]]\n", progname);
205          printf("   or  %s [general options] @configfile\n", progname);          printf("   or  %s [general options] @configfile\n", progname);
206    #ifdef UNSTABLE_DEVEL
207          printf("   or  %s [userland, other, and general options] file "          printf("   or  %s [userland, other, and general options] file "
208              "[args ...]\n", progname);              "[args ...]\n", progname);
209    #endif
210    
211          if (!longusage) {          if (!longusage) {
212                  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 223  static void usage(int longusage)
223          printf("\nOther options:\n");          printf("\nOther options:\n");
224          printf("  -A        disable alignment checks in some cases (for higher"          printf("  -A        disable alignment checks in some cases (for higher"
225              " 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  
226          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 "
227              "list of types.)\n");              "list of types.)\n");
228          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 241  static void usage(int longusage)
241          printf("                s      SCSI\n");          printf("                s      SCSI\n");
242          printf("                t      tape\n");          printf("                t      tape\n");
243          printf("                0-7    force a specific ID\n");          printf("                0-7    force a specific ID\n");
244            printf("  -G port   listen to gdb remote connections on this port\n");
245          printf("  -I x      emulate clock interrupts at x Hz (affects"          printf("  -I x      emulate clock interrupts at x Hz (affects"
246              " rtc devices only, not\n");              " rtc devices only, not\n");
247          printf("            actual runtime speed) (this disables automatic"          printf("            actual runtime speed) (this disables automatic"
248              " clock adjustments)\n");              " clock adjustments)\n");
249          printf("  -i        display each instruction as it is executed\n");          printf("  -i        display each instruction as it is executed\n");
250          printf("  -J        disable some speed tricks\n");          printf("  -J        disable some speed tricks\n");
251          printf("  -j name   set the name of the kernel, for example:\n");          printf("  -j name   set the name of the kernel; for DECstation "
252          printf("                -j netbsd          for NetBSD/pmax\n");              "emulation, this passes\n            the name to the bootloader,"
253          printf("                -j bsd             for OpenBSD/pmax\n");              " for example:\n");
254          printf("                -j vmunix          for Ultrix/RISC\n");          printf("                -j netbsd     (NetBSD/pmax)      "
255                "-j bsd      (OpenBSD/pmax)\n");
256            printf("                -j vmsprite   (Sprite/pmax)      "
257                "-j vmunix   (Ultrix/RISC)\n");
258            printf("            For other emulation modes, if the boot disk is an"
259                " ISO9660\n            filesystem, -j sets the name of the"
260                " kernel to load.\n");
261          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");  
262          printf("  -N        display nr of instructions/second average, at"          printf("  -N        display nr of instructions/second average, at"
263              " regular intervals\n");              " regular intervals\n");
264          printf("  -n nr     set nr of CPUs (for SMP experiments)\n");          printf("  -n nr     set nr of CPUs (for SMP experiments)\n");
265          printf("  -O        force netboot (tftp instead of disk), even when"          printf("  -O        force netboot (tftp instead of disk), even when"
266              " a disk image is\n"              " a disk image is\n"
267              "            present (for DECstation, SGI, and ARC emulation)\n");              "            present (for DECstation, SGI, and ARC emulation)\n");
268          printf("  -o arg    set the boot argument (for DEC, ARC, or SGI"          printf("  -o arg    set the boot argument, for DEC, ARC, or SGI"
269              " emulation).\n");              " emulation\n");
270          printf("            Default arg for DEC is '-a', for ARC '-aN'.\n");          printf("            (default arg for DEC is -a, for ARC/SGI -aN)\n");
271          printf("  -p pc     add a breakpoint (remember to use the '0x' "          printf("  -p pc     add a breakpoint (remember to use the '0x' "
272              "prefix for hex!)\n");              "prefix for hex!)\n");
273          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 276  static void usage(int longusage)
276          printf("  -r        register dumps before every instruction\n");          printf("  -r        register dumps before every instruction\n");
277          printf("  -S        initialize emulated RAM to random bytes, "          printf("  -S        initialize emulated RAM to random bytes, "
278              "instead of zeroes\n");              "instead of zeroes\n");
         printf("  -T        enter the single-step debugger on "  
             "unimplemented memory accesses\n");  
279          printf("  -t        show function trace tree\n");          printf("  -t        show function trace tree\n");
280          printf("  -U        enable slow_serial_interrupts_hack_for_linux\n");          printf("  -U        enable slow_serial_interrupts_hack_for_linux\n");
281  #ifdef WITH_X11  #ifdef WITH_X11
282          printf("  -X        use X11\n");          printf("  -X        use X11\n");
 #endif /*  WITH_X11  */  
283          printf("  -x        open up new xterms for emulated serial ports "          printf("  -x        open up new xterms for emulated serial ports "
284              "(default is on when\n            using configuration files or"              "(default is on when\n            using configuration files or"
285              " when X11 is used, off otherwise)\n");              " when X11 is used, off otherwise)\n");
 #ifdef WITH_X11  
286          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");
287  #endif /*  WITH_X11  */  #endif /*  WITH_X11  */
         printf("  -y x      set max_random_cycles_per_chunk to x"  
             " (experimental)\n");  
288          printf("  -Z n      set nr of graphics cards, for emulating a "          printf("  -Z n      set nr of graphics cards, for emulating a "
289              "dual-head or tripple-head\n"              "dual-head or tripple-head\n"
290              "            environment (only for DECstation emulation)\n");              "            environment (only for DECstation emulation)\n");
291          printf("  -z disp   add disp as an X11 display to use for "          printf("  -z disp   add disp as an X11 display to use for "
292              "framebuffers\n");              "framebuffers\n");
293    
294    #ifdef UNSTABLE_DEVEL
295          printf("\nUserland options:\n");          printf("\nUserland options:\n");
296          printf("  -u emul   userland-only (syscall) emulation (use -H to"          printf("  -u emul   userland-only (syscall) emulation (use -H to"
297              " get a list of\n            available emulation modes)\n");              " get a list of\n            available emulation modes)\n");
298    #endif
299    
300          printf("\nGeneral options:\n");          printf("\nGeneral options:\n");
301          printf("  -c cmd    add cmd as a command to run before starting "          printf("  -c cmd    add cmd as a command to run before starting "
302              "the simulation\n");              "the simulation\n");
303          printf("  -D        guarantee fully deterministic behaviour\n");          printf("  -D        guarantee (almost) fully deterministic "
304                "behaviour\n");
305          printf("  -H        display a list of possible CPU and "          printf("  -H        display a list of possible CPU and "
306              "machine types\n");              "machine types\n");
307          printf("  -h        display this help message\n");          printf("  -h        display this help message\n");
308          printf("  -K        force the debugger to be entered at the end "          printf("  -K        force the debugger to be entered at the end "
309              "of a simulation\n");              "of a simulation\n");
310          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");  
311          printf("  -V        start up in the single-step debugger, paused\n");          printf("  -V        start up in the single-step debugger, paused\n");
312          printf("  -v        verbose debug messages\n");          printf("  -v        verbose debug messages\n");
313          printf("\n");          printf("\n");
# Line 338  int get_cmd_args(int argc, char *argv[], Line 338  int get_cmd_args(int argc, char *argv[],
338          char ***diskimagesp, int *n_diskimagesp)          char ***diskimagesp, int *n_diskimagesp)
339  {  {
340          int ch, res, using_switch_d = 0, using_switch_Z = 0;          int ch, res, using_switch_d = 0, using_switch_Z = 0;
341            int using_switch_e = 0, using_switch_E = 0;
342          char *type = NULL, *subtype = NULL;          char *type = NULL, *subtype = NULL;
343          int n_cpus_set = 0;          int n_cpus_set = 0;
344          int msopts = 0;         /*  Machine-specific options used  */          int msopts = 0;         /*  Machine-specific options used  */
345          struct machine *m = emul_add_machine(emul, "default");          struct machine *m = emul_add_machine(emul, "default");
346    
347          while ((ch = getopt(argc, argv, "ABC:c:Dd:E:e:HhI:iJj:KM:m:"          char *opts =
348              "Nn:Oo:p:QqRrSsTtUu:VvW:XxY:y:Z:z:")) != -1) {              "A"
349                "C:c:Dd:E:e:G:HhI:iJj:KM:Nn:Oo:p:QqRrStU"
350    #ifdef UNSTABLE_DEVEL
351                "u:"
352    #endif
353                "VvW:"
354    #ifdef WITH_X11
355                "XxY:"
356    #endif
357                "Z:z:";
358    
359            while ((ch = getopt(argc, argv, opts)) != -1) {
360                  switch (ch) {                  switch (ch) {
361                  case 'A':                  case 'A':
362                            fprintf(stderr, "NOTE: The -A command line option"
363                                " is DEPRECATED and will be removed soon.\n");
364                          m->dyntrans_alignment_check = 0;                          m->dyntrans_alignment_check = 0;
365                          msopts = 1;                          msopts = 1;
366                          break;                          break;
                 case 'B':  
                         /*  Turns off both bintrans and dyntrans.  */  
                         m->bintrans_enable = 0;  
                         dyntrans_backend_enable = 0;  
                         msopts = 1;  
                         break;  
367                  case 'C':                  case 'C':
368                          m->cpu_name = strdup(optarg);                          m->cpu_name = strdup(optarg);
369                          msopts = 1;                          msopts = 1;
# Line 388  int get_cmd_args(int argc, char *argv[], Line 396  int get_cmd_args(int argc, char *argv[],
396                          msopts = 1;                          msopts = 1;
397                          break;                          break;
398                  case 'E':                  case 'E':
399                            if (using_switch_E ++ > 0) {
400                                    fprintf(stderr, "-E already used.\n");
401                                    exit(1);
402                            }
403                          type = optarg;                          type = optarg;
404                          msopts = 1;                          msopts = 1;
405                          break;                          break;
406                  case 'e':                  case 'e':
407                            if (using_switch_e ++ > 0) {
408                                    fprintf(stderr, "-e already used.\n");
409                                    exit(1);
410                            }
411                          subtype = optarg;                          subtype = optarg;
412                          msopts = 1;                          msopts = 1;
413                          break;                          break;
414                    case 'G':
415                            m->gdb.port = atoi(optarg);
416                            if (m->gdb.port < 1 || m->gdb.port > 65535) {
417                                    fprintf(stderr, "Invalid debugger port %i.\n",
418                                        m->gdb.port);
419                                    exit(1);
420                            }
421                            single_step = 1;        /*  implicit -V  */
422                            msopts = 1;
423                            break;
424                  case 'H':                  case 'H':
425                          machine_list_available_types_and_cpus();                          machine_list_available_types_and_cpus();
426                          exit(1);                          exit(1);
# Line 429  int get_cmd_args(int argc, char *argv[], Line 455  int get_cmd_args(int argc, char *argv[],
455                          m->physical_ram_in_mb = atoi(optarg);                          m->physical_ram_in_mb = atoi(optarg);
456                          msopts = 1;                          msopts = 1;
457                          break;                          break;
                 case 'm':  
                         m->max_instructions = atoi(optarg);  
                         msopts = 1;  
                         break;  
458                  case 'N':                  case 'N':
459                          m->show_nr_of_instructions = 1;                          m->show_nr_of_instructions = 1;
460                          msopts = 1;                          msopts = 1;
# Line 487  int get_cmd_args(int argc, char *argv[], Line 509  int get_cmd_args(int argc, char *argv[],
509                          m->random_mem_contents = 1;                          m->random_mem_contents = 1;
510                          msopts = 1;                          msopts = 1;
511                          break;                          break;
                 case 's':  
                         show_opcode_statistics = 1;  
                         break;  
                 case 'T':  
                         m->single_step_on_bad_addr = 1;  
                         msopts = 1;  
                         break;  
512                  case 't':                  case 't':
513                          m->show_trace_tree = 1;                          m->show_trace_tree = 1;
514                          msopts = 1;                          msopts = 1;
# Line 539  int get_cmd_args(int argc, char *argv[], Line 554  int get_cmd_args(int argc, char *argv[],
554                          }                          }
555                          msopts = 1;                          msopts = 1;
556                          break;                          break;
                 case 'y':  
                         m->max_random_cycles_per_chunk = atoi(optarg);  
                         msopts = 1;  
                         break;  
557                  case 'Z':                  case 'Z':
558                          m->n_gfx_cards = atoi(optarg);                          m->n_gfx_cards = atoi(optarg);
559                          using_switch_Z = 1;                          using_switch_Z = 1;
# Line 614  int get_cmd_args(int argc, char *argv[], Line 625  int get_cmd_args(int argc, char *argv[],
625                  quiet_mode = 0;                  quiet_mode = 0;
626          }          }
627    
         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;  
         }  
   
628    
629          /*          /*
630           *  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 671  int get_cmd_args(int argc, char *argv[],
671                  exit(1);                  exit(1);
672          }          }
673    
 #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  
   
674          if (!using_switch_Z && !m->use_x11)          if (!using_switch_Z && !m->use_x11)
675                  m->n_gfx_cards = 0;                  m->n_gfx_cards = 0;
676    
         m->bintrans_enabled_from_start = m->bintrans_enable;  
   
677          return 0;          return 0;
678  }  }
679    
# Line 726  int main(int argc, char *argv[]) Line 698  int main(int argc, char *argv[])
698    
699          progname = argv[0];          progname = argv[0];
700    
701            /*  Create the settings object, and add global settings to it:  */
702            global_settings = settings_new();
703    
704            settings_add(global_settings, "single_step", 0,
705                SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, (void *)&single_step);
706            settings_add(global_settings, "force_debugger_at_exit", 1,
707                SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO,
708                (void *)&force_debugger_at_exit);
709            settings_add(global_settings, "fully_deterministic", 0,
710                SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO,
711                (void *)&fully_deterministic);
712            settings_add(global_settings, "verbose", 1,
713                SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, (void *)&verbose);
714            settings_add(global_settings, "quiet_mode", 1,
715                SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, (void *)&quiet_mode);
716    
717            /*  Initialize all emulator subsystems:  */
718          console_init();          console_init();
719          cpu_init();          cpu_init();
720          device_init();          device_init();
# Line 832  int main(int argc, char *argv[]) Line 821  int main(int argc, char *argv[])
821          /*  Run all emulations:  */          /*  Run all emulations:  */
822          emul_run(emuls, n_emuls);          emul_run(emuls, n_emuls);
823    
824            settings_destroy(global_settings);
825    
826          return 0;          return 0;
827  }  }
828    

Legend:
Removed from v.23  
changed lines
  Added in v.24

  ViewVC Help
Powered by ViewVC 1.1.26