25 |
* SUCH DAMAGE. |
* SUCH DAMAGE. |
26 |
* |
* |
27 |
* |
* |
28 |
* $Id: main.c,v 1.296 2007/03/31 15:11:26 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> |
45 |
#include "misc.h" |
#include "misc.h" |
46 |
#include "settings.h" |
#include "settings.h" |
47 |
#include "timer.h" |
#include "timer.h" |
48 |
|
#include "useremul.h" |
|
#ifdef TEST_NATIVE_X86 |
|
|
#include "native_x86.h" |
|
|
#endif |
|
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; |
53 |
|
|
54 |
extern int optind; |
extern int optind; |
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); |
|
#ifdef UNSTABLE_DEVEL |
|
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); |
|
#endif |
|
213 |
|
|
214 |
if (!longusage) { |
if (!longusage) { |
215 |
printf("\nRun %s -h for help on command line options.\n", |
printf("\nRun %s -h for help on command line options.\n", |
303 |
printf(" -z disp add disp as an X11 display to use for " |
printf(" -z disp add disp as an X11 display to use for " |
304 |
"framebuffers\n"); |
"framebuffers\n"); |
305 |
|
|
|
#ifdef UNSTABLE_DEVEL |
|
306 |
printf("\nUserland options:\n"); |
printf("\nUserland options:\n"); |
307 |
printf(" -u emul userland-only (syscall) emulation (use -H to" |
printf(" -u emul userland-only (syscall) emulation (use -H to" |
308 |
" get a list of\n available emulation modes)\n"); |
" get a list of\n available emulation modes)\n"); |
|
#endif |
|
309 |
|
|
310 |
printf("\nGeneral options:\n"); |
printf("\nGeneral options:\n"); |
311 |
#ifdef UNSTABLE_DEVEL |
printf(" -b enable native code generation, if available\n"); |
312 |
printf(" -b enable native code generation\n"); |
printf(" -B disable native code generation (this is " |
313 |
printf(" -B disable native code generation\n"); |
"the default)\n"); |
|
#endif |
|
314 |
printf(" -c cmd add cmd as a command to run before starting " |
printf(" -c cmd add cmd as a command to run before starting " |
315 |
"the simulation\n"); |
"the simulation\n"); |
316 |
printf(" -D skip the srandom call at startup\n"); |
printf(" -D skip the srandom call at startup\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 |
|
|
359 |
struct machine *m = emul_add_machine(emul, "default"); |
struct machine *m = emul_add_machine(emul, "default"); |
360 |
|
|
361 |
char *opts = |
char *opts = |
362 |
#ifdef UNSTABLE_DEVEL |
"bBC:c:Dd:E:e:HhI:iJj:k:KM:Nn:Oo:p:QqRrSs:TtUu:VvW:" |
|
"bB" |
|
|
#endif |
|
|
"C:c:Dd:E:e:HhI:iJj:k:KM:Nn:Oo:p:QqRrSs:TtU" |
|
|
#ifdef UNSTABLE_DEVEL |
|
|
"u:" |
|
|
#endif |
|
|
"VvW:" |
|
363 |
#ifdef WITH_X11 |
#ifdef WITH_X11 |
364 |
"XxY:" |
"XxY:" |
365 |
#endif |
#endif |
367 |
|
|
368 |
while ((ch = getopt(argc, argv, opts)) != -1) { |
while ((ch = getopt(argc, argv, opts)) != -1) { |
369 |
switch (ch) { |
switch (ch) { |
|
#ifdef UNSTABLE_DEVEL |
|
370 |
case 'b': |
case 'b': |
|
#ifndef NATIVE_CODE_GENERATION |
|
|
printf("-b is not available on this host arch.\n"); |
|
|
exit(1); |
|
|
#else |
|
371 |
native_code_translation_enabled = 1; |
native_code_translation_enabled = 1; |
372 |
break; |
break; |
|
#endif |
|
373 |
case 'B': |
case 'B': |
374 |
native_code_translation_enabled = 0; |
native_code_translation_enabled = 0; |
375 |
break; |
break; |
|
#endif /* UNSTABLE_DEVEL */ |
|
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': |
case 'c': |
381 |
emul->n_debugger_cmds ++; |
emul->n_debugger_cmds ++; |
382 |
emul->debugger_cmds = realloc(emul->debugger_cmds, |
CHECK_ALLOCATION(emul->debugger_cmds = |
383 |
emul->n_debugger_cmds * sizeof(char *)); |
realloc(emul->debugger_cmds, |
384 |
if (emul->debugger_cmds == NULL) { |
emul->n_debugger_cmds * sizeof(char *))); |
385 |
fatal("out of memory\n"); |
CHECK_ALLOCATION(emul->debugger_cmds[emul-> |
386 |
exit(1); |
n_debugger_cmds-1] = strdup(optarg)); |
|
} |
|
|
emul->debugger_cmds[emul->n_debugger_cmds-1] = |
|
|
strdup(optarg); |
|
387 |
break; |
break; |
388 |
case 'D': |
case 'D': |
389 |
skip_srandom_call = 1; |
skip_srandom_call = 1; |
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; |
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)); |
|
fprintf(stderr, "out of memory\n"); |
|
|
exit(1); |
|
|
} |
|
439 |
msopts = 1; |
msopts = 1; |
440 |
break; |
break; |
441 |
case 'k': |
case 'k': |
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': |
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; |
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 |
/* FALL-THROUGH */ |
/* 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_scaleup = - m->x11_scaledown; |
m->x11_md.scaleup = - m->x11_md.scaledown; |
539 |
m->x11_scaledown = 1; |
m->x11_md.scaledown = 1; |
540 |
} |
} |
541 |
if (m->x11_scaledown < 1) { |
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 |
} |
} |
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: |
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 (!using_switch_Z && !m->use_x11) |
if (!using_switch_Z && !m->x11_md.in_use) |
652 |
m->n_gfx_cards = 0; |
m->n_gfx_cards = 0; |
653 |
|
|
654 |
return 0; |
return 0; |
679 |
int n_emuls; |
int n_emuls; |
680 |
int i; |
int i; |
681 |
|
|
|
|
|
|
/* |
|
|
* Experimental profil() code, which works on my laptop. |
|
|
* Don't use it for anything else. |
|
|
*/ |
|
|
#ifdef USE_PROFIL |
|
|
uint16_t samples[0x100000]; |
|
|
memset(samples, 0, sizeof(samples)); |
|
|
profil((char *)samples, sizeof(samples), (vm_offset_t) 0x400000, 8192); |
|
|
#endif |
|
|
|
|
|
#ifndef NATIVE_CODE_GENERATION |
|
|
native_code_translation_enabled = 0; |
|
|
#endif |
|
|
|
|
|
|
|
|
/* Experimental test code: */ |
|
|
#ifdef TEST_NATIVE_X86 |
|
|
test_native_x86(); |
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
682 |
progname = argv[0]; |
progname = argv[0]; |
683 |
|
|
684 |
|
|
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, 0); |
emuls[0] = emul_new(NULL, 0); |
|
if (emuls[0] == NULL) { |
|
|
fprintf(stderr, "out of memory\n"); |
|
|
exit(1); |
|
|
} |
|
732 |
settings_add(global_settings, "emul[0]", 1, |
settings_add(global_settings, "emul[0]", 1, |
733 |
SETTINGS_TYPE_SUBSETTINGS, 0, emuls[0]->settings); |
SETTINGS_TYPE_SUBSETTINGS, 0, emuls[0]->settings); |
734 |
|
|
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); |
|
|
} |
|
789 |
|
|
790 |
/* Always allow slave xterms when using multiple |
/* Always allow slave xterms when using multiple |
791 |
emulations: */ |
emulations: */ |
837 |
settings_remove_all(global_settings); |
settings_remove_all(global_settings); |
838 |
settings_destroy(global_settings); |
settings_destroy(global_settings); |
839 |
|
|
|
#ifdef USE_PROFIL |
|
|
{ |
|
|
int i; |
|
|
FILE *f = fopen("output.txt", "w"); |
|
|
for (i=0; i<sizeof(samples) / sizeof(uint16_t); ++i) { |
|
|
if (samples[i] != 0) |
|
|
fprintf(f, "%i %p\n", samples[i], |
|
|
(void *) (size_t) (0x400000 + i * 16)); |
|
|
} |
|
|
} |
|
|
#endif |
|
|
|
|
840 |
return 0; |
return 0; |
841 |
} |
} |
842 |
|
|