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

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

revision 26 by dpavlin, Mon Oct 8 16:20:10 2007 UTC revision 30 by dpavlin, Mon Oct 8 16:20:40 2007 UTC
# Line 25  Line 25 
25   *  SUCH DAMAGE.   *  SUCH DAMAGE.
26   *   *
27   *   *
28   *  $Id: cpu.c,v 1.344 2006/06/24 21:47:22 debug Exp $   *  $Id: cpu.c,v 1.349 2006/07/26 23:21:47 debug Exp $
29   *   *
30   *  Common routines for CPU emulation. (Not specific to any CPU type.)   *  Common routines for CPU emulation. (Not specific to any CPU type.)
31   */   */
# Line 42  Line 42 
42  #include "misc.h"  #include "misc.h"
43    
44    
 extern int quiet_mode;  
   
45  static struct cpu_family *first_cpu_family = NULL;  static struct cpu_family *first_cpu_family = NULL;
46    
47    
# Line 79  struct cpu *cpu_new(struct memory *mem, Line 77  struct cpu *cpu_new(struct memory *mem,
77          cpu->machine            = machine;          cpu->machine            = machine;
78          cpu->cpu_id             = cpu_id;          cpu->cpu_id             = cpu_id;
79          cpu->byte_order         = EMUL_LITTLE_ENDIAN;          cpu->byte_order         = EMUL_LITTLE_ENDIAN;
         cpu->bootstrap_cpu_flag = 0;  
80          cpu->running            = 0;          cpu->running            = 0;
81    
82          cpu_create_or_reset_tc(cpu);          cpu_create_or_reset_tc(cpu);
# Line 389  void cpu_run_deinit(struct machine *mach Line 386  void cpu_run_deinit(struct machine *mach
386          int te;          int te;
387    
388          /*          /*
389           *  Two last ticks of every hardware device.  This will allow           *  Two last ticks of every hardware device.  This will allow e.g.
390           *  framebuffers to draw the last updates to the screen before           *  framebuffers to draw the last updates to the screen before halting.
391           *  halting.           *
392             *  TODO: This should be refactored when redesigning the mainbus
393             *        concepts!
394           */           */
395          for (te=0; te<machine->n_tick_entries; te++) {          for (te=0; te<machine->n_tick_entries; te++) {
396                  machine->tick_func[te](machine->cpus[0],                  machine->tick_func[te](machine->cpus[0],
# Line 400  void cpu_run_deinit(struct machine *mach Line 399  void cpu_run_deinit(struct machine *mach
399                      machine->tick_extra[te]);                      machine->tick_extra[te]);
400          }          }
401    
402          debug("cpu_run_deinit(): All CPUs halted.\n");          if (machine->show_nr_of_instructions)
   
         if (machine->show_nr_of_instructions || !quiet_mode)  
403                  cpu_show_cycles(machine, 1);                  cpu_show_cycles(machine, 1);
404    
405          fflush(stdout);          fflush(stdout);
# Line 440  void cpu_show_cycles(struct machine *mac Line 437  void cpu_show_cycles(struct machine *mac
437          if (mseconds - mseconds_last == 0)          if (mseconds - mseconds_last == 0)
438                  mseconds ++;                  mseconds ++;
439    
440          ninstrs = machine->ncycles_since_gettimeofday;          ninstrs = machine->ninstrs_since_gettimeofday;
441    
442          if (machine->automatic_clock_adjustment) {          if (machine->automatic_clock_adjustment) {
443                  static int first_adjustment = 1;                  static int first_adjustment = 1;
# Line 472  void cpu_show_cycles(struct machine *mac Line 469  void cpu_show_cycles(struct machine *mac
469          if (!machine->show_nr_of_instructions && !forced)          if (!machine->show_nr_of_instructions && !forced)
470                  goto do_return;                  goto do_return;
471    
472          printf("[ %"PRIi64" instrs", (int64_t)machine->ncycles);          printf("[ %"PRIi64" instrs", (int64_t)machine->ninstrs);
473    
474          if (!machine->automatic_clock_adjustment) {          if (!machine->automatic_clock_adjustment) {
475                  d = machine->emulated_hz / 1000;                  d = machine->emulated_hz / 1000;
476                  if (d < 1)                  if (d < 1)
477                          d = 1;                          d = 1;
478                  ms = machine->ncycles / d;                  ms = machine->ninstrs / d;
479                  h = ms / 3600000;                  h = ms / 3600000;
480                  ms -= 3600000 * h;                  ms -= 3600000 * h;
481                  m = ms / 60000;                  m = ms / 60000;
# Line 525  do_return: Line 522  do_return:
522   */   */
523  void cpu_run_init(struct machine *machine)  void cpu_run_init(struct machine *machine)
524  {  {
525          int ncpus = machine->ncpus;          machine->ninstrs_flush = 0;
526          int te;          machine->ninstrs = 0;
527            machine->ninstrs_show = 0;
         machine->a_few_cycles = 1048576;  
         machine->ncycles_flush = 0;  
         machine->ncycles = 0;  
         machine->ncycles_show = 0;  
   
         /*  
          *  Instead of doing { one cycle, check hardware ticks }, we  
          *  can do { n cycles, check hardware ticks }, as long as  
          *  n is at most as much as the lowest number of cycles/tick  
          *  for any hardware device.  
          */  
         for (te=0; te<machine->n_tick_entries; te++) {  
                 if (machine->ticks_reset_value[te] < machine->a_few_cycles)  
                         machine->a_few_cycles = machine->ticks_reset_value[te];  
         }  
   
         machine->a_few_cycles >>= 1;  
         if (machine->a_few_cycles < 1)  
                 machine->a_few_cycles = 1;  
   
         if (ncpus > 1)  
                 machine->a_few_cycles = 1;  
   
         /*  debug("cpu_run_init(): a_few_cycles = %i\n",  
             machine->a_few_cycles);  */  
528    
529          /*  For performance measurement:  */          /*  For performance measurement:  */
530          gettimeofday(&machine->starttime, NULL);          gettimeofday(&machine->starttime, NULL);
531          machine->ncycles_since_gettimeofday = 0;          machine->ninstrs_since_gettimeofday = 0;
532  }  }
533    
534    
# Line 678  void cpu_init(void) Line 650  void cpu_init(void)
650          add_cpu_family(sparc_cpu_family_init, ARCH_SPARC);          add_cpu_family(sparc_cpu_family_init, ARCH_SPARC);
651  #endif  #endif
652    
653    #ifdef ENABLE_TRANSPUTER
654            add_cpu_family(transputer_cpu_family_init, ARCH_TRANSPUTER);
655    #endif
656    
657  #ifdef ENABLE_X86  #ifdef ENABLE_X86
658          add_cpu_family(x86_cpu_family_init, ARCH_X86);          add_cpu_family(x86_cpu_family_init, ARCH_X86);
659  #endif  #endif

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

  ViewVC Help
Powered by ViewVC 1.1.26