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