/[gxemul]/trunk/src/emul.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/emul.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 22 by dpavlin, Mon Oct 8 16:19:37 2007 UTC revision 26 by dpavlin, Mon Oct 8 16:20:10 2007 UTC
# Line 25  Line 25 
25   *  SUCH DAMAGE.   *  SUCH DAMAGE.
26   *   *
27   *   *
28   *  $Id: emul.c,v 1.247 2006/02/04 12:27:12 debug Exp $   *  $Id: emul.c,v 1.255 2006/06/24 19:52:27 debug Exp $
29   *   *
30   *  Emulation startup and misc. routines.   *  Emulation startup and misc. routines.
31   */   */
# Line 39  Line 39 
39  #include <unistd.h>  #include <unistd.h>
40    
41  #include "arcbios.h"  #include "arcbios.h"
 #include "bintrans.h"  
42  #include "cpu.h"  #include "cpu.h"
43  #include "emul.h"  #include "emul.h"
44  #include "console.h"  #include "console.h"
# Line 56  Line 55 
55  #include "x11.h"  #include "x11.h"
56    
57    
 extern int force_debugger_at_exit;  
   
58  extern int extra_argc;  extern int extra_argc;
59  extern char **extra_argv;  extern char **extra_argv;
60    
61  extern int verbose;  extern int verbose;
62  extern int quiet_mode;  extern int quiet_mode;
63    extern int force_debugger_at_exit;
64    extern int single_step;
65    extern int old_show_trace_tree;
66    extern int old_instruction_trace;
67    extern int old_quiet_mode;
68    extern int quiet_mode;
69    
70  extern struct emul *debugger_emul;  extern struct emul *debugger_emul;
71  extern struct diskimage *diskimages[];  extern struct diskimage *diskimages[];
# Line 105  static void add_dump_points(struct machi Line 108  static void add_dump_points(struct machi
108                          uint64_t addr;                          uint64_t addr;
109                          int res = get_symbol_addr(&m->symbol_context,                          int res = get_symbol_addr(&m->symbol_context,
110                              m->breakpoint_string[i], &addr);                              m->breakpoint_string[i], &addr);
111                          if (!res)                          if (!res) {
112                                  fprintf(stderr,                                  fprintf(stderr,
113                                      "WARNING! Breakpoint '%s' could not be"                                      "ERROR! Breakpoint '%s' could not be"
114                                          " parsed\n",                                          " parsed\n",
115                                      m->breakpoint_string[i]);                                      m->breakpoint_string[i]);
116                          else {                          } else {
117                                  dp = addr;                                  dp = addr;
118                                  string_flag = 1;                                  string_flag = 1;
119                          }                          }
# Line 940  void emul_machine_setup(struct machine * Line 943  void emul_machine_setup(struct machine *
943          if (m->arch == ARCH_ALPHA)          if (m->arch == ARCH_ALPHA)
944                  m->arch_pagesize = 8192;                  m->arch_pagesize = 8192;
945    
         if (m->arch != ARCH_MIPS)  
                 m->bintrans_enable = 0;  
   
946          machine_memsize_fix(m);          machine_memsize_fix(m);
947    
948          /*          /*
# Line 990  void emul_machine_setup(struct machine * Line 990  void emul_machine_setup(struct machine *
990          }          }
991          memset(m->cpus, 0, sizeof(struct cpu *) * m->ncpus);          memset(m->cpus, 0, sizeof(struct cpu *) * m->ncpus);
992    
         /*  Initialize dynamic binary translation, if available:  */  
         if (m->bintrans_enable)  
                 bintrans_init(m, m->memory);  
   
993          debug("cpu0");          debug("cpu0");
994          if (m->ncpus > 1)          if (m->ncpus > 1)
995                  debug(" .. cpu%i", m->ncpus - 1);                  debug(" .. cpu%i", m->ncpus - 1);
996          debug(": ");          debug(": ");
997          for (i=0; i<m->ncpus; i++) {          for (i=0; i<m->ncpus; i++) {
998                  m->cpus[i] = cpu_new(m->memory, m, i, m->cpu_name);                  m->cpus[i] = cpu_new(m->memory, m, i, m->cpu_name);
999                  if (m->bintrans_enable)                  if (m->cpus[i] == NULL) {
1000                          bintrans_init_cpu(m->cpus[i]);                          fprintf(stderr, "Unable to create CPU object. "
1001                                "Aborting.");
1002                            exit(1);
1003                    }
1004          }          }
1005          debug("\n");          debug("\n");
1006    
# Line 1012  void emul_machine_setup(struct machine * Line 1011  void emul_machine_setup(struct machine *
1011                  m->cpus[m->ncpus] = cpu_new(m->memory, m,                  m->cpus[m->ncpus] = cpu_new(m->memory, m,
1012                      0  /*  use 0 here to show info with debug()  */,                      0  /*  use 0 here to show info with debug()  */,
1013                      "Allegrex" /*  TODO  */);                      "Allegrex" /*  TODO  */);
                 if (m->bintrans_enable)  
                         bintrans_init_cpu(m->cpus[m->ncpus]);  
1014                  debug("\n");                  debug("\n");
1015                  m->ncpus ++;                  m->ncpus ++;
1016          }          }
# Line 1355  void emul_machine_setup(struct machine * Line 1352  void emul_machine_setup(struct machine *
1352    
1353          symbol_recalc_sizes(&m->symbol_context);          symbol_recalc_sizes(&m->symbol_context);
1354    
         if (m->max_random_cycles_per_chunk > 0)  
                 debug("using random cycle chunks (1 to %i cycles)\n",  
                     m->max_random_cycles_per_chunk);  
   
1355          /*  Special hack for ARC/SGI emulation:  */          /*  Special hack for ARC/SGI emulation:  */
1356          if ((m->machine_type == MACHINE_ARC ||          if ((m->machine_type == MACHINE_ARC ||
1357              m->machine_type == MACHINE_SGI) && m->prom_emulation)              m->machine_type == MACHINE_SGI) && m->prom_emulation)
# Line 1493  struct emul *emul_create_from_configfile Line 1486  struct emul *emul_create_from_configfile
1486  {  {
1487          int iadd = DEBUG_INDENTATION;          int iadd = DEBUG_INDENTATION;
1488          struct emul *e = emul_new(fname);          struct emul *e = emul_new(fname);
         FILE *f;  
         char buf[128];  
         size_t len;  
1489    
1490          debug("Creating emulation from configfile \"%s\":\n", fname);          debug("Creating emulation from configfile \"%s\":\n", fname);
1491          debug_indentation(iadd);          debug_indentation(iadd);
1492    
1493          f = fopen(fname, "r");          emul_parse_config(e, fname);
         if (f == NULL) {  
                 perror(fname);  
                 exit(1);  
         }  
   
         /*  Read header: (must be !!gxemul)  */  
         len = fread(buf, 1, 8, f);  
         if (len != 8 || strncmp(buf, "!!gxemul", 8) != 0) {  
                 fprintf(stderr, "%s: must start with '!!gxemul'\n", fname);  
                 exit(1);  
         }  
   
         /*  Restart from beginning:  */  
         rewind(f);  
   
         emul_parse_config(e, f);  
1494    
         fclose(f);  
1495          debug_indentation(-iadd);          debug_indentation(-iadd);
1496          return e;          return e;
1497  }  }
# Line 1608  void emul_run(struct emul **emuls, int n Line 1581  void emul_run(struct emul **emuls, int n
1581          while (go) {          while (go) {
1582                  go = 0;                  go = 0;
1583    
1584                  x11_check_event(emuls, n_emuls);                  /*  Flush X11 and serial console output every now and then:  */
1585                    if (emuls[0]->machines[0]->ncycles >
1586                  for (i=0; i<n_emuls; i++) {                      emuls[0]->machines[0]->ncycles_flush + (1<<18)) {
1587                          e = emuls[i];                          x11_check_event(emuls, n_emuls);
1588                          if (e == NULL)                          console_flush();
1589                                  continue;                          emuls[0]->machines[0]->ncycles_flush =
1590                                emuls[0]->machines[0]->ncycles;
1591                          for (j=0; j<e->n_machines; j++) {                  }
1592                                  /*  TODO: cpu_run() is a strange name, since  
1593                                      there can be multiple cpus in a machine  */                  if (emuls[0]->machines[0]->ncycles >
1594                                  anything = cpu_run(e, e->machines[j]);                      emuls[0]->machines[0]->ncycles_show + (1<<25)) {
1595                                  if (anything)                          emuls[0]->machines[0]->ncycles_since_gettimeofday +=
1596                                          go = 1;                              (emuls[0]->machines[0]->ncycles -
1597                          }                               emuls[0]->machines[0]->ncycles_show);
1598                            cpu_show_cycles(emuls[0]->machines[0], 0);
1599                            emuls[0]->machines[0]->ncycles_show =
1600                                emuls[0]->machines[0]->ncycles;
1601                    }
1602    
1603                    if (single_step == ENTER_SINGLE_STEPPING) {
1604                            /*  TODO: Cleanup!  */
1605                            old_instruction_trace =
1606                                emuls[0]->machines[0]->instruction_trace;
1607                            old_quiet_mode = quiet_mode;
1608                            old_show_trace_tree =
1609                                emuls[0]->machines[0]->show_trace_tree;
1610                            emuls[0]->machines[0]->instruction_trace = 1;
1611                            emuls[0]->machines[0]->show_trace_tree = 1;
1612                            quiet_mode = 0;
1613                            single_step = SINGLE_STEPPING;
1614                    }
1615    
1616                    if (single_step == SINGLE_STEPPING)
1617                            debugger();
1618    
1619                    e = emuls[0];   /*  Note: Only 1 emul supported now.  */
1620    
1621                    for (j=0; j<e->n_machines; j++) {
1622                            if (e->machines[j]->gdb.port > 0)
1623                                    debugger_gdb_check_incoming(e->machines[j]);
1624    
1625                            anything = machine_run(e->machines[j]);
1626                            if (anything)
1627                                    go = 1;
1628                  }                  }
1629          }          }
1630    

Legend:
Removed from v.22  
changed lines
  Added in v.26

  ViewVC Help
Powered by ViewVC 1.1.26