Home | History | Annotate | Line # | Download | only in kern
makesyscalls.sh revision 1.53.2.5
      1       1.1     glass #! /bin/sh -
      2  1.53.2.5  christos #	$NetBSD: makesyscalls.sh,v 1.53.2.5 2005/12/11 10:29:12 christos Exp $
      3       1.9       cgd #
      4      1.37       cgd # 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 # the config file sets the following variables:
     45      1.11       cgd #	sysnames	the syscall names file
     46      1.11       cgd #	sysnumhdr	the syscall numbers file
     47      1.11       cgd #	syssw		the syscall switch file
     48      1.11       cgd #	sysarghdr	the syscall argument struct definitions
     49      1.11       cgd #	compatopts	those syscall types that are for 'compat' syscalls
     50      1.11       cgd #	switchname	the name for the 'struct sysent' we define
     51      1.40   mycroft #	namesname	the name for the 'const char *[]' we define
     52      1.11       cgd #	constprefix	the prefix for the system call constants
     53      1.30       eeh #	registertype	the type for register_t
     54      1.40   mycroft #	nsysent		the size of the sysent table
     55      1.46  jdolecek #	sys_nosys	[optional] name of function called for unsupported
     56      1.46  jdolecek #			syscalls, if not sys_nosys()
     57      1.11       cgd #
     58  1.53.2.1     skrll # NOTE THAT THIS makesyscalls.sh DOES NOT SUPPORT 'SYSLIBCOMPAT'.
     59       1.1     glass 
     60      1.46  jdolecek # source the config file.
     61      1.46  jdolecek sys_nosys="sys_nosys"	# default is sys_nosys(), if not specified otherwise
     62      1.46  jdolecek . ./$1
     63      1.46  jdolecek 
     64       1.1     glass # tmp files:
     65       1.1     glass sysdcl="sysent.dcl"
     66      1.16   thorpej sysprotos="sys.protos"
     67      1.11       cgd syscompat_pref="sysent."
     68       1.1     glass sysent="sysent.switch"
     69      1.27   thorpej sysnamesbottom="sysnames.bottom"
     70       1.1     glass 
     71      1.27   thorpej trap "rm $sysdcl $sysprotos $sysent $sysnamesbottom" 0
     72      1.11       cgd 
     73      1.11       cgd # Awk program (must support nawk extensions)
     74      1.11       cgd # Use "awk" at Berkeley, "nawk" or "gawk" elsewhere.
     75      1.11       cgd awk=${AWK:-awk}
     76      1.11       cgd 
     77  1.53.2.2     skrll # Does this awk have a "toupper" function?
     78  1.53.2.2     skrll have_toupper=`$awk 'BEGIN { print toupper("true"); exit; }' 2>/dev/null`
     79      1.11       cgd 
     80      1.11       cgd # If this awk does not define "toupper" then define our own.
     81  1.53.2.2     skrll if [ "$have_toupper" = TRUE ] ; then
     82  1.53.2.2     skrll 	# Used awk (GNU awk or nawk) provides it
     83      1.11       cgd 	toupper=
     84      1.11       cgd else
     85      1.11       cgd 	# Provide our own toupper()
     86      1.11       cgd 	toupper='
     87      1.11       cgd function toupper(str) {
     88      1.11       cgd 	_toupper_cmd = "echo "str" |tr a-z A-Z"
     89      1.11       cgd 	_toupper_cmd | getline _toupper_str;
     90      1.11       cgd 	close(_toupper_cmd);
     91      1.11       cgd 	return _toupper_str;
     92      1.11       cgd }'
     93      1.11       cgd fi
     94      1.11       cgd 
     95      1.11       cgd # before handing it off to awk, make a few adjustments:
     96      1.11       cgd #	(1) insert spaces around {, }, (, ), *, and commas.
     97      1.11       cgd #	(2) get rid of any and all dollar signs (so that rcs id use safe)
     98      1.11       cgd #
     99      1.11       cgd # The awk script will deal with blank lines and lines that
    100      1.11       cgd # start with the comment character (';').
    101       1.1     glass 
    102      1.11       cgd sed -e '
    103      1.11       cgd s/\$//g
    104      1.11       cgd :join
    105      1.11       cgd 	/\\$/{a\
    106      1.11       cgd 
    107      1.11       cgd 	N
    108      1.11       cgd 	s/\\\n//
    109      1.11       cgd 	b join
    110      1.11       cgd 	}
    111      1.11       cgd 2,${
    112      1.11       cgd 	/^#/!s/\([{}()*,]\)/ \1 /g
    113      1.11       cgd }
    114      1.11       cgd ' < $2 | $awk "
    115      1.11       cgd $toupper
    116      1.11       cgd BEGIN {
    117      1.18       cgd 	# to allow nested #if/#else/#endif sets
    118      1.18       cgd 	savedepth = 0
    119      1.44  jdolecek 	# to track already processed syscalls
    120      1.18       cgd 
    121      1.11       cgd 	sysnames = \"$sysnames\"
    122      1.16   thorpej 	sysprotos = \"$sysprotos\"
    123      1.11       cgd 	sysnumhdr = \"$sysnumhdr\"
    124      1.11       cgd 	sysarghdr = \"$sysarghdr\"
    125      1.11       cgd 	switchname = \"$switchname\"
    126      1.11       cgd 	namesname = \"$namesname\"
    127      1.11       cgd 	constprefix = \"$constprefix\"
    128      1.30       eeh 	registertype = \"$registertype\"
    129      1.30       eeh 	if (!registertype) {
    130      1.30       eeh 	    registertype = \"register_t\"
    131      1.30       eeh 	}
    132      1.40   mycroft 	nsysent = \"$nsysent\"
    133      1.11       cgd 
    134      1.11       cgd 	sysdcl = \"$sysdcl\"
    135      1.11       cgd 	syscompat_pref = \"$syscompat_pref\"
    136      1.11       cgd 	sysent = \"$sysent\"
    137      1.27   thorpej 	sysnamesbottom = \"$sysnamesbottom\"
    138      1.46  jdolecek 	sys_nosys = \"$sys_nosys\"
    139      1.11       cgd 	infile = \"$2\"
    140      1.11       cgd 
    141      1.11       cgd 	compatopts = \"$compatopts\"
    142      1.11       cgd 	"'
    143      1.11       cgd 
    144      1.37       cgd 	printf "/* \$NetBSD\$ */\n\n" > sysdcl
    145      1.11       cgd 	printf "/*\n * System call switch table.\n *\n" > sysdcl
    146      1.11       cgd 	printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysdcl
    147      1.11       cgd 
    148      1.11       cgd 	ncompat = split(compatopts,compat)
    149      1.11       cgd 	for (i = 1; i <= ncompat; i++) {
    150      1.11       cgd 		compat_upper[i] = toupper(compat[i])
    151      1.11       cgd 
    152      1.17   mycroft 		printf "\n#ifdef %s\n", compat_upper[i] > sysent
    153      1.47     lukem 		printf "#define	%s(func) __CONCAT(%s_,func)\n", compat[i], \
    154      1.17   mycroft 		    compat[i] > sysent
    155      1.17   mycroft 		printf "#else\n" > sysent
    156      1.47     lukem 		printf "#define	%s(func) %s\n", compat[i], sys_nosys > sysent
    157      1.17   mycroft 		printf "#endif\n" > sysent
    158      1.11       cgd 	}
    159      1.11       cgd 
    160      1.17   mycroft 	printf "\n#define\ts(type)\tsizeof(type)\n\n" > sysent
    161      1.17   mycroft 	printf "struct sysent %s[] = {\n",switchname > sysent
    162      1.17   mycroft 
    163      1.37       cgd 	printf "/* \$NetBSD\$ */\n\n" > sysnames
    164      1.11       cgd 	printf "/*\n * System call names.\n *\n" > sysnames
    165      1.11       cgd 	printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysnames
    166      1.11       cgd 
    167      1.16   thorpej 	printf "\n/*\n * System call prototypes.\n */\n\n" > sysprotos
    168      1.16   thorpej 
    169      1.37       cgd 	printf "/* \$NetBSD\$ */\n\n" > sysnumhdr
    170      1.11       cgd 	printf "/*\n * System call numbers.\n *\n" > sysnumhdr
    171      1.11       cgd 	printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysnumhdr
    172      1.11       cgd 
    173      1.37       cgd 	printf "/* \$NetBSD\$ */\n\n" > sysarghdr
    174      1.13   mycroft 	printf "/*\n * System call argument lists.\n *\n" > sysarghdr
    175      1.11       cgd 	printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysarghdr
    176      1.11       cgd }
    177      1.11       cgd NR == 1 {
    178  1.53.2.4     skrll 	sub(/ $/, "")
    179      1.11       cgd 	printf " * created from%s\n */\n\n", $0 > sysdcl
    180      1.52     lukem 	printf "#include <sys/cdefs.h>\n__KERNEL_RCSID(0, \"\$NetBSD\$\");\n\n" > sysdcl
    181      1.11       cgd 
    182      1.11       cgd 	printf " * created from%s\n */\n\n", $0 > sysnames
    183      1.52     lukem 	printf "#include <sys/cdefs.h>\n__KERNEL_RCSID(0, \"\$NetBSD\$\");\n\n" > sysnames
    184      1.28   thorpej 
    185      1.28   thorpej 	# System call names are included by userland (kdump(1)), so
    186      1.28   thorpej 	# hide the include files from it.
    187      1.48       mrg 	printf "#if defined(_KERNEL_OPT)\n" > sysnames
    188      1.28   thorpej 
    189      1.48       mrg 	printf "#endif /* _KERNEL_OPT */\n\n" > sysnamesbottom
    190      1.41   mycroft 	printf "const char *const %s[] = {\n",namesname > sysnamesbottom
    191      1.11       cgd 
    192      1.11       cgd 	printf " * created from%s\n */\n\n", $0 > sysnumhdr
    193      1.11       cgd 
    194      1.11       cgd 	printf " * created from%s\n */\n\n", $0 > sysarghdr
    195  1.53.2.5  christos 	printf "#ifndef _" constprefix "SYSCALL_H_\n" > sysnumhdr
    196  1.53.2.5  christos 	printf "#define	_" constprefix "SYSCALL_H_\n\n" > sysnumhdr
    197  1.53.2.5  christos 	printf "#ifndef _" constprefix "SYSCALLARGS_H_\n" > sysarghdr
    198  1.53.2.5  christos 	printf "#define	_" constprefix "SYSCALLARGS_H_\n\n" > sysarghdr
    199      1.30       eeh 	printf "#ifdef\tsyscallarg\n" > sysarghdr
    200      1.30       eeh 	printf "#undef\tsyscallarg\n" > sysarghdr
    201      1.30       eeh 	printf "#endif\n\n" > sysarghdr
    202      1.35   thorpej 	printf "#define\tsyscallarg(x)\t\t\t\t\t\t\t\\\n" > sysarghdr
    203      1.35   thorpej 	printf "\tunion {\t\t\t\t\t\t\t\t\\\n" > sysarghdr
    204      1.35   thorpej 	printf "\t\t%s pad;\t\t\t\t\t\t\\\n", registertype > sysarghdr
    205      1.35   thorpej 	printf "\t\tstruct { x datum; } le;\t\t\t\t\t\\\n" > sysarghdr
    206      1.51      manu 	printf "\t\tstruct { /* LINTED zero array dimension */\t\t\\\n" \
    207      1.51      manu 		> sysarghdr
    208      1.51      manu 	printf "\t\t\tint8_t pad[  /* CONSTCOND */\t\t\t\\\n" > sysarghdr
    209      1.51      manu 	printf "\t\t\t\t(sizeof (%s) < sizeof (x))\t\\\n", \
    210      1.30       eeh 		registertype > sysarghdr
    211      1.35   thorpej 	printf "\t\t\t\t? 0\t\t\t\t\t\\\n" > sysarghdr
    212      1.35   thorpej 	printf "\t\t\t\t: sizeof (%s) - sizeof (x)];\t\\\n", \
    213      1.30       eeh 		registertype > sysarghdr
    214      1.35   thorpej 	printf "\t\t\tx datum;\t\t\t\t\t\\\n" > sysarghdr
    215      1.35   thorpej 	printf "\t\t} be;\t\t\t\t\t\t\t\\\n" > sysarghdr
    216      1.35   thorpej 	printf "\t}\n" > sysarghdr
    217      1.11       cgd 	next
    218      1.11       cgd }
    219      1.11       cgd NF == 0 || $1 ~ /^;/ {
    220      1.11       cgd 	next
    221      1.11       cgd }
    222      1.40   mycroft $0 ~ /^%%$/ {
    223      1.40   mycroft 	intable = 1
    224      1.40   mycroft 	next
    225      1.40   mycroft }
    226      1.11       cgd $1 ~ /^#[ 	]*include/ {
    227      1.11       cgd 	print > sysdcl
    228      1.27   thorpej 	print > sysnames
    229      1.11       cgd 	next
    230      1.11       cgd }
    231      1.40   mycroft $1 ~ /^#/ && !intable {
    232      1.40   mycroft 	print > sysdcl
    233      1.40   mycroft 	print > sysnames
    234      1.11       cgd 	next
    235      1.11       cgd }
    236      1.40   mycroft $1 ~ /^#/ && intable {
    237      1.40   mycroft 	if ($1 ~ /^#[ 	]*if/) {
    238      1.40   mycroft 		savedepth++
    239      1.40   mycroft 		savesyscall[savedepth] = syscall
    240      1.40   mycroft 	}
    241      1.40   mycroft 	if ($1 ~ /^#[ 	]*else/) {
    242      1.40   mycroft 		if (savedepth <= 0) {
    243      1.40   mycroft 			printf("%s: line %d: unbalanced #else\n", \
    244      1.40   mycroft 			    infile, NR)
    245      1.40   mycroft 			exit 1
    246      1.40   mycroft 		}
    247      1.40   mycroft 		syscall = savesyscall[savedepth]
    248      1.18       cgd 	}
    249      1.18       cgd 	if ($1 ~ /^#[       ]*endif/) {
    250      1.18       cgd 		if (savedepth <= 0) {
    251      1.40   mycroft 			printf("%s: line %d: unbalanced #endif\n", \
    252      1.40   mycroft 			    infile, NR)
    253      1.18       cgd 			exit 1
    254      1.18       cgd 		}
    255      1.40   mycroft 		savedepth--
    256      1.18       cgd 	}
    257      1.11       cgd 	print > sysent
    258  1.53.2.1     skrll 	print > sysarghdr
    259  1.53.2.1     skrll 	print > sysnumhdr
    260      1.16   thorpej 	print > sysprotos
    261      1.27   thorpej 	print > sysnamesbottom
    262      1.11       cgd 	next
    263      1.11       cgd }
    264      1.11       cgd syscall != $1 {
    265      1.11       cgd 	printf "%s: line %d: syscall number out of sync at %d\n", \
    266      1.11       cgd 	   infile, NR, syscall
    267      1.11       cgd 	printf "line is:\n"
    268      1.11       cgd 	print
    269      1.11       cgd 	exit 1
    270      1.11       cgd }
    271      1.11       cgd function parserr(was, wanted) {
    272      1.11       cgd 	printf "%s: line %d: unexpected %s (expected %s)\n", \
    273      1.11       cgd 	    infile, NR, was, wanted
    274      1.32  christos 	printf "line is:\n"
    275      1.32  christos 	print
    276      1.11       cgd 	exit 1
    277      1.11       cgd }
    278      1.11       cgd function parseline() {
    279      1.11       cgd 	f=3			# toss number and type
    280      1.45   thorpej 	sycall_flags="0"
    281      1.11       cgd 	if ($NF != "}") {
    282      1.11       cgd 		funcalias=$NF
    283      1.11       cgd 		end=NF-1
    284      1.11       cgd 	} else {
    285      1.11       cgd 		funcalias=""
    286      1.11       cgd 		end=NF
    287      1.43  jdolecek 	}
    288      1.45   thorpej 	if ($f == "MPSAFE") {		# allow for MP-safe syscalls
    289      1.45   thorpej 		sycall_flags = sprintf("SYCALL_MPSAFE | %s", sycall_flags)
    290      1.45   thorpej 		f++
    291      1.45   thorpej 	}
    292      1.43  jdolecek 	if ($f ~ /^[a-z0-9_]*$/) {	# allow syscall alias
    293      1.43  jdolecek 		funcalias=$f
    294      1.43  jdolecek 		f++
    295      1.11       cgd 	}
    296      1.11       cgd 	if ($f != "{")
    297      1.11       cgd 		parserr($f, "{")
    298      1.11       cgd 	f++
    299      1.11       cgd 	if ($end != "}")
    300      1.11       cgd 		parserr($end, "}")
    301      1.11       cgd 	end--
    302      1.11       cgd 	if ($end != ";")
    303      1.11       cgd 		parserr($end, ";")
    304      1.11       cgd 	end--
    305      1.11       cgd 	if ($end != ")")
    306      1.11       cgd 		parserr($end, ")")
    307      1.11       cgd 	end--
    308      1.11       cgd 
    309      1.19       cgd 	returntype = oldf = "";
    310      1.19       cgd 	do {
    311      1.19       cgd 		if (returntype != "" && oldf != "*")
    312      1.19       cgd 			returntype = returntype" ";
    313      1.19       cgd 		returntype = returntype$f;
    314      1.19       cgd 		oldf = $f;
    315      1.19       cgd 		f++
    316      1.19       cgd 	} while (f < (end - 1) && $(f+1) != "(");
    317      1.19       cgd 	if (f == (end - 1)) {
    318      1.19       cgd 		parserr($f, "function argument definition (maybe \"(\"?)");
    319      1.19       cgd 	}
    320      1.11       cgd 
    321      1.11       cgd 	funcname=$f
    322      1.17   mycroft 	if (funcalias == "") {
    323      1.11       cgd 		funcalias=funcname
    324      1.17   mycroft 		sub(/^([^_]+_)*sys_/, "", funcalias)
    325      1.17   mycroft 	}
    326      1.11       cgd 	f++
    327      1.11       cgd 
    328      1.11       cgd 	if ($f != "(")
    329      1.11       cgd 		parserr($f, ")")
    330      1.11       cgd 	f++
    331      1.11       cgd 
    332      1.19       cgd 	argc=0;
    333      1.11       cgd 	if (f == end) {
    334      1.11       cgd 		if ($f != "void")
    335      1.11       cgd 			parserr($f, "argument definition")
    336      1.19       cgd 		isvarargs = 0;
    337      1.19       cgd 		varargc = 0;
    338      1.11       cgd 		return
    339      1.11       cgd 	}
    340      1.11       cgd 
    341      1.19       cgd 	# some system calls (open() and fcntl()) can accept a variable
    342      1.19       cgd 	# number of arguments.  If syscalls accept a variable number of
    343      1.19       cgd 	# arguments, they must still have arguments specified for
    344      1.19       cgd 	# the remaining argument "positions," because of the way the
    345      1.19       cgd 	# kernel system call argument handling works.
    346      1.19       cgd 	#
    347      1.19       cgd 	# Indirect system calls, e.g. syscall(), are exceptions to this
    348      1.19       cgd 	# rule, since they are handled entirely by machine-dependent code
    349      1.19       cgd 	# and do not need argument structures built.
    350      1.19       cgd 
    351      1.19       cgd 	isvarargs = 0;
    352      1.11       cgd 	while (f <= end) {
    353      1.19       cgd 		if ($f == "...") {
    354      1.19       cgd 			f++;
    355      1.19       cgd 			isvarargs = 1;
    356      1.19       cgd 			varargc = argc;
    357      1.19       cgd 			continue;
    358      1.19       cgd 		}
    359      1.11       cgd 		argc++
    360      1.11       cgd 		argtype[argc]=""
    361      1.14       cgd 		oldf=""
    362      1.11       cgd 		while (f < end && $(f+1) != ",") {
    363      1.14       cgd 			if (argtype[argc] != "" && oldf != "*")
    364      1.11       cgd 				argtype[argc] = argtype[argc]" ";
    365      1.11       cgd 			argtype[argc] = argtype[argc]$f;
    366      1.14       cgd 			oldf = $f;
    367      1.11       cgd 			f++
    368      1.11       cgd 		}
    369      1.11       cgd 		if (argtype[argc] == "")
    370      1.11       cgd 			parserr($f, "argument definition")
    371      1.11       cgd 		argname[argc]=$f;
    372      1.11       cgd 		f += 2;			# skip name, and any comma
    373      1.11       cgd 	}
    374      1.19       cgd 	# must see another argument after varargs notice.
    375      1.19       cgd 	if (isvarargs) {
    376      1.19       cgd 		if (argc == varargc && $2 != "INDIR")
    377      1.19       cgd 			parserr($f, "argument definition")
    378      1.19       cgd 	} else
    379      1.19       cgd 		varargc = argc;
    380      1.11       cgd }
    381  1.53.2.1     skrll 
    382  1.53.2.1     skrll function printproto(wrap) {
    383  1.53.2.1     skrll 	printf("/* syscall: \"%s%s\" ret: \"%s\" args:", wrap, funcalias,
    384  1.53.2.1     skrll 	    returntype) > sysnumhdr
    385  1.53.2.1     skrll 	for (i = 1; i <= varargc; i++)
    386  1.53.2.1     skrll 		printf(" \"%s\"", argtype[i]) > sysnumhdr
    387  1.53.2.1     skrll 	if (isvarargs)
    388  1.53.2.1     skrll 		printf(" \"...\"") > sysnumhdr
    389  1.53.2.1     skrll 	printf(" */\n") > sysnumhdr
    390  1.53.2.1     skrll 	printf("#define\t%s%s%s\t%d\n\n", constprefix, wrap, funcalias,
    391  1.53.2.1     skrll 	    syscall) > sysnumhdr
    392  1.53.2.1     skrll }
    393  1.53.2.1     skrll 
    394      1.17   mycroft function putent(nodefs, compatwrap) {
    395      1.21       cgd 	# output syscall declaration for switch table.  INDIR functions
    396      1.21       cgd 	# get none, since they always have sys_nosys() for their table
    397      1.21       cgd 	# entries.
    398      1.21       cgd 	if (nodefs != "INDIR") {
    399      1.53   thorpej 		prototype = "(struct lwp *, void *, register_t *)"
    400      1.21       cgd 		if (compatwrap == "")
    401  1.53.2.1     skrll 			proto = sprintf("int\t%s%s;\n", funcname, prototype);
    402      1.21       cgd 		else
    403  1.53.2.1     skrll 			proto = sprintf("int\t%s_%s%s;\n", compatwrap,
    404  1.53.2.1     skrll 			    funcname, prototype);
    405  1.53.2.1     skrll 		if (sysmap[proto] != 1) {
    406  1.53.2.1     skrll 			sysmap[proto] = 1;
    407  1.53.2.1     skrll 			print proto > sysprotos;
    408  1.53.2.1     skrll 		}
    409      1.21       cgd 	}
    410      1.11       cgd 
    411      1.11       cgd 	# output syscall switch entry
    412      1.19       cgd 	if (nodefs == "INDIR") {
    413      1.46  jdolecek 		printf("\t{ 0, 0, %s,\n\t    %s },\t\t\t/* %d = %s (indir) */\n", \
    414      1.46  jdolecek 		    sycall_flags, sys_nosys, syscall, funcalias) > sysent
    415      1.19       cgd 	} else {
    416      1.19       cgd #		printf("\t{ { %d", argc) > sysent
    417      1.19       cgd #		for (i = 1; i <= argc; i++) {
    418      1.19       cgd #			if (i == 5) 		# wrap the line
    419      1.19       cgd #				printf(",\n\t    ") > sysent
    420      1.19       cgd #			else
    421      1.19       cgd #				printf(", ") > sysent
    422      1.19       cgd #			printf("s(%s)", argtypenospc[i]) > sysent
    423      1.19       cgd #		}
    424      1.19       cgd 		printf("\t{ %d, ", argc) > sysent
    425      1.19       cgd 		if (argc == 0)
    426      1.19       cgd 			printf("0") > sysent
    427      1.19       cgd 		else if (compatwrap == "")
    428      1.19       cgd 			printf("s(struct %s_args)", funcname) > sysent
    429      1.19       cgd 		else
    430      1.19       cgd 			printf("s(struct %s_%s_args)", compatwrap,
    431      1.19       cgd 			    funcname) > sysent
    432      1.19       cgd 		if (compatwrap == "")
    433      1.19       cgd 			wfn = sprintf("%s", funcname);
    434      1.19       cgd 		else
    435      1.19       cgd 			wfn = sprintf("%s(%s)", compatwrap, funcname);
    436      1.45   thorpej 		printf(", %s,\n\t    %s },", sycall_flags, wfn) > sysent
    437      1.19       cgd 		for (i = 0; i < (33 - length(wfn)) / 8; i++)
    438      1.19       cgd 			printf("\t") > sysent
    439      1.19       cgd 		if (compatwrap == "")
    440      1.19       cgd 			printf("/* %d = %s */\n", syscall, funcalias) > sysent
    441      1.19       cgd 		else
    442      1.19       cgd 			printf("/* %d = %s %s */\n", syscall, compatwrap,
    443      1.19       cgd 			    funcalias) > sysent
    444      1.19       cgd 	}
    445      1.11       cgd 
    446      1.11       cgd 	# output syscall name for names table
    447      1.11       cgd 	if (compatwrap == "")
    448      1.11       cgd 		printf("\t\"%s\",\t\t\t/* %d = %s */\n", funcalias, syscall,
    449      1.27   thorpej 		    funcalias) > sysnamesbottom
    450      1.11       cgd 	else
    451      1.11       cgd 		printf("\t\"%s_%s\",\t/* %d = %s %s */\n", compatwrap,
    452      1.27   thorpej 		    funcalias, syscall, compatwrap, funcalias) > sysnamesbottom
    453      1.11       cgd 
    454      1.11       cgd 	# output syscall number of header, if appropriate
    455  1.53.2.1     skrll 	if (nodefs == "" || nodefs == "NOARGS" || nodefs == "INDIR") {
    456      1.19       cgd 		# output a prototype, to be used to generate lint stubs in
    457      1.19       cgd 		# libc.
    458  1.53.2.1     skrll 		printproto("")
    459      1.19       cgd 
    460      1.29   thorpej 	} else if (nodefs == "COMPAT") {
    461      1.29   thorpej 		# Just define the syscall number with a comment.  These
    462      1.29   thorpej 		# may be used by compatibility stubs in libc.
    463  1.53.2.1     skrll 		printproto(compatwrap "_")
    464      1.19       cgd 	} else if (nodefs != "NODEF")
    465      1.19       cgd 		printf("\t\t\t\t/* %d is %s %s */\n\n", syscall,
    466      1.11       cgd 		    compatwrap, funcalias) > sysnumhdr
    467      1.11       cgd 
    468      1.11       cgd 	# output syscall argument structure, if it has arguments
    469      1.21       cgd 	if (argc != 0 && nodefs != "NOARGS" && nodefs != "INDIR") {
    470      1.11       cgd 		if (compatwrap == "")
    471      1.11       cgd 			printf("\nstruct %s_args {\n", funcname) > sysarghdr
    472      1.11       cgd 		else
    473      1.11       cgd 			printf("\nstruct %s_%s_args {\n", compatwrap,
    474      1.11       cgd 			    funcname) > sysarghdr
    475      1.11       cgd 		for (i = 1; i <= argc; i++)
    476      1.11       cgd 			printf("\tsyscallarg(%s) %s;\n", argtype[i],
    477      1.11       cgd 			    argname[i]) > sysarghdr
    478      1.11       cgd 		printf("};\n") > sysarghdr
    479      1.11       cgd 	}
    480      1.11       cgd }
    481      1.11       cgd $2 == "STD" {
    482      1.11       cgd 	parseline()
    483      1.17   mycroft 	putent("", "");
    484      1.11       cgd 	syscall++
    485      1.11       cgd 	next
    486      1.11       cgd }
    487      1.19       cgd $2 == "NODEF" || $2 == "NOARGS" || $2 == "INDIR" {
    488      1.11       cgd 	parseline()
    489      1.17   mycroft 	putent($2, "")
    490      1.11       cgd 	syscall++
    491      1.11       cgd 	next
    492      1.11       cgd }
    493      1.34  christos $2 == "OBSOL" || $2 == "UNIMPL" || $2 == "EXCL" {
    494      1.11       cgd 	if ($2 == "OBSOL")
    495      1.11       cgd 		comment="obsolete"
    496      1.34  christos 	else if ($2 == "EXCL")
    497      1.34  christos 		comment="excluded"
    498      1.11       cgd 	else
    499      1.11       cgd 		comment="unimplemented"
    500      1.11       cgd 	for (i = 3; i <= NF; i++)
    501      1.11       cgd 		comment=comment " " $i
    502      1.11       cgd 
    503      1.46  jdolecek 	printf("\t{ 0, 0, 0,\n\t    %s },\t\t\t/* %d = %s */\n", \
    504      1.46  jdolecek 	    sys_nosys, syscall, comment) > sysent
    505      1.11       cgd 	printf("\t\"#%d (%s)\",\t\t/* %d = %s */\n", \
    506      1.27   thorpej 	    syscall, comment, syscall, comment) > sysnamesbottom
    507      1.11       cgd 	if ($2 != "UNIMPL")
    508      1.11       cgd 		printf("\t\t\t\t/* %d is %s */\n", syscall, comment) > sysnumhdr
    509      1.11       cgd 	syscall++
    510      1.11       cgd 	next
    511      1.11       cgd }
    512      1.11       cgd {
    513      1.11       cgd 	for (i = 1; i <= ncompat; i++) {
    514      1.11       cgd 		if ($2 == compat_upper[i]) {
    515      1.11       cgd 			parseline();
    516      1.29   thorpej 			putent("COMPAT", compat[i])
    517      1.11       cgd 			syscall++
    518      1.11       cgd 			next
    519      1.11       cgd 		}
    520      1.11       cgd 	}
    521      1.40   mycroft 	printf("%s: line %d: unrecognized keyword %s\n", infile, NR, $2)
    522       1.1     glass 	exit 1
    523      1.11       cgd }
    524      1.11       cgd END {
    525      1.40   mycroft 	maxsyscall = syscall
    526      1.40   mycroft 	if (nsysent) {
    527      1.40   mycroft 		if (syscall > nsysent) {
    528      1.50       wiz 			printf("%s: line %d: too many syscalls [%d > %d]\n", infile, NR, syscall, nsysent)
    529      1.40   mycroft 			exit 1
    530      1.40   mycroft 		}
    531      1.40   mycroft 		while (syscall < nsysent) {
    532      1.46  jdolecek 			printf("\t{ 0, 0, 0,\n\t    %s },\t\t\t/* %d = filler */\n", \
    533      1.46  jdolecek 			    sys_nosys, syscall) > sysent
    534      1.40   mycroft 			syscall++
    535      1.40   mycroft 		}
    536      1.40   mycroft 	}
    537      1.11       cgd 	printf("};\n\n") > sysent
    538      1.27   thorpej 	printf("};\n") > sysnamesbottom
    539      1.40   mycroft 	printf("#define\t%sMAXSYSCALL\t%d\n", constprefix, maxsyscall) > sysnumhdr
    540      1.40   mycroft 	if (nsysent)
    541      1.40   mycroft 		printf("#define\t%sNSYSENT\t%d\n", constprefix, nsysent) > sysnumhdr
    542      1.11       cgd } '
    543       1.1     glass 
    544      1.17   mycroft cat $sysprotos >> $sysarghdr
    545  1.53.2.5  christos echo "#endif /* _${constprefix}SYSCALL_H_ */" >> $sysnumhdr
    546  1.53.2.5  christos echo "#endif /* _${constprefix}SYSCALLARGS_H_ */" >> $sysarghdr
    547      1.16   thorpej cat $sysdcl $sysent > $syssw
    548      1.27   thorpej cat $sysnamesbottom >> $sysnames
    549       1.1     glass 
    550      1.15  christos #chmod 444 $sysnames $sysnumhdr $syssw
    551