Home | History | Annotate | Line # | Download | only in kern
makesyscalls.sh revision 1.63.6.4
      1       1.1     glass #! /bin/sh -
      2  1.63.6.1       mjf #	$NetBSD: makesyscalls.sh,v 1.63.6.4 2009/01/17 13:29:19 mjf Exp $
      3       1.9       cgd #
      4      1.37       cgd # Copyright (c) 1994, 1996, 2000 Christopher G. Demetriou
      5      1.12       cgd # All rights reserved.
      6      1.12       cgd #
      7      1.12       cgd # Redistribution and use in source and binary forms, with or without
      8      1.12       cgd # modification, are permitted provided that the following conditions
      9      1.12       cgd # are met:
     10      1.12       cgd # 1. Redistributions of source code must retain the above copyright
     11      1.12       cgd #    notice, this list of conditions and the following disclaimer.
     12      1.12       cgd # 2. Redistributions in binary form must reproduce the above copyright
     13      1.12       cgd #    notice, this list of conditions and the following disclaimer in the
     14      1.12       cgd #    documentation and/or other materials provided with the distribution.
     15      1.12       cgd # 3. All advertising materials mentioning features or use of this software
     16      1.12       cgd #    must display the following acknowledgement:
     17      1.12       cgd #      This product includes software developed for the NetBSD Project
     18      1.12       cgd #      by Christopher G. Demetriou.
     19      1.12       cgd # 4. The name of the author may not be used to endorse or promote products
     20      1.12       cgd #    derived from this software without specific prior written permission
     21      1.12       cgd #
     22      1.12       cgd # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23      1.12       cgd # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24      1.12       cgd # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25      1.12       cgd # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26      1.12       cgd # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27      1.12       cgd # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28      1.12       cgd # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29      1.12       cgd # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30      1.12       cgd # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31      1.12       cgd # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32      1.14       cgd 
     33      1.14       cgd #	@(#)makesyscalls.sh	8.1 (Berkeley) 6/10/93
     34       1.1     glass 
     35       1.1     glass set -e
     36       1.1     glass 
     37      1.11       cgd case $# in
     38      1.11       cgd     2)	;;
     39      1.11       cgd     *)	echo "Usage: $0 config-file input-file" 1>&2
     40      1.11       cgd 	exit 1
     41      1.11       cgd 	;;
     42      1.11       cgd esac
     43      1.11       cgd 
     44      1.11       cgd # the config file sets the following variables:
     45  1.63.6.1       mjf #	sysalign	check for alignment of off_t
     46      1.11       cgd #	sysnames	the syscall names file
     47      1.11       cgd #	sysnumhdr	the syscall numbers file
     48      1.11       cgd #	syssw		the syscall switch file
     49      1.11       cgd #	sysarghdr	the syscall argument struct definitions
     50      1.11       cgd #	compatopts	those syscall types that are for 'compat' syscalls
     51      1.11       cgd #	switchname	the name for the 'struct sysent' we define
     52      1.40   mycroft #	namesname	the name for the 'const char *[]' we define
     53      1.11       cgd #	constprefix	the prefix for the system call constants
     54      1.30       eeh #	registertype	the type for register_t
     55      1.40   mycroft #	nsysent		the size of the sysent table
     56      1.46  jdolecek #	sys_nosys	[optional] name of function called for unsupported
     57      1.46  jdolecek #			syscalls, if not sys_nosys()
     58      1.60       dsl #       maxsysargs	[optiona] the maximum number or arguments
     59      1.11       cgd #
     60      1.56     lukem # NOTE THAT THIS makesyscalls.sh DOES NOT SUPPORT 'SYSLIBCOMPAT'.
     61       1.1     glass 
     62      1.46  jdolecek # source the config file.
     63      1.46  jdolecek sys_nosys="sys_nosys"	# default is sys_nosys(), if not specified otherwise
     64      1.60       dsl maxsysargs=8		# default limit is 8 (32bit) arguments
     65  1.63.6.1       mjf rumpcalls="/dev/null"
     66  1.63.6.1       mjf rumpcallshdr="/dev/null"
     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.1     glass 
     76      1.27   thorpej trap "rm $sysdcl $sysprotos $sysent $sysnamesbottom" 0
     77      1.11       cgd 
     78      1.11       cgd # Awk program (must support nawk extensions)
     79      1.11       cgd # Use "awk" at Berkeley, "nawk" or "gawk" elsewhere.
     80      1.11       cgd awk=${AWK:-awk}
     81      1.11       cgd 
     82      1.57  jdolecek # Does this awk have a "toupper" function?
     83      1.57  jdolecek have_toupper=`$awk 'BEGIN { print toupper("true"); exit; }' 2>/dev/null`
     84      1.11       cgd 
     85      1.11       cgd # If this awk does not define "toupper" then define our own.
     86      1.57  jdolecek if [ "$have_toupper" = TRUE ] ; then
     87      1.57  jdolecek 	# Used awk (GNU awk or nawk) provides it
     88      1.11       cgd 	toupper=
     89      1.11       cgd else
     90      1.11       cgd 	# Provide our own toupper()
     91      1.11       cgd 	toupper='
     92      1.11       cgd function toupper(str) {
     93      1.11       cgd 	_toupper_cmd = "echo "str" |tr a-z A-Z"
     94      1.11       cgd 	_toupper_cmd | getline _toupper_str;
     95      1.11       cgd 	close(_toupper_cmd);
     96      1.11       cgd 	return _toupper_str;
     97      1.11       cgd }'
     98      1.11       cgd fi
     99      1.11       cgd 
    100      1.11       cgd # before handing it off to awk, make a few adjustments:
    101      1.11       cgd #	(1) insert spaces around {, }, (, ), *, and commas.
    102      1.11       cgd #	(2) get rid of any and all dollar signs (so that rcs id use safe)
    103      1.11       cgd #
    104      1.11       cgd # The awk script will deal with blank lines and lines that
    105      1.11       cgd # start with the comment character (';').
    106       1.1     glass 
    107      1.11       cgd sed -e '
    108      1.11       cgd s/\$//g
    109      1.11       cgd :join
    110      1.11       cgd 	/\\$/{a\
    111      1.11       cgd 
    112      1.11       cgd 	N
    113      1.11       cgd 	s/\\\n//
    114      1.11       cgd 	b join
    115      1.11       cgd 	}
    116      1.11       cgd 2,${
    117  1.63.6.4       mjf 	/^#/!s/\([{}()*,|]\)/ \1 /g
    118      1.11       cgd }
    119      1.11       cgd ' < $2 | $awk "
    120      1.11       cgd $toupper
    121      1.11       cgd BEGIN {
    122  1.63.6.3       mjf 	# Create a NetBSD tag that does not get expanded when checking
    123  1.63.6.3       mjf 	# this script out of CVS.  (This part of the awk script is in a
    124  1.63.6.3       mjf 	# shell double-quoted string, so the backslashes are eaten by
    125  1.63.6.3       mjf 	# the shell.)
    126  1.63.6.3       mjf 	tag = \"\$\" \"NetBSD\" \"\$\"
    127  1.63.6.3       mjf 
    128      1.18       cgd 	# to allow nested #if/#else/#endif sets
    129      1.18       cgd 	savedepth = 0
    130      1.44  jdolecek 	# to track already processed syscalls
    131      1.18       cgd 
    132      1.11       cgd 	sysnames = \"$sysnames\"
    133      1.16   thorpej 	sysprotos = \"$sysprotos\"
    134      1.11       cgd 	sysnumhdr = \"$sysnumhdr\"
    135      1.11       cgd 	sysarghdr = \"$sysarghdr\"
    136  1.63.6.1       mjf 	rumpcalls = \"$rumpcalls\"
    137  1.63.6.1       mjf 	rumpcallshdr = \"$rumpcallshdr\"
    138      1.11       cgd 	switchname = \"$switchname\"
    139      1.11       cgd 	namesname = \"$namesname\"
    140      1.11       cgd 	constprefix = \"$constprefix\"
    141      1.30       eeh 	registertype = \"$registertype\"
    142  1.63.6.1       mjf 	sysalign=\"$sysalign\"
    143      1.30       eeh 	if (!registertype) {
    144      1.30       eeh 	    registertype = \"register_t\"
    145      1.30       eeh 	}
    146      1.40   mycroft 	nsysent = \"$nsysent\"
    147      1.11       cgd 
    148      1.11       cgd 	sysdcl = \"$sysdcl\"
    149      1.11       cgd 	syscompat_pref = \"$syscompat_pref\"
    150      1.11       cgd 	sysent = \"$sysent\"
    151      1.27   thorpej 	sysnamesbottom = \"$sysnamesbottom\"
    152      1.46  jdolecek 	sys_nosys = \"$sys_nosys\"
    153      1.60       dsl 	maxsysargs = \"$maxsysargs\"
    154      1.11       cgd 	infile = \"$2\"
    155      1.11       cgd 
    156      1.11       cgd 	compatopts = \"$compatopts\"
    157      1.11       cgd 	"'
    158      1.11       cgd 
    159  1.63.6.3       mjf 	printf "/* %s */\n\n", tag > sysdcl
    160      1.11       cgd 	printf "/*\n * System call switch table.\n *\n" > sysdcl
    161      1.11       cgd 	printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysdcl
    162      1.11       cgd 
    163      1.11       cgd 	ncompat = split(compatopts,compat)
    164      1.11       cgd 	for (i = 1; i <= ncompat; i++) {
    165      1.11       cgd 		compat_upper[i] = toupper(compat[i])
    166      1.11       cgd 
    167      1.17   mycroft 		printf "\n#ifdef %s\n", compat_upper[i] > sysent
    168      1.47     lukem 		printf "#define	%s(func) __CONCAT(%s_,func)\n", compat[i], \
    169      1.17   mycroft 		    compat[i] > sysent
    170      1.17   mycroft 		printf "#else\n" > sysent
    171      1.47     lukem 		printf "#define	%s(func) %s\n", compat[i], sys_nosys > sysent
    172      1.17   mycroft 		printf "#endif\n" > sysent
    173      1.11       cgd 	}
    174      1.11       cgd 
    175      1.60       dsl 	printf "\n#define\ts(type)\tsizeof(type)\n" > sysent
    176      1.60       dsl 	printf "#define\tn(type)\t(sizeof(type)/sizeof (%s))\n", registertype > sysent
    177      1.60       dsl 	printf "#define\tns(type)\tn(type), s(type)\n\n", registertype > sysent
    178      1.17   mycroft 	printf "struct sysent %s[] = {\n",switchname > sysent
    179      1.17   mycroft 
    180  1.63.6.3       mjf 	printf "/* %s */\n\n", tag > sysnames
    181      1.11       cgd 	printf "/*\n * System call names.\n *\n" > sysnames
    182      1.11       cgd 	printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysnames
    183      1.11       cgd 
    184      1.16   thorpej 	printf "\n/*\n * System call prototypes.\n */\n\n" > sysprotos
    185      1.16   thorpej 
    186  1.63.6.3       mjf 	printf "/* %s */\n\n", tag > sysnumhdr
    187      1.11       cgd 	printf "/*\n * System call numbers.\n *\n" > sysnumhdr
    188      1.11       cgd 	printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysnumhdr
    189      1.11       cgd 
    190  1.63.6.3       mjf 	printf "/* %s */\n\n", tag > sysarghdr
    191      1.13   mycroft 	printf "/*\n * System call argument lists.\n *\n" > sysarghdr
    192      1.11       cgd 	printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysarghdr
    193  1.63.6.1       mjf 
    194  1.63.6.3       mjf 	printf "/* %s */\n\n", tag > rumpcalls
    195  1.63.6.1       mjf 	printf "/*\n * System call marshalling for rump.\n *\n" > rumpcalls
    196  1.63.6.1       mjf 	printf " * DO NOT EDIT-- this file is automatically generated.\n" > rumpcalls
    197  1.63.6.1       mjf 
    198  1.63.6.3       mjf 	printf "/* %s */\n\n", tag > rumpcallshdr
    199  1.63.6.1       mjf 	printf "/*\n * System call protos in rump namespace.\n *\n" > rumpcallshdr
    200  1.63.6.1       mjf 	printf " * DO NOT EDIT-- this file is automatically generated.\n" > rumpcallshdr
    201      1.11       cgd }
    202      1.11       cgd NR == 1 {
    203      1.58     perry 	sub(/ $/, "")
    204      1.11       cgd 	printf " * created from%s\n */\n\n", $0 > sysdcl
    205  1.63.6.3       mjf 	printf "#include <sys/cdefs.h>\n__KERNEL_RCSID(0, \"%s\");\n\n", tag > sysdcl
    206      1.11       cgd 
    207      1.11       cgd 	printf " * created from%s\n */\n\n", $0 > sysnames
    208  1.63.6.3       mjf 	printf "#include <sys/cdefs.h>\n__KERNEL_RCSID(0, \"%s\");\n\n", tag > sysnames
    209      1.28   thorpej 
    210  1.63.6.1       mjf 	printf " * created from%s\n */\n\n", $0 > rumpcalls
    211  1.63.6.3       mjf 	printf "#include <sys/cdefs.h>\n__KERNEL_RCSID(0, \"%s\");\n\n", tag > rumpcalls
    212  1.63.6.1       mjf 	printf "#include <sys/types.h>\n" > rumpcalls
    213  1.63.6.1       mjf 	printf "#include <sys/param.h>\n" > rumpcalls
    214  1.63.6.1       mjf 	printf "#include <sys/proc.h>\n" > rumpcalls
    215  1.63.6.1       mjf 	printf "#include <sys/syscallargs.h>\n" > rumpcalls
    216  1.63.6.4       mjf 	printf "#include \"rump_private.h\"\n\n" > rumpcalls
    217  1.63.6.1       mjf 	printf "#if\tBYTE_ORDER == BIG_ENDIAN\n" > rumpcalls
    218  1.63.6.1       mjf 	printf "#define SPARG(p,k)\t((p)->k.be.datum)\n" > rumpcalls
    219  1.63.6.1       mjf 	printf "#else /* LITTLE_ENDIAN, I hope dearly */\n" > rumpcalls
    220  1.63.6.1       mjf 	printf "#define SPARG(p,k)\t((p)->k.le.datum)\n" > rumpcalls
    221  1.63.6.1       mjf 	printf "#endif\n\n" > rumpcalls
    222  1.63.6.4       mjf 	printf "int rump_enosys(void);\n" > rumpcalls
    223  1.63.6.4       mjf 	printf "int\nrump_enosys()\n{\n\n\treturn ENOSYS;\n}\n" > rumpcalls
    224  1.63.6.1       mjf 
    225      1.28   thorpej 	# System call names are included by userland (kdump(1)), so
    226      1.28   thorpej 	# hide the include files from it.
    227      1.48       mrg 	printf "#if defined(_KERNEL_OPT)\n" > sysnames
    228      1.28   thorpej 
    229      1.48       mrg 	printf "#endif /* _KERNEL_OPT */\n\n" > sysnamesbottom
    230      1.41   mycroft 	printf "const char *const %s[] = {\n",namesname > sysnamesbottom
    231      1.11       cgd 
    232      1.11       cgd 	printf " * created from%s\n */\n\n", $0 > sysnumhdr
    233      1.11       cgd 
    234      1.11       cgd 	printf " * created from%s\n */\n\n", $0 > sysarghdr
    235  1.63.6.1       mjf 
    236  1.63.6.1       mjf 	printf " * created from%s\n */\n\n", $0 > rumpcallshdr
    237  1.63.6.4       mjf 	printf "#ifdef _RUMPKERNEL\n" > rumpcallshdr
    238  1.63.6.4       mjf 	printf "#error Interface not supported inside rump kernel\n" > rumpcallshdr
    239  1.63.6.4       mjf 	printf "#endif /* _RUMPKERNEL */\n\n" > rumpcallshdr
    240  1.63.6.1       mjf 
    241      1.59  christos 	printf "#ifndef _" constprefix "SYSCALL_H_\n" > sysnumhdr
    242      1.59  christos 	printf "#define	_" constprefix "SYSCALL_H_\n\n" > sysnumhdr
    243      1.59  christos 	printf "#ifndef _" constprefix "SYSCALLARGS_H_\n" > sysarghdr
    244      1.59  christos 	printf "#define	_" constprefix "SYSCALLARGS_H_\n\n" > sysarghdr
    245      1.60       dsl 	# Write max number of system call arguments to both headers
    246      1.60       dsl 	printf("#define\t%sMAXSYSARGS\t%d\n\n", constprefix, maxsysargs) \
    247      1.60       dsl 		> sysnumhdr
    248      1.60       dsl 	printf("#define\t%sMAXSYSARGS\t%d\n\n", constprefix, maxsysargs) \
    249      1.60       dsl 		> sysarghdr
    250      1.30       eeh 	printf "#undef\tsyscallarg\n" > sysarghdr
    251      1.35   thorpej 	printf "#define\tsyscallarg(x)\t\t\t\t\t\t\t\\\n" > sysarghdr
    252      1.35   thorpej 	printf "\tunion {\t\t\t\t\t\t\t\t\\\n" > sysarghdr
    253      1.35   thorpej 	printf "\t\t%s pad;\t\t\t\t\t\t\\\n", registertype > sysarghdr
    254      1.35   thorpej 	printf "\t\tstruct { x datum; } le;\t\t\t\t\t\\\n" > sysarghdr
    255      1.51      manu 	printf "\t\tstruct { /* LINTED zero array dimension */\t\t\\\n" \
    256      1.51      manu 		> sysarghdr
    257      1.51      manu 	printf "\t\t\tint8_t pad[  /* CONSTCOND */\t\t\t\\\n" > sysarghdr
    258      1.51      manu 	printf "\t\t\t\t(sizeof (%s) < sizeof (x))\t\\\n", \
    259      1.30       eeh 		registertype > sysarghdr
    260      1.35   thorpej 	printf "\t\t\t\t? 0\t\t\t\t\t\\\n" > sysarghdr
    261      1.35   thorpej 	printf "\t\t\t\t: sizeof (%s) - sizeof (x)];\t\\\n", \
    262      1.30       eeh 		registertype > sysarghdr
    263      1.35   thorpej 	printf "\t\t\tx datum;\t\t\t\t\t\\\n" > sysarghdr
    264      1.35   thorpej 	printf "\t\t} be;\t\t\t\t\t\t\t\\\n" > sysarghdr
    265      1.35   thorpej 	printf "\t}\n" > sysarghdr
    266      1.60       dsl 	printf("\n#undef check_syscall_args\n") >sysarghdr
    267      1.60       dsl 	printf("#define check_syscall_args(call) \\\n" \
    268      1.60       dsl 		"\ttypedef char call##_check_args" \
    269      1.60       dsl 		    "[sizeof (struct call##_args) \\\n" \
    270      1.60       dsl 		"\t\t<= %sMAXSYSARGS * sizeof (%s) ? 1 : -1];\n", \
    271      1.60       dsl 		constprefix, registertype) >sysarghdr
    272      1.11       cgd 	next
    273      1.11       cgd }
    274      1.11       cgd NF == 0 || $1 ~ /^;/ {
    275      1.11       cgd 	next
    276      1.11       cgd }
    277      1.40   mycroft $0 ~ /^%%$/ {
    278      1.40   mycroft 	intable = 1
    279      1.40   mycroft 	next
    280      1.40   mycroft }
    281      1.11       cgd $1 ~ /^#[ 	]*include/ {
    282      1.11       cgd 	print > sysdcl
    283      1.27   thorpej 	print > sysnames
    284      1.11       cgd 	next
    285      1.11       cgd }
    286      1.40   mycroft $1 ~ /^#/ && !intable {
    287      1.40   mycroft 	print > sysdcl
    288      1.40   mycroft 	print > sysnames
    289      1.11       cgd 	next
    290      1.11       cgd }
    291      1.40   mycroft $1 ~ /^#/ && intable {
    292      1.40   mycroft 	if ($1 ~ /^#[ 	]*if/) {
    293      1.40   mycroft 		savedepth++
    294      1.40   mycroft 		savesyscall[savedepth] = syscall
    295      1.40   mycroft 	}
    296      1.40   mycroft 	if ($1 ~ /^#[ 	]*else/) {
    297      1.40   mycroft 		if (savedepth <= 0) {
    298      1.40   mycroft 			printf("%s: line %d: unbalanced #else\n", \
    299      1.40   mycroft 			    infile, NR)
    300      1.40   mycroft 			exit 1
    301      1.40   mycroft 		}
    302      1.40   mycroft 		syscall = savesyscall[savedepth]
    303      1.18       cgd 	}
    304      1.18       cgd 	if ($1 ~ /^#[       ]*endif/) {
    305      1.18       cgd 		if (savedepth <= 0) {
    306      1.40   mycroft 			printf("%s: line %d: unbalanced #endif\n", \
    307      1.40   mycroft 			    infile, NR)
    308      1.18       cgd 			exit 1
    309      1.18       cgd 		}
    310      1.40   mycroft 		savedepth--
    311      1.18       cgd 	}
    312      1.11       cgd 	print > sysent
    313      1.54  christos 	print > sysarghdr
    314      1.54  christos 	print > sysnumhdr
    315      1.16   thorpej 	print > sysprotos
    316      1.27   thorpej 	print > sysnamesbottom
    317      1.11       cgd 	next
    318      1.11       cgd }
    319      1.11       cgd syscall != $1 {
    320      1.11       cgd 	printf "%s: line %d: syscall number out of sync at %d\n", \
    321      1.11       cgd 	   infile, NR, syscall
    322      1.11       cgd 	printf "line is:\n"
    323      1.11       cgd 	print
    324      1.11       cgd 	exit 1
    325      1.11       cgd }
    326      1.11       cgd function parserr(was, wanted) {
    327  1.63.6.4       mjf 	printf "%s: line %d: unexpected %s (expected <%s>)\n", \
    328      1.11       cgd 	    infile, NR, was, wanted
    329      1.32  christos 	printf "line is:\n"
    330      1.32  christos 	print
    331      1.11       cgd 	exit 1
    332      1.11       cgd }
    333      1.11       cgd function parseline() {
    334      1.11       cgd 	f=3			# toss number and type
    335      1.60       dsl 	if ($2 == "INDIR")
    336      1.60       dsl 		sycall_flags="SYCALL_INDIRECT"
    337      1.60       dsl 	else
    338      1.60       dsl 		sycall_flags="0"
    339      1.11       cgd 	if ($NF != "}") {
    340      1.11       cgd 		funcalias=$NF
    341      1.11       cgd 		end=NF-1
    342      1.11       cgd 	} else {
    343      1.11       cgd 		funcalias=""
    344      1.11       cgd 		end=NF
    345      1.43  jdolecek 	}
    346      1.61       dsl 	if ($f == "INDIR") {		# allow for "NOARG INDIR"
    347      1.61       dsl 		sycall_flags = "SYCALL_INDIRECT | " sycall_flags
    348      1.61       dsl 		f++
    349      1.61       dsl 	}
    350  1.63.6.4       mjf 	if ($f == "MODULAR") {		# registered at runtime
    351  1.63.6.4       mjf 		modular = 1
    352  1.63.6.4       mjf 		f++
    353  1.63.6.4       mjf 	} else {
    354  1.63.6.4       mjf 		modular =  0;
    355  1.63.6.4       mjf 	}
    356  1.63.6.1       mjf 	if ($f == "RUMP") {
    357  1.63.6.1       mjf 		rumpable = 1
    358  1.63.6.1       mjf 		f++
    359  1.63.6.1       mjf 	} else {
    360  1.63.6.1       mjf 		rumpable = 0
    361  1.63.6.1       mjf 	}
    362      1.43  jdolecek 	if ($f ~ /^[a-z0-9_]*$/) {	# allow syscall alias
    363      1.43  jdolecek 		funcalias=$f
    364      1.43  jdolecek 		f++
    365      1.11       cgd 	}
    366      1.11       cgd 	if ($f != "{")
    367      1.11       cgd 		parserr($f, "{")
    368      1.11       cgd 	f++
    369      1.11       cgd 	if ($end != "}")
    370      1.11       cgd 		parserr($end, "}")
    371      1.11       cgd 	end--
    372      1.11       cgd 	if ($end != ";")
    373      1.11       cgd 		parserr($end, ";")
    374      1.11       cgd 	end--
    375      1.11       cgd 	if ($end != ")")
    376      1.11       cgd 		parserr($end, ")")
    377      1.11       cgd 	end--
    378      1.11       cgd 
    379      1.19       cgd 	returntype = oldf = "";
    380      1.19       cgd 	do {
    381      1.19       cgd 		if (returntype != "" && oldf != "*")
    382      1.19       cgd 			returntype = returntype" ";
    383      1.19       cgd 		returntype = returntype$f;
    384      1.19       cgd 		oldf = $f;
    385      1.19       cgd 		f++
    386  1.63.6.4       mjf 	} while ($f != "|" && f < (end-1))
    387      1.19       cgd 	if (f == (end - 1)) {
    388  1.63.6.4       mjf 		parserr($f, "function argument definition (maybe \"|\"?)");
    389  1.63.6.4       mjf 	}
    390  1.63.6.4       mjf 	f++
    391  1.63.6.4       mjf 
    392  1.63.6.4       mjf 	fprefix=$f
    393  1.63.6.4       mjf 	f++
    394  1.63.6.4       mjf 	if ($f != "|") {
    395  1.63.6.4       mjf 		parserr($f, "function compat delimiter (maybe \"|\"?)");
    396  1.63.6.4       mjf 	}
    397  1.63.6.4       mjf 	f++
    398  1.63.6.4       mjf 
    399  1.63.6.4       mjf 	fcompat=""
    400  1.63.6.4       mjf 	if ($f != "|") {
    401  1.63.6.4       mjf 		fcompat=$f
    402  1.63.6.4       mjf 		f++
    403  1.63.6.4       mjf 	}
    404  1.63.6.4       mjf 
    405  1.63.6.4       mjf 	if ($f != "|") {
    406  1.63.6.4       mjf 		parserr($f, "function name delimiter (maybe \"|\"?)");
    407  1.63.6.4       mjf 	}
    408  1.63.6.4       mjf 	f++
    409  1.63.6.4       mjf 	fbase=$f
    410  1.63.6.4       mjf 
    411  1.63.6.4       mjf 	funcstdname=fprefix "_" fbase
    412  1.63.6.4       mjf 	if (fcompat != "") {
    413  1.63.6.4       mjf 		funcname=fprefix "___" fbase "" fcompat
    414  1.63.6.4       mjf 		wantrename=1
    415  1.63.6.4       mjf 	} else {
    416  1.63.6.4       mjf 		funcname=funcstdname
    417  1.63.6.4       mjf 		wantrename=0
    418      1.19       cgd 	}
    419      1.11       cgd 
    420      1.17   mycroft 	if (funcalias == "") {
    421      1.11       cgd 		funcalias=funcname
    422      1.17   mycroft 		sub(/^([^_]+_)*sys_/, "", funcalias)
    423      1.17   mycroft 	}
    424      1.11       cgd 	f++
    425      1.11       cgd 
    426      1.11       cgd 	if ($f != "(")
    427  1.63.6.4       mjf 		parserr($f, "(")
    428      1.11       cgd 	f++
    429      1.11       cgd 
    430      1.19       cgd 	argc=0;
    431      1.63      yamt 	argalign=0;
    432      1.11       cgd 	if (f == end) {
    433      1.11       cgd 		if ($f != "void")
    434      1.11       cgd 			parserr($f, "argument definition")
    435      1.19       cgd 		isvarargs = 0;
    436      1.19       cgd 		varargc = 0;
    437      1.11       cgd 		return
    438      1.11       cgd 	}
    439      1.11       cgd 
    440      1.19       cgd 	# some system calls (open() and fcntl()) can accept a variable
    441      1.19       cgd 	# number of arguments.  If syscalls accept a variable number of
    442      1.19       cgd 	# arguments, they must still have arguments specified for
    443      1.19       cgd 	# the remaining argument "positions," because of the way the
    444      1.19       cgd 	# kernel system call argument handling works.
    445      1.19       cgd 	#
    446      1.19       cgd 	# Indirect system calls, e.g. syscall(), are exceptions to this
    447      1.19       cgd 	# rule, since they are handled entirely by machine-dependent code
    448      1.19       cgd 	# and do not need argument structures built.
    449      1.19       cgd 
    450      1.19       cgd 	isvarargs = 0;
    451      1.11       cgd 	while (f <= end) {
    452      1.19       cgd 		if ($f == "...") {
    453      1.19       cgd 			f++;
    454      1.19       cgd 			isvarargs = 1;
    455      1.19       cgd 			varargc = argc;
    456      1.19       cgd 			continue;
    457      1.19       cgd 		}
    458      1.11       cgd 		argc++
    459      1.11       cgd 		argtype[argc]=""
    460      1.14       cgd 		oldf=""
    461      1.11       cgd 		while (f < end && $(f+1) != ",") {
    462      1.14       cgd 			if (argtype[argc] != "" && oldf != "*")
    463      1.11       cgd 				argtype[argc] = argtype[argc]" ";
    464      1.11       cgd 			argtype[argc] = argtype[argc]$f;
    465      1.14       cgd 			oldf = $f;
    466      1.11       cgd 			f++
    467      1.11       cgd 		}
    468      1.11       cgd 		if (argtype[argc] == "")
    469      1.11       cgd 			parserr($f, "argument definition")
    470      1.63      yamt 		if (argtype[argc] == "off_t") {
    471  1.63.6.1       mjf 			if ((argalign % 2) != 0 && sysalign &&
    472      1.63      yamt 			    funcname != "sys_posix_fadvise") # XXX for now
    473      1.63      yamt 				parserr($f, "a padding argument")
    474      1.63      yamt 		} else {
    475      1.63      yamt 			argalign++;
    476      1.63      yamt 		}
    477      1.11       cgd 		argname[argc]=$f;
    478      1.11       cgd 		f += 2;			# skip name, and any comma
    479      1.11       cgd 	}
    480      1.19       cgd 	# must see another argument after varargs notice.
    481      1.19       cgd 	if (isvarargs) {
    482      1.61       dsl 		if (argc == varargc)
    483      1.19       cgd 			parserr($f, "argument definition")
    484      1.19       cgd 	} else
    485      1.19       cgd 		varargc = argc;
    486      1.11       cgd }
    487      1.54  christos 
    488      1.54  christos function printproto(wrap) {
    489      1.54  christos 	printf("/* syscall: \"%s%s\" ret: \"%s\" args:", wrap, funcalias,
    490      1.54  christos 	    returntype) > sysnumhdr
    491      1.54  christos 	for (i = 1; i <= varargc; i++)
    492      1.54  christos 		printf(" \"%s\"", argtype[i]) > sysnumhdr
    493      1.54  christos 	if (isvarargs)
    494      1.54  christos 		printf(" \"...\"") > sysnumhdr
    495      1.54  christos 	printf(" */\n") > sysnumhdr
    496      1.54  christos 	printf("#define\t%s%s%s\t%d\n\n", constprefix, wrap, funcalias,
    497      1.54  christos 	    syscall) > sysnumhdr
    498  1.63.6.1       mjf 
    499  1.63.6.1       mjf 	# rumpalooza
    500  1.63.6.1       mjf 	if (!rumpable)
    501  1.63.6.1       mjf 		return
    502  1.63.6.1       mjf 
    503  1.63.6.4       mjf 	printf("%s rump_%s(", returntype, funcstdname) > rumpcallshdr
    504  1.63.6.1       mjf 	for (i = 1; i <= argc; i++)
    505  1.63.6.1       mjf 		printf("%s, ", argtype[i]) > rumpcallshdr
    506  1.63.6.4       mjf 	printf("int *)") > rumpcallshdr
    507  1.63.6.4       mjf 	if (wantrename)
    508  1.63.6.4       mjf 		printf(" __RENAME(rump_%s)", funcname) > rumpcallshdr
    509  1.63.6.4       mjf 	printf(";\n") > rumpcallshdr
    510      1.54  christos }
    511      1.54  christos 
    512      1.61       dsl function putent(type, compatwrap) {
    513      1.60       dsl 	# output syscall declaration for switch table.
    514      1.60       dsl 	if (compatwrap == "")
    515      1.60       dsl 		compatwrap_ = ""
    516      1.60       dsl 	else
    517      1.60       dsl 		compatwrap_ = compatwrap "_"
    518      1.62       dsl 	if (argc == 0)
    519      1.62       dsl 		arg_type = "void";
    520      1.62       dsl 	else {
    521      1.62       dsl 		arg_type = "struct " compatwrap_ funcname "_args";
    522      1.62       dsl 	}
    523      1.62       dsl 	proto = "int\t" compatwrap_ funcname "(struct lwp *, const " \
    524      1.62       dsl 	    arg_type " *, register_t *);\n"
    525      1.60       dsl 	if (sysmap[proto] != 1) {
    526      1.60       dsl 		sysmap[proto] = 1;
    527      1.60       dsl 		print proto > sysprotos;
    528      1.21       cgd 	}
    529      1.11       cgd 
    530      1.11       cgd 	# output syscall switch entry
    531      1.60       dsl 	printf("\t{ ") > sysent
    532      1.60       dsl 	if (argc == 0) {
    533      1.60       dsl 		printf("0, 0, ") > sysent
    534      1.19       cgd 	} else {
    535      1.60       dsl 		printf("ns(struct %s%s_args), ", compatwrap_, funcname) > sysent
    536      1.19       cgd 	}
    537  1.63.6.4       mjf 	if (modular) 
    538  1.63.6.4       mjf 		wfn = "(sy_call_t *)sys_nomodule";
    539  1.63.6.4       mjf 	else if (compatwrap == "")
    540      1.62       dsl 		wfn = "(sy_call_t *)" funcname;
    541      1.60       dsl 	else
    542      1.62       dsl 		wfn = "(sy_call_t *)" compatwrap "(" funcname ")";
    543      1.60       dsl 	printf("%s,\n\t    %s },", sycall_flags, wfn) > sysent
    544      1.60       dsl 	for (i = 0; i < (33 - length(wfn)) / 8; i++)
    545      1.60       dsl 		printf("\t") > sysent
    546      1.60       dsl 	printf("/* %d = %s%s */\n", syscall, compatwrap_, funcalias) > sysent
    547      1.11       cgd 
    548      1.11       cgd 	# output syscall name for names table
    549      1.60       dsl 	printf("\t/* %3d */\t\"%s%s\",\n", syscall, compatwrap_, funcalias) \
    550      1.60       dsl 	    > sysnamesbottom
    551      1.11       cgd 
    552      1.11       cgd 	# output syscall number of header, if appropriate
    553      1.61       dsl 	if (type == "STD" || type == "NOARGS" || type == "INDIR") {
    554      1.19       cgd 		# output a prototype, to be used to generate lint stubs in
    555      1.19       cgd 		# libc.
    556      1.54  christos 		printproto("")
    557      1.61       dsl 	} else if (type == "COMPAT") {
    558      1.29   thorpej 		# Just define the syscall number with a comment.  These
    559      1.29   thorpej 		# may be used by compatibility stubs in libc.
    560      1.60       dsl 		printproto(compatwrap_)
    561      1.60       dsl 	}
    562      1.11       cgd 
    563      1.11       cgd 	# output syscall argument structure, if it has arguments
    564      1.62       dsl 	if (argc != 0) {
    565      1.62       dsl 		printf("\nstruct %s%s_args", compatwrap_, funcname) > sysarghdr
    566      1.62       dsl 		if (type != "NOARGS") {
    567      1.62       dsl 			print " {" >sysarghdr;
    568      1.62       dsl 			for (i = 1; i <= argc; i++)
    569      1.62       dsl 				printf("\tsyscallarg(%s) %s;\n", argtype[i],
    570      1.62       dsl 				    argname[i]) > sysarghdr
    571      1.62       dsl 			printf "}" >sysarghdr;
    572      1.62       dsl 		}
    573      1.62       dsl 		printf(";\n") > sysarghdr
    574      1.62       dsl 		if (type != "NOARGS" && type != "INDIR") {
    575      1.60       dsl 			printf("check_syscall_args(%s%s)\n", compatwrap_,
    576      1.60       dsl 			    funcname) >sysarghdr
    577      1.60       dsl 		}
    578      1.11       cgd 	}
    579  1.63.6.1       mjf 
    580  1.63.6.1       mjf 	# output rump marshalling code if necessary
    581  1.63.6.1       mjf 	if (!rumpable)
    582  1.63.6.1       mjf 		return
    583  1.63.6.1       mjf 
    584  1.63.6.4       mjf 	# need a local prototype, we export the re-re-named one in .h
    585  1.63.6.4       mjf 	printf("\n%s rump_%s(", returntype, funcname) > rumpcalls
    586  1.63.6.4       mjf 	for (i = 1; i <= argc; i++) {
    587  1.63.6.4       mjf 		printf("%s, ", argtype[i]) > rumpcalls
    588  1.63.6.4       mjf 	}
    589  1.63.6.4       mjf 	printf("int *);") > rumpcalls
    590  1.63.6.4       mjf 
    591  1.63.6.4       mjf 	printf("\n%s\nrump_%s(", returntype, funcname) > rumpcalls
    592  1.63.6.1       mjf 	for (i = 1; i <= argc; i++) {
    593  1.63.6.1       mjf 		printf("%s %s, ", argtype[i], argname[i]) > rumpcalls
    594  1.63.6.1       mjf 	}
    595  1.63.6.1       mjf 	printf("int *error)\n") > rumpcalls
    596  1.63.6.3       mjf 	printf("{\n\tregister_t retval = 0;\n") > rumpcalls
    597  1.63.6.4       mjf 
    598  1.63.6.1       mjf 	argarg = "NULL"
    599  1.63.6.1       mjf 	if (argc) {
    600  1.63.6.1       mjf 		argarg = "&arg"
    601  1.63.6.1       mjf 		printf("\tstruct %s%s_args arg;\n\n", funcname, compatwrap_) \
    602  1.63.6.1       mjf 		    > rumpcalls
    603  1.63.6.1       mjf 		for (i = 1; i <= argc; i++) {
    604  1.63.6.1       mjf 			printf("\tSPARG(&arg, %s) = %s;\n", \
    605  1.63.6.1       mjf 			    argname[i], argname[i]) > rumpcalls
    606  1.63.6.1       mjf 		}
    607  1.63.6.1       mjf 		printf("\n") > rumpcalls
    608  1.63.6.1       mjf 	} else {
    609  1.63.6.1       mjf 		printf("\n") > rumpcalls
    610  1.63.6.1       mjf 	}
    611  1.63.6.1       mjf 	printf("\t*error = %s(curlwp, %s, &retval);\n", funcname, argarg) \
    612  1.63.6.1       mjf 	    > rumpcalls
    613  1.63.6.3       mjf 	printf("\tif (*error)\n\t\tretval = -1;\n") > rumpcalls
    614  1.63.6.1       mjf 	if (returntype != "void")
    615  1.63.6.1       mjf 		printf("\treturn retval;\n") > rumpcalls
    616  1.63.6.4       mjf 	printf("}\n") > rumpcalls
    617  1.63.6.4       mjf 	printf("__weak_alias(%s,rump_enosys);\n", funcname) > rumpcalls
    618      1.11       cgd }
    619      1.61       dsl $2 == "STD" || $2 == "NODEF" || $2 == "NOARGS" || $2 == "INDIR" {
    620      1.11       cgd 	parseline()
    621      1.17   mycroft 	putent($2, "")
    622      1.11       cgd 	syscall++
    623      1.11       cgd 	next
    624      1.11       cgd }
    625  1.63.6.1       mjf $2 == "OBSOL" || $2 == "UNIMPL" || $2 == "EXCL" || $2 == "IGNORED" {
    626      1.11       cgd 	if ($2 == "OBSOL")
    627      1.11       cgd 		comment="obsolete"
    628      1.34  christos 	else if ($2 == "EXCL")
    629      1.34  christos 		comment="excluded"
    630  1.63.6.1       mjf 	else if ($2 == "IGNORED")
    631  1.63.6.1       mjf 		comment="ignored"
    632      1.11       cgd 	else
    633      1.11       cgd 		comment="unimplemented"
    634      1.11       cgd 	for (i = 3; i <= NF; i++)
    635      1.11       cgd 		comment=comment " " $i
    636      1.11       cgd 
    637  1.63.6.1       mjf 	if ($2 == "IGNORED")
    638  1.63.6.1       mjf 		sys_stub = "(sy_call_t *)nullop";
    639  1.63.6.1       mjf 	else
    640  1.63.6.1       mjf 		sys_stub = sys_nosys;
    641  1.63.6.1       mjf 
    642      1.46  jdolecek 	printf("\t{ 0, 0, 0,\n\t    %s },\t\t\t/* %d = %s */\n", \
    643  1.63.6.1       mjf 	    sys_stub, syscall, comment) > sysent
    644      1.60       dsl 	printf("\t/* %3d */\t\"#%d (%s)\",\n", syscall, syscall, comment) \
    645      1.60       dsl 	    > sysnamesbottom
    646      1.11       cgd 	if ($2 != "UNIMPL")
    647      1.11       cgd 		printf("\t\t\t\t/* %d is %s */\n", syscall, comment) > sysnumhdr
    648      1.11       cgd 	syscall++
    649      1.11       cgd 	next
    650      1.11       cgd }
    651      1.11       cgd {
    652      1.11       cgd 	for (i = 1; i <= ncompat; i++) {
    653      1.11       cgd 		if ($2 == compat_upper[i]) {
    654      1.11       cgd 			parseline();
    655      1.29   thorpej 			putent("COMPAT", compat[i])
    656      1.11       cgd 			syscall++
    657      1.11       cgd 			next
    658      1.11       cgd 		}
    659      1.11       cgd 	}
    660      1.40   mycroft 	printf("%s: line %d: unrecognized keyword %s\n", infile, NR, $2)
    661       1.1     glass 	exit 1
    662      1.11       cgd }
    663      1.11       cgd END {
    664      1.40   mycroft 	maxsyscall = syscall
    665      1.40   mycroft 	if (nsysent) {
    666      1.40   mycroft 		if (syscall > nsysent) {
    667      1.50       wiz 			printf("%s: line %d: too many syscalls [%d > %d]\n", infile, NR, syscall, nsysent)
    668      1.40   mycroft 			exit 1
    669      1.40   mycroft 		}
    670      1.40   mycroft 		while (syscall < nsysent) {
    671      1.46  jdolecek 			printf("\t{ 0, 0, 0,\n\t    %s },\t\t\t/* %d = filler */\n", \
    672      1.46  jdolecek 			    sys_nosys, syscall) > sysent
    673      1.40   mycroft 			syscall++
    674      1.40   mycroft 		}
    675      1.40   mycroft 	}
    676      1.11       cgd 	printf("};\n\n") > sysent
    677      1.27   thorpej 	printf("};\n") > sysnamesbottom
    678      1.40   mycroft 	printf("#define\t%sMAXSYSCALL\t%d\n", constprefix, maxsyscall) > sysnumhdr
    679      1.40   mycroft 	if (nsysent)
    680      1.40   mycroft 		printf("#define\t%sNSYSENT\t%d\n", constprefix, nsysent) > sysnumhdr
    681      1.11       cgd } '
    682       1.1     glass 
    683      1.17   mycroft cat $sysprotos >> $sysarghdr
    684      1.59  christos echo "#endif /* _${constprefix}SYSCALL_H_ */" >> $sysnumhdr
    685      1.59  christos echo "#endif /* _${constprefix}SYSCALLARGS_H_ */" >> $sysarghdr
    686      1.16   thorpej cat $sysdcl $sysent > $syssw
    687      1.27   thorpej cat $sysnamesbottom >> $sysnames
    688       1.1     glass 
    689      1.15  christos #chmod 444 $sysnames $sysnumhdr $syssw
    690