our ($sim);
our ($debug);
our ($vga);
-our ($jitter);
+our ($jitter, $realtime);
use Getopt::Long qw(:config require_order bundling);
GetOptions ("sim=s" => sub { set_sim (@_) },
"run|get|put|make-disk" => \&cmd_option,
"m|memory=i" => \$mem,
- "j|jitter=i" => \$jitter,
+ "j|jitter=i" => sub { set_jitter (@_) },
+ "r|realtime" => sub { set_realtime () },
"v|no-vga" => sub { set_vga ('none'); },
"s|no-serial" => sub { $serial_out = 0; },
$vga = $new_vga;
}
+sub set_jitter {
+ my ($new_jitter) = @_;
+ die "--realtime conflicts with --jitter\n" if defined $realtime;
+ die "different --jitter already defined\n"
+ if defined $jitter && $jitter != $new_jitter;
+ $jitter = $new_jitter;
+}
+
+sub set_realtime {
+ die "--realtime conflicts with --jitter\n" if defined $jitter;
+ $realtime = 1;
+}
+
sub cmd_option {
# Force an end to option processing, as with --.
die ("!FINISH");
if @ARGV < 1;
my ($cmd) = shift @ARGV;
if ($cmd eq 'run') {
- run_vm (@ARGV);
+ run_vm ('EXEC', @ARGV);
} elsif ($cmd eq 'make-disk') {
usage () if @ARGV != 2;
my ($file, $mb) = @ARGV;
# Create scratch disk from file.
die "$hostfn: $!\n" if ! -e $hostfn;
my ($size) = -s _;
- copy_pad ($hostfn, "scratch.dsk", 512);
+ 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 (@cmd);
+ run_vm ('EXEC', @cmd);
} elsif ($cmd eq 'get') {
usage () if @ARGV != 1 && @ARGV != 2;
my ($guestfn, $hostfn) = @ARGV;
if $scratch_size < $fs_size + 16384;
# Do copy.
- run_vm ("-co", $guestfn, "-q");
+ run_vm ('FORK', "-co", $guestfn, "-q");
# Read out scratch disk.
print "copying $guestfn from $disks[2] to $hostfn...\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";
}
sub run_vm {
+ my ($fork) = shift;
+ $fork eq 'FORK' || $fork eq 'EXEC' or die;
+
our (@disks);
die "$disks[0]: can't find OS disk\n" if ! -e $disks[0];
undef $disks[$i] if ! -e $disks[$i];
}
+ my ($project) = `pwd` =~ /\b(threads|userprog|vm|filesys)\b/;
+ if (($project eq 'userprog' || $project eq 'vm' || $project eq 'filesys')
+ && !defined $disks[1]) {
+ print STDERR "warning: it looks like you're running the $project project, "
+ . "but no file system disk is present\n";
+ }
+ if ($project eq 'vm' && !defined $disks[3]) {
+ print STDERR "warning: it looks like you're running the $project project, "
+ . "but no swap disk is present\n";
+ }
+
write_cmd_line ($disks[0], @_);
if ($sim eq 'bochs') {
print BOCHSRC bochs_disk_line ("ata1-slave", $disks[3]);
print BOCHSRC "boot: c\n";
print BOCHSRC "ips: 1000000\n";
- print BOCHSRC "clock: sync=none, time0=0\n";
+ if (!$realtime) {
+ print BOCHSRC "clock: sync=none, time0=0\n";
+ } else {
+ print BOCHSRC "clock: sync=realtime, time0=0\n";
+ }
print BOCHSRC "megs: $mem\n";
print BOCHSRC "log: bochsout.txt\n";
if ($vga ne 'terminal') {
my (@cmd) = ($bin, '-q');
push (@cmd, '-j', $jitter) if defined $jitter;
- print join (' ', @_), "\n";
- exec (@_);
+ print join (' ', @cmd), "\n";
+ $fork eq 'EXEC' ? exec (@cmd) : system (@cmd);
} elsif ($sim eq 'qemu') {
print "warning: qemu doesn't support --terminal\n"
if $vga eq 'terminal';