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.236 2005/05/25 06:40:18 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. |
226 |
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:\"" |
227 |
" as a prefix\n"); |
" as a prefix\n"); |
228 |
printf(" where xxx is one or more of the following:\n"); |
printf(" where xxx is one or more of the following:\n"); |
229 |
printf(" b specifies that this is the boot" |
printf(" b specifies that this is the boot" |
230 |
" device\n"); |
" device\n"); |
231 |
printf(" c CD-ROM (instead of normal SCSI DISK)\n"); |
printf(" c CD-ROM\n"); |
232 |
printf(" d SCSI DISK (this is the default)\n"); |
printf(" d DISK\n"); |
233 |
printf(" i IDE (instead of SCSI)\n"); |
printf(" f FLOPPY\n"); |
234 |
printf(" r read-only (don't allow changes to the" |
printf(" gH;S; set geometry to H heads and S" |
235 |
|
" sectors-per-track\n"); |
236 |
|
printf(" i IDE\n"); |
237 |
|
printf(" r read-only (don't allow changes to the" |
238 |
" file)\n"); |
" file)\n"); |
239 |
printf(" t SCSI tape\n"); |
printf(" s SCSI\n"); |
240 |
printf(" 0-7 force a specific SCSI ID number\n"); |
printf(" t tape\n"); |
241 |
|
printf(" 0-7 force a specific ID\n"); |
242 |
printf(" -I x emulate clock interrupts at x Hz (affects" |
printf(" -I x emulate clock interrupts at x Hz (affects" |
243 |
" rtc devices only, not\n"); |
" rtc devices only, not\n"); |
244 |
printf(" actual runtime speed) (this disables automatic" |
printf(" actual runtime speed) (this disables automatic" |
313 |
"on a binary.\n" |
"on a binary.\n" |
314 |
"To load a raw binary into memory, add \"address:\" in front " |
"To load a raw binary into memory, add \"address:\" in front " |
315 |
"of the filename,\n" |
"of the filename,\n" |
316 |
"or \"address:skiplen:\" or \"address:skiplen:initialpc\".\n" |
"or \"address:skiplen:\" or \"address:skiplen:initialpc:\".\n" |
317 |
"Examples:\n" |
"Examples:\n" |
318 |
" 0xbfc00000:rom.bin for a raw ROM image\n" |
" 0xbfc00000:rom.bin for a raw ROM image\n" |
319 |
" 0xbfc00000:0x100:rom.bin for an image with " |
" 0xbfc00000:0x100:rom.bin for an image with " |
320 |
"0x100 bytes header\n" |
"0x100 bytes header\n" |
321 |
" 0xbfc00000:0x100:0xbfc00884:rom.bin " |
" 0xbfc00000:0x100:0xbfc00884:rom.bin " |
322 |
"start with pc=0xbfc00884\n"); |
"start with pc=0xbfc00884\n"); |
323 |
} |
} |
324 |
|
|
328 |
* |
* |
329 |
* Reads command line arguments. |
* Reads command line arguments. |
330 |
*/ |
*/ |
331 |
int get_cmd_args(int argc, char *argv[], struct emul *emul) |
int get_cmd_args(int argc, char *argv[], struct emul *emul, |
332 |
|
char ***diskimagesp, int *n_diskimagesp) |
333 |
{ |
{ |
334 |
int ch, res, using_switch_d = 0, using_switch_Z = 0; |
int ch, res, using_switch_d = 0, using_switch_Z = 0; |
335 |
char *type = NULL, *subtype = NULL; |
char *type = NULL, *subtype = NULL; |
356 |
fully_deterministic = 1; |
fully_deterministic = 1; |
357 |
break; |
break; |
358 |
case 'd': |
case 'd': |
359 |
diskimage_add(m, optarg); |
/* diskimage_add() is called further down */ |
360 |
|
(*n_diskimagesp) ++; |
361 |
|
(*diskimagesp) = realloc(*diskimagesp, |
362 |
|
sizeof(char *) * (*n_diskimagesp)); |
363 |
|
if (*diskimagesp == NULL) { |
364 |
|
fprintf(stderr, "out of memory\n"); |
365 |
|
exit(1); |
366 |
|
} |
367 |
|
(*diskimagesp)[(*n_diskimagesp) - 1] = strdup(optarg); |
368 |
using_switch_d = 1; |
using_switch_d = 1; |
369 |
msopts = 1; |
msopts = 1; |
370 |
break; |
break; |
510 |
break; |
break; |
511 |
case 'Y': |
case 'Y': |
512 |
m->x11_scaledown = atoi(optarg); |
m->x11_scaledown = atoi(optarg); |
513 |
|
if (m->x11_scaledown < 1) { |
514 |
|
fprintf(stderr, "Invalid scaledown value.\n"); |
515 |
|
exit(1); |
516 |
|
} |
517 |
msopts = 1; |
msopts = 1; |
518 |
break; |
break; |
519 |
case 'y': |
case 'y': |
587 |
/* -i, -r, -t are pretty verbose: */ |
/* -i, -r, -t are pretty verbose: */ |
588 |
|
|
589 |
if (m->instruction_trace && !verbose) { |
if (m->instruction_trace && !verbose) { |
590 |
fprintf(stderr, "Implicitly turning of -q and turning on -v, " |
fprintf(stderr, "Implicitly %sturning on -v, because" |
591 |
"because of -i\n"); |
" of -i\n", quiet_mode? "turning off -q and " : ""); |
592 |
verbose = 1; |
verbose = 1; |
593 |
quiet_mode = 0; |
quiet_mode = 0; |
594 |
} |
} |
595 |
|
|
596 |
if (m->register_dump && !verbose) { |
if (m->register_dump && !verbose) { |
597 |
fprintf(stderr, "Implicitly turning of -q and turning on -v, " |
fprintf(stderr, "Implicitly %sturning on -v, because" |
598 |
"because of -r\n"); |
" of -r\n", quiet_mode? "turning off -q and " : ""); |
599 |
verbose = 1; |
verbose = 1; |
600 |
quiet_mode = 0; |
quiet_mode = 0; |
601 |
} |
} |
602 |
|
|
603 |
if (m->show_trace_tree && !verbose) { |
if (m->show_trace_tree && !verbose) { |
604 |
fprintf(stderr, "Implicitly turning of -q and turning on -v, " |
fprintf(stderr, "Implicitly %sturning on -v, because" |
605 |
"because of -t\n"); |
" of -t\n", quiet_mode? "turning off -q and " : ""); |
606 |
verbose = 1; |
verbose = 1; |
607 |
quiet_mode = 0; |
quiet_mode = 0; |
608 |
} |
} |
612 |
* Usually, an executable filename must be supplied. |
* Usually, an executable filename must be supplied. |
613 |
* |
* |
614 |
* However, it is possible to boot directly from a harddisk image |
* However, it is possible to boot directly from a harddisk image |
615 |
* 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, |
616 |
* DECstation emulation, and there is a diskimage, then try to boot |
* then try to boot from disk. |
|
* from that. |
|
617 |
*/ |
*/ |
618 |
if (extra_argc == 0) { |
if (extra_argc == 0) { |
619 |
if (using_switch_d) { |
if (using_switch_d) { |
702 |
int main(int argc, char *argv[]) |
int main(int argc, char *argv[]) |
703 |
{ |
{ |
704 |
struct emul **emuls; |
struct emul **emuls; |
705 |
|
char **diskimages = NULL; |
706 |
|
int n_diskimages = 0; |
707 |
int n_emuls; |
int n_emuls; |
708 |
int i; |
int i; |
709 |
|
|
729 |
exit(1); |
exit(1); |
730 |
} |
} |
731 |
|
|
732 |
get_cmd_args(argc, argv, emuls[0]); |
get_cmd_args(argc, argv, emuls[0], &diskimages, &n_diskimages); |
733 |
|
|
734 |
if (!fully_deterministic) { |
if (!fully_deterministic) { |
735 |
/* TODO: More than just time(). Use gettimeofday(). */ |
/* TODO: More than just time(). Use gettimeofday(). */ |
753 |
|
|
754 |
if (emuls[0]->machines[0]->machine_type == MACHINE_NONE) |
if (emuls[0]->machines[0]->machine_type == MACHINE_NONE) |
755 |
n_emuls --; |
n_emuls --; |
756 |
|
else { |
757 |
|
for (i=0; i<n_diskimages; i++) |
758 |
|
diskimage_add(emuls[0]->machines[0], diskimages[i]); |
759 |
|
} |
760 |
|
|
761 |
/* Simple initialization, from command line arguments: */ |
/* Simple initialization, from command line arguments: */ |
762 |
if (n_emuls > 0) { |
if (n_emuls > 0) { |
800 |
} |
} |
801 |
|
|
802 |
if (n_emuls == 0) { |
if (n_emuls == 0) { |
803 |
fprintf(stderr, "No emulations defined.\n"); |
fprintf(stderr, "No emulations defined. Maybe you forgot to " |
804 |
|
"use -E xx (and -e yy), to specify\nthe machine type)." |
805 |
|
" For example:\n\n %s -E dec -e 3max -d disk.img\n\n" |
806 |
|
"to boot an emulated DECstation 5000/200 with a disk " |
807 |
|
"image.\n", progname); |
808 |
exit(1); |
exit(1); |
809 |
} |
} |
810 |
|
|