25 |
* SUCH DAMAGE. |
* SUCH DAMAGE. |
26 |
* |
* |
27 |
* |
* |
28 |
* $Id: machine.c,v 1.679 2006/07/16 13:32:25 debug Exp $ |
* $Id: machine.c,v 1.689 2006/10/04 11:56:40 debug Exp $ |
29 |
*/ |
*/ |
30 |
|
|
31 |
#include <stdio.h> |
#include <stdio.h> |
49 |
#include "memory.h" |
#include "memory.h" |
50 |
#include "misc.h" |
#include "misc.h" |
51 |
#include "net.h" |
#include "net.h" |
52 |
|
#include "settings.h" |
53 |
#include "symbol.h" |
#include "symbol.h" |
54 |
|
|
55 |
|
|
78 |
|
|
79 |
memset(m, 0, sizeof(struct machine)); |
memset(m, 0, sizeof(struct machine)); |
80 |
|
|
81 |
/* Back pointer: */ |
/* Pointer back to the emul object that this machine belongs to: */ |
82 |
m->emul = emul; |
m->emul = emul; |
83 |
|
|
84 |
m->name = strdup(name); |
m->name = strdup(name); |
94 |
m->byte_order_override = NO_BYTE_ORDER_OVERRIDE; |
m->byte_order_override = NO_BYTE_ORDER_OVERRIDE; |
95 |
m->boot_kernel_filename = ""; |
m->boot_kernel_filename = ""; |
96 |
m->boot_string_argument = NULL; |
m->boot_string_argument = NULL; |
|
m->automatic_clock_adjustment = 1; |
|
97 |
m->x11_scaledown = 1; |
m->x11_scaledown = 1; |
98 |
m->x11_scaleup = 1; |
m->x11_scaleup = 1; |
99 |
m->n_gfx_cards = 1; |
m->n_gfx_cards = 1; |
101 |
m->show_symbolic_register_names = 1; |
m->show_symbolic_register_names = 1; |
102 |
symbol_init(&m->symbol_context); |
symbol_init(&m->symbol_context); |
103 |
|
|
104 |
|
/* Settings: */ |
105 |
|
m->settings = settings_new(); |
106 |
|
settings_add(m->settings, "name", 0, |
107 |
|
SETTINGS_TYPE_STRING, SETTINGS_FORMAT_STRING, |
108 |
|
(void *) &m->name); |
109 |
|
settings_add(m->settings, "serial_nr", 0, |
110 |
|
SETTINGS_TYPE_INT, SETTINGS_FORMAT_DECIMAL, |
111 |
|
(void *) &m->serial_nr); |
112 |
|
settings_add(m->settings, "arch_pagesize", 0, |
113 |
|
SETTINGS_TYPE_INT, SETTINGS_FORMAT_DECIMAL, |
114 |
|
(void *) &m->arch_pagesize); |
115 |
|
settings_add(m->settings, "prom_emulation", 0, |
116 |
|
SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, |
117 |
|
(void *) &m->prom_emulation); |
118 |
|
settings_add(m->settings, "allow_instruction_combinations", 0, |
119 |
|
SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, |
120 |
|
(void *) &m->allow_instruction_combinations); |
121 |
|
settings_add(m->settings, "n_gfx_cards", 0, |
122 |
|
SETTINGS_TYPE_INT, SETTINGS_FORMAT_DECIMAL, |
123 |
|
(void *) &m->n_gfx_cards); |
124 |
|
settings_add(m->settings, "show_symbolic_register_names", 1, |
125 |
|
SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, |
126 |
|
(void *) &m->show_symbolic_register_names); |
127 |
|
settings_add(m->settings, "statistics_enabled", 1, |
128 |
|
SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, |
129 |
|
(void *) &m->statistics_enabled); |
130 |
|
|
131 |
return m; |
return m; |
132 |
} |
} |
133 |
|
|
134 |
|
|
135 |
/* |
/* |
136 |
|
* machine_destroy(): |
137 |
|
* |
138 |
|
* Destroys a machine object. |
139 |
|
*/ |
140 |
|
void machine_destroy(struct machine *machine) |
141 |
|
{ |
142 |
|
int i; |
143 |
|
|
144 |
|
for (i=0; i<machine->ncpus; i++) |
145 |
|
cpu_destroy(machine->cpus[i]); |
146 |
|
|
147 |
|
if (machine->name != NULL) |
148 |
|
free(machine->name); |
149 |
|
|
150 |
|
/* Remove any remaining level-1 settings: */ |
151 |
|
settings_remove_all(machine->settings); |
152 |
|
settings_destroy(machine->settings); |
153 |
|
|
154 |
|
free(machine); |
155 |
|
} |
156 |
|
|
157 |
|
|
158 |
|
/* |
159 |
* machine_name_to_type(): |
* machine_name_to_type(): |
160 |
* |
* |
161 |
* Take a type and a subtype as strings, and convert them into numeric |
* Take a type and a subtype as strings, and convert them into numeric |
280 |
if (!machine->cycle_accurate) { |
if (!machine->cycle_accurate) { |
281 |
/* |
/* |
282 |
* The dyntrans subsystem wants to run code in relatively |
* The dyntrans subsystem wants to run code in relatively |
283 |
* large chunks without checking for external interrupts, |
* large chunks without checking for external interrupts; |
284 |
* so we cannot allow too low tickshifts: |
* too low tickshifts are not allowed. |
285 |
*/ |
*/ |
286 |
if (tickshift < N_SAFE_DYNTRANS_LIMIT_SHIFT) { |
if (tickshift < N_SAFE_DYNTRANS_LIMIT_SHIFT) { |
287 |
fatal("ERROR! tickshift = %i, less than " |
fatal("ERROR! tickshift = %i, less than " |
450 |
debug(", dbe_on_nonexistant_memaccess"); |
debug(", dbe_on_nonexistant_memaccess"); |
451 |
debug("\n"); |
debug("\n"); |
452 |
|
|
|
debug("clock: "); |
|
|
if (m->automatic_clock_adjustment) |
|
|
debug("adjusted automatically"); |
|
|
else |
|
|
debug("fixed at %i Hz", m->emulated_hz); |
|
|
debug("\n"); |
|
|
|
|
453 |
if (!m->prom_emulation) |
if (!m->prom_emulation) |
454 |
debug("PROM emulation disabled\n"); |
debug("PROM emulation disabled\n"); |
455 |
|
|
626 |
int store_32bit_word(struct cpu *cpu, uint64_t addr, uint64_t data32) |
int store_32bit_word(struct cpu *cpu, uint64_t addr, uint64_t data32) |
627 |
{ |
{ |
628 |
unsigned char data[4]; |
unsigned char data[4]; |
629 |
|
|
630 |
|
/* TODO: REMOVE THIS once everything is more stable! */ |
631 |
if (cpu->machine->arch == ARCH_MIPS && (addr >> 32) == 0) |
if (cpu->machine->arch == ARCH_MIPS && (addr >> 32) == 0) |
632 |
addr = (int64_t)(int32_t)addr; |
addr = (int64_t)(int32_t)addr; |
633 |
|
|
634 |
data[0] = (data32 >> 24) & 255; |
data[0] = (data32 >> 24) & 255; |
635 |
data[1] = (data32 >> 16) & 255; |
data[1] = (data32 >> 16) & 255; |
636 |
data[2] = (data32 >> 8) & 255; |
data[2] = (data32 >> 8) & 255; |
654 |
int store_16bit_word(struct cpu *cpu, uint64_t addr, uint64_t data16) |
int store_16bit_word(struct cpu *cpu, uint64_t addr, uint64_t data16) |
655 |
{ |
{ |
656 |
unsigned char data[2]; |
unsigned char data[2]; |
657 |
|
|
658 |
|
/* TODO: REMOVE THIS once everything is more stable! */ |
659 |
if (cpu->machine->arch == ARCH_MIPS && (addr >> 32) == 0) |
if (cpu->machine->arch == ARCH_MIPS && (addr >> 32) == 0) |
660 |
addr = (int64_t)(int32_t)addr; |
addr = (int64_t)(int32_t)addr; |
661 |
|
|
662 |
data[0] = (data16 >> 8) & 255; |
data[0] = (data16 >> 8) & 255; |
663 |
data[1] = (data16) & 255; |
data[1] = (data16) & 255; |
664 |
if (cpu->byte_order == EMUL_LITTLE_ENDIAN) { |
if (cpu->byte_order == EMUL_LITTLE_ENDIAN) { |
678 |
{ |
{ |
679 |
size_t psize = 1024; /* 1024 256 64 16 4 1 */ |
size_t psize = 1024; /* 1024 256 64 16 4 1 */ |
680 |
|
|
681 |
|
/* TODO: REMOVE THIS once everything is more stable! */ |
682 |
if (cpu->machine->arch == ARCH_MIPS && (addr >> 32) == 0) |
if (cpu->machine->arch == ARCH_MIPS && (addr >> 32) == 0) |
683 |
addr = (int64_t)(int32_t)addr; |
addr = (int64_t)(int32_t)addr; |
684 |
|
|
723 |
|
|
724 |
|
|
725 |
/* |
/* |
726 |
|
* load_64bit_word(): |
727 |
|
* |
728 |
|
* Helper function. Emulated byte order is taken into account. |
729 |
|
*/ |
730 |
|
uint64_t load_64bit_word(struct cpu *cpu, uint64_t addr) |
731 |
|
{ |
732 |
|
unsigned char data[8]; |
733 |
|
|
734 |
|
cpu->memory_rw(cpu, cpu->mem, |
735 |
|
addr, data, sizeof(data), MEM_READ, CACHE_DATA); |
736 |
|
|
737 |
|
if (cpu->byte_order == EMUL_LITTLE_ENDIAN) { |
738 |
|
int tmp = data[0]; data[0] = data[7]; data[7] = tmp; |
739 |
|
tmp = data[1]; data[1] = data[6]; data[6] = tmp; |
740 |
|
tmp = data[2]; data[2] = data[5]; data[5] = tmp; |
741 |
|
tmp = data[3]; data[3] = data[4]; data[4] = tmp; |
742 |
|
} |
743 |
|
|
744 |
|
return |
745 |
|
((uint64_t)data[0] << 56) + ((uint64_t)data[1] << 48) + |
746 |
|
((uint64_t)data[2] << 40) + ((uint64_t)data[3] << 32) + |
747 |
|
((uint64_t)data[4] << 24) + ((uint64_t)data[5] << 16) + |
748 |
|
((uint64_t)data[6] << 8) + (uint64_t)data[7]; |
749 |
|
} |
750 |
|
|
751 |
|
|
752 |
|
/* |
753 |
* load_32bit_word(): |
* load_32bit_word(): |
754 |
* |
* |
755 |
* Helper function. Prints a warning and returns 0, if the read failed. |
* Helper function. Emulated byte order is taken into account. |
|
* Emulated byte order is taken into account. |
|
756 |
*/ |
*/ |
757 |
uint32_t load_32bit_word(struct cpu *cpu, uint64_t addr) |
uint32_t load_32bit_word(struct cpu *cpu, uint64_t addr) |
758 |
{ |
{ |
759 |
unsigned char data[4]; |
unsigned char data[4]; |
760 |
|
|
761 |
|
/* TODO: REMOVE THIS once everything is more stable! */ |
762 |
if (cpu->machine->arch == ARCH_MIPS && (addr >> 32) == 0) |
if (cpu->machine->arch == ARCH_MIPS && (addr >> 32) == 0) |
763 |
addr = (int64_t)(int32_t)addr; |
addr = (int64_t)(int32_t)addr; |
764 |
|
|
765 |
cpu->memory_rw(cpu, cpu->mem, |
cpu->memory_rw(cpu, cpu->mem, |
766 |
addr, data, sizeof(data), MEM_READ, CACHE_DATA); |
addr, data, sizeof(data), MEM_READ, CACHE_DATA); |
767 |
|
|
777 |
/* |
/* |
778 |
* load_16bit_word(): |
* load_16bit_word(): |
779 |
* |
* |
780 |
* Helper function. Prints a warning and returns 0, if the read failed. |
* Helper function. Emulated byte order is taken into account. |
|
* Emulated byte order is taken into account. |
|
781 |
*/ |
*/ |
782 |
uint16_t load_16bit_word(struct cpu *cpu, uint64_t addr) |
uint16_t load_16bit_word(struct cpu *cpu, uint64_t addr) |
783 |
{ |
{ |
784 |
unsigned char data[2]; |
unsigned char data[2]; |
785 |
|
|
786 |
|
/* TODO: REMOVE THIS once everything is more stable! */ |
787 |
if (cpu->machine->arch == ARCH_MIPS && (addr >> 32) == 0) |
if (cpu->machine->arch == ARCH_MIPS && (addr >> 32) == 0) |
788 |
addr = (int64_t)(int32_t)addr; |
addr = (int64_t)(int32_t)addr; |
789 |
|
|
790 |
cpu->memory_rw(cpu, cpu->mem, |
cpu->memory_rw(cpu, cpu->mem, |
791 |
addr, data, sizeof(data), MEM_READ, CACHE_DATA); |
addr, data, sizeof(data), MEM_READ, CACHE_DATA); |
792 |
|
|
930 |
debug(" (%.2f MHz)", (float)machine->emulated_hz / 1000000); |
debug(" (%.2f MHz)", (float)machine->emulated_hz / 1000000); |
931 |
debug("\n"); |
debug("\n"); |
932 |
|
|
|
/* Default fake speed: 5 MHz */ |
|
|
if (machine->emulated_hz < 1) |
|
|
machine->emulated_hz = 5000000; |
|
|
|
|
933 |
if (machine->bootstr != NULL) { |
if (machine->bootstr != NULL) { |
934 |
debug("bootstring%s: %s", (machine->bootarg!=NULL && |
debug("bootstring%s: %s", (machine->bootarg!=NULL && |
935 |
strlen(machine->bootarg) >= 1)? "(+bootarg)" : "", |
strlen(machine->bootarg) >= 1)? "(+bootarg)" : "", |