25 |
* SUCH DAMAGE. |
* SUCH DAMAGE. |
26 |
* |
* |
27 |
* |
* |
28 |
* $Id: machine.c,v 1.671 2006/06/16 18:31:24 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> |
32 |
#include <stdlib.h> |
#include <stdlib.h> |
33 |
#include <stdarg.h> |
#include <stdarg.h> |
|
#ifdef SOLARIS |
|
|
/* TODO: is this strings vs string separation really necessary? */ |
|
|
#include <strings.h> |
|
|
#else |
|
34 |
#include <string.h> |
#include <string.h> |
|
#endif |
|
35 |
#include <time.h> |
#include <time.h> |
36 |
#include <unistd.h> |
#include <unistd.h> |
37 |
|
|
39 |
#include "bus_isa.h" |
#include "bus_isa.h" |
40 |
#include "bus_pci.h" |
#include "bus_pci.h" |
41 |
#include "cpu.h" |
#include "cpu.h" |
42 |
|
#include "debugger.h" |
43 |
#include "device.h" |
#include "device.h" |
44 |
#include "devices.h" |
#include "devices.h" |
45 |
#include "diskimage.h" |
#include "diskimage.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); |
89 |
m->machine_subtype = MACHINE_NONE; |
m->machine_subtype = MACHINE_NONE; |
90 |
m->arch_pagesize = 4096; /* Should be overriden in |
m->arch_pagesize = 4096; /* Should be overriden in |
91 |
emul.c for other pagesizes. */ |
emul.c for other pagesizes. */ |
|
m->dyntrans_alignment_check = 1; |
|
92 |
m->prom_emulation = 1; |
m->prom_emulation = 1; |
93 |
m->speed_tricks = 1; |
m->allow_instruction_combinations = 1; |
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 " |
302 |
|
|
303 |
|
|
304 |
/* |
/* |
305 |
|
* machine_statistics_init(): |
306 |
|
* |
307 |
|
* Initialize the parts of a machine struct that deal with instruction |
308 |
|
* statistics gathering. |
309 |
|
* |
310 |
|
* Note: The fname argument contains "flags:filename". |
311 |
|
*/ |
312 |
|
void machine_statistics_init(struct machine *machine, char *fname) |
313 |
|
{ |
314 |
|
int n_fields = 0; |
315 |
|
char *pcolon = fname; |
316 |
|
char *mode = "a"; /* Append by default */ |
317 |
|
|
318 |
|
machine->allow_instruction_combinations = 0; |
319 |
|
|
320 |
|
if (machine->statistics_fields != NULL) { |
321 |
|
fprintf(stderr, "Only one -s option is allowed.\n"); |
322 |
|
exit(1); |
323 |
|
} |
324 |
|
|
325 |
|
machine->statistics_fields = malloc(MAX_STATISTICS_FIELDS + 1); |
326 |
|
machine->statistics_enabled = 1; |
327 |
|
|
328 |
|
while (*pcolon && *pcolon != ':') |
329 |
|
pcolon ++; |
330 |
|
|
331 |
|
if (*pcolon != ':') { |
332 |
|
fprintf(stderr, "The syntax for the -s option is: " |
333 |
|
"-s flags:filename\nYou omitted the flags. Run g" |
334 |
|
"xemul -h for a list of available flags.\n"); |
335 |
|
exit(1); |
336 |
|
} |
337 |
|
|
338 |
|
while (*fname != ':') { |
339 |
|
switch (*fname) { |
340 |
|
|
341 |
|
/* Type flags: */ |
342 |
|
case 'v': |
343 |
|
case 'i': |
344 |
|
case 'p': |
345 |
|
machine->statistics_fields[n_fields ++] = *fname; |
346 |
|
if (n_fields >= MAX_STATISTICS_FIELDS) { |
347 |
|
fprintf(stderr, "Internal error: Too many " |
348 |
|
"statistics fields used. Increase " |
349 |
|
"MAX_STATISTICS_FIELDS.\n"); |
350 |
|
exit(1); |
351 |
|
} |
352 |
|
machine->statistics_fields[n_fields] = '\0'; |
353 |
|
break; |
354 |
|
|
355 |
|
/* Optional flags: */ |
356 |
|
case 'o': |
357 |
|
mode = "w"; |
358 |
|
break; |
359 |
|
case 'd': |
360 |
|
machine->statistics_enabled = 0; |
361 |
|
break; |
362 |
|
|
363 |
|
default:fprintf(stderr, "Unknown flag '%c' used with the" |
364 |
|
" -s option. Aborting.\n", *fname); |
365 |
|
exit(1); |
366 |
|
} |
367 |
|
fname ++; |
368 |
|
} |
369 |
|
|
370 |
|
fname ++; /* point to the filename after the colon */ |
371 |
|
|
372 |
|
machine->statistics_filename = strdup(fname); |
373 |
|
machine->statistics_file = fopen(machine->statistics_filename, mode); |
374 |
|
} |
375 |
|
|
376 |
|
|
377 |
|
/* |
378 |
* machine_bus_register(): |
* machine_bus_register(): |
379 |
* |
* |
380 |
* Registers a bus in a machine. |
* Registers a bus in a machine. |
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)" : "", |
1039 |
} |
} |
1040 |
|
|
1041 |
|
|
1042 |
|
/*****************************************************************************/ |
1043 |
|
|
1044 |
|
|
1045 |
|
/* |
1046 |
|
* machine_run(): |
1047 |
|
* |
1048 |
|
* Run one or more instructions on all CPUs in this machine. (Usually, |
1049 |
|
* around N_SAFE_DYNTRANS_LIMIT instructions will be run by the dyntrans |
1050 |
|
* system.) |
1051 |
|
* |
1052 |
|
* Return value is 1 if any CPU in this machine is still running, |
1053 |
|
* or 0 if all CPUs are stopped. |
1054 |
|
*/ |
1055 |
|
int machine_run(struct machine *machine) |
1056 |
|
{ |
1057 |
|
struct cpu **cpus = machine->cpus; |
1058 |
|
int ncpus = machine->ncpus, cpu0instrs = 0, i, te; |
1059 |
|
|
1060 |
|
for (i=0; i<ncpus; i++) { |
1061 |
|
if (cpus[i]->running) { |
1062 |
|
int instrs_run = cpus[i]->run_instr(cpus[i]); |
1063 |
|
if (i == 0) |
1064 |
|
cpu0instrs += instrs_run; |
1065 |
|
} |
1066 |
|
} |
1067 |
|
|
1068 |
|
/* |
1069 |
|
* Hardware 'ticks': (clocks, interrupt sources...) |
1070 |
|
* |
1071 |
|
* Here, cpu0instrs is the number of instructions executed on cpu0. |
1072 |
|
* |
1073 |
|
* TODO: This should be redesigned into some "mainbus" stuff instead! |
1074 |
|
*/ |
1075 |
|
|
1076 |
|
machine->ninstrs += cpu0instrs; |
1077 |
|
|
1078 |
|
for (te=0; te<machine->n_tick_entries; te++) { |
1079 |
|
machine->ticks_till_next[te] -= cpu0instrs; |
1080 |
|
if (machine->ticks_till_next[te] <= 0) { |
1081 |
|
while (machine->ticks_till_next[te] <= 0) { |
1082 |
|
machine->ticks_till_next[te] += |
1083 |
|
machine->ticks_reset_value[te]; |
1084 |
|
} |
1085 |
|
|
1086 |
|
machine->tick_func[te](cpus[0], |
1087 |
|
machine->tick_extra[te]); |
1088 |
|
} |
1089 |
|
} |
1090 |
|
|
1091 |
|
/* Is any CPU still alive? */ |
1092 |
|
for (i=0; i<ncpus; i++) |
1093 |
|
if (cpus[i]->running) |
1094 |
|
return 1; |
1095 |
|
|
1096 |
|
return 0; |
1097 |
|
} |
1098 |
|
|
1099 |
|
|
1100 |
|
/*****************************************************************************/ |
1101 |
|
|
1102 |
|
|
1103 |
/* |
/* |
1104 |
* machine_entry_new(): |
* machine_entry_new(): |
1105 |
* |
* |
1106 |
* This function creates a new machine_entry struct, and fills it with some |
* This function creates a new machine_entry struct, and fills it with some |
1107 |
* valid data; it is up to the caller to add additional data that weren't |
* valid data; it is up to the caller to add additional data that weren't |
1108 |
* passed as arguments to this function. |
* passed as arguments to this function, such as alias names and machine |
1109 |
|
* subtypes. |
1110 |
*/ |
*/ |
1111 |
struct machine_entry *machine_entry_new(const char *name, |
struct machine_entry *machine_entry_new(const char *name, int arch, |
1112 |
int arch, int oldstyle_type, int n_aliases, int n_subtypes) |
int oldstyle_type) |
1113 |
{ |
{ |
1114 |
struct machine_entry *me; |
struct machine_entry *me; |
1115 |
|
|
1124 |
me->name = name; |
me->name = name; |
1125 |
me->arch = arch; |
me->arch = arch; |
1126 |
me->machine_type = oldstyle_type; |
me->machine_type = oldstyle_type; |
1127 |
me->n_aliases = n_aliases; |
me->n_aliases = 0; |
1128 |
me->aliases = malloc(sizeof(char *) * n_aliases); |
me->aliases = NULL; |
1129 |
if (me->aliases == NULL) { |
me->n_subtypes = 0; |
|
fprintf(stderr, "machine_entry_new(): out of memory (2)\n"); |
|
|
exit(1); |
|
|
} |
|
|
me->n_subtypes = n_subtypes; |
|
1130 |
me->setup = NULL; |
me->setup = NULL; |
1131 |
|
|
1132 |
if (n_subtypes > 0) { |
return me; |
1133 |
me->subtype = malloc(sizeof(struct machine_entry_subtype *) * |
} |
1134 |
n_subtypes); |
|
1135 |
if (me->subtype == NULL) { |
|
1136 |
fprintf(stderr, "machine_entry_new(): out of " |
/* |
1137 |
"memory (3)\n"); |
* machine_entry_add_alias(): |
1138 |
exit(1); |
* |
1139 |
} |
* This function adds an "alias" to a machine entry. |
1140 |
|
*/ |
1141 |
|
void machine_entry_add_alias(struct machine_entry *me, const char *name) |
1142 |
|
{ |
1143 |
|
me->n_aliases ++; |
1144 |
|
me->aliases = realloc(me->aliases, sizeof(char *) * me->n_aliases); |
1145 |
|
if (me->aliases == NULL) { |
1146 |
|
fprintf(stderr, "out of memory\n"); |
1147 |
|
exit(1); |
1148 |
} |
} |
1149 |
|
|
1150 |
return me; |
me->aliases[me->n_aliases - 1] = (char *) name; |
1151 |
} |
} |
1152 |
|
|
1153 |
|
|
1154 |
/* |
/* |
1155 |
* machine_entry_subtype_new(): |
* machine_entry_add_subtype(): |
1156 |
* |
* |
1157 |
* This function creates a new machine_entry_subtype struct, and fills it with |
* This function adds a subtype to a machine entry. The argument list after |
1158 |
* some valid data; it is up to the caller to add additional data that weren't |
* oldstyle_subtype is a list of one or more char *, followed by NULL. E.g.: |
|
* passed as arguments to this function. |
|
1159 |
* |
* |
1160 |
* For internal use. |
* machine_entry_add_subtype(me, "Machine X", MACHINE_X, |
1161 |
|
* "machine-x", "x", NULL); |
1162 |
*/ |
*/ |
1163 |
struct machine_entry_subtype *machine_entry_subtype_new( |
void machine_entry_add_subtype(struct machine_entry *me, const char *name, |
1164 |
const char *name, int oldstyle_type, int n_aliases) |
int oldstyle_subtype, ...) |
1165 |
{ |
{ |
1166 |
|
va_list argp; |
1167 |
struct machine_entry_subtype *mes; |
struct machine_entry_subtype *mes; |
1168 |
|
|
1169 |
|
/* Allocate a new subtype struct: */ |
1170 |
mes = malloc(sizeof(struct machine_entry_subtype)); |
mes = malloc(sizeof(struct machine_entry_subtype)); |
1171 |
if (mes == NULL) { |
if (mes == NULL) { |
1172 |
fprintf(stderr, "machine_entry_subtype_new(): out " |
fprintf(stderr, "machine_entry_subtype_new(): out " |
1174 |
exit(1); |
exit(1); |
1175 |
} |
} |
1176 |
|
|
1177 |
|
/* Add the subtype to the machine entry: */ |
1178 |
|
me->n_subtypes ++; |
1179 |
|
me->subtype = realloc(me->subtype, sizeof(struct |
1180 |
|
machine_entry_subtype *) * me->n_subtypes); |
1181 |
|
if (me->subtype == NULL) { |
1182 |
|
fprintf(stderr, "out of memory\n"); |
1183 |
|
exit(1); |
1184 |
|
} |
1185 |
|
me->subtype[me->n_subtypes - 1] = mes; |
1186 |
|
|
1187 |
|
/* Fill the struct with subtype data: */ |
1188 |
memset(mes, 0, sizeof(struct machine_entry_subtype)); |
memset(mes, 0, sizeof(struct machine_entry_subtype)); |
1189 |
mes->name = name; |
mes->name = name; |
1190 |
mes->machine_subtype = oldstyle_type; |
mes->machine_subtype = oldstyle_subtype; |
1191 |
mes->n_aliases = n_aliases; |
|
1192 |
mes->aliases = malloc(sizeof(char *) * n_aliases); |
/* ... and all aliases: */ |
1193 |
if (mes->aliases == NULL) { |
mes->n_aliases = 0; |
1194 |
fprintf(stderr, "machine_entry_subtype_new(): " |
mes->aliases = NULL; |
1195 |
"out of memory (2)\n"); |
|
1196 |
exit(1); |
va_start(argp, oldstyle_subtype); |
1197 |
|
|
1198 |
|
for (;;) { |
1199 |
|
char *s = va_arg(argp, char *); |
1200 |
|
if (s == NULL) |
1201 |
|
break; |
1202 |
|
|
1203 |
|
mes->n_aliases ++; |
1204 |
|
mes->aliases = realloc(mes->aliases, sizeof(char *) * |
1205 |
|
mes->n_aliases); |
1206 |
|
if (mes->aliases == NULL) { |
1207 |
|
fprintf(stderr, "out of memory\n"); |
1208 |
|
exit(1); |
1209 |
|
} |
1210 |
|
|
1211 |
|
mes->aliases[mes->n_aliases - 1] = s; |
1212 |
} |
} |
1213 |
|
|
1214 |
return mes; |
va_end(argp); |
1215 |
} |
} |
1216 |
|
|
1217 |
|
|
1218 |
/* |
/* |
1219 |
* machine_entry_add(): |
* machine_entry_register(): |
1220 |
* |
* |
1221 |
* Inserts a new machine_entry into the machine entries list. |
* Inserts a new machine_entry into the machine entries list. |
1222 |
*/ |
*/ |
1223 |
void machine_entry_add(struct machine_entry *me, int arch) |
void machine_entry_register(struct machine_entry *me, int arch) |
1224 |
{ |
{ |
1225 |
struct machine_entry *prev, *next; |
struct machine_entry *prev, *next; |
1226 |
|
|