1 |
/* |
/* |
2 |
* Copyright (C) 2003-2005 Anders Gavare. All rights reserved. |
* Copyright (C) 2003-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: |
25 |
* SUCH DAMAGE. |
* SUCH DAMAGE. |
26 |
* |
* |
27 |
* |
* |
28 |
* $Id: main.c,v 1.248 2005/11/23 02:17:00 debug Exp $ |
* $Id: main.c,v 1.296 2007/03/31 15:11:26 debug Exp $ |
29 |
*/ |
*/ |
30 |
|
|
31 |
#include <stdio.h> |
#include <stdio.h> |
37 |
|
|
38 |
#include "console.h" |
#include "console.h" |
39 |
#include "cpu.h" |
#include "cpu.h" |
40 |
|
#include "debugger.h" |
41 |
#include "device.h" |
#include "device.h" |
42 |
#include "diskimage.h" |
#include "diskimage.h" |
43 |
#include "emul.h" |
#include "emul.h" |
44 |
#include "machine.h" |
#include "machine.h" |
45 |
#include "misc.h" |
#include "misc.h" |
46 |
|
#include "settings.h" |
47 |
|
#include "timer.h" |
48 |
|
|
49 |
|
#ifdef TEST_NATIVE_X86 |
50 |
|
#include "native_x86.h" |
51 |
|
#endif |
52 |
|
|
53 |
|
|
54 |
extern volatile int single_step; |
extern volatile int single_step; |
55 |
extern int force_debugger_at_exit; |
extern int force_debugger_at_exit; |
|
extern int show_opcode_statistics; |
|
56 |
|
|
57 |
extern int optind; |
extern int optind; |
58 |
extern char *optarg; |
extern char *optarg; |
59 |
|
|
60 |
|
struct settings *global_settings; |
61 |
|
|
62 |
int extra_argc; |
int extra_argc; |
63 |
char **extra_argv; |
char **extra_argv; |
64 |
char *progname; |
char *progname; |
65 |
|
|
66 |
int fully_deterministic = 0; |
size_t dyntrans_cache_size = DEFAULT_DYNTRANS_CACHE_SIZE; |
67 |
|
int native_code_translation_enabled = 0; |
68 |
|
int skip_srandom_call = 0; |
69 |
|
|
70 |
|
|
71 |
/***************************************************************************** |
/***************************************************************************** |
202 |
{ |
{ |
203 |
printf("GXemul"); |
printf("GXemul"); |
204 |
#ifdef VERSION |
#ifdef VERSION |
205 |
printf("-" VERSION); |
printf(" " VERSION); |
206 |
#endif |
#endif |
207 |
printf(" Copyright (C) 2003-2005 Anders Gavare\n"); |
printf(" Copyright (C) 2003-2007 Anders Gavare\n"); |
208 |
printf("Read the source code and/or documentation for " |
printf("Read the source code and/or documentation for " |
209 |
"other Copyright messages.\n"); |
"other Copyright messages.\n"); |
210 |
|
|
211 |
printf("\nusage: %s [machine, other, and general options] [file " |
printf("\nusage: %s [machine, other, and general options] [file " |
212 |
"[...]]\n", progname); |
"[...]]\n", progname); |
213 |
printf(" or %s [general options] @configfile\n", progname); |
printf(" or %s [general options] @configfile\n", progname); |
214 |
|
#ifdef UNSTABLE_DEVEL |
215 |
printf(" or %s [userland, other, and general options] file " |
printf(" or %s [userland, other, and general options] file " |
216 |
"[args ...]\n", progname); |
"[args ...]\n", progname); |
217 |
|
#endif |
218 |
|
|
219 |
if (!longusage) { |
if (!longusage) { |
220 |
printf("\nRun %s -h for help on command line options.\n", |
printf("\nRun %s -h for help on command line options.\n", |
229 |
"with -E.)\n"); |
"with -E.)\n"); |
230 |
|
|
231 |
printf("\nOther options:\n"); |
printf("\nOther options:\n"); |
|
printf(" -A disable alignment checks in some cases (for higher" |
|
|
" speed)\n"); |
|
|
#ifdef BINTRANS |
|
|
printf(" -B disable dynamic binary translation. (translation" |
|
|
" is turned on\n by default, if the host " |
|
|
"supports it)\n"); |
|
|
#endif |
|
232 |
printf(" -C x try to emulate a specific CPU. (Use -H to get a " |
printf(" -C x try to emulate a specific CPU. (Use -H to get a " |
233 |
"list of types.)\n"); |
"list of types.)\n"); |
234 |
printf(" -d fname add fname as a disk image. You can add \"xxx:\"" |
printf(" -d fname add fname as a disk image. You can add \"xxx:\"" |
242 |
printf(" gH;S; set geometry to H heads and S" |
printf(" gH;S; set geometry to H heads and S" |
243 |
" sectors-per-track\n"); |
" sectors-per-track\n"); |
244 |
printf(" i IDE\n"); |
printf(" i IDE\n"); |
245 |
|
printf(" oOFS; set base offset to OFS (for ISO9660" |
246 |
|
" filesystems)\n"); |
247 |
printf(" r read-only (don't allow changes to the" |
printf(" r read-only (don't allow changes to the" |
248 |
" file)\n"); |
" file)\n"); |
249 |
printf(" s SCSI\n"); |
printf(" s SCSI\n"); |
250 |
printf(" t tape\n"); |
printf(" t tape\n"); |
251 |
|
printf(" V add an overlay\n"); |
252 |
printf(" 0-7 force a specific ID\n"); |
printf(" 0-7 force a specific ID\n"); |
253 |
printf(" -I x emulate clock interrupts at x Hz (affects" |
printf(" -I hz set the main cpu frequency to hz (not used by " |
254 |
" rtc devices only, not\n"); |
"all combinations\n of machines and guest OSes)\n"); |
|
printf(" actual runtime speed) (this disables automatic" |
|
|
" clock adjustments)\n"); |
|
255 |
printf(" -i display each instruction as it is executed\n"); |
printf(" -i display each instruction as it is executed\n"); |
256 |
printf(" -J disable some speed tricks\n"); |
printf(" -J disable dyntrans instruction combinations\n"); |
257 |
printf(" -j name set the name of the kernel, for example:\n"); |
printf(" -j name set the name of the kernel; for DECstation " |
258 |
printf(" -j netbsd for NetBSD/pmax\n"); |
"emulation, this passes\n the name to the bootloader," |
259 |
printf(" -j bsd for OpenBSD/pmax\n"); |
" for example:\n"); |
260 |
printf(" -j vmunix for Ultrix/RISC\n"); |
printf(" -j netbsd (NetBSD/pmax) " |
261 |
|
"-j bsd (OpenBSD/pmax)\n"); |
262 |
|
printf(" -j vmsprite (Sprite/pmax) " |
263 |
|
"-j vmunix (Ultrix/RISC)\n"); |
264 |
|
printf(" For other emulation modes, if the boot disk is an" |
265 |
|
" ISO9660\n filesystem, -j sets the name of the" |
266 |
|
" kernel to load.\n"); |
267 |
printf(" -M m emulate m MBs of physical RAM\n"); |
printf(" -M m emulate m MBs of physical RAM\n"); |
|
printf(" -m nr run at most nr instructions (on any cpu)\n"); |
|
268 |
printf(" -N display nr of instructions/second average, at" |
printf(" -N display nr of instructions/second average, at" |
269 |
" regular intervals\n"); |
" regular intervals\n"); |
270 |
printf(" -n nr set nr of CPUs (for SMP experiments)\n"); |
printf(" -n nr set nr of CPUs (for SMP experiments)\n"); |
271 |
printf(" -O force netboot (tftp instead of disk), even when" |
printf(" -O force netboot (tftp instead of disk), even when" |
272 |
" a disk image is\n" |
" a disk image is\n" |
273 |
" present (for DECstation, SGI, and ARC emulation)\n"); |
" present (for DECstation, SGI, and ARC emulation)\n"); |
274 |
printf(" -o arg set the boot argument (for DEC, ARC, or SGI" |
printf(" -o arg set the boot argument, for DEC, ARC, or SGI" |
275 |
" emulation).\n"); |
" emulation\n"); |
276 |
printf(" Default arg for DEC is '-a', for ARC '-aN'.\n"); |
printf(" (default arg for DEC is -a, for ARC/SGI -aN)\n"); |
277 |
printf(" -p pc add a breakpoint (remember to use the '0x' " |
printf(" -p pc add a breakpoint (remember to use the '0x' " |
278 |
"prefix for hex!)\n"); |
"prefix for hex!)\n"); |
279 |
printf(" -Q no built-in PROM emulation (use this for " |
printf(" -Q no built-in PROM emulation (use this for " |
282 |
printf(" -r register dumps before every instruction\n"); |
printf(" -r register dumps before every instruction\n"); |
283 |
printf(" -S initialize emulated RAM to random bytes, " |
printf(" -S initialize emulated RAM to random bytes, " |
284 |
"instead of zeroes\n"); |
"instead of zeroes\n"); |
285 |
printf(" -T enter the single-step debugger on " |
printf(" -s f:name write statistics to file 'name', " |
286 |
"unimplemented memory accesses\n"); |
"f is one or more of the following:\n"); |
287 |
|
printf(" v virtual program counter\n"); |
288 |
|
printf(" p physical equivalent of program counter\n"); |
289 |
|
printf(" i internal ic->f representation of " |
290 |
|
"the program counter\n"); |
291 |
|
printf(" and optionally:\n"); |
292 |
|
printf(" d disable statistics gathering at " |
293 |
|
"startup\n"); |
294 |
|
printf(" o overwrite instead of append\n"); |
295 |
|
printf(" -T halt on non-existant memory accesses\n"); |
296 |
printf(" -t show function trace tree\n"); |
printf(" -t show function trace tree\n"); |
297 |
printf(" -U enable slow_serial_interrupts_hack_for_linux\n"); |
printf(" -U enable slow_serial_interrupts_hack_for_linux\n"); |
298 |
#ifdef WITH_X11 |
#ifdef WITH_X11 |
299 |
printf(" -X use X11\n"); |
printf(" -X use X11\n"); |
|
#endif /* WITH_X11 */ |
|
300 |
printf(" -x open up new xterms for emulated serial ports " |
printf(" -x open up new xterms for emulated serial ports " |
301 |
"(default is on when\n using configuration files, off" |
"(default is on when\n using configuration files or" |
302 |
" otherwise)\n"); |
" when X11 is used, off otherwise)\n"); |
|
#ifdef WITH_X11 |
|
303 |
printf(" -Y n scale down framebuffer windows by n x n times\n"); |
printf(" -Y n scale down framebuffer windows by n x n times\n"); |
304 |
#endif /* WITH_X11 */ |
#endif /* WITH_X11 */ |
|
printf(" -y x set max_random_cycles_per_chunk to x" |
|
|
" (experimental)\n"); |
|
305 |
printf(" -Z n set nr of graphics cards, for emulating a " |
printf(" -Z n set nr of graphics cards, for emulating a " |
306 |
"dual-head or tripple-head\n" |
"dual-head or tripple-head\n" |
307 |
" environment (only for DECstation emulation)\n"); |
" environment (only for DECstation emulation)\n"); |
308 |
printf(" -z disp add disp as an X11 display to use for " |
printf(" -z disp add disp as an X11 display to use for " |
309 |
"framebuffers\n"); |
"framebuffers\n"); |
310 |
|
|
311 |
|
#ifdef UNSTABLE_DEVEL |
312 |
printf("\nUserland options:\n"); |
printf("\nUserland options:\n"); |
313 |
printf(" -u emul userland-only (syscall) emulation (use -H to" |
printf(" -u emul userland-only (syscall) emulation (use -H to" |
314 |
" get a list of\n available emulation modes)\n"); |
" get a list of\n available emulation modes)\n"); |
315 |
|
#endif |
316 |
|
|
317 |
printf("\nGeneral options:\n"); |
printf("\nGeneral options:\n"); |
318 |
printf(" -D guarantee fully deterministic behaviour\n"); |
#ifdef UNSTABLE_DEVEL |
319 |
|
printf(" -b enable native code generation\n"); |
320 |
|
printf(" -B disable native code generation\n"); |
321 |
|
#endif |
322 |
|
printf(" -c cmd add cmd as a command to run before starting " |
323 |
|
"the simulation\n"); |
324 |
|
printf(" -D skip the srandom call at startup\n"); |
325 |
printf(" -H display a list of possible CPU and " |
printf(" -H display a list of possible CPU and " |
326 |
"machine types\n"); |
"machine types\n"); |
327 |
printf(" -h display this help message\n"); |
printf(" -h display this help message\n"); |
328 |
|
printf(" -k n set dyntrans translation caches to n MB (default" |
329 |
|
" size is %i MB)\n", DEFAULT_DYNTRANS_CACHE_SIZE / 1048576); |
330 |
printf(" -K force the debugger to be entered at the end " |
printf(" -K force the debugger to be entered at the end " |
331 |
"of a simulation\n"); |
"of a simulation\n"); |
332 |
printf(" -q quiet mode (don't print startup messages)\n"); |
printf(" -q quiet mode (don't print startup messages)\n"); |
|
printf(" -s show opcode usage statistics after simulation\n"); |
|
333 |
printf(" -V start up in the single-step debugger, paused\n"); |
printf(" -V start up in the single-step debugger, paused\n"); |
334 |
printf(" -v verbose debug messages\n"); |
printf(" -v verbose debug messages\n"); |
335 |
printf("\n"); |
printf("\n"); |
360 |
char ***diskimagesp, int *n_diskimagesp) |
char ***diskimagesp, int *n_diskimagesp) |
361 |
{ |
{ |
362 |
int ch, res, using_switch_d = 0, using_switch_Z = 0; |
int ch, res, using_switch_d = 0, using_switch_Z = 0; |
363 |
|
int using_switch_e = 0, using_switch_E = 0; |
364 |
char *type = NULL, *subtype = NULL; |
char *type = NULL, *subtype = NULL; |
365 |
int n_cpus_set = 0; |
int n_cpus_set = 0; |
366 |
int msopts = 0; /* Machine-specific options used */ |
int msopts = 0; /* Machine-specific options used */ |
367 |
struct machine *m = emul_add_machine(emul, "default"); |
struct machine *m = emul_add_machine(emul, "default"); |
368 |
|
|
369 |
while ((ch = getopt(argc, argv, "ABC:Dd:E:e:HhI:iJj:KM:m:" |
char *opts = |
370 |
"Nn:Oo:p:QqRrSsTtUu:VvW:XxY:y:Z:z:")) != -1) { |
#ifdef UNSTABLE_DEVEL |
371 |
|
"bB" |
372 |
|
#endif |
373 |
|
"C:c:Dd:E:e:HhI:iJj:k:KM:Nn:Oo:p:QqRrSs:TtU" |
374 |
|
#ifdef UNSTABLE_DEVEL |
375 |
|
"u:" |
376 |
|
#endif |
377 |
|
"VvW:" |
378 |
|
#ifdef WITH_X11 |
379 |
|
"XxY:" |
380 |
|
#endif |
381 |
|
"Z:z:"; |
382 |
|
|
383 |
|
while ((ch = getopt(argc, argv, opts)) != -1) { |
384 |
switch (ch) { |
switch (ch) { |
385 |
case 'A': |
#ifdef UNSTABLE_DEVEL |
386 |
m->dyntrans_alignment_check = 0; |
case 'b': |
387 |
msopts = 1; |
#ifndef NATIVE_CODE_GENERATION |
388 |
|
printf("-b is not available on this host arch.\n"); |
389 |
|
exit(1); |
390 |
|
#else |
391 |
|
native_code_translation_enabled = 1; |
392 |
break; |
break; |
393 |
|
#endif |
394 |
case 'B': |
case 'B': |
395 |
m->bintrans_enable = 0; |
native_code_translation_enabled = 0; |
|
msopts = 1; |
|
396 |
break; |
break; |
397 |
|
#endif /* UNSTABLE_DEVEL */ |
398 |
case 'C': |
case 'C': |
399 |
m->cpu_name = strdup(optarg); |
m->cpu_name = strdup(optarg); |
400 |
msopts = 1; |
msopts = 1; |
401 |
break; |
break; |
402 |
|
case 'c': |
403 |
|
emul->n_debugger_cmds ++; |
404 |
|
emul->debugger_cmds = realloc(emul->debugger_cmds, |
405 |
|
emul->n_debugger_cmds * sizeof(char *)); |
406 |
|
if (emul->debugger_cmds == NULL) { |
407 |
|
fatal("out of memory\n"); |
408 |
|
exit(1); |
409 |
|
} |
410 |
|
emul->debugger_cmds[emul->n_debugger_cmds-1] = |
411 |
|
strdup(optarg); |
412 |
|
break; |
413 |
case 'D': |
case 'D': |
414 |
fully_deterministic = 1; |
skip_srandom_call = 1; |
415 |
break; |
break; |
416 |
case 'd': |
case 'd': |
417 |
/* diskimage_add() is called further down */ |
/* diskimage_add() is called further down */ |
427 |
msopts = 1; |
msopts = 1; |
428 |
break; |
break; |
429 |
case 'E': |
case 'E': |
430 |
|
if (using_switch_E ++ > 0) { |
431 |
|
fprintf(stderr, "-E already used.\n"); |
432 |
|
exit(1); |
433 |
|
} |
434 |
type = optarg; |
type = optarg; |
435 |
msopts = 1; |
msopts = 1; |
436 |
break; |
break; |
437 |
case 'e': |
case 'e': |
438 |
|
if (using_switch_e ++ > 0) { |
439 |
|
fprintf(stderr, "-e already used.\n"); |
440 |
|
exit(1); |
441 |
|
} |
442 |
subtype = optarg; |
subtype = optarg; |
443 |
msopts = 1; |
msopts = 1; |
444 |
break; |
break; |
450 |
exit(1); |
exit(1); |
451 |
case 'I': |
case 'I': |
452 |
m->emulated_hz = atoi(optarg); |
m->emulated_hz = atoi(optarg); |
|
m->automatic_clock_adjustment = 0; |
|
453 |
msopts = 1; |
msopts = 1; |
454 |
break; |
break; |
455 |
case 'i': |
case 'i': |
457 |
msopts = 1; |
msopts = 1; |
458 |
break; |
break; |
459 |
case 'J': |
case 'J': |
460 |
m->speed_tricks = 0; |
m->allow_instruction_combinations = 0; |
461 |
msopts = 1; |
msopts = 1; |
462 |
break; |
break; |
463 |
case 'j': |
case 'j': |
468 |
} |
} |
469 |
msopts = 1; |
msopts = 1; |
470 |
break; |
break; |
471 |
|
case 'k': |
472 |
|
dyntrans_cache_size = atoi(optarg) * 1048576; |
473 |
|
if (dyntrans_cache_size < 1) { |
474 |
|
fprintf(stderr, "The dyntrans cache size must" |
475 |
|
" be at least 1 MB.\n"); |
476 |
|
exit(1); |
477 |
|
} |
478 |
|
break; |
479 |
case 'K': |
case 'K': |
480 |
force_debugger_at_exit = 1; |
force_debugger_at_exit = 1; |
481 |
break; |
break; |
483 |
m->physical_ram_in_mb = atoi(optarg); |
m->physical_ram_in_mb = atoi(optarg); |
484 |
msopts = 1; |
msopts = 1; |
485 |
break; |
break; |
|
case 'm': |
|
|
m->max_instructions = atoi(optarg); |
|
|
msopts = 1; |
|
|
break; |
|
486 |
case 'N': |
case 'N': |
487 |
m->show_nr_of_instructions = 1; |
m->show_nr_of_instructions = 1; |
488 |
msopts = 1; |
msopts = 1; |
538 |
msopts = 1; |
msopts = 1; |
539 |
break; |
break; |
540 |
case 's': |
case 's': |
541 |
show_opcode_statistics = 1; |
machine_statistics_init(m, optarg); |
542 |
|
native_code_translation_enabled = 0; |
543 |
|
msopts = 1; |
544 |
break; |
break; |
545 |
case 'T': |
case 'T': |
546 |
m->single_step_on_bad_addr = 1; |
m->halt_on_nonexistant_memaccess = 1; |
547 |
msopts = 1; |
msopts = 1; |
548 |
break; |
break; |
549 |
case 't': |
case 't': |
564 |
msopts = 1; |
msopts = 1; |
565 |
break; |
break; |
566 |
case 'V': |
case 'V': |
567 |
single_step = 1; |
single_step = ENTER_SINGLE_STEPPING; |
568 |
break; |
break; |
569 |
case 'v': |
case 'v': |
570 |
verbose ++; |
verbose ++; |
575 |
case 'X': |
case 'X': |
576 |
m->use_x11 = 1; |
m->use_x11 = 1; |
577 |
msopts = 1; |
msopts = 1; |
578 |
break; |
/* FALL-THROUGH */ |
579 |
case 'x': |
case 'x': |
580 |
console_allow_slaves(1); |
console_allow_slaves(1); |
581 |
break; |
break; |
591 |
} |
} |
592 |
msopts = 1; |
msopts = 1; |
593 |
break; |
break; |
|
case 'y': |
|
|
m->max_random_cycles_per_chunk = atoi(optarg); |
|
|
msopts = 1; |
|
|
break; |
|
594 |
case 'Z': |
case 'Z': |
595 |
m->n_gfx_cards = atoi(optarg); |
m->n_gfx_cards = atoi(optarg); |
596 |
using_switch_Z = 1; |
using_switch_Z = 1; |
662 |
quiet_mode = 0; |
quiet_mode = 0; |
663 |
} |
} |
664 |
|
|
|
if ((m->instruction_trace || m->register_dump || m->show_trace_tree) |
|
|
&& m->bintrans_enable) { |
|
|
if (m->arch == ARCH_MIPS) |
|
|
fprintf(stderr, "Implicitly turning off bintrans.\n"); |
|
|
m->bintrans_enable = 0; |
|
|
} |
|
|
|
|
665 |
|
|
666 |
/* |
/* |
667 |
* Usually, an executable filename must be supplied. |
* Usually, an executable filename must be supplied. |
708 |
exit(1); |
exit(1); |
709 |
} |
} |
710 |
|
|
|
if (m->bintrans_enable && m->arch == ARCH_MIPS) { |
|
|
m->speed_tricks = 0; |
|
|
/* TODO: Print a warning about this? */ |
|
|
} |
|
|
|
|
|
if (m->n_breakpoints > 0 && |
|
|
m->bintrans_enable && m->arch == ARCH_MIPS) { |
|
|
fprintf(stderr, "Breakpoints and MIPS binary translation " |
|
|
"don't work too well together right now.\n"); |
|
|
exit(1); |
|
|
} |
|
|
|
|
|
#ifndef BINTRANS |
|
|
if (m->bintrans_enable) { |
|
|
fprintf(stderr, "WARNING: %s was compiled without " |
|
|
"bintrans support. Ignoring -b.\n", progname); |
|
|
m->bintrans_enable = 0; |
|
|
} |
|
|
#endif |
|
|
|
|
|
#ifndef WITH_X11 |
|
|
if (m->use_x11) { |
|
|
fprintf(stderr, "WARNING: %s was compiled without " |
|
|
"X11 support. Ignoring -X.\n", progname); |
|
|
m->use_x11 = 0; |
|
|
} |
|
|
#endif |
|
|
|
|
711 |
if (!using_switch_Z && !m->use_x11) |
if (!using_switch_Z && !m->use_x11) |
712 |
m->n_gfx_cards = 0; |
m->n_gfx_cards = 0; |
713 |
|
|
|
m->bintrans_enabled_from_start = m->bintrans_enable; |
|
|
|
|
714 |
return 0; |
return 0; |
715 |
} |
} |
716 |
|
|
727 |
*/ |
*/ |
728 |
int main(int argc, char *argv[]) |
int main(int argc, char *argv[]) |
729 |
{ |
{ |
730 |
|
/* Setting constants: */ |
731 |
|
const int constant_yes = 1; |
732 |
|
const int constant_true = 1; |
733 |
|
const int constant_no = 0; |
734 |
|
const int constant_false = 0; |
735 |
|
|
736 |
struct emul **emuls; |
struct emul **emuls; |
737 |
char **diskimages = NULL; |
char **diskimages = NULL; |
738 |
int n_diskimages = 0; |
int n_diskimages = 0; |
739 |
int n_emuls; |
int n_emuls; |
740 |
int i; |
int i; |
741 |
|
|
742 |
|
|
743 |
|
/* |
744 |
|
* Experimental profil() code, which works on my laptop. |
745 |
|
* Don't use it for anything else. |
746 |
|
*/ |
747 |
|
#ifdef USE_PROFIL |
748 |
|
uint16_t samples[0x100000]; |
749 |
|
memset(samples, 0, sizeof(samples)); |
750 |
|
profil((char *)samples, sizeof(samples), (vm_offset_t) 0x400000, 8192); |
751 |
|
#endif |
752 |
|
|
753 |
|
#ifndef NATIVE_CODE_GENERATION |
754 |
|
native_code_translation_enabled = 0; |
755 |
|
#endif |
756 |
|
|
757 |
|
|
758 |
|
/* Experimental test code: */ |
759 |
|
#ifdef TEST_NATIVE_X86 |
760 |
|
test_native_x86(); |
761 |
|
#endif |
762 |
|
|
763 |
|
|
764 |
|
|
765 |
progname = argv[0]; |
progname = argv[0]; |
766 |
|
|
767 |
|
|
768 |
|
/* |
769 |
|
* Create the settings object, and add global settings to it: |
770 |
|
* |
771 |
|
* Read-only "constants": yes, no, true, false. |
772 |
|
* Global emulator settings: verbose, single_step, ... |
773 |
|
*/ |
774 |
|
global_settings = settings_new(); |
775 |
|
|
776 |
|
settings_add(global_settings, "yes", 0, SETTINGS_TYPE_INT, |
777 |
|
SETTINGS_FORMAT_YESNO, (void *)&constant_yes); |
778 |
|
settings_add(global_settings, "no", 0, SETTINGS_TYPE_INT, |
779 |
|
SETTINGS_FORMAT_YESNO, (void *)&constant_no); |
780 |
|
settings_add(global_settings, "true", 0, SETTINGS_TYPE_INT, |
781 |
|
SETTINGS_FORMAT_BOOL, (void *)&constant_true); |
782 |
|
settings_add(global_settings, "false", 0, SETTINGS_TYPE_INT, |
783 |
|
SETTINGS_FORMAT_BOOL, (void *)&constant_false); |
784 |
|
|
785 |
|
/* Read-only settings: */ |
786 |
|
settings_add(global_settings, "native_code_translation_enabled", 0, |
787 |
|
SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, |
788 |
|
(void *)&native_code_translation_enabled); |
789 |
|
settings_add(global_settings, "single_step", 0, |
790 |
|
SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, (void *)&single_step); |
791 |
|
|
792 |
|
/* Read/write settings: */ |
793 |
|
settings_add(global_settings, "force_debugger_at_exit", 1, |
794 |
|
SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, |
795 |
|
(void *)&force_debugger_at_exit); |
796 |
|
settings_add(global_settings, "verbose", 1, |
797 |
|
SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, (void *)&verbose); |
798 |
|
settings_add(global_settings, "quiet_mode", 1, |
799 |
|
SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, (void *)&quiet_mode); |
800 |
|
|
801 |
|
/* Initialize all emulator subsystems: */ |
802 |
console_init(); |
console_init(); |
803 |
cpu_init(); |
cpu_init(); |
804 |
device_init(); |
device_init(); |
805 |
machine_init(); |
machine_init(); |
806 |
|
timer_init(); |
807 |
useremul_init(); |
useremul_init(); |
808 |
|
|
809 |
emuls = malloc(sizeof(struct emul *)); |
emuls = malloc(sizeof(struct emul *)); |
814 |
|
|
815 |
/* Allocate space for a simple emul setup: */ |
/* Allocate space for a simple emul setup: */ |
816 |
n_emuls = 1; |
n_emuls = 1; |
817 |
emuls[0] = emul_new(NULL); |
emuls[0] = emul_new(NULL, 0); |
818 |
if (emuls[0] == NULL) { |
if (emuls[0] == NULL) { |
819 |
fprintf(stderr, "out of memory\n"); |
fprintf(stderr, "out of memory\n"); |
820 |
exit(1); |
exit(1); |
821 |
} |
} |
822 |
|
settings_add(global_settings, "emul[0]", 1, |
823 |
|
SETTINGS_TYPE_SUBSETTINGS, 0, emuls[0]->settings); |
824 |
|
|
825 |
get_cmd_args(argc, argv, emuls[0], &diskimages, &n_diskimages); |
get_cmd_args(argc, argv, emuls[0], &diskimages, &n_diskimages); |
826 |
|
|
827 |
if (!fully_deterministic) { |
if (!skip_srandom_call) { |
828 |
/* TODO: More than just time(). Use gettimeofday(). */ |
struct timeval tv; |
829 |
srandom(time(NULL) ^ (getpid() << 12)); |
gettimeofday(&tv, NULL); |
830 |
} else { |
srandom(tv.tv_sec ^ getpid() ^ tv.tv_usec); |
|
/* Fully deterministic. -I must have been supplied. */ |
|
|
if (emuls[0]->machines[0]->automatic_clock_adjustment) { |
|
|
fatal("Cannot have -D without -I.\n"); |
|
|
exit(1); |
|
|
} |
|
831 |
} |
} |
832 |
|
|
833 |
/* Print startup message: */ |
/* Print startup message: */ |
834 |
debug("GXemul"); |
debug("GXemul"); |
835 |
#ifdef VERSION |
#ifdef VERSION |
836 |
debug("-" VERSION); |
debug(" " VERSION); |
837 |
#endif |
#endif |
838 |
debug(" Copyright (C) 2003-2005 Anders Gavare\n"); |
debug(" Copyright (C) 2003-2007 Anders Gavare\n"); |
839 |
debug("Read the source code and/or documentation for " |
debug("Read the source code and/or documentation for " |
840 |
"other Copyright messages.\n\n"); |
"other Copyright messages.\n\n"); |
841 |
|
|
842 |
if (emuls[0]->machines[0]->machine_type == MACHINE_NONE) |
if (emuls[0]->machines[0]->machine_type == MACHINE_NONE) { |
843 |
n_emuls --; |
n_emuls --; |
844 |
else { |
} else { |
845 |
for (i=0; i<n_diskimages; i++) |
for (i=0; i<n_diskimages; i++) |
846 |
diskimage_add(emuls[0]->machines[0], diskimages[i]); |
diskimage_add(emuls[0]->machines[0], diskimages[i]); |
847 |
} |
} |
866 |
/* Initialize emulations from config files: */ |
/* Initialize emulations from config files: */ |
867 |
for (i=1; i<argc; i++) { |
for (i=1; i<argc; i++) { |
868 |
if (argv[i][0] == '@') { |
if (argv[i][0] == '@') { |
869 |
|
char tmpstr[50]; |
870 |
char *s = argv[i] + 1; |
char *s = argv[i] + 1; |
871 |
if (strlen(s) == 0 && i+1 < argc && |
if (strlen(s) == 0 && i+1 < argc && |
872 |
argv[i+1][0] != '@') { |
argv[i+1][0] != '@') { |
879 |
fprintf(stderr, "out of memory\n"); |
fprintf(stderr, "out of memory\n"); |
880 |
exit(1); |
exit(1); |
881 |
} |
} |
|
emuls[n_emuls - 1] = |
|
|
emul_create_from_configfile(s); |
|
882 |
|
|
883 |
/* Always allow slave xterms when using multiple |
/* Always allow slave xterms when using multiple |
884 |
emulations: */ |
emulations: */ |
885 |
console_allow_slaves(1); |
console_allow_slaves(1); |
886 |
|
|
887 |
|
/* Destroy the temporary emuls[0], since it will |
888 |
|
be overwritten: */ |
889 |
|
if (n_emuls == 1) { |
890 |
|
emul_destroy(emuls[0]); |
891 |
|
settings_remove(global_settings, "emul[0]"); |
892 |
|
} |
893 |
|
|
894 |
|
emuls[n_emuls - 1] = |
895 |
|
emul_create_from_configfile(s, n_emuls - 1); |
896 |
|
|
897 |
|
snprintf(tmpstr, sizeof(tmpstr), "emul[%i]", n_emuls-1); |
898 |
|
settings_add(global_settings, tmpstr, 1, |
899 |
|
SETTINGS_TYPE_SUBSETTINGS, 0, |
900 |
|
emuls[n_emuls-1]->settings); |
901 |
} |
} |
902 |
} |
} |
903 |
|
|
911 |
} |
} |
912 |
|
|
913 |
device_set_exit_on_error(0); |
device_set_exit_on_error(0); |
914 |
console_warn_if_slaves_are_needed(); |
console_warn_if_slaves_are_needed(1); |
915 |
|
|
916 |
|
|
917 |
/* Run all emulations: */ |
/* Run all emulations: */ |
918 |
emul_run(emuls, n_emuls); |
emul_run(emuls, n_emuls); |
919 |
|
|
920 |
|
|
921 |
|
/* |
922 |
|
* Deinitialize everything: |
923 |
|
*/ |
924 |
|
|
925 |
|
console_deinit(); |
926 |
|
|
927 |
|
for (i=0; i<n_emuls; i++) |
928 |
|
emul_destroy(emuls[i]); |
929 |
|
|
930 |
|
settings_remove_all(global_settings); |
931 |
|
settings_destroy(global_settings); |
932 |
|
|
933 |
|
#ifdef USE_PROFIL |
934 |
|
{ |
935 |
|
int i; |
936 |
|
FILE *f = fopen("output.txt", "w"); |
937 |
|
for (i=0; i<sizeof(samples) / sizeof(uint16_t); ++i) { |
938 |
|
if (samples[i] != 0) |
939 |
|
fprintf(f, "%i %p\n", samples[i], |
940 |
|
(void *) (size_t) (0x400000 + i * 16)); |
941 |
|
} |
942 |
|
} |
943 |
|
#endif |
944 |
|
|
945 |
return 0; |
return 0; |
946 |
} |
} |
947 |
|
|