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