/[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 38 by dpavlin, Mon Oct 8 16:21:53 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.296 2007/03/31 15:11:26 debug Exp $
29   */   */
30    
31  #include <stdio.h>  #include <stdio.h>
# Line 46  Line 46 
46  #include "settings.h"  #include "settings.h"
47  #include "timer.h"  #include "timer.h"
48    
49    #ifdef TEST_NATIVE_X86
50    #include "native_x86.h"
51    #endif
52    
53    
54  extern volatile int single_step;  extern volatile int single_step;
55  extern int force_debugger_at_exit;  extern int force_debugger_at_exit;
# Line 59  int extra_argc; Line 63  int extra_argc;
63  char **extra_argv;  char **extra_argv;
64  char *progname;  char *progname;
65    
66    size_t dyntrans_cache_size = DEFAULT_DYNTRANS_CACHE_SIZE;
67    int native_code_translation_enabled = 0;
68  int skip_srandom_call = 0;  int skip_srandom_call = 0;
69    
70    
# Line 198  static void usage(int longusage) Line 204  static void usage(int longusage)
204  #ifdef VERSION  #ifdef VERSION
205          printf(" " VERSION);          printf(" " VERSION);
206  #endif  #endif
207          printf("    Copyright (C) 2003-2006  Anders Gavare\n");          printf("    Copyright (C) 2003-2007  Anders Gavare\n");
208          printf("Read the source code and/or documentation for "          printf("Read the source code and/or documentation for "
209              "other Copyright messages.\n");              "other Copyright messages.\n");
210    
# Line 236  static void usage(int longusage) Line 242  static void usage(int longusage)
242          printf("                gH;S;  set geometry to H heads and S"          printf("                gH;S;  set geometry to H heads and S"
243              " sectors-per-track\n");              " sectors-per-track\n");
244          printf("                i      IDE\n");          printf("                i      IDE\n");
245            printf("                oOFS;  set base offset to OFS (for ISO9660"
246                " filesystems)\n");
247          printf("                r      read-only (don't allow changes to the"          printf("                r      read-only (don't allow changes to the"
248              " file)\n");              " file)\n");
249          printf("                s      SCSI\n");          printf("                s      SCSI\n");
250          printf("                t      tape\n");          printf("                t      tape\n");
251            printf("                V      add an overlay\n");
252          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");  
253          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 "
254              "all combinations\n            of machines and guest OSes)");              "all combinations\n            of machines and guest OSes)\n");
255          printf("  -i        display each instruction as it is executed\n");          printf("  -i        display each instruction as it is executed\n");
256          printf("  -J        disable dyntrans instruction combinations\n");          printf("  -J        disable dyntrans instruction combinations\n");
257          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 292  static void usage(int longusage)
292          printf("                d    disable statistics gathering at "          printf("                d    disable statistics gathering at "
293              "startup\n");              "startup\n");
294          printf("                o    overwrite instead of append\n");          printf("                o    overwrite instead of append\n");
295            printf("  -T        halt on non-existant memory accesses\n");
296          printf("  -t        show function trace tree\n");          printf("  -t        show function trace tree\n");
297          printf("  -U        enable slow_serial_interrupts_hack_for_linux\n");          printf("  -U        enable slow_serial_interrupts_hack_for_linux\n");
298  #ifdef WITH_X11  #ifdef WITH_X11
# Line 306  static void usage(int longusage) Line 315  static void usage(int longusage)
315  #endif  #endif
316    
317          printf("\nGeneral options:\n");          printf("\nGeneral options:\n");
318    #ifdef UNSTABLE_DEVEL
319            printf("  -b        enable native code generation\n");
320            printf("  -B        disable native code generation\n");
321    #endif
322          printf("  -c cmd    add cmd as a command to run before starting "          printf("  -c cmd    add cmd as a command to run before starting "
323              "the simulation\n");              "the simulation\n");
324          printf("  -D        skip the srandom call at startup\n");          printf("  -D        skip the srandom call at startup\n");
325          printf("  -H        display a list of possible CPU and "          printf("  -H        display a list of possible CPU and "
326              "machine types\n");              "machine types\n");
327          printf("  -h        display this help message\n");          printf("  -h        display this help message\n");
328            printf("  -k n      set dyntrans translation caches to n MB (default"
329                " size is %i MB)\n", DEFAULT_DYNTRANS_CACHE_SIZE / 1048576);
330          printf("  -K        force the debugger to be entered at the end "          printf("  -K        force the debugger to be entered at the end "
331              "of a simulation\n");              "of a simulation\n");
332          printf("  -q        quiet mode (don't print startup messages)\n");          printf("  -q        quiet mode (don't print startup messages)\n");
# Line 352  int get_cmd_args(int argc, char *argv[], Line 367  int get_cmd_args(int argc, char *argv[],
367          struct machine *m = emul_add_machine(emul, "default");          struct machine *m = emul_add_machine(emul, "default");
368    
369          char *opts =          char *opts =
370              "C:c:Dd:E:e:G:HhI:iJj:KM:Nn:Oo:p:QqRrSs:tU"  #ifdef UNSTABLE_DEVEL
371                "bB"
372    #endif
373                "C:c:Dd:E:e:HhI:iJj:k:KM:Nn:Oo:p:QqRrSs:TtU"
374  #ifdef UNSTABLE_DEVEL  #ifdef UNSTABLE_DEVEL
375              "u:"              "u:"
376  #endif  #endif
# Line 364  int get_cmd_args(int argc, char *argv[], Line 382  int get_cmd_args(int argc, char *argv[],
382    
383          while ((ch = getopt(argc, argv, opts)) != -1) {          while ((ch = getopt(argc, argv, opts)) != -1) {
384                  switch (ch) {                  switch (ch) {
385    #ifdef UNSTABLE_DEVEL
386                    case 'b':
387    #ifndef NATIVE_CODE_GENERATION
388                            printf("-b is not available on this host arch.\n");
389                            exit(1);
390    #else
391                            native_code_translation_enabled = 1;
392                            break;
393    #endif
394                    case 'B':
395                            native_code_translation_enabled = 0;
396                            break;
397    #endif  /*  UNSTABLE_DEVEL  */
398                  case 'C':                  case 'C':
399                          m->cpu_name = strdup(optarg);                          m->cpu_name = strdup(optarg);
400                          msopts = 1;                          msopts = 1;
# Line 411  int get_cmd_args(int argc, char *argv[], Line 442  int get_cmd_args(int argc, char *argv[],
442                          subtype = optarg;                          subtype = optarg;
443                          msopts = 1;                          msopts = 1;
444                          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;  
445                  case 'H':                  case 'H':
446                          machine_list_available_types_and_cpus();                          machine_list_available_types_and_cpus();
447                          exit(1);                          exit(1);
# Line 448  int get_cmd_args(int argc, char *argv[], Line 468  int get_cmd_args(int argc, char *argv[],
468                          }                          }
469                          msopts = 1;                          msopts = 1;
470                          break;                          break;
471                    case 'k':
472                            dyntrans_cache_size = atoi(optarg) * 1048576;
473                            if (dyntrans_cache_size < 1) {
474                                    fprintf(stderr, "The dyntrans cache size must"
475                                        " be at least 1 MB.\n");
476                                    exit(1);
477                            }
478                            break;
479                  case 'K':                  case 'K':
480                          force_debugger_at_exit = 1;                          force_debugger_at_exit = 1;
481                          break;                          break;
# Line 511  int get_cmd_args(int argc, char *argv[], Line 539  int get_cmd_args(int argc, char *argv[],
539                          break;                          break;
540                  case 's':                  case 's':
541                          machine_statistics_init(m, optarg);                          machine_statistics_init(m, optarg);
542                            native_code_translation_enabled = 0;
543                            msopts = 1;
544                            break;
545                    case 'T':
546                            m->halt_on_nonexistant_memaccess = 1;
547                          msopts = 1;                          msopts = 1;
548                          break;                          break;
549                  case 't':                  case 't':
# Line 707  int main(int argc, char *argv[]) Line 740  int main(int argc, char *argv[])
740          int i;          int i;
741    
742    
743    /*
744     *  Experimental profil() code, which works on my laptop.
745     *  Don't use it for anything else.
746     */
747    #ifdef USE_PROFIL
748            uint16_t samples[0x100000];
749            memset(samples, 0, sizeof(samples));
750            profil((char *)samples, sizeof(samples), (vm_offset_t) 0x400000, 8192);
751    #endif
752    
753    #ifndef NATIVE_CODE_GENERATION
754            native_code_translation_enabled = 0;
755    #endif
756    
757    
758    /*  Experimental test code:  */
759    #ifdef TEST_NATIVE_X86
760            test_native_x86();
761    #endif
762    
763    
764    
765          progname = argv[0];          progname = argv[0];
766    
767    
# Line 727  int main(int argc, char *argv[]) Line 782  int main(int argc, char *argv[])
782          settings_add(global_settings, "false", 0, SETTINGS_TYPE_INT,          settings_add(global_settings, "false", 0, SETTINGS_TYPE_INT,
783              SETTINGS_FORMAT_BOOL, (void *)&constant_false);              SETTINGS_FORMAT_BOOL, (void *)&constant_false);
784    
785            /*  Read-only settings:  */
786            settings_add(global_settings, "native_code_translation_enabled", 0,
787                SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO,
788                (void *)&native_code_translation_enabled);
789          settings_add(global_settings, "single_step", 0,          settings_add(global_settings, "single_step", 0,
790              SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, (void *)&single_step);              SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, (void *)&single_step);
791    
792            /*  Read/write settings:  */
793          settings_add(global_settings, "force_debugger_at_exit", 1,          settings_add(global_settings, "force_debugger_at_exit", 1,
794              SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO,              SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO,
795              (void *)&force_debugger_at_exit);              (void *)&force_debugger_at_exit);
# Line 753  int main(int argc, char *argv[]) Line 814  int main(int argc, char *argv[])
814    
815          /*  Allocate space for a simple emul setup:  */          /*  Allocate space for a simple emul setup:  */
816          n_emuls = 1;          n_emuls = 1;
817          emuls[0] = emul_new(NULL);          emuls[0] = emul_new(NULL, 0);
818          if (emuls[0] == NULL) {          if (emuls[0] == NULL) {
819                  fprintf(stderr, "out of memory\n");                  fprintf(stderr, "out of memory\n");
820                  exit(1);                  exit(1);
# Line 774  int main(int argc, char *argv[]) Line 835  int main(int argc, char *argv[])
835  #ifdef VERSION  #ifdef VERSION
836          debug(" " VERSION);          debug(" " VERSION);
837  #endif  #endif
838          debug("    Copyright (C) 2003-2006  Anders Gavare\n");          debug("    Copyright (C) 2003-2007  Anders Gavare\n");
839          debug("Read the source code and/or documentation for "          debug("Read the source code and/or documentation for "
840              "other Copyright messages.\n\n");              "other Copyright messages.\n\n");
841    
# Line 831  int main(int argc, char *argv[]) Line 892  int main(int argc, char *argv[])
892                          }                          }
893    
894                          emuls[n_emuls - 1] =                          emuls[n_emuls - 1] =
895                              emul_create_from_configfile(s);                              emul_create_from_configfile(s, n_emuls - 1);
896    
897                          snprintf(tmpstr, sizeof(tmpstr), "emul[%i]", n_emuls-1);                          snprintf(tmpstr, sizeof(tmpstr), "emul[%i]", n_emuls-1);
898                          settings_add(global_settings, tmpstr, 1,                          settings_add(global_settings, tmpstr, 1,
# Line 869  int main(int argc, char *argv[]) Line 930  int main(int argc, char *argv[])
930          settings_remove_all(global_settings);          settings_remove_all(global_settings);
931          settings_destroy(global_settings);          settings_destroy(global_settings);
932    
933    #ifdef USE_PROFIL
934    {
935            int i;
936            FILE *f = fopen("output.txt", "w");
937            for (i=0; i<sizeof(samples) / sizeof(uint16_t); ++i) {
938                    if (samples[i] != 0)
939                            fprintf(f, "%i %p\n", samples[i],
940                                (void *) (size_t) (0x400000 + i * 16));
941            }
942    }
943    #endif
944    
945          return 0;          return 0;
946  }  }
947    

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

  ViewVC Help
Powered by ViewVC 1.1.26