Home | History | Annotate | Line # | Download | only in kern
makesyscalls.sh revision 1.107
      1    1.1     glass #! /bin/sh -
      2  1.107     pooka #	$NetBSD: makesyscalls.sh,v 1.107 2010/12/30 16:49:24 pooka 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.83     pooka 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.83     pooka 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.78     pooka 	/^#/!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.70       apb 	# Create a NetBSD tag that does not get expanded when checking
    124   1.70       apb 	# this script out of CVS.  (This part of the awk script is in a
    125   1.70       apb 	# shell double-quoted string, so the backslashes are eaten by
    126   1.70       apb 	# the shell.)
    127   1.70       apb 	tag = \"\$\" \"NetBSD\" \"\$\"
    128   1.70       apb 
    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.94     pooka 	sysarghdrextra = \"$sysarghdrextra\"
    138   1.66     pooka 	rumpcalls = \"$rumpcalls\"
    139   1.66     pooka 	rumpcallshdr = \"$rumpcallshdr\"
    140   1.83     pooka 	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.70       apb 	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.70       apb 	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.70       apb 	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.70       apb 	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.70       apb 	printf "/* %s */\n\n", tag > rumpcalls
    198   1.83     pooka 	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.70       apb 	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.70       apb 	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.70       apb 	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.70       apb 	printf "#include <sys/cdefs.h>\n__KERNEL_RCSID(0, \"%s\");\n\n", tag > rumpcalls
    215  1.102     pooka 
    216   1.66     pooka 	printf "#include <sys/param.h>\n" > rumpcalls
    217  1.102     pooka 	printf "#include <sys/fstypes.h>\n" > rumpcalls
    218   1.66     pooka 	printf "#include <sys/proc.h>\n" > rumpcalls
    219   1.83     pooka 	printf "#include <sys/syscall.h>\n" > rumpcalls
    220  1.102     pooka 	printf "#include <sys/syscallargs.h>\n\n" > rumpcalls
    221  1.102     pooka 	printf "#ifdef RUMP_CLIENT\n" > rumpcalls
    222  1.102     pooka 	printf "#include <errno.h>\n" > rumpcalls
    223  1.102     pooka 	printf "#include <rump/rumpclient.h>\n\n" > rumpcalls
    224  1.102     pooka 	printf "#define rsys_syscall(num, data, dlen, retval)\t\\\n" > rumpcalls
    225  1.102     pooka 	printf "    rumpclient_syscall(num, data, dlen, retval)\n" > rumpcalls
    226  1.102     pooka 	printf "#define rsys_seterrno(error) errno = error\n" > rumpcalls
    227  1.102     pooka 	printf "#define rsys_alias(a,b)\n#else\n" > rumpcalls
    228  1.103     pooka 	printf "#include <sys/syscallvar.h>\n\n" > rumpcalls
    229   1.80     pooka 	printf "#include <rump/rumpuser.h>\n" > rumpcalls
    230   1.72     pooka 	printf "#include \"rump_private.h\"\n\n" > rumpcalls
    231  1.102     pooka 	printf "static int\nrsys_syscall" > rumpcalls
    232  1.102     pooka 	printf "(int num, void *data, size_t dlen, register_t *retval)" > rumpcalls
    233  1.103     pooka 	printf "\n{\n\tstruct sysent *callp = rump_sysent + num;\n" > rumpcalls
    234  1.103     pooka 	printf "\tint rv;\n" > rumpcalls
    235  1.103     pooka 	printf "\n\tKASSERT(num > 0 && num < SYS_NSYSENT);\n\n" > rumpcalls
    236  1.103     pooka 	printf "\trump_schedule();\n" > rumpcalls
    237  1.103     pooka 	printf "\trv = sy_call(callp, curlwp, data, retval);\n" > rumpcalls
    238  1.102     pooka 	printf "\trump_unschedule();\n\n\treturn rv;\n}\n\n" > rumpcalls
    239  1.102     pooka 	printf "#define rsys_seterrno(error) rumpuser_seterrno(error)\n" > rumpcalls
    240  1.102     pooka 	printf "#define rsys_alias(a,b) __weak_alias(a,b);\n#endif\n\n" > rumpcalls
    241  1.102     pooka 
    242   1.66     pooka 	printf "#if\tBYTE_ORDER == BIG_ENDIAN\n" > rumpcalls
    243   1.66     pooka 	printf "#define SPARG(p,k)\t((p)->k.be.datum)\n" > rumpcalls
    244   1.66     pooka 	printf "#else /* LITTLE_ENDIAN, I hope dearly */\n" > rumpcalls
    245   1.66     pooka 	printf "#define SPARG(p,k)\t((p)->k.le.datum)\n" > rumpcalls
    246   1.73     pooka 	printf "#endif\n\n" > rumpcalls
    247  1.102     pooka 	printf "#ifndef RUMP_CLIENT\n" > rumpcalls
    248   1.73     pooka 	printf "int rump_enosys(void);\n" > rumpcalls
    249   1.73     pooka 	printf "int\nrump_enosys()\n{\n\n\treturn ENOSYS;\n}\n" > rumpcalls
    250  1.102     pooka 	printf "#endif\n" > rumpcalls
    251   1.66     pooka 
    252  1.102     pooka 	printf "\n#ifndef RUMP_CLIENT\n" > rumpsysent
    253  1.102     pooka 	printf "#define\ts(type)\tsizeof(type)\n" > rumpsysent
    254   1.83     pooka 	printf "#define\tn(type)\t(sizeof(type)/sizeof (%s))\n", registertype > rumpsysent
    255   1.83     pooka 	printf "#define\tns(type)\tn(type), s(type)\n\n", registertype > rumpsysent
    256   1.83     pooka 	printf "struct sysent rump_sysent[] = {\n" > rumpsysent
    257   1.83     pooka 
    258   1.28   thorpej 	# System call names are included by userland (kdump(1)), so
    259   1.28   thorpej 	# hide the include files from it.
    260   1.48       mrg 	printf "#if defined(_KERNEL_OPT)\n" > sysnames
    261   1.28   thorpej 
    262   1.48       mrg 	printf "#endif /* _KERNEL_OPT */\n\n" > sysnamesbottom
    263   1.41   mycroft 	printf "const char *const %s[] = {\n",namesname > sysnamesbottom
    264   1.11       cgd 
    265   1.11       cgd 	printf " * created from%s\n */\n\n", $0 > sysnumhdr
    266   1.97     njoly 	printf "#ifndef _" constprefix "SYSCALL_H_\n" > sysnumhdr
    267   1.97     njoly 	printf "#define	_" constprefix "SYSCALL_H_\n\n" > sysnumhdr
    268   1.11       cgd 
    269   1.11       cgd 	printf " * created from%s\n */\n\n", $0 > sysarghdr
    270   1.97     njoly 	printf "#ifndef _" constprefix "SYSCALLARGS_H_\n" > sysarghdr
    271   1.97     njoly 	printf "#define	_" constprefix "SYSCALLARGS_H_\n\n" > sysarghdr
    272   1.66     pooka 
    273   1.66     pooka 	printf " * created from%s\n */\n\n", $0 > rumpcallshdr
    274   1.97     njoly 	printf "#ifndef _RUMP_RUMP_SYSCALLS_H_\n" > rumpcallshdr
    275   1.97     njoly 	printf "#define _RUMP_RUMP_SYSCALLS_H_\n\n" > rumpcallshdr
    276   1.96     pooka 	printf "#ifdef _KERNEL\n" > rumpcallshdr
    277   1.96     pooka 	printf "#error Interface not supported inside kernel\n" > rumpcallshdr
    278   1.96     pooka 	printf "#endif /* _KERNEL */\n\n" > rumpcallshdr
    279   1.85     pooka 	printf "#include <sys/types.h>\n" > rumpcallshdr
    280   1.85     pooka 	printf "#include <sys/select.h>\n\n" > rumpcallshdr
    281   1.85     pooka 	printf "#include <signal.h>\n\n" > rumpcallshdr
    282   1.66     pooka 
    283   1.94     pooka 	printf "%s", sysarghdrextra > sysarghdr
    284   1.60       dsl 	# Write max number of system call arguments to both headers
    285   1.60       dsl 	printf("#define\t%sMAXSYSARGS\t%d\n\n", constprefix, maxsysargs) \
    286   1.60       dsl 		> sysnumhdr
    287   1.60       dsl 	printf("#define\t%sMAXSYSARGS\t%d\n\n", constprefix, maxsysargs) \
    288   1.60       dsl 		> sysarghdr
    289   1.30       eeh 	printf "#undef\tsyscallarg\n" > sysarghdr
    290   1.35   thorpej 	printf "#define\tsyscallarg(x)\t\t\t\t\t\t\t\\\n" > sysarghdr
    291   1.35   thorpej 	printf "\tunion {\t\t\t\t\t\t\t\t\\\n" > sysarghdr
    292   1.35   thorpej 	printf "\t\t%s pad;\t\t\t\t\t\t\\\n", registertype > sysarghdr
    293   1.35   thorpej 	printf "\t\tstruct { x datum; } le;\t\t\t\t\t\\\n" > sysarghdr
    294   1.51      manu 	printf "\t\tstruct { /* LINTED zero array dimension */\t\t\\\n" \
    295   1.51      manu 		> sysarghdr
    296   1.51      manu 	printf "\t\t\tint8_t pad[  /* CONSTCOND */\t\t\t\\\n" > sysarghdr
    297   1.51      manu 	printf "\t\t\t\t(sizeof (%s) < sizeof (x))\t\\\n", \
    298   1.30       eeh 		registertype > sysarghdr
    299   1.35   thorpej 	printf "\t\t\t\t? 0\t\t\t\t\t\\\n" > sysarghdr
    300   1.35   thorpej 	printf "\t\t\t\t: sizeof (%s) - sizeof (x)];\t\\\n", \
    301   1.30       eeh 		registertype > sysarghdr
    302   1.35   thorpej 	printf "\t\t\tx datum;\t\t\t\t\t\\\n" > sysarghdr
    303   1.35   thorpej 	printf "\t\t} be;\t\t\t\t\t\t\t\\\n" > sysarghdr
    304   1.35   thorpej 	printf "\t}\n" > sysarghdr
    305   1.60       dsl 	printf("\n#undef check_syscall_args\n") >sysarghdr
    306  1.101     pooka 	printf("#define check_syscall_args(call) /*LINTED*/ \\\n" \
    307   1.60       dsl 		"\ttypedef char call##_check_args" \
    308   1.60       dsl 		    "[sizeof (struct call##_args) \\\n" \
    309   1.60       dsl 		"\t\t<= %sMAXSYSARGS * sizeof (%s) ? 1 : -1];\n", \
    310   1.60       dsl 		constprefix, registertype) >sysarghdr
    311   1.11       cgd 	next
    312   1.11       cgd }
    313   1.11       cgd NF == 0 || $1 ~ /^;/ {
    314   1.11       cgd 	next
    315   1.11       cgd }
    316   1.40   mycroft $0 ~ /^%%$/ {
    317   1.40   mycroft 	intable = 1
    318   1.40   mycroft 	next
    319   1.40   mycroft }
    320   1.11       cgd $1 ~ /^#[ 	]*include/ {
    321   1.11       cgd 	print > sysdcl
    322   1.27   thorpej 	print > sysnames
    323   1.11       cgd 	next
    324   1.11       cgd }
    325   1.40   mycroft $1 ~ /^#/ && !intable {
    326   1.40   mycroft 	print > sysdcl
    327   1.40   mycroft 	print > sysnames
    328   1.11       cgd 	next
    329   1.11       cgd }
    330   1.40   mycroft $1 ~ /^#/ && intable {
    331   1.40   mycroft 	if ($1 ~ /^#[ 	]*if/) {
    332   1.40   mycroft 		savedepth++
    333   1.40   mycroft 		savesyscall[savedepth] = syscall
    334   1.40   mycroft 	}
    335   1.40   mycroft 	if ($1 ~ /^#[ 	]*else/) {
    336   1.40   mycroft 		if (savedepth <= 0) {
    337   1.40   mycroft 			printf("%s: line %d: unbalanced #else\n", \
    338   1.40   mycroft 			    infile, NR)
    339   1.40   mycroft 			exit 1
    340   1.40   mycroft 		}
    341   1.40   mycroft 		syscall = savesyscall[savedepth]
    342   1.18       cgd 	}
    343   1.18       cgd 	if ($1 ~ /^#[       ]*endif/) {
    344   1.18       cgd 		if (savedepth <= 0) {
    345   1.40   mycroft 			printf("%s: line %d: unbalanced #endif\n", \
    346   1.40   mycroft 			    infile, NR)
    347   1.18       cgd 			exit 1
    348   1.18       cgd 		}
    349   1.40   mycroft 		savedepth--
    350   1.18       cgd 	}
    351   1.11       cgd 	print > sysent
    352   1.54  christos 	print > sysarghdr
    353   1.54  christos 	print > sysnumhdr
    354   1.16   thorpej 	print > sysprotos
    355   1.27   thorpej 	print > sysnamesbottom
    356   1.83     pooka 
    357   1.83     pooka 	# XXX: technically we do not want to have conditionals in rump,
    358   1.83     pooka 	# but it is easier to just let the cpp handle them than try to
    359   1.83     pooka 	# figure out what we want here in this script
    360   1.83     pooka 	print > rumpsysent
    361   1.11       cgd 	next
    362   1.11       cgd }
    363   1.11       cgd syscall != $1 {
    364   1.11       cgd 	printf "%s: line %d: syscall number out of sync at %d\n", \
    365   1.11       cgd 	   infile, NR, syscall
    366   1.11       cgd 	printf "line is:\n"
    367   1.11       cgd 	print
    368   1.11       cgd 	exit 1
    369   1.11       cgd }
    370   1.11       cgd function parserr(was, wanted) {
    371   1.77     pooka 	printf "%s: line %d: unexpected %s (expected <%s>)\n", \
    372   1.11       cgd 	    infile, NR, was, wanted
    373   1.32  christos 	printf "line is:\n"
    374   1.32  christos 	print
    375   1.11       cgd 	exit 1
    376   1.11       cgd }
    377   1.11       cgd function parseline() {
    378   1.11       cgd 	f=3			# toss number and type
    379   1.60       dsl 	if ($2 == "INDIR")
    380   1.60       dsl 		sycall_flags="SYCALL_INDIRECT"
    381   1.60       dsl 	else
    382   1.60       dsl 		sycall_flags="0"
    383   1.11       cgd 	if ($NF != "}") {
    384   1.11       cgd 		funcalias=$NF
    385   1.11       cgd 		end=NF-1
    386   1.11       cgd 	} else {
    387   1.11       cgd 		funcalias=""
    388   1.11       cgd 		end=NF
    389   1.43  jdolecek 	}
    390   1.61       dsl 	if ($f == "INDIR") {		# allow for "NOARG INDIR"
    391   1.61       dsl 		sycall_flags = "SYCALL_INDIRECT | " sycall_flags
    392   1.61       dsl 		f++
    393   1.61       dsl 	}
    394   1.74        ad 	if ($f == "MODULAR") {		# registered at runtime
    395   1.74        ad 		modular = 1
    396   1.74        ad 		f++
    397   1.74        ad 	} else {
    398   1.74        ad 		modular =  0;
    399   1.74        ad 	}
    400   1.66     pooka 	if ($f == "RUMP") {
    401   1.66     pooka 		rumpable = 1
    402   1.66     pooka 		f++
    403   1.66     pooka 	} else {
    404   1.66     pooka 		rumpable = 0
    405   1.66     pooka 	}
    406   1.43  jdolecek 	if ($f ~ /^[a-z0-9_]*$/) {	# allow syscall alias
    407   1.43  jdolecek 		funcalias=$f
    408   1.43  jdolecek 		f++
    409   1.11       cgd 	}
    410   1.11       cgd 	if ($f != "{")
    411   1.11       cgd 		parserr($f, "{")
    412   1.11       cgd 	f++
    413   1.11       cgd 	if ($end != "}")
    414   1.11       cgd 		parserr($end, "}")
    415   1.11       cgd 	end--
    416   1.11       cgd 	if ($end != ";")
    417   1.11       cgd 		parserr($end, ";")
    418   1.11       cgd 	end--
    419   1.11       cgd 	if ($end != ")")
    420   1.11       cgd 		parserr($end, ")")
    421   1.11       cgd 	end--
    422   1.11       cgd 
    423   1.19       cgd 	returntype = oldf = "";
    424   1.19       cgd 	do {
    425   1.19       cgd 		if (returntype != "" && oldf != "*")
    426   1.19       cgd 			returntype = returntype" ";
    427   1.19       cgd 		returntype = returntype$f;
    428   1.19       cgd 		oldf = $f;
    429   1.19       cgd 		f++
    430   1.78     pooka 	} while ($f != "|" && f < (end-1))
    431   1.19       cgd 	if (f == (end - 1)) {
    432   1.78     pooka 		parserr($f, "function argument definition (maybe \"|\"?)");
    433   1.78     pooka 	}
    434   1.78     pooka 	f++
    435   1.78     pooka 
    436   1.78     pooka 	fprefix=$f
    437   1.78     pooka 	f++
    438   1.78     pooka 	if ($f != "|") {
    439   1.78     pooka 		parserr($f, "function compat delimiter (maybe \"|\"?)");
    440   1.78     pooka 	}
    441   1.78     pooka 	f++
    442   1.78     pooka 
    443   1.78     pooka 	fcompat=""
    444   1.78     pooka 	if ($f != "|") {
    445   1.78     pooka 		fcompat=$f
    446   1.78     pooka 		f++
    447   1.78     pooka 	}
    448   1.78     pooka 
    449   1.78     pooka 	if ($f != "|") {
    450   1.78     pooka 		parserr($f, "function name delimiter (maybe \"|\"?)");
    451   1.78     pooka 	}
    452   1.78     pooka 	f++
    453   1.78     pooka 	fbase=$f
    454   1.78     pooka 
    455   1.90     pooka 	# pipe is special in how to returns its values.
    456   1.90     pooka 	# So just generate it manually if present.
    457   1.90     pooka 	if (rumpable == 1 && fbase == "pipe") {
    458   1.90     pooka 		rumpable = 0;
    459   1.90     pooka 		rumphaspipe = 1;
    460   1.90     pooka 	}
    461   1.90     pooka 
    462   1.78     pooka 	funcstdname=fprefix "_" fbase
    463   1.78     pooka 	if (fcompat != "") {
    464   1.78     pooka 		funcname=fprefix "___" fbase "" fcompat
    465   1.78     pooka 		wantrename=1
    466   1.78     pooka 	} else {
    467   1.78     pooka 		funcname=funcstdname
    468   1.78     pooka 		wantrename=0
    469   1.19       cgd 	}
    470   1.92      matt 	if (returntype == "quad_t" || returntype == "off_t") {
    471   1.92      matt 		if (sycall_flags == "0")
    472   1.92      matt 			sycall_flags = "SYCALL_RET_64";
    473   1.92      matt 		else
    474   1.92      matt 			sycall_flags = "SYCALL_RET_64 | " sycall_flags;
    475   1.92      matt 	}
    476   1.11       cgd 
    477   1.17   mycroft 	if (funcalias == "") {
    478   1.11       cgd 		funcalias=funcname
    479   1.17   mycroft 		sub(/^([^_]+_)*sys_/, "", funcalias)
    480   1.17   mycroft 	}
    481   1.11       cgd 	f++
    482   1.11       cgd 
    483   1.11       cgd 	if ($f != "(")
    484   1.76     pooka 		parserr($f, "(")
    485   1.11       cgd 	f++
    486   1.11       cgd 
    487   1.19       cgd 	argc=0;
    488   1.63      yamt 	argalign=0;
    489   1.11       cgd 	if (f == end) {
    490   1.11       cgd 		if ($f != "void")
    491   1.11       cgd 			parserr($f, "argument definition")
    492   1.19       cgd 		isvarargs = 0;
    493   1.19       cgd 		varargc = 0;
    494   1.80     pooka 		argtype[0]="void";
    495   1.11       cgd 		return
    496   1.11       cgd 	}
    497   1.11       cgd 
    498   1.19       cgd 	# some system calls (open() and fcntl()) can accept a variable
    499   1.19       cgd 	# number of arguments.  If syscalls accept a variable number of
    500   1.19       cgd 	# arguments, they must still have arguments specified for
    501   1.19       cgd 	# the remaining argument "positions," because of the way the
    502   1.19       cgd 	# kernel system call argument handling works.
    503   1.19       cgd 	#
    504   1.19       cgd 	# Indirect system calls, e.g. syscall(), are exceptions to this
    505   1.19       cgd 	# rule, since they are handled entirely by machine-dependent code
    506   1.19       cgd 	# and do not need argument structures built.
    507   1.19       cgd 
    508   1.19       cgd 	isvarargs = 0;
    509   1.92      matt 	args64 = 0;
    510   1.11       cgd 	while (f <= end) {
    511   1.19       cgd 		if ($f == "...") {
    512   1.19       cgd 			f++;
    513   1.19       cgd 			isvarargs = 1;
    514   1.19       cgd 			varargc = argc;
    515   1.19       cgd 			continue;
    516   1.19       cgd 		}
    517   1.11       cgd 		argc++
    518   1.11       cgd 		argtype[argc]=""
    519   1.14       cgd 		oldf=""
    520   1.11       cgd 		while (f < end && $(f+1) != ",") {
    521   1.14       cgd 			if (argtype[argc] != "" && oldf != "*")
    522   1.11       cgd 				argtype[argc] = argtype[argc]" ";
    523   1.11       cgd 			argtype[argc] = argtype[argc]$f;
    524   1.14       cgd 			oldf = $f;
    525   1.11       cgd 			f++
    526   1.11       cgd 		}
    527   1.11       cgd 		if (argtype[argc] == "")
    528   1.11       cgd 			parserr($f, "argument definition")
    529   1.86     pooka 		if (argtype[argc] == "off_t"  \
    530   1.86     pooka 		  || argtype[argc] == "dev_t" \
    531   1.86     pooka 		  || argtype[argc] == "time_t") {
    532   1.68  christos 			if ((argalign % 2) != 0 && sysalign &&
    533   1.63      yamt 			    funcname != "sys_posix_fadvise") # XXX for now
    534   1.63      yamt 				parserr($f, "a padding argument")
    535   1.63      yamt 		} else {
    536   1.63      yamt 			argalign++;
    537   1.63      yamt 		}
    538   1.93     skrll 		if (argtype[argc] == "quad_t" || argtype[argc] == "off_t" \
    539   1.93     skrll 		  || argtype[argc] == "dev_t" || argtype[argc] == "time_t") {
    540   1.92      matt 			if (sycall_flags == "0")
    541   1.92      matt 				sycall_flags = "SYCALL_ARG"argc-1"_64";
    542   1.92      matt 			else
    543   1.92      matt 				sycall_flags = "SYCALL_ARG"argc-1"_64 | " sycall_flags;
    544   1.92      matt 			args64++;
    545   1.92      matt 		}
    546   1.11       cgd 		argname[argc]=$f;
    547   1.11       cgd 		f += 2;			# skip name, and any comma
    548   1.11       cgd 	}
    549   1.92      matt 	if (args64 > 0)
    550   1.92      matt 		sycall_flags = "SYCALL_NARGS64_VAL("args64") | " sycall_flags;
    551   1.19       cgd 	# must see another argument after varargs notice.
    552   1.19       cgd 	if (isvarargs) {
    553   1.61       dsl 		if (argc == varargc)
    554   1.19       cgd 			parserr($f, "argument definition")
    555   1.19       cgd 	} else
    556   1.19       cgd 		varargc = argc;
    557   1.11       cgd }
    558   1.54  christos 
    559   1.54  christos function printproto(wrap) {
    560   1.54  christos 	printf("/* syscall: \"%s%s\" ret: \"%s\" args:", wrap, funcalias,
    561   1.54  christos 	    returntype) > sysnumhdr
    562   1.54  christos 	for (i = 1; i <= varargc; i++)
    563   1.54  christos 		printf(" \"%s\"", argtype[i]) > sysnumhdr
    564   1.54  christos 	if (isvarargs)
    565   1.54  christos 		printf(" \"...\"") > sysnumhdr
    566   1.54  christos 	printf(" */\n") > sysnumhdr
    567   1.54  christos 	printf("#define\t%s%s%s\t%d\n\n", constprefix, wrap, funcalias,
    568   1.54  christos 	    syscall) > sysnumhdr
    569   1.66     pooka 
    570   1.66     pooka 	# rumpalooza
    571   1.66     pooka 	if (!rumpable)
    572   1.66     pooka 		return
    573   1.66     pooka 
    574   1.99     pooka 	if (wantrename)
    575   1.99     pooka 		printf("%s rump_%s(", returntype, funcstdname) > rumpcallshdr
    576   1.99     pooka 	else
    577   1.99     pooka 		printf("%s rump_sys_%s(", returntype, funcalias) > rumpcallshdr
    578   1.88     pooka 	for (i = 1; i < varargc; i++)
    579   1.87     pooka 		if (argname[i] != "PAD")
    580   1.87     pooka 			printf("%s, ", argtype[i]) > rumpcallshdr
    581   1.88     pooka 	if (isvarargs)
    582   1.88     pooka 		printf("%s, ...)", argtype[varargc]) > rumpcallshdr
    583   1.88     pooka 	else
    584   1.88     pooka 		printf("%s)", argtype[argc]) > rumpcallshdr
    585   1.78     pooka 	if (wantrename)
    586   1.78     pooka 		printf(" __RENAME(rump_%s)", funcname) > rumpcallshdr
    587   1.78     pooka 	printf(";\n") > rumpcallshdr
    588   1.54  christos }
    589   1.54  christos 
    590   1.90     pooka function printrumpsysent(insysent, compatwrap) {
    591   1.90     pooka 	if (!insysent) {
    592   1.95     pooka 		eno[0] = "rump_enosys"
    593   1.95     pooka 		eno[1] = "sys_nomodule"
    594  1.107     pooka 		flags[0] = "SYCALL_NOSYS"
    595  1.107     pooka 		flags[1] = "0"
    596  1.107     pooka 		printf("\t{ 0, 0, %s,\n\t    (sy_call_t *)%s }, \t"	\
    597   1.95     pooka 		    "/* %d = unrumped */\n",				\
    598  1.107     pooka 		    flags[modular], eno[modular], syscall) > rumpsysent
    599   1.90     pooka 		return
    600   1.90     pooka 	}
    601   1.90     pooka 
    602   1.90     pooka 	printf("\t{ ") > rumpsysent
    603   1.90     pooka 	if (argc == 0) {
    604   1.90     pooka 		printf("0, 0, ") > rumpsysent
    605   1.90     pooka 	} else {
    606   1.99     pooka 		printf("ns(struct sys_%s%s_args), ", compatwrap_, funcalias) > rumpsysent
    607   1.90     pooka 	}
    608   1.90     pooka 	printf("0,\n\t    %s },", wfn) > rumpsysent
    609  1.106     pooka 	for (i = 0; i < (33 - length(wfn)) / 8; i++)
    610   1.90     pooka 		printf("\t") > rumpsysent
    611   1.90     pooka 	printf("/* %d = %s%s */\n", syscall, compatwrap_, funcalias) > rumpsysent
    612   1.90     pooka }
    613   1.90     pooka 
    614   1.61       dsl function putent(type, compatwrap) {
    615   1.60       dsl 	# output syscall declaration for switch table.
    616   1.60       dsl 	if (compatwrap == "")
    617   1.60       dsl 		compatwrap_ = ""
    618   1.60       dsl 	else
    619   1.60       dsl 		compatwrap_ = compatwrap "_"
    620   1.62       dsl 	if (argc == 0)
    621   1.62       dsl 		arg_type = "void";
    622   1.62       dsl 	else {
    623   1.62       dsl 		arg_type = "struct " compatwrap_ funcname "_args";
    624   1.62       dsl 	}
    625   1.62       dsl 	proto = "int\t" compatwrap_ funcname "(struct lwp *, const " \
    626   1.62       dsl 	    arg_type " *, register_t *);\n"
    627   1.60       dsl 	if (sysmap[proto] != 1) {
    628   1.60       dsl 		sysmap[proto] = 1;
    629   1.60       dsl 		print proto > sysprotos;
    630   1.21       cgd 	}
    631   1.11       cgd 
    632   1.11       cgd 	# output syscall switch entry
    633   1.60       dsl 	printf("\t{ ") > sysent
    634   1.60       dsl 	if (argc == 0) {
    635   1.60       dsl 		printf("0, 0, ") > sysent
    636   1.19       cgd 	} else {
    637   1.60       dsl 		printf("ns(struct %s%s_args), ", compatwrap_, funcname) > sysent
    638   1.19       cgd 	}
    639   1.74        ad 	if (modular) 
    640   1.74        ad 		wfn = "(sy_call_t *)sys_nomodule";
    641   1.74        ad 	else if (compatwrap == "")
    642   1.62       dsl 		wfn = "(sy_call_t *)" funcname;
    643   1.60       dsl 	else
    644   1.62       dsl 		wfn = "(sy_call_t *)" compatwrap "(" funcname ")";
    645   1.60       dsl 	printf("%s,\n\t    %s },", sycall_flags, wfn) > sysent
    646   1.60       dsl 	for (i = 0; i < (33 - length(wfn)) / 8; i++)
    647   1.60       dsl 		printf("\t") > sysent
    648   1.60       dsl 	printf("/* %d = %s%s */\n", syscall, compatwrap_, funcalias) > sysent
    649   1.11       cgd 
    650   1.11       cgd 	# output syscall name for names table
    651   1.60       dsl 	printf("\t/* %3d */\t\"%s%s\",\n", syscall, compatwrap_, funcalias) \
    652   1.60       dsl 	    > sysnamesbottom
    653   1.11       cgd 
    654   1.11       cgd 	# output syscall number of header, if appropriate
    655   1.61       dsl 	if (type == "STD" || type == "NOARGS" || type == "INDIR") {
    656   1.19       cgd 		# output a prototype, to be used to generate lint stubs in
    657   1.19       cgd 		# libc.
    658   1.54  christos 		printproto("")
    659   1.61       dsl 	} else if (type == "COMPAT") {
    660   1.29   thorpej 		# Just define the syscall number with a comment.  These
    661   1.29   thorpej 		# may be used by compatibility stubs in libc.
    662   1.60       dsl 		printproto(compatwrap_)
    663   1.60       dsl 	}
    664   1.11       cgd 
    665   1.11       cgd 	# output syscall argument structure, if it has arguments
    666   1.62       dsl 	if (argc != 0) {
    667   1.62       dsl 		printf("\nstruct %s%s_args", compatwrap_, funcname) > sysarghdr
    668   1.62       dsl 		if (type != "NOARGS") {
    669   1.62       dsl 			print " {" >sysarghdr;
    670   1.62       dsl 			for (i = 1; i <= argc; i++)
    671   1.62       dsl 				printf("\tsyscallarg(%s) %s;\n", argtype[i],
    672   1.62       dsl 				    argname[i]) > sysarghdr
    673   1.62       dsl 			printf "}" >sysarghdr;
    674   1.62       dsl 		}
    675   1.62       dsl 		printf(";\n") > sysarghdr
    676   1.62       dsl 		if (type != "NOARGS" && type != "INDIR") {
    677   1.60       dsl 			printf("check_syscall_args(%s%s)\n", compatwrap_,
    678   1.60       dsl 			    funcname) >sysarghdr
    679   1.60       dsl 		}
    680   1.11       cgd 	}
    681   1.66     pooka 
    682   1.90     pooka 	if (!rumpable) {
    683   1.90     pooka 		if (funcname == "sys_pipe" && rumphaspipe == 1)
    684   1.90     pooka 			insysent = 1
    685   1.90     pooka 		else
    686   1.90     pooka 			insysent = 0
    687   1.90     pooka 	} else {
    688   1.90     pooka 		insysent = 1
    689   1.90     pooka 	}
    690   1.90     pooka 	printrumpsysent(insysent, compatwrap)
    691   1.90     pooka 
    692   1.66     pooka 	# output rump marshalling code if necessary
    693   1.83     pooka 	if (!rumpable) {
    694   1.66     pooka 		return
    695   1.83     pooka 	}
    696   1.66     pooka 
    697   1.78     pooka 	# need a local prototype, we export the re-re-named one in .h
    698   1.99     pooka 	printf("\n%s rump_sys_%s(", returntype, funcalias) > rumpcalls
    699   1.80     pooka 	for (i = 1; i < argc; i++) {
    700   1.87     pooka 		if (argname[i] != "PAD")
    701   1.87     pooka 			printf("%s, ", argtype[i]) > rumpcalls
    702   1.78     pooka 	}
    703   1.80     pooka 	printf("%s);", argtype[argc]) > rumpcalls
    704   1.78     pooka 
    705   1.99     pooka 	printf("\n%s\nrump_sys_%s(", returntype, funcalias) > rumpcalls
    706   1.80     pooka 	for (i = 1; i < argc; i++) {
    707   1.87     pooka 		if (argname[i] != "PAD")
    708   1.87     pooka 			printf("%s %s, ", argtype[i], argname[i]) > rumpcalls
    709   1.66     pooka 	}
    710   1.80     pooka 	printf("%s %s)\n", argtype[argc], argname[argc]) > rumpcalls
    711   1.89     pooka 	printf("{\n\tregister_t rval[2] = {0, 0};\n\tint error = 0;\n") \
    712   1.89     pooka 	    > rumpcalls
    713   1.78     pooka 
    714   1.66     pooka 	argarg = "NULL"
    715   1.83     pooka 	argsize = 0;
    716   1.66     pooka 	if (argc) {
    717   1.84     pooka 		argarg = "&callarg"
    718   1.84     pooka 		argsize = "sizeof(callarg)"
    719   1.84     pooka 		printf("\tstruct %s%s_args callarg;\n\n",compatwrap_,funcname) \
    720   1.66     pooka 		    > rumpcalls
    721   1.66     pooka 		for (i = 1; i <= argc; i++) {
    722   1.87     pooka 			if (argname[i] == "PAD") {
    723   1.87     pooka 				printf("\tSPARG(&callarg, %s) = 0;\n", \
    724   1.87     pooka 				    argname[i]) > rumpcalls
    725   1.87     pooka 			} else {
    726   1.87     pooka 				printf("\tSPARG(&callarg, %s) = %s;\n", \
    727   1.87     pooka 				    argname[i], argname[i]) > rumpcalls
    728   1.87     pooka 			}
    729   1.66     pooka 		}
    730   1.66     pooka 		printf("\n") > rumpcalls
    731   1.66     pooka 	} else {
    732   1.66     pooka 		printf("\n") > rumpcalls
    733   1.66     pooka 	}
    734  1.102     pooka 	printf("\terror = rsys_syscall(%s%s, " \
    735  1.102     pooka 	    "%s, %s, rval);\n", constprefix, funcalias, \
    736   1.83     pooka 	    argarg, argsize) > rumpcalls
    737   1.89     pooka 	printf("\tif (error) {\n\t\trval[0] = -1;\n") > rumpcalls
    738   1.80     pooka 	if (returntype != "void") {
    739  1.102     pooka 		printf("\t\trsys_seterrno(error);\n\t}\n") > rumpcalls
    740   1.89     pooka 		printf("\treturn rval[0];\n") > rumpcalls
    741   1.80     pooka 	} else {
    742   1.80     pooka 		printf("\t}\n") > rumpcalls
    743   1.80     pooka 	}
    744   1.72     pooka 	printf("}\n") > rumpcalls
    745  1.102     pooka 	printf("rsys_alias(%s,rump_enosys)\n", funcname) > rumpcalls
    746   1.83     pooka 
    747   1.11       cgd }
    748   1.61       dsl $2 == "STD" || $2 == "NODEF" || $2 == "NOARGS" || $2 == "INDIR" {
    749   1.11       cgd 	parseline()
    750   1.17   mycroft 	putent($2, "")
    751   1.11       cgd 	syscall++
    752   1.11       cgd 	next
    753   1.11       cgd }
    754   1.64    martin $2 == "OBSOL" || $2 == "UNIMPL" || $2 == "EXCL" || $2 == "IGNORED" {
    755   1.11       cgd 	if ($2 == "OBSOL")
    756   1.11       cgd 		comment="obsolete"
    757   1.34  christos 	else if ($2 == "EXCL")
    758   1.34  christos 		comment="excluded"
    759   1.64    martin 	else if ($2 == "IGNORED")
    760   1.64    martin 		comment="ignored"
    761   1.11       cgd 	else
    762   1.11       cgd 		comment="unimplemented"
    763   1.11       cgd 	for (i = 3; i <= NF; i++)
    764   1.11       cgd 		comment=comment " " $i
    765   1.11       cgd 
    766   1.64    martin 	if ($2 == "IGNORED")
    767   1.64    martin 		sys_stub = "(sy_call_t *)nullop";
    768   1.64    martin 	else
    769   1.65     njoly 		sys_stub = sys_nosys;
    770   1.64    martin 
    771   1.46  jdolecek 	printf("\t{ 0, 0, 0,\n\t    %s },\t\t\t/* %d = %s */\n", \
    772   1.64    martin 	    sys_stub, syscall, comment) > sysent
    773  1.107     pooka 	printf("\t{ 0, 0, SYCALL_NOSYS,\n\t    %s },\t\t/* %d = %s */\n", \
    774   1.83     pooka 	    "(sy_call_t *)rump_enosys", syscall, comment) > rumpsysent
    775   1.60       dsl 	printf("\t/* %3d */\t\"#%d (%s)\",\n", syscall, syscall, comment) \
    776   1.60       dsl 	    > sysnamesbottom
    777   1.11       cgd 	if ($2 != "UNIMPL")
    778   1.11       cgd 		printf("\t\t\t\t/* %d is %s */\n", syscall, comment) > sysnumhdr
    779   1.11       cgd 	syscall++
    780   1.11       cgd 	next
    781   1.11       cgd }
    782   1.11       cgd {
    783   1.11       cgd 	for (i = 1; i <= ncompat; i++) {
    784   1.11       cgd 		if ($2 == compat_upper[i]) {
    785   1.11       cgd 			parseline();
    786   1.29   thorpej 			putent("COMPAT", compat[i])
    787   1.11       cgd 			syscall++
    788   1.11       cgd 			next
    789   1.11       cgd 		}
    790   1.11       cgd 	}
    791   1.40   mycroft 	printf("%s: line %d: unrecognized keyword %s\n", infile, NR, $2)
    792    1.1     glass 	exit 1
    793   1.11       cgd }
    794   1.11       cgd END {
    795   1.91     pooka 	# output pipe() syscall with its special rval[2] handling
    796   1.90     pooka 	if (rumphaspipe) {
    797   1.90     pooka 		printf("int rump_sys_pipe(int *);\n") > rumpcallshdr
    798   1.90     pooka 		printf("\nint rump_sys_pipe(int *);\n") > rumpcalls
    799   1.90     pooka 		printf("int\nrump_sys_pipe(int *fd)\n{\n") > rumpcalls
    800   1.90     pooka 		printf("\tregister_t rval[2] = {0, 0};\n") > rumpcalls
    801   1.90     pooka 		printf("\tint error = 0;\n") > rumpcalls
    802  1.102     pooka 		printf("\n\terror = rsys_syscall(SYS_pipe, ") > rumpcalls
    803  1.102     pooka 		printf("NULL, 0, rval);\n") > rumpcalls
    804   1.90     pooka 		printf("\tif (error) {\n") > rumpcalls
    805  1.102     pooka 		printf("\t\trsys_seterrno(error);\n") > rumpcalls
    806   1.90     pooka 		printf("\t} else {\n\t\tfd[0] = rval[0];\n") > rumpcalls
    807   1.90     pooka 		printf("\t\tfd[1] = rval[1];\n\t}\n") > rumpcalls
    808   1.90     pooka 		printf("\treturn error ? -1 : 0;\n}\n") > rumpcalls
    809   1.90     pooka 	}
    810   1.90     pooka 
    811   1.40   mycroft 	maxsyscall = syscall
    812   1.40   mycroft 	if (nsysent) {
    813   1.40   mycroft 		if (syscall > nsysent) {
    814   1.50       wiz 			printf("%s: line %d: too many syscalls [%d > %d]\n", infile, NR, syscall, nsysent)
    815   1.40   mycroft 			exit 1
    816   1.40   mycroft 		}
    817   1.40   mycroft 		while (syscall < nsysent) {
    818   1.46  jdolecek 			printf("\t{ 0, 0, 0,\n\t    %s },\t\t\t/* %d = filler */\n", \
    819   1.46  jdolecek 			    sys_nosys, syscall) > sysent
    820  1.107     pooka 			printf("\t{ 0, 0, SYCALL_NOSYS,\n\t    %s },\t\t/* %d = filler */\n", \
    821   1.83     pooka 			    "(sy_call_t *)rump_enosys", syscall) > rumpsysent
    822  1.105     pooka 			printf("\t/* %3d */\t\"# filler\",\n", syscall) \
    823  1.105     pooka 			    > sysnamesbottom
    824   1.40   mycroft 			syscall++
    825   1.40   mycroft 		}
    826   1.40   mycroft 	}
    827   1.82     pooka 	printf("};\n") > sysent
    828   1.83     pooka 	printf("};\n") > rumpsysent
    829   1.83     pooka 	printf("CTASSERT(__arraycount(rump_sysent) == SYS_NSYSENT);\n") > rumpsysent
    830  1.102     pooka 	printf("#endif /* RUMP_CLIENT */\n") > rumpsysent
    831   1.27   thorpej 	printf("};\n") > sysnamesbottom
    832   1.40   mycroft 	printf("#define\t%sMAXSYSCALL\t%d\n", constprefix, maxsyscall) > sysnumhdr
    833   1.40   mycroft 	if (nsysent)
    834   1.40   mycroft 		printf("#define\t%sNSYSENT\t%d\n", constprefix, nsysent) > sysnumhdr
    835   1.11       cgd } '
    836    1.1     glass 
    837   1.17   mycroft cat $sysprotos >> $sysarghdr
    838   1.59  christos echo "#endif /* _${constprefix}SYSCALL_H_ */" >> $sysnumhdr
    839   1.59  christos echo "#endif /* _${constprefix}SYSCALLARGS_H_ */" >> $sysarghdr
    840   1.98     pooka printf "\n#include <rump/rump_syscalls_compat.h>\n" >> $rumpcallshdr
    841   1.97     njoly printf "\n#endif /* _RUMP_RUMP_SYSCALLS_H_ */\n" >> $rumpcallshdr
    842   1.16   thorpej cat $sysdcl $sysent > $syssw
    843   1.27   thorpej cat $sysnamesbottom >> $sysnames
    844   1.83     pooka cat $rumpsysent >> $rumpcalls
    845    1.1     glass 
    846   1.15  christos #chmod 444 $sysnames $sysnumhdr $syssw
    847