Home | History | Annotate | Line # | Download | only in kern
makesyscalls.sh revision 1.63.2.1
      1 #! /bin/sh -
      2 #	$NetBSD: makesyscalls.sh,v 1.63.2.1 2008/03/24 07:16:14 keiichi Exp $
      3 #
      4 # Copyright (c) 1994, 1996, 2000 Christopher G. Demetriou
      5 # All rights reserved.
      6 #
      7 # Redistribution and use in source and binary forms, with or without
      8 # modification, are permitted provided that the following conditions
      9 # are met:
     10 # 1. Redistributions of source code must retain the above copyright
     11 #    notice, this list of conditions and the following disclaimer.
     12 # 2. Redistributions in binary form must reproduce the above copyright
     13 #    notice, this list of conditions and the following disclaimer in the
     14 #    documentation and/or other materials provided with the distribution.
     15 # 3. All advertising materials mentioning features or use of this software
     16 #    must display the following acknowledgement:
     17 #      This product includes software developed for the NetBSD Project
     18 #      by Christopher G. Demetriou.
     19 # 4. The name of the author may not be used to endorse or promote products
     20 #    derived from this software without specific prior written permission
     21 #
     22 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32 
     33 #	@(#)makesyscalls.sh	8.1 (Berkeley) 6/10/93
     34 
     35 set -e
     36 
     37 case $# in
     38     2)	;;
     39     *)	echo "Usage: $0 config-file input-file" 1>&2
     40 	exit 1
     41 	;;
     42 esac
     43 
     44 # the config file sets the following variables:
     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 rumpcalls="/dev/null"
     65 rumpcallshdr="/dev/null"
     66 . ./$1
     67 
     68 # tmp files:
     69 sysdcl="sysent.dcl"
     70 sysprotos="sys.protos"
     71 syscompat_pref="sysent."
     72 sysent="sysent.switch"
     73 sysnamesbottom="sysnames.bottom"
     74 
     75 trap "rm $sysdcl $sysprotos $sysent $sysnamesbottom" 0
     76 
     77 # Awk program (must support nawk extensions)
     78 # Use "awk" at Berkeley, "nawk" or "gawk" elsewhere.
     79 awk=${AWK:-awk}
     80 
     81 # Does this awk have a "toupper" function?
     82 have_toupper=`$awk 'BEGIN { print toupper("true"); exit; }' 2>/dev/null`
     83 
     84 # If this awk does not define "toupper" then define our own.
     85 if [ "$have_toupper" = TRUE ] ; then
     86 	# Used awk (GNU awk or nawk) provides it
     87 	toupper=
     88 else
     89 	# Provide our own toupper()
     90 	toupper='
     91 function toupper(str) {
     92 	_toupper_cmd = "echo "str" |tr a-z A-Z"
     93 	_toupper_cmd | getline _toupper_str;
     94 	close(_toupper_cmd);
     95 	return _toupper_str;
     96 }'
     97 fi
     98 
     99 # before handing it off to awk, make a few adjustments:
    100 #	(1) insert spaces around {, }, (, ), *, and commas.
    101 #	(2) get rid of any and all dollar signs (so that rcs id use safe)
    102 #
    103 # The awk script will deal with blank lines and lines that
    104 # start with the comment character (';').
    105 
    106 sed -e '
    107 s/\$//g
    108 :join
    109 	/\\$/{a\
    110 
    111 	N
    112 	s/\\\n//
    113 	b join
    114 	}
    115 2,${
    116 	/^#/!s/\([{}()*,]\)/ \1 /g
    117 }
    118 ' < $2 | $awk "
    119 $toupper
    120 BEGIN {
    121 	# to allow nested #if/#else/#endif sets
    122 	savedepth = 0
    123 	# to track already processed syscalls
    124 
    125 	sysnames = \"$sysnames\"
    126 	sysprotos = \"$sysprotos\"
    127 	sysnumhdr = \"$sysnumhdr\"
    128 	sysarghdr = \"$sysarghdr\"
    129 	rumpcalls = \"$rumpcalls\"
    130 	rumpcallshdr = \"$rumpcallshdr\"
    131 	switchname = \"$switchname\"
    132 	namesname = \"$namesname\"
    133 	constprefix = \"$constprefix\"
    134 	registertype = \"$registertype\"
    135 	if (!registertype) {
    136 	    registertype = \"register_t\"
    137 	}
    138 	nsysent = \"$nsysent\"
    139 
    140 	sysdcl = \"$sysdcl\"
    141 	syscompat_pref = \"$syscompat_pref\"
    142 	sysent = \"$sysent\"
    143 	sysnamesbottom = \"$sysnamesbottom\"
    144 	sys_nosys = \"$sys_nosys\"
    145 	maxsysargs = \"$maxsysargs\"
    146 	infile = \"$2\"
    147 
    148 	compatopts = \"$compatopts\"
    149 	"'
    150 
    151 	printf "/* \$NetBSD\$ */\n\n" > sysdcl
    152 	printf "/*\n * System call switch table.\n *\n" > sysdcl
    153 	printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysdcl
    154 
    155 	ncompat = split(compatopts,compat)
    156 	for (i = 1; i <= ncompat; i++) {
    157 		compat_upper[i] = toupper(compat[i])
    158 
    159 		printf "\n#ifdef %s\n", compat_upper[i] > sysent
    160 		printf "#define	%s(func) __CONCAT(%s_,func)\n", compat[i], \
    161 		    compat[i] > sysent
    162 		printf "#else\n" > sysent
    163 		printf "#define	%s(func) %s\n", compat[i], sys_nosys > sysent
    164 		printf "#endif\n" > sysent
    165 	}
    166 
    167 	printf "\n#define\ts(type)\tsizeof(type)\n" > sysent
    168 	printf "#define\tn(type)\t(sizeof(type)/sizeof (%s))\n", registertype > sysent
    169 	printf "#define\tns(type)\tn(type), s(type)\n\n", registertype > sysent
    170 	printf "struct sysent %s[] = {\n",switchname > sysent
    171 
    172 	printf "/* \$NetBSD\$ */\n\n" > sysnames
    173 	printf "/*\n * System call names.\n *\n" > sysnames
    174 	printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysnames
    175 
    176 	printf "\n/*\n * System call prototypes.\n */\n\n" > sysprotos
    177 
    178 	printf "/* \$NetBSD\$ */\n\n" > sysnumhdr
    179 	printf "/*\n * System call numbers.\n *\n" > sysnumhdr
    180 	printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysnumhdr
    181 
    182 	printf "/* \$NetBSD\$ */\n\n" > sysarghdr
    183 	printf "/*\n * System call argument lists.\n *\n" > sysarghdr
    184 	printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysarghdr
    185 
    186 	printf "/* \$NetBSD\$ */\n\n" > rumpcalls
    187 	printf "/*\n * System call marshalling for rump.\n *\n" > rumpcalls
    188 	printf " * DO NOT EDIT-- this file is automatically generated.\n" > rumpcalls
    189 
    190 	printf "/* \$NetBSD\$ */\n\n" > rumpcallshdr
    191 	printf "/*\n * System call protos in rump namespace.\n *\n" > rumpcallshdr
    192 	printf " * DO NOT EDIT-- this file is automatically generated.\n" > rumpcallshdr
    193 }
    194 NR == 1 {
    195 	sub(/ $/, "")
    196 	printf " * created from%s\n */\n\n", $0 > sysdcl
    197 	printf "#include <sys/cdefs.h>\n__KERNEL_RCSID(0, \"\$NetBSD\$\");\n\n" > sysdcl
    198 
    199 	printf " * created from%s\n */\n\n", $0 > sysnames
    200 	printf "#include <sys/cdefs.h>\n__KERNEL_RCSID(0, \"\$NetBSD\$\");\n\n" > sysnames
    201 
    202 	printf " * created from%s\n */\n\n", $0 > rumpcalls
    203 	printf "#include <sys/cdefs.h>\n__KERNEL_RCSID(0, \"\$NetBSD\$\");\n\n" > rumpcalls
    204 	printf "#include <sys/types.h>\n" > rumpcalls
    205 	printf "#include <sys/param.h>\n" > rumpcalls
    206 	printf "#include <sys/proc.h>\n" > rumpcalls
    207 	printf "#include <sys/syscallargs.h>\n" > rumpcalls
    208 	printf "#include \"rump_syscalls.h\"\n\n" > rumpcalls
    209 	printf "#if\tBYTE_ORDER == BIG_ENDIAN\n" > rumpcalls
    210 	printf "#define SPARG(p,k)\t((p)->k.be.datum)\n" > rumpcalls
    211 	printf "#else /* LITTLE_ENDIAN, I hope dearly */\n" > rumpcalls
    212 	printf "#define SPARG(p,k)\t((p)->k.le.datum)\n" > rumpcalls
    213 	printf "#endif\n\n" > rumpcalls
    214 
    215 	# System call names are included by userland (kdump(1)), so
    216 	# hide the include files from it.
    217 	printf "#if defined(_KERNEL_OPT)\n" > sysnames
    218 
    219 	printf "#endif /* _KERNEL_OPT */\n\n" > sysnamesbottom
    220 	printf "const char *const %s[] = {\n",namesname > sysnamesbottom
    221 
    222 	printf " * created from%s\n */\n\n", $0 > sysnumhdr
    223 
    224 	printf " * created from%s\n */\n\n", $0 > sysarghdr
    225 
    226 	printf " * created from%s\n */\n\n", $0 > rumpcallshdr
    227 
    228 	printf "#ifndef _" constprefix "SYSCALL_H_\n" > sysnumhdr
    229 	printf "#define	_" constprefix "SYSCALL_H_\n\n" > sysnumhdr
    230 	printf "#ifndef _" constprefix "SYSCALLARGS_H_\n" > sysarghdr
    231 	printf "#define	_" constprefix "SYSCALLARGS_H_\n\n" > sysarghdr
    232 	# Write max number of system call arguments to both headers
    233 	printf("#define\t%sMAXSYSARGS\t%d\n\n", constprefix, maxsysargs) \
    234 		> sysnumhdr
    235 	printf("#define\t%sMAXSYSARGS\t%d\n\n", constprefix, maxsysargs) \
    236 		> sysarghdr
    237 	printf "#undef\tsyscallarg\n" > sysarghdr
    238 	printf "#define\tsyscallarg(x)\t\t\t\t\t\t\t\\\n" > sysarghdr
    239 	printf "\tunion {\t\t\t\t\t\t\t\t\\\n" > sysarghdr
    240 	printf "\t\t%s pad;\t\t\t\t\t\t\\\n", registertype > sysarghdr
    241 	printf "\t\tstruct { x datum; } le;\t\t\t\t\t\\\n" > sysarghdr
    242 	printf "\t\tstruct { /* LINTED zero array dimension */\t\t\\\n" \
    243 		> sysarghdr
    244 	printf "\t\t\tint8_t pad[  /* CONSTCOND */\t\t\t\\\n" > sysarghdr
    245 	printf "\t\t\t\t(sizeof (%s) < sizeof (x))\t\\\n", \
    246 		registertype > sysarghdr
    247 	printf "\t\t\t\t? 0\t\t\t\t\t\\\n" > sysarghdr
    248 	printf "\t\t\t\t: sizeof (%s) - sizeof (x)];\t\\\n", \
    249 		registertype > sysarghdr
    250 	printf "\t\t\tx datum;\t\t\t\t\t\\\n" > sysarghdr
    251 	printf "\t\t} be;\t\t\t\t\t\t\t\\\n" > sysarghdr
    252 	printf "\t}\n" > sysarghdr
    253 	printf("\n#undef check_syscall_args\n") >sysarghdr
    254 	printf("#define check_syscall_args(call) \\\n" \
    255 		"\ttypedef char call##_check_args" \
    256 		    "[sizeof (struct call##_args) \\\n" \
    257 		"\t\t<= %sMAXSYSARGS * sizeof (%s) ? 1 : -1];\n", \
    258 		constprefix, registertype) >sysarghdr
    259 	next
    260 }
    261 NF == 0 || $1 ~ /^;/ {
    262 	next
    263 }
    264 $0 ~ /^%%$/ {
    265 	intable = 1
    266 	next
    267 }
    268 $1 ~ /^#[ 	]*include/ {
    269 	print > sysdcl
    270 	print > sysnames
    271 	next
    272 }
    273 $1 ~ /^#/ && !intable {
    274 	print > sysdcl
    275 	print > sysnames
    276 	next
    277 }
    278 $1 ~ /^#/ && intable {
    279 	if ($1 ~ /^#[ 	]*if/) {
    280 		savedepth++
    281 		savesyscall[savedepth] = syscall
    282 	}
    283 	if ($1 ~ /^#[ 	]*else/) {
    284 		if (savedepth <= 0) {
    285 			printf("%s: line %d: unbalanced #else\n", \
    286 			    infile, NR)
    287 			exit 1
    288 		}
    289 		syscall = savesyscall[savedepth]
    290 	}
    291 	if ($1 ~ /^#[       ]*endif/) {
    292 		if (savedepth <= 0) {
    293 			printf("%s: line %d: unbalanced #endif\n", \
    294 			    infile, NR)
    295 			exit 1
    296 		}
    297 		savedepth--
    298 	}
    299 	print > sysent
    300 	print > sysarghdr
    301 	print > sysnumhdr
    302 	print > sysprotos
    303 	print > sysnamesbottom
    304 	next
    305 }
    306 syscall != $1 {
    307 	printf "%s: line %d: syscall number out of sync at %d\n", \
    308 	   infile, NR, syscall
    309 	printf "line is:\n"
    310 	print
    311 	exit 1
    312 }
    313 function parserr(was, wanted) {
    314 	printf "%s: line %d: unexpected %s (expected %s)\n", \
    315 	    infile, NR, was, wanted
    316 	printf "line is:\n"
    317 	print
    318 	exit 1
    319 }
    320 function parseline() {
    321 	f=3			# toss number and type
    322 	if ($2 == "INDIR")
    323 		sycall_flags="SYCALL_INDIRECT"
    324 	else
    325 		sycall_flags="0"
    326 	if ($NF != "}") {
    327 		funcalias=$NF
    328 		end=NF-1
    329 	} else {
    330 		funcalias=""
    331 		end=NF
    332 	}
    333 	if ($f == "INDIR") {		# allow for "NOARG INDIR"
    334 		sycall_flags = "SYCALL_INDIRECT | " sycall_flags
    335 		f++
    336 	}
    337 	if ($f == "MPSAFE") {		# allow for MP-safe syscalls
    338 		sycall_flags = "SYCALL_MPSAFE | " sycall_flags
    339 		f++
    340 	}
    341 	if ($f == "RUMP") {
    342 		rumpable = 1
    343 		f++
    344 	} else {
    345 		rumpable = 0
    346 	}
    347 	if ($f ~ /^[a-z0-9_]*$/) {	# allow syscall alias
    348 		funcalias=$f
    349 		f++
    350 	}
    351 	if ($f != "{")
    352 		parserr($f, "{")
    353 	f++
    354 	if ($end != "}")
    355 		parserr($end, "}")
    356 	end--
    357 	if ($end != ";")
    358 		parserr($end, ";")
    359 	end--
    360 	if ($end != ")")
    361 		parserr($end, ")")
    362 	end--
    363 
    364 	returntype = oldf = "";
    365 	do {
    366 		if (returntype != "" && oldf != "*")
    367 			returntype = returntype" ";
    368 		returntype = returntype$f;
    369 		oldf = $f;
    370 		f++
    371 	} while (f < (end - 1) && $(f+1) != "(");
    372 	if (f == (end - 1)) {
    373 		parserr($f, "function argument definition (maybe \"(\"?)");
    374 	}
    375 
    376 	funcname=$f
    377 	if (funcalias == "") {
    378 		funcalias=funcname
    379 		sub(/^([^_]+_)*sys_/, "", funcalias)
    380 	}
    381 	f++
    382 
    383 	if ($f != "(")
    384 		parserr($f, ")")
    385 	f++
    386 
    387 	argc=0;
    388 	argalign=0;
    389 	if (f == end) {
    390 		if ($f != "void")
    391 			parserr($f, "argument definition")
    392 		isvarargs = 0;
    393 		varargc = 0;
    394 		return
    395 	}
    396 
    397 	# some system calls (open() and fcntl()) can accept a variable
    398 	# number of arguments.  If syscalls accept a variable number of
    399 	# arguments, they must still have arguments specified for
    400 	# the remaining argument "positions," because of the way the
    401 	# kernel system call argument handling works.
    402 	#
    403 	# Indirect system calls, e.g. syscall(), are exceptions to this
    404 	# rule, since they are handled entirely by machine-dependent code
    405 	# and do not need argument structures built.
    406 
    407 	isvarargs = 0;
    408 	while (f <= end) {
    409 		if ($f == "...") {
    410 			f++;
    411 			isvarargs = 1;
    412 			varargc = argc;
    413 			continue;
    414 		}
    415 		argc++
    416 		argtype[argc]=""
    417 		oldf=""
    418 		while (f < end && $(f+1) != ",") {
    419 			if (argtype[argc] != "" && oldf != "*")
    420 				argtype[argc] = argtype[argc]" ";
    421 			argtype[argc] = argtype[argc]$f;
    422 			oldf = $f;
    423 			f++
    424 		}
    425 		if (argtype[argc] == "")
    426 			parserr($f, "argument definition")
    427 		if (argtype[argc] == "off_t") {
    428 			if ((argalign % 2) != 0 &&
    429 			    funcname != "sys_posix_fadvise") # XXX for now
    430 				parserr($f, "a padding argument")
    431 		} else {
    432 			argalign++;
    433 		}
    434 		argname[argc]=$f;
    435 		f += 2;			# skip name, and any comma
    436 	}
    437 	# must see another argument after varargs notice.
    438 	if (isvarargs) {
    439 		if (argc == varargc)
    440 			parserr($f, "argument definition")
    441 	} else
    442 		varargc = argc;
    443 }
    444 
    445 function printproto(wrap) {
    446 	printf("/* syscall: \"%s%s\" ret: \"%s\" args:", wrap, funcalias,
    447 	    returntype) > sysnumhdr
    448 	for (i = 1; i <= varargc; i++)
    449 		printf(" \"%s\"", argtype[i]) > sysnumhdr
    450 	if (isvarargs)
    451 		printf(" \"...\"") > sysnumhdr
    452 	printf(" */\n") > sysnumhdr
    453 	printf("#define\t%s%s%s\t%d\n\n", constprefix, wrap, funcalias,
    454 	    syscall) > sysnumhdr
    455 
    456 	# rumpalooza
    457 	if (!rumpable)
    458 		return
    459 
    460 	if (wrap == "")
    461 		wrap = "sys"
    462 	printf("%s rump_%s_%s(", returntype, wrap, funcalias) > rumpcallshdr
    463 	for (i = 1; i <= argc; i++)
    464 		printf("%s, ", argtype[i]) > rumpcallshdr
    465 	printf("int *);\n") > rumpcallshdr
    466 }
    467 
    468 function putent(type, compatwrap) {
    469 	# output syscall declaration for switch table.
    470 	if (compatwrap == "")
    471 		compatwrap_ = ""
    472 	else
    473 		compatwrap_ = compatwrap "_"
    474 	if (argc == 0)
    475 		arg_type = "void";
    476 	else {
    477 		arg_type = "struct " compatwrap_ funcname "_args";
    478 	}
    479 	proto = "int\t" compatwrap_ funcname "(struct lwp *, const " \
    480 	    arg_type " *, register_t *);\n"
    481 	if (sysmap[proto] != 1) {
    482 		sysmap[proto] = 1;
    483 		print proto > sysprotos;
    484 	}
    485 
    486 	# output syscall switch entry
    487 	printf("\t{ ") > sysent
    488 	if (argc == 0) {
    489 		printf("0, 0, ") > sysent
    490 	} else {
    491 		printf("ns(struct %s%s_args), ", compatwrap_, funcname) > sysent
    492 	}
    493 	if (compatwrap == "")
    494 		wfn = "(sy_call_t *)" funcname;
    495 	else
    496 		wfn = "(sy_call_t *)" compatwrap "(" funcname ")";
    497 	printf("%s,\n\t    %s },", sycall_flags, wfn) > sysent
    498 	for (i = 0; i < (33 - length(wfn)) / 8; i++)
    499 		printf("\t") > sysent
    500 	printf("/* %d = %s%s */\n", syscall, compatwrap_, funcalias) > sysent
    501 
    502 	# output syscall name for names table
    503 	printf("\t/* %3d */\t\"%s%s\",\n", syscall, compatwrap_, funcalias) \
    504 	    > sysnamesbottom
    505 
    506 	# output syscall number of header, if appropriate
    507 	if (type == "STD" || type == "NOARGS" || type == "INDIR") {
    508 		# output a prototype, to be used to generate lint stubs in
    509 		# libc.
    510 		printproto("")
    511 	} else if (type == "COMPAT") {
    512 		# Just define the syscall number with a comment.  These
    513 		# may be used by compatibility stubs in libc.
    514 		printproto(compatwrap_)
    515 	}
    516 
    517 	# output syscall argument structure, if it has arguments
    518 	if (argc != 0) {
    519 		printf("\nstruct %s%s_args", compatwrap_, funcname) > sysarghdr
    520 		if (type != "NOARGS") {
    521 			print " {" >sysarghdr;
    522 			for (i = 1; i <= argc; i++)
    523 				printf("\tsyscallarg(%s) %s;\n", argtype[i],
    524 				    argname[i]) > sysarghdr
    525 			printf "}" >sysarghdr;
    526 		}
    527 		printf(";\n") > sysarghdr
    528 		if (type != "NOARGS" && type != "INDIR") {
    529 			printf("check_syscall_args(%s%s)\n", compatwrap_,
    530 			    funcname) >sysarghdr
    531 		}
    532 	}
    533 
    534 	# output rump marshalling code if necessary
    535 	if (!rumpable)
    536 		return
    537 
    538 	printf("%s\nrump_%s(", returntype, funcname) > rumpcalls
    539 	for (i = 1; i <= argc; i++) {
    540 		printf("%s %s, ", argtype[i], argname[i]) > rumpcalls
    541 	}
    542 	printf("int *error)\n") > rumpcalls
    543 	printf("{\n\tregister_t retval;\n") > rumpcalls
    544 	argarg = "NULL"
    545 	if (argc) {
    546 		argarg = "&arg"
    547 		printf("\tstruct %s%s_args arg;\n\n", funcname, compatwrap_) \
    548 		    > rumpcalls
    549 		for (i = 1; i <= argc; i++) {
    550 			printf("\tSPARG(&arg, %s) = %s;\n", \
    551 			    argname[i], argname[i]) > rumpcalls
    552 		}
    553 		printf("\n") > rumpcalls
    554 	} else {
    555 		printf("\n") > rumpcalls
    556 	}
    557 	printf("\t*error = %s(curlwp, %s, &retval);\n", funcname, argarg) \
    558 	    > rumpcalls
    559 	if (returntype != "void")
    560 		printf("\treturn retval;\n") > rumpcalls
    561 	printf("}\n\n") > rumpcalls
    562 }
    563 $2 == "STD" || $2 == "NODEF" || $2 == "NOARGS" || $2 == "INDIR" {
    564 	parseline()
    565 	putent($2, "")
    566 	syscall++
    567 	next
    568 }
    569 $2 == "OBSOL" || $2 == "UNIMPL" || $2 == "EXCL" || $2 == "IGNORED" {
    570 	if ($2 == "OBSOL")
    571 		comment="obsolete"
    572 	else if ($2 == "EXCL")
    573 		comment="excluded"
    574 	else if ($2 == "IGNORED")
    575 		comment="ignored"
    576 	else
    577 		comment="unimplemented"
    578 	for (i = 3; i <= NF; i++)
    579 		comment=comment " " $i
    580 
    581 	if ($2 == "IGNORED")
    582 		sys_stub = "(sy_call_t *)nullop";
    583 	else
    584 		sys_stub = sys_nosys;
    585 
    586 	printf("\t{ 0, 0, 0,\n\t    %s },\t\t\t/* %d = %s */\n", \
    587 	    sys_stub, syscall, comment) > sysent
    588 	printf("\t/* %3d */\t\"#%d (%s)\",\n", syscall, syscall, comment) \
    589 	    > sysnamesbottom
    590 	if ($2 != "UNIMPL")
    591 		printf("\t\t\t\t/* %d is %s */\n", syscall, comment) > sysnumhdr
    592 	syscall++
    593 	next
    594 }
    595 {
    596 	for (i = 1; i <= ncompat; i++) {
    597 		if ($2 == compat_upper[i]) {
    598 			parseline();
    599 			putent("COMPAT", compat[i])
    600 			syscall++
    601 			next
    602 		}
    603 	}
    604 	printf("%s: line %d: unrecognized keyword %s\n", infile, NR, $2)
    605 	exit 1
    606 }
    607 END {
    608 	maxsyscall = syscall
    609 	if (nsysent) {
    610 		if (syscall > nsysent) {
    611 			printf("%s: line %d: too many syscalls [%d > %d]\n", infile, NR, syscall, nsysent)
    612 			exit 1
    613 		}
    614 		while (syscall < nsysent) {
    615 			printf("\t{ 0, 0, 0,\n\t    %s },\t\t\t/* %d = filler */\n", \
    616 			    sys_nosys, syscall) > sysent
    617 			syscall++
    618 		}
    619 	}
    620 	printf("};\n\n") > sysent
    621 	printf("};\n") > sysnamesbottom
    622 	printf("#define\t%sMAXSYSCALL\t%d\n", constprefix, maxsyscall) > sysnumhdr
    623 	if (nsysent)
    624 		printf("#define\t%sNSYSENT\t%d\n", constprefix, nsysent) > sysnumhdr
    625 } '
    626 
    627 cat $sysprotos >> $sysarghdr
    628 echo "#endif /* _${constprefix}SYSCALL_H_ */" >> $sysnumhdr
    629 echo "#endif /* _${constprefix}SYSCALLARGS_H_ */" >> $sysarghdr
    630 cat $sysdcl $sysent > $syssw
    631 cat $sysnamesbottom >> $sysnames
    632 
    633 #chmod 444 $sysnames $sysnumhdr $syssw
    634