]> rtime.felk.cvut.cz Git - l4.git/blob - l4/tool/bin/qemu-x86-launch
2376e3b27f63a1cd8475d4b19265c19be30a74aa
[l4.git] / l4 / tool / bin / qemu-x86-launch
1 #! /usr/bin/perl -W
2 #
3 # (c) 2009 Technische Universität Dresden
4 # This file is part of TUD:OS and distributed under the terms of the
5 # GNU General Public License 2.
6 # Please see the COPYING-GPL-2 file for details.
7 #
8 # Adam Lackorzynski <adam@os.inf.tu-dresden.de>
9 #
10
11 use strict;
12
13 BEGIN { unshift @INC, $ENV{L4DIR}.'/tool/lib'
14            if $ENV{L4DIR} && -d $ENV{L4DIR}.'/tool/lib/L4';}
15
16 use L4::ModList;
17 use File::Temp qw/tempdir/;
18
19 my $qemu         = $ENV{QEMU}       || 'qemu';
20 my $kernelname   = $ENV{KERNEL}     || 'bootstrap';
21 my $module_path  = $ENV{SEARCHPATH} || ".";
22 my $modulesfile  = shift;
23 my $entryname    = shift;
24 my $unzip_tmp    = tempdir(CLEANUP => 1); 
25
26 sub get_file($$)
27 {
28   my $command = shift;
29   my $cmdline = shift;
30
31   my $fp = L4::ModList::search_file_or_die($command, $module_path);
32
33   $cmdline =~ s/^\S+\s*//;
34
35   open F, $fp || die "connot open '$fp': $!";
36   my $buf;
37   read F, $buf, 2;
38   close F;
39
40   if (unpack("n", $buf) == 0x1f8b) {
41     (my $tf = $fp) =~ s|.*/||;
42     $tf = $unzip_tmp.'/'.$tf;
43     print "'$fp' is a zipped file, uncompressing to '$tf'\n";
44     system("zcat $fp >$tf");
45     $fp = $tf;
46   }
47
48   $fp.' '.$cmdline;
49 }
50
51
52 die "No entry name given" unless defined $entryname;
53
54 my %entry = L4::ModList::get_module_entry($modulesfile, $entryname);
55
56 my @mods = @{$entry{mods}};
57 my $kernel = L4::ModList::search_file_or_die($entry{bootstrap}{command}, $module_path);
58 my $initrd = join(',', map { get_file($_->{command}, $_->{cmdline}) } @mods);
59
60 my $qemu_cmd =
61       "$qemu -kernel $kernel -append \"$entry{bootstrap}{cmdline}\" ".
62       "-initrd \"$initrd\" ".join(' ', @ARGV);
63
64 print "$qemu_cmd\n";
65 system("$qemu_cmd");