/[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 32 by dpavlin, Mon Oct 8 16:20:58 2007 UTC revision 42 by dpavlin, Mon Oct 8 16:22:32 2007 UTC
# Line 1  Line 1 
1  /*  /*
2   *  Copyright (C) 2003-2006  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.284 2006/09/19 10:50:08 debug Exp $   *  $Id: main.c,v 1.305 2007/06/15 17:02:38 debug Exp $
29   */   */
30    
31  #include <stdio.h>  #include <stdio.h>
# Line 45  Line 45 
45  #include "misc.h"  #include "misc.h"
46  #include "settings.h"  #include "settings.h"
47  #include "timer.h"  #include "timer.h"
48    #include "useremul.h"
49    
50    
51  extern volatile int single_step;  extern int single_step;
52  extern int force_debugger_at_exit;  extern int force_debugger_at_exit;
53    
54  extern int optind;  extern int optind;
# Line 59  int extra_argc; Line 60  int extra_argc;
60  char **extra_argv;  char **extra_argv;
61  char *progname;  char *progname;
62    
63    size_t dyntrans_cache_size = DEFAULT_DYNTRANS_CACHE_SIZE;
64    int native_code_translation_enabled = 0;
65  int skip_srandom_call = 0;  int skip_srandom_call = 0;
66    
67    
# Line 198  static void usage(int longusage) Line 201  static void usage(int longusage)
201  #ifdef VERSION  #ifdef VERSION
202          printf(" " VERSION);          printf(" " VERSION);
203  #endif  #endif
204          printf("    Copyright (C) 2003-2006  Anders Gavare\n");          printf("    Copyright (C) 2003-2007  Anders Gavare\n");
205          printf("Read the source code and/or documentation for "          printf("Read the source code and/or documentation for "
206              "other Copyright messages.\n");              "other Copyright messages.\n");
207    
208          printf("\nusage: %s [machine, other, and general options] [file "          printf("\nusage: %s [machine, other, and general options] [file "
209              "[...]]\n", progname);              "[...]]\n", progname);
210          printf("   or  %s [general options] @configfile\n", progname);          printf("   or  %s [general options] @configfile\n", progname);
 #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);
 #endif  
213    
214          if (!longusage) {          if (!longusage) {
215                  printf("\nRun  %s -h  for help on command line options.\n",                  printf("\nRun  %s -h  for help on command line options.\n",
# Line 236  static void usage(int longusage) Line 237  static void usage(int longusage)
237          printf("                gH;S;  set geometry to H heads and S"          printf("                gH;S;  set geometry to H heads and S"
238              " sectors-per-track\n");              " sectors-per-track\n");
239          printf("                i      IDE\n");          printf("                i      IDE\n");
240            printf("                oOFS;  set base offset to OFS (for ISO9660"
241                " filesystems)\n");
242          printf("                r      read-only (don't allow changes to the"          printf("                r      read-only (don't allow changes to the"
243              " file)\n");              " file)\n");
244          printf("                s      SCSI\n");          printf("                s      SCSI\n");
245          printf("                t      tape\n");          printf("                t      tape\n");
246            printf("                V      add an overlay\n");
247          printf("                0-7    force a specific ID\n");          printf("                0-7    force a specific ID\n");
         printf("  -G port   listen to gdb remote connections on this port\n");  
248          printf("  -I hz     set the main cpu frequency to hz (not used by "          printf("  -I hz     set the main cpu frequency to hz (not used by "
249              "all combinations\n            of machines and guest OSes)");              "all combinations\n            of machines and guest OSes)\n");
250          printf("  -i        display each instruction as it is executed\n");          printf("  -i        display each instruction as it is executed\n");
251          printf("  -J        disable dyntrans instruction combinations\n");          printf("  -J        disable dyntrans instruction combinations\n");
252          printf("  -j name   set the name of the kernel; for DECstation "          printf("  -j name   set the name of the kernel; for DECstation "
# Line 284  static void usage(int longusage) Line 287  static void usage(int longusage)
287          printf("                d    disable statistics gathering at "          printf("                d    disable statistics gathering at "
288              "startup\n");              "startup\n");
289          printf("                o    overwrite instead of append\n");          printf("                o    overwrite instead of append\n");
290            printf("  -T        halt on non-existant memory accesses\n");
291          printf("  -t        show function trace tree\n");          printf("  -t        show function trace tree\n");
292          printf("  -U        enable slow_serial_interrupts_hack_for_linux\n");          printf("  -U        enable slow_serial_interrupts_hack_for_linux\n");
293  #ifdef WITH_X11  #ifdef WITH_X11
# Line 299  static void usage(int longusage) Line 303  static void usage(int longusage)
303          printf("  -z disp   add disp as an X11 display to use for "          printf("  -z disp   add disp as an X11 display to use for "
304              "framebuffers\n");              "framebuffers\n");
305    
 #ifdef UNSTABLE_DEVEL  
306          printf("\nUserland options:\n");          printf("\nUserland options:\n");
307          printf("  -u emul   userland-only (syscall) emulation (use -H to"          printf("  -u emul   userland-only (syscall) emulation (use -H to"
308              " get a list of\n            available emulation modes)\n");              " get a list of\n            available emulation modes)\n");
 #endif  
309    
310          printf("\nGeneral options:\n");          printf("\nGeneral options:\n");
311            printf("  -b        enable native code generation, if available\n");
312            printf("  -B        disable native code generation (this is "
313                "the default)\n");
314          printf("  -c cmd    add cmd as a command to run before starting "          printf("  -c cmd    add cmd as a command to run before starting "
315              "the simulation\n");              "the simulation\n");
316          printf("  -D        skip the srandom call at startup\n");          printf("  -D        skip the srandom call at startup\n");
317          printf("  -H        display a list of possible CPU and "          printf("  -H        display a list of possible CPU and "
318              "machine types\n");              "machine types\n");
319          printf("  -h        display this help message\n");          printf("  -h        display this help message\n");
320            printf("  -k n      set dyntrans translation caches to n MB (default"
321                " size is %i MB)\n", DEFAULT_DYNTRANS_CACHE_SIZE / 1048576);
322          printf("  -K        force the debugger to be entered at the end "          printf("  -K        force the debugger to be entered at the end "
323              "of a simulation\n");              "of a simulation\n");
324          printf("  -q        quiet mode (don't print startup messages)\n");          printf("  -q        quiet mode (don't print startup messages)\n");
# Line 327  static void usage(int longusage) Line 334  static void usage(int longusage)
334              "To load a raw binary into memory, add \"address:\" in front "              "To load a raw binary into memory, add \"address:\" in front "
335              "of the filename,\n"              "of the filename,\n"
336              "or \"address:skiplen:\" or \"address:skiplen:initialpc:\".\n"              "or \"address:skiplen:\" or \"address:skiplen:initialpc:\".\n"
337              "Examples:\n"              "\nExamples:\n"
338              "    0xbfc00000:rom.bin                    for a raw ROM image\n"              "    0xbfc00000:rom.bin                    for a raw ROM image\n"
339              "    0xbfc00000:0x100:rom.bin              for an image with "              "    0xbfc00000:0x100:rom.bin              for an image with "
340              "0x100 bytes header\n"              "0x100 bytes header\n"
341              "    0xbfc00000:0x100:0xbfc00884:rom.bin   "              "    0xbfc00000:0x100:0xbfc00884:rom.bin   "
342              "start with pc=0xbfc00884\n");              "start with pc=0xbfc00884\n\n");
343  }  }
344    
345    
# Line 352  int get_cmd_args(int argc, char *argv[], Line 359  int get_cmd_args(int argc, char *argv[],
359          struct machine *m = emul_add_machine(emul, "default");          struct machine *m = emul_add_machine(emul, "default");
360    
361          char *opts =          char *opts =
362              "C:c:Dd:E:e:G:HhI:iJj:KM:Nn:Oo:p:QqRrSs:tU"              "bBC:c:Dd:E:e:HhI:iJj:k:KM:Nn:Oo:p:QqRrSs:TtUu:VvW:"
 #ifdef UNSTABLE_DEVEL  
             "u:"  
 #endif  
             "VvW:"  
363  #ifdef WITH_X11  #ifdef WITH_X11
364              "XxY:"              "XxY:"
365  #endif  #endif
# Line 364  int get_cmd_args(int argc, char *argv[], Line 367  int get_cmd_args(int argc, char *argv[],
367    
368          while ((ch = getopt(argc, argv, opts)) != -1) {          while ((ch = getopt(argc, argv, opts)) != -1) {
369                  switch (ch) {                  switch (ch) {
370                    case 'b':
371                            native_code_translation_enabled = 1;
372                            break;
373                    case 'B':
374                            native_code_translation_enabled = 0;
375                            break;
376                  case 'C':                  case 'C':
377                          m->cpu_name = strdup(optarg);                          CHECK_ALLOCATION(m->cpu_name = strdup(optarg));
378                          msopts = 1;                          msopts = 1;
379                          break;                          break;
380                  case 'c':                  case 'c':
381                          emul->n_debugger_cmds ++;                          emul->n_debugger_cmds ++;
382                          emul->debugger_cmds = realloc(emul->debugger_cmds,                          CHECK_ALLOCATION(emul->debugger_cmds =
383                              emul->n_debugger_cmds * sizeof(char *));                              realloc(emul->debugger_cmds,
384                          if (emul->debugger_cmds == NULL) {                              emul->n_debugger_cmds * sizeof(char *)));
385                                  fatal("out of memory\n");                          CHECK_ALLOCATION(emul->debugger_cmds[emul->
386                                  exit(1);                              n_debugger_cmds-1] = strdup(optarg));
                         }  
                         emul->debugger_cmds[emul->n_debugger_cmds-1] =  
                             strdup(optarg);  
387                          break;                          break;
388                  case 'D':                  case 'D':
389                          skip_srandom_call = 1;                          skip_srandom_call = 1;
# Line 385  int get_cmd_args(int argc, char *argv[], Line 391  int get_cmd_args(int argc, char *argv[],
391                  case 'd':                  case 'd':
392                          /*  diskimage_add() is called further down  */                          /*  diskimage_add() is called further down  */
393                          (*n_diskimagesp) ++;                          (*n_diskimagesp) ++;
394                          (*diskimagesp) = realloc(*diskimagesp,                          CHECK_ALLOCATION( (*diskimagesp) =
395                              sizeof(char *) * (*n_diskimagesp));                              realloc(*diskimagesp,
396                          if (*diskimagesp == NULL) {                              sizeof(char *) * (*n_diskimagesp)) );
397                                  fprintf(stderr, "out of memory\n");                          CHECK_ALLOCATION( (*diskimagesp)[(*n_diskimagesp) - 1] =
398                                  exit(1);                              strdup(optarg) );
                         }  
                         (*diskimagesp)[(*n_diskimagesp) - 1] = strdup(optarg);  
399                          using_switch_d = 1;                          using_switch_d = 1;
400                          msopts = 1;                          msopts = 1;
401                          break;                          break;
# Line 411  int get_cmd_args(int argc, char *argv[], Line 415  int get_cmd_args(int argc, char *argv[],
415                          subtype = optarg;                          subtype = optarg;
416                          msopts = 1;                          msopts = 1;
417                          break;                          break;
                 case 'G':  
                         m->gdb.port = atoi(optarg);  
                         if (m->gdb.port < 1 || m->gdb.port > 65535) {  
                                 fprintf(stderr, "Invalid debugger port %i.\n",  
                                     m->gdb.port);  
                                 exit(1);  
                         }  
                         /*  Note: implicit -V  */  
                         single_step = ENTER_SINGLE_STEPPING;  
                         msopts = 1;  
                         break;  
418                  case 'H':                  case 'H':
419                          machine_list_available_types_and_cpus();                          machine_list_available_types_and_cpus();
420                          exit(1);                          exit(1);
# Line 441  int get_cmd_args(int argc, char *argv[], Line 434  int get_cmd_args(int argc, char *argv[],
434                          msopts = 1;                          msopts = 1;
435                          break;                          break;
436                  case 'j':                  case 'j':
437                          m->boot_kernel_filename = strdup(optarg);                          CHECK_ALLOCATION(m->boot_kernel_filename =
438                          if (m->boot_kernel_filename == NULL) {                              strdup(optarg));
439                                  fprintf(stderr, "out of memory\n");                          msopts = 1;
440                            break;
441                    case 'k':
442                            dyntrans_cache_size = atoi(optarg) * 1048576;
443                            if (dyntrans_cache_size < 1) {
444                                    fprintf(stderr, "The dyntrans cache size must"
445                                        " be at least 1 MB.\n");
446                                  exit(1);                                  exit(1);
447                          }                          }
                         msopts = 1;  
448                          break;                          break;
449                  case 'K':                  case 'K':
450                          force_debugger_at_exit = 1;                          force_debugger_at_exit = 1;
# Line 469  int get_cmd_args(int argc, char *argv[], Line 467  int get_cmd_args(int argc, char *argv[],
467                          msopts = 1;                          msopts = 1;
468                          break;                          break;
469                  case 'o':                  case 'o':
470                          m->boot_string_argument = strdup(optarg);                          CHECK_ALLOCATION(m->boot_string_argument =
471                          if (m->boot_string_argument == NULL) {                              strdup(optarg));
                                 fprintf(stderr, "out of memory\n");  
                                 exit(1);  
                         }  
472                          msopts = 1;                          msopts = 1;
473                          break;                          break;
474                  case 'p':                  case 'p':
475                          if (m->n_breakpoints >= MAX_BREAKPOINTS) {                          machine_add_breakpoint_string(m, optarg);
                                 fprintf(stderr, "too many breakpoints\n");  
                                 exit(1);  
                         }  
                         m->breakpoint_string[m->n_breakpoints] = strdup(optarg);  
                         if (m->breakpoint_string[m->n_breakpoints] == NULL) {  
                                 fprintf(stderr, "out of memory\n");  
                                 exit(1);  
                         }  
                         m->breakpoint_flags[m->n_breakpoints] = 0;  
                         m->n_breakpoints ++;  
476                          msopts = 1;                          msopts = 1;
477                          break;                          break;
478                  case 'Q':                  case 'Q':
# Line 511  int get_cmd_args(int argc, char *argv[], Line 496  int get_cmd_args(int argc, char *argv[],
496                          break;                          break;
497                  case 's':                  case 's':
498                          machine_statistics_init(m, optarg);                          machine_statistics_init(m, optarg);
499                            native_code_translation_enabled = 0;
500                            msopts = 1;
501                            break;
502                    case 'T':
503                            m->halt_on_nonexistant_memaccess = 1;
504                          msopts = 1;                          msopts = 1;
505                          break;                          break;
506                  case 't':                  case 't':
# Line 522  int get_cmd_args(int argc, char *argv[], Line 512  int get_cmd_args(int argc, char *argv[],
512                          msopts = 1;                          msopts = 1;
513                          break;                          break;
514                  case 'u':                  case 'u':
515                          m->userland_emul = strdup(optarg);                          CHECK_ALLOCATION(m->userland_emul = strdup(optarg));
                         if (m->userland_emul == NULL) {  
                                 fprintf(stderr, "out of memory\n");  
                                 exit(1);  
                         }  
516                          m->machine_type = MACHINE_USERLAND;                          m->machine_type = MACHINE_USERLAND;
517                          msopts = 1;                          msopts = 1;
518                          break;                          break;
# Line 540  int get_cmd_args(int argc, char *argv[], Line 526  int get_cmd_args(int argc, char *argv[],
526                          internal_w(optarg);                          internal_w(optarg);
527                          exit(0);                          exit(0);
528                  case 'X':                  case 'X':
529                          m->use_x11 = 1;                          m->x11_md.in_use = 1;
530                          msopts = 1;                          msopts = 1;
531                          /*  FALL-THROUGH  */                          /*  FALL-THROUGH  */
532                  case 'x':                  case 'x':
533                          console_allow_slaves(1);                          console_allow_slaves(1);
534                          break;                          break;
535                  case 'Y':                  case 'Y':
536                          m->x11_scaledown = atoi(optarg);                          m->x11_md.scaledown = atoi(optarg);
537                          if (m->x11_scaledown < -1) {                          if (m->x11_md.scaledown < -1) {
538                                  m->x11_scaleup = - m->x11_scaledown;                                  m->x11_md.scaleup = - m->x11_md.scaledown;
539                                  m->x11_scaledown = 1;                                  m->x11_md.scaledown = 1;
540                          }                          }
541                          if (m->x11_scaledown < 1) {                          if (m->x11_md.scaledown < 1) {
542                                  fprintf(stderr, "Invalid scaledown value.\n");                                  fprintf(stderr, "Invalid scaledown value.\n");
543                                  exit(1);                                  exit(1);
544                          }                          }
# Line 564  int get_cmd_args(int argc, char *argv[], Line 550  int get_cmd_args(int argc, char *argv[],
550                          msopts = 1;                          msopts = 1;
551                          break;                          break;
552                  case 'z':                  case 'z':
553                          m->x11_n_display_names ++;                          m->x11_md.n_display_names ++;
554                          m->x11_display_names = realloc(                          CHECK_ALLOCATION(m->x11_md.display_names = realloc(
555                              m->x11_display_names,                              m->x11_md.display_names,
556                              m->x11_n_display_names * sizeof(char *));                              m->x11_md.n_display_names * sizeof(char *)));
557                          if (m->x11_display_names == NULL) {                          CHECK_ALLOCATION(m->x11_md.display_names[
558                                  fprintf(stderr, "out of memory\n");                              m->x11_md.n_display_names-1] = strdup(optarg));
                                 exit(1);  
                         }  
                         m->x11_display_names[m->x11_n_display_names-1] =  
                             strdup(optarg);  
                         if (m->x11_display_names  
                             [m->x11_n_display_names-1] == NULL) {  
                                 fprintf(stderr, "out of memory\n");  
                                 exit(1);  
                         }  
559                          msopts = 1;                          msopts = 1;
560                          break;                          break;
561                  default:                  default:
# Line 663  int get_cmd_args(int argc, char *argv[], Line 640  int get_cmd_args(int argc, char *argv[],
640                  else                  else
641                          s2 ++;                          s2 ++;
642    
643                  m->boot_kernel_filename = strdup(s2);                  CHECK_ALLOCATION(m->boot_kernel_filename = strdup(s2));
                 if (m->boot_kernel_filename == NULL) {  
                         fprintf(stderr, "out of memory\n");  
                         exit(1);  
                 }  
644          }          }
645    
646          if (m->n_gfx_cards < 0 || m->n_gfx_cards > 3) {          if (m->n_gfx_cards < 0 || m->n_gfx_cards > 3) {
# Line 675  int get_cmd_args(int argc, char *argv[], Line 648  int get_cmd_args(int argc, char *argv[],
648                  exit(1);                  exit(1);
649          }          }
650    
651          if (!using_switch_Z && !m->use_x11)          if (!using_switch_Z && !m->x11_md.in_use)
652                  m->n_gfx_cards = 0;                  m->n_gfx_cards = 0;
653    
654          return 0;          return 0;
# Line 706  int main(int argc, char *argv[]) Line 679  int main(int argc, char *argv[])
679          int n_emuls;          int n_emuls;
680          int i;          int i;
681    
   
682          progname = argv[0];          progname = argv[0];
683    
684    
# Line 727  int main(int argc, char *argv[]) Line 699  int main(int argc, char *argv[])
699          settings_add(global_settings, "false", 0, SETTINGS_TYPE_INT,          settings_add(global_settings, "false", 0, SETTINGS_TYPE_INT,
700              SETTINGS_FORMAT_BOOL, (void *)&constant_false);              SETTINGS_FORMAT_BOOL, (void *)&constant_false);
701    
702            /*  Read-only settings:  */
703            settings_add(global_settings, "native_code_translation_enabled", 0,
704                SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO,
705                (void *)&native_code_translation_enabled);
706          settings_add(global_settings, "single_step", 0,          settings_add(global_settings, "single_step", 0,
707              SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, (void *)&single_step);              SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, (void *)&single_step);
708    
709            /*  Read/write settings:  */
710          settings_add(global_settings, "force_debugger_at_exit", 1,          settings_add(global_settings, "force_debugger_at_exit", 1,
711              SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO,              SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO,
712              (void *)&force_debugger_at_exit);              (void *)&force_debugger_at_exit);
# Line 746  int main(int argc, char *argv[]) Line 724  int main(int argc, char *argv[])
724          useremul_init();          useremul_init();
725    
726          emuls = malloc(sizeof(struct emul *));          emuls = malloc(sizeof(struct emul *));
727          if (emuls == NULL) {          CHECK_ALLOCATION(emuls);
                 fprintf(stderr, "out of memory\n");  
                 exit(1);  
         }  
728    
729          /*  Allocate space for a simple emul setup:  */          /*  Allocate space for a simple emul setup:  */
730          n_emuls = 1;          n_emuls = 1;
731          emuls[0] = emul_new(NULL);          emuls[0] = emul_new(NULL, 0);
         if (emuls[0] == NULL) {  
                 fprintf(stderr, "out of memory\n");  
                 exit(1);  
         }  
732          settings_add(global_settings, "emul[0]", 1,          settings_add(global_settings, "emul[0]", 1,
733              SETTINGS_TYPE_SUBSETTINGS, 0, emuls[0]->settings);              SETTINGS_TYPE_SUBSETTINGS, 0, emuls[0]->settings);
734    
# Line 774  int main(int argc, char *argv[]) Line 745  int main(int argc, char *argv[])
745  #ifdef VERSION  #ifdef VERSION
746          debug(" " VERSION);          debug(" " VERSION);
747  #endif  #endif
748          debug("    Copyright (C) 2003-2006  Anders Gavare\n");          debug("    Copyright (C) 2003-2007  Anders Gavare\n");
749          debug("Read the source code and/or documentation for "          debug("Read the source code and/or documentation for "
750              "other Copyright messages.\n\n");              "other Copyright messages.\n\n");
751    
# Line 813  int main(int argc, char *argv[]) Line 784  int main(int argc, char *argv[])
784                                  s = argv[i];                                  s = argv[i];
785                          }                          }
786                          n_emuls ++;                          n_emuls ++;
787                          emuls = realloc(emuls, sizeof(struct emul *) * n_emuls);                          CHECK_ALLOCATION(emuls = realloc(emuls,
788                          if (emuls == NULL) {                              sizeof(struct emul *) * n_emuls));
                                 fprintf(stderr, "out of memory\n");  
                                 exit(1);  
                         }  
789    
790                          /*  Always allow slave xterms when using multiple                          /*  Always allow slave xterms when using multiple
791                              emulations:  */                              emulations:  */
# Line 831  int main(int argc, char *argv[]) Line 799  int main(int argc, char *argv[])
799                          }                          }
800    
801                          emuls[n_emuls - 1] =                          emuls[n_emuls - 1] =
802                              emul_create_from_configfile(s);                              emul_create_from_configfile(s, n_emuls - 1);
803    
804                          snprintf(tmpstr, sizeof(tmpstr), "emul[%i]", n_emuls-1);                          snprintf(tmpstr, sizeof(tmpstr), "emul[%i]", n_emuls-1);
805                          settings_add(global_settings, tmpstr, 1,                          settings_add(global_settings, tmpstr, 1,

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

  ViewVC Help
Powered by ViewVC 1.1.26