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