xref: /dragonfly/sys/kern/makesyscalls.sh (revision 655933d6)
1#! /bin/sh -
2#	@(#)makesyscalls.sh	8.1 (Berkeley) 6/10/93
3# $FreeBSD: src/sys/kern/makesyscalls.sh,v 1.39.2.4 2001/10/20 09:01:24 marcel Exp $
4
5set -e
6
7# output files:
8sysnames="syscalls.c"
9sysproto="../sys/sysproto.h"
10sysunion="../sys/sysunion.h"
11sysproto_h=_SYS_SYSPROTO_H_
12syshdr="../sys/syscall.h"
13sysmk="../sys/syscall.mk"
14syssw="init_sysent.c"
15syscallprefix="SYS_"
16switchname="sysent"
17namesname="syscallnames"
18
19# tmp files:
20sysdcl="sysent.dcl.$$"
21syscompat="sysent.compat.$$"
22syscompatdcl="sysent.compatdcl.$$"
23sysent="sysent.switch.$$"
24sysinc="sysinc.switch.$$"
25sysarg="sysarg.switch.$$"
26sysun="sysunion.switch.$$"
27
28trap "rm $sysdcl $syscompat $syscompatdcl $sysent $sysinc $sysarg $sysun" 0
29
30touch $sysdcl $syscompat $syscompatdcl $sysent $sysinc $sysarg $sysun
31
32case $# in
33    0)	echo "Usage: $0 input-file <config-file>" 1>&2
34	exit 1
35	;;
36esac
37
38if [ -n "$2" -a -f "$2" ]; then
39	. $2
40fi
41
42sed -e '
43s/\$//g
44:join
45	/\\$/{a\
46
47	N
48	s/\\\n//
49	b join
50	}
512,${
52	/^#/!s/\([{}()*,]\)/ \1 /g
53}
54' < $1 | awk "
55	BEGIN {
56		sysdcl = \"$sysdcl\"
57		sysproto = \"$sysproto\"
58		sysproto_h = \"$sysproto_h\"
59		syscompat = \"$syscompat\"
60		syscompatdcl = \"$syscompatdcl\"
61		sysent = \"$sysent\"
62		syssw = \"$syssw\"
63		sysinc = \"$sysinc\"
64		sysarg = \"$sysarg\"
65		sysun = \"$sysun\"
66		sysnames = \"$sysnames\"
67		syshdr = \"$syshdr\"
68		sysmk = \"$sysmk\"
69		compat = \"$compat\"
70		syscallprefix = \"$syscallprefix\"
71		switchname = \"$switchname\"
72		namesname = \"$namesname\"
73		infile = \"$1\"
74		"'
75
76		printf "/*\n * System call switch table.\n *\n" > syssw
77		printf " * DO NOT EDIT-- To regenerate this file, edit syscalls.master followed\n" > syssw
78		printf " *               by running make sysent in the same directory.\n" > syssw
79		printf " */\n\n" > syssw
80
81		printf "/*\n * System call prototypes.\n *\n" > sysarg
82		printf " * DO NOT EDIT-- To regenerate this file, edit syscalls.master followed\n" > sysarg
83		printf " *               by running make sysent in the same directory.\n" > sysarg
84		printf " */\n\n" > sysarg
85		printf "#ifndef _KERNEL\n" >sysarg
86		printf "#error \"This file should not be included by userland programs.\"\n" >sysarg
87		printf "#endif\n\n" >sysarg
88		printf "#ifndef %s\n", sysproto_h > sysarg
89		printf "#define\t%s\n\n", sysproto_h > sysarg
90		printf "#include <sys/select.h>\n" > sysarg
91		printf "#include <sys/signal.h>\n" > sysarg
92		printf "#include <sys/acl.h>\n" > sysarg
93		printf "#include <sys/cpumask.h>\n" > sysarg
94		printf "#include <sys/mqueue.h>\n" > sysarg
95		printf "#include <sys/msgport.h>\n" > sysarg
96		printf "#include <sys/procctl.h>\n\n" > sysarg
97		printf "#define\tPAD_(t)\t(sizeof(register_t) <= sizeof(t) ? \\\n" > sysarg
98		printf "\t\t0 : sizeof(register_t) - sizeof(t))\n\n" > sysarg
99
100		printf "/*\n * System call names.\n *\n" > sysnames
101		printf " * DO NOT EDIT-- To regenerate this file, edit syscalls.master followed\n" > sysnames
102		printf " *               by running make sysent in the same directory.\n" > sysnames
103		printf " */\n\n" > sysnames
104		printf "const char *%s[] = {\n", namesname > sysnames
105
106		printf "/*\n * System call numbers.\n *\n" > syshdr
107		printf " * DO NOT EDIT-- To regenerate this file, edit syscalls.master followed\n" > syshdr
108		printf " *               by running make sysent in the same directory.\n" > syshdr
109		printf " */\n\n" > syshdr
110
111		printf "# DragonFly system call names.\n" > sysmk
112		printf "# DO NOT EDIT-- To regenerate this file, edit syscalls.master followed\n" > sysmk
113		printf "#               by running make sysent in the same directory.\n" > sysmk
114		printf "MIASM = " > sysmk
115
116		printf "/*\n * Union of syscall args for messaging.\n *\n" > sysun
117		printf " * DO NOT EDIT-- To regenerate this file, edit syscalls.master followed\n" > sysun
118		printf " *               by running make sysent in the same directory.\n" > sysun
119		printf " */\n\n" > sysun
120		printf "#ifndef _KERNEL\n" >sysun
121		printf "#error \"This file should not be included by userland programs.\"\n" >sysun
122		printf "#endif\n\n" >sysun
123		printf "#include <sys/sysproto.h>\n\n" > sysun
124		printf "union sysunion {\n" > sysun
125
126		printf "\n/* The casts are bogus but will do for now. */\n" > sysent
127		printf "struct sysent %s[] = {\n",switchname > sysent
128
129		printf "\n#ifdef _KERNEL\n\n" > sysdcl
130		printf "\n#ifdef _KERNEL\n\n" > syscompatdcl
131		printf "struct sysmsg;\n\n" > sysdcl
132		printf "struct sysmsg;\n\n" > syscompatdcl
133	}
134	NF == 0 || $1 ~ /^;/ {
135		next
136	}
137	$1 ~ /^#[ 	]*include/ {
138		print > sysinc
139		next
140	}
141	$1 ~ /^#[ 	]*if/ {
142		print > sysent
143		print > sysdcl
144		print > sysarg
145		print > syscompat
146		print > sysnames
147		print > sysun
148		savesyscall = syscall
149		next
150	}
151	$1 ~ /^#[ 	]*else/ {
152		print > sysent
153		print > sysdcl
154		print > sysarg
155		print > sysun
156		print > syscompat
157		print > sysnames
158		syscall = savesyscall
159		next
160	}
161	$1 ~ /^#/ {
162		print > sysent
163		print > sysdcl
164		print > sysarg
165		print > sysun
166		print > syscompat
167		print > sysnames
168		next
169	}
170	syscall != $1 {
171		printf "%s: line %d: syscall number out of sync at %d\n",
172		    infile, NR, syscall
173		printf "line is:\n"
174		print
175		exit 1
176	}
177	function align_sysent_comment(column) {
178		printf("\t") > sysent
179		column = column + 8 - column % 8
180		while (column < 56) {
181			printf("\t") > sysent
182			column = column + 8
183		}
184	}
185	function parserr(was, wanted) {
186		printf "%s: line %d: unexpected %s (expected %s)\n",
187		    infile, NR, was, wanted
188		exit 1
189	}
190	function parseline() {
191		f=3			# toss number and type
192		argc= 0;
193		argssize = "0"
194		if ($NF != "}") {
195			funcalias=$(NF-2)
196			argalias=$(NF-1)
197			rettype=$NF
198			end=NF-3
199		} else {
200			funcalias=""
201			argalias=""
202			rettype="int"
203			end=NF
204		}
205		if ($2 == "NODEF") {
206			funcname=$3
207			argssize = "AS(" $5 ")"
208			return
209		}
210		if ($f != "{")
211			parserr($f, "{")
212		f++
213		if ($end != "}")
214			parserr($end, "}")
215		end--
216		if ($end != ";")
217			parserr($end, ";")
218		end--
219		if ($end != ")")
220			parserr($end, ")")
221		end--
222
223		f++	#function return type
224
225		funcname=$f
226		usefuncname=$f
227		if (funcalias == "")
228			funcalias = funcname
229		if (argalias == "")
230			argalias = funcname "_args"
231		f++
232
233		if ($f != "(")
234			parserr($f, ")")
235		f++
236
237		if (f == end) {
238			if ($f != "void")
239				parserr($f, "argument definition")
240			return
241		}
242
243		while (f <= end) {
244			argc++
245			argtype[argc]=""
246			oldf=""
247			while (f < end && $(f+1) != ",") {
248				if (argtype[argc] != "" && oldf != "*")
249					argtype[argc] = argtype[argc]" ";
250				argtype[argc] = argtype[argc]$f;
251				oldf = $f;
252				f++
253			}
254			if (argtype[argc] == "")
255				parserr($f, "argument definition")
256			argname[argc]=$f;
257			f += 2;			# skip name, and any comma
258		}
259		if (argc != 0)
260			argssize = "AS(" argalias ")"
261	}
262	{	comment = $3
263		if (NF < 6)
264			for (i = 4; i <= NF; i++)
265				comment = comment " " $i
266	}
267	$2 == "STD" || $2 == "NODEF" || $2 == "NOARGS"  || $2 == "NOPROTO" \
268	    || $2 == "NOIMPL" {
269		parseline()
270		if ((!nosys || funcname != "nosys") && \
271		    (funcname != "lkmnosys")) {
272			if (argc != 0 && $2 != "NOARGS" && $2 != "NOPROTO") {
273				printf("\tstruct\t%s %s;\n", argalias, usefuncname) > sysun
274				printf("struct\t%s {\n", argalias) > sysarg
275				for (i = 1; i <= argc; i++)
276					printf("\t%s\t%s;\tchar %s_[PAD_(%s)];\n",
277					    argtype[i], argname[i],
278					    argname[i], argtype[i]) > sysarg
279				printf("};\n") > sysarg
280			}
281			else if ($2 != "NOARGS" && $2 != "NOPROTO" && \
282			    $2 != "NODEF") {
283				printf("\tstruct\t%s %s;\n", argalias, usefuncname) > sysun
284				printf("struct\t%s {\n", argalias) > sysarg
285				printf("\tregister_t dummy;\n") > sysarg
286				printf("};\n") > sysarg
287			}
288		}
289		if (($2 != "NOPROTO" && $2 != "NODEF" && \
290		    (funcname != "nosys" || !nosys)) || \
291		    (funcname == "lkmnosys" && !lkmnosys) || \
292		    funcname == "lkmressys") {
293			printf("%s\tsys_%s (struct sysmsg *sysmsg, const struct %s *)",
294			    rettype, funcname, argalias) > sysdcl
295			printf(";\n") > sysdcl
296		}
297		if (funcname == "nosys")
298			nosys = 1
299		if (funcname == "lkmnosys")
300			lkmnosys = 1
301		printf("\t{ %s, (sy_call_t *)", argssize) > sysent
302		column = 8 + 2 + length(argssize) + 15
303	 	if ($2 != "NOIMPL") {
304			printf("sys_%s },", funcname) > sysent
305			column = column + length(funcname) + 7
306		} else {
307			printf("sys_%s },", "nosys") > sysent
308			column = column + length("nosys") + 7
309		}
310		align_sysent_comment(column)
311		printf("/* %d = %s */\n", syscall, funcalias) > sysent
312		printf("\t\"%s\",\t\t\t/* %d = %s */\n",
313		    funcalias, syscall, funcalias) > sysnames
314		if ($2 != "NODEF") {
315			printf("#define\t%s%s\t%d\n", syscallprefix,
316		    	    funcalias, syscall) > syshdr
317			printf(" \\\n\t%s.o", funcalias) > sysmk
318		}
319		syscall++
320		next
321	}
322	$2 == "OBSOL" {
323		printf("\t{ 0, (sy_call_t *)sys_nosys },") > sysent
324		align_sysent_comment(37)
325		printf("/* %d = obsolete %s */\n", syscall, comment) > sysent
326		printf("\t\"obs_%s\",\t\t\t/* %d = obsolete %s */\n",
327		    $3, syscall, comment) > sysnames
328		printf("\t\t\t\t/* %d is obsolete %s */\n",
329		    syscall, comment) > syshdr
330		syscall++
331		next
332	}
333	$2 == "UNIMPL" {
334		printf("\t{ 0, (sy_call_t *)sys_nosys },\t\t\t/* %d = %s */\n",
335		    syscall, comment) > sysent
336		printf("\t\"#%d\",\t\t\t/* %d = %s */\n",
337		    syscall, syscall, comment) > sysnames
338		syscall++
339		next
340	}
341	{
342		printf "%s: line %d: unrecognized keyword %s\n", infile, NR, $2
343		exit 1
344	}
345	END {
346		printf "\n#define AS(name) (sizeof(struct name) / sizeof(register_t))\n" > sysinc
347		if (ncompat != 0)
348			printf "#define compat(n, name) 0, (sy_call_t *)sys_nosys\n" > sysinc
349
350		printf("\n#undef PAD_\n") > sysarg
351		printf("\n#endif /* _KERNEL */\n") > syscompatdcl
352		printf("\n#endif /* _KERNEL */\n") > sysdcl
353		printf("\n#endif /* !%s */\n", sysproto_h) > sysdcl
354
355		printf("\n") > sysmk
356		printf("};\n") > sysent
357		printf("};\n") > sysnames
358		printf("};\n") > sysun
359		printf("#define\t%sMAXSYSCALL\t%d\n", syscallprefix, syscall) \
360		    > syshdr
361	} '
362
363cat $sysinc $sysent >> $syssw
364cat $sysarg $syscompat $syscompatdcl $sysdcl > $sysproto
365cat $sysun > $sysunion
366