Home | History | Annotate | Line # | Download | only in kern
makesyscalls.sh revision 1.119
      1    1.1     glass #! /bin/sh -
      2  1.119  christos #	$NetBSD: makesyscalls.sh,v 1.119 2011/06/26 16:42:42 christos 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.109     pooka rumptypes="rumphdr.types"
     77  1.109     pooka rumpprotos="rumphdr.protos"
     78    1.1     glass 
     79  1.109     pooka trap "rm $sysdcl $sysprotos $sysent $sysnamesbottom $rumpsysent $rumptypes $rumpprotos" 0
     80   1.11       cgd 
     81   1.11       cgd # Awk program (must support nawk extensions)
     82   1.11       cgd # Use "awk" at Berkeley, "nawk" or "gawk" elsewhere.
     83   1.11       cgd awk=${AWK:-awk}
     84   1.11       cgd 
     85   1.57  jdolecek # Does this awk have a "toupper" function?
     86   1.57  jdolecek have_toupper=`$awk 'BEGIN { print toupper("true"); exit; }' 2>/dev/null`
     87   1.11       cgd 
     88   1.11       cgd # If this awk does not define "toupper" then define our own.
     89   1.57  jdolecek if [ "$have_toupper" = TRUE ] ; then
     90   1.57  jdolecek 	# Used awk (GNU awk or nawk) provides it
     91   1.11       cgd 	toupper=
     92   1.11       cgd else
     93   1.11       cgd 	# Provide our own toupper()
     94   1.11       cgd 	toupper='
     95   1.11       cgd function toupper(str) {
     96   1.11       cgd 	_toupper_cmd = "echo "str" |tr a-z A-Z"
     97   1.11       cgd 	_toupper_cmd | getline _toupper_str;
     98   1.11       cgd 	close(_toupper_cmd);
     99   1.11       cgd 	return _toupper_str;
    100   1.11       cgd }'
    101   1.11       cgd fi
    102   1.11       cgd 
    103   1.11       cgd # before handing it off to awk, make a few adjustments:
    104   1.11       cgd #	(1) insert spaces around {, }, (, ), *, and commas.
    105   1.11       cgd #	(2) get rid of any and all dollar signs (so that rcs id use safe)
    106   1.11       cgd #
    107   1.11       cgd # The awk script will deal with blank lines and lines that
    108   1.11       cgd # start with the comment character (';').
    109    1.1     glass 
    110   1.11       cgd sed -e '
    111   1.11       cgd s/\$//g
    112   1.11       cgd :join
    113   1.11       cgd 	/\\$/{a\
    114   1.11       cgd 
    115   1.11       cgd 	N
    116   1.11       cgd 	s/\\\n//
    117   1.11       cgd 	b join
    118   1.11       cgd 	}
    119   1.11       cgd 2,${
    120   1.78     pooka 	/^#/!s/\([{}()*,|]\)/ \1 /g
    121   1.11       cgd }
    122   1.11       cgd ' < $2 | $awk "
    123   1.11       cgd $toupper
    124   1.11       cgd BEGIN {
    125   1.70       apb 	# Create a NetBSD tag that does not get expanded when checking
    126   1.70       apb 	# this script out of CVS.  (This part of the awk script is in a
    127   1.70       apb 	# shell double-quoted string, so the backslashes are eaten by
    128   1.70       apb 	# the shell.)
    129   1.70       apb 	tag = \"\$\" \"NetBSD\" \"\$\"
    130   1.70       apb 
    131   1.18       cgd 	# to allow nested #if/#else/#endif sets
    132   1.18       cgd 	savedepth = 0
    133   1.44  jdolecek 	# to track already processed syscalls
    134   1.18       cgd 
    135   1.11       cgd 	sysnames = \"$sysnames\"
    136   1.16   thorpej 	sysprotos = \"$sysprotos\"
    137   1.11       cgd 	sysnumhdr = \"$sysnumhdr\"
    138   1.11       cgd 	sysarghdr = \"$sysarghdr\"
    139   1.94     pooka 	sysarghdrextra = \"$sysarghdrextra\"
    140   1.66     pooka 	rumpcalls = \"$rumpcalls\"
    141   1.66     pooka 	rumpcallshdr = \"$rumpcallshdr\"
    142   1.83     pooka 	rumpsysent = \"$rumpsysent\"
    143   1.11       cgd 	switchname = \"$switchname\"
    144   1.11       cgd 	namesname = \"$namesname\"
    145   1.11       cgd 	constprefix = \"$constprefix\"
    146   1.30       eeh 	registertype = \"$registertype\"
    147   1.68  christos 	sysalign=\"$sysalign\"
    148   1.30       eeh 	if (!registertype) {
    149   1.30       eeh 	    registertype = \"register_t\"
    150   1.30       eeh 	}
    151   1.40   mycroft 	nsysent = \"$nsysent\"
    152   1.11       cgd 
    153   1.11       cgd 	sysdcl = \"$sysdcl\"
    154   1.11       cgd 	syscompat_pref = \"$syscompat_pref\"
    155   1.11       cgd 	sysent = \"$sysent\"
    156   1.27   thorpej 	sysnamesbottom = \"$sysnamesbottom\"
    157  1.109     pooka 	rumpprotos = \"$rumpprotos\"
    158  1.109     pooka 	rumptypes = \"$rumptypes\"
    159   1.46  jdolecek 	sys_nosys = \"$sys_nosys\"
    160   1.60       dsl 	maxsysargs = \"$maxsysargs\"
    161   1.11       cgd 	infile = \"$2\"
    162   1.11       cgd 
    163   1.11       cgd 	compatopts = \"$compatopts\"
    164   1.11       cgd 	"'
    165   1.11       cgd 
    166   1.70       apb 	printf "/* %s */\n\n", tag > sysdcl
    167   1.11       cgd 	printf "/*\n * System call switch table.\n *\n" > sysdcl
    168   1.11       cgd 	printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysdcl
    169   1.11       cgd 
    170   1.11       cgd 	ncompat = split(compatopts,compat)
    171   1.11       cgd 	for (i = 1; i <= ncompat; i++) {
    172   1.11       cgd 		compat_upper[i] = toupper(compat[i])
    173   1.11       cgd 
    174   1.17   mycroft 		printf "\n#ifdef %s\n", compat_upper[i] > sysent
    175   1.47     lukem 		printf "#define	%s(func) __CONCAT(%s_,func)\n", compat[i], \
    176   1.17   mycroft 		    compat[i] > sysent
    177   1.17   mycroft 		printf "#else\n" > sysent
    178   1.47     lukem 		printf "#define	%s(func) %s\n", compat[i], sys_nosys > sysent
    179   1.17   mycroft 		printf "#endif\n" > sysent
    180   1.11       cgd 	}
    181   1.11       cgd 
    182   1.60       dsl 	printf "\n#define\ts(type)\tsizeof(type)\n" > sysent
    183   1.60       dsl 	printf "#define\tn(type)\t(sizeof(type)/sizeof (%s))\n", registertype > sysent
    184   1.60       dsl 	printf "#define\tns(type)\tn(type), s(type)\n\n", registertype > sysent
    185   1.17   mycroft 	printf "struct sysent %s[] = {\n",switchname > sysent
    186   1.17   mycroft 
    187   1.70       apb 	printf "/* %s */\n\n", tag > sysnames
    188   1.11       cgd 	printf "/*\n * System call names.\n *\n" > sysnames
    189   1.11       cgd 	printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysnames
    190   1.11       cgd 
    191   1.16   thorpej 	printf "\n/*\n * System call prototypes.\n */\n\n" > sysprotos
    192   1.16   thorpej 
    193   1.70       apb 	printf "/* %s */\n\n", tag > sysnumhdr
    194   1.11       cgd 	printf "/*\n * System call numbers.\n *\n" > sysnumhdr
    195   1.11       cgd 	printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysnumhdr
    196   1.11       cgd 
    197   1.70       apb 	printf "/* %s */\n\n", tag > sysarghdr
    198   1.13   mycroft 	printf "/*\n * System call argument lists.\n *\n" > sysarghdr
    199   1.11       cgd 	printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysarghdr
    200   1.66     pooka 
    201   1.70       apb 	printf "/* %s */\n\n", tag > rumpcalls
    202   1.83     pooka 	printf "/*\n * System call vector and marshalling for rump.\n *\n" > rumpcalls
    203   1.66     pooka 	printf " * DO NOT EDIT-- this file is automatically generated.\n" > rumpcalls
    204   1.66     pooka 
    205   1.70       apb 	printf "/* %s */\n\n", tag > rumpcallshdr
    206   1.66     pooka 	printf "/*\n * System call protos in rump namespace.\n *\n" > rumpcallshdr
    207   1.66     pooka 	printf " * DO NOT EDIT-- this file is automatically generated.\n" > rumpcallshdr
    208   1.11       cgd }
    209   1.11       cgd NR == 1 {
    210   1.58     perry 	sub(/ $/, "")
    211   1.11       cgd 	printf " * created from%s\n */\n\n", $0 > sysdcl
    212   1.70       apb 	printf "#include <sys/cdefs.h>\n__KERNEL_RCSID(0, \"%s\");\n\n", tag > sysdcl
    213   1.11       cgd 
    214   1.11       cgd 	printf " * created from%s\n */\n\n", $0 > sysnames
    215   1.70       apb 	printf "#include <sys/cdefs.h>\n__KERNEL_RCSID(0, \"%s\");\n\n", tag > sysnames
    216   1.28   thorpej 
    217   1.66     pooka 	printf " * created from%s\n */\n\n", $0 > rumpcalls
    218   1.70       apb 	printf "#include <sys/cdefs.h>\n__KERNEL_RCSID(0, \"%s\");\n\n", tag > rumpcalls
    219  1.102     pooka 
    220   1.66     pooka 	printf "#include <sys/param.h>\n" > rumpcalls
    221  1.102     pooka 	printf "#include <sys/fstypes.h>\n" > rumpcalls
    222   1.66     pooka 	printf "#include <sys/proc.h>\n" > rumpcalls
    223  1.102     pooka 	printf "#ifdef RUMP_CLIENT\n" > rumpcalls
    224  1.117     pooka 	printf "#include <srcsys/syscall.h>\n" > rumpcalls
    225  1.117     pooka 	printf "#include <srcsys/syscallargs.h>\n\n" > rumpcalls
    226  1.102     pooka 	printf "#include <errno.h>\n" > rumpcalls
    227  1.102     pooka 	printf "#include <rump/rumpclient.h>\n\n" > rumpcalls
    228  1.102     pooka 	printf "#define rsys_syscall(num, data, dlen, retval)\t\\\n" > rumpcalls
    229  1.102     pooka 	printf "    rumpclient_syscall(num, data, dlen, retval)\n" > rumpcalls
    230  1.102     pooka 	printf "#define rsys_seterrno(error) errno = error\n" > rumpcalls
    231  1.102     pooka 	printf "#define rsys_alias(a,b)\n#else\n" > rumpcalls
    232  1.117     pooka 	printf "#include <sys/syscall.h>\n" > rumpcalls
    233  1.117     pooka 	printf "#include <sys/syscallargs.h>\n\n" > rumpcalls
    234  1.103     pooka 	printf "#include <sys/syscallvar.h>\n\n" > rumpcalls
    235   1.80     pooka 	printf "#include <rump/rumpuser.h>\n" > rumpcalls
    236   1.72     pooka 	printf "#include \"rump_private.h\"\n\n" > rumpcalls
    237  1.102     pooka 	printf "static int\nrsys_syscall" > rumpcalls
    238  1.102     pooka 	printf "(int num, void *data, size_t dlen, register_t *retval)" > rumpcalls
    239  1.103     pooka 	printf "\n{\n\tstruct sysent *callp = rump_sysent + num;\n" > rumpcalls
    240  1.103     pooka 	printf "\tint rv;\n" > rumpcalls
    241  1.103     pooka 	printf "\n\tKASSERT(num > 0 && num < SYS_NSYSENT);\n\n" > rumpcalls
    242  1.103     pooka 	printf "\trump_schedule();\n" > rumpcalls
    243  1.103     pooka 	printf "\trv = sy_call(callp, curlwp, data, retval);\n" > rumpcalls
    244  1.102     pooka 	printf "\trump_unschedule();\n\n\treturn rv;\n}\n\n" > rumpcalls
    245  1.102     pooka 	printf "#define rsys_seterrno(error) rumpuser_seterrno(error)\n" > rumpcalls
    246  1.102     pooka 	printf "#define rsys_alias(a,b) __weak_alias(a,b);\n#endif\n\n" > rumpcalls
    247  1.102     pooka 
    248   1.66     pooka 	printf "#if\tBYTE_ORDER == BIG_ENDIAN\n" > rumpcalls
    249   1.66     pooka 	printf "#define SPARG(p,k)\t((p)->k.be.datum)\n" > rumpcalls
    250   1.66     pooka 	printf "#else /* LITTLE_ENDIAN, I hope dearly */\n" > rumpcalls
    251   1.66     pooka 	printf "#define SPARG(p,k)\t((p)->k.le.datum)\n" > rumpcalls
    252   1.73     pooka 	printf "#endif\n\n" > rumpcalls
    253  1.102     pooka 	printf "#ifndef RUMP_CLIENT\n" > rumpcalls
    254   1.73     pooka 	printf "int rump_enosys(void);\n" > rumpcalls
    255   1.73     pooka 	printf "int\nrump_enosys()\n{\n\n\treturn ENOSYS;\n}\n" > rumpcalls
    256  1.102     pooka 	printf "#endif\n" > rumpcalls
    257   1.66     pooka 
    258  1.102     pooka 	printf "\n#ifndef RUMP_CLIENT\n" > rumpsysent
    259  1.102     pooka 	printf "#define\ts(type)\tsizeof(type)\n" > rumpsysent
    260   1.83     pooka 	printf "#define\tn(type)\t(sizeof(type)/sizeof (%s))\n", registertype > rumpsysent
    261   1.83     pooka 	printf "#define\tns(type)\tn(type), s(type)\n\n", registertype > rumpsysent
    262   1.83     pooka 	printf "struct sysent rump_sysent[] = {\n" > rumpsysent
    263   1.83     pooka 
    264   1.28   thorpej 	# System call names are included by userland (kdump(1)), so
    265   1.28   thorpej 	# hide the include files from it.
    266   1.48       mrg 	printf "#if defined(_KERNEL_OPT)\n" > sysnames
    267   1.28   thorpej 
    268   1.48       mrg 	printf "#endif /* _KERNEL_OPT */\n\n" > sysnamesbottom
    269   1.41   mycroft 	printf "const char *const %s[] = {\n",namesname > sysnamesbottom
    270   1.11       cgd 
    271   1.11       cgd 	printf " * created from%s\n */\n\n", $0 > sysnumhdr
    272   1.97     njoly 	printf "#ifndef _" constprefix "SYSCALL_H_\n" > sysnumhdr
    273   1.97     njoly 	printf "#define	_" constprefix "SYSCALL_H_\n\n" > sysnumhdr
    274   1.11       cgd 
    275   1.11       cgd 	printf " * created from%s\n */\n\n", $0 > sysarghdr
    276   1.97     njoly 	printf "#ifndef _" constprefix "SYSCALLARGS_H_\n" > sysarghdr
    277   1.97     njoly 	printf "#define	_" constprefix "SYSCALLARGS_H_\n\n" > sysarghdr
    278   1.66     pooka 
    279   1.66     pooka 	printf " * created from%s\n */\n\n", $0 > rumpcallshdr
    280   1.97     njoly 	printf "#ifndef _RUMP_RUMP_SYSCALLS_H_\n" > rumpcallshdr
    281   1.97     njoly 	printf "#define _RUMP_RUMP_SYSCALLS_H_\n\n" > rumpcallshdr
    282   1.96     pooka 	printf "#ifdef _KERNEL\n" > rumpcallshdr
    283   1.96     pooka 	printf "#error Interface not supported inside kernel\n" > rumpcallshdr
    284   1.96     pooka 	printf "#endif /* _KERNEL */\n\n" > rumpcallshdr
    285  1.109     pooka 	printf "#include <sys/types.h> /* typedefs */\n" > rumpcallshdr
    286  1.119  christos 	printf "#include <sys/select.h> /* typedefs */\n" > rumpcallshdr
    287  1.119  christos 	printf "#include <sys/sigtypes.h> /* typedefs */\n" > rumpcallshdr
    288  1.119  christos 	printf "#include <sys/socket.h> /* typedefs */\n\n" > rumpcallshdr
    289  1.109     pooka 	printf "#include <rump/rump_syscalls_compat.h>\n\n" > rumpcallshdr
    290   1.66     pooka 
    291   1.94     pooka 	printf "%s", sysarghdrextra > sysarghdr
    292   1.60       dsl 	# Write max number of system call arguments to both headers
    293   1.60       dsl 	printf("#define\t%sMAXSYSARGS\t%d\n\n", constprefix, maxsysargs) \
    294   1.60       dsl 		> sysnumhdr
    295   1.60       dsl 	printf("#define\t%sMAXSYSARGS\t%d\n\n", constprefix, maxsysargs) \
    296   1.60       dsl 		> sysarghdr
    297   1.30       eeh 	printf "#undef\tsyscallarg\n" > sysarghdr
    298   1.35   thorpej 	printf "#define\tsyscallarg(x)\t\t\t\t\t\t\t\\\n" > sysarghdr
    299   1.35   thorpej 	printf "\tunion {\t\t\t\t\t\t\t\t\\\n" > sysarghdr
    300   1.35   thorpej 	printf "\t\t%s pad;\t\t\t\t\t\t\\\n", registertype > sysarghdr
    301   1.35   thorpej 	printf "\t\tstruct { x datum; } le;\t\t\t\t\t\\\n" > sysarghdr
    302   1.51      manu 	printf "\t\tstruct { /* LINTED zero array dimension */\t\t\\\n" \
    303   1.51      manu 		> sysarghdr
    304   1.51      manu 	printf "\t\t\tint8_t pad[  /* CONSTCOND */\t\t\t\\\n" > sysarghdr
    305   1.51      manu 	printf "\t\t\t\t(sizeof (%s) < sizeof (x))\t\\\n", \
    306   1.30       eeh 		registertype > sysarghdr
    307   1.35   thorpej 	printf "\t\t\t\t? 0\t\t\t\t\t\\\n" > sysarghdr
    308   1.35   thorpej 	printf "\t\t\t\t: sizeof (%s) - sizeof (x)];\t\\\n", \
    309   1.30       eeh 		registertype > sysarghdr
    310   1.35   thorpej 	printf "\t\t\tx datum;\t\t\t\t\t\\\n" > sysarghdr
    311   1.35   thorpej 	printf "\t\t} be;\t\t\t\t\t\t\t\\\n" > sysarghdr
    312   1.35   thorpej 	printf "\t}\n" > sysarghdr
    313   1.60       dsl 	printf("\n#undef check_syscall_args\n") >sysarghdr
    314  1.101     pooka 	printf("#define check_syscall_args(call) /*LINTED*/ \\\n" \
    315   1.60       dsl 		"\ttypedef char call##_check_args" \
    316   1.60       dsl 		    "[sizeof (struct call##_args) \\\n" \
    317   1.60       dsl 		"\t\t<= %sMAXSYSARGS * sizeof (%s) ? 1 : -1];\n", \
    318   1.60       dsl 		constprefix, registertype) >sysarghdr
    319  1.109     pooka 
    320  1.109     pooka 	# compat types from syscalls.master.  this is slightly ugly,
    321  1.109     pooka 	# but given that we have so few compats from over 17 years,
    322  1.109     pooka 	# a more complicated solution is not currently warranted.
    323  1.109     pooka 	uncompattypes["struct timeval50"] = "struct timeval";
    324  1.109     pooka 	uncompattypes["struct timespec50"] = "struct timespec";
    325  1.109     pooka 	uncompattypes["struct stat30"] = "struct stat";
    326  1.109     pooka 
    327   1.11       cgd 	next
    328   1.11       cgd }
    329   1.11       cgd NF == 0 || $1 ~ /^;/ {
    330   1.11       cgd 	next
    331   1.11       cgd }
    332   1.40   mycroft $0 ~ /^%%$/ {
    333   1.40   mycroft 	intable = 1
    334   1.40   mycroft 	next
    335   1.40   mycroft }
    336   1.11       cgd $1 ~ /^#[ 	]*include/ {
    337   1.11       cgd 	print > sysdcl
    338   1.27   thorpej 	print > sysnames
    339   1.11       cgd 	next
    340   1.11       cgd }
    341   1.40   mycroft $1 ~ /^#/ && !intable {
    342   1.40   mycroft 	print > sysdcl
    343   1.40   mycroft 	print > sysnames
    344   1.11       cgd 	next
    345   1.11       cgd }
    346   1.40   mycroft $1 ~ /^#/ && intable {
    347   1.40   mycroft 	if ($1 ~ /^#[ 	]*if/) {
    348   1.40   mycroft 		savedepth++
    349   1.40   mycroft 		savesyscall[savedepth] = syscall
    350   1.40   mycroft 	}
    351   1.40   mycroft 	if ($1 ~ /^#[ 	]*else/) {
    352   1.40   mycroft 		if (savedepth <= 0) {
    353   1.40   mycroft 			printf("%s: line %d: unbalanced #else\n", \
    354   1.40   mycroft 			    infile, NR)
    355   1.40   mycroft 			exit 1
    356   1.40   mycroft 		}
    357   1.40   mycroft 		syscall = savesyscall[savedepth]
    358   1.18       cgd 	}
    359   1.18       cgd 	if ($1 ~ /^#[       ]*endif/) {
    360   1.18       cgd 		if (savedepth <= 0) {
    361   1.40   mycroft 			printf("%s: line %d: unbalanced #endif\n", \
    362   1.40   mycroft 			    infile, NR)
    363   1.18       cgd 			exit 1
    364   1.18       cgd 		}
    365   1.40   mycroft 		savedepth--
    366   1.18       cgd 	}
    367   1.11       cgd 	print > sysent
    368   1.54  christos 	print > sysarghdr
    369   1.54  christos 	print > sysnumhdr
    370   1.16   thorpej 	print > sysprotos
    371   1.27   thorpej 	print > sysnamesbottom
    372   1.83     pooka 
    373   1.83     pooka 	# XXX: technically we do not want to have conditionals in rump,
    374   1.83     pooka 	# but it is easier to just let the cpp handle them than try to
    375   1.83     pooka 	# figure out what we want here in this script
    376   1.83     pooka 	print > rumpsysent
    377   1.11       cgd 	next
    378   1.11       cgd }
    379   1.11       cgd syscall != $1 {
    380   1.11       cgd 	printf "%s: line %d: syscall number out of sync at %d\n", \
    381   1.11       cgd 	   infile, NR, syscall
    382   1.11       cgd 	printf "line is:\n"
    383   1.11       cgd 	print
    384   1.11       cgd 	exit 1
    385   1.11       cgd }
    386   1.11       cgd function parserr(was, wanted) {
    387   1.77     pooka 	printf "%s: line %d: unexpected %s (expected <%s>)\n", \
    388   1.11       cgd 	    infile, NR, was, wanted
    389   1.32  christos 	printf "line is:\n"
    390   1.32  christos 	print
    391   1.11       cgd 	exit 1
    392   1.11       cgd }
    393   1.11       cgd function parseline() {
    394   1.11       cgd 	f=3			# toss number and type
    395   1.60       dsl 	if ($2 == "INDIR")
    396   1.60       dsl 		sycall_flags="SYCALL_INDIRECT"
    397   1.60       dsl 	else
    398   1.60       dsl 		sycall_flags="0"
    399   1.11       cgd 	if ($NF != "}") {
    400   1.11       cgd 		funcalias=$NF
    401   1.11       cgd 		end=NF-1
    402   1.11       cgd 	} else {
    403   1.11       cgd 		funcalias=""
    404   1.11       cgd 		end=NF
    405   1.43  jdolecek 	}
    406   1.61       dsl 	if ($f == "INDIR") {		# allow for "NOARG INDIR"
    407   1.61       dsl 		sycall_flags = "SYCALL_INDIRECT | " sycall_flags
    408   1.61       dsl 		f++
    409   1.61       dsl 	}
    410   1.74        ad 	if ($f == "MODULAR") {		# registered at runtime
    411   1.74        ad 		modular = 1
    412   1.74        ad 		f++
    413   1.74        ad 	} else {
    414   1.74        ad 		modular =  0;
    415   1.74        ad 	}
    416   1.66     pooka 	if ($f == "RUMP") {
    417   1.66     pooka 		rumpable = 1
    418   1.66     pooka 		f++
    419   1.66     pooka 	} else {
    420   1.66     pooka 		rumpable = 0
    421   1.66     pooka 	}
    422   1.43  jdolecek 	if ($f ~ /^[a-z0-9_]*$/) {	# allow syscall alias
    423   1.43  jdolecek 		funcalias=$f
    424   1.43  jdolecek 		f++
    425   1.11       cgd 	}
    426   1.11       cgd 	if ($f != "{")
    427   1.11       cgd 		parserr($f, "{")
    428   1.11       cgd 	f++
    429   1.11       cgd 	if ($end != "}")
    430   1.11       cgd 		parserr($end, "}")
    431   1.11       cgd 	end--
    432   1.11       cgd 	if ($end != ";")
    433   1.11       cgd 		parserr($end, ";")
    434   1.11       cgd 	end--
    435   1.11       cgd 	if ($end != ")")
    436   1.11       cgd 		parserr($end, ")")
    437   1.11       cgd 	end--
    438   1.11       cgd 
    439   1.19       cgd 	returntype = oldf = "";
    440   1.19       cgd 	do {
    441   1.19       cgd 		if (returntype != "" && oldf != "*")
    442   1.19       cgd 			returntype = returntype" ";
    443   1.19       cgd 		returntype = returntype$f;
    444   1.19       cgd 		oldf = $f;
    445   1.19       cgd 		f++
    446   1.78     pooka 	} while ($f != "|" && f < (end-1))
    447   1.19       cgd 	if (f == (end - 1)) {
    448   1.78     pooka 		parserr($f, "function argument definition (maybe \"|\"?)");
    449   1.78     pooka 	}
    450   1.78     pooka 	f++
    451   1.78     pooka 
    452   1.78     pooka 	fprefix=$f
    453   1.78     pooka 	f++
    454   1.78     pooka 	if ($f != "|") {
    455   1.78     pooka 		parserr($f, "function compat delimiter (maybe \"|\"?)");
    456   1.78     pooka 	}
    457   1.78     pooka 	f++
    458   1.78     pooka 
    459   1.78     pooka 	fcompat=""
    460   1.78     pooka 	if ($f != "|") {
    461   1.78     pooka 		fcompat=$f
    462   1.78     pooka 		f++
    463   1.78     pooka 	}
    464   1.78     pooka 
    465   1.78     pooka 	if ($f != "|") {
    466   1.78     pooka 		parserr($f, "function name delimiter (maybe \"|\"?)");
    467   1.78     pooka 	}
    468   1.78     pooka 	f++
    469   1.78     pooka 	fbase=$f
    470   1.78     pooka 
    471   1.90     pooka 	# pipe is special in how to returns its values.
    472   1.90     pooka 	# So just generate it manually if present.
    473   1.90     pooka 	if (rumpable == 1 && fbase == "pipe") {
    474   1.90     pooka 		rumpable = 0;
    475   1.90     pooka 		rumphaspipe = 1;
    476   1.90     pooka 	}
    477   1.90     pooka 
    478   1.78     pooka 	if (fcompat != "") {
    479   1.78     pooka 		funcname=fprefix "___" fbase "" fcompat
    480   1.78     pooka 	} else {
    481  1.109     pooka 		funcname=fprefix "_" fbase
    482   1.19       cgd 	}
    483   1.92      matt 	if (returntype == "quad_t" || returntype == "off_t") {
    484   1.92      matt 		if (sycall_flags == "0")
    485   1.92      matt 			sycall_flags = "SYCALL_RET_64";
    486   1.92      matt 		else
    487   1.92      matt 			sycall_flags = "SYCALL_RET_64 | " sycall_flags;
    488   1.92      matt 	}
    489   1.11       cgd 
    490   1.17   mycroft 	if (funcalias == "") {
    491   1.11       cgd 		funcalias=funcname
    492   1.17   mycroft 		sub(/^([^_]+_)*sys_/, "", funcalias)
    493  1.109     pooka 		realname=fbase
    494  1.109     pooka 	} else {
    495  1.109     pooka 		realname=funcalias
    496   1.17   mycroft 	}
    497  1.109     pooka 	rumpfname=realname "" fcompat
    498   1.11       cgd 	f++
    499   1.11       cgd 
    500   1.11       cgd 	if ($f != "(")
    501   1.76     pooka 		parserr($f, "(")
    502   1.11       cgd 	f++
    503   1.11       cgd 
    504   1.19       cgd 	argc=0;
    505   1.63      yamt 	argalign=0;
    506   1.11       cgd 	if (f == end) {
    507   1.11       cgd 		if ($f != "void")
    508   1.11       cgd 			parserr($f, "argument definition")
    509   1.19       cgd 		isvarargs = 0;
    510   1.19       cgd 		varargc = 0;
    511   1.80     pooka 		argtype[0]="void";
    512   1.11       cgd 		return
    513   1.11       cgd 	}
    514   1.11       cgd 
    515   1.19       cgd 	# some system calls (open() and fcntl()) can accept a variable
    516   1.19       cgd 	# number of arguments.  If syscalls accept a variable number of
    517   1.19       cgd 	# arguments, they must still have arguments specified for
    518   1.19       cgd 	# the remaining argument "positions," because of the way the
    519   1.19       cgd 	# kernel system call argument handling works.
    520   1.19       cgd 	#
    521   1.19       cgd 	# Indirect system calls, e.g. syscall(), are exceptions to this
    522   1.19       cgd 	# rule, since they are handled entirely by machine-dependent code
    523   1.19       cgd 	# and do not need argument structures built.
    524   1.19       cgd 
    525   1.19       cgd 	isvarargs = 0;
    526   1.92      matt 	args64 = 0;
    527   1.11       cgd 	while (f <= end) {
    528   1.19       cgd 		if ($f == "...") {
    529   1.19       cgd 			f++;
    530   1.19       cgd 			isvarargs = 1;
    531   1.19       cgd 			varargc = argc;
    532   1.19       cgd 			continue;
    533   1.19       cgd 		}
    534   1.11       cgd 		argc++
    535   1.11       cgd 		argtype[argc]=""
    536   1.14       cgd 		oldf=""
    537   1.11       cgd 		while (f < end && $(f+1) != ",") {
    538   1.14       cgd 			if (argtype[argc] != "" && oldf != "*")
    539   1.11       cgd 				argtype[argc] = argtype[argc]" ";
    540   1.11       cgd 			argtype[argc] = argtype[argc]$f;
    541   1.14       cgd 			oldf = $f;
    542   1.11       cgd 			f++
    543   1.11       cgd 		}
    544   1.11       cgd 		if (argtype[argc] == "")
    545   1.11       cgd 			parserr($f, "argument definition")
    546   1.86     pooka 		if (argtype[argc] == "off_t"  \
    547   1.86     pooka 		  || argtype[argc] == "dev_t" \
    548   1.86     pooka 		  || argtype[argc] == "time_t") {
    549   1.68  christos 			if ((argalign % 2) != 0 && sysalign &&
    550   1.63      yamt 			    funcname != "sys_posix_fadvise") # XXX for now
    551   1.63      yamt 				parserr($f, "a padding argument")
    552   1.63      yamt 		} else {
    553   1.63      yamt 			argalign++;
    554   1.63      yamt 		}
    555   1.93     skrll 		if (argtype[argc] == "quad_t" || argtype[argc] == "off_t" \
    556   1.93     skrll 		  || argtype[argc] == "dev_t" || argtype[argc] == "time_t") {
    557   1.92      matt 			if (sycall_flags == "0")
    558   1.92      matt 				sycall_flags = "SYCALL_ARG"argc-1"_64";
    559   1.92      matt 			else
    560   1.92      matt 				sycall_flags = "SYCALL_ARG"argc-1"_64 | " sycall_flags;
    561   1.92      matt 			args64++;
    562   1.92      matt 		}
    563   1.11       cgd 		argname[argc]=$f;
    564   1.11       cgd 		f += 2;			# skip name, and any comma
    565   1.11       cgd 	}
    566   1.92      matt 	if (args64 > 0)
    567   1.92      matt 		sycall_flags = "SYCALL_NARGS64_VAL("args64") | " sycall_flags;
    568   1.19       cgd 	# must see another argument after varargs notice.
    569   1.19       cgd 	if (isvarargs) {
    570   1.61       dsl 		if (argc == varargc)
    571   1.19       cgd 			parserr($f, "argument definition")
    572   1.19       cgd 	} else
    573   1.19       cgd 		varargc = argc;
    574   1.11       cgd }
    575   1.54  christos 
    576   1.54  christos function printproto(wrap) {
    577   1.54  christos 	printf("/* syscall: \"%s%s\" ret: \"%s\" args:", wrap, funcalias,
    578   1.54  christos 	    returntype) > sysnumhdr
    579   1.54  christos 	for (i = 1; i <= varargc; i++)
    580   1.54  christos 		printf(" \"%s\"", argtype[i]) > sysnumhdr
    581   1.54  christos 	if (isvarargs)
    582   1.54  christos 		printf(" \"...\"") > sysnumhdr
    583   1.54  christos 	printf(" */\n") > sysnumhdr
    584   1.54  christos 	printf("#define\t%s%s%s\t%d\n\n", constprefix, wrap, funcalias,
    585   1.54  christos 	    syscall) > sysnumhdr
    586   1.66     pooka 
    587   1.66     pooka 	# rumpalooza
    588   1.66     pooka 	if (!rumpable)
    589   1.66     pooka 		return
    590   1.66     pooka 
    591  1.109     pooka 	# accumulate fbases we have seen.  we want the last
    592  1.109     pooka 	# occurence for the default __RENAME()
    593  1.109     pooka 	seen = funcseen[fbase]
    594  1.109     pooka 	funcseen[fbase] = rumpfname
    595  1.109     pooka 	if (seen)
    596  1.109     pooka 		return
    597  1.109     pooka 
    598  1.109     pooka 	printf("%s rump_sys_%s(", returntype, realname) > rumpprotos
    599  1.109     pooka 
    600   1.88     pooka 	for (i = 1; i < varargc; i++)
    601   1.87     pooka 		if (argname[i] != "PAD")
    602  1.109     pooka 			printf("%s, ", uncompattype(argtype[i])) > rumpprotos
    603  1.109     pooka 
    604   1.88     pooka 	if (isvarargs)
    605  1.109     pooka 		printf("%s, ...)", uncompattype(argtype[varargc]))>rumpprotos
    606   1.88     pooka 	else
    607  1.109     pooka 		printf("%s)", uncompattype(argtype[argc])) > rumpprotos
    608  1.109     pooka 
    609  1.109     pooka 	printf(" __RENAME(RUMP_SYS_RENAME_%s)", toupper(fbase))> rumpprotos
    610  1.109     pooka 	printf(";\n") > rumpprotos
    611  1.109     pooka 
    612  1.109     pooka 	# generate forward-declares for types, apart from the
    613  1.109     pooka 	# braindead typedef jungle we cannot easily handle here
    614  1.109     pooka 	for (i = 1; i <= varargc; i++) {
    615  1.109     pooka 		type=uncompattype(argtype[i])
    616  1.109     pooka 		sub("const ", "", type)
    617  1.109     pooka 		if (!typeseen[type] && \
    618  1.109     pooka 		    match(type, "struct") && match(type, "\\*")) {
    619  1.109     pooka 			typeseen[type] = 1
    620  1.109     pooka 			sub(" *\\*", "", type);
    621  1.109     pooka 			printf("%s;\n", type) > rumptypes
    622  1.109     pooka 		}
    623  1.109     pooka 	}
    624   1.54  christos }
    625   1.54  christos 
    626   1.90     pooka function printrumpsysent(insysent, compatwrap) {
    627   1.90     pooka 	if (!insysent) {
    628   1.95     pooka 		eno[0] = "rump_enosys"
    629   1.95     pooka 		eno[1] = "sys_nomodule"
    630  1.107     pooka 		flags[0] = "SYCALL_NOSYS"
    631  1.107     pooka 		flags[1] = "0"
    632  1.107     pooka 		printf("\t{ 0, 0, %s,\n\t    (sy_call_t *)%s }, \t"	\
    633  1.108     pooka 		    "/* %d = %s */\n",					\
    634  1.108     pooka 		    flags[modular], eno[modular], syscall, funcalias)	\
    635  1.108     pooka 		    > rumpsysent
    636   1.90     pooka 		return
    637   1.90     pooka 	}
    638   1.90     pooka 
    639   1.90     pooka 	printf("\t{ ") > rumpsysent
    640   1.90     pooka 	if (argc == 0) {
    641   1.90     pooka 		printf("0, 0, ") > rumpsysent
    642   1.90     pooka 	} else {
    643  1.109     pooka 		printf("ns(struct %ssys_%s_args), ", compatwrap_, funcalias) > rumpsysent
    644  1.109     pooka 	}
    645  1.109     pooka 
    646  1.109     pooka 	if (compatwrap == "") {
    647  1.109     pooka 		if (modular)
    648  1.109     pooka 			rfn = "(sy_call_t *)sys_nomodule"
    649  1.109     pooka 		else
    650  1.109     pooka 			rfn = "(sy_call_t *)" funcname
    651  1.109     pooka 	} else {
    652  1.109     pooka 		rfn = "(sy_call_t *)" compatwrap "_" funcname
    653   1.90     pooka 	}
    654  1.109     pooka 
    655  1.109     pooka 	printf("0,\n\t    %s },", rfn) > rumpsysent
    656  1.109     pooka 	for (i = 0; i < (33 - length(rfn)) / 8; i++)
    657   1.90     pooka 		printf("\t") > rumpsysent
    658   1.90     pooka 	printf("/* %d = %s%s */\n", syscall, compatwrap_, funcalias) > rumpsysent
    659   1.90     pooka }
    660   1.90     pooka 
    661  1.109     pooka function iscompattype(type) {
    662  1.109     pooka 	for (var in uncompattypes) {
    663  1.109     pooka 		if (match(type, var)) {
    664  1.109     pooka 			return 1
    665  1.109     pooka 		}
    666  1.109     pooka 	}
    667  1.109     pooka 
    668  1.109     pooka 	return 0
    669  1.109     pooka }
    670  1.109     pooka 
    671  1.109     pooka function uncompattype(type) {
    672  1.109     pooka 	for (var in uncompattypes) {
    673  1.109     pooka 		if (match(type, var)) {
    674  1.109     pooka 			sub(var, uncompattypes[var], type)
    675  1.109     pooka 			return type
    676  1.109     pooka 		}
    677  1.109     pooka 	}
    678  1.109     pooka 
    679  1.109     pooka 	return type
    680  1.109     pooka }
    681  1.109     pooka 
    682   1.61       dsl function putent(type, compatwrap) {
    683   1.60       dsl 	# output syscall declaration for switch table.
    684   1.60       dsl 	if (compatwrap == "")
    685   1.60       dsl 		compatwrap_ = ""
    686   1.60       dsl 	else
    687   1.60       dsl 		compatwrap_ = compatwrap "_"
    688   1.62       dsl 	if (argc == 0)
    689   1.62       dsl 		arg_type = "void";
    690   1.62       dsl 	else {
    691   1.62       dsl 		arg_type = "struct " compatwrap_ funcname "_args";
    692   1.62       dsl 	}
    693   1.62       dsl 	proto = "int\t" compatwrap_ funcname "(struct lwp *, const " \
    694   1.62       dsl 	    arg_type " *, register_t *);\n"
    695   1.60       dsl 	if (sysmap[proto] != 1) {
    696   1.60       dsl 		sysmap[proto] = 1;
    697   1.60       dsl 		print proto > sysprotos;
    698   1.21       cgd 	}
    699   1.11       cgd 
    700   1.11       cgd 	# output syscall switch entry
    701   1.60       dsl 	printf("\t{ ") > sysent
    702   1.60       dsl 	if (argc == 0) {
    703   1.60       dsl 		printf("0, 0, ") > sysent
    704   1.19       cgd 	} else {
    705   1.60       dsl 		printf("ns(struct %s%s_args), ", compatwrap_, funcname) > sysent
    706   1.19       cgd 	}
    707   1.74        ad 	if (modular) 
    708   1.74        ad 		wfn = "(sy_call_t *)sys_nomodule";
    709   1.74        ad 	else if (compatwrap == "")
    710   1.62       dsl 		wfn = "(sy_call_t *)" funcname;
    711   1.60       dsl 	else
    712   1.62       dsl 		wfn = "(sy_call_t *)" compatwrap "(" funcname ")";
    713   1.60       dsl 	printf("%s,\n\t    %s },", sycall_flags, wfn) > sysent
    714   1.60       dsl 	for (i = 0; i < (33 - length(wfn)) / 8; i++)
    715   1.60       dsl 		printf("\t") > sysent
    716   1.60       dsl 	printf("/* %d = %s%s */\n", syscall, compatwrap_, funcalias) > sysent
    717   1.11       cgd 
    718   1.11       cgd 	# output syscall name for names table
    719   1.60       dsl 	printf("\t/* %3d */\t\"%s%s\",\n", syscall, compatwrap_, funcalias) \
    720   1.60       dsl 	    > sysnamesbottom
    721   1.11       cgd 
    722   1.11       cgd 	# output syscall number of header, if appropriate
    723  1.111     pooka 	if (type == "STD" || type == "NOARGS" || type == "INDIR" || \
    724  1.111     pooka 	    type == "NOERR") {
    725   1.19       cgd 		# output a prototype, to be used to generate lint stubs in
    726   1.19       cgd 		# libc.
    727   1.54  christos 		printproto("")
    728   1.61       dsl 	} else if (type == "COMPAT") {
    729   1.29   thorpej 		# Just define the syscall number with a comment.  These
    730   1.29   thorpej 		# may be used by compatibility stubs in libc.
    731   1.60       dsl 		printproto(compatwrap_)
    732   1.60       dsl 	}
    733   1.11       cgd 
    734   1.11       cgd 	# output syscall argument structure, if it has arguments
    735   1.62       dsl 	if (argc != 0) {
    736   1.62       dsl 		printf("\nstruct %s%s_args", compatwrap_, funcname) > sysarghdr
    737   1.62       dsl 		if (type != "NOARGS") {
    738   1.62       dsl 			print " {" >sysarghdr;
    739   1.62       dsl 			for (i = 1; i <= argc; i++)
    740   1.62       dsl 				printf("\tsyscallarg(%s) %s;\n", argtype[i],
    741   1.62       dsl 				    argname[i]) > sysarghdr
    742   1.62       dsl 			printf "}" >sysarghdr;
    743   1.62       dsl 		}
    744   1.62       dsl 		printf(";\n") > sysarghdr
    745   1.62       dsl 		if (type != "NOARGS" && type != "INDIR") {
    746   1.60       dsl 			printf("check_syscall_args(%s%s)\n", compatwrap_,
    747   1.60       dsl 			    funcname) >sysarghdr
    748   1.60       dsl 		}
    749   1.11       cgd 	}
    750   1.66     pooka 
    751   1.90     pooka 	if (!rumpable) {
    752   1.90     pooka 		if (funcname == "sys_pipe" && rumphaspipe == 1)
    753   1.90     pooka 			insysent = 1
    754   1.90     pooka 		else
    755   1.90     pooka 			insysent = 0
    756   1.90     pooka 	} else {
    757   1.90     pooka 		insysent = 1
    758   1.90     pooka 	}
    759   1.90     pooka 	printrumpsysent(insysent, compatwrap)
    760   1.90     pooka 
    761   1.66     pooka 	# output rump marshalling code if necessary
    762   1.83     pooka 	if (!rumpable) {
    763   1.66     pooka 		return
    764   1.83     pooka 	}
    765   1.66     pooka 
    766   1.78     pooka 	# need a local prototype, we export the re-re-named one in .h
    767  1.109     pooka 	printf("\n%s rump___sysimpl_%s(", returntype, rumpfname) \
    768  1.109     pooka 	    > rumpcalls
    769   1.80     pooka 	for (i = 1; i < argc; i++) {
    770   1.87     pooka 		if (argname[i] != "PAD")
    771  1.109     pooka 			printf("%s, ", uncompattype(argtype[i])) > rumpcalls
    772   1.78     pooka 	}
    773  1.109     pooka 	printf("%s);", uncompattype(argtype[argc])) > rumpcalls
    774   1.78     pooka 
    775  1.109     pooka 	printf("\n%s\nrump___sysimpl_%s(", returntype, rumpfname) > rumpcalls
    776   1.80     pooka 	for (i = 1; i < argc; i++) {
    777   1.87     pooka 		if (argname[i] != "PAD")
    778  1.109     pooka 			printf("%s %s, ", uncompattype(argtype[i]), \
    779  1.109     pooka 			    argname[i]) > rumpcalls
    780   1.66     pooka 	}
    781  1.109     pooka 	printf("%s %s)\n", uncompattype(argtype[argc]), argname[argc]) \
    782  1.109     pooka 	    > rumpcalls
    783  1.115     pooka 	printf("{\n\tregister_t retval[2] = {0, 0};\n") > rumpcalls
    784  1.115     pooka 	if (returntype != "void") {
    785  1.115     pooka 		if (type != "NOERR") {
    786  1.115     pooka 			printf("\tint error = 0;\n") > rumpcalls
    787  1.115     pooka 		}
    788  1.115     pooka 		# assume rumpcalls return only integral types
    789  1.115     pooka 		printf("\t%s rv = -1;\n", returntype) > rumpcalls
    790  1.115     pooka 	}
    791   1.78     pooka 
    792   1.66     pooka 	argarg = "NULL"
    793   1.83     pooka 	argsize = 0;
    794   1.66     pooka 	if (argc) {
    795   1.84     pooka 		argarg = "&callarg"
    796   1.84     pooka 		argsize = "sizeof(callarg)"
    797   1.84     pooka 		printf("\tstruct %s%s_args callarg;\n\n",compatwrap_,funcname) \
    798   1.66     pooka 		    > rumpcalls
    799   1.66     pooka 		for (i = 1; i <= argc; i++) {
    800   1.87     pooka 			if (argname[i] == "PAD") {
    801   1.87     pooka 				printf("\tSPARG(&callarg, %s) = 0;\n", \
    802   1.87     pooka 				    argname[i]) > rumpcalls
    803   1.87     pooka 			} else {
    804  1.109     pooka 				if (iscompattype(argtype[i])) {
    805  1.109     pooka 					printf("\tSPARG(&callarg, %s) = "    \
    806  1.109     pooka 					"(%s)%s;\n", argname[i], argtype[i], \
    807  1.109     pooka 					argname[i]) > rumpcalls
    808  1.109     pooka 				} else {
    809  1.109     pooka 					printf("\tSPARG(&callarg, %s) = %s;\n",\
    810  1.109     pooka 					    argname[i], argname[i]) > rumpcalls
    811  1.109     pooka 				}
    812   1.87     pooka 			}
    813   1.66     pooka 		}
    814   1.66     pooka 		printf("\n") > rumpcalls
    815   1.66     pooka 	} else {
    816   1.66     pooka 		printf("\n") > rumpcalls
    817   1.66     pooka 	}
    818  1.111     pooka 	printf("\t") > rumpcalls
    819  1.112     pooka 	if (returntype != "void" && type != "NOERR")
    820  1.111     pooka 		printf("error = ") > rumpcalls
    821  1.111     pooka 	printf("rsys_syscall(%s%s%s, " \
    822  1.115     pooka 	    "%s, %s, retval);\n", constprefix, compatwrap_, funcalias, \
    823   1.83     pooka 	    argarg, argsize) > rumpcalls
    824  1.111     pooka 	if (type != "NOERR") {
    825  1.111     pooka 		printf("\trsys_seterrno(error);\n") > rumpcalls
    826  1.115     pooka 		printf("\tif (error == 0) {\n") > rumpcalls
    827  1.115     pooka 		indent="\t\t"
    828  1.115     pooka 		ending="\t}\n"
    829  1.115     pooka 	} else {
    830  1.115     pooka 		indent="\t"
    831  1.115     pooka 		ending=""
    832  1.111     pooka 	}
    833   1.80     pooka 	if (returntype != "void") {
    834  1.115     pooka 		printf("%sif (sizeof(%s) > sizeof(register_t))\n", \
    835  1.115     pooka 		    indent, returntype) > rumpcalls
    836  1.115     pooka 		printf("%s\trv = *(%s *)retval;\n", \
    837  1.115     pooka 		    indent, returntype) > rumpcalls
    838  1.115     pooka 		printf("%selse\n", indent, indent) > rumpcalls
    839  1.116     pooka 		printf("%s\trv = *retval;\n", indent, returntype) > rumpcalls
    840  1.115     pooka 		printf("%s", ending) > rumpcalls
    841  1.115     pooka 		printf("\treturn rv;\n") > rumpcalls
    842   1.80     pooka 	}
    843   1.72     pooka 	printf("}\n") > rumpcalls
    844  1.109     pooka 	printf("rsys_alias(%s%s,rump_enosys)\n", \
    845  1.109     pooka 	    compatwrap_, funcname) > rumpcalls
    846   1.83     pooka 
    847   1.11       cgd }
    848  1.111     pooka $2 == "STD" || $2 == "NODEF" || $2 == "NOARGS" || $2 == "INDIR" \
    849  1.111     pooka     || $2 == "NOERR" {
    850   1.11       cgd 	parseline()
    851   1.17   mycroft 	putent($2, "")
    852   1.11       cgd 	syscall++
    853   1.11       cgd 	next
    854   1.11       cgd }
    855   1.64    martin $2 == "OBSOL" || $2 == "UNIMPL" || $2 == "EXCL" || $2 == "IGNORED" {
    856   1.11       cgd 	if ($2 == "OBSOL")
    857   1.11       cgd 		comment="obsolete"
    858   1.34  christos 	else if ($2 == "EXCL")
    859   1.34  christos 		comment="excluded"
    860   1.64    martin 	else if ($2 == "IGNORED")
    861   1.64    martin 		comment="ignored"
    862   1.11       cgd 	else
    863   1.11       cgd 		comment="unimplemented"
    864   1.11       cgd 	for (i = 3; i <= NF; i++)
    865   1.11       cgd 		comment=comment " " $i
    866   1.11       cgd 
    867   1.64    martin 	if ($2 == "IGNORED")
    868   1.64    martin 		sys_stub = "(sy_call_t *)nullop";
    869   1.64    martin 	else
    870   1.65     njoly 		sys_stub = sys_nosys;
    871   1.64    martin 
    872   1.46  jdolecek 	printf("\t{ 0, 0, 0,\n\t    %s },\t\t\t/* %d = %s */\n", \
    873   1.64    martin 	    sys_stub, syscall, comment) > sysent
    874  1.107     pooka 	printf("\t{ 0, 0, SYCALL_NOSYS,\n\t    %s },\t\t/* %d = %s */\n", \
    875   1.83     pooka 	    "(sy_call_t *)rump_enosys", syscall, comment) > rumpsysent
    876   1.60       dsl 	printf("\t/* %3d */\t\"#%d (%s)\",\n", syscall, syscall, comment) \
    877   1.60       dsl 	    > sysnamesbottom
    878   1.11       cgd 	if ($2 != "UNIMPL")
    879   1.11       cgd 		printf("\t\t\t\t/* %d is %s */\n", syscall, comment) > sysnumhdr
    880   1.11       cgd 	syscall++
    881   1.11       cgd 	next
    882   1.11       cgd }
    883   1.11       cgd {
    884   1.11       cgd 	for (i = 1; i <= ncompat; i++) {
    885   1.11       cgd 		if ($2 == compat_upper[i]) {
    886   1.11       cgd 			parseline();
    887   1.29   thorpej 			putent("COMPAT", compat[i])
    888   1.11       cgd 			syscall++
    889   1.11       cgd 			next
    890   1.11       cgd 		}
    891   1.11       cgd 	}
    892   1.40   mycroft 	printf("%s: line %d: unrecognized keyword %s\n", infile, NR, $2)
    893    1.1     glass 	exit 1
    894   1.11       cgd }
    895   1.11       cgd END {
    896  1.115     pooka 	# output pipe() syscall with its special retval[2] handling
    897   1.90     pooka 	if (rumphaspipe) {
    898  1.109     pooka 		printf("int rump_sys_pipe(int *);\n") > rumpprotos
    899   1.90     pooka 		printf("\nint rump_sys_pipe(int *);\n") > rumpcalls
    900   1.90     pooka 		printf("int\nrump_sys_pipe(int *fd)\n{\n") > rumpcalls
    901  1.115     pooka 		printf("\tregister_t retval[2] = {0, 0};\n") > rumpcalls
    902   1.90     pooka 		printf("\tint error = 0;\n") > rumpcalls
    903  1.102     pooka 		printf("\n\terror = rsys_syscall(SYS_pipe, ") > rumpcalls
    904  1.115     pooka 		printf("NULL, 0, retval);\n") > rumpcalls
    905   1.90     pooka 		printf("\tif (error) {\n") > rumpcalls
    906  1.102     pooka 		printf("\t\trsys_seterrno(error);\n") > rumpcalls
    907  1.115     pooka 		printf("\t} else {\n\t\tfd[0] = retval[0];\n") > rumpcalls
    908  1.115     pooka 		printf("\t\tfd[1] = retval[1];\n\t}\n") > rumpcalls
    909   1.90     pooka 		printf("\treturn error ? -1 : 0;\n}\n") > rumpcalls
    910   1.90     pooka 	}
    911   1.90     pooka 
    912  1.109     pooka 	# print default rump syscall interfaces
    913  1.109     pooka 	for (var in funcseen) {
    914  1.109     pooka 		printf("#ifndef RUMP_SYS_RENAME_%s\n", \
    915  1.109     pooka 		    toupper(var)) > rumpcallshdr
    916  1.109     pooka 		printf("#define RUMP_SYS_RENAME_%s rump___sysimpl_%s\n", \
    917  1.109     pooka 		    toupper(var), funcseen[var]) > rumpcallshdr
    918  1.109     pooka 		printf("#endif\n\n") > rumpcallshdr
    919  1.109     pooka 	}
    920  1.109     pooka 
    921   1.40   mycroft 	maxsyscall = syscall
    922   1.40   mycroft 	if (nsysent) {
    923   1.40   mycroft 		if (syscall > nsysent) {
    924   1.50       wiz 			printf("%s: line %d: too many syscalls [%d > %d]\n", infile, NR, syscall, nsysent)
    925   1.40   mycroft 			exit 1
    926   1.40   mycroft 		}
    927   1.40   mycroft 		while (syscall < nsysent) {
    928   1.46  jdolecek 			printf("\t{ 0, 0, 0,\n\t    %s },\t\t\t/* %d = filler */\n", \
    929   1.46  jdolecek 			    sys_nosys, syscall) > sysent
    930  1.107     pooka 			printf("\t{ 0, 0, SYCALL_NOSYS,\n\t    %s },\t\t/* %d = filler */\n", \
    931   1.83     pooka 			    "(sy_call_t *)rump_enosys", syscall) > rumpsysent
    932  1.105     pooka 			printf("\t/* %3d */\t\"# filler\",\n", syscall) \
    933  1.105     pooka 			    > sysnamesbottom
    934   1.40   mycroft 			syscall++
    935   1.40   mycroft 		}
    936   1.40   mycroft 	}
    937   1.82     pooka 	printf("};\n") > sysent
    938   1.83     pooka 	printf("};\n") > rumpsysent
    939   1.83     pooka 	printf("CTASSERT(__arraycount(rump_sysent) == SYS_NSYSENT);\n") > rumpsysent
    940  1.102     pooka 	printf("#endif /* RUMP_CLIENT */\n") > rumpsysent
    941   1.27   thorpej 	printf("};\n") > sysnamesbottom
    942   1.40   mycroft 	printf("#define\t%sMAXSYSCALL\t%d\n", constprefix, maxsyscall) > sysnumhdr
    943   1.40   mycroft 	if (nsysent)
    944   1.40   mycroft 		printf("#define\t%sNSYSENT\t%d\n", constprefix, nsysent) > sysnumhdr
    945   1.11       cgd } '
    946    1.1     glass 
    947   1.17   mycroft cat $sysprotos >> $sysarghdr
    948   1.59  christos echo "#endif /* _${constprefix}SYSCALL_H_ */" >> $sysnumhdr
    949   1.59  christos echo "#endif /* _${constprefix}SYSCALLARGS_H_ */" >> $sysarghdr
    950  1.109     pooka printf "\n#endif /* _RUMP_RUMP_SYSCALLS_H_ */\n" >> $rumpprotos
    951   1.16   thorpej cat $sysdcl $sysent > $syssw
    952   1.27   thorpej cat $sysnamesbottom >> $sysnames
    953   1.83     pooka cat $rumpsysent >> $rumpcalls
    954    1.1     glass 
    955  1.118     njoly touch $rumptypes
    956  1.109     pooka cat $rumptypes >> $rumpcallshdr
    957  1.109     pooka echo >> $rumpcallshdr
    958  1.109     pooka cat $rumpprotos >> $rumpcallshdr
    959  1.109     pooka 
    960   1.15  christos #chmod 444 $sysnames $sysnumhdr $syssw
    961