--- trunk/src/main.c 2007/10/08 16:21:17 34 +++ trunk/src/main.c 2007/10/08 16:22:32 42 @@ -25,7 +25,7 @@ * SUCH DAMAGE. * * - * $Id: main.c,v 1.293 2007/02/05 16:49:05 debug Exp $ + * $Id: main.c,v 1.305 2007/06/15 17:02:38 debug Exp $ */ #include @@ -45,9 +45,10 @@ #include "misc.h" #include "settings.h" #include "timer.h" +#include "useremul.h" -extern volatile int single_step; +extern int single_step; extern int force_debugger_at_exit; extern int optind; @@ -207,10 +208,8 @@ printf("\nusage: %s [machine, other, and general options] [file " "[...]]\n", progname); printf(" or %s [general options] @configfile\n", progname); -#ifdef UNSTABLE_DEVEL printf(" or %s [userland, other, and general options] file " "[args ...]\n", progname); -#endif if (!longusage) { printf("\nRun %s -h for help on command line options.\n", @@ -244,8 +243,8 @@ " file)\n"); printf(" s SCSI\n"); printf(" t tape\n"); + printf(" V add an overlay\n"); printf(" 0-7 force a specific ID\n"); - printf(" -G port listen to gdb remote connections on this port\n"); printf(" -I hz set the main cpu frequency to hz (not used by " "all combinations\n of machines and guest OSes)\n"); printf(" -i display each instruction as it is executed\n"); @@ -304,17 +303,14 @@ printf(" -z disp add disp as an X11 display to use for " "framebuffers\n"); -#ifdef UNSTABLE_DEVEL printf("\nUserland options:\n"); printf(" -u emul userland-only (syscall) emulation (use -H to" " get a list of\n available emulation modes)\n"); -#endif printf("\nGeneral options:\n"); -#ifdef UNSTABLE_DEVEL - printf(" -b enable native code generation\n"); - printf(" -B disable native code generation\n"); -#endif + printf(" -b enable native code generation, if available\n"); + printf(" -B disable native code generation (this is " + "the default)\n"); printf(" -c cmd add cmd as a command to run before starting " "the simulation\n"); printf(" -D skip the srandom call at startup\n"); @@ -338,12 +334,12 @@ "To load a raw binary into memory, add \"address:\" in front " "of the filename,\n" "or \"address:skiplen:\" or \"address:skiplen:initialpc:\".\n" - "Examples:\n" + "\nExamples:\n" " 0xbfc00000:rom.bin for a raw ROM image\n" " 0xbfc00000:0x100:rom.bin for an image with " "0x100 bytes header\n" " 0xbfc00000:0x100:0xbfc00884:rom.bin " - "start with pc=0xbfc00884\n"); + "start with pc=0xbfc00884\n\n"); } @@ -363,14 +359,7 @@ struct machine *m = emul_add_machine(emul, "default"); char *opts = -#ifdef UNSTABLE_DEVEL - "bB" -#endif - "C:c:Dd:E:e:G:HhI:iJj:k:KM:Nn:Oo:p:QqRrSs:TtU" -#ifdef UNSTABLE_DEVEL - "u:" -#endif - "VvW:" + "bBC:c:Dd:E:e:HhI:iJj:k:KM:Nn:Oo:p:QqRrSs:TtUu:VvW:" #ifdef WITH_X11 "XxY:" #endif @@ -378,33 +367,23 @@ while ((ch = getopt(argc, argv, opts)) != -1) { switch (ch) { -#ifdef UNSTABLE_DEVEL case 'b': -#ifndef NATIVE_CODE_GENERATION - printf("-b is not available on this host arch.\n"); - exit(1); -#else native_code_translation_enabled = 1; break; -#endif case 'B': native_code_translation_enabled = 0; break; -#endif /* UNSTABLE_DEVEL */ case 'C': - m->cpu_name = strdup(optarg); + CHECK_ALLOCATION(m->cpu_name = strdup(optarg)); msopts = 1; break; case 'c': emul->n_debugger_cmds ++; - emul->debugger_cmds = realloc(emul->debugger_cmds, - emul->n_debugger_cmds * sizeof(char *)); - if (emul->debugger_cmds == NULL) { - fatal("out of memory\n"); - exit(1); - } - emul->debugger_cmds[emul->n_debugger_cmds-1] = - strdup(optarg); + CHECK_ALLOCATION(emul->debugger_cmds = + realloc(emul->debugger_cmds, + emul->n_debugger_cmds * sizeof(char *))); + CHECK_ALLOCATION(emul->debugger_cmds[emul-> + n_debugger_cmds-1] = strdup(optarg)); break; case 'D': skip_srandom_call = 1; @@ -412,13 +391,11 @@ case 'd': /* diskimage_add() is called further down */ (*n_diskimagesp) ++; - (*diskimagesp) = realloc(*diskimagesp, - sizeof(char *) * (*n_diskimagesp)); - if (*diskimagesp == NULL) { - fprintf(stderr, "out of memory\n"); - exit(1); - } - (*diskimagesp)[(*n_diskimagesp) - 1] = strdup(optarg); + CHECK_ALLOCATION( (*diskimagesp) = + realloc(*diskimagesp, + sizeof(char *) * (*n_diskimagesp)) ); + CHECK_ALLOCATION( (*diskimagesp)[(*n_diskimagesp) - 1] = + strdup(optarg) ); using_switch_d = 1; msopts = 1; break; @@ -438,17 +415,6 @@ subtype = optarg; msopts = 1; break; - case 'G': - m->gdb.port = atoi(optarg); - if (m->gdb.port < 1 || m->gdb.port > 65535) { - fprintf(stderr, "Invalid debugger port %i.\n", - m->gdb.port); - exit(1); - } - /* Note: implicit -V */ - single_step = ENTER_SINGLE_STEPPING; - msopts = 1; - break; case 'H': machine_list_available_types_and_cpus(); exit(1); @@ -468,11 +434,8 @@ msopts = 1; break; case 'j': - m->boot_kernel_filename = strdup(optarg); - if (m->boot_kernel_filename == NULL) { - fprintf(stderr, "out of memory\n"); - exit(1); - } + CHECK_ALLOCATION(m->boot_kernel_filename = + strdup(optarg)); msopts = 1; break; case 'k': @@ -504,25 +467,12 @@ msopts = 1; break; case 'o': - m->boot_string_argument = strdup(optarg); - if (m->boot_string_argument == NULL) { - fprintf(stderr, "out of memory\n"); - exit(1); - } + CHECK_ALLOCATION(m->boot_string_argument = + strdup(optarg)); msopts = 1; break; case 'p': - if (m->n_breakpoints >= MAX_BREAKPOINTS) { - 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 ++; + machine_add_breakpoint_string(m, optarg); msopts = 1; break; case 'Q': @@ -562,11 +512,7 @@ msopts = 1; break; case 'u': - m->userland_emul = strdup(optarg); - if (m->userland_emul == NULL) { - fprintf(stderr, "out of memory\n"); - exit(1); - } + CHECK_ALLOCATION(m->userland_emul = strdup(optarg)); m->machine_type = MACHINE_USERLAND; msopts = 1; break; @@ -580,19 +526,19 @@ internal_w(optarg); exit(0); case 'X': - m->use_x11 = 1; + m->x11_md.in_use = 1; msopts = 1; /* FALL-THROUGH */ case 'x': console_allow_slaves(1); break; case 'Y': - m->x11_scaledown = atoi(optarg); - if (m->x11_scaledown < -1) { - m->x11_scaleup = - m->x11_scaledown; - m->x11_scaledown = 1; + m->x11_md.scaledown = atoi(optarg); + if (m->x11_md.scaledown < -1) { + m->x11_md.scaleup = - m->x11_md.scaledown; + m->x11_md.scaledown = 1; } - if (m->x11_scaledown < 1) { + if (m->x11_md.scaledown < 1) { fprintf(stderr, "Invalid scaledown value.\n"); exit(1); } @@ -604,21 +550,12 @@ msopts = 1; break; case 'z': - m->x11_n_display_names ++; - m->x11_display_names = realloc( - m->x11_display_names, - m->x11_n_display_names * sizeof(char *)); - if (m->x11_display_names == NULL) { - fprintf(stderr, "out of memory\n"); - 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); - } + m->x11_md.n_display_names ++; + CHECK_ALLOCATION(m->x11_md.display_names = realloc( + m->x11_md.display_names, + m->x11_md.n_display_names * sizeof(char *))); + CHECK_ALLOCATION(m->x11_md.display_names[ + m->x11_md.n_display_names-1] = strdup(optarg)); msopts = 1; break; default: @@ -703,11 +640,7 @@ else s2 ++; - m->boot_kernel_filename = strdup(s2); - if (m->boot_kernel_filename == NULL) { - fprintf(stderr, "out of memory\n"); - exit(1); - } + CHECK_ALLOCATION(m->boot_kernel_filename = strdup(s2)); } if (m->n_gfx_cards < 0 || m->n_gfx_cards > 3) { @@ -715,7 +648,7 @@ exit(1); } - if (!using_switch_Z && !m->use_x11) + if (!using_switch_Z && !m->x11_md.in_use) m->n_gfx_cards = 0; return 0; @@ -746,18 +679,6 @@ int n_emuls; int i; - -#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 - - progname = argv[0]; @@ -803,18 +724,11 @@ useremul_init(); emuls = malloc(sizeof(struct emul *)); - if (emuls == NULL) { - fprintf(stderr, "out of memory\n"); - exit(1); - } + CHECK_ALLOCATION(emuls); /* Allocate space for a simple emul setup: */ n_emuls = 1; emuls[0] = emul_new(NULL, 0); - if (emuls[0] == NULL) { - fprintf(stderr, "out of memory\n"); - exit(1); - } settings_add(global_settings, "emul[0]", 1, SETTINGS_TYPE_SUBSETTINGS, 0, emuls[0]->settings); @@ -870,11 +784,8 @@ s = argv[i]; } n_emuls ++; - emuls = realloc(emuls, sizeof(struct emul *) * n_emuls); - if (emuls == NULL) { - fprintf(stderr, "out of memory\n"); - exit(1); - } + CHECK_ALLOCATION(emuls = realloc(emuls, + sizeof(struct emul *) * n_emuls)); /* Always allow slave xterms when using multiple emulations: */ @@ -926,18 +837,6 @@ settings_remove_all(global_settings); settings_destroy(global_settings); -#ifdef USE_PROFIL -{ - int i; - FILE *f = fopen("output.txt", "w"); - for (i=0; i