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.243 2005/08/07 17:42:02 debug Exp $ |
* $Id: main.c,v 1.311 2007/06/28 14:58:38 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 |
|
#include "useremul.h" |
49 |
|
|
50 |
|
|
51 |
extern volatile int single_step; |
extern int single_step; |
52 |
extern int force_debugger_at_exit; |
extern int force_debugger_at_exit; |
|
extern int show_opcode_statistics; |
|
53 |
|
|
54 |
extern int optind; |
extern int optind; |
55 |
extern char *optarg; |
extern char *optarg; |
56 |
|
|
57 |
|
struct settings *global_settings; |
58 |
|
|
59 |
int extra_argc; |
int extra_argc; |
60 |
char **extra_argv; |
char **extra_argv; |
61 |
char *progname; |
char *progname; |
62 |
|
|
63 |
int fully_deterministic = 0; |
size_t dyntrans_cache_size = DEFAULT_DYNTRANS_CACHE_SIZE; |
64 |
|
static int skip_srandom_call = 0; |
65 |
|
|
66 |
|
|
67 |
/***************************************************************************** |
/***************************************************************************** |
196 |
*/ |
*/ |
197 |
static void usage(int longusage) |
static void usage(int longusage) |
198 |
{ |
{ |
199 |
printf("GXemul"); |
printf("GXemul "VERSION" Copyright (C) 2003-2007 Anders Gavare\n"); |
|
#ifdef VERSION |
|
|
printf("-" VERSION); |
|
|
#endif |
|
|
printf(" Copyright (C) 2003-2005 Anders Gavare\n"); |
|
200 |
printf("Read the source code and/or documentation for " |
printf("Read the source code and/or documentation for " |
201 |
"other Copyright messages.\n"); |
"other Copyright messages.\n"); |
202 |
|
|
203 |
printf("\nusage: %s [machine, other, and general options] [file " |
printf("\nusage: %s [machine, other, and general options] [file " |
204 |
"[...]]\n", progname); |
"[...]]\n", progname); |
205 |
printf(" or %s [general options] @configfile [...]\n", progname); |
printf(" or %s [general options] @configfile\n", progname); |
206 |
printf(" or %s [userland, other, and general options] file " |
printf(" or %s [userland, other, and general options] file " |
207 |
"[args ...]\n", progname); |
"[args ...]\n", progname); |
208 |
|
|
219 |
"with -E.)\n"); |
"with -E.)\n"); |
220 |
|
|
221 |
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 |
|
222 |
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 " |
223 |
"list of types.)\n"); |
"list of types.)\n"); |
224 |
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:\"" |
232 |
printf(" gH;S; set geometry to H heads and S" |
printf(" gH;S; set geometry to H heads and S" |
233 |
" sectors-per-track\n"); |
" sectors-per-track\n"); |
234 |
printf(" i IDE\n"); |
printf(" i IDE\n"); |
235 |
|
printf(" oOFS; set base offset to OFS (for ISO9660" |
236 |
|
" filesystems)\n"); |
237 |
printf(" r read-only (don't allow changes to the" |
printf(" r read-only (don't allow changes to the" |
238 |
" file)\n"); |
" file)\n"); |
239 |
printf(" s SCSI\n"); |
printf(" s SCSI\n"); |
240 |
printf(" t tape\n"); |
printf(" t tape\n"); |
241 |
|
printf(" V add an overlay\n"); |
242 |
printf(" 0-7 force a specific ID\n"); |
printf(" 0-7 force a specific ID\n"); |
243 |
printf(" -I x emulate clock interrupts at x Hz (affects" |
printf(" -I hz set the main cpu frequency to hz (not used by " |
244 |
" rtc devices only, not\n"); |
"all combinations\n of machines and guest OSes)\n"); |
|
printf(" actual runtime speed) (this disables automatic" |
|
|
" clock adjustments)\n"); |
|
245 |
printf(" -i display each instruction as it is executed\n"); |
printf(" -i display each instruction as it is executed\n"); |
246 |
printf(" -J disable some speed tricks\n"); |
printf(" -J disable dyntrans instruction combinations\n"); |
247 |
printf(" -j name set the name of the kernel, for example:\n"); |
printf(" -j name set the name of the kernel; for DECstation " |
248 |
printf(" -j netbsd for NetBSD/pmax\n"); |
"emulation, this passes\n the name to the bootloader," |
249 |
printf(" -j bsd for OpenBSD/pmax\n"); |
" for example:\n"); |
250 |
printf(" -j vmunix for Ultrix/RISC\n"); |
printf(" -j netbsd (NetBSD/pmax) " |
251 |
|
"-j bsd (OpenBSD/pmax)\n"); |
252 |
|
printf(" -j vmsprite (Sprite/pmax) " |
253 |
|
"-j vmunix (Ultrix/RISC)\n"); |
254 |
|
printf(" For other emulation modes, if the boot disk is an" |
255 |
|
" ISO9660\n filesystem, -j sets the name of the" |
256 |
|
" kernel to load.\n"); |
257 |
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"); |
|
258 |
printf(" -N display nr of instructions/second average, at" |
printf(" -N display nr of instructions/second average, at" |
259 |
" regular intervals\n"); |
" regular intervals\n"); |
260 |
printf(" -n nr set nr of CPUs (for SMP experiments)\n"); |
printf(" -n nr set nr of CPUs (for SMP experiments)\n"); |
261 |
printf(" -O force netboot (tftp instead of disk), even when" |
printf(" -O force netboot (tftp instead of disk), even when" |
262 |
" a disk image is\n" |
" a disk image is\n" |
263 |
" present (for DECstation, SGI, and ARC emulation)\n"); |
" present (for DECstation, SGI, and ARC emulation)\n"); |
264 |
printf(" -o arg set the boot argument (for DEC, ARC, or SGI" |
printf(" -o arg set the boot argument, for DEC, ARC, or SGI" |
265 |
" emulation).\n"); |
" emulation\n"); |
266 |
printf(" Default arg for DEC is '-a', for ARC '-aN'.\n"); |
printf(" (default arg for DEC is -a, for ARC/SGI -aN)\n"); |
267 |
printf(" -p pc add a breakpoint (remember to use the '0x' " |
printf(" -p pc add a breakpoint (remember to use the '0x' " |
268 |
"prefix for hex!)\n"); |
"prefix for hex!)\n"); |
269 |
printf(" -Q no built-in PROM emulation (use this for " |
printf(" -Q no built-in PROM emulation (use this for " |
272 |
printf(" -r register dumps before every instruction\n"); |
printf(" -r register dumps before every instruction\n"); |
273 |
printf(" -S initialize emulated RAM to random bytes, " |
printf(" -S initialize emulated RAM to random bytes, " |
274 |
"instead of zeroes\n"); |
"instead of zeroes\n"); |
275 |
printf(" -T enter the single-step debugger on " |
printf(" -s f:name write statistics to file 'name', " |
276 |
"unimplemented memory accesses\n"); |
"f is one or more of the following:\n"); |
277 |
|
printf(" v virtual program counter\n"); |
278 |
|
printf(" p physical equivalent of program counter\n"); |
279 |
|
printf(" i internal ic->f representation of " |
280 |
|
"the program counter\n"); |
281 |
|
printf(" and optionally:\n"); |
282 |
|
printf(" d disable statistics gathering at " |
283 |
|
"startup\n"); |
284 |
|
printf(" o overwrite instead of append\n"); |
285 |
|
printf(" -T halt on non-existant memory accesses\n"); |
286 |
printf(" -t show function trace tree\n"); |
printf(" -t show function trace tree\n"); |
287 |
printf(" -U enable slow_serial_interrupts_hack_for_linux\n"); |
printf(" -U enable slow_serial_interrupts_hack_for_linux\n"); |
288 |
#ifdef WITH_X11 |
#ifdef WITH_X11 |
289 |
printf(" -X use X11\n"); |
printf(" -X use X11\n"); |
|
#endif /* WITH_X11 */ |
|
290 |
printf(" -x open up new xterms for emulated serial ports " |
printf(" -x open up new xterms for emulated serial ports " |
291 |
"(default is on when\n using configuration files, off" |
"(default is on when\n using configuration files or" |
292 |
" otherwise)\n"); |
" when X11 is used, off otherwise)\n"); |
|
#ifdef WITH_X11 |
|
293 |
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"); |
294 |
#endif /* WITH_X11 */ |
#endif /* WITH_X11 */ |
|
printf(" -y x set max_random_cycles_per_chunk to x" |
|
|
" (experimental)\n"); |
|
295 |
printf(" -Z n set nr of graphics cards, for emulating a " |
printf(" -Z n set nr of graphics cards, for emulating a " |
296 |
"dual-head or tripple-head\n" |
"dual-head or tripple-head\n" |
297 |
" environment (only for DECstation emulation)\n"); |
" environment (only for DECstation emulation)\n"); |
303 |
" get a list of\n available emulation modes)\n"); |
" get a list of\n available emulation modes)\n"); |
304 |
|
|
305 |
printf("\nGeneral options:\n"); |
printf("\nGeneral options:\n"); |
306 |
printf(" -D guarantee fully deterministic behaviour\n"); |
printf(" -c cmd add cmd as a command to run before starting " |
307 |
|
"the simulation\n"); |
308 |
|
printf(" -D skip the srandom call at startup\n"); |
309 |
printf(" -H display a list of possible CPU and " |
printf(" -H display a list of possible CPU and " |
310 |
"machine types\n"); |
"machine types\n"); |
311 |
printf(" -h display this help message\n"); |
printf(" -h display this help message\n"); |
312 |
|
printf(" -k n set dyntrans translation caches to n MB (default" |
313 |
|
" size is %i MB)\n", DEFAULT_DYNTRANS_CACHE_SIZE / 1048576); |
314 |
printf(" -K force the debugger to be entered at the end " |
printf(" -K force the debugger to be entered at the end " |
315 |
"of a simulation\n"); |
"of a simulation\n"); |
316 |
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"); |
|
317 |
printf(" -V start up in the single-step debugger, paused\n"); |
printf(" -V start up in the single-step debugger, paused\n"); |
318 |
printf(" -v verbose debug messages\n"); |
printf(" -v verbose debug messages\n"); |
319 |
printf("\n"); |
printf("\n"); |
326 |
"To load a raw binary into memory, add \"address:\" in front " |
"To load a raw binary into memory, add \"address:\" in front " |
327 |
"of the filename,\n" |
"of the filename,\n" |
328 |
"or \"address:skiplen:\" or \"address:skiplen:initialpc:\".\n" |
"or \"address:skiplen:\" or \"address:skiplen:initialpc:\".\n" |
329 |
"Examples:\n" |
"\nExamples:\n" |
330 |
" 0xbfc00000:rom.bin for a raw ROM image\n" |
" 0xbfc00000:rom.bin for a raw ROM image\n" |
331 |
" 0xbfc00000:0x100:rom.bin for an image with " |
" 0xbfc00000:0x100:rom.bin for an image with " |
332 |
"0x100 bytes header\n" |
"0x100 bytes header\n" |
333 |
" 0xbfc00000:0x100:0xbfc00884:rom.bin " |
" 0xbfc00000:0x100:0xbfc00884:rom.bin " |
334 |
"start with pc=0xbfc00884\n"); |
"start with pc=0xbfc00884\n\n"); |
335 |
} |
} |
336 |
|
|
337 |
|
|
344 |
char ***diskimagesp, int *n_diskimagesp) |
char ***diskimagesp, int *n_diskimagesp) |
345 |
{ |
{ |
346 |
int ch, res, using_switch_d = 0, using_switch_Z = 0; |
int ch, res, using_switch_d = 0, using_switch_Z = 0; |
347 |
|
int using_switch_e = 0, using_switch_E = 0; |
348 |
char *type = NULL, *subtype = NULL; |
char *type = NULL, *subtype = NULL; |
349 |
int n_cpus_set = 0; |
int n_cpus_set = 0; |
350 |
int msopts = 0; /* Machine-specific options used */ |
int msopts = 0; /* Machine-specific options used */ |
351 |
struct machine *m = emul_add_machine(emul, "default"); |
struct machine *m = emul_add_machine(emul, NULL); |
352 |
|
|
353 |
|
char *opts = |
354 |
|
"C:c:Dd:E:e:HhI:iJj:k:KM:Nn:Oo:p:QqRrSs:TtUu:VvW:" |
355 |
|
#ifdef WITH_X11 |
356 |
|
"XxY:" |
357 |
|
#endif |
358 |
|
"Z:z:"; |
359 |
|
|
360 |
while ((ch = getopt(argc, argv, "ABC:Dd:E:e:HhI:iJj:KM:m:" |
while ((ch = getopt(argc, argv, opts)) != -1) { |
|
"Nn:Oo:p:QqRrSsTtUu:VvW:XxY:y:Z:z:")) != -1) { |
|
361 |
switch (ch) { |
switch (ch) { |
|
case 'A': |
|
|
m->dyntrans_alignment_check = 0; |
|
|
msopts = 1; |
|
|
break; |
|
|
case 'B': |
|
|
m->bintrans_enable = 0; |
|
|
msopts = 1; |
|
|
break; |
|
362 |
case 'C': |
case 'C': |
363 |
m->cpu_name = strdup(optarg); |
CHECK_ALLOCATION(m->cpu_name = strdup(optarg)); |
364 |
msopts = 1; |
msopts = 1; |
365 |
break; |
break; |
366 |
|
case 'c': |
367 |
|
emul->n_debugger_cmds ++; |
368 |
|
CHECK_ALLOCATION(emul->debugger_cmds = |
369 |
|
realloc(emul->debugger_cmds, |
370 |
|
emul->n_debugger_cmds * sizeof(char *))); |
371 |
|
CHECK_ALLOCATION(emul->debugger_cmds[emul-> |
372 |
|
n_debugger_cmds-1] = strdup(optarg)); |
373 |
|
break; |
374 |
case 'D': |
case 'D': |
375 |
fully_deterministic = 1; |
skip_srandom_call = 1; |
376 |
break; |
break; |
377 |
case 'd': |
case 'd': |
378 |
/* diskimage_add() is called further down */ |
/* diskimage_add() is called further down */ |
379 |
(*n_diskimagesp) ++; |
(*n_diskimagesp) ++; |
380 |
(*diskimagesp) = realloc(*diskimagesp, |
CHECK_ALLOCATION( (*diskimagesp) = |
381 |
sizeof(char *) * (*n_diskimagesp)); |
realloc(*diskimagesp, |
382 |
if (*diskimagesp == NULL) { |
sizeof(char *) * (*n_diskimagesp)) ); |
383 |
fprintf(stderr, "out of memory\n"); |
CHECK_ALLOCATION( (*diskimagesp)[(*n_diskimagesp) - 1] = |
384 |
exit(1); |
strdup(optarg) ); |
|
} |
|
|
(*diskimagesp)[(*n_diskimagesp) - 1] = strdup(optarg); |
|
385 |
using_switch_d = 1; |
using_switch_d = 1; |
386 |
msopts = 1; |
msopts = 1; |
387 |
break; |
break; |
388 |
case 'E': |
case 'E': |
389 |
|
if (using_switch_E ++ > 0) { |
390 |
|
fprintf(stderr, "-E already used.\n"); |
391 |
|
exit(1); |
392 |
|
} |
393 |
type = optarg; |
type = optarg; |
394 |
msopts = 1; |
msopts = 1; |
395 |
break; |
break; |
396 |
case 'e': |
case 'e': |
397 |
|
if (using_switch_e ++ > 0) { |
398 |
|
fprintf(stderr, "-e already used.\n"); |
399 |
|
exit(1); |
400 |
|
} |
401 |
subtype = optarg; |
subtype = optarg; |
402 |
msopts = 1; |
msopts = 1; |
403 |
break; |
break; |
409 |
exit(1); |
exit(1); |
410 |
case 'I': |
case 'I': |
411 |
m->emulated_hz = atoi(optarg); |
m->emulated_hz = atoi(optarg); |
|
m->automatic_clock_adjustment = 0; |
|
412 |
msopts = 1; |
msopts = 1; |
413 |
break; |
break; |
414 |
case 'i': |
case 'i': |
416 |
msopts = 1; |
msopts = 1; |
417 |
break; |
break; |
418 |
case 'J': |
case 'J': |
419 |
m->speed_tricks = 0; |
m->allow_instruction_combinations = 0; |
420 |
msopts = 1; |
msopts = 1; |
421 |
break; |
break; |
422 |
case 'j': |
case 'j': |
423 |
m->boot_kernel_filename = strdup(optarg); |
CHECK_ALLOCATION(m->boot_kernel_filename = |
424 |
if (m->boot_kernel_filename == NULL) { |
strdup(optarg)); |
425 |
fprintf(stderr, "out of memory\n"); |
msopts = 1; |
426 |
|
break; |
427 |
|
case 'k': |
428 |
|
dyntrans_cache_size = atoi(optarg) * 1048576; |
429 |
|
if (dyntrans_cache_size < 1) { |
430 |
|
fprintf(stderr, "The dyntrans cache size must" |
431 |
|
" be at least 1 MB.\n"); |
432 |
exit(1); |
exit(1); |
433 |
} |
} |
|
msopts = 1; |
|
434 |
break; |
break; |
435 |
case 'K': |
case 'K': |
436 |
force_debugger_at_exit = 1; |
force_debugger_at_exit = 1; |
439 |
m->physical_ram_in_mb = atoi(optarg); |
m->physical_ram_in_mb = atoi(optarg); |
440 |
msopts = 1; |
msopts = 1; |
441 |
break; |
break; |
|
case 'm': |
|
|
m->max_instructions = atoi(optarg); |
|
|
msopts = 1; |
|
|
break; |
|
442 |
case 'N': |
case 'N': |
443 |
m->show_nr_of_instructions = 1; |
m->show_nr_of_instructions = 1; |
444 |
msopts = 1; |
msopts = 1; |
453 |
msopts = 1; |
msopts = 1; |
454 |
break; |
break; |
455 |
case 'o': |
case 'o': |
456 |
m->boot_string_argument = strdup(optarg); |
CHECK_ALLOCATION(m->boot_string_argument = |
457 |
if (m->boot_string_argument == NULL) { |
strdup(optarg)); |
|
fprintf(stderr, "out of memory\n"); |
|
|
exit(1); |
|
|
} |
|
458 |
msopts = 1; |
msopts = 1; |
459 |
break; |
break; |
460 |
case 'p': |
case 'p': |
461 |
if (m->n_breakpoints >= MAX_BREAKPOINTS) { |
machine_add_breakpoint_string(m, optarg); |
|
fprintf(stderr, "too many breakpoints\n"); |
|
|
exit(1); |
|
|
} |
|
|
m->breakpoint_string[m->n_breakpoints] = strdup(optarg); |
|
|
if (m->breakpoint_string[m->n_breakpoints] == NULL) { |
|
|
fprintf(stderr, "out of memory\n"); |
|
|
exit(1); |
|
|
} |
|
|
m->breakpoint_flags[m->n_breakpoints] = 0; |
|
|
m->n_breakpoints ++; |
|
462 |
msopts = 1; |
msopts = 1; |
463 |
break; |
break; |
464 |
case 'Q': |
case 'Q': |
481 |
msopts = 1; |
msopts = 1; |
482 |
break; |
break; |
483 |
case 's': |
case 's': |
484 |
show_opcode_statistics = 1; |
machine_statistics_init(m, optarg); |
485 |
|
msopts = 1; |
486 |
break; |
break; |
487 |
case 'T': |
case 'T': |
488 |
m->single_step_on_bad_addr = 1; |
m->halt_on_nonexistant_memaccess = 1; |
489 |
msopts = 1; |
msopts = 1; |
490 |
break; |
break; |
491 |
case 't': |
case 't': |
497 |
msopts = 1; |
msopts = 1; |
498 |
break; |
break; |
499 |
case 'u': |
case 'u': |
500 |
m->userland_emul = strdup(optarg); |
CHECK_ALLOCATION(m->userland_emul = strdup(optarg)); |
|
if (m->userland_emul == NULL) { |
|
|
fprintf(stderr, "out of memory\n"); |
|
|
exit(1); |
|
|
} |
|
501 |
m->machine_type = MACHINE_USERLAND; |
m->machine_type = MACHINE_USERLAND; |
502 |
msopts = 1; |
msopts = 1; |
503 |
break; |
break; |
504 |
case 'V': |
case 'V': |
505 |
single_step = 1; |
single_step = ENTER_SINGLE_STEPPING; |
506 |
break; |
break; |
507 |
case 'v': |
case 'v': |
508 |
verbose ++; |
verbose ++; |
511 |
internal_w(optarg); |
internal_w(optarg); |
512 |
exit(0); |
exit(0); |
513 |
case 'X': |
case 'X': |
514 |
m->use_x11 = 1; |
m->x11_md.in_use = 1; |
515 |
msopts = 1; |
msopts = 1; |
516 |
break; |
/* FALL-THROUGH */ |
517 |
case 'x': |
case 'x': |
518 |
console_allow_slaves(1); |
console_allow_slaves(1); |
519 |
break; |
break; |
520 |
case 'Y': |
case 'Y': |
521 |
m->x11_scaledown = atoi(optarg); |
m->x11_md.scaledown = atoi(optarg); |
522 |
if (m->x11_scaledown < 1) { |
if (m->x11_md.scaledown < -1) { |
523 |
|
m->x11_md.scaleup = - m->x11_md.scaledown; |
524 |
|
m->x11_md.scaledown = 1; |
525 |
|
} |
526 |
|
if (m->x11_md.scaledown < 1) { |
527 |
fprintf(stderr, "Invalid scaledown value.\n"); |
fprintf(stderr, "Invalid scaledown value.\n"); |
528 |
exit(1); |
exit(1); |
529 |
} |
} |
530 |
msopts = 1; |
msopts = 1; |
531 |
break; |
break; |
|
case 'y': |
|
|
m->max_random_cycles_per_chunk = atoi(optarg); |
|
|
msopts = 1; |
|
|
break; |
|
532 |
case 'Z': |
case 'Z': |
533 |
m->n_gfx_cards = atoi(optarg); |
m->n_gfx_cards = atoi(optarg); |
534 |
using_switch_Z = 1; |
using_switch_Z = 1; |
535 |
msopts = 1; |
msopts = 1; |
536 |
break; |
break; |
537 |
case 'z': |
case 'z': |
538 |
m->x11_n_display_names ++; |
m->x11_md.n_display_names ++; |
539 |
m->x11_display_names = realloc( |
CHECK_ALLOCATION(m->x11_md.display_names = realloc( |
540 |
m->x11_display_names, |
m->x11_md.display_names, |
541 |
m->x11_n_display_names * sizeof(char *)); |
m->x11_md.n_display_names * sizeof(char *))); |
542 |
if (m->x11_display_names == NULL) { |
CHECK_ALLOCATION(m->x11_md.display_names[ |
543 |
fprintf(stderr, "out of memory\n"); |
m->x11_md.n_display_names-1] = strdup(optarg)); |
|
exit(1); |
|
|
} |
|
|
m->x11_display_names[m->x11_n_display_names-1] = |
|
|
strdup(optarg); |
|
|
if (m->x11_display_names |
|
|
[m->x11_n_display_names-1] == NULL) { |
|
|
fprintf(stderr, "out of memory\n"); |
|
|
exit(1); |
|
|
} |
|
544 |
msopts = 1; |
msopts = 1; |
545 |
break; |
break; |
546 |
default: |
default: |
591 |
quiet_mode = 0; |
quiet_mode = 0; |
592 |
} |
} |
593 |
|
|
|
if ((m->instruction_trace || m->register_dump || m->show_trace_tree) |
|
|
&& m->bintrans_enable) { |
|
|
fprintf(stderr, "Implicitly turning off bintrans.\n"); |
|
|
m->bintrans_enable = 0; |
|
|
} |
|
|
|
|
594 |
|
|
595 |
/* |
/* |
596 |
* Usually, an executable filename must be supplied. |
* Usually, an executable filename must be supplied. |
625 |
else |
else |
626 |
s2 ++; |
s2 ++; |
627 |
|
|
628 |
m->boot_kernel_filename = strdup(s2); |
CHECK_ALLOCATION(m->boot_kernel_filename = strdup(s2)); |
|
if (m->boot_kernel_filename == NULL) { |
|
|
fprintf(stderr, "out of memory\n"); |
|
|
exit(1); |
|
|
} |
|
629 |
} |
} |
630 |
|
|
631 |
if (m->n_gfx_cards < 0 || m->n_gfx_cards > 3) { |
if (m->n_gfx_cards < 0 || m->n_gfx_cards > 3) { |
633 |
exit(1); |
exit(1); |
634 |
} |
} |
635 |
|
|
636 |
if (m->bintrans_enable) { |
if (!using_switch_Z && !m->x11_md.in_use) |
|
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 |
|
|
|
|
|
if (!using_switch_Z && !m->use_x11) |
|
637 |
m->n_gfx_cards = 0; |
m->n_gfx_cards = 0; |
638 |
|
|
|
m->bintrans_enabled_from_start = m->bintrans_enable; |
|
|
|
|
639 |
return 0; |
return 0; |
640 |
} |
} |
641 |
|
|
652 |
*/ |
*/ |
653 |
int main(int argc, char *argv[]) |
int main(int argc, char *argv[]) |
654 |
{ |
{ |
655 |
struct emul **emuls; |
/* Setting constants: */ |
656 |
|
const int constant_yes = 1; |
657 |
|
const int constant_true = 1; |
658 |
|
const int constant_no = 0; |
659 |
|
const int constant_false = 0; |
660 |
|
|
661 |
|
struct emul *emul; |
662 |
|
int config_file = 0; |
663 |
|
|
664 |
char **diskimages = NULL; |
char **diskimages = NULL; |
665 |
int n_diskimages = 0; |
int n_diskimages = 0; |
|
int n_emuls; |
|
666 |
int i; |
int i; |
667 |
|
|
668 |
|
|
669 |
progname = argv[0]; |
progname = argv[0]; |
670 |
|
|
671 |
|
|
672 |
|
/* |
673 |
|
* Create the settings object, and add global settings to it: |
674 |
|
* |
675 |
|
* Read-only "constants": yes, no, true, false. |
676 |
|
* Global emulator settings: verbose, single_step, ... |
677 |
|
*/ |
678 |
|
global_settings = settings_new(); |
679 |
|
|
680 |
|
settings_add(global_settings, "yes", 0, SETTINGS_TYPE_INT, |
681 |
|
SETTINGS_FORMAT_YESNO, (void *)&constant_yes); |
682 |
|
settings_add(global_settings, "no", 0, SETTINGS_TYPE_INT, |
683 |
|
SETTINGS_FORMAT_YESNO, (void *)&constant_no); |
684 |
|
settings_add(global_settings, "true", 0, SETTINGS_TYPE_INT, |
685 |
|
SETTINGS_FORMAT_BOOL, (void *)&constant_true); |
686 |
|
settings_add(global_settings, "false", 0, SETTINGS_TYPE_INT, |
687 |
|
SETTINGS_FORMAT_BOOL, (void *)&constant_false); |
688 |
|
|
689 |
|
/* Read-only settings: */ |
690 |
|
settings_add(global_settings, "single_step", 0, |
691 |
|
SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, (void *)&single_step); |
692 |
|
|
693 |
|
/* Read/write settings: */ |
694 |
|
settings_add(global_settings, "force_debugger_at_exit", 1, |
695 |
|
SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, |
696 |
|
(void *)&force_debugger_at_exit); |
697 |
|
settings_add(global_settings, "verbose", 1, |
698 |
|
SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, (void *)&verbose); |
699 |
|
settings_add(global_settings, "quiet_mode", 1, |
700 |
|
SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, (void *)&quiet_mode); |
701 |
|
|
702 |
|
/* Initialize all emulator subsystems: */ |
703 |
console_init(); |
console_init(); |
704 |
cpu_init(); |
cpu_init(); |
705 |
device_init(); |
device_init(); |
706 |
machine_init(); |
machine_init(); |
707 |
|
timer_init(); |
708 |
useremul_init(); |
useremul_init(); |
709 |
|
|
710 |
emuls = malloc(sizeof(struct emul *)); |
/* Create a simple emulation setup: */ |
711 |
if (emuls == NULL) { |
emul = emul_new(NULL); |
712 |
fprintf(stderr, "out of memory\n"); |
settings_add(global_settings, "emul", 1, |
713 |
exit(1); |
SETTINGS_TYPE_SUBSETTINGS, 0, emul->settings); |
714 |
} |
|
715 |
|
get_cmd_args(argc, argv, emul, &diskimages, &n_diskimages); |
716 |
/* Allocate space for a simple emul setup: */ |
|
717 |
n_emuls = 1; |
if (!skip_srandom_call) { |
718 |
emuls[0] = emul_new(NULL); |
struct timeval tv; |
719 |
if (emuls[0] == NULL) { |
gettimeofday(&tv, NULL); |
720 |
fprintf(stderr, "out of memory\n"); |
srandom(tv.tv_sec ^ getpid() ^ tv.tv_usec); |
|
exit(1); |
|
|
} |
|
|
|
|
|
get_cmd_args(argc, argv, emuls[0], &diskimages, &n_diskimages); |
|
|
|
|
|
if (!fully_deterministic) { |
|
|
/* TODO: More than just time(). Use gettimeofday(). */ |
|
|
srandom(time(NULL) ^ (getpid() << 12)); |
|
|
} else { |
|
|
/* Fully deterministic. -I must have been supplied. */ |
|
|
if (emuls[0]->machines[0]->automatic_clock_adjustment) { |
|
|
fatal("Cannot have -D without -I.\n"); |
|
|
exit(1); |
|
|
} |
|
721 |
} |
} |
722 |
|
|
723 |
/* Print startup message: */ |
/* Print startup message: */ |
724 |
debug("GXemul"); |
debug("GXemul "VERSION" Copyright (C) 2003-2007 Anders Gavare\n" |
725 |
#ifdef VERSION |
"Read the source code and/or documentation for other Copyright " |
726 |
debug("-" VERSION); |
"messages.\n\n"); |
|
#endif |
|
|
debug(" Copyright (C) 2003-2005 Anders Gavare\n"); |
|
|
debug("Read the source code and/or documentation for " |
|
|
"other Copyright messages.\n\n"); |
|
|
|
|
|
if (emuls[0]->machines[0]->machine_type == MACHINE_NONE) |
|
|
n_emuls --; |
|
|
else { |
|
|
for (i=0; i<n_diskimages; i++) |
|
|
diskimage_add(emuls[0]->machines[0], diskimages[i]); |
|
|
} |
|
727 |
|
|
728 |
/* Simple initialization, from command line arguments: */ |
/* Simple initialization, from command line arguments: */ |
729 |
if (n_emuls > 0) { |
if (emul->machines[0]->machine_type != MACHINE_NONE) { |
730 |
|
for (i=0; i<n_diskimages; i++) |
731 |
|
diskimage_add(emul->machines[0], diskimages[i]); |
732 |
|
|
733 |
/* Make sure that there are no configuration files as well: */ |
/* Make sure that there are no configuration files as well: */ |
734 |
for (i=1; i<argc; i++) |
for (i=1; i<argc; i++) |
735 |
if (argv[i][0] == '@') { |
if (argv[i][0] == '@') { |
742 |
} |
} |
743 |
|
|
744 |
/* Initialize one emul: */ |
/* Initialize one emul: */ |
745 |
emul_simple_init(emuls[0]); |
emul_simple_init(emul); |
746 |
} |
} |
747 |
|
|
748 |
/* Initialize emulations from config files: */ |
/* Initialize an emulation from a config file: */ |
749 |
for (i=1; i<argc; i++) { |
for (i=1; i<argc; i++) { |
750 |
if (argv[i][0] == '@') { |
if (argv[i][0] == '@') { |
751 |
char *s = argv[i] + 1; |
char *s = argv[i] + 1; |
752 |
if (strlen(s) == 0 && i+1 < argc && |
|
753 |
argv[i+1][0] != '@') { |
if (config_file) { |
754 |
i++; |
fprintf(stderr, "More than one configuration " |
755 |
s = argv[i]; |
"file cannot be used.\n"); |
|
} |
|
|
n_emuls ++; |
|
|
emuls = realloc(emuls, sizeof(struct emul *) * n_emuls); |
|
|
if (emuls == NULL) { |
|
|
fprintf(stderr, "out of memory\n"); |
|
756 |
exit(1); |
exit(1); |
757 |
} |
} |
|
emuls[n_emuls - 1] = |
|
|
emul_create_from_configfile(s); |
|
758 |
|
|
759 |
/* Always allow slave xterms when using multiple |
if (strlen(s) == 0 && i+1 < argc && *argv[i+1] != '@') |
760 |
emulations: */ |
s = argv[++i]; |
761 |
|
|
762 |
|
/* Always allow slave xterms: */ |
763 |
console_allow_slaves(1); |
console_allow_slaves(1); |
764 |
|
|
765 |
|
/* Destroy the temporary emul, since it will |
766 |
|
be overwritten: */ |
767 |
|
if (emul != NULL) { |
768 |
|
emul_destroy(emul); |
769 |
|
settings_remove(global_settings, "emul"); |
770 |
|
emul = NULL; |
771 |
|
} |
772 |
|
|
773 |
|
emul = emul_create_from_configfile(s); |
774 |
|
|
775 |
|
settings_add(global_settings, "emul", 1, |
776 |
|
SETTINGS_TYPE_SUBSETTINGS, 0, emul->settings); |
777 |
|
|
778 |
|
config_file = 1; |
779 |
} |
} |
780 |
} |
} |
781 |
|
|
782 |
if (n_emuls == 0) { |
if (emul->n_machines == 0) { |
783 |
fprintf(stderr, "No emulations defined. Maybe you forgot to " |
fprintf(stderr, "No emulations defined. Maybe you forgot to " |
784 |
"use -E xx and/or -e yy, to specify\nthe machine type." |
"use -E xx and/or -e yy, to specify\nthe machine type." |
785 |
" For example:\n\n %s -e 3max -d disk.img\n\n" |
" For example:\n\n %s -e 3max -d disk.img\n\n" |
789 |
} |
} |
790 |
|
|
791 |
device_set_exit_on_error(0); |
device_set_exit_on_error(0); |
792 |
|
console_warn_if_slaves_are_needed(1); |
793 |
|
|
794 |
|
|
795 |
|
/* Run the emulation: */ |
796 |
|
emul_run(emul); |
797 |
|
|
798 |
|
|
799 |
|
/* |
800 |
|
* Deinitialize everything: |
801 |
|
*/ |
802 |
|
|
803 |
|
console_deinit(); |
804 |
|
|
805 |
|
emul_destroy(emul); |
806 |
|
|
807 |
/* Run all emulations: */ |
settings_remove_all(global_settings); |
808 |
emul_run(emuls, n_emuls); |
settings_destroy(global_settings); |
809 |
|
|
810 |
return 0; |
return 0; |
811 |
} |
} |