/[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 2 by dpavlin, Mon Oct 8 16:17:48 2007 UTC revision 38 by dpavlin, Mon Oct 8 16:21:53 2007 UTC
# Line 1  Line 1 
1  /*  /*
2   *  Copyright (C) 2005  Anders Gavare.  All rights reserved.   *  Copyright (C) 2005-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: cpu.c,v 1.291 2005/03/13 09:36:08 debug Exp $   *  $Id: cpu.c,v 1.374 2007/04/10 17:26:19 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 33  Line 33 
33  #include <stdio.h>  #include <stdio.h>
34  #include <stdlib.h>  #include <stdlib.h>
35  #include <sys/types.h>  #include <sys/types.h>
36    #include <sys/mman.h>
37  #include <string.h>  #include <string.h>
38    
39  #include "cpu.h"  #include "cpu.h"
40  #include "machine.h"  #include "machine.h"
41    #include "memory.h"
42  #include "misc.h"  #include "misc.h"
43    #include "settings.h"
44    
45    
46  extern int quiet_mode;  extern size_t dyntrans_cache_size;
47  extern int show_opcode_statistics;  extern int native_code_translation_enabled;
   
48    
49  static struct cpu_family *first_cpu_family = NULL;  static struct cpu_family *first_cpu_family = NULL;
50    
# Line 52  static struct cpu_family *first_cpu_fami Line 54  static struct cpu_family *first_cpu_fami
54   *   *
55   *  Create a new cpu object.  Each family is tried in sequence until a   *  Create a new cpu object.  Each family is tried in sequence until a
56   *  CPU family recognizes the cpu_type_name.   *  CPU family recognizes the cpu_type_name.
57     *
58     *  If there was no match, NULL is returned. Otherwise, a pointer to an
59     *  initialized cpu struct is returned.
60   */   */
61  struct cpu *cpu_new(struct memory *mem, struct machine *machine,  struct cpu *cpu_new(struct memory *mem, struct machine *machine,
62          int cpu_id, char *name)          int cpu_id, char *name)
63  {  {
64          struct cpu *c;          struct cpu *cpu;
65          struct cpu_family *fp;          struct cpu_family *fp;
66          char *cpu_type_name;          char *cpu_type_name;
67            char tmpstr[30];
68    
69          if (name == NULL) {          if (name == NULL) {
70                  fprintf(stderr, "cpu_new(): cpu name = NULL?\n");                  fprintf(stderr, "cpu_new(): cpu name = NULL?\n");
# Line 71  struct cpu *cpu_new(struct memory *mem, Line 77  struct cpu *cpu_new(struct memory *mem,
77                  exit(1);                  exit(1);
78          }          }
79    
80            cpu = zeroed_alloc(sizeof(struct cpu));
81    
82            cpu->path = malloc(strlen(machine->path) + 15);
83            if (cpu->path == NULL) {
84                    fprintf(stderr, "cpu_new(): out of memory\n");
85                    exit(1);
86            }
87            snprintf(cpu->path, strlen(machine->path) + 15,
88                "%s.cpu[%i]", machine->path, cpu_id);
89    
90            cpu->memory_rw  = NULL;
91            cpu->name       = cpu_type_name;
92            cpu->mem        = mem;
93            cpu->machine    = machine;
94            cpu->cpu_id     = cpu_id;
95            cpu->byte_order = EMUL_UNDEFINED_ENDIAN;
96            cpu->running    = 0;
97    
98            /*  Create settings, and attach to the machine:  */
99            cpu->settings = settings_new();
100            snprintf(tmpstr, sizeof(tmpstr), "cpu[%i]", cpu_id);
101            settings_add(machine->settings, tmpstr, 1,
102                SETTINGS_TYPE_SUBSETTINGS, 0, cpu->settings);
103    
104            settings_add(cpu->settings, "name", 0, SETTINGS_TYPE_STRING,
105                SETTINGS_FORMAT_STRING, (void *) &cpu->name);
106            settings_add(cpu->settings, "running", 0, SETTINGS_TYPE_INT,
107                SETTINGS_FORMAT_YESNO, (void *) &cpu->running);
108    
109            cpu_create_or_reset_tc(cpu);
110    
111          fp = first_cpu_family;          fp = first_cpu_family;
112    
113          while (fp != NULL) {          while (fp != NULL) {
114                  if (fp->cpu_new != NULL) {                  if (fp->cpu_new != NULL) {
115                          c = fp->cpu_new(mem, machine, cpu_id, cpu_type_name);                          if (fp->cpu_new(cpu, mem, machine, cpu_id,
116                          if (c != NULL) {                              cpu_type_name)) {
117                                  /*  Some sanity-checks:  */                                  /*  Sanity check:  */
118                                  if (c->memory_rw == NULL) {                                  if (cpu->memory_rw == NULL) {
119                                          fatal("No memory_rw?\n");                                          fatal("\ncpu_new(): memory_rw == "
120                                                "NULL\n");
121                                          exit(1);                                          exit(1);
122                                  }                                  }
123                                    break;
                                 return c;  
124                          }                          }
125                  }                  }
126    
127                  fp = fp->next;                  fp = fp->next;
128          }          }
129    
130          fprintf(stderr, "cpu_new(): unknown cpu type '%s'\n", cpu_type_name);          if (fp == NULL) {
131          exit(1);                  fatal("\ncpu_new(): unknown cpu type '%s'\n", cpu_type_name);
132                    return NULL;
133            }
134    
135            fp->init_tables(cpu);
136    
137            if (cpu->byte_order == EMUL_UNDEFINED_ENDIAN) {
138                    fatal("\ncpu_new(): Internal bug: Endianness not set.\n");
139                    exit(1);
140            }
141    
142            return cpu;
143  }  }
144    
145    
146  /*  /*
147   *  cpu_show_full_statistics():   *  cpu_destroy():
148   *   *
149   *  Show detailed statistics on opcode usage on each cpu.   *  Destroy a cpu object.
150   */   */
151  void cpu_show_full_statistics(struct machine *m)  void cpu_destroy(struct cpu *cpu)
152  {  {
153          if (m->cpu_family == NULL ||          settings_remove(cpu->settings, "name");
154              m->cpu_family->show_full_statistics == NULL)          settings_remove(cpu->settings, "running");
155                  fatal("cpu_show_full_statistics(): NULL\n");  
156          else          /*  Remove any remaining level-1 settings:  */
157                  m->cpu_family->show_full_statistics(m);          settings_remove_all(cpu->settings);
158    
159            settings_destroy(cpu->settings);
160    
161            if (cpu->path != NULL)
162                    free(cpu->path);
163    
164            /*  TODO: This assumes that zeroed_alloc() actually succeeded
165                with using mmap(), and not malloc()!  */
166            munmap((void *)cpu, sizeof(struct cpu));
167  }  }
168    
169    
# Line 129  void cpu_tlbdump(struct machine *m, int Line 186  void cpu_tlbdump(struct machine *m, int
186    
187    
188  /*  /*
  *  cpu_register_match():  
  *  
  *  Used by the debugger.  
  */  
 void cpu_register_match(struct machine *m, char *name,  
         int writeflag, uint64_t *valuep, int *match_register)  
 {  
         if (m->cpu_family == NULL || m->cpu_family->register_match == NULL)  
                 fatal("cpu_register_match(): NULL\n");  
         else  
                 m->cpu_family->register_match(m, name, writeflag,  
                     valuep, match_register);  
 }  
   
   
 /*  
189   *  cpu_disassemble_instr():   *  cpu_disassemble_instr():
190   *   *
191   *  Convert an instruction word into human readable format, for instruction   *  Convert an instruction word into human readable format, for instruction
192   *  tracing.   *  tracing.
193   */   */
194  int cpu_disassemble_instr(struct machine *m, struct cpu *cpu,  int cpu_disassemble_instr(struct machine *m, struct cpu *cpu,
195          unsigned char *instr, int running, uint64_t addr, int bintrans)          unsigned char *instr, int running, uint64_t addr)
196  {  {
197          if (m->cpu_family == NULL || m->cpu_family->disassemble_instr == NULL) {          if (m->cpu_family == NULL || m->cpu_family->disassemble_instr == NULL) {
198                  fatal("cpu_disassemble_instr(): NULL\n");                  fatal("cpu_disassemble_instr(): NULL\n");
199                  return 0;                  return 0;
200          } else          } else
201                  return m->cpu_family->disassemble_instr(cpu, instr,                  return m->cpu_family->disassemble_instr(cpu, instr,
202                      running, addr, bintrans);                      running, addr);
203  }  }
204    
205    
# Line 167  int cpu_disassemble_instr(struct machine Line 208  int cpu_disassemble_instr(struct machine
208   *   *
209   *  Dump cpu registers in a relatively readable format.   *  Dump cpu registers in a relatively readable format.
210   *   *
211   *  gprs: set to non-zero to dump GPRs. (CPU dependant.)   *  gprs: set to non-zero to dump GPRs. (CPU dependent.)
212   *  coprocs: set bit 0..x to dump registers in coproc 0..x. (CPU dependant.)   *  coprocs: set bit 0..x to dump registers in coproc 0..x. (CPU dependent.)
213   */   */
214  void cpu_register_dump(struct machine *m, struct cpu *cpu,  void cpu_register_dump(struct machine *m, struct cpu *cpu,
215          int gprs, int coprocs)          int gprs, int coprocs)
# Line 181  void cpu_register_dump(struct machine *m Line 222  void cpu_register_dump(struct machine *m
222    
223    
224  /*  /*
225   *  cpu_interrupt():   *  cpu_functioncall_trace():
226   *   *
227   *  Assert an interrupt.   *  This function should be called if machine->show_trace_tree is enabled, and
228   *  Return value is 1 if the interrupt was asserted, 0 otherwise.   *  a function call is being made. f contains the address of the function.
229   */   */
230  int cpu_interrupt(struct cpu *cpu, uint64_t irq_nr)  void cpu_functioncall_trace(struct cpu *cpu, uint64_t f)
231  {  {
232          if (cpu->machine->cpu_family == NULL ||          int i, n_args = -1;
233              cpu->machine->cpu_family->interrupt == NULL) {          char *symbol;
234                  fatal("cpu_interrupt(): NULL\n");          uint64_t offset;
235                  return 0;  
236          } else          if (cpu->machine->ncpus > 1)
237                  return cpu->machine->cpu_family->interrupt(cpu, irq_nr);                  fatal("cpu%i:\t", cpu->cpu_id);
238    
239            cpu->trace_tree_depth ++;
240            if (cpu->trace_tree_depth > 100)
241                    cpu->trace_tree_depth = 100;
242            for (i=0; i<cpu->trace_tree_depth; i++)
243                    fatal("  ");
244    
245            fatal("<");
246            symbol = get_symbol_name_and_n_args(&cpu->machine->symbol_context,
247                f, &offset, &n_args);
248            if (symbol != NULL)
249                    fatal("%s", symbol);
250            else {
251                    if (cpu->is_32bit)
252                            fatal("0x%"PRIx32, (uint32_t) f);
253                    else
254                            fatal("0x%"PRIx64, (uint64_t) f);
255            }
256            fatal("(");
257    
258            if (cpu->machine->cpu_family->functioncall_trace != NULL)
259                    cpu->machine->cpu_family->functioncall_trace(cpu, f, n_args);
260    
261            fatal(")>\n");
262    
263    #ifdef PRINT_MEMORY_CHECKSUM
264            /*  Temporary hack for finding bugs:  */
265            fatal("call chksum=%016"PRIx64"\n", memory_checksum(cpu->mem));
266    #endif
267  }  }
268    
269    
270  /*  /*
271   *  cpu_interrupt_ack():   *  cpu_functioncall_trace_return():
272     *
273     *  This function should be called if machine->show_trace_tree is enabled, and
274     *  a function is being returned from.
275   *   *
276   *  Acknowledge an interrupt.   *  TODO: Print return value? This could be implemented similar to the
277   *  Return value is 1 if the interrupt was deasserted, 0 otherwise.   *  cpu->functioncall_trace function call above.
278   */   */
279  int cpu_interrupt_ack(struct cpu *cpu, uint64_t irq_nr)  void cpu_functioncall_trace_return(struct cpu *cpu)
280  {  {
281          if (cpu->machine->cpu_family == NULL ||          cpu->trace_tree_depth --;
282              cpu->machine->cpu_family->interrupt_ack == NULL) {          if (cpu->trace_tree_depth < 0)
283                  /*  debug("cpu_interrupt_ack(): NULL\n");  */                  cpu->trace_tree_depth = 0;
                 return 0;  
         } else  
                 return cpu->machine->cpu_family->interrupt_ack(cpu, irq_nr);  
284  }  }
285    
286    
287  /*  /*
288   *  cpu_run():   *  cpu_create_or_reset_tc():
  *  
  *  Run instructions on all CPUs in this machine, for a "medium duration"  
  *  (or until all CPUs have halted).  
289   *   *
290   *  Return value is 1 if anything happened, 0 if all CPUs are stopped.   *  Create the translation cache in memory (ie allocate memory for it), if
291     *  necessary, and then reset it to an initial state.
292   */   */
293  int cpu_run(struct emul *emul, struct machine *m)  void cpu_create_or_reset_tc(struct cpu *cpu)
294  {  {
295          if (m->cpu_family == NULL || m->cpu_family->run == NULL) {          size_t s = dyntrans_cache_size + DYNTRANS_CACHE_MARGIN;
296                  fatal("cpu_run(): NULL\n");  
297                  return 0;          if (cpu->translation_cache == NULL) {
298          } else                  cpu->translation_cache = zeroed_alloc(s);
299                  return m->cpu_family->run(emul, m);  
300    #ifdef NATIVE_CODE_GENERATION
301                    if (native_code_translation_enabled) {
302                            mprotect(cpu->translation_cache, s,
303                                PROT_READ | PROT_WRITE | PROT_EXEC);
304                    }
305    #endif
306            }
307    
308    #ifdef NATIVE_CODE_GENERATION
309            if (native_code_translation_enabled && cpu->inr.inr_entries == NULL)
310                    cpu->inr.inr_entries = zeroed_alloc(
311                        sizeof(struct inr_entry) * INR_MAX_ENTRIES);
312    
313            cpu->inr.nr_inr_entries_used = 0;
314    #endif
315    
316            /*  Create an empty table at the beginning of the translation cache:  */
317            memset(cpu->translation_cache, 0, sizeof(uint32_t)
318                * N_BASE_TABLE_ENTRIES);
319    
320            cpu->translation_cache_cur_ofs =
321                N_BASE_TABLE_ENTRIES * sizeof(uint32_t);
322    
323            /*
324             *  There might be other translation pointers that still point to
325             *  within the translation_cache region. Let's invalidate those too:
326             */
327            if (cpu->invalidate_code_translation != NULL)
328                    cpu->invalidate_code_translation(cpu, 0, INVALIDATE_ALL);
329  }  }
330    
331    
# Line 236  int cpu_run(struct emul *emul, struct ma Line 333  int cpu_run(struct emul *emul, struct ma
333   *  cpu_dumpinfo():   *  cpu_dumpinfo():
334   *   *
335   *  Dumps info about a CPU using debug(). "cpu0: CPUNAME, running" (or similar)   *  Dumps info about a CPU using debug(). "cpu0: CPUNAME, running" (or similar)
336   *  is outputed, and it is up to CPU dependant code to complete the line.   *  is outputed, and it is up to CPU dependent code to complete the line.
337   */   */
338  void cpu_dumpinfo(struct machine *m, struct cpu *cpu)  void cpu_dumpinfo(struct machine *m, struct cpu *cpu)
339  {  {
# Line 258  void cpu_dumpinfo(struct machine *m, str Line 355  void cpu_dumpinfo(struct machine *m, str
355  void cpu_list_available_types(void)  void cpu_list_available_types(void)
356  {  {
357          struct cpu_family *fp;          struct cpu_family *fp;
358          int iadd = 4;          int iadd = DEBUG_INDENTATION;
359    
360          fp = first_cpu_family;          fp = first_cpu_family;
361    
# Line 288  void cpu_list_available_types(void) Line 385  void cpu_list_available_types(void)
385   *  Shuts down all CPUs in a machine when ending a simulation. (This function   *  Shuts down all CPUs in a machine when ending a simulation. (This function
386   *  should only need to be called once for each machine.)   *  should only need to be called once for each machine.)
387   */   */
388  void cpu_run_deinit(struct emul *emul, struct machine *machine)  void cpu_run_deinit(struct machine *machine)
389  {  {
390          int te;          int te;
391    
392          /*          /*
393           *  Two last ticks of every hardware device.  This will allow           *  Two last ticks of every hardware device.  This will allow e.g.
394           *  framebuffers to draw the last updates to the screen before           *  framebuffers to draw the last updates to the screen before halting.
395           *  halting.           *
396             *  TODO: This should be refactored when redesigning the mainbus
397             *        concepts!
398           */           */
399          for (te=0; te<machine->n_tick_entries; te++) {          for (te=0; te<machine->n_tick_entries; te++) {
400                  machine->tick_func[te](machine->cpus[0],                  machine->tick_func[te](machine->cpus[0],
# Line 304  void cpu_run_deinit(struct emul *emul, s Line 403  void cpu_run_deinit(struct emul *emul, s
403                      machine->tick_extra[te]);                      machine->tick_extra[te]);
404          }          }
405    
406          debug("cpu_run_deinit(): All CPUs halted.\n");          if (machine->show_nr_of_instructions)
407                    cpu_show_cycles(machine, 1);
         if (machine->show_nr_of_instructions || !quiet_mode)  
                 cpu_show_cycles(machine, &machine->starttime,  
                     machine->ncycles, 1);  
   
         if (show_opcode_statistics)  
                 cpu_show_full_statistics(machine);  
408    
409          fflush(stdout);          fflush(stdout);
410  }  }
# Line 320  void cpu_run_deinit(struct emul *emul, s Line 413  void cpu_run_deinit(struct emul *emul, s
413  /*  /*
414   *  cpu_show_cycles():   *  cpu_show_cycles():
415   *   *
416   *  If automatic adjustment of clock interrupts is turned on, then recalculate   *  If show_nr_of_instructions is on, then print a line to stdout about how
417   *  emulated_hz.  Also, if show_nr_of_instructions is on, then print a   *  many instructions/cycles have been executed so far.
  *  line to stdout about how many instructions/cycles have been executed so  
  *  far.  
418   */   */
419  void cpu_show_cycles(struct machine *machine,  void cpu_show_cycles(struct machine *machine, int forced)
         struct timeval *starttime, int64_t ncycles, int forced)  
420  {  {
421          uint64_t offset, pc;          uint64_t offset, pc;
         int is_32bit = 0, instrs_per_cycle;  
422          char *symbol;          char *symbol;
423          int64_t mseconds, ninstrs;          int64_t mseconds, ninstrs, is, avg;
424          struct timeval tv;          struct timeval tv;
425          int h, m, s, ms, d;          struct cpu *cpu = machine->cpus[machine->bootstrap_cpu];
426    
427          static int64_t mseconds_last = 0;          static int64_t mseconds_last = 0;
428          static int64_t ninstrs_last = -1;          static int64_t ninstrs_last = -1;
429    
430          if (machine->arch != ARCH_MIPS) {          pc = cpu->pc;
                 fatal("cpu_show_cycles(): not yet for !MIPS\n");  
                 return;  
         }  
   
         if (machine->cpus[machine->bootstrap_cpu]->cd.mips.cpu_type.isa_level  
             < 3 || machine->cpus[machine->bootstrap_cpu]->cd.mips.cpu_type.  
             isa_level == 32)  
                 is_32bit = 1;  
         pc = machine->cpus[machine->bootstrap_cpu]->pc;  
         instrs_per_cycle = machine->cpus[machine->bootstrap_cpu]->  
             cd.mips.cpu_type.instrs_per_cycle;  
431    
432          gettimeofday(&tv, NULL);          gettimeofday(&tv, NULL);
433          mseconds = (tv.tv_sec - starttime->tv_sec) * 1000          mseconds = (tv.tv_sec - machine->starttime.tv_sec) * 1000
434                   + (tv.tv_usec - starttime->tv_usec) / 1000;                   + (tv.tv_usec - machine->starttime.tv_usec) / 1000;
435    
436          if (mseconds == 0)          if (mseconds == 0)
437                  mseconds = 1;                  mseconds = 1;
# Line 361  void cpu_show_cycles(struct machine *mac Line 439  void cpu_show_cycles(struct machine *mac
439          if (mseconds - mseconds_last == 0)          if (mseconds - mseconds_last == 0)
440                  mseconds ++;                  mseconds ++;
441    
442          ninstrs = ncycles * instrs_per_cycle;          ninstrs = machine->ninstrs_since_gettimeofday;
   
         if (machine->automatic_clock_adjustment) {  
                 static int first_adjustment = 1;  
   
                 /*  Current nr of cycles per second:  */  
                 int64_t cur_cycles_per_second = 1000 *  
                     (ninstrs-ninstrs_last) / (mseconds-mseconds_last)  
                     / instrs_per_cycle;  
   
                 if (cur_cycles_per_second < 1000000)  
                         cur_cycles_per_second = 1000000;  
   
                 if (first_adjustment) {  
                         machine->emulated_hz = cur_cycles_per_second;  
                         first_adjustment = 0;  
                 } else {  
                         machine->emulated_hz = (15 * machine->emulated_hz +  
                             cur_cycles_per_second) / 16;  
                 }  
   
                 debug("[ updating emulated_hz to %lli Hz ]\n",  
                     (long long)machine->emulated_hz);  
         }  
   
443    
444          /*  RETURN here, unless show_nr_of_instructions (-N) is turned on:  */          /*  RETURN here, unless show_nr_of_instructions (-N) is turned on:  */
445          if (!machine->show_nr_of_instructions && !forced)          if (!machine->show_nr_of_instructions && !forced)
446                  goto do_return;                  goto do_return;
447    
448            printf("[ %"PRIi64" instrs", (int64_t)machine->ninstrs);
         printf("[ ");  
   
         if (!machine->automatic_clock_adjustment) {  
                 d = machine->emulated_hz / 1000;  
                 if (d < 1)  
                         d = 1;  
                 ms = ncycles / d;  
                 h = ms / 3600000;  
                 ms -= 3600000 * h;  
                 m = ms / 60000;  
                 ms -= 60000 * m;  
                 s = ms / 1000;  
                 ms -= 1000 * s;  
   
                 printf("emulated time = %02i:%02i:%02i.%03i; ", h, m, s, ms);  
         }  
   
         printf("cycles=%lli", (long long) ncycles);  
   
         if (instrs_per_cycle > 1)  
                 printf(" (%lli instrs)", (long long) ninstrs);  
449    
450          /*  Instructions per second, and average so far:  */          /*  Instructions per second, and average so far:  */
451          printf("; i/s=%lli avg=%lli",          is = 1000 * (ninstrs-ninstrs_last) / (mseconds-mseconds_last);
452              (long long) ((long long)1000 * (ninstrs-ninstrs_last)          avg = (long long)1000 * ninstrs / mseconds;
453                  / (mseconds-mseconds_last)),          if (is < 0)
454              (long long) ((long long)1000 * ninstrs / mseconds));                  is = 0;
455            if (avg < 0)
456                    avg = 0;
457    
458            if (cpu->has_been_idling) {
459                    printf("; idling");
460                    cpu->has_been_idling = 0;
461            } else
462                    printf("; i/s=%"PRIi64" avg=%"PRIi64, is, avg);
463    
464          symbol = get_symbol_name(&machine->symbol_context, pc, &offset);          symbol = get_symbol_name(&machine->symbol_context, pc, &offset);
465    
466          if (is_32bit)          if (machine->ncpus == 1) {
467                  printf("; pc=%08x", (int)pc);                  if (cpu->is_32bit)
468          else                          printf("; pc=0x%08"PRIx32, (uint32_t) pc);
469                  printf("; pc=%016llx", (long long)pc);                  else
470                            printf("; pc=0x%016"PRIx64, (uint64_t) pc);
471            }
472    
473          printf(" <%s> ]\n", symbol? symbol : "no symbol");          if (symbol != NULL)
474                    printf(" <%s>", symbol);
475            printf(" ]\n");
476    
477  do_return:  do_return:
478          ninstrs_last = ninstrs;          ninstrs_last = ninstrs;
# Line 441  do_return: Line 486  do_return:
486   *  Prepare to run instructions on all CPUs in this machine. (This function   *  Prepare to run instructions on all CPUs in this machine. (This function
487   *  should only need to be called once for each machine.)   *  should only need to be called once for each machine.)
488   */   */
489  void cpu_run_init(struct emul *emul, struct machine *machine)  void cpu_run_init(struct machine *machine)
490  {  {
491          int ncpus = machine->ncpus;          machine->ninstrs_flush = 0;
492          int te;          machine->ninstrs = 0;
493            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->max_random_cycles_per_chunk == 0)  
                 machine->a_few_cycles = 1;  
   
         /*  debug("cpu_run_init(): a_few_cycles = %i\n",  
             machine->a_few_cycles);  */  
494    
495          /*  For performance measurement:  */          /*  For performance measurement:  */
496          gettimeofday(&machine->starttime, NULL);          gettimeofday(&machine->starttime, NULL);
497            machine->ninstrs_since_gettimeofday = 0;
498  }  }
499    
500    
# Line 546  struct cpu_family *cpu_family_ptr_by_num Line 567  struct cpu_family *cpu_family_ptr_by_num
567   *  cpu_init():   *  cpu_init():
568   *   *
569   *  Should be called before any other cpu_*() function.   *  Should be called before any other cpu_*() function.
570     *
571     *  TODO: Make this nicer by moving out the conditional stuff to
572     *  an automagically generated file? Or a define in config.h?
573   */   */
574  void cpu_init(void)  void cpu_init(void)
575  {  {
576          /*  Note: These are registered in alphabetic order.  */          /*  Note: These are registered in alphabetic order.  */
577    
578    #ifdef ENABLE_ALPHA
579          add_cpu_family(alpha_cpu_family_init, ARCH_ALPHA);          add_cpu_family(alpha_cpu_family_init, ARCH_ALPHA);
580          add_cpu_family(hppa_cpu_family_init, ARCH_HPPA);  #endif
581    
582    #ifdef ENABLE_ARM
583            add_cpu_family(arm_cpu_family_init, ARCH_ARM);
584    #endif
585    
586    #ifdef ENABLE_AVR
587            add_cpu_family(avr_cpu_family_init, ARCH_AVR);
588    #endif
589    
590    #ifdef ENABLE_M68K
591            add_cpu_family(m68k_cpu_family_init, ARCH_M68K);
592    #endif
593    
594    #ifdef ENABLE_MIPS
595          add_cpu_family(mips_cpu_family_init, ARCH_MIPS);          add_cpu_family(mips_cpu_family_init, ARCH_MIPS);
596    #endif
597    
598    #ifdef ENABLE_PPC
599          add_cpu_family(ppc_cpu_family_init, ARCH_PPC);          add_cpu_family(ppc_cpu_family_init, ARCH_PPC);
600    #endif
601    
602    #ifdef ENABLE_SH
603            add_cpu_family(sh_cpu_family_init, ARCH_SH);
604    #endif
605    
606    #ifdef ENABLE_SPARC
607          add_cpu_family(sparc_cpu_family_init, ARCH_SPARC);          add_cpu_family(sparc_cpu_family_init, ARCH_SPARC);
608          add_cpu_family(urisc_cpu_family_init, ARCH_URISC);  #endif
609  }  }
610    

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

  ViewVC Help
Powered by ViewVC 1.1.26