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.228 2005/04/07 15:43:17 debug Exp $ |
* $Id: main.c,v 1.293 2007/02/05 16:49:05 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 |
|
|
49 |
|
|
50 |
extern volatile int single_step; |
extern volatile int single_step; |
51 |
extern int force_debugger_at_exit; |
extern int force_debugger_at_exit; |
|
extern int show_opcode_statistics; |
|
52 |
|
|
53 |
extern int optind; |
extern int optind; |
54 |
extern char *optarg; |
extern char *optarg; |
55 |
|
|
56 |
|
struct settings *global_settings; |
57 |
|
|
58 |
int extra_argc; |
int extra_argc; |
59 |
char **extra_argv; |
char **extra_argv; |
60 |
char *progname; |
char *progname; |
61 |
|
|
62 |
int fully_deterministic = 0; |
size_t dyntrans_cache_size = DEFAULT_DYNTRANS_CACHE_SIZE; |
63 |
|
int native_code_translation_enabled = 0; |
64 |
|
int skip_srandom_call = 0; |
65 |
|
|
66 |
|
|
67 |
/***************************************************************************** |
/***************************************************************************** |
161 |
|
|
162 |
|
|
163 |
/* |
/* |
|
* 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; |
|
|
} |
|
|
|
|
|
|
|
|
/*****************************************************************************/ |
|
|
|
|
|
|
|
|
/* |
|
164 |
* internal_w(): |
* internal_w(): |
165 |
* |
* |
166 |
* For internal use by gxemul itself. |
* For internal use by gxemul itself. |
198 |
{ |
{ |
199 |
printf("GXemul"); |
printf("GXemul"); |
200 |
#ifdef VERSION |
#ifdef VERSION |
201 |
printf("-" VERSION); |
printf(" " VERSION); |
202 |
#endif |
#endif |
203 |
printf(" Copyright (C) 2003-2005 Anders Gavare\n"); |
printf(" Copyright (C) 2003-2007 Anders Gavare\n"); |
204 |
printf("Read the source code and/or documentation for " |
printf("Read the source code and/or documentation for " |
205 |
"other Copyright messages.\n"); |
"other Copyright messages.\n"); |
206 |
|
|
207 |
printf("\nusage: %s [machine, other, and general options] [file " |
printf("\nusage: %s [machine, other, and general options] [file " |
208 |
"[...]]\n", progname); |
"[...]]\n", progname); |
209 |
printf(" or %s [general options] @configfile [...]\n", progname); |
printf(" or %s [general options] @configfile\n", progname); |
210 |
|
#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); |
213 |
|
#endif |
214 |
|
|
215 |
if (!longusage) { |
if (!longusage) { |
216 |
printf("\nRun %s -h for help on command line options.\n", |
printf("\nRun %s -h for help on command line options.\n", |
225 |
"with -E.)\n"); |
"with -E.)\n"); |
226 |
|
|
227 |
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 |
|
228 |
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 " |
229 |
"list of types.)\n"); |
"list of types.)\n"); |
230 |
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:\"" |
231 |
" as a prefix\n"); |
" as a prefix\n"); |
232 |
printf(" where xxx is one or more of the following:\n"); |
printf(" where xxx is one or more of the following:\n"); |
233 |
printf(" b specifies that this is the boot" |
printf(" b specifies that this is the boot" |
234 |
" device\n"); |
" device\n"); |
235 |
printf(" c CD-ROM (instead of normal SCSI DISK)\n"); |
printf(" c CD-ROM\n"); |
236 |
printf(" d SCSI DISK (this is the default)\n"); |
printf(" d DISK\n"); |
237 |
printf(" i IDE (instead of SCSI)\n"); |
printf(" f FLOPPY\n"); |
238 |
printf(" r read-only (don't allow changes to the" |
printf(" gH;S; set geometry to H heads and S" |
239 |
|
" sectors-per-track\n"); |
240 |
|
printf(" i IDE\n"); |
241 |
|
printf(" oOFS; set base offset to OFS (for ISO9660" |
242 |
|
" filesystems)\n"); |
243 |
|
printf(" r read-only (don't allow changes to the" |
244 |
" file)\n"); |
" file)\n"); |
245 |
printf(" t SCSI tape\n"); |
printf(" s SCSI\n"); |
246 |
printf(" 0-7 force a specific SCSI ID number\n"); |
printf(" t tape\n"); |
247 |
printf(" -I x emulate clock interrupts at x Hz (affects" |
printf(" 0-7 force a specific ID\n"); |
248 |
" rtc devices only, not\n"); |
printf(" -G port listen to gdb remote connections on this port\n"); |
249 |
printf(" actual runtime speed) (this disables automatic" |
printf(" -I hz set the main cpu frequency to hz (not used by " |
250 |
" clock adjustments)\n"); |
"all combinations\n of machines and guest OSes)\n"); |
251 |
printf(" -i display each instruction as it is executed\n"); |
printf(" -i display each instruction as it is executed\n"); |
252 |
printf(" -J disable some speed tricks\n"); |
printf(" -J disable dyntrans instruction combinations\n"); |
253 |
printf(" -j name set the name of the kernel, for example:\n"); |
printf(" -j name set the name of the kernel; for DECstation " |
254 |
printf(" -j netbsd for NetBSD/pmax\n"); |
"emulation, this passes\n the name to the bootloader," |
255 |
printf(" -j bsd for OpenBSD/pmax\n"); |
" for example:\n"); |
256 |
printf(" -j vmunix for Ultrix/RISC\n"); |
printf(" -j netbsd (NetBSD/pmax) " |
257 |
|
"-j bsd (OpenBSD/pmax)\n"); |
258 |
|
printf(" -j vmsprite (Sprite/pmax) " |
259 |
|
"-j vmunix (Ultrix/RISC)\n"); |
260 |
|
printf(" For other emulation modes, if the boot disk is an" |
261 |
|
" ISO9660\n filesystem, -j sets the name of the" |
262 |
|
" kernel to load.\n"); |
263 |
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"); |
|
264 |
printf(" -N display nr of instructions/second average, at" |
printf(" -N display nr of instructions/second average, at" |
265 |
" regular intervals\n"); |
" regular intervals\n"); |
266 |
printf(" -n nr set nr of CPUs (for SMP experiments)\n"); |
printf(" -n nr set nr of CPUs (for SMP experiments)\n"); |
267 |
printf(" -O force netboot (tftp instead of disk), even when" |
printf(" -O force netboot (tftp instead of disk), even when" |
268 |
" a disk image is\n" |
" a disk image is\n" |
269 |
" present (for DECstation, SGI, and ARC emulation)\n"); |
" present (for DECstation, SGI, and ARC emulation)\n"); |
270 |
printf(" -o arg set the boot argument (for DEC, ARC, or SGI" |
printf(" -o arg set the boot argument, for DEC, ARC, or SGI" |
271 |
" emulation).\n"); |
" emulation\n"); |
272 |
printf(" Default arg for DEC is '-a', for ARC '-aN'.\n"); |
printf(" (default arg for DEC is -a, for ARC/SGI -aN)\n"); |
273 |
printf(" -p pc add a breakpoint (remember to use the '0x' " |
printf(" -p pc add a breakpoint (remember to use the '0x' " |
274 |
"prefix for hex!)\n"); |
"prefix for hex!)\n"); |
275 |
printf(" -Q no built-in PROM emulation (use this for " |
printf(" -Q no built-in PROM emulation (use this for " |
278 |
printf(" -r register dumps before every instruction\n"); |
printf(" -r register dumps before every instruction\n"); |
279 |
printf(" -S initialize emulated RAM to random bytes, " |
printf(" -S initialize emulated RAM to random bytes, " |
280 |
"instead of zeroes\n"); |
"instead of zeroes\n"); |
281 |
printf(" -T enter the single-step debugger on " |
printf(" -s f:name write statistics to file 'name', " |
282 |
"unimplemented memory accesses\n"); |
"f is one or more of the following:\n"); |
283 |
|
printf(" v virtual program counter\n"); |
284 |
|
printf(" p physical equivalent of program counter\n"); |
285 |
|
printf(" i internal ic->f representation of " |
286 |
|
"the program counter\n"); |
287 |
|
printf(" and optionally:\n"); |
288 |
|
printf(" d disable statistics gathering at " |
289 |
|
"startup\n"); |
290 |
|
printf(" o overwrite instead of append\n"); |
291 |
|
printf(" -T halt on non-existant memory accesses\n"); |
292 |
printf(" -t show function trace tree\n"); |
printf(" -t show function trace tree\n"); |
293 |
printf(" -U enable slow_serial_interrupts_hack_for_linux\n"); |
printf(" -U enable slow_serial_interrupts_hack_for_linux\n"); |
294 |
#ifdef WITH_X11 |
#ifdef WITH_X11 |
295 |
printf(" -X use X11\n"); |
printf(" -X use X11\n"); |
|
#endif /* WITH_X11 */ |
|
296 |
printf(" -x open up new xterms for emulated serial ports " |
printf(" -x open up new xterms for emulated serial ports " |
297 |
"(default is on when\n using configuration files, off" |
"(default is on when\n using configuration files or" |
298 |
" otherwise)\n"); |
" when X11 is used, off otherwise)\n"); |
|
#ifdef WITH_X11 |
|
299 |
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"); |
300 |
#endif /* WITH_X11 */ |
#endif /* WITH_X11 */ |
|
printf(" -y x set max_random_cycles_per_chunk to x" |
|
|
" (experimental)\n"); |
|
301 |
printf(" -Z n set nr of graphics cards, for emulating a " |
printf(" -Z n set nr of graphics cards, for emulating a " |
302 |
"dual-head or tripple-head\n" |
"dual-head or tripple-head\n" |
303 |
" environment (only for DECstation emulation)\n"); |
" environment (only for DECstation emulation)\n"); |
304 |
printf(" -z disp add disp as an X11 display to use for " |
printf(" -z disp add disp as an X11 display to use for " |
305 |
"framebuffers\n"); |
"framebuffers\n"); |
306 |
|
|
307 |
|
#ifdef UNSTABLE_DEVEL |
308 |
printf("\nUserland options:\n"); |
printf("\nUserland options:\n"); |
309 |
printf(" -u emul userland-only (syscall) emulation (use -H to" |
printf(" -u emul userland-only (syscall) emulation (use -H to" |
310 |
" get a list of\n available emulation modes)\n"); |
" get a list of\n available emulation modes)\n"); |
311 |
|
#endif |
312 |
|
|
313 |
printf("\nGeneral options:\n"); |
printf("\nGeneral options:\n"); |
314 |
printf(" -D guarantee fully deterministic behaviour\n"); |
#ifdef UNSTABLE_DEVEL |
315 |
|
printf(" -b enable native code generation\n"); |
316 |
|
printf(" -B disable native code generation\n"); |
317 |
|
#endif |
318 |
|
printf(" -c cmd add cmd as a command to run before starting " |
319 |
|
"the simulation\n"); |
320 |
|
printf(" -D skip the srandom call at startup\n"); |
321 |
printf(" -H display a list of possible CPU and " |
printf(" -H display a list of possible CPU and " |
322 |
"machine types\n"); |
"machine types\n"); |
323 |
printf(" -h display this help message\n"); |
printf(" -h display this help message\n"); |
324 |
|
printf(" -k n set dyntrans translation caches to n MB (default" |
325 |
|
" size is %i MB)\n", DEFAULT_DYNTRANS_CACHE_SIZE / 1048576); |
326 |
printf(" -K force the debugger to be entered at the end " |
printf(" -K force the debugger to be entered at the end " |
327 |
"of a simulation\n"); |
"of a simulation\n"); |
328 |
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"); |
|
329 |
printf(" -V start up in the single-step debugger, paused\n"); |
printf(" -V start up in the single-step debugger, paused\n"); |
330 |
printf(" -v verbose debug messages\n"); |
printf(" -v verbose debug messages\n"); |
331 |
printf("\n"); |
printf("\n"); |
337 |
"on a binary.\n" |
"on a binary.\n" |
338 |
"To load a raw binary into memory, add \"address:\" in front " |
"To load a raw binary into memory, add \"address:\" in front " |
339 |
"of the filename,\n" |
"of the filename,\n" |
340 |
"or \"address:skiplen:\" or \"address:skiplen:initialpc\".\n" |
"or \"address:skiplen:\" or \"address:skiplen:initialpc:\".\n" |
341 |
"Examples:\n" |
"Examples:\n" |
342 |
" 0xbfc00000:rom.bin for a raw ROM image\n" |
" 0xbfc00000:rom.bin for a raw ROM image\n" |
343 |
" 0xbfc00000:0x100:rom.bin for an image with " |
" 0xbfc00000:0x100:rom.bin for an image with " |
344 |
"0x100 bytes header\n" |
"0x100 bytes header\n" |
345 |
" 0xbfc00000:0x100:0xbfc00884:rom.bin " |
" 0xbfc00000:0x100:0xbfc00884:rom.bin " |
346 |
"start with pc=0xbfc00884\n"); |
"start with pc=0xbfc00884\n"); |
347 |
} |
} |
348 |
|
|
352 |
* |
* |
353 |
* Reads command line arguments. |
* Reads command line arguments. |
354 |
*/ |
*/ |
355 |
int get_cmd_args(int argc, char *argv[], struct emul *emul) |
int get_cmd_args(int argc, char *argv[], struct emul *emul, |
356 |
|
char ***diskimagesp, int *n_diskimagesp) |
357 |
{ |
{ |
358 |
int ch, res, using_switch_d = 0, using_switch_Z = 0; |
int ch, res, using_switch_d = 0, using_switch_Z = 0; |
359 |
|
int using_switch_e = 0, using_switch_E = 0; |
360 |
char *type = NULL, *subtype = NULL; |
char *type = NULL, *subtype = NULL; |
361 |
int n_cpus_set = 0; |
int n_cpus_set = 0; |
362 |
int msopts = 0; /* Machine-specific options used */ |
int msopts = 0; /* Machine-specific options used */ |
363 |
struct machine *m = emul_add_machine(emul, "default"); |
struct machine *m = emul_add_machine(emul, "default"); |
364 |
|
|
365 |
while ((ch = getopt(argc, argv, "BbC:Dd:E:e:HhI:iJj:KM:m:" |
char *opts = |
366 |
"Nn:Oo:p:QqRrSsTtUu:VvW:XxY:y:Z:z:")) != -1) { |
#ifdef UNSTABLE_DEVEL |
367 |
|
"bB" |
368 |
|
#endif |
369 |
|
"C:c:Dd:E:e:G:HhI:iJj:k:KM:Nn:Oo:p:QqRrSs:TtU" |
370 |
|
#ifdef UNSTABLE_DEVEL |
371 |
|
"u:" |
372 |
|
#endif |
373 |
|
"VvW:" |
374 |
|
#ifdef WITH_X11 |
375 |
|
"XxY:" |
376 |
|
#endif |
377 |
|
"Z:z:"; |
378 |
|
|
379 |
|
while ((ch = getopt(argc, argv, opts)) != -1) { |
380 |
switch (ch) { |
switch (ch) { |
381 |
case 'B': |
#ifdef UNSTABLE_DEVEL |
|
m->bintrans_enable = 0; |
|
|
msopts = 1; |
|
|
break; |
|
382 |
case 'b': |
case 'b': |
383 |
m->old_bintrans_enable = 1; |
#ifndef NATIVE_CODE_GENERATION |
384 |
msopts = 1; |
printf("-b is not available on this host arch.\n"); |
385 |
|
exit(1); |
386 |
|
#else |
387 |
|
native_code_translation_enabled = 1; |
388 |
|
break; |
389 |
|
#endif |
390 |
|
case 'B': |
391 |
|
native_code_translation_enabled = 0; |
392 |
break; |
break; |
393 |
|
#endif /* UNSTABLE_DEVEL */ |
394 |
case 'C': |
case 'C': |
395 |
m->cpu_name = strdup(optarg); |
m->cpu_name = strdup(optarg); |
396 |
msopts = 1; |
msopts = 1; |
397 |
break; |
break; |
398 |
|
case 'c': |
399 |
|
emul->n_debugger_cmds ++; |
400 |
|
emul->debugger_cmds = realloc(emul->debugger_cmds, |
401 |
|
emul->n_debugger_cmds * sizeof(char *)); |
402 |
|
if (emul->debugger_cmds == NULL) { |
403 |
|
fatal("out of memory\n"); |
404 |
|
exit(1); |
405 |
|
} |
406 |
|
emul->debugger_cmds[emul->n_debugger_cmds-1] = |
407 |
|
strdup(optarg); |
408 |
|
break; |
409 |
case 'D': |
case 'D': |
410 |
fully_deterministic = 1; |
skip_srandom_call = 1; |
411 |
break; |
break; |
412 |
case 'd': |
case 'd': |
413 |
diskimage_add(m, optarg); |
/* diskimage_add() is called further down */ |
414 |
|
(*n_diskimagesp) ++; |
415 |
|
(*diskimagesp) = realloc(*diskimagesp, |
416 |
|
sizeof(char *) * (*n_diskimagesp)); |
417 |
|
if (*diskimagesp == NULL) { |
418 |
|
fprintf(stderr, "out of memory\n"); |
419 |
|
exit(1); |
420 |
|
} |
421 |
|
(*diskimagesp)[(*n_diskimagesp) - 1] = strdup(optarg); |
422 |
using_switch_d = 1; |
using_switch_d = 1; |
423 |
msopts = 1; |
msopts = 1; |
424 |
break; |
break; |
425 |
case 'E': |
case 'E': |
426 |
|
if (using_switch_E ++ > 0) { |
427 |
|
fprintf(stderr, "-E already used.\n"); |
428 |
|
exit(1); |
429 |
|
} |
430 |
type = optarg; |
type = optarg; |
431 |
msopts = 1; |
msopts = 1; |
432 |
break; |
break; |
433 |
case 'e': |
case 'e': |
434 |
|
if (using_switch_e ++ > 0) { |
435 |
|
fprintf(stderr, "-e already used.\n"); |
436 |
|
exit(1); |
437 |
|
} |
438 |
subtype = optarg; |
subtype = optarg; |
439 |
msopts = 1; |
msopts = 1; |
440 |
break; |
break; |
441 |
|
case 'G': |
442 |
|
m->gdb.port = atoi(optarg); |
443 |
|
if (m->gdb.port < 1 || m->gdb.port > 65535) { |
444 |
|
fprintf(stderr, "Invalid debugger port %i.\n", |
445 |
|
m->gdb.port); |
446 |
|
exit(1); |
447 |
|
} |
448 |
|
/* Note: implicit -V */ |
449 |
|
single_step = ENTER_SINGLE_STEPPING; |
450 |
|
msopts = 1; |
451 |
|
break; |
452 |
case 'H': |
case 'H': |
453 |
machine_list_available_types_and_cpus(); |
machine_list_available_types_and_cpus(); |
454 |
exit(1); |
exit(1); |
457 |
exit(1); |
exit(1); |
458 |
case 'I': |
case 'I': |
459 |
m->emulated_hz = atoi(optarg); |
m->emulated_hz = atoi(optarg); |
|
m->automatic_clock_adjustment = 0; |
|
460 |
msopts = 1; |
msopts = 1; |
461 |
break; |
break; |
462 |
case 'i': |
case 'i': |
464 |
msopts = 1; |
msopts = 1; |
465 |
break; |
break; |
466 |
case 'J': |
case 'J': |
467 |
m->speed_tricks = 0; |
m->allow_instruction_combinations = 0; |
468 |
msopts = 1; |
msopts = 1; |
469 |
break; |
break; |
470 |
case 'j': |
case 'j': |
475 |
} |
} |
476 |
msopts = 1; |
msopts = 1; |
477 |
break; |
break; |
478 |
|
case 'k': |
479 |
|
dyntrans_cache_size = atoi(optarg) * 1048576; |
480 |
|
if (dyntrans_cache_size < 1) { |
481 |
|
fprintf(stderr, "The dyntrans cache size must" |
482 |
|
" be at least 1 MB.\n"); |
483 |
|
exit(1); |
484 |
|
} |
485 |
|
break; |
486 |
case 'K': |
case 'K': |
487 |
force_debugger_at_exit = 1; |
force_debugger_at_exit = 1; |
488 |
break; |
break; |
490 |
m->physical_ram_in_mb = atoi(optarg); |
m->physical_ram_in_mb = atoi(optarg); |
491 |
msopts = 1; |
msopts = 1; |
492 |
break; |
break; |
|
case 'm': |
|
|
m->max_instructions = atoi(optarg); |
|
|
msopts = 1; |
|
|
break; |
|
493 |
case 'N': |
case 'N': |
494 |
m->show_nr_of_instructions = 1; |
m->show_nr_of_instructions = 1; |
495 |
msopts = 1; |
msopts = 1; |
545 |
msopts = 1; |
msopts = 1; |
546 |
break; |
break; |
547 |
case 's': |
case 's': |
548 |
show_opcode_statistics = 1; |
machine_statistics_init(m, optarg); |
549 |
|
native_code_translation_enabled = 0; |
550 |
|
msopts = 1; |
551 |
break; |
break; |
552 |
case 'T': |
case 'T': |
553 |
m->single_step_on_bad_addr = 1; |
m->halt_on_nonexistant_memaccess = 1; |
554 |
msopts = 1; |
msopts = 1; |
555 |
break; |
break; |
556 |
case 't': |
case 't': |
571 |
msopts = 1; |
msopts = 1; |
572 |
break; |
break; |
573 |
case 'V': |
case 'V': |
574 |
single_step = 1; |
single_step = ENTER_SINGLE_STEPPING; |
575 |
break; |
break; |
576 |
case 'v': |
case 'v': |
577 |
verbose ++; |
verbose ++; |
582 |
case 'X': |
case 'X': |
583 |
m->use_x11 = 1; |
m->use_x11 = 1; |
584 |
msopts = 1; |
msopts = 1; |
585 |
break; |
/* FALL-THROUGH */ |
586 |
case 'x': |
case 'x': |
587 |
console_allow_slaves(1); |
console_allow_slaves(1); |
588 |
break; |
break; |
589 |
case 'Y': |
case 'Y': |
590 |
m->x11_scaledown = atoi(optarg); |
m->x11_scaledown = atoi(optarg); |
591 |
msopts = 1; |
if (m->x11_scaledown < -1) { |
592 |
break; |
m->x11_scaleup = - m->x11_scaledown; |
593 |
case 'y': |
m->x11_scaledown = 1; |
594 |
m->max_random_cycles_per_chunk = atoi(optarg); |
} |
595 |
|
if (m->x11_scaledown < 1) { |
596 |
|
fprintf(stderr, "Invalid scaledown value.\n"); |
597 |
|
exit(1); |
598 |
|
} |
599 |
msopts = 1; |
msopts = 1; |
600 |
break; |
break; |
601 |
case 'Z': |
case 'Z': |
622 |
msopts = 1; |
msopts = 1; |
623 |
break; |
break; |
624 |
default: |
default: |
625 |
fprintf(stderr, "Invalid option.\n"); |
fprintf(stderr, "Run %s -h for help on command " |
626 |
usage(0); |
"line options.\n", progname); |
627 |
exit(1); |
exit(1); |
628 |
} |
} |
629 |
} |
} |
630 |
|
|
631 |
if (type != NULL) { |
if (type != NULL || subtype != NULL) { |
632 |
|
if (type == NULL) |
633 |
|
type = ""; |
634 |
if (subtype == NULL) |
if (subtype == NULL) |
635 |
subtype = ""; |
subtype = ""; |
636 |
res = machine_name_to_type(type, subtype, |
res = machine_name_to_type(type, subtype, |
646 |
extra_argv = argv; |
extra_argv = argv; |
647 |
|
|
648 |
|
|
|
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; |
|
|
} |
|
|
|
|
649 |
if (m->machine_type == MACHINE_NONE && msopts) { |
if (m->machine_type == MACHINE_NONE && msopts) { |
650 |
fprintf(stderr, "Machine specific options used directly on " |
fprintf(stderr, "Machine specific options used directly on " |
651 |
"the command line, but no machine\nemulation specified?\n"); |
"the command line, but no machine\nemulation specified?\n"); |
653 |
} |
} |
654 |
|
|
655 |
|
|
656 |
/* -i, -r, -t are pretty verbose: */ |
/* -i and -r are pretty verbose: */ |
657 |
|
|
658 |
if (m->instruction_trace && !verbose) { |
if (m->instruction_trace && !verbose) { |
659 |
fprintf(stderr, "Implicitly turning of -q and turning on -v, " |
fprintf(stderr, "Implicitly %sturning on -v, because" |
660 |
"because of -i\n"); |
" of -i\n", quiet_mode? "turning off -q and " : ""); |
661 |
verbose = 1; |
verbose = 1; |
662 |
quiet_mode = 0; |
quiet_mode = 0; |
663 |
} |
} |
664 |
|
|
665 |
if (m->register_dump && !verbose) { |
if (m->register_dump && !verbose) { |
666 |
fprintf(stderr, "Implicitly turning of -q and turning on -v, " |
fprintf(stderr, "Implicitly %sturning on -v, because" |
667 |
"because of -r\n"); |
" of -r\n", quiet_mode? "turning off -q and " : ""); |
|
verbose = 1; |
|
|
quiet_mode = 0; |
|
|
} |
|
|
|
|
|
if (m->show_trace_tree && !verbose) { |
|
|
fprintf(stderr, "Implicitly turning of -q and turning on -v, " |
|
|
"because of -t\n"); |
|
668 |
verbose = 1; |
verbose = 1; |
669 |
quiet_mode = 0; |
quiet_mode = 0; |
670 |
} |
} |
674 |
* Usually, an executable filename must be supplied. |
* Usually, an executable filename must be supplied. |
675 |
* |
* |
676 |
* However, it is possible to boot directly from a harddisk image |
* However, it is possible to boot directly from a harddisk image |
677 |
* 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, |
678 |
* DECstation emulation, and there is a diskimage, then try to boot |
* then try to boot from disk. |
|
* from that. |
|
679 |
*/ |
*/ |
680 |
if (extra_argc == 0) { |
if (extra_argc == 0) { |
681 |
if (using_switch_d) { |
if (using_switch_d) { |
715 |
exit(1); |
exit(1); |
716 |
} |
} |
717 |
|
|
|
if (m->bintrans_enable) { |
|
|
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 |
|
|
|
|
718 |
if (!using_switch_Z && !m->use_x11) |
if (!using_switch_Z && !m->use_x11) |
719 |
m->n_gfx_cards = 0; |
m->n_gfx_cards = 0; |
720 |
|
|
|
m->bintrans_enabled_from_start = m->bintrans_enable; |
|
|
|
|
721 |
return 0; |
return 0; |
722 |
} |
} |
723 |
|
|
734 |
*/ |
*/ |
735 |
int main(int argc, char *argv[]) |
int main(int argc, char *argv[]) |
736 |
{ |
{ |
737 |
|
/* Setting constants: */ |
738 |
|
const int constant_yes = 1; |
739 |
|
const int constant_true = 1; |
740 |
|
const int constant_no = 0; |
741 |
|
const int constant_false = 0; |
742 |
|
|
743 |
struct emul **emuls; |
struct emul **emuls; |
744 |
|
char **diskimages = NULL; |
745 |
|
int n_diskimages = 0; |
746 |
int n_emuls; |
int n_emuls; |
747 |
int i; |
int i; |
748 |
|
|
749 |
|
|
750 |
|
#ifdef USE_PROFIL |
751 |
|
uint16_t samples[0x100000]; |
752 |
|
memset(samples, 0, sizeof(samples)); |
753 |
|
profil((char *)samples, sizeof(samples), (vm_offset_t) 0x400000, 8192); |
754 |
|
#endif |
755 |
|
|
756 |
|
#ifndef NATIVE_CODE_GENERATION |
757 |
|
native_code_translation_enabled = 0; |
758 |
|
#endif |
759 |
|
|
760 |
|
|
761 |
progname = argv[0]; |
progname = argv[0]; |
762 |
|
|
763 |
|
|
764 |
|
/* |
765 |
|
* Create the settings object, and add global settings to it: |
766 |
|
* |
767 |
|
* Read-only "constants": yes, no, true, false. |
768 |
|
* Global emulator settings: verbose, single_step, ... |
769 |
|
*/ |
770 |
|
global_settings = settings_new(); |
771 |
|
|
772 |
|
settings_add(global_settings, "yes", 0, SETTINGS_TYPE_INT, |
773 |
|
SETTINGS_FORMAT_YESNO, (void *)&constant_yes); |
774 |
|
settings_add(global_settings, "no", 0, SETTINGS_TYPE_INT, |
775 |
|
SETTINGS_FORMAT_YESNO, (void *)&constant_no); |
776 |
|
settings_add(global_settings, "true", 0, SETTINGS_TYPE_INT, |
777 |
|
SETTINGS_FORMAT_BOOL, (void *)&constant_true); |
778 |
|
settings_add(global_settings, "false", 0, SETTINGS_TYPE_INT, |
779 |
|
SETTINGS_FORMAT_BOOL, (void *)&constant_false); |
780 |
|
|
781 |
|
/* Read-only settings: */ |
782 |
|
settings_add(global_settings, "native_code_translation_enabled", 0, |
783 |
|
SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, |
784 |
|
(void *)&native_code_translation_enabled); |
785 |
|
settings_add(global_settings, "single_step", 0, |
786 |
|
SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, (void *)&single_step); |
787 |
|
|
788 |
|
/* Read/write settings: */ |
789 |
|
settings_add(global_settings, "force_debugger_at_exit", 1, |
790 |
|
SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, |
791 |
|
(void *)&force_debugger_at_exit); |
792 |
|
settings_add(global_settings, "verbose", 1, |
793 |
|
SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, (void *)&verbose); |
794 |
|
settings_add(global_settings, "quiet_mode", 1, |
795 |
|
SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, (void *)&quiet_mode); |
796 |
|
|
797 |
|
/* Initialize all emulator subsystems: */ |
798 |
console_init(); |
console_init(); |
799 |
cpu_init(); |
cpu_init(); |
800 |
device_init(); |
device_init(); |
801 |
machine_init(); |
machine_init(); |
802 |
|
timer_init(); |
803 |
useremul_init(); |
useremul_init(); |
804 |
|
|
805 |
emuls = malloc(sizeof(struct emul *)); |
emuls = malloc(sizeof(struct emul *)); |
810 |
|
|
811 |
/* Allocate space for a simple emul setup: */ |
/* Allocate space for a simple emul setup: */ |
812 |
n_emuls = 1; |
n_emuls = 1; |
813 |
emuls[0] = emul_new(NULL); |
emuls[0] = emul_new(NULL, 0); |
814 |
if (emuls[0] == NULL) { |
if (emuls[0] == NULL) { |
815 |
fprintf(stderr, "out of memory\n"); |
fprintf(stderr, "out of memory\n"); |
816 |
exit(1); |
exit(1); |
817 |
} |
} |
818 |
|
settings_add(global_settings, "emul[0]", 1, |
819 |
|
SETTINGS_TYPE_SUBSETTINGS, 0, emuls[0]->settings); |
820 |
|
|
821 |
get_cmd_args(argc, argv, emuls[0]); |
get_cmd_args(argc, argv, emuls[0], &diskimages, &n_diskimages); |
822 |
|
|
823 |
if (!fully_deterministic) { |
if (!skip_srandom_call) { |
824 |
/* TODO: More than just time(). Use gettimeofday(). */ |
struct timeval tv; |
825 |
srandom(time(NULL) ^ (getpid() << 12)); |
gettimeofday(&tv, NULL); |
826 |
} 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); |
|
|
} |
|
827 |
} |
} |
828 |
|
|
829 |
/* Print startup message: */ |
/* Print startup message: */ |
830 |
debug("GXemul"); |
debug("GXemul"); |
831 |
#ifdef VERSION |
#ifdef VERSION |
832 |
debug("-" VERSION); |
debug(" " VERSION); |
833 |
#endif |
#endif |
834 |
debug(" Copyright (C) 2003-2005 Anders Gavare\n"); |
debug(" Copyright (C) 2003-2007 Anders Gavare\n"); |
835 |
debug("Read the source code and/or documentation for " |
debug("Read the source code and/or documentation for " |
836 |
"other Copyright messages.\n\n"); |
"other Copyright messages.\n\n"); |
837 |
|
|
838 |
if (emuls[0]->machines[0]->machine_type == MACHINE_NONE) |
if (emuls[0]->machines[0]->machine_type == MACHINE_NONE) { |
839 |
n_emuls --; |
n_emuls --; |
840 |
|
} else { |
841 |
|
for (i=0; i<n_diskimages; i++) |
842 |
|
diskimage_add(emuls[0]->machines[0], diskimages[i]); |
843 |
|
} |
844 |
|
|
845 |
/* Simple initialization, from command line arguments: */ |
/* Simple initialization, from command line arguments: */ |
846 |
if (n_emuls > 0) { |
if (n_emuls > 0) { |
862 |
/* Initialize emulations from config files: */ |
/* Initialize emulations from config files: */ |
863 |
for (i=1; i<argc; i++) { |
for (i=1; i<argc; i++) { |
864 |
if (argv[i][0] == '@') { |
if (argv[i][0] == '@') { |
865 |
|
char tmpstr[50]; |
866 |
char *s = argv[i] + 1; |
char *s = argv[i] + 1; |
867 |
if (strlen(s) == 0 && i+1 < argc && |
if (strlen(s) == 0 && i+1 < argc && |
868 |
argv[i+1][0] != '@') { |
argv[i+1][0] != '@') { |
875 |
fprintf(stderr, "out of memory\n"); |
fprintf(stderr, "out of memory\n"); |
876 |
exit(1); |
exit(1); |
877 |
} |
} |
|
emuls[n_emuls - 1] = |
|
|
emul_create_from_configfile(s); |
|
878 |
|
|
879 |
/* Always allow slave xterms when using multiple |
/* Always allow slave xterms when using multiple |
880 |
emulations: */ |
emulations: */ |
881 |
console_allow_slaves(1); |
console_allow_slaves(1); |
882 |
|
|
883 |
|
/* Destroy the temporary emuls[0], since it will |
884 |
|
be overwritten: */ |
885 |
|
if (n_emuls == 1) { |
886 |
|
emul_destroy(emuls[0]); |
887 |
|
settings_remove(global_settings, "emul[0]"); |
888 |
|
} |
889 |
|
|
890 |
|
emuls[n_emuls - 1] = |
891 |
|
emul_create_from_configfile(s, n_emuls - 1); |
892 |
|
|
893 |
|
snprintf(tmpstr, sizeof(tmpstr), "emul[%i]", n_emuls-1); |
894 |
|
settings_add(global_settings, tmpstr, 1, |
895 |
|
SETTINGS_TYPE_SUBSETTINGS, 0, |
896 |
|
emuls[n_emuls-1]->settings); |
897 |
} |
} |
898 |
} |
} |
899 |
|
|
900 |
if (n_emuls == 0) { |
if (n_emuls == 0) { |
901 |
fprintf(stderr, "No emulations defined.\n"); |
fprintf(stderr, "No emulations defined. Maybe you forgot to " |
902 |
|
"use -E xx and/or -e yy, to specify\nthe machine type." |
903 |
|
" For example:\n\n %s -e 3max -d disk.img\n\n" |
904 |
|
"to boot an emulated DECstation 5000/200 with a disk " |
905 |
|
"image.\n", progname); |
906 |
exit(1); |
exit(1); |
907 |
} |
} |
908 |
|
|
909 |
device_set_exit_on_error(0); |
device_set_exit_on_error(0); |
910 |
|
console_warn_if_slaves_are_needed(1); |
911 |
|
|
912 |
|
|
913 |
/* Run all emulations: */ |
/* Run all emulations: */ |
914 |
emul_run(emuls, n_emuls); |
emul_run(emuls, n_emuls); |
915 |
|
|
916 |
|
|
917 |
|
/* |
918 |
|
* Deinitialize everything: |
919 |
|
*/ |
920 |
|
|
921 |
|
console_deinit(); |
922 |
|
|
923 |
|
for (i=0; i<n_emuls; i++) |
924 |
|
emul_destroy(emuls[i]); |
925 |
|
|
926 |
|
settings_remove_all(global_settings); |
927 |
|
settings_destroy(global_settings); |
928 |
|
|
929 |
|
#ifdef USE_PROFIL |
930 |
|
{ |
931 |
|
int i; |
932 |
|
FILE *f = fopen("output.txt", "w"); |
933 |
|
for (i=0; i<sizeof(samples) / sizeof(uint16_t); ++i) { |
934 |
|
if (samples[i] != 0) |
935 |
|
fprintf(f, "%i %p\n", samples[i], |
936 |
|
(void *) (size_t) (0x400000 + i * 16)); |
937 |
|
} |
938 |
|
} |
939 |
|
#endif |
940 |
|
|
941 |
return 0; |
return 0; |
942 |
} |
} |
943 |
|
|