25 |
* SUCH DAMAGE. |
* SUCH DAMAGE. |
26 |
* |
* |
27 |
* |
* |
28 |
* $Id: cpu.c,v 1.342 2006/06/22 13:27:03 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 |
*/ |
*/ |
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 |
|
|
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); |
93 |
"NULL\n"); |
"NULL\n"); |
94 |
exit(1); |
exit(1); |
95 |
} |
} |
96 |
return cpu; |
break; |
97 |
} |
} |
98 |
} |
} |
99 |
|
|
100 |
fp = fp->next; |
fp = fp->next; |
101 |
} |
} |
102 |
|
|
103 |
fatal("\ncpu_new(): unknown cpu type '%s'\n", cpu_type_name); |
if (fp == NULL) { |
104 |
return NULL; |
fatal("\ncpu_new(): unknown cpu type '%s'\n", cpu_type_name); |
105 |
|
return NULL; |
106 |
|
} |
107 |
|
|
108 |
|
fp->init_tables(cpu); |
109 |
|
|
110 |
|
return cpu; |
111 |
} |
} |
112 |
|
|
113 |
|
|
326 |
|
|
327 |
|
|
328 |
/* |
/* |
|
* cpu_run(): |
|
|
* |
|
|
* Run instructions on all CPUs in this machine, for a "medium duration" |
|
|
* (or until all CPUs have halted). |
|
|
* |
|
|
* Return value is 1 if anything happened, 0 if all CPUs are stopped. |
|
|
*/ |
|
|
int cpu_run(struct emul *emul, struct machine *m) |
|
|
{ |
|
|
if (m->cpu_family == NULL || m->cpu_family->run == NULL) { |
|
|
fatal("cpu_run(): NULL\n"); |
|
|
return 0; |
|
|
} else |
|
|
return m->cpu_family->run(emul, m); |
|
|
} |
|
|
|
|
|
|
|
|
/* |
|
329 |
* cpu_dumpinfo(): |
* cpu_dumpinfo(): |
330 |
* |
* |
331 |
* Dumps info about a CPU using debug(). "cpu0: CPUNAME, running" (or similar) |
* Dumps info about a CPU using debug(). "cpu0: CPUNAME, running" (or similar) |
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], |
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); |
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; |
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; |
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 |
|
|
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 |