Home | History | Annotate | Line # | Download | only in kern
makesyscalls.sh revision 1.69.2.5
      1       1.1     glass #! /bin/sh -
      2  1.69.2.5      yamt #	$NetBSD: makesyscalls.sh,v 1.69.2.5 2010/10/09 03:32:31 yamt Exp $
      3       1.9       cgd #
      4      1.37       cgd # Copyright (c) 1994, 1996, 2000 Christopher G. Demetriou
      5      1.12       cgd # All rights reserved.
      6      1.12       cgd #
      7      1.12       cgd # Redistribution and use in source and binary forms, with or without
      8      1.12       cgd # modification, are permitted provided that the following conditions
      9      1.12       cgd # are met:
     10      1.12       cgd # 1. Redistributions of source code must retain the above copyright
     11      1.12       cgd #    notice, this list of conditions and the following disclaimer.
     12      1.12       cgd # 2. Redistributions in binary form must reproduce the above copyright
     13      1.12       cgd #    notice, this list of conditions and the following disclaimer in the
     14      1.12       cgd #    documentation and/or other materials provided with the distribution.
     15      1.12       cgd # 3. All advertising materials mentioning features or use of this software
     16      1.12       cgd #    must display the following acknowledgement:
     17      1.12       cgd #      This product includes software developed for the NetBSD Project
     18      1.12       cgd #      by Christopher G. Demetriou.
     19      1.12       cgd # 4. The name of the author may not be used to endorse or promote products
     20      1.12       cgd #    derived from this software without specific prior written permission
     21      1.12       cgd #
     22      1.12       cgd # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23      1.12       cgd # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24      1.12       cgd # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25      1.12       cgd # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26      1.12       cgd # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27      1.12       cgd # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28      1.12       cgd # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29      1.12       cgd # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30      1.12       cgd # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31      1.12       cgd # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32      1.14       cgd 
     33      1.14       cgd #	@(#)makesyscalls.sh	8.1 (Berkeley) 6/10/93
     34       1.1     glass 
     35       1.1     glass set -e
     36       1.1     glass 
     37      1.11       cgd case $# in
     38      1.11       cgd     2)	;;
     39      1.11       cgd     *)	echo "Usage: $0 config-file input-file" 1>&2
     40      1.11       cgd 	exit 1
     41      1.11       cgd 	;;
     42      1.11       cgd esac
     43      1.11       cgd 
     44      1.11       cgd # the config file sets the following variables:
     45      1.68  christos #	sysalign	check for alignment of off_t
     46      1.11       cgd #	sysnames	the syscall names file
     47      1.11       cgd #	sysnumhdr	the syscall numbers file
     48      1.11       cgd #	syssw		the syscall switch file
     49      1.11       cgd #	sysarghdr	the syscall argument struct definitions
     50      1.11       cgd #	compatopts	those syscall types that are for 'compat' syscalls
     51      1.11       cgd #	switchname	the name for the 'struct sysent' we define
     52      1.40   mycroft #	namesname	the name for the 'const char *[]' we define
     53      1.11       cgd #	constprefix	the prefix for the system call constants
     54      1.30       eeh #	registertype	the type for register_t
     55      1.40   mycroft #	nsysent		the size of the sysent table
     56      1.46  jdolecek #	sys_nosys	[optional] name of function called for unsupported
     57      1.46  jdolecek #			syscalls, if not sys_nosys()
     58      1.60       dsl #       maxsysargs	[optiona] the maximum number or arguments
     59      1.11       cgd #
     60      1.56     lukem # NOTE THAT THIS makesyscalls.sh DOES NOT SUPPORT 'SYSLIBCOMPAT'.
     61       1.1     glass 
     62      1.46  jdolecek # source the config file.
     63      1.46  jdolecek sys_nosys="sys_nosys"	# default is sys_nosys(), if not specified otherwise
     64      1.60       dsl maxsysargs=8		# default limit is 8 (32bit) arguments
     65      1.67     njoly rumpcalls="/dev/null"
     66      1.67     njoly rumpcallshdr="/dev/null"
     67  1.69.2.1      yamt rumpsysent="rumpsysent.tmp"
     68      1.46  jdolecek . ./$1
     69      1.46  jdolecek 
     70       1.1     glass # tmp files:
     71       1.1     glass sysdcl="sysent.dcl"
     72      1.16   thorpej sysprotos="sys.protos"
     73      1.11       cgd syscompat_pref="sysent."
     74       1.1     glass sysent="sysent.switch"
     75      1.27   thorpej sysnamesbottom="sysnames.bottom"
     76       1.1     glass 
     77  1.69.2.1      yamt trap "rm $sysdcl $sysprotos $sysent $sysnamesbottom $rumpsysent" 0
     78      1.11       cgd 
     79      1.11       cgd # Awk program (must support nawk extensions)
     80      1.11       cgd # Use "awk" at Berkeley, "nawk" or "gawk" elsewhere.
     81      1.11       cgd awk=${AWK:-awk}
     82      1.11       cgd 
     83      1.57  jdolecek # Does this awk have a "toupper" function?
     84      1.57  jdolecek have_toupper=`$awk 'BEGIN { print toupper("true"); exit; }' 2>/dev/null`
     85      1.11       cgd 
     86      1.11       cgd # If this awk does not define "toupper" then define our own.
     87      1.57  jdolecek if [ "$have_toupper" = TRUE ] ; then
     88      1.57  jdolecek 	# Used awk (GNU awk or nawk) provides it
     89      1.11       cgd 	toupper=
     90      1.11       cgd else
     91      1.11       cgd 	# Provide our own toupper()
     92      1.11       cgd 	toupper='
     93      1.11       cgd function toupper(str) {
     94      1.11       cgd 	_toupper_cmd = "echo "str" |tr a-z A-Z"
     95      1.11       cgd 	_toupper_cmd | getline _toupper_str;
     96      1.11       cgd 	close(_toupper_cmd);
     97      1.11       cgd 	return _toupper_str;
     98      1.11       cgd }'
     99      1.11       cgd fi
    100      1.11       cgd 
    101      1.11       cgd # before handing it off to awk, make a few adjustments:
    102      1.11       cgd #	(1) insert spaces around {, }, (, ), *, and commas.
    103      1.11       cgd #	(2) get rid of any and all dollar signs (so that rcs id use safe)
    104      1.11       cgd #
    105      1.11       cgd # The awk script will deal with blank lines and lines that
    106      1.11       cgd # start with the comment character (';').
    107       1.1     glass 
    108      1.11       cgd sed -e '
    109      1.11       cgd s/\$//g
    110      1.11       cgd :join
    111      1.11       cgd 	/\\$/{a\
    112      1.11       cgd 
    113      1.11       cgd 	N
    114      1.11       cgd 	s/\\\n//
    115      1.11       cgd 	b join
    116      1.11       cgd 	}
    117      1.11       cgd 2,${
    118  1.69.2.1      yamt 	/^#/!s/\([{}()*,|]\)/ \1 /g
    119      1.11       cgd }
    120      1.11       cgd ' < $2 | $awk "
    121      1.11       cgd $toupper
    122      1.11       cgd BEGIN {
    123  1.69.2.1      yamt 	# Create a NetBSD tag that does not get expanded when checking
    124  1.69.2.1      yamt 	# this script out of CVS.  (This part of the awk script is in a
    125  1.69.2.1      yamt 	# shell double-quoted string, so the backslashes are eaten by
    126  1.69.2.1      yamt 	# the shell.)
    127  1.69.2.1      yamt 	tag = \"\$\" \"NetBSD\" \"\$\"
    128  1.69.2.1      yamt 
    129      1.18       cgd 	# to allow nested #if/#else/#endif sets
    130      1.18       cgd 	savedepth = 0
    131      1.44  jdolecek 	# to track already processed syscalls
    132      1.18       cgd 
    133      1.11       cgd 	sysnames = \"$sysnames\"
    134      1.16   thorpej 	sysprotos = \"$sysprotos\"
    135      1.11       cgd 	sysnumhdr = \"$sysnumhdr\"
    136      1.11       cgd 	sysarghdr = \"$sysarghdr\"
    137  1.69.2.3      yamt 	sysarghdrextra = \"$sysarghdrextra\"
    138      1.66     pooka 	rumpcalls = \"$rumpcalls\"
    139      1.66     pooka 	rumpcallshdr = \"$rumpcallshdr\"
    140  1.69.2.1      yamt 	rumpsysent = \"$rumpsysent\"
    141      1.11       cgd 	switchname = \"$switchname\"
    142      1.11       cgd 	namesname = \"$namesname\"
    143      1.11       cgd 	constprefix = \"$constprefix\"
    144      1.30       eeh 	registertype = \"$registertype\"
    145      1.68  christos 	sysalign=\"$sysalign\"
    146      1.30       eeh 	if (!registertype) {
    147      1.30       eeh 	    registertype = \"register_t\"
    148      1.30       eeh 	}
    149      1.40   mycroft 	nsysent = \"$nsysent\"
    150      1.11       cgd 
    151      1.11       cgd 	sysdcl = \"$sysdcl\"
    152      1.11       cgd 	syscompat_pref = \"$syscompat_pref\"
    153      1.11       cgd 	sysent = \"$sysent\"
    154      1.27   thorpej 	sysnamesbottom = \"$sysnamesbottom\"
    155      1.46  jdolecek 	sys_nosys = \"$sys_nosys\"
    156      1.60       dsl 	maxsysargs = \"$maxsysargs\"
    157      1.11       cgd 	infile = \"$2\"
    158      1.11       cgd 
    159      1.11       cgd 	compatopts = \"$compatopts\"
    160      1.11       cgd 	"'
    161      1.11       cgd 
    162  1.69.2.1      yamt 	printf "/* %s */\n\n", tag > sysdcl
    163      1.11       cgd 	printf "/*\n * System call switch table.\n *\n" > sysdcl
    164      1.11       cgd 	printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysdcl
    165      1.11       cgd 
    166      1.11       cgd 	ncompat = split(compatopts,compat)
    167      1.11       cgd 	for (i = 1; i <= ncompat; i++) {
    168      1.11       cgd 		compat_upper[i] = toupper(compat[i])
    169      1.11       cgd 
    170      1.17   mycroft 		printf "\n#ifdef %s\n", compat_upper[i] > sysent
    171      1.47     lukem 		printf "#define	%s(func) __CONCAT(%s_,func)\n", compat[i], \
    172      1.17   mycroft 		    compat[i] > sysent
    173      1.17   mycroft 		printf "#else\n" > sysent
    174      1.47     lukem 		printf "#define	%s(func) %s\n", compat[i], sys_nosys > sysent
    175      1.17   mycroft 		printf "#endif\n" > sysent
    176      1.11       cgd 	}
    177      1.11       cgd 
    178      1.60       dsl 	printf "\n#define\ts(type)\tsizeof(type)\n" > sysent
    179      1.60       dsl 	printf "#define\tn(type)\t(sizeof(type)/sizeof (%s))\n", registertype > sysent
    180      1.60       dsl 	printf "#define\tns(type)\tn(type), s(type)\n\n", registertype > sysent
    181      1.17   mycroft 	printf "struct sysent %s[] = {\n",switchname > sysent
    182      1.17   mycroft 
    183  1.69.2.1      yamt 	printf "/* %s */\n\n", tag > sysnames
    184      1.11       cgd 	printf "/*\n * System call names.\n *\n" > sysnames
    185      1.11       cgd 	printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysnames
    186      1.11       cgd 
    187      1.16   thorpej 	printf "\n/*\n * System call prototypes.\n */\n\n" > sysprotos
    188      1.16   thorpej 
    189  1.69.2.1      yamt 	printf "/* %s */\n\n", tag > sysnumhdr
    190      1.11       cgd 	printf "/*\n * System call numbers.\n *\n" > sysnumhdr
    191      1.11       cgd 	printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysnumhdr
    192      1.11       cgd 
    193  1.69.2.1      yamt 	printf "/* %s */\n\n", tag > sysarghdr
    194      1.13   mycroft 	printf "/*\n * System call argument lists.\n *\n" > sysarghdr
    195      1.11       cgd 	printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysarghdr
    196      1.66     pooka 
    197  1.69.2.1      yamt 	printf "/* %s */\n\n", tag > rumpcalls
    198  1.69.2.1      yamt 	printf "/*\n * System call vector and marshalling for rump.\n *\n" > rumpcalls
    199      1.66     pooka 	printf " * DO NOT EDIT-- this file is automatically generated.\n" > rumpcalls
    200      1.66     pooka 
    201  1.69.2.1      yamt 	printf "/* %s */\n\n", tag > rumpcallshdr
    202      1.66     pooka 	printf "/*\n * System call protos in rump namespace.\n *\n" > rumpcallshdr
    203      1.66     pooka 	printf " * DO NOT EDIT-- this file is automatically generated.\n" > rumpcallshdr
    204      1.11       cgd }
    205      1.11       cgd NR == 1 {
    206      1.58     perry 	sub(/ $/, "")
    207      1.11       cgd 	printf " * created from%s\n */\n\n", $0 > sysdcl
    208  1.69.2.1      yamt 	printf "#include <sys/cdefs.h>\n__KERNEL_RCSID(0, \"%s\");\n\n", tag > sysdcl
    209      1.11       cgd 
    210      1.11       cgd 	printf " * created from%s\n */\n\n", $0 > sysnames
    211  1.69.2.1      yamt 	printf "#include <sys/cdefs.h>\n__KERNEL_RCSID(0, \"%s\");\n\n", tag > sysnames
    212      1.28   thorpej 
    213      1.66     pooka 	printf " * created from%s\n */\n\n", $0 > rumpcalls
    214  1.69.2.1      yamt 	printf "#include <sys/cdefs.h>\n__KERNEL_RCSID(0, \"%s\");\n\n", tag > rumpcalls
    215      1.66     pooka 	printf "#include <sys/types.h>\n" > rumpcalls
    216      1.66     pooka 	printf "#include <sys/param.h>\n" > rumpcalls
    217      1.66     pooka 	printf "#include <sys/proc.h>\n" > rumpcalls
    218  1.69.2.1      yamt 	printf "#include <sys/syscall.h>\n" > rumpcalls
    219      1.66     pooka 	printf "#include <sys/syscallargs.h>\n" > rumpcalls
    220  1.69.2.1      yamt 	printf "#include <rump/rumpuser.h>\n" > rumpcalls
    221  1.69.2.1      yamt 	printf "#include \"rump_private.h\"\n\n" > rumpcalls
    222      1.66     pooka 	printf "#if\tBYTE_ORDER == BIG_ENDIAN\n" > rumpcalls
    223      1.66     pooka 	printf "#define SPARG(p,k)\t((p)->k.be.datum)\n" > rumpcalls
    224      1.66     pooka 	printf "#else /* LITTLE_ENDIAN, I hope dearly */\n" > rumpcalls
    225      1.66     pooka 	printf "#define SPARG(p,k)\t((p)->k.le.datum)\n" > rumpcalls
    226      1.66     pooka 	printf "#endif\n\n" > rumpcalls
    227  1.69.2.1      yamt 	printf "int rump_enosys(void);\n" > rumpcalls
    228  1.69.2.1      yamt 	printf "int\nrump_enosys()\n{\n\n\treturn ENOSYS;\n}\n" > rumpcalls
    229  1.69.2.1      yamt 
    230  1.69.2.1      yamt 	printf "\n#define\ts(type)\tsizeof(type)\n" > rumpsysent
    231  1.69.2.1      yamt 	printf "#define\tn(type)\t(sizeof(type)/sizeof (%s))\n", registertype > rumpsysent
    232  1.69.2.1      yamt 	printf "#define\tns(type)\tn(type), s(type)\n\n", registertype > rumpsysent
    233  1.69.2.1      yamt 	printf "struct sysent rump_sysent[] = {\n" > rumpsysent
    234      1.66     pooka 
    235      1.28   thorpej 	# System call names are included by userland (kdump(1)), so
    236      1.28   thorpej 	# hide the include files from it.
    237      1.48       mrg 	printf "#if defined(_KERNEL_OPT)\n" > sysnames
    238      1.28   thorpej 
    239      1.48       mrg 	printf "#endif /* _KERNEL_OPT */\n\n" > sysnamesbottom
    240      1.41   mycroft 	printf "const char *const %s[] = {\n",namesname > sysnamesbottom
    241      1.11       cgd 
    242      1.11       cgd 	printf " * created from%s\n */\n\n", $0 > sysnumhdr
    243  1.69.2.4      yamt 	printf "#ifndef _" constprefix "SYSCALL_H_\n" > sysnumhdr
    244  1.69.2.4      yamt 	printf "#define	_" constprefix "SYSCALL_H_\n\n" > sysnumhdr
    245      1.11       cgd 
    246      1.11       cgd 	printf " * created from%s\n */\n\n", $0 > sysarghdr
    247  1.69.2.4      yamt 	printf "#ifndef _" constprefix "SYSCALLARGS_H_\n" > sysarghdr
    248  1.69.2.4      yamt 	printf "#define	_" constprefix "SYSCALLARGS_H_\n\n" > sysarghdr
    249      1.66     pooka 
    250      1.66     pooka 	printf " * created from%s\n */\n\n", $0 > rumpcallshdr
    251  1.69.2.4      yamt 	printf "#ifndef _RUMP_RUMP_SYSCALLS_H_\n" > rumpcallshdr
    252  1.69.2.4      yamt 	printf "#define _RUMP_RUMP_SYSCALLS_H_\n\n" > rumpcallshdr
    253  1.69.2.4      yamt 	printf "#ifdef _KERNEL\n" > rumpcallshdr
    254  1.69.2.4      yamt 	printf "#error Interface not supported inside kernel\n" > rumpcallshdr
    255  1.69.2.4      yamt 	printf "#endif /* _KERNEL */\n\n" > rumpcallshdr
    256  1.69.2.1      yamt 	printf "#include <sys/types.h>\n" > rumpcallshdr
    257  1.69.2.1      yamt 	printf "#include <sys/select.h>\n\n" > rumpcallshdr
    258  1.69.2.1      yamt 	printf "#include <signal.h>\n\n" > rumpcallshdr
    259      1.66     pooka 
    260  1.69.2.3      yamt 	printf "%s", sysarghdrextra > sysarghdr
    261      1.60       dsl 	# Write max number of system call arguments to both headers
    262      1.60       dsl 	printf("#define\t%sMAXSYSARGS\t%d\n\n", constprefix, maxsysargs) \
    263      1.60       dsl 		> sysnumhdr
    264      1.60       dsl 	printf("#define\t%sMAXSYSARGS\t%d\n\n", constprefix, maxsysargs) \
    265      1.60       dsl 		> sysarghdr
    266      1.30       eeh 	printf "#undef\tsyscallarg\n" > sysarghdr
    267      1.35   thorpej 	printf "#define\tsyscallarg(x)\t\t\t\t\t\t\t\\\n" > sysarghdr
    268      1.35   thorpej 	printf "\tunion {\t\t\t\t\t\t\t\t\\\n" > sysarghdr
    269      1.35   thorpej 	printf "\t\t%s pad;\t\t\t\t\t\t\\\n", registertype > sysarghdr
    270      1.35   thorpej 	printf "\t\tstruct { x datum; } le;\t\t\t\t\t\\\n" > sysarghdr
    271      1.51      manu 	printf "\t\tstruct { /* LINTED zero array dimension */\t\t\\\n" \
    272      1.51      manu 		> sysarghdr
    273      1.51      manu 	printf "\t\t\tint8_t pad[  /* CONSTCOND */\t\t\t\\\n" > sysarghdr
    274      1.51      manu 	printf "\t\t\t\t(sizeof (%s) < sizeof (x))\t\\\n", \
    275      1.30       eeh 		registertype > sysarghdr
    276      1.35   thorpej 	printf "\t\t\t\t? 0\t\t\t\t\t\\\n" > sysarghdr
    277      1.35   thorpej 	printf "\t\t\t\t: sizeof (%s) - sizeof (x)];\t\\\n", \
    278      1.30       eeh 		registertype > sysarghdr
    279      1.35   thorpej 	printf "\t\t\tx datum;\t\t\t\t\t\\\n" > sysarghdr
    280      1.35   thorpej 	printf "\t\t} be;\t\t\t\t\t\t\t\\\n" > sysarghdr
    281      1.35   thorpej 	printf "\t}\n" > sysarghdr
    282      1.60       dsl 	printf("\n#undef check_syscall_args\n") >sysarghdr
    283      1.60       dsl 	printf("#define check_syscall_args(call) \\\n" \
    284      1.60       dsl 		"\ttypedef char call##_check_args" \
    285      1.60       dsl 		    "[sizeof (struct call##_args) \\\n" \
    286      1.60       dsl 		"\t\t<= %sMAXSYSARGS * sizeof (%s) ? 1 : -1];\n", \
    287      1.60       dsl 		constprefix, registertype) >sysarghdr
    288      1.11       cgd 	next
    289      1.11       cgd }
    290      1.11       cgd NF == 0 || $1 ~ /^;/ {
    291      1.11       cgd 	next
    292      1.11       cgd }
    293      1.40   mycroft $0 ~ /^%%$/ {
    294      1.40   mycroft 	intable = 1
    295      1.40   mycroft 	next
    296      1.40   mycroft }
    297      1.11       cgd $1 ~ /^#[ 	]*include/ {
    298      1.11       cgd 	print > sysdcl
    299      1.27   thorpej 	print > sysnames
    300      1.11       cgd 	next
    301      1.11       cgd }
    302      1.40   mycroft $1 ~ /^#/ && !intable {
    303      1.40   mycroft 	print > sysdcl
    304      1.40   mycroft 	print > sysnames
    305      1.11       cgd 	next
    306      1.11       cgd }
    307      1.40   mycroft $1 ~ /^#/ && intable {
    308      1.40   mycroft 	if ($1 ~ /^#[ 	]*if/) {
    309      1.40   mycroft 		savedepth++
    310      1.40   mycroft 		savesyscall[savedepth] = syscall
    311      1.40   mycroft 	}
    312      1.40   mycroft 	if ($1 ~ /^#[ 	]*else/) {
    313      1.40   mycroft 		if (savedepth <= 0) {
    314      1.40   mycroft 			printf("%s: line %d: unbalanced #else\n", \
    315      1.40   mycroft 			    infile, NR)
    316      1.40   mycroft 			exit 1
    317      1.40   mycroft 		}
    318      1.40   mycroft 		syscall = savesyscall[savedepth]
    319      1.18       cgd 	}
    320      1.18       cgd 	if ($1 ~ /^#[       ]*endif/) {
    321      1.18       cgd 		if (savedepth <= 0) {
    322      1.40   mycroft 			printf("%s: line %d: unbalanced #endif\n", \
    323      1.40   mycroft 			    infile, NR)
    324      1.18       cgd 			exit 1
    325      1.18       cgd 		}
    326      1.40   mycroft 		savedepth--
    327      1.18       cgd 	}
    328      1.11       cgd 	print > sysent
    329      1.54  christos 	print > sysarghdr
    330      1.54  christos 	print > sysnumhdr
    331      1.16   thorpej 	print > sysprotos
    332      1.27   thorpej 	print > sysnamesbottom
    333  1.69.2.1      yamt 
    334  1.69.2.1      yamt 	# XXX: technically we do not want to have conditionals in rump,
    335  1.69.2.1      yamt 	# but it is easier to just let the cpp handle them than try to
    336  1.69.2.1      yamt 	# figure out what we want here in this script
    337  1.69.2.1      yamt 	print > rumpsysent
    338      1.11       cgd 	next
    339      1.11       cgd }
    340      1.11       cgd syscall != $1 {
    341      1.11       cgd 	printf "%s: line %d: syscall number out of sync at %d\n", \
    342      1.11       cgd 	   infile, NR, syscall
    343      1.11       cgd 	printf "line is:\n"
    344      1.11       cgd 	print
    345      1.11       cgd 	exit 1
    346      1.11       cgd }
    347      1.11       cgd function parserr(was, wanted) {
    348  1.69.2.1      yamt 	printf "%s: line %d: unexpected %s (expected <%s>)\n", \
    349      1.11       cgd 	    infile, NR, was, wanted
    350      1.32  christos 	printf "line is:\n"
    351      1.32  christos 	print
    352      1.11       cgd 	exit 1
    353      1.11       cgd }
    354      1.11       cgd function parseline() {
    355      1.11       cgd 	f=3			# toss number and type
    356      1.60       dsl 	if ($2 == "INDIR")
    357      1.60       dsl 		sycall_flags="SYCALL_INDIRECT"
    358      1.60       dsl 	else
    359      1.60       dsl 		sycall_flags="0"
    360      1.11       cgd 	if ($NF != "}") {
    361      1.11       cgd 		funcalias=$NF
    362      1.11       cgd 		end=NF-1
    363      1.11       cgd 	} else {
    364      1.11       cgd 		funcalias=""
    365      1.11       cgd 		end=NF
    366      1.43  jdolecek 	}
    367      1.61       dsl 	if ($f == "INDIR") {		# allow for "NOARG INDIR"
    368      1.61       dsl 		sycall_flags = "SYCALL_INDIRECT | " sycall_flags
    369      1.61       dsl 		f++
    370      1.61       dsl 	}
    371  1.69.2.1      yamt 	if ($f == "MODULAR") {		# registered at runtime
    372  1.69.2.1      yamt 		modular = 1
    373  1.69.2.1      yamt 		f++
    374  1.69.2.1      yamt 	} else {
    375  1.69.2.1      yamt 		modular =  0;
    376  1.69.2.1      yamt 	}
    377      1.66     pooka 	if ($f == "RUMP") {
    378      1.66     pooka 		rumpable = 1
    379      1.66     pooka 		f++
    380      1.66     pooka 	} else {
    381      1.66     pooka 		rumpable = 0
    382      1.66     pooka 	}
    383      1.43  jdolecek 	if ($f ~ /^[a-z0-9_]*$/) {	# allow syscall alias
    384      1.43  jdolecek 		funcalias=$f
    385      1.43  jdolecek 		f++
    386      1.11       cgd 	}
    387      1.11       cgd 	if ($f != "{")
    388      1.11       cgd 		parserr($f, "{")
    389      1.11       cgd 	f++
    390      1.11       cgd 	if ($end != "}")
    391      1.11       cgd 		parserr($end, "}")
    392      1.11       cgd 	end--
    393      1.11       cgd 	if ($end != ";")
    394      1.11       cgd 		parserr($end, ";")
    395      1.11       cgd 	end--
    396      1.11       cgd 	if ($end != ")")
    397      1.11       cgd 		parserr($end, ")")
    398      1.11       cgd 	end--
    399      1.11       cgd 
    400      1.19       cgd 	returntype = oldf = "";
    401      1.19       cgd 	do {
    402      1.19       cgd 		if (returntype != "" && oldf != "*")
    403      1.19       cgd 			returntype = returntype" ";
    404      1.19       cgd 		returntype = returntype$f;
    405      1.19       cgd 		oldf = $f;
    406      1.19       cgd 		f++
    407  1.69.2.1      yamt 	} while ($f != "|" && f < (end-1))
    408      1.19       cgd 	if (f == (end - 1)) {
    409  1.69.2.1      yamt 		parserr($f, "function argument definition (maybe \"|\"?)");
    410  1.69.2.1      yamt 	}
    411  1.69.2.1      yamt 	f++
    412  1.69.2.1      yamt 
    413  1.69.2.1      yamt 	fprefix=$f
    414  1.69.2.1      yamt 	f++
    415  1.69.2.1      yamt 	if ($f != "|") {
    416  1.69.2.1      yamt 		parserr($f, "function compat delimiter (maybe \"|\"?)");
    417  1.69.2.1      yamt 	}
    418  1.69.2.1      yamt 	f++
    419  1.69.2.1      yamt 
    420  1.69.2.1      yamt 	fcompat=""
    421  1.69.2.1      yamt 	if ($f != "|") {
    422  1.69.2.1      yamt 		fcompat=$f
    423  1.69.2.1      yamt 		f++
    424  1.69.2.1      yamt 	}
    425  1.69.2.1      yamt 
    426  1.69.2.1      yamt 	if ($f != "|") {
    427  1.69.2.1      yamt 		parserr($f, "function name delimiter (maybe \"|\"?)");
    428  1.69.2.1      yamt 	}
    429  1.69.2.1      yamt 	f++
    430  1.69.2.1      yamt 	fbase=$f
    431  1.69.2.1      yamt 
    432  1.69.2.3      yamt 	# pipe is special in how to returns its values.
    433  1.69.2.3      yamt 	# So just generate it manually if present.
    434  1.69.2.3      yamt 	if (rumpable == 1 && fbase == "pipe") {
    435  1.69.2.3      yamt 		rumpable = 0;
    436  1.69.2.3      yamt 		rumphaspipe = 1;
    437  1.69.2.3      yamt 	}
    438  1.69.2.3      yamt 
    439  1.69.2.1      yamt 	funcstdname=fprefix "_" fbase
    440  1.69.2.1      yamt 	if (fcompat != "") {
    441  1.69.2.1      yamt 		funcname=fprefix "___" fbase "" fcompat
    442  1.69.2.1      yamt 		wantrename=1
    443  1.69.2.1      yamt 	} else {
    444  1.69.2.1      yamt 		funcname=funcstdname
    445  1.69.2.1      yamt 		wantrename=0
    446      1.19       cgd 	}
    447  1.69.2.3      yamt 	if (returntype == "quad_t" || returntype == "off_t") {
    448  1.69.2.3      yamt 		if (sycall_flags == "0")
    449  1.69.2.3      yamt 			sycall_flags = "SYCALL_RET_64";
    450  1.69.2.3      yamt 		else
    451  1.69.2.3      yamt 			sycall_flags = "SYCALL_RET_64 | " sycall_flags;
    452  1.69.2.3      yamt 	}
    453      1.11       cgd 
    454      1.17   mycroft 	if (funcalias == "") {
    455      1.11       cgd 		funcalias=funcname
    456      1.17   mycroft 		sub(/^([^_]+_)*sys_/, "", funcalias)
    457      1.17   mycroft 	}
    458      1.11       cgd 	f++
    459      1.11       cgd 
    460      1.11       cgd 	if ($f != "(")
    461  1.69.2.1      yamt 		parserr($f, "(")
    462      1.11       cgd 	f++
    463      1.11       cgd 
    464      1.19       cgd 	argc=0;
    465      1.63      yamt 	argalign=0;
    466      1.11       cgd 	if (f == end) {
    467      1.11       cgd 		if ($f != "void")
    468      1.11       cgd 			parserr($f, "argument definition")
    469      1.19       cgd 		isvarargs = 0;
    470      1.19       cgd 		varargc = 0;
    471  1.69.2.1      yamt 		argtype[0]="void";
    472      1.11       cgd 		return
    473      1.11       cgd 	}
    474      1.11       cgd 
    475      1.19       cgd 	# some system calls (open() and fcntl()) can accept a variable
    476      1.19       cgd 	# number of arguments.  If syscalls accept a variable number of
    477      1.19       cgd 	# arguments, they must still have arguments specified for
    478      1.19       cgd 	# the remaining argument "positions," because of the way the
    479      1.19       cgd 	# kernel system call argument handling works.
    480      1.19       cgd 	#
    481      1.19       cgd 	# Indirect system calls, e.g. syscall(), are exceptions to this
    482      1.19       cgd 	# rule, since they are handled entirely by machine-dependent code
    483      1.19       cgd 	# and do not need argument structures built.
    484      1.19       cgd 
    485      1.19       cgd 	isvarargs = 0;
    486  1.69.2.3      yamt 	args64 = 0;
    487      1.11       cgd 	while (f <= end) {
    488      1.19       cgd 		if ($f == "...") {
    489      1.19       cgd 			f++;
    490      1.19       cgd 			isvarargs = 1;
    491      1.19       cgd 			varargc = argc;
    492      1.19       cgd 			continue;
    493      1.19       cgd 		}
    494      1.11       cgd 		argc++
    495      1.11       cgd 		argtype[argc]=""
    496      1.14       cgd 		oldf=""
    497      1.11       cgd 		while (f < end && $(f+1) != ",") {
    498      1.14       cgd 			if (argtype[argc] != "" && oldf != "*")
    499      1.11       cgd 				argtype[argc] = argtype[argc]" ";
    500      1.11       cgd 			argtype[argc] = argtype[argc]$f;
    501      1.14       cgd 			oldf = $f;
    502      1.11       cgd 			f++
    503      1.11       cgd 		}
    504      1.11       cgd 		if (argtype[argc] == "")
    505      1.11       cgd 			parserr($f, "argument definition")
    506  1.69.2.2      yamt 		if (argtype[argc] == "off_t"  \
    507  1.69.2.2      yamt 		  || argtype[argc] == "dev_t" \
    508  1.69.2.2      yamt 		  || argtype[argc] == "time_t") {
    509      1.68  christos 			if ((argalign % 2) != 0 && sysalign &&
    510      1.63      yamt 			    funcname != "sys_posix_fadvise") # XXX for now
    511      1.63      yamt 				parserr($f, "a padding argument")
    512      1.63      yamt 		} else {
    513      1.63      yamt 			argalign++;
    514      1.63      yamt 		}
    515  1.69.2.3      yamt 		if (argtype[argc] == "quad_t" || argtype[argc] == "off_t" \
    516  1.69.2.3      yamt 		  || argtype[argc] == "dev_t" || argtype[argc] == "time_t") {
    517  1.69.2.3      yamt 			if (sycall_flags == "0")
    518  1.69.2.3      yamt 				sycall_flags = "SYCALL_ARG"argc-1"_64";
    519  1.69.2.3      yamt 			else
    520  1.69.2.3      yamt 				sycall_flags = "SYCALL_ARG"argc-1"_64 | " sycall_flags;
    521  1.69.2.3      yamt 			args64++;
    522  1.69.2.3      yamt 		}
    523      1.11       cgd 		argname[argc]=$f;
    524      1.11       cgd 		f += 2;			# skip name, and any comma
    525      1.11       cgd 	}
    526  1.69.2.3      yamt 	if (args64 > 0)
    527  1.69.2.3      yamt 		sycall_flags = "SYCALL_NARGS64_VAL("args64") | " sycall_flags;
    528      1.19       cgd 	# must see another argument after varargs notice.
    529      1.19       cgd 	if (isvarargs) {
    530      1.61       dsl 		if (argc == varargc)
    531      1.19       cgd 			parserr($f, "argument definition")
    532      1.19       cgd 	} else
    533      1.19       cgd 		varargc = argc;
    534      1.11       cgd }
    535      1.54  christos 
    536      1.54  christos function printproto(wrap) {
    537      1.54  christos 	printf("/* syscall: \"%s%s\" ret: \"%s\" args:", wrap, funcalias,
    538      1.54  christos 	    returntype) > sysnumhdr
    539      1.54  christos 	for (i = 1; i <= varargc; i++)
    540      1.54  christos 		printf(" \"%s\"", argtype[i]) > sysnumhdr
    541      1.54  christos 	if (isvarargs)
    542      1.54  christos 		printf(" \"...\"") > sysnumhdr
    543      1.54  christos 	printf(" */\n") > sysnumhdr
    544      1.54  christos 	printf("#define\t%s%s%s\t%d\n\n", constprefix, wrap, funcalias,
    545      1.54  christos 	    syscall) > sysnumhdr
    546      1.66     pooka 
    547      1.66     pooka 	# rumpalooza
    548      1.66     pooka 	if (!rumpable)
    549      1.66     pooka 		return
    550      1.66     pooka 
    551  1.69.2.5      yamt 	if (wantrename)
    552  1.69.2.5      yamt 		printf("%s rump_%s(", returntype, funcstdname) > rumpcallshdr
    553  1.69.2.5      yamt 	else
    554  1.69.2.5      yamt 		printf("%s rump_sys_%s(", returntype, funcalias) > rumpcallshdr
    555  1.69.2.3      yamt 	for (i = 1; i < varargc; i++)
    556  1.69.2.2      yamt 		if (argname[i] != "PAD")
    557  1.69.2.2      yamt 			printf("%s, ", argtype[i]) > rumpcallshdr
    558  1.69.2.3      yamt 	if (isvarargs)
    559  1.69.2.3      yamt 		printf("%s, ...)", argtype[varargc]) > rumpcallshdr
    560  1.69.2.3      yamt 	else
    561  1.69.2.3      yamt 		printf("%s)", argtype[argc]) > rumpcallshdr
    562  1.69.2.1      yamt 	if (wantrename)
    563  1.69.2.1      yamt 		printf(" __RENAME(rump_%s)", funcname) > rumpcallshdr
    564  1.69.2.1      yamt 	printf(";\n") > rumpcallshdr
    565      1.54  christos }
    566      1.54  christos 
    567  1.69.2.3      yamt function printrumpsysent(insysent, compatwrap) {
    568  1.69.2.3      yamt 	if (!insysent) {
    569  1.69.2.4      yamt 		eno[0] = "rump_enosys"
    570  1.69.2.4      yamt 		eno[1] = "sys_nomodule"
    571  1.69.2.4      yamt 		printf("\t{ 0, 0, 0,\n\t    (sy_call_t *)%s },\t\t\t"	\
    572  1.69.2.4      yamt 		    "/* %d = unrumped */\n",				\
    573  1.69.2.4      yamt 		    eno[modular], syscall) > rumpsysent
    574  1.69.2.3      yamt 		return
    575  1.69.2.3      yamt 	}
    576  1.69.2.3      yamt 
    577  1.69.2.3      yamt 	printf("\t{ ") > rumpsysent
    578  1.69.2.3      yamt 	if (argc == 0) {
    579  1.69.2.3      yamt 		printf("0, 0, ") > rumpsysent
    580  1.69.2.3      yamt 	} else {
    581  1.69.2.5      yamt 		printf("ns(struct sys_%s%s_args), ", compatwrap_, funcalias) > rumpsysent
    582  1.69.2.3      yamt 	}
    583  1.69.2.3      yamt 	printf("0,\n\t    %s },", wfn) > rumpsysent
    584  1.69.2.3      yamt 	for (i = 0; i < (41 - length(wfn)) / 8; i++)
    585  1.69.2.3      yamt 		printf("\t") > rumpsysent
    586  1.69.2.3      yamt 	printf("/* %d = %s%s */\n", syscall, compatwrap_, funcalias) > rumpsysent
    587  1.69.2.3      yamt }
    588  1.69.2.3      yamt 
    589      1.61       dsl function putent(type, compatwrap) {
    590      1.60       dsl 	# output syscall declaration for switch table.
    591      1.60       dsl 	if (compatwrap == "")
    592      1.60       dsl 		compatwrap_ = ""
    593      1.60       dsl 	else
    594      1.60       dsl 		compatwrap_ = compatwrap "_"
    595      1.62       dsl 	if (argc == 0)
    596      1.62       dsl 		arg_type = "void";
    597      1.62       dsl 	else {
    598      1.62       dsl 		arg_type = "struct " compatwrap_ funcname "_args";
    599      1.62       dsl 	}
    600      1.62       dsl 	proto = "int\t" compatwrap_ funcname "(struct lwp *, const " \
    601      1.62       dsl 	    arg_type " *, register_t *);\n"
    602      1.60       dsl 	if (sysmap[proto] != 1) {
    603      1.60       dsl 		sysmap[proto] = 1;
    604      1.60       dsl 		print proto > sysprotos;
    605      1.21       cgd 	}
    606      1.11       cgd 
    607      1.11       cgd 	# output syscall switch entry
    608      1.60       dsl 	printf("\t{ ") > sysent
    609      1.60       dsl 	if (argc == 0) {
    610      1.60       dsl 		printf("0, 0, ") > sysent
    611      1.19       cgd 	} else {
    612      1.60       dsl 		printf("ns(struct %s%s_args), ", compatwrap_, funcname) > sysent
    613      1.19       cgd 	}
    614  1.69.2.1      yamt 	if (modular) 
    615  1.69.2.1      yamt 		wfn = "(sy_call_t *)sys_nomodule";
    616  1.69.2.1      yamt 	else if (compatwrap == "")
    617      1.62       dsl 		wfn = "(sy_call_t *)" funcname;
    618      1.60       dsl 	else
    619      1.62       dsl 		wfn = "(sy_call_t *)" compatwrap "(" funcname ")";
    620      1.60       dsl 	printf("%s,\n\t    %s },", sycall_flags, wfn) > sysent
    621      1.60       dsl 	for (i = 0; i < (33 - length(wfn)) / 8; i++)
    622      1.60       dsl 		printf("\t") > sysent
    623      1.60       dsl 	printf("/* %d = %s%s */\n", syscall, compatwrap_, funcalias) > sysent
    624      1.11       cgd 
    625      1.11       cgd 	# output syscall name for names table
    626      1.60       dsl 	printf("\t/* %3d */\t\"%s%s\",\n", syscall, compatwrap_, funcalias) \
    627      1.60       dsl 	    > sysnamesbottom
    628      1.11       cgd 
    629      1.11       cgd 	# output syscall number of header, if appropriate
    630      1.61       dsl 	if (type == "STD" || type == "NOARGS" || type == "INDIR") {
    631      1.19       cgd 		# output a prototype, to be used to generate lint stubs in
    632      1.19       cgd 		# libc.
    633      1.54  christos 		printproto("")
    634      1.61       dsl 	} else if (type == "COMPAT") {
    635      1.29   thorpej 		# Just define the syscall number with a comment.  These
    636      1.29   thorpej 		# may be used by compatibility stubs in libc.
    637      1.60       dsl 		printproto(compatwrap_)
    638      1.60       dsl 	}
    639      1.11       cgd 
    640      1.11       cgd 	# output syscall argument structure, if it has arguments
    641      1.62       dsl 	if (argc != 0) {
    642      1.62       dsl 		printf("\nstruct %s%s_args", compatwrap_, funcname) > sysarghdr
    643      1.62       dsl 		if (type != "NOARGS") {
    644      1.62       dsl 			print " {" >sysarghdr;
    645      1.62       dsl 			for (i = 1; i <= argc; i++)
    646      1.62       dsl 				printf("\tsyscallarg(%s) %s;\n", argtype[i],
    647      1.62       dsl 				    argname[i]) > sysarghdr
    648      1.62       dsl 			printf "}" >sysarghdr;
    649      1.62       dsl 		}
    650      1.62       dsl 		printf(";\n") > sysarghdr
    651      1.62       dsl 		if (type != "NOARGS" && type != "INDIR") {
    652      1.60       dsl 			printf("check_syscall_args(%s%s)\n", compatwrap_,
    653      1.60       dsl 			    funcname) >sysarghdr
    654      1.60       dsl 		}
    655      1.11       cgd 	}
    656      1.66     pooka 
    657  1.69.2.3      yamt 	if (!rumpable) {
    658  1.69.2.3      yamt 		if (funcname == "sys_pipe" && rumphaspipe == 1)
    659  1.69.2.3      yamt 			insysent = 1
    660  1.69.2.3      yamt 		else
    661  1.69.2.3      yamt 			insysent = 0
    662  1.69.2.3      yamt 	} else {
    663  1.69.2.3      yamt 		insysent = 1
    664  1.69.2.3      yamt 	}
    665  1.69.2.3      yamt 	printrumpsysent(insysent, compatwrap)
    666  1.69.2.3      yamt 
    667      1.66     pooka 	# output rump marshalling code if necessary
    668  1.69.2.1      yamt 	if (!rumpable) {
    669      1.66     pooka 		return
    670  1.69.2.1      yamt 	}
    671  1.69.2.1      yamt 
    672  1.69.2.1      yamt 	# need a local prototype, we export the re-re-named one in .h
    673  1.69.2.5      yamt 	printf("\n%s rump_sys_%s(", returntype, funcalias) > rumpcalls
    674  1.69.2.1      yamt 	for (i = 1; i < argc; i++) {
    675  1.69.2.2      yamt 		if (argname[i] != "PAD")
    676  1.69.2.2      yamt 			printf("%s, ", argtype[i]) > rumpcalls
    677  1.69.2.1      yamt 	}
    678  1.69.2.1      yamt 	printf("%s);", argtype[argc]) > rumpcalls
    679      1.66     pooka 
    680  1.69.2.5      yamt 	printf("\n%s\nrump_sys_%s(", returntype, funcalias) > rumpcalls
    681  1.69.2.1      yamt 	for (i = 1; i < argc; i++) {
    682  1.69.2.2      yamt 		if (argname[i] != "PAD")
    683  1.69.2.2      yamt 			printf("%s %s, ", argtype[i], argname[i]) > rumpcalls
    684      1.66     pooka 	}
    685  1.69.2.1      yamt 	printf("%s %s)\n", argtype[argc], argname[argc]) > rumpcalls
    686  1.69.2.3      yamt 	printf("{\n\tregister_t rval[2] = {0, 0};\n\tint error = 0;\n") \
    687  1.69.2.3      yamt 	    > rumpcalls
    688  1.69.2.1      yamt 
    689      1.66     pooka 	argarg = "NULL"
    690  1.69.2.1      yamt 	argsize = 0;
    691      1.66     pooka 	if (argc) {
    692  1.69.2.1      yamt 		argarg = "&callarg"
    693  1.69.2.1      yamt 		argsize = "sizeof(callarg)"
    694  1.69.2.1      yamt 		printf("\tstruct %s%s_args callarg;\n\n",compatwrap_,funcname) \
    695      1.66     pooka 		    > rumpcalls
    696      1.66     pooka 		for (i = 1; i <= argc; i++) {
    697  1.69.2.2      yamt 			if (argname[i] == "PAD") {
    698  1.69.2.2      yamt 				printf("\tSPARG(&callarg, %s) = 0;\n", \
    699  1.69.2.2      yamt 				    argname[i]) > rumpcalls
    700  1.69.2.2      yamt 			} else {
    701  1.69.2.2      yamt 				printf("\tSPARG(&callarg, %s) = %s;\n", \
    702  1.69.2.2      yamt 				    argname[i], argname[i]) > rumpcalls
    703  1.69.2.2      yamt 			}
    704      1.66     pooka 		}
    705      1.66     pooka 		printf("\n") > rumpcalls
    706      1.66     pooka 	} else {
    707      1.66     pooka 		printf("\n") > rumpcalls
    708      1.66     pooka 	}
    709  1.69.2.1      yamt 	printf("\terror = rump_sysproxy(%s%s, rump_sysproxy_arg,\n\t" \
    710  1.69.2.3      yamt 	    "    (uint8_t *)%s, %s, rval);\n", constprefix, funcalias, \
    711  1.69.2.1      yamt 	    argarg, argsize) > rumpcalls
    712  1.69.2.3      yamt 	printf("\tif (error) {\n\t\trval[0] = -1;\n") > rumpcalls
    713  1.69.2.1      yamt 	if (returntype != "void") {
    714  1.69.2.1      yamt 		printf("\t\trumpuser_seterrno(error);\n\t}\n") > rumpcalls
    715  1.69.2.3      yamt 		printf("\treturn rval[0];\n") > rumpcalls
    716  1.69.2.1      yamt 	} else {
    717  1.69.2.1      yamt 		printf("\t}\n") > rumpcalls
    718  1.69.2.1      yamt 	}
    719  1.69.2.1      yamt 	printf("}\n") > rumpcalls
    720  1.69.2.1      yamt 	printf("__weak_alias(%s,rump_enosys);\n", funcname) > rumpcalls
    721  1.69.2.1      yamt 
    722      1.11       cgd }
    723      1.61       dsl $2 == "STD" || $2 == "NODEF" || $2 == "NOARGS" || $2 == "INDIR" {
    724      1.11       cgd 	parseline()
    725      1.17   mycroft 	putent($2, "")
    726      1.11       cgd 	syscall++
    727      1.11       cgd 	next
    728      1.11       cgd }
    729      1.64    martin $2 == "OBSOL" || $2 == "UNIMPL" || $2 == "EXCL" || $2 == "IGNORED" {
    730      1.11       cgd 	if ($2 == "OBSOL")
    731      1.11       cgd 		comment="obsolete"
    732      1.34  christos 	else if ($2 == "EXCL")
    733      1.34  christos 		comment="excluded"
    734      1.64    martin 	else if ($2 == "IGNORED")
    735      1.64    martin 		comment="ignored"
    736      1.11       cgd 	else
    737      1.11       cgd 		comment="unimplemented"
    738      1.11       cgd 	for (i = 3; i <= NF; i++)
    739      1.11       cgd 		comment=comment " " $i
    740      1.11       cgd 
    741      1.64    martin 	if ($2 == "IGNORED")
    742      1.64    martin 		sys_stub = "(sy_call_t *)nullop";
    743      1.64    martin 	else
    744      1.65     njoly 		sys_stub = sys_nosys;
    745      1.64    martin 
    746      1.46  jdolecek 	printf("\t{ 0, 0, 0,\n\t    %s },\t\t\t/* %d = %s */\n", \
    747      1.64    martin 	    sys_stub, syscall, comment) > sysent
    748  1.69.2.1      yamt 	printf("\t{ 0, 0, 0,\n\t    %s },\t\t\t/* %d = %s */\n", \
    749  1.69.2.1      yamt 	    "(sy_call_t *)rump_enosys", syscall, comment) > rumpsysent
    750      1.60       dsl 	printf("\t/* %3d */\t\"#%d (%s)\",\n", syscall, syscall, comment) \
    751      1.60       dsl 	    > sysnamesbottom
    752      1.11       cgd 	if ($2 != "UNIMPL")
    753      1.11       cgd 		printf("\t\t\t\t/* %d is %s */\n", syscall, comment) > sysnumhdr
    754      1.11       cgd 	syscall++
    755      1.11       cgd 	next
    756      1.11       cgd }
    757      1.11       cgd {
    758      1.11       cgd 	for (i = 1; i <= ncompat; i++) {
    759      1.11       cgd 		if ($2 == compat_upper[i]) {
    760      1.11       cgd 			parseline();
    761      1.29   thorpej 			putent("COMPAT", compat[i])
    762      1.11       cgd 			syscall++
    763      1.11       cgd 			next
    764      1.11       cgd 		}
    765      1.11       cgd 	}
    766      1.40   mycroft 	printf("%s: line %d: unrecognized keyword %s\n", infile, NR, $2)
    767       1.1     glass 	exit 1
    768      1.11       cgd }
    769      1.11       cgd END {
    770  1.69.2.3      yamt 	# output pipe() syscall with its special rval[2] handling
    771  1.69.2.3      yamt 	if (rumphaspipe) {
    772  1.69.2.3      yamt 		printf("int rump_sys_pipe(int *);\n") > rumpcallshdr
    773  1.69.2.3      yamt 		printf("\nint rump_sys_pipe(int *);\n") > rumpcalls
    774  1.69.2.3      yamt 		printf("int\nrump_sys_pipe(int *fd)\n{\n") > rumpcalls
    775  1.69.2.3      yamt 		printf("\tregister_t rval[2] = {0, 0};\n") > rumpcalls
    776  1.69.2.3      yamt 		printf("\tint error = 0;\n") > rumpcalls
    777  1.69.2.3      yamt 		printf("\n\terror = rump_sysproxy(SYS_pipe, ") > rumpcalls
    778  1.69.2.3      yamt 		printf("rump_sysproxy_arg, NULL, 0, rval);\n") > rumpcalls
    779  1.69.2.3      yamt 		printf("\tif (error) {\n") > rumpcalls
    780  1.69.2.3      yamt 		printf("\t\trumpuser_seterrno(error);\n") > rumpcalls
    781  1.69.2.3      yamt 		printf("\t} else {\n\t\tfd[0] = rval[0];\n") > rumpcalls
    782  1.69.2.3      yamt 		printf("\t\tfd[1] = rval[1];\n\t}\n") > rumpcalls
    783  1.69.2.3      yamt 		printf("\treturn error ? -1 : 0;\n}\n") > rumpcalls
    784  1.69.2.3      yamt 	}
    785  1.69.2.3      yamt 
    786      1.40   mycroft 	maxsyscall = syscall
    787      1.40   mycroft 	if (nsysent) {
    788      1.40   mycroft 		if (syscall > nsysent) {
    789      1.50       wiz 			printf("%s: line %d: too many syscalls [%d > %d]\n", infile, NR, syscall, nsysent)
    790      1.40   mycroft 			exit 1
    791      1.40   mycroft 		}
    792      1.40   mycroft 		while (syscall < nsysent) {
    793      1.46  jdolecek 			printf("\t{ 0, 0, 0,\n\t    %s },\t\t\t/* %d = filler */\n", \
    794      1.46  jdolecek 			    sys_nosys, syscall) > sysent
    795  1.69.2.1      yamt 			printf("\t{ 0, 0, 0,\n\t    %s },\t\t\t/* %d = filler */\n", \
    796  1.69.2.1      yamt 			    "(sy_call_t *)rump_enosys", syscall) > rumpsysent
    797      1.40   mycroft 			syscall++
    798      1.40   mycroft 		}
    799      1.40   mycroft 	}
    800  1.69.2.1      yamt 	printf("};\n") > sysent
    801  1.69.2.1      yamt 	printf("};\n") > rumpsysent
    802  1.69.2.1      yamt 	printf("CTASSERT(__arraycount(rump_sysent) == SYS_NSYSENT);\n") > rumpsysent
    803      1.27   thorpej 	printf("};\n") > sysnamesbottom
    804      1.40   mycroft 	printf("#define\t%sMAXSYSCALL\t%d\n", constprefix, maxsyscall) > sysnumhdr
    805      1.40   mycroft 	if (nsysent)
    806      1.40   mycroft 		printf("#define\t%sNSYSENT\t%d\n", constprefix, nsysent) > sysnumhdr
    807      1.11       cgd } '
    808       1.1     glass 
    809      1.17   mycroft cat $sysprotos >> $sysarghdr
    810      1.59  christos echo "#endif /* _${constprefix}SYSCALL_H_ */" >> $sysnumhdr
    811      1.59  christos echo "#endif /* _${constprefix}SYSCALLARGS_H_ */" >> $sysarghdr
    812  1.69.2.4      yamt printf "\n#include <rump/rump_syscalls_compat.h>\n" >> $rumpcallshdr
    813  1.69.2.4      yamt printf "\n#endif /* _RUMP_RUMP_SYSCALLS_H_ */\n" >> $rumpcallshdr
    814      1.16   thorpej cat $sysdcl $sysent > $syssw
    815      1.27   thorpej cat $sysnamesbottom >> $sysnames
    816  1.69.2.1      yamt cat $rumpsysent >> $rumpcalls
    817       1.1     glass 
    818      1.15  christos #chmod 444 $sysnames $sysnumhdr $syssw
    819