Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / ipxe / src / util / parserom.pl
1 #!/usr/bin/env perl
2 #
3 # Parse PCI_ROM and ISA_ROM entries from a source file on stdin and
4 # output the relevant Makefile variable definitions to stdout
5 #
6 # Based upon portions of Ken Yap's genrules.pl
7
8 use strict;
9 use warnings;
10
11 die "Syntax: $0 driver_source.c" unless @ARGV == 1;
12 my $source = shift;
13 open DRV, "<$source" or die "Could not open $source: $!\n";
14
15 ( my $family, my $driver_name ) = ( $source =~ /^(.*?([^\/]+))\..$/ )
16     or die "Could not parse source file name \"$source\"\n";
17
18 my $printed_family;
19
20 sub rom {
21   ( my $type, my $image, my $desc, my $vendor, my $device, my $dup ) = @_;
22   my $ids = $vendor ? "$vendor,$device" : "-";
23   unless ( $printed_family ) {
24     print "\n";
25     print "# NIC\t\n";
26     print "# NIC\tfamily\t$family\n";
27     print "DRIVERS += $driver_name\n";
28     $printed_family = 1;
29   }
30   print "\n";
31   return if ( $vendor && ( ( $vendor eq "ffff" ) || ( $device eq "ffff" ) ) );
32   print "# NIC\t$image\t$ids\t$desc\n";
33   print "DRIVER_$image = $driver_name\n";
34   print "ROM_TYPE_$image = $type\n";
35   print "ROM_DESCRIPTION_$image = \"$desc\"\n";
36   print "PCI_VENDOR_$image = 0x$vendor\n" if $vendor;
37   print "PCI_DEVICE_$image = 0x$device\n" if $device;
38   print "ROMS += $image\n" unless $dup;
39   print "ROMS_$driver_name += $image\n" unless $dup;
40 }
41
42 while ( <DRV> ) {
43   next unless /(PCI|ISA)_ROM\s*\(/;
44
45   if ( /^\s*PCI_ROM\s*\(
46          \s*0x([0-9A-Fa-f]{4})\s*, # PCI vendor
47          \s*0x([0-9A-Fa-f]{4})\s*, # PCI device
48          \s*\"([^\"]*)\"\s*,       # Image
49          \s*\"([^\"]*)\"\s*,       # Description
50          \s*.*\s*                  # Driver data
51        \)/x ) {
52     ( my $vendor, my $device, my $image, my $desc ) = ( lc $1, lc $2, $3, $4 );
53     rom ( "pci", lc "${vendor}${device}", $desc, $vendor, $device );
54     rom ( "pci", $image, $desc, $vendor, $device, 1 );
55   } elsif ( /^\s*ISA_ROM\s*\(
56               \s*\"([^\"]*)\"\s*,  # Image
57               \s*\"([^\"]*)\"\s*   # Description
58             \)/x ) {
59     ( my $image, my $desc ) = ( $1, $2 );
60     rom ( "isa", $image, $desc );
61   } else {
62     warn "Malformed PCI_ROM or ISA_ROM macro on line $. of $source\n";
63   }
64 }
65
66 close DRV;