xref: /netbsd-src/sys/kern/makesyscalls.sh (revision 06dfa8449cb5e76c0044ec0f3badf7d5180af0f5)
1#	$NetBSD: makesyscalls.sh,v 1.186 2021/10/21 11:01:03 andvar Exp $
2#
3# Copyright (c) 1994, 1996, 2000 Christopher G. Demetriou
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions
8# are met:
9# 1. Redistributions of source code must retain the above copyright
10#    notice, this list of conditions and the following disclaimer.
11# 2. Redistributions in binary form must reproduce the above copyright
12#    notice, this list of conditions and the following disclaimer in the
13#    documentation and/or other materials provided with the distribution.
14# 3. All advertising materials mentioning features or use of this software
15#    must display the following acknowledgement:
16#      This product includes software developed for the NetBSD Project
17#      by Christopher G. Demetriou.
18# 4. The name of the author may not be used to endorse or promote products
19#    derived from this software without specific prior written permission
20#
21# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
32#	@(#)makesyscalls.sh	8.1 (Berkeley) 6/10/93
33
34set -e
35
36case $# in
37    2)	;;
38    *)	echo "Usage: $0 config-file input-file" 1>&2
39	exit 1
40	;;
41esac
42
43# the config file sets the following variables:
44#	sysalign	check for alignment of off_t/dev_t/time_t
45#	sysnames	the syscall names file
46#	sysnumhdr	the syscall numbers file
47#	syssw		the syscall switch file
48#	sysautoload	the syscall autoload definitions file
49#	sysarghdr	the syscall argument struct definitions
50#	sysarghdrextra	extra stuff dumped into sysarghdr
51#	systrace	the dtrace definitions
52#	compatopts	those syscall types that are for 'compat' syscalls
53#	switchname	the name for the 'struct sysent' we define
54#	namesname	the name for the 'const char *[]' we define
55#	constprefix	the prefix for the system call constants
56#	emulname	the emulation name
57#	registertype	the type for register_t
58#	nsysent		the size of the sysent table
59#	sys_nosys	[optional] name of function called for unsupported
60#			syscalls, if not sys_nosys()
61#       maxsysargs	[optional] the maximum number or arguments
62#	rumpcalls	???
63#	rumpcallshdr	???
64#	rumpsysmap	???
65#
66# NOTE THAT THIS makesyscalls.sh DOES NOT SUPPORT 'SYSLIBCOMPAT'.
67
68# source the config file.
69sys_nosys="sys_nosys"	# default is sys_nosys(), if not specified otherwise
70maxsysargs=8		# default limit is 8 (32bit) arguments
71systrace="/dev/null"
72sysautoload="/dev/null"
73rumpcalls="/dev/null"
74rumpcallshdr="/dev/null"
75rumpsysmap="/dev/null"
76rumpsysent="rumpsysent.tmp"
77rumpnoflags="\n\t\t.sy_flags = SYCALL_NOSYS,"
78rumpnosys="(sy_call_t *)(void *)rumpns_enosys"
79rumpnomodule="(sy_call_t *)(void *)rumpns_sys_nomodule"
80
81case $1 in
82/*)	. $1;;
83*)	. ./$1;;
84esac
85
86errmsg()
87{
88	fail=true;
89	printf '%s: %s\n' "$0" "$*" >&2
90}
91
92addsuffix()
93{
94	if [ "$1" = "/dev/null" -o -z "$2" ]; then
95		echo $1
96	else
97		echo $1.$2
98	fi
99}
100
101fail=false
102case "${nsysent:-0}" in
103*[!0-9]*)	errmsg "Non numeric value for nsysent:" "${nsysent}";;
104esac
105case "${maxsysargs:-0}" in
106*[!0-9]*)	errmsg "Non numeric value for maxsysargs:" "${maxsysargs}";;
107esac
108$fail && exit 1
109
110# tmp files:
111sysautoloadbottom=$(addsuffix $sysautoload "bottom")
112sysdcl="sysent.dcl"
113sysprotos="sys.protos"
114syscompat_pref="sysent."
115sysent="sysent.switch"
116sysnamesbottom=$(addsuffix $sysnames "bottom")
117sysnamesfriendly=$(addsuffix $sysnames "friendly")
118rumptypes="rumphdr.types"
119rumpprotos="rumphdr.protos"
120systracetmp="systrace.$$"
121systraceret="systraceret.$$"
122
123cleanup() {
124    rm $sysdcl $sysprotos $sysent $sysnamesbottom $sysnamesfriendly $rumpsysent $rumptypes $rumpprotos $systracetmp $systraceret ${sysautoloadbottom#/dev/null}
125}
126trap "cleanup" 0
127
128# Awk program (must support nawk extensions)
129# Use "awk" at Berkeley, "nawk" or "gawk" elsewhere.
130awk=${AWK:-awk}
131
132# Does this awk have a "toupper" function?
133have_toupper="$($awk 'BEGIN { print toupper("true"); exit; }' 2>/dev/null)"
134
135# If this awk does not define "toupper" then define our own.
136if [ "$have_toupper" = TRUE ] ; then
137	# Used awk (GNU awk or nawk) provides it
138	toupper=
139else
140	# Provide our own toupper()
141	toupper='
142function toupper(str) {
143	_toupper_cmd = "echo "str" |tr a-z A-Z"
144	_toupper_cmd | getline _toupper_str;
145	close(_toupper_cmd);
146	return _toupper_str;
147}'
148fi
149
150# before handing it off to awk, make a few adjustments:
151#	(1) insert spaces around {, }, (, ), *, |, and commas.
152#	(2) get rid of any and all dollar signs (so that rcs id use safe)
153#
154# The awk script will deal with blank lines and lines that
155# start with the comment character (';').
156
157sed -e '
158s/\$//g
159:join
160	/\\$/{a\
161
162	N
163	s/\\\n//
164	b join
165	}
1662,${
167	/^#/!s/\([{}()*,|]\)/ \1 /g
168}
169' < $2 | $awk "
170$toupper
171BEGIN {
172	# Create a NetBSD tag that does not get expanded when checking
173	# this script out of CVS.  (This part of the awk script is in a
174	# shell double-quoted string, so the backslashes are eaten by
175	# the shell.)
176	tag = \"\$\" \"NetBSD\" \"\$\"
177
178	# to allow nested #if/#else/#endif sets
179	savedepth = 0
180	# to track already processed syscalls
181
182	sysnames = \"$sysnames\"
183	sysprotos = \"$sysprotos\"
184	sysnumhdr = \"$sysnumhdr\"
185	sysarghdr = \"$sysarghdr\"
186	sysarghdrextra = \"$sysarghdrextra\"
187	systrace = \"$systrace\"
188	systracetmp = \"$systracetmp\"
189	systraceret = \"$systraceret\"
190	sysautoload = \"$sysautoload\"
191	sysautoloadbottom = \"$sysautoloadbottom\"
192	rumpcalls = \"$rumpcalls\"
193	rumpcallshdr = \"$rumpcallshdr\"
194	rumpsysent = \"$rumpsysent\"
195	rumpsysmap = \"$rumpsysmap\"
196	switchname = \"$switchname\"
197	namesname = \"$namesname\"
198	constprefix = \"$constprefix\"
199	emulname = \"$emulname\"
200	registertype = \"$registertype\"
201	sysalign=\"$sysalign\"
202	if (!registertype) {
203	    registertype = \"register_t\"
204	}
205	nsysent = ${nsysent:-0}
206
207	sysdcl = \"$sysdcl\"
208	syscompat_pref = \"$syscompat_pref\"
209	sysent = \"$sysent\"
210	sysnamesbottom = \"$sysnamesbottom\"
211	sysnamesfriendly = \"$sysnamesfriendly\"
212	rumpprotos = \"$rumpprotos\"
213	rumptypes = \"$rumptypes\"
214	sys_nosys = \"$sys_nosys\"
215	maxsysargs = ${maxsysargs:-8}
216	rumpnoflags=\"$rumpnoflags\"
217	rumpnosys=\"$rumpnosys\"
218	rumpnomodule=\"$rumpnomodule\"
219	infile = \"$2\"
220
221	compatopts = \"$compatopts\"
222	"'
223
224	if (rumpcalls != "/dev/null")
225		haverumpcalls = 1
226
227	printf "/* %s */\n\n", tag > sysdcl
228	printf "/*\n * System call switch table.\n *\n" > sysdcl
229	printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysdcl
230
231	ncompat = split(compatopts,compat)
232	for (i = 1; i <= ncompat; i++) {
233		compat_upper[i] = toupper(compat[i])
234
235		printf "\n#ifdef %s\n", compat_upper[i] > sysent
236		printf "#define	%s(func) __CONCAT(%s_,func)\n", compat[i], \
237		    compat[i] > sysent
238		printf "#else\n" > sysent
239		printf "#define	%s(func) %s\n", compat[i], sys_nosys > sysent
240		printf "#endif\n" > sysent
241	}
242
243	printf "\n#define\ts(type)\tsizeof(type)\n" > sysent
244	printf "#define\tn(type)\t(sizeof(type)/sizeof (%s))\n", registertype > sysent
245	printf "#define\tns(type)\t.sy_narg = n(type), .sy_argsize = s(type)\n\n", registertype > sysent
246	printf "struct sysent %s[] = {\n",switchname > sysent
247
248	printf "/* %s */\n\n", tag > sysnames
249	printf "/*\n * System call names.\n *\n" > sysnames
250	printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysnames
251
252	printf "\n/*\n * System call prototypes.\n */\n\n" > sysprotos
253	if (haverumpcalls)
254		printf("#ifndef RUMP_CLIENT\n") > sysprotos
255
256	printf "/* %s */\n\n", tag > sysnumhdr
257	printf "/*\n * System call numbers.\n *\n" > sysnumhdr
258	printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysnumhdr
259
260	printf "/* %s */\n\n", tag > sysarghdr
261	printf "/*\n * System call argument lists.\n *\n" > sysarghdr
262	printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysarghdr
263
264	printf "/* %s */\n\n", tag > sysautoload
265	printf "/*\n * System call autoload table.\n *\n" > sysautoload
266	printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysautoload
267
268	printf "/* %s */\n\n", tag > rumpcalls
269	printf "/*\n * System call vector and marshalling for rump.\n *\n" > rumpcalls
270	printf " * DO NOT EDIT-- this file is automatically generated.\n" > rumpcalls
271
272	printf "/* %s */\n\n", tag > rumpcallshdr
273	printf "/*\n * System call protos in rump namespace.\n *\n" > rumpcallshdr
274	printf " * DO NOT EDIT-- this file is automatically generated.\n" > rumpcallshdr
275
276	printf "/* %s */\n\n", tag > systrace
277	printf "/*\n * System call argument to DTrace register array conversion.\n *\n" > systrace
278	printf " * DO NOT EDIT-- this file is automatically generated.\n" > systrace
279}
280NR == 1 {
281	sub(/ $/, "")
282	printf " * created from%s\n */\n\n", $0 > sysdcl
283	printf "#include <sys/cdefs.h>\n__KERNEL_RCSID(0, \"%s\");\n\n", tag > sysdcl
284
285	printf " * created from%s\n */\n\n", $0 > sysnames
286	printf "#include <sys/cdefs.h>\n__KERNEL_RCSID(0, \"%s\");\n\n", tag > sysnames
287
288	printf " * created from%s\n */\n\n", $0 > sysautoload
289	printf "#include <sys/cdefs.h>\n__KERNEL_RCSID(0, \"%s\");\n\n", tag > sysautoload
290	printf("static struct sc_autoload " emulname \
291		"_syscalls_autoload[] = {\n")		> sysautoloadbottom
292
293	printf " * created from%s\n */\n\n", $0 > rumpcalls
294	printf "#ifdef RUMP_CLIENT\n" > rumpcalls
295	printf "#include <rump/rumpuser_port.h>\n" > rumpcalls
296	printf "#endif /* RUMP_CLIENT */\n\n" > rumpcalls
297	printf "#include <sys/param.h>\n\n" > rumpcalls
298	printf "#ifdef __NetBSD__\n" > rumpcalls
299	printf "#include <sys/cdefs.h>\n__KERNEL_RCSID(0, \"%s\");\n\n", tag > rumpcalls
300
301	printf "#include <sys/fstypes.h>\n" > rumpcalls
302	printf "#include <sys/proc.h>\n" > rumpcalls
303	printf "#endif /* __NetBSD__ */\n\n" > rumpcalls
304	printf "#ifdef RUMP_CLIENT\n" > rumpcalls
305	printf "#include <errno.h>\n" > rumpcalls
306	printf "#include <stdint.h>\n" > rumpcalls
307	printf "#include <stdlib.h>\n" > rumpcalls
308	printf "#include <string.h>\n\n" > rumpcalls
309	printf "#include <srcsys/syscall.h>\n" > rumpcalls
310	printf "#include <srcsys/syscallargs.h>\n\n" > rumpcalls
311	printf "#include <rump/rumpclient.h>\n\n" > rumpcalls
312	printf "#define rsys_syscall(num, data, dlen, retval)\t\\\n" > rumpcalls
313	printf "    rumpclient_syscall(num, data, dlen, retval)\n" > rumpcalls
314	printf "#define rsys_seterrno(error) errno = error\n" > rumpcalls
315	printf "#else\n" > rumpcalls
316	printf "#include <sys/syscall.h>\n" > rumpcalls
317	printf "#include <sys/syscallargs.h>\n\n" > rumpcalls
318	printf "#include <sys/syscallvar.h>\n\n" > rumpcalls
319	printf "#include <rump-sys/kern.h>\n\n" > rumpcalls
320	printf "#include <rump/rumpuser.h>\n" > rumpcalls
321	printf "#define rsys_syscall(num, data, dlen, retval)\t\\\n" > rumpcalls
322	printf "    rump_syscall(num, data, dlen, retval)\n\n" > rumpcalls
323	printf "#define rsys_seterrno(error) rumpuser_seterrno(error)\n" \
324	    > rumpcalls
325	printf "#endif\n\n" > rumpcalls
326
327	printf "#ifndef RUMP_KERNEL_IS_LIBC\n" > rumpcalls
328	printf "#define RUMP_SYS_COMPAT\n" > rumpcalls
329	printf "#endif\n\n" > rumpcalls
330
331	printf "#if\tBYTE_ORDER == BIG_ENDIAN\n" > rumpcalls
332	printf "#define SPARG(p,k)\t((p)->k.be.datum)\n" > rumpcalls
333	printf "#else /* LITTLE_ENDIAN, I hope dearly */\n" > rumpcalls
334	printf "#define SPARG(p,k)\t((p)->k.le.datum)\n" > rumpcalls
335	printf "#endif\n\n" > rumpcalls
336	printf "\nvoid rumpns_sys_nomodule(void);\n" > rumpcalls
337
338	printf "\n#ifndef RUMP_CLIENT\n" > rumpsysent
339	printf "int rumpns_enosys(void);\n" > rumpsysent
340	printf "#define\ts(type)\tsizeof(type)\n" > rumpsysent
341	printf "#define\tn(type)\t(sizeof(type)/sizeof (%s))\n", registertype > rumpsysent
342	printf "#define\tns(type)\tn(type), s(type)\n\n", registertype > rumpsysent
343	printf "struct sysent rump_sysent[] = {\n" > rumpsysent
344
345	# System call names are included by userland (kdump(1)), so
346	# hide the include files from it.
347	printf "#if defined(_KERNEL_OPT)\n" > sysnames
348
349	printf "#else /* _KERNEL_OPT */\n" > sysnamesbottom
350	printf "#include <sys/null.h>\n" > sysnamesbottom
351	printf "#endif /* _KERNEL_OPT */\n\n" > sysnamesbottom
352	printf "const char *const %s[] = {\n",namesname > sysnamesbottom
353	printf "\n\n/* libc style syscall names */\n" > sysnamesfriendly
354	printf "const char *const alt%s[] = {\n", namesname > sysnamesfriendly
355
356	printf " * created from%s\n */\n\n", $0 > sysnumhdr
357	printf "#ifndef _" constprefix "SYSCALL_H_\n" > sysnumhdr
358	printf "#define	_" constprefix "SYSCALL_H_\n\n" > sysnumhdr
359
360	printf " * created from%s\n */\n\n", $0 > sysarghdr
361	printf "#ifndef _" constprefix "SYSCALLARGS_H_\n" > sysarghdr
362	printf "#define	_" constprefix "SYSCALLARGS_H_\n\n" > sysarghdr
363
364	printf " * created from%s\n */\n\n", $0 > rumpcallshdr
365	printf "#ifndef _RUMP_RUMP_SYSCALLS_H_\n" > rumpcallshdr
366	printf "#define _RUMP_RUMP_SYSCALLS_H_\n\n" > rumpcallshdr
367	printf "#ifdef _KERNEL\n" > rumpcallshdr
368	printf "#error Interface not supported inside kernel\n" > rumpcallshdr
369	printf "#endif /* _KERNEL */\n\n" > rumpcallshdr
370	printf "#include <rump/rump_syscalls_compat.h>\n\n" > rumpcallshdr
371
372	printf "%s", sysarghdrextra > sysarghdr
373	printf "/* Forward declaration */\n" > sysarghdr
374	printf "struct lwp;\n" > sysarghdr
375	printf "\n" > sysarghdr
376
377	# Write max number of system call arguments to both headers
378	printf("#define\t%sMAXSYSARGS\t%d\n\n", constprefix, maxsysargs) \
379		> sysnumhdr
380	printf("#define\t%sMAXSYSARGS\t%d\n\n", constprefix, maxsysargs) \
381		> sysarghdr
382	printf "#undef\tsyscallarg\n" > sysarghdr
383	printf "#define\tsyscallarg(x)\t\t\t\t\t\t\t\\\n" > sysarghdr
384	printf "\tunion {\t\t\t\t\t\t\t\t\\\n" > sysarghdr
385	printf "\t\t%s pad;\t\t\t\t\t\t\\\n", registertype > sysarghdr
386	printf "\t\tstruct { x datum; } le;\t\t\t\t\t\\\n" > sysarghdr
387	printf "\t\tstruct { /* LINTED zero array dimension */\t\t\\\n" \
388		> sysarghdr
389	printf "\t\t\tint8_t pad[  /* CONSTCOND */\t\t\t\\\n" > sysarghdr
390	printf "\t\t\t\t(sizeof (%s) < sizeof (x))\t\\\n", \
391		registertype > sysarghdr
392	printf "\t\t\t\t? 0\t\t\t\t\t\\\n" > sysarghdr
393	printf "\t\t\t\t: sizeof (%s) - sizeof (x)];\t\\\n", \
394		registertype > sysarghdr
395	printf "\t\t\tx datum;\t\t\t\t\t\\\n" > sysarghdr
396	printf "\t\t} be;\t\t\t\t\t\t\t\\\n" > sysarghdr
397	printf "\t}\n" > sysarghdr
398	printf("\n#undef check_syscall_args\n") >sysarghdr
399	printf("#define check_syscall_args(call) /*LINTED*/ \\\n" \
400		"\ttypedef char call##_check_args" \
401		    "[sizeof (struct call##_args) \\\n" \
402		"\t\t<= %sMAXSYSARGS * sizeof (%s) ? 1 : -1];\n", \
403		constprefix, registertype) >sysarghdr
404
405	printf " * This file is part of the DTrace syscall provider.\n */\n\n" > systrace
406	printf "static void\nsystrace_args(register_t sysnum, const void *params, uintptr_t *uarg, size_t *n_args)\n{\n" > systrace
407	printf "\tintptr_t *iarg  = (intptr_t *)uarg;\n" > systrace
408	printf "\tswitch (sysnum) {\n" > systrace
409
410	printf "static void\nsystrace_entry_setargdesc(int sysnum, int ndx, char *desc, size_t descsz)\n{\n\tconst char *p = NULL;\n" > systracetmp
411	printf "\tswitch (sysnum) {\n" > systracetmp
412
413	printf "static void\nsystrace_return_setargdesc(int sysnum, int ndx, char *desc, size_t descsz)\n{\n\tconst char *p = NULL;\n" > systraceret
414	printf "\tswitch (sysnum) {\n" > systraceret
415
416	# compat types from syscalls.master.  this is slightly ugly,
417	# but given that we have so few compats from over 17 years,
418	# a more complicated solution is not currently warranted.
419	uncompattypes["struct timeval50"] = "struct timeval";
420	uncompattypes["struct timespec50"] = "struct timespec";
421	uncompattypes["struct stat30"] = "struct stat";
422
423	next
424}
425NF == 0 || $1 ~ /^;/ {
426	next
427}
428$0 ~ /^%%$/ {
429	intable = 1
430	next
431}
432$1 ~ /^#[ 	]*include/ {
433	print > sysdcl
434	print > sysnames
435	print > sysautoload
436	next
437}
438$1 ~ /^#/ && !intable {
439	print > sysdcl
440	print > sysnames
441	print > sysautoload
442	next
443}
444$1 ~ /^#/ && intable {
445	if ($1 ~ /^#[ 	]*if/) {
446		savedepth++
447		savesyscall[savedepth] = syscall
448	}
449	if ($1 ~ /^#[ 	]*else/) {
450		if (savedepth <= 0) {
451			printf("%s: line %d: unbalanced #else\n", \
452			    infile, NR)
453			exit 1
454		}
455		syscall = savesyscall[savedepth]
456	}
457	if ($1 ~ /^#[       ]*endif/) {
458		if (savedepth <= 0) {
459			printf("%s: line %d: unbalanced #endif\n", \
460			    infile, NR)
461			exit 1
462		}
463		savedepth--
464	}
465	print > sysent
466	print > sysarghdr
467	print > sysnumhdr
468	print > sysprotos
469	print > sysautoloadbottom
470	print > sysnamesbottom
471	print > sysnamesfriendly
472	print > systrace
473	print > systracetmp
474	print > systraceret
475
476	# XXX: technically we do not want to have conditionals in rump,
477	# but it is easier to just let the cpp handle them than try to
478	# figure out what we want here in this script
479	print > rumpsysent
480	next
481}
482syscall != $1 {
483	printf "%s: line %d: syscall number out of sync at %d\n", \
484	   infile, NR, syscall
485	printf "line is:\n"
486	print
487	exit 1
488}
489function isarg64(type) {
490	gsub("netbsd32_", "", type);
491	return type == "quad_t" || type == "off_t" \
492	    || type == "dev_t" ||  type == "time_t";
493}
494function parserr(was, wanted) {
495	printf "%s: line %d: unexpected %s (expected <%s>)\n", \
496	    infile, NR, was, wanted
497	printf "line is:\n"
498	print
499	exit 1
500}
501function fillerpsysent(syscall, flags, name, comment) {
502	return sprintf("\t{%s\n\t\t.sy_call = %s,\n\t},\t\t/* %d = filler */",\
503	    flags, name, syscall, comment);
504}
505function parseline() {
506	f=3			# toss number and type
507	if ($2 == "INDIR")
508		sycall_flags="SYCALL_INDIRECT"
509	else
510		sycall_flags="0"
511	if ($NF != "}") {
512		funcalias=$NF
513		end=NF-1
514	} else {
515		funcalias=""
516		end=NF
517	}
518	if ($f == "INDIR") {		# allow for "NOARG INDIR"
519		sycall_flags = "SYCALL_INDIRECT | " sycall_flags
520		f++
521	}
522	if ($f == "MODULAR") {		# registered at runtime
523		modular = 1
524		f++
525		modname = $f
526		f++
527	} else {
528		modular =  0;
529	}
530	if ($f == "RUMP") {
531		rumpable = 1
532		f++
533	} else {
534		rumpable = 0
535	}
536	if ($f ~ /^[a-z0-9_]*$/) {	# allow syscall alias
537		funcalias=$f
538		f++
539	}
540	if ($f != "{")
541		parserr($f, "{")
542	f++
543	if ($end != "}")
544		parserr($end, "}")
545	end--
546	if ($end != ";")
547		parserr($end, ";")
548	end--
549	if ($end != ")")
550		parserr($end, ")")
551	end--
552
553	returntype = oldf = "";
554	do {
555		if (returntype != "" && oldf != "*")
556			returntype = returntype" ";
557		returntype = returntype$f;
558		oldf = $f;
559		f++
560	} while ($f != "|" && f < (end-1))
561	if (f == (end - 1)) {
562		parserr($f, "function argument definition (maybe \"|\"?)");
563	}
564	f++
565
566	fprefix=$f
567	f++
568	if ($f != "|") {
569		parserr($f, "function compat delimiter (maybe \"|\"?)");
570	}
571	f++
572
573	fcompat=""
574	if ($f != "|") {
575		fcompat=$f
576		f++
577	}
578
579	if ($f != "|") {
580		parserr($f, "function name delimiter (maybe \"|\"?)");
581	}
582	f++
583	fbase=$f
584
585	# pipe is special in how to returns its values.
586	# So just generate it manually if present.
587	if (rumpable == 1 && fbase == "pipe") {
588		rumpable = 0;
589		rumphaspipe = 1;
590	}
591
592	if (fcompat != "") {
593		funcname=fprefix "___" fbase "" fcompat
594	} else {
595		funcname=fprefix "_" fbase
596	}
597	if (isarg64(returntype)) {
598		if (sycall_flags == "0")
599			sycall_flags = "SYCALL_RET_64";
600		else
601			sycall_flags = "SYCALL_RET_64 | " sycall_flags;
602	}
603
604	if (funcalias == "") {
605		funcalias=funcname
606		sub(/^([^_]+_)*sys_/, "", funcalias)
607		realname=fbase
608		rumpfname=realname "" fcompat
609	} else {
610		realname=funcalias
611		rumpfname=realname
612	}
613
614	f++
615
616	if ($f != "(")
617		parserr($f, "(")
618	f++
619
620	argc=0;
621	argalign=0;
622	if (f == end) {
623		if ($f != "void")
624			parserr($f, "argument definition")
625		isvarargs = 0;
626		varargc = 0;
627		argtype[0]="void";
628		return
629	}
630
631	# some system calls (open() and fcntl()) can accept a variable
632	# number of arguments.  If syscalls accept a variable number of
633	# arguments, they must still have arguments specified for
634	# the remaining argument "positions," because of the way the
635	# kernel system call argument handling works.
636	#
637	# Indirect system calls, e.g. syscall(), are exceptions to this
638	# rule, since they are handled entirely by machine-dependent code
639	# and do not need argument structures built.
640
641	isvarargs = 0;
642	args64 = 0;
643	ptr = 0;
644	while (f <= end) {
645		if ($f == "...") {
646			f++;
647			isvarargs = 1;
648			varargc = argc;
649			continue;
650		}
651		argc++
652		argtype[argc]=""
653		oldf=""
654		while (f < end && $(f+1) != ",") {
655			if (argtype[argc] != "" && oldf != "*")
656				argtype[argc] = argtype[argc]" ";
657			argtype[argc] = argtype[argc]$f;
658			oldf = $f;
659			f++
660		}
661		if (argtype[argc] == "")
662			parserr($f, "argument definition")
663		if (argtype[argc] == "off_t"  \
664		  || argtype[argc] == "dev_t" \
665		  || argtype[argc] == "time_t") {
666			if ((argalign % 2) != 0 && sysalign &&
667			    funcname != "sys_posix_fadvise") # XXX for now
668				parserr($f, "a padding argument")
669		} else {
670			argalign++;
671		}
672		if (isarg64(argtype[argc])) {
673			if (sycall_flags == "0")
674				sycall_flags = "SYCALL_ARG"argc-1"_64";
675			else
676				sycall_flags = "SYCALL_ARG"argc-1"_64 | " sycall_flags;
677			args64++;
678		}
679		if (index(argtype[argc], "*") != 0 && ptr == 0) {
680			if (sycall_flags == "0")
681				sycall_flags = "SYCALL_ARG_PTR";
682			else
683				sycall_flags = "SYCALL_ARG_PTR | " sycall_flags;
684			ptr = 1;
685		}
686		argname[argc]=$f;
687		f += 2;			# skip name, and any comma
688	}
689	if (args64 > 0)
690		sycall_flags = "SYCALL_NARGS64_VAL("args64") | " sycall_flags;
691	# must see another argument after varargs notice.
692	if (isvarargs) {
693		if (argc == varargc)
694			parserr($f, "argument definition")
695	} else
696		varargc = argc;
697}
698
699function printproto(wrap) {
700	printf("/* syscall: \"%s%s\" ret: \"%s\" args:", wrap, funcalias,
701	    returntype) > sysnumhdr
702	for (i = 1; i <= varargc; i++)
703		printf(" \"%s\"", argtype[i]) > sysnumhdr
704	if (isvarargs)
705		printf(" \"...\"") > sysnumhdr
706	printf(" */\n") > sysnumhdr
707	printf("#define\t%s%s%s\t%d\n\n", constprefix, wrap, funcalias,
708	    syscall) > sysnumhdr
709
710	# output entry for syscall autoload table, if modular
711	if (modular) {
712		printf("\t    { %s%s%s, \"%s\" },\n", constprefix, wrap,
713		   funcalias, modname) > sysautoloadbottom
714	}
715
716
717	# rumpalooza
718	if (!rumpable)
719		return
720
721	# accumulate fbases we have seen.  we want the last
722	# occurrence for the default __RENAME()
723	seen = funcseen[realname]
724	funcseen[realname] = rumpfname
725	# special case for mknod as type of last argument changed from
726	# uint32_t to dev_t
727	if ((seen && fbase != "mknod") || (!seen && fbase == "mknod"))
728		return
729
730	printf("%s rump_sys_%s(", returntype, realname) > rumpprotos
731
732	for (i = 1; i < varargc; i++)
733		if (argname[i] != "PAD")
734			printf("%s, ", uncompattype(argtype[i])) > rumpprotos
735
736	if (isvarargs)
737		printf("%s, ...)", uncompattype(argtype[varargc]))>rumpprotos
738	else
739		printf("%s)", uncompattype(argtype[argc])) > rumpprotos
740
741	printf(" __RENAME(RUMP_SYS_RENAME_%s)", toupper(realname))> rumpprotos
742	printf(";\n") > rumpprotos
743
744	# generate forward-declares for types, apart from the
745	# braindead typedef jungle we cannot easily handle here
746	for (i = 1; i <= varargc; i++) {
747		type=uncompattype(argtype[i])
748		sub("const ", "", type)
749		ntype=type
750		sub(" *\\*.*", "", ntype);
751		if (!typeseen[ntype] && \
752		    match(type, "struct") && match(type, "\\*")) {
753			typeseen[ntype] = 1
754			printf("%s;\n", ntype) > rumptypes
755		}
756	}
757}
758
759function printrumpsysent(insysent, compatwrap_) {
760	if (modular) {
761		fn = rumpnomodule
762		flags = rumpnoflags
763	} else {
764		fn = rumpnosys
765		flags = ""
766	}
767	if (!insysent) {
768		printf("\t{%s\n\t\t.sy_call = %s,\n},\t\t/* %d = %s */\n", \
769		    flags, fn, syscall, funcalias) > rumpsysent
770		return
771	}
772
773	printf("\t{") > rumpsysent
774	if (argc != 0) {
775		printf("\n\t\tns(struct %s%s_args),", compatwrap_, funcname) > rumpsysent
776	}
777
778	printf("\n\t\t.sy_call = %s,\n\t},", fn) > rumpsysent
779	printf("\t\t/* %d = %s%s */\n", syscall, compatwrap_, funcalias) > rumpsysent
780}
781
782function iscompattype(type) {
783	for (var in uncompattypes) {
784		if (match(type, var)) {
785			return 1
786		}
787	}
788
789	return 0
790}
791
792function uncompattype(type) {
793	for (var in uncompattypes) {
794		if (match(type, var)) {
795			sub(var, uncompattypes[var], type)
796			return type
797		}
798	}
799
800	return type
801}
802
803function printrumpsysmap(syscall, wfn, funcalias, rumpentry) {
804	printf("%-4d %-22s %-18s %s\n",
805	    syscall, wfn, funcalias, rumpentry) > rumpsysmap
806}
807
808function fixarray(arg) {
809	iii = index(arg, "[")
810	if (iii == 0) {
811		return arg
812	} else {
813		return substr(arg, 1, iii - 1) "[0]"
814	}
815}
816
817function putsystrace(type, compatwrap_) {
818	printf("\t/* %s */\n\tcase %d: {\n", funcname, syscall) > systrace
819	printf("\t/* %s */\n\tcase %d:\n", funcname, syscall) > systracetmp
820	printf("\t/* %s */\n\tcase %d:\n", funcname, syscall) > systraceret
821	if (argc > 0) {
822		printf("\t\tswitch(ndx) {\n") > systracetmp
823		printf("\t\tconst struct %s%s_args *p = params;\n", compatwrap_, funcname) > systrace
824		for (i = 1; i <= argc; i++) {
825			arg = argtype[i]
826			sub("__restrict$", "", arg)
827			printf("\t\tcase %d:\n\t\t\tp = \"%s\";\n\t\t\tbreak;\n", i - 1, arg) > systracetmp
828			if (arg ~ /.*p_t$/ || arg ~ /.*p$/ || arg ~ /.*_t_p$/ ||
829			    arg ~ /.*_pointer_t$/)
830				printf("\t\tuarg[%d] = (intptr_t) SCARG(p, %s).i32; /* %s */\n", \
831				     i - 1, \
832				     argname[i], arg) > systrace
833			else if (index(arg, "*") > 0 || arg == "caddr_t" ||
834			    arg ~ /.*_handler_t$/)
835				printf("\t\tuarg[%d] = (intptr_t) SCARG(p, %s); /* %s */\n", \
836				     i - 1, \
837				     fixarray(argname[i]), arg) > systrace
838			else if (substr(arg, 1, 1) == "u" || arg == "size_t")
839				printf("\t\tuarg[%d] = SCARG(p, %s); /* %s */\n", \
840				     i - 1, \
841				     argname[i], arg) > systrace
842			else
843				printf("\t\tiarg[%d] = SCARG(p, %s); /* %s */\n", \
844				     i - 1, \
845				     fixarray(argname[i]), arg) > systrace
846		}
847		printf("\t\tdefault:\n\t\t\tbreak;\n\t\t};\n") > systracetmp
848
849		printf("\t\tif (ndx == 0 || ndx == 1)\n") > systraceret
850		printf("\t\t\tp = \"%s\";\n", returntype) > systraceret
851		printf("\t\tbreak;\n") > systraceret
852	}
853	printf("\t\t*n_args = %d;\n\t\tbreak;\n\t}\n", argc) > systrace
854	printf("\t\tbreak;\n") > systracetmp
855}
856
857function putent(type, compatwrap) {
858	# output syscall declaration for switch table.
859	if (compatwrap == "")
860		compatwrap_ = ""
861	else
862		compatwrap_ = compatwrap "_"
863	if (argc == 0)
864		arg_type = "void";
865	else {
866		arg_type = "struct " compatwrap_ funcname "_args";
867	}
868	putsystrace(type, compatwrap_)
869	proto = "int\t" compatwrap_ funcname "(struct lwp *, const " \
870	    arg_type " *, register_t *);\n"
871	if (sysmap[proto] != 1) {
872		sysmap[proto] = 1;
873		print proto > sysprotos;
874	}
875
876	# output syscall switch entry
877	printf("\t{") > sysent
878	if (argc != 0) {
879		printf("\n\t\tns(struct %s%s_args),", compatwrap_, funcname) > sysent
880	}
881	if (modular) {
882		wfn = "sys_nomodule";
883		idx = int(syscall / 32);
884		bit = 2 ^ (syscall % 32);
885		nomodbits[ idx ] += bit;
886	} else if (compatwrap == "")
887		wfn = funcname;
888	else
889		wfn = compatwrap "(" funcname ")";
890	wfn_cast="(sy_call_t *)" wfn
891	if (sycall_flags != "0")
892		flags = "\n\t\t.sy_flags = " sycall_flags ","
893	else
894		flags = ""
895	printf("%s\n\t\t.sy_call = %s\n\t},", flags, wfn_cast) > sysent
896	printf("\t\t/* %d = %s%s */\n", syscall, compatwrap_, funcalias) > sysent
897
898	# output syscall name for names table
899	printf("\t/* %3d */\t\"%s%s\",\n", syscall, compatwrap_, funcalias) \
900	    > sysnamesbottom
901	if (compatwrap_ != "" || fbase == funcalias)
902		printf("\t/* %3d */\tNULL, /* %s%s */\n", syscall, \
903		    compatwrap_, funcalias) > sysnamesfriendly
904	else
905		printf("\t/* %3d */\t\"%s%s\",\n", syscall, compatwrap_, \
906		    fbase) > sysnamesfriendly
907
908	# output syscall number of header, if appropriate
909	if (type == "STD" || type == "NOARGS" || type == "INDIR" || \
910	    type == "NOERR") {
911		# output a prototype, to be used to generate lint stubs in
912		# libc.
913		printproto("")
914	} else if (type == "COMPAT" || type == "EXTERN") {
915		# Just define the syscall number with a comment.  These
916		# may be used by compatibility stubs in libc.
917		printproto(compatwrap_)
918	}
919
920	# output syscall argument structure, if it has arguments
921	if (argc != 0) {
922		printf("\n") > sysarghdr
923		if (haverumpcalls && !rumpable)
924			printf("#ifndef RUMP_CLIENT\n") > sysarghdr
925		printf("struct %s%s_args", compatwrap_, funcname) > sysarghdr
926		if (type != "NOARGS") {
927			print " {" >sysarghdr;
928			for (i = 1; i <= argc; i++)
929				printf("\tsyscallarg(%s) %s;\n", argtype[i],
930				    argname[i]) > sysarghdr
931			printf "}" >sysarghdr;
932		}
933		printf(";\n") > sysarghdr
934		if (type != "NOARGS" && type != "INDIR") {
935			printf("check_syscall_args(%s%s)\n", compatwrap_,
936			    funcname) >sysarghdr
937		}
938		if (haverumpcalls && !rumpable)
939			printf("#endif /* !RUMP_CLIENT */\n") > sysarghdr
940	}
941
942	if (!rumpable) {
943		if (funcname == "sys_pipe" && rumphaspipe == 1) {
944			insysent = 1
945			printrumpsysmap(syscall,
946			    funcname, funcalias, "rump_sys_pipe")
947		} else {
948			insysent = 0
949		}
950	} else {
951		insysent = 1
952	}
953	printrumpsysent(insysent, compatwrap_)
954
955	# output rump marshalling code if necessary
956	if (!rumpable) {
957		return
958	}
959
960	printrumpsysmap(syscall, wfn, funcalias, "rump___sysimpl_" rumpfname)
961
962	printf("\n") > rumpcalls
963
964	if (compatwrap)
965		printf("#ifdef RUMP_SYS_COMPAT\n") > rumpcalls
966
967	# need a local prototype, we export the re-re-named one in .h
968	printf("%s rump___sysimpl_%s(", returntype, rumpfname) \
969	    > rumpcalls
970	for (i = 1; i < argc; i++) {
971		if (argname[i] != "PAD")
972			printf("%s, ", uncompattype(argtype[i])) > rumpcalls
973	}
974	printf("%s);", uncompattype(argtype[argc])) > rumpcalls
975
976	printf("\n%s\nrump___sysimpl_%s(", returntype, rumpfname) > rumpcalls
977	for (i = 1; i < argc; i++) {
978		if (argname[i] != "PAD")
979			printf("%s %s, ", uncompattype(argtype[i]), \
980			    argname[i]) > rumpcalls
981	}
982	printf("%s %s)\n", uncompattype(argtype[argc]), argname[argc]) \
983	    > rumpcalls
984	printf("{\n\tregister_t retval[2];\n") > rumpcalls
985	if (returntype != "void") {
986		if (type != "NOERR") {
987			printf("\tint error = 0;\n") > rumpcalls
988		}
989		# assume rumpcalls return only integral types
990		printf("\t%s rv = -1;\n", returntype) > rumpcalls
991	}
992
993	argarg = "NULL"
994	argsize = 0;
995	if (argc) {
996		argarg = "&callarg"
997		argsize = "sizeof(callarg)"
998		printf("\tstruct %s%s_args callarg;\n\n",compatwrap_,funcname) \
999		    > rumpcalls
1000		printf "\tmemset(&callarg, 0, sizeof(callarg));\n" > rumpcalls
1001		for (i = 1; i <= argc; i++) {
1002			if (argname[i] == "PAD") {
1003				printf("\tSPARG(&callarg, %s) = 0;\n", \
1004				    argname[i]) > rumpcalls
1005			} else {
1006				if (iscompattype(argtype[i])) {
1007					printf("\tSPARG(&callarg, %s) = "    \
1008					"(%s)%s;\n", argname[i], argtype[i], \
1009					argname[i]) > rumpcalls
1010				} else {
1011					printf("\tSPARG(&callarg, %s) = %s;\n",\
1012					    argname[i], argname[i]) > rumpcalls
1013				}
1014			}
1015		}
1016		printf("\n") > rumpcalls
1017	} else {
1018		printf("\n") > rumpcalls
1019	}
1020	printf("\t") > rumpcalls
1021	if (returntype != "void" && type != "NOERR")
1022		printf("error = ") > rumpcalls
1023	else if (returntype != "void")
1024		printf("(void)") > rumpcalls
1025	printf("rsys_syscall(%s%s%s, " \
1026	    "%s, %s, retval);\n", constprefix, compatwrap_, funcalias, \
1027	    argarg, argsize) > rumpcalls
1028	if (type != "NOERR") {
1029		printf("\trsys_seterrno(error);\n") > rumpcalls
1030		printf("\tif (error == 0) {\n") > rumpcalls
1031		indent="\t\t"
1032		ending="\t}\n"
1033	} else {
1034		indent="\t"
1035		ending=""
1036	}
1037	if (returntype != "void") {
1038		printf("%sif (sizeof(%s) > sizeof(register_t))\n", \
1039		    indent, returntype) > rumpcalls
1040		printf("%s\trv = *(%s *)retval;\n", \
1041		    indent, returntype) > rumpcalls
1042		printf("%selse\n", indent, indent) > rumpcalls
1043		printf("%s\trv = *retval;\n", indent, returntype) > rumpcalls
1044		printf("%s", ending) > rumpcalls
1045		printf("\treturn rv;\n") > rumpcalls
1046	}
1047	printf("}\n") > rumpcalls
1048
1049	printf("#ifdef RUMP_KERNEL_IS_LIBC\n") > rumpcalls
1050
1051	# create the bog-standard, non-renamed public name.
1052	# this way we get e.g. select instead of just __select50
1053	if (fcompat)
1054		printf("__weak_alias(%s,rump___sysimpl_%s);\n", \
1055		    fbase, rumpfname) > rumpcalls
1056
1057	printf("__weak_alias(%s,rump___sysimpl_%s);\n", \
1058	    funcalias, rumpfname) > rumpcalls
1059	printf("__weak_alias(_%s,rump___sysimpl_%s);\n", \
1060	    funcalias, rumpfname) > rumpcalls
1061	printf("__strong_alias(_sys_%s,rump___sysimpl_%s);\n", \
1062	    funcalias, rumpfname) >rumpcalls
1063
1064	printf("#endif /* RUMP_KERNEL_IS_LIBC */\n") > rumpcalls
1065
1066	if (compatwrap)
1067		printf("#endif /* RUMP_SYS_COMPAT */\n") > rumpcalls
1068
1069}
1070$2 == "STD" || $2 == "NODEF" || $2 == "NOARGS" || $2 == "INDIR" \
1071    || $2 == "NOERR" {
1072	parseline()
1073	putent($2, "")
1074	syscall++
1075	next
1076}
1077$2 == "OBSOL" || $2 == "UNIMPL" || $2 == "EXCL" || $2 == "IGNORED" {
1078	if ($2 == "OBSOL")
1079		comment="obsolete"
1080	else if ($2 == "EXCL")
1081		comment="excluded"
1082	else if ($2 == "IGNORED")
1083		comment="ignored"
1084	else
1085		comment="unimplemented"
1086	for (i = 3; i <= NF; i++)
1087		comment=comment " " $i
1088
1089	if ($2 == "IGNORED")
1090		sys_stub = "(sy_call_t *)(void *)nullop";
1091	else
1092		sys_stub = sys_nosys;
1093
1094	print fillerpsysent(syscall, "", sys_stub, comment) > sysent
1095	print fillerpsysent(syscall, rumpnoflags, rumpnosys, comment) > rumpsysent
1096	printf("\t/* %3d */\t\"#%d (%s)\",\n", syscall, syscall, comment) \
1097	    > sysnamesbottom
1098	printf("\t/* %3d */\tNULL, /* %s */\n", syscall, comment) \
1099	    > sysnamesfriendly
1100	if ($2 != "UNIMPL")
1101		printf("\t\t\t\t/* %d is %s */\n", syscall, comment) > sysnumhdr
1102	syscall++
1103	next
1104}
1105$2 == "EXTERN" {
1106	parseline()
1107	putent("EXTERN", "")
1108	syscall++
1109	next
1110}
1111{
1112	for (i = 1; i <= ncompat; i++) {
1113		if ($2 == compat_upper[i]) {
1114			parseline();
1115			putent("COMPAT", compat[i])
1116			syscall++
1117			next
1118		}
1119	}
1120	printf("%s: line %d: unrecognized keyword %s\n", infile, NR, $2)
1121	exit 1
1122}
1123
1124function sort(arr, n,    i, j, t) {
1125	# this is going to be bubble sort because I cannot be bothered to
1126	# write a real sort, this whole script is hopefully going to be
1127	# deprecated before much longer, and performance of a few hundred
1128	# things (even interpreted in awk) should be adequate.
1129	for (i = 1; i <= n; i++) {
1130		for (j = i + 1; j <= n; j++) {
1131			if (arr[j] < arr[i]) {
1132				t = arr[i];
1133				arr[i] = arr[j];
1134				arr[j] = t;
1135			}
1136		}
1137	}
1138	return 0;
1139}
1140
1141END {
1142	# output pipe() syscall with its special retval[2] handling
1143	if (rumphaspipe) {
1144		printf("int rump_sys_pipe(int *);\n") > rumpprotos
1145		printf("\nint rump_sys_pipe(int *);\n") > rumpcalls
1146		printf("int\nrump_sys_pipe(int *fd)\n{\n") > rumpcalls
1147		printf("\tregister_t retval[2];\n") > rumpcalls
1148		printf("\tint error = 0;\n") > rumpcalls
1149		printf("\n\terror = rsys_syscall(SYS_pipe, ") > rumpcalls
1150		printf("NULL, 0, retval);\n") > rumpcalls
1151		printf("\tif (error) {\n") > rumpcalls
1152		printf("\t\trsys_seterrno(error);\n") > rumpcalls
1153		printf("\t} else {\n\t\tfd[0] = retval[0];\n") > rumpcalls
1154		printf("\t\tfd[1] = retval[1];\n\t}\n") > rumpcalls
1155		printf("\treturn error ? -1 : 0;\n}\n") > rumpcalls
1156		printf("#ifdef RUMP_KERNEL_IS_LIBC\n") > rumpcalls
1157		printf("__weak_alias(pipe,rump_sys_pipe);\n") > rumpcalls
1158		printf("__weak_alias(_pipe,rump_sys_pipe);\n") > rumpcalls
1159		printf("__strong_alias(_sys_pipe,rump_sys_pipe);\n") > rumpcalls
1160		printf("#endif\n") > rumpcalls
1161	}
1162
1163	# print default rump syscall interfaces
1164	# be sure to generate them in a deterministic order, not awk
1165	# hash order as would happen with a plain "for (var in funcseen)"
1166	numfuncseenvars = 0;
1167	for (var in funcseen) {
1168		funcseenvars[++numfuncseenvars] = var;
1169	}
1170	sort(funcseenvars, numfuncseenvars)
1171	for (i = 1; i <= numfuncseenvars; i++) {
1172		var = funcseenvars[i];
1173		printf("#ifndef RUMP_SYS_RENAME_%s\n", \
1174		    toupper(var)) > rumpcallshdr
1175		printf("#define RUMP_SYS_RENAME_%s rump___sysimpl_%s\n", \
1176		    toupper(var), funcseen[var]) > rumpcallshdr
1177		printf("#endif\n\n") > rumpcallshdr
1178	}
1179
1180	maxsyscall = syscall
1181
1182	if (nsysent) {
1183		if (syscall > nsysent) {
1184			printf("%s: line %d: too many syscalls [%d > %d]\n", infile, NR, syscall, nsysent)
1185			exit 1
1186		}
1187		while (syscall < nsysent) {
1188			print fillerpsysent(syscall, "", sys_nosys, "filler") > sysent
1189			print fillerpsysent(syscall, rumpnoflags, rumpnosys, "filler") > rumpsysent
1190			printf("\t/* %3d */\t\"# filler\",\n", syscall) \
1191			    > sysnamesbottom
1192			printf("\t/* %3d */\tNULL, /* filler */\n", syscall) \
1193			    > sysnamesfriendly
1194			syscall++
1195		}
1196	}
1197	printf("};\n") > sysent
1198	printf("\nconst uint32_t %s_nomodbits[] = {\n", switchname) > sysent
1199	printf("};\n") > rumpsysent
1200	printf("\nconst uint32_t rump_sysent_nomodbits[] = {\n") > rumpsysent
1201	for (i = 0; i < syscall / 32; i++) {
1202		printf("\t0x%08x,\t/* syscalls %3d-%3d */\n",
1203			nomodbits[i], i * 32, i * 32 + 31) > sysent
1204		printf("\t0x%08x,\t/* syscalls %3d-%3d */\n",
1205			nomodbits[i], i * 32, i * 32 + 31) > rumpsysent
1206	}
1207	printf("};\n") > sysent
1208	printf("};\n") > rumpsysent
1209	printf("CTASSERT(__arraycount(rump_sysent) == SYS_NSYSENT);\n") > rumpsysent
1210	printf("__strong_alias(rumpns_sysent,rump_sysent);\n") > rumpsysent
1211	printf("#endif /* RUMP_CLIENT */\n") > rumpsysent
1212	if (haverumpcalls)
1213		printf("#endif /* !RUMP_CLIENT */\n") > sysprotos
1214	printf("};\n") > sysnamesbottom
1215	printf("};\n") > sysnamesfriendly
1216	printf("#define\t%sMAXSYSCALL\t%d\n", constprefix, maxsyscall) > sysnumhdr
1217	if (nsysent)
1218		printf("#define\t%sNSYSENT\t%d\n", constprefix, nsysent) > sysnumhdr
1219	printf "\tdefault:\n\t\t*n_args = 0;\n\t\tbreak;\n\t};\n}\n" > systrace
1220	printf "\tdefault:\n\t\tbreak;\n\t};\n\tif (p != NULL)\n\t\tstrlcpy(desc, p, descsz);\n}\n" > systracetmp
1221	printf "\tdefault:\n\t\tbreak;\n\t};\n\tif (p != NULL)\n\t\tstrlcpy(desc, p, descsz);\n}\n" > systraceret
1222} '
1223
1224cat $sysprotos >> $sysarghdr
1225echo "#endif /* _${constprefix}SYSCALL_H_ */" >> $sysnumhdr
1226echo "#endif /* _${constprefix}SYSCALLARGS_H_ */" >> $sysarghdr
1227printf "\t    { 0, NULL }\n" >> $sysautoloadbottom
1228echo "};" >> $sysautoloadbottom
1229printf "\n#endif /* _RUMP_RUMP_SYSCALLS_H_ */\n" >> $rumpprotos
1230cat $sysdcl $sysent > $syssw
1231cat $sysnamesbottom >> $sysnames
1232cat $sysnamesfriendly >> $sysnames
1233cat $rumpsysent >> $rumpcalls
1234cat $sysautoloadbottom >> $sysautoload
1235
1236touch $rumptypes
1237cat $rumptypes >> $rumpcallshdr
1238echo >> $rumpcallshdr
1239cat $rumpprotos >> $rumpcallshdr
1240
1241#chmod 444 $sysnames $sysnumhdr $syssw
1242
1243cat $systracetmp >> $systrace
1244cat $systraceret >> $systrace
1245
1246echo Generated following files:
1247echo $sysarghdr $sysnumhdr $syssw $sysnames $sysautoload $systrace $rumpcalls $rumpcallshdr $rumpsysmap
1248