Home | History | Annotate | Line # | Download | only in kern
makesyscalls.sh revision 1.149
      1 #	$NetBSD: makesyscalls.sh,v 1.149 2015/03/08 15:07:05 christos Exp $
      2 #
      3 # Copyright (c) 1994, 1996, 2000 Christopher G. Demetriou
      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. All advertising materials mentioning features or use of this software
     15 #    must display the following acknowledgement:
     16 #      This product includes software developed for the NetBSD Project
     17 #      by Christopher G. Demetriou.
     18 # 4. The name of the author may not be used to endorse or promote products
     19 #    derived from this software without specific prior written permission
     20 #
     21 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31 
     32 #	@(#)makesyscalls.sh	8.1 (Berkeley) 6/10/93
     33 
     34 set -e
     35 
     36 case $# in
     37     2)	;;
     38     *)	echo "Usage: $0 config-file input-file" 1>&2
     39 	exit 1
     40 	;;
     41 esac
     42 
     43 # the config file sets the following variables:
     44 #	sysalign	check for alignment of off_t/dev_t/time_t
     45 #	sysnames	the syscall names file
     46 #	sysnumhdr	the syscall numbers file
     47 #	syssw		the syscall switch file
     48 #	sysarghdr	the syscall argument struct definitions
     49 #	compatopts	those syscall types that are for 'compat' syscalls
     50 #	switchname	the name for the 'struct sysent' we define
     51 #	namesname	the name for the 'const char *[]' we define
     52 #	constprefix	the prefix for the system call constants
     53 #	registertype	the type for register_t
     54 #	nsysent		the size of the sysent table
     55 #	sys_nosys	[optional] name of function called for unsupported
     56 #			syscalls, if not sys_nosys()
     57 #       maxsysargs	[optiona] the maximum number or arguments
     58 #
     59 # NOTE THAT THIS makesyscalls.sh DOES NOT SUPPORT 'SYSLIBCOMPAT'.
     60 
     61 # source the config file.
     62 sys_nosys="sys_nosys"	# default is sys_nosys(), if not specified otherwise
     63 maxsysargs=8		# default limit is 8 (32bit) arguments
     64 systrace="/dev/null"
     65 rumpcalls="/dev/null"
     66 rumpcallshdr="/dev/null"
     67 rumpsysmap="/dev/null"
     68 rumpsysent="rumpsysent.tmp"
     69 rumpnoflags="\n\t\t.sy_flags = SYCALL_NOSYS,"
     70 rumpnosys="(sy_call_t *)rumpns_enosys"
     71 rumpnomodule="(sy_call_t *)rumpns_sys_nomodule"
     72 
     73 case $1 in
     74 /*)	. $1;;
     75 *)	. ./$1;;
     76 esac
     77 
     78 # tmp files:
     79 sysdcl="sysent.dcl"
     80 sysprotos="sys.protos"
     81 syscompat_pref="sysent."
     82 sysent="sysent.switch"
     83 sysnamesbottom="sysnames.bottom"
     84 rumptypes="rumphdr.types"
     85 rumpprotos="rumphdr.protos"
     86 systracetmp="systrace.$$"
     87 systraceret="systraceret.$$"
     88 
     89 trap "rm $sysdcl $sysprotos $sysent $sysnamesbottom $rumpsysent $rumptypes $rumpprotos $systracetmp $systraceret" 0
     90 
     91 # Awk program (must support nawk extensions)
     92 # Use "awk" at Berkeley, "nawk" or "gawk" elsewhere.
     93 awk=${AWK:-awk}
     94 
     95 # Does this awk have a "toupper" function?
     96 have_toupper="$($awk 'BEGIN { print toupper("true"); exit; }' 2>/dev/null)"
     97 
     98 # If this awk does not define "toupper" then define our own.
     99 if [ "$have_toupper" = TRUE ] ; then
    100 	# Used awk (GNU awk or nawk) provides it
    101 	toupper=
    102 else
    103 	# Provide our own toupper()
    104 	toupper='
    105 function toupper(str) {
    106 	_toupper_cmd = "echo "str" |tr a-z A-Z"
    107 	_toupper_cmd | getline _toupper_str;
    108 	close(_toupper_cmd);
    109 	return _toupper_str;
    110 }'
    111 fi
    112 
    113 # before handing it off to awk, make a few adjustments:
    114 #	(1) insert spaces around {, }, (, ), *, and commas.
    115 #	(2) get rid of any and all dollar signs (so that rcs id use safe)
    116 #
    117 # The awk script will deal with blank lines and lines that
    118 # start with the comment character (';').
    119 
    120 sed -e '
    121 s/\$//g
    122 :join
    123 	/\\$/{a\
    124 
    125 	N
    126 	s/\\\n//
    127 	b join
    128 	}
    129 2,${
    130 	/^#/!s/\([{}()*,|]\)/ \1 /g
    131 }
    132 ' < $2 | $awk "
    133 $toupper
    134 BEGIN {
    135 	# Create a NetBSD tag that does not get expanded when checking
    136 	# this script out of CVS.  (This part of the awk script is in a
    137 	# shell double-quoted string, so the backslashes are eaten by
    138 	# the shell.)
    139 	tag = \"\$\" \"NetBSD\" \"\$\"
    140 
    141 	# to allow nested #if/#else/#endif sets
    142 	savedepth = 0
    143 	# to track already processed syscalls
    144 
    145 	sysnames = \"$sysnames\"
    146 	sysprotos = \"$sysprotos\"
    147 	sysnumhdr = \"$sysnumhdr\"
    148 	sysarghdr = \"$sysarghdr\"
    149 	sysarghdrextra = \"$sysarghdrextra\"
    150 	systrace = \"$systrace\"
    151 	systracetmp = \"$systracetmp\"
    152 	systraceret = \"$systraceret\"
    153 	rumpcalls = \"$rumpcalls\"
    154 	rumpcallshdr = \"$rumpcallshdr\"
    155 	rumpsysent = \"$rumpsysent\"
    156 	rumpsysmap = \"$rumpsysmap\"
    157 	switchname = \"$switchname\"
    158 	namesname = \"$namesname\"
    159 	constprefix = \"$constprefix\"
    160 	registertype = \"$registertype\"
    161 	sysalign=\"$sysalign\"
    162 	if (!registertype) {
    163 	    registertype = \"register_t\"
    164 	}
    165 	nsysent = \"$nsysent\"
    166 
    167 	sysdcl = \"$sysdcl\"
    168 	syscompat_pref = \"$syscompat_pref\"
    169 	sysent = \"$sysent\"
    170 	sysnamesbottom = \"$sysnamesbottom\"
    171 	rumpprotos = \"$rumpprotos\"
    172 	rumptypes = \"$rumptypes\"
    173 	sys_nosys = \"$sys_nosys\"
    174 	maxsysargs = \"$maxsysargs\"
    175 	infile = \"$2\"
    176 
    177 	compatopts = \"$compatopts\"
    178 	"'
    179 
    180 	if (rumpcalls != "/dev/null")
    181 		haverumpcalls = 1
    182 
    183 	printf "/* %s */\n\n", tag > sysdcl
    184 	printf "/*\n * System call switch table.\n *\n" > sysdcl
    185 	printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysdcl
    186 
    187 	ncompat = split(compatopts,compat)
    188 	for (i = 1; i <= ncompat; i++) {
    189 		compat_upper[i] = toupper(compat[i])
    190 
    191 		printf "\n#ifdef %s\n", compat_upper[i] > sysent
    192 		printf "#define	%s(func) __CONCAT(%s_,func)\n", compat[i], \
    193 		    compat[i] > sysent
    194 		printf "#else\n" > sysent
    195 		printf "#define	%s(func) %s\n", compat[i], sys_nosys > sysent
    196 		printf "#endif\n" > sysent
    197 	}
    198 
    199 	printf "\n#define\ts(type)\tsizeof(type)\n" > sysent
    200 	printf "#define\tn(type)\t(sizeof(type)/sizeof (%s))\n", registertype > sysent
    201 	printf "#define\tns(type)\t.sy_narg = n(type), .sy_argsize = s(type)\n\n", registertype > sysent
    202 	printf "struct sysent %s[] = {\n",switchname > sysent
    203 
    204 	printf "/* %s */\n\n", tag > sysnames
    205 	printf "/*\n * System call names.\n *\n" > sysnames
    206 	printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysnames
    207 
    208 	printf "\n/*\n * System call prototypes.\n */\n\n" > sysprotos
    209 	if (haverumpcalls)
    210 		printf("#ifndef RUMP_CLIENT\n") > sysprotos
    211 
    212 	printf "/* %s */\n\n", tag > sysnumhdr
    213 	printf "/*\n * System call numbers.\n *\n" > sysnumhdr
    214 	printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysnumhdr
    215 
    216 	printf "/* %s */\n\n", tag > sysarghdr
    217 	printf "/*\n * System call argument lists.\n *\n" > sysarghdr
    218 	printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysarghdr
    219 
    220 	printf "/* %s */\n\n", tag > rumpcalls
    221 	printf "/*\n * System call vector and marshalling for rump.\n *\n" > rumpcalls
    222 	printf " * DO NOT EDIT-- this file is automatically generated.\n" > rumpcalls
    223 
    224 	printf "/* %s */\n\n", tag > rumpcallshdr
    225 	printf "/*\n * System call protos in rump namespace.\n *\n" > rumpcallshdr
    226 	printf " * DO NOT EDIT-- this file is automatically generated.\n" > rumpcallshdr
    227 
    228 	printf "/* %s */\n\n", tag > systrace
    229 	printf "/*\n * System call argument to DTrace register array converstion.\n *\n" > systrace
    230 	printf " * DO NOT EDIT-- this file is automatically generated.\n" > systrace
    231 }
    232 NR == 1 {
    233 	sub(/ $/, "")
    234 	printf " * created from%s\n */\n\n", $0 > sysdcl
    235 	printf "#include <sys/cdefs.h>\n__KERNEL_RCSID(0, \"%s\");\n\n", tag > sysdcl
    236 
    237 	printf " * created from%s\n */\n\n", $0 > sysnames
    238 	printf "#include <sys/cdefs.h>\n__KERNEL_RCSID(0, \"%s\");\n\n", tag > sysnames
    239 
    240 	printf " * created from%s\n */\n\n", $0 > rumpcalls
    241 	printf "#ifdef RUMP_CLIENT\n" > rumpcalls
    242 	printf "#include <rump/rumpuser_port.h>\n" > rumpcalls
    243 	printf "#endif /* RUMP_CLIENT */\n\n" > rumpcalls
    244 	printf "#include <sys/param.h>\n\n" > rumpcalls
    245 	printf "#ifdef __NetBSD__\n" > rumpcalls
    246 	printf "#include <sys/cdefs.h>\n__KERNEL_RCSID(0, \"%s\");\n\n", tag > rumpcalls
    247 
    248 	printf "#include <sys/fstypes.h>\n" > rumpcalls
    249 	printf "#include <sys/proc.h>\n" > rumpcalls
    250 	printf "#endif /* __NetBSD__ */\n\n" > rumpcalls
    251 	printf "#ifdef RUMP_CLIENT\n" > rumpcalls
    252 	printf "#include <errno.h>\n" > rumpcalls
    253 	printf "#include <stdint.h>\n" > rumpcalls
    254 	printf "#include <stdlib.h>\n" > rumpcalls
    255 	printf "#include <string.h>\n\n" > rumpcalls
    256 	printf "#include <srcsys/syscall.h>\n" > rumpcalls
    257 	printf "#include <srcsys/syscallargs.h>\n\n" > rumpcalls
    258 	printf "#include <rump/rumpclient.h>\n\n" > rumpcalls
    259 	printf "#define rsys_syscall(num, data, dlen, retval)\t\\\n" > rumpcalls
    260 	printf "    rumpclient_syscall(num, data, dlen, retval)\n" > rumpcalls
    261 	printf "#define rsys_seterrno(error) errno = error\n" > rumpcalls
    262 	printf "#else\n" > rumpcalls
    263 	printf "#include <sys/syscall.h>\n" > rumpcalls
    264 	printf "#include <sys/syscallargs.h>\n\n" > rumpcalls
    265 	printf "#include <sys/syscallvar.h>\n\n" > rumpcalls
    266 	printf "#include <rump/rumpuser.h>\n" > rumpcalls
    267 	printf "#include \"rump_private.h\"\n\n" > rumpcalls
    268 	printf "#define rsys_syscall(num, data, dlen, retval)\t\\\n" > rumpcalls
    269 	printf "    rump_syscall(num, data, dlen, retval)\n\n" > rumpcalls
    270 	printf "#define rsys_seterrno(error) rumpuser_seterrno(error)\n" \
    271 	    > rumpcalls
    272 	printf "#endif\n\n" > rumpcalls
    273 
    274 	printf "#ifndef RUMP_KERNEL_IS_LIBC\n" > rumpcalls
    275 	printf "#define RUMP_SYS_COMPAT\n" > rumpcalls
    276 	printf "#endif\n\n" > rumpcalls
    277 
    278 	printf "#if\tBYTE_ORDER == BIG_ENDIAN\n" > rumpcalls
    279 	printf "#define SPARG(p,k)\t((p)->k.be.datum)\n" > rumpcalls
    280 	printf "#else /* LITTLE_ENDIAN, I hope dearly */\n" > rumpcalls
    281 	printf "#define SPARG(p,k)\t((p)->k.le.datum)\n" > rumpcalls
    282 	printf "#endif\n\n" > rumpcalls
    283 	printf "\nvoid rumpns_sys_nomodule(void);\n" > rumpcalls
    284 
    285 	printf "\n#ifndef RUMP_CLIENT\n" > rumpsysent
    286 	printf "int rumpns_enosys(void);\n" > rumpsysent
    287 	printf "#define\ts(type)\tsizeof(type)\n" > rumpsysent
    288 	printf "#define\tn(type)\t(sizeof(type)/sizeof (%s))\n", registertype > rumpsysent
    289 	printf "#define\tns(type)\tn(type), s(type)\n\n", registertype > rumpsysent
    290 	printf "struct sysent rump_sysent[] = {\n" > rumpsysent
    291 
    292 	# System call names are included by userland (kdump(1)), so
    293 	# hide the include files from it.
    294 	printf "#if defined(_KERNEL_OPT)\n" > sysnames
    295 
    296 	printf "#endif /* _KERNEL_OPT */\n\n" > sysnamesbottom
    297 	printf "const char *const %s[] = {\n",namesname > sysnamesbottom
    298 
    299 	printf " * created from%s\n */\n\n", $0 > sysnumhdr
    300 	printf "#ifndef _" constprefix "SYSCALL_H_\n" > sysnumhdr
    301 	printf "#define	_" constprefix "SYSCALL_H_\n\n" > sysnumhdr
    302 
    303 	printf " * created from%s\n */\n\n", $0 > sysarghdr
    304 	printf "#ifndef _" constprefix "SYSCALLARGS_H_\n" > sysarghdr
    305 	printf "#define	_" constprefix "SYSCALLARGS_H_\n\n" > sysarghdr
    306 
    307 	printf " * created from%s\n */\n\n", $0 > rumpcallshdr
    308 	printf "#ifndef _RUMP_RUMP_SYSCALLS_H_\n" > rumpcallshdr
    309 	printf "#define _RUMP_RUMP_SYSCALLS_H_\n\n" > rumpcallshdr
    310 	printf "#ifdef _KERNEL\n" > rumpcallshdr
    311 	printf "#error Interface not supported inside kernel\n" > rumpcallshdr
    312 	printf "#endif /* _KERNEL */\n\n" > rumpcallshdr
    313 	printf "#include <rump/rump_syscalls_compat.h>\n\n" > rumpcallshdr
    314 
    315 	printf "%s", sysarghdrextra > sysarghdr
    316 	# Write max number of system call arguments to both headers
    317 	printf("#define\t%sMAXSYSARGS\t%d\n\n", constprefix, maxsysargs) \
    318 		> sysnumhdr
    319 	printf("#define\t%sMAXSYSARGS\t%d\n\n", constprefix, maxsysargs) \
    320 		> sysarghdr
    321 	printf "#undef\tsyscallarg\n" > sysarghdr
    322 	printf "#define\tsyscallarg(x)\t\t\t\t\t\t\t\\\n" > sysarghdr
    323 	printf "\tunion {\t\t\t\t\t\t\t\t\\\n" > sysarghdr
    324 	printf "\t\t%s pad;\t\t\t\t\t\t\\\n", registertype > sysarghdr
    325 	printf "\t\tstruct { x datum; } le;\t\t\t\t\t\\\n" > sysarghdr
    326 	printf "\t\tstruct { /* LINTED zero array dimension */\t\t\\\n" \
    327 		> sysarghdr
    328 	printf "\t\t\tint8_t pad[  /* CONSTCOND */\t\t\t\\\n" > sysarghdr
    329 	printf "\t\t\t\t(sizeof (%s) < sizeof (x))\t\\\n", \
    330 		registertype > sysarghdr
    331 	printf "\t\t\t\t? 0\t\t\t\t\t\\\n" > sysarghdr
    332 	printf "\t\t\t\t: sizeof (%s) - sizeof (x)];\t\\\n", \
    333 		registertype > sysarghdr
    334 	printf "\t\t\tx datum;\t\t\t\t\t\\\n" > sysarghdr
    335 	printf "\t\t} be;\t\t\t\t\t\t\t\\\n" > sysarghdr
    336 	printf "\t}\n" > sysarghdr
    337 	printf("\n#undef check_syscall_args\n") >sysarghdr
    338 	printf("#define check_syscall_args(call) /*LINTED*/ \\\n" \
    339 		"\ttypedef char call##_check_args" \
    340 		    "[sizeof (struct call##_args) \\\n" \
    341 		"\t\t<= %sMAXSYSARGS * sizeof (%s) ? 1 : -1];\n", \
    342 		constprefix, registertype) >sysarghdr
    343 
    344 	printf " * This file is part of the DTrace syscall provider.\n */\n\n" > systrace
    345 	printf "static void\nsystrace_args(register_t sysnum, const void *params, uintptr_t *uarg, size_t *n_args)\n{\n" > systrace
    346 	printf "\tintptr_t *iarg  = (intptr_t *)uarg;\n" > systrace
    347 	printf "\tswitch (sysnum) {\n" > systrace
    348 
    349 	printf "static void\nsystrace_entry_setargdesc(int sysnum, int ndx, char *desc, size_t descsz)\n{\n\tconst char *p = NULL;\n" > systracetmp
    350 	printf "\tswitch (sysnum) {\n" > systracetmp
    351 
    352 	printf "static void\nsystrace_return_setargdesc(int sysnum, int ndx, char *desc, size_t descsz)\n{\n\tconst char *p = NULL;\n" > systraceret
    353 	printf "\tswitch (sysnum) {\n" > systraceret
    354 
    355 	# compat types from syscalls.master.  this is slightly ugly,
    356 	# but given that we have so few compats from over 17 years,
    357 	# a more complicated solution is not currently warranted.
    358 	uncompattypes["struct timeval50"] = "struct timeval";
    359 	uncompattypes["struct timespec50"] = "struct timespec";
    360 	uncompattypes["struct stat30"] = "struct stat";
    361 
    362 	next
    363 }
    364 NF == 0 || $1 ~ /^;/ {
    365 	next
    366 }
    367 $0 ~ /^%%$/ {
    368 	intable = 1
    369 	next
    370 }
    371 $1 ~ /^#[ 	]*include/ {
    372 	print > sysdcl
    373 	print > sysnames
    374 	next
    375 }
    376 $1 ~ /^#/ && !intable {
    377 	print > sysdcl
    378 	print > sysnames
    379 	next
    380 }
    381 $1 ~ /^#/ && intable {
    382 	if ($1 ~ /^#[ 	]*if/) {
    383 		savedepth++
    384 		savesyscall[savedepth] = syscall
    385 	}
    386 	if ($1 ~ /^#[ 	]*else/) {
    387 		if (savedepth <= 0) {
    388 			printf("%s: line %d: unbalanced #else\n", \
    389 			    infile, NR)
    390 			exit 1
    391 		}
    392 		syscall = savesyscall[savedepth]
    393 	}
    394 	if ($1 ~ /^#[       ]*endif/) {
    395 		if (savedepth <= 0) {
    396 			printf("%s: line %d: unbalanced #endif\n", \
    397 			    infile, NR)
    398 			exit 1
    399 		}
    400 		savedepth--
    401 	}
    402 	print > sysent
    403 	print > sysarghdr
    404 	print > sysnumhdr
    405 	print > sysprotos
    406 	print > sysnamesbottom
    407 	print > systrace
    408 	print > systracetmp
    409 	print > systraceret
    410 
    411 	# XXX: technically we do not want to have conditionals in rump,
    412 	# but it is easier to just let the cpp handle them than try to
    413 	# figure out what we want here in this script
    414 	print > rumpsysent
    415 	next
    416 }
    417 syscall != $1 {
    418 	printf "%s: line %d: syscall number out of sync at %d\n", \
    419 	   infile, NR, syscall
    420 	printf "line is:\n"
    421 	print
    422 	exit 1
    423 }
    424 function parserr(was, wanted) {
    425 	printf "%s: line %d: unexpected %s (expected <%s>)\n", \
    426 	    infile, NR, was, wanted
    427 	printf "line is:\n"
    428 	print
    429 	exit 1
    430 }
    431 function fillerpsysent(syscall, flags, name, comment) {
    432 	return sprintf("\t{%s\n\t\t.sy_call = %s,\n\t},\t\t/* %d = filler */",\
    433 	    flags, name, syscall, comment);
    434 }
    435 function parseline() {
    436 	f=3			# toss number and type
    437 	if ($2 == "INDIR")
    438 		sycall_flags="SYCALL_INDIRECT"
    439 	else
    440 		sycall_flags="0"
    441 	if ($NF != "}") {
    442 		funcalias=$NF
    443 		end=NF-1
    444 	} else {
    445 		funcalias=""
    446 		end=NF
    447 	}
    448 	if ($f == "INDIR") {		# allow for "NOARG INDIR"
    449 		sycall_flags = "SYCALL_INDIRECT | " sycall_flags
    450 		f++
    451 	}
    452 	if ($f == "MODULAR") {		# registered at runtime
    453 		modular = 1
    454 		f++
    455 	} else {
    456 		modular =  0;
    457 	}
    458 	if ($f == "RUMP") {
    459 		rumpable = 1
    460 		f++
    461 	} else {
    462 		rumpable = 0
    463 	}
    464 	if ($f ~ /^[a-z0-9_]*$/) {	# allow syscall alias
    465 		funcalias=$f
    466 		f++
    467 	}
    468 	if ($f != "{")
    469 		parserr($f, "{")
    470 	f++
    471 	if ($end != "}")
    472 		parserr($end, "}")
    473 	end--
    474 	if ($end != ";")
    475 		parserr($end, ";")
    476 	end--
    477 	if ($end != ")")
    478 		parserr($end, ")")
    479 	end--
    480 
    481 	returntype = oldf = "";
    482 	do {
    483 		if (returntype != "" && oldf != "*")
    484 			returntype = returntype" ";
    485 		returntype = returntype$f;
    486 		oldf = $f;
    487 		f++
    488 	} while ($f != "|" && f < (end-1))
    489 	if (f == (end - 1)) {
    490 		parserr($f, "function argument definition (maybe \"|\"?)");
    491 	}
    492 	f++
    493 
    494 	fprefix=$f
    495 	f++
    496 	if ($f != "|") {
    497 		parserr($f, "function compat delimiter (maybe \"|\"?)");
    498 	}
    499 	f++
    500 
    501 	fcompat=""
    502 	if ($f != "|") {
    503 		fcompat=$f
    504 		f++
    505 	}
    506 
    507 	if ($f != "|") {
    508 		parserr($f, "function name delimiter (maybe \"|\"?)");
    509 	}
    510 	f++
    511 	fbase=$f
    512 
    513 	# pipe is special in how to returns its values.
    514 	# So just generate it manually if present.
    515 	if (rumpable == 1 && fbase == "pipe") {
    516 		rumpable = 0;
    517 		rumphaspipe = 1;
    518 	}
    519 
    520 	if (fcompat != "") {
    521 		funcname=fprefix "___" fbase "" fcompat
    522 	} else {
    523 		funcname=fprefix "_" fbase
    524 	}
    525 	if (returntype == "quad_t" || returntype == "off_t") {
    526 		if (sycall_flags == "0")
    527 			sycall_flags = "SYCALL_RET_64";
    528 		else
    529 			sycall_flags = "SYCALL_RET_64 | " sycall_flags;
    530 	}
    531 
    532 	if (funcalias == "") {
    533 		funcalias=funcname
    534 		sub(/^([^_]+_)*sys_/, "", funcalias)
    535 		realname=fbase
    536 	} else {
    537 		realname=funcalias
    538 	}
    539 	rumpfname=realname "" fcompat
    540 	f++
    541 
    542 	if ($f != "(")
    543 		parserr($f, "(")
    544 	f++
    545 
    546 	argc=0;
    547 	argalign=0;
    548 	if (f == end) {
    549 		if ($f != "void")
    550 			parserr($f, "argument definition")
    551 		isvarargs = 0;
    552 		varargc = 0;
    553 		argtype[0]="void";
    554 		return
    555 	}
    556 
    557 	# some system calls (open() and fcntl()) can accept a variable
    558 	# number of arguments.  If syscalls accept a variable number of
    559 	# arguments, they must still have arguments specified for
    560 	# the remaining argument "positions," because of the way the
    561 	# kernel system call argument handling works.
    562 	#
    563 	# Indirect system calls, e.g. syscall(), are exceptions to this
    564 	# rule, since they are handled entirely by machine-dependent code
    565 	# and do not need argument structures built.
    566 
    567 	isvarargs = 0;
    568 	args64 = 0;
    569 	ptr = 0;
    570 	while (f <= end) {
    571 		if ($f == "...") {
    572 			f++;
    573 			isvarargs = 1;
    574 			varargc = argc;
    575 			continue;
    576 		}
    577 		argc++
    578 		argtype[argc]=""
    579 		oldf=""
    580 		while (f < end && $(f+1) != ",") {
    581 			if (argtype[argc] != "" && oldf != "*")
    582 				argtype[argc] = argtype[argc]" ";
    583 			argtype[argc] = argtype[argc]$f;
    584 			oldf = $f;
    585 			f++
    586 		}
    587 		if (argtype[argc] == "")
    588 			parserr($f, "argument definition")
    589 		if (argtype[argc] == "off_t"  \
    590 		  || argtype[argc] == "dev_t" \
    591 		  || argtype[argc] == "time_t") {
    592 			if ((argalign % 2) != 0 && sysalign &&
    593 			    funcname != "sys_posix_fadvise") # XXX for now
    594 				parserr($f, "a padding argument")
    595 		} else {
    596 			argalign++;
    597 		}
    598 		if (argtype[argc] == "quad_t" || argtype[argc] == "off_t" \
    599 		  || argtype[argc] == "dev_t" || argtype[argc] == "time_t") {
    600 			if (sycall_flags == "0")
    601 				sycall_flags = "SYCALL_ARG"argc-1"_64";
    602 			else
    603 				sycall_flags = "SYCALL_ARG"argc-1"_64 | " sycall_flags;
    604 			args64++;
    605 		}
    606 		if (index(argtype[argc], "*") != 0 && ptr == 0) {
    607 			if (sycall_flags == "0")
    608 				sycall_flags = "SYCALL_ARG_PTR";
    609 			else
    610 				sycall_flags = "SYCALL_ARG_PTR | " sycall_flags;
    611 			ptr = 1;
    612 		}
    613 		argname[argc]=$f;
    614 		f += 2;			# skip name, and any comma
    615 	}
    616 	if (args64 > 0)
    617 		sycall_flags = "SYCALL_NARGS64_VAL("args64") | " sycall_flags;
    618 	# must see another argument after varargs notice.
    619 	if (isvarargs) {
    620 		if (argc == varargc)
    621 			parserr($f, "argument definition")
    622 	} else
    623 		varargc = argc;
    624 }
    625 
    626 function printproto(wrap) {
    627 	printf("/* syscall: \"%s%s\" ret: \"%s\" args:", wrap, funcalias,
    628 	    returntype) > sysnumhdr
    629 	for (i = 1; i <= varargc; i++)
    630 		printf(" \"%s\"", argtype[i]) > sysnumhdr
    631 	if (isvarargs)
    632 		printf(" \"...\"") > sysnumhdr
    633 	printf(" */\n") > sysnumhdr
    634 	printf("#define\t%s%s%s\t%d\n\n", constprefix, wrap, funcalias,
    635 	    syscall) > sysnumhdr
    636 
    637 	# rumpalooza
    638 	if (!rumpable)
    639 		return
    640 
    641 	# accumulate fbases we have seen.  we want the last
    642 	# occurence for the default __RENAME()
    643 	seen = funcseen[fbase]
    644 	funcseen[fbase] = rumpfname
    645 	# special case for mknod as type of last argument changed from
    646 	# uint32_t to dev_t
    647 	if ((seen && fbase != "mknod") || (!seen && fbase == "mknod"))
    648 		return
    649 
    650 	printf("%s rump_sys_%s(", returntype, realname) > rumpprotos
    651 
    652 	for (i = 1; i < varargc; i++)
    653 		if (argname[i] != "PAD")
    654 			printf("%s, ", uncompattype(argtype[i])) > rumpprotos
    655 
    656 	if (isvarargs)
    657 		printf("%s, ...)", uncompattype(argtype[varargc]))>rumpprotos
    658 	else
    659 		printf("%s)", uncompattype(argtype[argc])) > rumpprotos
    660 
    661 	printf(" __RENAME(RUMP_SYS_RENAME_%s)", toupper(fbase))> rumpprotos
    662 	printf(";\n") > rumpprotos
    663 
    664 	# generate forward-declares for types, apart from the
    665 	# braindead typedef jungle we cannot easily handle here
    666 	for (i = 1; i <= varargc; i++) {
    667 		type=uncompattype(argtype[i])
    668 		sub("const ", "", type)
    669 		ntype=type
    670 		sub(" *\\*.*", "", ntype);
    671 		if (!typeseen[ntype] && \
    672 		    match(type, "struct") && match(type, "\\*")) {
    673 			typeseen[ntype] = 1
    674 			printf("%s;\n", ntype) > rumptypes
    675 		}
    676 	}
    677 }
    678 
    679 function printrumpsysent(insysent, compatwrap) {
    680 	if (modular) {
    681 		fn = rumpnomodule
    682 		flags = rumpnoflags
    683 	} else {
    684 		fn = rumpnosys
    685 		flags = ""
    686 	}
    687 	if (!insysent) {
    688 		printf("\t{%s\n\t\t.sy_call = %s,\n},\t\t/* %d = %s */\n", \
    689 		    flags, fn, syscall, funcalias) > rumpsysent
    690 		return
    691 	}
    692 
    693 	printf("\t{") > rumpsysent
    694 	if (argc != 0) {
    695 		printf("\n\t\tns(struct %ssys_%s_args),", compatwrap_, funcalias) > rumpsysent
    696 	}
    697 
    698 	printf("\n\t\t.sy_call = %s,\n\t},", fn) > rumpsysent
    699 	printf("\t\t/* %d = %s%s */\n", syscall, compatwrap_, funcalias) > rumpsysent
    700 }
    701 
    702 function iscompattype(type) {
    703 	for (var in uncompattypes) {
    704 		if (match(type, var)) {
    705 			return 1
    706 		}
    707 	}
    708 
    709 	return 0
    710 }
    711 
    712 function uncompattype(type) {
    713 	for (var in uncompattypes) {
    714 		if (match(type, var)) {
    715 			sub(var, uncompattypes[var], type)
    716 			return type
    717 		}
    718 	}
    719 
    720 	return type
    721 }
    722 
    723 function printrumpsysmap(syscall, wfn, funcalias, rumpentry) {
    724 	printf("%-4d %-22s %-18s %s\n",
    725 	    syscall, wfn, funcalias, rumpentry) > rumpsysmap
    726 }
    727 
    728 function putsystrace(type, compatwrap_) {
    729 	printf("\t/* %s */\n\tcase %d: {\n", funcname, syscall) > systrace
    730 	printf("\t/* %s */\n\tcase %d:\n", funcname, syscall) > systracetmp
    731 	printf("\t/* %s */\n\tcase %d:\n", funcname, syscall) > systraceret
    732 	if (argc > 0) {
    733 		printf("\t\tswitch(ndx) {\n") > systracetmp
    734 		printf("\t\tstruct %s%s_args *p = params;\n", compatwrap_, funcname) > systrace
    735 		for (i = 1; i <= argc; i++) {
    736 			arg = argtype[i]
    737 			sub("__restrict$", "", arg)
    738 			printf("\t\tcase %d:\n\t\t\tp = \"%s\";\n\t\t\tbreak;\n", i - 1, arg) > systracetmp
    739 			if (arg ~ /.*p_t$/ || arg ~ /.*p$/ || arg ~ /.*_t_p$/ ||
    740 			    arg ~ /.*_pointer_t$/)
    741 				printf("\t\tuarg[%d] = (intptr_t) SCARG(p, %s).i32; /* %s */\n", \
    742 				     i - 1, \
    743 				     argname[i], arg) > systrace
    744 			else if (index(arg, "*") > 0 || arg == "caddr_t")
    745 				printf("\t\tuarg[%d] = (intptr_t) SCARG(p, %s); /* %s */\n", \
    746 				     i - 1, \
    747 				     argname[i], arg) > systrace
    748 			else if (substr(arg, 1, 1) == "u" || arg == "size_t")
    749 				printf("\t\tuarg[%d] = SCARG(p, %s); /* %s */\n", \
    750 				     i - 1, \
    751 				     argname[i], arg) > systrace
    752 			else
    753 				printf("\t\tiarg[%d] = SCARG(p, %s); /* %s */\n", \
    754 				     i - 1, \
    755 				     argname[i], arg) > systrace
    756 		}
    757 		printf("\t\tdefault:\n\t\t\tbreak;\n\t\t};\n") > systracetmp
    758 
    759 		printf("\t\tif (ndx == 0 || ndx == 1)\n") > systraceret
    760 		printf("\t\t\tp = \"%s\";\n", returntype) > systraceret
    761 		printf("\t\tbreak;\n") > systraceret
    762 	}
    763 	printf("\t\t*n_args = %d;\n\t\tbreak;\n\t}\n", argc) > systrace
    764 	printf("\t\tbreak;\n") > systracetmp
    765 }
    766 
    767 function putent(type, compatwrap) {
    768 	# output syscall declaration for switch table.
    769 	if (compatwrap == "")
    770 		compatwrap_ = ""
    771 	else
    772 		compatwrap_ = compatwrap "_"
    773 	if (argc == 0)
    774 		arg_type = "void";
    775 	else {
    776 		arg_type = "struct " compatwrap_ funcname "_args";
    777 	}
    778 	putsystrace(type, compatwrap_)
    779 	proto = "int\t" compatwrap_ funcname "(struct lwp *, const " \
    780 	    arg_type " *, register_t *);\n"
    781 	if (sysmap[proto] != 1) {
    782 		sysmap[proto] = 1;
    783 		print proto > sysprotos;
    784 	}
    785 
    786 	# output syscall switch entry
    787 	printf("\t{\n\t\t") > sysent
    788 	if (argc != 0) {
    789 		printf("ns(struct %s%s_args),", compatwrap_, funcname) > sysent
    790 	}
    791 	if (modular) 
    792 		wfn = "sys_nomodule";
    793 	else if (compatwrap == "")
    794 		wfn = funcname;
    795 	else
    796 		wfn = compatwrap "(" funcname ")";
    797 	wfn_cast="(sy_call_t *)" wfn
    798 	if (sycall_flags != "0")
    799 		flags = "\n\t\t.sy_flags = " sycall_flags ","
    800 	else
    801 		flags = ""
    802 	printf("%s\n\t\t.sy_call = %s\n\t},", flags, wfn_cast) > sysent
    803 	printf("\t\t/* %d = %s%s */\n", syscall, compatwrap_, funcalias) > sysent
    804 
    805 	# output syscall name for names table
    806 	printf("\t/* %3d */\t\"%s%s\",\n", syscall, compatwrap_, funcalias) \
    807 	    > sysnamesbottom
    808 
    809 	# output syscall number of header, if appropriate
    810 	if (type == "STD" || type == "NOARGS" || type == "INDIR" || \
    811 	    type == "NOERR") {
    812 		# output a prototype, to be used to generate lint stubs in
    813 		# libc.
    814 		printproto("")
    815 	} else if (type == "COMPAT" || type == "EXTERN") {
    816 		# Just define the syscall number with a comment.  These
    817 		# may be used by compatibility stubs in libc.
    818 		printproto(compatwrap_)
    819 	}
    820 
    821 	# output syscall argument structure, if it has arguments
    822 	if (argc != 0) {
    823 		printf("\n") > sysarghdr
    824 		if (haverumpcalls && !rumpable)
    825 			printf("#ifndef RUMP_CLIENT\n") > sysarghdr
    826 		printf("struct %s%s_args", compatwrap_, funcname) > sysarghdr
    827 		if (type != "NOARGS") {
    828 			print " {" >sysarghdr;
    829 			for (i = 1; i <= argc; i++)
    830 				printf("\tsyscallarg(%s) %s;\n", argtype[i],
    831 				    argname[i]) > sysarghdr
    832 			printf "}" >sysarghdr;
    833 		}
    834 		printf(";\n") > sysarghdr
    835 		if (type != "NOARGS" && type != "INDIR") {
    836 			printf("check_syscall_args(%s%s)\n", compatwrap_,
    837 			    funcname) >sysarghdr
    838 		}
    839 		if (haverumpcalls && !rumpable)
    840 			printf("#endif /* !RUMP_CLIENT */\n") > sysarghdr
    841 	}
    842 
    843 	if (!rumpable) {
    844 		if (funcname == "sys_pipe" && rumphaspipe == 1) {
    845 			insysent = 1
    846 			printrumpsysmap(syscall,
    847 			    funcname, funcalias, "rump_sys_pipe")
    848 		} else {
    849 			insysent = 0
    850 		}
    851 	} else {
    852 		insysent = 1
    853 	}
    854 	printrumpsysent(insysent, compatwrap)
    855 
    856 	# output rump marshalling code if necessary
    857 	if (!rumpable) {
    858 		return
    859 	}
    860 
    861 	printrumpsysmap(syscall, wfn, funcalias, "rump___sysimpl_" rumpfname)
    862 
    863 	printf("\n") > rumpcalls
    864 
    865 	if (compatwrap)
    866 		printf("#ifdef RUMP_SYS_COMPAT\n") > rumpcalls
    867 
    868 	# need a local prototype, we export the re-re-named one in .h
    869 	printf("%s rump___sysimpl_%s(", returntype, rumpfname) \
    870 	    > rumpcalls
    871 	for (i = 1; i < argc; i++) {
    872 		if (argname[i] != "PAD")
    873 			printf("%s, ", uncompattype(argtype[i])) > rumpcalls
    874 	}
    875 	printf("%s);", uncompattype(argtype[argc])) > rumpcalls
    876 
    877 	printf("\n%s\nrump___sysimpl_%s(", returntype, rumpfname) > rumpcalls
    878 	for (i = 1; i < argc; i++) {
    879 		if (argname[i] != "PAD")
    880 			printf("%s %s, ", uncompattype(argtype[i]), \
    881 			    argname[i]) > rumpcalls
    882 	}
    883 	printf("%s %s)\n", uncompattype(argtype[argc]), argname[argc]) \
    884 	    > rumpcalls
    885 	printf("{\n\tregister_t retval[2];\n") > rumpcalls
    886 	if (returntype != "void") {
    887 		if (type != "NOERR") {
    888 			printf("\tint error = 0;\n") > rumpcalls
    889 		}
    890 		# assume rumpcalls return only integral types
    891 		printf("\t%s rv = -1;\n", returntype) > rumpcalls
    892 	}
    893 
    894 	argarg = "NULL"
    895 	argsize = 0;
    896 	if (argc) {
    897 		argarg = "&callarg"
    898 		argsize = "sizeof(callarg)"
    899 		printf("\tstruct %s%s_args callarg;\n\n",compatwrap_,funcname) \
    900 		    > rumpcalls
    901 		printf "\tmemset(&callarg, 0, sizeof(callarg));\n" > rumpcalls
    902 		for (i = 1; i <= argc; i++) {
    903 			if (argname[i] == "PAD") {
    904 				printf("\tSPARG(&callarg, %s) = 0;\n", \
    905 				    argname[i]) > rumpcalls
    906 			} else {
    907 				if (iscompattype(argtype[i])) {
    908 					printf("\tSPARG(&callarg, %s) = "    \
    909 					"(%s)%s;\n", argname[i], argtype[i], \
    910 					argname[i]) > rumpcalls
    911 				} else {
    912 					printf("\tSPARG(&callarg, %s) = %s;\n",\
    913 					    argname[i], argname[i]) > rumpcalls
    914 				}
    915 			}
    916 		}
    917 		printf("\n") > rumpcalls
    918 	} else {
    919 		printf("\n") > rumpcalls
    920 	}
    921 	printf("\t") > rumpcalls
    922 	if (returntype != "void" && type != "NOERR")
    923 		printf("error = ") > rumpcalls
    924 	printf("rsys_syscall(%s%s%s, " \
    925 	    "%s, %s, retval);\n", constprefix, compatwrap_, funcalias, \
    926 	    argarg, argsize) > rumpcalls
    927 	if (type != "NOERR") {
    928 		printf("\trsys_seterrno(error);\n") > rumpcalls
    929 		printf("\tif (error == 0) {\n") > rumpcalls
    930 		indent="\t\t"
    931 		ending="\t}\n"
    932 	} else {
    933 		indent="\t"
    934 		ending=""
    935 	}
    936 	if (returntype != "void") {
    937 		printf("%sif (sizeof(%s) > sizeof(register_t))\n", \
    938 		    indent, returntype) > rumpcalls
    939 		printf("%s\trv = *(%s *)retval;\n", \
    940 		    indent, returntype) > rumpcalls
    941 		printf("%selse\n", indent, indent) > rumpcalls
    942 		printf("%s\trv = *retval;\n", indent, returntype) > rumpcalls
    943 		printf("%s", ending) > rumpcalls
    944 		printf("\treturn rv;\n") > rumpcalls
    945 	}
    946 	printf("}\n") > rumpcalls
    947 
    948 	printf("#ifdef RUMP_KERNEL_IS_LIBC\n") > rumpcalls
    949 
    950 	# create the bog-standard, non-renamed public name.
    951 	# this way we get e.g. select instead of just __select50
    952 	if (fcompat)
    953 		printf("__weak_alias(%s,rump___sysimpl_%s);\n", \
    954 		    fbase, rumpfname) > rumpcalls
    955 
    956 	printf("__weak_alias(%s,rump___sysimpl_%s);\n", \
    957 	    funcalias, rumpfname) > rumpcalls
    958 	printf("__weak_alias(_%s,rump___sysimpl_%s);\n", \
    959 	    funcalias, rumpfname) > rumpcalls
    960 	printf("__strong_alias(_sys_%s,rump___sysimpl_%s);\n", \
    961 	    funcalias, rumpfname) >rumpcalls
    962 
    963 	printf("#endif /* RUMP_KERNEL_IS_LIBC */\n") > rumpcalls
    964 
    965 	if (compatwrap)
    966 		printf("#endif /* RUMP_SYS_COMPAT */\n") > rumpcalls
    967 
    968 }
    969 $2 == "STD" || $2 == "NODEF" || $2 == "NOARGS" || $2 == "INDIR" \
    970     || $2 == "NOERR" {
    971 	parseline()
    972 	putent($2, "")
    973 	syscall++
    974 	next
    975 }
    976 $2 == "OBSOL" || $2 == "UNIMPL" || $2 == "EXCL" || $2 == "IGNORED" {
    977 	if ($2 == "OBSOL")
    978 		comment="obsolete"
    979 	else if ($2 == "EXCL")
    980 		comment="excluded"
    981 	else if ($2 == "IGNORED")
    982 		comment="ignored"
    983 	else
    984 		comment="unimplemented"
    985 	for (i = 3; i <= NF; i++)
    986 		comment=comment " " $i
    987 
    988 	if ($2 == "IGNORED")
    989 		sys_stub = "(sy_call_t *)nullop";
    990 	else
    991 		sys_stub = sys_nosys;
    992 
    993 	print fillerpsysent(syscall, "", sys_stub, comment) > sysent
    994 	print fillerpsysent(syscall, rumpnoflags, rumpnosys, comment) > rumpsysent
    995 	printf("\t/* %3d */\t\"#%d (%s)\",\n", syscall, syscall, comment) \
    996 	    > sysnamesbottom
    997 	if ($2 != "UNIMPL")
    998 		printf("\t\t\t\t/* %d is %s */\n", syscall, comment) > sysnumhdr
    999 	syscall++
   1000 	next
   1001 }
   1002 $2 == "EXTERN" {
   1003 	parseline()
   1004 	putent("EXTERN", "")
   1005 	syscall++
   1006 	next
   1007 }
   1008 {
   1009 	for (i = 1; i <= ncompat; i++) {
   1010 		if ($2 == compat_upper[i]) {
   1011 			parseline();
   1012 			putent("COMPAT", compat[i])
   1013 			syscall++
   1014 			next
   1015 		}
   1016 	}
   1017 	printf("%s: line %d: unrecognized keyword %s\n", infile, NR, $2)
   1018 	exit 1
   1019 }
   1020 END {
   1021 	# output pipe() syscall with its special retval[2] handling
   1022 	if (rumphaspipe) {
   1023 		printf("int rump_sys_pipe(int *);\n") > rumpprotos
   1024 		printf("\nint rump_sys_pipe(int *);\n") > rumpcalls
   1025 		printf("int\nrump_sys_pipe(int *fd)\n{\n") > rumpcalls
   1026 		printf("\tregister_t retval[2];\n") > rumpcalls
   1027 		printf("\tint error = 0;\n") > rumpcalls
   1028 		printf("\n\terror = rsys_syscall(SYS_pipe, ") > rumpcalls
   1029 		printf("NULL, 0, retval);\n") > rumpcalls
   1030 		printf("\tif (error) {\n") > rumpcalls
   1031 		printf("\t\trsys_seterrno(error);\n") > rumpcalls
   1032 		printf("\t} else {\n\t\tfd[0] = retval[0];\n") > rumpcalls
   1033 		printf("\t\tfd[1] = retval[1];\n\t}\n") > rumpcalls
   1034 		printf("\treturn error ? -1 : 0;\n}\n") > rumpcalls
   1035 		printf("#ifdef RUMP_KERNEL_IS_LIBC\n") > rumpcalls
   1036 		printf("__weak_alias(pipe,rump_sys_pipe);\n") > rumpcalls
   1037 		printf("__weak_alias(_pipe,rump_sys_pipe);\n") > rumpcalls
   1038 		printf("__strong_alias(_sys_pipe,rump_sys_pipe);\n") > rumpcalls
   1039 		printf("#endif\n") > rumpcalls
   1040 	}
   1041 
   1042 	# print default rump syscall interfaces
   1043 	for (var in funcseen) {
   1044 		printf("#ifndef RUMP_SYS_RENAME_%s\n", \
   1045 		    toupper(var)) > rumpcallshdr
   1046 		printf("#define RUMP_SYS_RENAME_%s rump___sysimpl_%s\n", \
   1047 		    toupper(var), funcseen[var]) > rumpcallshdr
   1048 		printf("#endif\n\n") > rumpcallshdr
   1049 	}
   1050 
   1051 	maxsyscall = syscall
   1052 	if (nsysent) {
   1053 		if (syscall > nsysent) {
   1054 			printf("%s: line %d: too many syscalls [%d > %d]\n", infile, NR, syscall, nsysent)
   1055 			exit 1
   1056 		}
   1057 		while (syscall < nsysent) {
   1058 			print fillerpsysent(syscall, "", sys_nosys, "filler") > sysent
   1059 			print fillerpsysent(syscall, rumpnoflags, rumpnosys, "filler") > rumpsysent
   1060 			printf("\t/* %3d */\t\"# filler\",\n", syscall) \
   1061 			    > sysnamesbottom
   1062 			syscall++
   1063 		}
   1064 	}
   1065 	printf("};\n") > sysent
   1066 	printf("};\n") > rumpsysent
   1067 	printf("CTASSERT(__arraycount(rump_sysent) == SYS_NSYSENT);\n") > rumpsysent
   1068 	printf("__strong_alias(rumpns_sysent,rump_sysent);\n") > rumpsysent
   1069 	printf("#endif /* RUMP_CLIENT */\n") > rumpsysent
   1070 	if (haverumpcalls)
   1071 		printf("#endif /* !RUMP_CLIENT */\n") > sysprotos
   1072 	printf("};\n") > sysnamesbottom
   1073 	printf("#define\t%sMAXSYSCALL\t%d\n", constprefix, maxsyscall) > sysnumhdr
   1074 	if (nsysent)
   1075 		printf("#define\t%sNSYSENT\t%d\n", constprefix, nsysent) > sysnumhdr
   1076 	printf "\tdefault:\n\t\t*n_args = 0;\n\t\tbreak;\n\t};\n}\n" > systrace
   1077 	printf "\tdefault:\n\t\tbreak;\n\t};\n\tif (p != NULL)\n\t\tstrlcpy(desc, p, descsz);\n}\n" > systracetmp
   1078 	printf "\tdefault:\n\t\tbreak;\n\t};\n\tif (p != NULL)\n\t\tstrlcpy(desc, p, descsz);\n}\n" > systraceret
   1079 } '
   1080 
   1081 cat $sysprotos >> $sysarghdr
   1082 echo "#endif /* _${constprefix}SYSCALL_H_ */" >> $sysnumhdr
   1083 echo "#endif /* _${constprefix}SYSCALLARGS_H_ */" >> $sysarghdr
   1084 printf "\n#endif /* _RUMP_RUMP_SYSCALLS_H_ */\n" >> $rumpprotos
   1085 cat $sysdcl $sysent > $syssw
   1086 cat $sysnamesbottom >> $sysnames
   1087 cat $rumpsysent >> $rumpcalls
   1088 
   1089 touch $rumptypes
   1090 cat $rumptypes >> $rumpcallshdr
   1091 echo >> $rumpcallshdr
   1092 cat $rumpprotos >> $rumpcallshdr
   1093 
   1094 #chmod 444 $sysnames $sysnumhdr $syssw
   1095 
   1096 cat $systracetmp >> $systrace
   1097 cat $systraceret >> $systrace
   1098 
   1099 echo Generated following files:
   1100 echo $sysarghdr $sysnumhdr $syssw $sysnames $systrace $rumpcalls $rumpcallshdr $rumpsysmap
   1101