/[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 24 by dpavlin, Mon Oct 8 16:19:56 2007 UTC revision 32 by dpavlin, Mon Oct 8 16:20:58 2007 UTC
# Line 25  Line 25 
25   *  SUCH DAMAGE.   *  SUCH DAMAGE.
26   *   *
27   *   *
28   *  $Id: main.c,v 1.274 2006/06/22 13:22:41 debug Exp $   *  $Id: main.c,v 1.284 2006/09/19 10:50:08 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"  #include "settings.h"
47    #include "timer.h"
48    
49    
50  extern volatile int single_step;  extern volatile int single_step;
# Line 57  int extra_argc; Line 59  int extra_argc;
59  char **extra_argv;  char **extra_argv;
60  char *progname;  char *progname;
61    
62  int fully_deterministic = 0;  int skip_srandom_call = 0;
63    
64    
65  /*****************************************************************************  /*****************************************************************************
# Line 194  static void usage(int longusage) Line 196  static void usage(int longusage)
196  {  {
197          printf("GXemul");          printf("GXemul");
198  #ifdef VERSION  #ifdef VERSION
199          printf("-" VERSION);          printf(" " VERSION);
200  #endif  #endif
201          printf("   Copyright (C) 2003-2006  Anders Gavare\n");          printf("    Copyright (C) 2003-2006  Anders Gavare\n");
202          printf("Read the source code and/or documentation for "          printf("Read the source code and/or documentation for "
203              "other Copyright messages.\n");              "other Copyright messages.\n");
204    
# Line 221  static void usage(int longusage) Line 223  static void usage(int longusage)
223              "with -E.)\n");              "with -E.)\n");
224    
225          printf("\nOther options:\n");          printf("\nOther options:\n");
         printf("  -A        disable alignment checks in some cases (for higher"  
             " speed)\n");  
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 242  static void usage(int longusage) Line 242  static void usage(int longusage)
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");          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 hz     set the main cpu frequency to hz (not used by "
246              " rtc devices only, not\n");              "all combinations\n            of machines and guest OSes)");
         printf("            actual runtime speed) (this disables automatic"  
             " clock adjustments)\n");  
247          printf("  -i        display each instruction as it is executed\n");          printf("  -i        display each instruction as it is executed\n");
248          printf("  -J        disable some speed tricks\n");          printf("  -J        disable dyntrans instruction combinations\n");
249          printf("  -j name   set the name of the kernel; for DECstation "          printf("  -j name   set the name of the kernel; for DECstation "
250              "emulation, this passes\n            the name to the bootloader,"              "emulation, this passes\n            the name to the bootloader,"
251              " for example:\n");              " for example:\n");
# Line 276  static void usage(int longusage) Line 274  static void usage(int longusage)
274          printf("  -r        register dumps before every instruction\n");          printf("  -r        register dumps before every instruction\n");
275          printf("  -S        initialize emulated RAM to random bytes, "          printf("  -S        initialize emulated RAM to random bytes, "
276              "instead of zeroes\n");              "instead of zeroes\n");
277            printf("  -s f:name write statistics to file 'name', "
278                "f is one or more of the following:\n");
279            printf("                v    virtual program counter\n");
280            printf("                p    physical equivalent of program counter\n");
281            printf("                i    internal ic->f representation of "
282                "the program counter\n");
283            printf("            and optionally:\n");
284            printf("                d    disable statistics gathering at "
285                "startup\n");
286            printf("                o    overwrite instead of append\n");
287          printf("  -t        show function trace tree\n");          printf("  -t        show function trace tree\n");
288          printf("  -U        enable slow_serial_interrupts_hack_for_linux\n");          printf("  -U        enable slow_serial_interrupts_hack_for_linux\n");
289  #ifdef WITH_X11  #ifdef WITH_X11
# Line 300  static void usage(int longusage) Line 308  static void usage(int longusage)
308          printf("\nGeneral options:\n");          printf("\nGeneral options:\n");
309          printf("  -c cmd    add cmd as a command to run before starting "          printf("  -c cmd    add cmd as a command to run before starting "
310              "the simulation\n");              "the simulation\n");
311          printf("  -D        guarantee (almost) fully deterministic "          printf("  -D        skip the srandom call at startup\n");
             "behaviour\n");  
312          printf("  -H        display a list of possible CPU and "          printf("  -H        display a list of possible CPU and "
313              "machine types\n");              "machine types\n");
314          printf("  -h        display this help message\n");          printf("  -h        display this help message\n");
# Line 345  int get_cmd_args(int argc, char *argv[], Line 352  int get_cmd_args(int argc, char *argv[],
352          struct machine *m = emul_add_machine(emul, "default");          struct machine *m = emul_add_machine(emul, "default");
353    
354          char *opts =          char *opts =
355              "A"              "C:c:Dd:E:e:G:HhI:iJj:KM:Nn:Oo:p:QqRrSs:tU"
             "C:c:Dd:E:e:G:HhI:iJj:KM:Nn:Oo:p:QqRrStU"  
356  #ifdef UNSTABLE_DEVEL  #ifdef UNSTABLE_DEVEL
357              "u:"              "u:"
358  #endif  #endif
# Line 358  int get_cmd_args(int argc, char *argv[], Line 364  int get_cmd_args(int argc, char *argv[],
364    
365          while ((ch = getopt(argc, argv, opts)) != -1) {          while ((ch = getopt(argc, argv, opts)) != -1) {
366                  switch (ch) {                  switch (ch) {
                 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;  
367                  case 'C':                  case 'C':
368                          m->cpu_name = strdup(optarg);                          m->cpu_name = strdup(optarg);
369                          msopts = 1;                          msopts = 1;
# Line 380  int get_cmd_args(int argc, char *argv[], Line 380  int get_cmd_args(int argc, char *argv[],
380                              strdup(optarg);                              strdup(optarg);
381                          break;                          break;
382                  case 'D':                  case 'D':
383                          fully_deterministic = 1;                          skip_srandom_call = 1;
384                          break;                          break;
385                  case 'd':                  case 'd':
386                          /*  diskimage_add() is called further down  */                          /*  diskimage_add() is called further down  */
# Line 418  int get_cmd_args(int argc, char *argv[], Line 418  int get_cmd_args(int argc, char *argv[],
418                                      m->gdb.port);                                      m->gdb.port);
419                                  exit(1);                                  exit(1);
420                          }                          }
421                          single_step = 1;        /*  implicit -V  */                          /*  Note: implicit -V  */
422                            single_step = ENTER_SINGLE_STEPPING;
423                          msopts = 1;                          msopts = 1;
424                          break;                          break;
425                  case 'H':                  case 'H':
# Line 429  int get_cmd_args(int argc, char *argv[], Line 430  int get_cmd_args(int argc, char *argv[],
430                          exit(1);                          exit(1);
431                  case 'I':                  case 'I':
432                          m->emulated_hz = atoi(optarg);                          m->emulated_hz = atoi(optarg);
                         m->automatic_clock_adjustment = 0;  
433                          msopts = 1;                          msopts = 1;
434                          break;                          break;
435                  case 'i':                  case 'i':
# Line 437  int get_cmd_args(int argc, char *argv[], Line 437  int get_cmd_args(int argc, char *argv[],
437                          msopts = 1;                          msopts = 1;
438                          break;                          break;
439                  case 'J':                  case 'J':
440                          m->speed_tricks = 0;                          m->allow_instruction_combinations = 0;
441                          msopts = 1;                          msopts = 1;
442                          break;                          break;
443                  case 'j':                  case 'j':
# Line 509  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;
512                    case 's':
513                            machine_statistics_init(m, optarg);
514                            msopts = 1;
515                            break;
516                  case 't':                  case 't':
517                          m->show_trace_tree = 1;                          m->show_trace_tree = 1;
518                          msopts = 1;                          msopts = 1;
# Line 527  int get_cmd_args(int argc, char *argv[], Line 531  int get_cmd_args(int argc, char *argv[],
531                          msopts = 1;                          msopts = 1;
532                          break;                          break;
533                  case 'V':                  case 'V':
534                          single_step = 1;                          single_step = ENTER_SINGLE_STEPPING;
535                          break;                          break;
536                  case 'v':                  case 'v':
537                          verbose ++;                          verbose ++;
# Line 690  int get_cmd_args(int argc, char *argv[], Line 694  int get_cmd_args(int argc, char *argv[],
694   */   */
695  int main(int argc, char *argv[])  int main(int argc, char *argv[])
696  {  {
697            /*  Setting constants:  */
698            const int constant_yes = 1;
699            const int constant_true = 1;
700            const int constant_no = 0;
701            const int constant_false = 0;
702    
703          struct emul **emuls;          struct emul **emuls;
704          char **diskimages = NULL;          char **diskimages = NULL;
705          int n_diskimages = 0;          int n_diskimages = 0;
706          int n_emuls;          int n_emuls;
707          int i;          int i;
708    
709    
710          progname = argv[0];          progname = argv[0];
711    
712          /*  Create the settings object, and add global settings to it:  */  
713            /*
714             *  Create the settings object, and add global settings to it:
715             *
716             *  Read-only "constants":     yes, no, true, false.
717             *  Global emulator settings:  verbose, single_step, ...
718             */
719          global_settings = settings_new();          global_settings = settings_new();
720    
721            settings_add(global_settings, "yes", 0, SETTINGS_TYPE_INT,
722                SETTINGS_FORMAT_YESNO, (void *)&constant_yes);
723            settings_add(global_settings, "no", 0, SETTINGS_TYPE_INT,
724                SETTINGS_FORMAT_YESNO, (void *)&constant_no);
725            settings_add(global_settings, "true", 0, SETTINGS_TYPE_INT,
726                SETTINGS_FORMAT_BOOL, (void *)&constant_true);
727            settings_add(global_settings, "false", 0, SETTINGS_TYPE_INT,
728                SETTINGS_FORMAT_BOOL, (void *)&constant_false);
729    
730          settings_add(global_settings, "single_step", 0,          settings_add(global_settings, "single_step", 0,
731              SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, (void *)&single_step);              SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, (void *)&single_step);
732          settings_add(global_settings, "force_debugger_at_exit", 1,          settings_add(global_settings, "force_debugger_at_exit", 1,
733              SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO,              SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO,
734              (void *)&force_debugger_at_exit);              (void *)&force_debugger_at_exit);
         settings_add(global_settings, "fully_deterministic", 0,  
             SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO,  
             (void *)&fully_deterministic);  
735          settings_add(global_settings, "verbose", 1,          settings_add(global_settings, "verbose", 1,
736              SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, (void *)&verbose);              SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, (void *)&verbose);
737          settings_add(global_settings, "quiet_mode", 1,          settings_add(global_settings, "quiet_mode", 1,
# Line 719  int main(int argc, char *argv[]) Line 742  int main(int argc, char *argv[])
742          cpu_init();          cpu_init();
743          device_init();          device_init();
744          machine_init();          machine_init();
745            timer_init();
746          useremul_init();          useremul_init();
747    
748          emuls = malloc(sizeof(struct emul *));          emuls = malloc(sizeof(struct emul *));
# Line 734  int main(int argc, char *argv[]) Line 758  int main(int argc, char *argv[])
758                  fprintf(stderr, "out of memory\n");                  fprintf(stderr, "out of memory\n");
759                  exit(1);                  exit(1);
760          }          }
761            settings_add(global_settings, "emul[0]", 1,
762                SETTINGS_TYPE_SUBSETTINGS, 0, emuls[0]->settings);
763    
764          get_cmd_args(argc, argv, emuls[0], &diskimages, &n_diskimages);          get_cmd_args(argc, argv, emuls[0], &diskimages, &n_diskimages);
765    
766          if (!fully_deterministic) {          if (!skip_srandom_call) {
767                  /*  TODO: More than just time(). Use gettimeofday().  */                  struct timeval tv;
768                  srandom(time(NULL) ^ (getpid() << 12));                  gettimeofday(&tv, NULL);
769          } 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);  
                 }  
770          }          }
771    
772          /*  Print startup message:  */          /*  Print startup message:  */
773          debug("GXemul");          debug("GXemul");
774  #ifdef VERSION  #ifdef VERSION
775          debug("-" VERSION);          debug(" " VERSION);
776  #endif  #endif
777          debug("   Copyright (C) 2003-2006  Anders Gavare\n");          debug("    Copyright (C) 2003-2006  Anders Gavare\n");
778          debug("Read the source code and/or documentation for "          debug("Read the source code and/or documentation for "
779              "other Copyright messages.\n\n");              "other Copyright messages.\n\n");
780    
781          if (emuls[0]->machines[0]->machine_type == MACHINE_NONE)          if (emuls[0]->machines[0]->machine_type == MACHINE_NONE) {
782                  n_emuls --;                  n_emuls --;
783          else {          } else {
784                  for (i=0; i<n_diskimages; i++)                  for (i=0; i<n_diskimages; i++)
785                          diskimage_add(emuls[0]->machines[0], diskimages[i]);                          diskimage_add(emuls[0]->machines[0], diskimages[i]);
786          }          }
# Line 784  int main(int argc, char *argv[]) Line 805  int main(int argc, char *argv[])
805          /*  Initialize emulations from config files:  */          /*  Initialize emulations from config files:  */
806          for (i=1; i<argc; i++) {          for (i=1; i<argc; i++) {
807                  if (argv[i][0] == '@') {                  if (argv[i][0] == '@') {
808                            char tmpstr[50];
809                          char *s = argv[i] + 1;                          char *s = argv[i] + 1;
810                          if (strlen(s) == 0 && i+1 < argc &&                          if (strlen(s) == 0 && i+1 < argc &&
811                              argv[i+1][0] != '@') {                              argv[i+1][0] != '@') {
# Line 801  int main(int argc, char *argv[]) Line 823  int main(int argc, char *argv[])
823                              emulations:  */                              emulations:  */
824                          console_allow_slaves(1);                          console_allow_slaves(1);
825    
826                            /*  Destroy the temporary emuls[0], since it will
827                                be overwritten:  */
828                            if (n_emuls == 1) {
829                                    emul_destroy(emuls[0]);
830                                    settings_remove(global_settings, "emul[0]");
831                            }
832    
833                          emuls[n_emuls - 1] =                          emuls[n_emuls - 1] =
834                              emul_create_from_configfile(s);                              emul_create_from_configfile(s);
835    
836                            snprintf(tmpstr, sizeof(tmpstr), "emul[%i]", n_emuls-1);
837                            settings_add(global_settings, tmpstr, 1,
838                                SETTINGS_TYPE_SUBSETTINGS, 0,
839                                emuls[n_emuls-1]->settings);
840                  }                  }
841          }          }
842    
# Line 818  int main(int argc, char *argv[]) Line 852  int main(int argc, char *argv[])
852          device_set_exit_on_error(0);          device_set_exit_on_error(0);
853          console_warn_if_slaves_are_needed(1);          console_warn_if_slaves_are_needed(1);
854    
855    
856          /*  Run all emulations:  */          /*  Run all emulations:  */
857          emul_run(emuls, n_emuls);          emul_run(emuls, n_emuls);
858    
859    
860            /*
861             *  Deinitialize everything:
862             */
863    
864            console_deinit();
865    
866            for (i=0; i<n_emuls; i++)
867                    emul_destroy(emuls[i]);
868    
869            settings_remove_all(global_settings);
870          settings_destroy(global_settings);          settings_destroy(global_settings);
871    
872          return 0;          return 0;

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

  ViewVC Help
Powered by ViewVC 1.1.26