blob: 0dc389ae0202c0cf0c3bb1bf64e201f3c1b39f7f [file] [log] [blame]
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +00001#!/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
37use strict;
38use POSIX;
39
40use vars qw(%sysprint %syscat);
41
42sub usage() {
43 print STDERR
44 "usage: $0 syscalls.master [<syscalls.print>] [<syscalls.cat>]\n";
45 exit 1;
46}
47
48sub 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
69sub 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
85usage if (!defined($ARGV[0]) || defined($ARGV[3]));
86
87%sysprint = ();
88readprint $ARGV[1] if defined $ARGV[1];
89
90%syscat = ();
91readcat $ARGV[2] if defined $ARGV[2];
92
93open(MASTER, "< $ARGV[0]") || die "can't open $ARGV[0]: $!";
94
95open(SYSCALL, "> syscall.h") || die "can't create syscall.h: $!";
96
97print SYSCALL "/*\n * Automatically generated by $0 on " . ctime(time()) . " */\n\n";
98print "/*\n * Automatically generated by $0 on " . ctime(time()) . " */\n\n";
99
100my $sysnum = 0;
101
102while (<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 Hughes3deafe22001-03-06 16:22:18 +0000113 if (/^(\d+)\s+(?:MPSAFE\s+)?\w+\s+\w+\s+\{\s*([^}]+)\s*\}([^}]*)$/) {
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000114 my($proto, $ext, $name, $nargs, @args, $pfunc, $cat);
115
116 $proto = $2;
117 $ext = $3;
118
119 if ($1 > $sysnum) { # syscall gap
120 while($sysnum < $1) {
121 print " { -1,\t0,\tprintargs,\t\"SYS_$sysnum\"\t}, /* $sysnum */\n";
122 $sysnum++;
123 }
124 } elsif ($1 < $sysnum) {
125 warn "error in master file: syscall $1 found, expecting $sysnum.";
126 }
127
128 if ($proto =~ /^[^\s]+\s+([^\s]+)\s*\(([^)]*)\);/) {
129 my @args = split(/,/, $2);
130 $nargs = @args;
131 $name = $1;
132 $name = $1 if ($ext =~ /^\s*([^\s]+)\s+[^\s]+\s+[^\s]+$/);
133 if (defined($sysprint{$name})) {
134 $pfunc = $sysprint{$name};
135 print SYSCALL "int $pfunc();\n";
136 } else {
137 $pfunc = "sys_$name";
138 print SYSCALL "#define $pfunc printargs\n";
139 }
140 if (defined($syscat{$name})) {
141 $cat = $syscat{$name};
142 } else {
143 $cat = "0";
144 }
145 print " { $nargs,\t$cat,\t$pfunc,\t\"$name\"\t}, /* $sysnum */\n";
146 $sysnum++;
147 } else {
148 warn "bad syscall specification for $sysnum: $proto";
149 }
150 }
151}