Home | History | Annotate | Line # | Download | only in kern
makesyscalls.sh revision 1.59.46.2
      1        1.1     glass #! /bin/sh -
      2  1.59.46.2      matt #	makesyscalls.sh,v 1.59.46.1 2008/01/09 01:56:13 matt 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.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.59.46.1      matt #       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.59.46.1      matt maxsysargs=8		# default limit is 8 (32bit) arguments
     64  1.59.46.2      matt rumpcalls="/dev/null"
     65  1.59.46.2      matt rumpcallshdr="/dev/null"
     66       1.46  jdolecek . ./$1
     67       1.46  jdolecek 
     68        1.1     glass # tmp files:
     69        1.1     glass sysdcl="sysent.dcl"
     70       1.16   thorpej sysprotos="sys.protos"
     71       1.11       cgd syscompat_pref="sysent."
     72        1.1     glass sysent="sysent.switch"
     73       1.27   thorpej sysnamesbottom="sysnames.bottom"
     74        1.1     glass 
     75       1.27   thorpej trap "rm $sysdcl $sysprotos $sysent $sysnamesbottom" 0
     76       1.11       cgd 
     77       1.11       cgd # Awk program (must support nawk extensions)
     78       1.11       cgd # Use "awk" at Berkeley, "nawk" or "gawk" elsewhere.
     79       1.11       cgd awk=${AWK:-awk}
     80       1.11       cgd 
     81       1.57  jdolecek # Does this awk have a "toupper" function?
     82       1.57  jdolecek have_toupper=`$awk 'BEGIN { print toupper("true"); exit; }' 2>/dev/null`
     83       1.11       cgd 
     84       1.11       cgd # If this awk does not define "toupper" then define our own.
     85       1.57  jdolecek if [ "$have_toupper" = TRUE ] ; then
     86       1.57  jdolecek 	# Used awk (GNU awk or nawk) provides it
     87       1.11       cgd 	toupper=
     88       1.11       cgd else
     89       1.11       cgd 	# Provide our own toupper()
     90       1.11       cgd 	toupper='
     91       1.11       cgd function toupper(str) {
     92       1.11       cgd 	_toupper_cmd = "echo "str" |tr a-z A-Z"
     93       1.11       cgd 	_toupper_cmd | getline _toupper_str;
     94       1.11       cgd 	close(_toupper_cmd);
     95       1.11       cgd 	return _toupper_str;
     96       1.11       cgd }'
     97       1.11       cgd fi
     98       1.11       cgd 
     99       1.11       cgd # before handing it off to awk, make a few adjustments:
    100       1.11       cgd #	(1) insert spaces around {, }, (, ), *, and commas.
    101       1.11       cgd #	(2) get rid of any and all dollar signs (so that rcs id use safe)
    102       1.11       cgd #
    103       1.11       cgd # The awk script will deal with blank lines and lines that
    104       1.11       cgd # start with the comment character (';').
    105        1.1     glass 
    106       1.11       cgd sed -e '
    107       1.11       cgd s/\$//g
    108       1.11       cgd :join
    109       1.11       cgd 	/\\$/{a\
    110       1.11       cgd 
    111       1.11       cgd 	N
    112       1.11       cgd 	s/\\\n//
    113       1.11       cgd 	b join
    114       1.11       cgd 	}
    115       1.11       cgd 2,${
    116       1.11       cgd 	/^#/!s/\([{}()*,]\)/ \1 /g
    117       1.11       cgd }
    118       1.11       cgd ' < $2 | $awk "
    119       1.11       cgd $toupper
    120       1.11       cgd BEGIN {
    121       1.18       cgd 	# to allow nested #if/#else/#endif sets
    122       1.18       cgd 	savedepth = 0
    123       1.44  jdolecek 	# to track already processed syscalls
    124       1.18       cgd 
    125       1.11       cgd 	sysnames = \"$sysnames\"
    126       1.16   thorpej 	sysprotos = \"$sysprotos\"
    127       1.11       cgd 	sysnumhdr = \"$sysnumhdr\"
    128       1.11       cgd 	sysarghdr = \"$sysarghdr\"
    129  1.59.46.2      matt 	rumpcalls = \"$rumpcalls\"
    130  1.59.46.2      matt 	rumpcallshdr = \"$rumpcallshdr\"
    131       1.11       cgd 	switchname = \"$switchname\"
    132       1.11       cgd 	namesname = \"$namesname\"
    133       1.11       cgd 	constprefix = \"$constprefix\"
    134       1.30       eeh 	registertype = \"$registertype\"
    135       1.30       eeh 	if (!registertype) {
    136       1.30       eeh 	    registertype = \"register_t\"
    137       1.30       eeh 	}
    138       1.40   mycroft 	nsysent = \"$nsysent\"
    139       1.11       cgd 
    140       1.11       cgd 	sysdcl = \"$sysdcl\"
    141       1.11       cgd 	syscompat_pref = \"$syscompat_pref\"
    142       1.11       cgd 	sysent = \"$sysent\"
    143       1.27   thorpej 	sysnamesbottom = \"$sysnamesbottom\"
    144       1.46  jdolecek 	sys_nosys = \"$sys_nosys\"
    145  1.59.46.1      matt 	maxsysargs = \"$maxsysargs\"
    146       1.11       cgd 	infile = \"$2\"
    147       1.11       cgd 
    148       1.11       cgd 	compatopts = \"$compatopts\"
    149       1.11       cgd 	"'
    150       1.11       cgd 
    151       1.37       cgd 	printf "/* \$NetBSD\$ */\n\n" > sysdcl
    152       1.11       cgd 	printf "/*\n * System call switch table.\n *\n" > sysdcl
    153       1.11       cgd 	printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysdcl
    154       1.11       cgd 
    155       1.11       cgd 	ncompat = split(compatopts,compat)
    156       1.11       cgd 	for (i = 1; i <= ncompat; i++) {
    157       1.11       cgd 		compat_upper[i] = toupper(compat[i])
    158       1.11       cgd 
    159       1.17   mycroft 		printf "\n#ifdef %s\n", compat_upper[i] > sysent
    160       1.47     lukem 		printf "#define	%s(func) __CONCAT(%s_,func)\n", compat[i], \
    161       1.17   mycroft 		    compat[i] > sysent
    162       1.17   mycroft 		printf "#else\n" > sysent
    163       1.47     lukem 		printf "#define	%s(func) %s\n", compat[i], sys_nosys > sysent
    164       1.17   mycroft 		printf "#endif\n" > sysent
    165       1.11       cgd 	}
    166       1.11       cgd 
    167  1.59.46.1      matt 	printf "\n#define\ts(type)\tsizeof(type)\n" > sysent
    168  1.59.46.1      matt 	printf "#define\tn(type)\t(sizeof(type)/sizeof (%s))\n", registertype > sysent
    169  1.59.46.1      matt 	printf "#define\tns(type)\tn(type), s(type)\n\n", registertype > sysent
    170       1.17   mycroft 	printf "struct sysent %s[] = {\n",switchname > sysent
    171       1.17   mycroft 
    172       1.37       cgd 	printf "/* \$NetBSD\$ */\n\n" > sysnames
    173       1.11       cgd 	printf "/*\n * System call names.\n *\n" > sysnames
    174       1.11       cgd 	printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysnames
    175       1.11       cgd 
    176       1.16   thorpej 	printf "\n/*\n * System call prototypes.\n */\n\n" > sysprotos
    177       1.16   thorpej 
    178       1.37       cgd 	printf "/* \$NetBSD\$ */\n\n" > sysnumhdr
    179       1.11       cgd 	printf "/*\n * System call numbers.\n *\n" > sysnumhdr
    180       1.11       cgd 	printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysnumhdr
    181       1.11       cgd 
    182       1.37       cgd 	printf "/* \$NetBSD\$ */\n\n" > sysarghdr
    183       1.13   mycroft 	printf "/*\n * System call argument lists.\n *\n" > sysarghdr
    184       1.11       cgd 	printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysarghdr
    185  1.59.46.2      matt 
    186  1.59.46.2      matt 	printf "/* \$NetBSD\$ */\n\n" > rumpcalls
    187  1.59.46.2      matt 	printf "/*\n * System call marshalling for rump.\n *\n" > rumpcalls
    188  1.59.46.2      matt 	printf " * DO NOT EDIT-- this file is automatically generated.\n" > rumpcalls
    189  1.59.46.2      matt 
    190  1.59.46.2      matt 	printf "/* \$NetBSD\$ */\n\n" > rumpcallshdr
    191  1.59.46.2      matt 	printf "/*\n * System call protos in rump namespace.\n *\n" > rumpcallshdr
    192  1.59.46.2      matt 	printf " * DO NOT EDIT-- this file is automatically generated.\n" > rumpcallshdr
    193       1.11       cgd }
    194       1.11       cgd NR == 1 {
    195       1.58     perry 	sub(/ $/, "")
    196       1.11       cgd 	printf " * created from%s\n */\n\n", $0 > sysdcl
    197       1.52     lukem 	printf "#include <sys/cdefs.h>\n__KERNEL_RCSID(0, \"\$NetBSD\$\");\n\n" > sysdcl
    198       1.11       cgd 
    199       1.11       cgd 	printf " * created from%s\n */\n\n", $0 > sysnames
    200       1.52     lukem 	printf "#include <sys/cdefs.h>\n__KERNEL_RCSID(0, \"\$NetBSD\$\");\n\n" > sysnames
    201       1.28   thorpej 
    202  1.59.46.2      matt 	printf " * created from%s\n */\n\n", $0 > rumpcalls
    203  1.59.46.2      matt 	printf "#include <sys/cdefs.h>\n__KERNEL_RCSID(0, \"\$NetBSD\$\");\n\n" > rumpcalls
    204  1.59.46.2      matt 	printf "#include <sys/types.h>\n" > rumpcalls
    205  1.59.46.2      matt 	printf "#include <sys/param.h>\n" > rumpcalls
    206  1.59.46.2      matt 	printf "#include <sys/proc.h>\n" > rumpcalls
    207  1.59.46.2      matt 	printf "#include <sys/syscallargs.h>\n" > rumpcalls
    208  1.59.46.2      matt 	printf "#include \"rump_syscalls.h\"\n\n" > rumpcalls
    209  1.59.46.2      matt 	printf "#if\tBYTE_ORDER == BIG_ENDIAN\n" > rumpcalls
    210  1.59.46.2      matt 	printf "#define SPARG(p,k)\t((p)->k.be.datum)\n" > rumpcalls
    211  1.59.46.2      matt 	printf "#else /* LITTLE_ENDIAN, I hope dearly */\n" > rumpcalls
    212  1.59.46.2      matt 	printf "#define SPARG(p,k)\t((p)->k.le.datum)\n" > rumpcalls
    213  1.59.46.2      matt 	printf "#endif\n\n" > rumpcalls
    214  1.59.46.2      matt 
    215       1.28   thorpej 	# System call names are included by userland (kdump(1)), so
    216       1.28   thorpej 	# hide the include files from it.
    217       1.48       mrg 	printf "#if defined(_KERNEL_OPT)\n" > sysnames
    218       1.28   thorpej 
    219       1.48       mrg 	printf "#endif /* _KERNEL_OPT */\n\n" > sysnamesbottom
    220       1.41   mycroft 	printf "const char *const %s[] = {\n",namesname > sysnamesbottom
    221       1.11       cgd 
    222       1.11       cgd 	printf " * created from%s\n */\n\n", $0 > sysnumhdr
    223       1.11       cgd 
    224       1.11       cgd 	printf " * created from%s\n */\n\n", $0 > sysarghdr
    225  1.59.46.2      matt 
    226  1.59.46.2      matt 	printf " * created from%s\n */\n\n", $0 > rumpcallshdr
    227  1.59.46.2      matt 
    228       1.59  christos 	printf "#ifndef _" constprefix "SYSCALL_H_\n" > sysnumhdr
    229       1.59  christos 	printf "#define	_" constprefix "SYSCALL_H_\n\n" > sysnumhdr
    230       1.59  christos 	printf "#ifndef _" constprefix "SYSCALLARGS_H_\n" > sysarghdr
    231       1.59  christos 	printf "#define	_" constprefix "SYSCALLARGS_H_\n\n" > sysarghdr
    232  1.59.46.1      matt 	# Write max number of system call arguments to both headers
    233  1.59.46.1      matt 	printf("#define\t%sMAXSYSARGS\t%d\n\n", constprefix, maxsysargs) \
    234  1.59.46.1      matt 		> sysnumhdr
    235  1.59.46.1      matt 	printf("#define\t%sMAXSYSARGS\t%d\n\n", constprefix, maxsysargs) \
    236  1.59.46.1      matt 		> sysarghdr
    237       1.30       eeh 	printf "#undef\tsyscallarg\n" > sysarghdr
    238       1.35   thorpej 	printf "#define\tsyscallarg(x)\t\t\t\t\t\t\t\\\n" > sysarghdr
    239       1.35   thorpej 	printf "\tunion {\t\t\t\t\t\t\t\t\\\n" > sysarghdr
    240       1.35   thorpej 	printf "\t\t%s pad;\t\t\t\t\t\t\\\n", registertype > sysarghdr
    241       1.35   thorpej 	printf "\t\tstruct { x datum; } le;\t\t\t\t\t\\\n" > sysarghdr
    242       1.51      manu 	printf "\t\tstruct { /* LINTED zero array dimension */\t\t\\\n" \
    243       1.51      manu 		> sysarghdr
    244       1.51      manu 	printf "\t\t\tint8_t pad[  /* CONSTCOND */\t\t\t\\\n" > sysarghdr
    245       1.51      manu 	printf "\t\t\t\t(sizeof (%s) < sizeof (x))\t\\\n", \
    246       1.30       eeh 		registertype > sysarghdr
    247       1.35   thorpej 	printf "\t\t\t\t? 0\t\t\t\t\t\\\n" > sysarghdr
    248       1.35   thorpej 	printf "\t\t\t\t: sizeof (%s) - sizeof (x)];\t\\\n", \
    249       1.30       eeh 		registertype > sysarghdr
    250       1.35   thorpej 	printf "\t\t\tx datum;\t\t\t\t\t\\\n" > sysarghdr
    251       1.35   thorpej 	printf "\t\t} be;\t\t\t\t\t\t\t\\\n" > sysarghdr
    252       1.35   thorpej 	printf "\t}\n" > sysarghdr
    253  1.59.46.1      matt 	printf("\n#undef check_syscall_args\n") >sysarghdr
    254  1.59.46.1      matt 	printf("#define check_syscall_args(call) \\\n" \
    255  1.59.46.1      matt 		"\ttypedef char call##_check_args" \
    256  1.59.46.1      matt 		    "[sizeof (struct call##_args) \\\n" \
    257  1.59.46.1      matt 		"\t\t<= %sMAXSYSARGS * sizeof (%s) ? 1 : -1];\n", \
    258  1.59.46.1      matt 		constprefix, registertype) >sysarghdr
    259       1.11       cgd 	next
    260       1.11       cgd }
    261       1.11       cgd NF == 0 || $1 ~ /^;/ {
    262       1.11       cgd 	next
    263       1.11       cgd }
    264       1.40   mycroft $0 ~ /^%%$/ {
    265       1.40   mycroft 	intable = 1
    266       1.40   mycroft 	next
    267       1.40   mycroft }
    268       1.11       cgd $1 ~ /^#[ 	]*include/ {
    269       1.11       cgd 	print > sysdcl
    270       1.27   thorpej 	print > sysnames
    271       1.11       cgd 	next
    272       1.11       cgd }
    273       1.40   mycroft $1 ~ /^#/ && !intable {
    274       1.40   mycroft 	print > sysdcl
    275       1.40   mycroft 	print > sysnames
    276       1.11       cgd 	next
    277       1.11       cgd }
    278       1.40   mycroft $1 ~ /^#/ && intable {
    279       1.40   mycroft 	if ($1 ~ /^#[ 	]*if/) {
    280       1.40   mycroft 		savedepth++
    281       1.40   mycroft 		savesyscall[savedepth] = syscall
    282       1.40   mycroft 	}
    283       1.40   mycroft 	if ($1 ~ /^#[ 	]*else/) {
    284       1.40   mycroft 		if (savedepth <= 0) {
    285       1.40   mycroft 			printf("%s: line %d: unbalanced #else\n", \
    286       1.40   mycroft 			    infile, NR)
    287       1.40   mycroft 			exit 1
    288       1.40   mycroft 		}
    289       1.40   mycroft 		syscall = savesyscall[savedepth]
    290       1.18       cgd 	}
    291       1.18       cgd 	if ($1 ~ /^#[       ]*endif/) {
    292       1.18       cgd 		if (savedepth <= 0) {
    293       1.40   mycroft 			printf("%s: line %d: unbalanced #endif\n", \
    294       1.40   mycroft 			    infile, NR)
    295       1.18       cgd 			exit 1
    296       1.18       cgd 		}
    297       1.40   mycroft 		savedepth--
    298       1.18       cgd 	}
    299       1.11       cgd 	print > sysent
    300       1.54  christos 	print > sysarghdr
    301       1.54  christos 	print > sysnumhdr
    302       1.16   thorpej 	print > sysprotos
    303       1.27   thorpej 	print > sysnamesbottom
    304       1.11       cgd 	next
    305       1.11       cgd }
    306       1.11       cgd syscall != $1 {
    307       1.11       cgd 	printf "%s: line %d: syscall number out of sync at %d\n", \
    308       1.11       cgd 	   infile, NR, syscall
    309       1.11       cgd 	printf "line is:\n"
    310       1.11       cgd 	print
    311       1.11       cgd 	exit 1
    312       1.11       cgd }
    313       1.11       cgd function parserr(was, wanted) {
    314       1.11       cgd 	printf "%s: line %d: unexpected %s (expected %s)\n", \
    315       1.11       cgd 	    infile, NR, was, wanted
    316       1.32  christos 	printf "line is:\n"
    317       1.32  christos 	print
    318       1.11       cgd 	exit 1
    319       1.11       cgd }
    320       1.11       cgd function parseline() {
    321       1.11       cgd 	f=3			# toss number and type
    322  1.59.46.1      matt 	if ($2 == "INDIR")
    323  1.59.46.1      matt 		sycall_flags="SYCALL_INDIRECT"
    324  1.59.46.1      matt 	else
    325  1.59.46.1      matt 		sycall_flags="0"
    326       1.11       cgd 	if ($NF != "}") {
    327       1.11       cgd 		funcalias=$NF
    328       1.11       cgd 		end=NF-1
    329       1.11       cgd 	} else {
    330       1.11       cgd 		funcalias=""
    331       1.11       cgd 		end=NF
    332       1.43  jdolecek 	}
    333  1.59.46.1      matt 	if ($f == "INDIR") {		# allow for "NOARG INDIR"
    334  1.59.46.1      matt 		sycall_flags = "SYCALL_INDIRECT | " sycall_flags
    335  1.59.46.1      matt 		f++
    336  1.59.46.1      matt 	}
    337       1.45   thorpej 	if ($f == "MPSAFE") {		# allow for MP-safe syscalls
    338  1.59.46.1      matt 		sycall_flags = "SYCALL_MPSAFE | " sycall_flags
    339       1.45   thorpej 		f++
    340       1.45   thorpej 	}
    341  1.59.46.2      matt 	if ($f == "RUMP") {
    342  1.59.46.2      matt 		rumpable = 1
    343  1.59.46.2      matt 		f++
    344  1.59.46.2      matt 	} else {
    345  1.59.46.2      matt 		rumpable = 0
    346  1.59.46.2      matt 	}
    347       1.43  jdolecek 	if ($f ~ /^[a-z0-9_]*$/) {	# allow syscall alias
    348       1.43  jdolecek 		funcalias=$f
    349       1.43  jdolecek 		f++
    350       1.11       cgd 	}
    351       1.11       cgd 	if ($f != "{")
    352       1.11       cgd 		parserr($f, "{")
    353       1.11       cgd 	f++
    354       1.11       cgd 	if ($end != "}")
    355       1.11       cgd 		parserr($end, "}")
    356       1.11       cgd 	end--
    357       1.11       cgd 	if ($end != ";")
    358       1.11       cgd 		parserr($end, ";")
    359       1.11       cgd 	end--
    360       1.11       cgd 	if ($end != ")")
    361       1.11       cgd 		parserr($end, ")")
    362       1.11       cgd 	end--
    363       1.11       cgd 
    364       1.19       cgd 	returntype = oldf = "";
    365       1.19       cgd 	do {
    366       1.19       cgd 		if (returntype != "" && oldf != "*")
    367       1.19       cgd 			returntype = returntype" ";
    368       1.19       cgd 		returntype = returntype$f;
    369       1.19       cgd 		oldf = $f;
    370       1.19       cgd 		f++
    371       1.19       cgd 	} while (f < (end - 1) && $(f+1) != "(");
    372       1.19       cgd 	if (f == (end - 1)) {
    373       1.19       cgd 		parserr($f, "function argument definition (maybe \"(\"?)");
    374       1.19       cgd 	}
    375       1.11       cgd 
    376       1.11       cgd 	funcname=$f
    377       1.17   mycroft 	if (funcalias == "") {
    378       1.11       cgd 		funcalias=funcname
    379       1.17   mycroft 		sub(/^([^_]+_)*sys_/, "", funcalias)
    380       1.17   mycroft 	}
    381       1.11       cgd 	f++
    382       1.11       cgd 
    383       1.11       cgd 	if ($f != "(")
    384       1.11       cgd 		parserr($f, ")")
    385       1.11       cgd 	f++
    386       1.11       cgd 
    387       1.19       cgd 	argc=0;
    388  1.59.46.2      matt 	argalign=0;
    389       1.11       cgd 	if (f == end) {
    390       1.11       cgd 		if ($f != "void")
    391       1.11       cgd 			parserr($f, "argument definition")
    392       1.19       cgd 		isvarargs = 0;
    393       1.19       cgd 		varargc = 0;
    394       1.11       cgd 		return
    395       1.11       cgd 	}
    396       1.11       cgd 
    397       1.19       cgd 	# some system calls (open() and fcntl()) can accept a variable
    398       1.19       cgd 	# number of arguments.  If syscalls accept a variable number of
    399       1.19       cgd 	# arguments, they must still have arguments specified for
    400       1.19       cgd 	# the remaining argument "positions," because of the way the
    401       1.19       cgd 	# kernel system call argument handling works.
    402       1.19       cgd 	#
    403       1.19       cgd 	# Indirect system calls, e.g. syscall(), are exceptions to this
    404       1.19       cgd 	# rule, since they are handled entirely by machine-dependent code
    405       1.19       cgd 	# and do not need argument structures built.
    406       1.19       cgd 
    407       1.19       cgd 	isvarargs = 0;
    408       1.11       cgd 	while (f <= end) {
    409       1.19       cgd 		if ($f == "...") {
    410       1.19       cgd 			f++;
    411       1.19       cgd 			isvarargs = 1;
    412       1.19       cgd 			varargc = argc;
    413       1.19       cgd 			continue;
    414       1.19       cgd 		}
    415       1.11       cgd 		argc++
    416       1.11       cgd 		argtype[argc]=""
    417       1.14       cgd 		oldf=""
    418       1.11       cgd 		while (f < end && $(f+1) != ",") {
    419       1.14       cgd 			if (argtype[argc] != "" && oldf != "*")
    420       1.11       cgd 				argtype[argc] = argtype[argc]" ";
    421       1.11       cgd 			argtype[argc] = argtype[argc]$f;
    422       1.14       cgd 			oldf = $f;
    423       1.11       cgd 			f++
    424       1.11       cgd 		}
    425       1.11       cgd 		if (argtype[argc] == "")
    426       1.11       cgd 			parserr($f, "argument definition")
    427  1.59.46.2      matt 		if (argtype[argc] == "off_t") {
    428  1.59.46.2      matt 			if ((argalign % 2) != 0 &&
    429  1.59.46.2      matt 			    funcname != "sys_posix_fadvise") # XXX for now
    430  1.59.46.2      matt 				parserr($f, "a padding argument")
    431  1.59.46.2      matt 		} else {
    432  1.59.46.2      matt 			argalign++;
    433  1.59.46.2      matt 		}
    434       1.11       cgd 		argname[argc]=$f;
    435       1.11       cgd 		f += 2;			# skip name, and any comma
    436       1.11       cgd 	}
    437       1.19       cgd 	# must see another argument after varargs notice.
    438       1.19       cgd 	if (isvarargs) {
    439  1.59.46.1      matt 		if (argc == varargc)
    440       1.19       cgd 			parserr($f, "argument definition")
    441       1.19       cgd 	} else
    442       1.19       cgd 		varargc = argc;
    443       1.11       cgd }
    444       1.54  christos 
    445       1.54  christos function printproto(wrap) {
    446       1.54  christos 	printf("/* syscall: \"%s%s\" ret: \"%s\" args:", wrap, funcalias,
    447       1.54  christos 	    returntype) > sysnumhdr
    448       1.54  christos 	for (i = 1; i <= varargc; i++)
    449       1.54  christos 		printf(" \"%s\"", argtype[i]) > sysnumhdr
    450       1.54  christos 	if (isvarargs)
    451       1.54  christos 		printf(" \"...\"") > sysnumhdr
    452       1.54  christos 	printf(" */\n") > sysnumhdr
    453       1.54  christos 	printf("#define\t%s%s%s\t%d\n\n", constprefix, wrap, funcalias,
    454       1.54  christos 	    syscall) > sysnumhdr
    455  1.59.46.2      matt 
    456  1.59.46.2      matt 	# rumpalooza
    457  1.59.46.2      matt 	if (!rumpable)
    458  1.59.46.2      matt 		return
    459  1.59.46.2      matt 
    460  1.59.46.2      matt 	if (wrap == "")
    461  1.59.46.2      matt 		wrap = "sys"
    462  1.59.46.2      matt 	printf("%s rump_%s_%s(", returntype, wrap, funcalias) > rumpcallshdr
    463  1.59.46.2      matt 	for (i = 1; i <= argc; i++)
    464  1.59.46.2      matt 		printf("%s, ", argtype[i]) > rumpcallshdr
    465  1.59.46.2      matt 	printf("int *);\n") > rumpcallshdr
    466       1.54  christos }
    467       1.54  christos 
    468  1.59.46.1      matt function putent(type, compatwrap) {
    469  1.59.46.1      matt 	# output syscall declaration for switch table.
    470  1.59.46.1      matt 	if (compatwrap == "")
    471  1.59.46.1      matt 		compatwrap_ = ""
    472  1.59.46.1      matt 	else
    473  1.59.46.1      matt 		compatwrap_ = compatwrap "_"
    474  1.59.46.1      matt 	if (argc == 0)
    475  1.59.46.1      matt 		arg_type = "void";
    476  1.59.46.1      matt 	else {
    477  1.59.46.1      matt 		arg_type = "struct " compatwrap_ funcname "_args";
    478  1.59.46.1      matt 	}
    479  1.59.46.1      matt 	proto = "int\t" compatwrap_ funcname "(struct lwp *, const " \
    480  1.59.46.1      matt 	    arg_type " *, register_t *);\n"
    481  1.59.46.1      matt 	if (sysmap[proto] != 1) {
    482  1.59.46.1      matt 		sysmap[proto] = 1;
    483  1.59.46.1      matt 		print proto > sysprotos;
    484       1.21       cgd 	}
    485       1.11       cgd 
    486       1.11       cgd 	# output syscall switch entry
    487  1.59.46.1      matt 	printf("\t{ ") > sysent
    488  1.59.46.1      matt 	if (argc == 0) {
    489  1.59.46.1      matt 		printf("0, 0, ") > sysent
    490       1.19       cgd 	} else {
    491  1.59.46.1      matt 		printf("ns(struct %s%s_args), ", compatwrap_, funcname) > sysent
    492       1.19       cgd 	}
    493       1.11       cgd 	if (compatwrap == "")
    494  1.59.46.1      matt 		wfn = "(sy_call_t *)" funcname;
    495       1.11       cgd 	else
    496  1.59.46.1      matt 		wfn = "(sy_call_t *)" compatwrap "(" funcname ")";
    497  1.59.46.1      matt 	printf("%s,\n\t    %s },", sycall_flags, wfn) > sysent
    498  1.59.46.1      matt 	for (i = 0; i < (33 - length(wfn)) / 8; i++)
    499  1.59.46.1      matt 		printf("\t") > sysent
    500  1.59.46.1      matt 	printf("/* %d = %s%s */\n", syscall, compatwrap_, funcalias) > sysent
    501  1.59.46.1      matt 
    502  1.59.46.1      matt 	# output syscall name for names table
    503  1.59.46.1      matt 	printf("\t/* %3d */\t\"%s%s\",\n", syscall, compatwrap_, funcalias) \
    504  1.59.46.1      matt 	    > sysnamesbottom
    505       1.11       cgd 
    506       1.11       cgd 	# output syscall number of header, if appropriate
    507  1.59.46.1      matt 	if (type == "STD" || type == "NOARGS" || type == "INDIR") {
    508       1.19       cgd 		# output a prototype, to be used to generate lint stubs in
    509       1.19       cgd 		# libc.
    510       1.54  christos 		printproto("")
    511  1.59.46.1      matt 	} else if (type == "COMPAT") {
    512       1.29   thorpej 		# Just define the syscall number with a comment.  These
    513       1.29   thorpej 		# may be used by compatibility stubs in libc.
    514  1.59.46.1      matt 		printproto(compatwrap_)
    515  1.59.46.1      matt 	}
    516       1.11       cgd 
    517       1.11       cgd 	# output syscall argument structure, if it has arguments
    518  1.59.46.1      matt 	if (argc != 0) {
    519  1.59.46.1      matt 		printf("\nstruct %s%s_args", compatwrap_, funcname) > sysarghdr
    520  1.59.46.1      matt 		if (type != "NOARGS") {
    521  1.59.46.1      matt 			print " {" >sysarghdr;
    522  1.59.46.1      matt 			for (i = 1; i <= argc; i++)
    523  1.59.46.1      matt 				printf("\tsyscallarg(%s) %s;\n", argtype[i],
    524  1.59.46.1      matt 				    argname[i]) > sysarghdr
    525  1.59.46.1      matt 			printf "}" >sysarghdr;
    526  1.59.46.1      matt 		}
    527  1.59.46.1      matt 		printf(";\n") > sysarghdr
    528  1.59.46.1      matt 		if (type != "NOARGS" && type != "INDIR") {
    529  1.59.46.1      matt 			printf("check_syscall_args(%s%s)\n", compatwrap_,
    530  1.59.46.1      matt 			    funcname) >sysarghdr
    531  1.59.46.1      matt 		}
    532       1.11       cgd 	}
    533  1.59.46.2      matt 
    534  1.59.46.2      matt 	# output rump marshalling code if necessary
    535  1.59.46.2      matt 	if (!rumpable)
    536  1.59.46.2      matt 		return
    537  1.59.46.2      matt 
    538  1.59.46.2      matt 	printf("%s\nrump_%s(", returntype, funcname) > rumpcalls
    539  1.59.46.2      matt 	for (i = 1; i <= argc; i++) {
    540  1.59.46.2      matt 		printf("%s %s, ", argtype[i], argname[i]) > rumpcalls
    541  1.59.46.2      matt 	}
    542  1.59.46.2      matt 	printf("int *error)\n") > rumpcalls
    543  1.59.46.2      matt 	printf("{\n\tregister_t retval;\n") > rumpcalls
    544  1.59.46.2      matt 	argarg = "NULL"
    545  1.59.46.2      matt 	if (argc) {
    546  1.59.46.2      matt 		argarg = "&arg"
    547  1.59.46.2      matt 		printf("\tstruct %s%s_args arg;\n\n", funcname, compatwrap_) \
    548  1.59.46.2      matt 		    > rumpcalls
    549  1.59.46.2      matt 		for (i = 1; i <= argc; i++) {
    550  1.59.46.2      matt 			printf("\tSPARG(&arg, %s) = %s;\n", \
    551  1.59.46.2      matt 			    argname[i], argname[i]) > rumpcalls
    552  1.59.46.2      matt 		}
    553  1.59.46.2      matt 		printf("\n") > rumpcalls
    554  1.59.46.2      matt 	} else {
    555  1.59.46.2      matt 		printf("\n") > rumpcalls
    556  1.59.46.2      matt 	}
    557  1.59.46.2      matt 	printf("\t*error = %s(curlwp, %s, &retval);\n", funcname, argarg) \
    558  1.59.46.2      matt 	    > rumpcalls
    559  1.59.46.2      matt 	if (returntype != "void")
    560  1.59.46.2      matt 		printf("\treturn retval;\n") > rumpcalls
    561  1.59.46.2      matt 	printf("}\n\n") > rumpcalls
    562       1.11       cgd }
    563  1.59.46.1      matt $2 == "STD" || $2 == "NODEF" || $2 == "NOARGS" || $2 == "INDIR" {
    564       1.11       cgd 	parseline()
    565       1.17   mycroft 	putent($2, "")
    566       1.11       cgd 	syscall++
    567       1.11       cgd 	next
    568       1.11       cgd }
    569  1.59.46.2      matt $2 == "OBSOL" || $2 == "UNIMPL" || $2 == "EXCL" || $2 == "IGNORED" {
    570       1.11       cgd 	if ($2 == "OBSOL")
    571       1.11       cgd 		comment="obsolete"
    572       1.34  christos 	else if ($2 == "EXCL")
    573       1.34  christos 		comment="excluded"
    574  1.59.46.2      matt 	else if ($2 == "IGNORED")
    575  1.59.46.2      matt 		comment="ignored"
    576       1.11       cgd 	else
    577       1.11       cgd 		comment="unimplemented"
    578       1.11       cgd 	for (i = 3; i <= NF; i++)
    579       1.11       cgd 		comment=comment " " $i
    580       1.11       cgd 
    581  1.59.46.2      matt 	if ($2 == "IGNORED")
    582  1.59.46.2      matt 		sys_stub = "(sy_call_t *)nullop";
    583  1.59.46.2      matt 	else
    584  1.59.46.2      matt 		sys_stub = sys_nosys;
    585  1.59.46.2      matt 
    586       1.46  jdolecek 	printf("\t{ 0, 0, 0,\n\t    %s },\t\t\t/* %d = %s */\n", \
    587  1.59.46.2      matt 	    sys_stub, syscall, comment) > sysent
    588  1.59.46.1      matt 	printf("\t/* %3d */\t\"#%d (%s)\",\n", syscall, syscall, comment) \
    589  1.59.46.1      matt 	    > sysnamesbottom
    590       1.11       cgd 	if ($2 != "UNIMPL")
    591       1.11       cgd 		printf("\t\t\t\t/* %d is %s */\n", syscall, comment) > sysnumhdr
    592       1.11       cgd 	syscall++
    593       1.11       cgd 	next
    594       1.11       cgd }
    595       1.11       cgd {
    596       1.11       cgd 	for (i = 1; i <= ncompat; i++) {
    597       1.11       cgd 		if ($2 == compat_upper[i]) {
    598       1.11       cgd 			parseline();
    599       1.29   thorpej 			putent("COMPAT", compat[i])
    600       1.11       cgd 			syscall++
    601       1.11       cgd 			next
    602       1.11       cgd 		}
    603       1.11       cgd 	}
    604       1.40   mycroft 	printf("%s: line %d: unrecognized keyword %s\n", infile, NR, $2)
    605        1.1     glass 	exit 1
    606       1.11       cgd }
    607       1.11       cgd END {
    608       1.40   mycroft 	maxsyscall = syscall
    609       1.40   mycroft 	if (nsysent) {
    610       1.40   mycroft 		if (syscall > nsysent) {
    611       1.50       wiz 			printf("%s: line %d: too many syscalls [%d > %d]\n", infile, NR, syscall, nsysent)
    612       1.40   mycroft 			exit 1
    613       1.40   mycroft 		}
    614       1.40   mycroft 		while (syscall < nsysent) {
    615       1.46  jdolecek 			printf("\t{ 0, 0, 0,\n\t    %s },\t\t\t/* %d = filler */\n", \
    616       1.46  jdolecek 			    sys_nosys, syscall) > sysent
    617       1.40   mycroft 			syscall++
    618       1.40   mycroft 		}
    619       1.40   mycroft 	}
    620       1.11       cgd 	printf("};\n\n") > sysent
    621       1.27   thorpej 	printf("};\n") > sysnamesbottom
    622       1.40   mycroft 	printf("#define\t%sMAXSYSCALL\t%d\n", constprefix, maxsyscall) > sysnumhdr
    623       1.40   mycroft 	if (nsysent)
    624       1.40   mycroft 		printf("#define\t%sNSYSENT\t%d\n", constprefix, nsysent) > sysnumhdr
    625       1.11       cgd } '
    626        1.1     glass 
    627       1.17   mycroft cat $sysprotos >> $sysarghdr
    628       1.59  christos echo "#endif /* _${constprefix}SYSCALL_H_ */" >> $sysnumhdr
    629       1.59  christos echo "#endif /* _${constprefix}SYSCALLARGS_H_ */" >> $sysarghdr
    630       1.16   thorpej cat $sysdcl $sysent > $syssw
    631       1.27   thorpej cat $sysnamesbottom >> $sysnames
    632        1.1     glass 
    633       1.15  christos #chmod 444 $sysnames $sysnumhdr $syssw
    634