25 |
* SUCH DAMAGE. |
* SUCH DAMAGE. |
26 |
* |
* |
27 |
* |
* |
28 |
* $Id: main.c,v 1.228 2005/04/07 15:43:17 debug Exp $ |
* $Id: main.c,v 1.244 2005/09/07 07:41:29 debug Exp $ |
29 |
*/ |
*/ |
30 |
|
|
31 |
#include <stdio.h> |
#include <stdio.h> |
155 |
|
|
156 |
|
|
157 |
/* |
/* |
|
* 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; |
|
|
} |
|
|
|
|
|
|
|
|
/*****************************************************************************/ |
|
|
|
|
|
|
|
|
/* |
|
158 |
* internal_w(): |
* internal_w(): |
159 |
* |
* |
160 |
* For internal use by gxemul itself. |
* For internal use by gxemul itself. |
200 |
|
|
201 |
printf("\nusage: %s [machine, other, and general options] [file " |
printf("\nusage: %s [machine, other, and general options] [file " |
202 |
"[...]]\n", progname); |
"[...]]\n", progname); |
203 |
printf(" or %s [general options] @configfile [...]\n", progname); |
printf(" or %s [general options] @configfile\n", progname); |
204 |
printf(" or %s [userland, other, and general options] file " |
printf(" or %s [userland, other, and general options] file " |
205 |
"[args ...]\n", progname); |
"[args ...]\n", progname); |
206 |
|
|
217 |
"with -E.)\n"); |
"with -E.)\n"); |
218 |
|
|
219 |
printf("\nOther options:\n"); |
printf("\nOther options:\n"); |
220 |
|
printf(" -A disable alignment checks in some cases (for higher" |
221 |
|
" speed)\n"); |
222 |
#ifdef BINTRANS |
#ifdef BINTRANS |
223 |
printf(" -B disable dynamic binary translation completely\n"); |
printf(" -B disable dynamic binary translation. (translation" |
224 |
printf(" -b use the OLD binary translation subsystem\n"); |
" is turned on\n by default, if the host " |
225 |
|
"supports it)\n"); |
226 |
#endif |
#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:\"" |
230 |
" as a prefix\n"); |
" as a prefix\n"); |
231 |
printf(" where xxx is one or more of the following:\n"); |
printf(" where xxx is one or more of the following:\n"); |
232 |
printf(" b specifies that this is the boot" |
printf(" b specifies that this is the boot" |
233 |
" device\n"); |
" device\n"); |
234 |
printf(" c CD-ROM (instead of normal SCSI DISK)\n"); |
printf(" c CD-ROM\n"); |
235 |
printf(" d SCSI DISK (this is the default)\n"); |
printf(" d DISK\n"); |
236 |
printf(" i IDE (instead of SCSI)\n"); |
printf(" f FLOPPY\n"); |
237 |
printf(" r read-only (don't allow changes to the" |
printf(" gH;S; set geometry to H heads and S" |
238 |
|
" sectors-per-track\n"); |
239 |
|
printf(" i IDE\n"); |
240 |
|
printf(" r read-only (don't allow changes to the" |
241 |
" file)\n"); |
" file)\n"); |
242 |
printf(" t SCSI tape\n"); |
printf(" s SCSI\n"); |
243 |
printf(" 0-7 force a specific SCSI ID number\n"); |
printf(" t tape\n"); |
244 |
|
printf(" 0-7 force a specific ID\n"); |
245 |
printf(" -I x emulate clock interrupts at x Hz (affects" |
printf(" -I x emulate clock interrupts at x Hz (affects" |
246 |
" rtc devices only, not\n"); |
" rtc devices only, not\n"); |
247 |
printf(" actual runtime speed) (this disables automatic" |
printf(" actual runtime speed) (this disables automatic" |
316 |
"on a binary.\n" |
"on a binary.\n" |
317 |
"To load a raw binary into memory, add \"address:\" in front " |
"To load a raw binary into memory, add \"address:\" in front " |
318 |
"of the filename,\n" |
"of the filename,\n" |
319 |
"or \"address:skiplen:\" or \"address:skiplen:initialpc\".\n" |
"or \"address:skiplen:\" or \"address:skiplen:initialpc:\".\n" |
320 |
"Examples:\n" |
"Examples:\n" |
321 |
" 0xbfc00000:rom.bin for a raw ROM image\n" |
" 0xbfc00000:rom.bin for a raw ROM image\n" |
322 |
" 0xbfc00000:0x100:rom.bin for an image with " |
" 0xbfc00000:0x100:rom.bin for an image with " |
323 |
"0x100 bytes header\n" |
"0x100 bytes header\n" |
324 |
" 0xbfc00000:0x100:0xbfc00884:rom.bin " |
" 0xbfc00000:0x100:0xbfc00884:rom.bin " |
325 |
"start with pc=0xbfc00884\n"); |
"start with pc=0xbfc00884\n"); |
326 |
} |
} |
327 |
|
|
331 |
* |
* |
332 |
* Reads command line arguments. |
* Reads command line arguments. |
333 |
*/ |
*/ |
334 |
int get_cmd_args(int argc, char *argv[], struct emul *emul) |
int get_cmd_args(int argc, char *argv[], struct emul *emul, |
335 |
|
char ***diskimagesp, int *n_diskimagesp) |
336 |
{ |
{ |
337 |
int ch, res, using_switch_d = 0, using_switch_Z = 0; |
int ch, res, using_switch_d = 0, using_switch_Z = 0; |
338 |
char *type = NULL, *subtype = NULL; |
char *type = NULL, *subtype = NULL; |
340 |
int msopts = 0; /* Machine-specific options used */ |
int msopts = 0; /* Machine-specific options used */ |
341 |
struct machine *m = emul_add_machine(emul, "default"); |
struct machine *m = emul_add_machine(emul, "default"); |
342 |
|
|
343 |
while ((ch = getopt(argc, argv, "BbC:Dd:E:e:HhI:iJj:KM:m:" |
while ((ch = getopt(argc, argv, "ABC:Dd:E:e:HhI:iJj:KM:m:" |
344 |
"Nn:Oo:p:QqRrSsTtUu:VvW:XxY:y:Z:z:")) != -1) { |
"Nn:Oo:p:QqRrSsTtUu:VvW:XxY:y:Z:z:")) != -1) { |
345 |
switch (ch) { |
switch (ch) { |
346 |
case 'B': |
case 'A': |
347 |
m->bintrans_enable = 0; |
m->dyntrans_alignment_check = 0; |
348 |
msopts = 1; |
msopts = 1; |
349 |
break; |
break; |
350 |
case 'b': |
case 'B': |
351 |
m->old_bintrans_enable = 1; |
m->bintrans_enable = 0; |
352 |
msopts = 1; |
msopts = 1; |
353 |
break; |
break; |
354 |
case 'C': |
case 'C': |
359 |
fully_deterministic = 1; |
fully_deterministic = 1; |
360 |
break; |
break; |
361 |
case 'd': |
case 'd': |
362 |
diskimage_add(m, optarg); |
/* diskimage_add() is called further down */ |
363 |
|
(*n_diskimagesp) ++; |
364 |
|
(*diskimagesp) = realloc(*diskimagesp, |
365 |
|
sizeof(char *) * (*n_diskimagesp)); |
366 |
|
if (*diskimagesp == NULL) { |
367 |
|
fprintf(stderr, "out of memory\n"); |
368 |
|
exit(1); |
369 |
|
} |
370 |
|
(*diskimagesp)[(*n_diskimagesp) - 1] = strdup(optarg); |
371 |
using_switch_d = 1; |
using_switch_d = 1; |
372 |
msopts = 1; |
msopts = 1; |
373 |
break; |
break; |
513 |
break; |
break; |
514 |
case 'Y': |
case 'Y': |
515 |
m->x11_scaledown = atoi(optarg); |
m->x11_scaledown = atoi(optarg); |
516 |
|
if (m->x11_scaledown < 1) { |
517 |
|
fprintf(stderr, "Invalid scaledown value.\n"); |
518 |
|
exit(1); |
519 |
|
} |
520 |
msopts = 1; |
msopts = 1; |
521 |
break; |
break; |
522 |
case 'y': |
case 'y': |
547 |
msopts = 1; |
msopts = 1; |
548 |
break; |
break; |
549 |
default: |
default: |
550 |
fprintf(stderr, "Invalid option.\n"); |
fprintf(stderr, "Run %s -h for help on command " |
551 |
usage(0); |
"line options.\n", progname); |
552 |
exit(1); |
exit(1); |
553 |
} |
} |
554 |
} |
} |
555 |
|
|
556 |
if (type != NULL) { |
if (type != NULL || subtype != NULL) { |
557 |
|
if (type == NULL) |
558 |
|
type = ""; |
559 |
if (subtype == NULL) |
if (subtype == NULL) |
560 |
subtype = ""; |
subtype = ""; |
561 |
res = machine_name_to_type(type, subtype, |
res = machine_name_to_type(type, subtype, |
571 |
extra_argv = argv; |
extra_argv = argv; |
572 |
|
|
573 |
|
|
|
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; |
|
|
} |
|
|
|
|
574 |
if (m->machine_type == MACHINE_NONE && msopts) { |
if (m->machine_type == MACHINE_NONE && msopts) { |
575 |
fprintf(stderr, "Machine specific options used directly on " |
fprintf(stderr, "Machine specific options used directly on " |
576 |
"the command line, but no machine\nemulation specified?\n"); |
"the command line, but no machine\nemulation specified?\n"); |
578 |
} |
} |
579 |
|
|
580 |
|
|
581 |
/* -i, -r, -t are pretty verbose: */ |
/* -i and -r are pretty verbose: */ |
582 |
|
|
583 |
if (m->instruction_trace && !verbose) { |
if (m->instruction_trace && !verbose) { |
584 |
fprintf(stderr, "Implicitly turning of -q and turning on -v, " |
fprintf(stderr, "Implicitly %sturning on -v, because" |
585 |
"because of -i\n"); |
" of -i\n", quiet_mode? "turning off -q and " : ""); |
586 |
verbose = 1; |
verbose = 1; |
587 |
quiet_mode = 0; |
quiet_mode = 0; |
588 |
} |
} |
589 |
|
|
590 |
if (m->register_dump && !verbose) { |
if (m->register_dump && !verbose) { |
591 |
fprintf(stderr, "Implicitly turning of -q and turning on -v, " |
fprintf(stderr, "Implicitly %sturning on -v, because" |
592 |
"because of -r\n"); |
" of -r\n", quiet_mode? "turning off -q and " : ""); |
593 |
verbose = 1; |
verbose = 1; |
594 |
quiet_mode = 0; |
quiet_mode = 0; |
595 |
} |
} |
596 |
|
|
597 |
if (m->show_trace_tree && !verbose) { |
if ((m->instruction_trace || m->register_dump || m->show_trace_tree) |
598 |
fprintf(stderr, "Implicitly turning of -q and turning on -v, " |
&& m->bintrans_enable) { |
599 |
"because of -t\n"); |
fprintf(stderr, "Implicitly turning off bintrans.\n"); |
600 |
verbose = 1; |
m->bintrans_enable = 0; |
|
quiet_mode = 0; |
|
601 |
} |
} |
602 |
|
|
603 |
|
|
605 |
* Usually, an executable filename must be supplied. |
* Usually, an executable filename must be supplied. |
606 |
* |
* |
607 |
* However, it is possible to boot directly from a harddisk image |
* However, it is possible to boot directly from a harddisk image |
608 |
* file. If no kernel is supplied, and the emulation mode is set to |
* file. If no kernel is supplied, but a diskimage is being used, |
609 |
* DECstation emulation, and there is a diskimage, then try to boot |
* then try to boot from disk. |
|
* from that. |
|
610 |
*/ |
*/ |
611 |
if (extra_argc == 0) { |
if (extra_argc == 0) { |
612 |
if (using_switch_d) { |
if (using_switch_d) { |
651 |
/* TODO: Print a warning about this? */ |
/* TODO: Print a warning about this? */ |
652 |
} |
} |
653 |
|
|
654 |
if (m->n_breakpoints > 0 && m->bintrans_enable) { |
if (m->n_breakpoints > 0 && |
655 |
fprintf(stderr, "Breakpoints and dynamic translation " |
m->bintrans_enable && m->arch == ARCH_MIPS) { |
656 |
|
fprintf(stderr, "Breakpoints and MIPS binary translation " |
657 |
"don't work too well together right now.\n"); |
"don't work too well together right now.\n"); |
658 |
exit(1); |
exit(1); |
659 |
} |
} |
696 |
int main(int argc, char *argv[]) |
int main(int argc, char *argv[]) |
697 |
{ |
{ |
698 |
struct emul **emuls; |
struct emul **emuls; |
699 |
|
char **diskimages = NULL; |
700 |
|
int n_diskimages = 0; |
701 |
int n_emuls; |
int n_emuls; |
702 |
int i; |
int i; |
703 |
|
|
723 |
exit(1); |
exit(1); |
724 |
} |
} |
725 |
|
|
726 |
get_cmd_args(argc, argv, emuls[0]); |
get_cmd_args(argc, argv, emuls[0], &diskimages, &n_diskimages); |
727 |
|
|
728 |
if (!fully_deterministic) { |
if (!fully_deterministic) { |
729 |
/* TODO: More than just time(). Use gettimeofday(). */ |
/* TODO: More than just time(). Use gettimeofday(). */ |
747 |
|
|
748 |
if (emuls[0]->machines[0]->machine_type == MACHINE_NONE) |
if (emuls[0]->machines[0]->machine_type == MACHINE_NONE) |
749 |
n_emuls --; |
n_emuls --; |
750 |
|
else { |
751 |
|
for (i=0; i<n_diskimages; i++) |
752 |
|
diskimage_add(emuls[0]->machines[0], diskimages[i]); |
753 |
|
} |
754 |
|
|
755 |
/* Simple initialization, from command line arguments: */ |
/* Simple initialization, from command line arguments: */ |
756 |
if (n_emuls > 0) { |
if (n_emuls > 0) { |
794 |
} |
} |
795 |
|
|
796 |
if (n_emuls == 0) { |
if (n_emuls == 0) { |
797 |
fprintf(stderr, "No emulations defined.\n"); |
fprintf(stderr, "No emulations defined. Maybe you forgot to " |
798 |
|
"use -E xx and/or -e yy, to specify\nthe machine type." |
799 |
|
" For example:\n\n %s -e 3max -d disk.img\n\n" |
800 |
|
"to boot an emulated DECstation 5000/200 with a disk " |
801 |
|
"image.\n", progname); |
802 |
exit(1); |
exit(1); |
803 |
} |
} |
804 |
|
|