-sub cmd_option {
- # Force an end to option processing, as with --.
- die ("!FINISH");
-}
-
-die "no command specified; use --help for help\n"
- if @ARGV < 1;
-my ($cmd) = shift @ARGV;
-if ($cmd eq 'run') {
- run_vm ('EXEC', @ARGV);
-} elsif ($cmd eq 'make-disk') {
- usage () if @ARGV != 2;
- my ($file, $mb) = @ARGV;
- usage () if $mb !~ /^\d+(\.\d+)?|\.\d+$/;
- die "$file: already exists\n" if -e $file;
-
- create_disk ($file, int ($mb * 1008));
-} elsif ($cmd eq 'put') {
- # Take a -f option to combine formatting with putting.
- my ($format) = 0;
- if (@ARGV > 0 && $ARGV[0] eq '-f') {
- shift @ARGV;
- $format = 1;
- }
-
- usage () if @ARGV != 1 && @ARGV != 2;
- my ($hostfn, $guestfn) = @ARGV;
- $guestfn = $hostfn if !defined $guestfn;
-
- # Create scratch disk from file.
- die "$hostfn: $!\n" if ! -e $hostfn;
- my ($size) = -s _;
- if ($size) {
- copy_pad ($hostfn, "scratch.dsk", 512);
- } else {
- open (SCRATCH, ">scratch.dsk") or die "scratch.dsk: create: $!\n";
- syswrite (SCRATCH, "\0" x 512);
- close (SCRATCH);
- }
-
- # Do copy.
- my (@cmd) = ("-ci", $guestfn, $size, "-q");
- unshift (@cmd, "-f") if $format;
- run_vm ('EXEC', @cmd);
-
- exit 1;
-} elsif ($cmd eq 'get') {
- usage () if @ARGV != 1 && @ARGV != 2;
- my ($guestfn, $hostfn) = @ARGV;
- $hostfn = $guestfn if !defined $hostfn;
- die "$hostfn: already exists\n" if -e $hostfn;
-
- # Create scratch disk big enough for any file in the filesystem
- # (modulo sparse files).
- die "$disks[1]: $!\n" if ! -e $disks[1];
- my ($fs_size) = -s _;
- my ($scratch_size) = -s $disks[2];
- $scratch_size = 0 if !defined $scratch_size;
- create_disk ($disks[2], $fs_size / 1024 + 16)
- if $scratch_size < $fs_size + 16384;
-
- # Do copy.
- run_vm ('FORK', "-co", $guestfn, "-q");
-
- # Read out scratch disk.
- print "copying $guestfn from $disks[2] to $hostfn...\n";
- open (SRC, "<$disks[2]") or die "$disks[2]: open: $!\n";
- open (DST, ">$hostfn") or die "$hostfn: create: $!\n";
- my ($input);
- read (SRC, $input, 512) == 512 or die "$disks[2]: read error\n";
- my ($size) = unpack ("V", $input);
- $size != 0xffffffff or die "$guestfn: too big for $disks[2]?";
- my ($src);
- read (SRC, $src, $size) == $size or die "$disks[2]: read error\n";
- print DST $src or die "$hostfn: write error\n";
- close (DST);
- close (SRC);
-
- exit 1;
-} elsif ($cmd eq 'help') {
- usage (0);
-} else {
- die "unknown command `$cmd'; use --help for help\n";
-}
-exit 0;
-
-sub usage {
- my ($exitcode) = @_;
- $exitcode = 1 unless defined $exitcode;
- print "pintos, a utility for invoking Pintos in a simulator\n";
- print "Usage: pintos [OPTION...] COMMAND [ARG...]\n";
- print "where COMMAND is one of the following:\n";
- print " run [CMDLINE...] run a VM in the simulator\n";
- print " make-disk FILE.DSK SIZE create FILE.DSK as empty SIZE MB disk\n";
- print " put HOSTFN [GUESTFN] copy HOSTFN into VM (as GUESTFN)\n";
- print " get GUESTFN [HOSTFN] copy GUESTFN out of VM (to HOSTFN)\n";
- print " help print this help message and exit\n";
- print "Simulator options:\n";
- print " --bochs (default) Use Bochs as simulator\n";
- print " --qemu Use qemu as simulator\n";
- print " --gsx Use VMware GSX Server 3.x as simulator\n";
- print "Debugger options:\n";
- print " --no-debug (default) No debugger\n";
- print " --monitor Debug with simulator's monitor\n";
- print " --gdb Debug with gdb\n";
- print "Display options: (default is VGA + serial)\n";
- print " -v, --no-vga No VGA display\n";
- print " -s, --no-serial No serial output\n";
- print " -t, --terminal Display VGA in terminal (Bochs only)\n";
- print "VM options:\n";
- print " -j SEED Randomize timer interrupts (Bochs only)\n";
- print " -r, --realtime Use realistic, but not reproducible, timings\n";
- print " -m, --mem=MB Run VM with MB megabytes of physical memory\n";
- print "Disk options:\n";
- print " --os-disk=DISK Set OS disk file (default: os.dsk)\n";
- print " --fs-disk=DISK Set FS disk file (default: fs.dsk)\n";
- print " --scratch-disk=DISK Set scratch disk (default: scratch.dsk)\n";
- print " --swap-disk=DISK Set swap disk file (default: swap.dsk)\n";
- exit $exitcode;