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