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