/[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 20 by dpavlin, Mon Oct 8 16:19:23 2007 UTC revision 34 by dpavlin, Mon Oct 8 16:21:17 2007 UTC
# Line 1  Line 1 
1  /*  /*
2   *  Copyright (C) 2003-2005  Anders Gavare.  All rights reserved.   *  Copyright (C) 2003-2007  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:
# Line 25  Line 25 
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.293 2007/02/05 16:49:05 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    #include "timer.h"
48    
49    
50  extern volatile int single_step;  extern volatile int single_step;
51  extern int force_debugger_at_exit;  extern int force_debugger_at_exit;
 extern int show_opcode_statistics;  
52    
53  extern int optind;  extern int optind;
54  extern char *optarg;  extern char *optarg;
55    
56    struct settings *global_settings;
57    
58  int extra_argc;  int extra_argc;
59  char **extra_argv;  char **extra_argv;
60  char *progname;  char *progname;
61    
62  int fully_deterministic = 0;  size_t dyntrans_cache_size = DEFAULT_DYNTRANS_CACHE_SIZE;
63    int native_code_translation_enabled = 0;
64    int skip_srandom_call = 0;
65    
66    
67  /*****************************************************************************  /*****************************************************************************
# Line 192  static void usage(int longusage) Line 198  static void usage(int longusage)
198  {  {
199          printf("GXemul");          printf("GXemul");
200  #ifdef VERSION  #ifdef VERSION
201          printf("-" VERSION);          printf(" " VERSION);
202  #endif  #endif
203          printf("   Copyright (C) 2003-2005  Anders Gavare\n");          printf("    Copyright (C) 2003-2007  Anders Gavare\n");
204          printf("Read the source code and/or documentation for "          printf("Read the source code and/or documentation for "
205              "other Copyright messages.\n");              "other Copyright messages.\n");
206    
207          printf("\nusage: %s [machine, other, and general options] [file "          printf("\nusage: %s [machine, other, and general options] [file "
208              "[...]]\n", progname);              "[...]]\n", progname);
209          printf("   or  %s [general options] @configfile\n", progname);          printf("   or  %s [general options] @configfile\n", progname);
210    #ifdef UNSTABLE_DEVEL
211          printf("   or  %s [userland, other, and general options] file "          printf("   or  %s [userland, other, and general options] file "
212              "[args ...]\n", progname);              "[args ...]\n", progname);
213    #endif
214    
215          if (!longusage) {          if (!longusage) {
216                  printf("\nRun  %s -h  for help on command line options.\n",                  printf("\nRun  %s -h  for help on command line options.\n",
# Line 217  static void usage(int longusage) Line 225  static void usage(int longusage)
225              "with -E.)\n");              "with -E.)\n");
226    
227          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  
228          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 "
229              "list of types.)\n");              "list of types.)\n");
230          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 237  static void usage(int longusage) Line 238  static void usage(int longusage)
238          printf("                gH;S;  set geometry to H heads and S"          printf("                gH;S;  set geometry to H heads and S"
239              " sectors-per-track\n");              " sectors-per-track\n");
240          printf("                i      IDE\n");          printf("                i      IDE\n");
241            printf("                oOFS;  set base offset to OFS (for ISO9660"
242                " filesystems)\n");
243          printf("                r      read-only (don't allow changes to the"          printf("                r      read-only (don't allow changes to the"
244              " file)\n");              " file)\n");
245          printf("                s      SCSI\n");          printf("                s      SCSI\n");
246          printf("                t      tape\n");          printf("                t      tape\n");
247          printf("                0-7    force a specific ID\n");          printf("                0-7    force a specific ID\n");
248          printf("  -I x      emulate clock interrupts at x Hz (affects"          printf("  -G port   listen to gdb remote connections on this port\n");
249              " rtc devices only, not\n");          printf("  -I hz     set the main cpu frequency to hz (not used by "
250          printf("            actual runtime speed) (this disables automatic"              "all combinations\n            of machines and guest OSes)\n");
             " clock adjustments)\n");  
251          printf("  -i        display each instruction as it is executed\n");          printf("  -i        display each instruction as it is executed\n");
252          printf("  -J        disable some speed tricks\n");          printf("  -J        disable dyntrans instruction combinations\n");
253          printf("  -j name   set the name of the kernel, for example:\n");          printf("  -j name   set the name of the kernel; for DECstation "
254          printf("                -j netbsd          for NetBSD/pmax\n");              "emulation, this passes\n            the name to the bootloader,"
255          printf("                -j bsd             for OpenBSD/pmax\n");              " for example:\n");
256          printf("                -j vmunix          for Ultrix/RISC\n");          printf("                -j netbsd     (NetBSD/pmax)      "
257                "-j bsd      (OpenBSD/pmax)\n");
258            printf("                -j vmsprite   (Sprite/pmax)      "
259                "-j vmunix   (Ultrix/RISC)\n");
260            printf("            For other emulation modes, if the boot disk is an"
261                " ISO9660\n            filesystem, -j sets the name of the"
262                " kernel to load.\n");
263          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");  
264          printf("  -N        display nr of instructions/second average, at"          printf("  -N        display nr of instructions/second average, at"
265              " regular intervals\n");              " regular intervals\n");
266          printf("  -n nr     set nr of CPUs (for SMP experiments)\n");          printf("  -n nr     set nr of CPUs (for SMP experiments)\n");
267          printf("  -O        force netboot (tftp instead of disk), even when"          printf("  -O        force netboot (tftp instead of disk), even when"
268              " a disk image is\n"              " a disk image is\n"
269              "            present (for DECstation, SGI, and ARC emulation)\n");              "            present (for DECstation, SGI, and ARC emulation)\n");
270          printf("  -o arg    set the boot argument (for DEC, ARC, or SGI"          printf("  -o arg    set the boot argument, for DEC, ARC, or SGI"
271              " emulation).\n");              " emulation\n");
272          printf("            Default arg for DEC is '-a', for ARC '-aN'.\n");          printf("            (default arg for DEC is -a, for ARC/SGI -aN)\n");
273          printf("  -p pc     add a breakpoint (remember to use the '0x' "          printf("  -p pc     add a breakpoint (remember to use the '0x' "
274              "prefix for hex!)\n");              "prefix for hex!)\n");
275          printf("  -Q        no built-in PROM emulation  (use this for "          printf("  -Q        no built-in PROM emulation  (use this for "
# Line 271  static void usage(int longusage) Line 278  static void usage(int longusage)
278          printf("  -r        register dumps before every instruction\n");          printf("  -r        register dumps before every instruction\n");
279          printf("  -S        initialize emulated RAM to random bytes, "          printf("  -S        initialize emulated RAM to random bytes, "
280              "instead of zeroes\n");              "instead of zeroes\n");
281          printf("  -T        enter the single-step debugger on "          printf("  -s f:name write statistics to file 'name', "
282              "unimplemented memory accesses\n");              "f is one or more of the following:\n");
283            printf("                v    virtual program counter\n");
284            printf("                p    physical equivalent of program counter\n");
285            printf("                i    internal ic->f representation of "
286                "the program counter\n");
287            printf("            and optionally:\n");
288            printf("                d    disable statistics gathering at "
289                "startup\n");
290            printf("                o    overwrite instead of append\n");
291            printf("  -T        halt on non-existant memory accesses\n");
292          printf("  -t        show function trace tree\n");          printf("  -t        show function trace tree\n");
293          printf("  -U        enable slow_serial_interrupts_hack_for_linux\n");          printf("  -U        enable slow_serial_interrupts_hack_for_linux\n");
294  #ifdef WITH_X11  #ifdef WITH_X11
295          printf("  -X        use X11\n");          printf("  -X        use X11\n");
 #endif /*  WITH_X11  */  
296          printf("  -x        open up new xterms for emulated serial ports "          printf("  -x        open up new xterms for emulated serial ports "
297              "(default is on when\n            using configuration files, off"              "(default is on when\n            using configuration files or"
298              " otherwise)\n");              " when X11 is used, off otherwise)\n");
 #ifdef WITH_X11  
299          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");
300  #endif /*  WITH_X11  */  #endif /*  WITH_X11  */
         printf("  -y x      set max_random_cycles_per_chunk to x"  
             " (experimental)\n");  
301          printf("  -Z n      set nr of graphics cards, for emulating a "          printf("  -Z n      set nr of graphics cards, for emulating a "
302              "dual-head or tripple-head\n"              "dual-head or tripple-head\n"
303              "            environment (only for DECstation emulation)\n");              "            environment (only for DECstation emulation)\n");
304          printf("  -z disp   add disp as an X11 display to use for "          printf("  -z disp   add disp as an X11 display to use for "
305              "framebuffers\n");              "framebuffers\n");
306    
307    #ifdef UNSTABLE_DEVEL
308          printf("\nUserland options:\n");          printf("\nUserland options:\n");
309          printf("  -u emul   userland-only (syscall) emulation (use -H to"          printf("  -u emul   userland-only (syscall) emulation (use -H to"
310              " get a list of\n            available emulation modes)\n");              " get a list of\n            available emulation modes)\n");
311    #endif
312    
313          printf("\nGeneral options:\n");          printf("\nGeneral options:\n");
314          printf("  -D        guarantee fully deterministic behaviour\n");  #ifdef UNSTABLE_DEVEL
315            printf("  -b        enable native code generation\n");
316            printf("  -B        disable native code generation\n");
317    #endif
318            printf("  -c cmd    add cmd as a command to run before starting "
319                "the simulation\n");
320            printf("  -D        skip the srandom call at startup\n");
321          printf("  -H        display a list of possible CPU and "          printf("  -H        display a list of possible CPU and "
322              "machine types\n");              "machine types\n");
323          printf("  -h        display this help message\n");          printf("  -h        display this help message\n");
324            printf("  -k n      set dyntrans translation caches to n MB (default"
325                " size is %i MB)\n", DEFAULT_DYNTRANS_CACHE_SIZE / 1048576);
326          printf("  -K        force the debugger to be entered at the end "          printf("  -K        force the debugger to be entered at the end "
327              "of a simulation\n");              "of a simulation\n");
328          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");  
329          printf("  -V        start up in the single-step debugger, paused\n");          printf("  -V        start up in the single-step debugger, paused\n");
330          printf("  -v        verbose debug messages\n");          printf("  -v        verbose debug messages\n");
331          printf("\n");          printf("\n");
# Line 335  int get_cmd_args(int argc, char *argv[], Line 356  int get_cmd_args(int argc, char *argv[],
356          char ***diskimagesp, int *n_diskimagesp)          char ***diskimagesp, int *n_diskimagesp)
357  {  {
358          int ch, res, using_switch_d = 0, using_switch_Z = 0;          int ch, res, using_switch_d = 0, using_switch_Z = 0;
359            int using_switch_e = 0, using_switch_E = 0;
360          char *type = NULL, *subtype = NULL;          char *type = NULL, *subtype = NULL;
361          int n_cpus_set = 0;          int n_cpus_set = 0;
362          int msopts = 0;         /*  Machine-specific options used  */          int msopts = 0;         /*  Machine-specific options used  */
363          struct machine *m = emul_add_machine(emul, "default");          struct machine *m = emul_add_machine(emul, "default");
364    
365          while ((ch = getopt(argc, argv, "ABC:Dd:E:e:HhI:iJj:KM:m:"          char *opts =
366              "Nn:Oo:p:QqRrSsTtUu:VvW:XxY:y:Z:z:")) != -1) {  #ifdef UNSTABLE_DEVEL
367                "bB"
368    #endif
369                "C:c:Dd:E:e:G:HhI:iJj:k:KM:Nn:Oo:p:QqRrSs:TtU"
370    #ifdef UNSTABLE_DEVEL
371                "u:"
372    #endif
373                "VvW:"
374    #ifdef WITH_X11
375                "XxY:"
376    #endif
377                "Z:z:";
378    
379            while ((ch = getopt(argc, argv, opts)) != -1) {
380                  switch (ch) {                  switch (ch) {
381                  case 'A':  #ifdef UNSTABLE_DEVEL
382                          m->dyntrans_alignment_check = 0;                  case 'b':
383                          msopts = 1;  #ifndef NATIVE_CODE_GENERATION
384                            printf("-b is not available on this host arch.\n");
385                            exit(1);
386    #else
387                            native_code_translation_enabled = 1;
388                          break;                          break;
389    #endif
390                  case 'B':                  case 'B':
391                          m->bintrans_enable = 0;                          native_code_translation_enabled = 0;
                         msopts = 1;  
392                          break;                          break;
393    #endif  /*  UNSTABLE_DEVEL  */
394                  case 'C':                  case 'C':
395                          m->cpu_name = strdup(optarg);                          m->cpu_name = strdup(optarg);
396                          msopts = 1;                          msopts = 1;
397                          break;                          break;
398                    case 'c':
399                            emul->n_debugger_cmds ++;
400                            emul->debugger_cmds = realloc(emul->debugger_cmds,
401                                emul->n_debugger_cmds * sizeof(char *));
402                            if (emul->debugger_cmds == NULL) {
403                                    fatal("out of memory\n");
404                                    exit(1);
405                            }
406                            emul->debugger_cmds[emul->n_debugger_cmds-1] =
407                                strdup(optarg);
408                            break;
409                  case 'D':                  case 'D':
410                          fully_deterministic = 1;                          skip_srandom_call = 1;
411                          break;                          break;
412                  case 'd':                  case 'd':
413                          /*  diskimage_add() is called further down  */                          /*  diskimage_add() is called further down  */
# Line 372  int get_cmd_args(int argc, char *argv[], Line 423  int get_cmd_args(int argc, char *argv[],
423                          msopts = 1;                          msopts = 1;
424                          break;                          break;
425                  case 'E':                  case 'E':
426                            if (using_switch_E ++ > 0) {
427                                    fprintf(stderr, "-E already used.\n");
428                                    exit(1);
429                            }
430                          type = optarg;                          type = optarg;
431                          msopts = 1;                          msopts = 1;
432                          break;                          break;
433                  case 'e':                  case 'e':
434                            if (using_switch_e ++ > 0) {
435                                    fprintf(stderr, "-e already used.\n");
436                                    exit(1);
437                            }
438                          subtype = optarg;                          subtype = optarg;
439                          msopts = 1;                          msopts = 1;
440                          break;                          break;
441                    case 'G':
442                            m->gdb.port = atoi(optarg);
443                            if (m->gdb.port < 1 || m->gdb.port > 65535) {
444                                    fprintf(stderr, "Invalid debugger port %i.\n",
445                                        m->gdb.port);
446                                    exit(1);
447                            }
448                            /*  Note: implicit -V  */
449                            single_step = ENTER_SINGLE_STEPPING;
450                            msopts = 1;
451                            break;
452                  case 'H':                  case 'H':
453                          machine_list_available_types_and_cpus();                          machine_list_available_types_and_cpus();
454                          exit(1);                          exit(1);
# Line 387  int get_cmd_args(int argc, char *argv[], Line 457  int get_cmd_args(int argc, char *argv[],
457                          exit(1);                          exit(1);
458                  case 'I':                  case 'I':
459                          m->emulated_hz = atoi(optarg);                          m->emulated_hz = atoi(optarg);
                         m->automatic_clock_adjustment = 0;  
460                          msopts = 1;                          msopts = 1;
461                          break;                          break;
462                  case 'i':                  case 'i':
# Line 395  int get_cmd_args(int argc, char *argv[], Line 464  int get_cmd_args(int argc, char *argv[],
464                          msopts = 1;                          msopts = 1;
465                          break;                          break;
466                  case 'J':                  case 'J':
467                          m->speed_tricks = 0;                          m->allow_instruction_combinations = 0;
468                          msopts = 1;                          msopts = 1;
469                          break;                          break;
470                  case 'j':                  case 'j':
# Line 406  int get_cmd_args(int argc, char *argv[], Line 475  int get_cmd_args(int argc, char *argv[],
475                          }                          }
476                          msopts = 1;                          msopts = 1;
477                          break;                          break;
478                    case 'k':
479                            dyntrans_cache_size = atoi(optarg) * 1048576;
480                            if (dyntrans_cache_size < 1) {
481                                    fprintf(stderr, "The dyntrans cache size must"
482                                        " be at least 1 MB.\n");
483                                    exit(1);
484                            }
485                            break;
486                  case 'K':                  case 'K':
487                          force_debugger_at_exit = 1;                          force_debugger_at_exit = 1;
488                          break;                          break;
# Line 413  int get_cmd_args(int argc, char *argv[], Line 490  int get_cmd_args(int argc, char *argv[],
490                          m->physical_ram_in_mb = atoi(optarg);                          m->physical_ram_in_mb = atoi(optarg);
491                          msopts = 1;                          msopts = 1;
492                          break;                          break;
                 case 'm':  
                         m->max_instructions = atoi(optarg);  
                         msopts = 1;  
                         break;  
493                  case 'N':                  case 'N':
494                          m->show_nr_of_instructions = 1;                          m->show_nr_of_instructions = 1;
495                          msopts = 1;                          msopts = 1;
# Line 472  int get_cmd_args(int argc, char *argv[], Line 545  int get_cmd_args(int argc, char *argv[],
545                          msopts = 1;                          msopts = 1;
546                          break;                          break;
547                  case 's':                  case 's':
548                          show_opcode_statistics = 1;                          machine_statistics_init(m, optarg);
549                            native_code_translation_enabled = 0;
550                            msopts = 1;
551                          break;                          break;
552                  case 'T':                  case 'T':
553                          m->single_step_on_bad_addr = 1;                          m->halt_on_nonexistant_memaccess = 1;
554                          msopts = 1;                          msopts = 1;
555                          break;                          break;
556                  case 't':                  case 't':
# Line 496  int get_cmd_args(int argc, char *argv[], Line 571  int get_cmd_args(int argc, char *argv[],
571                          msopts = 1;                          msopts = 1;
572                          break;                          break;
573                  case 'V':                  case 'V':
574                          single_step = 1;                          single_step = ENTER_SINGLE_STEPPING;
575                          break;                          break;
576                  case 'v':                  case 'v':
577                          verbose ++;                          verbose ++;
# Line 507  int get_cmd_args(int argc, char *argv[], Line 582  int get_cmd_args(int argc, char *argv[],
582                  case 'X':                  case 'X':
583                          m->use_x11 = 1;                          m->use_x11 = 1;
584                          msopts = 1;                          msopts = 1;
585                          break;                          /*  FALL-THROUGH  */
586                  case 'x':                  case 'x':
587                          console_allow_slaves(1);                          console_allow_slaves(1);
588                          break;                          break;
# Line 523  int get_cmd_args(int argc, char *argv[], Line 598  int get_cmd_args(int argc, char *argv[],
598                          }                          }
599                          msopts = 1;                          msopts = 1;
600                          break;                          break;
                 case 'y':  
                         m->max_random_cycles_per_chunk = atoi(optarg);  
                         msopts = 1;  
                         break;  
601                  case 'Z':                  case 'Z':
602                          m->n_gfx_cards = atoi(optarg);                          m->n_gfx_cards = atoi(optarg);
603                          using_switch_Z = 1;                          using_switch_Z = 1;
# Line 598  int get_cmd_args(int argc, char *argv[], Line 669  int get_cmd_args(int argc, char *argv[],
669                  quiet_mode = 0;                  quiet_mode = 0;
670          }          }
671    
         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;  
         }  
   
672    
673          /*          /*
674           *  Usually, an executable filename must be supplied.           *  Usually, an executable filename must be supplied.
# Line 651  int get_cmd_args(int argc, char *argv[], Line 715  int get_cmd_args(int argc, char *argv[],
715                  exit(1);                  exit(1);
716          }          }
717    
         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  
   
718          if (!using_switch_Z && !m->use_x11)          if (!using_switch_Z && !m->use_x11)
719                  m->n_gfx_cards = 0;                  m->n_gfx_cards = 0;
720    
         m->bintrans_enabled_from_start = m->bintrans_enable;  
   
721          return 0;          return 0;
722  }  }
723    
# Line 700  int get_cmd_args(int argc, char *argv[], Line 734  int get_cmd_args(int argc, char *argv[],
734   */   */
735  int main(int argc, char *argv[])  int main(int argc, char *argv[])
736  {  {
737            /*  Setting constants:  */
738            const int constant_yes = 1;
739            const int constant_true = 1;
740            const int constant_no = 0;
741            const int constant_false = 0;
742    
743          struct emul **emuls;          struct emul **emuls;
744          char **diskimages = NULL;          char **diskimages = NULL;
745          int n_diskimages = 0;          int n_diskimages = 0;
746          int n_emuls;          int n_emuls;
747          int i;          int i;
748    
749    
750    #ifdef USE_PROFIL
751            uint16_t samples[0x100000];
752            memset(samples, 0, sizeof(samples));
753            profil((char *)samples, sizeof(samples), (vm_offset_t) 0x400000, 8192);
754    #endif
755    
756    #ifndef NATIVE_CODE_GENERATION
757            native_code_translation_enabled = 0;
758    #endif
759    
760    
761          progname = argv[0];          progname = argv[0];
762    
763    
764            /*
765             *  Create the settings object, and add global settings to it:
766             *
767             *  Read-only "constants":     yes, no, true, false.
768             *  Global emulator settings:  verbose, single_step, ...
769             */
770            global_settings = settings_new();
771    
772            settings_add(global_settings, "yes", 0, SETTINGS_TYPE_INT,
773                SETTINGS_FORMAT_YESNO, (void *)&constant_yes);
774            settings_add(global_settings, "no", 0, SETTINGS_TYPE_INT,
775                SETTINGS_FORMAT_YESNO, (void *)&constant_no);
776            settings_add(global_settings, "true", 0, SETTINGS_TYPE_INT,
777                SETTINGS_FORMAT_BOOL, (void *)&constant_true);
778            settings_add(global_settings, "false", 0, SETTINGS_TYPE_INT,
779                SETTINGS_FORMAT_BOOL, (void *)&constant_false);
780    
781            /*  Read-only settings:  */
782            settings_add(global_settings, "native_code_translation_enabled", 0,
783                SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO,
784                (void *)&native_code_translation_enabled);
785            settings_add(global_settings, "single_step", 0,
786                SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, (void *)&single_step);
787    
788            /*  Read/write settings:  */
789            settings_add(global_settings, "force_debugger_at_exit", 1,
790                SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO,
791                (void *)&force_debugger_at_exit);
792            settings_add(global_settings, "verbose", 1,
793                SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, (void *)&verbose);
794            settings_add(global_settings, "quiet_mode", 1,
795                SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, (void *)&quiet_mode);
796    
797            /*  Initialize all emulator subsystems:  */
798          console_init();          console_init();
799          cpu_init();          cpu_init();
800          device_init();          device_init();
801          machine_init();          machine_init();
802            timer_init();
803          useremul_init();          useremul_init();
804    
805          emuls = malloc(sizeof(struct emul *));          emuls = malloc(sizeof(struct emul *));
# Line 722  int main(int argc, char *argv[]) Line 810  int main(int argc, char *argv[])
810    
811          /*  Allocate space for a simple emul setup:  */          /*  Allocate space for a simple emul setup:  */
812          n_emuls = 1;          n_emuls = 1;
813          emuls[0] = emul_new(NULL);          emuls[0] = emul_new(NULL, 0);
814          if (emuls[0] == NULL) {          if (emuls[0] == NULL) {
815                  fprintf(stderr, "out of memory\n");                  fprintf(stderr, "out of memory\n");
816                  exit(1);                  exit(1);
817          }          }
818            settings_add(global_settings, "emul[0]", 1,
819                SETTINGS_TYPE_SUBSETTINGS, 0, emuls[0]->settings);
820    
821          get_cmd_args(argc, argv, emuls[0], &diskimages, &n_diskimages);          get_cmd_args(argc, argv, emuls[0], &diskimages, &n_diskimages);
822    
823          if (!fully_deterministic) {          if (!skip_srandom_call) {
824                  /*  TODO: More than just time(). Use gettimeofday().  */                  struct timeval tv;
825                  srandom(time(NULL) ^ (getpid() << 12));                  gettimeofday(&tv, NULL);
826          } else {                  srandom(tv.tv_sec ^ getpid() ^ tv.tv_usec);
                 /*  Fully deterministic. -I must have been supplied.  */  
                 if (emuls[0]->machines[0]->automatic_clock_adjustment) {  
                         fatal("Cannot have -D without -I.\n");  
                         exit(1);  
                 }  
827          }          }
828    
829          /*  Print startup message:  */          /*  Print startup message:  */
830          debug("GXemul");          debug("GXemul");
831  #ifdef VERSION  #ifdef VERSION
832          debug("-" VERSION);          debug(" " VERSION);
833  #endif  #endif
834          debug("   Copyright (C) 2003-2005  Anders Gavare\n");          debug("    Copyright (C) 2003-2007  Anders Gavare\n");
835          debug("Read the source code and/or documentation for "          debug("Read the source code and/or documentation for "
836              "other Copyright messages.\n\n");              "other Copyright messages.\n\n");
837    
838          if (emuls[0]->machines[0]->machine_type == MACHINE_NONE)          if (emuls[0]->machines[0]->machine_type == MACHINE_NONE) {
839                  n_emuls --;                  n_emuls --;
840          else {          } else {
841                  for (i=0; i<n_diskimages; i++)                  for (i=0; i<n_diskimages; i++)
842                          diskimage_add(emuls[0]->machines[0], diskimages[i]);                          diskimage_add(emuls[0]->machines[0], diskimages[i]);
843          }          }
# Line 777  int main(int argc, char *argv[]) Line 862  int main(int argc, char *argv[])
862          /*  Initialize emulations from config files:  */          /*  Initialize emulations from config files:  */
863          for (i=1; i<argc; i++) {          for (i=1; i<argc; i++) {
864                  if (argv[i][0] == '@') {                  if (argv[i][0] == '@') {
865                            char tmpstr[50];
866                          char *s = argv[i] + 1;                          char *s = argv[i] + 1;
867                          if (strlen(s) == 0 && i+1 < argc &&                          if (strlen(s) == 0 && i+1 < argc &&
868                              argv[i+1][0] != '@') {                              argv[i+1][0] != '@') {
# Line 789  int main(int argc, char *argv[]) Line 875  int main(int argc, char *argv[])
875                                  fprintf(stderr, "out of memory\n");                                  fprintf(stderr, "out of memory\n");
876                                  exit(1);                                  exit(1);
877                          }                          }
                         emuls[n_emuls - 1] =  
                             emul_create_from_configfile(s);  
878    
879                          /*  Always allow slave xterms when using multiple                          /*  Always allow slave xterms when using multiple
880                              emulations:  */                              emulations:  */
881                          console_allow_slaves(1);                          console_allow_slaves(1);
882    
883                            /*  Destroy the temporary emuls[0], since it will
884                                be overwritten:  */
885                            if (n_emuls == 1) {
886                                    emul_destroy(emuls[0]);
887                                    settings_remove(global_settings, "emul[0]");
888                            }
889    
890                            emuls[n_emuls - 1] =
891                                emul_create_from_configfile(s, n_emuls - 1);
892    
893                            snprintf(tmpstr, sizeof(tmpstr), "emul[%i]", n_emuls-1);
894                            settings_add(global_settings, tmpstr, 1,
895                                SETTINGS_TYPE_SUBSETTINGS, 0,
896                                emuls[n_emuls-1]->settings);
897                  }                  }
898          }          }
899    
# Line 808  int main(int argc, char *argv[]) Line 907  int main(int argc, char *argv[])
907          }          }
908    
909          device_set_exit_on_error(0);          device_set_exit_on_error(0);
910          console_warn_if_slaves_are_needed();          console_warn_if_slaves_are_needed(1);
911    
912    
913          /*  Run all emulations:  */          /*  Run all emulations:  */
914          emul_run(emuls, n_emuls);          emul_run(emuls, n_emuls);
915    
916    
917            /*
918             *  Deinitialize everything:
919             */
920    
921            console_deinit();
922    
923            for (i=0; i<n_emuls; i++)
924                    emul_destroy(emuls[i]);
925    
926            settings_remove_all(global_settings);
927            settings_destroy(global_settings);
928    
929    #ifdef USE_PROFIL
930    {
931            int i;
932            FILE *f = fopen("output.txt", "w");
933            for (i=0; i<sizeof(samples) / sizeof(uint16_t); ++i) {
934                    if (samples[i] != 0)
935                            fprintf(f, "%i %p\n", samples[i],
936                                (void *) (size_t) (0x400000 + i * 16));
937            }
938    }
939    #endif
940    
941          return 0;          return 0;
942  }  }
943    

Legend:
Removed from v.20  
changed lines
  Added in v.34

  ViewVC Help
Powered by ViewVC 1.1.26