/[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 2 by dpavlin, Mon Oct 8 16:17:48 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.228 2005/04/07 15:43:17 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 (instead of normal SCSI DISK)\n");          printf("                c      CD-ROM\n");
236          printf("                d     SCSI DISK (this is the default)\n");          printf("                d      DISK\n");
237          printf("                i     IDE (instead of SCSI)\n");          printf("                f      FLOPPY\n");
238          printf("                r     read-only (don't allow changes to the"          printf("                gH;S;  set geometry to H heads and S"
239                " 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("                t     SCSI tape\n");          printf("                s      SCSI\n");
244          printf("                0-7   force a specific SCSI ID number\n");          printf("                t      tape\n");
245            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 342  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 360  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 379  static void usage(int longusage) Line 319  static void usage(int longusage)
319              "on a binary.\n"              "on a binary.\n"
320              "To load a raw binary into memory, add \"address:\" in front "              "To load a raw binary into memory, add \"address:\" in front "
321              "of the filename,\n"              "of the filename,\n"
322              "or \"address:skiplen:\" or \"address:skiplen:initialpc\".\n"              "or \"address:skiplen:\" or \"address:skiplen:initialpc:\".\n"
323              "Examples:\n"              "Examples:\n"
324              "    0xbfc00000:rom.bin                  for a raw ROM image\n"              "    0xbfc00000:rom.bin                    for a raw ROM image\n"
325              "    0xbfc00000:0x100:rom.bin            for an image with "              "    0xbfc00000:0x100:rom.bin              for an image with "
326              "0x100 bytes header\n"              "0x100 bytes header\n"
327              "    0xbfc00000:0x100:0xbfc00884:rom.bin  "              "    0xbfc00000:0x100:0xbfc00884:rom.bin   "
328              "start with pc=0xbfc00884\n");              "start with pc=0xbfc00884\n");
329  }  }
330    
# Line 394  static void usage(int longusage) Line 334  static void usage(int longusage)
334   *   *
335   *  Reads command line arguments.   *  Reads command line arguments.
336   */   */
337  int get_cmd_args(int argc, char *argv[], struct emul *emul)  int get_cmd_args(int argc, char *argv[], struct emul *emul,
338            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          char *type = NULL, *subtype = NULL;          char *type = NULL, *subtype = NULL;
# Line 402  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;
377                  case 'd':                  case 'd':
378                          diskimage_add(m, optarg);                          /*  diskimage_add() is called further down  */
379                            (*n_diskimagesp) ++;
380                            (*diskimagesp) = realloc(*diskimagesp,
381                                sizeof(char *) * (*n_diskimagesp));
382                            if (*diskimagesp == NULL) {
383                                    fprintf(stderr, "out of memory\n");
384                                    exit(1);
385                            }
386                            (*diskimagesp)[(*n_diskimagesp) - 1] = strdup(optarg);
387                          using_switch_d = 1;                          using_switch_d = 1;
388                          msopts = 1;                          msopts = 1;
389                          break;                          break;
# Line 561  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) {
537                                    fprintf(stderr, "Invalid scaledown value.\n");
538                                    exit(1);
539                            }
540                          msopts = 1;                          msopts = 1;
541                          break;                          break;
542                  case 'y':                  case 'y':
# Line 597  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 619  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 637  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 turning of -q and turning on -v, "                  fprintf(stderr, "Implicitly %sturning on -v, because"
605                      "because of -i\n");                      " of -i\n", quiet_mode? "turning off -q and " : "");
606                  verbose = 1;                  verbose = 1;
607                  quiet_mode = 0;                  quiet_mode = 0;
608          }          }
609    
610          if (m->register_dump && !verbose) {          if (m->register_dump && !verbose) {
611                  fprintf(stderr, "Implicitly turning of -q and turning on -v, "                  fprintf(stderr, "Implicitly %sturning on -v, because"
612                      "because of -r\n");                      " of -r\n", quiet_mode? "turning off -q and " : "");
613                  verbose = 1;                  verbose = 1;
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 turning of -q and turning on -v, "              && m->bintrans_enable) {
619                      "because of -t\n");                  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 665  int get_cmd_args(int argc, char *argv[], Line 626  int get_cmd_args(int argc, char *argv[],
626           *  Usually, an executable filename must be supplied.           *  Usually, an executable filename must be supplied.
627           *           *
628           *  However, it is possible to boot directly from a harddisk image           *  However, it is possible to boot directly from a harddisk image
629           *  file. If no kernel is supplied, and the emulation mode is set to           *  file. If no kernel is supplied, but a diskimage is being used,
630           *  DECstation emulation, and there is a diskimage, then try to boot           *  then try to boot from disk.
          *  from that.  
631           */           */
632          if (extra_argc == 0) {          if (extra_argc == 0) {
633                  if (using_switch_d) {                  if (using_switch_d) {
# Line 707  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 756  int get_cmd_args(int argc, char *argv[], Line 719  int get_cmd_args(int argc, char *argv[],
719  int main(int argc, char *argv[])  int main(int argc, char *argv[])
720  {  {
721          struct emul **emuls;          struct emul **emuls;
722            char **diskimages = NULL;
723            int n_diskimages = 0;
724          int n_emuls;          int n_emuls;
725          int i;          int i;
726    
# Line 781  int main(int argc, char *argv[]) Line 746  int main(int argc, char *argv[])
746                  exit(1);                  exit(1);
747          }          }
748    
749          get_cmd_args(argc, argv, emuls[0]);          get_cmd_args(argc, argv, emuls[0], &diskimages, &n_diskimages);
750    
751          if (!fully_deterministic) {          if (!fully_deterministic) {
752                  /*  TODO: More than just time(). Use gettimeofday().  */                  /*  TODO: More than just time(). Use gettimeofday().  */
# Line 799  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    
771          if (emuls[0]->machines[0]->machine_type == MACHINE_NONE)          if (emuls[0]->machines[0]->machine_type == MACHINE_NONE)
772                  n_emuls --;                  n_emuls --;
773            else {
774                    for (i=0; i<n_diskimages; i++)
775                            diskimage_add(emuls[0]->machines[0], diskimages[i]);
776            }
777    
778          /*  Simple initialization, from command line arguments:  */          /*  Simple initialization, from command line arguments:  */
779          if (n_emuls > 0) {          if (n_emuls > 0) {
# Line 838  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.2  
changed lines
  Added in v.22

  ViewVC Help
Powered by ViewVC 1.1.26