/[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 4 by dpavlin, Mon Oct 8 16:18:00 2007 UTC revision 22 by dpavlin, Mon Oct 8 16:19:37 2007 UTC
# Line 1  Line 1 
1  /*  /*
2   *  Copyright (C) 2003-2005  Anders Gavare.  All rights reserved.   *  Copyright (C) 2003-2006  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.232 2005/04/18 21:40:58 debug Exp $   *  $Id: main.c,v 1.256 2006/02/04 11:10:58 debug Exp $
29   */   */
30    
31  #include <stdio.h>  #include <stdio.h>
# Line 56  char **extra_argv; Line 56  char **extra_argv;
56  char *progname;  char *progname;
57    
58  int fully_deterministic = 0;  int fully_deterministic = 0;
59    int dyntrans_backend_enable = 1;
60    
61    
62  /*****************************************************************************  /*****************************************************************************
# Line 155  void fatal(char *fmt, ...) Line 156  void fatal(char *fmt, ...)
156    
157    
158  /*  /*
  *  mystrtoull():  
  *  
  *  This function is used on OSes that don't have strtoull() in libc.  
  */  
 unsigned long long mystrtoull(const char *s, char **endp, int base)  
 {  
         unsigned long long res = 0;  
         int minus_sign = 0;  
   
         if (s == NULL)  
                 return 0;  
   
         /*  TODO: Implement endp?  */  
         if (endp != NULL) {  
                 fprintf(stderr, "mystrtoull(): endp isn't implemented\n");  
                 exit(1);  
         }  
   
         if (s[0] == '-') {  
                 minus_sign = 1;  
                 s++;  
         }  
   
         /*  Guess base:  */  
         if (base == 0) {  
                 if (s[0] == '0') {  
                         /*  Just "0"? :-)  */  
                         if (!s[1])  
                                 return 0;  
                         if (s[1] == 'x' || s[1] == 'X') {  
                                 base = 16;  
                                 s += 2;  
                         } else {  
                                 base = 8;  
                                 s ++;  
                         }  
                 } else if (s[0] >= '1' && s[0] <= '9')  
                         base = 10;  
         }  
   
         while (s[0]) {  
                 int c = s[0];  
                 if (c >= '0' && c <= '9')  
                         c -= '0';  
                 else if (c >= 'a' && c <= 'f')  
                         c = c - 'a' + 10;  
                 else if (c >= 'A' && c <= 'F')  
                         c = c - 'A' + 10;  
                 else  
                         break;  
                 switch (base) {  
                 case 8: res = (res << 3) | c;  
                         break;  
                 case 16:res = (res << 4) | c;  
                         break;  
                 default:res = (res * base) + c;  
                 }  
                 s++;  
         }  
   
         if (minus_sign)  
                 res = (uint64_t) -(int64_t)res;  
         return res;  
 }  
   
   
 /*****************************************************************************/  
   
   
 /*  
159   *  internal_w():   *  internal_w():
160   *   *
161   *  For internal use by gxemul itself.   *  For internal use by gxemul itself.
# Line 264  static void usage(int longusage) Line 195  static void usage(int longusage)
195  #ifdef VERSION  #ifdef VERSION
196          printf("-" VERSION);          printf("-" VERSION);
197  #endif  #endif
198          printf("   Copyright (C) 2003-2005  Anders Gavare\n");          printf("   Copyright (C) 2003-2006  Anders Gavare\n");
199          printf("Read the source code and/or documentation for "          printf("Read the source code and/or documentation for "
200              "other Copyright messages.\n");              "other Copyright messages.\n");
201    
202          printf("\nusage: %s [machine, other, and general options] [file "          printf("\nusage: %s [machine, other, and general options] [file "
203              "[...]]\n", progname);              "[...]]\n", progname);
204          printf("   or  %s [general options] @configfile [...]\n", progname);          printf("   or  %s [general options] @configfile\n", progname);
205          printf("   or  %s [userland, other, and general options] file "          printf("   or  %s [userland, other, and general options] file "
206              "[args ...]\n", progname);              "[args ...]\n", progname);
207    
# Line 287  static void usage(int longusage) Line 218  static void usage(int longusage)
218              "with -E.)\n");              "with -E.)\n");
219    
220          printf("\nOther options:\n");          printf("\nOther options:\n");
221  #ifdef BINTRANS          printf("  -A        disable alignment checks in some cases (for higher"
222          printf("  -B        disable dynamic binary translation completely\n");              " speed)\n");
223          printf("  -b        use the OLD binary translation subsystem\n");  #if defined(BINTRANS) || defined(DYNTRANS_BACKEND)
224            printf("  -B        disable native translation backends. (translation"
225                " is turned on\n            by default, if it is supposed for "
226                "the particular host)\n");
227  #endif  #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:\""
231              " as a prefix\n");              " as a prefix\n");
232          printf("            where xxx is one or more of the following:\n");          printf("            where xxx is one or more of the following:\n");
233          printf("                b     specifies that this is the boot"          printf("                b      specifies that this is the boot"
234              " device\n");              " device\n");
235          printf("                c     CD-ROM\n");          printf("                c      CD-ROM\n");
236          printf("                d     DISK\n");          printf("                d      DISK\n");
237          printf("                f     FLOPPY\n");          printf("                f      FLOPPY\n");
238          printf("                i     IDE\n");          printf("                gH;S;  set geometry to H heads and S"
239          printf("                r     read-only (don't allow changes to the"              " sectors-per-track\n");
240            printf("                i      IDE\n");
241            printf("                r      read-only (don't allow changes to the"
242              " file)\n");              " file)\n");
243          printf("                s     SCSI\n");          printf("                s      SCSI\n");
244          printf("                t     tape\n");          printf("                t      tape\n");
245          printf("                0-7   force a specific ID\n");          printf("                0-7    force a specific ID\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"
# Line 344  static void usage(int longusage) Line 280  static void usage(int longusage)
280          printf("  -X        use X11\n");          printf("  -X        use X11\n");
281  #endif /*  WITH_X11  */  #endif /*  WITH_X11  */
282          printf("  -x        open up new xterms for emulated serial ports "          printf("  -x        open up new xterms for emulated serial ports "
283              "(default is on when\n            using configuration files, off"              "(default is on when\n            using configuration files or"
284              " otherwise)\n");              " when X11 is used, off otherwise)\n");
285  #ifdef WITH_X11  #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  */
# Line 362  static void usage(int longusage) Line 298  static void usage(int longusage)
298              " get a list of\n            available emulation modes)\n");              " get a list of\n            available emulation modes)\n");
299    
300          printf("\nGeneral options:\n");          printf("\nGeneral options:\n");
301            printf("  -c cmd    add cmd as a command to run before starting "
302                "the simulation\n");
303          printf("  -D        guarantee fully deterministic behaviour\n");          printf("  -D        guarantee fully deterministic behaviour\n");
304          printf("  -H        display a list of possible CPU and "          printf("  -H        display a list of possible CPU and "
305              "machine types\n");              "machine types\n");
# Line 405  int get_cmd_args(int argc, char *argv[], Line 343  int get_cmd_args(int argc, char *argv[],
343          int msopts = 0;         /*  Machine-specific options used  */          int msopts = 0;         /*  Machine-specific options used  */
344          struct machine *m = emul_add_machine(emul, "default");          struct machine *m = emul_add_machine(emul, "default");
345    
346          while ((ch = getopt(argc, argv, "BbC:Dd:E:e:HhI:iJj:KM:m:"          while ((ch = getopt(argc, argv, "ABC:c:Dd:E:e:HhI:iJj:KM:m:"
347              "Nn:Oo:p:QqRrSsTtUu:VvW:XxY:y:Z:z:")) != -1) {              "Nn:Oo:p:QqRrSsTtUu:VvW:XxY:y:Z:z:")) != -1) {
348                  switch (ch) {                  switch (ch) {
349                  case 'B':                  case 'A':
350                          m->bintrans_enable = 0;                          m->dyntrans_alignment_check = 0;
351                          msopts = 1;                          msopts = 1;
352                          break;                          break;
353                  case 'b':                  case 'B':
354                          m->old_bintrans_enable = 1;                          /*  Turns off both bintrans and dyntrans.  */
355                            m->bintrans_enable = 0;
356                            dyntrans_backend_enable = 0;
357                          msopts = 1;                          msopts = 1;
358                          break;                          break;
359                  case 'C':                  case 'C':
360                          m->cpu_name = strdup(optarg);                          m->cpu_name = strdup(optarg);
361                          msopts = 1;                          msopts = 1;
362                          break;                          break;
363                    case 'c':
364                            emul->n_debugger_cmds ++;
365                            emul->debugger_cmds = realloc(emul->debugger_cmds,
366                                emul->n_debugger_cmds * sizeof(char *));
367                            if (emul->debugger_cmds == NULL) {
368                                    fatal("out of memory\n");
369                                    exit(1);
370                            }
371                            emul->debugger_cmds[emul->n_debugger_cmds-1] =
372                                strdup(optarg);
373                            break;
374                  case 'D':                  case 'D':
375                          fully_deterministic = 1;                          fully_deterministic = 1;
376                          break;                          break;
# Line 572  int get_cmd_args(int argc, char *argv[], Line 523  int get_cmd_args(int argc, char *argv[],
523                  case 'X':                  case 'X':
524                          m->use_x11 = 1;                          m->use_x11 = 1;
525                          msopts = 1;                          msopts = 1;
526                          break;                          /*  FALL-THROUGH  */
527                  case 'x':                  case 'x':
528                          console_allow_slaves(1);                          console_allow_slaves(1);
529                          break;                          break;
530                  case 'Y':                  case 'Y':
531                          m->x11_scaledown = atoi(optarg);                          m->x11_scaledown = atoi(optarg);
532                            if (m->x11_scaledown < -1) {
533                                    m->x11_scaleup = - m->x11_scaledown;
534                                    m->x11_scaledown = 1;
535                            }
536                          if (m->x11_scaledown < 1) {                          if (m->x11_scaledown < 1) {
537                                  fprintf(stderr, "Invalid scaledown value.\n");                                  fprintf(stderr, "Invalid scaledown value.\n");
538                                  exit(1);                                  exit(1);
# Line 612  int get_cmd_args(int argc, char *argv[], Line 567  int get_cmd_args(int argc, char *argv[],
567                          msopts = 1;                          msopts = 1;
568                          break;                          break;
569                  default:                  default:
570                          fprintf(stderr, "Invalid option.\n");                          fprintf(stderr, "Run  %s -h  for help on command "
571                          usage(0);                              "line options.\n", progname);
572                          exit(1);                          exit(1);
573                  }                  }
574          }          }
575    
576          if (type != NULL) {          if (type != NULL || subtype != NULL) {
577                    if (type == NULL)
578                            type = "";
579                  if (subtype == NULL)                  if (subtype == NULL)
580                          subtype = "";                          subtype = "";
581                  res = machine_name_to_type(type, subtype,                  res = machine_name_to_type(type, subtype,
# Line 634  int get_cmd_args(int argc, char *argv[], Line 591  int get_cmd_args(int argc, char *argv[],
591          extra_argv = argv;          extra_argv = argv;
592    
593    
         if (!m->bintrans_enable && m->old_bintrans_enable) {  
                 fprintf(stderr, "You cannot both select old bintrans and"  
                     " disable bintrans at the same time.\n");  
                 exit(1);  
         }  
   
         /*  TODO: Remove this once there is a new bintrans system.  */  
         if (m->bintrans_enable && !m->old_bintrans_enable) {  
                 m->bintrans_enable = 0;  
         }  
   
594          if (m->machine_type == MACHINE_NONE && msopts) {          if (m->machine_type == MACHINE_NONE && msopts) {
595                  fprintf(stderr, "Machine specific options used directly on "                  fprintf(stderr, "Machine specific options used directly on "
596                      "the command line, but no machine\nemulation specified?\n");                      "the command line, but no machine\nemulation specified?\n");
# Line 652  int get_cmd_args(int argc, char *argv[], Line 598  int get_cmd_args(int argc, char *argv[],
598          }          }
599    
600    
601          /*  -i, -r, -t are pretty verbose:  */          /*  -i and -r are pretty verbose:  */
602    
603          if (m->instruction_trace && !verbose) {          if (m->instruction_trace && !verbose) {
604                  fprintf(stderr, "Implicitly %sturning on -v, because"                  fprintf(stderr, "Implicitly %sturning on -v, because"
# Line 668  int get_cmd_args(int argc, char *argv[], Line 614  int get_cmd_args(int argc, char *argv[],
614                  quiet_mode = 0;                  quiet_mode = 0;
615          }          }
616    
617          if (m->show_trace_tree && !verbose) {          if ((m->instruction_trace || m->register_dump || m->show_trace_tree)
618                  fprintf(stderr, "Implicitly %sturning on -v, because"              && m->bintrans_enable) {
619                      " of -t\n", quiet_mode? "turning off -q and " : "");                  if (m->arch == ARCH_MIPS)
620                  verbose = 1;                          fprintf(stderr, "Implicitly turning off bintrans.\n");
621                  quiet_mode = 0;                  m->bintrans_enable = 0;
622          }          }
623    
624    
# Line 721  int get_cmd_args(int argc, char *argv[], Line 667  int get_cmd_args(int argc, char *argv[],
667                  exit(1);                  exit(1);
668          }          }
669    
670          if (m->bintrans_enable) {  #ifndef EXPERIMENTAL_NEWMIPS
671            if (m->bintrans_enable && m->arch == ARCH_MIPS) {
672                  m->speed_tricks = 0;                  m->speed_tricks = 0;
673                  /*  TODO: Print a warning about this?  */                  /*  TODO: Print a warning about this?  */
674          }          }
675    #endif
676    
677          if (m->n_breakpoints > 0 && m->bintrans_enable) {          if (m->n_breakpoints > 0 &&
678                  fprintf(stderr, "Breakpoints and dynamic translation "              m->bintrans_enable && m->arch == ARCH_MIPS) {
679                    fprintf(stderr, "Breakpoints and MIPS binary translation "
680                      "don't work too well together right now.\n");                      "don't work too well together right now.\n");
681                  exit(1);                  exit(1);
682          }          }
# Line 815  int main(int argc, char *argv[]) Line 764  int main(int argc, char *argv[])
764  #ifdef VERSION  #ifdef VERSION
765          debug("-" VERSION);          debug("-" VERSION);
766  #endif  #endif
767          debug("   Copyright (C) 2003-2005  Anders Gavare\n");          debug("   Copyright (C) 2003-2006  Anders Gavare\n");
768          debug("Read the source code and/or documentation for "          debug("Read the source code and/or documentation for "
769              "other Copyright messages.\n\n");              "other Copyright messages.\n\n");
770    
# Line 858  int main(int argc, char *argv[]) Line 807  int main(int argc, char *argv[])
807                                  fprintf(stderr, "out of memory\n");                                  fprintf(stderr, "out of memory\n");
808                                  exit(1);                                  exit(1);
809                          }                          }
                         emuls[n_emuls - 1] =  
                             emul_create_from_configfile(s);  
810    
811                          /*  Always allow slave xterms when using multiple                          /*  Always allow slave xterms when using multiple
812                              emulations:  */                              emulations:  */
813                          console_allow_slaves(1);                          console_allow_slaves(1);
814    
815                            emuls[n_emuls - 1] =
816                                emul_create_from_configfile(s);
817                  }                  }
818          }          }
819    
820          if (n_emuls == 0) {          if (n_emuls == 0) {
821                  fprintf(stderr, "No emulations defined.\n");                  fprintf(stderr, "No emulations defined. Maybe you forgot to "
822                        "use -E xx and/or -e yy, to specify\nthe machine type."
823                        " For example:\n\n    %s -e 3max -d disk.img\n\n"
824                        "to boot an emulated DECstation 5000/200 with a disk "
825                        "image.\n", progname);
826                  exit(1);                  exit(1);
827          }          }
828    
829          device_set_exit_on_error(0);          device_set_exit_on_error(0);
830            console_warn_if_slaves_are_needed(1);
831    
832          /*  Run all emulations:  */          /*  Run all emulations:  */
833          emul_run(emuls, n_emuls);          emul_run(emuls, n_emuls);

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

  ViewVC Help
Powered by ViewVC 1.1.26