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