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