1 |
#ifndef MACHINE_H |
2 |
#define MACHINE_H |
3 |
|
4 |
/* |
5 |
* Copyright (C) 2005-2007 Anders Gavare. All rights reserved. |
6 |
* |
7 |
* Redistribution and use in source and binary forms, with or without |
8 |
* modification, are permitted provided that the following conditions are met: |
9 |
* |
10 |
* 1. Redistributions of source code must retain the above copyright |
11 |
* notice, this list of conditions and the following disclaimer. |
12 |
* 2. Redistributions in binary form must reproduce the above copyright |
13 |
* notice, this list of conditions and the following disclaimer in the |
14 |
* documentation and/or other materials provided with the distribution. |
15 |
* 3. The name of the author may not be used to endorse or promote products |
16 |
* derived from this software without specific prior written permission. |
17 |
* |
18 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
19 |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
20 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
21 |
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
22 |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
23 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
24 |
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
25 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
26 |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
27 |
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
28 |
* SUCH DAMAGE. |
29 |
* |
30 |
* |
31 |
* $Id: machine.h,v 1.162 2007/04/19 15:18:16 debug Exp $ |
32 |
*/ |
33 |
|
34 |
#include <sys/types.h> |
35 |
#include <sys/time.h> |
36 |
|
37 |
#include "symbol.h" |
38 |
|
39 |
#include "machine_arc.h" |
40 |
#include "machine_pmax.h" |
41 |
|
42 |
|
43 |
#define MAX_BREAKPOINTS 8 |
44 |
|
45 |
#define MAX_TICK_FUNCTIONS 16 |
46 |
|
47 |
#define MAX_STATISTICS_FIELDS 8 |
48 |
|
49 |
struct cpu_family; |
50 |
struct diskimage; |
51 |
struct emul; |
52 |
struct fb_window; |
53 |
struct memory; |
54 |
struct of_data; |
55 |
struct settings; |
56 |
|
57 |
|
58 |
/* TODO: This should probably go away... */ |
59 |
struct isa_pic_data { |
60 |
struct pic8259_data *pic1; |
61 |
struct pic8259_data *pic2; |
62 |
|
63 |
int *pending_timer_interrupts; |
64 |
int last_int; |
65 |
}; |
66 |
|
67 |
|
68 |
struct machine { |
69 |
/* Pointer back to the emul struct we are in: */ |
70 |
struct emul *emul; |
71 |
|
72 |
/* Settings: */ |
73 |
struct settings *settings; |
74 |
|
75 |
/* Name as choosen by the user: */ |
76 |
char *name; |
77 |
|
78 |
/* Full "path" to the machine, e.g. "emul[0].machine[0]": */ |
79 |
char *path; |
80 |
|
81 |
int arch; /* ARCH_MIPS, ARCH_PPC, .. */ |
82 |
int machine_type; /* MACHINE_PMAX, .. */ |
83 |
int machine_subtype; /* MACHINE_DEC_3MAX_5000, .. */ |
84 |
|
85 |
/* NOTE/TODO: This isn't working yet: */ |
86 |
int cycle_accurate; /* Set to non-zero for cycle |
87 |
accurate (slow) emulation. */ |
88 |
|
89 |
/* Name set by code in src/machines/machine_*.c: */ |
90 |
char *machine_name; |
91 |
|
92 |
int stable; /* startup warning for non-stable |
93 |
emulation modes. */ |
94 |
|
95 |
/* The serial number is mostly used when emulating multiple machines |
96 |
in a network. nr_of_nics is the current nr of network cards, which |
97 |
is useful when emulating multiple cards in one machine: */ |
98 |
int serial_nr; |
99 |
int nr_of_nics; |
100 |
|
101 |
/* TODO: How about multiple cpu familys in one machine? */ |
102 |
struct cpu_family *cpu_family; |
103 |
|
104 |
/* |
105 |
* The "mainbus": |
106 |
* |
107 |
* o) memory |
108 |
* o) devices |
109 |
* o) CPUs |
110 |
*/ |
111 |
|
112 |
struct memory *memory; |
113 |
|
114 |
int main_console_handle; |
115 |
|
116 |
/* Hardware devices, run every x clock cycles. */ |
117 |
int n_tick_entries; |
118 |
int ticks_till_next[MAX_TICK_FUNCTIONS]; |
119 |
int ticks_reset_value[MAX_TICK_FUNCTIONS]; |
120 |
void (*tick_func[MAX_TICK_FUNCTIONS])(struct cpu *, void *); |
121 |
void *tick_extra[MAX_TICK_FUNCTIONS]; |
122 |
double tick_hz[MAX_TICK_FUNCTIONS]; |
123 |
|
124 |
char *cpu_name; /* TODO: remove this, there could be several |
125 |
cpus with different names in a machine */ |
126 |
int byte_order_override; |
127 |
int bootstrap_cpu; |
128 |
int use_random_bootstrap_cpu; |
129 |
int start_paused; |
130 |
int ncpus; |
131 |
struct cpu **cpus; |
132 |
|
133 |
/* These are used by stuff in cpu.c, mostly: */ |
134 |
/* TODO: Move to cpu.h! */ |
135 |
int64_t ninstrs; |
136 |
int64_t ninstrs_show; |
137 |
int64_t ninstrs_flush; |
138 |
int64_t ninstrs_since_gettimeofday; |
139 |
struct timeval starttime; |
140 |
|
141 |
struct diskimage *first_diskimage; |
142 |
|
143 |
struct symbol_context symbol_context; |
144 |
|
145 |
int random_mem_contents; |
146 |
int physical_ram_in_mb; |
147 |
int memory_offset_in_mb; |
148 |
int prom_emulation; |
149 |
int register_dump; |
150 |
int arch_pagesize; |
151 |
|
152 |
int bootdev_type; |
153 |
int bootdev_id; |
154 |
char *bootstr; |
155 |
char *bootarg; |
156 |
|
157 |
/* Breakpoints: */ |
158 |
int n_breakpoints; |
159 |
char *breakpoint_string[MAX_BREAKPOINTS]; |
160 |
uint64_t breakpoint_addr[MAX_BREAKPOINTS]; |
161 |
int breakpoint_flags[MAX_BREAKPOINTS]; |
162 |
|
163 |
/* Cache sizes: (1 << x) x=0 for default values */ |
164 |
/* TODO: these should be _PER CPU_! */ |
165 |
int cache_picache; |
166 |
int cache_pdcache; |
167 |
int cache_secondary; |
168 |
int cache_picache_linesize; |
169 |
int cache_pdcache_linesize; |
170 |
int cache_secondary_linesize; |
171 |
|
172 |
int dbe_on_nonexistant_memaccess; |
173 |
int halt_on_nonexistant_memaccess; |
174 |
int instruction_trace; |
175 |
int show_nr_of_instructions; |
176 |
int show_trace_tree; |
177 |
int show_symbolic_register_names; |
178 |
int emulated_hz; |
179 |
int allow_instruction_combinations; |
180 |
char *userland_emul; /* NULL for no userland emulation */ |
181 |
int force_netboot; |
182 |
int slow_serial_interrupts_hack_for_linux; |
183 |
uint64_t file_loaded_end_addr; |
184 |
char *boot_kernel_filename; |
185 |
char *boot_string_argument; |
186 |
int exit_without_entering_debugger; |
187 |
int n_gfx_cards; |
188 |
|
189 |
/* Instruction statistics: */ |
190 |
char *statistics_filename; |
191 |
FILE *statistics_file; |
192 |
int statistics_enabled; |
193 |
char *statistics_fields; /* "vpi" etc. */ |
194 |
|
195 |
/* Machine-dependent: (PROM stuff, etc.) */ |
196 |
union { |
197 |
struct machine_arcbios arc; |
198 |
struct machine_pmax pmax; |
199 |
struct of_data *of_data; |
200 |
} md; |
201 |
|
202 |
/* Bus-specific interrupt data: */ |
203 |
/* TODO: Remove! */ |
204 |
struct isa_pic_data isa_pic_data; |
205 |
|
206 |
/* X11/framebuffer stuff: */ |
207 |
int use_x11; |
208 |
int x11_scaledown; |
209 |
int x11_scaleup; |
210 |
int x11_n_display_names; |
211 |
char **x11_display_names; |
212 |
int x11_current_display_name_nr; /* updated by x11.c */ |
213 |
|
214 |
int n_fb_windows; |
215 |
struct fb_window **fb_windows; |
216 |
}; |
217 |
|
218 |
|
219 |
/* Tick function "prototype": */ |
220 |
#define DEVICE_TICK(x) void dev_ ## x ## _tick(struct cpu *cpu, void *extra) |
221 |
|
222 |
|
223 |
/* |
224 |
* Machine emulation types: |
225 |
*/ |
226 |
|
227 |
#define ARCH_NOARCH 0 |
228 |
#define ARCH_MIPS 1 |
229 |
#define ARCH_PPC 2 |
230 |
#define ARCH_SPARC 3 |
231 |
#define ARCH_ALPHA 4 |
232 |
#define ARCH_ARM 5 |
233 |
#define ARCH_SH 6 |
234 |
#define ARCH_AVR 7 |
235 |
#define ARCH_M88K 8 |
236 |
|
237 |
/* MIPS: */ |
238 |
#define MACHINE_BAREMIPS 1000 |
239 |
#define MACHINE_TESTMIPS 1001 |
240 |
#define MACHINE_PMAX 1002 |
241 |
#define MACHINE_COBALT 1003 |
242 |
#define MACHINE_HPCMIPS 1004 |
243 |
#define MACHINE_PS2 1005 |
244 |
#define MACHINE_SGI 1006 |
245 |
#define MACHINE_ARC 1007 |
246 |
#define MACHINE_NETGEAR 1008 |
247 |
#define MACHINE_SONYNEWS 1009 |
248 |
#define MACHINE_EVBMIPS 1010 |
249 |
#define MACHINE_PSP 1011 |
250 |
#define MACHINE_ALGOR 1012 |
251 |
#define MACHINE_QEMU_MIPS 1013 |
252 |
|
253 |
/* PPC: */ |
254 |
#define MACHINE_BAREPPC 2000 |
255 |
#define MACHINE_TESTPPC 2001 |
256 |
#define MACHINE_PMPPC 2002 |
257 |
#define MACHINE_SANDPOINT 2003 |
258 |
#define MACHINE_BEBOX 2004 |
259 |
#define MACHINE_PREP 2005 |
260 |
#define MACHINE_MACPPC 2006 |
261 |
#define MACHINE_MVMEPPC 2007 |
262 |
|
263 |
/* SPARC: */ |
264 |
#define MACHINE_BARESPARC 3000 |
265 |
#define MACHINE_TESTSPARC 3001 |
266 |
#define MACHINE_SPARC 3002 |
267 |
|
268 |
/* Alpha: */ |
269 |
#define MACHINE_BAREALPHA 4000 |
270 |
#define MACHINE_TESTALPHA 4001 |
271 |
#define MACHINE_ALPHA 4002 |
272 |
|
273 |
/* ARM: */ |
274 |
#define MACHINE_BAREARM 5000 |
275 |
#define MACHINE_TESTARM 5001 |
276 |
#define MACHINE_CATS 5002 |
277 |
#define MACHINE_HPCARM 5003 |
278 |
#define MACHINE_ZAURUS 5004 |
279 |
#define MACHINE_NETWINDER 5005 |
280 |
#define MACHINE_SHARK 5006 |
281 |
#define MACHINE_IQ80321 5007 |
282 |
#define MACHINE_IYONIX 5008 |
283 |
#define MACHINE_QEMU_ARM 5009 |
284 |
|
285 |
/* SH: */ |
286 |
#define MACHINE_BARESH 6000 |
287 |
#define MACHINE_TESTSH 6001 |
288 |
#define MACHINE_HPCSH 6002 |
289 |
#define MACHINE_DREAMCAST 6003 |
290 |
#define MACHINE_LANDISK 6004 |
291 |
|
292 |
/* AVR: */ |
293 |
#define MACHINE_BAREAVR 7000 |
294 |
#define MACHINE_AVR_PAL 7001 |
295 |
#define MACHINE_AVR_MAHPONG 7002 |
296 |
|
297 |
/* M88K: */ |
298 |
#define MACHINE_BAREM88K 8000 |
299 |
#define MACHINE_TESTM88K 8001 |
300 |
|
301 |
/* Other "pseudo"-machines: */ |
302 |
#define MACHINE_NONE 0 |
303 |
#define MACHINE_USERLAND 100000 |
304 |
|
305 |
/* DEC: */ |
306 |
#define MACHINE_DEC_PMAX_3100 1 |
307 |
#define MACHINE_DEC_3MAX_5000 2 |
308 |
#define MACHINE_DEC_3MIN_5000 3 |
309 |
#define MACHINE_DEC_3MAXPLUS_5000 4 |
310 |
#define MACHINE_DEC_5800 5 |
311 |
#define MACHINE_DEC_5400 6 |
312 |
#define MACHINE_DEC_MAXINE_5000 7 |
313 |
#define MACHINE_DEC_5500 11 |
314 |
#define MACHINE_DEC_MIPSMATE_5100 12 |
315 |
|
316 |
#define DEC_PROM_CALLBACK_STRUCT 0xffffffffbfc04000ULL |
317 |
#define DEC_PROM_EMULATION 0xffffffffbfc08000ULL |
318 |
#define DEC_PROM_INITIAL_ARGV (INITIAL_STACK_POINTER + 0x80) |
319 |
#define DEC_PROM_STRINGS 0xffffffffbfc20000ULL |
320 |
#define DEC_PROM_TCINFO 0xffffffffbfc2c000ULL |
321 |
#define DEC_MEMMAP_ADDR 0xffffffffbfc30000ULL |
322 |
|
323 |
/* HPCmips: */ |
324 |
#define MACHINE_HPCMIPS_CASIO_BE300 1 |
325 |
#define MACHINE_HPCMIPS_CASIO_E105 2 |
326 |
#define MACHINE_HPCMIPS_NEC_MOBILEPRO_770 3 |
327 |
#define MACHINE_HPCMIPS_NEC_MOBILEPRO_780 4 |
328 |
#define MACHINE_HPCMIPS_NEC_MOBILEPRO_800 5 |
329 |
#define MACHINE_HPCMIPS_NEC_MOBILEPRO_880 6 |
330 |
#define MACHINE_HPCMIPS_AGENDA_VR3 7 |
331 |
#define MACHINE_HPCMIPS_IBM_WORKPAD_Z50 8 |
332 |
|
333 |
/* HPCarm: */ |
334 |
#define MACHINE_HPCARM_IPAQ 1 |
335 |
#define MACHINE_HPCARM_JORNADA720 2 |
336 |
|
337 |
/* HPCsh: */ |
338 |
#define MACHINE_HPCSH_JORNADA680 1 |
339 |
#define MACHINE_HPCSH_JORNADA690 2 |
340 |
|
341 |
/* SGI and ARC: */ |
342 |
#define MACHINE_ARC_NEC_RD94 1 |
343 |
#define MACHINE_ARC_JAZZ_PICA 2 |
344 |
#define MACHINE_ARC_NEC_R94 3 |
345 |
#define MACHINE_ARC_DESKTECH_TYNE 4 |
346 |
#define MACHINE_ARC_JAZZ_MAGNUM 5 |
347 |
#define MACHINE_ARC_NEC_R98 6 |
348 |
#define MACHINE_ARC_JAZZ_M700 7 |
349 |
#define MACHINE_ARC_NEC_R96 8 |
350 |
|
351 |
/* Algor: */ |
352 |
#define MACHINE_ALGOR_P4032 4 |
353 |
#define MACHINE_ALGOR_P5064 5 |
354 |
|
355 |
/* EVBMIPS: */ |
356 |
#define MACHINE_EVBMIPS_MALTA 1 |
357 |
#define MACHINE_EVBMIPS_MALTA_BE 2 |
358 |
|
359 |
/* PReP: */ |
360 |
#define MACHINE_PREP_IBM6050 1 |
361 |
#define MACHINE_PREP_MVME2400 2 |
362 |
|
363 |
/* Sun SPARC: */ |
364 |
#define MACHINE_SPARC_SS5 1 |
365 |
#define MACHINE_SPARC_SS20 2 |
366 |
#define MACHINE_SPARC_ULTRA1 3 |
367 |
#define MACHINE_SPARC_ULTRA60 4 |
368 |
#define MACHINE_SPARC_SUN4V 5 |
369 |
|
370 |
/* MacPPC: TODO: Real model names */ |
371 |
#define MACHINE_MACPPC_G3 1 |
372 |
#define MACHINE_MACPPC_G4 2 |
373 |
#define MACHINE_MACPPC_G5 3 |
374 |
|
375 |
/* MVMEPPC */ |
376 |
#define MACHINE_MVMEPPC_1600 1 |
377 |
#define MACHINE_MVMEPPC_2100 2 |
378 |
#define MACHINE_MVMEPPC_5500 3 |
379 |
|
380 |
|
381 |
/* For the automachine system: */ |
382 |
struct machine_entry_subtype { |
383 |
int machine_subtype;/* Old-style subtype */ |
384 |
const char *name; /* Official name */ |
385 |
int n_aliases; |
386 |
char **aliases; /* Aliases */ |
387 |
}; |
388 |
|
389 |
struct machine_entry { |
390 |
struct machine_entry *next; |
391 |
|
392 |
/* Machine type: */ |
393 |
int arch; |
394 |
int machine_type; /* Old-style type */ |
395 |
const char *name; /* Official name */ |
396 |
int n_aliases; |
397 |
char **aliases; /* Aliases */ |
398 |
|
399 |
void (*setup)(struct machine *, struct cpu *); |
400 |
void (*set_default_cpu)(struct machine *); |
401 |
void (*set_default_ram)(struct machine *); |
402 |
|
403 |
/* Machine subtypes: */ |
404 |
int n_subtypes; |
405 |
struct machine_entry_subtype **subtype; |
406 |
}; |
407 |
|
408 |
#define MACHINE_SETUP_TYPE(n) void (*n)(struct machine *, struct cpu *) |
409 |
#define MACHINE_SETUP(x) void machine_setup_ ## x(struct machine *machine, \ |
410 |
struct cpu *cpu) |
411 |
#define MACHINE_DEFAULT_CPU(x) void machine_default_cpu_ ## x(struct machine *machine) |
412 |
#define MACHINE_DEFAULT_RAM(x) void machine_default_ram_ ## x(struct machine *machine) |
413 |
#define MACHINE_REGISTER(x) void machine_register_ ## x(void) |
414 |
#define MR_DEFAULT(x,name,arch,type) struct machine_entry \ |
415 |
*me = machine_entry_new(name,arch,type); \ |
416 |
me->setup = machine_setup_ ## x; \ |
417 |
me->set_default_cpu = machine_default_cpu_ ## x; \ |
418 |
machine_entry_register(me, arch); |
419 |
void automachine_init(void); |
420 |
|
421 |
|
422 |
/* machine.c: */ |
423 |
struct machine *machine_new(char *name, struct emul *emul, int id); |
424 |
void machine_destroy(struct machine *machine); |
425 |
int machine_name_to_type(char *stype, char *ssubtype, |
426 |
int *type, int *subtype, int *arch); |
427 |
void machine_add_tickfunction(struct machine *machine, |
428 |
void (*func)(struct cpu *, void *), void *extra, |
429 |
int clockshift, double hz); |
430 |
void machine_statistics_init(struct machine *, char *fname); |
431 |
void machine_register(char *name, MACHINE_SETUP_TYPE(setup)); |
432 |
void dump_mem_string(struct cpu *cpu, uint64_t addr); |
433 |
void store_string(struct cpu *cpu, uint64_t addr, char *s); |
434 |
int store_64bit_word(struct cpu *cpu, uint64_t addr, uint64_t data64); |
435 |
int store_32bit_word(struct cpu *cpu, uint64_t addr, uint64_t data32); |
436 |
int store_16bit_word(struct cpu *cpu, uint64_t addr, uint64_t data16); |
437 |
void store_byte(struct cpu *cpu, uint64_t addr, uint8_t data); |
438 |
void store_64bit_word_in_host(struct cpu *cpu, unsigned char *data, |
439 |
uint64_t data32); |
440 |
void store_32bit_word_in_host(struct cpu *cpu, unsigned char *data, |
441 |
uint64_t data32); |
442 |
void store_16bit_word_in_host(struct cpu *cpu, unsigned char *data, |
443 |
uint16_t data16); |
444 |
uint64_t load_64bit_word(struct cpu *cpu, uint64_t addr); |
445 |
uint32_t load_32bit_word(struct cpu *cpu, uint64_t addr); |
446 |
uint16_t load_16bit_word(struct cpu *cpu, uint64_t addr); |
447 |
void store_buf(struct cpu *cpu, uint64_t addr, char *s, size_t len); |
448 |
void add_environment_string(struct cpu *cpu, char *s, uint64_t *addr); |
449 |
void add_environment_string_dual(struct cpu *cpu, |
450 |
uint64_t *ptrp, uint64_t *addrp, char *s1, char *s2); |
451 |
void store_pointer_and_advance(struct cpu *cpu, uint64_t *addrp, |
452 |
uint64_t data, int flag64); |
453 |
void machine_setup(struct machine *); |
454 |
void machine_memsize_fix(struct machine *); |
455 |
void machine_default_cputype(struct machine *); |
456 |
void machine_dumpinfo(struct machine *); |
457 |
int machine_run(struct machine *machine); |
458 |
void machine_list_available_types_and_cpus(void); |
459 |
struct machine_entry *machine_entry_new(const char *name, |
460 |
int arch, int oldstyle_type); |
461 |
void machine_entry_add_alias(struct machine_entry *me, const char *name); |
462 |
void machine_entry_add_subtype(struct machine_entry *me, const char *name, |
463 |
int oldstyle_subtype, ...); |
464 |
void machine_entry_register(struct machine_entry *me, int arch); |
465 |
void machine_init(void); |
466 |
|
467 |
|
468 |
#endif /* MACHINE_H */ |