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.236 2005/05/25 06:40:18 debug Exp $ |
* $Id: main.c,v 1.305 2007/06/15 17:02: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 |
|
int native_code_translation_enabled = 0; |
65 |
|
int skip_srandom_call = 0; |
66 |
|
|
67 |
|
|
68 |
/***************************************************************************** |
/***************************************************************************** |
199 |
{ |
{ |
200 |
printf("GXemul"); |
printf("GXemul"); |
201 |
#ifdef VERSION |
#ifdef VERSION |
202 |
printf("-" VERSION); |
printf(" " VERSION); |
203 |
#endif |
#endif |
204 |
printf(" Copyright (C) 2003-2005 Anders Gavare\n"); |
printf(" Copyright (C) 2003-2007 Anders Gavare\n"); |
205 |
printf("Read the source code and/or documentation for " |
printf("Read the source code and/or documentation for " |
206 |
"other Copyright messages.\n"); |
"other Copyright messages.\n"); |
207 |
|
|
208 |
printf("\nusage: %s [machine, other, and general options] [file " |
printf("\nusage: %s [machine, other, and general options] [file " |
209 |
"[...]]\n", progname); |
"[...]]\n", progname); |
210 |
printf(" or %s [general options] @configfile [...]\n", progname); |
printf(" or %s [general options] @configfile\n", progname); |
211 |
printf(" or %s [userland, other, and general options] file " |
printf(" or %s [userland, other, and general options] file " |
212 |
"[args ...]\n", progname); |
"[args ...]\n", progname); |
213 |
|
|
224 |
"with -E.)\n"); |
"with -E.)\n"); |
225 |
|
|
226 |
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 |
|
227 |
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 " |
228 |
"list of types.)\n"); |
"list of types.)\n"); |
229 |
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:\"" |
237 |
printf(" gH;S; set geometry to H heads and S" |
printf(" gH;S; set geometry to H heads and S" |
238 |
" sectors-per-track\n"); |
" sectors-per-track\n"); |
239 |
printf(" i IDE\n"); |
printf(" i IDE\n"); |
240 |
|
printf(" oOFS; set base offset to OFS (for ISO9660" |
241 |
|
" filesystems)\n"); |
242 |
printf(" r read-only (don't allow changes to the" |
printf(" r read-only (don't allow changes to the" |
243 |
" file)\n"); |
" file)\n"); |
244 |
printf(" s SCSI\n"); |
printf(" s SCSI\n"); |
245 |
printf(" t tape\n"); |
printf(" t tape\n"); |
246 |
|
printf(" V add an overlay\n"); |
247 |
printf(" 0-7 force a specific ID\n"); |
printf(" 0-7 force a specific ID\n"); |
248 |
printf(" -I x emulate clock interrupts at x Hz (affects" |
printf(" -I hz set the main cpu frequency to hz (not used by " |
249 |
" rtc devices only, not\n"); |
"all combinations\n of machines and guest OSes)\n"); |
|
printf(" actual runtime speed) (this disables automatic" |
|
|
" clock adjustments)\n"); |
|
250 |
printf(" -i display each instruction as it is executed\n"); |
printf(" -i display each instruction as it is executed\n"); |
251 |
printf(" -J disable some speed tricks\n"); |
printf(" -J disable dyntrans instruction combinations\n"); |
252 |
printf(" -j name set the name of the kernel, for example:\n"); |
printf(" -j name set the name of the kernel; for DECstation " |
253 |
printf(" -j netbsd for NetBSD/pmax\n"); |
"emulation, this passes\n the name to the bootloader," |
254 |
printf(" -j bsd for OpenBSD/pmax\n"); |
" for example:\n"); |
255 |
printf(" -j vmunix for Ultrix/RISC\n"); |
printf(" -j netbsd (NetBSD/pmax) " |
256 |
|
"-j bsd (OpenBSD/pmax)\n"); |
257 |
|
printf(" -j vmsprite (Sprite/pmax) " |
258 |
|
"-j vmunix (Ultrix/RISC)\n"); |
259 |
|
printf(" For other emulation modes, if the boot disk is an" |
260 |
|
" ISO9660\n filesystem, -j sets the name of the" |
261 |
|
" kernel to load.\n"); |
262 |
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"); |
|
263 |
printf(" -N display nr of instructions/second average, at" |
printf(" -N display nr of instructions/second average, at" |
264 |
" regular intervals\n"); |
" regular intervals\n"); |
265 |
printf(" -n nr set nr of CPUs (for SMP experiments)\n"); |
printf(" -n nr set nr of CPUs (for SMP experiments)\n"); |
266 |
printf(" -O force netboot (tftp instead of disk), even when" |
printf(" -O force netboot (tftp instead of disk), even when" |
267 |
" a disk image is\n" |
" a disk image is\n" |
268 |
" present (for DECstation, SGI, and ARC emulation)\n"); |
" present (for DECstation, SGI, and ARC emulation)\n"); |
269 |
printf(" -o arg set the boot argument (for DEC, ARC, or SGI" |
printf(" -o arg set the boot argument, for DEC, ARC, or SGI" |
270 |
" emulation).\n"); |
" emulation\n"); |
271 |
printf(" Default arg for DEC is '-a', for ARC '-aN'.\n"); |
printf(" (default arg for DEC is -a, for ARC/SGI -aN)\n"); |
272 |
printf(" -p pc add a breakpoint (remember to use the '0x' " |
printf(" -p pc add a breakpoint (remember to use the '0x' " |
273 |
"prefix for hex!)\n"); |
"prefix for hex!)\n"); |
274 |
printf(" -Q no built-in PROM emulation (use this for " |
printf(" -Q no built-in PROM emulation (use this for " |
277 |
printf(" -r register dumps before every instruction\n"); |
printf(" -r register dumps before every instruction\n"); |
278 |
printf(" -S initialize emulated RAM to random bytes, " |
printf(" -S initialize emulated RAM to random bytes, " |
279 |
"instead of zeroes\n"); |
"instead of zeroes\n"); |
280 |
printf(" -T enter the single-step debugger on " |
printf(" -s f:name write statistics to file 'name', " |
281 |
"unimplemented memory accesses\n"); |
"f is one or more of the following:\n"); |
282 |
|
printf(" v virtual program counter\n"); |
283 |
|
printf(" p physical equivalent of program counter\n"); |
284 |
|
printf(" i internal ic->f representation of " |
285 |
|
"the program counter\n"); |
286 |
|
printf(" and optionally:\n"); |
287 |
|
printf(" d disable statistics gathering at " |
288 |
|
"startup\n"); |
289 |
|
printf(" o overwrite instead of append\n"); |
290 |
|
printf(" -T halt on non-existant memory accesses\n"); |
291 |
printf(" -t show function trace tree\n"); |
printf(" -t show function trace tree\n"); |
292 |
printf(" -U enable slow_serial_interrupts_hack_for_linux\n"); |
printf(" -U enable slow_serial_interrupts_hack_for_linux\n"); |
293 |
#ifdef WITH_X11 |
#ifdef WITH_X11 |
294 |
printf(" -X use X11\n"); |
printf(" -X use X11\n"); |
|
#endif /* WITH_X11 */ |
|
295 |
printf(" -x open up new xterms for emulated serial ports " |
printf(" -x open up new xterms for emulated serial ports " |
296 |
"(default is on when\n using configuration files, off" |
"(default is on when\n using configuration files or" |
297 |
" otherwise)\n"); |
" when X11 is used, off otherwise)\n"); |
|
#ifdef WITH_X11 |
|
298 |
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"); |
299 |
#endif /* WITH_X11 */ |
#endif /* WITH_X11 */ |
|
printf(" -y x set max_random_cycles_per_chunk to x" |
|
|
" (experimental)\n"); |
|
300 |
printf(" -Z n set nr of graphics cards, for emulating a " |
printf(" -Z n set nr of graphics cards, for emulating a " |
301 |
"dual-head or tripple-head\n" |
"dual-head or tripple-head\n" |
302 |
" environment (only for DECstation emulation)\n"); |
" environment (only for DECstation emulation)\n"); |
308 |
" get a list of\n available emulation modes)\n"); |
" get a list of\n available emulation modes)\n"); |
309 |
|
|
310 |
printf("\nGeneral options:\n"); |
printf("\nGeneral options:\n"); |
311 |
printf(" -D guarantee fully deterministic behaviour\n"); |
printf(" -b enable native code generation, if available\n"); |
312 |
|
printf(" -B disable native code generation (this is " |
313 |
|
"the default)\n"); |
314 |
|
printf(" -c cmd add cmd as a command to run before starting " |
315 |
|
"the simulation\n"); |
316 |
|
printf(" -D skip the srandom call at startup\n"); |
317 |
printf(" -H display a list of possible CPU and " |
printf(" -H display a list of possible CPU and " |
318 |
"machine types\n"); |
"machine types\n"); |
319 |
printf(" -h display this help message\n"); |
printf(" -h display this help message\n"); |
320 |
|
printf(" -k n set dyntrans translation caches to n MB (default" |
321 |
|
" size is %i MB)\n", DEFAULT_DYNTRANS_CACHE_SIZE / 1048576); |
322 |
printf(" -K force the debugger to be entered at the end " |
printf(" -K force the debugger to be entered at the end " |
323 |
"of a simulation\n"); |
"of a simulation\n"); |
324 |
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"); |
|
325 |
printf(" -V start up in the single-step debugger, paused\n"); |
printf(" -V start up in the single-step debugger, paused\n"); |
326 |
printf(" -v verbose debug messages\n"); |
printf(" -v verbose debug messages\n"); |
327 |
printf("\n"); |
printf("\n"); |
334 |
"To load a raw binary into memory, add \"address:\" in front " |
"To load a raw binary into memory, add \"address:\" in front " |
335 |
"of the filename,\n" |
"of the filename,\n" |
336 |
"or \"address:skiplen:\" or \"address:skiplen:initialpc:\".\n" |
"or \"address:skiplen:\" or \"address:skiplen:initialpc:\".\n" |
337 |
"Examples:\n" |
"\nExamples:\n" |
338 |
" 0xbfc00000:rom.bin for a raw ROM image\n" |
" 0xbfc00000:rom.bin for a raw ROM image\n" |
339 |
" 0xbfc00000:0x100:rom.bin for an image with " |
" 0xbfc00000:0x100:rom.bin for an image with " |
340 |
"0x100 bytes header\n" |
"0x100 bytes header\n" |
341 |
" 0xbfc00000:0x100:0xbfc00884:rom.bin " |
" 0xbfc00000:0x100:0xbfc00884:rom.bin " |
342 |
"start with pc=0xbfc00884\n"); |
"start with pc=0xbfc00884\n\n"); |
343 |
} |
} |
344 |
|
|
345 |
|
|
352 |
char ***diskimagesp, int *n_diskimagesp) |
char ***diskimagesp, int *n_diskimagesp) |
353 |
{ |
{ |
354 |
int ch, res, using_switch_d = 0, using_switch_Z = 0; |
int ch, res, using_switch_d = 0, using_switch_Z = 0; |
355 |
|
int using_switch_e = 0, using_switch_E = 0; |
356 |
char *type = NULL, *subtype = NULL; |
char *type = NULL, *subtype = NULL; |
357 |
int n_cpus_set = 0; |
int n_cpus_set = 0; |
358 |
int msopts = 0; /* Machine-specific options used */ |
int msopts = 0; /* Machine-specific options used */ |
359 |
struct machine *m = emul_add_machine(emul, "default"); |
struct machine *m = emul_add_machine(emul, "default"); |
360 |
|
|
361 |
while ((ch = getopt(argc, argv, "BbC:Dd:E:e:HhI:iJj:KM:m:" |
char *opts = |
362 |
"Nn:Oo:p:QqRrSsTtUu:VvW:XxY:y:Z:z:")) != -1) { |
"bBC:c:Dd:E:e:HhI:iJj:k:KM:Nn:Oo:p:QqRrSs:TtUu:VvW:" |
363 |
|
#ifdef WITH_X11 |
364 |
|
"XxY:" |
365 |
|
#endif |
366 |
|
"Z:z:"; |
367 |
|
|
368 |
|
while ((ch = getopt(argc, argv, opts)) != -1) { |
369 |
switch (ch) { |
switch (ch) { |
|
case 'B': |
|
|
m->bintrans_enable = 0; |
|
|
msopts = 1; |
|
|
break; |
|
370 |
case 'b': |
case 'b': |
371 |
m->old_bintrans_enable = 1; |
native_code_translation_enabled = 1; |
372 |
msopts = 1; |
break; |
373 |
|
case 'B': |
374 |
|
native_code_translation_enabled = 0; |
375 |
break; |
break; |
376 |
case 'C': |
case 'C': |
377 |
m->cpu_name = strdup(optarg); |
CHECK_ALLOCATION(m->cpu_name = strdup(optarg)); |
378 |
msopts = 1; |
msopts = 1; |
379 |
break; |
break; |
380 |
|
case 'c': |
381 |
|
emul->n_debugger_cmds ++; |
382 |
|
CHECK_ALLOCATION(emul->debugger_cmds = |
383 |
|
realloc(emul->debugger_cmds, |
384 |
|
emul->n_debugger_cmds * sizeof(char *))); |
385 |
|
CHECK_ALLOCATION(emul->debugger_cmds[emul-> |
386 |
|
n_debugger_cmds-1] = strdup(optarg)); |
387 |
|
break; |
388 |
case 'D': |
case 'D': |
389 |
fully_deterministic = 1; |
skip_srandom_call = 1; |
390 |
break; |
break; |
391 |
case 'd': |
case 'd': |
392 |
/* diskimage_add() is called further down */ |
/* diskimage_add() is called further down */ |
393 |
(*n_diskimagesp) ++; |
(*n_diskimagesp) ++; |
394 |
(*diskimagesp) = realloc(*diskimagesp, |
CHECK_ALLOCATION( (*diskimagesp) = |
395 |
sizeof(char *) * (*n_diskimagesp)); |
realloc(*diskimagesp, |
396 |
if (*diskimagesp == NULL) { |
sizeof(char *) * (*n_diskimagesp)) ); |
397 |
fprintf(stderr, "out of memory\n"); |
CHECK_ALLOCATION( (*diskimagesp)[(*n_diskimagesp) - 1] = |
398 |
exit(1); |
strdup(optarg) ); |
|
} |
|
|
(*diskimagesp)[(*n_diskimagesp) - 1] = strdup(optarg); |
|
399 |
using_switch_d = 1; |
using_switch_d = 1; |
400 |
msopts = 1; |
msopts = 1; |
401 |
break; |
break; |
402 |
case 'E': |
case 'E': |
403 |
|
if (using_switch_E ++ > 0) { |
404 |
|
fprintf(stderr, "-E already used.\n"); |
405 |
|
exit(1); |
406 |
|
} |
407 |
type = optarg; |
type = optarg; |
408 |
msopts = 1; |
msopts = 1; |
409 |
break; |
break; |
410 |
case 'e': |
case 'e': |
411 |
|
if (using_switch_e ++ > 0) { |
412 |
|
fprintf(stderr, "-e already used.\n"); |
413 |
|
exit(1); |
414 |
|
} |
415 |
subtype = optarg; |
subtype = optarg; |
416 |
msopts = 1; |
msopts = 1; |
417 |
break; |
break; |
423 |
exit(1); |
exit(1); |
424 |
case 'I': |
case 'I': |
425 |
m->emulated_hz = atoi(optarg); |
m->emulated_hz = atoi(optarg); |
|
m->automatic_clock_adjustment = 0; |
|
426 |
msopts = 1; |
msopts = 1; |
427 |
break; |
break; |
428 |
case 'i': |
case 'i': |
430 |
msopts = 1; |
msopts = 1; |
431 |
break; |
break; |
432 |
case 'J': |
case 'J': |
433 |
m->speed_tricks = 0; |
m->allow_instruction_combinations = 0; |
434 |
msopts = 1; |
msopts = 1; |
435 |
break; |
break; |
436 |
case 'j': |
case 'j': |
437 |
m->boot_kernel_filename = strdup(optarg); |
CHECK_ALLOCATION(m->boot_kernel_filename = |
438 |
if (m->boot_kernel_filename == NULL) { |
strdup(optarg)); |
439 |
fprintf(stderr, "out of memory\n"); |
msopts = 1; |
440 |
|
break; |
441 |
|
case 'k': |
442 |
|
dyntrans_cache_size = atoi(optarg) * 1048576; |
443 |
|
if (dyntrans_cache_size < 1) { |
444 |
|
fprintf(stderr, "The dyntrans cache size must" |
445 |
|
" be at least 1 MB.\n"); |
446 |
exit(1); |
exit(1); |
447 |
} |
} |
|
msopts = 1; |
|
448 |
break; |
break; |
449 |
case 'K': |
case 'K': |
450 |
force_debugger_at_exit = 1; |
force_debugger_at_exit = 1; |
453 |
m->physical_ram_in_mb = atoi(optarg); |
m->physical_ram_in_mb = atoi(optarg); |
454 |
msopts = 1; |
msopts = 1; |
455 |
break; |
break; |
|
case 'm': |
|
|
m->max_instructions = atoi(optarg); |
|
|
msopts = 1; |
|
|
break; |
|
456 |
case 'N': |
case 'N': |
457 |
m->show_nr_of_instructions = 1; |
m->show_nr_of_instructions = 1; |
458 |
msopts = 1; |
msopts = 1; |
467 |
msopts = 1; |
msopts = 1; |
468 |
break; |
break; |
469 |
case 'o': |
case 'o': |
470 |
m->boot_string_argument = strdup(optarg); |
CHECK_ALLOCATION(m->boot_string_argument = |
471 |
if (m->boot_string_argument == NULL) { |
strdup(optarg)); |
|
fprintf(stderr, "out of memory\n"); |
|
|
exit(1); |
|
|
} |
|
472 |
msopts = 1; |
msopts = 1; |
473 |
break; |
break; |
474 |
case 'p': |
case 'p': |
475 |
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 ++; |
|
476 |
msopts = 1; |
msopts = 1; |
477 |
break; |
break; |
478 |
case 'Q': |
case 'Q': |
495 |
msopts = 1; |
msopts = 1; |
496 |
break; |
break; |
497 |
case 's': |
case 's': |
498 |
show_opcode_statistics = 1; |
machine_statistics_init(m, optarg); |
499 |
|
native_code_translation_enabled = 0; |
500 |
|
msopts = 1; |
501 |
break; |
break; |
502 |
case 'T': |
case 'T': |
503 |
m->single_step_on_bad_addr = 1; |
m->halt_on_nonexistant_memaccess = 1; |
504 |
msopts = 1; |
msopts = 1; |
505 |
break; |
break; |
506 |
case 't': |
case 't': |
512 |
msopts = 1; |
msopts = 1; |
513 |
break; |
break; |
514 |
case 'u': |
case 'u': |
515 |
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); |
|
|
} |
|
516 |
m->machine_type = MACHINE_USERLAND; |
m->machine_type = MACHINE_USERLAND; |
517 |
msopts = 1; |
msopts = 1; |
518 |
break; |
break; |
519 |
case 'V': |
case 'V': |
520 |
single_step = 1; |
single_step = ENTER_SINGLE_STEPPING; |
521 |
break; |
break; |
522 |
case 'v': |
case 'v': |
523 |
verbose ++; |
verbose ++; |
526 |
internal_w(optarg); |
internal_w(optarg); |
527 |
exit(0); |
exit(0); |
528 |
case 'X': |
case 'X': |
529 |
m->use_x11 = 1; |
m->x11_md.in_use = 1; |
530 |
msopts = 1; |
msopts = 1; |
531 |
break; |
/* FALL-THROUGH */ |
532 |
case 'x': |
case 'x': |
533 |
console_allow_slaves(1); |
console_allow_slaves(1); |
534 |
break; |
break; |
535 |
case 'Y': |
case 'Y': |
536 |
m->x11_scaledown = atoi(optarg); |
m->x11_md.scaledown = atoi(optarg); |
537 |
if (m->x11_scaledown < 1) { |
if (m->x11_md.scaledown < -1) { |
538 |
|
m->x11_md.scaleup = - m->x11_md.scaledown; |
539 |
|
m->x11_md.scaledown = 1; |
540 |
|
} |
541 |
|
if (m->x11_md.scaledown < 1) { |
542 |
fprintf(stderr, "Invalid scaledown value.\n"); |
fprintf(stderr, "Invalid scaledown value.\n"); |
543 |
exit(1); |
exit(1); |
544 |
} |
} |
545 |
msopts = 1; |
msopts = 1; |
546 |
break; |
break; |
|
case 'y': |
|
|
m->max_random_cycles_per_chunk = atoi(optarg); |
|
|
msopts = 1; |
|
|
break; |
|
547 |
case 'Z': |
case 'Z': |
548 |
m->n_gfx_cards = atoi(optarg); |
m->n_gfx_cards = atoi(optarg); |
549 |
using_switch_Z = 1; |
using_switch_Z = 1; |
550 |
msopts = 1; |
msopts = 1; |
551 |
break; |
break; |
552 |
case 'z': |
case 'z': |
553 |
m->x11_n_display_names ++; |
m->x11_md.n_display_names ++; |
554 |
m->x11_display_names = realloc( |
CHECK_ALLOCATION(m->x11_md.display_names = realloc( |
555 |
m->x11_display_names, |
m->x11_md.display_names, |
556 |
m->x11_n_display_names * sizeof(char *)); |
m->x11_md.n_display_names * sizeof(char *))); |
557 |
if (m->x11_display_names == NULL) { |
CHECK_ALLOCATION(m->x11_md.display_names[ |
558 |
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); |
|
|
} |
|
559 |
msopts = 1; |
msopts = 1; |
560 |
break; |
break; |
561 |
default: |
default: |
562 |
fprintf(stderr, "Invalid option.\n"); |
fprintf(stderr, "Run %s -h for help on command " |
563 |
usage(0); |
"line options.\n", progname); |
564 |
exit(1); |
exit(1); |
565 |
} |
} |
566 |
} |
} |
567 |
|
|
568 |
if (type != NULL) { |
if (type != NULL || subtype != NULL) { |
569 |
|
if (type == NULL) |
570 |
|
type = ""; |
571 |
if (subtype == NULL) |
if (subtype == NULL) |
572 |
subtype = ""; |
subtype = ""; |
573 |
res = machine_name_to_type(type, subtype, |
res = machine_name_to_type(type, subtype, |
583 |
extra_argv = argv; |
extra_argv = argv; |
584 |
|
|
585 |
|
|
|
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; |
|
|
} |
|
|
|
|
586 |
if (m->machine_type == MACHINE_NONE && msopts) { |
if (m->machine_type == MACHINE_NONE && msopts) { |
587 |
fprintf(stderr, "Machine specific options used directly on " |
fprintf(stderr, "Machine specific options used directly on " |
588 |
"the command line, but no machine\nemulation specified?\n"); |
"the command line, but no machine\nemulation specified?\n"); |
590 |
} |
} |
591 |
|
|
592 |
|
|
593 |
/* -i, -r, -t are pretty verbose: */ |
/* -i and -r are pretty verbose: */ |
594 |
|
|
595 |
if (m->instruction_trace && !verbose) { |
if (m->instruction_trace && !verbose) { |
596 |
fprintf(stderr, "Implicitly %sturning on -v, because" |
fprintf(stderr, "Implicitly %sturning on -v, because" |
606 |
quiet_mode = 0; |
quiet_mode = 0; |
607 |
} |
} |
608 |
|
|
|
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; |
|
|
} |
|
|
|
|
609 |
|
|
610 |
/* |
/* |
611 |
* Usually, an executable filename must be supplied. |
* Usually, an executable filename must be supplied. |
640 |
else |
else |
641 |
s2 ++; |
s2 ++; |
642 |
|
|
643 |
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); |
|
|
} |
|
644 |
} |
} |
645 |
|
|
646 |
if (m->n_gfx_cards < 0 || m->n_gfx_cards > 3) { |
if (m->n_gfx_cards < 0 || m->n_gfx_cards > 3) { |
648 |
exit(1); |
exit(1); |
649 |
} |
} |
650 |
|
|
651 |
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) { |
|
|
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 |
|
|
|
|
|
if (!using_switch_Z && !m->use_x11) |
|
652 |
m->n_gfx_cards = 0; |
m->n_gfx_cards = 0; |
653 |
|
|
|
m->bintrans_enabled_from_start = m->bintrans_enable; |
|
|
|
|
654 |
return 0; |
return 0; |
655 |
} |
} |
656 |
|
|
667 |
*/ |
*/ |
668 |
int main(int argc, char *argv[]) |
int main(int argc, char *argv[]) |
669 |
{ |
{ |
670 |
|
/* Setting constants: */ |
671 |
|
const int constant_yes = 1; |
672 |
|
const int constant_true = 1; |
673 |
|
const int constant_no = 0; |
674 |
|
const int constant_false = 0; |
675 |
|
|
676 |
struct emul **emuls; |
struct emul **emuls; |
677 |
char **diskimages = NULL; |
char **diskimages = NULL; |
678 |
int n_diskimages = 0; |
int n_diskimages = 0; |
681 |
|
|
682 |
progname = argv[0]; |
progname = argv[0]; |
683 |
|
|
684 |
|
|
685 |
|
/* |
686 |
|
* Create the settings object, and add global settings to it: |
687 |
|
* |
688 |
|
* Read-only "constants": yes, no, true, false. |
689 |
|
* Global emulator settings: verbose, single_step, ... |
690 |
|
*/ |
691 |
|
global_settings = settings_new(); |
692 |
|
|
693 |
|
settings_add(global_settings, "yes", 0, SETTINGS_TYPE_INT, |
694 |
|
SETTINGS_FORMAT_YESNO, (void *)&constant_yes); |
695 |
|
settings_add(global_settings, "no", 0, SETTINGS_TYPE_INT, |
696 |
|
SETTINGS_FORMAT_YESNO, (void *)&constant_no); |
697 |
|
settings_add(global_settings, "true", 0, SETTINGS_TYPE_INT, |
698 |
|
SETTINGS_FORMAT_BOOL, (void *)&constant_true); |
699 |
|
settings_add(global_settings, "false", 0, SETTINGS_TYPE_INT, |
700 |
|
SETTINGS_FORMAT_BOOL, (void *)&constant_false); |
701 |
|
|
702 |
|
/* Read-only settings: */ |
703 |
|
settings_add(global_settings, "native_code_translation_enabled", 0, |
704 |
|
SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, |
705 |
|
(void *)&native_code_translation_enabled); |
706 |
|
settings_add(global_settings, "single_step", 0, |
707 |
|
SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, (void *)&single_step); |
708 |
|
|
709 |
|
/* Read/write settings: */ |
710 |
|
settings_add(global_settings, "force_debugger_at_exit", 1, |
711 |
|
SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, |
712 |
|
(void *)&force_debugger_at_exit); |
713 |
|
settings_add(global_settings, "verbose", 1, |
714 |
|
SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, (void *)&verbose); |
715 |
|
settings_add(global_settings, "quiet_mode", 1, |
716 |
|
SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, (void *)&quiet_mode); |
717 |
|
|
718 |
|
/* Initialize all emulator subsystems: */ |
719 |
console_init(); |
console_init(); |
720 |
cpu_init(); |
cpu_init(); |
721 |
device_init(); |
device_init(); |
722 |
machine_init(); |
machine_init(); |
723 |
|
timer_init(); |
724 |
useremul_init(); |
useremul_init(); |
725 |
|
|
726 |
emuls = malloc(sizeof(struct emul *)); |
emuls = malloc(sizeof(struct emul *)); |
727 |
if (emuls == NULL) { |
CHECK_ALLOCATION(emuls); |
|
fprintf(stderr, "out of memory\n"); |
|
|
exit(1); |
|
|
} |
|
728 |
|
|
729 |
/* Allocate space for a simple emul setup: */ |
/* Allocate space for a simple emul setup: */ |
730 |
n_emuls = 1; |
n_emuls = 1; |
731 |
emuls[0] = emul_new(NULL); |
emuls[0] = emul_new(NULL, 0); |
732 |
if (emuls[0] == NULL) { |
settings_add(global_settings, "emul[0]", 1, |
733 |
fprintf(stderr, "out of memory\n"); |
SETTINGS_TYPE_SUBSETTINGS, 0, emuls[0]->settings); |
|
exit(1); |
|
|
} |
|
734 |
|
|
735 |
get_cmd_args(argc, argv, emuls[0], &diskimages, &n_diskimages); |
get_cmd_args(argc, argv, emuls[0], &diskimages, &n_diskimages); |
736 |
|
|
737 |
if (!fully_deterministic) { |
if (!skip_srandom_call) { |
738 |
/* TODO: More than just time(). Use gettimeofday(). */ |
struct timeval tv; |
739 |
srandom(time(NULL) ^ (getpid() << 12)); |
gettimeofday(&tv, NULL); |
740 |
} 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); |
|
|
} |
|
741 |
} |
} |
742 |
|
|
743 |
/* Print startup message: */ |
/* Print startup message: */ |
744 |
debug("GXemul"); |
debug("GXemul"); |
745 |
#ifdef VERSION |
#ifdef VERSION |
746 |
debug("-" VERSION); |
debug(" " VERSION); |
747 |
#endif |
#endif |
748 |
debug(" Copyright (C) 2003-2005 Anders Gavare\n"); |
debug(" Copyright (C) 2003-2007 Anders Gavare\n"); |
749 |
debug("Read the source code and/or documentation for " |
debug("Read the source code and/or documentation for " |
750 |
"other Copyright messages.\n\n"); |
"other Copyright messages.\n\n"); |
751 |
|
|
752 |
if (emuls[0]->machines[0]->machine_type == MACHINE_NONE) |
if (emuls[0]->machines[0]->machine_type == MACHINE_NONE) { |
753 |
n_emuls --; |
n_emuls --; |
754 |
else { |
} else { |
755 |
for (i=0; i<n_diskimages; i++) |
for (i=0; i<n_diskimages; i++) |
756 |
diskimage_add(emuls[0]->machines[0], diskimages[i]); |
diskimage_add(emuls[0]->machines[0], diskimages[i]); |
757 |
} |
} |
776 |
/* Initialize emulations from config files: */ |
/* Initialize emulations from config files: */ |
777 |
for (i=1; i<argc; i++) { |
for (i=1; i<argc; i++) { |
778 |
if (argv[i][0] == '@') { |
if (argv[i][0] == '@') { |
779 |
|
char tmpstr[50]; |
780 |
char *s = argv[i] + 1; |
char *s = argv[i] + 1; |
781 |
if (strlen(s) == 0 && i+1 < argc && |
if (strlen(s) == 0 && i+1 < argc && |
782 |
argv[i+1][0] != '@') { |
argv[i+1][0] != '@') { |
784 |
s = argv[i]; |
s = argv[i]; |
785 |
} |
} |
786 |
n_emuls ++; |
n_emuls ++; |
787 |
emuls = realloc(emuls, sizeof(struct emul *) * n_emuls); |
CHECK_ALLOCATION(emuls = realloc(emuls, |
788 |
if (emuls == NULL) { |
sizeof(struct emul *) * n_emuls)); |
|
fprintf(stderr, "out of memory\n"); |
|
|
exit(1); |
|
|
} |
|
|
emuls[n_emuls - 1] = |
|
|
emul_create_from_configfile(s); |
|
789 |
|
|
790 |
/* Always allow slave xterms when using multiple |
/* Always allow slave xterms when using multiple |
791 |
emulations: */ |
emulations: */ |
792 |
console_allow_slaves(1); |
console_allow_slaves(1); |
793 |
|
|
794 |
|
/* Destroy the temporary emuls[0], since it will |
795 |
|
be overwritten: */ |
796 |
|
if (n_emuls == 1) { |
797 |
|
emul_destroy(emuls[0]); |
798 |
|
settings_remove(global_settings, "emul[0]"); |
799 |
|
} |
800 |
|
|
801 |
|
emuls[n_emuls - 1] = |
802 |
|
emul_create_from_configfile(s, n_emuls - 1); |
803 |
|
|
804 |
|
snprintf(tmpstr, sizeof(tmpstr), "emul[%i]", n_emuls-1); |
805 |
|
settings_add(global_settings, tmpstr, 1, |
806 |
|
SETTINGS_TYPE_SUBSETTINGS, 0, |
807 |
|
emuls[n_emuls-1]->settings); |
808 |
} |
} |
809 |
} |
} |
810 |
|
|
811 |
if (n_emuls == 0) { |
if (n_emuls == 0) { |
812 |
fprintf(stderr, "No emulations defined. Maybe you forgot to " |
fprintf(stderr, "No emulations defined. Maybe you forgot to " |
813 |
"use -E xx (and -e yy), to specify\nthe machine type)." |
"use -E xx and/or -e yy, to specify\nthe machine type." |
814 |
" For example:\n\n %s -E dec -e 3max -d disk.img\n\n" |
" For example:\n\n %s -e 3max -d disk.img\n\n" |
815 |
"to boot an emulated DECstation 5000/200 with a disk " |
"to boot an emulated DECstation 5000/200 with a disk " |
816 |
"image.\n", progname); |
"image.\n", progname); |
817 |
exit(1); |
exit(1); |
818 |
} |
} |
819 |
|
|
820 |
device_set_exit_on_error(0); |
device_set_exit_on_error(0); |
821 |
|
console_warn_if_slaves_are_needed(1); |
822 |
|
|
823 |
|
|
824 |
/* Run all emulations: */ |
/* Run all emulations: */ |
825 |
emul_run(emuls, n_emuls); |
emul_run(emuls, n_emuls); |
826 |
|
|
827 |
|
|
828 |
|
/* |
829 |
|
* Deinitialize everything: |
830 |
|
*/ |
831 |
|
|
832 |
|
console_deinit(); |
833 |
|
|
834 |
|
for (i=0; i<n_emuls; i++) |
835 |
|
emul_destroy(emuls[i]); |
836 |
|
|
837 |
|
settings_remove_all(global_settings); |
838 |
|
settings_destroy(global_settings); |
839 |
|
|
840 |
return 0; |
return 0; |
841 |
} |
} |
842 |
|
|