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