3 # Copyright (c) 2000, Gaƫl Roualland <gael.roualland@iname.com>
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
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.
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.
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)
40 use vars qw(%sysprint %syscat);
44 "usage: $0 syscalls.master [<syscalls.print>] [<syscalls.cat>]\n";
51 open (PRINT, "< $fprint") || die "can't open $fprint: $!";
57 my($sys, $func) = split(/\s+/);
60 $sysprint{$sys} = $func;
62 $sysprint{$sys} = "sys_$sys";
72 open (CAT, "< $fcat") || die "can't open $fcat: $!";
78 my($sys, $cat) = split(/\s+/);
79 $syscat{$sys} = $cat if (defined($sys) && defined($cat));
85 usage if (!defined($ARGV[0]) || defined($ARGV[3]));
88 readprint $ARGV[1] if defined $ARGV[1];
91 readcat $ARGV[2] if defined $ARGV[2];
93 open(MASTER, "< $ARGV[0]") || die "can't open $ARGV[0]: $!";
95 open(SYSCALL, "> syscall.h") || die "can't create syscall.h: $!";
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";
113 if (/^(\d+)\s+(?:MPSAFE\s+)?(\w+)\s+\w+\s+\{\s*([^}]+)\s*\}([^}]*)$/) {
114 my($compat, $proto, $ext, $name, $nargs, @args, $pfunc, $cat);
116 next if $2 eq 'OBSOL' || $2 eq 'UNIMPL';
118 $compat = $2 eq 'COMPAT' ? '?' : "";
123 if ($1 > $sysnum) { # syscall gap
124 while($sysnum < $1) {
125 print " { -1,\t0,\tprintargs,\t\"SYS_$sysnum\"\t}, /* $sysnum */\n";
128 } elsif ($1 < $sysnum) {
129 warn "error in master file: syscall $1 found, expecting $sysnum.";
132 if ($proto =~ /^[^\s]+\s+([^\s]+)\s*\(([^)]*)\);/) {
133 my @args = split(/,/, $2);
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";
141 $pfunc = "sys_$name";
142 print SYSCALL "#define $pfunc printargs\n";
144 if (defined($syscat{$name})) {
145 $cat = $syscat{$name};
150 print " { $nargs,\t$cat,\t$pfunc,\t\"$name\"\t}, /* $sysnum */\n";
153 warn "bad syscall specification for $sysnum: $proto";