Change -nv to -v, -ns to -s, for consistency.
[pintos-anon] / src / utils / pintos
index 867f2c1c056348866aaad710edc456425fe263d5..5557535457f34c1d9d71c374bea7c8f998a5cc67 100755 (executable)
@@ -13,32 +13,34 @@ while (@ARGV) {
     } elsif ($arg eq 'run') {
        run_vm (@ARGV);
        exit 0;
-    } elsif ($arg =~ /^mem(?:ory)?=(\d+)/) {
+    } elsif ($arg =~ /^--mem(?:ory)?=(\d+)/) {
        $mem = $1;
-    } elsif ($arg eq '--no-vga' || $arg eq '-nv') {
+    } elsif ($arg eq '-m') {
+       die "-m needs integer argument\n" if !@ARGV || $ARGV[0] !~ /^-?\d+$/;
+       $mem = shift (@ARGV);
+    } elsif ($arg eq '-j') {
+       die "-j need random seed argument\n" if !@ARGV;
+       die "-j need integer argument\n" if $ARGV[0] !~ /^-?\d+$/;
+       $jitter = shift (@ARGV);
+    } elsif ($arg =~ /--jitter=(-?\d+)$/) {
+       $jitter = $1;
+    } elsif ($arg eq '--no-vga' || $arg eq '-v') {
        print "warning: --no-vga conflicts with --terminal\n"
            if $vga eq 'terminal';
        $vga = 'none';
-    } elsif ($arg eq '--no-serial' || $arg eq '-ns') {
+    } elsif ($arg eq '--no-serial' || $arg eq '-s') {
        $serial_out = 0;
     } elsif ($arg eq '--terminal' || $arg eq '-t') {
        print "warning: --terminal conflicts with --no-vga\n"
            if $vga eq 'none';
        $vga = 'terminal';
     } elsif ($arg eq 'make-disk') {
-       my ($force) = @ARGV > 0 && $ARGV[0] eq '--force';
-       shift @ARGV if $force;
        usage () if @ARGV != 2;
        my ($file, $mb) = @ARGV;
-       usage () if $mb !~ /^\d+$/;
+       usage () if $mb !~ /^\d+(\.\d+)?|\.\d+$/;
        die "$file: already exists\n" if -e $file;
 
-       if ($mb != .5 && $mb != 1 && $mb != 1.5 && $mb != 2) {
-           print "$file: recommended sizes are .5, 1, 1.5, or 2 MB\n";
-           die "use --force to override\n" if !$force;
-       }
-
-       create_disk ($file, $mb * 1008);
+       create_disk ($file, int ($mb * 1008));
        exit 0;
     } elsif ($arg eq 'put') {
        usage () if @ARGV != 1 && @ARGV != 2;
@@ -51,7 +53,7 @@ while (@ARGV) {
        copy_pad ($hostfn, "scratch.dsk", 512);
 
        # Do copy.
-       run_vm ("-ci", $hostfn, $size, "-q");
+       run_vm ("-ci", $guestfn, $size, "-q");
        exit 0;
     } elsif ($arg eq 'get') {
        usage () if @ARGV != 1 && @ARGV != 2;
@@ -113,11 +115,12 @@ sub usage {
     print "  --monitor        Debug with simulator's monitor\n";
     print "  --gdb            Debug with gdb\n";
     print "Display options: (default is VGA + serial)\n";
-    print "  -nv, --no-vga    No VGA display\n";
-    print "  -ns, --no-serial No serial output\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 "  --mem=MB         Run VM with MB megabytes of physical memory\n";
+    print "  -j SEED          Randomize timer interrupts (Bochs only)\n";
+    print "  -m, --mem=MB     Run VM with MB megabytes of physical memory\n";
     exit $exitcode;
 }
 
@@ -164,6 +167,8 @@ sub run_vm {
        print BOCHSRC "vgaromimage: $vgaromimage\n";
        print BOCHSRC bochs_disk_line ("ata0-master", $disks[0]);
        print BOCHSRC bochs_disk_line ("ata0-slave", $disks[1]);
+       print BOCHSRC "ata1: enabled=1, ioaddr1=0x170, ioaddr2=0x370, irq=15\n"
+           if defined ($disks[2]) || defined ($disks[3]);
        print BOCHSRC bochs_disk_line ("ata1-master", $disks[2]);
        print BOCHSRC bochs_disk_line ("ata1-slave", $disks[3]);
        print BOCHSRC "boot: c\n";
@@ -180,10 +185,14 @@ sub run_vm {
            print BOCHSRC "display_library: term\n";
        }
        close (BOCHSRC);
-       run_command ($bin, '-q');
+       @cmd = ($bin, '-q');
+       push (@cmd, '-j', $jitter) if defined $jitter;
+       run_command_no_die (@cmd);
     } elsif ($sim eq 'qemu') {
        print "warning: qemu doesn't support --terminal\n"
            if $vga eq 'terminal';
+       print "warning: qemu doesn't support jitter\n"
+           if defined $jitter;
        my (@cmd) = ('qemu');
        push (@cmd, '-hda', $disks[0]) if defined $disks[0];
        push (@cmd, '-hdb', $disks[1]) if defined $disks[1];
@@ -202,6 +211,8 @@ sub run_vm {
            if $vga eq 'none';
        print "warning: VMware GSX Server doesn't support --terminal\n"
            if $vga eq 'terminal';
+       print "warning: VMware GSX Server doesn't support jitter\n"
+           if defined $jitter;
 
        open (VMX, ">pintos.vmx") or die "pintos.vmx: create: $!\n";
        chmod 0777 & ~umask, "pintos.vmx";
@@ -271,6 +282,11 @@ sub run_command {
     die "command failed\n" if system (@_);
 }
 
+sub run_command_no_die {
+    print join (' ', @_), "\n";
+    system (@_);
+}
+
 sub search_path {
     my ($target) = @_;
     for $dir (split (':', $ENV{PATH})) {
@@ -284,7 +300,7 @@ sub bochs_disk_line {
     return "" if !defined $file;
     my (%geom) = disk_geometry ($file);
     return "$device: type=disk, path=$file, mode=flat, "
-       . " cylinders=$geom{C}, heads=$geom{H}, spt=$geom{S}, "
+       . "cylinders=$geom{C}, heads=$geom{H}, spt=$geom{S}, "
        . "translation=none\n";
 }