xref: /dragonfly/sys/kern/makesyscalls.sh (revision 0de61e28)
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 %s\n", sysproto_h > sysarg
86		printf "#define\t%s\n\n", sysproto_h > sysarg
87		printf "#include <sys/select.h>\n" > sysarg
88		printf "#include <sys/signal.h>\n" > sysarg
89		printf "#include <sys/acl.h>\n" > sysarg
90		printf "#include <sys/cpumask.h>\n" > sysarg
91		printf "#include <sys/mqueue.h>\n" > sysarg
92		printf "#include <sys/msgport.h>\n" > sysarg
93		printf "#include <sys/sysmsg.h>\n" > sysarg
94		printf "#include <sys/procctl.h>\n\n" > sysarg
95		printf "#define\tPAD_(t)\t(sizeof(register_t) <= sizeof(t) ? \\\n" > sysarg
96		printf "\t\t0 : sizeof(register_t) - sizeof(t))\n\n" > sysarg
97
98		printf "/*\n * System call names.\n *\n" > sysnames
99		printf " * DO NOT EDIT-- To regenerate this file, edit syscalls.master followed\n" > sysnames
100		printf " *               by running make sysent in the same directory.\n" > sysnames
101		printf " */\n\n" > sysnames
102		printf "const char *%s[] = {\n", namesname > sysnames
103
104		printf "/*\n * System call numbers.\n *\n" > syshdr
105		printf " * DO NOT EDIT-- To regenerate this file, edit syscalls.master followed\n" > syshdr
106		printf " *               by running make sysent in the same directory.\n" > syshdr
107		printf " */\n\n" > syshdr
108
109		printf "# DragonFly system call names.\n" > sysmk
110		printf "# DO NOT EDIT-- To regenerate this file, edit syscalls.master followed\n" > sysmk
111		printf "#               by running make sysent in the same directory.\n" > sysmk
112		printf "MIASM = " > sysmk
113
114		printf "/*\n * Union of syscall args for messaging.\n *\n" > sysun
115		printf " * DO NOT EDIT-- To regenerate this file, edit syscalls.master followed\n" > sysun
116		printf " *               by running make sysent in the same directory.\n" > sysun
117		printf " */\n\n" > sysun
118		printf "union sysunion {\n" > sysun
119		printf "#ifdef _KERNEL /* header only applies in kernel */\n" > sysun
120		#printf "\tstruct\tlwkt_msg lmsg;\n" > sysun
121		printf "\tstruct\tsysmsg sysmsg;\n" > sysun
122		printf "#endif\n" > sysun
123
124		printf "\n/* The casts are bogus but will do for now. */\n" > sysent
125		printf "struct sysent %s[] = {\n",switchname > sysent
126
127		printf "\n#ifdef _KERNEL\n\n" > sysdcl
128		printf "\n#ifdef _KERNEL\n\n" > syscompatdcl
129	}
130	NF == 0 || $1 ~ /^;/ {
131		next
132	}
133	$1 ~ /^#[ 	]*include/ {
134		print > sysinc
135		next
136	}
137	$1 ~ /^#[ 	]*if/ {
138		print > sysent
139		print > sysdcl
140		print > sysarg
141		print > syscompat
142		print > sysnames
143		print > sysun
144		savesyscall = syscall
145		next
146	}
147	$1 ~ /^#[ 	]*else/ {
148		print > sysent
149		print > sysdcl
150		print > sysarg
151		print > sysun
152		print > syscompat
153		print > sysnames
154		syscall = savesyscall
155		next
156	}
157	$1 ~ /^#/ {
158		print > sysent
159		print > sysdcl
160		print > sysarg
161		print > sysun
162		print > syscompat
163		print > sysnames
164		next
165	}
166	syscall != $1 {
167		printf "%s: line %d: syscall number out of sync at %d\n",
168		    infile, NR, syscall
169		printf "line is:\n"
170		print
171		exit 1
172	}
173	function align_sysent_comment(column) {
174		printf("\t") > sysent
175		column = column + 8 - column % 8
176		while (column < 56) {
177			printf("\t") > sysent
178			column = column + 8
179		}
180	}
181	function parserr(was, wanted) {
182		printf "%s: line %d: unexpected %s (expected %s)\n",
183		    infile, NR, was, wanted
184		exit 1
185	}
186	function parseline() {
187		f=3			# toss number and type
188		argc= 0;
189		argssize = "0"
190		if ($NF != "}") {
191			funcalias=$(NF-2)
192			argalias=$(NF-1)
193			rettype=$NF
194			end=NF-3
195		} else {
196			funcalias=""
197			argalias=""
198			rettype="int"
199			end=NF
200		}
201		if ($2 == "NODEF") {
202			funcname=$3
203			argssize = "AS(" $5 ")"
204			return
205		}
206		if ($f != "{")
207			parserr($f, "{")
208		f++
209		if ($end != "}")
210			parserr($end, "}")
211		end--
212		if ($end != ";")
213			parserr($end, ";")
214		end--
215		if ($end != ")")
216			parserr($end, ")")
217		end--
218
219		f++	#function return type
220
221		funcname=$f
222		usefuncname=$f
223		if (funcalias == "")
224			funcalias = funcname
225		if (argalias == "")
226			argalias = funcname "_args"
227		f++
228
229		if ($f != "(")
230			parserr($f, ")")
231		f++
232
233		if (f == end) {
234			if ($f != "void")
235				parserr($f, "argument definition")
236			return
237		}
238
239		while (f <= end) {
240			argc++
241			argtype[argc]=""
242			oldf=""
243			while (f < end && $(f+1) != ",") {
244				if (argtype[argc] != "" && oldf != "*")
245					argtype[argc] = argtype[argc]" ";
246				argtype[argc] = argtype[argc]$f;
247				oldf = $f;
248				f++
249			}
250			if (argtype[argc] == "")
251				parserr($f, "argument definition")
252			argname[argc]=$f;
253			f += 2;			# skip name, and any comma
254		}
255		if (argc != 0)
256			argssize = "AS(" argalias ")"
257	}
258	{	comment = $3
259		if (NF < 6)
260			for (i = 4; i <= NF; i++)
261				comment = comment " " $i
262	}
263	$2 == "STD" || $2 == "NODEF" || $2 == "NOARGS"  || $2 == "NOPROTO" \
264	    || $2 == "NOIMPL" {
265		parseline()
266		if ((!nosys || funcname != "nosys") && \
267		    (funcname != "lkmnosys")) {
268			if (argc != 0 && $2 != "NOARGS" && $2 != "NOPROTO") {
269				printf("\tstruct\t%s %s;\n", argalias, usefuncname) > sysun
270				printf("struct\t%s {\n", argalias) > sysarg
271				printf("#ifdef _KERNEL\n") > sysarg
272				printf("\tstruct sysmsg sysmsg;\n") > sysarg
273				printf("#endif\n") > sysarg
274				for (i = 1; i <= argc; i++)
275					printf("\t%s\t%s;\tchar %s_[PAD_(%s)];\n",
276					    argtype[i], argname[i],
277					    argname[i], argtype[i]) > sysarg
278				printf("};\n") > sysarg
279			}
280			else if ($2 != "NOARGS" && $2 != "NOPROTO" && \
281			    $2 != "NODEF") {
282				printf("\tstruct\t%s %s;\n", argalias, usefuncname) > sysun
283				printf("struct\t%s {\n", argalias) > sysarg
284				printf("#ifdef _KERNEL\n") > sysarg
285				printf("\tstruct sysmsg sysmsg;\n") > sysarg
286				printf("#endif\n") > sysarg
287				printf("\tregister_t dummy;\n") > sysarg
288				printf("};\n") > sysarg
289			}
290		}
291		if (($2 != "NOPROTO" && $2 != "NODEF" && \
292		    (funcname != "nosys" || !nosys)) || \
293		    (funcname == "lkmnosys" && !lkmnosys) || \
294		    funcname == "lkmressys") {
295			printf("%s\tsys_%s (struct %s *)",
296			    rettype, funcname, argalias) > sysdcl
297			printf(";\n") > sysdcl
298		}
299		if (funcname == "nosys")
300			nosys = 1
301		if (funcname == "lkmnosys")
302			lkmnosys = 1
303		printf("\t{ %s, (sy_call_t *)", argssize) > sysent
304		column = 8 + 2 + length(argssize) + 15
305	 	if ($2 != "NOIMPL") {
306			printf("sys_%s },", funcname) > sysent
307			column = column + length(funcname) + 7
308		} else {
309			printf("sys_%s },", "nosys") > sysent
310			column = column + length("nosys") + 7
311		}
312		align_sysent_comment(column)
313		printf("/* %d = %s */\n", syscall, funcalias) > sysent
314		printf("\t\"%s\",\t\t\t/* %d = %s */\n",
315		    funcalias, syscall, funcalias) > sysnames
316		if ($2 != "NODEF") {
317			printf("#define\t%s%s\t%d\n", syscallprefix,
318		    	    funcalias, syscall) > syshdr
319			printf(" \\\n\t%s.o", funcalias) > sysmk
320		}
321		syscall++
322		next
323	}
324	$2 == "OBSOL" {
325		printf("\t{ 0, (sy_call_t *)sys_nosys },") > sysent
326		align_sysent_comment(37)
327		printf("/* %d = obsolete %s */\n", syscall, comment) > sysent
328		printf("\t\"obs_%s\",\t\t\t/* %d = obsolete %s */\n",
329		    $3, syscall, comment) > sysnames
330		printf("\t\t\t\t/* %d is obsolete %s */\n",
331		    syscall, comment) > syshdr
332		syscall++
333		next
334	}
335	$2 == "UNIMPL" {
336		printf("\t{ 0, (sy_call_t *)sys_nosys },\t\t\t/* %d = %s */\n",
337		    syscall, comment) > sysent
338		printf("\t\"#%d\",\t\t\t/* %d = %s */\n",
339		    syscall, syscall, comment) > sysnames
340		syscall++
341		next
342	}
343	{
344		printf "%s: line %d: unrecognized keyword %s\n", infile, NR, $2
345		exit 1
346	}
347	END {
348		printf "\n#define AS(name) ((sizeof(struct name) - sizeof(struct sysmsg)) / sizeof(register_t))\n" > sysinc
349		if (ncompat != 0)
350			printf "#define compat(n, name) 0, (sy_call_t *)sys_nosys\n" > sysinc
351
352		printf("\n#endif /* _KERNEL */\n") > syscompatdcl
353
354		printf("\n") > sysmk
355		printf("};\n") > sysent
356		printf("};\n") > sysnames
357		printf("};\n") > sysun
358		printf("\n#endif /* !%s */\n", sysproto_h) > sysdcl
359		printf("#undef PAD_\n") > sysdcl
360		printf("\n#endif /* _KERNEL */\n") > sysdcl
361		printf("#define\t%sMAXSYSCALL\t%d\n", syscallprefix, syscall) \
362		    > syshdr
363	} '
364
365cat $sysinc $sysent >> $syssw
366cat $sysarg $syscompat $syscompatdcl $sysdcl > $sysproto
367cat $sysun > $sysunion
368