/[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 10 by dpavlin, Mon Oct 8 16:18:27 2007 UTC
# 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.238 2005/06/25 13:25:33 debug Exp $
29   */   */
30    
31  #include <stdio.h>  #include <stdio.h>
# Line 155  void fatal(char *fmt, ...) Line 155  void fatal(char *fmt, ...)
155    
156    
157  /*  /*
  *  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;  
 }  
   
   
 /*****************************************************************************/  
   
   
 /*  
158   *  internal_w():   *  internal_w():
159   *   *
160   *  For internal use by gxemul itself.   *  For internal use by gxemul itself.
# Line 288  static void usage(int longusage) Line 218  static void usage(int longusage)
218    
219          printf("\nOther options:\n");          printf("\nOther options:\n");
220  #ifdef BINTRANS  #ifdef BINTRANS
221          printf("  -B        disable dynamic binary translation completely\n");          printf("  -B        disable dynamic binary translation. (translation"
222          printf("  -b        use the OLD binary translation subsystem\n");              " is turned on\n            by default, if the host "
223                "supports it)\n");
224  #endif  #endif
225          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 "
226              "list of types.)\n");              "list of types.)\n");
227          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:\""
228              " as a prefix\n");              " as a prefix\n");
229          printf("            where xxx is one or more of the following:\n");          printf("            where xxx is one or more of the following:\n");
230          printf("                b     specifies that this is the boot"          printf("                b      specifies that this is the boot"
231              " device\n");              " device\n");
232          printf("                c     CD-ROM (instead of normal SCSI DISK)\n");          printf("                c      CD-ROM\n");
233          printf("                d     SCSI DISK (this is the default)\n");          printf("                d      DISK\n");
234          printf("                i     IDE (instead of SCSI)\n");          printf("                f      FLOPPY\n");
235          printf("                r     read-only (don't allow changes to the"          printf("                gH;S;  set geometry to H heads and S"
236                " sectors-per-track\n");
237            printf("                i      IDE\n");
238            printf("                r      read-only (don't allow changes to the"
239              " file)\n");              " file)\n");
240          printf("                t     SCSI tape\n");          printf("                s      SCSI\n");
241          printf("                0-7   force a specific SCSI ID number\n");          printf("                t      tape\n");
242            printf("                0-7    force a specific ID\n");
243          printf("  -I x      emulate clock interrupts at x Hz (affects"          printf("  -I x      emulate clock interrupts at x Hz (affects"
244              " rtc devices only, not\n");              " rtc devices only, not\n");
245          printf("            actual runtime speed) (this disables automatic"          printf("            actual runtime speed) (this disables automatic"
# Line 379  static void usage(int longusage) Line 314  static void usage(int longusage)
314              "on a binary.\n"              "on a binary.\n"
315              "To load a raw binary into memory, add \"address:\" in front "              "To load a raw binary into memory, add \"address:\" in front "
316              "of the filename,\n"              "of the filename,\n"
317              "or \"address:skiplen:\" or \"address:skiplen:initialpc\".\n"              "or \"address:skiplen:\" or \"address:skiplen:initialpc:\".\n"
318              "Examples:\n"              "Examples:\n"
319              "    0xbfc00000:rom.bin                  for a raw ROM image\n"              "    0xbfc00000:rom.bin                    for a raw ROM image\n"
320              "    0xbfc00000:0x100:rom.bin            for an image with "              "    0xbfc00000:0x100:rom.bin              for an image with "
321              "0x100 bytes header\n"              "0x100 bytes header\n"
322              "    0xbfc00000:0x100:0xbfc00884:rom.bin  "              "    0xbfc00000:0x100:0xbfc00884:rom.bin   "
323              "start with pc=0xbfc00884\n");              "start with pc=0xbfc00884\n");
324  }  }
325    
# Line 394  static void usage(int longusage) Line 329  static void usage(int longusage)
329   *   *
330   *  Reads command line arguments.   *  Reads command line arguments.
331   */   */
332  int get_cmd_args(int argc, char *argv[], struct emul *emul)  int get_cmd_args(int argc, char *argv[], struct emul *emul,
333            char ***diskimagesp, int *n_diskimagesp)
334  {  {
335          int ch, res, using_switch_d = 0, using_switch_Z = 0;          int ch, res, using_switch_d = 0, using_switch_Z = 0;
336          char *type = NULL, *subtype = NULL;          char *type = NULL, *subtype = NULL;
# Line 402  int get_cmd_args(int argc, char *argv[], Line 338  int get_cmd_args(int argc, char *argv[],
338          int msopts = 0;         /*  Machine-specific options used  */          int msopts = 0;         /*  Machine-specific options used  */
339          struct machine *m = emul_add_machine(emul, "default");          struct machine *m = emul_add_machine(emul, "default");
340    
341          while ((ch = getopt(argc, argv, "BbC:Dd:E:e:HhI:iJj:KM:m:"          while ((ch = getopt(argc, argv, "BC:Dd:E:e:HhI:iJj:KM:m:"
342              "Nn:Oo:p:QqRrSsTtUu:VvW:XxY:y:Z:z:")) != -1) {              "Nn:Oo:p:QqRrSsTtUu:VvW:XxY:y:Z:z:")) != -1) {
343                  switch (ch) {                  switch (ch) {
344                  case 'B':                  case 'B':
345                          m->bintrans_enable = 0;                          m->bintrans_enable = 0;
346                          msopts = 1;                          msopts = 1;
347                          break;                          break;
                 case 'b':  
                         m->old_bintrans_enable = 1;  
                         msopts = 1;  
                         break;  
348                  case 'C':                  case 'C':
349                          m->cpu_name = strdup(optarg);                          m->cpu_name = strdup(optarg);
350                          msopts = 1;                          msopts = 1;
# Line 421  int get_cmd_args(int argc, char *argv[], Line 353  int get_cmd_args(int argc, char *argv[],
353                          fully_deterministic = 1;                          fully_deterministic = 1;
354                          break;                          break;
355                  case 'd':                  case 'd':
356                          diskimage_add(m, optarg);                          /*  diskimage_add() is called further down  */
357                            (*n_diskimagesp) ++;
358                            (*diskimagesp) = realloc(*diskimagesp,
359                                sizeof(char *) * (*n_diskimagesp));
360                            if (*diskimagesp == NULL) {
361                                    fprintf(stderr, "out of memory\n");
362                                    exit(1);
363                            }
364                            (*diskimagesp)[(*n_diskimagesp) - 1] = strdup(optarg);
365                          using_switch_d = 1;                          using_switch_d = 1;
366                          msopts = 1;                          msopts = 1;
367                          break;                          break;
# Line 567  int get_cmd_args(int argc, char *argv[], Line 507  int get_cmd_args(int argc, char *argv[],
507                          break;                          break;
508                  case 'Y':                  case 'Y':
509                          m->x11_scaledown = atoi(optarg);                          m->x11_scaledown = atoi(optarg);
510                            if (m->x11_scaledown < 1) {
511                                    fprintf(stderr, "Invalid scaledown value.\n");
512                                    exit(1);
513                            }
514                          msopts = 1;                          msopts = 1;
515                          break;                          break;
516                  case 'y':                  case 'y':
# Line 597  int get_cmd_args(int argc, char *argv[], Line 541  int get_cmd_args(int argc, char *argv[],
541                          msopts = 1;                          msopts = 1;
542                          break;                          break;
543                  default:                  default:
544                          fprintf(stderr, "Invalid option.\n");                          fprintf(stderr, "Run  %s -h  for help on command "
545                          usage(0);                              "line options.\n", progname);
546                          exit(1);                          exit(1);
547                  }                  }
548          }          }
# Line 619  int get_cmd_args(int argc, char *argv[], Line 563  int get_cmd_args(int argc, char *argv[],
563          extra_argv = argv;          extra_argv = argv;
564    
565    
         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;  
         }  
   
566          if (m->machine_type == MACHINE_NONE && msopts) {          if (m->machine_type == MACHINE_NONE && msopts) {
567                  fprintf(stderr, "Machine specific options used directly on "                  fprintf(stderr, "Machine specific options used directly on "
568                      "the command line, but no machine\nemulation specified?\n");                      "the command line, but no machine\nemulation specified?\n");
# Line 640  int get_cmd_args(int argc, char *argv[], Line 573  int get_cmd_args(int argc, char *argv[],
573          /*  -i, -r, -t are pretty verbose:  */          /*  -i, -r, -t are pretty verbose:  */
574    
575          if (m->instruction_trace && !verbose) {          if (m->instruction_trace && !verbose) {
576                  fprintf(stderr, "Implicitly turning of -q and turning on -v, "                  fprintf(stderr, "Implicitly %sturning on -v, because"
577                      "because of -i\n");                      " of -i\n", quiet_mode? "turning off -q and " : "");
578                  verbose = 1;                  verbose = 1;
579                  quiet_mode = 0;                  quiet_mode = 0;
580          }          }
581    
582          if (m->register_dump && !verbose) {          if (m->register_dump && !verbose) {
583                  fprintf(stderr, "Implicitly turning of -q and turning on -v, "                  fprintf(stderr, "Implicitly %sturning on -v, because"
584                      "because of -r\n");                      " of -r\n", quiet_mode? "turning off -q and " : "");
585                  verbose = 1;                  verbose = 1;
586                  quiet_mode = 0;                  quiet_mode = 0;
587          }          }
588    
589          if (m->show_trace_tree && !verbose) {          if (m->show_trace_tree && !verbose) {
590                  fprintf(stderr, "Implicitly turning of -q and turning on -v, "                  fprintf(stderr, "Implicitly %sturning on -v, because"
591                      "because of -t\n");                      " of -t\n", quiet_mode? "turning off -q and " : "");
592                  verbose = 1;                  verbose = 1;
593                  quiet_mode = 0;                  quiet_mode = 0;
594          }          }
595    
596            if ((m->instruction_trace || m->register_dump || m->show_trace_tree)
597                && m->bintrans_enable) {
598                    fprintf(stderr, "Implicitly turning off bintrans.\n");
599                    m->bintrans_enable = 0;
600            }
601    
602    
603          /*          /*
604           *  Usually, an executable filename must be supplied.           *  Usually, an executable filename must be supplied.
605           *           *
606           *  However, it is possible to boot directly from a harddisk image           *  However, it is possible to boot directly from a harddisk image
607           *  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,
608           *  DECstation emulation, and there is a diskimage, then try to boot           *  then try to boot from disk.
          *  from that.  
609           */           */
610          if (extra_argc == 0) {          if (extra_argc == 0) {
611                  if (using_switch_d) {                  if (using_switch_d) {
# Line 756  int get_cmd_args(int argc, char *argv[], Line 694  int get_cmd_args(int argc, char *argv[],
694  int main(int argc, char *argv[])  int main(int argc, char *argv[])
695  {  {
696          struct emul **emuls;          struct emul **emuls;
697            char **diskimages = NULL;
698            int n_diskimages = 0;
699          int n_emuls;          int n_emuls;
700          int i;          int i;
701    
# Line 781  int main(int argc, char *argv[]) Line 721  int main(int argc, char *argv[])
721                  exit(1);                  exit(1);
722          }          }
723    
724          get_cmd_args(argc, argv, emuls[0]);          get_cmd_args(argc, argv, emuls[0], &diskimages, &n_diskimages);
725    
726          if (!fully_deterministic) {          if (!fully_deterministic) {
727                  /*  TODO: More than just time(). Use gettimeofday().  */                  /*  TODO: More than just time(). Use gettimeofday().  */
# Line 805  int main(int argc, char *argv[]) Line 745  int main(int argc, char *argv[])
745    
746          if (emuls[0]->machines[0]->machine_type == MACHINE_NONE)          if (emuls[0]->machines[0]->machine_type == MACHINE_NONE)
747                  n_emuls --;                  n_emuls --;
748            else {
749                    for (i=0; i<n_diskimages; i++)
750                            diskimage_add(emuls[0]->machines[0], diskimages[i]);
751            }
752    
753          /*  Simple initialization, from command line arguments:  */          /*  Simple initialization, from command line arguments:  */
754          if (n_emuls > 0) {          if (n_emuls > 0) {
# Line 848  int main(int argc, char *argv[]) Line 792  int main(int argc, char *argv[])
792          }          }
793    
794          if (n_emuls == 0) {          if (n_emuls == 0) {
795                  fprintf(stderr, "No emulations defined.\n");                  fprintf(stderr, "No emulations defined. Maybe you forgot to "
796                        "use -E xx (and -e yy), to specify\nthe machine type)."
797                        " For example:\n\n    %s -E dec -e 3max -d disk.img\n\n"
798                        "to boot an emulated DECstation 5000/200 with a disk "
799                        "image.\n", progname);
800                  exit(1);                  exit(1);
801          }          }
802    

Legend:
Removed from v.2  
changed lines
  Added in v.10

  ViewVC Help
Powered by ViewVC 1.1.26