Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 1 | #!/usr/bin/perl -w |
| 2 | # |
| 3 | # Copyright (c) 2000, Gaƫl Roualland <gael.roualland@iname.com> |
| 4 | # All rights reserved. |
| 5 | # |
| 6 | # Redistribution and use in source and binary forms, with or without |
| 7 | # modification, are permitted provided that the following conditions |
| 8 | # are met: |
| 9 | # 1. Redistributions of source code must retain the above copyright |
| 10 | # notice, this list of conditions and the following disclaimer. |
| 11 | # 2. Redistributions in binary form must reproduce the above copyright |
| 12 | # notice, this list of conditions and the following disclaimer in the |
| 13 | # documentation and/or other materials provided with the distribution. |
| 14 | # 3. The name of the author may not be used to endorse or promote products |
| 15 | # derived from this software without specific prior written permission. |
| 16 | # |
| 17 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 18 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 19 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 20 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 21 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 22 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 26 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | # |
| 28 | # $Id$ |
| 29 | #/ |
| 30 | |
| 31 | # Buils syscall.h and syscallent.h from: |
| 32 | # - syscalls.cat containing lines of format: syscall catmask |
| 33 | # - syscalls.print containing lines of format: syscall [printfunction] |
| 34 | # if no printfunction is provided, sys_<call> is used. |
| 35 | # - syscalls.master in the FreeBSD kernel source tree (/usr/src/sys/kern) |
| 36 | |
| 37 | use strict; |
| 38 | use POSIX; |
| 39 | |
| 40 | use vars qw(%sysprint %syscat); |
| 41 | |
| 42 | sub usage() { |
| 43 | print STDERR |
| 44 | "usage: $0 syscalls.master [<syscalls.print>] [<syscalls.cat>]\n"; |
| 45 | exit 1; |
| 46 | } |
| 47 | |
| 48 | sub readprint ($) { |
| 49 | my($fprint) = @_; |
| 50 | |
| 51 | open (PRINT, "< $fprint") || die "can't open $fprint: $!"; |
| 52 | while(<PRINT>) { |
| 53 | chomp; |
| 54 | s/^\s*//; |
| 55 | s/\s+$//; |
| 56 | s/#.*$//; |
| 57 | my($sys, $func) = split(/\s+/); |
| 58 | if (defined($sys)) { |
| 59 | if (defined($func)) { |
| 60 | $sysprint{$sys} = $func; |
| 61 | } else { |
| 62 | $sysprint{$sys} = "sys_$sys"; |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | close(PRINT); |
| 67 | } |
| 68 | |
| 69 | sub readcat ($) { |
| 70 | my($fcat) = @_; |
| 71 | |
| 72 | open (CAT, "< $fcat") || die "can't open $fcat: $!"; |
| 73 | while(<CAT>) { |
| 74 | chomp; |
| 75 | s/^\s*//; |
| 76 | s/\s+$//; |
| 77 | s/#.*$//; |
| 78 | my($sys, $cat) = split(/\s+/); |
| 79 | $syscat{$sys} = $cat if (defined($sys) && defined($cat)); |
| 80 | } |
| 81 | close(CAT); |
| 82 | } |
| 83 | |
| 84 | |
| 85 | usage if (!defined($ARGV[0]) || defined($ARGV[3])); |
| 86 | |
| 87 | %sysprint = (); |
| 88 | readprint $ARGV[1] if defined $ARGV[1]; |
| 89 | |
| 90 | %syscat = (); |
| 91 | readcat $ARGV[2] if defined $ARGV[2]; |
| 92 | |
| 93 | open(MASTER, "< $ARGV[0]") || die "can't open $ARGV[0]: $!"; |
| 94 | |
| 95 | open(SYSCALL, "> syscall.h") || die "can't create syscall.h: $!"; |
| 96 | |
| 97 | print SYSCALL "/*\n * Automatically generated by $0 on " . ctime(time()) . " */\n\n"; |
| 98 | print "/*\n * Automatically generated by $0 on " . ctime(time()) . " */\n\n"; |
| 99 | |
| 100 | my $sysnum = 0; |
| 101 | |
| 102 | while (<MASTER>) { |
| 103 | chomp; |
| 104 | # join broken lines |
| 105 | while (/\\$/) { |
| 106 | my $line; |
| 107 | s/\\$//; |
| 108 | $line = <MASTER>; |
| 109 | chomp($line); |
| 110 | $_ = "$_$line"; |
| 111 | } |
| 112 | |
John Hughes | cf1de75 | 2001-03-08 17:27:20 +0000 | [diff] [blame] | 113 | if (/^(\d+)\s+(?:MPSAFE\s+)?(\w+)\s+\w+\s+\{\s*([^}]+)\s*\}([^}]*)$/) { |
| 114 | my($compat, $proto, $ext, $name, $nargs, @args, $pfunc, $cat); |
| 115 | |
| 116 | next if $2 eq 'OBSOL' || $2 eq 'UNIMPL'; |
| 117 | |
| 118 | $compat = $2 eq 'COMPAT' ? '?' : ""; |
| 119 | |
| 120 | $proto = $3; |
| 121 | $ext = $4; |
Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 122 | |
| 123 | if ($1 > $sysnum) { # syscall gap |
| 124 | while($sysnum < $1) { |
| 125 | print " { -1,\t0,\tprintargs,\t\"SYS_$sysnum\"\t}, /* $sysnum */\n"; |
| 126 | $sysnum++; |
| 127 | } |
| 128 | } elsif ($1 < $sysnum) { |
| 129 | warn "error in master file: syscall $1 found, expecting $sysnum."; |
| 130 | } |
| 131 | |
| 132 | if ($proto =~ /^[^\s]+\s+([^\s]+)\s*\(([^)]*)\);/) { |
| 133 | my @args = split(/,/, $2); |
| 134 | $nargs = @args; |
| 135 | $name = $1; |
| 136 | $name = $1 if ($ext =~ /^\s*([^\s]+)\s+[^\s]+\s+[^\s]+$/); |
| 137 | if (defined($sysprint{$name})) { |
| 138 | $pfunc = $sysprint{$name}; |
| 139 | print SYSCALL "int $pfunc();\n"; |
| 140 | } else { |
| 141 | $pfunc = "sys_$name"; |
| 142 | print SYSCALL "#define $pfunc printargs\n"; |
| 143 | } |
| 144 | if (defined($syscat{$name})) { |
| 145 | $cat = $syscat{$name}; |
| 146 | } else { |
| 147 | $cat = "0"; |
| 148 | } |
John Hughes | cf1de75 | 2001-03-08 17:27:20 +0000 | [diff] [blame] | 149 | $name .= $compat; |
Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 150 | print " { $nargs,\t$cat,\t$pfunc,\t\"$name\"\t}, /* $sysnum */\n"; |
| 151 | $sysnum++; |
| 152 | } else { |
| 153 | warn "bad syscall specification for $sysnum: $proto"; |
| 154 | } |
| 155 | } |
| 156 | } |