1 |
/* |
/* |
2 |
* Copyright (C) 2003-2005 Anders Gavare. All rights reserved. |
* Copyright (C) 2003-2006 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.232 2005/04/18 21:40:58 debug Exp $ |
* $Id: main.c,v 1.284 2006/09/19 10:50:08 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 |
|
|
50 |
extern volatile int single_step; |
extern volatile int single_step; |
51 |
extern int force_debugger_at_exit; |
extern int force_debugger_at_exit; |
|
extern int show_opcode_statistics; |
|
52 |
|
|
53 |
extern int optind; |
extern int optind; |
54 |
extern char *optarg; |
extern char *optarg; |
55 |
|
|
56 |
|
struct settings *global_settings; |
57 |
|
|
58 |
int extra_argc; |
int extra_argc; |
59 |
char **extra_argv; |
char **extra_argv; |
60 |
char *progname; |
char *progname; |
61 |
|
|
62 |
int fully_deterministic = 0; |
int skip_srandom_call = 0; |
63 |
|
|
64 |
|
|
65 |
/***************************************************************************** |
/***************************************************************************** |
159 |
|
|
160 |
|
|
161 |
/* |
/* |
|
* mystrtoull(): |
|
|
* |
|
|
* This function is used on OSes that don't have strtoull() in libc. |
|
|
*/ |
|
|
unsigned long long mystrtoull(const char *s, char **endp, int base) |
|
|
{ |
|
|
unsigned long long res = 0; |
|
|
int minus_sign = 0; |
|
|
|
|
|
if (s == NULL) |
|
|
return 0; |
|
|
|
|
|
/* TODO: Implement endp? */ |
|
|
if (endp != NULL) { |
|
|
fprintf(stderr, "mystrtoull(): endp isn't implemented\n"); |
|
|
exit(1); |
|
|
} |
|
|
|
|
|
if (s[0] == '-') { |
|
|
minus_sign = 1; |
|
|
s++; |
|
|
} |
|
|
|
|
|
/* Guess base: */ |
|
|
if (base == 0) { |
|
|
if (s[0] == '0') { |
|
|
/* Just "0"? :-) */ |
|
|
if (!s[1]) |
|
|
return 0; |
|
|
if (s[1] == 'x' || s[1] == 'X') { |
|
|
base = 16; |
|
|
s += 2; |
|
|
} else { |
|
|
base = 8; |
|
|
s ++; |
|
|
} |
|
|
} else if (s[0] >= '1' && s[0] <= '9') |
|
|
base = 10; |
|
|
} |
|
|
|
|
|
while (s[0]) { |
|
|
int c = s[0]; |
|
|
if (c >= '0' && c <= '9') |
|
|
c -= '0'; |
|
|
else if (c >= 'a' && c <= 'f') |
|
|
c = c - 'a' + 10; |
|
|
else if (c >= 'A' && c <= 'F') |
|
|
c = c - 'A' + 10; |
|
|
else |
|
|
break; |
|
|
switch (base) { |
|
|
case 8: res = (res << 3) | c; |
|
|
break; |
|
|
case 16:res = (res << 4) | c; |
|
|
break; |
|
|
default:res = (res * base) + c; |
|
|
} |
|
|
s++; |
|
|
} |
|
|
|
|
|
if (minus_sign) |
|
|
res = (uint64_t) -(int64_t)res; |
|
|
return res; |
|
|
} |
|
|
|
|
|
|
|
|
/*****************************************************************************/ |
|
|
|
|
|
|
|
|
/* |
|
162 |
* internal_w(): |
* internal_w(): |
163 |
* |
* |
164 |
* For internal use by gxemul itself. |
* For internal use by gxemul itself. |
196 |
{ |
{ |
197 |
printf("GXemul"); |
printf("GXemul"); |
198 |
#ifdef VERSION |
#ifdef VERSION |
199 |
printf("-" VERSION); |
printf(" " VERSION); |
200 |
#endif |
#endif |
201 |
printf(" Copyright (C) 2003-2005 Anders Gavare\n"); |
printf(" Copyright (C) 2003-2006 Anders Gavare\n"); |
202 |
printf("Read the source code and/or documentation for " |
printf("Read the source code and/or documentation for " |
203 |
"other Copyright messages.\n"); |
"other Copyright messages.\n"); |
204 |
|
|
205 |
printf("\nusage: %s [machine, other, and general options] [file " |
printf("\nusage: %s [machine, other, and general options] [file " |
206 |
"[...]]\n", progname); |
"[...]]\n", progname); |
207 |
printf(" or %s [general options] @configfile [...]\n", progname); |
printf(" or %s [general options] @configfile\n", progname); |
208 |
|
#ifdef UNSTABLE_DEVEL |
209 |
printf(" or %s [userland, other, and general options] file " |
printf(" or %s [userland, other, and general options] file " |
210 |
"[args ...]\n", progname); |
"[args ...]\n", progname); |
211 |
|
#endif |
212 |
|
|
213 |
if (!longusage) { |
if (!longusage) { |
214 |
printf("\nRun %s -h for help on command line options.\n", |
printf("\nRun %s -h for help on command line options.\n", |
223 |
"with -E.)\n"); |
"with -E.)\n"); |
224 |
|
|
225 |
printf("\nOther options:\n"); |
printf("\nOther options:\n"); |
|
#ifdef BINTRANS |
|
|
printf(" -B disable dynamic binary translation completely\n"); |
|
|
printf(" -b use the OLD binary translation subsystem\n"); |
|
|
#endif |
|
226 |
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 " |
227 |
"list of types.)\n"); |
"list of types.)\n"); |
228 |
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:\"" |
229 |
" as a prefix\n"); |
" as a prefix\n"); |
230 |
printf(" where xxx is one or more of the following:\n"); |
printf(" where xxx is one or more of the following:\n"); |
231 |
printf(" b specifies that this is the boot" |
printf(" b specifies that this is the boot" |
232 |
" device\n"); |
" device\n"); |
233 |
printf(" c CD-ROM\n"); |
printf(" c CD-ROM\n"); |
234 |
printf(" d DISK\n"); |
printf(" d DISK\n"); |
235 |
printf(" f FLOPPY\n"); |
printf(" f FLOPPY\n"); |
236 |
printf(" i IDE\n"); |
printf(" gH;S; set geometry to H heads and S" |
237 |
printf(" r read-only (don't allow changes to the" |
" sectors-per-track\n"); |
238 |
|
printf(" i IDE\n"); |
239 |
|
printf(" r read-only (don't allow changes to the" |
240 |
" file)\n"); |
" file)\n"); |
241 |
printf(" s SCSI\n"); |
printf(" s SCSI\n"); |
242 |
printf(" t tape\n"); |
printf(" t tape\n"); |
243 |
printf(" 0-7 force a specific ID\n"); |
printf(" 0-7 force a specific ID\n"); |
244 |
printf(" -I x emulate clock interrupts at x Hz (affects" |
printf(" -G port listen to gdb remote connections on this port\n"); |
245 |
" rtc devices only, not\n"); |
printf(" -I hz set the main cpu frequency to hz (not used by " |
246 |
printf(" actual runtime speed) (this disables automatic" |
"all combinations\n of machines and guest OSes)"); |
|
" clock adjustments)\n"); |
|
247 |
printf(" -i display each instruction as it is executed\n"); |
printf(" -i display each instruction as it is executed\n"); |
248 |
printf(" -J disable some speed tricks\n"); |
printf(" -J disable dyntrans instruction combinations\n"); |
249 |
printf(" -j name set the name of the kernel, for example:\n"); |
printf(" -j name set the name of the kernel; for DECstation " |
250 |
printf(" -j netbsd for NetBSD/pmax\n"); |
"emulation, this passes\n the name to the bootloader," |
251 |
printf(" -j bsd for OpenBSD/pmax\n"); |
" for example:\n"); |
252 |
printf(" -j vmunix for Ultrix/RISC\n"); |
printf(" -j netbsd (NetBSD/pmax) " |
253 |
|
"-j bsd (OpenBSD/pmax)\n"); |
254 |
|
printf(" -j vmsprite (Sprite/pmax) " |
255 |
|
"-j vmunix (Ultrix/RISC)\n"); |
256 |
|
printf(" For other emulation modes, if the boot disk is an" |
257 |
|
" ISO9660\n filesystem, -j sets the name of the" |
258 |
|
" kernel to load.\n"); |
259 |
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"); |
|
260 |
printf(" -N display nr of instructions/second average, at" |
printf(" -N display nr of instructions/second average, at" |
261 |
" regular intervals\n"); |
" regular intervals\n"); |
262 |
printf(" -n nr set nr of CPUs (for SMP experiments)\n"); |
printf(" -n nr set nr of CPUs (for SMP experiments)\n"); |
263 |
printf(" -O force netboot (tftp instead of disk), even when" |
printf(" -O force netboot (tftp instead of disk), even when" |
264 |
" a disk image is\n" |
" a disk image is\n" |
265 |
" present (for DECstation, SGI, and ARC emulation)\n"); |
" present (for DECstation, SGI, and ARC emulation)\n"); |
266 |
printf(" -o arg set the boot argument (for DEC, ARC, or SGI" |
printf(" -o arg set the boot argument, for DEC, ARC, or SGI" |
267 |
" emulation).\n"); |
" emulation\n"); |
268 |
printf(" Default arg for DEC is '-a', for ARC '-aN'.\n"); |
printf(" (default arg for DEC is -a, for ARC/SGI -aN)\n"); |
269 |
printf(" -p pc add a breakpoint (remember to use the '0x' " |
printf(" -p pc add a breakpoint (remember to use the '0x' " |
270 |
"prefix for hex!)\n"); |
"prefix for hex!)\n"); |
271 |
printf(" -Q no built-in PROM emulation (use this for " |
printf(" -Q no built-in PROM emulation (use this for " |
274 |
printf(" -r register dumps before every instruction\n"); |
printf(" -r register dumps before every instruction\n"); |
275 |
printf(" -S initialize emulated RAM to random bytes, " |
printf(" -S initialize emulated RAM to random bytes, " |
276 |
"instead of zeroes\n"); |
"instead of zeroes\n"); |
277 |
printf(" -T enter the single-step debugger on " |
printf(" -s f:name write statistics to file 'name', " |
278 |
"unimplemented memory accesses\n"); |
"f is one or more of the following:\n"); |
279 |
|
printf(" v virtual program counter\n"); |
280 |
|
printf(" p physical equivalent of program counter\n"); |
281 |
|
printf(" i internal ic->f representation of " |
282 |
|
"the program counter\n"); |
283 |
|
printf(" and optionally:\n"); |
284 |
|
printf(" d disable statistics gathering at " |
285 |
|
"startup\n"); |
286 |
|
printf(" o overwrite instead of append\n"); |
287 |
printf(" -t show function trace tree\n"); |
printf(" -t show function trace tree\n"); |
288 |
printf(" -U enable slow_serial_interrupts_hack_for_linux\n"); |
printf(" -U enable slow_serial_interrupts_hack_for_linux\n"); |
289 |
#ifdef WITH_X11 |
#ifdef WITH_X11 |
290 |
printf(" -X use X11\n"); |
printf(" -X use X11\n"); |
|
#endif /* WITH_X11 */ |
|
291 |
printf(" -x open up new xterms for emulated serial ports " |
printf(" -x open up new xterms for emulated serial ports " |
292 |
"(default is on when\n using configuration files, off" |
"(default is on when\n using configuration files or" |
293 |
" otherwise)\n"); |
" when X11 is used, off otherwise)\n"); |
|
#ifdef WITH_X11 |
|
294 |
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"); |
295 |
#endif /* WITH_X11 */ |
#endif /* WITH_X11 */ |
|
printf(" -y x set max_random_cycles_per_chunk to x" |
|
|
" (experimental)\n"); |
|
296 |
printf(" -Z n set nr of graphics cards, for emulating a " |
printf(" -Z n set nr of graphics cards, for emulating a " |
297 |
"dual-head or tripple-head\n" |
"dual-head or tripple-head\n" |
298 |
" environment (only for DECstation emulation)\n"); |
" environment (only for DECstation emulation)\n"); |
299 |
printf(" -z disp add disp as an X11 display to use for " |
printf(" -z disp add disp as an X11 display to use for " |
300 |
"framebuffers\n"); |
"framebuffers\n"); |
301 |
|
|
302 |
|
#ifdef UNSTABLE_DEVEL |
303 |
printf("\nUserland options:\n"); |
printf("\nUserland options:\n"); |
304 |
printf(" -u emul userland-only (syscall) emulation (use -H to" |
printf(" -u emul userland-only (syscall) emulation (use -H to" |
305 |
" get a list of\n available emulation modes)\n"); |
" get a list of\n available emulation modes)\n"); |
306 |
|
#endif |
307 |
|
|
308 |
printf("\nGeneral options:\n"); |
printf("\nGeneral options:\n"); |
309 |
printf(" -D guarantee fully deterministic behaviour\n"); |
printf(" -c cmd add cmd as a command to run before starting " |
310 |
|
"the simulation\n"); |
311 |
|
printf(" -D skip the srandom call at startup\n"); |
312 |
printf(" -H display a list of possible CPU and " |
printf(" -H display a list of possible CPU and " |
313 |
"machine types\n"); |
"machine types\n"); |
314 |
printf(" -h display this help message\n"); |
printf(" -h display this help message\n"); |
315 |
printf(" -K force the debugger to be entered at the end " |
printf(" -K force the debugger to be entered at the end " |
316 |
"of a simulation\n"); |
"of a simulation\n"); |
317 |
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"); |
|
318 |
printf(" -V start up in the single-step debugger, paused\n"); |
printf(" -V start up in the single-step debugger, paused\n"); |
319 |
printf(" -v verbose debug messages\n"); |
printf(" -v verbose debug messages\n"); |
320 |
printf("\n"); |
printf("\n"); |
345 |
char ***diskimagesp, int *n_diskimagesp) |
char ***diskimagesp, int *n_diskimagesp) |
346 |
{ |
{ |
347 |
int ch, res, using_switch_d = 0, using_switch_Z = 0; |
int ch, res, using_switch_d = 0, using_switch_Z = 0; |
348 |
|
int using_switch_e = 0, using_switch_E = 0; |
349 |
char *type = NULL, *subtype = NULL; |
char *type = NULL, *subtype = NULL; |
350 |
int n_cpus_set = 0; |
int n_cpus_set = 0; |
351 |
int msopts = 0; /* Machine-specific options used */ |
int msopts = 0; /* Machine-specific options used */ |
352 |
struct machine *m = emul_add_machine(emul, "default"); |
struct machine *m = emul_add_machine(emul, "default"); |
353 |
|
|
354 |
while ((ch = getopt(argc, argv, "BbC:Dd:E:e:HhI:iJj:KM:m:" |
char *opts = |
355 |
"Nn:Oo:p:QqRrSsTtUu:VvW:XxY:y:Z:z:")) != -1) { |
"C:c:Dd:E:e:G:HhI:iJj:KM:Nn:Oo:p:QqRrSs:tU" |
356 |
|
#ifdef UNSTABLE_DEVEL |
357 |
|
"u:" |
358 |
|
#endif |
359 |
|
"VvW:" |
360 |
|
#ifdef WITH_X11 |
361 |
|
"XxY:" |
362 |
|
#endif |
363 |
|
"Z:z:"; |
364 |
|
|
365 |
|
while ((ch = getopt(argc, argv, opts)) != -1) { |
366 |
switch (ch) { |
switch (ch) { |
|
case 'B': |
|
|
m->bintrans_enable = 0; |
|
|
msopts = 1; |
|
|
break; |
|
|
case 'b': |
|
|
m->old_bintrans_enable = 1; |
|
|
msopts = 1; |
|
|
break; |
|
367 |
case 'C': |
case 'C': |
368 |
m->cpu_name = strdup(optarg); |
m->cpu_name = strdup(optarg); |
369 |
msopts = 1; |
msopts = 1; |
370 |
break; |
break; |
371 |
|
case 'c': |
372 |
|
emul->n_debugger_cmds ++; |
373 |
|
emul->debugger_cmds = realloc(emul->debugger_cmds, |
374 |
|
emul->n_debugger_cmds * sizeof(char *)); |
375 |
|
if (emul->debugger_cmds == NULL) { |
376 |
|
fatal("out of memory\n"); |
377 |
|
exit(1); |
378 |
|
} |
379 |
|
emul->debugger_cmds[emul->n_debugger_cmds-1] = |
380 |
|
strdup(optarg); |
381 |
|
break; |
382 |
case 'D': |
case 'D': |
383 |
fully_deterministic = 1; |
skip_srandom_call = 1; |
384 |
break; |
break; |
385 |
case 'd': |
case 'd': |
386 |
/* diskimage_add() is called further down */ |
/* diskimage_add() is called further down */ |
396 |
msopts = 1; |
msopts = 1; |
397 |
break; |
break; |
398 |
case 'E': |
case 'E': |
399 |
|
if (using_switch_E ++ > 0) { |
400 |
|
fprintf(stderr, "-E already used.\n"); |
401 |
|
exit(1); |
402 |
|
} |
403 |
type = optarg; |
type = optarg; |
404 |
msopts = 1; |
msopts = 1; |
405 |
break; |
break; |
406 |
case 'e': |
case 'e': |
407 |
|
if (using_switch_e ++ > 0) { |
408 |
|
fprintf(stderr, "-e already used.\n"); |
409 |
|
exit(1); |
410 |
|
} |
411 |
subtype = optarg; |
subtype = optarg; |
412 |
msopts = 1; |
msopts = 1; |
413 |
break; |
break; |
414 |
|
case 'G': |
415 |
|
m->gdb.port = atoi(optarg); |
416 |
|
if (m->gdb.port < 1 || m->gdb.port > 65535) { |
417 |
|
fprintf(stderr, "Invalid debugger port %i.\n", |
418 |
|
m->gdb.port); |
419 |
|
exit(1); |
420 |
|
} |
421 |
|
/* Note: implicit -V */ |
422 |
|
single_step = ENTER_SINGLE_STEPPING; |
423 |
|
msopts = 1; |
424 |
|
break; |
425 |
case 'H': |
case 'H': |
426 |
machine_list_available_types_and_cpus(); |
machine_list_available_types_and_cpus(); |
427 |
exit(1); |
exit(1); |
430 |
exit(1); |
exit(1); |
431 |
case 'I': |
case 'I': |
432 |
m->emulated_hz = atoi(optarg); |
m->emulated_hz = atoi(optarg); |
|
m->automatic_clock_adjustment = 0; |
|
433 |
msopts = 1; |
msopts = 1; |
434 |
break; |
break; |
435 |
case 'i': |
case 'i': |
437 |
msopts = 1; |
msopts = 1; |
438 |
break; |
break; |
439 |
case 'J': |
case 'J': |
440 |
m->speed_tricks = 0; |
m->allow_instruction_combinations = 0; |
441 |
msopts = 1; |
msopts = 1; |
442 |
break; |
break; |
443 |
case 'j': |
case 'j': |
455 |
m->physical_ram_in_mb = atoi(optarg); |
m->physical_ram_in_mb = atoi(optarg); |
456 |
msopts = 1; |
msopts = 1; |
457 |
break; |
break; |
|
case 'm': |
|
|
m->max_instructions = atoi(optarg); |
|
|
msopts = 1; |
|
|
break; |
|
458 |
case 'N': |
case 'N': |
459 |
m->show_nr_of_instructions = 1; |
m->show_nr_of_instructions = 1; |
460 |
msopts = 1; |
msopts = 1; |
510 |
msopts = 1; |
msopts = 1; |
511 |
break; |
break; |
512 |
case 's': |
case 's': |
513 |
show_opcode_statistics = 1; |
machine_statistics_init(m, optarg); |
|
break; |
|
|
case 'T': |
|
|
m->single_step_on_bad_addr = 1; |
|
514 |
msopts = 1; |
msopts = 1; |
515 |
break; |
break; |
516 |
case 't': |
case 't': |
531 |
msopts = 1; |
msopts = 1; |
532 |
break; |
break; |
533 |
case 'V': |
case 'V': |
534 |
single_step = 1; |
single_step = ENTER_SINGLE_STEPPING; |
535 |
break; |
break; |
536 |
case 'v': |
case 'v': |
537 |
verbose ++; |
verbose ++; |
542 |
case 'X': |
case 'X': |
543 |
m->use_x11 = 1; |
m->use_x11 = 1; |
544 |
msopts = 1; |
msopts = 1; |
545 |
break; |
/* FALL-THROUGH */ |
546 |
case 'x': |
case 'x': |
547 |
console_allow_slaves(1); |
console_allow_slaves(1); |
548 |
break; |
break; |
549 |
case 'Y': |
case 'Y': |
550 |
m->x11_scaledown = atoi(optarg); |
m->x11_scaledown = atoi(optarg); |
551 |
|
if (m->x11_scaledown < -1) { |
552 |
|
m->x11_scaleup = - m->x11_scaledown; |
553 |
|
m->x11_scaledown = 1; |
554 |
|
} |
555 |
if (m->x11_scaledown < 1) { |
if (m->x11_scaledown < 1) { |
556 |
fprintf(stderr, "Invalid scaledown value.\n"); |
fprintf(stderr, "Invalid scaledown value.\n"); |
557 |
exit(1); |
exit(1); |
558 |
} |
} |
559 |
msopts = 1; |
msopts = 1; |
560 |
break; |
break; |
|
case 'y': |
|
|
m->max_random_cycles_per_chunk = atoi(optarg); |
|
|
msopts = 1; |
|
|
break; |
|
561 |
case 'Z': |
case 'Z': |
562 |
m->n_gfx_cards = atoi(optarg); |
m->n_gfx_cards = atoi(optarg); |
563 |
using_switch_Z = 1; |
using_switch_Z = 1; |
582 |
msopts = 1; |
msopts = 1; |
583 |
break; |
break; |
584 |
default: |
default: |
585 |
fprintf(stderr, "Invalid option.\n"); |
fprintf(stderr, "Run %s -h for help on command " |
586 |
usage(0); |
"line options.\n", progname); |
587 |
exit(1); |
exit(1); |
588 |
} |
} |
589 |
} |
} |
590 |
|
|
591 |
if (type != NULL) { |
if (type != NULL || subtype != NULL) { |
592 |
|
if (type == NULL) |
593 |
|
type = ""; |
594 |
if (subtype == NULL) |
if (subtype == NULL) |
595 |
subtype = ""; |
subtype = ""; |
596 |
res = machine_name_to_type(type, subtype, |
res = machine_name_to_type(type, subtype, |
606 |
extra_argv = argv; |
extra_argv = argv; |
607 |
|
|
608 |
|
|
|
if (!m->bintrans_enable && m->old_bintrans_enable) { |
|
|
fprintf(stderr, "You cannot both select old bintrans and" |
|
|
" disable bintrans at the same time.\n"); |
|
|
exit(1); |
|
|
} |
|
|
|
|
|
/* TODO: Remove this once there is a new bintrans system. */ |
|
|
if (m->bintrans_enable && !m->old_bintrans_enable) { |
|
|
m->bintrans_enable = 0; |
|
|
} |
|
|
|
|
609 |
if (m->machine_type == MACHINE_NONE && msopts) { |
if (m->machine_type == MACHINE_NONE && msopts) { |
610 |
fprintf(stderr, "Machine specific options used directly on " |
fprintf(stderr, "Machine specific options used directly on " |
611 |
"the command line, but no machine\nemulation specified?\n"); |
"the command line, but no machine\nemulation specified?\n"); |
613 |
} |
} |
614 |
|
|
615 |
|
|
616 |
/* -i, -r, -t are pretty verbose: */ |
/* -i and -r are pretty verbose: */ |
617 |
|
|
618 |
if (m->instruction_trace && !verbose) { |
if (m->instruction_trace && !verbose) { |
619 |
fprintf(stderr, "Implicitly %sturning on -v, because" |
fprintf(stderr, "Implicitly %sturning on -v, because" |
629 |
quiet_mode = 0; |
quiet_mode = 0; |
630 |
} |
} |
631 |
|
|
|
if (m->show_trace_tree && !verbose) { |
|
|
fprintf(stderr, "Implicitly %sturning on -v, because" |
|
|
" of -t\n", quiet_mode? "turning off -q and " : ""); |
|
|
verbose = 1; |
|
|
quiet_mode = 0; |
|
|
} |
|
|
|
|
632 |
|
|
633 |
/* |
/* |
634 |
* Usually, an executable filename must be supplied. |
* Usually, an executable filename must be supplied. |
675 |
exit(1); |
exit(1); |
676 |
} |
} |
677 |
|
|
|
if (m->bintrans_enable) { |
|
|
m->speed_tricks = 0; |
|
|
/* TODO: Print a warning about this? */ |
|
|
} |
|
|
|
|
|
if (m->n_breakpoints > 0 && m->bintrans_enable) { |
|
|
fprintf(stderr, "Breakpoints and dynamic 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 |
|
|
|
|
678 |
if (!using_switch_Z && !m->use_x11) |
if (!using_switch_Z && !m->use_x11) |
679 |
m->n_gfx_cards = 0; |
m->n_gfx_cards = 0; |
680 |
|
|
|
m->bintrans_enabled_from_start = m->bintrans_enable; |
|
|
|
|
681 |
return 0; |
return 0; |
682 |
} |
} |
683 |
|
|
694 |
*/ |
*/ |
695 |
int main(int argc, char *argv[]) |
int main(int argc, char *argv[]) |
696 |
{ |
{ |
697 |
|
/* Setting constants: */ |
698 |
|
const int constant_yes = 1; |
699 |
|
const int constant_true = 1; |
700 |
|
const int constant_no = 0; |
701 |
|
const int constant_false = 0; |
702 |
|
|
703 |
struct emul **emuls; |
struct emul **emuls; |
704 |
char **diskimages = NULL; |
char **diskimages = NULL; |
705 |
int n_diskimages = 0; |
int n_diskimages = 0; |
706 |
int n_emuls; |
int n_emuls; |
707 |
int i; |
int i; |
708 |
|
|
709 |
|
|
710 |
progname = argv[0]; |
progname = argv[0]; |
711 |
|
|
712 |
|
|
713 |
|
/* |
714 |
|
* Create the settings object, and add global settings to it: |
715 |
|
* |
716 |
|
* Read-only "constants": yes, no, true, false. |
717 |
|
* Global emulator settings: verbose, single_step, ... |
718 |
|
*/ |
719 |
|
global_settings = settings_new(); |
720 |
|
|
721 |
|
settings_add(global_settings, "yes", 0, SETTINGS_TYPE_INT, |
722 |
|
SETTINGS_FORMAT_YESNO, (void *)&constant_yes); |
723 |
|
settings_add(global_settings, "no", 0, SETTINGS_TYPE_INT, |
724 |
|
SETTINGS_FORMAT_YESNO, (void *)&constant_no); |
725 |
|
settings_add(global_settings, "true", 0, SETTINGS_TYPE_INT, |
726 |
|
SETTINGS_FORMAT_BOOL, (void *)&constant_true); |
727 |
|
settings_add(global_settings, "false", 0, SETTINGS_TYPE_INT, |
728 |
|
SETTINGS_FORMAT_BOOL, (void *)&constant_false); |
729 |
|
|
730 |
|
settings_add(global_settings, "single_step", 0, |
731 |
|
SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, (void *)&single_step); |
732 |
|
settings_add(global_settings, "force_debugger_at_exit", 1, |
733 |
|
SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, |
734 |
|
(void *)&force_debugger_at_exit); |
735 |
|
settings_add(global_settings, "verbose", 1, |
736 |
|
SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, (void *)&verbose); |
737 |
|
settings_add(global_settings, "quiet_mode", 1, |
738 |
|
SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, (void *)&quiet_mode); |
739 |
|
|
740 |
|
/* Initialize all emulator subsystems: */ |
741 |
console_init(); |
console_init(); |
742 |
cpu_init(); |
cpu_init(); |
743 |
device_init(); |
device_init(); |
744 |
machine_init(); |
machine_init(); |
745 |
|
timer_init(); |
746 |
useremul_init(); |
useremul_init(); |
747 |
|
|
748 |
emuls = malloc(sizeof(struct emul *)); |
emuls = malloc(sizeof(struct emul *)); |
758 |
fprintf(stderr, "out of memory\n"); |
fprintf(stderr, "out of memory\n"); |
759 |
exit(1); |
exit(1); |
760 |
} |
} |
761 |
|
settings_add(global_settings, "emul[0]", 1, |
762 |
|
SETTINGS_TYPE_SUBSETTINGS, 0, emuls[0]->settings); |
763 |
|
|
764 |
get_cmd_args(argc, argv, emuls[0], &diskimages, &n_diskimages); |
get_cmd_args(argc, argv, emuls[0], &diskimages, &n_diskimages); |
765 |
|
|
766 |
if (!fully_deterministic) { |
if (!skip_srandom_call) { |
767 |
/* TODO: More than just time(). Use gettimeofday(). */ |
struct timeval tv; |
768 |
srandom(time(NULL) ^ (getpid() << 12)); |
gettimeofday(&tv, NULL); |
769 |
} 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); |
|
|
} |
|
770 |
} |
} |
771 |
|
|
772 |
/* Print startup message: */ |
/* Print startup message: */ |
773 |
debug("GXemul"); |
debug("GXemul"); |
774 |
#ifdef VERSION |
#ifdef VERSION |
775 |
debug("-" VERSION); |
debug(" " VERSION); |
776 |
#endif |
#endif |
777 |
debug(" Copyright (C) 2003-2005 Anders Gavare\n"); |
debug(" Copyright (C) 2003-2006 Anders Gavare\n"); |
778 |
debug("Read the source code and/or documentation for " |
debug("Read the source code and/or documentation for " |
779 |
"other Copyright messages.\n\n"); |
"other Copyright messages.\n\n"); |
780 |
|
|
781 |
if (emuls[0]->machines[0]->machine_type == MACHINE_NONE) |
if (emuls[0]->machines[0]->machine_type == MACHINE_NONE) { |
782 |
n_emuls --; |
n_emuls --; |
783 |
else { |
} else { |
784 |
for (i=0; i<n_diskimages; i++) |
for (i=0; i<n_diskimages; i++) |
785 |
diskimage_add(emuls[0]->machines[0], diskimages[i]); |
diskimage_add(emuls[0]->machines[0], diskimages[i]); |
786 |
} |
} |
805 |
/* Initialize emulations from config files: */ |
/* Initialize emulations from config files: */ |
806 |
for (i=1; i<argc; i++) { |
for (i=1; i<argc; i++) { |
807 |
if (argv[i][0] == '@') { |
if (argv[i][0] == '@') { |
808 |
|
char tmpstr[50]; |
809 |
char *s = argv[i] + 1; |
char *s = argv[i] + 1; |
810 |
if (strlen(s) == 0 && i+1 < argc && |
if (strlen(s) == 0 && i+1 < argc && |
811 |
argv[i+1][0] != '@') { |
argv[i+1][0] != '@') { |
818 |
fprintf(stderr, "out of memory\n"); |
fprintf(stderr, "out of memory\n"); |
819 |
exit(1); |
exit(1); |
820 |
} |
} |
|
emuls[n_emuls - 1] = |
|
|
emul_create_from_configfile(s); |
|
821 |
|
|
822 |
/* Always allow slave xterms when using multiple |
/* Always allow slave xterms when using multiple |
823 |
emulations: */ |
emulations: */ |
824 |
console_allow_slaves(1); |
console_allow_slaves(1); |
825 |
|
|
826 |
|
/* Destroy the temporary emuls[0], since it will |
827 |
|
be overwritten: */ |
828 |
|
if (n_emuls == 1) { |
829 |
|
emul_destroy(emuls[0]); |
830 |
|
settings_remove(global_settings, "emul[0]"); |
831 |
|
} |
832 |
|
|
833 |
|
emuls[n_emuls - 1] = |
834 |
|
emul_create_from_configfile(s); |
835 |
|
|
836 |
|
snprintf(tmpstr, sizeof(tmpstr), "emul[%i]", n_emuls-1); |
837 |
|
settings_add(global_settings, tmpstr, 1, |
838 |
|
SETTINGS_TYPE_SUBSETTINGS, 0, |
839 |
|
emuls[n_emuls-1]->settings); |
840 |
} |
} |
841 |
} |
} |
842 |
|
|
843 |
if (n_emuls == 0) { |
if (n_emuls == 0) { |
844 |
fprintf(stderr, "No emulations defined.\n"); |
fprintf(stderr, "No emulations defined. Maybe you forgot to " |
845 |
|
"use -E xx and/or -e yy, to specify\nthe machine type." |
846 |
|
" For example:\n\n %s -e 3max -d disk.img\n\n" |
847 |
|
"to boot an emulated DECstation 5000/200 with a disk " |
848 |
|
"image.\n", progname); |
849 |
exit(1); |
exit(1); |
850 |
} |
} |
851 |
|
|
852 |
device_set_exit_on_error(0); |
device_set_exit_on_error(0); |
853 |
|
console_warn_if_slaves_are_needed(1); |
854 |
|
|
855 |
|
|
856 |
/* Run all emulations: */ |
/* Run all emulations: */ |
857 |
emul_run(emuls, n_emuls); |
emul_run(emuls, n_emuls); |
858 |
|
|
859 |
|
|
860 |
|
/* |
861 |
|
* Deinitialize everything: |
862 |
|
*/ |
863 |
|
|
864 |
|
console_deinit(); |
865 |
|
|
866 |
|
for (i=0; i<n_emuls; i++) |
867 |
|
emul_destroy(emuls[i]); |
868 |
|
|
869 |
|
settings_remove_all(global_settings); |
870 |
|
settings_destroy(global_settings); |
871 |
|
|
872 |
return 0; |
return 0; |
873 |
} |
} |
874 |
|
|