/[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 14 by dpavlin, Mon Oct 8 16:18:51 2007 UTC revision 42 by dpavlin, Mon Oct 8 16:22:32 2007 UTC
# Line 1  Line 1 
1  /*  /*
2   *  Copyright (C) 2003-2005  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.244 2005/09/07 07:41:29 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 37  Line 37 
37    
38  #include "console.h"  #include "console.h"
39  #include "cpu.h"  #include "cpu.h"
40    #include "debugger.h"
41  #include "device.h"  #include "device.h"
42  #include "diskimage.h"  #include "diskimage.h"
43  #include "emul.h"  #include "emul.h"
44  #include "machine.h"  #include "machine.h"
45  #include "misc.h"  #include "misc.h"
46    #include "settings.h"
47    #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;
 extern int show_opcode_statistics;  
53    
54  extern int optind;  extern int optind;
55  extern char *optarg;  extern char *optarg;
56    
57    struct settings *global_settings;
58    
59  int extra_argc;  int extra_argc;
60  char **extra_argv;  char **extra_argv;
61  char *progname;  char *progname;
62    
63  int fully_deterministic = 0;  size_t dyntrans_cache_size = DEFAULT_DYNTRANS_CACHE_SIZE;
64    int native_code_translation_enabled = 0;
65    int skip_srandom_call = 0;
66    
67    
68  /*****************************************************************************  /*****************************************************************************
# Line 192  static void usage(int longusage) Line 199  static void usage(int longusage)
199  {  {
200          printf("GXemul");          printf("GXemul");
201  #ifdef VERSION  #ifdef VERSION
202          printf("-" VERSION);          printf(" " VERSION);
203  #endif  #endif
204          printf("   Copyright (C) 2003-2005  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    
# Line 217  static void usage(int longusage) Line 224  static void usage(int longusage)
224              "with -E.)\n");              "with -E.)\n");
225    
226          printf("\nOther options:\n");          printf("\nOther options:\n");
         printf("  -A        disable alignment checks in some cases (for higher"  
             " speed)\n");  
 #ifdef BINTRANS  
         printf("  -B        disable dynamic binary translation. (translation"  
             " is turned on\n            by default, if the host "  
             "supports it)\n");  
 #endif  
227          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 "
228              "list of types.)\n");              "list of types.)\n");
229          printf("  -d fname  add fname as a disk image. You can add \"xxx:\""          printf("  -d fname  add fname as a disk image. You can add \"xxx:\""
# Line 237  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");
248          printf("  -I x      emulate clock interrupts at x Hz (affects"          printf("  -I hz     set the main cpu frequency to hz (not used by "
249              " rtc devices only, not\n");              "all combinations\n            of machines and guest OSes)\n");
         printf("            actual runtime speed) (this disables automatic"  
             " clock adjustments)\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 some speed tricks\n");          printf("  -J        disable dyntrans instruction combinations\n");
252          printf("  -j name   set the name of the kernel, for example:\n");          printf("  -j name   set the name of the kernel; for DECstation "
253          printf("                -j netbsd          for NetBSD/pmax\n");              "emulation, this passes\n            the name to the bootloader,"
254          printf("                -j bsd             for OpenBSD/pmax\n");              " for example:\n");
255          printf("                -j vmunix          for Ultrix/RISC\n");          printf("                -j netbsd     (NetBSD/pmax)      "
256                "-j bsd      (OpenBSD/pmax)\n");
257            printf("                -j vmsprite   (Sprite/pmax)      "
258                "-j vmunix   (Ultrix/RISC)\n");
259            printf("            For other emulation modes, if the boot disk is an"
260                " ISO9660\n            filesystem, -j sets the name of the"
261                " kernel to load.\n");
262          printf("  -M m      emulate m MBs of physical RAM\n");          printf("  -M m      emulate m MBs of physical RAM\n");
         printf("  -m nr     run at most nr instructions (on any cpu)\n");  
263          printf("  -N        display nr of instructions/second average, at"          printf("  -N        display nr of instructions/second average, at"
264              " regular intervals\n");              " regular intervals\n");
265          printf("  -n nr     set nr of CPUs (for SMP experiments)\n");          printf("  -n nr     set nr of CPUs (for SMP experiments)\n");
266          printf("  -O        force netboot (tftp instead of disk), even when"          printf("  -O        force netboot (tftp instead of disk), even when"
267              " a disk image is\n"              " a disk image is\n"
268              "            present (for DECstation, SGI, and ARC emulation)\n");              "            present (for DECstation, SGI, and ARC emulation)\n");
269          printf("  -o arg    set the boot argument (for DEC, ARC, or SGI"          printf("  -o arg    set the boot argument, for DEC, ARC, or SGI"
270              " emulation).\n");              " emulation\n");
271          printf("            Default arg for DEC is '-a', for ARC '-aN'.\n");          printf("            (default arg for DEC is -a, for ARC/SGI -aN)\n");
272          printf("  -p pc     add a breakpoint (remember to use the '0x' "          printf("  -p pc     add a breakpoint (remember to use the '0x' "
273              "prefix for hex!)\n");              "prefix for hex!)\n");
274          printf("  -Q        no built-in PROM emulation  (use this for "          printf("  -Q        no built-in PROM emulation  (use this for "
# Line 271  static void usage(int longusage) Line 277  static void usage(int longusage)
277          printf("  -r        register dumps before every instruction\n");          printf("  -r        register dumps before every instruction\n");
278          printf("  -S        initialize emulated RAM to random bytes, "          printf("  -S        initialize emulated RAM to random bytes, "
279              "instead of zeroes\n");              "instead of zeroes\n");
280          printf("  -T        enter the single-step debugger on "          printf("  -s f:name write statistics to file 'name', "
281              "unimplemented memory accesses\n");              "f is one or more of the following:\n");
282            printf("                v    virtual program counter\n");
283            printf("                p    physical equivalent of program counter\n");
284            printf("                i    internal ic->f representation of "
285                "the program counter\n");
286            printf("            and optionally:\n");
287            printf("                d    disable statistics gathering at "
288                "startup\n");
289            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
294          printf("  -X        use X11\n");          printf("  -X        use X11\n");
 #endif /*  WITH_X11  */  
295          printf("  -x        open up new xterms for emulated serial ports "          printf("  -x        open up new xterms for emulated serial ports "
296              "(default is on when\n            using configuration files, off"              "(default is on when\n            using configuration files or"
297              " otherwise)\n");              " when X11 is used, off otherwise)\n");
 #ifdef WITH_X11  
298          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");
299  #endif /*  WITH_X11  */  #endif /*  WITH_X11  */
         printf("  -y x      set max_random_cycles_per_chunk to x"  
             " (experimental)\n");  
300          printf("  -Z n      set nr of graphics cards, for emulating a "          printf("  -Z n      set nr of graphics cards, for emulating a "
301              "dual-head or tripple-head\n"              "dual-head or tripple-head\n"
302              "            environment (only for DECstation emulation)\n");              "            environment (only for DECstation emulation)\n");
# Line 297  static void usage(int longusage) Line 308  static void usage(int longusage)
308              " get a list of\n            available emulation modes)\n");              " get a list of\n            available emulation modes)\n");
309    
310          printf("\nGeneral options:\n");          printf("\nGeneral options:\n");
311          printf("  -D        guarantee fully deterministic behaviour\n");          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 "
315                "the simulation\n");
316            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");
         printf("  -s        show opcode usage statistics after simulation\n");  
325          printf("  -V        start up in the single-step debugger, paused\n");          printf("  -V        start up in the single-step debugger, paused\n");
326          printf("  -v        verbose debug messages\n");          printf("  -v        verbose debug messages\n");
327          printf("\n");          printf("\n");
# Line 317  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 335  int get_cmd_args(int argc, char *argv[], Line 352  int get_cmd_args(int argc, char *argv[],
352          char ***diskimagesp, int *n_diskimagesp)          char ***diskimagesp, int *n_diskimagesp)
353  {  {
354          int ch, res, using_switch_d = 0, using_switch_Z = 0;          int ch, res, using_switch_d = 0, using_switch_Z = 0;
355            int using_switch_e = 0, using_switch_E = 0;
356          char *type = NULL, *subtype = NULL;          char *type = NULL, *subtype = NULL;
357          int n_cpus_set = 0;          int n_cpus_set = 0;
358          int msopts = 0;         /*  Machine-specific options used  */          int msopts = 0;         /*  Machine-specific options used  */
359          struct machine *m = emul_add_machine(emul, "default");          struct machine *m = emul_add_machine(emul, "default");
360    
361          while ((ch = getopt(argc, argv, "ABC:Dd:E:e:HhI:iJj:KM:m:"          char *opts =
362              "Nn:Oo:p:QqRrSsTtUu:VvW:XxY:y:Z:z:")) != -1) {              "bBC:c:Dd:E:e:HhI:iJj:k:KM:Nn:Oo:p:QqRrSs:TtUu:VvW:"
363    #ifdef WITH_X11
364                "XxY:"
365    #endif
366                "Z:z:";
367    
368            while ((ch = getopt(argc, argv, opts)) != -1) {
369                  switch (ch) {                  switch (ch) {
370                  case 'A':                  case 'b':
371                          m->dyntrans_alignment_check = 0;                          native_code_translation_enabled = 1;
                         msopts = 1;  
372                          break;                          break;
373                  case 'B':                  case 'B':
374                          m->bintrans_enable = 0;                          native_code_translation_enabled = 0;
                         msopts = 1;  
375                          break;                          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':
381                            emul->n_debugger_cmds ++;
382                            CHECK_ALLOCATION(emul->debugger_cmds =
383                                realloc(emul->debugger_cmds,
384                                emul->n_debugger_cmds * sizeof(char *)));
385                            CHECK_ALLOCATION(emul->debugger_cmds[emul->
386                                n_debugger_cmds-1] = strdup(optarg));
387                            break;
388                  case 'D':                  case 'D':
389                          fully_deterministic = 1;                          skip_srandom_call = 1;
390                          break;                          break;
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;
402                  case 'E':                  case 'E':
403                            if (using_switch_E ++ > 0) {
404                                    fprintf(stderr, "-E already used.\n");
405                                    exit(1);
406                            }
407                          type = optarg;                          type = optarg;
408                          msopts = 1;                          msopts = 1;
409                          break;                          break;
410                  case 'e':                  case 'e':
411                            if (using_switch_e ++ > 0) {
412                                    fprintf(stderr, "-e already used.\n");
413                                    exit(1);
414                            }
415                          subtype = optarg;                          subtype = optarg;
416                          msopts = 1;                          msopts = 1;
417                          break;                          break;
# Line 387  int get_cmd_args(int argc, char *argv[], Line 423  int get_cmd_args(int argc, char *argv[],
423                          exit(1);                          exit(1);
424                  case 'I':                  case 'I':
425                          m->emulated_hz = atoi(optarg);                          m->emulated_hz = atoi(optarg);
                         m->automatic_clock_adjustment = 0;  
426                          msopts = 1;                          msopts = 1;
427                          break;                          break;
428                  case 'i':                  case 'i':
# Line 395  int get_cmd_args(int argc, char *argv[], Line 430  int get_cmd_args(int argc, char *argv[],
430                          msopts = 1;                          msopts = 1;
431                          break;                          break;
432                  case 'J':                  case 'J':
433                          m->speed_tricks = 0;                          m->allow_instruction_combinations = 0;
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 413  int get_cmd_args(int argc, char *argv[], Line 453  int get_cmd_args(int argc, char *argv[],
453                          m->physical_ram_in_mb = atoi(optarg);                          m->physical_ram_in_mb = atoi(optarg);
454                          msopts = 1;                          msopts = 1;
455                          break;                          break;
                 case 'm':  
                         m->max_instructions = atoi(optarg);  
                         msopts = 1;  
                         break;  
456                  case 'N':                  case 'N':
457                          m->show_nr_of_instructions = 1;                          m->show_nr_of_instructions = 1;
458                          msopts = 1;                          msopts = 1;
# Line 431  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 472  int get_cmd_args(int argc, char *argv[], Line 495  int get_cmd_args(int argc, char *argv[],
495                          msopts = 1;                          msopts = 1;
496                          break;                          break;
497                  case 's':                  case 's':
498                          show_opcode_statistics = 1;                          machine_statistics_init(m, optarg);
499                            native_code_translation_enabled = 0;
500                            msopts = 1;
501                          break;                          break;
502                  case 'T':                  case 'T':
503                          m->single_step_on_bad_addr = 1;                          m->halt_on_nonexistant_memaccess = 1;
504                          msopts = 1;                          msopts = 1;
505                          break;                          break;
506                  case 't':                  case 't':
# Line 487  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;
519                  case 'V':                  case 'V':
520                          single_step = 1;                          single_step = ENTER_SINGLE_STEPPING;
521                          break;                          break;
522                  case 'v':                  case 'v':
523                          verbose ++;                          verbose ++;
# Line 505  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                          break;                          /*  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_md.scaleup = - m->x11_md.scaledown;
539                                    m->x11_md.scaledown = 1;
540                            }
541                            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                          }                          }
545                          msopts = 1;                          msopts = 1;
546                          break;                          break;
                 case 'y':  
                         m->max_random_cycles_per_chunk = atoi(optarg);  
                         msopts = 1;  
                         break;  
547                  case 'Z':                  case 'Z':
548                          m->n_gfx_cards = atoi(optarg);                          m->n_gfx_cards = atoi(optarg);
549                          using_switch_Z = 1;                          using_switch_Z = 1;
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 594  int get_cmd_args(int argc, char *argv[], Line 606  int get_cmd_args(int argc, char *argv[],
606                  quiet_mode = 0;                  quiet_mode = 0;
607          }          }
608    
         if ((m->instruction_trace || m->register_dump || m->show_trace_tree)  
             && m->bintrans_enable) {  
                 fprintf(stderr, "Implicitly turning off bintrans.\n");  
                 m->bintrans_enable = 0;  
         }  
   
609    
610          /*          /*
611           *  Usually, an executable filename must be supplied.           *  Usually, an executable filename must be supplied.
# Line 634  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 646  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 (m->bintrans_enable) {          if (!using_switch_Z && !m->x11_md.in_use)
                 m->speed_tricks = 0;  
                 /*  TODO: Print a warning about this?  */  
         }  
   
         if (m->n_breakpoints > 0 &&  
             m->bintrans_enable && m->arch == ARCH_MIPS) {  
                 fprintf(stderr, "Breakpoints and MIPS binary translation "  
                     "don't work too well together right now.\n");  
                 exit(1);  
         }  
   
 #ifndef BINTRANS  
         if (m->bintrans_enable) {  
                 fprintf(stderr, "WARNING: %s was compiled without "  
                     "bintrans support. Ignoring -b.\n", progname);  
                 m->bintrans_enable = 0;  
         }  
 #endif  
   
 #ifndef WITH_X11  
         if (m->use_x11) {  
                 fprintf(stderr, "WARNING: %s was compiled without "  
                     "X11 support. Ignoring -X.\n", progname);  
                 m->use_x11 = 0;  
         }  
 #endif  
   
         if (!using_switch_Z && !m->use_x11)  
652                  m->n_gfx_cards = 0;                  m->n_gfx_cards = 0;
653    
         m->bintrans_enabled_from_start = m->bintrans_enable;  
   
654          return 0;          return 0;
655  }  }
656    
# Line 695  int get_cmd_args(int argc, char *argv[], Line 667  int get_cmd_args(int argc, char *argv[],
667   */   */
668  int main(int argc, char *argv[])  int main(int argc, char *argv[])
669  {  {
670            /*  Setting constants:  */
671            const int constant_yes = 1;
672            const int constant_true = 1;
673            const int constant_no = 0;
674            const int constant_false = 0;
675    
676          struct emul **emuls;          struct emul **emuls;
677          char **diskimages = NULL;          char **diskimages = NULL;
678          int n_diskimages = 0;          int n_diskimages = 0;
# Line 703  int main(int argc, char *argv[]) Line 681  int main(int argc, char *argv[])
681    
682          progname = argv[0];          progname = argv[0];
683    
684    
685            /*
686             *  Create the settings object, and add global settings to it:
687             *
688             *  Read-only "constants":     yes, no, true, false.
689             *  Global emulator settings:  verbose, single_step, ...
690             */
691            global_settings = settings_new();
692    
693            settings_add(global_settings, "yes", 0, SETTINGS_TYPE_INT,
694                SETTINGS_FORMAT_YESNO, (void *)&constant_yes);
695            settings_add(global_settings, "no", 0, SETTINGS_TYPE_INT,
696                SETTINGS_FORMAT_YESNO, (void *)&constant_no);
697            settings_add(global_settings, "true", 0, SETTINGS_TYPE_INT,
698                SETTINGS_FORMAT_BOOL, (void *)&constant_true);
699            settings_add(global_settings, "false", 0, SETTINGS_TYPE_INT,
700                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,
707                SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, (void *)&single_step);
708    
709            /*  Read/write settings:  */
710            settings_add(global_settings, "force_debugger_at_exit", 1,
711                SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO,
712                (void *)&force_debugger_at_exit);
713            settings_add(global_settings, "verbose", 1,
714                SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, (void *)&verbose);
715            settings_add(global_settings, "quiet_mode", 1,
716                SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, (void *)&quiet_mode);
717    
718            /*  Initialize all emulator subsystems:  */
719          console_init();          console_init();
720          cpu_init();          cpu_init();
721          device_init();          device_init();
722          machine_init();          machine_init();
723            timer_init();
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);
732          if (emuls[0] == NULL) {          settings_add(global_settings, "emul[0]", 1,
733                  fprintf(stderr, "out of memory\n");              SETTINGS_TYPE_SUBSETTINGS, 0, emuls[0]->settings);
                 exit(1);  
         }  
734    
735          get_cmd_args(argc, argv, emuls[0], &diskimages, &n_diskimages);          get_cmd_args(argc, argv, emuls[0], &diskimages, &n_diskimages);
736    
737          if (!fully_deterministic) {          if (!skip_srandom_call) {
738                  /*  TODO: More than just time(). Use gettimeofday().  */                  struct timeval tv;
739                  srandom(time(NULL) ^ (getpid() << 12));                  gettimeofday(&tv, NULL);
740          } else {                  srandom(tv.tv_sec ^ getpid() ^ tv.tv_usec);
                 /*  Fully deterministic. -I must have been supplied.  */  
                 if (emuls[0]->machines[0]->automatic_clock_adjustment) {  
                         fatal("Cannot have -D without -I.\n");  
                         exit(1);  
                 }  
741          }          }
742    
743          /*  Print startup message:  */          /*  Print startup message:  */
744          debug("GXemul");          debug("GXemul");
745  #ifdef VERSION  #ifdef VERSION
746          debug("-" VERSION);          debug(" " VERSION);
747  #endif  #endif
748          debug("   Copyright (C) 2003-2005  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    
752          if (emuls[0]->machines[0]->machine_type == MACHINE_NONE)          if (emuls[0]->machines[0]->machine_type == MACHINE_NONE) {
753                  n_emuls --;                  n_emuls --;
754          else {          } else {
755                  for (i=0; i<n_diskimages; i++)                  for (i=0; i<n_diskimages; i++)
756                          diskimage_add(emuls[0]->machines[0], diskimages[i]);                          diskimage_add(emuls[0]->machines[0], diskimages[i]);
757          }          }
# Line 772  int main(int argc, char *argv[]) Line 776  int main(int argc, char *argv[])
776          /*  Initialize emulations from config files:  */          /*  Initialize emulations from config files:  */
777          for (i=1; i<argc; i++) {          for (i=1; i<argc; i++) {
778                  if (argv[i][0] == '@') {                  if (argv[i][0] == '@') {
779                            char tmpstr[50];
780                          char *s = argv[i] + 1;                          char *s = argv[i] + 1;
781                          if (strlen(s) == 0 && i+1 < argc &&                          if (strlen(s) == 0 && i+1 < argc &&
782                              argv[i+1][0] != '@') {                              argv[i+1][0] != '@') {
# Line 779  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);  
                         }  
                         emuls[n_emuls - 1] =  
                             emul_create_from_configfile(s);  
789    
790                          /*  Always allow slave xterms when using multiple                          /*  Always allow slave xterms when using multiple
791                              emulations:  */                              emulations:  */
792                          console_allow_slaves(1);                          console_allow_slaves(1);
793    
794                            /*  Destroy the temporary emuls[0], since it will
795                                be overwritten:  */
796                            if (n_emuls == 1) {
797                                    emul_destroy(emuls[0]);
798                                    settings_remove(global_settings, "emul[0]");
799                            }
800    
801                            emuls[n_emuls - 1] =
802                                emul_create_from_configfile(s, n_emuls - 1);
803    
804                            snprintf(tmpstr, sizeof(tmpstr), "emul[%i]", n_emuls-1);
805                            settings_add(global_settings, tmpstr, 1,
806                                SETTINGS_TYPE_SUBSETTINGS, 0,
807                                emuls[n_emuls-1]->settings);
808                  }                  }
809          }          }
810    
# Line 803  int main(int argc, char *argv[]) Line 818  int main(int argc, char *argv[])
818          }          }
819    
820          device_set_exit_on_error(0);          device_set_exit_on_error(0);
821            console_warn_if_slaves_are_needed(1);
822    
823    
824          /*  Run all emulations:  */          /*  Run all emulations:  */
825          emul_run(emuls, n_emuls);          emul_run(emuls, n_emuls);
826    
827    
828            /*
829             *  Deinitialize everything:
830             */
831    
832            console_deinit();
833    
834            for (i=0; i<n_emuls; i++)
835                    emul_destroy(emuls[i]);
836    
837            settings_remove_all(global_settings);
838            settings_destroy(global_settings);
839    
840          return 0;          return 0;
841  }  }
842    

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

  ViewVC Help
Powered by ViewVC 1.1.26