Home | History | Annotate | Line # | Download | only in kern
makesyscalls.sh revision 1.35.2.6
      1       1.1     glass #! /bin/sh -
      2  1.35.2.6    bouyer #	$NetBSD: makesyscalls.sh,v 1.35.2.6 2001/02/11 19:16:47 bouyer Exp $
      3       1.9       cgd #
      4  1.35.2.1    bouyer # Copyright (c) 1994, 1996, 2000 Christopher G. Demetriou
      5      1.12       cgd # All rights reserved.
      6      1.12       cgd #
      7      1.12       cgd # Redistribution and use in source and binary forms, with or without
      8      1.12       cgd # modification, are permitted provided that the following conditions
      9      1.12       cgd # are met:
     10      1.12       cgd # 1. Redistributions of source code must retain the above copyright
     11      1.12       cgd #    notice, this list of conditions and the following disclaimer.
     12      1.12       cgd # 2. Redistributions in binary form must reproduce the above copyright
     13      1.12       cgd #    notice, this list of conditions and the following disclaimer in the
     14      1.12       cgd #    documentation and/or other materials provided with the distribution.
     15      1.12       cgd # 3. All advertising materials mentioning features or use of this software
     16      1.12       cgd #    must display the following acknowledgement:
     17      1.12       cgd #      This product includes software developed for the NetBSD Project
     18      1.12       cgd #      by Christopher G. Demetriou.
     19      1.12       cgd # 4. The name of the author may not be used to endorse or promote products
     20      1.12       cgd #    derived from this software without specific prior written permission
     21      1.12       cgd #
     22      1.12       cgd # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23      1.12       cgd # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24      1.12       cgd # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25      1.12       cgd # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26      1.12       cgd # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27      1.12       cgd # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28      1.12       cgd # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29      1.12       cgd # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30      1.12       cgd # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31      1.12       cgd # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32      1.14       cgd 
     33      1.14       cgd #	@(#)makesyscalls.sh	8.1 (Berkeley) 6/10/93
     34       1.1     glass 
     35       1.1     glass set -e
     36       1.1     glass 
     37      1.11       cgd case $# in
     38      1.11       cgd     2)	;;
     39      1.11       cgd     *)	echo "Usage: $0 config-file input-file" 1>&2
     40      1.11       cgd 	exit 1
     41      1.11       cgd 	;;
     42      1.11       cgd esac
     43      1.11       cgd 
     44      1.11       cgd # source the config file.
     45      1.33  christos . ./$1
     46      1.11       cgd 
     47      1.11       cgd # the config file sets the following variables:
     48      1.11       cgd #	sysnames	the syscall names file
     49      1.11       cgd #	sysnumhdr	the syscall numbers file
     50      1.11       cgd #	syssw		the syscall switch file
     51      1.11       cgd #	sysarghdr	the syscall argument struct definitions
     52      1.11       cgd #	compatopts	those syscall types that are for 'compat' syscalls
     53      1.11       cgd #	switchname	the name for the 'struct sysent' we define
     54  1.35.2.4    bouyer #	namesname	the name for the 'const char *[]' we define
     55      1.11       cgd #	constprefix	the prefix for the system call constants
     56      1.30       eeh #	registertype	the type for register_t
     57  1.35.2.4    bouyer #	nsysent		the size of the sysent table
     58      1.11       cgd #
     59      1.11       cgd # NOTE THAT THIS makesyscalls.sh DOES NOT SUPPORT 'LIBCOMPAT'.
     60       1.1     glass 
     61       1.1     glass # tmp files:
     62       1.1     glass sysdcl="sysent.dcl"
     63      1.16   thorpej sysprotos="sys.protos"
     64      1.11       cgd syscompat_pref="sysent."
     65       1.1     glass sysent="sysent.switch"
     66      1.27   thorpej sysnamesbottom="sysnames.bottom"
     67       1.1     glass 
     68      1.27   thorpej trap "rm $sysdcl $sysprotos $sysent $sysnamesbottom" 0
     69      1.11       cgd 
     70      1.11       cgd # Awk program (must support nawk extensions)
     71      1.11       cgd # Use "awk" at Berkeley, "nawk" or "gawk" elsewhere.
     72      1.11       cgd awk=${AWK:-awk}
     73      1.11       cgd 
     74      1.11       cgd # Does this awk have a "toupper" function? (i.e. is it GNU awk)
     75      1.11       cgd isgawk=`$awk 'BEGIN { print toupper("true"); exit; }' 2>/dev/null`
     76      1.11       cgd 
     77      1.11       cgd # If this awk does not define "toupper" then define our own.
     78      1.11       cgd if [ "$isgawk" = TRUE ] ; then
     79      1.11       cgd 	# GNU awk provides it.
     80      1.11       cgd 	toupper=
     81      1.11       cgd else
     82      1.11       cgd 	# Provide our own toupper()
     83      1.11       cgd 	toupper='
     84      1.11       cgd function toupper(str) {
     85      1.11       cgd 	_toupper_cmd = "echo "str" |tr a-z A-Z"
     86      1.11       cgd 	_toupper_cmd | getline _toupper_str;
     87      1.11       cgd 	close(_toupper_cmd);
     88      1.11       cgd 	return _toupper_str;
     89      1.11       cgd }'
     90      1.11       cgd fi
     91      1.11       cgd 
     92      1.11       cgd # before handing it off to awk, make a few adjustments:
     93      1.11       cgd #	(1) insert spaces around {, }, (, ), *, and commas.
     94      1.11       cgd #	(2) get rid of any and all dollar signs (so that rcs id use safe)
     95      1.11       cgd #
     96      1.11       cgd # The awk script will deal with blank lines and lines that
     97      1.11       cgd # start with the comment character (';').
     98       1.1     glass 
     99      1.11       cgd sed -e '
    100      1.11       cgd s/\$//g
    101      1.11       cgd :join
    102      1.11       cgd 	/\\$/{a\
    103      1.11       cgd 
    104      1.11       cgd 	N
    105      1.11       cgd 	s/\\\n//
    106      1.11       cgd 	b join
    107      1.11       cgd 	}
    108      1.11       cgd 2,${
    109      1.11       cgd 	/^#/!s/\([{}()*,]\)/ \1 /g
    110      1.11       cgd }
    111      1.11       cgd ' < $2 | $awk "
    112      1.11       cgd $toupper
    113      1.11       cgd BEGIN {
    114      1.18       cgd 	# to allow nested #if/#else/#endif sets
    115      1.18       cgd 	savedepth = 0
    116  1.35.2.5    bouyer 	# to track already processed syscalls
    117  1.35.2.5    bouyer 	syscallseen[0] = 0
    118      1.18       cgd 
    119      1.11       cgd 	sysnames = \"$sysnames\"
    120      1.16   thorpej 	sysprotos = \"$sysprotos\"
    121      1.11       cgd 	sysnumhdr = \"$sysnumhdr\"
    122      1.11       cgd 	sysarghdr = \"$sysarghdr\"
    123      1.11       cgd 	switchname = \"$switchname\"
    124      1.11       cgd 	namesname = \"$namesname\"
    125      1.11       cgd 	constprefix = \"$constprefix\"
    126      1.30       eeh 	registertype = \"$registertype\"
    127      1.30       eeh 	if (!registertype) {
    128      1.30       eeh 	    registertype = \"register_t\"
    129      1.30       eeh 	}
    130  1.35.2.4    bouyer 	nsysent = \"$nsysent\"
    131      1.11       cgd 
    132      1.11       cgd 	sysdcl = \"$sysdcl\"
    133      1.11       cgd 	syscompat_pref = \"$syscompat_pref\"
    134      1.11       cgd 	sysent = \"$sysent\"
    135      1.27   thorpej 	sysnamesbottom = \"$sysnamesbottom\"
    136      1.11       cgd 	infile = \"$2\"
    137      1.11       cgd 
    138      1.11       cgd 	compatopts = \"$compatopts\"
    139      1.11       cgd 	"'
    140      1.11       cgd 
    141  1.35.2.1    bouyer 	printf "/* \$NetBSD\$ */\n\n" > sysdcl
    142      1.11       cgd 	printf "/*\n * System call switch table.\n *\n" > sysdcl
    143      1.11       cgd 	printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysdcl
    144      1.11       cgd 
    145      1.11       cgd 	ncompat = split(compatopts,compat)
    146      1.11       cgd 	for (i = 1; i <= ncompat; i++) {
    147      1.11       cgd 		compat_upper[i] = toupper(compat[i])
    148      1.11       cgd 
    149      1.17   mycroft 		printf "\n#ifdef %s\n", compat_upper[i] > sysent
    150      1.17   mycroft 		printf "#define %s(func) __CONCAT(%s_,func)\n", compat[i], \
    151      1.17   mycroft 		    compat[i] > sysent
    152      1.17   mycroft 		printf "#else\n" > sysent
    153      1.17   mycroft 		printf "#define %s(func) sys_nosys\n", compat[i] > sysent
    154      1.17   mycroft 		printf "#endif\n" > sysent
    155      1.11       cgd 	}
    156      1.11       cgd 
    157      1.17   mycroft 	printf "\n#define\ts(type)\tsizeof(type)\n\n" > sysent
    158      1.17   mycroft 	printf "struct sysent %s[] = {\n",switchname > sysent
    159      1.17   mycroft 
    160  1.35.2.1    bouyer 	printf "/* \$NetBSD\$ */\n\n" > sysnames
    161      1.11       cgd 	printf "/*\n * System call names.\n *\n" > sysnames
    162      1.11       cgd 	printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysnames
    163      1.11       cgd 
    164      1.16   thorpej 	printf "\n/*\n * System call prototypes.\n */\n\n" > sysprotos
    165      1.16   thorpej 
    166  1.35.2.1    bouyer 	printf "/* \$NetBSD\$ */\n\n" > sysnumhdr
    167      1.11       cgd 	printf "/*\n * System call numbers.\n *\n" > sysnumhdr
    168      1.11       cgd 	printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysnumhdr
    169      1.11       cgd 
    170  1.35.2.1    bouyer 	printf "/* \$NetBSD\$ */\n\n" > sysarghdr
    171      1.13   mycroft 	printf "/*\n * System call argument lists.\n *\n" > sysarghdr
    172      1.11       cgd 	printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysarghdr
    173      1.11       cgd }
    174      1.11       cgd NR == 1 {
    175      1.11       cgd 	printf " * created from%s\n */\n\n", $0 > sysdcl
    176      1.11       cgd 
    177      1.11       cgd 	printf " * created from%s\n */\n\n", $0 > sysnames
    178      1.28   thorpej 
    179      1.28   thorpej 	# System call names are included by userland (kdump(1)), so
    180      1.28   thorpej 	# hide the include files from it.
    181      1.28   thorpej 	printf "#if defined(_KERNEL) && !defined(_LKM)\n" > sysnames
    182      1.28   thorpej 
    183      1.28   thorpej 	printf "#endif /* _KERNEL && ! _LKM */\n\n" > sysnamesbottom
    184  1.35.2.4    bouyer 	printf "const char *const %s[] = {\n",namesname > sysnamesbottom
    185      1.11       cgd 
    186      1.11       cgd 	printf " * created from%s\n */\n\n", $0 > sysnumhdr
    187      1.11       cgd 
    188      1.11       cgd 	printf " * created from%s\n */\n\n", $0 > sysarghdr
    189      1.31       erh 	printf "#ifndef _" constprefix "_SYSCALLARGS_H_\n" > sysarghdr
    190      1.31       erh 	printf "#define _" constprefix "_SYSCALLARGS_H_\n\n" > sysarghdr
    191      1.30       eeh 	printf "#ifdef\tsyscallarg\n" > sysarghdr
    192      1.30       eeh 	printf "#undef\tsyscallarg\n" > sysarghdr
    193      1.30       eeh 	printf "#endif\n\n" > sysarghdr
    194      1.35   thorpej 	printf "#define\tsyscallarg(x)\t\t\t\t\t\t\t\\\n" > sysarghdr
    195      1.35   thorpej 	printf "\tunion {\t\t\t\t\t\t\t\t\\\n" > sysarghdr
    196      1.35   thorpej 	printf "\t\t%s pad;\t\t\t\t\t\t\\\n", registertype > sysarghdr
    197      1.35   thorpej 	printf "\t\tstruct { x datum; } le;\t\t\t\t\t\\\n" > sysarghdr
    198      1.35   thorpej 	printf "\t\tstruct {\t\t\t\t\t\t\\\n" > sysarghdr
    199      1.35   thorpej 	printf "\t\t\tint8_t pad[ (sizeof (%s) < sizeof (x))\t\\\n", \
    200      1.30       eeh 		registertype > sysarghdr
    201      1.35   thorpej 	printf "\t\t\t\t? 0\t\t\t\t\t\\\n" > sysarghdr
    202      1.35   thorpej 	printf "\t\t\t\t: sizeof (%s) - sizeof (x)];\t\\\n", \
    203      1.30       eeh 		registertype > sysarghdr
    204      1.35   thorpej 	printf "\t\t\tx datum;\t\t\t\t\t\\\n" > sysarghdr
    205      1.35   thorpej 	printf "\t\t} be;\t\t\t\t\t\t\t\\\n" > sysarghdr
    206      1.35   thorpej 	printf "\t}\n" > sysarghdr
    207      1.11       cgd 	next
    208      1.11       cgd }
    209      1.11       cgd NF == 0 || $1 ~ /^;/ {
    210      1.11       cgd 	next
    211      1.11       cgd }
    212  1.35.2.4    bouyer $0 ~ /^%%$/ {
    213  1.35.2.4    bouyer 	intable = 1
    214  1.35.2.4    bouyer 	next
    215  1.35.2.4    bouyer }
    216      1.11       cgd $1 ~ /^#[ 	]*include/ {
    217      1.11       cgd 	print > sysdcl
    218      1.27   thorpej 	print > sysnames
    219      1.11       cgd 	next
    220      1.11       cgd }
    221  1.35.2.4    bouyer $1 ~ /^#/ && !intable {
    222  1.35.2.4    bouyer 	print > sysdcl
    223  1.35.2.4    bouyer 	print > sysnames
    224      1.11       cgd 	next
    225      1.11       cgd }
    226  1.35.2.4    bouyer $1 ~ /^#/ && intable {
    227  1.35.2.4    bouyer 	if ($1 ~ /^#[ 	]*if/) {
    228  1.35.2.4    bouyer 		savedepth++
    229  1.35.2.4    bouyer 		savesyscall[savedepth] = syscall
    230  1.35.2.4    bouyer 	}
    231  1.35.2.4    bouyer 	if ($1 ~ /^#[ 	]*else/) {
    232  1.35.2.4    bouyer 		if (savedepth <= 0) {
    233  1.35.2.4    bouyer 			printf("%s: line %d: unbalanced #else\n", \
    234  1.35.2.4    bouyer 			    infile, NR)
    235  1.35.2.4    bouyer 			exit 1
    236  1.35.2.4    bouyer 		}
    237  1.35.2.4    bouyer 		syscall = savesyscall[savedepth]
    238      1.18       cgd 	}
    239      1.18       cgd 	if ($1 ~ /^#[       ]*endif/) {
    240      1.18       cgd 		if (savedepth <= 0) {
    241  1.35.2.4    bouyer 			printf("%s: line %d: unbalanced #endif\n", \
    242  1.35.2.4    bouyer 			    infile, NR)
    243      1.18       cgd 			exit 1
    244      1.18       cgd 		}
    245  1.35.2.4    bouyer 		savedepth--
    246      1.18       cgd 	}
    247      1.11       cgd 	print > sysent
    248      1.16   thorpej 	print > sysprotos
    249      1.27   thorpej 	print > sysnamesbottom
    250      1.11       cgd 	next
    251      1.11       cgd }
    252      1.11       cgd syscall != $1 {
    253      1.11       cgd 	printf "%s: line %d: syscall number out of sync at %d\n", \
    254      1.11       cgd 	   infile, NR, syscall
    255      1.11       cgd 	printf "line is:\n"
    256      1.11       cgd 	print
    257      1.11       cgd 	exit 1
    258      1.11       cgd }
    259      1.11       cgd function parserr(was, wanted) {
    260      1.11       cgd 	printf "%s: line %d: unexpected %s (expected %s)\n", \
    261      1.11       cgd 	    infile, NR, was, wanted
    262      1.32  christos 	printf "line is:\n"
    263      1.32  christos 	print
    264      1.11       cgd 	exit 1
    265      1.11       cgd }
    266      1.11       cgd function parseline() {
    267      1.11       cgd 	f=3			# toss number and type
    268  1.35.2.6    bouyer 	sycall_flags="0"
    269      1.11       cgd 	if ($NF != "}") {
    270      1.11       cgd 		funcalias=$NF
    271      1.11       cgd 		end=NF-1
    272      1.11       cgd 	} else {
    273      1.11       cgd 		funcalias=""
    274      1.11       cgd 		end=NF
    275      1.11       cgd 	}
    276  1.35.2.6    bouyer 	if ($f == "MPSAFE") {		# allow for MP-safe syscalls
    277  1.35.2.6    bouyer 		sycall_flags = sprintf("SYCALL_MPSAFE | %s", sycall_flags)
    278  1.35.2.6    bouyer 		f++
    279  1.35.2.6    bouyer 	}
    280  1.35.2.4    bouyer 	if ($f ~ /^[a-z0-9_]*$/) {	# allow syscall alias
    281  1.35.2.4    bouyer 		funcalias=$f
    282  1.35.2.4    bouyer 		f++
    283  1.35.2.4    bouyer 	}
    284      1.11       cgd 	if ($f != "{")
    285      1.11       cgd 		parserr($f, "{")
    286      1.11       cgd 	f++
    287      1.11       cgd 	if ($end != "}")
    288      1.11       cgd 		parserr($end, "}")
    289      1.11       cgd 	end--
    290      1.11       cgd 	if ($end != ";")
    291      1.11       cgd 		parserr($end, ";")
    292      1.11       cgd 	end--
    293      1.11       cgd 	if ($end != ")")
    294      1.11       cgd 		parserr($end, ")")
    295      1.11       cgd 	end--
    296      1.11       cgd 
    297      1.19       cgd 	returntype = oldf = "";
    298      1.19       cgd 	do {
    299      1.19       cgd 		if (returntype != "" && oldf != "*")
    300      1.19       cgd 			returntype = returntype" ";
    301      1.19       cgd 		returntype = returntype$f;
    302      1.19       cgd 		oldf = $f;
    303      1.19       cgd 		f++
    304      1.19       cgd 	} while (f < (end - 1) && $(f+1) != "(");
    305      1.19       cgd 	if (f == (end - 1)) {
    306      1.19       cgd 		parserr($f, "function argument definition (maybe \"(\"?)");
    307      1.19       cgd 	}
    308      1.11       cgd 
    309      1.11       cgd 	funcname=$f
    310      1.17   mycroft 	if (funcalias == "") {
    311      1.11       cgd 		funcalias=funcname
    312      1.17   mycroft 		sub(/^([^_]+_)*sys_/, "", funcalias)
    313      1.17   mycroft 	}
    314      1.11       cgd 	f++
    315      1.11       cgd 
    316      1.11       cgd 	if ($f != "(")
    317      1.11       cgd 		parserr($f, ")")
    318      1.11       cgd 	f++
    319      1.11       cgd 
    320      1.19       cgd 	argc=0;
    321      1.11       cgd 	if (f == end) {
    322      1.11       cgd 		if ($f != "void")
    323      1.11       cgd 			parserr($f, "argument definition")
    324      1.19       cgd 		isvarargs = 0;
    325      1.19       cgd 		varargc = 0;
    326      1.11       cgd 		return
    327      1.11       cgd 	}
    328      1.11       cgd 
    329      1.19       cgd 	# some system calls (open() and fcntl()) can accept a variable
    330      1.19       cgd 	# number of arguments.  If syscalls accept a variable number of
    331      1.19       cgd 	# arguments, they must still have arguments specified for
    332      1.19       cgd 	# the remaining argument "positions," because of the way the
    333      1.19       cgd 	# kernel system call argument handling works.
    334      1.19       cgd 	#
    335      1.19       cgd 	# Indirect system calls, e.g. syscall(), are exceptions to this
    336      1.19       cgd 	# rule, since they are handled entirely by machine-dependent code
    337      1.19       cgd 	# and do not need argument structures built.
    338      1.19       cgd 
    339      1.19       cgd 	isvarargs = 0;
    340      1.11       cgd 	while (f <= end) {
    341      1.19       cgd 		if ($f == "...") {
    342      1.19       cgd 			f++;
    343      1.19       cgd 			isvarargs = 1;
    344      1.19       cgd 			varargc = argc;
    345      1.19       cgd 			continue;
    346      1.19       cgd 		}
    347      1.11       cgd 		argc++
    348      1.11       cgd 		argtype[argc]=""
    349      1.14       cgd 		oldf=""
    350      1.11       cgd 		while (f < end && $(f+1) != ",") {
    351      1.14       cgd 			if (argtype[argc] != "" && oldf != "*")
    352      1.11       cgd 				argtype[argc] = argtype[argc]" ";
    353      1.11       cgd 			argtype[argc] = argtype[argc]$f;
    354      1.14       cgd 			oldf = $f;
    355      1.11       cgd 			f++
    356      1.11       cgd 		}
    357      1.11       cgd 		if (argtype[argc] == "")
    358      1.11       cgd 			parserr($f, "argument definition")
    359      1.11       cgd 		argname[argc]=$f;
    360      1.11       cgd 		f += 2;			# skip name, and any comma
    361      1.11       cgd 	}
    362      1.19       cgd 	# must see another argument after varargs notice.
    363      1.19       cgd 	if (isvarargs) {
    364      1.19       cgd 		if (argc == varargc && $2 != "INDIR")
    365      1.19       cgd 			parserr($f, "argument definition")
    366      1.19       cgd 	} else
    367      1.19       cgd 		varargc = argc;
    368      1.11       cgd }
    369      1.17   mycroft function putent(nodefs, compatwrap) {
    370      1.21       cgd 	# output syscall declaration for switch table.  INDIR functions
    371      1.21       cgd 	# get none, since they always have sys_nosys() for their table
    372      1.21       cgd 	# entries.
    373      1.21       cgd 	if (nodefs != "INDIR") {
    374  1.35.2.1    bouyer 		prototype = "(struct proc *, void *, register_t *)"
    375      1.21       cgd 		if (compatwrap == "")
    376  1.35.2.1    bouyer 			printf("int\t%s%s;\n", funcname,
    377      1.21       cgd 			    prototype) > sysprotos
    378      1.21       cgd 		else
    379  1.35.2.1    bouyer 			printf("int\t%s_%s%s;\n", compatwrap, funcname,
    380      1.21       cgd 			    prototype) > sysprotos
    381      1.21       cgd 	}
    382      1.11       cgd 
    383      1.11       cgd 	# output syscall switch entry
    384      1.19       cgd 	if (nodefs == "INDIR") {
    385  1.35.2.6    bouyer 		printf("\t{ 0, 0, %s,\n\t    sys_nosys },\t\t\t/* %d = %s (indir) */\n", \
    386  1.35.2.6    bouyer 		    sycall_flags, syscall, funcalias) > sysent
    387      1.19       cgd 	} else {
    388      1.19       cgd #		printf("\t{ { %d", argc) > sysent
    389      1.19       cgd #		for (i = 1; i <= argc; i++) {
    390      1.19       cgd #			if (i == 5) 		# wrap the line
    391      1.19       cgd #				printf(",\n\t    ") > sysent
    392      1.19       cgd #			else
    393      1.19       cgd #				printf(", ") > sysent
    394      1.19       cgd #			printf("s(%s)", argtypenospc[i]) > sysent
    395      1.19       cgd #		}
    396      1.19       cgd 		printf("\t{ %d, ", argc) > sysent
    397      1.19       cgd 		if (argc == 0)
    398      1.19       cgd 			printf("0") > sysent
    399      1.19       cgd 		else if (compatwrap == "")
    400      1.19       cgd 			printf("s(struct %s_args)", funcname) > sysent
    401      1.19       cgd 		else
    402      1.19       cgd 			printf("s(struct %s_%s_args)", compatwrap,
    403      1.19       cgd 			    funcname) > sysent
    404      1.19       cgd 		if (compatwrap == "")
    405      1.19       cgd 			wfn = sprintf("%s", funcname);
    406      1.19       cgd 		else
    407      1.19       cgd 			wfn = sprintf("%s(%s)", compatwrap, funcname);
    408  1.35.2.6    bouyer 		printf(", %s,\n\t    %s },", sycall_flags, wfn) > sysent
    409      1.19       cgd 		for (i = 0; i < (33 - length(wfn)) / 8; i++)
    410      1.19       cgd 			printf("\t") > sysent
    411      1.19       cgd 		if (compatwrap == "")
    412      1.19       cgd 			printf("/* %d = %s */\n", syscall, funcalias) > sysent
    413      1.19       cgd 		else
    414      1.19       cgd 			printf("/* %d = %s %s */\n", syscall, compatwrap,
    415      1.19       cgd 			    funcalias) > sysent
    416      1.19       cgd 	}
    417      1.11       cgd 
    418      1.11       cgd 	# output syscall name for names table
    419      1.11       cgd 	if (compatwrap == "")
    420      1.11       cgd 		printf("\t\"%s\",\t\t\t/* %d = %s */\n", funcalias, syscall,
    421      1.27   thorpej 		    funcalias) > sysnamesbottom
    422      1.11       cgd 	else
    423      1.11       cgd 		printf("\t\"%s_%s\",\t/* %d = %s %s */\n", compatwrap,
    424      1.27   thorpej 		    funcalias, syscall, compatwrap, funcalias) > sysnamesbottom
    425      1.11       cgd 
    426      1.11       cgd 	# output syscall number of header, if appropriate
    427  1.35.2.5    bouyer 	if (syscallseen[syscall]) {
    428  1.35.2.5    bouyer 		# nop
    429  1.35.2.5    bouyer 	} else if (nodefs == "" || nodefs == "NOARGS" || nodefs == "INDIR") {
    430      1.19       cgd 		# output a prototype, to be used to generate lint stubs in
    431      1.19       cgd 		# libc.
    432      1.19       cgd 		printf("/* syscall: \"%s\" ret: \"%s\" args:", funcalias,
    433      1.19       cgd 		    returntype) > sysnumhdr
    434      1.19       cgd 		for (i = 1; i <= varargc; i++)
    435      1.19       cgd 			printf(" \"%s\"", argtype[i]) > sysnumhdr
    436      1.19       cgd 		if (isvarargs)
    437      1.19       cgd 			printf(" \"...\"") > sysnumhdr
    438      1.19       cgd 		printf(" */\n") > sysnumhdr
    439      1.19       cgd 
    440      1.19       cgd 		printf("#define\t%s%s\t%d\n\n", constprefix, funcalias,
    441      1.11       cgd 		    syscall) > sysnumhdr
    442      1.29   thorpej 	} else if (nodefs == "COMPAT") {
    443      1.29   thorpej 		# Just define the syscall number with a comment.  These
    444      1.29   thorpej 		# may be used by compatibility stubs in libc.
    445      1.29   thorpej 		printf("#define\t%s%s_%s\t%d\n\n",
    446      1.29   thorpej 		    constprefix, compatwrap, funcalias, syscall) > sysnumhdr
    447      1.19       cgd 	} else if (nodefs != "NODEF")
    448      1.19       cgd 		printf("\t\t\t\t/* %d is %s %s */\n\n", syscall,
    449      1.11       cgd 		    compatwrap, funcalias) > sysnumhdr
    450  1.35.2.5    bouyer 	syscallseen[syscall] = 1
    451      1.11       cgd 
    452      1.11       cgd 	# output syscall argument structure, if it has arguments
    453      1.21       cgd 	if (argc != 0 && nodefs != "NOARGS" && nodefs != "INDIR") {
    454      1.11       cgd 		if (compatwrap == "")
    455      1.11       cgd 			printf("\nstruct %s_args {\n", funcname) > sysarghdr
    456      1.11       cgd 		else
    457      1.11       cgd 			printf("\nstruct %s_%s_args {\n", compatwrap,
    458      1.11       cgd 			    funcname) > sysarghdr
    459      1.11       cgd 		for (i = 1; i <= argc; i++)
    460      1.11       cgd 			printf("\tsyscallarg(%s) %s;\n", argtype[i],
    461      1.11       cgd 			    argname[i]) > sysarghdr
    462      1.11       cgd 		printf("};\n") > sysarghdr
    463      1.11       cgd 	}
    464      1.11       cgd }
    465      1.11       cgd $2 == "STD" {
    466      1.11       cgd 	parseline()
    467      1.17   mycroft 	putent("", "");
    468      1.11       cgd 	syscall++
    469      1.11       cgd 	next
    470      1.11       cgd }
    471      1.19       cgd $2 == "NODEF" || $2 == "NOARGS" || $2 == "INDIR" {
    472      1.11       cgd 	parseline()
    473      1.17   mycroft 	putent($2, "")
    474      1.11       cgd 	syscall++
    475      1.11       cgd 	next
    476      1.11       cgd }
    477      1.34  christos $2 == "OBSOL" || $2 == "UNIMPL" || $2 == "EXCL" {
    478      1.11       cgd 	if ($2 == "OBSOL")
    479      1.11       cgd 		comment="obsolete"
    480      1.34  christos 	else if ($2 == "EXCL")
    481      1.34  christos 		comment="excluded"
    482      1.11       cgd 	else
    483      1.11       cgd 		comment="unimplemented"
    484      1.11       cgd 	for (i = 3; i <= NF; i++)
    485      1.11       cgd 		comment=comment " " $i
    486      1.11       cgd 
    487  1.35.2.6    bouyer 	printf("\t{ 0, 0, 0,\n\t    sys_nosys },\t\t\t/* %d = %s */\n", \
    488      1.11       cgd 	    syscall, comment) > sysent
    489      1.11       cgd 	printf("\t\"#%d (%s)\",\t\t/* %d = %s */\n", \
    490      1.27   thorpej 	    syscall, comment, syscall, comment) > sysnamesbottom
    491      1.11       cgd 	if ($2 != "UNIMPL")
    492      1.11       cgd 		printf("\t\t\t\t/* %d is %s */\n", syscall, comment) > sysnumhdr
    493      1.11       cgd 	syscall++
    494      1.11       cgd 	next
    495      1.11       cgd }
    496      1.11       cgd {
    497      1.11       cgd 	for (i = 1; i <= ncompat; i++) {
    498      1.11       cgd 		if ($2 == compat_upper[i]) {
    499      1.11       cgd 			parseline();
    500      1.29   thorpej 			putent("COMPAT", compat[i])
    501      1.11       cgd 			syscall++
    502      1.11       cgd 			next
    503      1.11       cgd 		}
    504      1.11       cgd 	}
    505  1.35.2.4    bouyer 	printf("%s: line %d: unrecognized keyword %s\n", infile, NR, $2)
    506       1.1     glass 	exit 1
    507      1.11       cgd }
    508      1.11       cgd END {
    509  1.35.2.4    bouyer 	maxsyscall = syscall
    510  1.35.2.4    bouyer 	if (nsysent) {
    511  1.35.2.4    bouyer 		if (syscall > nsysent) {
    512  1.35.2.4    bouyer 			printf("%s: line %d: too many syscalls\n", infile, NR)
    513  1.35.2.4    bouyer 			exit 1
    514  1.35.2.4    bouyer 		}
    515  1.35.2.4    bouyer 		while (syscall < nsysent) {
    516  1.35.2.6    bouyer 			printf("\t{ 0, 0, 0,\n\t    sys_nosys },\t\t\t/* %d = filler */\n", \
    517  1.35.2.4    bouyer 			    syscall) > sysent
    518  1.35.2.4    bouyer 			syscall++
    519  1.35.2.4    bouyer 		}
    520  1.35.2.4    bouyer 	}
    521      1.11       cgd 	printf("};\n\n") > sysent
    522      1.27   thorpej 	printf("};\n") > sysnamesbottom
    523  1.35.2.4    bouyer 	printf("#define\t%sMAXSYSCALL\t%d\n", constprefix, maxsyscall) > sysnumhdr
    524  1.35.2.4    bouyer 	if (nsysent)
    525  1.35.2.4    bouyer 		printf("#define\t%sNSYSENT\t%d\n", constprefix, nsysent) > sysnumhdr
    526      1.11       cgd } '
    527       1.1     glass 
    528      1.17   mycroft cat $sysprotos >> $sysarghdr
    529      1.31       erh echo "#endif /* _${constprefix}_SYSCALLARGS_H_ */" >> $sysarghdr
    530      1.16   thorpej cat $sysdcl $sysent > $syssw
    531      1.27   thorpej cat $sysnamesbottom >> $sysnames
    532       1.1     glass 
    533      1.15  christos #chmod 444 $sysnames $sysnumhdr $syssw
    534